domain_conf: Common routine to handle network storage host xml def

In preparation for hostdev support for iSCSI and a virStorageNetHostDefPtr,
split out the network disk storage parsing of the 'host' element into a
separate routine.
This commit is contained in:
John Ferlan 2014-07-10 09:11:30 -04:00
parent 265680c58e
commit c3f4942939

View File

@ -4050,6 +4050,79 @@ virDomainHostdevSubsysPCIDefParseXML(xmlNodePtr node,
return ret; return ret;
} }
static int
virDomainStorageHostParse(xmlNodePtr node,
virStorageNetHostDefPtr *hosts,
size_t *nhosts)
{
int ret = -1;
xmlNodePtr child;
char *transport = NULL;
virStorageNetHostDef host;
memset(&host, 0, sizeof(host));
child = node->children;
while (child != NULL) {
if (child->type == XML_ELEMENT_NODE &&
xmlStrEqual(child->name, BAD_CAST "host")) {
host.transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
/* transport can be tcp (default), unix or rdma. */
if ((transport = virXMLPropString(child, "transport"))) {
host.transport = virStorageNetHostTransportTypeFromString(transport);
if (host.transport < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown protocol transport type '%s'"),
transport);
goto cleanup;
}
}
host.socket = virXMLPropString(child, "socket");
if (host.transport == VIR_STORAGE_NET_HOST_TRANS_UNIX &&
host.socket == NULL) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing socket for unix transport"));
goto cleanup;
}
if (host.transport != VIR_STORAGE_NET_HOST_TRANS_UNIX &&
host.socket != NULL) {
virReportError(VIR_ERR_XML_ERROR,
_("transport '%s' does not support "
"socket attribute"),
transport);
goto cleanup;
}
VIR_FREE(transport);
if (host.transport != VIR_STORAGE_NET_HOST_TRANS_UNIX) {
if (!(host.name = virXMLPropString(child, "name"))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing name for host"));
goto cleanup;
}
host.port = virXMLPropString(child, "port");
}
if (VIR_APPEND_ELEMENT(*hosts, *nhosts, host) < 0)
goto cleanup;
}
child = child->next;
}
ret = 0;
cleanup:
virStorageNetHostDefClear(&host);
VIR_FREE(transport);
return ret;
}
static int static int
virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode, virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode,
virDomainHostdevSubsysSCSIPtr scsisrc) virDomainHostdevSubsysSCSIPtr scsisrc)
@ -5046,13 +5119,8 @@ int
virDomainDiskSourceParse(xmlNodePtr node, virDomainDiskSourceParse(xmlNodePtr node,
virStorageSourcePtr src) virStorageSourcePtr src)
{ {
char *protocol = NULL;
char *transport = NULL;
virStorageNetHostDef host;
xmlNodePtr child;
int ret = -1; int ret = -1;
char *protocol = NULL;
memset(&host, 0, sizeof(host));
switch ((virStorageType)src->type) { switch ((virStorageType)src->type) {
case VIR_STORAGE_TYPE_FILE: case VIR_STORAGE_TYPE_FILE:
@ -5105,59 +5173,8 @@ virDomainDiskSourceParse(xmlNodePtr node,
tmp[0] = '\0'; tmp[0] = '\0';
} }
child = node->children; if (virDomainStorageHostParse(node, &src->hosts, &src->nhosts) < 0)
while (child != NULL) { goto cleanup;
if (child->type == XML_ELEMENT_NODE &&
xmlStrEqual(child->name, BAD_CAST "host")) {
host.transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
/* transport can be tcp (default), unix or rdma. */
if ((transport = virXMLPropString(child, "transport"))) {
host.transport = virStorageNetHostTransportTypeFromString(transport);
if (host.transport < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown protocol transport type '%s'"),
transport);
goto cleanup;
}
}
host.socket = virXMLPropString(child, "socket");
if (host.transport == VIR_STORAGE_NET_HOST_TRANS_UNIX &&
host.socket == NULL) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing socket for unix transport"));
goto cleanup;
}
if (host.transport != VIR_STORAGE_NET_HOST_TRANS_UNIX &&
host.socket != NULL) {
virReportError(VIR_ERR_XML_ERROR,
_("transport '%s' does not support "
"socket attribute"),
transport);
goto cleanup;
}
VIR_FREE(transport);
if (host.transport != VIR_STORAGE_NET_HOST_TRANS_UNIX) {
if (!(host.name = virXMLPropString(child, "name"))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing name for host"));
goto cleanup;
}
host.port = virXMLPropString(child, "port");
}
if (VIR_APPEND_ELEMENT(src->hosts, src->nhosts, host) < 0)
goto cleanup;
}
child = child->next;
}
break; break;
case VIR_STORAGE_TYPE_VOLUME: case VIR_STORAGE_TYPE_VOLUME:
if (virDomainDiskSourcePoolDefParse(node, &src->srcpool) < 0) if (virDomainDiskSourcePoolDefParse(node, &src->srcpool) < 0)
@ -5180,9 +5197,7 @@ virDomainDiskSourceParse(xmlNodePtr node,
ret = 0; ret = 0;
cleanup: cleanup:
virStorageNetHostDefClear(&host);
VIR_FREE(protocol); VIR_FREE(protocol);
VIR_FREE(transport);
return ret; return ret;
} }