qerror: Move #include out of qerror.h
[qemu.git] / hmp.c
blobfd10ab51b4f828e967ead4c7cec6acde20793f26
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", false);
442 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
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 bool 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 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1043 bool full = qdict_get_try_bool(qdict, "full", false);
1044 enum NewImageMode mode;
1045 Error *err = NULL;
1047 if (!filename) {
1048 error_setg(&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 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1073 bool full = qdict_get_try_bool(qdict, "full", false);
1074 enum NewImageMode mode;
1075 Error *err = NULL;
1077 if (!filename) {
1078 error_setg(&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 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
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_setg(&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_setg(&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_setg(&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 bool force = qdict_get_try_bool(qdict, "force", false);
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", false);
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 bool detach = qdict_get_try_bool(qdict, "detach", false);
1478 bool blk = qdict_get_try_bool(qdict, "blk", false);
1479 bool inc = qdict_get_try_bool(qdict, "inc", false);
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 Error *err = NULL;
1512 qmp_device_add((QDict *)qdict, NULL, &err);
1513 hmp_handle_error(mon, &err);
1516 void hmp_device_del(Monitor *mon, const QDict *qdict)
1518 const char *id = qdict_get_str(qdict, "id");
1519 Error *err = NULL;
1521 qmp_device_del(id, &err);
1522 hmp_handle_error(mon, &err);
1525 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1527 Error *err = NULL;
1528 bool paging = qdict_get_try_bool(qdict, "paging", false);
1529 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
1530 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
1531 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
1532 const char *file = qdict_get_str(qdict, "filename");
1533 bool has_begin = qdict_haskey(qdict, "begin");
1534 bool has_length = qdict_haskey(qdict, "length");
1535 int64_t begin = 0;
1536 int64_t length = 0;
1537 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1538 char *prot;
1540 if (zlib + lzo + snappy > 1) {
1541 error_setg(&err, "only one of '-z|-l|-s' can be set");
1542 hmp_handle_error(mon, &err);
1543 return;
1546 if (zlib) {
1547 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1550 if (lzo) {
1551 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1554 if (snappy) {
1555 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1558 if (has_begin) {
1559 begin = qdict_get_int(qdict, "begin");
1561 if (has_length) {
1562 length = qdict_get_int(qdict, "length");
1565 prot = g_strconcat("file:", file, NULL);
1567 qmp_dump_guest_memory(paging, prot, has_begin, begin, has_length, length,
1568 true, dump_format, &err);
1569 hmp_handle_error(mon, &err);
1570 g_free(prot);
1573 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1575 Error *err = NULL;
1576 QemuOpts *opts;
1578 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1579 if (err) {
1580 goto out;
1583 netdev_add(opts, &err);
1584 if (err) {
1585 qemu_opts_del(opts);
1588 out:
1589 hmp_handle_error(mon, &err);
1592 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1594 const char *id = qdict_get_str(qdict, "id");
1595 Error *err = NULL;
1597 qmp_netdev_del(id, &err);
1598 hmp_handle_error(mon, &err);
1601 void hmp_object_add(Monitor *mon, const QDict *qdict)
1603 Error *err = NULL;
1604 Error *err_end = NULL;
1605 QemuOpts *opts;
1606 char *type = NULL;
1607 char *id = NULL;
1608 void *dummy = NULL;
1609 OptsVisitor *ov;
1610 QDict *pdict;
1612 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1613 if (err) {
1614 goto out;
1617 ov = opts_visitor_new(opts);
1618 pdict = qdict_clone_shallow(qdict);
1620 visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err);
1621 if (err) {
1622 goto out_clean;
1625 qdict_del(pdict, "qom-type");
1626 visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
1627 if (err) {
1628 goto out_end;
1631 qdict_del(pdict, "id");
1632 visit_type_str(opts_get_visitor(ov), &id, "id", &err);
1633 if (err) {
1634 goto out_end;
1637 object_add(type, id, pdict, opts_get_visitor(ov), &err);
1639 out_end:
1640 visit_end_struct(opts_get_visitor(ov), &err_end);
1641 if (!err && err_end) {
1642 qmp_object_del(id, NULL);
1644 error_propagate(&err, err_end);
1645 out_clean:
1646 opts_visitor_cleanup(ov);
1648 QDECREF(pdict);
1649 qemu_opts_del(opts);
1650 g_free(id);
1651 g_free(type);
1652 g_free(dummy);
1654 out:
1655 hmp_handle_error(mon, &err);
1658 void hmp_getfd(Monitor *mon, const QDict *qdict)
1660 const char *fdname = qdict_get_str(qdict, "fdname");
1661 Error *err = NULL;
1663 qmp_getfd(fdname, &err);
1664 hmp_handle_error(mon, &err);
1667 void hmp_closefd(Monitor *mon, const QDict *qdict)
1669 const char *fdname = qdict_get_str(qdict, "fdname");
1670 Error *err = NULL;
1672 qmp_closefd(fdname, &err);
1673 hmp_handle_error(mon, &err);
1676 void hmp_sendkey(Monitor *mon, const QDict *qdict)
1678 const char *keys = qdict_get_str(qdict, "keys");
1679 KeyValueList *keylist, *head = NULL, *tmp = NULL;
1680 int has_hold_time = qdict_haskey(qdict, "hold-time");
1681 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1682 Error *err = NULL;
1683 char keyname_buf[16];
1684 char *separator;
1685 int keyname_len;
1687 while (1) {
1688 separator = strchr(keys, '-');
1689 keyname_len = separator ? separator - keys : strlen(keys);
1690 pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
1692 /* Be compatible with old interface, convert user inputted "<" */
1693 if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) {
1694 pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
1695 keyname_len = 4;
1697 keyname_buf[keyname_len] = 0;
1699 keylist = g_malloc0(sizeof(*keylist));
1700 keylist->value = g_malloc0(sizeof(*keylist->value));
1702 if (!head) {
1703 head = keylist;
1705 if (tmp) {
1706 tmp->next = keylist;
1708 tmp = keylist;
1710 if (strstart(keyname_buf, "0x", NULL)) {
1711 char *endp;
1712 int value = strtoul(keyname_buf, &endp, 0);
1713 if (*endp != '\0') {
1714 goto err_out;
1716 keylist->value->kind = KEY_VALUE_KIND_NUMBER;
1717 keylist->value->number = value;
1718 } else {
1719 int idx = index_from_key(keyname_buf);
1720 if (idx == Q_KEY_CODE_MAX) {
1721 goto err_out;
1723 keylist->value->kind = KEY_VALUE_KIND_QCODE;
1724 keylist->value->qcode = idx;
1727 if (!separator) {
1728 break;
1730 keys = separator + 1;
1733 qmp_send_key(head, has_hold_time, hold_time, &err);
1734 hmp_handle_error(mon, &err);
1736 out:
1737 qapi_free_KeyValueList(head);
1738 return;
1740 err_out:
1741 monitor_printf(mon, "invalid parameter: %s\n", keyname_buf);
1742 goto out;
1745 void hmp_screendump(Monitor *mon, const QDict *qdict)
1747 const char *filename = qdict_get_str(qdict, "filename");
1748 Error *err = NULL;
1750 qmp_screendump(filename, &err);
1751 hmp_handle_error(mon, &err);
1754 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1756 const char *uri = qdict_get_str(qdict, "uri");
1757 bool writable = qdict_get_try_bool(qdict, "writable", false);
1758 bool all = qdict_get_try_bool(qdict, "all", false);
1759 Error *local_err = NULL;
1760 BlockInfoList *block_list, *info;
1761 SocketAddress *addr;
1763 if (writable && !all) {
1764 error_setg(&local_err, "-w only valid together with -a");
1765 goto exit;
1768 /* First check if the address is valid and start the server. */
1769 addr = socket_parse(uri, &local_err);
1770 if (local_err != NULL) {
1771 goto exit;
1774 qmp_nbd_server_start(addr, &local_err);
1775 qapi_free_SocketAddress(addr);
1776 if (local_err != NULL) {
1777 goto exit;
1780 if (!all) {
1781 return;
1784 /* Then try adding all block devices. If one fails, close all and
1785 * exit.
1787 block_list = qmp_query_block(NULL);
1789 for (info = block_list; info; info = info->next) {
1790 if (!info->value->has_inserted) {
1791 continue;
1794 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1796 if (local_err != NULL) {
1797 qmp_nbd_server_stop(NULL);
1798 break;
1802 qapi_free_BlockInfoList(block_list);
1804 exit:
1805 hmp_handle_error(mon, &local_err);
1808 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1810 const char *device = qdict_get_str(qdict, "device");
1811 bool writable = qdict_get_try_bool(qdict, "writable", false);
1812 Error *local_err = NULL;
1814 qmp_nbd_server_add(device, true, writable, &local_err);
1816 if (local_err != NULL) {
1817 hmp_handle_error(mon, &local_err);
1821 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1823 Error *err = NULL;
1825 qmp_nbd_server_stop(&err);
1826 hmp_handle_error(mon, &err);
1829 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
1831 int cpuid;
1832 Error *err = NULL;
1834 cpuid = qdict_get_int(qdict, "id");
1835 qmp_cpu_add(cpuid, &err);
1836 hmp_handle_error(mon, &err);
1839 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1841 const char *args = qdict_get_str(qdict, "args");
1842 Error *err = NULL;
1843 QemuOpts *opts;
1845 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
1846 if (opts == NULL) {
1847 error_setg(&err, "Parsing chardev args failed");
1848 } else {
1849 qemu_chr_new_from_opts(opts, NULL, &err);
1851 hmp_handle_error(mon, &err);
1854 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1856 Error *local_err = NULL;
1858 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1859 hmp_handle_error(mon, &local_err);
1862 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1864 BlockBackend *blk;
1865 const char* device = qdict_get_str(qdict, "device");
1866 const char* command = qdict_get_str(qdict, "command");
1867 Error *err = NULL;
1869 blk = blk_by_name(device);
1870 if (blk) {
1871 qemuio_command(blk, command);
1872 } else {
1873 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
1874 "Device '%s' not found", device);
1877 hmp_handle_error(mon, &err);
1880 void hmp_object_del(Monitor *mon, const QDict *qdict)
1882 const char *id = qdict_get_str(qdict, "id");
1883 Error *err = NULL;
1885 qmp_object_del(id, &err);
1886 hmp_handle_error(mon, &err);
1889 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
1891 Error *err = NULL;
1892 MemdevList *memdev_list = qmp_query_memdev(&err);
1893 MemdevList *m = memdev_list;
1894 StringOutputVisitor *ov;
1895 char *str;
1896 int i = 0;
1899 while (m) {
1900 ov = string_output_visitor_new(false);
1901 visit_type_uint16List(string_output_get_visitor(ov),
1902 &m->value->host_nodes, NULL, NULL);
1903 monitor_printf(mon, "memory backend: %d\n", i);
1904 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
1905 monitor_printf(mon, " merge: %s\n",
1906 m->value->merge ? "true" : "false");
1907 monitor_printf(mon, " dump: %s\n",
1908 m->value->dump ? "true" : "false");
1909 monitor_printf(mon, " prealloc: %s\n",
1910 m->value->prealloc ? "true" : "false");
1911 monitor_printf(mon, " policy: %s\n",
1912 HostMemPolicy_lookup[m->value->policy]);
1913 str = string_output_get_string(ov);
1914 monitor_printf(mon, " host nodes: %s\n", str);
1916 g_free(str);
1917 string_output_visitor_cleanup(ov);
1918 m = m->next;
1919 i++;
1922 monitor_printf(mon, "\n");
1924 qapi_free_MemdevList(memdev_list);
1927 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
1929 Error *err = NULL;
1930 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
1931 MemoryDeviceInfoList *info;
1932 MemoryDeviceInfo *value;
1933 PCDIMMDeviceInfo *di;
1935 for (info = info_list; info; info = info->next) {
1936 value = info->value;
1938 if (value) {
1939 switch (value->kind) {
1940 case MEMORY_DEVICE_INFO_KIND_DIMM:
1941 di = value->dimm;
1943 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1944 MemoryDeviceInfoKind_lookup[value->kind],
1945 di->id ? di->id : "");
1946 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
1947 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
1948 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
1949 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
1950 monitor_printf(mon, " memdev: %s\n", di->memdev);
1951 monitor_printf(mon, " hotplugged: %s\n",
1952 di->hotplugged ? "true" : "false");
1953 monitor_printf(mon, " hotpluggable: %s\n",
1954 di->hotpluggable ? "true" : "false");
1955 break;
1956 default:
1957 break;
1962 qapi_free_MemoryDeviceInfoList(info_list);
1965 void hmp_qom_list(Monitor *mon, const QDict *qdict)
1967 const char *path = qdict_get_try_str(qdict, "path");
1968 ObjectPropertyInfoList *list;
1969 Error *err = NULL;
1971 if (path == NULL) {
1972 monitor_printf(mon, "/\n");
1973 return;
1976 list = qmp_qom_list(path, &err);
1977 if (err == NULL) {
1978 ObjectPropertyInfoList *start = list;
1979 while (list != NULL) {
1980 ObjectPropertyInfo *value = list->value;
1982 monitor_printf(mon, "%s (%s)\n",
1983 value->name, value->type);
1984 list = list->next;
1986 qapi_free_ObjectPropertyInfoList(start);
1988 hmp_handle_error(mon, &err);
1991 void hmp_qom_set(Monitor *mon, const QDict *qdict)
1993 const char *path = qdict_get_str(qdict, "path");
1994 const char *property = qdict_get_str(qdict, "property");
1995 const char *value = qdict_get_str(qdict, "value");
1996 Error *err = NULL;
1997 bool ambiguous = false;
1998 Object *obj;
2000 obj = object_resolve_path(path, &ambiguous);
2001 if (obj == NULL) {
2002 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2003 "Device '%s' not found", path);
2004 } else {
2005 if (ambiguous) {
2006 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2008 object_property_parse(obj, value, property, &err);
2010 hmp_handle_error(mon, &err);
2013 void hmp_rocker(Monitor *mon, const QDict *qdict)
2015 const char *name = qdict_get_str(qdict, "name");
2016 RockerSwitch *rocker;
2017 Error *errp = NULL;
2019 rocker = qmp_query_rocker(name, &errp);
2020 if (errp != NULL) {
2021 hmp_handle_error(mon, &errp);
2022 return;
2025 monitor_printf(mon, "name: %s\n", rocker->name);
2026 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2027 monitor_printf(mon, "ports: %d\n", rocker->ports);
2029 qapi_free_RockerSwitch(rocker);
2032 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2034 RockerPortList *list, *port;
2035 const char *name = qdict_get_str(qdict, "name");
2036 Error *errp = NULL;
2038 list = qmp_query_rocker_ports(name, &errp);
2039 if (errp != NULL) {
2040 hmp_handle_error(mon, &errp);
2041 return;
2044 monitor_printf(mon, " ena/ speed/ auto\n");
2045 monitor_printf(mon, " port link duplex neg?\n");
2047 for (port = list; port; port = port->next) {
2048 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2049 port->value->name,
2050 port->value->enabled ? port->value->link_up ?
2051 "up" : "down" : "!ena",
2052 port->value->speed == 10000 ? "10G" : "??",
2053 port->value->duplex ? "FD" : "HD",
2054 port->value->autoneg ? "Yes" : "No");
2057 qapi_free_RockerPortList(list);
2060 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2062 RockerOfDpaFlowList *list, *info;
2063 const char *name = qdict_get_str(qdict, "name");
2064 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2065 Error *errp = NULL;
2067 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &errp);
2068 if (errp != NULL) {
2069 hmp_handle_error(mon, &errp);
2070 return;
2073 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2075 for (info = list; info; info = info->next) {
2076 RockerOfDpaFlow *flow = info->value;
2077 RockerOfDpaFlowKey *key = flow->key;
2078 RockerOfDpaFlowMask *mask = flow->mask;
2079 RockerOfDpaFlowAction *action = flow->action;
2081 if (flow->hits) {
2082 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2083 key->priority, key->tbl_id, flow->hits);
2084 } else {
2085 monitor_printf(mon, "%-4d %-3d ",
2086 key->priority, key->tbl_id);
2089 if (key->has_in_pport) {
2090 monitor_printf(mon, " pport %d", key->in_pport);
2091 if (mask->has_in_pport) {
2092 monitor_printf(mon, "(0x%x)", mask->in_pport);
2096 if (key->has_vlan_id) {
2097 monitor_printf(mon, " vlan %d",
2098 key->vlan_id & VLAN_VID_MASK);
2099 if (mask->has_vlan_id) {
2100 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2104 if (key->has_tunnel_id) {
2105 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2106 if (mask->has_tunnel_id) {
2107 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2111 if (key->has_eth_type) {
2112 switch (key->eth_type) {
2113 case 0x0806:
2114 monitor_printf(mon, " ARP");
2115 break;
2116 case 0x0800:
2117 monitor_printf(mon, " IP");
2118 break;
2119 case 0x86dd:
2120 monitor_printf(mon, " IPv6");
2121 break;
2122 case 0x8809:
2123 monitor_printf(mon, " LACP");
2124 break;
2125 case 0x88cc:
2126 monitor_printf(mon, " LLDP");
2127 break;
2128 default:
2129 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2130 break;
2134 if (key->has_eth_src) {
2135 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2136 (mask->has_eth_src) &&
2137 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2138 monitor_printf(mon, " src <any mcast/bcast>");
2139 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2140 (mask->has_eth_src) &&
2141 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2142 monitor_printf(mon, " src <any ucast>");
2143 } else {
2144 monitor_printf(mon, " src %s", key->eth_src);
2145 if (mask->has_eth_src) {
2146 monitor_printf(mon, "(%s)", mask->eth_src);
2151 if (key->has_eth_dst) {
2152 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2153 (mask->has_eth_dst) &&
2154 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2155 monitor_printf(mon, " dst <any mcast/bcast>");
2156 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2157 (mask->has_eth_dst) &&
2158 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2159 monitor_printf(mon, " dst <any ucast>");
2160 } else {
2161 monitor_printf(mon, " dst %s", key->eth_dst);
2162 if (mask->has_eth_dst) {
2163 monitor_printf(mon, "(%s)", mask->eth_dst);
2168 if (key->has_ip_proto) {
2169 monitor_printf(mon, " proto %d", key->ip_proto);
2170 if (mask->has_ip_proto) {
2171 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2175 if (key->has_ip_tos) {
2176 monitor_printf(mon, " TOS %d", key->ip_tos);
2177 if (mask->has_ip_tos) {
2178 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2182 if (key->has_ip_dst) {
2183 monitor_printf(mon, " dst %s", key->ip_dst);
2186 if (action->has_goto_tbl || action->has_group_id ||
2187 action->has_new_vlan_id) {
2188 monitor_printf(mon, " -->");
2191 if (action->has_new_vlan_id) {
2192 monitor_printf(mon, " apply new vlan %d",
2193 ntohs(action->new_vlan_id));
2196 if (action->has_group_id) {
2197 monitor_printf(mon, " write group 0x%08x", action->group_id);
2200 if (action->has_goto_tbl) {
2201 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2204 monitor_printf(mon, "\n");
2207 qapi_free_RockerOfDpaFlowList(list);
2210 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2212 RockerOfDpaGroupList *list, *g;
2213 const char *name = qdict_get_str(qdict, "name");
2214 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2215 Error *errp = NULL;
2216 bool set = false;
2218 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &errp);
2219 if (errp != NULL) {
2220 hmp_handle_error(mon, &errp);
2221 return;
2224 monitor_printf(mon, "id (decode) --> buckets\n");
2226 for (g = list; g; g = g->next) {
2227 RockerOfDpaGroup *group = g->value;
2229 monitor_printf(mon, "0x%08x", group->id);
2231 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2232 group->type == 1 ? "L2 rewrite" :
2233 group->type == 2 ? "L3 unicast" :
2234 group->type == 3 ? "L2 multicast" :
2235 group->type == 4 ? "L2 flood" :
2236 group->type == 5 ? "L3 interface" :
2237 group->type == 6 ? "L3 multicast" :
2238 group->type == 7 ? "L3 ECMP" :
2239 group->type == 8 ? "L2 overlay" :
2240 "unknown");
2242 if (group->has_vlan_id) {
2243 monitor_printf(mon, " vlan %d", group->vlan_id);
2246 if (group->has_pport) {
2247 monitor_printf(mon, " pport %d", group->pport);
2250 if (group->has_index) {
2251 monitor_printf(mon, " index %d", group->index);
2254 monitor_printf(mon, ") -->");
2256 if (group->has_set_vlan_id && group->set_vlan_id) {
2257 set = true;
2258 monitor_printf(mon, " set vlan %d",
2259 group->set_vlan_id & VLAN_VID_MASK);
2262 if (group->has_set_eth_src) {
2263 if (!set) {
2264 set = true;
2265 monitor_printf(mon, " set");
2267 monitor_printf(mon, " src %s", group->set_eth_src);
2270 if (group->has_set_eth_dst) {
2271 if (!set) {
2272 set = true;
2273 monitor_printf(mon, " set");
2275 monitor_printf(mon, " dst %s", group->set_eth_dst);
2278 set = false;
2280 if (group->has_ttl_check && group->ttl_check) {
2281 monitor_printf(mon, " check TTL");
2284 if (group->has_group_id && group->group_id) {
2285 monitor_printf(mon, " group id 0x%08x", group->group_id);
2288 if (group->has_pop_vlan && group->pop_vlan) {
2289 monitor_printf(mon, " pop vlan");
2292 if (group->has_out_pport) {
2293 monitor_printf(mon, " out pport %d", group->out_pport);
2296 if (group->has_group_ids) {
2297 struct uint32List *id;
2299 monitor_printf(mon, " groups [");
2300 for (id = group->group_ids; id; id = id->next) {
2301 monitor_printf(mon, "0x%08x", id->value);
2302 if (id->next) {
2303 monitor_printf(mon, ",");
2306 monitor_printf(mon, "]");
2309 monitor_printf(mon, "\n");
2312 qapi_free_RockerOfDpaGroupList(list);