From 3f836b036ffcc4c452880f0792f3a0e3960244a4 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Wed, 16 Jan 2019 15:40:59 +0900 Subject: [PATCH] dif: Fix opposite definition of DIF location parameter from SPDK NVMe API SPDK NVMe driver and NVMe CLI define the parameter about DIF location as follows: If set to 1 and DIF is enabled, then DIF is transferred as the first 8 bytes of metadata. If set to 0 and DIF is enabled, then DIF is transferred as the last 8 bytes of metadata. Defaults to 0. This patch fixes the apparent inconsistency. Change-Id: I481332bb9a6caa488664dbd1fe6039270b9f9663 Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/c/440672 Tested-by: SPDK CI Jenkins Reviewed-by: wuzhouhui Reviewed-by: Paul Luse Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu Chandler-Test-Pool: SPDK Automated Test System --- include/spdk/dif.h | 4 ++-- lib/util/dif.c | 2 +- test/unit/lib/util/dif.c/dif_ut.c | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/spdk/dif.h b/include/spdk/dif.h index 684afad4c..440809e19 100644 --- a/include/spdk/dif.h +++ b/include/spdk/dif.h @@ -110,8 +110,8 @@ struct spdk_dif_error { * \param md_size Metadata size in a block. * \param md_interleave If true, metadata is interleaved with block data. * If false, metadata is separated with block data. - * \param dif_loc DIF location. If true, DIF is set in the last 8 bytes of metadata. - * If false, DIF is in the first 8 bytes of metadata. + * \param dif_loc DIF location. If true, DIF is set in the first 8 bytes of metadata. + * If false, DIF is in the last 8 bytes of metadata. * \param dif_type Type of DIF. * \param dif_flags Flag to specify the DIF action. * \param init_ref_tag Initial reference tag. For type 1, this is the diff --git a/lib/util/dif.c b/lib/util/dif.c index 04d61e66e..b39b71658 100644 --- a/lib/util/dif.c +++ b/lib/util/dif.c @@ -158,7 +158,7 @@ _dif_is_disabled(enum spdk_dif_type dif_type) static uint32_t _get_guard_interval(uint32_t block_size, uint32_t md_size, bool dif_loc, bool md_interleave) { - if (dif_loc) { + if (!dif_loc) { /* For metadata formats with more than 8 bytes, if the DIF is * contained in the last 8 bytes of metadata, then the CRC * covers all metadata up to but excluding these last 8 bytes. diff --git a/test/unit/lib/util/dif.c/dif_ut.c b/test/unit/lib/util/dif.c/dif_ut.c index 6859e64d1..99be968a8 100644 --- a/test/unit/lib/util/dif.c/dif_ut.c +++ b/test/unit/lib/util/dif.c/dif_ut.c @@ -183,7 +183,7 @@ dif_generate_and_verify_test(void) /* The case that DIF is contained in the first 8 bytes of metadata. */ _dif_generate_and_verify(&iov, - 4096 + 128, 128, false, + 4096 + 128, 128, true, SPDK_DIF_TYPE1, dif_flags, 22, 22, 0x22, 0xFFFF, 0x22, @@ -191,7 +191,7 @@ dif_generate_and_verify_test(void) /* The case that DIF is contained in the last 8 bytes of metadata. */ _dif_generate_and_verify(&iov, - 4096 + 128, 128, true, + 4096 + 128, 128, false, SPDK_DIF_TYPE1, dif_flags, 22, 22, 0x22, 0xFFFF, 0x22, @@ -613,11 +613,11 @@ dif_inject_error_and_verify(struct iovec *iovs, int iovcnt, { /* The case that DIF is contained in the first 8 bytes of metadata. */ _dif_inject_error_and_verify(iovs, iovcnt, block_size, md_size, num_blocks, - inject_flags, false); + inject_flags, true); /* The case that DIF is contained in the last 8 bytes of metadata. */ _dif_inject_error_and_verify(iovs, iovcnt, block_size, md_size, num_blocks, - inject_flags, true); + inject_flags, false); } static void @@ -935,12 +935,12 @@ dif_copy_inject_error_and_verify(struct iovec *iovs, int iovcnt, struct iovec *b /* The case that DIF is contained in the first 8 bytes of metadata. */ _dif_copy_inject_error_and_verify(iovs, iovcnt, bounce_iov, block_size, md_size, num_blocks, - inject_flags, false); + inject_flags, true); /* The case that DIF is contained in the last 8 bytes of metadata. */ _dif_copy_inject_error_and_verify(iovs, iovcnt, bounce_iov, block_size, md_size, num_blocks, - inject_flags, true); + inject_flags, false); } static void @@ -1219,11 +1219,11 @@ dix_inject_error_and_verify(struct iovec *iovs, int iovcnt, struct iovec *md_iov { /* The case that DIF is contained in the first 8 bytes of metadata. */ _dix_inject_error_and_verify(iovs, iovcnt, md_iov, block_size, md_size, num_blocks, - inject_flags, false); + inject_flags, true); /* The case that DIF is contained in the last 8 bytes of metadata. */ _dix_inject_error_and_verify(iovs, iovcnt, md_iov, block_size, md_size, num_blocks, - inject_flags, true); + inject_flags, false); } static void