Change all feasible vir*Ptr pointers to be AUTOUNREF(), clearing
up the 'cleanup' labels when possible.
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/qemu/qemu_process.c | 295 +++++++++++++++-------------------------
1 file changed, 109 insertions(+), 186 deletions(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 14208ae996..3194b4da74 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -108,11 +108,10 @@ qemuProcessRemoveDomainStatus(virQEMUDriverPtr driver,
char ebuf[1024];
VIR_AUTOFREE(char *) file = NULL;
qemuDomainObjPrivatePtr priv = vm->privateData;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
- int ret = -1;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
if (virAsprintf(&file, "%s/%s.xml", cfg->stateDir,
vm->def->name) < 0)
- goto cleanup;
+ return -1;
if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
VIR_WARN("Failed to remove domain XML for %s: %s",
@@ -124,10 +123,7 @@ qemuProcessRemoveDomainStatus(virQEMUDriverPtr driver,
VIR_WARN("Failed to remove PID file for %s: %s",
vm->def->name, virStrerror(errno, ebuf, sizeof(ebuf)));
- ret = 0;
- cleanup:
- virObjectUnref(cfg);
- return ret;
+ return 0;
}
@@ -407,7 +403,7 @@ qemuProcessHandleReset(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virQEMUDriverPtr driver = opaque;
virObjectEventPtr event;
qemuDomainObjPrivatePtr priv;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
int ret = -1;
virObjectLock(vm);
@@ -444,7 +440,6 @@ qemuProcessHandleReset(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
cleanup:
virObjectUnlock(vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
return ret;
}
@@ -463,7 +458,7 @@ qemuProcessFakeReboot(void *opaque)
virDomainObjPtr vm = opaque;
qemuDomainObjPrivatePtr priv = vm->privateData;
virQEMUDriverPtr driver = priv->driver;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
virDomainRunningReason reason = VIR_DOMAIN_RUNNING_BOOTED;
int ret = -1, rc;
@@ -513,7 +508,6 @@ qemuProcessFakeReboot(void *opaque)
if (ret == -1)
ignore_value(qemuProcessKill(vm, VIR_QEMU_PROCESS_KILL_FORCE));
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
}
@@ -576,7 +570,7 @@ qemuProcessHandleShutdown(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virQEMUDriverPtr driver = opaque;
qemuDomainObjPrivatePtr priv;
virObjectEventPtr event = NULL;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
int detail = 0;
VIR_DEBUG("vm=%p", vm);
@@ -633,7 +627,6 @@ qemuProcessHandleShutdown(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
unlock:
virObjectUnlock(vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
return 0;
}
@@ -648,7 +641,7 @@ qemuProcessHandleStop(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virObjectEventPtr event = NULL;
virDomainPausedReason reason;
virDomainEventSuspendedDetailType detail;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
qemuDomainObjPrivatePtr priv = vm->privateData;
virObjectLock(vm);
@@ -694,7 +687,6 @@ qemuProcessHandleStop(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virObjectUnlock(vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
return 0;
}
@@ -707,7 +699,7 @@ qemuProcessHandleResume(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
{
virQEMUDriverPtr driver = opaque;
virObjectEventPtr event = NULL;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
qemuDomainObjPrivatePtr priv;
virDomainRunningReason reason = VIR_DOMAIN_RUNNING_UNPAUSED;
virDomainEventResumedDetailType eventDetail;
@@ -740,7 +732,6 @@ qemuProcessHandleResume(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virObjectUnlock(vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
return 0;
}
@@ -752,7 +743,7 @@ qemuProcessHandleRTCChange(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
{
virQEMUDriverPtr driver = opaque;
virObjectEventPtr event = NULL;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
virObjectLock(vm);
@@ -784,7 +775,6 @@ qemuProcessHandleRTCChange(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virObjectUnlock(vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
return 0;
}
@@ -798,7 +788,7 @@ qemuProcessHandleWatchdog(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virQEMUDriverPtr driver = opaque;
virObjectEventPtr watchdogEvent = NULL;
virObjectEventPtr lifecycleEvent = NULL;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
virObjectLock(vm);
watchdogEvent = virDomainEventWatchdogNewFromObj(vm, action);
@@ -846,7 +836,6 @@ qemuProcessHandleWatchdog(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virObjectEventStateQueue(driver->domainEventState, watchdogEvent);
virObjectEventStateQueue(driver->domainEventState, lifecycleEvent);
- virObjectUnref(cfg);
return 0;
}
@@ -867,7 +856,7 @@ qemuProcessHandleIOError(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
const char *srcPath;
const char *devAlias;
virDomainDiskDefPtr disk;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
virObjectLock(vm);
@@ -918,7 +907,6 @@ qemuProcessHandleIOError(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virObjectEventStateQueue(driver->domainEventState, ioErrorEvent);
virObjectEventStateQueue(driver->domainEventState, ioErrorEvent2);
virObjectEventStateQueue(driver->domainEventState, lifecycleEvent);
- virObjectUnref(cfg);
return 0;
}
@@ -1147,7 +1135,7 @@ qemuProcessHandleTrayChange(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virQEMUDriverPtr driver = opaque;
virObjectEventPtr event = NULL;
virDomainDiskDefPtr disk;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
virObjectLock(vm);
disk = qemuProcessFindDomainDiskByAliasOrQOM(vm, devAlias, devid);
@@ -1170,7 +1158,6 @@ qemuProcessHandleTrayChange(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virObjectUnlock(vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
return 0;
}
@@ -1182,7 +1169,7 @@ qemuProcessHandlePMWakeup(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virQEMUDriverPtr driver = opaque;
virObjectEventPtr event = NULL;
virObjectEventPtr lifecycleEvent = NULL;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
virObjectLock(vm);
event = virDomainEventPMWakeupNewFromObj(vm);
@@ -1209,7 +1196,6 @@ qemuProcessHandlePMWakeup(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virObjectUnlock(vm);
virObjectEventStateQueue(driver->domainEventState, event);
virObjectEventStateQueue(driver->domainEventState, lifecycleEvent);
- virObjectUnref(cfg);
return 0;
}
@@ -1221,7 +1207,7 @@ qemuProcessHandlePMSuspend(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virQEMUDriverPtr driver = opaque;
virObjectEventPtr event = NULL;
virObjectEventPtr lifecycleEvent = NULL;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
virObjectLock(vm);
event = virDomainEventPMSuspendNewFromObj(vm);
@@ -1251,7 +1237,6 @@ qemuProcessHandlePMSuspend(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virObjectEventStateQueue(driver->domainEventState, event);
virObjectEventStateQueue(driver->domainEventState, lifecycleEvent);
- virObjectUnref(cfg);
return 0;
}
@@ -1263,7 +1248,7 @@ qemuProcessHandleBalloonChange(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
{
virQEMUDriverPtr driver = opaque;
virObjectEventPtr event = NULL;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
virObjectLock(vm);
event = virDomainEventBalloonChangeNewFromObj(vm, actual);
@@ -1278,7 +1263,6 @@ qemuProcessHandleBalloonChange(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virObjectUnlock(vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
return 0;
}
@@ -1290,7 +1274,7 @@ qemuProcessHandlePMSuspendDisk(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virQEMUDriverPtr driver = opaque;
virObjectEventPtr event = NULL;
virObjectEventPtr lifecycleEvent = NULL;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
virObjectLock(vm);
event = virDomainEventPMSuspendDiskNewFromObj(vm);
@@ -1320,7 +1304,6 @@ qemuProcessHandlePMSuspendDisk(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virObjectEventStateQueue(driver->domainEventState, event);
virObjectEventStateQueue(driver->domainEventState, lifecycleEvent);
- virObjectUnref(cfg);
return 0;
}
@@ -1651,7 +1634,7 @@ qemuProcessHandleMigrationStatus(qemuMonitorPtr mon
ATTRIBUTE_UNUSED,
qemuDomainObjPrivatePtr priv;
virQEMUDriverPtr driver = opaque;
virObjectEventPtr event = NULL;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
int reason;
virObjectLock(vm);
@@ -1690,7 +1673,6 @@ qemuProcessHandleMigrationStatus(qemuMonitorPtr mon
ATTRIBUTE_UNUSED,
cleanup:
virObjectUnlock(vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
return 0;
}
@@ -2750,9 +2732,8 @@ static int
qemuProcessResctrlCreate(virQEMUDriverPtr driver,
virDomainObjPtr vm)
{
- int ret = -1;
size_t i = 0;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
qemuDomainObjPrivatePtr priv = vm->privateData;
if (!vm->def->nresctrls)
@@ -2769,7 +2750,7 @@ qemuProcessResctrlCreate(virQEMUDriverPtr driver,
if (virResctrlAllocCreate(caps->host.resctrl,
vm->def->resctrls[i]->alloc,
priv->machineName) < 0)
- goto cleanup;
+ return -1;
for (j = 0; j < vm->def->resctrls[i]->nmonitors; j++) {
virDomainResctrlMonDefPtr mon = NULL;
@@ -2777,14 +2758,11 @@ qemuProcessResctrlCreate(virQEMUDriverPtr driver,
mon = vm->def->resctrls[i]->monitors[j];
if (virResctrlMonitorCreate(mon->instance,
priv->machineName) < 0)
- goto cleanup;
+ return -1;
}
}
- ret = 0;
- cleanup:
- virObjectUnref(caps);
- return ret;
+ return 0;
}
@@ -2857,7 +2835,7 @@ qemuProcessStartManagedPRDaemon(virDomainObjPtr vm)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
virQEMUDriverPtr driver = priv->driver;
- virQEMUDriverConfigPtr cfg;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
int errfd = -1;
VIR_AUTOFREE(char *) pidfile = NULL;
int pidfd = -1;
@@ -2969,7 +2947,6 @@ qemuProcessStartManagedPRDaemon(virDomainObjPtr vm)
virCommandFree(cmd);
VIR_FORCE_CLOSE(pidfd);
VIR_FORCE_CLOSE(errfd);
- virObjectUnref(cfg);
return ret;
}
@@ -2980,7 +2957,7 @@ qemuProcessInitPasswords(virQEMUDriverPtr driver,
int asyncJob)
{
int ret = 0;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
size_t i;
for (i = 0; i < vm->def->ngraphics; ++i) {
@@ -3000,11 +2977,9 @@ qemuProcessInitPasswords(virQEMUDriverPtr driver,
}
if (ret < 0)
- goto cleanup;
+ return ret;
}
- cleanup:
- virObjectUnref(cfg);
return ret;
}
@@ -3065,7 +3040,7 @@ qemuProcessUpdateVideoRamSize(virQEMUDriverPtr driver,
ssize_t i;
qemuDomainObjPrivatePtr priv = vm->privateData;
virDomainVideoDefPtr video = NULL;
- virQEMUDriverConfigPtr cfg = NULL;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
return -1;
@@ -3124,7 +3099,6 @@ qemuProcessUpdateVideoRamSize(virQEMUDriverPtr driver,
cfg = virQEMUDriverGetConfig(driver);
ret = virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps);
- virObjectUnref(cfg);
return ret;
@@ -3231,11 +3205,11 @@ qemuProcessStartCPUs(virQEMUDriverPtr driver, virDomainObjPtr vm,
{
int ret = -1;
qemuDomainObjPrivatePtr priv = vm->privateData;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
/* Bring up netdevs before starting CPUs */
if (qemuInterfaceStartDevices(vm->def) < 0)
- goto cleanup;
+ return -1;
VIR_DEBUG("Using lock state '%s'", NULLSTR(priv->lockState));
if (virDomainLockProcessResume(driver->lockManager, cfg->uri,
@@ -3244,7 +3218,7 @@ qemuProcessStartCPUs(virQEMUDriverPtr driver, virDomainObjPtr vm,
* to make sure we have state still present if the user
* tries to resume again
*/
- goto cleanup;
+ return -1;
}
VIR_FREE(priv->lockState);
@@ -3265,8 +3239,6 @@ qemuProcessStartCPUs(virQEMUDriverPtr driver, virDomainObjPtr vm,
* lifecycle event.
*/
- cleanup:
- virObjectUnref(cfg);
return ret;
release:
@@ -3274,7 +3246,7 @@ qemuProcessStartCPUs(virQEMUDriverPtr driver, virDomainObjPtr vm,
if (virDomainLockProcessPause(driver->lockManager, vm, &priv->lockState)
< 0)
VIR_WARN("Unable to release lease on %s", vm->def->name);
VIR_DEBUG("Preserving lock state '%s'",
NULLSTR(priv->lockState));
- goto cleanup;
+ return ret;
}
@@ -3328,7 +3300,7 @@ static void
qemuProcessNotifyNets(virDomainDefPtr def)
{
size_t i;
- virConnectPtr conn = NULL;
+ VIR_AUTOUNREF(virConnectPtr) conn = NULL;
for (i = 0; i < def->nnets; i++) {
virDomainNetDefPtr net = def->nets[i];
@@ -3346,8 +3318,6 @@ qemuProcessNotifyNets(virDomainDefPtr def)
virDomainNetNotifyActualDevice(conn, def, net);
}
}
-
- virObjectUnref(conn);
}
/* Attempt to instantiate the filters. Ignore failures because it's
@@ -3872,12 +3842,11 @@ qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver,
virDomainMemoryDefPtr mem,
bool build)
{
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
VIR_AUTOFREE(char *) path = NULL;
size_t i;
bool shouldBuildHP = false;
bool shouldBuildMB = false;
- int ret = -1;
if (build) {
shouldBuildHP = qemuProcessNeedHugepagesPath(vm->def, mem);
@@ -3889,11 +3858,11 @@ qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver,
path = qemuGetDomainHugepagePath(vm->def, &cfg->hugetlbfs[i]);
if (!path)
- goto cleanup;
+ return -1;
if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm,
path, build) < 0)
- goto cleanup;
+ return -1;
VIR_FREE(path);
}
@@ -3901,17 +3870,14 @@ qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver,
if (!build || shouldBuildMB) {
if (qemuGetMemoryBackingDomainPath(vm->def, cfg, &path) < 0)
- goto cleanup;
+ return -1;
if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm,
path, build) < 0)
- goto cleanup;
+ return -1;
}
- ret = 0;
- cleanup:
- virObjectUnref(cfg);
- return ret;
+ return 0;
}
@@ -3920,23 +3886,19 @@ qemuProcessDestroyMemoryBackingPath(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainMemoryDefPtr mem)
{
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
VIR_AUTOFREE(char *) path = NULL;
- int ret = -1;
if (qemuGetMemoryBackingPath(vm->def, cfg, mem->info.alias, &path) < 0)
- goto cleanup;
+ return -1;
if (unlink(path) < 0 &&
errno != ENOENT) {
virReportSystemError(errno, _("Unable to remove %s"), path);
- goto cleanup;
+ return -1;
}
- ret = 0;
- cleanup:
- virObjectUnref(cfg);
- return ret;
+ return 0;
}
@@ -3975,12 +3937,11 @@ qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
virDomainGraphicsDefPtr graphics,
bool allocate)
{
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
unsigned short port = 0;
unsigned short tlsPort;
size_t i;
int defaultMode = graphics->data.spice.defaultMode;
- int ret = -1;
bool needTLSPort = false;
bool needPort = false;
@@ -4026,13 +3987,12 @@ qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
if (needTLSPort || graphics->data.spice.tlsPort == -1)
graphics->data.spice.tlsPort = 5902;
- ret = 0;
- goto cleanup;
+ return 0;
}
if (needPort || graphics->data.spice.port == -1) {
if (virPortAllocatorAcquire(driver->remotePorts, &port) < 0)
- goto cleanup;
+ return -1;
graphics->data.spice.port = port;
@@ -4045,11 +4005,11 @@ qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Auto allocation of spice TLS port requested "
"but spice TLS is disabled in qemu.conf"));
- goto cleanup;
+ return -1;
}
if (virPortAllocatorAcquire(driver->remotePorts, &tlsPort) < 0)
- goto cleanup;
+ return -1;
graphics->data.spice.tlsPort = tlsPort;
@@ -4057,11 +4017,7 @@ qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
graphics->data.spice.tlsPortReserved = true;
}
- ret = 0;
-
- cleanup:
- virObjectUnref(cfg);
- return ret;
+ return 0;
}
@@ -4748,9 +4704,9 @@ static int
qemuProcessGetNetworkAddress(const char *netname,
char **netaddr)
{
- virConnectPtr conn = NULL;
+ VIR_AUTOUNREF(virConnectPtr) conn = NULL;
int ret = -1;
- virNetworkPtr net;
+ VIR_AUTOUNREF(virNetworkPtr) net = NULL;
virNetworkDefPtr netdef = NULL;
virNetworkIPDefPtr ipdef;
virSocketAddr addr;
@@ -4836,8 +4792,6 @@ qemuProcessGetNetworkAddress(const char *netname,
ret = 0;
cleanup:
virNetworkDefFree(netdef);
- virObjectUnref(net);
- virObjectUnref(conn);
return ret;
}
@@ -4875,12 +4829,11 @@ qemuProcessGraphicsSetupListen(virQEMUDriverPtr driver,
virDomainObjPtr vm)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
const char *type = virDomainGraphicsTypeToString(graphics->type);
char *listenAddr = NULL;
bool useSocket = false;
size_t i;
- int ret = -1;
switch (graphics->type) {
case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
@@ -4914,12 +4867,12 @@ qemuProcessGraphicsSetupListen(virQEMUDriverPtr driver,
memset(glisten, 0, sizeof(virDomainGraphicsListenDef));
if (virAsprintf(&glisten->socket, "%s/%s.sock",
priv->libDir, type) < 0)
- goto cleanup;
+ return -1;
glisten->fromConfig = true;
glisten->type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET;
} else if (listenAddr) {
if (VIR_STRDUP(glisten->address, listenAddr) < 0)
- goto cleanup;
+ return -1;
glisten->fromConfig = true;
}
}
@@ -4931,14 +4884,14 @@ qemuProcessGraphicsSetupListen(virQEMUDriverPtr driver,
if (qemuProcessGraphicsSetupNetworkAddress(glisten,
listenAddr) < 0)
- goto cleanup;
+ return -1;
break;
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET:
if (!glisten->socket) {
if (virAsprintf(&glisten->socket, "%s/%s.sock",
priv->libDir, type) < 0)
- goto cleanup;
+ return -1;
glisten->autoGenerated = true;
}
break;
@@ -4949,11 +4902,7 @@ qemuProcessGraphicsSetupListen(virQEMUDriverPtr driver,
}
}
- ret = 0;
-
- cleanup:
- virObjectUnref(cfg);
- return ret;
+ return 0;
}
@@ -5585,7 +5534,7 @@ qemuProcessInit(virQEMUDriverPtr driver,
bool migration,
unsigned int flags)
{
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
qemuDomainObjPrivatePtr priv = vm->privateData;
int stopFlags;
virCPUDefPtr origCPU = NULL;
@@ -5668,7 +5617,6 @@ qemuProcessInit(virQEMUDriverPtr driver,
cleanup:
virCPUDefFree(origCPU);
- virObjectUnref(caps);
return ret;
stop:
@@ -5689,9 +5637,8 @@ qemuProcessNetworkPrepareDevices(virQEMUDriverPtr driver,
{
virDomainDefPtr def = vm->def;
qemuDomainObjPrivatePtr priv = vm->privateData;
- int ret = -1;
size_t i;
- virConnectPtr conn = NULL;
+ VIR_AUTOUNREF(virConnectPtr) conn = NULL;
for (i = 0; i < def->nnets; i++) {
virDomainNetDefPtr net = def->nets[i];
@@ -5703,9 +5650,9 @@ qemuProcessNetworkPrepareDevices(virQEMUDriverPtr driver,
*/
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
if (!conn && !(conn = virGetConnectNetwork()))
- goto cleanup;
+ return -1;
if (virDomainNetAllocateActualDevice(conn, def, net) < 0)
- goto cleanup;
+ return -1;
}
actualType = virDomainNetGetActualType(net);
@@ -5729,10 +5676,10 @@ qemuProcessNetworkPrepareDevices(virQEMUDriverPtr driver,
pcisrc->addr.domain, pcisrc->addr.bus,
pcisrc->addr.slot, pcisrc->addr.function,
net->data.network.name, def->name);
- goto cleanup;
+ return -1;
}
if (virDomainHostdevInsert(def, hostdev) < 0)
- goto cleanup;
+ return -1;
} else if (actualType == VIR_DOMAIN_NET_TYPE_USER &&
!priv->disableSlirp &&
virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DBUS_VMSTATE)) {
@@ -5742,10 +5689,7 @@ qemuProcessNetworkPrepareDevices(virQEMUDriverPtr driver,
}
}
- ret = 0;
- cleanup:
- virObjectUnref(conn);
- return ret;
+ return 0;
}
@@ -6249,18 +6193,17 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver,
virDomainObjPtr vm,
unsigned int flags)
{
- int ret = -1;
size_t i;
qemuDomainObjPrivatePtr priv = vm->privateData;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
- virCapsPtr caps;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
- goto cleanup;
+ return -1;
priv->machineName = qemuDomainGetMachineName(vm);
if (!priv->machineName)
- goto cleanup;
+ return -1;
if (!(flags & VIR_QEMU_PROCESS_START_PRETEND)) {
/* If you are using a SecurityDriver with dynamic labelling,
@@ -6268,12 +6211,12 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver,
VIR_DEBUG("Generating domain security label (if required)");
if (qemuSecurityGenLabel(driver->securityManager, vm->def) < 0) {
virDomainAuditSecurityLabel(vm, false);
- goto cleanup;
+ return -1;
}
virDomainAuditSecurityLabel(vm, true);
if (qemuProcessPrepareDomainNUMAPlacement(vm, caps) < 0)
- goto cleanup;
+ return -1;
}
/* Whether we should use virtlogd as stdio handler for character
@@ -6307,51 +6250,51 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver,
VIR_DEBUG("Assigning domain PCI addresses");
if ((qemuDomainAssignAddresses(vm->def, priv->qemuCaps, driver, vm,
!!(flags & VIR_QEMU_PROCESS_START_NEW))) < 0)
{
- goto cleanup;
+ return -1;
}
if (qemuAssignDeviceAliases(vm->def, priv->qemuCaps) < 0)
- goto cleanup;
+ return -1;
VIR_DEBUG("Setting graphics devices");
if (qemuProcessSetupGraphics(driver, vm, priv->qemuCaps, flags) < 0)
- goto cleanup;
+ return -1;
VIR_DEBUG("Create domain masterKey");
if (qemuDomainMasterKeyCreate(vm) < 0)
- goto cleanup;
+ return -1;
VIR_DEBUG("Setting up storage");
if (qemuProcessPrepareDomainStorage(driver, vm, priv, cfg, flags) < 0)
- goto cleanup;
+ return -1;
VIR_DEBUG("Prepare chardev source backends for TLS");
qemuDomainPrepareChardevSource(vm->def, cfg);
VIR_DEBUG("Prepare device secrets");
if (qemuDomainSecretPrepare(driver, vm) < 0)
- goto cleanup;
+ return -1;
VIR_DEBUG("Prepare bios/uefi paths");
if (qemuFirmwareFillDomain(driver, vm, flags) < 0)
- goto cleanup;
+ return -1;
VIR_DEBUG("Preparing external devices");
if (qemuExtDevicesPrepareDomain(driver, vm) < 0)
- goto cleanup;
+ return -1;
for (i = 0; i < vm->def->nchannels; i++) {
if (qemuDomainPrepareChannel(vm->def->channels[i],
priv->channelTargetDir) < 0)
- goto cleanup;
+ return -1;
}
if (!(priv->monConfig = virDomainChrSourceDefNew(driver->xmlopt)))
- goto cleanup;
+ return -1;
VIR_DEBUG("Preparing monitor state");
if (qemuProcessPrepareMonitorChr(priv->monConfig, priv->libDir) < 0)
- goto cleanup;
+ return -1;
priv->monError = false;
priv->monStart = 0;
@@ -6360,18 +6303,14 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver,
VIR_DEBUG("Updating guest CPU definition");
if (qemuProcessUpdateGuestCPU(vm->def, priv->qemuCaps, caps, flags) < 0)
- goto cleanup;
+ return -1;
for (i = 0; i < vm->def->nshmems; i++) {
if (qemuDomainPrepareShmemChardev(vm->def->shmems[i]) < 0)
- goto cleanup;
+ return -1;
}
- ret = 0;
- cleanup:
- virObjectUnref(caps);
- virObjectUnref(cfg);
- return ret;
+ return 0;
}
@@ -6523,17 +6462,16 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver,
virDomainObjPtr vm,
unsigned int flags)
{
- int ret = -1;
unsigned int hostdev_flags = 0;
qemuDomainObjPrivatePtr priv = vm->privateData;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
if (qemuPrepareNVRAM(cfg, vm) < 0)
- goto cleanup;
+ return -1;
if (vm->def->vsock) {
if (qemuProcessOpenVhostVsock(vm->def->vsock) < 0)
- goto cleanup;
+ return -1;
}
/* network devices must be "prepared" before hostdevs, because
* setting up a network device might create a new hostdev that
@@ -6541,7 +6479,7 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver,
*/
VIR_DEBUG("Preparing network devices");
if (qemuProcessNetworkPrepareDevices(driver, vm) < 0)
- goto cleanup;
+ return -1;
/* Must be run before security labelling */
VIR_DEBUG("Preparing host devices");
@@ -6551,17 +6489,17 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver,
hostdev_flags |= VIR_HOSTDEV_COLD_BOOT;
if (qemuHostdevPrepareDomainDevices(driver, vm->def, priv->qemuCaps,
hostdev_flags) < 0)
- goto cleanup;
+ return -1;
VIR_DEBUG("Preparing chr devices");
if (virDomainChrDefForeach(vm->def,
true,
qemuProcessPrepareChardevDevice,
NULL) < 0)
- goto cleanup;
+ return -1;
if (qemuProcessBuildDestroyMemoryPaths(driver, vm, NULL, true) < 0)
- goto cleanup;
+ return -1;
/* Ensure no historical cgroup for this VM is lying around bogus
* settings */
@@ -6572,14 +6510,14 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver,
virReportSystemError(errno,
_("cannot create log directory %s"),
cfg->logDir);
- goto cleanup;
+ return -1;
}
VIR_FREE(priv->pidfile);
if (!(priv->pidfile = virPidFileBuildPath(cfg->stateDir, vm->def->name)))
{
virReportSystemError(errno,
"%s", _("Failed to build pidfile
path."));
- goto cleanup;
+ return -1;
}
if (unlink(priv->pidfile) < 0 &&
@@ -6587,7 +6525,7 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver,
virReportSystemError(errno,
_("Cannot remove stale PID file %s"),
priv->pidfile);
- goto cleanup;
+ return -1;
}
/*
@@ -6596,27 +6534,24 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver,
*/
if (qemuProcessMakeDir(driver, vm, priv->libDir) < 0 ||
qemuProcessMakeDir(driver, vm, priv->channelTargetDir) < 0)
- goto cleanup;
+ return -1;
VIR_DEBUG("Write domain masterKey");
if (qemuDomainWriteMasterKeyFile(driver, vm) < 0)
- goto cleanup;
+ return -1;
VIR_DEBUG("Preparing disks (host)");
if (qemuProcessPrepareHostStorage(driver, vm, flags) < 0)
- goto cleanup;
+ return -1;
VIR_DEBUG("Preparing external devices");
if (qemuExtDevicesPrepareHost(driver, vm) < 0)
- goto cleanup;
+ return -1;
if (qemuProcessPrepareSEVGuestInput(vm) < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- virObjectUnref(cfg);
- return ret;
+ return 0;
}
@@ -6730,8 +6665,8 @@ qemuProcessLaunch(virConnectPtr conn,
qemuDomainObjPrivatePtr priv = vm->privateData;
virCommandPtr cmd = NULL;
struct qemuProcessHookData hookData;
- virQEMUDriverConfigPtr cfg;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
size_t nnicindexes = 0;
VIR_AUTOFREE(int *) nicindexes = NULL;
size_t i;
@@ -7046,8 +6981,6 @@ qemuProcessLaunch(virConnectPtr conn,
qemuDomainSecretDestroy(vm);
virCommandFree(cmd);
virObjectUnref(logCtxt);
- virObjectUnref(cfg);
- virObjectUnref(caps);
return ret;
}
@@ -7104,8 +7037,7 @@ qemuProcessFinishStartup(virQEMUDriverPtr driver,
bool startCPUs,
virDomainPausedReason pausedReason)
{
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
- int ret = -1;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
if (startCPUs) {
VIR_DEBUG("Starting domain CPUs");
@@ -7115,7 +7047,7 @@ qemuProcessFinishStartup(virQEMUDriverPtr driver,
if (virGetLastErrorCode() == VIR_ERR_OK)
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("resume operation failed"));
- goto cleanup;
+ return -1;
}
} else {
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, pausedReason);
@@ -7123,18 +7055,14 @@ qemuProcessFinishStartup(virQEMUDriverPtr driver,
VIR_DEBUG("Writing domain status to disk");
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps)
< 0)
- goto cleanup;
+ return -1;
if (qemuProcessStartHook(driver, vm,
VIR_HOOK_QEMU_OP_STARTED,
VIR_HOOK_SUBOP_BEGIN) < 0)
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- virObjectUnref(cfg);
- return ret;
+ return 0;
}
@@ -7373,8 +7301,8 @@ void qemuProcessStop(virQEMUDriverPtr driver,
virNetDevVPortProfilePtr vport = NULL;
size_t i;
VIR_AUTOFREE(char *) timestamp = NULL;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
- virConnectPtr conn = NULL;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
+ VIR_AUTOUNREF(virConnectPtr) conn = NULL;
VIR_DEBUG("Shutting down vm=%p name=%s id=%d pid=%lld, "
"reason=%s, asyncJob=%s, flags=0x%x",
@@ -7680,8 +7608,6 @@ void qemuProcessStop(virQEMUDriverPtr driver,
virSetError(orig_err);
virFreeError(orig_err);
}
- virObjectUnref(conn);
- virObjectUnref(cfg);
}
@@ -7816,7 +7742,7 @@ static int
qemuProcessRefreshCPU(virQEMUDriverPtr driver,
virDomainObjPtr vm)
{
- virCapsPtr caps = virQEMUDriverGetCapabilities(driver, false);
+ VIR_AUTOUNREF(virCapsPtr) caps = virQEMUDriverGetCapabilities(driver, false);
qemuDomainObjPrivatePtr priv = vm->privateData;
virCPUDefPtr host = NULL;
virCPUDefPtr cpu = NULL;
@@ -7867,7 +7793,6 @@ qemuProcessRefreshCPU(virQEMUDriverPtr driver,
cleanup:
virCPUDefFree(cpu);
virCPUDefFree(host);
- virObjectUnref(caps);
return ret;
}
@@ -8003,11 +7928,11 @@ qemuProcessReconnect(void *opaque)
qemuDomainJobObj oldjob;
int state;
int reason;
- virQEMUDriverConfigPtr cfg;
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
size_t i;
unsigned int stopFlags = 0;
bool jobStarted = false;
- virCapsPtr caps = NULL;
+ VIR_AUTOUNREF(virCapsPtr) caps = NULL;
bool retry = true;
bool tryMonReconn = false;
@@ -8251,8 +8176,6 @@ qemuProcessReconnect(void *opaque)
qemuDomainRemoveInactiveJob(driver, obj);
}
virDomainObjEndAPI(&obj);
- virObjectUnref(cfg);
- virObjectUnref(caps);
virNWFilterUnlockFilterUpdates();
virIdentitySetCurrent(NULL);
return;
--
2.21.0