From nobody Thu May 2 08:11:07 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 1493159829061424.26921415963386; Tue, 25 Apr 2017 15:37:09 -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 1BDA73DBCD; Tue, 25 Apr 2017 22:37:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DEE5786D25; Tue, 25 Apr 2017 22:37: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 97FF74ED32; Tue, 25 Apr 2017 22:37:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PMb1En029179 for ; Tue, 25 Apr 2017 18:37:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id DB1AE18123; Tue, 25 Apr 2017 22:37:01 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 759231811B for ; Tue, 25 Apr 2017 22:37:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1BDA73DBCD 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 1BDA73DBCD From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 18:36:49 -0400 Message-Id: <20170425223656.20740-2-jferlan@redhat.com> In-Reply-To: <20170425223656.20740-1-jferlan@redhat.com> References: <20170425223656.20740-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/8] interface: Consistently use 'obj' for a virInterfaceObjPtr 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.30]); Tue, 25 Apr 2017 22:37:08 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Alter variable names to be obj rather than 'iface' and/or 'obj'. Signed-off-by: John Ferlan --- src/conf/virinterfaceobj.c | 48 ++++++++++++++-------------- src/conf/virinterfaceobj.h | 4 +-- src/test/test_driver.c | 78 +++++++++++++++++++++++-------------------= ---- 3 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index e80db23..62c3735 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -51,14 +51,14 @@ virInterfaceObjUnlock(virInterfaceObjPtr obj) =20 =20 void -virInterfaceObjFree(virInterfaceObjPtr iface) +virInterfaceObjFree(virInterfaceObjPtr obj) { - if (!iface) + if (!obj) return; =20 - virInterfaceDefFree(iface->def); - virMutexDestroy(&iface->lock); - VIR_FREE(iface); + virInterfaceDefFree(obj->def); + virMutexDestroy(&obj->lock); + VIR_FREE(obj); } =20 =20 @@ -136,7 +136,7 @@ virInterfaceObjListClone(virInterfaceObjListPtr src, for (i =3D 0; i < cnt; i++) { virInterfaceDefPtr def =3D src->objs[i]->def; virInterfaceDefPtr backup; - virInterfaceObjPtr iface; + virInterfaceObjPtr obj; char *xml =3D virInterfaceDefFormat(def); =20 if (!xml) @@ -148,9 +148,9 @@ virInterfaceObjListClone(virInterfaceObjListPtr src, } =20 VIR_FREE(xml); - if ((iface =3D virInterfaceObjAssignDef(dest, backup)) =3D=3D NULL) + if ((obj =3D virInterfaceObjAssignDef(dest, backup)) =3D=3D NULL) goto cleanup; - virInterfaceObjUnlock(iface); /* locked by virInterfaceObjAssignDe= f */ + virInterfaceObjUnlock(obj); /* locked by virInterfaceObjAssignDef = */ } =20 ret =3D cnt; @@ -165,47 +165,47 @@ virInterfaceObjPtr virInterfaceObjAssignDef(virInterfaceObjListPtr interfaces, virInterfaceDefPtr def) { - virInterfaceObjPtr iface; + virInterfaceObjPtr obj; =20 - if ((iface =3D virInterfaceObjFindByName(interfaces, def->name))) { - virInterfaceDefFree(iface->def); - iface->def =3D def; + if ((obj =3D virInterfaceObjFindByName(interfaces, def->name))) { + virInterfaceDefFree(obj->def); + obj->def =3D def; =20 - return iface; + return obj; } =20 - if (VIR_ALLOC(iface) < 0) + if (VIR_ALLOC(obj) < 0) return NULL; - if (virMutexInit(&iface->lock) < 0) { + if (virMutexInit(&obj->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); - VIR_FREE(iface); + VIR_FREE(obj); return NULL; } - virInterfaceObjLock(iface); + virInterfaceObjLock(obj); =20 if (VIR_APPEND_ELEMENT_COPY(interfaces->objs, - interfaces->count, iface) < 0) { - virInterfaceObjFree(iface); + interfaces->count, obj) < 0) { + virInterfaceObjFree(obj); return NULL; } =20 - iface->def =3D def; - return iface; + obj->def =3D def; + return obj; =20 } =20 =20 void virInterfaceObjRemove(virInterfaceObjListPtr interfaces, - virInterfaceObjPtr iface) + virInterfaceObjPtr obj) { size_t i; =20 - virInterfaceObjUnlock(iface); + virInterfaceObjUnlock(obj); for (i =3D 0; i < interfaces->count; i++) { virInterfaceObjLock(interfaces->objs[i]); - if (interfaces->objs[i] =3D=3D iface) { + if (interfaces->objs[i] =3D=3D obj) { virInterfaceObjUnlock(interfaces->objs[i]); virInterfaceObjFree(interfaces->objs[i]); =20 diff --git a/src/conf/virinterfaceobj.h b/src/conf/virinterfaceobj.h index 5b0527d..ee166c6 100644 --- a/src/conf/virinterfaceobj.h +++ b/src/conf/virinterfaceobj.h @@ -54,7 +54,7 @@ virInterfaceObjFindByName(virInterfaceObjListPtr interfac= es, const char *name); =20 void -virInterfaceObjFree(virInterfaceObjPtr iface); +virInterfaceObjFree(virInterfaceObjPtr obj); =20 void virInterfaceObjListFree(virInterfaceObjListPtr vms); @@ -69,7 +69,7 @@ virInterfaceObjAssignDef(virInterfaceObjListPtr interface= s, =20 void virInterfaceObjRemove(virInterfaceObjListPtr interfaces, - virInterfaceObjPtr iface); + virInterfaceObjPtr obj); =20 void virInterfaceObjLock(virInterfaceObjPtr obj); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 2db3f7d..c2697e8 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -3627,18 +3627,18 @@ static virInterfaceObjPtr testInterfaceObjFindByName(testDriverPtr privconn, const char *name) { - virInterfaceObjPtr iface; + virInterfaceObjPtr obj; =20 testDriverLock(privconn); - iface =3D virInterfaceObjFindByName(&privconn->ifaces, name); + obj =3D virInterfaceObjFindByName(&privconn->ifaces, name); testDriverUnlock(privconn); =20 - if (!iface) + if (!obj) virReportError(VIR_ERR_NO_INTERFACE, _("no interface with matching name '%s'"), name); =20 - return iface; + return obj; } =20 =20 @@ -3705,17 +3705,17 @@ testInterfaceLookupByName(virConnectPtr conn, const char *name) { testDriverPtr privconn =3D conn->privateData; - virInterfaceObjPtr iface; + virInterfaceObjPtr obj; virInterfacePtr ret =3D NULL; =20 - if (!(iface =3D testInterfaceObjFindByName(privconn, name))) + if (!(obj =3D testInterfaceObjFindByName(privconn, name))) goto cleanup; =20 - ret =3D virGetInterface(conn, iface->def->name, iface->def->mac); + ret =3D virGetInterface(conn, obj->def->name, obj->def->mac); =20 cleanup: - if (iface) - virInterfaceObjUnlock(iface); + if (obj) + virInterfaceObjUnlock(obj); return ret; } =20 @@ -3725,12 +3725,12 @@ testInterfaceLookupByMACString(virConnectPtr conn, const char *mac) { testDriverPtr privconn =3D conn->privateData; - virInterfaceObjPtr iface; + virInterfaceObjPtr obj; int ifacect; virInterfacePtr ret =3D NULL; =20 testDriverLock(privconn); - ifacect =3D virInterfaceObjFindByMACString(&privconn->ifaces, mac, &if= ace, 1); + ifacect =3D virInterfaceObjFindByMACString(&privconn->ifaces, mac, &ob= j, 1); testDriverUnlock(privconn); =20 if (ifacect =3D=3D 0) { @@ -3743,11 +3743,11 @@ testInterfaceLookupByMACString(virConnectPtr conn, goto cleanup; } =20 - ret =3D virGetInterface(conn, iface->def->name, iface->def->mac); + ret =3D virGetInterface(conn, obj->def->name, obj->def->mac); =20 cleanup: - if (iface) - virInterfaceObjUnlock(iface); + if (obj) + virInterfaceObjUnlock(obj); return ret; } =20 @@ -3869,19 +3869,19 @@ testInterfaceGetXMLDesc(virInterfacePtr iface, unsigned int flags) { testDriverPtr privconn =3D iface->conn->privateData; - virInterfaceObjPtr privinterface; + virInterfaceObjPtr obj; char *ret =3D NULL; =20 virCheckFlags(0, NULL); =20 - if (!(privinterface =3D testInterfaceObjFindByName(privconn, iface->na= me))) + if (!(obj =3D testInterfaceObjFindByName(privconn, iface->name))) goto cleanup; =20 - ret =3D virInterfaceDefFormat(privinterface->def); + ret =3D virInterfaceDefFormat(obj->def); =20 cleanup: - if (privinterface) - virInterfaceObjUnlock(privinterface); + if (obj) + virInterfaceObjUnlock(obj); return ret; } =20 @@ -3893,7 +3893,7 @@ testInterfaceDefineXML(virConnectPtr conn, { testDriverPtr privconn =3D conn->privateData; virInterfaceDefPtr def; - virInterfaceObjPtr iface =3D NULL; + virInterfaceObjPtr obj =3D NULL; virInterfacePtr ret =3D NULL; =20 virCheckFlags(0, NULL); @@ -3902,16 +3902,16 @@ testInterfaceDefineXML(virConnectPtr conn, if ((def =3D virInterfaceDefParseString(xmlStr)) =3D=3D NULL) goto cleanup; =20 - if ((iface =3D virInterfaceObjAssignDef(&privconn->ifaces, def)) =3D= =3D NULL) + if ((obj =3D virInterfaceObjAssignDef(&privconn->ifaces, def)) =3D=3D = NULL) goto cleanup; def =3D NULL; =20 - ret =3D virGetInterface(conn, iface->def->name, iface->def->mac); + ret =3D virGetInterface(conn, obj->def->name, obj->def->mac); =20 cleanup: virInterfaceDefFree(def); - if (iface) - virInterfaceObjUnlock(iface); + if (obj) + virInterfaceObjUnlock(obj); testDriverUnlock(privconn); return ret; } @@ -3921,13 +3921,13 @@ static int testInterfaceUndefine(virInterfacePtr iface) { testDriverPtr privconn =3D iface->conn->privateData; - virInterfaceObjPtr privinterface; + virInterfaceObjPtr obj; int ret =3D -1; =20 - if (!(privinterface =3D testInterfaceObjFindByName(privconn, iface->na= me))) + if (!(obj =3D testInterfaceObjFindByName(privconn, iface->name))) goto cleanup; =20 - virInterfaceObjRemove(&privconn->ifaces, privinterface); + virInterfaceObjRemove(&privconn->ifaces, obj); ret =3D 0; =20 cleanup: @@ -3940,25 +3940,25 @@ testInterfaceCreate(virInterfacePtr iface, unsigned int flags) { testDriverPtr privconn =3D iface->conn->privateData; - virInterfaceObjPtr privinterface; + virInterfaceObjPtr obj; int ret =3D -1; =20 virCheckFlags(0, -1); =20 - if (!(privinterface =3D testInterfaceObjFindByName(privconn, iface->na= me))) + if (!(obj =3D testInterfaceObjFindByName(privconn, iface->name))) goto cleanup; =20 - if (privinterface->active !=3D 0) { + if (obj->active !=3D 0) { virReportError(VIR_ERR_OPERATION_INVALID, NULL); goto cleanup; } =20 - privinterface->active =3D 1; + obj->active =3D 1; ret =3D 0; =20 cleanup: - if (privinterface) - virInterfaceObjUnlock(privinterface); + if (obj) + virInterfaceObjUnlock(obj); return ret; } =20 @@ -3968,25 +3968,25 @@ testInterfaceDestroy(virInterfacePtr iface, unsigned int flags) { testDriverPtr privconn =3D iface->conn->privateData; - virInterfaceObjPtr privinterface; + virInterfaceObjPtr obj; int ret =3D -1; =20 virCheckFlags(0, -1); =20 - if (!(privinterface =3D testInterfaceObjFindByName(privconn, iface->na= me))) + if (!(obj =3D testInterfaceObjFindByName(privconn, iface->name))) goto cleanup; =20 - if (privinterface->active =3D=3D 0) { + if (obj->active =3D=3D 0) { virReportError(VIR_ERR_OPERATION_INVALID, NULL); goto cleanup; } =20 - privinterface->active =3D 0; + obj->active =3D 0; ret =3D 0; =20 cleanup: - if (privinterface) - virInterfaceObjUnlock(privinterface); + if (obj) + virInterfaceObjUnlock(obj); return ret; } =20 --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 08:11:07 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 1493159846434285.22804180067544; Tue, 25 Apr 2017 15:37:26 -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 C69FC46D091; Tue, 25 Apr 2017 22:37:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8A75A18115; Tue, 25 Apr 2017 22:37:24 +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 357865EC62; Tue, 25 Apr 2017 22:37:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PMb30w029187 for ; Tue, 25 Apr 2017 18:37:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3AEB91811B; Tue, 25 Apr 2017 22:37:03 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB99360E3E for ; Tue, 25 Apr 2017 22:37:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C69FC46D091 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 C69FC46D091 From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 18:36:50 -0400 Message-Id: <20170425223656.20740-3-jferlan@redhat.com> In-Reply-To: <20170425223656.20740-1-jferlan@redhat.com> References: <20170425223656.20740-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/8] interface: Remove some unnecessary goto's for Interface tests 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.29]); Tue, 25 Apr 2017 22:37:25 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than using goto cleanup on object find failure and having cleanup need to check if the obj was present before unlocking, just return immediat= ely. Signed-off-by: John Ferlan --- src/test/test_driver.c | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index c2697e8..da45542 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -3709,13 +3709,11 @@ testInterfaceLookupByName(virConnectPtr conn, virInterfacePtr ret =3D NULL; =20 if (!(obj =3D testInterfaceObjFindByName(privconn, name))) - goto cleanup; + return NULL; =20 ret =3D virGetInterface(conn, obj->def->name, obj->def->mac); =20 - cleanup: - if (obj) - virInterfaceObjUnlock(obj); + virInterfaceObjUnlock(obj); return ret; } =20 @@ -3760,13 +3758,11 @@ testInterfaceIsActive(virInterfacePtr iface) int ret =3D -1; =20 if (!(obj =3D testInterfaceObjFindByName(privconn, iface->name))) - goto cleanup; + return -1; =20 ret =3D virInterfaceObjIsActive(obj); =20 - cleanup: - if (obj) - virInterfaceObjUnlock(obj); + virInterfaceObjUnlock(obj); return ret; } =20 @@ -3875,13 +3871,11 @@ testInterfaceGetXMLDesc(virInterfacePtr iface, virCheckFlags(0, NULL); =20 if (!(obj =3D testInterfaceObjFindByName(privconn, iface->name))) - goto cleanup; + return NULL; =20 ret =3D virInterfaceDefFormat(obj->def); =20 - cleanup: - if (obj) - virInterfaceObjUnlock(obj); + virInterfaceObjUnlock(obj); return ret; } =20 @@ -3899,7 +3893,7 @@ testInterfaceDefineXML(virConnectPtr conn, virCheckFlags(0, NULL); =20 testDriverLock(privconn); - if ((def =3D virInterfaceDefParseString(xmlStr)) =3D=3D NULL) + if (!(def =3D virInterfaceDefParseString(xmlStr))) goto cleanup; =20 if ((obj =3D virInterfaceObjAssignDef(&privconn->ifaces, def)) =3D=3D = NULL) @@ -3922,16 +3916,13 @@ testInterfaceUndefine(virInterfacePtr iface) { testDriverPtr privconn =3D iface->conn->privateData; virInterfaceObjPtr obj; - int ret =3D -1; =20 if (!(obj =3D testInterfaceObjFindByName(privconn, iface->name))) - goto cleanup; + return -1; =20 virInterfaceObjRemove(&privconn->ifaces, obj); - ret =3D 0; =20 - cleanup: - return ret; + return 0; } =20 =20 @@ -3946,7 +3937,7 @@ testInterfaceCreate(virInterfacePtr iface, virCheckFlags(0, -1); =20 if (!(obj =3D testInterfaceObjFindByName(privconn, iface->name))) - goto cleanup; + return -1; =20 if (obj->active !=3D 0) { virReportError(VIR_ERR_OPERATION_INVALID, NULL); @@ -3957,8 +3948,7 @@ testInterfaceCreate(virInterfacePtr iface, ret =3D 0; =20 cleanup: - if (obj) - virInterfaceObjUnlock(obj); + virInterfaceObjUnlock(obj); return ret; } =20 @@ -3974,7 +3964,7 @@ testInterfaceDestroy(virInterfacePtr iface, virCheckFlags(0, -1); =20 if (!(obj =3D testInterfaceObjFindByName(privconn, iface->name))) - goto cleanup; + return -1; =20 if (obj->active =3D=3D 0) { virReportError(VIR_ERR_OPERATION_INVALID, NULL); @@ -3985,8 +3975,7 @@ testInterfaceDestroy(virInterfacePtr iface, ret =3D 0; =20 cleanup: - if (obj) - virInterfaceObjUnlock(obj); + virInterfaceObjUnlock(obj); return ret; } =20 --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 08:11:07 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 1493159829347833.4809862465164; Tue, 25 Apr 2017 15:37: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 4BF1F3DBD5; Tue, 25 Apr 2017 22:37:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1F5BD19EE3; Tue, 25 Apr 2017 22:37:07 +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 AFF114E9BD; Tue, 25 Apr 2017 22:37:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PMb33K029194 for ; Tue, 25 Apr 2017 18:37:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id AB1A01811B; Tue, 25 Apr 2017 22:37:03 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6643760E3E for ; Tue, 25 Apr 2017 22:37:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4BF1F3DBD5 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 4BF1F3DBD5 From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 18:36:51 -0400 Message-Id: <20170425223656.20740-4-jferlan@redhat.com> In-Reply-To: <20170425223656.20740-1-jferlan@redhat.com> References: <20170425223656.20740-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/8] interface: Use virInterfaceDefPtr rather than deref from virInterfaceObjPtr 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.30]); Tue, 25 Apr 2017 22:37:08 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We're about to make the obj much more private, so make it easier to see future changes which will require accessors for the obj->def This also includes modifying some interfaces->objs[i]->X references to be obj =3D interfaces->objs[i]; and then def =3D obj->def Signed-off-by: John Ferlan --- src/conf/virinterfaceobj.c | 33 +++++++++++++++++++++------------ src/test/test_driver.c | 12 +++++++++--- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index 62c3735..36131af 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -55,7 +55,6 @@ virInterfaceObjFree(virInterfaceObjPtr obj) { if (!obj) return; - virInterfaceDefFree(obj->def); virMutexDestroy(&obj->lock); VIR_FREE(obj); @@ -72,18 +71,21 @@ virInterfaceObjFindByMACString(virInterfaceObjListPtr i= nterfaces, unsigned int matchct =3D 0; =20 for (i =3D 0; i < interfaces->count; i++) { + virInterfaceObjPtr obj =3D interfaces->objs[i]; + virInterfaceDefPtr def; =20 - virInterfaceObjLock(interfaces->objs[i]); - if (STRCASEEQ(interfaces->objs[i]->def->mac, mac)) { + virInterfaceObjLock(obj); + def =3D obj->def; + if (STRCASEEQ(def->mac, mac)) { matchct++; if (matchct <=3D maxmatches) { - matches[matchct - 1] =3D interfaces->objs[i]; + matches[matchct - 1] =3D obj; /* keep the lock if we're returning object to caller */ /* it is the caller's responsibility to unlock *all* match= es */ continue; } } - virInterfaceObjUnlock(interfaces->objs[i]); + virInterfaceObjUnlock(obj); =20 } return matchct; @@ -97,10 +99,14 @@ virInterfaceObjFindByName(virInterfaceObjListPtr interf= aces, size_t i; =20 for (i =3D 0; i < interfaces->count; i++) { - virInterfaceObjLock(interfaces->objs[i]); - if (STREQ(interfaces->objs[i]->def->name, name)) - return interfaces->objs[i]; - virInterfaceObjUnlock(interfaces->objs[i]); + virInterfaceObjPtr obj =3D interfaces->objs[i]; + virInterfaceDefPtr def; + + virInterfaceObjLock(obj); + def =3D obj->def; + if (STREQ(def->name, name)) + return obj; + virInterfaceObjUnlock(obj); } =20 return NULL; @@ -134,10 +140,10 @@ virInterfaceObjListClone(virInterfaceObjListPtr src, virInterfaceObjListFree(dest); /* start with an empty list */ cnt =3D src->count; for (i =3D 0; i < cnt; i++) { - virInterfaceDefPtr def =3D src->objs[i]->def; + virInterfaceObjPtr srcobj =3D src->objs[i]; virInterfaceDefPtr backup; virInterfaceObjPtr obj; - char *xml =3D virInterfaceDefFormat(def); + char *xml =3D virInterfaceDefFormat(srcobj->def); =20 if (!xml) goto cleanup; @@ -247,9 +253,12 @@ virInterfaceObjGetNames(virInterfaceObjListPtr interfa= ces, =20 for (i =3D 0; i < interfaces->count && nnames < maxnames; i++) { virInterfaceObjPtr obj =3D interfaces->objs[i]; + virInterfaceDefPtr def; + virInterfaceObjLock(obj); + def =3D obj->def; if (wantActive =3D=3D virInterfaceObjIsActive(obj)) { - if (VIR_STRDUP(names[nnames], obj->def->name) < 0) { + if (VIR_STRDUP(names[nnames], def->name) < 0) { virInterfaceObjUnlock(obj); goto failure; } diff --git a/src/test/test_driver.c b/src/test/test_driver.c index da45542..6ff4657 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -3706,12 +3706,14 @@ testInterfaceLookupByName(virConnectPtr conn, { testDriverPtr privconn =3D conn->privateData; virInterfaceObjPtr obj; + virInterfaceDefPtr def; virInterfacePtr ret =3D NULL; =20 if (!(obj =3D testInterfaceObjFindByName(privconn, name))) return NULL; + def =3D obj->def; =20 - ret =3D virGetInterface(conn, obj->def->name, obj->def->mac); + ret =3D virGetInterface(conn, def->name, def->mac); =20 virInterfaceObjUnlock(obj); return ret; @@ -3724,6 +3726,7 @@ testInterfaceLookupByMACString(virConnectPtr conn, { testDriverPtr privconn =3D conn->privateData; virInterfaceObjPtr obj; + virInterfaceDefPtr def; int ifacect; virInterfacePtr ret =3D NULL; =20 @@ -3741,7 +3744,8 @@ testInterfaceLookupByMACString(virConnectPtr conn, goto cleanup; } =20 - ret =3D virGetInterface(conn, obj->def->name, obj->def->mac); + def =3D obj->def; + ret =3D virGetInterface(conn, def->name, def->mac); =20 cleanup: if (obj) @@ -3888,6 +3892,7 @@ testInterfaceDefineXML(virConnectPtr conn, testDriverPtr privconn =3D conn->privateData; virInterfaceDefPtr def; virInterfaceObjPtr obj =3D NULL; + virInterfaceDefPtr objdef; virInterfacePtr ret =3D NULL; =20 virCheckFlags(0, NULL); @@ -3899,8 +3904,9 @@ testInterfaceDefineXML(virConnectPtr conn, if ((obj =3D virInterfaceObjAssignDef(&privconn->ifaces, def)) =3D=3D = NULL) goto cleanup; def =3D NULL; + objdef =3D obj->def; =20 - ret =3D virGetInterface(conn, obj->def->name, obj->def->mac); + ret =3D virGetInterface(conn, objdef->name, objdef->mac); =20 cleanup: virInterfaceDefFree(def); --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 08:11:07 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 1493159846156683.0683748485554; Tue, 25 Apr 2017 15:37: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 BAA883DBC8; Tue, 25 Apr 2017 22:37:24 +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 8CF8B86D37; Tue, 25 Apr 2017 22:37:24 +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 2A47E18523C0; Tue, 25 Apr 2017 22:37:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PMb4f5029199 for ; Tue, 25 Apr 2017 18:37:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 224CE1811B; Tue, 25 Apr 2017 22:37:04 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3C1B60E3E for ; Tue, 25 Apr 2017 22:37:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BAA883DBC8 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 BAA883DBC8 From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 18:36:52 -0400 Message-Id: <20170425223656.20740-5-jferlan@redhat.com> In-Reply-To: <20170425223656.20740-1-jferlan@redhat.com> References: <20170425223656.20740-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/8] interface: Make _virInterfaceObj struct private 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.30]); Tue, 25 Apr 2017 22:37:25 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move the struct into virinterfaceobj.c, create necessary accessors, and initializers. Signed-off-by: John Ferlan --- src/conf/virinterfaceobj.c | 28 ++++++++++++++++++++++++++++ src/conf/virinterfaceobj.h | 20 +++++++++----------- src/libvirt_private.syms | 3 +++ src/test/test_driver.c | 20 +++++++++++--------- 4 files changed, 51 insertions(+), 20 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index 36131af..68faa66 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -32,6 +32,12 @@ =20 VIR_LOG_INIT("conf.virinterfaceobj"); =20 +struct _virInterfaceObj { + virMutex lock; + + bool active; /* true if interface is active (up) */ + virInterfaceDefPtr def; /* The interface definition */ +}; =20 =20 /* virInterfaceObj manipulation */ @@ -61,6 +67,28 @@ virInterfaceObjFree(virInterfaceObjPtr obj) } =20 =20 +virInterfaceDefPtr +virInterfaceObjGetDef(virInterfaceObjPtr obj) +{ + return obj->def; +} + + +bool +virInterfaceObjIsActive(virInterfaceObjPtr obj) +{ + return obj->active; +} + + +void +virInterfaceObjSetActive(virInterfaceObjPtr obj, + bool active) +{ + obj->active =3D active; +} + + /* virInterfaceObjList manipulation */ int virInterfaceObjFindByMACString(virInterfaceObjListPtr interfaces, diff --git a/src/conf/virinterfaceobj.h b/src/conf/virinterfaceobj.h index ee166c6..79b6fc9 100644 --- a/src/conf/virinterfaceobj.h +++ b/src/conf/virinterfaceobj.h @@ -24,12 +24,6 @@ =20 typedef struct _virInterfaceObj virInterfaceObj; typedef virInterfaceObj *virInterfaceObjPtr; -struct _virInterfaceObj { - virMutex lock; - - bool active; /* true if interface is active (up) */ - virInterfaceDefPtr def; /* The interface definition */ -}; =20 typedef struct _virInterfaceObjList virInterfaceObjList; typedef virInterfaceObjList *virInterfaceObjListPtr; @@ -38,11 +32,15 @@ struct _virInterfaceObjList { virInterfaceObjPtr *objs; }; =20 -static inline bool -virInterfaceObjIsActive(const virInterfaceObj *iface) -{ - return iface->active; -} +virInterfaceDefPtr +virInterfaceObjGetDef(virInterfaceObjPtr obj); + +bool +virInterfaceObjIsActive(virInterfaceObjPtr obj); + +void +virInterfaceObjSetActive(virInterfaceObjPtr obj, + bool active); =20 int virInterfaceObjFindByMACString(virInterfaceObjListPtr interfaces, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 83e979a..751d1ac 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -909,12 +909,15 @@ virDomainObjListRename; virInterfaceObjAssignDef; virInterfaceObjFindByMACString; virInterfaceObjFindByName; +virInterfaceObjGetDef; virInterfaceObjGetNames; +virInterfaceObjIsActive; virInterfaceObjListClone; virInterfaceObjListFree; virInterfaceObjLock; virInterfaceObjNumOfInterfaces; virInterfaceObjRemove; +virInterfaceObjSetActive; virInterfaceObjUnlock; =20 =20 diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 6ff4657..412d9f1 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1025,7 +1025,7 @@ testParseInterfaces(testDriverPtr privconn, goto error; } =20 - obj->active =3D 1; + virInterfaceObjSetActive(obj, true); virInterfaceObjUnlock(obj); } =20 @@ -3711,7 +3711,7 @@ testInterfaceLookupByName(virConnectPtr conn, =20 if (!(obj =3D testInterfaceObjFindByName(privconn, name))) return NULL; - def =3D obj->def; + def =3D virInterfaceObjGetDef(obj); =20 ret =3D virGetInterface(conn, def->name, def->mac); =20 @@ -3744,7 +3744,7 @@ testInterfaceLookupByMACString(virConnectPtr conn, goto cleanup; } =20 - def =3D obj->def; + def =3D virInterfaceObjGetDef(obj); ret =3D virGetInterface(conn, def->name, def->mac); =20 cleanup: @@ -3870,14 +3870,16 @@ testInterfaceGetXMLDesc(virInterfacePtr iface, { testDriverPtr privconn =3D iface->conn->privateData; virInterfaceObjPtr obj; + virInterfaceDefPtr def; char *ret =3D NULL; =20 virCheckFlags(0, NULL); =20 if (!(obj =3D testInterfaceObjFindByName(privconn, iface->name))) return NULL; + def =3D virInterfaceObjGetDef(obj); =20 - ret =3D virInterfaceDefFormat(obj->def); + ret =3D virInterfaceDefFormat(def); =20 virInterfaceObjUnlock(obj); return ret; @@ -3904,7 +3906,7 @@ testInterfaceDefineXML(virConnectPtr conn, if ((obj =3D virInterfaceObjAssignDef(&privconn->ifaces, def)) =3D=3D = NULL) goto cleanup; def =3D NULL; - objdef =3D obj->def; + objdef =3D virInterfaceObjGetDef(obj); =20 ret =3D virGetInterface(conn, objdef->name, objdef->mac); =20 @@ -3945,12 +3947,12 @@ testInterfaceCreate(virInterfacePtr iface, if (!(obj =3D testInterfaceObjFindByName(privconn, iface->name))) return -1; =20 - if (obj->active !=3D 0) { + if (virInterfaceObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, NULL); goto cleanup; } =20 - obj->active =3D 1; + virInterfaceObjSetActive(obj, true); ret =3D 0; =20 cleanup: @@ -3972,12 +3974,12 @@ testInterfaceDestroy(virInterfacePtr iface, if (!(obj =3D testInterfaceObjFindByName(privconn, iface->name))) return -1; =20 - if (obj->active =3D=3D 0) { + if (!virInterfaceObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, NULL); goto cleanup; } =20 - obj->active =3D 0; + virInterfaceObjSetActive(obj, false); ret =3D 0; =20 cleanup: --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 08:11:07 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 1493159850728602.6620125844414; Tue, 25 Apr 2017 15:37:30 -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 03D4661B8C; Tue, 25 Apr 2017 22:37:29 +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 C64E17BE49; Tue, 25 Apr 2017 22:37:28 +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 6D0A018523D7; Tue, 25 Apr 2017 22:37:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PMb4Sg029204 for ; Tue, 25 Apr 2017 18:37:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9BCBE1811B; Tue, 25 Apr 2017 22:37:04 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 595D460E3E for ; Tue, 25 Apr 2017 22:37:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 03D4661B8C 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 03D4661B8C From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 18:36:53 -0400 Message-Id: <20170425223656.20740-6-jferlan@redhat.com> In-Reply-To: <20170425223656.20740-1-jferlan@redhat.com> References: <20170425223656.20740-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/8] interface: Make _virInterfaceObjList struct private 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.39]); Tue, 25 Apr 2017 22:37:29 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move the structs into virinterfaceobj.c, create necessary accessors, and initializers. This also includes reworking virInterfaceObjListClone to handle receiving a source interfaces list pointer, creating the destination interfaces objec= t, and copying everything from source into dest. Signed-off-by: John Ferlan --- src/conf/virinterfaceobj.c | 58 ++++++++++++++++++++++++++++--------------= ---- src/conf/virinterfaceobj.h | 12 ++++------ src/test/test_driver.c | 38 ++++++++++++++---------------- 3 files changed, 59 insertions(+), 49 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index 68faa66..301ad94 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -39,6 +39,10 @@ struct _virInterfaceObj { virInterfaceDefPtr def; /* The interface definition */ }; =20 +struct _virInterfaceObjList { + size_t count; + virInterfaceObjPtr *objs; +}; =20 /* virInterfaceObj manipulation */ =20 @@ -90,6 +94,17 @@ virInterfaceObjSetActive(virInterfaceObjPtr obj, =20 =20 /* virInterfaceObjList manipulation */ +virInterfaceObjListPtr +virInterfaceObjListNew(void) +{ + virInterfaceObjListPtr interfaces; + + if (VIR_ALLOC(interfaces) < 0) + return NULL; + return interfaces; +} + + int virInterfaceObjFindByMACString(virInterfaceObjListPtr interfaces, const char *mac, @@ -148,50 +163,49 @@ virInterfaceObjListFree(virInterfaceObjListPtr interf= aces) =20 for (i =3D 0; i < interfaces->count; i++) virInterfaceObjFree(interfaces->objs[i]); - - VIR_FREE(interfaces->objs); - interfaces->count =3D 0; + VIR_FREE(interfaces); } =20 =20 -int -virInterfaceObjListClone(virInterfaceObjListPtr src, - virInterfaceObjListPtr dest) +virInterfaceObjListPtr +virInterfaceObjListClone(virInterfaceObjListPtr interfaces) { - int ret =3D -1; size_t i; unsigned int cnt; + virInterfaceObjListPtr dest; =20 - if (!src || !dest) - goto cleanup; + if (!interfaces) + return NULL; =20 - virInterfaceObjListFree(dest); /* start with an empty list */ - cnt =3D src->count; + if (!(dest =3D virInterfaceObjListNew())) + return NULL; + + cnt =3D interfaces->count; for (i =3D 0; i < cnt; i++) { - virInterfaceObjPtr srcobj =3D src->objs[i]; + virInterfaceObjPtr srcobj =3D interfaces->objs[i]; virInterfaceDefPtr backup; virInterfaceObjPtr obj; char *xml =3D virInterfaceDefFormat(srcobj->def); =20 if (!xml) - goto cleanup; + goto error; =20 - if ((backup =3D virInterfaceDefParseString(xml)) =3D=3D NULL) { + if (!(backup =3D virInterfaceDefParseString(xml))) { VIR_FREE(xml); - goto cleanup; + goto error; } =20 VIR_FREE(xml); - if ((obj =3D virInterfaceObjAssignDef(dest, backup)) =3D=3D NULL) - goto cleanup; + if (!(obj =3D virInterfaceObjAssignDef(dest, backup))) + goto error; virInterfaceObjUnlock(obj); /* locked by virInterfaceObjAssignDef = */ } =20 - ret =3D cnt; - cleanup: - if ((ret < 0) && dest) - virInterfaceObjListFree(dest); - return ret; + return dest; + + error: + virInterfaceObjListFree(dest); + return NULL; } =20 =20 diff --git a/src/conf/virinterfaceobj.h b/src/conf/virinterfaceobj.h index 79b6fc9..19c4947 100644 --- a/src/conf/virinterfaceobj.h +++ b/src/conf/virinterfaceobj.h @@ -27,10 +27,6 @@ typedef virInterfaceObj *virInterfaceObjPtr; =20 typedef struct _virInterfaceObjList virInterfaceObjList; typedef virInterfaceObjList *virInterfaceObjListPtr; -struct _virInterfaceObjList { - size_t count; - virInterfaceObjPtr *objs; -}; =20 virInterfaceDefPtr virInterfaceObjGetDef(virInterfaceObjPtr obj); @@ -42,6 +38,9 @@ void virInterfaceObjSetActive(virInterfaceObjPtr obj, bool active); =20 +virInterfaceObjListPtr +virInterfaceObjListNew(void); + int virInterfaceObjFindByMACString(virInterfaceObjListPtr interfaces, const char *mac, @@ -57,9 +56,8 @@ virInterfaceObjFree(virInterfaceObjPtr obj); void virInterfaceObjListFree(virInterfaceObjListPtr vms); =20 -int -virInterfaceObjListClone(virInterfaceObjListPtr src, - virInterfaceObjListPtr dest); +virInterfaceObjListPtr +virInterfaceObjListClone(virInterfaceObjListPtr interfaces); =20 virInterfaceObjPtr virInterfaceObjAssignDef(virInterfaceObjListPtr interfaces, diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 412d9f1..2cd55ec 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -97,9 +97,9 @@ struct _testDriver { virMutex lock; =20 virNodeInfo nodeInfo; - virInterfaceObjList ifaces; + virInterfaceObjListPtr ifaces; bool transaction_running; - virInterfaceObjList backupIfaces; + virInterfaceObjListPtr backupIfaces; virStoragePoolObjList pools; virNodeDeviceObjList devs; int numCells; @@ -154,7 +154,7 @@ testDriverFree(testDriverPtr driver) virObjectUnref(driver->domains); virNodeDeviceObjListFree(&driver->devs); virObjectUnref(driver->networks); - virInterfaceObjListFree(&driver->ifaces); + virInterfaceObjListFree(driver->ifaces); virStoragePoolObjListFree(&driver->pools); virObjectUnref(driver->eventState); virMutexUnlock(&driver->lock); @@ -416,6 +416,7 @@ testDriverNew(void) =20 if (!(ret->xmlopt =3D virDomainXMLOptionNew(NULL, NULL, &ns)) || !(ret->eventState =3D virObjectEventStateNew()) || + !(ret->ifaces =3D virInterfaceObjListNew()) || !(ret->domains =3D virDomainObjListNew()) || !(ret->networks =3D virNetworkObjListNew())) goto error; @@ -1020,7 +1021,7 @@ testParseInterfaces(testDriverPtr privconn, if (!def) goto error; =20 - if (!(obj =3D virInterfaceObjAssignDef(&privconn->ifaces, def))) { + if (!(obj =3D virInterfaceObjAssignDef(privconn->ifaces, def))) { virInterfaceDefFree(def); goto error; } @@ -3630,7 +3631,7 @@ testInterfaceObjFindByName(testDriverPtr privconn, virInterfaceObjPtr obj; =20 testDriverLock(privconn); - obj =3D virInterfaceObjFindByName(&privconn->ifaces, name); + obj =3D virInterfaceObjFindByName(privconn->ifaces, name); testDriverUnlock(privconn); =20 if (!obj) @@ -3649,7 +3650,7 @@ testConnectNumOfInterfaces(virConnectPtr conn) int ninterfaces; =20 testDriverLock(privconn); - ninterfaces =3D virInterfaceObjNumOfInterfaces(&privconn->ifaces, true= ); + ninterfaces =3D virInterfaceObjNumOfInterfaces(privconn->ifaces, true); testDriverUnlock(privconn); return ninterfaces; } @@ -3664,7 +3665,7 @@ testConnectListInterfaces(virConnectPtr conn, int nnames; =20 testDriverLock(privconn); - nnames =3D virInterfaceObjGetNames(&privconn->ifaces, true, names, max= names); + nnames =3D virInterfaceObjGetNames(privconn->ifaces, true, names, maxn= ames); testDriverUnlock(privconn); =20 return nnames; @@ -3678,7 +3679,7 @@ testConnectNumOfDefinedInterfaces(virConnectPtr conn) int ninterfaces; =20 testDriverLock(privconn); - ninterfaces =3D virInterfaceObjNumOfInterfaces(&privconn->ifaces, fals= e); + ninterfaces =3D virInterfaceObjNumOfInterfaces(privconn->ifaces, false= ); testDriverUnlock(privconn); return ninterfaces; } @@ -3693,7 +3694,7 @@ testConnectListDefinedInterfaces(virConnectPtr conn, int nnames; =20 testDriverLock(privconn); - nnames =3D virInterfaceObjGetNames(&privconn->ifaces, false, names, ma= xnames); + nnames =3D virInterfaceObjGetNames(privconn->ifaces, false, names, max= names); testDriverUnlock(privconn); =20 return nnames; @@ -3731,7 +3732,7 @@ testInterfaceLookupByMACString(virConnectPtr conn, virInterfacePtr ret =3D NULL; =20 testDriverLock(privconn); - ifacect =3D virInterfaceObjFindByMACString(&privconn->ifaces, mac, &ob= j, 1); + ifacect =3D virInterfaceObjFindByMACString(privconn->ifaces, mac, &obj= , 1); testDriverUnlock(privconn); =20 if (ifacect =3D=3D 0) { @@ -3789,8 +3790,7 @@ testInterfaceChangeBegin(virConnectPtr conn, =20 privconn->transaction_running =3D true; =20 - if (virInterfaceObjListClone(&privconn->ifaces, - &privconn->backupIfaces) < 0) + if (!(privconn->backupIfaces =3D virInterfaceObjListClone(privconn->if= aces))) goto cleanup; =20 ret =3D 0; @@ -3818,7 +3818,7 @@ testInterfaceChangeCommit(virConnectPtr conn, goto cleanup; } =20 - virInterfaceObjListFree(&privconn->backupIfaces); + virInterfaceObjListFree(privconn->backupIfaces); privconn->transaction_running =3D false; =20 ret =3D 0; @@ -3848,11 +3848,9 @@ testInterfaceChangeRollback(virConnectPtr conn, goto cleanup; } =20 - virInterfaceObjListFree(&privconn->ifaces); - privconn->ifaces.count =3D privconn->backupIfaces.count; - privconn->ifaces.objs =3D privconn->backupIfaces.objs; - privconn->backupIfaces.count =3D 0; - privconn->backupIfaces.objs =3D NULL; + virInterfaceObjListFree(privconn->ifaces); + privconn->ifaces =3D privconn->backupIfaces; + privconn->backupIfaces =3D NULL; =20 privconn->transaction_running =3D false; =20 @@ -3903,7 +3901,7 @@ testInterfaceDefineXML(virConnectPtr conn, if (!(def =3D virInterfaceDefParseString(xmlStr))) goto cleanup; =20 - if ((obj =3D virInterfaceObjAssignDef(&privconn->ifaces, def)) =3D=3D = NULL) + if ((obj =3D virInterfaceObjAssignDef(privconn->ifaces, def)) =3D=3D N= ULL) goto cleanup; def =3D NULL; objdef =3D virInterfaceObjGetDef(obj); @@ -3928,7 +3926,7 @@ testInterfaceUndefine(virInterfacePtr iface) if (!(obj =3D testInterfaceObjFindByName(privconn, iface->name))) return -1; =20 - virInterfaceObjRemove(&privconn->ifaces, obj); + virInterfaceObjRemove(privconn->ifaces, obj); =20 return 0; } --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 08:11:07 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 1493159846685288.8500222696317; Tue, 25 Apr 2017 15:37:26 -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 0EC4B3DBCE; Tue, 25 Apr 2017 22:37:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9829217CCA; Tue, 25 Apr 2017 22:37:24 +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 4538A4E9BE; Tue, 25 Apr 2017 22:37:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PMb5PO029214 for ; Tue, 25 Apr 2017 18:37:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8D5021811C; Tue, 25 Apr 2017 22:37:05 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 46F9D1811B for ; Tue, 25 Apr 2017 22:37:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0EC4B3DBCE 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 0EC4B3DBCE From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 18:36:54 -0400 Message-Id: <20170425223656.20740-7-jferlan@redhat.com> In-Reply-To: <20170425223656.20740-1-jferlan@redhat.com> References: <20170425223656.20740-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 6/8] interface: Rename some virInterfaceObj* 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 25 Apr 2017 22:37:25 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Prefix should have been virInterfaceObjList since the API is operating on the list of interfaces. Signed-off-by: John Ferlan --- src/conf/virinterfaceobj.c | 37 +++++++++++++++++++------------------ src/conf/virinterfaceobj.h | 31 ++++++++++++++++--------------- src/libvirt_private.syms | 12 ++++++------ src/test/test_driver.c | 20 +++++++++++--------- 4 files changed, 52 insertions(+), 48 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index 301ad94..3aeeebd 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -106,9 +106,10 @@ virInterfaceObjListNew(void) =20 =20 int -virInterfaceObjFindByMACString(virInterfaceObjListPtr interfaces, - const char *mac, - virInterfaceObjPtr *matches, int maxmatches) +virInterfaceObjListFindByMACString(virInterfaceObjListPtr interfaces, + const char *mac, + virInterfaceObjPtr *matches, + int maxmatches) { size_t i; unsigned int matchct =3D 0; @@ -136,8 +137,8 @@ virInterfaceObjFindByMACString(virInterfaceObjListPtr i= nterfaces, =20 =20 virInterfaceObjPtr -virInterfaceObjFindByName(virInterfaceObjListPtr interfaces, - const char *name) +virInterfaceObjListFindByName(virInterfaceObjListPtr interfaces, + const char *name) { size_t i; =20 @@ -196,9 +197,9 @@ virInterfaceObjListClone(virInterfaceObjListPtr interfa= ces) } =20 VIR_FREE(xml); - if (!(obj =3D virInterfaceObjAssignDef(dest, backup))) + if (!(obj =3D virInterfaceObjListAssignDef(dest, backup))) goto error; - virInterfaceObjUnlock(obj); /* locked by virInterfaceObjAssignDef = */ + virInterfaceObjUnlock(obj); /* locked by virInterfaceObjListAssign= Def */ } =20 return dest; @@ -210,12 +211,12 @@ virInterfaceObjListClone(virInterfaceObjListPtr inter= faces) =20 =20 virInterfaceObjPtr -virInterfaceObjAssignDef(virInterfaceObjListPtr interfaces, - virInterfaceDefPtr def) +virInterfaceObjListAssignDef(virInterfaceObjListPtr interfaces, + virInterfaceDefPtr def) { virInterfaceObjPtr obj; =20 - if ((obj =3D virInterfaceObjFindByName(interfaces, def->name))) { + if ((obj =3D virInterfaceObjListFindByName(interfaces, def->name))) { virInterfaceDefFree(obj->def); obj->def =3D def; =20 @@ -245,8 +246,8 @@ virInterfaceObjAssignDef(virInterfaceObjListPtr interfa= ces, =20 =20 void -virInterfaceObjRemove(virInterfaceObjListPtr interfaces, - virInterfaceObjPtr obj) +virInterfaceObjListRemove(virInterfaceObjListPtr interfaces, + virInterfaceObjPtr obj) { size_t i; =20 @@ -266,8 +267,8 @@ virInterfaceObjRemove(virInterfaceObjListPtr interfaces, =20 =20 int -virInterfaceObjNumOfInterfaces(virInterfaceObjListPtr interfaces, - bool wantActive) +virInterfaceObjListNumOfInterfaces(virInterfaceObjListPtr interfaces, + bool wantActive) { size_t i; int ninterfaces =3D 0; @@ -285,10 +286,10 @@ virInterfaceObjNumOfInterfaces(virInterfaceObjListPtr= interfaces, =20 =20 int -virInterfaceObjGetNames(virInterfaceObjListPtr interfaces, - bool wantActive, - char **const names, - int maxnames) +virInterfaceObjListGetNames(virInterfaceObjListPtr interfaces, + bool wantActive, + char **const names, + int maxnames) { int nnames =3D 0; size_t i; diff --git a/src/conf/virinterfaceobj.h b/src/conf/virinterfaceobj.h index 19c4947..f1bcab9 100644 --- a/src/conf/virinterfaceobj.h +++ b/src/conf/virinterfaceobj.h @@ -42,13 +42,14 @@ virInterfaceObjListPtr virInterfaceObjListNew(void); =20 int -virInterfaceObjFindByMACString(virInterfaceObjListPtr interfaces, - const char *mac, - virInterfaceObjPtr *matches, int maxmatches= ); +virInterfaceObjListFindByMACString(virInterfaceObjListPtr interfaces, + const char *mac, + virInterfaceObjPtr *matches, + int maxmatches); =20 virInterfaceObjPtr -virInterfaceObjFindByName(virInterfaceObjListPtr interfaces, - const char *name); +virInterfaceObjListFindByName(virInterfaceObjListPtr interfaces, + const char *name); =20 void virInterfaceObjFree(virInterfaceObjPtr obj); @@ -60,12 +61,12 @@ virInterfaceObjListPtr virInterfaceObjListClone(virInterfaceObjListPtr interfaces); =20 virInterfaceObjPtr -virInterfaceObjAssignDef(virInterfaceObjListPtr interfaces, - virInterfaceDefPtr def); +virInterfaceObjListAssignDef(virInterfaceObjListPtr interfaces, + virInterfaceDefPtr def); =20 void -virInterfaceObjRemove(virInterfaceObjListPtr interfaces, - virInterfaceObjPtr obj); +virInterfaceObjListRemove(virInterfaceObjListPtr interfaces, + virInterfaceObjPtr obj); =20 void virInterfaceObjLock(virInterfaceObjPtr obj); @@ -78,13 +79,13 @@ typedef bool virInterfaceDefPtr def); =20 int -virInterfaceObjNumOfInterfaces(virInterfaceObjListPtr interfaces, - bool wantActive); +virInterfaceObjListNumOfInterfaces(virInterfaceObjListPtr interfaces, + bool wantActive); =20 int -virInterfaceObjGetNames(virInterfaceObjListPtr interfaces, - bool wantActive, - char **const names, - int maxnames); +virInterfaceObjListGetNames(virInterfaceObjListPtr interfaces, + bool wantActive, + char **const names, + int maxnames); =20 #endif /* __VIRINTERFACEOBJ_H__ */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 751d1ac..4feb081 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -906,17 +906,17 @@ virDomainObjListRename; =20 =20 # conf/virinterfaceobj.h -virInterfaceObjAssignDef; -virInterfaceObjFindByMACString; -virInterfaceObjFindByName; virInterfaceObjGetDef; -virInterfaceObjGetNames; virInterfaceObjIsActive; +virInterfaceObjListAssignDef; virInterfaceObjListClone; +virInterfaceObjListFindByMACString; +virInterfaceObjListFindByName; virInterfaceObjListFree; +virInterfaceObjListGetNames; +virInterfaceObjListNumOfInterfaces; +virInterfaceObjListRemove; virInterfaceObjLock; -virInterfaceObjNumOfInterfaces; -virInterfaceObjRemove; virInterfaceObjSetActive; virInterfaceObjUnlock; =20 diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 2cd55ec..89a705c 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1021,7 +1021,7 @@ testParseInterfaces(testDriverPtr privconn, if (!def) goto error; =20 - if (!(obj =3D virInterfaceObjAssignDef(privconn->ifaces, def))) { + if (!(obj =3D virInterfaceObjListAssignDef(privconn->ifaces, def))= ) { virInterfaceDefFree(def); goto error; } @@ -3631,7 +3631,7 @@ testInterfaceObjFindByName(testDriverPtr privconn, virInterfaceObjPtr obj; =20 testDriverLock(privconn); - obj =3D virInterfaceObjFindByName(privconn->ifaces, name); + obj =3D virInterfaceObjListFindByName(privconn->ifaces, name); testDriverUnlock(privconn); =20 if (!obj) @@ -3650,7 +3650,7 @@ testConnectNumOfInterfaces(virConnectPtr conn) int ninterfaces; =20 testDriverLock(privconn); - ninterfaces =3D virInterfaceObjNumOfInterfaces(privconn->ifaces, true); + ninterfaces =3D virInterfaceObjListNumOfInterfaces(privconn->ifaces, t= rue); testDriverUnlock(privconn); return ninterfaces; } @@ -3665,7 +3665,8 @@ testConnectListInterfaces(virConnectPtr conn, int nnames; =20 testDriverLock(privconn); - nnames =3D virInterfaceObjGetNames(privconn->ifaces, true, names, maxn= ames); + nnames =3D virInterfaceObjListGetNames(privconn->ifaces, true, + names, maxnames); testDriverUnlock(privconn); =20 return nnames; @@ -3679,7 +3680,7 @@ testConnectNumOfDefinedInterfaces(virConnectPtr conn) int ninterfaces; =20 testDriverLock(privconn); - ninterfaces =3D virInterfaceObjNumOfInterfaces(privconn->ifaces, false= ); + ninterfaces =3D virInterfaceObjListNumOfInterfaces(privconn->ifaces, f= alse); testDriverUnlock(privconn); return ninterfaces; } @@ -3694,7 +3695,8 @@ testConnectListDefinedInterfaces(virConnectPtr conn, int nnames; =20 testDriverLock(privconn); - nnames =3D virInterfaceObjGetNames(privconn->ifaces, false, names, max= names); + nnames =3D virInterfaceObjListGetNames(privconn->ifaces, false, + names, maxnames); testDriverUnlock(privconn); =20 return nnames; @@ -3732,7 +3734,7 @@ testInterfaceLookupByMACString(virConnectPtr conn, virInterfacePtr ret =3D NULL; =20 testDriverLock(privconn); - ifacect =3D virInterfaceObjFindByMACString(privconn->ifaces, mac, &obj= , 1); + ifacect =3D virInterfaceObjListFindByMACString(privconn->ifaces, mac, = &obj, 1); testDriverUnlock(privconn); =20 if (ifacect =3D=3D 0) { @@ -3901,7 +3903,7 @@ testInterfaceDefineXML(virConnectPtr conn, if (!(def =3D virInterfaceDefParseString(xmlStr))) goto cleanup; =20 - if ((obj =3D virInterfaceObjAssignDef(privconn->ifaces, def)) =3D=3D N= ULL) + if ((obj =3D virInterfaceObjListAssignDef(privconn->ifaces, def)) =3D= =3D NULL) goto cleanup; def =3D NULL; objdef =3D virInterfaceObjGetDef(obj); @@ -3926,7 +3928,7 @@ testInterfaceUndefine(virInterfacePtr iface) if (!(obj =3D testInterfaceObjFindByName(privconn, iface->name))) return -1; =20 - virInterfaceObjRemove(privconn->ifaces, obj); + virInterfaceObjListRemove(privconn->ifaces, obj); =20 return 0; } --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 08:11:07 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 1493159856287180.26930794837165; Tue, 25 Apr 2017 15:37:36 -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 9B976C05AD70; Tue, 25 Apr 2017 22:37:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 73D215C474; Tue, 25 Apr 2017 22:37:34 +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 CFF0E5EC62; Tue, 25 Apr 2017 22:37:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PMb6ho029219 for ; Tue, 25 Apr 2017 18:37:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2BA351811B; Tue, 25 Apr 2017 22:37:06 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD8B960E3E for ; Tue, 25 Apr 2017 22:37:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9B976C05AD70 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 9B976C05AD70 From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 18:36:55 -0400 Message-Id: <20170425223656.20740-8-jferlan@redhat.com> In-Reply-To: <20170425223656.20740-1-jferlan@redhat.com> References: <20170425223656.20740-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 7/8] interface: Clean up virInterfaceObjListFindByMACString 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.32]); Tue, 25 Apr 2017 22:37:35 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Alter the algorithm to return a list of matching names rather than a list of match virInterfaceObjPtr which are then just dereferenced extracting the def->name and def->mac. Since the def->mac would be the same as the passed @mac, just return a list of names and as long as there's only one, extract the [0] entry from the passed list. Also alter the error message on failure to include the mac that wasn't found. Signed-off-by: John Ferlan --- src/conf/virinterfaceobj.c | 23 ++++++++++++++--------- src/conf/virinterfaceobj.h | 2 +- src/test/test_driver.c | 16 ++++++++-------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index 3aeeebd..1cc5c92 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -108,11 +108,11 @@ virInterfaceObjListNew(void) int virInterfaceObjListFindByMACString(virInterfaceObjListPtr interfaces, const char *mac, - virInterfaceObjPtr *matches, + char **const matches, int maxmatches) { size_t i; - unsigned int matchct =3D 0; + int matchct =3D 0; =20 for (i =3D 0; i < interfaces->count; i++) { virInterfaceObjPtr obj =3D interfaces->objs[i]; @@ -121,18 +121,23 @@ virInterfaceObjListFindByMACString(virInterfaceObjLis= tPtr interfaces, virInterfaceObjLock(obj); def =3D obj->def; if (STRCASEEQ(def->mac, mac)) { - matchct++; - if (matchct <=3D maxmatches) { - matches[matchct - 1] =3D obj; - /* keep the lock if we're returning object to caller */ - /* it is the caller's responsibility to unlock *all* match= es */ - continue; + if (matchct < maxmatches) { + if (VIR_STRDUP(matches[matchct], def->name) < 0) { + virInterfaceObjUnlock(obj); + goto error; + } + matchct++; } } virInterfaceObjUnlock(obj); - } return matchct; + + error: + while (--matchct >=3D 0) + VIR_FREE(matches[matchct]); + + return -1; } =20 =20 diff --git a/src/conf/virinterfaceobj.h b/src/conf/virinterfaceobj.h index f1bcab9..3934e63 100644 --- a/src/conf/virinterfaceobj.h +++ b/src/conf/virinterfaceobj.h @@ -44,7 +44,7 @@ virInterfaceObjListNew(void); int virInterfaceObjListFindByMACString(virInterfaceObjListPtr interfaces, const char *mac, - virInterfaceObjPtr *matches, + char **const matches, int maxmatches); =20 virInterfaceObjPtr diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 89a705c..ac16f4f 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -3728,17 +3728,18 @@ testInterfaceLookupByMACString(virConnectPtr conn, const char *mac) { testDriverPtr privconn =3D conn->privateData; - virInterfaceObjPtr obj; - virInterfaceDefPtr def; int ifacect; + char *ifacenames[] =3D { NULL, NULL }; virInterfacePtr ret =3D NULL; =20 testDriverLock(privconn); - ifacect =3D virInterfaceObjListFindByMACString(privconn->ifaces, mac, = &obj, 1); + ifacect =3D virInterfaceObjListFindByMACString(privconn->ifaces, mac, + ifacenames, 2); testDriverUnlock(privconn); =20 if (ifacect =3D=3D 0) { - virReportError(VIR_ERR_NO_INTERFACE, NULL); + virReportError(VIR_ERR_NO_INTERFACE, + _("no interface with matching mac '%s'"), mac); goto cleanup; } =20 @@ -3747,12 +3748,11 @@ testInterfaceLookupByMACString(virConnectPtr conn, goto cleanup; } =20 - def =3D virInterfaceObjGetDef(obj); - ret =3D virGetInterface(conn, def->name, def->mac); + ret =3D virGetInterface(conn, ifacenames[0], mac); =20 cleanup: - if (obj) - virInterfaceObjUnlock(obj); + VIR_FREE(ifacenames[0]); + VIR_FREE(ifacenames[1]); return ret; } =20 --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 08:11:07 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 1493159850810805.2376914774601; Tue, 25 Apr 2017 15:37:30 -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 1B24BC056800; Tue, 25 Apr 2017 22:37:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E689619175; Tue, 25 Apr 2017 22:37:28 +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 91F94410B1; Tue, 25 Apr 2017 22:37:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PMb68G029229 for ; Tue, 25 Apr 2017 18:37:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9707D1811B; Tue, 25 Apr 2017 22:37:06 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5563960E3E for ; Tue, 25 Apr 2017 22:37:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1B24BC056800 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 1B24BC056800 From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 18:36:56 -0400 Message-Id: <20170425223656.20740-9-jferlan@redhat.com> In-Reply-To: <20170425223656.20740-1-jferlan@redhat.com> References: <20170425223656.20740-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 8/8] interface: Introduce virInterfaceObjNew 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.32]); Tue, 25 Apr 2017 22:37:29 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Create/use a helper to perform the object allocation Signed-off-by: John Ferlan --- src/conf/virinterfaceobj.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index 1cc5c92..4463653 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -46,6 +46,27 @@ struct _virInterfaceObjList { =20 /* virInterfaceObj manipulation */ =20 +static virInterfaceObjPtr +virInterfaceObjNew(void) +{ + virInterfaceObjPtr obj; + + if (VIR_ALLOC(obj) < 0) + return NULL; + + if (virMutexInit(&obj->lock) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("cannot initialize mutex")); + VIR_FREE(obj); + return NULL; + } + + virInterfaceObjLock(obj); + + return obj; +} + + void virInterfaceObjLock(virInterfaceObjPtr obj) { @@ -228,18 +249,12 @@ virInterfaceObjListAssignDef(virInterfaceObjListPtr i= nterfaces, return obj; } =20 - if (VIR_ALLOC(obj) < 0) - return NULL; - if (virMutexInit(&obj->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot initialize mutex")); - VIR_FREE(obj); + if (!(obj =3D virInterfaceObjNew())) return NULL; - } - virInterfaceObjLock(obj); =20 if (VIR_APPEND_ELEMENT_COPY(interfaces->objs, interfaces->count, obj) < 0) { + virInterfaceObjUnlock(obj); virInterfaceObjFree(obj); return NULL; } --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 08:11:07 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 1495381048278586.2204551106299; Sun, 21 May 2017 08:37:28 -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 6170780C1D; Sun, 21 May 2017 15:37:26 +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 2BE4818967; Sun, 21 May 2017 15:37:26 +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 9A6281800C8D; Sun, 21 May 2017 15:37:25 +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 v4LFamF8031322 for ; Sun, 21 May 2017 11:36:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0C024179DA; Sun, 21 May 2017 15:36:48 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-18.phx2.redhat.com [10.3.116.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id C05FF5DC1D for ; Sun, 21 May 2017 15:36:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6170780C1D 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 6170780C1D From: John Ferlan To: libvir-list@redhat.com Date: Sun, 21 May 2017 11:36:45 -0400 Message-Id: <20170521153645.32172-1-jferlan@redhat.com> In-Reply-To: <20170425223656.20740-1-jferlan@redhat.com> References: <20170425223656.20740-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/08] interface: Introduce virInterfaceObjEndAPI 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.26]); Sun, 21 May 2017 15:37:27 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" For now it'll just call the virInterfaceObjUnlock, but a future adjustment will do something different. The virInterfaceObjUnlock is now private to virinterfaceobj.c with a short term forward reference. Additionally, make virInterfaceObjLock private since it's only used in virinterfaceobj anyway. For now this will involved creating a forward reference, but this will go away soon too. Signed-off-by: John Ferlan --- src/conf/virinterfaceobj.c | 17 +++++++++++++++-- src/conf/virinterfaceobj.h | 9 +++------ src/libvirt_private.syms | 3 +-- src/test/test_driver.c | 15 +++++++-------- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index 1e3f25c..8f839b3 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -44,6 +44,9 @@ struct _virInterfaceObjList { virInterfaceObjPtr *objs; }; =20 +static void +virInterfaceObjLock(virInterfaceObjPtr obj); + /* virInterfaceObj manipulation */ =20 static virInterfaceObjPtr @@ -67,14 +70,14 @@ virInterfaceObjNew(void) } =20 =20 -void +static void virInterfaceObjLock(virInterfaceObjPtr obj) { virMutexLock(&obj->lock); } =20 =20 -void +static void virInterfaceObjUnlock(virInterfaceObjPtr obj) { virMutexUnlock(&obj->lock); @@ -82,6 +85,16 @@ virInterfaceObjUnlock(virInterfaceObjPtr obj) =20 =20 void +virInterfaceObjEndAPI(virInterfaceObjPtr *obj) +{ + if (!*obj) + return; + + virInterfaceObjUnlock(*obj); +} + + +void virInterfaceObjFree(virInterfaceObjPtr obj) { if (!obj) diff --git a/src/conf/virinterfaceobj.h b/src/conf/virinterfaceobj.h index 3934e63..2b9e1b2 100644 --- a/src/conf/virinterfaceobj.h +++ b/src/conf/virinterfaceobj.h @@ -28,6 +28,9 @@ typedef virInterfaceObj *virInterfaceObjPtr; typedef struct _virInterfaceObjList virInterfaceObjList; typedef virInterfaceObjList *virInterfaceObjListPtr; =20 +void +virInterfaceObjEndAPI(virInterfaceObjPtr *obj); + virInterfaceDefPtr virInterfaceObjGetDef(virInterfaceObjPtr obj); =20 @@ -68,12 +71,6 @@ void virInterfaceObjListRemove(virInterfaceObjListPtr interfaces, virInterfaceObjPtr obj); =20 -void -virInterfaceObjLock(virInterfaceObjPtr obj); - -void -virInterfaceObjUnlock(virInterfaceObjPtr obj); - typedef bool (*virInterfaceObjListFilter)(virConnectPtr conn, virInterfaceDefPtr def); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index aa6f351..364b32e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -910,6 +910,7 @@ virDomainObjListRename; =20 =20 # conf/virinterfaceobj.h +virInterfaceObjEndAPI; virInterfaceObjGetDef; virInterfaceObjIsActive; virInterfaceObjListAssignDef; @@ -921,9 +922,7 @@ virInterfaceObjListGetNames; virInterfaceObjListNew; virInterfaceObjListNumOfInterfaces; virInterfaceObjListRemove; -virInterfaceObjLock; virInterfaceObjSetActive; -virInterfaceObjUnlock; =20 =20 # conf/virnetworkobj.h diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ac16f4f..fb95319 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1027,7 +1027,7 @@ testParseInterfaces(testDriverPtr privconn, } =20 virInterfaceObjSetActive(obj, true); - virInterfaceObjUnlock(obj); + virInterfaceObjEndAPI(&obj); } =20 ret =3D 0; @@ -3718,7 +3718,7 @@ testInterfaceLookupByName(virConnectPtr conn, =20 ret =3D virGetInterface(conn, def->name, def->mac); =20 - virInterfaceObjUnlock(obj); + virInterfaceObjEndAPI(&obj); return ret; } =20 @@ -3769,7 +3769,7 @@ testInterfaceIsActive(virInterfacePtr iface) =20 ret =3D virInterfaceObjIsActive(obj); =20 - virInterfaceObjUnlock(obj); + virInterfaceObjEndAPI(&obj); return ret; } =20 @@ -3881,7 +3881,7 @@ testInterfaceGetXMLDesc(virInterfacePtr iface, =20 ret =3D virInterfaceDefFormat(def); =20 - virInterfaceObjUnlock(obj); + virInterfaceObjEndAPI(&obj); return ret; } =20 @@ -3912,8 +3912,7 @@ testInterfaceDefineXML(virConnectPtr conn, =20 cleanup: virInterfaceDefFree(def); - if (obj) - virInterfaceObjUnlock(obj); + virInterfaceObjEndAPI(&obj); testDriverUnlock(privconn); return ret; } @@ -3956,7 +3955,7 @@ testInterfaceCreate(virInterfacePtr iface, ret =3D 0; =20 cleanup: - virInterfaceObjUnlock(obj); + virInterfaceObjEndAPI(&obj); return ret; } =20 @@ -3983,7 +3982,7 @@ testInterfaceDestroy(virInterfacePtr iface, ret =3D 0; =20 cleanup: - virInterfaceObjUnlock(obj); + virInterfaceObjEndAPI(&obj); return ret; } =20 --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 08:11:07 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 1495381081103509.2480189612945; Sun, 21 May 2017 08:38:01 -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 61B7D448D6B; Sun, 21 May 2017 15:37: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 346405C6E7; Sun, 21 May 2017 15:37: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 E3A87180BAF2; Sun, 21 May 2017 15:37:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4LFaxew031358 for ; Sun, 21 May 2017 11:36:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9519018408; Sun, 21 May 2017 15:36:59 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-18.phx2.redhat.com [10.3.116.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 547DA77C83 for ; Sun, 21 May 2017 15:36:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 61B7D448D6B 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 61B7D448D6B From: John Ferlan To: libvir-list@redhat.com Date: Sun, 21 May 2017 11:36:56 -0400 Message-Id: <20170521153656.32224-1-jferlan@redhat.com> In-Reply-To: <20170425223656.20740-1-jferlan@redhat.com> References: <20170425223656.20740-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/08] interface: Convert virInterfaceObj to use virObjectLockable 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]); Sun, 21 May 2017 15:38:00 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Now that we have a bit more control, let's convert our object into a lockable object and let that magic handle the create and lock/unlock. Signed-off-by: John Ferlan --- po/POTFILES.in | 1 - src/conf/virinterfaceobj.c | 110 ++++++++++++++++++++++-------------------= ---- 2 files changed, 53 insertions(+), 58 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 5077857..4aac3bc 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -44,7 +44,6 @@ src/conf/storage_adapter_conf.c src/conf/storage_conf.c src/conf/virchrdev.c src/conf/virdomainobjlist.c -src/conf/virinterfaceobj.c src/conf/virnetworkobj.c src/conf/virnodedeviceobj.c src/conf/virnwfilterobj.c diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index 8f839b3..51c3c82 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -33,7 +33,7 @@ VIR_LOG_INIT("conf.virinterfaceobj"); =20 struct _virInterfaceObj { - virMutex lock; + virObjectLockable parent; =20 bool active; /* true if interface is active (up) */ virInterfaceDefPtr def; /* The interface definition */ @@ -44,65 +44,62 @@ struct _virInterfaceObjList { virInterfaceObjPtr *objs; }; =20 -static void -virInterfaceObjLock(virInterfaceObjPtr obj); - /* virInterfaceObj manipulation */ =20 -static virInterfaceObjPtr -virInterfaceObjNew(void) -{ - virInterfaceObjPtr obj; +static virClassPtr virInterfaceObjClass; +static void virInterfaceObjDispose(void *obj); =20 - if (VIR_ALLOC(obj) < 0) - return NULL; +static int +virInterfaceObjOnceInit(void) +{ + if (!(virInterfaceObjClass =3D virClassNew(virClassForObjectLockable(), + "virInterfaceObj", + sizeof(virInterfaceObj), + virInterfaceObjDispose))) + return -1; =20 - if (virMutexInit(&obj->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot initialize mutex")); - VIR_FREE(obj); - return NULL; - } + return 0; +} =20 - virInterfaceObjLock(obj); =20 - return obj; -} +VIR_ONCE_GLOBAL_INIT(virInterfaceObj) =20 =20 static void -virInterfaceObjLock(virInterfaceObjPtr obj) +virInterfaceObjDispose(void *opaque) { - virMutexLock(&obj->lock); + virInterfaceObjPtr obj =3D opaque; + + virInterfaceDefFree(obj->def); } =20 =20 -static void -virInterfaceObjUnlock(virInterfaceObjPtr obj) +static virInterfaceObjPtr +virInterfaceObjNew(void) { - virMutexUnlock(&obj->lock); -} + virInterfaceObjPtr obj; =20 + if (virInterfaceObjInitialize() < 0) + return NULL; =20 -void -virInterfaceObjEndAPI(virInterfaceObjPtr *obj) -{ - if (!*obj) - return; + if (!(obj =3D virObjectLockableNew(virInterfaceObjClass))) + return NULL; =20 - virInterfaceObjUnlock(*obj); + virObjectLock(obj); + + return obj; } =20 =20 void -virInterfaceObjFree(virInterfaceObjPtr obj) +virInterfaceObjEndAPI(virInterfaceObjPtr *obj) { - if (!obj) + if (!*obj) return; =20 - virInterfaceDefFree(obj->def); - virMutexDestroy(&obj->lock); - VIR_FREE(obj); + virObjectUnlock(*obj); + virObjectUnref(*obj); + *obj =3D NULL; } =20 =20 @@ -153,18 +150,18 @@ virInterfaceObjListFindByMACString(virInterfaceObjLis= tPtr interfaces, virInterfaceObjPtr obj =3D interfaces->objs[i]; virInterfaceDefPtr def; =20 - virInterfaceObjLock(obj); + virObjectLock(obj); def =3D obj->def; if (STRCASEEQ(def->mac, mac)) { if (matchct < maxmatches) { if (VIR_STRDUP(matches[matchct], def->name) < 0) { - virInterfaceObjUnlock(obj); + virObjectUnlock(obj); goto error; } matchct++; } } - virInterfaceObjUnlock(obj); + virObjectUnlock(obj); } return matchct; =20 @@ -186,11 +183,11 @@ virInterfaceObjListFindByName(virInterfaceObjListPtr = interfaces, virInterfaceObjPtr obj =3D interfaces->objs[i]; virInterfaceDefPtr def; =20 - virInterfaceObjLock(obj); + virObjectLock(obj); def =3D obj->def; if (STREQ(def->name, name)) - return obj; - virInterfaceObjUnlock(obj); + return virObjectRef(obj); + virObjectUnlock(obj); } =20 return NULL; @@ -203,7 +200,7 @@ virInterfaceObjListFree(virInterfaceObjListPtr interfac= es) size_t i; =20 for (i =3D 0; i < interfaces->count; i++) - virInterfaceObjFree(interfaces->objs[i]); + virObjectUnref(interfaces->objs[i]); VIR_FREE(interfaces->objs); VIR_FREE(interfaces); } @@ -240,7 +237,7 @@ virInterfaceObjListClone(virInterfaceObjListPtr interfa= ces) VIR_FREE(xml); if (!(obj =3D virInterfaceObjListAssignDef(dest, backup))) goto error; - virInterfaceObjUnlock(obj); /* locked by virInterfaceObjListAssign= Def */ + virInterfaceObjEndAPI(&obj); } =20 return dest; @@ -269,13 +266,12 @@ virInterfaceObjListAssignDef(virInterfaceObjListPtr i= nterfaces, =20 if (VIR_APPEND_ELEMENT_COPY(interfaces->objs, interfaces->count, obj) < 0) { - virInterfaceObjUnlock(obj); - virInterfaceObjFree(obj); + virInterfaceObjEndAPI(&obj); return NULL; } =20 obj->def =3D def; - return obj; + return virObjectRef(obj); =20 } =20 @@ -286,17 +282,17 @@ virInterfaceObjListRemove(virInterfaceObjListPtr inte= rfaces, { size_t i; =20 - virInterfaceObjUnlock(obj); + virObjectUnlock(obj); for (i =3D 0; i < interfaces->count; i++) { - virInterfaceObjLock(interfaces->objs[i]); + virObjectLock(interfaces->objs[i]); if (interfaces->objs[i] =3D=3D obj) { - virInterfaceObjUnlock(interfaces->objs[i]); - virInterfaceObjFree(interfaces->objs[i]); + virObjectUnlock(interfaces->objs[i]); + virObjectUnref(interfaces->objs[i]); =20 VIR_DELETE_ELEMENT(interfaces->objs, i, interfaces->count); break; } - virInterfaceObjUnlock(interfaces->objs[i]); + virObjectUnlock(interfaces->objs[i]); } } =20 @@ -310,10 +306,10 @@ virInterfaceObjListNumOfInterfaces(virInterfaceObjLis= tPtr interfaces, =20 for (i =3D 0; (i < interfaces->count); i++) { virInterfaceObjPtr obj =3D interfaces->objs[i]; - virInterfaceObjLock(obj); + virObjectLock(obj); if (wantActive =3D=3D virInterfaceObjIsActive(obj)) ninterfaces++; - virInterfaceObjUnlock(obj); + virObjectUnlock(obj); } =20 return ninterfaces; @@ -333,16 +329,16 @@ virInterfaceObjListGetNames(virInterfaceObjListPtr in= terfaces, virInterfaceObjPtr obj =3D interfaces->objs[i]; virInterfaceDefPtr def; =20 - virInterfaceObjLock(obj); + virObjectLock(obj); def =3D obj->def; if (wantActive =3D=3D virInterfaceObjIsActive(obj)) { if (VIR_STRDUP(names[nnames], def->name) < 0) { - virInterfaceObjUnlock(obj); + virObjectUnlock(obj); goto failure; } nnames++; } - virInterfaceObjUnlock(obj); + virObjectUnlock(obj); } =20 return nnames; --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 08:11:07 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 1495729154723216.40694875481267; Thu, 25 May 2017 09:19:14 -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 AB49875717; Thu, 25 May 2017 16:19:12 +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 20C0B77DC4; Thu, 25 May 2017 16:19:12 +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 077B24A48D; Thu, 25 May 2017 16:19:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4PGId15020708 for ; Thu, 25 May 2017 12:18:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 17CA57DFE9; Thu, 25 May 2017 16:18:39 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-108.phx2.redhat.com [10.3.116.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id CBBD87E589 for ; Thu, 25 May 2017 16:18:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AB49875717 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 AB49875717 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 25 May 2017 12:18:34 -0400 Message-Id: <20170525161834.17206-1-jferlan@redhat.com> In-Reply-To: <20170425223656.20740-1-jferlan@redhat.com> References: <20170425223656.20740-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/08] interface: Alter virInterfaceObjListAssignDef @def param 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.27]); Thu, 25 May 2017 16:19:13 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than pass by value, let's pass by reference since the object ends up "owning" the XML definition, let's make that ownership a bit more real. Signed-off-by: John Ferlan --- Since 09 and 10 weren't reviewed yet, I'll add one more. src/conf/virinterfaceobj.c | 12 +++++++----- src/conf/virinterfaceobj.h | 2 +- src/test/test_driver.c | 5 ++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index 51c3c82..f7352d2 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -235,8 +235,10 @@ virInterfaceObjListClone(virInterfaceObjListPtr interf= aces) } =20 VIR_FREE(xml); - if (!(obj =3D virInterfaceObjListAssignDef(dest, backup))) + if (!(obj =3D virInterfaceObjListAssignDef(dest, &backup))) { + virInterfaceDefFree(backup); goto error; + } virInterfaceObjEndAPI(&obj); } =20 @@ -250,13 +252,13 @@ virInterfaceObjListClone(virInterfaceObjListPtr inter= faces) =20 virInterfaceObjPtr virInterfaceObjListAssignDef(virInterfaceObjListPtr interfaces, - virInterfaceDefPtr def) + virInterfaceDefPtr *def) { virInterfaceObjPtr obj; =20 - if ((obj =3D virInterfaceObjListFindByName(interfaces, def->name))) { + if ((obj =3D virInterfaceObjListFindByName(interfaces, (*def)->name)))= { virInterfaceDefFree(obj->def); - obj->def =3D def; + VIR_STEAL_PTR(obj->def, *def); =20 return obj; } @@ -270,7 +272,7 @@ virInterfaceObjListAssignDef(virInterfaceObjListPtr int= erfaces, return NULL; } =20 - obj->def =3D def; + VIR_STEAL_PTR(obj->def, *def); return virObjectRef(obj); =20 } diff --git a/src/conf/virinterfaceobj.h b/src/conf/virinterfaceobj.h index 2b9e1b2..0000ee9 100644 --- a/src/conf/virinterfaceobj.h +++ b/src/conf/virinterfaceobj.h @@ -65,7 +65,7 @@ virInterfaceObjListClone(virInterfaceObjListPtr interface= s); =20 virInterfaceObjPtr virInterfaceObjListAssignDef(virInterfaceObjListPtr interfaces, - virInterfaceDefPtr def); + virInterfaceDefPtr *def); =20 void virInterfaceObjListRemove(virInterfaceObjListPtr interfaces, diff --git a/src/test/test_driver.c b/src/test/test_driver.c index fb95319..4b4a782 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1021,7 +1021,7 @@ testParseInterfaces(testDriverPtr privconn, if (!def) goto error; =20 - if (!(obj =3D virInterfaceObjListAssignDef(privconn->ifaces, def))= ) { + if (!(obj =3D virInterfaceObjListAssignDef(privconn->ifaces, &def)= )) { virInterfaceDefFree(def); goto error; } @@ -3903,9 +3903,8 @@ testInterfaceDefineXML(virConnectPtr conn, if (!(def =3D virInterfaceDefParseString(xmlStr))) goto cleanup; =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); =20 ret =3D virGetInterface(conn, objdef->name, objdef->mac); --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list