[PATCH 050/103] qemuValidateDomainDeviceDef: Optimize virDomainDeviceInfo validation

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

 



Commit ffda44030a2 added validation of the 'acpiIndex' field in
virDomainDeviceInfo by calling 'virDomainDeviceInfoIterate' from
'qemuValidateDomainDef'. This is overly complicated we have
'qemuValidateDomainDeviceDef' which is already called for every single
device so we can avoid the extra loop.

Restructure the code by calling 'qemuValidateDomainDeviceInfo' directly
from 'qemuValidateDomainDeviceDef' and avoid unnecessary calls to
'virDomainDeviceGetInfo' by calling 'qemuValidateDomainDeviceDefAddress'
from 'qemuValidateDomainDeviceInfo'

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_validate.c | 79 ++++++++++++++++++----------------------
 1 file changed, 35 insertions(+), 44 deletions(-)

diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index e120f3385f..3f76adb586 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -997,33 +997,6 @@ qemuValidateDomainDefPanic(const virDomainDef *def,
 }


-static int
-qemuValidateDomainDeviceInfo(virDomainDef *def G_GNUC_UNUSED,
-                             virDomainDeviceDef *dev G_GNUC_UNUSED,
-                             virDomainDeviceInfo *info,
-                             void *opaque)
-{
-    virQEMUCaps *qemuCaps = opaque;
-
-    if (info->acpiIndex) {
-        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_ACPI_INDEX)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("ACPI index is not supported with this QEMU"));
-            return -1;
-        }
-
-        if (info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
-            info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("ACPI index is only supported for PCI devices"));
-            return -1;
-        }
-    }
-
-    return 0;
-}
-
-
 int
 qemuValidateLifecycleAction(virDomainLifecycleAction onPoweroff,
                             virDomainLifecycleAction onReboot,
@@ -1252,15 +1225,6 @@ qemuValidateDomainDef(const virDomainDef *def,
         return -1;
     }

-    /* Explicitly discarding 'const' from 'def' is ok because
-     * we know our callback qemuValidateDomainDeviceInfo will
-     * not modify it
-     */
-    if (virDomainDeviceInfoIterate((virDomainDef *)def,
-                                   qemuValidateDomainDeviceInfo,
-                                   qemuCaps) < 0)
-        return -1;
-
     return 0;
 }

@@ -1298,15 +1262,10 @@ qemuValidateDomainDeviceDefZPCIAddress(virDomainDeviceInfo *info,


 static int
-qemuValidateDomainDeviceDefAddress(const virDomainDeviceDef *dev,
+qemuValidateDomainDeviceDefAddress(virDomainDeviceInfo *info,
                                    const virDomainDef *def,
                                    virQEMUCaps *qemuCaps)
 {
-    virDomainDeviceInfo *info;
-
-    if (!(info = virDomainDeviceGetInfo(dev)))
-        return 0;
-
     switch ((virDomainDeviceAddressType) info->type) {
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
         if (qemuValidateDomainDeviceDefZPCIAddress(info, qemuCaps) < 0)
@@ -1375,6 +1334,38 @@ qemuValidateDomainDeviceDefAddress(const virDomainDeviceDef *dev,
 }


+static int
+qemuValidateDomainDeviceInfo(const virDomainDeviceDef *dev,
+                             const virDomainDef *def,
+                             virQEMUCaps *qemuCaps)
+{
+    virDomainDeviceInfo *info;
+
+    if (!(info = virDomainDeviceGetInfo(dev)))
+        return 0;
+
+    if (qemuValidateDomainDeviceDefAddress(info, def, qemuCaps) < 0)
+        return -1;
+
+    if (info->acpiIndex) {
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_ACPI_INDEX)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("ACPI index is not supported with this QEMU"));
+            return -1;
+        }
+
+        if (info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
+            info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("ACPI index is only supported for PCI devices"));
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
+
 static bool
 qemuValidateNetSupportsCoalesce(virDomainNetType type)
 {
@@ -5020,8 +5011,8 @@ qemuValidateDomainDeviceDef(const virDomainDeviceDef *dev,
         qemuCaps = qemuCapsLocal;
     }

-    if ((ret = qemuValidateDomainDeviceDefAddress(dev, def, qemuCaps)) < 0)
-        return ret;
+    if (qemuValidateDomainDeviceInfo(dev, def, qemuCaps) < 0)
+        return -1;

     switch ((virDomainDeviceType)dev->type) {
     case VIR_DOMAIN_DEVICE_NET:
-- 
2.31.1




[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]

  Powered by Linux