[PATCH 4/6] block: freeze queue for updating QUEUE_FLAG_NONROT

Ming Lei
2020-01-19T07:15:23Z

We will read the NONROT flag for bypassing scsi->device_busy in SCSI
IO path, so have to freeze queue when updating this flag.

Cc: Sathya Prakash <sathya.prakash@broadcom.com>
Cc: Chaitra P B <chaitra.basappa@broadcom.com>
Cc: Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>
Cc: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: Sumit Saxena <sumit.saxena@broadcom.com>
Cc: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Cc: Ewan D. Milne <emilne@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>,
Cc: Hannes Reinecke <hare@suse.de>
Cc: Bart Van Assche <bart.vanassche@wdc.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
block/blk-sysfs.c | 14 +++++++++++++-
drivers/scsi/sd.c | 4 ++++
2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index fca9b158f4a0..9cc0dd5f88a1 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -281,6 +281,18 @@ QUEUE_SYSFS_BIT_FNS(random, ADD_RANDOM, 0);
QUEUE_SYSFS_BIT_FNS(iostats, IO_STAT, 0);
#undef QUEUE_SYSFS_BIT_FNS

+static ssize_t queue_store_nonrot_freeze(struct request_queue *q,
+ const char *page, size_t count)
+{
+ size_t ret;
+
+ blk_mq_freeze_queue(q);
+ ret = queue_store_nonrot(q, page, count);
+ blk_mq_unfreeze_queue(q);
+
+ return ret;
+}
+
static ssize_t queue_zoned_show(struct request_queue *q, char *page)
{
switch (blk_queue_zoned_model(q)) {
@@ -642,7 +654,7 @@ static struct queue_sysfs_entry queue_write_zeroes_max_entry = {
static struct queue_sysfs_entry queue_nonrot_entry = {
.attr = {.name = "rotational", .mode = 0644 },
.show = queue_show_nonrot,
- .store = queue_store_nonrot,
+ .store = queue_store_nonrot_freeze,
};

static struct queue_sysfs_entry queue_zoned_entry = {
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index f401ba96dcfd..349c944b29a3 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2935,7 +2935,9 @@ static void sd_read_block_characteristics(struct scsi_disk *sdkp)
rot = get_unaligned_be16(&buffer[4]);

if (rot == 1) {
+ blk_mq_freeze_queue(q);
blk_queue_flag_set(QUEUE_FLAG_NONROT, q);
+ blk_mq_unfreeze_queue(q);
blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, q);
}

@@ -3131,7 +3133,9 @@ static int sd_revalidate_disk(struct gendisk *disk)
* cause this to be updated correctly and any device which
* doesn't support it should be treated as rotational.
*/
+ blk_mq_freeze_queue(q);
blk_queue_flag_clear(QUEUE_FLAG_NONROT, q);
+ blk_mq_unfreeze_queue(q);
blk_queue_flag_set(QUEUE_FLAG_ADD_RANDOM, q);

if (scsi_device_supports_vpd(sdp)) {
--
2.20.1