diff --git a/include/spdk/nvme.h b/include/spdk/nvme.h index 3b4d2e4e8..9bfdc4409 100644 --- a/include/spdk/nvme.h +++ b/include/spdk/nvme.h @@ -195,6 +195,24 @@ struct spdk_nvme_transport_id { */ int spdk_nvme_transport_id_parse(struct spdk_nvme_transport_id *trid, const char *str); +/** + * Parse the string representation of a transport ID tranport type. + * + * \param trtype Output transport type (allocated by caller). + * \param str Input string representation of transport type (e.g. "PCIe", "RDMA") + * \return 0 if parsing was successful and trtype is filled out, or negated errno values on failure. + */ +int spdk_nvme_transport_id_parse_trtype(enum spdk_nvme_transport_type *trtype, const char *str); + +/** + * Parse the string representation of a tranport ID address family. + * + * \param adrfam Output address family (allocated by caller). + * \param str Input string representation of address family (e.g. "IPv4", "IPv6") + * \return 0 if parsing was successful and adrfam is filled out, or negated errno values on failure. + */ +int spdk_nvme_transport_id_parse_adrfam(enum spdk_nvmf_adrfam *adrfam, const char *str); + /** * Determine whether the NVMe library can handle a specific NVMe over Fabrics transport type. * diff --git a/lib/nvme/nvme.c b/lib/nvme/nvme.c index fa5404fc7..0a00dde94 100644 --- a/lib/nvme/nvme.c +++ b/lib/nvme/nvme.c @@ -443,9 +443,13 @@ spdk_nvme_probe(const struct spdk_nvme_transport_id *trid, void *cb_ctx, return rc; } -static int -parse_trtype(enum spdk_nvme_transport_type *trtype, const char *str) +int +spdk_nvme_transport_id_parse_trtype(enum spdk_nvme_transport_type *trtype, const char *str) { + if (trtype == NULL || str == NULL) { + return -EINVAL; + } + if (strcasecmp(str, "PCIe") == 0) { *trtype = SPDK_NVME_TRANSPORT_PCIE; } else if (strcasecmp(str, "RDMA") == 0) { @@ -456,9 +460,13 @@ parse_trtype(enum spdk_nvme_transport_type *trtype, const char *str) return 0; } -static int -parse_adrfam(enum spdk_nvmf_adrfam *adrfam, const char *str) +int +spdk_nvme_transport_id_parse_adrfam(enum spdk_nvmf_adrfam *adrfam, const char *str) { + if (adrfam == NULL || str == NULL) { + return -EINVAL; + } + if (strcasecmp(str, "IPv4") == 0) { *adrfam = SPDK_NVMF_ADRFAM_IPV4; } else if (strcasecmp(str, "IPv6") == 0) { @@ -524,12 +532,12 @@ spdk_nvme_transport_id_parse(struct spdk_nvme_transport_id *trid, const char *st str += val_len; if (strcasecmp(key, "trtype") == 0) { - if (parse_trtype(&trid->trtype, val) != 0) { + if (spdk_nvme_transport_id_parse_trtype(&trid->trtype, val) != 0) { SPDK_ERRLOG("Unknown trtype '%s'\n", val); return -EINVAL; } } else if (strcasecmp(key, "adrfam") == 0) { - if (parse_adrfam(&trid->adrfam, val) != 0) { + if (spdk_nvme_transport_id_parse_adrfam(&trid->adrfam, val) != 0) { SPDK_ERRLOG("Unknown adrfam '%s'\n", val); return -EINVAL; }