Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring: split out fadvise/madvise operations

Signed-off-by: Jens Axboe <axboe@kernel.dk>

+109 -85
+1 -1
io_uring/Makefile
··· 3 3 # Makefile for io_uring 4 4 5 5 obj-$(CONFIG_IO_URING) += io_uring.o xattr.o nop.o fs.o splice.o \ 6 - sync.o 6 + sync.o advise.o 7 7 obj-$(CONFIG_IO_WQ) += io-wq.o
+100
io_uring/advise.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #include <linux/kernel.h> 3 + #include <linux/errno.h> 4 + #include <linux/fs.h> 5 + #include <linux/file.h> 6 + #include <linux/mm.h> 7 + #include <linux/slab.h> 8 + #include <linux/namei.h> 9 + #include <linux/io_uring.h> 10 + 11 + #include <uapi/linux/fadvise.h> 12 + #include <uapi/linux/io_uring.h> 13 + 14 + #include "io_uring_types.h" 15 + #include "io_uring.h" 16 + #include "advise.h" 17 + 18 + struct io_fadvise { 19 + struct file *file; 20 + u64 offset; 21 + u32 len; 22 + u32 advice; 23 + }; 24 + 25 + struct io_madvise { 26 + struct file *file; 27 + u64 addr; 28 + u32 len; 29 + u32 advice; 30 + }; 31 + 32 + int io_madvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 33 + { 34 + #if defined(CONFIG_ADVISE_SYSCALLS) && defined(CONFIG_MMU) 35 + struct io_madvise *ma = io_kiocb_to_cmd(req); 36 + 37 + if (sqe->buf_index || sqe->off || sqe->splice_fd_in) 38 + return -EINVAL; 39 + 40 + ma->addr = READ_ONCE(sqe->addr); 41 + ma->len = READ_ONCE(sqe->len); 42 + ma->advice = READ_ONCE(sqe->fadvise_advice); 43 + return 0; 44 + #else 45 + return -EOPNOTSUPP; 46 + #endif 47 + } 48 + 49 + int io_madvise(struct io_kiocb *req, unsigned int issue_flags) 50 + { 51 + #if defined(CONFIG_ADVISE_SYSCALLS) && defined(CONFIG_MMU) 52 + struct io_madvise *ma = io_kiocb_to_cmd(req); 53 + int ret; 54 + 55 + if (issue_flags & IO_URING_F_NONBLOCK) 56 + return -EAGAIN; 57 + 58 + ret = do_madvise(current->mm, ma->addr, ma->len, ma->advice); 59 + io_req_set_res(req, ret, 0); 60 + return IOU_OK; 61 + #else 62 + return -EOPNOTSUPP; 63 + #endif 64 + } 65 + 66 + int io_fadvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 67 + { 68 + struct io_fadvise *fa = io_kiocb_to_cmd(req); 69 + 70 + if (sqe->buf_index || sqe->addr || sqe->splice_fd_in) 71 + return -EINVAL; 72 + 73 + fa->offset = READ_ONCE(sqe->off); 74 + fa->len = READ_ONCE(sqe->len); 75 + fa->advice = READ_ONCE(sqe->fadvise_advice); 76 + return 0; 77 + } 78 + 79 + int io_fadvise(struct io_kiocb *req, unsigned int issue_flags) 80 + { 81 + struct io_fadvise *fa = io_kiocb_to_cmd(req); 82 + int ret; 83 + 84 + if (issue_flags & IO_URING_F_NONBLOCK) { 85 + switch (fa->advice) { 86 + case POSIX_FADV_NORMAL: 87 + case POSIX_FADV_RANDOM: 88 + case POSIX_FADV_SEQUENTIAL: 89 + break; 90 + default: 91 + return -EAGAIN; 92 + } 93 + } 94 + 95 + ret = vfs_fadvise(req->file, fa->offset, fa->len, fa->advice); 96 + if (ret < 0) 97 + req_set_fail(req); 98 + io_req_set_res(req, ret, 0); 99 + return IOU_OK; 100 + }
+7
io_uring/advise.h
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + int io_madvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); 4 + int io_madvise(struct io_kiocb *req, unsigned int issue_flags); 5 + 6 + int io_fadvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); 7 + int io_fadvise(struct io_kiocb *req, unsigned int issue_flags);
+1 -84
io_uring/io_uring.c
··· 97 97 #include "fs.h" 98 98 #include "splice.h" 99 99 #include "sync.h" 100 + #include "advise.h" 100 101 101 102 #define IORING_MAX_ENTRIES 32768 102 103 #define IORING_MAX_CQ_ENTRIES (2 * IORING_MAX_ENTRIES) ··· 407 406 u64 arg; 408 407 u32 nr_args; 409 408 u32 offset; 410 - }; 411 - 412 - struct io_fadvise { 413 - struct file *file; 414 - u64 offset; 415 - u32 len; 416 - u32 advice; 417 - }; 418 - 419 - struct io_madvise { 420 - struct file *file; 421 - u64 addr; 422 - u32 len; 423 - u32 advice; 424 409 }; 425 410 426 411 struct io_epoll { ··· 4413 4426 #else 4414 4427 return -EOPNOTSUPP; 4415 4428 #endif 4416 - } 4417 - 4418 - static int io_madvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 4419 - { 4420 - #if defined(CONFIG_ADVISE_SYSCALLS) && defined(CONFIG_MMU) 4421 - struct io_madvise *ma = io_kiocb_to_cmd(req); 4422 - 4423 - if (sqe->buf_index || sqe->off || sqe->splice_fd_in) 4424 - return -EINVAL; 4425 - 4426 - ma->addr = READ_ONCE(sqe->addr); 4427 - ma->len = READ_ONCE(sqe->len); 4428 - ma->advice = READ_ONCE(sqe->fadvise_advice); 4429 - return 0; 4430 - #else 4431 - return -EOPNOTSUPP; 4432 - #endif 4433 - } 4434 - 4435 - static int io_madvise(struct io_kiocb *req, unsigned int issue_flags) 4436 - { 4437 - #if defined(CONFIG_ADVISE_SYSCALLS) && defined(CONFIG_MMU) 4438 - struct io_madvise *ma = io_kiocb_to_cmd(req); 4439 - int ret; 4440 - 4441 - if (issue_flags & IO_URING_F_NONBLOCK) 4442 - return -EAGAIN; 4443 - 4444 - ret = do_madvise(current->mm, ma->addr, ma->len, ma->advice); 4445 - io_req_set_res(req, ret, 0); 4446 - return IOU_OK; 4447 - #else 4448 - return -EOPNOTSUPP; 4449 - #endif 4450 - } 4451 - 4452 - static int io_fadvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 4453 - { 4454 - struct io_fadvise *fa = io_kiocb_to_cmd(req); 4455 - 4456 - if (sqe->buf_index || sqe->addr || sqe->splice_fd_in) 4457 - return -EINVAL; 4458 - 4459 - fa->offset = READ_ONCE(sqe->off); 4460 - fa->len = READ_ONCE(sqe->len); 4461 - fa->advice = READ_ONCE(sqe->fadvise_advice); 4462 - return 0; 4463 - } 4464 - 4465 - static int io_fadvise(struct io_kiocb *req, unsigned int issue_flags) 4466 - { 4467 - struct io_fadvise *fa = io_kiocb_to_cmd(req); 4468 - int ret; 4469 - 4470 - if (issue_flags & IO_URING_F_NONBLOCK) { 4471 - switch (fa->advice) { 4472 - case POSIX_FADV_NORMAL: 4473 - case POSIX_FADV_RANDOM: 4474 - case POSIX_FADV_SEQUENTIAL: 4475 - break; 4476 - default: 4477 - return -EAGAIN; 4478 - } 4479 - } 4480 - 4481 - ret = vfs_fadvise(req->file, fa->offset, fa->len, fa->advice); 4482 - if (ret < 0) 4483 - req_set_fail(req); 4484 - io_req_set_res(req, ret, 0); 4485 - return IOU_OK; 4486 4429 } 4487 4430 4488 4431 static int io_statx_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)