From nobody Sun Feb 8 22:06:37 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 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