From nobody Sun Feb 8 20:52:12 2026 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 1499117152045196.24586861948944; Mon, 3 Jul 2017 14:25:52 -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 18FAD315D3F; Mon, 3 Jul 2017 21:25:50 +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 A9B8A619CF; Mon, 3 Jul 2017 21:25:49 +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 3DB1C41F79; Mon, 3 Jul 2017 21:25:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v63LPYpB021494 for ; Mon, 3 Jul 2017 17:25:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id C8B4318830; Mon, 3 Jul 2017 21:25:34 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-36.phx2.redhat.com [10.3.116.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F1EB619CF for ; Mon, 3 Jul 2017 21:25:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 18FAD315D3F 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 18FAD315D3F From: John Ferlan To: libvir-list@redhat.com Date: Mon, 3 Jul 2017 17:25:18 -0400 Message-Id: <20170703212530.22989-3-jferlan@redhat.com> In-Reply-To: <20170703212530.22989-1-jferlan@redhat.com> References: <20170703212530.22989-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 02/14] test: Adjust cleanup/error paths for nodedev test 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-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.29]); Mon, 03 Jul 2017 21:25:50 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" - In testDestroyVport rather than use a cleanup label, just return -1 immediately since nothing else is needed. - In testStoragePoolDestroy, if !privpool, then just return -1 since nothing else will happen anyway. - Rather than "goto cleanup;" on failure to virNodeDeviceObjFindByName an @obj, just return directly. This then allows the cleanup: label code to not have to check "if (obj)" before calling virNodeDeviceObjUnlock. This also simplifies some exit logic... - In testNodeDeviceObjFindByName use an error: label to handle the failure and don't do the ncaps++ within the VIR_STRDUP() source target index. Only increment ncaps after success. Easier on eyes at error label too. - In testNodeDeviceDestroy use "cleanup" rather than "out" for the goto Signed-off-by: John Ferlan --- src/test/test_driver.c | 78 +++++++++++++++++++---------------------------= ---- 1 file changed, 30 insertions(+), 48 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 04887e0..2889ffa 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4509,7 +4509,6 @@ testDestroyVport(testDriverPtr privconn, const char *wwnn ATTRIBUTE_UNUSED, const char *wwpn ATTRIBUTE_UNUSED) { - int ret =3D -1; virNodeDeviceObjPtr obj =3D NULL; virObjectEventPtr event =3D NULL; =20 @@ -4523,7 +4522,7 @@ testDestroyVport(testDriverPtr privconn, if (!(obj =3D virNodeDeviceObjFindByName(&privconn->devs, "scsi_host12= "))) { virReportError(VIR_ERR_NO_NODE_DEVICE, "%s", _("no node device with matching name 'scsi_host12'"= )); - goto cleanup; + return -1; } =20 event =3D virNodeDeviceEventLifecycleNew("scsi_host12", @@ -4532,15 +4531,9 @@ testDestroyVport(testDriverPtr privconn, =20 virNodeDeviceObjRemove(&privconn->devs, obj); virNodeDeviceObjFree(obj); - obj =3D NULL; =20 - ret =3D 0; - - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); testObjectEventQueue(privconn, event); - return ret; + return 0; } =20 =20 @@ -4553,7 +4546,7 @@ testStoragePoolDestroy(virStoragePoolPtr pool) virObjectEventPtr event =3D NULL; =20 if (!(privpool =3D testStoragePoolObjFindByName(privconn, pool->name))) - goto cleanup; + return -1; =20 if (!virStoragePoolObjIsActive(privpool)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -5328,7 +5321,7 @@ testNodeDeviceLookupByName(virConnectPtr conn, const = char *name) virNodeDevicePtr ret =3D NULL; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, name))) - goto cleanup; + return NULL; def =3D virNodeDeviceObjGetDef(obj); =20 if ((ret =3D virGetNodeDevice(conn, name))) { @@ -5338,9 +5331,7 @@ testNodeDeviceLookupByName(virConnectPtr conn, const = char *name) } } =20 - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjUnlock(obj); return ret; } =20 @@ -5355,13 +5346,11 @@ testNodeDeviceGetXMLDesc(virNodeDevicePtr dev, virCheckFlags(0, NULL); =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto cleanup; + return NULL; =20 ret =3D virNodeDeviceDefFormat(virNodeDeviceObjGetDef(obj)); =20 - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjUnlock(obj); return ret; } =20 @@ -5374,7 +5363,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) char *ret =3D NULL; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto cleanup; + return NULL; def =3D virNodeDeviceObjGetDef(obj); =20 if (def->parent) { @@ -5384,9 +5373,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) "%s", _("no parent for this device")); } =20 - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjUnlock(obj); return ret; } =20 @@ -5399,20 +5386,16 @@ testNodeDeviceNumOfCaps(virNodeDevicePtr dev) virNodeDeviceDefPtr def; virNodeDevCapsDefPtr caps; int ncaps =3D 0; - int ret =3D -1; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto cleanup; + return -1; def =3D virNodeDeviceObjGetDef(obj); =20 for (caps =3D def->caps; caps; caps =3D caps->next) ++ncaps; - ret =3D ncaps; =20 - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); - return ret; + virNodeDeviceObjUnlock(obj); + return ncaps; } =20 =20 @@ -5424,27 +5407,26 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char *= *const names, int maxnames) virNodeDeviceDefPtr def; virNodeDevCapsDefPtr caps; int ncaps =3D 0; - int ret =3D -1; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto cleanup; + return -1; def =3D virNodeDeviceObjGetDef(obj); =20 for (caps =3D def->caps; caps && ncaps < maxnames; caps =3D caps->next= ) { - if (VIR_STRDUP(names[ncaps++], virNodeDevCapTypeToString(caps->dat= a.type)) < 0) - goto cleanup; + if (VIR_STRDUP(names[ncaps], + virNodeDevCapTypeToString(caps->data.type)) < 0) + goto error; + ncaps++; } - ret =3D ncaps; =20 - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); - if (ret =3D=3D -1) { - --ncaps; - while (--ncaps >=3D 0) - VIR_FREE(names[ncaps]); - } - return ret; + virNodeDeviceObjUnlock(obj); + return ncaps; + + error: + while (--ncaps >=3D 0) + VIR_FREE(names[ncaps]); + virNodeDeviceObjUnlock(obj); + return -1; } =20 =20 @@ -5598,14 +5580,14 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) virObjectEventPtr event =3D NULL; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto out; + return -1; def =3D virNodeDeviceObjGetDef(obj); =20 if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) =3D=3D -1) - goto out; + goto cleanup; =20 if (VIR_STRDUP(parent_name, def->parent) < 0) - goto out; + goto cleanup; =20 /* virNodeDeviceGetParentHost will cause the device object's lock to be * taken, so we have to dup the parent's name and drop the lock @@ -5618,7 +5600,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) if (virNodeDeviceObjGetParentHost(&driver->devs, def, EXISTING_DEVICE) < 0) { obj =3D NULL; - goto out; + goto cleanup; } =20 event =3D virNodeDeviceEventLifecycleNew(dev->name, @@ -5630,7 +5612,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) virNodeDeviceObjFree(obj); obj =3D NULL; =20 - out: + cleanup: if (obj) virNodeDeviceObjUnlock(obj); testObjectEventQueue(driver, event); --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list