qemu: Handle CanonicalizeMachine in post parse

Rather than open coding calls. I can't see any reason not to
This commit is contained in:
Cole Robinson 2016-01-06 20:39:06 -05:00
parent 9cec6239c1
commit a8b628e7a8
2 changed files with 23 additions and 29 deletions

View File

@ -1207,6 +1207,26 @@ qemuDomainDefAddDefaultDevices(virDomainDefPtr def,
} }
static int
qemuCanonicalizeMachine(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
{
const char *canon;
if (!(canon = virQEMUCapsGetCanonicalMachine(qemuCaps, def->os.machine)))
return 0;
if (STRNEQ(canon, def->os.machine)) {
char *tmp;
if (VIR_STRDUP(tmp, canon) < 0)
return -1;
VIR_FREE(def->os.machine);
def->os.machine = tmp;
}
return 0;
}
static int static int
qemuDomainDefPostParse(virDomainDefPtr def, qemuDomainDefPostParse(virDomainDefPtr def,
virCapsPtr caps, virCapsPtr caps,
@ -1232,6 +1252,9 @@ qemuDomainDefPostParse(virDomainDefPtr def,
if (qemuDomainDefAddDefaultDevices(def, qemuCaps) < 0) if (qemuDomainDefAddDefaultDevices(def, qemuCaps) < 0)
goto cleanup; goto cleanup;
if (qemuCanonicalizeMachine(def, qemuCaps) < 0)
goto cleanup;
ret = 0; ret = 0;
cleanup: cleanup:
virObjectUnref(qemuCaps); virObjectUnref(qemuCaps);

View File

@ -1684,26 +1684,6 @@ static int qemuConnectNumOfDomains(virConnectPtr conn)
} }
static int
qemuCanonicalizeMachine(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
{
const char *canon;
if (!(canon = virQEMUCapsGetCanonicalMachine(qemuCaps, def->os.machine)))
return 0;
if (STRNEQ(canon, def->os.machine)) {
char *tmp;
if (VIR_STRDUP(tmp, canon) < 0)
return -1;
VIR_FREE(def->os.machine);
def->os.machine = tmp;
}
return 0;
}
static virDomainPtr qemuDomainCreateXML(virConnectPtr conn, static virDomainPtr qemuDomainCreateXML(virConnectPtr conn,
const char *xml, const char *xml,
unsigned int flags) unsigned int flags)
@ -1749,9 +1729,6 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn,
if (!(qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator))) if (!(qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator)))
goto cleanup; goto cleanup;
if (qemuCanonicalizeMachine(def, qemuCaps) < 0)
goto cleanup;
if (qemuDomainAssignAddresses(def, qemuCaps, NULL) < 0) if (qemuDomainAssignAddresses(def, qemuCaps, NULL) < 0)
goto cleanup; goto cleanup;
@ -7531,9 +7508,6 @@ static virDomainPtr qemuDomainDefineXMLFlags(virConnectPtr conn, const char *xml
if (!(qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator))) if (!(qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator)))
goto cleanup; goto cleanup;
if (qemuCanonicalizeMachine(def, qemuCaps) < 0)
goto cleanup;
if (qemuDomainAssignAddresses(def, qemuCaps, NULL) < 0) if (qemuDomainAssignAddresses(def, qemuCaps, NULL) < 0)
goto cleanup; goto cleanup;
@ -15893,9 +15867,6 @@ static virDomainPtr qemuDomainQemuAttach(virConnectPtr conn,
if (!(qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator))) if (!(qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator)))
goto cleanup; goto cleanup;
if (qemuCanonicalizeMachine(def, qemuCaps) < 0)
goto cleanup;
if (qemuAssignDeviceAliases(def, qemuCaps) < 0) if (qemuAssignDeviceAliases(def, qemuCaps) < 0)
goto cleanup; goto cleanup;