From: Jens Axboe <axboe@kernel.dk>
To: io-uring@vger.kernel.org
Cc: joshi.k@samsung.com, hch@lst.de, kbusch@kernel.org,
linux-nvme@lists.infradead.org, metze@samba.org,
Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 6/8] block: add example ioctl
Date: Wed, 17 Mar 2021 16:10:25 -0600 [thread overview]
Message-ID: <20210317221027.366780-7-axboe@kernel.dk> (raw)
In-Reply-To: <20210317221027.366780-1-axboe@kernel.dk>
Grab op == 1, BLOCK_URING_OP_IOCTL, and use it to implement basic
ioctl functionality.
Example code, to issue BLKBSZGET through IORING_OP_URING_CMD:
struct block_uring_cmd {
__u32 ioctl_cmd;
__u32 unused1;
__u64 unused2[4];
};
static int get_bs(struct io_uring *ring, const char *dev)
{
struct io_uring_cqe *cqe;
struct io_uring_sqe *sqe;
struct io_uring_cmd_sqe *csqe;
struct block_uring_cmd *cmd;
int ret, fd;
fd = open(dev, O_RDONLY);
sqe = io_uring_get_sqe(ring);
csqe = (void *) sqe;
memset(csqe, 0, sizeof(*csqe));
csqe->hdr.opcode = IORING_OP_URING_CMD;
csqe->hdr.fd = fd;
csqe->user_data = 0x1234;
csqe->op = BLOCK_URING_OP_IOCTL;
io_uring_submit(ring);
io_uring_wait_cqe(ring, &cqe);
printf("bs=%d\n", cqe->res);
io_uring_cqe_seen(ring, cqe);
return 0;
err:
return 1;
}
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
fs/block_dev.c | 20 ++++++++++++++++++++
include/linux/blkdev.h | 11 +++++++++++
2 files changed, 31 insertions(+)
diff --git a/fs/block_dev.c b/fs/block_dev.c
index cbc403ad0330..9e44f63a0fe1 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -318,11 +318,31 @@ struct blkdev_dio {
static struct bio_set blkdev_dio_pool;
+static int blkdev_uring_ioctl(struct block_device *bdev,
+ struct io_uring_cmd *cmd)
+{
+ struct block_uring_cmd *bcmd = (struct block_uring_cmd *) &cmd->pdu;
+
+ switch (bcmd->ioctl_cmd) {
+ case BLKBSZGET:
+ return block_size(bdev);
+ default:
+ return -ENOTTY;
+ }
+}
+
static int blkdev_uring_cmd(struct io_uring_cmd *cmd,
enum io_uring_cmd_flags flags)
{
struct block_device *bdev = I_BDEV(cmd->file->f_mapping->host);
+ switch (cmd->op) {
+ case BLOCK_URING_OP_IOCTL:
+ return blkdev_uring_ioctl(bdev, cmd);
+ default:
+ break;
+ }
+
return blk_uring_cmd(bdev, cmd, flags);
}
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 7eb993e82783..fa895aa3b51a 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -44,6 +44,17 @@ struct blk_queue_stats;
struct blk_stat_callback;
struct blk_keyslot_manager;
+enum {
+ BLOCK_URING_OP_IOCTL = 1,
+};
+
+/* This overlays struct io_uring_cmd pdu (40 bytes) */
+struct block_uring_cmd {
+ __u32 ioctl_cmd;
+ __u32 unused1;
+ __u64 unused2[4];
+};
+
#define BLKDEV_MIN_RQ 4
#define BLKDEV_MAX_RQ 128 /* Default maximum */
--
2.31.0
WARNING: multiple messages have this Message-ID (diff)
From: Jens Axboe <axboe@kernel.dk>
To: io-uring@vger.kernel.org
Cc: joshi.k@samsung.com, hch@lst.de, kbusch@kernel.org,
linux-nvme@lists.infradead.org, metze@samba.org,
Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 6/8] block: add example ioctl
Date: Wed, 17 Mar 2021 16:10:25 -0600 [thread overview]
Message-ID: <20210317221027.366780-7-axboe@kernel.dk> (raw)
In-Reply-To: <20210317221027.366780-1-axboe@kernel.dk>
Grab op == 1, BLOCK_URING_OP_IOCTL, and use it to implement basic
ioctl functionality.
Example code, to issue BLKBSZGET through IORING_OP_URING_CMD:
struct block_uring_cmd {
__u32 ioctl_cmd;
__u32 unused1;
__u64 unused2[4];
};
static int get_bs(struct io_uring *ring, const char *dev)
{
struct io_uring_cqe *cqe;
struct io_uring_sqe *sqe;
struct io_uring_cmd_sqe *csqe;
struct block_uring_cmd *cmd;
int ret, fd;
fd = open(dev, O_RDONLY);
sqe = io_uring_get_sqe(ring);
csqe = (void *) sqe;
memset(csqe, 0, sizeof(*csqe));
csqe->hdr.opcode = IORING_OP_URING_CMD;
csqe->hdr.fd = fd;
csqe->user_data = 0x1234;
csqe->op = BLOCK_URING_OP_IOCTL;
io_uring_submit(ring);
io_uring_wait_cqe(ring, &cqe);
printf("bs=%d\n", cqe->res);
io_uring_cqe_seen(ring, cqe);
return 0;
err:
return 1;
}
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
fs/block_dev.c | 20 ++++++++++++++++++++
include/linux/blkdev.h | 11 +++++++++++
2 files changed, 31 insertions(+)
diff --git a/fs/block_dev.c b/fs/block_dev.c
index cbc403ad0330..9e44f63a0fe1 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -318,11 +318,31 @@ struct blkdev_dio {
static struct bio_set blkdev_dio_pool;
+static int blkdev_uring_ioctl(struct block_device *bdev,
+ struct io_uring_cmd *cmd)
+{
+ struct block_uring_cmd *bcmd = (struct block_uring_cmd *) &cmd->pdu;
+
+ switch (bcmd->ioctl_cmd) {
+ case BLKBSZGET:
+ return block_size(bdev);
+ default:
+ return -ENOTTY;
+ }
+}
+
static int blkdev_uring_cmd(struct io_uring_cmd *cmd,
enum io_uring_cmd_flags flags)
{
struct block_device *bdev = I_BDEV(cmd->file->f_mapping->host);
+ switch (cmd->op) {
+ case BLOCK_URING_OP_IOCTL:
+ return blkdev_uring_ioctl(bdev, cmd);
+ default:
+ break;
+ }
+
return blk_uring_cmd(bdev, cmd, flags);
}
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 7eb993e82783..fa895aa3b51a 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -44,6 +44,17 @@ struct blk_queue_stats;
struct blk_stat_callback;
struct blk_keyslot_manager;
+enum {
+ BLOCK_URING_OP_IOCTL = 1,
+};
+
+/* This overlays struct io_uring_cmd pdu (40 bytes) */
+struct block_uring_cmd {
+ __u32 ioctl_cmd;
+ __u32 unused1;
+ __u64 unused2[4];
+};
+
#define BLKDEV_MIN_RQ 4
#define BLKDEV_MAX_RQ 128 /* Default maximum */
--
2.31.0
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
next prev parent reply other threads:[~2021-03-17 22:11 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-17 22:10 [PATCHSET v4 0/8] io_uring passthrough support Jens Axboe
2021-03-17 22:10 ` Jens Axboe
2021-03-17 22:10 ` [PATCH 1/8] io_uring: split up io_uring_sqe into hdr + main Jens Axboe
2021-03-17 22:10 ` Jens Axboe
2021-03-18 5:34 ` Christoph Hellwig
2021-03-18 5:34 ` Christoph Hellwig
2021-03-18 18:40 ` Jens Axboe
2021-03-18 18:40 ` Jens Axboe
2021-03-19 11:20 ` Stefan Metzmacher
2021-03-19 11:20 ` Stefan Metzmacher
2021-03-19 13:29 ` Christoph Hellwig
2021-03-19 13:29 ` Christoph Hellwig
2022-02-24 22:34 ` Luis Chamberlain
2021-03-17 22:10 ` [PATCH 2/8] io_uring: add infrastructure around io_uring_cmd_sqe issue type Jens Axboe
2021-03-17 22:10 ` Jens Axboe
2021-03-17 22:10 ` [PATCH 3/8] fs: add file_operations->uring_cmd() Jens Axboe
2021-03-17 22:10 ` Jens Axboe
2021-03-18 5:38 ` Christoph Hellwig
2021-03-18 5:38 ` Christoph Hellwig
2021-03-18 18:41 ` Jens Axboe
2021-03-18 18:41 ` Jens Axboe
2022-02-17 1:27 ` Luis Chamberlain
2022-02-17 1:25 ` Luis Chamberlain
2021-03-17 22:10 ` [PATCH 4/8] io_uring: add support for IORING_OP_URING_CMD Jens Axboe
2021-03-17 22:10 ` Jens Axboe
2021-03-18 5:42 ` Christoph Hellwig
2021-03-18 5:42 ` Christoph Hellwig
2021-03-18 18:43 ` Jens Axboe
2021-03-18 18:43 ` Jens Axboe
2021-03-17 22:10 ` [PATCH 5/8] block: wire up support for file_operations->uring_cmd() Jens Axboe
2021-03-17 22:10 ` Jens Axboe
2021-03-18 5:44 ` Christoph Hellwig
2021-03-18 5:44 ` Christoph Hellwig
2021-03-17 22:10 ` Jens Axboe [this message]
2021-03-17 22:10 ` [PATCH 6/8] block: add example ioctl Jens Axboe
2021-03-18 5:45 ` Christoph Hellwig
2021-03-18 5:45 ` Christoph Hellwig
2021-03-18 12:43 ` Pavel Begunkov
2021-03-18 12:43 ` Pavel Begunkov
2021-03-18 18:44 ` Jens Axboe
2021-03-18 18:44 ` Jens Axboe
2021-03-17 22:10 ` [PATCH 7/8] net: wire up support for file_operations->uring_cmd() Jens Axboe
2021-03-17 22:10 ` Jens Axboe
2022-02-17 1:03 ` Luis Chamberlain
2021-03-17 22:10 ` [PATCH 8/8] net: add example SOCKET_URING_OP_SIOCINQ/SOCKET_URING_OP_SIOCOUTQ Jens Axboe
2021-03-17 22:10 ` Jens Axboe
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=20210317221027.366780-7-axboe@kernel.dk \
--to=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=io-uring@vger.kernel.org \
--cc=joshi.k@samsung.com \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=metze@samba.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.