]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: monitor: Add API to help creating 'transaction' arguments
authorPeter Krempa <pkrempa@redhat.com>
Tue, 3 Jul 2018 07:24:40 +0000 (09:24 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 20 Jul 2018 11:39:44 +0000 (13:39 +0200)
Add a new helper that will be solely used to create arguments for the
transaction command. Later on this will make it possible to remove the
overloading which was caused by the fact that snapshots were created
without transaction and also will help in blockdevification of snapshots.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h

index cc3c8f2dd6108c3eea39844dd2cffa9e2e23814f..95ad53fc89a4e10803232ec130f235eb7cdaaeaf 100644 (file)
@@ -466,6 +466,51 @@ qemuMonitorJSONHasError(virJSONValuePtr reply,
 }
 
 
+/**
+ * qemuMonitorJSONTransactionAdd:
+ * @actions: array of actions for the 'transaction' command
+ * @cmdname: command to add to @actions
+ * @...: arguments for @cmdname (see virJSONValueObjectAddVArgs for formatting)
+ *
+ * Add a new command with arguments to the existing ones. The resulting array
+ * is intended to be used as argument for the 'transaction' command.
+ *
+ * Returns 0 on success and -1 on error.
+ */
+int
+qemuMonitorJSONTransactionAdd(virJSONValuePtr actions,
+                              const char *cmdname,
+                              ...)
+{
+    virJSONValuePtr entry = NULL;
+    virJSONValuePtr data = NULL;
+    va_list args;
+    int ret = -1;
+
+    va_start(args, cmdname);
+
+    if (virJSONValueObjectCreateVArgs(&data, args) < 0)
+        goto cleanup;
+
+    if (virJSONValueObjectCreate(&entry,
+                                 "s:type", cmdname,
+                                 "A:data", &data, NULL) < 0)
+        goto cleanup;
+
+    if (virJSONValueArrayAppend(actions, entry) < 0)
+        goto cleanup;
+
+    entry = NULL;
+    ret = 0;
+
+ cleanup:
+    virJSONValueFree(entry);
+    virJSONValueFree(data);
+    va_end(args);
+    return ret;
+}
+
+
 /**
  * qemuMonitorJSONMakeCommandInternal:
  * @cmdname: QMP command name
index 66536ceb971c7f94652a2f30434628fbffe3b44d..eb77ea45e05ec50e1d8c7adc6b4972d6e8a0d862 100644 (file)
 # include "cpu/cpu.h"
 # include "util/virgic.h"
 
+int qemuMonitorJSONTransactionAdd(virJSONValuePtr actions,
+                                  const char *cmdname,
+                                  ...);
+
 int qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon,
                                  const char *line,
                                  qemuMonitorMessagePtr msg);