virCapsPtr 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 virCapsPtr declarations to use VIR_AUTOUNREF().
'cleanup' labels were deleted when possible.
Suggested-by: Erik Skultety <eskultet(a)redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/qemu/qemu_driver.c | 113 ++++++++++++++---------------------------
1 file changed, 37 insertions(+), 76 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d9effd7f34..99923b0ab6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -396,7 +396,7 @@ qemuDomainSnapshotLoad(virDomainObjPtr vm,
VIR_DOMAIN_SNAPSHOT_PARSE_DISKS |
VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL);
int ret = -1;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
int direrr;
qemuDomainObjPrivatePtr priv;
@@ -495,7 +495,6 @@ qemuDomainSnapshotLoad(virDomainObjPtr vm,
cleanup:
VIR_DIR_CLOSE(dir);
VIR_FREE(snapDir);
- virObjectUnref(caps);
virObjectUnlock(vm);
return ret;
}
@@ -516,7 +515,7 @@ qemuDomainCheckpointLoad(virDomainObjPtr vm,
virDomainMomentObjPtr current = NULL;
unsigned int flags = VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE;
int ret = -1;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
int direrr;
qemuDomainObjPrivatePtr priv;
@@ -606,7 +605,6 @@ qemuDomainCheckpointLoad(virDomainObjPtr vm,
cleanup:
VIR_DIR_CLOSE(dir);
VIR_FREE(chkDir);
- virObjectUnref(caps);
virObjectUnlock(vm);
return ret;
}
@@ -1072,13 +1070,13 @@ static int
qemuStateReload(void)
{
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
if (!qemu_driver)
return 0;
if (!(caps = virQEMUDriverGetCapabilities(qemu_driver, false)))
- goto cleanup;
+ return 0;
cfg = virQEMUDriverGetConfig(qemu_driver);
virDomainObjListLoadAllConfigs(qemu_driver->domains,
@@ -1086,8 +1084,6 @@ qemuStateReload(void)
cfg->autostartDir, false,
caps, qemu_driver->xmlopt,
qemuNotifyLoadDomain, qemu_driver);
- cleanup:
- virObjectUnref(caps);
return 0;
}
@@ -1356,21 +1352,15 @@ qemuConnectGetMaxVcpus(virConnectPtr conn G_GNUC_UNUSED, const
char *type)
static char *qemuConnectGetCapabilities(virConnectPtr conn) {
virQEMUDriverPtr driver = conn->privateData;
- virCapsPtr caps = NULL;
- char *xml = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
if (virConnectGetCapabilitiesEnsureACL(conn) < 0)
return NULL;
if (!(caps = virQEMUDriverGetCapabilities(driver, true)))
- goto cleanup;
-
- xml = virCapabilitiesFormatXML(caps);
- virObjectUnref(caps);
-
- cleanup:
+ return NULL;
- return xml;
+ return virCapabilitiesFormatXML(caps);
}
@@ -1716,27 +1706,22 @@ static int qemuDomainIsUpdated(virDomainPtr dom)
static int qemuConnectGetVersion(virConnectPtr conn, unsigned long *version)
{
virQEMUDriverPtr driver = conn->privateData;
- int ret = -1;
unsigned int qemuVersion = 0;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
if (virConnectGetVersionEnsureACL(conn) < 0)
return -1;
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
- goto cleanup;
+ return -1;
if (virQEMUCapsGetDefaultVersion(caps,
driver->qemuCapsCache,
&qemuVersion) < 0)
- goto cleanup;
+ return -1;
*version = qemuVersion;
- ret = 0;
-
- cleanup:
- virObjectUnref(caps);
- return ret;
+ return 0;
}
@@ -1789,7 +1774,7 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn,
virObjectEventPtr event = NULL;
virObjectEventPtr event2 = NULL;
unsigned int start_flags = VIR_QEMU_PROCESS_START_COLD;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE |
VIR_DOMAIN_DEF_PARSE_ABI_UPDATE;
@@ -1864,7 +1849,6 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn,
virDomainObjEndAPI(&vm);
virObjectEventStateQueue(driver->domainEventState, event);
virObjectEventStateQueue(driver->domainEventState, event2);
- virObjectUnref(caps);
virNWFilterUnlockFilterUpdates();
return dom;
}
@@ -3324,7 +3308,7 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver,
int ret = -1;
virObjectEventPtr event = NULL;
qemuDomainObjPrivatePtr priv = vm->privateData;
- virCapsPtr caps;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
virQEMUSaveDataPtr data = NULL;
qemuDomainSaveCookiePtr cookie = NULL;
@@ -3439,7 +3423,6 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver,
VIR_FREE(xml);
virQEMUSaveDataFree(data);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(caps);
return ret;
}
@@ -6604,29 +6587,27 @@ static int qemuNodeGetSecurityModel(virConnectPtr conn,
{
virQEMUDriverPtr driver = conn->privateData;
char *p;
- int ret = 0;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
memset(secmodel, 0, sizeof(*secmodel));
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
- goto cleanup;
+ return 0;
if (virNodeGetSecurityModelEnsureACL(conn) < 0)
- goto cleanup;
+ return 0;
/* We treat no driver as success, but simply return no data in *secmodel */
if (caps->host.nsecModels == 0 ||
caps->host.secModels[0].model == NULL)
- goto cleanup;
+ return 0;
p = caps->host.secModels[0].model;
if (strlen(p) >= VIR_SECURITY_MODEL_BUFLEN-1) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("security model string exceeds max %d bytes"),
VIR_SECURITY_MODEL_BUFLEN-1);
- ret = -1;
- goto cleanup;
+ return -1;
}
strcpy(secmodel->model, p);
@@ -6635,14 +6616,11 @@ static int qemuNodeGetSecurityModel(virConnectPtr conn,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("security DOI string exceeds max %d bytes"),
VIR_SECURITY_DOI_BUFLEN-1);
- ret = -1;
- goto cleanup;
+ return -1;
}
strcpy(secmodel->doi, p);
- cleanup:
- virObjectUnref(caps);
- return ret;
+ return 0;
}
@@ -6663,7 +6641,7 @@ qemuDomainSaveImageUpdateDef(virQEMUDriverPtr driver,
virDomainDefPtr ret = NULL;
virDomainDefPtr newdef_migr = NULL;
virDomainDefPtr newdef = NULL;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup;
@@ -6701,7 +6679,6 @@ qemuDomainSaveImageUpdateDef(virQEMUDriverPtr driver,
}
cleanup:
- virObjectUnref(caps);
virDomainDefFree(newdef);
virDomainDefFree(newdef_migr);
@@ -6741,7 +6718,7 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver,
virQEMUSaveHeaderPtr header;
virDomainDefPtr def = NULL;
int oflags = open_write ? O_RDWR : O_RDONLY;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
size_t xml_len;
size_t cookie_len;
@@ -6861,7 +6838,6 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver,
*ret_data = data;
cleanup:
- virObjectUnref(caps);
return fd;
error:
@@ -7435,7 +7411,7 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
char *ret = NULL;
size_t i;
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
virCheckFlags(0, NULL);
@@ -7497,7 +7473,6 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
cleanup:
virCommandFree(cmd);
virObjectUnref(vm);
- virObjectUnref(caps);
return ret;
}
@@ -7685,7 +7660,7 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
virDomainPtr dom = NULL;
virObjectEventPtr event = NULL;
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE |
VIR_DOMAIN_DEF_PARSE_ABI_UPDATE;
@@ -7749,7 +7724,6 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
virDomainDefFree(def);
virDomainObjEndAPI(&vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(caps);
return dom;
}
@@ -8721,7 +8695,7 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm,
virDomainDeviceDefPtr devConf = NULL;
virDomainDeviceDefPtr devLive = NULL;
int ret = -1;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE |
VIR_DOMAIN_DEF_PARSE_ABI_UPDATE;
@@ -8802,7 +8776,6 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm,
virDomainDefFree(vmdef);
virDomainDeviceDefFree(devConf);
virDomainDeviceDefFree(devLive);
- virObjectUnref(caps);
return ret;
}
@@ -8863,7 +8836,7 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom,
bool force = (flags & VIR_DOMAIN_DEVICE_MODIFY_FORCE) != 0;
int ret = -1;
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
unsigned int parse_flags = 0;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
@@ -8962,7 +8935,6 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom,
virDomainDeviceDefFree(dev_copy);
virDomainDeviceDefFree(dev);
virDomainObjEndAPI(&vm);
- virObjectUnref(caps);
virNWFilterUnlockFilterUpdates();
return ret;
}
@@ -8974,7 +8946,7 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr driver,
unsigned int flags)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
virDomainDeviceDefPtr dev = NULL, dev_copy = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE;
@@ -9053,7 +9025,6 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr driver,
ret = 0;
cleanup:
- virObjectUnref(caps);
if (dev != dev_copy)
virDomainDeviceDefFree(dev_copy);
virDomainDeviceDefFree(dev);
@@ -9069,7 +9040,7 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDriverPtr driver,
unsigned int flags)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
virDomainDefPtr def = NULL;
virDomainDefPtr persistentDef = NULL;
@@ -9131,7 +9102,6 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDriverPtr driver,
ret = 0;
cleanup:
virDomainDefFree(vmdef);
- virObjectUnref(caps);
return ret;
}
@@ -10645,7 +10615,7 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
int ret = -1;
int rc;
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
qemuDomainObjPrivatePtr priv;
virObjectEventPtr event = NULL;
virTypedParameterPtr eventParams = NULL;
@@ -10937,7 +10907,6 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
virDomainObjEndAPI(&vm);
if (eventNparams)
virTypedParamsFree(eventParams, eventNparams);
- virObjectUnref(caps);
return ret;
}
#undef SCHED_RANGE_CHECK
@@ -13549,27 +13518,22 @@ qemuConnectCompareCPU(virConnectPtr conn,
unsigned int flags)
{
virQEMUDriverPtr driver = conn->privateData;
- int ret = VIR_CPU_COMPARE_ERROR;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
bool failIncompatible;
virCheckFlags(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE,
VIR_CPU_COMPARE_ERROR);
if (virConnectCompareCPUEnsureACL(conn) < 0)
- goto cleanup;
+ return VIR_CPU_COMPARE_ERROR;
failIncompatible = !!(flags & VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE);
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
- goto cleanup;
-
- ret = virCPUCompareXML(caps->host.arch, caps->host.cpu,
- xmlDesc, failIncompatible);
+ return VIR_CPU_COMPARE_ERROR;
- cleanup:
- virObjectUnref(caps);
- return ret;
+ return virCPUCompareXML(caps->host.arch, caps->host.cpu,
+ xmlDesc, failIncompatible);
}
@@ -15892,7 +15856,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
int align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
bool align_match = true;
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
qemuDomainObjPrivatePtr priv;
virDomainSnapshotState state;
VIR_AUTOUNREF(virDomainSnapshotDefPtr) def = NULL;
@@ -16164,7 +16128,6 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
cleanup:
virDomainObjEndAPI(&vm);
VIR_FREE(xml);
- virObjectUnref(caps);
return snapshot;
}
@@ -16575,7 +16538,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
virDomainDefPtr config = NULL;
virDomainDefPtr inactiveConfig = NULL;
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
bool was_stopped = false;
qemuDomainSaveCookiePtr cookie;
virCPUDefPtr origCPU = NULL;
@@ -16992,7 +16955,6 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
virObjectEventStateQueue(driver->domainEventState, event);
virObjectEventStateQueue(driver->domainEventState, event2);
virDomainObjEndAPI(&vm);
- virObjectUnref(caps);
virNWFilterUnlockFilterUpdates();
virCPUDefFree(origCPU);
virDomainDefFree(config);
@@ -19659,7 +19621,7 @@ qemuDomainSetMetadata(virDomainPtr dom,
virQEMUDriverPtr driver = dom->conn->privateData;
virDomainObjPtr vm;
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
int ret = -1;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
@@ -19693,7 +19655,6 @@ qemuDomainSetMetadata(virDomainPtr dom,
cleanup:
virDomainObjEndAPI(&vm);
- virObjectUnref(caps);
return ret;
}
--
2.21.0