Commit a5e3d61d authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Jim Harris
Browse files

dif: handle the case that metadata is supported but DIF is not enabled as normal



The case that metadata is supported but DIF is not enabled was
handled as error. But the case is described as an normal case
in NVMe specification.

This patch changes the case to normal.

Besides a break was missing and added in this patch.

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


Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarGangCao <gang.cao@intel.com>
Reviewed-by: default avatarwuzhouhui <wuzhouhui@kingsoft.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 2077fbd7
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -47,9 +47,10 @@
#define SPDK_DIF_DATA_ERROR	0x8

enum spdk_dif_type {
	SPDK_DIF_DISABLE = 0,
	SPDK_DIF_TYPE1 = 1,
	SPDK_DIF_TYPE2,
	SPDK_DIF_TYPE3,
	SPDK_DIF_TYPE2 = 2,
	SPDK_DIF_TYPE3 = 3,
};

struct spdk_dif {
+24 −0
Original line number Diff line number Diff line
@@ -133,6 +133,7 @@ _dif_type_is_valid(enum spdk_dif_type dif_type, uint32_t dif_flags)
	switch (dif_type) {
	case SPDK_DIF_TYPE1:
	case SPDK_DIF_TYPE2:
	case SPDK_DIF_DISABLE:
		break;
	case SPDK_DIF_TYPE3:
		if (dif_flags & SPDK_DIF_REFTAG_CHECK) {
@@ -148,6 +149,16 @@ _dif_type_is_valid(enum spdk_dif_type dif_type, uint32_t dif_flags)
	return true;
}

static bool
_dif_is_disabled(enum spdk_dif_type dif_type)
{
	if (dif_type == SPDK_DIF_DISABLE) {
		return true;
	} else {
		return false;
	}
}

static uint32_t
_get_dif_guard_interval(uint32_t block_size, uint32_t md_size, bool dif_loc)
{
@@ -323,6 +334,10 @@ spdk_dif_generate(struct iovec *iovs, int iovcnt,
		return -EINVAL;
	}

	if (_dif_is_disabled(dif_type)) {
		return 0;
	}

	guard_interval = _get_dif_guard_interval(block_size, md_size, dif_loc);

	if (_are_iovs_bytes_multiple(iovs, iovcnt, block_size)) {
@@ -362,6 +377,9 @@ _dif_verify(void *_dif, enum spdk_dif_type dif_type, uint32_t dif_flags,
		if (dif->app_tag == 0xFFFF && dif->ref_tag == 0xFFFFFFFF) {
			return 0;
		}
		break;
	default:
		break;
	}

	if (dif_flags & SPDK_DIF_GUARD_CHECK) {
@@ -412,6 +430,8 @@ _dif_verify(void *_dif, enum spdk_dif_type dif_type, uint32_t dif_flags,
			 * Hence ignore the Reference Tag field.
			 */
			break;
		default:
			break;
		}
	}

@@ -564,6 +584,10 @@ spdk_dif_verify(struct iovec *iovs, int iovcnt,
		return -EINVAL;
	}

	if (_dif_is_disabled(dif_type)) {
		return 0;
	}

	guard_interval = _get_dif_guard_interval(block_size, md_size, dif_loc);

	if (_are_iovs_bytes_multiple(iovs, iovcnt, block_size)) {
+14 −0
Original line number Diff line number Diff line
@@ -290,6 +290,18 @@ dif_generate_and_verify(struct iovec *iovs, int iovcnt,
	CU_ASSERT(rc == 0);
}

static void
dif_disable_sec_512_md_8_single_iov_test(void)
{
	struct iovec iov;

	_iov_alloc_buf(&iov, (512 + 8) * 4);

	dif_generate_and_verify(&iov, 1, 512 + 8, 8, 1, false, SPDK_DIF_DISABLE, 0, 0, 0, 0);

	_iov_free_buf(&iov);
}

static void
dif_sec_512_md_8_prchk_0_single_iov_test(void)
{
@@ -717,6 +729,8 @@ main(int argc, char **argv)
		CU_add_test(suite, "dif_generate_and_verify_test", dif_generate_and_verify_test) == NULL ||
		CU_add_test(suite, "dif_disable_check_test", dif_disable_check_test) == NULL ||
		CU_add_test(suite, "dif_sec_512_md_0_error_test", dif_sec_512_md_0_error_test) == NULL ||
		CU_add_test(suite, "dif_disable_sec_512_md_8_single_iov_test",
			    dif_disable_sec_512_md_8_single_iov_test) == NULL ||
		CU_add_test(suite, "dif_sec_512_md_8_prchk_0_single_iov_test",
			    dif_sec_512_md_8_prchk_0_single_iov_test) == NULL ||
		CU_add_test(suite, "dif_sec_512_md_8_prchk_0_1_2_4_multi_iovs_test",