Host preparation steps which are deliberately skipped when pretend-creating a commandline are normally executed after VM object preparation. In the test code we are faking some of the host preparation steps, but we were doing that prior to the call to qemuProcessPrepareDomain embedded in qemuProcessCreatePretendCmd. By splitting up qemuProcessCreatePretendCmd into two functions we can ensure that the ordering of the prepare steps stays consistent. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_driver.c | 9 ++++++--- src/qemu/qemu_process.c | 42 +++++++++++++++++++++++++--------------- src/qemu/qemu_process.h | 19 +++++++++++------- tests/qemuxml2argvtest.c | 11 +++++++---- 4 files changed, 51 insertions(+), 30 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 825bdd9119..f07a27d525 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6451,9 +6451,12 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, vm->def->nets[i] = newNet; } - if (!(cmd = qemuProcessCreatePretendCmd(driver, vm, NULL, - qemuCheckFips(), true, false, - VIR_QEMU_PROCESS_START_COLD))) + if (qemuProcessCreatePretendCmdPrepare(driver, vm, NULL, true, + VIR_QEMU_PROCESS_START_COLD) < 0) + goto cleanup; + + if (!(cmd = qemuProcessCreatePretendCmdBuild(driver, vm, NULL, + qemuCheckFips(), true, false))) goto cleanup; ret = virCommandToString(cmd, false); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 5bc76a75e3..85943594fa 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7267,35 +7267,45 @@ qemuProcessStart(virConnectPtr conn, } -virCommandPtr -qemuProcessCreatePretendCmd(virQEMUDriverPtr driver, - virDomainObjPtr vm, - const char *migrateURI, - bool enableFips, - bool standalone, - bool jsonPropsValidation, - unsigned int flags) +int +qemuProcessCreatePretendCmdPrepare(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *migrateURI, + bool standalone, + unsigned int flags) { - unsigned int buildflags = 0; - virCheckFlags(VIR_QEMU_PROCESS_START_COLD | VIR_QEMU_PROCESS_START_PAUSED | - VIR_QEMU_PROCESS_START_AUTODESTROY, NULL); + VIR_QEMU_PROCESS_START_AUTODESTROY, -1); flags |= VIR_QEMU_PROCESS_START_PRETEND; flags |= VIR_QEMU_PROCESS_START_NEW; if (standalone) flags |= VIR_QEMU_PROCESS_START_STANDALONE; - if (jsonPropsValidation) - buildflags = QEMU_BUILD_COMMANDLINE_VALIDATE_KEEP_JSON; - if (qemuProcessInit(driver, vm, NULL, QEMU_ASYNC_JOB_NONE, !!migrateURI, flags) < 0) - return NULL; + return -1; if (qemuProcessPrepareDomain(driver, vm, flags) < 0) - return NULL; + return -1; + + return 0; +} + + +virCommandPtr +qemuProcessCreatePretendCmdBuild(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *migrateURI, + bool enableFips, + bool standalone, + bool jsonPropsValidation) +{ + unsigned int buildflags = 0; + + if (jsonPropsValidation) + buildflags = QEMU_BUILD_COMMANDLINE_VALIDATE_KEEP_JSON; VIR_DEBUG("Building emulator command line"); return qemuBuildCommandLine(driver, diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index dbd989c321..830b2b23d6 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -96,13 +96,18 @@ int qemuProcessStart(virConnectPtr conn, virNetDevVPortProfileOp vmop, unsigned int flags); -virCommandPtr qemuProcessCreatePretendCmd(virQEMUDriverPtr driver, - virDomainObjPtr vm, - const char *migrateURI, - bool enableFips, - bool standalone, - bool jsonPropsValidation, - unsigned int flags); +int qemuProcessCreatePretendCmdPrepare(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *migrateURI, + bool standalone, + unsigned int flags); + +virCommandPtr qemuProcessCreatePretendCmdBuild(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *migrateURI, + bool enableFips, + bool standalone, + bool jsonPropsValidation); int qemuProcessInit(virQEMUDriverPtr driver, virDomainObjPtr vm, diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 8aa791d9f7..7270f2c3cc 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -401,6 +401,10 @@ testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv, { size_t i; + if (qemuProcessCreatePretendCmdPrepare(drv, vm, migrateURI, false, + VIR_QEMU_PROCESS_START_COLD) < 0) + return NULL; + for (i = 0; i < vm->def->nhostdevs; i++) { virDomainHostdevDefPtr hostdev = vm->def->hostdevs[i]; @@ -466,10 +470,9 @@ testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv, } } - return qemuProcessCreatePretendCmd(drv, vm, migrateURI, - (flags & FLAG_FIPS), false, - jsonPropsValidation, - VIR_QEMU_PROCESS_START_COLD); + return qemuProcessCreatePretendCmdBuild(drv, vm, migrateURI, + (flags & FLAG_FIPS), false, + jsonPropsValidation); } -- 2.26.2