From nobody Mon Apr 29 19:12:58 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 149614103591091.90795644140769; Tue, 30 May 2017 03:43:55 -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 5AAA44E34C; Tue, 30 May 2017 10:43:53 +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 236CD5DC1F; Tue, 30 May 2017 10:43:52 +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 9CC894A48C; Tue, 30 May 2017 10:43:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4UAhmQ2027487 for ; Tue, 30 May 2017 06:43:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id EEB92171BB; Tue, 30 May 2017 10:43:48 +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 A9F8D5C542 for ; Tue, 30 May 2017 10:43:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5AAA44E34C 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 5AAA44E34C From: John Ferlan To: libvir-list@redhat.com Date: Tue, 30 May 2017 06:43:36 -0400 Message-Id: <20170530104344.25015-2-jferlan@redhat.com> In-Reply-To: <20170530104344.25015-1-jferlan@redhat.com> References: <20170530104344.25015-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 1/9] 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 30 May 2017 10:43:54 +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 9330d9e..d9f9329 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 Mon Apr 29 19:12:58 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 1496141046051936.2742640086337; Tue, 30 May 2017 03:44:06 -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 8B466811D8; Tue, 30 May 2017 10:44:03 +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 5CC58183D3; Tue, 30 May 2017 10:44:03 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id EC1344A491; Tue, 30 May 2017 10:44:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4UAhnTO027492 for ; Tue, 30 May 2017 06:43:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8F9C3171BB; Tue, 30 May 2017 10:43:49 +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 4DAC8171F2 for ; Tue, 30 May 2017 10:43:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8B466811D8 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 8B466811D8 From: John Ferlan To: libvir-list@redhat.com Date: Tue, 30 May 2017 06:43:37 -0400 Message-Id: <20170530104344.25015-3-jferlan@redhat.com> In-Reply-To: <20170530104344.25015-1-jferlan@redhat.com> References: <20170530104344.25015-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 2/9] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 30 May 2017 10:44:04 +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 | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index d9f9329..8f7ff63 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 @@ -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 Mon Apr 29 19:12:58 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 1496141037421955.1136055001881; Tue, 30 May 2017 03:43:57 -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 1CB4AC0567B5; Tue, 30 May 2017 10:43:55 +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 E624619F0E; Tue, 30 May 2017 10:43: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 6DE45180BAF5; Tue, 30 May 2017 10:43:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4UAhooK027501 for ; Tue, 30 May 2017 06:43:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 041FD171BB; Tue, 30 May 2017 10:43:50 +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 B6F415C542 for ; Tue, 30 May 2017 10:43:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1CB4AC0567B5 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1CB4AC0567B5 From: John Ferlan To: libvir-list@redhat.com Date: Tue, 30 May 2017 06:43:38 -0400 Message-Id: <20170530104344.25015-4-jferlan@redhat.com> In-Reply-To: <20170530104344.25015-1-jferlan@redhat.com> References: <20170530104344.25015-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 3/9] interface: Use virInterfaceDefPtr rather than deref from virInterfaceObjPtr X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 30 May 2017 10:43:55 +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 8f7ff63..29c31ad 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 Mon Apr 29 19:12:58 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 14961410460841012.6985276404536; Tue, 30 May 2017 03:44:06 -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 53BE61556C; Tue, 30 May 2017 10:44:03 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2B468183BE; Tue, 30 May 2017 10:44:03 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BE8BA180BAF9; Tue, 30 May 2017 10:44:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4UAhoGr027509 for ; Tue, 30 May 2017 06:43:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6EC81171BB; Tue, 30 May 2017 10:43:50 +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 2CDEA171F2 for ; Tue, 30 May 2017 10:43:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 53BE61556C 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 53BE61556C From: John Ferlan To: libvir-list@redhat.com Date: Tue, 30 May 2017 06:43:39 -0400 Message-Id: <20170530104344.25015-5-jferlan@redhat.com> In-Reply-To: <20170530104344.25015-1-jferlan@redhat.com> References: <20170530104344.25015-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 4/9] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 30 May 2017 10:44:04 +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 429b095..0929728 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 29c31ad..1b6063a 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 Mon Apr 29 19:12:58 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 1496141050428925.8056058999564; Tue, 30 May 2017 03:44:10 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 84368448D68; Tue, 30 May 2017 10:44:07 +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 551D718C5B; Tue, 30 May 2017 10:44:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E7E4F4A492; Tue, 30 May 2017 10:44:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4UAho3S027514 for ; Tue, 30 May 2017 06:43:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id D6035171D2; Tue, 30 May 2017 10:43:50 +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 967F8171BB for ; Tue, 30 May 2017 10:43:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 84368448D68 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 84368448D68 From: John Ferlan To: libvir-list@redhat.com Date: Tue, 30 May 2017 06:43:40 -0400 Message-Id: <20170530104344.25015-6-jferlan@redhat.com> In-Reply-To: <20170530104344.25015-1-jferlan@redhat.com> References: <20170530104344.25015-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 5/9] 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 30 May 2017 10:44:08 +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 0929728..bdf4eeb 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 1b6063a..7cf0d43 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)) =3D=3D NULL) 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 Mon Apr 29 19:12:58 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 1496141053592143.43792691611225; Tue, 30 May 2017 03:44:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 96A1AC0467DF; Tue, 30 May 2017 10:44:11 +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 587CB94D9E; Tue, 30 May 2017 10:44:11 +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 E95E2180BAFC; Tue, 30 May 2017 10:44:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4UAhp7p027524 for ; Tue, 30 May 2017 06:43:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4C838171BB; Tue, 30 May 2017 10:43:51 +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 0A8B25C542 for ; Tue, 30 May 2017 10:43:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 96A1AC0467DF Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 96A1AC0467DF From: John Ferlan To: libvir-list@redhat.com Date: Tue, 30 May 2017 06:43:41 -0400 Message-Id: <20170530104344.25015-7-jferlan@redhat.com> In-Reply-To: <20170530104344.25015-1-jferlan@redhat.com> References: <20170530104344.25015-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 6/9] 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 30 May 2017 10:44:12 +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 bdf4eeb..9be50cb 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 7cf0d43..8444e91 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)) =3D=3D NULL) 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 Mon Apr 29 19:12:58 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 1496141047585866.8979392556719; Tue, 30 May 2017 03:44:07 -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 6D5B588E60; Tue, 30 May 2017 10:44:05 +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 45986183D1; Tue, 30 May 2017 10:44:05 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E7A86180BAFA; Tue, 30 May 2017 10:44:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4UAhpqJ027529 for ; Tue, 30 May 2017 06:43:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id B36F2171BB; Tue, 30 May 2017 10:43:51 +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 72C3C171F2 for ; Tue, 30 May 2017 10:43:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6D5B588E60 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 6D5B588E60 From: John Ferlan To: libvir-list@redhat.com Date: Tue, 30 May 2017 06:43:42 -0400 Message-Id: <20170530104344.25015-8-jferlan@redhat.com> In-Reply-To: <20170530104344.25015-1-jferlan@redhat.com> References: <20170530104344.25015-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 7/9] 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]); Tue, 30 May 2017 10:44:06 +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 8444e91..511d65f 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 Mon Apr 29 19:12:58 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 1496141052055806.357343568521; Tue, 30 May 2017 03:44:12 -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 82F603DFCD; Tue, 30 May 2017 10:44:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5C39518694; Tue, 30 May 2017 10:44:09 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 06E024A493; Tue, 30 May 2017 10:44:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4UAhqbK027535 for ; Tue, 30 May 2017 06:43:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 27BCC171BB; Tue, 30 May 2017 10:43:52 +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 DBE335C542 for ; Tue, 30 May 2017 10:43:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 82F603DFCD 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 82F603DFCD From: John Ferlan To: libvir-list@redhat.com Date: Tue, 30 May 2017 06:43:43 -0400 Message-Id: <20170530104344.25015-9-jferlan@redhat.com> In-Reply-To: <20170530104344.25015-1-jferlan@redhat.com> References: <20170530104344.25015-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 8/9] 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.29]); Tue, 30 May 2017 10:44:10 +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 Mon Apr 29 19:12:58 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 1496141057286289.503357136556; Tue, 30 May 2017 03:44:17 -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 2F9C281235; Tue, 30 May 2017 10:44:15 +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 E90B97DB5C; Tue, 30 May 2017 10:44:14 +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 947CD4A494; Tue, 30 May 2017 10:44:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4UAhqrg027545 for ; Tue, 30 May 2017 06:43:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id AA996171BB; Tue, 30 May 2017 10:43:52 +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 507C6171F2 for ; Tue, 30 May 2017 10:43:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2F9C281235 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 2F9C281235 From: John Ferlan To: libvir-list@redhat.com Date: Tue, 30 May 2017 06:43:44 -0400 Message-Id: <20170530104344.25015-10-jferlan@redhat.com> In-Reply-To: <20170530104344.25015-1-jferlan@redhat.com> References: <20170530104344.25015-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 9/9] 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]); Tue, 30 May 2017 10:44:16 +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. This commit also introduces virInterfaceObjEndAPI in order to handle the lock unlock and object unref in one call for consumers returning a NULL obj upon return. This removes the need for virInterfaceObj{Lock|Unlock} external API's. Signed-off-by: John Ferlan --- po/POTFILES.in | 1 - src/conf/virinterfaceobj.c | 105 ++++++++++++++++++++++++-----------------= ---- src/conf/virinterfaceobj.h | 9 ++-- src/libvirt_private.syms | 3 +- src/test/test_driver.c | 15 +++---- 5 files changed, 68 insertions(+), 65 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 142b4d3..923d647 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 1e3f25c..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 */ @@ -46,50 +46,60 @@ struct _virInterfaceObjList { =20 /* 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 -void -virInterfaceObjLock(virInterfaceObjPtr obj) +static void +virInterfaceObjDispose(void *opaque) { - virMutexLock(&obj->lock); + virInterfaceObjPtr obj =3D opaque; + + virInterfaceDefFree(obj->def); } =20 =20 -void -virInterfaceObjUnlock(virInterfaceObjPtr obj) +static virInterfaceObjPtr +virInterfaceObjNew(void) { - virMutexUnlock(&obj->lock); + virInterfaceObjPtr obj; + + if (virInterfaceObjInitialize() < 0) + return NULL; + + if (!(obj =3D virObjectLockableNew(virInterfaceObjClass))) + return NULL; + + 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 @@ -140,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 @@ -173,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; @@ -190,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); } @@ -227,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; @@ -256,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 @@ -273,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 @@ -297,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; @@ -320,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; 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 9be50cb..5d6cb5e 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 511d65f..9a1c8a5 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