From ade7d070f27dd92d51775b406274d8a35825cf6c Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Wed, 19 Jun 2019 09:04:42 +0900 Subject: [PATCH] nvme/tcp: Factor out operation to append multiple SGL entries Such small refactoring will be helpful to add DIF insert/strip feature, and is done in this patch. Signed-off-by: Shuhei Matsumoto Change-Id: I4b16a041d176acef948d2af1a5a1811380287738 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/458527 Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Darek Stojaczyk --- include/spdk_internal/nvme_tcp.h | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/include/spdk_internal/nvme_tcp.h b/include/spdk_internal/nvme_tcp.h index ad9160692..0b1cf89a0 100644 --- a/include/spdk_internal/nvme_tcp.h +++ b/include/spdk_internal/nvme_tcp.h @@ -247,12 +247,26 @@ _nvme_tcp_sgl_append(struct _nvme_tcp_sgl *s, uint8_t *data, uint32_t data_len) return true; } +static inline bool +_nvme_tcp_sgl_append_multi(struct _nvme_tcp_sgl *s, struct iovec *iov, int iovcnt) +{ + int i; + + for (i = 0; i < iovcnt; i++) { + if (!_nvme_tcp_sgl_append(s, iov[i].iov_base, iov[i].iov_len)) { + return false; + } + } + + return true; +} + static int nvme_tcp_build_iovs(struct iovec *iov, int iovcnt, struct nvme_tcp_pdu *pdu, bool hdgst_enable, bool ddgst_enable, uint32_t *_mapped_length) { int enable_digest; - uint32_t hlen, plen, i; + uint32_t hlen, plen; struct _nvme_tcp_sgl *sgl; if (iovcnt == 0) { @@ -295,10 +309,8 @@ nvme_tcp_build_iovs(struct iovec *iov, int iovcnt, struct nvme_tcp_pdu *pdu, /* Data Segment */ plen += pdu->data_len; - for (i = 0; i < pdu->data_iovcnt; i++) { - if (!_nvme_tcp_sgl_append(sgl, pdu->data_iov[i].iov_base, pdu->data_iov[i].iov_len)) { - goto end; - } + if (!_nvme_tcp_sgl_append_multi(sgl, pdu->data_iov, pdu->data_iovcnt)) { + goto end; } /* Data Digest */ @@ -325,7 +337,6 @@ nvme_tcp_build_payload_iovs(struct iovec *iov, int iovcnt, struct nvme_tcp_pdu * bool ddgst_enable, uint32_t *_mapped_length) { struct _nvme_tcp_sgl *sgl; - uint32_t i; if (iovcnt == 0) { return 0; @@ -334,10 +345,8 @@ nvme_tcp_build_payload_iovs(struct iovec *iov, int iovcnt, struct nvme_tcp_pdu * sgl = &pdu->sgl; _nvme_tcp_sgl_init(sgl, iov, iovcnt, pdu->readv_offset); - for (i = 0; i < pdu->data_iovcnt; i++) { - if (!_nvme_tcp_sgl_append(sgl, pdu->data_iov[i].iov_base, pdu->data_iov[i].iov_len)) { - goto end; - } + if (!_nvme_tcp_sgl_append_multi(sgl, pdu->data_iov, pdu->data_iovcnt)) { + goto end; } /* Data Digest */