mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
qemu_process: move checks to qemuProcessStartValidate
Move all code that checks host and domain. Do not check host if we use VIR_QEMU_PROCESS_START_PRETEND flag. Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
a431d3440f
commit
1e38ef728c
@ -6984,7 +6984,9 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
|
|||||||
VIR_DOMAIN_DEF_PARSE_ABI_UPDATE)))
|
VIR_DOMAIN_DEF_PARSE_ABI_UPDATE)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuProcessStartValidate(vm->def, qemuCaps, false, false) < 0)
|
if (qemuProcessStartValidate(driver, vm, qemuCaps, false, false,
|
||||||
|
VIR_QEMU_PROCESS_START_COLD |
|
||||||
|
VIR_QEMU_PROCESS_START_PRETEND) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* Generate per-domain paths because we don't have the domain object */
|
/* Generate per-domain paths because we don't have the domain object */
|
||||||
|
@ -3580,7 +3580,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (qemuProcessInit(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
|
if (qemuProcessInit(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
|
||||||
true, false) < 0)
|
true, false, VIR_QEMU_PROCESS_START_AUTODESTROY) < 0)
|
||||||
goto stopjob;
|
goto stopjob;
|
||||||
stopProcess = true;
|
stopProcess = true;
|
||||||
|
|
||||||
|
@ -4372,22 +4372,104 @@ qemuProcessMakeDir(virQEMUDriverPtr driver,
|
|||||||
* @qemuCaps: emulator capabilities
|
* @qemuCaps: emulator capabilities
|
||||||
* @migration: restoration of existing state
|
* @migration: restoration of existing state
|
||||||
*
|
*
|
||||||
* This function aggregates checks independent from host state done prior to
|
* This function aggregates checks done prior to start of a VM.
|
||||||
* start of a VM.
|
*
|
||||||
|
* Flag VIR_QEMU_PROCESS_START_PRETEND tells, that we don't want to actually
|
||||||
|
* start the domain but create a valid qemu command. If some code shouldn't be
|
||||||
|
* executed in this case, make sure to check this flag.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
qemuProcessStartValidate(virDomainDefPtr def,
|
qemuProcessStartValidate(virQEMUDriverPtr driver,
|
||||||
|
virDomainObjPtr vm,
|
||||||
virQEMUCapsPtr qemuCaps,
|
virQEMUCapsPtr qemuCaps,
|
||||||
bool migration,
|
bool migration,
|
||||||
bool snapshot)
|
bool snapshot,
|
||||||
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
if (qemuValidateCpuCount(def, qemuCaps) < 0)
|
bool check_shmem = false;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (!(flags & VIR_QEMU_PROCESS_START_PRETEND)) {
|
||||||
|
if (vm->def->virtType == VIR_DOMAIN_VIRT_KVM) {
|
||||||
|
VIR_DEBUG("Checking for KVM availability");
|
||||||
|
if (!virFileExists("/dev/kvm")) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
|
_("Domain requires KVM, but it is not available. "
|
||||||
|
"Check that virtualization is enabled in the "
|
||||||
|
"host BIOS, and host configuration is setup to "
|
||||||
|
"load the kvm modules."));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qemuDomainCheckDiskPresence(driver, vm,
|
||||||
|
flags & VIR_QEMU_PROCESS_START_COLD) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
VIR_DEBUG("Checking domain and device security labels");
|
||||||
|
if (virSecurityManagerCheckAllLabel(driver->securityManager, vm->def) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qemuValidateCpuCount(vm->def, qemuCaps) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!migration && !snapshot &&
|
if (!migration && !snapshot &&
|
||||||
virDomainDefCheckDuplicateDiskInfo(def) < 0)
|
virDomainDefCheckDuplicateDiskInfo(vm->def) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (vm->def->mem.min_guarantee) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
|
_("Parameter 'min_guarantee' "
|
||||||
|
"not supported by QEMU."));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
VIR_DEBUG("Checking for any possible (non-fatal) issues");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For vhost-user to work, the domain has to have some type of
|
||||||
|
* shared memory configured. We're not the proper ones to judge
|
||||||
|
* whether shared hugepages or shm are enough and will be in the
|
||||||
|
* future, so we'll just warn in case neither is configured.
|
||||||
|
* Moreover failing would give the false illusion that libvirt is
|
||||||
|
* really checking that everything works before running the domain
|
||||||
|
* and not only we are unable to do that, but it's also not our
|
||||||
|
* aim to do so.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < vm->def->nnets; i++) {
|
||||||
|
if (virDomainNetGetActualType(vm->def->nets[i]) ==
|
||||||
|
VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
|
||||||
|
check_shmem = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (check_shmem) {
|
||||||
|
bool shmem = vm->def->nshmems;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This check is by no means complete. We merely check
|
||||||
|
* whether there are *some* hugepages enabled and *some* NUMA
|
||||||
|
* nodes with shared memory access.
|
||||||
|
*/
|
||||||
|
if (!shmem && vm->def->mem.nhugepages) {
|
||||||
|
for (i = 0; i < virDomainNumaGetNodeCount(vm->def->numa); i++) {
|
||||||
|
if (virDomainNumaGetNodeMemoryAccessMode(vm->def->numa, i) ==
|
||||||
|
VIR_NUMA_MEM_ACCESS_SHARED) {
|
||||||
|
shmem = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shmem) {
|
||||||
|
VIR_WARN("Detected vhost-user interface without any shared memory, "
|
||||||
|
"the interface might not be operational");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4405,7 +4487,8 @@ qemuProcessInit(virQEMUDriverPtr driver,
|
|||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
qemuDomainAsyncJob asyncJob,
|
qemuDomainAsyncJob asyncJob,
|
||||||
bool migration,
|
bool migration,
|
||||||
bool snap)
|
bool snap,
|
||||||
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||||
virCapsPtr caps = NULL;
|
virCapsPtr caps = NULL;
|
||||||
@ -4434,7 +4517,8 @@ qemuProcessInit(virQEMUDriverPtr driver,
|
|||||||
vm->def->os.machine)))
|
vm->def->os.machine)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuProcessStartValidate(vm->def, priv->qemuCaps, migration, snap) < 0)
|
if (qemuProcessStartValidate(driver, vm, priv->qemuCaps,
|
||||||
|
migration, snap, flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* Do this upfront, so any part of the startup process can add
|
/* Do this upfront, so any part of the startup process can add
|
||||||
@ -5025,12 +5109,10 @@ qemuProcessLaunch(virConnectPtr conn,
|
|||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
virCommandPtr cmd = NULL;
|
virCommandPtr cmd = NULL;
|
||||||
struct qemuProcessHookData hookData;
|
struct qemuProcessHookData hookData;
|
||||||
size_t i;
|
|
||||||
virQEMUDriverConfigPtr cfg;
|
virQEMUDriverConfigPtr cfg;
|
||||||
virCapsPtr caps = NULL;
|
virCapsPtr caps = NULL;
|
||||||
size_t nnicindexes = 0;
|
size_t nnicindexes = 0;
|
||||||
int *nicindexes = NULL;
|
int *nicindexes = NULL;
|
||||||
bool check_shmem = false;
|
|
||||||
|
|
||||||
VIR_DEBUG("vm=%p name=%s id=%d asyncJob=%d "
|
VIR_DEBUG("vm=%p name=%s id=%d asyncJob=%d "
|
||||||
"incoming.launchURI=%s incoming.deferredURI=%s "
|
"incoming.launchURI=%s incoming.deferredURI=%s "
|
||||||
@ -5060,38 +5142,12 @@ qemuProcessLaunch(virConnectPtr conn,
|
|||||||
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
|
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
VIR_DEBUG("Checking domain and device security labels");
|
|
||||||
if (virSecurityManagerCheckAllLabel(driver->securityManager, vm->def) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
VIR_DEBUG("Creating domain log file");
|
VIR_DEBUG("Creating domain log file");
|
||||||
if (!(logCtxt = qemuDomainLogContextNew(driver, vm,
|
if (!(logCtxt = qemuDomainLogContextNew(driver, vm,
|
||||||
QEMU_DOMAIN_LOG_CONTEXT_MODE_START)))
|
QEMU_DOMAIN_LOG_CONTEXT_MODE_START)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
logfile = qemuDomainLogContextGetWriteFD(logCtxt);
|
logfile = qemuDomainLogContextGetWriteFD(logCtxt);
|
||||||
|
|
||||||
if (vm->def->virtType == VIR_DOMAIN_VIRT_KVM) {
|
|
||||||
VIR_DEBUG("Checking for KVM availability");
|
|
||||||
if (!virFileExists("/dev/kvm")) {
|
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
||||||
_("Domain requires KVM, but it is not available. "
|
|
||||||
"Check that virtualization is enabled in the host BIOS, "
|
|
||||||
"and host configuration is setup to load the kvm modules."));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qemuDomainCheckDiskPresence(driver, vm,
|
|
||||||
flags & VIR_QEMU_PROCESS_START_COLD) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (vm->def->mem.min_guarantee) {
|
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
||||||
_("Parameter 'min_guarantee' "
|
|
||||||
"not supported by QEMU."));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qemuDomainSetPrivatePaths(&priv->libDir,
|
if (qemuDomainSetPrivatePaths(&priv->libDir,
|
||||||
&priv->channelTargetDir,
|
&priv->channelTargetDir,
|
||||||
cfg->libDir,
|
cfg->libDir,
|
||||||
@ -5100,50 +5156,6 @@ qemuProcessLaunch(virConnectPtr conn,
|
|||||||
vm->def->id) < 0)
|
vm->def->id) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
VIR_DEBUG("Checking for any possible (non-fatal) issues");
|
|
||||||
|
|
||||||
/*
|
|
||||||
* For vhost-user to work, the domain has to have some type of
|
|
||||||
* shared memory configured. We're not the proper ones to judge
|
|
||||||
* whether shared hugepages or shm are enough and will be in the
|
|
||||||
* future, so we'll just warn in case neither is configured.
|
|
||||||
* Moreover failing would give the false illusion that libvirt is
|
|
||||||
* really checking that everything works before running the domain
|
|
||||||
* and not only we are unable to do that, but it's also not our
|
|
||||||
* aim to do so.
|
|
||||||
*/
|
|
||||||
for (i = 0; i < vm->def->nnets; i++) {
|
|
||||||
if (virDomainNetGetActualType(vm->def->nets[i]) ==
|
|
||||||
VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
|
|
||||||
check_shmem = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (check_shmem) {
|
|
||||||
bool shmem = vm->def->nshmems;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This check is by no means complete. We merely check
|
|
||||||
* whether there are *some* hugepages enabled and *some* NUMA
|
|
||||||
* nodes with shared memory access.
|
|
||||||
*/
|
|
||||||
if (!shmem && vm->def->mem.nhugepages) {
|
|
||||||
for (i = 0; i < virDomainNumaGetNodeCount(vm->def->numa); i++) {
|
|
||||||
if (virDomainNumaGetNodeMemoryAccessMode(vm->def->numa, i) ==
|
|
||||||
VIR_NUMA_MEM_ACCESS_SHARED) {
|
|
||||||
shmem = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!shmem) {
|
|
||||||
VIR_WARN("Detected vhost-user interface without any shared memory, "
|
|
||||||
"the interface might not be operational");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VIR_DEBUG("Building emulator command line");
|
VIR_DEBUG("Building emulator command line");
|
||||||
if (!(cmd = qemuBuildCommandLine(conn, driver,
|
if (!(cmd = qemuBuildCommandLine(conn, driver,
|
||||||
qemuDomainLogContextGetManager(logCtxt),
|
qemuDomainLogContextGetManager(logCtxt),
|
||||||
@ -5466,7 +5478,8 @@ qemuProcessStart(virConnectPtr conn,
|
|||||||
VIR_QEMU_PROCESS_START_PAUSED |
|
VIR_QEMU_PROCESS_START_PAUSED |
|
||||||
VIR_QEMU_PROCESS_START_AUTODESTROY, cleanup);
|
VIR_QEMU_PROCESS_START_AUTODESTROY, cleanup);
|
||||||
|
|
||||||
if (qemuProcessInit(driver, vm, asyncJob, !!migrateFrom, !!snapshot) < 0)
|
if (qemuProcessInit(driver, vm, asyncJob, !!migrateFrom,
|
||||||
|
!!snapshot, flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (migrateFrom) {
|
if (migrateFrom) {
|
||||||
|
@ -82,16 +82,19 @@ int qemuProcessStart(virConnectPtr conn,
|
|||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
|
|
||||||
|
|
||||||
int qemuProcessStartValidate(virDomainDefPtr def,
|
int qemuProcessStartValidate(virQEMUDriverPtr driver,
|
||||||
|
virDomainObjPtr vm,
|
||||||
virQEMUCapsPtr qemuCaps,
|
virQEMUCapsPtr qemuCaps,
|
||||||
bool migration,
|
bool migration,
|
||||||
bool snap);
|
bool snap,
|
||||||
|
unsigned int flags);
|
||||||
|
|
||||||
int qemuProcessInit(virQEMUDriverPtr driver,
|
int qemuProcessInit(virQEMUDriverPtr driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
qemuDomainAsyncJob asyncJob,
|
qemuDomainAsyncJob asyncJob,
|
||||||
bool migration,
|
bool migration,
|
||||||
bool snap);
|
bool snap,
|
||||||
|
unsigned int flags);
|
||||||
|
|
||||||
int qemuProcessPrepareDomain(virConnectPtr conn,
|
int qemuProcessPrepareDomain(virConnectPtr conn,
|
||||||
virQEMUDriverPtr driver,
|
virQEMUDriverPtr driver,
|
||||||
|
@ -350,7 +350,10 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemuProcessStartValidate(vm->def, extraFlags, !!migrateURI, false) < 0) {
|
if (qemuProcessStartValidate(&driver, vm, extraFlags,
|
||||||
|
!!migrateURI, false,
|
||||||
|
VIR_QEMU_PROCESS_START_COLD |
|
||||||
|
VIR_QEMU_PROCESS_START_PRETEND) < 0) {
|
||||||
if (flags & FLAG_EXPECT_FAILURE)
|
if (flags & FLAG_EXPECT_FAILURE)
|
||||||
goto ok;
|
goto ok;
|
||||||
goto out;
|
goto out;
|
||||||
|
Loading…
Reference in New Issue
Block a user