aboutsummaryrefslogtreecommitdiffstats
path: root/fs/pnode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/pnode.c')
-rw-r--r--fs/pnode.c81
1 files changed, 80 insertions, 1 deletions
diff --git a/fs/pnode.c b/fs/pnode.c
index 1e22165ea41f..2d572b88e6f6 100644
--- a/fs/pnode.c
+++ b/fs/pnode.c
@@ -20,9 +20,88 @@ static inline struct vfsmount *next_peer(struct vfsmount *p)
20void change_mnt_propagation(struct vfsmount *mnt, int type) 20void change_mnt_propagation(struct vfsmount *mnt, int type)
21{ 21{
22 if (type == MS_SHARED) { 22 if (type == MS_SHARED) {
23 mnt->mnt_flags |= MNT_SHARED; 23 set_mnt_shared(mnt);
24 } else { 24 } else {
25 list_del_init(&mnt->mnt_share); 25 list_del_init(&mnt->mnt_share);
26 mnt->mnt_flags &= ~MNT_PNODE_MASK; 26 mnt->mnt_flags &= ~MNT_PNODE_MASK;
27 } 27 }
28} 28}
29
30/*
31 * get the next mount in the propagation tree.
32 * @m: the mount seen last
33 * @origin: the original mount from where the tree walk initiated
34 */
35static struct vfsmount *propagation_next(struct vfsmount *m,
36 struct vfsmount *origin)
37{
38 m = next_peer(m);
39 if (m == origin)
40 return NULL;
41 return m;
42}
43
44/*
45 * mount 'source_mnt' under the destination 'dest_mnt' at
46 * dentry 'dest_dentry'. And propagate that mount to
47 * all the peer and slave mounts of 'dest_mnt'.
48 * Link all the new mounts into a propagation tree headed at
49 * source_mnt. Also link all the new mounts using ->mnt_list
50 * headed at source_mnt's ->mnt_list
51 *
52 * @dest_mnt: destination mount.
53 * @dest_dentry: destination dentry.
54 * @source_mnt: source mount.
55 * @tree_list : list of heads of trees to be attached.
56 */
57int propagate_mnt(struct vfsmount *dest_mnt, struct dentry *dest_dentry,
58 struct vfsmount *source_mnt, struct list_head *tree_list)
59{
60 struct vfsmount *m, *child;
61 int ret = 0;
62 struct vfsmount *prev_dest_mnt = dest_mnt;
63 struct vfsmount *prev_src_mnt = source_mnt;
64 LIST_HEAD(tmp_list);
65 LIST_HEAD(umount_list);
66
67 for (m = propagation_next(dest_mnt, dest_mnt); m;
68 m = propagation_next(m, dest_mnt)) {
69 int type = CL_PROPAGATION;
70
71 if (IS_MNT_NEW(m))
72 continue;
73
74 if (IS_MNT_SHARED(m))
75 type |= CL_MAKE_SHARED;
76
77 if (!(child = copy_tree(source_mnt, source_mnt->mnt_root,
78 type))) {
79 ret = -ENOMEM;
80 list_splice(tree_list, tmp_list.prev);
81 goto out;
82 }
83
84 if (is_subdir(dest_dentry, m->mnt_root)) {
85 mnt_set_mountpoint(m, dest_dentry, child);
86 list_add_tail(&child->mnt_hash, tree_list);
87 } else {
88 /*
89 * This can happen if the parent mount was bind mounted
90 * on some subdirectory of a shared/slave mount.
91 */
92 list_add_tail(&child->mnt_hash, &tmp_list);
93 }
94 prev_dest_mnt = m;
95 prev_src_mnt = child;
96 }
97out:
98 spin_lock(&vfsmount_lock);
99 while (!list_empty(&tmp_list)) {
100 child = list_entry(tmp_list.next, struct vfsmount, mnt_hash);
101 list_del_init(&child->mnt_hash);
102 umount_tree(child, &umount_list);
103 }
104 spin_unlock(&vfsmount_lock);
105 release_mounts(&umount_list);
106 return ret;
107}