qemuDomainDetachDeviceLiveAndConfig: Avoid overwriting @ret

The fact that we are overwriting @ret multiple times makes it
difficult to see what is actually happening here. Follow our
traditional pattern where @ret is initialized to -1, and set to 0
only in case we know we succeeded.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2018-05-23 15:59:55 +02:00
parent 604f3ff0c0
commit a7837f92cc

View File

@ -8710,35 +8710,35 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr driver,
if (!vmdef) if (!vmdef)
goto cleanup; goto cleanup;
if ((ret = qemuDomainDetachDeviceConfig(vmdef, dev, caps, if (qemuDomainDetachDeviceConfig(vmdef, dev, caps,
parse_flags, parse_flags,
driver->xmlopt)) < 0) driver->xmlopt) < 0)
goto cleanup; goto cleanup;
} }
if (flags & VIR_DOMAIN_AFFECT_LIVE) { if (flags & VIR_DOMAIN_AFFECT_LIVE) {
if ((ret = qemuDomainDetachDeviceLive(vm, dev_copy, driver)) < 0) if (qemuDomainDetachDeviceLive(vm, dev_copy, driver) < 0)
goto cleanup; goto cleanup;
/* /*
* update domain status forcibly because the domain status may be * update domain status forcibly because the domain status may be
* changed even if we failed to attach the device. For example, * changed even if we failed to attach the device. For example,
* a new controller may be created. * a new controller may be created.
*/ */
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, caps) < 0) { if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, caps) < 0)
ret = -1;
goto cleanup; goto cleanup;
}
} }
/* Finally, if no error until here, we can save config. */ /* Finally, if no error until here, we can save config. */
if (flags & VIR_DOMAIN_AFFECT_CONFIG) { if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
ret = virDomainSaveConfig(cfg->configDir, caps, vmdef); if (virDomainSaveConfig(cfg->configDir, caps, vmdef) < 0)
if (!ret) { goto cleanup;
virDomainObjAssignDef(vm, vmdef, false, NULL);
vmdef = NULL; virDomainObjAssignDef(vm, vmdef, false, NULL);
} vmdef = NULL;
} }
ret = 0;
cleanup: cleanup:
virObjectUnref(caps); virObjectUnref(caps);
virObjectUnref(cfg); virObjectUnref(cfg);