[libvirt] [PATCH 6/7] qemu_monitor: Introduce qemuMonitorJSONGetPRManagerInfo
Peter Krempa
pkrempa at redhat.com
Wed Jul 4 11:54:39 UTC 2018
On Wed, Jul 04, 2018 at 12:46:54 +0200, Michal Privoznik wrote:
> This function fetches status of all pr-managers. So far, qemu
> reports only a single attribute "connected" but that fits our
> needs.
>
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
> src/qemu/qemu_monitor.c | 25 ++++++++++++
> src/qemu/qemu_monitor.h | 9 +++++
> src/qemu/qemu_monitor_json.c | 90 ++++++++++++++++++++++++++++++++++++++++++++
> src/qemu/qemu_monitor_json.h | 4 ++
> 4 files changed, 128 insertions(+)
[...]
> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> index 03c94cd88b..460312a067 100644
> --- a/src/qemu/qemu_monitor_json.c
> +++ b/src/qemu/qemu_monitor_json.c
> @@ -8065,3 +8065,93 @@ qemuMonitorJSONGetSEVMeasurement(qemuMonitorPtr mon)
> virJSONValueFree(reply);
> return measurement;
> }
> +
> +
> +/*
> + * Example return data
> + *
> + * "return": [
> + * { "connected": true, "id": "pr-helper0" }
> + * ]}
> + *
> + */
> +static int
> +qemuMonitorJSONExtractPRManagerInfo(virJSONValuePtr reply,
> + virHashTablePtr info)
> +{
> + qemuMonitorPRManagerInfoPtr entry = NULL;
> + virJSONValuePtr data;
> + int ret = -1;
> + size_t i;
> +
> + data = virJSONValueObjectGetArray(reply, "return");
> +
> + for (i = 0; i < virJSONValueArraySize(data); i++) {
> + virJSONValuePtr prManager = virJSONValueArrayGet(data, i);
> + const char *alias;
> +
> + if (!prManager) {
> + virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> + _("prManager information was missing array element"));
[1]
> + goto cleanup;
> + }
> +
> + if (!(alias = virJSONValueObjectGetString(prManager, "id"))) {
> + virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> + _("prManager information was missing id"));
[1]
> + goto cleanup;
> + }
> +
> + if (VIR_ALLOC(entry) < 0)
> + goto cleanup;
> +
> + if (virJSONValueObjectGetBoolean(prManager,
> + "connected",
> + &entry->connected) < 0) {
> + virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> + _("prManager information was missing connected"));
I don't think we need special errors for all these different [1] cases.
Just extract everything and report that query-pr-managers returned
malformed data.
> + goto cleanup;
> + }
> +
> + if (virHashAddEntry(info, alias, entry) < 0) {
> + virReportError(VIR_ERR_OPERATION_FAILED,
> + _("failed to add chardev '%s' info"), alias);
This is overwriting existing error.
> + VIR_FREE(entry);
This is done in the cleanup section too.
> + goto cleanup;
> + }
> +
> + entry = NULL;
> + }
> +
> + ret = 0;
> + cleanup:
> + VIR_FREE(entry);
> + return ret;
> +}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20180704/89646f80/attachment-0001.sig>
More information about the libvir-list
mailing list