[Libguestfs] [PATCH 3/7] fish: Handle Ceph/rbd URIs and convert them to paths properly (RHBZ#1026688).

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


The path at the API level (for guestfs_add_drive_opts) is:

  pool/disk

The URI syntax is either rbd:///pool/disk or rbd://server:port/pool/disk.
Because of the way URI parsing works we may need to remove a leading
'/' character before passing the path down to the API.
---
 fish/guestfish.pod   |  6 ++++--
 fish/test-add-uri.sh |  6 ++++--
 fish/uri.c           | 16 +++++++++++++---
 3 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/fish/guestfish.pod b/fish/guestfish.pod
index 04d9aa9..0d81ba8 100644
--- a/fish/guestfish.pod
+++ b/fish/guestfish.pod
@@ -1198,7 +1198,9 @@ The equivalent API command would be (no export name):
 
  ><fs> add "" protocol:nbd server:[tcp:example.com|unix:/socket]
 
-=head2 B<-a rbd://example.com[:port]/disk>
+=head2 B<-a rbd:///pool/disk>
+
+=head2 B<-a rbd://example.com[:port]/pool/disk>
 
 Add a disk image located on a Ceph (RBD/librbd) storage volume.
 
@@ -1207,7 +1209,7 @@ server can be specified when using this URI syntax.
 
 The equivalent API command would be:
 
- ><fs> add /disk protocol:rbd server:tcp:example.com
+ ><fs> add pool/disk protocol:rbd server:tcp:example.com:port
 
 =head2 B<-a sheepdog://[example.com[:port]]/volume/image>
 
diff --git a/fish/test-add-uri.sh b/fish/test-add-uri.sh
index dfeccf7..3d414b9 100755
--- a/fish/test-add-uri.sh
+++ b/fish/test-add-uri.sh
@@ -59,8 +59,10 @@ $VG ./guestfish -x -a 'nbd:///export?socket=/sk' </dev/null >test-add-uri.out 2>
 grep -sq 'add_drive "/export" "protocol:nbd" "server:unix:/sk"' test-add-uri.out || fail
 
 # rbd
-$VG ./guestfish -x -a rbd://example.com:3000/disk </dev/null >test-add-uri.out 2>&1
-grep -sq 'add_drive "/disk" "protocol:rbd" "server:tcp:example.com:3000"' test-add-uri.out || fail
+$VG ./guestfish -x -a rbd://example.com:6789/pool/disk </dev/null >test-add-uri.out 2>&1
+grep -sq 'add_drive "pool/disk" "protocol:rbd" "server:tcp:example.com:6789"' test-add-uri.out || fail
+$VG ./guestfish -x -a rbd:///pool/disk </dev/null >test-add-uri.out 2>&1
+grep -sq 'add_drive "pool/disk" "protocol:rbd" test-add-uri.out || fail
 
 # sheepdog
 $VG ./guestfish -x -a sheepdog:///volume/image </dev/null >test-add-uri.out 2>&1
diff --git a/fish/uri.c b/fish/uri.c
index 876d731..0d530aa 100644
--- a/fish/uri.c
+++ b/fish/uri.c
@@ -105,6 +105,7 @@ parse (const char *arg, char **path_ret, char **protocol_ret,
 {
   CLEANUP_XMLFREEURI xmlURIPtr uri = NULL;
   CLEANUP_FREE char *socket = NULL;
+  char *path;
 
   uri = xmlParseURI (arg);
   if (!uri) {
@@ -162,9 +163,18 @@ parse (const char *arg, char **path_ret, char **protocol_ret,
   }
   else *username_ret = NULL;
 
-  *path_ret = strdup (uri->path ? uri->path : "");
-  if (!*path_ret) {
-    perror ("path");
+  /* We may have to adjust the path depending on the protocol.  For
+   * example ceph/rbd URIs look like rbd:///pool/disk, but the
+   * exportname expected will be "pool/disk".  Here, uri->path will be
+   * "/pool/disk" so we have to knock off the leading '/' character.
+   */
+  path = uri->path;
+  if (STREQ (uri->scheme, "rbd") && path[0] == '/')
+    path++;
+
+  *path_ret = strdup (path ? path : "");
+  if (*path_ret == NULL) {
+    perror ("strdup: path");
     free (*protocol_ret);
     guestfs___free_string_list (*server_ret);
     free (*username_ret);
-- 
1.8.4.2




More information about the Libguestfs mailing list