[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <m1lkcnhwfu.fsf_-_@ebiederm.dsl.xmission.com>
Date: Tue, 07 Aug 2007 15:22:13 -0600
From: ebiederm@...ssion.com (Eric W. Biederman)
To: Greg KH <greg@...ah.com>
Cc: linux-kernel@...r.kernel.org, satyam@...radead.org,
cornelia.huck@...ibm.com, stern@...land.harvard.edu,
Tejun Heo <htejun@...il.com>,
Linux Containers <containers@...ts.osdl.org>, gregkh@...e.de
Subject: [PATCH 13/25] sysfs: Simply sysfs_get_dentry
Now that we know the sysfs tree structure cannot change under us
simplfy sysfs_get_dentry.
Signed-off-by: Eric W. Biederman <ebiederm@...ssion.com>
---
fs/sysfs/dir.c | 48 ++++++------------------------------------------
1 files changed, 6 insertions(+), 42 deletions(-)
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index e0f49b7..a9bdb12 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -784,71 +784,35 @@ struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd)
{
struct sysfs_dirent *cur;
struct dentry *parent_dentry, *dentry;
- int i, depth;
/* Find the first parent which has valid dentry.
*/
- mutex_lock(&sysfs_mutex);
- restart:
-
dentry = NULL;
- depth = 0;
cur = sd;
while (!(dentry = __sysfs_get_dentry(sysfs_sb, cur))) {
if (cur->s_flags & SYSFS_FLAG_REMOVED) {
dentry = ERR_PTR(-ENOENT);
- depth = 0;
break;
}
cur = cur->s_parent;
- depth++;
}
/* from the found dentry, look up depth times */
- while (depth--) {
- /* find and get depth'th ancestor */
- for (cur = sd, i = 0; cur && i < depth; i++)
+ while (dentry->d_fsdata != sd) {
+ /* Find the first ancestor I have not looked up */
+ cur = sd;
+ while (cur->s_parent != dentry->d_fsdata)
cur = cur->s_parent;
- /* This can happen if tree structure was modified due
- * to move/rename. Restart.
- */
- if (i != depth) {
- dput(dentry);
- goto restart;
- }
-
- sysfs_get(cur);
-
- mutex_unlock(&sysfs_mutex);
-
/* look it up */
parent_dentry = dentry;
dentry = lookup_one_len_kern(cur->s_name, parent_dentry,
strlen(cur->s_name));
dput(parent_dentry);
- if (IS_ERR(dentry)) {
- sysfs_put(cur);
- return dentry;
- }
-
- mutex_lock(&sysfs_mutex);
-
- /* This, again, can happen if tree structure has
- * changed and we looked up the wrong thing. Restart.
- */
- if (dentry->d_fsdata != cur) {
- dput(dentry);
- sysfs_put(cur);
- goto restart;
- }
-
-
- sysfs_put(cur);
+ if (IS_ERR(dentry))
+ break;
}
-
- mutex_unlock(&sysfs_mutex);
return dentry;
}
--
1.5.1.1.181.g2de0
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists