qemu: qemuDomainDefineXMLFlags: move cleanup logic to cleanup section

Let's move objlist restoring to cleanup section so that we can handle failure
of actions between virDomainObjListAdd and virDomainDefSave. We are going
to add such actions in next patch.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Nikolay Shirokovskiy 2020-11-03 10:14:36 +03:00
parent e2738b2bd7
commit 773c7c4361

View File

@ -6705,7 +6705,7 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
if (!(def = virDomainDefParseString(xml, driver->xmlopt,
NULL, parse_flags)))
goto cleanup;
return NULL;
if (virXMLCheckIllegalChars("name", def->name, "\n") < 0)
goto cleanup;
@ -6719,10 +6719,23 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
goto cleanup;
def = NULL;
if (virDomainDefSave(vm->newDef ? vm->newDef : vm->def,
driver->xmlopt, cfg->configDir) < 0)
goto cleanup;
vm->persistent = 1;
if (virDomainDefSave(vm->newDef ? vm->newDef : vm->def,
driver->xmlopt, cfg->configDir) < 0) {
event = virDomainEventLifecycleNewFromObj(vm,
VIR_DOMAIN_EVENT_DEFINED,
!oldDef ?
VIR_DOMAIN_EVENT_DEFINED_ADDED :
VIR_DOMAIN_EVENT_DEFINED_UPDATED);
VIR_INFO("Creating domain '%s'", vm->def->name);
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
cleanup:
if (!dom && !def) {
if (oldDef) {
/* There is backup so this VM was defined before.
* Just restore the backup. */
@ -6735,22 +6748,9 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
} else {
/* Brand new domain. Remove it */
VIR_INFO("Deleting domain '%s'", vm->def->name);
vm->persistent = 0;
qemuDomainRemoveInactiveJob(driver, vm);
}
goto cleanup;
}
event = virDomainEventLifecycleNewFromObj(vm,
VIR_DOMAIN_EVENT_DEFINED,
!oldDef ?
VIR_DOMAIN_EVENT_DEFINED_ADDED :
VIR_DOMAIN_EVENT_DEFINED_UPDATED);
VIR_INFO("Creating domain '%s'", vm->def->name);
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
cleanup:
virDomainDefFree(oldDef);
virDomainDefFree(def);
virDomainObjEndAPI(&vm);