From: Maneesh Soni <maneesh@in.ibm.com>
To: Al Viro <viro@parcelfarce.linux.theplanet.co.uk>,
Greg KH <greg@kroah.com>, Patrick Mochel <mochel@osdl.org>,
Christian Borntraeger <CBORNTRA@de.ibm.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
Dipankar Sarma <dipankar@in.ibm.com>
Subject: Re: [RFC 4/5] sysfs-attr_group.patch
Date: Wed, 12 Nov 2003 17:56:15 +0530 [thread overview]
Message-ID: <20031112122615.GH14580@in.ibm.com> (raw)
In-Reply-To: <20031112122549.GG14580@in.ibm.com>
o This patch creates attribute group for the given kobject. Again here we don;t
create the sysfs directory but just allocated sysfs_dirent for the attribute
group and links it to the kobject's hierarchy.
fs/sysfs/group.c | 75 +++++++++++++++++++++++++++++++++----------------------
1 files changed, 45 insertions(+), 30 deletions(-)
diff -puN fs/sysfs/group.c~sysfs-attr_group fs/sysfs/group.c
--- linux-2.6.0-test9/fs/sysfs/group.c~sysfs-attr_group 2003-11-12 16:30:55.000000000 +0530
+++ linux-2.6.0-test9-maneesh/fs/sysfs/group.c 2003-11-12 16:30:55.000000000 +0530
@@ -12,70 +12,85 @@
#include <linux/module.h>
#include <linux/dcache.h>
#include <linux/err.h>
+#include <linux/namei.h>
#include "sysfs.h"
-static void remove_files(struct dentry * dir,
+static void remove_files(struct sysfs_dirent * sd,
const struct attribute_group * grp)
{
struct attribute *const* attr;
for (attr = grp->attrs; *attr; attr++)
- sysfs_hash_and_remove(dir,(*attr)->name);
+ sysfs_hash_and_remove(sd, (*attr)->name);
}
-static int create_files(struct dentry * dir,
+static int create_files(struct sysfs_dirent * parent_sd,
const struct attribute_group * grp)
{
struct attribute *const* attr;
int error = 0;
for (attr = grp->attrs; *attr && !error; attr++) {
- error = sysfs_add_file(dir,*attr);
+ error = sysfs_add_file(parent_sd, *attr);
}
if (error)
- remove_files(dir,grp);
+ remove_files(parent_sd, grp);
return error;
}
-
int sysfs_create_group(struct kobject * kobj,
const struct attribute_group * grp)
{
- struct dentry * dir;
- int error;
+ struct sysfs_dirent * sd;
+ int error = 0;
- if (grp->name) {
- error = sysfs_create_subdir(kobj,grp->name,&dir);
- if (error)
- return error;
- } else
- dir = kobj->dentry;
- dir = dget(dir);
- if ((error = create_files(dir,grp))) {
- if (grp->name)
- sysfs_remove_subdir(dir);
- dput(dir);
+ if (!kobj || !grp)
+ return -EINVAL;
+
+ sd = sysfs_alloc_dirent(kobj->s_dirent, (void *) grp, SYSFS_KOBJ_ATTR_GROUP);
+ if (IS_ERR(sd))
+ return PTR_ERR(sd);
+
+ if ((error = create_files(sd, grp))) {
+ sysfs_remove_group(kobj, grp);
}
+
return error;
}
void sysfs_remove_group(struct kobject * kobj,
const struct attribute_group * grp)
{
- struct dentry * dir;
+ struct sysfs_dirent * tmp_sd;
+ struct sysfs_dirent * grp_sd = NULL;
+ struct dentry * grp_dentry;
- if (grp->name)
- dir = sysfs_get_dentry(kobj->dentry,grp->name);
- else
- dir = kobj->dentry;
-
- remove_files(dir,grp);
- dput(dir);
- if (grp->name)
- sysfs_remove_subdir(dir);
-}
+ if (grp->name) {
+ down_read(&kobj->s_dirent->s_rwsem);
+ list_for_each_entry(tmp_sd, &kobj->s_dirent->s_children, s_sibling) {
+ if (!strcmp(grp->name, sysfs_get_name(tmp_sd))) {
+ grp_sd = tmp_sd;
+ break;
+ }
+ }
+ up_read(&kobj->s_dirent->s_rwsem);
+ } else
+ grp_sd = kobj->s_dirent;
+
+ if (grp_sd->s_dentry) {
+ spin_lock(&dcache_lock);
+ grp_dentry = dget_locked(grp_sd->s_dentry);
+ spin_unlock(&dcache_lock);
+ remove_files(grp_sd, grp);
+ if (grp->name)
+ sysfs_remove_subdir(grp_dentry);
+ dput(grp_dentry);
+ } else
+ sysfs_free_children(grp_sd);
+ sysfs_free_dirent(kobj->s_dirent, grp->name);
+}
EXPORT_SYMBOL(sysfs_create_group);
EXPORT_SYMBOL(sysfs_remove_group);
_
--
Maneesh Soni
Linux Technology Center,
IBM Software Lab, Bangalore, India
email: maneesh@in.ibm.com
Phone: 91-80-5044999 Fax: 91-80-5268553
T/L : 9243696
next prev parent reply other threads:[~2003-11-12 12:30 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-12 12:23 [RFC 0/5] Backing Store for sysfs (Overhauled) Maneesh Soni
2003-11-12 12:25 ` [RFC 1/5] sysfs-backing-store.patch Maneesh Soni
2003-11-12 12:25 ` [RFC 2/5] sysfs-dir.patch Maneesh Soni
2003-11-12 12:25 ` [RFC 3/5] sysfs-file.patch Maneesh Soni
2003-11-12 12:26 ` Maneesh Soni [this message]
2003-11-12 12:26 ` [RFC 5/5] sysfs-symlink.patch Maneesh Soni
2003-11-12 14:39 ` [RFC 2/5] sysfs-dir.patch viro
2003-11-12 16:00 ` [RFC 0/5] Backing Store for sysfs (Overhauled) Greg KH
2003-11-12 16:27 ` Dipankar Sarma
2003-11-12 16:39 ` Greg KH
2003-11-13 19:34 ` Patrick Mochel
2003-11-13 19:55 ` Dipankar Sarma
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20031112122615.GH14580@in.ibm.com \
--to=maneesh@in.ibm.com \
--cc=CBORNTRA@de.ibm.com \
--cc=dipankar@in.ibm.com \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mochel@osdl.org \
--cc=viro@parcelfarce.linux.theplanet.co.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.