From 8f65fcb4a4c5b1151beedd0eb6d61d1f6d448b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 13 Jun 2013 03:54:08 +0200 Subject: [PATCH] conf: virDomainObjListRemoveLocked function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Signed-off-by: Marek Marczykowski-Górecki --- 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 bb0faf52d8..f80b69074f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2343,6 +2343,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 7200062232..da83eb6060 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2260,6 +2260,8 @@ virDomainDefPtr virDomainObjCopyPersistentDef(virDomainObjPtr dom, void virDomainObjListRemove(virDomainObjListPtr doms, virDomainObjPtr dom); +void virDomainObjListRemoveLocked(virDomainObjListPtr doms, + virDomainObjPtr dom); virDomainDeviceDefPtr virDomainDeviceDefParse(const char *xmlStr, virDomainDefPtr def, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0881af43ad..6df55005e9 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -311,6 +311,7 @@ virDomainObjListLoadAllConfigs; virDomainObjListNew; virDomainObjListNumOfDomains; virDomainObjListRemove; +virDomainObjListRemoveLocked; virDomainObjNew; virDomainObjSetDefTransient; virDomainObjSetState;