>From ad861c06ec0a35278d546dc61e687bf65090a98d Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 13 Jun 2022 20:08:08 +0100 Subject: [PATCH] nbd: Permit NBD client to set IO minimum and preferred sizes The NBD protocol permits servers to specify a minimum, preferred and maximum block size during the handshake: https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md#block-size-constraints Our NBD client previously ignored this and would send requests with smaller granularity than the server wanted (eg. 512 bytes). Allow the userspace part of the client to negotiate minimum and preferred block sizes with the server and send this information over netlink to the kernel. The maximum block size is still ignored. Signed-off-by: Richard W.M. Jones --- drivers/block/nbd.c | 11 ++++++++++- include/uapi/linux/nbd-netlink.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 07f3c139a3d7..441cdd96aa9d 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1876,6 +1876,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 +2033,14 @@ static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info) &config->runtime_flags); } } - + if (info->attrs[NBD_ATTR_BLOCK_SIZE_MIN]) { + u32 bytes = nla_get_u32(info->attrs[NBD_ATTR_BLOCK_SIZE_MIN]); + blk_queue_io_min(nbd->disk->queue, bytes); + } + if (info->attrs[NBD_ATTR_BLOCK_SIZE_OPT]) { + u32 bytes = nla_get_u32(info->attrs[NBD_ATTR_BLOCK_SIZE_OPT]); + blk_queue_io_opt(nbd->disk->queue, bytes); + } 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