]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/namei.c
[PATCH] namei fixes (5/19)
[linux-2.6-omap-h63xx.git] / fs / namei.c
index 0f76fd75591bd0d5c3fbf44a2540519a972a44a2..020fb8c8d1cddb85b8b10714658b05774af9015c 100644 (file)
@@ -493,6 +493,11 @@ fail:
        return PTR_ERR(link);
 }
 
+struct path {
+       struct vfsmount *mnt;
+       struct dentry *dentry;
+};
+
 static inline int __do_follow_link(struct dentry *dentry, struct nameidata *nd)
 {
        int error;
@@ -518,27 +523,32 @@ static inline int __do_follow_link(struct dentry *dentry, struct nameidata *nd)
  * Without that kind of total limit, nasty chains of consecutive
  * symlinks can cause almost arbitrarily long lookups. 
  */
-static inline int do_follow_link(struct dentry *dentry, struct nameidata *nd)
+static inline int do_follow_link(struct path *path, struct nameidata *nd)
 {
        int err = -ELOOP;
+       mntget(path->mnt);
        if (current->link_count >= MAX_NESTED_LINKS)
                goto loop;
        if (current->total_link_count >= 40)
                goto loop;
        BUG_ON(nd->depth >= MAX_NESTED_LINKS);
        cond_resched();
-       err = security_inode_follow_link(dentry, nd);
+       err = security_inode_follow_link(path->dentry, nd);
        if (err)
                goto loop;
        current->link_count++;
        current->total_link_count++;
        nd->depth++;
-       err = __do_follow_link(dentry, nd);
+       err = __do_follow_link(path->dentry, nd);
        current->link_count--;
        nd->depth--;
+       dput(path->dentry);
+       mntput(path->mnt);
        return err;
 loop:
        path_release(nd);
+       dput(path->dentry);
+       mntput(path->mnt);
        return err;
 }
 
@@ -641,11 +651,6 @@ static inline void follow_dotdot(struct vfsmount **mnt, struct dentry **dentry)
        follow_mount(mnt, dentry);
 }
 
-struct path {
-       struct vfsmount *mnt;
-       struct dentry *dentry;
-};
-
 /*
  *  It's more convoluted than I'd like it to be, but... it's still fairly
  *  small and for now I'd prefer to have fast path as straight as possible.
@@ -783,10 +788,7 @@ static fastcall int __link_path_walk(const char * name, struct nameidata *nd)
                        goto out_dput;
 
                if (inode->i_op->follow_link) {
-                       mntget(next.mnt);
-                       err = do_follow_link(next.dentry, nd);
-                       dput(next.dentry);
-                       mntput(next.mnt);
+                       err = do_follow_link(&next, nd);
                        if (err)
                                goto return_err;
                        err = -ENOENT;
@@ -837,10 +839,7 @@ last_component:
                inode = next.dentry->d_inode;
                if ((lookup_flags & LOOKUP_FOLLOW)
                    && inode && inode->i_op && inode->i_op->follow_link) {
-                       mntget(next.mnt);
-                       err = do_follow_link(next.dentry, nd);
-                       dput(next.dentry);
-                       mntput(next.mnt);
+                       err = do_follow_link(&next, nd);
                        if (err)
                                goto return_err;
                        inode = nd->dentry->d_inode;
@@ -1398,7 +1397,7 @@ int may_open(struct nameidata *nd, int acc_mode, int flag)
 int open_namei(const char * pathname, int flag, int mode, struct nameidata *nd)
 {
        int acc_mode, error = 0;
-       struct dentry *dentry;
+       struct path path;
        struct dentry *dir;
        int count = 0;
 
@@ -1442,23 +1441,24 @@ int open_namei(const char * pathname, int flag, int mode, struct nameidata *nd)
        dir = nd->dentry;
        nd->flags &= ~LOOKUP_PARENT;
        down(&dir->d_inode->i_sem);
-       dentry = __lookup_hash(&nd->last, nd->dentry, nd);
+       path.dentry = __lookup_hash(&nd->last, nd->dentry, nd);
+       path.mnt = nd->mnt;
 
 do_last:
-       error = PTR_ERR(dentry);
-       if (IS_ERR(dentry)) {
+       error = PTR_ERR(path.dentry);
+       if (IS_ERR(path.dentry)) {
                up(&dir->d_inode->i_sem);
                goto exit;
        }
 
        /* Negative dentry, just create the file */
-       if (!dentry->d_inode) {
+       if (!path.dentry->d_inode) {
                if (!IS_POSIXACL(dir->d_inode))
                        mode &= ~current->fs->umask;
-               error = vfs_create(dir->d_inode, dentry, mode, nd);
+               error = vfs_create(dir->d_inode, path.dentry, mode, nd);
                up(&dir->d_inode->i_sem);
                dput(nd->dentry);
-               nd->dentry = dentry;
+               nd->dentry = path.dentry;
                if (error)
                        goto exit;
                /* Don't check for write permission, don't truncate */
@@ -1476,22 +1476,23 @@ do_last:
        if (flag & O_EXCL)
                goto exit_dput;
 
-       if (d_mountpoint(dentry)) {
+       if (d_mountpoint(path.dentry)) {
                error = -ELOOP;
                if (flag & O_NOFOLLOW)
                        goto exit_dput;
-               while (__follow_down(&nd->mnt,&dentry) && d_mountpoint(dentry));
+               while (__follow_down(&path.mnt,&path.dentry) && d_mountpoint(path.dentry));
+               nd->mnt = path.mnt;
        }
        error = -ENOENT;
-       if (!dentry->d_inode)
+       if (!path.dentry->d_inode)
                goto exit_dput;
-       if (dentry->d_inode->i_op && dentry->d_inode->i_op->follow_link)
+       if (path.dentry->d_inode->i_op && path.dentry->d_inode->i_op->follow_link)
                goto do_link;
 
        dput(nd->dentry);
-       nd->dentry = dentry;
+       nd->dentry = path.dentry;
        error = -EISDIR;
-       if (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))
+       if (path.dentry->d_inode && S_ISDIR(path.dentry->d_inode->i_mode))
                goto exit;
 ok:
        error = may_open(nd, acc_mode, flag);
@@ -1500,7 +1501,7 @@ ok:
        return 0;
 
 exit_dput:
-       dput(dentry);
+       dput(path.dentry);
 exit:
        path_release(nd);
        return error;
@@ -1520,16 +1521,19 @@ do_link:
         * are done. Procfs-like symlinks just set LAST_BIND.
         */
        nd->flags |= LOOKUP_PARENT;
-       error = security_inode_follow_link(dentry, nd);
+       error = security_inode_follow_link(path.dentry, nd);
        if (error)
                goto exit_dput;
-       error = __do_follow_link(dentry, nd);
-       dput(dentry);
+       mntget(path.mnt);
+       error = __do_follow_link(path.dentry, nd);
+       dput(path.dentry);
+       mntput(path.mnt);
+       path.mnt = nd->mnt;
        if (error)
                return error;
        nd->flags &= ~LOOKUP_PARENT;
        if (nd->last_type == LAST_BIND) {
-               dentry = nd->dentry;
+               path.dentry = nd->dentry;
                goto ok;
        }
        error = -EISDIR;
@@ -1546,7 +1550,7 @@ do_link:
        }
        dir = nd->dentry;
        down(&dir->d_inode->i_sem);
-       dentry = __lookup_hash(&nd->last, nd->dentry, nd);
+       path.dentry = __lookup_hash(&nd->last, nd->dentry, nd);
        putname(nd->last.name);
        goto do_last;
 }
@@ -1580,6 +1584,7 @@ enoent:
 fail:
        return dentry;
 }
+EXPORT_SYMBOL_GPL(lookup_create);
 
 int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
 {
@@ -2071,8 +2076,8 @@ exit:
  *        ->i_sem on parents, which works but leads to some truely excessive
  *        locking].
  */
-int vfs_rename_dir(struct inode *old_dir, struct dentry *old_dentry,
-              struct inode *new_dir, struct dentry *new_dentry)
+static int vfs_rename_dir(struct inode *old_dir, struct dentry *old_dentry,
+                         struct inode *new_dir, struct dentry *new_dentry)
 {
        int error = 0;
        struct inode *target;
@@ -2116,8 +2121,8 @@ int vfs_rename_dir(struct inode *old_dir, struct dentry *old_dentry,
        return error;
 }
 
-int vfs_rename_other(struct inode *old_dir, struct dentry *old_dentry,
-              struct inode *new_dir, struct dentry *new_dentry)
+static int vfs_rename_other(struct inode *old_dir, struct dentry *old_dentry,
+                           struct inode *new_dir, struct dentry *new_dentry)
 {
        struct inode *target;
        int error;