Introduce a helper which will return a list of all domain objects inside
of the list without filtering and thus without the need to lock
individual members.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/virdomainobjlist.c | 32 ++++++++++++++++++++------------
src/conf/virdomainobjlist.h | 4 ++++
src/libvirt_private.syms | 1 +
3 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c
index 2569454ff8..4968dfcf3e 100644
--- a/src/conf/virdomainobjlist.c
+++ b/src/conf/virdomainobjlist.c
@@ -913,6 +913,24 @@ virDomainObjListCollectIterator(void *payload,
}
+void
+virDomainObjListCollectAll(virDomainObjList *domlist,
+ virDomainObj ***vms,
+ size_t *nvms)
+{
+ struct virDomainListData data = { NULL, 0 };
+
+ virObjectRWLockRead(domlist);
+ data.vms = g_new0(virDomainObj *, virHashSize(domlist->objs));
+
+ virHashForEach(domlist->objs, virDomainObjListCollectIterator, &data);
+ virObjectRWUnlock(domlist);
+
+ *nvms = data.nvms;
+ *vms = data.vms;
+}
+
+
static void
virDomainObjListFilter(virDomainObj ***list,
size_t *nvms,
@@ -954,18 +972,8 @@ virDomainObjListCollect(virDomainObjList *domlist,
virDomainObjListACLFilter filter,
unsigned int flags)
{
- struct virDomainListData data = { NULL, 0 };
-
- virObjectRWLockRead(domlist);
- data.vms = g_new0(virDomainObj *, virHashSize(domlist->objs));
-
- virHashForEach(domlist->objs, virDomainObjListCollectIterator, &data);
- virObjectRWUnlock(domlist);
-
- virDomainObjListFilter(&data.vms, &data.nvms, conn, filter, flags);
-
- *nvms = data.nvms;
- *vms = data.vms;
+ virDomainObjListCollectAll(domlist, vms, nvms);
+ virDomainObjListFilter(vms, nvms, conn, filter, flags);
return 0;
}
diff --git a/src/conf/virdomainobjlist.h b/src/conf/virdomainobjlist.h
index cfa165d56f..8c53680374 100644
--- a/src/conf/virdomainobjlist.h
+++ b/src/conf/virdomainobjlist.h
@@ -145,6 +145,10 @@ virDomainObjListForEach(virDomainObjList *doms,
VIR_CONNECT_LIST_DOMAINS_FILTERS_SNAPSHOT | \
VIR_CONNECT_LIST_DOMAINS_FILTERS_CHECKPOINT)
+void
+virDomainObjListCollectAll(virDomainObjList *domlist,
+ virDomainObj ***vms,
+ size_t *nvms);
int
virDomainObjListCollect(virDomainObjList *doms,
virConnectPtr conn,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index ae746a2d51..54a3859604 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1209,6 +1209,7 @@ virDomainMomentObjNew;
# conf/virdomainobjlist.h
virDomainObjListAdd;
virDomainObjListCollect;
+virDomainObjListCollectAll;
virDomainObjListConvert;
virDomainObjListExport;
virDomainObjListFindByID;
--
2.38.1