diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index a3abd4127e..41d47f51b0 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8092,6 +8092,79 @@ qemuProcessStart(virConnectPtr conn, } +/** + * qemuProcessStartWithMemoryState: + * @conn: connection object + * @driver: qemu driver object + * @vm: domain object + * @fd: FD pointer of memory state file + * @path: path to memory state file + * @data: data from memory state file + * @asyncJob: type of asynchronous job + * @start_flags: flags to start QEMU process with + * @started: boolean to store if QEMU process was started + * + * Start VM with existing memory state. Make sure that the stored memory state + * is correctly decompressed so it can be loaded by QEMU process. + * + * Returns 0 on success, -1 on error. + */ +int +qemuProcessStartWithMemoryState(virConnectPtr conn, + virQEMUDriver *driver, + virDomainObj *vm, + int *fd, + const char *path, + virQEMUSaveData *data, + virDomainAsyncJob asyncJob, + unsigned int start_flags, + bool *started) +{ + qemuDomainObjPrivate *priv = vm->privateData; + g_autoptr(qemuDomainSaveCookie) cookie = NULL; + VIR_AUTOCLOSE intermediatefd = -1; + g_autoptr(virCommand) cmd = NULL; + g_autofree char *errbuf = NULL; + int rc = 0; + + if (virSaveCookieParseString(data->cookie, (virObject **)&cookie, + virDomainXMLOptionGetSaveCookie(driver->xmlopt)) < 0) + return -1; + + if (qemuSaveImageDecompressionStart(data, fd, &intermediatefd, &errbuf, &cmd) < 0) + return -1; + + /* No cookie means libvirt which saved the domain was too old to mess up + * the CPU definitions. + */ + if (cookie && + qemuDomainFixupCPUs(vm, &cookie->cpu) < 0) + return -1; + + if (cookie && !cookie->slirpHelper) + priv->disableSlirp = true; + + if (qemuProcessStart(conn, driver, vm, cookie ? cookie->cpu : NULL, + asyncJob, "stdio", *fd, path, NULL, + VIR_NETDEV_VPORT_PROFILE_OP_RESTORE, + start_flags) == 0) + *started = true; + + rc = qemuSaveImageDecompressionStop(cmd, fd, &intermediatefd, errbuf, *started, path); + + virDomainAuditStart(vm, "restored", *started); + if (!*started || rc < 0) + return -1; + + /* qemuProcessStart doesn't unset the qemu error reporting infrastructure + * in case of migration (which is used in this case) so we need to reset it + * so that the handle to virtlogd is not held open unnecessarily */ + qemuMonitorSetDomainLog(qemuDomainGetMonitor(vm), NULL, NULL, NULL); + + return 0; +} + + int qemuProcessCreatePretendCmdPrepare(virQEMUDriver *driver, virDomainObj *vm, diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 86a60d29c9..a4454f84c4 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -23,6 +23,7 @@ #include "qemu_conf.h" #include "qemu_domain.h" +#include "qemu_saveimage.h" #include "vireventthread.h" int qemuProcessPrepareMonitorChr(virDomainChrSourceDef *monConfig, @@ -90,6 +91,16 @@ int qemuProcessStart(virConnectPtr conn, virNetDevVPortProfileOp vmop, unsigned int flags); +int qemuProcessStartWithMemoryState(virConnectPtr conn, + virQEMUDriver *driver, + virDomainObj *vm, + int *fd, + const char *path, + virQEMUSaveData *data, + virDomainAsyncJob asyncJob, + unsigned int start_flags, + bool *started); + int qemuProcessCreatePretendCmdPrepare(virQEMUDriver *driver, virDomainObj *vm, const char *migrateURI, diff --git a/src/qemu/qemu_saveimage.c b/src/qemu/qemu_saveimage.c index 95fabee907..1fbc7891b1 100644 --- a/src/qemu/qemu_saveimage.c +++ b/src/qemu/qemu_saveimage.c @@ -675,77 +675,6 @@ qemuSaveImageOpen(virQEMUDriver *driver, return ret; } -/** - * qemuSaveImageStartProcess: - * @conn: connection object - * @driver: qemu driver object - * @vm: domain object - * @fd: FD pointer of memory state file - * @path: path to memory state file - * @data: data from memory state file - * @asyncJob: type of asynchronous job - * @start_flags: flags to start QEMU process with - * @started: boolean to store if QEMU process was started - * - * Start VM with existing memory state. Make sure that the stored memory state - * is correctly decompressed so it can be loaded by QEMU process. - * - * Returns 0 on success, -1 on error. - */ -int -qemuSaveImageStartProcess(virConnectPtr conn, - virQEMUDriver *driver, - virDomainObj *vm, - int *fd, - const char *path, - virQEMUSaveData *data, - virDomainAsyncJob asyncJob, - unsigned int start_flags, - bool *started) -{ - qemuDomainObjPrivate *priv = vm->privateData; - g_autoptr(qemuDomainSaveCookie) cookie = NULL; - VIR_AUTOCLOSE intermediatefd = -1; - g_autoptr(virCommand) cmd = NULL; - g_autofree char *errbuf = NULL; - int rc = 0; - - if (virSaveCookieParseString(data->cookie, (virObject **)&cookie, - virDomainXMLOptionGetSaveCookie(driver->xmlopt)) < 0) - return -1; - - if (qemuSaveImageDecompressionStart(data, fd, &intermediatefd, &errbuf, &cmd) < 0) - return -1; - - /* No cookie means libvirt which saved the domain was too old to mess up - * the CPU definitions. - */ - if (cookie && - qemuDomainFixupCPUs(vm, &cookie->cpu) < 0) - return -1; - - if (cookie && !cookie->slirpHelper) - priv->disableSlirp = true; - - if (qemuProcessStart(conn, driver, vm, cookie ? cookie->cpu : NULL, - asyncJob, "stdio", *fd, path, NULL, - VIR_NETDEV_VPORT_PROFILE_OP_RESTORE, - start_flags) == 0) - *started = true; - - rc = qemuSaveImageDecompressionStop(cmd, fd, &intermediatefd, errbuf, *started, path); - - virDomainAuditStart(vm, "restored", *started); - if (!*started || rc < 0) - return -1; - - /* qemuProcessStart doesn't unset the qemu error reporting infrastructure - * in case of migration (which is used in this case) so we need to reset it - * so that the handle to virtlogd is not held open unnecessarily */ - qemuMonitorSetDomainLog(qemuDomainGetMonitor(vm), NULL, NULL, NULL); - - return 0; -} int qemuSaveImageStartVM(virConnectPtr conn, @@ -769,8 +698,8 @@ qemuSaveImageStartVM(virConnectPtr conn, if (reset_nvram) start_flags |= VIR_QEMU_PROCESS_START_RESET_NVRAM; - if (qemuSaveImageStartProcess(conn, driver, vm, fd, path, data, - asyncJob, start_flags, &started) < 0) { + if (qemuProcessStartWithMemoryState(conn, driver, vm, fd, path, data, + asyncJob, start_flags, &started) < 0) { goto cleanup; } diff --git a/src/qemu/qemu_saveimage.h b/src/qemu/qemu_saveimage.h index dcee482066..e541792153 100644 --- a/src/qemu/qemu_saveimage.h +++ b/src/qemu/qemu_saveimage.h @@ -57,17 +57,6 @@ qemuSaveImageUpdateDef(virQEMUDriver *driver, virDomainDef *def, const char *newxml); -int -qemuSaveImageStartProcess(virConnectPtr conn, - virQEMUDriver *driver, - virDomainObj *vm, - int *fd, - const char *path, - virQEMUSaveData *data, - virDomainAsyncJob asyncJob, - unsigned int start_flags, - bool *started); - int qemuSaveImageStartVM(virConnectPtr conn, virQEMUDriver *driver,