From nobody Wed May 14 12:57:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1521743643940958.8428463753476; Thu, 22 Mar 2018 11:34:03 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 74F147FEAF; Thu, 22 Mar 2018 18:34:02 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2D3AE80A51; Thu, 22 Mar 2018 18:34:02 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D43AA4CA9B; Thu, 22 Mar 2018 18:34:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2MIVura015617 for ; Thu, 22 Mar 2018 14:31:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0B51C84433; Thu, 22 Mar 2018 18:31:56 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 88D2C8442E; Thu, 22 Mar 2018 18:31:55 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 22 Mar 2018 19:31:41 +0100 Message-Id: <6cd03e0d87fb82746db66ba232c3c93b3c08e95c.1521743167.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 04/11] qemu: monitor: Move processing of QMP schema to the new file X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 22 Mar 2018 18:34:02 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The JSON array was processed to the hash table used by the query apis in the monitor code. Move it to a new helper in qemu_qapi.c. Signed-off-by: Peter Krempa --- src/qemu/qemu_capabilities.c | 9 ++++++-- src/qemu/qemu_monitor.c | 2 +- src/qemu/qemu_monitor.h | 2 +- src/qemu/qemu_monitor_json.c | 41 +++++------------------------------- src/qemu/qemu_monitor_json.h | 2 +- src/qemu/qemu_qapi.c | 50 ++++++++++++++++++++++++++++++++++++++++= ++++ src/qemu/qemu_qapi.h | 4 ++++ 7 files changed, 69 insertions(+), 41 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index a6170c66f2..16f7c7d6c9 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4570,12 +4570,17 @@ virQEMUCapsProbeQMPSchemaCapabilities(virQEMUCapsPt= r qemuCaps, qemuMonitorPtr mon) { struct virQEMUCapsStringFlags *entry; - virHashTablePtr schema; + virJSONValuePtr schemareply; + virHashTablePtr schema =3D NULL; size_t i; - if (!(schema =3D qemuMonitorQueryQMPSchema(mon))) + if (!(schemareply =3D qemuMonitorQueryQMPSchema(mon))) return -1; + if (!(schema =3D virQEMUQapiSchemaConvert(schemareply))) + return -1; + schemareply =3D NULL; + for (i =3D 0; i < ARRAY_CARDINALITY(virQEMUCapsQMPSchemaQueries); i++)= { entry =3D virQEMUCapsQMPSchemaQueries + i; diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 1d67a97789..e169553b7e 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4316,7 +4316,7 @@ qemuMonitorGetRTCTime(qemuMonitorPtr mon, } -virHashTablePtr +virJSONValuePtr qemuMonitorQueryQMPSchema(qemuMonitorPtr mon) { QEMU_CHECK_MONITOR_JSON_NULL(mon); diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index adfa87aba9..7a22323504 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1175,7 +1175,7 @@ int qemuMonitorMigrateContinue(qemuMonitorPtr mon, int qemuMonitorGetRTCTime(qemuMonitorPtr mon, struct tm *tm); -virHashTablePtr qemuMonitorQueryQMPSchema(qemuMonitorPtr mon); +virJSONValuePtr qemuMonitorQueryQMPSchema(qemuMonitorPtr mon); int qemuMonitorSetBlockThreshold(qemuMonitorPtr mon, const char *nodename, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 08dfffdf64..d80c4f18d1 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -7776,35 +7776,12 @@ qemuMonitorJSONGetHotpluggableCPUs(qemuMonitorPtr m= on, } -static int -qemuMonitorJSONFillQMPSchema(size_t pos ATTRIBUTE_UNUSED, - virJSONValuePtr item, - void *opaque) -{ - const char *name; - virHashTablePtr schema =3D opaque; - - if (!(name =3D virJSONValueObjectGetString(item, "name"))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("malformed QMP schema")); - return -1; - } - - if (virHashAddEntry(schema, name, item) < 0) - return -1; - - return 0; -} - - -virHashTablePtr +virJSONValuePtr qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon) { virJSONValuePtr cmd; virJSONValuePtr reply =3D NULL; - virJSONValuePtr arr; - virHashTablePtr schema =3D NULL; - virHashTablePtr ret =3D NULL; + virJSONValuePtr ret =3D NULL; if (!(cmd =3D qemuMonitorJSONMakeCommand("query-qmp-schema", NULL))) return NULL; @@ -7815,21 +7792,13 @@ qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon) if (qemuMonitorJSONCheckError(cmd, reply) < 0) goto cleanup; - arr =3D virJSONValueObjectGet(reply, "return"); - - if (!(schema =3D virHashCreate(512, virJSONValueHashFree))) - goto cleanup; - - if (virJSONValueArrayForeachSteal(arr, qemuMonitorJSONFillQMPSchema, - schema) < 0) - goto cleanup; - - VIR_STEAL_PTR(ret, schema); + if (!(ret =3D virJSONValueObjectStealArray(reply, "return"))) + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("query-qmp-schema reply is not an array")); cleanup: virJSONValueFree(cmd); virJSONValueFree(reply); - virHashFree(schema); return ret; } diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index ec243becc4..846d366b27 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -516,7 +516,7 @@ int qemuMonitorJSONGetHotpluggableCPUs(qemuMonitorPtr m= on, size_t *nentries) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); -virHashTablePtr qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon) +virJSONValuePtr qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon) ATTRIBUTE_NONNULL(1); int qemuMonitorJSONSetBlockThreshold(qemuMonitorPtr mon, diff --git a/src/qemu/qemu_qapi.c b/src/qemu/qemu_qapi.c index 0a18764ac1..e63896397f 100644 --- a/src/qemu/qemu_qapi.c +++ b/src/qemu/qemu_qapi.c @@ -185,3 +185,53 @@ virQEMUQapiSchemaPathExists(const char *query, return !!entry; } + +static int +virQEMUQapiSchemaEntryProcess(size_t pos ATTRIBUTE_UNUSED, + virJSONValuePtr item, + void *opaque) +{ + const char *name; + virHashTablePtr schema =3D opaque; + + if (!(name =3D virJSONValueObjectGetString(item, "name"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("malformed QMP schema")); + return -1; + } + + if (virHashAddEntry(schema, name, item) < 0) + return -1; + + return 0; +} + + +/** + * virQEMUQapiSchemaConvert: + * @schemareply: Schema data as returned by the qemu monitor + * + * Converts the schema into the hash-table used by the functions working w= ith + * the schema. @schemareply is consumed and freed. + */ +virHashTablePtr +virQEMUQapiSchemaConvert(virJSONValuePtr schemareply) +{ + virHashTablePtr schema; + virHashTablePtr ret =3D NULL; + + if (!(schema =3D virHashCreate(512, virJSONValueHashFree))) + goto cleanup; + + if (virJSONValueArrayForeachSteal(schemareply, + virQEMUQapiSchemaEntryProcess, + schema) < 0) + goto cleanup; + + VIR_STEAL_PTR(ret, schema); + + cleanup: + virJSONValueFree(schemareply); + virHashFree(schema); + return ret; +} diff --git a/src/qemu/qemu_qapi.h b/src/qemu/qemu_qapi.h index 7b5546eefe..b0a68bec12 100644 --- a/src/qemu/qemu_qapi.h +++ b/src/qemu/qemu_qapi.h @@ -33,4 +33,8 @@ bool virQEMUQapiSchemaPathExists(const char *query, virHashTablePtr schema); +virHashTablePtr +virQEMUQapiSchemaConvert(virJSONValuePtr schemareply); + + #endif /* __QEMU_QAPI_H__ */ --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list