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"
40 #include <spice/enums.h>
43 static void hmp_handle_error(Monitor *mon, Error **errp)
47 error_report_err(*errp);
51 void hmp_info_name(Monitor *mon, const QDict *qdict)
55 info = qmp_query_name(NULL);
57 monitor_printf(mon, "%s\n", info->name);
59 qapi_free_NameInfo(info);
62 void hmp_info_version(Monitor *mon, const QDict *qdict)
66 info = qmp_query_version(NULL);
68 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
69 info->qemu->major, info->qemu->minor, info->qemu->micro,
72 qapi_free_VersionInfo(info);
75 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
79 info = qmp_query_kvm(NULL);
80 monitor_printf(mon, "kvm support: ");
82 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
84 monitor_printf(mon, "not compiled\n");
87 qapi_free_KvmInfo(info);
90 void hmp_info_status(Monitor *mon, const QDict *qdict)
94 info = qmp_query_status(NULL);
96 monitor_printf(mon, "VM status: %s%s",
97 info->running ? "running" : "paused",
98 info->singlestep ? " (single step mode)" : "");
100 if (!info->running && info->status != RUN_STATE_PAUSED) {
101 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
104 monitor_printf(mon, "\n");
106 qapi_free_StatusInfo(info);
109 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
113 info = qmp_query_uuid(NULL);
114 monitor_printf(mon, "%s\n", info->UUID);
115 qapi_free_UuidInfo(info);
118 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
120 ChardevInfoList *char_info, *info;
122 char_info = qmp_query_chardev(NULL);
123 for (info = char_info; info; info = info->next) {
124 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
125 info->value->filename);
128 qapi_free_ChardevInfoList(char_info);
131 void hmp_info_mice(Monitor *mon, const QDict *qdict)
133 MouseInfoList *mice_list, *mouse;
135 mice_list = qmp_query_mice(NULL);
137 monitor_printf(mon, "No mouse devices connected\n");
141 for (mouse = mice_list; mouse; mouse = mouse->next) {
142 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
143 mouse->value->current ? '*' : ' ',
144 mouse->value->index, mouse->value->name,
145 mouse->value->absolute ? " (absolute)" : "");
148 qapi_free_MouseInfoList(mice_list);
151 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
154 MigrationCapabilityStatusList *caps, *cap;
156 info = qmp_query_migrate(NULL);
157 caps = qmp_query_migrate_capabilities(NULL);
159 /* do not display parameters during setup */
160 if (info->has_status && caps) {
161 monitor_printf(mon, "capabilities: ");
162 for (cap = caps; cap; cap = cap->next) {
163 monitor_printf(mon, "%s: %s ",
164 MigrationCapability_lookup[cap->value->capability],
165 cap->value->state ? "on" : "off");
167 monitor_printf(mon, "\n");
170 if (info->has_status) {
171 monitor_printf(mon, "Migration status: %s\n",
172 MigrationStatus_lookup[info->status]);
173 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
175 if (info->has_expected_downtime) {
176 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
177 info->expected_downtime);
179 if (info->has_downtime) {
180 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
183 if (info->has_setup_time) {
184 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
190 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
191 info->ram->transferred >> 10);
192 monitor_printf(mon, "throughput: %0.2f mbps\n",
194 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
195 info->ram->remaining >> 10);
196 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
197 info->ram->total >> 10);
198 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
199 info->ram->duplicate);
200 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
202 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
204 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
205 info->ram->normal_bytes >> 10);
206 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
207 info->ram->dirty_sync_count);
208 if (info->ram->dirty_pages_rate) {
209 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
210 info->ram->dirty_pages_rate);
214 if (info->has_disk) {
215 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
216 info->disk->transferred >> 10);
217 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
218 info->disk->remaining >> 10);
219 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
220 info->disk->total >> 10);
223 if (info->has_xbzrle_cache) {
224 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
225 info->xbzrle_cache->cache_size);
226 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
227 info->xbzrle_cache->bytes >> 10);
228 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
229 info->xbzrle_cache->pages);
230 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
231 info->xbzrle_cache->cache_miss);
232 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
233 info->xbzrle_cache->cache_miss_rate);
234 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
235 info->xbzrle_cache->overflow);
238 if (info->has_x_cpu_throttle_percentage) {
239 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
240 info->x_cpu_throttle_percentage);
243 qapi_free_MigrationInfo(info);
244 qapi_free_MigrationCapabilityStatusList(caps);
247 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
249 MigrationCapabilityStatusList *caps, *cap;
251 caps = qmp_query_migrate_capabilities(NULL);
254 monitor_printf(mon, "capabilities: ");
255 for (cap = caps; cap; cap = cap->next) {
256 monitor_printf(mon, "%s: %s ",
257 MigrationCapability_lookup[cap->value->capability],
258 cap->value->state ? "on" : "off");
260 monitor_printf(mon, "\n");
263 qapi_free_MigrationCapabilityStatusList(caps);
266 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
268 MigrationParameters *params;
270 params = qmp_query_migrate_parameters(NULL);
273 monitor_printf(mon, "parameters:");
274 monitor_printf(mon, " %s: %" PRId64,
275 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_LEVEL],
276 params->compress_level);
277 monitor_printf(mon, " %s: %" PRId64,
278 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_THREADS],
279 params->compress_threads);
280 monitor_printf(mon, " %s: %" PRId64,
281 MigrationParameter_lookup[MIGRATION_PARAMETER_DECOMPRESS_THREADS],
282 params->decompress_threads);
283 monitor_printf(mon, " %s: %" PRId64,
284 MigrationParameter_lookup[MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL],
285 params->x_cpu_throttle_initial);
286 monitor_printf(mon, " %s: %" PRId64,
287 MigrationParameter_lookup[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT],
288 params->x_cpu_throttle_increment);
289 monitor_printf(mon, "\n");
292 qapi_free_MigrationParameters(params);
295 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
297 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
298 qmp_query_migrate_cache_size(NULL) >> 10);
301 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
303 CpuInfoList *cpu_list, *cpu;
305 cpu_list = qmp_query_cpus(NULL);
307 for (cpu = cpu_list; cpu; cpu = cpu->next) {
310 if (cpu->value->CPU == monitor_get_cpu_index()) {
314 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
316 switch (cpu->value->arch) {
317 case CPU_INFO_ARCH_X86:
318 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->u.x86.pc);
320 case CPU_INFO_ARCH_PPC:
321 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->u.ppc.nip);
323 case CPU_INFO_ARCH_SPARC:
324 monitor_printf(mon, " pc=0x%016" PRIx64,
325 cpu->value->u.q_sparc.pc);
326 monitor_printf(mon, " npc=0x%016" PRIx64,
327 cpu->value->u.q_sparc.npc);
329 case CPU_INFO_ARCH_MIPS:
330 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.q_mips.PC);
332 case CPU_INFO_ARCH_TRICORE:
333 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.tricore.PC);
339 if (cpu->value->halted) {
340 monitor_printf(mon, " (halted)");
343 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
346 qapi_free_CpuInfoList(cpu_list);
349 static void print_block_info(Monitor *mon, BlockInfo *info,
350 BlockDeviceInfo *inserted, bool verbose)
352 ImageInfo *image_info;
354 assert(!info || !info->has_inserted || info->inserted == inserted);
357 monitor_printf(mon, "%s", info->device);
358 if (inserted && inserted->has_node_name) {
359 monitor_printf(mon, " (%s)", inserted->node_name);
363 monitor_printf(mon, "%s",
364 inserted->has_node_name
365 ? inserted->node_name
370 monitor_printf(mon, ": %s (%s%s%s)\n",
373 inserted->ro ? ", read-only" : "",
374 inserted->encrypted ? ", encrypted" : "");
376 monitor_printf(mon, ": [not inserted]\n");
380 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
381 monitor_printf(mon, " I/O status: %s\n",
382 BlockDeviceIoStatus_lookup[info->io_status]);
385 if (info->removable) {
386 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
387 info->locked ? "" : "not ",
388 info->tray_open ? "open" : "closed");
397 monitor_printf(mon, " Cache mode: %s%s%s\n",
398 inserted->cache->writeback ? "writeback" : "writethrough",
399 inserted->cache->direct ? ", direct" : "",
400 inserted->cache->no_flush ? ", ignore flushes" : "");
402 if (inserted->has_backing_file) {
405 "(chain depth: %" PRId64 ")\n",
406 inserted->backing_file,
407 inserted->backing_file_depth);
410 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
411 monitor_printf(mon, " Detect zeroes: %s\n",
412 BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]);
415 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
416 inserted->iops || inserted->iops_rd || inserted->iops_wr)
418 monitor_printf(mon, " I/O throttling: bps=%" PRId64
419 " bps_rd=%" PRId64 " bps_wr=%" PRId64
421 " bps_rd_max=%" PRId64
422 " bps_wr_max=%" PRId64
423 " iops=%" PRId64 " iops_rd=%" PRId64
426 " iops_rd_max=%" PRId64
427 " iops_wr_max=%" PRId64
428 " iops_size=%" PRId64
434 inserted->bps_rd_max,
435 inserted->bps_wr_max,
440 inserted->iops_rd_max,
441 inserted->iops_wr_max,
447 monitor_printf(mon, "\nImages:\n");
448 image_info = inserted->image;
450 bdrv_image_info_dump((fprintf_function)monitor_printf,
452 if (image_info->has_backing_image) {
453 image_info = image_info->backing_image;
461 void hmp_info_block(Monitor *mon, const QDict *qdict)
463 BlockInfoList *block_list, *info;
464 BlockDeviceInfoList *blockdev_list, *blockdev;
465 const char *device = qdict_get_try_str(qdict, "device");
466 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
467 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
468 bool printed = false;
470 /* Print BlockBackend information */
472 block_list = qmp_query_block(NULL);
477 for (info = block_list; info; info = info->next) {
478 if (device && strcmp(device, info->value->device)) {
482 if (info != block_list) {
483 monitor_printf(mon, "\n");
486 print_block_info(mon, info->value, info->value->has_inserted
487 ? info->value->inserted : NULL,
492 qapi_free_BlockInfoList(block_list);
494 if ((!device && !nodes) || printed) {
498 /* Print node information */
499 blockdev_list = qmp_query_named_block_nodes(NULL);
500 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
501 assert(blockdev->value->has_node_name);
502 if (device && strcmp(device, blockdev->value->node_name)) {
506 if (blockdev != blockdev_list) {
507 monitor_printf(mon, "\n");
510 print_block_info(mon, NULL, blockdev->value, verbose);
512 qapi_free_BlockDeviceInfoList(blockdev_list);
515 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
517 BlockStatsList *stats_list, *stats;
519 stats_list = qmp_query_blockstats(false, false, NULL);
521 for (stats = stats_list; stats; stats = stats->next) {
522 if (!stats->value->has_device) {
526 monitor_printf(mon, "%s:", stats->value->device);
527 monitor_printf(mon, " rd_bytes=%" PRId64
529 " rd_operations=%" PRId64
530 " wr_operations=%" PRId64
531 " flush_operations=%" PRId64
532 " wr_total_time_ns=%" PRId64
533 " rd_total_time_ns=%" PRId64
534 " flush_total_time_ns=%" PRId64
535 " rd_merged=%" PRId64
536 " wr_merged=%" PRId64
537 " idle_time_ns=%" PRId64
539 stats->value->stats->rd_bytes,
540 stats->value->stats->wr_bytes,
541 stats->value->stats->rd_operations,
542 stats->value->stats->wr_operations,
543 stats->value->stats->flush_operations,
544 stats->value->stats->wr_total_time_ns,
545 stats->value->stats->rd_total_time_ns,
546 stats->value->stats->flush_total_time_ns,
547 stats->value->stats->rd_merged,
548 stats->value->stats->wr_merged,
549 stats->value->stats->idle_time_ns);
552 qapi_free_BlockStatsList(stats_list);
555 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
559 VncClientInfoList *client;
561 info = qmp_query_vnc(&err);
563 error_report_err(err);
567 if (!info->enabled) {
568 monitor_printf(mon, "Server: disabled\n");
572 monitor_printf(mon, "Server:\n");
573 if (info->has_host && info->has_service) {
574 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
576 if (info->has_auth) {
577 monitor_printf(mon, " auth: %s\n", info->auth);
580 if (!info->has_clients || info->clients == NULL) {
581 monitor_printf(mon, "Client: none\n");
583 for (client = info->clients; client; client = client->next) {
584 monitor_printf(mon, "Client:\n");
585 monitor_printf(mon, " address: %s:%s\n",
587 client->value->service);
588 monitor_printf(mon, " x509_dname: %s\n",
589 client->value->x509_dname ?
590 client->value->x509_dname : "none");
591 monitor_printf(mon, " username: %s\n",
592 client->value->has_sasl_username ?
593 client->value->sasl_username : "none");
598 qapi_free_VncInfo(info);
602 void hmp_info_spice(Monitor *mon, const QDict *qdict)
604 SpiceChannelList *chan;
606 const char *channel_name;
607 const char * const channel_names[] = {
608 [SPICE_CHANNEL_MAIN] = "main",
609 [SPICE_CHANNEL_DISPLAY] = "display",
610 [SPICE_CHANNEL_INPUTS] = "inputs",
611 [SPICE_CHANNEL_CURSOR] = "cursor",
612 [SPICE_CHANNEL_PLAYBACK] = "playback",
613 [SPICE_CHANNEL_RECORD] = "record",
614 [SPICE_CHANNEL_TUNNEL] = "tunnel",
615 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
616 [SPICE_CHANNEL_USBREDIR] = "usbredir",
617 [SPICE_CHANNEL_PORT] = "port",
619 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
620 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
621 * as quick fix for build failures with older versions. */
622 [SPICE_CHANNEL_WEBDAV] = "webdav",
626 info = qmp_query_spice(NULL);
628 if (!info->enabled) {
629 monitor_printf(mon, "Server: disabled\n");
633 monitor_printf(mon, "Server:\n");
634 if (info->has_port) {
635 monitor_printf(mon, " address: %s:%" PRId64 "\n",
636 info->host, info->port);
638 if (info->has_tls_port) {
639 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
640 info->host, info->tls_port);
642 monitor_printf(mon, " migrated: %s\n",
643 info->migrated ? "true" : "false");
644 monitor_printf(mon, " auth: %s\n", info->auth);
645 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
646 monitor_printf(mon, " mouse-mode: %s\n",
647 SpiceQueryMouseMode_lookup[info->mouse_mode]);
649 if (!info->has_channels || info->channels == NULL) {
650 monitor_printf(mon, "Channels: none\n");
652 for (chan = info->channels; chan; chan = chan->next) {
653 monitor_printf(mon, "Channel:\n");
654 monitor_printf(mon, " address: %s:%s%s\n",
655 chan->value->host, chan->value->port,
656 chan->value->tls ? " [tls]" : "");
657 monitor_printf(mon, " session: %" PRId64 "\n",
658 chan->value->connection_id);
659 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
660 chan->value->channel_type, chan->value->channel_id);
662 channel_name = "unknown";
663 if (chan->value->channel_type > 0 &&
664 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
665 channel_names[chan->value->channel_type]) {
666 channel_name = channel_names[chan->value->channel_type];
669 monitor_printf(mon, " channel name: %s\n", channel_name);
674 qapi_free_SpiceInfo(info);
678 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
683 info = qmp_query_balloon(&err);
685 error_report_err(err);
689 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
691 qapi_free_BalloonInfo(info);
694 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
696 PciMemoryRegionList *region;
698 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
699 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
700 dev->slot, dev->function);
701 monitor_printf(mon, " ");
703 if (dev->class_info->has_desc) {
704 monitor_printf(mon, "%s", dev->class_info->desc);
706 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
709 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
710 dev->id->vendor, dev->id->device);
713 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
716 if (dev->has_pci_bridge) {
717 monitor_printf(mon, " BUS %" PRId64 ".\n",
718 dev->pci_bridge->bus->number);
719 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
720 dev->pci_bridge->bus->secondary);
721 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
722 dev->pci_bridge->bus->subordinate);
724 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
725 dev->pci_bridge->bus->io_range->base,
726 dev->pci_bridge->bus->io_range->limit);
729 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
730 dev->pci_bridge->bus->memory_range->base,
731 dev->pci_bridge->bus->memory_range->limit);
733 monitor_printf(mon, " prefetchable memory range "
734 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
735 dev->pci_bridge->bus->prefetchable_range->base,
736 dev->pci_bridge->bus->prefetchable_range->limit);
739 for (region = dev->regions; region; region = region->next) {
742 addr = region->value->address;
743 size = region->value->size;
745 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
747 if (!strcmp(region->value->type, "io")) {
748 monitor_printf(mon, "I/O at 0x%04" PRIx64
749 " [0x%04" PRIx64 "].\n",
750 addr, addr + size - 1);
752 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
753 " [0x%08" PRIx64 "].\n",
754 region->value->mem_type_64 ? 64 : 32,
755 region->value->prefetch ? " prefetchable" : "",
756 addr, addr + size - 1);
760 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
762 if (dev->has_pci_bridge) {
763 if (dev->pci_bridge->has_devices) {
764 PciDeviceInfoList *cdev;
765 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
766 hmp_info_pci_device(mon, cdev->value);
772 void hmp_info_pci(Monitor *mon, const QDict *qdict)
774 PciInfoList *info_list, *info;
777 info_list = qmp_query_pci(&err);
779 monitor_printf(mon, "PCI devices not supported\n");
784 for (info = info_list; info; info = info->next) {
785 PciDeviceInfoList *dev;
787 for (dev = info->value->devices; dev; dev = dev->next) {
788 hmp_info_pci_device(mon, dev->value);
792 qapi_free_PciInfoList(info_list);
795 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
797 BlockJobInfoList *list;
800 list = qmp_query_block_jobs(&err);
804 monitor_printf(mon, "No active jobs\n");
809 if (strcmp(list->value->type, "stream") == 0) {
810 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
811 " of %" PRId64 " bytes, speed limit %" PRId64
818 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
819 " of %" PRId64 " bytes, speed limit %" PRId64
830 qapi_free_BlockJobInfoList(list);
833 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
835 TPMInfoList *info_list, *info;
838 TPMPassthroughOptions *tpo;
840 info_list = qmp_query_tpm(&err);
842 monitor_printf(mon, "TPM device not supported\n");
848 monitor_printf(mon, "TPM device:\n");
851 for (info = info_list; info; info = info->next) {
852 TPMInfo *ti = info->value;
853 monitor_printf(mon, " tpm%d: model=%s\n",
854 c, TpmModel_lookup[ti->model]);
856 monitor_printf(mon, " \\ %s: type=%s",
857 ti->id, TpmTypeOptionsKind_lookup[ti->options->type]);
859 switch (ti->options->type) {
860 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
861 tpo = ti->options->u.passthrough.data;
862 monitor_printf(mon, "%s%s%s%s",
863 tpo->has_path ? ",path=" : "",
864 tpo->has_path ? tpo->path : "",
865 tpo->has_cancel_path ? ",cancel-path=" : "",
866 tpo->has_cancel_path ? tpo->cancel_path : "");
868 case TPM_TYPE_OPTIONS_KIND__MAX:
871 monitor_printf(mon, "\n");
874 qapi_free_TPMInfoList(info_list);
877 void hmp_quit(Monitor *mon, const QDict *qdict)
879 monitor_suspend(mon);
883 void hmp_stop(Monitor *mon, const QDict *qdict)
888 void hmp_system_reset(Monitor *mon, const QDict *qdict)
890 qmp_system_reset(NULL);
893 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
895 qmp_system_powerdown(NULL);
898 void hmp_cpu(Monitor *mon, const QDict *qdict)
902 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
903 use it are converted to the QAPI */
904 cpu_index = qdict_get_int(qdict, "index");
905 if (monitor_set_cpu(cpu_index) < 0) {
906 monitor_printf(mon, "invalid CPU index\n");
910 void hmp_memsave(Monitor *mon, const QDict *qdict)
912 uint32_t size = qdict_get_int(qdict, "size");
913 const char *filename = qdict_get_str(qdict, "filename");
914 uint64_t addr = qdict_get_int(qdict, "val");
917 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &err);
918 hmp_handle_error(mon, &err);
921 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
923 uint32_t size = qdict_get_int(qdict, "size");
924 const char *filename = qdict_get_str(qdict, "filename");
925 uint64_t addr = qdict_get_int(qdict, "val");
928 qmp_pmemsave(addr, size, filename, &err);
929 hmp_handle_error(mon, &err);
932 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
934 const char *chardev = qdict_get_str(qdict, "device");
935 const char *data = qdict_get_str(qdict, "data");
938 qmp_ringbuf_write(chardev, data, false, 0, &err);
940 hmp_handle_error(mon, &err);
943 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
945 uint32_t size = qdict_get_int(qdict, "size");
946 const char *chardev = qdict_get_str(qdict, "device");
951 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
953 error_report_err(err);
957 for (i = 0; data[i]; i++) {
958 unsigned char ch = data[i];
961 monitor_printf(mon, "\\\\");
962 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
963 monitor_printf(mon, "\\u%04X", ch);
965 monitor_printf(mon, "%c", ch);
969 monitor_printf(mon, "\n");
973 static void hmp_cont_cb(void *opaque, int err)
980 static bool key_is_missing(const BlockInfo *bdev)
982 return (bdev->inserted && bdev->inserted->encryption_key_missing);
985 void hmp_cont(Monitor *mon, const QDict *qdict)
987 BlockInfoList *bdev_list, *bdev;
990 bdev_list = qmp_query_block(NULL);
991 for (bdev = bdev_list; bdev; bdev = bdev->next) {
992 if (key_is_missing(bdev->value)) {
993 monitor_read_block_device_key(mon, bdev->value->device,
1000 hmp_handle_error(mon, &err);
1003 qapi_free_BlockInfoList(bdev_list);
1006 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1008 qmp_system_wakeup(NULL);
1011 void hmp_nmi(Monitor *mon, const QDict *qdict)
1015 qmp_inject_nmi(&err);
1016 hmp_handle_error(mon, &err);
1019 void hmp_set_link(Monitor *mon, const QDict *qdict)
1021 const char *name = qdict_get_str(qdict, "name");
1022 bool up = qdict_get_bool(qdict, "up");
1025 qmp_set_link(name, up, &err);
1026 hmp_handle_error(mon, &err);
1029 #if defined(CONFIG_MARU)
1030 void hmp_get_link(Monitor *mon, const QDict *qdict)
1032 const char *name = qdict_get_str(qdict, "name");
1035 info = qmp_get_link(name, &errp);
1037 hmp_handle_error(mon, &errp);
1041 monitor_printf(mon, "%s\n", info->is_up ? "on": "off");
1046 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1048 const char *device = qdict_get_str(qdict, "device");
1049 const char *password = qdict_get_str(qdict, "password");
1052 qmp_block_passwd(true, device, false, NULL, password, &err);
1053 hmp_handle_error(mon, &err);
1056 void hmp_balloon(Monitor *mon, const QDict *qdict)
1058 int64_t value = qdict_get_int(qdict, "value");
1061 qmp_balloon(value, &err);
1063 error_report_err(err);
1067 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1069 const char *device = qdict_get_str(qdict, "device");
1070 int64_t size = qdict_get_int(qdict, "size");
1073 qmp_block_resize(true, device, false, NULL, size, &err);
1074 hmp_handle_error(mon, &err);
1077 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1079 const char *device = qdict_get_str(qdict, "device");
1080 const char *filename = qdict_get_str(qdict, "target");
1081 const char *format = qdict_get_try_str(qdict, "format");
1082 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1083 bool full = qdict_get_try_bool(qdict, "full", false);
1084 enum NewImageMode mode;
1088 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1089 hmp_handle_error(mon, &err);
1094 mode = NEW_IMAGE_MODE_EXISTING;
1096 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1099 qmp_drive_mirror(device, filename, !!format, format,
1100 false, NULL, false, NULL,
1101 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1102 true, mode, false, 0, false, 0, false, 0,
1103 false, 0, false, 0, false, true, &err);
1104 hmp_handle_error(mon, &err);
1107 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1109 const char *device = qdict_get_str(qdict, "device");
1110 const char *filename = qdict_get_str(qdict, "target");
1111 const char *format = qdict_get_try_str(qdict, "format");
1112 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1113 bool full = qdict_get_try_bool(qdict, "full", false);
1114 enum NewImageMode mode;
1118 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1119 hmp_handle_error(mon, &err);
1124 mode = NEW_IMAGE_MODE_EXISTING;
1126 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1129 qmp_drive_backup(device, filename, !!format, format,
1130 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1131 true, mode, false, 0, false, NULL,
1132 false, 0, false, 0, &err);
1133 hmp_handle_error(mon, &err);
1136 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1138 const char *device = qdict_get_str(qdict, "device");
1139 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1140 const char *format = qdict_get_try_str(qdict, "format");
1141 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1142 enum NewImageMode mode;
1146 /* In the future, if 'snapshot-file' is not specified, the snapshot
1147 will be taken internally. Today it's actually required. */
1148 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1149 hmp_handle_error(mon, &err);
1153 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1154 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1155 filename, false, NULL,
1158 hmp_handle_error(mon, &err);
1161 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1163 const char *device = qdict_get_str(qdict, "device");
1164 const char *name = qdict_get_str(qdict, "name");
1167 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1168 hmp_handle_error(mon, &err);
1171 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1173 const char *device = qdict_get_str(qdict, "device");
1174 const char *name = qdict_get_str(qdict, "name");
1175 const char *id = qdict_get_try_str(qdict, "id");
1178 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1180 hmp_handle_error(mon, &err);
1183 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1185 qmp_migrate_cancel(NULL);
1188 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1191 const char *uri = qdict_get_str(qdict, "uri");
1193 qmp_migrate_incoming(uri, &err);
1195 hmp_handle_error(mon, &err);
1198 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1200 double value = qdict_get_double(qdict, "value");
1201 qmp_migrate_set_downtime(value, NULL);
1204 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1206 int64_t value = qdict_get_int(qdict, "value");
1209 qmp_migrate_set_cache_size(value, &err);
1211 error_report_err(err);
1216 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1218 int64_t value = qdict_get_int(qdict, "value");
1219 qmp_migrate_set_speed(value, NULL);
1222 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1224 const char *cap = qdict_get_str(qdict, "capability");
1225 bool state = qdict_get_bool(qdict, "state");
1227 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1230 for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
1231 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1232 caps->value = g_malloc0(sizeof(*caps->value));
1233 caps->value->capability = i;
1234 caps->value->state = state;
1236 qmp_migrate_set_capabilities(caps, &err);
1241 if (i == MIGRATION_CAPABILITY__MAX) {
1242 error_setg(&err, QERR_INVALID_PARAMETER, cap);
1245 qapi_free_MigrationCapabilityStatusList(caps);
1248 error_report_err(err);
1252 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1254 const char *param = qdict_get_str(qdict, "parameter");
1255 int value = qdict_get_int(qdict, "value");
1257 bool has_compress_level = false;
1258 bool has_compress_threads = false;
1259 bool has_decompress_threads = false;
1260 bool has_x_cpu_throttle_initial = false;
1261 bool has_x_cpu_throttle_increment = false;
1264 for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
1265 if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
1267 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1268 has_compress_level = true;
1270 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1271 has_compress_threads = true;
1273 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1274 has_decompress_threads = true;
1276 case MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL:
1277 has_x_cpu_throttle_initial = true;
1279 case MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT:
1280 has_x_cpu_throttle_increment = true;
1283 qmp_migrate_set_parameters(has_compress_level, value,
1284 has_compress_threads, value,
1285 has_decompress_threads, value,
1286 has_x_cpu_throttle_initial, value,
1287 has_x_cpu_throttle_increment, value,
1293 if (i == MIGRATION_PARAMETER__MAX) {
1294 error_setg(&err, QERR_INVALID_PARAMETER, param);
1298 error_report_err(err);
1302 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1305 const char *protocol = qdict_get_str(qdict, "protocol");
1306 const char *hostname = qdict_get_str(qdict, "hostname");
1307 bool has_port = qdict_haskey(qdict, "port");
1308 int port = qdict_get_try_int(qdict, "port", -1);
1309 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1310 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1311 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1313 qmp_client_migrate_info(protocol, hostname,
1314 has_port, port, has_tls_port, tls_port,
1315 !!cert_subject, cert_subject, &err);
1316 hmp_handle_error(mon, &err);
1319 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1322 qmp_migrate_start_postcopy(&err);
1323 hmp_handle_error(mon, &err);
1326 void hmp_set_password(Monitor *mon, const QDict *qdict)
1328 const char *protocol = qdict_get_str(qdict, "protocol");
1329 const char *password = qdict_get_str(qdict, "password");
1330 const char *connected = qdict_get_try_str(qdict, "connected");
1333 qmp_set_password(protocol, password, !!connected, connected, &err);
1334 hmp_handle_error(mon, &err);
1337 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1339 const char *protocol = qdict_get_str(qdict, "protocol");
1340 const char *whenstr = qdict_get_str(qdict, "time");
1343 qmp_expire_password(protocol, whenstr, &err);
1344 hmp_handle_error(mon, &err);
1347 void hmp_eject(Monitor *mon, const QDict *qdict)
1349 bool force = qdict_get_try_bool(qdict, "force", false);
1350 const char *device = qdict_get_str(qdict, "device");
1353 qmp_eject(device, true, force, &err);
1354 hmp_handle_error(mon, &err);
1357 static void hmp_change_read_arg(void *opaque, const char *password,
1358 void *readline_opaque)
1360 qmp_change_vnc_password(password, NULL);
1361 monitor_read_command(opaque, 1);
1364 void hmp_change(Monitor *mon, const QDict *qdict)
1366 const char *device = qdict_get_str(qdict, "device");
1367 const char *target = qdict_get_str(qdict, "target");
1368 const char *arg = qdict_get_try_str(qdict, "arg");
1369 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1370 BlockdevChangeReadOnlyMode read_only_mode = 0;
1373 if (strcmp(device, "vnc") == 0) {
1376 "Parameter 'read-only-mode' is invalid for VNC\n");
1379 if (strcmp(target, "passwd") == 0 ||
1380 strcmp(target, "password") == 0) {
1382 monitor_read_password(mon, hmp_change_read_arg, NULL);
1386 qmp_change("vnc", target, !!arg, arg, &err);
1390 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup,
1391 read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX,
1392 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1394 hmp_handle_error(mon, &err);
1399 qmp_blockdev_change_medium(device, target, !!arg, arg,
1400 !!read_only, read_only_mode, &err);
1402 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
1404 monitor_read_block_device_key(mon, device, NULL, NULL);
1409 hmp_handle_error(mon, &err);
1412 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1416 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
1417 qdict_get_int(qdict, "bps"),
1418 qdict_get_int(qdict, "bps_rd"),
1419 qdict_get_int(qdict, "bps_wr"),
1420 qdict_get_int(qdict, "iops"),
1421 qdict_get_int(qdict, "iops_rd"),
1422 qdict_get_int(qdict, "iops_wr"),
1423 false, /* no burst max via HMP */
1435 false, /* no burst length via HMP */
1447 false, /* No default I/O size */
1451 hmp_handle_error(mon, &err);
1454 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1456 Error *error = NULL;
1457 const char *device = qdict_get_str(qdict, "device");
1458 const char *base = qdict_get_try_str(qdict, "base");
1459 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1461 qmp_block_stream(device, base != NULL, base, false, NULL,
1462 qdict_haskey(qdict, "speed"), speed,
1463 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1465 hmp_handle_error(mon, &error);
1468 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1470 Error *error = NULL;
1471 const char *device = qdict_get_str(qdict, "device");
1472 int64_t value = qdict_get_int(qdict, "speed");
1474 qmp_block_job_set_speed(device, value, &error);
1476 hmp_handle_error(mon, &error);
1479 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1481 Error *error = NULL;
1482 const char *device = qdict_get_str(qdict, "device");
1483 bool force = qdict_get_try_bool(qdict, "force", false);
1485 qmp_block_job_cancel(device, true, force, &error);
1487 hmp_handle_error(mon, &error);
1490 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1492 Error *error = NULL;
1493 const char *device = qdict_get_str(qdict, "device");
1495 qmp_block_job_pause(device, &error);
1497 hmp_handle_error(mon, &error);
1500 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1502 Error *error = NULL;
1503 const char *device = qdict_get_str(qdict, "device");
1505 qmp_block_job_resume(device, &error);
1507 hmp_handle_error(mon, &error);
1510 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1512 Error *error = NULL;
1513 const char *device = qdict_get_str(qdict, "device");
1515 qmp_block_job_complete(device, &error);
1517 hmp_handle_error(mon, &error);
1520 typedef struct HMPMigrationStatus
1524 bool is_block_migration;
1525 } HMPMigrationStatus;
1527 static void hmp_migrate_status_cb(void *opaque)
1529 HMPMigrationStatus *status = opaque;
1530 MigrationInfo *info;
1532 info = qmp_query_migrate(NULL);
1533 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1534 info->status == MIGRATION_STATUS_SETUP) {
1535 if (info->has_disk) {
1538 if (info->disk->remaining) {
1539 progress = info->disk->transferred * 100 / info->disk->total;
1544 monitor_printf(status->mon, "Completed %d %%\r", progress);
1545 monitor_flush(status->mon);
1548 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1550 if (status->is_block_migration) {
1551 monitor_printf(status->mon, "\n");
1553 monitor_resume(status->mon);
1554 timer_del(status->timer);
1558 qapi_free_MigrationInfo(info);
1561 void hmp_migrate(Monitor *mon, const QDict *qdict)
1563 bool detach = qdict_get_try_bool(qdict, "detach", false);
1564 bool blk = qdict_get_try_bool(qdict, "blk", false);
1565 bool inc = qdict_get_try_bool(qdict, "inc", false);
1566 const char *uri = qdict_get_str(qdict, "uri");
1569 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1571 error_report_err(err);
1576 HMPMigrationStatus *status;
1578 if (monitor_suspend(mon) < 0) {
1579 monitor_printf(mon, "terminal does not allow synchronous "
1580 "migration, continuing detached\n");
1584 status = g_malloc0(sizeof(*status));
1586 status->is_block_migration = blk || inc;
1587 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1589 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1593 void hmp_device_add(Monitor *mon, const QDict *qdict)
1597 qmp_device_add((QDict *)qdict, NULL, &err);
1598 hmp_handle_error(mon, &err);
1601 void hmp_device_del(Monitor *mon, const QDict *qdict)
1603 const char *id = qdict_get_str(qdict, "id");
1606 qmp_device_del(id, &err);
1607 hmp_handle_error(mon, &err);
1610 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1613 bool paging = qdict_get_try_bool(qdict, "paging", false);
1614 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
1615 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
1616 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
1617 const char *file = qdict_get_str(qdict, "filename");
1618 bool has_begin = qdict_haskey(qdict, "begin");
1619 bool has_length = qdict_haskey(qdict, "length");
1620 bool has_detach = qdict_haskey(qdict, "detach");
1623 bool detach = false;
1624 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1627 if (zlib + lzo + snappy > 1) {
1628 error_setg(&err, "only one of '-z|-l|-s' can be set");
1629 hmp_handle_error(mon, &err);
1634 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1638 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1642 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1646 begin = qdict_get_int(qdict, "begin");
1649 length = qdict_get_int(qdict, "length");
1652 detach = qdict_get_bool(qdict, "detach");
1655 prot = g_strconcat("file:", file, NULL);
1657 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
1658 has_length, length, true, dump_format, &err);
1659 hmp_handle_error(mon, &err);
1663 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1668 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1673 netdev_add(opts, &err);
1675 qemu_opts_del(opts);
1679 hmp_handle_error(mon, &err);
1682 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1684 const char *id = qdict_get_str(qdict, "id");
1687 qmp_netdev_del(id, &err);
1688 hmp_handle_error(mon, &err);
1691 void hmp_object_add(Monitor *mon, const QDict *qdict)
1698 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1700 hmp_handle_error(mon, &err);
1704 ov = opts_visitor_new(opts);
1705 obj = user_creatable_add(qdict, opts_get_visitor(ov), &err);
1706 opts_visitor_cleanup(ov);
1707 qemu_opts_del(opts);
1710 hmp_handle_error(mon, &err);
1717 void hmp_getfd(Monitor *mon, const QDict *qdict)
1719 const char *fdname = qdict_get_str(qdict, "fdname");
1722 qmp_getfd(fdname, &err);
1723 hmp_handle_error(mon, &err);
1726 void hmp_closefd(Monitor *mon, const QDict *qdict)
1728 const char *fdname = qdict_get_str(qdict, "fdname");
1731 qmp_closefd(fdname, &err);
1732 hmp_handle_error(mon, &err);
1735 void hmp_sendkey(Monitor *mon, const QDict *qdict)
1737 const char *keys = qdict_get_str(qdict, "keys");
1738 KeyValueList *keylist, *head = NULL, *tmp = NULL;
1739 int has_hold_time = qdict_haskey(qdict, "hold-time");
1740 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1746 separator = strchr(keys, '-');
1747 keyname_len = separator ? separator - keys : strlen(keys);
1749 /* Be compatible with old interface, convert user inputted "<" */
1750 if (keys[0] == '<' && keyname_len == 1) {
1755 keylist = g_malloc0(sizeof(*keylist));
1756 keylist->value = g_malloc0(sizeof(*keylist->value));
1762 tmp->next = keylist;
1766 if (strstart(keys, "0x", NULL)) {
1768 int value = strtoul(keys, &endp, 0);
1769 assert(endp <= keys + keyname_len);
1770 if (endp != keys + keyname_len) {
1773 keylist->value->type = KEY_VALUE_KIND_NUMBER;
1774 keylist->value->u.number.data = value;
1776 int idx = index_from_key(keys, keyname_len);
1777 if (idx == Q_KEY_CODE__MAX) {
1780 keylist->value->type = KEY_VALUE_KIND_QCODE;
1781 keylist->value->u.qcode.data = idx;
1787 keys = separator + 1;
1790 qmp_send_key(head, has_hold_time, hold_time, &err);
1791 hmp_handle_error(mon, &err);
1794 qapi_free_KeyValueList(head);
1798 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
1802 void hmp_screendump(Monitor *mon, const QDict *qdict)
1804 const char *filename = qdict_get_str(qdict, "filename");
1807 qmp_screendump(filename, &err);
1808 hmp_handle_error(mon, &err);
1811 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1813 const char *uri = qdict_get_str(qdict, "uri");
1814 bool writable = qdict_get_try_bool(qdict, "writable", false);
1815 bool all = qdict_get_try_bool(qdict, "all", false);
1816 Error *local_err = NULL;
1817 BlockInfoList *block_list, *info;
1818 SocketAddress *addr;
1820 if (writable && !all) {
1821 error_setg(&local_err, "-w only valid together with -a");
1825 /* First check if the address is valid and start the server. */
1826 addr = socket_parse(uri, &local_err);
1827 if (local_err != NULL) {
1831 qmp_nbd_server_start(addr, false, NULL, &local_err);
1832 qapi_free_SocketAddress(addr);
1833 if (local_err != NULL) {
1841 /* Then try adding all block devices. If one fails, close all and
1844 block_list = qmp_query_block(NULL);
1846 for (info = block_list; info; info = info->next) {
1847 if (!info->value->has_inserted) {
1851 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1853 if (local_err != NULL) {
1854 qmp_nbd_server_stop(NULL);
1859 qapi_free_BlockInfoList(block_list);
1862 hmp_handle_error(mon, &local_err);
1865 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1867 const char *device = qdict_get_str(qdict, "device");
1868 bool writable = qdict_get_try_bool(qdict, "writable", false);
1869 Error *local_err = NULL;
1871 qmp_nbd_server_add(device, true, writable, &local_err);
1873 if (local_err != NULL) {
1874 hmp_handle_error(mon, &local_err);
1878 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1882 qmp_nbd_server_stop(&err);
1883 hmp_handle_error(mon, &err);
1886 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
1891 cpuid = qdict_get_int(qdict, "id");
1892 qmp_cpu_add(cpuid, &err);
1893 hmp_handle_error(mon, &err);
1896 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1898 const char *args = qdict_get_str(qdict, "args");
1902 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
1904 error_setg(&err, "Parsing chardev args failed");
1906 qemu_chr_new_from_opts(opts, NULL, &err);
1908 hmp_handle_error(mon, &err);
1911 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1913 Error *local_err = NULL;
1915 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1916 hmp_handle_error(mon, &local_err);
1919 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1922 const char* device = qdict_get_str(qdict, "device");
1923 const char* command = qdict_get_str(qdict, "command");
1926 blk = blk_by_name(device);
1928 qemuio_command(blk, command);
1930 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
1931 "Device '%s' not found", device);
1934 hmp_handle_error(mon, &err);
1937 void hmp_object_del(Monitor *mon, const QDict *qdict)
1939 const char *id = qdict_get_str(qdict, "id");
1942 user_creatable_del(id, &err);
1943 hmp_handle_error(mon, &err);
1946 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
1949 MemdevList *memdev_list = qmp_query_memdev(&err);
1950 MemdevList *m = memdev_list;
1951 StringOutputVisitor *ov;
1957 ov = string_output_visitor_new(false);
1958 visit_type_uint16List(string_output_get_visitor(ov), NULL,
1959 &m->value->host_nodes, NULL);
1960 monitor_printf(mon, "memory backend: %d\n", i);
1961 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
1962 monitor_printf(mon, " merge: %s\n",
1963 m->value->merge ? "true" : "false");
1964 monitor_printf(mon, " dump: %s\n",
1965 m->value->dump ? "true" : "false");
1966 monitor_printf(mon, " prealloc: %s\n",
1967 m->value->prealloc ? "true" : "false");
1968 monitor_printf(mon, " policy: %s\n",
1969 HostMemPolicy_lookup[m->value->policy]);
1970 str = string_output_get_string(ov);
1971 monitor_printf(mon, " host nodes: %s\n", str);
1974 string_output_visitor_cleanup(ov);
1979 monitor_printf(mon, "\n");
1981 qapi_free_MemdevList(memdev_list);
1984 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
1987 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
1988 MemoryDeviceInfoList *info;
1989 MemoryDeviceInfo *value;
1990 PCDIMMDeviceInfo *di;
1992 for (info = info_list; info; info = info->next) {
1993 value = info->value;
1996 switch (value->type) {
1997 case MEMORY_DEVICE_INFO_KIND_DIMM:
1998 di = value->u.dimm.data;
2000 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2001 MemoryDeviceInfoKind_lookup[value->type],
2002 di->id ? di->id : "");
2003 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2004 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2005 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2006 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2007 monitor_printf(mon, " memdev: %s\n", di->memdev);
2008 monitor_printf(mon, " hotplugged: %s\n",
2009 di->hotplugged ? "true" : "false");
2010 monitor_printf(mon, " hotpluggable: %s\n",
2011 di->hotpluggable ? "true" : "false");
2019 qapi_free_MemoryDeviceInfoList(info_list);
2022 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2024 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2025 IOThreadInfoList *info;
2027 for (info = info_list; info; info = info->next) {
2028 monitor_printf(mon, "%s: thread_id=%" PRId64 "\n",
2029 info->value->id, info->value->thread_id);
2032 qapi_free_IOThreadInfoList(info_list);
2035 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2037 const char *path = qdict_get_try_str(qdict, "path");
2038 ObjectPropertyInfoList *list;
2042 monitor_printf(mon, "/\n");
2046 list = qmp_qom_list(path, &err);
2048 ObjectPropertyInfoList *start = list;
2049 while (list != NULL) {
2050 ObjectPropertyInfo *value = list->value;
2052 monitor_printf(mon, "%s (%s)\n",
2053 value->name, value->type);
2056 qapi_free_ObjectPropertyInfoList(start);
2058 hmp_handle_error(mon, &err);
2061 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2063 const char *path = qdict_get_str(qdict, "path");
2064 const char *property = qdict_get_str(qdict, "property");
2065 const char *value = qdict_get_str(qdict, "value");
2067 bool ambiguous = false;
2070 obj = object_resolve_path(path, &ambiguous);
2072 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2073 "Device '%s' not found", path);
2076 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2078 object_property_parse(obj, value, property, &err);
2080 hmp_handle_error(mon, &err);
2083 void hmp_rocker(Monitor *mon, const QDict *qdict)
2085 const char *name = qdict_get_str(qdict, "name");
2086 RockerSwitch *rocker;
2089 rocker = qmp_query_rocker(name, &err);
2091 hmp_handle_error(mon, &err);
2095 monitor_printf(mon, "name: %s\n", rocker->name);
2096 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2097 monitor_printf(mon, "ports: %d\n", rocker->ports);
2099 qapi_free_RockerSwitch(rocker);
2102 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2104 RockerPortList *list, *port;
2105 const char *name = qdict_get_str(qdict, "name");
2108 list = qmp_query_rocker_ports(name, &err);
2110 hmp_handle_error(mon, &err);
2114 monitor_printf(mon, " ena/ speed/ auto\n");
2115 monitor_printf(mon, " port link duplex neg?\n");
2117 for (port = list; port; port = port->next) {
2118 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2120 port->value->enabled ? port->value->link_up ?
2121 "up" : "down" : "!ena",
2122 port->value->speed == 10000 ? "10G" : "??",
2123 port->value->duplex ? "FD" : "HD",
2124 port->value->autoneg ? "Yes" : "No");
2127 qapi_free_RockerPortList(list);
2130 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2132 RockerOfDpaFlowList *list, *info;
2133 const char *name = qdict_get_str(qdict, "name");
2134 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2137 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2139 hmp_handle_error(mon, &err);
2143 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2145 for (info = list; info; info = info->next) {
2146 RockerOfDpaFlow *flow = info->value;
2147 RockerOfDpaFlowKey *key = flow->key;
2148 RockerOfDpaFlowMask *mask = flow->mask;
2149 RockerOfDpaFlowAction *action = flow->action;
2152 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2153 key->priority, key->tbl_id, flow->hits);
2155 monitor_printf(mon, "%-4d %-3d ",
2156 key->priority, key->tbl_id);
2159 if (key->has_in_pport) {
2160 monitor_printf(mon, " pport %d", key->in_pport);
2161 if (mask->has_in_pport) {
2162 monitor_printf(mon, "(0x%x)", mask->in_pport);
2166 if (key->has_vlan_id) {
2167 monitor_printf(mon, " vlan %d",
2168 key->vlan_id & VLAN_VID_MASK);
2169 if (mask->has_vlan_id) {
2170 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2174 if (key->has_tunnel_id) {
2175 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2176 if (mask->has_tunnel_id) {
2177 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2181 if (key->has_eth_type) {
2182 switch (key->eth_type) {
2184 monitor_printf(mon, " ARP");
2187 monitor_printf(mon, " IP");
2190 monitor_printf(mon, " IPv6");
2193 monitor_printf(mon, " LACP");
2196 monitor_printf(mon, " LLDP");
2199 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2204 if (key->has_eth_src) {
2205 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2206 (mask->has_eth_src) &&
2207 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2208 monitor_printf(mon, " src <any mcast/bcast>");
2209 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2210 (mask->has_eth_src) &&
2211 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2212 monitor_printf(mon, " src <any ucast>");
2214 monitor_printf(mon, " src %s", key->eth_src);
2215 if (mask->has_eth_src) {
2216 monitor_printf(mon, "(%s)", mask->eth_src);
2221 if (key->has_eth_dst) {
2222 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2223 (mask->has_eth_dst) &&
2224 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2225 monitor_printf(mon, " dst <any mcast/bcast>");
2226 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2227 (mask->has_eth_dst) &&
2228 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2229 monitor_printf(mon, " dst <any ucast>");
2231 monitor_printf(mon, " dst %s", key->eth_dst);
2232 if (mask->has_eth_dst) {
2233 monitor_printf(mon, "(%s)", mask->eth_dst);
2238 if (key->has_ip_proto) {
2239 monitor_printf(mon, " proto %d", key->ip_proto);
2240 if (mask->has_ip_proto) {
2241 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2245 if (key->has_ip_tos) {
2246 monitor_printf(mon, " TOS %d", key->ip_tos);
2247 if (mask->has_ip_tos) {
2248 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2252 if (key->has_ip_dst) {
2253 monitor_printf(mon, " dst %s", key->ip_dst);
2256 if (action->has_goto_tbl || action->has_group_id ||
2257 action->has_new_vlan_id) {
2258 monitor_printf(mon, " -->");
2261 if (action->has_new_vlan_id) {
2262 monitor_printf(mon, " apply new vlan %d",
2263 ntohs(action->new_vlan_id));
2266 if (action->has_group_id) {
2267 monitor_printf(mon, " write group 0x%08x", action->group_id);
2270 if (action->has_goto_tbl) {
2271 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2274 monitor_printf(mon, "\n");
2277 qapi_free_RockerOfDpaFlowList(list);
2280 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2282 RockerOfDpaGroupList *list, *g;
2283 const char *name = qdict_get_str(qdict, "name");
2284 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2288 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2290 hmp_handle_error(mon, &err);
2294 monitor_printf(mon, "id (decode) --> buckets\n");
2296 for (g = list; g; g = g->next) {
2297 RockerOfDpaGroup *group = g->value;
2299 monitor_printf(mon, "0x%08x", group->id);
2301 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2302 group->type == 1 ? "L2 rewrite" :
2303 group->type == 2 ? "L3 unicast" :
2304 group->type == 3 ? "L2 multicast" :
2305 group->type == 4 ? "L2 flood" :
2306 group->type == 5 ? "L3 interface" :
2307 group->type == 6 ? "L3 multicast" :
2308 group->type == 7 ? "L3 ECMP" :
2309 group->type == 8 ? "L2 overlay" :
2312 if (group->has_vlan_id) {
2313 monitor_printf(mon, " vlan %d", group->vlan_id);
2316 if (group->has_pport) {
2317 monitor_printf(mon, " pport %d", group->pport);
2320 if (group->has_index) {
2321 monitor_printf(mon, " index %d", group->index);
2324 monitor_printf(mon, ") -->");
2326 if (group->has_set_vlan_id && group->set_vlan_id) {
2328 monitor_printf(mon, " set vlan %d",
2329 group->set_vlan_id & VLAN_VID_MASK);
2332 if (group->has_set_eth_src) {
2335 monitor_printf(mon, " set");
2337 monitor_printf(mon, " src %s", group->set_eth_src);
2340 if (group->has_set_eth_dst) {
2343 monitor_printf(mon, " set");
2345 monitor_printf(mon, " dst %s", group->set_eth_dst);
2350 if (group->has_ttl_check && group->ttl_check) {
2351 monitor_printf(mon, " check TTL");
2354 if (group->has_group_id && group->group_id) {
2355 monitor_printf(mon, " group id 0x%08x", group->group_id);
2358 if (group->has_pop_vlan && group->pop_vlan) {
2359 monitor_printf(mon, " pop vlan");
2362 if (group->has_out_pport) {
2363 monitor_printf(mon, " out pport %d", group->out_pport);
2366 if (group->has_group_ids) {
2367 struct uint32List *id;
2369 monitor_printf(mon, " groups [");
2370 for (id = group->group_ids; id; id = id->next) {
2371 monitor_printf(mon, "0x%08x", id->value);
2373 monitor_printf(mon, ",");
2376 monitor_printf(mon, "]");
2379 monitor_printf(mon, "\n");
2382 qapi_free_RockerOfDpaGroupList(list);
2385 void hmp_info_dump(Monitor *mon, const QDict *qdict)
2387 DumpQueryResult *result = qmp_query_dump(NULL);
2389 assert(result && result->status < DUMP_STATUS__MAX);
2390 monitor_printf(mon, "Status: %s\n", DumpStatus_lookup[result->status]);
2392 if (result->status == DUMP_STATUS_ACTIVE) {
2394 assert(result->total != 0);
2395 percent = 100.0 * result->completed / result->total;
2396 monitor_printf(mon, "Finished: %.2f %%\n", percent);
2399 qapi_free_DumpQueryResult(result);