From nobody Fri May 3 10:54:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; envelope-from=libvir-list-bounces@redhat.com; helo=mx5-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mx.zohomail.com with SMTPS id 1488284160650850.926515027943; Tue, 28 Feb 2017 04:16:00 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1SCCS0q064317; Tue, 28 Feb 2017 07:12:28 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1SCC92c002264 for ; Tue, 28 Feb 2017 07:12:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0353D306A2; Tue, 28 Feb 2017 12:12:09 +0000 (UTC) Received: from moe.brq.redhat.com (dhcp129-131.brq.redhat.com [10.34.129.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 518C6306A0; Tue, 28 Feb 2017 12:12:08 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 28 Feb 2017 13:12:01 +0100 Message-Id: X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] testNodeDeviceMockCreateVport: Don't call public APIs 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-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This function is calling public APIs (virNodeDeviceLookupByName etc.). That requires the driver lock to be unlocked and locked again. If we, however, replace the public APIs calls with the internal calls (that public APIs call anyway), we can drop the lock/unlock exercise. Signed-off-by: Michal Privoznik --- src/test/test_driver.c | 59 ++++++++++++++++++++++++++++------------------= ---- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 5fef3f10b..8495443db 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -5626,17 +5626,16 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char *= *const names, int maxnames) } =20 =20 -static virNodeDeviceDefPtr +static virNodeDeviceObjPtr testNodeDeviceMockCreateVport(virConnectPtr conn, const char *wwnn, const char *wwpn) { testDriverPtr driver =3D conn->privateData; - virNodeDevicePtr devcpy =3D NULL; char *xml =3D NULL; virNodeDeviceDefPtr def =3D NULL; virNodeDevCapsDefPtr caps; - virNodeDeviceObjPtr obj =3D NULL; + virNodeDeviceObjPtr obj =3D NULL, objcopy =3D NULL; virObjectEventPtr event =3D NULL; =20 /* In the real code, we'd call virVHBAManageVport which would take the @@ -5648,9 +5647,15 @@ testNodeDeviceMockCreateVport(virConnectPtr conn, * using the scsi_host11 definition, changing the name and the * scsi_host capability fields before calling virNodeDeviceAssignDef * to add the def to the node device objects list. */ - if (!(devcpy =3D virNodeDeviceLookupByName(conn, "scsi_host11")) || - !(xml =3D virNodeDeviceGetXMLDesc(devcpy, 0)) || - !(def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL))) + if (!(objcopy =3D virNodeDeviceFindByName(&driver->devs, "scsi_host11"= ))) + goto cleanup; + + xml =3D virNodeDeviceDefFormat(objcopy->def); + virNodeDeviceObjUnlock(objcopy); + if (!xml) + goto cleanup; + + if (!(def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL))) goto cleanup; =20 VIR_FREE(def->name); @@ -5684,23 +5689,17 @@ testNodeDeviceMockCreateVport(virConnectPtr conn, =20 if (!(obj =3D virNodeDeviceAssignDef(&driver->devs, def))) goto cleanup; - virNodeDeviceObjUnlock(obj); + def =3D NULL; =20 - event =3D virNodeDeviceEventLifecycleNew(def->name, + event =3D virNodeDeviceEventLifecycleNew(obj->def->name, VIR_NODE_DEVICE_EVENT_CREATED, 0); testObjectEventQueue(driver, event); =20 cleanup: VIR_FREE(xml); - if (!obj) { - virNodeDeviceDefFree(def); - def =3D NULL; - } - if (devcpy) - virNodeDeviceFree(devcpy); - - return def; + virNodeDeviceDefFree(def); + return obj; } =20 =20 @@ -5712,8 +5711,8 @@ testNodeDeviceCreateXML(virConnectPtr conn, testDriverPtr driver =3D conn->privateData; virNodeDeviceDefPtr def =3D NULL; char *wwnn =3D NULL, *wwpn =3D NULL; - virNodeDevicePtr dev =3D NULL; - virNodeDeviceDefPtr newdef =3D NULL; + virNodeDevicePtr dev =3D NULL, ret =3D NULL; + virNodeDeviceObjPtr obj =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -5739,20 +5738,28 @@ testNodeDeviceCreateXML(virConnectPtr conn, * mocking udev. The mock routine will copy an existing vHBA and * rename a few fields to mock that. So in order to allow that to * work properly, we need to drop our lock */ - testDriverUnlock(driver); - if ((newdef =3D testNodeDeviceMockCreateVport(conn, wwnn, wwpn))) { - if ((dev =3D virNodeDeviceLookupByName(conn, newdef->name))) - ignore_value(VIR_STRDUP(dev->parent, def->parent)); - } - testDriverLock(driver); - newdef =3D NULL; + if (!(obj =3D testNodeDeviceMockCreateVport(conn, wwnn, wwpn))) + goto cleanup; + + if (!(dev =3D virGetNodeDevice(conn, obj->def->name))) + goto cleanup; + + VIR_FREE(dev->parent); + if (VIR_STRDUP(dev->parent, def->parent) < 0) + goto cleanup; + + ret =3D dev; + dev =3D NULL; =20 cleanup: + if (obj) + virNodeDeviceObjUnlock(obj); testDriverUnlock(driver); virNodeDeviceDefFree(def); + virObjectUnref(dev); VIR_FREE(wwnn); VIR_FREE(wwpn); - return dev; + return ret; } =20 static int --=20 2.11.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list