qemu: Set capabilities based on supported monitor commands

In the future (my next patch in fact) we may want to make
decisions depending on qemu having a monitor command or not.
Therefore, we want to set qemuCaps flag instead of querying
on the monitor each time we are about to make that decision.
This commit is contained in:
Michal Privoznik 2012-02-13 12:19:24 +01:00
parent c95c90ee4a
commit 2f1e003939
7 changed files with 29 additions and 20 deletions

View File

@ -152,6 +152,7 @@ VIR_ENUM_IMPL(qemuCaps, QEMU_CAPS_LAST,
"fsdev-writeout", "fsdev-writeout",
"drive-iotune", /* 85 */ "drive-iotune", /* 85 */
"system_wakeup",
); );
struct qemu_feature_flags { struct qemu_feature_flags {

View File

@ -120,6 +120,7 @@ enum qemuCapsFlags {
QEMU_CAPS_CPU_HOST = 83, /* support for -cpu host */ QEMU_CAPS_CPU_HOST = 83, /* support for -cpu host */
QEMU_CAPS_FSDEV_WRITEOUT = 84, /* -fsdev writeout supported */ QEMU_CAPS_FSDEV_WRITEOUT = 84, /* -fsdev writeout supported */
QEMU_CAPS_DRIVE_IOTUNE = 85, /* -drive bps= and friends */ QEMU_CAPS_DRIVE_IOTUNE = 85, /* -drive bps= and friends */
QEMU_CAPS_WAKEUP = 86, /* system_wakeup monitor command */
QEMU_CAPS_LAST, /* this must always be the last item */ QEMU_CAPS_LAST, /* this must always be the last item */
}; };

View File

@ -996,9 +996,11 @@ int qemuMonitorEmitBlockJob(qemuMonitorPtr mon,
int qemuMonitorSetCapabilities(qemuMonitorPtr mon) int qemuMonitorSetCapabilities(qemuMonitorPtr mon,
virBitmapPtr qemuCaps)
{ {
int ret; int ret;
int json_hmp;
VIR_DEBUG("mon=%p", mon); VIR_DEBUG("mon=%p", mon);
if (!mon) { if (!mon) {
@ -1009,19 +1011,16 @@ int qemuMonitorSetCapabilities(qemuMonitorPtr mon)
if (mon->json) { if (mon->json) {
ret = qemuMonitorJSONSetCapabilities(mon); ret = qemuMonitorJSONSetCapabilities(mon);
if (ret == 0) { if (ret)
int hmp = qemuMonitorJSONCheckHMP(mon); goto cleanup;
if (hmp < 0) {
/* qemu may quited unexpectedly when we call ret = qemuMonitorJSONCheckCommands(mon, qemuCaps, &json_hmp);
* qemuMonitorJSONCheckHMP() */ mon->json_hmp = json_hmp > 0;
ret = -1;
} else {
mon->json_hmp = hmp > 0;
}
}
} else { } else {
ret = 0; ret = 0;
} }
cleanup:
return ret; return ret;
} }

View File

@ -29,6 +29,7 @@
# include "domain_conf.h" # include "domain_conf.h"
# include "qemu_conf.h" # include "qemu_conf.h"
# include "bitmap.h"
# include "virhash.h" # include "virhash.h"
typedef struct _qemuMonitor qemuMonitor; typedef struct _qemuMonitor qemuMonitor;
@ -135,7 +136,8 @@ qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm,
void qemuMonitorClose(qemuMonitorPtr mon); void qemuMonitorClose(qemuMonitorPtr mon);
int qemuMonitorSetCapabilities(qemuMonitorPtr mon); int qemuMonitorSetCapabilities(qemuMonitorPtr mon,
virBitmapPtr qemuCaps);
int qemuMonitorCheckHMP(qemuMonitorPtr mon, const char *cmd); int qemuMonitorCheckHMP(qemuMonitorPtr mon, const char *cmd);

View File

@ -34,6 +34,7 @@
#include "qemu_monitor_text.h" #include "qemu_monitor_text.h"
#include "qemu_monitor_json.h" #include "qemu_monitor_json.h"
#include "qemu_command.h" #include "qemu_command.h"
#include "qemu_capabilities.h"
#include "memory.h" #include "memory.h"
#include "logging.h" #include "logging.h"
#include "driver.h" #include "driver.h"
@ -800,7 +801,9 @@ qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon)
* human-monitor-command worked or -1 on failure * human-monitor-command worked or -1 on failure
*/ */
int int
qemuMonitorJSONCheckHMP(qemuMonitorPtr mon) qemuMonitorJSONCheckCommands(qemuMonitorPtr mon,
virBitmapPtr qemuCaps,
int *json_hmp)
{ {
int ret = -1; int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-commands", NULL); virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-commands", NULL);
@ -828,13 +831,13 @@ qemuMonitorJSONCheckHMP(qemuMonitorPtr mon)
!(name = virJSONValueObjectGetString(entry, "name"))) !(name = virJSONValueObjectGetString(entry, "name")))
goto cleanup; goto cleanup;
if (STREQ(name, "human-monitor-command")) { if (STREQ(name, "human-monitor-command"))
ret = 1; *json_hmp = 1;
goto cleanup;
} if (STREQ(name, "system_wakeup"))
qemuCapsSet(qemuCaps, QEMU_CAPS_WAKEUP);
} }
/* human-monitor-command is not supported */
ret = 0; ret = 0;
cleanup: cleanup:

View File

@ -28,6 +28,7 @@
# include "internal.h" # include "internal.h"
# include "qemu_monitor.h" # include "qemu_monitor.h"
# include "bitmap.h"
int qemuMonitorJSONIOProcess(qemuMonitorPtr mon, int qemuMonitorJSONIOProcess(qemuMonitorPtr mon,
const char *data, const char *data,
@ -41,7 +42,9 @@ int qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon,
int qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon); int qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon);
int qemuMonitorJSONCheckHMP(qemuMonitorPtr mon); int qemuMonitorJSONCheckCommands(qemuMonitorPtr mon,
virBitmapPtr qemuCaps,
int *json_hmp);
int qemuMonitorJSONStartCPUs(qemuMonitorPtr mon, int qemuMonitorJSONStartCPUs(qemuMonitorPtr mon,
virConnectPtr conn); virConnectPtr conn);

View File

@ -1086,7 +1086,7 @@ qemuConnectMonitor(struct qemud_driver *driver, virDomainObjPtr vm)
qemuDomainObjEnterMonitorWithDriver(driver, vm); qemuDomainObjEnterMonitorWithDriver(driver, vm);
ret = qemuMonitorSetCapabilities(priv->mon); ret = qemuMonitorSetCapabilities(priv->mon, priv->qemuCaps);
qemuDomainObjExitMonitorWithDriver(driver, vm); qemuDomainObjExitMonitorWithDriver(driver, vm);
error: error: