Commit 09dd17d3 authored by Miklos Szeredi's avatar Miklos Szeredi Committed by Linus Torvalds

[PATCH] namei cleanup

Extract common code into inline functions to make reading easier.
Signed-off-by: default avatarMiklos Szeredi <miklos@szeredi.hu>
Cc: <viro@parcelfarce.linux.theplanet.co.uk>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent e89bbd3a
...@@ -525,6 +525,22 @@ static inline int __do_follow_link(struct path *path, struct nameidata *nd) ...@@ -525,6 +525,22 @@ static inline int __do_follow_link(struct path *path, struct nameidata *nd)
return error; return error;
} }
static inline void dput_path(struct path *path, struct nameidata *nd)
{
dput(path->dentry);
if (path->mnt != nd->mnt)
mntput(path->mnt);
}
static inline void path_to_nameidata(struct path *path, struct nameidata *nd)
{
dput(nd->dentry);
if (nd->mnt != path->mnt)
mntput(nd->mnt);
nd->mnt = path->mnt;
nd->dentry = path->dentry;
}
/* /*
* This limits recursive symlink follows to 8, while * This limits recursive symlink follows to 8, while
* limiting consecutive symlinks to 40. * limiting consecutive symlinks to 40.
...@@ -552,9 +568,7 @@ static inline int do_follow_link(struct path *path, struct nameidata *nd) ...@@ -552,9 +568,7 @@ static inline int do_follow_link(struct path *path, struct nameidata *nd)
nd->depth--; nd->depth--;
return err; return err;
loop: loop:
dput(path->dentry); dput_path(path, nd);
if (path->mnt != nd->mnt)
mntput(path->mnt);
path_release(nd); path_release(nd);
return err; return err;
} }
...@@ -813,13 +827,8 @@ static fastcall int __link_path_walk(const char * name, struct nameidata *nd) ...@@ -813,13 +827,8 @@ static fastcall int __link_path_walk(const char * name, struct nameidata *nd)
err = -ENOTDIR; err = -ENOTDIR;
if (!inode->i_op) if (!inode->i_op)
break; break;
} else { } else
dput(nd->dentry); path_to_nameidata(&next, nd);
if (nd->mnt != next.mnt)
mntput(nd->mnt);
nd->mnt = next.mnt;
nd->dentry = next.dentry;
}
err = -ENOTDIR; err = -ENOTDIR;
if (!inode->i_op->lookup) if (!inode->i_op->lookup)
break; break;
...@@ -859,13 +868,8 @@ last_component: ...@@ -859,13 +868,8 @@ last_component:
if (err) if (err)
goto return_err; goto return_err;
inode = nd->dentry->d_inode; inode = nd->dentry->d_inode;
} else { } else
dput(nd->dentry); path_to_nameidata(&next, nd);
if (nd->mnt != next.mnt)
mntput(nd->mnt);
nd->mnt = next.mnt;
nd->dentry = next.dentry;
}
err = -ENOENT; err = -ENOENT;
if (!inode) if (!inode)
break; break;
...@@ -901,9 +905,7 @@ return_reval: ...@@ -901,9 +905,7 @@ return_reval:
return_base: return_base:
return 0; return 0;
out_dput: out_dput:
dput(next.dentry); dput_path(&next, nd);
if (nd->mnt != next.mnt)
mntput(next.mnt);
break; break;
} }
path_release(nd); path_release(nd);
...@@ -1507,11 +1509,7 @@ do_last: ...@@ -1507,11 +1509,7 @@ do_last:
if (path.dentry->d_inode->i_op && path.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; goto do_link;
dput(nd->dentry); path_to_nameidata(&path, nd);
nd->dentry = path.dentry;
if (nd->mnt != path.mnt)
mntput(nd->mnt);
nd->mnt = path.mnt;
error = -EISDIR; error = -EISDIR;
if (path.dentry->d_inode && S_ISDIR(path.dentry->d_inode->i_mode)) if (path.dentry->d_inode && S_ISDIR(path.dentry->d_inode->i_mode))
goto exit; goto exit;
...@@ -1522,9 +1520,7 @@ ok: ...@@ -1522,9 +1520,7 @@ ok:
return 0; return 0;
exit_dput: exit_dput:
dput(path.dentry); dput_path(&path, nd);
if (nd->mnt != path.mnt)
mntput(path.mnt);
exit: exit:
path_release(nd); path_release(nd);
return error; return error;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment