mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
Add a qemuMonitorGetEvents() method for QMP query-events command
Add a new qemuMonitorGetEvents() method to support invocation of the 'query-events' JSON monitor command. No HMP equivalent is required, since this will only be used when JSON is available The existing qemuMonitorJSONCheckEvents() method is refactored to use this new method Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
c70a6154b6
commit
3b565d3f46
@ -3119,3 +3119,25 @@ int qemuMonitorGetCommands(qemuMonitorPtr mon,
|
|||||||
|
|
||||||
return qemuMonitorJSONGetCommands(mon, commands);
|
return qemuMonitorJSONGetCommands(mon, commands);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int qemuMonitorGetEvents(qemuMonitorPtr mon,
|
||||||
|
char ***events)
|
||||||
|
{
|
||||||
|
VIR_DEBUG("mon=%p events=%p",
|
||||||
|
mon, events);
|
||||||
|
|
||||||
|
if (!mon) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||||
|
_("monitor must not be NULL"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mon->json) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
|
_("JSON monitor is required"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return qemuMonitorJSONGetEvents(mon, events);
|
||||||
|
}
|
||||||
|
@ -598,6 +598,8 @@ int qemuMonitorGetCPUDefinitions(qemuMonitorPtr mon,
|
|||||||
|
|
||||||
int qemuMonitorGetCommands(qemuMonitorPtr mon,
|
int qemuMonitorGetCommands(qemuMonitorPtr mon,
|
||||||
char ***commands);
|
char ***commands);
|
||||||
|
int qemuMonitorGetEvents(qemuMonitorPtr mon,
|
||||||
|
char ***events);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1007,49 +1007,23 @@ int
|
|||||||
qemuMonitorJSONCheckEvents(qemuMonitorPtr mon,
|
qemuMonitorJSONCheckEvents(qemuMonitorPtr mon,
|
||||||
qemuCapsPtr caps)
|
qemuCapsPtr caps)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
char **events = NULL;
|
||||||
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-events", NULL);
|
int nevents;
|
||||||
virJSONValuePtr reply = NULL;
|
size_t i;
|
||||||
virJSONValuePtr data;
|
|
||||||
int i, n;
|
|
||||||
|
|
||||||
if (!cmd)
|
if ((nevents = qemuMonitorJSONGetEvents(mon, &events)) < 0)
|
||||||
return ret;
|
return -1;
|
||||||
|
|
||||||
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
for (i = 0 ; i < nevents ; i++) {
|
||||||
goto cleanup;
|
char *name = events[i];
|
||||||
|
|
||||||
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
|
||||||
ret = 0;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (!(data = virJSONValueObjectGet(reply, "return")) ||
|
|
||||||
data->type != VIR_JSON_TYPE_ARRAY ||
|
|
||||||
(n = virJSONValueArraySize(data)) <= 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
virJSONValuePtr entry;
|
|
||||||
const char *name;
|
|
||||||
|
|
||||||
if (!(entry = virJSONValueArrayGet(data, i)) ||
|
|
||||||
!(name = virJSONValueObjectGetString(entry, "name")))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (STREQ(name, "BALLOON_CHANGE"))
|
if (STREQ(name, "BALLOON_CHANGE"))
|
||||||
qemuCapsSet(caps, QEMU_CAPS_BALLOON_EVENT);
|
qemuCapsSet(caps, QEMU_CAPS_BALLOON_EVENT);
|
||||||
|
VIR_FREE(name);
|
||||||
}
|
}
|
||||||
|
VIR_FREE(events);
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virJSONValueFree(cmd);
|
|
||||||
virJSONValueFree(reply);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -4170,3 +4144,77 @@ cleanup:
|
|||||||
virJSONValueFree(reply);
|
virJSONValueFree(reply);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int qemuMonitorJSONGetEvents(qemuMonitorPtr mon,
|
||||||
|
char ***events)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
virJSONValuePtr cmd;
|
||||||
|
virJSONValuePtr reply = NULL;
|
||||||
|
virJSONValuePtr data;
|
||||||
|
char **eventlist = NULL;
|
||||||
|
int n = 0;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
*events = NULL;
|
||||||
|
|
||||||
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-events", NULL)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
ret = qemuMonitorJSONCommand(mon, cmd, &reply);
|
||||||
|
|
||||||
|
if (ret == 0)
|
||||||
|
ret = qemuMonitorJSONCheckError(cmd, reply);
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
|
if (!(data = virJSONValueObjectGet(reply, "return"))) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("query-events reply was missing return data"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((n = virJSONValueArraySize(data)) < 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("query-events reply data was not an array"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VIR_ALLOC_N(eventlist, n) < 0) {
|
||||||
|
virReportOOMError();
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0 ; i < n ; i++) {
|
||||||
|
virJSONValuePtr child = virJSONValueArrayGet(data, i);
|
||||||
|
const char *tmp;
|
||||||
|
|
||||||
|
if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("query-events reply data was missing 'name'"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(eventlist[i] = strdup(tmp))) {
|
||||||
|
virReportOOMError();
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = n;
|
||||||
|
*events = eventlist;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if (ret < 0 && eventlist) {
|
||||||
|
for (i = 0 ; i < n ; i++)
|
||||||
|
VIR_FREE(eventlist[i]);
|
||||||
|
VIR_FREE(eventlist);
|
||||||
|
}
|
||||||
|
virJSONValueFree(cmd);
|
||||||
|
virJSONValueFree(reply);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -301,5 +301,8 @@ int qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
|
|||||||
int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
|
int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
|
||||||
char ***commands)
|
char ***commands)
|
||||||
ATTRIBUTE_NONNULL(2);
|
ATTRIBUTE_NONNULL(2);
|
||||||
|
int qemuMonitorJSONGetEvents(qemuMonitorPtr mon,
|
||||||
|
char ***events)
|
||||||
|
ATTRIBUTE_NONNULL(2);
|
||||||
|
|
||||||
#endif /* QEMU_MONITOR_JSON_H */
|
#endif /* QEMU_MONITOR_JSON_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user