4 * (C) Copyright IBM Corporation 2005.
5 * Released under GPL v2.
6 * Author : Ram Pai (linuxram@us.ibm.com)
9 #include <linux/namespace.h>
10 #include <linux/mount.h>
14 /* return the next shared peer mount of @p */
15 static inline struct vfsmount *next_peer(struct vfsmount *p)
17 return list_entry(p->mnt_share.next, struct vfsmount, mnt_share);
20 void change_mnt_propagation(struct vfsmount *mnt, int type)
22 if (type == MS_SHARED) {
25 list_del_init(&mnt->mnt_share);
26 mnt->mnt_flags &= ~MNT_PNODE_MASK;
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
35 static struct vfsmount *propagation_next(struct vfsmount *m,
36 struct vfsmount *origin)
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
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.
57 int propagate_mnt(struct vfsmount *dest_mnt, struct dentry *dest_dentry,
58 struct vfsmount *source_mnt, struct list_head *tree_list)
60 struct vfsmount *m, *child;
62 struct vfsmount *prev_dest_mnt = dest_mnt;
63 struct vfsmount *prev_src_mnt = source_mnt;
65 LIST_HEAD(umount_list);
67 for (m = propagation_next(dest_mnt, dest_mnt); m;
68 m = propagation_next(m, dest_mnt)) {
69 int type = CL_PROPAGATION;
75 type |= CL_MAKE_SHARED;
77 if (!(child = copy_tree(source_mnt, source_mnt->mnt_root,
80 list_splice(tree_list, tmp_list.prev);
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);
89 * This can happen if the parent mount was bind mounted
90 * on some subdirectory of a shared/slave mount.
92 list_add_tail(&child->mnt_hash, &tmp_list);
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);
104 spin_unlock(&vfsmount_lock);
105 release_mounts(&umount_list);