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

nvme/tcp: Minor cleanups for SGL operations



Using naming rules consistent with other related libraries is helpful
to ensure the quality as verified by this patch series.

This patch changes a few parts to use iov and iovcnt for SGL operations.
Besides, name of an array points to the head of the array and is
constant. So copying name of array to an another pointer is not
necessary and can be removed.

Change-Id: I2324f28126b3088098c1c767cf6c060f22c175c3
Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/455629


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: default avatarPaul Luse <paul.e.luse@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarMaciej Szwed <maciej.szwed@intel.com>
Reviewed-by: default avatarZiye Yang <ziye.yang@intel.com>
parent 127cfac0
Loading
Loading
Loading
Loading
+16 −17
Original line number Diff line number Diff line
@@ -248,19 +248,19 @@ _nvme_tcp_sgl_append(struct _nvme_tcp_sgl *s, uint8_t *data, uint32_t data_len)
}

static int
nvme_tcp_build_iovecs(struct iovec *iovec, int num_iovs, struct nvme_tcp_pdu *pdu,
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;
	struct _nvme_tcp_sgl *sgl;

	if (num_iovs == 0) {
	if (iovcnt == 0) {
		return 0;
	}

	sgl = &pdu->sgl;
	_nvme_tcp_sgl_init(sgl, iovec, num_iovs, pdu->writev_offset);
	_nvme_tcp_sgl_init(sgl, iov, iovcnt, pdu->writev_offset);
	hlen = pdu->hdr.common.hlen;
	enable_digest = 1;
	if (pdu->hdr.common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_IC_REQ ||
@@ -317,22 +317,22 @@ end:
		assert(plen == pdu->hdr.common.plen);
	}

	return num_iovs - sgl->iovcnt;
	return iovcnt - sgl->iovcnt;
}

static int
nvme_tcp_build_payload_iovecs(struct iovec *iovec, int num_iovs, struct nvme_tcp_pdu *pdu,
nvme_tcp_build_payload_iovs(struct iovec *iov, int iovcnt, struct nvme_tcp_pdu *pdu,
			    bool ddgst_enable, uint32_t *_mapped_length)
{
	struct _nvme_tcp_sgl *sgl;
	uint32_t i;

	if (num_iovs == 0) {
	if (iovcnt == 0) {
		return 0;
	}

	sgl = &pdu->sgl;
	_nvme_tcp_sgl_init(sgl, iovec, num_iovs, pdu->readv_offset);
	_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)) {
@@ -349,7 +349,7 @@ end:
	if (_mapped_length != NULL) {
		*_mapped_length = sgl->total_size;
	}
	return num_iovs - sgl->iovcnt;
	return iovcnt - sgl->iovcnt;
}

static int
@@ -426,15 +426,14 @@ nvme_tcp_readv_data(struct spdk_sock *sock, struct iovec *iov, int iovcnt)
static int
nvme_tcp_read_payload_data(struct spdk_sock *sock, struct nvme_tcp_pdu *pdu)
{
	struct iovec iovec_array[NVME_TCP_MAX_SGL_DESCRIPTORS + 1];
	struct iovec *iov = iovec_array;
	int iovec_cnt;
	struct iovec iov[NVME_TCP_MAX_SGL_DESCRIPTORS + 1];
	int iovcnt;

	iovec_cnt = nvme_tcp_build_payload_iovecs(iovec_array, NVME_TCP_MAX_SGL_DESCRIPTORS + 1, pdu,
	iovcnt = nvme_tcp_build_payload_iovs(iov, NVME_TCP_MAX_SGL_DESCRIPTORS + 1, pdu,
					     pdu->ddgst_enable, NULL);
	assert(iovec_cnt >= 0);
	assert(iovcnt >= 0);

	return nvme_tcp_readv_data(sock, iov, iovec_cnt);
	return nvme_tcp_readv_data(sock, iov, iovcnt);
}

static void
+7 −8
Original line number Diff line number Diff line
@@ -383,9 +383,8 @@ static int
nvme_tcp_qpair_process_send_queue(struct nvme_tcp_qpair *tqpair)
{
	const int array_size = 32;
	struct iovec	iovec_array[array_size];
	struct iovec	*iov = iovec_array;
	int iovec_cnt = 0;
	struct iovec iovs[array_size];
	int iovcnt = 0;
	int bytes = 0;
	uint32_t mapped_length;
	struct nvme_tcp_pdu *pdu;
@@ -402,14 +401,14 @@ nvme_tcp_qpair_process_send_queue(struct nvme_tcp_qpair *tqpair)
	 * Build up a list of iovecs for the first few PDUs in the
	 *  tqpair 's send_queue.
	 */
	while (pdu != NULL && ((array_size - iovec_cnt) >= 3)) {
		iovec_cnt += nvme_tcp_build_iovecs(&iovec_array[iovec_cnt], array_size - iovec_cnt,
	while (pdu != NULL && ((array_size - iovcnt) >= 3)) {
		iovcnt += nvme_tcp_build_iovs(&iovs[iovcnt], array_size - iovcnt,
					      pdu, tqpair->host_hdgst_enable,
					      tqpair->host_ddgst_enable, &mapped_length);
		pdu = TAILQ_NEXT(pdu, tailq);
	}

	bytes = spdk_sock_writev(tqpair->sock, iov, iovec_cnt);
	bytes = spdk_sock_writev(tqpair->sock, iovs, iovcnt);
	SPDK_DEBUGLOG(SPDK_LOG_NVME, "bytes=%d are out\n", bytes);
	if (bytes == -1) {
		if (errno == EWOULDBLOCK || errno == EAGAIN) {
+11 −12
Original line number Diff line number Diff line
@@ -755,9 +755,8 @@ static int
spdk_nvmf_tcp_qpair_flush_pdus_internal(struct spdk_nvmf_tcp_qpair *tqpair)
{
	const int array_size = 32;
	struct iovec	iovec_array[array_size];
	struct iovec	*iov = iovec_array;
	int iovec_cnt = 0;
	struct iovec iovs[array_size];
	int iovcnt = 0;
	int bytes = 0;
	int total_length = 0;
	uint32_t mapped_length;
@@ -776,9 +775,9 @@ spdk_nvmf_tcp_qpair_flush_pdus_internal(struct spdk_nvmf_tcp_qpair *tqpair)
	 * Build up a list of iovecs for the first few PDUs in the
	 *  tqpair 's send_queue.
	 */
	while (pdu != NULL && ((array_size - iovec_cnt) >= 3)) {
		iovec_cnt += nvme_tcp_build_iovecs(&iovec_array[iovec_cnt],
						   array_size - iovec_cnt,
	while (pdu != NULL && ((array_size - iovcnt) >= 3)) {
		iovcnt += nvme_tcp_build_iovs(&iovs[iovcnt],
					      array_size - iovcnt,
					      pdu,
					      tqpair->host_hdgst_enable,
					      tqpair->host_ddgst_enable,
@@ -787,9 +786,9 @@ spdk_nvmf_tcp_qpair_flush_pdus_internal(struct spdk_nvmf_tcp_qpair *tqpair)
		pdu = TAILQ_NEXT(pdu, tailq);
	}

	spdk_trace_record(TRACE_TCP_FLUSH_WRITEBUF_START, 0, total_length, 0, iovec_cnt);
	spdk_trace_record(TRACE_TCP_FLUSH_WRITEBUF_START, 0, total_length, 0, iovcnt);

	bytes = spdk_sock_writev(tqpair->sock, iov, iovec_cnt);
	bytes = spdk_sock_writev(tqpair->sock, iovs, iovcnt);
	if (bytes == -1) {
		if (errno == EWOULDBLOCK || errno == EAGAIN) {
			return 1;