Skip to content

Commit

Permalink
fs/namei.c: new helper - legitimize_root()
Browse files Browse the repository at this point in the history
identical logics in unlazy_walk() and unlazy_child()

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Al Viro committed Aug 31, 2019
1 parent ce6595a commit ee594bf
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,13 @@ static bool legitimize_links(struct nameidata *nd)
return true;
}

static bool legitimize_root(struct nameidata *nd)
{
if (!nd->root.mnt || (nd->flags & LOOKUP_ROOT))
return true;
return legitimize_path(nd, &nd->root, nd->root_seq);
}

/*
* Path walking has 2 modes, rcu-walk and ref-walk (see
* Documentation/filesystems/path-lookup.txt). In situations when we can't
Expand Down Expand Up @@ -674,10 +681,8 @@ static int unlazy_walk(struct nameidata *nd)
goto out2;
if (unlikely(!legitimize_path(nd, &nd->path, nd->seq)))
goto out1;
if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT)) {
if (unlikely(!legitimize_path(nd, &nd->root, nd->root_seq)))
goto out;
}
if (unlikely(!legitimize_root(nd)))
goto out;
rcu_read_unlock();
BUG_ON(nd->inode != parent->d_inode);
return 0;
Expand Down Expand Up @@ -736,12 +741,10 @@ static int unlazy_child(struct nameidata *nd, struct dentry *dentry, unsigned se
* Sequence counts matched. Now make sure that the root is
* still valid and get it if required.
*/
if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT)) {
if (unlikely(!legitimize_path(nd, &nd->root, nd->root_seq))) {
rcu_read_unlock();
dput(dentry);
return -ECHILD;
}
if (unlikely(!legitimize_root(nd))) {
rcu_read_unlock();
dput(dentry);
return -ECHILD;
}

rcu_read_unlock();
Expand Down

0 comments on commit ee594bf

Please sign in to comment.