From: ebiederm@xmission.com (Eric W. Biederman)
To: Greg Kroah-Hartman <gregkh@suse.de>, Greg KH <greg@kroah.com>
Cc: Tejun Heo <htejun@gmail.com>,
Linux Containers <containers@lists.osdl.org>,
<netdev@vger.kernel.org>,
cornelia.huck@de.ibm.com, stern@rowland.harvard.edu,
kay.sievers@vrfy.org, <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Herbert Xu <herbert@gondor.apana.org.au>,
David Miller <davem@davemloft.net>
Subject: [PATCH 05/10] sysfs: Rename Support multiple superblocks
Date: Sat, 01 Dec 2007 02:23:24 -0700 [thread overview]
Message-ID: <m1k5ny7oqb.fsf_-_@ebiederm.dsl.xmission.com> (raw)
In-Reply-To: <m1odda7oxs.fsf_-_@ebiederm.dsl.xmission.com> (Eric W. Biederman's message of "Sat, 01 Dec 2007 02:18:55 -0700")
This patch modifies the sysfs_rename_dir and sysfs_move_dir
to support multiple sysfs dentry trees rooted in different
sysfs superblocks.
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---
fs/sysfs/dir.c | 190 +++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 135 insertions(+), 55 deletions(-)
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 3ec9040..0d0c87e 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -802,42 +802,112 @@ static struct dentry *__sysfs_get_dentry(struct super_block *sb, struct sysfs_di
return dentry;
}
+struct sysfs_rename_struct {
+ struct list_head list;
+ struct dentry *old_dentry;
+ struct dentry *new_dentry;
+ struct dentry *old_parent;
+ struct dentry *new_parent;
+};
+
+static void post_rename(struct list_head *head)
+{
+ struct sysfs_rename_struct *srs;
+ while (!list_empty(head)) {
+ srs = list_entry(head->next, struct sysfs_rename_struct, list);
+ dput(srs->old_dentry);
+ dput(srs->new_dentry);
+ dput(srs->old_parent);
+ dput(srs->new_parent);
+ list_del(&srs->list);
+ kfree(srs);
+ }
+}
+
+static int prep_rename(struct list_head *head,
+ struct sysfs_dirent *sd, struct sysfs_dirent *new_parent_sd,
+ const char *name)
+{
+ struct sysfs_rename_struct *srs;
+ struct super_block *sb;
+ struct dentry *dentry;
+ int error;
+
+ list_for_each_entry(sb, &sysfs_fs_type.fs_supers, s_instances) {
+ dentry = sysfs_get_dentry(sb, sd);
+ if (dentry == ERR_PTR(-EXDEV))
+ continue;
+ if (IS_ERR(dentry)) {
+ error = PTR_ERR(dentry);
+ goto err_out;
+ }
+
+ srs = kzalloc(sizeof(*srs), GFP_KERNEL);
+ if (!srs) {
+ dput(dentry);
+ goto err_out;
+ }
+
+ INIT_LIST_HEAD(&srs->list);
+ list_add(head, &srs->list);
+ srs->old_dentry = dentry;
+ srs->old_parent = dget(dentry->d_parent);
+
+ dentry = sysfs_get_dentry(sb, new_parent_sd);
+ if (IS_ERR(dentry)) {
+ error = PTR_ERR(dentry);
+ goto err_out;
+ }
+ srs->new_parent = dentry;
+
+ error = -ENOMEM;
+ dentry = d_alloc_name(srs->new_parent, name);
+ if (!dentry)
+ goto err_out;
+ srs->new_dentry = dentry;
+ }
+ return 0;
+
+err_out:
+ post_rename(head);
+ return error;
+}
+
int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
{
struct sysfs_dirent *sd = kobj->sd;
- struct dentry *parent = NULL;
- struct dentry *old_dentry = NULL, *new_dentry = NULL;
+ struct list_head todo;
+ struct sysfs_rename_struct *srs;
+ struct inode *parent_inode = NULL;
const char *dup_name = NULL;
int error;
+ INIT_LIST_HEAD(&todo);
mutex_lock(&sysfs_rename_mutex);
error = 0;
if (strcmp(sd->s_name, new_name) == 0)
goto out; /* nothing to rename */
- /* get the original dentry */
- old_dentry = sysfs_get_dentry(sysfs_sb, sd);
- if (IS_ERR(old_dentry)) {
- error = PTR_ERR(old_dentry);
- goto out;
- }
+ sysfs_grab_supers();
+ error = prep_rename(&todo, sd, sd->s_parent, new_name);
+ if (error)
+ goto out_release;
- parent = old_dentry->d_parent;
+ error = -ENOMEM;
+ mutex_lock(&sysfs_mutex);
+ parent_inode = sysfs_get_inode(sd->s_parent);
+ mutex_unlock(&sysfs_mutex);
+ if (!parent_inode)
+ goto out_release;
- /* lock parent and get dentry for new name */
- mutex_lock(&parent->d_inode->i_mutex);
+ mutex_lock(&parent_inode->i_mutex);
mutex_lock(&sysfs_mutex);
error = -EEXIST;
if (sysfs_find_dirent(sd->s_parent, new_name))
goto out_unlock;
- 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);
@@ -852,17 +922,21 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
sd->s_name = new_name;
/* rename */
- d_add(new_dentry, NULL);
- d_move(old_dentry, new_dentry);
+ list_for_each_entry(srs, &todo, list) {
+ d_add(srs->new_dentry, NULL);
+ d_move(srs->old_dentry, srs->new_dentry);
+ }
error = 0;
- out_unlock:
+out_unlock:
mutex_unlock(&sysfs_mutex);
- mutex_unlock(&parent->d_inode->i_mutex);
+ mutex_unlock(&parent_inode->i_mutex);
kfree(dup_name);
- dput(old_dentry);
- dput(new_dentry);
- out:
+out_release:
+ iput(parent_inode);
+ post_rename(&todo);
+ sysfs_release_supers();
+out:
mutex_unlock(&sysfs_rename_mutex);
return error;
}
@@ -871,10 +945,12 @@ int sysfs_move_dir(struct kobject *kobj, struct kobject *new_parent_kobj)
{
struct sysfs_dirent *sd = kobj->sd;
struct sysfs_dirent *new_parent_sd;
- struct dentry *old_parent, *new_parent = NULL;
- struct dentry *old_dentry = NULL, *new_dentry = NULL;
+ struct list_head todo;
+ struct sysfs_rename_struct *srs;
+ struct inode *old_parent_inode = NULL, *new_parent_inode = NULL;
int error;
+ INIT_LIST_HEAD(&todo);
mutex_lock(&sysfs_rename_mutex);
BUG_ON(!sd->s_parent);
new_parent_sd = new_parent_kobj->sd ? new_parent_kobj->sd : &sysfs_root;
@@ -883,24 +959,29 @@ int sysfs_move_dir(struct kobject *kobj, struct kobject *new_parent_kobj)
if (sd->s_parent == new_parent_sd)
goto out; /* nothing to move */
- /* get dentries */
- old_dentry = sysfs_get_dentry(sysfs_sb, sd);
- if (IS_ERR(old_dentry)) {
- error = PTR_ERR(old_dentry);
- goto out;
- }
- old_parent = old_dentry->d_parent;
+ sysfs_grab_supers();
+ error = prep_rename(&todo, sd, new_parent_sd, sd->s_name);
+ if (error)
+ goto out_release;
- new_parent = sysfs_get_dentry(sysfs_sb, new_parent_sd);
- if (IS_ERR(new_parent)) {
- error = PTR_ERR(new_parent);
- goto out;
- }
+ error = -ENOMEM;
+ mutex_lock(&sysfs_mutex);
+ old_parent_inode = sysfs_get_inode(sd->s_parent);
+ mutex_unlock(&sysfs_mutex);
+ if (!old_parent_inode)
+ goto out_release;
+
+ error = -ENOMEM;
+ mutex_lock(&sysfs_mutex);
+ new_parent_inode = sysfs_get_inode(new_parent_sd);
+ mutex_unlock(&sysfs_mutex);
+ if (!new_parent_inode)
+ goto out_release;
again:
- mutex_lock(&old_parent->d_inode->i_mutex);
- if (!mutex_trylock(&new_parent->d_inode->i_mutex)) {
- mutex_unlock(&old_parent->d_inode->i_mutex);
+ mutex_lock(&old_parent_inode->i_mutex);
+ if (!mutex_trylock(&new_parent_inode->i_mutex)) {
+ mutex_unlock(&old_parent_inode->i_mutex);
goto again;
}
mutex_lock(&sysfs_mutex);
@@ -909,15 +990,11 @@ again:
if (sysfs_find_dirent(new_parent_sd, sd->s_name))
goto out_unlock;
- error = -ENOMEM;
- new_dentry = d_alloc_name(new_parent, sd->s_name);
- if (!new_dentry)
- goto out_unlock;
-
error = 0;
- d_add(new_dentry, NULL);
- d_move(old_dentry, new_dentry);
- dput(new_dentry);
+ list_for_each_entry(srs, &todo, list) {
+ d_add(srs->new_dentry, NULL);
+ d_move(srs->old_dentry, srs->new_dentry);
+ }
/* Remove from old parent's list and insert into new parent's list. */
sysfs_unlink_sibling(sd);
@@ -926,14 +1003,17 @@ again:
sd->s_parent = new_parent_sd;
sysfs_link_sibling(sd);
- out_unlock:
+out_unlock:
mutex_unlock(&sysfs_mutex);
- mutex_unlock(&new_parent->d_inode->i_mutex);
- mutex_unlock(&old_parent->d_inode->i_mutex);
- out:
- dput(new_parent);
- dput(old_dentry);
- dput(new_dentry);
+ mutex_unlock(&new_parent_inode->i_mutex);
+ mutex_unlock(&old_parent_inode->i_mutex);
+
+out_release:
+ iput(new_parent_inode);
+ iput(old_parent_inode);
+ post_rename(&todo);
+ sysfs_release_supers();
+out:
mutex_unlock(&sysfs_rename_mutex);
return error;
}
--
1.5.3.rc6.17.g1911
next prev parent reply other threads:[~2007-12-01 9:25 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-01 9:06 [PATCH 0/10] sysfs network namespace support Eric W. Biederman
2007-12-01 9:12 ` [PATCH 01/10] sysfs: Make sysfs_mount static again Eric W. Biederman
2007-12-01 9:13 ` [PATCH 02/10] sysfs: Support for preventing unmounts Eric W. Biederman
2007-12-01 9:16 ` [PATCH 03/10] sysfs: sysfs_get_dentry add a sb parameter Eric W. Biederman
2007-12-01 9:18 ` [PATCH 04/10] sysfs: Implement __sysfs_get_dentry Eric W. Biederman
2007-12-01 9:23 ` Eric W. Biederman [this message]
2007-12-01 9:25 ` [PATCH 06/10] sysfs: sysfs_chmod_file handle multiple superblocks Eric W. Biederman
2007-12-01 9:28 ` [PATCH 07/10] sysfs: Implement sysfs tagged directory support Eric W. Biederman
2007-12-01 9:30 ` [PATCH 08/10] sysfs: Implement sysfs_delete_link and sysfs_rename_link Eric W. Biederman
2007-12-01 9:33 ` [PATCH 09/10] driver core: Implement tagged directory support for device classes Eric W. Biederman
2007-12-01 9:35 ` [PATCH 10/10] net: Enable tagging for net_class directories in sysfs Eric W. Biederman
2007-12-01 13:10 ` namespace support requires network modules to say "GPL" Mark Lord
2007-12-01 13:13 ` Mark Lord
2007-12-01 19:17 ` Stephen Hemminger
2007-12-01 19:23 ` Alan Cox
2007-12-01 19:38 ` Stephen Hemminger
2007-12-01 19:45 ` Alan Cox
2007-12-01 20:13 ` Eric W. Biederman
2007-12-01 20:21 ` Mark Lord
2007-12-01 20:29 ` Arjan van de Ven
2007-12-01 22:12 ` Mark Lord
2007-12-01 23:13 ` Eric W. Biederman
2007-12-01 23:24 ` Jiri Slaby
2007-12-02 1:14 ` Eric W. Biederman
2007-12-01 23:51 ` Mark Lord
2007-12-02 1:08 ` Eric W. Biederman
2007-12-01 20:52 ` Eric W. Biederman
2007-12-01 22:13 ` Mark Lord
2007-12-03 0:02 ` David Schwartz
2007-12-03 0:14 ` Alan Cox
2007-12-01 19:54 ` Eric W. Biederman
2007-12-02 0:30 ` Stephen Hemminger
2007-12-02 2:02 ` Eric W. Biederman
2007-12-02 3:34 ` Mark Lord
2007-12-02 4:23 ` Stephen Hemminger
2007-12-02 19:28 ` Ben Greear
2007-12-02 20:03 ` Patrick McHardy
2007-12-02 20:43 ` Adrian Bunk
2007-12-02 21:59 ` Patrick McHardy
2007-12-03 1:14 ` Adrian Bunk
2007-12-03 8:33 ` Denis V. Lunev
2007-12-03 17:35 ` Eric W. Biederman
2007-12-03 18:19 ` Ben Greear
2007-12-03 18:57 ` Daniel Lezcano
2007-12-04 15:19 ` Daniel Lezcano
2007-12-04 18:03 ` Eric W. Biederman
2007-12-04 18:44 ` Ben Greear
2007-12-04 19:17 ` Eric W. Biederman
2007-12-04 19:35 ` Ben Greear
2007-12-04 20:09 ` Eric W. Biederman
2007-12-05 6:14 ` David Miller
2007-12-05 6:01 ` David Miller
2007-12-04 17:59 ` Eric W. Biederman
2007-12-04 18:57 ` Ben Greear
2007-12-04 20:01 ` Eric W. Biederman
2007-12-05 6:07 ` David Miller
2007-12-03 8:24 ` Romano Giannetti
2007-12-03 15:34 ` Arjan van de Ven
2007-12-03 18:03 ` Eric W. Biederman
2007-12-03 18:13 ` David Miller
2007-12-02 13:51 ` Alan Cox
2007-12-02 19:56 ` Valdis.Kletnieks
2007-12-21 3:07 ` [PATCH 0/10] sysfs network namespace support Greg KH
2007-12-21 13:04 ` Eric W. Biederman
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=m1k5ny7oqb.fsf_-_@ebiederm.dsl.xmission.com \
--to=ebiederm@xmission.com \
--cc=akpm@linux-foundation.org \
--cc=containers@lists.osdl.org \
--cc=cornelia.huck@de.ibm.com \
--cc=davem@davemloft.net \
--cc=greg@kroah.com \
--cc=gregkh@suse.de \
--cc=herbert@gondor.apana.org.au \
--cc=htejun@gmail.com \
--cc=kay.sievers@vrfy.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@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;
as well as URLs for NNTP newsgroup(s).