1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

qemu: Simplify qemuDomainSetInterfaceParameters by using virDomainObjGetDefs

This commit is contained in:
Peter Krempa 2015-06-15 19:46:28 +02:00
parent 875a731d21
commit caa6cd39cc

View File

@ -11246,12 +11246,12 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
virQEMUDriverPtr driver = dom->conn->privateData; virQEMUDriverPtr driver = dom->conn->privateData;
size_t i; size_t i;
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
virDomainDefPtr persistentDef = NULL; virDomainDefPtr def;
virDomainDefPtr persistentDef;
int ret = -1; int ret = -1;
virDomainNetDefPtr net = NULL, persistentNet = NULL; virDomainNetDefPtr net = NULL, persistentNet = NULL;
virNetDevBandwidthPtr bandwidth = NULL, newBandwidth = NULL; virNetDevBandwidthPtr bandwidth = NULL, newBandwidth = NULL;
virQEMUDriverConfigPtr cfg = NULL; virQEMUDriverConfigPtr cfg = NULL;
virCapsPtr caps = NULL;
bool inboundSpecified = false, outboundSpecified = false; bool inboundSpecified = false, outboundSpecified = false;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
@ -11280,31 +11280,24 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
if (virDomainSetInterfaceParametersEnsureACL(dom->conn, vm->def, flags) < 0) if (virDomainSetInterfaceParametersEnsureACL(dom->conn, vm->def, flags) < 0)
goto cleanup; goto cleanup;
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup;
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
goto cleanup; goto cleanup;
if (virDomainLiveConfigHelperMethod(caps, driver->xmlopt, vm, &flags, if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
&persistentDef) < 0)
goto endjob; goto endjob;
if (flags & VIR_DOMAIN_AFFECT_LIVE) { if (def &&
net = virDomainNetFind(vm->def, device); !(net = virDomainNetFind(vm->def, device))) {
if (!net) { virReportError(VIR_ERR_INVALID_ARG,
virReportError(VIR_ERR_INVALID_ARG, _("Can't find device %s"), device);
_("Can't find device %s"), device); goto endjob;
goto endjob;
}
} }
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
persistentNet = virDomainNetFind(persistentDef, device); if (persistentDef &&
if (!persistentNet) { !(persistentNet = virDomainNetFind(persistentDef, device))) {
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("Can't find device %s"), device); _("Can't find device %s"), device);
goto endjob; goto endjob;
}
} }
if ((VIR_ALLOC(bandwidth) < 0) || if ((VIR_ALLOC(bandwidth) < 0) ||
@ -11340,7 +11333,7 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
if (!bandwidth->out->average) if (!bandwidth->out->average)
VIR_FREE(bandwidth->out); VIR_FREE(bandwidth->out);
if (flags & VIR_DOMAIN_AFFECT_LIVE) { if (net) {
if (VIR_ALLOC(newBandwidth) < 0) if (VIR_ALLOC(newBandwidth) < 0)
goto endjob; goto endjob;
@ -11392,7 +11385,7 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
goto endjob; goto endjob;
} }
if (flags & VIR_DOMAIN_AFFECT_CONFIG) { if (persistentNet) {
if (!persistentNet->bandwidth) { if (!persistentNet->bandwidth) {
persistentNet->bandwidth = bandwidth; persistentNet->bandwidth = bandwidth;
bandwidth = NULL; bandwidth = NULL;
@ -11426,7 +11419,6 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
virNetDevBandwidthFree(bandwidth); virNetDevBandwidthFree(bandwidth);
virNetDevBandwidthFree(newBandwidth); virNetDevBandwidthFree(newBandwidth);
virDomainObjEndAPI(&vm); virDomainObjEndAPI(&vm);
virObjectUnref(caps);
virObjectUnref(cfg); virObjectUnref(cfg);
return ret; return ret;
} }