qemu: Introduce qemuDomainDefMachinePostParse()

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>
This commit is contained in:
Andrea Bolognani 2023-01-20 17:04:28 +01:00
parent 6f1c6534a8
commit 7e12610387

View 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;