target-microblaze: Convert use-fpu to a CPU property
[qemu/cris-port.git] / hmp.c
blob23abc7d9f1ba954e47dbdbdaf1a43e596694e7d2
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/string-output-visitor.h"
29 #include "qapi-visit.h"
30 #include "ui/console.h"
31 #include "block/qapi.h"
32 #include "qemu-io.h"
34 #ifdef CONFIG_SPICE
35 #include <spice/enums.h>
36 #endif
38 static void hmp_handle_error(Monitor *mon, Error **errp)
40 assert(errp);
41 if (*errp) {
42 monitor_printf(mon, "%s\n", error_get_pretty(*errp));
43 error_free(*errp);
47 void hmp_info_name(Monitor *mon, const QDict *qdict)
49 NameInfo *info;
51 info = qmp_query_name(NULL);
52 if (info->has_name) {
53 monitor_printf(mon, "%s\n", info->name);
55 qapi_free_NameInfo(info);
58 void hmp_info_version(Monitor *mon, const QDict *qdict)
60 VersionInfo *info;
62 info = qmp_query_version(NULL);
64 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
65 info->qemu->major, info->qemu->minor, info->qemu->micro,
66 info->package);
68 qapi_free_VersionInfo(info);
71 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
73 KvmInfo *info;
75 info = qmp_query_kvm(NULL);
76 monitor_printf(mon, "kvm support: ");
77 if (info->present) {
78 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
79 } else {
80 monitor_printf(mon, "not compiled\n");
83 qapi_free_KvmInfo(info);
86 void hmp_info_status(Monitor *mon, const QDict *qdict)
88 StatusInfo *info;
90 info = qmp_query_status(NULL);
92 monitor_printf(mon, "VM status: %s%s",
93 info->running ? "running" : "paused",
94 info->singlestep ? " (single step mode)" : "");
96 if (!info->running && info->status != RUN_STATE_PAUSED) {
97 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
100 monitor_printf(mon, "\n");
102 qapi_free_StatusInfo(info);
105 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
107 UuidInfo *info;
109 info = qmp_query_uuid(NULL);
110 monitor_printf(mon, "%s\n", info->UUID);
111 qapi_free_UuidInfo(info);
114 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
116 ChardevInfoList *char_info, *info;
118 char_info = qmp_query_chardev(NULL);
119 for (info = char_info; info; info = info->next) {
120 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
121 info->value->filename);
124 qapi_free_ChardevInfoList(char_info);
127 void hmp_info_mice(Monitor *mon, const QDict *qdict)
129 MouseInfoList *mice_list, *mouse;
131 mice_list = qmp_query_mice(NULL);
132 if (!mice_list) {
133 monitor_printf(mon, "No mouse devices connected\n");
134 return;
137 for (mouse = mice_list; mouse; mouse = mouse->next) {
138 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
139 mouse->value->current ? '*' : ' ',
140 mouse->value->index, mouse->value->name,
141 mouse->value->absolute ? " (absolute)" : "");
144 qapi_free_MouseInfoList(mice_list);
147 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
149 MigrationInfo *info;
150 MigrationCapabilityStatusList *caps, *cap;
152 info = qmp_query_migrate(NULL);
153 caps = qmp_query_migrate_capabilities(NULL);
155 /* do not display parameters during setup */
156 if (info->has_status && caps) {
157 monitor_printf(mon, "capabilities: ");
158 for (cap = caps; cap; cap = cap->next) {
159 monitor_printf(mon, "%s: %s ",
160 MigrationCapability_lookup[cap->value->capability],
161 cap->value->state ? "on" : "off");
163 monitor_printf(mon, "\n");
166 if (info->has_status) {
167 monitor_printf(mon, "Migration status: %s\n",
168 MigrationStatus_lookup[info->status]);
169 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
170 info->total_time);
171 if (info->has_expected_downtime) {
172 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
173 info->expected_downtime);
175 if (info->has_downtime) {
176 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
177 info->downtime);
179 if (info->has_setup_time) {
180 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
181 info->setup_time);
185 if (info->has_ram) {
186 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
187 info->ram->transferred >> 10);
188 monitor_printf(mon, "throughput: %0.2f mbps\n",
189 info->ram->mbps);
190 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
191 info->ram->remaining >> 10);
192 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
193 info->ram->total >> 10);
194 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
195 info->ram->duplicate);
196 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
197 info->ram->skipped);
198 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
199 info->ram->normal);
200 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
201 info->ram->normal_bytes >> 10);
202 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
203 info->ram->dirty_sync_count);
204 if (info->ram->dirty_pages_rate) {
205 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
206 info->ram->dirty_pages_rate);
210 if (info->has_disk) {
211 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
212 info->disk->transferred >> 10);
213 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
214 info->disk->remaining >> 10);
215 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
216 info->disk->total >> 10);
219 if (info->has_xbzrle_cache) {
220 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
221 info->xbzrle_cache->cache_size);
222 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
223 info->xbzrle_cache->bytes >> 10);
224 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
225 info->xbzrle_cache->pages);
226 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
227 info->xbzrle_cache->cache_miss);
228 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
229 info->xbzrle_cache->cache_miss_rate);
230 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
231 info->xbzrle_cache->overflow);
234 qapi_free_MigrationInfo(info);
235 qapi_free_MigrationCapabilityStatusList(caps);
238 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
240 MigrationCapabilityStatusList *caps, *cap;
242 caps = qmp_query_migrate_capabilities(NULL);
244 if (caps) {
245 monitor_printf(mon, "capabilities: ");
246 for (cap = caps; cap; cap = cap->next) {
247 monitor_printf(mon, "%s: %s ",
248 MigrationCapability_lookup[cap->value->capability],
249 cap->value->state ? "on" : "off");
251 monitor_printf(mon, "\n");
254 qapi_free_MigrationCapabilityStatusList(caps);
257 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
259 MigrationParameters *params;
261 params = qmp_query_migrate_parameters(NULL);
263 if (params) {
264 monitor_printf(mon, "parameters:");
265 monitor_printf(mon, " %s: %" PRId64,
266 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_LEVEL],
267 params->compress_level);
268 monitor_printf(mon, " %s: %" PRId64,
269 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_THREADS],
270 params->compress_threads);
271 monitor_printf(mon, " %s: %" PRId64,
272 MigrationParameter_lookup[MIGRATION_PARAMETER_DECOMPRESS_THREADS],
273 params->decompress_threads);
274 monitor_printf(mon, "\n");
277 qapi_free_MigrationParameters(params);
280 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
282 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
283 qmp_query_migrate_cache_size(NULL) >> 10);
286 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
288 CpuInfoList *cpu_list, *cpu;
290 cpu_list = qmp_query_cpus(NULL);
292 for (cpu = cpu_list; cpu; cpu = cpu->next) {
293 int active = ' ';
295 if (cpu->value->CPU == monitor_get_cpu_index()) {
296 active = '*';
299 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
301 if (cpu->value->has_pc) {
302 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->pc);
304 if (cpu->value->has_nip) {
305 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->nip);
307 if (cpu->value->has_npc) {
308 monitor_printf(mon, " npc=0x%016" PRIx64, cpu->value->npc);
310 if (cpu->value->has_PC) {
311 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->PC);
314 if (cpu->value->halted) {
315 monitor_printf(mon, " (halted)");
318 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
321 qapi_free_CpuInfoList(cpu_list);
324 static void print_block_info(Monitor *mon, BlockInfo *info,
325 BlockDeviceInfo *inserted, bool verbose)
327 ImageInfo *image_info;
329 assert(!info || !info->has_inserted || info->inserted == inserted);
331 if (info) {
332 monitor_printf(mon, "%s", info->device);
333 if (inserted && inserted->has_node_name) {
334 monitor_printf(mon, " (%s)", inserted->node_name);
336 } else {
337 assert(inserted);
338 monitor_printf(mon, "%s",
339 inserted->has_node_name
340 ? inserted->node_name
341 : "<anonymous>");
344 if (inserted) {
345 monitor_printf(mon, ": %s (%s%s%s)\n",
346 inserted->file,
347 inserted->drv,
348 inserted->ro ? ", read-only" : "",
349 inserted->encrypted ? ", encrypted" : "");
350 } else {
351 monitor_printf(mon, ": [not inserted]\n");
354 if (info) {
355 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
356 monitor_printf(mon, " I/O status: %s\n",
357 BlockDeviceIoStatus_lookup[info->io_status]);
360 if (info->removable) {
361 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
362 info->locked ? "" : "not ",
363 info->tray_open ? "open" : "closed");
368 if (!inserted) {
369 return;
372 monitor_printf(mon, " Cache mode: %s%s%s\n",
373 inserted->cache->writeback ? "writeback" : "writethrough",
374 inserted->cache->direct ? ", direct" : "",
375 inserted->cache->no_flush ? ", ignore flushes" : "");
377 if (inserted->has_backing_file) {
378 monitor_printf(mon,
379 " Backing file: %s "
380 "(chain depth: %" PRId64 ")\n",
381 inserted->backing_file,
382 inserted->backing_file_depth);
385 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
386 monitor_printf(mon, " Detect zeroes: %s\n",
387 BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]);
390 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
391 inserted->iops || inserted->iops_rd || inserted->iops_wr)
393 monitor_printf(mon, " I/O throttling: bps=%" PRId64
394 " bps_rd=%" PRId64 " bps_wr=%" PRId64
395 " bps_max=%" PRId64
396 " bps_rd_max=%" PRId64
397 " bps_wr_max=%" PRId64
398 " iops=%" PRId64 " iops_rd=%" PRId64
399 " iops_wr=%" PRId64
400 " iops_max=%" PRId64
401 " iops_rd_max=%" PRId64
402 " iops_wr_max=%" PRId64
403 " iops_size=%" PRId64
404 " group=%s\n",
405 inserted->bps,
406 inserted->bps_rd,
407 inserted->bps_wr,
408 inserted->bps_max,
409 inserted->bps_rd_max,
410 inserted->bps_wr_max,
411 inserted->iops,
412 inserted->iops_rd,
413 inserted->iops_wr,
414 inserted->iops_max,
415 inserted->iops_rd_max,
416 inserted->iops_wr_max,
417 inserted->iops_size,
418 inserted->group);
421 if (verbose) {
422 monitor_printf(mon, "\nImages:\n");
423 image_info = inserted->image;
424 while (1) {
425 bdrv_image_info_dump((fprintf_function)monitor_printf,
426 mon, image_info);
427 if (image_info->has_backing_image) {
428 image_info = image_info->backing_image;
429 } else {
430 break;
436 void hmp_info_block(Monitor *mon, const QDict *qdict)
438 BlockInfoList *block_list, *info;
439 BlockDeviceInfoList *blockdev_list, *blockdev;
440 const char *device = qdict_get_try_str(qdict, "device");
441 bool verbose = qdict_get_try_bool(qdict, "verbose", 0);
442 bool nodes = qdict_get_try_bool(qdict, "nodes", 0);
443 bool printed = false;
445 /* Print BlockBackend information */
446 if (!nodes) {
447 block_list = qmp_query_block(NULL);
448 } else {
449 block_list = NULL;
452 for (info = block_list; info; info = info->next) {
453 if (device && strcmp(device, info->value->device)) {
454 continue;
457 if (info != block_list) {
458 monitor_printf(mon, "\n");
461 print_block_info(mon, info->value, info->value->has_inserted
462 ? info->value->inserted : NULL,
463 verbose);
464 printed = true;
467 qapi_free_BlockInfoList(block_list);
469 if ((!device && !nodes) || printed) {
470 return;
473 /* Print node information */
474 blockdev_list = qmp_query_named_block_nodes(NULL);
475 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
476 assert(blockdev->value->has_node_name);
477 if (device && strcmp(device, blockdev->value->node_name)) {
478 continue;
481 if (blockdev != blockdev_list) {
482 monitor_printf(mon, "\n");
485 print_block_info(mon, NULL, blockdev->value, verbose);
487 qapi_free_BlockDeviceInfoList(blockdev_list);
490 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
492 BlockStatsList *stats_list, *stats;
494 stats_list = qmp_query_blockstats(false, false, NULL);
496 for (stats = stats_list; stats; stats = stats->next) {
497 if (!stats->value->has_device) {
498 continue;
501 monitor_printf(mon, "%s:", stats->value->device);
502 monitor_printf(mon, " rd_bytes=%" PRId64
503 " wr_bytes=%" PRId64
504 " rd_operations=%" PRId64
505 " wr_operations=%" PRId64
506 " flush_operations=%" PRId64
507 " wr_total_time_ns=%" PRId64
508 " rd_total_time_ns=%" PRId64
509 " flush_total_time_ns=%" PRId64
510 " rd_merged=%" PRId64
511 " wr_merged=%" PRId64
512 "\n",
513 stats->value->stats->rd_bytes,
514 stats->value->stats->wr_bytes,
515 stats->value->stats->rd_operations,
516 stats->value->stats->wr_operations,
517 stats->value->stats->flush_operations,
518 stats->value->stats->wr_total_time_ns,
519 stats->value->stats->rd_total_time_ns,
520 stats->value->stats->flush_total_time_ns,
521 stats->value->stats->rd_merged,
522 stats->value->stats->wr_merged);
525 qapi_free_BlockStatsList(stats_list);
528 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
530 VncInfo *info;
531 Error *err = NULL;
532 VncClientInfoList *client;
534 info = qmp_query_vnc(&err);
535 if (err) {
536 monitor_printf(mon, "%s\n", error_get_pretty(err));
537 error_free(err);
538 return;
541 if (!info->enabled) {
542 monitor_printf(mon, "Server: disabled\n");
543 goto out;
546 monitor_printf(mon, "Server:\n");
547 if (info->has_host && info->has_service) {
548 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
550 if (info->has_auth) {
551 monitor_printf(mon, " auth: %s\n", info->auth);
554 if (!info->has_clients || info->clients == NULL) {
555 monitor_printf(mon, "Client: none\n");
556 } else {
557 for (client = info->clients; client; client = client->next) {
558 monitor_printf(mon, "Client:\n");
559 monitor_printf(mon, " address: %s:%s\n",
560 client->value->base->host,
561 client->value->base->service);
562 monitor_printf(mon, " x509_dname: %s\n",
563 client->value->x509_dname ?
564 client->value->x509_dname : "none");
565 monitor_printf(mon, " username: %s\n",
566 client->value->has_sasl_username ?
567 client->value->sasl_username : "none");
571 out:
572 qapi_free_VncInfo(info);
575 #ifdef CONFIG_SPICE
576 void hmp_info_spice(Monitor *mon, const QDict *qdict)
578 SpiceChannelList *chan;
579 SpiceInfo *info;
580 const char *channel_name;
581 const char * const channel_names[] = {
582 [SPICE_CHANNEL_MAIN] = "main",
583 [SPICE_CHANNEL_DISPLAY] = "display",
584 [SPICE_CHANNEL_INPUTS] = "inputs",
585 [SPICE_CHANNEL_CURSOR] = "cursor",
586 [SPICE_CHANNEL_PLAYBACK] = "playback",
587 [SPICE_CHANNEL_RECORD] = "record",
588 [SPICE_CHANNEL_TUNNEL] = "tunnel",
589 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
590 [SPICE_CHANNEL_USBREDIR] = "usbredir",
591 [SPICE_CHANNEL_PORT] = "port",
592 #if 0
593 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
594 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
595 * as quick fix for build failures with older versions. */
596 [SPICE_CHANNEL_WEBDAV] = "webdav",
597 #endif
600 info = qmp_query_spice(NULL);
602 if (!info->enabled) {
603 monitor_printf(mon, "Server: disabled\n");
604 goto out;
607 monitor_printf(mon, "Server:\n");
608 if (info->has_port) {
609 monitor_printf(mon, " address: %s:%" PRId64 "\n",
610 info->host, info->port);
612 if (info->has_tls_port) {
613 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
614 info->host, info->tls_port);
616 monitor_printf(mon, " migrated: %s\n",
617 info->migrated ? "true" : "false");
618 monitor_printf(mon, " auth: %s\n", info->auth);
619 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
620 monitor_printf(mon, " mouse-mode: %s\n",
621 SpiceQueryMouseMode_lookup[info->mouse_mode]);
623 if (!info->has_channels || info->channels == NULL) {
624 monitor_printf(mon, "Channels: none\n");
625 } else {
626 for (chan = info->channels; chan; chan = chan->next) {
627 monitor_printf(mon, "Channel:\n");
628 monitor_printf(mon, " address: %s:%s%s\n",
629 chan->value->base->host, chan->value->base->port,
630 chan->value->tls ? " [tls]" : "");
631 monitor_printf(mon, " session: %" PRId64 "\n",
632 chan->value->connection_id);
633 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
634 chan->value->channel_type, chan->value->channel_id);
636 channel_name = "unknown";
637 if (chan->value->channel_type > 0 &&
638 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
639 channel_names[chan->value->channel_type]) {
640 channel_name = channel_names[chan->value->channel_type];
643 monitor_printf(mon, " channel name: %s\n", channel_name);
647 out:
648 qapi_free_SpiceInfo(info);
650 #endif
652 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
654 BalloonInfo *info;
655 Error *err = NULL;
657 info = qmp_query_balloon(&err);
658 if (err) {
659 monitor_printf(mon, "%s\n", error_get_pretty(err));
660 error_free(err);
661 return;
664 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
666 qapi_free_BalloonInfo(info);
669 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
671 PciMemoryRegionList *region;
673 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
674 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
675 dev->slot, dev->function);
676 monitor_printf(mon, " ");
678 if (dev->class_info->has_desc) {
679 monitor_printf(mon, "%s", dev->class_info->desc);
680 } else {
681 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
684 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
685 dev->id->vendor, dev->id->device);
687 if (dev->has_irq) {
688 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
691 if (dev->has_pci_bridge) {
692 monitor_printf(mon, " BUS %" PRId64 ".\n",
693 dev->pci_bridge->bus->number);
694 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
695 dev->pci_bridge->bus->secondary);
696 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
697 dev->pci_bridge->bus->subordinate);
699 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
700 dev->pci_bridge->bus->io_range->base,
701 dev->pci_bridge->bus->io_range->limit);
703 monitor_printf(mon,
704 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
705 dev->pci_bridge->bus->memory_range->base,
706 dev->pci_bridge->bus->memory_range->limit);
708 monitor_printf(mon, " prefetchable memory range "
709 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
710 dev->pci_bridge->bus->prefetchable_range->base,
711 dev->pci_bridge->bus->prefetchable_range->limit);
714 for (region = dev->regions; region; region = region->next) {
715 uint64_t addr, size;
717 addr = region->value->address;
718 size = region->value->size;
720 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
722 if (!strcmp(region->value->type, "io")) {
723 monitor_printf(mon, "I/O at 0x%04" PRIx64
724 " [0x%04" PRIx64 "].\n",
725 addr, addr + size - 1);
726 } else {
727 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
728 " [0x%08" PRIx64 "].\n",
729 region->value->mem_type_64 ? 64 : 32,
730 region->value->prefetch ? " prefetchable" : "",
731 addr, addr + size - 1);
735 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
737 if (dev->has_pci_bridge) {
738 if (dev->pci_bridge->has_devices) {
739 PciDeviceInfoList *cdev;
740 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
741 hmp_info_pci_device(mon, cdev->value);
747 void hmp_info_pci(Monitor *mon, const QDict *qdict)
749 PciInfoList *info_list, *info;
750 Error *err = NULL;
752 info_list = qmp_query_pci(&err);
753 if (err) {
754 monitor_printf(mon, "PCI devices not supported\n");
755 error_free(err);
756 return;
759 for (info = info_list; info; info = info->next) {
760 PciDeviceInfoList *dev;
762 for (dev = info->value->devices; dev; dev = dev->next) {
763 hmp_info_pci_device(mon, dev->value);
767 qapi_free_PciInfoList(info_list);
770 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
772 BlockJobInfoList *list;
773 Error *err = NULL;
775 list = qmp_query_block_jobs(&err);
776 assert(!err);
778 if (!list) {
779 monitor_printf(mon, "No active jobs\n");
780 return;
783 while (list) {
784 if (strcmp(list->value->type, "stream") == 0) {
785 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
786 " of %" PRId64 " bytes, speed limit %" PRId64
787 " bytes/s\n",
788 list->value->device,
789 list->value->offset,
790 list->value->len,
791 list->value->speed);
792 } else {
793 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
794 " of %" PRId64 " bytes, speed limit %" PRId64
795 " bytes/s\n",
796 list->value->type,
797 list->value->device,
798 list->value->offset,
799 list->value->len,
800 list->value->speed);
802 list = list->next;
805 qapi_free_BlockJobInfoList(list);
808 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
810 TPMInfoList *info_list, *info;
811 Error *err = NULL;
812 unsigned int c = 0;
813 TPMPassthroughOptions *tpo;
815 info_list = qmp_query_tpm(&err);
816 if (err) {
817 monitor_printf(mon, "TPM device not supported\n");
818 error_free(err);
819 return;
822 if (info_list) {
823 monitor_printf(mon, "TPM device:\n");
826 for (info = info_list; info; info = info->next) {
827 TPMInfo *ti = info->value;
828 monitor_printf(mon, " tpm%d: model=%s\n",
829 c, TpmModel_lookup[ti->model]);
831 monitor_printf(mon, " \\ %s: type=%s",
832 ti->id, TpmTypeOptionsKind_lookup[ti->options->kind]);
834 switch (ti->options->kind) {
835 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
836 tpo = ti->options->passthrough;
837 monitor_printf(mon, "%s%s%s%s",
838 tpo->has_path ? ",path=" : "",
839 tpo->has_path ? tpo->path : "",
840 tpo->has_cancel_path ? ",cancel-path=" : "",
841 tpo->has_cancel_path ? tpo->cancel_path : "");
842 break;
843 case TPM_TYPE_OPTIONS_KIND_MAX:
844 break;
846 monitor_printf(mon, "\n");
847 c++;
849 qapi_free_TPMInfoList(info_list);
852 void hmp_quit(Monitor *mon, const QDict *qdict)
854 monitor_suspend(mon);
855 qmp_quit(NULL);
858 void hmp_stop(Monitor *mon, const QDict *qdict)
860 qmp_stop(NULL);
863 void hmp_system_reset(Monitor *mon, const QDict *qdict)
865 qmp_system_reset(NULL);
868 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
870 qmp_system_powerdown(NULL);
873 void hmp_cpu(Monitor *mon, const QDict *qdict)
875 int64_t cpu_index;
877 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
878 use it are converted to the QAPI */
879 cpu_index = qdict_get_int(qdict, "index");
880 if (monitor_set_cpu(cpu_index) < 0) {
881 monitor_printf(mon, "invalid CPU index\n");
885 void hmp_memsave(Monitor *mon, const QDict *qdict)
887 uint32_t size = qdict_get_int(qdict, "size");
888 const char *filename = qdict_get_str(qdict, "filename");
889 uint64_t addr = qdict_get_int(qdict, "val");
890 Error *err = NULL;
892 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &err);
893 hmp_handle_error(mon, &err);
896 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
898 uint32_t size = qdict_get_int(qdict, "size");
899 const char *filename = qdict_get_str(qdict, "filename");
900 uint64_t addr = qdict_get_int(qdict, "val");
901 Error *err = NULL;
903 qmp_pmemsave(addr, size, filename, &err);
904 hmp_handle_error(mon, &err);
907 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
909 const char *chardev = qdict_get_str(qdict, "device");
910 const char *data = qdict_get_str(qdict, "data");
911 Error *err = NULL;
913 qmp_ringbuf_write(chardev, data, false, 0, &err);
915 hmp_handle_error(mon, &err);
918 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
920 uint32_t size = qdict_get_int(qdict, "size");
921 const char *chardev = qdict_get_str(qdict, "device");
922 char *data;
923 Error *err = NULL;
924 int i;
926 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
927 if (err) {
928 monitor_printf(mon, "%s\n", error_get_pretty(err));
929 error_free(err);
930 return;
933 for (i = 0; data[i]; i++) {
934 unsigned char ch = data[i];
936 if (ch == '\\') {
937 monitor_printf(mon, "\\\\");
938 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
939 monitor_printf(mon, "\\u%04X", ch);
940 } else {
941 monitor_printf(mon, "%c", ch);
945 monitor_printf(mon, "\n");
946 g_free(data);
949 static void hmp_cont_cb(void *opaque, int err)
951 if (!err) {
952 qmp_cont(NULL);
956 static bool key_is_missing(const BlockInfo *bdev)
958 return (bdev->inserted && bdev->inserted->encryption_key_missing);
961 void hmp_cont(Monitor *mon, const QDict *qdict)
963 BlockInfoList *bdev_list, *bdev;
964 Error *err = NULL;
966 bdev_list = qmp_query_block(NULL);
967 for (bdev = bdev_list; bdev; bdev = bdev->next) {
968 if (key_is_missing(bdev->value)) {
969 monitor_read_block_device_key(mon, bdev->value->device,
970 hmp_cont_cb, NULL);
971 goto out;
975 qmp_cont(&err);
976 hmp_handle_error(mon, &err);
978 out:
979 qapi_free_BlockInfoList(bdev_list);
982 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
984 qmp_system_wakeup(NULL);
987 void hmp_nmi(Monitor *mon, const QDict *qdict)
989 Error *err = NULL;
991 qmp_inject_nmi(&err);
992 hmp_handle_error(mon, &err);
995 void hmp_set_link(Monitor *mon, const QDict *qdict)
997 const char *name = qdict_get_str(qdict, "name");
998 int up = qdict_get_bool(qdict, "up");
999 Error *err = NULL;
1001 qmp_set_link(name, up, &err);
1002 hmp_handle_error(mon, &err);
1005 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1007 const char *device = qdict_get_str(qdict, "device");
1008 const char *password = qdict_get_str(qdict, "password");
1009 Error *err = NULL;
1011 qmp_block_passwd(true, device, false, NULL, password, &err);
1012 hmp_handle_error(mon, &err);
1015 void hmp_balloon(Monitor *mon, const QDict *qdict)
1017 int64_t value = qdict_get_int(qdict, "value");
1018 Error *err = NULL;
1020 qmp_balloon(value, &err);
1021 if (err) {
1022 monitor_printf(mon, "balloon: %s\n", error_get_pretty(err));
1023 error_free(err);
1027 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1029 const char *device = qdict_get_str(qdict, "device");
1030 int64_t size = qdict_get_int(qdict, "size");
1031 Error *err = NULL;
1033 qmp_block_resize(true, device, false, NULL, size, &err);
1034 hmp_handle_error(mon, &err);
1037 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1039 const char *device = qdict_get_str(qdict, "device");
1040 const char *filename = qdict_get_str(qdict, "target");
1041 const char *format = qdict_get_try_str(qdict, "format");
1042 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
1043 int full = qdict_get_try_bool(qdict, "full", 0);
1044 enum NewImageMode mode;
1045 Error *err = NULL;
1047 if (!filename) {
1048 error_set(&err, QERR_MISSING_PARAMETER, "target");
1049 hmp_handle_error(mon, &err);
1050 return;
1053 if (reuse) {
1054 mode = NEW_IMAGE_MODE_EXISTING;
1055 } else {
1056 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1059 qmp_drive_mirror(device, filename, !!format, format,
1060 false, NULL, false, NULL,
1061 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1062 true, mode, false, 0, false, 0, false, 0,
1063 false, 0, false, 0, &err);
1064 hmp_handle_error(mon, &err);
1067 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1069 const char *device = qdict_get_str(qdict, "device");
1070 const char *filename = qdict_get_str(qdict, "target");
1071 const char *format = qdict_get_try_str(qdict, "format");
1072 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
1073 int full = qdict_get_try_bool(qdict, "full", 0);
1074 enum NewImageMode mode;
1075 Error *err = NULL;
1077 if (!filename) {
1078 error_set(&err, QERR_MISSING_PARAMETER, "target");
1079 hmp_handle_error(mon, &err);
1080 return;
1083 if (reuse) {
1084 mode = NEW_IMAGE_MODE_EXISTING;
1085 } else {
1086 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1089 qmp_drive_backup(device, filename, !!format, format,
1090 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1091 true, mode, false, 0, false, NULL,
1092 false, 0, false, 0, &err);
1093 hmp_handle_error(mon, &err);
1096 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1098 const char *device = qdict_get_str(qdict, "device");
1099 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1100 const char *format = qdict_get_try_str(qdict, "format");
1101 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
1102 enum NewImageMode mode;
1103 Error *err = NULL;
1105 if (!filename) {
1106 /* In the future, if 'snapshot-file' is not specified, the snapshot
1107 will be taken internally. Today it's actually required. */
1108 error_set(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1109 hmp_handle_error(mon, &err);
1110 return;
1113 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1114 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1115 filename, false, NULL,
1116 !!format, format,
1117 true, mode, &err);
1118 hmp_handle_error(mon, &err);
1121 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1123 const char *device = qdict_get_str(qdict, "device");
1124 const char *name = qdict_get_str(qdict, "name");
1125 Error *err = NULL;
1127 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1128 hmp_handle_error(mon, &err);
1131 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1133 const char *device = qdict_get_str(qdict, "device");
1134 const char *name = qdict_get_str(qdict, "name");
1135 const char *id = qdict_get_try_str(qdict, "id");
1136 Error *err = NULL;
1138 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1139 true, name, &err);
1140 hmp_handle_error(mon, &err);
1143 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1145 qmp_migrate_cancel(NULL);
1148 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1150 Error *err = NULL;
1151 const char *uri = qdict_get_str(qdict, "uri");
1153 qmp_migrate_incoming(uri, &err);
1155 hmp_handle_error(mon, &err);
1158 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1160 double value = qdict_get_double(qdict, "value");
1161 qmp_migrate_set_downtime(value, NULL);
1164 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1166 int64_t value = qdict_get_int(qdict, "value");
1167 Error *err = NULL;
1169 qmp_migrate_set_cache_size(value, &err);
1170 if (err) {
1171 monitor_printf(mon, "%s\n", error_get_pretty(err));
1172 error_free(err);
1173 return;
1177 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1179 int64_t value = qdict_get_int(qdict, "value");
1180 qmp_migrate_set_speed(value, NULL);
1183 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1185 const char *cap = qdict_get_str(qdict, "capability");
1186 bool state = qdict_get_bool(qdict, "state");
1187 Error *err = NULL;
1188 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1189 int i;
1191 for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
1192 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1193 caps->value = g_malloc0(sizeof(*caps->value));
1194 caps->value->capability = i;
1195 caps->value->state = state;
1196 caps->next = NULL;
1197 qmp_migrate_set_capabilities(caps, &err);
1198 break;
1202 if (i == MIGRATION_CAPABILITY_MAX) {
1203 error_set(&err, QERR_INVALID_PARAMETER, cap);
1206 qapi_free_MigrationCapabilityStatusList(caps);
1208 if (err) {
1209 monitor_printf(mon, "migrate_set_capability: %s\n",
1210 error_get_pretty(err));
1211 error_free(err);
1215 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1217 const char *param = qdict_get_str(qdict, "parameter");
1218 int value = qdict_get_int(qdict, "value");
1219 Error *err = NULL;
1220 bool has_compress_level = false;
1221 bool has_compress_threads = false;
1222 bool has_decompress_threads = false;
1223 int i;
1225 for (i = 0; i < MIGRATION_PARAMETER_MAX; i++) {
1226 if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
1227 switch (i) {
1228 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1229 has_compress_level = true;
1230 break;
1231 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1232 has_compress_threads = true;
1233 break;
1234 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1235 has_decompress_threads = true;
1236 break;
1238 qmp_migrate_set_parameters(has_compress_level, value,
1239 has_compress_threads, value,
1240 has_decompress_threads, value,
1241 &err);
1242 break;
1246 if (i == MIGRATION_PARAMETER_MAX) {
1247 error_set(&err, QERR_INVALID_PARAMETER, param);
1250 if (err) {
1251 monitor_printf(mon, "migrate_set_parameter: %s\n",
1252 error_get_pretty(err));
1253 error_free(err);
1257 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1259 Error *err = NULL;
1260 const char *protocol = qdict_get_str(qdict, "protocol");
1261 const char *hostname = qdict_get_str(qdict, "hostname");
1262 bool has_port = qdict_haskey(qdict, "port");
1263 int port = qdict_get_try_int(qdict, "port", -1);
1264 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1265 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1266 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1268 qmp_client_migrate_info(protocol, hostname,
1269 has_port, port, has_tls_port, tls_port,
1270 !!cert_subject, cert_subject, &err);
1271 hmp_handle_error(mon, &err);
1274 void hmp_set_password(Monitor *mon, const QDict *qdict)
1276 const char *protocol = qdict_get_str(qdict, "protocol");
1277 const char *password = qdict_get_str(qdict, "password");
1278 const char *connected = qdict_get_try_str(qdict, "connected");
1279 Error *err = NULL;
1281 qmp_set_password(protocol, password, !!connected, connected, &err);
1282 hmp_handle_error(mon, &err);
1285 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1287 const char *protocol = qdict_get_str(qdict, "protocol");
1288 const char *whenstr = qdict_get_str(qdict, "time");
1289 Error *err = NULL;
1291 qmp_expire_password(protocol, whenstr, &err);
1292 hmp_handle_error(mon, &err);
1295 void hmp_eject(Monitor *mon, const QDict *qdict)
1297 int force = qdict_get_try_bool(qdict, "force", 0);
1298 const char *device = qdict_get_str(qdict, "device");
1299 Error *err = NULL;
1301 qmp_eject(device, true, force, &err);
1302 hmp_handle_error(mon, &err);
1305 static void hmp_change_read_arg(void *opaque, const char *password,
1306 void *readline_opaque)
1308 qmp_change_vnc_password(password, NULL);
1309 monitor_read_command(opaque, 1);
1312 void hmp_change(Monitor *mon, const QDict *qdict)
1314 const char *device = qdict_get_str(qdict, "device");
1315 const char *target = qdict_get_str(qdict, "target");
1316 const char *arg = qdict_get_try_str(qdict, "arg");
1317 Error *err = NULL;
1319 if (strcmp(device, "vnc") == 0 &&
1320 (strcmp(target, "passwd") == 0 ||
1321 strcmp(target, "password") == 0)) {
1322 if (!arg) {
1323 monitor_read_password(mon, hmp_change_read_arg, NULL);
1324 return;
1328 qmp_change(device, target, !!arg, arg, &err);
1329 if (err &&
1330 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
1331 error_free(err);
1332 monitor_read_block_device_key(mon, device, NULL, NULL);
1333 return;
1335 hmp_handle_error(mon, &err);
1338 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1340 Error *err = NULL;
1342 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
1343 qdict_get_int(qdict, "bps"),
1344 qdict_get_int(qdict, "bps_rd"),
1345 qdict_get_int(qdict, "bps_wr"),
1346 qdict_get_int(qdict, "iops"),
1347 qdict_get_int(qdict, "iops_rd"),
1348 qdict_get_int(qdict, "iops_wr"),
1349 false, /* no burst max via HMP */
1351 false,
1353 false,
1355 false,
1357 false,
1359 false,
1361 false, /* No default I/O size */
1363 false,
1364 NULL, &err);
1365 hmp_handle_error(mon, &err);
1368 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1370 Error *error = NULL;
1371 const char *device = qdict_get_str(qdict, "device");
1372 const char *base = qdict_get_try_str(qdict, "base");
1373 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1375 qmp_block_stream(device, base != NULL, base, false, NULL,
1376 qdict_haskey(qdict, "speed"), speed,
1377 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1379 hmp_handle_error(mon, &error);
1382 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1384 Error *error = NULL;
1385 const char *device = qdict_get_str(qdict, "device");
1386 int64_t value = qdict_get_int(qdict, "speed");
1388 qmp_block_job_set_speed(device, value, &error);
1390 hmp_handle_error(mon, &error);
1393 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1395 Error *error = NULL;
1396 const char *device = qdict_get_str(qdict, "device");
1397 bool force = qdict_get_try_bool(qdict, "force", 0);
1399 qmp_block_job_cancel(device, true, force, &error);
1401 hmp_handle_error(mon, &error);
1404 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1406 Error *error = NULL;
1407 const char *device = qdict_get_str(qdict, "device");
1409 qmp_block_job_pause(device, &error);
1411 hmp_handle_error(mon, &error);
1414 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1416 Error *error = NULL;
1417 const char *device = qdict_get_str(qdict, "device");
1419 qmp_block_job_resume(device, &error);
1421 hmp_handle_error(mon, &error);
1424 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1426 Error *error = NULL;
1427 const char *device = qdict_get_str(qdict, "device");
1429 qmp_block_job_complete(device, &error);
1431 hmp_handle_error(mon, &error);
1434 typedef struct HMPMigrationStatus
1436 QEMUTimer *timer;
1437 Monitor *mon;
1438 bool is_block_migration;
1439 } HMPMigrationStatus;
1441 static void hmp_migrate_status_cb(void *opaque)
1443 HMPMigrationStatus *status = opaque;
1444 MigrationInfo *info;
1446 info = qmp_query_migrate(NULL);
1447 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1448 info->status == MIGRATION_STATUS_SETUP) {
1449 if (info->has_disk) {
1450 int progress;
1452 if (info->disk->remaining) {
1453 progress = info->disk->transferred * 100 / info->disk->total;
1454 } else {
1455 progress = 100;
1458 monitor_printf(status->mon, "Completed %d %%\r", progress);
1459 monitor_flush(status->mon);
1462 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1463 } else {
1464 if (status->is_block_migration) {
1465 monitor_printf(status->mon, "\n");
1467 monitor_resume(status->mon);
1468 timer_del(status->timer);
1469 g_free(status);
1472 qapi_free_MigrationInfo(info);
1475 void hmp_migrate(Monitor *mon, const QDict *qdict)
1477 int detach = qdict_get_try_bool(qdict, "detach", 0);
1478 int blk = qdict_get_try_bool(qdict, "blk", 0);
1479 int inc = qdict_get_try_bool(qdict, "inc", 0);
1480 const char *uri = qdict_get_str(qdict, "uri");
1481 Error *err = NULL;
1483 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1484 if (err) {
1485 monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
1486 error_free(err);
1487 return;
1490 if (!detach) {
1491 HMPMigrationStatus *status;
1493 if (monitor_suspend(mon) < 0) {
1494 monitor_printf(mon, "terminal does not allow synchronous "
1495 "migration, continuing detached\n");
1496 return;
1499 status = g_malloc0(sizeof(*status));
1500 status->mon = mon;
1501 status->is_block_migration = blk || inc;
1502 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1503 status);
1504 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1508 void hmp_device_add(Monitor *mon, const QDict *qdict)
1510 do_device_add(mon, qdict, NULL);
1513 void hmp_device_del(Monitor *mon, const QDict *qdict)
1515 const char *id = qdict_get_str(qdict, "id");
1516 Error *err = NULL;
1518 qmp_device_del(id, &err);
1519 hmp_handle_error(mon, &err);
1522 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1524 Error *err = NULL;
1525 int paging = qdict_get_try_bool(qdict, "paging", 0);
1526 int zlib = qdict_get_try_bool(qdict, "zlib", 0);
1527 int lzo = qdict_get_try_bool(qdict, "lzo", 0);
1528 int snappy = qdict_get_try_bool(qdict, "snappy", 0);
1529 const char *file = qdict_get_str(qdict, "filename");
1530 bool has_begin = qdict_haskey(qdict, "begin");
1531 bool has_length = qdict_haskey(qdict, "length");
1532 int64_t begin = 0;
1533 int64_t length = 0;
1534 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1535 char *prot;
1537 if (zlib + lzo + snappy > 1) {
1538 error_setg(&err, "only one of '-z|-l|-s' can be set");
1539 hmp_handle_error(mon, &err);
1540 return;
1543 if (zlib) {
1544 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1547 if (lzo) {
1548 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1551 if (snappy) {
1552 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1555 if (has_begin) {
1556 begin = qdict_get_int(qdict, "begin");
1558 if (has_length) {
1559 length = qdict_get_int(qdict, "length");
1562 prot = g_strconcat("file:", file, NULL);
1564 qmp_dump_guest_memory(paging, prot, has_begin, begin, has_length, length,
1565 true, dump_format, &err);
1566 hmp_handle_error(mon, &err);
1567 g_free(prot);
1570 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1572 Error *err = NULL;
1573 QemuOpts *opts;
1575 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1576 if (err) {
1577 goto out;
1580 netdev_add(opts, &err);
1581 if (err) {
1582 qemu_opts_del(opts);
1585 out:
1586 hmp_handle_error(mon, &err);
1589 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1591 const char *id = qdict_get_str(qdict, "id");
1592 Error *err = NULL;
1594 qmp_netdev_del(id, &err);
1595 hmp_handle_error(mon, &err);
1598 void hmp_object_add(Monitor *mon, const QDict *qdict)
1600 Error *err = NULL;
1601 Error *err_end = NULL;
1602 QemuOpts *opts;
1603 char *type = NULL;
1604 char *id = NULL;
1605 void *dummy = NULL;
1606 OptsVisitor *ov;
1607 QDict *pdict;
1609 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1610 if (err) {
1611 goto out;
1614 ov = opts_visitor_new(opts);
1615 pdict = qdict_clone_shallow(qdict);
1617 visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err);
1618 if (err) {
1619 goto out_clean;
1622 qdict_del(pdict, "qom-type");
1623 visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
1624 if (err) {
1625 goto out_end;
1628 qdict_del(pdict, "id");
1629 visit_type_str(opts_get_visitor(ov), &id, "id", &err);
1630 if (err) {
1631 goto out_end;
1634 object_add(type, id, pdict, opts_get_visitor(ov), &err);
1636 out_end:
1637 visit_end_struct(opts_get_visitor(ov), &err_end);
1638 if (!err && err_end) {
1639 qmp_object_del(id, NULL);
1641 error_propagate(&err, err_end);
1642 out_clean:
1643 opts_visitor_cleanup(ov);
1645 QDECREF(pdict);
1646 qemu_opts_del(opts);
1647 g_free(id);
1648 g_free(type);
1649 g_free(dummy);
1651 out:
1652 hmp_handle_error(mon, &err);
1655 void hmp_getfd(Monitor *mon, const QDict *qdict)
1657 const char *fdname = qdict_get_str(qdict, "fdname");
1658 Error *err = NULL;
1660 qmp_getfd(fdname, &err);
1661 hmp_handle_error(mon, &err);
1664 void hmp_closefd(Monitor *mon, const QDict *qdict)
1666 const char *fdname = qdict_get_str(qdict, "fdname");
1667 Error *err = NULL;
1669 qmp_closefd(fdname, &err);
1670 hmp_handle_error(mon, &err);
1673 void hmp_sendkey(Monitor *mon, const QDict *qdict)
1675 const char *keys = qdict_get_str(qdict, "keys");
1676 KeyValueList *keylist, *head = NULL, *tmp = NULL;
1677 int has_hold_time = qdict_haskey(qdict, "hold-time");
1678 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1679 Error *err = NULL;
1680 char keyname_buf[16];
1681 char *separator;
1682 int keyname_len;
1684 while (1) {
1685 separator = strchr(keys, '-');
1686 keyname_len = separator ? separator - keys : strlen(keys);
1687 pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
1689 /* Be compatible with old interface, convert user inputted "<" */
1690 if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) {
1691 pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
1692 keyname_len = 4;
1694 keyname_buf[keyname_len] = 0;
1696 keylist = g_malloc0(sizeof(*keylist));
1697 keylist->value = g_malloc0(sizeof(*keylist->value));
1699 if (!head) {
1700 head = keylist;
1702 if (tmp) {
1703 tmp->next = keylist;
1705 tmp = keylist;
1707 if (strstart(keyname_buf, "0x", NULL)) {
1708 char *endp;
1709 int value = strtoul(keyname_buf, &endp, 0);
1710 if (*endp != '\0') {
1711 goto err_out;
1713 keylist->value->kind = KEY_VALUE_KIND_NUMBER;
1714 keylist->value->number = value;
1715 } else {
1716 int idx = index_from_key(keyname_buf);
1717 if (idx == Q_KEY_CODE_MAX) {
1718 goto err_out;
1720 keylist->value->kind = KEY_VALUE_KIND_QCODE;
1721 keylist->value->qcode = idx;
1724 if (!separator) {
1725 break;
1727 keys = separator + 1;
1730 qmp_send_key(head, has_hold_time, hold_time, &err);
1731 hmp_handle_error(mon, &err);
1733 out:
1734 qapi_free_KeyValueList(head);
1735 return;
1737 err_out:
1738 monitor_printf(mon, "invalid parameter: %s\n", keyname_buf);
1739 goto out;
1742 void hmp_screendump(Monitor *mon, const QDict *qdict)
1744 const char *filename = qdict_get_str(qdict, "filename");
1745 Error *err = NULL;
1747 qmp_screendump(filename, &err);
1748 hmp_handle_error(mon, &err);
1751 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1753 const char *uri = qdict_get_str(qdict, "uri");
1754 int writable = qdict_get_try_bool(qdict, "writable", 0);
1755 int all = qdict_get_try_bool(qdict, "all", 0);
1756 Error *local_err = NULL;
1757 BlockInfoList *block_list, *info;
1758 SocketAddress *addr;
1760 if (writable && !all) {
1761 error_setg(&local_err, "-w only valid together with -a");
1762 goto exit;
1765 /* First check if the address is valid and start the server. */
1766 addr = socket_parse(uri, &local_err);
1767 if (local_err != NULL) {
1768 goto exit;
1771 qmp_nbd_server_start(addr, &local_err);
1772 qapi_free_SocketAddress(addr);
1773 if (local_err != NULL) {
1774 goto exit;
1777 if (!all) {
1778 return;
1781 /* Then try adding all block devices. If one fails, close all and
1782 * exit.
1784 block_list = qmp_query_block(NULL);
1786 for (info = block_list; info; info = info->next) {
1787 if (!info->value->has_inserted) {
1788 continue;
1791 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1793 if (local_err != NULL) {
1794 qmp_nbd_server_stop(NULL);
1795 break;
1799 qapi_free_BlockInfoList(block_list);
1801 exit:
1802 hmp_handle_error(mon, &local_err);
1805 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1807 const char *device = qdict_get_str(qdict, "device");
1808 int writable = qdict_get_try_bool(qdict, "writable", 0);
1809 Error *local_err = NULL;
1811 qmp_nbd_server_add(device, true, writable, &local_err);
1813 if (local_err != NULL) {
1814 hmp_handle_error(mon, &local_err);
1818 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1820 Error *err = NULL;
1822 qmp_nbd_server_stop(&err);
1823 hmp_handle_error(mon, &err);
1826 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
1828 int cpuid;
1829 Error *err = NULL;
1831 cpuid = qdict_get_int(qdict, "id");
1832 qmp_cpu_add(cpuid, &err);
1833 hmp_handle_error(mon, &err);
1836 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1838 const char *args = qdict_get_str(qdict, "args");
1839 Error *err = NULL;
1840 QemuOpts *opts;
1842 opts = qemu_opts_parse(qemu_find_opts("chardev"), args, 1);
1843 if (opts == NULL) {
1844 error_setg(&err, "Parsing chardev args failed");
1845 } else {
1846 qemu_chr_new_from_opts(opts, NULL, &err);
1848 hmp_handle_error(mon, &err);
1851 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1853 Error *local_err = NULL;
1855 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1856 hmp_handle_error(mon, &local_err);
1859 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1861 BlockBackend *blk;
1862 const char* device = qdict_get_str(qdict, "device");
1863 const char* command = qdict_get_str(qdict, "command");
1864 Error *err = NULL;
1866 blk = blk_by_name(device);
1867 if (blk) {
1868 qemuio_command(blk, command);
1869 } else {
1870 error_set(&err, QERR_DEVICE_NOT_FOUND, device);
1873 hmp_handle_error(mon, &err);
1876 void hmp_object_del(Monitor *mon, const QDict *qdict)
1878 const char *id = qdict_get_str(qdict, "id");
1879 Error *err = NULL;
1881 qmp_object_del(id, &err);
1882 hmp_handle_error(mon, &err);
1885 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
1887 Error *err = NULL;
1888 MemdevList *memdev_list = qmp_query_memdev(&err);
1889 MemdevList *m = memdev_list;
1890 StringOutputVisitor *ov;
1891 char *str;
1892 int i = 0;
1895 while (m) {
1896 ov = string_output_visitor_new(false);
1897 visit_type_uint16List(string_output_get_visitor(ov),
1898 &m->value->host_nodes, NULL, NULL);
1899 monitor_printf(mon, "memory backend: %d\n", i);
1900 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
1901 monitor_printf(mon, " merge: %s\n",
1902 m->value->merge ? "true" : "false");
1903 monitor_printf(mon, " dump: %s\n",
1904 m->value->dump ? "true" : "false");
1905 monitor_printf(mon, " prealloc: %s\n",
1906 m->value->prealloc ? "true" : "false");
1907 monitor_printf(mon, " policy: %s\n",
1908 HostMemPolicy_lookup[m->value->policy]);
1909 str = string_output_get_string(ov);
1910 monitor_printf(mon, " host nodes: %s\n", str);
1912 g_free(str);
1913 string_output_visitor_cleanup(ov);
1914 m = m->next;
1915 i++;
1918 monitor_printf(mon, "\n");
1920 qapi_free_MemdevList(memdev_list);
1923 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
1925 Error *err = NULL;
1926 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
1927 MemoryDeviceInfoList *info;
1928 MemoryDeviceInfo *value;
1929 PCDIMMDeviceInfo *di;
1931 for (info = info_list; info; info = info->next) {
1932 value = info->value;
1934 if (value) {
1935 switch (value->kind) {
1936 case MEMORY_DEVICE_INFO_KIND_DIMM:
1937 di = value->dimm;
1939 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1940 MemoryDeviceInfoKind_lookup[value->kind],
1941 di->id ? di->id : "");
1942 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
1943 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
1944 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
1945 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
1946 monitor_printf(mon, " memdev: %s\n", di->memdev);
1947 monitor_printf(mon, " hotplugged: %s\n",
1948 di->hotplugged ? "true" : "false");
1949 monitor_printf(mon, " hotpluggable: %s\n",
1950 di->hotpluggable ? "true" : "false");
1951 break;
1952 default:
1953 break;
1958 qapi_free_MemoryDeviceInfoList(info_list);
1961 void hmp_qom_list(Monitor *mon, const QDict *qdict)
1963 const char *path = qdict_get_try_str(qdict, "path");
1964 ObjectPropertyInfoList *list;
1965 Error *err = NULL;
1967 if (path == NULL) {
1968 monitor_printf(mon, "/\n");
1969 return;
1972 list = qmp_qom_list(path, &err);
1973 if (err == NULL) {
1974 ObjectPropertyInfoList *start = list;
1975 while (list != NULL) {
1976 ObjectPropertyInfo *value = list->value;
1978 monitor_printf(mon, "%s (%s)\n",
1979 value->name, value->type);
1980 list = list->next;
1982 qapi_free_ObjectPropertyInfoList(start);
1984 hmp_handle_error(mon, &err);
1987 void hmp_qom_set(Monitor *mon, const QDict *qdict)
1989 const char *path = qdict_get_str(qdict, "path");
1990 const char *property = qdict_get_str(qdict, "property");
1991 const char *value = qdict_get_str(qdict, "value");
1992 Error *err = NULL;
1993 bool ambiguous = false;
1994 Object *obj;
1996 obj = object_resolve_path(path, &ambiguous);
1997 if (obj == NULL) {
1998 error_set(&err, QERR_DEVICE_NOT_FOUND, path);
1999 } else {
2000 if (ambiguous) {
2001 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2003 object_property_parse(obj, value, property, &err);
2005 hmp_handle_error(mon, &err);
2008 void hmp_rocker(Monitor *mon, const QDict *qdict)
2010 const char *name = qdict_get_str(qdict, "name");
2011 RockerSwitch *rocker;
2012 Error *errp = NULL;
2014 rocker = qmp_query_rocker(name, &errp);
2015 if (errp != NULL) {
2016 hmp_handle_error(mon, &errp);
2017 return;
2020 monitor_printf(mon, "name: %s\n", rocker->name);
2021 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2022 monitor_printf(mon, "ports: %d\n", rocker->ports);
2024 qapi_free_RockerSwitch(rocker);
2027 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2029 RockerPortList *list, *port;
2030 const char *name = qdict_get_str(qdict, "name");
2031 Error *errp = NULL;
2033 list = qmp_query_rocker_ports(name, &errp);
2034 if (errp != NULL) {
2035 hmp_handle_error(mon, &errp);
2036 return;
2039 monitor_printf(mon, " ena/ speed/ auto\n");
2040 monitor_printf(mon, " port link duplex neg?\n");
2042 for (port = list; port; port = port->next) {
2043 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2044 port->value->name,
2045 port->value->enabled ? port->value->link_up ?
2046 "up" : "down" : "!ena",
2047 port->value->speed == 10000 ? "10G" : "??",
2048 port->value->duplex ? "FD" : "HD",
2049 port->value->autoneg ? "Yes" : "No");
2052 qapi_free_RockerPortList(list);
2055 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2057 RockerOfDpaFlowList *list, *info;
2058 const char *name = qdict_get_str(qdict, "name");
2059 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2060 Error *errp = NULL;
2062 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &errp);
2063 if (errp != NULL) {
2064 hmp_handle_error(mon, &errp);
2065 return;
2068 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2070 for (info = list; info; info = info->next) {
2071 RockerOfDpaFlow *flow = info->value;
2072 RockerOfDpaFlowKey *key = flow->key;
2073 RockerOfDpaFlowMask *mask = flow->mask;
2074 RockerOfDpaFlowAction *action = flow->action;
2076 if (flow->hits) {
2077 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2078 key->priority, key->tbl_id, flow->hits);
2079 } else {
2080 monitor_printf(mon, "%-4d %-3d ",
2081 key->priority, key->tbl_id);
2084 if (key->has_in_pport) {
2085 monitor_printf(mon, " pport %d", key->in_pport);
2086 if (mask->has_in_pport) {
2087 monitor_printf(mon, "(0x%x)", mask->in_pport);
2091 if (key->has_vlan_id) {
2092 monitor_printf(mon, " vlan %d",
2093 key->vlan_id & VLAN_VID_MASK);
2094 if (mask->has_vlan_id) {
2095 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2099 if (key->has_tunnel_id) {
2100 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2101 if (mask->has_tunnel_id) {
2102 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2106 if (key->has_eth_type) {
2107 switch (key->eth_type) {
2108 case 0x0806:
2109 monitor_printf(mon, " ARP");
2110 break;
2111 case 0x0800:
2112 monitor_printf(mon, " IP");
2113 break;
2114 case 0x86dd:
2115 monitor_printf(mon, " IPv6");
2116 break;
2117 case 0x8809:
2118 monitor_printf(mon, " LACP");
2119 break;
2120 case 0x88cc:
2121 monitor_printf(mon, " LLDP");
2122 break;
2123 default:
2124 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2125 break;
2129 if (key->has_eth_src) {
2130 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2131 (mask->has_eth_src) &&
2132 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2133 monitor_printf(mon, " src <any mcast/bcast>");
2134 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2135 (mask->has_eth_src) &&
2136 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2137 monitor_printf(mon, " src <any ucast>");
2138 } else {
2139 monitor_printf(mon, " src %s", key->eth_src);
2140 if (mask->has_eth_src) {
2141 monitor_printf(mon, "(%s)", mask->eth_src);
2146 if (key->has_eth_dst) {
2147 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2148 (mask->has_eth_dst) &&
2149 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2150 monitor_printf(mon, " dst <any mcast/bcast>");
2151 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2152 (mask->has_eth_dst) &&
2153 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2154 monitor_printf(mon, " dst <any ucast>");
2155 } else {
2156 monitor_printf(mon, " dst %s", key->eth_dst);
2157 if (mask->has_eth_dst) {
2158 monitor_printf(mon, "(%s)", mask->eth_dst);
2163 if (key->has_ip_proto) {
2164 monitor_printf(mon, " proto %d", key->ip_proto);
2165 if (mask->has_ip_proto) {
2166 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2170 if (key->has_ip_tos) {
2171 monitor_printf(mon, " TOS %d", key->ip_tos);
2172 if (mask->has_ip_tos) {
2173 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2177 if (key->has_ip_dst) {
2178 monitor_printf(mon, " dst %s", key->ip_dst);
2181 if (action->has_goto_tbl || action->has_group_id ||
2182 action->has_new_vlan_id) {
2183 monitor_printf(mon, " -->");
2186 if (action->has_new_vlan_id) {
2187 monitor_printf(mon, " apply new vlan %d",
2188 ntohs(action->new_vlan_id));
2191 if (action->has_group_id) {
2192 monitor_printf(mon, " write group 0x%08x", action->group_id);
2195 if (action->has_goto_tbl) {
2196 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2199 monitor_printf(mon, "\n");
2202 qapi_free_RockerOfDpaFlowList(list);
2205 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2207 RockerOfDpaGroupList *list, *g;
2208 const char *name = qdict_get_str(qdict, "name");
2209 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2210 Error *errp = NULL;
2211 bool set = false;
2213 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &errp);
2214 if (errp != NULL) {
2215 hmp_handle_error(mon, &errp);
2216 return;
2219 monitor_printf(mon, "id (decode) --> buckets\n");
2221 for (g = list; g; g = g->next) {
2222 RockerOfDpaGroup *group = g->value;
2224 monitor_printf(mon, "0x%08x", group->id);
2226 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2227 group->type == 1 ? "L2 rewrite" :
2228 group->type == 2 ? "L3 unicast" :
2229 group->type == 3 ? "L2 multicast" :
2230 group->type == 4 ? "L2 flood" :
2231 group->type == 5 ? "L3 interface" :
2232 group->type == 6 ? "L3 multicast" :
2233 group->type == 7 ? "L3 ECMP" :
2234 group->type == 8 ? "L2 overlay" :
2235 "unknown");
2237 if (group->has_vlan_id) {
2238 monitor_printf(mon, " vlan %d", group->vlan_id);
2241 if (group->has_pport) {
2242 monitor_printf(mon, " pport %d", group->pport);
2245 if (group->has_index) {
2246 monitor_printf(mon, " index %d", group->index);
2249 monitor_printf(mon, ") -->");
2251 if (group->has_set_vlan_id && group->set_vlan_id) {
2252 set = true;
2253 monitor_printf(mon, " set vlan %d",
2254 group->set_vlan_id & VLAN_VID_MASK);
2257 if (group->has_set_eth_src) {
2258 if (!set) {
2259 set = true;
2260 monitor_printf(mon, " set");
2262 monitor_printf(mon, " src %s", group->set_eth_src);
2265 if (group->has_set_eth_dst) {
2266 if (!set) {
2267 set = true;
2268 monitor_printf(mon, " set");
2270 monitor_printf(mon, " dst %s", group->set_eth_dst);
2273 set = false;
2275 if (group->has_ttl_check && group->ttl_check) {
2276 monitor_printf(mon, " check TTL");
2279 if (group->has_group_id && group->group_id) {
2280 monitor_printf(mon, " group id 0x%08x", group->group_id);
2283 if (group->has_pop_vlan && group->pop_vlan) {
2284 monitor_printf(mon, " pop vlan");
2287 if (group->has_out_pport) {
2288 monitor_printf(mon, " out pport %d", group->out_pport);
2291 if (group->has_group_ids) {
2292 struct uint32List *id;
2294 monitor_printf(mon, " groups [");
2295 for (id = group->group_ids; id; id = id->next) {
2296 monitor_printf(mon, "0x%08x", id->value);
2297 if (id->next) {
2298 monitor_printf(mon, ",");
2301 monitor_printf(mon, "]");
2304 monitor_printf(mon, "\n");
2307 qapi_free_RockerOfDpaGroupList(list);