summaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-07-16 00:20:52 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-07-16 00:20:52 -0400
commit9637d517347e80ee2fe1c5d8ce45ba1b88d8b5cd (patch)
tree3cee2a1d8b3c6ea466924517307a1f98ada1e92f /drivers/block
parent273cbf61c3ddee9574ef1f4959b9bc6db5b24271 (diff)
parent787c79d6393fc028887cc1b6066915f0b094e92f (diff)
Merge tag 'for-linus-20190715' of git://git.kernel.dk/linux-block
Pull more block updates from Jens Axboe: "A later pull request with some followup items. I had some vacation coming up to the merge window, so certain things items were delayed a bit. This pull request also contains fixes that came in within the last few days of the merge window, which I didn't want to push right before sending you a pull request. This contains: - NVMe pull request, mostly fixes, but also a few minor items on the feature side that were timing constrained (Christoph et al) - Report zones fixes (Damien) - Removal of dead code (Damien) - Turn on cgroup psi memstall (Josef) - block cgroup MAINTAINERS entry (Konstantin) - Flush init fix (Josef) - blk-throttle low iops timing fix (Konstantin) - nbd resize fixes (Mike) - nbd 0 blocksize crash fix (Xiubo) - block integrity error leak fix (Wenwen) - blk-cgroup writeback and priority inheritance fixes (Tejun)" * tag 'for-linus-20190715' of git://git.kernel.dk/linux-block: (42 commits) MAINTAINERS: add entry for block io cgroup null_blk: fixup ->report_zones() for !CONFIG_BLK_DEV_ZONED block: Limit zone array allocation size sd_zbc: Fix report zones buffer allocation block: Kill gfp_t argument of blkdev_report_zones() block: Allow mapping of vmalloc-ed buffers block/bio-integrity: fix a memory leak bug nvme: fix NULL deref for fabrics options nbd: add netlink reconfigure resize support nbd: fix crash when the blksize is zero block: Disable write plugging for zoned block devices block: Fix elevator name declaration block: Remove unused definitions nvme: fix regression upon hot device removal and insertion blk-throttle: fix zero wait time for iops throttled group block: Fix potential overflow in blk_report_zones() blkcg: implement REQ_CGROUP_PUNT blkcg, writeback: Implement wbc_blkcg_css() blkcg, writeback: Add wbc->no_cgroup_owner blkcg, writeback: Rename wbc_account_io() to wbc_account_cgroup_owner() ...
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/nbd.c59
-rw-r--r--drivers/block/null_blk.h5
-rw-r--r--drivers/block/null_blk_zoned.c3
3 files changed, 49 insertions, 18 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 3a9bca3aa093..9bcde2325893 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -134,6 +134,8 @@ static struct dentry *nbd_dbg_dir;
134 134
135#define NBD_MAGIC 0x68797548 135#define NBD_MAGIC 0x68797548
136 136
137#define NBD_DEF_BLKSIZE 1024
138
137static unsigned int nbds_max = 16; 139static unsigned int nbds_max = 16;
138static int max_part = 16; 140static int max_part = 16;
139static struct workqueue_struct *recv_workqueue; 141static struct workqueue_struct *recv_workqueue;
@@ -1236,6 +1238,14 @@ static void nbd_clear_sock_ioctl(struct nbd_device *nbd,
1236 nbd_config_put(nbd); 1238 nbd_config_put(nbd);
1237} 1239}
1238 1240
1241static bool nbd_is_valid_blksize(unsigned long blksize)
1242{
1243 if (!blksize || !is_power_of_2(blksize) || blksize < 512 ||
1244 blksize > PAGE_SIZE)
1245 return false;
1246 return true;
1247}
1248
1239/* Must be called with config_lock held */ 1249/* Must be called with config_lock held */
1240static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd, 1250static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
1241 unsigned int cmd, unsigned long arg) 1251 unsigned int cmd, unsigned long arg)
@@ -1251,8 +1261,9 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
1251 case NBD_SET_SOCK: 1261 case NBD_SET_SOCK:
1252 return nbd_add_socket(nbd, arg, false); 1262 return nbd_add_socket(nbd, arg, false);
1253 case NBD_SET_BLKSIZE: 1263 case NBD_SET_BLKSIZE:
1254 if (!arg || !is_power_of_2(arg) || arg < 512 || 1264 if (!arg)
1255 arg > PAGE_SIZE) 1265 arg = NBD_DEF_BLKSIZE;
1266 if (!nbd_is_valid_blksize(arg))
1256 return -EINVAL; 1267 return -EINVAL;
1257 nbd_size_set(nbd, arg, 1268 nbd_size_set(nbd, arg,
1258 div_s64(config->bytesize, arg)); 1269 div_s64(config->bytesize, arg));
@@ -1332,7 +1343,7 @@ static struct nbd_config *nbd_alloc_config(void)
1332 atomic_set(&config->recv_threads, 0); 1343 atomic_set(&config->recv_threads, 0);
1333 init_waitqueue_head(&config->recv_wq); 1344 init_waitqueue_head(&config->recv_wq);
1334 init_waitqueue_head(&config->conn_wait); 1345 init_waitqueue_head(&config->conn_wait);
1335 config->blksize = 1024; 1346 config->blksize = NBD_DEF_BLKSIZE;
1336 atomic_set(&config->live_connections, 0); 1347 atomic_set(&config->live_connections, 0);
1337 try_module_get(THIS_MODULE); 1348 try_module_get(THIS_MODULE);
1338 return config; 1349 return config;
@@ -1673,6 +1684,30 @@ nbd_device_policy[NBD_DEVICE_ATTR_MAX + 1] = {
1673 [NBD_DEVICE_CONNECTED] = { .type = NLA_U8 }, 1684 [NBD_DEVICE_CONNECTED] = { .type = NLA_U8 },
1674}; 1685};
1675 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
1676static 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)
1677{ 1712{
1678 struct nbd_device *nbd = NULL; 1713 struct nbd_device *nbd = NULL;
@@ -1760,16 +1795,10 @@ again:
1760 refcount_set(&nbd->config_refs, 1); 1795 refcount_set(&nbd->config_refs, 1);
1761 set_bit(NBD_BOUND, &config->runtime_flags); 1796 set_bit(NBD_BOUND, &config->runtime_flags);
1762 1797
1763 if (info->attrs[NBD_ATTR_SIZE_BYTES]) { 1798 ret = nbd_genl_size_set(info, nbd);
1764 u64 bytes = nla_get_u64(info->attrs[NBD_ATTR_SIZE_BYTES]); 1799 if (ret)
1765 nbd_size_set(nbd, config->blksize, 1800 goto out;
1766 div64_u64(bytes, config->blksize)); 1801
1767 }
1768 if (info->attrs[NBD_ATTR_BLOCK_SIZE_BYTES]) {
1769 u64 bsize =
1770 nla_get_u64(info->attrs[NBD_ATTR_BLOCK_SIZE_BYTES]);
1771 nbd_size_set(nbd, bsize, div64_u64(config->bytesize, bsize));
1772 }
1773 if (info->attrs[NBD_ATTR_TIMEOUT]) { 1802 if (info->attrs[NBD_ATTR_TIMEOUT]) {
1774 u64 timeout = nla_get_u64(info->attrs[NBD_ATTR_TIMEOUT]); 1803 u64 timeout = nla_get_u64(info->attrs[NBD_ATTR_TIMEOUT]);
1775 nbd->tag_set.timeout = timeout * HZ; 1804 nbd->tag_set.timeout = timeout * HZ;
@@ -1938,6 +1967,10 @@ static int nbd_genl_reconfigure(struct sk_buff *skb, struct genl_info *info)
1938 goto out; 1967 goto out;
1939 } 1968 }
1940 1969
1970 ret = nbd_genl_size_set(info, nbd);
1971 if (ret)
1972 goto out;
1973
1941 if (info->attrs[NBD_ATTR_TIMEOUT]) { 1974 if (info->attrs[NBD_ATTR_TIMEOUT]) {
1942 u64 timeout = nla_get_u64(info->attrs[NBD_ATTR_TIMEOUT]); 1975 u64 timeout = nla_get_u64(info->attrs[NBD_ATTR_TIMEOUT]);
1943 nbd->tag_set.timeout = timeout * HZ; 1976 nbd->tag_set.timeout = timeout * HZ;
diff --git a/drivers/block/null_blk.h b/drivers/block/null_blk.h
index 34b22d6523ba..a1b9929bd911 100644
--- a/drivers/block/null_blk.h
+++ b/drivers/block/null_blk.h
@@ -89,8 +89,7 @@ struct nullb {
89int null_zone_init(struct nullb_device *dev); 89int null_zone_init(struct nullb_device *dev);
90void null_zone_exit(struct nullb_device *dev); 90void null_zone_exit(struct nullb_device *dev);
91int null_zone_report(struct gendisk *disk, sector_t sector, 91int null_zone_report(struct gendisk *disk, sector_t sector,
92 struct blk_zone *zones, unsigned int *nr_zones, 92 struct blk_zone *zones, unsigned int *nr_zones);
93 gfp_t gfp_mask);
94void null_zone_write(struct nullb_cmd *cmd, sector_t sector, 93void null_zone_write(struct nullb_cmd *cmd, sector_t sector,
95 unsigned int nr_sectors); 94 unsigned int nr_sectors);
96void null_zone_reset(struct nullb_cmd *cmd, sector_t sector); 95void null_zone_reset(struct nullb_cmd *cmd, sector_t sector);
@@ -103,7 +102,7 @@ static inline int null_zone_init(struct nullb_device *dev)
103static inline void null_zone_exit(struct nullb_device *dev) {} 102static inline void null_zone_exit(struct nullb_device *dev) {}
104static inline int null_zone_report(struct gendisk *disk, sector_t sector, 103static inline int null_zone_report(struct gendisk *disk, sector_t sector,
105 struct blk_zone *zones, 104 struct blk_zone *zones,
106 unsigned int *nr_zones, gfp_t gfp_mask) 105 unsigned int *nr_zones)
107{ 106{
108 return -EOPNOTSUPP; 107 return -EOPNOTSUPP;
109} 108}
diff --git a/drivers/block/null_blk_zoned.c b/drivers/block/null_blk_zoned.c
index fca0c97ff1aa..cb28d93f2bd1 100644
--- a/drivers/block/null_blk_zoned.c
+++ b/drivers/block/null_blk_zoned.c
@@ -67,8 +67,7 @@ void null_zone_exit(struct nullb_device *dev)
67} 67}
68 68
69int null_zone_report(struct gendisk *disk, sector_t sector, 69int null_zone_report(struct gendisk *disk, sector_t sector,
70 struct blk_zone *zones, unsigned int *nr_zones, 70 struct blk_zone *zones, unsigned int *nr_zones)
71 gfp_t gfp_mask)
72{ 71{
73 struct nullb *nullb = disk->private_data; 72 struct nullb *nullb = disk->private_data;
74 struct nullb_device *dev = nullb->dev; 73 struct nullb_device *dev = nullb->dev;