From nobody Tue Feb 10 12:43:47 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1501259951903956.9020142552446; Fri, 28 Jul 2017 09:39:11 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7278BB8BA4; Fri, 28 Jul 2017 16:39:09 +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 50B3B5D759; Fri, 28 Jul 2017 16:39:09 +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 E786E4A468; Fri, 28 Jul 2017 16:39:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6SGd7Nu010349 for ; Fri, 28 Jul 2017 12:39:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 02FB15D759; Fri, 28 Jul 2017 16:39:07 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-46.phx2.redhat.com [10.3.117.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0B7E5D747 for ; Fri, 28 Jul 2017 16:39:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7278BB8BA4 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Fri, 28 Jul 2017 12:38:58 -0400 Message-Id: <20170728163901.21444-5-jferlan@redhat.com> In-Reply-To: <20170728163901.21444-1-jferlan@redhat.com> References: <20170728163901.21444-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/7] util: Introduce virObjectGetRWLockableObj 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 28 Jul 2017 16:39:10 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Introduce a helper to handle the error path more cleanly. The same as virObjectGetLockableObj. Signed-off-by: John Ferlan --- src/util/virobject.c | 51 ++++++++++++++++++++++++++++++------------------= --- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/util/virobject.c b/src/util/virobject.c index f9047a1..0db98c3 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -383,6 +383,22 @@ virObjectGetLockableObj(void *anyobj) } =20 =20 +static virObjectRWLockablePtr +virObjectGetRWLockableObj(void *anyobj) +{ + virObjectPtr obj; + + if (virObjectIsClass(anyobj, virObjectRWLockableClass)) + return anyobj; + + obj =3D anyobj; + VIR_WARN("Object %p (%s) is not a virObjectRWLockable instance", + anyobj, obj ? obj->klass->name : "(unknown)"); + + return NULL; +} + + /** * virObjectLock: * @anyobj: any instance of virObjectLockable or virObjectRWLockable @@ -422,18 +438,13 @@ virObjectLock(void *anyobj) int virObjectLockRead(void *anyobj) { - if (virObjectIsClass(anyobj, virObjectRWLockableClass)) { - virObjectRWLockablePtr obj =3D anyobj; - virRWLockRead(&obj->lock); - return 0; - } else { - virObjectPtr obj =3D anyobj; - VIR_WARN("Object %p (%s) is not a virObjectRWLockable instance", - anyobj, obj ? obj->klass->name : "(unknown)"); - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unable to obtain rwlock for object=3D%p"), anyob= j); - } - return -1; + virObjectRWLockablePtr obj =3D virObjectGetRWLockableObj(anyobj); + + if (!obj) + return -1; + + virRWLockRead(&obj->lock); + return 0; } =20 =20 @@ -454,18 +465,16 @@ virObjectLockRead(void *anyobj) int virObjectLockWrite(void *anyobj) { - if (virObjectIsClass(anyobj, virObjectRWLockableClass)) { - virObjectRWLockablePtr obj =3D anyobj; - virRWLockWrite(&obj->lock); - return 0; - } else { - virObjectPtr obj =3D anyobj; - VIR_WARN("Object %p (%s) is not a virObjectRWLockable instance", - anyobj, obj ? obj->klass->name : "(unknown)"); + virObjectRWLockablePtr obj =3D virObjectGetRWLockableObj(anyobj); + + if (!obj) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to obtain rwlock for object=3D%p"), anyob= j); + return -1; } - return -1; + + virRWLockWrite(&obj->lock); + return 0; } =20 =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list