[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 3/3] gluster: Fix "key" attribute for gluster volumes



According to our documentation the "key" value has the following
meaning: "Providing an identifier for the volume which is globally
unique. This cannot be set when creating a volume: it is always
generated." The currently used keys for gluster volumes consist of the
gluster volume name and file path. This can't be considered unique as a
different storage server can serve a volume with the same name.

Use the full URI as the key for the volume to avoid ambiguity problems.
---
 src/storage/storage_backend_gluster.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c
index 202a441..bb13463 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -185,6 +185,7 @@ virStorageBackendGlusterSetMetadata(virStorageBackendGlusterStatePtr state,
                                     const char *name)
 {
     int ret = -1;
+    char *path = NULL;
     char *tmp;

     VIR_FREE(vol->key);
@@ -199,12 +200,12 @@ virStorageBackendGlusterSetMetadata(virStorageBackendGlusterStatePtr state,
             goto cleanup;
     }

-    if (virAsprintf(&vol->key, "%s%s%s", state->volname, state->dir,
+    if (virAsprintf(&path, "%s%s%s", state->volname, state->dir,
                     vol->name) < 0)
         goto cleanup;

     tmp = state->uri->path;
-    if (virAsprintf(&state->uri->path, "/%s", vol->key) < 0) {
+    if (virAsprintf(&state->uri->path, "/%s", path) < 0) {
         state->uri->path = tmp;
         goto cleanup;
     }
@@ -216,9 +217,14 @@ virStorageBackendGlusterSetMetadata(virStorageBackendGlusterStatePtr state,
     VIR_FREE(state->uri->path);
     state->uri->path = tmp;

+    /* the path is unique enough to serve as a volume key */
+    if (VIR_STRDUP(vol->key, vol->target.path) < 0)
+        goto cleanup;
+
     ret = 0;

 cleanup:
+    VIR_FREE(path);
     return ret;
 }

-- 
1.8.5.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]