From nobody Mon May 6 10:23:46 2024 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.zoho.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 1498140177129172.34090335568715; Thu, 22 Jun 2017 07:02:57 -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 65070C001096; Thu, 22 Jun 2017 14:02:54 +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 38A9E5C3FA; Thu, 22 Jun 2017 14:02:54 +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 DE3864E984; Thu, 22 Jun 2017 14:02:53 +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 v5ME2p4n004449 for ; Thu, 22 Jun 2017 10:02:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7806E5D969; Thu, 22 Jun 2017 14:02:51 +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 34B1F5D967 for ; Thu, 22 Jun 2017 14:02:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 65070C001096 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 65070C001096 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 10:02:31 -0400 Message-Id: <20170622140246.31777-2-jferlan@redhat.com> In-Reply-To: <20170622140246.31777-1-jferlan@redhat.com> References: <20170622140246.31777-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 01/16] util: Generate a common internal only error print 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.32]); Thu, 22 Jun 2017 14:02:55 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If virObjectIsClass fails "internally" to virobject.c, create a macro to generate the VIR_WARN describing what the problem is. Also improve the checks and message a bit to indicate which was the failure - whether the obj was NULL or just not the right class Signed-off-by: John Ferlan --- src/util/virobject.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/util/virobject.c b/src/util/virobject.c index 34805d3..ff9385b 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -47,6 +47,16 @@ struct _virClass { virObjectDisposeCallback dispose; }; =20 +#define VIR_OBJECT_USAGE_PRINT_WARNING(anyobj, objclass) = \ + do { = \ + virObjectPtr obj =3D anyobj; = \ + if (!obj) = \ + VIR_WARN("Object cannot be NULL"); = \ + else = \ + VIR_WARN("Object %p (%s) is not a %s instance", = \ + anyobj, obj->klass->name, #objclass); = \ + } while (0) + static virClassPtr virObjectClass; static virClassPtr virObjectLockableClass; =20 @@ -312,14 +322,10 @@ virObjectRef(void *anyobj) static virObjectLockablePtr virObjectGetLockableObj(void *anyobj) { - virObjectPtr obj; - if (virObjectIsClass(anyobj, virObjectLockableClass)) return anyobj; =20 - obj =3D anyobj; - VIR_WARN("Object %p (%s) is not a virObjectLockable instance", - anyobj, obj ? obj->klass->name : "(unknown)"); + VIR_OBJECT_USAGE_PRINT_WARNING(anyobj, virObjectLockableClass); =20 return NULL; } --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 10:23:46 2024 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.zoho.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 1498140654387672.6531324223133; Thu, 22 Jun 2017 07:10:54 -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 5CC05142869; Thu, 22 Jun 2017 14:10:51 +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 E66875C7A5; Thu, 22 Jun 2017 14:10:50 +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 9E1444E987; Thu, 22 Jun 2017 14:10:49 +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 v5ME2qNQ004457 for ; Thu, 22 Jun 2017 10:02:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 26DEA5D967; Thu, 22 Jun 2017 14:02:52 +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 DB1425D96A for ; Thu, 22 Jun 2017 14:02:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5CC05142869 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5CC05142869 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 10:02:32 -0400 Message-Id: <20170622140246.31777-3-jferlan@redhat.com> In-Reply-To: <20170622140246.31777-1-jferlan@redhat.com> References: <20170622140246.31777-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 02/16] util: Add safety net of checks to ensure valid object 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.39]); Thu, 22 Jun 2017 14:10:52 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The virObject logic "assumes" that whatever is passed to its API's would be some sort of virObjectPtr; however, if it is not then some really bad things can happen. So far there's been only virObject{Ref|Unref}, virObject{Lock|Unlock}, and virObjectIsClass and the virObject and virObjectLockable class consumers have been well behaved and code well tested. Soon there will be more consumers and one such consumer tripped over this during testing by passing a virHashTablePtr to virObjectIsClass which ends up calling virClassIsDerivedFrom using "obj->klass", which wasn't really a klass object causing one of those bad things to happen. To avoid the future possibility that a non virObject class memory was passed to some virObject* API, this patch adds two new checks - one to validate that the object has the 0xCAFExxxx value in obj->->u.s.magic and the other to ensure obj->u.s.magic doesn't "wrap" some day to 0xCAFF0000 if we ever get that many object classes. The check is also moved before the name VIR_STRDUP to avoid the extra VIR_FREE that would be required on the failure path. It is still left up to the caller to handle the failed API calls just as it would be if it passed a NULL opaque pointer anyobj. Signed-off-by: John Ferlan --- src/util/virobject.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/util/virobject.c b/src/util/virobject.c index ff9385b..443718b 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -47,14 +47,21 @@ struct _virClass { virObjectDisposeCallback dispose; }; =20 +#define VIR_OBJECT_NOTVALID(obj) (!obj || ((obj->u.s.magic & 0xCAFE0000) != =3D 0xCAFE0000)) + #define VIR_OBJECT_USAGE_PRINT_WARNING(anyobj, objclass) = \ do { = \ virObjectPtr obj =3D anyobj; = \ - if (!obj) = \ - VIR_WARN("Object cannot be NULL"); = \ - else = \ + if (VIR_OBJECT_NOTVALID(obj)) { = \ + if (!obj) = \ + VIR_WARN("Object cannot be NULL"); = \ + else = \ + VIR_WARN("Object %p has a bad magic number %X", = \ + obj, obj->u.s.magic); = \ + } else { = \ VIR_WARN("Object %p (%s) is not a %s instance", = \ anyobj, obj->klass->name, #objclass); = \ + } = \ } while (0) =20 static virClassPtr virObjectClass; @@ -153,9 +160,14 @@ virClassNew(virClassPtr parent, goto error; =20 klass->parent =3D parent; + klass->magic =3D virAtomicIntInc(&magicCounter); + if (klass->magic > 0xCAFEFFFF) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("too many object classes defined")); + goto error; + } if (VIR_STRDUP(klass->name, name) < 0) goto error; - klass->magic =3D virAtomicIntInc(&magicCounter); klass->objectSize =3D objectSize; klass->dispose =3D dispose; =20 @@ -272,7 +284,7 @@ virObjectUnref(void *anyobj) { virObjectPtr obj =3D anyobj; =20 - if (!obj) + if (VIR_OBJECT_NOTVALID(obj)) return false; =20 bool lastRef =3D virAtomicIntDecAndTest(&obj->u.s.refs); @@ -311,7 +323,7 @@ virObjectRef(void *anyobj) { virObjectPtr obj =3D anyobj; =20 - if (!obj) + if (VIR_OBJECT_NOTVALID(obj)) return NULL; virAtomicIntInc(&obj->u.s.refs); PROBE(OBJECT_REF, "obj=3D%p", obj); @@ -389,7 +401,7 @@ virObjectIsClass(void *anyobj, virClassPtr klass) { virObjectPtr obj =3D anyobj; - if (!obj) + if (VIR_OBJECT_NOTVALID(obj)) return false; =20 return virClassIsDerivedFrom(obj->klass, klass); --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 10:23:46 2024 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.zoho.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 14981401854190.18245401075023437; Thu, 22 Jun 2017 07:03:05 -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 B383164A71; Thu, 22 Jun 2017 14:02:57 +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 8E5835C7A9; Thu, 22 Jun 2017 14:02:57 +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 46061184383E; Thu, 22 Jun 2017 14:02:57 +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 v5ME2qSI004462 for ; Thu, 22 Jun 2017 10:02:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8ED945D967; Thu, 22 Jun 2017 14:02:52 +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 4E6FE5D969 for ; Thu, 22 Jun 2017 14:02:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B383164A71 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B383164A71 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 10:02:33 -0400 Message-Id: <20170622140246.31777-4-jferlan@redhat.com> In-Reply-To: <20170622140246.31777-1-jferlan@redhat.com> References: <20170622140246.31777-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 03/16] util: Introduce virObjectLookupKeys 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.26]); Thu, 22 Jun 2017 14:02:58 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a new virObjectLockable child virObjectLookupKeys which can be used by various driver/vir*object consumers as the means to describe the lookup keys @uuid and/or @name. Either or both keys may be defined/used and it's left up to the object consumer to utilize the lookup keys as it sees fit. Eventually, these will be the keys used to insert the object into the hash table(s) for the driver/vir*object consumer. Signed-off-by: John Ferlan --- src/libvirt_private.syms | 2 ++ src/util/virobject.c | 78 ++++++++++++++++++++++++++++++++++++++++++++= +++- src/util/virobject.h | 17 +++++++++++ 3 files changed, 96 insertions(+), 1 deletion(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c1e9471..44d712d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2274,6 +2274,7 @@ virNumaSetupMemoryPolicy; # util/virobject.h virClassForObject; virClassForObjectLockable; +virClassForObjectLookupKeys; virClassIsDerivedFrom; virClassName; virClassNew; @@ -2284,6 +2285,7 @@ virObjectListFree; virObjectListFreeCount; virObjectLock; virObjectLockableNew; +virObjectLookupKeysNew; virObjectNew; virObjectRef; virObjectUnlock; diff --git a/src/util/virobject.c b/src/util/virobject.c index 443718b..6908e8d 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -66,8 +66,10 @@ struct _virClass { =20 static virClassPtr virObjectClass; static virClassPtr virObjectLockableClass; +static virClassPtr virObjectLookupKeysClass; =20 static void virObjectLockableDispose(void *anyobj); +static void virObjectLookupKeysDispose(void *anyobj); =20 static int virObjectOnceInit(void) @@ -84,6 +86,12 @@ virObjectOnceInit(void) virObjectLockableDispose))) return -1; =20 + if (!(virObjectLookupKeysClass =3D virClassNew(virObjectLockableClass, + "virObjectLookupKeys", + sizeof(virObjectLookupKey= s), + virObjectLookupKeysDispos= e))) + return -1; + return 0; } =20 @@ -121,6 +129,21 @@ virClassForObjectLockable(void) =20 =20 /** + * virClassForObjectLookupKeys: + * + * Returns the class instance for the virObjectLookupKeys type + */ +virClassPtr +virClassForObjectLookupKeys(void) +{ + if (virObjectInitialize() < 0) + return NULL; + + return virObjectLookupKeysClass; +} + + +/** * virClassNew: * @parent: the parent class * @name: the class name @@ -268,6 +291,58 @@ virObjectLockableDispose(void *anyobj) } =20 =20 +void * +virObjectLookupKeysNew(virClassPtr klass, + const char *uuid, + const char *name) +{ + virObjectLookupKeysPtr obj; + + if (!virClassIsDerivedFrom(klass, virClassForObjectLookupKeys())) { + virReportInvalidArg(klass, + _("Class %s must derive from virObjectLookupKe= ys"), + virClassName(klass)); + return NULL; + } + + if (!uuid && !name) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("no key, either 'uuid' or 'name' must be defined"= )); + return NULL; + } + + if (!(obj =3D virObjectLockableNew(klass))) + return NULL; + + if (VIR_STRDUP(obj->uuid, uuid) < 0) + goto error; + + if (VIR_STRDUP(obj->name, name) < 0) + goto error; + + VIR_DEBUG("obj=3D%p, uuid=3D%s name=3D%s", + obj, NULLSTR(obj->uuid), NULLSTR(obj->name)); + + return obj; + + error: + virObjectUnref(obj); + return NULL; +} + + +static void +virObjectLookupKeysDispose(void *anyobj) +{ + virObjectLookupKeysPtr obj =3D anyobj; + + VIR_DEBUG("dispose obj=3D%p", obj); + + VIR_FREE(obj->uuid); + VIR_FREE(obj->name); +} + + /** * virObjectUnref: * @anyobj: any instance of virObjectPtr @@ -334,7 +409,8 @@ virObjectRef(void *anyobj) static virObjectLockablePtr virObjectGetLockableObj(void *anyobj) { - if (virObjectIsClass(anyobj, virObjectLockableClass)) + if (virObjectIsClass(anyobj, virObjectLockableClass) || + virObjectIsClass(anyobj, virObjectLookupKeysClass)) return anyobj; =20 VIR_OBJECT_USAGE_PRINT_WARNING(anyobj, virObjectLockableClass); diff --git a/src/util/virobject.h b/src/util/virobject.h index f4c292b..1cade9d 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -34,6 +34,9 @@ typedef virObject *virObjectPtr; typedef struct _virObjectLockable virObjectLockable; typedef virObjectLockable *virObjectLockablePtr; =20 +typedef struct _virObjectLookupKeys virObjectLookupKeys; +typedef virObjectLookupKeys *virObjectLookupKeysPtr; + typedef void (*virObjectDisposeCallback)(void *obj); =20 /* Most code should not play with the contents of this struct; however, @@ -59,9 +62,17 @@ struct _virObjectLockable { virMutex lock; }; =20 +struct _virObjectLookupKeys { + virObjectLockable parent; + + char *uuid; + char *name; +}; + =20 virClassPtr virClassForObject(void); virClassPtr virClassForObjectLockable(void); +virClassPtr virClassForObjectLookupKeys(void); =20 # ifndef VIR_PARENT_REQUIRED # define VIR_PARENT_REQUIRED ATTRIBUTE_NONNULL(1) @@ -108,6 +119,12 @@ void * virObjectLockableNew(virClassPtr klass) ATTRIBUTE_NONNULL(1); =20 +void * +virObjectLookupKeysNew(virClassPtr klass, + const char *uuid, + const char *name) + ATTRIBUTE_NONNULL(1); + void virObjectLock(void *lockableobj) ATTRIBUTE_NONNULL(1); --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 10:23:46 2024 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.zoho.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 1498140187310430.4952463587109; Thu, 22 Jun 2017 07:03:07 -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 1835F769E4; Thu, 22 Jun 2017 14:02:59 +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 E53C15D960; Thu, 22 Jun 2017 14:02:58 +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 9E3181853DD3; Thu, 22 Jun 2017 14:02:58 +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 v5ME2rpr004469 for ; Thu, 22 Jun 2017 10:02:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 395F75D969; Thu, 22 Jun 2017 14:02:53 +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 E969D5D967 for ; Thu, 22 Jun 2017 14:02:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1835F769E4 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=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1835F769E4 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 10:02:34 -0400 Message-Id: <20170622140246.31777-5-jferlan@redhat.com> In-Reply-To: <20170622140246.31777-1-jferlan@redhat.com> References: <20170622140246.31777-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 04/16] util: Introduce virObjectLookupKeysGet{UUID|Name} 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.27]); Thu, 22 Jun 2017 14:03:00 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a pair of accessor API's for the object elements which will return the requested key value from the object to the caller. It is up to the caller to check the returned key value and error if the return value is NULL. Signed-off-by: John Ferlan --- src/libvirt_private.syms | 2 ++ src/util/virobject.c | 48 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virobject.h | 6 ++++++ 3 files changed, 56 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 44d712d..bfc68eb 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2285,6 +2285,8 @@ virObjectListFree; virObjectListFreeCount; virObjectLock; virObjectLockableNew; +virObjectLookupKeysGetName; +virObjectLookupKeysGetUUID; virObjectLookupKeysNew; virObjectNew; virObjectRef; diff --git a/src/util/virobject.c b/src/util/virobject.c index 6908e8d..862d46b 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -419,6 +419,18 @@ virObjectGetLockableObj(void *anyobj) } =20 =20 +static virObjectLookupKeysPtr +virObjectGetLookupKeysObj(void *anyobj) +{ + if (virObjectIsClass(anyobj, virObjectLookupKeysClass)) + return anyobj; + + VIR_OBJECT_USAGE_PRINT_WARNING(anyobj, virObjectLookupKeysClass); + + return NULL; +} + + /** * virObjectLock: * @anyobj: any instance of virObjectLockablePtr @@ -570,3 +582,39 @@ virObjectListFreeCount(void *list, =20 VIR_FREE(list); } + + +/** + * virObjectLookupKeysGetUUID + * @anyobj: Pointer to a LookupKeys object + * + * Returns: Pointer to the object's uuid key value or possibly NULL + */ +const char * +virObjectLookupKeysGetUUID(void *anyobj) +{ + virObjectLookupKeysPtr obj =3D virObjectGetLookupKeysObj(anyobj); + + if (!obj) + return NULL; + + return obj->uuid; +} + + +/** + * virObjectLookupKeysGetName + * @anyobj: Pointer to a LookupKeys object + * + * Returns: Pointer to the object's name key value or possibly NULL + */ +const char * +virObjectLookupKeysGetName(void *anyobj) +{ + virObjectLookupKeysPtr obj =3D virObjectGetLookupKeysObj(anyobj); + + if (!obj) + return NULL; + + return obj->name; +} diff --git a/src/util/virobject.h b/src/util/virobject.h index 1cade9d..e77634b 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -140,4 +140,10 @@ void virObjectListFreeCount(void *list, size_t count); =20 +const char * +virObjectLookupKeysGetUUID(void *anyobj); + +const char * +virObjectLookupKeysGetName(void *anyobj); + #endif /* __VIR_OBJECT_H */ --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 10:23:46 2024 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.zoho.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 1498140663565294.94296726644575; Thu, 22 Jun 2017 07:11:03 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7D5017C83C; Thu, 22 Jun 2017 14:10:59 +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 580A76FE4F; Thu, 22 Jun 2017 14:10:59 +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 E95234E988; Thu, 22 Jun 2017 14:10:58 +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 v5ME2r71004474 for ; Thu, 22 Jun 2017 10:02:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9F73A5D969; Thu, 22 Jun 2017 14:02:53 +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 5F4135D967 for ; Thu, 22 Jun 2017 14:02:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7D5017C83C 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=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7D5017C83C From: John Ferlan To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 10:02:35 -0400 Message-Id: <20170622140246.31777-6-jferlan@redhat.com> In-Reply-To: <20170622140246.31777-1-jferlan@redhat.com> References: <20170622140246.31777-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 05/16] interface: Use virObjectLookupKeys 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 22 Jun 2017 14:11:00 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use the virObjectLookupKeys rather than virObjectLockable. Signed-off-by: John Ferlan --- src/conf/virinterfaceobj.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index 106f232..243ff33 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -33,7 +33,7 @@ VIR_LOG_INIT("conf.virinterfaceobj"); =20 struct _virInterfaceObj { - virObjectLockable parent; + virObjectLookupKeys parent; =20 bool active; /* true if interface is active (up) */ virInterfaceDefPtr def; /* The interface definition */ @@ -52,7 +52,7 @@ static void virInterfaceObjDispose(void *obj); static int virInterfaceObjOnceInit(void) { - if (!(virInterfaceObjClass =3D virClassNew(virClassForObjectLockable(), + if (!(virInterfaceObjClass =3D virClassNew(virClassForObjectLookupKeys= (), "virInterfaceObj", sizeof(virInterfaceObj), virInterfaceObjDispose))) @@ -81,7 +81,7 @@ virInterfaceObjNew(virInterfaceDefPtr def) if (virInterfaceObjInitialize() < 0) return NULL; =20 - if (!(obj =3D virObjectLockableNew(virInterfaceObjClass))) + if (!(obj =3D virObjectLookupKeysNew(virInterfaceObjClass, NULL, def->= name))) return NULL; =20 virObjectLock(obj); --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 10:23:46 2024 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.zoho.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 1498140188169123.02126252196638; Thu, 22 Jun 2017 07:03:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5A4F8C000956; Thu, 22 Jun 2017 14:03:02 +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 21F746EE43; Thu, 22 Jun 2017 14:03:02 +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 CE38E1853E2E; Thu, 22 Jun 2017 14:03:01 +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 v5ME2sMt004482 for ; Thu, 22 Jun 2017 10:02:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 14A265D969; Thu, 22 Jun 2017 14:02:54 +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 C82BD5D967 for ; Thu, 22 Jun 2017 14:02:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5A4F8C000956 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5A4F8C000956 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 10:02:36 -0400 Message-Id: <20170622140246.31777-7-jferlan@redhat.com> In-Reply-To: <20170622140246.31777-1-jferlan@redhat.com> References: <20170622140246.31777-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 06/16] util: Introduce virObjectLookupKeys*Active API's 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 22 Jun 2017 14:03:03 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a 'bool active' field to the virObjectLookupKeys object and then virObjectLookupKeysIsActive and virObjectLookupKeysSetActive API's to manage it. Signed-off-by: John Ferlan --- src/libvirt_private.syms | 2 ++ src/util/virobject.c | 39 +++++++++++++++++++++++++++++++++++++++ src/util/virobject.h | 9 +++++++++ 3 files changed, 50 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index bfc68eb..6a87e6b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2287,7 +2287,9 @@ virObjectLock; virObjectLockableNew; virObjectLookupKeysGetName; virObjectLookupKeysGetUUID; +virObjectLookupKeysIsActive; virObjectLookupKeysNew; +virObjectLookupKeysSetActive; virObjectNew; virObjectRef; virObjectUnlock; diff --git a/src/util/virobject.c b/src/util/virobject.c index 862d46b..6e2b222 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -585,6 +585,45 @@ virObjectListFreeCount(void *list, =20 =20 /** + * virObjectLookupKeysIsActive + * @anyobj: Pointer to a locked LookupKeys object + * + * Returns: True if object is active, false if not + */ +bool +virObjectLookupKeysIsActive(void *anyobj) +{ + virObjectLookupKeysPtr obj =3D virObjectGetLookupKeysObj(anyobj); + + if (!obj) + return false; + + return obj->active; +} + + +/** + * virObjectLookupKeysSetActive + * @anyobj: Pointer to a locked LookupKeys object + * @active: New active setting + * + * Set the lookup keys active bool value; value not changed if object + * is not a lookup keys object + */ +void +virObjectLookupKeysSetActive(void *anyobj, + bool active) +{ + virObjectLookupKeysPtr obj =3D virObjectGetLookupKeysObj(anyobj); + + if (!obj) + return; + + obj->active =3D active; +} + + +/** * virObjectLookupKeysGetUUID * @anyobj: Pointer to a LookupKeys object * diff --git a/src/util/virobject.h b/src/util/virobject.h index e77634b..9e0ecc1 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -67,6 +67,8 @@ struct _virObjectLookupKeys { =20 char *uuid; char *name; + + bool active; /* true if object is active */ }; =20 =20 @@ -140,6 +142,13 @@ void virObjectListFreeCount(void *list, size_t count); =20 +bool +virObjectLookupKeysIsActive(void *anyobj); + +void +virObjectLookupKeysSetActive(void *anyobj, + bool active); + const char * virObjectLookupKeysGetUUID(void *anyobj); =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 10:23:46 2024 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.zoho.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 1498140187412780.5676956652577; Thu, 22 Jun 2017 07:03:07 -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 820C775712; Thu, 22 Jun 2017 14:03:02 +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 38966171E4; Thu, 22 Jun 2017 14:03:02 +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 E661C1853E2F; Thu, 22 Jun 2017 14:03:01 +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 v5ME2shQ004492 for ; Thu, 22 Jun 2017 10:02:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id AB21A5D969; Thu, 22 Jun 2017 14:02:54 +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 6ADBD5D967 for ; Thu, 22 Jun 2017 14:02:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 820C775712 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=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 820C775712 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 10:02:37 -0400 Message-Id: <20170622140246.31777-8-jferlan@redhat.com> In-Reply-To: <20170622140246.31777-1-jferlan@redhat.com> References: <20170622140246.31777-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 07/16] interface: Use virObjectLookupKeys*Active 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.27]); Thu, 22 Jun 2017 14:03:03 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use the @active definition of the virObjectLookupKeys Signed-off-by: John Ferlan --- src/conf/virinterfaceobj.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index 243ff33..69a716b 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -35,7 +35,6 @@ VIR_LOG_INIT("conf.virinterfaceobj"); struct _virInterfaceObj { virObjectLookupKeys parent; =20 - bool active; /* true if interface is active (up) */ virInterfaceDefPtr def; /* The interface definition */ }; =20 @@ -113,7 +112,7 @@ virInterfaceObjGetDef(virInterfaceObjPtr obj) bool virInterfaceObjIsActive(virInterfaceObjPtr obj) { - return obj->active; + return virObjectLookupKeysIsActive(obj); } =20 =20 @@ -121,7 +120,7 @@ void virInterfaceObjSetActive(virInterfaceObjPtr obj, bool active) { - obj->active =3D active; + virObjectLookupKeysSetActive(obj, active); } =20 =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 10:23:46 2024 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.zoho.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 149814018958593.61692212704668; Thu, 22 Jun 2017 07:03:09 -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 CD50E2B0A81; Thu, 22 Jun 2017 14:03:05 +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 894915C472; Thu, 22 Jun 2017 14:03:05 +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 2DA304E98B; Thu, 22 Jun 2017 14:03:05 +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 v5ME2t54004497 for ; Thu, 22 Jun 2017 10:02:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2CAE75D960; Thu, 22 Jun 2017 14:02:55 +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 DFA315D967 for ; Thu, 22 Jun 2017 14:02:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CD50E2B0A81 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CD50E2B0A81 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 10:02:38 -0400 Message-Id: <20170622140246.31777-9-jferlan@redhat.com> In-Reply-To: <20170622140246.31777-1-jferlan@redhat.com> References: <20170622140246.31777-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 08/16] util: Introduce virObjectLookupHash 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.29]); Thu, 22 Jun 2017 14:03:06 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the virObjectLockable class as the base and the virObjectLookupKeys uuid and name from the virObjectLookupKeys, create the virObjectLookupHash to manage a common mechanism to store objects for a driver via self locking hash tables. Each hash table will have : tableElemsStart -> # of elements to create the initial table objsUUID -> Hash table for the LookupKeys->UUID objsName -> Hash table for the LookupKeys->name A secondary benefit of self locking hash tables is each driver then does not have to keep a higher level driver lock for interactions with the object storage since the object itself can manage locking as needed. Signed-off-by: John Ferlan --- src/libvirt_private.syms | 2 ++ src/util/virobject.c | 85 ++++++++++++++++++++++++++++++++++++++++++++= +++- src/util/virobject.h | 24 ++++++++++++++ 3 files changed, 110 insertions(+), 1 deletion(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6a87e6b..655a8f8 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2274,6 +2274,7 @@ virNumaSetupMemoryPolicy; # util/virobject.h virClassForObject; virClassForObjectLockable; +virClassForObjectLookupHash; virClassForObjectLookupKeys; virClassIsDerivedFrom; virClassName; @@ -2285,6 +2286,7 @@ virObjectListFree; virObjectListFreeCount; virObjectLock; virObjectLockableNew; +virObjectLookupHashNew; virObjectLookupKeysGetName; virObjectLookupKeysGetUUID; virObjectLookupKeysIsActive; diff --git a/src/util/virobject.c b/src/util/virobject.c index 6e2b222..79f1fe9 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -67,9 +67,11 @@ struct _virClass { static virClassPtr virObjectClass; static virClassPtr virObjectLockableClass; static virClassPtr virObjectLookupKeysClass; +static virClassPtr virObjectLookupHashClass; =20 static void virObjectLockableDispose(void *anyobj); static void virObjectLookupKeysDispose(void *anyobj); +static void virObjectLookupHashDispose(void *anyobj); =20 static int virObjectOnceInit(void) @@ -92,6 +94,12 @@ virObjectOnceInit(void) virObjectLookupKeysDispos= e))) return -1; =20 + if (!(virObjectLookupHashClass =3D virClassNew(virObjectLockableClass, + "virObjectLookupHash", + sizeof(virObjectLookupHas= h), + virObjectLookupHashDispos= e))) + return -1; + return 0; } =20 @@ -144,6 +152,21 @@ virClassForObjectLookupKeys(void) =20 =20 /** + * virClassForObjectLookupHash: + * + * Returns the class instance for the virObjectLookupHash type + */ +virClassPtr +virClassForObjectLookupHash(void) +{ + if (virObjectInitialize() < 0) + return NULL; + + return virObjectLookupHashClass; +} + + +/** * virClassNew: * @parent: the parent class * @name: the class name @@ -344,6 +367,65 @@ virObjectLookupKeysDispose(void *anyobj) =20 =20 /** + * virObjectLookupHashNew: + * @klass: the klass to check + * @tableElemsStart: number of elements initially in the table + * + * Create a new poolable hash table object for storing hash tables capable + * of storing virObjectLookupKeys objects. + * + * Returns: New object on success, NULL on failure w/ error message set + */ +void * +virObjectLookupHashNew(virClassPtr klass, + int tableElemsStart) +{ + virObjectLookupHashPtr obj; + + if (!virClassIsDerivedFrom(klass, virClassForObjectLookupHash())) { + virReportInvalidArg(klass, + _("Class %s must derive from virObjectLookupHa= sh"), + virClassName(klass)); + return NULL; + } + + if (!(obj =3D virObjectLockableNew(klass))) + return NULL; + + obj->tableElemsStart =3D tableElemsStart; + + if (!(obj->objsUUID =3D virHashCreate(tableElemsStart, + virObjectFreeHashData))) + goto error; + + if (!(obj->objsName =3D virHashCreate(tableElemsStart, + virObjectFreeHashData))) + goto error; + + VIR_DEBUG("obj=3D%p, elems=3D%d objsUUID=3D%p objsName=3D%p", + obj, tableElemsStart, obj->objsUUID, obj->objsName); + + return obj; + + error: + virObjectUnref(obj); + return NULL; +} + + +static void +virObjectLookupHashDispose(void *anyobj) +{ + virObjectLookupHashPtr obj =3D anyobj; + + VIR_DEBUG("dispose obj=3D%p", obj); + + virHashFree(obj->objsUUID); + virHashFree(obj->objsName); +} + + +/** * virObjectUnref: * @anyobj: any instance of virObjectPtr * @@ -410,7 +492,8 @@ static virObjectLockablePtr virObjectGetLockableObj(void *anyobj) { if (virObjectIsClass(anyobj, virObjectLockableClass) || - virObjectIsClass(anyobj, virObjectLookupKeysClass)) + virObjectIsClass(anyobj, virObjectLookupKeysClass) || + virObjectIsClass(anyobj, virObjectLookupHashClass)) return anyobj; =20 VIR_OBJECT_USAGE_PRINT_WARNING(anyobj, virObjectLockableClass); diff --git a/src/util/virobject.h b/src/util/virobject.h index 9e0ecc1..3c45182 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -23,6 +23,7 @@ # define __VIR_OBJECT_H__ =20 # include "internal.h" +# include "virhash.h" # include "virthread.h" =20 typedef struct _virClass virClass; @@ -37,6 +38,9 @@ typedef virObjectLockable *virObjectLockablePtr; typedef struct _virObjectLookupKeys virObjectLookupKeys; typedef virObjectLookupKeys *virObjectLookupKeysPtr; =20 +typedef struct _virObjectLookupHash virObjectLookupHash; +typedef virObjectLookupHash *virObjectLookupHashPtr; + typedef void (*virObjectDisposeCallback)(void *obj); =20 /* Most code should not play with the contents of this struct; however, @@ -71,10 +75,25 @@ struct _virObjectLookupKeys { bool active; /* true if object is active */ }; =20 +struct _virObjectLookupHash { + virObjectLockable parent; + + int tableElemsStart; + + /* uuid string -> object mapping for O(1), + * lockless lookup-by-uuid */ + virHashTable *objsUUID; + + /* name key -> object mapping for O(1), + * lockless lookup-by-name */ + virHashTable *objsName; +}; + =20 virClassPtr virClassForObject(void); virClassPtr virClassForObjectLockable(void); virClassPtr virClassForObjectLookupKeys(void); +virClassPtr virClassForObjectLookupHash(void); =20 # ifndef VIR_PARENT_REQUIRED # define VIR_PARENT_REQUIRED ATTRIBUTE_NONNULL(1) @@ -127,6 +146,11 @@ virObjectLookupKeysNew(virClassPtr klass, const char *name) ATTRIBUTE_NONNULL(1); =20 +void * +virObjectLookupHashNew(virClassPtr klass, + int tableElemsStart) + ATTRIBUTE_NONNULL(1); + void virObjectLock(void *lockableobj) ATTRIBUTE_NONNULL(1); --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 10:23:46 2024 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.zoho.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 1498140667229787.3770606082338; Thu, 22 Jun 2017 07:11:07 -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 AAABFC049D7F; Thu, 22 Jun 2017 14:11:03 +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 7C7E14D72B; Thu, 22 Jun 2017 14:11:03 +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 320DF1833033; Thu, 22 Jun 2017 14:11:03 +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 v5ME2tSX004507 for ; Thu, 22 Jun 2017 10:02:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 93B4A5D967; Thu, 22 Jun 2017 14:02:55 +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 53AAD5D960 for ; Thu, 22 Jun 2017 14:02:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AAABFC049D7F Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com AAABFC049D7F From: John Ferlan To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 10:02:39 -0400 Message-Id: <20170622140246.31777-10-jferlan@redhat.com> In-Reply-To: <20170622140246.31777-1-jferlan@redhat.com> References: <20170622140246.31777-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 09/16] util: Introduce virObjectLoookupHashGet{UUID|Name} 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.31]); Thu, 22 Jun 2017 14:11:04 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a pair of accessor API's for the object elements which will return the requested key value from the object to the caller. It is up to the caller to check the returned key value and error if the return value is NULL. Signed-off-by: John Ferlan --- src/libvirt_private.syms | 2 ++ src/util/virobject.c | 48 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virobject.h | 6 ++++++ 3 files changed, 56 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 655a8f8..28244ab 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2286,6 +2286,8 @@ virObjectListFree; virObjectListFreeCount; virObjectLock; virObjectLockableNew; +virObjectLookupHashGetName; +virObjectLookupHashGetUUID; virObjectLookupHashNew; virObjectLookupKeysGetName; virObjectLookupKeysGetUUID; diff --git a/src/util/virobject.c b/src/util/virobject.c index 79f1fe9..949a93d 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -514,6 +514,18 @@ virObjectGetLookupKeysObj(void *anyobj) } =20 =20 +static virObjectLookupHashPtr +virObjectGetLookupHashObj(void *anyobj) +{ + if (virObjectIsClass(anyobj, virObjectLookupHashClass)) + return anyobj; + + VIR_OBJECT_USAGE_PRINT_WARNING(anyobj, virObjectLookupHashClass); + + return NULL; +} + + /** * virObjectLock: * @anyobj: any instance of virObjectLockablePtr @@ -740,3 +752,39 @@ virObjectLookupKeysGetName(void *anyobj) =20 return obj->name; } + + +/** + * virObjectLookupHashGetUUID + * @anyobj: Pointer to a LookupHash object + * + * Returns: Pointer to the UUID Hash Table or NULL on failure + */ +virHashTablePtr +virObjectLookupHashGetUUID(void *anyobj) +{ + virObjectLookupHashPtr obj =3D virObjectGetLookupHashObj(anyobj); + + if (!obj) + return NULL; + + return obj->objsUUID; +} + + +/** + * virObjectLookupHashGetName + * @anyobj: Pointer to a LookupHash object + * + * Returns: Pointer to the Name Hash Table or NULL on failure + */ +virHashTablePtr +virObjectLookupHashGetName(void *anyobj) +{ + virObjectLookupHashPtr obj =3D virObjectGetLookupHashObj(anyobj); + + if (!obj) + return NULL; + + return obj->objsName; +} diff --git a/src/util/virobject.h b/src/util/virobject.h index 3c45182..7da680a 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -179,4 +179,10 @@ virObjectLookupKeysGetUUID(void *anyobj); const char * virObjectLookupKeysGetName(void *anyobj); =20 +virHashTablePtr +virObjectLookupHashGetUUID(void *anyobj); + +virHashTablePtr +virObjectLookupHashGetName(void *anyobj); + #endif /* __VIR_OBJECT_H */ --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 10:23:46 2024 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.zoho.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 1498140188517123.33442013942806; Thu, 22 Jun 2017 07:03:08 -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 AD6C81E305; Thu, 22 Jun 2017 14:03:05 +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 824554D72B; Thu, 22 Jun 2017 14:03:05 +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 24B694E98A; Thu, 22 Jun 2017 14:03:05 +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 v5ME2ut2004512 for ; Thu, 22 Jun 2017 10:02:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0665B5D967; Thu, 22 Jun 2017 14:02:56 +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 BAC795D960 for ; Thu, 22 Jun 2017 14:02:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AD6C81E305 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com AD6C81E305 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 10:02:40 -0400 Message-Id: <20170622140246.31777-11-jferlan@redhat.com> In-Reply-To: <20170622140246.31777-1-jferlan@redhat.com> References: <20170622140246.31777-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 10/16] util: Introduce virObjectLookupHash{Add|Remove} 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.30]); Thu, 22 Jun 2017 14:03:06 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a pair of API's to add/remove the LookupKeys object to/from the LookupHash object. The caller must check return status and handle failure properly for the Add. The Remove API callers are all void functions, so only report the problem and ignore the attempt to remove if for some reason the passed @tableobj is not as expected. Signed-off-by: John Ferlan --- src/libvirt_private.syms | 2 ++ src/util/virobject.c | 80 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virobject.h | 8 +++++ 3 files changed, 90 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 28244ab..de986e5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2286,9 +2286,11 @@ virObjectListFree; virObjectListFreeCount; virObjectLock; virObjectLockableNew; +virObjectLookupHashAdd; virObjectLookupHashGetName; virObjectLookupHashGetUUID; virObjectLookupHashNew; +virObjectLookupHashRemove; virObjectLookupKeysGetName; virObjectLookupKeysGetUUID; virObjectLookupKeysIsActive; diff --git a/src/util/virobject.c b/src/util/virobject.c index 949a93d..9443dda 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -755,6 +755,86 @@ virObjectLookupKeysGetName(void *anyobj) =20 =20 /** + * virObjectLookupHashAdd: + * @tableobj: LookupHash object with objsUUID/objsName + * @obj: The LookupKeys object to insert in the hash table(s) + * + * Insert @obj into the hash tables found in @tableobj. + * + * Returns 0 on success, -1 on failure. + */ +int +virObjectLookupHashAdd(void *tableobj, + virObjectLookupKeysPtr obj) +{ + virObjectLookupHashPtr hashObj =3D virObjectGetLookupHashObj(tableobj); + + if (!hashObj) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("tableobj=3D%p is not a lookup hash object"), tab= leobj); + return -1; + } + + if (obj->uuid) { + if (virHashAddEntry(hashObj->objsUUID, obj->uuid, obj) < 0) + return -1; + virObjectRef(obj); + } + + if (obj->name) { + if (virHashAddEntry(hashObj->objsName, obj->name, obj) < 0) { + virHashRemoveEntry(hashObj->objsUUID, obj->uuid); + return -1; + } + virObjectRef(obj); + } + + return 0; +} + + +/** + * virObjectLookupHashRemove: + * @tableobj: LookupHash object with objsUUID/objsName + * @obj: The LookupKeys object to remove from the hash table(s) + * + * Remove @obj from the hash tables found in @tableobj. The common + * function to remove an object from a hash table will also cause + * the virObjectUnref to be called via virObjectFreeHashData since + * the virHashCreate used that as the Free object element argument. + * + * Even though this is a void, report the error for a bad @tableobj. + */ +void +virObjectLookupHashRemove(void *tableobj, + virObjectLookupKeysPtr obj) +{ + virObjectLookupHashPtr hashObj; + + if (!obj) + return; + + if (!(hashObj =3D virObjectGetLookupHashObj(tableobj))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("tableobj=3D%p is not a lookup hash object"), tab= leobj); + return; + } + + virObjectRef(obj); + virObjectUnlock(obj); + virObjectLock(tableobj); + virObjectLock(obj); + if (obj->uuid) + virHashRemoveEntry(hashObj->objsUUID, obj->uuid); + if (obj->name) + virHashRemoveEntry(hashObj->objsName, obj->name); + virObjectUnlock(obj); + virObjectUnref(obj); + virObjectUnlock(tableobj); +} + + +/** * virObjectLookupHashGetUUID * @anyobj: Pointer to a LookupHash object * diff --git a/src/util/virobject.h b/src/util/virobject.h index 7da680a..422c81e 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -179,6 +179,14 @@ virObjectLookupKeysGetUUID(void *anyobj); const char * virObjectLookupKeysGetName(void *anyobj); =20 +int +virObjectLookupHashAdd(void *tableobj, + virObjectLookupKeysPtr obj); + +void +virObjectLookupHashRemove(void *tableobj, + virObjectLookupKeysPtr obj); + virHashTablePtr virObjectLookupHashGetUUID(void *anyobj); =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 10:23:46 2024 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.zoho.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 1498140670620543.8749964364941; Thu, 22 Jun 2017 07:11:10 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CD41761B92; Thu, 22 Jun 2017 14:11:06 +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 9D1B6619CF; Thu, 22 Jun 2017 14:11:06 +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 59C3C1853E2E; Thu, 22 Jun 2017 14:11:06 +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 v5ME2uJ0004519 for ; Thu, 22 Jun 2017 10:02:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 801D65D967; Thu, 22 Jun 2017 14:02:56 +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 3E6255D960 for ; Thu, 22 Jun 2017 14:02:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CD41761B92 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CD41761B92 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 10:02:41 -0400 Message-Id: <20170622140246.31777-12-jferlan@redhat.com> In-Reply-To: <20170622140246.31777-1-jferlan@redhat.com> References: <20170622140246.31777-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 11/16] util: Introduce virObjectLookupHashFind 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 22 Jun 2017 14:11:07 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This API will use the virHashLookup in order to find the object in the requested hash table (via @useUUID) by the specified @key. It is up to the caller to know which table (UUID or Name) to find the data by @key and handle the error or NULL return. Signed-off-by: John Ferlan --- src/libvirt_private.syms | 1 + src/util/virobject.c | 25 +++++++++++++++++++++++++ src/util/virobject.h | 5 +++++ 3 files changed, 31 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index de986e5..68961e7 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2287,6 +2287,7 @@ virObjectListFreeCount; virObjectLock; virObjectLockableNew; virObjectLookupHashAdd; +virObjectLookupHashFind; virObjectLookupHashGetName; virObjectLookupHashGetUUID; virObjectLookupHashNew; diff --git a/src/util/virobject.c b/src/util/virobject.c index 9443dda..01922b3 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -853,6 +853,31 @@ virObjectLookupHashGetUUID(void *anyobj) =20 =20 /** + * virObjectLookupHashFind: + * @tableobj: poolable hash table pointer find data + * @useUUID: boolean to use objsUUID + * @key: Key to use for lookup + * + * Returns a pointer to the entry or NULL on failure + */ +virObjectLookupKeysPtr +virObjectLookupHashFind(void *tableobj, + bool useUUID, + const char *key) +{ + virObjectLookupHashPtr hashObj =3D virObjectGetLookupHashObj(tableobj); + + if (!hashObj) { + virReportError(VIR_ERR_INTERNAL_ERROR, + ("tableobj=3D%p is not a lookup hash object"), tabl= eobj); + return NULL; + } + + return virHashLookup(useUUID ? hashObj->objsUUID : hashObj->objsName, = key); +} + + +/** * virObjectLookupHashGetName * @anyobj: Pointer to a LookupHash object * diff --git a/src/util/virobject.h b/src/util/virobject.h index 422c81e..ed99540 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -187,6 +187,11 @@ void virObjectLookupHashRemove(void *tableobj, virObjectLookupKeysPtr obj); =20 +virObjectLookupKeysPtr +virObjectLookupHashFind(void *tableobj, + bool useUUID, + const char *key); + virHashTablePtr virObjectLookupHashGetUUID(void *anyobj); =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 10:23:46 2024 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.zoho.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 1498140199188370.8896219503224; Thu, 22 Jun 2017 07:03:19 -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 249947F413; Thu, 22 Jun 2017 14:03:14 +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 D176E4D72B; Thu, 22 Jun 2017 14:03:13 +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 96B181853E34; Thu, 22 Jun 2017 14:03: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 v5ME2vjX004524 for ; Thu, 22 Jun 2017 10:02:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id 072865D967; Thu, 22 Jun 2017 14:02:57 +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 BA25A5D960 for ; Thu, 22 Jun 2017 14:02:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 249947F413 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=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 249947F413 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 10:02:42 -0400 Message-Id: <20170622140246.31777-13-jferlan@redhat.com> In-Reply-To: <20170622140246.31777-1-jferlan@redhat.com> References: <20170622140246.31777-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 12/16] util: Introduce virObjectLookupHashForEach 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.25]); Thu, 22 Jun 2017 14:03:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Introduce an API to use the virHashForEach API to go through each element of a specified LookupHash (via @useUUID) calling a callback with a LookupKey object entry from the LookupHash in order for it to be processed. Create a common structure to define the various pieces of data needed by the callback consumers: struct _virObjectLookupHashForEachData { virConnectPtr conn; -> Connect ptr for @aclfilter APIs void *aclfilter; -> A pointer to function for ACL calls bool wantActive; -> Filter active objs bool error; -> Set by callback functions for error const char *matchstr; -> Filter for specific string in many ob= js unsigned int flags; -> @flags argument to for Export calls int nelems; -> # of elements found and passing filte= rs void **elems; -> array of elements int maxelems; -> maximum # of elements to collect }; Upon successful completion, the data.nelems is returned to the caller and possibly various fields within the structure filled in depending on the callers need as follows: vir{Object}NumOf{Elem} =3D> Would typically only care about @nelems based on whether the caller cares about @wantActive. Can also filter results based on the @aclfilter call. vir{Object}Get{Key} =3D> Use the @elems and @maxelems in order to fill in an array of char ** strings based on the {Key} filtering data as necessary from the @aclfilter and possibly the @matchstr. Callers of this function will preallocate the @elems and supply the @maxelems value. The @nelems is used to keep track of the number of elements. vir{Object}Export =3D> When @maxelems =3D=3D -1, will cause allocation into data->ele= ms of an array sized by the hash table size which will be used by the callback function to store addresses of objects specific to each {Object} that are typically assocated with virConnectListAl= l* API's from the virGet{Object}() calls. The @flags argument is typically used for additional filtering via vir{Object}Match or vir{Object}Filter APIs found in various vir*obj modules. Upon return from the call, the calling function must then move the data->elems into the returned structure. It is up to the callback function to set @error in the event of an error during processing resulting in calling the VIR_FREE() for each of the @nelems already in the array. When an error occurs, any collection done by the callback functions into the @elems array is discarded. Signed-off-by: John Ferlan --- src/libvirt_private.syms | 1 + src/util/virobject.c | 61 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virobject.h | 20 ++++++++++++++++ 3 files changed, 82 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 68961e7..f783fec 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2288,6 +2288,7 @@ virObjectLock; virObjectLockableNew; virObjectLookupHashAdd; virObjectLookupHashFind; +virObjectLookupHashForEach; virObjectLookupHashGetName; virObjectLookupHashGetUUID; virObjectLookupHashNew; diff --git a/src/util/virobject.c b/src/util/virobject.c index 01922b3..8a994f5 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -893,3 +893,64 @@ virObjectLookupHashGetName(void *anyobj) =20 return obj->objsName; } + + +/** + * virObjectLookupHashForEach + * @tableobj: poolable hash table pointer to walk through + * @useUUID: boolean to use objsUUID + * @callback: callback function to handle the object specific checks + * @opaque: callback data + * + * For each element of the objsName hash table make a call into the + * callback routine to handle its task + * + * Returns 0 on success, -1 on failure + */ +int +virObjectLookupHashForEach(void *tableobj, + bool useUUID, + virHashIterator callback, + virObjectLookupHashForEachDataPtr data) +{ + virObjectLookupHashPtr hashObj =3D virObjectGetLookupHashObj(tableobj); + virHashTablePtr tbl; + + if (!hashObj) + return -1; + + if (useUUID) + tbl =3D hashObj->objsUUID; + else + tbl =3D hashObj->objsName; + + if (data->maxelems =3D=3D -1) { + if (VIR_ALLOC_N(data->elems, virHashSize(tbl) + 1) < 0) + return -1; + } + + virObjectLock(hashObj); + virHashForEach(tbl, callback, data); + virObjectUnlock(hashObj); + + if (data->error) + goto error; + + if (data->maxelems =3D=3D -1) { + /* trim the array to the final size */ + ignore_value(VIR_REALLOC_N(data->elems, data->nelems + 1)); + } + + return data->nelems; + + error: + if (data->elems) { + if (data->maxelems =3D=3D -1) { + virObjectListFree(data->elems); + } else { + while (--data->nelems) + VIR_FREE(data->elems[data->nelems]); + } + } + return -1; +} diff --git a/src/util/virobject.h b/src/util/virobject.h index ed99540..926c9d3 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -198,4 +198,24 @@ virObjectLookupHashGetUUID(void *anyobj); virHashTablePtr virObjectLookupHashGetName(void *anyobj); =20 +typedef struct _virObjectLookupHashForEachData virObjectLookupHashForEachD= ata; +typedef virObjectLookupHashForEachData *virObjectLookupHashForEachDataPtr; +struct _virObjectLookupHashForEachData { + virConnectPtr conn; + void *aclfilter; + bool wantActive; + bool error; + const char *matchstr; + unsigned int flags; + int nelems; + void **elems; + int maxelems; +}; + +int +virObjectLookupHashForEach(void *tableobj, + bool useUUID, + virHashIterator callback, + virObjectLookupHashForEachDataPtr data); + #endif /* __VIR_OBJECT_H */ --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 10:23:46 2024 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.zoho.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 1498140207823690.0798501632266; Thu, 22 Jun 2017 07:03:27 -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 7CD537F40D; Thu, 22 Jun 2017 14:03:21 +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 5367A6062E; Thu, 22 Jun 2017 14:03:21 +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 109DA1853E3C; Thu, 22 Jun 2017 14:03:12 +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 v5ME2vWZ004529 for ; Thu, 22 Jun 2017 10:02:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6E0EA5D969; Thu, 22 Jun 2017 14:02:57 +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 2DAC95D960 for ; Thu, 22 Jun 2017 14:02:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7CD537F40D 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=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7CD537F40D From: John Ferlan To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 10:02:43 -0400 Message-Id: <20170622140246.31777-14-jferlan@redhat.com> In-Reply-To: <20170622140246.31777-1-jferlan@redhat.com> References: <20170622140246.31777-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 13/16] util: Introduce virObjectLookupHashSearch 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]); Thu, 22 Jun 2017 14:03:22 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" A common object API wrapper to use the virHashSearch API to search the specified LookupHash for specific data defined in the @opaque parameter. Once data is found, the search would end and the LookupKeys object that is represented is returned locked with it's reference count incremented. It is up to the caller to unlock and lower the refcnt once done with the object and of course handle a NULL return indicating no object found. Signed-off-by: John Ferlan --- src/libvirt_private.syms | 1 + src/util/virobject.c | 38 ++++++++++++++++++++++++++++++++++++++ src/util/virobject.h | 6 ++++++ 3 files changed, 45 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index f783fec..2c4296a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2293,6 +2293,7 @@ virObjectLookupHashGetName; virObjectLookupHashGetUUID; virObjectLookupHashNew; virObjectLookupHashRemove; +virObjectLookupHashSearch; virObjectLookupKeysGetName; virObjectLookupKeysGetUUID; virObjectLookupKeysIsActive; diff --git a/src/util/virobject.c b/src/util/virobject.c index 8a994f5..60bc5b5 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -954,3 +954,41 @@ virObjectLookupHashForEach(void *tableobj, } return -1; } + + +/** + * virObjectLookupHashSearchName + * @tableobj: poolable hash table pointer to search + * @useUUID: boolean to use objsUUID + * @callback: callback function to handle the object specific checks + * @opaque: callback data + * + * Search the objsName hash table calling the specified @callback routine + * with an object and @opaque data in order to determine whether the searc= hed + * object is represented by the @opaque data. + * + * Returns locked/refcnt incremented object on success, NULL on failure + */ +virObjectLookupKeysPtr +virObjectLookupHashSearch(void *tableobj, + bool useUUID, + virHashSearcher callback, + void *opaque) +{ + virObjectLookupHashPtr tableObj =3D virObjectGetLookupHashObj(tableobj= ); + virObjectLookupKeysPtr obj; + + if (!tableObj) + return NULL; + + virObjectLock(tableObj); + obj =3D virHashSearch(useUUID ? tableObj->objsUUID : tableObj->objsNam= e, + callback, opaque); + virObjectRef(obj); + virObjectUnlock(tableObj); + + if (obj) + virObjectLock(obj); + + return obj; +} diff --git a/src/util/virobject.h b/src/util/virobject.h index 926c9d3..7e58e34 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -218,4 +218,10 @@ virObjectLookupHashForEach(void *tableobj, virHashIterator callback, virObjectLookupHashForEachDataPtr data); =20 +virObjectLookupKeysPtr +virObjectLookupHashSearch(void *tableobj, + bool useUUID, + virHashSearcher callback, + void *opaque); + #endif /* __VIR_OBJECT_H */ --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 10:23:46 2024 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.zoho.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 1498140192513622.1961710706898; Thu, 22 Jun 2017 07:03:12 -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 184E07F40F; Thu, 22 Jun 2017 14:03: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 E3D7E171E4; Thu, 22 Jun 2017 14:03:08 +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 956B94E9B4; Thu, 22 Jun 2017 14:03: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 v5ME2vg7004535 for ; Thu, 22 Jun 2017 10:02:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id DA36D5D967; Thu, 22 Jun 2017 14:02:57 +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 99E665D960 for ; Thu, 22 Jun 2017 14:02:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 184E07F40F 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=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 184E07F40F From: John Ferlan To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 10:02:44 -0400 Message-Id: <20170622140246.31777-15-jferlan@redhat.com> In-Reply-To: <20170622140246.31777-1-jferlan@redhat.com> References: <20170622140246.31777-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 14/16] util: Introduce virObjectLookupHashClone 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.25]); Thu, 22 Jun 2017 14:03:10 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" A convenience API that will utilize the virHashForEach API for a specified LookupHash in order to create a clone/copy. Primary consumer is the interfa= ce driver which has a desire to save off a copy of it's @Name LookupHash table in order to possible restore it if something goes wrong during processing. The callback function's primary purpose is to copy anything within the local LookupKeys into the target. Signed-off-by: John Ferlan --- src/libvirt_private.syms | 1 + src/util/virobject.c | 79 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virobject.h | 10 ++++++ 3 files changed, 90 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2c4296a..41638f6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2287,6 +2287,7 @@ virObjectListFreeCount; virObjectLock; virObjectLockableNew; virObjectLookupHashAdd; +virObjectLookupHashClone; virObjectLookupHashFind; virObjectLookupHashForEach; virObjectLookupHashGetName; diff --git a/src/util/virobject.c b/src/util/virobject.c index 60bc5b5..9182a2e 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -992,3 +992,82 @@ virObjectLookupHashSearch(void *tableobj, =20 return obj; } + + +struct cloneData { + virObjectLookupHashCloneCallback callback; + virObjectLookupHashPtr dst; + bool error; +}; + +/* + * Take the provided virHashForEach element and call the driver @cb functi= on + * with the input @dstTable and the source element from the @srcTable in o= rder + * to perform the copy - tracking success/failure using the error boolean. + * Once there's a failure, no future copy/clone will occur. + * + * The @cb function can expect the @srcTable object to be locked upon entr= y. + * + * Returns 0 to the virHashForEach on success, -1 on failure. + */ +static int +cloneCallback(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *opaque) +{ + virObjectLookupKeysPtr obj =3D payload; + struct cloneData *data =3D opaque; + + if (data->error) + return 0; + + virObjectLock(obj); + + if (data->callback(data->dst, obj) < 0) + data->error =3D true; + + virObjectUnlock(obj); + + if (data->error) + return -1; + + return 0; +} + +/** + * virObjectLookupHashClone + * @srcTable: source poolable hash table pointer to clone from + * @dstTable: destination poolable hash table pointer to clone to + * @useUUID: Use the objsUUID for clone (or objsName) + * @cb: callback function from driver code to handle the clone + * + * The clone function is designed to traverse each @srcTable hash element + * and call the driver specific @cb function with the element from the + * @srcTable in order to clone into the @dstTable. If @useUUID is true, + * then clone the objsUUID table; otherwise, clone the objsName table. + * + * Return 0 on success, -1 on failure + */ +int +virObjectLookupHashClone(void *srcTable, + void *dstTable, + bool useUUID, + virObjectLookupHashCloneCallback cb) +{ + virObjectLookupHashPtr src =3D virObjectGetLookupHashObj(srcTable); + virObjectLookupHashPtr dst =3D virObjectGetLookupHashObj(dstTable); + struct cloneData data =3D { .callback =3D cb, .dst =3D dst, .error =3D= false }; + + if (!src || !dst) + return -1; + + virObjectLock(src); + virHashForEach(useUUID ? src->objsUUID : src->objsName, + cloneCallback, &data); + virObjectUnlock(src); + + if (data.error) + return -1; + + return 0; +} diff --git a/src/util/virobject.h b/src/util/virobject.h index 7e58e34..350929d 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -224,4 +224,14 @@ virObjectLookupHashSearch(void *tableobj, virHashSearcher callback, void *opaque); =20 +typedef int (*virObjectLookupHashCloneCallback)(void *dstTable, + void *srcElem); +int +virObjectLookupHashClone(void *srcTable, + void *dstTable, + bool useUUID, + virObjectLookupHashCloneCallback cb) + ATTRIBUTE_NONNULL(4); + + #endif /* __VIR_OBJECT_H */ --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 10:23:46 2024 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.zoho.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 1498140200081209.605951828946; Thu, 22 Jun 2017 07:03:20 -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 69C49C04D301; Thu, 22 Jun 2017 14:03:16 +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 3C41C171E4; Thu, 22 Jun 2017 14:03:16 +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 D41384E989; Thu, 22 Jun 2017 14:03:15 +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 v5ME2w6m004540 for ; Thu, 22 Jun 2017 10:02:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7993C5D969; Thu, 22 Jun 2017 14:02:58 +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 393455D967 for ; Thu, 22 Jun 2017 14:02:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 69C49C04D301 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 69C49C04D301 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 10:02:45 -0400 Message-Id: <20170622140246.31777-16-jferlan@redhat.com> In-Reply-To: <20170622140246.31777-1-jferlan@redhat.com> References: <20170622140246.31777-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 15/16] interface: Use virObjectLookupHash 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.31]); Thu, 22 Jun 2017 14:03:17 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Convert the code to use the LookupHash object and APIs rather than the local forward linked list processing. While this could have been done function by function (for easier review) - converting to the LookupHash would have required changes to the Add, Remove, Find, and List functions anyway in order to properly search hash tables - so rather than piecemeal those changes only to undo them, just use the object. Signed-off-by: John Ferlan --- src/conf/virinterfaceobj.c | 321 ++++++++++++++++++++++++++---------------= ---- 1 file changed, 189 insertions(+), 132 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index 69a716b..053a5e5 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -39,8 +39,7 @@ struct _virInterfaceObj { }; =20 struct _virInterfaceObjList { - size_t count; - virInterfaceObjPtr *objs; + virObjectLookupHash parent; }; =20 /* virInterfaceObj manipulation */ @@ -128,11 +127,40 @@ virInterfaceObjSetActive(virInterfaceObjPtr obj, virInterfaceObjListPtr virInterfaceObjListNew(void) { - virInterfaceObjListPtr interfaces; + return virObjectLookupHashNew(virClassForObjectLookupHash(), 10); +} =20 - if (VIR_ALLOC(interfaces) < 0) - return NULL; - return interfaces; + +static int +virInterfaceObjListFindByMACStringCallback(void *payload, + const void *name ATTRIBUTE_UNUS= ED, + void *opaque) +{ + virInterfaceObjPtr obj =3D payload; + virObjectLookupHashForEachDataPtr data =3D opaque; + char **const matches =3D (char **const)data->elems; + virInterfaceDefPtr def; + int ret =3D -1; + + if (data->error) + return 0; + + virObjectLock(obj); + def =3D obj->def; + if (STRCASEEQ(def->mac, data->matchstr)) { + if (data->nelems < data->maxelems) { + if (VIR_STRDUP(matches[data->nelems], def->name) < 0) { + data->error =3D true; + goto cleanup; + } + data->nelems++; + } + } + ret =3D 0; + + cleanup: + virObjectUnlock(obj); + return ret; } =20 =20 @@ -142,33 +170,23 @@ virInterfaceObjListFindByMACString(virInterfaceObjLis= tPtr interfaces, char **const matches, int maxmatches) { - size_t i; - int matchct =3D 0; - - for (i =3D 0; i < interfaces->count; i++) { - virInterfaceObjPtr obj =3D interfaces->objs[i]; - virInterfaceDefPtr def; + virObjectLookupHashForEachData data =3D { + .error =3D false, .matchstr =3D mac, .nelems =3D 0, + .elems =3D (void **)matches, .maxelems =3D maxmatches }; =20 - virObjectLock(obj); - def =3D obj->def; - if (STRCASEEQ(def->mac, mac)) { - if (matchct < maxmatches) { - if (VIR_STRDUP(matches[matchct], def->name) < 0) { - virObjectUnlock(obj); - goto error; - } - matchct++; - } - } - virObjectUnlock(obj); - } - return matchct; + return virObjectLookupHashForEach(interfaces, false, + virInterfaceObjListFindByMACStringCa= llback, + &data); +} =20 - error: - while (--matchct >=3D 0) - VIR_FREE(matches[matchct]); =20 - return -1; +static virInterfaceObjPtr +virInterfaceObjListFindByNameLocked(virInterfaceObjListPtr interfaces, + const char *name) +{ + virObjectLookupKeysPtr obj =3D virObjectLookupHashFind(interfaces, fal= se, + name); + return virObjectRef((virInterfaceObjPtr)obj); } =20 =20 @@ -176,74 +194,96 @@ virInterfaceObjPtr virInterfaceObjListFindByName(virInterfaceObjListPtr interfaces, const char *name) { - size_t i; - - for (i =3D 0; i < interfaces->count; i++) { - virInterfaceObjPtr obj =3D interfaces->objs[i]; - virInterfaceDefPtr def; + virInterfaceObjPtr obj; =20 + virObjectLock(interfaces); + obj =3D virInterfaceObjListFindByNameLocked(interfaces, name); + virObjectUnlock(interfaces); + if (obj) virObjectLock(obj); - def =3D obj->def; - if (STREQ(def->name, name)) - return virObjectRef(obj); - virObjectUnlock(obj); - } =20 - return NULL; + return obj; } =20 =20 void virInterfaceObjListFree(virInterfaceObjListPtr interfaces) { - size_t i; + virObjectUnref(interfaces); +} + + +struct interfaceCloneData { + const char *primaryKey; + virInterfaceObjListPtr dest; + bool error; +}; + +static int +virInterfaceObjListCloneCallback(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *opaque) +{ + virInterfaceObjPtr srcobj =3D payload; + struct interfaceCloneData *data =3D opaque; + int ret =3D -1; + char *xml =3D NULL; + virInterfaceObjPtr obj; + virInterfaceDefPtr backup =3D NULL; + + if (data->error) + return 0; + + virObjectLock(srcobj); + if (!(xml =3D virInterfaceDefFormat(srcobj->def))) + goto error; + + if (!(backup =3D virInterfaceDefParseString(xml))) + goto error; + + if (!(obj =3D virInterfaceObjListAssignDef(data->dest, backup))) + goto error; =20 - for (i =3D 0; i < interfaces->count; i++) - virObjectUnref(interfaces->objs[i]); - VIR_FREE(interfaces->objs); - VIR_FREE(interfaces); + virInterfaceObjEndAPI(&obj); + ret =3D 0; + + cleanup: + VIR_FREE(xml); + virInterfaceDefFree(backup); + + return ret; + + error: + data->error =3D true; + goto cleanup; } =20 =20 virInterfaceObjListPtr virInterfaceObjListClone(virInterfaceObjListPtr interfaces) { - size_t i; - unsigned int cnt; - virInterfaceObjListPtr dest; + virHashTablePtr objsName; + struct interfaceCloneData data =3D { .error =3D false }; =20 if (!interfaces) return NULL; =20 - if (!(dest =3D virInterfaceObjListNew())) + if (!(data.dest =3D virInterfaceObjListNew())) return NULL; =20 - cnt =3D interfaces->count; - for (i =3D 0; i < cnt; i++) { - virInterfaceObjPtr srcobj =3D interfaces->objs[i]; - virInterfaceDefPtr backup; - virInterfaceObjPtr obj; - char *xml =3D virInterfaceDefFormat(srcobj->def); + virObjectLock(interfaces); + objsName =3D virObjectLookupHashGetName(interfaces); + virHashForEach(objsName, virInterfaceObjListCloneCallback, &data); + virObjectUnlock(interfaces); =20 - if (!xml) - goto error; + if (data.error) + goto cleanup; =20 - if (!(backup =3D virInterfaceDefParseString(xml))) { - VIR_FREE(xml); - goto error; - } - - VIR_FREE(xml); - if (!(obj =3D virInterfaceObjListAssignDef(dest, backup))) - goto error; - virInterfaceObjEndAPI(&obj); - } + return data.dest; =20 - return dest; - - error: - virInterfaceObjListFree(dest); - return NULL; + cleanup: + virObjectUnref(data.dest); + return NULL; } =20 =20 @@ -252,24 +292,31 @@ virInterfaceObjListAssignDef(virInterfaceObjListPtr i= nterfaces, virInterfaceDefPtr def) { virInterfaceObjPtr obj; + virInterfaceObjPtr ret =3D NULL; + + virObjectLock(interfaces); =20 - if ((obj =3D virInterfaceObjListFindByName(interfaces, def->name))) { + if ((obj =3D virInterfaceObjListFindByNameLocked(interfaces, def->name= ))) { + virObjectLock(obj); virInterfaceDefFree(obj->def); obj->def =3D def; - - return obj; + } else { + if (!(obj =3D virInterfaceObjNew(def))) + goto cleanup; + + if (virObjectLookupHashAdd(interfaces, + (virObjectLookupKeysPtr)obj) < 0) { + obj->def =3D NULL; + virInterfaceObjEndAPI(&obj); + goto cleanup; + } } =20 - if (!(obj =3D virInterfaceObjNew(def))) - return NULL; + ret =3D obj; =20 - if (VIR_APPEND_ELEMENT_COPY(interfaces->objs, - interfaces->count, obj) < 0) { - obj->def =3D NULL; - virInterfaceObjEndAPI(&obj); - return NULL; - } - return virObjectRef(obj); + cleanup: + virObjectUnlock(interfaces); + return ret; } =20 =20 @@ -277,20 +324,24 @@ void virInterfaceObjListRemove(virInterfaceObjListPtr interfaces, virInterfaceObjPtr obj) { - size_t i; + virObjectLookupHashRemove(interfaces, (virObjectLookupKeysPtr)obj); +} + + +static int +virInterfaceObjListNumOfInterfacesCb(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *opaque) +{ + virInterfaceObjPtr obj =3D payload; + virObjectLookupHashForEachDataPtr data =3D opaque; =20 + virObjectLock(obj); + if (data->wantActive =3D=3D virInterfaceObjIsActive(obj)) + data->nelems++; virObjectUnlock(obj); - for (i =3D 0; i < interfaces->count; i++) { - virObjectLock(interfaces->objs[i]); - if (interfaces->objs[i] =3D=3D obj) { - virObjectUnlock(interfaces->objs[i]); - virObjectUnref(interfaces->objs[i]); - - VIR_DELETE_ELEMENT(interfaces->objs, i, interfaces->count); - break; - } - virObjectUnlock(interfaces->objs[i]); - } + + return 0; } =20 =20 @@ -298,18 +349,44 @@ int virInterfaceObjListNumOfInterfaces(virInterfaceObjListPtr interfaces, bool wantActive) { - size_t i; - int ninterfaces =3D 0; + virObjectLookupHashForEachData data =3D { + .wantActive =3D wantActive, .nelems =3D 0, .error =3D false }; =20 - for (i =3D 0; (i < interfaces->count); i++) { - virInterfaceObjPtr obj =3D interfaces->objs[i]; - virObjectLock(obj); - if (wantActive =3D=3D virInterfaceObjIsActive(obj)) - ninterfaces++; - virObjectUnlock(obj); - } + return virObjectLookupHashForEach(interfaces, false, + virInterfaceObjListNumOfInterfacesCb, + &data); +} + + +static int +virInterfaceObjListGetNamesCb(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *opaque) +{ + virInterfaceObjPtr obj =3D payload; + virObjectLookupHashForEachDataPtr data =3D opaque; + char **const names =3D (char **const)data->elems; + virInterfaceDefPtr def; + + if (data->error) + return 0; + + if (data->maxelems >=3D 0 && data->nelems =3D=3D data->maxelems) + return 0; + + virObjectLock(obj); + def =3D obj->def; + if (data->wantActive =3D=3D virInterfaceObjIsActive(obj)) { + if (VIR_STRDUP(names[data->nelems], def->name) < 0) { + data->error =3D true; + goto cleanup; + } + data->nelems++; + } =20 - return ninterfaces; + cleanup: + virObjectUnlock(obj); + return 0; } =20 =20 @@ -319,30 +396,10 @@ virInterfaceObjListGetNames(virInterfaceObjListPtr in= terfaces, char **const names, int maxnames) { - int nnames =3D 0; - size_t i; - - for (i =3D 0; i < interfaces->count && nnames < maxnames; i++) { - virInterfaceObjPtr obj =3D interfaces->objs[i]; - virInterfaceDefPtr def; - - virObjectLock(obj); - def =3D obj->def; - if (wantActive =3D=3D virInterfaceObjIsActive(obj)) { - if (VIR_STRDUP(names[nnames], def->name) < 0) { - virObjectUnlock(obj); - goto failure; - } - nnames++; - } - virObjectUnlock(obj); - } - - return nnames; - - failure: - while (--nnames >=3D 0) - VIR_FREE(names[nnames]); + virObjectLookupHashForEachData data =3D { + .wantActive =3D wantActive, .error =3D false, .nelems =3D 0, + .elems =3D (void **)names, .maxelems =3D maxnames }; =20 - return -1; + return virObjectLookupHashForEach(interfaces, false, + virInterfaceObjListGetNamesCb, &data= ); } --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 10:23:46 2024 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.zoho.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 1498140206744873.8574599183238; Thu, 22 Jun 2017 07:03:26 -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 433F17C832; Thu, 22 Jun 2017 14:03:21 +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 17E4B60602; Thu, 22 Jun 2017 14:03:21 +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 105891853E3B; Thu, 22 Jun 2017 14:03:12 +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 v5ME2wlM004548 for ; Thu, 22 Jun 2017 10:02:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id E39FF5D967; Thu, 22 Jun 2017 14:02:58 +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 A26E65D960 for ; Thu, 22 Jun 2017 14:02:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 433F17C832 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=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 433F17C832 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 10:02:46 -0400 Message-Id: <20170622140246.31777-17-jferlan@redhat.com> In-Reply-To: <20170622140246.31777-1-jferlan@redhat.com> References: <20170622140246.31777-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 16/16] test: Clean up test driver Interface interactions 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.27]); Thu, 22 Jun 2017 14:03:21 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Now that we have self locking hash table for Interface object lookups, there's no need to take the test driver lock in order to "lock" between the various API's, so remove the Lock/Unlock logic accordingly. Add a virInterfaceObjListFree during testDriverFree for the backupIfaces "just in case". Also use the VIR_STEAL_PTR rather than inline the code. Finally alter a couple of "if ((obj =3D function()) =3D=3D NULL" to use the more standard "if (!(obj =3D function()))" syntax. Signed-off-by: John Ferlan --- src/test/test_driver.c | 55 ++++++++++++----------------------------------= ---- 1 file changed, 13 insertions(+), 42 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 11e7fd8..ff2077c 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -155,6 +155,7 @@ testDriverFree(testDriverPtr driver) virNodeDeviceObjListFree(&driver->devs); virObjectUnref(driver->networks); virInterfaceObjListFree(driver->ifaces); + virInterfaceObjListFree(driver->backupIfaces); virStoragePoolObjListFree(&driver->pools); virObjectUnref(driver->eventState); virMutexUnlock(&driver->lock); @@ -3630,11 +3631,7 @@ testInterfaceObjFindByName(testDriverPtr privconn, { virInterfaceObjPtr obj; =20 - testDriverLock(privconn); - obj =3D virInterfaceObjListFindByName(privconn->ifaces, name); - testDriverUnlock(privconn); - - if (!obj) + if (!(obj =3D virInterfaceObjListFindByName(privconn->ifaces, name))) virReportError(VIR_ERR_NO_INTERFACE, _("no interface with matching name '%s'"), name); @@ -3647,12 +3644,8 @@ static int testConnectNumOfInterfaces(virConnectPtr conn) { testDriverPtr privconn =3D conn->privateData; - int ninterfaces; =20 - testDriverLock(privconn); - ninterfaces =3D virInterfaceObjListNumOfInterfaces(privconn->ifaces, t= rue); - testDriverUnlock(privconn); - return ninterfaces; + return virInterfaceObjListNumOfInterfaces(privconn->ifaces, true); } =20 =20 @@ -3662,14 +3655,8 @@ testConnectListInterfaces(virConnectPtr conn, int maxnames) { testDriverPtr privconn =3D conn->privateData; - int nnames; =20 - testDriverLock(privconn); - nnames =3D virInterfaceObjListGetNames(privconn->ifaces, true, - names, maxnames); - testDriverUnlock(privconn); - - return nnames; + return virInterfaceObjListGetNames(privconn->ifaces, true, names, maxn= ames); } =20 =20 @@ -3677,12 +3664,8 @@ static int testConnectNumOfDefinedInterfaces(virConnectPtr conn) { testDriverPtr privconn =3D conn->privateData; - int ninterfaces; =20 - testDriverLock(privconn); - ninterfaces =3D virInterfaceObjListNumOfInterfaces(privconn->ifaces, f= alse); - testDriverUnlock(privconn); - return ninterfaces; + return virInterfaceObjListNumOfInterfaces(privconn->ifaces, false); } =20 =20 @@ -3692,14 +3675,8 @@ testConnectListDefinedInterfaces(virConnectPtr conn, int maxnames) { testDriverPtr privconn =3D conn->privateData; - int nnames; =20 - testDriverLock(privconn); - nnames =3D virInterfaceObjListGetNames(privconn->ifaces, false, - names, maxnames); - testDriverUnlock(privconn); - - return nnames; + return virInterfaceObjListGetNames(privconn->ifaces, false, names, max= names); } =20 =20 @@ -3732,12 +3709,8 @@ testInterfaceLookupByMACString(virConnectPtr conn, char *ifacenames[] =3D { NULL, NULL }; virInterfacePtr ret =3D NULL; =20 - testDriverLock(privconn); - ifacect =3D virInterfaceObjListFindByMACString(privconn->ifaces, mac, - ifacenames, 2); - testDriverUnlock(privconn); - - if (ifacect =3D=3D 0) { + if ((ifacect =3D virInterfaceObjListFindByMACString(privconn->ifaces, = mac, + ifacenames, 2)) =3D= =3D 0) { virReportError(VIR_ERR_NO_INTERFACE, _("no interface with matching mac '%s'"), mac); goto cleanup; @@ -3821,6 +3794,7 @@ testInterfaceChangeCommit(virConnectPtr conn, } =20 virInterfaceObjListFree(privconn->backupIfaces); + privconn->backupIfaces =3D NULL; privconn->transaction_running =3D false; =20 ret =3D 0; @@ -3851,8 +3825,7 @@ testInterfaceChangeRollback(virConnectPtr conn, } =20 virInterfaceObjListFree(privconn->ifaces); - privconn->ifaces =3D privconn->backupIfaces; - privconn->backupIfaces =3D NULL; + VIR_STEAL_PTR(privconn->ifaces, privconn->backupIfaces); =20 privconn->transaction_running =3D false; =20 @@ -3899,11 +3872,10 @@ testInterfaceDefineXML(virConnectPtr conn, =20 virCheckFlags(0, NULL); =20 - testDriverLock(privconn); - if ((def =3D virInterfaceDefParseString(xmlStr)) =3D=3D NULL) - goto cleanup; + if (!(def =3D virInterfaceDefParseString(xmlStr))) + return NULL; =20 - if ((obj =3D virInterfaceObjListAssignDef(privconn->ifaces, def)) =3D= =3D NULL) + if (!(obj =3D virInterfaceObjListAssignDef(privconn->ifaces, def))) goto cleanup; def =3D NULL; objdef =3D virInterfaceObjGetDef(obj); @@ -3913,7 +3885,6 @@ testInterfaceDefineXML(virConnectPtr conn, cleanup: virInterfaceDefFree(def); virInterfaceObjEndAPI(&obj); - testDriverUnlock(privconn); return ret; } =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list