From: Tejun Heo <htejun@gmail.com>
To: greg@kroah.com, 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 01/11] sysfs: make sysfs_drop_dentry() access inodes using ilookup()
Date: Thu, 14 Jun 2007 04:27:21 +0900 [thread overview]
Message-ID: <11817628414141-git-send-email-htejun@gmail.com> (raw)
In-Reply-To: <1181762840495-git-send-email-htejun@gmail.com>
sysfs_drop_dentry() used to go through sd->s_dentry and
sd->s_parent->s_dentry to access the inodes. This is incorrect
because inode can be cached without dentry.
This patch makes sysfs_drop_dentry() access inodes using ilookup() on
sd->s_ino. This is both correct and simpler.
Signed-off-by: Tejun Heo <htejun@gmail.com>
---
fs/sysfs/inode.c | 63 ++++++++++++++++++++++++------------------------------
1 files changed, 28 insertions(+), 35 deletions(-)
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index ee31bf3..63daa06 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -219,9 +219,9 @@ void sysfs_instantiate(struct dentry *dentry, struct inode *inode)
*/
void sysfs_drop_dentry(struct sysfs_dirent *sd)
{
- struct dentry *dentry = NULL, *parent = NULL;
- struct inode *dir;
+ struct dentry *dentry = NULL;
struct timespec curtime;
+ struct inode *inode;
/* We're not holding a reference to ->s_dentry dentry but the
* field will stay valid as long as sysfs_lock is held.
@@ -229,19 +229,9 @@ void sysfs_drop_dentry(struct sysfs_dirent *sd)
spin_lock(&sysfs_lock);
spin_lock(&dcache_lock);
+ /* drop dentry if it's there and dput() didn't kill it yet */
if (sd->s_dentry && sd->s_dentry->d_inode) {
- /* get dentry if it's there and dput() didn't kill it yet */
dentry = dget_locked(sd->s_dentry);
- parent = dentry->d_parent;
- } else if (sd->s_parent->s_dentry->d_inode) {
- /* We need to update the parent even if dentry for the
- * victim itself doesn't exist.
- */
- parent = dget_locked(sd->s_parent->s_dentry);
- }
-
- /* drop */
- if (dentry) {
spin_lock(&dentry->d_lock);
__d_drop(dentry);
spin_unlock(&dentry->d_lock);
@@ -250,36 +240,39 @@ void sysfs_drop_dentry(struct sysfs_dirent *sd)
spin_unlock(&dcache_lock);
spin_unlock(&sysfs_lock);
- /* nothing to do if the parent isn't in dcache */
- if (!parent)
- return;
+ dput(dentry);
+ /* XXX: unpin if directory, this will go away soon */
+ if (sd->s_type & SYSFS_DIR)
+ dput(dentry);
/* adjust nlink and update timestamp */
- dir = parent->d_inode;
- mutex_lock(&dir->i_mutex);
-
curtime = CURRENT_TIME;
- dir->i_ctime = dir->i_mtime = curtime;
+ inode = ilookup(sysfs_sb, sd->s_ino);
+ if (inode) {
+ mutex_lock(&inode->i_mutex);
- if (dentry) {
- dentry->d_inode->i_ctime = curtime;
- drop_nlink(dentry->d_inode);
- if (sd->s_type & SYSFS_DIR) {
- drop_nlink(dentry->d_inode);
- drop_nlink(dir);
- /* XXX: unpin if directory, this will go away soon */
- dput(dentry);
- }
+ inode->i_ctime = curtime;
+ drop_nlink(inode);
+ if (sd->s_type & SYSFS_DIR)
+ drop_nlink(inode);
+
+ mutex_unlock(&inode->i_mutex);
+ iput(inode);
}
- mutex_unlock(&dir->i_mutex);
+ /* adjust nlink and udpate timestamp of the parent */
+ inode = ilookup(sysfs_sb, sd->s_parent->s_ino);
+ if (inode) {
+ mutex_lock(&inode->i_mutex);
- /* bye bye */
- if (dentry)
- dput(dentry);
- else
- dput(parent);
+ inode->i_ctime = inode->i_mtime = curtime;
+ if (sd->s_type & SYSFS_DIR)
+ drop_nlink(inode);
+
+ mutex_unlock(&inode->i_mutex);
+ iput(inode);
+ }
}
int sysfs_hash_and_remove(struct dentry * dir, const char * name)
--
1.5.0.3
next prev parent reply other threads:[~2007-06-13 19:28 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-13 19:27 [PATCHSET 2.6.22-rc4-mm2] sysfs: make directory dentries/inodes reclaimable, take#2 Tejun Heo
2007-06-13 19:27 ` Tejun Heo [this message]
2007-06-13 19:27 ` [PATCH 02/11] sysfs: rename sysfs_dirent->s_type to s_flags and make room for flags Tejun Heo
2007-06-13 19:27 ` [PATCH 05/11] sysfs: make kobj point to sysfs_dirent instead of dentry Tejun Heo
2007-06-13 19:27 ` [PATCH 03/11] sysfs: implement SYSFS_FLAG_REMOVED flag Tejun Heo
2007-06-13 19:27 ` [PATCH 04/11] sysfs: implement sysfs_find_dirent() and sysfs_get_dirent() Tejun Heo
2007-06-13 19:27 ` [PATCH 07/11] sysfs: use sysfs_mutex to protect the sysfs_dirent tree Tejun Heo
2007-06-13 19:27 ` [PATCH 06/11] sysfs: consolidate sysfs spinlocks Tejun Heo
2007-06-13 19:27 ` [PATCH 08/11] sysfs: restructure add/remove paths and fix inode update Tejun Heo
2007-06-13 19:27 ` [PATCH 09/11] sysfs: move sysfs_drop_dentry() to dir.c and make it static Tejun Heo
2007-06-13 19:27 ` [PATCH 10/11] sysfs: implement sysfs_get_dentry() Tejun Heo
2007-06-13 19:27 ` [PATCH 11/11] sysfs: make directory dentries and inodes reclaimable 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=11817628414141-git-send-email-htejun@gmail.com \
--to=htejun@gmail.com \
--cc=cornelia.huck@de.ibm.com \
--cc=dmitry.torokhov@gmail.com \
--cc=greg@kroah.com \
--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.