From nobody Wed May 14 15:42:51 2025 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522271987398831.3887560088975; Wed, 28 Mar 2018 14:19:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C18008124B; Wed, 28 Mar 2018 21:19:45 +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 729E16A944; Wed, 28 Mar 2018 21:19:45 +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 175DB181BA02; Wed, 28 Mar 2018 21:19:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2SLJgx2000499 for ; Wed, 28 Mar 2018 17:19:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9704C63143; Wed, 28 Mar 2018 21:19:42 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-109.phx2.redhat.com [10.3.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57AE063142 for ; Wed, 28 Mar 2018 21:19:42 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 28 Mar 2018 17:19:27 -0400 Message-Id: <20180328211933.8033-4-jferlan@redhat.com> In-Reply-To: <20180328211933.8033-1-jferlan@redhat.com> References: <20180328211933.8033-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 3/9] interface: Alter virInterfaceObjListRemove processing 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 28 Mar 2018 21:19:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Current processing requires a "fire dance" unlocking the @obj, adding an @obj ref, locking the @interfaces, and relocking @obj in order to ensure proper lock ordering. This can be avoided by changing virInterfaceObjListRemove to take @name instead of @obj. Then, we can lock the @interfaces list, look up the @obj by @name (like we do when adding), and remove the @obj from the list. This removes the last reference to the object effectively reaping it. NB: Since prior to calling we remove the reference to the object we cannot pass anything contained within the object (such as the obj->def or obj->def->name) because it's possible that the object could be reaped by two competing remove threads. Signed-off-by: John Ferlan --- src/conf/virinterfaceobj.c | 26 +++++++++++++++++--------- src/conf/virinterfaceobj.h | 2 +- src/test/test_driver.c | 4 ++-- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index f90c0bd9c..c3a7d4cd8 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -358,20 +358,28 @@ virInterfaceObjListAssignDef(virInterfaceObjListPtr i= nterfaces, } =20 =20 +/* + * virInterfaceObjListRemove: + * @interfaces: list of interface objects + * @name: name of interface definition to remove + * + * Find the object by name in the list, remove the object from the + * list hash table, and free the object. + * + * Upon entry it's expected that prior to entry any locks on + * the object related to @name will have been removed. + */ void virInterfaceObjListRemove(virInterfaceObjListPtr interfaces, - virInterfaceObjPtr obj) + const char *name) { - if (!obj) - return; + virInterfaceObjPtr obj; =20 - virObjectRef(obj); - virObjectUnlock(obj); virObjectRWLockWrite(interfaces); - virObjectLock(obj); - virHashRemoveEntry(interfaces->objsName, obj->def->name); - virObjectUnlock(obj); - virObjectUnref(obj); + if ((obj =3D virInterfaceObjListFindByNameLocked(interfaces, name))) { + virHashRemoveEntry(interfaces->objsName, name); + virInterfaceObjEndAPI(&obj); + } virObjectRWUnlock(interfaces); } =20 diff --git a/src/conf/virinterfaceobj.h b/src/conf/virinterfaceobj.h index 799d38038..82eb2ee87 100644 --- a/src/conf/virinterfaceobj.h +++ b/src/conf/virinterfaceobj.h @@ -66,7 +66,7 @@ virInterfaceObjListAssignDef(virInterfaceObjListPtr inter= faces, =20 void virInterfaceObjListRemove(virInterfaceObjListPtr interfaces, - virInterfaceObjPtr obj); + const char *name); =20 typedef bool (*virInterfaceObjListFilter)(virConnectPtr conn, diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 99c27cc0a..ddddd8dcb 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4092,8 +4092,8 @@ testInterfaceUndefine(virInterfacePtr iface) if (!(obj =3D testInterfaceObjFindByName(privconn, iface->name))) return -1; =20 - virInterfaceObjListRemove(privconn->ifaces, obj); - virObjectUnref(obj); + virInterfaceObjEndAPI(&obj); + virInterfaceObjListRemove(privconn->ifaces, iface->name); =20 return 0; } --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list