io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Metzmacher <metze@samba.org>
To: io-uring@vger.kernel.org, axboe@kernel.dk
Cc: Stefan Metzmacher <metze@samba.org>
Subject: [RFC PATCH 8/8] io_uring: introduce struct io_uring_sqe_{fsync,sfr,fallocate}
Date: Fri, 12 Aug 2022 10:34:32 +0200	[thread overview]
Message-ID: <07ade3e4e9182f0857e6206e6613063639f95dce.1660291547.git.metze@samba.org> (raw)
In-Reply-To: <cover.1660291547.git.metze@samba.org>

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 --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;
 }
 
-- 
2.34.1


      parent reply	other threads:[~2022-08-12  8:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-12  8:34 [RFC PATCH 0/8] cleanup struct io_uring_sqe layout Stefan Metzmacher
2022-08-12  8:34 ` [RFC PATCH 1/8] io_uring: move the current struct io_uring_sqe members to legacy sub struct Stefan Metzmacher
2022-08-12  8:34 ` [RFC PATCH 2/8] io_uring: add a generic structure for struct io_uring_sqe Stefan Metzmacher
2022-08-12  8:34 ` [RFC PATCH 3/8] io_uring: check legacy layout of struct io_uring_sqe with BUILD_BUG_SQE_LEGACY* Stefan Metzmacher
2022-08-12  8:34 ` [RFC PATCH 4/8] io_uring: only make use generic struct io_uring_sqe elements for tracing Stefan Metzmacher
2022-08-12  8:34 ` [RFC PATCH 5/8] io_uring: only access generic struct io_uring_sqe elements in io_uring.c Stefan Metzmacher
2022-08-12  8:34 ` [RFC PATCH 6/8] io_uring: add BUILD_BUG_SQE_HDR_COMMON() macro Stefan Metzmacher
2022-08-12  8:34 ` [RFC PATCH 7/8] io_uring: introduce struct io_uring_sqe_rw for all io_prep_rw() using opcodes Stefan Metzmacher
2022-08-12  8:34 ` Stefan Metzmacher [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=07ade3e4e9182f0857e6206e6613063639f95dce.1660291547.git.metze@samba.org \
    --to=metze@samba.org \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).