From cde0c555ab2981f6150e650417813f7217d569e9 Mon Sep 17 00:00:00 2001 From: Liu Xiaodong Date: Mon, 23 Jan 2023 11:31:42 -0500 Subject: [PATCH] ublk: close queue based on queue's io info Every queue should be closed based on only its own I/O information, not the whole device. Remove function ublk_is_ready_to_stop(). Change-Id: Iec5a260f68d6f84c0af4c8e0b5380272049b1f5d Signed-off-by: Liu Xiaodong Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16416 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Konrad Sztyber --- lib/ublk/ublk.c | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/lib/ublk/ublk.c b/lib/ublk/ublk.c index 8ed0cd946..0bdb2e3cc 100644 --- a/lib/ublk/ublk.c +++ b/lib/ublk/ublk.c @@ -646,27 +646,6 @@ ublk_dev_list_unregister(struct spdk_ublk_dev *ublk) } } -static inline bool -ublk_is_ready_to_stop(struct spdk_ublk_dev *ublk) -{ - /* - * Stop action should be called only after all ublk_io are completed. - */ - bool ready_to_stop = true; - struct ublk_queue *q; - uint32_t i; - - for (i = 0; i < ublk->num_queues; i++) { - q = &ublk->queues[i]; - if (!TAILQ_EMPTY(&q->inflight_io_list) || !TAILQ_EMPTY(&q->completed_io_list) || q->cmd_inflight) { - ready_to_stop = false; - break; - } - } - - return ready_to_stop; -} - static void ublk_close_dev_done(void *arg) { @@ -763,15 +742,18 @@ ublk_try_close_dev(void *arg) } static void -ublk_try_close_queue(void *arg) +ublk_try_close_queue(struct ublk_queue *q) { - struct ublk_queue *q = arg; struct spdk_ublk_dev *ublk = q->dev; - if (!ublk_is_ready_to_stop(ublk)) { + /* Close queue until no I/O is submitted to bdev in flight, + * no I/O is waiting to commit result, and all I/Os are aborted back. + */ + if (!TAILQ_EMPTY(&q->inflight_io_list) || !TAILQ_EMPTY(&q->completed_io_list) || q->cmd_inflight) { /* wait for next retry */ return; } + TAILQ_REMOVE(&q->thread_ctx->queue_list, q, tailq); spdk_put_io_channel(ublk->ch[q->q_id]); ublk->ch[q->q_id] = NULL;