提交 698d5df4 编写于 作者: J John Ferlan

conf: Extract FCHost adapter type processing into their own helpers

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: NJohn Ferlan <jferlan@redhat.com>
上级 1e21c040
......@@ -37,16 +37,23 @@ VIR_ENUM_IMPL(virStoragePoolSourceAdapter,
"default", "scsi_host", "fc_host")
void
virStorageAdapterClear(virStoragePoolSourceAdapterPtr adapter)
static void
virStorageAdapterClearFCHost(virStoragePoolSourceAdapterPtr adapter)
{
if (adapter->type == 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);
}
void
virStorageAdapterClear(virStoragePoolSourceAdapterPtr adapter)
{
if (adapter->type == VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) {
virStorageAdapterClearFCHost(adapter);
} else if (adapter->type ==
VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) {
VIR_FREE(adapter->data.scsi_host.name);
......@@ -54,6 +61,40 @@ virStorageAdapterClear(virStoragePoolSourceAdapterPtr adapter)
}
static int
virStorageAdapterParseXMLFCHost(xmlNodePtr node,
virStoragePoolSourcePtr source)
{
char *managed = NULL;
source->adapter.data.fchost.parent = virXMLPropString(node, "parent");
if ((managed = virXMLPropString(node, "managed"))) {
source->adapter.data.fchost.managed =
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 =
virXMLPropString(node, "parent_wwnn");
source->adapter.data.fchost.parent_wwpn =
virXMLPropString(node, "parent_wwpn");
source->adapter.data.fchost.parent_fabric_wwn =
virXMLPropString(node, "parent_fabric_wwn");
source->adapter.data.fchost.wwpn = virXMLPropString(node, "wwpn");
source->adapter.data.fchost.wwnn = virXMLPropString(node, "wwnn");
VIR_FREE(managed);
return 0;
}
int
virStorageAdapterParseXML(virStoragePoolSourcePtr source,
xmlNodePtr node,
......@@ -62,7 +103,6 @@ virStorageAdapterParseXML(virStoragePoolSourcePtr source,
int ret = -1;
xmlNodePtr relnode = ctxt->node;
char *adapter_type = NULL;
char *managed = NULL;
ctxt->node = node;
......@@ -77,29 +117,8 @@ virStorageAdapterParseXML(virStoragePoolSourcePtr source,
if (source->adapter.type ==
VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) {
source->adapter.data.fchost.parent =
virXMLPropString(node, "parent");
managed = virXMLPropString(node, "managed");
if (managed) {
source->adapter.data.fchost.managed =
virTristateBoolTypeFromString(managed);
if (source->adapter.data.fchost.managed < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown fc_host managed setting '%s'"),
managed);
if (virStorageAdapterParseXMLFCHost(node, source) < 0)
goto cleanup;
}
}
source->adapter.data.fchost.parent_wwnn =
virXMLPropString(node, "parent_wwnn");
source->adapter.data.fchost.parent_wwpn =
virXMLPropString(node, "parent_wwpn");
source->adapter.data.fchost.parent_fabric_wwn =
virXMLPropString(node, "parent_fabric_wwn");
source->adapter.data.fchost.wwpn = virXMLPropString(node, "wwpn");
source->adapter.data.fchost.wwnn = virXMLPropString(node, "wwnn");
} else if (source->adapter.type ==
VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) {
......@@ -171,22 +190,13 @@ virStorageAdapterParseXML(virStoragePoolSourcePtr source,
cleanup:
ctxt->node = relnode;
VIR_FREE(adapter_type);
VIR_FREE(managed);
return ret;
}
int
virStorageAdapterValidate(virStoragePoolDefPtr ret)
static int
virStorageAdapterValidateFCHost(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 ==
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",
......@@ -229,6 +239,22 @@ virStorageAdapterValidate(virStoragePoolDefPtr ret)
!virValidateWWN(ret->source.adapter.data.fchost.parent_fabric_wwn))
return -1;
return 0;
}
int
virStorageAdapterValidate(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 ==
VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) {
return virStorageAdapterValidateFCHost(ret);
} else if (ret->source.adapter.type ==
VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) {
if (!ret->source.adapter.data.scsi_host.name &&
......@@ -252,14 +278,10 @@ virStorageAdapterValidate(virStoragePoolDefPtr ret)
}
void
virStorageAdapterFormat(virBufferPtr buf,
static void
virStorageAdapterFormatFCHost(virBufferPtr buf,
virStoragePoolSourcePtr src)
{
virBufferAsprintf(buf, "<adapter type='%s'",
virStoragePoolSourceAdapterTypeToString(src->adapter.type));
if (src->adapter.type == VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) {
virBufferEscapeString(buf, " parent='%s'",
src->adapter.data.fchost.parent);
if (src->adapter.data.fchost.managed)
......@@ -275,6 +297,18 @@ virStorageAdapterFormat(virBufferPtr buf,
virBufferAsprintf(buf, " wwnn='%s' wwpn='%s'/>\n",
src->adapter.data.fchost.wwnn,
src->adapter.data.fchost.wwpn);
}
void
virStorageAdapterFormat(virBufferPtr buf,
virStoragePoolSourcePtr src)
{
virBufferAsprintf(buf, "<adapter type='%s'",
virStoragePoolSourceAdapterTypeToString(src->adapter.type));
if (src->adapter.type == VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) {
virStorageAdapterFormatFCHost(buf, src);
} else if (src->adapter.type ==
VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) {
if (src->adapter.data.scsi_host.name) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部