[Devel] [PATCH rh7 7/9] sysfs: create bin_attributes under the requested group

Vladimir Davydov vdavydov at virtuozzo.com
Mon Oct 26 00:49:23 PDT 2015


From: Cody P Schafer <cody at linux.vnet.ibm.com>

bin_attributes created/updated in create_files() (such as those listed
via (struct device).attribute_groups) were not placed under the
specified group, and instead appeared in the base kobj directory.

Fix this by making bin_attributes use creating code similar to normal
attributes.

A quick grep shows that no one is using bin_attrs in a named attribute
group yet, so we can do this without breaking anything in usespace.

Note that I do not add is_visible() support to
bin_attributes, though that could be done as well.

Signed-off-by: Cody P Schafer <cody at linux.vnet.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
(cherry picked from commit aabaf4c2050d21d39fe11eec889c508e84d6a328)
Signed-off-by: Vladimir Davydov <vdavydov at virtuozzo.com>

Conflicts:
	fs/sysfs/cgroup.c
---
 fs/sysfs/group.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index 5f92cd2f61c1..c2f76a5e2f61 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -29,7 +29,8 @@ static void remove_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
 			sysfs_hash_and_remove(dir_sd, NULL, (*attr)->name);
 	if (grp->bin_attrs)
 		for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++)
-			sysfs_remove_bin_file(kobj, *bin_attr);
+			sysfs_hash_and_remove(dir_sd, NULL,
+					      (*bin_attr)->attr.name);
 }
 
 static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
@@ -71,8 +72,10 @@ static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
 	if (grp->bin_attrs) {
 		for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++) {
 			if (update)
-				sysfs_remove_bin_file(kobj, *bin_attr);
-			error = sysfs_create_bin_file(kobj, *bin_attr);
+				sysfs_hash_and_remove(dir_sd, NULL,
+						      (*bin_attr)->attr.name);
+			error = sysfs_add_file(dir_sd, &(*bin_attr)->attr,
+					       SYSFS_KOBJ_BIN_ATTR);
 			if (error)
 				break;
 		}
-- 
2.1.4




More information about the Devel mailing list