From nobody Thu May 15 23:33:39 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1503093116329393.5228759733658; Fri, 18 Aug 2017 14:51:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 729CF86647; Fri, 18 Aug 2017 21:51:54 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D1551897B; Fri, 18 Aug 2017 21:51: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 17E1F3FAD3; Fri, 18 Aug 2017 21:51:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7ILonWN005078 for ; Fri, 18 Aug 2017 17:50:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 441C55D962; Fri, 18 Aug 2017 21:50:49 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-120-47.rdu2.redhat.com [10.10.120.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 114FB5D961 for ; Fri, 18 Aug 2017 21:50:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 729CF86647 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=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Fri, 18 Aug 2017 17:50:38 -0400 Message-Id: <20170818215041.8118-15-jferlan@redhat.com> In-Reply-To: <20170818215041.8118-1-jferlan@redhat.com> References: <20170818215041.8118-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 14/17] test: Clean up test driver Interface interactions X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 18 Aug 2017 21:51:55 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Now that we have self locking hash table for Interface object lookups, there's no need to take the test driver lock in order to "lock" between the various API's, so remove the Lock/Unlock logic accordingly. Add a virInterfaceObjListFree during testDriverFree for the backupIfaces "just in case". Also use the VIR_STEAL_PTR rather than inline the code. Finally alter a couple of "if ((obj =3D function()) =3D=3D NULL" to use the more standard "if (!(obj =3D function()))" syntax. Signed-off-by: John Ferlan --- src/test/test_driver.c | 55 ++++++++++++----------------------------------= ---- 1 file changed, 13 insertions(+), 42 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index aa38f54..70977b8 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -155,6 +155,7 @@ testDriverFree(testDriverPtr driver) virNodeDeviceObjListFree(driver->devs); virObjectUnref(driver->networks); virInterfaceObjListFree(driver->ifaces); + virInterfaceObjListFree(driver->backupIfaces); virStoragePoolObjListFree(&driver->pools); virObjectUnref(driver->eventState); virMutexUnlock(&driver->lock); @@ -3689,11 +3690,7 @@ testInterfaceObjFindByName(testDriverPtr privconn, { virInterfaceObjPtr obj; =20 - testDriverLock(privconn); - obj =3D virInterfaceObjListFindByName(privconn->ifaces, name); - testDriverUnlock(privconn); - - if (!obj) + if (!(obj =3D virInterfaceObjListFindByName(privconn->ifaces, name))) virReportError(VIR_ERR_NO_INTERFACE, _("no interface with matching name '%s'"), name); @@ -3706,12 +3703,8 @@ static int testConnectNumOfInterfaces(virConnectPtr conn) { testDriverPtr privconn =3D conn->privateData; - int ninterfaces; =20 - testDriverLock(privconn); - ninterfaces =3D virInterfaceObjListNumOfInterfaces(privconn->ifaces, t= rue); - testDriverUnlock(privconn); - return ninterfaces; + return virInterfaceObjListNumOfInterfaces(privconn->ifaces, true); } =20 =20 @@ -3721,14 +3714,8 @@ testConnectListInterfaces(virConnectPtr conn, int maxnames) { testDriverPtr privconn =3D conn->privateData; - int nnames; =20 - testDriverLock(privconn); - nnames =3D virInterfaceObjListGetNames(privconn->ifaces, true, - names, maxnames); - testDriverUnlock(privconn); - - return nnames; + return virInterfaceObjListGetNames(privconn->ifaces, true, names, maxn= ames); } =20 =20 @@ -3736,12 +3723,8 @@ static int testConnectNumOfDefinedInterfaces(virConnectPtr conn) { testDriverPtr privconn =3D conn->privateData; - int ninterfaces; =20 - testDriverLock(privconn); - ninterfaces =3D virInterfaceObjListNumOfInterfaces(privconn->ifaces, f= alse); - testDriverUnlock(privconn); - return ninterfaces; + return virInterfaceObjListNumOfInterfaces(privconn->ifaces, false); } =20 =20 @@ -3751,14 +3734,8 @@ testConnectListDefinedInterfaces(virConnectPtr conn, int maxnames) { testDriverPtr privconn =3D conn->privateData; - int nnames; =20 - testDriverLock(privconn); - nnames =3D virInterfaceObjListGetNames(privconn->ifaces, false, - names, maxnames); - testDriverUnlock(privconn); - - return nnames; + return virInterfaceObjListGetNames(privconn->ifaces, false, names, max= names); } =20 =20 @@ -3791,12 +3768,8 @@ testInterfaceLookupByMACString(virConnectPtr conn, char *ifacenames[] =3D { NULL, NULL }; virInterfacePtr ret =3D NULL; =20 - testDriverLock(privconn); - ifacect =3D virInterfaceObjListFindByMACString(privconn->ifaces, mac, - ifacenames, 2); - testDriverUnlock(privconn); - - if (ifacect =3D=3D 0) { + if ((ifacect =3D virInterfaceObjListFindByMACString(privconn->ifaces, = mac, + ifacenames, 2)) =3D= =3D 0) { virReportError(VIR_ERR_NO_INTERFACE, _("no interface with matching mac '%s'"), mac); goto cleanup; @@ -3880,6 +3853,7 @@ testInterfaceChangeCommit(virConnectPtr conn, } =20 virInterfaceObjListFree(privconn->backupIfaces); + privconn->backupIfaces =3D NULL; privconn->transaction_running =3D false; =20 ret =3D 0; @@ -3910,8 +3884,7 @@ testInterfaceChangeRollback(virConnectPtr conn, } =20 virInterfaceObjListFree(privconn->ifaces); - privconn->ifaces =3D privconn->backupIfaces; - privconn->backupIfaces =3D NULL; + VIR_STEAL_PTR(privconn->ifaces, privconn->backupIfaces); =20 privconn->transaction_running =3D false; =20 @@ -3958,11 +3931,10 @@ testInterfaceDefineXML(virConnectPtr conn, =20 virCheckFlags(0, NULL); =20 - testDriverLock(privconn); - if ((def =3D virInterfaceDefParseString(xmlStr)) =3D=3D NULL) - goto cleanup; + if (!(def =3D virInterfaceDefParseString(xmlStr))) + return NULL; =20 - if ((obj =3D virInterfaceObjListAssignDef(privconn->ifaces, def)) =3D= =3D NULL) + if (!(obj =3D virInterfaceObjListAssignDef(privconn->ifaces, def))) goto cleanup; def =3D NULL; objdef =3D virInterfaceObjGetDef(obj); @@ -3972,7 +3944,6 @@ testInterfaceDefineXML(virConnectPtr conn, cleanup: virInterfaceDefFree(def); virInterfaceObjEndAPI(&obj); - testDriverUnlock(privconn); return ret; } =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list