commit: Add 'job-id' parameter to 'block-commit'
[qemu.git] / hmp.c
blob3ca79c3ea3103077b6eefb5ffcb9ccd78f048d1a
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 "qemu/osdep.h"
17 #include "hmp.h"
18 #include "net/net.h"
19 #include "net/eth.h"
20 #include "sysemu/char.h"
21 #include "sysemu/block-backend.h"
22 #include "qemu/option.h"
23 #include "qemu/timer.h"
24 #include "qmp-commands.h"
25 #include "qemu/sockets.h"
26 #include "monitor/monitor.h"
27 #include "monitor/qdev.h"
28 #include "qapi/opts-visitor.h"
29 #include "qapi/qmp/qerror.h"
30 #include "qapi/string-output-visitor.h"
31 #include "qapi/util.h"
32 #include "qapi-visit.h"
33 #include "qom/object_interfaces.h"
34 #include "ui/console.h"
35 #include "block/qapi.h"
36 #include "qemu-io.h"
37 #include "qemu/cutils.h"
38 #include "qemu/error-report.h"
40 #ifdef CONFIG_SPICE
41 #include <spice/enums.h>
42 #endif
44 static void hmp_handle_error(Monitor *mon, Error **errp)
46 assert(errp);
47 if (*errp) {
48 error_report_err(*errp);
52 void hmp_info_name(Monitor *mon, const QDict *qdict)
54 NameInfo *info;
56 info = qmp_query_name(NULL);
57 if (info->has_name) {
58 monitor_printf(mon, "%s\n", info->name);
60 qapi_free_NameInfo(info);
63 void hmp_info_version(Monitor *mon, const QDict *qdict)
65 VersionInfo *info;
67 info = qmp_query_version(NULL);
69 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
70 info->qemu->major, info->qemu->minor, info->qemu->micro,
71 info->package);
73 qapi_free_VersionInfo(info);
76 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
78 KvmInfo *info;
80 info = qmp_query_kvm(NULL);
81 monitor_printf(mon, "kvm support: ");
82 if (info->present) {
83 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
84 } else {
85 monitor_printf(mon, "not compiled\n");
88 qapi_free_KvmInfo(info);
91 void hmp_info_status(Monitor *mon, const QDict *qdict)
93 StatusInfo *info;
95 info = qmp_query_status(NULL);
97 monitor_printf(mon, "VM status: %s%s",
98 info->running ? "running" : "paused",
99 info->singlestep ? " (single step mode)" : "");
101 if (!info->running && info->status != RUN_STATE_PAUSED) {
102 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
105 monitor_printf(mon, "\n");
107 qapi_free_StatusInfo(info);
110 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
112 UuidInfo *info;
114 info = qmp_query_uuid(NULL);
115 monitor_printf(mon, "%s\n", info->UUID);
116 qapi_free_UuidInfo(info);
119 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
121 ChardevInfoList *char_info, *info;
123 char_info = qmp_query_chardev(NULL);
124 for (info = char_info; info; info = info->next) {
125 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
126 info->value->filename);
129 qapi_free_ChardevInfoList(char_info);
132 void hmp_info_mice(Monitor *mon, const QDict *qdict)
134 MouseInfoList *mice_list, *mouse;
136 mice_list = qmp_query_mice(NULL);
137 if (!mice_list) {
138 monitor_printf(mon, "No mouse devices connected\n");
139 return;
142 for (mouse = mice_list; mouse; mouse = mouse->next) {
143 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
144 mouse->value->current ? '*' : ' ',
145 mouse->value->index, mouse->value->name,
146 mouse->value->absolute ? " (absolute)" : "");
149 qapi_free_MouseInfoList(mice_list);
152 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
154 MigrationInfo *info;
155 MigrationCapabilityStatusList *caps, *cap;
157 info = qmp_query_migrate(NULL);
158 caps = qmp_query_migrate_capabilities(NULL);
160 /* do not display parameters during setup */
161 if (info->has_status && caps) {
162 monitor_printf(mon, "capabilities: ");
163 for (cap = caps; cap; cap = cap->next) {
164 monitor_printf(mon, "%s: %s ",
165 MigrationCapability_lookup[cap->value->capability],
166 cap->value->state ? "on" : "off");
168 monitor_printf(mon, "\n");
171 if (info->has_status) {
172 monitor_printf(mon, "Migration status: %s",
173 MigrationStatus_lookup[info->status]);
174 if (info->status == MIGRATION_STATUS_FAILED &&
175 info->has_error_desc) {
176 monitor_printf(mon, " (%s)\n", info->error_desc);
177 } else {
178 monitor_printf(mon, "\n");
181 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
182 info->total_time);
183 if (info->has_expected_downtime) {
184 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
185 info->expected_downtime);
187 if (info->has_downtime) {
188 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
189 info->downtime);
191 if (info->has_setup_time) {
192 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
193 info->setup_time);
197 if (info->has_ram) {
198 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
199 info->ram->transferred >> 10);
200 monitor_printf(mon, "throughput: %0.2f mbps\n",
201 info->ram->mbps);
202 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
203 info->ram->remaining >> 10);
204 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
205 info->ram->total >> 10);
206 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
207 info->ram->duplicate);
208 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
209 info->ram->skipped);
210 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
211 info->ram->normal);
212 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
213 info->ram->normal_bytes >> 10);
214 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
215 info->ram->dirty_sync_count);
216 if (info->ram->dirty_pages_rate) {
217 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
218 info->ram->dirty_pages_rate);
220 if (info->ram->postcopy_requests) {
221 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
222 info->ram->postcopy_requests);
226 if (info->has_disk) {
227 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
228 info->disk->transferred >> 10);
229 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
230 info->disk->remaining >> 10);
231 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
232 info->disk->total >> 10);
235 if (info->has_xbzrle_cache) {
236 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
237 info->xbzrle_cache->cache_size);
238 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
239 info->xbzrle_cache->bytes >> 10);
240 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
241 info->xbzrle_cache->pages);
242 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
243 info->xbzrle_cache->cache_miss);
244 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
245 info->xbzrle_cache->cache_miss_rate);
246 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
247 info->xbzrle_cache->overflow);
250 if (info->has_cpu_throttle_percentage) {
251 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
252 info->cpu_throttle_percentage);
255 qapi_free_MigrationInfo(info);
256 qapi_free_MigrationCapabilityStatusList(caps);
259 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
261 MigrationCapabilityStatusList *caps, *cap;
263 caps = qmp_query_migrate_capabilities(NULL);
265 if (caps) {
266 monitor_printf(mon, "capabilities: ");
267 for (cap = caps; cap; cap = cap->next) {
268 monitor_printf(mon, "%s: %s ",
269 MigrationCapability_lookup[cap->value->capability],
270 cap->value->state ? "on" : "off");
272 monitor_printf(mon, "\n");
275 qapi_free_MigrationCapabilityStatusList(caps);
278 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
280 MigrationParameters *params;
282 params = qmp_query_migrate_parameters(NULL);
284 if (params) {
285 monitor_printf(mon, "parameters:");
286 monitor_printf(mon, " %s: %" PRId64,
287 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_LEVEL],
288 params->compress_level);
289 monitor_printf(mon, " %s: %" PRId64,
290 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_THREADS],
291 params->compress_threads);
292 monitor_printf(mon, " %s: %" PRId64,
293 MigrationParameter_lookup[MIGRATION_PARAMETER_DECOMPRESS_THREADS],
294 params->decompress_threads);
295 monitor_printf(mon, " %s: %" PRId64,
296 MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL],
297 params->cpu_throttle_initial);
298 monitor_printf(mon, " %s: %" PRId64,
299 MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT],
300 params->cpu_throttle_increment);
301 monitor_printf(mon, " %s: '%s'",
302 MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_CREDS],
303 params->tls_creds ? : "");
304 monitor_printf(mon, " %s: '%s'",
305 MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_HOSTNAME],
306 params->tls_hostname ? : "");
307 monitor_printf(mon, "\n");
310 qapi_free_MigrationParameters(params);
313 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
315 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
316 qmp_query_migrate_cache_size(NULL) >> 10);
319 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
321 CpuInfoList *cpu_list, *cpu;
323 cpu_list = qmp_query_cpus(NULL);
325 for (cpu = cpu_list; cpu; cpu = cpu->next) {
326 int active = ' ';
328 if (cpu->value->CPU == monitor_get_cpu_index()) {
329 active = '*';
332 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
334 switch (cpu->value->arch) {
335 case CPU_INFO_ARCH_X86:
336 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->u.x86.pc);
337 break;
338 case CPU_INFO_ARCH_PPC:
339 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->u.ppc.nip);
340 break;
341 case CPU_INFO_ARCH_SPARC:
342 monitor_printf(mon, " pc=0x%016" PRIx64,
343 cpu->value->u.q_sparc.pc);
344 monitor_printf(mon, " npc=0x%016" PRIx64,
345 cpu->value->u.q_sparc.npc);
346 break;
347 case CPU_INFO_ARCH_MIPS:
348 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.q_mips.PC);
349 break;
350 case CPU_INFO_ARCH_TRICORE:
351 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.tricore.PC);
352 break;
353 default:
354 break;
357 if (cpu->value->halted) {
358 monitor_printf(mon, " (halted)");
361 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
364 qapi_free_CpuInfoList(cpu_list);
367 static void print_block_info(Monitor *mon, BlockInfo *info,
368 BlockDeviceInfo *inserted, bool verbose)
370 ImageInfo *image_info;
372 assert(!info || !info->has_inserted || info->inserted == inserted);
374 if (info) {
375 monitor_printf(mon, "%s", info->device);
376 if (inserted && inserted->has_node_name) {
377 monitor_printf(mon, " (%s)", inserted->node_name);
379 } else {
380 assert(inserted);
381 monitor_printf(mon, "%s",
382 inserted->has_node_name
383 ? inserted->node_name
384 : "<anonymous>");
387 if (inserted) {
388 monitor_printf(mon, ": %s (%s%s%s)\n",
389 inserted->file,
390 inserted->drv,
391 inserted->ro ? ", read-only" : "",
392 inserted->encrypted ? ", encrypted" : "");
393 } else {
394 monitor_printf(mon, ": [not inserted]\n");
397 if (info) {
398 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
399 monitor_printf(mon, " I/O status: %s\n",
400 BlockDeviceIoStatus_lookup[info->io_status]);
403 if (info->removable) {
404 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
405 info->locked ? "" : "not ",
406 info->tray_open ? "open" : "closed");
411 if (!inserted) {
412 return;
415 monitor_printf(mon, " Cache mode: %s%s%s\n",
416 inserted->cache->writeback ? "writeback" : "writethrough",
417 inserted->cache->direct ? ", direct" : "",
418 inserted->cache->no_flush ? ", ignore flushes" : "");
420 if (inserted->has_backing_file) {
421 monitor_printf(mon,
422 " Backing file: %s "
423 "(chain depth: %" PRId64 ")\n",
424 inserted->backing_file,
425 inserted->backing_file_depth);
428 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
429 monitor_printf(mon, " Detect zeroes: %s\n",
430 BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]);
433 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
434 inserted->iops || inserted->iops_rd || inserted->iops_wr)
436 monitor_printf(mon, " I/O throttling: bps=%" PRId64
437 " bps_rd=%" PRId64 " bps_wr=%" PRId64
438 " bps_max=%" PRId64
439 " bps_rd_max=%" PRId64
440 " bps_wr_max=%" PRId64
441 " iops=%" PRId64 " iops_rd=%" PRId64
442 " iops_wr=%" PRId64
443 " iops_max=%" PRId64
444 " iops_rd_max=%" PRId64
445 " iops_wr_max=%" PRId64
446 " iops_size=%" PRId64
447 " group=%s\n",
448 inserted->bps,
449 inserted->bps_rd,
450 inserted->bps_wr,
451 inserted->bps_max,
452 inserted->bps_rd_max,
453 inserted->bps_wr_max,
454 inserted->iops,
455 inserted->iops_rd,
456 inserted->iops_wr,
457 inserted->iops_max,
458 inserted->iops_rd_max,
459 inserted->iops_wr_max,
460 inserted->iops_size,
461 inserted->group);
464 if (verbose) {
465 monitor_printf(mon, "\nImages:\n");
466 image_info = inserted->image;
467 while (1) {
468 bdrv_image_info_dump((fprintf_function)monitor_printf,
469 mon, image_info);
470 if (image_info->has_backing_image) {
471 image_info = image_info->backing_image;
472 } else {
473 break;
479 void hmp_info_block(Monitor *mon, const QDict *qdict)
481 BlockInfoList *block_list, *info;
482 BlockDeviceInfoList *blockdev_list, *blockdev;
483 const char *device = qdict_get_try_str(qdict, "device");
484 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
485 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
486 bool printed = false;
488 /* Print BlockBackend information */
489 if (!nodes) {
490 block_list = qmp_query_block(NULL);
491 } else {
492 block_list = NULL;
495 for (info = block_list; info; info = info->next) {
496 if (device && strcmp(device, info->value->device)) {
497 continue;
500 if (info != block_list) {
501 monitor_printf(mon, "\n");
504 print_block_info(mon, info->value, info->value->has_inserted
505 ? info->value->inserted : NULL,
506 verbose);
507 printed = true;
510 qapi_free_BlockInfoList(block_list);
512 if ((!device && !nodes) || printed) {
513 return;
516 /* Print node information */
517 blockdev_list = qmp_query_named_block_nodes(NULL);
518 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
519 assert(blockdev->value->has_node_name);
520 if (device && strcmp(device, blockdev->value->node_name)) {
521 continue;
524 if (blockdev != blockdev_list) {
525 monitor_printf(mon, "\n");
528 print_block_info(mon, NULL, blockdev->value, verbose);
530 qapi_free_BlockDeviceInfoList(blockdev_list);
533 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
535 BlockStatsList *stats_list, *stats;
537 stats_list = qmp_query_blockstats(false, false, NULL);
539 for (stats = stats_list; stats; stats = stats->next) {
540 if (!stats->value->has_device) {
541 continue;
544 monitor_printf(mon, "%s:", stats->value->device);
545 monitor_printf(mon, " rd_bytes=%" PRId64
546 " wr_bytes=%" PRId64
547 " rd_operations=%" PRId64
548 " wr_operations=%" PRId64
549 " flush_operations=%" PRId64
550 " wr_total_time_ns=%" PRId64
551 " rd_total_time_ns=%" PRId64
552 " flush_total_time_ns=%" PRId64
553 " rd_merged=%" PRId64
554 " wr_merged=%" PRId64
555 " idle_time_ns=%" PRId64
556 "\n",
557 stats->value->stats->rd_bytes,
558 stats->value->stats->wr_bytes,
559 stats->value->stats->rd_operations,
560 stats->value->stats->wr_operations,
561 stats->value->stats->flush_operations,
562 stats->value->stats->wr_total_time_ns,
563 stats->value->stats->rd_total_time_ns,
564 stats->value->stats->flush_total_time_ns,
565 stats->value->stats->rd_merged,
566 stats->value->stats->wr_merged,
567 stats->value->stats->idle_time_ns);
570 qapi_free_BlockStatsList(stats_list);
573 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
575 VncInfo *info;
576 Error *err = NULL;
577 VncClientInfoList *client;
579 info = qmp_query_vnc(&err);
580 if (err) {
581 error_report_err(err);
582 return;
585 if (!info->enabled) {
586 monitor_printf(mon, "Server: disabled\n");
587 goto out;
590 monitor_printf(mon, "Server:\n");
591 if (info->has_host && info->has_service) {
592 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
594 if (info->has_auth) {
595 monitor_printf(mon, " auth: %s\n", info->auth);
598 if (!info->has_clients || info->clients == NULL) {
599 monitor_printf(mon, "Client: none\n");
600 } else {
601 for (client = info->clients; client; client = client->next) {
602 monitor_printf(mon, "Client:\n");
603 monitor_printf(mon, " address: %s:%s\n",
604 client->value->host,
605 client->value->service);
606 monitor_printf(mon, " x509_dname: %s\n",
607 client->value->x509_dname ?
608 client->value->x509_dname : "none");
609 monitor_printf(mon, " username: %s\n",
610 client->value->has_sasl_username ?
611 client->value->sasl_username : "none");
615 out:
616 qapi_free_VncInfo(info);
619 #ifdef CONFIG_SPICE
620 void hmp_info_spice(Monitor *mon, const QDict *qdict)
622 SpiceChannelList *chan;
623 SpiceInfo *info;
624 const char *channel_name;
625 const char * const channel_names[] = {
626 [SPICE_CHANNEL_MAIN] = "main",
627 [SPICE_CHANNEL_DISPLAY] = "display",
628 [SPICE_CHANNEL_INPUTS] = "inputs",
629 [SPICE_CHANNEL_CURSOR] = "cursor",
630 [SPICE_CHANNEL_PLAYBACK] = "playback",
631 [SPICE_CHANNEL_RECORD] = "record",
632 [SPICE_CHANNEL_TUNNEL] = "tunnel",
633 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
634 [SPICE_CHANNEL_USBREDIR] = "usbredir",
635 [SPICE_CHANNEL_PORT] = "port",
636 #if 0
637 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
638 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
639 * as quick fix for build failures with older versions. */
640 [SPICE_CHANNEL_WEBDAV] = "webdav",
641 #endif
644 info = qmp_query_spice(NULL);
646 if (!info->enabled) {
647 monitor_printf(mon, "Server: disabled\n");
648 goto out;
651 monitor_printf(mon, "Server:\n");
652 if (info->has_port) {
653 monitor_printf(mon, " address: %s:%" PRId64 "\n",
654 info->host, info->port);
656 if (info->has_tls_port) {
657 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
658 info->host, info->tls_port);
660 monitor_printf(mon, " migrated: %s\n",
661 info->migrated ? "true" : "false");
662 monitor_printf(mon, " auth: %s\n", info->auth);
663 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
664 monitor_printf(mon, " mouse-mode: %s\n",
665 SpiceQueryMouseMode_lookup[info->mouse_mode]);
667 if (!info->has_channels || info->channels == NULL) {
668 monitor_printf(mon, "Channels: none\n");
669 } else {
670 for (chan = info->channels; chan; chan = chan->next) {
671 monitor_printf(mon, "Channel:\n");
672 monitor_printf(mon, " address: %s:%s%s\n",
673 chan->value->host, chan->value->port,
674 chan->value->tls ? " [tls]" : "");
675 monitor_printf(mon, " session: %" PRId64 "\n",
676 chan->value->connection_id);
677 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
678 chan->value->channel_type, chan->value->channel_id);
680 channel_name = "unknown";
681 if (chan->value->channel_type > 0 &&
682 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
683 channel_names[chan->value->channel_type]) {
684 channel_name = channel_names[chan->value->channel_type];
687 monitor_printf(mon, " channel name: %s\n", channel_name);
691 out:
692 qapi_free_SpiceInfo(info);
694 #endif
696 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
698 BalloonInfo *info;
699 Error *err = NULL;
701 info = qmp_query_balloon(&err);
702 if (err) {
703 error_report_err(err);
704 return;
707 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
709 qapi_free_BalloonInfo(info);
712 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
714 PciMemoryRegionList *region;
716 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
717 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
718 dev->slot, dev->function);
719 monitor_printf(mon, " ");
721 if (dev->class_info->has_desc) {
722 monitor_printf(mon, "%s", dev->class_info->desc);
723 } else {
724 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
727 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
728 dev->id->vendor, dev->id->device);
730 if (dev->has_irq) {
731 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
734 if (dev->has_pci_bridge) {
735 monitor_printf(mon, " BUS %" PRId64 ".\n",
736 dev->pci_bridge->bus->number);
737 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
738 dev->pci_bridge->bus->secondary);
739 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
740 dev->pci_bridge->bus->subordinate);
742 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
743 dev->pci_bridge->bus->io_range->base,
744 dev->pci_bridge->bus->io_range->limit);
746 monitor_printf(mon,
747 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
748 dev->pci_bridge->bus->memory_range->base,
749 dev->pci_bridge->bus->memory_range->limit);
751 monitor_printf(mon, " prefetchable memory range "
752 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
753 dev->pci_bridge->bus->prefetchable_range->base,
754 dev->pci_bridge->bus->prefetchable_range->limit);
757 for (region = dev->regions; region; region = region->next) {
758 uint64_t addr, size;
760 addr = region->value->address;
761 size = region->value->size;
763 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
765 if (!strcmp(region->value->type, "io")) {
766 monitor_printf(mon, "I/O at 0x%04" PRIx64
767 " [0x%04" PRIx64 "].\n",
768 addr, addr + size - 1);
769 } else {
770 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
771 " [0x%08" PRIx64 "].\n",
772 region->value->mem_type_64 ? 64 : 32,
773 region->value->prefetch ? " prefetchable" : "",
774 addr, addr + size - 1);
778 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
780 if (dev->has_pci_bridge) {
781 if (dev->pci_bridge->has_devices) {
782 PciDeviceInfoList *cdev;
783 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
784 hmp_info_pci_device(mon, cdev->value);
790 void hmp_info_pci(Monitor *mon, const QDict *qdict)
792 PciInfoList *info_list, *info;
793 Error *err = NULL;
795 info_list = qmp_query_pci(&err);
796 if (err) {
797 monitor_printf(mon, "PCI devices not supported\n");
798 error_free(err);
799 return;
802 for (info = info_list; info; info = info->next) {
803 PciDeviceInfoList *dev;
805 for (dev = info->value->devices; dev; dev = dev->next) {
806 hmp_info_pci_device(mon, dev->value);
810 qapi_free_PciInfoList(info_list);
813 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
815 BlockJobInfoList *list;
816 Error *err = NULL;
818 list = qmp_query_block_jobs(&err);
819 assert(!err);
821 if (!list) {
822 monitor_printf(mon, "No active jobs\n");
823 return;
826 while (list) {
827 if (strcmp(list->value->type, "stream") == 0) {
828 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
829 " of %" PRId64 " bytes, speed limit %" PRId64
830 " bytes/s\n",
831 list->value->device,
832 list->value->offset,
833 list->value->len,
834 list->value->speed);
835 } else {
836 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
837 " of %" PRId64 " bytes, speed limit %" PRId64
838 " bytes/s\n",
839 list->value->type,
840 list->value->device,
841 list->value->offset,
842 list->value->len,
843 list->value->speed);
845 list = list->next;
848 qapi_free_BlockJobInfoList(list);
851 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
853 TPMInfoList *info_list, *info;
854 Error *err = NULL;
855 unsigned int c = 0;
856 TPMPassthroughOptions *tpo;
858 info_list = qmp_query_tpm(&err);
859 if (err) {
860 monitor_printf(mon, "TPM device not supported\n");
861 error_free(err);
862 return;
865 if (info_list) {
866 monitor_printf(mon, "TPM device:\n");
869 for (info = info_list; info; info = info->next) {
870 TPMInfo *ti = info->value;
871 monitor_printf(mon, " tpm%d: model=%s\n",
872 c, TpmModel_lookup[ti->model]);
874 monitor_printf(mon, " \\ %s: type=%s",
875 ti->id, TpmTypeOptionsKind_lookup[ti->options->type]);
877 switch (ti->options->type) {
878 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
879 tpo = ti->options->u.passthrough.data;
880 monitor_printf(mon, "%s%s%s%s",
881 tpo->has_path ? ",path=" : "",
882 tpo->has_path ? tpo->path : "",
883 tpo->has_cancel_path ? ",cancel-path=" : "",
884 tpo->has_cancel_path ? tpo->cancel_path : "");
885 break;
886 case TPM_TYPE_OPTIONS_KIND__MAX:
887 break;
889 monitor_printf(mon, "\n");
890 c++;
892 qapi_free_TPMInfoList(info_list);
895 void hmp_quit(Monitor *mon, const QDict *qdict)
897 monitor_suspend(mon);
898 qmp_quit(NULL);
901 void hmp_stop(Monitor *mon, const QDict *qdict)
903 qmp_stop(NULL);
906 void hmp_system_reset(Monitor *mon, const QDict *qdict)
908 qmp_system_reset(NULL);
911 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
913 qmp_system_powerdown(NULL);
916 void hmp_cpu(Monitor *mon, const QDict *qdict)
918 int64_t cpu_index;
920 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
921 use it are converted to the QAPI */
922 cpu_index = qdict_get_int(qdict, "index");
923 if (monitor_set_cpu(cpu_index) < 0) {
924 monitor_printf(mon, "invalid CPU index\n");
928 void hmp_memsave(Monitor *mon, const QDict *qdict)
930 uint32_t size = qdict_get_int(qdict, "size");
931 const char *filename = qdict_get_str(qdict, "filename");
932 uint64_t addr = qdict_get_int(qdict, "val");
933 Error *err = NULL;
935 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &err);
936 hmp_handle_error(mon, &err);
939 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
941 uint32_t size = qdict_get_int(qdict, "size");
942 const char *filename = qdict_get_str(qdict, "filename");
943 uint64_t addr = qdict_get_int(qdict, "val");
944 Error *err = NULL;
946 qmp_pmemsave(addr, size, filename, &err);
947 hmp_handle_error(mon, &err);
950 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
952 const char *chardev = qdict_get_str(qdict, "device");
953 const char *data = qdict_get_str(qdict, "data");
954 Error *err = NULL;
956 qmp_ringbuf_write(chardev, data, false, 0, &err);
958 hmp_handle_error(mon, &err);
961 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
963 uint32_t size = qdict_get_int(qdict, "size");
964 const char *chardev = qdict_get_str(qdict, "device");
965 char *data;
966 Error *err = NULL;
967 int i;
969 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
970 if (err) {
971 error_report_err(err);
972 return;
975 for (i = 0; data[i]; i++) {
976 unsigned char ch = data[i];
978 if (ch == '\\') {
979 monitor_printf(mon, "\\\\");
980 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
981 monitor_printf(mon, "\\u%04X", ch);
982 } else {
983 monitor_printf(mon, "%c", ch);
987 monitor_printf(mon, "\n");
988 g_free(data);
991 static void hmp_cont_cb(void *opaque, int err)
993 if (!err) {
994 qmp_cont(NULL);
998 static bool key_is_missing(const BlockInfo *bdev)
1000 return (bdev->inserted && bdev->inserted->encryption_key_missing);
1003 void hmp_cont(Monitor *mon, const QDict *qdict)
1005 BlockInfoList *bdev_list, *bdev;
1006 Error *err = NULL;
1008 bdev_list = qmp_query_block(NULL);
1009 for (bdev = bdev_list; bdev; bdev = bdev->next) {
1010 if (key_is_missing(bdev->value)) {
1011 monitor_read_block_device_key(mon, bdev->value->device,
1012 hmp_cont_cb, NULL);
1013 goto out;
1017 qmp_cont(&err);
1018 hmp_handle_error(mon, &err);
1020 out:
1021 qapi_free_BlockInfoList(bdev_list);
1024 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1026 qmp_system_wakeup(NULL);
1029 void hmp_nmi(Monitor *mon, const QDict *qdict)
1031 Error *err = NULL;
1033 qmp_inject_nmi(&err);
1034 hmp_handle_error(mon, &err);
1037 void hmp_set_link(Monitor *mon, const QDict *qdict)
1039 const char *name = qdict_get_str(qdict, "name");
1040 bool up = qdict_get_bool(qdict, "up");
1041 Error *err = NULL;
1043 qmp_set_link(name, up, &err);
1044 hmp_handle_error(mon, &err);
1047 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1049 const char *device = qdict_get_str(qdict, "device");
1050 const char *password = qdict_get_str(qdict, "password");
1051 Error *err = NULL;
1053 qmp_block_passwd(true, device, false, NULL, password, &err);
1054 hmp_handle_error(mon, &err);
1057 void hmp_balloon(Monitor *mon, const QDict *qdict)
1059 int64_t value = qdict_get_int(qdict, "value");
1060 Error *err = NULL;
1062 qmp_balloon(value, &err);
1063 if (err) {
1064 error_report_err(err);
1068 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1070 const char *device = qdict_get_str(qdict, "device");
1071 int64_t size = qdict_get_int(qdict, "size");
1072 Error *err = NULL;
1074 qmp_block_resize(true, device, false, NULL, size, &err);
1075 hmp_handle_error(mon, &err);
1078 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1080 const char *device = qdict_get_str(qdict, "device");
1081 const char *filename = qdict_get_str(qdict, "target");
1082 const char *format = qdict_get_try_str(qdict, "format");
1083 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1084 bool full = qdict_get_try_bool(qdict, "full", false);
1085 enum NewImageMode mode;
1086 Error *err = NULL;
1088 if (!filename) {
1089 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1090 hmp_handle_error(mon, &err);
1091 return;
1094 if (reuse) {
1095 mode = NEW_IMAGE_MODE_EXISTING;
1096 } else {
1097 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1100 qmp_drive_mirror(false, NULL, device, filename, !!format, format,
1101 false, NULL, false, NULL,
1102 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1103 true, mode, false, 0, false, 0, false, 0,
1104 false, 0, false, 0, false, true, &err);
1105 hmp_handle_error(mon, &err);
1108 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1110 const char *device = qdict_get_str(qdict, "device");
1111 const char *filename = qdict_get_str(qdict, "target");
1112 const char *format = qdict_get_try_str(qdict, "format");
1113 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1114 bool full = qdict_get_try_bool(qdict, "full", false);
1115 enum NewImageMode mode;
1116 Error *err = NULL;
1118 if (!filename) {
1119 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1120 hmp_handle_error(mon, &err);
1121 return;
1124 if (reuse) {
1125 mode = NEW_IMAGE_MODE_EXISTING;
1126 } else {
1127 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1130 qmp_drive_backup(false, NULL, device, filename, !!format, format,
1131 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1132 true, mode, false, 0, false, NULL,
1133 false, 0, false, 0, &err);
1134 hmp_handle_error(mon, &err);
1137 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1139 const char *device = qdict_get_str(qdict, "device");
1140 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1141 const char *format = qdict_get_try_str(qdict, "format");
1142 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1143 enum NewImageMode mode;
1144 Error *err = NULL;
1146 if (!filename) {
1147 /* In the future, if 'snapshot-file' is not specified, the snapshot
1148 will be taken internally. Today it's actually required. */
1149 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1150 hmp_handle_error(mon, &err);
1151 return;
1154 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1155 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1156 filename, false, NULL,
1157 !!format, format,
1158 true, mode, &err);
1159 hmp_handle_error(mon, &err);
1162 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1164 const char *device = qdict_get_str(qdict, "device");
1165 const char *name = qdict_get_str(qdict, "name");
1166 Error *err = NULL;
1168 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1169 hmp_handle_error(mon, &err);
1172 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1174 const char *device = qdict_get_str(qdict, "device");
1175 const char *name = qdict_get_str(qdict, "name");
1176 const char *id = qdict_get_try_str(qdict, "id");
1177 Error *err = NULL;
1179 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1180 true, name, &err);
1181 hmp_handle_error(mon, &err);
1184 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1186 qmp_migrate_cancel(NULL);
1189 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1191 Error *err = NULL;
1192 const char *uri = qdict_get_str(qdict, "uri");
1194 qmp_migrate_incoming(uri, &err);
1196 hmp_handle_error(mon, &err);
1199 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1201 double value = qdict_get_double(qdict, "value");
1202 qmp_migrate_set_downtime(value, NULL);
1205 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1207 int64_t value = qdict_get_int(qdict, "value");
1208 Error *err = NULL;
1210 qmp_migrate_set_cache_size(value, &err);
1211 if (err) {
1212 error_report_err(err);
1213 return;
1217 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1219 int64_t value = qdict_get_int(qdict, "value");
1220 qmp_migrate_set_speed(value, NULL);
1223 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1225 const char *cap = qdict_get_str(qdict, "capability");
1226 bool state = qdict_get_bool(qdict, "state");
1227 Error *err = NULL;
1228 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1229 int i;
1231 for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
1232 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1233 caps->value = g_malloc0(sizeof(*caps->value));
1234 caps->value->capability = i;
1235 caps->value->state = state;
1236 caps->next = NULL;
1237 qmp_migrate_set_capabilities(caps, &err);
1238 break;
1242 if (i == MIGRATION_CAPABILITY__MAX) {
1243 error_setg(&err, QERR_INVALID_PARAMETER, cap);
1246 qapi_free_MigrationCapabilityStatusList(caps);
1248 if (err) {
1249 error_report_err(err);
1253 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1255 const char *param = qdict_get_str(qdict, "parameter");
1256 const char *valuestr = qdict_get_str(qdict, "value");
1257 long valueint = 0;
1258 Error *err = NULL;
1259 bool has_compress_level = false;
1260 bool has_compress_threads = false;
1261 bool has_decompress_threads = false;
1262 bool has_cpu_throttle_initial = false;
1263 bool has_cpu_throttle_increment = false;
1264 bool has_tls_creds = false;
1265 bool has_tls_hostname = false;
1266 bool use_int_value = false;
1267 int i;
1269 for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
1270 if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
1271 switch (i) {
1272 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1273 has_compress_level = true;
1274 use_int_value = true;
1275 break;
1276 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1277 has_compress_threads = true;
1278 use_int_value = true;
1279 break;
1280 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1281 has_decompress_threads = true;
1282 use_int_value = true;
1283 break;
1284 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1285 has_cpu_throttle_initial = true;
1286 use_int_value = true;
1287 break;
1288 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1289 has_cpu_throttle_increment = true;
1290 break;
1291 case MIGRATION_PARAMETER_TLS_CREDS:
1292 has_tls_creds = true;
1293 break;
1294 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1295 has_tls_hostname = true;
1296 break;
1299 if (use_int_value) {
1300 if (qemu_strtol(valuestr, NULL, 10, &valueint) < 0) {
1301 error_setg(&err, "Unable to parse '%s' as an int",
1302 valuestr);
1303 goto cleanup;
1307 qmp_migrate_set_parameters(has_compress_level, valueint,
1308 has_compress_threads, valueint,
1309 has_decompress_threads, valueint,
1310 has_cpu_throttle_initial, valueint,
1311 has_cpu_throttle_increment, valueint,
1312 has_tls_creds, valuestr,
1313 has_tls_hostname, valuestr,
1314 &err);
1315 break;
1319 if (i == MIGRATION_PARAMETER__MAX) {
1320 error_setg(&err, QERR_INVALID_PARAMETER, param);
1323 cleanup:
1324 if (err) {
1325 error_report_err(err);
1329 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1331 Error *err = NULL;
1332 const char *protocol = qdict_get_str(qdict, "protocol");
1333 const char *hostname = qdict_get_str(qdict, "hostname");
1334 bool has_port = qdict_haskey(qdict, "port");
1335 int port = qdict_get_try_int(qdict, "port", -1);
1336 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1337 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1338 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1340 qmp_client_migrate_info(protocol, hostname,
1341 has_port, port, has_tls_port, tls_port,
1342 !!cert_subject, cert_subject, &err);
1343 hmp_handle_error(mon, &err);
1346 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1348 Error *err = NULL;
1349 qmp_migrate_start_postcopy(&err);
1350 hmp_handle_error(mon, &err);
1353 void hmp_set_password(Monitor *mon, const QDict *qdict)
1355 const char *protocol = qdict_get_str(qdict, "protocol");
1356 const char *password = qdict_get_str(qdict, "password");
1357 const char *connected = qdict_get_try_str(qdict, "connected");
1358 Error *err = NULL;
1360 qmp_set_password(protocol, password, !!connected, connected, &err);
1361 hmp_handle_error(mon, &err);
1364 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1366 const char *protocol = qdict_get_str(qdict, "protocol");
1367 const char *whenstr = qdict_get_str(qdict, "time");
1368 Error *err = NULL;
1370 qmp_expire_password(protocol, whenstr, &err);
1371 hmp_handle_error(mon, &err);
1374 void hmp_eject(Monitor *mon, const QDict *qdict)
1376 bool force = qdict_get_try_bool(qdict, "force", false);
1377 const char *device = qdict_get_str(qdict, "device");
1378 Error *err = NULL;
1380 qmp_eject(device, true, force, &err);
1381 hmp_handle_error(mon, &err);
1384 static void hmp_change_read_arg(void *opaque, const char *password,
1385 void *readline_opaque)
1387 qmp_change_vnc_password(password, NULL);
1388 monitor_read_command(opaque, 1);
1391 void hmp_change(Monitor *mon, const QDict *qdict)
1393 const char *device = qdict_get_str(qdict, "device");
1394 const char *target = qdict_get_str(qdict, "target");
1395 const char *arg = qdict_get_try_str(qdict, "arg");
1396 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1397 BlockdevChangeReadOnlyMode read_only_mode = 0;
1398 Error *err = NULL;
1400 if (strcmp(device, "vnc") == 0) {
1401 if (read_only) {
1402 monitor_printf(mon,
1403 "Parameter 'read-only-mode' is invalid for VNC\n");
1404 return;
1406 if (strcmp(target, "passwd") == 0 ||
1407 strcmp(target, "password") == 0) {
1408 if (!arg) {
1409 monitor_read_password(mon, hmp_change_read_arg, NULL);
1410 return;
1413 qmp_change("vnc", target, !!arg, arg, &err);
1414 } else {
1415 if (read_only) {
1416 read_only_mode =
1417 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup,
1418 read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX,
1419 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1420 if (err) {
1421 hmp_handle_error(mon, &err);
1422 return;
1426 qmp_blockdev_change_medium(device, target, !!arg, arg,
1427 !!read_only, read_only_mode, &err);
1428 if (err &&
1429 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
1430 error_free(err);
1431 monitor_read_block_device_key(mon, device, NULL, NULL);
1432 return;
1436 hmp_handle_error(mon, &err);
1439 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1441 Error *err = NULL;
1443 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
1444 qdict_get_int(qdict, "bps"),
1445 qdict_get_int(qdict, "bps_rd"),
1446 qdict_get_int(qdict, "bps_wr"),
1447 qdict_get_int(qdict, "iops"),
1448 qdict_get_int(qdict, "iops_rd"),
1449 qdict_get_int(qdict, "iops_wr"),
1450 false, /* no burst max via HMP */
1452 false,
1454 false,
1456 false,
1458 false,
1460 false,
1462 false, /* no burst length via HMP */
1464 false,
1466 false,
1468 false,
1470 false,
1472 false,
1474 false, /* No default I/O size */
1476 false,
1477 NULL, &err);
1478 hmp_handle_error(mon, &err);
1481 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1483 Error *error = NULL;
1484 const char *device = qdict_get_str(qdict, "device");
1485 const char *base = qdict_get_try_str(qdict, "base");
1486 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1488 qmp_block_stream(false, NULL, device, base != NULL, base, false, NULL,
1489 qdict_haskey(qdict, "speed"), speed,
1490 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1492 hmp_handle_error(mon, &error);
1495 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1497 Error *error = NULL;
1498 const char *device = qdict_get_str(qdict, "device");
1499 int64_t value = qdict_get_int(qdict, "speed");
1501 qmp_block_job_set_speed(device, value, &error);
1503 hmp_handle_error(mon, &error);
1506 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1508 Error *error = NULL;
1509 const char *device = qdict_get_str(qdict, "device");
1510 bool force = qdict_get_try_bool(qdict, "force", false);
1512 qmp_block_job_cancel(device, true, force, &error);
1514 hmp_handle_error(mon, &error);
1517 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1519 Error *error = NULL;
1520 const char *device = qdict_get_str(qdict, "device");
1522 qmp_block_job_pause(device, &error);
1524 hmp_handle_error(mon, &error);
1527 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1529 Error *error = NULL;
1530 const char *device = qdict_get_str(qdict, "device");
1532 qmp_block_job_resume(device, &error);
1534 hmp_handle_error(mon, &error);
1537 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1539 Error *error = NULL;
1540 const char *device = qdict_get_str(qdict, "device");
1542 qmp_block_job_complete(device, &error);
1544 hmp_handle_error(mon, &error);
1547 typedef struct HMPMigrationStatus
1549 QEMUTimer *timer;
1550 Monitor *mon;
1551 bool is_block_migration;
1552 } HMPMigrationStatus;
1554 static void hmp_migrate_status_cb(void *opaque)
1556 HMPMigrationStatus *status = opaque;
1557 MigrationInfo *info;
1559 info = qmp_query_migrate(NULL);
1560 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1561 info->status == MIGRATION_STATUS_SETUP) {
1562 if (info->has_disk) {
1563 int progress;
1565 if (info->disk->remaining) {
1566 progress = info->disk->transferred * 100 / info->disk->total;
1567 } else {
1568 progress = 100;
1571 monitor_printf(status->mon, "Completed %d %%\r", progress);
1572 monitor_flush(status->mon);
1575 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1576 } else {
1577 if (status->is_block_migration) {
1578 monitor_printf(status->mon, "\n");
1580 if (info->has_error_desc) {
1581 error_report("%s", info->error_desc);
1583 monitor_resume(status->mon);
1584 timer_del(status->timer);
1585 g_free(status);
1588 qapi_free_MigrationInfo(info);
1591 void hmp_migrate(Monitor *mon, const QDict *qdict)
1593 bool detach = qdict_get_try_bool(qdict, "detach", false);
1594 bool blk = qdict_get_try_bool(qdict, "blk", false);
1595 bool inc = qdict_get_try_bool(qdict, "inc", false);
1596 const char *uri = qdict_get_str(qdict, "uri");
1597 Error *err = NULL;
1599 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1600 if (err) {
1601 error_report_err(err);
1602 return;
1605 if (!detach) {
1606 HMPMigrationStatus *status;
1608 if (monitor_suspend(mon) < 0) {
1609 monitor_printf(mon, "terminal does not allow synchronous "
1610 "migration, continuing detached\n");
1611 return;
1614 status = g_malloc0(sizeof(*status));
1615 status->mon = mon;
1616 status->is_block_migration = blk || inc;
1617 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1618 status);
1619 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1623 void hmp_device_add(Monitor *mon, const QDict *qdict)
1625 Error *err = NULL;
1627 qmp_device_add((QDict *)qdict, NULL, &err);
1628 hmp_handle_error(mon, &err);
1631 void hmp_device_del(Monitor *mon, const QDict *qdict)
1633 const char *id = qdict_get_str(qdict, "id");
1634 Error *err = NULL;
1636 qmp_device_del(id, &err);
1637 hmp_handle_error(mon, &err);
1640 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1642 Error *err = NULL;
1643 bool paging = qdict_get_try_bool(qdict, "paging", false);
1644 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
1645 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
1646 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
1647 const char *file = qdict_get_str(qdict, "filename");
1648 bool has_begin = qdict_haskey(qdict, "begin");
1649 bool has_length = qdict_haskey(qdict, "length");
1650 bool has_detach = qdict_haskey(qdict, "detach");
1651 int64_t begin = 0;
1652 int64_t length = 0;
1653 bool detach = false;
1654 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1655 char *prot;
1657 if (zlib + lzo + snappy > 1) {
1658 error_setg(&err, "only one of '-z|-l|-s' can be set");
1659 hmp_handle_error(mon, &err);
1660 return;
1663 if (zlib) {
1664 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1667 if (lzo) {
1668 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1671 if (snappy) {
1672 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1675 if (has_begin) {
1676 begin = qdict_get_int(qdict, "begin");
1678 if (has_length) {
1679 length = qdict_get_int(qdict, "length");
1681 if (has_detach) {
1682 detach = qdict_get_bool(qdict, "detach");
1685 prot = g_strconcat("file:", file, NULL);
1687 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
1688 has_length, length, true, dump_format, &err);
1689 hmp_handle_error(mon, &err);
1690 g_free(prot);
1693 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1695 Error *err = NULL;
1696 QemuOpts *opts;
1698 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1699 if (err) {
1700 goto out;
1703 netdev_add(opts, &err);
1704 if (err) {
1705 qemu_opts_del(opts);
1708 out:
1709 hmp_handle_error(mon, &err);
1712 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1714 const char *id = qdict_get_str(qdict, "id");
1715 Error *err = NULL;
1717 qmp_netdev_del(id, &err);
1718 hmp_handle_error(mon, &err);
1721 void hmp_object_add(Monitor *mon, const QDict *qdict)
1723 Error *err = NULL;
1724 QemuOpts *opts;
1725 Visitor *v;
1726 Object *obj = NULL;
1728 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1729 if (err) {
1730 hmp_handle_error(mon, &err);
1731 return;
1734 v = opts_visitor_new(opts);
1735 obj = user_creatable_add(qdict, v, &err);
1736 visit_free(v);
1737 qemu_opts_del(opts);
1739 if (err) {
1740 hmp_handle_error(mon, &err);
1742 if (obj) {
1743 object_unref(obj);
1747 void hmp_getfd(Monitor *mon, const QDict *qdict)
1749 const char *fdname = qdict_get_str(qdict, "fdname");
1750 Error *err = NULL;
1752 qmp_getfd(fdname, &err);
1753 hmp_handle_error(mon, &err);
1756 void hmp_closefd(Monitor *mon, const QDict *qdict)
1758 const char *fdname = qdict_get_str(qdict, "fdname");
1759 Error *err = NULL;
1761 qmp_closefd(fdname, &err);
1762 hmp_handle_error(mon, &err);
1765 void hmp_sendkey(Monitor *mon, const QDict *qdict)
1767 const char *keys = qdict_get_str(qdict, "keys");
1768 KeyValueList *keylist, *head = NULL, *tmp = NULL;
1769 int has_hold_time = qdict_haskey(qdict, "hold-time");
1770 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1771 Error *err = NULL;
1772 char *separator;
1773 int keyname_len;
1775 while (1) {
1776 separator = strchr(keys, '-');
1777 keyname_len = separator ? separator - keys : strlen(keys);
1779 /* Be compatible with old interface, convert user inputted "<" */
1780 if (keys[0] == '<' && keyname_len == 1) {
1781 keys = "less";
1782 keyname_len = 4;
1785 keylist = g_malloc0(sizeof(*keylist));
1786 keylist->value = g_malloc0(sizeof(*keylist->value));
1788 if (!head) {
1789 head = keylist;
1791 if (tmp) {
1792 tmp->next = keylist;
1794 tmp = keylist;
1796 if (strstart(keys, "0x", NULL)) {
1797 char *endp;
1798 int value = strtoul(keys, &endp, 0);
1799 assert(endp <= keys + keyname_len);
1800 if (endp != keys + keyname_len) {
1801 goto err_out;
1803 keylist->value->type = KEY_VALUE_KIND_NUMBER;
1804 keylist->value->u.number.data = value;
1805 } else {
1806 int idx = index_from_key(keys, keyname_len);
1807 if (idx == Q_KEY_CODE__MAX) {
1808 goto err_out;
1810 keylist->value->type = KEY_VALUE_KIND_QCODE;
1811 keylist->value->u.qcode.data = idx;
1814 if (!separator) {
1815 break;
1817 keys = separator + 1;
1820 qmp_send_key(head, has_hold_time, hold_time, &err);
1821 hmp_handle_error(mon, &err);
1823 out:
1824 qapi_free_KeyValueList(head);
1825 return;
1827 err_out:
1828 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
1829 goto out;
1832 void hmp_screendump(Monitor *mon, const QDict *qdict)
1834 const char *filename = qdict_get_str(qdict, "filename");
1835 Error *err = NULL;
1837 qmp_screendump(filename, &err);
1838 hmp_handle_error(mon, &err);
1841 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1843 const char *uri = qdict_get_str(qdict, "uri");
1844 bool writable = qdict_get_try_bool(qdict, "writable", false);
1845 bool all = qdict_get_try_bool(qdict, "all", false);
1846 Error *local_err = NULL;
1847 BlockInfoList *block_list, *info;
1848 SocketAddress *addr;
1850 if (writable && !all) {
1851 error_setg(&local_err, "-w only valid together with -a");
1852 goto exit;
1855 /* First check if the address is valid and start the server. */
1856 addr = socket_parse(uri, &local_err);
1857 if (local_err != NULL) {
1858 goto exit;
1861 qmp_nbd_server_start(addr, false, NULL, &local_err);
1862 qapi_free_SocketAddress(addr);
1863 if (local_err != NULL) {
1864 goto exit;
1867 if (!all) {
1868 return;
1871 /* Then try adding all block devices. If one fails, close all and
1872 * exit.
1874 block_list = qmp_query_block(NULL);
1876 for (info = block_list; info; info = info->next) {
1877 if (!info->value->has_inserted) {
1878 continue;
1881 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1883 if (local_err != NULL) {
1884 qmp_nbd_server_stop(NULL);
1885 break;
1889 qapi_free_BlockInfoList(block_list);
1891 exit:
1892 hmp_handle_error(mon, &local_err);
1895 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1897 const char *device = qdict_get_str(qdict, "device");
1898 bool writable = qdict_get_try_bool(qdict, "writable", false);
1899 Error *local_err = NULL;
1901 qmp_nbd_server_add(device, true, writable, &local_err);
1903 if (local_err != NULL) {
1904 hmp_handle_error(mon, &local_err);
1908 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1910 Error *err = NULL;
1912 qmp_nbd_server_stop(&err);
1913 hmp_handle_error(mon, &err);
1916 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
1918 int cpuid;
1919 Error *err = NULL;
1921 cpuid = qdict_get_int(qdict, "id");
1922 qmp_cpu_add(cpuid, &err);
1923 hmp_handle_error(mon, &err);
1926 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1928 const char *args = qdict_get_str(qdict, "args");
1929 Error *err = NULL;
1930 QemuOpts *opts;
1932 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
1933 if (opts == NULL) {
1934 error_setg(&err, "Parsing chardev args failed");
1935 } else {
1936 qemu_chr_new_from_opts(opts, NULL, &err);
1938 hmp_handle_error(mon, &err);
1941 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1943 Error *local_err = NULL;
1945 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1946 hmp_handle_error(mon, &local_err);
1949 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1951 BlockBackend *blk;
1952 const char* device = qdict_get_str(qdict, "device");
1953 const char* command = qdict_get_str(qdict, "command");
1954 Error *err = NULL;
1956 blk = blk_by_name(device);
1957 if (blk) {
1958 AioContext *aio_context = blk_get_aio_context(blk);
1959 aio_context_acquire(aio_context);
1961 qemuio_command(blk, command);
1963 aio_context_release(aio_context);
1964 } else {
1965 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
1966 "Device '%s' not found", device);
1969 hmp_handle_error(mon, &err);
1972 void hmp_object_del(Monitor *mon, const QDict *qdict)
1974 const char *id = qdict_get_str(qdict, "id");
1975 Error *err = NULL;
1977 user_creatable_del(id, &err);
1978 hmp_handle_error(mon, &err);
1981 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
1983 Error *err = NULL;
1984 MemdevList *memdev_list = qmp_query_memdev(&err);
1985 MemdevList *m = memdev_list;
1986 Visitor *v;
1987 char *str;
1988 int i = 0;
1991 while (m) {
1992 v = string_output_visitor_new(false, &str);
1993 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
1994 monitor_printf(mon, "memory backend: %d\n", i);
1995 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
1996 monitor_printf(mon, " merge: %s\n",
1997 m->value->merge ? "true" : "false");
1998 monitor_printf(mon, " dump: %s\n",
1999 m->value->dump ? "true" : "false");
2000 monitor_printf(mon, " prealloc: %s\n",
2001 m->value->prealloc ? "true" : "false");
2002 monitor_printf(mon, " policy: %s\n",
2003 HostMemPolicy_lookup[m->value->policy]);
2004 visit_complete(v, &str);
2005 monitor_printf(mon, " host nodes: %s\n", str);
2007 g_free(str);
2008 visit_free(v);
2009 m = m->next;
2010 i++;
2013 monitor_printf(mon, "\n");
2015 qapi_free_MemdevList(memdev_list);
2018 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2020 Error *err = NULL;
2021 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2022 MemoryDeviceInfoList *info;
2023 MemoryDeviceInfo *value;
2024 PCDIMMDeviceInfo *di;
2026 for (info = info_list; info; info = info->next) {
2027 value = info->value;
2029 if (value) {
2030 switch (value->type) {
2031 case MEMORY_DEVICE_INFO_KIND_DIMM:
2032 di = value->u.dimm.data;
2034 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2035 MemoryDeviceInfoKind_lookup[value->type],
2036 di->id ? di->id : "");
2037 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2038 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2039 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2040 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2041 monitor_printf(mon, " memdev: %s\n", di->memdev);
2042 monitor_printf(mon, " hotplugged: %s\n",
2043 di->hotplugged ? "true" : "false");
2044 monitor_printf(mon, " hotpluggable: %s\n",
2045 di->hotpluggable ? "true" : "false");
2046 break;
2047 default:
2048 break;
2053 qapi_free_MemoryDeviceInfoList(info_list);
2056 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2058 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2059 IOThreadInfoList *info;
2061 for (info = info_list; info; info = info->next) {
2062 monitor_printf(mon, "%s: thread_id=%" PRId64 "\n",
2063 info->value->id, info->value->thread_id);
2066 qapi_free_IOThreadInfoList(info_list);
2069 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2071 const char *path = qdict_get_try_str(qdict, "path");
2072 ObjectPropertyInfoList *list;
2073 Error *err = NULL;
2075 if (path == NULL) {
2076 monitor_printf(mon, "/\n");
2077 return;
2080 list = qmp_qom_list(path, &err);
2081 if (err == NULL) {
2082 ObjectPropertyInfoList *start = list;
2083 while (list != NULL) {
2084 ObjectPropertyInfo *value = list->value;
2086 monitor_printf(mon, "%s (%s)\n",
2087 value->name, value->type);
2088 list = list->next;
2090 qapi_free_ObjectPropertyInfoList(start);
2092 hmp_handle_error(mon, &err);
2095 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2097 const char *path = qdict_get_str(qdict, "path");
2098 const char *property = qdict_get_str(qdict, "property");
2099 const char *value = qdict_get_str(qdict, "value");
2100 Error *err = NULL;
2101 bool ambiguous = false;
2102 Object *obj;
2104 obj = object_resolve_path(path, &ambiguous);
2105 if (obj == NULL) {
2106 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2107 "Device '%s' not found", path);
2108 } else {
2109 if (ambiguous) {
2110 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2112 object_property_parse(obj, value, property, &err);
2114 hmp_handle_error(mon, &err);
2117 void hmp_rocker(Monitor *mon, const QDict *qdict)
2119 const char *name = qdict_get_str(qdict, "name");
2120 RockerSwitch *rocker;
2121 Error *err = NULL;
2123 rocker = qmp_query_rocker(name, &err);
2124 if (err != NULL) {
2125 hmp_handle_error(mon, &err);
2126 return;
2129 monitor_printf(mon, "name: %s\n", rocker->name);
2130 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2131 monitor_printf(mon, "ports: %d\n", rocker->ports);
2133 qapi_free_RockerSwitch(rocker);
2136 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2138 RockerPortList *list, *port;
2139 const char *name = qdict_get_str(qdict, "name");
2140 Error *err = NULL;
2142 list = qmp_query_rocker_ports(name, &err);
2143 if (err != NULL) {
2144 hmp_handle_error(mon, &err);
2145 return;
2148 monitor_printf(mon, " ena/ speed/ auto\n");
2149 monitor_printf(mon, " port link duplex neg?\n");
2151 for (port = list; port; port = port->next) {
2152 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2153 port->value->name,
2154 port->value->enabled ? port->value->link_up ?
2155 "up" : "down" : "!ena",
2156 port->value->speed == 10000 ? "10G" : "??",
2157 port->value->duplex ? "FD" : "HD",
2158 port->value->autoneg ? "Yes" : "No");
2161 qapi_free_RockerPortList(list);
2164 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2166 RockerOfDpaFlowList *list, *info;
2167 const char *name = qdict_get_str(qdict, "name");
2168 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2169 Error *err = NULL;
2171 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2172 if (err != NULL) {
2173 hmp_handle_error(mon, &err);
2174 return;
2177 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2179 for (info = list; info; info = info->next) {
2180 RockerOfDpaFlow *flow = info->value;
2181 RockerOfDpaFlowKey *key = flow->key;
2182 RockerOfDpaFlowMask *mask = flow->mask;
2183 RockerOfDpaFlowAction *action = flow->action;
2185 if (flow->hits) {
2186 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2187 key->priority, key->tbl_id, flow->hits);
2188 } else {
2189 monitor_printf(mon, "%-4d %-3d ",
2190 key->priority, key->tbl_id);
2193 if (key->has_in_pport) {
2194 monitor_printf(mon, " pport %d", key->in_pport);
2195 if (mask->has_in_pport) {
2196 monitor_printf(mon, "(0x%x)", mask->in_pport);
2200 if (key->has_vlan_id) {
2201 monitor_printf(mon, " vlan %d",
2202 key->vlan_id & VLAN_VID_MASK);
2203 if (mask->has_vlan_id) {
2204 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2208 if (key->has_tunnel_id) {
2209 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2210 if (mask->has_tunnel_id) {
2211 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2215 if (key->has_eth_type) {
2216 switch (key->eth_type) {
2217 case 0x0806:
2218 monitor_printf(mon, " ARP");
2219 break;
2220 case 0x0800:
2221 monitor_printf(mon, " IP");
2222 break;
2223 case 0x86dd:
2224 monitor_printf(mon, " IPv6");
2225 break;
2226 case 0x8809:
2227 monitor_printf(mon, " LACP");
2228 break;
2229 case 0x88cc:
2230 monitor_printf(mon, " LLDP");
2231 break;
2232 default:
2233 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2234 break;
2238 if (key->has_eth_src) {
2239 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2240 (mask->has_eth_src) &&
2241 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2242 monitor_printf(mon, " src <any mcast/bcast>");
2243 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2244 (mask->has_eth_src) &&
2245 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2246 monitor_printf(mon, " src <any ucast>");
2247 } else {
2248 monitor_printf(mon, " src %s", key->eth_src);
2249 if (mask->has_eth_src) {
2250 monitor_printf(mon, "(%s)", mask->eth_src);
2255 if (key->has_eth_dst) {
2256 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2257 (mask->has_eth_dst) &&
2258 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2259 monitor_printf(mon, " dst <any mcast/bcast>");
2260 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2261 (mask->has_eth_dst) &&
2262 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2263 monitor_printf(mon, " dst <any ucast>");
2264 } else {
2265 monitor_printf(mon, " dst %s", key->eth_dst);
2266 if (mask->has_eth_dst) {
2267 monitor_printf(mon, "(%s)", mask->eth_dst);
2272 if (key->has_ip_proto) {
2273 monitor_printf(mon, " proto %d", key->ip_proto);
2274 if (mask->has_ip_proto) {
2275 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2279 if (key->has_ip_tos) {
2280 monitor_printf(mon, " TOS %d", key->ip_tos);
2281 if (mask->has_ip_tos) {
2282 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2286 if (key->has_ip_dst) {
2287 monitor_printf(mon, " dst %s", key->ip_dst);
2290 if (action->has_goto_tbl || action->has_group_id ||
2291 action->has_new_vlan_id) {
2292 monitor_printf(mon, " -->");
2295 if (action->has_new_vlan_id) {
2296 monitor_printf(mon, " apply new vlan %d",
2297 ntohs(action->new_vlan_id));
2300 if (action->has_group_id) {
2301 monitor_printf(mon, " write group 0x%08x", action->group_id);
2304 if (action->has_goto_tbl) {
2305 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2308 monitor_printf(mon, "\n");
2311 qapi_free_RockerOfDpaFlowList(list);
2314 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2316 RockerOfDpaGroupList *list, *g;
2317 const char *name = qdict_get_str(qdict, "name");
2318 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2319 Error *err = NULL;
2320 bool set = false;
2322 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2323 if (err != NULL) {
2324 hmp_handle_error(mon, &err);
2325 return;
2328 monitor_printf(mon, "id (decode) --> buckets\n");
2330 for (g = list; g; g = g->next) {
2331 RockerOfDpaGroup *group = g->value;
2333 monitor_printf(mon, "0x%08x", group->id);
2335 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2336 group->type == 1 ? "L2 rewrite" :
2337 group->type == 2 ? "L3 unicast" :
2338 group->type == 3 ? "L2 multicast" :
2339 group->type == 4 ? "L2 flood" :
2340 group->type == 5 ? "L3 interface" :
2341 group->type == 6 ? "L3 multicast" :
2342 group->type == 7 ? "L3 ECMP" :
2343 group->type == 8 ? "L2 overlay" :
2344 "unknown");
2346 if (group->has_vlan_id) {
2347 monitor_printf(mon, " vlan %d", group->vlan_id);
2350 if (group->has_pport) {
2351 monitor_printf(mon, " pport %d", group->pport);
2354 if (group->has_index) {
2355 monitor_printf(mon, " index %d", group->index);
2358 monitor_printf(mon, ") -->");
2360 if (group->has_set_vlan_id && group->set_vlan_id) {
2361 set = true;
2362 monitor_printf(mon, " set vlan %d",
2363 group->set_vlan_id & VLAN_VID_MASK);
2366 if (group->has_set_eth_src) {
2367 if (!set) {
2368 set = true;
2369 monitor_printf(mon, " set");
2371 monitor_printf(mon, " src %s", group->set_eth_src);
2374 if (group->has_set_eth_dst) {
2375 if (!set) {
2376 set = true;
2377 monitor_printf(mon, " set");
2379 monitor_printf(mon, " dst %s", group->set_eth_dst);
2382 set = false;
2384 if (group->has_ttl_check && group->ttl_check) {
2385 monitor_printf(mon, " check TTL");
2388 if (group->has_group_id && group->group_id) {
2389 monitor_printf(mon, " group id 0x%08x", group->group_id);
2392 if (group->has_pop_vlan && group->pop_vlan) {
2393 monitor_printf(mon, " pop vlan");
2396 if (group->has_out_pport) {
2397 monitor_printf(mon, " out pport %d", group->out_pport);
2400 if (group->has_group_ids) {
2401 struct uint32List *id;
2403 monitor_printf(mon, " groups [");
2404 for (id = group->group_ids; id; id = id->next) {
2405 monitor_printf(mon, "0x%08x", id->value);
2406 if (id->next) {
2407 monitor_printf(mon, ",");
2410 monitor_printf(mon, "]");
2413 monitor_printf(mon, "\n");
2416 qapi_free_RockerOfDpaGroupList(list);
2419 void hmp_info_dump(Monitor *mon, const QDict *qdict)
2421 DumpQueryResult *result = qmp_query_dump(NULL);
2423 assert(result && result->status < DUMP_STATUS__MAX);
2424 monitor_printf(mon, "Status: %s\n", DumpStatus_lookup[result->status]);
2426 if (result->status == DUMP_STATUS_ACTIVE) {
2427 float percent = 0;
2428 assert(result->total != 0);
2429 percent = 100.0 * result->completed / result->total;
2430 monitor_printf(mon, "Finished: %.2f %%\n", percent);
2433 qapi_free_DumpQueryResult(result);
2436 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
2438 Error *err = NULL;
2439 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
2440 HotpluggableCPUList *saved = l;
2441 CpuInstanceProperties *c;
2443 if (err != NULL) {
2444 hmp_handle_error(mon, &err);
2445 return;
2448 monitor_printf(mon, "Hotpluggable CPUs:\n");
2449 while (l) {
2450 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
2451 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
2452 l->value->vcpus_count);
2453 if (l->value->has_qom_path) {
2454 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
2457 c = l->value->props;
2458 monitor_printf(mon, " CPUInstance Properties:\n");
2459 if (c->has_node_id) {
2460 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
2462 if (c->has_socket_id) {
2463 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
2465 if (c->has_core_id) {
2466 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
2468 if (c->has_thread_id) {
2469 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
2472 l = l->next;
2475 qapi_free_HotpluggableCPUList(saved);