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

dif: Merge single and multiple iovec cases of spdk_dif_generate_stream



As same as spdk_dif_set_md_interleave_iovs, no noticeable performance
difference was observed even if dif_generate_stream and
dif_generate_stream_split are merged into the latter.

spdk_dif_generate_stream will be updated in subsequent patches anyway.
Hence merge them into dif_generate_stream_split.

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


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
parent 759a700f
Loading
Loading
Loading
Loading
+7 −55
Original line number Diff line number Diff line
@@ -1438,49 +1438,18 @@ end:
	return iovcnt - dif_sgl.iovcnt;
}

static int
dif_generate_stream(uint8_t *buf, uint32_t buf_len,
int
spdk_dif_generate_stream(struct iovec *iovs, int iovcnt,
			 uint32_t data_offset, uint32_t data_len,
			 const struct spdk_dif_ctx *ctx)
{
	uint32_t data_block_size, offset_blocks, num_blocks, i;
	uint16_t guard = 0;

	data_block_size = ctx->block_size - ctx->md_size;

	offset_blocks = data_offset / data_block_size;
	data_len += data_offset % data_block_size;

	data_offset = offset_blocks * ctx->block_size;
	num_blocks = data_len / data_block_size;

	if (data_offset + num_blocks * ctx->block_size > buf_len) {
		return -ERANGE;
	}

	buf += data_offset;

	for (i = 0; i < num_blocks; i++) {
		if (ctx->dif_flags & SPDK_DIF_FLAGS_GUARD_CHECK) {
			guard = spdk_crc16_t10dif(ctx->guard_seed, buf, ctx->guard_interval);
		}

		_dif_generate(buf + ctx->guard_interval, guard, offset_blocks + i, ctx);

		buf += ctx->block_size;
	}
	struct _dif_sgl sgl;

	return 0;
	if (iovs == NULL || iovcnt == 0) {
		return -EINVAL;
	}

static int
dif_generate_stream_split(struct iovec *iovs, int iovcnt,
			  uint32_t data_offset, uint32_t data_len,
			  const struct spdk_dif_ctx *ctx)
{
	uint32_t data_block_size, offset_blocks, num_blocks, i;
	struct _dif_sgl sgl;

	data_block_size = ctx->block_size - ctx->md_size;

	offset_blocks = data_offset / data_block_size;
@@ -1503,20 +1472,3 @@ dif_generate_stream_split(struct iovec *iovs, int iovcnt,

	return 0;
}

int
spdk_dif_generate_stream(struct iovec *iovs, int iovcnt,
			 uint32_t data_offset, uint32_t data_len,
			 const struct spdk_dif_ctx *ctx)
{
	if (iovs == NULL || iovcnt == 0) {
		return -EINVAL;
	}

	if (iovcnt == 1) {
		return dif_generate_stream(iovs[0].iov_base, iovs[0].iov_len,
					   data_offset, data_len, ctx);
	} else {
		return dif_generate_stream_split(iovs, iovcnt, data_offset, data_len, ctx);
	}
}