Skip to content

Commit c31cc60

Browse files
Dylan Yudakenaxboe
authored andcommitted
io_uring: always go async for unsupported fadvise 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-4-dylany@meta.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent aebb224 commit c31cc60

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

io_uring/advise.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ int io_madvise(struct io_kiocb *req, unsigned int issue_flags)
6262
#endif
6363
}
6464

65+
static bool io_fadvise_force_async(struct io_fadvise *fa)
66+
{
67+
switch (fa->advice) {
68+
case POSIX_FADV_NORMAL:
69+
case POSIX_FADV_RANDOM:
70+
case POSIX_FADV_SEQUENTIAL:
71+
return false;
72+
default:
73+
return true;
74+
}
75+
}
76+
6577
int io_fadvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
6678
{
6779
struct io_fadvise *fa = io_kiocb_to_cmd(req, struct io_fadvise);
@@ -72,6 +84,8 @@ int io_fadvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
7284
fa->offset = READ_ONCE(sqe->off);
7385
fa->len = READ_ONCE(sqe->len);
7486
fa->advice = READ_ONCE(sqe->fadvise_advice);
87+
if (io_fadvise_force_async(fa))
88+
req->flags |= REQ_F_FORCE_ASYNC;
7589
return 0;
7690
}
7791

@@ -80,16 +94,7 @@ int io_fadvise(struct io_kiocb *req, unsigned int issue_flags)
8094
struct io_fadvise *fa = io_kiocb_to_cmd(req, struct io_fadvise);
8195
int ret;
8296

83-
if (issue_flags & IO_URING_F_NONBLOCK) {
84-
switch (fa->advice) {
85-
case POSIX_FADV_NORMAL:
86-
case POSIX_FADV_RANDOM:
87-
case POSIX_FADV_SEQUENTIAL:
88-
break;
89-
default:
90-
return -EAGAIN;
91-
}
92-
}
97+
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK && io_fadvise_force_async(fa));
9398

9499
ret = vfs_fadvise(req->file, fa->offset, fa->len, fa->advice);
95100
if (ret < 0)

0 commit comments

Comments
 (0)