]>
Commit | Line | Data |
---|---|---|
48a32bed | 1 | /* |
f1b3ccfa | 2 | * Human Monitor Interface commands |
48a32bed AL |
3 | * |
4 | * Copyright IBM, Corp. 2011 | |
5 | * | |
6 | * Authors: | |
7 | * Anthony Liguori <aliguori@us.ibm.com> | |
8 | * | |
9 | * This work is licensed under the terms of the GNU GPL, version 2. See | |
10 | * the COPYING file in the top-level directory. | |
11 | * | |
6b620ca3 PB |
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. | |
48a32bed AL |
14 | */ |
15 | ||
d38ea87a | 16 | #include "qemu/osdep.h" |
275307aa | 17 | #include "monitor/hmp.h" |
1422e32d | 18 | #include "net/net.h" |
fafa4d50 | 19 | #include "net/eth.h" |
8228e353 | 20 | #include "chardev/char.h" |
4c7b7e9b | 21 | #include "sysemu/block-backend.h" |
54d31236 | 22 | #include "sysemu/runstate.h" |
213dcb06 | 23 | #include "qemu/config-file.h" |
1de7afc9 PB |
24 | #include "qemu/option.h" |
25 | #include "qemu/timer.h" | |
1de7afc9 | 26 | #include "qemu/sockets.h" |
ad6f932f | 27 | #include "qemu/help_option.h" |
5bce308a | 28 | #include "monitor/monitor-internal.h" |
e688df6b | 29 | #include "qapi/error.h" |
08528271 | 30 | #include "qapi/clone-visitor.h" |
cff8b2c6 | 31 | #include "qapi/opts-visitor.h" |
eb815e24 | 32 | #include "qapi/qapi-builtin-visit.h" |
112ed241 MA |
33 | #include "qapi/qapi-commands-block.h" |
34 | #include "qapi/qapi-commands-char.h" | |
fa4dcf57 | 35 | #include "qapi/qapi-commands-control.h" |
a83e24ba | 36 | #include "qapi/qapi-commands-machine.h" |
112ed241 MA |
37 | #include "qapi/qapi-commands-migration.h" |
38 | #include "qapi/qapi-commands-misc.h" | |
39 | #include "qapi/qapi-commands-net.h" | |
61c7f987 | 40 | #include "qapi/qapi-commands-pci.h" |
112ed241 MA |
41 | #include "qapi/qapi-commands-rocker.h" |
42 | #include "qapi/qapi-commands-run-state.h" | |
43 | #include "qapi/qapi-commands-tpm.h" | |
44 | #include "qapi/qapi-commands-ui.h" | |
08528271 | 45 | #include "qapi/qapi-visit-net.h" |
96eef042 | 46 | #include "qapi/qapi-visit-migration.h" |
452fcdbc | 47 | #include "qapi/qmp/qdict.h" |
cc7a8ea7 | 48 | #include "qapi/qmp/qerror.h" |
f4a06d13 | 49 | #include "qapi/string-input-visitor.h" |
eb1539b2 | 50 | #include "qapi/string-output-visitor.h" |
90998d58 | 51 | #include "qom/object_interfaces.h" |
28ecbaee | 52 | #include "ui/console.h" |
f348b6d1 | 53 | #include "qemu/cutils.h" |
d59ce6f3 | 54 | #include "qemu/error-report.h" |
61b97833 | 55 | #include "hw/intc/intc.h" |
5e22479a | 56 | #include "migration/snapshot.h" |
9d18af93 | 57 | #include "migration/misc.h" |
48a32bed | 58 | |
22fa7da0 CR |
59 | #ifdef CONFIG_SPICE |
60 | #include <spice/enums.h> | |
61 | #endif | |
62 | ||
0ca117a7 | 63 | bool hmp_handle_error(Monitor *mon, Error *err) |
0cfd6a9a | 64 | { |
187c6147 VSO |
65 | if (err) { |
66 | error_reportf_err(err, "Error: "); | |
0ca117a7 | 67 | return true; |
0cfd6a9a | 68 | } |
0ca117a7 | 69 | return false; |
0cfd6a9a LC |
70 | } |
71 | ||
08528271 DDAG |
72 | /* |
73 | * Produce a strList from a comma separated list. | |
74 | * A NULL or empty input string return NULL. | |
75 | */ | |
76 | static strList *strList_from_comma_list(const char *in) | |
77 | { | |
78 | strList *res = NULL; | |
c3033fd3 | 79 | strList **tail = &res; |
08528271 DDAG |
80 | |
81 | while (in && in[0]) { | |
82 | char *comma = strchr(in, ','); | |
c3033fd3 | 83 | char *value; |
08528271 DDAG |
84 | |
85 | if (comma) { | |
c3033fd3 | 86 | value = g_strndup(in, comma - in); |
08528271 DDAG |
87 | in = comma + 1; /* skip the , */ |
88 | } else { | |
c3033fd3 | 89 | value = g_strdup(in); |
08528271 DDAG |
90 | in = NULL; |
91 | } | |
c3033fd3 | 92 | QAPI_LIST_APPEND(tail, value); |
08528271 DDAG |
93 | } |
94 | ||
95 | return res; | |
96 | } | |
97 | ||
84f2d0ea | 98 | void hmp_info_name(Monitor *mon, const QDict *qdict) |
48a32bed AL |
99 | { |
100 | NameInfo *info; | |
101 | ||
102 | info = qmp_query_name(NULL); | |
103 | if (info->has_name) { | |
104 | monitor_printf(mon, "%s\n", info->name); | |
105 | } | |
106 | qapi_free_NameInfo(info); | |
107 | } | |
b9c15f16 | 108 | |
84f2d0ea | 109 | void hmp_info_version(Monitor *mon, const QDict *qdict) |
b9c15f16 LC |
110 | { |
111 | VersionInfo *info; | |
112 | ||
113 | info = qmp_query_version(NULL); | |
114 | ||
115 | monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n", | |
4752cdbb | 116 | info->qemu->major, info->qemu->minor, info->qemu->micro, |
b9c15f16 LC |
117 | info->package); |
118 | ||
119 | qapi_free_VersionInfo(info); | |
120 | } | |
292a2602 | 121 | |
84f2d0ea | 122 | void hmp_info_kvm(Monitor *mon, const QDict *qdict) |
292a2602 LC |
123 | { |
124 | KvmInfo *info; | |
125 | ||
126 | info = qmp_query_kvm(NULL); | |
127 | monitor_printf(mon, "kvm support: "); | |
128 | if (info->present) { | |
129 | monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled"); | |
130 | } else { | |
131 | monitor_printf(mon, "not compiled\n"); | |
132 | } | |
133 | ||
134 | qapi_free_KvmInfo(info); | |
135 | } | |
136 | ||
84f2d0ea | 137 | void hmp_info_status(Monitor *mon, const QDict *qdict) |
1fa9a5e4 LC |
138 | { |
139 | StatusInfo *info; | |
140 | ||
141 | info = qmp_query_status(NULL); | |
142 | ||
143 | monitor_printf(mon, "VM status: %s%s", | |
144 | info->running ? "running" : "paused", | |
145 | info->singlestep ? " (single step mode)" : ""); | |
146 | ||
147 | if (!info->running && info->status != RUN_STATE_PAUSED) { | |
977c736f | 148 | monitor_printf(mon, " (%s)", RunState_str(info->status)); |
1fa9a5e4 LC |
149 | } |
150 | ||
151 | monitor_printf(mon, "\n"); | |
152 | ||
153 | qapi_free_StatusInfo(info); | |
154 | } | |
155 | ||
84f2d0ea | 156 | void hmp_info_uuid(Monitor *mon, const QDict *qdict) |
efab767e LC |
157 | { |
158 | UuidInfo *info; | |
159 | ||
160 | info = qmp_query_uuid(NULL); | |
161 | monitor_printf(mon, "%s\n", info->UUID); | |
162 | qapi_free_UuidInfo(info); | |
163 | } | |
c5a415a0 | 164 | |
84f2d0ea | 165 | void hmp_info_chardev(Monitor *mon, const QDict *qdict) |
c5a415a0 LC |
166 | { |
167 | ChardevInfoList *char_info, *info; | |
168 | ||
169 | char_info = qmp_query_chardev(NULL); | |
170 | for (info = char_info; info; info = info->next) { | |
171 | monitor_printf(mon, "%s: filename=%s\n", info->value->label, | |
172 | info->value->filename); | |
173 | } | |
174 | ||
175 | qapi_free_ChardevInfoList(char_info); | |
176 | } | |
7a7f325e | 177 | |
84f2d0ea | 178 | void hmp_info_mice(Monitor *mon, const QDict *qdict) |
e235cec3 LC |
179 | { |
180 | MouseInfoList *mice_list, *mouse; | |
181 | ||
182 | mice_list = qmp_query_mice(NULL); | |
183 | if (!mice_list) { | |
184 | monitor_printf(mon, "No mouse devices connected\n"); | |
185 | return; | |
186 | } | |
187 | ||
188 | for (mouse = mice_list; mouse; mouse = mouse->next) { | |
189 | monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n", | |
190 | mouse->value->current ? '*' : ' ', | |
191 | mouse->value->index, mouse->value->name, | |
192 | mouse->value->absolute ? " (absolute)" : ""); | |
193 | } | |
194 | ||
195 | qapi_free_MouseInfoList(mice_list); | |
196 | } | |
197 | ||
9aca82ba JQ |
198 | static char *SocketAddress_to_str(SocketAddress *addr) |
199 | { | |
200 | switch (addr->type) { | |
201 | case SOCKET_ADDRESS_TYPE_INET: | |
202 | return g_strdup_printf("tcp:%s:%s", | |
203 | addr->u.inet.host, | |
204 | addr->u.inet.port); | |
205 | case SOCKET_ADDRESS_TYPE_UNIX: | |
206 | return g_strdup_printf("unix:%s", | |
207 | addr->u.q_unix.path); | |
208 | case SOCKET_ADDRESS_TYPE_FD: | |
209 | return g_strdup_printf("fd:%s", addr->u.fd.str); | |
210 | case SOCKET_ADDRESS_TYPE_VSOCK: | |
211 | return g_strdup_printf("tcp:%s:%s", | |
212 | addr->u.vsock.cid, | |
213 | addr->u.vsock.port); | |
214 | default: | |
215 | return g_strdup("unknown address type"); | |
216 | } | |
217 | } | |
218 | ||
84f2d0ea | 219 | void hmp_info_migrate(Monitor *mon, const QDict *qdict) |
791e7c82 LC |
220 | { |
221 | MigrationInfo *info; | |
222 | ||
223 | info = qmp_query_migrate(NULL); | |
bbf6da32 | 224 | |
9d18af93 PX |
225 | migration_global_dump(mon); |
226 | ||
372043f3 | 227 | if (info->blocked_reasons) { |
a64aec72 DDAG |
228 | strList *reasons = info->blocked_reasons; |
229 | monitor_printf(mon, "Outgoing migration blocked:\n"); | |
230 | while (reasons) { | |
231 | monitor_printf(mon, " %s\n", reasons->value); | |
232 | reasons = reasons->next; | |
233 | } | |
234 | } | |
235 | ||
791e7c82 | 236 | if (info->has_status) { |
d59ce6f3 | 237 | monitor_printf(mon, "Migration status: %s", |
977c736f | 238 | MigrationStatus_str(info->status)); |
d59ce6f3 DB |
239 | if (info->status == MIGRATION_STATUS_FAILED && |
240 | info->has_error_desc) { | |
241 | monitor_printf(mon, " (%s)\n", info->error_desc); | |
242 | } else { | |
243 | monitor_printf(mon, "\n"); | |
244 | } | |
245 | ||
7ac5529a | 246 | monitor_printf(mon, "total time: %" PRIu64 " ms\n", |
7aa939af | 247 | info->total_time); |
2c52ddf1 | 248 | if (info->has_expected_downtime) { |
7ac5529a | 249 | monitor_printf(mon, "expected downtime: %" PRIu64 " ms\n", |
2c52ddf1 JQ |
250 | info->expected_downtime); |
251 | } | |
9c5a9fcf | 252 | if (info->has_downtime) { |
7ac5529a | 253 | monitor_printf(mon, "downtime: %" PRIu64 " ms\n", |
9c5a9fcf JQ |
254 | info->downtime); |
255 | } | |
ed4fbd10 | 256 | if (info->has_setup_time) { |
7ac5529a | 257 | monitor_printf(mon, "setup: %" PRIu64 " ms\n", |
ed4fbd10 MH |
258 | info->setup_time); |
259 | } | |
791e7c82 LC |
260 | } |
261 | ||
262 | if (info->has_ram) { | |
263 | monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n", | |
264 | info->ram->transferred >> 10); | |
7e114f8c MH |
265 | monitor_printf(mon, "throughput: %0.2f mbps\n", |
266 | info->ram->mbps); | |
791e7c82 LC |
267 | monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n", |
268 | info->ram->remaining >> 10); | |
269 | monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", | |
270 | info->ram->total >> 10); | |
004d4c10 OW |
271 | monitor_printf(mon, "duplicate: %" PRIu64 " pages\n", |
272 | info->ram->duplicate); | |
f1c72795 PL |
273 | monitor_printf(mon, "skipped: %" PRIu64 " pages\n", |
274 | info->ram->skipped); | |
004d4c10 OW |
275 | monitor_printf(mon, "normal: %" PRIu64 " pages\n", |
276 | info->ram->normal); | |
277 | monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n", | |
278 | info->ram->normal_bytes >> 10); | |
58570ed8 C |
279 | monitor_printf(mon, "dirty sync count: %" PRIu64 "\n", |
280 | info->ram->dirty_sync_count); | |
030ce1f8 CF |
281 | monitor_printf(mon, "page size: %" PRIu64 " kbytes\n", |
282 | info->ram->page_size >> 10); | |
a61c45bd JQ |
283 | monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n", |
284 | info->ram->multifd_bytes >> 10); | |
aecbfe9c XG |
285 | monitor_printf(mon, "pages-per-second: %" PRIu64 "\n", |
286 | info->ram->pages_per_second); | |
030ce1f8 | 287 | |
8d017193 JQ |
288 | if (info->ram->dirty_pages_rate) { |
289 | monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n", | |
290 | info->ram->dirty_pages_rate); | |
291 | } | |
d3bf5418 DDAG |
292 | if (info->ram->postcopy_requests) { |
293 | monitor_printf(mon, "postcopy request count: %" PRIu64 "\n", | |
294 | info->ram->postcopy_requests); | |
295 | } | |
ae680668 DE |
296 | if (info->ram->precopy_bytes) { |
297 | monitor_printf(mon, "precopy ram: %" PRIu64 " kbytes\n", | |
298 | info->ram->precopy_bytes >> 10); | |
299 | } | |
300 | if (info->ram->downtime_bytes) { | |
301 | monitor_printf(mon, "downtime ram: %" PRIu64 " kbytes\n", | |
302 | info->ram->downtime_bytes >> 10); | |
303 | } | |
304 | if (info->ram->postcopy_bytes) { | |
305 | monitor_printf(mon, "postcopy ram: %" PRIu64 " kbytes\n", | |
306 | info->ram->postcopy_bytes >> 10); | |
307 | } | |
791e7c82 LC |
308 | } |
309 | ||
310 | if (info->has_disk) { | |
311 | monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n", | |
312 | info->disk->transferred >> 10); | |
313 | monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n", | |
314 | info->disk->remaining >> 10); | |
315 | monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n", | |
316 | info->disk->total >> 10); | |
317 | } | |
318 | ||
f36d55af OW |
319 | if (info->has_xbzrle_cache) { |
320 | monitor_printf(mon, "cache size: %" PRIu64 " bytes\n", | |
321 | info->xbzrle_cache->cache_size); | |
322 | monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n", | |
323 | info->xbzrle_cache->bytes >> 10); | |
324 | monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n", | |
325 | info->xbzrle_cache->pages); | |
afb5d01c | 326 | monitor_printf(mon, "xbzrle cache miss: %" PRIu64 " pages\n", |
f36d55af | 327 | info->xbzrle_cache->cache_miss); |
8bc39233 C |
328 | monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n", |
329 | info->xbzrle_cache->cache_miss_rate); | |
e460a4b1 WW |
330 | monitor_printf(mon, "xbzrle encoding rate: %0.2f\n", |
331 | info->xbzrle_cache->encoding_rate); | |
06b1c6f8 | 332 | monitor_printf(mon, "xbzrle overflow: %" PRIu64 "\n", |
f36d55af OW |
333 | info->xbzrle_cache->overflow); |
334 | } | |
335 | ||
76e03000 XG |
336 | if (info->has_compression) { |
337 | monitor_printf(mon, "compression pages: %" PRIu64 " pages\n", | |
338 | info->compression->pages); | |
339 | monitor_printf(mon, "compression busy: %" PRIu64 "\n", | |
340 | info->compression->busy); | |
341 | monitor_printf(mon, "compression busy rate: %0.2f\n", | |
342 | info->compression->busy_rate); | |
afb5d01c MZ |
343 | monitor_printf(mon, "compressed size: %" PRIu64 " kbytes\n", |
344 | info->compression->compressed_size >> 10); | |
76e03000 XG |
345 | monitor_printf(mon, "compression rate: %0.2f\n", |
346 | info->compression->compression_rate); | |
347 | } | |
348 | ||
d85a31d1 | 349 | if (info->has_cpu_throttle_percentage) { |
4782893e | 350 | monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n", |
d85a31d1 | 351 | info->cpu_throttle_percentage); |
4782893e JH |
352 | } |
353 | ||
65ace060 AP |
354 | if (info->has_postcopy_blocktime) { |
355 | monitor_printf(mon, "postcopy blocktime: %u\n", | |
356 | info->postcopy_blocktime); | |
357 | } | |
358 | ||
359 | if (info->has_postcopy_vcpu_blocktime) { | |
360 | Visitor *v; | |
361 | char *str; | |
362 | v = string_output_visitor_new(false, &str); | |
1f584248 MA |
363 | visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, |
364 | &error_abort); | |
65ace060 AP |
365 | visit_complete(v, &str); |
366 | monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str); | |
367 | g_free(str); | |
368 | visit_free(v); | |
369 | } | |
9aca82ba JQ |
370 | if (info->has_socket_address) { |
371 | SocketAddressList *addr; | |
372 | ||
373 | monitor_printf(mon, "socket address: [\n"); | |
374 | ||
375 | for (addr = info->socket_address; addr; addr = addr->next) { | |
376 | char *s = SocketAddress_to_str(addr->value); | |
377 | monitor_printf(mon, "\t%s\n", s); | |
378 | g_free(s); | |
379 | } | |
380 | monitor_printf(mon, "]\n"); | |
381 | } | |
3710586c KW |
382 | |
383 | if (info->has_vfio) { | |
384 | monitor_printf(mon, "vfio device transferred: %" PRIu64 " kbytes\n", | |
385 | info->vfio->transferred >> 10); | |
386 | } | |
387 | ||
791e7c82 | 388 | qapi_free_MigrationInfo(info); |
bbf6da32 OW |
389 | } |
390 | ||
84f2d0ea | 391 | void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict) |
bbf6da32 OW |
392 | { |
393 | MigrationCapabilityStatusList *caps, *cap; | |
394 | ||
395 | caps = qmp_query_migrate_capabilities(NULL); | |
396 | ||
397 | if (caps) { | |
bbf6da32 | 398 | for (cap = caps; cap; cap = cap->next) { |
d80a0169 | 399 | monitor_printf(mon, "%s: %s\n", |
977c736f | 400 | MigrationCapability_str(cap->value->capability), |
bbf6da32 OW |
401 | cap->value->state ? "on" : "off"); |
402 | } | |
bbf6da32 OW |
403 | } |
404 | ||
405 | qapi_free_MigrationCapabilityStatusList(caps); | |
791e7c82 LC |
406 | } |
407 | ||
50e9a629 LL |
408 | void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) |
409 | { | |
410 | MigrationParameters *params; | |
411 | ||
412 | params = qmp_query_migrate_parameters(NULL); | |
413 | ||
414 | if (params) { | |
ee3d96ba DDAG |
415 | monitor_printf(mon, "%s: %" PRIu64 " ms\n", |
416 | MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL), | |
417 | params->announce_initial); | |
418 | monitor_printf(mon, "%s: %" PRIu64 " ms\n", | |
419 | MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX), | |
420 | params->announce_max); | |
421 | monitor_printf(mon, "%s: %" PRIu64 "\n", | |
422 | MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS), | |
423 | params->announce_rounds); | |
424 | monitor_printf(mon, "%s: %" PRIu64 " ms\n", | |
425 | MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP), | |
426 | params->announce_step); | |
de63ab61 | 427 | assert(params->has_compress_level); |
741d4086 | 428 | monitor_printf(mon, "%s: %u\n", |
977c736f | 429 | MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL), |
50e9a629 | 430 | params->compress_level); |
de63ab61 | 431 | assert(params->has_compress_threads); |
741d4086 | 432 | monitor_printf(mon, "%s: %u\n", |
977c736f | 433 | MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS), |
50e9a629 | 434 | params->compress_threads); |
1d58872a XG |
435 | assert(params->has_compress_wait_thread); |
436 | monitor_printf(mon, "%s: %s\n", | |
437 | MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD), | |
438 | params->compress_wait_thread ? "on" : "off"); | |
de63ab61 | 439 | assert(params->has_decompress_threads); |
741d4086 | 440 | monitor_printf(mon, "%s: %u\n", |
977c736f | 441 | MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS), |
50e9a629 | 442 | params->decompress_threads); |
dc14a470 KZ |
443 | assert(params->has_throttle_trigger_threshold); |
444 | monitor_printf(mon, "%s: %u\n", | |
445 | MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD), | |
446 | params->throttle_trigger_threshold); | |
de63ab61 | 447 | assert(params->has_cpu_throttle_initial); |
741d4086 | 448 | monitor_printf(mon, "%s: %u\n", |
977c736f | 449 | MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL), |
d85a31d1 | 450 | params->cpu_throttle_initial); |
de63ab61 | 451 | assert(params->has_cpu_throttle_increment); |
741d4086 | 452 | monitor_printf(mon, "%s: %u\n", |
977c736f | 453 | MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT), |
d85a31d1 | 454 | params->cpu_throttle_increment); |
cbbf8182 KZ |
455 | assert(params->has_cpu_throttle_tailslow); |
456 | monitor_printf(mon, "%s: %s\n", | |
457 | MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW), | |
458 | params->cpu_throttle_tailslow ? "on" : "off"); | |
4cbc9c7f LQ |
459 | assert(params->has_max_cpu_throttle); |
460 | monitor_printf(mon, "%s: %u\n", | |
461 | MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE), | |
462 | params->max_cpu_throttle); | |
8cc99dcd | 463 | assert(params->has_tls_creds); |
2c02468c | 464 | monitor_printf(mon, "%s: '%s'\n", |
977c736f | 465 | MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS), |
8cc99dcd MA |
466 | params->tls_creds); |
467 | assert(params->has_tls_hostname); | |
2c02468c | 468 | monitor_printf(mon, "%s: '%s'\n", |
977c736f | 469 | MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME), |
8cc99dcd | 470 | params->tls_hostname); |
2ff30257 | 471 | assert(params->has_max_bandwidth); |
741d4086 | 472 | monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n", |
977c736f | 473 | MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH), |
2ff30257 AA |
474 | params->max_bandwidth); |
475 | assert(params->has_downtime_limit); | |
39337f12 | 476 | monitor_printf(mon, "%s: %" PRIu64 " ms\n", |
977c736f | 477 | MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT), |
2ff30257 | 478 | params->downtime_limit); |
fe39a4d4 | 479 | assert(params->has_x_checkpoint_delay); |
39337f12 | 480 | monitor_printf(mon, "%s: %u ms\n", |
977c736f | 481 | MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY), |
68b53591 | 482 | params->x_checkpoint_delay); |
2833c59b JQ |
483 | assert(params->has_block_incremental); |
484 | monitor_printf(mon, "%s: %s\n", | |
977c736f MA |
485 | MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL), |
486 | params->block_incremental ? "on" : "off"); | |
741d4086 | 487 | monitor_printf(mon, "%s: %u\n", |
cbfd6c95 JQ |
488 | MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS), |
489 | params->multifd_channels); | |
96eef042 JQ |
490 | monitor_printf(mon, "%s: %s\n", |
491 | MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION), | |
492 | MultiFDCompression_str(params->multifd_compression)); | |
39337f12 | 493 | monitor_printf(mon, "%s: %" PRIu64 " bytes\n", |
73af8dd8 JQ |
494 | MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE), |
495 | params->xbzrle_cache_size); | |
7e555c6c DDAG |
496 | monitor_printf(mon, "%s: %" PRIu64 "\n", |
497 | MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH), | |
498 | params->max_postcopy_bandwidth); | |
7cd75cbd | 499 | monitor_printf(mon, "%s: '%s'\n", |
d2f1d29b | 500 | MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ), |
7cd75cbd | 501 | params->tls_authz); |
31e4c354 HR |
502 | |
503 | if (params->has_block_bitmap_mapping) { | |
504 | const BitmapMigrationNodeAliasList *bmnal; | |
505 | ||
506 | monitor_printf(mon, "%s:\n", | |
507 | MigrationParameter_str( | |
508 | MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING)); | |
509 | ||
510 | for (bmnal = params->block_bitmap_mapping; | |
511 | bmnal; | |
512 | bmnal = bmnal->next) | |
513 | { | |
514 | const BitmapMigrationNodeAlias *bmna = bmnal->value; | |
515 | const BitmapMigrationBitmapAliasList *bmbal; | |
516 | ||
517 | monitor_printf(mon, " '%s' -> '%s'\n", | |
518 | bmna->node_name, bmna->alias); | |
519 | ||
520 | for (bmbal = bmna->bitmaps; bmbal; bmbal = bmbal->next) { | |
521 | const BitmapMigrationBitmapAlias *bmba = bmbal->value; | |
522 | ||
523 | monitor_printf(mon, " '%s' -> '%s'\n", | |
524 | bmba->name, bmba->alias); | |
525 | } | |
526 | } | |
527 | } | |
50e9a629 LL |
528 | } |
529 | ||
530 | qapi_free_MigrationParameters(params); | |
531 | } | |
532 | ||
f11f57e4 | 533 | |
05eb4a25 | 534 | #ifdef CONFIG_VNC |
0a9667ec DDAG |
535 | /* Helper for hmp_info_vnc_clients, _servers */ |
536 | static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info, | |
537 | const char *name) | |
538 | { | |
539 | monitor_printf(mon, " %s: %s:%s (%s%s)\n", | |
540 | name, | |
541 | info->host, | |
542 | info->service, | |
977c736f | 543 | NetworkAddressFamily_str(info->family), |
0a9667ec DDAG |
544 | info->websocket ? " (Websocket)" : ""); |
545 | } | |
546 | ||
547 | /* Helper displaying and auth and crypt info */ | |
548 | static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent, | |
549 | VncPrimaryAuth auth, | |
550 | VncVencryptSubAuth *vencrypt) | |
551 | { | |
552 | monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent, | |
977c736f MA |
553 | VncPrimaryAuth_str(auth), |
554 | vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none"); | |
0a9667ec DDAG |
555 | } |
556 | ||
557 | static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client) | |
558 | { | |
559 | while (client) { | |
560 | VncClientInfo *cinfo = client->value; | |
561 | ||
562 | hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client"); | |
563 | monitor_printf(mon, " x509_dname: %s\n", | |
564 | cinfo->has_x509_dname ? | |
565 | cinfo->x509_dname : "none"); | |
566 | monitor_printf(mon, " sasl_username: %s\n", | |
567 | cinfo->has_sasl_username ? | |
568 | cinfo->sasl_username : "none"); | |
569 | ||
570 | client = client->next; | |
571 | } | |
572 | } | |
573 | ||
574 | static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server) | |
575 | { | |
576 | while (server) { | |
577 | VncServerInfo2 *sinfo = server->value; | |
578 | hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server"); | |
579 | hmp_info_vnc_authcrypt(mon, " ", sinfo->auth, | |
580 | sinfo->has_vencrypt ? &sinfo->vencrypt : NULL); | |
581 | server = server->next; | |
582 | } | |
583 | } | |
584 | ||
84f2d0ea | 585 | void hmp_info_vnc(Monitor *mon, const QDict *qdict) |
2b54aa87 | 586 | { |
d4ff1093 | 587 | VncInfo2List *info2l, *info2l_head; |
2b54aa87 | 588 | Error *err = NULL; |
2b54aa87 | 589 | |
0a9667ec | 590 | info2l = qmp_query_vnc_servers(&err); |
d4ff1093 | 591 | info2l_head = info2l; |
0ca117a7 | 592 | if (hmp_handle_error(mon, err)) { |
2b54aa87 LC |
593 | return; |
594 | } | |
0a9667ec DDAG |
595 | if (!info2l) { |
596 | monitor_printf(mon, "None\n"); | |
597 | return; | |
2b54aa87 LC |
598 | } |
599 | ||
0a9667ec DDAG |
600 | while (info2l) { |
601 | VncInfo2 *info = info2l->value; | |
602 | monitor_printf(mon, "%s:\n", info->id); | |
603 | hmp_info_vnc_servers(mon, info->server); | |
604 | hmp_info_vnc_clients(mon, info->clients); | |
605 | if (!info->server) { | |
606 | /* The server entry displays its auth, we only | |
607 | * need to display in the case of 'reverse' connections | |
608 | * where there's no server. | |
609 | */ | |
610 | hmp_info_vnc_authcrypt(mon, " ", info->auth, | |
611 | info->has_vencrypt ? &info->vencrypt : NULL); | |
612 | } | |
613 | if (info->has_display) { | |
614 | monitor_printf(mon, " Display: %s\n", info->display); | |
2b54aa87 | 615 | } |
0a9667ec | 616 | info2l = info2l->next; |
2b54aa87 LC |
617 | } |
618 | ||
d4ff1093 | 619 | qapi_free_VncInfo2List(info2l_head); |
0a9667ec | 620 | |
2b54aa87 | 621 | } |
05eb4a25 | 622 | #endif |
2b54aa87 | 623 | |
206addd5 | 624 | #ifdef CONFIG_SPICE |
84f2d0ea | 625 | void hmp_info_spice(Monitor *mon, const QDict *qdict) |
d1f29646 LC |
626 | { |
627 | SpiceChannelList *chan; | |
628 | SpiceInfo *info; | |
22fa7da0 CR |
629 | const char *channel_name; |
630 | const char * const channel_names[] = { | |
631 | [SPICE_CHANNEL_MAIN] = "main", | |
632 | [SPICE_CHANNEL_DISPLAY] = "display", | |
633 | [SPICE_CHANNEL_INPUTS] = "inputs", | |
634 | [SPICE_CHANNEL_CURSOR] = "cursor", | |
635 | [SPICE_CHANNEL_PLAYBACK] = "playback", | |
636 | [SPICE_CHANNEL_RECORD] = "record", | |
637 | [SPICE_CHANNEL_TUNNEL] = "tunnel", | |
638 | [SPICE_CHANNEL_SMARTCARD] = "smartcard", | |
639 | [SPICE_CHANNEL_USBREDIR] = "usbredir", | |
640 | [SPICE_CHANNEL_PORT] = "port", | |
7c6044a9 GH |
641 | #if 0 |
642 | /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7, | |
643 | * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable | |
644 | * as quick fix for build failures with older versions. */ | |
22fa7da0 | 645 | [SPICE_CHANNEL_WEBDAV] = "webdav", |
7c6044a9 | 646 | #endif |
22fa7da0 | 647 | }; |
d1f29646 LC |
648 | |
649 | info = qmp_query_spice(NULL); | |
650 | ||
651 | if (!info->enabled) { | |
652 | monitor_printf(mon, "Server: disabled\n"); | |
653 | goto out; | |
654 | } | |
655 | ||
656 | monitor_printf(mon, "Server:\n"); | |
657 | if (info->has_port) { | |
658 | monitor_printf(mon, " address: %s:%" PRId64 "\n", | |
659 | info->host, info->port); | |
660 | } | |
661 | if (info->has_tls_port) { | |
662 | monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n", | |
663 | info->host, info->tls_port); | |
664 | } | |
61c4efe2 YH |
665 | monitor_printf(mon, " migrated: %s\n", |
666 | info->migrated ? "true" : "false"); | |
d1f29646 LC |
667 | monitor_printf(mon, " auth: %s\n", info->auth); |
668 | monitor_printf(mon, " compiled: %s\n", info->compiled_version); | |
4efee029 | 669 | monitor_printf(mon, " mouse-mode: %s\n", |
977c736f | 670 | SpiceQueryMouseMode_str(info->mouse_mode)); |
d1f29646 LC |
671 | |
672 | if (!info->has_channels || info->channels == NULL) { | |
673 | monitor_printf(mon, "Channels: none\n"); | |
674 | } else { | |
675 | for (chan = info->channels; chan; chan = chan->next) { | |
676 | monitor_printf(mon, "Channel:\n"); | |
677 | monitor_printf(mon, " address: %s:%s%s\n", | |
ddf21908 | 678 | chan->value->host, chan->value->port, |
d1f29646 LC |
679 | chan->value->tls ? " [tls]" : ""); |
680 | monitor_printf(mon, " session: %" PRId64 "\n", | |
681 | chan->value->connection_id); | |
682 | monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n", | |
683 | chan->value->channel_type, chan->value->channel_id); | |
22fa7da0 CR |
684 | |
685 | channel_name = "unknown"; | |
686 | if (chan->value->channel_type > 0 && | |
687 | chan->value->channel_type < ARRAY_SIZE(channel_names) && | |
688 | channel_names[chan->value->channel_type]) { | |
689 | channel_name = channel_names[chan->value->channel_type]; | |
690 | } | |
691 | ||
692 | monitor_printf(mon, " channel name: %s\n", channel_name); | |
d1f29646 LC |
693 | } |
694 | } | |
695 | ||
696 | out: | |
697 | qapi_free_SpiceInfo(info); | |
698 | } | |
206addd5 | 699 | #endif |
d1f29646 | 700 | |
84f2d0ea | 701 | void hmp_info_balloon(Monitor *mon, const QDict *qdict) |
96637bcd LC |
702 | { |
703 | BalloonInfo *info; | |
704 | Error *err = NULL; | |
705 | ||
706 | info = qmp_query_balloon(&err); | |
0ca117a7 | 707 | if (hmp_handle_error(mon, err)) { |
96637bcd LC |
708 | return; |
709 | } | |
710 | ||
01ceb97e | 711 | monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20); |
96637bcd LC |
712 | |
713 | qapi_free_BalloonInfo(info); | |
714 | } | |
715 | ||
79627472 LC |
716 | static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) |
717 | { | |
718 | PciMemoryRegionList *region; | |
719 | ||
720 | monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus); | |
721 | monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n", | |
722 | dev->slot, dev->function); | |
723 | monitor_printf(mon, " "); | |
724 | ||
9fa02cd1 EB |
725 | if (dev->class_info->has_desc) { |
726 | monitor_printf(mon, "%s", dev->class_info->desc); | |
79627472 | 727 | } else { |
9fa02cd1 | 728 | monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class); |
79627472 LC |
729 | } |
730 | ||
731 | monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n", | |
9fa02cd1 | 732 | dev->id->vendor, dev->id->device); |
18613dc6 DL |
733 | if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) { |
734 | monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n", | |
735 | dev->id->subsystem_vendor, dev->id->subsystem); | |
736 | } | |
79627472 LC |
737 | |
738 | if (dev->has_irq) { | |
12fcf49c PX |
739 | monitor_printf(mon, " IRQ %" PRId64 ", pin %c\n", |
740 | dev->irq, (char)('A' + dev->irq_pin - 1)); | |
79627472 LC |
741 | } |
742 | ||
743 | if (dev->has_pci_bridge) { | |
744 | monitor_printf(mon, " BUS %" PRId64 ".\n", | |
9fa02cd1 | 745 | dev->pci_bridge->bus->number); |
79627472 | 746 | monitor_printf(mon, " secondary bus %" PRId64 ".\n", |
9fa02cd1 | 747 | dev->pci_bridge->bus->secondary); |
79627472 | 748 | monitor_printf(mon, " subordinate bus %" PRId64 ".\n", |
9fa02cd1 | 749 | dev->pci_bridge->bus->subordinate); |
79627472 LC |
750 | |
751 | monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n", | |
9fa02cd1 EB |
752 | dev->pci_bridge->bus->io_range->base, |
753 | dev->pci_bridge->bus->io_range->limit); | |
79627472 LC |
754 | |
755 | monitor_printf(mon, | |
756 | " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n", | |
9fa02cd1 EB |
757 | dev->pci_bridge->bus->memory_range->base, |
758 | dev->pci_bridge->bus->memory_range->limit); | |
79627472 LC |
759 | |
760 | monitor_printf(mon, " prefetchable memory range " | |
761 | "[0x%08"PRIx64", 0x%08"PRIx64"]\n", | |
9fa02cd1 EB |
762 | dev->pci_bridge->bus->prefetchable_range->base, |
763 | dev->pci_bridge->bus->prefetchable_range->limit); | |
79627472 LC |
764 | } |
765 | ||
766 | for (region = dev->regions; region; region = region->next) { | |
767 | uint64_t addr, size; | |
768 | ||
769 | addr = region->value->address; | |
770 | size = region->value->size; | |
771 | ||
772 | monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar); | |
773 | ||
774 | if (!strcmp(region->value->type, "io")) { | |
775 | monitor_printf(mon, "I/O at 0x%04" PRIx64 | |
776 | " [0x%04" PRIx64 "].\n", | |
777 | addr, addr + size - 1); | |
778 | } else { | |
779 | monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64 | |
780 | " [0x%08" PRIx64 "].\n", | |
781 | region->value->mem_type_64 ? 64 : 32, | |
782 | region->value->prefetch ? " prefetchable" : "", | |
783 | addr, addr + size - 1); | |
784 | } | |
785 | } | |
786 | ||
787 | monitor_printf(mon, " id \"%s\"\n", dev->qdev_id); | |
788 | ||
789 | if (dev->has_pci_bridge) { | |
790 | if (dev->pci_bridge->has_devices) { | |
791 | PciDeviceInfoList *cdev; | |
792 | for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) { | |
793 | hmp_info_pci_device(mon, cdev->value); | |
794 | } | |
795 | } | |
796 | } | |
797 | } | |
798 | ||
61b97833 HP |
799 | static int hmp_info_pic_foreach(Object *obj, void *opaque) |
800 | { | |
801 | InterruptStatsProvider *intc; | |
802 | InterruptStatsProviderClass *k; | |
803 | Monitor *mon = opaque; | |
804 | ||
805 | if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) { | |
806 | intc = INTERRUPT_STATS_PROVIDER(obj); | |
807 | k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj); | |
808 | if (k->print_info) { | |
809 | k->print_info(intc, mon); | |
810 | } else { | |
811 | monitor_printf(mon, "Interrupt controller information not available for %s.\n", | |
812 | object_get_typename(obj)); | |
813 | } | |
814 | } | |
815 | ||
816 | return 0; | |
817 | } | |
818 | ||
819 | void hmp_info_pic(Monitor *mon, const QDict *qdict) | |
820 | { | |
821 | object_child_foreach_recursive(object_get_root(), | |
822 | hmp_info_pic_foreach, mon); | |
823 | } | |
824 | ||
84f2d0ea | 825 | void hmp_info_pci(Monitor *mon, const QDict *qdict) |
79627472 | 826 | { |
f46cee37 | 827 | PciInfoList *info_list, *info; |
79627472 LC |
828 | Error *err = NULL; |
829 | ||
f46cee37 | 830 | info_list = qmp_query_pci(&err); |
79627472 LC |
831 | if (err) { |
832 | monitor_printf(mon, "PCI devices not supported\n"); | |
833 | error_free(err); | |
834 | return; | |
835 | } | |
836 | ||
f46cee37 | 837 | for (info = info_list; info; info = info->next) { |
79627472 LC |
838 | PciDeviceInfoList *dev; |
839 | ||
840 | for (dev = info->value->devices; dev; dev = dev->next) { | |
841 | hmp_info_pci_device(mon, dev->value); | |
842 | } | |
843 | } | |
844 | ||
f46cee37 | 845 | qapi_free_PciInfoList(info_list); |
79627472 LC |
846 | } |
847 | ||
d1a0cf73 SB |
848 | void hmp_info_tpm(Monitor *mon, const QDict *qdict) |
849 | { | |
caff255a | 850 | #ifdef CONFIG_TPM |
d1a0cf73 SB |
851 | TPMInfoList *info_list, *info; |
852 | Error *err = NULL; | |
853 | unsigned int c = 0; | |
854 | TPMPassthroughOptions *tpo; | |
f4ede81e | 855 | TPMEmulatorOptions *teo; |
d1a0cf73 SB |
856 | |
857 | info_list = qmp_query_tpm(&err); | |
858 | if (err) { | |
859 | monitor_printf(mon, "TPM device not supported\n"); | |
860 | error_free(err); | |
861 | return; | |
862 | } | |
863 | ||
864 | if (info_list) { | |
865 | monitor_printf(mon, "TPM device:\n"); | |
866 | } | |
867 | ||
868 | for (info = info_list; info; info = info->next) { | |
869 | TPMInfo *ti = info->value; | |
870 | monitor_printf(mon, " tpm%d: model=%s\n", | |
977c736f | 871 | c, TpmModel_str(ti->model)); |
d1a0cf73 SB |
872 | |
873 | monitor_printf(mon, " \\ %s: type=%s", | |
39dc3e4a | 874 | ti->id, TpmType_str(ti->options->type)); |
d1a0cf73 | 875 | |
ce21131a | 876 | switch (ti->options->type) { |
39dc3e4a | 877 | case TPM_TYPE_PASSTHROUGH: |
32bafa8f | 878 | tpo = ti->options->u.passthrough.data; |
d1a0cf73 SB |
879 | monitor_printf(mon, "%s%s%s%s", |
880 | tpo->has_path ? ",path=" : "", | |
881 | tpo->has_path ? tpo->path : "", | |
882 | tpo->has_cancel_path ? ",cancel-path=" : "", | |
883 | tpo->has_cancel_path ? tpo->cancel_path : ""); | |
884 | break; | |
39dc3e4a | 885 | case TPM_TYPE_EMULATOR: |
f4ede81e AV |
886 | teo = ti->options->u.emulator.data; |
887 | monitor_printf(mon, ",chardev=%s", teo->chardev); | |
888 | break; | |
39dc3e4a | 889 | case TPM_TYPE__MAX: |
d1a0cf73 SB |
890 | break; |
891 | } | |
892 | monitor_printf(mon, "\n"); | |
893 | c++; | |
894 | } | |
895 | qapi_free_TPMInfoList(info_list); | |
caff255a PMD |
896 | #else |
897 | monitor_printf(mon, "TPM device not supported\n"); | |
898 | #endif /* CONFIG_TPM */ | |
d1a0cf73 SB |
899 | } |
900 | ||
7a7f325e LC |
901 | void hmp_quit(Monitor *mon, const QDict *qdict) |
902 | { | |
903 | monitor_suspend(mon); | |
904 | qmp_quit(NULL); | |
905 | } | |
5f158f21 LC |
906 | |
907 | void hmp_stop(Monitor *mon, const QDict *qdict) | |
908 | { | |
909 | qmp_stop(NULL); | |
910 | } | |
38d22653 | 911 | |
dd12e1bb EC |
912 | void hmp_sync_profile(Monitor *mon, const QDict *qdict) |
913 | { | |
914 | const char *op = qdict_get_try_str(qdict, "op"); | |
915 | ||
916 | if (op == NULL) { | |
917 | bool on = qsp_is_enabled(); | |
918 | ||
919 | monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off"); | |
920 | return; | |
921 | } | |
922 | if (!strcmp(op, "on")) { | |
923 | qsp_enable(); | |
924 | } else if (!strcmp(op, "off")) { | |
925 | qsp_disable(); | |
926 | } else if (!strcmp(op, "reset")) { | |
927 | qsp_reset(); | |
928 | } else { | |
929 | Error *err = NULL; | |
930 | ||
931 | error_setg(&err, QERR_INVALID_PARAMETER, op); | |
187c6147 | 932 | hmp_handle_error(mon, err); |
dd12e1bb EC |
933 | } |
934 | } | |
935 | ||
38d22653 LC |
936 | void hmp_system_reset(Monitor *mon, const QDict *qdict) |
937 | { | |
938 | qmp_system_reset(NULL); | |
939 | } | |
5bc465e4 LC |
940 | |
941 | void hmp_system_powerdown(Monitor *mon, const QDict *qdict) | |
942 | { | |
943 | qmp_system_powerdown(NULL); | |
944 | } | |
755f1968 | 945 | |
8e8581e6 DDAG |
946 | void hmp_exit_preconfig(Monitor *mon, const QDict *qdict) |
947 | { | |
948 | Error *err = NULL; | |
949 | ||
361ac948 | 950 | qmp_x_exit_preconfig(&err); |
187c6147 | 951 | hmp_handle_error(mon, err); |
8e8581e6 DDAG |
952 | } |
953 | ||
755f1968 LC |
954 | void hmp_cpu(Monitor *mon, const QDict *qdict) |
955 | { | |
956 | int64_t cpu_index; | |
957 | ||
958 | /* XXX: drop the monitor_set_cpu() usage when all HMP commands that | |
959 | use it are converted to the QAPI */ | |
960 | cpu_index = qdict_get_int(qdict, "index"); | |
dcba65f8 | 961 | if (monitor_set_cpu(mon, cpu_index) < 0) { |
755f1968 LC |
962 | monitor_printf(mon, "invalid CPU index\n"); |
963 | } | |
964 | } | |
0cfd6a9a LC |
965 | |
966 | void hmp_memsave(Monitor *mon, const QDict *qdict) | |
967 | { | |
968 | uint32_t size = qdict_get_int(qdict, "size"); | |
969 | const char *filename = qdict_get_str(qdict, "filename"); | |
970 | uint64_t addr = qdict_get_int(qdict, "val"); | |
e940f543 | 971 | Error *err = NULL; |
87e6f4a4 | 972 | int cpu_index = monitor_get_cpu_index(mon); |
0cfd6a9a | 973 | |
854e67fe TH |
974 | if (cpu_index < 0) { |
975 | monitor_printf(mon, "No CPU available\n"); | |
976 | return; | |
977 | } | |
978 | ||
979 | qmp_memsave(addr, size, filename, true, cpu_index, &err); | |
187c6147 | 980 | hmp_handle_error(mon, err); |
0cfd6a9a | 981 | } |
6d3962bf LC |
982 | |
983 | void hmp_pmemsave(Monitor *mon, const QDict *qdict) | |
984 | { | |
985 | uint32_t size = qdict_get_int(qdict, "size"); | |
986 | const char *filename = qdict_get_str(qdict, "filename"); | |
987 | uint64_t addr = qdict_get_int(qdict, "val"); | |
e940f543 | 988 | Error *err = NULL; |
6d3962bf | 989 | |
e940f543 | 990 | qmp_pmemsave(addr, size, filename, &err); |
187c6147 | 991 | hmp_handle_error(mon, err); |
1f590cf9 LL |
992 | } |
993 | ||
3949e594 | 994 | void hmp_ringbuf_write(Monitor *mon, const QDict *qdict) |
1f590cf9 | 995 | { |
1f590cf9 LL |
996 | const char *chardev = qdict_get_str(qdict, "device"); |
997 | const char *data = qdict_get_str(qdict, "data"); | |
e940f543 | 998 | Error *err = NULL; |
1f590cf9 | 999 | |
e940f543 | 1000 | qmp_ringbuf_write(chardev, data, false, 0, &err); |
1f590cf9 | 1001 | |
187c6147 | 1002 | hmp_handle_error(mon, err); |
6d3962bf | 1003 | } |
e42e818b | 1004 | |
3949e594 | 1005 | void hmp_ringbuf_read(Monitor *mon, const QDict *qdict) |
49b6d722 LL |
1006 | { |
1007 | uint32_t size = qdict_get_int(qdict, "size"); | |
1008 | const char *chardev = qdict_get_str(qdict, "device"); | |
3ab651fc | 1009 | char *data; |
e940f543 | 1010 | Error *err = NULL; |
543f3412 | 1011 | int i; |
49b6d722 | 1012 | |
e940f543 | 1013 | data = qmp_ringbuf_read(chardev, size, false, 0, &err); |
0ca117a7 | 1014 | if (hmp_handle_error(mon, err)) { |
49b6d722 LL |
1015 | return; |
1016 | } | |
1017 | ||
543f3412 MA |
1018 | for (i = 0; data[i]; i++) { |
1019 | unsigned char ch = data[i]; | |
1020 | ||
1021 | if (ch == '\\') { | |
1022 | monitor_printf(mon, "\\\\"); | |
1023 | } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) { | |
1024 | monitor_printf(mon, "\\u%04X", ch); | |
1025 | } else { | |
1026 | monitor_printf(mon, "%c", ch); | |
1027 | } | |
1028 | ||
1029 | } | |
1030 | monitor_printf(mon, "\n"); | |
3ab651fc | 1031 | g_free(data); |
49b6d722 LL |
1032 | } |
1033 | ||
e42e818b LC |
1034 | void hmp_cont(Monitor *mon, const QDict *qdict) |
1035 | { | |
e940f543 | 1036 | Error *err = NULL; |
e42e818b | 1037 | |
e940f543 | 1038 | qmp_cont(&err); |
187c6147 | 1039 | hmp_handle_error(mon, err); |
e42e818b | 1040 | } |
ab49ab5c | 1041 | |
9b9df25a GH |
1042 | void hmp_system_wakeup(Monitor *mon, const QDict *qdict) |
1043 | { | |
fb064112 DHB |
1044 | Error *err = NULL; |
1045 | ||
1046 | qmp_system_wakeup(&err); | |
187c6147 | 1047 | hmp_handle_error(mon, err); |
9b9df25a GH |
1048 | } |
1049 | ||
3e5a50d6 | 1050 | void hmp_nmi(Monitor *mon, const QDict *qdict) |
ab49ab5c | 1051 | { |
e940f543 | 1052 | Error *err = NULL; |
ab49ab5c | 1053 | |
e940f543 | 1054 | qmp_inject_nmi(&err); |
187c6147 | 1055 | hmp_handle_error(mon, err); |
ab49ab5c | 1056 | } |
4b37156c LC |
1057 | |
1058 | void hmp_set_link(Monitor *mon, const QDict *qdict) | |
1059 | { | |
1060 | const char *name = qdict_get_str(qdict, "name"); | |
34acbc95 | 1061 | bool up = qdict_get_bool(qdict, "up"); |
e940f543 | 1062 | Error *err = NULL; |
4b37156c | 1063 | |
e940f543 | 1064 | qmp_set_link(name, up, &err); |
187c6147 | 1065 | hmp_handle_error(mon, err); |
4b37156c | 1066 | } |
a4dea8a9 | 1067 | |
d72f3264 LC |
1068 | void hmp_balloon(Monitor *mon, const QDict *qdict) |
1069 | { | |
1070 | int64_t value = qdict_get_int(qdict, "value"); | |
e940f543 | 1071 | Error *err = NULL; |
d72f3264 | 1072 | |
e940f543 | 1073 | qmp_balloon(value, &err); |
187c6147 | 1074 | hmp_handle_error(mon, err); |
d72f3264 | 1075 | } |
5e7caacb | 1076 | |
52b26205 JQ |
1077 | void hmp_loadvm(Monitor *mon, const QDict *qdict) |
1078 | { | |
1079 | int saved_vm_running = runstate_is_running(); | |
1080 | const char *name = qdict_get_str(qdict, "name"); | |
927d6638 | 1081 | Error *err = NULL; |
52b26205 JQ |
1082 | |
1083 | vm_stop(RUN_STATE_RESTORE_VM); | |
1084 | ||
c53cd04e | 1085 | if (load_snapshot(name, NULL, false, NULL, &err) && saved_vm_running) { |
52b26205 JQ |
1086 | vm_start(); |
1087 | } | |
187c6147 | 1088 | hmp_handle_error(mon, err); |
52b26205 JQ |
1089 | } |
1090 | ||
d9c7d137 JQ |
1091 | void hmp_savevm(Monitor *mon, const QDict *qdict) |
1092 | { | |
927d6638 JQ |
1093 | Error *err = NULL; |
1094 | ||
f1a9fcdd DB |
1095 | save_snapshot(qdict_get_try_str(qdict, "name"), |
1096 | true, NULL, false, NULL, &err); | |
187c6147 | 1097 | hmp_handle_error(mon, err); |
d9c7d137 JQ |
1098 | } |
1099 | ||
d905bb7b JQ |
1100 | void hmp_delvm(Monitor *mon, const QDict *qdict) |
1101 | { | |
32cd6550 | 1102 | Error *err = NULL; |
d905bb7b JQ |
1103 | const char *name = qdict_get_str(qdict, "name"); |
1104 | ||
bef7e9e2 | 1105 | delete_snapshot(name, false, NULL, &err); |
187c6147 | 1106 | hmp_handle_error(mon, err); |
d905bb7b JQ |
1107 | } |
1108 | ||
544f6ea3 DDAG |
1109 | void hmp_announce_self(Monitor *mon, const QDict *qdict) |
1110 | { | |
08528271 | 1111 | const char *interfaces_str = qdict_get_try_str(qdict, "interfaces"); |
c6644548 | 1112 | const char *id = qdict_get_try_str(qdict, "id"); |
08528271 DDAG |
1113 | AnnounceParameters *params = QAPI_CLONE(AnnounceParameters, |
1114 | migrate_announce_params()); | |
1115 | ||
1116 | qapi_free_strList(params->interfaces); | |
1117 | params->interfaces = strList_from_comma_list(interfaces_str); | |
1118 | params->has_interfaces = params->interfaces != NULL; | |
c6644548 DDAG |
1119 | params->id = g_strdup(id); |
1120 | params->has_id = !!params->id; | |
08528271 DDAG |
1121 | qmp_announce_self(params, NULL); |
1122 | qapi_free_AnnounceParameters(params); | |
544f6ea3 DDAG |
1123 | } |
1124 | ||
6cdedb07 LC |
1125 | void hmp_migrate_cancel(Monitor *mon, const QDict *qdict) |
1126 | { | |
1127 | qmp_migrate_cancel(NULL); | |
1128 | } | |
4f0a993b | 1129 | |
94ae12cb DDAG |
1130 | void hmp_migrate_continue(Monitor *mon, const QDict *qdict) |
1131 | { | |
1132 | Error *err = NULL; | |
1133 | const char *state = qdict_get_str(qdict, "state"); | |
1134 | int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err); | |
1135 | ||
1136 | if (val >= 0) { | |
1137 | qmp_migrate_continue(val, &err); | |
1138 | } | |
1139 | ||
187c6147 | 1140 | hmp_handle_error(mon, err); |
94ae12cb DDAG |
1141 | } |
1142 | ||
bf1ae1f4 DDAG |
1143 | void hmp_migrate_incoming(Monitor *mon, const QDict *qdict) |
1144 | { | |
1145 | Error *err = NULL; | |
1146 | const char *uri = qdict_get_str(qdict, "uri"); | |
1147 | ||
1148 | qmp_migrate_incoming(uri, &err); | |
1149 | ||
187c6147 | 1150 | hmp_handle_error(mon, err); |
bf1ae1f4 DDAG |
1151 | } |
1152 | ||
3b563c4b PX |
1153 | void hmp_migrate_recover(Monitor *mon, const QDict *qdict) |
1154 | { | |
1155 | Error *err = NULL; | |
1156 | const char *uri = qdict_get_str(qdict, "uri"); | |
1157 | ||
1158 | qmp_migrate_recover(uri, &err); | |
1159 | ||
187c6147 | 1160 | hmp_handle_error(mon, err); |
3b563c4b PX |
1161 | } |
1162 | ||
d37297dc PX |
1163 | void hmp_migrate_pause(Monitor *mon, const QDict *qdict) |
1164 | { | |
1165 | Error *err = NULL; | |
1166 | ||
1167 | qmp_migrate_pause(&err); | |
1168 | ||
187c6147 | 1169 | hmp_handle_error(mon, err); |
d37297dc PX |
1170 | } |
1171 | ||
fbf796fd | 1172 | |
00458433 OW |
1173 | void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict) |
1174 | { | |
1175 | const char *cap = qdict_get_str(qdict, "capability"); | |
1176 | bool state = qdict_get_bool(qdict, "state"); | |
1177 | Error *err = NULL; | |
54aa3de7 EB |
1178 | MigrationCapabilityStatusList *caps = NULL; |
1179 | MigrationCapabilityStatus *value; | |
8e615e34 | 1180 | int val; |
00458433 | 1181 | |
f7abe0ec | 1182 | val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err); |
8e615e34 MAL |
1183 | if (val < 0) { |
1184 | goto end; | |
00458433 OW |
1185 | } |
1186 | ||
54aa3de7 EB |
1187 | value = g_malloc0(sizeof(*value)); |
1188 | value->capability = val; | |
1189 | value->state = state; | |
1190 | QAPI_LIST_PREPEND(caps, value); | |
8e615e34 | 1191 | qmp_migrate_set_capabilities(caps, &err); |
54aa3de7 | 1192 | qapi_free_MigrationCapabilityStatusList(caps); |
00458433 | 1193 | |
8e615e34 | 1194 | end: |
187c6147 | 1195 | hmp_handle_error(mon, err); |
00458433 OW |
1196 | } |
1197 | ||
50e9a629 LL |
1198 | void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) |
1199 | { | |
1200 | const char *param = qdict_get_str(qdict, "parameter"); | |
69ef1f36 | 1201 | const char *valuestr = qdict_get_str(qdict, "value"); |
f4a06d13 | 1202 | Visitor *v = string_input_visitor_new(valuestr); |
1bda8b3c | 1203 | MigrateSetParameters *p = g_new0(MigrateSetParameters, 1); |
f46bfdbf | 1204 | uint64_t valuebw = 0; |
73af8dd8 | 1205 | uint64_t cache_size; |
50e9a629 | 1206 | Error *err = NULL; |
262517b7 | 1207 | int val, ret; |
69ef1f36 | 1208 | |
f7abe0ec | 1209 | val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err); |
262517b7 MAL |
1210 | if (val < 0) { |
1211 | goto cleanup; | |
1212 | } | |
1213 | ||
1214 | switch (val) { | |
1215 | case MIGRATION_PARAMETER_COMPRESS_LEVEL: | |
1216 | p->has_compress_level = true; | |
ec17de0a | 1217 | visit_type_uint8(v, param, &p->compress_level, &err); |
262517b7 MAL |
1218 | break; |
1219 | case MIGRATION_PARAMETER_COMPRESS_THREADS: | |
1220 | p->has_compress_threads = true; | |
ec17de0a | 1221 | visit_type_uint8(v, param, &p->compress_threads, &err); |
262517b7 | 1222 | break; |
1d58872a XG |
1223 | case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD: |
1224 | p->has_compress_wait_thread = true; | |
1225 | visit_type_bool(v, param, &p->compress_wait_thread, &err); | |
1226 | break; | |
262517b7 MAL |
1227 | case MIGRATION_PARAMETER_DECOMPRESS_THREADS: |
1228 | p->has_decompress_threads = true; | |
ec17de0a | 1229 | visit_type_uint8(v, param, &p->decompress_threads, &err); |
262517b7 | 1230 | break; |
dc14a470 KZ |
1231 | case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD: |
1232 | p->has_throttle_trigger_threshold = true; | |
ec17de0a | 1233 | visit_type_uint8(v, param, &p->throttle_trigger_threshold, &err); |
33ee3d96 | 1234 | break; |
262517b7 MAL |
1235 | case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL: |
1236 | p->has_cpu_throttle_initial = true; | |
ec17de0a | 1237 | visit_type_uint8(v, param, &p->cpu_throttle_initial, &err); |
262517b7 MAL |
1238 | break; |
1239 | case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT: | |
1240 | p->has_cpu_throttle_increment = true; | |
ec17de0a | 1241 | visit_type_uint8(v, param, &p->cpu_throttle_increment, &err); |
262517b7 | 1242 | break; |
cbbf8182 KZ |
1243 | case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW: |
1244 | p->has_cpu_throttle_tailslow = true; | |
1245 | visit_type_bool(v, param, &p->cpu_throttle_tailslow, &err); | |
1246 | break; | |
4cbc9c7f LQ |
1247 | case MIGRATION_PARAMETER_MAX_CPU_THROTTLE: |
1248 | p->has_max_cpu_throttle = true; | |
ec17de0a | 1249 | visit_type_uint8(v, param, &p->max_cpu_throttle, &err); |
4cbc9c7f | 1250 | break; |
262517b7 MAL |
1251 | case MIGRATION_PARAMETER_TLS_CREDS: |
1252 | p->has_tls_creds = true; | |
1253 | p->tls_creds = g_new0(StrOrNull, 1); | |
1254 | p->tls_creds->type = QTYPE_QSTRING; | |
1255 | visit_type_str(v, param, &p->tls_creds->u.s, &err); | |
1256 | break; | |
1257 | case MIGRATION_PARAMETER_TLS_HOSTNAME: | |
1258 | p->has_tls_hostname = true; | |
1259 | p->tls_hostname = g_new0(StrOrNull, 1); | |
1260 | p->tls_hostname->type = QTYPE_QSTRING; | |
1261 | visit_type_str(v, param, &p->tls_hostname->u.s, &err); | |
1262 | break; | |
d2f1d29b DB |
1263 | case MIGRATION_PARAMETER_TLS_AUTHZ: |
1264 | p->has_tls_authz = true; | |
1265 | p->tls_authz = g_new0(StrOrNull, 1); | |
1266 | p->tls_authz->type = QTYPE_QSTRING; | |
1267 | visit_type_str(v, param, &p->tls_authz->u.s, &err); | |
1268 | break; | |
262517b7 MAL |
1269 | case MIGRATION_PARAMETER_MAX_BANDWIDTH: |
1270 | p->has_max_bandwidth = true; | |
1271 | /* | |
1272 | * Can't use visit_type_size() here, because it | |
1273 | * defaults to Bytes rather than Mebibytes. | |
1274 | */ | |
1275 | ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw); | |
1276 | if (ret < 0 || valuebw > INT64_MAX | |
1277 | || (size_t)valuebw != valuebw) { | |
1278 | error_setg(&err, "Invalid size %s", valuestr); | |
50e9a629 LL |
1279 | break; |
1280 | } | |
262517b7 MAL |
1281 | p->max_bandwidth = valuebw; |
1282 | break; | |
1283 | case MIGRATION_PARAMETER_DOWNTIME_LIMIT: | |
1284 | p->has_downtime_limit = true; | |
ec17de0a | 1285 | visit_type_size(v, param, &p->downtime_limit, &err); |
262517b7 MAL |
1286 | break; |
1287 | case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY: | |
1288 | p->has_x_checkpoint_delay = true; | |
ec17de0a | 1289 | visit_type_uint32(v, param, &p->x_checkpoint_delay, &err); |
262517b7 MAL |
1290 | break; |
1291 | case MIGRATION_PARAMETER_BLOCK_INCREMENTAL: | |
1292 | p->has_block_incremental = true; | |
1293 | visit_type_bool(v, param, &p->block_incremental, &err); | |
1294 | break; | |
cbfd6c95 JQ |
1295 | case MIGRATION_PARAMETER_MULTIFD_CHANNELS: |
1296 | p->has_multifd_channels = true; | |
ec17de0a | 1297 | visit_type_uint8(v, param, &p->multifd_channels, &err); |
4075fb1c | 1298 | break; |
96eef042 JQ |
1299 | case MIGRATION_PARAMETER_MULTIFD_COMPRESSION: |
1300 | p->has_multifd_compression = true; | |
3c4b89c3 MA |
1301 | visit_type_MultiFDCompression(v, param, &p->multifd_compression, |
1302 | &err); | |
96eef042 | 1303 | break; |
9004db48 JQ |
1304 | case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL: |
1305 | p->has_multifd_zlib_level = true; | |
ec17de0a | 1306 | visit_type_uint8(v, param, &p->multifd_zlib_level, &err); |
9004db48 | 1307 | break; |
6a9ad154 JQ |
1308 | case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL: |
1309 | p->has_multifd_zstd_level = true; | |
ec17de0a | 1310 | visit_type_uint8(v, param, &p->multifd_zstd_level, &err); |
6a9ad154 | 1311 | break; |
73af8dd8 JQ |
1312 | case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE: |
1313 | p->has_xbzrle_cache_size = true; | |
62a35aaa | 1314 | if (!visit_type_size(v, param, &cache_size, &err)) { |
d013283a JQ |
1315 | break; |
1316 | } | |
1317 | if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) { | |
73af8dd8 JQ |
1318 | error_setg(&err, "Invalid size %s", valuestr); |
1319 | break; | |
1320 | } | |
1321 | p->xbzrle_cache_size = cache_size; | |
1322 | break; | |
7e555c6c DDAG |
1323 | case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH: |
1324 | p->has_max_postcopy_bandwidth = true; | |
1325 | visit_type_size(v, param, &p->max_postcopy_bandwidth, &err); | |
1326 | break; | |
ee3d96ba DDAG |
1327 | case MIGRATION_PARAMETER_ANNOUNCE_INITIAL: |
1328 | p->has_announce_initial = true; | |
1329 | visit_type_size(v, param, &p->announce_initial, &err); | |
1330 | break; | |
1331 | case MIGRATION_PARAMETER_ANNOUNCE_MAX: | |
1332 | p->has_announce_max = true; | |
1333 | visit_type_size(v, param, &p->announce_max, &err); | |
1334 | break; | |
1335 | case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS: | |
1336 | p->has_announce_rounds = true; | |
1337 | visit_type_size(v, param, &p->announce_rounds, &err); | |
1338 | break; | |
1339 | case MIGRATION_PARAMETER_ANNOUNCE_STEP: | |
1340 | p->has_announce_step = true; | |
1341 | visit_type_size(v, param, &p->announce_step, &err); | |
1342 | break; | |
31e4c354 HR |
1343 | case MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING: |
1344 | error_setg(&err, "The block-bitmap-mapping parameter can only be set " | |
1345 | "through QMP"); | |
1346 | break; | |
262517b7 MAL |
1347 | default: |
1348 | assert(0); | |
50e9a629 LL |
1349 | } |
1350 | ||
262517b7 MAL |
1351 | if (err) { |
1352 | goto cleanup; | |
50e9a629 LL |
1353 | } |
1354 | ||
262517b7 MAL |
1355 | qmp_migrate_set_parameters(p, &err); |
1356 | ||
69ef1f36 | 1357 | cleanup: |
1bda8b3c | 1358 | qapi_free_MigrateSetParameters(p); |
f4a06d13 | 1359 | visit_free(v); |
187c6147 | 1360 | hmp_handle_error(mon, err); |
50e9a629 LL |
1361 | } |
1362 | ||
b8a185bc MA |
1363 | void hmp_client_migrate_info(Monitor *mon, const QDict *qdict) |
1364 | { | |
1365 | Error *err = NULL; | |
1366 | const char *protocol = qdict_get_str(qdict, "protocol"); | |
1367 | const char *hostname = qdict_get_str(qdict, "hostname"); | |
1368 | bool has_port = qdict_haskey(qdict, "port"); | |
1369 | int port = qdict_get_try_int(qdict, "port", -1); | |
1370 | bool has_tls_port = qdict_haskey(qdict, "tls-port"); | |
1371 | int tls_port = qdict_get_try_int(qdict, "tls-port", -1); | |
1372 | const char *cert_subject = qdict_get_try_str(qdict, "cert-subject"); | |
1373 | ||
1374 | qmp_client_migrate_info(protocol, hostname, | |
1375 | has_port, port, has_tls_port, tls_port, | |
1376 | !!cert_subject, cert_subject, &err); | |
187c6147 | 1377 | hmp_handle_error(mon, err); |
b8a185bc MA |
1378 | } |
1379 | ||
4886a1bc DDAG |
1380 | void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict) |
1381 | { | |
1382 | Error *err = NULL; | |
1383 | qmp_migrate_start_postcopy(&err); | |
187c6147 | 1384 | hmp_handle_error(mon, err); |
4886a1bc DDAG |
1385 | } |
1386 | ||
d89e666e HZ |
1387 | void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict) |
1388 | { | |
1389 | Error *err = NULL; | |
1390 | ||
1391 | qmp_x_colo_lost_heartbeat(&err); | |
187c6147 | 1392 | hmp_handle_error(mon, err); |
d89e666e HZ |
1393 | } |
1394 | ||
fbf796fd LC |
1395 | void hmp_set_password(Monitor *mon, const QDict *qdict) |
1396 | { | |
1397 | const char *protocol = qdict_get_str(qdict, "protocol"); | |
1398 | const char *password = qdict_get_str(qdict, "password"); | |
675fd3c9 | 1399 | const char *display = qdict_get_try_str(qdict, "display"); |
fbf796fd LC |
1400 | const char *connected = qdict_get_try_str(qdict, "connected"); |
1401 | Error *err = NULL; | |
1402 | ||
675fd3c9 SR |
1403 | SetPasswordOptions opts = { |
1404 | .password = (char *)password, | |
1405 | .has_connected = !!connected, | |
1406 | }; | |
1407 | ||
1408 | opts.connected = qapi_enum_parse(&SetPasswordAction_lookup, connected, | |
1409 | SET_PASSWORD_ACTION_KEEP, &err); | |
7277db91 SR |
1410 | if (err) { |
1411 | goto out; | |
1412 | } | |
1413 | ||
675fd3c9 SR |
1414 | opts.protocol = qapi_enum_parse(&DisplayProtocol_lookup, protocol, |
1415 | DISPLAY_PROTOCOL_VNC, &err); | |
7277db91 SR |
1416 | if (err) { |
1417 | goto out; | |
1418 | } | |
1419 | ||
675fd3c9 SR |
1420 | if (opts.protocol == DISPLAY_PROTOCOL_VNC) { |
1421 | opts.u.vnc.has_display = !!display; | |
1422 | opts.u.vnc.display = (char *)display; | |
1423 | } | |
1424 | ||
1425 | qmp_set_password(&opts, &err); | |
7277db91 SR |
1426 | |
1427 | out: | |
187c6147 | 1428 | hmp_handle_error(mon, err); |
fbf796fd | 1429 | } |
9ad5372d LC |
1430 | |
1431 | void hmp_expire_password(Monitor *mon, const QDict *qdict) | |
1432 | { | |
1433 | const char *protocol = qdict_get_str(qdict, "protocol"); | |
1434 | const char *whenstr = qdict_get_str(qdict, "time"); | |
675fd3c9 | 1435 | const char *display = qdict_get_try_str(qdict, "display"); |
9ad5372d | 1436 | Error *err = NULL; |
7277db91 | 1437 | |
675fd3c9 SR |
1438 | ExpirePasswordOptions opts = { |
1439 | .time = (char *)whenstr, | |
1440 | }; | |
1441 | ||
1442 | opts.protocol = qapi_enum_parse(&DisplayProtocol_lookup, protocol, | |
1443 | DISPLAY_PROTOCOL_VNC, &err); | |
7277db91 SR |
1444 | if (err) { |
1445 | goto out; | |
1446 | } | |
9ad5372d | 1447 | |
675fd3c9 SR |
1448 | if (opts.protocol == DISPLAY_PROTOCOL_VNC) { |
1449 | opts.u.vnc.has_display = !!display; | |
1450 | opts.u.vnc.display = (char *)display; | |
1451 | } | |
1452 | ||
1453 | qmp_expire_password(&opts, &err); | |
7277db91 SR |
1454 | |
1455 | out: | |
187c6147 | 1456 | hmp_handle_error(mon, err); |
9ad5372d | 1457 | } |
c245b6a3 | 1458 | |
333a96ec | 1459 | |
05eb4a25 | 1460 | #ifdef CONFIG_VNC |
c60bf339 SH |
1461 | static void hmp_change_read_arg(void *opaque, const char *password, |
1462 | void *readline_opaque) | |
333a96ec LC |
1463 | { |
1464 | qmp_change_vnc_password(password, NULL); | |
c60bf339 | 1465 | monitor_read_command(opaque, 1); |
333a96ec | 1466 | } |
05eb4a25 | 1467 | #endif |
333a96ec | 1468 | |
333a96ec LC |
1469 | void hmp_change(Monitor *mon, const QDict *qdict) |
1470 | { | |
1471 | const char *device = qdict_get_str(qdict, "device"); | |
1472 | const char *target = qdict_get_str(qdict, "target"); | |
1473 | const char *arg = qdict_get_try_str(qdict, "arg"); | |
baead0ab HR |
1474 | const char *read_only = qdict_get_try_str(qdict, "read-only-mode"); |
1475 | BlockdevChangeReadOnlyMode read_only_mode = 0; | |
333a96ec LC |
1476 | Error *err = NULL; |
1477 | ||
05eb4a25 | 1478 | #ifdef CONFIG_VNC |
10686749 | 1479 | if (strcmp(device, "vnc") == 0) { |
baead0ab HR |
1480 | if (read_only) { |
1481 | monitor_printf(mon, | |
1482 | "Parameter 'read-only-mode' is invalid for VNC\n"); | |
1483 | return; | |
1484 | } | |
10686749 HR |
1485 | if (strcmp(target, "passwd") == 0 || |
1486 | strcmp(target, "password") == 0) { | |
6193344f | 1487 | if (!arg) { |
ea73f370 | 1488 | MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common); |
5f9dba16 | 1489 | monitor_read_password(hmp_mon, hmp_change_read_arg, NULL); |
10686749 | 1490 | return; |
cfb5387a PB |
1491 | } else { |
1492 | qmp_change_vnc_password(arg, &err); | |
10686749 | 1493 | } |
cfb5387a PB |
1494 | } else { |
1495 | monitor_printf(mon, "Expected 'password' after 'vnc'\n"); | |
10686749 | 1496 | } |
05eb4a25 MAL |
1497 | } else |
1498 | #endif | |
1499 | { | |
baead0ab HR |
1500 | if (read_only) { |
1501 | read_only_mode = | |
f7abe0ec | 1502 | qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup, |
06c60b6c | 1503 | read_only, |
baead0ab HR |
1504 | BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err); |
1505 | if (err) { | |
ac9c95b1 | 1506 | goto end; |
baead0ab HR |
1507 | } |
1508 | } | |
1509 | ||
70e2cb3b KW |
1510 | qmp_blockdev_change_medium(true, device, false, NULL, target, |
1511 | !!arg, arg, !!read_only, read_only_mode, | |
1512 | &err); | |
333a96ec LC |
1513 | } |
1514 | ||
ac9c95b1 | 1515 | end: |
187c6147 | 1516 | hmp_handle_error(mon, err); |
333a96ec | 1517 | } |
80047da5 | 1518 | |
d22b854d | 1519 | typedef struct HMPMigrationStatus { |
e1c37d0e LC |
1520 | QEMUTimer *timer; |
1521 | Monitor *mon; | |
1522 | bool is_block_migration; | |
e49f35bd | 1523 | } HMPMigrationStatus; |
e1c37d0e LC |
1524 | |
1525 | static void hmp_migrate_status_cb(void *opaque) | |
1526 | { | |
e49f35bd | 1527 | HMPMigrationStatus *status = opaque; |
e1c37d0e LC |
1528 | MigrationInfo *info; |
1529 | ||
1530 | info = qmp_query_migrate(NULL); | |
24b8c39b HZ |
1531 | if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE || |
1532 | info->status == MIGRATION_STATUS_SETUP) { | |
e1c37d0e LC |
1533 | if (info->has_disk) { |
1534 | int progress; | |
1535 | ||
1536 | if (info->disk->remaining) { | |
1537 | progress = info->disk->transferred * 100 / info->disk->total; | |
1538 | } else { | |
1539 | progress = 100; | |
1540 | } | |
1541 | ||
1542 | monitor_printf(status->mon, "Completed %d %%\r", progress); | |
1543 | monitor_flush(status->mon); | |
1544 | } | |
1545 | ||
bc72ad67 | 1546 | timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000); |
e1c37d0e LC |
1547 | } else { |
1548 | if (status->is_block_migration) { | |
1549 | monitor_printf(status->mon, "\n"); | |
1550 | } | |
d59ce6f3 DB |
1551 | if (info->has_error_desc) { |
1552 | error_report("%s", info->error_desc); | |
1553 | } | |
e1c37d0e | 1554 | monitor_resume(status->mon); |
d34a10af | 1555 | timer_free(status->timer); |
e1c37d0e LC |
1556 | g_free(status); |
1557 | } | |
1558 | ||
1559 | qapi_free_MigrationInfo(info); | |
1560 | } | |
1561 | ||
1562 | void hmp_migrate(Monitor *mon, const QDict *qdict) | |
1563 | { | |
34acbc95 EB |
1564 | bool detach = qdict_get_try_bool(qdict, "detach", false); |
1565 | bool blk = qdict_get_try_bool(qdict, "blk", false); | |
1566 | bool inc = qdict_get_try_bool(qdict, "inc", false); | |
7a4da28b | 1567 | bool resume = qdict_get_try_bool(qdict, "resume", false); |
e1c37d0e LC |
1568 | const char *uri = qdict_get_str(qdict, "uri"); |
1569 | Error *err = NULL; | |
1570 | ||
7a4da28b PX |
1571 | qmp_migrate(uri, !!blk, blk, !!inc, inc, |
1572 | false, false, true, resume, &err); | |
0ca117a7 | 1573 | if (hmp_handle_error(mon, err)) { |
e1c37d0e LC |
1574 | return; |
1575 | } | |
1576 | ||
1577 | if (!detach) { | |
e49f35bd | 1578 | HMPMigrationStatus *status; |
e1c37d0e LC |
1579 | |
1580 | if (monitor_suspend(mon) < 0) { | |
1581 | monitor_printf(mon, "terminal does not allow synchronous " | |
1582 | "migration, continuing detached\n"); | |
1583 | return; | |
1584 | } | |
1585 | ||
1586 | status = g_malloc0(sizeof(*status)); | |
1587 | status->mon = mon; | |
1588 | status->is_block_migration = blk || inc; | |
bc72ad67 | 1589 | status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb, |
e1c37d0e | 1590 | status); |
bc72ad67 | 1591 | timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME)); |
e1c37d0e LC |
1592 | } |
1593 | } | |
a15fef21 | 1594 | |
928059a3 LC |
1595 | void hmp_netdev_add(Monitor *mon, const QDict *qdict) |
1596 | { | |
1597 | Error *err = NULL; | |
1598 | QemuOpts *opts; | |
ad6f932f | 1599 | const char *type = qdict_get_try_str(qdict, "type"); |
928059a3 | 1600 | |
ad6f932f PB |
1601 | if (type && is_help_option(type)) { |
1602 | show_netdevs(); | |
1603 | return; | |
1604 | } | |
928059a3 | 1605 | opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err); |
84d18f06 | 1606 | if (err) { |
928059a3 LC |
1607 | goto out; |
1608 | } | |
1609 | ||
1610 | netdev_add(opts, &err); | |
84d18f06 | 1611 | if (err) { |
928059a3 LC |
1612 | qemu_opts_del(opts); |
1613 | } | |
1614 | ||
1615 | out: | |
187c6147 | 1616 | hmp_handle_error(mon, err); |
928059a3 | 1617 | } |
5f964155 LC |
1618 | |
1619 | void hmp_netdev_del(Monitor *mon, const QDict *qdict) | |
1620 | { | |
1621 | const char *id = qdict_get_str(qdict, "id"); | |
1622 | Error *err = NULL; | |
1623 | ||
1624 | qmp_netdev_del(id, &err); | |
187c6147 | 1625 | hmp_handle_error(mon, err); |
5f964155 | 1626 | } |
208c9d1b | 1627 | |
cff8b2c6 PB |
1628 | void hmp_object_add(Monitor *mon, const QDict *qdict) |
1629 | { | |
da0a932b | 1630 | const char *options = qdict_get_str(qdict, "object"); |
cff8b2c6 | 1631 | Error *err = NULL; |
cff8b2c6 | 1632 | |
da0a932b | 1633 | user_creatable_add_from_str(options, &err); |
0705ecc4 | 1634 | hmp_handle_error(mon, err); |
cff8b2c6 PB |
1635 | } |
1636 | ||
208c9d1b CB |
1637 | void hmp_getfd(Monitor *mon, const QDict *qdict) |
1638 | { | |
1639 | const char *fdname = qdict_get_str(qdict, "fdname"); | |
e940f543 | 1640 | Error *err = NULL; |
208c9d1b | 1641 | |
e940f543 | 1642 | qmp_getfd(fdname, &err); |
187c6147 | 1643 | hmp_handle_error(mon, err); |
208c9d1b CB |
1644 | } |
1645 | ||
1646 | void hmp_closefd(Monitor *mon, const QDict *qdict) | |
1647 | { | |
1648 | const char *fdname = qdict_get_str(qdict, "fdname"); | |
e940f543 | 1649 | Error *err = NULL; |
208c9d1b | 1650 | |
e940f543 | 1651 | qmp_closefd(fdname, &err); |
187c6147 | 1652 | hmp_handle_error(mon, err); |
208c9d1b | 1653 | } |
e4c8f004 | 1654 | |
3e5a50d6 | 1655 | void hmp_sendkey(Monitor *mon, const QDict *qdict) |
e4c8f004 AK |
1656 | { |
1657 | const char *keys = qdict_get_str(qdict, "keys"); | |
95b3a8c8 EB |
1658 | KeyValue *v = NULL; |
1659 | KeyValueList *head = NULL, **tail = &head; | |
e4c8f004 AK |
1660 | int has_hold_time = qdict_haskey(qdict, "hold-time"); |
1661 | int hold_time = qdict_get_try_int(qdict, "hold-time", -1); | |
1662 | Error *err = NULL; | |
5c99fa37 | 1663 | const char *separator; |
9f328977 | 1664 | int keyname_len; |
e4c8f004 AK |
1665 | |
1666 | while (1) { | |
5c99fa37 KF |
1667 | separator = qemu_strchrnul(keys, '-'); |
1668 | keyname_len = separator - keys; | |
e4c8f004 AK |
1669 | |
1670 | /* Be compatible with old interface, convert user inputted "<" */ | |
64ffbe04 WB |
1671 | if (keys[0] == '<' && keyname_len == 1) { |
1672 | keys = "less"; | |
e4c8f004 AK |
1673 | keyname_len = 4; |
1674 | } | |
e4c8f004 | 1675 | |
95b3a8c8 | 1676 | v = g_malloc0(sizeof(*v)); |
e4c8f004 | 1677 | |
64ffbe04 | 1678 | if (strstart(keys, "0x", NULL)) { |
9f328977 | 1679 | char *endp; |
64ffbe04 WB |
1680 | int value = strtoul(keys, &endp, 0); |
1681 | assert(endp <= keys + keyname_len); | |
1682 | if (endp != keys + keyname_len) { | |
9f328977 LC |
1683 | goto err_out; |
1684 | } | |
95b3a8c8 EB |
1685 | v->type = KEY_VALUE_KIND_NUMBER; |
1686 | v->u.number.data = value; | |
9f328977 | 1687 | } else { |
64ffbe04 | 1688 | int idx = index_from_key(keys, keyname_len); |
7fb1cf16 | 1689 | if (idx == Q_KEY_CODE__MAX) { |
9f328977 LC |
1690 | goto err_out; |
1691 | } | |
95b3a8c8 EB |
1692 | v->type = KEY_VALUE_KIND_QCODE; |
1693 | v->u.qcode.data = idx; | |
9f328977 | 1694 | } |
95b3a8c8 EB |
1695 | QAPI_LIST_APPEND(tail, v); |
1696 | v = NULL; | |
9f328977 | 1697 | |
5c99fa37 | 1698 | if (!*separator) { |
e4c8f004 AK |
1699 | break; |
1700 | } | |
1701 | keys = separator + 1; | |
1702 | } | |
1703 | ||
9f328977 | 1704 | qmp_send_key(head, has_hold_time, hold_time, &err); |
187c6147 | 1705 | hmp_handle_error(mon, err); |
9f328977 LC |
1706 | |
1707 | out: | |
95b3a8c8 | 1708 | qapi_free_KeyValue(v); |
9f328977 LC |
1709 | qapi_free_KeyValueList(head); |
1710 | return; | |
1711 | ||
1712 | err_out: | |
64ffbe04 | 1713 | monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys); |
9f328977 | 1714 | goto out; |
e4c8f004 | 1715 | } |
ad39cf6d | 1716 | |
0d9b90ce MAL |
1717 | void coroutine_fn |
1718 | hmp_screendump(Monitor *mon, const QDict *qdict) | |
ad39cf6d LC |
1719 | { |
1720 | const char *filename = qdict_get_str(qdict, "filename"); | |
f771c544 TH |
1721 | const char *id = qdict_get_try_str(qdict, "device"); |
1722 | int64_t head = qdict_get_try_int(qdict, "head", 0); | |
ad39cf6d LC |
1723 | Error *err = NULL; |
1724 | ||
f771c544 | 1725 | qmp_screendump(filename, id != NULL, id, id != NULL, head, &err); |
187c6147 | 1726 | hmp_handle_error(mon, err); |
ad39cf6d | 1727 | } |
4057725f | 1728 | |
f1088908 GH |
1729 | void hmp_chardev_add(Monitor *mon, const QDict *qdict) |
1730 | { | |
1731 | const char *args = qdict_get_str(qdict, "args"); | |
1732 | Error *err = NULL; | |
1733 | QemuOpts *opts; | |
1734 | ||
70b94331 | 1735 | opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true); |
f1088908 | 1736 | if (opts == NULL) { |
312fd5f2 | 1737 | error_setg(&err, "Parsing chardev args failed"); |
f1088908 | 1738 | } else { |
4ad6f6cb | 1739 | qemu_chr_new_from_opts(opts, NULL, &err); |
0a73336d | 1740 | qemu_opts_del(opts); |
f1088908 | 1741 | } |
187c6147 | 1742 | hmp_handle_error(mon, err); |
f1088908 GH |
1743 | } |
1744 | ||
75b60160 AN |
1745 | void hmp_chardev_change(Monitor *mon, const QDict *qdict) |
1746 | { | |
1747 | const char *args = qdict_get_str(qdict, "args"); | |
1748 | const char *id; | |
1749 | Error *err = NULL; | |
1750 | ChardevBackend *backend = NULL; | |
1751 | ChardevReturn *ret = NULL; | |
1752 | QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, | |
1753 | true); | |
1754 | if (!opts) { | |
1755 | error_setg(&err, "Parsing chardev args failed"); | |
1756 | goto end; | |
1757 | } | |
1758 | ||
1759 | id = qdict_get_str(qdict, "id"); | |
1760 | if (qemu_opts_id(opts)) { | |
1761 | error_setg(&err, "Unexpected 'id' parameter"); | |
1762 | goto end; | |
1763 | } | |
1764 | ||
1765 | backend = qemu_chr_parse_opts(opts, &err); | |
1766 | if (!backend) { | |
1767 | goto end; | |
1768 | } | |
1769 | ||
1770 | ret = qmp_chardev_change(id, backend, &err); | |
1771 | ||
1772 | end: | |
1773 | qapi_free_ChardevReturn(ret); | |
1774 | qapi_free_ChardevBackend(backend); | |
1775 | qemu_opts_del(opts); | |
187c6147 | 1776 | hmp_handle_error(mon, err); |
75b60160 AN |
1777 | } |
1778 | ||
f1088908 GH |
1779 | void hmp_chardev_remove(Monitor *mon, const QDict *qdict) |
1780 | { | |
1781 | Error *local_err = NULL; | |
1782 | ||
1783 | qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err); | |
187c6147 | 1784 | hmp_handle_error(mon, local_err); |
f1088908 | 1785 | } |
587da2c3 | 1786 | |
bd1d5ad9 SF |
1787 | void hmp_chardev_send_break(Monitor *mon, const QDict *qdict) |
1788 | { | |
1789 | Error *local_err = NULL; | |
1790 | ||
1791 | qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err); | |
187c6147 | 1792 | hmp_handle_error(mon, local_err); |
bd1d5ad9 SF |
1793 | } |
1794 | ||
ab2d0531 PB |
1795 | void hmp_object_del(Monitor *mon, const QDict *qdict) |
1796 | { | |
1797 | const char *id = qdict_get_str(qdict, "id"); | |
1798 | Error *err = NULL; | |
1799 | ||
90998d58 | 1800 | user_creatable_del(id, &err); |
187c6147 | 1801 | hmp_handle_error(mon, err); |
ab2d0531 | 1802 | } |
eb1539b2 | 1803 | |
a631892f ZG |
1804 | void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) |
1805 | { | |
1806 | Error *err = NULL; | |
1807 | MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err); | |
1808 | MemoryDeviceInfoList *info; | |
d766b22b | 1809 | VirtioPMEMDeviceInfo *vpi; |
2e70874b | 1810 | VirtioMEMDeviceInfo *vmi; |
a631892f ZG |
1811 | MemoryDeviceInfo *value; |
1812 | PCDIMMDeviceInfo *di; | |
a7c565a9 | 1813 | SgxEPCDeviceInfo *se; |
a631892f ZG |
1814 | |
1815 | for (info = info_list; info; info = info->next) { | |
1816 | value = info->value; | |
1817 | ||
1818 | if (value) { | |
1fd5d4fe | 1819 | switch (value->type) { |
a631892f | 1820 | case MEMORY_DEVICE_INFO_KIND_DIMM: |
6388e18d | 1821 | case MEMORY_DEVICE_INFO_KIND_NVDIMM: |
d766b22b DH |
1822 | di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ? |
1823 | value->u.dimm.data : value->u.nvdimm.data; | |
a631892f | 1824 | monitor_printf(mon, "Memory device [%s]: \"%s\"\n", |
977c736f | 1825 | MemoryDeviceInfoKind_str(value->type), |
a631892f ZG |
1826 | di->id ? di->id : ""); |
1827 | monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr); | |
1828 | monitor_printf(mon, " slot: %" PRId64 "\n", di->slot); | |
1829 | monitor_printf(mon, " node: %" PRId64 "\n", di->node); | |
1830 | monitor_printf(mon, " size: %" PRIu64 "\n", di->size); | |
1831 | monitor_printf(mon, " memdev: %s\n", di->memdev); | |
1832 | monitor_printf(mon, " hotplugged: %s\n", | |
1833 | di->hotplugged ? "true" : "false"); | |
1834 | monitor_printf(mon, " hotpluggable: %s\n", | |
1835 | di->hotpluggable ? "true" : "false"); | |
d766b22b DH |
1836 | break; |
1837 | case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM: | |
1838 | vpi = value->u.virtio_pmem.data; | |
1839 | monitor_printf(mon, "Memory device [%s]: \"%s\"\n", | |
1840 | MemoryDeviceInfoKind_str(value->type), | |
1841 | vpi->id ? vpi->id : ""); | |
1842 | monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->memaddr); | |
1843 | monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size); | |
1844 | monitor_printf(mon, " memdev: %s\n", vpi->memdev); | |
1845 | break; | |
2e70874b DH |
1846 | case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM: |
1847 | vmi = value->u.virtio_mem.data; | |
1848 | monitor_printf(mon, "Memory device [%s]: \"%s\"\n", | |
1849 | MemoryDeviceInfoKind_str(value->type), | |
1850 | vmi->id ? vmi->id : ""); | |
1851 | monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vmi->memaddr); | |
1852 | monitor_printf(mon, " node: %" PRId64 "\n", vmi->node); | |
1853 | monitor_printf(mon, " requested-size: %" PRIu64 "\n", | |
1854 | vmi->requested_size); | |
1855 | monitor_printf(mon, " size: %" PRIu64 "\n", vmi->size); | |
1856 | monitor_printf(mon, " max-size: %" PRIu64 "\n", vmi->max_size); | |
1857 | monitor_printf(mon, " block-size: %" PRIu64 "\n", | |
1858 | vmi->block_size); | |
1859 | monitor_printf(mon, " memdev: %s\n", vmi->memdev); | |
1860 | break; | |
a7c565a9 YZ |
1861 | case MEMORY_DEVICE_INFO_KIND_SGX_EPC: |
1862 | se = value->u.sgx_epc.data; | |
1863 | monitor_printf(mon, "Memory device [%s]: \"%s\"\n", | |
1864 | MemoryDeviceInfoKind_str(value->type), | |
1865 | se->id ? se->id : ""); | |
1866 | monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", se->memaddr); | |
1867 | monitor_printf(mon, " size: %" PRIu64 "\n", se->size); | |
11058123 | 1868 | monitor_printf(mon, " node: %" PRId64 "\n", se->node); |
a7c565a9 YZ |
1869 | monitor_printf(mon, " memdev: %s\n", se->memdev); |
1870 | break; | |
d766b22b DH |
1871 | default: |
1872 | g_assert_not_reached(); | |
a631892f ZG |
1873 | } |
1874 | } | |
1875 | } | |
1876 | ||
1877 | qapi_free_MemoryDeviceInfoList(info_list); | |
187c6147 | 1878 | hmp_handle_error(mon, err); |
a631892f | 1879 | } |
89d7fa9e | 1880 | |
62313160 TW |
1881 | void hmp_info_iothreads(Monitor *mon, const QDict *qdict) |
1882 | { | |
1883 | IOThreadInfoList *info_list = qmp_query_iothreads(NULL); | |
1884 | IOThreadInfoList *info; | |
5fc00480 | 1885 | IOThreadInfo *value; |
62313160 TW |
1886 | |
1887 | for (info = info_list; info; info = info->next) { | |
5fc00480 PH |
1888 | value = info->value; |
1889 | monitor_printf(mon, "%s:\n", value->id); | |
1890 | monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id); | |
1891 | monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns); | |
1892 | monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow); | |
1893 | monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink); | |
1793ad02 SG |
1894 | monitor_printf(mon, " aio-max-batch=%" PRId64 "\n", |
1895 | value->aio_max_batch); | |
62313160 TW |
1896 | } |
1897 | ||
1898 | qapi_free_IOThreadInfoList(info_list); | |
1899 | } | |
1900 | ||
fafa4d50 SF |
1901 | void hmp_rocker(Monitor *mon, const QDict *qdict) |
1902 | { | |
1903 | const char *name = qdict_get_str(qdict, "name"); | |
1904 | RockerSwitch *rocker; | |
533fdaed | 1905 | Error *err = NULL; |
fafa4d50 | 1906 | |
533fdaed | 1907 | rocker = qmp_query_rocker(name, &err); |
0ca117a7 | 1908 | if (hmp_handle_error(mon, err)) { |
fafa4d50 SF |
1909 | return; |
1910 | } | |
1911 | ||
1912 | monitor_printf(mon, "name: %s\n", rocker->name); | |
1913 | monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id); | |
1914 | monitor_printf(mon, "ports: %d\n", rocker->ports); | |
1915 | ||
1916 | qapi_free_RockerSwitch(rocker); | |
1917 | } | |
1918 | ||
1919 | void hmp_rocker_ports(Monitor *mon, const QDict *qdict) | |
1920 | { | |
1921 | RockerPortList *list, *port; | |
1922 | const char *name = qdict_get_str(qdict, "name"); | |
533fdaed | 1923 | Error *err = NULL; |
fafa4d50 | 1924 | |
533fdaed | 1925 | list = qmp_query_rocker_ports(name, &err); |
0ca117a7 | 1926 | if (hmp_handle_error(mon, err)) { |
fafa4d50 SF |
1927 | return; |
1928 | } | |
1929 | ||
1930 | monitor_printf(mon, " ena/ speed/ auto\n"); | |
1931 | monitor_printf(mon, " port link duplex neg?\n"); | |
1932 | ||
1933 | for (port = list; port; port = port->next) { | |
61848717 | 1934 | monitor_printf(mon, "%10s %-4s %-3s %2s %s\n", |
fafa4d50 SF |
1935 | port->value->name, |
1936 | port->value->enabled ? port->value->link_up ? | |
1937 | "up" : "down" : "!ena", | |
1938 | port->value->speed == 10000 ? "10G" : "??", | |
1939 | port->value->duplex ? "FD" : "HD", | |
1940 | port->value->autoneg ? "Yes" : "No"); | |
1941 | } | |
1942 | ||
1943 | qapi_free_RockerPortList(list); | |
1944 | } | |
1945 | ||
1946 | void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict) | |
1947 | { | |
1948 | RockerOfDpaFlowList *list, *info; | |
1949 | const char *name = qdict_get_str(qdict, "name"); | |
1950 | uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1); | |
533fdaed | 1951 | Error *err = NULL; |
fafa4d50 | 1952 | |
533fdaed | 1953 | list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err); |
0ca117a7 | 1954 | if (hmp_handle_error(mon, err)) { |
fafa4d50 SF |
1955 | return; |
1956 | } | |
1957 | ||
1958 | monitor_printf(mon, "prio tbl hits key(mask) --> actions\n"); | |
1959 | ||
1960 | for (info = list; info; info = info->next) { | |
1961 | RockerOfDpaFlow *flow = info->value; | |
1962 | RockerOfDpaFlowKey *key = flow->key; | |
1963 | RockerOfDpaFlowMask *mask = flow->mask; | |
1964 | RockerOfDpaFlowAction *action = flow->action; | |
1965 | ||
1966 | if (flow->hits) { | |
1967 | monitor_printf(mon, "%-4d %-3d %-4" PRIu64, | |
1968 | key->priority, key->tbl_id, flow->hits); | |
1969 | } else { | |
1970 | monitor_printf(mon, "%-4d %-3d ", | |
1971 | key->priority, key->tbl_id); | |
1972 | } | |
1973 | ||
1974 | if (key->has_in_pport) { | |
1975 | monitor_printf(mon, " pport %d", key->in_pport); | |
1976 | if (mask->has_in_pport) { | |
1977 | monitor_printf(mon, "(0x%x)", mask->in_pport); | |
1978 | } | |
1979 | } | |
1980 | ||
1981 | if (key->has_vlan_id) { | |
1982 | monitor_printf(mon, " vlan %d", | |
1983 | key->vlan_id & VLAN_VID_MASK); | |
1984 | if (mask->has_vlan_id) { | |
1985 | monitor_printf(mon, "(0x%x)", mask->vlan_id); | |
1986 | } | |
1987 | } | |
1988 | ||
1989 | if (key->has_tunnel_id) { | |
1990 | monitor_printf(mon, " tunnel %d", key->tunnel_id); | |
1991 | if (mask->has_tunnel_id) { | |
1992 | monitor_printf(mon, "(0x%x)", mask->tunnel_id); | |
1993 | } | |
1994 | } | |
1995 | ||
1996 | if (key->has_eth_type) { | |
1997 | switch (key->eth_type) { | |
1998 | case 0x0806: | |
1999 | monitor_printf(mon, " ARP"); | |
2000 | break; | |
2001 | case 0x0800: | |
2002 | monitor_printf(mon, " IP"); | |
2003 | break; | |
2004 | case 0x86dd: | |
2005 | monitor_printf(mon, " IPv6"); | |
2006 | break; | |
2007 | case 0x8809: | |
2008 | monitor_printf(mon, " LACP"); | |
2009 | break; | |
2010 | case 0x88cc: | |
2011 | monitor_printf(mon, " LLDP"); | |
2012 | break; | |
2013 | default: | |
2014 | monitor_printf(mon, " eth type 0x%04x", key->eth_type); | |
2015 | break; | |
2016 | } | |
2017 | } | |
2018 | ||
2019 | if (key->has_eth_src) { | |
2020 | if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) && | |
2021 | (mask->has_eth_src) && | |
2022 | (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { | |
2023 | monitor_printf(mon, " src <any mcast/bcast>"); | |
2024 | } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) && | |
2025 | (mask->has_eth_src) && | |
2026 | (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { | |
2027 | monitor_printf(mon, " src <any ucast>"); | |
2028 | } else { | |
2029 | monitor_printf(mon, " src %s", key->eth_src); | |
2030 | if (mask->has_eth_src) { | |
2031 | monitor_printf(mon, "(%s)", mask->eth_src); | |
2032 | } | |
2033 | } | |
2034 | } | |
2035 | ||
2036 | if (key->has_eth_dst) { | |
2037 | if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) && | |
2038 | (mask->has_eth_dst) && | |
2039 | (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { | |
2040 | monitor_printf(mon, " dst <any mcast/bcast>"); | |
2041 | } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) && | |
2042 | (mask->has_eth_dst) && | |
2043 | (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { | |
2044 | monitor_printf(mon, " dst <any ucast>"); | |
2045 | } else { | |
2046 | monitor_printf(mon, " dst %s", key->eth_dst); | |
2047 | if (mask->has_eth_dst) { | |
2048 | monitor_printf(mon, "(%s)", mask->eth_dst); | |
2049 | } | |
2050 | } | |
2051 | } | |
2052 | ||
2053 | if (key->has_ip_proto) { | |
2054 | monitor_printf(mon, " proto %d", key->ip_proto); | |
2055 | if (mask->has_ip_proto) { | |
2056 | monitor_printf(mon, "(0x%x)", mask->ip_proto); | |
2057 | } | |
2058 | } | |
2059 | ||
2060 | if (key->has_ip_tos) { | |
2061 | monitor_printf(mon, " TOS %d", key->ip_tos); | |
2062 | if (mask->has_ip_tos) { | |
2063 | monitor_printf(mon, "(0x%x)", mask->ip_tos); | |
2064 | } | |
2065 | } | |
2066 | ||
2067 | if (key->has_ip_dst) { | |
2068 | monitor_printf(mon, " dst %s", key->ip_dst); | |
2069 | } | |
2070 | ||
2071 | if (action->has_goto_tbl || action->has_group_id || | |
2072 | action->has_new_vlan_id) { | |
2073 | monitor_printf(mon, " -->"); | |
2074 | } | |
2075 | ||
2076 | if (action->has_new_vlan_id) { | |
2077 | monitor_printf(mon, " apply new vlan %d", | |
2078 | ntohs(action->new_vlan_id)); | |
2079 | } | |
2080 | ||
2081 | if (action->has_group_id) { | |
2082 | monitor_printf(mon, " write group 0x%08x", action->group_id); | |
2083 | } | |
2084 | ||
2085 | if (action->has_goto_tbl) { | |
2086 | monitor_printf(mon, " goto tbl %d", action->goto_tbl); | |
2087 | } | |
2088 | ||
2089 | monitor_printf(mon, "\n"); | |
2090 | } | |
2091 | ||
2092 | qapi_free_RockerOfDpaFlowList(list); | |
2093 | } | |
2094 | ||
2095 | void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict) | |
2096 | { | |
2097 | RockerOfDpaGroupList *list, *g; | |
2098 | const char *name = qdict_get_str(qdict, "name"); | |
2099 | uint8_t type = qdict_get_try_int(qdict, "type", 9); | |
533fdaed | 2100 | Error *err = NULL; |
fafa4d50 | 2101 | |
533fdaed | 2102 | list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err); |
0ca117a7 | 2103 | if (hmp_handle_error(mon, err)) { |
fafa4d50 SF |
2104 | return; |
2105 | } | |
2106 | ||
2107 | monitor_printf(mon, "id (decode) --> buckets\n"); | |
2108 | ||
2109 | for (g = list; g; g = g->next) { | |
2110 | RockerOfDpaGroup *group = g->value; | |
916c9250 | 2111 | bool set = false; |
fafa4d50 SF |
2112 | |
2113 | monitor_printf(mon, "0x%08x", group->id); | |
2114 | ||
2115 | monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" : | |
2116 | group->type == 1 ? "L2 rewrite" : | |
2117 | group->type == 2 ? "L3 unicast" : | |
2118 | group->type == 3 ? "L2 multicast" : | |
2119 | group->type == 4 ? "L2 flood" : | |
2120 | group->type == 5 ? "L3 interface" : | |
2121 | group->type == 6 ? "L3 multicast" : | |
2122 | group->type == 7 ? "L3 ECMP" : | |
2123 | group->type == 8 ? "L2 overlay" : | |
2124 | "unknown"); | |
2125 | ||
2126 | if (group->has_vlan_id) { | |
2127 | monitor_printf(mon, " vlan %d", group->vlan_id); | |
2128 | } | |
2129 | ||
2130 | if (group->has_pport) { | |
2131 | monitor_printf(mon, " pport %d", group->pport); | |
2132 | } | |
2133 | ||
2134 | if (group->has_index) { | |
2135 | monitor_printf(mon, " index %d", group->index); | |
2136 | } | |
2137 | ||
2138 | monitor_printf(mon, ") -->"); | |
2139 | ||
2140 | if (group->has_set_vlan_id && group->set_vlan_id) { | |
2141 | set = true; | |
2142 | monitor_printf(mon, " set vlan %d", | |
2143 | group->set_vlan_id & VLAN_VID_MASK); | |
2144 | } | |
2145 | ||
2146 | if (group->has_set_eth_src) { | |
2147 | if (!set) { | |
2148 | set = true; | |
2149 | monitor_printf(mon, " set"); | |
2150 | } | |
2151 | monitor_printf(mon, " src %s", group->set_eth_src); | |
2152 | } | |
2153 | ||
2154 | if (group->has_set_eth_dst) { | |
2155 | if (!set) { | |
fafa4d50 SF |
2156 | monitor_printf(mon, " set"); |
2157 | } | |
2158 | monitor_printf(mon, " dst %s", group->set_eth_dst); | |
2159 | } | |
2160 | ||
fafa4d50 SF |
2161 | if (group->has_ttl_check && group->ttl_check) { |
2162 | monitor_printf(mon, " check TTL"); | |
2163 | } | |
2164 | ||
2165 | if (group->has_group_id && group->group_id) { | |
2166 | monitor_printf(mon, " group id 0x%08x", group->group_id); | |
2167 | } | |
2168 | ||
2169 | if (group->has_pop_vlan && group->pop_vlan) { | |
2170 | monitor_printf(mon, " pop vlan"); | |
2171 | } | |
2172 | ||
2173 | if (group->has_out_pport) { | |
2174 | monitor_printf(mon, " out pport %d", group->out_pport); | |
2175 | } | |
2176 | ||
2177 | if (group->has_group_ids) { | |
2178 | struct uint32List *id; | |
2179 | ||
2180 | monitor_printf(mon, " groups ["); | |
2181 | for (id = group->group_ids; id; id = id->next) { | |
2182 | monitor_printf(mon, "0x%08x", id->value); | |
2183 | if (id->next) { | |
2184 | monitor_printf(mon, ","); | |
2185 | } | |
2186 | } | |
2187 | monitor_printf(mon, "]"); | |
2188 | } | |
2189 | ||
2190 | monitor_printf(mon, "\n"); | |
2191 | } | |
2192 | ||
2193 | qapi_free_RockerOfDpaGroupList(list); | |
2194 | } | |
4a6b52d6 | 2195 | |
39164c13 IM |
2196 | void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict) |
2197 | { | |
72d9196f BW |
2198 | Error *err = NULL; |
2199 | GuidInfo *info = qmp_query_vm_generation_id(&err); | |
39164c13 IM |
2200 | if (info) { |
2201 | monitor_printf(mon, "%s\n", info->guid); | |
2202 | } | |
187c6147 | 2203 | hmp_handle_error(mon, err); |
39164c13 IM |
2204 | qapi_free_GuidInfo(info); |
2205 | } | |
d0f63c1e VG |
2206 | |
2207 | void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict) | |
2208 | { | |
2209 | Error *err = NULL; | |
2210 | MemoryInfo *info = qmp_query_memory_size_summary(&err); | |
2211 | if (info) { | |
2212 | monitor_printf(mon, "base memory: %" PRIu64 "\n", | |
2213 | info->base_memory); | |
2214 | ||
2215 | if (info->has_plugged_memory) { | |
2216 | monitor_printf(mon, "plugged memory: %" PRIu64 "\n", | |
2217 | info->plugged_memory); | |
2218 | } | |
2219 | ||
2220 | qapi_free_MemoryInfo(info); | |
2221 | } | |
187c6147 | 2222 | hmp_handle_error(mon, err); |
d0f63c1e | 2223 | } |