While iterating with virDomainObjListForEach it is safe to remove
current element. But while iterating, 'doms' lock is already taken, so
can't use standard virDomainObjListRemove. So introduce
virDomainObjListRemoveLocked for this purpose.
---
src/conf/domain_conf.c | 17 +++++++++++++++++
src/conf/domain_conf.h | 2 ++
src/libvirt_private.syms | 1 +
3 files changed, 20 insertions(+)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index bf1fec6..e4f7288 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2199,6 +2199,23 @@ void virDomainObjListRemove(virDomainObjListPtr doms,
virObjectUnlock(doms);
}
+/* The caller must hold lock on 'doms' in addition to
'virDomainObjListRemove'
+ * requirements
+ *
+ * Can be used to remove current element while iterating with
+ * virDomainObjListForEach
+ */
+void virDomainObjListRemoveLocked(virDomainObjListPtr doms,
+ virDomainObjPtr dom)
+{
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+ virUUIDFormat(dom->def->uuid, uuidstr);
+ virObjectUnlock(dom);
+
+ virHashRemoveEntry(doms->objs, uuidstr);
+}
+
static int
virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddressPtr addr)
{
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index db3002b..e34143b 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2073,6 +2073,8 @@ virDomainObjCopyPersistentDef(virCapsPtr caps, virDomainXMLConfPtr
xmlconf,
void virDomainObjListRemove(virDomainObjListPtr doms,
virDomainObjPtr dom);
+void virDomainObjListRemoveLocked(virDomainObjListPtr doms,
+ virDomainObjPtr dom);
virDomainDeviceDefPtr virDomainDeviceDefParse(virCapsPtr caps,
virDomainDefPtr def,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 96eea0a..e6b6b1b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -270,6 +270,7 @@ virDomainObjListLoadAllConfigs;
virDomainObjListNew;
virDomainObjListNumOfDomains;
virDomainObjListRemove;
+virDomainObjListRemoveLocked;
virDomainObjNew;
virDomainObjSetDefTransient;
virDomainObjSetState;
--
1.8.1.4