vmw_pvscsi: Introduce 'x-old-pci-configuration' backword compatability property
[qemu/ar7.git] / hmp.c
blobc2b2c161c8c16c3c3a35987f806e85abcb6ce6ec
1 /*
2 * Human Monitor Interface
4 * Copyright IBM, Corp. 2011
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
16 #include "hmp.h"
17 #include "net/net.h"
18 #include "net/eth.h"
19 #include "sysemu/char.h"
20 #include "sysemu/block-backend.h"
21 #include "qemu/option.h"
22 #include "qemu/timer.h"
23 #include "qmp-commands.h"
24 #include "qemu/sockets.h"
25 #include "monitor/monitor.h"
26 #include "monitor/qdev.h"
27 #include "qapi/opts-visitor.h"
28 #include "qapi/qmp/qerror.h"
29 #include "qapi/string-output-visitor.h"
30 #include "qapi/util.h"
31 #include "qapi-visit.h"
32 #include "ui/console.h"
33 #include "block/qapi.h"
34 #include "qemu-io.h"
36 #ifdef CONFIG_SPICE
37 #include <spice/enums.h>
38 #endif
40 static void hmp_handle_error(Monitor *mon, Error **errp)
42 assert(errp);
43 if (*errp) {
44 monitor_printf(mon, "%s\n", error_get_pretty(*errp));
45 error_free(*errp);
49 void hmp_info_name(Monitor *mon, const QDict *qdict)
51 NameInfo *info;
53 info = qmp_query_name(NULL);
54 if (info->has_name) {
55 monitor_printf(mon, "%s\n", info->name);
57 qapi_free_NameInfo(info);
60 void hmp_info_version(Monitor *mon, const QDict *qdict)
62 VersionInfo *info;
64 info = qmp_query_version(NULL);
66 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
67 info->qemu->major, info->qemu->minor, info->qemu->micro,
68 info->package);
70 qapi_free_VersionInfo(info);
73 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
75 KvmInfo *info;
77 info = qmp_query_kvm(NULL);
78 monitor_printf(mon, "kvm support: ");
79 if (info->present) {
80 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
81 } else {
82 monitor_printf(mon, "not compiled\n");
85 qapi_free_KvmInfo(info);
88 void hmp_info_status(Monitor *mon, const QDict *qdict)
90 StatusInfo *info;
92 info = qmp_query_status(NULL);
94 monitor_printf(mon, "VM status: %s%s",
95 info->running ? "running" : "paused",
96 info->singlestep ? " (single step mode)" : "");
98 if (!info->running && info->status != RUN_STATE_PAUSED) {
99 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
102 monitor_printf(mon, "\n");
104 qapi_free_StatusInfo(info);
107 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
109 UuidInfo *info;
111 info = qmp_query_uuid(NULL);
112 monitor_printf(mon, "%s\n", info->UUID);
113 qapi_free_UuidInfo(info);
116 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
118 ChardevInfoList *char_info, *info;
120 char_info = qmp_query_chardev(NULL);
121 for (info = char_info; info; info = info->next) {
122 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
123 info->value->filename);
126 qapi_free_ChardevInfoList(char_info);
129 void hmp_info_mice(Monitor *mon, const QDict *qdict)
131 MouseInfoList *mice_list, *mouse;
133 mice_list = qmp_query_mice(NULL);
134 if (!mice_list) {
135 monitor_printf(mon, "No mouse devices connected\n");
136 return;
139 for (mouse = mice_list; mouse; mouse = mouse->next) {
140 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
141 mouse->value->current ? '*' : ' ',
142 mouse->value->index, mouse->value->name,
143 mouse->value->absolute ? " (absolute)" : "");
146 qapi_free_MouseInfoList(mice_list);
149 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
151 MigrationInfo *info;
152 MigrationCapabilityStatusList *caps, *cap;
154 info = qmp_query_migrate(NULL);
155 caps = qmp_query_migrate_capabilities(NULL);
157 /* do not display parameters during setup */
158 if (info->has_status && caps) {
159 monitor_printf(mon, "capabilities: ");
160 for (cap = caps; cap; cap = cap->next) {
161 monitor_printf(mon, "%s: %s ",
162 MigrationCapability_lookup[cap->value->capability],
163 cap->value->state ? "on" : "off");
165 monitor_printf(mon, "\n");
168 if (info->has_status) {
169 monitor_printf(mon, "Migration status: %s\n",
170 MigrationStatus_lookup[info->status]);
171 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
172 info->total_time);
173 if (info->has_expected_downtime) {
174 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
175 info->expected_downtime);
177 if (info->has_downtime) {
178 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
179 info->downtime);
181 if (info->has_setup_time) {
182 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
183 info->setup_time);
187 if (info->has_ram) {
188 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
189 info->ram->transferred >> 10);
190 monitor_printf(mon, "throughput: %0.2f mbps\n",
191 info->ram->mbps);
192 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
193 info->ram->remaining >> 10);
194 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
195 info->ram->total >> 10);
196 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
197 info->ram->duplicate);
198 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
199 info->ram->skipped);
200 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
201 info->ram->normal);
202 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
203 info->ram->normal_bytes >> 10);
204 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
205 info->ram->dirty_sync_count);
206 if (info->ram->dirty_pages_rate) {
207 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
208 info->ram->dirty_pages_rate);
212 if (info->has_disk) {
213 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
214 info->disk->transferred >> 10);
215 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
216 info->disk->remaining >> 10);
217 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
218 info->disk->total >> 10);
221 if (info->has_xbzrle_cache) {
222 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
223 info->xbzrle_cache->cache_size);
224 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
225 info->xbzrle_cache->bytes >> 10);
226 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
227 info->xbzrle_cache->pages);
228 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
229 info->xbzrle_cache->cache_miss);
230 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
231 info->xbzrle_cache->cache_miss_rate);
232 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
233 info->xbzrle_cache->overflow);
236 if (info->has_x_cpu_throttle_percentage) {
237 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
238 info->x_cpu_throttle_percentage);
241 qapi_free_MigrationInfo(info);
242 qapi_free_MigrationCapabilityStatusList(caps);
245 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
247 MigrationCapabilityStatusList *caps, *cap;
249 caps = qmp_query_migrate_capabilities(NULL);
251 if (caps) {
252 monitor_printf(mon, "capabilities: ");
253 for (cap = caps; cap; cap = cap->next) {
254 monitor_printf(mon, "%s: %s ",
255 MigrationCapability_lookup[cap->value->capability],
256 cap->value->state ? "on" : "off");
258 monitor_printf(mon, "\n");
261 qapi_free_MigrationCapabilityStatusList(caps);
264 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
266 MigrationParameters *params;
268 params = qmp_query_migrate_parameters(NULL);
270 if (params) {
271 monitor_printf(mon, "parameters:");
272 monitor_printf(mon, " %s: %" PRId64,
273 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_LEVEL],
274 params->compress_level);
275 monitor_printf(mon, " %s: %" PRId64,
276 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_THREADS],
277 params->compress_threads);
278 monitor_printf(mon, " %s: %" PRId64,
279 MigrationParameter_lookup[MIGRATION_PARAMETER_DECOMPRESS_THREADS],
280 params->decompress_threads);
281 monitor_printf(mon, " %s: %" PRId64,
282 MigrationParameter_lookup[MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL],
283 params->x_cpu_throttle_initial);
284 monitor_printf(mon, " %s: %" PRId64,
285 MigrationParameter_lookup[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT],
286 params->x_cpu_throttle_increment);
287 monitor_printf(mon, "\n");
290 qapi_free_MigrationParameters(params);
293 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
295 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
296 qmp_query_migrate_cache_size(NULL) >> 10);
299 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
301 CpuInfoList *cpu_list, *cpu;
303 cpu_list = qmp_query_cpus(NULL);
305 for (cpu = cpu_list; cpu; cpu = cpu->next) {
306 int active = ' ';
308 if (cpu->value->CPU == monitor_get_cpu_index()) {
309 active = '*';
312 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
314 switch (cpu->value->arch) {
315 case CPU_INFO_ARCH_X86:
316 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->u.x86->pc);
317 break;
318 case CPU_INFO_ARCH_PPC:
319 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->u.ppc->nip);
320 break;
321 case CPU_INFO_ARCH_SPARC:
322 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->u.sparc->pc);
323 monitor_printf(mon, " npc=0x%016" PRIx64, cpu->value->u.sparc->npc);
324 break;
325 case CPU_INFO_ARCH_MIPS:
326 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.mips->PC);
327 break;
328 case CPU_INFO_ARCH_TRICORE:
329 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.tricore->PC);
330 break;
331 default:
332 break;
335 if (cpu->value->halted) {
336 monitor_printf(mon, " (halted)");
339 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
342 qapi_free_CpuInfoList(cpu_list);
345 static void print_block_info(Monitor *mon, BlockInfo *info,
346 BlockDeviceInfo *inserted, bool verbose)
348 ImageInfo *image_info;
350 assert(!info || !info->has_inserted || info->inserted == inserted);
352 if (info) {
353 monitor_printf(mon, "%s", info->device);
354 if (inserted && inserted->has_node_name) {
355 monitor_printf(mon, " (%s)", inserted->node_name);
357 } else {
358 assert(inserted);
359 monitor_printf(mon, "%s",
360 inserted->has_node_name
361 ? inserted->node_name
362 : "<anonymous>");
365 if (inserted) {
366 monitor_printf(mon, ": %s (%s%s%s)\n",
367 inserted->file,
368 inserted->drv,
369 inserted->ro ? ", read-only" : "",
370 inserted->encrypted ? ", encrypted" : "");
371 } else {
372 monitor_printf(mon, ": [not inserted]\n");
375 if (info) {
376 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
377 monitor_printf(mon, " I/O status: %s\n",
378 BlockDeviceIoStatus_lookup[info->io_status]);
381 if (info->removable) {
382 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
383 info->locked ? "" : "not ",
384 info->tray_open ? "open" : "closed");
389 if (!inserted) {
390 return;
393 monitor_printf(mon, " Cache mode: %s%s%s\n",
394 inserted->cache->writeback ? "writeback" : "writethrough",
395 inserted->cache->direct ? ", direct" : "",
396 inserted->cache->no_flush ? ", ignore flushes" : "");
398 if (inserted->has_backing_file) {
399 monitor_printf(mon,
400 " Backing file: %s "
401 "(chain depth: %" PRId64 ")\n",
402 inserted->backing_file,
403 inserted->backing_file_depth);
406 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
407 monitor_printf(mon, " Detect zeroes: %s\n",
408 BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]);
411 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
412 inserted->iops || inserted->iops_rd || inserted->iops_wr)
414 monitor_printf(mon, " I/O throttling: bps=%" PRId64
415 " bps_rd=%" PRId64 " bps_wr=%" PRId64
416 " bps_max=%" PRId64
417 " bps_rd_max=%" PRId64
418 " bps_wr_max=%" PRId64
419 " iops=%" PRId64 " iops_rd=%" PRId64
420 " iops_wr=%" PRId64
421 " iops_max=%" PRId64
422 " iops_rd_max=%" PRId64
423 " iops_wr_max=%" PRId64
424 " iops_size=%" PRId64
425 " group=%s\n",
426 inserted->bps,
427 inserted->bps_rd,
428 inserted->bps_wr,
429 inserted->bps_max,
430 inserted->bps_rd_max,
431 inserted->bps_wr_max,
432 inserted->iops,
433 inserted->iops_rd,
434 inserted->iops_wr,
435 inserted->iops_max,
436 inserted->iops_rd_max,
437 inserted->iops_wr_max,
438 inserted->iops_size,
439 inserted->group);
442 if (verbose) {
443 monitor_printf(mon, "\nImages:\n");
444 image_info = inserted->image;
445 while (1) {
446 bdrv_image_info_dump((fprintf_function)monitor_printf,
447 mon, image_info);
448 if (image_info->has_backing_image) {
449 image_info = image_info->backing_image;
450 } else {
451 break;
457 void hmp_info_block(Monitor *mon, const QDict *qdict)
459 BlockInfoList *block_list, *info;
460 BlockDeviceInfoList *blockdev_list, *blockdev;
461 const char *device = qdict_get_try_str(qdict, "device");
462 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
463 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
464 bool printed = false;
466 /* Print BlockBackend information */
467 if (!nodes) {
468 block_list = qmp_query_block(NULL);
469 } else {
470 block_list = NULL;
473 for (info = block_list; info; info = info->next) {
474 if (device && strcmp(device, info->value->device)) {
475 continue;
478 if (info != block_list) {
479 monitor_printf(mon, "\n");
482 print_block_info(mon, info->value, info->value->has_inserted
483 ? info->value->inserted : NULL,
484 verbose);
485 printed = true;
488 qapi_free_BlockInfoList(block_list);
490 if ((!device && !nodes) || printed) {
491 return;
494 /* Print node information */
495 blockdev_list = qmp_query_named_block_nodes(NULL);
496 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
497 assert(blockdev->value->has_node_name);
498 if (device && strcmp(device, blockdev->value->node_name)) {
499 continue;
502 if (blockdev != blockdev_list) {
503 monitor_printf(mon, "\n");
506 print_block_info(mon, NULL, blockdev->value, verbose);
508 qapi_free_BlockDeviceInfoList(blockdev_list);
511 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
513 BlockStatsList *stats_list, *stats;
515 stats_list = qmp_query_blockstats(false, false, NULL);
517 for (stats = stats_list; stats; stats = stats->next) {
518 if (!stats->value->has_device) {
519 continue;
522 monitor_printf(mon, "%s:", stats->value->device);
523 monitor_printf(mon, " rd_bytes=%" PRId64
524 " wr_bytes=%" PRId64
525 " rd_operations=%" PRId64
526 " wr_operations=%" PRId64
527 " flush_operations=%" PRId64
528 " wr_total_time_ns=%" PRId64
529 " rd_total_time_ns=%" PRId64
530 " flush_total_time_ns=%" PRId64
531 " rd_merged=%" PRId64
532 " wr_merged=%" PRId64
533 " idle_time_ns=%" PRId64
534 "\n",
535 stats->value->stats->rd_bytes,
536 stats->value->stats->wr_bytes,
537 stats->value->stats->rd_operations,
538 stats->value->stats->wr_operations,
539 stats->value->stats->flush_operations,
540 stats->value->stats->wr_total_time_ns,
541 stats->value->stats->rd_total_time_ns,
542 stats->value->stats->flush_total_time_ns,
543 stats->value->stats->rd_merged,
544 stats->value->stats->wr_merged,
545 stats->value->stats->idle_time_ns);
548 qapi_free_BlockStatsList(stats_list);
551 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
553 VncInfo *info;
554 Error *err = NULL;
555 VncClientInfoList *client;
557 info = qmp_query_vnc(&err);
558 if (err) {
559 monitor_printf(mon, "%s\n", error_get_pretty(err));
560 error_free(err);
561 return;
564 if (!info->enabled) {
565 monitor_printf(mon, "Server: disabled\n");
566 goto out;
569 monitor_printf(mon, "Server:\n");
570 if (info->has_host && info->has_service) {
571 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
573 if (info->has_auth) {
574 monitor_printf(mon, " auth: %s\n", info->auth);
577 if (!info->has_clients || info->clients == NULL) {
578 monitor_printf(mon, "Client: none\n");
579 } else {
580 for (client = info->clients; client; client = client->next) {
581 monitor_printf(mon, "Client:\n");
582 monitor_printf(mon, " address: %s:%s\n",
583 client->value->host,
584 client->value->service);
585 monitor_printf(mon, " x509_dname: %s\n",
586 client->value->x509_dname ?
587 client->value->x509_dname : "none");
588 monitor_printf(mon, " username: %s\n",
589 client->value->has_sasl_username ?
590 client->value->sasl_username : "none");
594 out:
595 qapi_free_VncInfo(info);
598 #ifdef CONFIG_SPICE
599 void hmp_info_spice(Monitor *mon, const QDict *qdict)
601 SpiceChannelList *chan;
602 SpiceInfo *info;
603 const char *channel_name;
604 const char * const channel_names[] = {
605 [SPICE_CHANNEL_MAIN] = "main",
606 [SPICE_CHANNEL_DISPLAY] = "display",
607 [SPICE_CHANNEL_INPUTS] = "inputs",
608 [SPICE_CHANNEL_CURSOR] = "cursor",
609 [SPICE_CHANNEL_PLAYBACK] = "playback",
610 [SPICE_CHANNEL_RECORD] = "record",
611 [SPICE_CHANNEL_TUNNEL] = "tunnel",
612 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
613 [SPICE_CHANNEL_USBREDIR] = "usbredir",
614 [SPICE_CHANNEL_PORT] = "port",
615 #if 0
616 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
617 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
618 * as quick fix for build failures with older versions. */
619 [SPICE_CHANNEL_WEBDAV] = "webdav",
620 #endif
623 info = qmp_query_spice(NULL);
625 if (!info->enabled) {
626 monitor_printf(mon, "Server: disabled\n");
627 goto out;
630 monitor_printf(mon, "Server:\n");
631 if (info->has_port) {
632 monitor_printf(mon, " address: %s:%" PRId64 "\n",
633 info->host, info->port);
635 if (info->has_tls_port) {
636 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
637 info->host, info->tls_port);
639 monitor_printf(mon, " migrated: %s\n",
640 info->migrated ? "true" : "false");
641 monitor_printf(mon, " auth: %s\n", info->auth);
642 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
643 monitor_printf(mon, " mouse-mode: %s\n",
644 SpiceQueryMouseMode_lookup[info->mouse_mode]);
646 if (!info->has_channels || info->channels == NULL) {
647 monitor_printf(mon, "Channels: none\n");
648 } else {
649 for (chan = info->channels; chan; chan = chan->next) {
650 monitor_printf(mon, "Channel:\n");
651 monitor_printf(mon, " address: %s:%s%s\n",
652 chan->value->host, chan->value->port,
653 chan->value->tls ? " [tls]" : "");
654 monitor_printf(mon, " session: %" PRId64 "\n",
655 chan->value->connection_id);
656 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
657 chan->value->channel_type, chan->value->channel_id);
659 channel_name = "unknown";
660 if (chan->value->channel_type > 0 &&
661 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
662 channel_names[chan->value->channel_type]) {
663 channel_name = channel_names[chan->value->channel_type];
666 monitor_printf(mon, " channel name: %s\n", channel_name);
670 out:
671 qapi_free_SpiceInfo(info);
673 #endif
675 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
677 BalloonInfo *info;
678 Error *err = NULL;
680 info = qmp_query_balloon(&err);
681 if (err) {
682 monitor_printf(mon, "%s\n", error_get_pretty(err));
683 error_free(err);
684 return;
687 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
689 qapi_free_BalloonInfo(info);
692 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
694 PciMemoryRegionList *region;
696 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
697 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
698 dev->slot, dev->function);
699 monitor_printf(mon, " ");
701 if (dev->class_info->has_desc) {
702 monitor_printf(mon, "%s", dev->class_info->desc);
703 } else {
704 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
707 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
708 dev->id->vendor, dev->id->device);
710 if (dev->has_irq) {
711 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
714 if (dev->has_pci_bridge) {
715 monitor_printf(mon, " BUS %" PRId64 ".\n",
716 dev->pci_bridge->bus->number);
717 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
718 dev->pci_bridge->bus->secondary);
719 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
720 dev->pci_bridge->bus->subordinate);
722 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
723 dev->pci_bridge->bus->io_range->base,
724 dev->pci_bridge->bus->io_range->limit);
726 monitor_printf(mon,
727 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
728 dev->pci_bridge->bus->memory_range->base,
729 dev->pci_bridge->bus->memory_range->limit);
731 monitor_printf(mon, " prefetchable memory range "
732 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
733 dev->pci_bridge->bus->prefetchable_range->base,
734 dev->pci_bridge->bus->prefetchable_range->limit);
737 for (region = dev->regions; region; region = region->next) {
738 uint64_t addr, size;
740 addr = region->value->address;
741 size = region->value->size;
743 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
745 if (!strcmp(region->value->type, "io")) {
746 monitor_printf(mon, "I/O at 0x%04" PRIx64
747 " [0x%04" PRIx64 "].\n",
748 addr, addr + size - 1);
749 } else {
750 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
751 " [0x%08" PRIx64 "].\n",
752 region->value->mem_type_64 ? 64 : 32,
753 region->value->prefetch ? " prefetchable" : "",
754 addr, addr + size - 1);
758 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
760 if (dev->has_pci_bridge) {
761 if (dev->pci_bridge->has_devices) {
762 PciDeviceInfoList *cdev;
763 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
764 hmp_info_pci_device(mon, cdev->value);
770 void hmp_info_pci(Monitor *mon, const QDict *qdict)
772 PciInfoList *info_list, *info;
773 Error *err = NULL;
775 info_list = qmp_query_pci(&err);
776 if (err) {
777 monitor_printf(mon, "PCI devices not supported\n");
778 error_free(err);
779 return;
782 for (info = info_list; info; info = info->next) {
783 PciDeviceInfoList *dev;
785 for (dev = info->value->devices; dev; dev = dev->next) {
786 hmp_info_pci_device(mon, dev->value);
790 qapi_free_PciInfoList(info_list);
793 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
795 BlockJobInfoList *list;
796 Error *err = NULL;
798 list = qmp_query_block_jobs(&err);
799 assert(!err);
801 if (!list) {
802 monitor_printf(mon, "No active jobs\n");
803 return;
806 while (list) {
807 if (strcmp(list->value->type, "stream") == 0) {
808 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
809 " of %" PRId64 " bytes, speed limit %" PRId64
810 " bytes/s\n",
811 list->value->device,
812 list->value->offset,
813 list->value->len,
814 list->value->speed);
815 } else {
816 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
817 " of %" PRId64 " bytes, speed limit %" PRId64
818 " bytes/s\n",
819 list->value->type,
820 list->value->device,
821 list->value->offset,
822 list->value->len,
823 list->value->speed);
825 list = list->next;
828 qapi_free_BlockJobInfoList(list);
831 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
833 TPMInfoList *info_list, *info;
834 Error *err = NULL;
835 unsigned int c = 0;
836 TPMPassthroughOptions *tpo;
838 info_list = qmp_query_tpm(&err);
839 if (err) {
840 monitor_printf(mon, "TPM device not supported\n");
841 error_free(err);
842 return;
845 if (info_list) {
846 monitor_printf(mon, "TPM device:\n");
849 for (info = info_list; info; info = info->next) {
850 TPMInfo *ti = info->value;
851 monitor_printf(mon, " tpm%d: model=%s\n",
852 c, TpmModel_lookup[ti->model]);
854 monitor_printf(mon, " \\ %s: type=%s",
855 ti->id, TpmTypeOptionsKind_lookup[ti->options->type]);
857 switch (ti->options->type) {
858 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
859 tpo = ti->options->u.passthrough;
860 monitor_printf(mon, "%s%s%s%s",
861 tpo->has_path ? ",path=" : "",
862 tpo->has_path ? tpo->path : "",
863 tpo->has_cancel_path ? ",cancel-path=" : "",
864 tpo->has_cancel_path ? tpo->cancel_path : "");
865 break;
866 case TPM_TYPE_OPTIONS_KIND__MAX:
867 break;
869 monitor_printf(mon, "\n");
870 c++;
872 qapi_free_TPMInfoList(info_list);
875 void hmp_quit(Monitor *mon, const QDict *qdict)
877 monitor_suspend(mon);
878 qmp_quit(NULL);
881 void hmp_stop(Monitor *mon, const QDict *qdict)
883 qmp_stop(NULL);
886 void hmp_system_reset(Monitor *mon, const QDict *qdict)
888 qmp_system_reset(NULL);
891 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
893 qmp_system_powerdown(NULL);
896 void hmp_cpu(Monitor *mon, const QDict *qdict)
898 int64_t cpu_index;
900 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
901 use it are converted to the QAPI */
902 cpu_index = qdict_get_int(qdict, "index");
903 if (monitor_set_cpu(cpu_index) < 0) {
904 monitor_printf(mon, "invalid CPU index\n");
908 void hmp_memsave(Monitor *mon, const QDict *qdict)
910 uint32_t size = qdict_get_int(qdict, "size");
911 const char *filename = qdict_get_str(qdict, "filename");
912 uint64_t addr = qdict_get_int(qdict, "val");
913 Error *err = NULL;
915 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &err);
916 hmp_handle_error(mon, &err);
919 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
921 uint32_t size = qdict_get_int(qdict, "size");
922 const char *filename = qdict_get_str(qdict, "filename");
923 uint64_t addr = qdict_get_int(qdict, "val");
924 Error *err = NULL;
926 qmp_pmemsave(addr, size, filename, &err);
927 hmp_handle_error(mon, &err);
930 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
932 const char *chardev = qdict_get_str(qdict, "device");
933 const char *data = qdict_get_str(qdict, "data");
934 Error *err = NULL;
936 qmp_ringbuf_write(chardev, data, false, 0, &err);
938 hmp_handle_error(mon, &err);
941 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
943 uint32_t size = qdict_get_int(qdict, "size");
944 const char *chardev = qdict_get_str(qdict, "device");
945 char *data;
946 Error *err = NULL;
947 int i;
949 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
950 if (err) {
951 monitor_printf(mon, "%s\n", error_get_pretty(err));
952 error_free(err);
953 return;
956 for (i = 0; data[i]; i++) {
957 unsigned char ch = data[i];
959 if (ch == '\\') {
960 monitor_printf(mon, "\\\\");
961 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
962 monitor_printf(mon, "\\u%04X", ch);
963 } else {
964 monitor_printf(mon, "%c", ch);
968 monitor_printf(mon, "\n");
969 g_free(data);
972 static void hmp_cont_cb(void *opaque, int err)
974 if (!err) {
975 qmp_cont(NULL);
979 static bool key_is_missing(const BlockInfo *bdev)
981 return (bdev->inserted && bdev->inserted->encryption_key_missing);
984 void hmp_cont(Monitor *mon, const QDict *qdict)
986 BlockInfoList *bdev_list, *bdev;
987 Error *err = NULL;
989 bdev_list = qmp_query_block(NULL);
990 for (bdev = bdev_list; bdev; bdev = bdev->next) {
991 if (key_is_missing(bdev->value)) {
992 monitor_read_block_device_key(mon, bdev->value->device,
993 hmp_cont_cb, NULL);
994 goto out;
998 qmp_cont(&err);
999 hmp_handle_error(mon, &err);
1001 out:
1002 qapi_free_BlockInfoList(bdev_list);
1005 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1007 qmp_system_wakeup(NULL);
1010 void hmp_nmi(Monitor *mon, const QDict *qdict)
1012 Error *err = NULL;
1014 qmp_inject_nmi(&err);
1015 hmp_handle_error(mon, &err);
1018 void hmp_set_link(Monitor *mon, const QDict *qdict)
1020 const char *name = qdict_get_str(qdict, "name");
1021 bool up = qdict_get_bool(qdict, "up");
1022 Error *err = NULL;
1024 qmp_set_link(name, up, &err);
1025 hmp_handle_error(mon, &err);
1028 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1030 const char *device = qdict_get_str(qdict, "device");
1031 const char *password = qdict_get_str(qdict, "password");
1032 Error *err = NULL;
1034 qmp_block_passwd(true, device, false, NULL, password, &err);
1035 hmp_handle_error(mon, &err);
1038 void hmp_balloon(Monitor *mon, const QDict *qdict)
1040 int64_t value = qdict_get_int(qdict, "value");
1041 Error *err = NULL;
1043 qmp_balloon(value, &err);
1044 if (err) {
1045 monitor_printf(mon, "balloon: %s\n", error_get_pretty(err));
1046 error_free(err);
1050 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1052 const char *device = qdict_get_str(qdict, "device");
1053 int64_t size = qdict_get_int(qdict, "size");
1054 Error *err = NULL;
1056 qmp_block_resize(true, device, false, NULL, size, &err);
1057 hmp_handle_error(mon, &err);
1060 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1062 const char *device = qdict_get_str(qdict, "device");
1063 const char *filename = qdict_get_str(qdict, "target");
1064 const char *format = qdict_get_try_str(qdict, "format");
1065 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1066 bool full = qdict_get_try_bool(qdict, "full", false);
1067 enum NewImageMode mode;
1068 Error *err = NULL;
1070 if (!filename) {
1071 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1072 hmp_handle_error(mon, &err);
1073 return;
1076 if (reuse) {
1077 mode = NEW_IMAGE_MODE_EXISTING;
1078 } else {
1079 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1082 qmp_drive_mirror(device, filename, !!format, format,
1083 false, NULL, false, NULL,
1084 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1085 true, mode, false, 0, false, 0, false, 0,
1086 false, 0, false, 0, false, true, &err);
1087 hmp_handle_error(mon, &err);
1090 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1092 const char *device = qdict_get_str(qdict, "device");
1093 const char *filename = qdict_get_str(qdict, "target");
1094 const char *format = qdict_get_try_str(qdict, "format");
1095 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1096 bool full = qdict_get_try_bool(qdict, "full", false);
1097 enum NewImageMode mode;
1098 Error *err = NULL;
1100 if (!filename) {
1101 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1102 hmp_handle_error(mon, &err);
1103 return;
1106 if (reuse) {
1107 mode = NEW_IMAGE_MODE_EXISTING;
1108 } else {
1109 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1112 qmp_drive_backup(device, filename, !!format, format,
1113 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1114 true, mode, false, 0, false, NULL,
1115 false, 0, false, 0, &err);
1116 hmp_handle_error(mon, &err);
1119 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1121 const char *device = qdict_get_str(qdict, "device");
1122 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1123 const char *format = qdict_get_try_str(qdict, "format");
1124 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1125 enum NewImageMode mode;
1126 Error *err = NULL;
1128 if (!filename) {
1129 /* In the future, if 'snapshot-file' is not specified, the snapshot
1130 will be taken internally. Today it's actually required. */
1131 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1132 hmp_handle_error(mon, &err);
1133 return;
1136 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1137 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1138 filename, false, NULL,
1139 !!format, format,
1140 true, mode, &err);
1141 hmp_handle_error(mon, &err);
1144 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1146 const char *device = qdict_get_str(qdict, "device");
1147 const char *name = qdict_get_str(qdict, "name");
1148 Error *err = NULL;
1150 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1151 hmp_handle_error(mon, &err);
1154 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1156 const char *device = qdict_get_str(qdict, "device");
1157 const char *name = qdict_get_str(qdict, "name");
1158 const char *id = qdict_get_try_str(qdict, "id");
1159 Error *err = NULL;
1161 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1162 true, name, &err);
1163 hmp_handle_error(mon, &err);
1166 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1168 qmp_migrate_cancel(NULL);
1171 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1173 Error *err = NULL;
1174 const char *uri = qdict_get_str(qdict, "uri");
1176 qmp_migrate_incoming(uri, &err);
1178 hmp_handle_error(mon, &err);
1181 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1183 double value = qdict_get_double(qdict, "value");
1184 qmp_migrate_set_downtime(value, NULL);
1187 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1189 int64_t value = qdict_get_int(qdict, "value");
1190 Error *err = NULL;
1192 qmp_migrate_set_cache_size(value, &err);
1193 if (err) {
1194 monitor_printf(mon, "%s\n", error_get_pretty(err));
1195 error_free(err);
1196 return;
1200 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1202 int64_t value = qdict_get_int(qdict, "value");
1203 qmp_migrate_set_speed(value, NULL);
1206 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1208 const char *cap = qdict_get_str(qdict, "capability");
1209 bool state = qdict_get_bool(qdict, "state");
1210 Error *err = NULL;
1211 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1212 int i;
1214 for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
1215 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1216 caps->value = g_malloc0(sizeof(*caps->value));
1217 caps->value->capability = i;
1218 caps->value->state = state;
1219 caps->next = NULL;
1220 qmp_migrate_set_capabilities(caps, &err);
1221 break;
1225 if (i == MIGRATION_CAPABILITY__MAX) {
1226 error_setg(&err, QERR_INVALID_PARAMETER, cap);
1229 qapi_free_MigrationCapabilityStatusList(caps);
1231 if (err) {
1232 monitor_printf(mon, "migrate_set_capability: %s\n",
1233 error_get_pretty(err));
1234 error_free(err);
1238 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1240 const char *param = qdict_get_str(qdict, "parameter");
1241 int value = qdict_get_int(qdict, "value");
1242 Error *err = NULL;
1243 bool has_compress_level = false;
1244 bool has_compress_threads = false;
1245 bool has_decompress_threads = false;
1246 bool has_x_cpu_throttle_initial = false;
1247 bool has_x_cpu_throttle_increment = false;
1248 int i;
1250 for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
1251 if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
1252 switch (i) {
1253 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1254 has_compress_level = true;
1255 break;
1256 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1257 has_compress_threads = true;
1258 break;
1259 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1260 has_decompress_threads = true;
1261 break;
1262 case MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL:
1263 has_x_cpu_throttle_initial = true;
1264 break;
1265 case MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT:
1266 has_x_cpu_throttle_increment = true;
1267 break;
1269 qmp_migrate_set_parameters(has_compress_level, value,
1270 has_compress_threads, value,
1271 has_decompress_threads, value,
1272 has_x_cpu_throttle_initial, value,
1273 has_x_cpu_throttle_increment, value,
1274 &err);
1275 break;
1279 if (i == MIGRATION_PARAMETER__MAX) {
1280 error_setg(&err, QERR_INVALID_PARAMETER, param);
1283 if (err) {
1284 monitor_printf(mon, "migrate_set_parameter: %s\n",
1285 error_get_pretty(err));
1286 error_free(err);
1290 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1292 Error *err = NULL;
1293 const char *protocol = qdict_get_str(qdict, "protocol");
1294 const char *hostname = qdict_get_str(qdict, "hostname");
1295 bool has_port = qdict_haskey(qdict, "port");
1296 int port = qdict_get_try_int(qdict, "port", -1);
1297 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1298 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1299 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1301 qmp_client_migrate_info(protocol, hostname,
1302 has_port, port, has_tls_port, tls_port,
1303 !!cert_subject, cert_subject, &err);
1304 hmp_handle_error(mon, &err);
1307 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1309 Error *err = NULL;
1310 qmp_migrate_start_postcopy(&err);
1311 hmp_handle_error(mon, &err);
1314 void hmp_set_password(Monitor *mon, const QDict *qdict)
1316 const char *protocol = qdict_get_str(qdict, "protocol");
1317 const char *password = qdict_get_str(qdict, "password");
1318 const char *connected = qdict_get_try_str(qdict, "connected");
1319 Error *err = NULL;
1321 qmp_set_password(protocol, password, !!connected, connected, &err);
1322 hmp_handle_error(mon, &err);
1325 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1327 const char *protocol = qdict_get_str(qdict, "protocol");
1328 const char *whenstr = qdict_get_str(qdict, "time");
1329 Error *err = NULL;
1331 qmp_expire_password(protocol, whenstr, &err);
1332 hmp_handle_error(mon, &err);
1335 void hmp_eject(Monitor *mon, const QDict *qdict)
1337 bool force = qdict_get_try_bool(qdict, "force", false);
1338 const char *device = qdict_get_str(qdict, "device");
1339 Error *err = NULL;
1341 qmp_eject(device, true, force, &err);
1342 hmp_handle_error(mon, &err);
1345 static void hmp_change_read_arg(void *opaque, const char *password,
1346 void *readline_opaque)
1348 qmp_change_vnc_password(password, NULL);
1349 monitor_read_command(opaque, 1);
1352 void hmp_change(Monitor *mon, const QDict *qdict)
1354 const char *device = qdict_get_str(qdict, "device");
1355 const char *target = qdict_get_str(qdict, "target");
1356 const char *arg = qdict_get_try_str(qdict, "arg");
1357 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1358 BlockdevChangeReadOnlyMode read_only_mode = 0;
1359 Error *err = NULL;
1361 if (strcmp(device, "vnc") == 0) {
1362 if (read_only) {
1363 monitor_printf(mon,
1364 "Parameter 'read-only-mode' is invalid for VNC\n");
1365 return;
1367 if (strcmp(target, "passwd") == 0 ||
1368 strcmp(target, "password") == 0) {
1369 if (!arg) {
1370 monitor_read_password(mon, hmp_change_read_arg, NULL);
1371 return;
1374 qmp_change("vnc", target, !!arg, arg, &err);
1375 } else {
1376 if (read_only) {
1377 read_only_mode =
1378 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup,
1379 read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX,
1380 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1381 if (err) {
1382 hmp_handle_error(mon, &err);
1383 return;
1387 qmp_blockdev_change_medium(device, target, !!arg, arg,
1388 !!read_only, read_only_mode, &err);
1389 if (err &&
1390 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
1391 error_free(err);
1392 monitor_read_block_device_key(mon, device, NULL, NULL);
1393 return;
1397 hmp_handle_error(mon, &err);
1400 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1402 Error *err = NULL;
1404 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
1405 qdict_get_int(qdict, "bps"),
1406 qdict_get_int(qdict, "bps_rd"),
1407 qdict_get_int(qdict, "bps_wr"),
1408 qdict_get_int(qdict, "iops"),
1409 qdict_get_int(qdict, "iops_rd"),
1410 qdict_get_int(qdict, "iops_wr"),
1411 false, /* no burst max via HMP */
1413 false,
1415 false,
1417 false,
1419 false,
1421 false,
1423 false, /* No default I/O size */
1425 false,
1426 NULL, &err);
1427 hmp_handle_error(mon, &err);
1430 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1432 Error *error = NULL;
1433 const char *device = qdict_get_str(qdict, "device");
1434 const char *base = qdict_get_try_str(qdict, "base");
1435 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1437 qmp_block_stream(device, base != NULL, base, false, NULL,
1438 qdict_haskey(qdict, "speed"), speed,
1439 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1441 hmp_handle_error(mon, &error);
1444 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1446 Error *error = NULL;
1447 const char *device = qdict_get_str(qdict, "device");
1448 int64_t value = qdict_get_int(qdict, "speed");
1450 qmp_block_job_set_speed(device, value, &error);
1452 hmp_handle_error(mon, &error);
1455 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1457 Error *error = NULL;
1458 const char *device = qdict_get_str(qdict, "device");
1459 bool force = qdict_get_try_bool(qdict, "force", false);
1461 qmp_block_job_cancel(device, true, force, &error);
1463 hmp_handle_error(mon, &error);
1466 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1468 Error *error = NULL;
1469 const char *device = qdict_get_str(qdict, "device");
1471 qmp_block_job_pause(device, &error);
1473 hmp_handle_error(mon, &error);
1476 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1478 Error *error = NULL;
1479 const char *device = qdict_get_str(qdict, "device");
1481 qmp_block_job_resume(device, &error);
1483 hmp_handle_error(mon, &error);
1486 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1488 Error *error = NULL;
1489 const char *device = qdict_get_str(qdict, "device");
1491 qmp_block_job_complete(device, &error);
1493 hmp_handle_error(mon, &error);
1496 typedef struct HMPMigrationStatus
1498 QEMUTimer *timer;
1499 Monitor *mon;
1500 bool is_block_migration;
1501 } HMPMigrationStatus;
1503 static void hmp_migrate_status_cb(void *opaque)
1505 HMPMigrationStatus *status = opaque;
1506 MigrationInfo *info;
1508 info = qmp_query_migrate(NULL);
1509 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1510 info->status == MIGRATION_STATUS_SETUP) {
1511 if (info->has_disk) {
1512 int progress;
1514 if (info->disk->remaining) {
1515 progress = info->disk->transferred * 100 / info->disk->total;
1516 } else {
1517 progress = 100;
1520 monitor_printf(status->mon, "Completed %d %%\r", progress);
1521 monitor_flush(status->mon);
1524 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1525 } else {
1526 if (status->is_block_migration) {
1527 monitor_printf(status->mon, "\n");
1529 monitor_resume(status->mon);
1530 timer_del(status->timer);
1531 g_free(status);
1534 qapi_free_MigrationInfo(info);
1537 void hmp_migrate(Monitor *mon, const QDict *qdict)
1539 bool detach = qdict_get_try_bool(qdict, "detach", false);
1540 bool blk = qdict_get_try_bool(qdict, "blk", false);
1541 bool inc = qdict_get_try_bool(qdict, "inc", false);
1542 const char *uri = qdict_get_str(qdict, "uri");
1543 Error *err = NULL;
1545 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1546 if (err) {
1547 monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
1548 error_free(err);
1549 return;
1552 if (!detach) {
1553 HMPMigrationStatus *status;
1555 if (monitor_suspend(mon) < 0) {
1556 monitor_printf(mon, "terminal does not allow synchronous "
1557 "migration, continuing detached\n");
1558 return;
1561 status = g_malloc0(sizeof(*status));
1562 status->mon = mon;
1563 status->is_block_migration = blk || inc;
1564 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1565 status);
1566 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1570 void hmp_device_add(Monitor *mon, const QDict *qdict)
1572 Error *err = NULL;
1574 qmp_device_add((QDict *)qdict, NULL, &err);
1575 hmp_handle_error(mon, &err);
1578 void hmp_device_del(Monitor *mon, const QDict *qdict)
1580 const char *id = qdict_get_str(qdict, "id");
1581 Error *err = NULL;
1583 qmp_device_del(id, &err);
1584 hmp_handle_error(mon, &err);
1587 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1589 Error *err = NULL;
1590 bool paging = qdict_get_try_bool(qdict, "paging", false);
1591 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
1592 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
1593 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
1594 const char *file = qdict_get_str(qdict, "filename");
1595 bool has_begin = qdict_haskey(qdict, "begin");
1596 bool has_length = qdict_haskey(qdict, "length");
1597 int64_t begin = 0;
1598 int64_t length = 0;
1599 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1600 char *prot;
1602 if (zlib + lzo + snappy > 1) {
1603 error_setg(&err, "only one of '-z|-l|-s' can be set");
1604 hmp_handle_error(mon, &err);
1605 return;
1608 if (zlib) {
1609 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1612 if (lzo) {
1613 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1616 if (snappy) {
1617 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1620 if (has_begin) {
1621 begin = qdict_get_int(qdict, "begin");
1623 if (has_length) {
1624 length = qdict_get_int(qdict, "length");
1627 prot = g_strconcat("file:", file, NULL);
1629 qmp_dump_guest_memory(paging, prot, has_begin, begin, has_length, length,
1630 true, dump_format, &err);
1631 hmp_handle_error(mon, &err);
1632 g_free(prot);
1635 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1637 Error *err = NULL;
1638 QemuOpts *opts;
1640 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1641 if (err) {
1642 goto out;
1645 netdev_add(opts, &err);
1646 if (err) {
1647 qemu_opts_del(opts);
1650 out:
1651 hmp_handle_error(mon, &err);
1654 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1656 const char *id = qdict_get_str(qdict, "id");
1657 Error *err = NULL;
1659 qmp_netdev_del(id, &err);
1660 hmp_handle_error(mon, &err);
1663 void hmp_object_add(Monitor *mon, const QDict *qdict)
1665 Error *err = NULL;
1666 Error *err_end = NULL;
1667 QemuOpts *opts;
1668 char *type = NULL;
1669 char *id = NULL;
1670 void *dummy = NULL;
1671 OptsVisitor *ov;
1672 QDict *pdict;
1674 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1675 if (err) {
1676 goto out;
1679 ov = opts_visitor_new(opts);
1680 pdict = qdict_clone_shallow(qdict);
1682 visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err);
1683 if (err) {
1684 goto out_clean;
1687 qdict_del(pdict, "qom-type");
1688 visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
1689 if (err) {
1690 goto out_end;
1693 qdict_del(pdict, "id");
1694 visit_type_str(opts_get_visitor(ov), &id, "id", &err);
1695 if (err) {
1696 goto out_end;
1699 object_add(type, id, pdict, opts_get_visitor(ov), &err);
1701 out_end:
1702 visit_end_struct(opts_get_visitor(ov), &err_end);
1703 if (!err && err_end) {
1704 qmp_object_del(id, NULL);
1706 error_propagate(&err, err_end);
1707 out_clean:
1708 opts_visitor_cleanup(ov);
1710 QDECREF(pdict);
1711 qemu_opts_del(opts);
1712 g_free(id);
1713 g_free(type);
1714 g_free(dummy);
1716 out:
1717 hmp_handle_error(mon, &err);
1720 void hmp_getfd(Monitor *mon, const QDict *qdict)
1722 const char *fdname = qdict_get_str(qdict, "fdname");
1723 Error *err = NULL;
1725 qmp_getfd(fdname, &err);
1726 hmp_handle_error(mon, &err);
1729 void hmp_closefd(Monitor *mon, const QDict *qdict)
1731 const char *fdname = qdict_get_str(qdict, "fdname");
1732 Error *err = NULL;
1734 qmp_closefd(fdname, &err);
1735 hmp_handle_error(mon, &err);
1738 void hmp_sendkey(Monitor *mon, const QDict *qdict)
1740 const char *keys = qdict_get_str(qdict, "keys");
1741 KeyValueList *keylist, *head = NULL, *tmp = NULL;
1742 int has_hold_time = qdict_haskey(qdict, "hold-time");
1743 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1744 Error *err = NULL;
1745 char keyname_buf[16];
1746 char *separator;
1747 int keyname_len;
1749 while (1) {
1750 separator = strchr(keys, '-');
1751 keyname_len = separator ? separator - keys : strlen(keys);
1752 pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
1754 /* Be compatible with old interface, convert user inputted "<" */
1755 if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) {
1756 pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
1757 keyname_len = 4;
1759 keyname_buf[keyname_len] = 0;
1761 keylist = g_malloc0(sizeof(*keylist));
1762 keylist->value = g_malloc0(sizeof(*keylist->value));
1764 if (!head) {
1765 head = keylist;
1767 if (tmp) {
1768 tmp->next = keylist;
1770 tmp = keylist;
1772 if (strstart(keyname_buf, "0x", NULL)) {
1773 char *endp;
1774 int value = strtoul(keyname_buf, &endp, 0);
1775 if (*endp != '\0') {
1776 goto err_out;
1778 keylist->value->type = KEY_VALUE_KIND_NUMBER;
1779 keylist->value->u.number = value;
1780 } else {
1781 int idx = index_from_key(keyname_buf);
1782 if (idx == Q_KEY_CODE__MAX) {
1783 goto err_out;
1785 keylist->value->type = KEY_VALUE_KIND_QCODE;
1786 keylist->value->u.qcode = idx;
1789 if (!separator) {
1790 break;
1792 keys = separator + 1;
1795 qmp_send_key(head, has_hold_time, hold_time, &err);
1796 hmp_handle_error(mon, &err);
1798 out:
1799 qapi_free_KeyValueList(head);
1800 return;
1802 err_out:
1803 monitor_printf(mon, "invalid parameter: %s\n", keyname_buf);
1804 goto out;
1807 void hmp_screendump(Monitor *mon, const QDict *qdict)
1809 const char *filename = qdict_get_str(qdict, "filename");
1810 Error *err = NULL;
1812 qmp_screendump(filename, &err);
1813 hmp_handle_error(mon, &err);
1816 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1818 const char *uri = qdict_get_str(qdict, "uri");
1819 bool writable = qdict_get_try_bool(qdict, "writable", false);
1820 bool all = qdict_get_try_bool(qdict, "all", false);
1821 Error *local_err = NULL;
1822 BlockInfoList *block_list, *info;
1823 SocketAddress *addr;
1825 if (writable && !all) {
1826 error_setg(&local_err, "-w only valid together with -a");
1827 goto exit;
1830 /* First check if the address is valid and start the server. */
1831 addr = socket_parse(uri, &local_err);
1832 if (local_err != NULL) {
1833 goto exit;
1836 qmp_nbd_server_start(addr, &local_err);
1837 qapi_free_SocketAddress(addr);
1838 if (local_err != NULL) {
1839 goto exit;
1842 if (!all) {
1843 return;
1846 /* Then try adding all block devices. If one fails, close all and
1847 * exit.
1849 block_list = qmp_query_block(NULL);
1851 for (info = block_list; info; info = info->next) {
1852 if (!info->value->has_inserted) {
1853 continue;
1856 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1858 if (local_err != NULL) {
1859 qmp_nbd_server_stop(NULL);
1860 break;
1864 qapi_free_BlockInfoList(block_list);
1866 exit:
1867 hmp_handle_error(mon, &local_err);
1870 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1872 const char *device = qdict_get_str(qdict, "device");
1873 bool writable = qdict_get_try_bool(qdict, "writable", false);
1874 Error *local_err = NULL;
1876 qmp_nbd_server_add(device, true, writable, &local_err);
1878 if (local_err != NULL) {
1879 hmp_handle_error(mon, &local_err);
1883 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1885 Error *err = NULL;
1887 qmp_nbd_server_stop(&err);
1888 hmp_handle_error(mon, &err);
1891 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
1893 int cpuid;
1894 Error *err = NULL;
1896 cpuid = qdict_get_int(qdict, "id");
1897 qmp_cpu_add(cpuid, &err);
1898 hmp_handle_error(mon, &err);
1901 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1903 const char *args = qdict_get_str(qdict, "args");
1904 Error *err = NULL;
1905 QemuOpts *opts;
1907 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
1908 if (opts == NULL) {
1909 error_setg(&err, "Parsing chardev args failed");
1910 } else {
1911 qemu_chr_new_from_opts(opts, NULL, &err);
1913 hmp_handle_error(mon, &err);
1916 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1918 Error *local_err = NULL;
1920 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1921 hmp_handle_error(mon, &local_err);
1924 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1926 BlockBackend *blk;
1927 const char* device = qdict_get_str(qdict, "device");
1928 const char* command = qdict_get_str(qdict, "command");
1929 Error *err = NULL;
1931 blk = blk_by_name(device);
1932 if (blk) {
1933 qemuio_command(blk, command);
1934 } else {
1935 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
1936 "Device '%s' not found", device);
1939 hmp_handle_error(mon, &err);
1942 void hmp_object_del(Monitor *mon, const QDict *qdict)
1944 const char *id = qdict_get_str(qdict, "id");
1945 Error *err = NULL;
1947 qmp_object_del(id, &err);
1948 hmp_handle_error(mon, &err);
1951 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
1953 Error *err = NULL;
1954 MemdevList *memdev_list = qmp_query_memdev(&err);
1955 MemdevList *m = memdev_list;
1956 StringOutputVisitor *ov;
1957 char *str;
1958 int i = 0;
1961 while (m) {
1962 ov = string_output_visitor_new(false);
1963 visit_type_uint16List(string_output_get_visitor(ov),
1964 &m->value->host_nodes, NULL, NULL);
1965 monitor_printf(mon, "memory backend: %d\n", i);
1966 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
1967 monitor_printf(mon, " merge: %s\n",
1968 m->value->merge ? "true" : "false");
1969 monitor_printf(mon, " dump: %s\n",
1970 m->value->dump ? "true" : "false");
1971 monitor_printf(mon, " prealloc: %s\n",
1972 m->value->prealloc ? "true" : "false");
1973 monitor_printf(mon, " policy: %s\n",
1974 HostMemPolicy_lookup[m->value->policy]);
1975 str = string_output_get_string(ov);
1976 monitor_printf(mon, " host nodes: %s\n", str);
1978 g_free(str);
1979 string_output_visitor_cleanup(ov);
1980 m = m->next;
1981 i++;
1984 monitor_printf(mon, "\n");
1986 qapi_free_MemdevList(memdev_list);
1989 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
1991 Error *err = NULL;
1992 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
1993 MemoryDeviceInfoList *info;
1994 MemoryDeviceInfo *value;
1995 PCDIMMDeviceInfo *di;
1997 for (info = info_list; info; info = info->next) {
1998 value = info->value;
2000 if (value) {
2001 switch (value->type) {
2002 case MEMORY_DEVICE_INFO_KIND_DIMM:
2003 di = value->u.dimm;
2005 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2006 MemoryDeviceInfoKind_lookup[value->type],
2007 di->id ? di->id : "");
2008 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2009 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2010 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2011 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2012 monitor_printf(mon, " memdev: %s\n", di->memdev);
2013 monitor_printf(mon, " hotplugged: %s\n",
2014 di->hotplugged ? "true" : "false");
2015 monitor_printf(mon, " hotpluggable: %s\n",
2016 di->hotpluggable ? "true" : "false");
2017 break;
2018 default:
2019 break;
2024 qapi_free_MemoryDeviceInfoList(info_list);
2027 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2029 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2030 IOThreadInfoList *info;
2032 for (info = info_list; info; info = info->next) {
2033 monitor_printf(mon, "%s: thread_id=%" PRId64 "\n",
2034 info->value->id, info->value->thread_id);
2037 qapi_free_IOThreadInfoList(info_list);
2040 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2042 const char *path = qdict_get_try_str(qdict, "path");
2043 ObjectPropertyInfoList *list;
2044 Error *err = NULL;
2046 if (path == NULL) {
2047 monitor_printf(mon, "/\n");
2048 return;
2051 list = qmp_qom_list(path, &err);
2052 if (err == NULL) {
2053 ObjectPropertyInfoList *start = list;
2054 while (list != NULL) {
2055 ObjectPropertyInfo *value = list->value;
2057 monitor_printf(mon, "%s (%s)\n",
2058 value->name, value->type);
2059 list = list->next;
2061 qapi_free_ObjectPropertyInfoList(start);
2063 hmp_handle_error(mon, &err);
2066 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2068 const char *path = qdict_get_str(qdict, "path");
2069 const char *property = qdict_get_str(qdict, "property");
2070 const char *value = qdict_get_str(qdict, "value");
2071 Error *err = NULL;
2072 bool ambiguous = false;
2073 Object *obj;
2075 obj = object_resolve_path(path, &ambiguous);
2076 if (obj == NULL) {
2077 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2078 "Device '%s' not found", path);
2079 } else {
2080 if (ambiguous) {
2081 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2083 object_property_parse(obj, value, property, &err);
2085 hmp_handle_error(mon, &err);
2088 void hmp_rocker(Monitor *mon, const QDict *qdict)
2090 const char *name = qdict_get_str(qdict, "name");
2091 RockerSwitch *rocker;
2092 Error *errp = NULL;
2094 rocker = qmp_query_rocker(name, &errp);
2095 if (errp != NULL) {
2096 hmp_handle_error(mon, &errp);
2097 return;
2100 monitor_printf(mon, "name: %s\n", rocker->name);
2101 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2102 monitor_printf(mon, "ports: %d\n", rocker->ports);
2104 qapi_free_RockerSwitch(rocker);
2107 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2109 RockerPortList *list, *port;
2110 const char *name = qdict_get_str(qdict, "name");
2111 Error *errp = NULL;
2113 list = qmp_query_rocker_ports(name, &errp);
2114 if (errp != NULL) {
2115 hmp_handle_error(mon, &errp);
2116 return;
2119 monitor_printf(mon, " ena/ speed/ auto\n");
2120 monitor_printf(mon, " port link duplex neg?\n");
2122 for (port = list; port; port = port->next) {
2123 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2124 port->value->name,
2125 port->value->enabled ? port->value->link_up ?
2126 "up" : "down" : "!ena",
2127 port->value->speed == 10000 ? "10G" : "??",
2128 port->value->duplex ? "FD" : "HD",
2129 port->value->autoneg ? "Yes" : "No");
2132 qapi_free_RockerPortList(list);
2135 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2137 RockerOfDpaFlowList *list, *info;
2138 const char *name = qdict_get_str(qdict, "name");
2139 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2140 Error *errp = NULL;
2142 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &errp);
2143 if (errp != NULL) {
2144 hmp_handle_error(mon, &errp);
2145 return;
2148 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2150 for (info = list; info; info = info->next) {
2151 RockerOfDpaFlow *flow = info->value;
2152 RockerOfDpaFlowKey *key = flow->key;
2153 RockerOfDpaFlowMask *mask = flow->mask;
2154 RockerOfDpaFlowAction *action = flow->action;
2156 if (flow->hits) {
2157 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2158 key->priority, key->tbl_id, flow->hits);
2159 } else {
2160 monitor_printf(mon, "%-4d %-3d ",
2161 key->priority, key->tbl_id);
2164 if (key->has_in_pport) {
2165 monitor_printf(mon, " pport %d", key->in_pport);
2166 if (mask->has_in_pport) {
2167 monitor_printf(mon, "(0x%x)", mask->in_pport);
2171 if (key->has_vlan_id) {
2172 monitor_printf(mon, " vlan %d",
2173 key->vlan_id & VLAN_VID_MASK);
2174 if (mask->has_vlan_id) {
2175 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2179 if (key->has_tunnel_id) {
2180 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2181 if (mask->has_tunnel_id) {
2182 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2186 if (key->has_eth_type) {
2187 switch (key->eth_type) {
2188 case 0x0806:
2189 monitor_printf(mon, " ARP");
2190 break;
2191 case 0x0800:
2192 monitor_printf(mon, " IP");
2193 break;
2194 case 0x86dd:
2195 monitor_printf(mon, " IPv6");
2196 break;
2197 case 0x8809:
2198 monitor_printf(mon, " LACP");
2199 break;
2200 case 0x88cc:
2201 monitor_printf(mon, " LLDP");
2202 break;
2203 default:
2204 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2205 break;
2209 if (key->has_eth_src) {
2210 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2211 (mask->has_eth_src) &&
2212 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2213 monitor_printf(mon, " src <any mcast/bcast>");
2214 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2215 (mask->has_eth_src) &&
2216 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2217 monitor_printf(mon, " src <any ucast>");
2218 } else {
2219 monitor_printf(mon, " src %s", key->eth_src);
2220 if (mask->has_eth_src) {
2221 monitor_printf(mon, "(%s)", mask->eth_src);
2226 if (key->has_eth_dst) {
2227 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2228 (mask->has_eth_dst) &&
2229 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2230 monitor_printf(mon, " dst <any mcast/bcast>");
2231 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2232 (mask->has_eth_dst) &&
2233 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2234 monitor_printf(mon, " dst <any ucast>");
2235 } else {
2236 monitor_printf(mon, " dst %s", key->eth_dst);
2237 if (mask->has_eth_dst) {
2238 monitor_printf(mon, "(%s)", mask->eth_dst);
2243 if (key->has_ip_proto) {
2244 monitor_printf(mon, " proto %d", key->ip_proto);
2245 if (mask->has_ip_proto) {
2246 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2250 if (key->has_ip_tos) {
2251 monitor_printf(mon, " TOS %d", key->ip_tos);
2252 if (mask->has_ip_tos) {
2253 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2257 if (key->has_ip_dst) {
2258 monitor_printf(mon, " dst %s", key->ip_dst);
2261 if (action->has_goto_tbl || action->has_group_id ||
2262 action->has_new_vlan_id) {
2263 monitor_printf(mon, " -->");
2266 if (action->has_new_vlan_id) {
2267 monitor_printf(mon, " apply new vlan %d",
2268 ntohs(action->new_vlan_id));
2271 if (action->has_group_id) {
2272 monitor_printf(mon, " write group 0x%08x", action->group_id);
2275 if (action->has_goto_tbl) {
2276 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2279 monitor_printf(mon, "\n");
2282 qapi_free_RockerOfDpaFlowList(list);
2285 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2287 RockerOfDpaGroupList *list, *g;
2288 const char *name = qdict_get_str(qdict, "name");
2289 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2290 Error *errp = NULL;
2291 bool set = false;
2293 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &errp);
2294 if (errp != NULL) {
2295 hmp_handle_error(mon, &errp);
2296 return;
2299 monitor_printf(mon, "id (decode) --> buckets\n");
2301 for (g = list; g; g = g->next) {
2302 RockerOfDpaGroup *group = g->value;
2304 monitor_printf(mon, "0x%08x", group->id);
2306 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2307 group->type == 1 ? "L2 rewrite" :
2308 group->type == 2 ? "L3 unicast" :
2309 group->type == 3 ? "L2 multicast" :
2310 group->type == 4 ? "L2 flood" :
2311 group->type == 5 ? "L3 interface" :
2312 group->type == 6 ? "L3 multicast" :
2313 group->type == 7 ? "L3 ECMP" :
2314 group->type == 8 ? "L2 overlay" :
2315 "unknown");
2317 if (group->has_vlan_id) {
2318 monitor_printf(mon, " vlan %d", group->vlan_id);
2321 if (group->has_pport) {
2322 monitor_printf(mon, " pport %d", group->pport);
2325 if (group->has_index) {
2326 monitor_printf(mon, " index %d", group->index);
2329 monitor_printf(mon, ") -->");
2331 if (group->has_set_vlan_id && group->set_vlan_id) {
2332 set = true;
2333 monitor_printf(mon, " set vlan %d",
2334 group->set_vlan_id & VLAN_VID_MASK);
2337 if (group->has_set_eth_src) {
2338 if (!set) {
2339 set = true;
2340 monitor_printf(mon, " set");
2342 monitor_printf(mon, " src %s", group->set_eth_src);
2345 if (group->has_set_eth_dst) {
2346 if (!set) {
2347 set = true;
2348 monitor_printf(mon, " set");
2350 monitor_printf(mon, " dst %s", group->set_eth_dst);
2353 set = false;
2355 if (group->has_ttl_check && group->ttl_check) {
2356 monitor_printf(mon, " check TTL");
2359 if (group->has_group_id && group->group_id) {
2360 monitor_printf(mon, " group id 0x%08x", group->group_id);
2363 if (group->has_pop_vlan && group->pop_vlan) {
2364 monitor_printf(mon, " pop vlan");
2367 if (group->has_out_pport) {
2368 monitor_printf(mon, " out pport %d", group->out_pport);
2371 if (group->has_group_ids) {
2372 struct uint32List *id;
2374 monitor_printf(mon, " groups [");
2375 for (id = group->group_ids; id; id = id->next) {
2376 monitor_printf(mon, "0x%08x", id->value);
2377 if (id->next) {
2378 monitor_printf(mon, ",");
2381 monitor_printf(mon, "]");
2384 monitor_printf(mon, "\n");
2387 qapi_free_RockerOfDpaGroupList(list);