diff --git a/fish/guestfish.pod b/fish/guestfish.pod index 04d9aa969f..0d81ba8abe 100644 --- a/fish/guestfish.pod +++ b/fish/guestfish.pod @@ -1198,7 +1198,9 @@ The equivalent API command would be (no export name): > 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: - > add /disk protocol:rbd server:tcp:example.com + > 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 dfeccf733f..bc06a242e8 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' 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 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 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 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 test-add-uri.out 2>&1 diff --git a/fish/uri.c b/fish/uri.c index 876d731898..0d530aace1 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);