Commit 5c9dccc9 authored by Ziye Yang's avatar Ziye Yang Committed by Changpeng Liu
Browse files

nvme: fix the parse of spdk_nvme_transport_id_parse



Normally, there will be only one separator in transport id,
for example, either ':' or '='. But the users may input
this: trtype=PCIe traddr=0000:81:00.0.

Thus, there will be two diffrent separator '=' and ':',
and our function doest not handle this case correctly.
And this patch can fix this issue, and also update the
test case.

Change-Id: Ic3f10dc1e37c66647fede37c5cf9523fc2652677
Signed-off-by: default avatarZiye Yang <ziye.yang@intel.com>
Reviewed-on: https://review.gerrithub.io/428307


Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent 93ee8c7a
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -711,7 +711,7 @@ spdk_nvme_transport_id_adrfam_str(enum spdk_nvmf_adrfam adrfam)
int
spdk_nvme_transport_id_parse(struct spdk_nvme_transport_id *trid, const char *str)
{
	const char *sep;
	const char *sep, *sep1;
	const char *whitespace = " \t\n";
	size_t key_len, val_len;
	char key[32];
@@ -731,6 +731,11 @@ spdk_nvme_transport_id_parse(struct spdk_nvme_transport_id *trid, const char *st
				SPDK_ERRLOG("Key without ':' or '=' separator\n");
				return -EINVAL;
			}
		} else {
			sep1 = strchr(str, '=');
			if ((sep1 != NULL) && (sep1 < sep)) {
				sep = sep1;
			}
		}

		key_len = sep - str;
+5 −0
Original line number Diff line number Diff line
@@ -913,6 +913,11 @@ test_trid_parse_and_compare(void)
	CU_ASSERT(spdk_nvme_transport_id_parse(&trid1, "trtype:PCIe traddr:0000:04:00.0") == 0);
	CU_ASSERT(spdk_nvme_transport_id_parse(&trid2, "trtype:PCIe traddr:05:00.0") == 0);
	CU_ASSERT(spdk_nvme_transport_id_compare(&trid1, &trid2) < 0);

	memset_trid(&trid1, &trid2);
	CU_ASSERT(spdk_nvme_transport_id_parse(&trid1, "trtype=PCIe traddr=0000:04:00.0") == 0);
	CU_ASSERT(spdk_nvme_transport_id_parse(&trid2, "trtype=PCIe traddr=05:00.0") == 0);
	CU_ASSERT(spdk_nvme_transport_id_compare(&trid1, &trid2) < 0);
}

static void