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.
Unified · Split
| @@ -1725,7 +1725,7 @@ static int pick_link(struct nameidata *nd, struct path *link, · 1724 unmodified lines | ||
| 1725 | 1725 | return 1; |
| 1726 | 1726 | } |
| 1727 | 1727 | |
| 1728 | −enum {WALK_GET = 1, WALK_MORE = 2}; | |
| 1728 | +enum {WALK_FOLLOW = 1, WALK_MORE = 2}; | |
| 1729 | 1729 | |
| 1730 | 1730 | /* |
| 1731 | 1731 | * 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 | ||
| 1733 | 1733 | * so we keep a cache of "no, this doesn't need follow_link" |
| 1734 | 1734 | * for the common case. |
| 1735 | 1735 | */ |
| 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) | |
| 1739 | 1738 | { |
| 1740 | 1739 | if (!(flags & WALK_MORE) && nd->depth) |
| 1741 | 1740 | 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; | |
| 1745 | 1747 | return 0; |
| 1748 | + } | |
| 1746 | 1749 | /* make sure that d_is_symlink above matches inode */ |
| 1747 | 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 | 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 | |
| 1754 | 1757 | 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 | ||
| 1791 | 1794 | inode = d_backing_inode(path.dentry); |
| 1792 | 1795 | } |
| 1793 | 1796 | |
| 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); | |
| 1801 | 1798 | } |
| 1802 | 1799 | |
| 1803 | 1800 | /* |
| @@ -2104,10 +2101,10 @@ OK: · 300 unmodified lines | ||
| 2104 | 2101 | if (!name) |
| 2105 | 2102 | return 0; |
| 2106 | 2103 | /* last component of nested symlink */ |
| 2107 | − err = walk_component(nd, WALK_GET); | |
| 2104 | + err = walk_component(nd, WALK_FOLLOW); | |
| 2108 | 2105 | } else { |
| 2109 | 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 | 2109 | if (err < 0) |
| 2113 | 2110 | return err; |
| @@ -2617,12 +2614,7 @@ mountpoint_last(struct nameidata *nd) · 503 unmodified lines | ||
| 2617 | 2614 | return -ENOENT; |
| 2618 | 2615 | } |
| 2619 | 2616 | 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); | |
| 2626 | 2618 | } |
| 2627 | 2619 | |
| 2628 | 2620 | /** |
| @@ -3311,15 +3303,11 @@ static int do_last(struct nameidata *nd, · 682 unmodified lines | ||
| 3311 | 3303 | seq = 0; /* out of RCU mode, so the value doesn't matter */ |
| 3312 | 3304 | inode = d_backing_inode(path.dentry); |
| 3313 | 3305 | finish_lookup: |
| 3314 | − error = should_follow_link(nd, &path, 0, inode, seq); | |
| 3306 | + error = step_into(nd, &path, 0, inode, seq); | |
| 3315 | 3307 | if (unlikely(error)) |
| 3316 | 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... */ | |
| 3322 | 3309 | finish_open: |
| 3310 | + /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */ | |
| 3323 | 3311 | error = complete_walk(nd); |
| 3324 | 3312 | if (error) |
| 3325 | 3313 | return error; |