]> git.baikalelectronics.ru Git - kernel.git/commitdiff
nvme-tcp: handle number of queue changes
authorDaniel Wagner <dwagner@suse.de>
Mon, 29 Aug 2022 09:28:40 +0000 (11:28 +0200)
committerChristoph Hellwig <hch@lst.de>
Mon, 19 Sep 2022 15:55:19 +0000 (17:55 +0200)
On reconnect, the number of queues might have changed.

In the case where we have more queues available than previously we try
to access queues which are not initialized yet.

The other case where we have less queues than previously, the
connection attempt will fail because the target doesn't support the
old number of queues and we end up in a reconnect loop.

Thus, only start queues which are currently present in the tagset
limited by the number of available queues. Then we update the tagset
and we can start any new queue.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/host/tcp.c

index ef151c23d49512805ee8d3808ebd6b1ae56b98e4..4c2d198145a73f982b0376ffc95882c3594d8a85 100644 (file)
@@ -1762,11 +1762,12 @@ static void nvme_tcp_stop_io_queues(struct nvme_ctrl *ctrl)
                nvme_tcp_stop_queue(ctrl, i);
 }
 
-static int nvme_tcp_start_io_queues(struct nvme_ctrl *ctrl)
+static int nvme_tcp_start_io_queues(struct nvme_ctrl *ctrl,
+                                   int first, int last)
 {
        int i, ret;
 
-       for (i = 1; i < ctrl->queue_count; i++) {
+       for (i = first; i < last; i++) {
                ret = nvme_tcp_start_queue(ctrl, i);
                if (ret)
                        goto out_stop_queues;
@@ -1775,7 +1776,7 @@ static int nvme_tcp_start_io_queues(struct nvme_ctrl *ctrl)
        return 0;
 
 out_stop_queues:
-       for (i--; i >= 1; i--)
+       for (i--; i >= first; i--)
                nvme_tcp_stop_queue(ctrl, i);
        return ret;
 }
@@ -1901,7 +1902,7 @@ static void nvme_tcp_destroy_io_queues(struct nvme_ctrl *ctrl, bool remove)
 
 static int nvme_tcp_configure_io_queues(struct nvme_ctrl *ctrl, bool new)
 {
-       int ret;
+       int ret, nr_queues;
 
        ret = nvme_tcp_alloc_io_queues(ctrl);
        if (ret)
@@ -1917,7 +1918,13 @@ static int nvme_tcp_configure_io_queues(struct nvme_ctrl *ctrl, bool new)
                        goto out_free_tag_set;
        }
 
-       ret = nvme_tcp_start_io_queues(ctrl);
+       /*
+        * Only start IO queues for which we have allocated the tagset
+        * and limitted it to the available queues. On reconnects, the
+        * queue number might have changed.
+        */
+       nr_queues = min(ctrl->tagset->nr_hw_queues + 1, ctrl->queue_count);
+       ret = nvme_tcp_start_io_queues(ctrl, 1, nr_queues);
        if (ret)
                goto out_cleanup_connect_q;
 
@@ -1937,6 +1944,15 @@ static int nvme_tcp_configure_io_queues(struct nvme_ctrl *ctrl, bool new)
                nvme_unfreeze(ctrl);
        }
 
+       /*
+        * If the number of queues has increased (reconnect case)
+        * start all new queues now.
+        */
+       ret = nvme_tcp_start_io_queues(ctrl, nr_queues,
+                                      ctrl->tagset->nr_hw_queues + 1);
+       if (ret)
+               goto out_wait_freeze_timed_out;
+
        return 0;
 
 out_wait_freeze_timed_out: