mirror of
https://github.com/torvalds/linux.git
synced 2026-01-24 23:16:46 +00:00
block: freeze queue when updating zone resources
Modify disk_update_zone_resources() to freeze the device queue before
updating the number of zones, zone capacity and other zone related
resources. The locking order resulting from the call to
queue_limits_commit_update_frozen() is preserved, that is, the queue
limits lock is first taken by calling queue_limits_start_update() before
freezing the queue, and the queue is unfrozen after executing
queue_limits_commit_update(), which replaces the call to
queue_limits_commit_update_frozen().
This change ensures that there are no in-flights I/Os when the zone
resources are updated due to a zone revalidation. In case of error when
the limits are applied, directly call disk_free_zone_resources() from
disk_update_zone_resources() while the disk queue is still frozen to
avoid needing to freeze & unfreeze the queue again in
blk_revalidate_disk_zones(), thus simplifying that function code a
little.
Fixes: 0b83c86b44 ("block: Prevent potential deadlock in blk_revalidate_disk_zones()")
Cc: stable@vger.kernel.org
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
committed by
Jens Axboe
parent
efae226c2e
commit
bba4322e3f
@@ -1557,8 +1557,13 @@ static int disk_update_zone_resources(struct gendisk *disk,
|
||||
{
|
||||
struct request_queue *q = disk->queue;
|
||||
unsigned int nr_seq_zones, nr_conv_zones;
|
||||
unsigned int pool_size;
|
||||
unsigned int pool_size, memflags;
|
||||
struct queue_limits lim;
|
||||
int ret = 0;
|
||||
|
||||
lim = queue_limits_start_update(q);
|
||||
|
||||
memflags = blk_mq_freeze_queue(q);
|
||||
|
||||
disk->nr_zones = args->nr_zones;
|
||||
disk->zone_capacity = args->zone_capacity;
|
||||
@@ -1568,11 +1573,10 @@ static int disk_update_zone_resources(struct gendisk *disk,
|
||||
if (nr_conv_zones >= disk->nr_zones) {
|
||||
pr_warn("%s: Invalid number of conventional zones %u / %u\n",
|
||||
disk->disk_name, nr_conv_zones, disk->nr_zones);
|
||||
return -ENODEV;
|
||||
ret = -ENODEV;
|
||||
goto unfreeze;
|
||||
}
|
||||
|
||||
lim = queue_limits_start_update(q);
|
||||
|
||||
/*
|
||||
* Some devices can advertize zone resource limits that are larger than
|
||||
* the number of sequential zones of the zoned block device, e.g. a
|
||||
@@ -1609,7 +1613,15 @@ static int disk_update_zone_resources(struct gendisk *disk,
|
||||
}
|
||||
|
||||
commit:
|
||||
return queue_limits_commit_update_frozen(q, &lim);
|
||||
ret = queue_limits_commit_update(q, &lim);
|
||||
|
||||
unfreeze:
|
||||
if (ret)
|
||||
disk_free_zone_resources(disk);
|
||||
|
||||
blk_mq_unfreeze_queue(q, memflags);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int blk_revalidate_conv_zone(struct blk_zone *zone, unsigned int idx,
|
||||
@@ -1774,7 +1786,7 @@ int blk_revalidate_disk_zones(struct gendisk *disk)
|
||||
sector_t zone_sectors = q->limits.chunk_sectors;
|
||||
sector_t capacity = get_capacity(disk);
|
||||
struct blk_revalidate_zone_args args = { };
|
||||
unsigned int noio_flag;
|
||||
unsigned int memflags, noio_flag;
|
||||
int ret = -ENOMEM;
|
||||
|
||||
if (WARN_ON_ONCE(!blk_queue_is_zoned(q)))
|
||||
@@ -1824,20 +1836,14 @@ int blk_revalidate_disk_zones(struct gendisk *disk)
|
||||
ret = -ENODEV;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the new disk zone parameters only once the queue is frozen and
|
||||
* all I/Os are completed.
|
||||
*/
|
||||
if (ret > 0)
|
||||
ret = disk_update_zone_resources(disk, &args);
|
||||
else
|
||||
pr_warn("%s: failed to revalidate zones\n", disk->disk_name);
|
||||
if (ret) {
|
||||
unsigned int memflags = blk_mq_freeze_queue(q);
|
||||
return disk_update_zone_resources(disk, &args);
|
||||
|
||||
disk_free_zone_resources(disk);
|
||||
blk_mq_unfreeze_queue(q, memflags);
|
||||
}
|
||||
pr_warn("%s: failed to revalidate zones\n", disk->disk_name);
|
||||
|
||||
memflags = blk_mq_freeze_queue(q);
|
||||
disk_free_zone_resources(disk);
|
||||
blk_mq_unfreeze_queue(q, memflags);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user