diff mbox series

[RFC,8/8] io_uring: introduce struct io_uring_sqe_{fsync,sfr,fallocate}

Message ID 07ade3e4e9182f0857e6206e6613063639f95dce.1660291547.git.metze@samba.org (mailing list archive)
State New
Headers show
Series cleanup struct io_uring_sqe layout | expand

Commit Message

Stefan Metzmacher Aug. 12, 2022, 8:34 a.m. UTC
This allows us to use IO_URING_SQE_HIDE_LEGACY in io_uring/sync.c

Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
 include/uapi/linux/io_uring.h | 48 +++++++++++++++++++++++++++++
 io_uring/io_uring.c           | 33 ++++++++++++++++++++
 io_uring/sync.c               | 58 ++++++++++++++++++++++++++---------
 3 files changed, 124 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index 690b13229227..6428d97e14fc 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -132,6 +132,54 @@  struct io_uring_sqe {
 			__u64	u64_ofs48;
 			__u64	u64_ofs56;
 		} rw;
+
+		/* IORING_OP_FSYNC */
+		struct io_uring_sqe_fsync {
+			struct io_uring_sqe_hdr hdr;
+
+			__u64	offset;
+			__u64	u64_ofs16;
+			__u32	length;
+			__u32	flags;
+
+			struct io_uring_sqe_common common;
+
+			__u32	u32_ofs44;
+			__u64	u64_ofs48;
+			__u64	u64_ofs56;
+		} fsync;
+
+		/* IORING_OP_SYNC_FILE_RANGE */
+		struct io_uring_sqe_sfr {
+			struct io_uring_sqe_hdr hdr;
+
+			__u64	offset;
+			__u64	u64_ofs16;
+			__u32	length;
+			__u32	flags;
+
+			struct io_uring_sqe_common common;
+
+			__u32	u32_ofs44;
+			__u64	u64_ofs48;
+			__u64	u64_ofs56;
+		} sfr;
+
+		/* IORING_OP_FALLOCATE */
+		struct io_uring_sqe_fallocate {
+			struct io_uring_sqe_hdr hdr;
+
+			__u64	offset;
+			__u64	length;
+			__u32	mode;
+			__u32	u32_ofs28;
+
+			struct io_uring_sqe_common common;
+
+			__u32	u32_ofs44;
+			__u64	u64_ofs48;
+			__u64	u64_ofs56;
+		} fallocate;
 	};
 };
 
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index e3336621e667..893252701363 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -4012,6 +4012,39 @@  static int __init io_uring_init(void)
 	BUILD_BUG_SQE_ALIAS(48,		__u64, rw.u64_ofs48,	u64_ofs48);
 	BUILD_BUG_SQE_ALIAS(56,		__u64, rw.u64_ofs56,	u64_ofs56);
 
