]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/namei.c
[PATCH] autofs4: post expire race fix
[linux-2.6-omap-h63xx.git] / fs / namei.c
index 37fcf941fa3f92c4627dbc07c9ff5d76bb8cd338..a7f7f44119b3dda8e18a3de1e23990eb4f3ffb05 100644 (file)
@@ -503,10 +503,11 @@ static inline int __do_follow_link(struct path *path, struct nameidata *nd)
        int error;
        struct dentry *dentry = path->dentry;
 
-       touch_atime(nd->mnt, dentry);
+       touch_atime(path->mnt, dentry);
        nd_set_link(nd, NULL);
 
-       mntget(path->mnt);
+       if (path->mnt == nd->mnt)
+               mntget(path->mnt);
        error = dentry->d_inode->i_op->follow_link(dentry, nd);
        if (!error) {
                char *s = nd_get_link(nd);
@@ -549,6 +550,8 @@ static inline int do_follow_link(struct path *path, struct nameidata *nd)
        return err;
 loop:
        dput(path->dentry);
+       if (path->mnt != nd->mnt)
+               mntput(path->mnt);
        path_release(nd);
        return err;
 }
@@ -593,20 +596,17 @@ static int __follow_mount(struct path *path)
        return res;
 }
 
-static int follow_mount(struct vfsmount **mnt, struct dentry **dentry)
+static void follow_mount(struct vfsmount **mnt, struct dentry **dentry)
 {
-       int res = 0;
        while (d_mountpoint(*dentry)) {
                struct vfsmount *mounted = lookup_mnt(*mnt, *dentry);
                if (!mounted)
                        break;
+               dput(*dentry);
                mntput(*mnt);
                *mnt = mounted;
-               dput(*dentry);
                *dentry = dget(mounted->mnt_root);
-               res = 1;
        }
-       return res;
 }
 
 /* no need for dcache_lock, as serialization is taken care in
@@ -627,41 +627,41 @@ int follow_down(struct vfsmount **mnt, struct dentry **dentry)
        return 0;
 }
 
-static inline void follow_dotdot(struct vfsmount **mnt, struct dentry **dentry)
+static inline void follow_dotdot(struct nameidata *nd)
 {
        while(1) {
                struct vfsmount *parent;
-               struct dentry *old = *dentry;
+               struct dentry *old = nd->dentry;
 
                 read_lock(&current->fs->lock);
-               if (*dentry == current->fs->root &&
-                   *mnt == current->fs->rootmnt) {
+               if (nd->dentry == current->fs->root &&
+                   nd->mnt == current->fs->rootmnt) {
                         read_unlock(&current->fs->lock);
                        break;
                }
                 read_unlock(&current->fs->lock);
                spin_lock(&dcache_lock);
-               if (*dentry != (*mnt)->mnt_root) {
-                       *dentry = dget((*dentry)->d_parent);
+               if (nd->dentry != nd->mnt->mnt_root) {
+                       nd->dentry = dget(nd->dentry->d_parent);
                        spin_unlock(&dcache_lock);
                        dput(old);
                        break;
                }
                spin_unlock(&dcache_lock);
                spin_lock(&vfsmount_lock);
-               parent = (*mnt)->mnt_parent;
-               if (parent == *mnt) {
+               parent = nd->mnt->mnt_parent;
+               if (parent == nd->mnt) {
                        spin_unlock(&vfsmount_lock);
                        break;
                }
                mntget(parent);
-               *dentry = dget((*mnt)->mnt_mountpoint);
+               nd->dentry = dget(nd->mnt->mnt_mountpoint);
                spin_unlock(&vfsmount_lock);
                dput(old);
-               mntput(*mnt);
-               *mnt = parent;
+               mntput(nd->mnt);
+               nd->mnt = parent;
        }
-       follow_mount(mnt, dentry);
+       follow_mount(&nd->mnt, &nd->dentry);
 }
 
 /*
@@ -682,6 +682,7 @@ static int do_lookup(struct nameidata *nd, struct qstr *name,
 done:
        path->mnt = mnt;
        path->dentry = dentry;
+       __follow_mount(path);
        return 0;
 
 need_lookup:
@@ -769,7 +770,7 @@ static fastcall int __link_path_walk(const char * name, struct nameidata *nd)
                        case 2: 
                                if (this.name[1] != '.')
                                        break;
-                               follow_dotdot(&nd->mnt, &nd->dentry);
+                               follow_dotdot(nd);
                                inode = nd->dentry->d_inode;
                                /* fallthrough */
                        case 1:
@@ -789,8 +790,6 @@ static fastcall int __link_path_walk(const char * name, struct nameidata *nd)
                err = do_lookup(nd, &this, &next);
                if (err)
                        break;
-               /* Check mountpoints.. */
-               __follow_mount(&next);
 
                err = -ENOENT;
                inode = next.dentry->d_inode;
@@ -801,8 +800,6 @@ static fastcall int __link_path_walk(const char * name, struct nameidata *nd)
                        goto out_dput;
 
                if (inode->i_op->follow_link) {
-                       if (nd->mnt != next.mnt)
-                               mntput(nd->mnt);
                        err = do_follow_link(&next, nd);
                        if (err)
                                goto return_err;
@@ -838,7 +835,7 @@ last_component:
                        case 2: 
                                if (this.name[1] != '.')
                                        break;
-                               follow_dotdot(&nd->mnt, &nd->dentry);
+                               follow_dotdot(nd);
                                inode = nd->dentry->d_inode;
                                /* fallthrough */
                        case 1:
@@ -852,12 +849,9 @@ last_component:
                err = do_lookup(nd, &this, &next);
                if (err)
                        break;
-               __follow_mount(&next);
                inode = next.dentry->d_inode;
                if ((lookup_flags & LOOKUP_FOLLOW)
                    && inode && inode->i_op && inode->i_op->follow_link) {
-                       if (next.mnt != nd->mnt)
-                               mntput(nd->mnt);
                        err = do_follow_link(&next, nd);
                        if (err)
                                goto return_err;
@@ -906,7 +900,7 @@ return_base:
 out_dput:
                dput(next.dentry);
                if (nd->mnt != next.mnt)
-                       mntput(nd->mnt);
+                       mntput(next.mnt);
                break;
        }
        path_release(nd);
@@ -1501,11 +1495,8 @@ do_last:
 
        if (__follow_mount(&path)) {
                error = -ELOOP;
-               if (flag & O_NOFOLLOW) {
-                       dput(path.dentry);
-                       mntput(path.mnt);
-                       goto exit;
-               }
+               if (flag & O_NOFOLLOW)
+                       goto exit_dput;
        }
        error = -ENOENT;
        if (!path.dentry->d_inode)
@@ -1530,8 +1521,7 @@ ok:
 exit_dput:
        dput(path.dentry);
        if (nd->mnt != path.mnt)
-               mntput(nd->mnt);
-       nd->mnt = path.mnt;
+               mntput(path.mnt);
 exit:
        path_release(nd);
        return error;
@@ -1554,9 +1544,6 @@ do_link:
        error = security_inode_follow_link(path.dentry, nd);
        if (error)
                goto exit_dput;
-       if (nd->mnt != path.mnt)
-               mntput(nd->mnt);
-       nd->mnt = path.mnt;
        error = __do_follow_link(&path, nd);
        if (error)
                return error;