aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2016-11-14 01:50:26 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2016-12-05 19:11:58 -0500
commit8f64fb1ccef331077a96cbfc3c23f91cbe563fd0 (patch)
tree7beb8dc566ef1fb70abe82b7ea817efc677b8367
parent31d66bcd3f197d135145afb268996b4f5ea83459 (diff)
namei: fold should_follow_link() with the step into not-followed link
All callers are followed by the same boilerplate - "if it has returned 0, update nd->path/inode/seq - we are not following a symlink here". Pull it into the function itself, renaming it into step_into(). Rename WALK_GET to WALK_FOLLOW, while we are at it - more descriptive name. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--fs/namei.c48
1 files changed, 18 insertions, 30 deletions
diff --git a/fs/namei.c b/fs/namei.c
index 5d31f0b2006d..092ac5667ec7 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1725,7 +1725,7 @@ static int pick_link(struct nameidata *nd, struct path *link,
1725 return 1; 1725 return 1;
1726} 1726}
1727 1727
1728enum {WALK_GET = 1, WALK_MORE = 2}; 1728enum {WALK_FOLLOW = 1, WALK_MORE = 2};
1729 1729
1730/* 1730/*
1731 * Do we need to follow links? We _really_ want to be able 1731 * Do we need to follow links? We _really_ want to be able
@@ -1733,22 +1733,25 @@ enum {WALK_GET = 1, WALK_MORE = 2};
1733 * so we keep a cache of "no, this doesn't need follow_link" 1733 * so we keep a cache of "no, this doesn't need follow_link"
1734 * for the common case. 1734 * for the common case.
1735 */ 1735 */
1736static inline int should_follow_link(struct nameidata *nd, struct path *link, 1736static inline int step_into(struct nameidata *nd, struct path *path,
1737 int flags, 1737 int flags, struct inode *inode, unsigned seq)
1738 struct inode *inode, unsigned seq)
1739{ 1738{
1740 if (!(flags & WALK_MORE) && nd->depth) 1739 if (!(flags & WALK_MORE) && nd->depth)
1741 put_link(nd); 1740 put_link(nd);
1742 if (likely(!d_is_symlink(link->dentry))) 1741 if (likely(!d_is_symlink(path->dentry)) ||
1743 return 0; 1742 !(flags & WALK_FOLLOW || nd->flags & LOOKUP_FOLLOW)) {
1744 if (!(flags & WALK_GET) && !(nd->flags & LOOKUP_FOLLOW)) 1743 /* not a symlink or should not follow */
1744 path_to_nameidata(path, nd);
1745 nd->inode = inode;
1746 nd->seq = seq;
1745 return 0; 1747 return 0;
1748 }
1746 /* make sure that d_is_symlink above matches inode */ 1749 /* make sure that d_is_symlink above matches inode */
1747 if (nd->flags & LOOKUP_RCU) { 1750 if (nd->flags & LOOKUP_RCU) {
1748 if (read_seqcount_retry(&link->dentry->d_seq, seq)) 1751 if (read_seqcount_retry(&path->dentry->d_seq, seq))
1749 return -ECHILD; 1752 return -ECHILD;
1750 } 1753 }
1751 return pick_link(nd, link, inode, seq); 1754 return pick_link(nd, path, inode, seq);
1752} 1755}
1753 1756
1754static int walk_component(struct nameidata *nd, int flags) 1757static int walk_component(struct nameidata *nd, int flags)
@@ -1791,13 +1794,7 @@ static int walk_component(struct nameidata *nd, int flags)
1791 inode = d_backing_inode(path.dentry); 1794 inode = d_backing_inode(path.dentry);
1792 } 1795 }
1793 1796
1794 err = should_follow_link(nd, &path, flags, inode, seq); 1797 return step_into(nd, &path, flags, inode, seq);
1795 if (unlikely(err))
1796 return err;
1797 path_to_nameidata(&path, nd);
1798 nd->inode = inode;
1799 nd->seq = seq;
1800 return 0;
1801} 1798}
1802 1799
1803/* 1800/*
@@ -2104,10 +2101,10 @@ OK:
2104 if (!name) 2101 if (!name)
2105 return 0; 2102 return 0;
2106 /* last component of nested symlink */ 2103 /* last component of nested symlink */
2107 err = walk_component(nd, WALK_GET); 2104 err = walk_component(nd, WALK_FOLLOW);
2108 } else { 2105 } else {
2109 /* not the last component */ 2106 /* not the last component */
2110 err = walk_component(nd, WALK_GET | WALK_MORE); 2107 err = walk_component(nd, WALK_FOLLOW | WALK_MORE);
2111 } 2108 }
2112 if (err < 0) 2109 if (err < 0)
2113 return err; 2110 return err;
@@ -2617,12 +2614,7 @@ mountpoint_last(struct nameidata *nd)
2617 return -ENOENT; 2614 return -ENOENT;
2618 } 2615 }
2619 path.mnt = nd->path.mnt; 2616 path.mnt = nd->path.mnt;
2620 error = should_follow_link(nd, &path, 0, 2617 return step_into(nd, &path, 0, d_backing_inode(path.dentry), 0);
2621 d_backing_inode(path.dentry), 0);
2622 if (unlikely(error))
2623 return error;
2624 path_to_nameidata(&path, nd);
2625 return 0;
2626} 2618}
2627 2619
2628/** 2620/**
@@ -3311,15 +3303,11 @@ static int do_last(struct nameidata *nd,
3311 seq = 0; /* out of RCU mode, so the value doesn't matter */ 3303 seq = 0; /* out of RCU mode, so the value doesn't matter */
3312 inode = d_backing_inode(path.dentry); 3304 inode = d_backing_inode(path.dentry);
3313finish_lookup: 3305finish_lookup:
3314 error = should_follow_link(nd, &path, 0, inode, seq); 3306 error = step_into(nd, &path, 0, inode, seq);
3315 if (unlikely(error)) 3307 if (unlikely(error))
3316 return error; 3308 return error;
3317
3318 path_to_nameidata(&path, nd);
3319 nd->inode = inode;
3320 nd->seq = seq;
3321 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
3322finish_open: 3309finish_open:
3310 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
3323 error = complete_walk(nd); 3311 error = complete_walk(nd);
3324 if (error) 3312 if (error)
3325 return error; 3313 return error;