Skip to content

Commit

Permalink
sysfs: simplify sysfs_rename_dir()
Browse files Browse the repository at this point in the history
With the shadow directories gone, sysfs_rename_dir() can be simplified.

* parent doesn't need to be grabbed separately.  Just access
  old_dentry->d_parent.

* parent sd can never change.  Remove code to move under the new
  parent.

* Massage comments a bit.

Signed-off-by: Tejun Heo <htejun@gmail.com>
Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Tejun Heo authored and Greg Kroah-Hartman committed Oct 12, 2007
1 parent a7a0475 commit ff869de
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions fs/sysfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -883,27 +883,18 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
struct sysfs_dirent *sd;
struct dentry *parent = NULL;
struct dentry *old_dentry = NULL, *new_dentry = NULL;
struct sysfs_dirent *parent_sd;
const char *dup_name = NULL;
int error;

if (!kobj->parent)
return -EINVAL;

/* get dentries */
/* 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;
}

parent_sd = kobj->parent->sd;
parent = sysfs_get_dentry(parent_sd);
if (IS_ERR(parent)) {
error = PTR_ERR(parent);
goto out_dput;
}
parent = old_dentry->d_parent;

/* lock parent and get dentry for new name */
mutex_lock(&parent->d_inode->i_mutex);
Expand Down Expand Up @@ -933,22 +924,14 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
goto out_drop;

mutex_lock(&sysfs_mutex);

dup_name = sd->s_name;
sd->s_name = new_name;
mutex_unlock(&sysfs_mutex);

/* move under the new parent */
/* rename */
d_add(new_dentry, NULL);
d_move(sd->s_dentry, new_dentry);

sysfs_unlink_sibling(sd);
sysfs_get(parent_sd);
sysfs_put(sd->s_parent);
sd->s_parent = parent_sd;
sysfs_link_sibling(sd);

mutex_unlock(&sysfs_mutex);

error = 0;
goto out_unlock;

Expand All @@ -958,7 +941,6 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
mutex_unlock(&parent->d_inode->i_mutex);
out_dput:
kfree(dup_name);
dput(parent);
dput(old_dentry);
dput(new_dentry);
return error;
Expand Down

0 comments on commit ff869de

Please sign in to comment.