Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=d4acd722b7bb5f48b9fc3848e8c2a845b100d84f
Commit:     d4acd722b7bb5f48b9fc3848e8c2a845b100d84f
Parent:     d52b3815a52456dcf1a45fbc344e23bb643b2bda
Author:     James Bottomley <[EMAIL PROTECTED]>
AuthorDate: Wed Oct 31 09:38:04 2007 -0500
Committer:  James Bottomley <[EMAIL PROTECTED]>
CommitDate: Wed Jan 23 11:29:18 2008 -0600

    [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 <[EMAIL PROTECTED]>
    Signed-off-by: James Bottomley <[EMAIL PROTECTED]>
---
 fs/sysfs/group.c      |   26 ++++++++++++++++----------
 include/linux/sysfs.h |    2 ++
 kernel/params.c       |    2 +-
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index d197237..0871c3d 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -16,25 +16,31 @@
 #include "sysfs.h"
 
 
-static void remove_files(struct sysfs_dirent *dir_sd,
+static void remove_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
                         const struct attribute_group *grp)
 {
        struct attribute *const* attr;
+       int i;
 
-       for (attr = grp->attrs; *attr; attr++)
-               sysfs_hash_and_remove(dir_sd, (*attr)->name);
+       for (i = 0, attr = grp->attrs; *attr; i++, attr++)
+               if (!grp->is_visible ||
+                   grp->is_visible(kobj, *attr, i))
+                       sysfs_hash_and_remove(dir_sd, (*attr)->name);
 }
 
-static int create_files(struct sysfs_dirent *dir_sd,
+static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
                        const struct attribute_group *grp)
 {
        struct attribute *const* attr;
-       int error = 0;
+       int error = 0, i;
 
-       for (attr = grp->attrs; *attr && !error; attr++)
-               error = sysfs_add_file(dir_sd, *attr, SYSFS_KOBJ_ATTR);
+       for (i = 0, attr = grp->attrs; *attr && !error; i++, attr++)
+               if (!grp->is_visible ||
+                   grp->is_visible(kobj, *attr, i))
+                       error |=
+                               sysfs_add_file(dir_sd, *attr, SYSFS_KOBJ_ATTR);
        if (error)
-               remove_files(dir_sd, grp);
+               remove_files(dir_sd, kobj, grp);
        return error;
 }
 
@@ -54,7 +60,7 @@ int sysfs_create_group(struct kobject * kobj,
        } else
                sd = kobj->sd;
        sysfs_get(sd);
-       error = create_files(sd, grp);
+       error = create_files(sd, kobj, grp);
        if (error) {
                if (grp->name)
                        sysfs_remove_subdir(sd);
@@ -75,7 +81,7 @@ void sysfs_remove_group(struct kobject * kobj,
        } else
                sd = sysfs_get(dir_sd);
 
-       remove_files(sd, grp);
+       remove_files(sd, kobj, grp);
        if (grp->name)
                sysfs_remove_subdir(sd);
 
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 149ab62..8027104 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -32,6 +32,8 @@ struct attribute {
 
 struct attribute_group {
        const char              *name;
+       int                     (*is_visible)(struct kobject *,
+                                             struct attribute *, int);
        struct attribute        **attrs;
 };
 
diff --git a/kernel/params.c b/kernel/params.c
index 7686417..dfef464 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -472,7 +472,7 @@ param_sysfs_setup(struct module_kobject *mk,
                        sizeof(mp->grp.attrs[0]));
        size[1] = (valid_attrs + 1) * sizeof(mp->grp.attrs[0]);
 
-       mp = kmalloc(size[0] + size[1], GFP_KERNEL);
+       mp = kzalloc(size[0] + size[1], GFP_KERNEL);
        if (!mp)
                return ERR_PTR(-ENOMEM);
 
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to