From 6af9bb35608e8b14533e973cd46abfc17d516d77 Mon Sep 17 00:00:00 2001 From: Shivaprasad G Bhat Date: Wed, 14 Jan 2015 06:02:40 -0500 Subject: [PATCH] virpci: Implement virPCIDeviceGetAddress function Basically a getter function which is implemented for accessing the address fields in virPCIDevice. Signed-off-by: Shivaprasad G Bhat Signed-off-by: Michal Privoznik --- src/util/virpci.c | 26 ++++++++++++++++++++++++++ src/util/virpci.h | 1 + 2 files changed, 27 insertions(+) diff --git a/src/util/virpci.c b/src/util/virpci.c index cd78212a00..512e8399eb 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1655,6 +1655,32 @@ virPCIDeviceFree(virPCIDevicePtr dev) VIR_FREE(dev); } +/** + * virPCIDeviceGetAddress: + * @dev: device to get address from + * + * Take a PCI device on input and return its PCI address. The + * caller must free the returned value when no longer needed. + * + * Returns NULL on failure, the device address on success. + */ +virPCIDeviceAddressPtr +virPCIDeviceGetAddress(virPCIDevicePtr dev) +{ + + virPCIDeviceAddressPtr pciAddrPtr; + + if (!dev || (VIR_ALLOC(pciAddrPtr) < 0)) + return NULL; + + pciAddrPtr->domain = dev->domain; + pciAddrPtr->bus = dev->bus; + pciAddrPtr->slot = dev->slot; + pciAddrPtr->function = dev->function; + + return pciAddrPtr; +} + const char * virPCIDeviceGetName(virPCIDevicePtr dev) { diff --git a/src/util/virpci.h b/src/util/virpci.h index 1ce9821e00..64b9e96040 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -94,6 +94,7 @@ int virPCIDeviceSetStubDriver(virPCIDevicePtr dev, const char *driver) ATTRIBUTE_NONNULL(2); const char *virPCIDeviceGetStubDriver(virPCIDevicePtr dev); +virPCIDeviceAddressPtr virPCIDeviceGetAddress(virPCIDevicePtr dev); int virPCIDeviceSetUsedBy(virPCIDevice *dev, const char *drv_name, const char *dom_name);