]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: monitor: Separate probing for active block commit
authorPeter Krempa <pkrempa@redhat.com>
Tue, 14 Aug 2018 13:52:01 +0000 (15:52 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 24 Aug 2018 11:52:44 +0000 (13:52 +0200)
Extract the code used to probe for the functionality so that it does not
litter the code used for actual work.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h

index 024618922437ae443fdce8f866dd54240cf09665..4c0002d16d85a8a321326aa5ca0764addc465b3b 100644 (file)
@@ -3302,7 +3302,7 @@ qemuMonitorSupportsActiveCommit(qemuMonitorPtr mon)
     if (!mon || !mon->json)
         return false;
 
-    return qemuMonitorJSONBlockCommit(mon, "bogus", NULL, NULL, NULL, 0) == -2;
+    return qemuMonitorJSONSupportsActiveCommit(mon);
 }
 
 
index 2c3ba27cbfcede592c4d1025d94573461ee913f6..3181805f9ce79d30b9aa011e9c5859576638f52f 100644 (file)
@@ -4366,14 +4366,42 @@ qemuMonitorJSONTransaction(qemuMonitorPtr mon, virJSONValuePtr *actions)
     return ret;
 }
 
+/* Probe if active commit is supported: pass in a bogus device and NULL top
+ * and base.  The probe return is true if active commit is detected or false
+ * if not supported or on any error */
+bool
+qemuMonitorJSONSupportsActiveCommit(qemuMonitorPtr mon)
+{
+    bool ret = false;
+    virJSONValuePtr cmd;
+    virJSONValuePtr reply = NULL;
+
+    if (!(cmd = qemuMonitorJSONMakeCommand("block-commit", "s:device",
+                                           "bogus", NULL)))
+        return false;
+
+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+        goto cleanup;
+
+    if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) {
+        VIR_DEBUG("block-commit supports active commit");
+        ret = true;
+        goto cleanup;
+    }
+
+    /* This is a false negative for qemu 2.0; but probably not
+     * worth the additional complexity to worry about it */
+    VIR_DEBUG("block-commit requires 'top' parameter, "
+              "assuming it lacks active commit");
+ cleanup:
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    return ret;
+}
+
+
 /* speed is in bytes/sec. Returns 0 on success, -1 with error message
- * emitted on failure.
- *
- * Additionally, can be used to probe if active commit is supported:
- * pass in a bogus device and NULL top and base.  The probe return is
- * -2 if active commit is detected, -3 if inconclusive; with no error
- * message issued.
- */
+ * emitted on failure. */
 int
 qemuMonitorJSONBlockCommit(qemuMonitorPtr mon, const char *device,
                            const char *top, const char *base,
@@ -4396,22 +4424,6 @@ qemuMonitorJSONBlockCommit(qemuMonitorPtr mon, const char *device,
 
     if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
         goto cleanup;
-    if (!top && !base) {
-        /* Normally we always specify top and base; but omitting them
-         * allows for probing whether qemu is new enough to support
-         * live commit.  */
-        if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) {
-            VIR_DEBUG("block-commit supports active commit");
-            ret = -2;
-        } else {
-            /* This is a false negative for qemu 2.0; but probably not
-             * worth the additional complexity to worry about it */
-            VIR_DEBUG("block-commit requires 'top' parameter, "
-                      "assuming it lacks active commit");
-            ret = -3;
-        }
-        goto cleanup;
-    }
 
     if (qemuMonitorJSONCheckError(cmd, reply) < 0)
         goto cleanup;
index 69faecd0abec250a358e27259ebd3baeac3ad29d..da267b15b06e9ebbb223efcf4599d48dca1086df 100644 (file)
@@ -270,6 +270,9 @@ int qemuMonitorJSONDrivePivot(qemuMonitorPtr mon,
                               const char *jobname)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
+bool qemuMonitorJSONSupportsActiveCommit(qemuMonitorPtr mon)
+    ATTRIBUTE_NONNULL(1);
+
 int qemuMonitorJSONBlockCommit(qemuMonitorPtr mon,
                                const char *device,
                                const char *top,