Merge remote-tracking branch 'remotes/stefanha/tags/net-pull-request' into staging
[qemu/ar7.git] / hmp.c
blob1e7cac02aca2e5c8804bdb11218502bb8054d3ce
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 "\n",
404 inserted->bps,
405 inserted->bps_rd,
406 inserted->bps_wr,
407 inserted->bps_max,
408 inserted->bps_rd_max,
409 inserted->bps_wr_max,
410 inserted->iops,
411 inserted->iops_rd,
412 inserted->iops_wr,
413 inserted->iops_max,
414 inserted->iops_rd_max,
415 inserted->iops_wr_max,
416 inserted->iops_size);
419 if (verbose) {
420 monitor_printf(mon, "\nImages:\n");
421 image_info = inserted->image;
422 while (1) {
423 bdrv_image_info_dump((fprintf_function)monitor_printf,
424 mon, image_info);
425 if (image_info->has_backing_image) {
426 image_info = image_info->backing_image;
427 } else {
428 break;
434 void hmp_info_block(Monitor *mon, const QDict *qdict)
436 BlockInfoList *block_list, *info;
437 BlockDeviceInfoList *blockdev_list, *blockdev;
438 const char *device = qdict_get_try_str(qdict, "device");
439 bool verbose = qdict_get_try_bool(qdict, "verbose", 0);
440 bool nodes = qdict_get_try_bool(qdict, "nodes", 0);
441 bool printed = false;
443 /* Print BlockBackend information */
444 if (!nodes) {
445 block_list = qmp_query_block(NULL);
446 } else {
447 block_list = NULL;
450 for (info = block_list; info; info = info->next) {
451 if (device && strcmp(device, info->value->device)) {
452 continue;
455 if (info != block_list) {
456 monitor_printf(mon, "\n");
459 print_block_info(mon, info->value, info->value->has_inserted
460 ? info->value->inserted : NULL,
461 verbose);
462 printed = true;
465 qapi_free_BlockInfoList(block_list);
467 if ((!device && !nodes) || printed) {
468 return;
471 /* Print node information */
472 blockdev_list = qmp_query_named_block_nodes(NULL);
473 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
474 assert(blockdev->value->has_node_name);
475 if (device && strcmp(device, blockdev->value->node_name)) {
476 continue;
479 if (blockdev != blockdev_list) {
480 monitor_printf(mon, "\n");
483 print_block_info(mon, NULL, blockdev->value, verbose);
485 qapi_free_BlockDeviceInfoList(blockdev_list);
488 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
490 BlockStatsList *stats_list, *stats;
492 stats_list = qmp_query_blockstats(false, false, NULL);
494 for (stats = stats_list; stats; stats = stats->next) {
495 if (!stats->value->has_device) {
496 continue;
499 monitor_printf(mon, "%s:", stats->value->device);
500 monitor_printf(mon, " rd_bytes=%" PRId64
501 " wr_bytes=%" PRId64
502 " rd_operations=%" PRId64
503 " wr_operations=%" PRId64
504 " flush_operations=%" PRId64
505 " wr_total_time_ns=%" PRId64
506 " rd_total_time_ns=%" PRId64
507 " flush_total_time_ns=%" PRId64
508 " rd_merged=%" PRId64
509 " wr_merged=%" PRId64
510 "\n",
511 stats->value->stats->rd_bytes,
512 stats->value->stats->wr_bytes,
513 stats->value->stats->rd_operations,
514 stats->value->stats->wr_operations,
515 stats->value->stats->flush_operations,
516 stats->value->stats->wr_total_time_ns,
517 stats->value->stats->rd_total_time_ns,
518 stats->value->stats->flush_total_time_ns,
519 stats->value->stats->rd_merged,
520 stats->value->stats->wr_merged);
523 qapi_free_BlockStatsList(stats_list);
526 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
528 VncInfo *info;
529 Error *err = NULL;
530 VncClientInfoList *client;
532 info = qmp_query_vnc(&err);
533 if (err) {
534 monitor_printf(mon, "%s\n", error_get_pretty(err));
535 error_free(err);
536 return;
539 if (!info->enabled) {
540 monitor_printf(mon, "Server: disabled\n");
541 goto out;
544 monitor_printf(mon, "Server:\n");
545 if (info->has_host && info->has_service) {
546 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
548 if (info->has_auth) {
549 monitor_printf(mon, " auth: %s\n", info->auth);
552 if (!info->has_clients || info->clients == NULL) {
553 monitor_printf(mon, "Client: none\n");
554 } else {
555 for (client = info->clients; client; client = client->next) {
556 monitor_printf(mon, "Client:\n");
557 monitor_printf(mon, " address: %s:%s\n",
558 client->value->base->host,
559 client->value->base->service);
560 monitor_printf(mon, " x509_dname: %s\n",
561 client->value->x509_dname ?
562 client->value->x509_dname : "none");
563 monitor_printf(mon, " username: %s\n",
564 client->value->has_sasl_username ?
565 client->value->sasl_username : "none");
569 out:
570 qapi_free_VncInfo(info);
573 #ifdef CONFIG_SPICE
574 void hmp_info_spice(Monitor *mon, const QDict *qdict)
576 SpiceChannelList *chan;
577 SpiceInfo *info;
578 const char *channel_name;
579 const char * const channel_names[] = {
580 [SPICE_CHANNEL_MAIN] = "main",
581 [SPICE_CHANNEL_DISPLAY] = "display",
582 [SPICE_CHANNEL_INPUTS] = "inputs",
583 [SPICE_CHANNEL_CURSOR] = "cursor",
584 [SPICE_CHANNEL_PLAYBACK] = "playback",
585 [SPICE_CHANNEL_RECORD] = "record",
586 [SPICE_CHANNEL_TUNNEL] = "tunnel",
587 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
588 [SPICE_CHANNEL_USBREDIR] = "usbredir",
589 [SPICE_CHANNEL_PORT] = "port",
590 #if 0
591 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
592 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
593 * as quick fix for build failures with older versions. */
594 [SPICE_CHANNEL_WEBDAV] = "webdav",
595 #endif
598 info = qmp_query_spice(NULL);
600 if (!info->enabled) {
601 monitor_printf(mon, "Server: disabled\n");
602 goto out;
605 monitor_printf(mon, "Server:\n");
606 if (info->has_port) {
607 monitor_printf(mon, " address: %s:%" PRId64 "\n",
608 info->host, info->port);
610 if (info->has_tls_port) {
611 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
612 info->host, info->tls_port);
614 monitor_printf(mon, " migrated: %s\n",
615 info->migrated ? "true" : "false");
616 monitor_printf(mon, " auth: %s\n", info->auth);
617 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
618 monitor_printf(mon, " mouse-mode: %s\n",
619 SpiceQueryMouseMode_lookup[info->mouse_mode]);
621 if (!info->has_channels || info->channels == NULL) {
622 monitor_printf(mon, "Channels: none\n");
623 } else {
624 for (chan = info->channels; chan; chan = chan->next) {
625 monitor_printf(mon, "Channel:\n");
626 monitor_printf(mon, " address: %s:%s%s\n",
627 chan->value->base->host, chan->value->base->port,
628 chan->value->tls ? " [tls]" : "");
629 monitor_printf(mon, " session: %" PRId64 "\n",
630 chan->value->connection_id);
631 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
632 chan->value->channel_type, chan->value->channel_id);
634 channel_name = "unknown";
635 if (chan->value->channel_type > 0 &&
636 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
637 channel_names[chan->value->channel_type]) {
638 channel_name = channel_names[chan->value->channel_type];
641 monitor_printf(mon, " channel name: %s\n", channel_name);
645 out:
646 qapi_free_SpiceInfo(info);
648 #endif
650 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
652 BalloonInfo *info;
653 Error *err = NULL;
655 info = qmp_query_balloon(&err);
656 if (err) {
657 monitor_printf(mon, "%s\n", error_get_pretty(err));
658 error_free(err);
659 return;
662 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
664 qapi_free_BalloonInfo(info);
667 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
669 PciMemoryRegionList *region;
671 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
672 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
673 dev->slot, dev->function);
674 monitor_printf(mon, " ");
676 if (dev->class_info->has_desc) {
677 monitor_printf(mon, "%s", dev->class_info->desc);
678 } else {
679 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
682 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
683 dev->id->vendor, dev->id->device);
685 if (dev->has_irq) {
686 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
689 if (dev->has_pci_bridge) {
690 monitor_printf(mon, " BUS %" PRId64 ".\n",
691 dev->pci_bridge->bus->number);
692 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
693 dev->pci_bridge->bus->secondary);
694 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
695 dev->pci_bridge->bus->subordinate);
697 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
698 dev->pci_bridge->bus->io_range->base,
699 dev->pci_bridge->bus->io_range->limit);
701 monitor_printf(mon,
702 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
703 dev->pci_bridge->bus->memory_range->base,
704 dev->pci_bridge->bus->memory_range->limit);
706 monitor_printf(mon, " prefetchable memory range "
707 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
708 dev->pci_bridge->bus->prefetchable_range->base,
709 dev->pci_bridge->bus->prefetchable_range->limit);
712 for (region = dev->regions; region; region = region->next) {
713 uint64_t addr, size;
715 addr = region->value->address;
716 size = region->value->size;
718 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
720 if (!strcmp(region->value->type, "io")) {
721 monitor_printf(mon, "I/O at 0x%04" PRIx64
722 " [0x%04" PRIx64 "].\n",
723 addr, addr + size - 1);
724 } else {
725 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
726 " [0x%08" PRIx64 "].\n",
727 region->value->mem_type_64 ? 64 : 32,
728 region->value->prefetch ? " prefetchable" : "",
729 addr, addr + size - 1);
733 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
735 if (dev->has_pci_bridge) {
736 if (dev->pci_bridge->has_devices) {
737 PciDeviceInfoList *cdev;
738 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
739 hmp_info_pci_device(mon, cdev->value);
745 void hmp_info_pci(Monitor *mon, const QDict *qdict)
747 PciInfoList *info_list, *info;
748 Error *err = NULL;
750 info_list = qmp_query_pci(&err);
751 if (err) {
752 monitor_printf(mon, "PCI devices not supported\n");
753 error_free(err);
754 return;
757 for (info = info_list; info; info = info->next) {
758 PciDeviceInfoList *dev;
760 for (dev = info->value->devices; dev; dev = dev->next) {
761 hmp_info_pci_device(mon, dev->value);
765 qapi_free_PciInfoList(info_list);
768 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
770 BlockJobInfoList *list;
771 Error *err = NULL;
773 list = qmp_query_block_jobs(&err);
774 assert(!err);
776 if (!list) {
777 monitor_printf(mon, "No active jobs\n");
778 return;
781 while (list) {
782 if (strcmp(list->value->type, "stream") == 0) {
783 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
784 " of %" PRId64 " bytes, speed limit %" PRId64
785 " bytes/s\n",
786 list->value->device,
787 list->value->offset,
788 list->value->len,
789 list->value->speed);
790 } else {
791 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
792 " of %" PRId64 " bytes, speed limit %" PRId64
793 " bytes/s\n",
794 list->value->type,
795 list->value->device,
796 list->value->offset,
797 list->value->len,
798 list->value->speed);
800 list = list->next;
803 qapi_free_BlockJobInfoList(list);
806 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
808 TPMInfoList *info_list, *info;
809 Error *err = NULL;
810 unsigned int c = 0;
811 TPMPassthroughOptions *tpo;
813 info_list = qmp_query_tpm(&err);
814 if (err) {
815 monitor_printf(mon, "TPM device not supported\n");
816 error_free(err);
817 return;
820 if (info_list) {
821 monitor_printf(mon, "TPM device:\n");
824 for (info = info_list; info; info = info->next) {
825 TPMInfo *ti = info->value;
826 monitor_printf(mon, " tpm%d: model=%s\n",
827 c, TpmModel_lookup[ti->model]);
829 monitor_printf(mon, " \\ %s: type=%s",
830 ti->id, TpmTypeOptionsKind_lookup[ti->options->kind]);
832 switch (ti->options->kind) {
833 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
834 tpo = ti->options->passthrough;
835 monitor_printf(mon, "%s%s%s%s",
836 tpo->has_path ? ",path=" : "",
837 tpo->has_path ? tpo->path : "",
838 tpo->has_cancel_path ? ",cancel-path=" : "",
839 tpo->has_cancel_path ? tpo->cancel_path : "");
840 break;
841 case TPM_TYPE_OPTIONS_KIND_MAX:
842 break;
844 monitor_printf(mon, "\n");
845 c++;
847 qapi_free_TPMInfoList(info_list);
850 void hmp_quit(Monitor *mon, const QDict *qdict)
852 monitor_suspend(mon);
853 qmp_quit(NULL);
856 void hmp_stop(Monitor *mon, const QDict *qdict)
858 qmp_stop(NULL);
861 void hmp_system_reset(Monitor *mon, const QDict *qdict)
863 qmp_system_reset(NULL);
866 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
868 qmp_system_powerdown(NULL);
871 void hmp_cpu(Monitor *mon, const QDict *qdict)
873 int64_t cpu_index;
875 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
876 use it are converted to the QAPI */
877 cpu_index = qdict_get_int(qdict, "index");
878 if (monitor_set_cpu(cpu_index) < 0) {
879 monitor_printf(mon, "invalid CPU index\n");
883 void hmp_memsave(Monitor *mon, const QDict *qdict)
885 uint32_t size = qdict_get_int(qdict, "size");
886 const char *filename = qdict_get_str(qdict, "filename");
887 uint64_t addr = qdict_get_int(qdict, "val");
888 Error *err = NULL;
890 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &err);
891 hmp_handle_error(mon, &err);
894 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
896 uint32_t size = qdict_get_int(qdict, "size");
897 const char *filename = qdict_get_str(qdict, "filename");
898 uint64_t addr = qdict_get_int(qdict, "val");
899 Error *err = NULL;
901 qmp_pmemsave(addr, size, filename, &err);
902 hmp_handle_error(mon, &err);
905 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
907 const char *chardev = qdict_get_str(qdict, "device");
908 const char *data = qdict_get_str(qdict, "data");
909 Error *err = NULL;
911 qmp_ringbuf_write(chardev, data, false, 0, &err);
913 hmp_handle_error(mon, &err);
916 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
918 uint32_t size = qdict_get_int(qdict, "size");
919 const char *chardev = qdict_get_str(qdict, "device");
920 char *data;
921 Error *err = NULL;
922 int i;
924 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
925 if (err) {
926 monitor_printf(mon, "%s\n", error_get_pretty(err));
927 error_free(err);
928 return;
931 for (i = 0; data[i]; i++) {
932 unsigned char ch = data[i];
934 if (ch == '\\') {
935 monitor_printf(mon, "\\\\");
936 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
937 monitor_printf(mon, "\\u%04X", ch);
938 } else {
939 monitor_printf(mon, "%c", ch);
943 monitor_printf(mon, "\n");
944 g_free(data);
947 static void hmp_cont_cb(void *opaque, int err)
949 if (!err) {
950 qmp_cont(NULL);
954 static bool key_is_missing(const BlockInfo *bdev)
956 return (bdev->inserted && bdev->inserted->encryption_key_missing);
959 void hmp_cont(Monitor *mon, const QDict *qdict)
961 BlockInfoList *bdev_list, *bdev;
962 Error *err = NULL;
964 bdev_list = qmp_query_block(NULL);
965 for (bdev = bdev_list; bdev; bdev = bdev->next) {
966 if (key_is_missing(bdev->value)) {
967 monitor_read_block_device_key(mon, bdev->value->device,
968 hmp_cont_cb, NULL);
969 goto out;
973 qmp_cont(&err);
974 hmp_handle_error(mon, &err);
976 out:
977 qapi_free_BlockInfoList(bdev_list);
980 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
982 qmp_system_wakeup(NULL);
985 void hmp_nmi(Monitor *mon, const QDict *qdict)
987 Error *err = NULL;
989 qmp_inject_nmi(&err);
990 hmp_handle_error(mon, &err);
993 void hmp_set_link(Monitor *mon, const QDict *qdict)
995 const char *name = qdict_get_str(qdict, "name");
996 int up = qdict_get_bool(qdict, "up");
997 Error *err = NULL;
999 qmp_set_link(name, up, &err);
1000 hmp_handle_error(mon, &err);
1003 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1005 const char *device = qdict_get_str(qdict, "device");
1006 const char *password = qdict_get_str(qdict, "password");
1007 Error *err = NULL;
1009 qmp_block_passwd(true, device, false, NULL, password, &err);
1010 hmp_handle_error(mon, &err);
1013 void hmp_balloon(Monitor *mon, const QDict *qdict)
1015 int64_t value = qdict_get_int(qdict, "value");
1016 Error *err = NULL;
1018 qmp_balloon(value, &err);
1019 if (err) {
1020 monitor_printf(mon, "balloon: %s\n", error_get_pretty(err));
1021 error_free(err);
1025 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1027 const char *device = qdict_get_str(qdict, "device");
1028 int64_t size = qdict_get_int(qdict, "size");
1029 Error *err = NULL;
1031 qmp_block_resize(true, device, false, NULL, size, &err);
1032 hmp_handle_error(mon, &err);
1035 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1037 const char *device = qdict_get_str(qdict, "device");
1038 const char *filename = qdict_get_str(qdict, "target");
1039 const char *format = qdict_get_try_str(qdict, "format");
1040 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
1041 int full = qdict_get_try_bool(qdict, "full", 0);
1042 enum NewImageMode mode;
1043 Error *err = NULL;
1045 if (!filename) {
1046 error_set(&err, QERR_MISSING_PARAMETER, "target");
1047 hmp_handle_error(mon, &err);
1048 return;
1051 if (reuse) {
1052 mode = NEW_IMAGE_MODE_EXISTING;
1053 } else {
1054 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1057 qmp_drive_mirror(device, filename, !!format, format,
1058 false, NULL, false, NULL,
1059 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1060 true, mode, false, 0, false, 0, false, 0,
1061 false, 0, false, 0, &err);
1062 hmp_handle_error(mon, &err);
1065 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1067 const char *device = qdict_get_str(qdict, "device");
1068 const char *filename = qdict_get_str(qdict, "target");
1069 const char *format = qdict_get_try_str(qdict, "format");
1070 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
1071 int full = qdict_get_try_bool(qdict, "full", 0);
1072 enum NewImageMode mode;
1073 Error *err = NULL;
1075 if (!filename) {
1076 error_set(&err, QERR_MISSING_PARAMETER, "target");
1077 hmp_handle_error(mon, &err);
1078 return;
1081 if (reuse) {
1082 mode = NEW_IMAGE_MODE_EXISTING;
1083 } else {
1084 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1087 qmp_drive_backup(device, filename, !!format, format,
1088 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1089 true, mode, false, 0, false, NULL,
1090 false, 0, false, 0, &err);
1091 hmp_handle_error(mon, &err);
1094 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1096 const char *device = qdict_get_str(qdict, "device");
1097 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1098 const char *format = qdict_get_try_str(qdict, "format");
1099 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
1100 enum NewImageMode mode;
1101 Error *err = NULL;
1103 if (!filename) {
1104 /* In the future, if 'snapshot-file' is not specified, the snapshot
1105 will be taken internally. Today it's actually required. */
1106 error_set(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1107 hmp_handle_error(mon, &err);
1108 return;
1111 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1112 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1113 filename, false, NULL,
1114 !!format, format,
1115 true, mode, &err);
1116 hmp_handle_error(mon, &err);
1119 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1121 const char *device = qdict_get_str(qdict, "device");
1122 const char *name = qdict_get_str(qdict, "name");
1123 Error *err = NULL;
1125 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1126 hmp_handle_error(mon, &err);
1129 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1131 const char *device = qdict_get_str(qdict, "device");
1132 const char *name = qdict_get_str(qdict, "name");
1133 const char *id = qdict_get_try_str(qdict, "id");
1134 Error *err = NULL;
1136 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1137 true, name, &err);
1138 hmp_handle_error(mon, &err);
1141 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1143 qmp_migrate_cancel(NULL);
1146 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1148 Error *err = NULL;
1149 const char *uri = qdict_get_str(qdict, "uri");
1151 qmp_migrate_incoming(uri, &err);
1153 hmp_handle_error(mon, &err);
1156 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1158 double value = qdict_get_double(qdict, "value");
1159 qmp_migrate_set_downtime(value, NULL);
1162 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1164 int64_t value = qdict_get_int(qdict, "value");
1165 Error *err = NULL;
1167 qmp_migrate_set_cache_size(value, &err);
1168 if (err) {
1169 monitor_printf(mon, "%s\n", error_get_pretty(err));
1170 error_free(err);
1171 return;
1175 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1177 int64_t value = qdict_get_int(qdict, "value");
1178 qmp_migrate_set_speed(value, NULL);
1181 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1183 const char *cap = qdict_get_str(qdict, "capability");
1184 bool state = qdict_get_bool(qdict, "state");
1185 Error *err = NULL;
1186 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1187 int i;
1189 for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
1190 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1191 caps->value = g_malloc0(sizeof(*caps->value));
1192 caps->value->capability = i;
1193 caps->value->state = state;
1194 caps->next = NULL;
1195 qmp_migrate_set_capabilities(caps, &err);
1196 break;
1200 if (i == MIGRATION_CAPABILITY_MAX) {
1201 error_set(&err, QERR_INVALID_PARAMETER, cap);
1204 qapi_free_MigrationCapabilityStatusList(caps);
1206 if (err) {
1207 monitor_printf(mon, "migrate_set_capability: %s\n",
1208 error_get_pretty(err));
1209 error_free(err);
1213 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1215 const char *param = qdict_get_str(qdict, "parameter");
1216 int value = qdict_get_int(qdict, "value");
1217 Error *err = NULL;
1218 bool has_compress_level = false;
1219 bool has_compress_threads = false;
1220 bool has_decompress_threads = false;
1221 int i;
1223 for (i = 0; i < MIGRATION_PARAMETER_MAX; i++) {
1224 if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
1225 switch (i) {
1226 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1227 has_compress_level = true;
1228 break;
1229 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1230 has_compress_threads = true;
1231 break;
1232 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1233 has_decompress_threads = true;
1234 break;
1236 qmp_migrate_set_parameters(has_compress_level, value,
1237 has_compress_threads, value,
1238 has_decompress_threads, value,
1239 &err);
1240 break;
1244 if (i == MIGRATION_PARAMETER_MAX) {
1245 error_set(&err, QERR_INVALID_PARAMETER, param);
1248 if (err) {
1249 monitor_printf(mon, "migrate_set_parameter: %s\n",
1250 error_get_pretty(err));
1251 error_free(err);
1255 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1257 Error *err = NULL;
1258 const char *protocol = qdict_get_str(qdict, "protocol");
1259 const char *hostname = qdict_get_str(qdict, "hostname");
1260 bool has_port = qdict_haskey(qdict, "port");
1261 int port = qdict_get_try_int(qdict, "port", -1);
1262 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1263 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1264 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1266 qmp_client_migrate_info(protocol, hostname,
1267 has_port, port, has_tls_port, tls_port,
1268 !!cert_subject, cert_subject, &err);
1269 hmp_handle_error(mon, &err);
1272 void hmp_set_password(Monitor *mon, const QDict *qdict)
1274 const char *protocol = qdict_get_str(qdict, "protocol");
1275 const char *password = qdict_get_str(qdict, "password");
1276 const char *connected = qdict_get_try_str(qdict, "connected");
1277 Error *err = NULL;
1279 qmp_set_password(protocol, password, !!connected, connected, &err);
1280 hmp_handle_error(mon, &err);
1283 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1285 const char *protocol = qdict_get_str(qdict, "protocol");
1286 const char *whenstr = qdict_get_str(qdict, "time");
1287 Error *err = NULL;
1289 qmp_expire_password(protocol, whenstr, &err);
1290 hmp_handle_error(mon, &err);
1293 void hmp_eject(Monitor *mon, const QDict *qdict)
1295 int force = qdict_get_try_bool(qdict, "force", 0);
1296 const char *device = qdict_get_str(qdict, "device");
1297 Error *err = NULL;
1299 qmp_eject(device, true, force, &err);
1300 hmp_handle_error(mon, &err);
1303 static void hmp_change_read_arg(void *opaque, const char *password,
1304 void *readline_opaque)
1306 qmp_change_vnc_password(password, NULL);
1307 monitor_read_command(opaque, 1);
1310 void hmp_change(Monitor *mon, const QDict *qdict)
1312 const char *device = qdict_get_str(qdict, "device");
1313 const char *target = qdict_get_str(qdict, "target");
1314 const char *arg = qdict_get_try_str(qdict, "arg");
1315 Error *err = NULL;
1317 if (strcmp(device, "vnc") == 0 &&
1318 (strcmp(target, "passwd") == 0 ||
1319 strcmp(target, "password") == 0)) {
1320 if (!arg) {
1321 monitor_read_password(mon, hmp_change_read_arg, NULL);
1322 return;
1326 qmp_change(device, target, !!arg, arg, &err);
1327 if (err &&
1328 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
1329 error_free(err);
1330 monitor_read_block_device_key(mon, device, NULL, NULL);
1331 return;
1333 hmp_handle_error(mon, &err);
1336 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1338 Error *err = NULL;
1340 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
1341 qdict_get_int(qdict, "bps"),
1342 qdict_get_int(qdict, "bps_rd"),
1343 qdict_get_int(qdict, "bps_wr"),
1344 qdict_get_int(qdict, "iops"),
1345 qdict_get_int(qdict, "iops_rd"),
1346 qdict_get_int(qdict, "iops_wr"),
1347 false, /* no burst max via HMP */
1349 false,
1351 false,
1353 false,
1355 false,
1357 false,
1359 false, /* No default I/O size */
1360 0, &err);
1361 hmp_handle_error(mon, &err);
1364 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1366 Error *error = NULL;
1367 const char *device = qdict_get_str(qdict, "device");
1368 const char *base = qdict_get_try_str(qdict, "base");
1369 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1371 qmp_block_stream(device, base != NULL, base, false, NULL,
1372 qdict_haskey(qdict, "speed"), speed,
1373 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1375 hmp_handle_error(mon, &error);
1378 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1380 Error *error = NULL;
1381 const char *device = qdict_get_str(qdict, "device");
1382 int64_t value = qdict_get_int(qdict, "speed");
1384 qmp_block_job_set_speed(device, value, &error);
1386 hmp_handle_error(mon, &error);
1389 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1391 Error *error = NULL;
1392 const char *device = qdict_get_str(qdict, "device");
1393 bool force = qdict_get_try_bool(qdict, "force", 0);
1395 qmp_block_job_cancel(device, true, force, &error);
1397 hmp_handle_error(mon, &error);
1400 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1402 Error *error = NULL;
1403 const char *device = qdict_get_str(qdict, "device");
1405 qmp_block_job_pause(device, &error);
1407 hmp_handle_error(mon, &error);
1410 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1412 Error *error = NULL;
1413 const char *device = qdict_get_str(qdict, "device");
1415 qmp_block_job_resume(device, &error);
1417 hmp_handle_error(mon, &error);
1420 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1422 Error *error = NULL;
1423 const char *device = qdict_get_str(qdict, "device");
1425 qmp_block_job_complete(device, &error);
1427 hmp_handle_error(mon, &error);
1430 typedef struct HMPMigrationStatus
1432 QEMUTimer *timer;
1433 Monitor *mon;
1434 bool is_block_migration;
1435 } HMPMigrationStatus;
1437 static void hmp_migrate_status_cb(void *opaque)
1439 HMPMigrationStatus *status = opaque;
1440 MigrationInfo *info;
1442 info = qmp_query_migrate(NULL);
1443 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1444 info->status == MIGRATION_STATUS_SETUP) {
1445 if (info->has_disk) {
1446 int progress;
1448 if (info->disk->remaining) {
1449 progress = info->disk->transferred * 100 / info->disk->total;
1450 } else {
1451 progress = 100;
1454 monitor_printf(status->mon, "Completed %d %%\r", progress);
1455 monitor_flush(status->mon);
1458 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1459 } else {
1460 if (status->is_block_migration) {
1461 monitor_printf(status->mon, "\n");
1463 monitor_resume(status->mon);
1464 timer_del(status->timer);
1465 g_free(status);
1468 qapi_free_MigrationInfo(info);
1471 void hmp_migrate(Monitor *mon, const QDict *qdict)
1473 int detach = qdict_get_try_bool(qdict, "detach", 0);
1474 int blk = qdict_get_try_bool(qdict, "blk", 0);
1475 int inc = qdict_get_try_bool(qdict, "inc", 0);
1476 const char *uri = qdict_get_str(qdict, "uri");
1477 Error *err = NULL;
1479 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1480 if (err) {
1481 monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
1482 error_free(err);
1483 return;
1486 if (!detach) {
1487 HMPMigrationStatus *status;
1489 if (monitor_suspend(mon) < 0) {
1490 monitor_printf(mon, "terminal does not allow synchronous "
1491 "migration, continuing detached\n");
1492 return;
1495 status = g_malloc0(sizeof(*status));
1496 status->mon = mon;
1497 status->is_block_migration = blk || inc;
1498 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1499 status);
1500 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1504 void hmp_device_add(Monitor *mon, const QDict *qdict)
1506 do_device_add(mon, qdict, NULL);
1509 void hmp_device_del(Monitor *mon, const QDict *qdict)
1511 const char *id = qdict_get_str(qdict, "id");
1512 Error *err = NULL;
1514 qmp_device_del(id, &err);
1515 hmp_handle_error(mon, &err);
1518 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1520 Error *err = NULL;
1521 int paging = qdict_get_try_bool(qdict, "paging", 0);
1522 int zlib = qdict_get_try_bool(qdict, "zlib", 0);
1523 int lzo = qdict_get_try_bool(qdict, "lzo", 0);
1524 int snappy = qdict_get_try_bool(qdict, "snappy", 0);
1525 const char *file = qdict_get_str(qdict, "filename");
1526 bool has_begin = qdict_haskey(qdict, "begin");
1527 bool has_length = qdict_haskey(qdict, "length");
1528 int64_t begin = 0;
1529 int64_t length = 0;
1530 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1531 char *prot;
1533 if (zlib + lzo + snappy > 1) {
1534 error_setg(&err, "only one of '-z|-l|-s' can be set");
1535 hmp_handle_error(mon, &err);
1536 return;
1539 if (zlib) {
1540 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1543 if (lzo) {
1544 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1547 if (snappy) {
1548 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1551 if (has_begin) {
1552 begin = qdict_get_int(qdict, "begin");
1554 if (has_length) {
1555 length = qdict_get_int(qdict, "length");
1558 prot = g_strconcat("file:", file, NULL);
1560 qmp_dump_guest_memory(paging, prot, has_begin, begin, has_length, length,
1561 true, dump_format, &err);
1562 hmp_handle_error(mon, &err);
1563 g_free(prot);
1566 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1568 Error *err = NULL;
1569 QemuOpts *opts;
1571 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1572 if (err) {
1573 goto out;
1576 netdev_add(opts, &err);
1577 if (err) {
1578 qemu_opts_del(opts);
1581 out:
1582 hmp_handle_error(mon, &err);
1585 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1587 const char *id = qdict_get_str(qdict, "id");
1588 Error *err = NULL;
1590 qmp_netdev_del(id, &err);
1591 hmp_handle_error(mon, &err);
1594 void hmp_object_add(Monitor *mon, const QDict *qdict)
1596 Error *err = NULL;
1597 Error *err_end = NULL;
1598 QemuOpts *opts;
1599 char *type = NULL;
1600 char *id = NULL;
1601 void *dummy = NULL;
1602 OptsVisitor *ov;
1603 QDict *pdict;
1605 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1606 if (err) {
1607 goto out;
1610 ov = opts_visitor_new(opts);
1611 pdict = qdict_clone_shallow(qdict);
1613 visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err);
1614 if (err) {
1615 goto out_clean;
1618 qdict_del(pdict, "qom-type");
1619 visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
1620 if (err) {
1621 goto out_end;
1624 qdict_del(pdict, "id");
1625 visit_type_str(opts_get_visitor(ov), &id, "id", &err);
1626 if (err) {
1627 goto out_end;
1630 object_add(type, id, pdict, opts_get_visitor(ov), &err);
1632 out_end:
1633 visit_end_struct(opts_get_visitor(ov), &err_end);
1634 if (!err && err_end) {
1635 qmp_object_del(id, NULL);
1637 error_propagate(&err, err_end);
1638 out_clean:
1639 opts_visitor_cleanup(ov);
1641 QDECREF(pdict);
1642 qemu_opts_del(opts);
1643 g_free(id);
1644 g_free(type);
1645 g_free(dummy);
1647 out:
1648 hmp_handle_error(mon, &err);
1651 void hmp_getfd(Monitor *mon, const QDict *qdict)
1653 const char *fdname = qdict_get_str(qdict, "fdname");
1654 Error *err = NULL;
1656 qmp_getfd(fdname, &err);
1657 hmp_handle_error(mon, &err);
1660 void hmp_closefd(Monitor *mon, const QDict *qdict)
1662 const char *fdname = qdict_get_str(qdict, "fdname");
1663 Error *err = NULL;
1665 qmp_closefd(fdname, &err);
1666 hmp_handle_error(mon, &err);
1669 void hmp_sendkey(Monitor *mon, const QDict *qdict)
1671 const char *keys = qdict_get_str(qdict, "keys");
1672 KeyValueList *keylist, *head = NULL, *tmp = NULL;
1673 int has_hold_time = qdict_haskey(qdict, "hold-time");
1674 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1675 Error *err = NULL;
1676 char keyname_buf[16];
1677 char *separator;
1678 int keyname_len;
1680 while (1) {
1681 separator = strchr(keys, '-');
1682 keyname_len = separator ? separator - keys : strlen(keys);
1683 pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
1685 /* Be compatible with old interface, convert user inputted "<" */
1686 if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) {
1687 pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
1688 keyname_len = 4;
1690 keyname_buf[keyname_len] = 0;
1692 keylist = g_malloc0(sizeof(*keylist));
1693 keylist->value = g_malloc0(sizeof(*keylist->value));
1695 if (!head) {
1696 head = keylist;
1698 if (tmp) {
1699 tmp->next = keylist;
1701 tmp = keylist;
1703 if (strstart(keyname_buf, "0x", NULL)) {
1704 char *endp;
1705 int value = strtoul(keyname_buf, &endp, 0);
1706 if (*endp != '\0') {
1707 goto err_out;
1709 keylist->value->kind = KEY_VALUE_KIND_NUMBER;
1710 keylist->value->number = value;
1711 } else {
1712 int idx = index_from_key(keyname_buf);
1713 if (idx == Q_KEY_CODE_MAX) {
1714 goto err_out;
1716 keylist->value->kind = KEY_VALUE_KIND_QCODE;
1717 keylist->value->qcode = idx;
1720 if (!separator) {
1721 break;
1723 keys = separator + 1;
1726 qmp_send_key(head, has_hold_time, hold_time, &err);
1727 hmp_handle_error(mon, &err);
1729 out:
1730 qapi_free_KeyValueList(head);
1731 return;
1733 err_out:
1734 monitor_printf(mon, "invalid parameter: %s\n", keyname_buf);
1735 goto out;
1738 void hmp_screendump(Monitor *mon, const QDict *qdict)
1740 const char *filename = qdict_get_str(qdict, "filename");
1741 Error *err = NULL;
1743 qmp_screendump(filename, &err);
1744 hmp_handle_error(mon, &err);
1747 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1749 const char *uri = qdict_get_str(qdict, "uri");
1750 int writable = qdict_get_try_bool(qdict, "writable", 0);
1751 int all = qdict_get_try_bool(qdict, "all", 0);
1752 Error *local_err = NULL;
1753 BlockInfoList *block_list, *info;
1754 SocketAddress *addr;
1756 if (writable && !all) {
1757 error_setg(&local_err, "-w only valid together with -a");
1758 goto exit;
1761 /* First check if the address is valid and start the server. */
1762 addr = socket_parse(uri, &local_err);
1763 if (local_err != NULL) {
1764 goto exit;
1767 qmp_nbd_server_start(addr, &local_err);
1768 qapi_free_SocketAddress(addr);
1769 if (local_err != NULL) {
1770 goto exit;
1773 if (!all) {
1774 return;
1777 /* Then try adding all block devices. If one fails, close all and
1778 * exit.
1780 block_list = qmp_query_block(NULL);
1782 for (info = block_list; info; info = info->next) {
1783 if (!info->value->has_inserted) {
1784 continue;
1787 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1789 if (local_err != NULL) {
1790 qmp_nbd_server_stop(NULL);
1791 break;
1795 qapi_free_BlockInfoList(block_list);
1797 exit:
1798 hmp_handle_error(mon, &local_err);
1801 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1803 const char *device = qdict_get_str(qdict, "device");
1804 int writable = qdict_get_try_bool(qdict, "writable", 0);
1805 Error *local_err = NULL;
1807 qmp_nbd_server_add(device, true, writable, &local_err);
1809 if (local_err != NULL) {
1810 hmp_handle_error(mon, &local_err);
1814 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1816 Error *err = NULL;
1818 qmp_nbd_server_stop(&err);
1819 hmp_handle_error(mon, &err);
1822 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
1824 int cpuid;
1825 Error *err = NULL;
1827 cpuid = qdict_get_int(qdict, "id");
1828 qmp_cpu_add(cpuid, &err);
1829 hmp_handle_error(mon, &err);
1832 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1834 const char *args = qdict_get_str(qdict, "args");
1835 Error *err = NULL;
1836 QemuOpts *opts;
1838 opts = qemu_opts_parse(qemu_find_opts("chardev"), args, 1);
1839 if (opts == NULL) {
1840 error_setg(&err, "Parsing chardev args failed");
1841 } else {
1842 qemu_chr_new_from_opts(opts, NULL, &err);
1844 hmp_handle_error(mon, &err);
1847 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1849 Error *local_err = NULL;
1851 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1852 hmp_handle_error(mon, &local_err);
1855 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1857 BlockBackend *blk;
1858 const char* device = qdict_get_str(qdict, "device");
1859 const char* command = qdict_get_str(qdict, "command");
1860 Error *err = NULL;
1862 blk = blk_by_name(device);
1863 if (blk) {
1864 qemuio_command(blk, command);
1865 } else {
1866 error_set(&err, QERR_DEVICE_NOT_FOUND, device);
1869 hmp_handle_error(mon, &err);
1872 void hmp_object_del(Monitor *mon, const QDict *qdict)
1874 const char *id = qdict_get_str(qdict, "id");
1875 Error *err = NULL;
1877 qmp_object_del(id, &err);
1878 hmp_handle_error(mon, &err);
1881 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
1883 Error *err = NULL;
1884 MemdevList *memdev_list = qmp_query_memdev(&err);
1885 MemdevList *m = memdev_list;
1886 StringOutputVisitor *ov;
1887 char *str;
1888 int i = 0;
1891 while (m) {
1892 ov = string_output_visitor_new(false);
1893 visit_type_uint16List(string_output_get_visitor(ov),
1894 &m->value->host_nodes, NULL, NULL);
1895 monitor_printf(mon, "memory backend: %d\n", i);
1896 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
1897 monitor_printf(mon, " merge: %s\n",
1898 m->value->merge ? "true" : "false");
1899 monitor_printf(mon, " dump: %s\n",
1900 m->value->dump ? "true" : "false");
1901 monitor_printf(mon, " prealloc: %s\n",
1902 m->value->prealloc ? "true" : "false");
1903 monitor_printf(mon, " policy: %s\n",
1904 HostMemPolicy_lookup[m->value->policy]);
1905 str = string_output_get_string(ov);
1906 monitor_printf(mon, " host nodes: %s\n", str);
1908 g_free(str);
1909 string_output_visitor_cleanup(ov);
1910 m = m->next;
1911 i++;
1914 monitor_printf(mon, "\n");
1916 qapi_free_MemdevList(memdev_list);
1919 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
1921 Error *err = NULL;
1922 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
1923 MemoryDeviceInfoList *info;
1924 MemoryDeviceInfo *value;
1925 PCDIMMDeviceInfo *di;
1927 for (info = info_list; info; info = info->next) {
1928 value = info->value;
1930 if (value) {
1931 switch (value->kind) {
1932 case MEMORY_DEVICE_INFO_KIND_DIMM:
1933 di = value->dimm;
1935 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1936 MemoryDeviceInfoKind_lookup[value->kind],
1937 di->id ? di->id : "");
1938 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
1939 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
1940 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
1941 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
1942 monitor_printf(mon, " memdev: %s\n", di->memdev);
1943 monitor_printf(mon, " hotplugged: %s\n",
1944 di->hotplugged ? "true" : "false");
1945 monitor_printf(mon, " hotpluggable: %s\n",
1946 di->hotpluggable ? "true" : "false");
1947 break;
1948 default:
1949 break;
1954 qapi_free_MemoryDeviceInfoList(info_list);
1957 void hmp_qom_list(Monitor *mon, const QDict *qdict)
1959 const char *path = qdict_get_try_str(qdict, "path");
1960 ObjectPropertyInfoList *list;
1961 Error *err = NULL;
1963 if (path == NULL) {
1964 monitor_printf(mon, "/\n");
1965 return;
1968 list = qmp_qom_list(path, &err);
1969 if (err == NULL) {
1970 ObjectPropertyInfoList *start = list;
1971 while (list != NULL) {
1972 ObjectPropertyInfo *value = list->value;
1974 monitor_printf(mon, "%s (%s)\n",
1975 value->name, value->type);
1976 list = list->next;
1978 qapi_free_ObjectPropertyInfoList(start);
1980 hmp_handle_error(mon, &err);
1983 void hmp_qom_set(Monitor *mon, const QDict *qdict)
1985 const char *path = qdict_get_str(qdict, "path");
1986 const char *property = qdict_get_str(qdict, "property");
1987 const char *value = qdict_get_str(qdict, "value");
1988 Error *err = NULL;
1989 bool ambiguous = false;
1990 Object *obj;
1992 obj = object_resolve_path(path, &ambiguous);
1993 if (obj == NULL) {
1994 error_set(&err, QERR_DEVICE_NOT_FOUND, path);
1995 } else {
1996 if (ambiguous) {
1997 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
1999 object_property_parse(obj, value, property, &err);
2001 hmp_handle_error(mon, &err);
2004 void hmp_rocker(Monitor *mon, const QDict *qdict)
2006 const char *name = qdict_get_str(qdict, "name");
2007 RockerSwitch *rocker;
2008 Error *errp = NULL;
2010 rocker = qmp_query_rocker(name, &errp);
2011 if (errp != NULL) {
2012 hmp_handle_error(mon, &errp);
2013 return;
2016 monitor_printf(mon, "name: %s\n", rocker->name);
2017 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2018 monitor_printf(mon, "ports: %d\n", rocker->ports);
2020 qapi_free_RockerSwitch(rocker);
2023 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2025 RockerPortList *list, *port;
2026 const char *name = qdict_get_str(qdict, "name");
2027 Error *errp = NULL;
2029 list = qmp_query_rocker_ports(name, &errp);
2030 if (errp != NULL) {
2031 hmp_handle_error(mon, &errp);
2032 return;
2035 monitor_printf(mon, " ena/ speed/ auto\n");
2036 monitor_printf(mon, " port link duplex neg?\n");
2038 for (port = list; port; port = port->next) {
2039 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2040 port->value->name,
2041 port->value->enabled ? port->value->link_up ?
2042 "up" : "down" : "!ena",
2043 port->value->speed == 10000 ? "10G" : "??",
2044 port->value->duplex ? "FD" : "HD",
2045 port->value->autoneg ? "Yes" : "No");
2048 qapi_free_RockerPortList(list);
2051 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2053 RockerOfDpaFlowList *list, *info;
2054 const char *name = qdict_get_str(qdict, "name");
2055 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2056 Error *errp = NULL;
2058 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &errp);
2059 if (errp != NULL) {
2060 hmp_handle_error(mon, &errp);
2061 return;
2064 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2066 for (info = list; info; info = info->next) {
2067 RockerOfDpaFlow *flow = info->value;
2068 RockerOfDpaFlowKey *key = flow->key;
2069 RockerOfDpaFlowMask *mask = flow->mask;
2070 RockerOfDpaFlowAction *action = flow->action;
2072 if (flow->hits) {
2073 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2074 key->priority, key->tbl_id, flow->hits);
2075 } else {
2076 monitor_printf(mon, "%-4d %-3d ",
2077 key->priority, key->tbl_id);
2080 if (key->has_in_pport) {
2081 monitor_printf(mon, " pport %d", key->in_pport);
2082 if (mask->has_in_pport) {
2083 monitor_printf(mon, "(0x%x)", mask->in_pport);
2087 if (key->has_vlan_id) {
2088 monitor_printf(mon, " vlan %d",
2089 key->vlan_id & VLAN_VID_MASK);
2090 if (mask->has_vlan_id) {
2091 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2095 if (key->has_tunnel_id) {
2096 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2097 if (mask->has_tunnel_id) {
2098 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2102 if (key->has_eth_type) {
2103 switch (key->eth_type) {
2104 case 0x0806:
2105 monitor_printf(mon, " ARP");
2106 break;
2107 case 0x0800:
2108 monitor_printf(mon, " IP");
2109 break;
2110 case 0x86dd:
2111 monitor_printf(mon, " IPv6");
2112 break;
2113 case 0x8809:
2114 monitor_printf(mon, " LACP");
2115 break;
2116 case 0x88cc:
2117 monitor_printf(mon, " LLDP");
2118 break;
2119 default:
2120 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2121 break;
2125 if (key->has_eth_src) {
2126 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2127 (mask->has_eth_src) &&
2128 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2129 monitor_printf(mon, " src <any mcast/bcast>");
2130 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2131 (mask->has_eth_src) &&
2132 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2133 monitor_printf(mon, " src <any ucast>");
2134 } else {
2135 monitor_printf(mon, " src %s", key->eth_src);
2136 if (mask->has_eth_src) {
2137 monitor_printf(mon, "(%s)", mask->eth_src);
2142 if (key->has_eth_dst) {
2143 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2144 (mask->has_eth_dst) &&
2145 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2146 monitor_printf(mon, " dst <any mcast/bcast>");
2147 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2148 (mask->has_eth_dst) &&
2149 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2150 monitor_printf(mon, " dst <any ucast>");
2151 } else {
2152 monitor_printf(mon, " dst %s", key->eth_dst);
2153 if (mask->has_eth_dst) {
2154 monitor_printf(mon, "(%s)", mask->eth_dst);
2159 if (key->has_ip_proto) {
2160 monitor_printf(mon, " proto %d", key->ip_proto);
2161 if (mask->has_ip_proto) {
2162 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2166 if (key->has_ip_tos) {
2167 monitor_printf(mon, " TOS %d", key->ip_tos);
2168 if (mask->has_ip_tos) {
2169 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2173 if (key->has_ip_dst) {
2174 monitor_printf(mon, " dst %s", key->ip_dst);
2177 if (action->has_goto_tbl || action->has_group_id ||
2178 action->has_new_vlan_id) {
2179 monitor_printf(mon, " -->");
2182 if (action->has_new_vlan_id) {
2183 monitor_printf(mon, " apply new vlan %d",
2184 ntohs(action->new_vlan_id));
2187 if (action->has_group_id) {
2188 monitor_printf(mon, " write group 0x%08x", action->group_id);
2191 if (action->has_goto_tbl) {
2192 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2195 monitor_printf(mon, "\n");
2198 qapi_free_RockerOfDpaFlowList(list);
2201 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2203 RockerOfDpaGroupList *list, *g;
2204 const char *name = qdict_get_str(qdict, "name");
2205 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2206 Error *errp = NULL;
2207 bool set = false;
2209 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &errp);
2210 if (errp != NULL) {
2211 hmp_handle_error(mon, &errp);
2212 return;
2215 monitor_printf(mon, "id (decode) --> buckets\n");
2217 for (g = list; g; g = g->next) {
2218 RockerOfDpaGroup *group = g->value;
2220 monitor_printf(mon, "0x%08x", group->id);
2222 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2223 group->type == 1 ? "L2 rewrite" :
2224 group->type == 2 ? "L3 unicast" :
2225 group->type == 3 ? "L2 multicast" :
2226 group->type == 4 ? "L2 flood" :
2227 group->type == 5 ? "L3 interface" :
2228 group->type == 6 ? "L3 multicast" :
2229 group->type == 7 ? "L3 ECMP" :
2230 group->type == 8 ? "L2 overlay" :
2231 "unknown");
2233 if (group->has_vlan_id) {
2234 monitor_printf(mon, " vlan %d", group->vlan_id);
2237 if (group->has_pport) {
2238 monitor_printf(mon, " pport %d", group->pport);
2241 if (group->has_index) {
2242 monitor_printf(mon, " index %d", group->index);
2245 monitor_printf(mon, ") -->");
2247 if (group->has_set_vlan_id && group->set_vlan_id) {
2248 set = true;
2249 monitor_printf(mon, " set vlan %d",
2250 group->set_vlan_id & VLAN_VID_MASK);
2253 if (group->has_set_eth_src) {
2254 if (!set) {
2255 set = true;
2256 monitor_printf(mon, " set");
2258 monitor_printf(mon, " src %s", group->set_eth_src);
2261 if (group->has_set_eth_dst) {
2262 if (!set) {
2263 set = true;
2264 monitor_printf(mon, " set");
2266 monitor_printf(mon, " dst %s", group->set_eth_dst);
2269 set = false;
2271 if (group->has_ttl_check && group->ttl_check) {
2272 monitor_printf(mon, " check TTL");
2275 if (group->has_group_id && group->group_id) {
2276 monitor_printf(mon, " group id 0x%08x", group->group_id);
2279 if (group->has_pop_vlan && group->pop_vlan) {
2280 monitor_printf(mon, " pop vlan");
2283 if (group->has_out_pport) {
2284 monitor_printf(mon, " out pport %d", group->out_pport);
2287 if (group->has_group_ids) {
2288 struct uint32List *id;
2290 monitor_printf(mon, " groups [");
2291 for (id = group->group_ids; id; id = id->next) {
2292 monitor_printf(mon, "0x%08x", id->value);
2293 if (id->next) {
2294 monitor_printf(mon, ",");
2297 monitor_printf(mon, "]");
2300 monitor_printf(mon, "\n");
2303 qapi_free_RockerOfDpaGroupList(list);