From 9ba4bb22fe42659f5db64d4a2ad71ac2bab07f49 Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Mon, 9 Mar 2020 23:26:21 +0800 Subject: [PATCH] lib/nvme_tcp: get the max_sges from the nvme ctrlr. Add the error print if there is still remaining_size in order to provide more meaningful debug info. Signed-off-by: Ziye Yang Change-Id: I7b15c9c9a630ea7ecb2d3191b73c9c99f7febf31 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1189 Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto Reviewed-by: Aleksey Marchuk Tested-by: SPDK CI Jenkins --- lib/nvme/nvme_tcp.c | 7 +++++-- test/unit/lib/nvme/nvme_tcp.c/nvme_tcp_ut.c | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/nvme/nvme_tcp.c b/lib/nvme/nvme_tcp.c index c7f203b2c..1396730c4 100644 --- a/lib/nvme/nvme_tcp.c +++ b/lib/nvme/nvme_tcp.c @@ -379,7 +379,7 @@ static int nvme_tcp_build_sgl_request(struct nvme_tcp_qpair *tqpair, struct nvme_tcp_req *tcp_req) { int rc; - uint32_t length, remaining_size, iovcnt = 0; + uint32_t length, remaining_size, iovcnt = 0, max_num_sgl; struct nvme_request *req = tcp_req->req; SPDK_DEBUGLOG(SPDK_LOG_NVME, "enter\n"); @@ -390,6 +390,7 @@ nvme_tcp_build_sgl_request(struct nvme_tcp_qpair *tqpair, struct nvme_tcp_req *t assert(req->payload.next_sge_fn != NULL); req->payload.reset_sgl_fn(req->payload.contig_or_cb_arg, req->payload_offset); + max_num_sgl = spdk_min(req->qpair->ctrlr->max_sges, NVME_TCP_MAX_SGL_DESCRIPTORS); remaining_size = req->payload_size; do { @@ -403,11 +404,13 @@ nvme_tcp_build_sgl_request(struct nvme_tcp_qpair *tqpair, struct nvme_tcp_req *t tcp_req->iov[iovcnt].iov_len = length; remaining_size -= length; iovcnt++; - } while (remaining_size > 0 && iovcnt < NVME_TCP_MAX_SGL_DESCRIPTORS); + } while (remaining_size > 0 && iovcnt < max_num_sgl); /* Should be impossible if we did our sgl checks properly up the stack, but do a sanity check here. */ if (remaining_size > 0) { + SPDK_ERRLOG("Failed to construct tcp_req=%p, and the iovcnt=%u, remaining_size=%u\n", + tcp_req, iovcnt, remaining_size); return -1; } diff --git a/test/unit/lib/nvme/nvme_tcp.c/nvme_tcp_ut.c b/test/unit/lib/nvme/nvme_tcp.c/nvme_tcp_ut.c index 2c6790243..6086dde3e 100644 --- a/test/unit/lib/nvme/nvme_tcp.c/nvme_tcp_ut.c +++ b/test/unit/lib/nvme/nvme_tcp.c/nvme_tcp_ut.c @@ -220,12 +220,15 @@ static void test_nvme_tcp_build_sgl_request(void) { struct nvme_tcp_qpair tqpair; + struct spdk_nvme_ctrlr ctrlr = {0}; struct nvme_tcp_req tcp_req = {0}; struct nvme_request req = {{0}}; struct nvme_tcp_ut_bdev_io bio; uint64_t i; int rc; + ctrlr.max_sges = NVME_TCP_MAX_SGL_DESCRIPTORS; + tqpair.qpair.ctrlr = &ctrlr; tcp_req.req = &req; req.payload.reset_sgl_fn = nvme_tcp_ut_reset_sgl;