]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Introduce qemuDomainDefMachinePostParse()
authorAndrea Bolognani <abologna@redhat.com>
Fri, 20 Jan 2023 16:04:28 +0000 (17:04 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Fri, 3 Mar 2023 12:40:57 +0000 (13:40 +0100)
Move all the machine type related parts of
qemuDomainDefPostParse() to a separate helper.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_domain.c

index a083e7e1efd1bec6740d095abf32a270e99a0477..6f6fb282bee3f7e28b1ebe210025df13f15259de 100644 (file)
@@ -4425,6 +4425,31 @@ qemuDomainRecheckInternalPaths(virDomainDef *def,
 }
 
 
+static int
+qemuDomainDefMachinePostParse(virDomainDef *def,
+                              virQEMUCaps *qemuCaps)
+{
+    if (!def->os.machine) {
+        const char *machine = virQEMUCapsGetPreferredMachine(qemuCaps,
+                                                             def->virtType);
+        if (!machine) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("could not get preferred machine for %s type=%s"),
+                           def->emulator,
+                           virDomainVirtTypeToString(def->virtType));
+            return -1;
+        }
+
+        def->os.machine = g_strdup(machine);
+    }
+
+    if (qemuCanonicalizeMachine(def, qemuCaps) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 static int
 qemuDomainDefVcpusPostParse(virDomainDef *def)
 {
@@ -4767,26 +4792,15 @@ qemuDomainDefPostParse(virDomainDef *def,
     if (!qemuCaps)
         return 1;
 
+    if (qemuDomainDefMachinePostParse(def, qemuCaps) < 0)
+        return -1;
+
     if (def->os.bootloader || def->os.bootloaderArgs) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("bootloader is not supported by QEMU"));
         return -1;
     }
 
-    if (!def->os.machine) {
-        const char *machine = virQEMUCapsGetPreferredMachine(qemuCaps,
-                                                             def->virtType);
-        if (!machine) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("could not get preferred machine for %s type=%s"),
-                           def->emulator,
-                           virDomainVirtTypeToString(def->virtType));
-            return -1;
-        }
-
-        def->os.machine = g_strdup(machine);
-    }
-
     if (virDomainDefHasOldStyleROUEFI(def) &&
         !def->os.loader->nvram &&
         def->os.loader->stateless != VIR_TRISTATE_BOOL_YES) {
@@ -4799,9 +4813,6 @@ qemuDomainDefPostParse(virDomainDef *def,
     if (qemuDomainDefAddDefaultDevices(driver, def, qemuCaps) < 0)
         return -1;
 
-    if (qemuCanonicalizeMachine(def, qemuCaps) < 0)
-        return -1;
-
     if (qemuDomainDefSetDefaultCPU(def, driver->hostarch, qemuCaps) < 0)
         return -1;