block: fix revalidate performance regression

The scsi driver function sd_read_block_characteristics() always calls
disk_set_zoned() to a disk zoned model correctly, in case the device
model changed. This is done even for regular disks to set the zoned
model to BLK_ZONED_NONE and free any zone related resources if the drive
previously was zoned.

This behavior significantly impact the time it takes to revalidate disks
on a large system as the call to disk_clear_zone_settings() done from
disk_set_zoned() for the BLK_ZONED_NONE case results in the device
request queued to be frozen, even if there are no zone resources to
free.

Avoid this overhead for non-zoned devices by not calling
disk_clear_zone_settings() in disk_set_zoned() if the device model
was already set to BLK_ZONED_NONE, which is always the case for regular
devices.

Reported by: Brian Bunker <brian@purestorage.com>

Fixes: 508aebb80527 ("block: introduce blk_queue_clear_zone_settings()")
Cc: stable@vger.kernel.org
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20230529073237.1339862-1-dlemoal@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by Damien Le Moal and committed by Jens Axboe 47fe1c30 f270f858

+2 -1
+2 -1
block/blk-settings.c
··· 915 void disk_set_zoned(struct gendisk *disk, enum blk_zoned_model model) 916 { 917 struct request_queue *q = disk->queue; 918 919 switch (model) { 920 case BLK_ZONED_HM: ··· 953 */ 954 blk_queue_zone_write_granularity(q, 955 queue_logical_block_size(q)); 956 - } else { 957 disk_clear_zone_settings(disk); 958 } 959 }
··· 915 void disk_set_zoned(struct gendisk *disk, enum blk_zoned_model model) 916 { 917 struct request_queue *q = disk->queue; 918 + unsigned int old_model = q->limits.zoned; 919 920 switch (model) { 921 case BLK_ZONED_HM: ··· 952 */ 953 blk_queue_zone_write_granularity(q, 954 queue_logical_block_size(q)); 955 + } else if (old_model != BLK_ZONED_NONE) { 956 disk_clear_zone_settings(disk); 957 } 958 }