]> bbs.cooldavid.org Git - net-next-2.6.git/blame - fs/pnode.c
[PATCH] shared mounts handling: move
[net-next-2.6.git] / fs / pnode.c
CommitLineData
07b20889
RP
1/*
2 * linux/fs/pnode.c
3 *
4 * (C) Copyright IBM Corporation 2005.
5 * Released under GPL v2.
6 * Author : Ram Pai (linuxram@us.ibm.com)
7 *
8 */
9#include <linux/namespace.h>
10#include <linux/mount.h>
11#include <linux/fs.h>
12#include "pnode.h"
13
03e06e68
RP
14/* return the next shared peer mount of @p */
15static inline struct vfsmount *next_peer(struct vfsmount *p)
16{
17 return list_entry(p->mnt_share.next, struct vfsmount, mnt_share);
18}
19
07b20889
RP
20void change_mnt_propagation(struct vfsmount *mnt, int type)
21{
03e06e68 22 if (type == MS_SHARED) {
b90fa9ae 23 set_mnt_shared(mnt);
03e06e68
RP
24 } else {
25 list_del_init(&mnt->mnt_share);
26 mnt->mnt_flags &= ~MNT_PNODE_MASK;
27 }
07b20889 28}
b90fa9ae
RP
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}