From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651060911178.34345992097246; Fri, 8 Feb 2019 10:37:40 -0800 (PST) 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 4C72B83F51; Fri, 8 Feb 2019 18:37:38 +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 E39CF17A66; Fri, 8 Feb 2019 18:37:37 +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 ABBBA3F7CD; Fri, 8 Feb 2019 18:37:35 +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 x18IbYXN007530 for ; Fri, 8 Feb 2019 13:37:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5BA064250; Fri, 8 Feb 2019 18:37:34 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 01FF060C55; Fri, 8 Feb 2019 18:37:33 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:36:55 -0500 Message-Id: <20190208183726.30903-2-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 01/32] conf, util, qemu: Use VIR_STEAL_PTR for authdef processing 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: , 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.27]); Fri, 08 Feb 2019 18:37:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 3 +-- src/conf/storage_conf.c | 3 +-- src/qemu/qemu_parse_command.c | 3 +-- src/util/virstoragefile.c | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6772c327ed..a33f18c957 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7632,8 +7632,7 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr= sourcenode, authdef->secrettype); goto cleanup; } - iscsisrc->src->auth =3D authdef; - authdef =3D NULL; + VIR_STEAL_PTR(iscsisrc->src->auth, authdef); } cur =3D cur->next; } diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 1ee31ca676..fbd62e1305 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -584,8 +584,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, goto cleanup; } =20 - source->auth =3D authdef; - authdef =3D NULL; + VIR_STEAL_PTR(source->auth, authdef); } =20 /* Option protocol version string (NFSvN) */ diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c index c4650f01e0..679d49d442 100644 --- a/src/qemu/qemu_parse_command.c +++ b/src/qemu/qemu_parse_command.c @@ -133,8 +133,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURI= Ptr uri, if (VIR_STRDUP(authdef->secrettype, secrettype) < 0) goto error; } - def->src->auth =3D authdef; - authdef =3D NULL; + VIR_STEAL_PTR(def->src->auth, authdef); =20 /* Cannot formulate a secretType (eg, usage or uuid) given * what is provided. diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 8319ba9c8c..98f9bc803f 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2895,9 +2895,8 @@ virStorageSourceParseRBDColonString(const char *rbdst= r, if (VIR_STRDUP(authdef->secrettype, virSecretUsageTypeToString(VIR_SECRET_USAGE_TYP= E_CEPH)) < 0) goto error; - src->auth =3D authdef; + VIR_STEAL_PTR(src->auth, authdef); src->authInherited =3D true; - authdef =3D NULL; =20 /* Cannot formulate a secretType (eg, usage or uuid) given * what is provided. --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651061482539.7600666126872; Fri, 8 Feb 2019 10:37:41 -0800 (PST) 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 AD939C0495BF; Fri, 8 Feb 2019 18:37:38 +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 4015F5D970; Fri, 8 Feb 2019 18:37:38 +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 8904418005AF; Fri, 8 Feb 2019 18:37:37 +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 x18IbYgh007535 for ; Fri, 8 Feb 2019 13:37:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id DEDC3383F; Fri, 8 Feb 2019 18:37:34 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8569160C55; Fri, 8 Feb 2019 18:37:34 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:36:56 -0500 Message-Id: <20190208183726.30903-3-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 02/32] util: Rework virStorageAuthDefCopy 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: , 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.31]); Fri, 08 Feb 2019 18:37:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Rather than having an error path, let's rework the code to allocate and fill into an @authdef variable and then steal that into @ret when we are successful leaving just a cleanup: path. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/util/virstoragefile.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 98f9bc803f..7fbeea78eb 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1879,26 +1879,26 @@ virStorageAuthDefFree(virStorageAuthDefPtr authdef) virStorageAuthDefPtr virStorageAuthDefCopy(const virStorageAuthDef *src) { - virStorageAuthDefPtr ret; + virStorageAuthDefPtr authdef; + virStorageAuthDefPtr ret =3D NULL; =20 - if (VIR_ALLOC(ret) < 0) + if (VIR_ALLOC(authdef) < 0) return NULL; =20 - if (VIR_STRDUP(ret->username, src->username) < 0) - goto error; + if (VIR_STRDUP(authdef->username, src->username) < 0) + goto cleanup; /* Not present for storage pool, but used for disk source */ - if (VIR_STRDUP(ret->secrettype, src->secrettype) < 0) - goto error; - ret->authType =3D src->authType; + if (VIR_STRDUP(authdef->secrettype, src->secrettype) < 0) + goto cleanup; + authdef->authType =3D src->authType; =20 - if (virSecretLookupDefCopy(&ret->seclookupdef, &src->seclookupdef) < 0) - goto error; + if (virSecretLookupDefCopy(&authdef->seclookupdef, &src->seclookupdef)= < 0) + goto cleanup; =20 + VIR_STEAL_PTR(ret, authdef); + cleanup: + virStorageAuthDefFree(authdef); return ret; - - error: - virStorageAuthDefFree(ret); - return NULL; } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651078314754.6033995499577; Fri, 8 Feb 2019 10:37:58 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 501B459469; Fri, 8 Feb 2019 18:37:56 +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 0C1C15C240; Fri, 8 Feb 2019 18:37:56 +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 A843418033CB; Fri, 8 Feb 2019 18:37:55 +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 x18IbZoB007541 for ; Fri, 8 Feb 2019 13:37:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6D96D60C55; Fri, 8 Feb 2019 18:37:35 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1561160BE0; Fri, 8 Feb 2019 18:37:34 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:36:57 -0500 Message-Id: <20190208183726.30903-4-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 03/32] util: Introduce VIR_DEFINE_AUTOPTR_FUNC for virStorageAuthDef 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: , 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 08 Feb 2019 18:37:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 26 ++++++++++---------------- src/conf/storage_conf.c | 3 +-- src/qemu/qemu_parse_command.c | 3 +-- src/util/virstoragefile.c | 16 ++++++---------- src/util/virstoragefile.h | 2 ++ 5 files changed, 20 insertions(+), 30 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a33f18c957..2b1389035e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7578,11 +7578,10 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodeP= tr sourcenode, virDomainHostdevSubsysSCSIPtr d= ef, xmlXPathContextPtr ctxt) { - int ret =3D -1; int auth_secret_usage =3D -1; xmlNodePtr cur; - virStorageAuthDefPtr authdef =3D NULL; virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc =3D &def->u.iscsi; + VIR_AUTOPTR(virStorageAuthDef) authdef =3D NULL; =20 /* For the purposes of command line creation, this needs to look * like a disk storage source */ @@ -7594,23 +7593,23 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodeP= tr sourcenode, if (!(iscsisrc->src->path =3D virXMLPropString(sourcenode, "name"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing iSCSI hostdev source path name")); - goto cleanup; + return -1; } =20 if (virDomainStorageNetworkParseHosts(sourcenode, &iscsisrc->src->host= s, &iscsisrc->src->nhosts) < 0) - goto cleanup; + return -1; =20 if (iscsisrc->src->nhosts < 1) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing the host address for the iSCSI hostdev")= ); - goto cleanup; + return -1; } if (iscsisrc->src->nhosts > 1) { virReportError(VIR_ERR_XML_ERROR, "%s", _("only one source host address may be specified " "for the iSCSI hostdev")); - goto cleanup; + return -1; } =20 cur =3D sourcenode->children; @@ -7618,29 +7617,25 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodeP= tr sourcenode, if (cur->type =3D=3D XML_ELEMENT_NODE && virXMLNodeNameEqual(cur, "auth")) { if (!(authdef =3D virStorageAuthDefParse(cur, ctxt))) - goto cleanup; + return -1; if ((auth_secret_usage =3D virSecretUsageTypeFromString(authdef->secrettype)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("invalid secret type %s"), authdef->secrettype); - goto cleanup; + return -1; } if (auth_secret_usage !=3D VIR_SECRET_USAGE_TYPE_ISCSI) { virReportError(VIR_ERR_INTERNAL_ERROR, _("hostdev invalid secret type '%s'"), authdef->secrettype); - goto cleanup; + return -1; } VIR_STEAL_PTR(iscsisrc->src->auth, authdef); } cur =3D cur->next; } - ret =3D 0; - - cleanup: - virStorageAuthDefFree(authdef); - return ret; + return 0; } =20 static int @@ -9683,7 +9678,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, virStorageEncryptionPtr encryption =3D NULL; char *serial =3D NULL; char *startupPolicy =3D NULL; - virStorageAuthDefPtr authdef =3D NULL; char *tray =3D NULL; char *removable =3D NULL; char *logical_block_size =3D NULL; @@ -9692,6 +9686,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, char *vendor =3D NULL; char *product =3D NULL; char *domain_name =3D NULL; + VIR_AUTOPTR(virStorageAuthDef) authdef =3D NULL; =20 if (!(def =3D virDomainDiskDefNew(xmlopt))) return NULL; @@ -10093,7 +10088,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlo= pt, VIR_FREE(target); VIR_FREE(tray); VIR_FREE(removable); - virStorageAuthDefFree(authdef); VIR_FREE(devaddr); VIR_FREE(serial); virStorageEncryptionFree(encryption); diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index fbd62e1305..ead24816bc 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -458,11 +458,11 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, int nsource; size_t i; virStoragePoolOptionsPtr options; - virStorageAuthDefPtr authdef =3D NULL; char *name =3D NULL; char *port =3D NULL; char *ver =3D NULL; int n; + VIR_AUTOPTR(virStorageAuthDef) authdef =3D NULL; =20 relnode =3D ctxt->node; ctxt->node =3D node; @@ -614,7 +614,6 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, =20 VIR_FREE(port); VIR_FREE(nodeset); - virStorageAuthDefFree(authdef); return ret; } =20 diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c index 679d49d442..81691cb85e 100644 --- a/src/qemu/qemu_parse_command.c +++ b/src/qemu/qemu_parse_command.c @@ -59,7 +59,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPt= r uri, char *sock =3D NULL; char *volimg =3D NULL; char *secret =3D NULL; - virStorageAuthDefPtr authdef =3D NULL; + VIR_AUTOPTR(virStorageAuthDef) authdef =3D NULL; =20 if (VIR_ALLOC(def->src->hosts) < 0) goto error; @@ -151,7 +151,6 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURI= Ptr uri, error: virStorageNetHostDefClear(def->src->hosts); VIR_FREE(def->src->hosts); - virStorageAuthDefFree(authdef); goto cleanup; } =20 diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 7fbeea78eb..1eb1ede59d 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1879,25 +1879,23 @@ virStorageAuthDefFree(virStorageAuthDefPtr authdef) virStorageAuthDefPtr virStorageAuthDefCopy(const virStorageAuthDef *src) { - virStorageAuthDefPtr authdef; virStorageAuthDefPtr ret =3D NULL; + VIR_AUTOPTR(virStorageAuthDef) authdef =3D NULL; =20 if (VIR_ALLOC(authdef) < 0) return NULL; =20 if (VIR_STRDUP(authdef->username, src->username) < 0) - goto cleanup; + return NULL; /* Not present for storage pool, but used for disk source */ if (VIR_STRDUP(authdef->secrettype, src->secrettype) < 0) - goto cleanup; + return NULL; authdef->authType =3D src->authType; =20 if (virSecretLookupDefCopy(&authdef->seclookupdef, &src->seclookupdef)= < 0) - goto cleanup; + return NULL; =20 VIR_STEAL_PTR(ret, authdef); - cleanup: - virStorageAuthDefFree(authdef); return ret; } =20 @@ -1907,10 +1905,10 @@ virStorageAuthDefParse(xmlNodePtr node, xmlXPathContextPtr ctxt) { xmlNodePtr saveNode =3D ctxt->node; - virStorageAuthDefPtr authdef =3D NULL; virStorageAuthDefPtr ret =3D NULL; xmlNodePtr secretnode =3D NULL; char *authtype =3D NULL; + VIR_AUTOPTR(virStorageAuthDef) authdef =3D NULL; =20 ctxt->node =3D node; =20 @@ -1958,7 +1956,6 @@ virStorageAuthDefParse(xmlNodePtr node, =20 cleanup: VIR_FREE(authtype); - virStorageAuthDefFree(authdef); ctxt->node =3D saveNode; =20 return ret; @@ -2832,7 +2829,7 @@ virStorageSourceParseRBDColonString(const char *rbdst= r, { char *options =3D NULL; char *p, *e, *next; - virStorageAuthDefPtr authdef =3D NULL; + VIR_AUTOPTR(virStorageAuthDef) authdef =3D NULL; =20 /* optionally skip the "rbd:" prefix if provided */ if (STRPREFIX(rbdstr, "rbd:")) @@ -2935,7 +2932,6 @@ virStorageSourceParseRBDColonString(const char *rbdst= r, =20 error: VIR_FREE(options); - virStorageAuthDefFree(authdef); return -1; } =20 diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index a98d5103fa..eacc927ea6 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -543,4 +543,6 @@ void virStorageFileReportBrokenChain(int errcode, virStorageSourcePtr src, virStorageSourcePtr parent); =20 +VIR_DEFINE_AUTOPTR_FUNC(virStorageAuthDef, virStorageAuthDefFree); + #endif /* LIBVIRT_VIRSTORAGEFILE_H */ --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651077991200.6071166270125; Fri, 8 Feb 2019 10:37:57 -0800 (PST) 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 E348080F7C; Fri, 8 Feb 2019 18:37: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 94C1E611D4; Fri, 8 Feb 2019 18:37:55 +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 3BCFC18033A9; Fri, 8 Feb 2019 18:37:55 +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 x18IbaVK007553 for ; Fri, 8 Feb 2019 13:37:36 -0500 Received: by smtp.corp.redhat.com (Postfix) id F1AC4383F; Fri, 8 Feb 2019 18:37:35 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9818E60BE0; Fri, 8 Feb 2019 18:37:35 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:36:58 -0500 Message-Id: <20190208183726.30903-5-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 04/32] conf: Introduce VIR_DEFINE_AUTOPTR_FUNC for virStoragePoolSource 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: , 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.27]); Fri, 08 Feb 2019 18:37:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/conf/storage_conf.c | 4 ++-- src/conf/storage_conf.h | 2 ++ src/storage/storage_backend_fs.c | 3 +-- src/storage/storage_backend_gluster.c | 3 +-- src/storage/storage_backend_iscsi.c | 3 +-- src/storage/storage_backend_iscsi_direct.c | 3 +-- src/test/test_driver.c | 14 +++++++------- 7 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index ead24816bc..9563d2bc6b 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -625,7 +625,8 @@ virStoragePoolDefParseSourceString(const char *srcSpec, xmlDocPtr doc =3D NULL; xmlNodePtr node =3D NULL; xmlXPathContextPtr xpath_ctxt =3D NULL; - virStoragePoolSourcePtr def =3D NULL, ret =3D NULL; + virStoragePoolSourcePtr ret =3D NULL; + VIR_AUTOPTR(virStoragePoolSource) def =3D NULL; =20 if (!(doc =3D virXMLParseStringCtxt(srcSpec, _("(storage_source_specification)"), @@ -647,7 +648,6 @@ virStoragePoolDefParseSourceString(const char *srcSpec, =20 VIR_STEAL_PTR(ret, def); cleanup: - virStoragePoolSourceFree(def); xmlFreeDoc(doc); xmlXPathFreeContext(xpath_ctxt); =20 diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index 1ba4b80616..3fa97bba76 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -460,4 +460,6 @@ VIR_ENUM_DECL(virStoragePartedFs); VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_AUTOSTART | \ VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_POOL_TYPE) =20 +VIR_DEFINE_AUTOPTR_FUNC(virStoragePoolSource, virStoragePoolSourceFree); + #endif /* LIBVIRT_STORAGE_CONF_H */ diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend= _fs.c index ddb422d874..420601a303 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -145,11 +145,11 @@ virStorageBackendFileSystemNetFindPoolSources(const c= har *srcSpec, .sources =3D NULL } }; - virStoragePoolSourcePtr source =3D NULL; char *ret =3D NULL; size_t i; int retNFS =3D -1; int retGluster =3D 0; + VIR_AUTOPTR(virStoragePoolSource) source =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -196,7 +196,6 @@ virStorageBackendFileSystemNetFindPoolSources(const cha= r *srcSpec, virStoragePoolSourceClear(&state.list.sources[i]); VIR_FREE(state.list.sources); =20 - virStoragePoolSourceFree(source); return ret; } =20 diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_ba= ckend_gluster.c index e09bc54196..559189fd1d 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -489,10 +489,10 @@ virStorageBackendGlusterFindPoolSources(const char *s= rcSpec, .nsources =3D 0, .sources =3D NULL }; - virStoragePoolSourcePtr source =3D NULL; char *ret =3D NULL; int rc; size_t i; + VIR_AUTOPTR(virStoragePoolSource) source =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -532,7 +532,6 @@ virStorageBackendGlusterFindPoolSources(const char *src= Spec, virStoragePoolSourceClear(&list.sources[i]); VIR_FREE(list.sources); =20 - virStoragePoolSourceFree(source); return ret; } =20 diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_back= end_iscsi.c index 4792bd70b8..dc1a983b58 100644 --- a/src/storage/storage_backend_iscsi.c +++ b/src/storage/storage_backend_iscsi.c @@ -158,7 +158,6 @@ static char * virStorageBackendISCSIFindPoolSources(const char *srcSpec, unsigned int flags) { - virStoragePoolSourcePtr source =3D NULL; size_t ntargets =3D 0; char **targets =3D NULL; char *ret =3D NULL; @@ -169,6 +168,7 @@ virStorageBackendISCSIFindPoolSources(const char *srcSp= ec, .sources =3D NULL }; char *portal =3D NULL; + VIR_AUTOPTR(virStoragePoolSource) source =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -227,7 +227,6 @@ virStorageBackendISCSIFindPoolSources(const char *srcSp= ec, VIR_FREE(targets[i]); VIR_FREE(targets); VIR_FREE(portal); - virStoragePoolSourceFree(source); return ret; } =20 diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/stora= ge_backend_iscsi_direct.c index 0babe26550..8d12c1a274 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -486,7 +486,6 @@ static char * virStorageBackendISCSIDirectFindPoolSources(const char *srcSpec, unsigned int flags) { - virStoragePoolSourcePtr source =3D NULL; size_t ntargets =3D 0; char **targets =3D NULL; char *ret =3D NULL; @@ -497,6 +496,7 @@ virStorageBackendISCSIDirectFindPoolSources(const char = *srcSpec, .sources =3D NULL }; char *portal =3D NULL; + VIR_AUTOPTR(virStoragePoolSource) source =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -557,7 +557,6 @@ virStorageBackendISCSIDirectFindPoolSources(const char = *srcSpec, VIR_FREE(targets[i]); VIR_FREE(targets); VIR_FREE(portal); - virStoragePoolSourceFree(source); return ret; } =20 diff --git a/src/test/test_driver.c b/src/test/test_driver.c index b06567855e..de221b4190 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4394,9 +4394,9 @@ testConnectFindStoragePoolSources(virConnectPtr conn = ATTRIBUTE_UNUSED, const char *srcSpec, unsigned int flags) { - virStoragePoolSourcePtr source =3D NULL; int pool_type; char *ret =3D NULL; + VIR_AUTOPTR(virStoragePoolSource) source =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -4404,30 +4404,32 @@ testConnectFindStoragePoolSources(virConnectPtr con= n ATTRIBUTE_UNUSED, if (!pool_type) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown storage pool type %s"), type); - goto cleanup; + return NULL; } =20 if (srcSpec) { source =3D virStoragePoolDefParseSourceString(srcSpec, pool_type); if (!source) - goto cleanup; + return NULL; } =20 switch (pool_type) { =20 case VIR_STORAGE_POOL_LOGICAL: ignore_value(VIR_STRDUP(ret, defaultPoolSourcesLogicalXML)); + return ret; break; =20 case VIR_STORAGE_POOL_NETFS: if (!source || !source->hosts[0].name) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("hostname must be specified for netfs s= ources")); - goto cleanup; + return NULL; } =20 ignore_value(virAsprintf(&ret, defaultPoolSourcesNetFSXML, source->hosts[0].name)); + return ret; break; =20 default: @@ -4435,9 +4437,7 @@ testConnectFindStoragePoolSources(virConnectPtr conn = ATTRIBUTE_UNUSED, _("pool type '%s' does not support source discovery= "), type); } =20 - cleanup: - virStoragePoolSourceFree(source); - return ret; + return NULL; } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 154965108429622.26731103132647; Fri, 8 Feb 2019 10:38:04 -0800 (PST) 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 173414CE8C; Fri, 8 Feb 2019 18:38:02 +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 A845A6012B; Fri, 8 Feb 2019 18:38:01 +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 3CCAD3F606; Fri, 8 Feb 2019 18:38:01 +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 x18Ibamp007560 for ; Fri, 8 Feb 2019 13:37:36 -0500 Received: by smtp.corp.redhat.com (Postfix) id 81A3860C55; Fri, 8 Feb 2019 18:37:36 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28DBC60BE0; Fri, 8 Feb 2019 18:37:36 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:36:59 -0500 Message-Id: <20190208183726.30903-6-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 05/32] storage: Use VIR_STEAL_PTR for gluster volume processing 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: , 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.30]); Fri, 08 Feb 2019 18:38:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_backend_gluster.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_ba= ckend_gluster.c index 559189fd1d..6759d7f1e5 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -278,8 +278,7 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlu= sterStatePtr state, if (S_ISDIR(st->st_mode)) { vol->type =3D VIR_STORAGE_VOL_NETDIR; vol->target.format =3D VIR_STORAGE_FILE_DIR; - *volptr =3D vol; - vol =3D NULL; + VIR_STEAL_PTR(*volptr, vol); ret =3D 0; goto cleanup; } @@ -328,8 +327,7 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlu= sterStatePtr state, vol->target.compat =3D meta->compat; meta->compat =3D NULL; =20 - *volptr =3D vol; - vol =3D NULL; + VIR_STEAL_PTR(*volptr, vol); ret =3D 0; cleanup: virStorageSourceFree(meta); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651084197737.4416209581102; Fri, 8 Feb 2019 10:38:04 -0800 (PST) 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 E426AC06021F; Fri, 8 Feb 2019 18:38:01 +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 9E44C17CF1; Fri, 8 Feb 2019 18:38:01 +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 3E09518033A6; Fri, 8 Feb 2019 18:38:01 +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 x18IbbtI007566 for ; Fri, 8 Feb 2019 13:37:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1373CBA91; Fri, 8 Feb 2019 18:37:37 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id ACA9660BE0; Fri, 8 Feb 2019 18:37:36 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:00 -0500 Message-Id: <20190208183726.30903-7-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 06/32] conf: Rework virStorageVolDefParseXML 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: , 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.32]); Fri, 08 Feb 2019 18:38:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Rather than having an error path, let's rework the code to allocate and fill into an @def variable and then steal that into @ret when we are successful leaving just a cleanup: path. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/conf/storage_conf.c | 113 ++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 57 deletions(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 9563d2bc6b..0ebdbafa0c 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1168,7 +1168,8 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, xmlXPathContextPtr ctxt, unsigned int flags) { - virStorageVolDefPtr ret; + virStorageVolDefPtr def; + virStorageVolDefPtr ret =3D NULL; virStorageVolOptionsPtr options; char *type =3D NULL; char *allocation =3D NULL; @@ -1187,132 +1188,132 @@ virStorageVolDefParseXML(virStoragePoolDefPtr poo= l, if (options =3D=3D NULL) return NULL; =20 - if (VIR_ALLOC(ret) < 0) + if (VIR_ALLOC(def) < 0) return NULL; =20 - ret->target.type =3D VIR_STORAGE_TYPE_FILE; + def->target.type =3D VIR_STORAGE_TYPE_FILE; =20 - ret->name =3D virXPathString("string(./name)", ctxt); - if (ret->name =3D=3D NULL) { + def->name =3D virXPathString("string(./name)", ctxt); + if (def->name =3D=3D NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing volume name element")); - goto error; + goto cleanup; } =20 /* Normally generated by pool refresh, but useful for unit tests */ - ret->key =3D virXPathString("string(./key)", ctxt); + def->key =3D virXPathString("string(./key)", ctxt); =20 /* Technically overridden by pool refresh, but useful for unit tests */ type =3D virXPathString("string(./@type)", ctxt); if (type) { - if ((ret->type =3D virStorageVolTypeFromString(type)) < 0) { + if ((def->type =3D virStorageVolTypeFromString(type)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown volume type '%s'"), type); - goto error; + goto cleanup; } } =20 if ((backingStore =3D virXPathString("string(./backingStore/path)", ct= xt))) { - if (VIR_ALLOC(ret->target.backingStore) < 0) - goto error; + if (VIR_ALLOC(def->target.backingStore) < 0) + goto cleanup; =20 - ret->target.backingStore->type =3D VIR_STORAGE_TYPE_FILE; + def->target.backingStore->type =3D VIR_STORAGE_TYPE_FILE; =20 - ret->target.backingStore->path =3D backingStore; + def->target.backingStore->path =3D backingStore; backingStore =3D NULL; =20 if (options->formatFromString) { char *format =3D virXPathString("string(./backingStore/format/= @type)", ctxt); if (format =3D=3D NULL) - ret->target.backingStore->format =3D options->defaultForma= t; + def->target.backingStore->format =3D options->defaultForma= t; else - ret->target.backingStore->format =3D (options->formatFromS= tring)(format); + def->target.backingStore->format =3D (options->formatFromS= tring)(format); =20 - if (ret->target.backingStore->format < 0) { + if (def->target.backingStore->format < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown volume format type %s"), format); VIR_FREE(format); - goto error; + goto cleanup; } VIR_FREE(format); } =20 - if (VIR_ALLOC(ret->target.backingStore->perms) < 0) - goto error; - if (virStorageDefParsePerms(ctxt, ret->target.backingStore->perms, + if (VIR_ALLOC(def->target.backingStore->perms) < 0) + goto cleanup; + if (virStorageDefParsePerms(ctxt, def->target.backingStore->perms, "./backingStore/permissions") < 0) - goto error; + goto cleanup; } =20 capacity =3D virXPathString("string(./capacity)", ctxt); unit =3D virXPathString("string(./capacity/@unit)", ctxt); if (capacity) { - if (virStorageSize(unit, capacity, &ret->target.capacity) < 0) - goto error; + if (virStorageSize(unit, capacity, &def->target.capacity) < 0) + goto cleanup; } else if (!(flags & VIR_VOL_XML_PARSE_NO_CAPACITY) && !((flags & VIR_VOL_XML_PARSE_OPT_CAPACITY) && - virStorageSourceHasBacking(&ret->target))) { + virStorageSourceHasBacking(&def->target))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing capacity elemen= t")); - goto error; + goto cleanup; } VIR_FREE(unit); =20 allocation =3D virXPathString("string(./allocation)", ctxt); if (allocation) { unit =3D virXPathString("string(./allocation/@unit)", ctxt); - if (virStorageSize(unit, allocation, &ret->target.allocation) < 0) - goto error; - ret->target.has_allocation =3D true; + if (virStorageSize(unit, allocation, &def->target.allocation) < 0) + goto cleanup; + def->target.has_allocation =3D true; } else { - ret->target.allocation =3D ret->target.capacity; + def->target.allocation =3D def->target.capacity; } =20 - ret->target.path =3D virXPathString("string(./target/path)", ctxt); + def->target.path =3D virXPathString("string(./target/path)", ctxt); if (options->formatFromString) { char *format =3D virXPathString("string(./target/format/@type)", c= txt); if (format =3D=3D NULL) - ret->target.format =3D options->defaultFormat; + def->target.format =3D options->defaultFormat; else - ret->target.format =3D (options->formatFromString)(format); + def->target.format =3D (options->formatFromString)(format); =20 - if (ret->target.format < 0) { + if (def->target.format < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown volume format type %s"), format); VIR_FREE(format); - goto error; + goto cleanup; } VIR_FREE(format); } =20 - if (VIR_ALLOC(ret->target.perms) < 0) - goto error; - if (virStorageDefParsePerms(ctxt, ret->target.perms, + if (VIR_ALLOC(def->target.perms) < 0) + goto cleanup; + if (virStorageDefParsePerms(ctxt, def->target.perms, "./target/permissions") < 0) - goto error; + goto cleanup; =20 node =3D virXPathNode("./target/encryption", ctxt); if (node !=3D NULL) { - ret->target.encryption =3D virStorageEncryptionParseNode(node, ctx= t); - if (ret->target.encryption =3D=3D NULL) - goto error; + def->target.encryption =3D virStorageEncryptionParseNode(node, ctx= t); + if (def->target.encryption =3D=3D NULL) + goto cleanup; } =20 - ret->target.compat =3D virXPathString("string(./target/compat)", ctxt); - if (virStorageFileCheckCompat(ret->target.compat) < 0) - goto error; + def->target.compat =3D virXPathString("string(./target/compat)", ctxt); + if (virStorageFileCheckCompat(def->target.compat) < 0) + goto cleanup; =20 if (virXPathNode("./target/nocow", ctxt)) - ret->target.nocow =3D true; + def->target.nocow =3D true; =20 if (virXPathNode("./target/features", ctxt)) { if ((n =3D virXPathNodeSet("./target/features/*", ctxt, &nodes)) <= 0) - goto error; + goto cleanup; =20 - if (!ret->target.compat && VIR_STRDUP(ret->target.compat, "1.1") <= 0) - goto error; + if (!def->target.compat && VIR_STRDUP(def->target.compat, "1.1") <= 0) + goto cleanup; =20 - if (!(ret->target.features =3D virBitmapNew(VIR_STORAGE_FILE_FEATU= RE_LAST))) - goto error; + if (!(def->target.features =3D virBitmapNew(VIR_STORAGE_FILE_FEATU= RE_LAST))) + goto cleanup; =20 for (i =3D 0; i < n; i++) { int f =3D virStorageFileFeatureTypeFromString((const char*)nod= es[i]->name); @@ -1320,14 +1321,17 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, if (f < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unsupported = feature %s"), (const char*)nodes[i]->name); - goto error; + goto cleanup; } - ignore_value(virBitmapSetBit(ret->target.features, f)); + ignore_value(virBitmapSetBit(def->target.features, f)); } VIR_FREE(nodes); } =20 + VIR_STEAL_PTR(ret, def); + cleanup: + virStorageVolDefFree(def); VIR_FREE(nodes); VIR_FREE(allocation); VIR_FREE(capacity); @@ -1335,11 +1339,6 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, VIR_FREE(type); VIR_FREE(backingStore); return ret; - - error: - virStorageVolDefFree(ret); - ret =3D NULL; - goto cleanup; } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651089777197.98071414316246; Fri, 8 Feb 2019 10:38:09 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 56AC9C04D319; Fri, 8 Feb 2019 18:38:07 +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 F0C94106A7BC; Fri, 8 Feb 2019 18:38:06 +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 7B86818033AA; Fri, 8 Feb 2019 18:38:06 +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 x18Ibb3s007574 for ; Fri, 8 Feb 2019 13:37:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id AC619BA53; Fri, 8 Feb 2019 18:37:37 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3CC4860BE0; Fri, 8 Feb 2019 18:37:37 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:01 -0500 Message-Id: <20190208183726.30903-8-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 07/32] conf: Introduce VIR_DEFINE_AUTOPTR_FUNC for virStorageVolDef 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 08 Feb 2019 18:38:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/conf/storage_conf.c | 3 +-- src/conf/storage_conf.h | 1 + src/esx/esx_storage_backend_vmfs.c | 6 ++---- src/phyp/phyp_driver.c | 3 +-- src/storage/storage_backend_gluster.c | 3 +-- src/storage/storage_backend_iscsi_direct.c | 19 +++++++---------- src/storage/storage_backend_mpath.c | 24 ++++++++-------------- src/storage/storage_backend_rbd.c | 9 +++----- src/storage/storage_backend_sheepdog.c | 15 ++++++-------- src/storage/storage_driver.c | 6 ++---- src/storage/storage_util.c | 6 ++---- src/test/test_driver.c | 10 ++++----- src/vbox/vbox_storage.c | 3 +-- tests/storagebackendsheepdogtest.c | 3 +-- tests/storagevolxml2argvtest.c | 5 ++--- tests/storagevolxml2xmltest.c | 3 +-- 16 files changed, 44 insertions(+), 75 deletions(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 0ebdbafa0c..e6accb14c6 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1168,7 +1168,6 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, xmlXPathContextPtr ctxt, unsigned int flags) { - virStorageVolDefPtr def; virStorageVolDefPtr ret =3D NULL; virStorageVolOptionsPtr options; char *type =3D NULL; @@ -1180,6 +1179,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, xmlNodePtr *nodes =3D NULL; size_t i; int n; + VIR_AUTOPTR(virStorageVolDef) def =3D NULL; =20 virCheckFlags(VIR_VOL_XML_PARSE_NO_CAPACITY | VIR_VOL_XML_PARSE_OPT_CAPACITY, NULL); @@ -1331,7 +1331,6 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, VIR_STEAL_PTR(ret, def); =20 cleanup: - virStorageVolDefFree(def); VIR_FREE(nodes); VIR_FREE(allocation); VIR_FREE(capacity); diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index 3fa97bba76..b8e73864c4 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -461,5 +461,6 @@ VIR_ENUM_DECL(virStoragePartedFs); VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_POOL_TYPE) =20 VIR_DEFINE_AUTOPTR_FUNC(virStoragePoolSource, virStoragePoolSourceFree); +VIR_DEFINE_AUTOPTR_FUNC(virStorageVolDef, virStorageVolDefFree); =20 #endif /* LIBVIRT_STORAGE_CONF_H */ diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backe= nd_vmfs.c index 8458d4e95c..6d6bd1a6ce 100644 --- a/src/esx/esx_storage_backend_vmfs.c +++ b/src/esx/esx_storage_backend_vmfs.c @@ -836,7 +836,6 @@ esxStorageVolCreateXML(virStoragePoolPtr pool, virStorageVolPtr volume =3D NULL; esxPrivate *priv =3D pool->conn->privateData; virStoragePoolDef poolDef; - virStorageVolDefPtr def =3D NULL; char *tmp; char *unescapedDatastorePath =3D NULL; char *unescapedDirectoryName =3D NULL; @@ -852,6 +851,7 @@ esxStorageVolCreateXML(virStoragePoolPtr pool, char *taskInfoErrorMessage =3D NULL; char *uuid_string =3D NULL; char *key =3D NULL; + VIR_AUTOPTR(virStorageVolDef) def =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -1024,7 +1024,6 @@ esxStorageVolCreateXML(virStoragePoolPtr pool, virtualDiskSpec->adapterType =3D NULL; } =20 - virStorageVolDefFree(def); VIR_FREE(unescapedDatastorePath); VIR_FREE(unescapedDirectoryName); VIR_FREE(unescapedDirectoryAndFileName); @@ -1054,7 +1053,6 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool, esxPrivate *priv =3D pool->conn->privateData; virStoragePoolDef poolDef; char *sourceDatastorePath =3D NULL; - virStorageVolDefPtr def =3D NULL; char *tmp; char *unescapedDatastorePath =3D NULL; char *unescapedDirectoryName =3D NULL; @@ -1069,6 +1067,7 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool, char *taskInfoErrorMessage =3D NULL; char *uuid_string =3D NULL; char *key =3D NULL; + VIR_AUTOPTR(virStorageVolDef) def =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -1207,7 +1206,6 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool, =20 cleanup: VIR_FREE(sourceDatastorePath); - virStorageVolDefFree(def); VIR_FREE(unescapedDatastorePath); VIR_FREE(unescapedDirectoryName); VIR_FREE(unescapedDirectoryAndFileName); diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 4ffa08ff43..cac5642afd 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1952,11 +1952,11 @@ phypStorageVolCreateXML(virStoragePoolPtr pool, { virCheckFlags(0, NULL); =20 - virStorageVolDefPtr voldef =3D NULL; virStoragePoolDefPtr spdef =3D NULL; virStorageVolPtr vol =3D NULL; virStorageVolPtr dup_vol =3D NULL; char *key =3D NULL; + VIR_AUTOPTR(virStorageVolDef) voldef =3D NULL; =20 if (VIR_ALLOC(spdef) < 0) return NULL; @@ -2036,7 +2036,6 @@ phypStorageVolCreateXML(virStoragePoolPtr pool, =20 err: VIR_FREE(key); - virStorageVolDefFree(voldef); virStoragePoolDefFree(spdef); virObjectUnref(vol); return NULL; diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_ba= ckend_gluster.c index 6759d7f1e5..5428bb92ba 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -242,12 +242,12 @@ virStorageBackendGlusterRefreshVol(virStorageBackendG= lusterStatePtr state, virStorageVolDefPtr *volptr) { int ret =3D -1; - virStorageVolDefPtr vol =3D NULL; glfs_fd_t *fd =3D NULL; virStorageSourcePtr meta =3D NULL; char *header =3D NULL; ssize_t len; int backingFormat; + VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; =20 *volptr =3D NULL; =20 @@ -331,7 +331,6 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlu= sterStatePtr state, ret =3D 0; cleanup: virStorageSourceFree(meta); - virStorageVolDefFree(vol); if (fd) glfs_close(fd); VIR_FREE(header); diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/stora= ge_backend_iscsi_direct.c index 8d12c1a274..42060dd758 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -305,22 +305,21 @@ virISCSIDirectRefreshVol(virStoragePoolObjPtr pool, char *portal) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - virStorageVolDefPtr vol =3D NULL; uint32_t block_size; uint32_t nb_block; - int ret =3D -1; + VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; =20 virStoragePoolObjClearVols(pool); if (virISCSIDirectTestUnitReady(iscsi, lun) < 0) - goto cleanup; + return -1; =20 if (VIR_ALLOC(vol) < 0) - goto cleanup; + return -1; =20 vol->type =3D VIR_STORAGE_VOL_NETWORK; =20 if (virISCSIDirectGetVolumeCapacity(iscsi, lun, &block_size, &nb_block= ) < 0) - goto cleanup; + return -1; =20 vol->target.capacity =3D block_size * nb_block; vol->target.allocation =3D block_size * nb_block; @@ -328,17 +327,13 @@ virISCSIDirectRefreshVol(virStoragePoolObjPtr pool, def->allocation +=3D vol->target.allocation; =20 if (virISCSIDirectSetVolumeAttributes(pool, vol, lun, portal) < 0) - goto cleanup; + return -1; =20 if (virStoragePoolObjAddVol(pool, vol) < 0) - goto cleanup; - + return -1; vol =3D NULL; =20 - ret =3D 0; - cleanup: - virStorageVolDefFree(vol); - return ret; + return 0; } =20 static int diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_back= end_mpath.c index b3a49ee1b2..423f945fbc 100644 --- a/src/storage/storage_backend_mpath.c +++ b/src/storage/storage_backend_mpath.c @@ -46,42 +46,36 @@ virStorageBackendMpathNewVol(virStoragePoolObjPtr pool, const char *dev) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - virStorageVolDefPtr vol; - int ret =3D -1; + VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; =20 if (VIR_ALLOC(vol) < 0) - goto cleanup; + return -1; =20 vol->type =3D VIR_STORAGE_VOL_BLOCK; =20 if (virAsprintf(&(vol->name), "dm-%u", devnum) < 0) - goto cleanup; + return -1; =20 if (virAsprintf(&vol->target.path, "/dev/%s", dev) < 0) - goto cleanup; + return -1; =20 if (virStorageBackendUpdateVolInfo(vol, true, VIR_STORAGE_VOL_OPEN_DEFAULT, 0) < = 0) { - goto cleanup; + return -1; } =20 /* XXX should use logical unit's UUID instead */ if (VIR_STRDUP(vol->key, vol->target.path) < 0) - goto cleanup; + return -1; =20 if (virStoragePoolObjAddVol(pool, vol) < 0) - goto cleanup; + return -1; =20 def->capacity +=3D vol->target.capacity; def->allocation +=3D vol->target.allocation; - ret =3D 0; - - cleanup: + vol =3D NULL; =20 - if (ret !=3D 0) - virStorageVolDefFree(vol); - - return ret; + return 0; } =20 =20 diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backen= d_rbd.c index cfbce1ad19..ece04f0f2d 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -618,7 +618,7 @@ virStorageBackendRBDRefreshPool(virStoragePoolObjPtr po= ol) } =20 for (name =3D names; name < names + max_size;) { - virStorageVolDefPtr vol; + VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; =20 if (STREQ(name, "")) break; @@ -626,10 +626,8 @@ virStorageBackendRBDRefreshPool(virStoragePoolObjPtr p= ool) if (VIR_ALLOC(vol) < 0) goto cleanup; =20 - if (VIR_STRDUP(vol->name, name) < 0) { - VIR_FREE(vol); + if (VIR_STRDUP(vol->name, name) < 0) goto cleanup; - } =20 name +=3D strlen(name) + 1; =20 @@ -648,15 +646,14 @@ virStorageBackendRBDRefreshPool(virStoragePoolObjPtr = pool) if (r =3D=3D -ENOENT || r =3D=3D -ETIMEDOUT) continue; =20 - virStorageVolDefFree(vol); goto cleanup; } =20 if (virStoragePoolObjAddVol(pool, vol) < 0) { - virStorageVolDefFree(vol); virStoragePoolObjClearVols(pool); goto cleanup; } + vol =3D NULL; } =20 VIR_DEBUG("Found %zu images in RBD pool %s", diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_b= ackend_sheepdog.c index b6f424bea1..7cba6e02aa 100644 --- a/src/storage/storage_backend_sheepdog.c +++ b/src/storage/storage_backend_sheepdog.c @@ -110,30 +110,27 @@ virStorageBackendSheepdogAddHostArg(virCommandPtr cmd, static int virStorageBackendSheepdogAddVolume(virStoragePoolObjPtr pool, const char *= diskInfo) { - virStorageVolDefPtr vol =3D NULL; + VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; =20 if (diskInfo =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing disk info when adding volume")); - goto error; + return -1; } =20 if (VIR_ALLOC(vol) < 0 || VIR_STRDUP(vol->name, diskInfo) < 0) - goto error; + return -1; =20 vol->type =3D VIR_STORAGE_VOL_NETWORK; =20 if (virStorageBackendSheepdogRefreshVol(pool, vol) < 0) - goto error; + return -1; =20 if (virStoragePoolObjAddVol(pool, vol) < 0) - goto error; + return -1; + vol =3D NULL; =20 return 0; - - error: - virStorageVolDefFree(vol); - return -1; } =20 static int diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 878a40cac5..c50a8ef5d4 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1820,8 +1820,8 @@ storageVolCreateXML(virStoragePoolPtr pool, virStoragePoolObjPtr obj; virStoragePoolDefPtr def; virStorageBackendPtr backend; - virStorageVolDefPtr voldef =3D NULL; virStorageVolPtr vol =3D NULL, newvol =3D NULL; + VIR_AUTOPTR(virStorageVolDef) voldef =3D NULL; =20 virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL); =20 @@ -1941,7 +1941,6 @@ storageVolCreateXML(virStoragePoolPtr pool, =20 cleanup: virObjectUnref(newvol); - virStorageVolDefFree(voldef); virStoragePoolObjEndAPI(&obj); return vol; } @@ -1957,11 +1956,11 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool, virStoragePoolObjPtr objsrc =3D NULL; virStorageBackendPtr backend; virStorageVolDefPtr voldefsrc =3D NULL; - virStorageVolDefPtr voldef =3D NULL; virStorageVolDefPtr shadowvol =3D NULL; virStorageVolPtr newvol =3D NULL; virStorageVolPtr vol =3D NULL; int buildret; + VIR_AUTOPTR(virStorageVolDef) voldef =3D NULL; =20 virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA | VIR_STORAGE_VOL_CREATE_REFLINK, @@ -2134,7 +2133,6 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool, =20 cleanup: virObjectUnref(newvol); - virStorageVolDefFree(voldef); VIR_FREE(shadowvol); virStoragePoolObjEndAPI(&obj); virStoragePoolObjEndAPI(&objsrc); diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 95e05d950b..1770d21f33 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -3672,10 +3672,10 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr = pool) struct dirent *ent; struct statvfs sb; struct stat statbuf; - virStorageVolDefPtr vol =3D NULL; virStorageSourcePtr target =3D NULL; int direrr; int fd =3D -1, ret =3D -1; + VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; =20 if (virDirOpen(&dir, def->target.path) < 0) goto cleanup; @@ -3767,7 +3767,6 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr po= ol) cleanup: VIR_DIR_CLOSE(dir); VIR_FORCE_CLOSE(fd); - virStorageVolDefFree(vol); virStorageSourceFree(target); if (ret < 0) virStoragePoolObjClearVols(pool); @@ -3816,9 +3815,9 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, const char *dev) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - virStorageVolDefPtr vol =3D NULL; char *devpath =3D NULL; int retval =3D -1; + VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; =20 /* Check if the pool is using a stable target path. The call to * virStorageBackendStablePath will fail if the pool target path @@ -3898,7 +3897,6 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, retval =3D 0; =20 cleanup: - virStorageVolDefFree(vol); VIR_FREE(devpath); return retval; } diff --git a/src/test/test_driver.c b/src/test/test_driver.c index de221b4190..f07a075755 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1025,7 +1025,7 @@ testOpenVolumesForPool(const char *file, size_t i; int num, ret =3D -1; xmlNodePtr *nodes =3D NULL; - virStorageVolDefPtr volDef =3D NULL; + VIR_AUTOPTR(virStorageVolDef) volDef =3D NULL; =20 /* Find storage volumes */ if (virAsprintf(&vol_xpath, "/node/pool[%d]/volume", objidx) < 0) @@ -1064,7 +1064,6 @@ testOpenVolumesForPool(const char *file, =20 ret =3D 0; error: - virStorageVolDefFree(volDef); VIR_FREE(nodes); return ret; } @@ -5053,8 +5052,8 @@ testStorageVolCreateXML(virStoragePoolPtr pool, testDriverPtr privconn =3D pool->conn->privateData; virStoragePoolObjPtr obj; virStoragePoolDefPtr def; - virStorageVolDefPtr privvol =3D NULL; virStorageVolPtr ret =3D NULL; + VIR_AUTOPTR(virStorageVolDef) privvol =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -5098,7 +5097,6 @@ testStorageVolCreateXML(virStoragePoolPtr pool, privvol =3D NULL; =20 cleanup: - virStorageVolDefFree(privvol); virStoragePoolObjEndAPI(&obj); return ret; } @@ -5113,8 +5111,9 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, testDriverPtr privconn =3D pool->conn->privateData; virStoragePoolObjPtr obj; virStoragePoolDefPtr def; - virStorageVolDefPtr privvol =3D NULL, origvol =3D NULL; + virStorageVolDefPtr origvol =3D NULL; virStorageVolPtr ret =3D NULL; + VIR_AUTOPTR(virStorageVolDef) privvol =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -5166,7 +5165,6 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, privvol =3D NULL; =20 cleanup: - virStorageVolDefFree(privvol); virStoragePoolObjEndAPI(&obj); return ret; } diff --git a/src/vbox/vbox_storage.c b/src/vbox/vbox_storage.c index 7047e54084..ae16094dbe 100644 --- a/src/vbox/vbox_storage.c +++ b/src/vbox/vbox_storage.c @@ -401,7 +401,6 @@ vboxStorageVolCreateXML(virStoragePoolPtr pool, const char *xml, unsigned int flags) { vboxDriverPtr data =3D pool->conn->privateData; - virStorageVolDefPtr def =3D NULL; PRUnichar *hddFormatUtf16 =3D NULL; PRUnichar *hddNameUtf16 =3D NULL; virStoragePoolDef poolDef; @@ -415,6 +414,7 @@ vboxStorageVolCreateXML(virStoragePoolPtr pool, PRUint32 variant =3D HardDiskVariant_Standard; resultCodeUnion resultCode; virStorageVolPtr ret =3D NULL; + VIR_AUTOPTR(virStorageVolDef) def =3D NULL; =20 if (!data->vboxObj) return ret; @@ -501,7 +501,6 @@ vboxStorageVolCreateXML(virStoragePoolPtr pool, VBOX_RELEASE(progress); VBOX_UTF16_FREE(hddFormatUtf16); VBOX_UTF16_FREE(hddNameUtf16); - virStorageVolDefFree(def); return ret; } =20 diff --git a/tests/storagebackendsheepdogtest.c b/tests/storagebackendsheep= dogtest.c index 616af22d73..540f89c3ab 100644 --- a/tests/storagebackendsheepdogtest.c +++ b/tests/storagebackendsheepdogtest.c @@ -94,7 +94,7 @@ test_vdi_list_parser(const void *opaque) int ret =3D -1; char *output =3D NULL; virStoragePoolDefPtr pool =3D NULL; - virStorageVolDefPtr vol =3D NULL; + VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; =20 if (!(pool =3D virStoragePoolDefParseFile(data->poolxml))) goto cleanup; @@ -121,7 +121,6 @@ test_vdi_list_parser(const void *opaque) cleanup: VIR_FREE(output); virStoragePoolDefFree(pool); - virStorageVolDefFree(vol); return ret; } =20 diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c index bc2da37410..4c98decc4d 100644 --- a/tests/storagevolxml2argvtest.c +++ b/tests/storagevolxml2argvtest.c @@ -48,10 +48,11 @@ testCompareXMLToArgvFiles(bool shouldFail, =20 virCommandPtr cmd =3D NULL; =20 - virStorageVolDefPtr vol =3D NULL, inputvol =3D NULL; virStoragePoolDefPtr def =3D NULL; virStoragePoolDefPtr inputpool =3D NULL; virStoragePoolObjPtr obj =3D NULL; + VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; + VIR_AUTOPTR(virStorageVolDef) inputvol =3D NULL; =20 if (!(def =3D virStoragePoolDefParseFile(poolxml))) goto cleanup; @@ -139,8 +140,6 @@ testCompareXMLToArgvFiles(bool shouldFail, =20 cleanup: virStoragePoolDefFree(inputpool); - virStorageVolDefFree(vol); - virStorageVolDefFree(inputvol); virCommandFree(cmd); VIR_FREE(actualCmdline); virStoragePoolObjEndAPI(&obj); diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c index 040bbc7585..95e205a0ab 100644 --- a/tests/storagevolxml2xmltest.c +++ b/tests/storagevolxml2xmltest.c @@ -20,7 +20,7 @@ testCompareXMLToXMLFiles(const char *poolxml, const char = *inxml, char *actual =3D NULL; int ret =3D -1; virStoragePoolDefPtr pool =3D NULL; - virStorageVolDefPtr dev =3D NULL; + VIR_AUTOPTR(virStorageVolDef) dev =3D NULL; =20 if (!(pool =3D virStoragePoolDefParseFile(poolxml))) goto fail; @@ -39,7 +39,6 @@ testCompareXMLToXMLFiles(const char *poolxml, const char = *inxml, fail: VIR_FREE(actual); virStoragePoolDefFree(pool); - virStorageVolDefFree(dev); return ret; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651089251265.6736688914291; Fri, 8 Feb 2019 10:38:09 -0800 (PST) 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 53EB988312; Fri, 8 Feb 2019 18:38: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 E3E2F62957; Fri, 8 Feb 2019 18:38:06 +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 7AF4C3F609; Fri, 8 Feb 2019 18:38:06 +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 x18Ibcl4007585 for ; Fri, 8 Feb 2019 13:37:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2611F60C55; Fri, 8 Feb 2019 18:37:38 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id D651860BE0 for ; Fri, 8 Feb 2019 18:37:37 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:02 -0500 Message-Id: <20190208183726.30903-9-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 08/32] conf: Rework virStoragePoolDefParseXML 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: , 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.28]); Fri, 08 Feb 2019 18:38:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Rather than having an error path, let's rework the code to allocate and fill into an @def variable and then steal that into @ret when we are successful leaving just a cleanup: path. Signed-off-by: John Ferlan Reviewed-by: J=C3=A1n Tomko --- src/conf/storage_conf.c | 114 ++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 58 deletions(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index e6accb14c6..4a52b1497b 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -737,159 +737,157 @@ virStoragePoolDefPtr virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) { virStoragePoolOptionsPtr options; - virStoragePoolDefPtr ret; + virStoragePoolDefPtr def; + virStoragePoolDefPtr ret =3D NULL; xmlNodePtr source_node; char *type =3D NULL; char *uuid =3D NULL; char *target_path =3D NULL; =20 - if (VIR_ALLOC(ret) < 0) + if (VIR_ALLOC(def) < 0) return NULL; =20 type =3D virXPathString("string(./@type)", ctxt); if (type =3D=3D NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("storage pool missing type attribute")); - goto error; + goto cleanup; } =20 - if ((ret->type =3D virStoragePoolTypeFromString(type)) < 0) { + if ((def->type =3D virStoragePoolTypeFromString(type)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown storage pool type %s"), type); - goto error; + goto cleanup; } =20 - if ((options =3D virStoragePoolOptionsForPoolType(ret->type)) =3D=3D N= ULL) - goto error; + if ((options =3D virStoragePoolOptionsForPoolType(def->type)) =3D=3D N= ULL) + goto cleanup; =20 source_node =3D virXPathNode("./source", ctxt); if (source_node) { - if (virStoragePoolDefParseSource(ctxt, &ret->source, ret->type, + if (virStoragePoolDefParseSource(ctxt, &def->source, def->type, source_node) < 0) - goto error; + goto cleanup; } else { if (options->formatFromString) - ret->source.format =3D options->defaultFormat; + def->source.format =3D options->defaultFormat; } =20 - ret->name =3D virXPathString("string(./name)", ctxt); - if (ret->name =3D=3D NULL && + def->name =3D virXPathString("string(./name)", ctxt); + if (def->name =3D=3D NULL && options->flags & VIR_STORAGE_POOL_SOURCE_NAME && - VIR_STRDUP(ret->name, ret->source.name) < 0) - goto error; - if (ret->name =3D=3D NULL) { + VIR_STRDUP(def->name, def->source.name) < 0) + goto cleanup; + if (def->name =3D=3D NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing pool source name element")); - goto error; + goto cleanup; } =20 - if (strchr(ret->name, '/')) { + if (strchr(def->name, '/')) { virReportError(VIR_ERR_XML_ERROR, - _("name %s cannot contain '/'"), ret->name); - goto error; + _("name %s cannot contain '/'"), def->name); + goto cleanup; } =20 uuid =3D virXPathString("string(./uuid)", ctxt); if (uuid =3D=3D NULL) { - if (virUUIDGenerate(ret->uuid) < 0) { + if (virUUIDGenerate(def->uuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unable to generate uuid")); - goto error; + goto cleanup; } } else { - if (virUUIDParse(uuid, ret->uuid) < 0) { + if (virUUIDParse(uuid, def->uuid) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("malformed uuid element")); - goto error; + goto cleanup; } } =20 if (options->flags & VIR_STORAGE_POOL_SOURCE_HOST) { - if (!ret->source.nhost) { + if (!def->source.nhost) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing storage pool source host name")); - goto error; + goto cleanup; } } =20 if (options->flags & VIR_STORAGE_POOL_SOURCE_DIR) { - if (!ret->source.dir) { + if (!def->source.dir) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing storage pool source path")); - goto error; + goto cleanup; } } if (options->flags & VIR_STORAGE_POOL_SOURCE_NAME) { - if (ret->source.name =3D=3D NULL) { + if (def->source.name =3D=3D NULL) { /* source name defaults to pool name */ - if (VIR_STRDUP(ret->source.name, ret->name) < 0) - goto error; + if (VIR_STRDUP(def->source.name, def->name) < 0) + goto cleanup; } } =20 if ((options->flags & VIR_STORAGE_POOL_SOURCE_ADAPTER) && - (virStorageAdapterValidate(&ret->source.adapter)) < 0) - goto error; + (virStorageAdapterValidate(&def->source.adapter)) < 0) + goto cleanup; =20 /* If DEVICE is the only source type, then its required */ if (options->flags =3D=3D VIR_STORAGE_POOL_SOURCE_DEVICE) { - if (!ret->source.ndevice) { + if (!def->source.ndevice) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing storage pool source device name")); - goto error; + goto cleanup; } } =20 /* When we are working with a virtual disk we can skip the target * path and permissions */ if (!(options->flags & VIR_STORAGE_POOL_SOURCE_NETWORK)) { - if (ret->type =3D=3D VIR_STORAGE_POOL_LOGICAL) { - if (virAsprintf(&target_path, "/dev/%s", ret->source.name) < 0) - goto error; - } else if (ret->type =3D=3D VIR_STORAGE_POOL_ZFS) { - if (virAsprintf(&target_path, "/dev/zvol/%s", ret->source.name= ) < 0) - goto error; + if (def->type =3D=3D VIR_STORAGE_POOL_LOGICAL) { + if (virAsprintf(&target_path, "/dev/%s", def->source.name) < 0) + goto cleanup; + } else if (def->type =3D=3D VIR_STORAGE_POOL_ZFS) { + if (virAsprintf(&target_path, "/dev/zvol/%s", def->source.name= ) < 0) + goto cleanup; } else { target_path =3D virXPathString("string(./target/path)", ctxt); if (!target_path) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing storage pool target path")); - goto error; + goto cleanup; } } - ret->target.path =3D virFileSanitizePath(target_path); - if (!ret->target.path) - goto error; + def->target.path =3D virFileSanitizePath(target_path); + if (!def->target.path) + goto cleanup; =20 - if (virStorageDefParsePerms(ctxt, &ret->target.perms, + if (virStorageDefParsePerms(ctxt, &def->target.perms, "./target/permissions") < 0) - goto error; + goto cleanup; } =20 - if (ret->type =3D=3D VIR_STORAGE_POOL_ISCSI_DIRECT && - !ret->source.initiator.iqn) { + if (def->type =3D=3D VIR_STORAGE_POOL_ISCSI_DIRECT && + !def->source.initiator.iqn) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("missing initiator IQN")); - goto error; + goto cleanup; } =20 /* Make a copy of all the callback pointers here for easier use, * especially during the virStoragePoolSourceClear method */ - ret->ns =3D options->ns; - if (ret->ns.parse && - (ret->ns.parse)(ctxt, &ret->namespaceData) < 0) - goto error; + def->ns =3D options->ns; + if (def->ns.parse && + (def->ns.parse)(ctxt, &def->namespaceData) < 0) + goto cleanup; =20 + VIR_STEAL_PTR(ret, def); cleanup: + virStoragePoolDefFree(def); VIR_FREE(uuid); VIR_FREE(type); VIR_FREE(target_path); return ret; - - error: - virStoragePoolDefFree(ret); - ret =3D NULL; - goto cleanup; } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 154965109477389.85401856612975; Fri, 8 Feb 2019 10:38:14 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 861D9C0669B5; Fri, 8 Feb 2019 18:38:12 +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 517EB27067; Fri, 8 Feb 2019 18:38:12 +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 E7E653F60D; Fri, 8 Feb 2019 18:38:11 +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 x18IbcUf007591 for ; Fri, 8 Feb 2019 13:37:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id AC95217A65; Fri, 8 Feb 2019 18:37:38 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5192460BE0; Fri, 8 Feb 2019 18:37:38 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:03 -0500 Message-Id: <20190208183726.30903-10-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 09/32] conf: Introduce VIR_DEFINE_AUTOPTR_FUNC for virStoragePoolDef 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 08 Feb 2019 18:38:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 3 +-- src/conf/storage_conf.c | 3 +-- src/conf/storage_conf.h | 1 + src/conf/virstorageobj.c | 27 +++++++++++---------------- src/phyp/phyp_driver.c | 3 +-- src/storage/storage_driver.c | 6 ++---- src/test/test_driver.c | 6 ++---- tests/storagebackendsheepdogtest.c | 6 ++---- tests/storagepoolxml2xmltest.c | 3 +-- tests/storagevolxml2argvtest.c | 3 +-- tests/storagevolxml2xmltest.c | 3 +-- 11 files changed, 24 insertions(+), 40 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2b1389035e..9e46cf721b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30988,12 +30988,12 @@ int virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def) { virConnectPtr conn =3D NULL; - virStoragePoolDefPtr pooldef =3D NULL; virStoragePoolPtr pool =3D NULL; virStorageVolPtr vol =3D NULL; char *poolxml =3D NULL; virStorageVolInfo info; int ret =3D -1; + VIR_AUTOPTR(virStoragePoolDef) pooldef =3D NULL; =20 if (def->src->type !=3D VIR_STORAGE_TYPE_VOLUME) return 0; @@ -31152,7 +31152,6 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPt= r def) virObjectUnref(pool); virObjectUnref(vol); VIR_FREE(poolxml); - virStoragePoolDefFree(pooldef); return ret; } =20 diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 4a52b1497b..177ea63076 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -737,12 +737,12 @@ virStoragePoolDefPtr virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) { virStoragePoolOptionsPtr options; - virStoragePoolDefPtr def; virStoragePoolDefPtr ret =3D NULL; xmlNodePtr source_node; char *type =3D NULL; char *uuid =3D NULL; char *target_path =3D NULL; + VIR_AUTOPTR(virStoragePoolDef) def =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -883,7 +883,6 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) =20 VIR_STEAL_PTR(ret, def); cleanup: - virStoragePoolDefFree(def); VIR_FREE(uuid); VIR_FREE(type); VIR_FREE(target_path); diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index b8e73864c4..daf6f9b68c 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -461,6 +461,7 @@ VIR_ENUM_DECL(virStoragePartedFs); VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_POOL_TYPE) =20 VIR_DEFINE_AUTOPTR_FUNC(virStoragePoolSource, virStoragePoolSourceFree); +VIR_DEFINE_AUTOPTR_FUNC(virStoragePoolDef, virStoragePoolDefFree); VIR_DEFINE_AUTOPTR_FUNC(virStorageVolDef, virStorageVolDefFree); =20 #endif /* LIBVIRT_STORAGE_CONF_H */ diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 7005de3c24..2286857acf 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -1579,8 +1579,8 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools, const char *path, const char *autostartLink) { - virStoragePoolDefPtr def; virStoragePoolObjPtr obj; + VIR_AUTOPTR(virStoragePoolDef) def =3D NULL; =20 if (!(def =3D virStoragePoolDefParseFile(path))) return NULL; @@ -1590,14 +1590,12 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pool= s, _("Storage pool config filename '%s' does " "not match pool name '%s'"), path, def->name); - virStoragePoolDefFree(def); return NULL; } =20 - if (!(obj =3D virStoragePoolObjAssignDef(pools, def, false))) { - virStoragePoolDefFree(def); + if (!(obj =3D virStoragePoolObjAssignDef(pools, def, false))) return NULL; - } + def =3D NULL; =20 VIR_FREE(obj->configFile); /* for driver reload */ if (VIR_STRDUP(obj->configFile, path) < 0) { @@ -1625,39 +1623,40 @@ virStoragePoolObjLoadState(virStoragePoolObjListPtr= pools, const char *name) { char *stateFile =3D NULL; - virStoragePoolDefPtr def =3D NULL; virStoragePoolObjPtr obj =3D NULL; xmlDocPtr xml =3D NULL; xmlXPathContextPtr ctxt =3D NULL; xmlNodePtr node =3D NULL; + VIR_AUTOPTR(virStoragePoolDef) def =3D NULL; =20 if (!(stateFile =3D virFileBuildPath(stateDir, name, ".xml"))) - goto error; + return NULL; =20 if (!(xml =3D virXMLParseCtxt(stateFile, NULL, _("(pool state)"), &ctx= t))) - goto error; + goto cleanup; =20 if (!(node =3D virXPathNode("//pool", ctxt))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not find any 'pool' element in state file"= )); - goto error; + goto cleanup; } =20 ctxt->node =3D node; if (!(def =3D virStoragePoolDefParseXML(ctxt))) - goto error; + goto cleanup; =20 if (STRNEQ(name, def->name)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Storage pool state file '%s' does not match " "pool name '%s'"), stateFile, def->name); - goto error; + goto cleanup; } =20 /* create the object */ if (!(obj =3D virStoragePoolObjAssignDef(pools, def, true))) - goto error; + goto cleanup; + def =3D NULL; =20 /* XXX: future handling of some additional useful status data, * for now, if a status file for a pool exists, the pool will be marked @@ -1671,10 +1670,6 @@ virStoragePoolObjLoadState(virStoragePoolObjListPtr = pools, xmlFreeDoc(xml); xmlXPathFreeContext(ctxt); return obj; - - error: - virStoragePoolDefFree(def); - goto cleanup; } =20 =20 diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index cac5642afd..dc082b1d08 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1952,11 +1952,11 @@ phypStorageVolCreateXML(virStoragePoolPtr pool, { virCheckFlags(0, NULL); =20 - virStoragePoolDefPtr spdef =3D NULL; virStorageVolPtr vol =3D NULL; virStorageVolPtr dup_vol =3D NULL; char *key =3D NULL; VIR_AUTOPTR(virStorageVolDef) voldef =3D NULL; + VIR_AUTOPTR(virStoragePoolDef) spdef =3D NULL; =20 if (VIR_ALLOC(spdef) < 0) return NULL; @@ -2036,7 +2036,6 @@ phypStorageVolCreateXML(virStoragePoolPtr pool, =20 err: VIR_FREE(key); - virStoragePoolDefFree(spdef); virObjectUnref(vol); return NULL; } diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index c50a8ef5d4..c684f44475 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -690,7 +690,6 @@ storagePoolCreateXML(virConnectPtr conn, const char *xml, unsigned int flags) { - virStoragePoolDefPtr newDef; virStoragePoolObjPtr obj =3D NULL; virStoragePoolDefPtr def; virStoragePoolPtr pool =3D NULL; @@ -698,6 +697,7 @@ storagePoolCreateXML(virConnectPtr conn, virObjectEventPtr event =3D NULL; char *stateFile =3D NULL; unsigned int build_flags =3D 0; + VIR_AUTOPTR(virStoragePoolDef) newDef =3D NULL; =20 virCheckFlags(VIR_STORAGE_POOL_CREATE_WITH_BUILD | VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE | @@ -762,7 +762,6 @@ storagePoolCreateXML(virConnectPtr conn, =20 cleanup: VIR_FREE(stateFile); - virStoragePoolDefFree(newDef); virObjectEventStateQueue(driver->storageEventState, event); virStoragePoolObjEndAPI(&obj); return pool; @@ -779,11 +778,11 @@ storagePoolDefineXML(virConnectPtr conn, const char *xml, unsigned int flags) { - virStoragePoolDefPtr newDef; virStoragePoolObjPtr obj =3D NULL; virStoragePoolDefPtr def; virStoragePoolPtr pool =3D NULL; virObjectEventPtr event =3D NULL; + VIR_AUTOPTR(virStoragePoolDef) newDef =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -822,7 +821,6 @@ storagePoolDefineXML(virConnectPtr conn, =20 cleanup: virObjectEventStateQueue(driver->storageEventState, event); - virStoragePoolDefFree(newDef); virStoragePoolObjEndAPI(&obj); return pool; } diff --git a/src/test/test_driver.c b/src/test/test_driver.c index f07a075755..df10a02bbc 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4474,11 +4474,11 @@ testStoragePoolCreateXML(virConnectPtr conn, unsigned int flags) { testDriverPtr privconn =3D conn->privateData; - virStoragePoolDefPtr newDef; virStoragePoolObjPtr obj =3D NULL; virStoragePoolDefPtr def; virStoragePoolPtr pool =3D NULL; virObjectEventPtr event =3D NULL; + VIR_AUTOPTR(virStoragePoolDef) newDef =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -4527,7 +4527,6 @@ testStoragePoolCreateXML(virConnectPtr conn, pool =3D virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); =20 cleanup: - virStoragePoolDefFree(newDef); virObjectEventStateQueue(privconn->eventState, event); virStoragePoolObjEndAPI(&obj); virObjectUnlock(privconn); @@ -4541,11 +4540,11 @@ testStoragePoolDefineXML(virConnectPtr conn, unsigned int flags) { testDriverPtr privconn =3D conn->privateData; - virStoragePoolDefPtr newDef; virStoragePoolObjPtr obj =3D NULL; virStoragePoolDefPtr def; virStoragePoolPtr pool =3D NULL; virObjectEventPtr event =3D NULL; + VIR_AUTOPTR(virStoragePoolDef) newDef =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -4576,7 +4575,6 @@ testStoragePoolDefineXML(virConnectPtr conn, pool =3D virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); =20 cleanup: - virStoragePoolDefFree(newDef); virObjectEventStateQueue(privconn->eventState, event); virStoragePoolObjEndAPI(&obj); virObjectUnlock(privconn); diff --git a/tests/storagebackendsheepdogtest.c b/tests/storagebackendsheep= dogtest.c index 540f89c3ab..03ddf76d65 100644 --- a/tests/storagebackendsheepdogtest.c +++ b/tests/storagebackendsheepdogtest.c @@ -59,7 +59,7 @@ test_node_info_parser(const void *opaque) collie_test test =3D data->data; int ret =3D -1; char *output =3D NULL; - virStoragePoolDefPtr pool =3D NULL; + VIR_AUTOPTR(virStoragePoolDef) pool =3D NULL; =20 if (!(pool =3D virStoragePoolDefParseFile(data->poolxml))) goto cleanup; @@ -82,7 +82,6 @@ test_node_info_parser(const void *opaque) =20 cleanup: VIR_FREE(output); - virStoragePoolDefFree(pool); return ret; } =20 @@ -93,7 +92,7 @@ test_vdi_list_parser(const void *opaque) collie_test test =3D data->data; int ret =3D -1; char *output =3D NULL; - virStoragePoolDefPtr pool =3D NULL; + VIR_AUTOPTR(virStoragePoolDef) pool =3D NULL; VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; =20 if (!(pool =3D virStoragePoolDefParseFile(data->poolxml))) @@ -120,7 +119,6 @@ test_vdi_list_parser(const void *opaque) =20 cleanup: VIR_FREE(output); - virStoragePoolDefFree(pool); return ret; } =20 diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c index acb15f3a2c..c8d5c41cd4 100644 --- a/tests/storagepoolxml2xmltest.c +++ b/tests/storagepoolxml2xmltest.c @@ -20,7 +20,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *o= utxml) { char *actual =3D NULL; int ret =3D -1; - virStoragePoolDefPtr dev =3D NULL; + VIR_AUTOPTR(virStoragePoolDef) dev =3D NULL; =20 if (!(dev =3D virStoragePoolDefParseFile(inxml))) goto fail; @@ -35,7 +35,6 @@ testCompareXMLToXMLFiles(const char *inxml, const char *o= utxml) =20 fail: VIR_FREE(actual); - virStoragePoolDefFree(dev); return ret; } =20 diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c index 4c98decc4d..edff8d8477 100644 --- a/tests/storagevolxml2argvtest.c +++ b/tests/storagevolxml2argvtest.c @@ -49,10 +49,10 @@ testCompareXMLToArgvFiles(bool shouldFail, virCommandPtr cmd =3D NULL; =20 virStoragePoolDefPtr def =3D NULL; - virStoragePoolDefPtr inputpool =3D NULL; virStoragePoolObjPtr obj =3D NULL; VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; VIR_AUTOPTR(virStorageVolDef) inputvol =3D NULL; + VIR_AUTOPTR(virStoragePoolDef) inputpool =3D NULL; =20 if (!(def =3D virStoragePoolDefParseFile(poolxml))) goto cleanup; @@ -139,7 +139,6 @@ testCompareXMLToArgvFiles(bool shouldFail, ret =3D 0; =20 cleanup: - virStoragePoolDefFree(inputpool); virCommandFree(cmd); VIR_FREE(actualCmdline); virStoragePoolObjEndAPI(&obj); diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c index 95e205a0ab..cb78bd5b28 100644 --- a/tests/storagevolxml2xmltest.c +++ b/tests/storagevolxml2xmltest.c @@ -19,7 +19,7 @@ testCompareXMLToXMLFiles(const char *poolxml, const char = *inxml, { char *actual =3D NULL; int ret =3D -1; - virStoragePoolDefPtr pool =3D NULL; + VIR_AUTOPTR(virStoragePoolDef) pool =3D NULL; VIR_AUTOPTR(virStorageVolDef) dev =3D NULL; =20 if (!(pool =3D virStoragePoolDefParseFile(poolxml))) @@ -38,7 +38,6 @@ testCompareXMLToXMLFiles(const char *poolxml, const char = *inxml, =20 fail: VIR_FREE(actual); - virStoragePoolDefFree(pool); return ret; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 154965109420724.852927586919577; Fri, 8 Feb 2019 10:38:14 -0800 (PST) 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 25A7D89AD6; Fri, 8 Feb 2019 18:38:12 +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 DA90E17BBE; Fri, 8 Feb 2019 18:38: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 7D72018033AE; Fri, 8 Feb 2019 18:38:11 +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 x18IbdWi007596 for ; Fri, 8 Feb 2019 13:37:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3BC2D60C55; Fri, 8 Feb 2019 18:37:39 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id D5A8F60BE0; Fri, 8 Feb 2019 18:37:38 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:04 -0500 Message-Id: <20190208183726.30903-11-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 10/32] storage: Use VIR_AUTOPTR(virString) 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: , 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, 08 Feb 2019 18:38:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_backend_iscsi_direct.c | 3 +- src/storage/storage_backend_sheepdog.c | 6 +-- src/storage/storage_backend_zfs.c | 15 ++---- src/util/virstoragefile.c | 58 ++++++++-------------- 4 files changed, 28 insertions(+), 54 deletions(-) diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/stora= ge_backend_iscsi_direct.c index 42060dd758..cf48c29cde 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -411,7 +411,7 @@ virISCSIDirectUpdateTargets(struct iscsi_context *iscsi, struct iscsi_discovery_address *addr; struct iscsi_discovery_address *tmp_addr; size_t tmp_ntargets =3D 0; - char **tmp_targets =3D NULL; + VIR_AUTOPTR(virString) tmp_targets =3D NULL; =20 if (!(addr =3D iscsi_discovery_sync(iscsi))) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -439,7 +439,6 @@ virISCSIDirectUpdateTargets(struct iscsi_context *iscsi, ret =3D 0; cleanup: iscsi_free_discovery_data(iscsi, addr); - virStringListFreeCount(tmp_targets, tmp_ntargets); return ret; } =20 diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_b= ackend_sheepdog.c index 7cba6e02aa..9ab318bb4d 100644 --- a/src/storage/storage_backend_sheepdog.c +++ b/src/storage/storage_backend_sheepdog.c @@ -138,9 +138,9 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePoolOb= jPtr pool) { int ret =3D -1; char *output =3D NULL; - char **lines =3D NULL; - char **cells =3D NULL; size_t i; + VIR_AUTOPTR(virString) lines =3D NULL; + VIR_AUTOPTR(virString) cells =3D NULL; =20 virCommandPtr cmd =3D virCommandNewArgList(SHEEPDOGCLI, "vdi", "list",= "-r", NULL); virStorageBackendSheepdogAddHostArg(cmd, pool); @@ -173,8 +173,6 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePoolOb= jPtr pool) =20 cleanup: virCommandFree(cmd); - virStringListFree(lines); - virStringListFree(cells); VIR_FREE(output); return ret; } diff --git a/src/storage/storage_backend_zfs.c b/src/storage/storage_backen= d_zfs.c index ec39d9403b..4235b48c14 100644 --- a/src/storage/storage_backend_zfs.c +++ b/src/storage/storage_backend_zfs.c @@ -104,13 +104,13 @@ virStorageBackendZFSParseVol(virStoragePoolObjPtr poo= l, const char *volume_string) { int ret =3D -1; - char **tokens; size_t count; - char **name_tokens =3D NULL; char *vol_name; bool is_new_vol =3D false; virStorageVolDefPtr volume =3D NULL; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); + VIR_AUTOPTR(virString) tokens =3D NULL; + VIR_AUTOPTR(virString) name_tokens =3D NULL; =20 if (!(tokens =3D virStringSplitCount(volume_string, "\t", 0, &count))) return -1; @@ -169,8 +169,6 @@ virStorageBackendZFSParseVol(virStoragePoolObjPtr pool, =20 ret =3D 0; cleanup: - virStringListFree(tokens); - virStringListFree(name_tokens); if (is_new_vol) virStorageVolDefFree(volume); return ret; @@ -183,8 +181,8 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr pool, virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); virCommandPtr cmd =3D NULL; char *volumes_list =3D NULL; - char **lines =3D NULL; size_t i; + VIR_AUTOPTR(virString) lines =3D NULL; =20 /** * $ zfs list -Hp -t volume -o name,volsize -r test @@ -221,7 +219,6 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr pool, =20 cleanup: virCommandFree(cmd); - virStringListFree(lines); VIR_FREE(volumes_list); =20 return 0; @@ -233,9 +230,9 @@ virStorageBackendZFSRefreshPool(virStoragePoolObjPtr po= ol ATTRIBUTE_UNUSED) virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); virCommandPtr cmd =3D NULL; char *zpool_props =3D NULL; - char **lines =3D NULL; - char **tokens =3D NULL; size_t i; + VIR_AUTOPTR(virString) lines =3D NULL; + VIR_AUTOPTR(virString) tokens =3D NULL; =20 /** * $ zpool get -Hp health,size,free,allocated test @@ -296,8 +293,6 @@ virStorageBackendZFSRefreshPool(virStoragePoolObjPtr po= ol ATTRIBUTE_UNUSED) =20 cleanup: virCommandFree(cmd); - virStringListFree(lines); - virStringListFree(tokens); VIR_FREE(zpool_props); =20 return 0; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 1eb1ede59d..fc26c2f22e 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1594,11 +1594,10 @@ virStorageFileParseBackingStoreStr(const char *str, char **target, unsigned int *chainIndex) { - char **strings =3D NULL; size_t nstrings; unsigned int idx =3D 0; char *suffix; - int ret =3D -1; + VIR_AUTOPTR(virString) strings =3D NULL; =20 *chainIndex =3D 0; =20 @@ -1608,19 +1607,15 @@ virStorageFileParseBackingStoreStr(const char *str, if (nstrings =3D=3D 2) { if (virStrToLong_uip(strings[1], &suffix, 10, &idx) < 0 || STRNEQ(suffix, "]")) - goto cleanup; + return -1; } =20 if (target && VIR_STRDUP(*target, strings[0]) < 0) - goto cleanup; + return -1; =20 *chainIndex =3D idx; - ret =3D 0; - - cleanup: - virStringListFreeCount(strings, nstrings); - return ret; + return 0; } =20 =20 @@ -2677,8 +2672,8 @@ virStorageSourceParseBackingURI(virStorageSourcePtr s= rc, { virURIPtr uri =3D NULL; const char *path =3D NULL; - char **scheme =3D NULL; int ret =3D -1; + VIR_AUTOPTR(virString) scheme =3D NULL; =20 if (!(uri =3D virURIParse(uristr))) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2772,7 +2767,6 @@ virStorageSourceParseBackingURI(virStorageSourcePtr s= rc, =20 cleanup: virURIFree(uri); - virStringListFree(scheme); return ret; } =20 @@ -2783,7 +2777,7 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src, { char *port; size_t skip; - char **parts; + VIR_AUTOPTR(virString) parts =3D NULL; =20 if (VIR_EXPAND_N(src->hosts, src->nhosts, 1) < 0) return -1; @@ -2808,7 +2802,6 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src, if (!parts) goto error; src->hosts[src->nhosts-1].name =3D virStringListJoin((const char **)pa= rts, ":"); - virStringListFree(parts); if (!src->hosts[src->nhosts-1].name) goto error; =20 @@ -2940,16 +2933,15 @@ static int virStorageSourceParseNBDColonString(const char *nbdstr, virStorageSourcePtr src) { - char **backing =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virString) backing =3D NULL; =20 if (!(backing =3D virStringSplit(nbdstr, ":", 0))) - goto cleanup; + return -1; =20 /* we know that backing[0] now equals to "nbd" */ =20 if (VIR_ALLOC_N(src->hosts, 1) < 0) - goto cleanup; + return -1; =20 src->nhosts =3D 1; src->hosts->transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; @@ -2962,44 +2954,39 @@ virStorageSourceParseNBDColonString(const char *nbd= str, virReportError(VIR_ERR_INTERNAL_ERROR, _("missing remote information in '%s' for protocol = nbd"), nbdstr); - goto cleanup; + return -1; } else if (STREQ(backing[1], "unix")) { if (!backing[2]) { virReportError(VIR_ERR_INTERNAL_ERROR, _("missing unix socket path in nbd backing stri= ng %s"), nbdstr); - goto cleanup; + return -1; } =20 if (VIR_STRDUP(src->hosts->socket, backing[2]) < 0) - goto cleanup; + return -1; =20 } else { if (VIR_STRDUP(src->hosts->name, backing[1]) < 0) - goto cleanup; + return -1; =20 if (!backing[2]) { virReportError(VIR_ERR_INTERNAL_ERROR, _("missing port in nbd string '%s'"), nbdstr); - goto cleanup; + return -1; } =20 if (virStringParsePort(backing[2], &src->hosts->port) < 0) - goto cleanup; + return -1; } =20 if (backing[3] && STRPREFIX(backing[3], "exportname=3D")) { if (VIR_STRDUP(src->path, backing[3] + strlen("exportname=3D")) < = 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - virStringListFree(backing); - - return ret; + return 0; } =20 =20 @@ -4250,9 +4237,8 @@ virStorageFileGetRelativeBackingPath(virStorageSource= Ptr top, int virStorageFileCheckCompat(const char *compat) { - char **version; unsigned int result; - int ret =3D -1; + VIR_AUTOPTR(virString) version =3D NULL; =20 if (!compat) return 0; @@ -4263,13 +4249,9 @@ virStorageFileCheckCompat(const char *compat) virStrToLong_ui(version[1], NULL, 10, &result) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("forbidden characters in 'compat' attribute")); - goto cleanup; + return -1; } - ret =3D 0; - - cleanup: - virStringListFree(version); - return ret; + return 0; } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651105277290.9989986912641; Fri, 8 Feb 2019 10:38:25 -0800 (PST) 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 BA3C6C0C0568; Fri, 8 Feb 2019 18:38:21 +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 6B443BA53; Fri, 8 Feb 2019 18:38:21 +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 12FEF18033B4; Fri, 8 Feb 2019 18:38:21 +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 x18IbdPG007601 for ; Fri, 8 Feb 2019 13:37:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id D8F9317A66; Fri, 8 Feb 2019 18:37:39 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67CF360BE0; Fri, 8 Feb 2019 18:37:39 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:05 -0500 Message-Id: <20190208183726.30903-12-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 11/32] storage: Use VIR_AUTOPTR(virCommand) 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: , 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.32]); Fri, 08 Feb 2019 18:38:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_backend_disk.c | 85 +++++++++------------ src/storage/storage_backend_fs.c | 39 +++------- src/storage/storage_backend_logical.c | 101 +++++++------------------ src/storage/storage_backend_sheepdog.c | 59 ++++++--------- src/storage/storage_backend_vstorage.c | 14 +--- src/storage/storage_backend_zfs.c | 47 +++--------- src/storage/storage_driver.c | 3 +- src/storage/storage_util.c | 34 +++------ src/util/virstoragefile.c | 67 +++++++--------- tests/storagepoolxml2argvtest.c | 7 +- tests/storagevolxml2argvtest.c | 6 +- tests/virstoragetest.c | 6 +- 12 files changed, 156 insertions(+), 312 deletions(-) diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backe= nd_disk.c index 061c494b7d..4fb38178b2 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -356,12 +356,12 @@ virStorageBackendDiskReadPartitions(virStoragePoolObj= Ptr pool, =20 virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); char *parthelper_path; - virCommandPtr cmd; struct virStorageBackendDiskPoolVolData cbdata =3D { .pool =3D pool, .vol =3D vol, }; int ret; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (!(parthelper_path =3D virFileFindResource("libvirt_parthelper", abs_topbuilddir "/src", @@ -392,7 +392,6 @@ virStorageBackendDiskReadPartitions(virStoragePoolObjPt= r pool, 6, virStorageBackendDiskMakeVol, &cbdata); - virCommandFree(cmd); VIR_FREE(parthelper_path); return ret; } @@ -421,8 +420,8 @@ virStorageBackendDiskReadGeometry(virStoragePoolObjPtr = pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); char *parthelper_path; - virCommandPtr cmd; int ret; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (!(parthelper_path =3D virFileFindResource("libvirt_parthelper", abs_topbuilddir "/src", @@ -438,7 +437,6 @@ virStorageBackendDiskReadGeometry(virStoragePoolObjPtr = pool) 3, virStorageBackendDiskMakePoolGeometry, pool); - virCommandFree(cmd); VIR_FREE(parthelper_path); return ret; } @@ -502,51 +500,40 @@ virStorageBackendDiskBuildPool(virStoragePoolObjPtr p= ool, virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); int format =3D def->source.format; const char *fmt; - bool ok_to_mklabel =3D false; - int ret =3D -1; - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 virCheckFlags(VIR_STORAGE_POOL_BUILD_OVERWRITE | - VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, ret); + VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, -1); =20 - VIR_EXCLUSIVE_FLAGS_GOTO(VIR_STORAGE_POOL_BUILD_OVERWRITE, - VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, - error); + VIR_EXCLUSIVE_FLAGS_RET(VIR_STORAGE_POOL_BUILD_OVERWRITE, + VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, + -1); =20 fmt =3D virStoragePoolFormatDiskTypeToString(format); - if (flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) { - ok_to_mklabel =3D true; - } else { - if (virStorageBackendDeviceIsEmpty(def->source.devices[0].path, - fmt, true)) - ok_to_mklabel =3D true; - } + if (!(flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) && + !(virStorageBackendDeviceIsEmpty(def->source.devices[0].path, + fmt, true))) + return -1; =20 - if (ok_to_mklabel) { - if (virStorageBackendZeroPartitionTable(def->source.devices[0].pat= h, - 1024 * 1024) < 0) - goto error; + if (virStorageBackendZeroPartitionTable(def->source.devices[0].path, + 1024 * 1024) < 0) + return -1; =20 - /* eg parted /dev/sda mklabel --script msdos */ - if (format =3D=3D VIR_STORAGE_POOL_DISK_UNKNOWN) - format =3D def->source.format =3D VIR_STORAGE_POOL_DISK_DOS; - if (format =3D=3D VIR_STORAGE_POOL_DISK_DOS) - fmt =3D "msdos"; - else - fmt =3D virStoragePoolFormatDiskTypeToString(format); - - cmd =3D virCommandNewArgList(PARTED, - def->source.devices[0].path, - "mklabel", - "--script", - fmt, - NULL); - ret =3D virCommandRun(cmd, NULL); - } + /* eg parted /dev/sda mklabel --script msdos */ + if (format =3D=3D VIR_STORAGE_POOL_DISK_UNKNOWN) + format =3D def->source.format =3D VIR_STORAGE_POOL_DISK_DOS; + if (format =3D=3D VIR_STORAGE_POOL_DISK_DOS) + fmt =3D "msdos"; + else + fmt =3D virStoragePoolFormatDiskTypeToString(format); =20 - error: - virCommandFree(cmd); - return ret; + cmd =3D virCommandNewArgList(PARTED, + def->source.devices[0].path, + "mklabel", + "--script", + fmt, + NULL); + return virCommandRun(cmd, NULL); } =20 =20 @@ -787,9 +774,9 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr poo= l, virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); char *src_path =3D def->source.devices[0].path; char *srcname =3D last_component(src_path); - virCommandPtr cmd =3D NULL; bool isDevMapperDevice; int rc =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 virCheckFlags(0, -1); =20 @@ -862,7 +849,6 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr poo= l, rc =3D 0; cleanup: VIR_FREE(devpath); - virCommandFree(cmd); return rc; } =20 @@ -876,11 +862,13 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr p= ool, unsigned long long startOffset =3D 0, endOffset =3D 0; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); virErrorPtr save_err; - virCommandPtr cmd =3D virCommandNewArgList(PARTED, - def->source.devices[0].path, - "mkpart", - "--script", - NULL); + VIR_AUTOPTR(virCommand) cmd =3D NULL; + + cmd =3D virCommandNewArgList(PARTED, + def->source.devices[0].path, + "mkpart", + "--script", + NULL); =20 if (vol->target.encryption && vol->target.encryption->format !=3D VIR_STORAGE_ENCRYPTION_FORMAT_= LUKS) { @@ -934,7 +922,6 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr poo= l, =20 cleanup: VIR_FREE(partFormat); - virCommandFree(cmd); return res; =20 error: diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend= _fs.c index 420601a303..0436c25af0 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -95,8 +95,6 @@ virStorageBackendFileSystemNetFindPoolSourcesFunc(char **= const groups, static int virStorageBackendFileSystemNetFindNFSPoolSources(virNetfsDiscoverState *st= ate) { - int ret =3D -1; - /* * # showmount --no-headers -e HOSTNAME * /tmp * @@ -112,7 +110,7 @@ virStorageBackendFileSystemNetFindNFSPoolSources(virNet= fsDiscoverState *state) 1 }; =20 - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNewArgList(SHOWMOUNT, "--no-headers", @@ -120,16 +118,9 @@ virStorageBackendFileSystemNetFindNFSPoolSources(virNe= tfsDiscoverState *state) state->host, NULL); =20 - if (virCommandRunRegex(cmd, 1, regexes, vars, - virStorageBackendFileSystemNetFindPoolSourcesFu= nc, - state, NULL, NULL) < 0) - goto cleanup; - - ret =3D 0; - - cleanup: - virCommandFree(cmd); - return ret; + return virCommandRunRegex(cmd, 1, regexes, vars, + virStorageBackendFileSystemNetFindPoolSource= sFunc, + state, NULL, NULL); } =20 =20 @@ -309,9 +300,9 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr p= ool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); char *src =3D NULL; - virCommandPtr cmd =3D NULL; int ret =3D -1; int rc; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (virStorageBackendFileSystemIsValid(pool) < 0) return -1; @@ -334,7 +325,6 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr p= ool) =20 ret =3D 0; cleanup: - virCommandFree(cmd); VIR_FREE(src); return ret; } @@ -376,9 +366,8 @@ static int virStorageBackendFileSystemStop(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - virCommandPtr cmd =3D NULL; - int ret =3D -1; int rc; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (virStorageBackendFileSystemIsValid(pool) < 0) return -1; @@ -388,13 +377,7 @@ virStorageBackendFileSystemStop(virStoragePoolObjPtr p= ool) return rc; =20 cmd =3D virCommandNewArgList(UMOUNT, def->target.path, NULL); - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; - - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return virCommandRun(cmd, NULL); } #endif /* WITH_STORAGE_FS */ =20 @@ -432,8 +415,7 @@ static int virStorageBackendExecuteMKFS(const char *device, const char *format) { - int ret =3D 0; - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNewArgList(MKFS, "-t", format, NULL); =20 @@ -456,11 +438,10 @@ virStorageBackendExecuteMKFS(const char *device, _("Failed to make filesystem of " "type '%s' on device '%s'"), format, device); - ret =3D -1; + return -1; } =20 - virCommandFree(cmd); - return ret; + return 0; } #else /* #ifdef MKFS */ static int diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_ba= ckend_logical.c index fd95bd0d48..9ebc560a46 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -48,13 +48,11 @@ static int virStorageBackendLogicalSetActive(virStoragePoolObjPtr pool, bool on) { - int ret; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - virCommandPtr cmd =3D virStorageBackendLogicalChangeCmd(VGCHANGE, def,= on); + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 - ret =3D virCommandRun(cmd, NULL); - virCommandFree(cmd); - return ret; + cmd =3D virStorageBackendLogicalChangeCmd(VGCHANGE, def, on); + return virCommandRun(cmd, NULL); } =20 =20 @@ -67,11 +65,11 @@ virStorageBackendLogicalSetActive(virStoragePoolObjPtr = pool, static void virStorageBackendLogicalRemoveDevice(const char *path) { - virCommandPtr cmd =3D virCommandNewArgList(PVREMOVE, path, NULL); + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 + cmd =3D virCommandNewArgList(PVREMOVE, path, NULL); if (virCommandRun(cmd, NULL) < 0) VIR_INFO("Failed to pvremove logical device '%s'", path); - virCommandFree(cmd); } =20 =20 @@ -85,8 +83,7 @@ virStorageBackendLogicalRemoveDevice(const char *path) static int virStorageBackendLogicalInitializeDevice(const char *path) { - int ret =3D -1; - virCommandPtr pvcmd =3D NULL; + VIR_AUTOPTR(virCommand) pvcmd =3D NULL; =20 /* * LVM requires that the first sector is blanked if using @@ -101,15 +98,7 @@ virStorageBackendLogicalInitializeDevice(const char *pa= th) * clever enough todo this for us :-( */ pvcmd =3D virCommandNewArgList(PVCREATE, path, NULL); - if (virCommandRun(pvcmd, NULL) < 0) - goto cleanup; - - ret =3D 0; - - cleanup: - virCommandFree(pvcmd); - - return ret; + return virCommandRun(pvcmd, NULL); } =20 =20 @@ -426,13 +415,12 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr = pool, int vars[] =3D { VIR_STORAGE_VOL_LOGICAL_REGEX_COUNT }; - int ret =3D -1; - virCommandPtr cmd; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); struct virStorageBackendLogicalPoolVolData cbdata =3D { .pool =3D pool, .vol =3D vol, }; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNewArgList(LVS, "--separator", "#", @@ -444,20 +432,9 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr p= ool, "lv_name,origin,uuid,devices,segtype,stripe= s,seg_size,vg_extent_size,size,lv_attr", def->source.name, NULL); - if (virCommandRunRegex(cmd, - 1, - regexes, - vars, - virStorageBackendLogicalMakeVol, - &cbdata, - "lvs", - NULL) < 0) - goto cleanup; - - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return virCommandRunRegex(cmd, 1, regexes, vars, + virStorageBackendLogicalMakeVol, + &cbdata, "lvs", NULL); } =20 static int @@ -550,8 +527,7 @@ virStorageBackendLogicalGetPoolSources(virStoragePoolSo= urceListPtr sourceList) int vars[] =3D { 2 }; - virCommandPtr cmd; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 /* * NOTE: ignoring errors here; this is just to "touch" any logical vol= umes @@ -567,15 +543,9 @@ virStorageBackendLogicalGetPoolSources(virStoragePoolS= ourceListPtr sourceList) "--noheadings", "-o", "pv_name,vg_name", NULL, NULL); - if (virCommandRunRegex(cmd, 1, regexes, vars, - virStorageBackendLogicalFindPoolSourcesFunc, - sourceList, "pvs", NULL) < 0) - goto cleanup; - ret =3D 0; - - cleanup: - virCommandFree(cmd); - return ret; + return virCommandRunRegex(cmd, 1, regexes, vars, + virStorageBackendLogicalFindPoolSourcesFunc, + sourceList, "pvs", NULL); } =20 =20 @@ -737,9 +707,9 @@ virStorageBackendLogicalBuildPool(virStoragePoolObjPtr = pool, unsigned int flags) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - virCommandPtr vgcmd =3D NULL; int ret =3D -1; size_t i =3D 0; + VIR_AUTOPTR(virCommand) vgcmd =3D NULL; =20 virCheckFlags(VIR_STORAGE_POOL_BUILD_OVERWRITE | VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, ret); @@ -773,8 +743,6 @@ virStorageBackendLogicalBuildPool(virStoragePoolObjPtr = pool, ret =3D 0; =20 cleanup: - virCommandFree(vgcmd); - /* On any failure, run through the devices that had pvcreate run in * in order to run pvremove on the device; otherwise, subsequent build * will fail if a pvcreate had been run already. */ @@ -805,8 +773,8 @@ virStorageBackendLogicalRefreshPool(virStoragePoolObjPt= r pool) 2 }; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - virCommandPtr cmd =3D NULL; int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 virWaitForDevices(); =20 @@ -838,7 +806,6 @@ virStorageBackendLogicalRefreshPool(virStoragePoolObjPt= r pool) ret =3D 0; =20 cleanup: - virCommandFree(cmd); if (ret < 0) virStoragePoolObjClearVols(pool); return ret; @@ -863,9 +830,8 @@ virStorageBackendLogicalDeletePool(virStoragePoolObjPtr= pool, unsigned int flags) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - virCommandPtr cmd =3D NULL; size_t i; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 virCheckFlags(0, -1); =20 @@ -874,17 +840,13 @@ virStorageBackendLogicalDeletePool(virStoragePoolObjP= tr pool, "-f", def->source.name, NULL); if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 /* now remove the pv devices and clear them out */ for (i =3D 0; i < def->source.ndevice; i++) virStorageBackendLogicalRemoveDevice(def->source.devices[i].path); =20 - ret =3D 0; - - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -893,10 +855,8 @@ virStorageBackendLogicalDeleteVol(virStoragePoolObjPtr= pool ATTRIBUTE_UNUSED, virStorageVolDefPtr vol, unsigned int flags) { - int ret =3D -1; - - virCommandPtr lvchange_cmd =3D NULL; - virCommandPtr lvremove_cmd =3D NULL; + VIR_AUTOPTR(virCommand) lvchange_cmd =3D NULL; + VIR_AUTOPTR(virCommand) lvremove_cmd =3D NULL; =20 virCheckFlags(0, -1); =20 @@ -907,18 +867,14 @@ virStorageBackendLogicalDeleteVol(virStoragePoolObjPt= r pool ATTRIBUTE_UNUSED, =20 if (virCommandRun(lvremove_cmd, NULL) < 0) { if (virCommandRun(lvchange_cmd, NULL) < 0) { - goto cleanup; + return -1; } else { if (virCommandRun(lvremove_cmd, NULL) < 0) - goto cleanup; + return -1; } } =20 - ret =3D 0; - cleanup: - virCommandFree(lvchange_cmd); - virCommandFree(lvremove_cmd); - return ret; + return 0; } =20 =20 @@ -926,9 +882,8 @@ static int virStorageBackendLogicalLVCreate(virStorageVolDefPtr vol, virStoragePoolDefPtr def) { - int ret; unsigned long long capacity =3D vol->target.capacity; - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (vol->target.encryption && vol->target.encryption->format !=3D VIR_STORAGE_ENCRYPTION_FORMAT_= LUKS) { @@ -961,9 +916,7 @@ virStorageBackendLogicalLVCreate(virStorageVolDefPtr vo= l, else virCommandAddArg(cmd, def->source.name); =20 - ret =3D virCommandRun(cmd, NULL); - virCommandFree(cmd); - return ret; + return virCommandRun(cmd, NULL); } =20 =20 diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_b= ackend_sheepdog.c index 9ab318bb4d..73dcfb2f40 100644 --- a/src/storage/storage_backend_sheepdog.c +++ b/src/storage/storage_backend_sheepdog.c @@ -141,8 +141,9 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePoolOb= jPtr pool) size_t i; VIR_AUTOPTR(virString) lines =3D NULL; VIR_AUTOPTR(virString) cells =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 - virCommandPtr cmd =3D virCommandNewArgList(SHEEPDOGCLI, "vdi", "list",= "-r", NULL); + cmd =3D virCommandNewArgList(SHEEPDOGCLI, "vdi", "list", "-r", NULL); virStorageBackendSheepdogAddHostArg(cmd, pool); virCommandSetOutputBuffer(cmd, &output); if (virCommandRun(cmd, NULL) < 0) @@ -172,7 +173,6 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePoolOb= jPtr pool) ret =3D 0; =20 cleanup: - virCommandFree(cmd); VIR_FREE(output); return ret; } @@ -183,7 +183,7 @@ virStorageBackendSheepdogRefreshPool(virStoragePoolObjP= tr pool) { int ret =3D -1; char *output =3D NULL; - virCommandPtr cmd; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNewArgList(SHEEPDOGCLI, "node", "info", "-r", NULL); virStorageBackendSheepdogAddHostArg(cmd, pool); @@ -197,7 +197,6 @@ virStorageBackendSheepdogRefreshPool(virStoragePoolObjP= tr pool) =20 ret =3D virStorageBackendSheepdogRefreshAllVol(pool); cleanup: - virCommandFree(cmd); VIR_FREE(output); return ret; } @@ -208,14 +207,13 @@ virStorageBackendSheepdogDeleteVol(virStoragePoolObjP= tr pool, virStorageVolDefPtr vol, unsigned int flags) { + VIR_AUTOPTR(virCommand) cmd =3D NULL; + virCheckFlags(0, -1); =20 - virCommandPtr cmd =3D virCommandNewArgList(SHEEPDOGCLI, "vdi", "delete= ", vol->name, NULL); + cmd =3D virCommandNewArgList(SHEEPDOGCLI, "vdi", "delete", vol->name, = NULL); virStorageBackendSheepdogAddHostArg(cmd, pool); - int ret =3D virCommandRun(cmd, NULL); - - virCommandFree(cmd); - return ret; + return virCommandRun(cmd, NULL); } =20 =20 @@ -252,27 +250,20 @@ virStorageBackendSheepdogBuildVol(virStoragePoolObjPt= r pool, virStorageVolDefPtr vol, unsigned int flags) { - int ret =3D -1; - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 virCheckFlags(0, -1); =20 if (!vol->target.capacity) { virReportError(VIR_ERR_NO_SUPPORT, "%s", _("volume capacity required for this pool")); - goto cleanup; + return -1; } =20 cmd =3D virCommandNewArgList(SHEEPDOGCLI, "vdi", "create", vol->name, = NULL); virCommandAddArgFormat(cmd, "%llu", vol->target.capacity); virStorageBackendSheepdogAddHostArg(cmd, pool); - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; - - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return virCommandRun(cmd, NULL); } =20 =20 @@ -341,33 +332,30 @@ static int virStorageBackendSheepdogRefreshVol(virStoragePoolObjPtr pool, virStorageVolDefPtr vol) { - int ret; char *output =3D NULL; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - virCommandPtr cmd =3D virCommandNewArgList(SHEEPDOGCLI, "vdi", "list",= vol->name, "-r", NULL); + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 + cmd =3D virCommandNewArgList(SHEEPDOGCLI, "vdi", "list", vol->name, "-= r", NULL); virStorageBackendSheepdogAddHostArg(cmd, pool); virCommandSetOutputBuffer(cmd, &output); - ret =3D virCommandRun(cmd, NULL); - - if (ret < 0) - goto cleanup; + if (virCommandRun(cmd, NULL) < 0) + return -1; =20 - if ((ret =3D virStorageBackendSheepdogParseVdiList(vol, output)) < 0) - goto cleanup; + if (virStorageBackendSheepdogParseVdiList(vol, output) < 0) + return -1; =20 vol->type =3D VIR_STORAGE_VOL_NETWORK; =20 VIR_FREE(vol->key); if (virAsprintf(&vol->key, "%s/%s", def->source.name, vol->name) < 0) - goto cleanup; + return -1; =20 VIR_FREE(vol->target.path); ignore_value(VIR_STRDUP(vol->target.path, vol->name)); - cleanup: - virCommandFree(cmd); - return ret; + + return 0; } =20 =20 @@ -377,15 +365,14 @@ virStorageBackendSheepdogResizeVol(virStoragePoolObjP= tr pool, unsigned long long capacity, unsigned int flags) { + VIR_AUTOPTR(virCommand) cmd =3D NULL; + virCheckFlags(0, -1); =20 - virCommandPtr cmd =3D virCommandNewArgList(SHEEPDOGCLI, "vdi", "resize= ", vol->name, NULL); + cmd =3D virCommandNewArgList(SHEEPDOGCLI, "vdi", "resize", vol->name, = NULL); virCommandAddArgFormat(cmd, "%llu", capacity); virStorageBackendSheepdogAddHostArg(cmd, pool); - int ret =3D virCommandRun(cmd, NULL); - - virCommandFree(cmd); - return ret; + return virCommandRun(cmd, NULL); } =20 =20 diff --git a/src/storage/storage_backend_vstorage.c b/src/storage/storage_b= ackend_vstorage.c index 0a9abd446b..8c5becd4c4 100644 --- a/src/storage/storage_backend_vstorage.c +++ b/src/storage/storage_backend_vstorage.c @@ -39,10 +39,10 @@ virStorageBackendVzPoolStart(virStoragePoolObjPtr pool) { int ret =3D -1; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - virCommandPtr cmd =3D NULL; char *grp_name =3D NULL; char *usr_name =3D NULL; char *mode =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 /* Check the permissions */ if (def->target.perms.mode =3D=3D (mode_t)-1) @@ -75,7 +75,6 @@ virStorageBackendVzPoolStart(virStoragePoolObjPtr pool) ret =3D 0; =20 cleanup: - virCommandFree(cmd); VIR_FREE(mode); VIR_FREE(grp_name); VIR_FREE(usr_name); @@ -125,22 +124,15 @@ static int virStorageBackendVzPoolStop(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - virCommandPtr cmd =3D NULL; - int ret =3D -1; int rc; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 /* Short-circuit if already unmounted */ if ((rc =3D virStorageBackendVzIsMounted(pool)) !=3D 1) return rc; =20 cmd =3D virCommandNewArgList(UMOUNT, def->target.path, NULL); - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; - - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return virCommandRun(cmd, NULL); } =20 =20 diff --git a/src/storage/storage_backend_zfs.c b/src/storage/storage_backen= d_zfs.c index 4235b48c14..7d1a3dd2cd 100644 --- a/src/storage/storage_backend_zfs.c +++ b/src/storage/storage_backend_zfs.c @@ -51,9 +51,9 @@ VIR_LOG_INIT("storage.storage_backend_zfs"); static int virStorageBackendZFSVolModeNeeded(void) { - virCommandPtr cmd =3D NULL; int ret =3D -1, exit_code =3D -1; char *error =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 /* 'zfs get' without arguments prints out * usage information to stderr, including @@ -77,7 +77,6 @@ virStorageBackendZFSVolModeNeeded(void) ret =3D 0; =20 cleanup: - virCommandFree(cmd); VIR_FREE(error); return ret; } @@ -179,10 +178,10 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr poo= l, virStorageVolDefPtr vol) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - virCommandPtr cmd =3D NULL; char *volumes_list =3D NULL; size_t i; VIR_AUTOPTR(virString) lines =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 /** * $ zfs list -Hp -t volume -o name,volsize -r test @@ -218,7 +217,6 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr pool, } =20 cleanup: - virCommandFree(cmd); VIR_FREE(volumes_list); =20 return 0; @@ -228,9 +226,9 @@ static int virStorageBackendZFSRefreshPool(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - virCommandPtr cmd =3D NULL; char *zpool_props =3D NULL; size_t i; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOPTR(virString) lines =3D NULL; VIR_AUTOPTR(virString) tokens =3D NULL; =20 @@ -292,7 +290,6 @@ virStorageBackendZFSRefreshPool(virStoragePoolObjPtr po= ol ATTRIBUTE_UNUSED) goto cleanup; =20 cleanup: - virCommandFree(cmd); VIR_FREE(zpool_props); =20 return 0; @@ -303,9 +300,9 @@ virStorageBackendZFSCreateVol(virStoragePoolObjPtr pool, virStorageVolDefPtr vol) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - virCommandPtr cmd =3D NULL; int ret =3D -1; int volmode_needed =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (vol->target.encryption !=3D NULL) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -364,7 +361,6 @@ virStorageBackendZFSCreateVol(virStoragePoolObjPtr pool, =20 ret =3D 0; cleanup: - virCommandFree(cmd); return ret; =20 } @@ -374,9 +370,8 @@ virStorageBackendZFSDeleteVol(virStoragePoolObjPtr pool, virStorageVolDefPtr vol, unsigned int flags) { - int ret =3D -1; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - virCommandPtr destroy_cmd =3D NULL; + VIR_AUTOPTR(virCommand) destroy_cmd =3D NULL; =20 virCheckFlags(0, -1); =20 @@ -385,13 +380,7 @@ virStorageBackendZFSDeleteVol(virStoragePoolObjPtr poo= l, virCommandAddArgFormat(destroy_cmd, "%s/%s", def->source.name, vol->name); =20 - if (virCommandRun(destroy_cmd, NULL) < 0) - goto cleanup; - - ret =3D 0; - cleanup: - virCommandFree(destroy_cmd); - return ret; + return virCommandRun(destroy_cmd, NULL); } =20 static int @@ -399,9 +388,8 @@ virStorageBackendZFSBuildPool(virStoragePoolObjPtr pool, unsigned int flags) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - virCommandPtr cmd =3D NULL; size_t i; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 virCheckFlags(0, -1); =20 @@ -417,14 +405,7 @@ virStorageBackendZFSBuildPool(virStoragePoolObjPtr poo= l, for (i =3D 0; i < def->source.ndevice; i++) virCommandAddArg(cmd, def->source.devices[i].path); =20 - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; - - ret =3D 0; - - cleanup: - virCommandFree(cmd); - return ret; + return virCommandRun(cmd, NULL); } =20 static int @@ -432,22 +413,14 @@ virStorageBackendZFSDeletePool(virStoragePoolObjPtr p= ool, unsigned int flags) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - virCommandPtr cmd =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 virCheckFlags(0, -1); =20 cmd =3D virCommandNewArgList(ZPOOL, "destroy", def->source.name, NULL); =20 - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; - - ret =3D 0; - - cleanup: - virCommandFree(cmd); - return ret; + return virCommandRun(cmd, NULL); } =20 virStorageBackend virStorageBackendZFS =3D { diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index c684f44475..a71a16add1 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -2207,9 +2207,9 @@ static int virStorageBackendPloopRestoreDesc(char *path) { int ret =3D -1; - virCommandPtr cmd =3D NULL; char *refresh_tool =3D NULL; char *desc =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (virAsprintf(&desc, "%s/DiskDescriptor.xml", path) < 0) return ret; @@ -2238,7 +2238,6 @@ virStorageBackendPloopRestoreDesc(char *path) =20 cleanup: VIR_FREE(refresh_tool); - virCommandFree(cmd); VIR_FREE(desc); return ret; } diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 1770d21f33..fa364941c5 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -617,9 +617,9 @@ storageBackendCreatePloop(virStoragePoolObjPtr pool ATT= RIBUTE_UNUSED, unsigned int flags) { int ret =3D -1; - virCommandPtr cmd =3D NULL; char *create_tool =3D NULL; bool created =3D false; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 virCheckFlags(0, -1); =20 @@ -677,7 +677,6 @@ storageBackendCreatePloop(virStoragePoolObjPtr pool ATT= RIBUTE_UNUSED, created =3D true; ret =3D virCommandRun(cmd, NULL); cleanup: - virCommandFree(cmd); VIR_FREE(create_tool); if (ret < 0 && created) virFileDeleteTree(vol->target.path); @@ -690,8 +689,8 @@ storagePloopResize(virStorageVolDefPtr vol, unsigned long long capacity) { int ret =3D -1; - virCommandPtr cmd =3D NULL; char *resize_tool =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 resize_tool =3D virFindFileInPath("ploop"); if (!resize_tool) { @@ -705,7 +704,6 @@ storagePloopResize(virStorageVolDefPtr vol, virCommandAddArgFormat(cmd, "%s/DiskDescriptor.xml", vol->target.path); =20 ret =3D virCommandRun(cmd, NULL); - virCommandFree(cmd); VIR_FREE(resize_tool); return ret; } @@ -1319,8 +1317,7 @@ storageBackendDoCreateQemuImg(virStoragePoolObjPtr po= ol, const char *inputSecretPath, virStorageVolEncryptConvertStep convertStep) { - int ret; - virCommandPtr cmd; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virStorageBackendCreateQemuImgCmdFromVol(pool, vol, inputvol, flags, create_tool, @@ -1329,11 +1326,7 @@ storageBackendDoCreateQemuImg(virStoragePoolObjPtr p= ool, if (!cmd) return -1; =20 - ret =3D virStorageBackendCreateExecCommand(pool, vol, cmd); - - virCommandFree(cmd); - - return ret; + return virStorageBackendCreateExecCommand(pool, vol, cmd); } =20 =20 @@ -2324,11 +2317,11 @@ storageBackendResizeQemuImg(virStoragePoolObjPtr po= ol, { int ret =3D -1; char *img_tool =3D NULL; - virCommandPtr cmd =3D NULL; const char *type; char *secretPath =3D NULL; char *secretAlias =3D NULL; virStorageEncryptionPtr enc =3D vol->target.encryption; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (enc && (enc->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMAT_QCOW || enc->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT) = && @@ -2395,7 +2388,6 @@ storageBackendResizeQemuImg(virStoragePoolObjPtr pool, VIR_FREE(secretPath); } VIR_FREE(secretAlias); - virCommandFree(cmd); return ret; } =20 @@ -2449,10 +2441,10 @@ virStorageBackendVolResizeLocal(virStoragePoolObjPt= r pool, static int storageBackendPloopHasSnapshots(char *path) { - virCommandPtr cmd =3D NULL; char *output =3D NULL; char *snap_tool =3D NULL; int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 snap_tool =3D virFindFileInPath("ploop"); if (!snap_tool) { @@ -2477,7 +2469,6 @@ storageBackendPloopHasSnapshots(char *path) =20 cleanup: VIR_FREE(output); - virCommandFree(cmd); return ret; } =20 @@ -2685,7 +2676,7 @@ storageBackendVolWipeLocalFile(const char *path, int ret =3D -1, fd =3D -1; const char *alg_char =3D NULL; struct stat st; - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 fd =3D open(path, O_RDWR); if (fd =3D=3D -1) { @@ -2763,7 +2754,6 @@ storageBackendVolWipeLocalFile(const char *path, } =20 cleanup: - virCommandFree(cmd); VIR_FORCE_CLOSE(fd); return ret; } @@ -2773,10 +2763,10 @@ static int storageBackendVolWipePloop(virStorageVolDefPtr vol, unsigned int algorithm) { - virCommandPtr cmd =3D NULL; char *target_path =3D NULL; char *disk_desc =3D NULL; char *create_tool =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 int ret =3D -1; =20 @@ -2820,7 +2810,6 @@ storageBackendVolWipePloop(virStorageVolDefPtr vol, VIR_FREE(disk_desc); VIR_FREE(target_path); VIR_FREE(create_tool); - virCommandFree(cmd); return ret; } =20 @@ -3034,8 +3023,8 @@ virStorageBackendFindGlusterPoolSources(const char *h= ost, { char *glusterpath =3D NULL; char *outbuf =3D NULL; - virCommandPtr cmd =3D NULL; int rc; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 int ret =3D -1; =20 @@ -3069,7 +3058,6 @@ virStorageBackendFindGlusterPoolSources(const char *h= ost, =20 cleanup: VIR_FREE(outbuf); - virCommandFree(cmd); VIR_FREE(glusterpath); return ret; } @@ -3309,12 +3297,13 @@ virStorageBackendPARTEDFindLabel(const char *device, const char *const args[] =3D { device, "print", "--script", NULL, }; - virCommandPtr cmd =3D virCommandNew(PARTED); char *output =3D NULL; char *error =3D NULL; char *start, *end; int ret =3D VIR_STORAGE_PARTED_ERROR; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 + cmd =3D virCommandNew(PARTED); virCommandAddArgSet(cmd, args); virCommandAddEnvString(cmd, "LC_ALL=3DC"); virCommandSetOutputBuffer(cmd, &output); @@ -3359,7 +3348,6 @@ virStorageBackendPARTEDFindLabel(const char *device, ret =3D VIR_STORAGE_PARTED_DIFFERENT; =20 cleanup: - virCommandFree(cmd); VIR_FREE(output); VIR_FREE(error); return ret; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index fc26c2f22e..828e95d5d3 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1376,13 +1376,14 @@ int virStorageFileGetLVMKey(const char *path, * 06UgP5-2rhb-w3Bo-3mdR-WeoL-pytO-SAa2ky */ int status; - virCommandPtr cmd =3D virCommandNewArgList(LVS, "--noheadings", - "--unbuffered", "--nosuffix", - "--options", "uuid", path, - NULL - ); int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 + cmd =3D virCommandNewArgList(LVS, "--noheadings", + "--unbuffered", "--nosuffix", + "--options", "uuid", path, + NULL + ); *key =3D NULL; =20 /* Run the program and capture its output */ @@ -1417,8 +1418,6 @@ int virStorageFileGetLVMKey(const char *path, if (*key && STREQ(*key, "")) VIR_FREE(*key); =20 - virCommandFree(cmd); - return ret; } #else @@ -1451,20 +1450,20 @@ virStorageFileGetSCSIKey(const char *path, bool ignoreError ATTRIBUTE_UNUSED) { int status; - virCommandPtr cmd =3D virCommandNewArgList("/lib/udev/scsi_id", - "--replace-whitespace", - "--whitelisted", - "--device", path, - NULL - ); - int ret =3D -2; - + VIR_AUTOPTR(virCommand) cmd =3D NULL; + + cmd =3D virCommandNewArgList("/lib/udev/scsi_id", + "--replace-whitespace", + "--whitelisted", + "--device", path, + NULL + ); *key =3D NULL; =20 /* Run the program and capture its output */ virCommandSetOutputBuffer(cmd, key); if (virCommandRun(cmd, &status) < 0) - goto cleanup; + return -2; =20 /* Explicitly check status =3D=3D 0, rather than passing NULL * to virCommandRun because we don't want to raise an actual @@ -1476,15 +1475,10 @@ virStorageFileGetSCSIKey(const char *path, *nl =3D '\0'; } =20 - ret =3D 0; - - cleanup: if (*key && STREQ(*key, "")) VIR_FREE(*key); =20 - virCommandFree(cmd); - - return ret; + return 0; } #else int virStorageFileGetSCSIKey(const char *path, @@ -1521,24 +1515,24 @@ virStorageFileGetNPIVKey(const char *path, char **key) { int status; - VIR_AUTOFREE(char *) outbuf =3D NULL; const char *serial; const char *port; - virCommandPtr cmd =3D virCommandNewArgList("/lib/udev/scsi_id", - "--replace-whitespace", - "--whitelisted", - "--export", - "--device", path, - NULL - ); - int ret =3D -2; - + VIR_AUTOFREE(char *) outbuf =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; + + cmd =3D virCommandNewArgList("/lib/udev/scsi_id", + "--replace-whitespace", + "--whitelisted", + "--export", + "--device", path, + NULL + ); *key =3D NULL; =20 /* Run the program and capture its output */ virCommandSetOutputBuffer(cmd, &outbuf); if (virCommandRun(cmd, &status) < 0) - goto cleanup; + return -2; =20 /* Explicitly check status =3D=3D 0, rather than passing NULL * to virCommandRun because we don't want to raise an actual @@ -1562,12 +1556,7 @@ virStorageFileGetNPIVKey(const char *path, ignore_value(virAsprintf(key, "%s_PORT%s", serial, port)); } =20 - ret =3D 0; - - cleanup: - virCommandFree(cmd); - - return ret; + return 0; } #else int virStorageFileGetNPIVKey(const char *path ATTRIBUTE_UNUSED, diff --git a/tests/storagepoolxml2argvtest.c b/tests/storagepoolxml2argvtes= t.c index e7f42dc0f8..c9ba9b3fde 100644 --- a/tests/storagepoolxml2argvtest.c +++ b/tests/storagepoolxml2argvtest.c @@ -22,12 +22,12 @@ testCompareXMLToArgvFiles(bool shouldFail, const char *poolxml, const char *cmdline) { - VIR_AUTOFREE(char *) actualCmdline =3D NULL; - VIR_AUTOFREE(char *) src =3D NULL; int ret =3D -1; - virCommandPtr cmd =3D NULL; virStoragePoolDefPtr def =3D NULL; virStoragePoolObjPtr pool =3D NULL; + VIR_AUTOFREE(char *) actualCmdline =3D NULL; + VIR_AUTOFREE(char *) src =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (!(def =3D virStoragePoolDefParseFile(poolxml))) goto cleanup; @@ -83,7 +83,6 @@ testCompareXMLToArgvFiles(bool shouldFail, ret =3D 0; =20 cleanup: - virCommandFree(cmd); VIR_FREE(actualCmdline); virStoragePoolObjEndAPI(&pool); if (shouldFail) { diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c index edff8d8477..d4ac02b31d 100644 --- a/tests/storagevolxml2argvtest.c +++ b/tests/storagevolxml2argvtest.c @@ -45,14 +45,12 @@ testCompareXMLToArgvFiles(bool shouldFail, char *actualCmdline =3D NULL; virStorageVolEncryptConvertStep convertStep =3D VIR_STORAGE_VOL_ENCRYP= T_NONE; int ret =3D -1; - - virCommandPtr cmd =3D NULL; - virStoragePoolDefPtr def =3D NULL; virStoragePoolObjPtr obj =3D NULL; VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; VIR_AUTOPTR(virStorageVolDef) inputvol =3D NULL; VIR_AUTOPTR(virStoragePoolDef) inputpool =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (!(def =3D virStoragePoolDefParseFile(poolxml))) goto cleanup; @@ -90,6 +88,7 @@ testCompareXMLToArgvFiles(bool shouldFail, convertStep =3D VIR_STORAGE_VOL_ENCRYPT_CREATE; =20 do { + virCommandFree(cmd); cmd =3D virStorageBackendCreateQemuImgCmdFromVol(obj, vol, inputvol, flags, create_tool, @@ -139,7 +138,6 @@ testCompareXMLToArgvFiles(bool shouldFail, ret =3D 0; =20 cleanup: - virCommandFree(cmd); VIR_FREE(actualCmdline); virStoragePoolObjEndAPI(&obj); return ret; diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index c7c40b16f8..7272df7e33 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -128,9 +128,9 @@ static int testPrepImages(void) { int ret =3D EXIT_FAILURE; - virCommandPtr cmd =3D NULL; char *buf =3D NULL; bool compat =3D false; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 qemuimg =3D virFindFileInPath("qemu-img"); if (!qemuimg) @@ -246,7 +246,6 @@ testPrepImages(void) ret =3D 0; cleanup: VIR_FREE(buf); - virCommandFree(cmd); if (ret) testCleanupImages(); return ret; @@ -713,7 +712,6 @@ static int mymain(void) { int ret; - virCommandPtr cmd =3D NULL; struct testChainData data; struct testLookupData data2; struct testPathCanonicalizeData data3; @@ -722,6 +720,7 @@ mymain(void) virStorageSourcePtr chain =3D NULL; virStorageSourcePtr chain2; /* short for chain->backingStore */ virStorageSourcePtr chain3; /* short for chain2->backingStore */ + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (storageRegisterAll() < 0) return EXIT_FAILURE; @@ -1604,7 +1603,6 @@ mymain(void) /* Final cleanup */ virStorageSourceFree(chain); testCleanupImages(); - virCommandFree(cmd); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651099821169.68919994593637; Fri, 8 Feb 2019 10:38:19 -0800 (PST) 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 92FF0C067C2F; Fri, 8 Feb 2019 18:38:17 +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 2D39760BE0; Fri, 8 Feb 2019 18:38:17 +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 CE70918033AF; Fri, 8 Feb 2019 18:38:16 +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 x18IbeJW007609 for ; Fri, 8 Feb 2019 13:37:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 686164250; Fri, 8 Feb 2019 18:37:40 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F09960BE0 for ; Fri, 8 Feb 2019 18:37:39 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:06 -0500 Message-Id: <20190208183726.30903-13-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 12/32] storage: Use VIR_AUTOFREE for storage backends 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: , 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.32]); Fri, 08 Feb 2019 18:38:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities. This also allows for the cleanup of some goto paths. Signed-off-by: John Ferlan Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_backend.c | 9 +-- src/storage/storage_backend_disk.c | 62 ++++++----------- src/storage/storage_backend_fs.c | 17 ++--- src/storage/storage_backend_gluster.c | 30 +++----- src/storage/storage_backend_iscsi.c | 73 +++++++------------- src/storage/storage_backend_iscsi_direct.c | 36 ++++------ src/storage/storage_backend_logical.c | 35 +++------- src/storage/storage_backend_mpath.c | 18 ++--- src/storage/storage_backend_rbd.c | 35 +++------- src/storage/storage_backend_scsi.c | 79 ++++++++-------------- src/storage/storage_backend_sheepdog.c | 27 +++----- src/storage/storage_backend_vstorage.c | 25 +++---- src/storage/storage_backend_zfs.c | 15 ++-- src/storage/storage_file_gluster.c | 16 ++--- 14 files changed, 158 insertions(+), 319 deletions(-) diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index a54c338cf0..5c8275e978 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -87,8 +87,7 @@ virStorageDriverLoadBackendModule(const char *name, const char *regfunc, bool forceload) { - char *modfile =3D NULL; - int ret; + VIR_AUTOFREE(char *) modfile =3D NULL; =20 if (!(modfile =3D virFileFindResourceFull(name, "libvirt_storage_backend_", @@ -98,11 +97,7 @@ virStorageDriverLoadBackendModule(const char *name, "LIBVIRT_STORAGE_BACKEND_DIR")= )) return -1; =20 - ret =3D virModuleLoad(modfile, regfunc, forceload); - - VIR_FREE(modfile); - - return ret; + return virModuleLoad(modfile, regfunc, forceload); } =20 =20 diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backe= nd_disk.c index 4fb38178b2..4103f2d039 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -56,8 +56,9 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr poo= l, virStorageVolDefPtr vol) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *tmp, *devpath, *partname; + char *tmp, *partname; bool addVol =3D false; + VIR_AUTOFREE(char *) devpath =3D NULL; =20 /* Prepended path will be same for all partitions, so we can * strip the path to form a reasonable pool-unique name @@ -89,7 +90,6 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr poo= l, * way of doing this... */ vol->target.path =3D virStorageBackendStablePath(pool, devpath, tr= ue); - VIR_FREE(devpath); if (vol->target.path =3D=3D NULL) goto error; } @@ -355,12 +355,11 @@ virStorageBackendDiskReadPartitions(virStoragePoolObj= Ptr pool, */ =20 virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *parthelper_path; struct virStorageBackendDiskPoolVolData cbdata =3D { .pool =3D pool, .vol =3D vol, }; - int ret; + VIR_AUTOFREE(char *) parthelper_path =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (!(parthelper_path =3D virFileFindResource("libvirt_parthelper", @@ -388,12 +387,7 @@ virStorageBackendDiskReadPartitions(virStoragePoolObjP= tr pool, def->allocation =3D 0; def->capacity =3D def->available =3D 0; =20 - ret =3D virCommandRunNul(cmd, - 6, - virStorageBackendDiskMakeVol, - &cbdata); - VIR_FREE(parthelper_path); - return ret; + return virCommandRunNul(cmd, 6, virStorageBackendDiskMakeVol, &cbdata); } =20 static int @@ -419,8 +413,7 @@ static int virStorageBackendDiskReadGeometry(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *parthelper_path; - int ret; + VIR_AUTOFREE(char *) parthelper_path =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (!(parthelper_path =3D virFileFindResource("libvirt_parthelper", @@ -433,12 +426,8 @@ virStorageBackendDiskReadGeometry(virStoragePoolObjPtr= pool) "-g", NULL); =20 - ret =3D virCommandRunNul(cmd, - 3, - virStorageBackendDiskMakePoolGeometry, - pool); - VIR_FREE(parthelper_path); - return ret; + return virCommandRunNul(cmd, 3, virStorageBackendDiskMakePoolGeometry, + pool); } =20 static int @@ -769,13 +758,12 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr p= ool, unsigned int flags) { char *part_num =3D NULL; - char *devpath =3D NULL; char *dev_name; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); char *src_path =3D def->source.devices[0].path; char *srcname =3D last_component(src_path); bool isDevMapperDevice; - int rc =3D -1; + VIR_AUTOFREE(char *) devpath =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 virCheckFlags(0, -1); @@ -799,7 +787,7 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr poo= l, virReportSystemError(errno, _("Couldn't read volume target path '%s'"= ), vol->target.path); - goto cleanup; + return -1; } dev_name =3D last_component(devpath); } @@ -810,7 +798,7 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr poo= l, virReportError(VIR_ERR_INTERNAL_ERROR, _("Volume path '%s' did not start with parent " "pool source device name."), dev_name); - goto cleanup; + return -1; } =20 part_num =3D dev_name + strlen(srcname); @@ -824,7 +812,7 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr poo= l, virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse partition number from target " "'%s'"), dev_name); - goto cleanup; + return -1; } =20 /* eg parted /dev/sda rm 2 or /dev/mapper/mpathc rm 2 */ @@ -835,7 +823,7 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr poo= l, part_num, NULL); if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 /* Refreshing the pool is the easiest option as LOGICAL and EXTENDED * partition allocation/capacity management is handled within @@ -844,12 +832,9 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr po= ol, */ virStoragePoolObjClearVols(pool); if (virStorageBackendDiskRefreshPool(pool) < 0) - goto cleanup; + return -1; =20 - rc =3D 0; - cleanup: - VIR_FREE(devpath); - return rc; + return 0; } =20 =20 @@ -857,11 +842,10 @@ static int virStorageBackendDiskCreateVol(virStoragePoolObjPtr pool, virStorageVolDefPtr vol) { - int res =3D -1; - char *partFormat =3D NULL; unsigned long long startOffset =3D 0, endOffset =3D 0; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); virErrorPtr save_err; + VIR_AUTOFREE(char *)partFormat =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNewArgList(PARTED, @@ -874,11 +858,11 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr p= ool, vol->target.encryption->format !=3D VIR_STORAGE_ENCRYPTION_FORMAT_= LUKS) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("storage pool only supports LUKS encrypted volume= s")); - goto cleanup; + return -1; } =20 if (virStorageBackendDiskPartFormat(pool, vol, &partFormat) !=3D 0) - goto cleanup; + return -1; virCommandAddArg(cmd, partFormat); =20 /* If we're going to encrypt using LUKS, then we could need up to @@ -888,13 +872,13 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr p= ool, =20 if (virStorageBackendDiskPartBoundaries(pool, &startOffset, &endOffset, vol->target.capacity) < 0) - goto cleanup; + return -1; =20 virCommandAddArgFormat(cmd, "%lluB", startOffset); virCommandAddArgFormat(cmd, "%lluB", endOffset); =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 /* wait for device node to show up */ virWaitForDevices(); @@ -918,11 +902,7 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr po= ol, goto error; } =20 - res =3D 0; - - cleanup: - VIR_FREE(partFormat); - return res; + return 0; =20 error: /* Best effort to remove the partition. Ignore any errors @@ -932,7 +912,7 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr poo= l, ignore_value(virStorageBackendDiskDeleteVol(pool, vol, 0)); virSetError(save_err); virFreeError(save_err); - goto cleanup; + return -1; } =20 =20 diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend= _fs.c index 0436c25af0..97148acebe 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -246,11 +246,11 @@ virStorageBackendFileSystemIsMounted(virStoragePoolOb= jPtr pool) { int ret =3D -1; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *src =3D NULL; FILE *mtab; struct mntent ent; char buf[1024]; int rc1, rc2; + VIR_AUTOFREE(char *) src =3D NULL; =20 if ((mtab =3D fopen(_PATH_MOUNTED, "r")) =3D=3D NULL) { virReportSystemError(errno, @@ -282,7 +282,6 @@ virStorageBackendFileSystemIsMounted(virStoragePoolObjP= tr pool) =20 cleanup: VIR_FORCE_FCLOSE(mtab); - VIR_FREE(src); return ret; } =20 @@ -299,9 +298,8 @@ static int virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *src =3D NULL; - int ret =3D -1; int rc; + VIR_AUTOFREE(char *) src =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (virStorageBackendFileSystemIsValid(pool) < 0) @@ -320,13 +318,7 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr = pool) return -1; =20 cmd =3D virStorageBackendFileSystemMountCmd(MOUNT, def, src); - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; - - ret =3D 0; - cleanup: - VIR_FREE(src); - return ret; + return virCommandRun(cmd, NULL); } =20 =20 @@ -579,10 +571,10 @@ virStoragePoolDefFSNamespaceParse(xmlXPathContextPtr = ctxt, void **data) { virStoragePoolFSMountOptionsDefPtr cmdopts =3D NULL; - xmlNodePtr *nodes =3D NULL; int nnodes; size_t i; int ret =3D -1; + VIR_AUTOFREE(xmlNodePtr *)nodes =3D NULL; =20 if (xmlXPathRegisterNs(ctxt, BAD_CAST "fs", BAD_CAST STORAGE_POOL_FS_NAMESPACE_HREF) < 0) { @@ -617,7 +609,6 @@ virStoragePoolDefFSNamespaceParse(xmlXPathContextPtr ct= xt, ret =3D 0; =20 cleanup: - VIR_FREE(nodes); virStoragePoolDefFSNamespaceFree(cmdopts); return ret; } diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_ba= ckend_gluster.c index 5428bb92ba..1888314d95 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -127,11 +127,9 @@ virStorageBackendGlusterOpen(virStoragePoolObjPtr pool) if (glfs_set_volfile_server(ret->vol, "tcp", ret->uri->server, ret->uri->port) < 0 || glfs_init(ret->vol) < 0) { - char *uri =3D virURIFormat(ret->uri); - - virReportSystemError(errno, _("failed to connect to %s"), - NULLSTR(uri)); - VIR_FREE(uri); + VIR_AUTOFREE(char *) uri =3D NULL; + uri =3D virURIFormat(ret->uri); + virReportSystemError(errno, _("failed to connect to %s"), NULLSTR(= uri)); goto error; } =20 @@ -187,9 +185,8 @@ virStorageBackendGlusterSetMetadata(virStorageBackendGl= usterStatePtr state, virStorageVolDefPtr vol, const char *name) { - int ret =3D -1; - char *path =3D NULL; char *tmp; + VIR_AUTOFREE(char *) path =3D NULL; =20 VIR_FREE(vol->key); VIR_FREE(vol->target.path); @@ -200,35 +197,31 @@ virStorageBackendGlusterSetMetadata(virStorageBackend= GlusterStatePtr state, if (name) { VIR_FREE(vol->name); if (VIR_STRDUP(vol->name, name) < 0) - goto cleanup; + return -1; } =20 if (virAsprintf(&path, "%s%s%s", state->volname, state->dir, vol->name) < 0) - goto cleanup; + return -1; =20 tmp =3D state->uri->path; if (virAsprintf(&state->uri->path, "/%s", path) < 0) { state->uri->path =3D tmp; - goto cleanup; + return -1; } if (!(vol->target.path =3D virURIFormat(state->uri))) { VIR_FREE(state->uri->path); state->uri->path =3D tmp; - goto cleanup; + return -1; } VIR_FREE(state->uri->path); state->uri->path =3D tmp; =20 /* the path is unique enough to serve as a volume key */ if (VIR_STRDUP(vol->key, vol->target.path) < 0) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(path); - return ret; + return 0; } =20 =20 @@ -244,10 +237,10 @@ virStorageBackendGlusterRefreshVol(virStorageBackendG= lusterStatePtr state, int ret =3D -1; glfs_fd_t *fd =3D NULL; virStorageSourcePtr meta =3D NULL; - char *header =3D NULL; ssize_t len; int backingFormat; VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; + VIR_AUTOFREE(char *) header =3D NULL; =20 *volptr =3D NULL; =20 @@ -333,7 +326,6 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlu= sterStatePtr state, virStorageSourceFree(meta); if (fd) glfs_close(fd); - VIR_FREE(header); return ret; } =20 diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_back= end_iscsi.c index dc1a983b58..9314427cda 100644 --- a/src/storage/storage_backend_iscsi.c +++ b/src/storage/storage_backend_iscsi.c @@ -130,27 +130,20 @@ static int virStorageBackendISCSIFindLUs(virStoragePoolObjPtr pool, const char *session) { - char *sysfs_path; - int retval =3D -1; uint32_t host; + VIR_AUTOFREE(char *) sysfs_path =3D NULL; =20 if (virAsprintf(&sysfs_path, "/sys/class/iscsi_session/session%s/device", session) = < 0) - goto cleanup; + return -1; =20 if (virStorageBackendISCSIGetHostNumber(sysfs_path, &host) < 0) - goto cleanup; + return -1; =20 if (virStorageBackendSCSIFindLUs(pool, host) < 0) - goto cleanup; - - retval =3D 0; - - cleanup: - - VIR_FREE(sysfs_path); + return -1; =20 - return retval; + return 0; } =20 =20 @@ -167,7 +160,7 @@ virStorageBackendISCSIFindPoolSources(const char *srcSp= ec, .nsources =3D 0, .sources =3D NULL }; - char *portal =3D NULL; + VIR_AUTOFREE(char *) portal =3D NULL; VIR_AUTOPTR(virStoragePoolSource) source =3D NULL; =20 virCheckFlags(0, NULL); @@ -223,10 +216,10 @@ virStorageBackendISCSIFindPoolSources(const char *src= Spec, } VIR_FREE(list.sources); } + /* NB: Not virString -like, managed by VIR_APPEND_ELEMENT */ for (i =3D 0; i < ntargets; i++) VIR_FREE(targets[i]); VIR_FREE(targets); - VIR_FREE(portal); return ret; } =20 @@ -235,8 +228,8 @@ virStorageBackendISCSICheckPool(virStoragePoolObjPtr po= ol, bool *isActive) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *session =3D NULL; int ret =3D -1; + VIR_AUTOFREE(char *) session =3D NULL; =20 *isActive =3D false; =20 @@ -259,10 +252,8 @@ virStorageBackendISCSICheckPool(virStoragePoolObjPtr p= ool, return -1; } =20 - if ((session =3D virStorageBackendISCSISession(pool, true)) !=3D NULL)= { + if ((session =3D virStorageBackendISCSISession(pool, true))) *isActive =3D true; - VIR_FREE(session); - } ret =3D 0; =20 return ret; @@ -330,9 +321,8 @@ static int virStorageBackendISCSIStartPool(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *portal =3D NULL; - char *session =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) portal =3D NULL; + VIR_AUTOFREE(char *) session =3D NULL; =20 if (def->source.nhost !=3D 1) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -355,50 +345,40 @@ virStorageBackendISCSIStartPool(virStoragePoolObjPtr = pool) =20 if ((session =3D virStorageBackendISCSISession(pool, true)) =3D=3D NUL= L) { if ((portal =3D virStorageBackendISCSIPortal(&def->source)) =3D=3D= NULL) - goto cleanup; + return -1; =20 /* Create a static node record for the IQN target. Must be done * in order for login to the target */ if (virISCSINodeNew(portal, def->source.devices[0].path) < 0) - goto cleanup; + return -1; =20 if (virStorageBackendISCSISetAuth(portal, &def->source) < 0) - goto cleanup; + return -1; =20 if (virISCSIConnectionLogin(portal, def->source.initiator.iqn, def->source.devices[0].path) < 0) - goto cleanup; + return -1; } - ret =3D 0; - - cleanup: - VIR_FREE(portal); - VIR_FREE(session); - return ret; + return 0; } =20 static int virStorageBackendISCSIRefreshPool(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *session =3D NULL; + VIR_AUTOFREE(char *) session =3D NULL; =20 def->allocation =3D def->capacity =3D def->available =3D 0; =20 if ((session =3D virStorageBackendISCSISession(pool, false)) =3D=3D NU= LL) - goto cleanup; + return -1; if (virISCSIRescanLUNs(session) < 0) - goto cleanup; + return -1; if (virStorageBackendISCSIFindLUs(pool, session) < 0) - goto cleanup; - VIR_FREE(session); + return -1; =20 return 0; - - cleanup: - VIR_FREE(session); - return -1; } =20 =20 @@ -406,13 +386,11 @@ static int virStorageBackendISCSIStopPool(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *portal; - char *session; - int ret =3D -1; + VIR_AUTOFREE(char *) portal =3D NULL; + VIR_AUTOFREE(char *) session =3D NULL; =20 if ((session =3D virStorageBackendISCSISession(pool, true)) =3D=3D NUL= L) return 0; - VIR_FREE(session); =20 if ((portal =3D virStorageBackendISCSIPortal(&def->source)) =3D=3D NUL= L) return -1; @@ -420,12 +398,9 @@ virStorageBackendISCSIStopPool(virStoragePoolObjPtr po= ol) if (virISCSIConnectionLogout(portal, def->source.initiator.iqn, def->source.devices[0].path) < 0) - goto cleanup; - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(portal); - return ret; + return 0; } =20 virStorageBackend virStorageBackendISCSI =3D { diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/stora= ge_backend_iscsi_direct.c index cf48c29cde..464732f7ab 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -421,15 +421,13 @@ virISCSIDirectUpdateTargets(struct iscsi_context *isc= si, } =20 for (tmp_addr =3D addr; tmp_addr; tmp_addr =3D tmp_addr->next) { - char *target =3D NULL; + VIR_AUTOFREE(char *) target =3D NULL; =20 if (VIR_STRDUP(target, tmp_addr->target_name) < 0) goto cleanup; =20 - if (VIR_APPEND_ELEMENT(tmp_targets, tmp_ntargets, target) < 0) { - VIR_FREE(target); + if (VIR_APPEND_ELEMENT(tmp_targets, tmp_ntargets, target) < 0) goto cleanup; - } } =20 VIR_STEAL_PTR(*targets, tmp_targets); @@ -489,7 +487,7 @@ virStorageBackendISCSIDirectFindPoolSources(const char = *srcSpec, .nsources =3D 0, .sources =3D NULL }; - char *portal =3D NULL; + VIR_AUTOFREE(char *) portal =3D NULL; VIR_AUTOPTR(virStoragePoolSource) source =3D NULL; =20 virCheckFlags(0, NULL); @@ -550,7 +548,6 @@ virStorageBackendISCSIDirectFindPoolSources(const char = *srcSpec, for (i =3D 0; i < ntargets; i++) VIR_FREE(targets[i]); VIR_FREE(targets); - VIR_FREE(portal); return ret; } =20 @@ -560,7 +557,7 @@ virStorageBackendISCSIDirectSetConnection(virStoragePoo= lObjPtr pool, { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); struct iscsi_context *iscsi =3D NULL; - char *portal =3D NULL; + VIR_AUTOFREE(char *) portal =3D NULL; =20 if (!(iscsi =3D virISCSIDirectCreateContext(def->source.initiator.iqn)= )) goto error; @@ -577,7 +574,6 @@ virStorageBackendISCSIDirectSetConnection(virStoragePoo= lObjPtr pool, VIR_STEAL_PTR(*portalRet, portal); =20 cleanup: - VIR_FREE(portal); return iscsi; =20 error: @@ -590,19 +586,14 @@ static int virStorageBackendISCSIDirectRefreshPool(virStoragePoolObjPtr pool) { struct iscsi_context *iscsi =3D NULL; - char *portal =3D NULL; int ret =3D -1; - if (!(iscsi =3D virStorageBackendISCSIDirectSetConnection(pool, &porta= l))) - goto cleanup; - if (virISCSIDirectReportLuns(pool, iscsi, portal) < 0) - goto disconect; + VIR_AUTOFREE(char *) portal =3D NULL; =20 - ret =3D 0; - disconect: + if (!(iscsi =3D virStorageBackendISCSIDirectSetConnection(pool, &porta= l))) + return -1; + ret =3D virISCSIDirectReportLuns(pool, iscsi, portal); virISCSIDirectDisconnect(iscsi); iscsi_destroy_context(iscsi); - cleanup: - VIR_FREE(portal); return ret; } =20 @@ -638,7 +629,7 @@ virStorageBackendISCSIDirectVolWipeZero(virStorageVolDe= fPtr vol, struct scsi_task *task =3D NULL; int lun =3D 0; int ret =3D -1; - unsigned char *data; + VIR_AUTOFREE(unsigned char *) data =3D NULL; =20 if (virStorageBackendISCSIDirectGetLun(vol, &lun) < 0) return ret; @@ -655,22 +646,19 @@ virStorageBackendISCSIDirectVolWipeZero(virStorageVol= DefPtr vol, if (!(task =3D iscsi_write10_sync(iscsi, lun, lba, data, block_size * BLOCK_PER_PACKET, block_size, 0, 0, 0, 0, 0))) - goto cleanup; + return -1; scsi_free_scsi_task(task); lba +=3D BLOCK_PER_PACKET; } else { if (!(task =3D iscsi_write10_sync(iscsi, lun, lba, data, block= _size, block_size, 0, 0, 0, 0, 0))) - goto cleanup; + return -1; scsi_free_scsi_task(task); lba++; } } =20 - ret =3D 0; - cleanup: - VIR_FREE(data); - return ret; + return 0; } =20 static int diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_ba= ckend_logical.c index 9ebc560a46..c61d03519f 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -117,14 +117,14 @@ virStorageBackendLogicalParseVolExtents(virStorageVol= DefPtr vol, { int nextents, ret =3D -1; const char *regex_unit =3D "(\\S+)\\((\\S+)\\)"; - char *regex =3D NULL; - regex_t *reg =3D NULL; - regmatch_t *vars =3D NULL; char *p =3D NULL; size_t i; int err, nvars; unsigned long long offset, size, length; virStorageVolSourceExtent extent; + VIR_AUTOFREE(char *) regex =3D NULL; + VIR_AUTOFREE(regex_t *) reg =3D NULL; + VIR_AUTOFREE(regmatch_t *) vars =3D NULL; =20 memset(&extent, 0, sizeof(extent)); =20 @@ -202,7 +202,7 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDe= fPtr vol, for (i =3D 0; i < nextents; i++) { size_t j; int len; - char *offset_str =3D NULL; + VIR_AUTOFREE(char *) offset_str =3D NULL; =20 j =3D (i * 2) + 1; len =3D vars[j].rm_eo - vars[j].rm_so; @@ -219,10 +219,8 @@ virStorageBackendLogicalParseVolExtents(virStorageVolD= efPtr vol, if (virStrToLong_ull(offset_str, NULL, 10, &offset) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed volume extent offset value")); - VIR_FREE(offset_str); goto cleanup; } - VIR_FREE(offset_str); extent.start =3D offset * size; extent.end =3D (offset * size) + length; =20 @@ -234,9 +232,6 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDe= fPtr vol, ret =3D 0; =20 cleanup: - VIR_FREE(regex); - VIR_FREE(reg); - VIR_FREE(vars); VIR_FREE(extent.path); return ret; } @@ -459,15 +454,15 @@ virStorageBackendLogicalFindPoolSourcesFunc(char **co= nst groups, void *data) { virStoragePoolSourceListPtr sourceList =3D data; - char *pvname =3D NULL; - char *vgname =3D NULL; size_t i; virStoragePoolSourceDevicePtr dev; virStoragePoolSource *thisSource; + VIR_AUTOFREE(char *) pvname =3D NULL; + VIR_AUTOFREE(char *) vgname =3D NULL; =20 if (VIR_STRDUP(pvname, groups[0]) < 0 || VIR_STRDUP(vgname, groups[1]) < 0) - goto error; + return -1; =20 thisSource =3D NULL; for (i =3D 0; i < sourceList->nsources; i++) { @@ -479,30 +474,22 @@ virStorageBackendLogicalFindPoolSourcesFunc(char **co= nst groups, =20 if (thisSource =3D=3D NULL) { if (!(thisSource =3D virStoragePoolSourceListNewSource(sourceList)= )) - goto error; + return -1; =20 - thisSource->name =3D vgname; + VIR_STEAL_PTR(thisSource->name, vgname); } - else - VIR_FREE(vgname); =20 if (VIR_REALLOC_N(thisSource->devices, thisSource->ndevice + 1) !=3D 0) - goto error; + return -1; =20 dev =3D &thisSource->devices[thisSource->ndevice]; thisSource->ndevice++; thisSource->format =3D VIR_STORAGE_POOL_LOGICAL_LVM2; =20 memset(dev, 0, sizeof(*dev)); - dev->path =3D pvname; + VIR_STEAL_PTR(dev->path, pvname); =20 return 0; - - error: - VIR_FREE(pvname); - VIR_FREE(vgname); - - return -1; } =20 /* diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_back= end_mpath.c index 423f945fbc..b78eb726b2 100644 --- a/src/storage/storage_backend_mpath.c +++ b/src/storage/storage_backend_mpath.c @@ -153,33 +153,32 @@ static int virStorageBackendCreateVols(virStoragePoolObjPtr pool, struct dm_names *names) { - int retval =3D -1, is_mpath =3D 0; - char *map_device =3D NULL; + int is_mpath =3D 0; uint32_t minor =3D -1; uint32_t next; + VIR_AUTOFREE(char *) map_device =3D NULL; =20 do { is_mpath =3D virStorageBackendIsMultipath(names->name); =20 if (is_mpath < 0) - goto out; + return -1; =20 if (is_mpath =3D=3D 1) { =20 if (virAsprintf(&map_device, "mapper/%s", names->name) < 0) - goto out; + return -1; =20 if (virStorageBackendGetMinorNumber(names->name, &minor) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to get %s minor number"), names->name); - goto out; + return -1; } =20 if (virStorageBackendMpathNewVol(pool, minor, map_device) < 0) - goto out; + return -1; =20 - VIR_FREE(map_device); } =20 /* Given the way libdevmapper returns its data, I don't see @@ -191,10 +190,7 @@ virStorageBackendCreateVols(virStoragePoolObjPtr pool, =20 } while (next); =20 - retval =3D 0; - out: - VIR_FREE(map_device); - return retval; + return 0; } =20 =20 diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backen= d_rbd.c index ece04f0f2d..2b7af1db23 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -86,10 +86,10 @@ virStoragePoolDefRBDNamespaceParse(xmlXPathContextPtr c= txt, void **data) { virStoragePoolRBDConfigOptionsDefPtr cmdopts =3D NULL; - xmlNodePtr *nodes =3D NULL; int nnodes; size_t i; int ret =3D -1; + VIR_AUTOFREE(xmlNodePtr *)nodes =3D NULL; =20 if (xmlXPathRegisterNs(ctxt, BAD_CAST "rbd", BAD_CAST STORAGE_POOL_RBD_NAMESPACE_HREF) < 0) { @@ -145,7 +145,6 @@ virStoragePoolDefRBDNamespaceParse(xmlXPathContextPtr c= txt, ret =3D 0; =20 cleanup: - VIR_FREE(nodes); virStoragePoolDefRBDNamespaceFree(cmdopts); return ret; } @@ -213,12 +212,12 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRB= DStatePtr ptr, char *rados_key =3D NULL; virBuffer mon_host =3D VIR_BUFFER_INITIALIZER; size_t i; - char *mon_buff =3D NULL; const char *client_mount_timeout =3D "30"; const char *mon_op_timeout =3D "30"; const char *osd_op_timeout =3D "30"; const char *rbd_default_format =3D "2"; virConnectPtr conn =3D NULL; + VIR_AUTOFREE(char *) mon_buff =3D NULL; =20 if (authdef) { VIR_DEBUG("Using cephx authorization, username: %s", authdef->user= name); @@ -348,7 +347,6 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDS= tatePtr ptr, =20 virObjectUnref(conn); virBufferFreeAndReset(&mon_host); - VIR_FREE(mon_buff); return ret; } =20 @@ -574,11 +572,12 @@ virStorageBackendRBDRefreshPool(virStoragePoolObjPtr = pool) int ret =3D -1; int len =3D -1; int r =3D 0; - char *name, *names =3D NULL; + char *name; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); virStorageBackendRBDStatePtr ptr =3D NULL; struct rados_cluster_stat_t clusterstat; struct rados_pool_stat_t poolstat; + VIR_AUTOFREE(char *) names =3D NULL; =20 if (!(ptr =3D virStorageBackendRBDNewState(pool))) goto cleanup; @@ -662,7 +661,6 @@ virStorageBackendRBDRefreshPool(virStoragePoolObjPtr po= ol) ret =3D 0; =20 cleanup: - VIR_FREE(names); virStorageBackendRBDFreeState(&ptr); return ret; } @@ -677,8 +675,8 @@ virStorageBackendRBDCleanupSnapshots(rados_ioctx_t ioct= x, int max_snaps =3D 128; int snap_count, protected; size_t i; - rbd_snap_info_t *snaps =3D NULL; rbd_image_t image =3D NULL; + VIR_AUTOFREE(rbd_snap_info_t *) snaps =3D NULL; =20 if ((r =3D rbd_open(ioctx, vol->name, &image, NULL)) < 0) { virReportSystemError(-r, _("failed to open the RBD image '%s'"), @@ -737,8 +735,6 @@ virStorageBackendRBDCleanupSnapshots(rados_ioctx_t ioct= x, if (snaps) rbd_snap_list_end(snaps); =20 - VIR_FREE(snaps); - if (image) rbd_close(image); =20 @@ -949,8 +945,8 @@ virStorageBackendRBDSnapshotFindNoDiff(rbd_image_t imag= e, int max_snaps =3D 128; size_t i; int diff; - rbd_snap_info_t *snaps =3D NULL; rbd_image_info_t info; + VIR_AUTOFREE(rbd_snap_info_t *) snaps =3D NULL; =20 if ((r =3D rbd_stat(image, &info, sizeof(info))) < 0) { virReportSystemError(-r, _("failed to stat the RBD image %s"), @@ -1023,8 +1019,6 @@ virStorageBackendRBDSnapshotFindNoDiff(rbd_image_t im= age, if (snaps) rbd_snap_list_end(snaps); =20 - VIR_FREE(snaps); - return ret; } =20 @@ -1098,8 +1092,8 @@ virStorageBackendRBDCloneImage(rados_ioctx_t io, uint64_t stripe_count; uint64_t stripe_unit; virBuffer snapname =3D VIR_BUFFER_INITIALIZER; - char *snapname_buff =3D NULL; rbd_image_t image =3D NULL; + VIR_AUTOFREE(char *) snapname_buff =3D NULL; =20 if ((r =3D rbd_open(io, origvol, &image, NULL)) < 0) { virReportSystemError(-r, _("failed to open the RBD image %s"), @@ -1170,7 +1164,6 @@ virStorageBackendRBDCloneImage(rados_ioctx_t io, =20 cleanup: virBufferFreeAndReset(&snapname); - VIR_FREE(snapname_buff); =20 if (image) rbd_close(image); @@ -1271,13 +1264,12 @@ virStorageBackendRBDVolWipeZero(rbd_image_t image, uint64_t stripe_count) { int r =3D -1; - int ret =3D -1; unsigned long long offset =3D 0; unsigned long long length; - char *writebuf; + VIR_AUTOFREE(char *) writebuf =3D NULL; =20 if (VIR_ALLOC_N(writebuf, info->obj_size * stripe_count) < 0) - goto cleanup; + return -1; =20 while (offset < info->size) { length =3D MIN((info->size - offset), (info->obj_size * stripe_cou= nt)); @@ -1286,7 +1278,7 @@ virStorageBackendRBDVolWipeZero(rbd_image_t image, virReportSystemError(-r, _("writing %llu bytes failed on " "RBD image %s at offset %llu"), length, imgname, offset); - goto cleanup; + return -1; } =20 VIR_DEBUG("Wrote %llu bytes to RBD image %s at offset %llu", @@ -1295,12 +1287,7 @@ virStorageBackendRBDVolWipeZero(rbd_image_t image, offset +=3D length; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(writebuf); - - return ret; + return 0; } =20 static int diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backe= nd_scsi.c index 14f01f9ec0..7460349c81 100644 --- a/src/storage/storage_backend_scsi.c +++ b/src/storage/storage_backend_scsi.c @@ -56,16 +56,14 @@ static int virStorageBackendSCSITriggerRescan(uint32_t host) { int fd =3D -1; - int retval =3D 0; - char *path; + int retval =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; =20 VIR_DEBUG("Triggering rescan of host %d", host); =20 if (virAsprintf(&path, "%s/host%u/scan", - LINUX_SYSFS_SCSI_HOST_PREFIX, host) < 0) { - retval =3D -1; - goto out; - } + LINUX_SYSFS_SCSI_HOST_PREFIX, host) < 0) + return -1; =20 VIR_DEBUG("Scan trigger path is '%s'", path); =20 @@ -75,8 +73,7 @@ virStorageBackendSCSITriggerRescan(uint32_t host) virReportSystemError(errno, _("Could not open '%s' to trigger host scan"), path); - retval =3D -1; - goto free_path; + goto cleanup; } =20 if (safewrite(fd, @@ -86,13 +83,12 @@ virStorageBackendSCSITriggerRescan(uint32_t host) virReportSystemError(errno, _("Write to '%s' to trigger host scan failed"= ), path); - retval =3D -1; } =20 + retval =3D 0; + + cleanup: VIR_FORCE_CLOSE(fd); - free_path: - VIR_FREE(path); - out: VIR_DEBUG("Rescan of host %d complete", host); return retval; } @@ -178,7 +174,6 @@ static char * getAdapterName(virStorageAdapterPtr adapter) { char *name =3D NULL; - char *parentaddr =3D NULL; =20 if (adapter->type =3D=3D VIR_STORAGE_ADAPTER_TYPE_SCSI_HOST) { virStorageAdapterSCSIHostPtr scsi_host =3D &adapter->data.scsi_hos= t; @@ -192,7 +187,7 @@ getAdapterName(virStorageAdapterPtr adapter) addr->slot, addr->function, unique_id))) - goto cleanup; + return NULL; } else { ignore_value(VIR_STRDUP(name, scsi_host->name)); } @@ -206,8 +201,6 @@ getAdapterName(virStorageAdapterPtr adapter) } } =20 - cleanup: - VIR_FREE(parentaddr); return name; } =20 @@ -248,10 +241,10 @@ checkParent(const char *name, const char *parent_name) { unsigned int host_num; - char *scsi_host_name =3D NULL; - char *vhba_parent =3D NULL; bool retval =3D false; virConnectPtr conn =3D NULL; + VIR_AUTOFREE(char *) scsi_host_name =3D NULL; + VIR_AUTOFREE(char *) vhba_parent =3D NULL; =20 VIR_DEBUG("name=3D%s, parent_name=3D%s", name, parent_name); =20 @@ -291,8 +284,6 @@ checkParent(const char *name, =20 cleanup: virObjectUnref(conn); - VIR_FREE(vhba_parent); - VIR_FREE(scsi_host_name); return retval; } =20 @@ -302,10 +293,9 @@ createVport(virStoragePoolDefPtr def, const char *configFile, virStorageAdapterFCHostPtr fchost) { - char *name =3D NULL; virStoragePoolFCRefreshInfoPtr cbdata =3D NULL; virThread thread; - int ret =3D -1; + VIR_AUTOFREE(char *) name =3D NULL; =20 VIR_DEBUG("configFile=3D'%s' parent=3D'%s', wwnn=3D'%s' wwpn=3D'%s'", NULLSTR(configFile), NULLSTR(fchost->parent), @@ -317,14 +307,14 @@ createVport(virStoragePoolDefPtr def, */ if ((name =3D virVHBAGetHostByWWN(NULL, fchost->wwnn, fchost->wwpn))) { if (!(checkName(name))) - goto cleanup; + return -1; =20 /* If a parent was provided, let's make sure the 'name' we've * retrieved has the same parent. If not this will cause failure. = */ if (!fchost->parent || checkParent(name, fchost->parent)) - ret =3D 0; + return 0; =20 - goto cleanup; + return -1; } =20 /* Since we're creating the vHBA, then we need to manage removing it @@ -336,12 +326,12 @@ createVport(virStoragePoolDefPtr def, fchost->managed =3D VIR_TRISTATE_BOOL_YES; if (configFile) { if (virStoragePoolSaveConfig(configFile, def) < 0) - goto cleanup; + return -1; } } =20 if (!(name =3D virNodeDeviceCreateVport(fchost))) - goto cleanup; + return -1; =20 /* Creating our own VPORT didn't leave enough time to find any LUN's, * so, let's create a thread whose job it is to call the FindLU's with @@ -360,11 +350,7 @@ createVport(virStoragePoolDefPtr def, } } =20 - ret =3D 0; - - cleanup: - VIR_FREE(name); - return ret; + return 0; } =20 =20 @@ -373,10 +359,9 @@ virStorageBackendSCSICheckPool(virStoragePoolObjPtr po= ol, bool *isActive) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *path =3D NULL; - char *name =3D NULL; unsigned int host; - int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) name =3D NULL; =20 *isActive =3D false; =20 @@ -394,28 +379,23 @@ virStorageBackendSCSICheckPool(virStoragePoolObjPtr p= ool, } =20 if (virSCSIHostGetNumber(name, &host) < 0) - goto cleanup; + return -1; =20 if (virAsprintf(&path, "%s/host%d", LINUX_SYSFS_SCSI_HOST_PREFIX, host) < 0) - goto cleanup; + return -1; =20 *isActive =3D virFileExists(path); =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - VIR_FREE(name); - return ret; + return 0; } =20 static int virStorageBackendSCSIRefreshPool(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *name =3D NULL; unsigned int host; - int ret =3D -1; + VIR_AUTOFREE(char *) name =3D NULL; =20 def->allocation =3D def->capacity =3D def->available =3D 0; =20 @@ -423,20 +403,17 @@ virStorageBackendSCSIRefreshPool(virStoragePoolObjPtr= pool) return -1; =20 if (virSCSIHostGetNumber(name, &host) < 0) - goto out; + return -1; =20 VIR_DEBUG("Scanning host%u", host); =20 if (virStorageBackendSCSITriggerRescan(host) < 0) - goto out; + return -1; =20 if (virStorageBackendSCSIFindLUs(pool, host) < 0) - goto out; + return -1; =20 - ret =3D 0; - out: - VIR_FREE(name); - return ret; + return 0; } =20 =20 diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_b= ackend_sheepdog.c index 73dcfb2f40..d3f126da8d 100644 --- a/src/storage/storage_backend_sheepdog.c +++ b/src/storage/storage_backend_sheepdog.c @@ -136,9 +136,8 @@ virStorageBackendSheepdogAddVolume(virStoragePoolObjPtr= pool, const char *diskIn static int virStorageBackendSheepdogRefreshAllVol(virStoragePoolObjPtr pool) { - int ret =3D -1; - char *output =3D NULL; size_t i; + VIR_AUTOFREE(char *) output =3D NULL; VIR_AUTOPTR(virString) lines =3D NULL; VIR_AUTOPTR(virString) cells =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; @@ -147,11 +146,11 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePool= ObjPtr pool) virStorageBackendSheepdogAddHostArg(cmd, pool); virCommandSetOutputBuffer(cmd, &output); if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 lines =3D virStringSplit(output, "\n", 0); if (lines =3D=3D NULL) - goto cleanup; + return -1; =20 for (i =3D 0; lines[i]; i++) { const char *line =3D lines[i]; @@ -163,42 +162,34 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePool= ObjPtr pool) if (cells !=3D NULL && virStringListLength((const char * const *)cells) > 2) { if (virStorageBackendSheepdogAddVolume(pool, cells[1]) < 0) - goto cleanup; + return -1; } =20 virStringListFree(cells); cells =3D NULL; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(output); - return ret; + return 0; } =20 =20 static int virStorageBackendSheepdogRefreshPool(virStoragePoolObjPtr pool) { - int ret =3D -1; - char *output =3D NULL; + VIR_AUTOFREE(char *) output =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNewArgList(SHEEPDOGCLI, "node", "info", "-r", NULL); virStorageBackendSheepdogAddHostArg(cmd, pool); virCommandSetOutputBuffer(cmd, &output); if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 if (virStorageBackendSheepdogParseNodeInfo(virStoragePoolObjGetDef(poo= l), output) < 0) - goto cleanup; + return -1; =20 - ret =3D virStorageBackendSheepdogRefreshAllVol(pool); - cleanup: - VIR_FREE(output); - return ret; + return virStorageBackendSheepdogRefreshAllVol(pool); } =20 =20 diff --git a/src/storage/storage_backend_vstorage.c b/src/storage/storage_b= ackend_vstorage.c index 8c5becd4c4..df157a48b1 100644 --- a/src/storage/storage_backend_vstorage.c +++ b/src/storage/storage_backend_vstorage.c @@ -39,9 +39,9 @@ virStorageBackendVzPoolStart(virStoragePoolObjPtr pool) { int ret =3D -1; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *grp_name =3D NULL; - char *usr_name =3D NULL; - char *mode =3D NULL; + VIR_AUTOFREE(char *) grp_name =3D NULL; + VIR_AUTOFREE(char *) usr_name =3D NULL; + VIR_AUTOFREE(char *) mode =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 /* Check the permissions */ @@ -55,13 +55,13 @@ virStorageBackendVzPoolStart(virStoragePoolObjPtr pool) /* Convert ids to names because vstorage uses names */ =20 if (!(grp_name =3D virGetGroupName(def->target.perms.gid))) - goto cleanup; + return -1; =20 if (!(usr_name =3D virGetUserName(def->target.perms.uid))) - goto cleanup; + return -1; =20 if (virAsprintf(&mode, "%o", def->target.perms.mode) < 0) - goto cleanup; + return -1; =20 cmd =3D virCommandNewArgList(VSTORAGE_MOUNT, "-c", def->source.name, @@ -70,15 +70,7 @@ virStorageBackendVzPoolStart(virStoragePoolObjPtr pool) "-g", grp_name, "-u", usr_name, NULL); =20 - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; - ret =3D 0; - - cleanup: - VIR_FREE(mode); - VIR_FREE(grp_name); - VIR_FREE(usr_name); - return ret; + return virCommandRun(cmd, NULL); } =20 =20 @@ -90,7 +82,7 @@ virStorageBackendVzIsMounted(virStoragePoolObjPtr pool) FILE *mtab; struct mntent ent; char buf[1024]; - char *cluster =3D NULL; + VIR_AUTOFREE(char *) cluster =3D NULL; =20 if (virAsprintf(&cluster, "vstorage://%s", def->source.name) < 0) return -1; @@ -115,7 +107,6 @@ virStorageBackendVzIsMounted(virStoragePoolObjPtr pool) =20 cleanup: VIR_FORCE_FCLOSE(mtab); - VIR_FREE(cluster); return ret; } =20 diff --git a/src/storage/storage_backend_zfs.c b/src/storage/storage_backen= d_zfs.c index 7d1a3dd2cd..7ffdff638e 100644 --- a/src/storage/storage_backend_zfs.c +++ b/src/storage/storage_backend_zfs.c @@ -52,7 +52,7 @@ static int virStorageBackendZFSVolModeNeeded(void) { int ret =3D -1, exit_code =3D -1; - char *error =3D NULL; + VIR_AUTOFREE(char *) error =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 /* 'zfs get' without arguments prints out @@ -77,7 +77,6 @@ virStorageBackendZFSVolModeNeeded(void) ret =3D 0; =20 cleanup: - VIR_FREE(error); return ret; } =20 @@ -86,13 +85,12 @@ virStorageBackendZFSCheckPool(virStoragePoolObjPtr pool= ATTRIBUTE_UNUSED, bool *isActive) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *devpath; + VIR_AUTOFREE(char *) devpath =3D NULL; =20 if (virAsprintf(&devpath, "/dev/zvol/%s", def->source.name) < 0) return -1; *isActive =3D virFileIsDir(devpath); - VIR_FREE(devpath); =20 return 0; } @@ -178,10 +176,10 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr poo= l, virStorageVolDefPtr vol) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *volumes_list =3D NULL; size_t i; VIR_AUTOPTR(virString) lines =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; + VIR_AUTOFREE(char *) volumes_list =3D NULL; =20 /** * $ zfs list -Hp -t volume -o name,volsize -r test @@ -203,10 +201,10 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr poo= l, NULL); virCommandSetOutputBuffer(cmd, &volumes_list); if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 if (!(lines =3D virStringSplit(volumes_list, "\n", 0))) - goto cleanup; + return -1; =20 for (i =3D 0; lines[i]; i++) { if (STREQ(lines[i], "")) @@ -216,9 +214,6 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr pool, continue; } =20 - cleanup: - VIR_FREE(volumes_list); - return 0; } =20 diff --git a/src/storage/storage_file_gluster.c b/src/storage/storage_file_= gluster.c index f8bbde8cfe..7c2189d297 100644 --- a/src/storage/storage_file_gluster.c +++ b/src/storage/storage_file_gluster.c @@ -258,10 +258,10 @@ virStorageFileBackendGlusterReadlinkCallback(const ch= ar *path, void *data) { virStorageFileBackendGlusterPrivPtr priv =3D data; - char *buf =3D NULL; size_t bufsiz =3D 0; ssize_t ret; struct stat st; + VIR_AUTOFREE(char *) buf =3D NULL; =20 *linkpath =3D NULL; =20 @@ -277,13 +277,13 @@ virStorageFileBackendGlusterReadlinkCallback(const ch= ar *path, =20 realloc: if (VIR_EXPAND_N(buf, bufsiz, 256) < 0) - goto error; + return -1; =20 if ((ret =3D glfs_readlink(priv->vol, path, buf, bufsiz)) < 0) { virReportSystemError(errno, _("failed to read link of gluster file '%s'"), path); - goto error; + return -1; } =20 if (ret =3D=3D bufsiz) @@ -291,13 +291,9 @@ virStorageFileBackendGlusterReadlinkCallback(const cha= r *path, =20 buf[ret] =3D '\0'; =20 - *linkpath =3D buf; + VIR_STEAL_PTR(*linkpath, buf); =20 return 0; - - error: - VIR_FREE(buf); - return -1; } =20 =20 @@ -305,7 +301,7 @@ static const char * virStorageFileBackendGlusterGetUniqueIdentifier(virStorageSourcePtr src) { virStorageFileBackendGlusterPrivPtr priv =3D src->drv->priv; - char *filePath =3D NULL; + VIR_AUTOFREE(char *) filePath =3D NULL; =20 if (priv->canonpath) return priv->canonpath; @@ -321,8 +317,6 @@ virStorageFileBackendGlusterGetUniqueIdentifier(virStor= ageSourcePtr src) src->volume, filePath)); =20 - VIR_FREE(filePath); - return priv->canonpath; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651105606802.5365130304567; Fri, 8 Feb 2019 10:38:25 -0800 (PST) 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 8C7E82CD801; Fri, 8 Feb 2019 18:38:22 +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 F32BD6012B; Fri, 8 Feb 2019 18:38:21 +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 A80503F616; Fri, 8 Feb 2019 18:38:21 +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 x18IbeEW007619 for ; Fri, 8 Feb 2019 13:37:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id EC6CD4250; Fri, 8 Feb 2019 18:37:40 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9378560BE0; Fri, 8 Feb 2019 18:37:40 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:07 -0500 Message-Id: <20190208183726.30903-14-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 13/32] storage: Use VIR_AUTOFREE for storage driver 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: , 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.29]); Fri, 08 Feb 2019 18:38:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_driver.c | 70 ++++++++++++------------------------ 1 file changed, 23 insertions(+), 47 deletions(-) diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index a71a16add1..34634e97d9 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -122,7 +122,7 @@ storagePoolUpdateStateCallback(virStoragePoolObjPtr obj, virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(obj); bool active =3D false; virStorageBackendPtr backend; - char *stateFile; + VIR_AUTOFREE(char *) stateFile =3D NULL; =20 if ((backend =3D virStorageBackendForType(def->type)) =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -164,8 +164,6 @@ storagePoolUpdateStateCallback(virStoragePoolObjPtr obj, if (!virStoragePoolObjIsActive(obj)) virStoragePoolUpdateInactive(&obj); =20 - VIR_FREE(stateFile); - return; } =20 @@ -203,7 +201,7 @@ storageDriverAutostartCallback(virStoragePoolObjPtr obj, } =20 if (started) { - char *stateFile; + VIR_AUTOFREE(char *) stateFile =3D NULL; =20 virStoragePoolObjClearVols(obj); stateFile =3D virFileBuildPath(driver->stateDir, def->name, ".xml"= ); @@ -217,7 +215,6 @@ storageDriverAutostartCallback(virStoragePoolObjPtr obj, } else { virStoragePoolObjSetActive(obj, true); } - VIR_FREE(stateFile); } } =20 @@ -240,16 +237,15 @@ storageStateInitialize(bool privileged, virStateInhibitCallback callback ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) { - int ret =3D -1; - char *configdir =3D NULL; - char *rundir =3D NULL; + VIR_AUTOFREE(char *) configdir =3D NULL; + VIR_AUTOFREE(char *) rundir =3D NULL; =20 if (VIR_ALLOC(driver) < 0) - return ret; + return -1; =20 if (virMutexInit(&driver->lock) < 0) { VIR_FREE(driver); - return ret; + return -1; } storageDriverLock(); =20 @@ -302,16 +298,12 @@ storageStateInitialize(bool privileged, =20 storageDriverUnlock(); =20 - ret =3D 0; - cleanup: - VIR_FREE(configdir); - VIR_FREE(rundir); - return ret; + return 0; =20 error: storageDriverUnlock(); storageStateCleanup(); - goto cleanup; + return -1; } =20 /** @@ -695,9 +687,9 @@ storagePoolCreateXML(virConnectPtr conn, virStoragePoolPtr pool =3D NULL; virStorageBackendPtr backend; virObjectEventPtr event =3D NULL; - char *stateFile =3D NULL; unsigned int build_flags =3D 0; VIR_AUTOPTR(virStoragePoolDef) newDef =3D NULL; + VIR_AUTOFREE(char *) stateFile =3D NULL; =20 virCheckFlags(VIR_STORAGE_POOL_CREATE_WITH_BUILD | VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE | @@ -761,7 +753,6 @@ storagePoolCreateXML(virConnectPtr conn, pool =3D virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); =20 cleanup: - VIR_FREE(stateFile); virObjectEventStateQueue(driver->storageEventState, event); virStoragePoolObjEndAPI(&obj); return pool; @@ -892,8 +883,8 @@ storagePoolCreate(virStoragePoolPtr pool, virStorageBackendPtr backend; virObjectEventPtr event =3D NULL; int ret =3D -1; - char *stateFile =3D NULL; unsigned int build_flags =3D 0; + VIR_AUTOFREE(char *) stateFile =3D NULL; =20 virCheckFlags(VIR_STORAGE_POOL_CREATE_WITH_BUILD | VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE | @@ -955,7 +946,6 @@ storagePoolCreate(virStoragePoolPtr pool, ret =3D 0; =20 cleanup: - VIR_FREE(stateFile); virObjectEventStateQueue(driver->storageEventState, event); virStoragePoolObjEndAPI(&obj); return ret; @@ -1013,8 +1003,8 @@ storagePoolDestroy(virStoragePoolPtr pool) virStoragePoolDefPtr def; virStorageBackendPtr backend; virObjectEventPtr event =3D NULL; - char *stateFile =3D NULL; int ret =3D -1; + VIR_AUTOFREE(char *) stateFile =3D NULL; =20 if (!(obj =3D storagePoolObjFindByUUID(pool->uuid, pool->name))) goto cleanup; @@ -1045,7 +1035,6 @@ storagePoolDestroy(virStoragePoolPtr pool) goto cleanup; =20 unlink(stateFile); - VIR_FREE(stateFile); =20 if (backend->stopPool && backend->stopPool(obj) < 0) @@ -1078,8 +1067,8 @@ storagePoolDelete(virStoragePoolPtr pool, virStoragePoolDefPtr def; virStorageBackendPtr backend; virObjectEventPtr event =3D NULL; - char *stateFile =3D NULL; int ret =3D -1; + VIR_AUTOFREE(char *) stateFile =3D NULL; =20 if (!(obj =3D virStoragePoolObjFromStoragePool(pool))) return -1; @@ -1111,7 +1100,6 @@ storagePoolDelete(virStoragePoolPtr pool, goto cleanup; =20 unlink(stateFile); - VIR_FREE(stateFile); =20 if (!backend->deletePool) { virReportError(VIR_ERR_NO_SUPPORT, @@ -1172,10 +1160,10 @@ storagePoolRefresh(virStoragePoolPtr pool, =20 virStoragePoolObjClearVols(obj); if (backend->refreshPool(obj) < 0) { - char *stateFile =3D virFileBuildPath(driver->stateDir, def->name, = ".xml"); + VIR_AUTOFREE(char *) stateFile =3D NULL; =20 + stateFile =3D virFileBuildPath(driver->stateDir, def->name, ".xml"= ); storagePoolRefreshFailCleanup(backend, obj, stateFile); - VIR_FREE(stateFile); =20 event =3D virStoragePoolEventLifecycleNew(def->name, def->uuid, @@ -1540,7 +1528,7 @@ storageVolLookupByPathCallback(virStoragePoolObjPtr o= bj, { struct storageVolLookupData *data =3D (struct storageVolLookupData *)o= paque; virStoragePoolDefPtr def; - char *stable_path =3D NULL; + VIR_AUTOFREE(char *) stable_path =3D NULL; =20 if (!virStoragePoolObjIsActive(obj)) return false; @@ -1579,7 +1567,6 @@ storageVolLookupByPathCallback(virStoragePoolObjPtr o= bj, } =20 data->voldef =3D virStorageVolDefFindByPath(obj, stable_path); - VIR_FREE(stable_path); =20 return !!data->voldef; } @@ -1649,7 +1636,7 @@ storagePoolLookupByTargetPath(virConnectPtr conn, virStoragePoolObjPtr obj; virStoragePoolDefPtr def; virStoragePoolPtr pool =3D NULL; - char *cleanpath; + VIR_AUTOFREE(char *) cleanpath =3D NULL; =20 cleanpath =3D virFileSanitizePath(path); if (!cleanpath) @@ -1660,7 +1647,7 @@ storagePoolLookupByTargetPath(virConnectPtr conn, cleanpath))) { def =3D virStoragePoolObjGetDef(obj); if (virStoragePoolLookupByTargetPathEnsureACL(conn, def) < 0) - goto cleanup; + return NULL; =20 pool =3D virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); virStoragePoolObjEndAPI(&obj); @@ -1678,8 +1665,6 @@ storagePoolLookupByTargetPath(virConnectPtr conn, } } =20 - cleanup: - VIR_FREE(cleanpath); return pool; } =20 @@ -2206,40 +2191,31 @@ virStorageVolPoolRefreshDataFree(void *opaque) static int virStorageBackendPloopRestoreDesc(char *path) { - int ret =3D -1; - char *refresh_tool =3D NULL; - char *desc =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; + VIR_AUTOFREE(char *) refresh_tool =3D NULL; + VIR_AUTOFREE(char *) desc =3D NULL; =20 if (virAsprintf(&desc, "%s/DiskDescriptor.xml", path) < 0) - return ret; + return -1; =20 if (virFileRemove(desc, 0, 0) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("refresh ploop failed:" " unable to delete DiskDescriptor.xml")); - goto cleanup; + return -1; } =20 refresh_tool =3D virFindFileInPath("ploop"); if (!refresh_tool) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unable to find ploop, please install ploop tools= ")); - goto cleanup; + return -1; } =20 cmd =3D virCommandNewArgList(refresh_tool, "restore-descriptor", path, NULL); virCommandAddArgFormat(cmd, "%s/root.hds", path); - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; - - ret =3D 0; - - cleanup: - VIR_FREE(refresh_tool); - VIR_FREE(desc); - return ret; + return virCommandRun(cmd, NULL); } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 154965110927666.57710402583041; Fri, 8 Feb 2019 10:38:29 -0800 (PST) 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 80F5AC01DE0D; Fri, 8 Feb 2019 18:38:27 +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 3C2D94272; Fri, 8 Feb 2019 18:38:27 +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 C14383F5D8; Fri, 8 Feb 2019 18:38:26 +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 x18Ibf0G007629 for ; Fri, 8 Feb 2019 13:37:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6841B60BE0; Fri, 8 Feb 2019 18:37:41 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 228F060C55 for ; Fri, 8 Feb 2019 18:37:41 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:08 -0500 Message-Id: <20190208183726.30903-15-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 14/32] util: Fix virStorageBackendSCSINewLun error handling 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: , 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.31]); Fri, 08 Feb 2019 18:38:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Commit a523770c3 added @retval return processing for virStorageBackendUpdateVolInfo in order to allow a -2 to be return; however, upon successful completion @retval =3D 0 and if either the virStorageBackendSCSISerial or the virStoragePoolObjAddVol failed, the method would return 0, but not add the @vol to the pool. So let's just reset retval =3D -1 and continue processing. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_util.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index fa364941c5..e4913b3405 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -3869,6 +3869,9 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, VIR_STORAGE_VOL_READ_NOER= ROR)) < 0) goto cleanup; =20 + /* Reset retval for proper error handling */ + retval =3D -1; + vol->key =3D virStorageBackendSCSISerial(vol->target.path, (def->source.adapter.type =3D= =3D VIR_STORAGE_ADAPTER_TYPE_FC_HO= ST)); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651109463744.1597406605028; Fri, 8 Feb 2019 10:38:29 -0800 (PST) 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 12E5DC0740DD; Fri, 8 Feb 2019 18:38:27 +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 B651117BAD; Fri, 8 Feb 2019 18:38:26 +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 5BC7018033B9; Fri, 8 Feb 2019 18:38:26 +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 x18Ibfi4007639 for ; Fri, 8 Feb 2019 13:37:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id D9B2C60C55; Fri, 8 Feb 2019 18:37:41 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9476C60BE0 for ; Fri, 8 Feb 2019 18:37:41 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:09 -0500 Message-Id: <20190208183726.30903-16-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 15/32] storage: Use VIR_AUTOFREE for storage util 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: , 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.31]); Fri, 08 Feb 2019 18:38:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_util.c | 335 +++++++++++++------------------------ 1 file changed, 113 insertions(+), 222 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index e4913b3405..1c290f1995 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -136,9 +136,9 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, size_t rbytes =3D READ_BLOCK_SIZE_DEFAULT; int wbytes =3D 0; int interval; - char *zerobuf =3D NULL; - char *buf =3D NULL; struct stat st; + VIR_AUTOFREE(char *) zerobuf =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; =20 if ((inputfd =3D open(inputvol->target.path, O_RDONLY)) < 0) { ret =3D -errno; @@ -241,9 +241,6 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, cleanup: VIR_FORCE_CLOSE(inputfd); =20 - VIR_FREE(zerobuf); - VIR_FREE(buf); - return ret; } =20 @@ -617,9 +614,9 @@ storageBackendCreatePloop(virStoragePoolObjPtr pool ATT= RIBUTE_UNUSED, unsigned int flags) { int ret =3D -1; - char *create_tool =3D NULL; bool created =3D false; VIR_AUTOPTR(virCommand) cmd =3D NULL; + VIR_AUTOFREE(char *) create_tool =3D NULL; =20 virCheckFlags(0, -1); =20 @@ -677,7 +674,6 @@ storageBackendCreatePloop(virStoragePoolObjPtr pool ATT= RIBUTE_UNUSED, created =3D true; ret =3D virCommandRun(cmd, NULL); cleanup: - VIR_FREE(create_tool); if (ret < 0 && created) virFileDeleteTree(vol->target.path); return ret; @@ -688,9 +684,8 @@ static int storagePloopResize(virStorageVolDefPtr vol, unsigned long long capacity) { - int ret =3D -1; - char *resize_tool =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; + VIR_AUTOFREE(char *) resize_tool =3D NULL; =20 resize_tool =3D virFindFileInPath("ploop"); if (!resize_tool) { @@ -703,9 +698,7 @@ storagePloopResize(virStorageVolDefPtr vol, =20 virCommandAddArgFormat(cmd, "%s/DiskDescriptor.xml", vol->target.path); =20 - ret =3D virCommandRun(cmd, NULL); - VIR_FREE(resize_tool); - return ret; + return virCommandRun(cmd, NULL); } =20 =20 @@ -881,7 +874,7 @@ storageBackendCreateQemuImgSetBacking(virStoragePoolObj= Ptr pool, { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); int accessRetCode =3D -1; - char *absolutePath =3D NULL; + VIR_AUTOFREE(char *) absolutePath =3D NULL; =20 if (info->format =3D=3D VIR_STORAGE_FILE_RAW) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -927,7 +920,6 @@ storageBackendCreateQemuImgSetBacking(virStoragePoolObj= Ptr pool, return -1; accessRetCode =3D access(absolutePath ? absolutePath : info->backingPath, R_OK); - VIR_FREE(absolutePath); if (accessRetCode !=3D 0) { virReportSystemError(errno, _("inaccessible backing store volume %s"), @@ -944,13 +936,12 @@ storageBackendCreateQemuImgSetOptions(virCommandPtr c= md, virStorageEncryptionInfoDefPtr encin= fo, struct _virStorageBackendQemuImgInfo= *info) { - char *opts =3D NULL; + VIR_AUTOFREE(char *) opts =3D NULL; =20 if (storageBackendCreateQemuImgOpts(encinfo, &opts, info) < 0) return -1; if (opts) virCommandAddArgList(cmd, "-o", opts, NULL); - VIR_FREE(opts); =20 return 0; } @@ -967,7 +958,7 @@ storageBackendCreateQemuImgSecretObject(virCommandPtr c= md, const char *secretAlias) { virBuffer buf =3D VIR_BUFFER_INITIALIZER; - char *commandStr =3D NULL; + VIR_AUTOFREE(char *) commandStr =3D NULL; =20 virBufferAsprintf(&buf, "secret,id=3D%s,file=3D", secretAlias); virQEMUBuildBufferEscapeComma(&buf, secretPath); @@ -981,7 +972,6 @@ storageBackendCreateQemuImgSecretObject(virCommandPtr c= md, =20 virCommandAddArgList(cmd, "--object", commandStr, NULL); =20 - VIR_FREE(commandStr); return 0; } =20 @@ -997,7 +987,7 @@ storageBackendResizeQemuImgImageOpts(virCommandPtr cmd, const char *secretAlias) { virBuffer buf =3D VIR_BUFFER_INITIALIZER; - char *commandStr =3D NULL; + VIR_AUTOFREE(char *) commandStr =3D NULL; =20 virBufferAsprintf(&buf, "driver=3Dluks,key-secret=3D%s,file.filename= =3D", secretAlias); @@ -1012,7 +1002,6 @@ storageBackendResizeQemuImgImageOpts(virCommandPtr cm= d, =20 virCommandAddArgList(cmd, "--image-opts", commandStr, NULL); =20 - VIR_FREE(commandStr); return 0; } =20 @@ -1118,9 +1107,9 @@ virStorageBackendCreateQemuImgCmdFromVol(virStoragePo= olObjPtr pool, .secretAlias =3D NULL, }; virStorageEncryptionPtr enc =3D vol->target.encryption; - char *inputSecretAlias =3D NULL; virStorageEncryptionPtr inputenc =3D inputvol ? inputvol->target.encry= ption : NULL; virStorageEncryptionInfoDefPtr encinfo =3D NULL; + VIR_AUTOFREE(char *) inputSecretAlias =3D NULL; =20 virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL); =20 @@ -1222,13 +1211,11 @@ virStorageBackendCreateQemuImgCmdFromVol(virStorage= PoolObjPtr pool, =20 } VIR_FREE(info.secretAlias); - VIR_FREE(inputSecretAlias); =20 return cmd; =20 error: VIR_FREE(info.secretAlias); - VIR_FREE(inputSecretAlias); virCommandFree(cmd); return NULL; } @@ -1337,10 +1324,10 @@ storageBackendCreateQemuImg(virStoragePoolObjPtr po= ol, unsigned int flags) { int ret =3D -1; - char *create_tool; - char *secretPath =3D NULL; - char *inputSecretPath =3D NULL; virStorageVolEncryptConvertStep convertStep =3D VIR_STORAGE_VOL_ENCRYP= T_NONE; + VIR_AUTOFREE(char *) create_tool =3D NULL; + VIR_AUTOFREE(char *) secretPath =3D NULL; + VIR_AUTOFREE(char *) inputSecretPath =3D NULL; =20 virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, -1); =20 @@ -1388,15 +1375,10 @@ storageBackendCreateQemuImg(virStoragePoolObjPtr po= ol, } while (convertStep !=3D VIR_STORAGE_VOL_ENCRYPT_DONE); =20 cleanup: - if (secretPath) { + if (secretPath) unlink(secretPath); - VIR_FREE(secretPath); - } - if (inputSecretPath) { + if (inputSecretPath) unlink(inputSecretPath); - VIR_FREE(inputSecretPath); - } - VIR_FREE(create_tool); return ret; } =20 @@ -1717,23 +1699,16 @@ virStorageBackendVolOpen(const char *path, struct s= tat *sb, static bool storageBackendIsPloopDir(char *path) { - bool ret =3D false; - char *root =3D NULL; - char *desc =3D NULL; - if (virAsprintf(&root, "%s/root.hds", path) < 0) - return ret; - if (!virFileExists(root)) - goto cleanup; - if (virAsprintf(&desc, "%s/DiskDescriptor.xml", path) < 0) - goto cleanup; - if (!virFileExists(desc)) - goto cleanup; + VIR_AUTOFREE(char *) root =3D NULL; + VIR_AUTOFREE(char *) desc =3D NULL; =20 - ret =3D true; - cleanup: - VIR_FREE(root); - VIR_FREE(desc); - return ret; + if (virAsprintf(&root, "%s/root.hds", path) < 0 || + !virFileExists(root) || + virAsprintf(&desc, "%s/DiskDescriptor.xml", path) < 0 || + !virFileExists(desc)) + return false; + + return true; } =20 /* In case of ploop volumes, path to volume is the path to the ploop @@ -1745,20 +1720,14 @@ static int storageBackendRedoPloopUpdate(virStorageSourcePtr target, struct stat *sb, int *fd, unsigned int flags) { - char *path =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (virAsprintf(&path, "%s/root.hds", target->path) < 0) return -1; VIR_FORCE_CLOSE(*fd); if ((*fd =3D virStorageBackendVolOpen(path, sb, flags)) < 0) - goto cleanup; - ret =3D virStorageBackendUpdateVolTargetInfoFD(target, *fd, sb); - - cleanup: - - VIR_FREE(path); - return ret; + return -1; + return virStorageBackendUpdateVolTargetInfoFD(target, *fd, sb); } =20 /* @@ -1784,8 +1753,8 @@ storageBackendUpdateVolTargetInfo(virStorageVolType v= oltype, { int ret, fd =3D -1; struct stat sb; - char *buf =3D NULL; ssize_t len =3D VIR_STORAGE_MAX_HEADER; + VIR_AUTOFREE(char *) buf =3D NULL; =20 if ((ret =3D virStorageBackendVolOpen(target->path, &sb, openflags)) <= 0) goto cleanup; @@ -1842,7 +1811,6 @@ storageBackendUpdateVolTargetInfo(virStorageVolType v= oltype, =20 cleanup: VIR_FORCE_CLOSE(fd); - VIR_FREE(buf); return ret; } =20 @@ -2316,12 +2284,12 @@ storageBackendResizeQemuImg(virStoragePoolObjPtr po= ol, unsigned long long capacity) { int ret =3D -1; - char *img_tool =3D NULL; const char *type; - char *secretPath =3D NULL; - char *secretAlias =3D NULL; virStorageEncryptionPtr enc =3D vol->target.encryption; VIR_AUTOPTR(virCommand) cmd =3D NULL; + VIR_AUTOFREE(char *) img_tool =3D NULL; + VIR_AUTOFREE(char *) secretPath =3D NULL; + VIR_AUTOFREE(char *) secretAlias =3D NULL; =20 if (enc && (enc->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMAT_QCOW || enc->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT) = && @@ -2382,12 +2350,8 @@ storageBackendResizeQemuImg(virStoragePoolObjPtr poo= l, ret =3D virCommandRun(cmd, NULL); =20 cleanup: - VIR_FREE(img_tool); - if (secretPath) { + if (secretPath) unlink(secretPath); - VIR_FREE(secretPath); - } - VIR_FREE(secretAlias); return ret; } =20 @@ -2441,35 +2405,29 @@ virStorageBackendVolResizeLocal(virStoragePoolObjPt= r pool, static int storageBackendPloopHasSnapshots(char *path) { - char *output =3D NULL; char *snap_tool =3D NULL; - int ret =3D -1; VIR_AUTOPTR(virCommand) cmd =3D NULL; + VIR_AUTOFREE(char *) output =3D NULL; =20 snap_tool =3D virFindFileInPath("ploop"); if (!snap_tool) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unable to find ploop, please install " "ploop tools")); - return ret; + return -1; } =20 cmd =3D virCommandNewArgList(snap_tool, "snapshot-list", NULL); virCommandAddArgFormat(cmd, "%s/DiskDescriptor.xml", path); virCommandSetOutputBuffer(cmd, &output); =20 - if ((ret =3D virCommandRun(cmd, NULL)) < 0) - goto cleanup; + if (virCommandRun(cmd, NULL) < 0) + return -1; =20 - if (!strstr(output, "root.hds.")) { - ret =3D 1; - goto cleanup; - } - ret =3D 0; + if (!strstr(output, "root.hds.")) + return 1; =20 - cleanup: - VIR_FREE(output); - return ret; + return 0; } =20 =20 @@ -2481,11 +2439,10 @@ virStorageBackendVolUploadLocal(virStoragePoolObjPt= r pool ATTRIBUTE_UNUSED, unsigned long long len, unsigned int flags) { - char *path =3D NULL; char *target_path =3D vol->target.path; - int ret =3D -1; int has_snap =3D 0; bool sparse =3D flags & VIR_STORAGE_VOL_UPLOAD_SPARSE_STREAM; + VIR_AUTOFREE(char *)path =3D NULL; =20 virCheckFlags(VIR_STORAGE_VOL_UPLOAD_SPARSE_STREAM, -1); /* if volume has target format VIR_STORAGE_FILE_PLOOP @@ -2496,12 +2453,12 @@ virStorageBackendVolUploadLocal(virStoragePoolObjPt= r pool ATTRIBUTE_UNUSED, /* Fail if the volume contains snapshots or we failed to check it.= */ has_snap =3D storageBackendPloopHasSnapshots(vol->target.path); if (has_snap < 0) { - goto cleanup; + return -1; } else if (!has_snap) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("can't upload volume, all existing snapshots" " will be lost")); - goto cleanup; + return -1; } =20 if (virAsprintf(&path, "%s/root.hds", vol->target.path) < 0) @@ -2511,12 +2468,8 @@ virStorageBackendVolUploadLocal(virStoragePoolObjPtr= pool ATTRIBUTE_UNUSED, =20 /* Not using O_CREAT because the file is required to already exist at * this point */ - ret =3D virFDStreamOpenBlockDevice(stream, target_path, - offset, len, sparse, O_WRONLY); - - cleanup: - VIR_FREE(path); - return ret; + return virFDStreamOpenBlockDevice(stream, target_path, + offset, len, sparse, O_WRONLY); } =20 int @@ -2527,34 +2480,29 @@ virStorageBackendVolDownloadLocal(virStoragePoolObj= Ptr pool ATTRIBUTE_UNUSED, unsigned long long len, unsigned int flags) { - char *path =3D NULL; char *target_path =3D vol->target.path; - int ret =3D -1; int has_snap =3D 0; bool sparse =3D flags & VIR_STORAGE_VOL_DOWNLOAD_SPARSE_STREAM; + VIR_AUTOFREE(char *) path =3D NULL; =20 virCheckFlags(VIR_STORAGE_VOL_DOWNLOAD_SPARSE_STREAM, -1); if (vol->target.format =3D=3D VIR_STORAGE_FILE_PLOOP) { has_snap =3D storageBackendPloopHasSnapshots(vol->target.path); if (has_snap < 0) { - goto cleanup; + return -1; } else if (!has_snap) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("can't download volume, all existing snapshot= s" " will be lost")); - goto cleanup; + return -1; } if (virAsprintf(&path, "%s/root.hds", vol->target.path) < 0) - goto cleanup; + return -1; target_path =3D path; } =20 - ret =3D virFDStreamOpenBlockDevice(stream, target_path, - offset, len, sparse, O_RDONLY); - - cleanup: - VIR_FREE(path); - return ret; + return virFDStreamOpenBlockDevice(stream, target_path, + offset, len, sparse, O_RDONLY); } =20 =20 @@ -2604,14 +2552,14 @@ storageBackendWipeLocal(const char *path, size_t writebuf_length, bool zero_end) { - int ret =3D -1, written =3D 0; + int written =3D 0; unsigned long long remaining =3D 0; off_t size; size_t write_size =3D 0; - char *writebuf =3D NULL; + VIR_AUTOFREE(char *) writebuf =3D NULL; =20 if (VIR_ALLOC_N(writebuf, writebuf_length) < 0) - goto cleanup; + return -1; =20 if (!zero_end) { if ((size =3D lseek(fd, 0, SEEK_SET)) < 0) { @@ -2619,7 +2567,7 @@ storageBackendWipeLocal(const char *path, _("Failed to seek to the start in volume " "with path '%s'"), path); - goto cleanup; + return -1; } } else { if ((size =3D lseek(fd, -wipe_len, SEEK_END)) < 0) { @@ -2627,7 +2575,7 @@ storageBackendWipeLocal(const char *path, _("Failed to seek to %llu bytes to the en= d " "in volume with path '%s'"), wipe_len, path); - goto cleanup; + return -1; } } =20 @@ -2644,7 +2592,7 @@ storageBackendWipeLocal(const char *path, "storage volume with path '%s'"), write_size, path); =20 - goto cleanup; + return -1; } =20 remaining -=3D written; @@ -2654,16 +2602,12 @@ storageBackendWipeLocal(const char *path, virReportSystemError(errno, _("cannot sync data to volume with path '%s'"= ), path); - goto cleanup; + return -1; } =20 VIR_DEBUG("Wrote %llu bytes to volume with path '%s'", wipe_len, path); =20 - ret =3D 0; - - cleanup: - VIR_FREE(writebuf); - return ret; + return 0; } =20 =20 @@ -2763,12 +2707,10 @@ static int storageBackendVolWipePloop(virStorageVolDefPtr vol, unsigned int algorithm) { - char *target_path =3D NULL; - char *disk_desc =3D NULL; - char *create_tool =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; - - int ret =3D -1; + VIR_AUTOFREE(char *) target_path =3D NULL; + VIR_AUTOFREE(char *) disk_desc =3D NULL; + VIR_AUTOFREE(char *) create_tool =3D NULL; =20 create_tool =3D virFindFileInPath("ploop"); if (!create_tool) { @@ -2778,24 +2720,24 @@ storageBackendVolWipePloop(virStorageVolDefPtr vol, } =20 if (virAsprintf(&target_path, "%s/root.hds", vol->target.path) < 0) - goto cleanup; + return -1; =20 if (virAsprintf(&disk_desc, "%s/DiskDescriptor.xml", vol->target.path)= < 0) - goto cleanup; + return -1; =20 if (storageBackendVolWipeLocalFile(target_path, algorithm, vol->target.allocation, false) < 0) - goto cleanup; + return -1; =20 if (virFileRemove(disk_desc, 0, 0) < 0) { virReportError(errno, _("Failed to delete DiskDescriptor.xml of vo= lume '%s'"), vol->target.path); - goto cleanup; + return -1; } if (virFileRemove(target_path, 0, 0) < 0) { virReportError(errno, _("failed to delete root.hds of volume '%s'"= ), vol->target.path); - goto cleanup; + return -1; } =20 cmd =3D virCommandNewArgList(create_tool, "init", "-s", NULL); @@ -2804,13 +2746,7 @@ storageBackendVolWipePloop(virStorageVolDefPtr vol, (1024 * 1024))); virCommandAddArgList(cmd, "-t", "ext4", NULL); virCommandAddArg(cmd, target_path); - ret =3D virCommandRun(cmd, NULL); - - cleanup: - VIR_FREE(disk_desc); - VIR_FREE(target_path); - VIR_FREE(create_tool); - return ret; + return virCommandRun(cmd, NULL); } =20 =20 @@ -2850,20 +2786,19 @@ int virStorageBackendBuildLocal(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - int ret =3D -1; - char *parent =3D NULL; char *p =3D NULL; mode_t mode; bool needs_create_as_uid; unsigned int dir_create_flags; + VIR_AUTOFREE(char *) parent =3D NULL; =20 if (VIR_STRDUP(parent, def->target.path) < 0) - goto cleanup; + return -1; if (!(p =3D strrchr(parent, '/'))) { virReportError(VIR_ERR_INVALID_ARG, _("path '%s' is not absolute"), def->target.path); - goto cleanup; + return -1; } =20 if (p !=3D parent) { @@ -2873,7 +2808,7 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr pool) if (virFileMakePath(parent) < 0) { virReportSystemError(errno, _("cannot create path '%s'"), parent); - goto cleanup; + return -1; } } =20 @@ -2890,18 +2825,11 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr po= ol) /* Now create the final dir in the path with the uid/gid/mode * requested in the config. If the dir already exists, just set * the perms. */ - if (virDirCreate(def->target.path, - mode, - def->target.perms.uid, - def->target.perms.gid, - dir_create_flags) < 0) - goto cleanup; - - ret =3D 0; - - cleanup: - VIR_FREE(parent); - return ret; + return virDirCreate(def->target.path, + mode, + def->target.perms.uid, + def->target.perms.gid, + dir_create_flags); } =20 =20 @@ -2942,12 +2870,12 @@ virStorageUtilGlusterExtractPoolSources(const char = *host, { xmlDocPtr doc =3D NULL; xmlXPathContextPtr ctxt =3D NULL; - xmlNodePtr *nodes =3D NULL; virStoragePoolSource *src =3D NULL; - char *volname =3D NULL; size_t i; int nnodes; int ret =3D -1; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; + VIR_AUTOFREE(char *) volname =3D NULL; =20 if (!(doc =3D virXMLParseStringCtxt(xml, _("(gluster_cli_output)"), &c= txt))) goto cleanup; @@ -2991,8 +2919,6 @@ virStorageUtilGlusterExtractPoolSources(const char *h= ost, ret =3D nnodes; =20 cleanup: - VIR_FREE(volname); - VIR_FREE(nodes); xmlXPathFreeContext(ctxt); xmlFreeDoc(doc); =20 @@ -3021,12 +2947,10 @@ virStorageBackendFindGlusterPoolSources(const char = *host, virStoragePoolSourceListPtr list, bool report) { - char *glusterpath =3D NULL; - char *outbuf =3D NULL; int rc; VIR_AUTOPTR(virCommand) cmd =3D NULL; - - int ret =3D -1; + VIR_AUTOFREE(char *) glusterpath =3D NULL; + VIR_AUTOFREE(char *) outbuf =3D NULL; =20 if (!(glusterpath =3D virFindFileInPath("gluster"))) { if (report) { @@ -3047,19 +2971,12 @@ virStorageBackendFindGlusterPoolSources(const char = *host, virCommandSetOutputBuffer(cmd, &outbuf); =20 if (virCommandRun(cmd, &rc) < 0) - goto cleanup; - - if (rc !=3D 0) { - ret =3D 0; - goto cleanup; - } + return -1; =20 - ret =3D virStorageUtilGlusterExtractPoolSources(host, outbuf, list, po= oltype); + if (rc !=3D 0) + return 0; =20 - cleanup: - VIR_FREE(outbuf); - VIR_FREE(glusterpath); - return ret; + return virStorageUtilGlusterExtractPoolSources(host, outbuf, list, poo= ltype); } =20 =20 @@ -3297,11 +3214,11 @@ virStorageBackendPARTEDFindLabel(const char *device, const char *const args[] =3D { device, "print", "--script", NULL, }; - char *output =3D NULL; - char *error =3D NULL; char *start, *end; int ret =3D VIR_STORAGE_PARTED_ERROR; VIR_AUTOPTR(virCommand) cmd =3D NULL; + VIR_AUTOFREE(char *) output =3D NULL; + VIR_AUTOFREE(char *) error =3D NULL; =20 cmd =3D virCommandNew(PARTED); virCommandAddArgSet(cmd, args); @@ -3316,7 +3233,7 @@ virStorageBackendPARTEDFindLabel(const char *device, (error && strstr(error, "unrecognised disk label"))) { ret =3D VIR_STORAGE_PARTED_UNKNOWN; } - goto cleanup; + return ret; } =20 /* Search for "Partition Table:" in the output. If not present, @@ -3325,8 +3242,7 @@ virStorageBackendPARTEDFindLabel(const char *device, if (!(start =3D strstr(output, "Partition Table: ")) || !(end =3D strstr(start, "\n"))) { VIR_DEBUG("Unable to find tag in output: %s", output); - ret =3D VIR_STORAGE_PARTED_NOPTTYPE; - goto cleanup; + return VIR_STORAGE_PARTED_NOPTTYPE; } start +=3D strlen("Partition Table: "); *end =3D '\0'; @@ -3336,21 +3252,14 @@ virStorageBackendPARTEDFindLabel(const char *device, start +=3D 2; =20 /* Make sure we know about this type */ - if (virStoragePoolFormatDiskTypeFromString(start) < 0) { - ret =3D VIR_STORAGE_PARTED_PTTYPE_UNK; - goto cleanup; - } + if (virStoragePoolFormatDiskTypeFromString(start) < 0) + return VIR_STORAGE_PARTED_PTTYPE_UNK; =20 /* Does the on disk match what the pool desired? */ if (STREQ(start, format)) - ret =3D VIR_STORAGE_PARTED_MATCH; - else - ret =3D VIR_STORAGE_PARTED_DIFFERENT; + return VIR_STORAGE_PARTED_MATCH; =20 - cleanup: - VIR_FREE(output); - VIR_FREE(error); - return ret; + return VIR_STORAGE_PARTED_DIFFERENT; } =20 =20 @@ -3803,9 +3712,9 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, const char *dev) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *devpath =3D NULL; int retval =3D -1; VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; + VIR_AUTOFREE(char *) devpath =3D NULL; =20 /* Check if the pool is using a stable target path. The call to * virStorageBackendStablePath will fail if the pool target path @@ -3820,11 +3729,11 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr po= ol, virReportError(VIR_ERR_INVALID_ARG, _("unable to use target path '%s' for dev '%s'"), NULLSTR(def->target.path), dev); - goto cleanup; + return -1; } =20 if (VIR_ALLOC(vol) < 0) - goto cleanup; + return -1; =20 vol->type =3D VIR_STORAGE_VOL_BLOCK; =20 @@ -3834,10 +3743,10 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr po= ol, * just leave 'host' out */ if (virAsprintf(&(vol->name), "unit:%u:%u:%u", bus, target, lun) < 0) - goto cleanup; + return -1; =20 if (virAsprintf(&devpath, "/dev/%s", dev) < 0) - goto cleanup; + return -1; =20 VIR_DEBUG("Trying to create volume for '%s'", devpath); =20 @@ -3850,7 +3759,7 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, if ((vol->target.path =3D virStorageBackendStablePath(pool, devpath, true)) =3D=3D NULL) - goto cleanup; + return -1; =20 if (STREQ(devpath, vol->target.path) && !(STREQ(def->target.path, "/dev") || @@ -3859,37 +3768,29 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr po= ol, VIR_DEBUG("No stable path found for '%s' in '%s'", devpath, def->target.path); =20 - retval =3D -2; - goto cleanup; + return -2; } =20 /* Allow a volume read failure to ignore or skip this block file */ if ((retval =3D virStorageBackendUpdateVolInfo(vol, true, VIR_STORAGE_VOL_OPEN_DEFA= ULT, VIR_STORAGE_VOL_READ_NOER= ROR)) < 0) - goto cleanup; - - /* Reset retval for proper error handling */ - retval =3D -1; + return retval; =20 vol->key =3D virStorageBackendSCSISerial(vol->target.path, (def->source.adapter.type =3D= =3D VIR_STORAGE_ADAPTER_TYPE_FC_HO= ST)); if (!vol->key) - goto cleanup; + return -1; =20 def->capacity +=3D vol->target.capacity; def->allocation +=3D vol->target.allocation; =20 if (virStoragePoolObjAddVol(pool, vol) < 0) - goto cleanup; + return -1; vol =3D NULL; =20 - retval =3D 0; - - cleanup: - VIR_FREE(devpath); - return retval; + return 0; } =20 =20 @@ -3899,11 +3800,11 @@ getNewStyleBlockDevice(const char *lun_path, const char *block_name ATTRIBUTE_UNUSED, char **block_device) { - char *block_path =3D NULL; DIR *block_dir =3D NULL; struct dirent *block_dirent =3D NULL; int retval =3D -1; int direrr; + VIR_AUTOFREE(char *) block_path =3D NULL; =20 if (virAsprintf(&block_path, "%s/block", lun_path) < 0) goto cleanup; @@ -3929,7 +3830,6 @@ getNewStyleBlockDevice(const char *lun_path, =20 cleanup: VIR_DIR_CLOSE(block_dir); - VIR_FREE(block_path); return retval; } =20 @@ -3979,11 +3879,11 @@ getBlockDevice(uint32_t host, uint32_t lun, char **block_device) { - char *lun_path =3D NULL; DIR *lun_dir =3D NULL; struct dirent *lun_dirent =3D NULL; int retval =3D -1; int direrr; + VIR_AUTOFREE(char *) lun_path =3D NULL; =20 *block_device =3D NULL; =20 @@ -4021,7 +3921,6 @@ getBlockDevice(uint32_t host, =20 cleanup: VIR_DIR_CLOSE(lun_dir); - VIR_FREE(lun_path); return retval; } =20 @@ -4037,15 +3936,14 @@ getDeviceType(uint32_t host, uint32_t lun, int *type) { - char *type_path =3D NULL; char typestr[3]; char *gottype, *p; FILE *typefile; - int retval =3D 0; + VIR_AUTOFREE(char *) type_path =3D NULL; =20 if (virAsprintf(&type_path, "/sys/bus/scsi/devices/%u:%u:%u:%u/type", host, bus, target, lun) < 0) - goto out; + return -1; =20 typefile =3D fopen(type_path, "r"); if (typefile =3D=3D NULL) { @@ -4053,8 +3951,7 @@ getDeviceType(uint32_t host, _("Could not find typefile '%s'"), type_path); /* there was no type file; that doesn't seem right */ - retval =3D -1; - goto out; + return -1; } =20 gottype =3D fgets(typestr, 3, typefile); @@ -4065,8 +3962,7 @@ getDeviceType(uint32_t host, _("Could not read typefile '%s'"), type_path); /* we couldn't read the type file; have to give up */ - retval =3D -1; - goto out; + return -1; } =20 /* we don't actually care about p, but if you pass NULL and the last @@ -4077,15 +3973,12 @@ getDeviceType(uint32_t host, _("Device type '%s' is not an integer"), typestr); /* Hm, type wasn't an integer; seems strange */ - retval =3D -1; - goto out; + return -1; } =20 VIR_DEBUG("Device type is %d", *type); =20 - out: - VIR_FREE(type_path); - return retval; + return 0; } =20 =20 @@ -4107,7 +4000,7 @@ processLU(virStoragePoolObjPtr pool, { int retval =3D -1; int device_type; - char *block_device =3D NULL; + VIR_AUTOFREE(char *) block_device =3D NULL; =20 VIR_DEBUG("Processing LU %u:%u:%u:%u", host, bus, target, lun); @@ -4139,14 +4032,12 @@ processLU(virStoragePoolObjPtr pool, if (retval < 0) { VIR_DEBUG("Failed to create new storage volume for %u:%u:%u:%u", host, bus, target, lun); - goto cleanup; + return retval; } =20 VIR_DEBUG("Created new storage volume for %u:%u:%u:%u successfully", host, bus, target, lun); =20 - cleanup: - VIR_FREE(block_device); return retval; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651083867483.5078984604161; Fri, 8 Feb 2019 10:38:03 -0800 (PST) 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 90FCE4CE8D; Fri, 8 Feb 2019 18:38:01 +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 2BE4362988; Fri, 8 Feb 2019 18:38:01 +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 A378E3F603; Fri, 8 Feb 2019 18:38:00 +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 x18Ibg5L007652 for ; Fri, 8 Feb 2019 13:37:42 -0500 Received: by smtp.corp.redhat.com (Postfix) id 69F7F383F; Fri, 8 Feb 2019 18:37:42 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 102C860BE0; Fri, 8 Feb 2019 18:37:41 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:10 -0500 Message-Id: <20190208183726.30903-17-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 16/32] conf: Use VIR_AUTOFREE for storage_conf 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: , 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.30]); Fri, 08 Feb 2019 18:38:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/conf/storage_conf.c | 179 +++++++++++++++++----------------------- 1 file changed, 74 insertions(+), 105 deletions(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 177ea63076..a2ddecf0f2 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -453,16 +453,16 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, xmlNodePtr node) { int ret =3D -1; - xmlNodePtr relnode, authnode, *nodeset =3D NULL; + xmlNodePtr relnode, authnode; xmlNodePtr adapternode; int nsource; size_t i; virStoragePoolOptionsPtr options; - char *name =3D NULL; - char *port =3D NULL; - char *ver =3D NULL; int n; VIR_AUTOPTR(virStorageAuthDef) authdef =3D NULL; + VIR_AUTOFREE(char *) port =3D NULL; + VIR_AUTOFREE(char *) ver =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) nodeset =3D NULL; =20 relnode =3D ctxt->node; ctxt->node =3D node; @@ -478,7 +478,9 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, } =20 if (options->formatFromString) { - char *format =3D virXPathString("string(./format/@type)", ctxt); + VIR_AUTOFREE(char *) format =3D NULL; + + format =3D virXPathString("string(./format/@type)", ctxt); if (format =3D=3D NULL) source->format =3D options->defaultFormat; else @@ -487,10 +489,8 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, if (source->format < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown pool format type %s"), format); - VIR_FREE(format); goto cleanup; } - VIR_FREE(format); } =20 if ((n =3D virXPathNodeSet("./host", ctxt, &nodeset)) < 0) @@ -502,13 +502,12 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, source->nhost =3D n; =20 for (i =3D 0; i < source->nhost; i++) { - name =3D virXMLPropString(nodeset[i], "name"); - if (name =3D=3D NULL) { + source->hosts[i].name =3D virXMLPropString(nodeset[i], "name"); + if (!source->hosts[i].name) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing storage pool host name")); goto cleanup; } - source->hosts[i].name =3D name; =20 port =3D virXMLPropString(nodeset[i], "port"); if (port) { @@ -518,7 +517,6 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, port); goto cleanup; } - VIR_FREE(port); } } } @@ -532,7 +530,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, goto cleanup; =20 for (i =3D 0; i < nsource; i++) { - char *partsep; + VIR_AUTOFREE(char *) partsep =3D NULL; virStoragePoolSourceDevice dev =3D { .path =3D NULL }; dev.path =3D virXMLPropString(nodeset[i], "path"); =20 @@ -550,10 +548,8 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, _("invalid part_separator setting '%s'"), partsep); virStoragePoolSourceDeviceClear(&dev); - VIR_FREE(partsep); goto cleanup; } - VIR_FREE(partsep); } =20 if (VIR_APPEND_ELEMENT(source->devices, source->ndevice, dev) < 0)= { @@ -612,8 +608,6 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, cleanup: ctxt->node =3D relnode; =20 - VIR_FREE(port); - VIR_FREE(nodeset); return ret; } =20 @@ -660,11 +654,11 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt, virStoragePermsPtr perms, const char *permxpath) { - char *mode; long long val; int ret =3D -1; xmlNodePtr relnode; xmlNodePtr node; + VIR_AUTOFREE(char *) mode =3D NULL; =20 node =3D virXPathNode(permxpath, ctxt); if (node =3D=3D NULL) { @@ -683,13 +677,11 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt, int tmp; =20 if (virStrToLong_i(mode, NULL, 8, &tmp) < 0 || (tmp & ~0777)) { - VIR_FREE(mode); virReportError(VIR_ERR_XML_ERROR, "%s", _("malformed octal mode")); goto error; } perms->mode =3D tmp; - VIR_FREE(mode); } else { perms->mode =3D (mode_t) -1; } @@ -739,10 +731,10 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) virStoragePoolOptionsPtr options; virStoragePoolDefPtr ret =3D NULL; xmlNodePtr source_node; - char *type =3D NULL; - char *uuid =3D NULL; - char *target_path =3D NULL; VIR_AUTOPTR(virStoragePoolDef) def =3D NULL; + VIR_AUTOFREE(char *) type =3D NULL; + VIR_AUTOFREE(char *) uuid =3D NULL; + VIR_AUTOFREE(char *) target_path =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -751,23 +743,23 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) if (type =3D=3D NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("storage pool missing type attribute")); - goto cleanup; + return NULL; } =20 if ((def->type =3D virStoragePoolTypeFromString(type)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown storage pool type %s"), type); - goto cleanup; + return NULL; } =20 if ((options =3D virStoragePoolOptionsForPoolType(def->type)) =3D=3D N= ULL) - goto cleanup; + return NULL; =20 source_node =3D virXPathNode("./source", ctxt); if (source_node) { if (virStoragePoolDefParseSource(ctxt, &def->source, def->type, source_node) < 0) - goto cleanup; + return NULL; } else { if (options->formatFromString) def->source.format =3D options->defaultFormat; @@ -777,17 +769,18 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) if (def->name =3D=3D NULL && options->flags & VIR_STORAGE_POOL_SOURCE_NAME && VIR_STRDUP(def->name, def->source.name) < 0) - goto cleanup; + return NULL; + if (def->name =3D=3D NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing pool source name element")); - goto cleanup; + return NULL; } =20 if (strchr(def->name, '/')) { virReportError(VIR_ERR_XML_ERROR, _("name %s cannot contain '/'"), def->name); - goto cleanup; + return NULL; } =20 uuid =3D virXPathString("string(./uuid)", ctxt); @@ -795,13 +788,13 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) if (virUUIDGenerate(def->uuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unable to generate uuid")); - goto cleanup; + return NULL; } } else { if (virUUIDParse(uuid, def->uuid) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("malformed uuid element")); - goto cleanup; + return NULL; } } =20 @@ -809,7 +802,7 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) if (!def->source.nhost) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing storage pool source host name")); - goto cleanup; + return NULL; } } =20 @@ -817,27 +810,27 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) if (!def->source.dir) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing storage pool source path")); - goto cleanup; + return NULL; } } if (options->flags & VIR_STORAGE_POOL_SOURCE_NAME) { if (def->source.name =3D=3D NULL) { /* source name defaults to pool name */ if (VIR_STRDUP(def->source.name, def->name) < 0) - goto cleanup; + return NULL; } } =20 if ((options->flags & VIR_STORAGE_POOL_SOURCE_ADAPTER) && (virStorageAdapterValidate(&def->source.adapter)) < 0) - goto cleanup; + return NULL; =20 /* If DEVICE is the only source type, then its required */ if (options->flags =3D=3D VIR_STORAGE_POOL_SOURCE_DEVICE) { if (!def->source.ndevice) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing storage pool source device name")); - goto cleanup; + return NULL; } } =20 @@ -846,32 +839,32 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) if (!(options->flags & VIR_STORAGE_POOL_SOURCE_NETWORK)) { if (def->type =3D=3D VIR_STORAGE_POOL_LOGICAL) { if (virAsprintf(&target_path, "/dev/%s", def->source.name) < 0) - goto cleanup; + return NULL; } else if (def->type =3D=3D VIR_STORAGE_POOL_ZFS) { if (virAsprintf(&target_path, "/dev/zvol/%s", def->source.name= ) < 0) - goto cleanup; + return NULL; } else { target_path =3D virXPathString("string(./target/path)", ctxt); if (!target_path) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing storage pool target path")); - goto cleanup; + return NULL; } } def->target.path =3D virFileSanitizePath(target_path); if (!def->target.path) - goto cleanup; + return NULL; =20 if (virStorageDefParsePerms(ctxt, &def->target.perms, "./target/permissions") < 0) - goto cleanup; + return NULL; } =20 if (def->type =3D=3D VIR_STORAGE_POOL_ISCSI_DIRECT && !def->source.initiator.iqn) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("missing initiator IQN")); - goto cleanup; + return NULL; } =20 /* Make a copy of all the callback pointers here for easier use, @@ -879,13 +872,9 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) def->ns =3D options->ns; if (def->ns.parse && (def->ns.parse)(ctxt, &def->namespaceData) < 0) - goto cleanup; + return NULL; =20 VIR_STEAL_PTR(ret, def); - cleanup: - VIR_FREE(uuid); - VIR_FREE(type); - VIR_FREE(target_path); return ret; } =20 @@ -1167,16 +1156,16 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, { virStorageVolDefPtr ret =3D NULL; virStorageVolOptionsPtr options; - char *type =3D NULL; - char *allocation =3D NULL; - char *capacity =3D NULL; - char *unit =3D NULL; - char *backingStore =3D NULL; xmlNodePtr node; - xmlNodePtr *nodes =3D NULL; size_t i; int n; VIR_AUTOPTR(virStorageVolDef) def =3D NULL; + VIR_AUTOFREE(char *) type =3D NULL; + VIR_AUTOFREE(char *) allocation =3D NULL; + VIR_AUTOFREE(char *) capacity =3D NULL; + VIR_AUTOFREE(char *) unit =3D NULL; + VIR_AUTOFREE(char *) backingStore =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; =20 virCheckFlags(VIR_VOL_XML_PARSE_NO_CAPACITY | VIR_VOL_XML_PARSE_OPT_CAPACITY, NULL); @@ -1194,7 +1183,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, if (def->name =3D=3D NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing volume name element")); - goto cleanup; + return NULL; } =20 /* Normally generated by pool refresh, but useful for unit tests */ @@ -1206,13 +1195,13 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, if ((def->type =3D virStorageVolTypeFromString(type)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown volume type '%s'"), type); - goto cleanup; + return NULL; } } =20 if ((backingStore =3D virXPathString("string(./backingStore/path)", ct= xt))) { if (VIR_ALLOC(def->target.backingStore) < 0) - goto cleanup; + return NULL; =20 def->target.backingStore->type =3D VIR_STORAGE_TYPE_FILE; =20 @@ -1220,7 +1209,9 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, backingStore =3D NULL; =20 if (options->formatFromString) { - char *format =3D virXPathString("string(./backingStore/format/= @type)", ctxt); + VIR_AUTOFREE(char *) format =3D NULL; + + format =3D virXPathString("string(./backingStore/format/@type)= ", ctxt); if (format =3D=3D NULL) def->target.backingStore->format =3D options->defaultForma= t; else @@ -1229,29 +1220,27 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, if (def->target.backingStore->format < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown volume format type %s"), format); - VIR_FREE(format); - goto cleanup; + return NULL; } - VIR_FREE(format); } =20 if (VIR_ALLOC(def->target.backingStore->perms) < 0) - goto cleanup; + return NULL; if (virStorageDefParsePerms(ctxt, def->target.backingStore->perms, "./backingStore/permissions") < 0) - goto cleanup; + return NULL; } =20 capacity =3D virXPathString("string(./capacity)", ctxt); unit =3D virXPathString("string(./capacity/@unit)", ctxt); if (capacity) { if (virStorageSize(unit, capacity, &def->target.capacity) < 0) - goto cleanup; + return NULL; } else if (!(flags & VIR_VOL_XML_PARSE_NO_CAPACITY) && !((flags & VIR_VOL_XML_PARSE_OPT_CAPACITY) && virStorageSourceHasBacking(&def->target))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing capacity elemen= t")); - goto cleanup; + return NULL; } VIR_FREE(unit); =20 @@ -1259,7 +1248,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, if (allocation) { unit =3D virXPathString("string(./allocation/@unit)", ctxt); if (virStorageSize(unit, allocation, &def->target.allocation) < 0) - goto cleanup; + return NULL; def->target.has_allocation =3D true; } else { def->target.allocation =3D def->target.capacity; @@ -1267,7 +1256,9 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, =20 def->target.path =3D virXPathString("string(./target/path)", ctxt); if (options->formatFromString) { - char *format =3D virXPathString("string(./target/format/@type)", c= txt); + VIR_AUTOFREE(char *) format =3D NULL; + + format =3D virXPathString("string(./target/format/@type)", ctxt); if (format =3D=3D NULL) def->target.format =3D options->defaultFormat; else @@ -1276,41 +1267,39 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, if (def->target.format < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown volume format type %s"), format); - VIR_FREE(format); - goto cleanup; + return NULL; } - VIR_FREE(format); } =20 if (VIR_ALLOC(def->target.perms) < 0) - goto cleanup; + return NULL; if (virStorageDefParsePerms(ctxt, def->target.perms, "./target/permissions") < 0) - goto cleanup; + return NULL; =20 node =3D virXPathNode("./target/encryption", ctxt); if (node !=3D NULL) { def->target.encryption =3D virStorageEncryptionParseNode(node, ctx= t); if (def->target.encryption =3D=3D NULL) - goto cleanup; + return NULL; } =20 def->target.compat =3D virXPathString("string(./target/compat)", ctxt); if (virStorageFileCheckCompat(def->target.compat) < 0) - goto cleanup; + return NULL; =20 if (virXPathNode("./target/nocow", ctxt)) def->target.nocow =3D true; =20 if (virXPathNode("./target/features", ctxt)) { if ((n =3D virXPathNodeSet("./target/features/*", ctxt, &nodes)) <= 0) - goto cleanup; + return NULL; =20 if (!def->target.compat && VIR_STRDUP(def->target.compat, "1.1") <= 0) - goto cleanup; + return NULL; =20 if (!(def->target.features =3D virBitmapNew(VIR_STORAGE_FILE_FEATU= RE_LAST))) - goto cleanup; + return NULL; =20 for (i =3D 0; i < n; i++) { int f =3D virStorageFileFeatureTypeFromString((const char*)nod= es[i]->name); @@ -1318,7 +1307,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, if (f < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unsupported = feature %s"), (const char*)nodes[i]->name); - goto cleanup; + return NULL; } ignore_value(virBitmapSetBit(def->target.features, f)); } @@ -1326,14 +1315,6 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, } =20 VIR_STEAL_PTR(ret, def); - - cleanup: - VIR_FREE(nodes); - VIR_FREE(allocation); - VIR_FREE(capacity); - VIR_FREE(unit); - VIR_FREE(type); - VIR_FREE(backingStore); return ret; } =20 @@ -1615,32 +1596,27 @@ virStoragePoolSaveState(const char *stateFile, virStoragePoolDefPtr def) { virBuffer buf =3D VIR_BUFFER_INITIALIZER; - int ret =3D -1; - char *xml; + VIR_AUTOFREE(char *) xml =3D NULL; =20 virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); =20 if (virStoragePoolDefFormatBuf(&buf, def) < 0) - goto error; + return -1; =20 virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); =20 if (virBufferCheckError(&buf) < 0) - goto error; + return -1; =20 if (!(xml =3D virBufferContentAndReset(&buf))) - goto error; + return -1; =20 if (virStoragePoolSaveXML(stateFile, def, xml)) - goto error; - - ret =3D 0; + return -1; =20 - error: - VIR_FREE(xml); - return ret; + return 0; } =20 =20 @@ -1648,8 +1624,7 @@ int virStoragePoolSaveConfig(const char *configFile, virStoragePoolDefPtr def) { - char *xml; - int ret =3D -1; + VIR_AUTOFREE(char *) xml =3D NULL; =20 if (!(xml =3D virStoragePoolDefFormat(def))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1657,13 +1632,7 @@ virStoragePoolSaveConfig(const char *configFile, return -1; } =20 - if (virStoragePoolSaveXML(configFile, def, xml)) - goto cleanup; - - ret =3D 0; - cleanup: - VIR_FREE(xml); - return ret; + return virStoragePoolSaveXML(configFile, def, xml); } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651113764720.7130867253331; Fri, 8 Feb 2019 10:38:33 -0800 (PST) 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 05A7388317; Fri, 8 Feb 2019 18:38:32 +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 B122462986; Fri, 8 Feb 2019 18:38:31 +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 5594218033BC; Fri, 8 Feb 2019 18:38:31 +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 x18IbgZr007664 for ; Fri, 8 Feb 2019 13:37:43 -0500 Received: by smtp.corp.redhat.com (Postfix) id F06BB60C55; Fri, 8 Feb 2019 18:37:42 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94E1460BE0; Fri, 8 Feb 2019 18:37:42 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:11 -0500 Message-Id: <20190208183726.30903-18-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 17/32] util: Use VIR_STEAL_PTR in virstoragefile 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: , 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.28]); Fri, 08 Feb 2019 18:38:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" virStorageFileGetRelativeBackingPath and virStorageFileGetMetadataRecurse open coded. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/util/virstoragefile.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 828e95d5d3..c6425308fb 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -4208,8 +4208,7 @@ virStorageFileGetRelativeBackingPath(virStorageSource= Ptr top, goto cleanup; } =20 - *relpath =3D path; - path =3D NULL; + VIR_STEAL_PTR(*relpath, path); =20 ret =3D 0; =20 @@ -4947,8 +4946,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr = src, goto cleanup; } =20 - src->backingStore =3D backingStore; - backingStore =3D NULL; + VIR_STEAL_PTR(src->backingStore, backingStore); ret =3D 0; =20 cleanup: --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651114545823.1168611426077; Fri, 8 Feb 2019 10:38:34 -0800 (PST) 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 52468882EA; Fri, 8 Feb 2019 18:38:32 +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 E174417F3F; Fri, 8 Feb 2019 18:38:31 +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 89A2318033BB; Fri, 8 Feb 2019 18:38:31 +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 x18IbhwD007671 for ; Fri, 8 Feb 2019 13:37:43 -0500 Received: by smtp.corp.redhat.com (Postfix) id 813F1383F; Fri, 8 Feb 2019 18:37:43 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 25F1F60BE0; Fri, 8 Feb 2019 18:37:43 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:12 -0500 Message-Id: <20190208183726.30903-19-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 18/32] util: Use VIR_AUTOFREE for virstoragefile 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: , 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.28]); Fri, 08 Feb 2019 18:38:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/util/virstoragefile.c | 128 ++++++++++++++------------------------ 1 file changed, 46 insertions(+), 82 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index c6425308fb..fddfea65db 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -595,9 +595,10 @@ vmdk4GetBackingStore(char **res, size_t buf_size) { static const char prefix[] =3D "parentFileNameHint=3D\""; - char *desc, *start, *end; + char *start, *end; size_t len; int ret =3D BACKING_STORE_ERROR; + VIR_AUTOFREE(char *) desc =3D NULL; =20 if (VIR_ALLOC_N(desc, VIR_STORAGE_MAX_HEADER) < 0) goto cleanup; @@ -645,7 +646,6 @@ vmdk4GetBackingStore(char **res, ret =3D BACKING_STORE_OK; =20 cleanup: - VIR_FREE(desc); return ret; } =20 @@ -1084,7 +1084,7 @@ virStorageFileProbeFormat(const char *path, uid_t uid= , gid_t gid) int ret =3D -1; struct stat sb; ssize_t len =3D VIR_STORAGE_MAX_HEADER; - char *header =3D NULL; + VIR_AUTOFREE(char *) header =3D NULL; =20 if ((fd =3D virFileOpenAs(path, O_RDONLY, 0, uid, gid, 0)) < 0) { virReportSystemError(-fd, _("Failed to open file '%s'"), path); @@ -1115,7 +1115,6 @@ virStorageFileProbeFormat(const char *path, uid_t uid= , gid_t gid) ret =3D virStorageFileProbeFormatFromBuf(path, header, len); =20 cleanup: - VIR_FREE(header); VIR_FORCE_CLOSE(fd); =20 return ret; @@ -1215,10 +1214,10 @@ virStorageFileGetMetadataFromFD(const char *path, { virStorageSourcePtr ret =3D NULL; virStorageSourcePtr meta =3D NULL; - char *buf =3D NULL; ssize_t len =3D VIR_STORAGE_MAX_HEADER; struct stat sb; int dummy; + VIR_AUTOFREE(char *) buf =3D NULL; =20 if (!backingFormat) backingFormat =3D &dummy; @@ -1265,7 +1264,6 @@ virStorageFileGetMetadataFromFD(const char *path, =20 cleanup: virStorageSourceFree(meta); - VIR_FREE(buf); return ret; } =20 @@ -1614,8 +1612,7 @@ virStorageFileParseChainIndex(const char *diskTarget, unsigned int *chainIndex) { unsigned int idx =3D 0; - char *target =3D NULL; - int ret =3D 0; + VIR_AUTOFREE(char *) target =3D NULL; =20 *chainIndex =3D 0; =20 @@ -1626,21 +1623,18 @@ virStorageFileParseChainIndex(const char *diskTarge= t, return 0; =20 if (idx =3D=3D 0) - goto cleanup; + return 0; =20 if (STRNEQ(diskTarget, target)) { virReportError(VIR_ERR_INVALID_ARG, _("requested target '%s' does not match target '%s'= "), target, diskTarget); - ret =3D -1; - goto cleanup; + return -1; } =20 *chainIndex =3D idx; =20 - cleanup: - VIR_FREE(target); - return ret; + return 0; } =20 =20 @@ -1891,8 +1885,8 @@ virStorageAuthDefParse(xmlNodePtr node, xmlNodePtr saveNode =3D ctxt->node; virStorageAuthDefPtr ret =3D NULL; xmlNodePtr secretnode =3D NULL; - char *authtype =3D NULL; VIR_AUTOPTR(virStorageAuthDef) authdef =3D NULL; + VIR_AUTOFREE(char *) authtype =3D NULL; =20 ctxt->node =3D node; =20 @@ -1939,7 +1933,6 @@ virStorageAuthDefParse(xmlNodePtr node, VIR_STEAL_PTR(ret, authdef); =20 cleanup: - VIR_FREE(authtype); ctxt->node =3D saveNode; =20 return ret; @@ -1983,10 +1976,10 @@ virStoragePRDefParseXML(xmlXPathContextPtr ctxt) { virStoragePRDefPtr prd; virStoragePRDefPtr ret =3D NULL; - char *managed =3D NULL; - char *type =3D NULL; - char *path =3D NULL; - char *mode =3D NULL; + VIR_AUTOFREE(char *) managed =3D NULL; + VIR_AUTOFREE(char *) type =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) mode =3D NULL; =20 if (VIR_ALLOC(prd) < 0) return NULL; @@ -2045,10 +2038,6 @@ virStoragePRDefParseXML(xmlXPathContextPtr ctxt) VIR_STEAL_PTR(ret, prd); =20 cleanup: - VIR_FREE(mode); - VIR_FREE(path); - VIR_FREE(type); - VIR_FREE(managed); virStoragePRDefFree(prd); return ret; } @@ -2601,8 +2590,8 @@ static virStorageSourcePtr virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent, const char *rel) { - char *dirname =3D NULL; virStorageSourcePtr ret; + VIR_AUTOFREE(char *) dirname =3D NULL; =20 if (VIR_ALLOC(ret) < 0) return NULL; @@ -2645,7 +2634,6 @@ virStorageSourceNewFromBackingRelative(virStorageSour= cePtr parent, } =20 cleanup: - VIR_FREE(dirname); return ret; =20 error: @@ -2809,8 +2797,8 @@ int virStorageSourceParseRBDColonString(const char *rbdstr, virStorageSourcePtr src) { - char *options =3D NULL; char *p, *e, *next; + VIR_AUTOFREE(char *) options =3D NULL; VIR_AUTOPTR(virStorageAuthDef) authdef =3D NULL; =20 /* optionally skip the "rbd:" prefix if provided */ @@ -2818,19 +2806,19 @@ virStorageSourceParseRBDColonString(const char *rbd= str, rbdstr +=3D strlen("rbd:"); =20 if (VIR_STRDUP(src->path, rbdstr) < 0) - goto error; + return -1; =20 p =3D strchr(src->path, ':'); if (p) { if (VIR_STRDUP(options, p + 1) < 0) - goto error; + return -1; *p =3D '\0'; } =20 /* snapshot name */ if ((p =3D strchr(src->path, '@'))) { if (VIR_STRDUP(src->snapshot, p + 1) < 0) - goto error; + return -1; *p =3D '\0'; } =20 @@ -2838,7 +2826,7 @@ virStorageSourceParseRBDColonString(const char *rbdst= r, if ((p =3D strchr(src->path, '/'))) { VIR_STEAL_PTR(src->volume, src->path); if (VIR_STRDUP(src->path, p + 1) < 0) - goto error; + return -1; *p =3D '\0'; } =20 @@ -2866,14 +2854,14 @@ virStorageSourceParseRBDColonString(const char *rbd= str, if (STRPREFIX(p, "id=3D")) { /* formulate authdef for src->auth */ if (VIR_ALLOC(authdef) < 0) - goto error; + return -1; =20 if (VIR_STRDUP(authdef->username, p + strlen("id=3D")) < 0) - goto error; + return -1; =20 if (VIR_STRDUP(authdef->secrettype, virSecretUsageTypeToString(VIR_SECRET_USAGE_TYP= E_CEPH)) < 0) - goto error; + return -1; VIR_STEAL_PTR(src->auth, authdef); src->authInherited =3D true; =20 @@ -2897,7 +2885,7 @@ virStorageSourceParseRBDColonString(const char *rbdst= r, } =20 if (virStorageSourceRBDAddHost(src, h) < 0) - goto error; + return -1; =20 h =3D sep; } @@ -2905,16 +2893,11 @@ virStorageSourceParseRBDColonString(const char *rbd= str, =20 if (STRPREFIX(p, "conf=3D") && VIR_STRDUP(src->configFile, p + strlen("conf=3D")) < 0) - goto error; + return -1; =20 p =3D next; } - VIR_FREE(options); return 0; - - error: - VIR_FREE(options); - return -1; } =20 =20 @@ -2983,36 +2966,35 @@ static int virStorageSourceParseBackingColon(virStorageSourcePtr src, const char *path) { - char *protocol =3D NULL; const char *p; - int ret =3D -1; + VIR_AUTOFREE(char *) protocol =3D NULL; =20 if (!(p =3D strchr(path, ':'))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("invalid backing protocol string '%s'"), path); - goto cleanup; + return -1; } =20 if (VIR_STRNDUP(protocol, path, p - path) < 0) - goto cleanup; + return -1; =20 if ((src->protocol =3D virStorageNetProtocolTypeFromString(protocol)) = < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("invalid backing protocol '%s'"), protocol); - goto cleanup; + return -1; } =20 switch ((virStorageNetProtocol) src->protocol) { case VIR_STORAGE_NET_PROTOCOL_NBD: if (virStorageSourceParseNBDColonString(path, src) < 0) - goto cleanup; + return -1; break; =20 case VIR_STORAGE_NET_PROTOCOL_RBD: if (virStorageSourceParseRBDColonString(path, src) < 0) - goto cleanup; + return -1; break; =20 case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: @@ -3021,7 +3003,7 @@ virStorageSourceParseBackingColon(virStorageSourcePtr= src, virReportError(VIR_ERR_INTERNAL_ERROR, _("backing store parser is not implemented for prot= ocol %s"), protocol); - goto cleanup; + return -1; =20 case VIR_STORAGE_NET_PROTOCOL_HTTP: case VIR_STORAGE_NET_PROTOCOL_HTTPS: @@ -3035,14 +3017,10 @@ virStorageSourceParseBackingColon(virStorageSourceP= tr src, virReportError(VIR_ERR_INTERNAL_ERROR, _("malformed backing store path for protocol %s"), protocol); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(protocol); - return ret; + return 0; } =20 =20 @@ -3593,9 +3571,9 @@ virStorageSourceParseBackingJSONInternal(virStorageSo= urcePtr src, virJSONValuePtr deflattened =3D NULL; virJSONValuePtr file; const char *drvname; - char *str =3D NULL; size_t i; int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; =20 if (!(deflattened =3D virJSONValueObjectDeflatten(json))) goto cleanup; @@ -3628,7 +3606,6 @@ virStorageSourceParseBackingJSONInternal(virStorageSo= urcePtr src, "driver '%s'"), drvname); =20 cleanup: - VIR_FREE(str); virJSONValueFree(deflattened); return ret; } @@ -3997,12 +3974,12 @@ virStorageFileCanonicalizePath(const char *path, bool beginDoubleSlash =3D false; char **components =3D NULL; size_t ncomponents =3D 0; - char *linkpath =3D NULL; - char *currentpath =3D NULL; size_t i =3D 0; size_t j =3D 0; int rc; char *ret =3D NULL; + VIR_AUTOFREE(char *) linkpath =3D NULL; + VIR_AUTOFREE(char *) currentpath =3D NULL; =20 if (path[0] =3D=3D '/') { beginSlash =3D true; @@ -4131,8 +4108,6 @@ virStorageFileCanonicalizePath(const char *path, cleanup: virHashFree(cycle); virStringListFreeCount(components, ncomponents); - VIR_FREE(linkpath); - VIR_FREE(currentpath); =20 return ret; } @@ -4175,25 +4150,22 @@ virStorageFileGetRelativeBackingPath(virStorageSour= cePtr top, char **relpath) { virStorageSourcePtr next; - char *tmp =3D NULL; - char *path =3D NULL; - char ret =3D -1; + VIR_AUTOFREE(char *) tmp =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; =20 *relpath =3D NULL; =20 for (next =3D top; virStorageSourceIsBacking(next); next =3D next->bac= kingStore) { - if (!next->relPath) { - ret =3D 1; - goto cleanup; - } + if (!next->relPath) + return 1; =20 if (!(tmp =3D virStorageFileRemoveLastPathComponent(path))) - goto cleanup; + return -1; =20 VIR_FREE(path); =20 if (virAsprintf(&path, "%s%s", tmp, next->relPath) < 0) - goto cleanup; + return -1; =20 VIR_FREE(tmp); =20 @@ -4205,17 +4177,11 @@ virStorageFileGetRelativeBackingPath(virStorageSour= cePtr top, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to resolve relative backing name: " "base image is not in backing chain")); - goto cleanup; + return -1; } =20 VIR_STEAL_PTR(*relpath, path); - - ret =3D 0; - - cleanup: - VIR_FREE(path); - VIR_FREE(tmp); - return ret; + return 0; } =20 =20 @@ -4866,11 +4832,11 @@ virStorageFileGetMetadataRecurse(virStorageSourcePt= r src, { int ret =3D -1; const char *uniqueName; - char *buf =3D NULL; ssize_t headerLen; virStorageSourcePtr backingStore =3D NULL; int backingFormat; int rv; + VIR_AUTOFREE(char *) buf =3D NULL; =20 VIR_DEBUG("path=3D%s format=3D%d uid=3D%u gid=3D%u", src->path, src->format, @@ -4952,7 +4918,6 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr = src, cleanup: if (virStorageSourceHasBacking(src)) src->backingStore->id =3D depth; - VIR_FREE(buf); virStorageFileDeinit(src); virStorageSourceFree(backingStore); return ret; @@ -5024,10 +4989,10 @@ virStorageFileGetBackingStoreStr(virStorageSourcePt= r src, char **backing) { virStorageSourcePtr tmp =3D NULL; - char *buf =3D NULL; ssize_t headerLen; int ret =3D -1; int rv; + VIR_AUTOFREE(char *) buf =3D NULL; =20 *backing =3D NULL; =20 @@ -5061,7 +5026,6 @@ virStorageFileGetBackingStoreStr(virStorageSourcePtr = src, ret =3D 0; =20 cleanup: - VIR_FREE(buf); virStorageSourceFree(tmp); =20 return ret; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651093540818.6049650611964; Fri, 8 Feb 2019 10:38:13 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A7E5F637F9; Fri, 8 Feb 2019 18:38:11 +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 516A010002B9; Fri, 8 Feb 2019 18:38: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 02E1E3F60C; Fri, 8 Feb 2019 18:38:11 +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 x18IbkHQ007692 for ; Fri, 8 Feb 2019 13:37:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id D5C8E60BE0; Fri, 8 Feb 2019 18:37:46 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A15262F83; Fri, 8 Feb 2019 18:37:43 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:13 -0500 Message-Id: <20190208183726.30903-20-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 19/32] test: Cleanup testDomainRenameCallback 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 08 Feb 2019 18:38:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Rather than have a need for old_dom_name, let's just VIR_FREE the old name first, then use VIR_STEAL_PTR to handle the swap from the old name to the new name. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/test/test_driver.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index df10a02bbc..f51efa51b7 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2579,7 +2579,6 @@ testDomainRenameCallback(virDomainObjPtr privdom, virObjectEventPtr event_old =3D NULL; int ret =3D -1; char *new_dom_name =3D NULL; - char *old_dom_name =3D NULL; =20 virCheckFlags(0, -1); =20 @@ -2597,9 +2596,8 @@ testDomainRenameCallback(virDomainObjPtr privdom, VIR_DOMAIN_EVENT_UNDEFIN= ED_RENAMED); =20 /* Switch name in domain definition. */ - old_dom_name =3D privdom->def->name; - privdom->def->name =3D new_dom_name; - new_dom_name =3D NULL; + VIR_FREE(privdom->def->name); + VIR_STEAL_PTR(privdom->def->name, new_dom_name); =20 event_new =3D virDomainEventLifecycleNewFromObj(privdom, VIR_DOMAIN_EVENT_DEFINED, @@ -2607,7 +2605,6 @@ testDomainRenameCallback(virDomainObjPtr privdom, ret =3D 0; =20 cleanup: - VIR_FREE(old_dom_name); VIR_FREE(new_dom_name); virObjectEventStateQueue(driver->eventState, event_old); virObjectEventStateQueue(driver->eventState, event_new); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651121230862.4113754194448; Fri, 8 Feb 2019 10:38:41 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 41424CD66C; Fri, 8 Feb 2019 18:38:39 +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 061F127067; Fri, 8 Feb 2019 18:38:39 +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 A4F423D39B; Fri, 8 Feb 2019 18:38:38 +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 x18IblAI007703 for ; Fri, 8 Feb 2019 13:37:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id 651E1BA53; Fri, 8 Feb 2019 18:37:47 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C04B60BE0; Fri, 8 Feb 2019 18:37:46 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:14 -0500 Message-Id: <20190208183726.30903-21-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 20/32] test: Remove unused @xml from testDomainSnapshotCreateXML 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 08 Feb 2019 18:38:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Commit 390c06b67 added @xml, but it was never used. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/test/test_driver.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index f51efa51b7..1dde92e961 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -6339,7 +6339,6 @@ testDomainSnapshotCreateXML(virDomainPtr domain, virDomainSnapshotObjPtr snap =3D NULL; virDomainSnapshotPtr snapshot =3D NULL; virObjectEventPtr event =3D NULL; - char *xml =3D NULL; bool update_current =3D true; bool redefine =3D flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE; unsigned int parse_flags =3D VIR_DOMAIN_SNAPSHOT_PARSE_DISKS; @@ -6424,7 +6423,6 @@ testDomainSnapshotCreateXML(virDomainPtr domain, =20 snapshot =3D virGetDomainSnapshot(domain, snap->def->name); cleanup: - VIR_FREE(xml); if (vm) { if (snapshot) { virDomainSnapshotObjPtr other; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651126726460.12530506088274; Fri, 8 Feb 2019 10:38:46 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DD97410FA5; Fri, 8 Feb 2019 18:38:44 +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 9201E106F74B; Fri, 8 Feb 2019 18:38:44 +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 2676C3D3A8; Fri, 8 Feb 2019 18:38:44 +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 x18IbuJx007747 for ; Fri, 8 Feb 2019 13:37:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9908853B2E; Fri, 8 Feb 2019 18:37:56 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3271E383F; Fri, 8 Feb 2019 18:37:47 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:15 -0500 Message-Id: <20190208183726.30903-22-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 21/32] test: Use VIR_AUTOFREE for test driver 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 08 Feb 2019 18:38:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/test/test_driver.c | 169 ++++++++++++++++------------------------- 1 file changed, 66 insertions(+), 103 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 1dde92e961..f748cc32f0 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -200,10 +200,10 @@ testDomainDefNamespaceParse(xmlDocPtr xml ATTRIBUTE_U= NUSED, void **data) { testDomainNamespaceDefPtr nsdata =3D NULL; - xmlNodePtr *nodes =3D NULL; int tmp, n; size_t i; unsigned int tmpuint; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; =20 if (xmlXPathRegisterNs(ctxt, BAD_CAST "test", BAD_CAST TEST_NAMESPACE_HREF) < 0) { @@ -233,7 +233,6 @@ testDomainDefNamespaceParse(xmlDocPtr xml ATTRIBUTE_UNU= SED, nsdata->snap_nodes[nsdata->num_snap_nodes] =3D newnode; nsdata->num_snap_nodes++; } - VIR_FREE(nodes); =20 tmp =3D virXPathBoolean("boolean(./test:transient)", ctxt); if (tmp =3D=3D -1) { @@ -280,7 +279,6 @@ testDomainDefNamespaceParse(xmlDocPtr xml ATTRIBUTE_UNU= SED, return 0; =20 error: - VIR_FREE(nodes); testDomainDefNamespaceFree(nsdata); return -1; } @@ -695,11 +693,10 @@ testParseXMLDocFromFile(xmlNodePtr node, const char *= file, const char *type) xmlNodePtr ret =3D NULL; xmlDocPtr doc =3D NULL; char *absFile =3D NULL; - char *relFile =3D virXMLPropString(node, "file"); + VIR_AUTOFREE(char *) relFile =3D NULL; =20 - if (relFile !=3D NULL) { + if ((relFile =3D virXMLPropString(node, "file"))) { absFile =3D testBuildFilename(file, relFile); - VIR_FREE(relFile); if (!absFile) { virReportError(VIR_ERR_INTERNAL_ERROR, _("resolving %s filename"), type); @@ -722,16 +719,15 @@ testParseXMLDocFromFile(xmlNodePtr node, const char *= file, const char *type) =20 error: xmlFreeDoc(doc); - VIR_FREE(absFile); return ret; } =20 static int testParseNodeInfo(virNodeInfoPtr nodeInfo, xmlXPathContextPtr ctxt) { - char *str; long l; int ret; + VIR_AUTOFREE(char *) str =3D NULL; =20 ret =3D virXPathLong("string(/node/cpu/nodes[1])", ctxt, &l); if (ret =3D=3D 0) { @@ -794,10 +790,8 @@ testParseNodeInfo(virNodeInfoPtr nodeInfo, xmlXPathCon= textPtr ctxt) if (virStrcpyStatic(nodeInfo->model, str) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Model %s too big for destination"), str); - VIR_FREE(str); goto error; } - VIR_FREE(str); } =20 ret =3D virXPathLong("string(/node/memory[1])", ctxt, &l); @@ -877,12 +871,12 @@ testParseDomains(testDriverPtr privconn, { int num, ret =3D -1; size_t i; - xmlNodePtr *nodes =3D NULL; virDomainObjPtr obj =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; =20 num =3D virXPathNodeSet("/node/domain", ctxt, &nodes); if (num < 0) - goto error; + return -1; =20 for (i =3D 0; i < num; i++) { virDomainDefPtr def; @@ -928,7 +922,6 @@ testParseDomains(testDriverPtr privconn, ret =3D 0; error: virDomainObjEndAPI(&obj); - VIR_FREE(nodes); return ret; } =20 @@ -938,38 +931,35 @@ testParseNetworks(testDriverPtr privconn, const char *file, xmlXPathContextPtr ctxt) { - int num, ret =3D -1; + int num; size_t i; - xmlNodePtr *nodes =3D NULL; virNetworkObjPtr obj; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; =20 num =3D virXPathNodeSet("/node/network", ctxt, &nodes); if (num < 0) - goto error; + return -1; =20 for (i =3D 0; i < num; i++) { virNetworkDefPtr def; xmlNodePtr node =3D testParseXMLDocFromFile(nodes[i], file, "netwo= rk"); if (!node) - goto error; + return -1; =20 def =3D virNetworkDefParseNode(ctxt->doc, node); if (!def) - goto error; + return -1; =20 if (!(obj =3D virNetworkObjAssignDef(privconn->networks, def, 0)))= { virNetworkDefFree(def); - goto error; + return -1; } =20 virNetworkObjSetActive(obj, true); virNetworkObjEndAPI(&obj); } =20 - ret =3D 0; - error: - VIR_FREE(nodes); - return ret; + return 0; } =20 =20 @@ -978,39 +968,36 @@ testParseInterfaces(testDriverPtr privconn, const char *file, xmlXPathContextPtr ctxt) { - int num, ret =3D -1; + int num; size_t i; - xmlNodePtr *nodes =3D NULL; virInterfaceObjPtr obj; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; =20 num =3D virXPathNodeSet("/node/interface", ctxt, &nodes); if (num < 0) - goto error; + return -1; =20 for (i =3D 0; i < num; i++) { virInterfaceDefPtr def; xmlNodePtr node =3D testParseXMLDocFromFile(nodes[i], file, "interface"); if (!node) - goto error; + return -1; =20 def =3D virInterfaceDefParseNode(ctxt->doc, node); if (!def) - goto error; + return -1; =20 if (!(obj =3D virInterfaceObjListAssignDef(privconn->ifaces, def))= ) { virInterfaceDefFree(def); - goto error; + return -1; } =20 virInterfaceObjSetActive(obj, true); virInterfaceObjEndAPI(&obj); } =20 - ret =3D 0; - error: - VIR_FREE(nodes); - return ret; + return 0; } =20 =20 @@ -1021,51 +1008,47 @@ testOpenVolumesForPool(const char *file, int objidx) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(obj); - char *vol_xpath; size_t i; - int num, ret =3D -1; - xmlNodePtr *nodes =3D NULL; + int num; + VIR_AUTOFREE(char *) vol_xpath =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; VIR_AUTOPTR(virStorageVolDef) volDef =3D NULL; =20 /* Find storage volumes */ if (virAsprintf(&vol_xpath, "/node/pool[%d]/volume", objidx) < 0) - goto error; + return -1; =20 num =3D virXPathNodeSet(vol_xpath, ctxt, &nodes); - VIR_FREE(vol_xpath); if (num < 0) - goto error; + return -1; =20 for (i =3D 0; i < num; i++) { xmlNodePtr node =3D testParseXMLDocFromFile(nodes[i], file, "volume"); if (!node) - goto error; + return -1; =20 if (!(volDef =3D virStorageVolDefParseNode(def, ctxt->doc, node, 0= ))) - goto error; + return -1; =20 if (!volDef->target.path) { if (virAsprintf(&volDef->target.path, "%s/%s", def->target.path, volDef->name) < 0) - goto error; + return -1; } =20 if (!volDef->key && VIR_STRDUP(volDef->key, volDef->target.path) <= 0) - goto error; + return -1; =20 if (virStoragePoolObjAddVol(obj, volDef) < 0) - goto error; + return -1; =20 def->allocation +=3D volDef->target.allocation; def->available =3D (def->capacity - def->allocation); volDef =3D NULL; } =20 - ret =3D 0; - error: - VIR_FREE(nodes); - return ret; + return 0; } =20 =20 @@ -1074,50 +1057,47 @@ testParseStorage(testDriverPtr privconn, const char *file, xmlXPathContextPtr ctxt) { - int num, ret =3D -1; + int num; size_t i; - xmlNodePtr *nodes =3D NULL; virStoragePoolObjPtr obj; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; =20 num =3D virXPathNodeSet("/node/pool", ctxt, &nodes); if (num < 0) - goto error; + return -1; =20 for (i =3D 0; i < num; i++) { virStoragePoolDefPtr def; xmlNodePtr node =3D testParseXMLDocFromFile(nodes[i], file, "pool"); if (!node) - goto error; + return -1; =20 def =3D virStoragePoolDefParseNode(ctxt->doc, node); if (!def) - goto error; + return -1; =20 if (!(obj =3D virStoragePoolObjAssignDef(privconn->pools, def, fal= se))) { virStoragePoolDefFree(def); - goto error; + return -1; } =20 if (testStoragePoolObjSetDefaults(obj) =3D=3D -1) { virStoragePoolObjEndAPI(&obj); - goto error; + return -1; } virStoragePoolObjSetActive(obj, true); =20 /* Find storage volumes */ if (testOpenVolumesForPool(file, ctxt, obj, i+1) < 0) { virStoragePoolObjEndAPI(&obj); - goto error; + return -1; } =20 virStoragePoolObjEndAPI(&obj); } =20 - ret =3D 0; - error: - VIR_FREE(nodes); - return ret; + return 0; } =20 =20 @@ -1126,79 +1106,70 @@ testParseNodedevs(testDriverPtr privconn, const char *file, xmlXPathContextPtr ctxt) { - int num, ret =3D -1; + int num; size_t i; - xmlNodePtr *nodes =3D NULL; virNodeDeviceObjPtr obj; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; =20 num =3D virXPathNodeSet("/node/device", ctxt, &nodes); if (num < 0) - goto error; + return -1; =20 for (i =3D 0; i < num; i++) { virNodeDeviceDefPtr def; xmlNodePtr node =3D testParseXMLDocFromFile(nodes[i], file, "nodedev"); if (!node) - goto error; + return -1; =20 def =3D virNodeDeviceDefParseNode(ctxt->doc, node, 0, NULL); if (!def) - goto error; + return -1; =20 if (!(obj =3D virNodeDeviceObjListAssignDef(privconn->devs, def)))= { virNodeDeviceDefFree(def); - goto error; + return -1; } =20 virNodeDeviceObjSetSkipUpdateCaps(obj, true); virNodeDeviceObjEndAPI(&obj); } =20 - ret =3D 0; - error: - VIR_FREE(nodes); - return ret; + return 0; } =20 static int testParseAuthUsers(testDriverPtr privconn, xmlXPathContextPtr ctxt) { - int num, ret =3D -1; + int num; size_t i; - xmlNodePtr *nodes =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; =20 num =3D virXPathNodeSet("/node/auth/user", ctxt, &nodes); if (num < 0) - goto error; + return -1; =20 privconn->numAuths =3D num; if (num && VIR_ALLOC_N(privconn->auths, num) < 0) - goto error; + return -1; =20 for (i =3D 0; i < num; i++) { - char *username, *password; + VIR_AUTOFREE(char *) username =3D NULL; =20 ctxt->node =3D nodes[i]; username =3D virXPathString("string(.)", ctxt); if (!username || STREQ(username, "")) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing username in /node/auth/user field")); - VIR_FREE(username); - goto error; + return -1; } /* This field is optional. */ - password =3D virXMLPropString(nodes[i], "password"); - - privconn->auths[i].username =3D username; - privconn->auths[i].password =3D password; + privconn->auths[i].password =3D virXMLPropString(nodes[i], "passwo= rd"); + VIR_STEAL_PTR(privconn->auths[i].username, username); } =20 - ret =3D 0; - error: - VIR_FREE(nodes); - return ret; + return 0; } =20 static int @@ -1348,7 +1319,8 @@ testConnectAuthenticate(virConnectPtr conn, testDriverPtr privconn =3D conn->privateData; int ret =3D -1; ssize_t i; - char *username =3D NULL, *password =3D NULL; + VIR_AUTOFREE(char *) username =3D NULL; + VIR_AUTOFREE(char *) password =3D NULL; =20 virObjectLock(privconn); if (privconn->numAuths =3D=3D 0) { @@ -1388,8 +1360,6 @@ testConnectAuthenticate(virConnectPtr conn, ret =3D 0; cleanup: virObjectUnlock(privconn); - VIR_FREE(username); - VIR_FREE(password); return ret; } =20 @@ -1977,12 +1947,12 @@ testDomainSaveFlags(virDomainPtr domain, const char= *path, const char *dxml, unsigned int flags) { testDriverPtr privconn =3D domain->conn->privateData; - char *xml =3D NULL; int fd =3D -1; int len; virDomainObjPtr privdom; virObjectEventPtr event =3D NULL; int ret =3D -1; + VIR_AUTOFREE(char *) xml =3D NULL; =20 virCheckFlags(0, -1); if (dxml) { @@ -2052,8 +2022,6 @@ testDomainSaveFlags(virDomainPtr domain, const char *= path, =20 ret =3D 0; cleanup: - VIR_FREE(xml); - /* Don't report failure in close or unlink, because * in either case we're already in a failure scenario * and have reported an earlier error */ @@ -2080,7 +2048,6 @@ testDomainRestoreFlags(virConnectPtr conn, unsigned int flags) { testDriverPtr privconn =3D conn->privateData; - char *xml =3D NULL; char magic[15]; int fd =3D -1; int len; @@ -2088,6 +2055,7 @@ testDomainRestoreFlags(virConnectPtr conn, virDomainObjPtr dom =3D NULL; virObjectEventPtr event =3D NULL; int ret =3D -1; + VIR_AUTOFREE(char *) xml =3D NULL; =20 virCheckFlags(0, -1); if (dxml) { @@ -2162,7 +2130,6 @@ testDomainRestoreFlags(virConnectPtr conn, =20 cleanup: virDomainDefFree(def); - VIR_FREE(xml); VIR_FORCE_CLOSE(fd); virDomainObjEndAPI(&dom); virObjectEventStateQueue(privconn->eventState, event); @@ -2578,7 +2545,7 @@ testDomainRenameCallback(virDomainObjPtr privdom, virObjectEventPtr event_new =3D NULL; virObjectEventPtr event_old =3D NULL; int ret =3D -1; - char *new_dom_name =3D NULL; + VIR_AUTOFREE(char *) new_dom_name =3D NULL; =20 virCheckFlags(0, -1); =20 @@ -2605,7 +2572,6 @@ testDomainRenameCallback(virDomainObjPtr privdom, ret =3D 0; =20 cleanup: - VIR_FREE(new_dom_name); virObjectEventStateQueue(driver->eventState, event_old); virObjectEventStateQueue(driver->eventState, event_new); return ret; @@ -5468,12 +5434,12 @@ testNodeDeviceMockCreateVport(testDriverPtr driver, const char *wwnn, const char *wwpn) { - char *xml =3D NULL; virNodeDeviceDefPtr def =3D NULL; virNodeDevCapsDefPtr caps; virNodeDeviceObjPtr obj =3D NULL, objcopy =3D NULL; virNodeDeviceDefPtr objdef; virObjectEventPtr event =3D NULL; + VIR_AUTOFREE(char *) xml =3D NULL; =20 /* In the real code, we'd call virVHBAManageVport which would take the * wwnn/wwpn from the input XML in order to call the "vport_create" @@ -5537,7 +5503,6 @@ testNodeDeviceMockCreateVport(testDriverPtr driver, virObjectEventStateQueue(driver->eventState, event); =20 cleanup: - VIR_FREE(xml); virNodeDeviceDefFree(def); return obj; } @@ -5550,10 +5515,11 @@ testNodeDeviceCreateXML(virConnectPtr conn, { testDriverPtr driver =3D conn->privateData; virNodeDeviceDefPtr def =3D NULL; - char *wwnn =3D NULL, *wwpn =3D NULL; virNodeDevicePtr dev =3D NULL, ret =3D NULL; virNodeDeviceObjPtr obj =3D NULL; virNodeDeviceDefPtr objdef; + VIR_AUTOFREE(char *) wwnn =3D NULL; + VIR_AUTOFREE(char *) wwpn =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -5594,8 +5560,6 @@ testNodeDeviceCreateXML(virConnectPtr conn, virNodeDeviceObjEndAPI(&obj); virNodeDeviceDefFree(def); virObjectUnref(dev); - VIR_FREE(wwnn); - VIR_FREE(wwpn); return ret; } =20 @@ -5607,8 +5571,9 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) virNodeDeviceObjPtr obj =3D NULL; virNodeDeviceObjPtr parentobj =3D NULL; virNodeDeviceDefPtr def; - char *wwnn =3D NULL, *wwpn =3D NULL; virObjectEventPtr event =3D NULL; + VIR_AUTOFREE(char *) wwnn =3D NULL; + VIR_AUTOFREE(char *) wwpn =3D NULL; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) return -1; @@ -5646,8 +5611,6 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) cleanup: virNodeDeviceObjEndAPI(&obj); virObjectEventStateQueue(driver->eventState, event); - VIR_FREE(wwnn); - VIR_FREE(wwpn); return ret; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651098187825.1511309307299; Fri, 8 Feb 2019 10:38:18 -0800 (PST) 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 5703659479; Fri, 8 Feb 2019 18:38:16 +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 1E9175DF29; Fri, 8 Feb 2019 18:38:16 +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 B24A23F610; Fri, 8 Feb 2019 18:38:15 +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 x18Ic0aV007757 for ; Fri, 8 Feb 2019 13:38:00 -0500 Received: by smtp.corp.redhat.com (Postfix) id A9AFE17A65; Fri, 8 Feb 2019 18:38:00 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA24F60BE0; Fri, 8 Feb 2019 18:37:56 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:16 -0500 Message-Id: <20190208183726.30903-23-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 22/32] tests: Use VIR_AUTOFREE for various storage 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: , 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.39]); Fri, 08 Feb 2019 18:38:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- tests/storagebackendsheepdogtest.c | 50 ++++++++++++------------------ tests/storagepoolxml2argvtest.c | 18 +++-------- tests/storagepoolxml2xmltest.c | 33 ++++++-------------- tests/storagevolxml2argvtest.c | 42 +++++++++---------------- tests/storagevolxml2xmltest.c | 38 +++++++---------------- tests/virstoragetest.c | 45 +++++++-------------------- tests/virstorageutiltest.c | 7 ++--- 7 files changed, 75 insertions(+), 158 deletions(-) diff --git a/tests/storagebackendsheepdogtest.c b/tests/storagebackendsheep= dogtest.c index 03ddf76d65..1806f9725f 100644 --- a/tests/storagebackendsheepdogtest.c +++ b/tests/storagebackendsheepdogtest.c @@ -57,32 +57,27 @@ test_node_info_parser(const void *opaque) { const struct testNodeInfoParserData *data =3D opaque; collie_test test =3D data->data; - int ret =3D -1; - char *output =3D NULL; + VIR_AUTOFREE(char *) output =3D NULL; VIR_AUTOPTR(virStoragePoolDef) pool =3D NULL; =20 if (!(pool =3D virStoragePoolDefParseFile(data->poolxml))) - goto cleanup; + return -1; =20 if (VIR_STRDUP(output, test.output) < 0) - goto cleanup; + return -1; =20 if (virStorageBackendSheepdogParseNodeInfo(pool, output) !=3D test.expected_return) - goto cleanup; + return -1; =20 - if (test.expected_return) { - ret =3D 0; - goto cleanup; - } + if (test.expected_return) + return 0; =20 if (pool->capacity =3D=3D test.expected_capacity && pool->allocation =3D=3D test.expected_allocation) - ret =3D 0; + return 0; =20 - cleanup: - VIR_FREE(output); - return ret; + return -1; } =20 static int @@ -90,36 +85,31 @@ test_vdi_list_parser(const void *opaque) { const struct testVDIListParserData *data =3D opaque; collie_test test =3D data->data; - int ret =3D -1; - char *output =3D NULL; + VIR_AUTOFREE(char *) output =3D NULL; VIR_AUTOPTR(virStoragePoolDef) pool =3D NULL; VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; =20 if (!(pool =3D virStoragePoolDefParseFile(data->poolxml))) - goto cleanup; + return -1; =20 if (!(vol =3D virStorageVolDefParseFile(pool, data->volxml, 0))) - goto cleanup; + return -1; =20 if (VIR_STRDUP(output, test.output) < 0) - goto cleanup; + return -1; =20 if (virStorageBackendSheepdogParseVdiList(vol, output) !=3D test.expected_return) - goto cleanup; + return -1; =20 - if (test.expected_return) { - ret =3D 0; - goto cleanup; - } + if (test.expected_return) + return 0; =20 if (vol->target.capacity =3D=3D test.expected_capacity && vol->target.allocation =3D=3D test.expected_allocation) - ret =3D 0; + return 0; =20 - cleanup: - VIR_FREE(output); - return ret; + return -1; } =20 =20 @@ -127,8 +117,8 @@ static int mymain(void) { int ret =3D 0; - char *poolxml =3D NULL; - char *volxml =3D NULL; + VIR_AUTOFREE(char *) poolxml =3D NULL; + VIR_AUTOFREE(char *) volxml =3D NULL; =20 collie_test node_info_tests[] =3D { {"", -1, 0, 0}, @@ -215,8 +205,6 @@ mymain(void) } =20 cleanup: - VIR_FREE(poolxml); - VIR_FREE(volxml); return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 diff --git a/tests/storagepoolxml2argvtest.c b/tests/storagepoolxml2argvtes= t.c index c9ba9b3fde..288b81af1d 100644 --- a/tests/storagepoolxml2argvtest.c +++ b/tests/storagepoolxml2argvtest.c @@ -83,7 +83,6 @@ testCompareXMLToArgvFiles(bool shouldFail, ret =3D 0; =20 cleanup: - VIR_FREE(actualCmdline); virStoragePoolObjEndAPI(&pool); if (shouldFail) { virResetLastError(); @@ -101,27 +100,20 @@ struct testInfo { static int testCompareXMLToArgvHelper(const void *data) { - int result =3D -1; const struct testInfo *info =3D data; - char *poolxml =3D NULL; - char *cmdline =3D NULL; + VIR_AUTOFREE(char *) poolxml =3D NULL; + VIR_AUTOFREE(char *) cmdline =3D NULL; =20 if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml", abs_srcdir, info->pool) < 0) - goto cleanup; + return -1; =20 if (virAsprintf(&cmdline, "%s/storagepoolxml2argvdata/%s%s.argv", abs_srcdir, info->pool, info->platformSuffix) < 0 && !info->shouldFail) - goto cleanup; - - result =3D testCompareXMLToArgvFiles(info->shouldFail, poolxml, cmdlin= e); - - cleanup: - VIR_FREE(poolxml); - VIR_FREE(cmdline); + return -1; =20 - return result; + return testCompareXMLToArgvFiles(info->shouldFail, poolxml, cmdline); } =20 =20 diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c index c8d5c41cd4..bd3408e8b8 100644 --- a/tests/storagepoolxml2xmltest.c +++ b/tests/storagepoolxml2xmltest.c @@ -18,47 +18,34 @@ static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) { - char *actual =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) actual =3D NULL; VIR_AUTOPTR(virStoragePoolDef) dev =3D NULL; =20 if (!(dev =3D virStoragePoolDefParseFile(inxml))) - goto fail; + return -1; =20 if (!(actual =3D virStoragePoolDefFormat(dev))) - goto fail; + return -1; =20 if (virTestCompareToFile(actual, outxml) < 0) - goto fail; + return -1; =20 - ret =3D 0; - - fail: - VIR_FREE(actual); - return ret; + return 0; } =20 static int testCompareXMLToXMLHelper(const void *data) { - int result =3D -1; - char *inxml =3D NULL; - char *outxml =3D NULL; + VIR_AUTOFREE(char *) inxml =3D NULL; + VIR_AUTOFREE(char *) outxml =3D NULL; =20 if (virAsprintf(&inxml, "%s/storagepoolxml2xmlin/%s.xml", abs_srcdir, (const char*)data) < 0 || virAsprintf(&outxml, "%s/storagepoolxml2xmlout/%s.xml", - abs_srcdir, (const char*)data) < 0) { - goto cleanup; - } - - result =3D testCompareXMLToXMLFiles(inxml, outxml); - - cleanup: - VIR_FREE(inxml); - VIR_FREE(outxml); + abs_srcdir, (const char*)data) < 0) + return -1; =20 - return result; + return testCompareXMLToXMLFiles(inxml, outxml); } =20 static int diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c index d4ac02b31d..20d986b524 100644 --- a/tests/storagevolxml2argvtest.c +++ b/tests/storagevolxml2argvtest.c @@ -42,11 +42,11 @@ testCompareXMLToArgvFiles(bool shouldFail, unsigned int flags, unsigned long parse_flags) { - char *actualCmdline =3D NULL; virStorageVolEncryptConvertStep convertStep =3D VIR_STORAGE_VOL_ENCRYP= T_NONE; int ret =3D -1; virStoragePoolDefPtr def =3D NULL; virStoragePoolObjPtr obj =3D NULL; + VIR_AUTOFREE(char *) actualCmdline =3D NULL; VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; VIR_AUTOPTR(virStorageVolDef) inputvol =3D NULL; VIR_AUTOPTR(virStoragePoolDef) inputpool =3D NULL; @@ -108,7 +108,7 @@ testCompareXMLToArgvFiles(bool shouldFail, goto cleanup; } else { char *createCmdline =3D actualCmdline; - char *cvtCmdline; + VIR_AUTOFREE(char *) cvtCmdline =3D NULL; int rc; =20 if (!(cvtCmdline =3D virCommandToString(cmd, false))) @@ -118,7 +118,6 @@ testCompareXMLToArgvFiles(bool shouldFail, createCmdline, cvtCmdline); =20 VIR_FREE(createCmdline); - VIR_FREE(cvtCmdline); if (rc < 0) goto cleanup; } @@ -138,7 +137,6 @@ testCompareXMLToArgvFiles(bool shouldFail, ret =3D 0; =20 cleanup: - VIR_FREE(actualCmdline); virStoragePoolObjEndAPI(&obj); return ret; } @@ -157,45 +155,35 @@ struct testInfo { static int testCompareXMLToArgvHelper(const void *data) { - int result =3D -1; const struct testInfo *info =3D data; - char *poolxml =3D NULL; - char *inputpoolxml =3D NULL; - char *volxml =3D NULL; - char *inputvolxml =3D NULL; - char *cmdline =3D NULL; + VIR_AUTOFREE(char *) poolxml =3D NULL; + VIR_AUTOFREE(char *) inputpoolxml =3D NULL; + VIR_AUTOFREE(char *) volxml =3D NULL; + VIR_AUTOFREE(char *) inputvolxml =3D NULL; + VIR_AUTOFREE(char *) cmdline =3D NULL; =20 if (info->inputvol && virAsprintf(&inputvolxml, "%s/storagevolxml2xmlin/%s.xml", abs_srcdir, info->inputvol) < 0) - goto cleanup; + return -1; if (info->inputpool && virAsprintf(&inputpoolxml, "%s/storagepoolxml2xmlin/%s.xml", abs_srcdir, info->inputpool) < 0) - goto cleanup; + return -1; if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml", abs_srcdir, info->pool) < 0 || virAsprintf(&volxml, "%s/storagevolxml2xmlin/%s.xml", abs_srcdir, info->vol) < 0) { - goto cleanup; + return -1; } if (virAsprintf(&cmdline, "%s/storagevolxml2argvdata/%s.argv", abs_srcdir, info->cmdline) < 0 && !info->shouldFail) - goto cleanup; - - result =3D testCompareXMLToArgvFiles(info->shouldFail, poolxml, volxml, - inputpoolxml, inputvolxml, - cmdline, info->flags, - info->parseflags); - - cleanup: - VIR_FREE(poolxml); - VIR_FREE(volxml); - VIR_FREE(inputvolxml); - VIR_FREE(inputpoolxml); - VIR_FREE(cmdline); + return -1; =20 - return result; + return testCompareXMLToArgvFiles(info->shouldFail, poolxml, volxml, + inputpoolxml, inputvolxml, + cmdline, info->flags, + info->parseflags); } =20 =20 diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c index cb78bd5b28..7c5d8e7e38 100644 --- a/tests/storagevolxml2xmltest.c +++ b/tests/storagevolxml2xmltest.c @@ -17,28 +17,23 @@ static int testCompareXMLToXMLFiles(const char *poolxml, const char *inxml, const char *outxml, unsigned int flags) { - char *actual =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) actual =3D NULL; VIR_AUTOPTR(virStoragePoolDef) pool =3D NULL; VIR_AUTOPTR(virStorageVolDef) dev =3D NULL; =20 if (!(pool =3D virStoragePoolDefParseFile(poolxml))) - goto fail; + return -1; =20 if (!(dev =3D virStorageVolDefParseFile(pool, inxml, flags))) - goto fail; + return -1; =20 if (!(actual =3D virStorageVolDefFormat(pool, dev))) - goto fail; + return -1; =20 if (virTestCompareToFile(actual, outxml) < 0) - goto fail; + return -1; =20 - ret =3D 0; - - fail: - VIR_FREE(actual); - return ret; + return 0; } =20 struct testInfo { @@ -50,29 +45,20 @@ struct testInfo { static int testCompareXMLToXMLHelper(const void *data) { - int result =3D -1; const struct testInfo *info =3D data; - char *poolxml =3D NULL; - char *inxml =3D NULL; - char *outxml =3D NULL; + VIR_AUTOFREE(char *) poolxml =3D NULL; + VIR_AUTOFREE(char *) inxml =3D NULL; + VIR_AUTOFREE(char *) outxml =3D NULL; =20 if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml", abs_srcdir, info->pool) < 0 || virAsprintf(&inxml, "%s/storagevolxml2xmlin/%s.xml", abs_srcdir, info->name) < 0 || virAsprintf(&outxml, "%s/storagevolxml2xmlout/%s.xml", - abs_srcdir, info->name) < 0) { - goto cleanup; - } - - result =3D testCompareXMLToXMLFiles(poolxml, inxml, outxml, info->flag= s); - - cleanup: - VIR_FREE(poolxml); - VIR_FREE(inxml); - VIR_FREE(outxml); + abs_srcdir, info->name) < 0) + return -1; =20 - return result; + return testCompareXMLToXMLFiles(poolxml, inxml, outxml, info->flags); } =20 =20 diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 7272df7e33..49b8f42e6d 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -128,9 +128,9 @@ static int testPrepImages(void) { int ret =3D EXIT_FAILURE; - char *buf =3D NULL; bool compat =3D false; VIR_AUTOPTR(virCommand) cmd =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; =20 qemuimg =3D virFindFileInPath("qemu-img"); if (!qemuimg) @@ -245,7 +245,6 @@ testPrepImages(void) =20 ret =3D 0; cleanup: - VIR_FREE(buf); if (ret) testCleanupImages(); return ret; @@ -313,7 +312,7 @@ testStorageChain(const void *args) virStorageSourcePtr meta; virStorageSourcePtr elt; size_t i =3D 0; - char *broken =3D NULL; + VIR_AUTOFREE(char *) broken =3D NULL; =20 meta =3D testStorageFileGetMetadata(data->start, data->format, -1, -1); if (!meta) { @@ -349,8 +348,8 @@ testStorageChain(const void *args) =20 elt =3D meta; while (virStorageSourceIsBacking(elt)) { - char *expect =3D NULL; - char *actual =3D NULL; + VIR_AUTOFREE(char *) expect =3D NULL; + VIR_AUTOFREE(char *) actual =3D NULL; =20 if (i =3D=3D data->nfiles) { fprintf(stderr, "probed chain was too long\n"); @@ -379,18 +378,12 @@ testStorageChain(const void *args) elt->format, virStorageNetProtocolTypeToString(elt->protocol), NULLSTR(elt->nhosts ? elt->hosts[0].name : NULL)) = < 0) { - VIR_FREE(expect); - VIR_FREE(actual); goto cleanup; } if (STRNEQ(expect, actual)) { virTestDifference(stderr, expect, actual); - VIR_FREE(expect); - VIR_FREE(actual); goto cleanup; } - VIR_FREE(expect); - VIR_FREE(actual); elt =3D elt->backingStore; i++; } @@ -401,7 +394,6 @@ testStorageChain(const void *args) =20 ret =3D 0; cleanup: - VIR_FREE(broken); virStorageSourceFree(meta); return ret; } @@ -539,8 +531,7 @@ static int testPathCanonicalize(const void *args) { const struct testPathCanonicalizeData *data =3D args; - char *canon =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) canon =3D NULL; =20 canon =3D virStorageFileCanonicalizePath(data->path, testPathCanonicalizeReadlink, @@ -551,15 +542,10 @@ testPathCanonicalize(const void *args) "path canonicalization of '%s' failed: expected '%s' got '= %s'\n", data->path, NULLSTR(data->expect), NULLSTR(canon)); =20 - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(canon); - - return ret; + return 0; } =20 static virStorageSource backingchain[12]; @@ -629,14 +615,13 @@ static int testPathRelative(const void *args) { const struct testPathRelativeBacking *data =3D args; - char *actual =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) actual =3D NULL; =20 if (virStorageFileGetRelativeBackingPath(data->top, data->base, &actual) < 0) { fprintf(stderr, "relative backing path resolution failed\n"); - goto cleanup; + return -1; } =20 if (STRNEQ_NULLABLE(data->expect, actual)) { @@ -644,15 +629,10 @@ testPathRelative(const void *args) "expected '%s', got '%s'\n", data->top->path, data->base->path, NULLSTR(data->expect), NULLSTR(actual)); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(actual); - - return ret; + return 0; } =20 =20 @@ -667,8 +647,8 @@ testBackingParse(const void *args) const struct testBackingParseData *data =3D args; virBuffer buf =3D VIR_BUFFER_INITIALIZER; virStorageSourcePtr src =3D NULL; - char *xml =3D NULL; int ret =3D -1; + VIR_AUTOFREE(char *) xml =3D NULL; =20 if (!(src =3D virStorageSourceNewFromBackingAbsolute(data->backing))) { if (!data->expect) @@ -702,7 +682,6 @@ testBackingParse(const void *args) cleanup: virStorageSourceFree(src); virBufferFreeAndReset(&buf); - VIR_FREE(xml); =20 return ret; } diff --git a/tests/virstorageutiltest.c b/tests/virstorageutiltest.c index d91c5d4d6f..94d8b9b091 100644 --- a/tests/virstorageutiltest.c +++ b/tests/virstorageutiltest.c @@ -45,9 +45,9 @@ testGlusterExtractPoolSources(const void *opaque) .sources =3D NULL }; size_t i; - char *srcxmldata =3D NULL; - char *actual =3D NULL; int ret =3D -1; + VIR_AUTOFREE(char *) srcxmldata =3D NULL; + VIR_AUTOFREE(char *) actual =3D NULL; =20 if (virTestLoadFile(data->srcxml, &srcxmldata) < 0) goto cleanup; @@ -62,9 +62,6 @@ testGlusterExtractPoolSources(const void *opaque) ret =3D virTestCompareToFile(actual, data->dstxml); =20 cleanup: - VIR_FREE(srcxmldata); - VIR_FREE(actual); - for (i =3D 0; i < list.nsources; i++) virStoragePoolSourceClear(&list.sources[i]); VIR_FREE(list.sources); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651121737444.9195875306825; Fri, 8 Feb 2019 10:38:41 -0800 (PST) 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 8855580F75; Fri, 8 Feb 2019 18:38:39 +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 5091F611D1; Fri, 8 Feb 2019 18:38:39 +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 E06293D3A1; Fri, 8 Feb 2019 18:38:38 +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 x18Ic1ZS007762 for ; Fri, 8 Feb 2019 13:38:01 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3CD2DBA53; Fri, 8 Feb 2019 18:38:01 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id D560860BE0; Fri, 8 Feb 2019 18:38:00 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:17 -0500 Message-Id: <20190208183726.30903-24-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 23/32] storage: Use VIR_AUTOCLOSE 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: , 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.27]); Fri, 08 Feb 2019 18:38:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Modify code to use the VIR_AUTOCLOSE logic cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_backend_logical.c | 3 +- src/storage/storage_backend_scsi.c | 12 +-- src/storage/storage_file_fs.c | 15 +-- src/storage/storage_util.c | 150 ++++++++++---------------- src/util/virstoragefile.c | 39 +++---- 5 files changed, 77 insertions(+), 142 deletions(-) diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_ba= ckend_logical.c index c61d03519f..f153d23aec 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -911,10 +911,10 @@ static int virStorageBackendLogicalCreateVol(virStoragePoolObjPtr pool, virStorageVolDefPtr vol) { - int fd =3D -1; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); virErrorPtr err; struct stat sb; + VIR_AUTOCLOSE fd =3D -1; =20 vol->type =3D VIR_STORAGE_VOL_BLOCK; =20 @@ -971,7 +971,6 @@ virStorageBackendLogicalCreateVol(virStoragePoolObjPtr = pool, =20 error: err =3D virSaveLastError(); - VIR_FORCE_CLOSE(fd); virStorageBackendLogicalDeleteVol(pool, vol, 0); virSetError(err); virFreeError(err); diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backe= nd_scsi.c index 7460349c81..1e643f466e 100644 --- a/src/storage/storage_backend_scsi.c +++ b/src/storage/storage_backend_scsi.c @@ -55,8 +55,7 @@ struct _virStoragePoolFCRefreshInfo { static int virStorageBackendSCSITriggerRescan(uint32_t host) { - int fd =3D -1; - int retval =3D -1; + VIR_AUTOCLOSE fd =3D -1; VIR_AUTOFREE(char *) path =3D NULL; =20 VIR_DEBUG("Triggering rescan of host %d", host); @@ -73,24 +72,19 @@ virStorageBackendSCSITriggerRescan(uint32_t host) virReportSystemError(errno, _("Could not open '%s' to trigger host scan"), path); - goto cleanup; + return -1; } =20 if (safewrite(fd, LINUX_SYSFS_SCSI_HOST_SCAN_STRING, sizeof(LINUX_SYSFS_SCSI_HOST_SCAN_STRING)) < 0) { - VIR_FORCE_CLOSE(fd); virReportSystemError(errno, _("Write to '%s' to trigger host scan failed"= ), path); } =20 - retval =3D 0; - - cleanup: - VIR_FORCE_CLOSE(fd); VIR_DEBUG("Rescan of host %d complete", host); - return retval; + return 0; } =20 /** diff --git a/src/storage/storage_file_fs.c b/src/storage/storage_file_fs.c index 3b6ed6e34d..8817970f44 100644 --- a/src/storage/storage_file_fs.c +++ b/src/storage/storage_file_fs.c @@ -83,8 +83,8 @@ virStorageFileBackendFileInit(virStorageSourcePtr src) static int virStorageFileBackendFileCreate(virStorageSourcePtr src) { - int fd =3D -1; mode_t mode =3D S_IRUSR; + VIR_AUTOCLOSE fd =3D -1; =20 if (!src->readonly) mode |=3D S_IWUSR; @@ -95,7 +95,6 @@ virStorageFileBackendFileCreate(virStorageSourcePtr src) return -1; } =20 - VIR_FORCE_CLOSE(fd); return 0; } =20 @@ -121,8 +120,8 @@ virStorageFileBackendFileRead(virStorageSourcePtr src, size_t len, char **buf) { - int fd =3D -1; ssize_t ret =3D -1; + VIR_AUTOCLOSE fd =3D -1; =20 if ((fd =3D virFileOpenAs(src->path, O_RDONLY, 0, src->drv->uid, src->drv->gid, 0)) < 0) { @@ -134,19 +133,15 @@ virStorageFileBackendFileRead(virStorageSourcePtr src, if (offset > 0) { if (lseek(fd, offset, SEEK_SET) =3D=3D (off_t) -1) { virReportSystemError(errno, _("cannot seek into '%s'"), src->p= ath); - goto cleanup; + return -1; } } =20 if ((ret =3D virFileReadHeaderFD(fd, len, buf)) < 0) { - virReportSystemError(errno, - _("cannot read header '%s'"), src->path); - goto cleanup; + virReportSystemError(errno, _("cannot read header '%s'"), src->pat= h); + return -1; } =20 - cleanup: - VIR_FORCE_CLOSE(fd); - return ret; } =20 diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 1c290f1995..012c6b319b 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -130,7 +130,6 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, bool want_sparse, bool reflink_copy) { - int inputfd =3D -1; int amtread =3D -1; int ret =3D 0; size_t rbytes =3D READ_BLOCK_SIZE_DEFAULT; @@ -139,13 +138,14 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, struct stat st; VIR_AUTOFREE(char *) zerobuf =3D NULL; VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOCLOSE inputfd =3D -1; =20 if ((inputfd =3D open(inputvol->target.path, O_RDONLY)) < 0) { ret =3D -errno; virReportSystemError(errno, _("could not open input path '%s'"), inputvol->target.path); - goto cleanup; + return ret; } =20 #ifdef __linux__ @@ -157,15 +157,11 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, if (wbytes < WRITE_BLOCK_SIZE_DEFAULT) wbytes =3D WRITE_BLOCK_SIZE_DEFAULT; =20 - if (VIR_ALLOC_N(zerobuf, wbytes) < 0) { - ret =3D -errno; - goto cleanup; - } + if (VIR_ALLOC_N(zerobuf, wbytes) < 0) + return -errno; =20 - if (VIR_ALLOC_N(buf, rbytes) < 0) { - ret =3D -errno; - goto cleanup; - } + if (VIR_ALLOC_N(buf, rbytes) < 0) + return -errno; =20 if (reflink_copy) { if (reflinkCloneFile(fd, inputfd) < 0) { @@ -173,10 +169,10 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, virReportSystemError(errno, _("failed to clone files from '%s'"), inputvol->target.path); - goto cleanup; + return ret; } else { VIR_DEBUG("btrfs clone finished."); - goto cleanup; + return 0; } } =20 @@ -191,7 +187,7 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, virReportSystemError(errno, _("failed reading from file '%s'"), inputvol->target.path); - goto cleanup; + return ret; } *total -=3D amtread; =20 @@ -208,14 +204,14 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, virReportSystemError(errno, _("cannot extend file '%s'"), vol->target.path); - goto cleanup; + return ret; } } else if (safewrite(fd, buf+offset, interval) < 0) { ret =3D -errno; virReportSystemError(errno, _("failed writing to file '%s'"), vol->target.path); - goto cleanup; + return ret; =20 } } while ((amtleft -=3D interval) > 0); @@ -225,23 +221,18 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, ret =3D -errno; virReportSystemError(errno, _("cannot sync data to file '%s'"), vol->target.path); - goto cleanup; + return ret; } =20 - if (VIR_CLOSE(inputfd) < 0) { ret =3D -errno; virReportSystemError(errno, _("cannot close file '%s'"), inputvol->target.path); - goto cleanup; + return ret; } - inputfd =3D -1; - - cleanup: - VIR_FORCE_CLOSE(inputfd); =20 - return ret; + return 0; } =20 static int @@ -250,14 +241,13 @@ storageBackendCreateBlockFrom(virStoragePoolObjPtr po= ol ATTRIBUTE_UNUSED, virStorageVolDefPtr inputvol, unsigned int flags) { - int fd =3D -1; - int ret =3D -1; unsigned long long remain; struct stat st; gid_t gid; uid_t uid; mode_t mode; bool reflink_copy =3D false; + VIR_AUTOCLOSE fd =3D -1; =20 virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA | VIR_STORAGE_VOL_CREATE_REFLINK, @@ -267,7 +257,7 @@ storageBackendCreateBlockFrom(virStoragePoolObjPtr pool= ATTRIBUTE_UNUSED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("metadata preallocation is not supported for bloc= k " "volumes")); - goto cleanup; + return -1; } =20 if (flags & VIR_STORAGE_VOL_CREATE_REFLINK) @@ -277,7 +267,7 @@ storageBackendCreateBlockFrom(virStoragePoolObjPtr pool= ATTRIBUTE_UNUSED, virReportSystemError(errno, _("cannot create path '%s'"), vol->target.path); - goto cleanup; + return -1; } =20 remain =3D vol->target.capacity; @@ -285,13 +275,13 @@ storageBackendCreateBlockFrom(virStoragePoolObjPtr po= ol ATTRIBUTE_UNUSED, if (inputvol) { if (virStorageBackendCopyToFD(vol, inputvol, fd, &remain, false, reflink_copy) < 0) - goto cleanup; + return -1; } =20 if (fstat(fd, &st) =3D=3D -1) { virReportSystemError(errno, _("stat of '%s' failed"), vol->target.path); - goto cleanup; + return -1; } uid =3D (vol->target.perms->uid !=3D st.st_uid) ? vol->target.perms->u= id : (uid_t)-1; @@ -303,7 +293,7 @@ storageBackendCreateBlockFrom(virStoragePoolObjPtr pool= ATTRIBUTE_UNUSED, _("cannot chown '%s' to (%u, %u)"), vol->target.path, (unsigned int)uid, (unsigned int)gid); - goto cleanup; + return -1; } =20 mode =3D (vol->target.perms->mode =3D=3D (mode_t)-1 ? @@ -312,21 +302,16 @@ storageBackendCreateBlockFrom(virStoragePoolObjPtr po= ol ATTRIBUTE_UNUSED, virReportSystemError(errno, _("cannot set mode of '%s' to %04o"), vol->target.path, mode); - goto cleanup; + return -1; } if (VIR_CLOSE(fd) < 0) { virReportSystemError(errno, _("cannot close file '%s'"), vol->target.path); - goto cleanup; + return -1; } - fd =3D -1; =20 - ret =3D 0; - cleanup: - VIR_FORCE_CLOSE(fd); - - return ret; + return 0; } =20 static int @@ -419,11 +404,11 @@ storageBackendCreateRaw(virStoragePoolObjPtr pool, { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); int ret =3D -1; - int fd =3D -1; int operation_flags; bool reflink_copy =3D false; mode_t open_mode =3D VIR_STORAGE_DEFAULT_VOL_PERM_MODE; bool created =3D false; + VIR_AUTOCLOSE fd =3D -1; =20 virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA | VIR_STORAGE_VOL_CREATE_REFLINK, @@ -501,7 +486,6 @@ storageBackendCreateRaw(virStoragePoolObjPtr pool, ignore_value(virFileRemove(vol->target.path, vol->target.perms->uid, vol->target.perms->gid)); - VIR_FORCE_CLOSE(fd); return ret; } =20 @@ -542,7 +526,7 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr= pool, * re-open the file and attempt to force the mode change. */ if (mode !=3D (st.st_mode & S_IRWXUGO)) { - int fd =3D -1; + VIR_AUTOCLOSE fd =3D -1; int flags =3D VIR_FILE_OPEN_FORK | VIR_FILE_OPEN_FORCE= _MODE; =20 if ((fd =3D virFileOpenAs(vol->target.path, O_RDWR, mo= de, @@ -550,7 +534,6 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr= pool, vol->target.perms->gid, flags)) >=3D 0) { /* Success - means we're good */ - VIR_FORCE_CLOSE(fd); ret =3D 0; goto cleanup; } @@ -1227,10 +1210,10 @@ storageBackendCreateQemuImgSecretPath(virStoragePoo= lObjPtr pool, { virStorageEncryptionPtr enc =3D vol->target.encryption; char *secretPath =3D NULL; - int fd =3D -1; uint8_t *secret =3D NULL; size_t secretlen =3D 0; virConnectPtr conn =3D NULL; + VIR_AUTOCLOSE fd =3D -1; =20 if (!enc) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1268,7 +1251,6 @@ storageBackendCreateQemuImgSecretPath(virStoragePoolO= bjPtr pool, _("failed to write secret file")); goto error; } - VIR_FORCE_CLOSE(fd); =20 if ((vol->target.perms->uid !=3D (uid_t)-1) && (vol->target.perms->gid !=3D (gid_t)-1)) { @@ -1283,7 +1265,6 @@ storageBackendCreateQemuImgSecretPath(virStoragePoolO= bjPtr pool, cleanup: virObjectUnref(conn); VIR_DISPOSE_N(secret, secretlen); - VIR_FORCE_CLOSE(fd); =20 return secretPath; =20 @@ -1751,17 +1732,17 @@ storageBackendUpdateVolTargetInfo(virStorageVolType= voltype, unsigned int openflags, unsigned int readflags) { - int ret, fd =3D -1; + int ret; struct stat sb; ssize_t len =3D VIR_STORAGE_MAX_HEADER; VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOCLOSE fd =3D -1; =20 - if ((ret =3D virStorageBackendVolOpen(target->path, &sb, openflags)) <= 0) - goto cleanup; - fd =3D ret; + if ((fd =3D virStorageBackendVolOpen(target->path, &sb, openflags)) < = 0) + return -1; =20 if ((ret =3D virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb)) = < 0) - goto cleanup; + return ret; =20 if ((voltype =3D=3D VIR_STORAGE_VOL_FILE || voltype =3D=3D VIR_STORAGE= _VOL_BLOCK) && target->format !=3D VIR_STORAGE_FILE_NONE) { @@ -1769,49 +1750,39 @@ storageBackendUpdateVolTargetInfo(virStorageVolType= voltype, if (storageBackendIsPloopDir(target->path)) { if ((ret =3D storageBackendRedoPloopUpdate(target, &sb, &f= d, openflags)) < 0) - goto cleanup; + return ret; target->format =3D VIR_STORAGE_FILE_PLOOP; } else { - ret =3D 0; - goto cleanup; + return 0; } } =20 if (lseek(fd, 0, SEEK_SET) =3D=3D (off_t)-1) { virReportSystemError(errno, _("cannot seek to start of '%s'"),= target->path); - ret =3D -1; - goto cleanup; + return -1; } =20 if ((len =3D virFileReadHeaderFD(fd, len, &buf)) < 0) { if (readflags & VIR_STORAGE_VOL_READ_NOERROR) { VIR_WARN("ignoring failed header read for '%s'", target->path); - ret =3D -2; + return -2; } else { virReportSystemError(errno, _("cannot read header '%s'"), target->path); - ret =3D -1; + return -1; } - goto cleanup; } =20 - if (virStorageSourceUpdateCapacity(target, buf, len, false) < 0) { - ret =3D -1; - goto cleanup; - } + if (virStorageSourceUpdateCapacity(target, buf, len, false) < 0) + return -1; } =20 - if (withBlockVolFormat) { - if ((ret =3D virStorageBackendDetectBlockVolFormatFD(target, fd, - readflags)) < 0) - goto cleanup; - } + if (withBlockVolFormat) + return virStorageBackendDetectBlockVolFormatFD(target, fd, readfla= gs); =20 - cleanup: - VIR_FORCE_CLOSE(fd); - return ret; + return 0; } =20 /* @@ -2617,9 +2588,9 @@ storageBackendVolWipeLocalFile(const char *path, unsigned long long allocation, bool zero_end) { - int ret =3D -1, fd =3D -1; const char *alg_char =3D NULL; struct stat st; + VIR_AUTOCLOSE fd =3D -1; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 fd =3D open(path, O_RDWR); @@ -2627,14 +2598,14 @@ storageBackendVolWipeLocalFile(const char *path, virReportSystemError(errno, _("Failed to open storage volume with path '%= s'"), path); - goto cleanup; + return -1; } =20 if (fstat(fd, &st) =3D=3D -1) { virReportSystemError(errno, _("Failed to stat storage volume with path '%= s'"), path); - goto cleanup; + return -1; } =20 switch ((virStorageVolWipeAlgorithm) algorithm) { @@ -2668,12 +2639,12 @@ storageBackendVolWipeLocalFile(const char *path, case VIR_STORAGE_VOL_WIPE_ALG_TRIM: virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", _("'trim' algorithm not supported")); - goto cleanup; + return -1; case VIR_STORAGE_VOL_WIPE_ALG_LAST: virReportError(VIR_ERR_INVALID_ARG, _("unsupported algorithm %d"), algorithm); - goto cleanup; + return -1; } =20 VIR_DEBUG("Wiping file '%s' with algorithm '%s'", path, alg_char); @@ -2682,24 +2653,14 @@ storageBackendVolWipeLocalFile(const char *path, cmd =3D virCommandNew(SCRUB); virCommandAddArgList(cmd, "-f", "-p", alg_char, path, NULL); =20 - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; - - ret =3D 0; - } else { - if (S_ISREG(st.st_mode) && st.st_blocks < (st.st_size / DEV_BSIZE)= ) { - ret =3D storageBackendVolZeroSparseFileLocal(path, st.st_size,= fd); - } else { - ret =3D storageBackendWipeLocal(path, fd, allocation, st.st_bl= ksize, - zero_end); - } - if (ret < 0) - goto cleanup; + return virCommandRun(cmd, NULL); } =20 - cleanup: - VIR_FORCE_CLOSE(fd); - return ret; + if (S_ISREG(st.st_mode) && st.st_blocks < (st.st_size / DEV_BSIZE)) + return storageBackendVolZeroSparseFileLocal(path, st.st_size, fd); + + return storageBackendWipeLocal(path, fd, allocation, st.st_blksize, + zero_end); } =20 =20 @@ -3392,11 +3353,11 @@ storageBackendProbeTarget(virStorageSourcePtr targe= t, virStorageEncryptionPtr *encryption) { int backingStoreFormat; - int fd =3D -1; int ret =3D -1; int rc; virStorageSourcePtr meta =3D NULL; struct stat sb; + VIR_AUTOCLOSE fd =3D -1; =20 if (encryption) *encryption =3D NULL; @@ -3499,7 +3460,6 @@ storageBackendProbeTarget(virStorageSourcePtr target, } =20 cleanup: - VIR_FORCE_CLOSE(fd); virStorageSourceFree(meta); return ret; } @@ -3571,8 +3531,9 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr po= ol) struct stat statbuf; virStorageSourcePtr target =3D NULL; int direrr; - int fd =3D -1, ret =3D -1; + int ret =3D -1; VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; + VIR_AUTOCLOSE fd =3D -1; =20 if (virDirOpen(&dir, def->target.path) < 0) goto cleanup; @@ -3663,7 +3624,6 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr po= ol) ret =3D 0; cleanup: VIR_DIR_CLOSE(dir); - VIR_FORCE_CLOSE(fd); virStorageSourceFree(target); if (ret < 0) virStoragePoolObjClearVols(pool); diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index fddfea65db..907358a8fe 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1080,10 +1080,9 @@ virStorageFileGetMetadataInternal(virStorageSourcePt= r meta, int virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid) { - int fd; - int ret =3D -1; struct stat sb; ssize_t len =3D VIR_STORAGE_MAX_HEADER; + VIR_AUTOCLOSE fd =3D -1; VIR_AUTOFREE(char *) header =3D NULL; =20 if ((fd =3D virFileOpenAs(path, O_RDONLY, 0, uid, gid, 0)) < 0) { @@ -1093,31 +1092,24 @@ virStorageFileProbeFormat(const char *path, uid_t u= id, gid_t gid) =20 if (fstat(fd, &sb) < 0) { virReportSystemError(errno, _("cannot stat file '%s'"), path); - goto cleanup; + return -1; } =20 /* No header to probe for directories */ - if (S_ISDIR(sb.st_mode)) { - ret =3D VIR_STORAGE_FILE_DIR; - goto cleanup; - } + if (S_ISDIR(sb.st_mode)) + return VIR_STORAGE_FILE_DIR; =20 if (lseek(fd, 0, SEEK_SET) =3D=3D (off_t)-1) { virReportSystemError(errno, _("cannot set to start of '%s'"), path= ); - goto cleanup; + return -1; } =20 if ((len =3D virFileReadHeaderFD(fd, len, &header)) < 0) { virReportSystemError(errno, _("cannot read header '%s'"), path); - goto cleanup; + return -1; } =20 - ret =3D virStorageFileProbeFormatFromBuf(path, header, len); - - cleanup: - VIR_FORCE_CLOSE(fd); - - return ret; + return virStorageFileProbeFormatFromBuf(path, header, len); } =20 =20 @@ -1312,13 +1304,12 @@ virStorageFileResize(const char *path, unsigned long long capacity, bool pre_allocate) { - int fd =3D -1; - int ret =3D -1; int rc; + VIR_AUTOCLOSE fd =3D -1; =20 if ((fd =3D open(path, O_RDWR)) < 0) { virReportSystemError(errno, _("Unable to open '%s'"), path); - goto cleanup; + return -1; } =20 if (pre_allocate) { @@ -1331,26 +1322,22 @@ virStorageFileResize(const char *path, _("Failed to pre-allocate space for " "file '%s'"), path); } - goto cleanup; + return -1; } } =20 if (ftruncate(fd, capacity) < 0) { virReportSystemError(errno, _("Failed to truncate file '%s'"), path); - goto cleanup; + return -1; } =20 if (VIR_CLOSE(fd) < 0) { virReportSystemError(errno, _("Unable to save '%s'"), path); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FORCE_CLOSE(fd); - return ret; + return 0; } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651127004511.25318131234656; Fri, 8 Feb 2019 10:38:47 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1C83AC056839; Fri, 8 Feb 2019 18:38:45 +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 D5D03277B0; Fri, 8 Feb 2019 18:38:44 +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 692C718033CA; Fri, 8 Feb 2019 18:38:44 +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 x18Ic1mg007767 for ; Fri, 8 Feb 2019 13:38:01 -0500 Received: by smtp.corp.redhat.com (Postfix) id A9CD54251; Fri, 8 Feb 2019 18:38:01 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65EED60BE0 for ; Fri, 8 Feb 2019 18:38:01 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:18 -0500 Message-Id: <20190208183726.30903-25-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 24/32] tests: Fix memory leak in testCompareXMLToArgvFiles 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 08 Feb 2019 18:38:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Only one path will consume the @def; otherwise, we need to free it. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- tests/storagepoolxml2argvtest.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/storagepoolxml2argvtest.c b/tests/storagepoolxml2argvtes= t.c index 288b81af1d..f2a8af12b0 100644 --- a/tests/storagepoolxml2argvtest.c +++ b/tests/storagepoolxml2argvtest.c @@ -23,6 +23,7 @@ testCompareXMLToArgvFiles(bool shouldFail, const char *cmdline) { int ret =3D -1; + bool consumeDef =3D false; virStoragePoolDefPtr def =3D NULL; virStoragePoolObjPtr pool =3D NULL; VIR_AUTOFREE(char *) actualCmdline =3D NULL; @@ -41,6 +42,7 @@ testCompareXMLToArgvFiles(bool shouldFail, goto cleanup; } virStoragePoolObjSetDef(pool, def); + consumeDef =3D true; =20 if (!(src =3D virStorageBackendFileSystemGetPoolSource(pool))) { VIR_TEST_DEBUG("pool type %d has no pool source\n", def->type); @@ -83,6 +85,8 @@ testCompareXMLToArgvFiles(bool shouldFail, ret =3D 0; =20 cleanup: + if (!consumeDef) + virStoragePoolDefFree(def); virStoragePoolObjEndAPI(&pool); if (shouldFail) { virResetLastError(); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651103977598.8459968635706; Fri, 8 Feb 2019 10:38:23 -0800 (PST) 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 30F73149BC; Fri, 8 Feb 2019 18:38:21 +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 D635A60474; Fri, 8 Feb 2019 18:38:20 +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 764E43F615; Fri, 8 Feb 2019 18:38:20 +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 x18Ic4O8007786 for ; Fri, 8 Feb 2019 13:38:04 -0500 Received: by smtp.corp.redhat.com (Postfix) id D080117A65; Fri, 8 Feb 2019 18:38:04 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7636760C55; Fri, 8 Feb 2019 18:38:01 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:19 -0500 Message-Id: <20190208183726.30903-26-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 25/32] storage: Use VIR_STEAL_PTR in storageBackendProbeTarget 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: , 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.39]); Fri, 08 Feb 2019 18:38:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_util.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 012c6b319b..af6ab20ea6 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -3450,13 +3450,11 @@ storageBackendProbeTarget(virStorageSourcePtr targe= t, } =20 virBitmapFree(target->features); - target->features =3D meta->features; - meta->features =3D NULL; + VIR_STEAL_PTR(target->features, meta->features); =20 if (meta->compat) { VIR_FREE(target->compat); - target->compat =3D meta->compat; - meta->compat =3D NULL; + VIR_STEAL_PTR(target->compat, meta->compat); } =20 cleanup: --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 154965113416427.199656610082002; Fri, 8 Feb 2019 10:38:54 -0800 (PST) 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 5CB23C0495BF; Fri, 8 Feb 2019 18:38:52 +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 1DFB16012B; Fri, 8 Feb 2019 18:38: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 BBABE181B9F6; Fri, 8 Feb 2019 18:38:51 +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 x18Ic5qW007793 for ; Fri, 8 Feb 2019 13:38:05 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4C4EA60C55; Fri, 8 Feb 2019 18:38:05 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0612460BE0 for ; Fri, 8 Feb 2019 18:38:04 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:20 -0500 Message-Id: <20190208183726.30903-27-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 26/32] util: Rename variable in virStorageFileMetadataNew 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: , 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.31]); Fri, 08 Feb 2019 18:38:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" To prepare for subsequent change to use VIR_AUTOPTR logic rename the @ret to @def. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/util/virstoragefile.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 907358a8fe..adce5f0fe3 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1117,21 +1117,21 @@ static virStorageSourcePtr virStorageFileMetadataNew(const char *path, int format) { - virStorageSourcePtr ret =3D NULL; + virStorageSourcePtr def =3D NULL; =20 - if (VIR_ALLOC(ret) < 0) + if (VIR_ALLOC(def) < 0) return NULL; =20 - ret->format =3D format; - ret->type =3D VIR_STORAGE_TYPE_FILE; + def->format =3D format; + def->type =3D VIR_STORAGE_TYPE_FILE; =20 - if (VIR_STRDUP(ret->path, path) < 0) + if (VIR_STRDUP(def->path, path) < 0) goto error; =20 - return ret; + return def; =20 error: - virStorageSourceFree(ret); + virStorageSourceFree(def); return NULL; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651138997451.3811603204899; Fri, 8 Feb 2019 10:38:58 -0800 (PST) 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 1727AC01DDFA; Fri, 8 Feb 2019 18:38:57 +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 B97CF6091C; Fri, 8 Feb 2019 18:38:56 +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 6A63918E306A; Fri, 8 Feb 2019 18:38:56 +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 x18Ic58I007798 for ; Fri, 8 Feb 2019 13:38:05 -0500 Received: by smtp.corp.redhat.com (Postfix) id BC46517BB7; Fri, 8 Feb 2019 18:38:05 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 762E060BE0 for ; Fri, 8 Feb 2019 18:38:05 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:21 -0500 Message-Id: <20190208183726.30903-28-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 27/32] util: Rename variable in virStorageSourceCopy 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: , 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]); Fri, 08 Feb 2019 18:38:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" To prepare for subsequent change to use VIR_AUTOPTR logic rename the @ret to @def. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/util/virstoragefile.c | 96 +++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index adce5f0fe3..45399f98ce 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2243,98 +2243,98 @@ virStorageSourcePtr virStorageSourceCopy(const virStorageSource *src, bool backingChain) { - virStorageSourcePtr ret =3D NULL; + virStorageSourcePtr def =3D NULL; =20 - if (VIR_ALLOC(ret) < 0) + if (VIR_ALLOC(def) < 0) return NULL; =20 - ret->id =3D src->id; - ret->type =3D src->type; - ret->protocol =3D src->protocol; - ret->format =3D src->format; - ret->capacity =3D src->capacity; - ret->allocation =3D src->allocation; - ret->has_allocation =3D src->has_allocation; - ret->physical =3D src->physical; - ret->readonly =3D src->readonly; - ret->shared =3D src->shared; - ret->haveTLS =3D src->haveTLS; - ret->tlsFromConfig =3D src->tlsFromConfig; - ret->detected =3D src->detected; - ret->debugLevel =3D src->debugLevel; - ret->debug =3D src->debug; - ret->iomode =3D src->iomode; - ret->cachemode =3D src->cachemode; - ret->discard =3D src->discard; - ret->detect_zeroes =3D src->detect_zeroes; + def->id =3D src->id; + def->type =3D src->type; + def->protocol =3D src->protocol; + def->format =3D src->format; + def->capacity =3D src->capacity; + def->allocation =3D src->allocation; + def->has_allocation =3D src->has_allocation; + def->physical =3D src->physical; + def->readonly =3D src->readonly; + def->shared =3D src->shared; + def->haveTLS =3D src->haveTLS; + def->tlsFromConfig =3D src->tlsFromConfig; + def->detected =3D src->detected; + def->debugLevel =3D src->debugLevel; + def->debug =3D src->debug; + def->iomode =3D src->iomode; + def->cachemode =3D src->cachemode; + def->discard =3D src->discard; + def->detect_zeroes =3D src->detect_zeroes; =20 /* storage driver metadata are not copied */ - ret->drv =3D NULL; - - if (VIR_STRDUP(ret->path, src->path) < 0 || - VIR_STRDUP(ret->volume, src->volume) < 0 || - VIR_STRDUP(ret->relPath, src->relPath) < 0 || - VIR_STRDUP(ret->backingStoreRaw, src->backingStoreRaw) < 0 || - VIR_STRDUP(ret->snapshot, src->snapshot) < 0 || - VIR_STRDUP(ret->configFile, src->configFile) < 0 || - VIR_STRDUP(ret->nodeformat, src->nodeformat) < 0 || - VIR_STRDUP(ret->nodestorage, src->nodestorage) < 0 || - VIR_STRDUP(ret->compat, src->compat) < 0 || - VIR_STRDUP(ret->tlsAlias, src->tlsAlias) < 0 || - VIR_STRDUP(ret->tlsCertdir, src->tlsCertdir) < 0) + def->drv =3D NULL; + + if (VIR_STRDUP(def->path, src->path) < 0 || + VIR_STRDUP(def->volume, src->volume) < 0 || + VIR_STRDUP(def->relPath, src->relPath) < 0 || + VIR_STRDUP(def->backingStoreRaw, src->backingStoreRaw) < 0 || + VIR_STRDUP(def->snapshot, src->snapshot) < 0 || + VIR_STRDUP(def->configFile, src->configFile) < 0 || + VIR_STRDUP(def->nodeformat, src->nodeformat) < 0 || + VIR_STRDUP(def->nodestorage, src->nodestorage) < 0 || + VIR_STRDUP(def->compat, src->compat) < 0 || + VIR_STRDUP(def->tlsAlias, src->tlsAlias) < 0 || + VIR_STRDUP(def->tlsCertdir, src->tlsCertdir) < 0) goto error; =20 if (src->nhosts) { - if (!(ret->hosts =3D virStorageNetHostDefCopy(src->nhosts, src->ho= sts))) + if (!(def->hosts =3D virStorageNetHostDefCopy(src->nhosts, src->ho= sts))) goto error; =20 - ret->nhosts =3D src->nhosts; + def->nhosts =3D src->nhosts; } =20 if (src->srcpool && - !(ret->srcpool =3D virStorageSourcePoolDefCopy(src->srcpool))) + !(def->srcpool =3D virStorageSourcePoolDefCopy(src->srcpool))) goto error; =20 if (src->features && - !(ret->features =3D virBitmapNewCopy(src->features))) + !(def->features =3D virBitmapNewCopy(src->features))) goto error; =20 if (src->encryption && - !(ret->encryption =3D virStorageEncryptionCopy(src->encryption))) + !(def->encryption =3D virStorageEncryptionCopy(src->encryption))) goto error; =20 if (src->perms && - !(ret->perms =3D virStoragePermsCopy(src->perms))) + !(def->perms =3D virStoragePermsCopy(src->perms))) goto error; =20 if (src->timestamps && - !(ret->timestamps =3D virStorageTimestampsCopy(src->timestamps))) + !(def->timestamps =3D virStorageTimestampsCopy(src->timestamps))) goto error; =20 - if (virStorageSourceSeclabelsCopy(ret, src) < 0) + if (virStorageSourceSeclabelsCopy(def, src) < 0) goto error; =20 if (src->auth && - !(ret->auth =3D virStorageAuthDefCopy(src->auth))) + !(def->auth =3D virStorageAuthDefCopy(src->auth))) goto error; =20 if (src->pr && - !(ret->pr =3D virStoragePRDefCopy(src->pr))) + !(def->pr =3D virStoragePRDefCopy(src->pr))) goto error; =20 - if (virStorageSourceInitiatorCopy(&ret->initiator, &src->initiator)) + if (virStorageSourceInitiatorCopy(&def->initiator, &src->initiator)) goto error; =20 if (backingChain && src->backingStore) { - if (!(ret->backingStore =3D virStorageSourceCopy(src->backingStore, + if (!(def->backingStore =3D virStorageSourceCopy(src->backingStore, true))) goto error; } =20 - return ret; + return def; =20 error: - virStorageSourceFree(ret); + virStorageSourceFree(def); return NULL; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 154965111069691.86927277859013; Fri, 8 Feb 2019 10:38:30 -0800 (PST) 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 94C7D81138; Fri, 8 Feb 2019 18:38:28 +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 50E016091C; Fri, 8 Feb 2019 18:38:28 +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 015663F5CA; Fri, 8 Feb 2019 18:38:28 +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 x18Ic67A007806 for ; Fri, 8 Feb 2019 13:38:06 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3731417BB0; Fri, 8 Feb 2019 18:38:06 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5C7D60BE0 for ; Fri, 8 Feb 2019 18:38:05 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:22 -0500 Message-Id: <20190208183726.30903-29-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 28/32] util: Rename variable in virStorageSourceNewFromBackingRelative 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: , 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.27]); Fri, 08 Feb 2019 18:38:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" To prepare for subsequent change to use VIR_AUTOPTR logic rename the @ret to @def. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/util/virstoragefile.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 45399f98ce..475e797e1b 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2577,14 +2577,14 @@ static virStorageSourcePtr virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent, const char *rel) { - virStorageSourcePtr ret; + virStorageSourcePtr def; VIR_AUTOFREE(char *) dirname =3D NULL; =20 - if (VIR_ALLOC(ret) < 0) + if (VIR_ALLOC(def) < 0) return NULL; =20 /* store relative name */ - if (VIR_STRDUP(ret->relPath, parent->backingStoreRaw) < 0) + if (VIR_STRDUP(def->relPath, parent->backingStoreRaw) < 0) goto error; =20 if (!(dirname =3D mdir_name(parent->path))) { @@ -2593,39 +2593,39 @@ virStorageSourceNewFromBackingRelative(virStorageSo= urcePtr parent, } =20 if (STRNEQ(dirname, "/")) { - if (virAsprintf(&ret->path, "%s/%s", dirname, rel) < 0) + if (virAsprintf(&def->path, "%s/%s", dirname, rel) < 0) goto error; } else { - if (virAsprintf(&ret->path, "/%s", rel) < 0) + if (virAsprintf(&def->path, "/%s", rel) < 0) goto error; } =20 if (virStorageSourceGetActualType(parent) =3D=3D VIR_STORAGE_TYPE_NETW= ORK) { - ret->type =3D VIR_STORAGE_TYPE_NETWORK; + def->type =3D VIR_STORAGE_TYPE_NETWORK; =20 /* copy the host network part */ - ret->protocol =3D parent->protocol; + def->protocol =3D parent->protocol; if (parent->nhosts) { - if (!(ret->hosts =3D virStorageNetHostDefCopy(parent->nhosts, + if (!(def->hosts =3D virStorageNetHostDefCopy(parent->nhosts, parent->hosts))) goto error; =20 - ret->nhosts =3D parent->nhosts; + def->nhosts =3D parent->nhosts; } =20 - if (VIR_STRDUP(ret->volume, parent->volume) < 0) + if (VIR_STRDUP(def->volume, parent->volume) < 0) goto error; } else { /* set the type to _FILE, the caller shall update it to the actual= type */ - ret->type =3D VIR_STORAGE_TYPE_FILE; + def->type =3D VIR_STORAGE_TYPE_FILE; } =20 cleanup: - return ret; + return def; =20 error: - virStorageSourceFree(ret); - ret =3D NULL; + virStorageSourceFree(def); + def =3D NULL; goto cleanup; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651115517838.2822709944605; Fri, 8 Feb 2019 10:38:35 -0800 (PST) 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 74B08637E3; Fri, 8 Feb 2019 18:38:33 +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 251C9174B4; Fri, 8 Feb 2019 18:38:33 +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 B4AE43F5DD; Fri, 8 Feb 2019 18:38:32 +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 x18Ic6hD007824 for ; Fri, 8 Feb 2019 13:38:06 -0500 Received: by smtp.corp.redhat.com (Postfix) id A4E4E17BB6; Fri, 8 Feb 2019 18:38:06 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6210360BE0 for ; Fri, 8 Feb 2019 18:38:06 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:23 -0500 Message-Id: <20190208183726.30903-30-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 29/32] util: Rename variable in virStorageSourceNewFromBackingAbsolute 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: , 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.28]); Fri, 08 Feb 2019 18:38:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" To prepare for subsequent change to use VIR_AUTOPTR logic rename the @ret to @def. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/util/virstoragefile.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 475e797e1b..d2636eec0a 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -3619,48 +3619,48 @@ virStorageSourcePtr virStorageSourceNewFromBackingAbsolute(const char *path) { const char *json; - virStorageSourcePtr ret; + virStorageSourcePtr def; int rc; =20 - if (VIR_ALLOC(ret) < 0) + if (VIR_ALLOC(def) < 0) return NULL; =20 if (virStorageIsFile(path)) { - ret->type =3D VIR_STORAGE_TYPE_FILE; + def->type =3D VIR_STORAGE_TYPE_FILE; =20 - if (VIR_STRDUP(ret->path, path) < 0) + if (VIR_STRDUP(def->path, path) < 0) goto error; } else { - ret->type =3D VIR_STORAGE_TYPE_NETWORK; + def->type =3D VIR_STORAGE_TYPE_NETWORK; =20 VIR_DEBUG("parsing backing store string: '%s'", path); =20 /* handle URI formatted backing stores */ if ((json =3D STRSKIP(path, "json:"))) - rc =3D virStorageSourceParseBackingJSON(ret, json); + rc =3D virStorageSourceParseBackingJSON(def, json); else if (strstr(path, "://")) - rc =3D virStorageSourceParseBackingURI(ret, path); + rc =3D virStorageSourceParseBackingURI(def, path); else - rc =3D virStorageSourceParseBackingColon(ret, path); + rc =3D virStorageSourceParseBackingColon(def, path); =20 if (rc < 0) goto error; =20 - virStorageSourceNetworkAssignDefaultPorts(ret); + virStorageSourceNetworkAssignDefaultPorts(def); =20 /* Some of the legacy parsers parse authentication data since they= are * also used in other places. For backing store detection the * authentication data would be invalid anyways, so we clear it */ - if (ret->auth) { - virStorageAuthDefFree(ret->auth); - ret->auth =3D NULL; + if (def->auth) { + virStorageAuthDefFree(def->auth); + def->auth =3D NULL; } } =20 - return ret; + return def; =20 error: - virStorageSourceFree(ret); + virStorageSourceFree(def); return NULL; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651119998789.0285795383617; Fri, 8 Feb 2019 10:38:39 -0800 (PST) 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 23B3F4CE91; Fri, 8 Feb 2019 18:38:38 +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 DA4D317BBA; Fri, 8 Feb 2019 18:38:37 +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 8F5963D39F; Fri, 8 Feb 2019 18:38:37 +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 x18Ic7ON007837 for ; Fri, 8 Feb 2019 13:38:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2005F17BB6; Fri, 8 Feb 2019 18:38:07 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id D00DE60BE0 for ; Fri, 8 Feb 2019 18:38:06 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:24 -0500 Message-Id: <20190208183726.30903-31-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 30/32] util: Rename variable in virStorageSourceNewFromBacking 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: , 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.30]); Fri, 08 Feb 2019 18:38:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" To prepare for subsequent change to use VIR_AUTOPTR logic rename the @ret to @def. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/util/virstoragefile.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index d2636eec0a..5a8e5667f5 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -3669,39 +3669,39 @@ virStorageSourcePtr virStorageSourceNewFromBacking(virStorageSourcePtr parent) { struct stat st; - virStorageSourcePtr ret; + virStorageSourcePtr def; =20 if (virStorageIsRelative(parent->backingStoreRaw)) - ret =3D virStorageSourceNewFromBackingRelative(parent, + def =3D virStorageSourceNewFromBackingRelative(parent, parent->backingStoreR= aw); else - ret =3D virStorageSourceNewFromBackingAbsolute(parent->backingStor= eRaw); + def =3D virStorageSourceNewFromBackingAbsolute(parent->backingStor= eRaw); =20 - if (ret) { + if (def) { /* possibly update local type */ - if (ret->type =3D=3D VIR_STORAGE_TYPE_FILE) { - if (stat(ret->path, &st) =3D=3D 0) { + if (def->type =3D=3D VIR_STORAGE_TYPE_FILE) { + if (stat(def->path, &st) =3D=3D 0) { if (S_ISDIR(st.st_mode)) { - ret->type =3D VIR_STORAGE_TYPE_DIR; - ret->format =3D VIR_STORAGE_FILE_DIR; + def->type =3D VIR_STORAGE_TYPE_DIR; + def->format =3D VIR_STORAGE_FILE_DIR; } else if (S_ISBLK(st.st_mode)) { - ret->type =3D VIR_STORAGE_TYPE_BLOCK; + def->type =3D VIR_STORAGE_TYPE_BLOCK; } } } =20 /* copy parent's labelling and other top level stuff */ - if (virStorageSourceInitChainElement(ret, parent, true) < 0) + if (virStorageSourceInitChainElement(def, parent, true) < 0) goto error; =20 - ret->readonly =3D true; - ret->detected =3D true; + def->readonly =3D true; + def->detected =3D true; } =20 - return ret; + return def; =20 error: - virStorageSourceFree(ret); + virStorageSourceFree(def); return NULL; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651133016976.1653911531755; Fri, 8 Feb 2019 10:38:53 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F2E8880F7C; Fri, 8 Feb 2019 18:38:49 +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 BB18527067; Fri, 8 Feb 2019 18:38: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 5E9F1184B558; Fri, 8 Feb 2019 18:38: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 x18Ic7Wr007842 for ; Fri, 8 Feb 2019 13:38:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8EED717A66; Fri, 8 Feb 2019 18:38:07 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A62C60BE0 for ; Fri, 8 Feb 2019 18:38:07 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:25 -0500 Message-Id: <20190208183726.30903-32-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 31/32] tests: Rename variable in testStorageFileGetMetadata 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 08 Feb 2019 18:38:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" To prepare for subsequent change to use VIR_AUTOPTR logic rename the @ret to @def. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- tests/virstoragetest.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 49b8f42e6d..8db1d294b0 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -95,32 +95,32 @@ testStorageFileGetMetadata(const char *path, uid_t uid, gid_t gid) { struct stat st; - virStorageSourcePtr ret =3D NULL; + virStorageSourcePtr def =3D NULL; =20 - if (VIR_ALLOC(ret) < 0) + if (VIR_ALLOC(def) < 0) return NULL; =20 - ret->type =3D VIR_STORAGE_TYPE_FILE; - ret->format =3D format; + def->type =3D VIR_STORAGE_TYPE_FILE; + def->format =3D format; =20 if (stat(path, &st) =3D=3D 0) { if (S_ISDIR(st.st_mode)) { - ret->type =3D VIR_STORAGE_TYPE_DIR; + def->type =3D VIR_STORAGE_TYPE_DIR; } else if (S_ISBLK(st.st_mode)) { - ret->type =3D VIR_STORAGE_TYPE_BLOCK; + def->type =3D VIR_STORAGE_TYPE_BLOCK; } } =20 - if (VIR_STRDUP(ret->path, path) < 0) + if (VIR_STRDUP(def->path, path) < 0) goto error; =20 - if (virStorageFileGetMetadata(ret, uid, gid, false) < 0) + if (virStorageFileGetMetadata(def, uid, gid, false) < 0) goto error; =20 - return ret; + return def; =20 error: - virStorageSourceFree(ret); + virStorageSourceFree(def); return NULL; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 09:31:24 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.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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651137095613.4966950487442; Fri, 8 Feb 2019 10:38:57 -0800 (PST) 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 4FB715947A; Fri, 8 Feb 2019 18:38:55 +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 9B3CB62957; Fri, 8 Feb 2019 18:38: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 3A7183D3AB; Fri, 8 Feb 2019 18:38:54 +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 x18Ic8t5007853 for ; Fri, 8 Feb 2019 13:38:08 -0500 Received: by smtp.corp.redhat.com (Postfix) id 10433BA53; Fri, 8 Feb 2019 18:38:08 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC26360BE0 for ; Fri, 8 Feb 2019 18:38:07 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:26 -0500 Message-Id: <20190208183726.30903-33-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 32/32] util: Introduce VIR_DEFINE_AUTOPTR_FUNC for virStorageSource 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: , 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.39]); Fri, 08 Feb 2019 18:38:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 3 +- src/qemu/qemu_domain.c | 3 +- src/qemu/qemu_driver.c | 9 +- src/qemu/qemu_migration.c | 3 +- src/storage/storage_backend_gluster.c | 3 +- src/storage/storage_util.c | 25 ++--- src/util/virstoragefile.c | 141 +++++++++++--------------- src/util/virstoragefile.h | 1 + tests/qemublocktest.c | 6 +- tests/virstoragetest.c | 50 ++++----- 10 files changed, 97 insertions(+), 147 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9e46cf721b..5cd7362580 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9059,13 +9059,13 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr c= txt, unsigned int flags, virDomainXMLOptionPtr xmlopt) { - virStorageSourcePtr backingStore =3D NULL; xmlNodePtr save_ctxt =3D ctxt->node; xmlNodePtr source; char *type =3D NULL; char *format =3D NULL; char *idx =3D NULL; int ret =3D -1; + VIR_AUTOPTR(virStorageSource) backingStore =3D NULL; =20 if (!(ctxt->node =3D virXPathNode("./backingStore", ctxt))) { ret =3D 0; @@ -9126,7 +9126,6 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctx= t, ret =3D 0; =20 cleanup: - virStorageSourceFree(backingStore); VIR_FREE(type); VIR_FREE(format); VIR_FREE(idx); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 801d25a44b..ac01e861f7 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2730,10 +2730,10 @@ qemuDomainObjPrivateXMLParseJobNBDSource(xmlNodePtr= node, { xmlNodePtr savedNode =3D ctxt->node; qemuDomainDiskPrivatePtr diskPriv =3D QEMU_DOMAIN_DISK_PRIVATE(disk); - virStorageSourcePtr migrSource =3D NULL; char *format =3D NULL; char *type =3D NULL; int ret =3D -1; + VIR_AUTOPTR(virStorageSource) migrSource =3D NULL; =20 ctxt->node =3D node; =20 @@ -2781,7 +2781,6 @@ qemuDomainObjPrivateXMLParseJobNBDSource(xmlNodePtr n= ode, ret =3D 0; =20 cleanup: - virStorageSourceFree(migrSource); VIR_FREE(format); VIR_FREE(type); ctxt->node =3D savedNode; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1822248749..dc51de0310 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -274,11 +274,11 @@ qemuSecurityChownCallback(const virStorageSource *src, uid_t uid, gid_t gid) { - virStorageSourcePtr cpy =3D NULL; struct stat sb; int save_errno =3D 0; int ret =3D -1; int rv; + VIR_AUTOPTR(virStorageSource) cpy =3D NULL; =20 rv =3D virStorageFileSupportsSecurityDriver(src); if (rv <=3D 0) @@ -319,7 +319,6 @@ qemuSecurityChownCallback(const virStorageSource *src, cleanup: save_errno =3D errno; virStorageFileDeinit(cpy); - virStorageSourceFree(cpy); errno =3D save_errno; =20 return ret; @@ -17958,7 +17957,7 @@ qemuDomainBlockRebase(virDomainPtr dom, const char = *path, const char *base, virDomainObjPtr vm; int ret =3D -1; unsigned long long speed =3D bandwidth; - virStorageSourcePtr dest =3D NULL; + VIR_AUTOPTR(virStorageSource) dest =3D NULL; =20 virCheckFlags(VIR_DOMAIN_BLOCK_REBASE_SHALLOW | VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT | @@ -18020,7 +18019,6 @@ qemuDomainBlockRebase(virDomainPtr dom, const char = *path, const char *base, =20 cleanup: virDomainObjEndAPI(&vm); - virStorageSourceFree(dest); return ret; } =20 @@ -18150,10 +18148,10 @@ qemuDomainBlockCommit(virDomainPtr dom, char *topPath =3D NULL; char *basePath =3D NULL; char *backingPath =3D NULL; - virStorageSourcePtr mirror =3D NULL; unsigned long long speed =3D bandwidth; qemuBlockJobDataPtr job =3D NULL; qemuBlockJobType jobtype =3D QEMU_BLOCKJOB_TYPE_COMMIT; + VIR_AUTOPTR(virStorageSource) mirror =3D NULL; =20 /* XXX Add support for COMMIT_DELETE */ virCheckFlags(VIR_DOMAIN_BLOCK_COMMIT_SHALLOW | @@ -18352,7 +18350,6 @@ qemuDomainBlockCommit(virDomainPtr dom, virFreeError(orig_err); } } - virStorageSourceFree(mirror); qemuBlockJobStartupFinalize(job); qemuDomainObjEndJob(driver, vm); =20 diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 3107a279dd..c93ae33476 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -788,9 +788,9 @@ qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverPtr= driver, { qemuBlockStorageSourceAttachDataPtr data =3D NULL; qemuDomainDiskPrivatePtr diskPriv =3D QEMU_DOMAIN_DISK_PRIVATE(disk); - virStorageSourcePtr copysrc =3D NULL; int mon_ret =3D 0; int ret =3D -1; + VIR_AUTOPTR(virStorageSource) copysrc =3D NULL; =20 VIR_DEBUG("starting blockdev mirror for disk=3D%s to host=3D%s", diskA= lias, host); =20 @@ -849,7 +849,6 @@ qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverPtr= driver, =20 cleanup: qemuBlockStorageSourceAttachDataFree(data); - virStorageSourceFree(copysrc); return ret; } =20 diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_ba= ckend_gluster.c index 1888314d95..846a647cb6 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -236,10 +236,10 @@ virStorageBackendGlusterRefreshVol(virStorageBackendG= lusterStatePtr state, { int ret =3D -1; glfs_fd_t *fd =3D NULL; - virStorageSourcePtr meta =3D NULL; ssize_t len; int backingFormat; VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; + VIR_AUTOPTR(virStorageSource) meta =3D NULL; VIR_AUTOFREE(char *) header =3D NULL; =20 *volptr =3D NULL; @@ -323,7 +323,6 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlu= sterStatePtr state, VIR_STEAL_PTR(*volptr, vol); ret =3D 0; cleanup: - virStorageSourceFree(meta); if (fd) glfs_close(fd); return ret; diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index af6ab20ea6..04e7592bf2 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -3353,10 +3353,9 @@ storageBackendProbeTarget(virStorageSourcePtr target, virStorageEncryptionPtr *encryption) { int backingStoreFormat; - int ret =3D -1; int rc; - virStorageSourcePtr meta =3D NULL; struct stat sb; + VIR_AUTOPTR(virStorageSource) meta =3D NULL; VIR_AUTOCLOSE fd =3D -1; =20 if (encryption) @@ -3368,17 +3367,16 @@ storageBackendProbeTarget(virStorageSourcePtr targe= t, fd =3D rc; =20 if (virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb) < 0) - goto cleanup; + return -1; =20 if (S_ISDIR(sb.st_mode)) { if (storageBackendIsPloopDir(target->path)) { if (storageBackendRedoPloopUpdate(target, &sb, &fd, VIR_STORAGE_VOL_FS_PROBE_FLA= GS) < 0) - goto cleanup; + return -1; } else { target->format =3D VIR_STORAGE_FILE_DIR; - ret =3D 0; - goto cleanup; + return 0; } } =20 @@ -3386,11 +3384,11 @@ storageBackendProbeTarget(virStorageSourcePtr targe= t, fd, VIR_STORAGE_FILE_AUTO, &backingStoreFormat))) - goto cleanup; + return -1; =20 if (meta->backingStoreRaw) { if (!(target->backingStore =3D virStorageSourceNewFromBacking(meta= ))) - goto cleanup; + return -1; =20 target->backingStore->format =3D backingStoreFormat; =20 @@ -3401,7 +3399,7 @@ storageBackendProbeTarget(virStorageSourcePtr target, virStorageSourceFree(target->backingStore); =20 if (VIR_ALLOC(target->backingStore) < 0) - goto cleanup; + return -1; =20 target->backingStore->type =3D VIR_STORAGE_TYPE_NETWORK; target->backingStore->path =3D meta->backingStoreRaw; @@ -3430,8 +3428,6 @@ storageBackendProbeTarget(virStorageSourcePtr target, target->format =3D meta->format; =20 /* Default to success below this point */ - ret =3D 0; - if (meta->capacity) target->capacity =3D meta->capacity; =20 @@ -3457,9 +3453,7 @@ storageBackendProbeTarget(virStorageSourcePtr target, VIR_STEAL_PTR(target->compat, meta->compat); } =20 - cleanup: - virStorageSourceFree(meta); - return ret; + return 0; } =20 =20 @@ -3527,11 +3521,11 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr = pool) struct dirent *ent; struct statvfs sb; struct stat statbuf; - virStorageSourcePtr target =3D NULL; int direrr; int ret =3D -1; VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; VIR_AUTOCLOSE fd =3D -1; + VIR_AUTOPTR(virStorageSource) target =3D NULL; =20 if (virDirOpen(&dir, def->target.path) < 0) goto cleanup; @@ -3622,7 +3616,6 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr po= ol) ret =3D 0; cleanup: VIR_DIR_CLOSE(dir); - virStorageSourceFree(target); if (ret < 0) virStoragePoolObjClearVols(pool); return ret; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 5a8e5667f5..2d887fe873 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1117,7 +1117,8 @@ static virStorageSourcePtr virStorageFileMetadataNew(const char *path, int format) { - virStorageSourcePtr def =3D NULL; + virStorageSourcePtr ret =3D NULL; + VIR_AUTOPTR(virStorageSource) def =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -1126,13 +1127,10 @@ virStorageFileMetadataNew(const char *path, def->type =3D VIR_STORAGE_TYPE_FILE; =20 if (VIR_STRDUP(def->path, path) < 0) - goto error; - - return def; + return NULL; =20 - error: - virStorageSourceFree(def); - return NULL; + VIR_STEAL_PTR(ret, def); + return ret; } =20 =20 @@ -1205,11 +1203,11 @@ virStorageFileGetMetadataFromFD(const char *path, =20 { virStorageSourcePtr ret =3D NULL; - virStorageSourcePtr meta =3D NULL; ssize_t len =3D VIR_STORAGE_MAX_HEADER; struct stat sb; int dummy; VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOPTR(virStorageSource) meta =3D NULL; =20 if (!backingFormat) backingFormat =3D &dummy; @@ -1231,21 +1229,21 @@ virStorageFileGetMetadataFromFD(const char *path, meta->type =3D VIR_STORAGE_TYPE_DIR; meta->format =3D VIR_STORAGE_FILE_DIR; VIR_STEAL_PTR(ret, meta); - goto cleanup; + return ret; } =20 if (lseek(fd, 0, SEEK_SET) =3D=3D (off_t)-1) { virReportSystemError(errno, _("cannot seek to start of '%s'"), met= a->path); - goto cleanup; + return NULL; } =20 if ((len =3D virFileReadHeaderFD(fd, len, &buf)) < 0) { virReportSystemError(errno, _("cannot read header '%s'"), meta->pa= th); - goto cleanup; + return NULL; } =20 if (virStorageFileGetMetadataInternal(meta, buf, len, backingFormat) <= 0) - goto cleanup; + return NULL; =20 if (S_ISREG(sb.st_mode)) meta->type =3D VIR_STORAGE_TYPE_FILE; @@ -1253,9 +1251,6 @@ virStorageFileGetMetadataFromFD(const char *path, meta->type =3D VIR_STORAGE_TYPE_BLOCK; =20 VIR_STEAL_PTR(ret, meta); - - cleanup: - virStorageSourceFree(meta); return ret; } =20 @@ -2243,7 +2238,8 @@ virStorageSourcePtr virStorageSourceCopy(const virStorageSource *src, bool backingChain) { - virStorageSourcePtr def =3D NULL; + virStorageSourcePtr ret =3D NULL; + VIR_AUTOPTR(virStorageSource) def =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -2282,60 +2278,57 @@ virStorageSourceCopy(const virStorageSource *src, VIR_STRDUP(def->compat, src->compat) < 0 || VIR_STRDUP(def->tlsAlias, src->tlsAlias) < 0 || VIR_STRDUP(def->tlsCertdir, src->tlsCertdir) < 0) - goto error; + return NULL; =20 if (src->nhosts) { if (!(def->hosts =3D virStorageNetHostDefCopy(src->nhosts, src->ho= sts))) - goto error; + return NULL; =20 def->nhosts =3D src->nhosts; } =20 if (src->srcpool && !(def->srcpool =3D virStorageSourcePoolDefCopy(src->srcpool))) - goto error; + return NULL; =20 if (src->features && !(def->features =3D virBitmapNewCopy(src->features))) - goto error; + return NULL; =20 if (src->encryption && !(def->encryption =3D virStorageEncryptionCopy(src->encryption))) - goto error; + return NULL; =20 if (src->perms && !(def->perms =3D virStoragePermsCopy(src->perms))) - goto error; + return NULL; =20 if (src->timestamps && !(def->timestamps =3D virStorageTimestampsCopy(src->timestamps))) - goto error; + return NULL; =20 if (virStorageSourceSeclabelsCopy(def, src) < 0) - goto error; + return NULL; =20 if (src->auth && !(def->auth =3D virStorageAuthDefCopy(src->auth))) - goto error; + return NULL; =20 if (src->pr && !(def->pr =3D virStoragePRDefCopy(src->pr))) - goto error; + return NULL; =20 if (virStorageSourceInitiatorCopy(&def->initiator, &src->initiator)) - goto error; + return NULL; =20 if (backingChain && src->backingStore) { if (!(def->backingStore =3D virStorageSourceCopy(src->backingStore, true))) - goto error; + return NULL; } =20 - return def; - - error: - virStorageSourceFree(def); - return NULL; + VIR_STEAL_PTR(ret, def); + return ret; } =20 =20 @@ -2577,27 +2570,28 @@ static virStorageSourcePtr virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent, const char *rel) { - virStorageSourcePtr def; + virStorageSourcePtr ret =3D NULL; VIR_AUTOFREE(char *) dirname =3D NULL; + VIR_AUTOPTR(virStorageSource) def =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; =20 /* store relative name */ if (VIR_STRDUP(def->relPath, parent->backingStoreRaw) < 0) - goto error; + return NULL; =20 if (!(dirname =3D mdir_name(parent->path))) { virReportOOMError(); - goto error; + return NULL; } =20 if (STRNEQ(dirname, "/")) { if (virAsprintf(&def->path, "%s/%s", dirname, rel) < 0) - goto error; + return NULL; } else { if (virAsprintf(&def->path, "/%s", rel) < 0) - goto error; + return NULL; } =20 if (virStorageSourceGetActualType(parent) =3D=3D VIR_STORAGE_TYPE_NETW= ORK) { @@ -2608,25 +2602,20 @@ virStorageSourceNewFromBackingRelative(virStorageSo= urcePtr parent, if (parent->nhosts) { if (!(def->hosts =3D virStorageNetHostDefCopy(parent->nhosts, parent->hosts))) - goto error; + return NULL; =20 def->nhosts =3D parent->nhosts; } =20 if (VIR_STRDUP(def->volume, parent->volume) < 0) - goto error; + return NULL; } else { /* set the type to _FILE, the caller shall update it to the actual= type */ def->type =3D VIR_STORAGE_TYPE_FILE; } =20 - cleanup: - return def; - - error: - virStorageSourceFree(def); - def =3D NULL; - goto cleanup; + VIR_STEAL_PTR(ret, def); + return ret; } =20 =20 @@ -3619,8 +3608,9 @@ virStorageSourcePtr virStorageSourceNewFromBackingAbsolute(const char *path) { const char *json; - virStorageSourcePtr def; + virStorageSourcePtr ret =3D NULL; int rc; + VIR_AUTOPTR(virStorageSource) def =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -3629,7 +3619,7 @@ virStorageSourceNewFromBackingAbsolute(const char *pa= th) def->type =3D VIR_STORAGE_TYPE_FILE; =20 if (VIR_STRDUP(def->path, path) < 0) - goto error; + return NULL; } else { def->type =3D VIR_STORAGE_TYPE_NETWORK; =20 @@ -3644,7 +3634,7 @@ virStorageSourceNewFromBackingAbsolute(const char *pa= th) rc =3D virStorageSourceParseBackingColon(def, path); =20 if (rc < 0) - goto error; + return NULL; =20 virStorageSourceNetworkAssignDefaultPorts(def); =20 @@ -3657,11 +3647,8 @@ virStorageSourceNewFromBackingAbsolute(const char *p= ath) } } =20 - return def; - - error: - virStorageSourceFree(def); - return NULL; + VIR_STEAL_PTR(ret, def); + return ret; } =20 =20 @@ -3669,7 +3656,8 @@ virStorageSourcePtr virStorageSourceNewFromBacking(virStorageSourcePtr parent) { struct stat st; - virStorageSourcePtr def; + virStorageSourcePtr ret =3D NULL; + VIR_AUTOPTR(virStorageSource) def =3D NULL; =20 if (virStorageIsRelative(parent->backingStoreRaw)) def =3D virStorageSourceNewFromBackingRelative(parent, @@ -3692,17 +3680,14 @@ virStorageSourceNewFromBacking(virStorageSourcePtr = parent) =20 /* copy parent's labelling and other top level stuff */ if (virStorageSourceInitChainElement(def, parent, true) < 0) - goto error; + return NULL; =20 def->readonly =3D true; def->detected =3D true; } =20 - return def; - - error: - virStorageSourceFree(def); - return NULL; + VIR_STEAL_PTR(ret, def); + return ret; } =20 =20 @@ -3843,9 +3828,8 @@ virStorageSourceUpdateCapacity(virStorageSourcePtr sr= c, ssize_t len, bool probe) { - int ret =3D -1; - virStorageSourcePtr meta =3D NULL; int format =3D src->format; + VIR_AUTOPTR(virStorageSource) meta =3D NULL; =20 /* Raw files: capacity is physical size. For all other files: if * the metadata has a capacity, use that, otherwise fall back to @@ -3855,12 +3839,12 @@ virStorageSourceUpdateCapacity(virStorageSourcePtr = src, virReportError(VIR_ERR_INTERNAL_ERROR, _("no disk format for %s and probing is disable= d"), src->path); - goto cleanup; + return -1; } =20 if ((format =3D virStorageFileProbeFormatFromBuf(src->path, buf, len)) < 0) - goto cleanup; + return -1; =20 src->format =3D format; } @@ -3873,17 +3857,13 @@ virStorageSourceUpdateCapacity(virStorageSourcePtr = src, if (src->encryption && meta->encryption) src->encryption->payload_offset =3D meta->encryption->payload_= offset; } else { - goto cleanup; + return -1; } =20 if (src->encryption && src->encryption->payload_offset !=3D -1) src->capacity -=3D src->encryption->payload_offset * 512; =20 - ret =3D 0; - - cleanup: - virStorageSourceFree(meta); - return ret; + return 0; } =20 =20 @@ -4820,10 +4800,10 @@ virStorageFileGetMetadataRecurse(virStorageSourcePt= r src, int ret =3D -1; const char *uniqueName; ssize_t headerLen; - virStorageSourcePtr backingStore =3D NULL; int backingFormat; int rv; VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOPTR(virStorageSource) backingStore =3D NULL; =20 VIR_DEBUG("path=3D%s format=3D%d uid=3D%u gid=3D%u", src->path, src->format, @@ -4906,7 +4886,6 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr = src, if (virStorageSourceHasBacking(src)) src->backingStore->id =3D depth; virStorageFileDeinit(src); - virStorageSourceFree(backingStore); return ret; } =20 @@ -4975,11 +4954,10 @@ int virStorageFileGetBackingStoreStr(virStorageSourcePtr src, char **backing) { - virStorageSourcePtr tmp =3D NULL; ssize_t headerLen; - int ret =3D -1; int rv; VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOPTR(virStorageSource) tmp =3D NULL; =20 *backing =3D NULL; =20 @@ -5003,17 +4981,12 @@ virStorageFileGetBackingStoreStr(virStorageSourcePt= r src, } =20 if (!(tmp =3D virStorageSourceCopy(src, false))) - goto cleanup; + return -1; =20 if (virStorageFileGetMetadataInternal(tmp, buf, headerLen, NULL) < 0) - goto cleanup; + return -1; =20 VIR_STEAL_PTR(*backing, tmp->backingStoreRaw); =20 - ret =3D 0; - - cleanup: - virStorageSourceFree(tmp); - - return ret; + return 0; } diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index eacc927ea6..8c3a36d473 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -544,5 +544,6 @@ void virStorageFileReportBrokenChain(int errcode, virStorageSourcePtr parent); =20 VIR_DEFINE_AUTOPTR_FUNC(virStorageAuthDef, virStorageAuthDefFree); +VIR_DEFINE_AUTOPTR_FUNC(virStorageSource, virStorageSourceFree); =20 #endif /* LIBVIRT_VIRSTORAGEFILE_H */ diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index 5848f6b5b5..d7e5e72a0b 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -46,14 +46,14 @@ testBackingXMLjsonXML(const void *args) xmlDocPtr xml =3D NULL; xmlXPathContextPtr ctxt =3D NULL; virBuffer buf =3D VIR_BUFFER_INITIALIZER; - virStorageSourcePtr xmlsrc =3D NULL; - virStorageSourcePtr jsonsrc =3D NULL; virJSONValuePtr backendprops =3D NULL; virJSONValuePtr wrapper =3D NULL; char *propsstr =3D NULL; char *protocolwrapper =3D NULL; char *actualxml =3D NULL; int ret =3D -1; + VIR_AUTOPTR(virStorageSource) xmlsrc =3D NULL; + VIR_AUTOPTR(virStorageSource) jsonsrc =3D NULL; =20 if (VIR_ALLOC(xmlsrc) < 0) return -1; @@ -104,8 +104,6 @@ testBackingXMLjsonXML(const void *args) ret =3D 0; =20 cleanup: - virStorageSourceFree(xmlsrc); - virStorageSourceFree(jsonsrc); VIR_FREE(propsstr); VIR_FREE(protocolwrapper); VIR_FREE(actualxml); diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 8db1d294b0..646ae78ff0 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -95,7 +95,8 @@ testStorageFileGetMetadata(const char *path, uid_t uid, gid_t gid) { struct stat st; - virStorageSourcePtr def =3D NULL; + virStorageSourcePtr ret =3D NULL; + VIR_AUTOPTR(virStorageSource) def =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -112,16 +113,13 @@ testStorageFileGetMetadata(const char *path, } =20 if (VIR_STRDUP(def->path, path) < 0) - goto error; + return NULL; =20 if (virStorageFileGetMetadata(def, uid, gid, false) < 0) - goto error; - - return def; + return NULL; =20 - error: - virStorageSourceFree(def); - return NULL; + VIR_STEAL_PTR(ret, def); + return ret; } =20 static int @@ -308,41 +306,40 @@ static int testStorageChain(const void *args) { const struct testChainData *data =3D args; - int ret =3D -1; - virStorageSourcePtr meta; virStorageSourcePtr elt; size_t i =3D 0; + VIR_AUTOPTR(virStorageSource) meta =3D NULL; VIR_AUTOFREE(char *) broken =3D NULL; =20 meta =3D testStorageFileGetMetadata(data->start, data->format, -1, -1); if (!meta) { if (data->flags & EXP_FAIL) { virResetLastError(); - ret =3D 0; + return 0; } - goto cleanup; + return -1; } else if (data->flags & EXP_FAIL) { fprintf(stderr, "call should have failed\n"); - goto cleanup; + return -1; } if (data->flags & EXP_WARN) { if (virGetLastErrorCode() =3D=3D VIR_ERR_OK) { fprintf(stderr, "call should have warned\n"); - goto cleanup; + return -1; } virResetLastError(); if (virStorageFileChainGetBroken(meta, &broken) || !broken) { fprintf(stderr, "call should identify broken part of chain\n"); - goto cleanup; + return -1; } } else { if (virGetLastErrorCode()) { fprintf(stderr, "call should not have warned\n"); - goto cleanup; + return -1; } if (virStorageFileChainGetBroken(meta, &broken) || broken) { fprintf(stderr, "chain should not be identified as broken\n"); - goto cleanup; + return -1; } } =20 @@ -353,7 +350,7 @@ testStorageChain(const void *args) =20 if (i =3D=3D data->nfiles) { fprintf(stderr, "probed chain was too long\n"); - goto cleanup; + return -1; } =20 if (virAsprintf(&expect, @@ -378,24 +375,21 @@ testStorageChain(const void *args) elt->format, virStorageNetProtocolTypeToString(elt->protocol), NULLSTR(elt->nhosts ? elt->hosts[0].name : NULL)) = < 0) { - goto cleanup; + return -1; } if (STRNEQ(expect, actual)) { virTestDifference(stderr, expect, actual); - goto cleanup; + return -1; } elt =3D elt->backingStore; i++; } if (i !=3D data->nfiles) { fprintf(stderr, "probed chain was too short\n"); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virStorageSourceFree(meta); - return ret; + return 0; } =20 struct testLookupData @@ -646,9 +640,9 @@ testBackingParse(const void *args) { const struct testBackingParseData *data =3D args; virBuffer buf =3D VIR_BUFFER_INITIALIZER; - virStorageSourcePtr src =3D NULL; int ret =3D -1; VIR_AUTOFREE(char *) xml =3D NULL; + VIR_AUTOPTR(virStorageSource) src =3D NULL; =20 if (!(src =3D virStorageSourceNewFromBackingAbsolute(data->backing))) { if (!data->expect) @@ -680,7 +674,6 @@ testBackingParse(const void *args) ret =3D 0; =20 cleanup: - virStorageSourceFree(src); virBufferFreeAndReset(&buf); =20 return ret; @@ -696,10 +689,10 @@ mymain(void) struct testPathCanonicalizeData data3; struct testPathRelativeBacking data4; struct testBackingParseData data5; - virStorageSourcePtr chain =3D NULL; virStorageSourcePtr chain2; /* short for chain->backingStore */ virStorageSourcePtr chain3; /* short for chain2->backingStore */ VIR_AUTOPTR(virCommand) cmd =3D NULL; + VIR_AUTOPTR(virStorageSource) chain =3D NULL; =20 if (storageRegisterAll() < 0) return EXIT_FAILURE; @@ -1580,7 +1573,6 @@ mymain(void) =20 cleanup: /* Final cleanup */ - virStorageSourceFree(chain); testCleanupImages(); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list