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