Skip to content

Commit

Permalink
lib, fish: Handle Gluster, NBD, iSCSI and Sheepdog paths properly.
Browse files Browse the repository at this point in the history
This fixes the handling of paths for the protocols named above, with
respect to leading '/' (or not) on the volume/export name.

See previous commits which did the same fixes for Ceph:
commit 53a3ff9
commit 992a6b2
  • Loading branch information
rwmjones committed Jan 23, 2014
1 parent 870f076 commit 01d2703
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 32 deletions.
8 changes: 4 additions & 4 deletions fish/guestfish.pod
Expand Up @@ -1159,23 +1159,23 @@ The equivalent API command would be:

><fs> add /disk.img protocol:(ftp|...) server:tcp:example.com

=head2 B<-a gluster://example.com[:port]/disk>
=head2 B<-a gluster://example.com[:port]/volname/image>

Add a disk image located on GlusterFS storage.

The server is the one running C<glusterd>, and may be C<localhost>.

The equivalent API command would be:

><fs> add /disk protocol:gluster server:tcp:example.com
><fs> add volname/image protocol:gluster server:tcp:example.com

=head2 B<-a iscsi://example.com[:port]/target-iqn-name[/lun]>

Add a disk located on an iSCSI server.

The equivalent API command would be:

><fs> add /target-iqn-name/lun protocol:iscsi server:tcp:example.com
><fs> add target-iqn-name/lun protocol:iscsi server:tcp:example.com

=head2 B<-a nbd://example.com[:port]>

Expand Down Expand Up @@ -1221,7 +1221,7 @@ when using this URI syntax.

The equivalent API command would be:

><fs> add /disk protocol:sheepdog [server:tcp:example.com]
><fs> add volume protocol:sheepdog [server:tcp:example.com]

=head2 B<-a ssh://[user@]example.com[:port]/disk.img>

Expand Down
6 changes: 3 additions & 3 deletions fish/test-add-uri.sh
Expand Up @@ -43,7 +43,7 @@ grep -sq 'add_drive "/disk.img" "protocol:ftp" "server:tcp:example.com" "usernam

# gluster
$VG ./guestfish -x -a gluster://example.com/disk </dev/null >test-add-uri.out 2>&1
grep -sq 'add_drive "/disk" "protocol:gluster" "server:tcp:example.com"' test-add-uri.out || fail
grep -sq 'add_drive "disk" "protocol:gluster" "server:tcp:example.com"' test-add-uri.out || fail

# NBD
$VG ./guestfish -x -a nbd://example.com </dev/null >test-add-uri.out 2>&1
Expand All @@ -66,10 +66,10 @@ 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
grep -sq 'add_drive "/volume/image" "protocol:sheepdog"' test-add-uri.out || fail
grep -sq 'add_drive "volume/image" "protocol:sheepdog"' test-add-uri.out || fail

$VG ./guestfish -x -a sheepdog://example.com:3000/volume/image </dev/null >test-add-uri.out 2>&1
grep -sq 'add_drive "/volume/image" "protocol:sheepdog" "server:tcp:example.com:3000"' test-add-uri.out || fail
grep -sq 'add_drive "volume/image" "protocol:sheepdog" "server:tcp:example.com:3000"' test-add-uri.out || fail

