diff --git a/include/spdk/dif.h b/include/spdk/dif.h index 9f030d4c0..06d279396 100644 --- a/include/spdk/dif.h +++ b/include/spdk/dif.h @@ -289,15 +289,15 @@ int spdk_dif_set_md_interleave_iovs(struct iovec *iovs, int iovcnt, /** * Generate and insert DIF into metadata space for newly read data block. * - * \param buf Buffer to create extended LBA payload. - * \param buf_len Length of the buffer to create extended LBA payload. - * \param offset Offset to the newly read data. - * \param read_len Length of the newly read data. + * \param iovs iovec array describing the extended LBA payload. + * \param iovcnt Number of elements in the iovec array. + * \param offset Offset to the newly read data in the extended LBA payload. + * \param read_len Length of the newly read data in the extended LBA payload. * \param ctx DIF context. * * \return 0 on success and negated errno otherwise. */ -int spdk_dif_generate_stream(uint8_t *buf, uint32_t buf_len, +int spdk_dif_generate_stream(struct iovec *iovs, int iovcnt, uint32_t offset, uint32_t read_len, const struct spdk_dif_ctx *ctx); #endif /* SPDK_DIF_H */ diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index 3855d521e..f58ca8bba 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -384,7 +384,7 @@ iscsi_conn_read_data_segment(struct spdk_iscsi_conn *conn, if (rc > 0) { rc = spdk_iscsi_conn_readv_data(conn, iovs, rc); if (rc > 0) { - _rc = spdk_dif_generate_stream(pdu->data_buf, pdu->data_buf_len, + _rc = spdk_dif_generate_stream(&buf_iov, 1, pdu->data_valid_bytes, rc, &dif_ctx); if (_rc != 0) { diff --git a/lib/util/dif.c b/lib/util/dif.c index 023ce58d3..c5c377153 100644 --- a/lib/util/dif.c +++ b/lib/util/dif.c @@ -1426,18 +1426,14 @@ spdk_dif_set_md_interleave_iovs(struct iovec *iovs, int iovcnt, } } -int -spdk_dif_generate_stream(uint8_t *buf, uint32_t buf_len, - uint32_t offset, uint32_t read_len, - const struct spdk_dif_ctx *ctx) +static int +dif_generate_stream(uint8_t *buf, uint32_t buf_len, + uint32_t offset, uint32_t read_len, + const struct spdk_dif_ctx *ctx) { uint32_t data_block_size, offset_blocks, num_blocks, i; uint16_t guard = 0; - if (buf == NULL) { - return -EINVAL; - } - data_block_size = ctx->block_size - ctx->md_size; offset_blocks = offset / data_block_size; @@ -1464,3 +1460,20 @@ spdk_dif_generate_stream(uint8_t *buf, uint32_t buf_len, return 0; } + +int +spdk_dif_generate_stream(struct iovec *iovs, int iovcnt, + uint32_t offset, uint32_t read_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, + offset, read_len, ctx); + } else { + return -EINVAL; + } +} diff --git a/test/unit/lib/util/dif.c/dif_ut.c b/test/unit/lib/util/dif.c/dif_ut.c index 0c43561f3..e45a23c39 100644 --- a/test/unit/lib/util/dif.c/dif_ut.c +++ b/test/unit/lib/util/dif.c/dif_ut.c @@ -1422,7 +1422,7 @@ set_md_interleave_iovs_test(void) read_base = ut_readv(0, 1024, dif_iovs, 4); CU_ASSERT(read_base == 1024); - rc = spdk_dif_generate_stream(buf1, (4096 + 128) * 4, 0, 1024, &ctx); + rc = spdk_dif_generate_stream(&iov1, 1, 0, 1024, &ctx); CU_ASSERT(rc == 0); rc = spdk_dif_set_md_interleave_iovs(dif_iovs, 4, &iov1, 1, @@ -1437,7 +1437,7 @@ set_md_interleave_iovs_test(void) read_base += ut_readv(read_base, 3071, dif_iovs, 4); CU_ASSERT(read_base == 4095); - rc = spdk_dif_generate_stream(buf1, (4096 + 128) * 4, 1024, 3071, &ctx); + rc = spdk_dif_generate_stream(&iov1, 1, 1024, 3071, &ctx); CU_ASSERT(rc == 0); rc = spdk_dif_set_md_interleave_iovs(dif_iovs, 4, &iov1, 1, @@ -1452,7 +1452,7 @@ set_md_interleave_iovs_test(void) read_base += ut_readv(read_base, 1 + 4096 * 2 + 512, dif_iovs, 4); CU_ASSERT(read_base == 4096 * 3 + 512); - rc = spdk_dif_generate_stream(buf1, (4096 + 128) * 4, 4095, 1 + 4096 * 2 + 512, &ctx); + rc = spdk_dif_generate_stream(&iov1, 1, 4095, 1 + 4096 * 2 + 512, &ctx); CU_ASSERT(rc == 0); rc = spdk_dif_set_md_interleave_iovs(dif_iovs, 4, &iov1, 1, @@ -1464,7 +1464,7 @@ set_md_interleave_iovs_test(void) read_base += ut_readv(read_base, 3584, dif_iovs, 1); CU_ASSERT(read_base == 4096 * 4); - rc = spdk_dif_generate_stream(buf1, (4096 + 128) * 4, 4096 * 3 + 512, 3584, &ctx); + rc = spdk_dif_generate_stream(&iov1, 1, 4096 * 3 + 512, 3584, &ctx); CU_ASSERT(rc == 0); /* The second data buffer: @@ -1604,25 +1604,25 @@ dif_generate_stream_test(void) 22, 0xFFFF, 0x22, GUARD_SEED); CU_ASSERT(rc == 0); - rc = spdk_dif_generate_stream(iov.iov_base, (512 + 8) * 5, 0, 511, &ctx); + rc = spdk_dif_generate_stream(&iov, 1, 0, 511, &ctx); CU_ASSERT(rc == 0); - rc = spdk_dif_generate_stream(iov.iov_base, (512 + 8) * 5, 511, 1, &ctx); + rc = spdk_dif_generate_stream(&iov, 1, 511, 1, &ctx); CU_ASSERT(rc == 0); - rc = spdk_dif_generate_stream(iov.iov_base, (512 + 8) * 5, 512, 256, &ctx); + rc = spdk_dif_generate_stream(&iov, 1, 512, 256, &ctx); CU_ASSERT(rc == 0); - rc = spdk_dif_generate_stream(iov.iov_base, (512 + 8) * 5, 768, 512, &ctx); + rc = spdk_dif_generate_stream(&iov, 1, 768, 512, &ctx); CU_ASSERT(rc == 0); - rc = spdk_dif_generate_stream(iov.iov_base, (512 + 8) * 5, 1280, 1024, &ctx); + rc = spdk_dif_generate_stream(&iov, 1, 1280, 1024, &ctx); CU_ASSERT(rc == 0); - rc = spdk_dif_generate_stream(iov.iov_base, (512 + 8) * 5, 2304, 256, &ctx); + rc = spdk_dif_generate_stream(&iov, 1, 2304, 256, &ctx); CU_ASSERT(rc == 0); - rc = spdk_dif_generate_stream(iov.iov_base, (512 + 8) * 5, 2560, 512, &ctx); + rc = spdk_dif_generate_stream(&iov, 1, 2560, 512, &ctx); CU_ASSERT(rc == -ERANGE); rc = spdk_dif_verify(&iov, 1, 5, &ctx, &err_blk);