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 6ce6348593..1bd9609761 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; } @@ -1074,7 +1071,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) @@ -1090,7 +1087,6 @@ qemuStateReload(void) caps, qemu_driver->xmlopt, qemuNotifyLoadDomain, qemu_driver); cleanup: - virObjectUnref(cfg); virObjectUnref(caps); return 0; } @@ -1112,7 +1108,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; @@ -1151,7 +1147,6 @@ qemuStateStop(void) } VIR_FREE(flags); virObjectUnref(conn); - virObjectUnref(cfg); return ret; } @@ -1209,20 +1204,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, @@ -1887,7 +1878,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; @@ -1930,7 +1921,6 @@ static int qemuDomainSuspend(virDomainPtr dom) cleanup: virDomainObjEndAPI(&vm); - virObjectUnref(cfg); return ret; } @@ -1942,7 +1932,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; @@ -1988,7 +1978,6 @@ static int qemuDomainResume(virDomainPtr dom) cleanup: virDomainObjEndAPI(&vm); - virObjectUnref(cfg); return ret; } @@ -2369,7 +2358,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 | @@ -2474,7 +2463,6 @@ static int qemuDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, cleanup: virDomainObjEndAPI(&vm); - virObjectUnref(cfg); return ret; } @@ -2497,7 +2485,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); @@ -2560,7 +2548,6 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPtr dom, int period, cleanup: virDomainObjEndAPI(&vm); - virObjectUnref(cfg); return ret; } @@ -3072,27 +3059,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 @@ -3257,7 +3238,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; @@ -3320,7 +3301,6 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, if (qemuFileWrapperFDClose(vm, wrapperFd) < 0) ret = -1; virFileWrapperFdFree(wrapperFd); - virObjectUnref(cfg); if (ret < 0 && needUnlink) unlink(path); @@ -3548,7 +3528,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 | @@ -3575,7 +3555,6 @@ qemuDomainSaveFlags(virDomainPtr dom, const char *path, const char *dxml, cleanup: virDomainObjEndAPI(&vm); VIR_FREE(compressedpath); - virObjectUnref(cfg); return ret; } @@ -3589,14 +3568,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; } @@ -3604,7 +3580,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; @@ -3650,7 +3626,6 @@ qemuDomainManagedSave(virDomainPtr dom, unsigned int flags) virDomainObjEndAPI(&vm); VIR_FREE(name); VIR_FREE(compressedpath); - virObjectUnref(cfg); return ret; } @@ -3848,7 +3823,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 @@ -3930,7 +3905,6 @@ doCoreDump(virQEMUDriverPtr driver, if (ret != 0) unlink(path); VIR_FREE(compressedpath); - virObjectUnref(cfg); return ret; } @@ -4062,7 +4036,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); @@ -4154,7 +4128,6 @@ qemuDomainScreenshot(virDomainPtr dom, cleanup: virDomainObjEndAPI(&vm); - virObjectUnref(cfg); return ret; } @@ -4167,7 +4140,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; @@ -4182,7 +4155,6 @@ getAutoDumpPath(virQEMUDriverPtr driver, domname, timestr)); - virObjectUnref(cfg); VIR_FREE(domname); return dumpfile; } @@ -4193,7 +4165,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; @@ -4234,7 +4206,6 @@ processWatchdogEvent(virQEMUDriverPtr driver, qemuDomainObjEndAsyncJob(driver, vm); cleanup: - virObjectUnref(cfg); VIR_FREE(dumpfile); } @@ -4244,7 +4215,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) @@ -4257,7 +4228,6 @@ doCoreDumpToAutoDumpPath(virQEMUDriverPtr driver, "%s", _("Dump failed")); cleanup: VIR_FREE(dumpfile); - virObjectUnref(cfg); return ret; } @@ -4286,13 +4256,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", @@ -4359,9 +4329,6 @@ processGuestPanicEvent(virQEMUDriverPtr driver, qemuDomainObjEndAsyncJob(driver, vm); if (removeInactive) qemuDomainRemoveInactiveJob(driver, vm); - - cleanup: - virObjectUnref(cfg); } @@ -4370,14 +4337,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"); @@ -4400,9 +4367,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