Commit 4caf3c56 authored by Ben Walker's avatar Ben Walker Committed by Daniel Verkamp
Browse files

env: Add a function to convert pci addr to string



Convert an spdk_pci_addr to a string.

Change-Id: Idab0a16822cc37d7095d19f062dfca65356211e8
Signed-off-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 8a9c1d40
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -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.
 *
+16 −0
Original line number Diff line number Diff line
@@ -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;
}