From nobody Mon Feb 9 05:59:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) client-ip=209.132.183.39; envelope-from=libvir-list-bounces@redhat.com; helo=mx6-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com [209.132.183.39]) by mx.zohomail.com with SMTPS id 1489180502650853.7566350110285; Fri, 10 Mar 2017 13:15:02 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2ALBUMi051955; Fri, 10 Mar 2017 16:11:30 -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 v2ALAwZv023931 for ; Fri, 10 Mar 2017 16:10:58 -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 v2ALArRo011410 for ; Fri, 10 Mar 2017 16:10:57 -0500 From: John Ferlan To: libvir-list@redhat.com Date: Fri, 10 Mar 2017 16:10:40 -0500 Message-Id: <20170310211050.27784-9-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 08/18] conf: Extract SCSI 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 | 239 +++++++++++++++++++++++-------------= ---- 1 file changed, 138 insertions(+), 101 deletions(-) diff --git a/src/conf/storage_adapter_conf.c b/src/conf/storage_adapter_con= f.c index a2d4a3a..a361c34 100644 --- a/src/conf/storage_adapter_conf.c +++ b/src/conf/storage_adapter_conf.c @@ -52,12 +52,11 @@ virStorageAdapterFCHostClear(virStoragePoolSourceAdapte= rPtr adapter) void virStorageAdapterClear(virStoragePoolSourceAdapterPtr adapter) { - if (adapter->type =3D=3D VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST)= { + if (adapter->type =3D=3D VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) virStorageAdapterFCHostClear(adapter); - } else if (adapter->type =3D=3D - VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) { + + if (adapter->type =3D=3D VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOS= T) VIR_FREE(adapter->data.scsi_host.name); - } } =20 =20 @@ -95,6 +94,83 @@ virStorageAdapterFCHostParseXML(xmlNodePtr node, } =20 =20 +static int +virStorageAdapterSCSIHostParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt, + virStoragePoolSourcePtr source) +{ + source->adapter.data.scsi_host.name =3D + virXMLPropString(node, "name"); + if (virXPathNode("./parentaddr", ctxt)) { + xmlNodePtr addrnode =3D virXPathNode("./parentaddr/address", ctxt); + virPCIDeviceAddressPtr addr =3D + &source->adapter.data.scsi_host.parentaddr; + + if (!addrnode) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Missing scsi_host PCI address element")); + return -1; + } + source->adapter.data.scsi_host.has_parent =3D true; + if (virPCIDeviceAddressParseXML(addrnode, addr) < 0) + return -1; + if ((virXPathInt("string(./parentaddr/@unique_id)", + ctxt, + &source->adapter.data.scsi_host.unique_id) < 0) || + (source->adapter.data.scsi_host.unique_id < 0)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Missing or invalid scsi adapter " + "'unique_id' value")); + return -1; + } + } + + return 0; +} + + +static int +virStorageAdapterLegacyParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt, + virStoragePoolSourcePtr source) +{ + char *wwnn =3D virXMLPropString(node, "wwnn"); + char *wwpn =3D virXMLPropString(node, "wwpn"); + char *parent =3D virXMLPropString(node, "parent"); + + /* "type" was not specified in the XML, so we must verify that + * "wwnn", "wwpn", "parent", or "parentaddr" are also not in the + * XML. If any are found, then we cannot just use "name" alone". + */ + if (wwnn || wwpn || parent) { + VIR_FREE(wwnn); + VIR_FREE(wwpn); + VIR_FREE(parent); + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Use of 'wwnn', 'wwpn', and 'parent' attributes " + "requires use of the adapter 'type'")); + return -1; + } + + if (virXPathNode("./parentaddr", ctxt)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Use of 'parent' element requires use " + "of the adapter 'type'")); + return -1; + } + + /* To keep back-compat, 'type' is not required to specify + * for scsi_host adapter. + */ + if ((source->adapter.data.scsi_host.name =3D + virXMLPropString(node, "name"))) + source->adapter.type =3D + VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST; + + return 0; +} + + int virStorageAdapterParseXML(virStoragePoolSourcePtr source, xmlNodePtr node, @@ -121,68 +197,13 @@ virStorageAdapterParseXML(virStoragePoolSourcePtr sou= rce, goto cleanup; } else if (source->adapter.type =3D=3D VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) { + if (virStorageAdapterSCSIHostParseXML(node, ctxt, source) < 0) + goto cleanup; =20 - source->adapter.data.scsi_host.name =3D - virXMLPropString(node, "name"); - if (virXPathNode("./parentaddr", ctxt)) { - xmlNodePtr addrnode =3D virXPathNode("./parentaddr/address= ", - ctxt); - virPCIDeviceAddressPtr addr =3D - &source->adapter.data.scsi_host.parentaddr; - - if (!addrnode) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Missing scsi_host PCI address elemen= t")); - goto cleanup; - } - source->adapter.data.scsi_host.has_parent =3D true; - if (virPCIDeviceAddressParseXML(addrnode, addr) < 0) - goto cleanup; - if ((virXPathInt("string(./parentaddr/@unique_id)", - ctxt, - &source->adapter.data.scsi_host.unique_id= ) < 0) || - (source->adapter.data.scsi_host.unique_id < 0)) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Missing or invalid scsi adapter " - "'unique_id' value")); - goto cleanup; - } - } } } else { - char *wwnn =3D virXMLPropString(node, "wwnn"); - char *wwpn =3D virXMLPropString(node, "wwpn"); - char *parent =3D virXMLPropString(node, "parent"); - - /* "type" was not specified in the XML, so we must verify that - * "wwnn", "wwpn", "parent", or "parentaddr" are also not in the - * XML. If any are found, then we cannot just use "name" alone". - */ - - if (wwnn || wwpn || parent) { - VIR_FREE(wwnn); - VIR_FREE(wwpn); - VIR_FREE(parent); - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Use of 'wwnn', 'wwpn', and 'parent' attribut= es " - "requires use of the adapter 'type'")); + if (virStorageAdapterLegacyParseXML(node, ctxt, source) < 0) goto cleanup; - } - - if (virXPathNode("./parentaddr", ctxt)) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Use of 'parent' element requires use " - "of the adapter 'type'")); - goto cleanup; - } - - /* To keep back-compat, 'type' is not required to specify - * for scsi_host adapter. - */ - if ((source->adapter.data.scsi_host.name =3D - virXMLPropString(node, "name"))) - source->adapter.type =3D - VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST; } =20 ret =3D 0; @@ -235,6 +256,29 @@ virStorageAdapterFCHostParseValidate(virStoragePoolDef= Ptr ret) } =20 =20 +static int +virStorageAdapterSCSIHostParseValidate(virStoragePoolDefPtr ret) +{ + if (!ret->source.adapter.data.scsi_host.name && + !ret->source.adapter.data.scsi_host.has_parent) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Either 'name' or 'parent' must be specified " + "for the 'scsi_host' adapter")); + return -1; + } + + if (ret->source.adapter.data.scsi_host.name && + ret->source.adapter.data.scsi_host.has_parent) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Both 'name' and 'parent' cannot be specified " + "for the 'scsi_host' adapter")); + return -1; + } + + return 0; +} + + int virStorageAdapterParseValidate(virStoragePoolDefPtr ret) { @@ -245,26 +289,12 @@ virStorageAdapterParseValidate(virStoragePoolDefPtr r= et) } =20 if (ret->source.adapter.type =3D=3D - VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) { + 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 && - !ret->source.adapter.data.scsi_host.has_parent) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Either 'name' or 'parent' must be specified " - "for the 'scsi_host' adapter")); - return -1; - } =20 - if (ret->source.adapter.data.scsi_host.name && - ret->source.adapter.data.scsi_host.has_parent) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Both 'name' and 'parent' cannot be specified= " - "for the 'scsi_host' adapter")); - return -1; - } - } + if (ret->source.adapter.type =3D=3D + VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) + return virStorageAdapterSCSIHostParseValidate(ret); =20 return 0; } @@ -292,6 +322,30 @@ virStorageAdapterFCHostFormat(virBufferPtr buf, } =20 =20 +static void +virStorageAdapterSCSIHostFormat(virBufferPtr buf, + virStoragePoolSourcePtr src) +{ + if (src->adapter.data.scsi_host.name) { + virBufferAsprintf(buf, " name=3D'%s'/>\n", + src->adapter.data.scsi_host.name); + } else { + virPCIDeviceAddress addr; + virBufferAddLit(buf, ">\n"); + virBufferAdjustIndent(buf, 2); + virBufferAsprintf(buf, "\n", + src->adapter.data.scsi_host.unique_id); + virBufferAdjustIndent(buf, 2); + addr =3D src->adapter.data.scsi_host.parentaddr; + ignore_value(virPCIDeviceAddressFormat(buf, addr, false)); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + } +} + + void virStorageAdapterFormat(virBufferPtr buf, virStoragePoolSourcePtr src) @@ -299,26 +353,9 @@ virStorageAdapterFormat(virBufferPtr buf, virBufferAsprintf(buf, "adapter= .type)); =20 - if (src->adapter.type =3D=3D VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_H= OST) { + if (src->adapter.type =3D=3D VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_H= OST) 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) { - virBufferAsprintf(buf, " name=3D'%s'/>\n", - src->adapter.data.scsi_host.name); - } else { - virPCIDeviceAddress addr; - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - virBufferAsprintf(buf, "\n", - src->adapter.data.scsi_host.unique_id); - virBufferAdjustIndent(buf, 2); - addr =3D src->adapter.data.scsi_host.parentaddr; - ignore_value(virPCIDeviceAddressFormat(buf, addr, false)); - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - } - } + + if (src->adapter.type =3D=3D VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI= _HOST) + virStorageAdapterSCSIHostFormat(buf, src); } --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list