drivers/net/ethernet/tundra/tsi108_eth.c: add missing iounmap
[firefly-linux-kernel-4.4.55.git] / fs / namespace.c
index dfed9a25f20479a8dd0ec80fe1a599f48b98fd17..e6081996c9a2f9d26525740545445630c4737583 100644 (file)
@@ -9,30 +9,17 @@
  */
 
 #include <linux/syscalls.h>
-#include <linux/slab.h>
-#include <linux/sched.h>
-#include <linux/spinlock.h>
-#include <linux/percpu.h>
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <linux/acct.h>
+#include <linux/export.h>
 #include <linux/capability.h>
-#include <linux/cpumask.h>
-#include <linux/module.h>
-#include <linux/sysfs.h>
-#include <linux/seq_file.h>
 #include <linux/mnt_namespace.h>
 #include <linux/namei.h>
-#include <linux/nsproxy.h>
 #include <linux/security.h>
-#include <linux/mount.h>
-#include <linux/ramfs.h>
-#include <linux/log2.h>
 #include <linux/idr.h>
-#include <linux/fs_struct.h>
-#include <linux/fsnotify.h>
-#include <asm/uaccess.h>
-#include <asm/unistd.h>
+#include <linux/acct.h>                /* acct_auto_close_mnt */
+#include <linux/ramfs.h>       /* init_rootfs */
+#include <linux/fs_struct.h>   /* get_fs_root et.al. */
+#include <linux/fsnotify.h>    /* fsnotify_vfsmount_delete */
+#include <linux/uaccess.h>
 #include "pnode.h"
 #include "internal.h"
 
@@ -173,12 +160,11 @@ unsigned int mnt_get_count(struct mount *mnt)
 
 static struct mount *alloc_vfsmnt(const char *name)
 {
-       struct mount *p = kmem_cache_zalloc(mnt_cache, GFP_KERNEL);
-       if (p) {
-               struct vfsmount *mnt = &p->mnt;
+       struct mount *mnt = kmem_cache_zalloc(mnt_cache, GFP_KERNEL);
+       if (mnt) {
                int err;
 
-               err = mnt_alloc_id(p);
+               err = mnt_alloc_id(mnt);
                if (err)
                        goto out_free_cache;
 
@@ -189,38 +175,38 @@ static struct mount *alloc_vfsmnt(const char *name)
                }
 
 #ifdef CONFIG_SMP
-               p->mnt_pcp = alloc_percpu(struct mnt_pcp);
-               if (!p->mnt_pcp)
+               mnt->mnt_pcp = alloc_percpu(struct mnt_pcp);
+               if (!mnt->mnt_pcp)
                        goto out_free_devname;
 
-               this_cpu_add(p->mnt_pcp->mnt_count, 1);
+               this_cpu_add(mnt->mnt_pcp->mnt_count, 1);
 #else
-               p->mnt_count = 1;
-               p->mnt_writers = 0;
+               mnt->mnt_count = 1;
+               mnt->mnt_writers = 0;
 #endif
 
-               INIT_LIST_HEAD(&p->mnt_hash);
-               INIT_LIST_HEAD(&p->mnt_child);
-               INIT_LIST_HEAD(&p->mnt_mounts);
+               INIT_LIST_HEAD(&mnt->mnt_hash);
+               INIT_LIST_HEAD(&mnt->mnt_child);
+               INIT_LIST_HEAD(&mnt->mnt_mounts);
                INIT_LIST_HEAD(&mnt->mnt_list);
-               INIT_LIST_HEAD(&p->mnt_expire);
-               INIT_LIST_HEAD(&p->mnt_share);
-               INIT_LIST_HEAD(&p->mnt_slave_list);
-               INIT_LIST_HEAD(&p->mnt_slave);
+               INIT_LIST_HEAD(&mnt->mnt_expire);
+               INIT_LIST_HEAD(&mnt->mnt_share);
+               INIT_LIST_HEAD(&mnt->mnt_slave_list);
+               INIT_LIST_HEAD(&mnt->mnt_slave);
 #ifdef CONFIG_FSNOTIFY
                INIT_HLIST_HEAD(&mnt->mnt_fsnotify_marks);
 #endif
        }
-       return p;
+       return mnt;
 
 #ifdef CONFIG_SMP
 out_free_devname:
-       kfree(p->mnt.mnt_devname);
+       kfree(mnt->mnt_devname);
 #endif
 out_free_id:
-       mnt_free_id(p);
+       mnt_free_id(mnt);
 out_free_cache:
-       kmem_cache_free(mnt_cache, p);
+       kmem_cache_free(mnt_cache, mnt);
        return NULL;
 }
 
@@ -287,6 +273,15 @@ static unsigned int mnt_get_writers(struct mount *mnt)
 #endif
 }
 
