mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
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:
parent
5bda835466
commit
9756884d14
@ -7846,6 +7846,9 @@ virDomainDiskSourceParse(xmlNodePtr node,
|
|||||||
|
|
||||||
if (virDomainStorageHostParse(node, &src->hosts, &src->nhosts) < 0)
|
if (virDomainStorageHostParse(node, &src->hosts, &src->nhosts) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (virStorageSourceNetworkAssignDefaultPorts(src) < 0)
|
||||||
|
goto cleanup;
|
||||||
break;
|
break;
|
||||||
case VIR_STORAGE_TYPE_VOLUME:
|
case VIR_STORAGE_TYPE_VOLUME:
|
||||||
if (virDomainDiskSourcePoolDefParse(node, &src->srcpool) < 0)
|
if (virDomainDiskSourcePoolDefParse(node, &src->srcpool) < 0)
|
||||||
|
@ -2617,7 +2617,7 @@ virStorageSourceIsBlockLocal;
|
|||||||
virStorageSourceIsEmpty;
|
virStorageSourceIsEmpty;
|
||||||
virStorageSourceIsLocalStorage;
|
virStorageSourceIsLocalStorage;
|
||||||
virStorageSourceIsRelative;
|
virStorageSourceIsRelative;
|
||||||
virStorageSourceNetworkDefaultPort;
|
virStorageSourceNetworkAssignDefaultPorts;
|
||||||
virStorageSourceNewFromBacking;
|
virStorageSourceNewFromBacking;
|
||||||
virStorageSourceNewFromBackingAbsolute;
|
virStorageSourceNewFromBackingAbsolute;
|
||||||
virStorageSourceParseRBDColonString;
|
virStorageSourceParseRBDColonString;
|
||||||
|
@ -477,15 +477,10 @@ qemuSafeSerialParamValue(const char *value)
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuNetworkDriveGetPort(int protocol,
|
qemuNetworkDriveGetPort(const char *port)
|
||||||
const char *port)
|
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (!port &&
|
|
||||||
!(port = virStorageSourceNetworkDefaultPort(protocol)))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (virStrToLong_i(port, NULL, 10, &ret) < 0 || ret < 0) {
|
if (virStrToLong_i(port, NULL, 10, &ret) < 0 || ret < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("failed to parse port number '%s'"),
|
_("failed to parse port number '%s'"),
|
||||||
@ -912,8 +907,7 @@ qemuBuildNetworkDriveURI(virStorageSourcePtr src,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) {
|
if (src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) {
|
||||||
if ((uri->port = qemuNetworkDriveGetPort(src->protocol,
|
if ((uri->port = qemuNetworkDriveGetPort(src->hosts->port)) < 0)
|
||||||
src->hosts->port)) < 0)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (VIR_STRDUP(uri->scheme,
|
if (VIR_STRDUP(uri->scheme,
|
||||||
|
@ -3961,7 +3961,7 @@ virStorageSourceFindByNodeName(virStorageSourcePtr top,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char *
|
static const char *
|
||||||
virStorageSourceNetworkDefaultPort(virStorageNetProtocol protocol)
|
virStorageSourceNetworkDefaultPort(virStorageNetProtocol protocol)
|
||||||
{
|
{
|
||||||
switch (protocol) {
|
switch (protocol) {
|
||||||
@ -4006,3 +4006,21 @@ virStorageSourceNetworkDefaultPort(virStorageNetProtocol protocol)
|
|||||||
|
|
||||||
return NULL;
|
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;
|
||||||
|
}
|
||||||
|
@ -406,7 +406,8 @@ virStorageSourceFindByNodeName(virStorageSourcePtr top,
|
|||||||
unsigned int *index)
|
unsigned int *index)
|
||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
||||||
|
|
||||||
const char *
|
int
|
||||||
virStorageSourceNetworkDefaultPort(virStorageNetProtocol protocol);
|
virStorageSourceNetworkAssignDefaultPorts(virStorageSourcePtr src)
|
||||||
|
ATTRIBUTE_NONNULL(1);
|
||||||
|
|
||||||
#endif /* __VIR_STORAGE_FILE_H__ */
|
#endif /* __VIR_STORAGE_FILE_H__ */
|
||||||
|
@ -17,14 +17,14 @@
|
|||||||
<disk type='network' device='disk'>
|
<disk type='network' device='disk'>
|
||||||
<driver name='qemu' type='raw'/>
|
<driver name='qemu' type='raw'/>
|
||||||
<source protocol='http' name='test.img'>
|
<source protocol='http' name='test.img'>
|
||||||
<host name='example.org'/>
|
<host name='example.org' port='80'/>
|
||||||
</source>
|
</source>
|
||||||
<target dev='vda' bus='virtio'/>
|
<target dev='vda' bus='virtio'/>
|
||||||
</disk>
|
</disk>
|
||||||
<disk type='network' device='disk'>
|
<disk type='network' device='disk'>
|
||||||
<driver name='qemu' type='raw'/>
|
<driver name='qemu' type='raw'/>
|
||||||
<source protocol='https' name='test2.img'>
|
<source protocol='https' name='test2.img'>
|
||||||
<host name='example.org'/>
|
<host name='example.org' port='443'/>
|
||||||
</source>
|
</source>
|
||||||
<target dev='vdb' bus='virtio'/>
|
<target dev='vdb' bus='virtio'/>
|
||||||
</disk>
|
</disk>
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
<driver name='qemu' type='qcow2'/>
|
<driver name='qemu' type='qcow2'/>
|
||||||
<source protocol='gluster' name='Volume3/Image.qcow2'>
|
<source protocol='gluster' name='Volume3/Image.qcow2'>
|
||||||
<host name='example.org' port='6000'/>
|
<host name='example.org' port='6000'/>
|
||||||
<host name='example.org'/>
|
<host name='example.org' port='24007'/>
|
||||||
<host transport='unix' socket='/path/to/sock'/>
|
<host transport='unix' socket='/path/to/sock'/>
|
||||||
</source>
|
</source>
|
||||||
<target dev='vdc' bus='virtio'/>
|
<target dev='vdc' bus='virtio'/>
|
||||||
|
Loading…
Reference in New Issue
Block a user