/* * Human Monitor Interface commands * * Copyright IBM, Corp. 2011 * * Authors: * Anthony Liguori * * This work is licensed under the terms of the GNU GPL, version 2. See * the COPYING file in the top-level directory. * * Contributions after 2012-01-13 are licensed under the terms of the * GNU GPL, version 2 or (at your option) any later version. */ #include "qemu/osdep.h" #include "monitor/hmp.h" #include "qemu/help_option.h" #include "monitor/monitor.h" #include "qapi/error.h" #include "qapi/qapi-commands-control.h" #include "qapi/qapi-commands-misc.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" #include "qemu/cutils.h" #include "hw/intc/intc.h" bool hmp_handle_error(Monitor *mon, Error *err) { if (err) { error_reportf_err(err, "Error: "); return true; } return false; } /* * Split @str at comma. * A null @str defaults to "". */ strList *hmp_split_at_comma(const char *str) { char **split = g_strsplit(str ?: "", ",", -1); strList *res = NULL; strList **tail = &res; int i; for (i = 0; split[i]; i++) { QAPI_LIST_APPEND(tail, split[i]); } g_free(split); return res; } void hmp_info_name(Monitor *mon, const QDict *qdict) { NameInfo *info; info = qmp_query_name(NULL); if (info->name) { monitor_printf(mon, "%s\n", info->name); } qapi_free_NameInfo(info); } void hmp_info_version(Monitor *mon, const QDict *qdict) { VersionInfo *info; info = qmp_query_version(NULL); monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n", info->qemu->major, info->qemu->minor, info->qemu->micro, info->package); qapi_free_VersionInfo(info); } static int hmp_info_pic_foreach(Object *obj, void *opaque) { InterruptStatsProvider *intc; InterruptStatsProviderClass *k; Monitor *mon = opaque; if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) { intc = INTERRUPT_STATS_PROVIDER(obj); k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj); if (k->print_info) { k->print_info(intc, mon); } else { monitor_printf(mon, "Interrupt controller information not available for %s.\n", object_get_typename(obj)); } } return 0; } void hmp_info_pic(Monitor *mon, const QDict *qdict) { object_child_foreach_recursive(object_get_root(), hmp_info_pic_foreach, mon); } void hmp_quit(Monitor *mon, const QDict *qdict) { monitor_suspend(mon); qmp_quit(NULL); } void hmp_stop(Monitor *mon, const QDict *qdict) { qmp_stop(NULL); } void hmp_sync_profile(Monitor *mon, const QDict *qdict) { const char *op = qdict_get_try_str(qdict, "op"); if (op == NULL) { bool on = qsp_is_enabled(); monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off"); return; } if (!strcmp(op, "on")) { qsp_enable(); } else if (!strcmp(op, "off")) { qsp_disable(); } else if (!strcmp(op, "reset")) { qsp_reset(); } else { Error *err = NULL; error_setg(&err, QERR_INVALID_PARAMETER, op); hmp_handle_error(mon, err); } } void hmp_exit_preconfig(Monitor *mon, const QDict *qdict) { Error *err = NULL; qmp_x_exit_preconfig(&err); hmp_handle_error(mon, err); } void hmp_cpu(Monitor *mon, const QDict *qdict) { int64_t cpu_index; /* XXX: drop the monitor_set_cpu() usage when all HMP commands that use it are converted to the QAPI */ cpu_index = qdict_get_int(qdict, "index"); if (monitor_set_cpu(mon, cpu_index) < 0) { monitor_printf(mon, "invalid CPU index\n"); } } void hmp_cont(Monitor *mon, const QDict *qdict) { Error *err = NULL; qmp_cont(&err); hmp_handle_error(mon, err); } void hmp_change(Monitor *mon, const QDict *qdict) { const char *device = qdict_get_str(qdict, "device"); const char *target = qdict_get_str(qdict, "target"); const char *arg = qdict_get_try_str(qdict, "arg"); const char *read_only = qdict_get_try_str(qdict, "read-only-mode"); bool force = qdict_get_try_bool(qdict, "force", false); Error *err = NULL; #ifdef CONFIG_VNC if (strcmp(device, "vnc") == 0) { hmp_change_vnc(mon, device, target, arg, read_only, force, &err); } else #endif { hmp_change_medium(mon, device, target, arg, read_only, force, &err); } hmp_handle_error(mon, err); } void hmp_getfd(Monitor *mon, const QDict *qdict) { const char *fdname = qdict_get_str(qdict, "fdname"); Error *err = NULL; qmp_getfd(fdname, &err); hmp_handle_error(mon, err); } void hmp_closefd(Monitor *mon, const QDict *qdict) { const char *fdname = qdict_get_str(qdict, "fdname"); Error *err = NULL; qmp_closefd(fdname, &err); hmp_handle_error(mon, err); } void hmp_info_iothreads(Monitor *mon, const QDict *qdict) { IOThreadInfoList *info_list = qmp_query_iothreads(NULL); IOThreadInfoList *info; IOThreadInfo *value; for (info = info_list; info; info = info->next) { value = info->value; monitor_printf(mon, "%s:\n", value->id); monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id); monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns); monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow); monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink); monitor_printf(mon, " aio-max-batch=%" PRId64 "\n", value->aio_max_batch); } qapi_free_IOThreadInfoList(info_list); }