From f0be9913303949f4327ac99063f11b925a2c0eae Mon Sep 17 00:00:00 2001 From: Seth Howell Date: Mon, 20 Jul 2020 15:04:10 -0700 Subject: [PATCH] lib/nvmf: complete requests in req_process for inactive qpairs. There is no reason to continue processing these requests if the qpair is not still active. We should complete them and free any resources they are still holding. Also, not doing so can cause issues with trying to access pointers in the qpair after they are invalid. See issue #1460. Signed-off-by: Seth Howell Change-Id: I6e570a576983dfedf726dc4a9a83316209403e00 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3451 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto Reviewed-by: Aleksey Marchuk --- lib/nvmf/tcp.c | 8 ++++++++ test/unit/lib/nvmf/tcp.c/tcp_ut.c | 1 + 2 files changed, 9 insertions(+) diff --git a/lib/nvmf/tcp.c b/lib/nvmf/tcp.c index 798df4d54..c8945d091 100644 --- a/lib/nvmf/tcp.c +++ b/lib/nvmf/tcp.c @@ -2088,6 +2088,14 @@ nvmf_tcp_req_process(struct spdk_nvmf_tcp_transport *ttransport, group = &tqpair->group->group; assert(tcp_req->state != TCP_REQUEST_STATE_FREE); + /* If the qpair is not active, we need to abort the outstanding requests. */ + if (tqpair->qpair.state != SPDK_NVMF_QPAIR_ACTIVE) { + if (tcp_req->state == TCP_REQUEST_STATE_NEED_BUFFER) { + STAILQ_REMOVE(&group->pending_buf_queue, &tcp_req->req, spdk_nvmf_request, buf_link); + } + nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_COMPLETED); + } + /* The loop here is to allow for several back-to-back state changes. */ do { prev_state = tcp_req->state; diff --git a/test/unit/lib/nvmf/tcp.c/tcp_ut.c b/test/unit/lib/nvmf/tcp.c/tcp_ut.c index 4c75b65aa..0aaa4f601 100644 --- a/test/unit/lib/nvmf/tcp.c/tcp_ut.c +++ b/test/unit/lib/nvmf/tcp.c/tcp_ut.c @@ -644,6 +644,7 @@ test_nvmf_tcp_incapsule_data_handle(void) tqpair.qpair.transport = &ttransport.transport; tqpair.state = NVME_TCP_QPAIR_STATE_RUNNING; tqpair.recv_state = NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PSH; + tqpair.qpair.state = SPDK_NVMF_QPAIR_ACTIVE; /* init a null tcp_req into tqpair TCP_REQUEST_STATE_FREE queue */ tcp_req2.req.qpair = &tqpair.qpair;