[Pkg-libvirt-commits] [libguestfs] 125/233: lib, fish: Handle Gluster, NBD, iSCSI and Sheepdog paths properly.
Hilko Bengen
bengen at moszumanska.debian.org
Wed Feb 19 21:11:38 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to branch experimental
in repository libguestfs.
commit 01d27033bdd12974f850ff7a8e5de8f6b790379d
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Thu Jan 23 21:49:16 2014 +0000
lib, fish: Handle Gluster, NBD, iSCSI and Sheepdog paths properly.
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 53a3ff9c005fd69e773fdb18461a635c2502df1b
commit 992a6b297023711862229aabe4e23b6a1c94c1cc
---
fish/guestfish.pod | 8 ++++----
fish/test-add-uri.sh | 6 +++---
fish/uri.c | 6 +++++-
src/drives.c | 12 ++++++------
src/guestfs.pod | 6 +++---
src/launch-direct.c | 18 ++++++++++++------
tests/disks/test-qemu-drive-libvirt.sh | 27 +++++++++++++++++++++------
tests/disks/test-qemu-drive.sh | 6 +++---
8 files changed, 57 insertions(+), 32 deletions(-)
diff --git a/fish/guestfish.pod b/fish/guestfish.pod
index 0d81ba8..3c9f5b8 100644
--- a/fish/guestfish.pod
+++ b/fish/guestfish.pod
@@ -1159,7 +1159,7 @@ 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.
@@ -1167,7 +1167,7 @@ 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]>
@@ -1175,7 +1175,7 @@ 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]>
@@ -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>
diff --git a/fish/test-add-uri.sh b/fish/test-add-uri.sh
index bc06a24..1a5b067 100755
--- a/fish/test-add-uri.sh
+++ b/fish/test-add-uri.sh
@@ -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
@@ -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
diff --git a/fish/uri.c b/fish/uri.c
index 0d530aa..972eada 100644
--- a/fish/uri.c
+++ b/fish/uri.c
@@ -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 : "");
diff --git a/src/drives.c b/src/drives.c
index 9646b08..dd2b96c 100644
--- a/src/drives.c
+++ b/src/drives.c
@@ -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;
}
@@ -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;
}
@@ -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;
}
diff --git a/src/guestfs.pod b/src/guestfs.pod
index 292c97e..df6044d 100644
--- a/src/guestfs.pod
+++ b/src/guestfs.pod
@@ -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,
@@ -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,
@@ -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,
diff --git a/src/launch-direct.c b/src/launch-direct.c
index c091732..2b22ed0 100644
--- a/src/launch-direct.c
+++ b/src/launch-direct.c
@@ -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:
@@ -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;
}
@@ -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,
diff --git a/tests/disks/test-qemu-drive-libvirt.sh b/tests/disks/test-qemu-drive-libvirt.sh
index dd0ca0e..e85c249 100755
--- a/tests/disks/test-qemu-drive-libvirt.sh
+++ b/tests/disks/test-qemu-drive-libvirt.sh
@@ -62,6 +62,20 @@ 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 ||:
@@ -69,14 +83,15 @@ 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.
diff --git a/tests/disks/test-qemu-drive.sh b/tests/disks/test-qemu-drive.sh
index 627d8e0..4f10cdb 100755
--- a/tests/disks/test-qemu-drive.sh
+++ b/tests/disks/test-qemu-drive.sh
@@ -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
@@ -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
@@ -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
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git
More information about the Pkg-libvirt-commits
mailing list