Skip to content

Commit 4ddeaae

Browse files
Mike Christieaxboe
authored andcommitted
nbd: add netlink reconfigure resize support
If the device is setup with ioctl we can resize the device after the initial setup, but if the device is setup with netlink we cannot use the resize related ioctls and there is no netlink reconfigure size ATTR handling code. This patch adds netlink reconfigure resize support to match the ioctl interface. Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Mike Christie <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 553768d commit 4ddeaae

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

drivers/block/nbd.c

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,30 @@ nbd_device_policy[NBD_DEVICE_ATTR_MAX + 1] = {
16841684
[NBD_DEVICE_CONNECTED] = { .type = NLA_U8 },
16851685
};
16861686

1687+
static int nbd_genl_size_set(struct genl_info *info, struct nbd_device *nbd)
1688+
{
1689+
struct nbd_config *config = nbd->config;
1690+
u64 bsize = config->blksize;
1691+
u64 bytes = config->bytesize;
1692+
1693+
if (info->attrs[NBD_ATTR_SIZE_BYTES])
1694+
bytes = nla_get_u64(info->attrs[NBD_ATTR_SIZE_BYTES]);
1695+
1696+
if (info->attrs[NBD_ATTR_BLOCK_SIZE_BYTES]) {
1697+
bsize = nla_get_u64(info->attrs[NBD_ATTR_BLOCK_SIZE_BYTES]);
1698+
if (!bsize)
1699+
bsize = NBD_DEF_BLKSIZE;
1700+
if (!nbd_is_valid_blksize(bsize)) {
1701+
printk(KERN_ERR "Invalid block size %llu\n", bsize);
1702+
return -EINVAL;
1703+
}
1704+
}
1705+
1706+
if (bytes != config->bytesize || bsize != config->blksize)
1707+
nbd_size_set(nbd, bsize, div64_u64(bytes, bsize));
1708+
return 0;
1709+
}
1710+
16871711
static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
16881712
{
16891713
struct nbd_device *nbd = NULL;
@@ -1771,22 +1795,10 @@ static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
17711795
refcount_set(&nbd->config_refs, 1);
17721796
set_bit(NBD_BOUND, &config->runtime_flags);
17731797

1774-
if (info->attrs[NBD_ATTR_SIZE_BYTES]) {
1775-
u64 bytes = nla_get_u64(info->attrs[NBD_ATTR_SIZE_BYTES]);
1776-
nbd_size_set(nbd, config->blksize,
1777-
div64_u64(bytes, config->blksize));
1778-
}
1779-
if (info->attrs[NBD_ATTR_BLOCK_SIZE_BYTES]) {
1780-
u64 bsize =
1781-
nla_get_u64(info->attrs[NBD_ATTR_BLOCK_SIZE_BYTES]);
1782-
if (!bsize)
1783-
bsize = NBD_DEF_BLKSIZE;
1784-
if (!nbd_is_valid_blksize(bsize)) {
1785-
ret = -EINVAL;
1786-
goto out;
1787-
}
1788-
nbd_size_set(nbd, bsize, div64_u64(config->bytesize, bsize));
1789-
}
1798+
ret = nbd_genl_size_set(info, nbd);
1799+
if (ret)
1800+
goto out;
1801+
17901802
if (info->attrs[NBD_ATTR_TIMEOUT]) {
17911803
u64 timeout = nla_get_u64(info->attrs[NBD_ATTR_TIMEOUT]);
17921804
nbd->tag_set.timeout = timeout * HZ;
@@ -1955,6 +1967,10 @@ static int nbd_genl_reconfigure(struct sk_buff *skb, struct genl_info *info)
19551967
goto out;
19561968
}
19571969

1970+
ret = nbd_genl_size_set(info, nbd);
1971+
if (ret)
1972+
goto out;
1973+
19581974
if (info->attrs[NBD_ATTR_TIMEOUT]) {
19591975
u64 timeout = nla_get_u64(info->attrs[NBD_ATTR_TIMEOUT]);
19601976
nbd->tag_set.timeout = timeout * HZ;

0 commit comments

Comments
 (0)