[libvirt] [PATCH 5/8] qemu: monitor: Add API to help creating 'transaction' arguments

Peter Krempa posted 8 patches 6 years, 10 months ago
[libvirt] [PATCH 5/8] qemu: monitor: Add API to help creating 'transaction' arguments
Posted by Peter Krempa 6 years, 10 months ago
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 blockdevizing of snapshots.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/qemu/qemu_monitor_json.c | 46 ++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_monitor_json.h |  4 ++++
 2 files changed, 50 insertions(+)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 3e90279b71..54fefcb612 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -464,6 +464,52 @@ 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 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
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 6bc0dd3ad2..da6c121d72 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -32,6 +32,10 @@
 # include "cpu/cpu.h"
 # include "util/virgic.h"

+int qemuMonitorJSONTransactionAdd(virJSONValuePtr actions,
+                                  const char *cmdname,
+                                  ...);
+
 int qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon,
                                  const char *line,
                                  qemuMonitorMessagePtr msg);
-- 
2.16.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 5/8] qemu: monitor: Add API to help creating 'transaction' arguments
Posted by Ján Tomko 6 years, 10 months ago
On Tue, Jul 03, 2018 at 02:33:03PM +0200, Peter Krempa wrote:
>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 blockdevizing of snapshots.

Have you considered 'blockdevification' or 'make blockdevable'?

>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> src/qemu/qemu_monitor_json.c | 46 ++++++++++++++++++++++++++++++++++++++++++++
> src/qemu/qemu_monitor_json.h |  4 ++++
> 2 files changed, 50 insertions(+)
>
>diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
>index 3e90279b71..54fefcb612 100644
>--- a/src/qemu/qemu_monitor_json.c
>+++ b/src/qemu/qemu_monitor_json.c
>@@ -464,6 +464,52 @@ 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 used as argument for the 'transaction' command.

"is intended to be used" or "can be used"?

>+ *
>+ * 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);
>+

I'm not a fan of this empty line.

>+    return ret;
>+}
>+
>+

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list