[PATCH 05/13] Move and rename qemuDomainValidateDevicePCISlotsPIIX3

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



qemuDomainValidateDevicePCISlotsPIIX3 is renamed to
virDomainValidateDevicePCISlotsPIIX3 and moved from qemu_domain_addr.c
to domain_addr.c

All these functions are being moved because they don't depend on
qemu, so they have the potential to be reused for more hypervisors.
---
 src/conf/domain_addr.c         | 133 ++++++++++++++++++++++++++++++++++++++++
 src/conf/domain_addr.h         |   6 ++
 src/libvirt_private.syms       |   1 +
 src/qemu/qemu_domain_address.c | 135 +----------------------------------------
 4 files changed, 141 insertions(+), 134 deletions(-)

diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index f3a75a0..17b60e4 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -1388,3 +1388,136 @@ virDomainMachineIsI440FX(const virDomainDef *def)
             STRPREFIX(def->os.machine, "pc-i440") ||
             STRPREFIX(def->os.machine, "rhel"));
 }
+
+
+int
+virDomainValidateDevicePCISlotsPIIX3(virDomainDefPtr def,
+                                      virDomainPCIAddressSetPtr addrs,
+                                      bool videoPrimaryEnabled)
+{
+    int ret = -1;
+    size_t i;
+    virPCIDeviceAddress tmp_addr;
+    char *addrStr = NULL;
+    virDomainPCIConnectFlags flags = (VIR_PCI_CONNECT_HOTPLUGGABLE
+                                      | VIR_PCI_CONNECT_TYPE_PCI_DEVICE);
+
+    /* Verify that first IDE and USB controllers (if any) is on the PIIX3, fn 1 */
+    for (i = 0; i < def->ncontrollers; i++) {
+        /* First IDE controller lives on the PIIX3 at slot=1, function=1 */
+        if (def->controllers[i]->type == VIR_DOMAIN_CONTROLLER_TYPE_IDE &&
+            def->controllers[i]->idx == 0) {
+            if (virDeviceInfoPCIAddressPresent(&def->controllers[i]->info)) {
+                if (def->controllers[i]->info.addr.pci.domain != 0 ||
+                    def->controllers[i]->info.addr.pci.bus != 0 ||
+                    def->controllers[i]->info.addr.pci.slot != 1 ||
+                    def->controllers[i]->info.addr.pci.function != 1) {
+                    virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                                   _("Primary IDE controller must have PCI address 0:0:1.1"));
+                    goto cleanup;
+                }
+            } else {
+                def->controllers[i]->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
+                def->controllers[i]->info.addr.pci.domain = 0;
+                def->controllers[i]->info.addr.pci.bus = 0;
+                def->controllers[i]->info.addr.pci.slot = 1;
+                def->controllers[i]->info.addr.pci.function = 1;
+            }
+        } else if (def->controllers[i]->type == VIR_DOMAIN_CONTROLLER_TYPE_USB &&
+                   def->controllers[i]->idx == 0 &&
+                   (def->controllers[i]->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_PIIX3_UHCI ||
+                    def->controllers[i]->model == -1)) {
+            if (virDeviceInfoPCIAddressPresent(&def->controllers[i]->info)) {
+                if (def->controllers[i]->info.addr.pci.domain != 0 ||
+                    def->controllers[i]->info.addr.pci.bus != 0 ||
+                    def->controllers[i]->info.addr.pci.slot != 1 ||
+                    def->controllers[i]->info.addr.pci.function != 2) {
+                    virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                                   _("PIIX3 USB controller must have PCI address 0:0:1.2"));
+                    goto cleanup;
+                }
+            } else {
+                def->controllers[i]->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
+                def->controllers[i]->info.addr.pci.domain = 0;
+                def->controllers[i]->info.addr.pci.bus = 0;
+                def->controllers[i]->info.addr.pci.slot = 1;
+                def->controllers[i]->info.addr.pci.function = 2;
+            }
+        }
+    }
+
+    /* PIIX3 (ISA bridge, IDE controller, something else unknown, USB controller)
+     * hardcoded slot=1, multifunction device
+     */
+    if (addrs->nbuses) {
+        memset(&tmp_addr, 0, sizeof(tmp_addr));
+        tmp_addr.slot = 1;
+        if (virDomainPCIAddressReserveSlot(addrs, &tmp_addr, flags) < 0)
+            goto cleanup;
+    }
+
+    if (def->nvideos > 0) {
+        /* Because the PIIX3 integrated IDE/USB controllers are
+         * already at slot 1, when qemu looks for the first free slot
+         * to place the VGA controller (which is always the first
+         * device added after integrated devices), it *always* ends up
+         * at slot 2.
+         */
+        virDomainVideoDefPtr primaryVideo = def->videos[0];
+        if (virDeviceInfoPCIAddressWanted(&primaryVideo->info)) {
+            memset(&tmp_addr, 0, sizeof(tmp_addr));
+            tmp_addr.slot = 2;
+
+            if (!(addrStr = virDomainPCIAddressAsString(&tmp_addr)))
+                goto cleanup;
+            if (!virDomainPCIAddressValidate(addrs, &tmp_addr,
+                                             addrStr, flags, false))
+                goto cleanup;
+
+            if (virDomainPCIAddressSlotInUse(addrs, &tmp_addr)) {
+                if (videoPrimaryEnabled) {
+                    if (virDomainPCIAddressReserveNextSlot(addrs,
+                                                           &primaryVideo->info,
+                                                           flags) < 0)
+                        goto cleanup;
+                } else {
+                    virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                                   _("PCI address 0:0:2.0 is in use, "
+                                     "QEMU needs it for primary video"));
+                    goto cleanup;
+                }
+            } else {
+                if (virDomainPCIAddressReserveSlot(addrs, &tmp_addr, flags) < 0)
+                    goto cleanup;
+                primaryVideo->info.addr.pci = tmp_addr;
+                primaryVideo->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
+            }
+        } else if (!videoPrimaryEnabled) {
+            if (primaryVideo->info.addr.pci.domain != 0 ||
+                primaryVideo->info.addr.pci.bus != 0 ||
+                primaryVideo->info.addr.pci.slot != 2 ||
+                primaryVideo->info.addr.pci.function != 0) {
+                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                               _("Primary video card must have PCI address 0:0:2.0"));
+                goto cleanup;
+            }
+            /* If TYPE == PCI, then virDomainCollectPCIAddress() function
+             * has already reserved the address, so we must skip */
+        }
+    } else if (addrs->nbuses && !videoPrimaryEnabled) {
+        memset(&tmp_addr, 0, sizeof(tmp_addr));
+        tmp_addr.slot = 2;
+
+        if (virDomainPCIAddressSlotInUse(addrs, &tmp_addr)) {
+            VIR_DEBUG("PCI address 0:0:2.0 in use, future addition of a video"
+                      " device will not be possible without manual"
+                      " intervention");
+        } else if (virDomainPCIAddressReserveSlot(addrs, &tmp_addr, flags) < 0) {
+            goto cleanup;
+        }
+    }
+    ret = 0;
+ cleanup:
+    VIR_FREE(addrStr);
+    return ret;
+}
diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h
index fb90ec9..0995e7b 100644
--- a/src/conf/domain_addr.h
+++ b/src/conf/domain_addr.h
@@ -244,6 +244,12 @@ virDomainMachineIsQ35(const virDomainDef *def);
 bool
 virDomainMachineIsI440FX(const virDomainDef *def);
 
