[PATCH V5] Sheepdog: Adding volume and on pool and refresh.

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

 



From: Joel SIMOES <joel.simoes@xxxxxxxxxxx>

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.

Adding last Daniel P. Berrange's syntaxes correction.
Adding vol on separeted function 'inspired' from parallels_storage :
parallelsAddDiskVolume
---
 src/storage/storage_backend_sheepdog.c | 86 ++++++++++++++++++++++++++++++++--
 1 file changed, 82 insertions(+), 4 deletions(-)

diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_backend_sheepdog.c
index a6981ce..08e5473 100644
--- a/src/storage/storage_backend_sheepdog.c
+++ b/src/storage/storage_backend_sheepdog.c
@@ -109,22 +109,100 @@ virStorageBackendSheepdogAddHostArg(virCommandPtr cmd,
     virCommandAddArgFormat(cmd, "%d", port);
 }
 
+static int
+virStorageBackendSheepdogAddVolume(virConnectPtr conn ATTRIBUTE_UNUSED,
+                                  virStoragePoolObjPtr pool, const char *diskInfo)
+{
+    virStorageVolDefPtr vol = NULL;
+
+    if (diskInfo == NULL)
+        goto error;
+
+    if (VIR_ALLOC(vol) < 0 || VIR_STRDUP(vol->name, diskInfo) < 0)
+        goto error;
+
+    vol->type = VIR_STORAGE_VOL_NETWORK;
+
+    if (VIR_EXPAND_N(pool->volumes.objs, pool->volumes.count, 1) < 0)
+        goto error;
+
+    pool->volumes.objs[pool->volumes.count - 1] = vol;
+
+    if (virStorageBackendSheepdogRefreshVol(conn, pool, vol) < 0)
+        goto error;
+
+    return 0;
+
+error:
+    virStorageVolDefFree(vol);
+    return -1;
+}
+
+static int
+virStorageBackendSheepdogRefreshAllVol(virConnectPtr conn ATTRIBUTE_UNUSED,
+                                       virStoragePoolObjPtr pool)
+{
+    int ret = -1;
+    char *output = NULL;
+    char **lines = NULL;
+    char **cells = NULL;
+    size_t i;
+
+    virCommandPtr cmd = virCommandNewArgList(COLLIE, "vdi", "list", "-r", NULL);
+    virStorageBackendSheepdogAddHostArg(cmd, pool);
+    virCommandSetOutputBuffer(cmd, &output);
+    if (virCommandRun(cmd, NULL) < 0)
+        goto cleanup;
+
+    lines = virStringSplit(output, "\n", 0);
+    if (lines == NULL)
+        goto cleanup;
+
+    for (i = 0; lines[i]; i++) {
+        char *line = lines[i];
+        if (line == NULL)
+            break;
+
+        cells = virStringSplit(line, " ", 0);
+
+        if (cells != NULL && virStringListLength(cells) > 2) {
+            if (virStorageBackendSheepdogAddVolume(conn, pool, cells[1]) < 0)
+                goto cleanup;
+        }
+
+        virStringFreeList(cells);
+        cells = NULL;
+    }
+
+    ret = 0;
+
+cleanup:
+    virCommandFree(cmd);
+    virStringFreeList(lines);
+    virStringFreeList(cells);
+    return ret;
+}
+
 
 static int
 virStorageBackendSheepdogRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
                                      virStoragePoolObjPtr pool)
 {
-    int ret;
+    int ret = -1;
     char *output = NULL;
     virCommandPtr cmd;
 
     cmd = virCommandNewArgList(COLLIE, "node", "info", "-r", NULL);
     virStorageBackendSheepdogAddHostArg(cmd, pool);
     virCommandSetOutputBuffer(cmd, &output);
-    ret = virCommandRun(cmd, NULL);
-    if (ret == 0)
-        ret = virStorageBackendSheepdogParseNodeInfo(pool->def, output);
+    if (virCommandRun(cmd, NULL) < 0)
+        goto cleanup;
 
+    if (virStorageBackendSheepdogParseNodeInfo(pool->def, output) < 0)
+        goto cleanup;
+
+    ret = virStorageBackendSheepdogRefreshAllVol(conn, pool);
+cleanup:
     virCommandFree(cmd);
     VIR_FREE(output);
     return ret;
-- 
1.8.3.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]