mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Richard W.M. Jones" <rjones@redhat.com>
To: josef@toxicpanda.com
Cc: axboe@kernel.dk, prasanna.kalever@redhat.com, xiubli@redhat.com,
	ming.lei@redhat.com, linux-block@vger.kernel.org,
	nbd@other.debian.org, linux-kernel@vger.kernel.org,
	eblake@redhat.com
Subject: [PATCH] nbd: Permit nbd-client to set minimum and optimal I/O sizes
Date: Thu, 16 Jun 2022 12:24:49 +0100	[thread overview]
Message-ID: <20220616112449.3222664-2-rjones@redhat.com> (raw)
In-Reply-To: <20220616112449.3222664-1-rjones@redhat.com>

Add new netlink attributes to allow the userspace nbd-client to
control the minimum_io_size and optimal_io_size settings.

This is the kernel part of an effort to implement NBD block size
constraints.

Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
Link: https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md#block-size-constraints
Link: https://lists.debian.org/nbd/2022/06/msg00022.html
---
 drivers/block/nbd.c              | 17 ++++++++++++++++-
 include/uapi/linux/nbd-netlink.h |  2 ++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 07f3c139a3d7..ff51b5c577b2 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -99,6 +99,7 @@ struct nbd_config {
 	wait_queue_head_t recv_wq;
 	unsigned int blksize_bits;
 	loff_t bytesize;
+	u32 minimum_io_size, optimal_io_size;
 #if IS_ENABLED(CONFIG_DEBUG_FS)
 	struct dentry *dbg_dir;
 #endif
@@ -338,6 +339,13 @@ static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize,
 	blk_queue_logical_block_size(nbd->disk->queue, blksize);
 	blk_queue_physical_block_size(nbd->disk->queue, blksize);
 
+	if (nbd->config->minimum_io_size)
+		blk_queue_io_min(nbd->disk->queue,
+				 nbd->config->minimum_io_size);
+	if (nbd->config->optimal_io_size)
+		blk_queue_io_opt(nbd->disk->queue,
+				 nbd->config->optimal_io_size);
+
 	if (max_part)
 		set_bit(GD_NEED_PART_SCAN, &nbd->disk->state);
 	if (!set_capacity_and_notify(nbd->disk, bytesize >> 9))
@@ -1876,6 +1884,8 @@ static const struct nla_policy nbd_attr_policy[NBD_ATTR_MAX + 1] = {
 	[NBD_ATTR_DEAD_CONN_TIMEOUT]	=	{ .type = NLA_U64 },
 	[NBD_ATTR_DEVICE_LIST]		=	{ .type = NLA_NESTED},
 	[NBD_ATTR_BACKEND_IDENTIFIER]	=	{ .type = NLA_STRING},
+	[NBD_ATTR_BLOCK_SIZE_MIN]	=	{ .type = NLA_U32 },
+	[NBD_ATTR_BLOCK_SIZE_OPT]	=	{ .type = NLA_U32 },
 };
 
 static const struct nla_policy nbd_sock_policy[NBD_SOCK_MAX + 1] = {
@@ -2031,7 +2041,12 @@ static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
 				&config->runtime_flags);
 		}
 	}
-
+	if (info->attrs[NBD_ATTR_BLOCK_SIZE_MIN])
+		config->minimum_io_size =
+			nla_get_u32(info->attrs[NBD_ATTR_BLOCK_SIZE_MIN]);
+	if (info->attrs[NBD_ATTR_BLOCK_SIZE_OPT])
+		config->optimal_io_size =
+			nla_get_u32(info->attrs[NBD_ATTR_BLOCK_SIZE_OPT]);
 	if (info->attrs[NBD_ATTR_SOCKETS]) {
 		struct nlattr *attr;
 		int rem, fd;
diff --git a/include/uapi/linux/nbd-netlink.h b/include/uapi/linux/nbd-netlink.h
index 2d0b90964227..1d6621487560 100644
--- a/include/uapi/linux/nbd-netlink.h
+++ b/include/uapi/linux/nbd-netlink.h
@@ -36,6 +36,8 @@ enum {
 	NBD_ATTR_DEAD_CONN_TIMEOUT,
 	NBD_ATTR_DEVICE_LIST,
 	NBD_ATTR_BACKEND_IDENTIFIER,
+	NBD_ATTR_BLOCK_SIZE_MIN,
+	NBD_ATTR_BLOCK_SIZE_OPT,
 	__NBD_ATTR_MAX,
 };
 #define NBD_ATTR_MAX (__NBD_ATTR_MAX - 1)
-- 
2.35.1


      reply	other threads:[~2022-06-16 11:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-16 11:24 Richard W.M. Jones
2022-06-16 11:24 ` Richard W.M. Jones [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=20220616112449.3222664-2-rjones@redhat.com \
    --to=rjones@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=eblake@redhat.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=nbd@other.debian.org \
    --cc=prasanna.kalever@redhat.com \
    --cc=xiubli@redhat.com \
    /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

all inboxes | Powered by JetHome®