Move all the machine type related parts of qemuDomainDefPostParse() to a separate helper. Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx> --- src/qemu/qemu_domain.c | 45 ++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e9bc0f375d..9db5370055 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -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; -- 2.39.1