lkml.org 
[lkml]   [2015]   [Apr]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 21/24] namei: regularize use of put_link() and follow_link(), trim arguments
Date
From: Al Viro <viro@zeniv.linux.org.uk>

don't bother with separate variables for link and cookie in trailing
symlink loops; use nd->stack[0] for that. That makes *all* callers
of put_link() (and follow_link()) operate on nd->stack[nd->depth].link
and nd->stack[nd->depth].cookie. Trim the argument lists.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
fs/namei.c | 42 ++++++++++++++++++++----------------------
1 file changed, 20 insertions(+), 22 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index 1c967d1..a8d6751 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -752,12 +752,14 @@ static inline char *nd_get_link(struct nameidata *nd)
return nd->stack[nd->depth].body;
}

-static inline void put_link(struct nameidata *nd, struct path *link, void *cookie)
+static inline void put_link(struct nameidata *nd)
{
- struct inode *inode = link->dentry->d_inode;
+ struct saved *last = nd->stack + nd->depth;
+ struct inode *inode = last->link.dentry->d_inode;
if (inode->i_op->put_link)
- inode->i_op->put_link(link->dentry, nd_get_link(nd), cookie);
- path_put(link);
+ inode->i_op->put_link(last->link.dentry, last->body,
+ last->cookie);
+ path_put(&last->link);
}

int sysctl_protected_symlinks __read_mostly = 0;
@@ -925,14 +927,16 @@ out:
return res;
}

-static int follow_link(struct path *link, struct nameidata *nd, void **p)
+static int follow_link(struct nameidata *nd, struct path *link)
{
char *s;
int error = may_follow_link(link, nd);
+ struct saved *last = nd->stack + nd->depth;
if (unlikely(error))
return error;
nd->flags |= LOOKUP_PARENT;
- s = get_link(link, nd, p);
+ last->link = *link;
+ s = get_link(&last->link, nd, &last->cookie);
if (unlikely(IS_ERR(s)))
return PTR_ERR(s);
if (unlikely(!s))
@@ -948,7 +952,7 @@ static int follow_link(struct path *link, struct nameidata *nd, void **p)
nd->inode = nd->path.dentry->d_inode;
error = link_path_walk(s, nd);
if (unlikely(error))
- put_link(nd, link, *p);
+ put_link(nd);
return error;
}

@@ -1869,7 +1873,7 @@ Walked:
err = 0;
if (unlikely(!s)) {
/* jumped */
- put_link(nd, &last->link, last->cookie);
+ put_link(nd);
nd->link_count--;
nd->depth--;
last--;
@@ -1900,7 +1904,7 @@ Walked:
terminate_walk(nd);
Err:
while (unlikely(nd->depth)) {
- put_link(nd, &last->link, last->cookie);
+ put_link(nd);
nd->link_count--;
nd->depth--;
last--;
@@ -1910,7 +1914,7 @@ OK:
if (unlikely(nd->depth)) {
name = last->name;
err = walk_component(nd, &next, LOOKUP_FOLLOW);
- put_link(nd, &last->link, last->cookie);
+ put_link(nd);
nd->link_count--;
nd->depth--;
last--;
@@ -2065,13 +2069,11 @@ static int path_lookupat(int dfd, const struct filename *name,
if (!err && !(flags & LOOKUP_PARENT)) {
err = lookup_last(nd, &path);
while (err > 0) {
- void *cookie;
- struct path link = path;
- err = follow_link(&link, nd, &cookie);
+ err = follow_link(nd, &path);
if (err)
break;
err = lookup_last(nd, &path);
- put_link(nd, &link, cookie);
+ put_link(nd);
}
}

@@ -2426,13 +2428,11 @@ path_mountpoint(int dfd, const struct filename *name, struct path *path,

err = mountpoint_last(&nd, path);
while (err > 0) {
- void *cookie;
- struct path link = *path;
- err = follow_link(&link, &nd, &cookie);
+ err = follow_link(&nd, path);
if (err)
break;
err = mountpoint_last(&nd, path);
- put_link(&nd, &link, cookie);
+ put_link(&nd);
}
out:
path_cleanup(&nd);
@@ -3310,8 +3310,6 @@ static struct file *path_openat(int dfd, struct filename *pathname,

error = do_last(nd, &path, file, op, &opened, pathname);
while (unlikely(error > 0)) { /* trailing symlink */
- struct path link = path;
- void *cookie;
if (!(nd->flags & LOOKUP_FOLLOW)) {
path_put_conditional(&path, nd);
path_put(&nd->path);
@@ -3319,11 +3317,11 @@ static struct file *path_openat(int dfd, struct filename *pathname,
break;
}
nd->flags &= ~(LOOKUP_OPEN|LOOKUP_CREATE|LOOKUP_EXCL);
- error = follow_link(&link, nd, &cookie);
+ error = follow_link(nd, &path);
if (unlikely(error))
break;
error = do_last(nd, &path, file, op, &opened, pathname);
- put_link(nd, &link, cookie);
+ put_link(nd);
}
out:
path_cleanup(nd);
--
2.1.4


\
 
 \ /
  Last update: 2015-04-20 20:21    [W:0.665 / U:1.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site