diff options
Diffstat (limited to 'fs/namespace.c')
-rw-r--r-- | fs/namespace.c | 829 |
1 files changed, 343 insertions, 486 deletions
diff --git a/fs/namespace.c b/fs/namespace.c index cfc6d4448aa5..7e6f2c9dc7c4 100644 --- a/fs/namespace.c +++ b/fs/namespace.c | |||
@@ -9,30 +9,17 @@ | |||
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/syscalls.h> | 11 | #include <linux/syscalls.h> |
12 | #include <linux/slab.h> | 12 | #include <linux/export.h> |
13 | #include <linux/sched.h> | ||
14 | #include <linux/spinlock.h> | ||
15 | #include <linux/percpu.h> | ||
16 | #include <linux/init.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/acct.h> | ||
19 | #include <linux/capability.h> | 13 | #include <linux/capability.h> |
20 | #include <linux/cpumask.h> | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/sysfs.h> | ||
23 | #include <linux/seq_file.h> | ||
24 | #include <linux/mnt_namespace.h> | 14 | #include <linux/mnt_namespace.h> |
25 | #include <linux/namei.h> | 15 | #include <linux/namei.h> |
26 | #include <linux/nsproxy.h> | ||
27 | #include <linux/security.h> | 16 | #include <linux/security.h> |
28 | #include <linux/mount.h> | ||
29 | #include <linux/ramfs.h> | ||
30 | #include <linux/log2.h> | ||
31 | #include <linux/idr.h> | 17 | #include <linux/idr.h> |
32 | #include <linux/fs_struct.h> | 18 | #include <linux/acct.h> /* acct_auto_close_mnt */ |
33 | #include <linux/fsnotify.h> | 19 | #include <linux/ramfs.h> /* init_rootfs */ |
34 | #include <asm/uaccess.h> | 20 | #include <linux/fs_struct.h> /* get_fs_root et.al. */ |
35 | #include <asm/unistd.h> | 21 | #include <linux/fsnotify.h> /* fsnotify_vfsmount_delete */ |
22 | #include <linux/uaccess.h> | ||
36 | #include "pnode.h" | 23 | #include "pnode.h" |
37 | #include "internal.h" | 24 | #include "internal.h" |
38 | 25 | ||
@@ -78,7 +65,7 @@ static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry) | |||
78 | * allocation is serialized by namespace_sem, but we need the spinlock to | 65 | * allocation is serialized by namespace_sem, but we need the spinlock to |
79 | * serialize with freeing. | 66 | * serialize with freeing. |
80 | */ | 67 | */ |
81 | static int mnt_alloc_id(struct vfsmount *mnt) | 68 | static int mnt_alloc_id(struct mount *mnt) |
82 | { | 69 | { |
83 | int res; | 70 | int res; |
84 | 71 | ||
@@ -95,7 +82,7 @@ retry: | |||
95 | return res; | 82 | return res; |
96 | } | 83 | } |
97 | 84 | ||
98 | static void mnt_free_id(struct vfsmount *mnt) | 85 | static void mnt_free_id(struct mount *mnt) |
99 | { | 86 | { |
100 | int id = mnt->mnt_id; | 87 | int id = mnt->mnt_id; |
101 | spin_lock(&mnt_id_lock); | 88 | spin_lock(&mnt_id_lock); |
@@ -110,7 +97,7 @@ static void mnt_free_id(struct vfsmount *mnt) | |||
110 | * | 97 | * |
111 | * mnt_group_ida is protected by namespace_sem | 98 | * mnt_group_ida is protected by namespace_sem |
112 | */ | 99 | */ |
113 | static int mnt_alloc_group_id(struct vfsmount *mnt) | 100 | static int mnt_alloc_group_id(struct mount *mnt) |
114 | { | 101 | { |
115 | int res; | 102 | int res; |
116 | 103 | ||
@@ -129,7 +116,7 @@ static int mnt_alloc_group_id(struct vfsmount *mnt) | |||
129 | /* | 116 | /* |
130 | * Release a peer group ID | 117 | * Release a peer group ID |
131 | */ | 118 | */ |
132 | void mnt_release_group_id(struct vfsmount *mnt) | 119 | void mnt_release_group_id(struct mount *mnt) |
133 | { | 120 | { |
134 | int id = mnt->mnt_group_id; | 121 | int id = mnt->mnt_group_id; |
135 | ida_remove(&mnt_group_ida, id); | 122 | ida_remove(&mnt_group_ida, id); |
@@ -141,7 +128,7 @@ void mnt_release_group_id(struct vfsmount *mnt) | |||
141 | /* | 128 | /* |
142 | * vfsmount lock must be held for read | 129 | * vfsmount lock must be held for read |
143 | */ | 130 | */ |
144 | static inline void mnt_add_count(struct vfsmount *mnt, int n) | 131 | static inline void mnt_add_count(struct mount *mnt, int n) |
145 | { | 132 | { |
146 | #ifdef CONFIG_SMP | 133 | #ifdef CONFIG_SMP |
147 | this_cpu_add(mnt->mnt_pcp->mnt_count, n); | 134 | this_cpu_add(mnt->mnt_pcp->mnt_count, n); |
@@ -152,35 +139,10 @@ static inline void mnt_add_count(struct vfsmount *mnt, int n) | |||
152 | #endif | 139 | #endif |
153 | } | 140 | } |
154 | 141 | ||
155 | static inline void mnt_set_count(struct vfsmount *mnt, int n) | ||
156 | { | ||
157 | #ifdef CONFIG_SMP | ||
158 | this_cpu_write(mnt->mnt_pcp->mnt_count, n); | ||
159 | #else | ||
160 | mnt->mnt_count = n; | ||
161 | #endif | ||
162 | } | ||
163 | |||
164 | /* | ||
165 | * vfsmount lock must be held for read | ||
166 | */ | ||
167 | static inline void mnt_inc_count(struct vfsmount *mnt) | ||
168 | { | ||
169 | mnt_add_count(mnt, 1); | ||
170 | } | ||
171 | |||
172 | /* | ||
173 | * vfsmount lock must be held for read | ||
174 | */ | ||
175 | static inline void mnt_dec_count(struct vfsmount *mnt) | ||
176 | { | ||
177 | mnt_add_count(mnt, -1); | ||
178 | } | ||
179 | |||
180 | /* | 142 | /* |
181 | * vfsmount lock must be held for write | 143 | * vfsmount lock must be held for write |
182 | */ | 144 | */ |
183 | unsigned int mnt_get_count(struct vfsmount *mnt) | 145 | unsigned int mnt_get_count(struct mount *mnt) |
184 | { | 146 | { |
185 | #ifdef CONFIG_SMP | 147 | #ifdef CONFIG_SMP |
186 | unsigned int count = 0; | 148 | unsigned int count = 0; |
@@ -196,9 +158,9 @@ unsigned int mnt_get_count(struct vfsmount *mnt) | |||
196 | #endif | 158 | #endif |
197 | } | 159 | } |
198 | 160 | ||
199 | static struct vfsmount *alloc_vfsmnt(const char *name) | 161 | static struct mount *alloc_vfsmnt(const char *name) |
200 | { | 162 | { |
201 | struct vfsmount *mnt = kmem_cache_zalloc(mnt_cache, GFP_KERNEL); | 163 | struct mount *mnt = kmem_cache_zalloc(mnt_cache, GFP_KERNEL); |
202 | if (mnt) { | 164 | if (mnt) { |
203 | int err; | 165 | int err; |
204 | 166 | ||
@@ -277,7 +239,7 @@ int __mnt_is_readonly(struct vfsmount *mnt) | |||
277 | } | 239 | } |
278 | EXPORT_SYMBOL_GPL(__mnt_is_readonly); | 240 | EXPORT_SYMBOL_GPL(__mnt_is_readonly); |
279 | 241 | ||
280 | static inline void mnt_inc_writers(struct vfsmount *mnt) | 242 | static inline void mnt_inc_writers(struct mount *mnt) |
281 | { | 243 | { |
282 | #ifdef CONFIG_SMP | 244 | #ifdef CONFIG_SMP |
283 | this_cpu_inc(mnt->mnt_pcp->mnt_writers); | 245 | this_cpu_inc(mnt->mnt_pcp->mnt_writers); |
@@ -286,7 +248,7 @@ static inline void mnt_inc_writers(struct vfsmount *mnt) | |||
286 | #endif | 248 | #endif |
287 | } | 249 | } |
288 | 250 | ||
289 | static inline void mnt_dec_writers(struct vfsmount *mnt) | 251 | static inline void mnt_dec_writers(struct mount *mnt) |
290 | { | 252 | { |
291 | #ifdef CONFIG_SMP | 253 | #ifdef CONFIG_SMP |
292 | this_cpu_dec(mnt->mnt_pcp->mnt_writers); | 254 | this_cpu_dec(mnt->mnt_pcp->mnt_writers); |
@@ -295,7 +257,7 @@ static inline void mnt_dec_writers(struct vfsmount *mnt) | |||
295 | #endif | 257 | #endif |
296 | } | 258 | } |
297 | 259 | ||
298 | static unsigned int mnt_get_writers(struct vfsmount *mnt) | 260 | static unsigned int mnt_get_writers(struct mount *mnt) |
299 | { | 261 | { |
300 | #ifdef CONFIG_SMP | 262 | #ifdef CONFIG_SMP |
301 | unsigned int count = 0; | 263 | unsigned int count = 0; |
@@ -311,6 +273,15 @@ static unsigned int mnt_get_writers(struct vfsmount *mnt) | |||
311 | #endif | 273 | #endif |
312 | } | 274 | } |
313 | 275 | ||
276 | static int mnt_is_readonly(struct vfsmount *mnt) | ||
277 | { | ||
278 | if (mnt->mnt_sb->s_readonly_remount) | ||
279 | return 1; | ||
280 | /* Order wrt setting s_flags/s_readonly_remount in do_remount() */ | ||
281 | smp_rmb(); | ||
282 | return __mnt_is_readonly(mnt); | ||
283 | } | ||
284 | |||
314 | /* | 285 | /* |
315 | * Most r/o checks on a fs are for operations that take | 286 | * Most r/o checks on a fs are for operations that take |
316 | * discrete amounts of time, like a write() or unlink(). | 287 | * discrete amounts of time, like a write() or unlink(). |
@@ -321,7 +292,7 @@ static unsigned int mnt_get_writers(struct vfsmount *mnt) | |||
321 | */ | 292 | */ |
322 | /** | 293 | /** |
323 | * mnt_want_write - get write access to a mount | 294 | * mnt_want_write - get write access to a mount |
324 | * @mnt: the mount on which to take a write | 295 | * @m: the mount on which to take a write |
325 | * | 296 | * |
326 | * This tells the low-level filesystem that a write is | 297 | * This tells the low-level filesystem that a write is |
327 | * about to be performed to it, and makes sure that | 298 | * about to be performed to it, and makes sure that |
@@ -329,8 +300,9 @@ static unsigned int mnt_get_writers(struct vfsmount *mnt) | |||
329 | * the write operation is finished, mnt_drop_write() | 300 | * the write operation is finished, mnt_drop_write() |
330 | * must be called. This is effectively a refcount. | 301 | * must be called. This is effectively a refcount. |
331 | */ | 302 | */ |
332 | int mnt_want_write(struct vfsmount *mnt) | 303 | int mnt_want_write(struct vfsmount *m) |
333 | { | 304 | { |
305 | struct mount *mnt = real_mount(m); | ||
334 | int ret = 0; | 306 | int ret = 0; |
335 | 307 | ||
336 | preempt_disable(); | 308 | preempt_disable(); |
@@ -341,7 +313,7 @@ int mnt_want_write(struct vfsmount *mnt) | |||
341 | * incremented count after it has set MNT_WRITE_HOLD. | 313 | * incremented count after it has set MNT_WRITE_HOLD. |
342 | */ | 314 | */ |
343 | smp_mb(); | 315 | smp_mb(); |
344 | while (mnt->mnt_flags & MNT_WRITE_HOLD) | 316 | while (mnt->mnt.mnt_flags & MNT_WRITE_HOLD) |
345 | cpu_relax(); | 317 | cpu_relax(); |
346 | /* | 318 | /* |
347 | * After the slowpath clears MNT_WRITE_HOLD, mnt_is_readonly will | 319 | * After the slowpath clears MNT_WRITE_HOLD, mnt_is_readonly will |
@@ -349,7 +321,7 @@ int mnt_want_write(struct vfsmount *mnt) | |||
349 | * MNT_WRITE_HOLD is cleared. | 321 | * MNT_WRITE_HOLD is cleared. |
350 | */ | 322 | */ |
351 | smp_rmb(); | 323 | smp_rmb(); |
352 | if (__mnt_is_readonly(mnt)) { | 324 | if (mnt_is_readonly(m)) { |
353 | mnt_dec_writers(mnt); | 325 | mnt_dec_writers(mnt); |
354 | ret = -EROFS; | 326 | ret = -EROFS; |
355 | goto out; | 327 | goto out; |
@@ -378,7 +350,7 @@ int mnt_clone_write(struct vfsmount *mnt) | |||
378 | if (__mnt_is_readonly(mnt)) | 350 | if (__mnt_is_readonly(mnt)) |
379 | return -EROFS; | 351 | return -EROFS; |
380 | preempt_disable(); | 352 | preempt_disable(); |
381 | mnt_inc_writers(mnt); | 353 | mnt_inc_writers(real_mount(mnt)); |
382 | preempt_enable(); | 354 | preempt_enable(); |
383 | return 0; | 355 | return 0; |
384 | } | 356 | } |
@@ -412,17 +384,23 @@ EXPORT_SYMBOL_GPL(mnt_want_write_file); | |||
412 | void mnt_drop_write(struct vfsmount *mnt) | 384 | void mnt_drop_write(struct vfsmount *mnt) |
413 | { | 385 | { |
414 | preempt_disable(); | 386 | preempt_disable(); |
415 | mnt_dec_writers(mnt); | 387 | mnt_dec_writers(real_mount(mnt)); |
416 | preempt_enable(); | 388 | preempt_enable(); |
417 | } | 389 | } |
418 | EXPORT_SYMBOL_GPL(mnt_drop_write); | 390 | EXPORT_SYMBOL_GPL(mnt_drop_write); |
419 | 391 | ||
420 | static int mnt_make_readonly(struct vfsmount *mnt) | 392 | void mnt_drop_write_file(struct file *file) |
393 | { | ||
394 | mnt_drop_write(file->f_path.mnt); | ||
395 | } | ||
396 | EXPORT_SYMBOL(mnt_drop_write_file); | ||
397 | |||
398 | static int mnt_make_readonly(struct mount *mnt) | ||
421 | { | 399 | { |
422 | int ret = 0; | 400 | int ret = 0; |
423 | 401 | ||
424 | br_write_lock(vfsmount_lock); | 402 | br_write_lock(vfsmount_lock); |
425 | mnt->mnt_flags |= MNT_WRITE_HOLD; | 403 | mnt->mnt.mnt_flags |= MNT_WRITE_HOLD; |
426 | /* | 404 | /* |
427 | * After storing MNT_WRITE_HOLD, we'll read the counters. This store | 405 | * After storing MNT_WRITE_HOLD, we'll read the counters. This store |
428 | * should be visible before we do. | 406 | * should be visible before we do. |
@@ -448,25 +426,61 @@ static int mnt_make_readonly(struct vfsmount *mnt) | |||
448 | if (mnt_get_writers(mnt) > 0) | 426 | if (mnt_get_writers(mnt) > 0) |
449 | ret = -EBUSY; | 427 | ret = -EBUSY; |
450 | else | 428 | else |
451 | mnt->mnt_flags |= MNT_READONLY; | 429 | mnt->mnt.mnt_flags |= MNT_READONLY; |
452 | /* | 430 | /* |
453 | * MNT_READONLY must become visible before ~MNT_WRITE_HOLD, so writers | 431 | * MNT_READONLY must become visible before ~MNT_WRITE_HOLD, so writers |
454 | * that become unheld will see MNT_READONLY. | 432 | * that become unheld will see MNT_READONLY. |
455 | */ | 433 | */ |
456 | smp_wmb(); | 434 | smp_wmb(); |
457 | mnt->mnt_flags &= ~MNT_WRITE_HOLD; | 435 | mnt->mnt.mnt_flags &= ~MNT_WRITE_HOLD; |
458 | br_write_unlock(vfsmount_lock); | 436 | br_write_unlock(vfsmount_lock); |
459 | return ret; | 437 | return ret; |
460 | } | 438 | } |
461 | 439 | ||
462 | static void __mnt_unmake_readonly(struct vfsmount *mnt) | 440 | static void __mnt_unmake_readonly(struct mount *mnt) |
463 | { | 441 | { |
464 | br_write_lock(vfsmount_lock); | 442 | br_write_lock(vfsmount_lock); |
465 | mnt->mnt_flags &= ~MNT_READONLY; | 443 | mnt->mnt.mnt_flags &= ~MNT_READONLY; |
466 | br_write_unlock(vfsmount_lock); | 444 | br_write_unlock(vfsmount_lock); |
467 | } | 445 | } |
468 | 446 | ||
469 | static void free_vfsmnt(struct vfsmount *mnt) | 447 | int sb_prepare_remount_readonly(struct super_block *sb) |
448 | { | ||
449 | struct mount *mnt; | ||
450 | int err = 0; | ||
451 | |||
452 | /* Racy optimization. Recheck the counter under MNT_WRITE_HOLD */ | ||
453 | if (atomic_long_read(&sb->s_remove_count)) | ||
454 | return -EBUSY; | ||
455 | |||
456 | br_write_lock(vfsmount_lock); | ||
457 | list_for_each_entry(mnt, &sb->s_mounts, mnt_instance) { | ||
458 | if (!(mnt->mnt.mnt_flags & MNT_READONLY)) { | ||
459 | mnt->mnt.mnt_flags |= MNT_WRITE_HOLD; | ||
460 | smp_mb(); | ||
461 | if (mnt_get_writers(mnt) > 0) { | ||
462 | err = -EBUSY; | ||
463 | break; | ||
464 | } | ||
465 | } | ||
466 | } | ||
467 | if (!err && atomic_long_read(&sb->s_remove_count)) | ||
468 | err = -EBUSY; | ||
469 | |||
470 | if (!err) { | ||
471 | sb->s_readonly_remount = 1; | ||
472 | smp_wmb(); | ||
473 | } | ||
474 | list_for_each_entry(mnt, &sb->s_mounts, mnt_instance) { | ||
475 | if (mnt->mnt.mnt_flags & MNT_WRITE_HOLD) | ||
476 | mnt->mnt.mnt_flags &= ~MNT_WRITE_HOLD; | ||
477 | } | ||
478 | br_write_unlock(vfsmount_lock); | ||
479 | |||
480 | return err; | ||
481 | } | ||
482 | |||
483 | static void free_vfsmnt(struct mount *mnt) | ||
470 | { | 484 | { |
471 | kfree(mnt->mnt_devname); | 485 | kfree(mnt->mnt_devname); |
472 | mnt_free_id(mnt); | 486 | mnt_free_id(mnt); |
@@ -481,20 +495,20 @@ static void free_vfsmnt(struct vfsmount *mnt) | |||
481 | * @dir. If @dir is set return the first mount else return the last mount. | 495 | * @dir. If @dir is set return the first mount else return the last mount. |
482 | * vfsmount_lock must be held for read or write. | 496 | * vfsmount_lock must be held for read or write. |
483 | */ | 497 | */ |
484 | struct vfsmount *__lookup_mnt(struct vfsmount *mnt, struct dentry *dentry, | 498 | struct mount *__lookup_mnt(struct vfsmount *mnt, struct dentry *dentry, |
485 | int dir) | 499 | int dir) |
486 | { | 500 | { |
487 | struct list_head *head = mount_hashtable + hash(mnt, dentry); | 501 | struct list_head *head = mount_hashtable + hash(mnt, dentry); |
488 | struct list_head *tmp = head; | 502 | struct list_head *tmp = head; |
489 | struct vfsmount *p, *found = NULL; | 503 | struct mount *p, *found = NULL; |
490 | 504 | ||
491 | for (;;) { | 505 | for (;;) { |
492 | tmp = dir ? tmp->next : tmp->prev; | 506 | tmp = dir ? tmp->next : tmp->prev; |
493 | p = NULL; | 507 | p = NULL; |
494 | if (tmp == head) | 508 | if (tmp == head) |
495 | break; | 509 | break; |
496 | p = list_entry(tmp, struct vfsmount, mnt_hash); | 510 | p = list_entry(tmp, struct mount, mnt_hash); |
497 | if (p->mnt_parent == mnt && p->mnt_mountpoint == dentry) { | 511 | if (&p->mnt_parent->mnt == mnt && p->mnt_mountpoint == dentry) { |
498 | found = p; | 512 | found = p; |
499 | break; | 513 | break; |
500 | } | 514 | } |
@@ -508,16 +522,21 @@ struct vfsmount *__lookup_mnt(struct vfsmount *mnt, struct dentry *dentry, | |||
508 | */ | 522 | */ |
509 | struct vfsmount *lookup_mnt(struct path *path) | 523 | struct vfsmount *lookup_mnt(struct path *path) |
510 | { | 524 | { |
511 | struct vfsmount *child_mnt; | 525 | struct mount *child_mnt; |
512 | 526 | ||
513 | br_read_lock(vfsmount_lock); | 527 | br_read_lock(vfsmount_lock); |
514 | if ((child_mnt = __lookup_mnt(path->mnt, path->dentry, 1))) | 528 | child_mnt = __lookup_mnt(path->mnt, path->dentry, 1); |
515 | mntget(child_mnt); | 529 | if (child_mnt) { |
516 | br_read_unlock(vfsmount_lock); | 530 | mnt_add_count(child_mnt, 1); |
517 | return child_mnt; | 531 | br_read_unlock(vfsmount_lock); |
532 | return &child_mnt->mnt; | ||
533 | } else { | ||
534 | br_read_unlock(vfsmount_lock); | ||
535 | return NULL; | ||
536 | } | ||
518 | } | 537 | } |
519 | 538 | ||
520 | static inline int check_mnt(struct vfsmount *mnt) | 539 | static inline int check_mnt(struct mount *mnt) |
521 | { | 540 | { |
522 | return mnt->mnt_ns == current->nsproxy->mnt_ns; | 541 | return mnt->mnt_ns == current->nsproxy->mnt_ns; |
523 | } | 542 | } |
@@ -548,12 +567,12 @@ static void __touch_mnt_namespace(struct mnt_namespace *ns) | |||
548 | * Clear dentry's mounted state if it has no remaining mounts. | 567 | * Clear dentry's mounted state if it has no remaining mounts. |
549 | * vfsmount_lock must be held for write. | 568 | * vfsmount_lock must be held for write. |
550 | */ | 569 | */ |
551 | static void dentry_reset_mounted(struct vfsmount *mnt, struct dentry *dentry) | 570 | static void dentry_reset_mounted(struct dentry *dentry) |
552 | { | 571 | { |
553 | unsigned u; | 572 | unsigned u; |
554 | 573 | ||
555 | for (u = 0; u < HASH_SIZE; u++) { | 574 | for (u = 0; u < HASH_SIZE; u++) { |
556 | struct vfsmount *p; | 575 | struct mount *p; |
557 | 576 | ||
558 | list_for_each_entry(p, &mount_hashtable[u], mnt_hash) { | 577 | list_for_each_entry(p, &mount_hashtable[u], mnt_hash) { |
559 | if (p->mnt_mountpoint == dentry) | 578 | if (p->mnt_mountpoint == dentry) |
@@ -568,25 +587,26 @@ static void dentry_reset_mounted(struct vfsmount *mnt, struct dentry *dentry) | |||
568 | /* | 587 | /* |
569 | * vfsmount lock must be held for write | 588 | * vfsmount lock must be held for write |
570 | */ | 589 | */ |
571 | static void detach_mnt(struct vfsmount *mnt, struct path *old_path) | 590 | static void detach_mnt(struct mount *mnt, struct path *old_path) |
572 | { | 591 | { |
573 | old_path->dentry = mnt->mnt_mountpoint; | 592 | old_path->dentry = mnt->mnt_mountpoint; |
574 | old_path->mnt = mnt->mnt_parent; | 593 | old_path->mnt = &mnt->mnt_parent->mnt; |
575 | mnt->mnt_parent = mnt; | 594 | mnt->mnt_parent = mnt; |
576 | mnt->mnt_mountpoint = mnt->mnt_root; | 595 | mnt->mnt_mountpoint = mnt->mnt.mnt_root; |
577 | list_del_init(&mnt->mnt_child); | 596 | list_del_init(&mnt->mnt_child); |
578 | list_del_init(&mnt->mnt_hash); | 597 | list_del_init(&mnt->mnt_hash); |
579 | dentry_reset_mounted(old_path->mnt, old_path->dentry); | 598 | dentry_reset_mounted(old_path->dentry); |
580 | } | 599 | } |
581 | 600 | ||
582 | /* | 601 | /* |
583 | * vfsmount lock must be held for write | 602 | * vfsmount lock must be held for write |
584 | */ | 603 | */ |
585 | void mnt_set_mountpoint(struct vfsmount *mnt, struct dentry *dentry, | 604 | void mnt_set_mountpoint(struct mount *mnt, struct dentry *dentry, |
586 | struct vfsmount *child_mnt) | 605 | struct mount *child_mnt) |
587 | { | 606 | { |
588 | child_mnt->mnt_parent = mntget(mnt); | 607 | mnt_add_count(mnt, 1); /* essentially, that's mntget */ |
589 | child_mnt->mnt_mountpoint = dget(dentry); | 608 | child_mnt->mnt_mountpoint = dget(dentry); |
609 | child_mnt->mnt_parent = mnt; | ||
590 | spin_lock(&dentry->d_lock); | 610 | spin_lock(&dentry->d_lock); |
591 | dentry->d_flags |= DCACHE_MOUNTED; | 611 | dentry->d_flags |= DCACHE_MOUNTED; |
592 | spin_unlock(&dentry->d_lock); | 612 | spin_unlock(&dentry->d_lock); |
@@ -595,15 +615,15 @@ void mnt_set_mountpoint(struct vfsmount *mnt, struct dentry *dentry, | |||
595 | /* | 615 | /* |
596 | * vfsmount lock must be held for write | 616 | * vfsmount lock must be held for write |
597 | */ | 617 | */ |
598 | static void attach_mnt(struct vfsmount *mnt, struct path *path) | 618 | static void attach_mnt(struct mount *mnt, struct path *path) |
599 | { | 619 | { |
600 | mnt_set_mountpoint(path->mnt, path->dentry, mnt); | 620 | mnt_set_mountpoint(real_mount(path->mnt), path->dentry, mnt); |
601 | list_add_tail(&mnt->mnt_hash, mount_hashtable + | 621 | list_add_tail(&mnt->mnt_hash, mount_hashtable + |
602 | hash(path->mnt, path->dentry)); | 622 | hash(path->mnt, path->dentry)); |
603 | list_add_tail(&mnt->mnt_child, &path->mnt->mnt_mounts); | 623 | list_add_tail(&mnt->mnt_child, &real_mount(path->mnt)->mnt_mounts); |
604 | } | 624 | } |
605 | 625 | ||
606 | static inline void __mnt_make_longterm(struct vfsmount *mnt) | 626 | static inline void __mnt_make_longterm(struct mount *mnt) |
607 | { | 627 | { |
608 | #ifdef CONFIG_SMP | 628 | #ifdef CONFIG_SMP |
609 | atomic_inc(&mnt->mnt_longterm); | 629 | atomic_inc(&mnt->mnt_longterm); |
@@ -611,7 +631,7 @@ static inline void __mnt_make_longterm(struct vfsmount *mnt) | |||
611 | } | 631 | } |
612 | 632 | ||
613 | /* needs vfsmount lock for write */ | 633 | /* needs vfsmount lock for write */ |
614 | static inline void __mnt_make_shortterm(struct vfsmount *mnt) | 634 | static inline void __mnt_make_shortterm(struct mount *mnt) |
615 | { | 635 | { |
616 | #ifdef CONFIG_SMP | 636 | #ifdef CONFIG_SMP |
617 | atomic_dec(&mnt->mnt_longterm); | 637 | atomic_dec(&mnt->mnt_longterm); |
@@ -621,10 +641,10 @@ static inline void __mnt_make_shortterm(struct vfsmount *mnt) | |||
621 | /* | 641 | /* |
622 | * vfsmount lock must be held for write | 642 | * vfsmount lock must be held for write |
623 | */ | 643 | */ |
624 | static void commit_tree(struct vfsmount *mnt) | 644 | static void commit_tree(struct mount *mnt) |
625 | { | 645 | { |
626 | struct vfsmount *parent = mnt->mnt_parent; | 646 | struct mount *parent = mnt->mnt_parent; |
627 | struct vfsmount *m; | 647 | struct mount *m; |
628 | LIST_HEAD(head); | 648 | LIST_HEAD(head); |
629 | struct mnt_namespace *n = parent->mnt_ns; | 649 | struct mnt_namespace *n = parent->mnt_ns; |
630 | 650 | ||
@@ -639,12 +659,12 @@ static void commit_tree(struct vfsmount *mnt) | |||
639 | list_splice(&head, n->list.prev); | 659 | list_splice(&head, n->list.prev); |
640 | 660 | ||
641 | list_add_tail(&mnt->mnt_hash, mount_hashtable + | 661 | list_add_tail(&mnt->mnt_hash, mount_hashtable + |
642 | hash(parent, mnt->mnt_mountpoint)); | 662 | hash(&parent->mnt, mnt->mnt_mountpoint)); |
643 | list_add_tail(&mnt->mnt_child, &parent->mnt_mounts); | 663 | list_add_tail(&mnt->mnt_child, &parent->mnt_mounts); |
644 | touch_mnt_namespace(n); | 664 | touch_mnt_namespace(n); |
645 | } | 665 | } |
646 | 666 | ||
647 | static struct vfsmount *next_mnt(struct vfsmount *p, struct vfsmount *root) | 667 | static struct mount *next_mnt(struct mount *p, struct mount *root) |
648 | { | 668 | { |
649 | struct list_head *next = p->mnt_mounts.next; | 669 | struct list_head *next = p->mnt_mounts.next; |
650 | if (next == &p->mnt_mounts) { | 670 | if (next == &p->mnt_mounts) { |
@@ -657,14 +677,14 @@ static struct vfsmount *next_mnt(struct vfsmount *p, struct vfsmount *root) | |||
657 | p = p->mnt_parent; | 677 | p = p->mnt_parent; |
658 | } | 678 | } |
659 | } | 679 | } |
660 | return list_entry(next, struct vfsmount, mnt_child); | 680 | return list_entry(next, struct mount, mnt_child); |
661 | } | 681 | } |
662 | 682 | ||
663 | static struct vfsmount *skip_mnt_tree(struct vfsmount *p) | 683 | static struct mount *skip_mnt_tree(struct mount *p) |
664 | { | 684 | { |
665 | struct list_head *prev = p->mnt_mounts.prev; | 685 | struct list_head *prev = p->mnt_mounts.prev; |
666 | while (prev != &p->mnt_mounts) { | 686 | while (prev != &p->mnt_mounts) { |
667 | p = list_entry(prev, struct vfsmount, mnt_child); | 687 | p = list_entry(prev, struct mount, mnt_child); |
668 | prev = p->mnt_mounts.prev; | 688 | prev = p->mnt_mounts.prev; |
669 | } | 689 | } |
670 | return p; | 690 | return p; |
@@ -673,7 +693,7 @@ static struct vfsmount *skip_mnt_tree(struct vfsmount *p) | |||
673 | struct vfsmount * | 693 | struct vfsmount * |
674 | vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data) | 694 | vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data) |
675 | { | 695 | { |
676 | struct vfsmount *mnt; | 696 | struct mount *mnt; |
677 | struct dentry *root; | 697 | struct dentry *root; |
678 | 698 | ||
679 | if (!type) | 699 | if (!type) |
@@ -684,7 +704,7 @@ vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void | |||
684 | return ERR_PTR(-ENOMEM); | 704 | return ERR_PTR(-ENOMEM); |
685 | 705 | ||
686 | if (flags & MS_KERNMOUNT) | 706 | if (flags & MS_KERNMOUNT) |
687 | mnt->mnt_flags = MNT_INTERNAL; | 707 | mnt->mnt.mnt_flags = MNT_INTERNAL; |
688 | 708 | ||
689 | root = mount_fs(type, flags, name, data); | 709 | root = mount_fs(type, flags, name, data); |
690 | if (IS_ERR(root)) { | 710 | if (IS_ERR(root)) { |
@@ -692,19 +712,22 @@ vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void | |||
692 | return ERR_CAST(root); | 712 | return ERR_CAST(root); |
693 | } | 713 | } |
694 | 714 | ||
695 | mnt->mnt_root = root; | 715 | mnt->mnt.mnt_root = root; |
696 | mnt->mnt_sb = root->d_sb; | 716 | mnt->mnt.mnt_sb = root->d_sb; |
697 | mnt->mnt_mountpoint = mnt->mnt_root; | 717 | mnt->mnt_mountpoint = mnt->mnt.mnt_root; |
698 | mnt->mnt_parent = mnt; | 718 | mnt->mnt_parent = mnt; |
699 | return mnt; | 719 | br_write_lock(vfsmount_lock); |
720 | list_add_tail(&mnt->mnt_instance, &root->d_sb->s_mounts); | ||
721 | br_write_unlock(vfsmount_lock); | ||
722 | return &mnt->mnt; | ||
700 | } | 723 | } |
701 | EXPORT_SYMBOL_GPL(vfs_kern_mount); | 724 | EXPORT_SYMBOL_GPL(vfs_kern_mount); |
702 | 725 | ||
703 | static struct vfsmount *clone_mnt(struct vfsmount *old, struct dentry *root, | 726 | static struct mount *clone_mnt(struct mount *old, struct dentry *root, |
704 | int flag) | 727 | int flag) |
705 | { | 728 | { |
706 | struct super_block *sb = old->mnt_sb; | 729 | struct super_block *sb = old->mnt.mnt_sb; |
707 | struct vfsmount *mnt = alloc_vfsmnt(old->mnt_devname); | 730 | struct mount *mnt = alloc_vfsmnt(old->mnt_devname); |
708 | 731 | ||
709 | if (mnt) { | 732 | if (mnt) { |
710 | if (flag & (CL_SLAVE | CL_PRIVATE)) | 733 | if (flag & (CL_SLAVE | CL_PRIVATE)) |
@@ -718,12 +741,15 @@ static struct vfsmount *clone_mnt(struct vfsmount *old, struct dentry *root, | |||
718 | goto out_free; | 741 | goto out_free; |
719 | } | 742 | } |
720 | 743 | ||
721 | mnt->mnt_flags = old->mnt_flags & ~MNT_WRITE_HOLD; | 744 | mnt->mnt.mnt_flags = old->mnt.mnt_flags & ~MNT_WRITE_HOLD; |
722 | atomic_inc(&sb->s_active); | 745 | atomic_inc(&sb->s_active); |
723 | mnt->mnt_sb = sb; | 746 | mnt->mnt.mnt_sb = sb; |
724 | mnt->mnt_root = dget(root); | 747 | mnt->mnt.mnt_root = dget(root); |
725 | mnt->mnt_mountpoint = mnt->mnt_root; | 748 | mnt->mnt_mountpoint = mnt->mnt.mnt_root; |
726 | mnt->mnt_parent = mnt; | 749 | mnt->mnt_parent = mnt; |
750 | br_write_lock(vfsmount_lock); | ||
751 | list_add_tail(&mnt->mnt_instance, &sb->s_mounts); | ||
752 | br_write_unlock(vfsmount_lock); | ||
727 | 753 | ||
728 | if (flag & CL_SLAVE) { | 754 | if (flag & CL_SLAVE) { |
729 | list_add(&mnt->mnt_slave, &old->mnt_slave_list); | 755 | list_add(&mnt->mnt_slave, &old->mnt_slave_list); |
@@ -753,9 +779,10 @@ static struct vfsmount *clone_mnt(struct vfsmount *old, struct dentry *root, | |||
753 | return NULL; | 779 | return NULL; |
754 | } | 780 | } |
755 | 781 | ||
756 | static inline void mntfree(struct vfsmount *mnt) | 782 | static inline void mntfree(struct mount *mnt) |
757 | { | 783 | { |
758 | struct super_block *sb = mnt->mnt_sb; | 784 | struct vfsmount *m = &mnt->mnt; |
785 | struct super_block *sb = m->mnt_sb; | ||
759 | 786 | ||
760 | /* | 787 | /* |
761 | * This probably indicates that somebody messed | 788 | * This probably indicates that somebody messed |
@@ -768,32 +795,32 @@ static inline void mntfree(struct vfsmount *mnt) | |||
768 | * so mnt_get_writers() below is safe. | 795 | * so mnt_get_writers() below is safe. |
769 | */ | 796 | */ |
770 | WARN_ON(mnt_get_writers(mnt)); | 797 | WARN_ON(mnt_get_writers(mnt)); |
771 | fsnotify_vfsmount_delete(mnt); | 798 | fsnotify_vfsmount_delete(m); |
772 | dput(mnt->mnt_root); | 799 | dput(m->mnt_root); |
773 | free_vfsmnt(mnt); | 800 | free_vfsmnt(mnt); |
774 | deactivate_super(sb); | 801 | deactivate_super(sb); |
775 | } | 802 | } |
776 | 803 | ||
777 | static void mntput_no_expire(struct vfsmount *mnt) | 804 | static void mntput_no_expire(struct mount *mnt) |
778 | { | 805 | { |
779 | put_again: | 806 | put_again: |
780 | #ifdef CONFIG_SMP | 807 | #ifdef CONFIG_SMP |
781 | br_read_lock(vfsmount_lock); | 808 | br_read_lock(vfsmount_lock); |
782 | if (likely(atomic_read(&mnt->mnt_longterm))) { | 809 | if (likely(atomic_read(&mnt->mnt_longterm))) { |
783 | mnt_dec_count(mnt); | 810 | mnt_add_count(mnt, -1); |
784 | br_read_unlock(vfsmount_lock); | 811 | br_read_unlock(vfsmount_lock); |
785 | return; | 812 | return; |
786 | } | 813 | } |
787 | br_read_unlock(vfsmount_lock); | 814 | br_read_unlock(vfsmount_lock); |
788 | 815 | ||
789 | br_write_lock(vfsmount_lock); | 816 | br_write_lock(vfsmount_lock); |
790 | mnt_dec_count(mnt); | 817 | mnt_add_count(mnt, -1); |
791 | if (mnt_get_count(mnt)) { | 818 | if (mnt_get_count(mnt)) { |
792 | br_write_unlock(vfsmount_lock); | 819 | br_write_unlock(vfsmount_lock); |
793 | return; | 820 | return; |
794 | } | 821 | } |
795 | #else | 822 | #else |
796 | mnt_dec_count(mnt); | 823 | mnt_add_count(mnt, -1); |
797 | if (likely(mnt_get_count(mnt))) | 824 | if (likely(mnt_get_count(mnt))) |
798 | return; | 825 | return; |
799 | br_write_lock(vfsmount_lock); | 826 | br_write_lock(vfsmount_lock); |
@@ -802,9 +829,10 @@ put_again: | |||
802 | mnt_add_count(mnt, mnt->mnt_pinned + 1); | 829 | mnt_add_count(mnt, mnt->mnt_pinned + 1); |
803 | mnt->mnt_pinned = 0; | 830 | mnt->mnt_pinned = 0; |
804 | br_write_unlock(vfsmount_lock); | 831 | br_write_unlock(vfsmount_lock); |
805 | acct_auto_close_mnt(mnt); | 832 | acct_auto_close_mnt(&mnt->mnt); |
806 | goto put_again; | 833 | goto put_again; |
807 | } | 834 | } |
835 | list_del(&mnt->mnt_instance); | ||
808 | br_write_unlock(vfsmount_lock); | 836 | br_write_unlock(vfsmount_lock); |
809 | mntfree(mnt); | 837 | mntfree(mnt); |
810 | } | 838 | } |
@@ -812,10 +840,11 @@ put_again: | |||
812 | void mntput(struct vfsmount *mnt) | 840 | void mntput(struct vfsmount *mnt) |
813 | { | 841 | { |
814 | if (mnt) { | 842 | if (mnt) { |
843 | struct mount *m = real_mount(mnt); | ||
815 | /* avoid cacheline pingpong, hope gcc doesn't get "smart" */ | 844 | /* avoid cacheline pingpong, hope gcc doesn't get "smart" */ |
816 | if (unlikely(mnt->mnt_expiry_mark)) | 845 | if (unlikely(m->mnt_expiry_mark)) |
817 | mnt->mnt_expiry_mark = 0; | 846 | m->mnt_expiry_mark = 0; |
818 | mntput_no_expire(mnt); | 847 | mntput_no_expire(m); |
819 | } | 848 | } |
820 | } | 849 | } |
821 | EXPORT_SYMBOL(mntput); | 850 | EXPORT_SYMBOL(mntput); |
@@ -823,7 +852,7 @@ EXPORT_SYMBOL(mntput); | |||
823 | struct vfsmount *mntget(struct vfsmount *mnt) | 852 | struct vfsmount *mntget(struct vfsmount *mnt) |
824 | { | 853 | { |
825 | if (mnt) | 854 | if (mnt) |
826 | mnt_inc_count(mnt); | 855 | mnt_add_count(real_mount(mnt), 1); |
827 | return mnt; | 856 | return mnt; |
828 | } | 857 | } |
829 | EXPORT_SYMBOL(mntget); | 858 | EXPORT_SYMBOL(mntget); |
@@ -831,16 +860,17 @@ EXPORT_SYMBOL(mntget); | |||
831 | void mnt_pin(struct vfsmount *mnt) | 860 | void mnt_pin(struct vfsmount *mnt) |
832 | { | 861 | { |
833 | br_write_lock(vfsmount_lock); | 862 | br_write_lock(vfsmount_lock); |
834 | mnt->mnt_pinned++; | 863 | real_mount(mnt)->mnt_pinned++; |
835 | br_write_unlock(vfsmount_lock); | 864 | br_write_unlock(vfsmount_lock); |
836 | } | 865 | } |
837 | EXPORT_SYMBOL(mnt_pin); | 866 | EXPORT_SYMBOL(mnt_pin); |
838 | 867 | ||
839 | void mnt_unpin(struct vfsmount *mnt) | 868 | void mnt_unpin(struct vfsmount *m) |
840 | { | 869 | { |
870 | struct mount *mnt = real_mount(m); | ||
841 | br_write_lock(vfsmount_lock); | 871 | br_write_lock(vfsmount_lock); |
842 | if (mnt->mnt_pinned) { | 872 | if (mnt->mnt_pinned) { |
843 | mnt_inc_count(mnt); | 873 | mnt_add_count(mnt, 1); |
844 | mnt->mnt_pinned--; | 874 | mnt->mnt_pinned--; |
845 | } | 875 | } |
846 | br_write_unlock(vfsmount_lock); | 876 | br_write_unlock(vfsmount_lock); |
@@ -858,12 +888,12 @@ static inline void mangle(struct seq_file *m, const char *s) | |||
858 | * | 888 | * |
859 | * See also save_mount_options(). | 889 | * See also save_mount_options(). |
860 | */ | 890 | */ |
861 | int generic_show_options(struct seq_file *m, struct vfsmount *mnt) | 891 | int generic_show_options(struct seq_file *m, struct dentry *root) |
862 | { | 892 | { |
863 | const char *options; | 893 | const char *options; |
864 | 894 | ||
865 | rcu_read_lock(); | 895 | rcu_read_lock(); |
866 | options = rcu_dereference(mnt->mnt_sb->s_options); | 896 | options = rcu_dereference(root->d_sb->s_options); |
867 | 897 | ||
868 | if (options != NULL && options[0]) { | 898 | if (options != NULL && options[0]) { |
869 | seq_putc(m, ','); | 899 | seq_putc(m, ','); |
@@ -907,10 +937,10 @@ void replace_mount_options(struct super_block *sb, char *options) | |||
907 | EXPORT_SYMBOL(replace_mount_options); | 937 | EXPORT_SYMBOL(replace_mount_options); |
908 | 938 | ||
909 | #ifdef CONFIG_PROC_FS | 939 | #ifdef CONFIG_PROC_FS |
910 | /* iterator */ | 940 | /* iterator; we want it to have access to namespace_sem, thus here... */ |
911 | static void *m_start(struct seq_file *m, loff_t *pos) | 941 | static void *m_start(struct seq_file *m, loff_t *pos) |
912 | { | 942 | { |
913 | struct proc_mounts *p = m->private; | 943 | struct proc_mounts *p = container_of(m, struct proc_mounts, m); |
914 | 944 | ||
915 | down_read(&namespace_sem); | 945 | down_read(&namespace_sem); |
916 | return seq_list_start(&p->ns->list, *pos); | 946 | return seq_list_start(&p->ns->list, *pos); |
@@ -918,7 +948,7 @@ static void *m_start(struct seq_file *m, loff_t *pos) | |||
918 | 948 | ||
919 | static void *m_next(struct seq_file *m, void *v, loff_t *pos) | 949 | static void *m_next(struct seq_file *m, void *v, loff_t *pos) |
920 | { | 950 | { |
921 | struct proc_mounts *p = m->private; | 951 | struct proc_mounts *p = container_of(m, struct proc_mounts, m); |
922 | 952 | ||
923 | return seq_list_next(v, &p->ns->list, pos); | 953 | return seq_list_next(v, &p->ns->list, pos); |
924 | } | 954 | } |
@@ -928,219 +958,18 @@ static void m_stop(struct seq_file *m, void *v) | |||
928 | up_read(&namespace_sem); | 958 | up_read(&namespace_sem); |
929 | } | 959 | } |
930 | 960 | ||
931 | int mnt_had_events(struct proc_mounts *p) | 961 | static int m_show(struct seq_file *m, void *v) |
932 | { | 962 | { |
933 | struct mnt_namespace *ns = p->ns; | 963 | struct proc_mounts *p = container_of(m, struct proc_mounts, m); |
934 | int res = 0; | 964 | struct mount *r = list_entry(v, struct mount, mnt_list); |
935 | 965 | return p->show(m, &r->mnt); | |
936 | br_read_lock(vfsmount_lock); | ||
937 | if (p->m.poll_event != ns->event) { | ||
938 | p->m.poll_event = ns->event; | ||
939 | res = 1; | ||
940 | } | ||
941 | br_read_unlock(vfsmount_lock); | ||
942 | |||
943 | return res; | ||
944 | } | ||
945 | |||
946 | struct proc_fs_info { | ||
947 | int flag; | ||
948 | const char *str; | ||
949 | }; | ||
950 | |||
951 | static int show_sb_opts(struct seq_file *m, struct super_block *sb) | ||
952 | { | ||
953 | static const struct proc_fs_info fs_info[] = { | ||
954 | { MS_SYNCHRONOUS, ",sync" }, | ||
955 | { MS_DIRSYNC, ",dirsync" }, | ||
956 | { MS_MANDLOCK, ",mand" }, | ||
957 | { 0, NULL } | ||
958 | }; | ||
959 | const struct proc_fs_info *fs_infop; | ||
960 | |||
961 | for (fs_infop = fs_info; fs_infop->flag; fs_infop++) { | ||
962 | if (sb->s_flags & fs_infop->flag) | ||
963 | seq_puts(m, fs_infop->str); | ||
964 | } | ||
965 | |||
966 | return security_sb_show_options(m, sb); | ||
967 | } | ||
968 | |||
969 | static void show_mnt_opts(struct seq_file *m, struct vfsmount *mnt) | ||
970 | { | ||
971 | static const struct proc_fs_info mnt_info[] = { | ||
972 | { MNT_NOSUID, ",nosuid" }, | ||
973 | { MNT_NODEV, ",nodev" }, | ||
974 | { MNT_NOEXEC, ",noexec" }, | ||
975 | { MNT_NOATIME, ",noatime" }, | ||
976 | { MNT_NODIRATIME, ",nodiratime" }, | ||
977 | { MNT_RELATIME, ",relatime" }, | ||
978 | { 0, NULL } | ||
979 | }; | ||
980 | const struct proc_fs_info *fs_infop; | ||
981 | |||
982 | for (fs_infop = mnt_info; fs_infop->flag; fs_infop++) { | ||
983 | if (mnt->mnt_flags & fs_infop->flag) | ||
984 | seq_puts(m, fs_infop->str); | ||
985 | } | ||
986 | } | ||
987 | |||
988 | static void show_type(struct seq_file *m, struct super_block *sb) | ||
989 | { | ||
990 | mangle(m, sb->s_type->name); | ||
991 | if (sb->s_subtype && sb->s_subtype[0]) { | ||
992 | seq_putc(m, '.'); | ||
993 | mangle(m, sb->s_subtype); | ||
994 | } | ||
995 | } | ||
996 | |||
997 | static int show_vfsmnt(struct seq_file *m, void *v) | ||
998 | { | ||
999 | struct vfsmount *mnt = list_entry(v, struct vfsmount, mnt_list); | ||
1000 | int err = 0; | ||
1001 | struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt }; | ||
1002 | |||
1003 | if (mnt->mnt_sb->s_op->show_devname) { | ||
1004 | err = mnt->mnt_sb->s_op->show_devname(m, mnt); | ||
1005 | if (err) | ||
1006 | goto out; | ||
1007 | } else { | ||
1008 | mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none"); | ||
1009 | } | ||
1010 | seq_putc(m, ' '); | ||
1011 | seq_path(m, &mnt_path, " \t\n\\"); | ||
1012 | seq_putc(m, ' '); | ||
1013 | show_type(m, mnt->mnt_sb); | ||
1014 | seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw"); | ||
1015 | err = show_sb_opts(m, mnt->mnt_sb); | ||
1016 | if (err) | ||
1017 | goto out; | ||
1018 | show_mnt_opts(m, mnt); | ||
1019 | if (mnt->mnt_sb->s_op->show_options) | ||
1020 | err = mnt->mnt_sb->s_op->show_options(m, mnt); | ||
1021 | seq_puts(m, " 0 0\n"); | ||
1022 | out: | ||
1023 | return err; | ||
1024 | } | 966 | } |
1025 | 967 | ||
1026 | const struct seq_operations mounts_op = { | 968 | const struct seq_operations mounts_op = { |
1027 | .start = m_start, | 969 | .start = m_start, |
1028 | .next = m_next, | 970 | .next = m_next, |
1029 | .stop = m_stop, | 971 | .stop = m_stop, |
1030 | .show = show_vfsmnt | 972 | .show = m_show, |
1031 | }; | ||
1032 | |||
1033 | static int show_mountinfo(struct seq_file *m, void *v) | ||
1034 | { | ||
1035 | struct proc_mounts *p = m->private; | ||
1036 | struct vfsmount *mnt = list_entry(v, struct vfsmount, mnt_list); | ||
1037 | struct super_block *sb = mnt->mnt_sb; | ||
1038 | struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt }; | ||
1039 | struct path root = p->root; | ||
1040 | int err = 0; | ||
1041 | |||
1042 | seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id, | ||
1043 | MAJOR(sb->s_dev), MINOR(sb->s_dev)); | ||
1044 | if (sb->s_op->show_path) | ||
1045 | err = sb->s_op->show_path(m, mnt); | ||
1046 | else | ||
1047 | seq_dentry(m, mnt->mnt_root, " \t\n\\"); | ||
1048 | if (err) | ||
1049 | goto out; | ||
1050 | seq_putc(m, ' '); | ||
1051 | |||
1052 | /* mountpoints outside of chroot jail will give SEQ_SKIP on this */ | ||
1053 | err = seq_path_root(m, &mnt_path, &root, " \t\n\\"); | ||
1054 | if (err) | ||
1055 | goto out; | ||
1056 | |||
1057 | seq_puts(m, mnt->mnt_flags & MNT_READONLY ? " ro" : " rw"); | ||
1058 | show_mnt_opts(m, mnt); | ||
1059 | |||
1060 | /* Tagged fields ("foo:X" or "bar") */ | ||
1061 | if (IS_MNT_SHARED(mnt)) | ||
1062 | seq_printf(m, " shared:%i", mnt->mnt_group_id); | ||
1063 | if (IS_MNT_SLAVE(mnt)) { | ||
1064 | int master = mnt->mnt_master->mnt_group_id; | ||
1065 | int dom = get_dominating_id(mnt, &p->root); | ||
1066 | seq_printf(m, " master:%i", master); | ||
1067 | if (dom && dom != master) | ||
1068 | seq_printf(m, " propagate_from:%i", dom); | ||
1069 | } | ||
1070 | if (IS_MNT_UNBINDABLE(mnt)) | ||
1071 | seq_puts(m, " unbindable"); | ||
1072 | |||
1073 | /* Filesystem specific data */ | ||
1074 | seq_puts(m, " - "); | ||
1075 | show_type(m, sb); | ||
1076 | seq_putc(m, ' '); | ||
1077 | if (sb->s_op->show_devname) | ||
1078 | err = sb->s_op->show_devname(m, mnt); | ||
1079 | else | ||
1080 | mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none"); | ||
1081 | if (err) | ||
1082 | goto out; | ||
1083 | seq_puts(m, sb->s_flags & MS_RDONLY ? " ro" : " rw"); | ||
1084 | err = show_sb_opts(m, sb); | ||
1085 | if (err) | ||
1086 | goto out; | ||
1087 | if (sb->s_op->show_options) | ||
1088 | err = sb->s_op->show_options(m, mnt); | ||
1089 | seq_putc(m, '\n'); | ||
1090 | out: | ||
1091 | return err; | ||
1092 | } | ||
1093 | |||
1094 | const struct seq_operations mountinfo_op = { | ||
1095 | .start = m_start, | ||
1096 | .next = m_next, | ||
1097 | .stop = m_stop, | ||
1098 | .show = show_mountinfo, | ||
1099 | }; | ||
1100 | |||
1101 | static int show_vfsstat(struct seq_file *m, void *v) | ||
1102 | { | ||
1103 | struct vfsmount *mnt = list_entry(v, struct vfsmount, mnt_list); | ||
1104 | struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt }; | ||
1105 | int err = 0; | ||
1106 | |||
1107 | /* device */ | ||
1108 | if (mnt->mnt_sb->s_op->show_devname) { | ||
1109 | seq_puts(m, "device "); | ||
1110 | err = mnt->mnt_sb->s_op->show_devname(m, mnt); | ||
1111 | } else { | ||
1112 | if (mnt->mnt_devname) { | ||
1113 | seq_puts(m, "device "); | ||
1114 | mangle(m, mnt->mnt_devname); | ||
1115 | } else | ||
1116 | seq_puts(m, "no device"); | ||
1117 | } | ||
1118 | |||
1119 | /* mount point */ | ||
1120 | seq_puts(m, " mounted on "); | ||
1121 | seq_path(m, &mnt_path, " \t\n\\"); | ||
1122 | seq_putc(m, ' '); | ||
1123 | |||
1124 | /* file system type */ | ||
1125 | seq_puts(m, "with fstype "); | ||
1126 | show_type(m, mnt->mnt_sb); | ||
1127 | |||
1128 | /* optional statistics */ | ||
1129 | if (mnt->mnt_sb->s_op->show_stats) { | ||
1130 | seq_putc(m, ' '); | ||
1131 | if (!err) | ||
1132 | err = mnt->mnt_sb->s_op->show_stats(m, mnt); | ||
1133 | } | ||
1134 | |||
1135 | seq_putc(m, '\n'); | ||
1136 | return err; | ||
1137 | } | ||
1138 | |||
1139 | const struct seq_operations mountstats_op = { | ||
1140 | .start = m_start, | ||
1141 | .next = m_next, | ||
1142 | .stop = m_stop, | ||
1143 | .show = show_vfsstat, | ||
1144 | }; | 973 | }; |
1145 | #endif /* CONFIG_PROC_FS */ | 974 | #endif /* CONFIG_PROC_FS */ |
1146 | 975 | ||
@@ -1152,11 +981,13 @@ const struct seq_operations mountstats_op = { | |||
1152 | * open files, pwds, chroots or sub mounts that are | 981 | * open files, pwds, chroots or sub mounts that are |
1153 | * busy. | 982 | * busy. |
1154 | */ | 983 | */ |
1155 | int may_umount_tree(struct vfsmount *mnt) | 984 | int may_umount_tree(struct vfsmount *m) |
1156 | { | 985 | { |
986 | struct mount *mnt = real_mount(m); | ||
1157 | int actual_refs = 0; | 987 | int actual_refs = 0; |
1158 | int minimum_refs = 0; | 988 | int minimum_refs = 0; |
1159 | struct vfsmount *p; | 989 | struct mount *p; |
990 | BUG_ON(!m); | ||
1160 | 991 | ||
1161 | /* write lock needed for mnt_get_count */ | 992 | /* write lock needed for mnt_get_count */ |
1162 | br_write_lock(vfsmount_lock); | 993 | br_write_lock(vfsmount_lock); |
@@ -1192,7 +1023,7 @@ int may_umount(struct vfsmount *mnt) | |||
1192 | int ret = 1; | 1023 | int ret = 1; |
1193 | down_read(&namespace_sem); | 1024 | down_read(&namespace_sem); |
1194 | br_write_lock(vfsmount_lock); | 1025 | br_write_lock(vfsmount_lock); |
1195 | if (propagate_mount_busy(mnt, 2)) | 1026 | if (propagate_mount_busy(real_mount(mnt), 2)) |
1196 | ret = 0; | 1027 | ret = 0; |
1197 | br_write_unlock(vfsmount_lock); | 1028 | br_write_unlock(vfsmount_lock); |
1198 | up_read(&namespace_sem); | 1029 | up_read(&namespace_sem); |
@@ -1203,25 +1034,25 @@ EXPORT_SYMBOL(may_umount); | |||
1203 | 1034 | ||
1204 | void release_mounts(struct list_head *head) | 1035 | void release_mounts(struct list_head *head) |
1205 | { | 1036 | { |
1206 | struct vfsmount *mnt; | 1037 | struct mount *mnt; |
1207 | while (!list_empty(head)) { | 1038 | while (!list_empty(head)) { |
1208 | mnt = list_first_entry(head, struct vfsmount, mnt_hash); | 1039 | mnt = list_first_entry(head, struct mount, mnt_hash); |
1209 | list_del_init(&mnt->mnt_hash); | 1040 | list_del_init(&mnt->mnt_hash); |
1210 | if (mnt->mnt_parent != mnt) { | 1041 | if (mnt_has_parent(mnt)) { |
1211 | struct dentry *dentry; | 1042 | struct dentry *dentry; |
1212 | struct vfsmount *m; | 1043 | struct mount *m; |
1213 | 1044 | ||
1214 | br_write_lock(vfsmount_lock); | 1045 | br_write_lock(vfsmount_lock); |
1215 | dentry = mnt->mnt_mountpoint; | 1046 | dentry = mnt->mnt_mountpoint; |
1216 | m = mnt->mnt_parent; | 1047 | m = mnt->mnt_parent; |
1217 | mnt->mnt_mountpoint = mnt->mnt_root; | 1048 | mnt->mnt_mountpoint = mnt->mnt.mnt_root; |
1218 | mnt->mnt_parent = mnt; | 1049 | mnt->mnt_parent = mnt; |
1219 | m->mnt_ghosts--; | 1050 | m->mnt_ghosts--; |
1220 | br_write_unlock(vfsmount_lock); | 1051 | br_write_unlock(vfsmount_lock); |
1221 | dput(dentry); | 1052 | dput(dentry); |
1222 | mntput(m); | 1053 | mntput(&m->mnt); |
1223 | } | 1054 | } |
1224 | mntput(mnt); | 1055 | mntput(&mnt->mnt); |
1225 | } | 1056 | } |
1226 | } | 1057 | } |
1227 | 1058 | ||
@@ -1229,10 +1060,10 @@ void release_mounts(struct list_head *head) | |||
1229 | * vfsmount lock must be held for write | 1060 | * vfsmount lock must be held for write |
1230 | * namespace_sem must be held for write | 1061 | * namespace_sem must be held for write |
1231 | */ | 1062 | */ |
1232 | void umount_tree(struct vfsmount *mnt, int propagate, struct list_head *kill) | 1063 | void umount_tree(struct mount *mnt, int propagate, struct list_head *kill) |
1233 | { | 1064 | { |
1234 | LIST_HEAD(tmp_list); | 1065 | LIST_HEAD(tmp_list); |
1235 | struct vfsmount *p; | 1066 | struct mount *p; |
1236 | 1067 | ||
1237 | for (p = mnt; p; p = next_mnt(p, mnt)) | 1068 | for (p = mnt; p; p = next_mnt(p, mnt)) |
1238 | list_move(&p->mnt_hash, &tmp_list); | 1069 | list_move(&p->mnt_hash, &tmp_list); |
@@ -1247,24 +1078,24 @@ void umount_tree(struct vfsmount *mnt, int propagate, struct list_head *kill) | |||
1247 | p->mnt_ns = NULL; | 1078 | p->mnt_ns = NULL; |
1248 | __mnt_make_shortterm(p); | 1079 | __mnt_make_shortterm(p); |
1249 | list_del_init(&p->mnt_child); | 1080 | list_del_init(&p->mnt_child); |
1250 | if (p->mnt_parent != p) { | 1081 | if (mnt_has_parent(p)) { |
1251 | p->mnt_parent->mnt_ghosts++; | 1082 | p->mnt_parent->mnt_ghosts++; |
1252 | dentry_reset_mounted(p->mnt_parent, p->mnt_mountpoint); | 1083 | dentry_reset_mounted(p->mnt_mountpoint); |
1253 | } | 1084 | } |
1254 | change_mnt_propagation(p, MS_PRIVATE); | 1085 | change_mnt_propagation(p, MS_PRIVATE); |
1255 | } | 1086 | } |
1256 | list_splice(&tmp_list, kill); | 1087 | list_splice(&tmp_list, kill); |
1257 | } | 1088 | } |
1258 | 1089 | ||
1259 | static void shrink_submounts(struct vfsmount *mnt, struct list_head *umounts); | 1090 | static void shrink_submounts(struct mount *mnt, struct list_head *umounts); |
1260 | 1091 | ||
1261 | static int do_umount(struct vfsmount *mnt, int flags) | 1092 | static int do_umount(struct mount *mnt, int flags) |
1262 | { | 1093 | { |
1263 | struct super_block *sb = mnt->mnt_sb; | 1094 | struct super_block *sb = mnt->mnt.mnt_sb; |
1264 | int retval; | 1095 | int retval; |
1265 | LIST_HEAD(umount_list); | 1096 | LIST_HEAD(umount_list); |
1266 | 1097 | ||
1267 | retval = security_sb_umount(mnt, flags); | 1098 | retval = security_sb_umount(&mnt->mnt, flags); |
1268 | if (retval) | 1099 | if (retval) |
1269 | return retval; | 1100 | return retval; |
1270 | 1101 | ||
@@ -1275,7 +1106,7 @@ static int do_umount(struct vfsmount *mnt, int flags) | |||
1275 | * (2) the usage count == 1 [parent vfsmount] + 1 [sys_umount] | 1106 | * (2) the usage count == 1 [parent vfsmount] + 1 [sys_umount] |
1276 | */ | 1107 | */ |
1277 | if (flags & MNT_EXPIRE) { | 1108 | if (flags & MNT_EXPIRE) { |
1278 | if (mnt == current->fs->root.mnt || | 1109 | if (&mnt->mnt == current->fs->root.mnt || |
1279 | flags & (MNT_FORCE | MNT_DETACH)) | 1110 | flags & (MNT_FORCE | MNT_DETACH)) |
1280 | return -EINVAL; | 1111 | return -EINVAL; |
1281 | 1112 | ||
@@ -1317,7 +1148,7 @@ static int do_umount(struct vfsmount *mnt, int flags) | |||
1317 | * /reboot - static binary that would close all descriptors and | 1148 | * /reboot - static binary that would close all descriptors and |
1318 | * call reboot(9). Then init(8) could umount root and exec /reboot. | 1149 | * call reboot(9). Then init(8) could umount root and exec /reboot. |
1319 | */ | 1150 | */ |
1320 | if (mnt == current->fs->root.mnt && !(flags & MNT_DETACH)) { | 1151 | if (&mnt->mnt == current->fs->root.mnt && !(flags & MNT_DETACH)) { |
1321 | /* | 1152 | /* |
1322 | * Special case for "unmounting" root ... | 1153 | * Special case for "unmounting" root ... |
1323 | * we just try to remount it readonly. | 1154 | * we just try to remount it readonly. |
@@ -1359,6 +1190,7 @@ static int do_umount(struct vfsmount *mnt, int flags) | |||
1359 | SYSCALL_DEFINE2(umount, char __user *, name, int, flags) | 1190 | SYSCALL_DEFINE2(umount, char __user *, name, int, flags) |
1360 | { | 1191 | { |
1361 | struct path path; | 1192 | struct path path; |
1193 | struct mount *mnt; | ||
1362 | int retval; | 1194 | int retval; |
1363 | int lookup_flags = 0; | 1195 | int lookup_flags = 0; |
1364 | 1196 | ||
@@ -1371,21 +1203,22 @@ SYSCALL_DEFINE2(umount, char __user *, name, int, flags) | |||
1371 | retval = user_path_at(AT_FDCWD, name, lookup_flags, &path); | 1203 | retval = user_path_at(AT_FDCWD, name, lookup_flags, &path); |
1372 | if (retval) | 1204 | if (retval) |
1373 | goto out; | 1205 | goto out; |
1206 | mnt = real_mount(path.mnt); | ||
1374 | retval = -EINVAL; | 1207 | retval = -EINVAL; |
1375 | if (path.dentry != path.mnt->mnt_root) | 1208 | if (path.dentry != path.mnt->mnt_root) |
1376 | goto dput_and_out; | 1209 | goto dput_and_out; |
1377 | if (!check_mnt(path.mnt)) | 1210 | if (!check_mnt(mnt)) |
1378 | goto dput_and_out; | 1211 | goto dput_and_out; |
1379 | 1212 | ||
1380 | retval = -EPERM; | 1213 | retval = -EPERM; |
1381 | if (!capable(CAP_SYS_ADMIN)) | 1214 | if (!capable(CAP_SYS_ADMIN)) |
1382 | goto dput_and_out; | 1215 | goto dput_and_out; |
1383 | 1216 | ||
1384 | retval = do_umount(path.mnt, flags); | 1217 | retval = do_umount(mnt, flags); |
1385 | dput_and_out: | 1218 | dput_and_out: |
1386 | /* we mustn't call path_put() as that would clear mnt_expiry_mark */ | 1219 | /* we mustn't call path_put() as that would clear mnt_expiry_mark */ |
1387 | dput(path.dentry); | 1220 | dput(path.dentry); |
1388 | mntput_no_expire(path.mnt); | 1221 | mntput_no_expire(mnt); |
1389 | out: | 1222 | out: |
1390 | return retval; | 1223 | return retval; |
1391 | } | 1224 | } |
@@ -1420,10 +1253,10 @@ static int mount_is_safe(struct path *path) | |||
1420 | #endif | 1253 | #endif |
1421 | } | 1254 | } |
1422 | 1255 | ||
1423 | struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry, | 1256 | struct mount *copy_tree(struct mount *mnt, struct dentry *dentry, |
1424 | int flag) | 1257 | int flag) |
1425 | { | 1258 | { |
1426 | struct vfsmount *res, *p, *q, *r, *s; | 1259 | struct mount *res, *p, *q, *r; |
1427 | struct path path; | 1260 | struct path path; |
1428 | 1261 | ||
1429 | if (!(flag & CL_COPY_ALL) && IS_MNT_UNBINDABLE(mnt)) | 1262 | if (!(flag & CL_COPY_ALL) && IS_MNT_UNBINDABLE(mnt)) |
@@ -1436,6 +1269,7 @@ struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry, | |||
1436 | 1269 | ||
1437 | p = mnt; | 1270 | p = mnt; |
1438 | list_for_each_entry(r, &mnt->mnt_mounts, mnt_child) { | 1271 | list_for_each_entry(r, &mnt->mnt_mounts, mnt_child) { |
1272 | struct mount *s; | ||
1439 | if (!is_subdir(r->mnt_mountpoint, dentry)) | 1273 | if (!is_subdir(r->mnt_mountpoint, dentry)) |
1440 | continue; | 1274 | continue; |
1441 | 1275 | ||
@@ -1449,9 +1283,9 @@ struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry, | |||
1449 | q = q->mnt_parent; | 1283 | q = q->mnt_parent; |
1450 | } | 1284 | } |
1451 | p = s; | 1285 | p = s; |
1452 | path.mnt = q; | 1286 | path.mnt = &q->mnt; |
1453 | path.dentry = p->mnt_mountpoint; | 1287 | path.dentry = p->mnt_mountpoint; |
1454 | q = clone_mnt(p, p->mnt_root, flag); | 1288 | q = clone_mnt(p, p->mnt.mnt_root, flag); |
1455 | if (!q) | 1289 | if (!q) |
1456 | goto Enomem; | 1290 | goto Enomem; |
1457 | br_write_lock(vfsmount_lock); | 1291 | br_write_lock(vfsmount_lock); |
@@ -1474,11 +1308,12 @@ Enomem: | |||
1474 | 1308 | ||
1475 | struct vfsmount *collect_mounts(struct path *path) | 1309 | struct vfsmount *collect_mounts(struct path *path) |
1476 | { | 1310 | { |
1477 | struct vfsmount *tree; | 1311 | struct mount *tree; |
1478 | down_write(&namespace_sem); | 1312 | down_write(&namespace_sem); |
1479 | tree = copy_tree(path->mnt, path->dentry, CL_COPY_ALL | CL_PRIVATE); | 1313 | tree = copy_tree(real_mount(path->mnt), path->dentry, |
1314 | CL_COPY_ALL | CL_PRIVATE); | ||
1480 | up_write(&namespace_sem); | 1315 | up_write(&namespace_sem); |
1481 | return tree; | 1316 | return tree ? &tree->mnt : NULL; |
1482 | } | 1317 | } |
1483 | 1318 | ||
1484 | void drop_collected_mounts(struct vfsmount *mnt) | 1319 | void drop_collected_mounts(struct vfsmount *mnt) |
@@ -1486,7 +1321,7 @@ void drop_collected_mounts(struct vfsmount *mnt) | |||
1486 | LIST_HEAD(umount_list); | 1321 | LIST_HEAD(umount_list); |
1487 | down_write(&namespace_sem); | 1322 | down_write(&namespace_sem); |
1488 | br_write_lock(vfsmount_lock); | 1323 | br_write_lock(vfsmount_lock); |
1489 | umount_tree(mnt, 0, &umount_list); | 1324 | umount_tree(real_mount(mnt), 0, &umount_list); |
1490 | br_write_unlock(vfsmount_lock); | 1325 | br_write_unlock(vfsmount_lock); |
1491 | up_write(&namespace_sem); | 1326 | up_write(&namespace_sem); |
1492 | release_mounts(&umount_list); | 1327 | release_mounts(&umount_list); |
@@ -1495,21 +1330,21 @@ void drop_collected_mounts(struct vfsmount *mnt) | |||
1495 | int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg, | 1330 | int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg, |
1496 | struct vfsmount *root) | 1331 | struct vfsmount *root) |
1497 | { | 1332 | { |
1498 | struct vfsmount *mnt; | 1333 | struct mount *mnt; |
1499 | int res = f(root, arg); | 1334 | int res = f(root, arg); |
1500 | if (res) | 1335 | if (res) |
1501 | return res; | 1336 | return res; |
1502 | list_for_each_entry(mnt, &root->mnt_list, mnt_list) { | 1337 | list_for_each_entry(mnt, &real_mount(root)->mnt_list, mnt_list) { |
1503 | res = f(mnt, arg); | 1338 | res = f(&mnt->mnt, arg); |
1504 | if (res) | 1339 | if (res) |
1505 | return res; | 1340 | return res; |
1506 | } | 1341 | } |
1507 | return 0; | 1342 | return 0; |
1508 | } | 1343 | } |
1509 | 1344 | ||
1510 | static void cleanup_group_ids(struct vfsmount *mnt, struct vfsmount *end) | 1345 | static void cleanup_group_ids(struct mount *mnt, struct mount *end) |
1511 | { | 1346 | { |
1512 | struct vfsmount *p; | 1347 | struct mount *p; |
1513 | 1348 | ||
1514 | for (p = mnt; p != end; p = next_mnt(p, mnt)) { | 1349 | for (p = mnt; p != end; p = next_mnt(p, mnt)) { |
1515 | if (p->mnt_group_id && !IS_MNT_SHARED(p)) | 1350 | if (p->mnt_group_id && !IS_MNT_SHARED(p)) |
@@ -1517,9 +1352,9 @@ static void cleanup_group_ids(struct vfsmount *mnt, struct vfsmount *end) | |||
1517 | } | 1352 | } |
1518 | } | 1353 | } |
1519 | 1354 | ||
1520 | static int invent_group_ids(struct vfsmount *mnt, bool recurse) | 1355 | static int invent_group_ids(struct mount *mnt, bool recurse) |
1521 | { | 1356 | { |
1522 | struct vfsmount *p; | 1357 | struct mount *p; |
1523 | 1358 | ||
1524 | for (p = mnt; p; p = recurse ? next_mnt(p, mnt) : NULL) { | 1359 | for (p = mnt; p; p = recurse ? next_mnt(p, mnt) : NULL) { |
1525 | if (!p->mnt_group_id && !IS_MNT_SHARED(p)) { | 1360 | if (!p->mnt_group_id && !IS_MNT_SHARED(p)) { |
@@ -1597,13 +1432,13 @@ static int invent_group_ids(struct vfsmount *mnt, bool recurse) | |||
1597 | * Must be called without spinlocks held, since this function can sleep | 1432 | * Must be called without spinlocks held, since this function can sleep |
1598 | * in allocations. | 1433 | * in allocations. |
1599 | */ | 1434 | */ |
1600 | static int attach_recursive_mnt(struct vfsmount *source_mnt, | 1435 | static int attach_recursive_mnt(struct mount *source_mnt, |
1601 | struct path *path, struct path *parent_path) | 1436 | struct path *path, struct path *parent_path) |
1602 | { | 1437 | { |
1603 | LIST_HEAD(tree_list); | 1438 | LIST_HEAD(tree_list); |
1604 | struct vfsmount *dest_mnt = path->mnt; | 1439 | struct mount *dest_mnt = real_mount(path->mnt); |
1605 | struct dentry *dest_dentry = path->dentry; | 1440 | struct dentry *dest_dentry = path->dentry; |
1606 | struct vfsmount *child, *p; | 1441 | struct mount *child, *p; |
1607 | int err; | 1442 | int err; |
1608 | 1443 | ||
1609 | if (IS_MNT_SHARED(dest_mnt)) { | 1444 | if (IS_MNT_SHARED(dest_mnt)) { |
@@ -1624,7 +1459,7 @@ static int attach_recursive_mnt(struct vfsmount *source_mnt, | |||
1624 | if (parent_path) { | 1459 | if (parent_path) { |
1625 | detach_mnt(source_mnt, parent_path); | 1460 | detach_mnt(source_mnt, parent_path); |
1626 | attach_mnt(source_mnt, path); | 1461 | attach_mnt(source_mnt, path); |
1627 | touch_mnt_namespace(parent_path->mnt->mnt_ns); | 1462 | touch_mnt_namespace(source_mnt->mnt_ns); |
1628 | } else { | 1463 | } else { |
1629 | mnt_set_mountpoint(dest_mnt, dest_dentry, source_mnt); | 1464 | mnt_set_mountpoint(dest_mnt, dest_dentry, source_mnt); |
1630 | commit_tree(source_mnt); | 1465 | commit_tree(source_mnt); |
@@ -1672,13 +1507,13 @@ static void unlock_mount(struct path *path) | |||
1672 | mutex_unlock(&path->dentry->d_inode->i_mutex); | 1507 | mutex_unlock(&path->dentry->d_inode->i_mutex); |
1673 | } | 1508 | } |
1674 | 1509 | ||
1675 | static int graft_tree(struct vfsmount *mnt, struct path *path) | 1510 | static int graft_tree(struct mount *mnt, struct path *path) |
1676 | { | 1511 | { |
1677 | if (mnt->mnt_sb->s_flags & MS_NOUSER) | 1512 | if (mnt->mnt.mnt_sb->s_flags & MS_NOUSER) |
1678 | return -EINVAL; | 1513 | return -EINVAL; |
1679 | 1514 | ||
1680 | if (S_ISDIR(path->dentry->d_inode->i_mode) != | 1515 | if (S_ISDIR(path->dentry->d_inode->i_mode) != |
1681 | S_ISDIR(mnt->mnt_root->d_inode->i_mode)) | 1516 | S_ISDIR(mnt->mnt.mnt_root->d_inode->i_mode)) |
1682 | return -ENOTDIR; | 1517 | return -ENOTDIR; |
1683 | 1518 | ||
1684 | if (d_unlinked(path->dentry)) | 1519 | if (d_unlinked(path->dentry)) |
@@ -1709,7 +1544,8 @@ static int flags_to_propagation_type(int flags) | |||
1709 | */ | 1544 | */ |
1710 | static int do_change_type(struct path *path, int flag) | 1545 | static int do_change_type(struct path *path, int flag) |
1711 | { | 1546 | { |
1712 | struct vfsmount *m, *mnt = path->mnt; | 1547 | struct mount *m; |
1548 | struct mount *mnt = real_mount(path->mnt); | ||
1713 | int recurse = flag & MS_REC; | 1549 | int recurse = flag & MS_REC; |
1714 | int type; | 1550 | int type; |
1715 | int err = 0; | 1551 | int err = 0; |
@@ -1749,7 +1585,7 @@ static int do_loopback(struct path *path, char *old_name, | |||
1749 | { | 1585 | { |
1750 | LIST_HEAD(umount_list); | 1586 | LIST_HEAD(umount_list); |
1751 | struct path old_path; | 1587 | struct path old_path; |
1752 | struct vfsmount *mnt = NULL; | 1588 | struct mount *mnt = NULL, *old; |
1753 | int err = mount_is_safe(path); | 1589 | int err = mount_is_safe(path); |
1754 | if (err) | 1590 | if (err) |
1755 | return err; | 1591 | return err; |
@@ -1763,18 +1599,20 @@ static int do_loopback(struct path *path, char *old_name, | |||
1763 | if (err) | 1599 | if (err) |
1764 | goto out; | 1600 | goto out; |
1765 | 1601 | ||
1602 | old = real_mount(old_path.mnt); | ||
1603 | |||
1766 | err = -EINVAL; | 1604 | err = -EINVAL; |
1767 | if (IS_MNT_UNBINDABLE(old_path.mnt)) | 1605 | if (IS_MNT_UNBINDABLE(old)) |
1768 | goto out2; | 1606 | goto out2; |
1769 | 1607 | ||
1770 | if (!check_mnt(path->mnt) || !check_mnt(old_path.mnt)) | 1608 | if (!check_mnt(real_mount(path->mnt)) || !check_mnt(old)) |
1771 | goto out2; | 1609 | goto out2; |
1772 | 1610 | ||
1773 | err = -ENOMEM; | 1611 | err = -ENOMEM; |
1774 | if (recurse) | 1612 | if (recurse) |
1775 | mnt = copy_tree(old_path.mnt, old_path.dentry, 0); | 1613 | mnt = copy_tree(old, old_path.dentry, 0); |
1776 | else | 1614 | else |
1777 | mnt = clone_mnt(old_path.mnt, old_path.dentry, 0); | 1615 | mnt = clone_mnt(old, old_path.dentry, 0); |
1778 | 1616 | ||
1779 | if (!mnt) | 1617 | if (!mnt) |
1780 | goto out2; | 1618 | goto out2; |
@@ -1804,9 +1642,9 @@ static int change_mount_flags(struct vfsmount *mnt, int ms_flags) | |||
1804 | return 0; | 1642 | return 0; |
1805 | 1643 | ||
1806 | if (readonly_request) | 1644 | if (readonly_request) |
1807 | error = mnt_make_readonly(mnt); | 1645 | error = mnt_make_readonly(real_mount(mnt)); |
1808 | else | 1646 | else |
1809 | __mnt_unmake_readonly(mnt); | 1647 | __mnt_unmake_readonly(real_mount(mnt)); |
1810 | return error; | 1648 | return error; |
1811 | } | 1649 | } |
1812 | 1650 | ||
@@ -1820,11 +1658,12 @@ static int do_remount(struct path *path, int flags, int mnt_flags, | |||
1820 | { | 1658 | { |
1821 | int err; | 1659 | int err; |
1822 | struct super_block *sb = path->mnt->mnt_sb; | 1660 | struct super_block *sb = path->mnt->mnt_sb; |
1661 | struct mount *mnt = real_mount(path->mnt); | ||
1823 | 1662 | ||
1824 | if (!capable(CAP_SYS_ADMIN)) | 1663 | if (!capable(CAP_SYS_ADMIN)) |
1825 | return -EPERM; | 1664 | return -EPERM; |
1826 | 1665 | ||
1827 | if (!check_mnt(path->mnt)) | 1666 | if (!check_mnt(mnt)) |
1828 | return -EINVAL; | 1667 | return -EINVAL; |
1829 | 1668 | ||
1830 | if (path->dentry != path->mnt->mnt_root) | 1669 | if (path->dentry != path->mnt->mnt_root) |
@@ -1841,22 +1680,22 @@ static int do_remount(struct path *path, int flags, int mnt_flags, | |||
1841 | err = do_remount_sb(sb, flags, data, 0); | 1680 | err = do_remount_sb(sb, flags, data, 0); |
1842 | if (!err) { | 1681 | if (!err) { |
1843 | br_write_lock(vfsmount_lock); | 1682 | br_write_lock(vfsmount_lock); |
1844 | mnt_flags |= path->mnt->mnt_flags & MNT_PROPAGATION_MASK; | 1683 | mnt_flags |= mnt->mnt.mnt_flags & MNT_PROPAGATION_MASK; |
1845 | path->mnt->mnt_flags = mnt_flags; | 1684 | mnt->mnt.mnt_flags = mnt_flags; |
1846 | br_write_unlock(vfsmount_lock); | 1685 | br_write_unlock(vfsmount_lock); |
1847 | } | 1686 | } |
1848 | up_write(&sb->s_umount); | 1687 | up_write(&sb->s_umount); |
1849 | if (!err) { | 1688 | if (!err) { |
1850 | br_write_lock(vfsmount_lock); | 1689 | br_write_lock(vfsmount_lock); |
1851 | touch_mnt_namespace(path->mnt->mnt_ns); | 1690 | touch_mnt_namespace(mnt->mnt_ns); |
1852 | br_write_unlock(vfsmount_lock); | 1691 | br_write_unlock(vfsmount_lock); |
1853 | } | 1692 | } |
1854 | return err; | 1693 | return err; |
1855 | } | 1694 | } |
1856 | 1695 | ||
1857 | static inline int tree_contains_unbindable(struct vfsmount *mnt) | 1696 | static inline int tree_contains_unbindable(struct mount *mnt) |
1858 | { | 1697 | { |
1859 | struct vfsmount *p; | 1698 | struct mount *p; |
1860 | for (p = mnt; p; p = next_mnt(p, mnt)) { | 1699 | for (p = mnt; p; p = next_mnt(p, mnt)) { |
1861 | if (IS_MNT_UNBINDABLE(p)) | 1700 | if (IS_MNT_UNBINDABLE(p)) |
1862 | return 1; | 1701 | return 1; |
@@ -1867,7 +1706,8 @@ static inline int tree_contains_unbindable(struct vfsmount *mnt) | |||
1867 | static int do_move_mount(struct path *path, char *old_name) | 1706 | static int do_move_mount(struct path *path, char *old_name) |
1868 | { | 1707 | { |
1869 | struct path old_path, parent_path; | 1708 | struct path old_path, parent_path; |
1870 | struct vfsmount *p; | 1709 | struct mount *p; |
1710 | struct mount *old; | ||
1871 | int err = 0; | 1711 | int err = 0; |
1872 | if (!capable(CAP_SYS_ADMIN)) | 1712 | if (!capable(CAP_SYS_ADMIN)) |
1873 | return -EPERM; | 1713 | return -EPERM; |
@@ -1881,8 +1721,11 @@ static int do_move_mount(struct path *path, char *old_name) | |||
1881 | if (err < 0) | 1721 | if (err < 0) |
1882 | goto out; | 1722 | goto out; |
1883 | 1723 | ||
1724 | old = real_mount(old_path.mnt); | ||
1725 | p = real_mount(path->mnt); | ||
1726 | |||
1884 | err = -EINVAL; | 1727 | err = -EINVAL; |
1885 | if (!check_mnt(path->mnt) || !check_mnt(old_path.mnt)) | 1728 | if (!check_mnt(p) || !check_mnt(old)) |
1886 | goto out1; | 1729 | goto out1; |
1887 | 1730 | ||
1888 | if (d_unlinked(path->dentry)) | 1731 | if (d_unlinked(path->dentry)) |
@@ -1892,7 +1735,7 @@ static int do_move_mount(struct path *path, char *old_name) | |||
1892 | if (old_path.dentry != old_path.mnt->mnt_root) | 1735 | if (old_path.dentry != old_path.mnt->mnt_root) |
1893 | goto out1; | 1736 | goto out1; |
1894 | 1737 | ||
1895 | if (old_path.mnt == old_path.mnt->mnt_parent) | 1738 | if (!mnt_has_parent(old)) |
1896 | goto out1; | 1739 | goto out1; |
1897 | 1740 | ||
1898 | if (S_ISDIR(path->dentry->d_inode->i_mode) != | 1741 | if (S_ISDIR(path->dentry->d_inode->i_mode) != |
@@ -1901,28 +1744,26 @@ static int do_move_mount(struct path *path, char *old_name) | |||
1901 | /* | 1744 | /* |
1902 | * Don't move a mount residing in a shared parent. | 1745 | * Don't move a mount residing in a shared parent. |
1903 | */ | 1746 | */ |
1904 | if (old_path.mnt->mnt_parent && | 1747 | if (IS_MNT_SHARED(old->mnt_parent)) |
1905 | IS_MNT_SHARED(old_path.mnt->mnt_parent)) | ||
1906 | goto out1; | 1748 | goto out1; |
1907 | /* | 1749 | /* |
1908 | * Don't move a mount tree containing unbindable mounts to a destination | 1750 | * Don't move a mount tree containing unbindable mounts to a destination |
1909 | * mount which is shared. | 1751 | * mount which is shared. |
1910 | */ | 1752 | */ |
1911 | if (IS_MNT_SHARED(path->mnt) && | 1753 | if (IS_MNT_SHARED(p) && tree_contains_unbindable(old)) |
1912 | tree_contains_unbindable(old_path.mnt)) | ||
1913 | goto out1; | 1754 | goto out1; |
1914 | err = -ELOOP; | 1755 | err = -ELOOP; |
1915 | for (p = path->mnt; p->mnt_parent != p; p = p->mnt_parent) | 1756 | for (; mnt_has_parent(p); p = p->mnt_parent) |
1916 | if (p == old_path.mnt) | 1757 | if (p == old) |
1917 | goto out1; | 1758 | goto out1; |
1918 | 1759 | ||
1919 | err = attach_recursive_mnt(old_path.mnt, path, &parent_path); | 1760 | err = attach_recursive_mnt(old, path, &parent_path); |
1920 | if (err) | 1761 | if (err) |
1921 | goto out1; | 1762 | goto out1; |
1922 | 1763 | ||
1923 | /* if the mount is moved, it should no longer be expire | 1764 | /* if the mount is moved, it should no longer be expire |
1924 | * automatically */ | 1765 | * automatically */ |
1925 | list_del_init(&old_path.mnt->mnt_expire); | 1766 | list_del_init(&old->mnt_expire); |
1926 | out1: | 1767 | out1: |
1927 | unlock_mount(path); | 1768 | unlock_mount(path); |
1928 | out: | 1769 | out: |
@@ -1955,7 +1796,7 @@ static struct vfsmount *fs_set_subtype(struct vfsmount *mnt, const char *fstype) | |||
1955 | return ERR_PTR(err); | 1796 | return ERR_PTR(err); |
1956 | } | 1797 | } |
1957 | 1798 | ||
1958 | struct vfsmount * | 1799 | static struct vfsmount * |
1959 | do_kern_mount(const char *fstype, int flags, const char *name, void *data) | 1800 | do_kern_mount(const char *fstype, int flags, const char *name, void *data) |
1960 | { | 1801 | { |
1961 | struct file_system_type *type = get_fs_type(fstype); | 1802 | struct file_system_type *type = get_fs_type(fstype); |
@@ -1969,12 +1810,11 @@ do_kern_mount(const char *fstype, int flags, const char *name, void *data) | |||
1969 | put_filesystem(type); | 1810 | put_filesystem(type); |
1970 | return mnt; | 1811 | return mnt; |
1971 | } | 1812 | } |
1972 | EXPORT_SYMBOL_GPL(do_kern_mount); | ||
1973 | 1813 | ||
1974 | /* | 1814 | /* |
1975 | * add a mount into a namespace's mount tree | 1815 | * add a mount into a namespace's mount tree |
1976 | */ | 1816 | */ |
1977 | static int do_add_mount(struct vfsmount *newmnt, struct path *path, int mnt_flags) | 1817 | static int do_add_mount(struct mount *newmnt, struct path *path, int mnt_flags) |
1978 | { | 1818 | { |
1979 | int err; | 1819 | int err; |
1980 | 1820 | ||
@@ -1985,20 +1825,20 @@ static int do_add_mount(struct vfsmount *newmnt, struct path *path, int mnt_flag | |||
1985 | return err; | 1825 | return err; |
1986 | 1826 | ||
1987 | err = -EINVAL; | 1827 | err = -EINVAL; |
1988 | if (!(mnt_flags & MNT_SHRINKABLE) && !check_mnt(path->mnt)) | 1828 | if (!(mnt_flags & MNT_SHRINKABLE) && !check_mnt(real_mount(path->mnt))) |
1989 | goto unlock; | 1829 | goto unlock; |
1990 | 1830 | ||
1991 | /* Refuse the same filesystem on the same mount point */ | 1831 | /* Refuse the same filesystem on the same mount point */ |
1992 | err = -EBUSY; | 1832 | err = -EBUSY; |
1993 | if (path->mnt->mnt_sb == newmnt->mnt_sb && | 1833 | if (path->mnt->mnt_sb == newmnt->mnt.mnt_sb && |
1994 | path->mnt->mnt_root == path->dentry) | 1834 | path->mnt->mnt_root == path->dentry) |
1995 | goto unlock; | 1835 | goto unlock; |
1996 | 1836 | ||
1997 | err = -EINVAL; | 1837 | err = -EINVAL; |
1998 | if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode)) | 1838 | if (S_ISLNK(newmnt->mnt.mnt_root->d_inode->i_mode)) |
1999 | goto unlock; | 1839 | goto unlock; |
2000 | 1840 | ||
2001 | newmnt->mnt_flags = mnt_flags; | 1841 | newmnt->mnt.mnt_flags = mnt_flags; |
2002 | err = graft_tree(newmnt, path); | 1842 | err = graft_tree(newmnt, path); |
2003 | 1843 | ||
2004 | unlock: | 1844 | unlock: |
@@ -2027,7 +1867,7 @@ static int do_new_mount(struct path *path, char *type, int flags, | |||
2027 | if (IS_ERR(mnt)) | 1867 | if (IS_ERR(mnt)) |
2028 | return PTR_ERR(mnt); | 1868 | return PTR_ERR(mnt); |
2029 | 1869 | ||
2030 | err = do_add_mount(mnt, path, mnt_flags); | 1870 | err = do_add_mount(real_mount(mnt), path, mnt_flags); |
2031 | if (err) | 1871 | if (err) |
2032 | mntput(mnt); | 1872 | mntput(mnt); |
2033 | return err; | 1873 | return err; |
@@ -2035,11 +1875,12 @@ static int do_new_mount(struct path *path, char *type, int flags, | |||
2035 | 1875 | ||
2036 | int finish_automount(struct vfsmount *m, struct path *path) | 1876 | int finish_automount(struct vfsmount *m, struct path *path) |
2037 | { | 1877 | { |
1878 | struct mount *mnt = real_mount(m); | ||
2038 | int err; | 1879 | int err; |
2039 | /* The new mount record should have at least 2 refs to prevent it being | 1880 | /* The new mount record should have at least 2 refs to prevent it being |
2040 | * expired before we get a chance to add it | 1881 | * expired before we get a chance to add it |
2041 | */ | 1882 | */ |
2042 | BUG_ON(mnt_get_count(m) < 2); | 1883 | BUG_ON(mnt_get_count(mnt) < 2); |
2043 | 1884 | ||
2044 | if (m->mnt_sb == path->mnt->mnt_sb && | 1885 | if (m->mnt_sb == path->mnt->mnt_sb && |
2045 | m->mnt_root == path->dentry) { | 1886 | m->mnt_root == path->dentry) { |
@@ -2047,15 +1888,15 @@ int finish_automount(struct vfsmount *m, struct path *path) | |||
2047 | goto fail; | 1888 | goto fail; |
2048 | } | 1889 | } |
2049 | 1890 | ||
2050 | err = do_add_mount(m, path, path->mnt->mnt_flags | MNT_SHRINKABLE); | 1891 | err = do_add_mount(mnt, path, path->mnt->mnt_flags | MNT_SHRINKABLE); |
2051 | if (!err) | 1892 | if (!err) |
2052 | return 0; | 1893 | return 0; |
2053 | fail: | 1894 | fail: |
2054 | /* remove m from any expiration list it may be on */ | 1895 | /* remove m from any expiration list it may be on */ |
2055 | if (!list_empty(&m->mnt_expire)) { | 1896 | if (!list_empty(&mnt->mnt_expire)) { |
2056 | down_write(&namespace_sem); | 1897 | down_write(&namespace_sem); |
2057 | br_write_lock(vfsmount_lock); | 1898 | br_write_lock(vfsmount_lock); |
2058 | list_del_init(&m->mnt_expire); | 1899 | list_del_init(&mnt->mnt_expire); |
2059 | br_write_unlock(vfsmount_lock); | 1900 | br_write_unlock(vfsmount_lock); |
2060 | up_write(&namespace_sem); | 1901 | up_write(&namespace_sem); |
2061 | } | 1902 | } |
@@ -2074,7 +1915,7 @@ void mnt_set_expiry(struct vfsmount *mnt, struct list_head *expiry_list) | |||
2074 | down_write(&namespace_sem); | 1915 | down_write(&namespace_sem); |
2075 | br_write_lock(vfsmount_lock); | 1916 | br_write_lock(vfsmount_lock); |
2076 | 1917 | ||
2077 | list_add_tail(&mnt->mnt_expire, expiry_list); | 1918 | list_add_tail(&real_mount(mnt)->mnt_expire, expiry_list); |
2078 | 1919 | ||
2079 | br_write_unlock(vfsmount_lock); | 1920 | br_write_unlock(vfsmount_lock); |
2080 | up_write(&namespace_sem); | 1921 | up_write(&namespace_sem); |
@@ -2088,7 +1929,7 @@ EXPORT_SYMBOL(mnt_set_expiry); | |||
2088 | */ | 1929 | */ |
2089 | void mark_mounts_for_expiry(struct list_head *mounts) | 1930 | void mark_mounts_for_expiry(struct list_head *mounts) |
2090 | { | 1931 | { |
2091 | struct vfsmount *mnt, *next; | 1932 | struct mount *mnt, *next; |
2092 | LIST_HEAD(graveyard); | 1933 | LIST_HEAD(graveyard); |
2093 | LIST_HEAD(umounts); | 1934 | LIST_HEAD(umounts); |
2094 | 1935 | ||
@@ -2111,7 +1952,7 @@ void mark_mounts_for_expiry(struct list_head *mounts) | |||
2111 | list_move(&mnt->mnt_expire, &graveyard); | 1952 | list_move(&mnt->mnt_expire, &graveyard); |
2112 | } | 1953 | } |
2113 | while (!list_empty(&graveyard)) { | 1954 | while (!list_empty(&graveyard)) { |
2114 | mnt = list_first_entry(&graveyard, struct vfsmount, mnt_expire); | 1955 | mnt = list_first_entry(&graveyard, struct mount, mnt_expire); |
2115 | touch_mnt_namespace(mnt->mnt_ns); | 1956 | touch_mnt_namespace(mnt->mnt_ns); |
2116 | umount_tree(mnt, 1, &umounts); | 1957 | umount_tree(mnt, 1, &umounts); |
2117 | } | 1958 | } |
@@ -2129,9 +1970,9 @@ EXPORT_SYMBOL_GPL(mark_mounts_for_expiry); | |||
2129 | * search the list of submounts for a given mountpoint, and move any | 1970 | * search the list of submounts for a given mountpoint, and move any |
2130 | * shrinkable submounts to the 'graveyard' list. | 1971 | * shrinkable submounts to the 'graveyard' list. |
2131 | */ | 1972 | */ |
2132 | static int select_submounts(struct vfsmount *parent, struct list_head *graveyard) | 1973 | static int select_submounts(struct mount *parent, struct list_head *graveyard) |
2133 | { | 1974 | { |
2134 | struct vfsmount *this_parent = parent; | 1975 | struct mount *this_parent = parent; |
2135 | struct list_head *next; | 1976 | struct list_head *next; |
2136 | int found = 0; | 1977 | int found = 0; |
2137 | 1978 | ||
@@ -2140,10 +1981,10 @@ repeat: | |||
2140 | resume: | 1981 | resume: |
2141 | while (next != &this_parent->mnt_mounts) { | 1982 | while (next != &this_parent->mnt_mounts) { |
2142 | struct list_head *tmp = next; | 1983 | struct list_head *tmp = next; |
2143 | struct vfsmount *mnt = list_entry(tmp, struct vfsmount, mnt_child); | 1984 | struct mount *mnt = list_entry(tmp, struct mount, mnt_child); |
2144 | 1985 | ||
2145 | next = tmp->next; | 1986 | next = tmp->next; |
2146 | if (!(mnt->mnt_flags & MNT_SHRINKABLE)) | 1987 | if (!(mnt->mnt.mnt_flags & MNT_SHRINKABLE)) |
2147 | continue; | 1988 | continue; |
2148 | /* | 1989 | /* |
2149 | * Descend a level if the d_mounts list is non-empty. | 1990 | * Descend a level if the d_mounts list is non-empty. |
@@ -2175,15 +2016,15 @@ resume: | |||
2175 | * | 2016 | * |
2176 | * vfsmount_lock must be held for write | 2017 | * vfsmount_lock must be held for write |
2177 | */ | 2018 | */ |
2178 | static void shrink_submounts(struct vfsmount *mnt, struct list_head *umounts) | 2019 | static void shrink_submounts(struct mount *mnt, struct list_head *umounts) |
2179 | { | 2020 | { |
2180 | LIST_HEAD(graveyard); | 2021 | LIST_HEAD(graveyard); |
2181 | struct vfsmount *m; | 2022 | struct mount *m; |
2182 | 2023 | ||
2183 | /* extract submounts of 'mountpoint' from the expiration list */ | 2024 | /* extract submounts of 'mountpoint' from the expiration list */ |
2184 | while (select_submounts(mnt, &graveyard)) { | 2025 | while (select_submounts(mnt, &graveyard)) { |
2185 | while (!list_empty(&graveyard)) { | 2026 | while (!list_empty(&graveyard)) { |
2186 | m = list_first_entry(&graveyard, struct vfsmount, | 2027 | m = list_first_entry(&graveyard, struct mount, |
2187 | mnt_expire); | 2028 | mnt_expire); |
2188 | touch_mnt_namespace(m->mnt_ns); | 2029 | touch_mnt_namespace(m->mnt_ns); |
2189 | umount_tree(m, 1, umounts); | 2030 | umount_tree(m, 1, umounts); |
@@ -2370,12 +2211,13 @@ static struct mnt_namespace *alloc_mnt_ns(void) | |||
2370 | 2211 | ||
2371 | void mnt_make_longterm(struct vfsmount *mnt) | 2212 | void mnt_make_longterm(struct vfsmount *mnt) |
2372 | { | 2213 | { |
2373 | __mnt_make_longterm(mnt); | 2214 | __mnt_make_longterm(real_mount(mnt)); |
2374 | } | 2215 | } |
2375 | 2216 | ||
2376 | void mnt_make_shortterm(struct vfsmount *mnt) | 2217 | void mnt_make_shortterm(struct vfsmount *m) |
2377 | { | 2218 | { |
2378 | #ifdef CONFIG_SMP | 2219 | #ifdef CONFIG_SMP |
2220 | struct mount *mnt = real_mount(m); | ||
2379 | if (atomic_add_unless(&mnt->mnt_longterm, -1, 1)) | 2221 | if (atomic_add_unless(&mnt->mnt_longterm, -1, 1)) |
2380 | return; | 2222 | return; |
2381 | br_write_lock(vfsmount_lock); | 2223 | br_write_lock(vfsmount_lock); |
@@ -2393,7 +2235,9 @@ static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns, | |||
2393 | { | 2235 | { |
2394 | struct mnt_namespace *new_ns; | 2236 | struct mnt_namespace *new_ns; |
2395 | struct vfsmount *rootmnt = NULL, *pwdmnt = NULL; | 2237 | struct vfsmount *rootmnt = NULL, *pwdmnt = NULL; |
2396 | struct vfsmount *p, *q; | 2238 | struct mount *p, *q; |
2239 | struct mount *old = mnt_ns->root; | ||
2240 | struct mount *new; | ||
2397 | 2241 | ||
2398 | new_ns = alloc_mnt_ns(); | 2242 | new_ns = alloc_mnt_ns(); |
2399 | if (IS_ERR(new_ns)) | 2243 | if (IS_ERR(new_ns)) |
@@ -2401,15 +2245,15 @@ static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns, | |||
2401 | 2245 | ||
2402 | down_write(&namespace_sem); | 2246 | down_write(&namespace_sem); |
2403 | /* First pass: copy the tree topology */ | 2247 | /* First pass: copy the tree topology */ |
2404 | new_ns->root = copy_tree(mnt_ns->root, mnt_ns->root->mnt_root, | 2248 | new = copy_tree(old, old->mnt.mnt_root, CL_COPY_ALL | CL_EXPIRE); |
2405 | CL_COPY_ALL | CL_EXPIRE); | 2249 | if (!new) { |
2406 | if (!new_ns->root) { | ||
2407 | up_write(&namespace_sem); | 2250 | up_write(&namespace_sem); |
2408 | kfree(new_ns); | 2251 | kfree(new_ns); |
2409 | return ERR_PTR(-ENOMEM); | 2252 | return ERR_PTR(-ENOMEM); |
2410 | } | 2253 | } |
2254 | new_ns->root = new; | ||
2411 | br_write_lock(vfsmount_lock); | 2255 | br_write_lock(vfsmount_lock); |
2412 | list_add_tail(&new_ns->list, &new_ns->root->mnt_list); | 2256 | list_add_tail(&new_ns->list, &new->mnt_list); |
2413 | br_write_unlock(vfsmount_lock); | 2257 | br_write_unlock(vfsmount_lock); |
2414 | 2258 | ||
2415 | /* | 2259 | /* |
@@ -2417,27 +2261,27 @@ static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns, | |||
2417 | * as belonging to new namespace. We have already acquired a private | 2261 | * as belonging to new namespace. We have already acquired a private |
2418 | * fs_struct, so tsk->fs->lock is not needed. | 2262 | * fs_struct, so tsk->fs->lock is not needed. |
2419 | */ | 2263 | */ |
2420 | p = mnt_ns->root; | 2264 | p = old; |
2421 | q = new_ns->root; | 2265 | q = new; |
2422 | while (p) { | 2266 | while (p) { |
2423 | q->mnt_ns = new_ns; | 2267 | q->mnt_ns = new_ns; |
2424 | __mnt_make_longterm(q); | 2268 | __mnt_make_longterm(q); |
2425 | if (fs) { | 2269 | if (fs) { |
2426 | if (p == fs->root.mnt) { | 2270 | if (&p->mnt == fs->root.mnt) { |
2427 | fs->root.mnt = mntget(q); | 2271 | fs->root.mnt = mntget(&q->mnt); |
2428 | __mnt_make_longterm(q); | 2272 | __mnt_make_longterm(q); |
2429 | mnt_make_shortterm(p); | 2273 | mnt_make_shortterm(&p->mnt); |
2430 | rootmnt = p; | 2274 | rootmnt = &p->mnt; |
2431 | } | 2275 | } |
2432 | if (p == fs->pwd.mnt) { | 2276 | if (&p->mnt == fs->pwd.mnt) { |
2433 | fs->pwd.mnt = mntget(q); | 2277 | fs->pwd.mnt = mntget(&q->mnt); |
2434 | __mnt_make_longterm(q); | 2278 | __mnt_make_longterm(q); |
2435 | mnt_make_shortterm(p); | 2279 | mnt_make_shortterm(&p->mnt); |
2436 | pwdmnt = p; | 2280 | pwdmnt = &p->mnt; |
2437 | } | 2281 | } |
2438 | } | 2282 | } |
2439 | p = next_mnt(p, mnt_ns->root); | 2283 | p = next_mnt(p, old); |
2440 | q = next_mnt(q, new_ns->root); | 2284 | q = next_mnt(q, new); |
2441 | } | 2285 | } |
2442 | up_write(&namespace_sem); | 2286 | up_write(&namespace_sem); |
2443 | 2287 | ||
@@ -2470,22 +2314,20 @@ struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns, | |||
2470 | * create_mnt_ns - creates a private namespace and adds a root filesystem | 2314 | * create_mnt_ns - creates a private namespace and adds a root filesystem |
2471 | * @mnt: pointer to the new root filesystem mountpoint | 2315 | * @mnt: pointer to the new root filesystem mountpoint |
2472 | */ | 2316 | */ |
2473 | struct mnt_namespace *create_mnt_ns(struct vfsmount *mnt) | 2317 | static struct mnt_namespace *create_mnt_ns(struct vfsmount *m) |
2474 | { | 2318 | { |
2475 | struct mnt_namespace *new_ns; | 2319 | struct mnt_namespace *new_ns = alloc_mnt_ns(); |
2476 | |||
2477 | new_ns = alloc_mnt_ns(); | ||
2478 | if (!IS_ERR(new_ns)) { | 2320 | if (!IS_ERR(new_ns)) { |
2321 | struct mount *mnt = real_mount(m); | ||
2479 | mnt->mnt_ns = new_ns; | 2322 | mnt->mnt_ns = new_ns; |
2480 | __mnt_make_longterm(mnt); | 2323 | __mnt_make_longterm(mnt); |
2481 | new_ns->root = mnt; | 2324 | new_ns->root = mnt; |
2482 | list_add(&new_ns->list, &new_ns->root->mnt_list); | 2325 | list_add(&new_ns->list, &mnt->mnt_list); |
2483 | } else { | 2326 | } else { |
2484 | mntput(mnt); | 2327 | mntput(m); |
2485 | } | 2328 | } |
2486 | return new_ns; | 2329 | return new_ns; |
2487 | } | 2330 | } |
2488 | EXPORT_SYMBOL(create_mnt_ns); | ||
2489 | 2331 | ||
2490 | struct dentry *mount_subtree(struct vfsmount *mnt, const char *name) | 2332 | struct dentry *mount_subtree(struct vfsmount *mnt, const char *name) |
2491 | { | 2333 | { |
@@ -2559,6 +2401,31 @@ out_type: | |||
2559 | } | 2401 | } |
2560 | 2402 | ||
2561 | /* | 2403 | /* |
2404 | * Return true if path is reachable from root | ||
2405 | * | ||
2406 | * namespace_sem or vfsmount_lock is held | ||
2407 | */ | ||
2408 | bool is_path_reachable(struct mount *mnt, struct dentry *dentry, | ||
2409 | const struct path *root) | ||
2410 | { | ||
2411 | while (&mnt->mnt != root->mnt && mnt_has_parent(mnt)) { | ||
2412 | dentry = mnt->mnt_mountpoint; | ||
2413 | mnt = mnt->mnt_parent; | ||
2414 | } | ||
2415 | return &mnt->mnt == root->mnt && is_subdir(dentry, root->dentry); | ||
2416 | } | ||
2417 | |||
2418 | int path_is_under(struct path *path1, struct path *path2) | ||
2419 | { | ||
2420 | int res; | ||
2421 | br_read_lock(vfsmount_lock); | ||
2422 | res = is_path_reachable(real_mount(path1->mnt), path1->dentry, path2); | ||
2423 | br_read_unlock(vfsmount_lock); | ||
2424 | return res; | ||
2425 | } | ||
2426 | EXPORT_SYMBOL(path_is_under); | ||
2427 | |||
2428 | /* | ||
2562 | * pivot_root Semantics: | 2429 | * pivot_root Semantics: |
2563 | * Moves the root file system of the current process to the directory put_old, | 2430 | * Moves the root file system of the current process to the directory put_old, |
2564 | * makes new_root as the new root file system of the current process, and sets | 2431 | * makes new_root as the new root file system of the current process, and sets |
@@ -2586,8 +2453,8 @@ out_type: | |||
2586 | SYSCALL_DEFINE2(pivot_root, const char __user *, new_root, | 2453 | SYSCALL_DEFINE2(pivot_root, const char __user *, new_root, |
2587 | const char __user *, put_old) | 2454 | const char __user *, put_old) |
2588 | { | 2455 | { |
2589 | struct vfsmount *tmp; | ||
2590 | struct path new, old, parent_path, root_parent, root; | 2456 | struct path new, old, parent_path, root_parent, root; |
2457 | struct mount *new_mnt, *root_mnt; | ||
2591 | int error; | 2458 | int error; |
2592 | 2459 | ||
2593 | if (!capable(CAP_SYS_ADMIN)) | 2460 | if (!capable(CAP_SYS_ADMIN)) |
@@ -2611,11 +2478,13 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root, | |||
2611 | goto out3; | 2478 | goto out3; |
2612 | 2479 | ||
2613 | error = -EINVAL; | 2480 | error = -EINVAL; |
2614 | if (IS_MNT_SHARED(old.mnt) || | 2481 | new_mnt = real_mount(new.mnt); |
2615 | IS_MNT_SHARED(new.mnt->mnt_parent) || | 2482 | root_mnt = real_mount(root.mnt); |
2616 | IS_MNT_SHARED(root.mnt->mnt_parent)) | 2483 | if (IS_MNT_SHARED(real_mount(old.mnt)) || |
2484 | IS_MNT_SHARED(new_mnt->mnt_parent) || | ||
2485 | IS_MNT_SHARED(root_mnt->mnt_parent)) | ||
2617 | goto out4; | 2486 | goto out4; |
2618 | if (!check_mnt(root.mnt) || !check_mnt(new.mnt)) | 2487 | if (!check_mnt(root_mnt) || !check_mnt(new_mnt)) |
2619 | goto out4; | 2488 | goto out4; |
2620 | error = -ENOENT; | 2489 | error = -ENOENT; |
2621 | if (d_unlinked(new.dentry)) | 2490 | if (d_unlinked(new.dentry)) |
@@ -2629,33 +2498,22 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root, | |||
2629 | error = -EINVAL; | 2498 | error = -EINVAL; |
2630 | if (root.mnt->mnt_root != root.dentry) | 2499 | if (root.mnt->mnt_root != root.dentry) |
2631 | goto out4; /* not a mountpoint */ | 2500 | goto out4; /* not a mountpoint */ |
2632 | if (root.mnt->mnt_parent == root.mnt) | 2501 | if (!mnt_has_parent(root_mnt)) |
2633 | goto out4; /* not attached */ | 2502 | goto out4; /* not attached */ |
2634 | if (new.mnt->mnt_root != new.dentry) | 2503 | if (new.mnt->mnt_root != new.dentry) |
2635 | goto out4; /* not a mountpoint */ | 2504 | goto out4; /* not a mountpoint */ |
2636 | if (new.mnt->mnt_parent == new.mnt) | 2505 | if (!mnt_has_parent(new_mnt)) |
2637 | goto out4; /* not attached */ | 2506 | goto out4; /* not attached */ |
2638 | /* make sure we can reach put_old from new_root */ | 2507 | /* make sure we can reach put_old from new_root */ |
2639 | tmp = old.mnt; | 2508 | if (!is_path_reachable(real_mount(old.mnt), old.dentry, &new)) |
2640 | if (tmp != new.mnt) { | ||
2641 | for (;;) { | ||
2642 | if (tmp->mnt_parent == tmp) | ||
2643 | goto out4; /* already mounted on put_old */ | ||
2644 | if (tmp->mnt_parent == new.mnt) | ||
2645 | break; | ||
2646 | tmp = tmp->mnt_parent; | ||
2647 | } | ||
2648 | if (!is_subdir(tmp->mnt_mountpoint, new.dentry)) | ||
2649 | goto out4; | ||
2650 | } else if (!is_subdir(old.dentry, new.dentry)) | ||
2651 | goto out4; | 2509 | goto out4; |
2652 | br_write_lock(vfsmount_lock); | 2510 | br_write_lock(vfsmount_lock); |
2653 | detach_mnt(new.mnt, &parent_path); | 2511 | detach_mnt(new_mnt, &parent_path); |
2654 | detach_mnt(root.mnt, &root_parent); | 2512 | detach_mnt(root_mnt, &root_parent); |
2655 | /* mount old root on put_old */ | 2513 | /* mount old root on put_old */ |
2656 | attach_mnt(root.mnt, &old); | 2514 | attach_mnt(root_mnt, &old); |
2657 | /* mount new_root on / */ | 2515 | /* mount new_root on / */ |
2658 | attach_mnt(new.mnt, &root_parent); | 2516 | attach_mnt(new_mnt, &root_parent); |
2659 | touch_mnt_namespace(current->nsproxy->mnt_ns); | 2517 | touch_mnt_namespace(current->nsproxy->mnt_ns); |
2660 | br_write_unlock(vfsmount_lock); | 2518 | br_write_unlock(vfsmount_lock); |
2661 | chroot_fs_refs(&root, &new); | 2519 | chroot_fs_refs(&root, &new); |
@@ -2693,8 +2551,8 @@ static void __init init_mount_tree(void) | |||
2693 | init_task.nsproxy->mnt_ns = ns; | 2551 | init_task.nsproxy->mnt_ns = ns; |
2694 | get_mnt_ns(ns); | 2552 | get_mnt_ns(ns); |
2695 | 2553 | ||
2696 | root.mnt = ns->root; | 2554 | root.mnt = mnt; |
2697 | root.dentry = ns->root->mnt_root; | 2555 | root.dentry = mnt->mnt_root; |
2698 | 2556 | ||
2699 | set_fs_pwd(current->fs, &root); | 2557 | set_fs_pwd(current->fs, &root); |
2700 | set_fs_root(current->fs, &root); | 2558 | set_fs_root(current->fs, &root); |
@@ -2707,7 +2565,7 @@ void __init mnt_init(void) | |||
2707 | 2565 | ||
2708 | init_rwsem(&namespace_sem); | 2566 | init_rwsem(&namespace_sem); |
2709 | 2567 | ||
2710 | mnt_cache = kmem_cache_create("mnt_cache", sizeof(struct vfsmount), | 2568 | mnt_cache = kmem_cache_create("mnt_cache", sizeof(struct mount), |
2711 | 0, SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL); | 2569 | 0, SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL); |
2712 | 2570 | ||
2713 | mount_hashtable = (struct list_head *)__get_free_page(GFP_ATOMIC); | 2571 | mount_hashtable = (struct list_head *)__get_free_page(GFP_ATOMIC); |
@@ -2747,7 +2605,6 @@ void put_mnt_ns(struct mnt_namespace *ns) | |||
2747 | release_mounts(&umount_list); | 2605 | release_mounts(&umount_list); |
2748 | kfree(ns); | 2606 | kfree(ns); |
2749 | } | 2607 | } |
2750 | EXPORT_SYMBOL(put_mnt_ns); | ||
2751 | 2608 | ||
2752 | struct vfsmount *kern_mount_data(struct file_system_type *type, void *data) | 2609 | struct vfsmount *kern_mount_data(struct file_system_type *type, void *data) |
2753 | { | 2610 | { |
@@ -2776,5 +2633,5 @@ EXPORT_SYMBOL(kern_unmount); | |||
2776 | 2633 | ||
2777 | bool our_mnt(struct vfsmount *mnt) | 2634 | bool our_mnt(struct vfsmount *mnt) |
2778 | { | 2635 | { |
2779 | return check_mnt(mnt); | 2636 | return check_mnt(real_mount(mnt)); |
2780 | } | 2637 | } |