From 237260f6a14b5882612ba67a6b4748518666a4a7 Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Fri, 15 Mar 2019 02:04:16 +0800 Subject: [PATCH] nvme/tcp: Restore nvme_tcp_read_data function. Purpose: To fix performance degradation. Restore the nvme_tcp_read_data function, and for nvme_tcp_readv_data, will call nvme_tcp_read_data if iovcnt=1. Change-Id: Ie3abb943c294dc27d736371cd7ce9a5aa966877a Signed-off-by: Ziye Yang Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/448030 Reviewed-by: wuzhouhui Reviewed-by: Shuhei Matsumoto Reviewed-by: Jim Harris Tested-by: SPDK CI Jenkins --- include/spdk_internal/nvme_tcp.h | 46 ++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/include/spdk_internal/nvme_tcp.h b/include/spdk_internal/nvme_tcp.h index 303ed5c65..dda88d379 100644 --- a/include/spdk_internal/nvme_tcp.h +++ b/include/spdk_internal/nvme_tcp.h @@ -312,6 +312,37 @@ end: return ctx->iovcnt; } +static int +nvme_tcp_read_data(struct spdk_sock *sock, int bytes, + void *buf) +{ + int ret; + + ret = spdk_sock_recv(sock, buf, bytes); + + if (ret > 0) { + return ret; + } + + if (ret < 0) { + if (errno == EAGAIN || errno == EWOULDBLOCK) { + return 0; + } + + /* For connect reset issue, do not output error log */ + if (errno == ECONNRESET) { + SPDK_DEBUGLOG(SPDK_LOG_NVME, "spdk_sock_recv() failed, errno %d: %s\n", + errno, spdk_strerror(errno)); + } else { + SPDK_ERRLOG("spdk_sock_recv() failed, errno %d: %s\n", + errno, spdk_strerror(errno)); + } + } + + /* connection closed */ + return NVME_TCP_CONNECTION_FATAL; +} + static int nvme_tcp_readv_data(struct spdk_sock *sock, struct iovec *iov, int iovcnt) { @@ -322,6 +353,10 @@ nvme_tcp_readv_data(struct spdk_sock *sock, struct iovec *iov, int iovcnt) return 0; } + if (iovcnt == 1) { + return nvme_tcp_read_data(sock, iov->iov_len, iov->iov_base); + } + ret = spdk_sock_readv(sock, iov, iovcnt); if (ret > 0) { @@ -347,17 +382,6 @@ nvme_tcp_readv_data(struct spdk_sock *sock, struct iovec *iov, int iovcnt) return NVME_TCP_CONNECTION_FATAL; } -static int -nvme_tcp_read_data(struct spdk_sock *sock, int bytes, - void *buf) -{ - struct iovec iov; - - iov.iov_base = buf; - iov.iov_len = bytes; - - return nvme_tcp_readv_data(sock, &iov, 1); -} static int nvme_tcp_read_payload_data(struct spdk_sock *sock, struct nvme_tcp_pdu *pdu)