[Libguestfs] [PATCH 2/7] lib: Handle Ceph/rbd paths properly (RHBZ#1026688).

Richard W.M. Jones rjones at redhat.com
Thu Jan 23 11:50:50 UTC 2014


The path at the protocol level is:

  pool/disk

(with no leading '/' character).  This is now what you have to pass to
guestfs_add_drive_opts.

Also Ceph can be called with no explicit servers (it uses the contents
of /etc/ceph/ceph.conf instead).  So allow zero servers to be used.
---
 generator/actions.ml           |  2 +-
 src/drives.c                   |  9 ++-------
 src/guestfs.pod                |  2 +-
 src/launch-direct.c            | 10 +++++-----
 tests/disks/test-qemu-drive.sh | 10 +++++++++-
 5 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/generator/actions.ml b/generator/actions.ml
index d331988..fa1a2c5 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -1440,7 +1440,7 @@ is a list of server(s).
  gluster        Exactly one
  iscsi          Exactly one
  nbd            Exactly one
- rbd            One or more
+ rbd            Zero or more
  sheepdog       Zero or more
  ssh            Exactly one
 
diff --git a/src/drives.c b/src/drives.c
index 4f8a7c5..9646b08 100644
--- a/src/drives.c
+++ b/src/drives.c
@@ -323,11 +323,6 @@ create_drive_rbd (guestfs_h *g,
 {
   size_t i;
 
-  if (nr_servers == 0) {
-    error (g, _("rbd: you must specify one or more servers"));
-    return NULL;
-  }
-
   for (i = 0; i < nr_servers; ++i) {
     if (servers[i].transport != drive_transport_none &&
         servers[i].transport != drive_transport_tcp) {
@@ -345,8 +340,8 @@ create_drive_rbd (guestfs_h *g,
     return NULL;
   }
 
-  if (exportname[0] != '/') {
-    error (g, _("rbd: image name must begin with a '/'"));
+  if (exportname[0] == '/') {
+    error (g, _("rbd: image name must not begin with a '/'"));
     return NULL;
   }
 
diff --git a/src/guestfs.pod b/src/guestfs.pod
index 1f0a324..292c97e 100644
--- a/src/guestfs.pod
+++ b/src/guestfs.pod
@@ -684,7 +684,7 @@ To do this, set the optional C<protocol> and C<server> parameters of
 L</guestfs_add_drive_opts> like this:
 
  char **servers = { "ceph1.example.org:3000", /* ... */, NULL };
- guestfs_add_drive_opts (g, "/pool/image",
+ guestfs_add_drive_opts (g, "pool/image",
                          GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
                          GUESTFS_ADD_DRIVE_OPTS_PROTOCOL, "rbd",
                          GUESTFS_ADD_DRIVE_OPTS_SERVER, servers,
diff --git a/src/launch-direct.c b/src/launch-direct.c
index c2a6885..6eaee63 100644
--- a/src/launch-direct.c
+++ b/src/launch-direct.c
@@ -1299,12 +1299,12 @@ guestfs___drive_source_qemu_param (guestfs_h *g, const struct drive_source *src)
   }
 
   case drive_protocol_rbd: {
-    /* build the list of all the mon hosts */
     CLEANUP_FREE char *mon_host = NULL, *username = NULL, *secret = NULL;
     const char *auth;
     size_t n = 0;
     size_t i, j;
 
+    /* build the list of all the mon hosts */
     for (i = 0; i < src->nr_servers; i++) {
       n += strlen (src->servers[i].u.hostname);
       n += 8; /* for slashes, colons, & port numbers */
@@ -1340,10 +1340,10 @@ guestfs___drive_source_qemu_param (guestfs_h *g, const struct drive_source *src)
     else
         auth = ":auth_supported=none";
 
-    /* Skip the mandatory leading '/' character on exportname. */
-    return safe_asprintf (g, "rbd:%s:mon_host=%s%s%s%s",
-                          &src->u.exportname[1],
-                          mon_host,
+    return safe_asprintf (g, "rbd:%s%s%s%s%s%s",
+                          src->u.exportname,
+                          src->nr_servers > 0 ? ":mon_host=" : "",
+                          src->nr_servers > 0 ? mon_host : "",
                           username ? username : "",
                           auth,
                           secret ? secret : "");
diff --git a/tests/disks/test-qemu-drive.sh b/tests/disks/test-qemu-drive.sh
index 3709c95..627d8e0 100755
--- a/tests/disks/test-qemu-drive.sh
+++ b/tests/disks/test-qemu-drive.sh
@@ -47,7 +47,7 @@ rm -f "$DEBUG_QEMU_FILE"
 # Ceph (RBD).
 
 $guestfish <<EOF ||:
-  add "/abc-def/ghi-jkl" "format:raw" "protocol:rbd" \
+  add "abc-def/ghi-jkl" "format:raw" "protocol:rbd" \
     "server:1.2.3.4:1234 1.2.3.5:1235 1.2.3.6:1236"
   run
 EOF
@@ -55,6 +55,14 @@ check_output
 grep -sq -- '-drive file=rbd:abc-def/ghi-jkl:mon_host=1.2.3.4\\:1234\\;1.2.3.5\\:1235\\;1.2.3.6\\:1236:auth_supported=none,' "$DEBUG_QEMU_FILE" || fail
 rm "$DEBUG_QEMU_FILE"
 
+$guestfish <<EOF ||:
+  add "abc-def/ghi-jkl" "format:raw" "protocol:rbd"
+  run
+EOF
+check_output
+grep -sq -- '-drive file=rbd:abc-def/ghi-jkl:auth_supported=none,' "$DEBUG_QEMU_FILE" || fail
+rm "$DEBUG_QEMU_FILE"
+
 # HTTP.
 
 $guestfish <<EOF ||:
-- 
1.8.4.2




More information about the Libguestfs mailing list