]>
git.ipfire.org Git - thirdparty/linux.git/blob - io_uring/advise.c
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kernel.h>
3 #include <linux/errno.h>
5 #include <linux/file.h>
7 #include <linux/slab.h>
8 #include <linux/namei.h>
9 #include <linux/io_uring.h>
11 #include <uapi/linux/fadvise.h>
12 #include <uapi/linux/io_uring.h>
31 int io_madvise_prep(struct io_kiocb
*req
, const struct io_uring_sqe
*sqe
)
33 #if defined(CONFIG_ADVISE_SYSCALLS) && defined(CONFIG_MMU)
34 struct io_madvise
*ma
= io_kiocb_to_cmd(req
, struct io_madvise
);
36 if (sqe
->buf_index
|| sqe
->off
|| sqe
->splice_fd_in
)
39 ma
->addr
= READ_ONCE(sqe
->addr
);
40 ma
->len
= READ_ONCE(sqe
->len
);
41 ma
->advice
= READ_ONCE(sqe
->fadvise_advice
);
42 req
->flags
|= REQ_F_FORCE_ASYNC
;
49 int io_madvise(struct io_kiocb
*req
, unsigned int issue_flags
)
51 #if defined(CONFIG_ADVISE_SYSCALLS) && defined(CONFIG_MMU)
52 struct io_madvise
*ma
= io_kiocb_to_cmd(req
, struct io_madvise
);
55 WARN_ON_ONCE(issue_flags
& IO_URING_F_NONBLOCK
);
57 ret
= do_madvise(current
->mm
, ma
->addr
, ma
->len
, ma
->advice
);
58 io_req_set_res(req
, ret
, 0);
65 static bool io_fadvise_force_async(struct io_fadvise
*fa
)
68 case POSIX_FADV_NORMAL
:
69 case POSIX_FADV_RANDOM
:
70 case POSIX_FADV_SEQUENTIAL
:
77 int io_fadvise_prep(struct io_kiocb
*req
, const struct io_uring_sqe
*sqe
)
79 struct io_fadvise
*fa
= io_kiocb_to_cmd(req
, struct io_fadvise
);
81 if (sqe
->buf_index
|| sqe
->addr
|| sqe
->splice_fd_in
)
84 fa
->offset
= READ_ONCE(sqe
->off
);
85 fa
->len
= READ_ONCE(sqe
->len
);
86 fa
->advice
= READ_ONCE(sqe
->fadvise_advice
);
87 if (io_fadvise_force_async(fa
))
88 req
->flags
|= REQ_F_FORCE_ASYNC
;
92 int io_fadvise(struct io_kiocb
*req
, unsigned int issue_flags
)
94 struct io_fadvise
*fa
= io_kiocb_to_cmd(req
, struct io_fadvise
);
97 WARN_ON_ONCE(issue_flags
& IO_URING_F_NONBLOCK
&& io_fadvise_force_async(fa
));
99 ret
= vfs_fadvise(req
->file
, fa
->offset
, fa
->len
, fa
->advice
);
102 io_req_set_res(req
, ret
, 0);