From 81bbd5e5673d2ed1b10b3a54876ed7945cd5f97c Mon Sep 17 00:00:00 2001 Message-Id: <81bbd5e5673d2ed1b10b3a54876ed7945cd5f97c@dist-git> From: Jiri Denemark Date: Tue, 6 Jun 2017 22:49:11 +0200 Subject: [PATCH] qemu: Introduce virQEMUSaveDataFinish The function is supposed to update the save image header after a successful migration to the save image file. Signed-off-by: Jiri Denemark Reviewed-by: Pavel Hrdina (cherry picked from commit ec986bc5727b88b0631236ad0cdecb0a8568d5cd) https://bugzilla.redhat.com/show_bug.cgi?id=1441662 Signed-off-by: Jiri Denemark --- src/qemu/qemu_driver.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 4a05793339..a0b607b419 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2882,6 +2882,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) { @@ -3135,21 +3154,10 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, if (virFileWrapperFdClose(wrapperFd) < 0) goto cleanup; - if ((fd = qemuOpenFile(driver, vm, path, O_WRONLY, NULL, NULL)) < 0) + if ((fd = qemuOpenFile(driver, vm, path, O_WRONLY, NULL, NULL)) < 0 || + virQEMUSaveDataFinish(header, &fd, path) < 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); - goto cleanup; - } - - if (VIR_CLOSE(fd) < 0) { - virReportSystemError(errno, _("unable to close %s"), path); - goto cleanup; - } - ret = 0; cleanup: -- 2.13.1