i386: kvmvapic: initialise imm32 variable
[qemu/ar7.git] / hmp.c
blobd51023667753d2b3b97c2204196712a4f2da3089
1 /*
2 * Human Monitor Interface
4 * Copyright IBM, Corp. 2011
6 * Authors:
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"
17 #include "hmp.h"
18 #include "net/net.h"
19 #include "net/eth.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"
36 #include "qemu-io.h"
37 #include "qemu/cutils.h"
39 #ifdef CONFIG_SPICE
40 #include <spice/enums.h>
41 #endif
43 static void hmp_handle_error(Monitor *mon, Error **errp)
45 assert(errp);
46 if (*errp) {
47 error_report_err(*errp);
51 void hmp_info_name(Monitor *mon, const QDict *qdict)
53 NameInfo *info;
55 info = qmp_query_name(NULL);
56 if (info->has_name) {
57 monitor_printf(mon, "%s\n", info->name);
59 qapi_free_NameInfo(info);
62 void hmp_info_version(Monitor *mon, const QDict *qdict)
64 VersionInfo *info;
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,
70 info->package);
72 qapi_free_VersionInfo(info);
75 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
77 KvmInfo *info;
79 info = qmp_query_kvm(NULL);
80 monitor_printf(mon, "kvm support: ");
81 if (info->present) {
82 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
83 } else {
84 monitor_printf(mon, "not compiled\n");
87 qapi_free_KvmInfo(info);
90 void hmp_info_status(Monitor *mon, const QDict *qdict)
92 StatusInfo *info;
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)
111 UuidInfo *info;
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);
136 if (!mice_list) {
137 monitor_printf(mon, "No mouse devices connected\n");
138 return;
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)
153 MigrationInfo *info;
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",
174 info->total_time);
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",
181 info->downtime);
183 if (info->has_setup_time) {
184 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
185 info->setup_time);
189 if (info->has_ram) {
190 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
191 info->ram->transferred >> 10);
192 monitor_printf(mon, "throughput: %0.2f mbps\n",
193 info->ram->mbps);
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",
201 info->ram->skipped);
202 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
203 info->ram->normal);
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);
253 if (caps) {
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);
272 if (params) {
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) {
308 int active = ' ';
310 if (cpu->value->CPU == monitor_get_cpu_index()) {
311 active = '*';
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);
319 break;
320 case CPU_INFO_ARCH_PPC:
321 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->u.ppc.nip);
322 break;
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);
328 break;
329 case CPU_INFO_ARCH_MIPS:
330 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.q_mips.PC);
331 break;
332 case CPU_INFO_ARCH_TRICORE:
333 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.tricore.PC);
334 break;
335 default:
336 break;
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);
356 if (info) {
357 monitor_printf(mon, "%s", info->device);
358 if (inserted && inserted->has_node_name) {
359 monitor_printf(mon, " (%s)", inserted->node_name);
361 } else {
362 assert(inserted);
363 monitor_printf(mon, "%s",
364 inserted->has_node_name
365 ? inserted->node_name
366 : "<anonymous>");
369 if (inserted) {
370 monitor_printf(mon, ": %s (%s%s%s)\n",
371 inserted->file,
372 inserted->drv,
373 inserted->ro ? ", read-only" : "",
374 inserted->encrypted ? ", encrypted" : "");
375 } else {
376 monitor_printf(mon, ": [not inserted]\n");
379 if (info) {
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");
393 if (!inserted) {
394 return;
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) {
403 monitor_printf(mon,
404 " Backing file: %s "
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
420 " bps_max=%" PRId64
421 " bps_rd_max=%" PRId64
422 " bps_wr_max=%" PRId64
423 " iops=%" PRId64 " iops_rd=%" PRId64
424 " iops_wr=%" PRId64
425 " iops_max=%" PRId64
426 " iops_rd_max=%" PRId64
427 " iops_wr_max=%" PRId64
428 " iops_size=%" PRId64
429 " group=%s\n",
430 inserted->bps,
431 inserted->bps_rd,
432 inserted->bps_wr,
433 inserted->bps_max,
434 inserted->bps_rd_max,
435 inserted->bps_wr_max,
436 inserted->iops,
437 inserted->iops_rd,
438 inserted->iops_wr,
439 inserted->iops_max,
440 inserted->iops_rd_max,
441 inserted->iops_wr_max,
442 inserted->iops_size,
443 inserted->group);
446 if (verbose) {
447 monitor_printf(mon, "\nImages:\n");
448 image_info = inserted->image;
449 while (1) {
450 bdrv_image_info_dump((fprintf_function)monitor_printf,
451 mon, image_info);
452 if (image_info->has_backing_image) {
453 image_info = image_info->backing_image;
454 } else {
455 break;
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 */
471 if (!nodes) {
472 block_list = qmp_query_block(NULL);
473 } else {
474 block_list = NULL;
477 for (info = block_list; info; info = info->next) {
478 if (device && strcmp(device, info->value->device)) {
479 continue;
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,
488 verbose);
489 printed = true;
492 qapi_free_BlockInfoList(block_list);
494 if ((!device && !nodes) || printed) {
495 return;
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)) {
503 continue;
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) {
523 continue;
526 monitor_printf(mon, "%s:", stats->value->device);
527 monitor_printf(mon, " rd_bytes=%" PRId64
528 " wr_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
538 "\n",
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)
557 VncInfo *info;
558 Error *err = NULL;
559 VncClientInfoList *client;
561 info = qmp_query_vnc(&err);
562 if (err) {
563 error_report_err(err);
564 return;
567 if (!info->enabled) {
568 monitor_printf(mon, "Server: disabled\n");
569 goto out;
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");
582 } else {
583 for (client = info->clients; client; client = client->next) {
584 monitor_printf(mon, "Client:\n");
585 monitor_printf(mon, " address: %s:%s\n",
586 client->value->host,
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");
597 out:
598 qapi_free_VncInfo(info);
601 #ifdef CONFIG_SPICE
602 void hmp_info_spice(Monitor *mon, const QDict *qdict)
604 SpiceChannelList *chan;
605 SpiceInfo *info;
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",
618 #if 0
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",
623 #endif
626 info = qmp_query_spice(NULL);
628 if (!info->enabled) {
629 monitor_printf(mon, "Server: disabled\n");
630 goto out;
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");
651 } else {
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);
673 out:
674 qapi_free_SpiceInfo(info);
676 #endif
678 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
680 BalloonInfo *info;
681 Error *err = NULL;
683 info = qmp_query_balloon(&err);
684 if (err) {
685 error_report_err(err);
686 return;
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);
705 } else {
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);
712 if (dev->has_irq) {
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);
728 monitor_printf(mon,
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) {
740 uint64_t addr, size;
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);
751 } else {
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;
775 Error *err = NULL;
777 info_list = qmp_query_pci(&err);
778 if (err) {
779 monitor_printf(mon, "PCI devices not supported\n");
780 error_free(err);
781 return;
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;
798 Error *err = NULL;
800 list = qmp_query_block_jobs(&err);
801 assert(!err);
803 if (!list) {
804 monitor_printf(mon, "No active jobs\n");
805 return;
808 while (list) {
809 if (strcmp(list->value->type, "stream") == 0) {
810 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
811 " of %" PRId64 " bytes, speed limit %" PRId64
812 " bytes/s\n",
813 list->value->device,
814 list->value->offset,
815 list->value->len,
816 list->value->speed);
817 } else {
818 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
819 " of %" PRId64 " bytes, speed limit %" PRId64
820 " bytes/s\n",
821 list->value->type,
822 list->value->device,
823 list->value->offset,
824 list->value->len,
825 list->value->speed);
827 list = list->next;
830 qapi_free_BlockJobInfoList(list);
833 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
835 TPMInfoList *info_list, *info;
836 Error *err = NULL;
837 unsigned int c = 0;
838 TPMPassthroughOptions *tpo;
840 info_list = qmp_query_tpm(&err);
841 if (err) {
842 monitor_printf(mon, "TPM device not supported\n");
843 error_free(err);
844 return;
847 if (info_list) {
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 : "");
867 break;
868 case TPM_TYPE_OPTIONS_KIND__MAX:
869 break;
871 monitor_printf(mon, "\n");
872 c++;
874 qapi_free_TPMInfoList(info_list);
877 void hmp_quit(Monitor *mon, const QDict *qdict)
879 monitor_suspend(mon);
880 qmp_quit(NULL);
883 void hmp_stop(Monitor *mon, const QDict *qdict)
885 qmp_stop(NULL);
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)
900 int64_t cpu_index;
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");
915 Error *err = NULL;
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");
926 Error *err = NULL;
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");
936 Error *err = NULL;
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");
947 char *data;
948 Error *err = NULL;
949 int i;
951 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
952 if (err) {
953 error_report_err(err);
954 return;
957 for (i = 0; data[i]; i++) {
958 unsigned char ch = data[i];
960 if (ch == '\\') {
961 monitor_printf(mon, "\\\\");
962 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
963 monitor_printf(mon, "\\u%04X", ch);
964 } else {
965 monitor_printf(mon, "%c", ch);
969 monitor_printf(mon, "\n");
970 g_free(data);
973 static void hmp_cont_cb(void *opaque, int err)
975 if (!err) {
976 qmp_cont(NULL);
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;
988 Error *err = NULL;
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,
994 hmp_cont_cb, NULL);
995 goto out;
999 qmp_cont(&err);
1000 hmp_handle_error(mon, &err);
1002 out:
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)
1013 Error *err = NULL;
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");
1023 Error *err = NULL;
1025 qmp_set_link(name, up, &err);
1026 hmp_handle_error(mon, &err);
1029 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1031 const char *device = qdict_get_str(qdict, "device");
1032 const char *password = qdict_get_str(qdict, "password");
1033 Error *err = NULL;
1035 qmp_block_passwd(true, device, false, NULL, password, &err);
1036 hmp_handle_error(mon, &err);
1039 void hmp_balloon(Monitor *mon, const QDict *qdict)
1041 int64_t value = qdict_get_int(qdict, "value");
1042 Error *err = NULL;
1044 qmp_balloon(value, &err);
1045 if (err) {
1046 error_report_err(err);
1050 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1052 const char *device = qdict_get_str(qdict, "device");
1053 int64_t size = qdict_get_int(qdict, "size");
1054 Error *err = NULL;
1056 qmp_block_resize(true, device, false, NULL, size, &err);
1057 hmp_handle_error(mon, &err);
1060 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1062 const char *device = qdict_get_str(qdict, "device");
1063 const char *filename = qdict_get_str(qdict, "target");
1064 const char *format = qdict_get_try_str(qdict, "format");
1065 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1066 bool full = qdict_get_try_bool(qdict, "full", false);
1067 enum NewImageMode mode;
1068 Error *err = NULL;
1070 if (!filename) {
1071 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1072 hmp_handle_error(mon, &err);
1073 return;
1076 if (reuse) {
1077 mode = NEW_IMAGE_MODE_EXISTING;
1078 } else {
1079 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1082 qmp_drive_mirror(device, filename, !!format, format,
1083 false, NULL, false, NULL,
1084 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1085 true, mode, false, 0, false, 0, false, 0,
1086 false, 0, false, 0, false, true, &err);
1087 hmp_handle_error(mon, &err);
1090 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1092 const char *device = qdict_get_str(qdict, "device");
1093 const char *filename = qdict_get_str(qdict, "target");
1094 const char *format = qdict_get_try_str(qdict, "format");
1095 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1096 bool full = qdict_get_try_bool(qdict, "full", false);
1097 enum NewImageMode mode;
1098 Error *err = NULL;
1100 if (!filename) {
1101 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1102 hmp_handle_error(mon, &err);
1103 return;
1106 if (reuse) {
1107 mode = NEW_IMAGE_MODE_EXISTING;
1108 } else {
1109 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1112 qmp_drive_backup(device, filename, !!format, format,
1113 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1114 true, mode, false, 0, false, NULL,
1115 false, 0, false, 0, &err);
1116 hmp_handle_error(mon, &err);
1119 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1121 const char *device = qdict_get_str(qdict, "device");
1122 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1123 const char *format = qdict_get_try_str(qdict, "format");
1124 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1125 enum NewImageMode mode;
1126 Error *err = NULL;
1128 if (!filename) {
1129 /* In the future, if 'snapshot-file' is not specified, the snapshot
1130 will be taken internally. Today it's actually required. */
1131 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1132 hmp_handle_error(mon, &err);
1133 return;
1136 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1137 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1138 filename, false, NULL,
1139 !!format, format,
1140 true, mode, &err);
1141 hmp_handle_error(mon, &err);
1144 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1146 const char *device = qdict_get_str(qdict, "device");
1147 const char *name = qdict_get_str(qdict, "name");
1148 Error *err = NULL;
1150 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1151 hmp_handle_error(mon, &err);
1154 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1156 const char *device = qdict_get_str(qdict, "device");
1157 const char *name = qdict_get_str(qdict, "name");
1158 const char *id = qdict_get_try_str(qdict, "id");
1159 Error *err = NULL;
1161 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1162 true, name, &err);
1163 hmp_handle_error(mon, &err);
1166 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1168 qmp_migrate_cancel(NULL);
1171 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1173 Error *err = NULL;
1174 const char *uri = qdict_get_str(qdict, "uri");
1176 qmp_migrate_incoming(uri, &err);
1178 hmp_handle_error(mon, &err);
1181 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1183 double value = qdict_get_double(qdict, "value");
1184 qmp_migrate_set_downtime(value, NULL);
1187 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1189 int64_t value = qdict_get_int(qdict, "value");
1190 Error *err = NULL;
1192 qmp_migrate_set_cache_size(value, &err);
1193 if (err) {
1194 error_report_err(err);
1195 return;
1199 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1201 int64_t value = qdict_get_int(qdict, "value");
1202 qmp_migrate_set_speed(value, NULL);
1205 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1207 const char *cap = qdict_get_str(qdict, "capability");
1208 bool state = qdict_get_bool(qdict, "state");
1209 Error *err = NULL;
1210 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1211 int i;
1213 for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
1214 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1215 caps->value = g_malloc0(sizeof(*caps->value));
1216 caps->value->capability = i;
1217 caps->value->state = state;
1218 caps->next = NULL;
1219 qmp_migrate_set_capabilities(caps, &err);
1220 break;
1224 if (i == MIGRATION_CAPABILITY__MAX) {
1225 error_setg(&err, QERR_INVALID_PARAMETER, cap);
1228 qapi_free_MigrationCapabilityStatusList(caps);
1230 if (err) {
1231 error_report_err(err);
1235 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1237 const char *param = qdict_get_str(qdict, "parameter");
1238 int value = qdict_get_int(qdict, "value");
1239 Error *err = NULL;
1240 bool has_compress_level = false;
1241 bool has_compress_threads = false;
1242 bool has_decompress_threads = false;
1243 bool has_x_cpu_throttle_initial = false;
1244 bool has_x_cpu_throttle_increment = false;
1245 int i;
1247 for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
1248 if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
1249 switch (i) {
1250 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1251 has_compress_level = true;
1252 break;
1253 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1254 has_compress_threads = true;
1255 break;
1256 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1257 has_decompress_threads = true;
1258 break;
1259 case MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL:
1260 has_x_cpu_throttle_initial = true;
1261 break;
1262 case MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT:
1263 has_x_cpu_throttle_increment = true;
1264 break;
1266 qmp_migrate_set_parameters(has_compress_level, value,
1267 has_compress_threads, value,
1268 has_decompress_threads, value,
1269 has_x_cpu_throttle_initial, value,
1270 has_x_cpu_throttle_increment, value,
1271 &err);
1272 break;
1276 if (i == MIGRATION_PARAMETER__MAX) {
1277 error_setg(&err, QERR_INVALID_PARAMETER, param);
1280 if (err) {
1281 error_report_err(err);
1285 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1287 Error *err = NULL;
1288 const char *protocol = qdict_get_str(qdict, "protocol");
1289 const char *hostname = qdict_get_str(qdict, "hostname");
1290 bool has_port = qdict_haskey(qdict, "port");
1291 int port = qdict_get_try_int(qdict, "port", -1);
1292 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1293 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1294 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1296 qmp_client_migrate_info(protocol, hostname,
1297 has_port, port, has_tls_port, tls_port,
1298 !!cert_subject, cert_subject, &err);
1299 hmp_handle_error(mon, &err);
1302 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1304 Error *err = NULL;
1305 qmp_migrate_start_postcopy(&err);
1306 hmp_handle_error(mon, &err);
1309 void hmp_set_password(Monitor *mon, const QDict *qdict)
1311 const char *protocol = qdict_get_str(qdict, "protocol");
1312 const char *password = qdict_get_str(qdict, "password");
1313 const char *connected = qdict_get_try_str(qdict, "connected");
1314 Error *err = NULL;
1316 qmp_set_password(protocol, password, !!connected, connected, &err);
1317 hmp_handle_error(mon, &err);
1320 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1322 const char *protocol = qdict_get_str(qdict, "protocol");
1323 const char *whenstr = qdict_get_str(qdict, "time");
1324 Error *err = NULL;
1326 qmp_expire_password(protocol, whenstr, &err);
1327 hmp_handle_error(mon, &err);
1330 void hmp_eject(Monitor *mon, const QDict *qdict)
1332 bool force = qdict_get_try_bool(qdict, "force", false);
1333 const char *device = qdict_get_str(qdict, "device");
1334 Error *err = NULL;
1336 qmp_eject(device, true, force, &err);
1337 hmp_handle_error(mon, &err);
1340 static void hmp_change_read_arg(void *opaque, const char *password,
1341 void *readline_opaque)
1343 qmp_change_vnc_password(password, NULL);
1344 monitor_read_command(opaque, 1);
1347 void hmp_change(Monitor *mon, const QDict *qdict)
1349 const char *device = qdict_get_str(qdict, "device");
1350 const char *target = qdict_get_str(qdict, "target");
1351 const char *arg = qdict_get_try_str(qdict, "arg");
1352 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1353 BlockdevChangeReadOnlyMode read_only_mode = 0;
1354 Error *err = NULL;
1356 if (strcmp(device, "vnc") == 0) {
1357 if (read_only) {
1358 monitor_printf(mon,
1359 "Parameter 'read-only-mode' is invalid for VNC\n");
1360 return;
1362 if (strcmp(target, "passwd") == 0 ||
1363 strcmp(target, "password") == 0) {
1364 if (!arg) {
1365 monitor_read_password(mon, hmp_change_read_arg, NULL);
1366 return;
1369 qmp_change("vnc", target, !!arg, arg, &err);
1370 } else {
1371 if (read_only) {
1372 read_only_mode =
1373 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup,
1374 read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX,
1375 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1376 if (err) {
1377 hmp_handle_error(mon, &err);
1378 return;
1382 qmp_blockdev_change_medium(device, target, !!arg, arg,
1383 !!read_only, read_only_mode, &err);
1384 if (err &&
1385 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
1386 error_free(err);
1387 monitor_read_block_device_key(mon, device, NULL, NULL);
1388 return;
1392 hmp_handle_error(mon, &err);
1395 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1397 Error *err = NULL;
1399 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
1400 qdict_get_int(qdict, "bps"),
1401 qdict_get_int(qdict, "bps_rd"),
1402 qdict_get_int(qdict, "bps_wr"),
1403 qdict_get_int(qdict, "iops"),
1404 qdict_get_int(qdict, "iops_rd"),
1405 qdict_get_int(qdict, "iops_wr"),
1406 false, /* no burst max via HMP */
1408 false,
1410 false,
1412 false,
1414 false,
1416 false,
1418 false, /* no burst length via HMP */
1420 false,
1422 false,
1424 false,
1426 false,
1428 false,
1430 false, /* No default I/O size */
1432 false,
1433 NULL, &err);
1434 hmp_handle_error(mon, &err);
1437 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1439 Error *error = NULL;
1440 const char *device = qdict_get_str(qdict, "device");
1441 const char *base = qdict_get_try_str(qdict, "base");
1442 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1444 qmp_block_stream(device, base != NULL, base, false, NULL,
1445 qdict_haskey(qdict, "speed"), speed,
1446 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1448 hmp_handle_error(mon, &error);
1451 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1453 Error *error = NULL;
1454 const char *device = qdict_get_str(qdict, "device");
1455 int64_t value = qdict_get_int(qdict, "speed");
1457 qmp_block_job_set_speed(device, value, &error);
1459 hmp_handle_error(mon, &error);
1462 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1464 Error *error = NULL;
1465 const char *device = qdict_get_str(qdict, "device");
1466 bool force = qdict_get_try_bool(qdict, "force", false);
1468 qmp_block_job_cancel(device, true, force, &error);
1470 hmp_handle_error(mon, &error);
1473 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1475 Error *error = NULL;
1476 const char *device = qdict_get_str(qdict, "device");
1478 qmp_block_job_pause(device, &error);
1480 hmp_handle_error(mon, &error);
1483 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1485 Error *error = NULL;
1486 const char *device = qdict_get_str(qdict, "device");
1488 qmp_block_job_resume(device, &error);
1490 hmp_handle_error(mon, &error);
1493 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1495 Error *error = NULL;
1496 const char *device = qdict_get_str(qdict, "device");
1498 qmp_block_job_complete(device, &error);
1500 hmp_handle_error(mon, &error);
1503 typedef struct HMPMigrationStatus
1505 QEMUTimer *timer;
1506 Monitor *mon;
1507 bool is_block_migration;
1508 } HMPMigrationStatus;
1510 static void hmp_migrate_status_cb(void *opaque)
1512 HMPMigrationStatus *status = opaque;
1513 MigrationInfo *info;
1515 info = qmp_query_migrate(NULL);
1516 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1517 info->status == MIGRATION_STATUS_SETUP) {
1518 if (info->has_disk) {
1519 int progress;
1521 if (info->disk->remaining) {
1522 progress = info->disk->transferred * 100 / info->disk->total;
1523 } else {
1524 progress = 100;
1527 monitor_printf(status->mon, "Completed %d %%\r", progress);
1528 monitor_flush(status->mon);
1531 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1532 } else {
1533 if (status->is_block_migration) {
1534 monitor_printf(status->mon, "\n");
1536 monitor_resume(status->mon);
1537 timer_del(status->timer);
1538 g_free(status);
1541 qapi_free_MigrationInfo(info);
1544 void hmp_migrate(Monitor *mon, const QDict *qdict)
1546 bool detach = qdict_get_try_bool(qdict, "detach", false);
1547 bool blk = qdict_get_try_bool(qdict, "blk", false);
1548 bool inc = qdict_get_try_bool(qdict, "inc", false);
1549 const char *uri = qdict_get_str(qdict, "uri");
1550 Error *err = NULL;
1552 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1553 if (err) {
1554 error_report_err(err);
1555 return;
1558 if (!detach) {
1559 HMPMigrationStatus *status;
1561 if (monitor_suspend(mon) < 0) {
1562 monitor_printf(mon, "terminal does not allow synchronous "
1563 "migration, continuing detached\n");
1564 return;
1567 status = g_malloc0(sizeof(*status));
1568 status->mon = mon;
1569 status->is_block_migration = blk || inc;
1570 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1571 status);
1572 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1576 void hmp_device_add(Monitor *mon, const QDict *qdict)
1578 Error *err = NULL;
1580 qmp_device_add((QDict *)qdict, NULL, &err);
1581 hmp_handle_error(mon, &err);
1584 void hmp_device_del(Monitor *mon, const QDict *qdict)
1586 const char *id = qdict_get_str(qdict, "id");
1587 Error *err = NULL;
1589 qmp_device_del(id, &err);
1590 hmp_handle_error(mon, &err);
1593 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1595 Error *err = NULL;
1596 bool paging = qdict_get_try_bool(qdict, "paging", false);
1597 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
1598 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
1599 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
1600 const char *file = qdict_get_str(qdict, "filename");
1601 bool has_begin = qdict_haskey(qdict, "begin");
1602 bool has_length = qdict_haskey(qdict, "length");
1603 bool has_detach = qdict_haskey(qdict, "detach");
1604 int64_t begin = 0;
1605 int64_t length = 0;
1606 bool detach = false;
1607 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1608 char *prot;
1610 if (zlib + lzo + snappy > 1) {
1611 error_setg(&err, "only one of '-z|-l|-s' can be set");
1612 hmp_handle_error(mon, &err);
1613 return;
1616 if (zlib) {
1617 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1620 if (lzo) {
1621 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1624 if (snappy) {
1625 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1628 if (has_begin) {
1629 begin = qdict_get_int(qdict, "begin");
1631 if (has_length) {
1632 length = qdict_get_int(qdict, "length");
1634 if (has_detach) {
1635 detach = qdict_get_bool(qdict, "detach");
1638 prot = g_strconcat("file:", file, NULL);
1640 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
1641 has_length, length, true, dump_format, &err);
1642 hmp_handle_error(mon, &err);
1643 g_free(prot);
1646 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1648 Error *err = NULL;
1649 QemuOpts *opts;
1651 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1652 if (err) {
1653 goto out;
1656 netdev_add(opts, &err);
1657 if (err) {
1658 qemu_opts_del(opts);
1661 out:
1662 hmp_handle_error(mon, &err);
1665 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1667 const char *id = qdict_get_str(qdict, "id");
1668 Error *err = NULL;
1670 qmp_netdev_del(id, &err);
1671 hmp_handle_error(mon, &err);
1674 void hmp_object_add(Monitor *mon, const QDict *qdict)
1676 Error *err = NULL;
1677 QemuOpts *opts;
1678 OptsVisitor *ov;
1679 Object *obj = NULL;
1681 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1682 if (err) {
1683 hmp_handle_error(mon, &err);
1684 return;
1687 ov = opts_visitor_new(opts);
1688 obj = user_creatable_add(qdict, opts_get_visitor(ov), &err);
1689 opts_visitor_cleanup(ov);
1690 qemu_opts_del(opts);
1692 if (err) {
1693 hmp_handle_error(mon, &err);
1695 if (obj) {
1696 object_unref(obj);
1700 void hmp_getfd(Monitor *mon, const QDict *qdict)
1702 const char *fdname = qdict_get_str(qdict, "fdname");
1703 Error *err = NULL;
1705 qmp_getfd(fdname, &err);
1706 hmp_handle_error(mon, &err);
1709 void hmp_closefd(Monitor *mon, const QDict *qdict)
1711 const char *fdname = qdict_get_str(qdict, "fdname");
1712 Error *err = NULL;
1714 qmp_closefd(fdname, &err);
1715 hmp_handle_error(mon, &err);
1718 void hmp_sendkey(Monitor *mon, const QDict *qdict)
1720 const char *keys = qdict_get_str(qdict, "keys");
1721 KeyValueList *keylist, *head = NULL, *tmp = NULL;
1722 int has_hold_time = qdict_haskey(qdict, "hold-time");
1723 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1724 Error *err = NULL;
1725 char *separator;
1726 int keyname_len;
1728 while (1) {
1729 separator = strchr(keys, '-');
1730 keyname_len = separator ? separator - keys : strlen(keys);
1732 /* Be compatible with old interface, convert user inputted "<" */
1733 if (keys[0] == '<' && keyname_len == 1) {
1734 keys = "less";
1735 keyname_len = 4;
1738 keylist = g_malloc0(sizeof(*keylist));
1739 keylist->value = g_malloc0(sizeof(*keylist->value));
1741 if (!head) {
1742 head = keylist;
1744 if (tmp) {
1745 tmp->next = keylist;
1747 tmp = keylist;
1749 if (strstart(keys, "0x", NULL)) {
1750 char *endp;
1751 int value = strtoul(keys, &endp, 0);
1752 assert(endp <= keys + keyname_len);
1753 if (endp != keys + keyname_len) {
1754 goto err_out;
1756 keylist->value->type = KEY_VALUE_KIND_NUMBER;
1757 keylist->value->u.number.data = value;
1758 } else {
1759 int idx = index_from_key(keys, keyname_len);
1760 if (idx == Q_KEY_CODE__MAX) {
1761 goto err_out;
1763 keylist->value->type = KEY_VALUE_KIND_QCODE;
1764 keylist->value->u.qcode.data = idx;
1767 if (!separator) {
1768 break;
1770 keys = separator + 1;
1773 qmp_send_key(head, has_hold_time, hold_time, &err);
1774 hmp_handle_error(mon, &err);
1776 out:
1777 qapi_free_KeyValueList(head);
1778 return;
1780 err_out:
1781 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
1782 goto out;
1785 void hmp_screendump(Monitor *mon, const QDict *qdict)
1787 const char *filename = qdict_get_str(qdict, "filename");
1788 Error *err = NULL;
1790 qmp_screendump(filename, &err);
1791 hmp_handle_error(mon, &err);
1794 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1796 const char *uri = qdict_get_str(qdict, "uri");
1797 bool writable = qdict_get_try_bool(qdict, "writable", false);
1798 bool all = qdict_get_try_bool(qdict, "all", false);
1799 Error *local_err = NULL;
1800 BlockInfoList *block_list, *info;
1801 SocketAddress *addr;
1803 if (writable && !all) {
1804 error_setg(&local_err, "-w only valid together with -a");
1805 goto exit;
1808 /* First check if the address is valid and start the server. */
1809 addr = socket_parse(uri, &local_err);
1810 if (local_err != NULL) {
1811 goto exit;
1814 qmp_nbd_server_start(addr, false, NULL, &local_err);
1815 qapi_free_SocketAddress(addr);
1816 if (local_err != NULL) {
1817 goto exit;
1820 if (!all) {
1821 return;
1824 /* Then try adding all block devices. If one fails, close all and
1825 * exit.
1827 block_list = qmp_query_block(NULL);
1829 for (info = block_list; info; info = info->next) {
1830 if (!info->value->has_inserted) {
1831 continue;
1834 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1836 if (local_err != NULL) {
1837 qmp_nbd_server_stop(NULL);
1838 break;
1842 qapi_free_BlockInfoList(block_list);
1844 exit:
1845 hmp_handle_error(mon, &local_err);
1848 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1850 const char *device = qdict_get_str(qdict, "device");
1851 bool writable = qdict_get_try_bool(qdict, "writable", false);
1852 Error *local_err = NULL;
1854 qmp_nbd_server_add(device, true, writable, &local_err);
1856 if (local_err != NULL) {
1857 hmp_handle_error(mon, &local_err);
1861 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1863 Error *err = NULL;
1865 qmp_nbd_server_stop(&err);
1866 hmp_handle_error(mon, &err);
1869 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
1871 int cpuid;
1872 Error *err = NULL;
1874 cpuid = qdict_get_int(qdict, "id");
1875 qmp_cpu_add(cpuid, &err);
1876 hmp_handle_error(mon, &err);
1879 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1881 const char *args = qdict_get_str(qdict, "args");
1882 Error *err = NULL;
1883 QemuOpts *opts;
1885 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
1886 if (opts == NULL) {
1887 error_setg(&err, "Parsing chardev args failed");
1888 } else {
1889 qemu_chr_new_from_opts(opts, NULL, &err);
1891 hmp_handle_error(mon, &err);
1894 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1896 Error *local_err = NULL;
1898 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1899 hmp_handle_error(mon, &local_err);
1902 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1904 BlockBackend *blk;
1905 const char* device = qdict_get_str(qdict, "device");
1906 const char* command = qdict_get_str(qdict, "command");
1907 Error *err = NULL;
1909 blk = blk_by_name(device);
1910 if (blk) {
1911 qemuio_command(blk, command);
1912 } else {
1913 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
1914 "Device '%s' not found", device);
1917 hmp_handle_error(mon, &err);
1920 void hmp_object_del(Monitor *mon, const QDict *qdict)
1922 const char *id = qdict_get_str(qdict, "id");
1923 Error *err = NULL;
1925 user_creatable_del(id, &err);
1926 hmp_handle_error(mon, &err);
1929 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
1931 Error *err = NULL;
1932 MemdevList *memdev_list = qmp_query_memdev(&err);
1933 MemdevList *m = memdev_list;
1934 StringOutputVisitor *ov;
1935 char *str;
1936 int i = 0;
1939 while (m) {
1940 ov = string_output_visitor_new(false);
1941 visit_type_uint16List(string_output_get_visitor(ov), NULL,
1942 &m->value->host_nodes, NULL);
1943 monitor_printf(mon, "memory backend: %d\n", i);
1944 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
1945 monitor_printf(mon, " merge: %s\n",
1946 m->value->merge ? "true" : "false");
1947 monitor_printf(mon, " dump: %s\n",
1948 m->value->dump ? "true" : "false");
1949 monitor_printf(mon, " prealloc: %s\n",
1950 m->value->prealloc ? "true" : "false");
1951 monitor_printf(mon, " policy: %s\n",
1952 HostMemPolicy_lookup[m->value->policy]);
1953 str = string_output_get_string(ov);
1954 monitor_printf(mon, " host nodes: %s\n", str);
1956 g_free(str);
1957 string_output_visitor_cleanup(ov);
1958 m = m->next;
1959 i++;
1962 monitor_printf(mon, "\n");
1964 qapi_free_MemdevList(memdev_list);
1967 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
1969 Error *err = NULL;
1970 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
1971 MemoryDeviceInfoList *info;
1972 MemoryDeviceInfo *value;
1973 PCDIMMDeviceInfo *di;
1975 for (info = info_list; info; info = info->next) {
1976 value = info->value;
1978 if (value) {
1979 switch (value->type) {
1980 case MEMORY_DEVICE_INFO_KIND_DIMM:
1981 di = value->u.dimm.data;
1983 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1984 MemoryDeviceInfoKind_lookup[value->type],
1985 di->id ? di->id : "");
1986 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
1987 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
1988 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
1989 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
1990 monitor_printf(mon, " memdev: %s\n", di->memdev);
1991 monitor_printf(mon, " hotplugged: %s\n",
1992 di->hotplugged ? "true" : "false");
1993 monitor_printf(mon, " hotpluggable: %s\n",
1994 di->hotpluggable ? "true" : "false");
1995 break;
1996 default:
1997 break;
2002 qapi_free_MemoryDeviceInfoList(info_list);
2005 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2007 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2008 IOThreadInfoList *info;
2010 for (info = info_list; info; info = info->next) {
2011 monitor_printf(mon, "%s: thread_id=%" PRId64 "\n",
2012 info->value->id, info->value->thread_id);
2015 qapi_free_IOThreadInfoList(info_list);
2018 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2020 const char *path = qdict_get_try_str(qdict, "path");
2021 ObjectPropertyInfoList *list;
2022 Error *err = NULL;
2024 if (path == NULL) {
2025 monitor_printf(mon, "/\n");
2026 return;
2029 list = qmp_qom_list(path, &err);
2030 if (err == NULL) {
2031 ObjectPropertyInfoList *start = list;
2032 while (list != NULL) {
2033 ObjectPropertyInfo *value = list->value;
2035 monitor_printf(mon, "%s (%s)\n",
2036 value->name, value->type);
2037 list = list->next;
2039 qapi_free_ObjectPropertyInfoList(start);
2041 hmp_handle_error(mon, &err);
2044 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2046 const char *path = qdict_get_str(qdict, "path");
2047 const char *property = qdict_get_str(qdict, "property");
2048 const char *value = qdict_get_str(qdict, "value");
2049 Error *err = NULL;
2050 bool ambiguous = false;
2051 Object *obj;
2053 obj = object_resolve_path(path, &ambiguous);
2054 if (obj == NULL) {
2055 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2056 "Device '%s' not found", path);
2057 } else {
2058 if (ambiguous) {
2059 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2061 object_property_parse(obj, value, property, &err);
2063 hmp_handle_error(mon, &err);
2066 void hmp_rocker(Monitor *mon, const QDict *qdict)
2068 const char *name = qdict_get_str(qdict, "name");
2069 RockerSwitch *rocker;
2070 Error *err = NULL;
2072 rocker = qmp_query_rocker(name, &err);
2073 if (err != NULL) {
2074 hmp_handle_error(mon, &err);
2075 return;
2078 monitor_printf(mon, "name: %s\n", rocker->name);
2079 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2080 monitor_printf(mon, "ports: %d\n", rocker->ports);
2082 qapi_free_RockerSwitch(rocker);
2085 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2087 RockerPortList *list, *port;
2088 const char *name = qdict_get_str(qdict, "name");
2089 Error *err = NULL;
2091 list = qmp_query_rocker_ports(name, &err);
2092 if (err != NULL) {
2093 hmp_handle_error(mon, &err);
2094 return;
2097 monitor_printf(mon, " ena/ speed/ auto\n");
2098 monitor_printf(mon, " port link duplex neg?\n");
2100 for (port = list; port; port = port->next) {
2101 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2102 port->value->name,
2103 port->value->enabled ? port->value->link_up ?
2104 "up" : "down" : "!ena",
2105 port->value->speed == 10000 ? "10G" : "??",
2106 port->value->duplex ? "FD" : "HD",
2107 port->value->autoneg ? "Yes" : "No");
2110 qapi_free_RockerPortList(list);
2113 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2115 RockerOfDpaFlowList *list, *info;
2116 const char *name = qdict_get_str(qdict, "name");
2117 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2118 Error *err = NULL;
2120 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2121 if (err != NULL) {
2122 hmp_handle_error(mon, &err);
2123 return;
2126 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2128 for (info = list; info; info = info->next) {
2129 RockerOfDpaFlow *flow = info->value;
2130 RockerOfDpaFlowKey *key = flow->key;
2131 RockerOfDpaFlowMask *mask = flow->mask;
2132 RockerOfDpaFlowAction *action = flow->action;
2134 if (flow->hits) {
2135 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2136 key->priority, key->tbl_id, flow->hits);
2137 } else {
2138 monitor_printf(mon, "%-4d %-3d ",
2139 key->priority, key->tbl_id);
2142 if (key->has_in_pport) {
2143 monitor_printf(mon, " pport %d", key->in_pport);
2144 if (mask->has_in_pport) {
2145 monitor_printf(mon, "(0x%x)", mask->in_pport);
2149 if (key->has_vlan_id) {
2150 monitor_printf(mon, " vlan %d",
2151 key->vlan_id & VLAN_VID_MASK);
2152 if (mask->has_vlan_id) {
2153 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2157 if (key->has_tunnel_id) {
2158 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2159 if (mask->has_tunnel_id) {
2160 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2164 if (key->has_eth_type) {
2165 switch (key->eth_type) {
2166 case 0x0806:
2167 monitor_printf(mon, " ARP");
2168 break;
2169 case 0x0800:
2170 monitor_printf(mon, " IP");
2171 break;
2172 case 0x86dd:
2173 monitor_printf(mon, " IPv6");
2174 break;
2175 case 0x8809:
2176 monitor_printf(mon, " LACP");
2177 break;
2178 case 0x88cc:
2179 monitor_printf(mon, " LLDP");
2180 break;
2181 default:
2182 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2183 break;
2187 if (key->has_eth_src) {
2188 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2189 (mask->has_eth_src) &&
2190 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2191 monitor_printf(mon, " src <any mcast/bcast>");
2192 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2193 (mask->has_eth_src) &&
2194 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2195 monitor_printf(mon, " src <any ucast>");
2196 } else {
2197 monitor_printf(mon, " src %s", key->eth_src);
2198 if (mask->has_eth_src) {
2199 monitor_printf(mon, "(%s)", mask->eth_src);
2204 if (key->has_eth_dst) {
2205 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2206 (mask->has_eth_dst) &&
2207 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2208 monitor_printf(mon, " dst <any mcast/bcast>");
2209 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2210 (mask->has_eth_dst) &&
2211 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2212 monitor_printf(mon, " dst <any ucast>");
2213 } else {
2214 monitor_printf(mon, " dst %s", key->eth_dst);
2215 if (mask->has_eth_dst) {
2216 monitor_printf(mon, "(%s)", mask->eth_dst);
2221 if (key->has_ip_proto) {
2222 monitor_printf(mon, " proto %d", key->ip_proto);
2223 if (mask->has_ip_proto) {
2224 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2228 if (key->has_ip_tos) {
2229 monitor_printf(mon, " TOS %d", key->ip_tos);
2230 if (mask->has_ip_tos) {
2231 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2235 if (key->has_ip_dst) {
2236 monitor_printf(mon, " dst %s", key->ip_dst);
2239 if (action->has_goto_tbl || action->has_group_id ||
2240 action->has_new_vlan_id) {
2241 monitor_printf(mon, " -->");
2244 if (action->has_new_vlan_id) {
2245 monitor_printf(mon, " apply new vlan %d",
2246 ntohs(action->new_vlan_id));
2249 if (action->has_group_id) {
2250 monitor_printf(mon, " write group 0x%08x", action->group_id);
2253 if (action->has_goto_tbl) {
2254 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2257 monitor_printf(mon, "\n");
2260 qapi_free_RockerOfDpaFlowList(list);
2263 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2265 RockerOfDpaGroupList *list, *g;
2266 const char *name = qdict_get_str(qdict, "name");
2267 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2268 Error *err = NULL;
2269 bool set = false;
2271 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2272 if (err != NULL) {
2273 hmp_handle_error(mon, &err);
2274 return;
2277 monitor_printf(mon, "id (decode) --> buckets\n");
2279 for (g = list; g; g = g->next) {
2280 RockerOfDpaGroup *group = g->value;
2282 monitor_printf(mon, "0x%08x", group->id);
2284 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2285 group->type == 1 ? "L2 rewrite" :
2286 group->type == 2 ? "L3 unicast" :
2287 group->type == 3 ? "L2 multicast" :
2288 group->type == 4 ? "L2 flood" :
2289 group->type == 5 ? "L3 interface" :
2290 group->type == 6 ? "L3 multicast" :
2291 group->type == 7 ? "L3 ECMP" :
2292 group->type == 8 ? "L2 overlay" :
2293 "unknown");
2295 if (group->has_vlan_id) {
2296 monitor_printf(mon, " vlan %d", group->vlan_id);
2299 if (group->has_pport) {
2300 monitor_printf(mon, " pport %d", group->pport);
2303 if (group->has_index) {
2304 monitor_printf(mon, " index %d", group->index);
2307 monitor_printf(mon, ") -->");
2309 if (group->has_set_vlan_id && group->set_vlan_id) {
2310 set = true;
2311 monitor_printf(mon, " set vlan %d",
2312 group->set_vlan_id & VLAN_VID_MASK);
2315 if (group->has_set_eth_src) {
2316 if (!set) {
2317 set = true;
2318 monitor_printf(mon, " set");
2320 monitor_printf(mon, " src %s", group->set_eth_src);
2323 if (group->has_set_eth_dst) {
2324 if (!set) {
2325 set = true;
2326 monitor_printf(mon, " set");
2328 monitor_printf(mon, " dst %s", group->set_eth_dst);
2331 set = false;
2333 if (group->has_ttl_check && group->ttl_check) {
2334 monitor_printf(mon, " check TTL");
2337 if (group->has_group_id && group->group_id) {
2338 monitor_printf(mon, " group id 0x%08x", group->group_id);
2341 if (group->has_pop_vlan && group->pop_vlan) {
2342 monitor_printf(mon, " pop vlan");
2345 if (group->has_out_pport) {
2346 monitor_printf(mon, " out pport %d", group->out_pport);
2349 if (group->has_group_ids) {
2350 struct uint32List *id;
2352 monitor_printf(mon, " groups [");
2353 for (id = group->group_ids; id; id = id->next) {
2354 monitor_printf(mon, "0x%08x", id->value);
2355 if (id->next) {
2356 monitor_printf(mon, ",");
2359 monitor_printf(mon, "]");
2362 monitor_printf(mon, "\n");
2365 qapi_free_RockerOfDpaGroupList(list);
2368 void hmp_info_dump(Monitor *mon, const QDict *qdict)
2370 DumpQueryResult *result = qmp_query_dump(NULL);
2372 assert(result && result->status < DUMP_STATUS__MAX);
2373 monitor_printf(mon, "Status: %s\n", DumpStatus_lookup[result->status]);
2375 if (result->status == DUMP_STATUS_ACTIVE) {
2376 float percent = 0;
2377 assert(result->total != 0);
2378 percent = 100.0 * result->completed / result->total;
2379 monitor_printf(mon, "Finished: %.2f %%\n", percent);
2382 qapi_free_DumpQueryResult(result);