conf: Pre-fill default ports when parsing network disk sources

Fill them in right away rather than having to figure out at runtime
whether they are necessary or not.

virStorageSourceNetworkDefaultPort does not need to be exported any
more.
This commit is contained in:
Peter Krempa 2017-07-10 13:41:43 +02:00
parent 5bda835466
commit 9756884d14
7 changed files with 31 additions and 15 deletions

View File

@ -7846,6 +7846,9 @@ virDomainDiskSourceParse(xmlNodePtr node,
if (virDomainStorageHostParse(node, &src->hosts, &src->nhosts) < 0)
goto cleanup;
if (virStorageSourceNetworkAssignDefaultPorts(src) < 0)
goto cleanup;
break;
case VIR_STORAGE_TYPE_VOLUME:
if (virDomainDiskSourcePoolDefParse(node, &src->srcpool) < 0)

View File

@ -2617,7 +2617,7 @@ virStorageSourceIsBlockLocal;
virStorageSourceIsEmpty;
virStorageSourceIsLocalStorage;
virStorageSourceIsRelative;
virStorageSourceNetworkDefaultPort;
virStorageSourceNetworkAssignDefaultPorts;
virStorageSourceNewFromBacking;
virStorageSourceNewFromBackingAbsolute;
virStorageSourceParseRBDColonString;

View File

@ -477,15 +477,10 @@ qemuSafeSerialParamValue(const char *value)
static int
qemuNetworkDriveGetPort(int protocol,
const char *port)
qemuNetworkDriveGetPort(const char *port)
{
int ret = 0;
if (!port &&
!(port = virStorageSourceNetworkDefaultPort(protocol)))
return -1;
if (virStrToLong_i(port, NULL, 10, &ret) < 0 || ret < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse port number '%s'"),
@ -912,8 +907,7 @@ qemuBuildNetworkDriveURI(virStorageSourcePtr src,
goto cleanup;
if (src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) {
if ((uri->port = qemuNetworkDriveGetPort(src->protocol,
src->hosts->port)) < 0)
if ((uri->port = qemuNetworkDriveGetPort(src->hosts->port)) < 0)
goto cleanup;
if (VIR_STRDUP(uri->scheme,

View File

@ -3961,7 +3961,7 @@ virStorageSourceFindByNodeName(virStorageSourcePtr top,
}
const char *
static const char *
virStorageSourceNetworkDefaultPort(virStorageNetProtocol protocol)
{
switch (protocol) {
@ -4006,3 +4006,21 @@ virStorageSourceNetworkDefaultPort(virStorageNetProtocol protocol)
return NULL;
}
int
virStorageSourceNetworkAssignDefaultPorts(virStorageSourcePtr src)
{
size_t i;
for (i = 0; i < src->nhosts; i++) {
if (src->hosts[i].transport == VIR_STORAGE_NET_HOST_TRANS_TCP &&
src->hosts[i].port == NULL) {
if (VIR_STRDUP(src->hosts[i].port,
virStorageSourceNetworkDefaultPort(src->protocol)) < 0)
return -1;
}
}
return 0;
}

View File

@ -406,7 +406,8 @@ virStorageSourceFindByNodeName(virStorageSourcePtr top,
unsigned int *index)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
const char *
virStorageSourceNetworkDefaultPort(virStorageNetProtocol protocol);
int
virStorageSourceNetworkAssignDefaultPorts(virStorageSourcePtr src)
ATTRIBUTE_NONNULL(1);
#endif /* __VIR_STORAGE_FILE_H__ */

View File

@ -17,14 +17,14 @@
<disk type='network' device='disk'>
<driver name='qemu' type='raw'/>
<source protocol='http' name='test.img'>
<host name='example.org'/>
<host name='example.org' port='80'/>
</source>
<target dev='vda' bus='virtio'/>
</disk>
<disk type='network' device='disk'>
<driver name='qemu' type='raw'/>
<source protocol='https' name='test2.img'>
<host name='example.org'/>
<host name='example.org' port='443'/>
</source>
<target dev='vdb' bus='virtio'/>
</disk>

View File

@ -34,7 +34,7 @@
<driver name='qemu' type='qcow2'/>
<source protocol='gluster' name='Volume3/Image.qcow2'>
<host name='example.org' port='6000'/>
<host name='example.org'/>
<host name='example.org' port='24007'/>
<host transport='unix' socket='/path/to/sock'/>
</source>
<target dev='vdc' bus='virtio'/>