From nobody Sat Feb 7 06:14:09 2026 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 1488639862306326.4178852690518; Sat, 4 Mar 2017 07:04:22 -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 v24F0x3O004656; Sat, 4 Mar 2017 10:00:59 -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 v24F0Rcv009855 for ; Sat, 4 Mar 2017 10:00:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id EF62C2D654; Sat, 4 Mar 2017 15:00:27 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-78.phx2.redhat.com [10.3.116.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 987342D653 for ; Sat, 4 Mar 2017 15:00:27 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Sat, 4 Mar 2017 10:00:22 -0500 Message-Id: <20170304150024.30063-2-jferlan@redhat.com> In-Reply-To: <20170304150024.30063-1-jferlan@redhat.com> References: <20170304150024.30063-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/3] test: Make common test*ObjFindByName helpers 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" Rather than have continued repeated sequences of : testDriverLock() xxx =3D vir*ObjFindByName() testDriverUnlock() if (xxx =3D=3D NULL) { virReportError goto cleanup; } Make some common helpers which will use the pattern and make a single reference using a single common error message. Altered for Interfaces, Storage Pools, Storage Volumes, and Node Devices. For each the common error message can now also indicate which 'name' was not found. For Storage Volumes, the "new" error will be more specific rather than just invalid argument. Signed-off-by: John Ferlan --- src/test/test_driver.c | 346 +++++++++++++--------------------------------= ---- 1 file changed, 90 insertions(+), 256 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 61c82b9..c2536c9 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -3637,6 +3637,25 @@ static int testNetworkSetAutostart(virNetworkPtr net= work, */ =20 =20 +static virInterfaceObjPtr +testInterfaceObjFindByName(testDriverPtr privconn, + const char *name) +{ + virInterfaceObjPtr iface; + + testDriverLock(privconn); + iface =3D virInterfaceFindByName(&privconn->ifaces, name); + testDriverUnlock(privconn); + + if (!iface) + virReportError(VIR_ERR_NO_INTERFACE, + _("no interface with matching name '%s'"), + name); + + return iface; +} + + static int testConnectNumOfInterfaces(virConnectPtr conn) { testDriverPtr privconn =3D conn->privateData; @@ -3736,14 +3755,8 @@ static virInterfacePtr testInterfaceLookupByName(vir= ConnectPtr conn, virInterfaceObjPtr iface; virInterfacePtr ret =3D NULL; =20 - testDriverLock(privconn); - iface =3D virInterfaceFindByName(&privconn->ifaces, name); - testDriverUnlock(privconn); - - if (iface =3D=3D NULL) { - virReportError(VIR_ERR_NO_INTERFACE, NULL); + if (!(iface =3D testInterfaceObjFindByName(privconn, name))) goto cleanup; - } =20 ret =3D virGetInterface(conn, iface->def->name, iface->def->mac); =20 @@ -3789,13 +3802,9 @@ static int testInterfaceIsActive(virInterfacePtr ifa= ce) virInterfaceObjPtr obj; int ret =3D -1; =20 - testDriverLock(privconn); - obj =3D virInterfaceFindByName(&privconn->ifaces, iface->name); - testDriverUnlock(privconn); - if (!obj) { - virReportError(VIR_ERR_NO_INTERFACE, NULL); + if (!(obj =3D testInterfaceObjFindByName(privconn, iface->name))) goto cleanup; - } + ret =3D virInterfaceObjIsActive(obj); =20 cleanup: @@ -3900,15 +3909,8 @@ static char *testInterfaceGetXMLDesc(virInterfacePtr= iface, =20 virCheckFlags(0, NULL); =20 - testDriverLock(privconn); - privinterface =3D virInterfaceFindByName(&privconn->ifaces, - iface->name); - testDriverUnlock(privconn); - - if (privinterface =3D=3D NULL) { - virReportError(VIR_ERR_NO_INTERFACE, __FUNCTION__); + if (!(privinterface =3D testInterfaceObjFindByName(privconn, iface->na= me))) goto cleanup; - } =20 ret =3D virInterfaceDefFormat(privinterface->def); =20 @@ -3953,14 +3955,8 @@ static int testInterfaceUndefine(virInterfacePtr ifa= ce) virInterfaceObjPtr privinterface; int ret =3D -1; =20 - testDriverLock(privconn); - privinterface =3D virInterfaceFindByName(&privconn->ifaces, - iface->name); - - if (privinterface =3D=3D NULL) { - virReportError(VIR_ERR_NO_INTERFACE, NULL); + if (!(privinterface =3D testInterfaceObjFindByName(privconn, iface->na= me))) goto cleanup; - } =20 virInterfaceRemove(&privconn->ifaces, privinterface); @@ -3980,14 +3976,8 @@ static int testInterfaceCreate(virInterfacePtr iface, =20 virCheckFlags(0, -1); =20 - testDriverLock(privconn); - privinterface =3D virInterfaceFindByName(&privconn->ifaces, - iface->name); - - if (privinterface =3D=3D NULL) { - virReportError(VIR_ERR_NO_INTERFACE, NULL); + if (!(privinterface =3D testInterfaceObjFindByName(privconn, iface->na= me))) goto cleanup; - } =20 if (privinterface->active !=3D 0) { virReportError(VIR_ERR_OPERATION_INVALID, NULL); @@ -4013,14 +4003,8 @@ static int testInterfaceDestroy(virInterfacePtr ifac= e, =20 virCheckFlags(0, -1); =20 - testDriverLock(privconn); - privinterface =3D virInterfaceFindByName(&privconn->ifaces, - iface->name); - - if (privinterface =3D=3D NULL) { - virReportError(VIR_ERR_NO_INTERFACE, NULL); + if (!(privinterface =3D testInterfaceObjFindByName(privconn, iface->na= me))) goto cleanup; - } =20 if (privinterface->active =3D=3D 0) { virReportError(VIR_ERR_OPERATION_INVALID, NULL); @@ -4055,6 +4039,25 @@ static int testStoragePoolObjSetDefaults(virStorageP= oolObjPtr pool) } =20 =20 +static virStoragePoolObjPtr +testStoragePoolObjFindByName(testDriverPtr privconn, + const char *name) +{ + virStoragePoolObjPtr pool; + + testDriverLock(privconn); + pool =3D virStoragePoolObjFindByName(&privconn->pools, name); + testDriverUnlock(privconn); + + if (!pool) + virReportError(VIR_ERR_NO_STORAGE_POOL, + _("no storage pool with matching name '%s'"), + name); + + return pool; +} + + static virStoragePoolPtr testStoragePoolLookupByUUID(virConnectPtr conn, const unsigned char *uuid) @@ -4089,14 +4092,8 @@ testStoragePoolLookupByName(virConnectPtr conn, virStoragePoolObjPtr pool; virStoragePoolPtr ret =3D NULL; =20 - testDriverLock(privconn); - pool =3D virStoragePoolObjFindByName(&privconn->pools, name); - testDriverUnlock(privconn); - - if (pool =3D=3D NULL) { - virReportError(VIR_ERR_NO_STORAGE_POOL, NULL); + if (!(pool =3D testStoragePoolObjFindByName(privconn, name))) goto cleanup; - } =20 ret =3D virGetStoragePool(conn, pool->def->name, pool->def->uuid, NULL, NULL); @@ -4283,15 +4280,8 @@ testStoragePoolCreate(virStoragePoolPtr pool, =20 virCheckFlags(0, -1); =20 - testDriverLock(privconn); - privpool =3D virStoragePoolObjFindByName(&privconn->pools, - pool->name); - testDriverUnlock(privconn); - - if (privpool =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privpool =3D testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - } =20 if (virStoragePoolObjIsActive(privpool)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -4474,14 +4464,8 @@ testStoragePoolUndefine(virStoragePoolPtr pool) int ret =3D -1; virObjectEventPtr event =3D NULL; =20 - testDriverLock(privconn); - privpool =3D virStoragePoolObjFindByName(&privconn->pools, - pool->name); - - if (privpool =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privpool =3D testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - } =20 if (virStoragePoolObjIsActive(privpool)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -4515,15 +4499,8 @@ testStoragePoolBuild(virStoragePoolPtr pool, =20 virCheckFlags(0, -1); =20 - testDriverLock(privconn); - privpool =3D virStoragePoolObjFindByName(&privconn->pools, - pool->name); - testDriverUnlock(privconn); - - if (privpool =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privpool =3D testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - } =20 if (virStoragePoolObjIsActive(privpool)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -4547,14 +4524,8 @@ testStoragePoolDestroy(virStoragePoolPtr pool) int ret =3D -1; virObjectEventPtr event =3D NULL; =20 - testDriverLock(privconn); - privpool =3D virStoragePoolObjFindByName(&privconn->pools, - pool->name); - - if (privpool =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privpool =3D testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - } =20 if (!virStoragePoolObjIsActive(privpool)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -4592,15 +4563,8 @@ testStoragePoolDelete(virStoragePoolPtr pool, =20 virCheckFlags(0, -1); =20 - testDriverLock(privconn); - privpool =3D virStoragePoolObjFindByName(&privconn->pools, - pool->name); - testDriverUnlock(privconn); - - if (privpool =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privpool =3D testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - } =20 if (virStoragePoolObjIsActive(privpool)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -4628,15 +4592,8 @@ testStoragePoolRefresh(virStoragePoolPtr pool, =20 virCheckFlags(0, -1); =20 - testDriverLock(privconn); - privpool =3D virStoragePoolObjFindByName(&privconn->pools, - pool->name); - testDriverUnlock(privconn); - - if (privpool =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privpool =3D testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - } =20 if (!virStoragePoolObjIsActive(privpool)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -4663,15 +4620,8 @@ testStoragePoolGetInfo(virStoragePoolPtr pool, virStoragePoolObjPtr privpool; int ret =3D -1; =20 - testDriverLock(privconn); - privpool =3D virStoragePoolObjFindByName(&privconn->pools, - pool->name); - testDriverUnlock(privconn); - - if (privpool =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privpool =3D testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - } =20 memset(info, 0, sizeof(virStoragePoolInfo)); if (privpool->active) @@ -4699,15 +4649,8 @@ testStoragePoolGetXMLDesc(virStoragePoolPtr pool, =20 virCheckFlags(0, NULL); =20 - testDriverLock(privconn); - privpool =3D virStoragePoolObjFindByName(&privconn->pools, - pool->name); - testDriverUnlock(privconn); - - if (privpool =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privpool =3D testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - } =20 ret =3D virStoragePoolDefFormat(privpool->def); =20 @@ -4725,15 +4668,8 @@ testStoragePoolGetAutostart(virStoragePoolPtr pool, virStoragePoolObjPtr privpool; int ret =3D -1; =20 - testDriverLock(privconn); - privpool =3D virStoragePoolObjFindByName(&privconn->pools, - pool->name); - testDriverUnlock(privconn); - - if (privpool =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privpool =3D testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - } =20 if (!privpool->configFile) { *autostart =3D 0; @@ -4756,15 +4692,8 @@ testStoragePoolSetAutostart(virStoragePoolPtr pool, virStoragePoolObjPtr privpool; int ret =3D -1; =20 - testDriverLock(privconn); - privpool =3D virStoragePoolObjFindByName(&privconn->pools, - pool->name); - testDriverUnlock(privconn); - - if (privpool =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privpool =3D testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - } =20 if (!privpool->configFile) { virReportError(VIR_ERR_INVALID_ARG, @@ -4790,15 +4719,8 @@ testStoragePoolNumOfVolumes(virStoragePoolPtr pool) virStoragePoolObjPtr privpool; int ret =3D -1; =20 - testDriverLock(privconn); - privpool =3D virStoragePoolObjFindByName(&privconn->pools, - pool->name); - testDriverUnlock(privconn); - - if (privpool =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privpool =3D testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - } =20 if (!virStoragePoolObjIsActive(privpool)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -4826,16 +4748,8 @@ testStoragePoolListVolumes(virStoragePoolPtr pool, =20 memset(names, 0, maxnames * sizeof(*names)); =20 - testDriverLock(privconn); - privpool =3D virStoragePoolObjFindByName(&privconn->pools, - pool->name); - testDriverUnlock(privconn); - - if (privpool =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privpool =3D testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - } - =20 if (!virStoragePoolObjIsActive(privpool)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -4938,16 +4852,8 @@ testStorageVolLookupByName(virStoragePoolPtr pool, virStorageVolDefPtr privvol; virStorageVolPtr ret =3D NULL; =20 - testDriverLock(privconn); - privpool =3D virStoragePoolObjFindByName(&privconn->pools, - pool->name); - testDriverUnlock(privconn); - - if (privpool =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privpool =3D testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - } - =20 if (!virStoragePoolObjIsActive(privpool)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -5058,15 +4964,8 @@ testStorageVolCreateXML(virStoragePoolPtr pool, =20 virCheckFlags(0, NULL); =20 - testDriverLock(privconn); - privpool =3D virStoragePoolObjFindByName(&privconn->pools, - pool->name); - testDriverUnlock(privconn); - - if (privpool =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privpool =3D testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - } =20 if (!virStoragePoolObjIsActive(privpool)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -5132,15 +5031,8 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, =20 virCheckFlags(0, NULL); =20 - testDriverLock(privconn); - privpool =3D virStoragePoolObjFindByName(&privconn->pools, - pool->name); - testDriverUnlock(privconn); - - if (privpool =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privpool =3D testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - } =20 if (!virStoragePoolObjIsActive(privpool)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -5215,16 +5107,8 @@ testStorageVolDelete(virStorageVolPtr vol, =20 virCheckFlags(0, -1); =20 - testDriverLock(privconn); - privpool =3D virStoragePoolObjFindByName(&privconn->pools, - vol->pool); - testDriverUnlock(privconn); - - if (privpool =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privpool =3D testStoragePoolObjFindByName(privconn, vol->pool))) goto cleanup; - } - =20 privvol =3D virStorageVolDefFindByName(privpool, vol->name); =20 @@ -5285,15 +5169,8 @@ testStorageVolGetInfo(virStorageVolPtr vol, virStorageVolDefPtr privvol; int ret =3D -1; =20 - testDriverLock(privconn); - privpool =3D virStoragePoolObjFindByName(&privconn->pools, - vol->pool); - testDriverUnlock(privconn); - - if (privpool =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privpool =3D testStoragePoolObjFindByName(privconn, vol->pool))) goto cleanup; - } =20 privvol =3D virStorageVolDefFindByName(privpool, vol->name); =20 @@ -5333,15 +5210,8 @@ testStorageVolGetXMLDesc(virStorageVolPtr vol, =20 virCheckFlags(0, NULL); =20 - testDriverLock(privconn); - privpool =3D virStoragePoolObjFindByName(&privconn->pools, - vol->pool); - testDriverUnlock(privconn); - - if (privpool =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privpool =3D testStoragePoolObjFindByName(privconn, vol->pool))) goto cleanup; - } =20 privvol =3D virStorageVolDefFindByName(privpool, vol->name); =20 @@ -5374,15 +5244,8 @@ testStorageVolGetPath(virStorageVolPtr vol) virStorageVolDefPtr privvol; char *ret =3D NULL; =20 - testDriverLock(privconn); - privpool =3D virStoragePoolObjFindByName(&privconn->pools, - vol->pool); - testDriverUnlock(privconn); - - if (privpool =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privpool =3D testStoragePoolObjFindByName(privconn, vol->pool))) goto cleanup; - } =20 privvol =3D virStorageVolDefFindByName(privpool, vol->name); =20 @@ -5410,6 +5273,25 @@ testStorageVolGetPath(virStorageVolPtr vol) =20 /* Node device implementations */ =20 +static virNodeDeviceObjPtr +testNodeDeviceObjFindByName(testDriverPtr driver, + const char *name) +{ + virNodeDeviceObjPtr obj; + + testDriverLock(driver); + obj =3D virNodeDeviceObjFindByName(&driver->devs, name); + testDriverUnlock(driver); + + if (!obj) + virReportError(VIR_ERR_NO_NODE_DEVICE, + _("no node device with matching name '%s'"), + name); + + return obj; +} + + static int testNodeNumOfDevices(virConnectPtr conn, const char *cap, @@ -5475,16 +5357,8 @@ testNodeDeviceLookupByName(virConnectPtr conn, const= char *name) virNodeDeviceObjPtr obj; virNodeDevicePtr ret =3D NULL; =20 - testDriverLock(driver); - obj =3D virNodeDeviceObjFindByName(&driver->devs, name); - testDriverUnlock(driver); - - if (!obj) { - virReportError(VIR_ERR_NO_NODE_DEVICE, - _("no node device with matching name '%s'"), - name); + if (!(obj =3D testNodeDeviceObjFindByName(driver, name))) goto cleanup; - } =20 if ((ret =3D virGetNodeDevice(conn, name))) { if (VIR_STRDUP(ret->parent, obj->def->parent) < 0) @@ -5507,16 +5381,8 @@ testNodeDeviceGetXMLDesc(virNodeDevicePtr dev, =20 virCheckFlags(0, NULL); =20 - testDriverLock(driver); - obj =3D virNodeDeviceObjFindByName(&driver->devs, dev->name); - testDriverUnlock(driver); - - if (!obj) { - virReportError(VIR_ERR_NO_NODE_DEVICE, - _("no node device with matching name '%s'"), - dev->name); + if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) goto cleanup; - } =20 ret =3D virNodeDeviceDefFormat(obj->def); =20 @@ -5533,16 +5399,8 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) virNodeDeviceObjPtr obj; char *ret =3D NULL; =20 - testDriverLock(driver); - obj =3D virNodeDeviceObjFindByName(&driver->devs, dev->name); - testDriverUnlock(driver); - - if (!obj) { - virReportError(VIR_ERR_NO_NODE_DEVICE, - _("no node device with matching name '%s'"), - dev->name); + if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) goto cleanup; - } =20 if (obj->def->parent) { ignore_value(VIR_STRDUP(ret, obj->def->parent)); @@ -5567,16 +5425,8 @@ testNodeDeviceNumOfCaps(virNodeDevicePtr dev) int ncaps =3D 0; int ret =3D -1; =20 - testDriverLock(driver); - obj =3D virNodeDeviceObjFindByName(&driver->devs, dev->name); - testDriverUnlock(driver); - - if (!obj) { - virReportError(VIR_ERR_NO_NODE_DEVICE, - _("no node device with matching name '%s'"), - dev->name); + if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) goto cleanup; - } =20 for (caps =3D obj->def->caps; caps; caps =3D caps->next) ++ncaps; @@ -5598,16 +5448,8 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **= const names, int maxnames) int ncaps =3D 0; int ret =3D -1; =20 - testDriverLock(driver); - obj =3D virNodeDeviceObjFindByName(&driver->devs, dev->name); - testDriverUnlock(driver); - - if (!obj) { - virReportError(VIR_ERR_NO_NODE_DEVICE, - _("no node device with matching name '%s'"), - dev->name); + if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) goto cleanup; - } =20 for (caps =3D obj->def->caps; caps && ncaps < maxnames; caps =3D caps-= >next) { if (VIR_STRDUP(names[ncaps++], virNodeDevCapTypeToString(caps->dat= a.type)) < 0) @@ -5771,16 +5613,8 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) char *parent_name =3D NULL, *wwnn =3D NULL, *wwpn =3D NULL; virObjectEventPtr event =3D NULL; =20 - testDriverLock(driver); - obj =3D virNodeDeviceObjFindByName(&driver->devs, dev->name); - testDriverUnlock(driver); - - if (!obj) { - virReportError(VIR_ERR_NO_NODE_DEVICE, - _("no node device with matching name '%s'"), - dev->name); + if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) goto out; - } =20 if (virNodeDeviceGetWWNs(obj->def, &wwnn, &wwpn) =3D=3D -1) goto out; --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list