+	BUILD_BUG_SQE_HDR_COMMON(struct io_uring_sqe_fsync, fsync);
+	BUILD_BUG_SQE_LEGACY_ALIAS(8,	__u64, fsync.offset,	off);
+	BUILD_BUG_SQE_LEGACY_ALIAS(16,	__u64, fsync.u64_ofs16,	addr);
+	BUILD_BUG_SQE_ALIAS(16,		__u64, fsync.u64_ofs16,	u64_ofs16);
+	BUILD_BUG_SQE_LEGACY_ALIAS(24,	__u32, fsync.length,	len);
+	BUILD_BUG_SQE_LEGACY_ALIAS(28,	__u32, fsync.flags,	fsync_flags);
+	BUILD_BUG_SQE_LEGACY_ALIAS(44,	__u32, fsync.u32_ofs44,	splice_fd_in);
+	BUILD_BUG_SQE_ALIAS(44,		__u32, rw.u32_ofs44,	u32_ofs44);
+	BUILD_BUG_SQE_ALIAS(48,		__u64, rw.u64_ofs48,	u64_ofs48);
+	BUILD_BUG_SQE_ALIAS(56,		__u64, rw.u64_ofs56,	u64_ofs56);
+
+	BUILD_BUG_SQE_HDR_COMMON(struct io_uring_sqe_sfr, sfr);
+	BUILD_BUG_SQE_LEGACY_ALIAS(8,	__u64, sfr.offset,	off);
+	BUILD_BUG_SQE_LEGACY_ALIAS(16,	__u64, sfr.u64_ofs16,	addr);
+	BUILD_BUG_SQE_ALIAS(16,		__u64, sfr.u64_ofs16,	u64_ofs16);
+	BUILD_BUG_SQE_LEGACY_ALIAS(24,	__u32, sfr.length,	len);
+	BUILD_BUG_SQE_LEGACY_ALIAS(28,	__u32, sfr.flags,	fsync_flags);
+	BUILD_BUG_SQE_LEGACY_ALIAS(44,	__u32, sfr.u32_ofs44,	splice_fd_in);
+	BUILD_BUG_SQE_ALIAS(44,		__u32, sfr.u32_ofs44,	u32_ofs44);
+	BUILD_BUG_SQE_ALIAS(48,		__u64, sfr.u64_ofs48,	u64_ofs48);
+	BUILD_BUG_SQE_ALIAS(56,		__u64, sfr.u64_ofs56,	u64_ofs56);
+
+	BUILD_BUG_SQE_HDR_COMMON(struct io_uring_sqe_fallocate, fallocate);
+	BUILD_BUG_SQE_LEGACY_ALIAS(8,	__u64, fallocate.offset,	off);
+	BUILD_BUG_SQE_LEGACY_ALIAS(16,	__u64, fallocate.length,	addr);
+	BUILD_BUG_SQE_LEGACY_ALIAS(24,	__u32, fallocate.mode,		len);
+	BUILD_BUG_SQE_LEGACY_ALIAS(28,	__u32, fallocate.u32_ofs28,	rw_flags);
+	BUILD_BUG_SQE_ALIAS(28,		__u32, fallocate.u32_ofs28,	u32_ofs28);
+	BUILD_BUG_SQE_LEGACY_ALIAS(44,	__u32, fallocate.u32_ofs44,	splice_fd_in);
+	BUILD_BUG_SQE_ALIAS(44,		__u32, fallocate.u32_ofs44,	u32_ofs44);
+	BUILD_BUG_SQE_ALIAS(48,		__u64, fallocate.u64_ofs48,	u64_ofs48);
+	BUILD_BUG_SQE_ALIAS(56,		__u64, fallocate.u64_ofs56,	u64_ofs56);
+
 	BUILD_BUG_ON(sizeof(struct io_uring_files_update) !=
 		     sizeof(struct io_uring_rsrc_update));
 	BUILD_BUG_ON(sizeof(struct io_uring_rsrc_update) >
diff --git a/io_uring/sync.c b/io_uring/sync.c
index 64e87ea2b8fb..ba8e3a91a1ab 100644
--- a/io_uring/sync.c
+++ b/io_uring/sync.c
@@ -1,4 +1,5 @@ 
 // SPDX-License-Identifier: GPL-2.0
+#define IO_URING_SQE_HIDE_LEGACY 1
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/fs.h>
@@ -22,16 +23,25 @@  struct io_sync {
 	int				mode;
 };
 
-int io_sfr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
+int io_sfr_prep(struct io_kiocb *req, const struct io_uring_sqe *_sqe)
 {
+	const struct io_uring_sqe_sfr *sqe = &_sqe->sfr;
 	struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync);
 
-	if (unlikely(sqe->addr || sqe->buf_index || sqe->splice_fd_in))
+	/*
+	 * Note for compat reasons we don't check the following
+	 * to be zero:
+	 *
+	 * sqe->u64_ofs48
+	 * sqe->u64_ofs56
+	 */
+	if (unlikely(sqe->u64_ofs16 || sqe->common.buf_info || sqe->u32_ofs44))
 		return -EINVAL;
 
-	sync->off = READ_ONCE(sqe->off);
-	sync->len = READ_ONCE(sqe->len);
-	sync->flags = READ_ONCE(sqe->sync_range_flags);
+	sync->off = READ_ONCE(sqe->offset);
+	sync->len = READ_ONCE(sqe->length);
+	sync->flags = READ_ONCE(sqe->flags);
+
 	return 0;
 }
 
@@ -49,19 +59,28 @@  int io_sync_file_range(struct io_kiocb *req, unsigned int issue_flags)
 	return IOU_OK;
 }
 
-int io_fsync_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
+int io_fsync_prep(struct io_kiocb *req, const struct io_uring_sqe *_sqe)
 {
+	const struct io_uring_sqe_fsync *sqe = &_sqe->fsync;
 	struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync);
 
-	if (unlikely(sqe->addr || sqe->buf_index || sqe->splice_fd_in))
+	/*
+	 * Note for compat reasons we don't check the following
+	 * to be zero:
+	 *
+	 * sqe->u64_ofs48
+	 * sqe->u64_ofs56
+	 */
+	if (unlikely(sqe->u64_ofs16 || sqe->common.buf_info || sqe->u32_ofs44))
 		return -EINVAL;
 
-	sync->flags = READ_ONCE(sqe->fsync_flags);
+	sync->flags = READ_ONCE(sqe->flags);
 	if (unlikely(sync->flags & ~IORING_FSYNC_DATASYNC))
 		return -EINVAL;
 
-	sync->off = READ_ONCE(sqe->off);
-	sync->len = READ_ONCE(sqe->len);
+	sync->off = READ_ONCE(sqe->offset);
+	sync->len = READ_ONCE(sqe->length);
+
 	return 0;
 }
 
@@ -81,16 +100,25 @@  int io_fsync(struct io_kiocb *req, unsigned int issue_flags)
 	return IOU_OK;
 }
 
-int io_fallocate_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
+int io_fallocate_prep(struct io_kiocb *req, const struct io_uring_sqe *_sqe)
 {
+	const struct io_uring_sqe_fallocate *sqe = &_sqe->fallocate;
 	struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync);
 
-	if (sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in)
+	/*
+	 * Note for compat reasons we don't check the following
+	 * to be zero:
+	 *
+	 * sqe->u64_ofs48
+	 * sqe->u64_ofs56
+	 */
+	if (sqe->common.buf_info || sqe->u32_ofs28 || sqe->u32_ofs44)
 		return -EINVAL;
 
-	sync->off = READ_ONCE(sqe->off);
-	sync->len = READ_ONCE(sqe->addr);
-	sync->mode = READ_ONCE(sqe->len);
+	sync->off = READ_ONCE(sqe->offset);
+	sync->len = READ_ONCE(sqe->length);
+	sync->mode = READ_ONCE(sqe->mode);
+
 	return 0;
 }