Skip to content

Commit

Permalink
vfs: do_last(): clean up retry
Browse files Browse the repository at this point in the history
Move the lookup retry logic to the bottom of the function to make the normal
case simpler to read.

Reported-by: David Howells <[email protected]>
Signed-off-by: Miklos Szeredi <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Miklos Szeredi authored and Al Viro committed Jul 14, 2012
1 parent 77d660a commit f60dc3d
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -2614,22 +2614,11 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
goto exit;
od->mnt = nd->path.mnt;
filp = finish_open(od, nd->path.dentry, NULL);
if (filp == ERR_PTR(-EOPENSTALE) && save_parent.dentry && !retried) {
BUG_ON(save_parent.dentry != dir);
path_put(&nd->path);
nd->path = save_parent;
nd->inode = dir->d_inode;
save_parent.mnt = NULL;
save_parent.dentry = NULL;
if (want_write) {
mnt_drop_write(nd->path.mnt);
want_write = false;
}
retried = true;
goto retry_lookup;
}
if (IS_ERR(filp))
if (IS_ERR(filp)) {
if (filp == ERR_PTR(-EOPENSTALE))
goto stale_open;
goto out;
}
error = open_check_o_direct(filp);
if (error)
goto exit_fput;
Expand Down Expand Up @@ -2659,6 +2648,23 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
fput(filp);
goto exit;

stale_open:
/* If no saved parent or already retried then can't retry */
if (!save_parent.dentry || retried)
goto out;

BUG_ON(save_parent.dentry != dir);
path_put(&nd->path);
nd->path = save_parent;
nd->inode = dir->d_inode;
save_parent.mnt = NULL;
save_parent.dentry = NULL;
if (want_write) {
mnt_drop_write(nd->path.mnt);
want_write = false;
}
retried = true;
goto retry_lookup;
}

static struct file *path_openat(int dfd, const char *pathname,
Expand Down

0 comments on commit f60dc3d

Please sign in to comment.