Every domain that grabs a domain object to work over should reference it to make sure it won't disappear meanwhile. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/bhyve/bhyve_driver.c | 3 +- src/conf/domain_conf.c | 1 + src/libxl/libxl_driver.c | 10 ++--- src/lxc/lxc_driver.c | 3 +- src/openvz/openvz_driver.c | 11 +++-- src/parallels/parallels_driver.c | 3 +- src/qemu/qemu_driver.c | 14 ++---- src/test/test_driver.c | 93 +++++++++++++--------------------------- src/uml/uml_driver.c | 15 +++---- 9 files changed, 51 insertions(+), 102 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index edbf1e4..dc76cf7 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -797,8 +797,7 @@ static virDomainPtr bhyveDomainLookupByName(virConnectPtr conn, dom->id = vm->def->id; cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return dom; } diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 686c614..6666d03 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1157,6 +1157,7 @@ virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms, virDomainObjPtr obj; virObjectLock(doms); obj = virHashSearch(doms->objs, virDomainObjListSearchName, name); + virObjectRef(obj); if (obj) { virObjectLock(obj); if (obj->removing) { diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 6a54c73..393f8bd 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -1001,8 +1001,7 @@ libxlDomainLookupByName(virConnectPtr conn, const char *name) dom->id = vm->def->id; cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return dom; } @@ -4955,12 +4954,12 @@ libxlDomainMigrateFinish3Params(virConnectPtr dconn, } if (virDomainMigrateFinish3ParamsEnsureACL(dconn, vm->def) < 0) { - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return NULL; } if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) { - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return NULL; } @@ -4969,8 +4968,7 @@ libxlDomainMigrateFinish3Params(virConnectPtr dconn, if (!libxlDomainObjEndJob(driver, vm)) vm = NULL; - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return ret; } diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 38d9bed..188ff80 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -321,8 +321,7 @@ static virDomainPtr lxcDomainLookupByName(virConnectPtr conn, dom->id = vm->def->id; cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return dom; } diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 1bb8973..10d94ff 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -427,8 +427,7 @@ static virDomainPtr openvzDomainLookupByName(virConnectPtr conn, dom->id = vm->def->id; cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return dom; } @@ -1007,6 +1006,7 @@ openvzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int fla virReportError(VIR_ERR_OPERATION_FAILED, _("Already an OPENVZ VM active with the id '%s'"), vmdef->name); + virDomainObjEndAPI(&vm); goto cleanup; } if (!(vm = virDomainObjListAdd(driver->domains, vmdef, @@ -1103,6 +1103,7 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml, virReportError(VIR_ERR_OPERATION_FAILED, _("Already an OPENVZ VM defined with the id '%s'"), vmdef->name); + virDomainObjEndAPI(&vm); goto cleanup; } if (!(vm = virDomainObjListAdd(driver->domains, @@ -1208,8 +1209,7 @@ openvzDomainCreateWithFlags(virDomainPtr dom, unsigned int flags) ret = 0; cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return ret; } @@ -2508,8 +2508,7 @@ openvzDomainMigrateFinish3Params(virConnectPtr dconn, dom->id = vm->def->id; cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return dom; } diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index 07f1311..1ddc14e 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -526,8 +526,7 @@ parallelsDomainLookupByName(virConnectPtr conn, const char *name) ret->id = dom->def->id; cleanup: - if (dom) - virObjectUnlock(dom); + virDomainObjEndAPI(&dom); return ret; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 82f34ec..47ada4b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1511,8 +1511,7 @@ static virDomainPtr qemuDomainLookupByName(virConnectPtr conn, if (dom) dom->id = vm->def->id; cleanup: - if (vm) - virObjectUnlock(vm); + qemuDomObjEndAPI(&vm); return dom; } @@ -12287,11 +12286,10 @@ qemuDomainMigrateFinish2(virConnectPtr dconn, } if (virDomainMigrateFinish2EnsureACL(dconn, vm->def) < 0) { - virObjectUnlock(vm); + qemuDomObjEndAPI(&vm); goto cleanup; } - virObjectRef(vm); /* Do not use cookies in v2 protocol, since the cookie * length was not sufficiently large, causing failures * migrating between old & new libvirtd @@ -12702,12 +12700,10 @@ qemuDomainMigrateFinish3(virConnectPtr dconn, } if (virDomainMigrateFinish3EnsureACL(dconn, vm->def) < 0) { - virObjectUnlock(vm); + qemuDomObjEndAPI(&vm); return NULL; } - virObjectRef(vm); - return qemuMigrationFinish(driver, dconn, vm, cookiein, cookieinlen, cookieout, cookieoutlen, @@ -12747,12 +12743,10 @@ qemuDomainMigrateFinish3Params(virConnectPtr dconn, } if (virDomainMigrateFinish3ParamsEnsureACL(dconn, vm->def) < 0) { - virObjectUnlock(vm); + qemuDomObjEndAPI(&vm); return NULL; } - virObjectRef(vm); - return qemuMigrationFinish(driver, dconn, vm, cookiein, cookieinlen, cookieout, cookieoutlen, diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 133805c..231c72a 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1859,8 +1859,7 @@ static virDomainPtr testDomainLookupByName(virConnectPtr conn, ret->id = dom->def->id; cleanup: - if (dom) - virObjectUnlock(dom); + virDomainObjEndAPI(&dom); return ret; } @@ -1902,13 +1901,11 @@ static int testDomainDestroy(virDomainPtr domain) if (!privdom->persistent) { virDomainObjListRemove(privconn->domains, privdom); - privdom = NULL; } ret = 0; cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); if (event) testObjectEventQueue(privconn, event); testDriverUnlock(privconn); @@ -1946,8 +1943,7 @@ static int testDomainResume(virDomainPtr domain) ret = 0; cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); if (event) { testDriverLock(privconn); testObjectEventQueue(privconn, event); @@ -1988,8 +1984,7 @@ static int testDomainSuspend(virDomainPtr domain) ret = 0; cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); if (event) { testDriverLock(privconn); @@ -2032,13 +2027,11 @@ static int testDomainShutdownFlags(virDomainPtr domain, if (!privdom->persistent) { virDomainObjListRemove(privconn->domains, privdom); - privdom = NULL; } ret = 0; cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); if (event) testObjectEventQueue(privconn, event); testDriverUnlock(privconn); @@ -2107,14 +2100,12 @@ static int testDomainReboot(virDomainPtr domain, if (!privdom->persistent) { virDomainObjListRemove(privconn->domains, privdom); - privdom = NULL; } } ret = 0; cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); if (event) testObjectEventQueue(privconn, event); testDriverUnlock(privconn); @@ -2153,8 +2144,7 @@ static int testDomainGetInfo(virDomainPtr domain, ret = 0; cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); return ret; } @@ -2184,8 +2174,7 @@ testDomainGetState(virDomainPtr domain, ret = 0; cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); return ret; } @@ -2271,7 +2260,6 @@ testDomainSaveFlags(virDomainPtr domain, const char *path, if (!privdom->persistent) { virDomainObjListRemove(privconn->domains, privdom); - privdom = NULL; } ret = 0; @@ -2285,8 +2273,7 @@ testDomainSaveFlags(virDomainPtr domain, const char *path, VIR_FORCE_CLOSE(fd); unlink(path); } - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); if (event) testObjectEventQueue(privconn, event); testDriverUnlock(privconn); @@ -2461,15 +2448,13 @@ static int testDomainCoreDumpWithFormat(virDomainPtr domain, if (!privdom->persistent) { virDomainObjListRemove(privconn->domains, privdom); - privdom = NULL; } } ret = 0; cleanup: VIR_FORCE_CLOSE(fd); - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); if (event) testObjectEventQueue(privconn, event); testDriverUnlock(privconn); @@ -2517,8 +2502,7 @@ testDomainGetMaxMemory(virDomainPtr domain) ret = virDomainDefGetMemoryActual(privdom->def); cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); return ret; } @@ -2544,8 +2528,7 @@ static int testDomainSetMaxMemory(virDomainPtr domain, ret = 0; cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); return ret; } @@ -2575,8 +2558,7 @@ static int testDomainSetMemory(virDomainPtr domain, ret = 0; cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); return ret; } @@ -2806,8 +2788,7 @@ static int testDomainGetVcpus(virDomainPtr domain, ret = maxinfo; cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); return ret; } @@ -2863,8 +2844,7 @@ static int testDomainPinVcpu(virDomainPtr domain, ret = 0; cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); return ret; } @@ -2894,8 +2874,7 @@ static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) virDomainDefFormatConvertXMLFlags(flags)); cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); return ret; } @@ -3014,8 +2993,7 @@ static char *testDomainGetMetadata(virDomainPtr dom, privconn->xmlopt, flags); cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); return ret; } @@ -3048,8 +3026,7 @@ static int testDomainSetMetadata(virDomainPtr dom, NULL, NULL, flags); cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); return ret; } @@ -3118,8 +3095,7 @@ static int testDomainCreateWithFlags(virDomainPtr domain, unsigned int flags) ret = 0; cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); if (event) testObjectEventQueue(privconn, event); testDriverUnlock(privconn); @@ -3188,14 +3164,12 @@ static int testDomainUndefineFlags(virDomainPtr domain, } else { virDomainObjListRemove(privconn->domains, privdom); - privdom = NULL; } ret = 0; cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); if (event) testObjectEventQueue(privconn, event); testDriverUnlock(privconn); @@ -3228,8 +3202,7 @@ static int testDomainGetAutostart(virDomainPtr domain, ret = 0; cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); return ret; } @@ -3255,8 +3228,7 @@ static int testDomainSetAutostart(virDomainPtr domain, ret = 0; cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); return ret; } @@ -3305,8 +3277,7 @@ testDomainGetSchedulerParametersFlags(virDomainPtr domain, ret = 0; cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); return ret; } @@ -3356,8 +3327,7 @@ testDomainSetSchedulerParametersFlags(virDomainPtr domain, ret = 0; cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); return ret; } @@ -3417,8 +3387,7 @@ static int testDomainBlockStats(virDomainPtr domain, ret = 0; error: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); return ret; } @@ -3476,8 +3445,7 @@ static int testDomainInterfaceStats(virDomainPtr domain, ret = 0; error: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); return ret; } @@ -6211,8 +6179,7 @@ testDomainManagedSave(virDomainPtr dom, unsigned int flags) ret = 0; cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); if (event) { testDriverLock(privconn); testObjectEventQueue(privconn, event); @@ -6242,8 +6209,7 @@ testDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags) ret = vm->hasManagedSave; cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); testDriverUnlock(privconn); return ret; } @@ -6268,8 +6234,7 @@ testDomainManagedSaveRemove(virDomainPtr dom, unsigned int flags) vm->hasManagedSave = false; ret = 0; cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); testDriverUnlock(privconn); return ret; } diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 9cee541..f8a84e4 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -339,7 +339,7 @@ umlInotifyEvent(int watch, if (e.mask & IN_DELETE) { VIR_DEBUG("Got inotify domain shutdown '%s'", name); if (!virDomainObjIsActive(dom)) { - virObjectUnlock(dom); + virDomainObjEndAPI(&dom); continue; } @@ -351,17 +351,16 @@ umlInotifyEvent(int watch, if (!dom->persistent) { virDomainObjListRemove(driver->domains, dom); - dom = NULL; } } else if (e.mask & (IN_CREATE | IN_MODIFY)) { VIR_DEBUG("Got inotify domain startup '%s'", name); if (virDomainObjIsActive(dom)) { - virObjectUnlock(dom); + virDomainObjEndAPI(&dom); continue; } if (umlReadPidFile(driver, dom) < 0) { - virObjectUnlock(dom); + virDomainObjEndAPI(&dom); continue; } @@ -385,7 +384,6 @@ umlInotifyEvent(int watch, if (!dom->persistent) { virDomainObjListRemove(driver->domains, dom); - dom = NULL; } } else if (umlIdentifyChrPTY(driver, dom) < 0) { VIR_WARN("Could not identify character devices for new domain"); @@ -398,12 +396,10 @@ umlInotifyEvent(int watch, if (!dom->persistent) { virDomainObjListRemove(driver->domains, dom); - dom = NULL; } } } - if (dom) - virObjectUnlock(dom); + virDomainObjEndAPI(&dom); if (event) { umlDomainEventQueue(driver, event); event = NULL; @@ -1448,8 +1444,7 @@ static virDomainPtr umlDomainLookupByName(virConnectPtr conn, if (dom) dom->id = vm->def->id; cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return dom; } -- 2.0.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list