mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 03:12:22 +00:00
qemuFileWrapperFDClose: move to qemu_domain.c
Move the code to qemu_domain.c so that it can be reused in other parts of the qemu driver. 'qemu_domain' was chosen as we check the domain state after closing the wrapper. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
19b2d84854
commit
8cd7ee6587
@ -10867,3 +10867,31 @@ qemuDomainOpenFile(virQEMUDriverPtr driver,
|
||||
return virQEMUFileOpenAs(user, group, dynamicOwnership,
|
||||
path, oflags, needUnlink);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
qemuDomainFileWrapperFDClose(virDomainObjPtr vm,
|
||||
virFileWrapperFdPtr fd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* virFileWrapperFd uses iohelper to write data onto disk.
|
||||
* However, iohelper calls fdatasync() which may take ages to
|
||||
* finish. Therefore, we shouldn't be waiting with the domain
|
||||
* object locked. */
|
||||
|
||||
/* XXX Currently, this function is intended for *Save() only
|
||||
* as restore needs some reworking before it's ready for
|
||||
* this. */
|
||||
|
||||
virObjectUnlock(vm);
|
||||
ret = virFileWrapperFdClose(fd);
|
||||
virObjectLock(vm);
|
||||
if (!virDomainObjIsActive(vm)) {
|
||||
if (virGetLastErrorCode() == VIR_ERR_OK)
|
||||
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||
_("domain is no longer running"));
|
||||
ret = -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -1030,3 +1030,7 @@ qemuDomainOpenFile(virQEMUDriverPtr driver,
|
||||
const char *path,
|
||||
int oflags,
|
||||
bool *needUnlink);
|
||||
|
||||
int
|
||||
qemuDomainFileWrapperFDClose(virDomainObjPtr vm,
|
||||
virFileWrapperFdPtr fd);
|
||||
|
@ -3022,34 +3022,6 @@ qemuCompressGetCommand(virQEMUSaveFormat compression)
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
qemuFileWrapperFDClose(virDomainObjPtr vm,
|
||||
virFileWrapperFdPtr fd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* virFileWrapperFd uses iohelper to write data onto disk.
|
||||
* However, iohelper calls fdatasync() which may take ages to
|
||||
* finish. Therefore, we shouldn't be waiting with the domain
|
||||
* object locked. */
|
||||
|
||||
/* XXX Currently, this function is intended for *Save() only
|
||||
* as restore needs some reworking before it's ready for
|
||||
* this. */
|
||||
|
||||
virObjectUnlock(vm);
|
||||
ret = virFileWrapperFdClose(fd);
|
||||
virObjectLock(vm);
|
||||
if (!virDomainObjIsActive(vm)) {
|
||||
if (virGetLastErrorCode() == VIR_ERR_OK)
|
||||
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||
_("domain is no longer running"));
|
||||
ret = -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* Helper function to execute a migration to file with a correct save header
|
||||
* the caller needs to make sure that the processors are stopped and do all other
|
||||
* actions besides saving memory */
|
||||
@ -3111,7 +3083,7 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (qemuFileWrapperFDClose(vm, wrapperFd) < 0)
|
||||
if (qemuDomainFileWrapperFDClose(vm, wrapperFd) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if ((fd = qemuDomainOpenFile(driver, vm, path, O_WRONLY, NULL)) < 0 ||
|
||||
@ -3122,7 +3094,7 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver,
|
||||
|
||||
cleanup:
|
||||
VIR_FORCE_CLOSE(fd);
|
||||
if (qemuFileWrapperFDClose(vm, wrapperFd) < 0)
|
||||
if (qemuDomainFileWrapperFDClose(vm, wrapperFd) < 0)
|
||||
ret = -1;
|
||||
virFileWrapperFdFree(wrapperFd);
|
||||
|
||||
@ -3704,14 +3676,14 @@ doCoreDump(virQEMUDriverPtr driver,
|
||||
path);
|
||||
goto cleanup;
|
||||
}
|
||||
if (qemuFileWrapperFDClose(vm, wrapperFd) < 0)
|
||||
if (qemuDomainFileWrapperFDClose(vm, wrapperFd) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FORCE_CLOSE(fd);
|
||||
if (qemuFileWrapperFDClose(vm, wrapperFd) < 0)
|
||||
if (qemuDomainFileWrapperFDClose(vm, wrapperFd) < 0)
|
||||
ret = -1;
|
||||
virFileWrapperFdFree(wrapperFd);
|
||||
if (ret != 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user