extern "C" {
# endif
+enum {
+ VIR_DOMAIN_QEMU_MONITOR_COMMAND_DEFAULT = 0,
+ VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP = (1 << 0), /* cmd is in HMP */
+} virDomainQemuMonitorCommandFlags;
+
int virDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd,
char **result, unsigned int flags);
# define N_(str) str
# include "libvirt/libvirt.h"
+# include "libvirt/libvirt-qemu.h"
# include "libvirt/virterror.h"
# include "libvirt_internal.h"
virDomainObjPtr vm = NULL;
int ret = -1;
qemuDomainObjPrivatePtr priv;
+ bool hmp;
- virCheckFlags(0, -1);
+ virCheckFlags(VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP, -1);
qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
priv->monitor_warned = 1;
}
+ hmp = !!(flags & VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP);
+
if (qemuDomainObjBeginJobWithDriver(driver, vm) < 0)
goto cleanup;
qemuDomainObjEnterMonitorWithDriver(driver, vm);
- ret = qemuMonitorArbitraryCommand(priv->mon, cmd, result);
+ ret = qemuMonitorArbitraryCommand(priv->mon, cmd, result, hmp);
qemuDomainObjExitMonitorWithDriver(driver, vm);
if (qemuDomainObjEndJob(vm) == 0) {
vm = NULL;
return ret;
}
-int qemuMonitorArbitraryCommand(qemuMonitorPtr mon, const char *cmd, char **reply)
+int qemuMonitorArbitraryCommand(qemuMonitorPtr mon,
+ const char *cmd,
+ char **reply,
+ bool hmp)
{
int ret;
- DEBUG("mon=%p, cmd=%s, reply=%p", mon, cmd, reply);
+ DEBUG("mon=%p, cmd=%s, reply=%p, hmp=%d", mon, cmd, reply, hmp);
if (mon->json)
- ret = qemuMonitorJSONArbitraryCommand(mon, cmd, reply);
+ ret = qemuMonitorJSONArbitraryCommand(mon, cmd, reply, hmp);
else
ret = qemuMonitorTextArbitraryCommand(mon, cmd, reply);
return ret;
int qemuMonitorLoadSnapshot(qemuMonitorPtr mon, const char *name);
int qemuMonitorDeleteSnapshot(qemuMonitorPtr mon, const char *name);
-int qemuMonitorArbitraryCommand(qemuMonitorPtr mon, const char *cmd, char **reply);
+int qemuMonitorArbitraryCommand(qemuMonitorPtr mon,
+ const char *cmd,
+ char **reply,
+ bool hmp);
/**
* When running two dd process and using <> redirection, we need a
int qemuMonitorJSONArbitraryCommand(qemuMonitorPtr mon,
const char *cmd_str,
- char **reply_str)
+ char **reply_str,
+ bool hmp)
{
virJSONValuePtr cmd = NULL;
virJSONValuePtr reply = NULL;
int ret = -1;
- cmd = virJSONValueFromString(cmd_str);
+ if (!hmp) {
+ cmd = virJSONValueFromString(cmd_str);
+ } else {
+ cmd = qemuMonitorJSONMakeCommand("human-monitor-command",
+ "s:command-line", cmd_str,
+ NULL);
+ }
+
if (!cmd)
return -1;
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- *reply_str = virJSONValueToString(reply);
- if (!(*reply_str))
+ if (!hmp) {
+ if (!(*reply_str = virJSONValueToString(reply)))
+ goto cleanup;
+ } else if (qemuMonitorJSONCheckError(cmd, reply)) {
goto cleanup;
+ } else {
+ const char *data;
+ if (!(data = virJSONValueObjectGetString(reply, "return"))) {
+ qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("human monitor command was missing return data"));
+ goto cleanup;
+ }
+ if (!(*reply_str = strdup(data))) {
+ virReportOOMError();
+ goto cleanup;
+ }
+ }
ret = 0;
int qemuMonitorJSONArbitraryCommand(qemuMonitorPtr mon,
const char *cmd_str,
- char **reply_str);
+ char **reply_str,
+ bool hmp);
#endif /* QEMU_MONITOR_JSON_H */
static const vshCmdOptDef opts_qemu_monitor_command[] = {
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
{"cmd", VSH_OT_DATA, VSH_OFLAG_REQ, N_("command")},
+ {"hmp", VSH_OT_BOOL, 0, N_("command is in human monitor protocol")},
{NULL, 0, 0, NULL}
};
int ret = FALSE;
char *monitor_cmd;
char *result = NULL;
+ unsigned int flags = 0;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
goto cleanup;
}
- if (virDomainQemuMonitorCommand(dom, monitor_cmd, &result, 0) < 0)
+ if (vshCommandOptBool(cmd, "hmp"))
+ flags |= VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP;
+
+ if (virDomainQemuMonitorCommand(dom, monitor_cmd, &result, flags) < 0)
goto cleanup;
printf("%s\n", result);
=over 4
-=item B<qemu-monitor-command> I<domain> I<command>
+=item B<qemu-monitor-command> I<domain> I<command> optional I<--hmp>
Send an arbitrary monitor command I<command> to domain I<domain> through the
-qemu monitor. The results of the command will be printed on stdout.
+qemu monitor. The results of the command will be printed on stdout. If
+I<--hmp> is passed, the command is considered to be a human monitor command
+and libvirt will automatically convert it into QMP if needed. In that case
+the result will also be converted back from QMP.
=back