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.
Note: there is a g_autofree GLib macro being used in
qemuDomainUndefineFlags. In this particular instance we're
using g_autoptr() instead of VIR_AUTOUNREF() to not mix-up VIR_*
and GLib macros in that method.
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 1bd9609761..9f9443f493 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4571,7 +4571,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;
@@ -4670,7 +4670,6 @@ processNicRxFilterChangedEvent(virQEMUDriverPtr driver,
cleanup:
virNetDevRxFilterFree(hostFilter);
virNetDevRxFilterFree(guestFilter);
- virObjectUnref(cfg);
}
@@ -4680,7 +4679,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;
@@ -4713,7 +4712,7 @@ processSerialChangedEvent(virQEMUDriverPtr driver,
}
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
- goto cleanup;
+ return;
if (!virDomainObjIsActive(vm)) {
VIR_DEBUG("Domain is not running");
@@ -4754,9 +4753,6 @@ processSerialChangedEvent(virQEMUDriverPtr driver,
endjob:
qemuDomainObjEndJob(driver, vm);
-
- cleanup:
- virObjectUnref(cfg);
}
@@ -5029,21 +5025,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 &&
@@ -5052,23 +5047,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;
}
@@ -5233,7 +5224,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);
@@ -5290,7 +5281,6 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
cleanup:
virDomainObjEndAPI(&vm);
virBitmapFree(pcpumap);
- virObjectUnref(cfg);
return ret;
}
@@ -5353,7 +5343,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;
@@ -5447,7 +5437,6 @@ qemuDomainPinEmulator(virDomainPtr dom,
VIR_FREE(str);
virBitmapFree(pcpumap);
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
@@ -5818,7 +5807,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;
@@ -5942,7 +5931,6 @@ qemuDomainPinIOThread(virDomainPtr dom,
VIR_FREE(str);
virBitmapFree(pcpumap);
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
@@ -6291,7 +6279,7 @@ qemuDomainChgIOThread(virQEMUDriverPtr driver,
virDomainIOThreadAction action,
unsigned int flags)
{
- virQEMUDriverConfigPtr cfg = NULL;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
qemuDomainObjPrivatePtr priv;
virDomainDefPtr def;
virDomainDefPtr persistentDef;
@@ -6302,7 +6290,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;
@@ -6390,8 +6378,6 @@ qemuDomainChgIOThread(virQEMUDriverPtr driver,
endjob:
qemuDomainObjEndJob(driver, vm);
- cleanup:
- virObjectUnref(cfg);
return ret;
}
@@ -6902,7 +6888,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;
@@ -7024,7 +7010,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;
}
@@ -7449,13 +7434,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;
@@ -7515,7 +7498,6 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
virCommandFree(cmd);
virObjectUnref(vm);
virObjectUnref(caps);
- virObjectUnref(cfg);
return ret;
}
@@ -7702,7 +7684,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;
@@ -7712,8 +7694,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;
@@ -7770,7 +7750,6 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
virDomainObjEndAPI(&vm);
virObjectEventStateQueue(driver->domainEventState, event);
virObjectUnref(caps);
- virObjectUnref(cfg);
return dom;
}
@@ -7791,7 +7770,7 @@ qemuDomainUndefineFlags(virDomainPtr dom,
int ret = -1;
int nsnapshots;
int ncheckpoints;
- virQEMUDriverConfigPtr cfg = NULL;
+ g_autoptr(virQEMUDriverConfig) cfg = NULL;
g_autofree char *nvram_path = NULL;
virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE |
@@ -7919,7 +7898,6 @@ qemuDomainUndefineFlags(virDomainPtr dom,
VIR_FREE(name);
virDomainObjEndAPI(&vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
return ret;
}
@@ -8739,7 +8717,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;
@@ -8824,7 +8802,6 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm,
virDomainDefFree(vmdef);
virDomainDeviceDefFree(devConf);
virDomainDeviceDefFree(devLive);
- virObjectUnref(cfg);
virObjectUnref(caps);
return ret;
@@ -8885,7 +8862,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;
@@ -8986,7 +8963,6 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom,
virDomainDeviceDefFree(dev);
virDomainObjEndAPI(&vm);
virObjectUnref(caps);
- virObjectUnref(cfg);
virNWFilterUnlockFilterUpdates();
return ret;
}
@@ -8999,7 +8975,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;
@@ -9078,7 +9054,6 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr driver,
cleanup:
virObjectUnref(caps);
- virObjectUnref(cfg);
if (dev != dev_copy)
virDomainDeviceDefFree(dev_copy);
virDomainDeviceDefFree(dev);
@@ -9095,7 +9070,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;
@@ -9156,7 +9131,6 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDriverPtr driver,
ret = 0;
cleanup:
virDomainDefFree(vmdef);
- virObjectUnref(cfg);
virObjectUnref(caps);
return ret;
}
@@ -9265,7 +9239,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;
@@ -9330,7 +9304,6 @@ static int qemuDomainSetAutostart(virDomainPtr dom,
VIR_FREE(configFile);
VIR_FREE(autostartLink);
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
@@ -9577,7 +9550,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 |
@@ -9777,7 +9750,6 @@ qemuDomainSetBlkioParameters(virDomainPtr dom,
cleanup:
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
@@ -9889,7 +9861,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;
@@ -10014,7 +9986,6 @@ qemuDomainSetMemoryParameters(virDomainPtr dom,
cleanup:
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
--
2.21.0