]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blobdiff - fs/pnode.c
UBUNTU: Start new release
[mirror_ubuntu-zesty-kernel.git] / fs / pnode.c
index 234a9ac49958ed978f67aad68d81fb75cf5717ce..5bc7896d122ae700fc76c3a71e123149d013b92a 100644 (file)
@@ -67,49 +67,47 @@ int get_dominating_id(struct mount *mnt, const struct path *root)
 
 static int do_make_slave(struct mount *mnt)
 {
-       struct mount *peer_mnt = mnt, *master = mnt->mnt_master;
-       struct mount *slave_mnt;
+       struct mount *master, *slave_mnt;
 
-       /*
-        * slave 'mnt' to a peer mount that has the
-        * 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.mnt_root != mnt->mnt.mnt_root) ;
-
-       if (peer_mnt == mnt) {
-               peer_mnt = next_peer(mnt);
-               if (peer_mnt == mnt)
-                       peer_mnt = NULL;
-       }
-       if (mnt->mnt_group_id && IS_MNT_SHARED(mnt) &&
-           list_empty(&mnt->mnt_share))
-               mnt_release_group_id(mnt);
-
-       list_del_init(&mnt->mnt_share);
-       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);
+       if (list_empty(&mnt->mnt_share)) {
+               if (IS_MNT_SHARED(mnt)) {
+                       mnt_release_group_id(mnt);
+                       CLEAR_MNT_SHARED(mnt);
+               }
+               master = mnt->mnt_master;
+               if (!master) {
+                       struct list_head *p = &mnt->mnt_slave_list;
+                       while (!list_empty(p)) {
+                               slave_mnt = list_first_entry(p,
+                                               struct mount, mnt_slave);
+                               list_del_init(&slave_mnt->mnt_slave);
+                               slave_mnt->mnt_master = NULL;
+                       }
+                       return 0;
+               }
        } else {
-               struct list_head *p = &mnt->mnt_slave_list;
-               while (!list_empty(p)) {
-                        slave_mnt = list_first_entry(p,
-                                       struct mount, mnt_slave);
-                       list_del_init(&slave_mnt->mnt_slave);
-                       slave_mnt->mnt_master = NULL;
+               struct mount *m;
+               /*
+                * slave 'mnt' to a peer mount that has the
+                * same root dentry. If none is available then
+                * slave it to anything that is available.
+                */
+               for (m = master = next_peer(mnt); m != mnt; m = next_peer(m)) {
+                       if (m->mnt.mnt_root == mnt->mnt.mnt_root) {
+                               master = m;
+                               break;
+                       }
                }
+               list_del_init(&mnt->mnt_share);
+               mnt->mnt_group_id = 0;
+               CLEAR_MNT_SHARED(mnt);
        }
+       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);
        mnt->mnt_master = master;
-       CLEAR_MNT_SHARED(mnt);
        return 0;
 }
 
@@ -324,6 +322,21 @@ out:
        return ret;
 }
 
+static struct mount *find_topper(struct mount *mnt)
+{
+       /* If there is exactly one mount covering mnt completely return it. */
+       struct mount *child;
+
+       if (!list_is_singular(&mnt->mnt_mounts))
+               return NULL;
+
+       child = list_first_entry(&mnt->mnt_mounts, struct mount, mnt_child);
+       if (child->mnt_mountpoint != mnt->mnt.mnt_root)
+               return NULL;
+
+       return child;
+}
+
 /*
  * return true if the refcount is greater than count
  */
@@ -344,9 +357,8 @@ static inline int do_refcount_check(struct mount *mnt, int count)
  */
 int propagate_mount_busy(struct mount *mnt, int refcnt)
 {
-       struct mount *m, *child;
+       struct mount *m, *child, *topper;
        struct mount *parent = mnt->mnt_parent;
-       int ret = 0;
 
        if (mnt == parent)
                return do_refcount_check(mnt, refcnt);
@@ -361,12 +373,24 @@ int propagate_mount_busy(struct mount *mnt, int refcnt)
 
        for (m = propagation_next(parent, parent); m;
                        m = propagation_next(m, parent)) {
-               child = __lookup_mnt_last(&m->mnt, mnt->mnt_mountpoint);
-               if (child && list_empty(&child->mnt_mounts) &&
-                   (ret = do_refcount_check(child, 1)))
-                       break;
+               int count = 1;
+               child = __lookup_mnt(&m->mnt, mnt->mnt_mountpoint);
+               if (!child)
+                       continue;
+
+               /* Is there exactly one mount on the child that covers
+                * it completely whose reference should be ignored?
+                */
+               topper = find_topper(child);
+               if (topper)
+                       count += 1;
+               else if (!list_empty(&child->mnt_mounts))
+                       continue;
+
+               if (do_refcount_check(child, count))
+                       return 1;
        }
-       return ret;
+       return 0;
 }
 
 /*
@@ -383,7 +407,7 @@ void propagate_mount_unlock(struct mount *mnt)
 
        for (m = propagation_next(parent, parent); m;
                        m = propagation_next(m, parent)) {
-               child = __lookup_mnt_last(&m->mnt, mnt->mnt_mountpoint);
+               child = __lookup_mnt(&m->mnt, mnt->mnt_mountpoint);
                if (child)
                        child->mnt.mnt_flags &= ~MNT_LOCKED;
        }
@@ -401,9 +425,11 @@ static void mark_umount_candidates(struct mount *mnt)
 
        for (m = propagation_next(parent, parent); m;
                        m = propagation_next(m, parent)) {
-               struct mount *child = __lookup_mnt_last(&m->mnt,
+               struct mount *child = __lookup_mnt(&m->mnt,
                                                mnt->mnt_mountpoint);
-               if (child && (!IS_MNT_LOCKED(child) || IS_MNT_MARKED(m))) {
+               if (!child || (child->mnt.mnt_flags & MNT_UMOUNT))
+                       continue;
+               if (!IS_MNT_LOCKED(child) || IS_MNT_MARKED(m)) {
                        SET_MNT_MARK(child);
                }
        }
@@ -422,8 +448,8 @@ static void __propagate_umount(struct mount *mnt)
 
        for (m = propagation_next(parent, parent); m;
                        m = propagation_next(m, parent)) {
-
-               struct mount *child = __lookup_mnt_last(&m->mnt,
+               struct mount *topper;
+               struct mount *child = __lookup_mnt(&m->mnt,
                                                mnt->mnt_mountpoint);
                /*
                 * umount the child only if the child has no children
@@ -432,6 +458,15 @@ static void __propagate_umount(struct mount *mnt)
                if (!child || !IS_MNT_MARKED(child))
                        continue;
                CLEAR_MNT_MARK(child);
+
+               /* If there is exactly one mount covering all of child
+                * replace child with that mount.
+                */
+               topper = find_topper(child);
+               if (topper)
+                       mnt_change_mountpoint(child->mnt_parent, child->mnt_mp,
+                                             topper);
+
                if (list_empty(&child->mnt_mounts)) {
                        list_del_init(&child->mnt_child);
                        child->mnt.mnt_flags |= MNT_UMOUNT;