static void monitor_read_command(Monitor *mon, int show_prompt)
{
+ if (!mon->rs)
+ return;
+
readline_start(mon->rs, "(qemu) ", 0, monitor_command_cb, NULL);
if (show_prompt)
readline_show_prompt(mon->rs);
{
char c;
- if (!mon)
- return;
-
for(;;) {
c = *str++;
if (c == '\0')
void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
{
+ if (!mon)
+ return;
+
if (mon->mc && !mon->mc->print_enabled) {
qemu_error_new(QERR_UNDEFINED_ERROR);
} else {
qobject_incref(data);
qdict_put_obj(qmp, "return", data);
} else {
- qdict_put(qmp, "return", qstring_from_str("OK"));
+ /* return an empty QDict by default */
+ qdict_put(qmp, "return", qdict_new());
}
} else {
/* error response */
{
QDict *qmp;
const char *event_name;
- Monitor *mon = cur_mon;
+ Monitor *mon;
assert(event < QEVENT_MAX);
- if (!monitor_ctrl_mode(mon))
- return;
-
switch (event) {
case QEVENT_DEBUG:
event_name = "DEBUG";
qmp = qdict_new();
timestamp_put(qmp);
qdict_put(qmp, "event", qstring_from_str(event_name));
- if (data)
+ if (data) {
+ qobject_incref(data);
qdict_put_obj(qmp, "data", data);
+ }
- monitor_json_emitter(mon, QOBJECT(qmp));
+ QLIST_FOREACH(mon, &mon_list, entry) {
+ if (monitor_ctrl_mode(mon)) {
+ monitor_json_emitter(mon, QOBJECT(qmp));
+ }
+ }
QDECREF(qmp);
}
}
#endif
-static void do_info_uuid(Monitor *mon)
+static void do_info_uuid_print(Monitor *mon, const QObject *data)
{
- monitor_printf(mon, UUID_FMT "\n", qemu_uuid[0], qemu_uuid[1],
+ monitor_printf(mon, "%s\n", qdict_get_str(qobject_to_qdict(data), "UUID"));
+}
+
+/**
+ * do_info_uuid(): Show VM UUID
+ *
+ * Return a QDict with the following information:
+ *
+ * - "UUID": Universally Unique Identifier
+ *
+ * Example:
+ *
+ * { "UUID": "550e8400-e29b-41d4-a716-446655440000" }
+ */
+static void do_info_uuid(Monitor *mon, QObject **ret_data)
+{
+ char uuid[64];
+
+ snprintf(uuid, sizeof(uuid), UUID_FMT, qemu_uuid[0], qemu_uuid[1],
qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5],
qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9],
qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13],
qemu_uuid[14], qemu_uuid[15]);
+ *ret_data = qobject_from_jsonf("{ 'UUID': %s }", uuid);
}
/* get the current CPU defined by the user */
{
BlockDriverState *bs;
int force = qdict_get_int(qdict, "force");
- const char *filename = qdict_get_str(qdict, "filename");
+ const char *filename = qdict_get_str(qdict, "device");
bs = bdrv_find(filename);
if (!bs) {
vm_running, singlestep);
}
+static ram_addr_t balloon_get_value(void)
+{
+ ram_addr_t actual;
+
+ if (kvm_enabled() && !kvm_has_sync_mmu()) {
+ qemu_error_new(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
+ return 0;
+ }
+
+ actual = qemu_balloon_status();
+ if (actual == 0) {
+ qemu_error_new(QERR_DEVICE_NOT_ACTIVE, "balloon");
+ return 0;
+ }
+
+ return actual;
+}
+
/**
* do_balloon(): Request VM to change its memory allocation
*/
static void do_balloon(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
- int value = qdict_get_int(qdict, "value");
- ram_addr_t target = value;
- qemu_balloon(target << 20);
+ if (balloon_get_value()) {
+ /* ballooning is active */
+ qemu_balloon(qdict_get_int(qdict, "value"));
+ }
}
static void monitor_print_balloon(Monitor *mon, const QObject *data)
{
ram_addr_t actual;
- actual = qemu_balloon_status();
- if (kvm_enabled() && !kvm_has_sync_mmu())
- qemu_error_new(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
- else if (actual == 0)
- qemu_error_new(QERR_DEVICE_NOT_ACTIVE, "balloon");
- else
+ actual = balloon_get_value();
+ if (actual != 0) {
*ret_data = qobject_from_jsonf("{ 'balloon': %" PRId64 "}",
(int64_t) actual);
+ }
}
static qemu_acl *find_acl(Monitor *mon, const char *name)
.args_type = "",
.params = "",
.help = "show the character devices",
- .mhandler.info = qemu_chr_info,
+ .user_print = qemu_chr_info_print,
+ .mhandler.info_new = qemu_chr_info,
},
{
.name = "block",
.args_type = "",
.params = "",
.help = "show the block devices",
- .mhandler.info = bdrv_info,
+ .user_print = bdrv_info_print,
+ .mhandler.info_new = bdrv_info,
},
{
.name = "blockstats",
.args_type = "",
.params = "",
.help = "show block device statistics",
- .mhandler.info = bdrv_info_stats,
+ .user_print = bdrv_stats_print,
+ .mhandler.info_new = bdrv_info_stats,
},
{
.name = "registers",
.args_type = "",
.params = "",
.help = "show which guest mouse is receiving events",
- .mhandler.info = do_info_mice,
+ .user_print = do_info_mice_print,
+ .mhandler.info_new = do_info_mice,
},
{
.name = "vnc",
.args_type = "",
.params = "",
.help = "show the vnc server status",
- .mhandler.info = do_info_vnc,
+ .user_print = do_info_vnc_print,
+ .mhandler.info_new = do_info_vnc,
},
{
.name = "name",
.args_type = "",
.params = "",
.help = "show the current VM UUID",
- .mhandler.info = do_info_uuid,
+ .user_print = do_info_uuid_print,
+ .mhandler.info_new = do_info_uuid,
},
#if defined(TARGET_PPC)
{
.args_type = "",
.params = "",
.help = "show migration status",
- .mhandler.info = do_info_migrate,
+ .user_print = do_info_migrate_print,
+ .mhandler.info_new = do_info_migrate,
},
{
.name = "balloon",
break;
case 'i':
case 'l':
+ case 'M':
{
int64_t val;
monitor_printf(mon, "\'%s\' has failed: ", cmdname);
monitor_printf(mon, "integer is for 32-bit values\n");
goto fail;
+ } else if (c == 'M') {
+ val <<= 20;
}
qdict_put(qdict, key, qint_from_int(val));
}
{
Monitor *mon = opaque;
- return (mon->suspend_cnt == 0) ? 128 : 0;
+ return (mon->suspend_cnt == 0) ? 1 : 0;
}
typedef struct CmdArgs {
}
case 'i':
case 'l':
+ case 'M':
if (qobject_type(value) != QTYPE_QINT) {
qemu_error_new(QERR_INVALID_PARAMETER_TYPE, name, "int");
return -1;
qobject_from_jsonf("{ 'item': %s }", info_item));
} else {
cmd = monitor_find_command(cmd_name);
- if (!cmd) {
+ if (!cmd || !monitor_handler_ported(cmd)) {
qemu_error_new(QERR_COMMAND_NOT_FOUND, cmd_name);
goto err_input;
}