+int
+virDomainValidateDevicePCISlotsPIIX3(virDomainDefPtr def,
+                                      virDomainPCIAddressSetPtr addrs,
+                                      bool videoPrimaryEnabled)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+
 
 
 #endif /* __DOMAIN_ADDR_H__ */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 2697afa..c154a83 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -109,6 +109,7 @@ virDomainPCIAddressSetGrow;
 virDomainPCIAddressSlotInUse;
 virDomainPCIAddressValidate;
 virDomainPCIControllerModelToConnectType;
+virDomainValidateDevicePCISlotsPIIX3;
 virDomainVirtioSerialAddrAssign;
 virDomainVirtioSerialAddrAutoAssign;
 virDomainVirtioSerialAddrIsComplete;
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 02642f9..abf1a26 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -419,139 +419,6 @@ qemuDomainPCIAddressSetCreate(virDomainDefPtr def,
 
 
 static int
-qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefPtr def,
-                                      virDomainPCIAddressSetPtr addrs,
-                                      bool videoPrimaryEnabled)
-{
-    int ret = -1;
-    size_t i;
-    virPCIDeviceAddress tmp_addr;
-    char *addrStr = NULL;
-    virDomainPCIConnectFlags flags = (VIR_PCI_CONNECT_HOTPLUGGABLE
-                                      | VIR_PCI_CONNECT_TYPE_PCI_DEVICE);
-
-    /* Verify that first IDE and USB controllers (if any) is on the PIIX3, fn 1 */
-    for (i = 0; i < def->ncontrollers; i++) {
-        /* First IDE controller lives on the PIIX3 at slot=1, function=1 */
-        if (def->controllers[i]->type == VIR_DOMAIN_CONTROLLER_TYPE_IDE &&
-            def->controllers[i]->idx == 0) {
-            if (virDeviceInfoPCIAddressPresent(&def->controllers[i]->info)) {
-                if (def->controllers[i]->info.addr.pci.domain != 0 ||
-                    def->controllers[i]->info.addr.pci.bus != 0 ||
-                    def->controllers[i]->info.addr.pci.slot != 1 ||
-                    def->controllers[i]->info.addr.pci.function != 1) {
-                    virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                                   _("Primary IDE controller must have PCI address 0:0:1.1"));
-                    goto cleanup;
-                }
-            } else {
-                def->controllers[i]->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
-                def->controllers[i]->info.addr.pci.domain = 0;
-                def->controllers[i]->info.addr.pci.bus = 0;
-                def->controllers[i]->info.addr.pci.slot = 1;
-                def->controllers[i]->info.addr.pci.function = 1;
-            }
-        } else if (def->controllers[i]->type == VIR_DOMAIN_CONTROLLER_TYPE_USB &&
-                   def->controllers[i]->idx == 0 &&
-                   (def->controllers[i]->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_PIIX3_UHCI ||
-                    def->controllers[i]->model == -1)) {
-            if (virDeviceInfoPCIAddressPresent(&def->controllers[i]->info)) {
-                if (def->controllers[i]->info.addr.pci.domain != 0 ||
-                    def->controllers[i]->info.addr.pci.bus != 0 ||
-                    def->controllers[i]->info.addr.pci.slot != 1 ||
-                    def->controllers[i]->info.addr.pci.function != 2) {
-                    virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                                   _("PIIX3 USB controller must have PCI address 0:0:1.2"));
-                    goto cleanup;
-                }
-            } else {
-                def->controllers[i]->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
-                def->controllers[i]->info.addr.pci.domain = 0;
-                def->controllers[i]->info.addr.pci.bus = 0;
-                def->controllers[i]->info.addr.pci.slot = 1;
-                def->controllers[i]->info.addr.pci.function = 2;
-            }
-        }
-    }
-
-    /* PIIX3 (ISA bridge, IDE controller, something else unknown, USB controller)
-     * hardcoded slot=1, multifunction device
-     */
-    if (addrs->nbuses) {
-        memset(&tmp_addr, 0, sizeof(tmp_addr));
-        tmp_addr.slot = 1;
-        if (virDomainPCIAddressReserveSlot(addrs, &tmp_addr, flags) < 0)
-            goto cleanup;
-    }
-
-    if (def->nvideos > 0) {
-        /* Because the PIIX3 integrated IDE/USB controllers are
-         * already at slot 1, when qemu looks for the first free slot
-         * to place the VGA controller (which is always the first
-         * device added after integrated devices), it *always* ends up
-         * at slot 2.
-         */
-        virDomainVideoDefPtr primaryVideo = def->videos[0];
-        if (virDeviceInfoPCIAddressWanted(&primaryVideo->info)) {
-            memset(&tmp_addr, 0, sizeof(tmp_addr));
-            tmp_addr.slot = 2;
-
-            if (!(addrStr = virDomainPCIAddressAsString(&tmp_addr)))
-                goto cleanup;
-            if (!virDomainPCIAddressValidate(addrs, &tmp_addr,
-                                             addrStr, flags, false))
-                goto cleanup;
-
-            if (virDomainPCIAddressSlotInUse(addrs, &tmp_addr)) {
-                if (videoPrimaryEnabled) {
-                    if (virDomainPCIAddressReserveNextSlot(addrs,
-                                                           &primaryVideo->info,
-                                                           flags) < 0)
-                        goto cleanup;
-                } else {
-                    virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                                   _("PCI address 0:0:2.0 is in use, "
-                                     "QEMU needs it for primary video"));
-                    goto cleanup;
-                }
-            } else {
-                if (virDomainPCIAddressReserveSlot(addrs, &tmp_addr, flags) < 0)
-                    goto cleanup;
-                primaryVideo->info.addr.pci = tmp_addr;
-                primaryVideo->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
-            }
-        } else if (!videoPrimaryEnabled) {
-            if (primaryVideo->info.addr.pci.domain != 0 ||
-                primaryVideo->info.addr.pci.bus != 0 ||
-                primaryVideo->info.addr.pci.slot != 2 ||
-                primaryVideo->info.addr.pci.function != 0) {
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                               _("Primary video card must have PCI address 0:0:2.0"));
-                goto cleanup;
-            }
-            /* If TYPE == PCI, then virDomainCollectPCIAddress() function
-             * has already reserved the address, so we must skip */
-        }
-    } else if (addrs->nbuses && !videoPrimaryEnabled) {
-        memset(&tmp_addr, 0, sizeof(tmp_addr));
-        tmp_addr.slot = 2;
-
-        if (virDomainPCIAddressSlotInUse(addrs, &tmp_addr)) {
-            VIR_DEBUG("PCI address 0:0:2.0 in use, future addition of a video"
-                      " device will not be possible without manual"
-                      " intervention");
-        } else if (virDomainPCIAddressReserveSlot(addrs, &tmp_addr, flags) < 0) {
-            goto cleanup;
-        }
-    }
-    ret = 0;
- cleanup:
-    VIR_FREE(addrStr);
-    return ret;
-}
-
-
-static int
 qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr def,
                                     virDomainPCIAddressSetPtr addrs,
                                     bool videoPrimaryEnabled)
@@ -748,7 +615,7 @@ qemuDomainValidateDevicePCISlotsChipsets(virDomainDefPtr def,
                                          bool videoPrimaryEnabled)
 {
     if (virDomainMachineIsI440FX(def) &&
-        qemuDomainValidateDevicePCISlotsPIIX3(def, addrs, videoPrimaryEnabled) < 0) {
+        virDomainValidateDevicePCISlotsPIIX3(def, addrs, videoPrimaryEnabled) < 0) {
         return -1;
     }
 
-- 
2.7.4 (Apple Git-66)

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]