Hi, all.
I'm Joel
I wan't propose patch to correct bug to refresh volume on sheepdog from
a sheep pool.
Bug I'm not understanding how to configure correctly my .git/config to
send patch.
Warning, I'm not C developper, this patch requiered correction for char
analyse and copy. It's work but ...
My patch (add auto volumes (vdi) and refresh when adding a pool sheepdog)
Thanks.
diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_backend_sheepdog.c
index a6981ce..5bcad03 100644
--- a/src/storage/storage_backend_sheepdog.c
+++ b/src/storage/storage_backend_sheepdog.c
@@ -34,6 +34,7 @@
#include "viralloc.h"
#include "virlog.h"
#include "virstring.h"
+#include <assert.h>
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -44,6 +45,56 @@ static int virStorageBackendSheepdogRefreshVol(virConnectPtr conn,
void virStorageBackendSheepdogAddHostArg(virCommandPtr cmd,
virStoragePoolObjPtr pool);
+char** str_split(char* a_str, const char a_delim);
+
+char** str_split(char* a_str, const char a_delim) {
+ char** result = 0;
+ size_t count = 0;
+
+
+ char* tmp = a_str;
+
+
+ char* last_comma = 0;
+ char delim[2];
+ delim[0] = a_delim;
+ delim[1] = 0;
+
+ /* Count how many elements will be extracted. */
+ while (*tmp) {
+ if (a_delim == *tmp) {
+ count++;
+ last_comma = tmp;
+ }
+ tmp++;
+ }
+
+ /* Add space for trailing token. */
+ count += last_comma < (a_str + strlen(a_str) - 1);
+
+ /* Add space for terminating null string so caller
+ knows where the list of returned strings ends. */
+ count++;
+
+ result = malloc(sizeof (char*) * count);
+
+
+ if (result) {
+ size_t idx = 0;
+ char* token = strtok(a_str, delim);
+
+ while (token) {
+ assert(idx < count);
+ *(result + idx++) = strdup(token);
+ token = strtok(0, delim);
+ }
+ assert(idx == count - 1);
+ *(result + idx) = 0;
+ }
+
+ return result;
+}
+
int
virStorageBackendSheepdogParseNodeInfo(virStoragePoolDefPtr pool,
char *output)
@@ -111,6 +162,69 @@ virStorageBackendSheepdogAddHostArg(virCommandPtr cmd,
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;
+ lines = (char**) str_split(output, '\n');
+ int i;
+ for (i = 0; *(lines + i); i++) {
+ char *line = *(lines + i);
+ char** cells;
+ cells = (char**) str_split(line, ' ');
+ int 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_REALLOC_N(pool->volumes.objs,
+ pool->volumes.count + 1) < 0)
+ goto cleanup;
+ pool->volumes.objs[pool->volumes.count++] = vol;
+
+ if (virStorageBackendSheepdogRefreshVol(conn, pool, vol) < 0)
+ goto cleanup;
+
+ vol = NULL;
+ }
+
+ free(*(cells + j));
+ }
+
+ free(cells);
+ free(*(lines + i));
+ }
+
+
+ free(lines);
+
+ if (ret < 0)
+ goto cleanup;
+
+
+cleanup:
+ virCommandFree(cmd);
+ return ret;
+}
+
+
+static int
virStorageBackendSheepdogRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool)
{
@@ -122,9 +236,10 @@ virStorageBackendSheepdogRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
virStorageBackendSheepdogAddHostArg(cmd, pool);
virCommandSetOutputBuffer(cmd, &output);
ret = virCommandRun(cmd, NULL);
- if (ret == 0)
+ if (ret == 0){
ret = virStorageBackendSheepdogParseNodeInfo(pool->def, output);
-
+ virStorageBackendSheepdogRefreshAllVol(conn, pool);
+ }
virCommandFree(cmd);
VIR_FREE(output);
return ret;
--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list