From nobody Sat May 4 15:28:44 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 1495799959533725.6632770577811; Fri, 26 May 2017 04:59:19 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BCCF0448D78; Fri, 26 May 2017 11:59:17 +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 3C4195C3FB; Fri, 26 May 2017 11:59:17 +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 6C65E4BB7F; Fri, 26 May 2017 11:59:15 +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 v4QBxEfJ008669 for ; Fri, 26 May 2017 07:59:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 07D0A7DFDE; Fri, 26 May 2017 11:59:14 +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 A80ED7DFFA for ; Fri, 26 May 2017 11:59:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BCCF0448D78 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 BCCF0448D78 From: John Ferlan To: libvir-list@redhat.com Date: Fri, 26 May 2017 07:59:00 -0400 Message-Id: <20170526115910.3977-2-jferlan@redhat.com> In-Reply-To: <20170526115910.3977-1-jferlan@redhat.com> References: <20170526115910.3977-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 01/11] 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 26 May 2017 11:59:18 +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.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:28:44 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 1495799971769802.7308380864386; Fri, 26 May 2017 04:59:31 -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 ED2D064D83; Fri, 26 May 2017 11:59:29 +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 C891F7FB7C; Fri, 26 May 2017 11:59:29 +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 70BCB4A491; Fri, 26 May 2017 11:59:29 +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 v4QBxEwU008674 for ; Fri, 26 May 2017 07:59:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6F5977E560; Fri, 26 May 2017 11:59:14 +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 2F0A17DFDE for ; Fri, 26 May 2017 11:59:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ED2D064D83 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.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 ED2D064D83 From: John Ferlan To: libvir-list@redhat.com Date: Fri, 26 May 2017 07:59:01 -0400 Message-Id: <20170526115910.3977-3-jferlan@redhat.com> In-Reply-To: <20170526115910.3977-1-jferlan@redhat.com> References: <20170526115910.3977-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 02/11] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 26 May 2017 11:59:30 +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.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:28:44 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 1495799960609972.9739494860842; Fri, 26 May 2017 04:59:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E28D6448D93; Fri, 26 May 2017 11:59:18 +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 B622A7DFE7; Fri, 26 May 2017 11:59:18 +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 3EA2B4A48C; Fri, 26 May 2017 11:59:18 +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 v4QBxFcS008682 for ; Fri, 26 May 2017 07:59:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 05BB17DFE7; Fri, 26 May 2017 11:59:15 +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 B14127DFDE for ; Fri, 26 May 2017 11:59:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E28D6448D93 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 E28D6448D93 From: John Ferlan To: libvir-list@redhat.com Date: Fri, 26 May 2017 07:59:02 -0400 Message-Id: <20170526115910.3977-4-jferlan@redhat.com> In-Reply-To: <20170526115910.3977-1-jferlan@redhat.com> References: <20170526115910.3977-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 03/11] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 26 May 2017 11:59:19 +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 | 32 +++++++++++++++++++++----------- src/test/test_driver.c | 12 +++++++++--- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index 62c3735..ead9512 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -72,18 +72,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 +100,14 @@ virInterfaceObjFindByName(virInterfaceObjListPtr inter= faces, 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 +141,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 +254,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.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:28:44 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 1495799971428353.13296003492076; Fri, 26 May 2017 04:59:31 -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 BA66019D39C; Fri, 26 May 2017 11:59: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 943417C76E; Fri, 26 May 2017 11:59:29 +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 45910180BAFB; Fri, 26 May 2017 11:59:29 +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 v4QBxF5b008687 for ; Fri, 26 May 2017 07:59:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6FE297DFE7; Fri, 26 May 2017 11:59:15 +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 2D35C7DFDE for ; Fri, 26 May 2017 11:59:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BA66019D39C 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 BA66019D39C From: John Ferlan To: libvir-list@redhat.com Date: Fri, 26 May 2017 07:59:03 -0400 Message-Id: <20170526115910.3977-5-jferlan@redhat.com> In-Reply-To: <20170526115910.3977-1-jferlan@redhat.com> References: <20170526115910.3977-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 04/11] 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 26 May 2017 11:59:30 +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 ead9512..a2ef7f4 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 */ @@ -62,6 +68,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 d361454..f9fe871 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -913,12 +913,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.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:28:44 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 1495799975747762.8635492027737; Fri, 26 May 2017 04:59:35 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EC4297F3FA; Fri, 26 May 2017 11:59:33 +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 993277E564; Fri, 26 May 2017 11:59:33 +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 45FB2180BAFD; Fri, 26 May 2017 11:59:33 +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 v4QBxGu1008697 for ; Fri, 26 May 2017 07:59:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 404777DFDE; Fri, 26 May 2017 11:59:16 +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 00CB47DFFB for ; Fri, 26 May 2017 11:59:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EC4297F3FA Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EC4297F3FA From: John Ferlan To: libvir-list@redhat.com Date: Fri, 26 May 2017 07:59:04 -0400 Message-Id: <20170526115910.3977-6-jferlan@redhat.com> In-Reply-To: <20170526115910.3977-1-jferlan@redhat.com> References: <20170526115910.3977-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 05/11] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 26 May 2017 11:59:34 +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 | 57 +++++++++++++++++++++++++++++-------------= ---- src/conf/virinterfaceobj.h | 12 ++++------ src/libvirt_private.syms | 1 + src/test/test_driver.c | 38 +++++++++++++++---------------- 4 files changed, 60 insertions(+), 48 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index a2ef7f4..dd86151 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 @@ -91,6 +95,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, @@ -149,50 +164,50 @@ 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/libvirt_private.syms b/src/libvirt_private.syms index f9fe871..4ba99ad 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -918,6 +918,7 @@ virInterfaceObjGetNames; virInterfaceObjIsActive; virInterfaceObjListClone; virInterfaceObjListFree; +virInterfaceObjListNew; virInterfaceObjLock; virInterfaceObjNumOfInterfaces; virInterfaceObjRemove; 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.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:28:44 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 1495799975578997.6694192229447; Fri, 26 May 2017 04:59:35 -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 1397D7F4A1; Fri, 26 May 2017 11:59:34 +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 D4E204DA66; Fri, 26 May 2017 11:59:33 +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 7F12F180BAFB; Fri, 26 May 2017 11:59:33 +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 v4QBxGG0008704 for ; Fri, 26 May 2017 07:59:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id A6E9D7DFEE; Fri, 26 May 2017 11:59:16 +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 67A787DFDE for ; Fri, 26 May 2017 11:59:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1397D7F4A1 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 1397D7F4A1 From: John Ferlan To: libvir-list@redhat.com Date: Fri, 26 May 2017 07:59:05 -0400 Message-Id: <20170526115910.3977-7-jferlan@redhat.com> In-Reply-To: <20170526115910.3977-1-jferlan@redhat.com> References: <20170526115910.3977-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 06/11] 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 26 May 2017 11:59:34 +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 dd86151..9470b4a 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -107,9 +107,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; @@ -137,8 +138,8 @@ virInterfaceObjFindByMACString(virInterfaceObjListPtr i= nterfaces, =20 =20 virInterfaceObjPtr -virInterfaceObjFindByName(virInterfaceObjListPtr interfaces, - const char *name) +virInterfaceObjListFindByName(virInterfaceObjListPtr interfaces, + const char *name) { size_t i; =20 @@ -198,9 +199,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; @@ -212,12 +213,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 @@ -247,8 +248,8 @@ virInterfaceObjAssignDef(virInterfaceObjListPtr interfa= ces, =20 =20 void -virInterfaceObjRemove(virInterfaceObjListPtr interfaces, - virInterfaceObjPtr obj) +virInterfaceObjListRemove(virInterfaceObjListPtr interfaces, + virInterfaceObjPtr obj) { size_t i; =20 @@ -268,8 +269,8 @@ virInterfaceObjRemove(virInterfaceObjListPtr interfaces, =20 =20 int -virInterfaceObjNumOfInterfaces(virInterfaceObjListPtr interfaces, - bool wantActive) +virInterfaceObjListNumOfInterfaces(virInterfaceObjListPtr interfaces, + bool wantActive) { size_t i; int ninterfaces =3D 0; @@ -287,10 +288,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 4ba99ad..aa6f351 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -910,18 +910,18 @@ virDomainObjListRename; =20 =20 # conf/virinterfaceobj.h -virInterfaceObjAssignDef; -virInterfaceObjFindByMACString; -virInterfaceObjFindByName; virInterfaceObjGetDef; -virInterfaceObjGetNames; virInterfaceObjIsActive; +virInterfaceObjListAssignDef; virInterfaceObjListClone; +virInterfaceObjListFindByMACString; +virInterfaceObjListFindByName; virInterfaceObjListFree; +virInterfaceObjListGetNames; virInterfaceObjListNew; +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.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:28:44 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 1495799979471642.4902136862042; Fri, 26 May 2017 04:59:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D88C0796EB; Fri, 26 May 2017 11:59:37 +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 7E13C7DFFD; Fri, 26 May 2017 11:59:37 +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 2B3C518325E4; Fri, 26 May 2017 11:59:37 +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 v4QBxHPQ008709 for ; Fri, 26 May 2017 07:59:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1C0407DFE7; Fri, 26 May 2017 11:59:17 +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 CFD367DFDE for ; Fri, 26 May 2017 11:59:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D88C0796EB Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D88C0796EB From: John Ferlan To: libvir-list@redhat.com Date: Fri, 26 May 2017 07:59:06 -0400 Message-Id: <20170526115910.3977-8-jferlan@redhat.com> In-Reply-To: <20170526115910.3977-1-jferlan@redhat.com> References: <20170526115910.3977-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 07/11] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 26 May 2017 11:59:38 +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 9470b4a..8bd8094 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -109,11 +109,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]; @@ -122,18 +122,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.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:28:44 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 1495799973155926.7774099420512; Fri, 26 May 2017 04:59:33 -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 148624E4E6; Fri, 26 May 2017 11:59:31 +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 DE3537C770; Fri, 26 May 2017 11:59:30 +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 7DF9D4A491; Fri, 26 May 2017 11:59:30 +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 v4QBxH7q008714 for ; Fri, 26 May 2017 07:59:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 824EE7DFE7; Fri, 26 May 2017 11:59:17 +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 439287DFFA for ; Fri, 26 May 2017 11:59:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 148624E4E6 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.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 148624E4E6 From: John Ferlan To: libvir-list@redhat.com Date: Fri, 26 May 2017 07:59:07 -0400 Message-Id: <20170526115910.3977-9-jferlan@redhat.com> In-Reply-To: <20170526115910.3977-1-jferlan@redhat.com> References: <20170526115910.3977-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 08/11] 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 26 May 2017 11:59:31 +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 8bd8094..1e3f25c 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) { @@ -230,18 +251,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.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:28:44 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 1495799985924664.7281779300537; Fri, 26 May 2017 04:59:45 -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 84A8636883; Fri, 26 May 2017 11:59:44 +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 437314D758; Fri, 26 May 2017 11:59:44 +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 D25CA18325E4; Fri, 26 May 2017 11:59:40 +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 v4QBxHTr008722 for ; Fri, 26 May 2017 07:59:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id E8E417DFE7; Fri, 26 May 2017 11:59:17 +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 A9E557DFDE for ; Fri, 26 May 2017 11:59:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 84A8636883 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 84A8636883 From: John Ferlan To: libvir-list@redhat.com Date: Fri, 26 May 2017 07:59:08 -0400 Message-Id: <20170526115910.3977-10-jferlan@redhat.com> In-Reply-To: <20170526115910.3977-1-jferlan@redhat.com> References: <20170526115910.3977-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 09/11] 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 26 May 2017 11:59:45 +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.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:28:44 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 14957999962128.294873731708776; Fri, 26 May 2017 04:59:56 -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 AC41D796F6; Fri, 26 May 2017 11:59:54 +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 884767C76E; Fri, 26 May 2017 11:59:54 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 68D46180BAFC; Fri, 26 May 2017 11:59:44 +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 v4QBxIjT008727 for ; Fri, 26 May 2017 07:59:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5B2C57DFE7; Fri, 26 May 2017 11:59:18 +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 1CB3B7DFDE for ; Fri, 26 May 2017 11:59:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AC41D796F6 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com AC41D796F6 From: John Ferlan To: libvir-list@redhat.com Date: Fri, 26 May 2017 07:59:09 -0400 Message-Id: <20170526115910.3977-11-jferlan@redhat.com> In-Reply-To: <20170526115910.3977-1-jferlan@redhat.com> References: <20170526115910.3977-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 10/11] 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 26 May 2017 11:59:55 +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.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 15:28:44 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 149579998014730.240078848485155; Fri, 26 May 2017 04:59:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 553C5A6E14; Fri, 26 May 2017 11:59:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 32A6A7DFDE; Fri, 26 May 2017 11:59:38 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D0B824A493; Fri, 26 May 2017 11:59:37 +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 v4QBxIsl008737 for ; Fri, 26 May 2017 07:59:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id C2DB17DFEE; Fri, 26 May 2017 11:59:18 +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 833CD7DFDE for ; Fri, 26 May 2017 11:59:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 553C5A6E14 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.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 553C5A6E14 From: John Ferlan To: libvir-list@redhat.com Date: Fri, 26 May 2017 07:59:10 -0400 Message-Id: <20170526115910.3977-12-jferlan@redhat.com> In-Reply-To: <20170526115910.3977-1-jferlan@redhat.com> References: <20170526115910.3977-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 11/11] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 26 May 2017 11:59:39 +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 --- 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