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;