now that we introduced virQEMUSaveFd, use it in the creation of a
new save image.
Signed-off-by: Claudio Fontana <cfontana(a)suse.de>
---
src/qemu/qemu_saveimage.c | 54 +++++++++++----------------------------
1 file changed, 15 insertions(+), 39 deletions(-)
diff --git a/src/qemu/qemu_saveimage.c b/src/qemu/qemu_saveimage.c
index 67c93e3865..30e9a16307 100644
--- a/src/qemu/qemu_saveimage.c
+++ b/src/qemu/qemu_saveimage.c
@@ -380,41 +380,31 @@ qemuSaveImageCreate(virQEMUDriver *driver,
virDomainAsyncJob asyncJob)
{
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
- bool needUnlink = false;
+ virQEMUSaveFd saveFd = QEMU_SAVEFD_INVALID;
+ unsigned int oflags = O_WRONLY | O_TRUNC | O_CREAT;
int ret = -1;
- int fd = -1;
- int directFlag = 0;
- virFileWrapperFd *wrapperFd = NULL;
- unsigned int wrapperFlags = VIR_FILE_WRAPPER_NON_BLOCKING;
- /* Obtain the file handle. */
- if ((flags & VIR_DOMAIN_SAVE_BYPASS_CACHE)) {
- wrapperFlags |= VIR_FILE_WRAPPER_BYPASS_CACHE;
- directFlag = virFileDirectFdFlag();
- if (directFlag < 0) {
+ if (flags & VIR_DOMAIN_SAVE_BYPASS_CACHE) {
+ if (virFileDirectFdFlag() < 0) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("bypass cache unsupported by this system"));
- goto cleanup;
+ return -1;
}
+ oflags |= O_DIRECT;
}
- fd = virQEMUFileOpenAs(cfg->user, cfg->group, false, path,
- O_WRONLY | O_TRUNC | O_CREAT | directFlag,
- &needUnlink);
- if (fd < 0)
+ if (virQEMUSaveFdInit(&saveFd, path, 0, oflags, cfg) < 0)
goto cleanup;
-
- if (qemuSecuritySetImageFDLabel(driver->securityManager, vm->def, fd) < 0)
+ if (qemuSecuritySetImageFDLabel(driver->securityManager, vm->def, saveFd.fd)
< 0)
goto cleanup;
-
- if (!(wrapperFd = virFileWrapperFdNew(&fd, path, wrapperFlags)))
+ if (virQEMUSaveDataWrite(data, saveFd.fd, saveFd.path) < 0)
goto cleanup;
- if (virQEMUSaveDataWrite(data, fd, path) < 0)
+ /* Perform the migration */
+ if (qemuMigrationSrcToFile(driver, vm, saveFd.fd, compressor, asyncJob) < 0)
goto cleanup;
- /* Perform the migration */
- if (qemuMigrationSrcToFile(driver, vm, fd, compressor, asyncJob) < 0)
+ if (virQEMUSaveFdClose(&saveFd, vm) < 0)
goto cleanup;
/* Touch up file header to mark image complete. */
@@ -423,29 +413,15 @@ qemuSaveImageCreate(virQEMUDriver *driver,
* up to seek backwards on wrapperFd. The reopened fd will
* trigger a single page of file system cache pollution, but
* that's acceptable. */
- if (VIR_CLOSE(fd) < 0) {
- virReportSystemError(errno, _("unable to close %s"), path);
- goto cleanup;
- }
- if (qemuDomainFileWrapperFDClose(vm, wrapperFd) < 0)
- goto cleanup;
-
- if ((fd = qemuDomainOpenFile(cfg, vm->def, path, O_WRONLY, NULL)) < 0 ||
- virQEMUSaveDataFinish(data, &fd, path) < 0)
+ if ((saveFd.fd = qemuDomainOpenFile(cfg, vm->def, saveFd.path, O_WRONLY, NULL))
< 0 ||
+ virQEMUSaveDataFinish(data, &saveFd.fd, saveFd.path) < 0)
goto cleanup;
ret = 0;
cleanup:
- VIR_FORCE_CLOSE(fd);
- if (qemuDomainFileWrapperFDClose(vm, wrapperFd) < 0)
- ret = -1;
- virFileWrapperFdFree(wrapperFd);
-
- if (ret < 0 && needUnlink)
- unlink(path);
-
+ ret = virQEMUSaveFdFini(&saveFd, vm, ret);
return ret;
}
--
2.35.3