From 90521d075493127a09b30205f2de8582214bd1d6 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 23 Oct 2017 16:23:45 +0200 Subject: [PATCH] storage: Store RBD image name as pool and image name Similarly to how we store gluster names, split the name into a pool and image portions when paring the XML and store them separately. --- src/conf/domain_conf.c | 13 ++++++----- src/libxl/libxl_conf.c | 2 +- src/qemu/qemu_command.c | 2 +- src/util/virstoragefile.c | 22 +++++++++---------- src/xenconfig/xen_xl.c | 2 +- .../domainsnapshotxml2xmlin/disk_snapshot.xml | 2 +- .../disk_snapshot.xml | 2 +- 7 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 75b4b99dcf..7dfd7b54e6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8388,16 +8388,17 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, src->tlsFromConfig = !!tlsCfgVal; } - /* for historical reasons the volume name for gluster volume is stored - * as a part of the path. This is hard to work with when dealing with - * relative names. Split out the volume into a separate variable */ - if (src->path && src->protocol == VIR_STORAGE_NET_PROTOCOL_GLUSTER) { + /* for historical reasons we store the volume and image name in one XML + * element although it complicates thing when attempting to access them. */ + if (src->path && + (src->protocol == VIR_STORAGE_NET_PROTOCOL_GLUSTER || + src->protocol == VIR_STORAGE_NET_PROTOCOL_RBD)) { char *tmp; if (!(tmp = strchr(src->path, '/')) || tmp == src->path) { virReportError(VIR_ERR_XML_ERROR, - _("missing volume name or file name in " - "gluster source path '%s'"), src->path); + _("can't split path '%s' into pool name and image " + "name"), src->path); goto cleanup; } diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index ecbabfc797..63397e94c0 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -657,7 +657,7 @@ libxlMakeNetworkDiskSrcStr(virStorageSourcePtr src, goto cleanup; } - virBufferStrcat(&buf, "rbd:", src->path, NULL); + virBufferStrcat(&buf, "rbd:", src->volume, "/", src->path, NULL); if (username) { virBufferEscape(&buf, '\\', ":", ":id=%s", username); diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 429f1a2156..03a8056d9e 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -951,7 +951,7 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src, goto cleanup; } - virBufferStrcat(&buf, "rbd:", src->path, NULL); + virBufferStrcat(&buf, "rbd:", src->volume, "/", src->path, NULL); if (src->snapshot) virBufferEscape(&buf, '\\', ":", "@%s", src->snapshot); diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index d48358abb0..9cee643121 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2545,6 +2545,14 @@ virStorageSourceParseRBDColonString(const char *rbdstr, *p = '\0'; } + /* pool vs. image name */ + if ((p = strchr(src->path, '/'))) { + VIR_STEAL_PTR(src->volume, src->path); + if (VIR_STRDUP(src->path, p + 1) < 0) + goto error; + *p = '\0'; + } + /* options */ if (!options) return 0; /* all done */ @@ -3178,7 +3186,6 @@ virStorageSourceParseBackingJSONRBD(virStorageSourcePtr src, const char *conf = virJSONValueObjectGetString(json, "conf"); const char *snapshot = virJSONValueObjectGetString(json, "snapshot"); virJSONValuePtr servers = virJSONValueObjectGetArray(json, "server"); - char *fullname = NULL; size_t nservers; size_t i; int ret = -1; @@ -3197,17 +3204,12 @@ virStorageSourceParseBackingJSONRBD(virStorageSourcePtr src, return -1; } - /* currently we need to store the pool name and image name together, since - * the rest of the code is not prepared for it */ - if (virAsprintf(&fullname, "%s/%s", pool, image) < 0) - return -1; - - if (VIR_STRDUP(src->snapshot, snapshot) < 0 || + if (VIR_STRDUP(src->volume, pool) < 0 || + VIR_STRDUP(src->path, image) < 0 || + VIR_STRDUP(src->snapshot, snapshot) < 0 || VIR_STRDUP(src->configFile, conf) < 0) goto cleanup; - VIR_STEAL_PTR(src->path, fullname); - if (servers) { nservers = virJSONValueArraySize(servers); @@ -3225,8 +3227,6 @@ virStorageSourceParseBackingJSONRBD(virStorageSourcePtr src, ret = 0; cleanup: - VIR_FREE(fullname); - return ret; } diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c index 8acbfe3f69..a61f1d7d58 100644 --- a/src/xenconfig/xen_xl.c +++ b/src/xenconfig/xen_xl.c @@ -1040,7 +1040,7 @@ xenFormatXLDiskSrcNet(virStorageSourcePtr src) goto cleanup; } - virBufferStrcat(&buf, "rbd:", src->path, NULL); + virBufferStrcat(&buf, "rbd:", src->volume, "/", src->path, NULL); virBufferAddLit(&buf, ":auth_supported=none"); diff --git a/tests/domainsnapshotxml2xmlin/disk_snapshot.xml b/tests/domainsnapshotxml2xmlin/disk_snapshot.xml index aa1522a450..cf5ea0814e 100644 --- a/tests/domainsnapshotxml2xmlin/disk_snapshot.xml +++ b/tests/domainsnapshotxml2xmlin/disk_snapshot.xml @@ -24,7 +24,7 @@ - + diff --git a/tests/domainsnapshotxml2xmlout/disk_snapshot.xml b/tests/domainsnapshotxml2xmlout/disk_snapshot.xml index c2e77d7aca..0e81f35c69 100644 --- a/tests/domainsnapshotxml2xmlout/disk_snapshot.xml +++ b/tests/domainsnapshotxml2xmlout/disk_snapshot.xml @@ -23,7 +23,7 @@ - +