]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Introduce virQEMUSaveDataFinish
authorJiri Denemark <jdenemar@redhat.com>
Tue, 6 Jun 2017 20:49:11 +0000 (22:49 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Wed, 7 Jun 2017 11:36:01 +0000 (13:36 +0200)
The function is supposed to update the save image header after a
successful migration to the save image file.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/qemu/qemu_driver.c

index 4415db8b4475bd4f35092ef5efd960781657a516..6f1f10eff90aadc745fd93a3c33b5349f570c381 100644 (file)
@@ -2877,6 +2877,25 @@ qemuDomainSaveHeader(int fd, const char *path, const char *xml,
 }
 
 
+static int
+virQEMUSaveDataFinish(virQEMUSaveHeaderPtr header,
+                      int *fd,
+                      const char *path)
+{
+    memcpy(header->magic, QEMU_SAVE_MAGIC, sizeof(header->magic));
+
+    if (safewrite(*fd, header, sizeof(*header)) != sizeof(*header) ||
+        VIR_CLOSE(*fd) < 0) {
+        virReportSystemError(errno,
+                             _("failed to write header to domain save file '%s'"),
+                             path);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static virCommandPtr
 qemuCompressGetCommand(virQEMUSaveFormat compression)
 {
@@ -3149,20 +3168,9 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver,
     if (virFileWrapperFdClose(wrapperFd) < 0)
         goto cleanup;
 
-    if ((fd = qemuOpenFile(driver, vm, path, O_WRONLY, NULL, NULL)) < 0)
-        goto cleanup;
-
-    memcpy(header->magic, QEMU_SAVE_MAGIC, sizeof(header->magic));
-
-    if (safewrite(fd, &header, sizeof(header)) != sizeof(header)) {
-        virReportSystemError(errno, _("unable to write %s"), path);
+    if ((fd = qemuOpenFile(driver, vm, path, O_WRONLY, NULL, NULL)) < 0 ||
+        virQEMUSaveDataFinish(header, &fd, path) < 0)
         goto cleanup;
-    }
-
-    if (VIR_CLOSE(fd) < 0) {
-        virReportSystemError(errno, _("unable to close %s"), path);
-        goto cleanup;
-    }
 
     ret = 0;