From nobody Sun Feb 8 23:03:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; envelope-from=libvir-list-bounces@redhat.com; helo=mx5-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mx.zohomail.com with SMTPS id 14891804774441002.5784952604589; Fri, 10 Mar 2017 13:14:37 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2ALBSYf045077; Fri, 10 Mar 2017 16:11:28 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2ALAv3a023926 for ; Fri, 10 Mar 2017 16:10:57 -0500 Received: from localhost.localdomain.com (ovpn-117-9.phx2.redhat.com [10.3.117.9]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2ALArRn011410 for ; Fri, 10 Mar 2017 16:10:57 -0500 From: John Ferlan To: libvir-list@redhat.com Date: Fri, 10 Mar 2017 16:10:39 -0500 Message-Id: <20170310211050.27784-8-jferlan@redhat.com> In-Reply-To: <20170310211050.27784-1-jferlan@redhat.com> References: <20170310211050.27784-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 07/18] conf: Extract FCHost adapter type processing into their own helpers 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-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than have lots of ugly inline code create helpers to try and make things more readable. While creating the helpers realign the code as necessary. Signed-off-by: John Ferlan --- src/conf/storage_adapter_conf.c | 194 +++++++++++++++++++++++-------------= ---- 1 file changed, 114 insertions(+), 80 deletions(-) diff --git a/src/conf/storage_adapter_conf.c b/src/conf/storage_adapter_con= f.c index 4f5b665..a2d4a3a 100644 --- a/src/conf/storage_adapter_conf.c +++ b/src/conf/storage_adapter_conf.c @@ -37,16 +37,23 @@ VIR_ENUM_IMPL(virStoragePoolSourceAdapter, "default", "scsi_host", "fc_host") =20 =20 +static void +virStorageAdapterFCHostClear(virStoragePoolSourceAdapterPtr adapter) +{ + VIR_FREE(adapter->data.fchost.wwnn); + VIR_FREE(adapter->data.fchost.wwpn); + VIR_FREE(adapter->data.fchost.parent); + VIR_FREE(adapter->data.fchost.parent_wwnn); + VIR_FREE(adapter->data.fchost.parent_wwpn); + VIR_FREE(adapter->data.fchost.parent_fabric_wwn); +} + + void virStorageAdapterClear(virStoragePoolSourceAdapterPtr adapter) { if (adapter->type =3D=3D VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST)= { - VIR_FREE(adapter->data.fchost.wwnn); - VIR_FREE(adapter->data.fchost.wwpn); - VIR_FREE(adapter->data.fchost.parent); - VIR_FREE(adapter->data.fchost.parent_wwnn); - VIR_FREE(adapter->data.fchost.parent_wwpn); - VIR_FREE(adapter->data.fchost.parent_fabric_wwn); + virStorageAdapterFCHostClear(adapter); } else if (adapter->type =3D=3D VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) { VIR_FREE(adapter->data.scsi_host.name); @@ -54,6 +61,40 @@ virStorageAdapterClear(virStoragePoolSourceAdapterPtr ad= apter) } =20 =20 +static int +virStorageAdapterFCHostParseXML(xmlNodePtr node, + virStoragePoolSourcePtr source) +{ + char *managed =3D NULL; + + source->adapter.data.fchost.parent =3D virXMLPropString(node, "parent"= ); + if ((managed =3D virXMLPropString(node, "managed"))) { + source->adapter.data.fchost.managed =3D + virTristateBoolTypeFromString(managed); + if (source->adapter.data.fchost.managed < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown fc_host managed setting '%s'"), + managed); + VIR_FREE(managed); + return -1; + } + } + + source->adapter.data.fchost.parent_wwnn =3D + virXMLPropString(node, "parent_wwnn"); + source->adapter.data.fchost.parent_wwpn =3D + virXMLPropString(node, "parent_wwpn"); + source->adapter.data.fchost.parent_fabric_wwn =3D + virXMLPropString(node, "parent_fabric_wwn"); + + source->adapter.data.fchost.wwpn =3D virXMLPropString(node, "wwpn"); + source->adapter.data.fchost.wwnn =3D virXMLPropString(node, "wwnn"); + + VIR_FREE(managed); + return 0; +} + + int virStorageAdapterParseXML(virStoragePoolSourcePtr source, xmlNodePtr node, @@ -62,7 +103,6 @@ virStorageAdapterParseXML(virStoragePoolSourcePtr source, int ret =3D -1; xmlNodePtr relnode =3D ctxt->node; char *adapter_type =3D NULL; - char *managed =3D NULL; =20 ctxt->node =3D node; =20 @@ -77,29 +117,8 @@ virStorageAdapterParseXML(virStoragePoolSourcePtr sourc= e, =20 if (source->adapter.type =3D=3D VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) { - source->adapter.data.fchost.parent =3D - virXMLPropString(node, "parent"); - managed =3D virXMLPropString(node, "managed"); - if (managed) { - source->adapter.data.fchost.managed =3D - virTristateBoolTypeFromString(managed); - if (source->adapter.data.fchost.managed < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown fc_host managed setting '%s'= "), - managed); - goto cleanup; - } - } - - source->adapter.data.fchost.parent_wwnn =3D - virXMLPropString(node, "parent_wwnn"); - source->adapter.data.fchost.parent_wwpn =3D - virXMLPropString(node, "parent_wwpn"); - source->adapter.data.fchost.parent_fabric_wwn =3D - virXMLPropString(node, "parent_fabric_wwn"); - - source->adapter.data.fchost.wwpn =3D virXMLPropString(node, "w= wpn"); - source->adapter.data.fchost.wwnn =3D virXMLPropString(node, "w= wnn"); + if (virStorageAdapterFCHostParseXML(node, source) < 0) + goto cleanup; } else if (source->adapter.type =3D=3D VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) { =20 @@ -171,56 +190,63 @@ virStorageAdapterParseXML(virStoragePoolSourcePtr sou= rce, cleanup: ctxt->node =3D relnode; VIR_FREE(adapter_type); - VIR_FREE(managed); return ret; } =20 =20 -int -virStorageAdapterParseValidate(virStoragePoolDefPtr ret) +static int +virStorageAdapterFCHostParseValidate(virStoragePoolDefPtr ret) { - if (!ret->source.adapter.type) { + if (!ret->source.adapter.data.fchost.wwnn || + !ret->source.adapter.data.fchost.wwpn) { virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing storage pool source adapter")); + _("'wwnn' and 'wwpn' must be specified for adapter " + "type 'fchost'")); return -1; } =20 - if (ret->source.adapter.type =3D=3D - VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) { - if (!ret->source.adapter.data.fchost.wwnn || - !ret->source.adapter.data.fchost.wwpn) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("'wwnn' and 'wwpn' must be specified for adap= ter " - "type 'fchost'")); - return -1; - } + if (!virValidateWWN(ret->source.adapter.data.fchost.wwnn) || + !virValidateWWN(ret->source.adapter.data.fchost.wwpn)) + return -1; =20 - if (!virValidateWWN(ret->source.adapter.data.fchost.wwnn) || - !virValidateWWN(ret->source.adapter.data.fchost.wwpn)) - return -1; + if ((ret->source.adapter.data.fchost.parent_wwnn && + !ret->source.adapter.data.fchost.parent_wwpn) || + (!ret->source.adapter.data.fchost.parent_wwnn && + ret->source.adapter.data.fchost.parent_wwpn)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("must supply both parent_wwnn and " + "parent_wwpn not just one or the other")); + return -1; + } =20 - if ((ret->source.adapter.data.fchost.parent_wwnn && - !ret->source.adapter.data.fchost.parent_wwpn) || - (!ret->source.adapter.data.fchost.parent_wwnn && - ret->source.adapter.data.fchost.parent_wwpn)) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("must supply both parent_wwnn and " - "parent_wwpn not just one or the other")); - return -1; - } + if (ret->source.adapter.data.fchost.parent_wwnn && + !virValidateWWN(ret->source.adapter.data.fchost.parent_wwnn)) + return -1; =20 - if (ret->source.adapter.data.fchost.parent_wwnn && - !virValidateWWN(ret->source.adapter.data.fchost.parent_wwnn)) - return -1; + if (ret->source.adapter.data.fchost.parent_wwpn && + !virValidateWWN(ret->source.adapter.data.fchost.parent_wwpn)) + return -1; =20 - if (ret->source.adapter.data.fchost.parent_wwpn && - !virValidateWWN(ret->source.adapter.data.fchost.parent_wwpn)) - return -1; + if (ret->source.adapter.data.fchost.parent_fabric_wwn && + !virValidateWWN(ret->source.adapter.data.fchost.parent_fabric_wwn)) + return -1; =20 - if (ret->source.adapter.data.fchost.parent_fabric_wwn && - !virValidateWWN(ret->source.adapter.data.fchost.parent_fabric_= wwn)) - return -1; + return 0; +} =20 + +int +virStorageAdapterParseValidate(virStoragePoolDefPtr ret) +{ + if (!ret->source.adapter.type) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing storage pool source adapter")); + return -1; + } + + if (ret->source.adapter.type =3D=3D + VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) { + return virStorageAdapterFCHostParseValidate(ret); } else if (ret->source.adapter.type =3D=3D VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) { if (!ret->source.adapter.data.scsi_host.name && @@ -244,6 +270,28 @@ virStorageAdapterParseValidate(virStoragePoolDefPtr re= t) } =20 =20 +static void +virStorageAdapterFCHostFormat(virBufferPtr buf, + virStoragePoolSourcePtr src) +{ + virBufferEscapeString(buf, " parent=3D'%s'", + src->adapter.data.fchost.parent); + if (src->adapter.data.fchost.managed) + virBufferAsprintf(buf, " managed=3D'%s'", + virTristateBoolTypeToString(src->adapter.data.fc= host.managed)); + virBufferEscapeString(buf, " parent_wwnn=3D'%s'", + src->adapter.data.fchost.parent_wwnn); + virBufferEscapeString(buf, " parent_wwpn=3D'%s'", + src->adapter.data.fchost.parent_wwpn); + virBufferEscapeString(buf, " parent_fabric_wwn=3D'%s'", + src->adapter.data.fchost.parent_fabric_wwn); + + virBufferAsprintf(buf, " wwnn=3D'%s' wwpn=3D'%s'/>\n", + src->adapter.data.fchost.wwnn, + src->adapter.data.fchost.wwpn); +} + + void virStorageAdapterFormat(virBufferPtr buf, virStoragePoolSourcePtr src) @@ -252,21 +300,7 @@ virStorageAdapterFormat(virBufferPtr buf, virStoragePoolSourceAdapterTypeToString(src->adapter= .type)); =20 if (src->adapter.type =3D=3D VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_H= OST) { - virBufferEscapeString(buf, " parent=3D'%s'", - src->adapter.data.fchost.parent); - if (src->adapter.data.fchost.managed) - virBufferAsprintf(buf, " managed=3D'%s'", - virTristateBoolTypeToString(src->adapter.dat= a.fchost.managed)); - virBufferEscapeString(buf, " parent_wwnn=3D'%s'", - src->adapter.data.fchost.parent_wwnn); - virBufferEscapeString(buf, " parent_wwpn=3D'%s'", - src->adapter.data.fchost.parent_wwpn); - virBufferEscapeString(buf, " parent_fabric_wwn=3D'%s'", - src->adapter.data.fchost.parent_fabric_wwn); - - virBufferAsprintf(buf, " wwnn=3D'%s' wwpn=3D'%s'/>\n", - src->adapter.data.fchost.wwnn, - src->adapter.data.fchost.wwpn); + virStorageAdapterFCHostFormat(buf, src); } else if (src->adapter.type =3D=3D VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) { if (src->adapter.data.scsi_host.name) { --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list