2 * Human Monitor Interface commands
4 * Copyright IBM, Corp. 2011
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
16 #include "qemu/osdep.h"
17 #include "monitor/hmp.h"
18 #include "qemu/help_option.h"
19 #include "monitor/monitor.h"
20 #include "qapi/error.h"
21 #include "qapi/qapi-commands-control.h"
22 #include "qapi/qapi-commands-misc.h"
23 #include "qapi/qmp/qdict.h"
24 #include "qapi/qmp/qerror.h"
25 #include "qemu/cutils.h"
26 #include "hw/intc/intc.h"
28 bool hmp_handle_error(Monitor
*mon
, Error
*err
)
31 error_reportf_err(err
, "Error: ");
38 * Split @str at comma.
39 * A null @str defaults to "".
41 strList
*hmp_split_at_comma(const char *str
)
43 char **split
= g_strsplit(str
?: "", ",", -1);
45 strList
**tail
= &res
;
48 for (i
= 0; split
[i
]; i
++) {
49 QAPI_LIST_APPEND(tail
, split
[i
]);
56 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
60 info
= qmp_query_name(NULL
);
62 monitor_printf(mon
, "%s\n", info
->name
);
64 qapi_free_NameInfo(info
);
67 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
71 info
= qmp_query_version(NULL
);
73 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
74 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
77 qapi_free_VersionInfo(info
);
80 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
82 InterruptStatsProvider
*intc
;
83 InterruptStatsProviderClass
*k
;
84 Monitor
*mon
= opaque
;
86 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
87 intc
= INTERRUPT_STATS_PROVIDER(obj
);
88 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
90 k
->print_info(intc
, mon
);
92 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
93 object_get_typename(obj
));
100 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
102 object_child_foreach_recursive(object_get_root(),
103 hmp_info_pic_foreach
, mon
);
106 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
108 monitor_suspend(mon
);
112 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
117 void hmp_sync_profile(Monitor
*mon
, const QDict
*qdict
)
119 const char *op
= qdict_get_try_str(qdict
, "op");
122 bool on
= qsp_is_enabled();
124 monitor_printf(mon
, "sync-profile is %s\n", on
? "on" : "off");
127 if (!strcmp(op
, "on")) {
129 } else if (!strcmp(op
, "off")) {
131 } else if (!strcmp(op
, "reset")) {
136 error_setg(&err
, QERR_INVALID_PARAMETER
, op
);
137 hmp_handle_error(mon
, err
);
141 void hmp_exit_preconfig(Monitor
*mon
, const QDict
*qdict
)
145 qmp_x_exit_preconfig(&err
);
146 hmp_handle_error(mon
, err
);
149 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
153 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
154 use it are converted to the QAPI */
155 cpu_index
= qdict_get_int(qdict
, "index");
156 if (monitor_set_cpu(mon
, cpu_index
) < 0) {
157 monitor_printf(mon
, "invalid CPU index\n");
161 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
166 hmp_handle_error(mon
, err
);
169 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
171 const char *device
= qdict_get_str(qdict
, "device");
172 const char *target
= qdict_get_str(qdict
, "target");
173 const char *arg
= qdict_get_try_str(qdict
, "arg");
174 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
175 bool force
= qdict_get_try_bool(qdict
, "force", false);
179 if (strcmp(device
, "vnc") == 0) {
180 hmp_change_vnc(mon
, device
, target
, arg
, read_only
, force
, &err
);
184 hmp_change_medium(mon
, device
, target
, arg
, read_only
, force
, &err
);
187 hmp_handle_error(mon
, err
);
190 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
192 const char *fdname
= qdict_get_str(qdict
, "fdname");
195 qmp_getfd(fdname
, &err
);
196 hmp_handle_error(mon
, err
);
199 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
201 const char *fdname
= qdict_get_str(qdict
, "fdname");
204 qmp_closefd(fdname
, &err
);
205 hmp_handle_error(mon
, err
);
208 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
210 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
211 IOThreadInfoList
*info
;
214 for (info
= info_list
; info
; info
= info
->next
) {
216 monitor_printf(mon
, "%s:\n", value
->id
);
217 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
218 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
219 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
220 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
221 monitor_printf(mon
, " aio-max-batch=%" PRId64
"\n",
222 value
->aio_max_batch
);
225 qapi_free_IOThreadInfoList(info_list
);