aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Bottomley <James.Bottomley@HansenPartnership.com>2007-10-31 10:38:04 -0400
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2008-01-23 12:29:18 -0500
commitd4acd722b7bb5f48b9fc3848e8c2a845b100d84f (patch)
tree24c0ccb9cd13d79b47588d44b27b3f1eb91a0ec7
parentd52b3815a52456dcf1a45fbc344e23bb643b2bda (diff)
[SCSI] sysfs: add filter function to groups
This patch allows the various users of attribute_groups to selectively allow the appearance of group attributes. The primary consumer of this will be the transport classes in which we currently have elaborate attribute selection algorithms to do this same thing. Acked-by: Greg KH <greg@kroah.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
-rw-r--r--fs/sysfs/group.c26
-rw-r--r--include/linux/sysfs.h2
-rw-r--r--kernel/params.c2
3 files changed, 19 insertions, 11 deletions
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index d1972374655a..0871c3dadce1 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -16,25 +16,31 @@
16#include "sysfs.h" 16#include "sysfs.h"
17 17
18 18
19static void remove_files(struct sysfs_dirent *dir_sd, 19static void remove_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
20 const struct attribute_group *grp) 20 const struct attribute_group *grp)
21{ 21{
22 struct attribute *const* attr; 22 struct attribute *const* attr;
23 int i;
23 24
24 for (attr = grp->attrs; *attr; attr++) 25 for (i = 0, attr = grp->attrs; *attr; i++, attr++)
25 sysfs_hash_and_remove(dir_sd, (*attr)->name); 26 if (!grp->is_visible ||
27 grp->is_visible(kobj, *attr, i))
28 sysfs_hash_and_remove(dir_sd, (*attr)->name);
26} 29}
27 30
28static int create_files(struct sysfs_dirent *dir_sd, 31static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
29 const struct attribute_group *grp) 32 const struct attribute_group *grp)
30{ 33{
31 struct attribute *const* attr; 34 struct attribute *const* attr;
32 int error = 0; 35 int error = 0, i;
33 36
34 for (attr = grp->attrs; *attr && !error; attr++) 37 for (i = 0, attr = grp->attrs; *attr && !error; i++, attr++)
35 error = sysfs_add_file(dir_sd, *attr, SYSFS_KOBJ_ATTR); 38 if (!grp->is_visible ||
39 grp->is_visible(kobj, *attr, i))
40 error |=
41 sysfs_add_file(dir_sd, *attr, SYSFS_KOBJ_ATTR);
36 if (error) 42 if (error)
37 remove_files(dir_sd, grp); 43 remove_files(dir_sd, kobj, grp);
38 return error; 44 return error;
39} 45}
40 46
@@ -54,7 +60,7 @@ int sysfs_create_group(struct kobject * kobj,
54 } else 60 } else
55 sd = kobj->sd; 61 sd = kobj->sd;
56 sysfs_get(sd); 62 sysfs_get(sd);
57 error = create_files(sd, grp); 63 error = create_files(sd, kobj, grp);
58 if (error) { 64 if (error) {
59 if (grp->name) 65 if (grp->name)
60 sysfs_remove_subdir(sd); 66 sysfs_remove_subdir(sd);
@@ -75,7 +81,7 @@ void sysfs_remove_group(struct kobject * kobj,
75 } else 81 } else
76 sd = sysfs_get(dir_sd); 82 sd = sysfs_get(dir_sd);
77 83
78 remove_files(sd, grp); 84 remove_files(sd, kobj, grp);
79 if (grp->name) 85 if (grp->name)
80 sysfs_remove_subdir(sd); 86 sysfs_remove_subdir(sd);
81 87
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 149ab62329e2..802710438a9e 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -32,6 +32,8 @@ struct attribute {
32 32
33struct attribute_group { 33struct attribute_group {
34 const char *name; 34 const char *name;
35 int (*is_visible)(struct kobject *,
36 struct attribute *, int);
35 struct attribute **attrs; 37 struct attribute **attrs;
36}; 38};
37 39
diff --git a/kernel/params.c b/kernel/params.c
index 7686417ee00e..dfef46474e55 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -472,7 +472,7 @@ param_sysfs_setup(struct module_kobject *mk,
472 sizeof(mp->grp.attrs[0])); 472 sizeof(mp->grp.attrs[0]));
473 size[1] = (valid_attrs + 1) * sizeof(mp->grp.attrs[0]); 473 size[1] = (valid_attrs + 1) * sizeof(mp->grp.attrs[0]);
474 474
475 mp = kmalloc(size[0] + size[1], GFP_KERNEL); 475 mp = kzalloc(size[0] + size[1], GFP_KERNEL);
476 if (!mp) 476 if (!mp)
477 return ERR_PTR(-ENOMEM); 477 return ERR_PTR(-ENOMEM);
478 478