[PATCHv3 1/5] qemu: Split out guts of qemuDomainSaveImageStartVM() to allow reuse

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The workhorse part of qemuDomainSaveImageStartVM can be reused while
loading external snapshots. This patch splits the code out into a new
function qemuDomainSaveImageLoad that is free of setting lifecycle
events.
---
Previous version ACKed. Just a repost.
---
 src/qemu/qemu_driver.c | 53 ++++++++++++++++++++++++++++++++++----------------
 1 file changed, 36 insertions(+), 17 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 5556f1e..2ddf63a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4956,19 +4956,19 @@ error:
     return -1;
 }

-static int ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5) ATTRIBUTE_NONNULL(6)
-qemuDomainSaveImageStartVM(virConnectPtr conn,
-                           struct qemud_driver *driver,
-                           virDomainObjPtr vm,
-                           int *fd,
-                           const struct qemud_save_header *header,
-                           const char *path,
-                           bool start_paused)
+/* this helper loads the save image into a new qemu process */
+static int
+qemuDomainSaveImageLoad(virConnectPtr conn,
+                        struct qemud_driver *driver,
+                        virDomainObjPtr vm,
+                        int *fd,
+                        const struct qemud_save_header *header,
+                        const char *path)
+
 {
-    int ret = -1;
-    virDomainEventPtr event;
     int intermediatefd = -1;
     virCommandPtr cmd = NULL;
+    int ret = -1;

     if (header->version == 2) {
         const char *prog = qemudSaveCompressionTypeToString(header->compressed);
@@ -4976,7 +4976,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
             virReportError(VIR_ERR_OPERATION_FAILED,
                            _("Invalid compressed save format %d"),
                            header->compressed);
-            goto out;
+            goto cleanup;
         }

         if (header->compressed != QEMUD_SAVE_FORMAT_RAW) {
@@ -4992,7 +4992,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
                                _("Failed to start decompression binary %s"),
                                prog);
                 *fd = intermediatefd;
-                goto out;
+                goto cleanup;
             }
         }
     }
@@ -5022,6 +5022,30 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
         ret = -1;
     }

+cleanup:
+    virCommandFree(cmd);
+    if (virSecurityManagerRestoreSavedStateLabel(driver->securityManager,
+                                                 vm->def, path) < 0)
+        VIR_WARN("failed to restore save state label on %s", path);
+
+
+    return ret;
+}
+
+static int ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5) ATTRIBUTE_NONNULL(6)
+qemuDomainSaveImageStartVM(virConnectPtr conn,
+                           struct qemud_driver *driver,
+                           virDomainObjPtr vm,
+                           int *fd,
+                           const struct qemud_save_header *header,
+                           const char *path,
+                           bool start_paused)
+{
+    virDomainEventPtr event;
+    int ret = -1;
+
+    ret = qemuDomainSaveImageLoad(conn, driver, vm, fd, header, path);
+
     if (ret < 0) {
         virDomainAuditStart(vm, "restored", false);
         goto out;
@@ -5062,11 +5086,6 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
     ret = 0;

 out:
-    virCommandFree(cmd);
-    if (virSecurityManagerRestoreSavedStateLabel(driver->securityManager,
-                                                 vm->def, path) < 0)
-        VIR_WARN("failed to restore save state label on %s", path);
-
     return ret;
 }

-- 
1.8.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]