nbd: pass queue_limits to blk_mq_alloc_disk
authorChristoph Hellwig <hch@lst.de>
Thu, 15 Feb 2024 07:02:48 +0000 (08:02 +0100)
committerJens Axboe <axboe@kernel.dk>
Mon, 19 Feb 2024 23:59:31 +0000 (16:59 -0700)
Pass the few limits nbd imposes directly to blk_mq_alloc_disk instead
of setting them one at a time.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20240215070300.2200308-6-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/nbd.c

index d2b422d..9ee9587 100644 (file)
@@ -1783,6 +1783,12 @@ static const struct blk_mq_ops nbd_mq_ops = {
 
 static struct nbd_device *nbd_dev_add(int index, unsigned int refs)
 {
+       struct queue_limits lim = {
+               .max_hw_sectors         = 65536,
+               .max_user_sectors       = 256,
+               .max_segments           = USHRT_MAX,
+               .max_segment_size       = UINT_MAX,
+       };
        struct nbd_device *nbd;
        struct gendisk *disk;
        int err = -ENOMEM;
@@ -1823,7 +1829,7 @@ static struct nbd_device *nbd_dev_add(int index, unsigned int refs)
        if (err < 0)
                goto out_free_tags;
 
-       disk = blk_mq_alloc_disk(&nbd->tag_set, NULL, NULL);
+       disk = blk_mq_alloc_disk(&nbd->tag_set, &lim, NULL);
        if (IS_ERR(disk)) {
                err = PTR_ERR(disk);
                goto out_free_idr;
@@ -1843,11 +1849,6 @@ static struct nbd_device *nbd_dev_add(int index, unsigned int refs)
         * Tell the block layer that we are not a rotational device
         */
        blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue);
-       blk_queue_max_discard_sectors(disk->queue, 0);
-       blk_queue_max_segment_size(disk->queue, UINT_MAX);
-       blk_queue_max_segments(disk->queue, USHRT_MAX);
-       blk_queue_max_hw_sectors(disk->queue, 65536);
-       disk->queue->limits.max_sectors = 256;
 
        mutex_init(&nbd->config_lock);
        refcount_set(&nbd->config_refs, 0);