[libvirt] [PATCH] storage: escape ipv6 for ceph mon hosts to librados

winhong-yili posted 1 patch 4 years, 11 months ago
Failed in applying to current master (apply log)
docs/schemas/storagepool.rng | 5 ++++-
src/storage/storage_backend_rbd.c | 13 ++++++++++---
tests/storagepoolxml2xmlin/pool-rbd-ipv6.xml | 13 +++++++++++++
tests/storagepoolxml2xmlout/pool-rbd-ipv6.xml | 16 ++++++++++++++++
tests/storagepoolxml2xmltest.c | 1 +
5 files changed, 44 insertions(+), 4 deletions(-)
create mode 100644 tests/storagepoolxml2xmlin/pool-rbd-ipv6.xml
create mode 100644 tests/storagepoolxml2xmlout/pool-rbd-ipv6.xml
[libvirt] [PATCH] storage: escape ipv6 for ceph mon hosts to librados
Posted by winhong-yili 4 years, 11 months ago
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: Yi Li <yili@winhong.com> 
--- 
docs/schemas/storagepool.rng | 5 ++++- 
src/storage/storage_backend_rbd.c | 13 ++++++++++--- 
tests/storagepoolxml2xmlin/pool-rbd-ipv6.xml | 13 +++++++++++++ 
tests/storagepoolxml2xmlout/pool-rbd-ipv6.xml | 16 ++++++++++++++++ 
tests/storagepoolxml2xmltest.c | 1 + 
5 files changed, 44 insertions(+), 4 deletions(-) 
create mode 100644 tests/storagepoolxml2xmlin/pool-rbd-ipv6.xml 
create mode 100644 tests/storagepoolxml2xmlout/pool-rbd-ipv6.xml 

diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng 
index 3ca8e79..976a02b 100644 
--- a/docs/schemas/storagepool.rng 
+++ b/docs/schemas/storagepool.rng 
@@ -305,7 +305,10 @@ 
<oneOrMore> 
<element name='host'> 
<attribute name='name'> 
- <text/> 
+ <choice> 
+ <ref name="dnsName"/> 
+ <ref name="ipAddr"/> 
+ </choice> 
</attribute> 
<optional> 
<attribute name='port'> 
diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c 
index f8c968e..3056563 100644 
--- a/src/storage/storage_backend_rbd.c 
+++ b/src/storage/storage_backend_rbd.c 
@@ -268,9 +268,16 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr, 
source->hosts[i].name); 
} else if (source->hosts[i].name != NULL && 
source->hosts[i].port) { 
- virBufferAsprintf(&mon_host, "%s:%d,", 
- source->hosts[i].name, 
- source->hosts[i].port); 
+ /* assume host containing : is ipv6 */ 
+ if (strchr(source->hosts[i].name, ':')) { 
+ virBufferAsprintf(&mon_host, "[%s]:%d,", 
+ source->hosts[i].name, 
+ source->hosts[i].port); 
+ } else { 
+ virBufferAsprintf(&mon_host, "%s:%d,", 
+ source->hosts[i].name, 
+ source->hosts[i].port); 
+ } 
} else { 
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", 
_("received malformed monitor, check the XML definition")); 
diff --git a/tests/storagepoolxml2xmlin/pool-rbd-ipv6.xml b/tests/storagepoolxml2xmlin/pool-rbd-ipv6.xml 
new file mode 100644 
index 0000000..0744b33 
--- /dev/null 
+++ b/tests/storagepoolxml2xmlin/pool-rbd-ipv6.xml 
@@ -0,0 +1,13 @@ 
+<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> 
diff --git a/tests/storagepoolxml2xmlout/pool-rbd-ipv6.xml b/tests/storagepoolxml2xmlout/pool-rbd-ipv6.xml 
new file mode 100644 
index 0000000..cc2a379 
--- /dev/null 
+++ b/tests/storagepoolxml2xmlout/pool-rbd-ipv6.xml 
@@ -0,0 +1,16 @@ 
+<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> 
diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c 
index 2ae514f..b6f4cb4 100644 
--- a/tests/storagepoolxml2xmltest.c 
+++ b/tests/storagepoolxml2xmltest.c 
@@ -95,6 +95,7 @@ mymain(void) 
DO_TEST("pool-zfs-sourcedev"); 
DO_TEST("pool-rbd"); 
#ifdef WITH_STORAGE_RBD 
+ DO_TEST("pool-rbd-ipv6"); 
DO_TEST("pool-rbd-refresh-volume-allocation"); 
DO_TEST("pool-rbd-ns-configopts"); 
#endif 
-- 
2.7.5 



 
From 91274da7ce184055f0c5c5581e5862cfb578fe6b Mon Sep 17 00:00:00 2001
From: Yi Li <yili@winhong.com>
Date: Thu, 25 Apr 2019 13:06:28 +0800
Subject: [PATCH] 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: Yi Li <yili@winhong.com>
---
 docs/schemas/storagepool.rng                  |  5 ++++-
 src/storage/storage_backend_rbd.c             | 13 ++++++++++---
 tests/storagepoolxml2xmlin/pool-rbd-ipv6.xml  | 13 +++++++++++++
 tests/storagepoolxml2xmlout/pool-rbd-ipv6.xml | 16 ++++++++++++++++
 tests/storagepoolxml2xmltest.c                |  1 +
 5 files changed, 44 insertions(+), 4 deletions(-)
 create mode 100644 tests/storagepoolxml2xmlin/pool-rbd-ipv6.xml
 create mode 100644 tests/storagepoolxml2xmlout/pool-rbd-ipv6.xml

diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng
index 3ca8e79..976a02b 100644
--- a/docs/schemas/storagepool.rng
+++ b/docs/schemas/storagepool.rng
@@ -305,7 +305,10 @@
     <oneOrMore>
       <element name='host'>
         <attribute name='name'>
-          <text/>
+          <choice>
+            <ref name="dnsName"/>
+            <ref name="ipAddr"/>
+          </choice>
         </attribute>
         <optional>
           <attribute name='port'>
diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index f8c968e..3056563 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -268,9 +268,16 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
                               source->hosts[i].name);
         } else if (source->hosts[i].name != NULL &&
             source->hosts[i].port) {
-            virBufferAsprintf(&mon_host, "%s:%d,",
-                              source->hosts[i].name,
-                              source->hosts[i].port);
+            /* assume host containing : is ipv6 */
+            if (strchr(source->hosts[i].name, ':')) {
+                virBufferAsprintf(&mon_host, "[%s]:%d,",
+                                  source->hosts[i].name,
+                                  source->hosts[i].port);
+            } else {
+                virBufferAsprintf(&mon_host, "%s:%d,",
+                                  source->hosts[i].name,
+                                  source->hosts[i].port);
+            }
         } else {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("received malformed monitor, check the XML definition"));
diff --git a/tests/storagepoolxml2xmlin/pool-rbd-ipv6.xml b/tests/storagepoolxml2xmlin/pool-rbd-ipv6.xml
new file mode 100644
index 0000000..0744b33
--- /dev/null
+++ b/tests/storagepoolxml2xmlin/pool-rbd-ipv6.xml
@@ -0,0 +1,13 @@
+<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>
diff --git a/tests/storagepoolxml2xmlout/pool-rbd-ipv6.xml b/tests/storagepoolxml2xmlout/pool-rbd-ipv6.xml
new file mode 100644
index 0000000..cc2a379
--- /dev/null
+++ b/tests/storagepoolxml2xmlout/pool-rbd-ipv6.xml
@@ -0,0 +1,16 @@
+<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>
diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c
index 2ae514f..b6f4cb4 100644
--- a/tests/storagepoolxml2xmltest.c
+++ b/tests/storagepoolxml2xmltest.c
@@ -95,6 +95,7 @@ mymain(void)
     DO_TEST("pool-zfs-sourcedev");
     DO_TEST("pool-rbd");
 #ifdef WITH_STORAGE_RBD
+    DO_TEST("pool-rbd-ipv6");
     DO_TEST("pool-rbd-refresh-volume-allocation");
     DO_TEST("pool-rbd-ns-configopts");
 #endif
-- 
2.7.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list