diff --git a/include/spdk/env.h b/include/spdk/env.h index f40397efd..5d656de61 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -237,6 +237,19 @@ int spdk_pci_addr_compare(const struct spdk_pci_addr *a1, const struct spdk_pci_ */ int spdk_pci_addr_parse(struct spdk_pci_addr *addr, const char *bdf); +/** + * Convert a struct spdk_pci_addr to a string. + * + * \param bdf String into which a string will be output in the format + * domain:bus:device.function. The string must be at least + * 14 characters in size. + * \param sz Size of bdf. Must be at least 14. + * \param addr PCI address input + * + * \return 0 on success, or a negated errno value on failure. + */ +int spdk_pci_addr_fmt(char *bdf, size_t sz, const struct spdk_pci_addr *addr); + /** * Call a function with CPU affinity unset. * diff --git a/lib/env_dpdk/pci.c b/lib/env_dpdk/pci.c index 45e350583..b9c56b825 100644 --- a/lib/env_dpdk/pci.c +++ b/lib/env_dpdk/pci.c @@ -429,3 +429,19 @@ spdk_pci_addr_parse(struct spdk_pci_addr *addr, const char *bdf) return 0; } + +int +spdk_pci_addr_fmt(char *bdf, size_t sz, const struct spdk_pci_addr *addr) +{ + int rc; + + rc = snprintf(bdf, sz, PCI_PRI_FMT, + addr->domain, addr->bus, + addr->dev, addr->func); + + if (rc > 0 && (size_t)rc < sz) { + return 0; + } + + return -1; +}