From nobody Fri May 3 14:51:38 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1506677167270897.981516412099; Fri, 29 Sep 2017 02:26:07 -0700 (PDT) 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 D377E4E33E; Fri, 29 Sep 2017 09:26:05 +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 8D75F6294C; Fri, 29 Sep 2017 09:26:05 +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 011244ED20; Fri, 29 Sep 2017 09:26:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v8T92XdW019396 for ; Fri, 29 Sep 2017 05:02:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9B48F1814D; Fri, 29 Sep 2017 09:02:33 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id E529C5D9CD; Fri, 29 Sep 2017 09:02:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D377E4E33E Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 29 Sep 2017 11:02:23 +0200 Message-Id: <640651b5303d4d31b9e82cb1ae12728efb810d33.1506675642.git.pkrempa@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH] conf: Split out parsing of network disk source XML elements X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 29 Sep 2017 09:26:06 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" virDomainDiskSourceParse got to the point of being an ugly spaghetti mess by adding more and more stuff into it. Split out parsing of network disk information into a separate function so that it stays contained. Reviewed-by: John Ferlan --- I've had this patch on a branch that makes virDomainDiskSourceParse uglier, but with the recent VxHS patches I've got a merge conflict, thus I'm sending it now. Note: this patch was generated with the "patience" diff algorithm src/conf/domain_conf.c | 183 ++++++++++++++++++++++++++-------------------= ---- 1 file changed, 99 insertions(+), 84 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 87192eb2d..98f5666ef 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8106,18 +8106,109 @@ virDomainDiskSourcePoolDefParse(xmlNodePtr node, } -int -virDomainDiskSourceParse(xmlNodePtr node, - xmlXPathContextPtr ctxt, - virStorageSourcePtr src, - unsigned int flags) +static int +virDomainDiskSourceNetworkParse(xmlNodePtr node, + xmlXPathContextPtr ctxt, + virStorageSourcePtr src, + unsigned int flags) { - int ret =3D -1; char *protocol =3D NULL; - xmlNodePtr saveNode =3D ctxt->node; char *haveTLS =3D NULL; char *tlsCfg =3D NULL; int tlsCfgVal; + int ret =3D -1; + + if (!(protocol =3D virXMLPropString(node, "protocol"))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing network source protocol type")); + goto cleanup; + } + + if ((src->protocol =3D virStorageNetProtocolTypeFromString(protocol)) = <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown protocol type '%s'"), protocol); + goto cleanup; + } + + if (!(src->path =3D virXMLPropString(node, "name")) && + src->protocol !=3D VIR_STORAGE_NET_PROTOCOL_NBD) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing name for disk source")); + goto cleanup; + } + + /* Check tls=3Dyes|no domain setting for the block device + * At present only VxHS. Other block devices may be added later */ + if (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_VXHS && + (haveTLS =3D virXMLPropString(node, "tls"))) { + if ((src->haveTLS =3D + virTristateBoolTypeFromString(haveTLS)) <=3D 0) { + virReportError(VIR_ERR_XML_ERROR, + _("unknown disk source 'tls' setting '%s'"), + haveTLS); + goto cleanup; + } + } + + if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) && + (tlsCfg =3D virXMLPropString(node, "tlsFromConfig"))) { + if (virStrToLong_i(tlsCfg, NULL, 10, &tlsCfgVal) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid tlsFromConfig value: %s"), + tlsCfg); + goto cleanup; + } + src->tlsFromConfig =3D !!tlsCfgVal; + } + + /* for historical reasons the volume name for gluster volume is stored + * as a part of the path. This is hard to work with when dealing with + * relative names. Split out the volume into a separate variable */ + if (src->path && src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_GLUSTER= ) { + char *tmp; + if (!(tmp =3D strchr(src->path, '/')) || + tmp =3D=3D src->path) { + virReportError(VIR_ERR_XML_ERROR, + _("missing volume name or file name in " + "gluster source path '%s'"), src->path); + goto cleanup; + } + + src->volume =3D src->path; + + if (VIR_STRDUP(src->path, tmp) < 0) + goto cleanup; + + tmp[0] =3D '\0'; + } + + /* snapshot currently works only for remote disks */ + src->snapshot =3D virXPathString("string(./snapshot/@name)", ctxt); + + /* config file currently only works with remote disks */ + src->configFile =3D virXPathString("string(./config/@file)", ctxt); + + if (virDomainStorageNetworkParseHosts(node, &src->hosts, &src->nhosts)= < 0) + goto cleanup; + + virStorageSourceNetworkAssignDefaultPorts(src); + + ret =3D 0; + + cleanup: + VIR_FREE(protocol); + return ret; +} + + +int +virDomainDiskSourceParse(xmlNodePtr node, + xmlXPathContextPtr ctxt, + virStorageSourcePtr src, + unsigned int flags) +{ + int ret =3D -1; + xmlNodePtr saveNode =3D ctxt->node; ctxt->node =3D node; @@ -8132,81 +8223,8 @@ virDomainDiskSourceParse(xmlNodePtr node, src->path =3D virXMLPropString(node, "dir"); break; case VIR_STORAGE_TYPE_NETWORK: - if (!(protocol =3D virXMLPropString(node, "protocol"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing network source protocol type")); + if (virDomainDiskSourceNetworkParse(node, ctxt, src, flags) < 0) goto cleanup; - } - - if ((src->protocol =3D virStorageNetProtocolTypeFromString(protoco= l)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown protocol type '%s'"), protocol); - goto cleanup; - } - - if (!(src->path =3D virXMLPropString(node, "name")) && - src->protocol !=3D VIR_STORAGE_NET_PROTOCOL_NBD) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing name for disk source")); - goto cleanup; - } - - /* Check tls=3Dyes|no domain setting for the block device - * At present only VxHS. Other block devices may be added later */ - if (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_VXHS && - (haveTLS =3D virXMLPropString(node, "tls"))) { - if ((src->haveTLS =3D - virTristateBoolTypeFromString(haveTLS)) <=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("unknown disk source 'tls' setting '%s'"), - haveTLS); - goto cleanup; - } - } - - if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) && - (tlsCfg =3D virXMLPropString(node, "tlsFromConfig"))) { - if (virStrToLong_i(tlsCfg, NULL, 10, &tlsCfgVal) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid tlsFromConfig value: %s"), - tlsCfg); - goto cleanup; - } - src->tlsFromConfig =3D !!tlsCfgVal; - } - - /* for historical reasons the volume name for gluster volume is st= ored - * as a part of the path. This is hard to work with when dealing w= ith - * relative names. Split out the volume into a separate variable */ - if (src->path && src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_GLU= STER) { - char *tmp; - if (!(tmp =3D strchr(src->path, '/')) || - tmp =3D=3D src->path) { - virReportError(VIR_ERR_XML_ERROR, - _("missing volume name or file name in " - "gluster source path '%s'"), src->path); - goto cleanup; - } - - src->volume =3D src->path; - - if (VIR_STRDUP(src->path, tmp) < 0) - goto cleanup; - - tmp[0] =3D '\0'; - } - - /* snapshot currently works only for remote disks */ - src->snapshot =3D virXPathString("string(./snapshot/@name)", ctxt); - - /* config file currently only works with remote disks */ - src->configFile =3D virXPathString("string(./config/@file)", ctxt); - - if (virDomainStorageNetworkParseHosts(node, &src->hosts, &src->nho= sts) < 0) - goto cleanup; - - virStorageSourceNetworkAssignDefaultPorts(src); - break; case VIR_STORAGE_TYPE_VOLUME: if (virDomainDiskSourcePoolDefParse(node, &src->srcpool) < 0) @@ -8229,9 +8247,6 @@ virDomainDiskSourceParse(xmlNodePtr node, ret =3D 0; cleanup: - VIR_FREE(protocol); - VIR_FREE(haveTLS); - VIR_FREE(tlsCfg); ctxt->node =3D saveNode; return ret; } --=20 2.14.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list