mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
qemu: monitor: Move processing of QMP schema to the new file
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 <pkrempa@redhat.com>
This commit is contained in:
parent
ab8c5fe63f
commit
38b3b20c66
@ -4570,12 +4570,17 @@ virQEMUCapsProbeQMPSchemaCapabilities(virQEMUCapsPtr qemuCaps,
|
||||
qemuMonitorPtr mon)
|
||||
{
|
||||
struct virQEMUCapsStringFlags *entry;
|
||||
virHashTablePtr schema;
|
||||
virJSONValuePtr schemareply;
|
||||
virHashTablePtr schema = NULL;
|
||||
size_t i;
|
||||
|
||||
if (!(schema = qemuMonitorQueryQMPSchema(mon)))
|
||||
if (!(schemareply = qemuMonitorQueryQMPSchema(mon)))
|
||||
return -1;
|
||||
|
||||
if (!(schema = virQEMUQAPISchemaConvert(schemareply)))
|
||||
return -1;
|
||||
schemareply = NULL;
|
||||
|
||||
for (i = 0; i < ARRAY_CARDINALITY(virQEMUCapsQMPSchemaQueries); i++) {
|
||||
entry = virQEMUCapsQMPSchemaQueries + i;
|
||||
|
||||
|
@ -4316,7 +4316,7 @@ qemuMonitorGetRTCTime(qemuMonitorPtr mon,
|
||||
}
|
||||
|
||||
|
||||
virHashTablePtr
|
||||
virJSONValuePtr
|
||||
qemuMonitorQueryQMPSchema(qemuMonitorPtr mon)
|
||||
{
|
||||
QEMU_CHECK_MONITOR_JSON_NULL(mon);
|
||||
|
@ -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,
|
||||
|
@ -7776,35 +7776,12 @@ qemuMonitorJSONGetHotpluggableCPUs(qemuMonitorPtr mon,
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
qemuMonitorJSONFillQMPSchema(size_t pos ATTRIBUTE_UNUSED,
|
||||
virJSONValuePtr item,
|
||||
void *opaque)
|
||||
{
|
||||
const char *name;
|
||||
virHashTablePtr schema = opaque;
|
||||
|
||||
if (!(name = 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 = NULL;
|
||||
virJSONValuePtr arr;
|
||||
virHashTablePtr schema = NULL;
|
||||
virHashTablePtr ret = NULL;
|
||||
virJSONValuePtr ret = NULL;
|
||||
|
||||
if (!(cmd = qemuMonitorJSONMakeCommand("query-qmp-schema", NULL)))
|
||||
return NULL;
|
||||
@ -7815,21 +7792,13 @@ qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon)
|
||||
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
||||
goto cleanup;
|
||||
|
||||
arr = virJSONValueObjectGet(reply, "return");
|
||||
|
||||
if (!(schema = virHashCreate(512, virJSONValueHashFree)))
|
||||
goto cleanup;
|
||||
|
||||
if (virJSONValueArrayForeachSteal(arr, qemuMonitorJSONFillQMPSchema,
|
||||
schema) < 0)
|
||||
goto cleanup;
|
||||
|
||||
VIR_STEAL_PTR(ret, schema);
|
||||
if (!(ret = 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;
|
||||
}
|
||||
|
@ -516,7 +516,7 @@ int qemuMonitorJSONGetHotpluggableCPUs(qemuMonitorPtr mon,
|
||||
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,
|
||||
|
@ -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 = opaque;
|
||||
|
||||
if (!(name = 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 with
|
||||
* the schema. @schemareply is consumed and freed.
|
||||
*/
|
||||
virHashTablePtr
|
||||
virQEMUQAPISchemaConvert(virJSONValuePtr schemareply)
|
||||
{
|
||||
virHashTablePtr schema;
|
||||
virHashTablePtr ret = NULL;
|
||||
|
||||
if (!(schema = 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;
|
||||
}
|
||||
|
@ -33,4 +33,8 @@ bool
|
||||
virQEMUQAPISchemaPathExists(const char *query,
|
||||
virHashTablePtr schema);
|
||||
|
||||
virHashTablePtr
|
||||
virQEMUQAPISchemaConvert(virJSONValuePtr schemareply);
|
||||
|
||||
|
||||
#endif /* __QEMU_QAPI_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user