+static int mnt_is_readonly(struct vfsmount *mnt)
+{
+       if (mnt->mnt_sb->s_readonly_remount)
+               return 1;
+       /* Order wrt setting s_flags/s_readonly_remount in do_remount() */
+       smp_rmb();
+       return __mnt_is_readonly(mnt);
+}
+
 /*
  * Most r/o checks on a fs are for operations that take
  * discrete amounts of time, like a write() or unlink().
@@ -326,12 +321,10 @@ int mnt_want_write(struct vfsmount *m)
         * MNT_WRITE_HOLD is cleared.
         */
        smp_rmb();
-       if (__mnt_is_readonly(m)) {
+       if (mnt_is_readonly(m)) {
                mnt_dec_writers(mnt);
                ret = -EROFS;
-               goto out;
        }
-out:
        preempt_enable();
        return ret;
 }
@@ -449,9 +442,45 @@ static void __mnt_unmake_readonly(struct mount *mnt)
        br_write_unlock(vfsmount_lock);
 }
 
+int sb_prepare_remount_readonly(struct super_block *sb)
+{
+       struct mount *mnt;
+       int err = 0;
+
+       /* Racy optimization.  Recheck the counter under MNT_WRITE_HOLD */
+       if (atomic_long_read(&sb->s_remove_count))
+               return -EBUSY;
+
+       br_write_lock(vfsmount_lock);
+       list_for_each_entry(mnt, &sb->s_mounts, mnt_instance) {
+               if (!(mnt->mnt.mnt_flags & MNT_READONLY)) {
+                       mnt->mnt.mnt_flags |= MNT_WRITE_HOLD;
+                       smp_mb();
+                       if (mnt_get_writers(mnt) > 0) {
+                               err = -EBUSY;
+                               break;
+                       }
+               }
+       }
+       if (!err && atomic_long_read(&sb->s_remove_count))
+               err = -EBUSY;
+
+       if (!err) {
+               sb->s_readonly_remount = 1;
+               smp_wmb();
+       }
+       list_for_each_entry(mnt, &sb->s_mounts, mnt_instance) {
+               if (mnt->mnt.mnt_flags & MNT_WRITE_HOLD)
+                       mnt->mnt.mnt_flags &= ~MNT_WRITE_HOLD;
+       }
+       br_write_unlock(vfsmount_lock);
+
+       return err;
+}
+
 static void free_vfsmnt(struct mount *mnt)
 {
-       kfree(mnt->mnt.mnt_devname);
+       kfree(mnt->mnt_devname);
        mnt_free_id(mnt);
 #ifdef CONFIG_SMP
        free_percpu(mnt->mnt_pcp);
@@ -573,8 +602,9 @@ static void detach_mnt(struct mount *mnt, struct path *old_path)
 void mnt_set_mountpoint(struct mount *mnt, struct dentry *dentry,
                        struct mount *child_mnt)
 {
-       child_mnt->mnt_parent = real_mount(mntget(&mnt->mnt));
+       mnt_add_count(mnt, 1);  /* essentially, that's mntget */
        child_mnt->mnt_mountpoint = dget(dentry);
+       child_mnt->mnt_parent = mnt;
        spin_lock(&dentry->d_lock);
        dentry->d_flags |= DCACHE_MOUNTED;
        spin_unlock(&dentry->d_lock);
@@ -618,8 +648,8 @@ static void commit_tree(struct mount *mnt)
 
        BUG_ON(parent == mnt);
 
-       list_add_tail(&head, &mnt->mnt.mnt_list);
-       list_for_each_entry(m, &head, mnt.mnt_list) {
+       list_add_tail(&head, &mnt->mnt_list);
+       list_for_each_entry(m, &head, mnt_list) {
                m->mnt_ns = n;
                __mnt_make_longterm(m);
        }
@@ -632,12 +662,12 @@ static void commit_tree(struct mount *mnt)
        touch_mnt_namespace(n);
 }
 
-static struct mount *next_mnt(struct mount *p, struct vfsmount *root)
+static struct mount *next_mnt(struct mount *p, struct mount *root)
 {
        struct list_head *next = p->mnt_mounts.next;
        if (next == &p->mnt_mounts) {
                while (1) {
-                       if (&p->mnt == root)
+                       if (p == root)
                                return NULL;
                        next = p->mnt_child.next;
                        if (next != &p->mnt_parent->mnt_mounts)
@@ -684,6 +714,9 @@ vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void
        mnt->mnt.mnt_sb = root->d_sb;
        mnt->mnt_mountpoint = mnt->mnt.mnt_root;
        mnt->mnt_parent = mnt;
+       br_write_lock(vfsmount_lock);
+       list_add_tail(&mnt->mnt_instance, &root->d_sb->s_mounts);
+       br_write_unlock(vfsmount_lock);
        return &mnt->mnt;
 }
 EXPORT_SYMBOL_GPL(vfs_kern_mount);
@@ -692,7 +725,7 @@ static struct mount *clone_mnt(struct mount *old, struct dentry *root,
                                        int flag)
 {
        struct super_block *sb = old->mnt.mnt_sb;
-       struct mount *mnt = alloc_vfsmnt(old->mnt.mnt_devname);
+       struct mount *mnt = alloc_vfsmnt(old->mnt_devname);
 
        if (mnt) {
                if (flag & (CL_SLAVE | CL_PRIVATE))
@@ -712,13 +745,16 @@ static struct mount *clone_mnt(struct mount *old, struct dentry *root,
                mnt->mnt.mnt_root = dget(root);
                mnt->mnt_mountpoint = mnt->mnt.mnt_root;
                mnt->mnt_parent = mnt;
+               br_write_lock(vfsmount_lock);
+               list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
+               br_write_unlock(vfsmount_lock);
 
                if (flag & CL_SLAVE) {
                        list_add(&mnt->mnt_slave, &old->mnt_slave_list);
                        mnt->mnt_master = old;
-                       CLEAR_MNT_SHARED(&mnt->mnt);
+                       CLEAR_MNT_SHARED(mnt);
                } else if (!(flag & CL_PRIVATE)) {
-                       if ((flag & CL_MAKE_SHARED) || IS_MNT_SHARED(&old->mnt))
+                       if ((flag & CL_MAKE_SHARED) || IS_MNT_SHARED(old))
                                list_add(&mnt->mnt_share, &old->mnt_share);
                        if (IS_MNT_SLAVE(old))
                                list_add(&mnt->mnt_slave, &old->mnt_slave);
@@ -787,13 +823,14 @@ put_again:
                return;
        br_write_lock(vfsmount_lock);
 #endif
-       if (unlikely(mnt->mnt.mnt_pinned)) {
-               mnt_add_count(mnt, mnt->mnt.mnt_pinned + 1);
-               mnt->mnt.mnt_pinned = 0;
+       if (unlikely(mnt->mnt_pinned)) {
+               mnt_add_count(mnt, mnt->mnt_pinned + 1);
+               mnt->mnt_pinned = 0;
                br_write_unlock(vfsmount_lock);
                acct_auto_close_mnt(&mnt->mnt);
                goto put_again;
        }
+       list_del(&mnt->mnt_instance);
        br_write_unlock(vfsmount_lock);
        mntfree(mnt);
 }
@@ -801,10 +838,11 @@ put_again:
 void mntput(struct vfsmount *mnt)
 {
        if (mnt) {
+               struct mount *m = real_mount(mnt);
                /* avoid cacheline pingpong, hope gcc doesn't get "smart" */
-               if (unlikely(mnt->mnt_expiry_mark))
-                       mnt->mnt_expiry_mark = 0;
-               mntput_no_expire(real_mount(mnt));
+               if (unlikely(m->mnt_expiry_mark))
+                       m->mnt_expiry_mark = 0;
+               mntput_no_expire(m);
        }
 }
 EXPORT_SYMBOL(mntput);
@@ -820,16 +858,17 @@ EXPORT_SYMBOL(mntget);
 void mnt_pin(struct vfsmount *mnt)
 {
        br_write_lock(vfsmount_lock);
-       mnt->mnt_pinned++;
+       real_mount(mnt)->mnt_pinned++;
        br_write_unlock(vfsmount_lock);
 }
 EXPORT_SYMBOL(mnt_pin);
 
-void mnt_unpin(struct vfsmount *mnt)
+void mnt_unpin(struct vfsmount *m)
 {
+       struct mount *mnt = real_mount(m);
        br_write_lock(vfsmount_lock);
        if (mnt->mnt_pinned) {
-               mnt_add_count(real_mount(mnt), 1);
+               mnt_add_count(mnt, 1);
                mnt->mnt_pinned--;
        }
        br_write_unlock(vfsmount_lock);
@@ -847,12 +886,12 @@ static inline void mangle(struct seq_file *m, const char *s)
  *
  * See also save_mount_options().
  */
-int generic_show_options(struct seq_file *m, struct vfsmount *mnt)
+int generic_show_options(struct seq_file *m, struct dentry *root)
 {
        const char *options;
 
        rcu_read_lock();
-       options = rcu_dereference(mnt->mnt_sb->s_options);
+       options = rcu_dereference(root->d_sb->s_options);
 
        if (options != NULL && options[0]) {
                seq_putc(m, ',');
@@ -896,10 +935,10 @@ void replace_mount_options(struct super_block *sb, char *options)
 EXPORT_SYMBOL(replace_mount_options);
 
 #ifdef CONFIG_PROC_FS
-/* iterator */
+/* iterator; we want it to have access to namespace_sem, thus here... */
 static void *m_start(struct seq_file *m, loff_t *pos)
 {
-       struct proc_mounts *p = m->private;
+       struct proc_mounts *p = container_of(m, struct proc_mounts, m);
 
        down_read(&namespace_sem);
        return seq_list_start(&p->ns->list, *pos);
@@ -907,7 +946,7 @@ static void *m_start(struct seq_file *m, loff_t *pos)
 
 static void *m_next(struct seq_file *m, void *v, loff_t *pos)
 {
-       struct proc_mounts *p = m->private;
+       struct proc_mounts *p = container_of(m, struct proc_mounts, m);
 
        return seq_list_next(v, &p->ns->list, pos);
 }
@@ -917,220 +956,18 @@ static void m_stop(struct seq_file *m, void *v)
        up_read(&namespace_sem);
 }
 
-int mnt_had_events(struct proc_mounts *p)
-{
-       struct mnt_namespace *ns = p->ns;
-       int res = 0;
-
-       br_read_lock(vfsmount_lock);
-       if (p->m.poll_event != ns->event) {
-               p->m.poll_event = ns->event;
-               res = 1;
-       }
-       br_read_unlock(vfsmount_lock);
-
-       return res;
-}
-
-struct proc_fs_info {
-       int flag;
-       const char *str;
-};
-
-static int show_sb_opts(struct seq_file *m, struct super_block *sb)
-{
-       static const struct proc_fs_info fs_info[] = {
-               { MS_SYNCHRONOUS, ",sync" },
-               { MS_DIRSYNC, ",dirsync" },
-               { MS_MANDLOCK, ",mand" },
-               { 0, NULL }
-       };
-       const struct proc_fs_info *fs_infop;
-
-       for (fs_infop = fs_info; fs_infop->flag; fs_infop++) {
-               if (sb->s_flags & fs_infop->flag)
-                       seq_puts(m, fs_infop->str);
-       }
-
-       return security_sb_show_options(m, sb);
-}
-
-static void show_mnt_opts(struct seq_file *m, struct vfsmount *mnt)
-{
-       static const struct proc_fs_info mnt_info[] = {
-               { MNT_NOSUID, ",nosuid" },
-               { MNT_NODEV, ",nodev" },
-               { MNT_NOEXEC, ",noexec" },
-               { MNT_NOATIME, ",noatime" },
-               { MNT_NODIRATIME, ",nodiratime" },
-               { MNT_RELATIME, ",relatime" },
-               { 0, NULL }
-       };
-       const struct proc_fs_info *fs_infop;
-
-       for (fs_infop = mnt_info; fs_infop->flag; fs_infop++) {
-               if (mnt->mnt_flags & fs_infop->flag)
-                       seq_puts(m, fs_infop->str);
-       }
-}
-
-static void show_type(struct seq_file *m, struct super_block *sb)
-{
-       mangle(m, sb->s_type->name);
-       if (sb->s_subtype && sb->s_subtype[0]) {
-               seq_putc(m, '.');
-               mangle(m, sb->s_subtype);
-       }
-}
-
-static int show_vfsmnt(struct seq_file *m, void *v)
+static int m_show(struct seq_file *m, void *v)
 {
-       struct vfsmount *mnt = list_entry(v, struct vfsmount, mnt_list);
-       int err = 0;
-       struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
-
-       if (mnt->mnt_sb->s_op->show_devname) {
-               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
-               if (err)
-                       goto out;
-       } else {
-               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
-       }
-       seq_putc(m, ' ');
-       seq_path(m, &mnt_path, " \t\n\\");
-       seq_putc(m, ' ');
-       show_type(m, mnt->mnt_sb);
-       seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
-       err = show_sb_opts(m, mnt->mnt_sb);
-       if (err)
-               goto out;
-       show_mnt_opts(m, mnt);
-       if (mnt->mnt_sb->s_op->show_options)
-               err = mnt->mnt_sb->s_op->show_options(m, mnt);
-       seq_puts(m, " 0 0\n");
-out:
-       return err;
+       struct proc_mounts *p = container_of(m, struct proc_mounts, m);
+       struct mount *r = list_entry(v, struct mount, mnt_list);
+       return p->show(m, &r->mnt);
 }
 
 const struct seq_operations mounts_op = {
        .start  = m_start,
        .next   = m_next,
        .stop   = m_stop,
-       .show   = show_vfsmnt
-};
-
-static int show_mountinfo(struct seq_file *m, void *v)
-{
-       struct proc_mounts *p = m->private;
-       struct vfsmount *mnt = list_entry(v, struct vfsmount, mnt_list);
-       struct mount *r = real_mount(mnt);
-       struct super_block *sb = mnt->mnt_sb;
-       struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
-       struct path root = p->root;
-       int err = 0;
-
-       seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
-                  MAJOR(sb->s_dev), MINOR(sb->s_dev));
-       if (sb->s_op->show_path)
-               err = sb->s_op->show_path(m, mnt);
-       else
-               seq_dentry(m, mnt->mnt_root, " \t\n\\");
-       if (err)
-               goto out;
-       seq_putc(m, ' ');
-
-       /* mountpoints outside of chroot jail will give SEQ_SKIP on this */
-       err = seq_path_root(m, &mnt_path, &root, " \t\n\\");
-       if (err)
-               goto out;
-
-       seq_puts(m, mnt->mnt_flags & MNT_READONLY ? " ro" : " rw");
-       show_mnt_opts(m, mnt);
-
-       /* Tagged fields ("foo:X" or "bar") */
-       if (IS_MNT_SHARED(mnt))
-               seq_printf(m, " shared:%i", r->mnt_group_id);
-       if (IS_MNT_SLAVE(r)) {
-               int master = r->mnt_master->mnt_group_id;
-               int dom = get_dominating_id(r, &p->root);
-               seq_printf(m, " master:%i", master);
-               if (dom && dom != master)
-                       seq_printf(m, " propagate_from:%i", dom);
-       }
-       if (IS_MNT_UNBINDABLE(mnt))
-               seq_puts(m, " unbindable");
-
-       /* Filesystem specific data */
-       seq_puts(m, " - ");
-       show_type(m, sb);
-       seq_putc(m, ' ');
-       if (sb->s_op->show_devname)
-               err = sb->s_op->show_devname(m, mnt);
-       else
-               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
-       if (err)
-               goto out;
-       seq_puts(m, sb->s_flags & MS_RDONLY ? " ro" : " rw");
-       err = show_sb_opts(m, sb);
-       if (err)
-               goto out;
-       if (sb->s_op->show_options)
-               err = sb->s_op->show_options(m, mnt);
-       seq_putc(m, '\n');
-out:
-       return err;
-}
-
-const struct seq_operations mountinfo_op = {
-       .start  = m_start,
-       .next   = m_next,
-       .stop   = m_stop,
-       .show   = show_mountinfo,
-};
-
-static int show_vfsstat(struct seq_file *m, void *v)
-{
-       struct vfsmount *mnt = list_entry(v, struct vfsmount, mnt_list);
-       struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
-       int err = 0;
-
-       /* device */
-       if (mnt->mnt_sb->s_op->show_devname) {
-               seq_puts(m, "device ");
-               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
-       } else {
-               if (mnt->mnt_devname) {
-                       seq_puts(m, "device ");
-                       mangle(m, mnt->mnt_devname);
-               } else
-                       seq_puts(m, "no device");
-       }
-
-       /* mount point */
-       seq_puts(m, " mounted on ");
-       seq_path(m, &mnt_path, " \t\n\\");
-       seq_putc(m, ' ');
-
-       /* file system type */
-       seq_puts(m, "with fstype ");
-       show_type(m, mnt->mnt_sb);
-
-       /* optional statistics */
-       if (mnt->mnt_sb->s_op->show_stats) {
-               seq_putc(m, ' ');
-               if (!err)
-                       err = mnt->mnt_sb->s_op->show_stats(m, mnt);
-       }
-
-       seq_putc(m, '\n');
-       return err;
-}
-
-const struct seq_operations mountstats_op = {
-       .start  = m_start,
-       .next   = m_next,
-       .stop   = m_stop,
-       .show   = show_vfsstat,
+       .show   = m_show,
 };
 #endif  /* CONFIG_PROC_FS */
 
@@ -1142,16 +979,17 @@ const struct seq_operations mountstats_op = {
  * open files, pwds, chroots or sub mounts that are
  * busy.
  */
-int may_umount_tree(struct vfsmount *mnt)
+int may_umount_tree(struct vfsmount *m)
 {
+       struct mount *mnt = real_mount(m);
        int actual_refs = 0;
        int minimum_refs = 0;
        struct mount *p;
-       BUG_ON(!mnt);
+       BUG_ON(!m);
 
        /* write lock needed for mnt_get_count */
        br_write_lock(vfsmount_lock);
-       for (p = real_mount(mnt); p; p = next_mnt(p, mnt)) {
+       for (p = mnt; p; p = next_mnt(p, mnt)) {
                actual_refs += mnt_get_count(p);
                minimum_refs += 2;
        }
@@ -1200,17 +1038,17 @@ void release_mounts(struct list_head *head)
                list_del_init(&mnt->mnt_hash);
                if (mnt_has_parent(mnt)) {
                        struct dentry *dentry;
-                       struct vfsmount *m;
+                       struct mount *m;
 
                        br_write_lock(vfsmount_lock);
                        dentry = mnt->mnt_mountpoint;
-                       m = &mnt->mnt_parent->mnt;
+                       m = mnt->mnt_parent;
                        mnt->mnt_mountpoint = mnt->mnt.mnt_root;
                        mnt->mnt_parent = mnt;
                        m->mnt_ghosts--;
                        br_write_unlock(vfsmount_lock);
                        dput(dentry);
-                       mntput(m);
+                       mntput(&m->mnt);
                }
                mntput(&mnt->mnt);
        }
@@ -1225,7 +1063,7 @@ void umount_tree(struct mount *mnt, int propagate, struct list_head *kill)
        LIST_HEAD(tmp_list);
        struct mount *p;
 
-       for (p = mnt; p; p = next_mnt(p, &mnt->mnt))
+       for (p = mnt; p; p = next_mnt(p, mnt))
                list_move(&p->mnt_hash, &tmp_list);
 
        if (propagate)
@@ -1233,13 +1071,13 @@ void umount_tree(struct mount *mnt, int propagate, struct list_head *kill)
 
        list_for_each_entry(p, &tmp_list, mnt_hash) {
                list_del_init(&p->mnt_expire);
-               list_del_init(&p->mnt.mnt_list);
+               list_del_init(&p->mnt_list);
                __touch_mnt_namespace(p->mnt_ns);
                p->mnt_ns = NULL;
                __mnt_make_shortterm(p);
                list_del_init(&p->mnt_child);
                if (mnt_has_parent(p)) {
-                       p->mnt_parent->mnt.mnt_ghosts++;
+                       p->mnt_parent->mnt_ghosts++;
                        dentry_reset_mounted(p->mnt_mountpoint);
                }
                change_mnt_propagation(p, MS_PRIVATE);
@@ -1281,7 +1119,7 @@ static int do_umount(struct mount *mnt, int flags)
                }
                br_write_unlock(vfsmount_lock);
 
-               if (!xchg(&mnt->mnt.mnt_expiry_mark, 1))
+               if (!xchg(&mnt->mnt_expiry_mark, 1))
                        return -EAGAIN;
        }
 
@@ -1329,7 +1167,7 @@ static int do_umount(struct mount *mnt, int flags)
 
        retval = -EBUSY;
        if (flags & MNT_DETACH || !propagate_mount_busy(mnt, 2)) {
-               if (!list_empty(&mnt->mnt.mnt_list))
+               if (!list_empty(&mnt->mnt_list))
                        umount_tree(mnt, 1, &umount_list);
                retval = 0;
        }
@@ -1419,7 +1257,7 @@ struct mount *copy_tree(struct mount *mnt, struct dentry *dentry,
        struct mount *res, *p, *q, *r;
        struct path path;
 
-       if (!(flag & CL_COPY_ALL) && IS_MNT_UNBINDABLE(&mnt->mnt))
+       if (!(flag & CL_COPY_ALL) && IS_MNT_UNBINDABLE(mnt))
                return NULL;
 
        res = q = clone_mnt(mnt, dentry, flag);
@@ -1433,8 +1271,8 @@ struct mount *copy_tree(struct mount *mnt, struct dentry *dentry,
                if (!is_subdir(r->mnt_mountpoint, dentry))
                        continue;
 
-               for (s = r; s; s = next_mnt(s, &r->mnt)) {
-                       if (!(flag & CL_COPY_ALL) && IS_MNT_UNBINDABLE(&s->mnt)) {
+               for (s = r; s; s = next_mnt(s, r)) {
+                       if (!(flag & CL_COPY_ALL) && IS_MNT_UNBINDABLE(s)) {
                                s = skip_mnt_tree(s);
                                continue;
                        }
@@ -1449,7 +1287,7 @@ struct mount *copy_tree(struct mount *mnt, struct dentry *dentry,
                        if (!q)
                                goto Enomem;
                        br_write_lock(vfsmount_lock);
-                       list_add_tail(&q->mnt.mnt_list, &res->mnt.mnt_list);
+                       list_add_tail(&q->mnt_list, &res->mnt_list);
                        attach_mnt(q, &path);
                        br_write_unlock(vfsmount_lock);
                }
@@ -1490,12 +1328,12 @@ void drop_collected_mounts(struct vfsmount *mnt)
 int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
                   struct vfsmount *root)
 {
-       struct vfsmount *mnt;
+       struct mount *mnt;
        int res = f(root, arg);
        if (res)
                return res;
-       list_for_each_entry(mnt, &root->mnt_list, mnt_list) {
-               res = f(mnt, arg);
+       list_for_each_entry(mnt, &real_mount(root)->mnt_list, mnt_list) {
+               res = f(&mnt->mnt, arg);
                if (res)
                        return res;
        }
@@ -1506,8 +1344,8 @@ static void cleanup_group_ids(struct mount *mnt, struct mount *end)
 {
        struct mount *p;
 
-       for (p = mnt; p != end; p = next_mnt(p, &mnt->mnt)) {
-               if (p->mnt_group_id && !IS_MNT_SHARED(&p->mnt))
+       for (p = mnt; p != end; p = next_mnt(p, mnt)) {
+               if (p->mnt_group_id && !IS_MNT_SHARED(p))
                        mnt_release_group_id(p);
        }
 }
@@ -1516,8 +1354,8 @@ static int invent_group_ids(struct mount *mnt, bool recurse)
 {
        struct mount *p;
 
-       for (p = mnt; p; p = recurse ? next_mnt(p, &mnt->mnt) : NULL) {
-               if (!p->mnt_group_id && !IS_MNT_SHARED(&p->mnt)) {
+       for (p = mnt; p; p = recurse ? next_mnt(p, mnt) : NULL) {
+               if (!p->mnt_group_id && !IS_MNT_SHARED(p)) {
                        int err = mnt_alloc_group_id(p);
                        if (err) {
                                cleanup_group_ids(mnt, p);
@@ -1601,7 +1439,7 @@ static int attach_recursive_mnt(struct mount *source_mnt,
        struct mount *child, *p;
        int err;
 
-       if (IS_MNT_SHARED(&dest_mnt->mnt)) {
+       if (IS_MNT_SHARED(dest_mnt)) {
                err = invent_group_ids(source_mnt, true);
                if (err)
                        goto out;
@@ -1612,8 +1450,8 @@ static int attach_recursive_mnt(struct mount *source_mnt,
 
        br_write_lock(vfsmount_lock);
 
-       if (IS_MNT_SHARED(&dest_mnt->mnt)) {
-               for (p = source_mnt; p; p = next_mnt(p, &source_mnt->mnt))
+       if (IS_MNT_SHARED(dest_mnt)) {
+               for (p = source_mnt; p; p = next_mnt(p, source_mnt))
                        set_mnt_shared(p);
        }
        if (parent_path) {
@@ -1634,7 +1472,7 @@ static int attach_recursive_mnt(struct mount *source_mnt,
        return 0;
 
  out_cleanup_ids:
-       if (IS_MNT_SHARED(&dest_mnt->mnt))
+       if (IS_MNT_SHARED(dest_mnt))
                cleanup_group_ids(source_mnt, NULL);
  out:
        return err;
@@ -1728,7 +1566,7 @@ static int do_change_type(struct path *path, int flag)
        }
 
        br_write_lock(vfsmount_lock);
-       for (m = mnt; m; m = (recurse ? next_mnt(m, &mnt->mnt) : NULL))
+       for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
                change_mnt_propagation(m, type);
        br_write_unlock(vfsmount_lock);
 
@@ -1762,7 +1600,7 @@ static int do_loopback(struct path *path, char *old_name,
        old = real_mount(old_path.mnt);
 
        err = -EINVAL;
-       if (IS_MNT_UNBINDABLE(old_path.mnt))
+       if (IS_MNT_UNBINDABLE(old))
                goto out2;
 
        if (!check_mnt(real_mount(path->mnt)) || !check_mnt(old))
@@ -1856,8 +1694,8 @@ static int do_remount(struct path *path, int flags, int mnt_flags,
 static inline int tree_contains_unbindable(struct mount *mnt)
 {
        struct mount *p;
-       for (p = mnt; p; p = next_mnt(p, &mnt->mnt)) {
-               if (IS_MNT_UNBINDABLE(&p->mnt))
+       for (p = mnt; p; p = next_mnt(p, mnt)) {
+               if (IS_MNT_UNBINDABLE(p))
                        return 1;
        }
        return 0;
@@ -1882,9 +1720,10 @@ static int do_move_mount(struct path *path, char *old_name)
                goto out;
 
        old = real_mount(old_path.mnt);
+       p = real_mount(path->mnt);
 
        err = -EINVAL;
-       if (!check_mnt(real_mount(path->mnt)) || !check_mnt(old))
+       if (!check_mnt(p) || !check_mnt(old))
                goto out1;
 
        if (d_unlinked(path->dentry))
@@ -1903,17 +1742,16 @@ static int do_move_mount(struct path *path, char *old_name)
        /*
         * Don't move a mount residing in a shared parent.
         */
-       if (IS_MNT_SHARED(&old->mnt_parent->mnt))
+       if (IS_MNT_SHARED(old->mnt_parent))
                goto out1;
        /*
         * Don't move a mount tree containing unbindable mounts to a destination
         * mount which is shared.
         */
-       if (IS_MNT_SHARED(path->mnt) &&
-           tree_contains_unbindable(old))
+       if (IS_MNT_SHARED(p) && tree_contains_unbindable(old))
                goto out1;
        err = -ELOOP;
-       for (p = real_mount(path->mnt); mnt_has_parent(p); p = p->mnt_parent)
+       for (; mnt_has_parent(p); p = p->mnt_parent)
                if (p == old)
                        goto out1;
 
@@ -2106,7 +1944,7 @@ void mark_mounts_for_expiry(struct list_head *mounts)
         *   cleared by mntput())
         */
        list_for_each_entry_safe(mnt, next, mounts, mnt_expire) {
-               if (!xchg(&mnt->mnt.mnt_expiry_mark, 1) ||
+               if (!xchg(&mnt->mnt_expiry_mark, 1) ||
                        propagate_mount_busy(mnt, 1))
                        continue;
                list_move(&mnt->mnt_expire, &graveyard);
@@ -2396,6 +2234,7 @@ static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
        struct mnt_namespace *new_ns;
        struct vfsmount *rootmnt = NULL, *pwdmnt = NULL;
        struct mount *p, *q;
+       struct mount *old = mnt_ns->root;
        struct mount *new;
 
        new_ns = alloc_mnt_ns();
@@ -2404,16 +2243,15 @@ static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
 
        down_write(&namespace_sem);
        /* First pass: copy the tree topology */
-       new = copy_tree(real_mount(mnt_ns->root), mnt_ns->root->mnt_root,
-                                       CL_COPY_ALL | CL_EXPIRE);
+       new = copy_tree(old, old->mnt.mnt_root, CL_COPY_ALL | CL_EXPIRE);
        if (!new) {
                up_write(&namespace_sem);
                kfree(new_ns);
                return ERR_PTR(-ENOMEM);
        }
-       new_ns->root = &new->mnt;
+       new_ns->root = new;
        br_write_lock(vfsmount_lock);
-       list_add_tail(&new_ns->list, &new_ns->root->mnt_list);
+       list_add_tail(&new_ns->list, &new->mnt_list);
        br_write_unlock(vfsmount_lock);
 
        /*
@@ -2421,7 +2259,7 @@ static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
         * as belonging to new namespace.  We have already acquired a private
         * fs_struct, so tsk->fs->lock is not needed.
         */
-       p = real_mount(mnt_ns->root);
+       p = old;
        q = new;
        while (p) {
                q->mnt_ns = new_ns;
@@ -2440,8 +2278,8 @@ static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
                                pwdmnt = &p->mnt;
                        }
                }
-               p = next_mnt(p, mnt_ns->root);
-               q = next_mnt(q, new_ns->root);
+               p = next_mnt(p, old);
+               q = next_mnt(q, new);
        }
        up_write(&namespace_sem);
 
@@ -2474,18 +2312,17 @@ struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
  * create_mnt_ns - creates a private namespace and adds a root filesystem
  * @mnt: pointer to the new root filesystem mountpoint
  */
-static struct mnt_namespace *create_mnt_ns(struct vfsmount *mnt)
+static struct mnt_namespace *create_mnt_ns(struct vfsmount *m)
 {
-       struct mnt_namespace *new_ns;
-
-       new_ns = alloc_mnt_ns();
+       struct mnt_namespace *new_ns = alloc_mnt_ns();
        if (!IS_ERR(new_ns)) {
-               real_mount(mnt)->mnt_ns = new_ns;
-               __mnt_make_longterm(real_mount(mnt));
+               struct mount *mnt = real_mount(m);
+               mnt->mnt_ns = new_ns;
+               __mnt_make_longterm(mnt);
                new_ns->root = mnt;
-               list_add(&new_ns->list, &new_ns->root->mnt_list);
+               list_add(&new_ns->list, &mnt->mnt_list);
        } else {
-               mntput(mnt);
+               mntput(m);
        }
        return new_ns;
 }
@@ -2641,9 +2478,9 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
        error = -EINVAL;
        new_mnt = real_mount(new.mnt);
        root_mnt = real_mount(root.mnt);
-       if (IS_MNT_SHARED(old.mnt) ||
-               IS_MNT_SHARED(&new_mnt->mnt_parent->mnt) ||
-               IS_MNT_SHARED(&root_mnt->mnt_parent->mnt))
+       if (IS_MNT_SHARED(real_mount(old.mnt)) ||
+               IS_MNT_SHARED(new_mnt->mnt_parent) ||
+               IS_MNT_SHARED(root_mnt->mnt_parent))
                goto out4;
        if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
                goto out4;
@@ -2712,8 +2549,8 @@ static void __init init_mount_tree(void)
        init_task.nsproxy->mnt_ns = ns;
        get_mnt_ns(ns);
 
-       root.mnt = ns->root;
-       root.dentry = ns->root->mnt_root;
+       root.mnt = mnt;
+       root.dentry = mnt->mnt_root;
 
        set_fs_pwd(current->fs, &root);
        set_fs_root(current->fs, &root);
@@ -2760,7 +2597,7 @@ void put_mnt_ns(struct mnt_namespace *ns)
                return;
        down_write(&namespace_sem);
        br_write_lock(vfsmount_lock);
-       umount_tree(real_mount(ns->root), 0, &umount_list);
+       umount_tree(ns->root, 0, &umount_list);
        br_write_unlock(vfsmount_lock);
        up_write(&namespace_sem);
        release_mounts(&umount_list);