qemu: process: Extract pre-start checks into a function

When starting a qemu process there are certain checks done to ensure
that the configuration makes sense. Extract them into a separate
function so that they can be reused in the test code.
This commit is contained in:
Peter Krempa 2016-02-04 15:25:29 +01:00
parent c3e170647e
commit c07bc2cc7d
3 changed files with 41 additions and 11 deletions

View File

@ -3462,7 +3462,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
goto stopjob;
}
if (qemuProcessInit(driver, vm, true) < 0)
if (qemuProcessInit(driver, vm, true, false) < 0)
goto stopjob;
stopProcess = true;

View File

@ -4401,6 +4401,32 @@ qemuProcessMakeDir(virQEMUDriverPtr driver,
}
/**
* qemuProcessStartValidate:
* @vm: domain object
* @qemuCaps: emulator capabilities
* @migration: restoration of existing state
*
* This function aggregates checks independent from host state done prior to
* start of a VM.
*/
int
qemuProcessStartValidate(virDomainDefPtr def,
virQEMUCapsPtr qemuCaps,
bool migration,
bool snapshot)
{
if (qemuValidateCpuCount(def, qemuCaps) < 0)
return -1;
if (!migration && !snapshot &&
virDomainDefCheckDuplicateDiskInfo(def) < 0)
return -1;
return 0;
}
/**
* qemuProcessInit:
*
@ -4412,7 +4438,8 @@ qemuProcessMakeDir(virQEMUDriverPtr driver,
int
qemuProcessInit(virQEMUDriverPtr driver,
virDomainObjPtr vm,
bool migration)
bool migration,
bool snap)
{
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
virCapsPtr caps = NULL;
@ -4441,6 +4468,9 @@ qemuProcessInit(virQEMUDriverPtr driver,
vm->def->os.machine)))
goto cleanup;
if (qemuProcessStartValidate(vm->def, priv->qemuCaps, migration, snap) < 0)
goto cleanup;
/* Some things, paths, ... are generated here and we want them to persist.
* Fill them in prior to setting the domain def as transient. */
VIR_DEBUG("Generating paths");
@ -4641,9 +4671,6 @@ qemuProcessLaunch(virConnectPtr conn,
}
}
if (qemuValidateCpuCount(vm->def, priv->qemuCaps) < 0)
goto cleanup;
if (qemuAssignDeviceAliases(vm->def, priv->qemuCaps) < 0)
goto cleanup;
@ -4667,10 +4694,6 @@ qemuProcessLaunch(virConnectPtr conn,
goto cleanup;
}
if (!incoming && !snapshot &&
virDomainDefCheckDuplicateDiskInfo(vm->def) < 0)
goto cleanup;
/* "volume" type disk's source must be translated before
* cgroup and security setting.
*/
@ -5113,7 +5136,7 @@ qemuProcessStart(virConnectPtr conn,
VIR_QEMU_PROCESS_START_PAUSED |
VIR_QEMU_PROCESS_START_AUTODESTROY, cleanup);
if (qemuProcessInit(driver, vm, !!migrateFrom) < 0)
if (qemuProcessInit(driver, vm, !!migrateFrom, !!snapshot) < 0)
goto cleanup;
if (migrateFrom) {

View File

@ -81,9 +81,16 @@ int qemuProcessStart(virConnectPtr conn,
virNetDevVPortProfileOp vmop,
unsigned int flags);
int qemuProcessStartValidate(virDomainDefPtr def,
virQEMUCapsPtr qemuCaps,
bool migration,
bool snap);
int qemuProcessInit(virQEMUDriverPtr driver,
virDomainObjPtr vm,
bool migration);
bool migration,
bool snap);
int qemuProcessLaunch(virConnectPtr conn,
virQEMUDriverPtr driver,