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 identifies a
single volume." 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.

Unfortunately I wasn't able to figure out a way to retrieve the gluster
volume UUID which would avoid the possibility of having two distinct
keys identifying a single volume.

Use the full URI as the key for the volume to avoid the more critical
ambiguity problem and document the possible change to UUID.
This commit is contained in:
Peter Krempa 2014-02-24 16:12:34 +01:00
parent fa5b5549cb
commit 0f6c50b9b6
2 changed files with 13 additions and 5 deletions

View File

@ -711,12 +711,14 @@
correspond to the files that can be found when mounting the correspond to the files that can be found when mounting the
gluster volume. The <code>name</code> is the path relative to gluster volume. The <code>name</code> is the path relative to
the effective mount specified for the pool; and the effective mount specified for the pool; and
the <code>key</code> is a path including the gluster volume the <code>key</code> is a string that identifies a single volume
name and any subdirectory specified by the pool.</p> uniquely. Currently the <code>key</code> attribute consists of the
URI of the volume but it may be changed to a UUID of the volume
in the future.</p>
<pre> <pre>
&lt;volume&gt; &lt;volume&gt;
&lt;name&gt;myfile&lt;/name&gt; &lt;name&gt;myfile&lt;/name&gt;
&lt;key&gt;volname/myfile&lt;/key&gt; &lt;key&gt;gluster://localhost/volname/myfile&lt;/key&gt;
&lt;source&gt; &lt;source&gt;
&lt;/source&gt; &lt;/source&gt;
&lt;capacity unit='bytes'&gt;53687091200&lt;/capacity&gt; &lt;capacity unit='bytes'&gt;53687091200&lt;/capacity&gt;

View File

@ -187,6 +187,7 @@ virStorageBackendGlusterSetMetadata(virStorageBackendGlusterStatePtr state,
const char *name) const char *name)
{ {
int ret = -1; int ret = -1;
char *path = NULL;
char *tmp; char *tmp;
VIR_FREE(vol->key); VIR_FREE(vol->key);
@ -201,12 +202,12 @@ virStorageBackendGlusterSetMetadata(virStorageBackendGlusterStatePtr state,
goto cleanup; 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) vol->name) < 0)
goto cleanup; goto cleanup;
tmp = state->uri->path; 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; state->uri->path = tmp;
goto cleanup; goto cleanup;
} }
@ -218,9 +219,14 @@ virStorageBackendGlusterSetMetadata(virStorageBackendGlusterStatePtr state,
VIR_FREE(state->uri->path); VIR_FREE(state->uri->path);
state->uri->path = tmp; 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; ret = 0;
cleanup: cleanup:
VIR_FREE(path);
return ret; return ret;
} }