@@ -579,6 +579,20 @@ static int nvme_add_ns_head_cdev(struct nvme_ns_head *head)
579
579
return ret ;
580
580
}
581
581
582
+ static void nvme_partition_scan_work (struct work_struct * work )
583
+ {
584
+ struct nvme_ns_head * head =
585
+ container_of (work , struct nvme_ns_head , partition_scan_work );
586
+
587
+ if (WARN_ON_ONCE (!test_and_clear_bit (GD_SUPPRESS_PART_SCAN ,
588
+ & head -> disk -> state )))
589
+ return ;
590
+
591
+ mutex_lock (& head -> disk -> open_mutex );
592
+ bdev_disk_changed (head -> disk , false);
593
+ mutex_unlock (& head -> disk -> open_mutex );
594
+ }
595
+
582
596
static void nvme_requeue_work (struct work_struct * work )
583
597
{
584
598
struct nvme_ns_head * head =
@@ -605,6 +619,7 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)
605
619
bio_list_init (& head -> requeue_list );
606
620
spin_lock_init (& head -> requeue_lock );
607
621
INIT_WORK (& head -> requeue_work , nvme_requeue_work );
622
+ INIT_WORK (& head -> partition_scan_work , nvme_partition_scan_work );
608
623
609
624
/*
610
625
* Add a multipath node if the subsystems supports multiple controllers.
@@ -628,6 +643,16 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)
628
643
return PTR_ERR (head -> disk );
629
644
head -> disk -> fops = & nvme_ns_head_ops ;
630
645
head -> disk -> private_data = head ;
646
+
647
+ /*
648
+ * We need to suppress the partition scan from occuring within the
649
+ * controller's scan_work context. If a path error occurs here, the IO
650
+ * will wait until a path becomes available or all paths are torn down,
651
+ * but that action also occurs within scan_work, so it would deadlock.
652
+ * Defer the partion scan to a different context that does not block
653
+ * scan_work.
654
+ */
655
+ set_bit (GD_SUPPRESS_PART_SCAN , & head -> disk -> state );
631
656
sprintf (head -> disk -> disk_name , "nvme%dn%d" ,
632
657
ctrl -> subsys -> instance , head -> instance );
633
658
return 0 ;
@@ -654,6 +679,7 @@ static void nvme_mpath_set_live(struct nvme_ns *ns)
654
679
return ;
655
680
}
656
681
nvme_add_ns_head_cdev (head );
682
+ kblockd_schedule_work (& head -> partition_scan_work );
657
683
}
658
684
659
685
mutex_lock (& head -> lock );
@@ -973,14 +999,14 @@ void nvme_mpath_shutdown_disk(struct nvme_ns_head *head)
973
999
return ;
974
1000
if (test_and_clear_bit (NVME_NSHEAD_DISK_LIVE , & head -> flags )) {
975
1001
nvme_cdev_del (& head -> cdev , & head -> cdev_device );
1002
+ /*
1003
+ * requeue I/O after NVME_NSHEAD_DISK_LIVE has been cleared
1004
+ * to allow multipath to fail all I/O.
1005
+ */
1006
+ synchronize_srcu (& head -> srcu );
1007
+ kblockd_schedule_work (& head -> requeue_work );
976
1008
del_gendisk (head -> disk );
977
1009
}
978
- /*
979
- * requeue I/O after NVME_NSHEAD_DISK_LIVE has been cleared
980
- * to allow multipath to fail all I/O.
981
- */
982
- synchronize_srcu (& head -> srcu );
983
- kblockd_schedule_work (& head -> requeue_work );
984
1010
}
985
1011
986
1012
void nvme_mpath_remove_disk (struct nvme_ns_head * head )
@@ -990,6 +1016,7 @@ void nvme_mpath_remove_disk(struct nvme_ns_head *head)
990
1016
/* make sure all pending bios are cleaned up */
991
1017
kblockd_schedule_work (& head -> requeue_work );
992
1018
flush_work (& head -> requeue_work );
1019
+ flush_work (& head -> partition_scan_work );
993
1020
put_disk (head -> disk );
994
1021
}
995
1022
0 commit comments