[libvirt] [PATCH v2 0/2] Rename/remove virDomainObjListFindBy{UUID|ID}Ref

These were actually posted before as part of a larger series to rework/rename virDomainObjListFindBy{UUID|ID}Ref as patches 19 and 20: https://www.redhat.com/archives/libvir-list/2018-March/msg00508.html https://www.redhat.com/archives/libvir-list/2018-March/msg00509.html Even though it's only 6 weeks ago, attempting to remember what (if anything) has changed is challenging. In the long run, the point is that the *Ref specific functions are now removed. This makes it much easier for the next step which will be to modify the Add/Remove logic to be simpler and more realistic w/r/t expectations as well as remove a few comments in the code that indicate some day we need to fix this crazy problem (some day is getting closer). John Ferlan (2): conf: Rework/rename virDomainObjListFindByUUIDRef conf: Rework/rename virDomainObjListFindByIDRef src/bhyve/bhyve_driver.c | 6 ++-- src/conf/virdomainobjlist.c | 66 ++++++++++---------------------------------- src/conf/virdomainobjlist.h | 4 --- src/libvirt_private.syms | 2 -- src/libxl/libxl_domain.c | 2 +- src/libxl/libxl_driver.c | 6 ++-- src/lxc/lxc_driver.c | 7 ++--- src/openvz/openvz_driver.c | 4 +-- src/qemu/qemu_driver.c | 9 +++--- src/test/test_driver.c | 6 ++-- src/uml/uml_driver.c | 6 ++-- src/util/virclosecallbacks.c | 4 +-- src/vmware/vmware_driver.c | 4 +-- src/vz/vz_driver.c | 6 ++-- src/vz/vz_sdk.c | 14 +++++----- src/vz/vz_utils.c | 2 +- 16 files changed, 51 insertions(+), 97 deletions(-) -- 2.13.6

