Skip to content

Commit

Permalink
fish: Handle Ceph/rbd URIs and convert them to paths properly (RHBZ#1…
Browse files Browse the repository at this point in the history
…026688).

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.
  • Loading branch information
rwmjones committed Jan 23, 2014
1 parent 53a3ff9 commit 992a6b2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
6 changes: 4 additions & 2 deletions fish/guestfish.pod
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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>

Expand Down
6 changes: 4 additions & 2 deletions fish/test-add-uri.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions fish/uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 992a6b2

Please sign in to comment.