vfs: new internal helper: mnt_has_parent(mnt)
authorAl Viro <viro@zeniv.linux.org.uk>
Thu, 24 Nov 2011 00:26:23 +0000 (19:26 -0500)
committerAl Viro <viro@zeniv.linux.org.uk>
Wed, 4 Jan 2012 03:52:36 +0000 (22:52 -0500)
vfsmounts have ->mnt_parent pointing either to a different vfsmount
or to itself; it's never NULL and termination condition in loops
traversing the tree towards root is mnt == mnt->mnt_parent.  At least
one place (see the next patch) is confused about what's going on;
let's add an explicit helper checking it right way and use it in
all places where we need it.  Not that there had been too many,
but...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/dcache.c
fs/mount.h [new file with mode: 0644]
fs/namespace.c
fs/pnode.c
fs/pnode.h

index 89509b5a090e27320e45b9c0c2f5480e082b1a37..8a75e3b0f49dab3e0be51000cc9aedf937647483 100644 (file)
@@ -38,6 +38,7 @@
 #include <linux/prefetch.h>
 #include <linux/ratelimit.h>
 #include "internal.h"
+#include "mount.h"
 
 /*
  * Usage:
@@ -2460,9 +2461,8 @@ static int prepend_path(const struct path *path,
 
                if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
                        /* Global root? */
-                       if (vfsmnt->mnt_parent == vfsmnt) {
+                       if (!mnt_has_parent(vfsmnt))
                                goto global_root;
-                       }
                        dentry = vfsmnt->mnt_mountpoint;
                        vfsmnt = vfsmnt->mnt_parent;
                        continue;
@@ -2862,7 +2862,7 @@ int path_is_under(struct path *path1, struct path *path2)
        br_read_lock(vfsmount_lock);
        if (mnt != path2->mnt) {
                for (;;) {
-                       if (mnt->mnt_parent == mnt) {
+                       if (!mnt_has_parent(mnt)) {
                                br_read_unlock(vfsmount_lock);
                                return 0;
                        }
diff --git a/fs/mount.h b/fs/mount.h
new file mode 100644 (file)
index 0000000..7890e49
--- /dev/null
@@ -0,0 +1,6 @@
+#include <linux/mount.h>
+
+static inline int mnt_has_parent(struct vfsmount *mnt)
+{
+       return mnt != mnt->mnt_parent;
+}
index 31d357450f7fc0bf247bb53afd1f200bd0b3cb2a..ec8512478b04fff1697bd9fb058176f5e67b4144 100644 (file)
@@ -1182,7 +1182,7 @@ void release_mounts(struct list_head *head)
        while (!list_empty(head)) {
                mnt = list_first_entry(head, struct vfsmount, mnt_hash);
                list_del_init(&mnt->mnt_hash);
-               if (mnt->mnt_parent != mnt) {
+               if (mnt_has_parent(mnt)) {
                        struct dentry *dentry;
                        struct vfsmount *m;
 
@@ -1222,7 +1222,7 @@ void umount_tree(struct vfsmount *mnt, int propagate, struct list_head *kill)
                p->mnt_ns = NULL;
                __mnt_make_shortterm(p);
                list_del_init(&p->mnt_child);
-               if (p->mnt_parent != p) {
+               if (mnt_has_parent(p)) {
                        p->mnt_parent->mnt_ghosts++;
                        dentry_reset_mounted(p->mnt_parent, p->mnt_mountpoint);
                }
@@ -1867,7 +1867,7 @@ static int do_move_mount(struct path *path, char *old_name)
        if (old_path.dentry != old_path.mnt->mnt_root)
                goto out1;
 
-       if (old_path.mnt == old_path.mnt->mnt_parent)
+       if (!mnt_has_parent(old_path.mnt))
                goto out1;
 
        if (S_ISDIR(path->dentry->d_inode->i_mode) !=
@@ -1887,7 +1887,7 @@ static int do_move_mount(struct path *path, char *old_name)
            tree_contains_unbindable(old_path.mnt))
                goto out1;
        err = -ELOOP;
-       for (p = path->mnt; p->mnt_parent != p; p = p->mnt_parent)
+       for (p = path->mnt; mnt_has_parent(p); p = p->mnt_parent)
                if (p == old_path.mnt)
                        goto out1;
 
@@ -2604,17 +2604,17 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
        error = -EINVAL;
        if (root.mnt->mnt_root != root.dentry)
                goto out4; /* not a mountpoint */
-       if (root.mnt->mnt_parent == root.mnt)
+       if (!mnt_has_parent(root.mnt))
                goto out4; /* not attached */
        if (new.mnt->mnt_root != new.dentry)
                goto out4; /* not a mountpoint */
-       if (new.mnt->mnt_parent == new.mnt)
+       if (!mnt_has_parent(new.mnt))
                goto out4; /* not attached */
        /* make sure we can reach put_old from new_root */
        tmp = old.mnt;
        if (tmp != new.mnt) {
                for (;;) {
-                       if (tmp->mnt_parent == tmp)
+                       if (!mnt_has_parent(tmp))
                                goto out4; /* already mounted on put_old */
                        if (tmp->mnt_parent == new.mnt)
                                break;
index d42514e32380b5edb38f7985069efe8d8ccc80fa..f1cd958b92e5678044d7fd1ca1b07801b780ef72 100644 (file)
@@ -36,7 +36,7 @@ static inline struct vfsmount *next_slave(struct vfsmount *p)
 static bool is_path_reachable(struct vfsmount *mnt, struct dentry *dentry,
                         const struct path *root)
 {
-       while (mnt != root->mnt && mnt->mnt_parent != mnt) {
+       while (mnt != root->mnt && mnt_has_parent(mnt)) {
                dentry = mnt->mnt_mountpoint;
                mnt = mnt->mnt_parent;
        }
index 391287110274c02e84e142f179da60a381552105..7f0c13ae94841c63361fe19c948a3e5d7fefe2bb 100644 (file)
@@ -9,7 +9,7 @@
 #define _LINUX_PNODE_H
 
 #include <linux/list.h>
-#include <linux/mount.h>
+#include "mount.h"
 
 #define IS_MNT_SHARED(mnt) (mnt->mnt_flags & MNT_SHARED)
 #define IS_MNT_SLAVE(mnt) (mnt->mnt_master)