Skip to content

Commit

Permalink
lib: Handle Ceph/rbd paths properly (RHBZ#1026688).
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rwmjones committed Jan 23, 2014
1 parent b93a1d5 commit 53a3ff9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion generator/actions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions src/drives.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/guestfs.pod
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ To do this, set the optional C<protocol> and C<server> parameters of
L</guestfs_add_drive_opts> 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,
Expand Down
10 changes: 5 additions & 5 deletions src/launch-direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 : "");
Expand Down
10 changes: 9 additions & 1 deletion tests/disks/test-qemu-drive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,22 @@ rm -f "$DEBUG_QEMU_FILE"
# Ceph (RBD).

$guestfish <<EOF ||:
add "/abc-def/ghi-jkl" "format:raw" "protocol:rbd" \
add "abc-def/ghi-jkl" "format:raw" "protocol:rbd" \
"server:1.2.3.4:1234 1.2.3.5:1235 1.2.3.6:1236"
run
EOF
check_output
grep -sq -- '-drive file=rbd:abc-def/ghi-jkl:mon_host=1.2.3.4\\:1234\\;1.2.3.5\\:1235\\;1.2.3.6\\:1236:auth_supported=none,' "$DEBUG_QEMU_FILE" || fail
rm "$DEBUG_QEMU_FILE"

$guestfish <<EOF ||:
add "abc-def/ghi-jkl" "format:raw" "protocol:rbd"
run
EOF
check_output
grep -sq -- '-drive file=rbd:abc-def/ghi-jkl:auth_supported=none,' "$DEBUG_QEMU_FILE" || fail
rm "$DEBUG_QEMU_FILE"

# HTTP.

$guestfish <<EOF ||:
Expand Down

0 comments on commit 53a3ff9

Please sign in to comment.