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,
linux-kernel@vger.kernel.org, htejun@gmail.com
Cc: Tejun Heo <htejun@gmail.com>
Subject: [PATCH 4/5] sysfs: use iget_locked() instead of new_inode()
Date: Tue, 29 May 2007 01:10:26 +0900 [thread overview]
Message-ID: <11803686261683-git-send-email-htejun@gmail.com> (raw)
In-Reply-To: <1180368625600-git-send-email-htejun@gmail.com>
After dentry is reclaimed, sysfs always used to allocate new dentry
and inode if the file is accessed again. This causes problem with
operations which only pin the inode. For example, if inotify watch is
added to a sysfs file and the dentry for the file is reclaimed, the
next update event creates new dentry and new inode making the inotify
watch miss all the events from there on.
This patch fixes it by using iget_locked() instead of new_inode().
sysfs_new_inode() is renamed to sysfs_get_inode() and inode is
initialized iff the inode is newly allocated. sysfs_instantiate() is
responsible for unlocking new inodes.
Signed-off-by: Tejun Heo <htejun@gmail.com>
---
fs/sysfs/dir.c | 37 +++++++++++++++++++++----------------
fs/sysfs/inode.c | 24 +++++++++++++++---------
fs/sysfs/sysfs.h | 2 +-
3 files changed, 37 insertions(+), 26 deletions(-)
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index bbf3525..06dff2c 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -219,14 +219,16 @@ static int create_dir(struct kobject *ko
goto out_drop;
sd->s_elem.dir.kobj = kobj;
- inode = sysfs_new_inode(sd);
+ inode = sysfs_get_inode(sd);
if (!inode)
goto out_sput;
- inode->i_op = &sysfs_dir_inode_operations;
- inode->i_fop = &sysfs_dir_operations;
- /* directory inodes start off with i_nlink == 2 (for "." entry) */
- inc_nlink(inode);
+ if (inode->i_state & I_NEW) {
+ inode->i_op = &sysfs_dir_inode_operations;
+ inode->i_fop = &sysfs_dir_operations;
+ /* directory inodes start off with i_nlink == 2 (for ".") */
+ inc_nlink(inode);
+ }
/* link in */
error = -EEXIST;
@@ -310,20 +312,23 @@ static struct dentry * sysfs_lookup(stru
return NULL;
/* attach dentry and inode */
- inode = sysfs_new_inode(sd);
+ inode = sysfs_get_inode(sd);
if (!inode)
return ERR_PTR(-ENOMEM);
- /* initialize inode according to type */
- if (sd->s_type & SYSFS_KOBJ_ATTR) {
- inode->i_size = PAGE_SIZE;
- inode->i_fop = &sysfs_file_operations;
- } else if (sd->s_type & SYSFS_KOBJ_BIN_ATTR) {
- struct bin_attribute *bin_attr = sd->s_elem.bin_attr.bin_attr;
- inode->i_size = bin_attr->size;
- inode->i_fop = &bin_fops;
- } else if (sd->s_type & SYSFS_KOBJ_LINK)
- inode->i_op = &sysfs_symlink_inode_operations;
+ if (inode->i_state & I_NEW) {
+ /* initialize inode according to type */
+ if (sd->s_type & SYSFS_KOBJ_ATTR) {
+ inode->i_size = PAGE_SIZE;
+ inode->i_fop = &sysfs_file_operations;
+ } else if (sd->s_type & SYSFS_KOBJ_BIN_ATTR) {
+ struct bin_attribute *bin_attr =
+ sd->s_elem.bin_attr.bin_attr;
+ inode->i_size = bin_attr->size;
+ inode->i_fop = &bin_fops;
+ } else if (sd->s_type & SYSFS_KOBJ_LINK)
+ inode->i_op = &sysfs_symlink_inode_operations;
+ }
sysfs_instantiate(dentry, inode);
sysfs_attach_dentry(sd, dentry);
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index 3b2dc2a..167c7fb 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -152,10 +152,12 @@ void sysfs_init_inode(struct sysfs_diren
}
/**
- * sysfs_new_inode - allocate new inode for sysfs_dirent
+ * sysfs_get_inode - get inode for sysfs_dirent
* @sd: sysfs_dirent to allocate inode for
*
- * Allocate inode for @sd and initialize basics.
+ * Get inode for @sd. If such inode doesn't exist, a new inode
+ * is allocated and basics are initialized. New inode is
+ * returned locked.
*
* LOCKING:
* Kernel thread context (may sleep).
@@ -163,12 +165,12 @@ void sysfs_init_inode(struct sysfs_diren
* RETURNS:
* Pointer to allocated inode on success, NULL on failure.
*/
-struct inode * sysfs_new_inode(struct sysfs_dirent *sd)
+struct inode * sysfs_get_inode(struct sysfs_dirent *sd)
{
struct inode *inode;
- inode = new_inode(sysfs_sb);
- if (inode)
+ inode = iget_locked(sysfs_sb, sd->s_ino);
+ if (inode && (inode->i_state & I_NEW))
sysfs_init_inode(sd, inode);
return inode;
@@ -179,7 +181,7 @@ struct inode * sysfs_new_inode(struct sy
* @dentry: dentry to be instantiated
* @inode: inode associated with @sd
*
- * Instantiate @dentry with @inode.
+ * Unlock @inode if locked and instantiate @dentry with @inode.
*
* LOCKING:
* None.
@@ -188,9 +190,13 @@ void sysfs_instantiate(struct dentry *de
{
BUG_ON(!dentry || dentry->d_inode);
- if (dentry->d_parent && dentry->d_parent->d_inode) {
- struct inode *p_inode = dentry->d_parent->d_inode;
- p_inode->i_mtime = p_inode->i_ctime = CURRENT_TIME;
+ if (inode->i_state & I_NEW) {
+ unlock_new_inode(inode);
+
+ if (dentry->d_parent && dentry->d_parent->d_inode) {
+ struct inode *p_inode = dentry->d_parent->d_inode;
+ p_inode->i_mtime = p_inode->i_ctime = CURRENT_TIME;
+ }
}
d_instantiate(dentry, inode);
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index 143fdbe..627bf39 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -58,7 +58,7 @@ extern struct kmem_cache *sysfs_dir_cach
extern void sysfs_delete_inode(struct inode *inode);
extern void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode);
-extern struct inode * sysfs_new_inode(struct sysfs_dirent *sd);
+extern struct inode * sysfs_get_inode(struct sysfs_dirent *sd);
extern void sysfs_instantiate(struct dentry *dentry, struct inode *inode);
extern void release_sysfs_dirent(struct sysfs_dirent * sd);
--
1.4.3.4
next prev parent reply other threads:[~2007-05-28 16:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-28 16:10 [PATCHSET 2.6.22-rc2-mm1] sysfs: assorted fixes Tejun Heo
2007-05-28 16:10 ` [PATCH 1/5] sysfs: make sysfs_alloc_ino() static Tejun Heo
2007-05-28 16:10 ` [PATCH 2/5] sysfs: fix parent refcounting during rename and move Tejun Heo
2007-05-28 16:10 ` Tejun Heo [this message]
2007-05-28 16:10 ` [PATCH 3/5] sysfs: reorganize sysfs_new_indoe() and sysfs_create() Tejun Heo
2007-05-28 16:10 ` [PATCH 5/5] sysfs: fix root sysfs_dirent -> root dentry association Tejun Heo
2007-05-29 14:02 ` [PATCHSET 2.6.22-rc2-mm1] sysfs: assorted fixes Cornelia Huck
2007-05-29 15:58 ` Greg KH
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=11803686261683-git-send-email-htejun@gmail.com \
--to=htejun@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox