From b11407d04cc9f98e7c42725cdb3edb3759ccd486 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Mon, 31 Oct 2022 12:40:48 -0700 Subject: [PATCH] nvmf/tcp: Use an spdk_sock_flush instead of an spdk_sock_write For IC_RESP and C2H_TERM_REQ, use the regular async write path but add an additional flush. The flush operation reports errors, so we may at some point attempt to handle busy conditions by blocking. However, for now this doesn't do that because previously the writev call didn't either. Change-Id: I4d05e19ac6dd781be7c96005549abdb52511b8c1 Signed-off-by: Ben Walker Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15213 Tested-by: SPDK CI Jenkins Reviewed-by: Konrad Sztyber Reviewed-by: Aleksey Marchuk --- lib/nvmf/tcp.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/nvmf/tcp.c b/lib/nvmf/tcp.c index 8a3d25217..0f6a1e057 100644 --- a/lib/nvmf/tcp.c +++ b/lib/nvmf/tcp.c @@ -951,26 +951,26 @@ _pdu_write_done(struct nvme_tcp_pdu *pdu, int err) static void _tcp_write_pdu(struct nvme_tcp_pdu *pdu) { - uint32_t mapped_length = 0; - ssize_t rc; + int rc; + uint32_t mapped_length; struct spdk_nvmf_tcp_qpair *tqpair = pdu->qpair; pdu->sock_req.iovcnt = nvme_tcp_build_iovs(pdu->iov, SPDK_COUNTOF(pdu->iov), pdu, - tqpair->host_hdgst_enable, tqpair->host_ddgst_enable, - &mapped_length); + tqpair->host_hdgst_enable, tqpair->host_ddgst_enable, &mapped_length); + spdk_sock_writev_async(tqpair->sock, &pdu->sock_req); + if (pdu->hdr.common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_IC_RESP || pdu->hdr.common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_C2H_TERM_REQ) { - rc = spdk_sock_writev(tqpair->sock, pdu->iov, pdu->sock_req.iovcnt); - if (rc == mapped_length) { + /* Try to force the send immediately. */ + rc = spdk_sock_flush(tqpair->sock); + if (rc > 0 && (uint32_t)rc == mapped_length) { _pdu_write_done(pdu, 0); } else { - SPDK_ERRLOG("Could not write %s to socket: rc=%zd, errno=%d\n", + SPDK_ERRLOG("Could not write %s to socket: rc=%d, errno=%d\n", pdu->hdr.common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_IC_RESP ? "IC_RESP" : "TERM_REQ", rc, errno); - _pdu_write_done(pdu, -1); + _pdu_write_done(pdu, rc >= 0 ? -EAGAIN : -errno); } - } else { - spdk_sock_writev_async(tqpair->sock, &pdu->sock_req); } }