[PATCH 11/12] conf: virDomainObjListRemoveLocked function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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. This is required to fix deadlock
in libxl driver.
---
 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


--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]