[libvirt] [PATCH v2 02/15] qemu: Introduce qemuDomainDeviceDefSkipController

John Ferlan jferlan at redhat.com
Wed Dec 6 15:27:34 UTC 2017


In order to be able to reuse some code for both controller def
validation and command line building, create a convenience helper
that will skip the same devices for validation that are being
skipped for command line building. This is in preference to copying
the individual checks in subsequent patches which split out the
various command line validation checks into a domain definition
validation check.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/qemu/qemu_command.c | 32 ++++++--------------------------
 src/qemu/qemu_domain.c  | 43 ++++++++++++++++++++++++++++++++++++++++++-
 src/qemu/qemu_domain.h  |  4 ++++
 3 files changed, 52 insertions(+), 27 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 6a8da1d58..d7696fb93 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3216,6 +3216,9 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd,
             if (cont->type != contOrder[j])
                 continue;
 
+            if (qemuDomainDeviceDefSkipController(cont, def))
+                continue;
+
             /* skip USB controllers with type none.*/
             if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_USB &&
                 cont->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE) {
@@ -3223,30 +3226,6 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd,
                 continue;
             }
 
-            /* skip pcie-root */
-            if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI &&
-                cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT) {
-                continue;
-            }
-
-            /* Skip pci-root, except for pSeries guests (which actually
-             * support more than one PCI Host Bridge per guest) */
-            if (!qemuDomainIsPSeries(def) &&
-                cont->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI &&
-                cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT) {
-                continue;
-            }
-
-            /* first SATA controller on Q35 machines is implicit */
-            if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_SATA &&
-                cont->idx == 0 && qemuDomainIsQ35(def))
-                    continue;
-
-            /* first IDE controller is implicit on various machines */
-            if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_IDE &&
-                cont->idx == 0 && qemuDomainHasBuiltinIDE(def))
-                    continue;
-
             if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_USB &&
                 cont->model == -1 &&
                 !qemuDomainIsQ35(def) &&
@@ -3268,11 +3247,12 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd,
                     virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                                    _("Multiple legacy USB controllers are "
                                      "not supported"));
-                    goto cleanup;
+                     goto cleanup;
                 }
                 usblegacy = true;
                 continue;
-            }
+             }
+
 
             if (qemuBuildControllerDevStr(def, cont, qemuCaps,
                                           &devstr, &usbcontroller) < 0)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 19e86797e..e4452c419 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -3892,10 +3892,51 @@ qemuDomainDeviceDefValidateDisk(const virDomainDiskDef *disk)
 }
 
 
+/**
+ * qemuDomainDeviceDefSkipController:
+ * @controller: Controller to check
+ * @def: Domain definition
+ *
+ * Returns true if this controller can be skipped for command line
+ * generation or device validation.
+ */
+bool
+qemuDomainDeviceDefSkipController(const virDomainControllerDef *controller,
+                                  const virDomainDef *def)
+{
+    /* skip pcie-root */
+    if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI &&
+        controller->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT)
+        return true;
+
+    /* Skip pci-root, except for pSeries guests (which actually
+     * support more than one PCI Host Bridge per guest) */
+    if (!qemuDomainIsPSeries(def) &&
+        controller->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI &&
+        controller->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT)
+        return true;
+
+    /* first SATA controller on Q35 machines is implicit */
+    if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_SATA &&
+        controller->idx == 0 && qemuDomainIsQ35(def))
+        return true;
+
+    /* first IDE controller is implicit on various machines */
+    if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_IDE &&
+        controller->idx == 0 && qemuDomainHasBuiltinIDE(def))
+        return true;
+
+    return false;
+}
+
+
 static int
 qemuDomainDeviceDefValidateController(const virDomainControllerDef *controller,
-                                      const virDomainDef *def ATTRIBUTE_UNUSED)
+                                      const virDomainDef *def)
 {
+    if (qemuDomainDeviceDefSkipController(controller, def))
+        return 0;
+
     switch ((virDomainControllerType) controller->type) {
     case VIR_DOMAIN_CONTROLLER_TYPE_IDE:
     case VIR_DOMAIN_CONTROLLER_TYPE_FDC:
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index ba807ca0b..b1292a1f0 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -1000,4 +1000,8 @@ qemuDomainPrepareDiskSource(virConnectPtr conn,
                             qemuDomainObjPrivatePtr priv,
                             virQEMUDriverConfigPtr cfg);
 
+bool
+qemuDomainDeviceDefSkipController(const virDomainControllerDef *controller,
+                                  const virDomainDef *def);
+
 #endif /* __QEMU_DOMAIN_H__ */
-- 
2.13.6




More information about the libvir-list mailing list