]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu_saveimage: move qemuSaveImageStartProcess to qemu_process
authorPavel Hrdina <phrdina@redhat.com>
Mon, 18 Sep 2023 13:20:12 +0000 (15:20 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Mon, 9 Oct 2023 11:56:49 +0000 (13:56 +0200)
The function will no longer be used only when restoring VM as it will
be used when reverting snapshot as well so move it to qemu_process
and rename it accordingly.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/qemu/qemu_process.c
src/qemu/qemu_process.h
src/qemu/qemu_saveimage.c
src/qemu/qemu_saveimage.h

index a3abd4127e95d6db87310cdfa0cb10416ecd739e..41d47f51b002ab89e9688340032f8f375ee10daf 100644 (file)
@@ -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,
index 86a60d29c9e7255ff54941445ee55b897949db02..a4454f84c406c821355159d8fe9731a0015fca24 100644 (file)
@@ -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,
index 95fabee907bd7e8dc70d428633386b5c24e583d6..1fbc7891b1b1a051578ca9930f3eae2e5dac8565 100644 (file)
@@ -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;
     }
 
index dcee482066a4e9340e017c7d43bbea2e5666ea71..e5417921533893a5f07045a8d7f833360887d9cc 100644 (file)
@@ -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,