Support for JSON mode monitor

Initial support for the new QEMU monitor protocol  using JSON
as the data encoding format instead of plain text

* po/POTFILES.in: Add src/qemu/qemu_monitor_json.c
* src/qemu/qemu_conf.c, src/qemu/qemu_conf.h: Hack to turn on QMP
  mode. Replace with a version number check on >= 0.12 later
* src/qemu/qemu_monitor.c: Delegate to json monitor if enabled
* src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h: Add
  impl of QMP protocol
* src/Makefile.am: Add src/qemu/qemu_monitor_json.{c,h}
This commit is contained in:
Daniel P. Berrange 2009-11-03 13:59:18 -05:00
parent c5358c0e1f
commit 3a4f172fdd
10 changed files with 1829 additions and 50 deletions

View File

@ -29,6 +29,7 @@ src/qemu/qemu_bridge_filter.c
src/qemu/qemu_conf.c src/qemu/qemu_conf.c
src/qemu/qemu_driver.c src/qemu/qemu_driver.c
src/qemu/qemu_monitor.c src/qemu/qemu_monitor.c
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_text.c src/qemu/qemu_monitor_text.c
src/remote/remote_driver.c src/remote/remote_driver.c
src/secret/secret_driver.c src/secret/secret_driver.c

View File

@ -189,7 +189,9 @@ QEMU_DRIVER_SOURCES = \
qemu/qemu_monitor.c qemu/qemu_monitor.h \ qemu/qemu_monitor.c qemu/qemu_monitor.h \
qemu/qemu_monitor_text.c \ qemu/qemu_monitor_text.c \
qemu/qemu_monitor_text.h \ qemu/qemu_monitor_text.h \
qemu/qemu_driver.c qemu/qemu_driver.h \ qemu/qemu_monitor_json.c \
qemu/qemu_monitor_json.h \
qemu/qemu_driver.c qemu/qemu_driver.h \
qemu/qemu_bridge_filter.c \ qemu/qemu_bridge_filter.c \
qemu/qemu_bridge_filter.h qemu/qemu_bridge_filter.h

View File

