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 | 316 +++++++++++++++-------------------------
1 file changed, 116 insertions(+), 200 deletions(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index f4b3144154..72919c370d 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 G_GNUC_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 G_GNUC_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 G_GNUC_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 G_GNUC_UNUSED,
unlock:
virObjectUnlock(vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
return 0;
}
@@ -648,7 +641,7 @@ qemuProcessHandleStop(qemuMonitorPtr mon G_GNUC_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 G_GNUC_UNUSED,
virObjectUnlock(vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
return 0;
}
@@ -707,7 +699,7 @@ qemuProcessHandleResume(qemuMonitorPtr mon G_GNUC_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 G_GNUC_UNUSED,
virObjectUnlock(vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
return 0;
}
@@ -752,7 +743,7 @@ qemuProcessHandleRTCChange(qemuMonitorPtr mon G_GNUC_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 G_GNUC_UNUSED,
virObjectUnlock(vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
return 0;
}
@@ -798,7 +788,7 @@ qemuProcessHandleWatchdog(qemuMonitorPtr mon G_GNUC_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 G_GNUC_UNUSED,
virObjectEventStateQueue(driver->domainEventState, watchdogEvent);
virObjectEventStateQueue(driver->domainEventState, lifecycleEvent);
- virObjectUnref(cfg);
return 0;
}
@@ -867,7 +856,7 @@ qemuProcessHandleIOError(qemuMonitorPtr mon G_GNUC_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 G_GNUC_UNUSED,
virObjectEventStateQueue(driver->domainEventState, ioErrorEvent);
virObjectEventStateQueue(driver->domainEventState, ioErrorEvent2);
virObjectEventStateQueue(driver->domainEventState, lifecycleEvent);
- virObjectUnref(cfg);
return 0;
}
@@ -1147,7 +1135,7 @@ qemuProcessHandleTrayChange(qemuMonitorPtr mon G_GNUC_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 G_GNUC_UNUSED,
virObjectUnlock(vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
return 0;
}
@@ -1182,7 +1169,7 @@ qemuProcessHandlePMWakeup(qemuMonitorPtr mon G_GNUC_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 G_GNUC_UNUSED,
virObjectUnlock(vm);
virObjectEventStateQueue(driver->domainEventState, event);
virObjectEventStateQueue(driver->domainEventState, lifecycleEvent);
- virObjectUnref(cfg);
return 0;
}
@@ -1221,7 +1207,7 @@ qemuProcessHandlePMSuspend(qemuMonitorPtr mon G_GNUC_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 G_GNUC_UNUSED,
virObjectEventStateQueue(driver->domainEventState, event);
virObjectEventStateQueue(driver->domainEventState, lifecycleEvent);
- virObjectUnref(cfg);
return 0;
}
@@ -1263,7 +1248,7 @@ qemuProcessHandleBalloonChange(qemuMonitorPtr mon G_GNUC_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 G_GNUC_UNUSED,
virObjectUnlock(vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
return 0;
}
@@ -1290,7 +1274,7 @@ qemuProcessHandlePMSuspendDisk(qemuMonitorPtr mon G_GNUC_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 G_GNUC_UNUSED,
virObjectEventStateQueue(driver->domainEventState, event);
virObjectEventStateQueue(driver->domainEventState, lifecycleEvent);
- virObjectUnref(cfg);
return 0;
}
@@ -1651,7 +1634,7 @@ qemuProcessHandleMigrationStatus(qemuMonitorPtr mon G_GNUC_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 G_GNUC_UNUSED,
cleanup:
virObjectUnlock(vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
return 0;
}
@@ -2735,9 +2717,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)
@@ -2754,7 +2735,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;
@@ -2762,14 +2743,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;
}
@@ -2842,7 +2820,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;
@@ -2954,7 +2932,6 @@ qemuProcessStartManagedPRDaemon(virDomainObjPtr vm)
virCommandFree(cmd);
VIR_FORCE_CLOSE(pidfd);
VIR_FORCE_CLOSE(errfd);
- virObjectUnref(cfg);
return ret;
}
@@ -2965,7 +2942,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) {
@@ -2985,11 +2962,9 @@ qemuProcessInitPasswords(virQEMUDriverPtr driver,
}
if (ret < 0)
- goto cleanup;
+ return ret;
}
- cleanup:
- virObjectUnref(cfg);
return ret;
}
@@ -3050,7 +3025,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;
@@ -3109,7 +3084,6 @@ qemuProcessUpdateVideoRamSize(virQEMUDriverPtr driver,
cfg = virQEMUDriverGetConfig(driver);
ret = virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps);
- virObjectUnref(cfg);
return ret;
@@ -3216,11 +3190,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,
@@ -3229,7 +3203,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);
@@ -3250,8 +3224,6 @@ qemuProcessStartCPUs(virQEMUDriverPtr driver, virDomainObjPtr vm,
* lifecycle event.
*/
- cleanup:
- virObjectUnref(cfg);
return ret;
release:
@@ -3259,7 +3231,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;
}
@@ -3313,7 +3285,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];
@@ -3331,8 +3303,6 @@ qemuProcessNotifyNets(virDomainDefPtr def)
virDomainNetNotifyActualDevice(conn, def, net);
}
}
-
- virObjectUnref(conn);
}
/* Attempt to instantiate the filters. Ignore failures because it's
@@ -3857,12 +3827,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);
@@ -3874,11 +3843,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);
}
@@ -3886,17 +3855,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;
}
@@ -3905,23 +3871,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;
}
@@ -3960,12 +3922,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;
@@ -4011,13 +3972,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;
@@ -4030,11 +3990,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;
@@ -4042,11 +4002,7 @@ qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
graphics->data.spice.tlsPortReserved = true;
}
- ret = 0;
-
- cleanup:
- virObjectUnref(cfg);
- return ret;
+ return 0;
}
@@ -4361,7 +4317,7 @@ qemuProcessUpdateCPU(virQEMUDriverPtr driver,
{
virCPUDataPtr cpu = NULL;
virCPUDataPtr disabled = NULL;
- virDomainCapsCPUModelsPtr models = NULL;
+ VIR_AUTOUNREF(virDomainCapsCPUModelsPtr) models = NULL;
int ret = -1;
/* The host CPU model comes from host caps rather than QEMU caps so
@@ -4384,7 +4340,6 @@ qemuProcessUpdateCPU(virQEMUDriverPtr driver,
cleanup:
virCPUDataFree(cpu);
virCPUDataFree(disabled);
- virObjectUnref(models);
return ret;
}
@@ -4733,9 +4688,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;
@@ -4821,8 +4776,6 @@ qemuProcessGetNetworkAddress(const char *netname,
ret = 0;
cleanup:
virNetworkDefFree(netdef);
- virObjectUnref(net);
- virObjectUnref(conn);
return ret;
}
@@ -4860,12 +4813,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:
@@ -4899,12 +4851,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;
}
}
@@ -4916,14 +4868,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;
@@ -4934,11 +4886,7 @@ qemuProcessGraphicsSetupListen(virQEMUDriverPtr driver,
}
}
- ret = 0;
-
- cleanup:
- virObjectUnref(cfg);
- return ret;
+ return 0;
}
@@ -5574,7 +5522,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;
@@ -5657,7 +5605,6 @@ qemuProcessInit(virQEMUDriverPtr driver,
cleanup:
virCPUDefFree(origCPU);
- virObjectUnref(caps);
return ret;
stop:
@@ -5678,9 +5625,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];
@@ -5692,9 +5638,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);
@@ -5718,10 +5664,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)) {
@@ -5731,10 +5677,7 @@ qemuProcessNetworkPrepareDevices(virQEMUDriverPtr driver,
}
}
- ret = 0;
- cleanup:
- virObjectUnref(conn);
- return ret;
+ return 0;
}
@@ -6238,18 +6181,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,
@@ -6257,12 +6199,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
@@ -6296,51 +6238,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;
@@ -6349,18 +6291,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;
}
@@ -6512,17 +6450,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
@@ -6530,7 +6467,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");
@@ -6540,17 +6477,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 */
@@ -6561,14 +6498,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 &&
@@ -6576,7 +6513,7 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver,
virReportSystemError(errno,
_("Cannot remove stale PID file %s"),
priv->pidfile);
- goto cleanup;
+ return -1;
}
/*
@@ -6585,27 +6522,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;
}
@@ -6715,12 +6649,12 @@ qemuProcessLaunch(virConnectPtr conn,
int ret = -1;
int rv;
int logfile = -1;
- qemuDomainLogContextPtr logCtxt = NULL;
+ VIR_AUTOUNREF(qemuDomainLogContextPtr) logCtxt = NULL;
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;
@@ -7035,9 +6969,6 @@ qemuProcessLaunch(virConnectPtr conn,
qemuExtDevicesStop(driver, vm);
qemuDomainSecretDestroy(vm);
virCommandFree(cmd);
- virObjectUnref(logCtxt);
- virObjectUnref(cfg);
- virObjectUnref(caps);
return ret;
}
@@ -7094,8 +7025,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");
@@ -7105,7 +7035,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);
@@ -7113,18 +7043,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;
}
@@ -7363,8 +7289,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",
@@ -7670,8 +7596,6 @@ void qemuProcessStop(virQEMUDriverPtr driver,
virSetError(orig_err);
virFreeError(orig_err);
}
- virObjectUnref(conn);
- virObjectUnref(cfg);
}
@@ -7806,7 +7730,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;
@@ -7857,7 +7781,6 @@ qemuProcessRefreshCPU(virQEMUDriverPtr driver,
cleanup:
virCPUDefFree(cpu);
virCPUDefFree(host);
- virObjectUnref(caps);
return ret;
}
@@ -7993,11 +7916,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;
@@ -8241,8 +8164,6 @@ qemuProcessReconnect(void *opaque)
qemuDomainRemoveInactiveJob(driver, obj);
}
virDomainObjEndAPI(&obj);
- virObjectUnref(cfg);
- virObjectUnref(caps);
virNWFilterUnlockFilterUpdates();
virIdentitySetCurrent(NULL);
return;
@@ -8605,9 +8526,8 @@ qemuProcessQMPInitMonitor(qemuMonitorPtr mon)
static int
qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc)
{
- virDomainXMLOptionPtr xmlopt = NULL;
+ VIR_AUTOUNREF(virDomainXMLOptionPtr) xmlopt = NULL;
virDomainChrSourceDef monConfig;
- int ret = -1;
VIR_DEBUG("proc=%p, emulator=%s, proc->pid=%lld",
proc, proc->binary, (long long)proc->pid);
@@ -8619,24 +8539,20 @@ qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc)
if (!(xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL)) ||
!(proc->vm = virDomainObjNew(xmlopt)) ||
!(proc->vm->def = virDomainDefNew()))
- goto cleanup;
+ return -1;
proc->vm->pid = proc->pid;
if (!(proc->mon = qemuMonitorOpen(proc->vm, &monConfig, true,
0, &callbacks, NULL)))
- goto cleanup;
+ return -1;
virObjectLock(proc->mon);
if (qemuProcessQMPInitMonitor(proc->mon) < 0)
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- virObjectUnref(xmlopt);
- return ret;
+ return 0;
}
--
2.21.0