]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: new function virDomainPCIAddressReserveNextAddr()
authorLaine Stump <laine@laine.org>
Thu, 1 Sep 2016 13:29:01 +0000 (09:29 -0400)
committerLaine Stump <laine@laine.org>
Mon, 24 Oct 2016 17:53:24 +0000 (13:53 -0400)
There is an existing virDomainPCIAddressReserveNextSlot() which will
reserve all functions of the next available PCI slot. One place in the
qemu PCI address assignment code requires reserving a *single*
function of the next available PCI slot. This patch modifies and
renames virDomainPCIAddressReserveNextSlot() so that it can fulfill
both the original purpose and the need to reserve a single function.

(This is being done so that the abovementioned code in qemu can have
its "kind of open coded" solution replaced with a call to this new
function).

src/conf/domain_addr.c
src/conf/domain_addr.h
src/libvirt_private.syms

index 1e96fe9730c2cf058e8c2fbacac59839aaa84083..ebbfab6f405400ec89cad146f584d8853b8687cc 100644 (file)
@@ -693,29 +693,63 @@ virDomainPCIAddressGetNextSlot(virDomainPCIAddressSetPtr addrs,
     return 0;
 }
 
+
+/**
+ * virDomainPCIAddressReserveNextAddr:
+ *
+ * @addrs: a set of PCI addresses.
+ * @dev: virDomainDeviceInfo that should get the new address.
+ * @flags: CONNECT_TYPE flags for the device that needs an address.
+ * @function: which function on the slot to mark as reserved
+ *            (if @reserveEntireSlot is false)
+ * @reserveEntireSlot: true to reserve all functions on the new slot,
+ *                     false to reserve just @function
+ *
+ * Find the next *completely unreserved* slot with compatible
+ * connection @flags, mark either one function or the entire
+ * slot as in-use (according to @function and @reserveEntireSlot),
+ * and set @dev->addr.pci with this newly reserved address.
+ *
+ * returns 0 on success, or -1 on failure.
+ */
 int
-virDomainPCIAddressReserveNextSlot(virDomainPCIAddressSetPtr addrs,
+virDomainPCIAddressReserveNextAddr(virDomainPCIAddressSetPtr addrs,
                                    virDomainDeviceInfoPtr dev,
-                                   virDomainPCIConnectFlags flags)
+                                   virDomainPCIConnectFlags flags,
+                                   unsigned int function,
+                                   bool reserveEntireSlot)
 {
     virPCIDeviceAddress addr;
+
     if (virDomainPCIAddressGetNextSlot(addrs, &addr, flags) < 0)
         return -1;
 
-    if (virDomainPCIAddressReserveSlot(addrs, &addr, flags) < 0)
+    addr.function = reserveEntireSlot ? 0 : function;
+
+    if (virDomainPCIAddressReserveAddr(addrs, &addr, flags, reserveEntireSlot, false) < 0)
         return -1;
 
+    addrs->lastaddr = addr;
+    addrs->lastFlags = flags;
+
     if (!addrs->dryRun) {
         dev->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
         dev->addr.pci = addr;
     }
 
-    addrs->lastaddr = addr;
-    addrs->lastFlags = flags;
     return 0;
 }
 
 
+int
+virDomainPCIAddressReserveNextSlot(virDomainPCIAddressSetPtr addrs,
+                                   virDomainDeviceInfoPtr dev,
+                                   virDomainPCIConnectFlags flags)
+{
+    return virDomainPCIAddressReserveNextAddr(addrs, dev, flags, 0, true);
+}
+
+
 static char*
 virDomainCCWAddressAsString(virDomainDeviceCCWAddressPtr addr)
 {
index 0072a08303fe6fd57f5ae2aa5ecd976c5e94aa96..904d0601194757d375aa1b684794ac36196996cd 100644 (file)
@@ -160,6 +160,13 @@ int virDomainPCIAddressGetNextSlot(virDomainPCIAddressSetPtr addrs,
                                    virDomainPCIConnectFlags flags)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
+int virDomainPCIAddressReserveNextAddr(virDomainPCIAddressSetPtr addrs,
+                                       virDomainDeviceInfoPtr dev,
+                                       virDomainPCIConnectFlags flags,
+                                       unsigned int function,
+                                       bool reserveEntireSlot)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+
 int virDomainPCIAddressReserveNextSlot(virDomainPCIAddressSetPtr addrs,
                                        virDomainDeviceInfoPtr dev,
                                        virDomainPCIConnectFlags flags)
index bf503a58cce9c521f3784906c4ea45f0025aaeb9..a7d268ac60c2451135f17fc9e231c1f90ab54542 100644 (file)
@@ -102,6 +102,7 @@ virDomainPCIAddressFlagsCompatible;
 virDomainPCIAddressGetNextSlot;
 virDomainPCIAddressReleaseSlot;
 virDomainPCIAddressReserveAddr;
+virDomainPCIAddressReserveNextAddr;
 virDomainPCIAddressReserveNextSlot;
 virDomainPCIAddressReserveSlot;
 virDomainPCIAddressSetAlloc;