From nobody Thu May 15 11:28: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 15076442805831022.0475533165925; Tue, 10 Oct 2017 07:04:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C6C517E44F; Tue, 10 Oct 2017 14:04:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 71D866C403; Tue, 10 Oct 2017 14:04:38 +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 61E29B3486; Tue, 10 Oct 2017 14:04:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9ADsXWf015286 for ; Tue, 10 Oct 2017 09:54:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id D78076C400; Tue, 10 Oct 2017 13:54:33 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-36.phx2.redhat.com [10.3.116.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E15F18ABA for ; Tue, 10 Oct 2017 13:54:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C6C517E44F Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Tue, 10 Oct 2017 09:54:26 -0400 Message-Id: <20171010135428.23097-2-jferlan@redhat.com> In-Reply-To: <20171010135428.23097-1-jferlan@redhat.com> References: <20171010135428.23097-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/3] nodedev: Convert virNodeDeviceObjList to use RWObjectLockable 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 10 Oct 2017 14:04:39 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Let's use the RWObjectLockable for the various list lock mgmt. Only time need Write lock will be for Add/Remove logic. Signed-off-by: John Ferlan --- src/conf/virnodedeviceobj.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index b0dcee16f1..49f4f436b8 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -40,7 +40,7 @@ struct _virNodeDeviceObj { }; =20 struct _virNodeDeviceObjList { - virObjectLockable parent; + virObjectRWLockable parent; =20 /* name string -> virNodeDeviceObj mapping * for O(1), lockless lookup-by-name */ @@ -63,7 +63,7 @@ virNodeDeviceObjOnceInit(void) virNodeDeviceObjDispose))) return -1; =20 - if (!(virNodeDeviceObjListClass =3D virClassNew(virClassForObjectLocka= ble(), + if (!(virNodeDeviceObjListClass =3D virClassNew(virClassForObjectRWLoc= kable(), "virNodeDeviceObjList", sizeof(virNodeDeviceObjL= ist), virNodeDeviceObjListDisp= ose))) @@ -231,10 +231,10 @@ virNodeDeviceObjListSearch(virNodeDeviceObjListPtr de= vs, { virNodeDeviceObjPtr obj; =20 - virObjectLock(devs); + virObjectRWLockRead(devs); obj =3D virHashSearch(devs->objs, callback, data, NULL); virObjectRef(obj); - virObjectUnlock(devs); + virObjectRWUnlock(devs); =20 if (obj) virObjectLock(obj); @@ -284,9 +284,9 @@ virNodeDeviceObjListFindByName(virNodeDeviceObjListPtr = devs, { virNodeDeviceObjPtr obj; =20 - virObjectLock(devs); + virObjectRWLockRead(devs); obj =3D virNodeDeviceObjListFindByNameLocked(devs, name); - virObjectUnlock(devs); + virObjectRWUnlock(devs); if (obj) virObjectLock(obj); =20 @@ -462,7 +462,7 @@ virNodeDeviceObjListNew(void) if (virNodeDeviceObjInitialize() < 0) return NULL; =20 - if (!(devs =3D virObjectLockableNew(virNodeDeviceObjListClass))) + if (!(devs =3D virObjectRWLockableNew(virNodeDeviceObjListClass))) return NULL; =20 if (!(devs->objs =3D virHashCreate(50, virObjectFreeHashData))) { @@ -487,7 +487,7 @@ virNodeDeviceObjListAssignDef(virNodeDeviceObjListPtr d= evs, { virNodeDeviceObjPtr obj; =20 - virObjectLock(devs); + virObjectRWLockWrite(devs); =20 if ((obj =3D virNodeDeviceObjListFindByNameLocked(devs, def->name))) { virObjectLock(obj); @@ -507,7 +507,7 @@ virNodeDeviceObjListAssignDef(virNodeDeviceObjListPtr d= evs, } =20 cleanup: - virObjectUnlock(devs); + virObjectRWUnlock(devs); return obj; } =20 @@ -524,12 +524,12 @@ virNodeDeviceObjListRemove(virNodeDeviceObjListPtr de= vs, =20 virObjectRef(obj); virObjectUnlock(obj); - virObjectLock(devs); + virObjectRWLockWrite(devs); virObjectLock(obj); virHashRemoveEntry(devs->objs, def->name); virObjectUnlock(obj); virObjectUnref(obj); - virObjectUnlock(devs); + virObjectRWUnlock(devs); } =20 =20 @@ -767,9 +767,9 @@ virNodeDeviceObjListNumOfDevices(virNodeDeviceObjListPt= r devs, struct virNodeDeviceCountData data =3D { .conn =3D conn, .filter =3D filter, .matchstr =3D cap, .count =3D = 0 }; =20 - virObjectLock(devs); + virObjectRWLockRead(devs); virHashForEach(devs->objs, virNodeDeviceObjListNumOfDevicesCallback, &= data); - virObjectUnlock(devs); + virObjectRWUnlock(devs); =20 return data.count; } @@ -828,9 +828,9 @@ virNodeDeviceObjListGetNames(virNodeDeviceObjListPtr de= vs, .conn =3D conn, .filter =3D filter, .matchstr =3D cap, .names =3D = names, .nnames =3D 0, .maxnames =3D maxnames, .error =3D false }; =20 - virObjectLock(devs); + virObjectRWLockRead(devs); virHashForEach(devs->objs, virNodeDeviceObjListGetNamesCallback, &data= ); - virObjectUnlock(devs); + virObjectRWUnlock(devs); =20 if (data.error) goto error; @@ -932,15 +932,15 @@ virNodeDeviceObjListExport(virConnectPtr conn, .conn =3D conn, .filter =3D filter, .flags =3D flags, .devices =3D NULL, .ndevices =3D 0, .error =3D false }; =20 - virObjectLock(devs); + virObjectRWLockRead(devs); if (devices && VIR_ALLOC_N(data.devices, virHashSize(devs->objs) + 1) < 0) { - virObjectUnlock(devs); + virObjectRWUnlock(devs); return -1; } =20 virHashForEach(devs->objs, virNodeDeviceObjListExportCallback, &data); - virObjectUnlock(devs); + virObjectRWUnlock(devs); =20 if (data.error) goto cleanup; --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list