]>
git.proxmox.com Git - mirror_ubuntu-kernels.git/blob - io_uring/sync.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>
10 #include <linux/fsnotify.h>
12 #include <uapi/linux/io_uring.h>
25 int io_sfr_prep(struct io_kiocb
*req
, const struct io_uring_sqe
*sqe
)
27 struct io_sync
*sync
= io_kiocb_to_cmd(req
, struct io_sync
);
29 if (unlikely(sqe
->addr
|| sqe
->buf_index
|| sqe
->splice_fd_in
))
32 sync
->off
= READ_ONCE(sqe
->off
);
33 sync
->len
= READ_ONCE(sqe
->len
);
34 sync
->flags
= READ_ONCE(sqe
->sync_range_flags
);
38 int io_sync_file_range(struct io_kiocb
*req
, unsigned int issue_flags
)
40 struct io_sync
*sync
= io_kiocb_to_cmd(req
, struct io_sync
);
43 /* sync_file_range always requires a blocking context */
44 if (issue_flags
& IO_URING_F_NONBLOCK
)
47 ret
= sync_file_range(req
->file
, sync
->off
, sync
->len
, sync
->flags
);
48 io_req_set_res(req
, ret
, 0);
52 int io_fsync_prep(struct io_kiocb
*req
, const struct io_uring_sqe
*sqe
)
54 struct io_sync
*sync
= io_kiocb_to_cmd(req
, struct io_sync
);
56 if (unlikely(sqe
->addr
|| sqe
->buf_index
|| sqe
->splice_fd_in
))
59 sync
->flags
= READ_ONCE(sqe
->fsync_flags
);
60 if (unlikely(sync
->flags
& ~IORING_FSYNC_DATASYNC
))
63 sync
->off
= READ_ONCE(sqe
->off
);
64 sync
->len
= READ_ONCE(sqe
->len
);
68 int io_fsync(struct io_kiocb
*req
, unsigned int issue_flags
)
70 struct io_sync
*sync
= io_kiocb_to_cmd(req
, struct io_sync
);
71 loff_t end
= sync
->off
+ sync
->len
;
74 /* fsync always requires a blocking context */
75 if (issue_flags
& IO_URING_F_NONBLOCK
)
78 ret
= vfs_fsync_range(req
->file
, sync
->off
, end
> 0 ? end
: LLONG_MAX
,
79 sync
->flags
& IORING_FSYNC_DATASYNC
);
80 io_req_set_res(req
, ret
, 0);
84 int io_fallocate_prep(struct io_kiocb
*req
, const struct io_uring_sqe
*sqe
)
86 struct io_sync
*sync
= io_kiocb_to_cmd(req
, struct io_sync
);
88 if (sqe
->buf_index
|| sqe
->rw_flags
|| sqe
->splice_fd_in
)
91 sync
->off
= READ_ONCE(sqe
->off
);
92 sync
->len
= READ_ONCE(sqe
->addr
);
93 sync
->mode
= READ_ONCE(sqe
->len
);
97 int io_fallocate(struct io_kiocb
*req
, unsigned int issue_flags
)
99 struct io_sync
*sync
= io_kiocb_to_cmd(req
, struct io_sync
);
102 /* fallocate always requiring blocking context */
103 if (issue_flags
& IO_URING_F_NONBLOCK
)
105 ret
= vfs_fallocate(req
->file
, sync
->mode
, sync
->off
, sync
->len
);
107 fsnotify_modify(req
->file
);
108 io_req_set_res(req
, ret
, 0);