Skip to content

Commit 0ffae64

Browse files
Dylan Yudakenaxboe
authored andcommitted
io_uring: always go async for unsupported open flags
No point in issuing -> return -EAGAIN -> go async, when it can be done upfront. Signed-off-by: Dylan Yudaken <dylany@meta.com> Link: https://lore.kernel.org/r/20230127135227.3646353-5-dylany@meta.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent c31cc60 commit 0ffae64

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

io_uring/openclose.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ struct io_close {
3131
u32 file_slot;
3232
};
3333

34+
static bool io_openat_force_async(struct io_open *open)
35+
{
36+
/*
37+
* Don't bother trying for O_TRUNC, O_CREAT, or O_TMPFILE open,
38+
* it'll always -EAGAIN
39+
*/
40+
return open->how.flags & (O_TRUNC | O_CREAT | O_TMPFILE);
41+
}
42+
3443
static int __io_openat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
3544
{
3645
struct io_open *open = io_kiocb_to_cmd(req, struct io_open);
@@ -61,6 +70,8 @@ static int __io_openat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe
6170

6271
open->nofile = rlimit(RLIMIT_NOFILE);
6372
req->flags |= REQ_F_NEED_CLEANUP;
73+
if (io_openat_force_async(open))
74+
req->flags |= REQ_F_FORCE_ASYNC;
6475
return 0;
6576
}
6677

@@ -108,12 +119,7 @@ int io_openat2(struct io_kiocb *req, unsigned int issue_flags)
108119
nonblock_set = op.open_flag & O_NONBLOCK;
109120
resolve_nonblock = open->how.resolve & RESOLVE_CACHED;
110121
if (issue_flags & IO_URING_F_NONBLOCK) {
111-
/*
112-
* Don't bother trying for O_TRUNC, O_CREAT, or O_TMPFILE open,
113-
* it'll always -EAGAIN
114-
*/
115-
if (open->how.flags & (O_TRUNC | O_CREAT | O_TMPFILE))
116-
return -EAGAIN;
122+
WARN_ON_ONCE(io_openat_force_async(open));
117123
op.lookup_flags |= LOOKUP_CACHED;
118124
op.open_flag |= O_NONBLOCK;
119125
}

0 commit comments

Comments
 (0)