History

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.

Al Viro committed 10 years ago

Commit 8f64fb11 parent 31d66bc1 file · +18 −30Browse files

Unified · Split

fs/namei.c+18−30
@@ -1725,7 +1725,7 @@ static int pick_link(struct nameidata *nd, struct path *link, · 1724 unmodified lines
17251725 return 1;
17261726 }
17271727
1728−enum {WALK_GET = 1, WALK_MORE = 2};
1728+enum {WALK_FOLLOW = 1, WALK_MORE = 2};
17291729
17301730 /*
17311731 * Do we need to follow links? We _really_ want to be able
@@ -1733,22 +1733,25 @@ enum {WALK_GET = 1, WALK_MORE = 2}; · 1 unmodified line
17331733 * so we keep a cache of "no, this doesn't need follow_link"
17341734 * for the common case.
17351735 */
1736−static inline int should_follow_link(struct nameidata *nd, struct path *link,
1737− int flags,
1738− struct inode *inode, unsigned seq)
1736+static inline int step_into(struct nameidata *nd, struct path *path,
1737+ int flags, struct inode *inode, unsigned seq)
17391738 {
17401739 if (!(flags & WALK_MORE) && nd->depth)
17411740 put_link(nd);
1742− if (likely(!d_is_symlink(link->dentry)))
1743− return 0;
1744− if (!(flags & WALK_GET) && !(nd->flags & LOOKUP_FOLLOW))
1741+ if (likely(!d_is_symlink(path->dentry)) ||
1742+ !(flags & WALK_FOLLOW || 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;
17451747 return 0;
1748+ }
17461749 /* make sure that d_is_symlink above matches inode */
17471750 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))
17491752 return -ECHILD;
17501753 }
1751− return pick_link(nd, link, inode, seq);
1754+ return pick_link(nd, path, inode, seq);
17521755 }
17531756
17541757 static int walk_component(struct nameidata *nd, int flags)
@@ -1791,13 +1794,7 @@ static int walk_component(struct nameidata *nd, int flags) · 36 unmodified lines
17911794 inode = d_backing_inode(path.dentry);
17921795 }
17931796
1794− err = should_follow_link(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;
1797+ return step_into(nd, &path, flags, inode, seq);
18011798 }
18021799
18031800 /*
@@ -2104,10 +2101,10 @@ OK: · 300 unmodified lines
21042101 if (!name)
21052102 return 0;
21062103 /* last component of nested symlink */
2107− err = walk_component(nd, WALK_GET);
2104+ err = walk_component(nd, WALK_FOLLOW);
21082105 } else {
21092106 /* not the last component */
2110− err = walk_component(nd, WALK_GET | WALK_MORE);
2107+ err = walk_component(nd, WALK_FOLLOW | WALK_MORE);
21112108 }
21122109 if (err < 0)
21132110 return err;
@@ -2617,12 +2614,7 @@ mountpoint_last(struct nameidata *nd) · 503 unmodified lines
26172614 return -ENOENT;
26182615 }
26192616 path.mnt = nd->path.mnt;
2620− error = should_follow_link(nd, &path, 0,
2621− d_backing_inode(path.dentry), 0);
2622− if (unlikely(error))
2623− return error;
2624− path_to_nameidata(&path, nd);
2625− return 0;
2617+ return step_into(nd, &path, 0, d_backing_inode(path.dentry), 0);
26262618 }
26272619
26282620 /**
@@ -3311,15 +3303,11 @@ static int do_last(struct nameidata *nd, · 682 unmodified lines
33113303 seq = 0; /* out of RCU mode, so the value doesn't matter */
33123304 inode = d_backing_inode(path.dentry);
33133305 finish_lookup:
3314− error = should_follow_link(nd, &path, 0, inode, seq);
3306+ error = step_into(nd, &path, 0, inode, seq);
33153307 if (unlikely(error))
33163308 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... */
33223309 finish_open:
3310+ /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
33233311 error = complete_walk(nd);
33243312 if (error)
33253313 return error;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t