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

block: pass a queue_limits argument to blk_alloc_disk

Pass a queue_limits to blk_alloc_disk and apply it if non-NULL. This
will allow allocating queues with valid queue limits instead of setting
the values one at a time later.

Also change blk_alloc_disk to return an ERR_PTR instead of just NULL
which can't distinguish errors.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Link: https://lore.kernel.org/r/20240215071055.2201424-2-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
74fa8f9c 31edf4bb

+69 -52
+4 -2
arch/m68k/emu/nfblock.c
··· 117 117 dev->bsize = bsize; 118 118 dev->bshift = ffs(bsize) - 10; 119 119 120 - dev->disk = blk_alloc_disk(NUMA_NO_NODE); 121 - if (!dev->disk) 120 + dev->disk = blk_alloc_disk(NULL, NUMA_NO_NODE); 121 + if (IS_ERR(dev->disk)) { 122 + err = PTR_ERR(dev->disk); 122 123 goto free_dev; 124 + } 123 125 124 126 dev->disk->major = major_num; 125 127 dev->disk->first_minor = dev_id * 16;
+5 -3
arch/xtensa/platforms/iss/simdisk.c
··· 264 264 struct proc_dir_entry *procdir) 265 265 { 266 266 char tmp[2] = { '0' + which, 0 }; 267 - int err = -ENOMEM; 267 + int err; 268 268 269 269 dev->fd = -1; 270 270 dev->filename = NULL; 271 271 spin_lock_init(&dev->lock); 272 272 dev->users = 0; 273 273 274 - dev->gd = blk_alloc_disk(NUMA_NO_NODE); 275 - if (!dev->gd) 274 + dev->gd = blk_alloc_disk(NULL, NUMA_NO_NODE); 275 + if (IS_ERR(dev->gd)) { 276 + err = PTR_ERR(dev->gd); 276 277 goto out; 278 + } 277 279 dev->gd->major = simdisk_major; 278 280 dev->gd->first_minor = which; 279 281 dev->gd->minors = SIMDISK_MINORS;
+6 -5
block/genhd.c
··· 1391 1391 return NULL; 1392 1392 } 1393 1393 1394 - struct gendisk *__blk_alloc_disk(int node, struct lock_class_key *lkclass) 1394 + struct gendisk *__blk_alloc_disk(struct queue_limits *lim, int node, 1395 + struct lock_class_key *lkclass) 1395 1396 { 1396 - struct queue_limits lim = { }; 1397 + struct queue_limits default_lim = { }; 1397 1398 struct request_queue *q; 1398 1399 struct gendisk *disk; 1399 1400 1400 - q = blk_alloc_queue(&lim, node); 1401 + q = blk_alloc_queue(lim ? lim : &default_lim, node); 1401 1402 if (IS_ERR(q)) 1402 - return NULL; 1403 + return ERR_CAST(q); 1403 1404 1404 1405 disk = __alloc_disk_node(q, node, lkclass); 1405 1406 if (!disk) { 1406 1407 blk_put_queue(q); 1407 - return NULL; 1408 + return ERR_PTR(-ENOMEM); 1408 1409 } 1409 1410 set_bit(GD_OWNS_QUEUE, &disk->state); 1410 1411 return disk;
+4 -3
drivers/block/brd.c
··· 335 335 debugfs_create_u64(buf, 0444, brd_debugfs_dir, 336 336 &brd->brd_nr_pages); 337 337 338 - disk = brd->brd_disk = blk_alloc_disk(NUMA_NO_NODE); 339 - if (!disk) 338 + disk = brd->brd_disk = blk_alloc_disk(NULL, NUMA_NO_NODE); 339 + if (IS_ERR(disk)) { 340 + err = PTR_ERR(disk); 340 341 goto out_free_dev; 341 - 342 + } 342 343 disk->major = RAMDISK_MAJOR; 343 344 disk->first_minor = i * max_part; 344 345 disk->minors = max_part;
+4 -2
drivers/block/drbd/drbd_main.c
··· 2708 2708 2709 2709 drbd_init_set_defaults(device); 2710 2710 2711 - disk = blk_alloc_disk(NUMA_NO_NODE); 2712 - if (!disk) 2711 + disk = blk_alloc_disk(NULL, NUMA_NO_NODE); 2712 + if (IS_ERR(disk)) { 2713 + err = PTR_ERR(disk); 2713 2714 goto out_no_disk; 2715 + } 2714 2716 2715 2717 device->vdisk = disk; 2716 2718 device->rq_queue = disk->queue;
+4 -2
drivers/block/n64cart.c
··· 131 131 if (IS_ERR(reg_base)) 132 132 return PTR_ERR(reg_base); 133 133 134 - disk = blk_alloc_disk(NUMA_NO_NODE); 135 - if (!disk) 134 + disk = blk_alloc_disk(NULL, NUMA_NO_NODE); 135 + if (IS_ERR(disk)) { 136 + err = PTR_ERR(disk); 136 137 goto out; 138 + } 137 139 138 140 disk->first_minor = 0; 139 141 disk->flags = GENHD_FL_NO_PART;
+4 -3
drivers/block/null_blk/main.c
··· 2154 2154 } 2155 2155 nullb->q = nullb->disk->queue; 2156 2156 } else if (dev->queue_mode == NULL_Q_BIO) { 2157 - rv = -ENOMEM; 2158 - nullb->disk = blk_alloc_disk(nullb->dev->home_node); 2159 - if (!nullb->disk) 2157 + nullb->disk = blk_alloc_disk(NULL, nullb->dev->home_node); 2158 + if (IS_ERR(nullb->disk)) { 2159 + rv = PTR_ERR(nullb->disk); 2160 2160 goto out_cleanup_queues; 2161 + } 2161 2162 2162 2163 nullb->q = nullb->disk->queue; 2163 2164 rv = init_driver_queues(nullb);
+4 -3
drivers/block/pktcdvd.c
··· 2673 2673 pd->write_congestion_on = write_congestion_on; 2674 2674 pd->write_congestion_off = write_congestion_off; 2675 2675 2676 - ret = -ENOMEM; 2677 - disk = blk_alloc_disk(NUMA_NO_NODE); 2678 - if (!disk) 2676 + disk = blk_alloc_disk(NULL, NUMA_NO_NODE); 2677 + if (IS_ERR(disk)) { 2678 + ret = PTR_ERR(disk); 2679 2679 goto out_mem; 2680 + } 2680 2681 pd->disk = disk; 2681 2682 disk->major = pktdev_major; 2682 2683 disk->first_minor = idx;
+3 -3
drivers/block/ps3vram.c
··· 730 730 731 731 ps3vram_proc_init(dev); 732 732 733 - gendisk = blk_alloc_disk(NUMA_NO_NODE); 734 - if (!gendisk) { 733 + gendisk = blk_alloc_disk(NULL, NUMA_NO_NODE); 734 + if (IS_ERR(gendisk)) { 735 735 dev_err(&dev->core, "blk_alloc_disk failed\n"); 736 - error = -ENOMEM; 736 + error = PTR_ERR(gendisk); 737 737 goto out_cache_cleanup; 738 738 } 739 739
+3 -3
drivers/block/zram/zram_drv.c
··· 2195 2195 #endif 2196 2196 2197 2197 /* gendisk structure */ 2198 - zram->disk = blk_alloc_disk(NUMA_NO_NODE); 2199 - if (!zram->disk) { 2198 + zram->disk = blk_alloc_disk(NULL, NUMA_NO_NODE); 2199 + if (IS_ERR(zram->disk)) { 2200 2200 pr_err("Error allocating disk structure for device %d\n", 2201 2201 device_id); 2202 - ret = -ENOMEM; 2202 + ret = PTR_ERR(zram->disk); 2203 2203 goto out_free_idr; 2204 2204 } 2205 2205
+2 -2
drivers/md/bcache/super.c
··· 935 935 BIOSET_NEED_BVECS|BIOSET_NEED_RESCUER)) 936 936 goto out_ida_remove; 937 937 938 - d->disk = blk_alloc_disk(NUMA_NO_NODE); 939 - if (!d->disk) 938 + d->disk = blk_alloc_disk(NULL, NUMA_NO_NODE); 939 + if (IS_ERR(d->disk)) 940 940 goto out_bioset_exit; 941 941 942 942 set_capacity(d->disk, sectors);
+2 -2
drivers/md/dm.c
··· 2098 2098 * established. If request-based table is loaded: blk-mq will 2099 2099 * override accordingly. 2100 2100 */ 2101 - md->disk = blk_alloc_disk(md->numa_node_id); 2102 - if (!md->disk) 2101 + md->disk = blk_alloc_disk(NULL, md->numa_node_id); 2102 + if (IS_ERR(md->disk)) 2103 2103 goto bad; 2104 2104 md->queue = md->disk->queue; 2105 2105
+4 -3
drivers/md/md.c
··· 5763 5763 */ 5764 5764 mddev->hold_active = UNTIL_STOP; 5765 5765 5766 - error = -ENOMEM; 5767 - disk = blk_alloc_disk(NUMA_NO_NODE); 5768 - if (!disk) 5766 + disk = blk_alloc_disk(NULL, NUMA_NO_NODE); 5767 + if (IS_ERR(disk)) { 5768 + error = PTR_ERR(disk); 5769 5769 goto out_free_mddev; 5770 + } 5770 5771 5771 5772 disk->major = MAJOR(mddev->unit); 5772 5773 disk->first_minor = unit << shift;
+4 -4
drivers/nvdimm/btt.c
··· 1496 1496 { 1497 1497 struct nd_btt *nd_btt = btt->nd_btt; 1498 1498 struct nd_namespace_common *ndns = nd_btt->ndns; 1499 - int rc = -ENOMEM; 1499 + int rc; 1500 1500 1501 - btt->btt_disk = blk_alloc_disk(NUMA_NO_NODE); 1502 - if (!btt->btt_disk) 1503 - return -ENOMEM; 1501 + btt->btt_disk = blk_alloc_disk(NULL, NUMA_NO_NODE); 1502 + if (IS_ERR(btt->btt_disk)) 1503 + return PTR_ERR(btt->btt_disk); 1504 1504 1505 1505 nvdimm_namespace_disk_name(ndns, btt->btt_disk->disk_name); 1506 1506 btt->btt_disk->first_minor = 0;
+3 -3
drivers/nvdimm/pmem.c
··· 497 497 return -EBUSY; 498 498 } 499 499 500 - disk = blk_alloc_disk(nid); 501 - if (!disk) 502 - return -ENOMEM; 500 + disk = blk_alloc_disk(NULL, nid); 501 + if (IS_ERR(disk)) 502 + return PTR_ERR(disk); 503 503 q = disk->queue; 504 504 505 505 pmem->disk = disk;
+3 -3
drivers/nvme/host/multipath.c
··· 532 532 !nvme_is_unique_nsid(ctrl, head) || !multipath) 533 533 return 0; 534 534 535 - head->disk = blk_alloc_disk(ctrl->numa_node); 536 - if (!head->disk) 537 - return -ENOMEM; 535 + head->disk = blk_alloc_disk(NULL, ctrl->numa_node); 536 + if (IS_ERR(head->disk)) 537 + return PTR_ERR(head->disk); 538 538 head->disk->fops = &nvme_ns_head_ops; 539 539 head->disk->private_data = head; 540 540 sprintf(head->disk->disk_name, "nvme%dn%d",
+3 -3
drivers/s390/block/dcssblk.c
··· 629 629 dev_info->dev.release = dcssblk_release_segment; 630 630 dev_info->dev.groups = dcssblk_dev_attr_groups; 631 631 INIT_LIST_HEAD(&dev_info->lh); 632 - dev_info->gd = blk_alloc_disk(NUMA_NO_NODE); 633 - if (dev_info->gd == NULL) { 634 - rc = -ENOMEM; 632 + dev_info->gd = blk_alloc_disk(NULL, NUMA_NO_NODE); 633 + if (IS_ERR(dev_info->gd)) { 634 + rc = PTR_ERR(dev_info->gd); 635 635 goto seg_list_del; 636 636 } 637 637 dev_info->gd->major = dcssblk_major;
+7 -3
include/linux/blkdev.h
··· 766 766 int bdev_disk_changed(struct gendisk *disk, bool invalidate); 767 767 768 768 void put_disk(struct gendisk *disk); 769 - struct gendisk *__blk_alloc_disk(int node, struct lock_class_key *lkclass); 769 + struct gendisk *__blk_alloc_disk(struct queue_limits *lim, int node, 770 + struct lock_class_key *lkclass); 770 771 771 772 /** 772 773 * blk_alloc_disk - allocate a gendisk structure 774 + * @lim: queue limits to be used for this disk. 773 775 * @node_id: numa node to allocate on 774 776 * 775 777 * Allocate and pre-initialize a gendisk structure for use with BIO based 776 778 * drivers. 777 779 * 780 + * Returns an ERR_PTR on error, else the allocated disk. 781 + * 778 782 * Context: can sleep 779 783 */ 780 - #define blk_alloc_disk(node_id) \ 784 + #define blk_alloc_disk(lim, node_id) \ 781 785 ({ \ 782 786 static struct lock_class_key __key; \ 783 787 \ 784 - __blk_alloc_disk(node_id, &__key); \ 788 + __blk_alloc_disk(lim, node_id, &__key); \ 785 789 }) 786 790 787 791 int __register_blkdev(unsigned int major, const char *name,