1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-25 01:34:11 +03: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:
Peter Krempa 2018-03-20 09:29:30 +01:00
parent ab8c5fe63f
commit 38b3b20c66
7 changed files with 69 additions and 41 deletions

View File

@ -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;

View File

@ -4316,7 +4316,7 @@ qemuMonitorGetRTCTime(qemuMonitorPtr mon,
}
virHashTablePtr
virJSONValuePtr
qemuMonitorQueryQMPSchema(qemuMonitorPtr mon)
{
QEMU_CHECK_MONITOR_JSON_NULL(mon);

View File

@ -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,

View File

@ -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;
}

View File

@ -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,

View File

@ -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;
}

View File

@ -33,4 +33,8 @@ bool
virQEMUQAPISchemaPathExists(const char *query,
virHashTablePtr schema);
virHashTablePtr
virQEMUQAPISchemaConvert(virJSONValuePtr schemareply);
#endif /* __QEMU_QAPI_H__ */