Now that every caller is using virDomainObjListFindByUUIDRef, let's just remove it and keep the name as virDomainObjListFindByUUID. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/bhyve/bhyve_driver.c | 4 ++-- src/conf/virdomainobjlist.c | 35 +++++++---------------------------- src/conf/virdomainobjlist.h | 2 -- src/libvirt_private.syms | 1 - src/libxl/libxl_driver.c | 4 ++-- src/lxc/lxc_driver.c | 4 ++-- src/openvz/openvz_driver.c | 2 +- src/qemu/qemu_driver.c | 4 ++-- src/test/test_driver.c | 4 ++-- src/uml/uml_driver.c | 4 ++-- src/util/virclosecallbacks.c | 4 ++-- src/vmware/vmware_driver.c | 2 +- src/vz/vz_driver.c | 4 ++-- src/vz/vz_sdk.c | 14 +++++++------- src/vz/vz_utils.c | 2 +- 15 files changed, 33 insertions(+), 57 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 24c4a9c80e..bd8c6b30ed 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -168,7 +168,7 @@ bhyveDomObjFromDomain(virDomainPtr domain) bhyveConnPtr privconn = domain->conn->privateData; char uuidstr[VIR_UUID_STRING_BUFLEN]; - vm = virDomainObjListFindByUUIDRef(privconn->domains, domain->uuid); + vm = virDomainObjListFindByUUID(privconn->domains, domain->uuid); if (!vm) { virUUIDFormat(domain->uuid, uuidstr); virReportError(VIR_ERR_NO_DOMAIN, @@ -791,7 +791,7 @@ bhyveDomainLookupByUUID(virConnectPtr conn, virDomainObjPtr vm; virDomainPtr dom = NULL; - vm = virDomainObjListFindByUUIDRef(privconn->domains, uuid); + vm = virDomainObjListFindByUUID(privconn->domains, uuid); if (!vm) { char uuidstr[VIR_UUID_STRING_BUFLEN]; diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index c09e5e5d2f..02b52465d0 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -149,10 +149,10 @@ virDomainObjListFindByIDRef(virDomainObjListPtr doms, return virDomainObjListFindByIDInternal(doms, id, true); } -static virDomainObjPtr -virDomainObjListFindByUUIDInternal(virDomainObjListPtr doms, - const unsigned char *uuid, - bool ref) + +virDomainObjPtr +virDomainObjListFindByUUID(virDomainObjListPtr doms, + const unsigned char *uuid) { char uuidstr[VIR_UUID_STRING_BUFLEN]; virDomainObjPtr obj; @@ -161,41 +161,20 @@ virDomainObjListFindByUUIDInternal(virDomainObjListPtr doms, virUUIDFormat(uuid, uuidstr); obj = virHashLookup(doms->objs, uuidstr); - if (ref) { - virObjectRef(obj); - virObjectRWUnlock(doms); - } + virObjectRef(obj); + virObjectRWUnlock(doms); if (obj) { virObjectLock(obj); if (obj->removing) { virObjectUnlock(obj); - if (ref) - virObjectUnref(obj); + virObjectUnref(obj); obj = NULL; } } - if (!ref) - virObjectRWUnlock(doms); return obj; } -virDomainObjPtr -virDomainObjListFindByUUID(virDomainObjListPtr doms, - const unsigned char *uuid) -{ - return virDomainObjListFindByUUIDInternal(doms, uuid, false); -} - - -virDomainObjPtr -virDomainObjListFindByUUIDRef(virDomainObjListPtr doms, - const unsigned char *uuid) -{ - return virDomainObjListFindByUUIDInternal(doms, uuid, true); -} - - virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms, const char *name) { diff --git a/src/conf/virdomainobjlist.h b/src/conf/virdomainobjlist.h index bb186bde30..1b77a95ba9 100644 --- a/src/conf/virdomainobjlist.h +++ b/src/conf/virdomainobjlist.h @@ -38,8 +38,6 @@ virDomainObjPtr virDomainObjListFindByIDRef(virDomainObjListPtr doms, int id); virDomainObjPtr virDomainObjListFindByUUID(virDomainObjListPtr doms, const unsigned char *uuid); -virDomainObjPtr virDomainObjListFindByUUIDRef(virDomainObjListPtr doms, - const unsigned char *uuid); virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms, const char *name); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b31f599bd2..f6c76d4341 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -955,7 +955,6 @@ virDomainObjListFindByID; virDomainObjListFindByIDRef; virDomainObjListFindByName; virDomainObjListFindByUUID; -virDomainObjListFindByUUIDRef; virDomainObjListForEach; virDomainObjListGetActiveIDs; virDomainObjListGetInactiveNames; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index b66a1de5f1..24553c7272 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -313,7 +313,7 @@ libxlDomObjFromDomain(virDomainPtr dom) libxlDriverPrivatePtr driver = dom->conn->privateData; char uuidstr[VIR_UUID_STRING_BUFLEN]; - vm = virDomainObjListFindByUUIDRef(driver->domains, dom->uuid); + vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); if (!vm) { virUUIDFormat(dom->uuid, uuidstr); virReportError(VIR_ERR_NO_DOMAIN, @@ -1105,7 +1105,7 @@ libxlDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) virDomainObjPtr vm; virDomainPtr dom = NULL; - vm = virDomainObjListFindByUUIDRef(driver->domains, uuid); + vm = virDomainObjListFindByUUID(driver->domains, uuid); if (!vm) { virReportError(VIR_ERR_NO_DOMAIN, NULL); goto cleanup; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 4097cef934..8773a3fd45 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -138,7 +138,7 @@ lxcDomObjFromDomain(virDomainPtr domain) virLXCDriverPtr driver = domain->conn->privateData; char uuidstr[VIR_UUID_STRING_BUFLEN]; - vm = virDomainObjListFindByUUIDRef(driver->domains, domain->uuid); + vm = virDomainObjListFindByUUID(driver->domains, domain->uuid); if (!vm) { virUUIDFormat(domain->uuid, uuidstr); virReportError(VIR_ERR_NO_DOMAIN, @@ -274,7 +274,7 @@ static virDomainPtr lxcDomainLookupByUUID(virConnectPtr conn, virDomainObjPtr vm; virDomainPtr dom = NULL; - vm = virDomainObjListFindByUUIDRef(driver->domains, uuid); + vm = virDomainObjListFindByUUID(driver->domains, uuid); if (!vm) { char uuidstr[VIR_UUID_STRING_BUFLEN]; diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index ba5ad8eeb4..f5a5526d28 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -95,7 +95,7 @@ openvzDomObjFromDomainLocked(struct openvz_driver *driver, virDomainObjPtr vm; char uuidstr[VIR_UUID_STRING_BUFLEN]; - if (!(vm = virDomainObjListFindByUUIDRef(driver->domains, uuid))) { + if (!(vm = virDomainObjListFindByUUID(driver->domains, uuid))) { virUUIDFormat(uuid, uuidstr); virReportError(VIR_ERR_NO_DOMAIN, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 5673d9fd8d..8a5b049296 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -203,7 +203,7 @@ qemuDomObjFromDomain(virDomainPtr domain) virQEMUDriverPtr driver = domain->conn->privateData; char uuidstr[VIR_UUID_STRING_BUFLEN]; - vm = virDomainObjListFindByUUIDRef(driver->domains, domain->uuid); + vm = virDomainObjListFindByUUID(driver->domains, domain->uuid); if (!vm) { virUUIDFormat(domain->uuid, uuidstr); virReportError(VIR_ERR_NO_DOMAIN, @@ -1555,7 +1555,7 @@ static virDomainPtr qemuDomainLookupByUUID(virConnectPtr conn, virDomainObjPtr vm; virDomainPtr dom = NULL; - vm = virDomainObjListFindByUUIDRef(driver->domains, uuid); + vm = virDomainObjListFindByUUID(driver->domains, uuid); if (!vm) { char uuidstr[VIR_UUID_STRING_BUFLEN]; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 3560c76fa5..249932de06 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -578,7 +578,7 @@ testDomObjFromDomain(virDomainPtr domain) testDriverPtr driver = domain->conn->privateData; char uuidstr[VIR_UUID_STRING_BUFLEN]; - vm = virDomainObjListFindByUUIDRef(driver->domains, domain->uuid); + vm = virDomainObjListFindByUUID(driver->domains, domain->uuid); if (!vm) { virUUIDFormat(domain->uuid, uuidstr); virReportError(VIR_ERR_NO_DOMAIN, @@ -1726,7 +1726,7 @@ static virDomainPtr testDomainLookupByUUID(virConnectPtr conn, virDomainPtr ret = NULL; virDomainObjPtr dom; - if (!(dom = virDomainObjListFindByUUIDRef(privconn->domains, uuid))) { + if (!(dom = virDomainObjListFindByUUID(privconn->domains, uuid))) { virReportError(VIR_ERR_NO_DOMAIN, NULL); return NULL; } diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 5b941f1dd8..0bafd0902e 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -171,7 +171,7 @@ umlDomObjFromDomainLocked(struct uml_driver *driver, virDomainObjPtr vm; char uuidstr[VIR_UUID_STRING_BUFLEN]; - if (!(vm = virDomainObjListFindByUUIDRef(driver->domains, uuid))) { + if (!(vm = virDomainObjListFindByUUID(driver->domains, uuid))) { virUUIDFormat(uuid, uuidstr); virReportError(VIR_ERR_NO_DOMAIN, @@ -773,7 +773,7 @@ static int umlProcessAutoDestroyDom(void *payload, return 0; } - if (!(dom = virDomainObjListFindByUUIDRef(data->driver->domains, uuid))) { + if (!(dom = virDomainObjListFindByUUID(data->driver->domains, uuid))) { VIR_DEBUG("No domain object to kill"); return 0; } diff --git a/src/util/virclosecallbacks.c b/src/util/virclosecallbacks.c index 0a395eb167..60070dc8d9 100644 --- a/src/util/virclosecallbacks.c +++ b/src/util/virclosecallbacks.c @@ -342,8 +342,8 @@ virCloseCallbacksRun(virCloseCallbacksPtr closeCallbacks, virDomainObjPtr vm; /* Grab a ref and lock to the vm */ - if (!(vm = virDomainObjListFindByUUIDRef(domains, - list->entries[i].uuid))) { + if (!(vm = virDomainObjListFindByUUID(domains, + list->entries[i].uuid))) { char uuidstr[VIR_UUID_STRING_BUFLEN]; virUUIDFormat(list->entries[i].uuid, uuidstr); VIR_DEBUG("No domain object with UUID %s", uuidstr); diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index f36fcc60a9..f94d192fd1 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -67,7 +67,7 @@ vmwareDomObjFromDomainLocked(struct vmware_driver *driver, virDomainObjPtr vm; char uuidstr[VIR_UUID_STRING_BUFLEN]; - if (!(vm = virDomainObjListFindByUUIDRef(driver->domains, uuid))) { + if (!(vm = virDomainObjListFindByUUID(driver->domains, uuid))) { virUUIDFormat(uuid, uuidstr); virReportError(VIR_ERR_NO_DOMAIN, diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 2f1e00f420..8f8720a037 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -579,7 +579,7 @@ vzDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) virDomainPtr ret = NULL; virDomainObjPtr dom; - dom = virDomainObjListFindByUUIDRef(privconn->driver->domains, uuid); + dom = virDomainObjListFindByUUID(privconn->driver->domains, uuid); if (dom == NULL) { char uuidstr[VIR_UUID_STRING_BUFLEN]; @@ -814,7 +814,7 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; - dom = virDomainObjListFindByUUIDRef(driver->domains, def->uuid); + dom = virDomainObjListFindByUUID(driver->domains, def->uuid); if (dom == NULL) { virResetLastError(); if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) { diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 871ad843e2..bb8f15e4fe 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -1958,7 +1958,7 @@ prlsdkLoadDomain(vzDriverPtr driver, goto error; virObjectLock(driver); - if (!(olddom = virDomainObjListFindByUUIDRef(driver->domains, def->uuid))) + if (!(olddom = virDomainObjListFindByUUID(driver->domains, def->uuid))) dom = virDomainObjListAdd(driver->domains, def, driver->xmlopt, 0, NULL); virObjectUnlock(driver); @@ -2144,7 +2144,7 @@ prlsdkHandleVmStateEvent(vzDriverPtr driver, virDomainEventType lvEventType = 0; int lvEventTypeDetails = 0; - dom = virDomainObjListFindByUUIDRef(driver->domains, uuid); + dom = virDomainObjListFindByUUID(driver->domains, uuid); if (dom == NULL) return; @@ -2177,7 +2177,7 @@ prlsdkHandleVmConfigEvent(vzDriverPtr driver, virDomainObjPtr dom = NULL; bool job = false; - dom = virDomainObjListFindByUUIDRef(driver->domains, uuid); + dom = virDomainObjListFindByUUID(driver->domains, uuid); if (dom == NULL) return; @@ -2207,7 +2207,7 @@ prlsdkHandleVmAddedEvent(vzDriverPtr driver, { virDomainObjPtr dom = NULL; - if (!(dom = virDomainObjListFindByUUIDRef(driver->domains, uuid)) && + if (!(dom = virDomainObjListFindByUUID(driver->domains, uuid)) && !(dom = prlsdkAddDomainByUUID(driver, uuid))) goto cleanup; @@ -2225,7 +2225,7 @@ prlsdkHandleVmRemovedEvent(vzDriverPtr driver, { virDomainObjPtr dom = NULL; - dom = virDomainObjListFindByUUIDRef(driver->domains, uuid); + dom = virDomainObjListFindByUUID(driver->domains, uuid); /* domain was removed from the list from the libvirt * API function in current connection */ if (dom == NULL) @@ -2248,7 +2248,7 @@ prlsdkHandlePerfEvent(vzDriverPtr driver, virDomainObjPtr dom = NULL; vzDomObjPtr privdom = NULL; - if (!(dom = virDomainObjListFindByUUIDRef(driver->domains, uuid))) { + if (!(dom = virDomainObjListFindByUUID(driver->domains, uuid))) { PrlHandle_Free(event); return; } @@ -2271,7 +2271,7 @@ prlsdkHandleMigrationProgress(vzDriverPtr driver, PRL_HANDLE param = PRL_INVALID_HANDLE; PRL_RESULT pret; - if (!(dom = virDomainObjListFindByUUIDRef(driver->domains, uuid))) + if (!(dom = virDomainObjListFindByUUID(driver->domains, uuid))) return; pret = PrlEvent_GetParam(event, 0, ¶m); diff --git a/src/vz/vz_utils.c b/src/vz/vz_utils.c index 8f4e3e3474..13f5deeaa5 100644 --- a/src/vz/vz_utils.c +++ b/src/vz/vz_utils.c @@ -76,7 +76,7 @@ vzDomObjFromDomain(virDomainPtr domain) char uuidstr[VIR_UUID_STRING_BUFLEN]; vzDriverPtr driver = privconn->driver; - vm = virDomainObjListFindByUUIDRef(driver->domains, domain->uuid); + vm = virDomainObjListFindByUUID(driver->domains, domain->uuid); if (!vm) { virUUIDFormat(domain->uuid, uuidstr); virReportError(VIR_ERR_NO_DOMAIN, -- 2.13.6

