@@ -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;
@@ -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)
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(-)