vfs: spread struct mount - get_dominating_id / do_make_slave
[firefly-linux-kernel-4.4.55.git] / fs / pnode.c
index d42514e32380b5edb38f7985069efe8d8ccc80fa..29e366dec02454051b7759e3090a2892902e2d36 100644 (file)
@@ -28,33 +28,18 @@ static inline struct vfsmount *next_slave(struct vfsmount *p)
        return list_entry(p->mnt_slave.next, struct vfsmount, mnt_slave);
 }
 
-/*
- * Return true if path is reachable from root
- *
- * namespace_sem is held, and mnt is attached
- */
-static bool is_path_reachable(struct vfsmount *mnt, struct dentry *dentry,
-                        const struct path *root)
-{
-       while (mnt != root->mnt && mnt->mnt_parent != mnt) {
-               dentry = mnt->mnt_mountpoint;
-               mnt = mnt->mnt_parent;
-       }
-       return mnt == root->mnt && is_subdir(dentry, root->dentry);
-}
-
-static struct vfsmount *get_peer_under_root(struct vfsmount *mnt,
-                                           struct mnt_namespace *ns,
-                                           const struct path *root)
+static struct mount *get_peer_under_root(struct mount *mnt,
+                                        struct mnt_namespace *ns,
+                                        const struct path *root)
 {
-       struct vfsmount *m = mnt;
+       struct mount *m = mnt;
 
        do {
                /* Check the namespace first for optimization */
-               if (m->mnt_ns == ns && is_path_reachable(m, m->mnt_root, root))
+               if (m->mnt.mnt_ns == ns && is_path_reachable(m, m->mnt.mnt_root, root))
                        return m;
 
-               m = next_peer(m);
+               m = real_mount(next_peer(&m->mnt));
        } while (m != mnt);
 
        return NULL;
@@ -66,22 +51,22 @@ static struct vfsmount *get_peer_under_root(struct vfsmount *mnt,
  *
  * Caller must hold namespace_sem
  */
-int get_dominating_id(struct vfsmount *mnt, const struct path *root)
+int get_dominating_id(struct mount *mnt, const struct path *root)
 {
-       struct vfsmount *m;
+       struct mount *m;
 
-       for (m = mnt->mnt_master; m != NULL; m = m->mnt_master) {
-               struct vfsmount *d = get_peer_under_root(m, mnt->mnt_ns, root);
+       for (m = real_mount(mnt->mnt.mnt_master); m != NULL; m = real_mount(m->mnt.mnt_master)) {
+               struct mount *d = get_peer_under_root(m, mnt->mnt.mnt_ns, root);
                if (d)
-                       return d->mnt_group_id;
+                       return d->mnt.mnt_group_id;
        }
 
        return 0;
 }
 
-static int do_make_slave(struct vfsmount *mnt)
+static int do_make_slave(struct mount *mnt)
 {
-       struct vfsmount *peer_mnt = mnt, *master = mnt->mnt_master;
+       struct mount *peer_mnt = mnt, *master = real_mount(mnt->mnt.mnt_master);
        struct vfsmount *slave_mnt;
 
        /*
@@ -89,31 +74,31 @@ static int do_make_slave(struct vfsmount *mnt)
         * same root dentry. If none is available then
         * slave it to anything that is available.
         */
-       while ((peer_mnt = next_peer(peer_mnt)) != mnt &&
-              peer_mnt->mnt_root != mnt->mnt_root) ;
+       while ((peer_mnt = real_mount(next_peer(&peer_mnt->mnt))) != mnt &&
+              peer_mnt->mnt.mnt_root != mnt->mnt.mnt_root) ;
 
        if (peer_mnt == mnt) {
-               peer_mnt = next_peer(mnt);
+               peer_mnt = real_mount(next_peer(&mnt->mnt));
                if (peer_mnt == mnt)
                        peer_mnt = NULL;
        }
-       if (IS_MNT_SHARED(mnt) && list_empty(&mnt->mnt_share))
+       if (IS_MNT_SHARED(&mnt->mnt) && list_empty(&mnt->mnt.mnt_share))
                mnt_release_group_id(mnt);
 
-       list_del_init(&mnt->mnt_share);
-       mnt->mnt_group_id = 0;
+       list_del_init(&mnt->mnt.mnt_share);
+       mnt->mnt.mnt_group_id = 0;
 
        if (peer_mnt)
                master = peer_mnt;
 
        if (master) {
-               list_for_each_entry(slave_mnt, &mnt->mnt_slave_list, mnt_slave)
-                       slave_mnt->mnt_master = master;
-               list_move(&mnt->mnt_slave, &master->mnt_slave_list);
-               list_splice(&mnt->mnt_slave_list, master->mnt_slave_list.prev);
-               INIT_LIST_HEAD(&mnt->mnt_slave_list);
+               list_for_each_entry(slave_mnt, &mnt->mnt.mnt_slave_list, mnt_slave)
+                       slave_mnt->mnt_master = &master->mnt;
+               list_move(&mnt->mnt.mnt_slave, &master->mnt.mnt_slave_list);
+               list_splice(&mnt->mnt.mnt_slave_list, master->mnt.mnt_slave_list.prev);
+               INIT_LIST_HEAD(&mnt->mnt.mnt_slave_list);
        } else {
-               struct list_head *p = &mnt->mnt_slave_list;
+               struct list_head *p = &mnt->mnt.mnt_slave_list;
                while (!list_empty(p)) {
                         slave_mnt = list_first_entry(p,
                                        struct vfsmount, mnt_slave);
@@ -121,15 +106,15 @@ static int do_make_slave(struct vfsmount *mnt)
                        slave_mnt->mnt_master = NULL;
                }
        }
-       mnt->mnt_master = master;
-       CLEAR_MNT_SHARED(mnt);
+       mnt->mnt.mnt_master = &master->mnt;
+       CLEAR_MNT_SHARED(&mnt->mnt);
        return 0;
 }
 
 /*
  * vfsmount lock must be held for write
  */
-void change_mnt_propagation(struct vfsmount *mnt, int type)
+void change_mnt_propagation(struct mount *mnt, int type)
 {
        if (type == MS_SHARED) {
                set_mnt_shared(mnt);
@@ -137,12 +122,12 @@ void change_mnt_propagation(struct vfsmount *mnt, int type)
        }
        do_make_slave(mnt);
        if (type != MS_SLAVE) {
-               list_del_init(&mnt->mnt_slave);
-               mnt->mnt_master = NULL;
+               list_del_init(&mnt->mnt.mnt_slave);
+               mnt->mnt.mnt_master = NULL;
                if (type == MS_UNBINDABLE)
-                       mnt->mnt_flags |= MNT_UNBINDABLE;
+                       mnt->mnt.mnt_flags |= MNT_UNBINDABLE;
                else
-                       mnt->mnt_flags &= ~MNT_UNBINDABLE;
+                       mnt->mnt.mnt_flags &= ~MNT_UNBINDABLE;
        }
 }
 
@@ -236,7 +221,8 @@ static struct vfsmount *get_source(struct vfsmount *dest,
 int propagate_mnt(struct vfsmount *dest_mnt, struct dentry *dest_dentry,
                    struct vfsmount *source_mnt, struct list_head *tree_list)
 {
-       struct vfsmount *m, *child;
+       struct vfsmount *m;
+       struct mount *child;
        int ret = 0;
        struct vfsmount *prev_dest_mnt = dest_mnt;
        struct vfsmount *prev_src_mnt  = source_mnt;
@@ -253,7 +239,7 @@ int propagate_mnt(struct vfsmount *dest_mnt, struct dentry *dest_dentry,
 
                source =  get_source(m, prev_dest_mnt, prev_src_mnt, &type);
 
-               if (!(child = copy_tree(source, source->mnt_root, type))) {
+               if (!(child = copy_tree(real_mount(source), source->mnt_root, type))) {
                        ret = -ENOMEM;
                        list_splice(tree_list, tmp_list.prev);
                        goto out;
@@ -270,12 +256,12 @@ int propagate_mnt(struct vfsmount *dest_mnt, struct dentry *dest_dentry,
                        list_add_tail(&child->mnt_hash, &tmp_list);
                }
                prev_dest_mnt = m;
-               prev_src_mnt  = child;
+               prev_src_mnt  = &child->mnt;
        }
 out:
        br_write_lock(vfsmount_lock);
        while (!list_empty(&tmp_list)) {
-               child = list_first_entry(&tmp_list, struct vfsmount, mnt_hash);
+               child = list_first_entry(&tmp_list, struct mount, mnt_hash);
                umount_tree(child, 0, &umount_list);
        }
        br_write_unlock(vfsmount_lock);
@@ -286,9 +272,9 @@ out:
 /*
  * return true if the refcount is greater than count
  */
-static inline int do_refcount_check(struct vfsmount *mnt, int count)
+static inline int do_refcount_check(struct mount *mnt, int count)
 {
-       int mycount = mnt_get_count(mnt) - mnt->mnt_ghosts;
+       int mycount = mnt_get_count(mnt) - mnt->mnt.mnt_ghosts;
        return (mycount > count);
 }
 
@@ -302,10 +288,11 @@ static inline int do_refcount_check(struct vfsmount *mnt, int count)
  *
  * vfsmount lock must be held for write
  */
-int propagate_mount_busy(struct vfsmount *mnt, int refcnt)
+int propagate_mount_busy(struct mount *mnt, int refcnt)
 {
-       struct vfsmount *m, *child;
-       struct vfsmount *parent = mnt->mnt_parent;
+       struct vfsmount *m;
+       struct mount *child;
+       struct mount *parent = mnt->mnt_parent;
        int ret = 0;
 
        if (mnt == parent)
@@ -319,8 +306,8 @@ int propagate_mount_busy(struct vfsmount *mnt, int refcnt)
        if (!list_empty(&mnt->mnt_mounts) || do_refcount_check(mnt, refcnt))
                return 1;
 
-       for (m = propagation_next(parent, parent); m;
-                       m = propagation_next(m, parent)) {
+       for (m = propagation_next(&parent->mnt, &parent->mnt); m;
+                       m = propagation_next(m, &parent->mnt)) {
                child = __lookup_mnt(m, mnt->mnt_mountpoint, 0);
                if (child && list_empty(&child->mnt_mounts) &&
                    (ret = do_refcount_check(child, 1)))
@@ -333,17 +320,17 @@ int propagate_mount_busy(struct vfsmount *mnt, int refcnt)
  * NOTE: unmounting 'mnt' naturally propagates to all other mounts its
  * parent propagates to.
  */
-static void __propagate_umount(struct vfsmount *mnt)
+static void __propagate_umount(struct mount *mnt)
 {
-       struct vfsmount *parent = mnt->mnt_parent;
+       struct mount *parent = mnt->mnt_parent;
        struct vfsmount *m;
 
        BUG_ON(parent == mnt);
 
-       for (m = propagation_next(parent, parent); m;
-                       m = propagation_next(m, parent)) {
+       for (m = propagation_next(&parent->mnt, &parent->mnt); m;
+                       m = propagation_next(m, &parent->mnt)) {
 
-               struct vfsmount *child = __lookup_mnt(m,
+               struct mount *child = __lookup_mnt(m,
                                        mnt->mnt_mountpoint, 0);
                /*
                 * umount the child only if the child has no
@@ -363,7 +350,7 @@ static void __propagate_umount(struct vfsmount *mnt)
  */
 int propagate_umount(struct list_head *list)
 {
-       struct vfsmount *mnt;
+       struct mount *mnt;
 
        list_for_each_entry(mnt, list, mnt_hash)
                __propagate_umount(mnt);