Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=9918f9a4817cb6241c727b434d5f8ec5564198de
Commit:     9918f9a4817cb6241c727b434d5f8ec5564198de
Parent:     5a26b79c426f8e55ebf7204cb138eb6b1645d4d3
Author:     Eric W. Biederman <[EMAIL PROTECTED]>
AuthorDate: Mon Aug 20 21:36:31 2007 +0900
Committer:  Greg Kroah-Hartman <[EMAIL PROTECTED]>
CommitDate: Fri Oct 12 14:51:08 2007 -0700

    sysfs: Rewrite rename in terms of sysfs dirents
    
    This patch rewrites sysfs_rename_dir to perform it's checks
    as much as possible on the underlying sysfs_dirents instead
    of the contents of the dcache.  It turns out that this version
    is a little simpler, and a little more like the rest of
    the sysfs directory modification code.
    
    tj: fixed double locking of sysfs_mutex
    
    Signed-off-by: Eric W. Biederman <[EMAIL PROTECTED]>
    Signed-off-by: Tejun Heo <[EMAIL PROTECTED]>
    Cc: Cornelia Huck <[EMAIL PROTECTED]>
    Signed-off-by: Greg Kroah-Hartman <[EMAIL PROTECTED]>
---
 fs/sysfs/dir.c |   38 ++++++++++++++++----------------------
 1 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 36b6c79..463c5e3 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -770,7 +770,7 @@ void sysfs_remove_dir(struct kobject * kobj)
 
 int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
 {
-       struct sysfs_dirent *sd;
+       struct sysfs_dirent *sd = kobj->sd;
        struct dentry *parent = NULL;
        struct dentry *old_dentry = NULL, *new_dentry = NULL;
        const char *dup_name = NULL;
@@ -778,63 +778,57 @@ int sysfs_rename_dir(struct kobject * kobj, const char 
*new_name)
 
        mutex_lock(&sysfs_rename_mutex);
 
+       error = 0;
+       if (strcmp(sd->s_name, new_name) == 0)
+               goto out;       /* nothing to rename */
+
        /* get the original dentry */
-       sd = kobj->sd;
        old_dentry = sysfs_get_dentry(sd);
        if (IS_ERR(old_dentry)) {
                error = PTR_ERR(old_dentry);
-               goto out_dput;
+               goto out;
        }
 
        parent = old_dentry->d_parent;
 
        /* lock parent and get dentry for new name */
        mutex_lock(&parent->d_inode->i_mutex);
+       mutex_lock(&sysfs_mutex);
 
-       new_dentry = lookup_one_len(new_name, parent, strlen(new_name));
-       if (IS_ERR(new_dentry)) {
-               error = PTR_ERR(new_dentry);
-               goto out_unlock;
-       }
-
-       error = -EINVAL;
-       if (old_dentry == new_dentry)
+       error = -EEXIST;
+       if (sysfs_find_dirent(sd->s_parent, new_name))
                goto out_unlock;
 
-       error = -EEXIST;
-       if (new_dentry->d_inode)
+       error = -ENOMEM;
+       new_dentry = d_alloc_name(parent, new_name);
+       if (!new_dentry)
                goto out_unlock;
 
        /* rename kobject and sysfs_dirent */
        error = -ENOMEM;
        new_name = dup_name = kstrdup(new_name, GFP_KERNEL);
        if (!new_name)
-               goto out_drop;
+               goto out_unlock;
 
        error = kobject_set_name(kobj, "%s", new_name);
        if (error)
-               goto out_drop;
+               goto out_unlock;
 
-       mutex_lock(&sysfs_mutex);
        dup_name = sd->s_name;
        sd->s_name = new_name;
-       mutex_unlock(&sysfs_mutex);
 
        /* rename */
        d_add(new_dentry, NULL);
        d_move(old_dentry, new_dentry);
 
        error = 0;
-       goto out_unlock;
-
- out_drop:
-       d_drop(new_dentry);
  out_unlock:
+       mutex_unlock(&sysfs_mutex);
        mutex_unlock(&parent->d_inode->i_mutex);
- out_dput:
        kfree(dup_name);
        dput(old_dentry);
        dput(new_dentry);
+ out:
        mutex_unlock(&sysfs_rename_mutex);
        return error;
 }
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to