提交 cdd362e0 编写于 作者: Y Yi Li 提交者: Ján Tomko

storage: escape ipv6 for ceph mon hosts to librados

Hosts for rbd are ceph monitor daemons. These have fixed IP addresses,
so they are often referenced by IP rather than hostname for
convenience, or to avoid relying on DNS. Using IPv4 addresses as the
host name works already, but IPv6 addresses require rbd-specific
escaping because the colon is used as an option separator in the
string passed to librados.

Escape these colons, and enclose the IPv6 address in square brackets
so it is distinguished from the port, which is currently mandatory.
Signed-off-by: NYi Li <yili@winhong.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
Signed-off-by: NJán Tomko <jtomko@redhat.com>
上级 53f3c43a
...@@ -305,7 +305,10 @@ ...@@ -305,7 +305,10 @@
<oneOrMore> <oneOrMore>
<element name='host'> <element name='host'>
<attribute name='name'> <attribute name='name'>
<text/> <choice>
<ref name="dnsName"/>
<ref name="ipAddr"/>
</choice>
</attribute> </attribute>
<optional> <optional>
<attribute name='port'> <attribute name='port'>
......
...@@ -261,6 +261,7 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr, ...@@ -261,6 +261,7 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
VIR_DEBUG("Found %zu RADOS cluster monitors in the pool configuration", VIR_DEBUG("Found %zu RADOS cluster monitors in the pool configuration",
source->nhost); source->nhost);
/* combine host and port into portal */
for (i = 0; i < source->nhost; i++) { for (i = 0; i < source->nhost; i++) {
if (source->hosts[i].name != NULL && if (source->hosts[i].name != NULL &&
!source->hosts[i].port) { !source->hosts[i].port) {
...@@ -268,7 +269,15 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr, ...@@ -268,7 +269,15 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
source->hosts[i].name); source->hosts[i].name);
} else if (source->hosts[i].name != NULL && } else if (source->hosts[i].name != NULL &&
source->hosts[i].port) { source->hosts[i].port) {
virBufferAsprintf(&mon_host, "%s:%d,", const char *incFormat;
if (virSocketAddrNumericFamily(source->hosts[i].name) == AF_INET6) {
/* IPv6 address must be escaped in brackets on the cmd line */
incFormat = "[%s]:%d";
} else {
/* listenAddress is a hostname or IPv4 */
incFormat = "%s:%d";
}
virBufferAsprintf(&mon_host, incFormat,
source->hosts[i].name, source->hosts[i].name,
source->hosts[i].port); source->hosts[i].port);
} else { } else {
......
<pool type='rbd'>
<name>ceph</name>
<uuid>47c1faee-0207-e741-f5ae-d9b019b98fe2</uuid>
<source>
<name>rbd</name>
<host name='localhost' port='6789'/>
<host name='localhost' port='6790'/>
<host name='2205::192:168:205:141' port='6789'/>
<auth username='admin' type='ceph'>
<secret uuid='2ec115d7-3a88-3ceb-bc12-0ac909a6fd87'/>
</auth>
</source>
</pool>
<pool type='rbd'>
<name>ceph</name>
<uuid>47c1faee-0207-e741-f5ae-d9b019b98fe2</uuid>
<capacity unit='bytes'>0</capacity>
<allocation unit='bytes'>0</allocation>
<available unit='bytes'>0</available>
<source>
<host name='localhost' port='6789'/>
<host name='localhost' port='6790'/>
<host name='2205::192:168:205:141' port='6789'/>
<name>rbd</name>
<auth type='ceph' username='admin'>
<secret uuid='2ec115d7-3a88-3ceb-bc12-0ac909a6fd87'/>
</auth>
</source>
</pool>
...@@ -95,6 +95,7 @@ mymain(void) ...@@ -95,6 +95,7 @@ mymain(void)
DO_TEST("pool-zfs-sourcedev"); DO_TEST("pool-zfs-sourcedev");
DO_TEST("pool-rbd"); DO_TEST("pool-rbd");
#ifdef WITH_STORAGE_RBD #ifdef WITH_STORAGE_RBD
DO_TEST("pool-rbd-ipv6");
DO_TEST("pool-rbd-refresh-volume-allocation"); DO_TEST("pool-rbd-refresh-volume-allocation");
DO_TEST("pool-rbd-ns-configopts"); DO_TEST("pool-rbd-ns-configopts");
#endif #endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册