nbd: Permit nbd-client to set minimum and optimal I/O sizes
Subsystems (3)
PATCH 1/1 nbd: Permit nbd-client to set minimum and optimal I/O sizes
This is a small change to the nbd kernel driver which allows the client to set minimum_io_size and optimal_io_size hints for the NBD device.
There is an accompanying patch for nbd-client (userspace tool) which I will send separately.
Rich.
PATCH 1/1 nbd: Permit nbd-client to set minimum and optimal I/O sizes
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 <[email protected]>
--- drivers/block/nbd.c | 17 ++++++++++++++++- include/uapi/linux/nbd-netlink.h | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-)
drivers/block/nbd.c +16 -1
@@ -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;
include/uapi/linux/nbd-netlink.h +2 -0
@@ -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)
Signature · 1 line
2.35.1