From fe2dddbbbce77c7e6964f570fbfef64d78a8ee56 Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Tue, 4 Jun 2019 20:56:45 +0800 Subject: [PATCH] nvme/tcp: Correct nvme_tcp_qpair_disconnect behavior The current nvme_tcp_qpair_disconnect behaviour is not exactly correct, we do not re-initialize the state of some data structures of the tqpair. And this caused the coredump. Purpose: Fixes #808. Signed-off-by: Ziye Yang Change-Id: I4d2cad8fc0712dbebfc2f3e52373cbe3b9908bf7 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/456755 Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Jim Harris --- lib/nvme/nvme_tcp.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/nvme/nvme_tcp.c b/lib/nvme/nvme_tcp.c index aaae9d378..716fc36e4 100644 --- a/lib/nvme/nvme_tcp.c +++ b/lib/nvme/nvme_tcp.c @@ -231,8 +231,18 @@ static void nvme_tcp_qpair_disconnect(struct spdk_nvme_qpair *qpair) { struct nvme_tcp_qpair *tqpair = nvme_tcp_qpair(qpair); + struct nvme_tcp_pdu *pdu; spdk_sock_close(&tqpair->sock); + + /* clear the send_queue */ + while (!TAILQ_EMPTY(&tqpair->send_queue)) { + pdu = TAILQ_FIRST(&tqpair->send_queue); + /* Remove the pdu from the send_queue to prevent the wrong sending out + * in the next round connection + */ + TAILQ_REMOVE(&tqpair->send_queue, pdu, tailq); + } } static int @@ -1714,6 +1724,11 @@ nvme_tcp_qpair_connect(struct nvme_tcp_qpair *tqpair) } tqpair->maxr2t = NVME_TCP_MAX_R2T_DEFAULT; + /* Explicitly set the state and recv_state of tqpair */ + tqpair->state = NVME_TCP_QPAIR_STATE_INVALID; + if (tqpair->recv_state != NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY) { + nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY); + } rc = nvme_tcp_qpair_icreq_send(tqpair); if (rc != 0) { SPDK_ERRLOG("Unable to connect the tqpair\n");