From 94f67dd5ae0ab903c0d15b2eee4546077a3f8c24 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Thu, 13 Jun 2019 07:39:29 +0900 Subject: [PATCH] dif: Change data_len of spdk_dif_set_md_interleave_iovs to be remaining length This patch changes the meaning of the data_len parameter of spdk_dif_set_md_interleave_iovs from `Expected data length of the payload` to `Expected length of the newly read data in the extended LBA payload`. This change will align the parameters of spdk_dif_set_md_intereleave_iovs to of spdk_dif_generate_stream. Signed-off-by: Shuhei Matsumoto Change-Id: I7f9c45e78be977625713acb79d2ae82d4375f419 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/457543 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Darek Stojaczyk --- include/spdk/dif.h | 2 +- lib/iscsi/iscsi.c | 7 ++++--- lib/util/dif.c | 11 +++-------- test/unit/lib/util/dif.c/dif_ut.c | 10 ++++++++++ 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/include/spdk/dif.h b/include/spdk/dif.h index 20dd17e3d..89a7fef24 100644 --- a/include/spdk/dif.h +++ b/include/spdk/dif.h @@ -293,7 +293,7 @@ int spdk_dix_inject_error(struct iovec *iovs, int iovcnt, struct iovec *md_iov, * \param buf_iovs SGL for the buffer to create extended LBA payload. * \param buf_iovcnt Size of the SGL for the buffer to create extended LBA payload. * \param data_offset Offset to store the next incoming data. - * \param data_len Expected data length of the payload. + * \param data_len Expected length of the newly read data in the extended LBA payload. * \param mapped_len Output parameter that will contain data length mapped by * the iovec array. * \param ctx DIF context. diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index fac2e952d..560c8a091 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -386,7 +386,8 @@ iscsi_conn_read_data_segment(struct spdk_iscsi_conn *conn, buf_iov.iov_base = pdu->data_buf; buf_iov.iov_len = pdu->data_buf_len; rc = spdk_dif_set_md_interleave_iovs(iovs, 32, &buf_iov, 1, - pdu->data_valid_bytes, segment_len, NULL, + pdu->data_valid_bytes, + segment_len - pdu->data_valid_bytes, NULL, &pdu->dif_ctx); if (rc > 0) { rc = spdk_iscsi_conn_readv_data(conn, iovs, rc); @@ -640,8 +641,8 @@ _iscsi_sgl_append_with_md(struct _iscsi_sgl *s, buf_iov.iov_base = buf; buf_iov.iov_len = buf_len; rc = spdk_dif_set_md_interleave_iovs(s->iov, s->iovcnt, &buf_iov, 1, - s->iov_offset, data_len, &total_size, - dif_ctx); + s->iov_offset, data_len - s->iov_offset, + &total_size, dif_ctx); if (rc < 0) { SPDK_ERRLOG("Failed to setup iovs for DIF strip\n"); return false; diff --git a/lib/util/dif.c b/lib/util/dif.c index 5ea276a9f..91b182025 100644 --- a/lib/util/dif.c +++ b/lib/util/dif.c @@ -1385,17 +1385,12 @@ spdk_dif_set_md_interleave_iovs(struct iovec *iovs, int iovcnt, data_block_size = ctx->block_size - ctx->md_size; - if ((data_len % data_block_size) != 0) { - SPDK_ERRLOG("Data length must be a multiple of data block size\n"); + if (((data_offset + data_len) % data_block_size) != 0) { + SPDK_ERRLOG("Data offset + length must be a multiple of data block size\n"); return -EINVAL; } - if (data_offset >= data_len) { - SPDK_ERRLOG("Data offset must be smaller than data length\n"); - return -ERANGE; - } - - num_blocks = data_len / data_block_size; + num_blocks = (data_offset + data_len) / data_block_size; _dif_sgl_init(&dif_sgl, iovs, iovcnt); _dif_sgl_init(&buf_sgl, buf_iovs, buf_iovcnt); diff --git a/test/unit/lib/util/dif.c/dif_ut.c b/test/unit/lib/util/dif.c/dif_ut.c index 4455f63a4..8184b8db9 100644 --- a/test/unit/lib/util/dif.c/dif_ut.c +++ b/test/unit/lib/util/dif.c/dif_ut.c @@ -1430,6 +1430,7 @@ set_md_interleave_iovs_test(void) CU_ASSERT(rc == 0); data_offset += read_len; + data_len -= read_len; /* 2nd read */ rc = spdk_dif_set_md_interleave_iovs(dif_iovs, 4, &iov1, 1, @@ -1448,6 +1449,7 @@ set_md_interleave_iovs_test(void) CU_ASSERT(rc == 0); data_offset += read_len; + data_len -= read_len; /* 3rd read */ rc = spdk_dif_set_md_interleave_iovs(dif_iovs, 4, &iov1, 1, @@ -1466,6 +1468,7 @@ set_md_interleave_iovs_test(void) CU_ASSERT(rc == 0); data_offset += read_len; + data_len -= read_len; /* 4th read */ rc = spdk_dif_set_md_interleave_iovs(dif_iovs, 4, &iov1, 1, @@ -1482,6 +1485,8 @@ set_md_interleave_iovs_test(void) data_offset += read_len; CU_ASSERT(data_offset == 4096 * 4); + data_len -= read_len; + CU_ASSERT(data_len == 0); /* The second data buffer: * - Set data pattern with a space for metadata for each block. @@ -1561,6 +1566,7 @@ set_md_interleave_iovs_split_test(void) CU_ASSERT(rc == 0); data_offset += read_len; + data_len -= read_len; /* 2nd read */ rc = spdk_dif_set_md_interleave_iovs(dif_iovs, 8, iovs1, 7, @@ -1583,6 +1589,7 @@ set_md_interleave_iovs_split_test(void) CU_ASSERT(rc == 0); data_offset += read_len; + data_len -= read_len; /* 3rd read */ rc = spdk_dif_set_md_interleave_iovs(dif_iovs, 8, iovs1, 7, @@ -1605,6 +1612,7 @@ set_md_interleave_iovs_split_test(void) CU_ASSERT(rc == 0); data_offset += read_len; + data_len -= read_len; /* 4th read */ rc = spdk_dif_set_md_interleave_iovs(dif_iovs, 8, iovs1, 7, @@ -1622,6 +1630,8 @@ set_md_interleave_iovs_split_test(void) data_offset += read_len; CU_ASSERT(data_offset == 512 * 4); + data_len -= read_len; + CU_ASSERT(data_len == 0); /* The second SGL data buffer: * - Set data pattern with a space for metadata for each block.