2 * Human Monitor Interface commands
4 * Copyright IBM, Corp. 2011
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"
20 #include "chardev/char.h"
21 #include "sysemu/block-backend.h"
22 #include "sysemu/sysemu.h"
23 #include "qemu/config-file.h"
24 #include "qemu/option.h"
25 #include "qemu/timer.h"
26 #include "qemu/sockets.h"
27 #include "monitor/monitor-internal.h"
28 #include "monitor/qdev.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-migration.h"
36 #include "qapi/qapi-commands-misc.h"
37 #include "qapi/qapi-commands-net.h"
38 #include "qapi/qapi-commands-rocker.h"
39 #include "qapi/qapi-commands-run-state.h"
40 #include "qapi/qapi-commands-tpm.h"
41 #include "qapi/qapi-commands-ui.h"
42 #include "qapi/qapi-visit-net.h"
43 #include "qapi/qmp/qdict.h"
44 #include "qapi/qmp/qerror.h"
45 #include "qapi/string-input-visitor.h"
46 #include "qapi/string-output-visitor.h"
47 #include "qom/object_interfaces.h"
48 #include "ui/console.h"
49 #include "block/nbd.h"
50 #include "block/qapi.h"
52 #include "qemu/cutils.h"
53 #include "qemu/error-report.h"
54 #include "exec/ramlist.h"
55 #include "hw/intc/intc.h"
56 #include "hw/rdma/rdma.h"
57 #include "migration/snapshot.h"
58 #include "migration/misc.h"
61 #include <spice/enums.h>
64 static void hmp_handle_error(Monitor *mon, Error **errp)
68 error_reportf_err(*errp, "Error: ");
73 * Produce a strList from a comma separated list.
74 * A NULL or empty input string return NULL.
76 static strList *strList_from_comma_list(const char *in)
79 strList **hook = &res;
82 char *comma = strchr(in, ',');
83 *hook = g_new0(strList, 1);
86 (*hook)->value = g_strndup(in, comma - in);
87 in = comma + 1; /* skip the , */
89 (*hook)->value = g_strdup(in);
92 hook = &(*hook)->next;
98 void hmp_info_name(Monitor *mon, const QDict *qdict)
102 info = qmp_query_name(NULL);
103 if (info->has_name) {
104 monitor_printf(mon, "%s\n", info->name);
106 qapi_free_NameInfo(info);
109 void hmp_info_version(Monitor *mon, const QDict *qdict)
113 info = qmp_query_version(NULL);
115 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
116 info->qemu->major, info->qemu->minor, info->qemu->micro,
119 qapi_free_VersionInfo(info);
122 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
126 info = qmp_query_kvm(NULL);
127 monitor_printf(mon, "kvm support: ");
129 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
131 monitor_printf(mon, "not compiled\n");
134 qapi_free_KvmInfo(info);
137 void hmp_info_status(Monitor *mon, const QDict *qdict)
141 info = qmp_query_status(NULL);
143 monitor_printf(mon, "VM status: %s%s",
144 info->running ? "running" : "paused",
145 info->singlestep ? " (single step mode)" : "");
147 if (!info->running && info->status != RUN_STATE_PAUSED) {
148 monitor_printf(mon, " (%s)", RunState_str(info->status));
151 monitor_printf(mon, "\n");
153 qapi_free_StatusInfo(info);
156 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
160 info = qmp_query_uuid(NULL);
161 monitor_printf(mon, "%s\n", info->UUID);
162 qapi_free_UuidInfo(info);
165 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
167 ChardevInfoList *char_info, *info;
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);
175 qapi_free_ChardevInfoList(char_info);
178 void hmp_info_mice(Monitor *mon, const QDict *qdict)
180 MouseInfoList *mice_list, *mouse;
182 mice_list = qmp_query_mice(NULL);
184 monitor_printf(mon, "No mouse devices connected\n");
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)" : "");
195 qapi_free_MouseInfoList(mice_list);
198 static char *SocketAddress_to_str(SocketAddress *addr)
200 switch (addr->type) {
201 case SOCKET_ADDRESS_TYPE_INET:
202 return g_strdup_printf("tcp:%s:%s",
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",
215 return g_strdup("unknown address type");
219 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
222 MigrationCapabilityStatusList *caps, *cap;
224 info = qmp_query_migrate(NULL);
225 caps = qmp_query_migrate_capabilities(NULL);
227 migration_global_dump(mon);
229 /* do not display parameters during setup */
230 if (info->has_status && caps) {
231 monitor_printf(mon, "capabilities: ");
232 for (cap = caps; cap; cap = cap->next) {
233 monitor_printf(mon, "%s: %s ",
234 MigrationCapability_str(cap->value->capability),
235 cap->value->state ? "on" : "off");
237 monitor_printf(mon, "\n");
240 if (info->has_status) {
241 monitor_printf(mon, "Migration status: %s",
242 MigrationStatus_str(info->status));
243 if (info->status == MIGRATION_STATUS_FAILED &&
244 info->has_error_desc) {
245 monitor_printf(mon, " (%s)\n", info->error_desc);
247 monitor_printf(mon, "\n");
250 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
252 if (info->has_expected_downtime) {
253 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
254 info->expected_downtime);
256 if (info->has_downtime) {
257 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
260 if (info->has_setup_time) {
261 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
267 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
268 info->ram->transferred >> 10);
269 monitor_printf(mon, "throughput: %0.2f mbps\n",
271 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
272 info->ram->remaining >> 10);
273 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
274 info->ram->total >> 10);
275 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
276 info->ram->duplicate);
277 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
279 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
281 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
282 info->ram->normal_bytes >> 10);
283 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
284 info->ram->dirty_sync_count);
285 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
286 info->ram->page_size >> 10);
287 monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n",
288 info->ram->multifd_bytes >> 10);
289 monitor_printf(mon, "pages-per-second: %" PRIu64 "\n",
290 info->ram->pages_per_second);
292 if (info->ram->dirty_pages_rate) {
293 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
294 info->ram->dirty_pages_rate);
296 if (info->ram->postcopy_requests) {
297 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
298 info->ram->postcopy_requests);
302 if (info->has_disk) {
303 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
304 info->disk->transferred >> 10);
305 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
306 info->disk->remaining >> 10);
307 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
308 info->disk->total >> 10);
311 if (info->has_xbzrle_cache) {
312 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
313 info->xbzrle_cache->cache_size);
314 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
315 info->xbzrle_cache->bytes >> 10);
316 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
317 info->xbzrle_cache->pages);
318 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
319 info->xbzrle_cache->cache_miss);
320 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
321 info->xbzrle_cache->cache_miss_rate);
322 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
323 info->xbzrle_cache->overflow);
326 if (info->has_compression) {
327 monitor_printf(mon, "compression pages: %" PRIu64 " pages\n",
328 info->compression->pages);
329 monitor_printf(mon, "compression busy: %" PRIu64 "\n",
330 info->compression->busy);
331 monitor_printf(mon, "compression busy rate: %0.2f\n",
332 info->compression->busy_rate);
333 monitor_printf(mon, "compressed size: %" PRIu64 "\n",
334 info->compression->compressed_size);
335 monitor_printf(mon, "compression rate: %0.2f\n",
336 info->compression->compression_rate);
339 if (info->has_cpu_throttle_percentage) {
340 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
341 info->cpu_throttle_percentage);
344 if (info->has_postcopy_blocktime) {
345 monitor_printf(mon, "postcopy blocktime: %u\n",
346 info->postcopy_blocktime);
349 if (info->has_postcopy_vcpu_blocktime) {
352 v = string_output_visitor_new(false, &str);
353 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NULL);
354 visit_complete(v, &str);
355 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
359 if (info->has_socket_address) {
360 SocketAddressList *addr;
362 monitor_printf(mon, "socket address: [\n");
364 for (addr = info->socket_address; addr; addr = addr->next) {
365 char *s = SocketAddress_to_str(addr->value);
366 monitor_printf(mon, "\t%s\n", s);
369 monitor_printf(mon, "]\n");
371 qapi_free_MigrationInfo(info);
372 qapi_free_MigrationCapabilityStatusList(caps);
375 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
377 MigrationCapabilityStatusList *caps, *cap;
379 caps = qmp_query_migrate_capabilities(NULL);
382 for (cap = caps; cap; cap = cap->next) {
383 monitor_printf(mon, "%s: %s\n",
384 MigrationCapability_str(cap->value->capability),
385 cap->value->state ? "on" : "off");
389 qapi_free_MigrationCapabilityStatusList(caps);
392 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
394 MigrationParameters *params;
396 params = qmp_query_migrate_parameters(NULL);
399 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
400 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL),
401 params->announce_initial);
402 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
403 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX),
404 params->announce_max);
405 monitor_printf(mon, "%s: %" PRIu64 "\n",
406 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS),
407 params->announce_rounds);
408 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
409 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP),
410 params->announce_step);
411 assert(params->has_compress_level);
412 monitor_printf(mon, "%s: %u\n",
413 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
414 params->compress_level);
415 assert(params->has_compress_threads);
416 monitor_printf(mon, "%s: %u\n",
417 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
418 params->compress_threads);
419 assert(params->has_compress_wait_thread);
420 monitor_printf(mon, "%s: %s\n",
421 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD),
422 params->compress_wait_thread ? "on" : "off");
423 assert(params->has_decompress_threads);
424 monitor_printf(mon, "%s: %u\n",
425 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
426 params->decompress_threads);
427 assert(params->has_cpu_throttle_initial);
428 monitor_printf(mon, "%s: %u\n",
429 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
430 params->cpu_throttle_initial);
431 assert(params->has_cpu_throttle_increment);
432 monitor_printf(mon, "%s: %u\n",
433 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
434 params->cpu_throttle_increment);
435 assert(params->has_max_cpu_throttle);
436 monitor_printf(mon, "%s: %u\n",
437 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE),
438 params->max_cpu_throttle);
439 assert(params->has_tls_creds);
440 monitor_printf(mon, "%s: '%s'\n",
441 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
443 assert(params->has_tls_hostname);
444 monitor_printf(mon, "%s: '%s'\n",
445 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
446 params->tls_hostname);
447 assert(params->has_max_bandwidth);
448 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
449 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
450 params->max_bandwidth);
451 assert(params->has_downtime_limit);
452 monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n",
453 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
454 params->downtime_limit);
455 assert(params->has_x_checkpoint_delay);
456 monitor_printf(mon, "%s: %u\n",
457 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
458 params->x_checkpoint_delay);
459 assert(params->has_block_incremental);
460 monitor_printf(mon, "%s: %s\n",
461 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
462 params->block_incremental ? "on" : "off");
463 monitor_printf(mon, "%s: %u\n",
464 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS),
465 params->multifd_channels);
466 monitor_printf(mon, "%s: %" PRIu64 "\n",
467 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
468 params->xbzrle_cache_size);
469 monitor_printf(mon, "%s: %" PRIu64 "\n",
470 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
471 params->max_postcopy_bandwidth);
472 monitor_printf(mon, " %s: '%s'\n",
473 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
474 params->has_tls_authz ? params->tls_authz : "");
477 qapi_free_MigrationParameters(params);
480 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
482 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
483 qmp_query_migrate_cache_size(NULL) >> 10);
486 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
488 CpuInfoFastList *cpu_list, *cpu;
490 cpu_list = qmp_query_cpus_fast(NULL);
492 for (cpu = cpu_list; cpu; cpu = cpu->next) {
495 if (cpu->value->cpu_index == monitor_get_cpu_index()) {
499 monitor_printf(mon, "%c CPU #%" PRId64 ":", active,
500 cpu->value->cpu_index);
501 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
504 qapi_free_CpuInfoFastList(cpu_list);
507 static void print_block_info(Monitor *mon, BlockInfo *info,
508 BlockDeviceInfo *inserted, bool verbose)
510 ImageInfo *image_info;
512 assert(!info || !info->has_inserted || info->inserted == inserted);
514 if (info && *info->device) {
515 monitor_printf(mon, "%s", info->device);
516 if (inserted && inserted->has_node_name) {
517 monitor_printf(mon, " (%s)", inserted->node_name);
520 assert(info || inserted);
521 monitor_printf(mon, "%s",
522 inserted && inserted->has_node_name ? inserted->node_name
523 : info && info->has_qdev ? info->qdev
528 monitor_printf(mon, ": %s (%s%s%s)\n",
531 inserted->ro ? ", read-only" : "",
532 inserted->encrypted ? ", encrypted" : "");
534 monitor_printf(mon, ": [not inserted]\n");
538 if (info->has_qdev) {
539 monitor_printf(mon, " Attached to: %s\n", info->qdev);
541 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
542 monitor_printf(mon, " I/O status: %s\n",
543 BlockDeviceIoStatus_str(info->io_status));
546 if (info->removable) {
547 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
548 info->locked ? "" : "not ",
549 info->tray_open ? "open" : "closed");
558 monitor_printf(mon, " Cache mode: %s%s%s\n",
559 inserted->cache->writeback ? "writeback" : "writethrough",
560 inserted->cache->direct ? ", direct" : "",
561 inserted->cache->no_flush ? ", ignore flushes" : "");
563 if (inserted->has_backing_file) {
566 "(chain depth: %" PRId64 ")\n",
567 inserted->backing_file,
568 inserted->backing_file_depth);
571 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
572 monitor_printf(mon, " Detect zeroes: %s\n",
573 BlockdevDetectZeroesOptions_str(inserted->detect_zeroes));
576 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
577 inserted->iops || inserted->iops_rd || inserted->iops_wr)
579 monitor_printf(mon, " I/O throttling: bps=%" PRId64
580 " bps_rd=%" PRId64 " bps_wr=%" PRId64
582 " bps_rd_max=%" PRId64
583 " bps_wr_max=%" PRId64
584 " iops=%" PRId64 " iops_rd=%" PRId64
587 " iops_rd_max=%" PRId64
588 " iops_wr_max=%" PRId64
589 " iops_size=%" PRId64
595 inserted->bps_rd_max,
596 inserted->bps_wr_max,
601 inserted->iops_rd_max,
602 inserted->iops_wr_max,
608 monitor_printf(mon, "\nImages:\n");
609 image_info = inserted->image;
611 bdrv_image_info_dump(image_info);
612 if (image_info->has_backing_image) {
613 image_info = image_info->backing_image;
621 void hmp_info_block(Monitor *mon, const QDict *qdict)
623 BlockInfoList *block_list, *info;
624 BlockDeviceInfoList *blockdev_list, *blockdev;
625 const char *device = qdict_get_try_str(qdict, "device");
626 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
627 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
628 bool printed = false;
630 /* Print BlockBackend information */
632 block_list = qmp_query_block(NULL);
637 for (info = block_list; info; info = info->next) {
638 if (device && strcmp(device, info->value->device)) {
642 if (info != block_list) {
643 monitor_printf(mon, "\n");
646 print_block_info(mon, info->value, info->value->has_inserted
647 ? info->value->inserted : NULL,
652 qapi_free_BlockInfoList(block_list);
654 if ((!device && !nodes) || printed) {
658 /* Print node information */
659 blockdev_list = qmp_query_named_block_nodes(NULL);
660 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
661 assert(blockdev->value->has_node_name);
662 if (device && strcmp(device, blockdev->value->node_name)) {
666 if (blockdev != blockdev_list) {
667 monitor_printf(mon, "\n");
670 print_block_info(mon, NULL, blockdev->value, verbose);
672 qapi_free_BlockDeviceInfoList(blockdev_list);
675 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
677 BlockStatsList *stats_list, *stats;
679 stats_list = qmp_query_blockstats(false, false, NULL);
681 for (stats = stats_list; stats; stats = stats->next) {
682 if (!stats->value->has_device) {
686 monitor_printf(mon, "%s:", stats->value->device);
687 monitor_printf(mon, " rd_bytes=%" PRId64
689 " rd_operations=%" PRId64
690 " wr_operations=%" PRId64
691 " flush_operations=%" PRId64
692 " wr_total_time_ns=%" PRId64
693 " rd_total_time_ns=%" PRId64
694 " flush_total_time_ns=%" PRId64
695 " rd_merged=%" PRId64
696 " wr_merged=%" PRId64
697 " idle_time_ns=%" PRId64
699 stats->value->stats->rd_bytes,
700 stats->value->stats->wr_bytes,
701 stats->value->stats->rd_operations,
702 stats->value->stats->wr_operations,
703 stats->value->stats->flush_operations,
704 stats->value->stats->wr_total_time_ns,
705 stats->value->stats->rd_total_time_ns,
706 stats->value->stats->flush_total_time_ns,
707 stats->value->stats->rd_merged,
708 stats->value->stats->wr_merged,
709 stats->value->stats->idle_time_ns);
712 qapi_free_BlockStatsList(stats_list);
716 /* Helper for hmp_info_vnc_clients, _servers */
717 static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
720 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
724 NetworkAddressFamily_str(info->family),
725 info->websocket ? " (Websocket)" : "");
728 /* Helper displaying and auth and crypt info */
729 static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
731 VncVencryptSubAuth *vencrypt)
733 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
734 VncPrimaryAuth_str(auth),
735 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
738 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
741 VncClientInfo *cinfo = client->value;
743 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
744 monitor_printf(mon, " x509_dname: %s\n",
745 cinfo->has_x509_dname ?
746 cinfo->x509_dname : "none");
747 monitor_printf(mon, " sasl_username: %s\n",
748 cinfo->has_sasl_username ?
749 cinfo->sasl_username : "none");
751 client = client->next;
755 static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
758 VncServerInfo2 *sinfo = server->value;
759 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
760 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
761 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
762 server = server->next;
766 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
768 VncInfo2List *info2l;
771 info2l = qmp_query_vnc_servers(&err);
773 hmp_handle_error(mon, &err);
777 monitor_printf(mon, "None\n");
782 VncInfo2 *info = info2l->value;
783 monitor_printf(mon, "%s:\n", info->id);
784 hmp_info_vnc_servers(mon, info->server);
785 hmp_info_vnc_clients(mon, info->clients);
787 /* The server entry displays its auth, we only
788 * need to display in the case of 'reverse' connections
789 * where there's no server.
791 hmp_info_vnc_authcrypt(mon, " ", info->auth,
792 info->has_vencrypt ? &info->vencrypt : NULL);
794 if (info->has_display) {
795 monitor_printf(mon, " Display: %s\n", info->display);
797 info2l = info2l->next;
800 qapi_free_VncInfo2List(info2l);
806 void hmp_info_spice(Monitor *mon, const QDict *qdict)
808 SpiceChannelList *chan;
810 const char *channel_name;
811 const char * const channel_names[] = {
812 [SPICE_CHANNEL_MAIN] = "main",
813 [SPICE_CHANNEL_DISPLAY] = "display",
814 [SPICE_CHANNEL_INPUTS] = "inputs",
815 [SPICE_CHANNEL_CURSOR] = "cursor",
816 [SPICE_CHANNEL_PLAYBACK] = "playback",
817 [SPICE_CHANNEL_RECORD] = "record",
818 [SPICE_CHANNEL_TUNNEL] = "tunnel",
819 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
820 [SPICE_CHANNEL_USBREDIR] = "usbredir",
821 [SPICE_CHANNEL_PORT] = "port",
823 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
824 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
825 * as quick fix for build failures with older versions. */
826 [SPICE_CHANNEL_WEBDAV] = "webdav",
830 info = qmp_query_spice(NULL);
832 if (!info->enabled) {
833 monitor_printf(mon, "Server: disabled\n");
837 monitor_printf(mon, "Server:\n");
838 if (info->has_port) {
839 monitor_printf(mon, " address: %s:%" PRId64 "\n",
840 info->host, info->port);
842 if (info->has_tls_port) {
843 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
844 info->host, info->tls_port);
846 monitor_printf(mon, " migrated: %s\n",
847 info->migrated ? "true" : "false");
848 monitor_printf(mon, " auth: %s\n", info->auth);
849 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
850 monitor_printf(mon, " mouse-mode: %s\n",
851 SpiceQueryMouseMode_str(info->mouse_mode));
853 if (!info->has_channels || info->channels == NULL) {
854 monitor_printf(mon, "Channels: none\n");
856 for (chan = info->channels; chan; chan = chan->next) {
857 monitor_printf(mon, "Channel:\n");
858 monitor_printf(mon, " address: %s:%s%s\n",
859 chan->value->host, chan->value->port,
860 chan->value->tls ? " [tls]" : "");
861 monitor_printf(mon, " session: %" PRId64 "\n",
862 chan->value->connection_id);
863 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
864 chan->value->channel_type, chan->value->channel_id);
866 channel_name = "unknown";
867 if (chan->value->channel_type > 0 &&
868 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
869 channel_names[chan->value->channel_type]) {
870 channel_name = channel_names[chan->value->channel_type];
873 monitor_printf(mon, " channel name: %s\n", channel_name);
878 qapi_free_SpiceInfo(info);
882 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
887 info = qmp_query_balloon(&err);
889 hmp_handle_error(mon, &err);
893 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
895 qapi_free_BalloonInfo(info);
898 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
900 PciMemoryRegionList *region;
902 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
903 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
904 dev->slot, dev->function);
905 monitor_printf(mon, " ");
907 if (dev->class_info->has_desc) {
908 monitor_printf(mon, "%s", dev->class_info->desc);
910 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
913 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
914 dev->id->vendor, dev->id->device);
915 if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) {
916 monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n",
917 dev->id->subsystem_vendor, dev->id->subsystem);
921 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
924 if (dev->has_pci_bridge) {
925 monitor_printf(mon, " BUS %" PRId64 ".\n",
926 dev->pci_bridge->bus->number);
927 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
928 dev->pci_bridge->bus->secondary);
929 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
930 dev->pci_bridge->bus->subordinate);
932 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
933 dev->pci_bridge->bus->io_range->base,
934 dev->pci_bridge->bus->io_range->limit);
937 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
938 dev->pci_bridge->bus->memory_range->base,
939 dev->pci_bridge->bus->memory_range->limit);
941 monitor_printf(mon, " prefetchable memory range "
942 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
943 dev->pci_bridge->bus->prefetchable_range->base,
944 dev->pci_bridge->bus->prefetchable_range->limit);
947 for (region = dev->regions; region; region = region->next) {
950 addr = region->value->address;
951 size = region->value->size;
953 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
955 if (!strcmp(region->value->type, "io")) {
956 monitor_printf(mon, "I/O at 0x%04" PRIx64
957 " [0x%04" PRIx64 "].\n",
958 addr, addr + size - 1);
960 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
961 " [0x%08" PRIx64 "].\n",
962 region->value->mem_type_64 ? 64 : 32,
963 region->value->prefetch ? " prefetchable" : "",
964 addr, addr + size - 1);
968 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
970 if (dev->has_pci_bridge) {
971 if (dev->pci_bridge->has_devices) {
972 PciDeviceInfoList *cdev;
973 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
974 hmp_info_pci_device(mon, cdev->value);
980 static int hmp_info_irq_foreach(Object *obj, void *opaque)
982 InterruptStatsProvider *intc;
983 InterruptStatsProviderClass *k;
984 Monitor *mon = opaque;
986 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
987 intc = INTERRUPT_STATS_PROVIDER(obj);
988 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
989 uint64_t *irq_counts;
990 unsigned int nb_irqs, i;
991 if (k->get_statistics &&
992 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
994 monitor_printf(mon, "IRQ statistics for %s:\n",
995 object_get_typename(obj));
996 for (i = 0; i < nb_irqs; i++) {
997 if (irq_counts[i] > 0) {
998 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
1004 monitor_printf(mon, "IRQ statistics not available for %s.\n",
1005 object_get_typename(obj));
1012 void hmp_info_irq(Monitor *mon, const QDict *qdict)
1014 object_child_foreach_recursive(object_get_root(),
1015 hmp_info_irq_foreach, mon);
1018 static int hmp_info_pic_foreach(Object *obj, void *opaque)
1020 InterruptStatsProvider *intc;
1021 InterruptStatsProviderClass *k;
1022 Monitor *mon = opaque;
1024 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
1025 intc = INTERRUPT_STATS_PROVIDER(obj);
1026 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
1027 if (k->print_info) {
1028 k->print_info(intc, mon);
1030 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
1031 object_get_typename(obj));
1038 void hmp_info_pic(Monitor *mon, const QDict *qdict)
1040 object_child_foreach_recursive(object_get_root(),
1041 hmp_info_pic_foreach, mon);
1044 static int hmp_info_rdma_foreach(Object *obj, void *opaque)
1047 RdmaProviderClass *k;
1048 Monitor *mon = opaque;
1050 if (object_dynamic_cast(obj, INTERFACE_RDMA_PROVIDER)) {
1051 rdma = RDMA_PROVIDER(obj);
1052 k = RDMA_PROVIDER_GET_CLASS(obj);
1053 if (k->print_statistics) {
1054 k->print_statistics(mon, rdma);
1056 monitor_printf(mon, "RDMA statistics not available for %s.\n",
1057 object_get_typename(obj));
1064 void hmp_info_rdma(Monitor *mon, const QDict *qdict)
1066 object_child_foreach_recursive(object_get_root(),
1067 hmp_info_rdma_foreach, mon);
1070 void hmp_info_pci(Monitor *mon, const QDict *qdict)
1072 PciInfoList *info_list, *info;
1075 info_list = qmp_query_pci(&err);
1077 monitor_printf(mon, "PCI devices not supported\n");
1082 for (info = info_list; info; info = info->next) {
1083 PciDeviceInfoList *dev;
1085 for (dev = info->value->devices; dev; dev = dev->next) {
1086 hmp_info_pci_device(mon, dev->value);
1090 qapi_free_PciInfoList(info_list);
1093 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
1095 BlockJobInfoList *list;
1098 list = qmp_query_block_jobs(&err);
1102 monitor_printf(mon, "No active jobs\n");
1107 if (strcmp(list->value->type, "stream") == 0) {
1108 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
1109 " of %" PRId64 " bytes, speed limit %" PRId64
1111 list->value->device,
1112 list->value->offset,
1114 list->value->speed);
1116 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
1117 " of %" PRId64 " bytes, speed limit %" PRId64
1120 list->value->device,
1121 list->value->offset,
1123 list->value->speed);
1128 qapi_free_BlockJobInfoList(list);
1131 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
1133 TPMInfoList *info_list, *info;
1136 TPMPassthroughOptions *tpo;
1137 TPMEmulatorOptions *teo;
1139 info_list = qmp_query_tpm(&err);
1141 monitor_printf(mon, "TPM device not supported\n");
1147 monitor_printf(mon, "TPM device:\n");
1150 for (info = info_list; info; info = info->next) {
1151 TPMInfo *ti = info->value;
1152 monitor_printf(mon, " tpm%d: model=%s\n",
1153 c, TpmModel_str(ti->model));
1155 monitor_printf(mon, " \\ %s: type=%s",
1156 ti->id, TpmTypeOptionsKind_str(ti->options->type));
1158 switch (ti->options->type) {
1159 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
1160 tpo = ti->options->u.passthrough.data;
1161 monitor_printf(mon, "%s%s%s%s",
1162 tpo->has_path ? ",path=" : "",
1163 tpo->has_path ? tpo->path : "",
1164 tpo->has_cancel_path ? ",cancel-path=" : "",
1165 tpo->has_cancel_path ? tpo->cancel_path : "");
1167 case TPM_TYPE_OPTIONS_KIND_EMULATOR:
1168 teo = ti->options->u.emulator.data;
1169 monitor_printf(mon, ",chardev=%s", teo->chardev);
1171 case TPM_TYPE_OPTIONS_KIND__MAX:
1174 monitor_printf(mon, "\n");
1177 qapi_free_TPMInfoList(info_list);
1180 void hmp_quit(Monitor *mon, const QDict *qdict)
1182 monitor_suspend(mon);
1186 void hmp_stop(Monitor *mon, const QDict *qdict)
1191 void hmp_sync_profile(Monitor *mon, const QDict *qdict)
1193 const char *op = qdict_get_try_str(qdict, "op");
1196 bool on = qsp_is_enabled();
1198 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off");
1201 if (!strcmp(op, "on")) {
1203 } else if (!strcmp(op, "off")) {
1205 } else if (!strcmp(op, "reset")) {
1210 error_setg(&err, QERR_INVALID_PARAMETER, op);
1211 hmp_handle_error(mon, &err);
1215 void hmp_system_reset(Monitor *mon, const QDict *qdict)
1217 qmp_system_reset(NULL);
1220 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
1222 qmp_system_powerdown(NULL);
1225 void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
1229 qmp_x_exit_preconfig(&err);
1230 hmp_handle_error(mon, &err);
1233 void hmp_cpu(Monitor *mon, const QDict *qdict)
1237 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1238 use it are converted to the QAPI */
1239 cpu_index = qdict_get_int(qdict, "index");
1240 if (monitor_set_cpu(cpu_index) < 0) {
1241 monitor_printf(mon, "invalid CPU index\n");
1245 void hmp_memsave(Monitor *mon, const QDict *qdict)
1247 uint32_t size = qdict_get_int(qdict, "size");
1248 const char *filename = qdict_get_str(qdict, "filename");
1249 uint64_t addr = qdict_get_int(qdict, "val");
1251 int cpu_index = monitor_get_cpu_index();
1253 if (cpu_index < 0) {
1254 monitor_printf(mon, "No CPU available\n");
1258 qmp_memsave(addr, size, filename, true, cpu_index, &err);
1259 hmp_handle_error(mon, &err);
1262 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1264 uint32_t size = qdict_get_int(qdict, "size");
1265 const char *filename = qdict_get_str(qdict, "filename");
1266 uint64_t addr = qdict_get_int(qdict, "val");
1269 qmp_pmemsave(addr, size, filename, &err);
1270 hmp_handle_error(mon, &err);
1273 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1275 const char *chardev = qdict_get_str(qdict, "device");
1276 const char *data = qdict_get_str(qdict, "data");
1279 qmp_ringbuf_write(chardev, data, false, 0, &err);
1281 hmp_handle_error(mon, &err);
1284 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
1286 uint32_t size = qdict_get_int(qdict, "size");
1287 const char *chardev = qdict_get_str(qdict, "device");
1292 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1294 hmp_handle_error(mon, &err);
1298 for (i = 0; data[i]; i++) {
1299 unsigned char ch = data[i];
1302 monitor_printf(mon, "\\\\");
1303 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1304 monitor_printf(mon, "\\u%04X", ch);
1306 monitor_printf(mon, "%c", ch);
1310 monitor_printf(mon, "\n");
1314 void hmp_cont(Monitor *mon, const QDict *qdict)
1319 hmp_handle_error(mon, &err);
1322 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1326 qmp_system_wakeup(&err);
1327 hmp_handle_error(mon, &err);
1330 void hmp_nmi(Monitor *mon, const QDict *qdict)
1334 qmp_inject_nmi(&err);
1335 hmp_handle_error(mon, &err);
1338 void hmp_set_link(Monitor *mon, const QDict *qdict)
1340 const char *name = qdict_get_str(qdict, "name");
1341 bool up = qdict_get_bool(qdict, "up");
1344 qmp_set_link(name, up, &err);
1345 hmp_handle_error(mon, &err);
1348 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1350 const char *device = qdict_get_str(qdict, "device");
1351 const char *password = qdict_get_str(qdict, "password");
1354 qmp_block_passwd(true, device, false, NULL, password, &err);
1355 hmp_handle_error(mon, &err);
1358 void hmp_balloon(Monitor *mon, const QDict *qdict)
1360 int64_t value = qdict_get_int(qdict, "value");
1363 qmp_balloon(value, &err);
1364 hmp_handle_error(mon, &err);
1367 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1369 const char *device = qdict_get_str(qdict, "device");
1370 int64_t size = qdict_get_int(qdict, "size");
1373 qmp_block_resize(true, device, false, NULL, size, &err);
1374 hmp_handle_error(mon, &err);
1377 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1379 const char *filename = qdict_get_str(qdict, "target");
1380 const char *format = qdict_get_try_str(qdict, "format");
1381 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1382 bool full = qdict_get_try_bool(qdict, "full", false);
1384 DriveMirror mirror = {
1385 .device = (char *)qdict_get_str(qdict, "device"),
1386 .target = (char *)filename,
1387 .has_format = !!format,
1388 .format = (char *)format,
1389 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1391 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1396 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1397 hmp_handle_error(mon, &err);
1400 qmp_drive_mirror(&mirror, &err);
1401 hmp_handle_error(mon, &err);
1404 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1406 const char *device = qdict_get_str(qdict, "device");
1407 const char *filename = qdict_get_str(qdict, "target");
1408 const char *format = qdict_get_try_str(qdict, "format");
1409 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1410 bool full = qdict_get_try_bool(qdict, "full", false);
1411 bool compress = qdict_get_try_bool(qdict, "compress", false);
1413 DriveBackup backup = {
1414 .device = (char *)device,
1415 .target = (char *)filename,
1416 .has_format = !!format,
1417 .format = (char *)format,
1418 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1420 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1421 .has_compress = !!compress,
1422 .compress = compress,
1426 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1427 hmp_handle_error(mon, &err);
1431 qmp_drive_backup(&backup, &err);
1432 hmp_handle_error(mon, &err);
1435 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1437 const char *device = qdict_get_str(qdict, "device");
1438 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1439 const char *format = qdict_get_try_str(qdict, "format");
1440 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1441 enum NewImageMode mode;
1445 /* In the future, if 'snapshot-file' is not specified, the snapshot
1446 will be taken internally. Today it's actually required. */
1447 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1448 hmp_handle_error(mon, &err);
1452 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1453 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1454 filename, false, NULL,
1457 hmp_handle_error(mon, &err);
1460 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1462 const char *device = qdict_get_str(qdict, "device");
1463 const char *name = qdict_get_str(qdict, "name");
1466 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1467 hmp_handle_error(mon, &err);
1470 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1472 const char *device = qdict_get_str(qdict, "device");
1473 const char *name = qdict_get_str(qdict, "name");
1474 const char *id = qdict_get_try_str(qdict, "id");
1477 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1479 hmp_handle_error(mon, &err);
1482 void hmp_loadvm(Monitor *mon, const QDict *qdict)
1484 int saved_vm_running = runstate_is_running();
1485 const char *name = qdict_get_str(qdict, "name");
1488 vm_stop(RUN_STATE_RESTORE_VM);
1490 if (load_snapshot(name, &err) == 0 && saved_vm_running) {
1493 hmp_handle_error(mon, &err);
1496 void hmp_savevm(Monitor *mon, const QDict *qdict)
1500 save_snapshot(qdict_get_try_str(qdict, "name"), &err);
1501 hmp_handle_error(mon, &err);
1504 void hmp_delvm(Monitor *mon, const QDict *qdict)
1506 BlockDriverState *bs;
1508 const char *name = qdict_get_str(qdict, "name");
1510 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
1512 "deleting snapshot on device '%s': ",
1513 bdrv_get_device_name(bs));
1515 hmp_handle_error(mon, &err);
1518 void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
1520 BlockDriverState *bs, *bs1;
1521 BdrvNextIterator it1;
1522 QEMUSnapshotInfo *sn_tab, *sn;
1523 bool no_snapshot = true;
1526 int *global_snapshots;
1527 AioContext *aio_context;
1529 typedef struct SnapshotEntry {
1530 QEMUSnapshotInfo sn;
1531 QTAILQ_ENTRY(SnapshotEntry) next;
1534 typedef struct ImageEntry {
1535 const char *imagename;
1536 QTAILQ_ENTRY(ImageEntry) next;
1537 QTAILQ_HEAD(, SnapshotEntry) snapshots;
1540 QTAILQ_HEAD(, ImageEntry) image_list =
1541 QTAILQ_HEAD_INITIALIZER(image_list);
1543 ImageEntry *image_entry, *next_ie;
1544 SnapshotEntry *snapshot_entry;
1546 bs = bdrv_all_find_vmstate_bs();
1548 monitor_printf(mon, "No available block device supports snapshots\n");
1551 aio_context = bdrv_get_aio_context(bs);
1553 aio_context_acquire(aio_context);
1554 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
1555 aio_context_release(aio_context);
1558 monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
1562 for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) {
1566 AioContext *ctx = bdrv_get_aio_context(bs1);
1568 aio_context_acquire(ctx);
1569 if (bdrv_can_snapshot(bs1)) {
1571 bs1_nb_sns = bdrv_snapshot_list(bs1, &sn);
1572 if (bs1_nb_sns > 0) {
1573 no_snapshot = false;
1574 ie = g_new0(ImageEntry, 1);
1575 ie->imagename = bdrv_get_device_name(bs1);
1576 QTAILQ_INIT(&ie->snapshots);
1577 QTAILQ_INSERT_TAIL(&image_list, ie, next);
1578 for (i = 0; i < bs1_nb_sns; i++) {
1579 se = g_new0(SnapshotEntry, 1);
1581 QTAILQ_INSERT_TAIL(&ie->snapshots, se, next);
1586 aio_context_release(ctx);
1590 monitor_printf(mon, "There is no snapshot available.\n");
1594 global_snapshots = g_new0(int, nb_sns);
1596 for (i = 0; i < nb_sns; i++) {
1597 SnapshotEntry *next_sn;
1598 if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) {
1599 global_snapshots[total] = i;
1601 QTAILQ_FOREACH(image_entry, &image_list, next) {
1602 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots,
1604 if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) {
1605 QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry,
1607 g_free(snapshot_entry);
1614 monitor_printf(mon, "List of snapshots present on all disks:\n");
1617 bdrv_snapshot_dump(NULL);
1618 monitor_printf(mon, "\n");
1619 for (i = 0; i < total; i++) {
1620 sn = &sn_tab[global_snapshots[i]];
1621 /* The ID is not guaranteed to be the same on all images, so
1624 pstrcpy(sn->id_str, sizeof(sn->id_str), "--");
1625 bdrv_snapshot_dump(sn);
1626 monitor_printf(mon, "\n");
1629 monitor_printf(mon, "None\n");
1632 QTAILQ_FOREACH(image_entry, &image_list, next) {
1633 if (QTAILQ_EMPTY(&image_entry->snapshots)) {
1637 "\nList of partial (non-loadable) snapshots on '%s':\n",
1638 image_entry->imagename);
1639 bdrv_snapshot_dump(NULL);
1640 monitor_printf(mon, "\n");
1641 QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) {
1642 bdrv_snapshot_dump(&snapshot_entry->sn);
1643 monitor_printf(mon, "\n");
1647 QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) {
1648 SnapshotEntry *next_sn;
1649 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next,
1651 g_free(snapshot_entry);
1653 g_free(image_entry);
1656 g_free(global_snapshots);
1660 void hmp_announce_self(Monitor *mon, const QDict *qdict)
1662 const char *interfaces_str = qdict_get_try_str(qdict, "interfaces");
1663 AnnounceParameters *params = QAPI_CLONE(AnnounceParameters,
1664 migrate_announce_params());
1666 qapi_free_strList(params->interfaces);
1667 params->interfaces = strList_from_comma_list(interfaces_str);
1668 params->has_interfaces = params->interfaces != NULL;
1669 qmp_announce_self(params, NULL);
1670 qapi_free_AnnounceParameters(params);
1673 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1675 qmp_migrate_cancel(NULL);
1678 void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1681 const char *state = qdict_get_str(qdict, "state");
1682 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1685 qmp_migrate_continue(val, &err);
1688 hmp_handle_error(mon, &err);
1691 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1694 const char *uri = qdict_get_str(qdict, "uri");
1696 qmp_migrate_incoming(uri, &err);
1698 hmp_handle_error(mon, &err);
1701 void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
1704 const char *uri = qdict_get_str(qdict, "uri");
1706 qmp_migrate_recover(uri, &err);
1708 hmp_handle_error(mon, &err);
1711 void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
1715 qmp_migrate_pause(&err);
1717 hmp_handle_error(mon, &err);
1720 /* Kept for backwards compatibility */
1721 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1723 double value = qdict_get_double(qdict, "value");
1724 qmp_migrate_set_downtime(value, NULL);
1727 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1729 int64_t value = qdict_get_int(qdict, "value");
1732 qmp_migrate_set_cache_size(value, &err);
1733 hmp_handle_error(mon, &err);
1736 /* Kept for backwards compatibility */
1737 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1739 int64_t value = qdict_get_int(qdict, "value");
1740 qmp_migrate_set_speed(value, NULL);
1743 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1745 const char *cap = qdict_get_str(qdict, "capability");
1746 bool state = qdict_get_bool(qdict, "state");
1748 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1751 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
1756 caps->value = g_malloc0(sizeof(*caps->value));
1757 caps->value->capability = val;
1758 caps->value->state = state;
1760 qmp_migrate_set_capabilities(caps, &err);
1763 qapi_free_MigrationCapabilityStatusList(caps);
1764 hmp_handle_error(mon, &err);
1767 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1769 const char *param = qdict_get_str(qdict, "parameter");
1770 const char *valuestr = qdict_get_str(qdict, "value");
1771 Visitor *v = string_input_visitor_new(valuestr);
1772 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
1773 uint64_t valuebw = 0;
1774 uint64_t cache_size;
1778 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
1784 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1785 p->has_compress_level = true;
1786 visit_type_int(v, param, &p->compress_level, &err);
1788 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1789 p->has_compress_threads = true;
1790 visit_type_int(v, param, &p->compress_threads, &err);
1792 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD:
1793 p->has_compress_wait_thread = true;
1794 visit_type_bool(v, param, &p->compress_wait_thread, &err);
1796 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1797 p->has_decompress_threads = true;
1798 visit_type_int(v, param, &p->decompress_threads, &err);
1800 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1801 p->has_cpu_throttle_initial = true;
1802 visit_type_int(v, param, &p->cpu_throttle_initial, &err);
1804 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1805 p->has_cpu_throttle_increment = true;
1806 visit_type_int(v, param, &p->cpu_throttle_increment, &err);
1808 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE:
1809 p->has_max_cpu_throttle = true;
1810 visit_type_int(v, param, &p->max_cpu_throttle, &err);
1812 case MIGRATION_PARAMETER_TLS_CREDS:
1813 p->has_tls_creds = true;
1814 p->tls_creds = g_new0(StrOrNull, 1);
1815 p->tls_creds->type = QTYPE_QSTRING;
1816 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1818 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1819 p->has_tls_hostname = true;
1820 p->tls_hostname = g_new0(StrOrNull, 1);
1821 p->tls_hostname->type = QTYPE_QSTRING;
1822 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1824 case MIGRATION_PARAMETER_TLS_AUTHZ:
1825 p->has_tls_authz = true;
1826 p->tls_authz = g_new0(StrOrNull, 1);
1827 p->tls_authz->type = QTYPE_QSTRING;
1828 visit_type_str(v, param, &p->tls_authz->u.s, &err);
1830 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1831 p->has_max_bandwidth = true;
1833 * Can't use visit_type_size() here, because it
1834 * defaults to Bytes rather than Mebibytes.
1836 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1837 if (ret < 0 || valuebw > INT64_MAX
1838 || (size_t)valuebw != valuebw) {
1839 error_setg(&err, "Invalid size %s", valuestr);
1842 p->max_bandwidth = valuebw;
1844 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1845 p->has_downtime_limit = true;
1846 visit_type_int(v, param, &p->downtime_limit, &err);
1848 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1849 p->has_x_checkpoint_delay = true;
1850 visit_type_int(v, param, &p->x_checkpoint_delay, &err);
1852 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1853 p->has_block_incremental = true;
1854 visit_type_bool(v, param, &p->block_incremental, &err);
1856 case MIGRATION_PARAMETER_MULTIFD_CHANNELS:
1857 p->has_multifd_channels = true;
1858 visit_type_int(v, param, &p->multifd_channels, &err);
1860 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1861 p->has_xbzrle_cache_size = true;
1862 visit_type_size(v, param, &cache_size, &err);
1866 if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) {
1867 error_setg(&err, "Invalid size %s", valuestr);
1870 p->xbzrle_cache_size = cache_size;
1872 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH:
1873 p->has_max_postcopy_bandwidth = true;
1874 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err);
1876 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL:
1877 p->has_announce_initial = true;
1878 visit_type_size(v, param, &p->announce_initial, &err);
1880 case MIGRATION_PARAMETER_ANNOUNCE_MAX:
1881 p->has_announce_max = true;
1882 visit_type_size(v, param, &p->announce_max, &err);
1884 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS:
1885 p->has_announce_rounds = true;
1886 visit_type_size(v, param, &p->announce_rounds, &err);
1888 case MIGRATION_PARAMETER_ANNOUNCE_STEP:
1889 p->has_announce_step = true;
1890 visit_type_size(v, param, &p->announce_step, &err);
1900 qmp_migrate_set_parameters(p, &err);
1903 qapi_free_MigrateSetParameters(p);
1905 hmp_handle_error(mon, &err);
1908 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1911 const char *protocol = qdict_get_str(qdict, "protocol");
1912 const char *hostname = qdict_get_str(qdict, "hostname");
1913 bool has_port = qdict_haskey(qdict, "port");
1914 int port = qdict_get_try_int(qdict, "port", -1);
1915 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1916 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1917 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1919 qmp_client_migrate_info(protocol, hostname,
1920 has_port, port, has_tls_port, tls_port,
1921 !!cert_subject, cert_subject, &err);
1922 hmp_handle_error(mon, &err);
1925 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1928 qmp_migrate_start_postcopy(&err);
1929 hmp_handle_error(mon, &err);
1932 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1936 qmp_x_colo_lost_heartbeat(&err);
1937 hmp_handle_error(mon, &err);
1940 void hmp_set_password(Monitor *mon, const QDict *qdict)
1942 const char *protocol = qdict_get_str(qdict, "protocol");
1943 const char *password = qdict_get_str(qdict, "password");
1944 const char *connected = qdict_get_try_str(qdict, "connected");
1947 qmp_set_password(protocol, password, !!connected, connected, &err);
1948 hmp_handle_error(mon, &err);
1951 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1953 const char *protocol = qdict_get_str(qdict, "protocol");
1954 const char *whenstr = qdict_get_str(qdict, "time");
1957 qmp_expire_password(protocol, whenstr, &err);
1958 hmp_handle_error(mon, &err);
1961 void hmp_eject(Monitor *mon, const QDict *qdict)
1963 bool force = qdict_get_try_bool(qdict, "force", false);
1964 const char *device = qdict_get_str(qdict, "device");
1967 qmp_eject(true, device, false, NULL, true, force, &err);
1968 hmp_handle_error(mon, &err);
1972 static void hmp_change_read_arg(void *opaque, const char *password,
1973 void *readline_opaque)
1975 qmp_change_vnc_password(password, NULL);
1976 monitor_read_command(opaque, 1);
1980 void hmp_change(Monitor *mon, const QDict *qdict)
1982 MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
1983 const char *device = qdict_get_str(qdict, "device");
1984 const char *target = qdict_get_str(qdict, "target");
1985 const char *arg = qdict_get_try_str(qdict, "arg");
1986 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1987 BlockdevChangeReadOnlyMode read_only_mode = 0;
1991 if (strcmp(device, "vnc") == 0) {
1994 "Parameter 'read-only-mode' is invalid for VNC\n");
1997 if (strcmp(target, "passwd") == 0 ||
1998 strcmp(target, "password") == 0) {
2000 monitor_read_password(hmp_mon, hmp_change_read_arg, NULL);
2004 qmp_change("vnc", target, !!arg, arg, &err);
2010 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
2012 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
2014 hmp_handle_error(mon, &err);
2019 qmp_blockdev_change_medium(true, device, false, NULL, target,
2020 !!arg, arg, !!read_only, read_only_mode,
2024 hmp_handle_error(mon, &err);
2027 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
2030 char *device = (char *) qdict_get_str(qdict, "device");
2031 BlockIOThrottle throttle = {
2032 .bps = qdict_get_int(qdict, "bps"),
2033 .bps_rd = qdict_get_int(qdict, "bps_rd"),
2034 .bps_wr = qdict_get_int(qdict, "bps_wr"),
2035 .iops = qdict_get_int(qdict, "iops"),
2036 .iops_rd = qdict_get_int(qdict, "iops_rd"),
2037 .iops_wr = qdict_get_int(qdict, "iops_wr"),
2040 /* qmp_block_set_io_throttle has separate parameters for the
2041 * (deprecated) block device name and the qdev ID but the HMP
2042 * version has only one, so we must decide which one to pass. */
2043 if (blk_by_name(device)) {
2044 throttle.has_device = true;
2045 throttle.device = device;
2047 throttle.has_id = true;
2048 throttle.id = device;
2051 qmp_block_set_io_throttle(&throttle, &err);
2052 hmp_handle_error(mon, &err);
2055 void hmp_block_stream(Monitor *mon, const QDict *qdict)
2057 Error *error = NULL;
2058 const char *device = qdict_get_str(qdict, "device");
2059 const char *base = qdict_get_try_str(qdict, "base");
2060 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
2062 qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
2063 false, NULL, qdict_haskey(qdict, "speed"), speed, true,
2064 BLOCKDEV_ON_ERROR_REPORT, false, false, false, false,
2067 hmp_handle_error(mon, &error);
2070 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
2072 Error *error = NULL;
2073 const char *device = qdict_get_str(qdict, "device");
2074 int64_t value = qdict_get_int(qdict, "speed");
2076 qmp_block_job_set_speed(device, value, &error);
2078 hmp_handle_error(mon, &error);
2081 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
2083 Error *error = NULL;
2084 const char *device = qdict_get_str(qdict, "device");
2085 bool force = qdict_get_try_bool(qdict, "force", false);
2087 qmp_block_job_cancel(device, true, force, &error);
2089 hmp_handle_error(mon, &error);
2092 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
2094 Error *error = NULL;
2095 const char *device = qdict_get_str(qdict, "device");
2097 qmp_block_job_pause(device, &error);
2099 hmp_handle_error(mon, &error);
2102 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
2104 Error *error = NULL;
2105 const char *device = qdict_get_str(qdict, "device");
2107 qmp_block_job_resume(device, &error);
2109 hmp_handle_error(mon, &error);
2112 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
2114 Error *error = NULL;
2115 const char *device = qdict_get_str(qdict, "device");
2117 qmp_block_job_complete(device, &error);
2119 hmp_handle_error(mon, &error);
2122 typedef struct HMPMigrationStatus
2126 bool is_block_migration;
2127 } HMPMigrationStatus;
2129 static void hmp_migrate_status_cb(void *opaque)
2131 HMPMigrationStatus *status = opaque;
2132 MigrationInfo *info;
2134 info = qmp_query_migrate(NULL);
2135 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
2136 info->status == MIGRATION_STATUS_SETUP) {
2137 if (info->has_disk) {
2140 if (info->disk->remaining) {
2141 progress = info->disk->transferred * 100 / info->disk->total;
2146 monitor_printf(status->mon, "Completed %d %%\r", progress);
2147 monitor_flush(status->mon);
2150 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
2152 if (status->is_block_migration) {
2153 monitor_printf(status->mon, "\n");
2155 if (info->has_error_desc) {
2156 error_report("%s", info->error_desc);
2158 monitor_resume(status->mon);
2159 timer_del(status->timer);
2160 timer_free(status->timer);
2164 qapi_free_MigrationInfo(info);
2167 void hmp_migrate(Monitor *mon, const QDict *qdict)
2169 bool detach = qdict_get_try_bool(qdict, "detach", false);
2170 bool blk = qdict_get_try_bool(qdict, "blk", false);
2171 bool inc = qdict_get_try_bool(qdict, "inc", false);
2172 bool resume = qdict_get_try_bool(qdict, "resume", false);
2173 const char *uri = qdict_get_str(qdict, "uri");
2176 qmp_migrate(uri, !!blk, blk, !!inc, inc,
2177 false, false, true, resume, &err);
2179 hmp_handle_error(mon, &err);
2184 HMPMigrationStatus *status;
2186 if (monitor_suspend(mon) < 0) {
2187 monitor_printf(mon, "terminal does not allow synchronous "
2188 "migration, continuing detached\n");
2192 status = g_malloc0(sizeof(*status));
2194 status->is_block_migration = blk || inc;
2195 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
2197 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
2201 void hmp_device_add(Monitor *mon, const QDict *qdict)
2205 qmp_device_add((QDict *)qdict, NULL, &err);
2206 hmp_handle_error(mon, &err);
2209 void hmp_device_del(Monitor *mon, const QDict *qdict)
2211 const char *id = qdict_get_str(qdict, "id");
2214 qmp_device_del(id, &err);
2215 hmp_handle_error(mon, &err);
2218 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
2221 bool win_dmp = qdict_get_try_bool(qdict, "windmp", false);
2222 bool paging = qdict_get_try_bool(qdict, "paging", false);
2223 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
2224 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
2225 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
2226 const char *file = qdict_get_str(qdict, "filename");
2227 bool has_begin = qdict_haskey(qdict, "begin");
2228 bool has_length = qdict_haskey(qdict, "length");
2229 bool has_detach = qdict_haskey(qdict, "detach");
2232 bool detach = false;
2233 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
2236 if (zlib + lzo + snappy + win_dmp > 1) {
2237 error_setg(&err, "only one of '-z|-l|-s|-w' can be set");
2238 hmp_handle_error(mon, &err);
2243 dump_format = DUMP_GUEST_MEMORY_FORMAT_WIN_DMP;
2247 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
2251 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
2255 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
2259 begin = qdict_get_int(qdict, "begin");
2262 length = qdict_get_int(qdict, "length");
2265 detach = qdict_get_bool(qdict, "detach");
2268 prot = g_strconcat("file:", file, NULL);
2270 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
2271 has_length, length, true, dump_format, &err);
2272 hmp_handle_error(mon, &err);
2276 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
2281 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
2286 netdev_add(opts, &err);
2288 qemu_opts_del(opts);
2292 hmp_handle_error(mon, &err);
2295 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
2297 const char *id = qdict_get_str(qdict, "id");
2300 qmp_netdev_del(id, &err);
2301 hmp_handle_error(mon, &err);
2304 void hmp_object_add(Monitor *mon, const QDict *qdict)
2310 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
2312 hmp_handle_error(mon, &err);
2316 obj = user_creatable_add_opts(opts, &err);
2317 qemu_opts_del(opts);
2320 hmp_handle_error(mon, &err);
2327 void hmp_getfd(Monitor *mon, const QDict *qdict)
2329 const char *fdname = qdict_get_str(qdict, "fdname");
2332 qmp_getfd(fdname, &err);
2333 hmp_handle_error(mon, &err);
2336 void hmp_closefd(Monitor *mon, const QDict *qdict)
2338 const char *fdname = qdict_get_str(qdict, "fdname");
2341 qmp_closefd(fdname, &err);
2342 hmp_handle_error(mon, &err);
2345 void hmp_sendkey(Monitor *mon, const QDict *qdict)
2347 const char *keys = qdict_get_str(qdict, "keys");
2348 KeyValueList *keylist, *head = NULL, *tmp = NULL;
2349 int has_hold_time = qdict_haskey(qdict, "hold-time");
2350 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
2352 const char *separator;
2356 separator = qemu_strchrnul(keys, '-');
2357 keyname_len = separator - keys;
2359 /* Be compatible with old interface, convert user inputted "<" */
2360 if (keys[0] == '<' && keyname_len == 1) {
2365 keylist = g_malloc0(sizeof(*keylist));
2366 keylist->value = g_malloc0(sizeof(*keylist->value));
2372 tmp->next = keylist;
2376 if (strstart(keys, "0x", NULL)) {
2378 int value = strtoul(keys, &endp, 0);
2379 assert(endp <= keys + keyname_len);
2380 if (endp != keys + keyname_len) {
2383 keylist->value->type = KEY_VALUE_KIND_NUMBER;
2384 keylist->value->u.number.data = value;
2386 int idx = index_from_key(keys, keyname_len);
2387 if (idx == Q_KEY_CODE__MAX) {
2390 keylist->value->type = KEY_VALUE_KIND_QCODE;
2391 keylist->value->u.qcode.data = idx;
2397 keys = separator + 1;
2400 qmp_send_key(head, has_hold_time, hold_time, &err);
2401 hmp_handle_error(mon, &err);
2404 qapi_free_KeyValueList(head);
2408 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
2412 void hmp_screendump(Monitor *mon, const QDict *qdict)
2414 const char *filename = qdict_get_str(qdict, "filename");
2415 const char *id = qdict_get_try_str(qdict, "device");
2416 int64_t head = qdict_get_try_int(qdict, "head", 0);
2419 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
2420 hmp_handle_error(mon, &err);
2423 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
2425 const char *uri = qdict_get_str(qdict, "uri");
2426 bool writable = qdict_get_try_bool(qdict, "writable", false);
2427 bool all = qdict_get_try_bool(qdict, "all", false);
2428 Error *local_err = NULL;
2429 BlockInfoList *block_list, *info;
2430 SocketAddress *addr;
2432 if (writable && !all) {
2433 error_setg(&local_err, "-w only valid together with -a");
2437 /* First check if the address is valid and start the server. */
2438 addr = socket_parse(uri, &local_err);
2439 if (local_err != NULL) {
2443 nbd_server_start(addr, NULL, NULL, &local_err);
2444 qapi_free_SocketAddress(addr);
2445 if (local_err != NULL) {
2453 /* Then try adding all block devices. If one fails, close all and
2456 block_list = qmp_query_block(NULL);
2458 for (info = block_list; info; info = info->next) {
2459 if (!info->value->has_inserted) {
2463 qmp_nbd_server_add(info->value->device, false, NULL,
2464 true, writable, false, NULL, &local_err);
2466 if (local_err != NULL) {
2467 qmp_nbd_server_stop(NULL);
2472 qapi_free_BlockInfoList(block_list);
2475 hmp_handle_error(mon, &local_err);
2478 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
2480 const char *device = qdict_get_str(qdict, "device");
2481 const char *name = qdict_get_try_str(qdict, "name");
2482 bool writable = qdict_get_try_bool(qdict, "writable", false);
2483 Error *local_err = NULL;
2485 qmp_nbd_server_add(device, !!name, name, true, writable,
2486 false, NULL, &local_err);
2487 hmp_handle_error(mon, &local_err);
2490 void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict)
2492 const char *name = qdict_get_str(qdict, "name");
2493 bool force = qdict_get_try_bool(qdict, "force", false);
2496 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
2497 qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err);
2498 hmp_handle_error(mon, &err);
2501 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
2505 qmp_nbd_server_stop(&err);
2506 hmp_handle_error(mon, &err);
2509 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
2514 error_report("cpu_add is deprecated, please use device_add instead");
2516 cpuid = qdict_get_int(qdict, "id");
2517 qmp_cpu_add(cpuid, &err);
2518 hmp_handle_error(mon, &err);
2521 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2523 const char *args = qdict_get_str(qdict, "args");
2527 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
2529 error_setg(&err, "Parsing chardev args failed");
2531 qemu_chr_new_from_opts(opts, NULL, &err);
2532 qemu_opts_del(opts);
2534 hmp_handle_error(mon, &err);
2537 void hmp_chardev_change(Monitor *mon, const QDict *qdict)
2539 const char *args = qdict_get_str(qdict, "args");
2542 ChardevBackend *backend = NULL;
2543 ChardevReturn *ret = NULL;
2544 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
2547 error_setg(&err, "Parsing chardev args failed");
2551 id = qdict_get_str(qdict, "id");
2552 if (qemu_opts_id(opts)) {
2553 error_setg(&err, "Unexpected 'id' parameter");
2557 backend = qemu_chr_parse_opts(opts, &err);
2562 ret = qmp_chardev_change(id, backend, &err);
2565 qapi_free_ChardevReturn(ret);
2566 qapi_free_ChardevBackend(backend);
2567 qemu_opts_del(opts);
2568 hmp_handle_error(mon, &err);
2571 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2573 Error *local_err = NULL;
2575 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
2576 hmp_handle_error(mon, &local_err);
2579 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
2581 Error *local_err = NULL;
2583 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
2584 hmp_handle_error(mon, &local_err);
2587 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
2590 BlockBackend *local_blk = NULL;
2591 const char* device = qdict_get_str(qdict, "device");
2592 const char* command = qdict_get_str(qdict, "command");
2596 blk = blk_by_name(device);
2598 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
2600 blk = local_blk = blk_new(bdrv_get_aio_context(bs),
2602 ret = blk_insert_bs(blk, bs, &err);
2612 * Notably absent: Proper permission management. This is sad, but it seems
2613 * almost impossible to achieve without changing the semantics and thereby
2614 * limiting the use cases of the qemu-io HMP command.
2616 * In an ideal world we would unconditionally create a new BlockBackend for
2617 * qemuio_command(), but we have commands like 'reopen' and want them to
2618 * take effect on the exact BlockBackend whose name the user passed instead
2619 * of just on a temporary copy of it.
2621 * Another problem is that deleting the temporary BlockBackend involves
2622 * draining all requests on it first, but some qemu-iotests cases want to
2623 * issue multiple aio_read/write requests and expect them to complete in
2624 * the background while the monitor has already returned.
2626 * This is also what prevents us from saving the original permissions and
2627 * restoring them later: We can't revoke permissions until all requests
2628 * have completed, and we don't know when that is nor can we really let
2629 * anything else run before we have revoken them to avoid race conditions.
2631 * What happens now is that command() in qemu-io-cmds.c can extend the
2632 * permissions if necessary for the qemu-io command. And they simply stay
2633 * extended, possibly resulting in a read-only guest device keeping write
2634 * permissions. Ugly, but it appears to be the lesser evil.
2636 qemuio_command(blk, command);
2639 blk_unref(local_blk);
2640 hmp_handle_error(mon, &err);
2643 void hmp_object_del(Monitor *mon, const QDict *qdict)
2645 const char *id = qdict_get_str(qdict, "id");
2648 user_creatable_del(id, &err);
2649 hmp_handle_error(mon, &err);
2652 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
2655 MemdevList *memdev_list = qmp_query_memdev(&err);
2656 MemdevList *m = memdev_list;
2661 v = string_output_visitor_new(false, &str);
2662 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
2663 monitor_printf(mon, "memory backend: %s\n", m->value->id);
2664 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
2665 monitor_printf(mon, " merge: %s\n",
2666 m->value->merge ? "true" : "false");
2667 monitor_printf(mon, " dump: %s\n",
2668 m->value->dump ? "true" : "false");
2669 monitor_printf(mon, " prealloc: %s\n",
2670 m->value->prealloc ? "true" : "false");
2671 monitor_printf(mon, " policy: %s\n",
2672 HostMemPolicy_str(m->value->policy));
2673 visit_complete(v, &str);
2674 monitor_printf(mon, " host nodes: %s\n", str);
2681 monitor_printf(mon, "\n");
2683 qapi_free_MemdevList(memdev_list);
2684 hmp_handle_error(mon, &err);
2687 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2690 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2691 MemoryDeviceInfoList *info;
2692 MemoryDeviceInfo *value;
2693 PCDIMMDeviceInfo *di;
2695 for (info = info_list; info; info = info->next) {
2696 value = info->value;
2699 switch (value->type) {
2700 case MEMORY_DEVICE_INFO_KIND_DIMM:
2701 di = value->u.dimm.data;
2704 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
2705 di = value->u.nvdimm.data;
2714 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2715 MemoryDeviceInfoKind_str(value->type),
2716 di->id ? di->id : "");
2717 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2718 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2719 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2720 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2721 monitor_printf(mon, " memdev: %s\n", di->memdev);
2722 monitor_printf(mon, " hotplugged: %s\n",
2723 di->hotplugged ? "true" : "false");
2724 monitor_printf(mon, " hotpluggable: %s\n",
2725 di->hotpluggable ? "true" : "false");
2730 qapi_free_MemoryDeviceInfoList(info_list);
2731 hmp_handle_error(mon, &err);
2734 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2736 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2737 IOThreadInfoList *info;
2738 IOThreadInfo *value;
2740 for (info = info_list; info; info = info->next) {
2741 value = info->value;
2742 monitor_printf(mon, "%s:\n", value->id);
2743 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
2744 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2745 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
2746 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
2749 qapi_free_IOThreadInfoList(info_list);
2752 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2754 const char *path = qdict_get_try_str(qdict, "path");
2755 ObjectPropertyInfoList *list;
2759 monitor_printf(mon, "/\n");
2763 list = qmp_qom_list(path, &err);
2765 ObjectPropertyInfoList *start = list;
2766 while (list != NULL) {
2767 ObjectPropertyInfo *value = list->value;
2769 monitor_printf(mon, "%s (%s)\n",
2770 value->name, value->type);
2773 qapi_free_ObjectPropertyInfoList(start);
2775 hmp_handle_error(mon, &err);
2778 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2780 const char *path = qdict_get_str(qdict, "path");
2781 const char *property = qdict_get_str(qdict, "property");
2782 const char *value = qdict_get_str(qdict, "value");
2784 bool ambiguous = false;
2787 obj = object_resolve_path(path, &ambiguous);
2789 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2790 "Device '%s' not found", path);
2793 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2795 object_property_parse(obj, value, property, &err);
2797 hmp_handle_error(mon, &err);
2800 void hmp_rocker(Monitor *mon, const QDict *qdict)
2802 const char *name = qdict_get_str(qdict, "name");
2803 RockerSwitch *rocker;
2806 rocker = qmp_query_rocker(name, &err);
2808 hmp_handle_error(mon, &err);
2812 monitor_printf(mon, "name: %s\n", rocker->name);
2813 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2814 monitor_printf(mon, "ports: %d\n", rocker->ports);
2816 qapi_free_RockerSwitch(rocker);
2819 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2821 RockerPortList *list, *port;
2822 const char *name = qdict_get_str(qdict, "name");
2825 list = qmp_query_rocker_ports(name, &err);
2827 hmp_handle_error(mon, &err);
2831 monitor_printf(mon, " ena/ speed/ auto\n");
2832 monitor_printf(mon, " port link duplex neg?\n");
2834 for (port = list; port; port = port->next) {
2835 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2837 port->value->enabled ? port->value->link_up ?
2838 "up" : "down" : "!ena",
2839 port->value->speed == 10000 ? "10G" : "??",
2840 port->value->duplex ? "FD" : "HD",
2841 port->value->autoneg ? "Yes" : "No");
2844 qapi_free_RockerPortList(list);
2847 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2849 RockerOfDpaFlowList *list, *info;
2850 const char *name = qdict_get_str(qdict, "name");
2851 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2854 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2856 hmp_handle_error(mon, &err);
2860 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2862 for (info = list; info; info = info->next) {
2863 RockerOfDpaFlow *flow = info->value;
2864 RockerOfDpaFlowKey *key = flow->key;
2865 RockerOfDpaFlowMask *mask = flow->mask;
2866 RockerOfDpaFlowAction *action = flow->action;
2869 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2870 key->priority, key->tbl_id, flow->hits);
2872 monitor_printf(mon, "%-4d %-3d ",
2873 key->priority, key->tbl_id);
2876 if (key->has_in_pport) {
2877 monitor_printf(mon, " pport %d", key->in_pport);
2878 if (mask->has_in_pport) {
2879 monitor_printf(mon, "(0x%x)", mask->in_pport);
2883 if (key->has_vlan_id) {
2884 monitor_printf(mon, " vlan %d",
2885 key->vlan_id & VLAN_VID_MASK);
2886 if (mask->has_vlan_id) {
2887 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2891 if (key->has_tunnel_id) {
2892 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2893 if (mask->has_tunnel_id) {
2894 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2898 if (key->has_eth_type) {
2899 switch (key->eth_type) {
2901 monitor_printf(mon, " ARP");
2904 monitor_printf(mon, " IP");
2907 monitor_printf(mon, " IPv6");
2910 monitor_printf(mon, " LACP");
2913 monitor_printf(mon, " LLDP");
2916 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2921 if (key->has_eth_src) {
2922 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2923 (mask->has_eth_src) &&
2924 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2925 monitor_printf(mon, " src <any mcast/bcast>");
2926 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2927 (mask->has_eth_src) &&
2928 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2929 monitor_printf(mon, " src <any ucast>");
2931 monitor_printf(mon, " src %s", key->eth_src);
2932 if (mask->has_eth_src) {
2933 monitor_printf(mon, "(%s)", mask->eth_src);
2938 if (key->has_eth_dst) {
2939 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2940 (mask->has_eth_dst) &&
2941 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2942 monitor_printf(mon, " dst <any mcast/bcast>");
2943 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2944 (mask->has_eth_dst) &&
2945 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2946 monitor_printf(mon, " dst <any ucast>");
2948 monitor_printf(mon, " dst %s", key->eth_dst);
2949 if (mask->has_eth_dst) {
2950 monitor_printf(mon, "(%s)", mask->eth_dst);
2955 if (key->has_ip_proto) {
2956 monitor_printf(mon, " proto %d", key->ip_proto);
2957 if (mask->has_ip_proto) {
2958 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2962 if (key->has_ip_tos) {
2963 monitor_printf(mon, " TOS %d", key->ip_tos);
2964 if (mask->has_ip_tos) {
2965 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2969 if (key->has_ip_dst) {
2970 monitor_printf(mon, " dst %s", key->ip_dst);
2973 if (action->has_goto_tbl || action->has_group_id ||
2974 action->has_new_vlan_id) {
2975 monitor_printf(mon, " -->");
2978 if (action->has_new_vlan_id) {
2979 monitor_printf(mon, " apply new vlan %d",
2980 ntohs(action->new_vlan_id));
2983 if (action->has_group_id) {
2984 monitor_printf(mon, " write group 0x%08x", action->group_id);
2987 if (action->has_goto_tbl) {
2988 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2991 monitor_printf(mon, "\n");
2994 qapi_free_RockerOfDpaFlowList(list);
2997 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2999 RockerOfDpaGroupList *list, *g;
3000 const char *name = qdict_get_str(qdict, "name");
3001 uint8_t type = qdict_get_try_int(qdict, "type", 9);
3005 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
3007 hmp_handle_error(mon, &err);
3011 monitor_printf(mon, "id (decode) --> buckets\n");
3013 for (g = list; g; g = g->next) {
3014 RockerOfDpaGroup *group = g->value;
3016 monitor_printf(mon, "0x%08x", group->id);
3018 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
3019 group->type == 1 ? "L2 rewrite" :
3020 group->type == 2 ? "L3 unicast" :
3021 group->type == 3 ? "L2 multicast" :
3022 group->type == 4 ? "L2 flood" :
3023 group->type == 5 ? "L3 interface" :
3024 group->type == 6 ? "L3 multicast" :
3025 group->type == 7 ? "L3 ECMP" :
3026 group->type == 8 ? "L2 overlay" :
3029 if (group->has_vlan_id) {
3030 monitor_printf(mon, " vlan %d", group->vlan_id);
3033 if (group->has_pport) {
3034 monitor_printf(mon, " pport %d", group->pport);
3037 if (group->has_index) {
3038 monitor_printf(mon, " index %d", group->index);
3041 monitor_printf(mon, ") -->");
3043 if (group->has_set_vlan_id && group->set_vlan_id) {
3045 monitor_printf(mon, " set vlan %d",
3046 group->set_vlan_id & VLAN_VID_MASK);
3049 if (group->has_set_eth_src) {
3052 monitor_printf(mon, " set");
3054 monitor_printf(mon, " src %s", group->set_eth_src);
3057 if (group->has_set_eth_dst) {
3060 monitor_printf(mon, " set");
3062 monitor_printf(mon, " dst %s", group->set_eth_dst);
3067 if (group->has_ttl_check && group->ttl_check) {
3068 monitor_printf(mon, " check TTL");
3071 if (group->has_group_id && group->group_id) {
3072 monitor_printf(mon, " group id 0x%08x", group->group_id);
3075 if (group->has_pop_vlan && group->pop_vlan) {
3076 monitor_printf(mon, " pop vlan");
3079 if (group->has_out_pport) {
3080 monitor_printf(mon, " out pport %d", group->out_pport);
3083 if (group->has_group_ids) {
3084 struct uint32List *id;
3086 monitor_printf(mon, " groups [");
3087 for (id = group->group_ids; id; id = id->next) {
3088 monitor_printf(mon, "0x%08x", id->value);
3090 monitor_printf(mon, ",");
3093 monitor_printf(mon, "]");
3096 monitor_printf(mon, "\n");
3099 qapi_free_RockerOfDpaGroupList(list);
3102 void hmp_info_dump(Monitor *mon, const QDict *qdict)
3104 DumpQueryResult *result = qmp_query_dump(NULL);
3106 assert(result && result->status < DUMP_STATUS__MAX);
3107 monitor_printf(mon, "Status: %s\n", DumpStatus_str(result->status));
3109 if (result->status == DUMP_STATUS_ACTIVE) {
3111 assert(result->total != 0);
3112 percent = 100.0 * result->completed / result->total;
3113 monitor_printf(mon, "Finished: %.2f %%\n", percent);
3116 qapi_free_DumpQueryResult(result);
3119 void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
3121 ram_block_dump(mon);
3124 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
3127 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
3128 HotpluggableCPUList *saved = l;
3129 CpuInstanceProperties *c;
3132 hmp_handle_error(mon, &err);
3136 monitor_printf(mon, "Hotpluggable CPUs:\n");
3138 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
3139 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
3140 l->value->vcpus_count);
3141 if (l->value->has_qom_path) {
3142 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
3145 c = l->value->props;
3146 monitor_printf(mon, " CPUInstance Properties:\n");
3147 if (c->has_node_id) {
3148 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
3150 if (c->has_socket_id) {
3151 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
3153 if (c->has_core_id) {
3154 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
3156 if (c->has_thread_id) {
3157 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
3163 qapi_free_HotpluggableCPUList(saved);
3166 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
3169 GuidInfo *info = qmp_query_vm_generation_id(&err);
3171 monitor_printf(mon, "%s\n", info->guid);
3173 hmp_handle_error(mon, &err);
3174 qapi_free_GuidInfo(info);
3177 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
3180 MemoryInfo *info = qmp_query_memory_size_summary(&err);
3182 monitor_printf(mon, "base memory: %" PRIu64 "\n",
3185 if (info->has_plugged_memory) {
3186 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
3187 info->plugged_memory);
3190 qapi_free_MemoryInfo(info);
3192 hmp_handle_error(mon, &err);