mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
Add a qemuMonitorGetVersion() method for QMP query-version command
Add a new qemuMonitorGetVersion() method to support invocation of the 'query-version' JSON monitor command. No HMP equivalent is provided, since this will only be used for QEMU >= 1.2 Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
1517099c7b
commit
3dce0a829a
@ -3022,3 +3022,27 @@ int qemuMonitorSystemWakeup(qemuMonitorPtr mon)
|
||||
|
||||
return qemuMonitorJSONSystemWakeup(mon);
|
||||
}
|
||||
|
||||
int qemuMonitorGetVersion(qemuMonitorPtr mon,
|
||||
int *major,
|
||||
int *minor,
|
||||
int *micro,
|
||||
char **package)
|
||||
{
|
||||
VIR_DEBUG("mon=%p major=%p minor=%p micro=%p package=%p",
|
||||
mon, major, minor, micro, package);
|
||||
|
||||
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 qemuMonitorJSONGetVersion(mon, major, minor, micro, package);
|
||||
}
|
||||
|
@ -571,6 +571,13 @@ int qemuMonitorGetBlockIoThrottle(qemuMonitorPtr mon,
|
||||
|
||||
int qemuMonitorSystemWakeup(qemuMonitorPtr mon);
|
||||
|
||||
int qemuMonitorGetVersion(qemuMonitorPtr mon,
|
||||
int *major,
|
||||
int *minor,
|
||||
int *micro,
|
||||
char **package)
|
||||
ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
|
||||
|
||||
/**
|
||||
* When running two dd process and using <> redirection, we need a
|
||||
* shell that will not truncate files. These two strings serve that
|
||||
|
@ -3863,3 +3863,81 @@ int qemuMonitorJSONSystemWakeup(qemuMonitorPtr mon)
|
||||
virJSONValueFree(reply);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qemuMonitorJSONGetVersion(qemuMonitorPtr mon,
|
||||
int *major,
|
||||
int *minor,
|
||||
int *micro,
|
||||
char **package)
|
||||
{
|
||||
int ret;
|
||||
virJSONValuePtr cmd;
|
||||
virJSONValuePtr reply = NULL;
|
||||
virJSONValuePtr data;
|
||||
virJSONValuePtr qemu;
|
||||
|
||||
*major = *minor = *micro = 0;
|
||||
if (package)
|
||||
*package = NULL;
|
||||
|
||||
if (!(cmd = qemuMonitorJSONMakeCommand("query-version", 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-version reply was missing 'return' data"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(qemu = virJSONValueObjectGet(data, "qemu"))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("query-version reply was missing 'qemu' data"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virJSONValueObjectGetNumberInt(qemu, "major", major) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("query-version reply was missing 'major' version"));
|
||||
goto cleanup;
|
||||
}
|
||||
if (virJSONValueObjectGetNumberInt(qemu, "minor", minor) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("query-version reply was missing 'minor' version"));
|
||||
goto cleanup;
|
||||
}
|
||||
if (virJSONValueObjectGetNumberInt(qemu, "micro", micro) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("query-version reply was missing 'micro' version"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (package) {
|
||||
const char *tmp;
|
||||
if (!(tmp = virJSONValueObjectGetString(data, "package"))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("query-version reply was missing 'package' version"));
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(*package = strdup(tmp))) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
virJSONValueFree(cmd);
|
||||
virJSONValueFree(reply);
|
||||
return ret;
|
||||
}
|
||||
|
@ -283,4 +283,11 @@ int qemuMonitorJSONGetBlockIoThrottle(qemuMonitorPtr mon,
|
||||
|
||||
int qemuMonitorJSONSystemWakeup(qemuMonitorPtr mon);
|
||||
|
||||
int qemuMonitorJSONGetVersion(qemuMonitorPtr mon,
|
||||
int *major,
|
||||
int *minor,
|
||||
int *micro,
|
||||
char **package)
|
||||
ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
|
||||
|
||||
#endif /* QEMU_MONITOR_JSON_H */
|
||||
|
@ -122,6 +122,107 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
testQemuMonitorJSONGetVersion(const void *data)
|
||||
{
|
||||
virCapsPtr caps = (virCapsPtr)data;
|
||||
qemuMonitorTestPtr test = qemuMonitorTestNew(true, caps);
|
||||
int ret = -1;
|
||||
int major;
|
||||
int minor;
|
||||
int micro;
|
||||
char *package;
|
||||
|
||||
if (!test)
|
||||
return -1;
|
||||
|
||||
if (qemuMonitorTestAddItem(test, "query-version",
|
||||
"{ "
|
||||
" \"return\":{ "
|
||||
" \"qemu\":{ "
|
||||
" \"major\":1, "
|
||||
" \"minor\":2, "
|
||||
" \"micro\":3 "
|
||||
" },"
|
||||
" \"package\":\"\""
|
||||
" }"
|
||||
"}") < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuMonitorTestAddItem(test, "query-version",
|
||||
"{ "
|
||||
" \"return\":{ "
|
||||
" \"qemu\":{ "
|
||||
" \"major\":0, "
|
||||
" \"minor\":11, "
|
||||
" \"micro\":6 "
|
||||
" },"
|
||||
" \"package\":\"2.283.el6\""
|
||||
" }"
|
||||
"}") < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuMonitorGetVersion(qemuMonitorTestGetMonitor(test),
|
||||
&major, &minor, µ,
|
||||
&package) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (major != 1) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"Major %d was not 1", major);
|
||||
goto cleanup;
|
||||
}
|
||||
if (minor != 2) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"Minor %d was not 2", major);
|
||||
goto cleanup;
|
||||
}
|
||||
if (micro != 3) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"Micro %d was not 3", major);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (STRNEQ(package, "")) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"Package %s was not ''", package);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (qemuMonitorGetVersion(qemuMonitorTestGetMonitor(test),
|
||||
&major, &minor, µ,
|
||||
&package) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (major != 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"Major %d was not 0", major);
|
||||
goto cleanup;
|
||||
}
|
||||
if (minor != 11) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"Minor %d was not 11", major);
|
||||
goto cleanup;
|
||||
}
|
||||
if (micro != 6) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"Micro %d was not 6", major);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (STRNEQ(package, "2.283.el6")) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"Package %s was not '2.283.el6'", package);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
qemuMonitorTestFree(test);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
mymain(void)
|
||||
{
|
||||
@ -141,6 +242,7 @@ mymain(void)
|
||||
ret = -1
|
||||
|
||||
DO_TEST(GetStatus);
|
||||
DO_TEST(GetVersion);
|
||||
|
||||
virCapabilitiesFree(caps);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user