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 fs related sync/fallocate functions

This splits out sync_file_range, fsync, and fallocate.

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

+124 -97
+2 -1
io_uring/Makefile
··· 2 2 # 3 3 # Makefile for io_uring 4 4 5 - obj-$(CONFIG_IO_URING) += io_uring.o xattr.o nop.o fs.o splice.o 5 + obj-$(CONFIG_IO_URING) += io_uring.o xattr.o nop.o fs.o splice.o \ 6 + sync.o 6 7 obj-$(CONFIG_IO_WQ) += io-wq.o
+1 -96
io_uring/io_uring.c
··· 96 96 #include "nop.h" 97 97 #include "fs.h" 98 98 #include "splice.h" 99 + #include "sync.h" 99 100 100 101 #define IORING_MAX_ENTRIES 32768 101 102 #define IORING_MAX_CQ_ENTRIES (2 * IORING_MAX_ENTRIES) ··· 335 334 int flags; 336 335 u32 file_slot; 337 336 unsigned long nofile; 338 - }; 339 - 340 - struct io_sync { 341 - struct file *file; 342 - loff_t len; 343 - loff_t off; 344 - int flags; 345 - int mode; 346 337 }; 347 338 348 339 struct io_cancel { ··· 3934 3941 return IOU_OK; 3935 3942 } 3936 3943 3937 - static int io_fsync_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 3938 - { 3939 - struct io_sync *sync = io_kiocb_to_cmd(req); 3940 - 3941 - if (unlikely(sqe->addr || sqe->buf_index || sqe->splice_fd_in)) 3942 - return -EINVAL; 3943 - 3944 - sync->flags = READ_ONCE(sqe->fsync_flags); 3945 - if (unlikely(sync->flags & ~IORING_FSYNC_DATASYNC)) 3946 - return -EINVAL; 3947 - 3948 - sync->off = READ_ONCE(sqe->off); 3949 - sync->len = READ_ONCE(sqe->len); 3950 - return 0; 3951 - } 3952 - 3953 - static int io_fsync(struct io_kiocb *req, unsigned int issue_flags) 3954 - { 3955 - struct io_sync *sync = io_kiocb_to_cmd(req); 3956 - loff_t end = sync->off + sync->len; 3957 - int ret; 3958 - 3959 - /* fsync always requires a blocking context */ 3960 - if (issue_flags & IO_URING_F_NONBLOCK) 3961 - return -EAGAIN; 3962 - 3963 - ret = vfs_fsync_range(req->file, sync->off, end > 0 ? end : LLONG_MAX, 3964 - sync->flags & IORING_FSYNC_DATASYNC); 3965 - io_req_set_res(req, ret, 0); 3966 - return IOU_OK; 3967 - } 3968 - 3969 - static int io_fallocate_prep(struct io_kiocb *req, 3970 - const struct io_uring_sqe *sqe) 3971 - { 3972 - struct io_sync *sync = io_kiocb_to_cmd(req); 3973 - 3974 - if (sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in) 3975 - return -EINVAL; 3976 - 3977 - sync->off = READ_ONCE(sqe->off); 3978 - sync->len = READ_ONCE(sqe->addr); 3979 - sync->mode = READ_ONCE(sqe->len); 3980 - return 0; 3981 - } 3982 - 3983 - static int io_fallocate(struct io_kiocb *req, unsigned int issue_flags) 3984 - { 3985 - struct io_sync *sync = io_kiocb_to_cmd(req); 3986 - int ret; 3987 - 3988 - /* fallocate always requiring blocking context */ 3989 - if (issue_flags & IO_URING_F_NONBLOCK) 3990 - return -EAGAIN; 3991 - ret = vfs_fallocate(req->file, sync->mode, sync->off, sync->len); 3992 - if (ret >= 0) 3993 - fsnotify_modify(req->file); 3994 - io_req_set_res(req, ret, 0); 3995 - return IOU_OK; 3996 - } 3997 - 3998 3944 static int __io_openat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 3999 3945 { 4000 3946 struct io_open *open = io_kiocb_to_cmd(req); ··· 4609 4677 err: 4610 4678 if (ret < 0) 4611 4679 req_set_fail(req); 4612 - io_req_set_res(req, ret, 0); 4613 - return IOU_OK; 4614 - } 4615 - 4616 - static int io_sfr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 4617 - { 4618 - struct io_sync *sync = io_kiocb_to_cmd(req); 4619 - 4620 - if (unlikely(sqe->addr || sqe->buf_index || sqe->splice_fd_in)) 4621 - return -EINVAL; 4622 - 4623 - sync->off = READ_ONCE(sqe->off); 4624 - sync->len = READ_ONCE(sqe->len); 4625 - sync->flags = READ_ONCE(sqe->sync_range_flags); 4626 - return 0; 4627 - } 4628 - 4629 - static int io_sync_file_range(struct io_kiocb *req, unsigned int issue_flags) 4630 - { 4631 - struct io_sync *sync = io_kiocb_to_cmd(req); 4632 - int ret; 4633 - 4634 - /* sync_file_range always requires a blocking context */ 4635 - if (issue_flags & IO_URING_F_NONBLOCK) 4636 - return -EAGAIN; 4637 - 4638 - ret = sync_file_range(req->file, sync->off, sync->len, sync->flags); 4639 4680 io_req_set_res(req, ret, 0); 4640 4681 return IOU_OK; 4641 4682 }
+111
io_uring/sync.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 + #include <linux/fsnotify.h> 11 + 12 + #include <uapi/linux/io_uring.h> 13 + 14 + #include "io_uring_types.h" 15 + #include "io_uring.h" 16 + #include "sync.h" 17 + 18 + struct io_sync { 19 + struct file *file; 20 + loff_t len; 21 + loff_t off; 22 + int flags; 23 + int mode; 24 + }; 25 + 26 + int io_sfr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 27 + { 28 + struct io_sync *sync = io_kiocb_to_cmd(req); 29 + 30 + if (unlikely(sqe->addr || sqe->buf_index || sqe->splice_fd_in)) 31 + return -EINVAL; 32 + 33 + sync->off = READ_ONCE(sqe->off); 34 + sync->len = READ_ONCE(sqe->len); 35 + sync->flags = READ_ONCE(sqe->sync_range_flags); 36 + return 0; 37 + } 38 + 39 + int io_sync_file_range(struct io_kiocb *req, unsigned int issue_flags) 40 + { 41 + struct io_sync *sync = io_kiocb_to_cmd(req); 42 + int ret; 43 + 44 + /* sync_file_range always requires a blocking context */ 45 + if (issue_flags & IO_URING_F_NONBLOCK) 46 + return -EAGAIN; 47 + 48 + ret = sync_file_range(req->file, sync->off, sync->len, sync->flags); 49 + io_req_set_res(req, ret, 0); 50 + return IOU_OK; 51 + } 52 + 53 + int io_fsync_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 54 + { 55 + struct io_sync *sync = io_kiocb_to_cmd(req); 56 + 57 + if (unlikely(sqe->addr || sqe->buf_index || sqe->splice_fd_in)) 58 + return -EINVAL; 59 + 60 + sync->flags = READ_ONCE(sqe->fsync_flags); 61 + if (unlikely(sync->flags & ~IORING_FSYNC_DATASYNC)) 62 + return -EINVAL; 63 + 64 + sync->off = READ_ONCE(sqe->off); 65 + sync->len = READ_ONCE(sqe->len); 66 + return 0; 67 + } 68 + 69 + int io_fsync(struct io_kiocb *req, unsigned int issue_flags) 70 + { 71 + struct io_sync *sync = io_kiocb_to_cmd(req); 72 + loff_t end = sync->off + sync->len; 73 + int ret; 74 + 75 + /* fsync always requires a blocking context */ 76 + if (issue_flags & IO_URING_F_NONBLOCK) 77 + return -EAGAIN; 78 + 79 + ret = vfs_fsync_range(req->file, sync->off, end > 0 ? end : LLONG_MAX, 80 + sync->flags & IORING_FSYNC_DATASYNC); 81 + io_req_set_res(req, ret, 0); 82 + return IOU_OK; 83 + } 84 + 85 + int io_fallocate_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 86 + { 87 + struct io_sync *sync = io_kiocb_to_cmd(req); 88 + 89 + if (sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in) 90 + return -EINVAL; 91 + 92 + sync->off = READ_ONCE(sqe->off); 93 + sync->len = READ_ONCE(sqe->addr); 94 + sync->mode = READ_ONCE(sqe->len); 95 + return 0; 96 + } 97 + 98 + int io_fallocate(struct io_kiocb *req, unsigned int issue_flags) 99 + { 100 + struct io_sync *sync = io_kiocb_to_cmd(req); 101 + int ret; 102 + 103 + /* fallocate always requiring blocking context */ 104 + if (issue_flags & IO_URING_F_NONBLOCK) 105 + return -EAGAIN; 106 + ret = vfs_fallocate(req->file, sync->mode, sync->off, sync->len); 107 + if (ret >= 0) 108 + fsnotify_modify(req->file); 109 + io_req_set_res(req, ret, 0); 110 + return IOU_OK; 111 + }
+10
io_uring/sync.h
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + int io_sfr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); 4 + int io_sync_file_range(struct io_kiocb *req, unsigned int issue_flags); 5 + 6 + int io_fsync_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); 7 + int io_fsync(struct io_kiocb *req, unsigned int issue_flags); 8 + 9 + int io_fallocate(struct io_kiocb *req, unsigned int issue_flags); 10 + int io_fallocate_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);