Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Mark Harmstone <maharmstone@fb.com>
To: <linux-btrfs@vger.kernel.org>
Cc: Mark Harmstone <maharmstone@fb.com>
Subject: [PATCH] btrfs: add io_uring interface for encoded reads
Date: Fri, 9 Aug 2024 18:35:27 +0100	[thread overview]
Message-ID: <20240809173552.929988-1-maharmstone@fb.com> (raw)

Adds an io_uring interface for asynchronous encoded reads, using the
same interface as for the ioctl. To use this you would use an SQE opcode
of IORING_OP_URING_CMD, the cmd_op would be BTRFS_IOC_ENCODED_READ, and
addr would point to the userspace address of the
btrfs_ioctl_encoded_io_args struct. As with the ioctl, you need to have
CAP_SYS_ADMIN for this to work.

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
---
 fs/btrfs/file.c  |  1 +
 fs/btrfs/ioctl.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 fs/btrfs/ioctl.h |  1 +
 3 files changed, 50 insertions(+)

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index f9d76072398d..974f9e85b46e 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -3850,6 +3850,7 @@ const struct file_operations btrfs_file_operations = {
 	.compat_ioctl	= btrfs_compat_ioctl,
 #endif
 	.remap_file_range = btrfs_remap_file_range,
+	.uring_cmd	= btrfs_uring_cmd,
 };
 
 int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 0493272a7668..8f5cc7d1429c 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -29,6 +29,7 @@
 #include <linux/fileattr.h>
 #include <linux/fsverity.h>
 #include <linux/sched/xacct.h>
+#include <linux/io_uring/cmd.h>
 #include "ctree.h"
 #include "disk-io.h"
 #include "export.h"
@@ -4648,6 +4649,53 @@ static int btrfs_ioctl_encoded_write(struct file *file, void __user *argp, bool
 	return ret;
 }
 
+static void btrfs_uring_encoded_read_cb(struct io_uring_cmd *cmd,
+					unsigned int issue_flags)
+{
+	int ret;
+
+	ret = btrfs_ioctl_encoded_read(cmd->file, (void __user *)cmd->sqe->addr,
+				       false);
+
+	io_uring_cmd_done(cmd, ret, 0, issue_flags);
+}
+
+static void btrfs_uring_encoded_read_compat_cb(struct io_uring_cmd *cmd,
+					       unsigned int issue_flags)
+{
+	int ret;
+
+	ret = btrfs_ioctl_encoded_read(cmd->file, (void __user *)cmd->sqe->addr,
+				       true);
+
+	io_uring_cmd_done(cmd, ret, 0, issue_flags);
+}
+
+static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd,
+				    unsigned int issue_flags)
+{
+	if (issue_flags & IO_URING_F_COMPAT)
+		io_uring_cmd_complete_in_task(cmd, btrfs_uring_encoded_read_compat_cb);
+	else
+		io_uring_cmd_complete_in_task(cmd, btrfs_uring_encoded_read_cb);
+
+	return -EIOCBQUEUED;
+}
+
+int btrfs_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)
+{
+	switch (cmd->cmd_op) {
+	case BTRFS_IOC_ENCODED_READ:
+#if defined(CONFIG_64BIT) && defined(CONFIG_COMPAT)
+	case BTRFS_IOC_ENCODED_READ_32:
+#endif
+		return btrfs_uring_encoded_read(cmd, issue_flags);
+	}
+
+	io_uring_cmd_done(cmd, -EINVAL, 0, issue_flags);
+	return -EIOCBQUEUED;
+}
+
 long btrfs_ioctl(struct file *file, unsigned int
 		cmd, unsigned long arg)
 {
diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h
index 2c5dc25ec670..33578f4b5f46 100644
--- a/fs/btrfs/ioctl.h
+++ b/fs/btrfs/ioctl.h
@@ -22,5 +22,6 @@ void btrfs_sync_inode_flags_to_i_flags(struct inode *inode);
 int __pure btrfs_is_empty_uuid(u8 *uuid);
 void btrfs_update_ioctl_balance_args(struct btrfs_fs_info *fs_info,
 				     struct btrfs_ioctl_balance_args *bargs);
+int btrfs_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags);
 
 #endif
-- 
2.44.2


             reply	other threads:[~2024-08-09 17:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-09 17:35 Mark Harmstone [this message]
2024-08-09 18:34 ` [PATCH] btrfs: add io_uring interface for encoded reads David Sterba
2024-08-12  9:20   ` Mark Harmstone
2024-08-12 11:23     ` David Sterba
2024-08-12 11:26 ` Christoph Hellwig
2024-08-12 14:46   ` Mark Harmstone
2024-08-12 15:03     ` Pavel Begunkov
2024-08-12 16:10   ` Pavel Begunkov
2024-08-12 16:58     ` David Sterba
2024-08-12 19:17       ` Pavel Begunkov
2024-08-13  0:49         ` David Sterba
2024-08-13  1:06           ` Pavel Begunkov

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=20240809173552.929988-1-maharmstone@fb.com \
    --to=maharmstone@fb.com \
    --cc=linux-btrfs@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