diff options
Diffstat (limited to 'fs/pnode.c')
| -rw-r--r-- | fs/pnode.c | 87 |
1 files changed, 86 insertions, 1 deletions
diff --git a/fs/pnode.c b/fs/pnode.c index 2d572b88e6f6..7bc942d047cd 100644 --- a/fs/pnode.c +++ b/fs/pnode.c | |||
| @@ -99,9 +99,94 @@ out: | |||
| 99 | while (!list_empty(&tmp_list)) { | 99 | while (!list_empty(&tmp_list)) { |
| 100 | child = list_entry(tmp_list.next, struct vfsmount, mnt_hash); | 100 | child = list_entry(tmp_list.next, struct vfsmount, mnt_hash); |
| 101 | list_del_init(&child->mnt_hash); | 101 | list_del_init(&child->mnt_hash); |
| 102 | umount_tree(child, &umount_list); | 102 | umount_tree(child, 0, &umount_list); |
| 103 | } | 103 | } |
| 104 | spin_unlock(&vfsmount_lock); | 104 | spin_unlock(&vfsmount_lock); |
| 105 | release_mounts(&umount_list); | 105 | release_mounts(&umount_list); |
| 106 | return ret; | 106 | return ret; |
| 107 | } | 107 | } |
| 108 | |||
| 109 | /* | ||
| 110 | * return true if the refcount is greater than count | ||
| 111 | */ | ||
| 112 | static inline int do_refcount_check(struct vfsmount *mnt, int count) | ||
| 113 | { | ||
| 114 | int mycount = atomic_read(&mnt->mnt_count); | ||
| 115 | return (mycount > count); | ||
| 116 | } | ||
| 117 | |||
| 118 | /* | ||
| 119 | * check if the mount 'mnt' can be unmounted successfully. | ||
| 120 | * @mnt: the mount to be checked for unmount | ||
| 121 | * NOTE: unmounting 'mnt' would naturally propagate to all | ||
| 122 | * other mounts its parent propagates to. | ||
| 123 | * Check if any of these mounts that **do not have submounts** | ||
| 124 | * have more references than 'refcnt'. If so return busy. | ||
| 125 | */ | ||
| 126 | int propagate_mount_busy(struct vfsmount *mnt, int refcnt) | ||
| 127 | { | ||
| 128 | struct vfsmount *m, *child; | ||
| 129 | struct vfsmount *parent = mnt->mnt_parent; | ||
| 130 | int ret = 0; | ||
| 131 | |||
| 132 | if (mnt == parent) | ||
| 133 | return do_refcount_check(mnt, refcnt); | ||
| 134 | |||
| 135 | /* | ||
| 136 | * quickly check if the current mount can be unmounted. | ||
| 137 | * If not, we don't have to go checking for all other | ||
| 138 | * mounts | ||
| 139 | */ | ||
| 140 | if (!list_empty(&mnt->mnt_mounts) || do_refcount_check(mnt, refcnt)) | ||
| 141 | return 1; | ||
| 142 | |||
| 143 | for (m = propagation_next(parent, parent); m; | ||
| 144 | m = propagation_next(m, parent)) { | ||
| 145 | child = __lookup_mnt(m, mnt->mnt_mountpoint, 0); | ||
| 146 | if (child && list_empty(&child->mnt_mounts) && | ||
| 147 | (ret = do_refcount_check(child, 1))) | ||
| 148 | break; | ||
| 149 | } | ||
| 150 | return ret; | ||
| 151 | } | ||
| 152 | |||
| 153 | /* | ||
| 154 | * NOTE: unmounting 'mnt' naturally propagates to all other mounts its | ||
| 155 | * parent propagates to. | ||
| 156 | */ | ||
| 157 | static void __propagate_umount(struct vfsmount *mnt) | ||
| 158 | { | ||
| 159 | struct vfsmount *parent = mnt->mnt_parent; | ||
| 160 | struct vfsmount *m; | ||
| 161 | |||
| 162 | BUG_ON(parent == mnt); | ||
| 163 | |||
| 164 | for (m = propagation_next(parent, parent); m; | ||
| 165 | m = propagation_next(m, parent)) { | ||
| 166 | |||
| 167 | struct vfsmount *child = __lookup_mnt(m, | ||
| 168 | mnt->mnt_mountpoint, 0); | ||
| 169 | /* | ||
| 170 | * umount the child only if the child has no | ||
| 171 | * other children | ||
| 172 | */ | ||
| 173 | if (child && list_empty(&child->mnt_mounts)) { | ||
| 174 | list_del(&child->mnt_hash); | ||
| 175 | list_add_tail(&child->mnt_hash, &mnt->mnt_hash); | ||
| 176 | } | ||
| 177 | } | ||
| 178 | } | ||
| 179 | |||
| 180 | /* | ||
| 181 | * collect all mounts that receive propagation from the mount in @list, | ||
| 182 | * and return these additional mounts in the same list. | ||
| 183 | * @list: the list of mounts to be unmounted. | ||
| 184 | */ | ||
| 185 | int propagate_umount(struct list_head *list) | ||
| 186 | { | ||
| 187 | struct vfsmount *mnt; | ||
| 188 | |||
| 189 | list_for_each_entry(mnt, list, mnt_hash) | ||
| 190 | __propagate_umount(mnt); | ||
| 191 | return 0; | ||
| 192 | } | ||
