nvme: add API to convert trtype and adrfam to string
Also add adrfam to the NVMe bdev JSON config output. Change-Id: I9472bda04947cffc0df9b02eba0035bac01b7d7b Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-on: https://review.gerrithub.io/367292 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
dbbde9991d
commit
37a7ff0fd7
@ -213,6 +213,22 @@ int spdk_nvme_transport_id_parse(struct spdk_nvme_transport_id *trid, const char
|
||||
*/
|
||||
int spdk_nvme_transport_id_parse_trtype(enum spdk_nvme_transport_type *trtype, const char *str);
|
||||
|
||||
/**
|
||||
* Look up the string representation of a transport ID transport type.
|
||||
*
|
||||
* \param trtype Transport type to convert.
|
||||
* \return Static string constant describing trtype, or NULL if trtype not found.
|
||||
*/
|
||||
const char *spdk_nvme_transport_id_trtype_str(enum spdk_nvme_transport_type trtype);
|
||||
|
||||
/**
|
||||
* Look up the string representation of a transport ID address family.
|
||||
*
|
||||
* \param adrfam Address family to convert.
|
||||
* \return Static string constant describing adrfam, or NULL if adrmfam not found.
|
||||
*/
|
||||
const char *spdk_nvme_transport_id_adrfam_str(enum spdk_nvmf_adrfam adrfam);
|
||||
|
||||
/**
|
||||
* Parse the string representation of a tranport ID address family.
|
||||
*
|
||||
|
@ -460,6 +460,8 @@ bdev_nvme_dump_config_json(void *ctx, struct spdk_json_write_ctx *w)
|
||||
struct spdk_nvme_ns *ns;
|
||||
union spdk_nvme_vs_register vs;
|
||||
union spdk_nvme_csts_register csts;
|
||||
const char *trtype_str;
|
||||
const char *adrfam_str;
|
||||
char buf[128];
|
||||
|
||||
cdata = spdk_nvme_ctrlr_get_data(nvme_bdev->nvme_ctrlr->ctrlr);
|
||||
@ -478,13 +480,16 @@ bdev_nvme_dump_config_json(void *ctx, struct spdk_json_write_ctx *w)
|
||||
spdk_json_write_name(w, "trid");
|
||||
spdk_json_write_object_begin(w);
|
||||
|
||||
spdk_json_write_name(w, "trtype");
|
||||
if (nvme_ctrlr->trid.trtype == SPDK_NVME_TRANSPORT_PCIE) {
|
||||
spdk_json_write_string(w, "PCIe");
|
||||
} else if (nvme_ctrlr->trid.trtype == SPDK_NVME_TRANSPORT_RDMA) {
|
||||
spdk_json_write_string(w, "RDMA");
|
||||
} else {
|
||||
spdk_json_write_string(w, "Unknown");
|
||||
trtype_str = spdk_nvme_transport_id_trtype_str(nvme_ctrlr->trid.trtype);
|
||||
if (trtype_str) {
|
||||
spdk_json_write_name(w, "trtype");
|
||||
spdk_json_write_string(w, trtype_str);
|
||||
}
|
||||
|
||||
adrfam_str = spdk_nvme_transport_id_adrfam_str(nvme_ctrlr->trid.adrfam);
|
||||
if (adrfam_str) {
|
||||
spdk_json_write_name(w, "adrfam");
|
||||
spdk_json_write_string(w, adrfam_str);
|
||||
}
|
||||
|
||||
if (nvme_ctrlr->trid.traddr[0] != '\0') {
|
||||
|
@ -467,6 +467,19 @@ spdk_nvme_transport_id_parse_trtype(enum spdk_nvme_transport_type *trtype, const
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *
|
||||
spdk_nvme_transport_id_trtype_str(enum spdk_nvme_transport_type trtype)
|
||||
{
|
||||
switch (trtype) {
|
||||
case SPDK_NVME_TRANSPORT_PCIE:
|
||||
return "PCIe";
|
||||
case SPDK_NVME_TRANSPORT_RDMA:
|
||||
return "RDMA";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
spdk_nvme_transport_id_parse_adrfam(enum spdk_nvmf_adrfam *adrfam, const char *str)
|
||||
{
|
||||
@ -488,6 +501,23 @@ spdk_nvme_transport_id_parse_adrfam(enum spdk_nvmf_adrfam *adrfam, const char *s
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *
|
||||
spdk_nvme_transport_id_adrfam_str(enum spdk_nvmf_adrfam adrfam)
|
||||
{
|
||||
switch (adrfam) {
|
||||
case SPDK_NVMF_ADRFAM_IPV4:
|
||||
return "IPv4";
|
||||
case SPDK_NVMF_ADRFAM_IPV6:
|
||||
return "IPv6";
|
||||
case SPDK_NVMF_ADRFAM_IB:
|
||||
return "IB";
|
||||
case SPDK_NVMF_ADRFAM_FC:
|
||||
return "FC";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
spdk_nvme_transport_id_parse(struct spdk_nvme_transport_id *trid, const char *str)
|
||||
{
|
||||
|
@ -381,6 +381,48 @@ test_spdk_nvme_transport_id_parse_adrfam(void)
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
test_trid_trtype_str(void)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
s = spdk_nvme_transport_id_trtype_str(-5);
|
||||
CU_ASSERT(s == NULL);
|
||||
|
||||
s = spdk_nvme_transport_id_trtype_str(SPDK_NVME_TRANSPORT_PCIE);
|
||||
SPDK_CU_ASSERT_FATAL(s != NULL);
|
||||
CU_ASSERT(strcmp(s, "PCIe") == 0);
|
||||
|
||||
s = spdk_nvme_transport_id_trtype_str(SPDK_NVME_TRANSPORT_RDMA);
|
||||
SPDK_CU_ASSERT_FATAL(s != NULL);
|
||||
CU_ASSERT(strcmp(s, "RDMA") == 0);
|
||||
}
|
||||
|
||||
static void
|
||||
test_trid_adrfam_str(void)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
s = spdk_nvme_transport_id_adrfam_str(-5);
|
||||
CU_ASSERT(s == NULL);
|
||||
|
||||
s = spdk_nvme_transport_id_adrfam_str(SPDK_NVMF_ADRFAM_IPV4);
|
||||
SPDK_CU_ASSERT_FATAL(s != NULL);
|
||||
CU_ASSERT(strcmp(s, "IPv4") == 0);
|
||||
|
||||
s = spdk_nvme_transport_id_adrfam_str(SPDK_NVMF_ADRFAM_IPV6);
|
||||
SPDK_CU_ASSERT_FATAL(s != NULL);
|
||||
CU_ASSERT(strcmp(s, "IPv6") == 0);
|
||||
|
||||
s = spdk_nvme_transport_id_adrfam_str(SPDK_NVMF_ADRFAM_IB);
|
||||
SPDK_CU_ASSERT_FATAL(s != NULL);
|
||||
CU_ASSERT(strcmp(s, "IB") == 0);
|
||||
|
||||
s = spdk_nvme_transport_id_adrfam_str(SPDK_NVMF_ADRFAM_FC);
|
||||
SPDK_CU_ASSERT_FATAL(s != NULL);
|
||||
CU_ASSERT(strcmp(s, "FC") == 0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
CU_pSuite suite = NULL;
|
||||
@ -405,6 +447,8 @@ int main(int argc, char **argv)
|
||||
test_spdk_nvme_transport_id_parse_adrfam) == NULL ||
|
||||
CU_add_test(suite, "test_trid_parse_and_compare",
|
||||
test_trid_parse_and_compare) == NULL ||
|
||||
CU_add_test(suite, "test_trid_trtype_str", test_trid_trtype_str) == NULL ||
|
||||
CU_add_test(suite, "test_trid_adrfam_str", test_trid_adrfam_str) == NULL ||
|
||||
CU_add_test(suite, "test_nvme_robust_mutex_init_shared",
|
||||
test_nvme_robust_mutex_init_shared) == NULL
|
||||
) {
|
||||
|
Loading…
Reference in New Issue
Block a user