Commit ade7d070 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Darek Stojaczyk
Browse files

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: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I4b16a041d176acef948d2af1a5a1811380287738
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/458527


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
parent b2982b7d
Loading
Loading
Loading
Loading
+19 −10
Original line number Diff line number Diff line
@@ -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,11 +309,9 @@ 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)) {
	if (!_nvme_tcp_sgl_append_multi(sgl, pdu->data_iov, pdu->data_iovcnt)) {
		goto end;
	}
	}

	/* Data Digest */
	if (enable_digest && ddgst_enable) {
@@ -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,11 +345,9 @@ 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)) {
	if (!_nvme_tcp_sgl_append_multi(sgl, pdu->data_iov, pdu->data_iovcnt)) {
		goto end;
	}
	}

	/* Data Digest */
	if (ddgst_enable) {