Skip to content

Commit b38c8be

Browse files
Christoph Hellwigaxboe
authored andcommitted
loop: refactor queue limits updates
Replace loop_reconfigure_limits with a slightly less encompassing loop_update_limits that expects the caller to acquire and commit the queue limits to prepare for sorting out the freeze vs limits lock ordering. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Ming Lei <[email protected]> Reviewed-by: Damien Le Moal <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Reviewed-by: Nilay Shroff <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 1233751 commit b38c8be

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

drivers/block/loop.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -977,12 +977,12 @@ static unsigned int loop_default_blocksize(struct loop_device *lo,
977977
return SECTOR_SIZE;
978978
}
979979

980-
static int loop_reconfigure_limits(struct loop_device *lo, unsigned int bsize)
980+
static void loop_update_limits(struct loop_device *lo, struct queue_limits *lim,
981+
unsigned int bsize)
981982
{
982983
struct file *file = lo->lo_backing_file;
983984
struct inode *inode = file->f_mapping->host;
984985
struct block_device *backing_bdev = NULL;
985-
struct queue_limits lim;
986986
u32 granularity = 0, max_discard_sectors = 0;
987987

988988
if (S_ISBLK(inode->i_mode))
@@ -995,22 +995,20 @@ static int loop_reconfigure_limits(struct loop_device *lo, unsigned int bsize)
995995

996996
loop_get_discard_config(lo, &granularity, &max_discard_sectors);
997997

998-
lim = queue_limits_start_update(lo->lo_queue);
999-
lim.logical_block_size = bsize;
1000-
lim.physical_block_size = bsize;
1001-
lim.io_min = bsize;
1002-
lim.features &= ~(BLK_FEAT_WRITE_CACHE | BLK_FEAT_ROTATIONAL);
998+
lim->logical_block_size = bsize;
999+
lim->physical_block_size = bsize;
1000+
lim->io_min = bsize;
1001+
lim->features &= ~(BLK_FEAT_WRITE_CACHE | BLK_FEAT_ROTATIONAL);
10031002
if (file->f_op->fsync && !(lo->lo_flags & LO_FLAGS_READ_ONLY))
1004-
lim.features |= BLK_FEAT_WRITE_CACHE;
1003+
lim->features |= BLK_FEAT_WRITE_CACHE;
10051004
if (backing_bdev && !bdev_nonrot(backing_bdev))
1006-
lim.features |= BLK_FEAT_ROTATIONAL;
1007-
lim.max_hw_discard_sectors = max_discard_sectors;
1008-
lim.max_write_zeroes_sectors = max_discard_sectors;
1005+
lim->features |= BLK_FEAT_ROTATIONAL;
1006+
lim->max_hw_discard_sectors = max_discard_sectors;
1007+
lim->max_write_zeroes_sectors = max_discard_sectors;
10091008
if (max_discard_sectors)
1010-
lim.discard_granularity = granularity;
1009+
lim->discard_granularity = granularity;
10111010
else
1012-
lim.discard_granularity = 0;
1013-
return queue_limits_commit_update(lo->lo_queue, &lim);
1011+
lim->discard_granularity = 0;
10141012
}
10151013

10161014
static int loop_configure(struct loop_device *lo, blk_mode_t mode,
@@ -1019,6 +1017,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
10191017
{
10201018
struct file *file = fget(config->fd);
10211019
struct address_space *mapping;
1020+
struct queue_limits lim;
10221021
int error;
10231022
loff_t size;
10241023
bool partscan;
@@ -1090,7 +1089,9 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
10901089
lo->old_gfp_mask = mapping_gfp_mask(mapping);
10911090
mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
10921091

1093-
error = loop_reconfigure_limits(lo, config->block_size);
1092+
lim = queue_limits_start_update(lo->lo_queue);
1093+
loop_update_limits(lo, &lim, config->block_size);
1094+
error = queue_limits_commit_update(lo->lo_queue, &lim);
10941095
if (error)
10951096
goto out_unlock;
10961097

@@ -1458,6 +1459,7 @@ static int loop_set_dio(struct loop_device *lo, unsigned long arg)
14581459

14591460
static int loop_set_block_size(struct loop_device *lo, unsigned long arg)
14601461
{
1462+
struct queue_limits lim;
14611463
int err = 0;
14621464

14631465
if (lo->lo_state != Lo_bound)
@@ -1470,7 +1472,9 @@ static int loop_set_block_size(struct loop_device *lo, unsigned long arg)
14701472
invalidate_bdev(lo->lo_device);
14711473

14721474
blk_mq_freeze_queue(lo->lo_queue);
1473-
err = loop_reconfigure_limits(lo, arg);
1475+
lim = queue_limits_start_update(lo->lo_queue);
1476+
loop_update_limits(lo, &lim, arg);
1477+
err = queue_limits_commit_update(lo->lo_queue, &lim);
14741478
loop_update_dio(lo);
14751479
blk_mq_unfreeze_queue(lo->lo_queue);
14761480

0 commit comments

Comments
 (0)