All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <htejun@gmail.com>
To: gregkh@suse.de, dmitry.torokhov@gmail.com,
	cornelia.huck@de.ibm.com, oneukum@suse.de, rpurdie@rpsys.net,
	stern@rowland.harvard.edu, maneesh@in.ibm.com,
	akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
	htejun@gmail.com
Cc: Tejun Heo <htejun@gmail.com>
Subject: [PATCH 20/21] sysfs: separate out sysfs_attach_dentry()
Date: Sat, 28 Apr 2007 22:39:42 +0900	[thread overview]
Message-ID: <11777675822227-git-send-email-htejun@gmail.com> (raw)
In-Reply-To: <11777675753460-git-send-email-htejun@gmail.com>

Consolidate sd <-> dentry association into sysfs_attach_dentry() and
call it after dentry and inode are properly set up.  This is in
preparation of sysfs_drop_dentry() updates.

Signed-off-by: Tejun Heo <htejun@gmail.com>
---
 fs/sysfs/dir.c   |   48 +++++++++++++++++++++---------------------------
 fs/sysfs/inode.c |    4 ++--
 fs/sysfs/sysfs.h |    3 ++-
 3 files changed, 25 insertions(+), 30 deletions(-)

diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 265042a..1a45a1d 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -130,14 +130,19 @@ struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type)
 	return NULL;
 }
 
+static void sysfs_attach_dentry(struct sysfs_dirent *sd, struct dentry *dentry)
+{
+	dentry->d_op = &sysfs_dentry_ops;
+	dentry->d_fsdata = sysfs_get(sd);
+	sd->s_dentry = dentry;
+	d_rehash(dentry);
+}
+
 void sysfs_attach_dirent(struct sysfs_dirent *sd,
 			 struct sysfs_dirent *parent_sd, struct dentry *dentry)
 {
-	if (dentry) {
-		sd->s_dentry = dentry;
-		dentry->d_fsdata = sysfs_get(sd);
-		dentry->d_op = &sysfs_dentry_ops;
-	}
+	if (dentry)
+		sysfs_attach_dentry(sd, dentry);
 
 	if (parent_sd) {
 		sd->s_parent = sysfs_get(parent_sd);
@@ -217,15 +222,13 @@ static int create_dir(struct kobject *kobj, struct dentry *parent,
 	if (!sd)
 		goto out_drop;
 	sd->s_elem.dir.kobj = kobj;
-	sysfs_attach_dirent(sd, parent->d_fsdata, dentry);
 
-	error = sysfs_create(dentry, mode, init_dir);
+	error = sysfs_create(sd, dentry, mode, init_dir);
 	if (error)
 		goto out_sput;
 
 	inc_nlink(parent->d_inode);
-	dentry->d_op = &sysfs_dentry_ops;
-	d_rehash(dentry);
+	sysfs_attach_dirent(sd, parent->d_fsdata, dentry);
 
 	*p_dentry = dentry;
 	error = 0;
@@ -296,36 +299,28 @@ static int sysfs_attach_attr(struct sysfs_dirent * sd, struct dentry * dentry)
                 init = init_file;
         }
 
-	dentry->d_fsdata = sysfs_get(sd);
-	sd->s_dentry = dentry;
-	error = sysfs_create(dentry, (attr->mode & S_IALLUGO) | S_IFREG, init);
-	if (error) {
-		sysfs_put(sd);
+	error = sysfs_create(sd, dentry,
+			     (attr->mode & S_IALLUGO) | S_IFREG, init);
+	if (error)
 		return error;
-	}
 
         if (bin_attr) {
 		dentry->d_inode->i_size = bin_attr->size;
 		dentry->d_inode->i_fop = &bin_fops;
 	}
-	dentry->d_op = &sysfs_dentry_ops;
-	d_rehash(dentry);
+
+	sysfs_attach_dentry(sd, dentry);
 
 	return 0;
 }
 
 static int sysfs_attach_link(struct sysfs_dirent * sd, struct dentry * dentry)
 {
-	int err = 0;
+	int err;
 
-	dentry->d_fsdata = sysfs_get(sd);
-	sd->s_dentry = dentry;
-	err = sysfs_create(dentry, S_IFLNK|S_IRWXUGO, init_symlink);
-	if (!err) {
-		dentry->d_op = &sysfs_dentry_ops;
-		d_rehash(dentry);
-	} else
-		sysfs_put(sd);
+	err = sysfs_create(sd, dentry, S_IFLNK|S_IRWXUGO, init_symlink);
+	if (!err)
+		sysfs_attach_dentry(sd, dentry);
 
 	return err;
 }
@@ -755,7 +750,6 @@ struct dentry *sysfs_create_shadow_dir(struct kobject *kobj)
 	d_instantiate(shadow, igrab(inode));
 	inc_nlink(inode);
 	inc_nlink(parent->d_inode);
-	shadow->d_op = &sysfs_dentry_ops;
 
 	dget(shadow);		/* Extra count - pin the dentry in core */
 
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index b72d18a..10aa33f 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -155,13 +155,13 @@ struct inode * sysfs_new_inode(mode_t mode, struct sysfs_dirent * sd)
 	return inode;
 }
 
