]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuMonitorJSONSetMigrationParams: Refactor command construction and cleanup
authorPeter Krempa <pkrempa@redhat.com>
Wed, 4 Mar 2020 09:10:56 +0000 (10:10 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 5 Mar 2020 10:31:38 +0000 (11:31 +0100)
qemuMonitorJSONMakeCommandInternal does the full command construction if
you pass in what would become the value of the 'arguments' key. Refactor
the open-coded implementation to use the helper and use modern cleanup
helpers at the same time.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/qemu/qemu_monitor_json.c

index 5f0185d10be4a302189de5cbd9cc3243b82acf7e..3eac80c060884116568b51969f9cb8f51292241d 100644 (file)
@@ -3440,30 +3440,19 @@ int
 qemuMonitorJSONSetMigrationParams(qemuMonitorPtr mon,
                                   virJSONValuePtr params)
 {
-    int ret = -1;
-    virJSONValuePtr cmd = virJSONValueNewObject();
-    virJSONValuePtr reply = NULL;
-
-    if (virJSONValueObjectAppendString(cmd, "execute",
-                                       "migrate-set-parameters") < 0)
-        goto cleanup;
+    g_autoptr(virJSONValue) cmd = NULL;
+    g_autoptr(virJSONValue) reply = NULL;
 
-    if (virJSONValueObjectAppend(cmd, "arguments", params) < 0)
-        goto cleanup;
-    params = NULL;
+    if (!(cmd = qemuMonitorJSONMakeCommandInternal("migrate-set-parameters", params)))
+        return -1;
 
     if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
-        goto cleanup;
+        return -1;
 
     if (qemuMonitorJSONCheckError(cmd, reply) < 0)
-        goto cleanup;
+        return -1;
 
-    ret = 0;
- cleanup:
-    virJSONValueFree(cmd);
-    virJSONValueFree(params);
-    virJSONValueFree(reply);
-    return ret;
+    return 0;
 }