summaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
authorMike Christie <mchristi@redhat.com>2019-05-29 16:16:06 -0400
committerJens Axboe <axboe@kernel.dk>2019-07-10 23:21:31 -0400
commit4ddeaae8903d703201e493e2d19dc9ac9acf2c76 (patch)
tree252647734366ae886edc2ee667b1b81d7c352f0b /drivers/block
parent553768d1169a48c0cd87c4eb4ab57534ee663415 (diff)
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 <josef@toxicpanda.com> Signed-off-by: Mike Christie <mchristi@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/nbd.c48
1 files changed, 32 insertions, 16 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 5c4e3f2160bf..9bcde2325893 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1684,6 +1684,30 @@ nbd_device_policy[NBD_DEVICE_ATTR_MAX + 1] = {
1684 [NBD_DEVICE_CONNECTED] = { .type = NLA_U8 }, 1684 [NBD_DEVICE_CONNECTED] = { .type = NLA_U8 },
1685}; 1685};
1686 1686
1687static 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
1687static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info) 1711static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
1688{ 1712{
1689 struct nbd_device *nbd = NULL; 1713 struct nbd_device *nbd = NULL;
@@ -1771,22 +1795,10 @@ again:
1771 refcount_set(&nbd->config_refs, 1); 1795 refcount_set(&nbd->config_refs, 1);
1772 set_bit(NBD_BOUND, &config->runtime_flags); 1796 set_bit(NBD_BOUND, &config->runtime_flags);
1773 1797
1774 if (info->attrs[NBD_ATTR_SIZE_BYTES]) { 1798 ret = nbd_genl_size_set(info, nbd);
1775 u64 bytes = nla_get_u64(info->attrs[NBD_ATTR_SIZE_BYTES]); 1799 if (ret)
1776 nbd_size_set(nbd, config->blksize, 1800 goto out;
1777 div64_u64(bytes, config->blksize)); 1801
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 }
1790 if (info->attrs[NBD_ATTR_TIMEOUT]) { 1802 if (info->attrs[NBD_ATTR_TIMEOUT]) {
1791 u64 timeout = nla_get_u64(info->attrs[NBD_ATTR_TIMEOUT]); 1803 u64 timeout = nla_get_u64(info->attrs[NBD_ATTR_TIMEOUT]);
1792 nbd->tag_set.timeout = timeout * HZ; 1804 nbd->tag_set.timeout = timeout * HZ;
@@ -1955,6 +1967,10 @@ static int nbd_genl_reconfigure(struct sk_buff *skb, struct genl_info *info)
1955 goto out; 1967 goto out;
1956 } 1968 }
1957 1969
1970 ret = nbd_genl_size_set(info, nbd);
1971 if (ret)
1972 goto out;
1973
1958 if (info->attrs[NBD_ATTR_TIMEOUT]) { 1974 if (info->attrs[NBD_ATTR_TIMEOUT]) {
1959 u64 timeout = nla_get_u64(info->attrs[NBD_ATTR_TIMEOUT]); 1975 u64 timeout = nla_get_u64(info->attrs[NBD_ATTR_TIMEOUT]);
1960 nbd->tag_set.timeout = timeout * HZ; 1976 nbd->tag_set.timeout = timeout * HZ;