summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKimberly Brown <kimbrownkd@gmail.com>2019-04-01 22:51:18 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-04-25 16:06:10 -0400
commitaa30f47cf666111f6bbfd15f290a27e8a7b9d854 (patch)
treef37b73de916cc982e5fe7b5d0ad5dc70c3bc7702
parent0b777eee88d712256ba8232a9429edb17c4f9ceb (diff)
kobject: Add support for default attribute groups to kobj_type
kobj_type currently uses a list of individual attributes to store default attributes. Attribute groups are more flexible than a list of attributes because groups provide support for attribute visibility. So, add support for default attribute groups to kobj_type. In future patches, the existing uses of kobj_type’s attribute list will be converted to attribute groups. When that is complete, kobj_type’s attribute list, “default_attrs”, will be removed. Signed-off-by: Kimberly Brown <kimbrownkd@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--include/linux/kobject.h3
-rw-r--r--lib/kobject.c14
2 files changed, 16 insertions, 1 deletions
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 1ab0d624fb36..e2ca0a292e21 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -139,7 +139,8 @@ static inline bool kobject_has_children(struct kobject *kobj)
139struct kobj_type { 139struct kobj_type {
140 void (*release)(struct kobject *kobj); 140 void (*release)(struct kobject *kobj);
141 const struct sysfs_ops *sysfs_ops; 141 const struct sysfs_ops *sysfs_ops;
142 struct attribute **default_attrs; 142 struct attribute **default_attrs; /* use default_groups instead */
143 const struct attribute_group **default_groups;
143 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj); 144 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
144 const void *(*namespace)(struct kobject *kobj); 145 const void *(*namespace)(struct kobject *kobj);
145 void (*get_ownership)(struct kobject *kobj, kuid_t *uid, kgid_t *gid); 146 void (*get_ownership)(struct kobject *kobj, kuid_t *uid, kgid_t *gid);
diff --git a/lib/kobject.c b/lib/kobject.c
index aa89edcd2b63..ede40005db28 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -82,6 +82,7 @@ static int populate_dir(struct kobject *kobj)
82 82
83static int create_dir(struct kobject *kobj) 83static int create_dir(struct kobject *kobj)
84{ 84{
85 const struct kobj_type *ktype = get_ktype(kobj);
85 const struct kobj_ns_type_operations *ops; 86 const struct kobj_ns_type_operations *ops;
86 int error; 87 int error;
87 88
@@ -95,6 +96,14 @@ static int create_dir(struct kobject *kobj)
95 return error; 96 return error;
96 } 97 }
97 98
99 if (ktype) {
100 error = sysfs_create_groups(kobj, ktype->default_groups);
101 if (error) {
102 sysfs_remove_dir(kobj);
103 return error;
104 }
105 }
106
98 /* 107 /*
99 * @kobj->sd may be deleted by an ancestor going away. Hold an 108 * @kobj->sd may be deleted by an ancestor going away. Hold an
100 * extra reference so that it stays until @kobj is gone. 109 * extra reference so that it stays until @kobj is gone.
@@ -584,11 +593,16 @@ EXPORT_SYMBOL_GPL(kobject_move);
584void kobject_del(struct kobject *kobj) 593void kobject_del(struct kobject *kobj)
585{ 594{
586 struct kernfs_node *sd; 595 struct kernfs_node *sd;
596 const struct kobj_type *ktype = get_ktype(kobj);
587 597
588 if (!kobj) 598 if (!kobj)
589 return; 599 return;
590 600
591 sd = kobj->sd; 601 sd = kobj->sd;
602
603 if (ktype)
604 sysfs_remove_groups(kobj, ktype->default_groups);
605
592 sysfs_remove_dir(kobj); 606 sysfs_remove_dir(kobj);
593 sysfs_put(sd); 607 sysfs_put(sd);
594 608