public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <htejun@gmail.com>
To: ebiederm@xmission.com, cornelia.huck@de.ibm.com, greg@kroah.com,
	stern@rowland.harvard.edu, kay.sievers@vrfy.org,
	linux-kernel@vger.kernel.org, htejun@gmail.com
Cc: Tejun Heo <htejun@gmail.com>
Subject: [PATCH 5/8] sysfs: implement symlink auto-rename
Date: Thu, 20 Sep 2007 17:31:38 +0900	[thread overview]
Message-ID: <1190277098339-git-send-email-htejun@gmail.com> (raw)
In-Reply-To: <11902770971822-git-send-email-htejun@gmail.com>

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 <htejun@gmail.com>
---
 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



  parent reply	other threads:[~2007-09-20  8:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-20  8:31 [PATCHSET 4/4] sysfs: implement new features Tejun Heo
2007-09-20  8:31 ` [PATCH 2/8] sysfs: add name formatting support for symlinks Tejun Heo
2007-09-20  8:31 ` [PATCH 1/8] sysfs: notify file on deactivation Tejun Heo
2007-09-20  8:31 ` [PATCH 3/8] sysfs: chain symlinks to their targets Tejun Heo
2007-09-20  8:31 ` [PATCH 4/8] sysfs: implement symlink auto-removal Tejun Heo
2007-09-20  8:31 ` [PATCH 8/8] sysfs: add copyrights Tejun Heo
2007-09-20  8:31 ` [PATCH 6/8] sysfs: implement plugged creation of sysfs nodes Tejun Heo
2007-09-20  8:31 ` Tejun Heo [this message]
2007-09-20  8:31 ` [PATCH 7/8] sysfs: implement batch error handling Tejun Heo
2007-09-25 22:50 ` [PATCHSET 4/4] sysfs: implement new features Greg KH
2007-09-27 12:24   ` Tejun Heo
2007-09-27 22:38   ` Kyle Moffett

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=1190277098339-git-send-email-htejun@gmail.com \
    --to=htejun@gmail.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=ebiederm@xmission.com \
    --cc=greg@kroah.com \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox