mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 : "");
|
||||
|
||||
@@ -47,7 +47,7 @@ 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
|
||||
@@ -55,6 +55,14 @@ 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 ||:
|
||||
|
||||
Reference in New Issue
Block a user