提交 1b21351b 编写于 作者: D Daniel P. Berrange

Move command/event capabilities detection out of QEMU monitor code

The qemuMonitorSetCapabilities() API is used to initialize the QMP
protocol capabilities. It has since been abused to initialize some
libvirt internal capabilities based on command/event existance too.
Move the latter code out into qemuCapsProbeQMP() in the QEMU
capabilities source file instead
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
上级 c25746c2
......@@ -1688,6 +1688,76 @@ const char *qemuCapsGetCanonicalMachine(qemuCapsPtr caps,
}
static int
qemuCapsProbeQMPCommands(qemuCapsPtr caps,
qemuMonitorPtr mon)
{
char **commands = NULL;
int ncommands;
size_t i;
if ((ncommands = qemuMonitorGetCommands(mon, &commands)) < 0)
return -1;
for (i = 0 ; i < ncommands ; i++) {
char *name = commands[i];
if (STREQ(name, "system_wakeup"))
qemuCapsSet(caps, QEMU_CAPS_WAKEUP);
else if (STREQ(name, "transaction"))
qemuCapsSet(caps, QEMU_CAPS_TRANSACTION);
else if (STREQ(name, "block_job_cancel"))
qemuCapsSet(caps, QEMU_CAPS_BLOCKJOB_SYNC);
else if (STREQ(name, "block-job-cancel"))
qemuCapsSet(caps, QEMU_CAPS_BLOCKJOB_ASYNC);
else if (STREQ(name, "dump-guest-memory"))
qemuCapsSet(caps, QEMU_CAPS_DUMP_GUEST_MEMORY);
VIR_FREE(name);
}
VIR_FREE(commands);
return 0;
}
static int
qemuCapsProbeQMPEvents(qemuCapsPtr caps,
qemuMonitorPtr mon)
{
char **events = NULL;
int nevents;
size_t i;
if ((nevents = qemuMonitorGetEvents(mon, &events)) < 0)
return -1;
for (i = 0 ; i < nevents ; i++) {
char *name = events[i];
if (STREQ(name, "BALLOON_CHANGE"))
qemuCapsSet(caps, QEMU_CAPS_BALLOON_EVENT);
VIR_FREE(name);
}
VIR_FREE(events);
return 0;
}
int qemuCapsProbeQMP(qemuCapsPtr caps,
qemuMonitorPtr mon)
{
VIR_DEBUG("caps=%p mon=%p", caps, mon);
if (qemuCapsProbeQMPCommands(caps, mon) < 0)
return -1;
if (qemuCapsProbeQMPEvents(caps, mon) < 0)
return -1;
return 0;
}
#define QEMU_SYSTEM_PREFIX "qemu-system-"
qemuCapsPtr qemuCapsNewForBinary(const char *binary)
......
......@@ -28,6 +28,7 @@
# include "capabilities.h"
# include "command.h"
# include "virobject.h"
# include "qemu_monitor.h"
/* Internal flags to keep track of qemu command line capabilities */
enum qemuCapsFlags {
......@@ -163,6 +164,9 @@ qemuCapsPtr qemuCapsNew(void);
qemuCapsPtr qemuCapsNewCopy(qemuCapsPtr caps);
qemuCapsPtr qemuCapsNewForBinary(const char *binary);
int qemuCapsProbeQMP(qemuCapsPtr caps,
qemuMonitorPtr mon);
void qemuCapsSet(qemuCapsPtr caps,
enum qemuCapsFlags flag) ATTRIBUTE_NONNULL(1);
......
......@@ -1126,8 +1126,7 @@ int qemuMonitorEmitBalloonChange(qemuMonitorPtr mon,
}
int qemuMonitorSetCapabilities(qemuMonitorPtr mon,
qemuCapsPtr caps)
int qemuMonitorSetCapabilities(qemuMonitorPtr mon)
{
int ret;
VIR_DEBUG("mon=%p", mon);
......@@ -1142,14 +1141,6 @@ int qemuMonitorSetCapabilities(qemuMonitorPtr mon,
ret = qemuMonitorJSONSetCapabilities(mon);
if (ret < 0)
goto cleanup;
ret = qemuMonitorJSONCheckCommands(mon, caps);
if (ret < 0)
goto cleanup;
ret = qemuMonitorJSONCheckEvents(mon, caps);
if (ret < 0)
goto cleanup;
} else {
ret = 0;
}
......
......@@ -27,7 +27,6 @@
# include "internal.h"
# include "qemu_capabilities.h"
# include "domain_conf.h"
# include "bitmap.h"
# include "virhash.h"
......@@ -155,8 +154,7 @@ qemuMonitorPtr qemuMonitorOpenFD(virDomainObjPtr vm,
void qemuMonitorClose(qemuMonitorPtr mon);
int qemuMonitorSetCapabilities(qemuMonitorPtr mon,
qemuCapsPtr caps);
int qemuMonitorSetCapabilities(qemuMonitorPtr mon);
void qemuMonitorLock(qemuMonitorPtr mon);
void qemuMonitorUnlock(qemuMonitorPtr mon);
......
......@@ -968,65 +968,6 @@ qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon)
}
/*
* Returns: 0 if human-monitor-command is not supported, +1 if
* human-monitor-command worked or -1 on failure
*/
int
qemuMonitorJSONCheckCommands(qemuMonitorPtr mon,
qemuCapsPtr caps)
{
char **commands = NULL;
int ncommands;
size_t i;
if ((ncommands = qemuMonitorJSONGetCommands(mon, &commands)) < 0)
return -1;
for (i = 0 ; i < ncommands ; i++) {
char *name = commands[i];
if (STREQ(name, "system_wakeup"))
qemuCapsSet(caps, QEMU_CAPS_WAKEUP);
else if (STREQ(name, "transaction"))
qemuCapsSet(caps, QEMU_CAPS_TRANSACTION);
else if (STREQ(name, "block_job_cancel"))
qemuCapsSet(caps, QEMU_CAPS_BLOCKJOB_SYNC);
else if (STREQ(name, "block-job-cancel"))
qemuCapsSet(caps, QEMU_CAPS_BLOCKJOB_ASYNC);
else if (STREQ(name, "dump-guest-memory"))
qemuCapsSet(caps, QEMU_CAPS_DUMP_GUEST_MEMORY);
VIR_FREE(name);
}
VIR_FREE(commands);
return 0;
}
int
qemuMonitorJSONCheckEvents(qemuMonitorPtr mon,
qemuCapsPtr caps)
{
char **events = NULL;
int nevents;
size_t i;
if ((nevents = qemuMonitorJSONGetEvents(mon, &events)) < 0)
return -1;
for (i = 0 ; i < nevents ; i++) {
char *name = events[i];
if (STREQ(name, "BALLOON_CHANGE"))
qemuCapsSet(caps, QEMU_CAPS_BALLOON_EVENT);
VIR_FREE(name);
}
VIR_FREE(events);
return 0;
}
int
qemuMonitorJSONStartCPUs(qemuMonitorPtr mon,
virConnectPtr conn ATTRIBUTE_UNUSED)
......
......@@ -42,11 +42,6 @@ int qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon,
int qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon);
int qemuMonitorJSONCheckCommands(qemuMonitorPtr mon,
qemuCapsPtr caps);
int qemuMonitorJSONCheckEvents(qemuMonitorPtr mon,
qemuCapsPtr caps);
int qemuMonitorJSONStartCPUs(qemuMonitorPtr mon,
virConnectPtr conn);
int qemuMonitorJSONStopCPUs(qemuMonitorPtr mon);
......
......@@ -1250,7 +1250,10 @@ qemuConnectMonitor(struct qemud_driver *driver, virDomainObjPtr vm)
qemuDomainObjEnterMonitorWithDriver(driver, vm);
ret = qemuMonitorSetCapabilities(priv->mon, priv->caps);
ret = qemuMonitorSetCapabilities(priv->mon);
if (ret == 0 &&
qemuCapsGet(priv->caps, QEMU_CAPS_MONITOR_JSON))
ret = qemuCapsProbeQMP(priv->caps, priv->mon);
qemuDomainObjExitMonitorWithDriver(driver, vm);
error:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册