Skip to contentSkip to conversation

fs: namespace: Simplify function commit_tree()

PATCH In review Jiang Liu 2 participants 3 messages Jan 13, 2015 VFS

lore
Share & tools
lore

Jiang Liu

author
#0 lore raw

PATCH 1/1 fs: namespace: Simplify function commit_tree()

Simplify function commit_tree() in fs/namespace.c, it also improves code readability.

---
 fs/namespace.c |   11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
fs/namespace.c +2 -9
index cd1e9681a0cf..c2b6f6f676ec 100644
@@ -846,18 +846,11 @@ static void attach_shadowed(struct mount *mnt,
 static void commit_tree(struct mount *mnt, struct mount *shadows)
 {
 	struct mount *parent = mnt->mnt_parent;
-	struct mount *m;
-	LIST_HEAD(head);
 	struct mnt_namespace *n = parent->mnt_ns;
 
 	BUG_ON(parent == mnt);
-
-	list_add_tail(&head, &mnt->mnt_list);
-	list_for_each_entry(m, &head, mnt_list)
-		m->mnt_ns = n;
-
-	list_splice(&head, n->list.prev);
-
+	mnt->mnt_ns = n;
+	list_add_tail(&mnt->mnt_list, &n->list);
 	attach_shadowed(mnt, parent, shadows);
 	touch_mnt_namespace(n);
 }
Signature · 1 line
1.7.10.4
maintainer
#1 lore raw
Quoted 2 lines · Jiang Liu

Simplify function commit_tree() in fs/namespace.c, it also improves code readability.

Huh?

Quoted 7 lines

static void commit_tree(struct mount *mnt, struct mount *shadows) {

fs/namespace.c +0 -2
 	struct mount *parent = mnt->mnt_parent;
-	struct mount *m;
-	LIST_HEAD(head);
 	struct mnt_namespace *n = parent->mnt_ns;
 

fs/namespace.c static void attach_shadowed(struct mount *mnt, · line 853

Quoted 10 lines
fs/namespace.c +2 -7
 	BUG_ON(parent == mnt);
-
-	list_add_tail(&head, &mnt->mnt_list);
-	list_for_each_entry(m, &head, mnt_list)
-		m->mnt_ns = n;
-
-	list_splice(&head, n->list.prev);
-
+	mnt->mnt_ns = n;
+	list_add_tail(&mnt->mnt_list, &n->list);

And who will set ->mnt_ns on other mounts reachable via ->mnt_list from mnt? Not to mention putting them on n->list...

What you seem to have missed is that list_add_tail(&head, &mnt->mnt_list) is not the same thing as list_add_tail(&mnt->mnt_list, &head). We are not ripping mnt->mnt_list from whatever list it was on and insert it into a previously empty one in head. We take an unanchored cyclic list (all elements being some_mnt->mnt_list) and anchor it at head, then go through all elements of the original list and move them all at once into the end of n->list.

author
#2 lore raw
Quoted 27 lines · Al Viro
Quoted 2 lines · Jiang Liu

Simplify function commit_tree() in fs/namespace.c, it also improves code readability.

Huh?

Quoted 7 lines

static void commit_tree(struct mount *mnt, struct mount *shadows) {

fs/namespace.c +0 -2
 	struct mount *parent = mnt->mnt_parent;
-	struct mount *m;
-	LIST_HEAD(head);
 	struct mnt_namespace *n = parent->mnt_ns;
 

fs/namespace.c static void attach_shadowed(struct mount *mnt, · line 853

Quoted 10 lines
fs/namespace.c +2 -7
 	BUG_ON(parent == mnt);
-
-	list_add_tail(&head, &mnt->mnt_list);
-	list_for_each_entry(m, &head, mnt_list)
-		m->mnt_ns = n;
-
-	list_splice(&head, n->list.prev);
-
+	mnt->mnt_ns = n;
+	list_add_tail(&mnt->mnt_list, &n->list);

And who will set ->mnt_ns on other mounts reachable via ->mnt_list from mnt? Not to mention putting them on n->list...

Quoted 7 lines

What you seem to have missed is that list_add_tail(&head, &mnt->mnt_list) is not the same thing as list_add_tail(&mnt->mnt_list, &head). We are not ripping mnt->mnt_list from whatever list it was on and insert it into a previously empty one in head. We take an unanchored cyclic list (all elements being some_mnt->mnt_list) and anchor it at head, then go through all elements of the original list and move them all at once into the end of n->list.

Hi Al,

	Sorry for the noise, didn't realized that mnt->mnt_list anchors

a whole list:(
Regards!
Gerry