Skip to content

Commit d308ae0

Browse files
Ming Leiaxboe
authored andcommitted
block: drain queue after disk is removed from sysfs
Before removing disk from sysfs, userspace still may change queue via sysfs, such as switching elevator or setting wbt latency, both may reinitialize wbt, then the warning in blk_free_queue_stats() will be triggered since rq_qos_exit() is moved to del_gendisk(). Fixes the issue by moving draining queue & tearing down after disk is removed from sysfs, at that time no one can come into queue's store()/show(). Reported-by: Yi Zhang <[email protected]> Tested-by: Yi Zhang <[email protected]> Fixes: 8e141f9 ("block: drain file system I/O on del_gendisk") Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 9fbfabf commit d308ae0

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

block/genhd.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -588,16 +588,6 @@ void del_gendisk(struct gendisk *disk)
588588
* Prevent new I/O from crossing bio_queue_enter().
589589
*/
590590
blk_queue_start_drain(q);
591-
blk_mq_freeze_queue_wait(q);
592-
593-
rq_qos_exit(q);
594-
blk_sync_queue(q);
595-
blk_flush_integrity();
596-
/*
597-
* Allow using passthrough request again after the queue is torn down.
598-
*/
599-
blk_queue_flag_clear(QUEUE_FLAG_INIT_DONE, q);
600-
__blk_mq_unfreeze_queue(q, true);
601591

602592
if (!(disk->flags & GENHD_FL_HIDDEN)) {
603593
sysfs_remove_link(&disk_to_dev(disk)->kobj, "bdi");
@@ -620,6 +610,18 @@ void del_gendisk(struct gendisk *disk)
620610
sysfs_remove_link(block_depr, dev_name(disk_to_dev(disk)));
621611
pm_runtime_set_memalloc_noio(disk_to_dev(disk), false);
622612
device_del(disk_to_dev(disk));
613+
614+
blk_mq_freeze_queue_wait(q);
615+
616+
rq_qos_exit(q);
617+
blk_sync_queue(q);
618+
blk_flush_integrity();
619+
/*
620+
* Allow using passthrough request again after the queue is torn down.
621+
*/
622+
blk_queue_flag_clear(QUEUE_FLAG_INIT_DONE, q);
623+
__blk_mq_unfreeze_queue(q, true);
624+
623625
}
624626
EXPORT_SYMBOL(del_gendisk);
625627

0 commit comments

Comments
 (0)