From 53a3ff9c005fd69e773fdb18461a635c2502df1b Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 23 Jan 2014 08:28:09 +0000 Subject: [PATCH] lib: Handle Ceph/rbd paths properly (RHBZ#1026688). The path at the protocol level is: pool/disk (with no leading '/' character). This is now what you have to pass to guestfs_add_drive_opts. Also Ceph can be called with no explicit servers (it uses the contents of /etc/ceph/ceph.conf instead). So allow zero servers to be used. --- generator/actions.ml | 2 +- src/drives.c | 9 ++------- src/guestfs.pod | 2 +- src/launch-direct.c | 10 +++++----- tests/disks/test-qemu-drive.sh | 10 +++++++++- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/generator/actions.ml b/generator/actions.ml index d331988ce..fa1a2c545 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -1440,7 +1440,7 @@ is a list of server(s). gluster Exactly one iscsi Exactly one nbd Exactly one - rbd One or more + rbd Zero or more sheepdog Zero or more ssh Exactly one diff --git a/src/drives.c b/src/drives.c index 4f8a7c57b..9646b08b4 100644 --- a/src/drives.c +++ b/src/drives.c @@ -323,11 +323,6 @@ create_drive_rbd (guestfs_h *g, { size_t i; - if (nr_servers == 0) { - error (g, _("rbd: you must specify one or more servers")); - return NULL; - } - for (i = 0; i < nr_servers; ++i) { if (servers[i].transport != drive_transport_none && servers[i].transport != drive_transport_tcp) { @@ -345,8 +340,8 @@ create_drive_rbd (guestfs_h *g, return NULL; } - if (exportname[0] != '/') { - error (g, _("rbd: image name must begin with a '/'")); + if (exportname[0] == '/') { + error (g, _("rbd: image name must not begin with a '/'")); return NULL; } diff --git a/src/guestfs.pod b/src/guestfs.pod index 1f0a3244b..292c97e03 100644 --- a/src/guestfs.pod +++ b/src/guestfs.pod @@ -684,7 +684,7 @@ To do this, set the optional C and C parameters of L like this: char **servers = { "ceph1.example.org:3000", /* ... */, NULL }; - guestfs_add_drive_opts (g, "/pool/image", + guestfs_add_drive_opts (g, "pool/image", GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw", GUESTFS_ADD_DRIVE_OPTS_PROTOCOL, "rbd", GUESTFS_ADD_DRIVE_OPTS_SERVER, servers, diff --git a/src/launch-direct.c b/src/launch-direct.c index c2a68856b..6eaee63a5 100644 --- a/src/launch-direct.c +++ b/src/launch-direct.c @@ -1299,12 +1299,12 @@ guestfs___drive_source_qemu_param (guestfs_h *g, const struct drive_source *src) } case drive_protocol_rbd: { - /* build the list of all the mon hosts */ CLEANUP_FREE char *mon_host = NULL, *username = NULL, *secret = NULL; const char *auth; size_t n = 0; size_t i, j; + /* build the list of all the mon hosts */ for (i = 0; i < src->nr_servers; i++) { n += strlen (src->servers[i].u.hostname); n += 8; /* for slashes, colons, & port numbers */ @@ -1340,10 +1340,10 @@ guestfs___drive_source_qemu_param (guestfs_h *g, const struct drive_source *src) else auth = ":auth_supported=none"; - /* Skip the mandatory leading '/' character on exportname. */ - return safe_asprintf (g, "rbd:%s:mon_host=%s%s%s%s", - &src->u.exportname[1], - mon_host, + return safe_asprintf (g, "rbd:%s%s%s%s%s%s", + src->u.exportname, + src->nr_servers > 0 ? ":mon_host=" : "", + src->nr_servers > 0 ? mon_host : "", username ? username : "", auth, secret ? secret : ""); diff --git a/tests/disks/test-qemu-drive.sh b/tests/disks/test-qemu-drive.sh index 3709c952d..627d8e039 100755 --- a/tests/disks/test-qemu-drive.sh +++ b/tests/disks/test-qemu-drive.sh @@ -47,7 +47,7 @@ rm -f "$DEBUG_QEMU_FILE" # Ceph (RBD). $guestfish <