virtio-pci: fix 1.0 virtqueue migration
[qemu/cris-port.git] / hmp.c
blobd3812831ced63402db06822d0ed2f8af3287a6c6
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 "hmp.h"
17 #include "net/net.h"
18 #include "net/eth.h"
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/qmp/qerror.h"
29 #include "qapi/string-output-visitor.h"
30 #include "qapi/util.h"
31 #include "qapi-visit.h"
32 #include "ui/console.h"
33 #include "block/qapi.h"
34 #include "qemu-io.h"
36 #ifdef CONFIG_SPICE
37 #include <spice/enums.h>
38 #endif
40 static void hmp_handle_error(Monitor *mon, Error **errp)
42 assert(errp);
43 if (*errp) {
44 monitor_printf(mon, "%s\n", error_get_pretty(*errp));
45 error_free(*errp);
49 void hmp_info_name(Monitor *mon, const QDict *qdict)
51 NameInfo *info;
53 info = qmp_query_name(NULL);
54 if (info->has_name) {
55 monitor_printf(mon, "%s\n", info->name);
57 qapi_free_NameInfo(info);
60 void hmp_info_version(Monitor *mon, const QDict *qdict)
62 VersionInfo *info;
64 info = qmp_query_version(NULL);
66 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
67 info->qemu->major, info->qemu->minor, info->qemu->micro,
68 info->package);
70 qapi_free_VersionInfo(info);
73 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
75 KvmInfo *info;
77 info = qmp_query_kvm(NULL);
78 monitor_printf(mon, "kvm support: ");
79 if (info->present) {
80 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
81 } else {
82 monitor_printf(mon, "not compiled\n");
85 qapi_free_KvmInfo(info);
88 void hmp_info_status(Monitor *mon, const QDict *qdict)
90 StatusInfo *info;
92 info = qmp_query_status(NULL);
94 monitor_printf(mon, "VM status: %s%s",
95 info->running ? "running" : "paused",
96 info->singlestep ? " (single step mode)" : "");
98 if (!info->running && info->status != RUN_STATE_PAUSED) {
99 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
102 monitor_printf(mon, "\n");
104 qapi_free_StatusInfo(info);
107 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
109 UuidInfo *info;
111 info = qmp_query_uuid(NULL);
112 monitor_printf(mon, "%s\n", info->UUID);
113 qapi_free_UuidInfo(info);
116 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
118 ChardevInfoList *char_info, *info;
120 char_info = qmp_query_chardev(NULL);
121 for (info = char_info; info; info = info->next) {
122 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
123 info->value->filename);
126 qapi_free_ChardevInfoList(char_info);
129 void hmp_info_mice(Monitor *mon, const QDict *qdict)
131 MouseInfoList *mice_list, *mouse;
133 mice_list = qmp_query_mice(NULL);
134 if (!mice_list) {
135 monitor_printf(mon, "No mouse devices connected\n");
136 return;
139 for (mouse = mice_list; mouse; mouse = mouse->next) {
140 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
141 mouse->value->current ? '*' : ' ',
142 mouse->value->index, mouse->value->name,
143 mouse->value->absolute ? " (absolute)" : "");
146 qapi_free_MouseInfoList(mice_list);
149 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
151 MigrationInfo *info;
152 MigrationCapabilityStatusList *caps, *cap;
154 info = qmp_query_migrate(NULL);
155 caps = qmp_query_migrate_capabilities(NULL);
157 /* do not display parameters during setup */
158 if (info->has_status && caps) {
159 monitor_printf(mon, "capabilities: ");
160 for (cap = caps; cap; cap = cap->next) {
161 monitor_printf(mon, "%s: %s ",
162 MigrationCapability_lookup[cap->value->capability],
163 cap->value->state ? "on" : "off");
165 monitor_printf(mon, "\n");
168 if (info->has_status) {
169 monitor_printf(mon, "Migration status: %s\n",
170 MigrationStatus_lookup[info->status]);
171 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
172 info->total_time);
173 if (info->has_expected_downtime) {
174 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
175 info->expected_downtime);
177 if (info->has_downtime) {
178 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
179 info->downtime);
181 if (info->has_setup_time) {
182 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
183 info->setup_time);
187 if (info->has_ram) {
188 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
189 info->ram->transferred >> 10);
190 monitor_printf(mon, "throughput: %0.2f mbps\n",
191 info->ram->mbps);
192 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
193 info->ram->remaining >> 10);
194 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
195 info->ram->total >> 10);
196 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
197 info->ram->duplicate);
198 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
199 info->ram->skipped);
200 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
201 info->ram->normal);
202 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
203 info->ram->normal_bytes >> 10);
204 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
205 info->ram->dirty_sync_count);
206 if (info->ram->dirty_pages_rate) {
207 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
208 info->ram->dirty_pages_rate);
212 if (info->has_disk) {
213 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
214 info->disk->transferred >> 10);
215 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
216 info->disk->remaining >> 10);
217 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
218 info->disk->total >> 10);
221 if (info->has_xbzrle_cache) {
222 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
223 info->xbzrle_cache->cache_size);
224 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
225 info->xbzrle_cache->bytes >> 10);
226 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
227 info->xbzrle_cache->pages);
228 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
229 info->xbzrle_cache->cache_miss);
230 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
231 info->xbzrle_cache->cache_miss_rate);
232 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
233 info->xbzrle_cache->overflow);
236 if (info->has_x_cpu_throttle_percentage) {
237 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
238 info->x_cpu_throttle_percentage);
241 qapi_free_MigrationInfo(info);
242 qapi_free_MigrationCapabilityStatusList(caps);
245 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
247 MigrationCapabilityStatusList *caps, *cap;
249 caps = qmp_query_migrate_capabilities(NULL);
251 if (caps) {
252 monitor_printf(mon, "capabilities: ");
253 for (cap = caps; cap; cap = cap->next) {
254 monitor_printf(mon, "%s: %s ",
255 MigrationCapability_lookup[cap->value->capability],
256 cap->value->state ? "on" : "off");
258 monitor_printf(mon, "\n");
261 qapi_free_MigrationCapabilityStatusList(caps);
264 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
266 MigrationParameters *params;
268 params = qmp_query_migrate_parameters(NULL);
270 if (params) {
271 monitor_printf(mon, "parameters:");
272 monitor_printf(mon, " %s: %" PRId64,
273 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_LEVEL],
274 params->compress_level);
275 monitor_printf(mon, " %s: %" PRId64,
276 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_THREADS],
277 params->compress_threads);
278 monitor_printf(mon, " %s: %" PRId64,
279 MigrationParameter_lookup[MIGRATION_PARAMETER_DECOMPRESS_THREADS],
280 params->decompress_threads);
281 monitor_printf(mon, " %s: %" PRId64,
282 MigrationParameter_lookup[MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL],
283 params->x_cpu_throttle_initial);
284 monitor_printf(mon, " %s: %" PRId64,
285 MigrationParameter_lookup[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT],
286 params->x_cpu_throttle_increment);
287 monitor_printf(mon, "\n");
290 qapi_free_MigrationParameters(params);
293 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
295 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
296 qmp_query_migrate_cache_size(NULL) >> 10);
299 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
301 CpuInfoList *cpu_list, *cpu;
303 cpu_list = qmp_query_cpus(NULL);
305 for (cpu = cpu_list; cpu; cpu = cpu->next) {
306 int active = ' ';
308 if (cpu->value->CPU == monitor_get_cpu_index()) {
309 active = '*';
312 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
314 if (cpu->value->has_pc) {
315 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->pc);
317 if (cpu->value->has_nip) {
318 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->nip);
320 if (cpu->value->has_npc) {
321 monitor_printf(mon, " npc=0x%016" PRIx64, cpu->value->npc);
323 if (cpu->value->has_PC) {
324 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->PC);
327 if (cpu->value->halted) {
328 monitor_printf(mon, " (halted)");
331 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
334 qapi_free_CpuInfoList(cpu_list);
337 static void print_block_info(Monitor *mon, BlockInfo *info,
338 BlockDeviceInfo *inserted, bool verbose)
340 ImageInfo *image_info;
342 assert(!info || !info->has_inserted || info->inserted == inserted);
344 if (info) {
345 monitor_printf(mon, "%s", info->device);
346 if (inserted && inserted->has_node_name) {
347 monitor_printf(mon, " (%s)", inserted->node_name);
349 } else {
350 assert(inserted);
351 monitor_printf(mon, "%s",
352 inserted->has_node_name
353 ? inserted->node_name
354 : "<anonymous>");
357 if (inserted) {
358 monitor_printf(mon, ": %s (%s%s%s)\n",
359 inserted->file,
360 inserted->drv,
361 inserted->ro ? ", read-only" : "",
362 inserted->encrypted ? ", encrypted" : "");
363 } else {
364 monitor_printf(mon, ": [not inserted]\n");
367 if (info) {
368 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
369 monitor_printf(mon, " I/O status: %s\n",
370 BlockDeviceIoStatus_lookup[info->io_status]);
373 if (info->removable) {
374 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
375 info->locked ? "" : "not ",
376 info->tray_open ? "open" : "closed");
381 if (!inserted) {
382 return;
385 monitor_printf(mon, " Cache mode: %s%s%s\n",
386 inserted->cache->writeback ? "writeback" : "writethrough",
387 inserted->cache->direct ? ", direct" : "",
388 inserted->cache->no_flush ? ", ignore flushes" : "");
390 if (inserted->has_backing_file) {
391 monitor_printf(mon,
392 " Backing file: %s "
393 "(chain depth: %" PRId64 ")\n",
394 inserted->backing_file,
395 inserted->backing_file_depth);
398 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
399 monitor_printf(mon, " Detect zeroes: %s\n",
400 BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]);
403 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
404 inserted->iops || inserted->iops_rd || inserted->iops_wr)
406 monitor_printf(mon, " I/O throttling: bps=%" PRId64
407 " bps_rd=%" PRId64 " bps_wr=%" PRId64
408 " bps_max=%" PRId64
409 " bps_rd_max=%" PRId64
410 " bps_wr_max=%" PRId64
411 " iops=%" PRId64 " iops_rd=%" PRId64
412 " iops_wr=%" PRId64
413 " iops_max=%" PRId64
414 " iops_rd_max=%" PRId64
415 " iops_wr_max=%" PRId64
416 " iops_size=%" PRId64
417 " group=%s\n",
418 inserted->bps,
419 inserted->bps_rd,
420 inserted->bps_wr,
421 inserted->bps_max,
422 inserted->bps_rd_max,
423 inserted->bps_wr_max,
424 inserted->iops,
425 inserted->iops_rd,
426 inserted->iops_wr,
427 inserted->iops_max,
428 inserted->iops_rd_max,
429 inserted->iops_wr_max,
430 inserted->iops_size,
431 inserted->group);
434 if (verbose) {
435 monitor_printf(mon, "\nImages:\n");
436 image_info = inserted->image;
437 while (1) {
438 bdrv_image_info_dump((fprintf_function)monitor_printf,
439 mon, image_info);
440 if (image_info->has_backing_image) {
441 image_info = image_info->backing_image;
442 } else {
443 break;
449 void hmp_info_block(Monitor *mon, const QDict *qdict)
451 BlockInfoList *block_list, *info;
452 BlockDeviceInfoList *blockdev_list, *blockdev;
453 const char *device = qdict_get_try_str(qdict, "device");
454 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
455 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
456 bool printed = false;
458 /* Print BlockBackend information */
459 if (!nodes) {
460 block_list = qmp_query_block(NULL);
461 } else {
462 block_list = NULL;
465 for (info = block_list; info; info = info->next) {
466 if (device && strcmp(device, info->value->device)) {
467 continue;
470 if (info != block_list) {
471 monitor_printf(mon, "\n");
474 print_block_info(mon, info->value, info->value->has_inserted
475 ? info->value->inserted : NULL,
476 verbose);
477 printed = true;
480 qapi_free_BlockInfoList(block_list);
482 if ((!device && !nodes) || printed) {
483 return;
486 /* Print node information */
487 blockdev_list = qmp_query_named_block_nodes(NULL);
488 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
489 assert(blockdev->value->has_node_name);
490 if (device && strcmp(device, blockdev->value->node_name)) {
491 continue;
494 if (blockdev != blockdev_list) {
495 monitor_printf(mon, "\n");
498 print_block_info(mon, NULL, blockdev->value, verbose);
500 qapi_free_BlockDeviceInfoList(blockdev_list);
503 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
505 BlockStatsList *stats_list, *stats;
507 stats_list = qmp_query_blockstats(false, false, NULL);
509 for (stats = stats_list; stats; stats = stats->next) {
510 if (!stats->value->has_device) {
511 continue;
514 monitor_printf(mon, "%s:", stats->value->device);
515 monitor_printf(mon, " rd_bytes=%" PRId64
516 " wr_bytes=%" PRId64
517 " rd_operations=%" PRId64
518 " wr_operations=%" PRId64
519 " flush_operations=%" PRId64
520 " wr_total_time_ns=%" PRId64
521 " rd_total_time_ns=%" PRId64
522 " flush_total_time_ns=%" PRId64
523 " rd_merged=%" PRId64
524 " wr_merged=%" PRId64
525 "\n",
526 stats->value->stats->rd_bytes,
527 stats->value->stats->wr_bytes,
528 stats->value->stats->rd_operations,
529 stats->value->stats->wr_operations,
530 stats->value->stats->flush_operations,
531 stats->value->stats->wr_total_time_ns,
532 stats->value->stats->rd_total_time_ns,
533 stats->value->stats->flush_total_time_ns,
534 stats->value->stats->rd_merged,
535 stats->value->stats->wr_merged);
538 qapi_free_BlockStatsList(stats_list);
541 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
543 VncInfo *info;
544 Error *err = NULL;
545 VncClientInfoList *client;
547 info = qmp_query_vnc(&err);
548 if (err) {
549 monitor_printf(mon, "%s\n", error_get_pretty(err));
550 error_free(err);
551 return;
554 if (!info->enabled) {
555 monitor_printf(mon, "Server: disabled\n");
556 goto out;
559 monitor_printf(mon, "Server:\n");
560 if (info->has_host && info->has_service) {
561 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
563 if (info->has_auth) {
564 monitor_printf(mon, " auth: %s\n", info->auth);
567 if (!info->has_clients || info->clients == NULL) {
568 monitor_printf(mon, "Client: none\n");
569 } else {
570 for (client = info->clients; client; client = client->next) {
571 monitor_printf(mon, "Client:\n");
572 monitor_printf(mon, " address: %s:%s\n",
573 client->value->host,
574 client->value->service);
575 monitor_printf(mon, " x509_dname: %s\n",
576 client->value->x509_dname ?
577 client->value->x509_dname : "none");
578 monitor_printf(mon, " username: %s\n",
579 client->value->has_sasl_username ?
580 client->value->sasl_username : "none");
584 out:
585 qapi_free_VncInfo(info);
588 #ifdef CONFIG_SPICE
589 void hmp_info_spice(Monitor *mon, const QDict *qdict)
591 SpiceChannelList *chan;
592 SpiceInfo *info;
593 const char *channel_name;
594 const char * const channel_names[] = {
595 [SPICE_CHANNEL_MAIN] = "main",
596 [SPICE_CHANNEL_DISPLAY] = "display",
597 [SPICE_CHANNEL_INPUTS] = "inputs",
598 [SPICE_CHANNEL_CURSOR] = "cursor",
599 [SPICE_CHANNEL_PLAYBACK] = "playback",
600 [SPICE_CHANNEL_RECORD] = "record",
601 [SPICE_CHANNEL_TUNNEL] = "tunnel",
602 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
603 [SPICE_CHANNEL_USBREDIR] = "usbredir",
604 [SPICE_CHANNEL_PORT] = "port",
605 #if 0
606 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
607 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
608 * as quick fix for build failures with older versions. */
609 [SPICE_CHANNEL_WEBDAV] = "webdav",
610 #endif
613 info = qmp_query_spice(NULL);
615 if (!info->enabled) {
616 monitor_printf(mon, "Server: disabled\n");
617 goto out;
620 monitor_printf(mon, "Server:\n");
621 if (info->has_port) {
622 monitor_printf(mon, " address: %s:%" PRId64 "\n",
623 info->host, info->port);
625 if (info->has_tls_port) {
626 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
627 info->host, info->tls_port);
629 monitor_printf(mon, " migrated: %s\n",
630 info->migrated ? "true" : "false");
631 monitor_printf(mon, " auth: %s\n", info->auth);
632 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
633 monitor_printf(mon, " mouse-mode: %s\n",
634 SpiceQueryMouseMode_lookup[info->mouse_mode]);
636 if (!info->has_channels || info->channels == NULL) {
637 monitor_printf(mon, "Channels: none\n");
638 } else {
639 for (chan = info->channels; chan; chan = chan->next) {
640 monitor_printf(mon, "Channel:\n");
641 monitor_printf(mon, " address: %s:%s%s\n",
642 chan->value->host, chan->value->port,
643 chan->value->tls ? " [tls]" : "");
644 monitor_printf(mon, " session: %" PRId64 "\n",
645 chan->value->connection_id);
646 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
647 chan->value->channel_type, chan->value->channel_id);
649 channel_name = "unknown";
650 if (chan->value->channel_type > 0 &&
651 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
652 channel_names[chan->value->channel_type]) {
653 channel_name = channel_names[chan->value->channel_type];
656 monitor_printf(mon, " channel name: %s\n", channel_name);
660 out:
661 qapi_free_SpiceInfo(info);
663 #endif
665 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
667 BalloonInfo *info;
668 Error *err = NULL;
670 info = qmp_query_balloon(&err);
671 if (err) {
672 monitor_printf(mon, "%s\n", error_get_pretty(err));
673 error_free(err);
674 return;
677 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
679 qapi_free_BalloonInfo(info);
682 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
684 PciMemoryRegionList *region;
686 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
687 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
688 dev->slot, dev->function);
689 monitor_printf(mon, " ");
691 if (dev->class_info->has_desc) {
692 monitor_printf(mon, "%s", dev->class_info->desc);
693 } else {
694 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
697 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
698 dev->id->vendor, dev->id->device);
700 if (dev->has_irq) {
701 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
704 if (dev->has_pci_bridge) {
705 monitor_printf(mon, " BUS %" PRId64 ".\n",
706 dev->pci_bridge->bus->number);
707 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
708 dev->pci_bridge->bus->secondary);
709 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
710 dev->pci_bridge->bus->subordinate);
712 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
713 dev->pci_bridge->bus->io_range->base,
714 dev->pci_bridge->bus->io_range->limit);
716 monitor_printf(mon,
717 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
718 dev->pci_bridge->bus->memory_range->base,
719 dev->pci_bridge->bus->memory_range->limit);
721 monitor_printf(mon, " prefetchable memory range "
722 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
723 dev->pci_bridge->bus->prefetchable_range->base,
724 dev->pci_bridge->bus->prefetchable_range->limit);
727 for (region = dev->regions; region; region = region->next) {
728 uint64_t addr, size;
730 addr = region->value->address;
731 size = region->value->size;
733 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
735 if (!strcmp(region->value->type, "io")) {
736 monitor_printf(mon, "I/O at 0x%04" PRIx64
737 " [0x%04" PRIx64 "].\n",
738 addr, addr + size - 1);
739 } else {
740 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
741 " [0x%08" PRIx64 "].\n",
742 region->value->mem_type_64 ? 64 : 32,
743 region->value->prefetch ? " prefetchable" : "",
744 addr, addr + size - 1);
748 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
750 if (dev->has_pci_bridge) {
751 if (dev->pci_bridge->has_devices) {
752 PciDeviceInfoList *cdev;
753 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
754 hmp_info_pci_device(mon, cdev->value);
760 void hmp_info_pci(Monitor *mon, const QDict *qdict)
762 PciInfoList *info_list, *info;
763 Error *err = NULL;
765 info_list = qmp_query_pci(&err);
766 if (err) {
767 monitor_printf(mon, "PCI devices not supported\n");
768 error_free(err);
769 return;
772 for (info = info_list; info; info = info->next) {
773 PciDeviceInfoList *dev;
775 for (dev = info->value->devices; dev; dev = dev->next) {
776 hmp_info_pci_device(mon, dev->value);
780 qapi_free_PciInfoList(info_list);
783 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
785 BlockJobInfoList *list;
786 Error *err = NULL;
788 list = qmp_query_block_jobs(&err);
789 assert(!err);
791 if (!list) {
792 monitor_printf(mon, "No active jobs\n");
793 return;
796 while (list) {
797 if (strcmp(list->value->type, "stream") == 0) {
798 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
799 " of %" PRId64 " bytes, speed limit %" PRId64
800 " bytes/s\n",
801 list->value->device,
802 list->value->offset,
803 list->value->len,
804 list->value->speed);
805 } else {
806 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
807 " of %" PRId64 " bytes, speed limit %" PRId64
808 " bytes/s\n",
809 list->value->type,
810 list->value->device,
811 list->value->offset,
812 list->value->len,
813 list->value->speed);
815 list = list->next;
818 qapi_free_BlockJobInfoList(list);
821 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
823 TPMInfoList *info_list, *info;
824 Error *err = NULL;
825 unsigned int c = 0;
826 TPMPassthroughOptions *tpo;
828 info_list = qmp_query_tpm(&err);
829 if (err) {
830 monitor_printf(mon, "TPM device not supported\n");
831 error_free(err);
832 return;
835 if (info_list) {
836 monitor_printf(mon, "TPM device:\n");
839 for (info = info_list; info; info = info->next) {
840 TPMInfo *ti = info->value;
841 monitor_printf(mon, " tpm%d: model=%s\n",
842 c, TpmModel_lookup[ti->model]);
844 monitor_printf(mon, " \\ %s: type=%s",
845 ti->id, TpmTypeOptionsKind_lookup[ti->options->type]);
847 switch (ti->options->type) {
848 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
849 tpo = ti->options->u.passthrough;
850 monitor_printf(mon, "%s%s%s%s",
851 tpo->has_path ? ",path=" : "",
852 tpo->has_path ? tpo->path : "",
853 tpo->has_cancel_path ? ",cancel-path=" : "",
854 tpo->has_cancel_path ? tpo->cancel_path : "");
855 break;
856 case TPM_TYPE_OPTIONS_KIND_MAX:
857 break;
859 monitor_printf(mon, "\n");
860 c++;
862 qapi_free_TPMInfoList(info_list);
865 void hmp_quit(Monitor *mon, const QDict *qdict)
867 monitor_suspend(mon);
868 qmp_quit(NULL);
871 void hmp_stop(Monitor *mon, const QDict *qdict)
873 qmp_stop(NULL);
876 void hmp_system_reset(Monitor *mon, const QDict *qdict)
878 qmp_system_reset(NULL);
881 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
883 qmp_system_powerdown(NULL);
886 void hmp_cpu(Monitor *mon, const QDict *qdict)
888 int64_t cpu_index;
890 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
891 use it are converted to the QAPI */
892 cpu_index = qdict_get_int(qdict, "index");
893 if (monitor_set_cpu(cpu_index) < 0) {
894 monitor_printf(mon, "invalid CPU index\n");
898 void hmp_memsave(Monitor *mon, const QDict *qdict)
900 uint32_t size = qdict_get_int(qdict, "size");
901 const char *filename = qdict_get_str(qdict, "filename");
902 uint64_t addr = qdict_get_int(qdict, "val");
903 Error *err = NULL;
905 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &err);
906 hmp_handle_error(mon, &err);
909 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
911 uint32_t size = qdict_get_int(qdict, "size");
912 const char *filename = qdict_get_str(qdict, "filename");
913 uint64_t addr = qdict_get_int(qdict, "val");
914 Error *err = NULL;
916 qmp_pmemsave(addr, size, filename, &err);
917 hmp_handle_error(mon, &err);
920 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
922 const char *chardev = qdict_get_str(qdict, "device");
923 const char *data = qdict_get_str(qdict, "data");
924 Error *err = NULL;
926 qmp_ringbuf_write(chardev, data, false, 0, &err);
928 hmp_handle_error(mon, &err);
931 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
933 uint32_t size = qdict_get_int(qdict, "size");
934 const char *chardev = qdict_get_str(qdict, "device");
935 char *data;
936 Error *err = NULL;
937 int i;
939 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
940 if (err) {
941 monitor_printf(mon, "%s\n", error_get_pretty(err));
942 error_free(err);
943 return;
946 for (i = 0; data[i]; i++) {
947 unsigned char ch = data[i];
949 if (ch == '\\') {
950 monitor_printf(mon, "\\\\");
951 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
952 monitor_printf(mon, "\\u%04X", ch);
953 } else {
954 monitor_printf(mon, "%c", ch);
958 monitor_printf(mon, "\n");
959 g_free(data);
962 static void hmp_cont_cb(void *opaque, int err)
964 if (!err) {
965 qmp_cont(NULL);
969 static bool key_is_missing(const BlockInfo *bdev)
971 return (bdev->inserted && bdev->inserted->encryption_key_missing);
974 void hmp_cont(Monitor *mon, const QDict *qdict)
976 BlockInfoList *bdev_list, *bdev;
977 Error *err = NULL;
979 bdev_list = qmp_query_block(NULL);
980 for (bdev = bdev_list; bdev; bdev = bdev->next) {
981 if (key_is_missing(bdev->value)) {
982 monitor_read_block_device_key(mon, bdev->value->device,
983 hmp_cont_cb, NULL);
984 goto out;
988 qmp_cont(&err);
989 hmp_handle_error(mon, &err);
991 out:
992 qapi_free_BlockInfoList(bdev_list);
995 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
997 qmp_system_wakeup(NULL);
1000 void hmp_nmi(Monitor *mon, const QDict *qdict)
1002 Error *err = NULL;
1004 qmp_inject_nmi(&err);
1005 hmp_handle_error(mon, &err);
1008 void hmp_set_link(Monitor *mon, const QDict *qdict)
1010 const char *name = qdict_get_str(qdict, "name");
1011 bool up = qdict_get_bool(qdict, "up");
1012 Error *err = NULL;
1014 qmp_set_link(name, up, &err);
1015 hmp_handle_error(mon, &err);
1018 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1020 const char *device = qdict_get_str(qdict, "device");
1021 const char *password = qdict_get_str(qdict, "password");
1022 Error *err = NULL;
1024 qmp_block_passwd(true, device, false, NULL, password, &err);
1025 hmp_handle_error(mon, &err);
1028 void hmp_balloon(Monitor *mon, const QDict *qdict)
1030 int64_t value = qdict_get_int(qdict, "value");
1031 Error *err = NULL;
1033 qmp_balloon(value, &err);
1034 if (err) {
1035 monitor_printf(mon, "balloon: %s\n", error_get_pretty(err));
1036 error_free(err);
1040 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1042 const char *device = qdict_get_str(qdict, "device");
1043 int64_t size = qdict_get_int(qdict, "size");
1044 Error *err = NULL;
1046 qmp_block_resize(true, device, false, NULL, size, &err);
1047 hmp_handle_error(mon, &err);
1050 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1052 const char *device = qdict_get_str(qdict, "device");
1053 const char *filename = qdict_get_str(qdict, "target");
1054 const char *format = qdict_get_try_str(qdict, "format");
1055 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1056 bool full = qdict_get_try_bool(qdict, "full", false);
1057 enum NewImageMode mode;
1058 Error *err = NULL;
1060 if (!filename) {
1061 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1062 hmp_handle_error(mon, &err);
1063 return;
1066 if (reuse) {
1067 mode = NEW_IMAGE_MODE_EXISTING;
1068 } else {
1069 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1072 qmp_drive_mirror(device, filename, !!format, format,
1073 false, NULL, false, NULL,
1074 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1075 true, mode, false, 0, false, 0, false, 0,
1076 false, 0, false, 0, false, true, &err);
1077 hmp_handle_error(mon, &err);
1080 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1082 const char *device = qdict_get_str(qdict, "device");
1083 const char *filename = qdict_get_str(qdict, "target");
1084 const char *format = qdict_get_try_str(qdict, "format");
1085 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1086 bool full = qdict_get_try_bool(qdict, "full", false);
1087 enum NewImageMode mode;
1088 Error *err = NULL;
1090 if (!filename) {
1091 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1092 hmp_handle_error(mon, &err);
1093 return;
1096 if (reuse) {
1097 mode = NEW_IMAGE_MODE_EXISTING;
1098 } else {
1099 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1102 qmp_drive_backup(device, filename, !!format, format,
1103 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1104 true, mode, false, 0, false, NULL,
1105 false, 0, false, 0, &err);
1106 hmp_handle_error(mon, &err);
1109 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1111 const char *device = qdict_get_str(qdict, "device");
1112 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1113 const char *format = qdict_get_try_str(qdict, "format");
1114 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1115 enum NewImageMode mode;
1116 Error *err = NULL;
1118 if (!filename) {
1119 /* In the future, if 'snapshot-file' is not specified, the snapshot
1120 will be taken internally. Today it's actually required. */
1121 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1122 hmp_handle_error(mon, &err);
1123 return;
1126 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1127 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1128 filename, false, NULL,
1129 !!format, format,
1130 true, mode, &err);
1131 hmp_handle_error(mon, &err);
1134 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1136 const char *device = qdict_get_str(qdict, "device");
1137 const char *name = qdict_get_str(qdict, "name");
1138 Error *err = NULL;
1140 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1141 hmp_handle_error(mon, &err);
1144 void hmp_snapshot_delete_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 const char *id = qdict_get_try_str(qdict, "id");
1149 Error *err = NULL;
1151 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1152 true, name, &err);
1153 hmp_handle_error(mon, &err);
1156 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1158 qmp_migrate_cancel(NULL);
1161 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1163 Error *err = NULL;
1164 const char *uri = qdict_get_str(qdict, "uri");
1166 qmp_migrate_incoming(uri, &err);
1168 hmp_handle_error(mon, &err);
1171 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1173 double value = qdict_get_double(qdict, "value");
1174 qmp_migrate_set_downtime(value, NULL);
1177 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1179 int64_t value = qdict_get_int(qdict, "value");
1180 Error *err = NULL;
1182 qmp_migrate_set_cache_size(value, &err);
1183 if (err) {
1184 monitor_printf(mon, "%s\n", error_get_pretty(err));
1185 error_free(err);
1186 return;
1190 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1192 int64_t value = qdict_get_int(qdict, "value");
1193 qmp_migrate_set_speed(value, NULL);
1196 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1198 const char *cap = qdict_get_str(qdict, "capability");
1199 bool state = qdict_get_bool(qdict, "state");
1200 Error *err = NULL;
1201 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1202 int i;
1204 for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
1205 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1206 caps->value = g_malloc0(sizeof(*caps->value));
1207 caps->value->capability = i;
1208 caps->value->state = state;
1209 caps->next = NULL;
1210 qmp_migrate_set_capabilities(caps, &err);
1211 break;
1215 if (i == MIGRATION_CAPABILITY_MAX) {
1216 error_setg(&err, QERR_INVALID_PARAMETER, cap);
1219 qapi_free_MigrationCapabilityStatusList(caps);
1221 if (err) {
1222 monitor_printf(mon, "migrate_set_capability: %s\n",
1223 error_get_pretty(err));
1224 error_free(err);
1228 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1230 const char *param = qdict_get_str(qdict, "parameter");
1231 int value = qdict_get_int(qdict, "value");
1232 Error *err = NULL;
1233 bool has_compress_level = false;
1234 bool has_compress_threads = false;
1235 bool has_decompress_threads = false;
1236 bool has_x_cpu_throttle_initial = false;
1237 bool has_x_cpu_throttle_increment = false;
1238 int i;
1240 for (i = 0; i < MIGRATION_PARAMETER_MAX; i++) {
1241 if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
1242 switch (i) {
1243 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1244 has_compress_level = true;
1245 break;
1246 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1247 has_compress_threads = true;
1248 break;
1249 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1250 has_decompress_threads = true;
1251 break;
1252 case MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL:
1253 has_x_cpu_throttle_initial = true;
1254 break;
1255 case MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT:
1256 has_x_cpu_throttle_increment = true;
1257 break;
1259 qmp_migrate_set_parameters(has_compress_level, value,
1260 has_compress_threads, value,
1261 has_decompress_threads, value,
1262 has_x_cpu_throttle_initial, value,
1263 has_x_cpu_throttle_increment, value,
1264 &err);
1265 break;
1269 if (i == MIGRATION_PARAMETER_MAX) {
1270 error_setg(&err, QERR_INVALID_PARAMETER, param);
1273 if (err) {
1274 monitor_printf(mon, "migrate_set_parameter: %s\n",
1275 error_get_pretty(err));
1276 error_free(err);
1280 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1282 Error *err = NULL;
1283 const char *protocol = qdict_get_str(qdict, "protocol");
1284 const char *hostname = qdict_get_str(qdict, "hostname");
1285 bool has_port = qdict_haskey(qdict, "port");
1286 int port = qdict_get_try_int(qdict, "port", -1);
1287 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1288 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1289 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1291 qmp_client_migrate_info(protocol, hostname,
1292 has_port, port, has_tls_port, tls_port,
1293 !!cert_subject, cert_subject, &err);
1294 hmp_handle_error(mon, &err);
1297 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1299 Error *err = NULL;
1300 qmp_migrate_start_postcopy(&err);
1301 hmp_handle_error(mon, &err);
1304 void hmp_set_password(Monitor *mon, const QDict *qdict)
1306 const char *protocol = qdict_get_str(qdict, "protocol");
1307 const char *password = qdict_get_str(qdict, "password");
1308 const char *connected = qdict_get_try_str(qdict, "connected");
1309 Error *err = NULL;
1311 qmp_set_password(protocol, password, !!connected, connected, &err);
1312 hmp_handle_error(mon, &err);
1315 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1317 const char *protocol = qdict_get_str(qdict, "protocol");
1318 const char *whenstr = qdict_get_str(qdict, "time");
1319 Error *err = NULL;
1321 qmp_expire_password(protocol, whenstr, &err);
1322 hmp_handle_error(mon, &err);
1325 void hmp_eject(Monitor *mon, const QDict *qdict)
1327 bool force = qdict_get_try_bool(qdict, "force", false);
1328 const char *device = qdict_get_str(qdict, "device");
1329 Error *err = NULL;
1331 qmp_eject(device, true, force, &err);
1332 hmp_handle_error(mon, &err);
1335 static void hmp_change_read_arg(void *opaque, const char *password,
1336 void *readline_opaque)
1338 qmp_change_vnc_password(password, NULL);
1339 monitor_read_command(opaque, 1);
1342 void hmp_change(Monitor *mon, const QDict *qdict)
1344 const char *device = qdict_get_str(qdict, "device");
1345 const char *target = qdict_get_str(qdict, "target");
1346 const char *arg = qdict_get_try_str(qdict, "arg");
1347 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1348 BlockdevChangeReadOnlyMode read_only_mode = 0;
1349 Error *err = NULL;
1351 if (strcmp(device, "vnc") == 0) {
1352 if (read_only) {
1353 monitor_printf(mon,
1354 "Parameter 'read-only-mode' is invalid for VNC\n");
1355 return;
1357 if (strcmp(target, "passwd") == 0 ||
1358 strcmp(target, "password") == 0) {
1359 if (!arg) {
1360 monitor_read_password(mon, hmp_change_read_arg, NULL);
1361 return;
1364 qmp_change("vnc", target, !!arg, arg, &err);
1365 } else {
1366 if (read_only) {
1367 read_only_mode =
1368 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup,
1369 read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE_MAX,
1370 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1371 if (err) {
1372 hmp_handle_error(mon, &err);
1373 return;
1377 qmp_blockdev_change_medium(device, target, !!arg, arg,
1378 !!read_only, read_only_mode, &err);
1379 if (err &&
1380 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
1381 error_free(err);
1382 monitor_read_block_device_key(mon, device, NULL, NULL);
1383 return;
1387 hmp_handle_error(mon, &err);
1390 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1392 Error *err = NULL;
1394 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
1395 qdict_get_int(qdict, "bps"),
1396 qdict_get_int(qdict, "bps_rd"),
1397 qdict_get_int(qdict, "bps_wr"),
1398 qdict_get_int(qdict, "iops"),
1399 qdict_get_int(qdict, "iops_rd"),
1400 qdict_get_int(qdict, "iops_wr"),
1401 false, /* no burst max via HMP */
1403 false,
1405 false,
1407 false,
1409 false,
1411 false,
1413 false, /* No default I/O size */
1415 false,
1416 NULL, &err);
1417 hmp_handle_error(mon, &err);
1420 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1422 Error *error = NULL;
1423 const char *device = qdict_get_str(qdict, "device");
1424 const char *base = qdict_get_try_str(qdict, "base");
1425 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1427 qmp_block_stream(device, base != NULL, base, false, NULL,
1428 qdict_haskey(qdict, "speed"), speed,
1429 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1431 hmp_handle_error(mon, &error);
1434 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1436 Error *error = NULL;
1437 const char *device = qdict_get_str(qdict, "device");
1438 int64_t value = qdict_get_int(qdict, "speed");
1440 qmp_block_job_set_speed(device, value, &error);
1442 hmp_handle_error(mon, &error);
1445 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1447 Error *error = NULL;
1448 const char *device = qdict_get_str(qdict, "device");
1449 bool force = qdict_get_try_bool(qdict, "force", false);
1451 qmp_block_job_cancel(device, true, force, &error);
1453 hmp_handle_error(mon, &error);
1456 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1458 Error *error = NULL;
1459 const char *device = qdict_get_str(qdict, "device");
1461 qmp_block_job_pause(device, &error);
1463 hmp_handle_error(mon, &error);
1466 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1468 Error *error = NULL;
1469 const char *device = qdict_get_str(qdict, "device");
1471 qmp_block_job_resume(device, &error);
1473 hmp_handle_error(mon, &error);
1476 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1478 Error *error = NULL;
1479 const char *device = qdict_get_str(qdict, "device");
1481 qmp_block_job_complete(device, &error);
1483 hmp_handle_error(mon, &error);
1486 typedef struct HMPMigrationStatus
1488 QEMUTimer *timer;
1489 Monitor *mon;
1490 bool is_block_migration;
1491 } HMPMigrationStatus;
1493 static void hmp_migrate_status_cb(void *opaque)
1495 HMPMigrationStatus *status = opaque;
1496 MigrationInfo *info;
1498 info = qmp_query_migrate(NULL);
1499 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1500 info->status == MIGRATION_STATUS_SETUP) {
1501 if (info->has_disk) {
1502 int progress;
1504 if (info->disk->remaining) {
1505 progress = info->disk->transferred * 100 / info->disk->total;
1506 } else {
1507 progress = 100;
1510 monitor_printf(status->mon, "Completed %d %%\r", progress);
1511 monitor_flush(status->mon);
1514 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1515 } else {
1516 if (status->is_block_migration) {
1517 monitor_printf(status->mon, "\n");
1519 monitor_resume(status->mon);
1520 timer_del(status->timer);
1521 g_free(status);
1524 qapi_free_MigrationInfo(info);
1527 void hmp_migrate(Monitor *mon, const QDict *qdict)
1529 bool detach = qdict_get_try_bool(qdict, "detach", false);
1530 bool blk = qdict_get_try_bool(qdict, "blk", false);
1531 bool inc = qdict_get_try_bool(qdict, "inc", false);
1532 const char *uri = qdict_get_str(qdict, "uri");
1533 Error *err = NULL;
1535 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1536 if (err) {
1537 monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
1538 error_free(err);
1539 return;
1542 if (!detach) {
1543 HMPMigrationStatus *status;
1545 if (monitor_suspend(mon) < 0) {
1546 monitor_printf(mon, "terminal does not allow synchronous "
1547 "migration, continuing detached\n");
1548 return;
1551 status = g_malloc0(sizeof(*status));
1552 status->mon = mon;
1553 status->is_block_migration = blk || inc;
1554 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1555 status);
1556 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1560 void hmp_device_add(Monitor *mon, const QDict *qdict)
1562 Error *err = NULL;
1564 qmp_device_add((QDict *)qdict, NULL, &err);
1565 hmp_handle_error(mon, &err);
1568 void hmp_device_del(Monitor *mon, const QDict *qdict)
1570 const char *id = qdict_get_str(qdict, "id");
1571 Error *err = NULL;
1573 qmp_device_del(id, &err);
1574 hmp_handle_error(mon, &err);
1577 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1579 Error *err = NULL;
1580 bool paging = qdict_get_try_bool(qdict, "paging", false);
1581 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
1582 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
1583 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
1584 const char *file = qdict_get_str(qdict, "filename");
1585 bool has_begin = qdict_haskey(qdict, "begin");
1586 bool has_length = qdict_haskey(qdict, "length");
1587 int64_t begin = 0;
1588 int64_t length = 0;
1589 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1590 char *prot;
1592 if (zlib + lzo + snappy > 1) {
1593 error_setg(&err, "only one of '-z|-l|-s' can be set");
1594 hmp_handle_error(mon, &err);
1595 return;
1598 if (zlib) {
1599 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1602 if (lzo) {
1603 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1606 if (snappy) {
1607 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1610 if (has_begin) {
1611 begin = qdict_get_int(qdict, "begin");
1613 if (has_length) {
1614 length = qdict_get_int(qdict, "length");
1617 prot = g_strconcat("file:", file, NULL);
1619 qmp_dump_guest_memory(paging, prot, has_begin, begin, has_length, length,
1620 true, dump_format, &err);
1621 hmp_handle_error(mon, &err);
1622 g_free(prot);
1625 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1627 Error *err = NULL;
1628 QemuOpts *opts;
1630 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1631 if (err) {
1632 goto out;
1635 netdev_add(opts, &err);
1636 if (err) {
1637 qemu_opts_del(opts);
1640 out:
1641 hmp_handle_error(mon, &err);
1644 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1646 const char *id = qdict_get_str(qdict, "id");
1647 Error *err = NULL;
1649 qmp_netdev_del(id, &err);
1650 hmp_handle_error(mon, &err);
1653 void hmp_object_add(Monitor *mon, const QDict *qdict)
1655 Error *err = NULL;
1656 Error *err_end = NULL;
1657 QemuOpts *opts;
1658 char *type = NULL;
1659 char *id = NULL;
1660 void *dummy = NULL;
1661 OptsVisitor *ov;
1662 QDict *pdict;
1664 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1665 if (err) {
1666 goto out;
1669 ov = opts_visitor_new(opts);
1670 pdict = qdict_clone_shallow(qdict);
1672 visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err);
1673 if (err) {
1674 goto out_clean;
1677 qdict_del(pdict, "qom-type");
1678 visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
1679 if (err) {
1680 goto out_end;
1683 qdict_del(pdict, "id");
1684 visit_type_str(opts_get_visitor(ov), &id, "id", &err);
1685 if (err) {
1686 goto out_end;
1689 object_add(type, id, pdict, opts_get_visitor(ov), &err);
1691 out_end:
1692 visit_end_struct(opts_get_visitor(ov), &err_end);
1693 if (!err && err_end) {
1694 qmp_object_del(id, NULL);
1696 error_propagate(&err, err_end);
1697 out_clean:
1698 opts_visitor_cleanup(ov);
1700 QDECREF(pdict);
1701 qemu_opts_del(opts);
1702 g_free(id);
1703 g_free(type);
1704 g_free(dummy);
1706 out:
1707 hmp_handle_error(mon, &err);
1710 void hmp_getfd(Monitor *mon, const QDict *qdict)
1712 const char *fdname = qdict_get_str(qdict, "fdname");
1713 Error *err = NULL;
1715 qmp_getfd(fdname, &err);
1716 hmp_handle_error(mon, &err);
1719 void hmp_closefd(Monitor *mon, const QDict *qdict)
1721 const char *fdname = qdict_get_str(qdict, "fdname");
1722 Error *err = NULL;
1724 qmp_closefd(fdname, &err);
1725 hmp_handle_error(mon, &err);
1728 void hmp_sendkey(Monitor *mon, const QDict *qdict)
1730 const char *keys = qdict_get_str(qdict, "keys");
1731 KeyValueList *keylist, *head = NULL, *tmp = NULL;
1732 int has_hold_time = qdict_haskey(qdict, "hold-time");
1733 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1734 Error *err = NULL;
1735 char keyname_buf[16];
1736 char *separator;
1737 int keyname_len;
1739 while (1) {
1740 separator = strchr(keys, '-');
1741 keyname_len = separator ? separator - keys : strlen(keys);
1742 pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
1744 /* Be compatible with old interface, convert user inputted "<" */
1745 if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) {
1746 pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
1747 keyname_len = 4;
1749 keyname_buf[keyname_len] = 0;
1751 keylist = g_malloc0(sizeof(*keylist));
1752 keylist->value = g_malloc0(sizeof(*keylist->value));
1754 if (!head) {
1755 head = keylist;
1757 if (tmp) {
1758 tmp->next = keylist;
1760 tmp = keylist;
1762 if (strstart(keyname_buf, "0x", NULL)) {
1763 char *endp;
1764 int value = strtoul(keyname_buf, &endp, 0);
1765 if (*endp != '\0') {
1766 goto err_out;
1768 keylist->value->type = KEY_VALUE_KIND_NUMBER;
1769 keylist->value->u.number = value;
1770 } else {
1771 int idx = index_from_key(keyname_buf);
1772 if (idx == Q_KEY_CODE_MAX) {
1773 goto err_out;
1775 keylist->value->type = KEY_VALUE_KIND_QCODE;
1776 keylist->value->u.qcode = idx;
1779 if (!separator) {
1780 break;
1782 keys = separator + 1;
1785 qmp_send_key(head, has_hold_time, hold_time, &err);
1786 hmp_handle_error(mon, &err);
1788 out:
1789 qapi_free_KeyValueList(head);
1790 return;
1792 err_out:
1793 monitor_printf(mon, "invalid parameter: %s\n", keyname_buf);
1794 goto out;
1797 void hmp_screendump(Monitor *mon, const QDict *qdict)
1799 const char *filename = qdict_get_str(qdict, "filename");
1800 Error *err = NULL;
1802 qmp_screendump(filename, &err);
1803 hmp_handle_error(mon, &err);
1806 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1808 const char *uri = qdict_get_str(qdict, "uri");
1809 bool writable = qdict_get_try_bool(qdict, "writable", false);
1810 bool all = qdict_get_try_bool(qdict, "all", false);
1811 Error *local_err = NULL;
1812 BlockInfoList *block_list, *info;
1813 SocketAddress *addr;
1815 if (writable && !all) {
1816 error_setg(&local_err, "-w only valid together with -a");
1817 goto exit;
1820 /* First check if the address is valid and start the server. */
1821 addr = socket_parse(uri, &local_err);
1822 if (local_err != NULL) {
1823 goto exit;
1826 qmp_nbd_server_start(addr, &local_err);
1827 qapi_free_SocketAddress(addr);
1828 if (local_err != NULL) {
1829 goto exit;
1832 if (!all) {
1833 return;
1836 /* Then try adding all block devices. If one fails, close all and
1837 * exit.
1839 block_list = qmp_query_block(NULL);
1841 for (info = block_list; info; info = info->next) {
1842 if (!info->value->has_inserted) {
1843 continue;
1846 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1848 if (local_err != NULL) {
1849 qmp_nbd_server_stop(NULL);
1850 break;
1854 qapi_free_BlockInfoList(block_list);
1856 exit:
1857 hmp_handle_error(mon, &local_err);
1860 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1862 const char *device = qdict_get_str(qdict, "device");
1863 bool writable = qdict_get_try_bool(qdict, "writable", false);
1864 Error *local_err = NULL;
1866 qmp_nbd_server_add(device, true, writable, &local_err);
1868 if (local_err != NULL) {
1869 hmp_handle_error(mon, &local_err);
1873 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1875 Error *err = NULL;
1877 qmp_nbd_server_stop(&err);
1878 hmp_handle_error(mon, &err);
1881 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
1883 int cpuid;
1884 Error *err = NULL;
1886 cpuid = qdict_get_int(qdict, "id");
1887 qmp_cpu_add(cpuid, &err);
1888 hmp_handle_error(mon, &err);
1891 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1893 const char *args = qdict_get_str(qdict, "args");
1894 Error *err = NULL;
1895 QemuOpts *opts;
1897 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
1898 if (opts == NULL) {
1899 error_setg(&err, "Parsing chardev args failed");
1900 } else {
1901 qemu_chr_new_from_opts(opts, NULL, &err);
1903 hmp_handle_error(mon, &err);
1906 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1908 Error *local_err = NULL;
1910 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1911 hmp_handle_error(mon, &local_err);
1914 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1916 BlockBackend *blk;
1917 const char* device = qdict_get_str(qdict, "device");
1918 const char* command = qdict_get_str(qdict, "command");
1919 Error *err = NULL;
1921 blk = blk_by_name(device);
1922 if (blk) {
1923 qemuio_command(blk, command);
1924 } else {
1925 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
1926 "Device '%s' not found", device);
1929 hmp_handle_error(mon, &err);
1932 void hmp_object_del(Monitor *mon, const QDict *qdict)
1934 const char *id = qdict_get_str(qdict, "id");
1935 Error *err = NULL;
1937 qmp_object_del(id, &err);
1938 hmp_handle_error(mon, &err);
1941 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
1943 Error *err = NULL;
1944 MemdevList *memdev_list = qmp_query_memdev(&err);
1945 MemdevList *m = memdev_list;
1946 StringOutputVisitor *ov;
1947 char *str;
1948 int i = 0;
1951 while (m) {
1952 ov = string_output_visitor_new(false);
1953 visit_type_uint16List(string_output_get_visitor(ov),
1954 &m->value->host_nodes, NULL, NULL);
1955 monitor_printf(mon, "memory backend: %d\n", i);
1956 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
1957 monitor_printf(mon, " merge: %s\n",
1958 m->value->merge ? "true" : "false");
1959 monitor_printf(mon, " dump: %s\n",
1960 m->value->dump ? "true" : "false");
1961 monitor_printf(mon, " prealloc: %s\n",
1962 m->value->prealloc ? "true" : "false");
1963 monitor_printf(mon, " policy: %s\n",
1964 HostMemPolicy_lookup[m->value->policy]);
1965 str = string_output_get_string(ov);
1966 monitor_printf(mon, " host nodes: %s\n", str);
1968 g_free(str);
1969 string_output_visitor_cleanup(ov);
1970 m = m->next;
1971 i++;
1974 monitor_printf(mon, "\n");
1976 qapi_free_MemdevList(memdev_list);
1979 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
1981 Error *err = NULL;
1982 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
1983 MemoryDeviceInfoList *info;
1984 MemoryDeviceInfo *value;
1985 PCDIMMDeviceInfo *di;
1987 for (info = info_list; info; info = info->next) {
1988 value = info->value;
1990 if (value) {
1991 switch (value->type) {
1992 case MEMORY_DEVICE_INFO_KIND_DIMM:
1993 di = value->u.dimm;
1995 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1996 MemoryDeviceInfoKind_lookup[value->type],
1997 di->id ? di->id : "");
1998 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
1999 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2000 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2001 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2002 monitor_printf(mon, " memdev: %s\n", di->memdev);
2003 monitor_printf(mon, " hotplugged: %s\n",
2004 di->hotplugged ? "true" : "false");
2005 monitor_printf(mon, " hotpluggable: %s\n",
2006 di->hotpluggable ? "true" : "false");
2007 break;
2008 default:
2009 break;
2014 qapi_free_MemoryDeviceInfoList(info_list);
2017 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2019 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2020 IOThreadInfoList *info;
2022 for (info = info_list; info; info = info->next) {
2023 monitor_printf(mon, "%s: thread_id=%" PRId64 "\n",
2024 info->value->id, info->value->thread_id);
2027 qapi_free_IOThreadInfoList(info_list);
2030 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2032 const char *path = qdict_get_try_str(qdict, "path");
2033 ObjectPropertyInfoList *list;
2034 Error *err = NULL;
2036 if (path == NULL) {
2037 monitor_printf(mon, "/\n");
2038 return;
2041 list = qmp_qom_list(path, &err);
2042 if (err == NULL) {
2043 ObjectPropertyInfoList *start = list;
2044 while (list != NULL) {
2045 ObjectPropertyInfo *value = list->value;
2047 monitor_printf(mon, "%s (%s)\n",
2048 value->name, value->type);
2049 list = list->next;
2051 qapi_free_ObjectPropertyInfoList(start);
2053 hmp_handle_error(mon, &err);
2056 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2058 const char *path = qdict_get_str(qdict, "path");
2059 const char *property = qdict_get_str(qdict, "property");
2060 const char *value = qdict_get_str(qdict, "value");
2061 Error *err = NULL;
2062 bool ambiguous = false;
2063 Object *obj;
2065 obj = object_resolve_path(path, &ambiguous);
2066 if (obj == NULL) {
2067 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2068 "Device '%s' not found", path);
2069 } else {
2070 if (ambiguous) {
2071 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2073 object_property_parse(obj, value, property, &err);
2075 hmp_handle_error(mon, &err);
2078 void hmp_rocker(Monitor *mon, const QDict *qdict)
2080 const char *name = qdict_get_str(qdict, "name");
2081 RockerSwitch *rocker;
2082 Error *errp = NULL;
2084 rocker = qmp_query_rocker(name, &errp);
2085 if (errp != NULL) {
2086 hmp_handle_error(mon, &errp);
2087 return;
2090 monitor_printf(mon, "name: %s\n", rocker->name);
2091 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2092 monitor_printf(mon, "ports: %d\n", rocker->ports);
2094 qapi_free_RockerSwitch(rocker);
2097 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2099 RockerPortList *list, *port;
2100 const char *name = qdict_get_str(qdict, "name");
2101 Error *errp = NULL;
2103 list = qmp_query_rocker_ports(name, &errp);
2104 if (errp != NULL) {
2105 hmp_handle_error(mon, &errp);
2106 return;
2109 monitor_printf(mon, " ena/ speed/ auto\n");
2110 monitor_printf(mon, " port link duplex neg?\n");
2112 for (port = list; port; port = port->next) {
2113 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2114 port->value->name,
2115 port->value->enabled ? port->value->link_up ?
2116 "up" : "down" : "!ena",
2117 port->value->speed == 10000 ? "10G" : "??",
2118 port->value->duplex ? "FD" : "HD",
2119 port->value->autoneg ? "Yes" : "No");
2122 qapi_free_RockerPortList(list);
2125 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2127 RockerOfDpaFlowList *list, *info;
2128 const char *name = qdict_get_str(qdict, "name");
2129 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2130 Error *errp = NULL;
2132 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &errp);
2133 if (errp != NULL) {
2134 hmp_handle_error(mon, &errp);
2135 return;
2138 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2140 for (info = list; info; info = info->next) {
2141 RockerOfDpaFlow *flow = info->value;
2142 RockerOfDpaFlowKey *key = flow->key;
2143 RockerOfDpaFlowMask *mask = flow->mask;
2144 RockerOfDpaFlowAction *action = flow->action;
2146 if (flow->hits) {
2147 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2148 key->priority, key->tbl_id, flow->hits);
2149 } else {
2150 monitor_printf(mon, "%-4d %-3d ",
2151 key->priority, key->tbl_id);
2154 if (key->has_in_pport) {
2155 monitor_printf(mon, " pport %d", key->in_pport);
2156 if (mask->has_in_pport) {
2157 monitor_printf(mon, "(0x%x)", mask->in_pport);
2161 if (key->has_vlan_id) {
2162 monitor_printf(mon, " vlan %d",
2163 key->vlan_id & VLAN_VID_MASK);
2164 if (mask->has_vlan_id) {
2165 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2169 if (key->has_tunnel_id) {
2170 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2171 if (mask->has_tunnel_id) {
2172 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2176 if (key->has_eth_type) {
2177 switch (key->eth_type) {
2178 case 0x0806:
2179 monitor_printf(mon, " ARP");
2180 break;
2181 case 0x0800:
2182 monitor_printf(mon, " IP");
2183 break;
2184 case 0x86dd:
2185 monitor_printf(mon, " IPv6");
2186 break;
2187 case 0x8809:
2188 monitor_printf(mon, " LACP");
2189 break;
2190 case 0x88cc:
2191 monitor_printf(mon, " LLDP");
2192 break;
2193 default:
2194 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2195 break;
2199 if (key->has_eth_src) {
2200 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2201 (mask->has_eth_src) &&
2202 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2203 monitor_printf(mon, " src <any mcast/bcast>");
2204 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2205 (mask->has_eth_src) &&
2206 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2207 monitor_printf(mon, " src <any ucast>");
2208 } else {
2209 monitor_printf(mon, " src %s", key->eth_src);
2210 if (mask->has_eth_src) {
2211 monitor_printf(mon, "(%s)", mask->eth_src);
2216 if (key->has_eth_dst) {
2217 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2218 (mask->has_eth_dst) &&
2219 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2220 monitor_printf(mon, " dst <any mcast/bcast>");
2221 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2222 (mask->has_eth_dst) &&
2223 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2224 monitor_printf(mon, " dst <any ucast>");
2225 } else {
2226 monitor_printf(mon, " dst %s", key->eth_dst);
2227 if (mask->has_eth_dst) {
2228 monitor_printf(mon, "(%s)", mask->eth_dst);
2233 if (key->has_ip_proto) {
2234 monitor_printf(mon, " proto %d", key->ip_proto);
2235 if (mask->has_ip_proto) {
2236 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2240 if (key->has_ip_tos) {
2241 monitor_printf(mon, " TOS %d", key->ip_tos);
2242 if (mask->has_ip_tos) {
2243 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2247 if (key->has_ip_dst) {
2248 monitor_printf(mon, " dst %s", key->ip_dst);
2251 if (action->has_goto_tbl || action->has_group_id ||
2252 action->has_new_vlan_id) {
2253 monitor_printf(mon, " -->");
2256 if (action->has_new_vlan_id) {
2257 monitor_printf(mon, " apply new vlan %d",
2258 ntohs(action->new_vlan_id));
2261 if (action->has_group_id) {
2262 monitor_printf(mon, " write group 0x%08x", action->group_id);
2265 if (action->has_goto_tbl) {
2266 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2269 monitor_printf(mon, "\n");
2272 qapi_free_RockerOfDpaFlowList(list);
2275 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2277 RockerOfDpaGroupList *list, *g;
2278 const char *name = qdict_get_str(qdict, "name");
2279 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2280 Error *errp = NULL;
2281 bool set = false;
2283 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &errp);
2284 if (errp != NULL) {
2285 hmp_handle_error(mon, &errp);
2286 return;
2289 monitor_printf(mon, "id (decode) --> buckets\n");
2291 for (g = list; g; g = g->next) {
2292 RockerOfDpaGroup *group = g->value;
2294 monitor_printf(mon, "0x%08x", group->id);
2296 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2297 group->type == 1 ? "L2 rewrite" :
2298 group->type == 2 ? "L3 unicast" :
2299 group->type == 3 ? "L2 multicast" :
2300 group->type == 4 ? "L2 flood" :
2301 group->type == 5 ? "L3 interface" :
2302 group->type == 6 ? "L3 multicast" :
2303 group->type == 7 ? "L3 ECMP" :
2304 group->type == 8 ? "L2 overlay" :
2305 "unknown");
2307 if (group->has_vlan_id) {
2308 monitor_printf(mon, " vlan %d", group->vlan_id);
2311 if (group->has_pport) {
2312 monitor_printf(mon, " pport %d", group->pport);
2315 if (group->has_index) {
2316 monitor_printf(mon, " index %d", group->index);
2319 monitor_printf(mon, ") -->");
2321 if (group->has_set_vlan_id && group->set_vlan_id) {
2322 set = true;
2323 monitor_printf(mon, " set vlan %d",
2324 group->set_vlan_id & VLAN_VID_MASK);
2327 if (group->has_set_eth_src) {
2328 if (!set) {
2329 set = true;
2330 monitor_printf(mon, " set");
2332 monitor_printf(mon, " src %s", group->set_eth_src);
2335 if (group->has_set_eth_dst) {
2336 if (!set) {
2337 set = true;
2338 monitor_printf(mon, " set");
2340 monitor_printf(mon, " dst %s", group->set_eth_dst);
2343 set = false;
2345 if (group->has_ttl_check && group->ttl_check) {
2346 monitor_printf(mon, " check TTL");
2349 if (group->has_group_id && group->group_id) {
2350 monitor_printf(mon, " group id 0x%08x", group->group_id);
2353 if (group->has_pop_vlan && group->pop_vlan) {
2354 monitor_printf(mon, " pop vlan");
2357 if (group->has_out_pport) {
2358 monitor_printf(mon, " out pport %d", group->out_pport);
2361 if (group->has_group_ids) {
2362 struct uint32List *id;
2364 monitor_printf(mon, " groups [");
2365 for (id = group->group_ids; id; id = id->next) {
2366 monitor_printf(mon, "0x%08x", id->value);
2367 if (id->next) {
2368 monitor_printf(mon, ",");
2371 monitor_printf(mon, "]");
2374 monitor_printf(mon, "\n");
2377 qapi_free_RockerOfDpaGroupList(list);