On Wed, Dec 12, 2018 at 06:09:00PM +0100, Peter Krempa wrote:
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_monitor.c | 23 +++++
src/qemu/qemu_monitor.h | 49 ++++++++++
src/qemu/qemu_monitor_json.c | 86 ++++++++++++++++++
src/qemu/qemu_monitor_json.h | 6 ++
.../query-jobs-create.json | 20 +++++
.../query-jobs-create.result | 11 +++
.../qemumonitorjsondata/query-jobs-empty.json | 1 +
.../query-jobs-empty.result | 0
tests/qemumonitorjsontest.c | 89 +++++++++++++++++++
9 files changed, 285 insertions(+)
create mode 100644 tests/qemumonitorjsondata/query-jobs-create.json
create mode 100644 tests/qemumonitorjsondata/query-jobs-create.result
create mode 100644 tests/qemumonitorjsondata/query-jobs-empty.json
create mode 100644 tests/qemumonitorjsondata/query-jobs-empty.result
+int
+qemuMonitorJSONGetJobInfo(qemuMonitorPtr mon,
+ qemuMonitorJobInfoPtr **jobs,
+ size_t *njobs)
+{
+ virJSONValuePtr data;
+ virJSONValuePtr cmd;
+ virJSONValuePtr reply = NULL;
+ size_t i;
+ int ret = -1;
+
+ if (!(cmd = qemuMonitorJSONMakeCommand("query-jobs", NULL)))
+ return -1;
+
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
+
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
+ goto cleanup;
+
+ data = virJSONValueObjectGetArray(reply, "return");
+
+ for (i = 0; i < virJSONValueArraySize(data); i++) {
+ qemuMonitorJobInfoPtr job = NULL;
+
+ if (!(job = qemuMonitorJSONGetJobInfoOne(virJSONValueArrayGet(data, i))))
+ goto cleanup;
+
+ if (VIR_APPEND_ELEMENT(*jobs, *njobs, job) < 0)
+ goto cleanup;
On the unlikely event of VIR_APPEND_ELEMENT returning -1, job will be
leaked.
+ }
+
+ ret = 0;
+
+ cleanup:
+ virJSONValueFree(cmd);
+ virJSONValueFree(reply);
+ return ret;
+}
Reviewed-by: Ján Tomko <jtomko(a)redhat.com>
Jano