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. Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx> --- src/qemu/qemu_driver.c | 94 +++++++++++++----------------------------- 1 file changed, 29 insertions(+), 65 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8751145ea0..1e709c1e97 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -202,7 +202,7 @@ qemuAutostartDomain(virDomainObjPtr vm, { virQEMUDriverPtr driver = opaque; int flags = 0; - virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver); int ret = -1; if (cfg->autoStartBypassCache) @@ -234,7 +234,6 @@ qemuAutostartDomain(virDomainObjPtr vm, ret = 0; cleanup: virDomainObjEndAPI(&vm); - virObjectUnref(cfg); return ret; } @@ -308,7 +307,7 @@ qemuSecurityInit(virQEMUDriverPtr driver) char **names; virSecurityManagerPtr mgr = NULL; virSecurityManagerPtr stack = NULL; - virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver); unsigned int flags = 0; if (cfg->securityDefaultConfined) @@ -368,7 +367,6 @@ qemuSecurityInit(virQEMUDriverPtr driver) } driver->securityManager = stack; - virObjectUnref(cfg); return 0; error: @@ -376,7 +374,6 @@ qemuSecurityInit(virQEMUDriverPtr driver) _("Failed to initialize security drivers")); virObjectUnref(stack); virObjectUnref(mgr); - virObjectUnref(cfg); return -1; } @@ -1069,7 +1066,7 @@ static void qemuNotifyLoadDomain(virDomainObjPtr vm, int newVM, void *opaque) static int qemuStateReload(void) { - virQEMUDriverConfigPtr cfg = NULL; + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL; virCapsPtr caps = NULL; if (!qemu_driver) @@ -1085,7 +1082,6 @@ qemuStateReload(void) caps, qemu_driver->xmlopt, qemuNotifyLoadDomain, qemu_driver); cleanup: - virObjectUnref(cfg); virObjectUnref(caps); return 0; } @@ -1107,7 +1103,7 @@ qemuStateStop(void) int state; virDomainPtr *domains = NULL; unsigned int *flags = NULL; - virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(qemu_driver); + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(qemu_driver); if (!(conn = virConnectOpen(cfg->uri))) goto cleanup; @@ -1146,7 +1142,6 @@ qemuStateStop(void) } VIR_FREE(flags); virObjectUnref(conn); - virObjectUnref(cfg); return ret; } @@ -1204,20 +1199,16 @@ qemuStateCleanup(void) static int qemuConnectURIProbe(char **uri) { - virQEMUDriverConfigPtr cfg = NULL; - int ret = -1; + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL; if (qemu_driver == NULL) return 0; cfg = virQEMUDriverGetConfig(qemu_driver); if (VIR_STRDUP(*uri, cfg->uri) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - virObjectUnref(cfg); - return ret; + return 0; } static virDrvOpenStatus qemuConnectOpen(virConnectPtr conn, @@ -1882,7 +1873,7 @@ static int qemuDomainSuspend(virDomainPtr dom) qemuDomainObjPrivatePtr priv; virDomainPausedReason reason; int state; - virQEMUDriverConfigPtr cfg = NULL; + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL; if (!(vm = qemuDomainObjFromDomain(dom))) return -1; @@ -1925,7 +1916,6 @@ static int qemuDomainSuspend(virDomainPtr dom) cleanup: virDomainObjEndAPI(&vm); - virObjectUnref(cfg); return ret; } @@ -1937,7 +1927,7 @@ static int qemuDomainResume(virDomainPtr dom) int ret = -1; int state; int reason; - virQEMUDriverConfigPtr cfg = NULL; + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL; if (!(vm = qemuDomainObjFromDomain(dom))) return -1; @@ -1983,7 +1973,6 @@ static int qemuDomainResume(virDomainPtr dom) cleanup: virDomainObjEndAPI(&vm); - virObjectUnref(cfg); return ret; } @@ -2364,7 +2353,7 @@ static int qemuDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, virDomainDefPtr def; virDomainDefPtr persistentDef; int ret = -1, r; - virQEMUDriverConfigPtr cfg = NULL; + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL; virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG | @@ -2469,7 +2458,6 @@ static int qemuDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, cleanup: virDomainObjEndAPI(&vm); - virObjectUnref(cfg); return ret; } @@ -2492,7 +2480,7 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPtr dom, int period, virDomainDefPtr def; virDomainDefPtr persistentDef; int ret = -1, r; - virQEMUDriverConfigPtr cfg = NULL; + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL; virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); @@ -2555,7 +2543,6 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPtr dom, int period, cleanup: virDomainObjEndAPI(&vm); - virObjectUnref(cfg); return ret; } @@ -3067,27 +3054,21 @@ qemuOpenFile(virQEMUDriverPtr driver, int oflags, bool *needUnlink) { - int ret = -1; - virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver); uid_t user = cfg->user; gid_t group = cfg->group; bool dynamicOwnership = cfg->dynamicOwnership; virSecurityLabelDefPtr seclabel; - virObjectUnref(cfg); - /* TODO: Take imagelabel into account? */ if (vm && (seclabel = virDomainDefGetSecurityLabelDef(vm->def, "dac")) != NULL && seclabel->label != NULL && (virParseOwnershipIds(seclabel->label, &user, &group) < 0)) - goto cleanup; - - ret = qemuOpenFileAs(user, group, dynamicOwnership, - path, oflags, needUnlink); + return -1; - cleanup: - return ret; + return qemuOpenFileAs(user, group, dynamicOwnership, + path, oflags, needUnlink); } static int @@ -3252,7 +3233,7 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, unsigned int flags, qemuDomainAsyncJob asyncJob) { - virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver); bool needUnlink = false; int ret = -1; int fd = -1; @@ -3315,7 +3296,6 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, if (qemuFileWrapperFDClose(vm, wrapperFd) < 0) ret = -1; virFileWrapperFdFree(wrapperFd); - virObjectUnref(cfg); if (ret < 0 && needUnlink) unlink(path); @@ -3543,7 +3523,7 @@ qemuDomainSaveFlags(virDomainPtr dom, const char *path, const char *dxml, char *compressedpath = NULL; int ret = -1; virDomainObjPtr vm = NULL; - virQEMUDriverConfigPtr cfg = NULL; + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL; virCheckFlags(VIR_DOMAIN_SAVE_BYPASS_CACHE | VIR_DOMAIN_SAVE_RUNNING | @@ -3570,7 +3550,6 @@ qemuDomainSaveFlags(virDomainPtr dom, const char *path, const char *dxml, cleanup: virDomainObjEndAPI(&vm); VIR_FREE(compressedpath); - virObjectUnref(cfg); return ret; } @@ -3584,14 +3563,11 @@ static char * qemuDomainManagedSavePath(virQEMUDriverPtr driver, virDomainObjPtr vm) { char *ret; - virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver); - if (virAsprintf(&ret, "%s/%s.save", cfg->saveDir, vm->def->name) < 0) { - virObjectUnref(cfg); + if (virAsprintf(&ret, "%s/%s.save", cfg->saveDir, vm->def->name) < 0) return NULL; - } - virObjectUnref(cfg); return ret; } @@ -3599,7 +3575,7 @@ static int qemuDomainManagedSave(virDomainPtr dom, unsigned int flags) { virQEMUDriverPtr driver = dom->conn->privateData; - virQEMUDriverConfigPtr cfg = NULL; + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL; int compressed; char *compressedpath = NULL; virDomainObjPtr vm; @@ -3645,7 +3621,6 @@ qemuDomainManagedSave(virDomainPtr dom, unsigned int flags) virDomainObjEndAPI(&vm); VIR_FREE(name); VIR_FREE(compressedpath); - virObjectUnref(cfg); return ret; } @@ -3843,7 +3818,7 @@ doCoreDump(virQEMUDriverPtr driver, int directFlag = 0; unsigned int flags = VIR_FILE_WRAPPER_NON_BLOCKING; const char *memory_dump_format = NULL; - virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver); char *compressedpath = NULL; /* We reuse "save" flag for "dump" here. Then, we can support the same @@ -3925,7 +3900,6 @@ doCoreDump(virQEMUDriverPtr driver, if (ret != 0) unlink(path); VIR_FREE(compressedpath); - virObjectUnref(cfg); return ret; } @@ -4057,7 +4031,7 @@ qemuDomainScreenshot(virDomainPtr dom, const char *videoAlias = NULL; char *ret = NULL; bool unlink_tmp = false; - virQEMUDriverConfigPtr cfg = NULL; + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL; virCheckFlags(0, NULL); @@ -4149,7 +4123,6 @@ qemuDomainScreenshot(virDomainPtr dom, cleanup: virDomainObjEndAPI(&vm); - virObjectUnref(cfg); return ret; } @@ -4162,7 +4135,7 @@ getAutoDumpPath(virQEMUDriverPtr driver, char timestr[100]; struct tm time_info; time_t curtime = time(NULL); - virQEMUDriverConfigPtr cfg = NULL; + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL; if (!domname) return NULL; @@ -4177,7 +4150,6 @@ getAutoDumpPath(virQEMUDriverPtr driver, domname, timestr)); - virObjectUnref(cfg); VIR_FREE(domname); return dumpfile; } @@ -4188,7 +4160,7 @@ processWatchdogEvent(virQEMUDriverPtr driver, int action) { int ret; - virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver); char *dumpfile = getAutoDumpPath(driver, vm); unsigned int flags = VIR_DUMP_MEMORY_ONLY; @@ -4229,7 +4201,6 @@ processWatchdogEvent(virQEMUDriverPtr driver, qemuDomainObjEndAsyncJob(driver, vm); cleanup: - virObjectUnref(cfg); VIR_FREE(dumpfile); } @@ -4239,7 +4210,7 @@ doCoreDumpToAutoDumpPath(virQEMUDriverPtr driver, unsigned int flags) { int ret = -1; - virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver); char *dumpfile = getAutoDumpPath(driver, vm); if (!dumpfile) @@ -4252,7 +4223,6 @@ doCoreDumpToAutoDumpPath(virQEMUDriverPtr driver, "%s", _("Dump failed")); cleanup: VIR_FREE(dumpfile); - virObjectUnref(cfg); return ret; } @@ -4281,13 +4251,13 @@ processGuestPanicEvent(virQEMUDriverPtr driver, { qemuDomainObjPrivatePtr priv = vm->privateData; virObjectEventPtr event = NULL; - virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver); bool removeInactive = false; unsigned long flags = VIR_DUMP_MEMORY_ONLY; if (qemuDomainObjBeginAsyncJob(driver, vm, QEMU_ASYNC_JOB_DUMP, VIR_DOMAIN_JOB_OPERATION_DUMP, flags) < 0) - goto cleanup; + return; if (!virDomainObjIsActive(vm)) { VIR_DEBUG("Ignoring GUEST_PANICKED event from inactive domain %s", @@ -4354,9 +4324,6 @@ processGuestPanicEvent(virQEMUDriverPtr driver, qemuDomainObjEndAsyncJob(driver, vm); if (removeInactive) qemuDomainRemoveInactiveJob(driver, vm); - - cleanup: - virObjectUnref(cfg); } @@ -4365,14 +4332,14 @@ processDeviceDeletedEvent(virQEMUDriverPtr driver, virDomainObjPtr vm, const char *devAlias) { - virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver); virDomainDeviceDef dev; VIR_DEBUG("Removing device %s from domain %p %s", devAlias, vm, vm->def->name); if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) - goto cleanup; + return; if (!virDomainObjIsActive(vm)) { VIR_DEBUG("Domain is not running"); @@ -4395,9 +4362,6 @@ processDeviceDeletedEvent(virQEMUDriverPtr driver, endjob: qemuDomainObjEndJob(driver, vm); - - cleanup: - virObjectUnref(cfg); } -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list