summaryrefslogtreecommitdiffstats
path: root/fs/namei.c
Commit message (Collapse)AuthorAgeFilesLines
...
* namei: may_follow_link() - lift terminate_walk() on failures into callerAl Viro2015-05-101-2/+3
| | | | Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: take increment of nd->depth into pick_link()Al Viro2015-05-101-7/+4
| | | | | | | | | | Makes the situation much more regular - we avoid a strange state when the element just after the top of stack is used to store struct path of symlink, but isn't counted in nd->depth. This is much more regular, so the normal failure exits, etc., work fine. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: kill nd->linkAl Viro2015-05-101-10/+8
| | | | | | | | Just store it in nd->stack[nd->depth].link right in pick_link(). Now that we make sure of stack expansion in pick_link(), we can do so... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* may_follow_link(): trim argumentsAl Viro2015-05-101-6/+5
| | | | Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: move bumping the refcount of link->mnt into pick_link()Al Viro2015-05-101-5/+4
| | | | | | update the failure cleanup in may_follow_link() to match that. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: fold put_link() into the failure case of complete_walk()Al Viro2015-05-101-23/+6
| | | | | | | | ... and don't open-code unlazy_walk() in there - the only reason for that is to avoid verfication of cached nd->root, which is trivially avoided by discarding said cached nd->root first. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: take the treatment of absolute symlinks to get_link()Al Viro2015-05-101-29/+20
| | | | | | | | | | | rather than letting the callers handle the jump-to-root part of semantics, do it right in get_link() and return the rest of the body for the caller to deal with - at that point it's treated the same way as relative symlinks would be. And return NULL when there's no "rest of the body" - those are treated the same as pure jump symlink would be. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: simpler treatment of symlinks with nothing other that / in the bodyAl Viro2015-05-101-5/+7
| | | | | | | | | | Instead of saving name and branching to OK:, where we'll immediately restore it, and call walk_component() with WALK_PUT|WALK_GET and nd->last_type being LAST_BIND, which is equivalent to put_link(nd), err = 0, we can just treat that the same way we'd treat procfs-style "jump" symlinks - do put_link(nd) and move on. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: simplify failure exits in get_link()Al Viro2015-05-101-8/+4
| | | | | | | | when cookie is NULL, put_link() is equivalent to path_put(), so as soon as we'd set last->cookie to NULL, we can bump nd->depth and let the normal logics in terminate_walk() to take care of cleanups. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* don't pass nameidata to ->follow_link()Al Viro2015-05-101-5/+6
| | | | | | | its only use is getting passed to nd_jump_link(), which can obtain it from current->nameidata Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: simplify the callers of follow_managed()Al Viro2015-05-101-22/+10
| | | | | | | | now that it gets nameidata, no reason to have setting LOOKUP_JUMPED on mountpoint crossing and calling path_put_conditional() on failures done in every caller. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* VFS: replace {, total_}link_count in task_struct with pointer to nameidataNeilBrown2015-05-101-31/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | task_struct currently contains two ad-hoc members for use by the VFS: link_count and total_link_count. These are only interesting to fs/namei.c, so exposing them explicitly is poor layering. Incidentally, link_count isn't used anymore, so it can just die. This patches replaces those with a single pointer to 'struct nameidata'. This structure represents the current filename lookup of which there can only be one per process, and is a natural place to store total_link_count. This will allow the current "nameidata" argument to all follow_link operations to be removed as current->nameidata can be used instead in the _very_ few instances that care about it at all. As there are occasional circumstances where pathname lookup can recurse, such as through kern_path_locked, we always save and old current->nameidata (if there is one) when setting a new value, and make sure any active link_counts are preserved. follow_mount and follow_automount now get a 'struct nameidata *' rather than 'int flags' so that they can directly access total_link_count, rather than going through 'current'. Suggested-by: Al Viro <viro@ZenIV.linux.org.uk> Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: move link count check and stack allocation into pick_link()Al Viro2015-05-101-15/+12
| | | | Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: make should_follow_link() store the link in nd->linkAl Viro2015-05-101-29/+33
| | | | | | ... if it decides to follow, that is. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: new calling conventions for walk_component()Al Viro2015-05-101-10/+20
| | | | | | | | | | | | | | instead of a single flag (!= 0 => we want to follow symlinks) pass two bits - WALK_GET (want to follow symlinks) and WALK_PUT (put_link() once we are done looking at the name). The latter matters only for success exits - on failure the caller will discard everything anyway. Suggestions for better variant are welcome; what this thing aims for is making sure that pending put_link() is done *before* walk_component() decides to pick a symlink up, rather than between picking it up and acting upon it. See the next commit for payoff. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* link_path_walk: move the OK: inside the loopAl Viro2015-05-101-15/+15
| | | | | | | fewer labels that way; in particular, resuming after the end of nested symlink is straight-line. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: have terminate_walk() do put_link() on everything leftAl Viro2015-05-101-8/+2
| | | | | | | | | | All callers of terminate_walk() are followed by more or less open-coded eqiuvalent of "do put_link() on everything left in nd->stack". Better done in terminate_walk() itself, and when we go for RCU symlink traversal we'll have to do it there anyway. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: take put_link() into {lookup,mountpoint,do}_last()Al Viro2015-05-101-13/+21
| | | | | | | | rationale: we'll need to have terminate_walk() do put_link() on everything, which will mean that in some cases ..._last() will do put_link() anyway. Easier to have them do it in all cases. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: lift (open-coded) terminate_walk() into callers of get_link()Al Viro2015-05-101-5/+4
| | | | Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* lift terminate_walk() into callers of walk_component()Al Viro2015-05-101-14/+11
| | | | Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: lift (open-coded) terminate_walk() in follow_dotdot_rcu() into callersAl Viro2015-05-101-9/+10
| | | | | | | | follow_dotdot_rcu() does an equivalent of terminate_walk() on failure; shifting it into callers makes for simpler rules and those callers already have terminate_walk() on other failure exits. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: we never need more than MAXSYMLINKS entries in nd->stackAl Viro2015-05-101-1/+1
| | | | | | | | | | | | The only reason why we needed one more was that purely nested MAXSYMLINKS symlinks could lead to path_init() using that many entries in addition to nd->stack[0] which it left unused. That can't happen now - path_init() starts with entry 0 (and trailing_symlink() is called only when we'd already encountered one symlink, so no more than MAXSYMLINKS-1 are left). Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* link_path_walk: end of nd->depth massageAl Viro2015-05-101-6/+2
| | | | | | | | | | | get rid of orig_depth - we only use it on error exit to tell whether to stop doing put_link() when depth reaches 0 (call from path_init()) or when it reaches 1 (call from trailing_symlink()). However, in the latter case the caller would immediately follow with one more put_link(). Just keep doing it until the depth reaches zero (and simplify trailing_symlink() as the result). Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* link_path_walk: nd->depth massage, part 10Al Viro2015-05-101-7/+10
| | | | | | | | | | | | | | | | | Get rid of orig_depth checks in OK: logics. If nd->depth is zero, we had been called from path_init() and we are done. If it is greater than 1, we are not done, whether we'd been called from path_init() or trailing_symlink(). And in case when it's 1, we might have been called from path_init() and reached the end of nested symlink (in which case nd->stack[0].name will point to the rest of pathname and we are not done) or from trailing_symlink(), in which case we are done. Just have trailing_symlink() leave NULL in nd->stack[0].name and use that to discriminate between those cases. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* link_path_walk: nd->depth massage, part 9Al Viro2015-05-101-6/+4
| | | | | | | | Make link_path_walk() work with any value of nd->depth on entry - memorize it and use it in tests instead of comparing with 1. Don't bother with increment/decrement in path_init(). Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* put_link: nd->depth massage, part 8Al Viro2015-05-101-14/+4
| | | | | | | all calls are preceded by decrement of nd->depth; move it into put_link() itself. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* trailing_symlink: nd->depth massage, part 7Al Viro2015-05-101-4/+4
| | | | | | move decrement of nd->depth on successful returns into the callers. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* get_link: nd->depth massage, part 6Al Viro2015-05-101-3/+2
| | | | | | make get_link() increment nd->depth on successful exit Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* trailing_symlink: nd->depth massage, part 5Al Viro2015-05-101-5/+10
| | | | | | | | move increment of ->depth to the point where we'd discovered that get_link() has not returned an error, adjust exits accordingly. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* link_path_walk: nd->depth massage, part 4Al Viro2015-05-101-4/+6
| | | | | | lift increment/decrement into link_path_walk() callers. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* link_path_walk: nd->depth massage, part 3Al Viro2015-05-101-3/+1
| | | | | | | remove decrement/increment surrounding nd_alloc_stack(), adjust the test in it. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* link_path_walk: nd->depth massage, part 2Al Viro2015-05-101-8/+0
| | | | | | collapse adjacent increment/decrement pairs. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* link_path_walk: nd->depth massage, part 1Al Viro2015-05-101-5/+17
| | | | | | | | | | | | | | nd->stack[0] is unused until the handling of trailing symlinks and we want to get rid of that. Having fucked that transformation up several times, I went for bloody pedantic series of provably equivalent transformations. Sorry. Step 1: keep nd->depth higher by one in link_path_walk() - increment upon entry, decrement on exits, adjust the arithmetics inside and surround the calls of functions that care about nd->depth value (nd_alloc_stack(), get_link(), put_link()) with decrement/increment pairs. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: remove restrictions on nesting depthAl Viro2015-05-101-14/+52
| | | | | | | The only restriction is that on the total amount of symlinks crossed; how they are nested does not matter Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: trim the arguments of get_link()Al Viro2015-05-101-24/+21
| | | | | | same story as the previous commit Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: trim redundant arguments of fs/namei.c:put_link()Al Viro2015-05-101-12/+13
| | | | Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: trim redundant arguments of trailing_symlink()Al Viro2015-05-101-13/+8
| | | | Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: move link/cookie pairs into nameidataAl Viro2015-05-101-17/+18
| | | | | | | | | | | | Array of MAX_NESTED_LINKS + 1 elements put into nameidata; what used to be a local array in link_path_walk() occupies entries 1 .. MAX_NESTED_LINKS in it, link and cookie from the trailing symlink handling loops - entry 0. This is _not_ the final arrangement; just an easily verified incremental step. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* link_path_walk: cleanup - turn goto start; into continue;Al Viro2015-05-101-3/+6
| | | | | | | Deal with skipping leading slashes before what used to be the recursive call. That way we can get rid of that goto completely. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* link_path_walk: split "return from recursive call" pathAl Viro2015-05-101-23/+17
| | | | Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* link_path_walk: kill the recursionAl Viro2015-05-101-11/+29
| | | | | | | | | absolutely straightforward now - the only variables we need to preserve across the recursive call are name, link and cookie, and recursion depth is limited (and can is equal to nd->depth). So arrange an array of triples to hold instances of those and be done with that. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* link_path_walk: final preparations to killing recursionAl Viro2015-05-101-7/+11
| | | | | | | | | | reduce the number of returns in there - turn all places where it returns zero into goto OK and places where it returns non-zero into goto Err. The only non-trivial detail is that all breaks in the loop are guaranteed to be with non-zero err. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* link_path_walk: get rid of duplicationAl Viro2015-05-101-8/+2
| | | | | | | | | | What we do after the second walk_component() + put_link() + depth decrement in there is exactly equivalent to what's done right after the first walk_component(). Easy to verify and not at all surprising, seeing that there we have just walked the last component of nested symlink. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* link_path_walk: massage a bit moreAl Viro2015-05-101-6/+13
| | | | | | | Pull the block after the if-else in the end of what used to be do-while body into all branches there. We are almost done with the massage... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* link_path_walk: turn inner loop into explicit gotoAl Viro2015-05-101-29/+32
| | | | Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* link_path_walk: don't bother with walk_component() after jumping linkAl Viro2015-05-101-3/+7
| | | | | | ... it does nothing if nd->last_type is LAST_BIND. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* link_path_walk: handle get_link() returning ERR_PTR() immediatelyAl Viro2015-05-101-1/+3
| | | | | | | | If we get ERR_PTR() from get_link(), we are guaranteed to get err != 0 when we break out of do-while, so we are going to hit if (err) return err; shortly after it. Pull that into the if (IS_ERR(s)) body. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: rename follow_link to trailing_symlink, move it downAl Viro2015-05-101-32/+30
| | | | Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: move the calls of may_follow_link() into follow_link()Al Viro2015-05-101-15/+6
| | | | | | All remaining callers of the former are preceded by the latter Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* namei: expand the call of follow_link() in link_path_walk()Al Viro2015-05-101-4/+22
| | | | | | | | | ... and strip __always_inline from follow_link() - remaining callers don't need that. Now link_path_walk() recursion is a direct one. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
OpenPOWER on IntegriCloud