mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
Fix minor issues in libxenlight managed save
There were a few minor issues in commit 5b6c961e - leak managed save path - leak managed save fd - functions that open an fd should also close it
This commit is contained in:
parent
39b59dbdb4
commit
9a76e737fc
@ -632,23 +632,27 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
|
|||||||
int ret;
|
int ret;
|
||||||
uint32_t domid = 0;
|
uint32_t domid = 0;
|
||||||
char *dom_xml = NULL;
|
char *dom_xml = NULL;
|
||||||
char *managed_save = NULL;
|
char *managed_save_path = NULL;
|
||||||
|
int managed_save_fd = -1;
|
||||||
pid_t child_console_pid = -1;
|
pid_t child_console_pid = -1;
|
||||||
libxlDomainObjPrivatePtr priv = vm->privateData;
|
libxlDomainObjPrivatePtr priv = vm->privateData;
|
||||||
|
|
||||||
/* If there is a managed saved state restore it instead of starting
|
/* If there is a managed saved state restore it instead of starting
|
||||||
* from scratch. The old state is removed once the restoring succeeded. */
|
* from scratch. The old state is removed once the restoring succeeded. */
|
||||||
if (restore_fd < 0) {
|
if (restore_fd < 0) {
|
||||||
managed_save = libxlDomainManagedSavePath(driver, vm);
|
managed_save_path = libxlDomainManagedSavePath(driver, vm);
|
||||||
if (managed_save == NULL)
|
if (managed_save_path == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virFileExists(managed_save)) {
|
if (virFileExists(managed_save_path)) {
|
||||||
|
|
||||||
restore_fd = libxlSaveImageOpen(driver, managed_save, &def, &hdr);
|
managed_save_fd = libxlSaveImageOpen(driver, managed_save_path,
|
||||||
if (restore_fd < 0)
|
&def, &hdr);
|
||||||
|
if (managed_save_fd < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
restore_fd = managed_save_fd;
|
||||||
|
|
||||||
if (STRNEQ(vm->def->name, def->name) ||
|
if (STRNEQ(vm->def->name, def->name) ||
|
||||||
memcmp(vm->def->uuid, def->uuid, VIR_UUID_BUFLEN)) {
|
memcmp(vm->def->uuid, def->uuid, VIR_UUID_BUFLEN)) {
|
||||||
char vm_uuidstr[VIR_UUID_STRING_BUFLEN];
|
char vm_uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
@ -665,9 +669,12 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
|
|||||||
virDomainObjAssignDef(vm, def, true);
|
virDomainObjAssignDef(vm, def, true);
|
||||||
def = NULL;
|
def = NULL;
|
||||||
|
|
||||||
if (unlink(managed_save) < 0)
|
if (unlink(managed_save_path) < 0) {
|
||||||
VIR_WARN("Failed to remove the managed state %s", managed_save);
|
VIR_WARN("Failed to remove the managed state %s",
|
||||||
|
managed_save_path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
VIR_FREE(managed_save_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&d_config, 0, sizeof(d_config));
|
memset(&d_config, 0, sizeof(d_config));
|
||||||
@ -738,6 +745,7 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
|
|||||||
|
|
||||||
libxl_domain_config_destroy(&d_config);
|
libxl_domain_config_destroy(&d_config);
|
||||||
VIR_FREE(dom_xml);
|
VIR_FREE(dom_xml);
|
||||||
|
VIR_FORCE_CLOSE(managed_save_fd);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
@ -748,9 +756,9 @@ error:
|
|||||||
}
|
}
|
||||||
libxl_domain_config_destroy(&d_config);
|
libxl_domain_config_destroy(&d_config);
|
||||||
VIR_FREE(dom_xml);
|
VIR_FREE(dom_xml);
|
||||||
VIR_FREE(managed_save);
|
VIR_FREE(managed_save_path);
|
||||||
virDomainDefFree(def);
|
virDomainDefFree(def);
|
||||||
VIR_FORCE_CLOSE(restore_fd);
|
VIR_FORCE_CLOSE(managed_save_fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1955,6 +1963,8 @@ libxlDomainRestore(virConnectPtr conn, const char *from)
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
if (VIR_CLOSE(fd) < 0)
|
||||||
|
virReportSystemError(errno, "%s", _("cannot close file"));
|
||||||
virDomainDefFree(def);
|
virDomainDefFree(def);
|
||||||
if (vm)
|
if (vm)
|
||||||
virDomainObjUnlock(vm);
|
virDomainObjUnlock(vm);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user