[libvirt] [PATCH 2/6] conf: new functions to check if PCI address is wanted/present

Laine Stump laine at laine.org
Wed May 18 19:23:50 UTC 2016

In order to allow <address type='pci'/> with no other attributes to
mean "I want a PCI address, but any PCI address will do" (just as
having no <address> at all usually indicates), we will need to change
several places in the code from a simple "info->type == (or !=)
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_(PCI|NONE)" into something slightly
more complex, this patch adds to new functions that take a
virDomainDeviceInfoPtr and return true/false depending on 1) whether
the current state of the info indicates that we "want" a PCI address
for this device (virDeviceInfoPCIAddressWanted()) and 2) whether this
device already has a valid PCI address

Both of these functions required the simpler check for whether a pci
address is "empty" (i.e. all of its attributes are 0, which can never
happen in a real PCI address, since slot 0 of bus 0 of domain 0 is
always reserved), so that function is also added.
 src/conf/device_conf.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
index 46c720d..847564b 100644
--- a/src/conf/device_conf.h
+++ b/src/conf/device_conf.h
@@ -184,6 +184,27 @@ typedef struct _virDomainDeviceInfo {
 int virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr,
                                bool report);
+static inline bool
+virPCIDeviceAddressIsEmpty(const virPCIDeviceAddress *addr)
+    return !(addr->domain || addr->bus || addr->slot);
+static inline bool
+virDeviceInfoPCIAddressWanted(const virDomainDeviceInfo *info)
+    return info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE ||
+        (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI &&
+         virPCIDeviceAddressIsEmpty(&info->addr.pci));
+static inline bool
+virDeviceInfoPCIAddressPresent(const virDomainDeviceInfo *info)
+    return info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI &&
+       !virPCIDeviceAddressIsEmpty(&info->addr.pci);
 int virPCIDeviceAddressParseXML(xmlNodePtr node,
                                 virPCIDeviceAddressPtr addr);

More information about the libvir-list mailing list