The temporary pool code will need to initialize some fields for the
temporary gluster volumes. This is done by the createVol function of
the storage backend. This patch implements only the metadata setting.
Attempts to create a regular volume yield an error.
---
src/storage/storage_backend_gluster.c | 119 ++++++++++++++++++++++++++++------
1 file changed, 99 insertions(+), 20 deletions(-)
diff --git a/src/storage/storage_backend_gluster.c
b/src/storage/storage_backend_gluster.c
index c73cf8a..8d57098 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -178,6 +178,51 @@ virStorageBackendGlusterReadHeader(glfs_fd_t *fd,
return nread;
}
+
+static int
+virStorageBackendGlusterSetMetadata(virStorageBackendGlusterStatePtr state,
+ virStorageVolDefPtr vol,
+ const char *name)
+{
+ int ret = -1;
+ char *tmp;
+
+ VIR_FREE(vol->key);
+ VIR_FREE(vol->target.path);
+
+ vol->type = VIR_STORAGE_VOL_NETWORK;
+ vol->target.format = VIR_STORAGE_FILE_RAW;
+
+ if (name) {
+ VIR_FREE(vol->name);
+ if (VIR_STRDUP(vol->name, name) < 0)
+ goto cleanup;
+ }
+
+ if (virAsprintf(&vol->key, "%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) {
+ state->uri->path = tmp;
+ goto cleanup;
+ }
+ if (!(vol->target.path = virURIFormat(state->uri))) {
+ VIR_FREE(state->uri->path);
+ state->uri->path = tmp;
+ goto cleanup;
+ }
+ VIR_FREE(state->uri->path);
+ state->uri->path = tmp;
+
+ ret = 0;
+
+cleanup:
+ return ret;
+}
+
+
/* Populate *volptr for the given name and stat information, or leave
* it NULL if the entry should be skipped (such as "."). Return 0 on
* success, -1 on failure. */
@@ -187,7 +232,6 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr
state,
struct stat *st,
virStorageVolDefPtr *volptr)
{
- char *tmp;
int ret = -1;
virStorageVolDefPtr vol = NULL;
glfs_fd_t *fd = NULL;
@@ -220,25 +264,9 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr
state,
&vol->capacity) < 0)
goto cleanup;
- if (VIR_STRDUP(vol->name, name) < 0)
- goto cleanup;
- if (virAsprintf(&vol->key, "%s%s%s", state->volname,
state->dir,
- vol->name) < 0)
+ if (virStorageBackendGlusterSetMetadata(state, vol, name) < 0)
goto cleanup;
- tmp = state->uri->path;
- if (virAsprintf(&state->uri->path, "/%s", vol->key) < 0) {
- state->uri->path = tmp;
- goto cleanup;
- }
- if (!(vol->target.path = virURIFormat(state->uri))) {
- VIR_FREE(state->uri->path);
- state->uri->path = tmp;
- goto cleanup;
- }
- VIR_FREE(state->uri->path);
- state->uri->path = tmp;
-
if (S_ISDIR(st->st_mode)) {
vol->type = VIR_STORAGE_VOL_NETDIR;
vol->target.format = VIR_STORAGE_FILE_DIR;
@@ -248,8 +276,6 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr
state,
goto cleanup;
}
- vol->type = VIR_STORAGE_VOL_NETWORK;
- vol->target.format = VIR_STORAGE_FILE_RAW;
/* No need to worry about O_NONBLOCK - gluster doesn't allow creation
* of fifos, so there's nothing it would protect us from. */
if (!(fd = glfs_open(state->vol, name, O_RDONLY | O_NOCTTY))) {
@@ -444,10 +470,63 @@ cleanup:
}
+static int
+virStorageBackendGlusterVolCreate(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virStoragePoolObjPtr pool,
+ virStorageVolDefPtr vol,
+ bool internal)
+{
+ virStorageBackendGlusterStatePtr state = NULL;
+ struct stat st;
+ int ret = -1;
+
+ if (!internal) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("gluster pool backend doesn't "
+ "yet support volume creation"));
+ goto cleanup;
+ }
+
+ if (!(state = virStorageBackendGlusterOpen(pool)))
+ goto cleanup;
+
+ if (virStorageBackendGlusterSetMetadata(state, vol, NULL) < 0)
+ goto cleanup;
+
+ if (glfs_stat(state->vol, vol->name, &st) == 0 &&
+ S_ISDIR(st.st_mode)) {
+ vol->type = VIR_STORAGE_VOL_NETDIR;
+ vol->target.format = VIR_STORAGE_FILE_DIR;
+ }
+
+ ret = 0;
+
+cleanup:
+ virStorageBackendGlusterClose(state);
+ return ret;
+}
+
+
+static int
+virStorageBackendGlusterVolBuild(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
+ virStorageVolDefPtr vol ATTRIBUTE_UNUSED,
+ unsigned int flags)
+{
+ virCheckFlags(0, -1);
+
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("gluster pool backend doesn't yet support volume
building"));
+ return -1;
+}
+
+
virStorageBackend virStorageBackendGluster = {
.type = VIR_STORAGE_POOL_GLUSTER,
.refreshPool = virStorageBackendGlusterRefreshPool,
+ .createVol = virStorageBackendGlusterVolCreate,
+ .buildVol = virStorageBackendGlusterVolBuild,
.deleteVol = virStorageBackendGlusterVolDelete,
};
--
1.8.5.2