[libvirt] [PATCH RFC 44/51] qemu: monitor: Add infrastructure for 'query-jobs'
Ján Tomko
jtomko at redhat.com
Tue Jan 8 12:41:58 UTC 2019
On Wed, Dec 12, 2018 at 06:09:00PM +0100, Peter Krempa wrote:
>Signed-off-by: Peter Krempa <pkrempa at 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 at redhat.com>
Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190108/b3dafcfe/attachment-0001.sig>
More information about the libvir-list
mailing list