When a sysfs_node or one of its ancestors is renamed, automatically rename symlinks pointing to it according to the name format together.
Note that as links created with kobject based sysfs_create_link() aren't chained on its target, they aren't renamed automatically. This is for backward compatibility. Signed-off-by: Tejun Heo <[EMAIL PROTECTED]> --- fs/sysfs/dir.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 45 insertions(+), 0 deletions(-) diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index 4a04cb4..eac8fef 100644 --- a/fs/sysfs/dir.c +++ b/fs/sysfs/dir.c @@ -1196,6 +1196,7 @@ static int sysfs_prep_rename(struct sysfs_rename_context *rcxt, { struct sysfs_rcxt_rename_ent *rent; struct sysfs_rcxt_mutex_ent *ment; + struct sysfs_dirent *cur; int rc; INIT_LIST_HEAD(&rcxt->mutexes); @@ -1220,6 +1221,50 @@ static int sysfs_prep_rename(struct sysfs_rename_context *rcxt, goto err; /* + * prep links pointing to @sd and its children + */ + cur = NULL; + while ((cur = sysfs_tree_walk_next(sd, cur))) { + struct sysfs_dirent *link; + + if (sysfs_type(cur) != SYSFS_DIR) + continue; + + for (link = cur->s_dir.links; link; link = link->s_link.next) { + const char *link_new_name; + int copied; + + rc = sysfs_link_name(link->s_link.name_fmt, + link->s_link.target, + &link_new_name, + sd, new_parent, new_name); + if (rc < 0) + goto err; + copied = rc; + + if (!strcmp(link->s_name, link_new_name)) { + if (copied) + kfree(link_new_name); + continue; + } + + rc = -ENOMEM; + rent = sysfs_rcxt_add(rcxt, link, link->s_parent); + if (!rent) { + mutex_unlock(&sysfs_mutex); + goto err; + } + + rent->new_name = link_new_name; + rent->new_name_copied = copied; + + rc = sysfs_rcxt_get_dentries(rcxt, rent); + if (rc) + goto err; + } + } + + /* * lock all i_mutexes */ try_lock: -- 1.5.0.3 - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/