# ssh
$VG ./guestfish -x -a ssh://example.com/disk.img </dev/null >test-add-uri.out 2>&1
Expand Down
6 changes: 5 additions & 1 deletion fish/uri.c
Expand Up @@ -169,7 +169,11 @@ parse (const char *arg, char **path_ret, char **protocol_ret,
* "/pool/disk" so we have to knock off the leading '/' character.
*/
path = uri->path;
if (STREQ (uri->scheme, "rbd") && path[0] == '/')
if (path && path[0] == '/' &&
(STREQ (uri->scheme, "gluster") ||
STREQ (uri->scheme, "iscsi") ||
STREQ (uri->scheme, "rbd") ||
STREQ (uri->scheme, "sheepdog")))
path++;

*path_ret = strdup (path ? path : "");
Expand Down
12 changes: 6 additions & 6 deletions src/drives.c
Expand Up @@ -255,8 +255,8 @@ create_drive_gluster (guestfs_h *g,
return NULL;
}

if (exportname[0] != '/') {
error (g, _("gluster: pathname must begin with a '/'"));
if (exportname[0] == '/') {
error (g, _("gluster: volume/image must not begin with a '/'"));
return NULL;
}

Expand Down Expand Up @@ -389,8 +389,8 @@ create_drive_sheepdog (guestfs_h *g,
return NULL;
}

if (exportname[0] != '/') {
error (g, _("sheepdog: volume parameter must begin with a '/'"));
if (exportname[0] == '/') {
error (g, _("sheepdog: volume parameter must not begin with a '/'"));
return NULL;
}

Expand Down Expand Up @@ -483,8 +483,8 @@ create_drive_iscsi (guestfs_h *g,
return NULL;
}

if (exportname[0] != '/') {
error (g, _("iscsi: target string must begin with a '/'"));
if (exportname[0] == '/') {
error (g, _("iscsi: target string must not begin with a '/'"));
return NULL;
}

Expand Down
6 changes: 3 additions & 3 deletions src/guestfs.pod
Expand Up @@ -728,7 +728,7 @@ To do this, set the optional C<protocol> and C<server> parameters of
L</guestfs_add_drive_opts> like this:

char **servers = { "gluster.example.org:24007", NULL };
guestfs_add_drive_opts (g, "/volname/image",
guestfs_add_drive_opts (g, "volname/image",
GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
GUESTFS_ADD_DRIVE_OPTS_PROTOCOL, "gluster",
GUESTFS_ADD_DRIVE_OPTS_SERVER, servers,
Expand All @@ -751,7 +751,7 @@ To do this, set the optional C<protocol> and C<server> parameters like
this:

char **server = { "iscsi.example.org:3000", NULL };
guestfs_add_drive_opts (g, "/target-iqn-name/lun",
guestfs_add_drive_opts (g, "target-iqn-name/lun",
GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
GUESTFS_ADD_DRIVE_OPTS_PROTOCOL, "iscsi",
GUESTFS_ADD_DRIVE_OPTS_SERVER, server,
Expand Down Expand Up @@ -831,7 +831,7 @@ To do this, set the optional C<protocol> and C<server> parameters of
L</guestfs_add_drive_opts> like this:

char **servers = { /* optional servers ... */ NULL };
guestfs_add_drive_opts (g, "/volume",
guestfs_add_drive_opts (g, "volume",
GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
GUESTFS_ADD_DRIVE_OPTS_PROTOCOL, "sheepdog",
GUESTFS_ADD_DRIVE_OPTS_SERVER, servers,
Expand Down
18 changes: 12 additions & 6 deletions src/launch-direct.c
Expand Up @@ -1202,9 +1202,17 @@ make_uri (guestfs_h *g, const char *scheme, const char *user,
struct drive_server *server, const char *path)
{
xmlURI uri = { .scheme = (char *) scheme,
.path = (char *) path,
.user = (char *) user };
CLEANUP_FREE char *query = NULL;
CLEANUP_FREE char *pathslash = NULL;

/* Need to add a leading '/' to URI paths since xmlSaveUri doesn't. */
if (path[0] != '/') {
pathslash = safe_asprintf (g, "/%s", path);
uri.path = pathslash;
}
else
uri.path = (char *) path;

switch (server->transport) {
case drive_transport_none:
Expand Down Expand Up @@ -1299,8 +1307,7 @@ guestfs___drive_source_qemu_param (guestfs_h *g, const struct drive_source *src)
if (STREQ (src->u.exportname, ""))
ret = safe_strdup (g, p);
else
/* Skip the mandatory leading '/' character. */
ret = safe_asprintf (g, "%s:exportname=%s", p, &src->u.exportname[1]);
ret = safe_asprintf (g, "%s:exportname=%s", p, src->u.exportname);

return ret;
}
Expand Down Expand Up @@ -1357,13 +1364,12 @@ guestfs___drive_source_qemu_param (guestfs_h *g, const struct drive_source *src)
}

case drive_protocol_sheepdog:
/* Skip the mandatory leading '/' character on exportname. */
if (src->nr_servers == 0)
return safe_asprintf (g, "sheepdog:%s", &src->u.exportname[1]);
return safe_asprintf (g, "sheepdog:%s", src->u.exportname);
else /* XXX How to pass multiple hosts? */
return safe_asprintf (g, "sheepdog:%s:%d:%s",
src->servers[0].u.hostname, src->servers[0].port,
&src->u.exportname[1]);
src->u.exportname);

case drive_protocol_ssh:
return make_uri (g, "ssh", src->username,
Expand Down
27 changes: 21 additions & 6 deletions tests/disks/test-qemu-drive-libvirt.sh
Expand Up @@ -62,21 +62,36 @@ check_output
grep -sq -- '-drive file=rbd:abc-def/ghi-jkl:auth_supported=none,' "$DEBUG_QEMU_FILE" || fail
rm "$DEBUG_QEMU_FILE"

# Gluster.

$guestfish -d gluster run ||:
check_output
grep -sq -- '-drive file=gluster://1.2.3.4:1234/volname/image,' "$DEBUG_QEMU_FILE" || fail
rm "$DEBUG_QEMU_FILE"

# iSCSI.

$guestfish -d iscsi run ||:
check_output
grep -sq -- '-drive file=iscsi://1.2.3.4:1234/iqn.2003-01.org.linux-iscsi.fedora,' "$DEBUG_QEMU_FILE" || fail
rm "$DEBUG_QEMU_FILE"

# NBD.

$guestfish -d nbd run ||:
check_output
grep -sq -- '-drive file=nbd:1.2.3.4:1234,' "$DEBUG_QEMU_FILE" || fail
rm "$DEBUG_QEMU_FILE"

# To do:

# HTTP - curl not yet supported by libvirt
# Sheepdog.

# Gluster.
$guestfish -d sheepdog run ||:
check_output
grep -sq -- '-drive file=sheepdog:volume,' "$DEBUG_QEMU_FILE" || fail
rm "$DEBUG_QEMU_FILE"

# iSCSI.
# To do:

# Sheepdog.
# HTTP - curl not yet supported by libvirt

# SSH.
6 changes: 3 additions & 3 deletions tests/disks/test-qemu-drive.sh
Expand Up @@ -76,7 +76,7 @@ rm "$DEBUG_QEMU_FILE"
# Gluster.

$guestfish <<EOF ||:
add "/volname/image" "format:raw" "protocol:gluster" "server:www.example.com:24007"
add "volname/image" "format:raw" "protocol:gluster" "server:www.example.com:24007"
run
EOF
check_output
Expand All @@ -86,7 +86,7 @@ rm "$DEBUG_QEMU_FILE"
# iSCSI.

$guestfish <<EOF ||:
add "/target-iqn-name/lun" "format:raw" "protocol:iscsi" "server:www.example.com:3000"
add "target-iqn-name/lun" "format:raw" "protocol:iscsi" "server:www.example.com:3000"
run
EOF
check_output
Expand Down Expand Up @@ -114,7 +114,7 @@ rm "$DEBUG_QEMU_FILE"
# Sheepdog.

$guestfish <<EOF ||:
add "/volume" "format:raw" "protocol:sheepdog"
add "volume" "format:raw" "protocol:sheepdog"
run
EOF
check_output
Expand Down

0 comments on commit 01d2703

Please sign in to comment.