]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Store RBD image name as pool and image name
authorPeter Krempa <pkrempa@redhat.com>
Mon, 23 Oct 2017 14:23:45 +0000 (16:23 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 7 Nov 2017 13:58:04 +0000 (14:58 +0100)
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
src/libxl/libxl_conf.c
src/qemu/qemu_command.c
src/util/virstoragefile.c
src/xenconfig/xen_xl.c
tests/domainsnapshotxml2xmlin/disk_snapshot.xml
tests/domainsnapshotxml2xmlout/disk_snapshot.xml

index 75b4b99dcfff19d7863360b71da121abc4a1657d..7dfd7b54e617bf7fa1a97bc90aef2ba5ee952b74 100644 (file)
@@ -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;
         }
 
index ecbabfc797af36921e8de2048791fe9306e52cb0..63397e94c06b380fdee369f9c02ea4fa7ab362b9 100644 (file)
@@ -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);
index 429f1a21565b8e7a9cf3e94f57d101aa4014e92a..03a8056d9ed1c33327766faa09975db7cb28bfc2 100644 (file)
@@ -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);
index d48358abb0667e62b24c14cd6bb5eda57d6f3509..9cee6431210c9c650f482ff8219159759689b735 100644 (file)
@@ -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;
 }
 
index 8acbfe3f6927f60d2e8f8ad3c3b7f6a05769b643..a61f1d7d583754f0722aeb25cb4dcc8a70ffab45 100644 (file)
@@ -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");
 
index aa1522a4506fc044765adec3a33a1506adfa6905..cf5ea0814e0b1ab21c1c7287f4aceae5d2e15f30 100644 (file)
@@ -24,7 +24,7 @@
       </source>
     </disk>
     <disk name='hdh' snapshot='external' type='network'>
-      <source protocol='rbd' name='name'>
+      <source protocol='rbd' name='vol/name'>
         <host name='host' port='1234'/>
         <host name='host2' port='1234' transport='rdma'/>
         <host name='host3' port='1234'/>
index c2e77d7aca123777c0a8e8398c4f81b24a0b1525..0e81f35c6903b19b1bda740b9cb72de15d887a06 100644 (file)
@@ -23,7 +23,7 @@
       </source>
     </disk>
     <disk name='hdh' snapshot='external' type='network'>
-      <source protocol='rbd' name='name'>
+      <source protocol='rbd' name='vol/name'>
         <host name='host' port='1234'/>
         <host name='host2' port='1234' transport='rdma'/>
         <host name='host3' port='1234'/>