From: Joel <joel.simoes(a)laposte.net>
Fix bug 1055479
https://bugzilla.redhat.com/show_bug.cgi?id=1055479
Libvirt lose sheepdogs volumes on pool refresh or restart.
When restarting sheepdog pool, all volumes are missing.
This patch add automatically all volume from the added pool.
---
src/storage/storage_backend_sheepdog.c | 74 +++++++++++++++++++++++++++++++++-
1 file changed, 72 insertions(+), 2 deletions(-)
diff --git a/src/storage/storage_backend_sheepdog.c
b/src/storage/storage_backend_sheepdog.c
index a6981ce..a836f27 100644
--- a/src/storage/storage_backend_sheepdog.c
+++ b/src/storage/storage_backend_sheepdog.c
@@ -109,6 +109,70 @@ virStorageBackendSheepdogAddHostArg(virCommandPtr cmd,
virCommandAddArgFormat(cmd, "%d", port);
}
+static int
+virStorageBackendSheepdogRefreshAllVol(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virStoragePoolObjPtr pool)
+{
+ int ret;
+ char *output = NULL;
+
+ virCommandPtr cmd = virCommandNewArgList(COLLIE, "vdi", "list",
"-r", NULL);
+ virStorageBackendSheepdogAddHostArg(cmd, pool);
+ virCommandSetOutputBuffer(cmd, &output);
+ ret = virCommandRun(cmd, NULL);
+ char** lines;
+ char** cells;
+
+ if (ret < 0)
+ goto cleanup;
+
+ ret = -1;
+ lines = virStringSplit(output, "\n", 0);
+ size_t i;
+ for (i = 0; *(lines + i); i++) {
+ char *line = *(lines + i);
+ cells = virStringSplit(line, " ", 0);
+ size_t j;
+ for (j = 0; *(cells + j); j++) {
+
+ char *cell = *(cells + j);
+ if (j == 1) {
+ virStorageVolDefPtr vol = NULL;
+ if (VIR_ALLOC(vol) < 0)
+ goto cleanup;
+
+ if (VIR_STRDUP(vol->name, cell) < 0)
+ goto cleanup;
+
+ vol->type = VIR_STORAGE_VOL_BLOCK;
+
+ if (VIR_EXPAND_N(pool->volumes.objs, pool->volumes.count, 1) <
0)
+ goto cleanup;
+ pool->volumes.objs[pool->volumes.count - 1] = vol;
+
+ if (virStorageBackendSheepdogRefreshVol(conn, pool, vol) < 0)
+ goto cleanup;
+
+ vol = NULL;
+ }
+
+ VIR_FREE(*(cells + j));
+ }
+
+ VIR_FREE(cells);
+ VIR_FREE(*(lines + i));
+ }
+
+
+ VIR_FREE(lines);
+ ret = 0;
+
+cleanup:
+ virCommandFree(cmd);
+ VIR_FREE(lines);
+ VIR_FREE(cells);
+ return ret;
+}
static int
virStorageBackendSheepdogRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
@@ -122,9 +186,15 @@ virStorageBackendSheepdogRefreshPool(virConnectPtr conn
ATTRIBUTE_UNUSED,
virStorageBackendSheepdogAddHostArg(cmd, pool);
virCommandSetOutputBuffer(cmd, &output);
ret = virCommandRun(cmd, NULL);
- if (ret == 0)
- ret = virStorageBackendSheepdogParseNodeInfo(pool->def, output);
+ if (ret < 0)
+ goto cleanup;
+ ret = virStorageBackendSheepdogParseNodeInfo(pool->def, output);
+ if (ret < 0)
+ goto cleanup;
+ ret = virStorageBackendSheepdogRefreshAllVol(conn, pool);
+
+cleanup:
virCommandFree(cmd);
VIR_FREE(output);
return ret;
--
1.8.3.2