[libvirt] [PATCH 1/2] storage: Separate out the qemu-img help output generation

John Ferlan jferlan at redhat.com
Tue Apr 17 19:23:32 UTC 2018


Separate out and return the output string for future comparison.
Going to need to add new checks shortly.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/storage/storage_util.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index 897dfdaaee..7df52239c2 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -799,11 +799,10 @@ enum {
     QEMU_IMG_BACKING_FORMAT_OPTIONS_COMPAT,
 };
 
-static bool
-virStorageBackendQemuImgSupportsCompat(const char *qemuimg)
+static char *
+virStorageBackendQemuImgCreateHelp(const char *qemuimg)
 {
-    bool ret = false;
-    char *output;
+    char *output = NULL;
     virCommandPtr cmd = NULL;
 
     cmd = virCommandNewArgList(qemuimg, "create", "-o", "?", "-f", "qcow2",
@@ -812,34 +811,40 @@ virStorageBackendQemuImgSupportsCompat(const char *qemuimg)
     virCommandAddEnvString(cmd, "LC_ALL=C");
     virCommandSetOutputBuffer(cmd, &output);
 
-    if (virCommandRun(cmd, NULL) < 0)
-        goto cleanup;
-
-    if (strstr(output, "\ncompat "))
-        ret = true;
+    ignore_value(virCommandRun(cmd, NULL));
 
- cleanup:
     virCommandFree(cmd);
-    VIR_FREE(output);
-    return ret;
+    return output;
 }
 
 
+static bool
+virStorageBackendQemuImgSupportsCompat(const char *output)
+{
+    return strstr(output, "\ncompat ");
+}
+
 static int
 virStorageBackendQEMUImgBackingFormat(const char *qemuimg)
 {
+    char *output = NULL;
     /* As of QEMU 0.11 the [-o options] support was added via qemu
      * commit id '9ea2ea71', so we start with that base and figure
      * out what else we have */
     int ret = QEMU_IMG_BACKING_FORMAT_OPTIONS;
 
+    if (!(output = virStorageBackendQemuImgCreateHelp(qemuimg)))
+        goto cleanup;
+
     /* QEMU 2.0 changed to using a format that only QEMU 1.1 and newer
      * understands. Since we still support QEMU 0.12 and newer, we need
      * to be able to handle the previous format as can be set via a
      * compat=0.10 option. */
-    if (virStorageBackendQemuImgSupportsCompat(qemuimg))
+    if (virStorageBackendQemuImgSupportsCompat(output))
         ret = QEMU_IMG_BACKING_FORMAT_OPTIONS_COMPAT;
 
+ cleanup:
+    VIR_FREE(output);
     return ret;
 }
 
-- 
2.13.6




More information about the libvir-list mailing list