2 * Human Monitor Interface
4 * Copyright IBM, Corp. 2011
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
16 #include "qemu/osdep.h"
20 #include "sysemu/char.h"
21 #include "sysemu/block-backend.h"
22 #include "qemu/option.h"
23 #include "qemu/timer.h"
24 #include "qmp-commands.h"
25 #include "qemu/sockets.h"
26 #include "monitor/monitor.h"
27 #include "monitor/qdev.h"
28 #include "qapi/opts-visitor.h"
29 #include "qapi/qmp/qerror.h"
30 #include "qapi/string-output-visitor.h"
31 #include "qapi/util.h"
32 #include "qapi-visit.h"
33 #include "qom/object_interfaces.h"
34 #include "ui/console.h"
35 #include "block/qapi.h"
37 #include "qemu/cutils.h"
38 #include "qemu/error-report.h"
41 #include <spice/enums.h>
44 static void hmp_handle_error(Monitor *mon, Error **errp)
48 error_report_err(*errp);
52 void hmp_info_name(Monitor *mon, const QDict *qdict)
56 info = qmp_query_name(NULL);
58 monitor_printf(mon, "%s\n", info->name);
60 qapi_free_NameInfo(info);
63 void hmp_info_version(Monitor *mon, const QDict *qdict)
67 info = qmp_query_version(NULL);
69 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
70 info->qemu->major, info->qemu->minor, info->qemu->micro,
73 qapi_free_VersionInfo(info);
76 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
80 info = qmp_query_kvm(NULL);
81 monitor_printf(mon, "kvm support: ");
83 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
85 monitor_printf(mon, "not compiled\n");
88 qapi_free_KvmInfo(info);
91 void hmp_info_status(Monitor *mon, const QDict *qdict)
95 info = qmp_query_status(NULL);
97 monitor_printf(mon, "VM status: %s%s",
98 info->running ? "running" : "paused",
99 info->singlestep ? " (single step mode)" : "");
101 if (!info->running && info->status != RUN_STATE_PAUSED) {
102 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
105 monitor_printf(mon, "\n");
107 qapi_free_StatusInfo(info);
110 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
114 info = qmp_query_uuid(NULL);
115 monitor_printf(mon, "%s\n", info->UUID);
116 qapi_free_UuidInfo(info);
119 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
121 ChardevInfoList *char_info, *info;
123 char_info = qmp_query_chardev(NULL);
124 for (info = char_info; info; info = info->next) {
125 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
126 info->value->filename);
129 qapi_free_ChardevInfoList(char_info);
132 void hmp_info_mice(Monitor *mon, const QDict *qdict)
134 MouseInfoList *mice_list, *mouse;
136 mice_list = qmp_query_mice(NULL);
138 monitor_printf(mon, "No mouse devices connected\n");
142 for (mouse = mice_list; mouse; mouse = mouse->next) {
143 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
144 mouse->value->current ? '*' : ' ',
145 mouse->value->index, mouse->value->name,
146 mouse->value->absolute ? " (absolute)" : "");
149 qapi_free_MouseInfoList(mice_list);
152 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
155 MigrationCapabilityStatusList *caps, *cap;
157 info = qmp_query_migrate(NULL);
158 caps = qmp_query_migrate_capabilities(NULL);
160 /* do not display parameters during setup */
161 if (info->has_status && caps) {
162 monitor_printf(mon, "capabilities: ");
163 for (cap = caps; cap; cap = cap->next) {
164 monitor_printf(mon, "%s: %s ",
165 MigrationCapability_lookup[cap->value->capability],
166 cap->value->state ? "on" : "off");
168 monitor_printf(mon, "\n");
171 if (info->has_status) {
172 monitor_printf(mon, "Migration status: %s",
173 MigrationStatus_lookup[info->status]);
174 if (info->status == MIGRATION_STATUS_FAILED &&
175 info->has_error_desc) {
176 monitor_printf(mon, " (%s)\n", info->error_desc);
178 monitor_printf(mon, "\n");
181 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
183 if (info->has_expected_downtime) {
184 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
185 info->expected_downtime);
187 if (info->has_downtime) {
188 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
191 if (info->has_setup_time) {
192 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
198 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
199 info->ram->transferred >> 10);
200 monitor_printf(mon, "throughput: %0.2f mbps\n",
202 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
203 info->ram->remaining >> 10);
204 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
205 info->ram->total >> 10);
206 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
207 info->ram->duplicate);
208 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
210 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
212 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
213 info->ram->normal_bytes >> 10);
214 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
215 info->ram->dirty_sync_count);
216 if (info->ram->dirty_pages_rate) {
217 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
218 info->ram->dirty_pages_rate);
220 if (info->ram->postcopy_requests) {
221 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
222 info->ram->postcopy_requests);
226 if (info->has_disk) {
227 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
228 info->disk->transferred >> 10);
229 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
230 info->disk->remaining >> 10);
231 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
232 info->disk->total >> 10);
235 if (info->has_xbzrle_cache) {
236 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
237 info->xbzrle_cache->cache_size);
238 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
239 info->xbzrle_cache->bytes >> 10);
240 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
241 info->xbzrle_cache->pages);
242 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
243 info->xbzrle_cache->cache_miss);
244 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
245 info->xbzrle_cache->cache_miss_rate);
246 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
247 info->xbzrle_cache->overflow);
250 if (info->has_cpu_throttle_percentage) {
251 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
252 info->cpu_throttle_percentage);
255 qapi_free_MigrationInfo(info);
256 qapi_free_MigrationCapabilityStatusList(caps);
259 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
261 MigrationCapabilityStatusList *caps, *cap;
263 caps = qmp_query_migrate_capabilities(NULL);
266 monitor_printf(mon, "capabilities: ");
267 for (cap = caps; cap; cap = cap->next) {
268 monitor_printf(mon, "%s: %s ",
269 MigrationCapability_lookup[cap->value->capability],
270 cap->value->state ? "on" : "off");
272 monitor_printf(mon, "\n");
275 qapi_free_MigrationCapabilityStatusList(caps);
278 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
280 MigrationParameters *params;
282 params = qmp_query_migrate_parameters(NULL);
285 monitor_printf(mon, "parameters:");
286 monitor_printf(mon, " %s: %" PRId64,
287 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_LEVEL],
288 params->compress_level);
289 monitor_printf(mon, " %s: %" PRId64,
290 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_THREADS],
291 params->compress_threads);
292 monitor_printf(mon, " %s: %" PRId64,
293 MigrationParameter_lookup[MIGRATION_PARAMETER_DECOMPRESS_THREADS],
294 params->decompress_threads);
295 monitor_printf(mon, " %s: %" PRId64,
296 MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL],
297 params->cpu_throttle_initial);
298 monitor_printf(mon, " %s: %" PRId64,
299 MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT],
300 params->cpu_throttle_increment);
301 monitor_printf(mon, " %s: '%s'",
302 MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_CREDS],
303 params->tls_creds ? : "");
304 monitor_printf(mon, " %s: '%s'",
305 MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_HOSTNAME],
306 params->tls_hostname ? : "");
307 monitor_printf(mon, "\n");
310 qapi_free_MigrationParameters(params);
313 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
315 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
316 qmp_query_migrate_cache_size(NULL) >> 10);
319 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
321 CpuInfoList *cpu_list, *cpu;
323 cpu_list = qmp_query_cpus(NULL);
325 for (cpu = cpu_list; cpu; cpu = cpu->next) {
328 if (cpu->value->CPU == monitor_get_cpu_index()) {
332 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
334 switch (cpu->value->arch) {
335 case CPU_INFO_ARCH_X86:
336 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->u.x86.pc);
338 case CPU_INFO_ARCH_PPC:
339 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->u.ppc.nip);
341 case CPU_INFO_ARCH_SPARC:
342 monitor_printf(mon, " pc=0x%016" PRIx64,
343 cpu->value->u.q_sparc.pc);
344 monitor_printf(mon, " npc=0x%016" PRIx64,
345 cpu->value->u.q_sparc.npc);
347 case CPU_INFO_ARCH_MIPS:
348 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.q_mips.PC);
350 case CPU_INFO_ARCH_TRICORE:
351 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.tricore.PC);
357 if (cpu->value->halted) {
358 monitor_printf(mon, " (halted)");
361 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
364 qapi_free_CpuInfoList(cpu_list);
367 static void print_block_info(Monitor *mon, BlockInfo *info,
368 BlockDeviceInfo *inserted, bool verbose)
370 ImageInfo *image_info;
372 assert(!info || !info->has_inserted || info->inserted == inserted);
375 monitor_printf(mon, "%s", info->device);
376 if (inserted && inserted->has_node_name) {
377 monitor_printf(mon, " (%s)", inserted->node_name);
381 monitor_printf(mon, "%s",
382 inserted->has_node_name
383 ? inserted->node_name
388 monitor_printf(mon, ": %s (%s%s%s)\n",
391 inserted->ro ? ", read-only" : "",
392 inserted->encrypted ? ", encrypted" : "");
394 monitor_printf(mon, ": [not inserted]\n");
398 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
399 monitor_printf(mon, " I/O status: %s\n",
400 BlockDeviceIoStatus_lookup[info->io_status]);
403 if (info->removable) {
404 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
405 info->locked ? "" : "not ",
406 info->tray_open ? "open" : "closed");
415 monitor_printf(mon, " Cache mode: %s%s%s\n",
416 inserted->cache->writeback ? "writeback" : "writethrough",
417 inserted->cache->direct ? ", direct" : "",
418 inserted->cache->no_flush ? ", ignore flushes" : "");
420 if (inserted->has_backing_file) {
423 "(chain depth: %" PRId64 ")\n",
424 inserted->backing_file,
425 inserted->backing_file_depth);
428 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
429 monitor_printf(mon, " Detect zeroes: %s\n",
430 BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]);
433 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
434 inserted->iops || inserted->iops_rd || inserted->iops_wr)
436 monitor_printf(mon, " I/O throttling: bps=%" PRId64
437 " bps_rd=%" PRId64 " bps_wr=%" PRId64
439 " bps_rd_max=%" PRId64
440 " bps_wr_max=%" PRId64
441 " iops=%" PRId64 " iops_rd=%" PRId64
444 " iops_rd_max=%" PRId64
445 " iops_wr_max=%" PRId64
446 " iops_size=%" PRId64
452 inserted->bps_rd_max,
453 inserted->bps_wr_max,
458 inserted->iops_rd_max,
459 inserted->iops_wr_max,
465 monitor_printf(mon, "\nImages:\n");
466 image_info = inserted->image;
468 bdrv_image_info_dump((fprintf_function)monitor_printf,
470 if (image_info->has_backing_image) {
471 image_info = image_info->backing_image;
479 void hmp_info_block(Monitor *mon, const QDict *qdict)
481 BlockInfoList *block_list, *info;
482 BlockDeviceInfoList *blockdev_list, *blockdev;
483 const char *device = qdict_get_try_str(qdict, "device");
484 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
485 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
486 bool printed = false;
488 /* Print BlockBackend information */
490 block_list = qmp_query_block(NULL);
495 for (info = block_list; info; info = info->next) {
496 if (device && strcmp(device, info->value->device)) {
500 if (info != block_list) {
501 monitor_printf(mon, "\n");
504 print_block_info(mon, info->value, info->value->has_inserted
505 ? info->value->inserted : NULL,
510 qapi_free_BlockInfoList(block_list);
512 if ((!device && !nodes) || printed) {
516 /* Print node information */
517 blockdev_list = qmp_query_named_block_nodes(NULL);
518 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
519 assert(blockdev->value->has_node_name);
520 if (device && strcmp(device, blockdev->value->node_name)) {
524 if (blockdev != blockdev_list) {
525 monitor_printf(mon, "\n");
528 print_block_info(mon, NULL, blockdev->value, verbose);
530 qapi_free_BlockDeviceInfoList(blockdev_list);
533 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
535 BlockStatsList *stats_list, *stats;
537 stats_list = qmp_query_blockstats(false, false, NULL);
539 for (stats = stats_list; stats; stats = stats->next) {
540 if (!stats->value->has_device) {
544 monitor_printf(mon, "%s:", stats->value->device);
545 monitor_printf(mon, " rd_bytes=%" PRId64
547 " rd_operations=%" PRId64
548 " wr_operations=%" PRId64
549 " flush_operations=%" PRId64
550 " wr_total_time_ns=%" PRId64
551 " rd_total_time_ns=%" PRId64
552 " flush_total_time_ns=%" PRId64
553 " rd_merged=%" PRId64
554 " wr_merged=%" PRId64
555 " idle_time_ns=%" PRId64
557 stats->value->stats->rd_bytes,
558 stats->value->stats->wr_bytes,
559 stats->value->stats->rd_operations,
560 stats->value->stats->wr_operations,
561 stats->value->stats->flush_operations,
562 stats->value->stats->wr_total_time_ns,
563 stats->value->stats->rd_total_time_ns,
564 stats->value->stats->flush_total_time_ns,
565 stats->value->stats->rd_merged,
566 stats->value->stats->wr_merged,
567 stats->value->stats->idle_time_ns);
570 qapi_free_BlockStatsList(stats_list);
573 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
577 VncClientInfoList *client;
579 info = qmp_query_vnc(&err);
581 error_report_err(err);
585 if (!info->enabled) {
586 monitor_printf(mon, "Server: disabled\n");
590 monitor_printf(mon, "Server:\n");
591 if (info->has_host && info->has_service) {
592 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
594 if (info->has_auth) {
595 monitor_printf(mon, " auth: %s\n", info->auth);
598 if (!info->has_clients || info->clients == NULL) {
599 monitor_printf(mon, "Client: none\n");
601 for (client = info->clients; client; client = client->next) {
602 monitor_printf(mon, "Client:\n");
603 monitor_printf(mon, " address: %s:%s\n",
605 client->value->service);
606 monitor_printf(mon, " x509_dname: %s\n",
607 client->value->x509_dname ?
608 client->value->x509_dname : "none");
609 monitor_printf(mon, " username: %s\n",
610 client->value->has_sasl_username ?
611 client->value->sasl_username : "none");
616 qapi_free_VncInfo(info);
620 void hmp_info_spice(Monitor *mon, const QDict *qdict)
622 SpiceChannelList *chan;
624 const char *channel_name;
625 const char * const channel_names[] = {
626 [SPICE_CHANNEL_MAIN] = "main",
627 [SPICE_CHANNEL_DISPLAY] = "display",
628 [SPICE_CHANNEL_INPUTS] = "inputs",
629 [SPICE_CHANNEL_CURSOR] = "cursor",
630 [SPICE_CHANNEL_PLAYBACK] = "playback",
631 [SPICE_CHANNEL_RECORD] = "record",
632 [SPICE_CHANNEL_TUNNEL] = "tunnel",
633 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
634 [SPICE_CHANNEL_USBREDIR] = "usbredir",
635 [SPICE_CHANNEL_PORT] = "port",
637 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
638 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
639 * as quick fix for build failures with older versions. */
640 [SPICE_CHANNEL_WEBDAV] = "webdav",
644 info = qmp_query_spice(NULL);
646 if (!info->enabled) {
647 monitor_printf(mon, "Server: disabled\n");
651 monitor_printf(mon, "Server:\n");
652 if (info->has_port) {
653 monitor_printf(mon, " address: %s:%" PRId64 "\n",
654 info->host, info->port);
656 if (info->has_tls_port) {
657 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
658 info->host, info->tls_port);
660 monitor_printf(mon, " migrated: %s\n",
661 info->migrated ? "true" : "false");
662 monitor_printf(mon, " auth: %s\n", info->auth);
663 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
664 monitor_printf(mon, " mouse-mode: %s\n",
665 SpiceQueryMouseMode_lookup[info->mouse_mode]);
667 if (!info->has_channels || info->channels == NULL) {
668 monitor_printf(mon, "Channels: none\n");
670 for (chan = info->channels; chan; chan = chan->next) {
671 monitor_printf(mon, "Channel:\n");
672 monitor_printf(mon, " address: %s:%s%s\n",
673 chan->value->host, chan->value->port,
674 chan->value->tls ? " [tls]" : "");
675 monitor_printf(mon, " session: %" PRId64 "\n",
676 chan->value->connection_id);
677 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
678 chan->value->channel_type, chan->value->channel_id);
680 channel_name = "unknown";
681 if (chan->value->channel_type > 0 &&
682 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
683 channel_names[chan->value->channel_type]) {
684 channel_name = channel_names[chan->value->channel_type];
687 monitor_printf(mon, " channel name: %s\n", channel_name);
692 qapi_free_SpiceInfo(info);
696 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
701 info = qmp_query_balloon(&err);
703 error_report_err(err);
707 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
709 qapi_free_BalloonInfo(info);
712 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
714 PciMemoryRegionList *region;
716 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
717 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
718 dev->slot, dev->function);
719 monitor_printf(mon, " ");
721 if (dev->class_info->has_desc) {
722 monitor_printf(mon, "%s", dev->class_info->desc);
724 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
727 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
728 dev->id->vendor, dev->id->device);
731 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
734 if (dev->has_pci_bridge) {
735 monitor_printf(mon, " BUS %" PRId64 ".\n",
736 dev->pci_bridge->bus->number);
737 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
738 dev->pci_bridge->bus->secondary);
739 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
740 dev->pci_bridge->bus->subordinate);
742 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
743 dev->pci_bridge->bus->io_range->base,
744 dev->pci_bridge->bus->io_range->limit);
747 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
748 dev->pci_bridge->bus->memory_range->base,
749 dev->pci_bridge->bus->memory_range->limit);
751 monitor_printf(mon, " prefetchable memory range "
752 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
753 dev->pci_bridge->bus->prefetchable_range->base,
754 dev->pci_bridge->bus->prefetchable_range->limit);
757 for (region = dev->regions; region; region = region->next) {
760 addr = region->value->address;
761 size = region->value->size;
763 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
765 if (!strcmp(region->value->type, "io")) {
766 monitor_printf(mon, "I/O at 0x%04" PRIx64
767 " [0x%04" PRIx64 "].\n",
768 addr, addr + size - 1);
770 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
771 " [0x%08" PRIx64 "].\n",
772 region->value->mem_type_64 ? 64 : 32,
773 region->value->prefetch ? " prefetchable" : "",
774 addr, addr + size - 1);
778 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
780 if (dev->has_pci_bridge) {
781 if (dev->pci_bridge->has_devices) {
782 PciDeviceInfoList *cdev;
783 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
784 hmp_info_pci_device(mon, cdev->value);
790 void hmp_info_pci(Monitor *mon, const QDict *qdict)
792 PciInfoList *info_list, *info;
795 info_list = qmp_query_pci(&err);
797 monitor_printf(mon, "PCI devices not supported\n");
802 for (info = info_list; info; info = info->next) {
803 PciDeviceInfoList *dev;
805 for (dev = info->value->devices; dev; dev = dev->next) {
806 hmp_info_pci_device(mon, dev->value);
810 qapi_free_PciInfoList(info_list);
813 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
815 BlockJobInfoList *list;
818 list = qmp_query_block_jobs(&err);
822 monitor_printf(mon, "No active jobs\n");
827 if (strcmp(list->value->type, "stream") == 0) {
828 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
829 " of %" PRId64 " bytes, speed limit %" PRId64
836 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
837 " of %" PRId64 " bytes, speed limit %" PRId64
848 qapi_free_BlockJobInfoList(list);
851 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
853 TPMInfoList *info_list, *info;
856 TPMPassthroughOptions *tpo;
858 info_list = qmp_query_tpm(&err);
860 monitor_printf(mon, "TPM device not supported\n");
866 monitor_printf(mon, "TPM device:\n");
869 for (info = info_list; info; info = info->next) {
870 TPMInfo *ti = info->value;
871 monitor_printf(mon, " tpm%d: model=%s\n",
872 c, TpmModel_lookup[ti->model]);
874 monitor_printf(mon, " \\ %s: type=%s",
875 ti->id, TpmTypeOptionsKind_lookup[ti->options->type]);
877 switch (ti->options->type) {
878 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
879 tpo = ti->options->u.passthrough.data;
880 monitor_printf(mon, "%s%s%s%s",
881 tpo->has_path ? ",path=" : "",
882 tpo->has_path ? tpo->path : "",
883 tpo->has_cancel_path ? ",cancel-path=" : "",
884 tpo->has_cancel_path ? tpo->cancel_path : "");
886 case TPM_TYPE_OPTIONS_KIND__MAX:
889 monitor_printf(mon, "\n");
892 qapi_free_TPMInfoList(info_list);
895 void hmp_quit(Monitor *mon, const QDict *qdict)
897 monitor_suspend(mon);
901 void hmp_stop(Monitor *mon, const QDict *qdict)
906 void hmp_system_reset(Monitor *mon, const QDict *qdict)
908 qmp_system_reset(NULL);
911 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
913 qmp_system_powerdown(NULL);
916 void hmp_cpu(Monitor *mon, const QDict *qdict)
920 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
921 use it are converted to the QAPI */
922 cpu_index = qdict_get_int(qdict, "index");
923 if (monitor_set_cpu(cpu_index) < 0) {
924 monitor_printf(mon, "invalid CPU index\n");
928 void hmp_memsave(Monitor *mon, const QDict *qdict)
930 uint32_t size = qdict_get_int(qdict, "size");
931 const char *filename = qdict_get_str(qdict, "filename");
932 uint64_t addr = qdict_get_int(qdict, "val");
935 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &err);
936 hmp_handle_error(mon, &err);
939 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
941 uint32_t size = qdict_get_int(qdict, "size");
942 const char *filename = qdict_get_str(qdict, "filename");
943 uint64_t addr = qdict_get_int(qdict, "val");
946 qmp_pmemsave(addr, size, filename, &err);
947 hmp_handle_error(mon, &err);
950 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
952 const char *chardev = qdict_get_str(qdict, "device");
953 const char *data = qdict_get_str(qdict, "data");
956 qmp_ringbuf_write(chardev, data, false, 0, &err);
958 hmp_handle_error(mon, &err);
961 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
963 uint32_t size = qdict_get_int(qdict, "size");
964 const char *chardev = qdict_get_str(qdict, "device");
969 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
971 error_report_err(err);
975 for (i = 0; data[i]; i++) {
976 unsigned char ch = data[i];
979 monitor_printf(mon, "\\\\");
980 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
981 monitor_printf(mon, "\\u%04X", ch);
983 monitor_printf(mon, "%c", ch);
987 monitor_printf(mon, "\n");
991 static void hmp_cont_cb(void *opaque, int err)
998 static bool key_is_missing(const BlockInfo *bdev)
1000 return (bdev->inserted && bdev->inserted->encryption_key_missing);
1003 void hmp_cont(Monitor *mon, const QDict *qdict)
1005 BlockInfoList *bdev_list, *bdev;
1008 bdev_list = qmp_query_block(NULL);
1009 for (bdev = bdev_list; bdev; bdev = bdev->next) {
1010 if (key_is_missing(bdev->value)) {
1011 monitor_read_block_device_key(mon, bdev->value->device,
1018 hmp_handle_error(mon, &err);
1021 qapi_free_BlockInfoList(bdev_list);
1024 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1026 qmp_system_wakeup(NULL);
1029 void hmp_nmi(Monitor *mon, const QDict *qdict)
1033 qmp_inject_nmi(&err);
1034 hmp_handle_error(mon, &err);
1037 void hmp_set_link(Monitor *mon, const QDict *qdict)
1039 const char *name = qdict_get_str(qdict, "name");
1040 bool up = qdict_get_bool(qdict, "up");
1043 qmp_set_link(name, up, &err);
1044 hmp_handle_error(mon, &err);
1047 #if defined(CONFIG_MARU)
1048 void hmp_get_link(Monitor *mon, const QDict *qdict)
1050 const char *name = qdict_get_str(qdict, "name");
1053 info = qmp_get_link(name, &errp);
1055 hmp_handle_error(mon, &errp);
1059 monitor_printf(mon, "%s\n", info->is_up ? "on": "off");
1064 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1066 const char *device = qdict_get_str(qdict, "device");
1067 const char *password = qdict_get_str(qdict, "password");
1070 qmp_block_passwd(true, device, false, NULL, password, &err);
1071 hmp_handle_error(mon, &err);
1074 void hmp_balloon(Monitor *mon, const QDict *qdict)
1076 int64_t value = qdict_get_int(qdict, "value");
1079 qmp_balloon(value, &err);
1081 error_report_err(err);
1085 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1087 const char *device = qdict_get_str(qdict, "device");
1088 int64_t size = qdict_get_int(qdict, "size");
1091 qmp_block_resize(true, device, false, NULL, size, &err);
1092 hmp_handle_error(mon, &err);
1095 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1097 const char *filename = qdict_get_str(qdict, "target");
1098 const char *format = qdict_get_try_str(qdict, "format");
1099 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1100 bool full = qdict_get_try_bool(qdict, "full", false);
1102 DriveMirror mirror = {
1103 .device = (char *)qdict_get_str(qdict, "device"),
1104 .target = (char *)filename,
1105 .has_format = !!format,
1106 .format = (char *)format,
1107 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1109 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1114 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1115 hmp_handle_error(mon, &err);
1118 qmp_drive_mirror(&mirror, &err);
1119 hmp_handle_error(mon, &err);
1122 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1124 const char *device = qdict_get_str(qdict, "device");
1125 const char *filename = qdict_get_str(qdict, "target");
1126 const char *format = qdict_get_try_str(qdict, "format");
1127 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1128 bool full = qdict_get_try_bool(qdict, "full", false);
1129 enum NewImageMode mode;
1133 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1134 hmp_handle_error(mon, &err);
1139 mode = NEW_IMAGE_MODE_EXISTING;
1141 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1144 qmp_drive_backup(false, NULL, device, filename, !!format, format,
1145 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1146 true, mode, false, 0, false, NULL,
1147 false, 0, false, 0, &err);
1148 hmp_handle_error(mon, &err);
1151 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1153 const char *device = qdict_get_str(qdict, "device");
1154 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1155 const char *format = qdict_get_try_str(qdict, "format");
1156 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1157 enum NewImageMode mode;
1161 /* In the future, if 'snapshot-file' is not specified, the snapshot
1162 will be taken internally. Today it's actually required. */
1163 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1164 hmp_handle_error(mon, &err);
1168 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1169 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1170 filename, false, NULL,
1173 hmp_handle_error(mon, &err);
1176 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1178 const char *device = qdict_get_str(qdict, "device");
1179 const char *name = qdict_get_str(qdict, "name");
1182 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1183 hmp_handle_error(mon, &err);
1186 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1188 const char *device = qdict_get_str(qdict, "device");
1189 const char *name = qdict_get_str(qdict, "name");
1190 const char *id = qdict_get_try_str(qdict, "id");
1193 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1195 hmp_handle_error(mon, &err);
1198 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1200 qmp_migrate_cancel(NULL);
1203 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1206 const char *uri = qdict_get_str(qdict, "uri");
1208 qmp_migrate_incoming(uri, &err);
1210 hmp_handle_error(mon, &err);
1213 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1215 double value = qdict_get_double(qdict, "value");
1216 qmp_migrate_set_downtime(value, NULL);
1219 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1221 int64_t value = qdict_get_int(qdict, "value");
1224 qmp_migrate_set_cache_size(value, &err);
1226 error_report_err(err);
1231 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1233 int64_t value = qdict_get_int(qdict, "value");
1234 qmp_migrate_set_speed(value, NULL);
1237 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1239 const char *cap = qdict_get_str(qdict, "capability");
1240 bool state = qdict_get_bool(qdict, "state");
1242 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1245 for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
1246 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1247 caps->value = g_malloc0(sizeof(*caps->value));
1248 caps->value->capability = i;
1249 caps->value->state = state;
1251 qmp_migrate_set_capabilities(caps, &err);
1256 if (i == MIGRATION_CAPABILITY__MAX) {
1257 error_setg(&err, QERR_INVALID_PARAMETER, cap);
1260 qapi_free_MigrationCapabilityStatusList(caps);
1263 error_report_err(err);
1267 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1269 const char *param = qdict_get_str(qdict, "parameter");
1270 const char *valuestr = qdict_get_str(qdict, "value");
1273 bool has_compress_level = false;
1274 bool has_compress_threads = false;
1275 bool has_decompress_threads = false;
1276 bool has_cpu_throttle_initial = false;
1277 bool has_cpu_throttle_increment = false;
1278 bool has_tls_creds = false;
1279 bool has_tls_hostname = false;
1280 bool use_int_value = false;
1283 for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
1284 if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
1286 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1287 has_compress_level = true;
1288 use_int_value = true;
1290 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1291 has_compress_threads = true;
1292 use_int_value = true;
1294 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1295 has_decompress_threads = true;
1296 use_int_value = true;
1298 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1299 has_cpu_throttle_initial = true;
1300 use_int_value = true;
1302 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1303 has_cpu_throttle_increment = true;
1305 case MIGRATION_PARAMETER_TLS_CREDS:
1306 has_tls_creds = true;
1308 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1309 has_tls_hostname = true;
1313 if (use_int_value) {
1314 if (qemu_strtol(valuestr, NULL, 10, &valueint) < 0) {
1315 error_setg(&err, "Unable to parse '%s' as an int",
1321 qmp_migrate_set_parameters(has_compress_level, valueint,
1322 has_compress_threads, valueint,
1323 has_decompress_threads, valueint,
1324 has_cpu_throttle_initial, valueint,
1325 has_cpu_throttle_increment, valueint,
1326 has_tls_creds, valuestr,
1327 has_tls_hostname, valuestr,
1333 if (i == MIGRATION_PARAMETER__MAX) {
1334 error_setg(&err, QERR_INVALID_PARAMETER, param);
1339 error_report_err(err);
1343 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1346 const char *protocol = qdict_get_str(qdict, "protocol");
1347 const char *hostname = qdict_get_str(qdict, "hostname");
1348 bool has_port = qdict_haskey(qdict, "port");
1349 int port = qdict_get_try_int(qdict, "port", -1);
1350 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1351 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1352 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1354 qmp_client_migrate_info(protocol, hostname,
1355 has_port, port, has_tls_port, tls_port,
1356 !!cert_subject, cert_subject, &err);
1357 hmp_handle_error(mon, &err);
1360 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1363 qmp_migrate_start_postcopy(&err);
1364 hmp_handle_error(mon, &err);
1367 void hmp_set_password(Monitor *mon, const QDict *qdict)
1369 const char *protocol = qdict_get_str(qdict, "protocol");
1370 const char *password = qdict_get_str(qdict, "password");
1371 const char *connected = qdict_get_try_str(qdict, "connected");
1374 qmp_set_password(protocol, password, !!connected, connected, &err);
1375 hmp_handle_error(mon, &err);
1378 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1380 const char *protocol = qdict_get_str(qdict, "protocol");
1381 const char *whenstr = qdict_get_str(qdict, "time");
1384 qmp_expire_password(protocol, whenstr, &err);
1385 hmp_handle_error(mon, &err);
1388 void hmp_eject(Monitor *mon, const QDict *qdict)
1390 bool force = qdict_get_try_bool(qdict, "force", false);
1391 const char *device = qdict_get_str(qdict, "device");
1394 qmp_eject(device, true, force, &err);
1395 hmp_handle_error(mon, &err);
1398 static void hmp_change_read_arg(void *opaque, const char *password,
1399 void *readline_opaque)
1401 qmp_change_vnc_password(password, NULL);
1402 monitor_read_command(opaque, 1);
1405 void hmp_change(Monitor *mon, const QDict *qdict)
1407 const char *device = qdict_get_str(qdict, "device");
1408 const char *target = qdict_get_str(qdict, "target");
1409 const char *arg = qdict_get_try_str(qdict, "arg");
1410 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1411 BlockdevChangeReadOnlyMode read_only_mode = 0;
1414 if (strcmp(device, "vnc") == 0) {
1417 "Parameter 'read-only-mode' is invalid for VNC\n");
1420 if (strcmp(target, "passwd") == 0 ||
1421 strcmp(target, "password") == 0) {
1423 monitor_read_password(mon, hmp_change_read_arg, NULL);
1427 qmp_change("vnc", target, !!arg, arg, &err);
1431 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup,
1432 read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX,
1433 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1435 hmp_handle_error(mon, &err);
1440 qmp_blockdev_change_medium(device, target, !!arg, arg,
1441 !!read_only, read_only_mode, &err);
1443 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
1445 monitor_read_block_device_key(mon, device, NULL, NULL);
1450 hmp_handle_error(mon, &err);
1453 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1456 BlockIOThrottle throttle = {
1457 .device = (char *) qdict_get_str(qdict, "device"),
1458 .bps = qdict_get_int(qdict, "bps"),
1459 .bps_rd = qdict_get_int(qdict, "bps_rd"),
1460 .bps_wr = qdict_get_int(qdict, "bps_wr"),
1461 .iops = qdict_get_int(qdict, "iops"),
1462 .iops_rd = qdict_get_int(qdict, "iops_rd"),
1463 .iops_wr = qdict_get_int(qdict, "iops_wr"),
1466 qmp_block_set_io_throttle(&throttle, &err);
1467 hmp_handle_error(mon, &err);
1470 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1472 Error *error = NULL;
1473 const char *device = qdict_get_str(qdict, "device");
1474 const char *base = qdict_get_try_str(qdict, "base");
1475 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1477 qmp_block_stream(false, NULL, device, base != NULL, base, false, NULL,
1478 qdict_haskey(qdict, "speed"), speed,
1479 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1481 hmp_handle_error(mon, &error);
1484 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1486 Error *error = NULL;
1487 const char *device = qdict_get_str(qdict, "device");
1488 int64_t value = qdict_get_int(qdict, "speed");
1490 qmp_block_job_set_speed(device, value, &error);
1492 hmp_handle_error(mon, &error);
1495 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1497 Error *error = NULL;
1498 const char *device = qdict_get_str(qdict, "device");
1499 bool force = qdict_get_try_bool(qdict, "force", false);
1501 qmp_block_job_cancel(device, true, force, &error);
1503 hmp_handle_error(mon, &error);
1506 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1508 Error *error = NULL;
1509 const char *device = qdict_get_str(qdict, "device");
1511 qmp_block_job_pause(device, &error);
1513 hmp_handle_error(mon, &error);
1516 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1518 Error *error = NULL;
1519 const char *device = qdict_get_str(qdict, "device");
1521 qmp_block_job_resume(device, &error);
1523 hmp_handle_error(mon, &error);
1526 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1528 Error *error = NULL;
1529 const char *device = qdict_get_str(qdict, "device");
1531 qmp_block_job_complete(device, &error);
1533 hmp_handle_error(mon, &error);
1536 typedef struct HMPMigrationStatus
1540 bool is_block_migration;
1541 } HMPMigrationStatus;
1543 static void hmp_migrate_status_cb(void *opaque)
1545 HMPMigrationStatus *status = opaque;
1546 MigrationInfo *info;
1548 info = qmp_query_migrate(NULL);
1549 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1550 info->status == MIGRATION_STATUS_SETUP) {
1551 if (info->has_disk) {
1554 if (info->disk->remaining) {
1555 progress = info->disk->transferred * 100 / info->disk->total;
1560 monitor_printf(status->mon, "Completed %d %%\r", progress);
1561 monitor_flush(status->mon);
1564 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1566 if (status->is_block_migration) {
1567 monitor_printf(status->mon, "\n");
1569 if (info->has_error_desc) {
1570 error_report("%s", info->error_desc);
1572 monitor_resume(status->mon);
1573 timer_del(status->timer);
1577 qapi_free_MigrationInfo(info);
1580 void hmp_migrate(Monitor *mon, const QDict *qdict)
1582 bool detach = qdict_get_try_bool(qdict, "detach", false);
1583 bool blk = qdict_get_try_bool(qdict, "blk", false);
1584 bool inc = qdict_get_try_bool(qdict, "inc", false);
1585 const char *uri = qdict_get_str(qdict, "uri");
1588 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1590 error_report_err(err);
1595 HMPMigrationStatus *status;
1597 if (monitor_suspend(mon) < 0) {
1598 monitor_printf(mon, "terminal does not allow synchronous "
1599 "migration, continuing detached\n");
1603 status = g_malloc0(sizeof(*status));
1605 status->is_block_migration = blk || inc;
1606 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1608 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1612 void hmp_device_add(Monitor *mon, const QDict *qdict)
1616 qmp_device_add((QDict *)qdict, NULL, &err);
1617 hmp_handle_error(mon, &err);
1620 void hmp_device_del(Monitor *mon, const QDict *qdict)
1622 const char *id = qdict_get_str(qdict, "id");
1625 qmp_device_del(id, &err);
1626 hmp_handle_error(mon, &err);
1629 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1632 bool paging = qdict_get_try_bool(qdict, "paging", false);
1633 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
1634 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
1635 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
1636 const char *file = qdict_get_str(qdict, "filename");
1637 bool has_begin = qdict_haskey(qdict, "begin");
1638 bool has_length = qdict_haskey(qdict, "length");
1639 bool has_detach = qdict_haskey(qdict, "detach");
1642 bool detach = false;
1643 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1646 if (zlib + lzo + snappy > 1) {
1647 error_setg(&err, "only one of '-z|-l|-s' can be set");
1648 hmp_handle_error(mon, &err);
1653 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1657 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1661 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1665 begin = qdict_get_int(qdict, "begin");
1668 length = qdict_get_int(qdict, "length");
1671 detach = qdict_get_bool(qdict, "detach");
1674 prot = g_strconcat("file:", file, NULL);
1676 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
1677 has_length, length, true, dump_format, &err);
1678 hmp_handle_error(mon, &err);
1682 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1687 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1692 netdev_add(opts, &err);
1694 qemu_opts_del(opts);
1698 hmp_handle_error(mon, &err);
1701 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1703 const char *id = qdict_get_str(qdict, "id");
1706 qmp_netdev_del(id, &err);
1707 hmp_handle_error(mon, &err);
1710 void hmp_object_add(Monitor *mon, const QDict *qdict)
1717 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1719 hmp_handle_error(mon, &err);
1723 v = opts_visitor_new(opts);
1724 obj = user_creatable_add(qdict, v, &err);
1726 qemu_opts_del(opts);
1729 hmp_handle_error(mon, &err);
1736 void hmp_getfd(Monitor *mon, const QDict *qdict)
1738 const char *fdname = qdict_get_str(qdict, "fdname");
1741 qmp_getfd(fdname, &err);
1742 hmp_handle_error(mon, &err);
1745 void hmp_closefd(Monitor *mon, const QDict *qdict)
1747 const char *fdname = qdict_get_str(qdict, "fdname");
1750 qmp_closefd(fdname, &err);
1751 hmp_handle_error(mon, &err);
1754 void hmp_sendkey(Monitor *mon, const QDict *qdict)
1756 const char *keys = qdict_get_str(qdict, "keys");
1757 KeyValueList *keylist, *head = NULL, *tmp = NULL;
1758 int has_hold_time = qdict_haskey(qdict, "hold-time");
1759 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1765 separator = strchr(keys, '-');
1766 keyname_len = separator ? separator - keys : strlen(keys);
1768 /* Be compatible with old interface, convert user inputted "<" */
1769 if (keys[0] == '<' && keyname_len == 1) {
1774 keylist = g_malloc0(sizeof(*keylist));
1775 keylist->value = g_malloc0(sizeof(*keylist->value));
1781 tmp->next = keylist;
1785 if (strstart(keys, "0x", NULL)) {
1787 int value = strtoul(keys, &endp, 0);
1788 assert(endp <= keys + keyname_len);
1789 if (endp != keys + keyname_len) {
1792 keylist->value->type = KEY_VALUE_KIND_NUMBER;
1793 keylist->value->u.number.data = value;
1795 int idx = index_from_key(keys, keyname_len);
1796 if (idx == Q_KEY_CODE__MAX) {
1799 keylist->value->type = KEY_VALUE_KIND_QCODE;
1800 keylist->value->u.qcode.data = idx;
1806 keys = separator + 1;
1809 qmp_send_key(head, has_hold_time, hold_time, &err);
1810 hmp_handle_error(mon, &err);
1813 qapi_free_KeyValueList(head);
1817 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
1821 void hmp_screendump(Monitor *mon, const QDict *qdict)
1823 const char *filename = qdict_get_str(qdict, "filename");
1826 qmp_screendump(filename, &err);
1827 hmp_handle_error(mon, &err);
1830 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1832 const char *uri = qdict_get_str(qdict, "uri");
1833 bool writable = qdict_get_try_bool(qdict, "writable", false);
1834 bool all = qdict_get_try_bool(qdict, "all", false);
1835 Error *local_err = NULL;
1836 BlockInfoList *block_list, *info;
1837 SocketAddress *addr;
1839 if (writable && !all) {
1840 error_setg(&local_err, "-w only valid together with -a");
1844 /* First check if the address is valid and start the server. */
1845 addr = socket_parse(uri, &local_err);
1846 if (local_err != NULL) {
1850 qmp_nbd_server_start(addr, false, NULL, &local_err);
1851 qapi_free_SocketAddress(addr);
1852 if (local_err != NULL) {
1860 /* Then try adding all block devices. If one fails, close all and
1863 block_list = qmp_query_block(NULL);
1865 for (info = block_list; info; info = info->next) {
1866 if (!info->value->has_inserted) {
1870 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1872 if (local_err != NULL) {
1873 qmp_nbd_server_stop(NULL);
1878 qapi_free_BlockInfoList(block_list);
1881 hmp_handle_error(mon, &local_err);
1884 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1886 const char *device = qdict_get_str(qdict, "device");
1887 bool writable = qdict_get_try_bool(qdict, "writable", false);
1888 Error *local_err = NULL;
1890 qmp_nbd_server_add(device, true, writable, &local_err);
1892 if (local_err != NULL) {
1893 hmp_handle_error(mon, &local_err);
1897 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1901 qmp_nbd_server_stop(&err);
1902 hmp_handle_error(mon, &err);
1905 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
1910 cpuid = qdict_get_int(qdict, "id");
1911 qmp_cpu_add(cpuid, &err);
1912 hmp_handle_error(mon, &err);
1915 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1917 const char *args = qdict_get_str(qdict, "args");
1921 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
1923 error_setg(&err, "Parsing chardev args failed");
1925 qemu_chr_new_from_opts(opts, NULL, &err);
1927 hmp_handle_error(mon, &err);
1930 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1932 Error *local_err = NULL;
1934 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1935 hmp_handle_error(mon, &local_err);
1938 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1941 const char* device = qdict_get_str(qdict, "device");
1942 const char* command = qdict_get_str(qdict, "command");
1945 blk = blk_by_name(device);
1947 AioContext *aio_context = blk_get_aio_context(blk);
1948 aio_context_acquire(aio_context);
1950 qemuio_command(blk, command);
1952 aio_context_release(aio_context);
1954 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
1955 "Device '%s' not found", device);
1958 hmp_handle_error(mon, &err);
1961 void hmp_object_del(Monitor *mon, const QDict *qdict)
1963 const char *id = qdict_get_str(qdict, "id");
1966 user_creatable_del(id, &err);
1967 hmp_handle_error(mon, &err);
1970 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
1973 MemdevList *memdev_list = qmp_query_memdev(&err);
1974 MemdevList *m = memdev_list;
1981 v = string_output_visitor_new(false, &str);
1982 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
1983 monitor_printf(mon, "memory backend: %d\n", i);
1984 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
1985 monitor_printf(mon, " merge: %s\n",
1986 m->value->merge ? "true" : "false");
1987 monitor_printf(mon, " dump: %s\n",
1988 m->value->dump ? "true" : "false");
1989 monitor_printf(mon, " prealloc: %s\n",
1990 m->value->prealloc ? "true" : "false");
1991 monitor_printf(mon, " policy: %s\n",
1992 HostMemPolicy_lookup[m->value->policy]);
1993 visit_complete(v, &str);
1994 monitor_printf(mon, " host nodes: %s\n", str);
2002 monitor_printf(mon, "\n");
2004 qapi_free_MemdevList(memdev_list);
2007 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2010 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2011 MemoryDeviceInfoList *info;
2012 MemoryDeviceInfo *value;
2013 PCDIMMDeviceInfo *di;
2015 for (info = info_list; info; info = info->next) {
2016 value = info->value;
2019 switch (value->type) {
2020 case MEMORY_DEVICE_INFO_KIND_DIMM:
2021 di = value->u.dimm.data;
2023 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2024 MemoryDeviceInfoKind_lookup[value->type],
2025 di->id ? di->id : "");
2026 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2027 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2028 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2029 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2030 monitor_printf(mon, " memdev: %s\n", di->memdev);
2031 monitor_printf(mon, " hotplugged: %s\n",
2032 di->hotplugged ? "true" : "false");
2033 monitor_printf(mon, " hotpluggable: %s\n",
2034 di->hotpluggable ? "true" : "false");
2042 qapi_free_MemoryDeviceInfoList(info_list);
2045 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2047 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2048 IOThreadInfoList *info;
2050 for (info = info_list; info; info = info->next) {
2051 monitor_printf(mon, "%s: thread_id=%" PRId64 "\n",
2052 info->value->id, info->value->thread_id);
2055 qapi_free_IOThreadInfoList(info_list);
2058 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2060 const char *path = qdict_get_try_str(qdict, "path");
2061 ObjectPropertyInfoList *list;
2065 monitor_printf(mon, "/\n");
2069 list = qmp_qom_list(path, &err);
2071 ObjectPropertyInfoList *start = list;
2072 while (list != NULL) {
2073 ObjectPropertyInfo *value = list->value;
2075 monitor_printf(mon, "%s (%s)\n",
2076 value->name, value->type);
2079 qapi_free_ObjectPropertyInfoList(start);
2081 hmp_handle_error(mon, &err);
2084 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2086 const char *path = qdict_get_str(qdict, "path");
2087 const char *property = qdict_get_str(qdict, "property");
2088 const char *value = qdict_get_str(qdict, "value");
2090 bool ambiguous = false;
2093 obj = object_resolve_path(path, &ambiguous);
2095 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2096 "Device '%s' not found", path);
2099 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2101 object_property_parse(obj, value, property, &err);
2103 hmp_handle_error(mon, &err);
2106 void hmp_rocker(Monitor *mon, const QDict *qdict)
2108 const char *name = qdict_get_str(qdict, "name");
2109 RockerSwitch *rocker;
2112 rocker = qmp_query_rocker(name, &err);
2114 hmp_handle_error(mon, &err);
2118 monitor_printf(mon, "name: %s\n", rocker->name);
2119 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2120 monitor_printf(mon, "ports: %d\n", rocker->ports);
2122 qapi_free_RockerSwitch(rocker);
2125 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2127 RockerPortList *list, *port;
2128 const char *name = qdict_get_str(qdict, "name");
2131 list = qmp_query_rocker_ports(name, &err);
2133 hmp_handle_error(mon, &err);
2137 monitor_printf(mon, " ena/ speed/ auto\n");
2138 monitor_printf(mon, " port link duplex neg?\n");
2140 for (port = list; port; port = port->next) {
2141 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2143 port->value->enabled ? port->value->link_up ?
2144 "up" : "down" : "!ena",
2145 port->value->speed == 10000 ? "10G" : "??",
2146 port->value->duplex ? "FD" : "HD",
2147 port->value->autoneg ? "Yes" : "No");
2150 qapi_free_RockerPortList(list);
2153 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2155 RockerOfDpaFlowList *list, *info;
2156 const char *name = qdict_get_str(qdict, "name");
2157 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2160 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2162 hmp_handle_error(mon, &err);
2166 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2168 for (info = list; info; info = info->next) {
2169 RockerOfDpaFlow *flow = info->value;
2170 RockerOfDpaFlowKey *key = flow->key;
2171 RockerOfDpaFlowMask *mask = flow->mask;
2172 RockerOfDpaFlowAction *action = flow->action;
2175 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2176 key->priority, key->tbl_id, flow->hits);
2178 monitor_printf(mon, "%-4d %-3d ",
2179 key->priority, key->tbl_id);
2182 if (key->has_in_pport) {
2183 monitor_printf(mon, " pport %d", key->in_pport);
2184 if (mask->has_in_pport) {
2185 monitor_printf(mon, "(0x%x)", mask->in_pport);
2189 if (key->has_vlan_id) {
2190 monitor_printf(mon, " vlan %d",
2191 key->vlan_id & VLAN_VID_MASK);
2192 if (mask->has_vlan_id) {
2193 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2197 if (key->has_tunnel_id) {
2198 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2199 if (mask->has_tunnel_id) {
2200 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2204 if (key->has_eth_type) {
2205 switch (key->eth_type) {
2207 monitor_printf(mon, " ARP");
2210 monitor_printf(mon, " IP");
2213 monitor_printf(mon, " IPv6");
2216 monitor_printf(mon, " LACP");
2219 monitor_printf(mon, " LLDP");
2222 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2227 if (key->has_eth_src) {
2228 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2229 (mask->has_eth_src) &&
2230 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2231 monitor_printf(mon, " src <any mcast/bcast>");
2232 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2233 (mask->has_eth_src) &&
2234 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2235 monitor_printf(mon, " src <any ucast>");
2237 monitor_printf(mon, " src %s", key->eth_src);
2238 if (mask->has_eth_src) {
2239 monitor_printf(mon, "(%s)", mask->eth_src);
2244 if (key->has_eth_dst) {
2245 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2246 (mask->has_eth_dst) &&
2247 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2248 monitor_printf(mon, " dst <any mcast/bcast>");
2249 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2250 (mask->has_eth_dst) &&
2251 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2252 monitor_printf(mon, " dst <any ucast>");
2254 monitor_printf(mon, " dst %s", key->eth_dst);
2255 if (mask->has_eth_dst) {
2256 monitor_printf(mon, "(%s)", mask->eth_dst);
2261 if (key->has_ip_proto) {
2262 monitor_printf(mon, " proto %d", key->ip_proto);
2263 if (mask->has_ip_proto) {
2264 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2268 if (key->has_ip_tos) {
2269 monitor_printf(mon, " TOS %d", key->ip_tos);
2270 if (mask->has_ip_tos) {
2271 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2275 if (key->has_ip_dst) {
2276 monitor_printf(mon, " dst %s", key->ip_dst);
2279 if (action->has_goto_tbl || action->has_group_id ||
2280 action->has_new_vlan_id) {
2281 monitor_printf(mon, " -->");
2284 if (action->has_new_vlan_id) {
2285 monitor_printf(mon, " apply new vlan %d",
2286 ntohs(action->new_vlan_id));
2289 if (action->has_group_id) {
2290 monitor_printf(mon, " write group 0x%08x", action->group_id);
2293 if (action->has_goto_tbl) {
2294 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2297 monitor_printf(mon, "\n");
2300 qapi_free_RockerOfDpaFlowList(list);
2303 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2305 RockerOfDpaGroupList *list, *g;
2306 const char *name = qdict_get_str(qdict, "name");
2307 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2311 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2313 hmp_handle_error(mon, &err);
2317 monitor_printf(mon, "id (decode) --> buckets\n");
2319 for (g = list; g; g = g->next) {
2320 RockerOfDpaGroup *group = g->value;
2322 monitor_printf(mon, "0x%08x", group->id);
2324 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2325 group->type == 1 ? "L2 rewrite" :
2326 group->type == 2 ? "L3 unicast" :
2327 group->type == 3 ? "L2 multicast" :
2328 group->type == 4 ? "L2 flood" :
2329 group->type == 5 ? "L3 interface" :
2330 group->type == 6 ? "L3 multicast" :
2331 group->type == 7 ? "L3 ECMP" :
2332 group->type == 8 ? "L2 overlay" :
2335 if (group->has_vlan_id) {
2336 monitor_printf(mon, " vlan %d", group->vlan_id);
2339 if (group->has_pport) {
2340 monitor_printf(mon, " pport %d", group->pport);
2343 if (group->has_index) {
2344 monitor_printf(mon, " index %d", group->index);
2347 monitor_printf(mon, ") -->");
2349 if (group->has_set_vlan_id && group->set_vlan_id) {
2351 monitor_printf(mon, " set vlan %d",
2352 group->set_vlan_id & VLAN_VID_MASK);
2355 if (group->has_set_eth_src) {
2358 monitor_printf(mon, " set");
2360 monitor_printf(mon, " src %s", group->set_eth_src);
2363 if (group->has_set_eth_dst) {
2366 monitor_printf(mon, " set");
2368 monitor_printf(mon, " dst %s", group->set_eth_dst);
2373 if (group->has_ttl_check && group->ttl_check) {
2374 monitor_printf(mon, " check TTL");
2377 if (group->has_group_id && group->group_id) {
2378 monitor_printf(mon, " group id 0x%08x", group->group_id);
2381 if (group->has_pop_vlan && group->pop_vlan) {
2382 monitor_printf(mon, " pop vlan");
2385 if (group->has_out_pport) {
2386 monitor_printf(mon, " out pport %d", group->out_pport);
2389 if (group->has_group_ids) {
2390 struct uint32List *id;
2392 monitor_printf(mon, " groups [");
2393 for (id = group->group_ids; id; id = id->next) {
2394 monitor_printf(mon, "0x%08x", id->value);
2396 monitor_printf(mon, ",");
2399 monitor_printf(mon, "]");
2402 monitor_printf(mon, "\n");
2405 qapi_free_RockerOfDpaGroupList(list);
2408 void hmp_info_dump(Monitor *mon, const QDict *qdict)
2410 DumpQueryResult *result = qmp_query_dump(NULL);
2412 assert(result && result->status < DUMP_STATUS__MAX);
2413 monitor_printf(mon, "Status: %s\n", DumpStatus_lookup[result->status]);
2415 if (result->status == DUMP_STATUS_ACTIVE) {
2417 assert(result->total != 0);
2418 percent = 100.0 * result->completed / result->total;
2419 monitor_printf(mon, "Finished: %.2f %%\n", percent);
2422 qapi_free_DumpQueryResult(result);
2425 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
2428 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
2429 HotpluggableCPUList *saved = l;
2430 CpuInstanceProperties *c;
2433 hmp_handle_error(mon, &err);
2437 monitor_printf(mon, "Hotpluggable CPUs:\n");
2439 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
2440 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
2441 l->value->vcpus_count);
2442 if (l->value->has_qom_path) {
2443 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
2446 c = l->value->props;
2447 monitor_printf(mon, " CPUInstance Properties:\n");
2448 if (c->has_node_id) {
2449 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
2451 if (c->has_socket_id) {
2452 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
2454 if (c->has_core_id) {
2455 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
2457 if (c->has_thread_id) {
2458 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
2464 qapi_free_HotpluggableCPUList(saved);