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.
---
src/conf/domain_conf.c | 3 +++
src/libvirt_private.syms | 2 +-
src/qemu/qemu_command.c | 10 ++--------
src/util/virstoragefile.c | 20 +++++++++++++++++++-
src/util/virstoragefile.h | 5 +++--
.../generic-disk-network-http.xml | 4 ++--
.../qemuxml2xmlout-disk-drive-network-gluster.xml | 2 +-
7 files changed, 31 insertions(+), 15 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c3149f976..bc4b10d60 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7807,6 +7807,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)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 44b5dc1e0..ae8d3483c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2614,7 +2614,7 @@ virStorageSourceIsBlockLocal;
virStorageSourceIsEmpty;
virStorageSourceIsLocalStorage;
virStorageSourceIsRelative;
-virStorageSourceNetworkDefaultPort;
+virStorageSourceNetworkAssignDefaultPorts;
virStorageSourceNewFromBacking;
virStorageSourceNewFromBackingAbsolute;
virStorageSourceParseRBDColonString;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index e5f4bdab7..285167145 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -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,
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 0c215e1b6..6c2516d34 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -4020,7 +4020,7 @@ virStorageSourceFindByNodeName(virStorageSourcePtr top,
}
-const char *
+static const char *
virStorageSourceNetworkDefaultPort(virStorageNetProtocol protocol)
{
switch (protocol) {
@@ -4065,3 +4065,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;
+}
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 877c3af4d..98992e04a 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -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__ */
diff --git a/tests/genericxml2xmlindata/generic-disk-network-http.xml
b/tests/genericxml2xmlindata/generic-disk-network-http.xml
index 51c779502..ec4520c7b 100644
--- a/tests/genericxml2xmlindata/generic-disk-network-http.xml
+++ b/tests/genericxml2xmlindata/generic-disk-network-http.xml
@@ -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>
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-network-gluster.xml
b/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-network-gluster.xml
index 66a84750a..2c7c46b01 100644
--- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-network-gluster.xml
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-network-gluster.xml
@@ -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'/>
--
2.12.2