-int sysfs_create(struct dentry * dentry, int mode, int (*init)(struct inode *))
+int sysfs_create(struct sysfs_dirent *sd, struct dentry *dentry, int mode,
+		 int (*init)(struct inode *))
 {
 	int error = 0;
 	struct inode * inode = NULL;
 	if (dentry) {
 		if (!dentry->d_inode) {
-			struct sysfs_dirent * sd = dentry->d_fsdata;
 			if ((inode = sysfs_new_inode(mode, sd))) {
 				if (dentry->d_parent && dentry->d_parent->d_inode) {
 					struct inode *p_inode = dentry->d_parent->d_inode;
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index 537c64b..06a237e 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -58,7 +58,8 @@ extern struct kmem_cache *sysfs_dir_cachep;
 
 extern void sysfs_delete_inode(struct inode *inode);
 extern struct inode * sysfs_new_inode(mode_t mode, struct sysfs_dirent *);
-extern int sysfs_create(struct dentry *, int mode, int (*init)(struct inode *));
+extern int sysfs_create(struct sysfs_dirent *sd, struct dentry *dentry,
+			int mode, int (*init)(struct inode *));
 
 extern void release_sysfs_dirent(struct sysfs_dirent * sd);
 extern int sysfs_dirent_exist(struct sysfs_dirent *, const unsigned char *);
-- 
1.5.0.3



  parent reply	other threads:[~2007-04-28 13:40 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-28 13:39 [PATCHSET] sysfs: sysfs rework, take #2 Tejun Heo
2007-04-28 13:39 ` [PATCH 01/21] idr: fix obscure bug in allocation path Tejun Heo
2007-04-28 13:39 ` [PATCH 02/21] idr: separate out idr_mark_full() Tejun Heo
2007-04-28 13:39 ` [PATCH 07/21] sysfs: fix error handling in binattr write() Tejun Heo
2007-04-28 13:39 ` [PATCH 04/21] sysfs: move release_sysfs_dirent() to dir.c Tejun Heo
2007-04-28 13:39 ` [PATCH 06/21] sysfs: make sysfs_put() ignore NULL sd Tejun Heo
2007-04-28 13:39 ` [PATCH 05/21] sysfs: allocate inode number using ida Tejun Heo
2007-04-28 13:39 ` [PATCH 03/21] ida: implement idr based id allocator Tejun Heo
2007-04-28 13:39 ` [PATCH 12/21] sysfs: add sysfs_dirent->s_name Tejun Heo
2007-04-28 13:39 ` [PATCH 10/21] sysfs: consolidate sysfs_dirent creation functions Tejun Heo
2007-04-28 13:39 ` [PATCH 11/21] sysfs: add sysfs_dirent->s_parent Tejun Heo
2007-04-28 13:39 ` [PATCH 09/21] sysfs: flatten and fix sysfs_rename_dir() error handling Tejun Heo
2007-04-28 13:39 ` [PATCH 08/21] sysfs: flatten cleanup paths in sysfs_add_link() and create_dir() Tejun Heo
2007-04-28 13:39 ` [PATCH 18/21] sysfs: kill attribute file orphaning Tejun Heo
2007-04-28 13:39 ` [PATCH 15/21] sysfs: reimplement symlink using sysfs_dirent tree Tejun Heo
2007-04-28 13:39 ` [PATCH 19/21] sysfs: kill unnecessary attribute->owner Tejun Heo
2007-04-28 13:39 ` [PATCH 16/21] sysfs: implement bin_buffer Tejun Heo
2007-05-01 14:25   ` Satyam Sharma
     [not found]     ` <463753DB.2060101@gmail.com>
2007-05-01 19:37       ` Satyam Sharma
2007-05-01 20:04         ` Satyam Sharma
2007-05-02 11:29           ` Tejun Heo
2007-04-28 13:39 ` [PATCH 14/21] sysfs: implement kobj_sysfs_assoc_lock Tejun Heo
2007-04-28 13:39 ` [PATCH 13/21] sysfs: make sysfs_dirent->s_element a union Tejun Heo
2007-04-28 13:39 ` Tejun Heo [this message]
2007-04-28 13:39 ` [PATCH 17/21] sysfs: implement sysfs_dirent active reference and immediate disconnect Tejun Heo
2007-04-28 13:39 ` [PATCH 21/21] sysfs: reimplement syfs_drop_dentry() Tejun Heo
2007-04-28 14:28 ` [PATCHSET] sysfs: sysfs rework, take #2 Alan Stern
2007-04-28 16:06   ` Tejun Heo
2007-05-02 12:38 ` Cornelia Huck
2007-05-02 13:04   ` Tejun Heo

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=11777675822227-git-send-email-htejun@gmail.com \
    --to=htejun@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cornelia.huck@de.ibm.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maneesh@in.ibm.com \
    --cc=oneukum@suse.de \
    --cc=rpurdie@rpsys.net \
    --cc=stern@rowland.harvard.edu \
    /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.