Skip to content

Commit aa427d7

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: add a queue_limits_commit_update_frozen helper
Add a helper that freezes the queue, updates the queue limits and unfreezes the queue and convert all open coded versions of that to the new helper. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: John Garry <[email protected]> Reviewed-by: Ming Lei <[email protected]> Reviewed-by: Damien Le Moal <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Reviewed-by: Nilay Shroff <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 9c96821 commit aa427d7

File tree

7 files changed

+35
-28
lines changed

7 files changed

+35
-28
lines changed

block/blk-integrity.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,7 @@ static ssize_t flag_store(struct device *dev, const char *page, size_t count,
218218
else
219219
lim.integrity.flags |= flag;
220220

221-
blk_mq_freeze_queue(q);
222-
err = queue_limits_commit_update(q, &lim);
223-
blk_mq_unfreeze_queue(q);
221+
err = queue_limits_commit_update_frozen(q, &lim);
224222
if (err)
225223
return err;
226224
return count;

block/blk-settings.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,30 @@ int queue_limits_commit_update(struct request_queue *q,
444444
}
445445
EXPORT_SYMBOL_GPL(queue_limits_commit_update);
446446

447+
/**
448+
* queue_limits_commit_update_frozen - commit an atomic update of queue limits
449+
* @q: queue to update
450+
* @lim: limits to apply
451+
*
452+
* Apply the limits in @lim that were obtained from queue_limits_start_update()
453+
* and updated with the new values by the caller to @q. Freezes the queue
454+
* before the update and unfreezes it after.
455+
*
456+
* Returns 0 if successful, else a negative error code.
457+
*/
458+
int queue_limits_commit_update_frozen(struct request_queue *q,
459+
struct queue_limits *lim)
460+
{
461+
int ret;
462+
463+
blk_mq_freeze_queue(q);
464+
ret = queue_limits_commit_update(q, lim);
465+
blk_mq_unfreeze_queue(q);
466+
467+
return ret;
468+
}
469+
EXPORT_SYMBOL_GPL(queue_limits_commit_update_frozen);
470+
447471
/**
448472
* queue_limits_set - apply queue limits to queue
449473
* @q: queue to update

block/blk-zoned.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,6 @@ static int disk_update_zone_resources(struct gendisk *disk,
14441444
unsigned int nr_seq_zones, nr_conv_zones;
14451445
unsigned int pool_size;
14461446
struct queue_limits lim;
1447-
int ret;
14481447

14491448
disk->nr_zones = args->nr_zones;
14501449
disk->zone_capacity = args->zone_capacity;
@@ -1495,11 +1494,7 @@ static int disk_update_zone_resources(struct gendisk *disk,
14951494
}
14961495

14971496
commit:
1498-
blk_mq_freeze_queue(q);
1499-
ret = queue_limits_commit_update(q, &lim);
1500-
blk_mq_unfreeze_queue(q);
1501-
1502-
return ret;
1497+
return queue_limits_commit_update_frozen(q, &lim);
15031498
}
15041499

15051500
static int blk_revalidate_conv_zone(struct blk_zone *zone, unsigned int idx,

drivers/block/virtio_blk.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,9 +1105,7 @@ cache_type_store(struct device *dev, struct device_attribute *attr,
11051105
lim.features |= BLK_FEAT_WRITE_CACHE;
11061106
else
11071107
lim.features &= ~BLK_FEAT_WRITE_CACHE;
1108-
blk_mq_freeze_queue(disk->queue);
1109-
i = queue_limits_commit_update(disk->queue, &lim);
1110-
blk_mq_unfreeze_queue(disk->queue);
1108+
i = queue_limits_commit_update_frozen(disk->queue, &lim);
11111109
if (i)
11121110
return i;
11131111
return count;

drivers/scsi/sd.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,8 @@ cache_type_store(struct device *dev, struct device_attribute *attr,
177177

178178
lim = queue_limits_start_update(sdkp->disk->queue);
179179
sd_set_flush_flag(sdkp, &lim);
180-
blk_mq_freeze_queue(sdkp->disk->queue);
181-
ret = queue_limits_commit_update(sdkp->disk->queue, &lim);
182-
blk_mq_unfreeze_queue(sdkp->disk->queue);
180+
ret = queue_limits_commit_update_frozen(sdkp->disk->queue,
181+
&lim);
183182
if (ret)
184183
return ret;
185184
return count;
@@ -483,9 +482,7 @@ provisioning_mode_store(struct device *dev, struct device_attribute *attr,
483482

484483
lim = queue_limits_start_update(sdkp->disk->queue);
485484
sd_config_discard(sdkp, &lim, mode);
486-
blk_mq_freeze_queue(sdkp->disk->queue);
487-
err = queue_limits_commit_update(sdkp->disk->queue, &lim);
488-
blk_mq_unfreeze_queue(sdkp->disk->queue);
485+
err = queue_limits_commit_update_frozen(sdkp->disk->queue, &lim);
489486
if (err)
490487
return err;
491488
return count;
@@ -594,9 +591,7 @@ max_write_same_blocks_store(struct device *dev, struct device_attribute *attr,
594591

595592
lim = queue_limits_start_update(sdkp->disk->queue);
596593
sd_config_write_same(sdkp, &lim);
597-
blk_mq_freeze_queue(sdkp->disk->queue);
598-
err = queue_limits_commit_update(sdkp->disk->queue, &lim);
599-
blk_mq_unfreeze_queue(sdkp->disk->queue);
594+
err = queue_limits_commit_update_frozen(sdkp->disk->queue, &lim);
600595
if (err)
601596
return err;
602597
return count;
@@ -3803,9 +3798,7 @@ static int sd_revalidate_disk(struct gendisk *disk)
38033798
sd_config_write_same(sdkp, &lim);
38043799
kfree(buffer);
38053800

3806-
blk_mq_freeze_queue(sdkp->disk->queue);
3807-
err = queue_limits_commit_update(sdkp->disk->queue, &lim);
3808-
blk_mq_unfreeze_queue(sdkp->disk->queue);
3801+
err = queue_limits_commit_update_frozen(sdkp->disk->queue, &lim);
38093802
if (err)
38103803
return err;
38113804

drivers/scsi/sr.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -797,10 +797,7 @@ static int get_sectorsize(struct scsi_cd *cd)
797797

798798
lim = queue_limits_start_update(q);
799799
lim.logical_block_size = sector_size;
800-
blk_mq_freeze_queue(q);
801-
err = queue_limits_commit_update(q, &lim);
802-
blk_mq_unfreeze_queue(q);
803-
return err;
800+
return queue_limits_commit_update_frozen(q, &lim);
804801
}
805802

806803
static int get_capabilities(struct scsi_cd *cd)

include/linux/blkdev.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,8 @@ queue_limits_start_update(struct request_queue *q)
952952
mutex_lock(&q->limits_lock);
953953
return q->limits;
954954
}
955+
int queue_limits_commit_update_frozen(struct request_queue *q,
956+
struct queue_limits *lim);
955957
int queue_limits_commit_update(struct request_queue *q,
956958
struct queue_limits *lim);
957959
int queue_limits_set(struct request_queue *q, struct queue_limits *lim);

0 commit comments

Comments
 (0)