Commit 12dcb58a authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Jens Axboe

io_uring: refactor io_openat2()

Put do_filp_open() fail path of io_openat2() under a single if,
deduplicating put_unused_fd(), making it look better and helping
the hot path.
Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/f4c84d25c049d0af2adc19c703bbfef607200209.1624543113.git.asml.silence@gmail.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 9ba6a1c0
...@@ -3851,27 +3851,26 @@ static int io_openat2(struct io_kiocb *req, unsigned int issue_flags) ...@@ -3851,27 +3851,26 @@ static int io_openat2(struct io_kiocb *req, unsigned int issue_flags)
goto err; goto err;
file = do_filp_open(req->open.dfd, req->open.filename, &op); file = do_filp_open(req->open.dfd, req->open.filename, &op);
/* only retry if RESOLVE_CACHED wasn't already set by application */ if (IS_ERR(file)) {
if ((!resolve_nonblock && (issue_flags & IO_URING_F_NONBLOCK)) &&
file == ERR_PTR(-EAGAIN)) {
/* /*
* We could hang on to this 'fd', but seems like marginal * We could hang on to this 'fd' on retrying, but seems like
* gain for something that is now known to be a slower path. * marginal gain for something that is now known to be a slower
* So just put it, and we'll get a new one when we retry. * path. So just put it, and we'll get a new one when we retry.
*/ */
put_unused_fd(ret); put_unused_fd(ret);
return -EAGAIN;
}
if (IS_ERR(file)) {
put_unused_fd(ret);
ret = PTR_ERR(file); ret = PTR_ERR(file);
} else { /* only retry if RESOLVE_CACHED wasn't already set by application */
if ((issue_flags & IO_URING_F_NONBLOCK) && !nonblock_set) if (ret == -EAGAIN &&
file->f_flags &= ~O_NONBLOCK; (!resolve_nonblock && (issue_flags & IO_URING_F_NONBLOCK)))
fsnotify_open(file); return -EAGAIN;
fd_install(ret, file); goto err;
} }
if ((issue_flags & IO_URING_F_NONBLOCK) && !nonblock_set)
file->f_flags &= ~O_NONBLOCK;
fsnotify_open(file);
fd_install(ret, file);
err: err:
putname(req->open.filename); putname(req->open.filename);
req->flags &= ~REQ_F_NEED_CLEANUP; req->flags &= ~REQ_F_NEED_CLEANUP;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment