[Libguestfs] [PATCH 1/5] rbd: send mon_host for rbd drives

Mike Kelly pioto at pioto.org
Tue May 7 14:50:08 UTC 2013


This is how the servers are passed to kvm.
---
 src/drives.c |   37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)

diff --git a/src/drives.c b/src/drives.c
index 0e62ca8..0a6d956 100644
--- a/src/drives.c
+++ b/src/drives.c
@@ -1086,12 +1086,37 @@ guestfs___drive_source_qemu_param (guestfs_h *g, const struct drive_source *src)
     return ret;
   }
 
-  case drive_protocol_rbd:
-    /* XXX Although libvirt allows multiple hosts to be specified,
-     * it's unclear how these are ever passed to Ceph.  Perhaps via
-     * environment variables?
-     */
-    return safe_asprintf (g, "rbd:%s", src->u.exportname);
+  case drive_protocol_rbd: {
+    /* build the list of all the mon hosts */
+    CLEANUP_FREE char *mon_host = NULL;
+    size_t n = 0;
+    for (int i = 0; i < src->nr_servers; i++) {
+      n += strlen (src->servers[i].u.hostname);
+      n += 8; /* for slashes, colons, & port numbers */
+    }
+    n++; /* for \0 */
+    mon_host = safe_malloc (g, sizeof (char *) * n);
+    n = 0;
+    for (int i = 0; i < src->nr_servers; i++) {
+      for (int j = 0; j < strlen (src->servers[i].u.hostname); j++) {
+        mon_host[n++] = src->servers[i].u.hostname[j];
+      }
+      mon_host[n++] = '\\';
+      mon_host[n++] = ':';
+      CLEANUP_FREE char *port = safe_asprintf (g, "%d", src->servers[i].port);
+      for (int j = 0; j < strlen (port); j++) {
+        mon_host[n++] = port[j];
+      }
+      /* join each host with \; */
+      if (i != src->nr_servers - 1) {
+        mon_host[n++] = '\\';
+        mon_host[n++] = ';';
+      }
+    }
+    mon_host[n] = '\0';
+
+    return safe_asprintf (g, "rbd:%s:mon_host=%s", src->u.exportname, mon_host);
+  }
 
   case drive_protocol_sheepdog:
     if (src->nr_servers == 0)
-- 
1.7.9.5




More information about the Libguestfs mailing list