Re: [libvirt] [PATCH] Sheepdog: Auto Adding volume and correct refresh volume problem. Resent file

From: Joel SIMOES <joel.simoes@laposte.net> --- src/storage/storage_backend_sheepdog.c | 92 ++++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 10 deletions(-) diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_backend_sheepdog.c index a6981ce..75304b1 100644 --- a/src/storage/storage_backend_sheepdog.c +++ b/src/storage/storage_backend_sheepdog.c @@ -86,7 +86,8 @@ virStorageBackendSheepdogParseNodeInfo(virStoragePoolDefPtr pool, pool->available = pool->capacity - pool->allocation; return 0; - } while ((p = next)); + } + while ((p = next)); return -1; } @@ -109,6 +110,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,15 +187,18 @@ 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; } - static int virStorageBackendSheepdogDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, @@ -143,12 +211,14 @@ virStorageBackendSheepdogDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED, virCommandPtr cmd = virCommandNewArgList(COLLIE, "vdi", "delete", vol->name, NULL); virStorageBackendSheepdogAddHostArg(cmd, pool); int ret = virCommandRun(cmd, NULL); + if (ret < 0) + goto cleanup; +cleanup: virCommandFree(cmd); return ret; } - static int virStorageBackendSheepdogCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, @@ -174,7 +244,6 @@ virStorageBackendSheepdogCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED, return 0; } - static int virStorageBackendSheepdogBuildVol(virConnectPtr conn, virStoragePoolObjPtr pool, @@ -195,12 +264,12 @@ virStorageBackendSheepdogBuildVol(virConnectPtr conn, goto cleanup; ret = 0; + cleanup: virCommandFree(cmd); return ret; } - int virStorageBackendSheepdogParseVdiList(virStorageVolDefPtr vol, char *output) @@ -257,7 +326,8 @@ virStorageBackendSheepdogParseVdiList(virStorageVolDefPtr vol, return -1; return 0; - } while ((p = next)); + } + while ((p = next)); return -1; } @@ -295,7 +365,6 @@ cleanup: return ret; } - static int virStorageBackendSheepdogResizeVol(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, @@ -310,7 +379,10 @@ virStorageBackendSheepdogResizeVol(virConnectPtr conn ATTRIBUTE_UNUSED, virCommandAddArgFormat(cmd, "%llu", capacity); virStorageBackendSheepdogAddHostArg(cmd, pool); int ret = virCommandRun(cmd, NULL); + if (ret < 0) + goto cleanup; +cleanup: virCommandFree(cmd); return ret; -- 1.8.3.2

On 01/27/2014 04:11 AM, joel SIMOES wrote:
From: Joel SIMOES <joel.simoes@laposte.net>
Your title says 'Re: ...', but there is no In-reply-to heading that states what you were replying to. Furthermore, including the text 'Resent file' in the subject line looks awkward when used as a git commit (look at 'git shortlog -30' for an idea of good subject lines, and note that none of them mention 'Resent file' in the text). If this is a second version of the patch, it is better to use 'git send-email --subject-prefix=PATCHv2' to make it clear that it is a resend, rather than munging the subject line by hand outside of the [] prefix.
---
Also, your commit message body is still empty. Remember, the subject line should be brief (the WHAT), the commit message body before the --- should not be empty (the WHY), and the space after the --- is useful for reviewer's notes (HOW this differs from v1).
+++ b/src/storage/storage_backend_sheepdog.c @@ -86,7 +86,8 @@ virStorageBackendSheepdogParseNodeInfo(virStoragePoolDefPtr pool, pool->available = pool->capacity - pool->allocation; return 0;
- } while ((p = next)); + } + while ((p = next));
This hunk is still spurious. I pointed it out last time, and it is rather annoying to review patches where items pointed out previously aren't addressed. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
joel SIMOES