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

[libvirt] [PATCHv4 1/4] qemu: Split out guts of qemuDomainSaveImageStartVM() to allow reuse



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.
---
No changes, ACKed.
---
 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 595c452..34aef0c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4952,19 +4952,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);
@@ -4972,7 +4972,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) {
@@ -4988,7 +4988,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
                                _("Failed to start decompression binary %s"),
                                prog);
                 *fd = intermediatefd;
-                goto out;
+                goto cleanup;
             }
         }
     }
@@ -5018,6 +5018,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;
@@ -5058,11 +5082,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


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