@ -942,6 +942,9 @@ static unsigned int qemudComputeCmdFlags(const char *help,
if (version >= 10000) if (version >= 10000)
flags |= QEMUD_CMD_FLAG_0_10; flags |= QEMUD_CMD_FLAG_0_10;
if (version >= 12000)
flags |= QEMUD_CMD_FLAG_0_12;
return flags; return flags;
} }
@ -1584,6 +1587,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
struct qemud_driver *driver, struct qemud_driver *driver,
virDomainDefPtr def, virDomainDefPtr def,
virDomainChrDefPtr monitor_chr, virDomainChrDefPtr monitor_chr,
int monitor_json,
unsigned int qemuCmdFlags, unsigned int qemuCmdFlags,
const char ***retargv, const char ***retargv,
const char ***retenv, const char ***retenv,
@ -1858,6 +1862,9 @@ int qemudBuildCommandLine(virConnectPtr conn,
if (monitor_chr) { if (monitor_chr) {
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
if (monitor_json)
virBufferAddLit(&buf, "control,");
qemudBuildCommandLineChrDevStr(monitor_chr, &buf); qemudBuildCommandLineChrDevStr(monitor_chr, &buf);
if (virBufferError(&buf)) if (virBufferError(&buf))
goto error; goto error;

View File

@ -74,6 +74,8 @@ enum qemud_cmd_flags {
QEMUD_CMD_FLAG_MIGRATE_QEMU_UNIX = (1 << 21), /* Does qemu support unix domain sockets for migration? */ QEMUD_CMD_FLAG_MIGRATE_QEMU_UNIX = (1 << 21), /* Does qemu support unix domain sockets for migration? */
QEMUD_CMD_FLAG_CHARDEV = (1 << 22), /* Is the new -chardev arg available */ QEMUD_CMD_FLAG_CHARDEV = (1 << 22), /* Is the new -chardev arg available */
QEMUD_CMD_FLAG_ENABLE_KVM = (1 << 23), /* Is the -enable-kvm flag available to "enable KVM full virtualization support" */ QEMUD_CMD_FLAG_ENABLE_KVM = (1 << 23), /* Is the -enable-kvm flag available to "enable KVM full virtualization support" */
QEMUD_CMD_FLAG_0_12 = (1 << 24),
QEMUD_CMD_FLAG_MONITOR_JSON = QEMUD_CMD_FLAG_0_12, /* JSON mode for monitor */
}; };
/* Main driver state */ /* Main driver state */
@ -168,6 +170,7 @@ int qemudBuildCommandLine (virConnectPtr conn,
struct qemud_driver *driver, struct qemud_driver *driver,
virDomainDefPtr def, virDomainDefPtr def,
virDomainChrDefPtr monitor_chr, virDomainChrDefPtr monitor_chr,
int monitor_json,
unsigned int qemuCmdFlags, unsigned int qemuCmdFlags,
const char ***retargv, const char ***retargv,
const char ***retenv, const char ***retenv,

View File

@ -87,6 +87,7 @@ struct _qemuDomainObjPrivate {
qemuMonitorPtr mon; qemuMonitorPtr mon;
virDomainChrDefPtr monConfig; virDomainChrDefPtr monConfig;
int monJSON;
int nvcpupids; int nvcpupids;
int *vcpupids; int *vcpupids;
@ -173,6 +174,8 @@ static int qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void *data)
} }
virBufferEscapeString(buf, " <monitor path='%s'", monitorpath); virBufferEscapeString(buf, " <monitor path='%s'", monitorpath);
if (priv->monJSON)
virBufferAddLit(buf, " json='1'");
virBufferVSprintf(buf, " type='%s'/>\n", virBufferVSprintf(buf, " type='%s'/>\n",
virDomainChrTypeToString(priv->monConfig->type)); virDomainChrTypeToString(priv->monConfig->type));
} }
@ -217,6 +220,9 @@ static int qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, void *data)
priv->monConfig->type = VIR_DOMAIN_CHR_TYPE_PTY; priv->monConfig->type = VIR_DOMAIN_CHR_TYPE_PTY;
VIR_FREE(tmp); VIR_FREE(tmp);
if (virXPathBoolean(NULL, "int(./monitor[1]/@json)", ctxt))
priv->monJSON = 1;
switch (priv->monConfig->type) { switch (priv->monConfig->type) {
case VIR_DOMAIN_CHR_TYPE_PTY: case VIR_DOMAIN_CHR_TYPE_PTY:
priv->monConfig->data.file.path = monitorpath; priv->monConfig->data.file.path = monitorpath;
@ -799,6 +805,7 @@ qemuConnectMonitor(virDomainObjPtr vm)
if ((priv->mon = qemuMonitorOpen(vm, if ((priv->mon = qemuMonitorOpen(vm,
priv->monConfig, priv->monConfig,
priv->monJSON,
qemuHandleMonitorEOF)) == NULL) { qemuHandleMonitorEOF)) == NULL) {
VIR_ERROR(_("Failed to connect monitor for %s\n"), vm->def->name); VIR_ERROR(_("Failed to connect monitor for %s\n"), vm->def->name);
return -1; return -1;
@ -2347,6 +2354,11 @@ static int qemudStartVMDaemon(virConnectPtr conn,
if (qemuPrepareMonitorChr(conn, driver, priv->monConfig, vm->def->name) < 0) if (qemuPrepareMonitorChr(conn, driver, priv->monConfig, vm->def->name) < 0)
goto cleanup; goto cleanup;
#if HAVE_YAJL
if (qemuCmdFlags & QEMUD_CMD_FLAG_MONITOR_JSON)
priv->monJSON = 1;
#endif
if ((ret = virFileDeletePid(driver->stateDir, vm->def->name)) != 0) { if ((ret = virFileDeletePid(driver->stateDir, vm->def->name)) != 0) {
virReportSystemError(conn, ret, virReportSystemError(conn, ret,
_("Cannot remove stale PID file for %s"), _("Cannot remove stale PID file for %s"),
@ -2362,7 +2374,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
vm->def->id = driver->nextvmid++; vm->def->id = driver->nextvmid++;
if (qemudBuildCommandLine(conn, driver, vm->def, priv->monConfig, if (qemudBuildCommandLine(conn, driver, vm->def, priv->monConfig,
qemuCmdFlags, &argv, &progenv, priv->monJSON, qemuCmdFlags, &argv, &progenv,
&tapfds, &ntapfds, migrateFrom) < 0) &tapfds, &ntapfds, migrateFrom) < 0)
goto cleanup; goto cleanup;
@ -4437,7 +4449,7 @@ static char *qemuDomainXMLToNative(virConnectPtr conn,
goto cleanup; goto cleanup;
if (qemudBuildCommandLine(conn, driver, def, if (qemudBuildCommandLine(conn, driver, def,
&monConfig, qemuCmdFlags, &monConfig, 0, qemuCmdFlags,
&retargv, &retenv, &retargv, &retenv,
NULL, NULL, /* Don't want it to create TAP devices */ NULL, NULL, /* Don't want it to create TAP devices */
NULL) < 0) { NULL) < 0) {

View File

@ -30,6 +30,7 @@
#include "qemu_monitor.h" #include "qemu_monitor.h"
#include "qemu_monitor_text.h" #include "qemu_monitor_text.h"
#include "qemu_monitor_json.h"
#include "qemu_conf.h" #include "qemu_conf.h"
#include "event.h" #include "event.h"
#include "virterror_internal.h" #include "virterror_internal.h"
@ -72,6 +73,7 @@ struct _qemuMonitor {
/* If the monitor is in process of shutting down */ /* If the monitor is in process of shutting down */
unsigned closed: 1; unsigned closed: 1;
unsigned json: 1;
}; };
@ -282,9 +284,14 @@ qemuMonitorIOProcess(qemuMonitorPtr mon)
msg = mon->msg; msg = mon->msg;
VIR_DEBUG("Process %d", (int)mon->bufferOffset); VIR_DEBUG("Process %d", (int)mon->bufferOffset);
len = qemuMonitorTextIOProcess(mon, if (mon->json)
mon->buffer, mon->bufferOffset, len = qemuMonitorJSONIOProcess(mon,
msg); mon->buffer, mon->bufferOffset,
msg);
else
len = qemuMonitorTextIOProcess(mon,
mon->buffer, mon->bufferOffset,
msg);
if (len < 0) { if (len < 0) {
mon->lastErrno = errno; mon->lastErrno = errno;
@ -528,6 +535,7 @@ qemuMonitorIO(int watch, int fd, int events, void *opaque) {
qemuMonitorPtr qemuMonitorPtr
qemuMonitorOpen(virDomainObjPtr vm, qemuMonitorOpen(virDomainObjPtr vm,
virDomainChrDefPtr config, virDomainChrDefPtr config,
int json,
qemuMonitorEOFNotify eofCB) qemuMonitorEOFNotify eofCB)
{ {
qemuMonitorPtr mon; qemuMonitorPtr mon;
@ -554,6 +562,7 @@ qemuMonitorOpen(virDomainObjPtr vm,
mon->refs = 1; mon->refs = 1;
mon->vm = vm; mon->vm = vm;
mon->eofCB = eofCB; mon->eofCB = eofCB;
mon->json = json;
qemuMonitorLock(mon); qemuMonitorLock(mon);
switch (config->type) { switch (config->type) {
@ -692,43 +701,68 @@ int
qemuMonitorStartCPUs(qemuMonitorPtr mon, qemuMonitorStartCPUs(qemuMonitorPtr mon,
virConnectPtr conn) virConnectPtr conn)
{ {
int ret;
DEBUG("mon=%p, fd=%d", mon, mon->fd); DEBUG("mon=%p, fd=%d", mon, mon->fd);
return qemuMonitorTextStartCPUs(mon, conn); if (mon->json)
ret = qemuMonitorJSONStartCPUs(mon, conn);
else
ret = qemuMonitorTextStartCPUs(mon, conn);
return ret;
} }
int int
qemuMonitorStopCPUs(qemuMonitorPtr mon) qemuMonitorStopCPUs(qemuMonitorPtr mon)
{ {
int ret;
DEBUG("mon=%p, fd=%d", mon, mon->fd); DEBUG("mon=%p, fd=%d", mon, mon->fd);
return qemuMonitorTextStopCPUs(mon); if (mon->json)
ret = qemuMonitorJSONStopCPUs(mon);
else
ret = qemuMonitorTextStopCPUs(mon);
return ret;
} }
int qemuMonitorSystemPowerdown(qemuMonitorPtr mon) int qemuMonitorSystemPowerdown(qemuMonitorPtr mon)
{ {
int ret;
DEBUG("mon=%p, fd=%d", mon, mon->fd); DEBUG("mon=%p, fd=%d", mon, mon->fd);
return qemuMonitorTextSystemPowerdown(mon); if (mon->json)
ret = qemuMonitorJSONSystemPowerdown(mon);
else
ret = qemuMonitorTextSystemPowerdown(mon);
return ret;
} }
int qemuMonitorGetCPUInfo(qemuMonitorPtr mon, int qemuMonitorGetCPUInfo(qemuMonitorPtr mon,
int **pids) int **pids)
{ {
int ret;
DEBUG("mon=%p, fd=%d", mon, mon->fd); DEBUG("mon=%p, fd=%d", mon, mon->fd);
return qemuMonitorTextGetCPUInfo(mon, pids); if (mon->json)
ret = qemuMonitorJSONGetCPUInfo(mon, pids);
else
ret = qemuMonitorTextGetCPUInfo(mon, pids);
return ret;
} }
int qemuMonitorGetBalloonInfo(qemuMonitorPtr mon, int qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
unsigned long *currmem) unsigned long *currmem)
{ {
int ret;
DEBUG("mon=%p, fd=%d", mon, mon->fd); DEBUG("mon=%p, fd=%d", mon, mon->fd);
return qemuMonitorTextGetBalloonInfo(mon, currmem); if (mon->json)
ret = qemuMonitorJSONGetBalloonInfo(mon, currmem);
else
ret = qemuMonitorTextGetBalloonInfo(mon, currmem);
return ret;
} }
@ -740,38 +774,61 @@ int qemuMonitorGetBlockStatsInfo(qemuMonitorPtr mon,
long long *wr_bytes, long long *wr_bytes,
long long *errs) long long *errs)
{ {
int ret;
DEBUG("mon=%p, fd=%d dev=%s", mon, mon->fd, devname); DEBUG("mon=%p, fd=%d dev=%s", mon, mon->fd, devname);
return qemuMonitorTextGetBlockStatsInfo(mon, devname, if (mon->json)
rd_req, rd_bytes, ret = qemuMonitorJSONGetBlockStatsInfo(mon, devname,
wr_req, wr_bytes, rd_req, rd_bytes,
errs); wr_req, wr_bytes,
errs);
else
ret = qemuMonitorTextGetBlockStatsInfo(mon, devname,
rd_req, rd_bytes,
wr_req, wr_bytes,
errs);
return ret;
} }
int qemuMonitorSetVNCPassword(qemuMonitorPtr mon, int qemuMonitorSetVNCPassword(qemuMonitorPtr mon,
const char *password) const char *password)
{ {
int ret;
DEBUG("mon=%p, fd=%d", mon, mon->fd); DEBUG("mon=%p, fd=%d", mon, mon->fd);
return qemuMonitorTextSetVNCPassword(mon, password); if (mon->json)
ret = qemuMonitorJSONSetVNCPassword(mon, password);
else
ret = qemuMonitorTextSetVNCPassword(mon, password);
return ret;
} }
int qemuMonitorSetBalloon(qemuMonitorPtr mon, int qemuMonitorSetBalloon(qemuMonitorPtr mon,
unsigned long newmem) unsigned long newmem)
{ {
int ret;
DEBUG("mon=%p, fd=%d newmem=%lu", mon, mon->fd, newmem); DEBUG("mon=%p, fd=%d newmem=%lu", mon, mon->fd, newmem);
return qemuMonitorTextSetBalloon(mon, newmem); if (mon->json)
ret = qemuMonitorJSONSetBalloon(mon, newmem);
else
ret = qemuMonitorTextSetBalloon(mon, newmem);
return ret;
} }
int qemuMonitorEjectMedia(qemuMonitorPtr mon, int qemuMonitorEjectMedia(qemuMonitorPtr mon,
const char *devname) const char *devname)
{ {
int ret;
DEBUG("mon=%p, fd=%d devname=%s", mon, mon->fd, devname); DEBUG("mon=%p, fd=%d devname=%s", mon, mon->fd, devname);
return qemuMonitorTextEjectMedia(mon, devname); if (mon->json)
ret = qemuMonitorJSONEjectMedia(mon, devname);
else
ret = qemuMonitorTextEjectMedia(mon, devname);
return ret;
} }
@ -780,10 +837,15 @@ int qemuMonitorChangeMedia(qemuMonitorPtr mon,
const char *newmedia, const char *newmedia,
const char *format) const char *format)
{ {
int ret;
DEBUG("mon=%p, fd=%d devname=%s newmedia=%s format=%s", DEBUG("mon=%p, fd=%d devname=%s newmedia=%s format=%s",
mon, mon->fd, devname, newmedia, format); mon, mon->fd, devname, newmedia, format);
return qemuMonitorTextChangeMedia(mon, devname, newmedia, format); if (mon->json)
ret = qemuMonitorJSONChangeMedia(mon, devname, newmedia, format);
else
ret = qemuMonitorTextChangeMedia(mon, devname, newmedia, format);
return ret;
} }
@ -792,10 +854,15 @@ int qemuMonitorSaveVirtualMemory(qemuMonitorPtr mon,
size_t length, size_t length,
const char *path) const char *path)
{ {
int ret;
DEBUG("mon=%p, fd=%d offset=%llu length=%zu path=%s", DEBUG("mon=%p, fd=%d offset=%llu length=%zu path=%s",
mon, mon->fd, offset, length, path); mon, mon->fd, offset, length, path);
return qemuMonitorTextSaveVirtualMemory(mon, offset, length, path); if (mon->json)
ret = qemuMonitorJSONSaveVirtualMemory(mon, offset, length, path);
else
ret = qemuMonitorTextSaveVirtualMemory(mon, offset, length, path);
return ret;
} }
int qemuMonitorSavePhysicalMemory(qemuMonitorPtr mon, int qemuMonitorSavePhysicalMemory(qemuMonitorPtr mon,
@ -803,19 +870,29 @@ int qemuMonitorSavePhysicalMemory(qemuMonitorPtr mon,
size_t length, size_t length,
const char *path) const char *path)
{ {
int ret;
DEBUG("mon=%p, fd=%d offset=%llu length=%zu path=%s", DEBUG("mon=%p, fd=%d offset=%llu length=%zu path=%s",
mon, mon->fd, offset, length, path); mon, mon->fd, offset, length, path);
return qemuMonitorTextSavePhysicalMemory(mon, offset, length, path); if (mon->json)
ret = qemuMonitorJSONSavePhysicalMemory(mon, offset, length, path);
else
ret = qemuMonitorTextSavePhysicalMemory(mon, offset, length, path);
return ret;
} }
int qemuMonitorSetMigrationSpeed(qemuMonitorPtr mon, int qemuMonitorSetMigrationSpeed(qemuMonitorPtr mon,
unsigned long bandwidth) unsigned long bandwidth)
{ {
int ret;
DEBUG("mon=%p, fd=%d bandwidth=%lu", mon, mon->fd, bandwidth); DEBUG("mon=%p, fd=%d bandwidth=%lu", mon, mon->fd, bandwidth);
return qemuMonitorTextSetMigrationSpeed(mon, bandwidth); if (mon->json)
ret = qemuMonitorJSONSetMigrationSpeed(mon, bandwidth);
else
ret = qemuMonitorTextSetMigrationSpeed(mon, bandwidth);
return ret;
} }
int qemuMonitorGetMigrationStatus(qemuMonitorPtr mon, int qemuMonitorGetMigrationStatus(qemuMonitorPtr mon,
@ -824,12 +901,20 @@ int qemuMonitorGetMigrationStatus(qemuMonitorPtr mon,
unsigned long long *remaining, unsigned long long *remaining,
unsigned long long *total) unsigned long long *total)
{ {
int ret;
DEBUG("mon=%p, fd=%d", mon, mon->fd); DEBUG("mon=%p, fd=%d", mon, mon->fd);
return qemuMonitorTextGetMigrationStatus(mon, status, if (mon->json)
transferred, ret = qemuMonitorJSONGetMigrationStatus(mon, status,
remaining, transferred,
total); remaining,
total);
else
ret = qemuMonitorTextGetMigrationStatus(mon, status,
transferred,
remaining,
total);
return ret;
} }
@ -838,10 +923,15 @@ int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
const char *hostname, const char *hostname,
int port) int port)
{ {
int ret;
DEBUG("mon=%p, fd=%d hostname=%s port=%d", DEBUG("mon=%p, fd=%d hostname=%s port=%d",
mon, mon->fd, hostname, port); mon, mon->fd, hostname, port);
return qemuMonitorTextMigrateToHost(mon, background, hostname, port); if (mon->json)
ret = qemuMonitorJSONMigrateToHost(mon, background, hostname, port);
else
ret = qemuMonitorTextMigrateToHost(mon, background, hostname, port);
return ret;
} }
@ -850,35 +940,55 @@ int qemuMonitorMigrateToCommand(qemuMonitorPtr mon,
const char * const *argv, const char * const *argv,
const char *target) const char *target)
{ {
int ret;
DEBUG("mon=%p, fd=%d argv=%p target=%s", DEBUG("mon=%p, fd=%d argv=%p target=%s",
mon, mon->fd, argv, target); mon, mon->fd, argv, target);
return qemuMonitorTextMigrateToCommand(mon, background, argv, target); if (mon->json)
ret = qemuMonitorJSONMigrateToCommand(mon, background, argv, target);
else
ret = qemuMonitorTextMigrateToCommand(mon, background, argv, target);
return ret;
} }
int qemuMonitorMigrateToUnix(qemuMonitorPtr mon, int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
int background, int background,
const char *unixfile) const char *unixfile)
{ {
int ret;
DEBUG("mon=%p fd=%d unixfile=%s", DEBUG("mon=%p fd=%d unixfile=%s",
mon, mon->fd, unixfile); mon, mon->fd, unixfile);
return qemuMonitorTextMigrateToUnix(mon, background, unixfile); if (mon->json)
ret = qemuMonitorJSONMigrateToUnix(mon, background, unixfile);
else
ret = qemuMonitorTextMigrateToUnix(mon, background, unixfile);
return ret;
} }
int qemuMonitorMigrateCancel(qemuMonitorPtr mon) int qemuMonitorMigrateCancel(qemuMonitorPtr mon)
{ {
int ret;
DEBUG("mon=%p fd=%d", mon, mon->fd); DEBUG("mon=%p fd=%d", mon, mon->fd);
return qemuMonitorTextMigrateCancel(mon); if (mon->json)
ret = qemuMonitorJSONMigrateCancel(mon);
else
ret = qemuMonitorTextMigrateCancel(mon);
return ret;
} }
int qemuMonitorAddUSBDisk(qemuMonitorPtr mon, int qemuMonitorAddUSBDisk(qemuMonitorPtr mon,
const char *path) const char *path)
{ {
int ret;
DEBUG("mon=%p, fd=%d path=%s", mon, mon->fd, path); DEBUG("mon=%p, fd=%d path=%s", mon, mon->fd, path);
return qemuMonitorTextAddUSBDisk(mon, path); if (mon->json)
ret = qemuMonitorJSONAddUSBDisk(mon, path);
else
ret = qemuMonitorTextAddUSBDisk(mon, path);
return ret;
} }
@ -886,19 +996,29 @@ int qemuMonitorAddUSBDeviceExact(qemuMonitorPtr mon,
int bus, int bus,
int dev) int dev)
{ {
int ret;
DEBUG("mon=%p, fd=%d bus=%d dev=%d", mon, mon->fd, bus, dev); DEBUG("mon=%p, fd=%d bus=%d dev=%d", mon, mon->fd, bus, dev);
return qemuMonitorTextAddUSBDeviceExact(mon, bus, dev); if (mon->json)
ret = qemuMonitorJSONAddUSBDeviceExact(mon, bus, dev);
else
ret = qemuMonitorTextAddUSBDeviceExact(mon, bus, dev);
return ret;
} }
int qemuMonitorAddUSBDeviceMatch(qemuMonitorPtr mon, int qemuMonitorAddUSBDeviceMatch(qemuMonitorPtr mon,
int vendor, int vendor,
int product) int product)
{ {
int ret;
DEBUG("mon=%p, fd=%d vendor=%d product=%d", DEBUG("mon=%p, fd=%d vendor=%d product=%d",
mon, mon->fd, vendor, product); mon, mon->fd, vendor, product);
return qemuMonitorTextAddUSBDeviceMatch(mon, vendor, product); if (mon->json)
ret = qemuMonitorJSONAddUSBDeviceMatch(mon, vendor, product);
else
ret = qemuMonitorTextAddUSBDeviceMatch(mon, vendor, product);
return ret;
} }
@ -911,16 +1031,26 @@ int qemuMonitorAddPCIHostDevice(qemuMonitorPtr mon,
unsigned *guestBus, unsigned *guestBus,
unsigned *guestSlot) unsigned *guestSlot)
{ {
int ret;
DEBUG("mon=%p, fd=%d domain=%d bus=%d slot=%d function=%d", DEBUG("mon=%p, fd=%d domain=%d bus=%d slot=%d function=%d",
mon, mon->fd, mon, mon->fd,
hostDomain, hostBus, hostSlot, hostFunction); hostDomain, hostBus, hostSlot, hostFunction);
return qemuMonitorTextAddPCIHostDevice(mon, hostDomain, if (mon->json)
hostBus, hostSlot, ret = qemuMonitorJSONAddPCIHostDevice(mon, hostDomain,
hostFunction, hostBus, hostSlot,
guestDomain, hostFunction,
guestBus, guestDomain,
guestSlot); guestBus,
guestSlot);
else
ret = qemuMonitorTextAddPCIHostDevice(mon, hostDomain,
hostBus, hostSlot,
hostFunction,
guestDomain,
guestBus,
guestSlot);
return ret;
} }
@ -931,11 +1061,17 @@ int qemuMonitorAddPCIDisk(qemuMonitorPtr mon,
unsigned *guestBus, unsigned *guestBus,
unsigned *guestSlot) unsigned *guestSlot)
{ {
int ret;
DEBUG("mon=%p, fd=%d path=%s bus=%s", DEBUG("mon=%p, fd=%d path=%s bus=%s",
mon, mon->fd, path, bus); mon, mon->fd, path, bus);
return qemuMonitorTextAddPCIDisk(mon, path, bus, if (mon->json)
guestDomain, guestBus, guestSlot); ret = qemuMonitorJSONAddPCIDisk(mon, path, bus,
guestDomain, guestBus, guestSlot);
else
ret = qemuMonitorTextAddPCIDisk(mon, path, bus,
guestDomain, guestBus, guestSlot);
return ret;
} }
@ -945,10 +1081,16 @@ int qemuMonitorAddPCINetwork(qemuMonitorPtr mon,
unsigned *guestBus, unsigned *guestBus,
unsigned *guestSlot) unsigned *guestSlot)
{ {
int ret;
DEBUG("mon=%p, fd=%d nicstr=%s", mon, mon->fd, nicstr); DEBUG("mon=%p, fd=%d nicstr=%s", mon, mon->fd, nicstr);
return qemuMonitorTextAddPCINetwork(mon, nicstr, guestDomain, if (mon->json)
guestBus, guestSlot); ret = qemuMonitorJSONAddPCINetwork(mon, nicstr, guestDomain,
guestBus, guestSlot);
else
ret = qemuMonitorTextAddPCINetwork(mon, nicstr, guestDomain,
guestBus, guestSlot);
return ret;
} }
@ -957,11 +1099,17 @@ int qemuMonitorRemovePCIDevice(qemuMonitorPtr mon,
unsigned guestBus, unsigned guestBus,
unsigned guestSlot) unsigned guestSlot)
{ {
int ret;
DEBUG("mon=%p, fd=%d domain=%d bus=%d slot=%d", DEBUG("mon=%p, fd=%d domain=%d bus=%d slot=%d",
mon, mon->fd, guestDomain, guestBus, guestSlot); mon, mon->fd, guestDomain, guestBus, guestSlot);
return qemuMonitorTextRemovePCIDevice(mon, guestDomain, if (mon->json)
guestBus, guestSlot); ret = qemuMonitorJSONRemovePCIDevice(mon, guestDomain,
guestBus, guestSlot);
else
ret = qemuMonitorTextRemovePCIDevice(mon, guestDomain,
guestBus, guestSlot);
return ret;
} }
@ -969,30 +1117,45 @@ int qemuMonitorSendFileHandle(qemuMonitorPtr mon,
const char *fdname, const char *fdname,
int fd) int fd)
{ {
int ret;
DEBUG("mon=%p, fd=%d fdname=%s fd=%d", DEBUG("mon=%p, fd=%d fdname=%s fd=%d",
mon, mon->fd, fdname, fd); mon, mon->fd, fdname, fd);
return qemuMonitorTextSendFileHandle(mon, fdname, fd); if (mon->json)
ret = qemuMonitorJSONSendFileHandle(mon, fdname, fd);
else
ret = qemuMonitorTextSendFileHandle(mon, fdname, fd);
return ret;
} }
int qemuMonitorCloseFileHandle(qemuMonitorPtr mon, int qemuMonitorCloseFileHandle(qemuMonitorPtr mon,
const char *fdname) const char *fdname)
{ {
int ret;
DEBUG("mon=%p, fd=%d fdname=%s", DEBUG("mon=%p, fd=%d fdname=%s",
mon, mon->fd, fdname); mon, mon->fd, fdname);
return qemuMonitorTextCloseFileHandle(mon, fdname); if (mon->json)
ret = qemuMonitorJSONCloseFileHandle(mon, fdname);
else
ret = qemuMonitorTextCloseFileHandle(mon, fdname);
return ret;
} }
int qemuMonitorAddHostNetwork(qemuMonitorPtr mon, int qemuMonitorAddHostNetwork(qemuMonitorPtr mon,
const char *netstr) const char *netstr)
{ {
int ret;
DEBUG("mon=%p, fd=%d netstr=%s", DEBUG("mon=%p, fd=%d netstr=%s",
mon, mon->fd, netstr); mon, mon->fd, netstr);
return qemuMonitorTextAddHostNetwork(mon, netstr); if (mon->json)
ret = qemuMonitorJSONAddHostNetwork(mon, netstr);
else
ret = qemuMonitorTextAddHostNetwork(mon, netstr);
return ret;
} }
@ -1000,8 +1163,13 @@ int qemuMonitorRemoveHostNetwork(qemuMonitorPtr mon,
int vlan, int vlan,
const char *netname) const char *netname)
{ {
int ret;
DEBUG("mon=%p, fd=%d netname=%s", DEBUG("mon=%p, fd=%d netname=%s",
mon, mon->fd, netname); mon, mon->fd, netname);
return qemuMonitorTextRemoveHostNetwork(mon, vlan, netname); if (mon->json)
ret = qemuMonitorJSONRemoveHostNetwork(mon, vlan, netname);
else
ret = qemuMonitorTextRemoveHostNetwork(mon, vlan, netname);
return ret;
} }

View File

@ -80,6 +80,7 @@ char *qemuMonitorEscapeShell(const char *in);
qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm, qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm,
virDomainChrDefPtr config, virDomainChrDefPtr config,
int json,
qemuMonitorEOFNotify eofCB); qemuMonitorEOFNotify eofCB);
int qemuMonitorClose(qemuMonitorPtr mon); int qemuMonitorClose(qemuMonitorPtr mon);
@ -132,6 +133,9 @@ int qemuMonitorSetBalloon(qemuMonitorPtr mon,
/* XXX should we pass the virDomainDiskDefPtr instead /* XXX should we pass the virDomainDiskDefPtr instead
* and hide devname details inside monitor. Reconsider * and hide devname details inside monitor. Reconsider
* this when doing the QMP implementation * this when doing the QMP implementation
*
* XXXX 'eject' has gained a 'force' flag we might like
* to make use of...
*/ */
int qemuMonitorEjectMedia(qemuMonitorPtr mon, int qemuMonitorEjectMedia(qemuMonitorPtr mon,
const char *devname); const char *devname);

1426
src/qemu/qemu_monitor_json.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,156 @@
/*
* qemu_monitor_json.h: interaction with QEMU monitor console
*
* Copyright (C) 2006-2009 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Daniel P. Berrange <berrange@redhat.com>
*/
#ifndef QEMU_MONITOR_JSON_H
#define QEMU_MONITOR_JSON_H
#include "internal.h"
#include "qemu_monitor.h"
int qemuMonitorJSONIOProcess(qemuMonitorPtr mon,
const char *data,
size_t len,
qemuMonitorMessagePtr msg);
int qemuMonitorJSONStartCPUs(qemuMonitorPtr mon,
virConnectPtr conn);
int qemuMonitorJSONStopCPUs(qemuMonitorPtr mon);
int qemuMonitorJSONSystemPowerdown(qemuMonitorPtr mon);
int qemuMonitorJSONGetCPUInfo(qemuMonitorPtr mon,
int **pids);
int qemuMonitorJSONGetBalloonInfo(qemuMonitorPtr mon,
unsigned long *currmem);
int qemuMonitorJSONGetBlockStatsInfo(qemuMonitorPtr mon,
const char *devname,
long long *rd_req,
long long *rd_bytes,
long long *wr_req,
long long *wr_bytes,
long long *errs);
int qemuMonitorJSONSetVNCPassword(qemuMonitorPtr mon,
const char *password);
int qemuMonitorJSONSetBalloon(qemuMonitorPtr mon,
unsigned long newmem);
int qemuMonitorJSONEjectMedia(qemuMonitorPtr mon,
const char *devname);
int qemuMonitorJSONChangeMedia(qemuMonitorPtr mon,
const char *devname,
const char *newmedia,
const char *format);
int qemuMonitorJSONSaveVirtualMemory(qemuMonitorPtr mon,
unsigned long long offset,
size_t length,
const char *path);
int qemuMonitorJSONSavePhysicalMemory(qemuMonitorPtr mon,
unsigned long long offset,
size_t length,
const char *path);
int qemuMonitorJSONSetMigrationSpeed(qemuMonitorPtr mon,
unsigned long bandwidth);
int qemuMonitorJSONGetMigrationStatus(qemuMonitorPtr mon,
int *status,
unsigned long long *transferred,
unsigned long long *remaining,
unsigned long long *total);
int qemuMonitorJSONMigrateToHost(qemuMonitorPtr mon,
int background,
const char *hostname,
int port);
int qemuMonitorJSONMigrateToCommand(qemuMonitorPtr mon,
int background,
const char * const *argv,
const char *target);
int qemuMonitorJSONMigrateToUnix(qemuMonitorPtr mon,
int background,
const char *unixfile);
int qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon);
int qemuMonitorJSONAddUSBDisk(qemuMonitorPtr mon,
const char *path);
int qemuMonitorJSONAddUSBDeviceExact(qemuMonitorPtr mon,
int bus,
int dev);
int qemuMonitorJSONAddUSBDeviceMatch(qemuMonitorPtr mon,
int vendor,
int product);
int qemuMonitorJSONAddPCIHostDevice(qemuMonitorPtr mon,
unsigned hostDomain,
unsigned hostBus,
unsigned hostSlot,
unsigned hostFunction,
unsigned *guestDomain,
unsigned *guestBus,
unsigned *guestSlot);
int qemuMonitorJSONAddPCIDisk(qemuMonitorPtr mon,
const char *path,
const char *bus,
unsigned *guestDomain,
unsigned *guestBus,
unsigned *guestSlot);
int qemuMonitorJSONAddPCINetwork(qemuMonitorPtr mon,
const char *nicstr,
unsigned *guestDomain,
unsigned *guestBus,
unsigned *guestSlot);
int qemuMonitorJSONRemovePCIDevice(qemuMonitorPtr mon,
unsigned guestDomain,
unsigned guestBus,
unsigned guestSlot);
int qemuMonitorJSONSendFileHandle(qemuMonitorPtr mon,
const char *fdname,
int fd);
int qemuMonitorJSONCloseFileHandle(qemuMonitorPtr mon,
const char *fdname);
int qemuMonitorJSONAddHostNetwork(qemuMonitorPtr mon,
const char *netstr);
int qemuMonitorJSONRemoveHostNetwork(qemuMonitorPtr mon,
int vlan,
const char *netname);
#endif /* QEMU_MONITOR_JSON_H */

View File

@ -60,7 +60,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
goto fail; goto fail;
if (qemudBuildCommandLine(NULL, &driver, if (qemudBuildCommandLine(NULL, &driver,
vmdef, &monitor_chr, flags, vmdef, &monitor_chr, 0, flags,
&argv, &qenv, &argv, &qenv,
NULL, NULL, migrateFrom) < 0) NULL, NULL, migrateFrom) < 0)
goto fail; goto fail;