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.
19 #include "sysemu/char.h"
20 #include "sysemu/block-backend.h"
21 #include "qemu/option.h"
22 #include "qemu/timer.h"
23 #include "qmp-commands.h"
24 #include "qemu/sockets.h"
25 #include "monitor/monitor.h"
26 #include "monitor/qdev.h"
27 #include "qapi/opts-visitor.h"
28 #include "qapi/string-output-visitor.h"
29 #include "qapi-visit.h"
30 #include "ui/console.h"
31 #include "block/qapi.h"
35 #include <spice/enums.h>
38 static void hmp_handle_error(Monitor *mon, Error **errp)
42 monitor_printf(mon, "%s\n", error_get_pretty(*errp));
47 void hmp_info_name(Monitor *mon, const QDict *qdict)
51 info = qmp_query_name(NULL);
53 monitor_printf(mon, "%s\n", info->name);
55 qapi_free_NameInfo(info);
58 void hmp_info_version(Monitor *mon, const QDict *qdict)
62 info = qmp_query_version(NULL);
64 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
65 info->qemu->major, info->qemu->minor, info->qemu->micro,
68 qapi_free_VersionInfo(info);
71 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
75 info = qmp_query_kvm(NULL);
76 monitor_printf(mon, "kvm support: ");
78 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
80 monitor_printf(mon, "not compiled\n");
83 qapi_free_KvmInfo(info);
86 void hmp_info_status(Monitor *mon, const QDict *qdict)
90 info = qmp_query_status(NULL);
92 monitor_printf(mon, "VM status: %s%s",
93 info->running ? "running" : "paused",
94 info->singlestep ? " (single step mode)" : "");
96 if (!info->running && info->status != RUN_STATE_PAUSED) {
97 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
100 monitor_printf(mon, "\n");
102 qapi_free_StatusInfo(info);
105 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
109 info = qmp_query_uuid(NULL);
110 monitor_printf(mon, "%s\n", info->UUID);
111 qapi_free_UuidInfo(info);
114 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
116 ChardevInfoList *char_info, *info;
118 char_info = qmp_query_chardev(NULL);
119 for (info = char_info; info; info = info->next) {
120 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
121 info->value->filename);
124 qapi_free_ChardevInfoList(char_info);
127 void hmp_info_mice(Monitor *mon, const QDict *qdict)
129 MouseInfoList *mice_list, *mouse;
131 mice_list = qmp_query_mice(NULL);
133 monitor_printf(mon, "No mouse devices connected\n");
137 for (mouse = mice_list; mouse; mouse = mouse->next) {
138 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
139 mouse->value->current ? '*' : ' ',
140 mouse->value->index, mouse->value->name,
141 mouse->value->absolute ? " (absolute)" : "");
144 qapi_free_MouseInfoList(mice_list);
147 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
150 MigrationCapabilityStatusList *caps, *cap;
152 info = qmp_query_migrate(NULL);
153 caps = qmp_query_migrate_capabilities(NULL);
155 /* do not display parameters during setup */
156 if (info->has_status && caps) {
157 monitor_printf(mon, "capabilities: ");
158 for (cap = caps; cap; cap = cap->next) {
159 monitor_printf(mon, "%s: %s ",
160 MigrationCapability_lookup[cap->value->capability],
161 cap->value->state ? "on" : "off");
163 monitor_printf(mon, "\n");
166 if (info->has_status) {
167 monitor_printf(mon, "Migration status: %s\n",
168 MigrationStatus_lookup[info->status]);
169 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
171 if (info->has_expected_downtime) {
172 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
173 info->expected_downtime);
175 if (info->has_downtime) {
176 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
179 if (info->has_setup_time) {
180 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
186 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
187 info->ram->transferred >> 10);
188 monitor_printf(mon, "throughput: %0.2f mbps\n",
190 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
191 info->ram->remaining >> 10);
192 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
193 info->ram->total >> 10);
194 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
195 info->ram->duplicate);
196 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
198 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
200 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
201 info->ram->normal_bytes >> 10);
202 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
203 info->ram->dirty_sync_count);
204 if (info->ram->dirty_pages_rate) {
205 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
206 info->ram->dirty_pages_rate);
210 if (info->has_disk) {
211 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
212 info->disk->transferred >> 10);
213 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
214 info->disk->remaining >> 10);
215 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
216 info->disk->total >> 10);
219 if (info->has_xbzrle_cache) {
220 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
221 info->xbzrle_cache->cache_size);
222 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
223 info->xbzrle_cache->bytes >> 10);
224 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
225 info->xbzrle_cache->pages);
226 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
227 info->xbzrle_cache->cache_miss);
228 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
229 info->xbzrle_cache->cache_miss_rate);
230 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
231 info->xbzrle_cache->overflow);
234 qapi_free_MigrationInfo(info);
235 qapi_free_MigrationCapabilityStatusList(caps);
238 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
240 MigrationCapabilityStatusList *caps, *cap;
242 caps = qmp_query_migrate_capabilities(NULL);
245 monitor_printf(mon, "capabilities: ");
246 for (cap = caps; cap; cap = cap->next) {
247 monitor_printf(mon, "%s: %s ",
248 MigrationCapability_lookup[cap->value->capability],
249 cap->value->state ? "on" : "off");
251 monitor_printf(mon, "\n");
254 qapi_free_MigrationCapabilityStatusList(caps);
257 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
259 MigrationParameters *params;
261 params = qmp_query_migrate_parameters(NULL);
264 monitor_printf(mon, "parameters:");
265 monitor_printf(mon, " %s: %" PRId64,
266 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_LEVEL],
267 params->compress_level);
268 monitor_printf(mon, " %s: %" PRId64,
269 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_THREADS],
270 params->compress_threads);
271 monitor_printf(mon, " %s: %" PRId64,
272 MigrationParameter_lookup[MIGRATION_PARAMETER_DECOMPRESS_THREADS],
273 params->decompress_threads);
274 monitor_printf(mon, "\n");
277 qapi_free_MigrationParameters(params);
280 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
282 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
283 qmp_query_migrate_cache_size(NULL) >> 10);
286 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
288 CpuInfoList *cpu_list, *cpu;
290 cpu_list = qmp_query_cpus(NULL);
292 for (cpu = cpu_list; cpu; cpu = cpu->next) {
295 if (cpu->value->CPU == monitor_get_cpu_index()) {
299 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
301 if (cpu->value->has_pc) {
302 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->pc);
304 if (cpu->value->has_nip) {
305 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->nip);
307 if (cpu->value->has_npc) {
308 monitor_printf(mon, " npc=0x%016" PRIx64, cpu->value->npc);
310 if (cpu->value->has_PC) {
311 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->PC);
314 if (cpu->value->halted) {
315 monitor_printf(mon, " (halted)");
318 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
321 qapi_free_CpuInfoList(cpu_list);
324 static void print_block_info(Monitor *mon, BlockInfo *info,
325 BlockDeviceInfo *inserted, bool verbose)
327 ImageInfo *image_info;
329 assert(!info || !info->has_inserted || info->inserted == inserted);
332 monitor_printf(mon, "%s", info->device);
333 if (inserted && inserted->has_node_name) {
334 monitor_printf(mon, " (%s)", inserted->node_name);
338 monitor_printf(mon, "%s",
339 inserted->has_node_name
340 ? inserted->node_name
345 monitor_printf(mon, ": %s (%s%s%s)\n",
348 inserted->ro ? ", read-only" : "",
349 inserted->encrypted ? ", encrypted" : "");
351 monitor_printf(mon, ": [not inserted]\n");
355 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
356 monitor_printf(mon, " I/O status: %s\n",
357 BlockDeviceIoStatus_lookup[info->io_status]);
360 if (info->removable) {
361 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
362 info->locked ? "" : "not ",
363 info->tray_open ? "open" : "closed");
372 monitor_printf(mon, " Cache mode: %s%s%s\n",
373 inserted->cache->writeback ? "writeback" : "writethrough",
374 inserted->cache->direct ? ", direct" : "",
375 inserted->cache->no_flush ? ", ignore flushes" : "");
377 if (inserted->has_backing_file) {
380 "(chain depth: %" PRId64 ")\n",
381 inserted->backing_file,
382 inserted->backing_file_depth);
385 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
386 monitor_printf(mon, " Detect zeroes: %s\n",
387 BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]);
390 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
391 inserted->iops || inserted->iops_rd || inserted->iops_wr)
393 monitor_printf(mon, " I/O throttling: bps=%" PRId64
394 " bps_rd=%" PRId64 " bps_wr=%" PRId64
396 " bps_rd_max=%" PRId64
397 " bps_wr_max=%" PRId64
398 " iops=%" PRId64 " iops_rd=%" PRId64
401 " iops_rd_max=%" PRId64
402 " iops_wr_max=%" PRId64
403 " iops_size=%" PRId64 "\n",
408 inserted->bps_rd_max,
409 inserted->bps_wr_max,
414 inserted->iops_rd_max,
415 inserted->iops_wr_max,
416 inserted->iops_size);
420 monitor_printf(mon, "\nImages:\n");
421 image_info = inserted->image;
423 bdrv_image_info_dump((fprintf_function)monitor_printf,
425 if (image_info->has_backing_image) {
426 image_info = image_info->backing_image;
434 void hmp_info_block(Monitor *mon, const QDict *qdict)
436 BlockInfoList *block_list, *info;
437 BlockDeviceInfoList *blockdev_list, *blockdev;
438 const char *device = qdict_get_try_str(qdict, "device");
439 bool verbose = qdict_get_try_bool(qdict, "verbose", 0);
440 bool nodes = qdict_get_try_bool(qdict, "nodes", 0);
441 bool printed = false;
443 /* Print BlockBackend information */
445 block_list = qmp_query_block(NULL);
450 for (info = block_list; info; info = info->next) {
451 if (device && strcmp(device, info->value->device)) {
455 if (info != block_list) {
456 monitor_printf(mon, "\n");
459 print_block_info(mon, info->value, info->value->has_inserted
460 ? info->value->inserted : NULL,
465 qapi_free_BlockInfoList(block_list);
467 if ((!device && !nodes) || printed) {
471 /* Print node information */
472 blockdev_list = qmp_query_named_block_nodes(NULL);
473 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
474 assert(blockdev->value->has_node_name);
475 if (device && strcmp(device, blockdev->value->node_name)) {
479 if (blockdev != blockdev_list) {
480 monitor_printf(mon, "\n");
483 print_block_info(mon, NULL, blockdev->value, verbose);
485 qapi_free_BlockDeviceInfoList(blockdev_list);
488 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
490 BlockStatsList *stats_list, *stats;
492 stats_list = qmp_query_blockstats(false, false, NULL);
494 for (stats = stats_list; stats; stats = stats->next) {
495 if (!stats->value->has_device) {
499 monitor_printf(mon, "%s:", stats->value->device);
500 monitor_printf(mon, " rd_bytes=%" PRId64
502 " rd_operations=%" PRId64
503 " wr_operations=%" PRId64
504 " flush_operations=%" PRId64
505 " wr_total_time_ns=%" PRId64
506 " rd_total_time_ns=%" PRId64
507 " flush_total_time_ns=%" PRId64
508 " rd_merged=%" PRId64
509 " wr_merged=%" PRId64
511 stats->value->stats->rd_bytes,
512 stats->value->stats->wr_bytes,
513 stats->value->stats->rd_operations,
514 stats->value->stats->wr_operations,
515 stats->value->stats->flush_operations,
516 stats->value->stats->wr_total_time_ns,
517 stats->value->stats->rd_total_time_ns,
518 stats->value->stats->flush_total_time_ns,
519 stats->value->stats->rd_merged,
520 stats->value->stats->wr_merged);
523 qapi_free_BlockStatsList(stats_list);
526 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
530 VncClientInfoList *client;
532 info = qmp_query_vnc(&err);
534 monitor_printf(mon, "%s\n", error_get_pretty(err));
539 if (!info->enabled) {
540 monitor_printf(mon, "Server: disabled\n");
544 monitor_printf(mon, "Server:\n");
545 if (info->has_host && info->has_service) {
546 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
548 if (info->has_auth) {
549 monitor_printf(mon, " auth: %s\n", info->auth);
552 if (!info->has_clients || info->clients == NULL) {
553 monitor_printf(mon, "Client: none\n");
555 for (client = info->clients; client; client = client->next) {
556 monitor_printf(mon, "Client:\n");
557 monitor_printf(mon, " address: %s:%s\n",
558 client->value->base->host,
559 client->value->base->service);
560 monitor_printf(mon, " x509_dname: %s\n",
561 client->value->x509_dname ?
562 client->value->x509_dname : "none");
563 monitor_printf(mon, " username: %s\n",
564 client->value->has_sasl_username ?
565 client->value->sasl_username : "none");
570 qapi_free_VncInfo(info);
574 void hmp_info_spice(Monitor *mon, const QDict *qdict)
576 SpiceChannelList *chan;
578 const char *channel_name;
579 const char * const channel_names[] = {
580 [SPICE_CHANNEL_MAIN] = "main",
581 [SPICE_CHANNEL_DISPLAY] = "display",
582 [SPICE_CHANNEL_INPUTS] = "inputs",
583 [SPICE_CHANNEL_CURSOR] = "cursor",
584 [SPICE_CHANNEL_PLAYBACK] = "playback",
585 [SPICE_CHANNEL_RECORD] = "record",
586 [SPICE_CHANNEL_TUNNEL] = "tunnel",
587 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
588 [SPICE_CHANNEL_USBREDIR] = "usbredir",
589 [SPICE_CHANNEL_PORT] = "port",
591 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
592 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
593 * as quick fix for build failures with older versions. */
594 [SPICE_CHANNEL_WEBDAV] = "webdav",
598 info = qmp_query_spice(NULL);
600 if (!info->enabled) {
601 monitor_printf(mon, "Server: disabled\n");
605 monitor_printf(mon, "Server:\n");
606 if (info->has_port) {
607 monitor_printf(mon, " address: %s:%" PRId64 "\n",
608 info->host, info->port);
610 if (info->has_tls_port) {
611 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
612 info->host, info->tls_port);
614 monitor_printf(mon, " migrated: %s\n",
615 info->migrated ? "true" : "false");
616 monitor_printf(mon, " auth: %s\n", info->auth);
617 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
618 monitor_printf(mon, " mouse-mode: %s\n",
619 SpiceQueryMouseMode_lookup[info->mouse_mode]);
621 if (!info->has_channels || info->channels == NULL) {
622 monitor_printf(mon, "Channels: none\n");
624 for (chan = info->channels; chan; chan = chan->next) {
625 monitor_printf(mon, "Channel:\n");
626 monitor_printf(mon, " address: %s:%s%s\n",
627 chan->value->base->host, chan->value->base->port,
628 chan->value->tls ? " [tls]" : "");
629 monitor_printf(mon, " session: %" PRId64 "\n",
630 chan->value->connection_id);
631 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
632 chan->value->channel_type, chan->value->channel_id);
634 channel_name = "unknown";
635 if (chan->value->channel_type > 0 &&
636 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
637 channel_names[chan->value->channel_type]) {
638 channel_name = channel_names[chan->value->channel_type];
641 monitor_printf(mon, " channel name: %s\n", channel_name);
646 qapi_free_SpiceInfo(info);
650 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
655 info = qmp_query_balloon(&err);
657 monitor_printf(mon, "%s\n", error_get_pretty(err));
662 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
664 qapi_free_BalloonInfo(info);
667 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
669 PciMemoryRegionList *region;
671 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
672 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
673 dev->slot, dev->function);
674 monitor_printf(mon, " ");
676 if (dev->class_info->has_desc) {
677 monitor_printf(mon, "%s", dev->class_info->desc);
679 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
682 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
683 dev->id->vendor, dev->id->device);
686 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
689 if (dev->has_pci_bridge) {
690 monitor_printf(mon, " BUS %" PRId64 ".\n",
691 dev->pci_bridge->bus->number);
692 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
693 dev->pci_bridge->bus->secondary);
694 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
695 dev->pci_bridge->bus->subordinate);
697 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
698 dev->pci_bridge->bus->io_range->base,
699 dev->pci_bridge->bus->io_range->limit);
702 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
703 dev->pci_bridge->bus->memory_range->base,
704 dev->pci_bridge->bus->memory_range->limit);
706 monitor_printf(mon, " prefetchable memory range "
707 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
708 dev->pci_bridge->bus->prefetchable_range->base,
709 dev->pci_bridge->bus->prefetchable_range->limit);
712 for (region = dev->regions; region; region = region->next) {
715 addr = region->value->address;
716 size = region->value->size;
718 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
720 if (!strcmp(region->value->type, "io")) {
721 monitor_printf(mon, "I/O at 0x%04" PRIx64
722 " [0x%04" PRIx64 "].\n",
723 addr, addr + size - 1);
725 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
726 " [0x%08" PRIx64 "].\n",
727 region->value->mem_type_64 ? 64 : 32,
728 region->value->prefetch ? " prefetchable" : "",
729 addr, addr + size - 1);
733 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
735 if (dev->has_pci_bridge) {
736 if (dev->pci_bridge->has_devices) {
737 PciDeviceInfoList *cdev;
738 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
739 hmp_info_pci_device(mon, cdev->value);
745 void hmp_info_pci(Monitor *mon, const QDict *qdict)
747 PciInfoList *info_list, *info;
750 info_list = qmp_query_pci(&err);
752 monitor_printf(mon, "PCI devices not supported\n");
757 for (info = info_list; info; info = info->next) {
758 PciDeviceInfoList *dev;
760 for (dev = info->value->devices; dev; dev = dev->next) {
761 hmp_info_pci_device(mon, dev->value);
765 qapi_free_PciInfoList(info_list);
768 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
770 BlockJobInfoList *list;
773 list = qmp_query_block_jobs(&err);
777 monitor_printf(mon, "No active jobs\n");
782 if (strcmp(list->value->type, "stream") == 0) {
783 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
784 " of %" PRId64 " bytes, speed limit %" PRId64
791 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
792 " of %" PRId64 " bytes, speed limit %" PRId64
803 qapi_free_BlockJobInfoList(list);
806 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
808 TPMInfoList *info_list, *info;
811 TPMPassthroughOptions *tpo;
813 info_list = qmp_query_tpm(&err);
815 monitor_printf(mon, "TPM device not supported\n");
821 monitor_printf(mon, "TPM device:\n");
824 for (info = info_list; info; info = info->next) {
825 TPMInfo *ti = info->value;
826 monitor_printf(mon, " tpm%d: model=%s\n",
827 c, TpmModel_lookup[ti->model]);
829 monitor_printf(mon, " \\ %s: type=%s",
830 ti->id, TpmTypeOptionsKind_lookup[ti->options->kind]);
832 switch (ti->options->kind) {
833 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
834 tpo = ti->options->passthrough;
835 monitor_printf(mon, "%s%s%s%s",
836 tpo->has_path ? ",path=" : "",
837 tpo->has_path ? tpo->path : "",
838 tpo->has_cancel_path ? ",cancel-path=" : "",
839 tpo->has_cancel_path ? tpo->cancel_path : "");
841 case TPM_TYPE_OPTIONS_KIND_MAX:
844 monitor_printf(mon, "\n");
847 qapi_free_TPMInfoList(info_list);
850 void hmp_quit(Monitor *mon, const QDict *qdict)
852 monitor_suspend(mon);
856 void hmp_stop(Monitor *mon, const QDict *qdict)
861 void hmp_system_reset(Monitor *mon, const QDict *qdict)
863 qmp_system_reset(NULL);
866 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
868 qmp_system_powerdown(NULL);
871 void hmp_cpu(Monitor *mon, const QDict *qdict)
875 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
876 use it are converted to the QAPI */
877 cpu_index = qdict_get_int(qdict, "index");
878 if (monitor_set_cpu(cpu_index) < 0) {
879 monitor_printf(mon, "invalid CPU index\n");
883 void hmp_memsave(Monitor *mon, const QDict *qdict)
885 uint32_t size = qdict_get_int(qdict, "size");
886 const char *filename = qdict_get_str(qdict, "filename");
887 uint64_t addr = qdict_get_int(qdict, "val");
890 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &err);
891 hmp_handle_error(mon, &err);
894 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
896 uint32_t size = qdict_get_int(qdict, "size");
897 const char *filename = qdict_get_str(qdict, "filename");
898 uint64_t addr = qdict_get_int(qdict, "val");
901 qmp_pmemsave(addr, size, filename, &err);
902 hmp_handle_error(mon, &err);
905 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
907 const char *chardev = qdict_get_str(qdict, "device");
908 const char *data = qdict_get_str(qdict, "data");
911 qmp_ringbuf_write(chardev, data, false, 0, &err);
913 hmp_handle_error(mon, &err);
916 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
918 uint32_t size = qdict_get_int(qdict, "size");
919 const char *chardev = qdict_get_str(qdict, "device");
924 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
926 monitor_printf(mon, "%s\n", error_get_pretty(err));
931 for (i = 0; data[i]; i++) {
932 unsigned char ch = data[i];
935 monitor_printf(mon, "\\\\");
936 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
937 monitor_printf(mon, "\\u%04X", ch);
939 monitor_printf(mon, "%c", ch);
943 monitor_printf(mon, "\n");
947 static void hmp_cont_cb(void *opaque, int err)
954 static bool key_is_missing(const BlockInfo *bdev)
956 return (bdev->inserted && bdev->inserted->encryption_key_missing);
959 void hmp_cont(Monitor *mon, const QDict *qdict)
961 BlockInfoList *bdev_list, *bdev;
964 bdev_list = qmp_query_block(NULL);
965 for (bdev = bdev_list; bdev; bdev = bdev->next) {
966 if (key_is_missing(bdev->value)) {
967 monitor_read_block_device_key(mon, bdev->value->device,
974 hmp_handle_error(mon, &err);
977 qapi_free_BlockInfoList(bdev_list);
980 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
982 qmp_system_wakeup(NULL);
985 void hmp_nmi(Monitor *mon, const QDict *qdict)
989 qmp_inject_nmi(&err);
990 hmp_handle_error(mon, &err);
993 void hmp_set_link(Monitor *mon, const QDict *qdict)
995 const char *name = qdict_get_str(qdict, "name");
996 int up = qdict_get_bool(qdict, "up");
999 qmp_set_link(name, up, &err);
1000 hmp_handle_error(mon, &err);
1003 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1005 const char *device = qdict_get_str(qdict, "device");
1006 const char *password = qdict_get_str(qdict, "password");
1009 qmp_block_passwd(true, device, false, NULL, password, &err);
1010 hmp_handle_error(mon, &err);
1013 void hmp_balloon(Monitor *mon, const QDict *qdict)
1015 int64_t value = qdict_get_int(qdict, "value");
1018 qmp_balloon(value, &err);
1020 monitor_printf(mon, "balloon: %s\n", error_get_pretty(err));
1025 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1027 const char *device = qdict_get_str(qdict, "device");
1028 int64_t size = qdict_get_int(qdict, "size");
1031 qmp_block_resize(true, device, false, NULL, size, &err);
1032 hmp_handle_error(mon, &err);
1035 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1037 const char *device = qdict_get_str(qdict, "device");
1038 const char *filename = qdict_get_str(qdict, "target");
1039 const char *format = qdict_get_try_str(qdict, "format");
1040 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
1041 int full = qdict_get_try_bool(qdict, "full", 0);
1042 enum NewImageMode mode;
1046 error_set(&err, QERR_MISSING_PARAMETER, "target");
1047 hmp_handle_error(mon, &err);
1052 mode = NEW_IMAGE_MODE_EXISTING;
1054 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1057 qmp_drive_mirror(device, filename, !!format, format,
1058 false, NULL, false, NULL,
1059 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1060 true, mode, false, 0, false, 0, false, 0,
1061 false, 0, false, 0, &err);
1062 hmp_handle_error(mon, &err);
1065 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1067 const char *device = qdict_get_str(qdict, "device");
1068 const char *filename = qdict_get_str(qdict, "target");
1069 const char *format = qdict_get_try_str(qdict, "format");
1070 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
1071 int full = qdict_get_try_bool(qdict, "full", 0);
1072 enum NewImageMode mode;
1076 error_set(&err, QERR_MISSING_PARAMETER, "target");
1077 hmp_handle_error(mon, &err);
1082 mode = NEW_IMAGE_MODE_EXISTING;
1084 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1087 qmp_drive_backup(device, filename, !!format, format,
1088 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1089 true, mode, false, 0, false, NULL,
1090 false, 0, false, 0, &err);
1091 hmp_handle_error(mon, &err);
1094 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1096 const char *device = qdict_get_str(qdict, "device");
1097 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1098 const char *format = qdict_get_try_str(qdict, "format");
1099 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
1100 enum NewImageMode mode;
1104 /* In the future, if 'snapshot-file' is not specified, the snapshot
1105 will be taken internally. Today it's actually required. */
1106 error_set(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1107 hmp_handle_error(mon, &err);
1111 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1112 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1113 filename, false, NULL,
1116 hmp_handle_error(mon, &err);
1119 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1121 const char *device = qdict_get_str(qdict, "device");
1122 const char *name = qdict_get_str(qdict, "name");
1125 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1126 hmp_handle_error(mon, &err);
1129 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1131 const char *device = qdict_get_str(qdict, "device");
1132 const char *name = qdict_get_str(qdict, "name");
1133 const char *id = qdict_get_try_str(qdict, "id");
1136 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1138 hmp_handle_error(mon, &err);
1141 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1143 qmp_migrate_cancel(NULL);
1146 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1149 const char *uri = qdict_get_str(qdict, "uri");
1151 qmp_migrate_incoming(uri, &err);
1153 hmp_handle_error(mon, &err);
1156 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1158 double value = qdict_get_double(qdict, "value");
1159 qmp_migrate_set_downtime(value, NULL);
1162 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1164 int64_t value = qdict_get_int(qdict, "value");
1167 qmp_migrate_set_cache_size(value, &err);
1169 monitor_printf(mon, "%s\n", error_get_pretty(err));
1175 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1177 int64_t value = qdict_get_int(qdict, "value");
1178 qmp_migrate_set_speed(value, NULL);
1181 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1183 const char *cap = qdict_get_str(qdict, "capability");
1184 bool state = qdict_get_bool(qdict, "state");
1186 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1189 for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
1190 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1191 caps->value = g_malloc0(sizeof(*caps->value));
1192 caps->value->capability = i;
1193 caps->value->state = state;
1195 qmp_migrate_set_capabilities(caps, &err);
1200 if (i == MIGRATION_CAPABILITY_MAX) {
1201 error_set(&err, QERR_INVALID_PARAMETER, cap);
1204 qapi_free_MigrationCapabilityStatusList(caps);
1207 monitor_printf(mon, "migrate_set_capability: %s\n",
1208 error_get_pretty(err));
1213 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1215 const char *param = qdict_get_str(qdict, "parameter");
1216 int value = qdict_get_int(qdict, "value");
1218 bool has_compress_level = false;
1219 bool has_compress_threads = false;
1220 bool has_decompress_threads = false;
1223 for (i = 0; i < MIGRATION_PARAMETER_MAX; i++) {
1224 if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
1226 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1227 has_compress_level = true;
1229 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1230 has_compress_threads = true;
1232 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1233 has_decompress_threads = true;
1236 qmp_migrate_set_parameters(has_compress_level, value,
1237 has_compress_threads, value,
1238 has_decompress_threads, value,
1244 if (i == MIGRATION_PARAMETER_MAX) {
1245 error_set(&err, QERR_INVALID_PARAMETER, param);
1249 monitor_printf(mon, "migrate_set_parameter: %s\n",
1250 error_get_pretty(err));
1255 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1258 const char *protocol = qdict_get_str(qdict, "protocol");
1259 const char *hostname = qdict_get_str(qdict, "hostname");
1260 bool has_port = qdict_haskey(qdict, "port");
1261 int port = qdict_get_try_int(qdict, "port", -1);
1262 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1263 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1264 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1266 qmp_client_migrate_info(protocol, hostname,
1267 has_port, port, has_tls_port, tls_port,
1268 !!cert_subject, cert_subject, &err);
1269 hmp_handle_error(mon, &err);
1272 void hmp_set_password(Monitor *mon, const QDict *qdict)
1274 const char *protocol = qdict_get_str(qdict, "protocol");
1275 const char *password = qdict_get_str(qdict, "password");
1276 const char *connected = qdict_get_try_str(qdict, "connected");
1279 qmp_set_password(protocol, password, !!connected, connected, &err);
1280 hmp_handle_error(mon, &err);
1283 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1285 const char *protocol = qdict_get_str(qdict, "protocol");
1286 const char *whenstr = qdict_get_str(qdict, "time");
1289 qmp_expire_password(protocol, whenstr, &err);
1290 hmp_handle_error(mon, &err);
1293 void hmp_eject(Monitor *mon, const QDict *qdict)
1295 int force = qdict_get_try_bool(qdict, "force", 0);
1296 const char *device = qdict_get_str(qdict, "device");
1299 qmp_eject(device, true, force, &err);
1300 hmp_handle_error(mon, &err);
1303 static void hmp_change_read_arg(void *opaque, const char *password,
1304 void *readline_opaque)
1306 qmp_change_vnc_password(password, NULL);
1307 monitor_read_command(opaque, 1);
1310 void hmp_change(Monitor *mon, const QDict *qdict)
1312 const char *device = qdict_get_str(qdict, "device");
1313 const char *target = qdict_get_str(qdict, "target");
1314 const char *arg = qdict_get_try_str(qdict, "arg");
1317 if (strcmp(device, "vnc") == 0 &&
1318 (strcmp(target, "passwd") == 0 ||
1319 strcmp(target, "password") == 0)) {
1321 monitor_read_password(mon, hmp_change_read_arg, NULL);
1326 qmp_change(device, target, !!arg, arg, &err);
1328 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
1330 monitor_read_block_device_key(mon, device, NULL, NULL);
1333 hmp_handle_error(mon, &err);
1336 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1340 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
1341 qdict_get_int(qdict, "bps"),
1342 qdict_get_int(qdict, "bps_rd"),
1343 qdict_get_int(qdict, "bps_wr"),
1344 qdict_get_int(qdict, "iops"),
1345 qdict_get_int(qdict, "iops_rd"),
1346 qdict_get_int(qdict, "iops_wr"),
1347 false, /* no burst max via HMP */
1359 false, /* No default I/O size */
1361 hmp_handle_error(mon, &err);
1364 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1366 Error *error = NULL;
1367 const char *device = qdict_get_str(qdict, "device");
1368 const char *base = qdict_get_try_str(qdict, "base");
1369 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1371 qmp_block_stream(device, base != NULL, base, false, NULL,
1372 qdict_haskey(qdict, "speed"), speed,
1373 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1375 hmp_handle_error(mon, &error);
1378 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1380 Error *error = NULL;
1381 const char *device = qdict_get_str(qdict, "device");
1382 int64_t value = qdict_get_int(qdict, "speed");
1384 qmp_block_job_set_speed(device, value, &error);
1386 hmp_handle_error(mon, &error);
1389 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1391 Error *error = NULL;
1392 const char *device = qdict_get_str(qdict, "device");
1393 bool force = qdict_get_try_bool(qdict, "force", 0);
1395 qmp_block_job_cancel(device, true, force, &error);
1397 hmp_handle_error(mon, &error);
1400 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1402 Error *error = NULL;
1403 const char *device = qdict_get_str(qdict, "device");
1405 qmp_block_job_pause(device, &error);
1407 hmp_handle_error(mon, &error);
1410 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1412 Error *error = NULL;
1413 const char *device = qdict_get_str(qdict, "device");
1415 qmp_block_job_resume(device, &error);
1417 hmp_handle_error(mon, &error);
1420 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1422 Error *error = NULL;
1423 const char *device = qdict_get_str(qdict, "device");
1425 qmp_block_job_complete(device, &error);
1427 hmp_handle_error(mon, &error);
1430 typedef struct HMPMigrationStatus
1434 bool is_block_migration;
1435 } HMPMigrationStatus;
1437 static void hmp_migrate_status_cb(void *opaque)
1439 HMPMigrationStatus *status = opaque;
1440 MigrationInfo *info;
1442 info = qmp_query_migrate(NULL);
1443 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1444 info->status == MIGRATION_STATUS_SETUP) {
1445 if (info->has_disk) {
1448 if (info->disk->remaining) {
1449 progress = info->disk->transferred * 100 / info->disk->total;
1454 monitor_printf(status->mon, "Completed %d %%\r", progress);
1455 monitor_flush(status->mon);
1458 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1460 if (status->is_block_migration) {
1461 monitor_printf(status->mon, "\n");
1463 monitor_resume(status->mon);
1464 timer_del(status->timer);
1468 qapi_free_MigrationInfo(info);
1471 void hmp_migrate(Monitor *mon, const QDict *qdict)
1473 int detach = qdict_get_try_bool(qdict, "detach", 0);
1474 int blk = qdict_get_try_bool(qdict, "blk", 0);
1475 int inc = qdict_get_try_bool(qdict, "inc", 0);
1476 const char *uri = qdict_get_str(qdict, "uri");
1479 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1481 monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
1487 HMPMigrationStatus *status;
1489 if (monitor_suspend(mon) < 0) {
1490 monitor_printf(mon, "terminal does not allow synchronous "
1491 "migration, continuing detached\n");
1495 status = g_malloc0(sizeof(*status));
1497 status->is_block_migration = blk || inc;
1498 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1500 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1504 void hmp_device_add(Monitor *mon, const QDict *qdict)
1506 do_device_add(mon, qdict, NULL);
1509 void hmp_device_del(Monitor *mon, const QDict *qdict)
1511 const char *id = qdict_get_str(qdict, "id");
1514 qmp_device_del(id, &err);
1515 hmp_handle_error(mon, &err);
1518 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1521 int paging = qdict_get_try_bool(qdict, "paging", 0);
1522 int zlib = qdict_get_try_bool(qdict, "zlib", 0);
1523 int lzo = qdict_get_try_bool(qdict, "lzo", 0);
1524 int snappy = qdict_get_try_bool(qdict, "snappy", 0);
1525 const char *file = qdict_get_str(qdict, "filename");
1526 bool has_begin = qdict_haskey(qdict, "begin");
1527 bool has_length = qdict_haskey(qdict, "length");
1530 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1533 if (zlib + lzo + snappy > 1) {
1534 error_setg(&err, "only one of '-z|-l|-s' can be set");
1535 hmp_handle_error(mon, &err);
1540 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1544 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1548 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1552 begin = qdict_get_int(qdict, "begin");
1555 length = qdict_get_int(qdict, "length");
1558 prot = g_strconcat("file:", file, NULL);
1560 qmp_dump_guest_memory(paging, prot, has_begin, begin, has_length, length,
1561 true, dump_format, &err);
1562 hmp_handle_error(mon, &err);
1566 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1571 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1576 netdev_add(opts, &err);
1578 qemu_opts_del(opts);
1582 hmp_handle_error(mon, &err);
1585 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1587 const char *id = qdict_get_str(qdict, "id");
1590 qmp_netdev_del(id, &err);
1591 hmp_handle_error(mon, &err);
1594 void hmp_object_add(Monitor *mon, const QDict *qdict)
1597 Error *err_end = NULL;
1605 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1610 ov = opts_visitor_new(opts);
1611 pdict = qdict_clone_shallow(qdict);
1613 visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err);
1618 qdict_del(pdict, "qom-type");
1619 visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
1624 qdict_del(pdict, "id");
1625 visit_type_str(opts_get_visitor(ov), &id, "id", &err);
1630 object_add(type, id, pdict, opts_get_visitor(ov), &err);
1633 visit_end_struct(opts_get_visitor(ov), &err_end);
1634 if (!err && err_end) {
1635 qmp_object_del(id, NULL);
1637 error_propagate(&err, err_end);
1639 opts_visitor_cleanup(ov);
1642 qemu_opts_del(opts);
1648 hmp_handle_error(mon, &err);
1651 void hmp_getfd(Monitor *mon, const QDict *qdict)
1653 const char *fdname = qdict_get_str(qdict, "fdname");
1656 qmp_getfd(fdname, &err);
1657 hmp_handle_error(mon, &err);
1660 void hmp_closefd(Monitor *mon, const QDict *qdict)
1662 const char *fdname = qdict_get_str(qdict, "fdname");
1665 qmp_closefd(fdname, &err);
1666 hmp_handle_error(mon, &err);
1669 void hmp_sendkey(Monitor *mon, const QDict *qdict)
1671 const char *keys = qdict_get_str(qdict, "keys");
1672 KeyValueList *keylist, *head = NULL, *tmp = NULL;
1673 int has_hold_time = qdict_haskey(qdict, "hold-time");
1674 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1676 char keyname_buf[16];
1681 separator = strchr(keys, '-');
1682 keyname_len = separator ? separator - keys : strlen(keys);
1683 pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
1685 /* Be compatible with old interface, convert user inputted "<" */
1686 if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) {
1687 pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
1690 keyname_buf[keyname_len] = 0;
1692 keylist = g_malloc0(sizeof(*keylist));
1693 keylist->value = g_malloc0(sizeof(*keylist->value));
1699 tmp->next = keylist;
1703 if (strstart(keyname_buf, "0x", NULL)) {
1705 int value = strtoul(keyname_buf, &endp, 0);
1706 if (*endp != '\0') {
1709 keylist->value->kind = KEY_VALUE_KIND_NUMBER;
1710 keylist->value->number = value;
1712 int idx = index_from_key(keyname_buf);
1713 if (idx == Q_KEY_CODE_MAX) {
1716 keylist->value->kind = KEY_VALUE_KIND_QCODE;
1717 keylist->value->qcode = idx;
1723 keys = separator + 1;
1726 qmp_send_key(head, has_hold_time, hold_time, &err);
1727 hmp_handle_error(mon, &err);
1730 qapi_free_KeyValueList(head);
1734 monitor_printf(mon, "invalid parameter: %s\n", keyname_buf);
1738 void hmp_screendump(Monitor *mon, const QDict *qdict)
1740 const char *filename = qdict_get_str(qdict, "filename");
1743 qmp_screendump(filename, &err);
1744 hmp_handle_error(mon, &err);
1747 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1749 const char *uri = qdict_get_str(qdict, "uri");
1750 int writable = qdict_get_try_bool(qdict, "writable", 0);
1751 int all = qdict_get_try_bool(qdict, "all", 0);
1752 Error *local_err = NULL;
1753 BlockInfoList *block_list, *info;
1754 SocketAddress *addr;
1756 if (writable && !all) {
1757 error_setg(&local_err, "-w only valid together with -a");
1761 /* First check if the address is valid and start the server. */
1762 addr = socket_parse(uri, &local_err);
1763 if (local_err != NULL) {
1767 qmp_nbd_server_start(addr, &local_err);
1768 qapi_free_SocketAddress(addr);
1769 if (local_err != NULL) {
1777 /* Then try adding all block devices. If one fails, close all and
1780 block_list = qmp_query_block(NULL);
1782 for (info = block_list; info; info = info->next) {
1783 if (!info->value->has_inserted) {
1787 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1789 if (local_err != NULL) {
1790 qmp_nbd_server_stop(NULL);
1795 qapi_free_BlockInfoList(block_list);
1798 hmp_handle_error(mon, &local_err);
1801 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1803 const char *device = qdict_get_str(qdict, "device");
1804 int writable = qdict_get_try_bool(qdict, "writable", 0);
1805 Error *local_err = NULL;
1807 qmp_nbd_server_add(device, true, writable, &local_err);
1809 if (local_err != NULL) {
1810 hmp_handle_error(mon, &local_err);
1814 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1818 qmp_nbd_server_stop(&err);
1819 hmp_handle_error(mon, &err);
1822 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
1827 cpuid = qdict_get_int(qdict, "id");
1828 qmp_cpu_add(cpuid, &err);
1829 hmp_handle_error(mon, &err);
1832 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1834 const char *args = qdict_get_str(qdict, "args");
1838 opts = qemu_opts_parse(qemu_find_opts("chardev"), args, 1);
1840 error_setg(&err, "Parsing chardev args failed");
1842 qemu_chr_new_from_opts(opts, NULL, &err);
1844 hmp_handle_error(mon, &err);
1847 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1849 Error *local_err = NULL;
1851 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1852 hmp_handle_error(mon, &local_err);
1855 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1858 const char* device = qdict_get_str(qdict, "device");
1859 const char* command = qdict_get_str(qdict, "command");
1862 blk = blk_by_name(device);
1864 qemuio_command(blk, command);
1866 error_set(&err, QERR_DEVICE_NOT_FOUND, device);
1869 hmp_handle_error(mon, &err);
1872 void hmp_object_del(Monitor *mon, const QDict *qdict)
1874 const char *id = qdict_get_str(qdict, "id");
1877 qmp_object_del(id, &err);
1878 hmp_handle_error(mon, &err);
1881 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
1884 MemdevList *memdev_list = qmp_query_memdev(&err);
1885 MemdevList *m = memdev_list;
1886 StringOutputVisitor *ov;
1892 ov = string_output_visitor_new(false);
1893 visit_type_uint16List(string_output_get_visitor(ov),
1894 &m->value->host_nodes, NULL, NULL);
1895 monitor_printf(mon, "memory backend: %d\n", i);
1896 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
1897 monitor_printf(mon, " merge: %s\n",
1898 m->value->merge ? "true" : "false");
1899 monitor_printf(mon, " dump: %s\n",
1900 m->value->dump ? "true" : "false");
1901 monitor_printf(mon, " prealloc: %s\n",
1902 m->value->prealloc ? "true" : "false");
1903 monitor_printf(mon, " policy: %s\n",
1904 HostMemPolicy_lookup[m->value->policy]);
1905 str = string_output_get_string(ov);
1906 monitor_printf(mon, " host nodes: %s\n", str);
1909 string_output_visitor_cleanup(ov);
1914 monitor_printf(mon, "\n");
1916 qapi_free_MemdevList(memdev_list);
1919 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
1922 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
1923 MemoryDeviceInfoList *info;
1924 MemoryDeviceInfo *value;
1925 PCDIMMDeviceInfo *di;
1927 for (info = info_list; info; info = info->next) {
1928 value = info->value;
1931 switch (value->kind) {
1932 case MEMORY_DEVICE_INFO_KIND_DIMM:
1935 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1936 MemoryDeviceInfoKind_lookup[value->kind],
1937 di->id ? di->id : "");
1938 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
1939 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
1940 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
1941 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
1942 monitor_printf(mon, " memdev: %s\n", di->memdev);
1943 monitor_printf(mon, " hotplugged: %s\n",
1944 di->hotplugged ? "true" : "false");
1945 monitor_printf(mon, " hotpluggable: %s\n",
1946 di->hotpluggable ? "true" : "false");
1954 qapi_free_MemoryDeviceInfoList(info_list);
1957 void hmp_qom_list(Monitor *mon, const QDict *qdict)
1959 const char *path = qdict_get_try_str(qdict, "path");
1960 ObjectPropertyInfoList *list;
1964 monitor_printf(mon, "/\n");
1968 list = qmp_qom_list(path, &err);
1970 ObjectPropertyInfoList *start = list;
1971 while (list != NULL) {
1972 ObjectPropertyInfo *value = list->value;
1974 monitor_printf(mon, "%s (%s)\n",
1975 value->name, value->type);
1978 qapi_free_ObjectPropertyInfoList(start);
1980 hmp_handle_error(mon, &err);
1983 void hmp_qom_set(Monitor *mon, const QDict *qdict)
1985 const char *path = qdict_get_str(qdict, "path");
1986 const char *property = qdict_get_str(qdict, "property");
1987 const char *value = qdict_get_str(qdict, "value");
1989 bool ambiguous = false;
1992 obj = object_resolve_path(path, &ambiguous);
1994 error_set(&err, QERR_DEVICE_NOT_FOUND, path);
1997 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
1999 object_property_parse(obj, value, property, &err);
2001 hmp_handle_error(mon, &err);
2004 void hmp_rocker(Monitor *mon, const QDict *qdict)
2006 const char *name = qdict_get_str(qdict, "name");
2007 RockerSwitch *rocker;
2010 rocker = qmp_query_rocker(name, &errp);
2012 hmp_handle_error(mon, &errp);
2016 monitor_printf(mon, "name: %s\n", rocker->name);
2017 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2018 monitor_printf(mon, "ports: %d\n", rocker->ports);
2020 qapi_free_RockerSwitch(rocker);
2023 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2025 RockerPortList *list, *port;
2026 const char *name = qdict_get_str(qdict, "name");
2029 list = qmp_query_rocker_ports(name, &errp);
2031 hmp_handle_error(mon, &errp);
2035 monitor_printf(mon, " ena/ speed/ auto\n");
2036 monitor_printf(mon, " port link duplex neg?\n");
2038 for (port = list; port; port = port->next) {
2039 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2041 port->value->enabled ? port->value->link_up ?
2042 "up" : "down" : "!ena",
2043 port->value->speed == 10000 ? "10G" : "??",
2044 port->value->duplex ? "FD" : "HD",
2045 port->value->autoneg ? "Yes" : "No");
2048 qapi_free_RockerPortList(list);
2051 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2053 RockerOfDpaFlowList *list, *info;
2054 const char *name = qdict_get_str(qdict, "name");
2055 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2058 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &errp);
2060 hmp_handle_error(mon, &errp);
2064 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2066 for (info = list; info; info = info->next) {
2067 RockerOfDpaFlow *flow = info->value;
2068 RockerOfDpaFlowKey *key = flow->key;
2069 RockerOfDpaFlowMask *mask = flow->mask;
2070 RockerOfDpaFlowAction *action = flow->action;
2073 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2074 key->priority, key->tbl_id, flow->hits);
2076 monitor_printf(mon, "%-4d %-3d ",
2077 key->priority, key->tbl_id);
2080 if (key->has_in_pport) {
2081 monitor_printf(mon, " pport %d", key->in_pport);
2082 if (mask->has_in_pport) {
2083 monitor_printf(mon, "(0x%x)", mask->in_pport);
2087 if (key->has_vlan_id) {
2088 monitor_printf(mon, " vlan %d",
2089 key->vlan_id & VLAN_VID_MASK);
2090 if (mask->has_vlan_id) {
2091 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2095 if (key->has_tunnel_id) {
2096 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2097 if (mask->has_tunnel_id) {
2098 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2102 if (key->has_eth_type) {
2103 switch (key->eth_type) {
2105 monitor_printf(mon, " ARP");
2108 monitor_printf(mon, " IP");
2111 monitor_printf(mon, " IPv6");
2114 monitor_printf(mon, " LACP");
2117 monitor_printf(mon, " LLDP");
2120 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2125 if (key->has_eth_src) {
2126 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2127 (mask->has_eth_src) &&
2128 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2129 monitor_printf(mon, " src <any mcast/bcast>");
2130 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2131 (mask->has_eth_src) &&
2132 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2133 monitor_printf(mon, " src <any ucast>");
2135 monitor_printf(mon, " src %s", key->eth_src);
2136 if (mask->has_eth_src) {
2137 monitor_printf(mon, "(%s)", mask->eth_src);
2142 if (key->has_eth_dst) {
2143 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2144 (mask->has_eth_dst) &&
2145 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2146 monitor_printf(mon, " dst <any mcast/bcast>");
2147 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2148 (mask->has_eth_dst) &&
2149 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2150 monitor_printf(mon, " dst <any ucast>");
2152 monitor_printf(mon, " dst %s", key->eth_dst);
2153 if (mask->has_eth_dst) {
2154 monitor_printf(mon, "(%s)", mask->eth_dst);
2159 if (key->has_ip_proto) {
2160 monitor_printf(mon, " proto %d", key->ip_proto);
2161 if (mask->has_ip_proto) {
2162 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2166 if (key->has_ip_tos) {
2167 monitor_printf(mon, " TOS %d", key->ip_tos);
2168 if (mask->has_ip_tos) {
2169 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2173 if (key->has_ip_dst) {
2174 monitor_printf(mon, " dst %s", key->ip_dst);
2177 if (action->has_goto_tbl || action->has_group_id ||
2178 action->has_new_vlan_id) {
2179 monitor_printf(mon, " -->");
2182 if (action->has_new_vlan_id) {
2183 monitor_printf(mon, " apply new vlan %d",
2184 ntohs(action->new_vlan_id));
2187 if (action->has_group_id) {
2188 monitor_printf(mon, " write group 0x%08x", action->group_id);
2191 if (action->has_goto_tbl) {
2192 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2195 monitor_printf(mon, "\n");
2198 qapi_free_RockerOfDpaFlowList(list);
2201 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2203 RockerOfDpaGroupList *list, *g;
2204 const char *name = qdict_get_str(qdict, "name");
2205 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2209 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &errp);
2211 hmp_handle_error(mon, &errp);
2215 monitor_printf(mon, "id (decode) --> buckets\n");
2217 for (g = list; g; g = g->next) {
2218 RockerOfDpaGroup *group = g->value;
2220 monitor_printf(mon, "0x%08x", group->id);
2222 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2223 group->type == 1 ? "L2 rewrite" :
2224 group->type == 2 ? "L3 unicast" :
2225 group->type == 3 ? "L2 multicast" :
2226 group->type == 4 ? "L2 flood" :
2227 group->type == 5 ? "L3 interface" :
2228 group->type == 6 ? "L3 multicast" :
2229 group->type == 7 ? "L3 ECMP" :
2230 group->type == 8 ? "L2 overlay" :
2233 if (group->has_vlan_id) {
2234 monitor_printf(mon, " vlan %d", group->vlan_id);
2237 if (group->has_pport) {
2238 monitor_printf(mon, " pport %d", group->pport);
2241 if (group->has_index) {
2242 monitor_printf(mon, " index %d", group->index);
2245 monitor_printf(mon, ") -->");
2247 if (group->has_set_vlan_id && group->set_vlan_id) {
2249 monitor_printf(mon, " set vlan %d",
2250 group->set_vlan_id & VLAN_VID_MASK);
2253 if (group->has_set_eth_src) {
2256 monitor_printf(mon, " set");
2258 monitor_printf(mon, " src %s", group->set_eth_src);
2261 if (group->has_set_eth_dst) {
2264 monitor_printf(mon, " set");
2266 monitor_printf(mon, " dst %s", group->set_eth_dst);
2271 if (group->has_ttl_check && group->ttl_check) {
2272 monitor_printf(mon, " check TTL");
2275 if (group->has_group_id && group->group_id) {
2276 monitor_printf(mon, " group id 0x%08x", group->group_id);
2279 if (group->has_pop_vlan && group->pop_vlan) {
2280 monitor_printf(mon, " pop vlan");
2283 if (group->has_out_pport) {
2284 monitor_printf(mon, " out pport %d", group->out_pport);
2287 if (group->has_group_ids) {
2288 struct uint32List *id;
2290 monitor_printf(mon, " groups [");
2291 for (id = group->group_ids; id; id = id->next) {
2292 monitor_printf(mon, "0x%08x", id->value);
2294 monitor_printf(mon, ",");
2297 monitor_printf(mon, "]");
2300 monitor_printf(mon, "\n");
2303 qapi_free_RockerOfDpaGroupList(list);