Skip to content

Commit 2682832

Browse files
Christoph Hellwigaxboe
authored andcommitted
nbd: use the atomic queue limits API in nbd_set_size
Use queue_limits_start_update / queue_limits_commit_update to update all the limits in one go and with proper sanity checking. Signed-off-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 242a49e commit 2682832

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/block/nbd.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ static void nbd_mark_nsock_dead(struct nbd_device *nbd, struct nbd_sock *nsock,
319319
static int __nbd_set_size(struct nbd_device *nbd, loff_t bytesize,
320320
loff_t blksize)
321321
{
322+
struct queue_limits lim;
323+
int error;
324+
322325
if (!blksize)
323326
blksize = 1u << NBD_DEF_BLKSIZE_BITS;
324327

@@ -334,12 +337,16 @@ static int __nbd_set_size(struct nbd_device *nbd, loff_t bytesize,
334337
if (!nbd->pid)
335338
return 0;
336339

340+
lim = queue_limits_start_update(nbd->disk->queue);
337341
if (nbd->config->flags & NBD_FLAG_SEND_TRIM)
338-
blk_queue_max_discard_sectors(nbd->disk->queue, UINT_MAX);
342+
lim.max_hw_discard_sectors = UINT_MAX;
339343
else
340-
blk_queue_max_discard_sectors(nbd->disk->queue, 0);
341-
blk_queue_logical_block_size(nbd->disk->queue, blksize);
342-
blk_queue_physical_block_size(nbd->disk->queue, blksize);
344+
lim.max_hw_discard_sectors = 0;
345+
lim.logical_block_size = blksize;
346+
lim.physical_block_size = blksize;
347+
error = queue_limits_commit_update(nbd->disk->queue, &lim);
348+
if (error)
349+
return error;
343350

344351
if (max_part)
345352
set_bit(GD_NEED_PART_SCAN, &nbd->disk->state);

0 commit comments

Comments
 (0)