ui: Fix silent truncation of numeric keys in HMP sendkey
[qemu.git] / monitor / hmp-cmds.c
blob9947ff0b453c8a6f91e6b9456396fe7b43866fd4
1 /*
2 * Human Monitor Interface commands
4 * Copyright IBM, Corp. 2011
6 * Authors:
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 "net/net.h"
19 #include "net/eth.h"
20 #include "chardev/char.h"
21 #include "sysemu/block-backend.h"
22 #include "sysemu/runstate.h"
23 #include "qemu/config-file.h"
24 #include "qemu/option.h"
25 #include "qemu/timer.h"
26 #include "qemu/sockets.h"
27 #include "qemu/help_option.h"
28 #include "monitor/monitor-internal.h"
29 #include "qapi/error.h"
30 #include "qapi/clone-visitor.h"
31 #include "qapi/opts-visitor.h"
32 #include "qapi/qapi-builtin-visit.h"
33 #include "qapi/qapi-commands-block.h"
34 #include "qapi/qapi-commands-char.h"
35 #include "qapi/qapi-commands-control.h"
36 #include "qapi/qapi-commands-machine.h"
37 #include "qapi/qapi-commands-migration.h"
38 #include "qapi/qapi-commands-misc.h"
39 #include "qapi/qapi-commands-net.h"
40 #include "qapi/qapi-commands-rocker.h"
41 #include "qapi/qapi-commands-run-state.h"
42 #include "qapi/qapi-commands-stats.h"
43 #include "qapi/qapi-commands-tpm.h"
44 #include "qapi/qapi-commands-ui.h"
45 #include "qapi/qapi-commands-virtio.h"
46 #include "qapi/qapi-visit-virtio.h"
47 #include "qapi/qapi-visit-net.h"
48 #include "qapi/qapi-visit-migration.h"
49 #include "qapi/qmp/qdict.h"
50 #include "qapi/qmp/qerror.h"
51 #include "qapi/string-input-visitor.h"
52 #include "qapi/string-output-visitor.h"
53 #include "qom/object_interfaces.h"
54 #include "ui/console.h"
55 #include "qemu/cutils.h"
56 #include "qemu/error-report.h"
57 #include "hw/core/cpu.h"
58 #include "hw/intc/intc.h"
59 #include "migration/snapshot.h"
60 #include "migration/misc.h"
62 #ifdef CONFIG_SPICE
63 #include <spice/enums.h>
64 #endif
66 bool hmp_handle_error(Monitor *mon, Error *err)
68 if (err) {
69 error_reportf_err(err, "Error: ");
70 return true;
72 return false;
76 * Produce a strList from a comma separated list.
77 * A NULL or empty input string return NULL.
79 static strList *strList_from_comma_list(const char *in)
81 strList *res = NULL;
82 strList **tail = &res;
84 while (in && in[0]) {
85 char *comma = strchr(in, ',');
86 char *value;
88 if (comma) {
89 value = g_strndup(in, comma - in);
90 in = comma + 1; /* skip the , */
91 } else {
92 value = g_strdup(in);
93 in = NULL;
95 QAPI_LIST_APPEND(tail, value);
98 return res;
101 void hmp_info_name(Monitor *mon, const QDict *qdict)
103 NameInfo *info;
105 info = qmp_query_name(NULL);
106 if (info->name) {
107 monitor_printf(mon, "%s\n", info->name);
109 qapi_free_NameInfo(info);
112 void hmp_info_version(Monitor *mon, const QDict *qdict)
114 VersionInfo *info;
116 info = qmp_query_version(NULL);
118 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
119 info->qemu->major, info->qemu->minor, info->qemu->micro,
120 info->package);
122 qapi_free_VersionInfo(info);
125 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
127 KvmInfo *info;
129 info = qmp_query_kvm(NULL);
130 monitor_printf(mon, "kvm support: ");
131 if (info->present) {
132 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
133 } else {
134 monitor_printf(mon, "not compiled\n");
137 qapi_free_KvmInfo(info);
140 void hmp_info_status(Monitor *mon, const QDict *qdict)
142 StatusInfo *info;
144 info = qmp_query_status(NULL);
146 monitor_printf(mon, "VM status: %s%s",
147 info->running ? "running" : "paused",
148 info->singlestep ? " (single step mode)" : "");
150 if (!info->running && info->status != RUN_STATE_PAUSED) {
151 monitor_printf(mon, " (%s)", RunState_str(info->status));
154 monitor_printf(mon, "\n");
156 qapi_free_StatusInfo(info);
159 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
161 UuidInfo *info;
163 info = qmp_query_uuid(NULL);
164 monitor_printf(mon, "%s\n", info->UUID);
165 qapi_free_UuidInfo(info);
168 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
170 ChardevInfoList *char_info, *info;
172 char_info = qmp_query_chardev(NULL);
173 for (info = char_info; info; info = info->next) {
174 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
175 info->value->filename);
178 qapi_free_ChardevInfoList(char_info);
181 void hmp_info_mice(Monitor *mon, const QDict *qdict)
183 MouseInfoList *mice_list, *mouse;
185 mice_list = qmp_query_mice(NULL);
186 if (!mice_list) {
187 monitor_printf(mon, "No mouse devices connected\n");
188 return;
191 for (mouse = mice_list; mouse; mouse = mouse->next) {
192 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
193 mouse->value->current ? '*' : ' ',
194 mouse->value->index, mouse->value->name,
195 mouse->value->absolute ? " (absolute)" : "");
198 qapi_free_MouseInfoList(mice_list);
201 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
203 MigrationInfo *info;
205 info = qmp_query_migrate(NULL);
207 migration_global_dump(mon);
209 if (info->blocked_reasons) {
210 strList *reasons = info->blocked_reasons;
211 monitor_printf(mon, "Outgoing migration blocked:\n");
212 while (reasons) {
213 monitor_printf(mon, " %s\n", reasons->value);
214 reasons = reasons->next;
218 if (info->has_status) {
219 monitor_printf(mon, "Migration status: %s",
220 MigrationStatus_str(info->status));
221 if (info->status == MIGRATION_STATUS_FAILED && info->error_desc) {
222 monitor_printf(mon, " (%s)\n", info->error_desc);
223 } else {
224 monitor_printf(mon, "\n");
227 monitor_printf(mon, "total time: %" PRIu64 " ms\n",
228 info->total_time);
229 if (info->has_expected_downtime) {
230 monitor_printf(mon, "expected downtime: %" PRIu64 " ms\n",
231 info->expected_downtime);
233 if (info->has_downtime) {
234 monitor_printf(mon, "downtime: %" PRIu64 " ms\n",
235 info->downtime);
237 if (info->has_setup_time) {
238 monitor_printf(mon, "setup: %" PRIu64 " ms\n",
239 info->setup_time);
243 if (info->ram) {
244 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
245 info->ram->transferred >> 10);
246 monitor_printf(mon, "throughput: %0.2f mbps\n",
247 info->ram->mbps);
248 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
249 info->ram->remaining >> 10);
250 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
251 info->ram->total >> 10);
252 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
253 info->ram->duplicate);
254 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
255 info->ram->skipped);
256 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
257 info->ram->normal);
258 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
259 info->ram->normal_bytes >> 10);
260 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
261 info->ram->dirty_sync_count);
262 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
263 info->ram->page_size >> 10);
264 monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n",
265 info->ram->multifd_bytes >> 10);
266 monitor_printf(mon, "pages-per-second: %" PRIu64 "\n",
267 info->ram->pages_per_second);
269 if (info->ram->dirty_pages_rate) {
270 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
271 info->ram->dirty_pages_rate);
273 if (info->ram->postcopy_requests) {
274 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
275 info->ram->postcopy_requests);
277 if (info->ram->precopy_bytes) {
278 monitor_printf(mon, "precopy ram: %" PRIu64 " kbytes\n",
279 info->ram->precopy_bytes >> 10);
281 if (info->ram->downtime_bytes) {
282 monitor_printf(mon, "downtime ram: %" PRIu64 " kbytes\n",
283 info->ram->downtime_bytes >> 10);
285 if (info->ram->postcopy_bytes) {
286 monitor_printf(mon, "postcopy ram: %" PRIu64 " kbytes\n",
287 info->ram->postcopy_bytes >> 10);
289 if (info->ram->dirty_sync_missed_zero_copy) {
290 monitor_printf(mon,
291 "Zero-copy-send fallbacks happened: %" PRIu64 " times\n",
292 info->ram->dirty_sync_missed_zero_copy);
296 if (info->disk) {
297 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
298 info->disk->transferred >> 10);
299 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
300 info->disk->remaining >> 10);
301 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
302 info->disk->total >> 10);
305 if (info->xbzrle_cache) {
306 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
307 info->xbzrle_cache->cache_size);
308 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
309 info->xbzrle_cache->bytes >> 10);
310 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
311 info->xbzrle_cache->pages);
312 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 " pages\n",
313 info->xbzrle_cache->cache_miss);
314 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
315 info->xbzrle_cache->cache_miss_rate);
316 monitor_printf(mon, "xbzrle encoding rate: %0.2f\n",
317 info->xbzrle_cache->encoding_rate);
318 monitor_printf(mon, "xbzrle overflow: %" PRIu64 "\n",
319 info->xbzrle_cache->overflow);
322 if (info->compression) {
323 monitor_printf(mon, "compression pages: %" PRIu64 " pages\n",
324 info->compression->pages);
325 monitor_printf(mon, "compression busy: %" PRIu64 "\n",
326 info->compression->busy);
327 monitor_printf(mon, "compression busy rate: %0.2f\n",
328 info->compression->busy_rate);
329 monitor_printf(mon, "compressed size: %" PRIu64 " kbytes\n",
330 info->compression->compressed_size >> 10);
331 monitor_printf(mon, "compression rate: %0.2f\n",
332 info->compression->compression_rate);
335 if (info->has_cpu_throttle_percentage) {
336 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
337 info->cpu_throttle_percentage);
340 if (info->has_postcopy_blocktime) {
341 monitor_printf(mon, "postcopy blocktime: %u\n",
342 info->postcopy_blocktime);
345 if (info->has_postcopy_vcpu_blocktime) {
346 Visitor *v;
347 char *str;
348 v = string_output_visitor_new(false, &str);
349 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime,
350 &error_abort);
351 visit_complete(v, &str);
352 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
353 g_free(str);
354 visit_free(v);
356 if (info->has_socket_address) {
357 SocketAddressList *addr;
359 monitor_printf(mon, "socket address: [\n");
361 for (addr = info->socket_address; addr; addr = addr->next) {
362 char *s = socket_uri(addr->value);
363 monitor_printf(mon, "\t%s\n", s);
364 g_free(s);
366 monitor_printf(mon, "]\n");
369 if (info->vfio) {
370 monitor_printf(mon, "vfio device transferred: %" PRIu64 " kbytes\n",
371 info->vfio->transferred >> 10);
374 qapi_free_MigrationInfo(info);
377 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
379 MigrationCapabilityStatusList *caps, *cap;
381 caps = qmp_query_migrate_capabilities(NULL);
383 if (caps) {
384 for (cap = caps; cap; cap = cap->next) {
385 monitor_printf(mon, "%s: %s\n",
386 MigrationCapability_str(cap->value->capability),
387 cap->value->state ? "on" : "off");
391 qapi_free_MigrationCapabilityStatusList(caps);
394 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
396 MigrationParameters *params;
398 params = qmp_query_migrate_parameters(NULL);
400 if (params) {
401 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
402 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL),
403 params->announce_initial);
404 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
405 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX),
406 params->announce_max);
407 monitor_printf(mon, "%s: %" PRIu64 "\n",
408 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS),
409 params->announce_rounds);
410 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
411 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP),
412 params->announce_step);
413 assert(params->has_compress_level);
414 monitor_printf(mon, "%s: %u\n",
415 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
416 params->compress_level);
417 assert(params->has_compress_threads);
418 monitor_printf(mon, "%s: %u\n",
419 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
420 params->compress_threads);
421 assert(params->has_compress_wait_thread);
422 monitor_printf(mon, "%s: %s\n",
423 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD),
424 params->compress_wait_thread ? "on" : "off");
425 assert(params->has_decompress_threads);
426 monitor_printf(mon, "%s: %u\n",
427 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
428 params->decompress_threads);
429 assert(params->has_throttle_trigger_threshold);
430 monitor_printf(mon, "%s: %u\n",
431 MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD),
432 params->throttle_trigger_threshold);
433 assert(params->has_cpu_throttle_initial);
434 monitor_printf(mon, "%s: %u\n",
435 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
436 params->cpu_throttle_initial);
437 assert(params->has_cpu_throttle_increment);
438 monitor_printf(mon, "%s: %u\n",
439 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
440 params->cpu_throttle_increment);
441 assert(params->has_cpu_throttle_tailslow);
442 monitor_printf(mon, "%s: %s\n",
443 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW),
444 params->cpu_throttle_tailslow ? "on" : "off");
445 assert(params->has_max_cpu_throttle);
446 monitor_printf(mon, "%s: %u\n",
447 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE),
448 params->max_cpu_throttle);
449 assert(params->tls_creds);
450 monitor_printf(mon, "%s: '%s'\n",
451 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
452 params->tls_creds);
453 assert(params->tls_hostname);
454 monitor_printf(mon, "%s: '%s'\n",
455 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
456 params->tls_hostname);
457 assert(params->has_max_bandwidth);
458 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
459 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
460 params->max_bandwidth);
461 assert(params->has_downtime_limit);
462 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
463 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
464 params->downtime_limit);
465 assert(params->has_x_checkpoint_delay);
466 monitor_printf(mon, "%s: %u ms\n",
467 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
468 params->x_checkpoint_delay);
469 assert(params->has_block_incremental);
470 monitor_printf(mon, "%s: %s\n",
471 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
472 params->block_incremental ? "on" : "off");
473 monitor_printf(mon, "%s: %u\n",
474 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS),
475 params->multifd_channels);
476 monitor_printf(mon, "%s: %s\n",
477 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION),
478 MultiFDCompression_str(params->multifd_compression));
479 monitor_printf(mon, "%s: %" PRIu64 " bytes\n",
480 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
481 params->xbzrle_cache_size);
482 monitor_printf(mon, "%s: %" PRIu64 "\n",
483 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
484 params->max_postcopy_bandwidth);
485 monitor_printf(mon, "%s: '%s'\n",
486 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
487 params->tls_authz);
489 if (params->has_block_bitmap_mapping) {
490 const BitmapMigrationNodeAliasList *bmnal;
492 monitor_printf(mon, "%s:\n",
493 MigrationParameter_str(
494 MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING));
496 for (bmnal = params->block_bitmap_mapping;
497 bmnal;
498 bmnal = bmnal->next)
500 const BitmapMigrationNodeAlias *bmna = bmnal->value;
501 const BitmapMigrationBitmapAliasList *bmbal;
503 monitor_printf(mon, " '%s' -> '%s'\n",
504 bmna->node_name, bmna->alias);
506 for (bmbal = bmna->bitmaps; bmbal; bmbal = bmbal->next) {
507 const BitmapMigrationBitmapAlias *bmba = bmbal->value;
509 monitor_printf(mon, " '%s' -> '%s'\n",
510 bmba->name, bmba->alias);
516 qapi_free_MigrationParameters(params);
520 #ifdef CONFIG_VNC
521 /* Helper for hmp_info_vnc_clients, _servers */
522 static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
523 const char *name)
525 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
526 name,
527 info->host,
528 info->service,
529 NetworkAddressFamily_str(info->family),
530 info->websocket ? " (Websocket)" : "");
533 /* Helper displaying and auth and crypt info */
534 static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
535 VncPrimaryAuth auth,
536 VncVencryptSubAuth *vencrypt)
538 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
539 VncPrimaryAuth_str(auth),
540 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
543 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
545 while (client) {
546 VncClientInfo *cinfo = client->value;
548 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
549 monitor_printf(mon, " x509_dname: %s\n",
550 cinfo->x509_dname ?: "none");
551 monitor_printf(mon, " sasl_username: %s\n",
552 cinfo->sasl_username ?: "none");
554 client = client->next;
558 static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
560 while (server) {
561 VncServerInfo2 *sinfo = server->value;
562 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
563 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
564 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
565 server = server->next;
569 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
571 VncInfo2List *info2l, *info2l_head;
572 Error *err = NULL;
574 info2l = qmp_query_vnc_servers(&err);
575 info2l_head = info2l;
576 if (hmp_handle_error(mon, err)) {
577 return;
579 if (!info2l) {
580 monitor_printf(mon, "None\n");
581 return;
584 while (info2l) {
585 VncInfo2 *info = info2l->value;
586 monitor_printf(mon, "%s:\n", info->id);
587 hmp_info_vnc_servers(mon, info->server);
588 hmp_info_vnc_clients(mon, info->clients);
589 if (!info->server) {
590 /* The server entry displays its auth, we only
591 * need to display in the case of 'reverse' connections
592 * where there's no server.
594 hmp_info_vnc_authcrypt(mon, " ", info->auth,
595 info->has_vencrypt ? &info->vencrypt : NULL);
597 if (info->display) {
598 monitor_printf(mon, " Display: %s\n", info->display);
600 info2l = info2l->next;
603 qapi_free_VncInfo2List(info2l_head);
606 #endif
608 #ifdef CONFIG_SPICE
609 void hmp_info_spice(Monitor *mon, const QDict *qdict)
611 SpiceChannelList *chan;
612 SpiceInfo *info;
613 const char *channel_name;
614 const char * const channel_names[] = {
615 [SPICE_CHANNEL_MAIN] = "main",
616 [SPICE_CHANNEL_DISPLAY] = "display",
617 [SPICE_CHANNEL_INPUTS] = "inputs",
618 [SPICE_CHANNEL_CURSOR] = "cursor",
619 [SPICE_CHANNEL_PLAYBACK] = "playback",
620 [SPICE_CHANNEL_RECORD] = "record",
621 [SPICE_CHANNEL_TUNNEL] = "tunnel",
622 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
623 [SPICE_CHANNEL_USBREDIR] = "usbredir",
624 [SPICE_CHANNEL_PORT] = "port",
625 #if 0
626 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
627 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
628 * as quick fix for build failures with older versions. */
629 [SPICE_CHANNEL_WEBDAV] = "webdav",
630 #endif
633 info = qmp_query_spice(NULL);
635 if (!info->enabled) {
636 monitor_printf(mon, "Server: disabled\n");
637 goto out;
640 monitor_printf(mon, "Server:\n");
641 if (info->has_port) {
642 monitor_printf(mon, " address: %s:%" PRId64 "\n",
643 info->host, info->port);
645 if (info->has_tls_port) {
646 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
647 info->host, info->tls_port);
649 monitor_printf(mon, " migrated: %s\n",
650 info->migrated ? "true" : "false");
651 monitor_printf(mon, " auth: %s\n", info->auth);
652 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
653 monitor_printf(mon, " mouse-mode: %s\n",
654 SpiceQueryMouseMode_str(info->mouse_mode));
656 if (!info->has_channels || info->channels == NULL) {
657 monitor_printf(mon, "Channels: none\n");
658 } else {
659 for (chan = info->channels; chan; chan = chan->next) {
660 monitor_printf(mon, "Channel:\n");
661 monitor_printf(mon, " address: %s:%s%s\n",
662 chan->value->host, chan->value->port,
663 chan->value->tls ? " [tls]" : "");
664 monitor_printf(mon, " session: %" PRId64 "\n",
665 chan->value->connection_id);
666 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
667 chan->value->channel_type, chan->value->channel_id);
669 channel_name = "unknown";
670 if (chan->value->channel_type > 0 &&
671 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
672 channel_names[chan->value->channel_type]) {
673 channel_name = channel_names[chan->value->channel_type];
676 monitor_printf(mon, " channel name: %s\n", channel_name);
680 out:
681 qapi_free_SpiceInfo(info);
683 #endif
685 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
687 BalloonInfo *info;
688 Error *err = NULL;
690 info = qmp_query_balloon(&err);
691 if (hmp_handle_error(mon, err)) {
692 return;
695 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
697 qapi_free_BalloonInfo(info);
700 static int hmp_info_pic_foreach(Object *obj, void *opaque)
702 InterruptStatsProvider *intc;
703 InterruptStatsProviderClass *k;
704 Monitor *mon = opaque;
706 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
707 intc = INTERRUPT_STATS_PROVIDER(obj);
708 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
709 if (k->print_info) {
710 k->print_info(intc, mon);
711 } else {
712 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
713 object_get_typename(obj));
717 return 0;
720 void hmp_info_pic(Monitor *mon, const QDict *qdict)
722 object_child_foreach_recursive(object_get_root(),
723 hmp_info_pic_foreach, mon);
726 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
728 #ifdef CONFIG_TPM
729 TPMInfoList *info_list, *info;
730 Error *err = NULL;
731 unsigned int c = 0;
732 TPMPassthroughOptions *tpo;
733 TPMEmulatorOptions *teo;
735 info_list = qmp_query_tpm(&err);
736 if (err) {
737 monitor_printf(mon, "TPM device not supported\n");
738 error_free(err);
739 return;
742 if (info_list) {
743 monitor_printf(mon, "TPM device:\n");
746 for (info = info_list; info; info = info->next) {
747 TPMInfo *ti = info->value;
748 monitor_printf(mon, " tpm%d: model=%s\n",
749 c, TpmModel_str(ti->model));
751 monitor_printf(mon, " \\ %s: type=%s",
752 ti->id, TpmType_str(ti->options->type));
754 switch (ti->options->type) {
755 case TPM_TYPE_PASSTHROUGH:
756 tpo = ti->options->u.passthrough.data;
757 monitor_printf(mon, "%s%s%s%s",
758 tpo->path ? ",path=" : "",
759 tpo->path ?: "",
760 tpo->cancel_path ? ",cancel-path=" : "",
761 tpo->cancel_path ?: "");
762 break;
763 case TPM_TYPE_EMULATOR:
764 teo = ti->options->u.emulator.data;
765 monitor_printf(mon, ",chardev=%s", teo->chardev);
766 break;
767 case TPM_TYPE__MAX:
768 break;
770 monitor_printf(mon, "\n");
771 c++;
773 qapi_free_TPMInfoList(info_list);
774 #else
775 monitor_printf(mon, "TPM device not supported\n");
776 #endif /* CONFIG_TPM */
779 void hmp_quit(Monitor *mon, const QDict *qdict)
781 monitor_suspend(mon);
782 qmp_quit(NULL);
785 void hmp_stop(Monitor *mon, const QDict *qdict)
787 qmp_stop(NULL);
790 void hmp_sync_profile(Monitor *mon, const QDict *qdict)
792 const char *op = qdict_get_try_str(qdict, "op");
794 if (op == NULL) {
795 bool on = qsp_is_enabled();
797 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off");
798 return;
800 if (!strcmp(op, "on")) {
801 qsp_enable();
802 } else if (!strcmp(op, "off")) {
803 qsp_disable();
804 } else if (!strcmp(op, "reset")) {
805 qsp_reset();
806 } else {
807 Error *err = NULL;
809 error_setg(&err, QERR_INVALID_PARAMETER, op);
810 hmp_handle_error(mon, err);
814 void hmp_system_reset(Monitor *mon, const QDict *qdict)
816 qmp_system_reset(NULL);
819 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
821 qmp_system_powerdown(NULL);
824 void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
826 Error *err = NULL;
828 qmp_x_exit_preconfig(&err);
829 hmp_handle_error(mon, err);
832 void hmp_cpu(Monitor *mon, const QDict *qdict)
834 int64_t cpu_index;
836 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
837 use it are converted to the QAPI */
838 cpu_index = qdict_get_int(qdict, "index");
839 if (monitor_set_cpu(mon, cpu_index) < 0) {
840 monitor_printf(mon, "invalid CPU index\n");
844 void hmp_memsave(Monitor *mon, const QDict *qdict)
846 uint32_t size = qdict_get_int(qdict, "size");
847 const char *filename = qdict_get_str(qdict, "filename");
848 uint64_t addr = qdict_get_int(qdict, "val");
849 Error *err = NULL;
850 int cpu_index = monitor_get_cpu_index(mon);
852 if (cpu_index < 0) {
853 monitor_printf(mon, "No CPU available\n");
854 return;
857 qmp_memsave(addr, size, filename, true, cpu_index, &err);
858 hmp_handle_error(mon, err);
861 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
863 uint32_t size = qdict_get_int(qdict, "size");
864 const char *filename = qdict_get_str(qdict, "filename");
865 uint64_t addr = qdict_get_int(qdict, "val");
866 Error *err = NULL;
868 qmp_pmemsave(addr, size, filename, &err);
869 hmp_handle_error(mon, err);
872 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
874 const char *chardev = qdict_get_str(qdict, "device");
875 const char *data = qdict_get_str(qdict, "data");
876 Error *err = NULL;
878 qmp_ringbuf_write(chardev, data, false, 0, &err);
880 hmp_handle_error(mon, err);
883 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
885 uint32_t size = qdict_get_int(qdict, "size");
886 const char *chardev = qdict_get_str(qdict, "device");
887 char *data;
888 Error *err = NULL;
889 int i;
891 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
892 if (hmp_handle_error(mon, err)) {
893 return;
896 for (i = 0; data[i]; i++) {
897 unsigned char ch = data[i];
899 if (ch == '\\') {
900 monitor_printf(mon, "\\\\");
901 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
902 monitor_printf(mon, "\\u%04X", ch);
903 } else {
904 monitor_printf(mon, "%c", ch);
908 monitor_printf(mon, "\n");
909 g_free(data);
912 void hmp_cont(Monitor *mon, const QDict *qdict)
914 Error *err = NULL;
916 qmp_cont(&err);
917 hmp_handle_error(mon, err);
920 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
922 Error *err = NULL;
924 qmp_system_wakeup(&err);
925 hmp_handle_error(mon, err);
928 void hmp_nmi(Monitor *mon, const QDict *qdict)
930 Error *err = NULL;
932 qmp_inject_nmi(&err);
933 hmp_handle_error(mon, err);
936 void hmp_set_link(Monitor *mon, const QDict *qdict)
938 const char *name = qdict_get_str(qdict, "name");
939 bool up = qdict_get_bool(qdict, "up");
940 Error *err = NULL;
942 qmp_set_link(name, up, &err);
943 hmp_handle_error(mon, err);
946 void hmp_balloon(Monitor *mon, const QDict *qdict)
948 int64_t value = qdict_get_int(qdict, "value");
949 Error *err = NULL;
951 qmp_balloon(value, &err);
952 hmp_handle_error(mon, err);
955 void hmp_loadvm(Monitor *mon, const QDict *qdict)
957 int saved_vm_running = runstate_is_running();
958 const char *name = qdict_get_str(qdict, "name");
959 Error *err = NULL;
961 vm_stop(RUN_STATE_RESTORE_VM);
963 if (load_snapshot(name, NULL, false, NULL, &err) && saved_vm_running) {
964 vm_start();
966 hmp_handle_error(mon, err);
969 void hmp_savevm(Monitor *mon, const QDict *qdict)
971 Error *err = NULL;
973 save_snapshot(qdict_get_try_str(qdict, "name"),
974 true, NULL, false, NULL, &err);
975 hmp_handle_error(mon, err);
978 void hmp_delvm(Monitor *mon, const QDict *qdict)
980 Error *err = NULL;
981 const char *name = qdict_get_str(qdict, "name");
983 delete_snapshot(name, false, NULL, &err);
984 hmp_handle_error(mon, err);
987 void hmp_announce_self(Monitor *mon, const QDict *qdict)
989 const char *interfaces_str = qdict_get_try_str(qdict, "interfaces");
990 const char *id = qdict_get_try_str(qdict, "id");
991 AnnounceParameters *params = QAPI_CLONE(AnnounceParameters,
992 migrate_announce_params());
994 qapi_free_strList(params->interfaces);
995 params->interfaces = strList_from_comma_list(interfaces_str);
996 params->has_interfaces = params->interfaces != NULL;
997 params->id = g_strdup(id);
998 qmp_announce_self(params, NULL);
999 qapi_free_AnnounceParameters(params);
1002 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1004 qmp_migrate_cancel(NULL);
1007 void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1009 Error *err = NULL;
1010 const char *state = qdict_get_str(qdict, "state");
1011 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1013 if (val >= 0) {
1014 qmp_migrate_continue(val, &err);
1017 hmp_handle_error(mon, err);
1020 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1022 Error *err = NULL;
1023 const char *uri = qdict_get_str(qdict, "uri");
1025 qmp_migrate_incoming(uri, &err);
1027 hmp_handle_error(mon, err);
1030 void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
1032 Error *err = NULL;
1033 const char *uri = qdict_get_str(qdict, "uri");
1035 qmp_migrate_recover(uri, &err);
1037 hmp_handle_error(mon, err);
1040 void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
1042 Error *err = NULL;
1044 qmp_migrate_pause(&err);
1046 hmp_handle_error(mon, err);
1050 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1052 const char *cap = qdict_get_str(qdict, "capability");
1053 bool state = qdict_get_bool(qdict, "state");
1054 Error *err = NULL;
1055 MigrationCapabilityStatusList *caps = NULL;
1056 MigrationCapabilityStatus *value;
1057 int val;
1059 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
1060 if (val < 0) {
1061 goto end;
1064 value = g_malloc0(sizeof(*value));
1065 value->capability = val;
1066 value->state = state;
1067 QAPI_LIST_PREPEND(caps, value);
1068 qmp_migrate_set_capabilities(caps, &err);
1069 qapi_free_MigrationCapabilityStatusList(caps);
1071 end:
1072 hmp_handle_error(mon, err);
1075 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1077 const char *param = qdict_get_str(qdict, "parameter");
1078 const char *valuestr = qdict_get_str(qdict, "value");
1079 Visitor *v = string_input_visitor_new(valuestr);
1080 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
1081 uint64_t valuebw = 0;
1082 uint64_t cache_size;
1083 Error *err = NULL;
1084 int val, ret;
1086 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
1087 if (val < 0) {
1088 goto cleanup;
1091 switch (val) {
1092 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1093 p->has_compress_level = true;
1094 visit_type_uint8(v, param, &p->compress_level, &err);
1095 break;
1096 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1097 p->has_compress_threads = true;
1098 visit_type_uint8(v, param, &p->compress_threads, &err);
1099 break;
1100 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD:
1101 p->has_compress_wait_thread = true;
1102 visit_type_bool(v, param, &p->compress_wait_thread, &err);
1103 break;
1104 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1105 p->has_decompress_threads = true;
1106 visit_type_uint8(v, param, &p->decompress_threads, &err);
1107 break;
1108 case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD:
1109 p->has_throttle_trigger_threshold = true;
1110 visit_type_uint8(v, param, &p->throttle_trigger_threshold, &err);
1111 break;
1112 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1113 p->has_cpu_throttle_initial = true;
1114 visit_type_uint8(v, param, &p->cpu_throttle_initial, &err);
1115 break;
1116 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1117 p->has_cpu_throttle_increment = true;
1118 visit_type_uint8(v, param, &p->cpu_throttle_increment, &err);
1119 break;
1120 case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW:
1121 p->has_cpu_throttle_tailslow = true;
1122 visit_type_bool(v, param, &p->cpu_throttle_tailslow, &err);
1123 break;
1124 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE:
1125 p->has_max_cpu_throttle = true;
1126 visit_type_uint8(v, param, &p->max_cpu_throttle, &err);
1127 break;
1128 case MIGRATION_PARAMETER_TLS_CREDS:
1129 p->tls_creds = g_new0(StrOrNull, 1);
1130 p->tls_creds->type = QTYPE_QSTRING;
1131 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1132 break;
1133 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1134 p->tls_hostname = g_new0(StrOrNull, 1);
1135 p->tls_hostname->type = QTYPE_QSTRING;
1136 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1137 break;
1138 case MIGRATION_PARAMETER_TLS_AUTHZ:
1139 p->tls_authz = g_new0(StrOrNull, 1);
1140 p->tls_authz->type = QTYPE_QSTRING;
1141 visit_type_str(v, param, &p->tls_authz->u.s, &err);
1142 break;
1143 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1144 p->has_max_bandwidth = true;
1146 * Can't use visit_type_size() here, because it
1147 * defaults to Bytes rather than Mebibytes.
1149 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1150 if (ret < 0 || valuebw > INT64_MAX
1151 || (size_t)valuebw != valuebw) {
1152 error_setg(&err, "Invalid size %s", valuestr);
1153 break;
1155 p->max_bandwidth = valuebw;
1156 break;
1157 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1158 p->has_downtime_limit = true;
1159 visit_type_size(v, param, &p->downtime_limit, &err);
1160 break;
1161 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1162 p->has_x_checkpoint_delay = true;
1163 visit_type_uint32(v, param, &p->x_checkpoint_delay, &err);
1164 break;
1165 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1166 p->has_block_incremental = true;
1167 visit_type_bool(v, param, &p->block_incremental, &err);
1168 break;
1169 case MIGRATION_PARAMETER_MULTIFD_CHANNELS:
1170 p->has_multifd_channels = true;
1171 visit_type_uint8(v, param, &p->multifd_channels, &err);
1172 break;
1173 case MIGRATION_PARAMETER_MULTIFD_COMPRESSION:
1174 p->has_multifd_compression = true;
1175 visit_type_MultiFDCompression(v, param, &p->multifd_compression,
1176 &err);
1177 break;
1178 case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL:
1179 p->has_multifd_zlib_level = true;
1180 visit_type_uint8(v, param, &p->multifd_zlib_level, &err);
1181 break;
1182 case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL:
1183 p->has_multifd_zstd_level = true;
1184 visit_type_uint8(v, param, &p->multifd_zstd_level, &err);
1185 break;
1186 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1187 p->has_xbzrle_cache_size = true;
1188 if (!visit_type_size(v, param, &cache_size, &err)) {
1189 break;
1191 if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) {
1192 error_setg(&err, "Invalid size %s", valuestr);
1193 break;
1195 p->xbzrle_cache_size = cache_size;
1196 break;
1197 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH:
1198 p->has_max_postcopy_bandwidth = true;
1199 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err);
1200 break;
1201 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL:
1202 p->has_announce_initial = true;
1203 visit_type_size(v, param, &p->announce_initial, &err);
1204 break;
1205 case MIGRATION_PARAMETER_ANNOUNCE_MAX:
1206 p->has_announce_max = true;
1207 visit_type_size(v, param, &p->announce_max, &err);
1208 break;
1209 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS:
1210 p->has_announce_rounds = true;
1211 visit_type_size(v, param, &p->announce_rounds, &err);
1212 break;
1213 case MIGRATION_PARAMETER_ANNOUNCE_STEP:
1214 p->has_announce_step = true;
1215 visit_type_size(v, param, &p->announce_step, &err);
1216 break;
1217 case MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING:
1218 error_setg(&err, "The block-bitmap-mapping parameter can only be set "
1219 "through QMP");
1220 break;
1221 default:
1222 assert(0);
1225 if (err) {
1226 goto cleanup;
1229 qmp_migrate_set_parameters(p, &err);
1231 cleanup:
1232 qapi_free_MigrateSetParameters(p);
1233 visit_free(v);
1234 hmp_handle_error(mon, err);
1237 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1239 Error *err = NULL;
1240 const char *protocol = qdict_get_str(qdict, "protocol");
1241 const char *hostname = qdict_get_str(qdict, "hostname");
1242 bool has_port = qdict_haskey(qdict, "port");
1243 int port = qdict_get_try_int(qdict, "port", -1);
1244 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1245 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1246 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1248 qmp_client_migrate_info(protocol, hostname,
1249 has_port, port, has_tls_port, tls_port,
1250 cert_subject, &err);
1251 hmp_handle_error(mon, err);
1254 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1256 Error *err = NULL;
1257 qmp_migrate_start_postcopy(&err);
1258 hmp_handle_error(mon, err);
1261 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1263 Error *err = NULL;
1265 qmp_x_colo_lost_heartbeat(&err);
1266 hmp_handle_error(mon, err);
1269 void hmp_set_password(Monitor *mon, const QDict *qdict)
1271 const char *protocol = qdict_get_str(qdict, "protocol");
1272 const char *password = qdict_get_str(qdict, "password");
1273 const char *display = qdict_get_try_str(qdict, "display");
1274 const char *connected = qdict_get_try_str(qdict, "connected");
1275 Error *err = NULL;
1277 SetPasswordOptions opts = {
1278 .password = (char *)password,
1279 .has_connected = !!connected,
1282 opts.connected = qapi_enum_parse(&SetPasswordAction_lookup, connected,
1283 SET_PASSWORD_ACTION_KEEP, &err);
1284 if (err) {
1285 goto out;
1288 opts.protocol = qapi_enum_parse(&DisplayProtocol_lookup, protocol,
1289 DISPLAY_PROTOCOL_VNC, &err);
1290 if (err) {
1291 goto out;
1294 if (opts.protocol == DISPLAY_PROTOCOL_VNC) {
1295 opts.u.vnc.display = (char *)display;
1298 qmp_set_password(&opts, &err);
1300 out:
1301 hmp_handle_error(mon, err);
1304 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1306 const char *protocol = qdict_get_str(qdict, "protocol");
1307 const char *whenstr = qdict_get_str(qdict, "time");
1308 const char *display = qdict_get_try_str(qdict, "display");
1309 Error *err = NULL;
1311 ExpirePasswordOptions opts = {
1312 .time = (char *)whenstr,
1315 opts.protocol = qapi_enum_parse(&DisplayProtocol_lookup, protocol,
1316 DISPLAY_PROTOCOL_VNC, &err);
1317 if (err) {
1318 goto out;
1321 if (opts.protocol == DISPLAY_PROTOCOL_VNC) {
1322 opts.u.vnc.display = (char *)display;
1325 qmp_expire_password(&opts, &err);
1327 out:
1328 hmp_handle_error(mon, err);
1332 #ifdef CONFIG_VNC
1333 static void hmp_change_read_arg(void *opaque, const char *password,
1334 void *readline_opaque)
1336 qmp_change_vnc_password(password, NULL);
1337 monitor_read_command(opaque, 1);
1339 #endif
1341 void hmp_change(Monitor *mon, const QDict *qdict)
1343 const char *device = qdict_get_str(qdict, "device");
1344 const char *target = qdict_get_str(qdict, "target");
1345 const char *arg = qdict_get_try_str(qdict, "arg");
1346 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1347 bool force = qdict_get_try_bool(qdict, "force", false);
1348 BlockdevChangeReadOnlyMode read_only_mode = 0;
1349 Error *err = NULL;
1351 #ifdef CONFIG_VNC
1352 if (strcmp(device, "vnc") == 0) {
1353 if (read_only) {
1354 monitor_printf(mon,
1355 "Parameter 'read-only-mode' is invalid for VNC\n");
1356 return;
1358 if (strcmp(target, "passwd") == 0 ||
1359 strcmp(target, "password") == 0) {
1360 if (!arg) {
1361 MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
1362 monitor_read_password(hmp_mon, hmp_change_read_arg, NULL);
1363 return;
1364 } else {
1365 qmp_change_vnc_password(arg, &err);
1367 } else {
1368 monitor_printf(mon, "Expected 'password' after 'vnc'\n");
1370 } else
1371 #endif
1373 if (read_only) {
1374 read_only_mode =
1375 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
1376 read_only,
1377 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1378 if (err) {
1379 goto end;
1383 qmp_blockdev_change_medium(device, NULL, target, arg, true, force,
1384 !!read_only, read_only_mode,
1385 &err);
1388 end:
1389 hmp_handle_error(mon, err);
1392 typedef struct HMPMigrationStatus {
1393 QEMUTimer *timer;
1394 Monitor *mon;
1395 bool is_block_migration;
1396 } HMPMigrationStatus;
1398 static void hmp_migrate_status_cb(void *opaque)
1400 HMPMigrationStatus *status = opaque;
1401 MigrationInfo *info;
1403 info = qmp_query_migrate(NULL);
1404 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1405 info->status == MIGRATION_STATUS_SETUP) {
1406 if (info->disk) {
1407 int progress;
1409 if (info->disk->remaining) {
1410 progress = info->disk->transferred * 100 / info->disk->total;
1411 } else {
1412 progress = 100;
1415 monitor_printf(status->mon, "Completed %d %%\r", progress);
1416 monitor_flush(status->mon);
1419 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1420 } else {
1421 if (status->is_block_migration) {
1422 monitor_printf(status->mon, "\n");
1424 if (info->error_desc) {
1425 error_report("%s", info->error_desc);
1427 monitor_resume(status->mon);
1428 timer_free(status->timer);
1429 g_free(status);
1432 qapi_free_MigrationInfo(info);
1435 void hmp_migrate(Monitor *mon, const QDict *qdict)
1437 bool detach = qdict_get_try_bool(qdict, "detach", false);
1438 bool blk = qdict_get_try_bool(qdict, "blk", false);
1439 bool inc = qdict_get_try_bool(qdict, "inc", false);
1440 bool resume = qdict_get_try_bool(qdict, "resume", false);
1441 const char *uri = qdict_get_str(qdict, "uri");
1442 Error *err = NULL;
1444 qmp_migrate(uri, !!blk, blk, !!inc, inc,
1445 false, false, true, resume, &err);
1446 if (hmp_handle_error(mon, err)) {
1447 return;
1450 if (!detach) {
1451 HMPMigrationStatus *status;
1453 if (monitor_suspend(mon) < 0) {
1454 monitor_printf(mon, "terminal does not allow synchronous "
1455 "migration, continuing detached\n");
1456 return;
1459 status = g_malloc0(sizeof(*status));
1460 status->mon = mon;
1461 status->is_block_migration = blk || inc;
1462 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1463 status);
1464 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1468 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1470 Error *err = NULL;
1471 QemuOpts *opts;
1472 const char *type = qdict_get_try_str(qdict, "type");
1474 if (type && is_help_option(type)) {
1475 show_netdevs();
1476 return;
1478 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1479 if (err) {
1480 goto out;
1483 netdev_add(opts, &err);
1484 if (err) {
1485 qemu_opts_del(opts);
1488 out:
1489 hmp_handle_error(mon, err);
1492 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1494 const char *id = qdict_get_str(qdict, "id");
1495 Error *err = NULL;
1497 qmp_netdev_del(id, &err);
1498 hmp_handle_error(mon, err);
1501 void hmp_object_add(Monitor *mon, const QDict *qdict)
1503 const char *options = qdict_get_str(qdict, "object");
1504 Error *err = NULL;
1506 user_creatable_add_from_str(options, &err);
1507 hmp_handle_error(mon, err);
1510 void hmp_getfd(Monitor *mon, const QDict *qdict)
1512 const char *fdname = qdict_get_str(qdict, "fdname");
1513 Error *err = NULL;
1515 qmp_getfd(fdname, &err);
1516 hmp_handle_error(mon, err);
1519 void hmp_closefd(Monitor *mon, const QDict *qdict)
1521 const char *fdname = qdict_get_str(qdict, "fdname");
1522 Error *err = NULL;
1524 qmp_closefd(fdname, &err);
1525 hmp_handle_error(mon, err);
1528 void hmp_sendkey(Monitor *mon, const QDict *qdict)
1530 const char *keys = qdict_get_str(qdict, "keys");
1531 KeyValue *v = NULL;
1532 KeyValueList *head = NULL, **tail = &head;
1533 int has_hold_time = qdict_haskey(qdict, "hold-time");
1534 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1535 Error *err = NULL;
1536 const char *separator;
1537 int keyname_len;
1539 while (1) {
1540 separator = qemu_strchrnul(keys, '-');
1541 keyname_len = separator - keys;
1543 /* Be compatible with old interface, convert user inputted "<" */
1544 if (keys[0] == '<' && keyname_len == 1) {
1545 keys = "less";
1546 keyname_len = 4;
1549 v = g_malloc0(sizeof(*v));
1551 if (strstart(keys, "0x", NULL)) {
1552 const char *endp;
1553 int value;
1555 if (qemu_strtoi(keys, &endp, 0, &value) < 0) {
1556 goto err_out;
1558 assert(endp <= keys + keyname_len);
1559 if (endp != keys + keyname_len) {
1560 goto err_out;
1562 v->type = KEY_VALUE_KIND_NUMBER;
1563 v->u.number.data = value;
1564 } else {
1565 int idx = index_from_key(keys, keyname_len);
1566 if (idx == Q_KEY_CODE__MAX) {
1567 goto err_out;
1569 v->type = KEY_VALUE_KIND_QCODE;
1570 v->u.qcode.data = idx;
1572 QAPI_LIST_APPEND(tail, v);
1573 v = NULL;
1575 if (!*separator) {
1576 break;
1578 keys = separator + 1;
1581 qmp_send_key(head, has_hold_time, hold_time, &err);
1582 hmp_handle_error(mon, err);
1584 out:
1585 qapi_free_KeyValue(v);
1586 qapi_free_KeyValueList(head);
1587 return;
1589 err_out:
1590 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
1591 goto out;
1594 void coroutine_fn
1595 hmp_screendump(Monitor *mon, const QDict *qdict)
1597 const char *filename = qdict_get_str(qdict, "filename");
1598 const char *id = qdict_get_try_str(qdict, "device");
1599 int64_t head = qdict_get_try_int(qdict, "head", 0);
1600 const char *input_format = qdict_get_try_str(qdict, "format");
1601 Error *err = NULL;
1602 ImageFormat format;
1604 format = qapi_enum_parse(&ImageFormat_lookup, input_format,
1605 IMAGE_FORMAT_PPM, &err);
1606 if (err) {
1607 goto end;
1610 qmp_screendump(filename, id, id != NULL, head,
1611 input_format != NULL, format, &err);
1612 end:
1613 hmp_handle_error(mon, err);
1616 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1618 const char *args = qdict_get_str(qdict, "args");
1619 Error *err = NULL;
1620 QemuOpts *opts;
1622 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
1623 if (opts == NULL) {
1624 error_setg(&err, "Parsing chardev args failed");
1625 } else {
1626 qemu_chr_new_from_opts(opts, NULL, &err);
1627 qemu_opts_del(opts);
1629 hmp_handle_error(mon, err);
1632 void hmp_chardev_change(Monitor *mon, const QDict *qdict)
1634 const char *args = qdict_get_str(qdict, "args");
1635 const char *id;
1636 Error *err = NULL;
1637 ChardevBackend *backend = NULL;
1638 ChardevReturn *ret = NULL;
1639 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
1640 true);
1641 if (!opts) {
1642 error_setg(&err, "Parsing chardev args failed");
1643 goto end;
1646 id = qdict_get_str(qdict, "id");
1647 if (qemu_opts_id(opts)) {
1648 error_setg(&err, "Unexpected 'id' parameter");
1649 goto end;
1652 backend = qemu_chr_parse_opts(opts, &err);
1653 if (!backend) {
1654 goto end;
1657 ret = qmp_chardev_change(id, backend, &err);
1659 end:
1660 qapi_free_ChardevReturn(ret);
1661 qapi_free_ChardevBackend(backend);
1662 qemu_opts_del(opts);
1663 hmp_handle_error(mon, err);
1666 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1668 Error *local_err = NULL;
1670 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1671 hmp_handle_error(mon, local_err);
1674 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
1676 Error *local_err = NULL;
1678 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
1679 hmp_handle_error(mon, local_err);
1682 void hmp_object_del(Monitor *mon, const QDict *qdict)
1684 const char *id = qdict_get_str(qdict, "id");
1685 Error *err = NULL;
1687 user_creatable_del(id, &err);
1688 hmp_handle_error(mon, err);
1691 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
1693 Error *err = NULL;
1694 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
1695 MemoryDeviceInfoList *info;
1696 VirtioPMEMDeviceInfo *vpi;
1697 VirtioMEMDeviceInfo *vmi;
1698 MemoryDeviceInfo *value;
1699 PCDIMMDeviceInfo *di;
1700 SgxEPCDeviceInfo *se;
1702 for (info = info_list; info; info = info->next) {
1703 value = info->value;
1705 if (value) {
1706 switch (value->type) {
1707 case MEMORY_DEVICE_INFO_KIND_DIMM:
1708 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
1709 di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ?
1710 value->u.dimm.data : value->u.nvdimm.data;
1711 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1712 MemoryDeviceInfoKind_str(value->type),
1713 di->id ? di->id : "");
1714 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
1715 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
1716 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
1717 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
1718 monitor_printf(mon, " memdev: %s\n", di->memdev);
1719 monitor_printf(mon, " hotplugged: %s\n",
1720 di->hotplugged ? "true" : "false");
1721 monitor_printf(mon, " hotpluggable: %s\n",
1722 di->hotpluggable ? "true" : "false");
1723 break;
1724 case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM:
1725 vpi = value->u.virtio_pmem.data;
1726 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1727 MemoryDeviceInfoKind_str(value->type),
1728 vpi->id ? vpi->id : "");
1729 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->memaddr);
1730 monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size);
1731 monitor_printf(mon, " memdev: %s\n", vpi->memdev);
1732 break;
1733 case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM:
1734 vmi = value->u.virtio_mem.data;
1735 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1736 MemoryDeviceInfoKind_str(value->type),
1737 vmi->id ? vmi->id : "");
1738 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vmi->memaddr);
1739 monitor_printf(mon, " node: %" PRId64 "\n", vmi->node);
1740 monitor_printf(mon, " requested-size: %" PRIu64 "\n",
1741 vmi->requested_size);
1742 monitor_printf(mon, " size: %" PRIu64 "\n", vmi->size);
1743 monitor_printf(mon, " max-size: %" PRIu64 "\n", vmi->max_size);
1744 monitor_printf(mon, " block-size: %" PRIu64 "\n",
1745 vmi->block_size);
1746 monitor_printf(mon, " memdev: %s\n", vmi->memdev);
1747 break;
1748 case MEMORY_DEVICE_INFO_KIND_SGX_EPC:
1749 se = value->u.sgx_epc.data;
1750 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1751 MemoryDeviceInfoKind_str(value->type),
1752 se->id ? se->id : "");
1753 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", se->memaddr);
1754 monitor_printf(mon, " size: %" PRIu64 "\n", se->size);
1755 monitor_printf(mon, " node: %" PRId64 "\n", se->node);
1756 monitor_printf(mon, " memdev: %s\n", se->memdev);
1757 break;
1758 default:
1759 g_assert_not_reached();
1764 qapi_free_MemoryDeviceInfoList(info_list);
1765 hmp_handle_error(mon, err);
1768 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
1770 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
1771 IOThreadInfoList *info;
1772 IOThreadInfo *value;
1774 for (info = info_list; info; info = info->next) {
1775 value = info->value;
1776 monitor_printf(mon, "%s:\n", value->id);
1777 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
1778 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
1779 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
1780 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
1781 monitor_printf(mon, " aio-max-batch=%" PRId64 "\n",
1782 value->aio_max_batch);
1785 qapi_free_IOThreadInfoList(info_list);
1788 void hmp_rocker(Monitor *mon, const QDict *qdict)
1790 const char *name = qdict_get_str(qdict, "name");
1791 RockerSwitch *rocker;
1792 Error *err = NULL;
1794 rocker = qmp_query_rocker(name, &err);
1795 if (hmp_handle_error(mon, err)) {
1796 return;
1799 monitor_printf(mon, "name: %s\n", rocker->name);
1800 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
1801 monitor_printf(mon, "ports: %d\n", rocker->ports);
1803 qapi_free_RockerSwitch(rocker);
1806 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
1808 RockerPortList *list, *port;
1809 const char *name = qdict_get_str(qdict, "name");
1810 Error *err = NULL;
1812 list = qmp_query_rocker_ports(name, &err);
1813 if (hmp_handle_error(mon, err)) {
1814 return;
1817 monitor_printf(mon, " ena/ speed/ auto\n");
1818 monitor_printf(mon, " port link duplex neg?\n");
1820 for (port = list; port; port = port->next) {
1821 monitor_printf(mon, "%10s %-4s %-3s %2s %s\n",
1822 port->value->name,
1823 port->value->enabled ? port->value->link_up ?
1824 "up" : "down" : "!ena",
1825 port->value->speed == 10000 ? "10G" : "??",
1826 port->value->duplex ? "FD" : "HD",
1827 port->value->autoneg ? "Yes" : "No");
1830 qapi_free_RockerPortList(list);
1833 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
1835 RockerOfDpaFlowList *list, *info;
1836 const char *name = qdict_get_str(qdict, "name");
1837 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
1838 Error *err = NULL;
1840 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
1841 if (hmp_handle_error(mon, err)) {
1842 return;
1845 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
1847 for (info = list; info; info = info->next) {
1848 RockerOfDpaFlow *flow = info->value;
1849 RockerOfDpaFlowKey *key = flow->key;
1850 RockerOfDpaFlowMask *mask = flow->mask;
1851 RockerOfDpaFlowAction *action = flow->action;
1853 if (flow->hits) {
1854 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
1855 key->priority, key->tbl_id, flow->hits);
1856 } else {
1857 monitor_printf(mon, "%-4d %-3d ",
1858 key->priority, key->tbl_id);
1861 if (key->has_in_pport) {
1862 monitor_printf(mon, " pport %d", key->in_pport);
1863 if (mask->has_in_pport) {
1864 monitor_printf(mon, "(0x%x)", mask->in_pport);
1868 if (key->has_vlan_id) {
1869 monitor_printf(mon, " vlan %d",
1870 key->vlan_id & VLAN_VID_MASK);
1871 if (mask->has_vlan_id) {
1872 monitor_printf(mon, "(0x%x)", mask->vlan_id);
1876 if (key->has_tunnel_id) {
1877 monitor_printf(mon, " tunnel %d", key->tunnel_id);
1878 if (mask->has_tunnel_id) {
1879 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
1883 if (key->has_eth_type) {
1884 switch (key->eth_type) {
1885 case 0x0806:
1886 monitor_printf(mon, " ARP");
1887 break;
1888 case 0x0800:
1889 monitor_printf(mon, " IP");
1890 break;
1891 case 0x86dd:
1892 monitor_printf(mon, " IPv6");
1893 break;
1894 case 0x8809:
1895 monitor_printf(mon, " LACP");
1896 break;
1897 case 0x88cc:
1898 monitor_printf(mon, " LLDP");
1899 break;
1900 default:
1901 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
1902 break;
1906 if (key->eth_src) {
1907 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
1908 mask->eth_src &&
1909 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
1910 monitor_printf(mon, " src <any mcast/bcast>");
1911 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
1912 mask->eth_src &&
1913 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
1914 monitor_printf(mon, " src <any ucast>");
1915 } else {
1916 monitor_printf(mon, " src %s", key->eth_src);
1917 if (mask->eth_src) {
1918 monitor_printf(mon, "(%s)", mask->eth_src);
1923 if (key->eth_dst) {
1924 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
1925 mask->eth_dst &&
1926 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
1927 monitor_printf(mon, " dst <any mcast/bcast>");
1928 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
1929 mask->eth_dst &&
1930 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
1931 monitor_printf(mon, " dst <any ucast>");
1932 } else {
1933 monitor_printf(mon, " dst %s", key->eth_dst);
1934 if (mask->eth_dst) {
1935 monitor_printf(mon, "(%s)", mask->eth_dst);
1940 if (key->has_ip_proto) {
1941 monitor_printf(mon, " proto %d", key->ip_proto);
1942 if (mask->has_ip_proto) {
1943 monitor_printf(mon, "(0x%x)", mask->ip_proto);
1947 if (key->has_ip_tos) {
1948 monitor_printf(mon, " TOS %d", key->ip_tos);
1949 if (mask->has_ip_tos) {
1950 monitor_printf(mon, "(0x%x)", mask->ip_tos);
1954 if (key->ip_dst) {
1955 monitor_printf(mon, " dst %s", key->ip_dst);
1958 if (action->has_goto_tbl || action->has_group_id ||
1959 action->has_new_vlan_id) {
1960 monitor_printf(mon, " -->");
1963 if (action->has_new_vlan_id) {
1964 monitor_printf(mon, " apply new vlan %d",
1965 ntohs(action->new_vlan_id));
1968 if (action->has_group_id) {
1969 monitor_printf(mon, " write group 0x%08x", action->group_id);
1972 if (action->has_goto_tbl) {
1973 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
1976 monitor_printf(mon, "\n");
1979 qapi_free_RockerOfDpaFlowList(list);
1982 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
1984 RockerOfDpaGroupList *list, *g;
1985 const char *name = qdict_get_str(qdict, "name");
1986 uint8_t type = qdict_get_try_int(qdict, "type", 9);
1987 Error *err = NULL;
1989 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
1990 if (hmp_handle_error(mon, err)) {
1991 return;
1994 monitor_printf(mon, "id (decode) --> buckets\n");
1996 for (g = list; g; g = g->next) {
1997 RockerOfDpaGroup *group = g->value;
1998 bool set = false;
2000 monitor_printf(mon, "0x%08x", group->id);
2002 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2003 group->type == 1 ? "L2 rewrite" :
2004 group->type == 2 ? "L3 unicast" :
2005 group->type == 3 ? "L2 multicast" :
2006 group->type == 4 ? "L2 flood" :
2007 group->type == 5 ? "L3 interface" :
2008 group->type == 6 ? "L3 multicast" :
2009 group->type == 7 ? "L3 ECMP" :
2010 group->type == 8 ? "L2 overlay" :
2011 "unknown");
2013 if (group->has_vlan_id) {
2014 monitor_printf(mon, " vlan %d", group->vlan_id);
2017 if (group->has_pport) {
2018 monitor_printf(mon, " pport %d", group->pport);
2021 if (group->has_index) {
2022 monitor_printf(mon, " index %d", group->index);
2025 monitor_printf(mon, ") -->");
2027 if (group->has_set_vlan_id && group->set_vlan_id) {
2028 set = true;
2029 monitor_printf(mon, " set vlan %d",
2030 group->set_vlan_id & VLAN_VID_MASK);
2033 if (group->set_eth_src) {
2034 if (!set) {
2035 set = true;
2036 monitor_printf(mon, " set");
2038 monitor_printf(mon, " src %s", group->set_eth_src);
2041 if (group->set_eth_dst) {
2042 if (!set) {
2043 monitor_printf(mon, " set");
2045 monitor_printf(mon, " dst %s", group->set_eth_dst);
2048 if (group->has_ttl_check && group->ttl_check) {
2049 monitor_printf(mon, " check TTL");
2052 if (group->has_group_id && group->group_id) {
2053 monitor_printf(mon, " group id 0x%08x", group->group_id);
2056 if (group->has_pop_vlan && group->pop_vlan) {
2057 monitor_printf(mon, " pop vlan");
2060 if (group->has_out_pport) {
2061 monitor_printf(mon, " out pport %d", group->out_pport);
2064 if (group->has_group_ids) {
2065 struct uint32List *id;
2067 monitor_printf(mon, " groups [");
2068 for (id = group->group_ids; id; id = id->next) {
2069 monitor_printf(mon, "0x%08x", id->value);
2070 if (id->next) {
2071 monitor_printf(mon, ",");
2074 monitor_printf(mon, "]");
2077 monitor_printf(mon, "\n");
2080 qapi_free_RockerOfDpaGroupList(list);
2083 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
2085 Error *err = NULL;
2086 GuidInfo *info = qmp_query_vm_generation_id(&err);
2087 if (info) {
2088 monitor_printf(mon, "%s\n", info->guid);
2090 hmp_handle_error(mon, err);
2091 qapi_free_GuidInfo(info);
2094 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
2096 Error *err = NULL;
2097 MemoryInfo *info = qmp_query_memory_size_summary(&err);
2098 if (info) {
2099 monitor_printf(mon, "base memory: %" PRIu64 "\n",
2100 info->base_memory);
2102 if (info->has_plugged_memory) {
2103 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
2104 info->plugged_memory);
2107 qapi_free_MemoryInfo(info);
2109 hmp_handle_error(mon, err);
2112 static void print_stats_schema_value(Monitor *mon, StatsSchemaValue *value)
2114 const char *unit = NULL;
2115 monitor_printf(mon, " %s (%s%s", value->name, StatsType_str(value->type),
2116 value->has_unit || value->exponent ? ", " : "");
2118 if (value->has_unit) {
2119 if (value->unit == STATS_UNIT_SECONDS) {
2120 unit = "s";
2121 } else if (value->unit == STATS_UNIT_BYTES) {
2122 unit = "B";
2126 if (unit && value->base == 10 &&
2127 value->exponent >= -18 && value->exponent <= 18 &&
2128 value->exponent % 3 == 0) {
2129 monitor_puts(mon, si_prefix(value->exponent));
2130 } else if (unit && value->base == 2 &&
2131 value->exponent >= 0 && value->exponent <= 60 &&
2132 value->exponent % 10 == 0) {
2134 monitor_puts(mon, iec_binary_prefix(value->exponent));
2135 } else if (value->exponent) {
2136 /* Use exponential notation and write the unit's English name */
2137 monitor_printf(mon, "* %d^%d%s",
2138 value->base, value->exponent,
2139 value->has_unit ? " " : "");
2140 unit = NULL;
2143 if (value->has_unit) {
2144 monitor_puts(mon, unit ? unit : StatsUnit_str(value->unit));
2147 /* Print bucket size for linear histograms */
2148 if (value->type == STATS_TYPE_LINEAR_HISTOGRAM && value->has_bucket_size) {
2149 monitor_printf(mon, ", bucket size=%d", value->bucket_size);
2151 monitor_printf(mon, ")");
2154 static StatsSchemaValueList *find_schema_value_list(
2155 StatsSchemaList *list, StatsProvider provider,
2156 StatsTarget target)
2158 StatsSchemaList *node;
2160 for (node = list; node; node = node->next) {
2161 if (node->value->provider == provider &&
2162 node->value->target == target) {
2163 return node->value->stats;
2166 return NULL;
2169 static void print_stats_results(Monitor *mon, StatsTarget target,
2170 bool show_provider,
2171 StatsResult *result,
2172 StatsSchemaList *schema)
2174 /* Find provider schema */
2175 StatsSchemaValueList *schema_value_list =
2176 find_schema_value_list(schema, result->provider, target);
2177 StatsList *stats_list;
2179 if (!schema_value_list) {
2180 monitor_printf(mon, "failed to find schema list for %s\n",
2181 StatsProvider_str(result->provider));
2182 return;
2185 if (show_provider) {
2186 monitor_printf(mon, "provider: %s\n",
2187 StatsProvider_str(result->provider));
2190 for (stats_list = result->stats; stats_list;
2191 stats_list = stats_list->next,
2192 schema_value_list = schema_value_list->next) {
2194 Stats *stats = stats_list->value;
2195 StatsValue *stats_value = stats->value;
2196 StatsSchemaValue *schema_value = schema_value_list->value;
2198 /* Find schema entry */
2199 while (!g_str_equal(stats->name, schema_value->name)) {
2200 if (!schema_value_list->next) {
2201 monitor_printf(mon, "failed to find schema entry for %s\n",
2202 stats->name);
2203 return;
2205 schema_value_list = schema_value_list->next;
2206 schema_value = schema_value_list->value;
2209 print_stats_schema_value(mon, schema_value);
2211 if (stats_value->type == QTYPE_QNUM) {
2212 monitor_printf(mon, ": %" PRId64 "\n", stats_value->u.scalar);
2213 } else if (stats_value->type == QTYPE_QBOOL) {
2214 monitor_printf(mon, ": %s\n", stats_value->u.boolean ? "yes" : "no");
2215 } else if (stats_value->type == QTYPE_QLIST) {
2216 uint64List *list;
2217 int i;
2219 monitor_printf(mon, ": ");
2220 for (list = stats_value->u.list, i = 1;
2221 list;
2222 list = list->next, i++) {
2223 monitor_printf(mon, "[%d]=%" PRId64 " ", i, list->value);
2225 monitor_printf(mon, "\n");
2230 /* Create the StatsFilter that is needed for an "info stats" invocation. */
2231 static StatsFilter *stats_filter(StatsTarget target, const char *names,
2232 int cpu_index, StatsProvider provider)
2234 StatsFilter *filter = g_malloc0(sizeof(*filter));
2235 StatsProvider provider_idx;
2236 StatsRequestList *request_list = NULL;
2238 filter->target = target;
2239 switch (target) {
2240 case STATS_TARGET_VM:
2241 break;
2242 case STATS_TARGET_VCPU:
2244 strList *vcpu_list = NULL;
2245 CPUState *cpu = qemu_get_cpu(cpu_index);
2246 char *canonical_path = object_get_canonical_path(OBJECT(cpu));
2248 QAPI_LIST_PREPEND(vcpu_list, canonical_path);
2249 filter->u.vcpu.has_vcpus = true;
2250 filter->u.vcpu.vcpus = vcpu_list;
2251 break;
2253 default:
2254 break;
2257 if (!names && provider == STATS_PROVIDER__MAX) {
2258 return filter;
2262 * "info stats" can only query either one or all the providers. Querying
2263 * by name, but not by provider, requires the creation of one filter per
2264 * provider.
2266 for (provider_idx = 0; provider_idx < STATS_PROVIDER__MAX; provider_idx++) {
2267 if (provider == STATS_PROVIDER__MAX || provider == provider_idx) {
2268 StatsRequest *request = g_new0(StatsRequest, 1);
2269 request->provider = provider_idx;
2270 if (names && !g_str_equal(names, "*")) {
2271 request->has_names = true;
2272 request->names = strList_from_comma_list(names);
2274 QAPI_LIST_PREPEND(request_list, request);
2278 filter->has_providers = true;
2279 filter->providers = request_list;
2280 return filter;
2283 void hmp_info_stats(Monitor *mon, const QDict *qdict)
2285 const char *target_str = qdict_get_str(qdict, "target");
2286 const char *provider_str = qdict_get_try_str(qdict, "provider");
2287 const char *names = qdict_get_try_str(qdict, "names");
2289 StatsProvider provider = STATS_PROVIDER__MAX;
2290 StatsTarget target;
2291 Error *err = NULL;
2292 g_autoptr(StatsSchemaList) schema = NULL;
2293 g_autoptr(StatsResultList) stats = NULL;
2294 g_autoptr(StatsFilter) filter = NULL;
2295 StatsResultList *entry;
2297 target = qapi_enum_parse(&StatsTarget_lookup, target_str, -1, &err);
2298 if (err) {
2299 monitor_printf(mon, "invalid stats target %s\n", target_str);
2300 goto exit_no_print;
2302 if (provider_str) {
2303 provider = qapi_enum_parse(&StatsProvider_lookup, provider_str, -1, &err);
2304 if (err) {
2305 monitor_printf(mon, "invalid stats provider %s\n", provider_str);
2306 goto exit_no_print;
2310 schema = qmp_query_stats_schemas(provider_str ? true : false,
2311 provider, &err);
2312 if (err) {
2313 goto exit;
2316 switch (target) {
2317 case STATS_TARGET_VM:
2318 filter = stats_filter(target, names, -1, provider);
2319 break;
2320 case STATS_TARGET_VCPU: {}
2321 int cpu_index = monitor_get_cpu_index(mon);
2322 filter = stats_filter(target, names, cpu_index, provider);
2323 break;
2324 default:
2325 abort();
2328 stats = qmp_query_stats(filter, &err);
2329 if (err) {
2330 goto exit;
2332 for (entry = stats; entry; entry = entry->next) {
2333 print_stats_results(mon, target, provider_str == NULL, entry->value, schema);
2336 exit:
2337 if (err) {
2338 monitor_printf(mon, "%s\n", error_get_pretty(err));
2340 exit_no_print:
2341 error_free(err);
2344 static void hmp_virtio_dump_protocols(Monitor *mon,
2345 VhostDeviceProtocols *pcol)
2347 strList *pcol_list = pcol->protocols;
2348 while (pcol_list) {
2349 monitor_printf(mon, "\t%s", pcol_list->value);
2350 pcol_list = pcol_list->next;
2351 if (pcol_list != NULL) {
2352 monitor_printf(mon, ",\n");
2355 monitor_printf(mon, "\n");
2356 if (pcol->has_unknown_protocols) {
2357 monitor_printf(mon, " unknown-protocols(0x%016"PRIx64")\n",
2358 pcol->unknown_protocols);
2362 static void hmp_virtio_dump_status(Monitor *mon,
2363 VirtioDeviceStatus *status)
2365 strList *status_list = status->statuses;
2366 while (status_list) {
2367 monitor_printf(mon, "\t%s", status_list->value);
2368 status_list = status_list->next;
2369 if (status_list != NULL) {
2370 monitor_printf(mon, ",\n");
2373 monitor_printf(mon, "\n");
2374 if (status->has_unknown_statuses) {
2375 monitor_printf(mon, " unknown-statuses(0x%016"PRIx32")\n",
2376 status->unknown_statuses);
2380 static void hmp_virtio_dump_features(Monitor *mon,
2381 VirtioDeviceFeatures *features)
2383 strList *transport_list = features->transports;
2384 while (transport_list) {
2385 monitor_printf(mon, "\t%s", transport_list->value);
2386 transport_list = transport_list->next;
2387 if (transport_list != NULL) {
2388 monitor_printf(mon, ",\n");
2392 monitor_printf(mon, "\n");
2393 strList *list = features->dev_features;
2394 if (list) {
2395 while (list) {
2396 monitor_printf(mon, "\t%s", list->value);
2397 list = list->next;
2398 if (list != NULL) {
2399 monitor_printf(mon, ",\n");
2402 monitor_printf(mon, "\n");
2405 if (features->has_unknown_dev_features) {
2406 monitor_printf(mon, " unknown-features(0x%016"PRIx64")\n",
2407 features->unknown_dev_features);
2411 void hmp_virtio_query(Monitor *mon, const QDict *qdict)
2413 Error *err = NULL;
2414 VirtioInfoList *list = qmp_x_query_virtio(&err);
2415 VirtioInfoList *node;
2417 if (err != NULL) {
2418 hmp_handle_error(mon, err);
2419 return;
2422 if (list == NULL) {
2423 monitor_printf(mon, "No VirtIO devices\n");
2424 return;
2427 node = list;
2428 while (node) {
2429 monitor_printf(mon, "%s [%s]\n", node->value->path,
2430 node->value->name);
2431 node = node->next;
2433 qapi_free_VirtioInfoList(list);
2436 void hmp_virtio_status(Monitor *mon, const QDict *qdict)
2438 Error *err = NULL;
2439 const char *path = qdict_get_try_str(qdict, "path");
2440 VirtioStatus *s = qmp_x_query_virtio_status(path, &err);
2442 if (err != NULL) {
2443 hmp_handle_error(mon, err);
2444 return;
2447 monitor_printf(mon, "%s:\n", path);
2448 monitor_printf(mon, " device_name: %s %s\n",
2449 s->name, s->vhost_dev ? "(vhost)" : "");
2450 monitor_printf(mon, " device_id: %d\n", s->device_id);
2451 monitor_printf(mon, " vhost_started: %s\n",
2452 s->vhost_started ? "true" : "false");
2453 monitor_printf(mon, " bus_name: %s\n", s->bus_name);
2454 monitor_printf(mon, " broken: %s\n",
2455 s->broken ? "true" : "false");
2456 monitor_printf(mon, " disabled: %s\n",
2457 s->disabled ? "true" : "false");
2458 monitor_printf(mon, " disable_legacy_check: %s\n",
2459 s->disable_legacy_check ? "true" : "false");
2460 monitor_printf(mon, " started: %s\n",
2461 s->started ? "true" : "false");
2462 monitor_printf(mon, " use_started: %s\n",
2463 s->use_started ? "true" : "false");
2464 monitor_printf(mon, " start_on_kick: %s\n",
2465 s->start_on_kick ? "true" : "false");
2466 monitor_printf(mon, " use_guest_notifier_mask: %s\n",
2467 s->use_guest_notifier_mask ? "true" : "false");
2468 monitor_printf(mon, " vm_running: %s\n",
2469 s->vm_running ? "true" : "false");
2470 monitor_printf(mon, " num_vqs: %"PRId64"\n", s->num_vqs);
2471 monitor_printf(mon, " queue_sel: %d\n",
2472 s->queue_sel);
2473 monitor_printf(mon, " isr: %d\n", s->isr);
2474 monitor_printf(mon, " endianness: %s\n",
2475 s->device_endian);
2476 monitor_printf(mon, " status:\n");
2477 hmp_virtio_dump_status(mon, s->status);
2478 monitor_printf(mon, " Guest features:\n");
2479 hmp_virtio_dump_features(mon, s->guest_features);
2480 monitor_printf(mon, " Host features:\n");
2481 hmp_virtio_dump_features(mon, s->host_features);
2482 monitor_printf(mon, " Backend features:\n");
2483 hmp_virtio_dump_features(mon, s->backend_features);
2485 if (s->vhost_dev) {
2486 monitor_printf(mon, " VHost:\n");
2487 monitor_printf(mon, " nvqs: %d\n",
2488 s->vhost_dev->nvqs);
2489 monitor_printf(mon, " vq_index: %"PRId64"\n",
2490 s->vhost_dev->vq_index);
2491 monitor_printf(mon, " max_queues: %"PRId64"\n",
2492 s->vhost_dev->max_queues);
2493 monitor_printf(mon, " n_mem_sections: %"PRId64"\n",
2494 s->vhost_dev->n_mem_sections);
2495 monitor_printf(mon, " n_tmp_sections: %"PRId64"\n",
2496 s->vhost_dev->n_tmp_sections);
2497 monitor_printf(mon, " backend_cap: %"PRId64"\n",
2498 s->vhost_dev->backend_cap);
2499 monitor_printf(mon, " log_enabled: %s\n",
2500 s->vhost_dev->log_enabled ? "true" : "false");
2501 monitor_printf(mon, " log_size: %"PRId64"\n",
2502 s->vhost_dev->log_size);
2503 monitor_printf(mon, " Features:\n");
2504 hmp_virtio_dump_features(mon, s->vhost_dev->features);
2505 monitor_printf(mon, " Acked features:\n");
2506 hmp_virtio_dump_features(mon, s->vhost_dev->acked_features);
2507 monitor_printf(mon, " Backend features:\n");
2508 hmp_virtio_dump_features(mon, s->vhost_dev->backend_features);
2509 monitor_printf(mon, " Protocol features:\n");
2510 hmp_virtio_dump_protocols(mon, s->vhost_dev->protocol_features);
2513 qapi_free_VirtioStatus(s);
2516 void hmp_vhost_queue_status(Monitor *mon, const QDict *qdict)
2518 Error *err = NULL;
2519 const char *path = qdict_get_try_str(qdict, "path");
2520 int queue = qdict_get_int(qdict, "queue");
2521 VirtVhostQueueStatus *s =
2522 qmp_x_query_virtio_vhost_queue_status(path, queue, &err);
2524 if (err != NULL) {
2525 hmp_handle_error(mon, err);
2526 return;
2529 monitor_printf(mon, "%s:\n", path);
2530 monitor_printf(mon, " device_name: %s (vhost)\n",
2531 s->name);
2532 monitor_printf(mon, " kick: %"PRId64"\n", s->kick);
2533 monitor_printf(mon, " call: %"PRId64"\n", s->call);
2534 monitor_printf(mon, " VRing:\n");
2535 monitor_printf(mon, " num: %"PRId64"\n", s->num);
2536 monitor_printf(mon, " desc: 0x%016"PRIx64"\n", s->desc);
2537 monitor_printf(mon, " desc_phys: 0x%016"PRIx64"\n",
2538 s->desc_phys);
2539 monitor_printf(mon, " desc_size: %"PRId32"\n", s->desc_size);
2540 monitor_printf(mon, " avail: 0x%016"PRIx64"\n", s->avail);
2541 monitor_printf(mon, " avail_phys: 0x%016"PRIx64"\n",
2542 s->avail_phys);
2543 monitor_printf(mon, " avail_size: %"PRId32"\n", s->avail_size);
2544 monitor_printf(mon, " used: 0x%016"PRIx64"\n", s->used);
2545 monitor_printf(mon, " used_phys: 0x%016"PRIx64"\n",
2546 s->used_phys);
2547 monitor_printf(mon, " used_size: %"PRId32"\n", s->used_size);
2549 qapi_free_VirtVhostQueueStatus(s);
2552 void hmp_virtio_queue_status(Monitor *mon, const QDict *qdict)
2554 Error *err = NULL;
2555 const char *path = qdict_get_try_str(qdict, "path");
2556 int queue = qdict_get_int(qdict, "queue");
2557 VirtQueueStatus *s = qmp_x_query_virtio_queue_status(path, queue, &err);
2559 if (err != NULL) {
2560 hmp_handle_error(mon, err);
2561 return;
2564 monitor_printf(mon, "%s:\n", path);
2565 monitor_printf(mon, " device_name: %s\n", s->name);
2566 monitor_printf(mon, " queue_index: %d\n", s->queue_index);
2567 monitor_printf(mon, " inuse: %d\n", s->inuse);
2568 monitor_printf(mon, " used_idx: %d\n", s->used_idx);
2569 monitor_printf(mon, " signalled_used: %d\n",
2570 s->signalled_used);
2571 monitor_printf(mon, " signalled_used_valid: %s\n",
2572 s->signalled_used_valid ? "true" : "false");
2573 if (s->has_last_avail_idx) {
2574 monitor_printf(mon, " last_avail_idx: %d\n",
2575 s->last_avail_idx);
2577 if (s->has_shadow_avail_idx) {
2578 monitor_printf(mon, " shadow_avail_idx: %d\n",
2579 s->shadow_avail_idx);
2581 monitor_printf(mon, " VRing:\n");
2582 monitor_printf(mon, " num: %"PRId32"\n", s->vring_num);
2583 monitor_printf(mon, " num_default: %"PRId32"\n",
2584 s->vring_num_default);
2585 monitor_printf(mon, " align: %"PRId32"\n",
2586 s->vring_align);
2587 monitor_printf(mon, " desc: 0x%016"PRIx64"\n",
2588 s->vring_desc);
2589 monitor_printf(mon, " avail: 0x%016"PRIx64"\n",
2590 s->vring_avail);
2591 monitor_printf(mon, " used: 0x%016"PRIx64"\n",
2592 s->vring_used);
2594 qapi_free_VirtQueueStatus(s);
2597 void hmp_virtio_queue_element(Monitor *mon, const QDict *qdict)
2599 Error *err = NULL;
2600 const char *path = qdict_get_try_str(qdict, "path");
2601 int queue = qdict_get_int(qdict, "queue");
2602 int index = qdict_get_try_int(qdict, "index", -1);
2603 VirtioQueueElement *e;
2604 VirtioRingDescList *list;
2606 e = qmp_x_query_virtio_queue_element(path, queue, index != -1,
2607 index, &err);
2608 if (err != NULL) {
2609 hmp_handle_error(mon, err);
2610 return;
2613 monitor_printf(mon, "%s:\n", path);
2614 monitor_printf(mon, " device_name: %s\n", e->name);
2615 monitor_printf(mon, " index: %d\n", e->index);
2616 monitor_printf(mon, " desc:\n");
2617 monitor_printf(mon, " descs:\n");
2619 list = e->descs;
2620 while (list) {
2621 monitor_printf(mon, " addr 0x%"PRIx64" len %d",
2622 list->value->addr, list->value->len);
2623 if (list->value->flags) {
2624 strList *flag = list->value->flags;
2625 monitor_printf(mon, " (");
2626 while (flag) {
2627 monitor_printf(mon, "%s", flag->value);
2628 flag = flag->next;
2629 if (flag) {
2630 monitor_printf(mon, ", ");
2633 monitor_printf(mon, ")");
2635 list = list->next;
2636 if (list) {
2637 monitor_printf(mon, ",\n");
2640 monitor_printf(mon, "\n");
2641 monitor_printf(mon, " avail:\n");
2642 monitor_printf(mon, " flags: %d\n", e->avail->flags);
2643 monitor_printf(mon, " idx: %d\n", e->avail->idx);
2644 monitor_printf(mon, " ring: %d\n", e->avail->ring);
2645 monitor_printf(mon, " used:\n");
2646 monitor_printf(mon, " flags: %d\n", e->used->flags);
2647 monitor_printf(mon, " idx: %d\n", e->used->idx);
2649 qapi_free_VirtioQueueElement(e);