nvme: paring quiesce/unquiesce
authorMing Lei <ming.lei@redhat.com>
Thu, 14 Oct 2021 08:17:08 +0000 (16:17 +0800)
committerJens Axboe <axboe@kernel.dk>
Wed, 20 Oct 2021 00:27:58 +0000 (18:27 -0600)
The current blk_mq_quiesce_queue() and blk_mq_unquiesce_queue() always
stops and starts the queue unconditionally. And there can be concurrent
quiesce/unquiesce coming from different unrelated code paths, so
unquiesce may come unexpectedly and start queue too early.

Prepare for supporting concurrent quiesce/unquiesce from multiple
contexts, so that we can address the above issue.

NVMe has very complicated quiesce/unquiesce use pattern, add one atomic
bit for makeiing sure that blk-mq quiece/unquiesce is always called in
pair.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20211014081710.1871747-5-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/nvme/host/core.c
drivers/nvme/host/nvme.h

index 570da6a..eb284f4 100644 (file)
@@ -4468,12 +4468,14 @@ EXPORT_SYMBOL_GPL(nvme_init_ctrl);
 
 static void nvme_start_ns_queue(struct nvme_ns *ns)
 {
-       blk_mq_unquiesce_queue(ns->queue);
+       if (test_and_clear_bit(NVME_NS_STOPPED, &ns->flags))
+               blk_mq_unquiesce_queue(ns->queue);
 }
 
 static void nvme_stop_ns_queue(struct nvme_ns *ns)
 {
-       blk_mq_quiesce_queue(ns->queue);
+       if (!test_and_set_bit(NVME_NS_STOPPED, &ns->flags))
+               blk_mq_quiesce_queue(ns->queue);
 }
 
 /*
@@ -4591,13 +4593,15 @@ EXPORT_SYMBOL_GPL(nvme_start_queues);
 
 void nvme_stop_admin_queue(struct nvme_ctrl *ctrl)
 {
-       blk_mq_quiesce_queue(ctrl->admin_q);
+       if (!test_and_set_bit(NVME_CTRL_ADMIN_Q_STOPPED, &ctrl->flags))
+               blk_mq_quiesce_queue(ctrl->admin_q);
 }
 EXPORT_SYMBOL_GPL(nvme_stop_admin_queue);
 
 void nvme_start_admin_queue(struct nvme_ctrl *ctrl)
 {
-       blk_mq_unquiesce_queue(ctrl->admin_q);
+       if (test_and_clear_bit(NVME_CTRL_ADMIN_Q_STOPPED, &ctrl->flags))
+               blk_mq_unquiesce_queue(ctrl->admin_q);
 }
 EXPORT_SYMBOL_GPL(nvme_start_admin_queue);
 
index e7af008..3652439 100644 (file)
@@ -342,6 +342,7 @@ struct nvme_ctrl {
        int nr_reconnects;
        unsigned long flags;
 #define NVME_CTRL_FAILFAST_EXPIRED     0
+#define NVME_CTRL_ADMIN_Q_STOPPED      1
        struct nvmf_ctrl_options *opts;
 
        struct page *discard_page;
@@ -463,6 +464,7 @@ struct nvme_ns {
 #define NVME_NS_ANA_PENDING    2
 #define NVME_NS_FORCE_RO       3
 #define NVME_NS_READY          4
+#define NVME_NS_STOPPED                5
 
        struct cdev             cdev;
        struct device           cdev_device;