qemu: Always use iohelper for domain save

This is probably not strictly needed as save operation is not live but
we may have other reasons to avoid blocking qemu's main loop.
This commit is contained in:
Jiri Denemark 2012-02-08 14:08:54 +01:00
parent afb96301f3
commit c4caab538e

View File

@ -2522,7 +2522,7 @@ qemuDomainSaveInternal(struct qemud_driver *driver, virDomainPtr dom,
int fd = -1; int fd = -1;
int directFlag = 0; int directFlag = 0;
virFileWrapperFdPtr wrapperFd = NULL; virFileWrapperFdPtr wrapperFd = NULL;
bool bypass_cache = flags & VIR_DOMAIN_SAVE_BYPASS_CACHE; unsigned int wrapperFlags = VIR_FILE_WRAPPER_NON_BLOCKING;
if (qemuProcessAutoDestroyActive(driver, vm)) { if (qemuProcessAutoDestroyActive(driver, vm)) {
qemuReportError(VIR_ERR_OPERATION_INVALID, qemuReportError(VIR_ERR_OPERATION_INVALID,
@ -2613,7 +2613,8 @@ qemuDomainSaveInternal(struct qemud_driver *driver, virDomainPtr dom,
header.xml_len = len; header.xml_len = len;
/* Obtain the file handle. */ /* Obtain the file handle. */
if (bypass_cache) { if ((flags & VIR_DOMAIN_SAVE_BYPASS_CACHE)) {
wrapperFlags |= VIR_FILE_WRAPPER_BYPASS_CACHE;
directFlag = virFileDirectFdFlag(); directFlag = virFileDirectFdFlag();
if (directFlag < 0) { if (directFlag < 0) {
qemuReportError(VIR_ERR_OPERATION_FAILED, "%s", qemuReportError(VIR_ERR_OPERATION_FAILED, "%s",
@ -2625,9 +2626,7 @@ qemuDomainSaveInternal(struct qemud_driver *driver, virDomainPtr dom,
&needUnlink, &bypassSecurityDriver); &needUnlink, &bypassSecurityDriver);
if (fd < 0) if (fd < 0)
goto endjob; goto endjob;
if (bypass_cache && if (!(wrapperFd = virFileWrapperFdNew(&fd, path, wrapperFlags)))
!(wrapperFd = virFileWrapperFdNew(&fd, path,
VIR_FILE_WRAPPER_BYPASS_CACHE)))
goto endjob; goto endjob;
/* Write header to file, followed by XML */ /* Write header to file, followed by XML */
@ -2643,27 +2642,22 @@ qemuDomainSaveInternal(struct qemud_driver *driver, virDomainPtr dom,
QEMU_ASYNC_JOB_SAVE) < 0) QEMU_ASYNC_JOB_SAVE) < 0)
goto endjob; goto endjob;
/* Touch up file header to mark image complete. */ /* Touch up file header to mark image complete. */
if (bypass_cache) {
/* Reopen the file to touch up the header, since we aren't set /* Reopen the file to touch up the header, since we aren't set
* up to seek backwards on wrapperFd. The reopened fd will * up to seek backwards on wrapperFd. The reopened fd will
* trigger a single page of file system cache pollution, but * trigger a single page of file system cache pollution, but
* that's acceptable. */ * that's acceptable. */
if (VIR_CLOSE(fd) < 0) { if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno, _("unable to close %s"), path); virReportSystemError(errno, _("unable to close %s"), path);
goto endjob; goto endjob;
}
if (virFileWrapperFdClose(wrapperFd) < 0)
goto endjob;
fd = qemuOpenFile(driver, path, O_WRONLY, NULL, NULL);
if (fd < 0)
goto endjob;
} else {
if (lseek(fd, 0, SEEK_SET) != 0) {
virReportSystemError(errno, _("unable to seek %s"), path);
goto endjob;
}
} }
if (virFileWrapperFdClose(wrapperFd) < 0)
goto endjob;
fd = qemuOpenFile(driver, path, O_WRONLY, NULL, NULL);
if (fd < 0)
goto endjob;
memcpy(header.magic, QEMUD_SAVE_MAGIC, sizeof(header.magic)); memcpy(header.magic, QEMUD_SAVE_MAGIC, sizeof(header.magic));
if (safewrite(fd, &header, sizeof(header)) != sizeof(header)) { if (safewrite(fd, &header, sizeof(header)) != sizeof(header)) {
virReportSystemError(errno, _("unable to write %s"), path); virReportSystemError(errno, _("unable to write %s"), path);