From 72eedc578de6162f97c68438b16d66071f7577cd Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Tue, 30 Jun 2020 00:13:15 +0900 Subject: [PATCH] nvmf/tcp: Abort request whose CID matches if it is pending If the request is queued and is not in completing, we can abort it safely. If the state of the request is NEED_BUFFERING, the request is queued to both tqpair->group->group.pending_buf_queue and the queue per state. If the state is AWAITING_R2T_ACK, the request is queued to the queue per state. Dequeueing from the queue per state is done in nvmf_tcp_req_set_state(). Hence explicit dequeuing only when the state of the request is NEED_BUFFERING. Most abort operation is common between two cases. We can use fallthrough in switch-case but factor out the common operation into a helper function nvmf_tcp_req_set_abort_status() instead because we may use the helper function in future and using helper function is easier to read than fallthrough. Signed-off-by: Shuhei Matsumoto Change-Id: I1695b084d5d1f2537fbdd512bc3cd136e0f6a65b Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3009 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Michael Haeuptle Reviewed-by: Jim Harris Reviewed-by: Aleksey Marchuk --- lib/nvmf/tcp.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/nvmf/tcp.c b/lib/nvmf/tcp.c index 83f2b6de8..54593b54e 100644 --- a/lib/nvmf/tcp.c +++ b/lib/nvmf/tcp.c @@ -2461,6 +2461,18 @@ nvmf_tcp_qpair_get_listen_trid(struct spdk_nvmf_qpair *qpair, return nvmf_tcp_qpair_get_trid(qpair, trid, 0); } +static void +nvmf_tcp_req_set_abort_status(struct spdk_nvmf_request *req, + struct spdk_nvmf_tcp_req *tcp_req_to_abort) +{ + tcp_req_to_abort->req.rsp->nvme_cpl.status.sct = SPDK_NVME_SCT_GENERIC; + tcp_req_to_abort->req.rsp->nvme_cpl.status.sc = SPDK_NVME_SC_ABORTED_BY_REQUEST; + + nvmf_tcp_req_set_state(tcp_req_to_abort, TCP_REQUEST_STATE_READY_TO_COMPLETE); + + req->rsp->nvme_cpl.cdw0 &= ~1U; /* Command was successfully aborted. */ +} + static void nvmf_tcp_qpair_abort_request(struct spdk_nvmf_qpair *qpair, struct spdk_nvmf_request *req) @@ -2494,6 +2506,18 @@ nvmf_tcp_qpair_abort_request(struct spdk_nvmf_qpair *qpair, return; } break; + + case TCP_REQUEST_STATE_NEED_BUFFER: + STAILQ_REMOVE(&tqpair->group->group.pending_buf_queue, + &tcp_req_to_abort->req, spdk_nvmf_request, buf_link); + + nvmf_tcp_req_set_abort_status(req, tcp_req_to_abort); + break; + + case TCP_REQUEST_STATE_AWAITING_R2T_ACK: + nvmf_tcp_req_set_abort_status(req, tcp_req_to_abort); + break; + default: break; }