2 * Human Monitor Interface
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 "sysemu/char.h"
21 #include "sysemu/block-backend.h"
22 #include "qemu/config-file.h"
23 #include "qemu/option.h"
24 #include "qemu/timer.h"
25 #include "qmp-commands.h"
26 #include "qemu/sockets.h"
27 #include "monitor/monitor.h"
28 #include "monitor/qdev.h"
29 #include "qapi/opts-visitor.h"
30 #include "qapi/qmp/qerror.h"
31 #include "qapi/string-output-visitor.h"
32 #include "qapi/util.h"
33 #include "qapi-visit.h"
34 #include "qom/object_interfaces.h"
35 #include "ui/console.h"
36 #include "block/qapi.h"
38 #include "qemu/cutils.h"
39 #include "qemu/error-report.h"
40 #include "hw/intc/intc.h"
43 #include <spice/enums.h>
46 static void hmp_handle_error(Monitor *mon, Error **errp)
50 error_report_err(*errp);
54 void hmp_info_name(Monitor *mon, const QDict *qdict)
58 info = qmp_query_name(NULL);
60 monitor_printf(mon, "%s\n", info->name);
62 qapi_free_NameInfo(info);
65 void hmp_info_version(Monitor *mon, const QDict *qdict)
69 info = qmp_query_version(NULL);
71 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
72 info->qemu->major, info->qemu->minor, info->qemu->micro,
75 qapi_free_VersionInfo(info);
78 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
82 info = qmp_query_kvm(NULL);
83 monitor_printf(mon, "kvm support: ");
85 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
87 monitor_printf(mon, "not compiled\n");
90 qapi_free_KvmInfo(info);
93 void hmp_info_status(Monitor *mon, const QDict *qdict)
97 info = qmp_query_status(NULL);
99 monitor_printf(mon, "VM status: %s%s",
100 info->running ? "running" : "paused",
101 info->singlestep ? " (single step mode)" : "");
103 if (!info->running && info->status != RUN_STATE_PAUSED) {
104 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
107 monitor_printf(mon, "\n");
109 qapi_free_StatusInfo(info);
112 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
116 info = qmp_query_uuid(NULL);
117 monitor_printf(mon, "%s\n", info->UUID);
118 qapi_free_UuidInfo(info);
121 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
123 ChardevInfoList *char_info, *info;
125 char_info = qmp_query_chardev(NULL);
126 for (info = char_info; info; info = info->next) {
127 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
128 info->value->filename);
131 qapi_free_ChardevInfoList(char_info);
134 void hmp_info_mice(Monitor *mon, const QDict *qdict)
136 MouseInfoList *mice_list, *mouse;
138 mice_list = qmp_query_mice(NULL);
140 monitor_printf(mon, "No mouse devices connected\n");
144 for (mouse = mice_list; mouse; mouse = mouse->next) {
145 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
146 mouse->value->current ? '*' : ' ',
147 mouse->value->index, mouse->value->name,
148 mouse->value->absolute ? " (absolute)" : "");
151 qapi_free_MouseInfoList(mice_list);
154 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
157 MigrationCapabilityStatusList *caps, *cap;
159 info = qmp_query_migrate(NULL);
160 caps = qmp_query_migrate_capabilities(NULL);
162 /* do not display parameters during setup */
163 if (info->has_status && caps) {
164 monitor_printf(mon, "capabilities: ");
165 for (cap = caps; cap; cap = cap->next) {
166 monitor_printf(mon, "%s: %s ",
167 MigrationCapability_lookup[cap->value->capability],
168 cap->value->state ? "on" : "off");
170 monitor_printf(mon, "\n");
173 if (info->has_status) {
174 monitor_printf(mon, "Migration status: %s",
175 MigrationStatus_lookup[info->status]);
176 if (info->status == MIGRATION_STATUS_FAILED &&
177 info->has_error_desc) {
178 monitor_printf(mon, " (%s)\n", info->error_desc);
180 monitor_printf(mon, "\n");
183 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
185 if (info->has_expected_downtime) {
186 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
187 info->expected_downtime);
189 if (info->has_downtime) {
190 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
193 if (info->has_setup_time) {
194 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
200 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
201 info->ram->transferred >> 10);
202 monitor_printf(mon, "throughput: %0.2f mbps\n",
204 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
205 info->ram->remaining >> 10);
206 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
207 info->ram->total >> 10);
208 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
209 info->ram->duplicate);
210 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
212 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
214 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
215 info->ram->normal_bytes >> 10);
216 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
217 info->ram->dirty_sync_count);
218 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
219 info->ram->page_size >> 10);
221 if (info->ram->dirty_pages_rate) {
222 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
223 info->ram->dirty_pages_rate);
225 if (info->ram->postcopy_requests) {
226 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
227 info->ram->postcopy_requests);
231 if (info->has_disk) {
232 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
233 info->disk->transferred >> 10);
234 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
235 info->disk->remaining >> 10);
236 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
237 info->disk->total >> 10);
240 if (info->has_xbzrle_cache) {
241 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
242 info->xbzrle_cache->cache_size);
243 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
244 info->xbzrle_cache->bytes >> 10);
245 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
246 info->xbzrle_cache->pages);
247 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
248 info->xbzrle_cache->cache_miss);
249 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
250 info->xbzrle_cache->cache_miss_rate);
251 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
252 info->xbzrle_cache->overflow);
255 if (info->has_cpu_throttle_percentage) {
256 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
257 info->cpu_throttle_percentage);
260 qapi_free_MigrationInfo(info);
261 qapi_free_MigrationCapabilityStatusList(caps);
264 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
266 MigrationCapabilityStatusList *caps, *cap;
268 caps = qmp_query_migrate_capabilities(NULL);
271 for (cap = caps; cap; cap = cap->next) {
272 monitor_printf(mon, "%s: %s\n",
273 MigrationCapability_lookup[cap->value->capability],
274 cap->value->state ? "on" : "off");
278 qapi_free_MigrationCapabilityStatusList(caps);
281 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
283 MigrationParameters *params;
285 params = qmp_query_migrate_parameters(NULL);
288 monitor_printf(mon, "parameters:");
289 assert(params->has_compress_level);
290 monitor_printf(mon, " %s: %" PRId64,
291 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_LEVEL],
292 params->compress_level);
293 assert(params->has_compress_threads);
294 monitor_printf(mon, " %s: %" PRId64,
295 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_THREADS],
296 params->compress_threads);
297 assert(params->has_decompress_threads);
298 monitor_printf(mon, " %s: %" PRId64,
299 MigrationParameter_lookup[MIGRATION_PARAMETER_DECOMPRESS_THREADS],
300 params->decompress_threads);
301 assert(params->has_cpu_throttle_initial);
302 monitor_printf(mon, " %s: %" PRId64,
303 MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL],
304 params->cpu_throttle_initial);
305 assert(params->has_cpu_throttle_increment);
306 monitor_printf(mon, " %s: %" PRId64,
307 MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT],
308 params->cpu_throttle_increment);
309 monitor_printf(mon, " %s: '%s'",
310 MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_CREDS],
311 params->has_tls_creds ? params->tls_creds : "");
312 monitor_printf(mon, " %s: '%s'",
313 MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_HOSTNAME],
314 params->has_tls_hostname ? params->tls_hostname : "");
315 assert(params->has_max_bandwidth);
316 monitor_printf(mon, " %s: %" PRId64 " bytes/second",
317 MigrationParameter_lookup[MIGRATION_PARAMETER_MAX_BANDWIDTH],
318 params->max_bandwidth);
319 assert(params->has_downtime_limit);
320 monitor_printf(mon, " %s: %" PRId64 " milliseconds",
321 MigrationParameter_lookup[MIGRATION_PARAMETER_DOWNTIME_LIMIT],
322 params->downtime_limit);
323 assert(params->has_x_checkpoint_delay);
324 monitor_printf(mon, " %s: %" PRId64,
325 MigrationParameter_lookup[MIGRATION_PARAMETER_X_CHECKPOINT_DELAY],
326 params->x_checkpoint_delay);
327 monitor_printf(mon, "\n");
330 qapi_free_MigrationParameters(params);
333 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
335 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
336 qmp_query_migrate_cache_size(NULL) >> 10);
339 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
341 CpuInfoList *cpu_list, *cpu;
343 cpu_list = qmp_query_cpus(NULL);
345 for (cpu = cpu_list; cpu; cpu = cpu->next) {
348 if (cpu->value->CPU == monitor_get_cpu_index()) {
352 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
354 switch (cpu->value->arch) {
355 case CPU_INFO_ARCH_X86:
356 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->u.x86.pc);
358 case CPU_INFO_ARCH_PPC:
359 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->u.ppc.nip);
361 case CPU_INFO_ARCH_SPARC:
362 monitor_printf(mon, " pc=0x%016" PRIx64,
363 cpu->value->u.q_sparc.pc);
364 monitor_printf(mon, " npc=0x%016" PRIx64,
365 cpu->value->u.q_sparc.npc);
367 case CPU_INFO_ARCH_MIPS:
368 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.q_mips.PC);
370 case CPU_INFO_ARCH_TRICORE:
371 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.tricore.PC);
377 if (cpu->value->halted) {
378 monitor_printf(mon, " (halted)");
381 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
384 qapi_free_CpuInfoList(cpu_list);
387 static void print_block_info(Monitor *mon, BlockInfo *info,
388 BlockDeviceInfo *inserted, bool verbose)
390 ImageInfo *image_info;
392 assert(!info || !info->has_inserted || info->inserted == inserted);
395 monitor_printf(mon, "%s", info->device);
396 if (inserted && inserted->has_node_name) {
397 monitor_printf(mon, " (%s)", inserted->node_name);
401 monitor_printf(mon, "%s",
402 inserted->has_node_name
403 ? inserted->node_name
408 monitor_printf(mon, ": %s (%s%s%s)\n",
411 inserted->ro ? ", read-only" : "",
412 inserted->encrypted ? ", encrypted" : "");
414 monitor_printf(mon, ": [not inserted]\n");
418 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
419 monitor_printf(mon, " I/O status: %s\n",
420 BlockDeviceIoStatus_lookup[info->io_status]);
423 if (info->removable) {
424 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
425 info->locked ? "" : "not ",
426 info->tray_open ? "open" : "closed");
435 monitor_printf(mon, " Cache mode: %s%s%s\n",
436 inserted->cache->writeback ? "writeback" : "writethrough",
437 inserted->cache->direct ? ", direct" : "",
438 inserted->cache->no_flush ? ", ignore flushes" : "");
440 if (inserted->has_backing_file) {
443 "(chain depth: %" PRId64 ")\n",
444 inserted->backing_file,
445 inserted->backing_file_depth);
448 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
449 monitor_printf(mon, " Detect zeroes: %s\n",
450 BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]);
453 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
454 inserted->iops || inserted->iops_rd || inserted->iops_wr)
456 monitor_printf(mon, " I/O throttling: bps=%" PRId64
457 " bps_rd=%" PRId64 " bps_wr=%" PRId64
459 " bps_rd_max=%" PRId64
460 " bps_wr_max=%" PRId64
461 " iops=%" PRId64 " iops_rd=%" PRId64
464 " iops_rd_max=%" PRId64
465 " iops_wr_max=%" PRId64
466 " iops_size=%" PRId64
472 inserted->bps_rd_max,
473 inserted->bps_wr_max,
478 inserted->iops_rd_max,
479 inserted->iops_wr_max,
485 monitor_printf(mon, "\nImages:\n");
486 image_info = inserted->image;
488 bdrv_image_info_dump((fprintf_function)monitor_printf,
490 if (image_info->has_backing_image) {
491 image_info = image_info->backing_image;
499 void hmp_info_block(Monitor *mon, const QDict *qdict)
501 BlockInfoList *block_list, *info;
502 BlockDeviceInfoList *blockdev_list, *blockdev;
503 const char *device = qdict_get_try_str(qdict, "device");
504 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
505 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
506 bool printed = false;
508 /* Print BlockBackend information */
510 block_list = qmp_query_block(NULL);
515 for (info = block_list; info; info = info->next) {
516 if (device && strcmp(device, info->value->device)) {
520 if (info != block_list) {
521 monitor_printf(mon, "\n");
524 print_block_info(mon, info->value, info->value->has_inserted
525 ? info->value->inserted : NULL,
530 qapi_free_BlockInfoList(block_list);
532 if ((!device && !nodes) || printed) {
536 /* Print node information */
537 blockdev_list = qmp_query_named_block_nodes(NULL);
538 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
539 assert(blockdev->value->has_node_name);
540 if (device && strcmp(device, blockdev->value->node_name)) {
544 if (blockdev != blockdev_list) {
545 monitor_printf(mon, "\n");
548 print_block_info(mon, NULL, blockdev->value, verbose);
550 qapi_free_BlockDeviceInfoList(blockdev_list);
553 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
555 BlockStatsList *stats_list, *stats;
557 stats_list = qmp_query_blockstats(false, false, NULL);
559 for (stats = stats_list; stats; stats = stats->next) {
560 if (!stats->value->has_device) {
564 monitor_printf(mon, "%s:", stats->value->device);
565 monitor_printf(mon, " rd_bytes=%" PRId64
567 " rd_operations=%" PRId64
568 " wr_operations=%" PRId64
569 " flush_operations=%" PRId64
570 " wr_total_time_ns=%" PRId64
571 " rd_total_time_ns=%" PRId64
572 " flush_total_time_ns=%" PRId64
573 " rd_merged=%" PRId64
574 " wr_merged=%" PRId64
575 " idle_time_ns=%" PRId64
577 stats->value->stats->rd_bytes,
578 stats->value->stats->wr_bytes,
579 stats->value->stats->rd_operations,
580 stats->value->stats->wr_operations,
581 stats->value->stats->flush_operations,
582 stats->value->stats->wr_total_time_ns,
583 stats->value->stats->rd_total_time_ns,
584 stats->value->stats->flush_total_time_ns,
585 stats->value->stats->rd_merged,
586 stats->value->stats->wr_merged,
587 stats->value->stats->idle_time_ns);
590 qapi_free_BlockStatsList(stats_list);
593 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
597 VncClientInfoList *client;
599 info = qmp_query_vnc(&err);
601 error_report_err(err);
605 if (!info->enabled) {
606 monitor_printf(mon, "Server: disabled\n");
610 monitor_printf(mon, "Server:\n");
611 if (info->has_host && info->has_service) {
612 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
614 if (info->has_auth) {
615 monitor_printf(mon, " auth: %s\n", info->auth);
618 if (!info->has_clients || info->clients == NULL) {
619 monitor_printf(mon, "Client: none\n");
621 for (client = info->clients; client; client = client->next) {
622 monitor_printf(mon, "Client:\n");
623 monitor_printf(mon, " address: %s:%s\n",
625 client->value->service);
626 monitor_printf(mon, " x509_dname: %s\n",
627 client->value->x509_dname ?
628 client->value->x509_dname : "none");
629 monitor_printf(mon, " username: %s\n",
630 client->value->has_sasl_username ?
631 client->value->sasl_username : "none");
636 qapi_free_VncInfo(info);
640 void hmp_info_spice(Monitor *mon, const QDict *qdict)
642 SpiceChannelList *chan;
644 const char *channel_name;
645 const char * const channel_names[] = {
646 [SPICE_CHANNEL_MAIN] = "main",
647 [SPICE_CHANNEL_DISPLAY] = "display",
648 [SPICE_CHANNEL_INPUTS] = "inputs",
649 [SPICE_CHANNEL_CURSOR] = "cursor",
650 [SPICE_CHANNEL_PLAYBACK] = "playback",
651 [SPICE_CHANNEL_RECORD] = "record",
652 [SPICE_CHANNEL_TUNNEL] = "tunnel",
653 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
654 [SPICE_CHANNEL_USBREDIR] = "usbredir",
655 [SPICE_CHANNEL_PORT] = "port",
657 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
658 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
659 * as quick fix for build failures with older versions. */
660 [SPICE_CHANNEL_WEBDAV] = "webdav",
664 info = qmp_query_spice(NULL);
666 if (!info->enabled) {
667 monitor_printf(mon, "Server: disabled\n");
671 monitor_printf(mon, "Server:\n");
672 if (info->has_port) {
673 monitor_printf(mon, " address: %s:%" PRId64 "\n",
674 info->host, info->port);
676 if (info->has_tls_port) {
677 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
678 info->host, info->tls_port);
680 monitor_printf(mon, " migrated: %s\n",
681 info->migrated ? "true" : "false");
682 monitor_printf(mon, " auth: %s\n", info->auth);
683 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
684 monitor_printf(mon, " mouse-mode: %s\n",
685 SpiceQueryMouseMode_lookup[info->mouse_mode]);
687 if (!info->has_channels || info->channels == NULL) {
688 monitor_printf(mon, "Channels: none\n");
690 for (chan = info->channels; chan; chan = chan->next) {
691 monitor_printf(mon, "Channel:\n");
692 monitor_printf(mon, " address: %s:%s%s\n",
693 chan->value->host, chan->value->port,
694 chan->value->tls ? " [tls]" : "");
695 monitor_printf(mon, " session: %" PRId64 "\n",
696 chan->value->connection_id);
697 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
698 chan->value->channel_type, chan->value->channel_id);
700 channel_name = "unknown";
701 if (chan->value->channel_type > 0 &&
702 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
703 channel_names[chan->value->channel_type]) {
704 channel_name = channel_names[chan->value->channel_type];
707 monitor_printf(mon, " channel name: %s\n", channel_name);
712 qapi_free_SpiceInfo(info);
716 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
721 info = qmp_query_balloon(&err);
723 error_report_err(err);
727 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
729 qapi_free_BalloonInfo(info);
732 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
734 PciMemoryRegionList *region;
736 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
737 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
738 dev->slot, dev->function);
739 monitor_printf(mon, " ");
741 if (dev->class_info->has_desc) {
742 monitor_printf(mon, "%s", dev->class_info->desc);
744 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
747 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
748 dev->id->vendor, dev->id->device);
751 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
754 if (dev->has_pci_bridge) {
755 monitor_printf(mon, " BUS %" PRId64 ".\n",
756 dev->pci_bridge->bus->number);
757 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
758 dev->pci_bridge->bus->secondary);
759 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
760 dev->pci_bridge->bus->subordinate);
762 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
763 dev->pci_bridge->bus->io_range->base,
764 dev->pci_bridge->bus->io_range->limit);
767 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
768 dev->pci_bridge->bus->memory_range->base,
769 dev->pci_bridge->bus->memory_range->limit);
771 monitor_printf(mon, " prefetchable memory range "
772 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
773 dev->pci_bridge->bus->prefetchable_range->base,
774 dev->pci_bridge->bus->prefetchable_range->limit);
777 for (region = dev->regions; region; region = region->next) {
780 addr = region->value->address;
781 size = region->value->size;
783 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
785 if (!strcmp(region->value->type, "io")) {
786 monitor_printf(mon, "I/O at 0x%04" PRIx64
787 " [0x%04" PRIx64 "].\n",
788 addr, addr + size - 1);
790 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
791 " [0x%08" PRIx64 "].\n",
792 region->value->mem_type_64 ? 64 : 32,
793 region->value->prefetch ? " prefetchable" : "",
794 addr, addr + size - 1);
798 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
800 if (dev->has_pci_bridge) {
801 if (dev->pci_bridge->has_devices) {
802 PciDeviceInfoList *cdev;
803 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
804 hmp_info_pci_device(mon, cdev->value);
810 static int hmp_info_irq_foreach(Object *obj, void *opaque)
812 InterruptStatsProvider *intc;
813 InterruptStatsProviderClass *k;
814 Monitor *mon = opaque;
816 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
817 intc = INTERRUPT_STATS_PROVIDER(obj);
818 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
819 uint64_t *irq_counts;
820 unsigned int nb_irqs, i;
821 if (k->get_statistics &&
822 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
824 monitor_printf(mon, "IRQ statistics for %s:\n",
825 object_get_typename(obj));
826 for (i = 0; i < nb_irqs; i++) {
827 if (irq_counts[i] > 0) {
828 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
834 monitor_printf(mon, "IRQ statistics not available for %s.\n",
835 object_get_typename(obj));
842 void hmp_info_irq(Monitor *mon, const QDict *qdict)
844 object_child_foreach_recursive(object_get_root(),
845 hmp_info_irq_foreach, mon);
848 static int hmp_info_pic_foreach(Object *obj, void *opaque)
850 InterruptStatsProvider *intc;
851 InterruptStatsProviderClass *k;
852 Monitor *mon = opaque;
854 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
855 intc = INTERRUPT_STATS_PROVIDER(obj);
856 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
858 k->print_info(intc, mon);
860 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
861 object_get_typename(obj));
868 void hmp_info_pic(Monitor *mon, const QDict *qdict)
870 object_child_foreach_recursive(object_get_root(),
871 hmp_info_pic_foreach, mon);
874 void hmp_info_pci(Monitor *mon, const QDict *qdict)
876 PciInfoList *info_list, *info;
879 info_list = qmp_query_pci(&err);
881 monitor_printf(mon, "PCI devices not supported\n");
886 for (info = info_list; info; info = info->next) {
887 PciDeviceInfoList *dev;
889 for (dev = info->value->devices; dev; dev = dev->next) {
890 hmp_info_pci_device(mon, dev->value);
894 qapi_free_PciInfoList(info_list);
897 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
899 BlockJobInfoList *list;
902 list = qmp_query_block_jobs(&err);
906 monitor_printf(mon, "No active jobs\n");
911 if (strcmp(list->value->type, "stream") == 0) {
912 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
913 " of %" PRId64 " bytes, speed limit %" PRId64
920 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
921 " of %" PRId64 " bytes, speed limit %" PRId64
932 qapi_free_BlockJobInfoList(list);
935 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
937 TPMInfoList *info_list, *info;
940 TPMPassthroughOptions *tpo;
942 info_list = qmp_query_tpm(&err);
944 monitor_printf(mon, "TPM device not supported\n");
950 monitor_printf(mon, "TPM device:\n");
953 for (info = info_list; info; info = info->next) {
954 TPMInfo *ti = info->value;
955 monitor_printf(mon, " tpm%d: model=%s\n",
956 c, TpmModel_lookup[ti->model]);
958 monitor_printf(mon, " \\ %s: type=%s",
959 ti->id, TpmTypeOptionsKind_lookup[ti->options->type]);
961 switch (ti->options->type) {
962 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
963 tpo = ti->options->u.passthrough.data;
964 monitor_printf(mon, "%s%s%s%s",
965 tpo->has_path ? ",path=" : "",
966 tpo->has_path ? tpo->path : "",
967 tpo->has_cancel_path ? ",cancel-path=" : "",
968 tpo->has_cancel_path ? tpo->cancel_path : "");
970 case TPM_TYPE_OPTIONS_KIND__MAX:
973 monitor_printf(mon, "\n");
976 qapi_free_TPMInfoList(info_list);
979 void hmp_quit(Monitor *mon, const QDict *qdict)
981 monitor_suspend(mon);
985 void hmp_stop(Monitor *mon, const QDict *qdict)
990 void hmp_system_reset(Monitor *mon, const QDict *qdict)
992 qmp_system_reset(NULL);
995 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
997 qmp_system_powerdown(NULL);
1000 void hmp_cpu(Monitor *mon, const QDict *qdict)
1004 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1005 use it are converted to the QAPI */
1006 cpu_index = qdict_get_int(qdict, "index");
1007 if (monitor_set_cpu(cpu_index) < 0) {
1008 monitor_printf(mon, "invalid CPU index\n");
1012 void hmp_memsave(Monitor *mon, const QDict *qdict)
1014 uint32_t size = qdict_get_int(qdict, "size");
1015 const char *filename = qdict_get_str(qdict, "filename");
1016 uint64_t addr = qdict_get_int(qdict, "val");
1018 int cpu_index = monitor_get_cpu_index();
1020 if (cpu_index < 0) {
1021 monitor_printf(mon, "No CPU available\n");
1025 qmp_memsave(addr, size, filename, true, cpu_index, &err);
1026 hmp_handle_error(mon, &err);
1029 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1031 uint32_t size = qdict_get_int(qdict, "size");
1032 const char *filename = qdict_get_str(qdict, "filename");
1033 uint64_t addr = qdict_get_int(qdict, "val");
1036 qmp_pmemsave(addr, size, filename, &err);
1037 hmp_handle_error(mon, &err);
1040 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1042 const char *chardev = qdict_get_str(qdict, "device");
1043 const char *data = qdict_get_str(qdict, "data");
1046 qmp_ringbuf_write(chardev, data, false, 0, &err);
1048 hmp_handle_error(mon, &err);
1051 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
1053 uint32_t size = qdict_get_int(qdict, "size");
1054 const char *chardev = qdict_get_str(qdict, "device");
1059 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1061 error_report_err(err);
1065 for (i = 0; data[i]; i++) {
1066 unsigned char ch = data[i];
1069 monitor_printf(mon, "\\\\");
1070 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1071 monitor_printf(mon, "\\u%04X", ch);
1073 monitor_printf(mon, "%c", ch);
1077 monitor_printf(mon, "\n");
1081 static void hmp_cont_cb(void *opaque, int err)
1088 static bool key_is_missing(const BlockInfo *bdev)
1090 return (bdev->inserted && bdev->inserted->encryption_key_missing);
1093 void hmp_cont(Monitor *mon, const QDict *qdict)
1095 BlockInfoList *bdev_list, *bdev;
1098 bdev_list = qmp_query_block(NULL);
1099 for (bdev = bdev_list; bdev; bdev = bdev->next) {
1100 if (key_is_missing(bdev->value)) {
1101 monitor_read_block_device_key(mon, bdev->value->device,
1108 hmp_handle_error(mon, &err);
1111 qapi_free_BlockInfoList(bdev_list);
1114 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1116 qmp_system_wakeup(NULL);
1119 void hmp_nmi(Monitor *mon, const QDict *qdict)
1123 qmp_inject_nmi(&err);
1124 hmp_handle_error(mon, &err);
1127 void hmp_set_link(Monitor *mon, const QDict *qdict)
1129 const char *name = qdict_get_str(qdict, "name");
1130 bool up = qdict_get_bool(qdict, "up");
1133 qmp_set_link(name, up, &err);
1134 hmp_handle_error(mon, &err);
1137 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1139 const char *device = qdict_get_str(qdict, "device");
1140 const char *password = qdict_get_str(qdict, "password");
1143 qmp_block_passwd(true, device, false, NULL, password, &err);
1144 hmp_handle_error(mon, &err);
1147 void hmp_balloon(Monitor *mon, const QDict *qdict)
1149 int64_t value = qdict_get_int(qdict, "value");
1152 qmp_balloon(value, &err);
1154 error_report_err(err);
1158 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1160 const char *device = qdict_get_str(qdict, "device");
1161 int64_t size = qdict_get_int(qdict, "size");
1164 qmp_block_resize(true, device, false, NULL, size, &err);
1165 hmp_handle_error(mon, &err);
1168 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1170 const char *filename = qdict_get_str(qdict, "target");
1171 const char *format = qdict_get_try_str(qdict, "format");
1172 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1173 bool full = qdict_get_try_bool(qdict, "full", false);
1175 DriveMirror mirror = {
1176 .device = (char *)qdict_get_str(qdict, "device"),
1177 .target = (char *)filename,
1178 .has_format = !!format,
1179 .format = (char *)format,
1180 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1182 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1187 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1188 hmp_handle_error(mon, &err);
1191 qmp_drive_mirror(&mirror, &err);
1192 hmp_handle_error(mon, &err);
1195 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1197 const char *device = qdict_get_str(qdict, "device");
1198 const char *filename = qdict_get_str(qdict, "target");
1199 const char *format = qdict_get_try_str(qdict, "format");
1200 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1201 bool full = qdict_get_try_bool(qdict, "full", false);
1202 bool compress = qdict_get_try_bool(qdict, "compress", false);
1204 DriveBackup backup = {
1205 .device = (char *)device,
1206 .target = (char *)filename,
1207 .has_format = !!format,
1208 .format = (char *)format,
1209 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1211 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1212 .has_compress = !!compress,
1213 .compress = compress,
1217 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1218 hmp_handle_error(mon, &err);
1222 qmp_drive_backup(&backup, &err);
1223 hmp_handle_error(mon, &err);
1226 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1228 const char *device = qdict_get_str(qdict, "device");
1229 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1230 const char *format = qdict_get_try_str(qdict, "format");
1231 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1232 enum NewImageMode mode;
1236 /* In the future, if 'snapshot-file' is not specified, the snapshot
1237 will be taken internally. Today it's actually required. */
1238 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1239 hmp_handle_error(mon, &err);
1243 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1244 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1245 filename, false, NULL,
1248 hmp_handle_error(mon, &err);
1251 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1253 const char *device = qdict_get_str(qdict, "device");
1254 const char *name = qdict_get_str(qdict, "name");
1257 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1258 hmp_handle_error(mon, &err);
1261 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1263 const char *device = qdict_get_str(qdict, "device");
1264 const char *name = qdict_get_str(qdict, "name");
1265 const char *id = qdict_get_try_str(qdict, "id");
1268 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1270 hmp_handle_error(mon, &err);
1273 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1275 qmp_migrate_cancel(NULL);
1278 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1281 const char *uri = qdict_get_str(qdict, "uri");
1283 qmp_migrate_incoming(uri, &err);
1285 hmp_handle_error(mon, &err);
1288 /* Kept for backwards compatibility */
1289 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1291 double value = qdict_get_double(qdict, "value");
1292 qmp_migrate_set_downtime(value, NULL);
1295 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1297 int64_t value = qdict_get_int(qdict, "value");
1300 qmp_migrate_set_cache_size(value, &err);
1302 error_report_err(err);
1307 /* Kept for backwards compatibility */
1308 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1310 int64_t value = qdict_get_int(qdict, "value");
1311 qmp_migrate_set_speed(value, NULL);
1314 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1316 const char *cap = qdict_get_str(qdict, "capability");
1317 bool state = qdict_get_bool(qdict, "state");
1319 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1322 for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
1323 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1324 caps->value = g_malloc0(sizeof(*caps->value));
1325 caps->value->capability = i;
1326 caps->value->state = state;
1328 qmp_migrate_set_capabilities(caps, &err);
1333 if (i == MIGRATION_CAPABILITY__MAX) {
1334 error_setg(&err, QERR_INVALID_PARAMETER, cap);
1337 qapi_free_MigrationCapabilityStatusList(caps);
1340 error_report_err(err);
1344 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1346 const char *param = qdict_get_str(qdict, "parameter");
1347 const char *valuestr = qdict_get_str(qdict, "value");
1348 uint64_t valuebw = 0;
1351 bool use_int_value = false;
1354 for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
1355 if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
1356 MigrationParameters p = { 0 };
1358 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1359 p.has_compress_level = true;
1360 use_int_value = true;
1362 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1363 p.has_compress_threads = true;
1364 use_int_value = true;
1366 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1367 p.has_decompress_threads = true;
1368 use_int_value = true;
1370 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1371 p.has_cpu_throttle_initial = true;
1372 use_int_value = true;
1374 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1375 p.has_cpu_throttle_increment = true;
1376 use_int_value = true;
1378 case MIGRATION_PARAMETER_TLS_CREDS:
1379 p.has_tls_creds = true;
1380 p.tls_creds = (char *) valuestr;
1382 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1383 p.has_tls_hostname = true;
1384 p.tls_hostname = (char *) valuestr;
1386 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1387 p.has_max_bandwidth = true;
1388 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1389 if (ret < 0 || valuebw > INT64_MAX
1390 || (size_t)valuebw != valuebw) {
1391 error_setg(&err, "Invalid size %s", valuestr);
1394 p.max_bandwidth = valuebw;
1396 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1397 p.has_downtime_limit = true;
1398 use_int_value = true;
1400 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1401 p.has_x_checkpoint_delay = true;
1402 use_int_value = true;
1406 if (use_int_value) {
1407 if (qemu_strtol(valuestr, NULL, 10, &valueint) < 0) {
1408 error_setg(&err, "Unable to parse '%s' as an int",
1412 /* Set all integers; only one has_FOO will be set, and
1413 * the code ignores the remaining values */
1414 p.compress_level = valueint;
1415 p.compress_threads = valueint;
1416 p.decompress_threads = valueint;
1417 p.cpu_throttle_initial = valueint;
1418 p.cpu_throttle_increment = valueint;
1419 p.downtime_limit = valueint;
1420 p.x_checkpoint_delay = valueint;
1423 qmp_migrate_set_parameters(&p, &err);
1428 if (i == MIGRATION_PARAMETER__MAX) {
1429 error_setg(&err, QERR_INVALID_PARAMETER, param);
1434 error_report_err(err);
1438 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1441 const char *protocol = qdict_get_str(qdict, "protocol");
1442 const char *hostname = qdict_get_str(qdict, "hostname");
1443 bool has_port = qdict_haskey(qdict, "port");
1444 int port = qdict_get_try_int(qdict, "port", -1);
1445 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1446 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1447 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1449 qmp_client_migrate_info(protocol, hostname,
1450 has_port, port, has_tls_port, tls_port,
1451 !!cert_subject, cert_subject, &err);
1452 hmp_handle_error(mon, &err);
1455 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1458 qmp_migrate_start_postcopy(&err);
1459 hmp_handle_error(mon, &err);
1462 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1466 qmp_x_colo_lost_heartbeat(&err);
1467 hmp_handle_error(mon, &err);
1470 void hmp_set_password(Monitor *mon, const QDict *qdict)
1472 const char *protocol = qdict_get_str(qdict, "protocol");
1473 const char *password = qdict_get_str(qdict, "password");
1474 const char *connected = qdict_get_try_str(qdict, "connected");
1477 qmp_set_password(protocol, password, !!connected, connected, &err);
1478 hmp_handle_error(mon, &err);
1481 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1483 const char *protocol = qdict_get_str(qdict, "protocol");
1484 const char *whenstr = qdict_get_str(qdict, "time");
1487 qmp_expire_password(protocol, whenstr, &err);
1488 hmp_handle_error(mon, &err);
1491 void hmp_eject(Monitor *mon, const QDict *qdict)
1493 bool force = qdict_get_try_bool(qdict, "force", false);
1494 const char *device = qdict_get_str(qdict, "device");
1497 qmp_eject(true, device, false, NULL, true, force, &err);
1498 hmp_handle_error(mon, &err);
1501 static void hmp_change_read_arg(void *opaque, const char *password,
1502 void *readline_opaque)
1504 qmp_change_vnc_password(password, NULL);
1505 monitor_read_command(opaque, 1);
1508 void hmp_change(Monitor *mon, const QDict *qdict)
1510 const char *device = qdict_get_str(qdict, "device");
1511 const char *target = qdict_get_str(qdict, "target");
1512 const char *arg = qdict_get_try_str(qdict, "arg");
1513 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1514 BlockdevChangeReadOnlyMode read_only_mode = 0;
1517 if (strcmp(device, "vnc") == 0) {
1520 "Parameter 'read-only-mode' is invalid for VNC\n");
1523 if (strcmp(target, "passwd") == 0 ||
1524 strcmp(target, "password") == 0) {
1526 monitor_read_password(mon, hmp_change_read_arg, NULL);
1530 qmp_change("vnc", target, !!arg, arg, &err);
1534 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup,
1535 read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX,
1536 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1538 hmp_handle_error(mon, &err);
1543 qmp_blockdev_change_medium(true, device, false, NULL, target,
1544 !!arg, arg, !!read_only, read_only_mode,
1547 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
1549 monitor_read_block_device_key(mon, device, NULL, NULL);
1554 hmp_handle_error(mon, &err);
1557 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1560 BlockIOThrottle throttle = {
1562 .device = (char *) qdict_get_str(qdict, "device"),
1563 .bps = qdict_get_int(qdict, "bps"),
1564 .bps_rd = qdict_get_int(qdict, "bps_rd"),
1565 .bps_wr = qdict_get_int(qdict, "bps_wr"),
1566 .iops = qdict_get_int(qdict, "iops"),
1567 .iops_rd = qdict_get_int(qdict, "iops_rd"),
1568 .iops_wr = qdict_get_int(qdict, "iops_wr"),
1571 qmp_block_set_io_throttle(&throttle, &err);
1572 hmp_handle_error(mon, &err);
1575 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1577 Error *error = NULL;
1578 const char *device = qdict_get_str(qdict, "device");
1579 const char *base = qdict_get_try_str(qdict, "base");
1580 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1582 qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
1583 false, NULL, qdict_haskey(qdict, "speed"), speed,
1584 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1586 hmp_handle_error(mon, &error);
1589 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1591 Error *error = NULL;
1592 const char *device = qdict_get_str(qdict, "device");
1593 int64_t value = qdict_get_int(qdict, "speed");
1595 qmp_block_job_set_speed(device, value, &error);
1597 hmp_handle_error(mon, &error);
1600 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1602 Error *error = NULL;
1603 const char *device = qdict_get_str(qdict, "device");
1604 bool force = qdict_get_try_bool(qdict, "force", false);
1606 qmp_block_job_cancel(device, true, force, &error);
1608 hmp_handle_error(mon, &error);
1611 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1613 Error *error = NULL;
1614 const char *device = qdict_get_str(qdict, "device");
1616 qmp_block_job_pause(device, &error);
1618 hmp_handle_error(mon, &error);
1621 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1623 Error *error = NULL;
1624 const char *device = qdict_get_str(qdict, "device");
1626 qmp_block_job_resume(device, &error);
1628 hmp_handle_error(mon, &error);
1631 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1633 Error *error = NULL;
1634 const char *device = qdict_get_str(qdict, "device");
1636 qmp_block_job_complete(device, &error);
1638 hmp_handle_error(mon, &error);
1641 typedef struct HMPMigrationStatus
1645 bool is_block_migration;
1646 } HMPMigrationStatus;
1648 static void hmp_migrate_status_cb(void *opaque)
1650 HMPMigrationStatus *status = opaque;
1651 MigrationInfo *info;
1653 info = qmp_query_migrate(NULL);
1654 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1655 info->status == MIGRATION_STATUS_SETUP) {
1656 if (info->has_disk) {
1659 if (info->disk->remaining) {
1660 progress = info->disk->transferred * 100 / info->disk->total;
1665 monitor_printf(status->mon, "Completed %d %%\r", progress);
1666 monitor_flush(status->mon);
1669 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1671 if (status->is_block_migration) {
1672 monitor_printf(status->mon, "\n");
1674 if (info->has_error_desc) {
1675 error_report("%s", info->error_desc);
1677 monitor_resume(status->mon);
1678 timer_del(status->timer);
1682 qapi_free_MigrationInfo(info);
1685 void hmp_migrate(Monitor *mon, const QDict *qdict)
1687 bool detach = qdict_get_try_bool(qdict, "detach", false);
1688 bool blk = qdict_get_try_bool(qdict, "blk", false);
1689 bool inc = qdict_get_try_bool(qdict, "inc", false);
1690 const char *uri = qdict_get_str(qdict, "uri");
1693 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1695 error_report_err(err);
1700 HMPMigrationStatus *status;
1702 if (monitor_suspend(mon) < 0) {
1703 monitor_printf(mon, "terminal does not allow synchronous "
1704 "migration, continuing detached\n");
1708 status = g_malloc0(sizeof(*status));
1710 status->is_block_migration = blk || inc;
1711 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1713 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1717 void hmp_device_add(Monitor *mon, const QDict *qdict)
1721 qmp_device_add((QDict *)qdict, NULL, &err);
1722 hmp_handle_error(mon, &err);
1725 void hmp_device_del(Monitor *mon, const QDict *qdict)
1727 const char *id = qdict_get_str(qdict, "id");
1730 qmp_device_del(id, &err);
1731 hmp_handle_error(mon, &err);
1734 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1737 bool paging = qdict_get_try_bool(qdict, "paging", false);
1738 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
1739 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
1740 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
1741 const char *file = qdict_get_str(qdict, "filename");
1742 bool has_begin = qdict_haskey(qdict, "begin");
1743 bool has_length = qdict_haskey(qdict, "length");
1744 bool has_detach = qdict_haskey(qdict, "detach");
1747 bool detach = false;
1748 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1751 if (zlib + lzo + snappy > 1) {
1752 error_setg(&err, "only one of '-z|-l|-s' can be set");
1753 hmp_handle_error(mon, &err);
1758 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1762 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1766 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1770 begin = qdict_get_int(qdict, "begin");
1773 length = qdict_get_int(qdict, "length");
1776 detach = qdict_get_bool(qdict, "detach");
1779 prot = g_strconcat("file:", file, NULL);
1781 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
1782 has_length, length, true, dump_format, &err);
1783 hmp_handle_error(mon, &err);
1787 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1792 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1797 netdev_add(opts, &err);
1799 qemu_opts_del(opts);
1803 hmp_handle_error(mon, &err);
1806 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1808 const char *id = qdict_get_str(qdict, "id");
1811 qmp_netdev_del(id, &err);
1812 hmp_handle_error(mon, &err);
1815 void hmp_object_add(Monitor *mon, const QDict *qdict)
1821 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1823 hmp_handle_error(mon, &err);
1827 obj = user_creatable_add_opts(opts, &err);
1828 qemu_opts_del(opts);
1831 hmp_handle_error(mon, &err);
1838 void hmp_getfd(Monitor *mon, const QDict *qdict)
1840 const char *fdname = qdict_get_str(qdict, "fdname");
1843 qmp_getfd(fdname, &err);
1844 hmp_handle_error(mon, &err);
1847 void hmp_closefd(Monitor *mon, const QDict *qdict)
1849 const char *fdname = qdict_get_str(qdict, "fdname");
1852 qmp_closefd(fdname, &err);
1853 hmp_handle_error(mon, &err);
1856 void hmp_sendkey(Monitor *mon, const QDict *qdict)
1858 const char *keys = qdict_get_str(qdict, "keys");
1859 KeyValueList *keylist, *head = NULL, *tmp = NULL;
1860 int has_hold_time = qdict_haskey(qdict, "hold-time");
1861 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1867 separator = strchr(keys, '-');
1868 keyname_len = separator ? separator - keys : strlen(keys);
1870 /* Be compatible with old interface, convert user inputted "<" */
1871 if (keys[0] == '<' && keyname_len == 1) {
1876 keylist = g_malloc0(sizeof(*keylist));
1877 keylist->value = g_malloc0(sizeof(*keylist->value));
1883 tmp->next = keylist;
1887 if (strstart(keys, "0x", NULL)) {
1889 int value = strtoul(keys, &endp, 0);
1890 assert(endp <= keys + keyname_len);
1891 if (endp != keys + keyname_len) {
1894 keylist->value->type = KEY_VALUE_KIND_NUMBER;
1895 keylist->value->u.number.data = value;
1897 int idx = index_from_key(keys, keyname_len);
1898 if (idx == Q_KEY_CODE__MAX) {
1901 keylist->value->type = KEY_VALUE_KIND_QCODE;
1902 keylist->value->u.qcode.data = idx;
1908 keys = separator + 1;
1911 qmp_send_key(head, has_hold_time, hold_time, &err);
1912 hmp_handle_error(mon, &err);
1915 qapi_free_KeyValueList(head);
1919 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
1923 void hmp_screendump(Monitor *mon, const QDict *qdict)
1925 const char *filename = qdict_get_str(qdict, "filename");
1928 qmp_screendump(filename, &err);
1929 hmp_handle_error(mon, &err);
1932 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1934 const char *uri = qdict_get_str(qdict, "uri");
1935 bool writable = qdict_get_try_bool(qdict, "writable", false);
1936 bool all = qdict_get_try_bool(qdict, "all", false);
1937 Error *local_err = NULL;
1938 BlockInfoList *block_list, *info;
1939 SocketAddress *addr;
1941 if (writable && !all) {
1942 error_setg(&local_err, "-w only valid together with -a");
1946 /* First check if the address is valid and start the server. */
1947 addr = socket_parse(uri, &local_err);
1948 if (local_err != NULL) {
1952 qmp_nbd_server_start(addr, false, NULL, &local_err);
1953 qapi_free_SocketAddress(addr);
1954 if (local_err != NULL) {
1962 /* Then try adding all block devices. If one fails, close all and
1965 block_list = qmp_query_block(NULL);
1967 for (info = block_list; info; info = info->next) {
1968 if (!info->value->has_inserted) {
1972 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1974 if (local_err != NULL) {
1975 qmp_nbd_server_stop(NULL);
1980 qapi_free_BlockInfoList(block_list);
1983 hmp_handle_error(mon, &local_err);
1986 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1988 const char *device = qdict_get_str(qdict, "device");
1989 bool writable = qdict_get_try_bool(qdict, "writable", false);
1990 Error *local_err = NULL;
1992 qmp_nbd_server_add(device, true, writable, &local_err);
1994 if (local_err != NULL) {
1995 hmp_handle_error(mon, &local_err);
1999 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
2003 qmp_nbd_server_stop(&err);
2004 hmp_handle_error(mon, &err);
2007 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
2012 cpuid = qdict_get_int(qdict, "id");
2013 qmp_cpu_add(cpuid, &err);
2014 hmp_handle_error(mon, &err);
2017 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2019 const char *args = qdict_get_str(qdict, "args");
2023 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
2025 error_setg(&err, "Parsing chardev args failed");
2027 qemu_chr_new_from_opts(opts, &err);
2028 qemu_opts_del(opts);
2030 hmp_handle_error(mon, &err);
2033 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2035 Error *local_err = NULL;
2037 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
2038 hmp_handle_error(mon, &local_err);
2041 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
2044 BlockBackend *local_blk = NULL;
2045 AioContext *aio_context;
2046 const char* device = qdict_get_str(qdict, "device");
2047 const char* command = qdict_get_str(qdict, "command");
2051 blk = blk_by_name(device);
2053 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
2055 blk = local_blk = blk_new(0, BLK_PERM_ALL);
2056 ret = blk_insert_bs(blk, bs, &err);
2065 aio_context = blk_get_aio_context(blk);
2066 aio_context_acquire(aio_context);
2069 * Notably absent: Proper permission management. This is sad, but it seems
2070 * almost impossible to achieve without changing the semantics and thereby
2071 * limiting the use cases of the qemu-io HMP command.
2073 * In an ideal world we would unconditionally create a new BlockBackend for
2074 * qemuio_command(), but we have commands like 'reopen' and want them to
2075 * take effect on the exact BlockBackend whose name the user passed instead
2076 * of just on a temporary copy of it.
2078 * Another problem is that deleting the temporary BlockBackend involves
2079 * draining all requests on it first, but some qemu-iotests cases want to
2080 * issue multiple aio_read/write requests and expect them to complete in
2081 * the background while the monitor has already returned.
2083 * This is also what prevents us from saving the original permissions and
2084 * restoring them later: We can't revoke permissions until all requests
2085 * have completed, and we don't know when that is nor can we really let
2086 * anything else run before we have revoken them to avoid race conditions.
2088 * What happens now is that command() in qemu-io-cmds.c can extend the
2089 * permissions if necessary for the qemu-io command. And they simply stay
2090 * extended, possibly resulting in a read-only guest device keeping write
2091 * permissions. Ugly, but it appears to be the lesser evil.
2093 qemuio_command(blk, command);
2095 aio_context_release(aio_context);
2098 blk_unref(local_blk);
2099 hmp_handle_error(mon, &err);
2102 void hmp_object_del(Monitor *mon, const QDict *qdict)
2104 const char *id = qdict_get_str(qdict, "id");
2107 user_creatable_del(id, &err);
2108 hmp_handle_error(mon, &err);
2111 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
2114 MemdevList *memdev_list = qmp_query_memdev(&err);
2115 MemdevList *m = memdev_list;
2120 v = string_output_visitor_new(false, &str);
2121 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
2122 monitor_printf(mon, "memory backend: %s\n", m->value->id);
2123 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
2124 monitor_printf(mon, " merge: %s\n",
2125 m->value->merge ? "true" : "false");
2126 monitor_printf(mon, " dump: %s\n",
2127 m->value->dump ? "true" : "false");
2128 monitor_printf(mon, " prealloc: %s\n",
2129 m->value->prealloc ? "true" : "false");
2130 monitor_printf(mon, " policy: %s\n",
2131 HostMemPolicy_lookup[m->value->policy]);
2132 visit_complete(v, &str);
2133 monitor_printf(mon, " host nodes: %s\n", str);
2140 monitor_printf(mon, "\n");
2142 qapi_free_MemdevList(memdev_list);
2145 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2148 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2149 MemoryDeviceInfoList *info;
2150 MemoryDeviceInfo *value;
2151 PCDIMMDeviceInfo *di;
2153 for (info = info_list; info; info = info->next) {
2154 value = info->value;
2157 switch (value->type) {
2158 case MEMORY_DEVICE_INFO_KIND_DIMM:
2159 di = value->u.dimm.data;
2161 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2162 MemoryDeviceInfoKind_lookup[value->type],
2163 di->id ? di->id : "");
2164 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2165 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2166 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2167 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2168 monitor_printf(mon, " memdev: %s\n", di->memdev);
2169 monitor_printf(mon, " hotplugged: %s\n",
2170 di->hotplugged ? "true" : "false");
2171 monitor_printf(mon, " hotpluggable: %s\n",
2172 di->hotpluggable ? "true" : "false");
2180 qapi_free_MemoryDeviceInfoList(info_list);
2183 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2185 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2186 IOThreadInfoList *info;
2187 IOThreadInfo *value;
2189 for (info = info_list; info; info = info->next) {
2190 value = info->value;
2191 monitor_printf(mon, "%s:\n", value->id);
2192 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
2193 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2194 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
2195 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
2198 qapi_free_IOThreadInfoList(info_list);
2201 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2203 const char *path = qdict_get_try_str(qdict, "path");
2204 ObjectPropertyInfoList *list;
2208 monitor_printf(mon, "/\n");
2212 list = qmp_qom_list(path, &err);
2214 ObjectPropertyInfoList *start = list;
2215 while (list != NULL) {
2216 ObjectPropertyInfo *value = list->value;
2218 monitor_printf(mon, "%s (%s)\n",
2219 value->name, value->type);
2222 qapi_free_ObjectPropertyInfoList(start);
2224 hmp_handle_error(mon, &err);
2227 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2229 const char *path = qdict_get_str(qdict, "path");
2230 const char *property = qdict_get_str(qdict, "property");
2231 const char *value = qdict_get_str(qdict, "value");
2233 bool ambiguous = false;
2236 obj = object_resolve_path(path, &ambiguous);
2238 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2239 "Device '%s' not found", path);
2242 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2244 object_property_parse(obj, value, property, &err);
2246 hmp_handle_error(mon, &err);
2249 void hmp_rocker(Monitor *mon, const QDict *qdict)
2251 const char *name = qdict_get_str(qdict, "name");
2252 RockerSwitch *rocker;
2255 rocker = qmp_query_rocker(name, &err);
2257 hmp_handle_error(mon, &err);
2261 monitor_printf(mon, "name: %s\n", rocker->name);
2262 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2263 monitor_printf(mon, "ports: %d\n", rocker->ports);
2265 qapi_free_RockerSwitch(rocker);
2268 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2270 RockerPortList *list, *port;
2271 const char *name = qdict_get_str(qdict, "name");
2274 list = qmp_query_rocker_ports(name, &err);
2276 hmp_handle_error(mon, &err);
2280 monitor_printf(mon, " ena/ speed/ auto\n");
2281 monitor_printf(mon, " port link duplex neg?\n");
2283 for (port = list; port; port = port->next) {
2284 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2286 port->value->enabled ? port->value->link_up ?
2287 "up" : "down" : "!ena",
2288 port->value->speed == 10000 ? "10G" : "??",
2289 port->value->duplex ? "FD" : "HD",
2290 port->value->autoneg ? "Yes" : "No");
2293 qapi_free_RockerPortList(list);
2296 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2298 RockerOfDpaFlowList *list, *info;
2299 const char *name = qdict_get_str(qdict, "name");
2300 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2303 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2305 hmp_handle_error(mon, &err);
2309 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2311 for (info = list; info; info = info->next) {
2312 RockerOfDpaFlow *flow = info->value;
2313 RockerOfDpaFlowKey *key = flow->key;
2314 RockerOfDpaFlowMask *mask = flow->mask;
2315 RockerOfDpaFlowAction *action = flow->action;
2318 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2319 key->priority, key->tbl_id, flow->hits);
2321 monitor_printf(mon, "%-4d %-3d ",
2322 key->priority, key->tbl_id);
2325 if (key->has_in_pport) {
2326 monitor_printf(mon, " pport %d", key->in_pport);
2327 if (mask->has_in_pport) {
2328 monitor_printf(mon, "(0x%x)", mask->in_pport);
2332 if (key->has_vlan_id) {
2333 monitor_printf(mon, " vlan %d",
2334 key->vlan_id & VLAN_VID_MASK);
2335 if (mask->has_vlan_id) {
2336 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2340 if (key->has_tunnel_id) {
2341 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2342 if (mask->has_tunnel_id) {
2343 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2347 if (key->has_eth_type) {
2348 switch (key->eth_type) {
2350 monitor_printf(mon, " ARP");
2353 monitor_printf(mon, " IP");
2356 monitor_printf(mon, " IPv6");
2359 monitor_printf(mon, " LACP");
2362 monitor_printf(mon, " LLDP");
2365 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2370 if (key->has_eth_src) {
2371 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2372 (mask->has_eth_src) &&
2373 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2374 monitor_printf(mon, " src <any mcast/bcast>");
2375 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2376 (mask->has_eth_src) &&
2377 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2378 monitor_printf(mon, " src <any ucast>");
2380 monitor_printf(mon, " src %s", key->eth_src);
2381 if (mask->has_eth_src) {
2382 monitor_printf(mon, "(%s)", mask->eth_src);
2387 if (key->has_eth_dst) {
2388 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2389 (mask->has_eth_dst) &&
2390 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2391 monitor_printf(mon, " dst <any mcast/bcast>");
2392 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2393 (mask->has_eth_dst) &&
2394 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2395 monitor_printf(mon, " dst <any ucast>");
2397 monitor_printf(mon, " dst %s", key->eth_dst);
2398 if (mask->has_eth_dst) {
2399 monitor_printf(mon, "(%s)", mask->eth_dst);
2404 if (key->has_ip_proto) {
2405 monitor_printf(mon, " proto %d", key->ip_proto);
2406 if (mask->has_ip_proto) {
2407 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2411 if (key->has_ip_tos) {
2412 monitor_printf(mon, " TOS %d", key->ip_tos);
2413 if (mask->has_ip_tos) {
2414 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2418 if (key->has_ip_dst) {
2419 monitor_printf(mon, " dst %s", key->ip_dst);
2422 if (action->has_goto_tbl || action->has_group_id ||
2423 action->has_new_vlan_id) {
2424 monitor_printf(mon, " -->");
2427 if (action->has_new_vlan_id) {
2428 monitor_printf(mon, " apply new vlan %d",
2429 ntohs(action->new_vlan_id));
2432 if (action->has_group_id) {
2433 monitor_printf(mon, " write group 0x%08x", action->group_id);
2436 if (action->has_goto_tbl) {
2437 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2440 monitor_printf(mon, "\n");
2443 qapi_free_RockerOfDpaFlowList(list);
2446 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2448 RockerOfDpaGroupList *list, *g;
2449 const char *name = qdict_get_str(qdict, "name");
2450 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2454 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2456 hmp_handle_error(mon, &err);
2460 monitor_printf(mon, "id (decode) --> buckets\n");
2462 for (g = list; g; g = g->next) {
2463 RockerOfDpaGroup *group = g->value;
2465 monitor_printf(mon, "0x%08x", group->id);
2467 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2468 group->type == 1 ? "L2 rewrite" :
2469 group->type == 2 ? "L3 unicast" :
2470 group->type == 3 ? "L2 multicast" :
2471 group->type == 4 ? "L2 flood" :
2472 group->type == 5 ? "L3 interface" :
2473 group->type == 6 ? "L3 multicast" :
2474 group->type == 7 ? "L3 ECMP" :
2475 group->type == 8 ? "L2 overlay" :
2478 if (group->has_vlan_id) {
2479 monitor_printf(mon, " vlan %d", group->vlan_id);
2482 if (group->has_pport) {
2483 monitor_printf(mon, " pport %d", group->pport);
2486 if (group->has_index) {
2487 monitor_printf(mon, " index %d", group->index);
2490 monitor_printf(mon, ") -->");
2492 if (group->has_set_vlan_id && group->set_vlan_id) {
2494 monitor_printf(mon, " set vlan %d",
2495 group->set_vlan_id & VLAN_VID_MASK);
2498 if (group->has_set_eth_src) {
2501 monitor_printf(mon, " set");
2503 monitor_printf(mon, " src %s", group->set_eth_src);
2506 if (group->has_set_eth_dst) {
2509 monitor_printf(mon, " set");
2511 monitor_printf(mon, " dst %s", group->set_eth_dst);
2516 if (group->has_ttl_check && group->ttl_check) {
2517 monitor_printf(mon, " check TTL");
2520 if (group->has_group_id && group->group_id) {
2521 monitor_printf(mon, " group id 0x%08x", group->group_id);
2524 if (group->has_pop_vlan && group->pop_vlan) {
2525 monitor_printf(mon, " pop vlan");
2528 if (group->has_out_pport) {
2529 monitor_printf(mon, " out pport %d", group->out_pport);
2532 if (group->has_group_ids) {
2533 struct uint32List *id;
2535 monitor_printf(mon, " groups [");
2536 for (id = group->group_ids; id; id = id->next) {
2537 monitor_printf(mon, "0x%08x", id->value);
2539 monitor_printf(mon, ",");
2542 monitor_printf(mon, "]");
2545 monitor_printf(mon, "\n");
2548 qapi_free_RockerOfDpaGroupList(list);
2551 void hmp_info_dump(Monitor *mon, const QDict *qdict)
2553 DumpQueryResult *result = qmp_query_dump(NULL);
2555 assert(result && result->status < DUMP_STATUS__MAX);
2556 monitor_printf(mon, "Status: %s\n", DumpStatus_lookup[result->status]);
2558 if (result->status == DUMP_STATUS_ACTIVE) {
2560 assert(result->total != 0);
2561 percent = 100.0 * result->completed / result->total;
2562 monitor_printf(mon, "Finished: %.2f %%\n", percent);
2565 qapi_free_DumpQueryResult(result);
2568 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
2571 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
2572 HotpluggableCPUList *saved = l;
2573 CpuInstanceProperties *c;
2576 hmp_handle_error(mon, &err);
2580 monitor_printf(mon, "Hotpluggable CPUs:\n");
2582 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
2583 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
2584 l->value->vcpus_count);
2585 if (l->value->has_qom_path) {
2586 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
2589 c = l->value->props;
2590 monitor_printf(mon, " CPUInstance Properties:\n");
2591 if (c->has_node_id) {
2592 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
2594 if (c->has_socket_id) {
2595 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
2597 if (c->has_core_id) {
2598 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
2600 if (c->has_thread_id) {
2601 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
2607 qapi_free_HotpluggableCPUList(saved);
2610 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
2613 GuidInfo *info = qmp_query_vm_generation_id(&err);
2615 monitor_printf(mon, "%s\n", info->guid);
2617 hmp_handle_error(mon, &err);
2618 qapi_free_GuidInfo(info);