Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

null_blk: Allow controlling max_hw_sectors limit

Add the module option and configfs attribute max_sectors to allow
configuring the maximum size of a command issued to a null_blk device.
This allows exercising the block layer BIO splitting with different
limits than the default BLK_SAFE_MAX_SECTORS. This is also useful for
testing the zone append write path of file systems as the max_hw_sectors
limit value is also used for the max_zone_append_sectors limit.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Damien Le Moal and committed by
Jens Axboe
ea17fd35 0ec4d913

+20 -1
+1
drivers/block/null_blk.h
··· 85 85 unsigned int home_node; /* home node for the device */ 86 86 unsigned int queue_mode; /* block interface */ 87 87 unsigned int blocksize; /* block size */ 88 + unsigned int max_sectors; /* Max sectors per command */ 88 89 unsigned int irqmode; /* IRQ completion handler */ 89 90 unsigned int hw_queue_depth; /* queue depth */ 90 91 unsigned int index; /* index of the disk, only valid with a disk */
+19 -1
drivers/block/null_blk_main.c
··· 152 152 module_param_named(bs, g_bs, int, 0444); 153 153 MODULE_PARM_DESC(bs, "Block size (in bytes)"); 154 154 155 + static int g_max_sectors; 156 + module_param_named(max_sectors, g_max_sectors, int, 0444); 157 + MODULE_PARM_DESC(max_sectors, "Maximum size of a command (in 512B sectors)"); 158 + 155 159 static unsigned int nr_devices = 1; 156 160 module_param(nr_devices, uint, 0444); 157 161 MODULE_PARM_DESC(nr_devices, "Number of devices to register"); ··· 350 346 NULLB_DEVICE_ATTR(home_node, uint, NULL); 351 347 NULLB_DEVICE_ATTR(queue_mode, uint, NULL); 352 348 NULLB_DEVICE_ATTR(blocksize, uint, NULL); 349 + NULLB_DEVICE_ATTR(max_sectors, uint, NULL); 353 350 NULLB_DEVICE_ATTR(irqmode, uint, NULL); 354 351 NULLB_DEVICE_ATTR(hw_queue_depth, uint, NULL); 355 352 NULLB_DEVICE_ATTR(index, uint, NULL); ··· 468 463 &nullb_device_attr_home_node, 469 464 &nullb_device_attr_queue_mode, 470 465 &nullb_device_attr_blocksize, 466 + &nullb_device_attr_max_sectors, 471 467 &nullb_device_attr_irqmode, 472 468 &nullb_device_attr_hw_queue_depth, 473 469 &nullb_device_attr_index, ··· 539 533 static ssize_t memb_group_features_show(struct config_item *item, char *page) 540 534 { 541 535 return snprintf(page, PAGE_SIZE, 542 - "memory_backed,discard,bandwidth,cache,badblocks,zoned,zone_size,zone_capacity,zone_nr_conv,zone_max_open,zone_max_active\n"); 536 + "memory_backed,discard,bandwidth,cache,badblocks,zoned,zone_size,zone_capacity,zone_nr_conv,zone_max_open,zone_max_active,blocksize,max_sectors\n"); 543 537 } 544 538 545 539 CONFIGFS_ATTR_RO(memb_group_, features); ··· 594 588 dev->home_node = g_home_node; 595 589 dev->queue_mode = g_queue_mode; 596 590 dev->blocksize = g_bs; 591 + dev->max_sectors = g_max_sectors; 597 592 dev->irqmode = g_irqmode; 598 593 dev->hw_queue_depth = g_hw_queue_depth; 599 594 dev->blocking = g_blocking; ··· 1874 1867 1875 1868 blk_queue_logical_block_size(nullb->q, dev->blocksize); 1876 1869 blk_queue_physical_block_size(nullb->q, dev->blocksize); 1870 + if (!dev->max_sectors) 1871 + dev->max_sectors = queue_max_hw_sectors(nullb->q); 1872 + dev->max_sectors = min_t(unsigned int, dev->max_sectors, 1873 + BLK_DEF_MAX_SECTORS); 1874 + blk_queue_max_hw_sectors(nullb->q, dev->max_sectors); 1877 1875 1878 1876 null_config_discard(nullb); 1879 1877 ··· 1920 1908 pr_warn("invalid block size\n"); 1921 1909 pr_warn("defaults block size to %lu\n", PAGE_SIZE); 1922 1910 g_bs = PAGE_SIZE; 1911 + } 1912 + 1913 + if (g_max_sectors > BLK_DEF_MAX_SECTORS) { 1914 + pr_warn("invalid max sectors\n"); 1915 + pr_warn("defaults max sectors to %u\n", BLK_DEF_MAX_SECTORS); 1916 + g_max_sectors = BLK_DEF_MAX_SECTORS; 1923 1917 } 1924 1918 1925 1919 if (g_home_node != NUMA_NO_NODE && g_home_node >= nr_online_nodes) {