virQEMUDriverConfigPtr can be auto-unref for the great majority
of the uses made in qemu_driver, sparing us a virObjectUnref()
call and sometimes a whole 'cleanup' label.
This patch changes virQEMUDriverConfigPtr declarations to
use VIR_AUTOUNREF(). 'cleanup' labels were deleted when
applicable.
Since there are a lot of references to change, let's do it in
3 steps. This is step 2.
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/qemu/qemu_driver.c | 81 ++++++++++++++----------------------------
1 file changed, 26 insertions(+), 55 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1e709c1e97..8321fbbe8b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4566,7 +4566,7 @@ processNicRxFilterChangedEvent(virQEMUDriverPtr driver,
virDomainObjPtr vm,
const char *devAlias)
{
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
qemuDomainObjPrivatePtr priv = vm->privateData;
virDomainDeviceDef dev;
virDomainNetDefPtr def;
@@ -4665,7 +4665,6 @@ processNicRxFilterChangedEvent(virQEMUDriverPtr driver,
cleanup:
virNetDevRxFilterFree(hostFilter);
virNetDevRxFilterFree(guestFilter);
- virObjectUnref(cfg);
}
@@ -4675,7 +4674,7 @@ processSerialChangedEvent(virQEMUDriverPtr driver,
const char *devAlias,
bool connected)
{
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
virDomainChrDeviceState newstate;
virObjectEventPtr event = NULL;
virDomainDeviceDef dev;
@@ -4708,7 +4707,7 @@ processSerialChangedEvent(virQEMUDriverPtr driver,
}
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
- goto cleanup;
+ return;
if (!virDomainObjIsActive(vm)) {
VIR_DEBUG("Domain is not running");
@@ -4749,9 +4748,6 @@ processSerialChangedEvent(virQEMUDriverPtr driver,
endjob:
qemuDomainObjEndJob(driver, vm);
-
- cleanup:
- virObjectUnref(cfg);
}
@@ -5024,21 +5020,20 @@ qemuDomainSetVcpusMax(virQEMUDriverPtr driver,
virDomainDefPtr persistentDef,
unsigned int nvcpus)
{
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
unsigned int topologycpus;
- int ret = -1;
if (def) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("maximum vcpu count of a live domain can't be
modified"));
- goto cleanup;
+ return -1;
}
if (virDomainNumaGetCPUCountTotal(persistentDef->numa) > nvcpus) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("Number of CPUs in <numa> exceeds the desired "
"maximum vcpu count"));
- goto cleanup;
+ return -1;
}
if (virDomainDefGetVcpusTopology(persistentDef, &topologycpus) == 0 &&
@@ -5047,23 +5042,19 @@ qemuDomainSetVcpusMax(virQEMUDriverPtr driver,
* setting may be corrected via this API */
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("CPU topology doesn't match the desired vcpu
count"));
- goto cleanup;
+ return -1;
}
/* ordering information may become invalid, thus clear it */
virDomainDefVcpuOrderClear(persistentDef);
if (virDomainDefSetVcpusMax(persistentDef, nvcpus, driver->xmlopt) < 0)
- goto cleanup;
+ return -1;
if (virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0)
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- virObjectUnref(cfg);
- return ret;
+ return 0;
}
@@ -5228,7 +5219,7 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
int ret = -1;
virBitmapPtr pcpumap = NULL;
virDomainVcpuDefPtr vcpuinfo = NULL;
- virQEMUDriverConfigPtr cfg = NULL;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1);
@@ -5285,7 +5276,6 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
cleanup:
virDomainObjEndAPI(&vm);
virBitmapFree(pcpumap);
- virObjectUnref(cfg);
return ret;
}
@@ -5348,7 +5338,7 @@ qemuDomainPinEmulator(virDomainPtr dom,
int ret = -1;
qemuDomainObjPrivatePtr priv;
virBitmapPtr pcpumap = NULL;
- virQEMUDriverConfigPtr cfg = NULL;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
virObjectEventPtr event = NULL;
char *str = NULL;
virTypedParameterPtr eventParams = NULL;
@@ -5442,7 +5432,6 @@ qemuDomainPinEmulator(virDomainPtr dom,
VIR_FREE(str);
virBitmapFree(pcpumap);
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
@@ -5813,7 +5802,7 @@ qemuDomainPinIOThread(virDomainPtr dom,
{
int ret = -1;
virQEMUDriverPtr driver = dom->conn->privateData;
- virQEMUDriverConfigPtr cfg = NULL;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
virDomainObjPtr vm;
virDomainDefPtr def;
virDomainDefPtr persistentDef;
@@ -5937,7 +5926,6 @@ qemuDomainPinIOThread(virDomainPtr dom,
VIR_FREE(str);
virBitmapFree(pcpumap);
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
@@ -6286,7 +6274,7 @@ qemuDomainChgIOThread(virQEMUDriverPtr driver,
virDomainIOThreadAction action,
unsigned int flags)
{
- virQEMUDriverConfigPtr cfg = NULL;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
qemuDomainObjPrivatePtr priv;
virDomainDefPtr def;
virDomainDefPtr persistentDef;
@@ -6297,7 +6285,7 @@ qemuDomainChgIOThread(virQEMUDriverPtr driver,
priv = vm->privateData;
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
- goto cleanup;
+ return -1;
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
goto endjob;
@@ -6385,8 +6373,6 @@ qemuDomainChgIOThread(virQEMUDriverPtr driver,
endjob:
qemuDomainObjEndJob(driver, vm);
- cleanup:
- virObjectUnref(cfg);
return ret;
}
@@ -6897,7 +6883,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
int intermediatefd = -1;
virCommandPtr cmd = NULL;
char *errbuf = NULL;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
virQEMUSaveHeaderPtr header = &data->header;
qemuDomainSaveCookiePtr cookie = NULL;
@@ -7019,7 +7005,6 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
VIR_FREE(errbuf);
if (qemuSecurityRestoreSavedStateLabel(driver, vm, path) < 0)
VIR_WARN("failed to restore save state label on %s", path);
- virObjectUnref(cfg);
return ret;
}
@@ -7444,13 +7429,11 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
virCommandPtr cmd = NULL;
char *ret = NULL;
size_t i;
- virQEMUDriverConfigPtr cfg;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
virCapsPtr caps = NULL;
virCheckFlags(0, NULL);
- cfg = virQEMUDriverGetConfig(driver);
-
if (virConnectDomainXMLToNativeEnsureACL(conn) < 0)
goto cleanup;
@@ -7510,7 +7493,6 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
virCommandFree(cmd);
virObjectUnref(vm);
virObjectUnref(caps);
- virObjectUnref(cfg);
return ret;
}
@@ -7697,7 +7679,7 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
virDomainObjPtr vm = NULL;
virDomainPtr dom = NULL;
virObjectEventPtr event = NULL;
- virQEMUDriverConfigPtr cfg;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
virCapsPtr caps = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE |
VIR_DOMAIN_DEF_PARSE_ABI_UPDATE;
@@ -7707,8 +7689,6 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
if (flags & VIR_DOMAIN_DEFINE_VALIDATE)
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA;
- cfg = virQEMUDriverGetConfig(driver);
-
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup;
@@ -7765,7 +7745,6 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
virDomainObjEndAPI(&vm);
virObjectEventStateQueue(driver->domainEventState, event);
virObjectUnref(caps);
- virObjectUnref(cfg);
return dom;
}
@@ -7786,7 +7765,7 @@ qemuDomainUndefineFlags(virDomainPtr dom,
int ret = -1;
int nsnapshots;
int ncheckpoints;
- virQEMUDriverConfigPtr cfg = NULL;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE |
VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA |
@@ -7906,7 +7885,6 @@ qemuDomainUndefineFlags(virDomainPtr dom,
VIR_FREE(name);
virDomainObjEndAPI(&vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
return ret;
}
@@ -8726,7 +8704,7 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm,
{
qemuDomainObjPrivatePtr priv = vm->privateData;
virDomainDefPtr vmdef = NULL;
- virQEMUDriverConfigPtr cfg = NULL;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
virDomainDeviceDefPtr devConf = NULL;
virDomainDeviceDefPtr devLive = NULL;
int ret = -1;
@@ -8811,7 +8789,6 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm,
virDomainDefFree(vmdef);
virDomainDeviceDefFree(devConf);
virDomainDeviceDefFree(devLive);
- virObjectUnref(cfg);
virObjectUnref(caps);
return ret;
@@ -8872,7 +8849,7 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom,
virDomainDeviceDefPtr dev = NULL, dev_copy = NULL;
bool force = (flags & VIR_DOMAIN_DEVICE_MODIFY_FORCE) != 0;
int ret = -1;
- virQEMUDriverConfigPtr cfg = NULL;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
virCapsPtr caps = NULL;
unsigned int parse_flags = 0;
@@ -8973,7 +8950,6 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom,
virDomainDeviceDefFree(dev);
virDomainObjEndAPI(&vm);
virObjectUnref(caps);
- virObjectUnref(cfg);
virNWFilterUnlockFilterUpdates();
return ret;
}
@@ -8986,7 +8962,7 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr driver,
{
qemuDomainObjPrivatePtr priv = vm->privateData;
virCapsPtr caps = NULL;
- virQEMUDriverConfigPtr cfg = NULL;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
virDomainDeviceDefPtr dev = NULL, dev_copy = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE;
virDomainDefPtr vmdef = NULL;
@@ -9065,7 +9041,6 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr driver,
cleanup:
virObjectUnref(caps);
- virObjectUnref(cfg);
if (dev != dev_copy)
virDomainDeviceDefFree(dev_copy);
virDomainDeviceDefFree(dev);
@@ -9082,7 +9057,7 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDriverPtr driver,
{
qemuDomainObjPrivatePtr priv = vm->privateData;
virCapsPtr caps = NULL;
- virQEMUDriverConfigPtr cfg = NULL;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
virDomainDefPtr def = NULL;
virDomainDefPtr persistentDef = NULL;
virDomainDefPtr vmdef = NULL;
@@ -9143,7 +9118,6 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDriverPtr driver,
ret = 0;
cleanup:
virDomainDefFree(vmdef);
- virObjectUnref(cfg);
virObjectUnref(caps);
return ret;
}
@@ -9252,7 +9226,7 @@ static int qemuDomainSetAutostart(virDomainPtr dom,
virDomainObjPtr vm;
char *configFile = NULL, *autostartLink = NULL;
int ret = -1;
- virQEMUDriverConfigPtr cfg = NULL;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
if (!(vm = qemuDomainObjFromDomain(dom)))
return -1;
@@ -9317,7 +9291,6 @@ static int qemuDomainSetAutostart(virDomainPtr dom,
VIR_FREE(configFile);
VIR_FREE(autostartLink);
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
@@ -9564,7 +9537,7 @@ qemuDomainSetBlkioParameters(virDomainPtr dom,
virDomainDefPtr def;
virDomainDefPtr persistentDef;
int ret = -1;
- virQEMUDriverConfigPtr cfg = NULL;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
qemuDomainObjPrivatePtr priv;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
@@ -9764,7 +9737,6 @@ qemuDomainSetBlkioParameters(virDomainPtr dom,
cleanup:
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
@@ -9876,7 +9848,7 @@ qemuDomainSetMemoryParameters(virDomainPtr dom,
bool set_swap_hard_limit = false;
bool set_hard_limit = false;
bool set_soft_limit = false;
- virQEMUDriverConfigPtr cfg = NULL;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
int rc;
int ret = -1;
qemuDomainObjPrivatePtr priv;
@@ -10001,7 +9973,6 @@ qemuDomainSetMemoryParameters(virDomainPtr dom,
cleanup:
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
--
2.21.0