提交 b6e5a0a2 编写于 作者: D Daniel P. Berrange

Fix parsing of port attribute in storage XML configuration

The XML docs describe a 'port' attribute for the
storage source <host> element, but the parser never
handled it.

* docs/schemas/storagepool.rng: Define port attribute
* src/conf/storage_conf.c: Add missing parsing/formatting
  of host port number
* src/conf/storage_conf.h: Remove bogus/unused 'protocol' field
上级 375ba36e
<?xml version="1.0"?>
<!-- A Relax NG schema for the libvirt storage pool XML format --> <!-- A Relax NG schema for the libvirt storage pool XML format -->
<grammar xmlns="http://relaxng.org/ns/structure/1.0" <grammar xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
...@@ -186,6 +187,11 @@ ...@@ -186,6 +187,11 @@
<attribute name='name'> <attribute name='name'>
<text/> <text/>
</attribute> </attribute>
<optional>
<attribute name='port'>
<ref name="PortNumber"/>
</attribute>
</optional>
<empty/> <empty/>
</element> </element>
</define> </define>
...@@ -471,5 +477,10 @@ ...@@ -471,5 +477,10 @@
</data> </data>
</define> </define>
<define name="PortNumber">
<data type="short">
<param name="minInclusive">-1</param>
</data>
</define>
</grammar> </grammar>
...@@ -396,6 +396,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, ...@@ -396,6 +396,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
char *authType = NULL; char *authType = NULL;
int nsource, i; int nsource, i;
virStoragePoolOptionsPtr options; virStoragePoolOptionsPtr options;
char *port;
relnode = ctxt->node; relnode = ctxt->node;
ctxt->node = node; ctxt->node = node;
...@@ -423,6 +424,17 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, ...@@ -423,6 +424,17 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
} }
source->host.name = virXPathString("string(./host/@name)", ctxt); source->host.name = virXPathString("string(./host/@name)", ctxt);
port = virXPathString("string(./host/@port)", ctxt);
if (port) {
if (virStrToLong_i(port, NULL, 10, &source->host.port) < 0) {
virStorageReportError(VIR_ERR_XML_ERROR,
_("Invalid port number: %s"),
port);
goto cleanup;
}
}
source->initiator.iqn = virXPathString("string(./initiator/iqn/@name)", ctxt); source->initiator.iqn = virXPathString("string(./initiator/iqn/@name)", ctxt);
nsource = virXPathNodeSet("./device", ctxt, &nodeset); nsource = virXPathNodeSet("./device", ctxt, &nodeset);
...@@ -475,6 +487,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, ...@@ -475,6 +487,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
cleanup: cleanup:
ctxt->node = relnode; ctxt->node = relnode;
VIR_FREE(port);
VIR_FREE(authType); VIR_FREE(authType);
VIR_FREE(nodeset); VIR_FREE(nodeset);
return ret; return ret;
...@@ -790,8 +803,12 @@ virStoragePoolSourceFormat(virBufferPtr buf, ...@@ -790,8 +803,12 @@ virStoragePoolSourceFormat(virBufferPtr buf,
virBufferAddLit(buf," <source>\n"); virBufferAddLit(buf," <source>\n");
if ((options->flags & VIR_STORAGE_POOL_SOURCE_HOST) && if ((options->flags & VIR_STORAGE_POOL_SOURCE_HOST) &&
src->host.name) src->host.name) {
virBufferVSprintf(buf," <host name='%s'/>\n", src->host.name); virBufferVSprintf(buf, " <host name='%s'", src->host.name);
if (src->host.port)
virBufferVSprintf(buf, " port='%d'", src->host.port);
virBufferAddLit(buf, "/>\n");
}
if ((options->flags & VIR_STORAGE_POOL_SOURCE_DEVICE) && if ((options->flags & VIR_STORAGE_POOL_SOURCE_DEVICE) &&
src->ndevice) { src->ndevice) {
......
...@@ -155,7 +155,6 @@ typedef virStoragePoolSourceHost *virStoragePoolSourceHostPtr; ...@@ -155,7 +155,6 @@ typedef virStoragePoolSourceHost *virStoragePoolSourceHostPtr;
struct _virStoragePoolSourceHost { struct _virStoragePoolSourceHost {
char *name; char *name;
int port; int port;
int protocol;
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册