mirror of https://gitee.com/openkylin/libvirt.git
qemu: Always call virFileWrapperFdClose()
Right now we're reporting errors in virFileWrapperFdFree(), but that's hardly the appropriate place to do so, as free functions are supposed to do nothing more than release allocated resources. We want to move that code back into virFileWrapperFdClose(), but before we can do that we need to make sure the function is actually called every time we're done processing the wrapped file. The cleanup path is the obvious candidate. In a couple of cases we can just move the call, but for the remaining ones we need to duplicate it instead in order not to alter the existing behavior. We do, however, make sure that in all cases a failure to properly close the wrapper results in the overall operation being reported as failed. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
aa60562869
commit
e0e16a3d9a
|
@ -3231,6 +3231,8 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver,
|
|||
|
||||
cleanup:
|
||||
VIR_FORCE_CLOSE(fd);
|
||||
if (qemuFileWrapperFDClose(vm, wrapperFd) < 0)
|
||||
ret = -1;
|
||||
virFileWrapperFdFree(wrapperFd);
|
||||
virObjectUnref(cfg);
|
||||
|
||||
|
@ -3834,9 +3836,11 @@ doCoreDump(virQEMUDriverPtr driver,
|
|||
|
||||
cleanup:
|
||||
VIR_FORCE_CLOSE(fd);
|
||||
if (qemuFileWrapperFDClose(vm, wrapperFd) < 0)
|
||||
ret = -1;
|
||||
virFileWrapperFdFree(wrapperFd);
|
||||
if (ret != 0)
|
||||
unlink(path);
|
||||
virFileWrapperFdFree(wrapperFd);
|
||||
VIR_FREE(compressedpath);
|
||||
virObjectUnref(cfg);
|
||||
return ret;
|
||||
|
@ -7043,17 +7047,17 @@ qemuDomainRestoreFlags(virConnectPtr conn,
|
|||
|
||||
ret = qemuDomainSaveImageStartVM(conn, driver, vm, &fd, data, path,
|
||||
false, QEMU_ASYNC_JOB_START);
|
||||
if (virFileWrapperFdClose(wrapperFd) < 0)
|
||||
VIR_WARN("Failed to close %s", path);
|
||||
|
||||
qemuProcessEndJob(driver, vm);
|
||||
|
||||
cleanup:
|
||||
virDomainDefFree(def);
|
||||
VIR_FORCE_CLOSE(fd);
|
||||
if (virFileWrapperFdClose(wrapperFd) < 0)
|
||||
ret = -1;
|
||||
virFileWrapperFdFree(wrapperFd);
|
||||
virQEMUSaveDataFree(data);
|
||||
VIR_FREE(xmlout);
|
||||
virFileWrapperFdFree(wrapperFd);
|
||||
if (vm && ret < 0)
|
||||
qemuDomainRemoveInactiveJob(driver, vm);
|
||||
virDomainObjEndAPI(&vm);
|
||||
|
@ -7316,14 +7320,14 @@ qemuDomainObjRestore(virConnectPtr conn,
|
|||
|
||||
ret = qemuDomainSaveImageStartVM(conn, driver, vm, &fd, data, path,
|
||||
start_paused, asyncJob);
|
||||
if (virFileWrapperFdClose(wrapperFd) < 0)
|
||||
VIR_WARN("Failed to close %s", path);
|
||||
|
||||
cleanup:
|
||||
virQEMUSaveDataFree(data);
|
||||
VIR_FREE(xmlout);
|
||||
virDomainDefFree(def);
|
||||
VIR_FORCE_CLOSE(fd);
|
||||
if (virFileWrapperFdClose(wrapperFd) < 0)
|
||||
ret = -1;
|
||||
virFileWrapperFdFree(wrapperFd);
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue