From nobody Sun Feb 8 16:31:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.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 1549460532653358.0014570882156; Wed, 6 Feb 2019 05:42:12 -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 889E289ACD; Wed, 6 Feb 2019 13:42:09 +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 3FEB463B86; Wed, 6 Feb 2019 13:42:08 +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 E748018033A4; Wed, 6 Feb 2019 13:42:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x16Dg4RP001889 for ; Wed, 6 Feb 2019 08:42:04 -0500 Received: by smtp.corp.redhat.com (Postfix) id C1A985C5FD; Wed, 6 Feb 2019 13:42:04 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-116-19.phx2.redhat.com [10.3.116.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61643660B2 for ; Wed, 6 Feb 2019 13:42:04 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 6 Feb 2019 08:41:33 -0500 Message-Id: <20190206134147.18032-2-jferlan@redhat.com> In-Reply-To: <20190206134147.18032-1-jferlan@redhat.com> References: <20190206134147.18032-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/15] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 06 Feb 2019 13:42:10 +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. For virStorageAuthDefCopy use authdef and ret as consistently as similar other code. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety --- src/conf/domain_conf.c | 29 +++++++++++------------------ src/conf/storage_conf.c | 6 ++---- src/qemu/qemu_parse_command.c | 6 ++---- src/util/virstoragefile.c | 33 ++++++++++++++------------------- src/util/virstoragefile.h | 1 + 5 files changed, 30 insertions(+), 45 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1fc4c8a35a..5699a60549 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7578,10 +7578,9 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePt= r sourcenode, virDomainHostdevSubsysSCSIPtr d= ef, xmlXPathContextPtr ctxt) { - int ret =3D -1; int auth_secret_usage =3D -1; xmlNodePtr cur; - virStorageAuthDefPtr authdef =3D NULL; + VIR_AUTOPTR(virStorageAuthDef) authdef =3D NULL; virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc =3D &def->u.iscsi; =20 /* For the purposes of command line creation, this needs to look @@ -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,30 +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; } - iscsisrc->src->auth =3D authdef; - authdef =3D NULL; + VIR_STEAL_PTR(iscsisrc->src->auth, authdef); } cur =3D cur->next; } - ret =3D 0; - - cleanup: - virStorageAuthDefFree(authdef); - return ret; + return 0; } =20 static int @@ -9684,7 +9678,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, virStorageEncryptionPtr encryption =3D NULL; char *serial =3D NULL; char *startupPolicy =3D NULL; - virStorageAuthDefPtr authdef =3D NULL; + VIR_AUTOPTR(virStorageAuthDef) authdef =3D NULL; char *tray =3D NULL; char *removable =3D NULL; char *logical_block_size =3D NULL; @@ -10094,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 1ee31ca676..9cd3d836a3 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -458,7 +458,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, int nsource; size_t i; virStoragePoolOptionsPtr options; - virStorageAuthDefPtr authdef =3D NULL; + VIR_AUTOPTR(virStorageAuthDef) authdef =3D NULL; char *name =3D NULL; char *port =3D NULL; char *ver =3D NULL; @@ -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) */ @@ -615,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 c4650f01e0..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; @@ -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. @@ -152,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 8319ba9c8c..b3f5e0204d 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1879,26 +1879,24 @@ virStorageAuthDefFree(virStorageAuthDefPtr authdef) virStorageAuthDefPtr virStorageAuthDefCopy(const virStorageAuthDef *src) { - virStorageAuthDefPtr ret; + VIR_AUTOPTR(virStorageAuthDef) authdef =3D NULL; + 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) + return NULL; /* 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) + return NULL; + authdef->authType =3D src->authType; =20 - if (virSecretLookupDefCopy(&ret->seclookupdef, &src->seclookupdef) < 0) - goto error; + if (virSecretLookupDefCopy(&authdef->seclookupdef, &src->seclookupdef)= < 0) + return NULL; =20 + VIR_STEAL_PTR(ret, authdef); return ret; - - error: - virStorageAuthDefFree(ret); - return NULL; } =20 =20 @@ -1907,7 +1905,7 @@ virStorageAuthDefParse(xmlNodePtr node, xmlXPathContextPtr ctxt) { xmlNodePtr saveNode =3D ctxt->node; - virStorageAuthDefPtr authdef =3D NULL; + VIR_AUTOPTR(virStorageAuthDef) authdef =3D NULL; virStorageAuthDefPtr ret =3D NULL; xmlNodePtr secretnode =3D NULL; char *authtype =3D NULL; @@ -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:")) @@ -2895,9 +2892,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. @@ -2936,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..f1164dde9b 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -543,4 +543,5 @@ 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