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.
---
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 d9b6c9c..04906d4 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4918,19 +4918,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);
@@ -4938,7 +4938,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) {
@@ -4954,7 +4954,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
_("Failed to start decompression binary %s"),
prog);
*fd = intermediatefd;
- goto out;
+ goto cleanup;
}
}
}
@@ -4984,6 +4984,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;
@@ -5024,11 +5048,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.7.12.4