From nobody Sun Feb 8 18:49:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1524573119146507.42870846783273; Tue, 24 Apr 2018 05:31:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6EEEE3134BB1; Tue, 24 Apr 2018 12:31:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 10FCD82F7F; Tue, 24 Apr 2018 12:31:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id F22331805971; Tue, 24 Apr 2018 12:31:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3OCSIV8014669 for ; Tue, 24 Apr 2018 08:28:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 34AA061F22; Tue, 24 Apr 2018 12:28:18 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-64.phx2.redhat.com [10.3.116.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id E798B61559 for ; Tue, 24 Apr 2018 12:28:17 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 24 Apr 2018 08:28:06 -0400 Message-Id: <20180424122809.12534-4-jferlan@redhat.com> In-Reply-To: <20180424122809.12534-1-jferlan@redhat.com> References: <20180424122809.12534-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/6] conf: Move and use virDomainObjListRemoveLocked X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 24 Apr 2018 12:31:58 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than open code within virDomainObjListRemove, just call the *Locked function. Additionally, add comments to virDomainObjListRemove to describe the usage model. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety --- src/conf/virdomainobjlist.c | 64 +++++++++++++++++++++++++----------------= ---- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index 6752f6c572..5725040552 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -355,26 +355,50 @@ virDomainObjPtr virDomainObjListAdd(virDomainObjListP= tr doms, } =20 =20 -/* - * The caller must hold a lock on the driver owning 'doms', - * and must also have locked 'dom', to ensure no one else - * is either waiting for 'dom' or still using it +/* The caller must hold lock on 'doms' in addition to 'virDomainObjListRem= ove' + * requirements + * + * Can be used to remove current element while iterating with + * virDomainObjListForEach */ -void virDomainObjListRemove(virDomainObjListPtr doms, - virDomainObjPtr dom) +void +virDomainObjListRemoveLocked(virDomainObjListPtr doms, + virDomainObjPtr dom) { char uuidstr[VIR_UUID_STRING_BUFLEN]; =20 - dom->removing =3D true; virUUIDFormat(dom->def->uuid, uuidstr); - virObjectRef(dom); - virObjectUnlock(dom); =20 - virObjectRWLockWrite(doms); - virObjectLock(dom); virHashRemoveEntry(doms->objs, uuidstr); virHashRemoveEntry(doms->objsName, dom->def->name); virObjectUnlock(dom); +} + + +/** + * @doms: Pointer to the domain object list + * @dom: Domain pointer from either after Add or FindBy* API where the + * @dom was successfully added to both the doms->objs and ->objsName + * hash tables that now would need to be removed. + * + * The caller must hold a lock on the driver owning 'doms', + * and must also have locked and ref counted 'dom', to ensure + * no one else is either waiting for 'dom' or still using it. + * + * When this function returns, @dom will be removed from the hash + * tables, unlocked, and returned with the refcnt that was present + * upon entry. + */ +void +virDomainObjListRemove(virDomainObjListPtr doms, + virDomainObjPtr dom) +{ + dom->removing =3D true; + virObjectRef(dom); + virObjectUnlock(dom); + virObjectRWLockWrite(doms); + virObjectLock(dom); + virDomainObjListRemoveLocked(doms, dom); virObjectUnref(dom); virObjectRWUnlock(doms); } @@ -446,24 +470,6 @@ virDomainObjListRename(virDomainObjListPtr doms, return ret; } =20 -/* The caller must hold lock on 'doms' in addition to 'virDomainObjListRem= ove' - * 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); - - virHashRemoveEntry(doms->objs, uuidstr); - virHashRemoveEntry(doms->objsName, dom->def->name); - virObjectUnlock(dom); -} - =20 static virDomainObjPtr virDomainObjListLoadConfig(virDomainObjListPtr doms, --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list