On 04/20/2018 07:08 AM, John Ferlan wrote:
Now that every caller is using virDomainObjListFindByUUIDRef, let's just remove it and keep the name as virDomainObjListFindByUUID.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/bhyve/bhyve_driver.c | 4 ++-- src/conf/virdomainobjlist.c | 35 +++++++---------------------------- src/conf/virdomainobjlist.h | 2 -- src/libvirt_private.syms | 1 - src/libxl/libxl_driver.c | 4 ++-- src/lxc/lxc_driver.c | 4 ++-- src/openvz/openvz_driver.c | 2 +- src/qemu/qemu_driver.c | 4 ++-- src/test/test_driver.c | 4 ++-- src/uml/uml_driver.c | 4 ++-- src/util/virclosecallbacks.c | 4 ++-- src/vmware/vmware_driver.c | 2 +- src/vz/vz_driver.c | 4 ++-- src/vz/vz_sdk.c | 14 +++++++------- src/vz/vz_utils.c | 2 +- 15 files changed, 33 insertions(+), 57 deletions(-)
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 24c4a9c80e..bd8c6b30ed 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -168,7 +168,7 @@ bhyveDomObjFromDomain(virDomainPtr domain) bhyveConnPtr privconn = domain->conn->privateData; char uuidstr[VIR_UUID_STRING_BUFLEN];
- vm = virDomainObjListFindByUUIDRef(privconn->domains, domain->uuid); + vm = virDomainObjListFindByUUID(privconn->domains, domain->uuid); if (!vm) { virUUIDFormat(domain->uuid, uuidstr); virReportError(VIR_ERR_NO_DOMAIN, @@ -791,7 +791,7 @@ bhyveDomainLookupByUUID(virConnectPtr conn, virDomainObjPtr vm; virDomainPtr dom = NULL;
- vm = virDomainObjListFindByUUIDRef(privconn->domains, uuid); + vm = virDomainObjListFindByUUID(privconn->domains, uuid);
if (!vm) { char uuidstr[VIR_UUID_STRING_BUFLEN]; diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index c09e5e5d2f..02b52465d0 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -149,10 +149,10 @@ virDomainObjListFindByIDRef(virDomainObjListPtr doms, return virDomainObjListFindByIDInternal(doms, id, true); }
-static virDomainObjPtr -virDomainObjListFindByUUIDInternal(virDomainObjListPtr doms, - const unsigned char *uuid, - bool ref) + +virDomainObjPtr +virDomainObjListFindByUUID(virDomainObjListPtr doms, + const unsigned char *uuid) { char uuidstr[VIR_UUID_STRING_BUFLEN]; virDomainObjPtr obj; @@ -161,41 +161,20 @@ virDomainObjListFindByUUIDInternal(virDomainObjListPtr doms, virUUIDFormat(uuid, uuidstr);
obj = virHashLookup(doms->objs, uuidstr); - if (ref) { - virObjectRef(obj); - virObjectRWUnlock(doms); - } + virObjectRef(obj); + virObjectRWUnlock(doms); if (obj) { virObjectLock(obj); if (obj->removing) { virObjectUnlock(obj); - if (ref) - virObjectUnref(obj); + virObjectUnref(obj); obj = NULL; } } - if (!ref) - virObjectRWUnlock(doms); return obj; }
-virDomainObjPtr -virDomainObjListFindByUUID(virDomainObjListPtr doms, - const unsigned char *uuid) -{ - return virDomainObjListFindByUUIDInternal(doms, uuid, false); -} - - -virDomainObjPtr -virDomainObjListFindByUUIDRef(virDomainObjListPtr doms, - const unsigned char *uuid) -{ - return virDomainObjListFindByUUIDInternal(doms, uuid, true); -} - - virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms, const char *name) { diff --git a/src/conf/virdomainobjlist.h b/src/conf/virdomainobjlist.h index bb186bde30..1b77a95ba9 100644 --- a/src/conf/virdomainobjlist.h +++ b/src/conf/virdomainobjlist.h @@ -38,8 +38,6 @@ virDomainObjPtr virDomainObjListFindByIDRef(virDomainObjListPtr doms, int id); virDomainObjPtr virDomainObjListFindByUUID(virDomainObjListPtr doms, const unsigned char *uuid); -virDomainObjPtr virDomainObjListFindByUUIDRef(virDomainObjListPtr doms, - const unsigned char *uuid);
There's one more mention of this function in the comments for virDomainObjEndAPI() in domain_conf.c. Otherwise Reviewed-by: Jim Fehlig <jfehlig@suse.com> Regards, Jim
virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms, const char *name);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b31f599bd2..f6c76d4341 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -955,7 +955,6 @@ virDomainObjListFindByID; virDomainObjListFindByIDRef; virDomainObjListFindByName; virDomainObjListFindByUUID; -virDomainObjListFindByUUIDRef; virDomainObjListForEach; virDomainObjListGetActiveIDs; virDomainObjListGetInactiveNames; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index b66a1de5f1..24553c7272 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -313,7 +313,7 @@ libxlDomObjFromDomain(virDomainPtr dom) libxlDriverPrivatePtr driver = dom->conn->privateData; char uuidstr[VIR_UUID_STRING_BUFLEN];
- vm = virDomainObjListFindByUUIDRef(driver->domains, dom->uuid); + vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); if (!vm) { virUUIDFormat(dom->uuid, uuidstr); virReportError(VIR_ERR_NO_DOMAIN, @@ -1105,7 +1105,7 @@ libxlDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) virDomainObjPtr vm; virDomainPtr dom = NULL;
- vm = virDomainObjListFindByUUIDRef(driver->domains, uuid); + vm = virDomainObjListFindByUUID(driver->domains, uuid); if (!vm) { virReportError(VIR_ERR_NO_DOMAIN, NULL); goto cleanup; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 4097cef934..8773a3fd45 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -138,7 +138,7 @@ lxcDomObjFromDomain(virDomainPtr domain) virLXCDriverPtr driver = domain->conn->privateData; char uuidstr[VIR_UUID_STRING_BUFLEN];
- vm = virDomainObjListFindByUUIDRef(driver->domains, domain->uuid); + vm = virDomainObjListFindByUUID(driver->domains, domain->uuid); if (!vm) { virUUIDFormat(domain->uuid, uuidstr); virReportError(VIR_ERR_NO_DOMAIN, @@ -274,7 +274,7 @@ static virDomainPtr lxcDomainLookupByUUID(virConnectPtr conn, virDomainObjPtr vm; virDomainPtr dom = NULL;
- vm = virDomainObjListFindByUUIDRef(driver->domains, uuid); + vm = virDomainObjListFindByUUID(driver->domains, uuid);
if (!vm) { char uuidstr[VIR_UUID_STRING_BUFLEN]; diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index ba5ad8eeb4..f5a5526d28 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -95,7 +95,7 @@ openvzDomObjFromDomainLocked(struct openvz_driver *driver, virDomainObjPtr vm; char uuidstr[VIR_UUID_STRING_BUFLEN];
- if (!(vm = virDomainObjListFindByUUIDRef(driver->domains, uuid))) { + if (!(vm = virDomainObjListFindByUUID(driver->domains, uuid))) { virUUIDFormat(uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 5673d9fd8d..8a5b049296 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -203,7 +203,7 @@ qemuDomObjFromDomain(virDomainPtr domain) virQEMUDriverPtr driver = domain->conn->privateData; char uuidstr[VIR_UUID_STRING_BUFLEN];
- vm = virDomainObjListFindByUUIDRef(driver->domains, domain->uuid); + vm = virDomainObjListFindByUUID(driver->domains, domain->uuid); if (!vm) { virUUIDFormat(domain->uuid, uuidstr); virReportError(VIR_ERR_NO_DOMAIN, @@ -1555,7 +1555,7 @@ static virDomainPtr qemuDomainLookupByUUID(virConnectPtr conn, virDomainObjPtr vm; virDomainPtr dom = NULL;
- vm = virDomainObjListFindByUUIDRef(driver->domains, uuid); + vm = virDomainObjListFindByUUID(driver->domains, uuid);
if (!vm) { char uuidstr[VIR_UUID_STRING_BUFLEN]; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 3560c76fa5..249932de06 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -578,7 +578,7 @@ testDomObjFromDomain(virDomainPtr domain) testDriverPtr driver = domain->conn->privateData; char uuidstr[VIR_UUID_STRING_BUFLEN];
- vm = virDomainObjListFindByUUIDRef(driver->domains, domain->uuid); + vm = virDomainObjListFindByUUID(driver->domains, domain->uuid); if (!vm) { virUUIDFormat(domain->uuid, uuidstr); virReportError(VIR_ERR_NO_DOMAIN, @@ -1726,7 +1726,7 @@ static virDomainPtr testDomainLookupByUUID(virConnectPtr conn, virDomainPtr ret = NULL; virDomainObjPtr dom;
- if (!(dom = virDomainObjListFindByUUIDRef(privconn->domains, uuid))) { + if (!(dom = virDomainObjListFindByUUID(privconn->domains, uuid))) { virReportError(VIR_ERR_NO_DOMAIN, NULL); return NULL; } diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 5b941f1dd8..0bafd0902e 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -171,7 +171,7 @@ umlDomObjFromDomainLocked(struct uml_driver *driver, virDomainObjPtr vm; char uuidstr[VIR_UUID_STRING_BUFLEN];
- if (!(vm = virDomainObjListFindByUUIDRef(driver->domains, uuid))) { + if (!(vm = virDomainObjListFindByUUID(driver->domains, uuid))) { virUUIDFormat(uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN, @@ -773,7 +773,7 @@ static int umlProcessAutoDestroyDom(void *payload, return 0; }
- if (!(dom = virDomainObjListFindByUUIDRef(data->driver->domains, uuid))) { + if (!(dom = virDomainObjListFindByUUID(data->driver->domains, uuid))) { VIR_DEBUG("No domain object to kill"); return 0; } diff --git a/src/util/virclosecallbacks.c b/src/util/virclosecallbacks.c index 0a395eb167..60070dc8d9 100644 --- a/src/util/virclosecallbacks.c +++ b/src/util/virclosecallbacks.c @@ -342,8 +342,8 @@ virCloseCallbacksRun(virCloseCallbacksPtr closeCallbacks, virDomainObjPtr vm;
/* Grab a ref and lock to the vm */ - if (!(vm = virDomainObjListFindByUUIDRef(domains, - list->entries[i].uuid))) { + if (!(vm = virDomainObjListFindByUUID(domains, + list->entries[i].uuid))) { char uuidstr[VIR_UUID_STRING_BUFLEN]; virUUIDFormat(list->entries[i].uuid, uuidstr); VIR_DEBUG("No domain object with UUID %s", uuidstr); diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index f36fcc60a9..f94d192fd1 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -67,7 +67,7 @@ vmwareDomObjFromDomainLocked(struct vmware_driver *driver, virDomainObjPtr vm; char uuidstr[VIR_UUID_STRING_BUFLEN];
- if (!(vm = virDomainObjListFindByUUIDRef(driver->domains, uuid))) { + if (!(vm = virDomainObjListFindByUUID(driver->domains, uuid))) { virUUIDFormat(uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN, diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 2f1e00f420..8f8720a037 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -579,7 +579,7 @@ vzDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) virDomainPtr ret = NULL; virDomainObjPtr dom;
- dom = virDomainObjListFindByUUIDRef(privconn->driver->domains, uuid); + dom = virDomainObjListFindByUUID(privconn->driver->domains, uuid);
if (dom == NULL) { char uuidstr[VIR_UUID_STRING_BUFLEN]; @@ -814,7 +814,7 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup;
- dom = virDomainObjListFindByUUIDRef(driver->domains, def->uuid); + dom = virDomainObjListFindByUUID(driver->domains, def->uuid); if (dom == NULL) { virResetLastError(); if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) { diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 871ad843e2..bb8f15e4fe 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -1958,7 +1958,7 @@ prlsdkLoadDomain(vzDriverPtr driver, goto error;
virObjectLock(driver); - if (!(olddom = virDomainObjListFindByUUIDRef(driver->domains, def->uuid))) + if (!(olddom = virDomainObjListFindByUUID(driver->domains, def->uuid))) dom = virDomainObjListAdd(driver->domains, def, driver->xmlopt, 0, NULL); virObjectUnlock(driver);
@@ -2144,7 +2144,7 @@ prlsdkHandleVmStateEvent(vzDriverPtr driver, virDomainEventType lvEventType = 0; int lvEventTypeDetails = 0;
- dom = virDomainObjListFindByUUIDRef(driver->domains, uuid); + dom = virDomainObjListFindByUUID(driver->domains, uuid); if (dom == NULL) return;
@@ -2177,7 +2177,7 @@ prlsdkHandleVmConfigEvent(vzDriverPtr driver, virDomainObjPtr dom = NULL; bool job = false;
- dom = virDomainObjListFindByUUIDRef(driver->domains, uuid); + dom = virDomainObjListFindByUUID(driver->domains, uuid); if (dom == NULL) return;
@@ -2207,7 +2207,7 @@ prlsdkHandleVmAddedEvent(vzDriverPtr driver, { virDomainObjPtr dom = NULL;
- if (!(dom = virDomainObjListFindByUUIDRef(driver->domains, uuid)) && + if (!(dom = virDomainObjListFindByUUID(driver->domains, uuid)) && !(dom = prlsdkAddDomainByUUID(driver, uuid))) goto cleanup;
@@ -2225,7 +2225,7 @@ prlsdkHandleVmRemovedEvent(vzDriverPtr driver, { virDomainObjPtr dom = NULL;
- dom = virDomainObjListFindByUUIDRef(driver->domains, uuid); + dom = virDomainObjListFindByUUID(driver->domains, uuid); /* domain was removed from the list from the libvirt * API function in current connection */ if (dom == NULL) @@ -2248,7 +2248,7 @@ prlsdkHandlePerfEvent(vzDriverPtr driver, virDomainObjPtr dom = NULL; vzDomObjPtr privdom = NULL;
- if (!(dom = virDomainObjListFindByUUIDRef(driver->domains, uuid))) { + if (!(dom = virDomainObjListFindByUUID(driver->domains, uuid))) { PrlHandle_Free(event); return; } @@ -2271,7 +2271,7 @@ prlsdkHandleMigrationProgress(vzDriverPtr driver, PRL_HANDLE param = PRL_INVALID_HANDLE; PRL_RESULT pret;
- if (!(dom = virDomainObjListFindByUUIDRef(driver->domains, uuid))) + if (!(dom = virDomainObjListFindByUUID(driver->domains, uuid))) return;
pret = PrlEvent_GetParam(event, 0, ¶m); diff --git a/src/vz/vz_utils.c b/src/vz/vz_utils.c index 8f4e3e3474..13f5deeaa5 100644 --- a/src/vz/vz_utils.c +++ b/src/vz/vz_utils.c @@ -76,7 +76,7 @@ vzDomObjFromDomain(virDomainPtr domain) char uuidstr[VIR_UUID_STRING_BUFLEN]; vzDriverPtr driver = privconn->driver;
- vm = virDomainObjListFindByUUIDRef(driver->domains, domain->uuid); + vm = virDomainObjListFindByUUID(driver->domains, domain->uuid); if (!vm) { virUUIDFormat(domain->uuid, uuidstr); virReportError(VIR_ERR_NO_DOMAIN,

Rework the code such that virDomainObjListFindByID will always return a locked/ref counted object so that the callers can always do the same cleanup logic to call virDomainObjEndAPI. Makes accessing the objects much more consistent. NB: There were 2 callers (lxcDomainLookupByID and qemuDomainLookupByID) that were already using the ByID name, but not virDomainObjEndAPI - these were changed as well in this update/patch. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/bhyve/bhyve_driver.c | 2 +- src/conf/virdomainobjlist.c | 35 +++++++++-------------------------- src/conf/virdomainobjlist.h | 2 -- src/libvirt_private.syms | 1 - src/libxl/libxl_domain.c | 2 +- src/libxl/libxl_driver.c | 2 +- src/lxc/lxc_driver.c | 3 +-- src/openvz/openvz_driver.c | 2 +- src/qemu/qemu_driver.c | 5 ++--- src/test/test_driver.c | 2 +- src/uml/uml_driver.c | 2 +- src/vmware/vmware_driver.c | 2 +- src/vz/vz_driver.c | 2 +- 13 files changed, 20 insertions(+), 42 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index bd8c6b30ed..768578a43f 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -844,7 +844,7 @@ bhyveDomainLookupByID(virConnectPtr conn, virDomainObjPtr vm; virDomainPtr dom = NULL; - vm = virDomainObjListFindByIDRef(privconn->domains, id); + vm = virDomainObjListFindByID(privconn->domains, id); if (!vm) { virReportError(VIR_ERR_NO_DOMAIN, diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index 02b52465d0..d57ed10a5f 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -109,44 +109,27 @@ static int virDomainObjListSearchID(const void *payload, return want; } -static virDomainObjPtr -virDomainObjListFindByIDInternal(virDomainObjListPtr doms, - int id, - bool ref) + +virDomainObjPtr +virDomainObjListFindByID(virDomainObjListPtr doms, + int id) { virDomainObjPtr obj; + virObjectRWLockRead(doms); obj = virHashSearch(doms->objs, virDomainObjListSearchID, &id, NULL); - if (ref) { - virObjectRef(obj); - virObjectRWUnlock(doms); - } + virObjectRef(obj); + virObjectRWUnlock(doms); if (obj) { virObjectLock(obj); if (obj->removing) { virObjectUnlock(obj); - if (ref) - virObjectUnref(obj); + virObjectUnref(obj); obj = NULL; } } - if (!ref) - virObjectRWUnlock(doms); - return obj; -} - -virDomainObjPtr -virDomainObjListFindByID(virDomainObjListPtr doms, - int id) -{ - return virDomainObjListFindByIDInternal(doms, id, false); -} -virDomainObjPtr -virDomainObjListFindByIDRef(virDomainObjListPtr doms, - int id) -{ - return virDomainObjListFindByIDInternal(doms, id, true); + return obj; } diff --git a/src/conf/virdomainobjlist.h b/src/conf/virdomainobjlist.h index 1b77a95ba9..7e2dece3aa 100644 --- a/src/conf/virdomainobjlist.h +++ b/src/conf/virdomainobjlist.h @@ -34,8 +34,6 @@ virDomainObjListPtr virDomainObjListNew(void); virDomainObjPtr virDomainObjListFindByID(virDomainObjListPtr doms, int id); -virDomainObjPtr virDomainObjListFindByIDRef(virDomainObjListPtr doms, - int id); virDomainObjPtr virDomainObjListFindByUUID(virDomainObjListPtr doms, const unsigned char *uuid); virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index f6c76d4341..d2728749fb 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -952,7 +952,6 @@ virDomainObjListCollect; virDomainObjListConvert; virDomainObjListExport; virDomainObjListFindByID; -virDomainObjListFindByIDRef; virDomainObjListFindByName; virDomainObjListFindByUUID; virDomainObjListForEach; diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index e401327df4..d4859d6707 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -450,7 +450,7 @@ libxlDomainShutdownThread(void *opaque) cfg = libxlDriverConfigGet(driver); - vm = virDomainObjListFindByIDRef(driver->domains, ev->domid); + vm = virDomainObjListFindByID(driver->domains, ev->domid); if (!vm) { VIR_INFO("Received event for unknown domain ID %d", ev->domid); goto cleanup; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 24553c7272..55a93a489b 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -1082,7 +1082,7 @@ libxlDomainLookupByID(virConnectPtr conn, int id) virDomainObjPtr vm; virDomainPtr dom = NULL; - vm = virDomainObjListFindByIDRef(driver->domains, id); + vm = virDomainObjListFindByID(driver->domains, id); if (!vm) { virReportError(VIR_ERR_NO_DOMAIN, NULL); goto cleanup; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 8773a3fd45..ca01d369d5 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -262,8 +262,7 @@ static virDomainPtr lxcDomainLookupByID(virConnectPtr conn, dom = virGetDomain(conn, vm->def->name, vm->def->uuid, 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 f5a5526d28..c10d6df663 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -342,7 +342,7 @@ static virDomainPtr openvzDomainLookupByID(virConnectPtr conn, virDomainPtr dom = NULL; openvzDriverLock(driver); - vm = virDomainObjListFindByIDRef(driver->domains, id); + vm = virDomainObjListFindByID(driver->domains, id); openvzDriverUnlock(driver); if (!vm) { diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8a5b049296..7484b00e23 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1529,7 +1529,7 @@ static virDomainPtr qemuDomainLookupByID(virConnectPtr conn, virDomainObjPtr vm; virDomainPtr dom = NULL; - vm = virDomainObjListFindByID(driver->domains, id); + vm = virDomainObjListFindByID(driver->domains, id); if (!vm) { virReportError(VIR_ERR_NO_DOMAIN, @@ -1543,8 +1543,7 @@ static virDomainPtr qemuDomainLookupByID(virConnectPtr conn, dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return dom; } diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 249932de06..a1888c0c9f 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1708,7 +1708,7 @@ static virDomainPtr testDomainLookupByID(virConnectPtr conn, virDomainPtr ret = NULL; virDomainObjPtr dom; - if (!(dom = virDomainObjListFindByIDRef(privconn->domains, id))) { + if (!(dom = virDomainObjListFindByID(privconn->domains, id))) { virReportError(VIR_ERR_NO_DOMAIN, NULL); return NULL; } diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 0bafd0902e..b50ba1ba64 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -1379,7 +1379,7 @@ static virDomainPtr umlDomainLookupByID(virConnectPtr conn, virDomainPtr dom = NULL; umlDriverLock(driver); - vm = virDomainObjListFindByIDRef(driver->domains, id); + vm = virDomainObjListFindByID(driver->domains, id); umlDriverUnlock(driver); if (!vm) { diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index f94d192fd1..21c10b6605 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -825,7 +825,7 @@ vmwareDomainLookupByID(virConnectPtr conn, int id) virDomainPtr dom = NULL; vmwareDriverLock(driver); - vm = virDomainObjListFindByIDRef(driver->domains, id); + vm = virDomainObjListFindByID(driver->domains, id); vmwareDriverUnlock(driver); if (!vm) { diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 8f8720a037..d3fcae491a 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -555,7 +555,7 @@ vzDomainLookupByID(virConnectPtr conn, int id) virDomainPtr ret = NULL; virDomainObjPtr dom; - dom = virDomainObjListFindByIDRef(privconn->driver->domains, id); + dom = virDomainObjListFindByID(privconn->driver->domains, id); if (dom == NULL) { virReportError(VIR_ERR_NO_DOMAIN, NULL); -- 2.13.6

On 04/20/2018 07:08 AM, John Ferlan wrote:
Rework the code such that virDomainObjListFindByID will always return a locked/ref counted object so that the callers can always do the same cleanup logic to call virDomainObjEndAPI. Makes accessing the objects much more consistent.
NB: There were 2 callers (lxcDomainLookupByID and qemuDomainLookupByID) that were already using the ByID name, but not virDomainObjEndAPI - these were changed as well in this update/patch.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/bhyve/bhyve_driver.c | 2 +- src/conf/virdomainobjlist.c | 35 +++++++++-------------------------- src/conf/virdomainobjlist.h | 2 -- src/libvirt_private.syms | 1 - src/libxl/libxl_domain.c | 2 +- src/libxl/libxl_driver.c | 2 +- src/lxc/lxc_driver.c | 3 +-- src/openvz/openvz_driver.c | 2 +- src/qemu/qemu_driver.c | 5 ++--- src/test/test_driver.c | 2 +- src/uml/uml_driver.c | 2 +- src/vmware/vmware_driver.c | 2 +- src/vz/vz_driver.c | 2 +- 13 files changed, 20 insertions(+), 42 deletions(-)
Reviewed-by: Jim Fehlig <jfehlig@suse.com> Regards, Jim
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index bd8c6b30ed..768578a43f 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -844,7 +844,7 @@ bhyveDomainLookupByID(virConnectPtr conn, virDomainObjPtr vm; virDomainPtr dom = NULL;
- vm = virDomainObjListFindByIDRef(privconn->domains, id); + vm = virDomainObjListFindByID(privconn->domains, id);
if (!vm) { virReportError(VIR_ERR_NO_DOMAIN, diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index 02b52465d0..d57ed10a5f 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -109,44 +109,27 @@ static int virDomainObjListSearchID(const void *payload, return want; }
-static virDomainObjPtr -virDomainObjListFindByIDInternal(virDomainObjListPtr doms, - int id, - bool ref) + +virDomainObjPtr +virDomainObjListFindByID(virDomainObjListPtr doms, + int id) { virDomainObjPtr obj; + virObjectRWLockRead(doms); obj = virHashSearch(doms->objs, virDomainObjListSearchID, &id, NULL); - if (ref) { - virObjectRef(obj); - virObjectRWUnlock(doms); - } + virObjectRef(obj); + virObjectRWUnlock(doms); if (obj) { virObjectLock(obj); if (obj->removing) { virObjectUnlock(obj); - if (ref) - virObjectUnref(obj); + virObjectUnref(obj); obj = NULL; } } - if (!ref) - virObjectRWUnlock(doms); - return obj; -} - -virDomainObjPtr -virDomainObjListFindByID(virDomainObjListPtr doms, - int id) -{ - return virDomainObjListFindByIDInternal(doms, id, false); -}
-virDomainObjPtr -virDomainObjListFindByIDRef(virDomainObjListPtr doms, - int id) -{ - return virDomainObjListFindByIDInternal(doms, id, true); + return obj; }
diff --git a/src/conf/virdomainobjlist.h b/src/conf/virdomainobjlist.h index 1b77a95ba9..7e2dece3aa 100644 --- a/src/conf/virdomainobjlist.h +++ b/src/conf/virdomainobjlist.h @@ -34,8 +34,6 @@ virDomainObjListPtr virDomainObjListNew(void);
virDomainObjPtr virDomainObjListFindByID(virDomainObjListPtr doms, int id); -virDomainObjPtr virDomainObjListFindByIDRef(virDomainObjListPtr doms, - int id); virDomainObjPtr virDomainObjListFindByUUID(virDomainObjListPtr doms, const unsigned char *uuid); virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index f6c76d4341..d2728749fb 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -952,7 +952,6 @@ virDomainObjListCollect; virDomainObjListConvert; virDomainObjListExport; virDomainObjListFindByID; -virDomainObjListFindByIDRef; virDomainObjListFindByName; virDomainObjListFindByUUID; virDomainObjListForEach; diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index e401327df4..d4859d6707 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -450,7 +450,7 @@ libxlDomainShutdownThread(void *opaque)
cfg = libxlDriverConfigGet(driver);
- vm = virDomainObjListFindByIDRef(driver->domains, ev->domid); + vm = virDomainObjListFindByID(driver->domains, ev->domid); if (!vm) { VIR_INFO("Received event for unknown domain ID %d", ev->domid); goto cleanup; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 24553c7272..55a93a489b 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -1082,7 +1082,7 @@ libxlDomainLookupByID(virConnectPtr conn, int id) virDomainObjPtr vm; virDomainPtr dom = NULL;
- vm = virDomainObjListFindByIDRef(driver->domains, id); + vm = virDomainObjListFindByID(driver->domains, id); if (!vm) { virReportError(VIR_ERR_NO_DOMAIN, NULL); goto cleanup; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 8773a3fd45..ca01d369d5 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -262,8 +262,7 @@ static virDomainPtr lxcDomainLookupByID(virConnectPtr conn, dom = virGetDomain(conn, vm->def->name, vm->def->uuid, 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 f5a5526d28..c10d6df663 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -342,7 +342,7 @@ static virDomainPtr openvzDomainLookupByID(virConnectPtr conn, virDomainPtr dom = NULL;
openvzDriverLock(driver); - vm = virDomainObjListFindByIDRef(driver->domains, id); + vm = virDomainObjListFindByID(driver->domains, id); openvzDriverUnlock(driver);
if (!vm) { diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8a5b049296..7484b00e23 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1529,7 +1529,7 @@ static virDomainPtr qemuDomainLookupByID(virConnectPtr conn, virDomainObjPtr vm; virDomainPtr dom = NULL;
- vm = virDomainObjListFindByID(driver->domains, id); + vm = virDomainObjListFindByID(driver->domains, id);
if (!vm) { virReportError(VIR_ERR_NO_DOMAIN, @@ -1543,8 +1543,7 @@ static virDomainPtr qemuDomainLookupByID(virConnectPtr conn, dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return dom; }
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 249932de06..a1888c0c9f 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1708,7 +1708,7 @@ static virDomainPtr testDomainLookupByID(virConnectPtr conn, virDomainPtr ret = NULL; virDomainObjPtr dom;
- if (!(dom = virDomainObjListFindByIDRef(privconn->domains, id))) { + if (!(dom = virDomainObjListFindByID(privconn->domains, id))) { virReportError(VIR_ERR_NO_DOMAIN, NULL); return NULL; } diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 0bafd0902e..b50ba1ba64 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -1379,7 +1379,7 @@ static virDomainPtr umlDomainLookupByID(virConnectPtr conn, virDomainPtr dom = NULL;
umlDriverLock(driver); - vm = virDomainObjListFindByIDRef(driver->domains, id); + vm = virDomainObjListFindByID(driver->domains, id); umlDriverUnlock(driver);
if (!vm) { diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index f94d192fd1..21c10b6605 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -825,7 +825,7 @@ vmwareDomainLookupByID(virConnectPtr conn, int id) virDomainPtr dom = NULL;
vmwareDriverLock(driver); - vm = virDomainObjListFindByIDRef(driver->domains, id); + vm = virDomainObjListFindByID(driver->domains, id); vmwareDriverUnlock(driver);
if (!vm) { diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 8f8720a037..d3fcae491a 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -555,7 +555,7 @@ vzDomainLookupByID(virConnectPtr conn, int id) virDomainPtr ret = NULL; virDomainObjPtr dom;
- dom = virDomainObjListFindByIDRef(privconn->driver->domains, id); + dom = virDomainObjListFindByID(privconn->driver->domains, id);
if (dom == NULL) { virReportError(VIR_ERR_NO_DOMAIN, NULL);
participants (2)
-
Jim Fehlig
-
John Ferlan