target/s390x: Fix typo
[qemu/ar7.git] / hmp.c
blob83e287e0a4708843293ec18539ac5de1216bbe97
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/config-file.h"
23 #include "qemu/option.h"
24 #include "qemu/timer.h"
25 #include "qmp-commands.h"
26 #include "qemu/sockets.h"
27 #include "monitor/monitor.h"
28 #include "monitor/qdev.h"
29 #include "qapi/opts-visitor.h"
30 #include "qapi/qmp/qerror.h"
31 #include "qapi/string-output-visitor.h"
32 #include "qapi/util.h"
33 #include "qapi-visit.h"
34 #include "qom/object_interfaces.h"
35 #include "ui/console.h"
36 #include "block/qapi.h"
37 #include "qemu-io.h"
38 #include "qemu/cutils.h"
39 #include "qemu/error-report.h"
40 #include "hw/intc/intc.h"
42 #ifdef CONFIG_SPICE
43 #include <spice/enums.h>
44 #endif
46 static void hmp_handle_error(Monitor *mon, Error **errp)
48 assert(errp);
49 if (*errp) {
50 error_report_err(*errp);
54 void hmp_info_name(Monitor *mon, const QDict *qdict)
56 NameInfo *info;
58 info = qmp_query_name(NULL);
59 if (info->has_name) {
60 monitor_printf(mon, "%s\n", info->name);
62 qapi_free_NameInfo(info);
65 void hmp_info_version(Monitor *mon, const QDict *qdict)
67 VersionInfo *info;
69 info = qmp_query_version(NULL);
71 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
72 info->qemu->major, info->qemu->minor, info->qemu->micro,
73 info->package);
75 qapi_free_VersionInfo(info);
78 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
80 KvmInfo *info;
82 info = qmp_query_kvm(NULL);
83 monitor_printf(mon, "kvm support: ");
84 if (info->present) {
85 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
86 } else {
87 monitor_printf(mon, "not compiled\n");
90 qapi_free_KvmInfo(info);
93 void hmp_info_status(Monitor *mon, const QDict *qdict)
95 StatusInfo *info;
97 info = qmp_query_status(NULL);
99 monitor_printf(mon, "VM status: %s%s",
100 info->running ? "running" : "paused",
101 info->singlestep ? " (single step mode)" : "");
103 if (!info->running && info->status != RUN_STATE_PAUSED) {
104 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
107 monitor_printf(mon, "\n");
109 qapi_free_StatusInfo(info);
112 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
114 UuidInfo *info;
116 info = qmp_query_uuid(NULL);
117 monitor_printf(mon, "%s\n", info->UUID);
118 qapi_free_UuidInfo(info);
121 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
123 ChardevInfoList *char_info, *info;
125 char_info = qmp_query_chardev(NULL);
126 for (info = char_info; info; info = info->next) {
127 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
128 info->value->filename);
131 qapi_free_ChardevInfoList(char_info);
134 void hmp_info_mice(Monitor *mon, const QDict *qdict)
136 MouseInfoList *mice_list, *mouse;
138 mice_list = qmp_query_mice(NULL);
139 if (!mice_list) {
140 monitor_printf(mon, "No mouse devices connected\n");
141 return;
144 for (mouse = mice_list; mouse; mouse = mouse->next) {
145 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
146 mouse->value->current ? '*' : ' ',
147 mouse->value->index, mouse->value->name,
148 mouse->value->absolute ? " (absolute)" : "");
151 qapi_free_MouseInfoList(mice_list);
154 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
156 MigrationInfo *info;
157 MigrationCapabilityStatusList *caps, *cap;
159 info = qmp_query_migrate(NULL);
160 caps = qmp_query_migrate_capabilities(NULL);
162 /* do not display parameters during setup */
163 if (info->has_status && caps) {
164 monitor_printf(mon, "capabilities: ");
165 for (cap = caps; cap; cap = cap->next) {
166 monitor_printf(mon, "%s: %s ",
167 MigrationCapability_lookup[cap->value->capability],
168 cap->value->state ? "on" : "off");
170 monitor_printf(mon, "\n");
173 if (info->has_status) {
174 monitor_printf(mon, "Migration status: %s",
175 MigrationStatus_lookup[info->status]);
176 if (info->status == MIGRATION_STATUS_FAILED &&
177 info->has_error_desc) {
178 monitor_printf(mon, " (%s)\n", info->error_desc);
179 } else {
180 monitor_printf(mon, "\n");
183 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
184 info->total_time);
185 if (info->has_expected_downtime) {
186 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
187 info->expected_downtime);
189 if (info->has_downtime) {
190 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
191 info->downtime);
193 if (info->has_setup_time) {
194 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
195 info->setup_time);
199 if (info->has_ram) {
200 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
201 info->ram->transferred >> 10);
202 monitor_printf(mon, "throughput: %0.2f mbps\n",
203 info->ram->mbps);
204 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
205 info->ram->remaining >> 10);
206 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
207 info->ram->total >> 10);
208 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
209 info->ram->duplicate);
210 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
211 info->ram->skipped);
212 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
213 info->ram->normal);
214 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
215 info->ram->normal_bytes >> 10);
216 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
217 info->ram->dirty_sync_count);
218 if (info->ram->dirty_pages_rate) {
219 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
220 info->ram->dirty_pages_rate);
222 if (info->ram->postcopy_requests) {
223 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
224 info->ram->postcopy_requests);
228 if (info->has_disk) {
229 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
230 info->disk->transferred >> 10);
231 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
232 info->disk->remaining >> 10);
233 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
234 info->disk->total >> 10);
237 if (info->has_xbzrle_cache) {
238 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
239 info->xbzrle_cache->cache_size);
240 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
241 info->xbzrle_cache->bytes >> 10);
242 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
243 info->xbzrle_cache->pages);
244 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
245 info->xbzrle_cache->cache_miss);
246 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
247 info->xbzrle_cache->cache_miss_rate);
248 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
249 info->xbzrle_cache->overflow);
252 if (info->has_cpu_throttle_percentage) {
253 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
254 info->cpu_throttle_percentage);
257 qapi_free_MigrationInfo(info);
258 qapi_free_MigrationCapabilityStatusList(caps);
261 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
263 MigrationCapabilityStatusList *caps, *cap;
265 caps = qmp_query_migrate_capabilities(NULL);
267 if (caps) {
268 monitor_printf(mon, "capabilities: ");
269 for (cap = caps; cap; cap = cap->next) {
270 monitor_printf(mon, "%s: %s ",
271 MigrationCapability_lookup[cap->value->capability],
272 cap->value->state ? "on" : "off");
274 monitor_printf(mon, "\n");
277 qapi_free_MigrationCapabilityStatusList(caps);
280 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
282 MigrationParameters *params;
284 params = qmp_query_migrate_parameters(NULL);
286 if (params) {
287 monitor_printf(mon, "parameters:");
288 assert(params->has_compress_level);
289 monitor_printf(mon, " %s: %" PRId64,
290 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_LEVEL],
291 params->compress_level);
292 assert(params->has_compress_threads);
293 monitor_printf(mon, " %s: %" PRId64,
294 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_THREADS],
295 params->compress_threads);
296 assert(params->has_decompress_threads);
297 monitor_printf(mon, " %s: %" PRId64,
298 MigrationParameter_lookup[MIGRATION_PARAMETER_DECOMPRESS_THREADS],
299 params->decompress_threads);
300 assert(params->has_cpu_throttle_initial);
301 monitor_printf(mon, " %s: %" PRId64,
302 MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL],
303 params->cpu_throttle_initial);
304 assert(params->has_cpu_throttle_increment);
305 monitor_printf(mon, " %s: %" PRId64,
306 MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT],
307 params->cpu_throttle_increment);
308 monitor_printf(mon, " %s: '%s'",
309 MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_CREDS],
310 params->has_tls_creds ? params->tls_creds : "");
311 monitor_printf(mon, " %s: '%s'",
312 MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_HOSTNAME],
313 params->has_tls_hostname ? params->tls_hostname : "");
314 assert(params->has_max_bandwidth);
315 monitor_printf(mon, " %s: %" PRId64 " bytes/second",
316 MigrationParameter_lookup[MIGRATION_PARAMETER_MAX_BANDWIDTH],
317 params->max_bandwidth);
318 assert(params->has_downtime_limit);
319 monitor_printf(mon, " %s: %" PRId64 " milliseconds",
320 MigrationParameter_lookup[MIGRATION_PARAMETER_DOWNTIME_LIMIT],
321 params->downtime_limit);
322 assert(params->has_x_checkpoint_delay);
323 monitor_printf(mon, " %s: %" PRId64,
324 MigrationParameter_lookup[MIGRATION_PARAMETER_X_CHECKPOINT_DELAY],
325 params->x_checkpoint_delay);
326 monitor_printf(mon, "\n");
329 qapi_free_MigrationParameters(params);
332 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
334 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
335 qmp_query_migrate_cache_size(NULL) >> 10);
338 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
340 CpuInfoList *cpu_list, *cpu;
342 cpu_list = qmp_query_cpus(NULL);
344 for (cpu = cpu_list; cpu; cpu = cpu->next) {
345 int active = ' ';
347 if (cpu->value->CPU == monitor_get_cpu_index()) {
348 active = '*';
351 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
353 switch (cpu->value->arch) {
354 case CPU_INFO_ARCH_X86:
355 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->u.x86.pc);
356 break;
357 case CPU_INFO_ARCH_PPC:
358 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->u.ppc.nip);
359 break;
360 case CPU_INFO_ARCH_SPARC:
361 monitor_printf(mon, " pc=0x%016" PRIx64,
362 cpu->value->u.q_sparc.pc);
363 monitor_printf(mon, " npc=0x%016" PRIx64,
364 cpu->value->u.q_sparc.npc);
365 break;
366 case CPU_INFO_ARCH_MIPS:
367 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.q_mips.PC);
368 break;
369 case CPU_INFO_ARCH_TRICORE:
370 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.tricore.PC);
371 break;
372 default:
373 break;
376 if (cpu->value->halted) {
377 monitor_printf(mon, " (halted)");
380 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
383 qapi_free_CpuInfoList(cpu_list);
386 static void print_block_info(Monitor *mon, BlockInfo *info,
387 BlockDeviceInfo *inserted, bool verbose)
389 ImageInfo *image_info;
391 assert(!info || !info->has_inserted || info->inserted == inserted);
393 if (info) {
394 monitor_printf(mon, "%s", info->device);
395 if (inserted && inserted->has_node_name) {
396 monitor_printf(mon, " (%s)", inserted->node_name);
398 } else {
399 assert(inserted);
400 monitor_printf(mon, "%s",
401 inserted->has_node_name
402 ? inserted->node_name
403 : "<anonymous>");
406 if (inserted) {
407 monitor_printf(mon, ": %s (%s%s%s)\n",
408 inserted->file,
409 inserted->drv,
410 inserted->ro ? ", read-only" : "",
411 inserted->encrypted ? ", encrypted" : "");
412 } else {
413 monitor_printf(mon, ": [not inserted]\n");
416 if (info) {
417 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
418 monitor_printf(mon, " I/O status: %s\n",
419 BlockDeviceIoStatus_lookup[info->io_status]);
422 if (info->removable) {
423 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
424 info->locked ? "" : "not ",
425 info->tray_open ? "open" : "closed");
430 if (!inserted) {
431 return;
434 monitor_printf(mon, " Cache mode: %s%s%s\n",
435 inserted->cache->writeback ? "writeback" : "writethrough",
436 inserted->cache->direct ? ", direct" : "",
437 inserted->cache->no_flush ? ", ignore flushes" : "");
439 if (inserted->has_backing_file) {
440 monitor_printf(mon,
441 " Backing file: %s "
442 "(chain depth: %" PRId64 ")\n",
443 inserted->backing_file,
444 inserted->backing_file_depth);
447 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
448 monitor_printf(mon, " Detect zeroes: %s\n",
449 BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]);
452 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
453 inserted->iops || inserted->iops_rd || inserted->iops_wr)
455 monitor_printf(mon, " I/O throttling: bps=%" PRId64
456 " bps_rd=%" PRId64 " bps_wr=%" PRId64
457 " bps_max=%" PRId64
458 " bps_rd_max=%" PRId64
459 " bps_wr_max=%" PRId64
460 " iops=%" PRId64 " iops_rd=%" PRId64
461 " iops_wr=%" PRId64
462 " iops_max=%" PRId64
463 " iops_rd_max=%" PRId64
464 " iops_wr_max=%" PRId64
465 " iops_size=%" PRId64
466 " group=%s\n",
467 inserted->bps,
468 inserted->bps_rd,
469 inserted->bps_wr,
470 inserted->bps_max,
471 inserted->bps_rd_max,
472 inserted->bps_wr_max,
473 inserted->iops,
474 inserted->iops_rd,
475 inserted->iops_wr,
476 inserted->iops_max,
477 inserted->iops_rd_max,
478 inserted->iops_wr_max,
479 inserted->iops_size,
480 inserted->group);
483 if (verbose) {
484 monitor_printf(mon, "\nImages:\n");
485 image_info = inserted->image;
486 while (1) {
487 bdrv_image_info_dump((fprintf_function)monitor_printf,
488 mon, image_info);
489 if (image_info->has_backing_image) {
490 image_info = image_info->backing_image;
491 } else {
492 break;
498 void hmp_info_block(Monitor *mon, const QDict *qdict)
500 BlockInfoList *block_list, *info;
501 BlockDeviceInfoList *blockdev_list, *blockdev;
502 const char *device = qdict_get_try_str(qdict, "device");
503 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
504 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
505 bool printed = false;
507 /* Print BlockBackend information */
508 if (!nodes) {
509 block_list = qmp_query_block(NULL);
510 } else {
511 block_list = NULL;
514 for (info = block_list; info; info = info->next) {
515 if (device && strcmp(device, info->value->device)) {
516 continue;
519 if (info != block_list) {
520 monitor_printf(mon, "\n");
523 print_block_info(mon, info->value, info->value->has_inserted
524 ? info->value->inserted : NULL,
525 verbose);
526 printed = true;
529 qapi_free_BlockInfoList(block_list);
531 if ((!device && !nodes) || printed) {
532 return;
535 /* Print node information */
536 blockdev_list = qmp_query_named_block_nodes(NULL);
537 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
538 assert(blockdev->value->has_node_name);
539 if (device && strcmp(device, blockdev->value->node_name)) {
540 continue;
543 if (blockdev != blockdev_list) {
544 monitor_printf(mon, "\n");
547 print_block_info(mon, NULL, blockdev->value, verbose);
549 qapi_free_BlockDeviceInfoList(blockdev_list);
552 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
554 BlockStatsList *stats_list, *stats;
556 stats_list = qmp_query_blockstats(false, false, NULL);
558 for (stats = stats_list; stats; stats = stats->next) {
559 if (!stats->value->has_device) {
560 continue;
563 monitor_printf(mon, "%s:", stats->value->device);
564 monitor_printf(mon, " rd_bytes=%" PRId64
565 " wr_bytes=%" PRId64
566 " rd_operations=%" PRId64
567 " wr_operations=%" PRId64
568 " flush_operations=%" PRId64
569 " wr_total_time_ns=%" PRId64
570 " rd_total_time_ns=%" PRId64
571 " flush_total_time_ns=%" PRId64
572 " rd_merged=%" PRId64
573 " wr_merged=%" PRId64
574 " idle_time_ns=%" PRId64
575 "\n",
576 stats->value->stats->rd_bytes,
577 stats->value->stats->wr_bytes,
578 stats->value->stats->rd_operations,
579 stats->value->stats->wr_operations,
580 stats->value->stats->flush_operations,
581 stats->value->stats->wr_total_time_ns,
582 stats->value->stats->rd_total_time_ns,
583 stats->value->stats->flush_total_time_ns,
584 stats->value->stats->rd_merged,
585 stats->value->stats->wr_merged,
586 stats->value->stats->idle_time_ns);
589 qapi_free_BlockStatsList(stats_list);
592 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
594 VncInfo *info;
595 Error *err = NULL;
596 VncClientInfoList *client;
598 info = qmp_query_vnc(&err);
599 if (err) {
600 error_report_err(err);
601 return;
604 if (!info->enabled) {
605 monitor_printf(mon, "Server: disabled\n");
606 goto out;
609 monitor_printf(mon, "Server:\n");
610 if (info->has_host && info->has_service) {
611 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
613 if (info->has_auth) {
614 monitor_printf(mon, " auth: %s\n", info->auth);
617 if (!info->has_clients || info->clients == NULL) {
618 monitor_printf(mon, "Client: none\n");
619 } else {
620 for (client = info->clients; client; client = client->next) {
621 monitor_printf(mon, "Client:\n");
622 monitor_printf(mon, " address: %s:%s\n",
623 client->value->host,
624 client->value->service);
625 monitor_printf(mon, " x509_dname: %s\n",
626 client->value->x509_dname ?
627 client->value->x509_dname : "none");
628 monitor_printf(mon, " username: %s\n",
629 client->value->has_sasl_username ?
630 client->value->sasl_username : "none");
634 out:
635 qapi_free_VncInfo(info);
638 #ifdef CONFIG_SPICE
639 void hmp_info_spice(Monitor *mon, const QDict *qdict)
641 SpiceChannelList *chan;
642 SpiceInfo *info;
643 const char *channel_name;
644 const char * const channel_names[] = {
645 [SPICE_CHANNEL_MAIN] = "main",
646 [SPICE_CHANNEL_DISPLAY] = "display",
647 [SPICE_CHANNEL_INPUTS] = "inputs",
648 [SPICE_CHANNEL_CURSOR] = "cursor",
649 [SPICE_CHANNEL_PLAYBACK] = "playback",
650 [SPICE_CHANNEL_RECORD] = "record",
651 [SPICE_CHANNEL_TUNNEL] = "tunnel",
652 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
653 [SPICE_CHANNEL_USBREDIR] = "usbredir",
654 [SPICE_CHANNEL_PORT] = "port",
655 #if 0
656 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
657 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
658 * as quick fix for build failures with older versions. */
659 [SPICE_CHANNEL_WEBDAV] = "webdav",
660 #endif
663 info = qmp_query_spice(NULL);
665 if (!info->enabled) {
666 monitor_printf(mon, "Server: disabled\n");
667 goto out;
670 monitor_printf(mon, "Server:\n");
671 if (info->has_port) {
672 monitor_printf(mon, " address: %s:%" PRId64 "\n",
673 info->host, info->port);
675 if (info->has_tls_port) {
676 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
677 info->host, info->tls_port);
679 monitor_printf(mon, " migrated: %s\n",
680 info->migrated ? "true" : "false");
681 monitor_printf(mon, " auth: %s\n", info->auth);
682 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
683 monitor_printf(mon, " mouse-mode: %s\n",
684 SpiceQueryMouseMode_lookup[info->mouse_mode]);
686 if (!info->has_channels || info->channels == NULL) {
687 monitor_printf(mon, "Channels: none\n");
688 } else {
689 for (chan = info->channels; chan; chan = chan->next) {
690 monitor_printf(mon, "Channel:\n");
691 monitor_printf(mon, " address: %s:%s%s\n",
692 chan->value->host, chan->value->port,
693 chan->value->tls ? " [tls]" : "");
694 monitor_printf(mon, " session: %" PRId64 "\n",
695 chan->value->connection_id);
696 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
697 chan->value->channel_type, chan->value->channel_id);
699 channel_name = "unknown";
700 if (chan->value->channel_type > 0 &&
701 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
702 channel_names[chan->value->channel_type]) {
703 channel_name = channel_names[chan->value->channel_type];
706 monitor_printf(mon, " channel name: %s\n", channel_name);
710 out:
711 qapi_free_SpiceInfo(info);
713 #endif
715 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
717 BalloonInfo *info;
718 Error *err = NULL;
720 info = qmp_query_balloon(&err);
721 if (err) {
722 error_report_err(err);
723 return;
726 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
728 qapi_free_BalloonInfo(info);
731 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
733 PciMemoryRegionList *region;
735 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
736 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
737 dev->slot, dev->function);
738 monitor_printf(mon, " ");
740 if (dev->class_info->has_desc) {
741 monitor_printf(mon, "%s", dev->class_info->desc);
742 } else {
743 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
746 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
747 dev->id->vendor, dev->id->device);
749 if (dev->has_irq) {
750 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
753 if (dev->has_pci_bridge) {
754 monitor_printf(mon, " BUS %" PRId64 ".\n",
755 dev->pci_bridge->bus->number);
756 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
757 dev->pci_bridge->bus->secondary);
758 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
759 dev->pci_bridge->bus->subordinate);
761 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
762 dev->pci_bridge->bus->io_range->base,
763 dev->pci_bridge->bus->io_range->limit);
765 monitor_printf(mon,
766 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
767 dev->pci_bridge->bus->memory_range->base,
768 dev->pci_bridge->bus->memory_range->limit);
770 monitor_printf(mon, " prefetchable memory range "
771 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
772 dev->pci_bridge->bus->prefetchable_range->base,
773 dev->pci_bridge->bus->prefetchable_range->limit);
776 for (region = dev->regions; region; region = region->next) {
777 uint64_t addr, size;
779 addr = region->value->address;
780 size = region->value->size;
782 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
784 if (!strcmp(region->value->type, "io")) {
785 monitor_printf(mon, "I/O at 0x%04" PRIx64
786 " [0x%04" PRIx64 "].\n",
787 addr, addr + size - 1);
788 } else {
789 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
790 " [0x%08" PRIx64 "].\n",
791 region->value->mem_type_64 ? 64 : 32,
792 region->value->prefetch ? " prefetchable" : "",
793 addr, addr + size - 1);
797 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
799 if (dev->has_pci_bridge) {
800 if (dev->pci_bridge->has_devices) {
801 PciDeviceInfoList *cdev;
802 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
803 hmp_info_pci_device(mon, cdev->value);
809 static int hmp_info_irq_foreach(Object *obj, void *opaque)
811 InterruptStatsProvider *intc;
812 InterruptStatsProviderClass *k;
813 Monitor *mon = opaque;
815 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
816 intc = INTERRUPT_STATS_PROVIDER(obj);
817 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
818 uint64_t *irq_counts;
819 unsigned int nb_irqs, i;
820 if (k->get_statistics &&
821 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
822 if (nb_irqs > 0) {
823 monitor_printf(mon, "IRQ statistics for %s:\n",
824 object_get_typename(obj));
825 for (i = 0; i < nb_irqs; i++) {
826 if (irq_counts[i] > 0) {
827 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
828 irq_counts[i]);
832 } else {
833 monitor_printf(mon, "IRQ statistics not available for %s.\n",
834 object_get_typename(obj));
838 return 0;
841 void hmp_info_irq(Monitor *mon, const QDict *qdict)
843 object_child_foreach_recursive(object_get_root(),
844 hmp_info_irq_foreach, mon);
847 static int hmp_info_pic_foreach(Object *obj, void *opaque)
849 InterruptStatsProvider *intc;
850 InterruptStatsProviderClass *k;
851 Monitor *mon = opaque;
853 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
854 intc = INTERRUPT_STATS_PROVIDER(obj);
855 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
856 if (k->print_info) {
857 k->print_info(intc, mon);
858 } else {
859 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
860 object_get_typename(obj));
864 return 0;
867 void hmp_info_pic(Monitor *mon, const QDict *qdict)
869 object_child_foreach_recursive(object_get_root(),
870 hmp_info_pic_foreach, mon);
873 void hmp_info_pci(Monitor *mon, const QDict *qdict)
875 PciInfoList *info_list, *info;
876 Error *err = NULL;
878 info_list = qmp_query_pci(&err);
879 if (err) {
880 monitor_printf(mon, "PCI devices not supported\n");
881 error_free(err);
882 return;
885 for (info = info_list; info; info = info->next) {
886 PciDeviceInfoList *dev;
888 for (dev = info->value->devices; dev; dev = dev->next) {
889 hmp_info_pci_device(mon, dev->value);
893 qapi_free_PciInfoList(info_list);
896 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
898 BlockJobInfoList *list;
899 Error *err = NULL;
901 list = qmp_query_block_jobs(&err);
902 assert(!err);
904 if (!list) {
905 monitor_printf(mon, "No active jobs\n");
906 return;
909 while (list) {
910 if (strcmp(list->value->type, "stream") == 0) {
911 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
912 " of %" PRId64 " bytes, speed limit %" PRId64
913 " bytes/s\n",
914 list->value->device,
915 list->value->offset,
916 list->value->len,
917 list->value->speed);
918 } else {
919 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
920 " of %" PRId64 " bytes, speed limit %" PRId64
921 " bytes/s\n",
922 list->value->type,
923 list->value->device,
924 list->value->offset,
925 list->value->len,
926 list->value->speed);
928 list = list->next;
931 qapi_free_BlockJobInfoList(list);
934 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
936 TPMInfoList *info_list, *info;
937 Error *err = NULL;
938 unsigned int c = 0;
939 TPMPassthroughOptions *tpo;
941 info_list = qmp_query_tpm(&err);
942 if (err) {
943 monitor_printf(mon, "TPM device not supported\n");
944 error_free(err);
945 return;
948 if (info_list) {
949 monitor_printf(mon, "TPM device:\n");
952 for (info = info_list; info; info = info->next) {
953 TPMInfo *ti = info->value;
954 monitor_printf(mon, " tpm%d: model=%s\n",
955 c, TpmModel_lookup[ti->model]);
957 monitor_printf(mon, " \\ %s: type=%s",
958 ti->id, TpmTypeOptionsKind_lookup[ti->options->type]);
960 switch (ti->options->type) {
961 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
962 tpo = ti->options->u.passthrough.data;
963 monitor_printf(mon, "%s%s%s%s",
964 tpo->has_path ? ",path=" : "",
965 tpo->has_path ? tpo->path : "",
966 tpo->has_cancel_path ? ",cancel-path=" : "",
967 tpo->has_cancel_path ? tpo->cancel_path : "");
968 break;
969 case TPM_TYPE_OPTIONS_KIND__MAX:
970 break;
972 monitor_printf(mon, "\n");
973 c++;
975 qapi_free_TPMInfoList(info_list);
978 void hmp_quit(Monitor *mon, const QDict *qdict)
980 monitor_suspend(mon);
981 qmp_quit(NULL);
984 void hmp_stop(Monitor *mon, const QDict *qdict)
986 qmp_stop(NULL);
989 void hmp_system_reset(Monitor *mon, const QDict *qdict)
991 qmp_system_reset(NULL);
994 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
996 qmp_system_powerdown(NULL);
999 void hmp_cpu(Monitor *mon, const QDict *qdict)
1001 int64_t cpu_index;
1003 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1004 use it are converted to the QAPI */
1005 cpu_index = qdict_get_int(qdict, "index");
1006 if (monitor_set_cpu(cpu_index) < 0) {
1007 monitor_printf(mon, "invalid CPU index\n");
1011 void hmp_memsave(Monitor *mon, const QDict *qdict)
1013 uint32_t size = qdict_get_int(qdict, "size");
1014 const char *filename = qdict_get_str(qdict, "filename");
1015 uint64_t addr = qdict_get_int(qdict, "val");
1016 Error *err = NULL;
1017 int cpu_index = monitor_get_cpu_index();
1019 if (cpu_index < 0) {
1020 monitor_printf(mon, "No CPU available\n");
1021 return;
1024 qmp_memsave(addr, size, filename, true, cpu_index, &err);
1025 hmp_handle_error(mon, &err);
1028 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1030 uint32_t size = qdict_get_int(qdict, "size");
1031 const char *filename = qdict_get_str(qdict, "filename");
1032 uint64_t addr = qdict_get_int(qdict, "val");
1033 Error *err = NULL;
1035 qmp_pmemsave(addr, size, filename, &err);
1036 hmp_handle_error(mon, &err);
1039 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1041 const char *chardev = qdict_get_str(qdict, "device");
1042 const char *data = qdict_get_str(qdict, "data");
1043 Error *err = NULL;
1045 qmp_ringbuf_write(chardev, data, false, 0, &err);
1047 hmp_handle_error(mon, &err);
1050 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
1052 uint32_t size = qdict_get_int(qdict, "size");
1053 const char *chardev = qdict_get_str(qdict, "device");
1054 char *data;
1055 Error *err = NULL;
1056 int i;
1058 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1059 if (err) {
1060 error_report_err(err);
1061 return;
1064 for (i = 0; data[i]; i++) {
1065 unsigned char ch = data[i];
1067 if (ch == '\\') {
1068 monitor_printf(mon, "\\\\");
1069 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1070 monitor_printf(mon, "\\u%04X", ch);
1071 } else {
1072 monitor_printf(mon, "%c", ch);
1076 monitor_printf(mon, "\n");
1077 g_free(data);
1080 static void hmp_cont_cb(void *opaque, int err)
1082 if (!err) {
1083 qmp_cont(NULL);
1087 static bool key_is_missing(const BlockInfo *bdev)
1089 return (bdev->inserted && bdev->inserted->encryption_key_missing);
1092 void hmp_cont(Monitor *mon, const QDict *qdict)
1094 BlockInfoList *bdev_list, *bdev;
1095 Error *err = NULL;
1097 bdev_list = qmp_query_block(NULL);
1098 for (bdev = bdev_list; bdev; bdev = bdev->next) {
1099 if (key_is_missing(bdev->value)) {
1100 monitor_read_block_device_key(mon, bdev->value->device,
1101 hmp_cont_cb, NULL);
1102 goto out;
1106 qmp_cont(&err);
1107 hmp_handle_error(mon, &err);
1109 out:
1110 qapi_free_BlockInfoList(bdev_list);
1113 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1115 qmp_system_wakeup(NULL);
1118 void hmp_nmi(Monitor *mon, const QDict *qdict)
1120 Error *err = NULL;
1122 qmp_inject_nmi(&err);
1123 hmp_handle_error(mon, &err);
1126 void hmp_set_link(Monitor *mon, const QDict *qdict)
1128 const char *name = qdict_get_str(qdict, "name");
1129 bool up = qdict_get_bool(qdict, "up");
1130 Error *err = NULL;
1132 qmp_set_link(name, up, &err);
1133 hmp_handle_error(mon, &err);
1136 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1138 const char *device = qdict_get_str(qdict, "device");
1139 const char *password = qdict_get_str(qdict, "password");
1140 Error *err = NULL;
1142 qmp_block_passwd(true, device, false, NULL, password, &err);
1143 hmp_handle_error(mon, &err);
1146 void hmp_balloon(Monitor *mon, const QDict *qdict)
1148 int64_t value = qdict_get_int(qdict, "value");
1149 Error *err = NULL;
1151 qmp_balloon(value, &err);
1152 if (err) {
1153 error_report_err(err);
1157 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1159 const char *device = qdict_get_str(qdict, "device");
1160 int64_t size = qdict_get_int(qdict, "size");
1161 Error *err = NULL;
1163 qmp_block_resize(true, device, false, NULL, size, &err);
1164 hmp_handle_error(mon, &err);
1167 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1169 const char *filename = qdict_get_str(qdict, "target");
1170 const char *format = qdict_get_try_str(qdict, "format");
1171 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1172 bool full = qdict_get_try_bool(qdict, "full", false);
1173 Error *err = NULL;
1174 DriveMirror mirror = {
1175 .device = (char *)qdict_get_str(qdict, "device"),
1176 .target = (char *)filename,
1177 .has_format = !!format,
1178 .format = (char *)format,
1179 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1180 .has_mode = true,
1181 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1182 .unmap = true,
1185 if (!filename) {
1186 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1187 hmp_handle_error(mon, &err);
1188 return;
1190 qmp_drive_mirror(&mirror, &err);
1191 hmp_handle_error(mon, &err);
1194 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1196 const char *device = qdict_get_str(qdict, "device");
1197 const char *filename = qdict_get_str(qdict, "target");
1198 const char *format = qdict_get_try_str(qdict, "format");
1199 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1200 bool full = qdict_get_try_bool(qdict, "full", false);
1201 bool compress = qdict_get_try_bool(qdict, "compress", false);
1202 Error *err = NULL;
1203 DriveBackup backup = {
1204 .device = (char *)device,
1205 .target = (char *)filename,
1206 .has_format = !!format,
1207 .format = (char *)format,
1208 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1209 .has_mode = true,
1210 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1211 .has_compress = !!compress,
1212 .compress = compress,
1215 if (!filename) {
1216 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1217 hmp_handle_error(mon, &err);
1218 return;
1221 qmp_drive_backup(&backup, &err);
1222 hmp_handle_error(mon, &err);
1225 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1227 const char *device = qdict_get_str(qdict, "device");
1228 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1229 const char *format = qdict_get_try_str(qdict, "format");
1230 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1231 enum NewImageMode mode;
1232 Error *err = NULL;
1234 if (!filename) {
1235 /* In the future, if 'snapshot-file' is not specified, the snapshot
1236 will be taken internally. Today it's actually required. */
1237 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1238 hmp_handle_error(mon, &err);
1239 return;
1242 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1243 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1244 filename, false, NULL,
1245 !!format, format,
1246 true, mode, &err);
1247 hmp_handle_error(mon, &err);
1250 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1252 const char *device = qdict_get_str(qdict, "device");
1253 const char *name = qdict_get_str(qdict, "name");
1254 Error *err = NULL;
1256 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1257 hmp_handle_error(mon, &err);
1260 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1262 const char *device = qdict_get_str(qdict, "device");
1263 const char *name = qdict_get_str(qdict, "name");
1264 const char *id = qdict_get_try_str(qdict, "id");
1265 Error *err = NULL;
1267 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1268 true, name, &err);
1269 hmp_handle_error(mon, &err);
1272 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1274 qmp_migrate_cancel(NULL);
1277 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1279 Error *err = NULL;
1280 const char *uri = qdict_get_str(qdict, "uri");
1282 qmp_migrate_incoming(uri, &err);
1284 hmp_handle_error(mon, &err);
1287 /* Kept for backwards compatibility */
1288 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1290 double value = qdict_get_double(qdict, "value");
1291 qmp_migrate_set_downtime(value, NULL);
1294 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1296 int64_t value = qdict_get_int(qdict, "value");
1297 Error *err = NULL;
1299 qmp_migrate_set_cache_size(value, &err);
1300 if (err) {
1301 error_report_err(err);
1302 return;
1306 /* Kept for backwards compatibility */
1307 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1309 int64_t value = qdict_get_int(qdict, "value");
1310 qmp_migrate_set_speed(value, NULL);
1313 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1315 const char *cap = qdict_get_str(qdict, "capability");
1316 bool state = qdict_get_bool(qdict, "state");
1317 Error *err = NULL;
1318 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1319 int i;
1321 for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
1322 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1323 caps->value = g_malloc0(sizeof(*caps->value));
1324 caps->value->capability = i;
1325 caps->value->state = state;
1326 caps->next = NULL;
1327 qmp_migrate_set_capabilities(caps, &err);
1328 break;
1332 if (i == MIGRATION_CAPABILITY__MAX) {
1333 error_setg(&err, QERR_INVALID_PARAMETER, cap);
1336 qapi_free_MigrationCapabilityStatusList(caps);
1338 if (err) {
1339 error_report_err(err);
1343 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1345 const char *param = qdict_get_str(qdict, "parameter");
1346 const char *valuestr = qdict_get_str(qdict, "value");
1347 uint64_t valuebw = 0;
1348 long valueint = 0;
1349 Error *err = NULL;
1350 bool use_int_value = false;
1351 int i, ret;
1353 for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
1354 if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
1355 MigrationParameters p = { 0 };
1356 switch (i) {
1357 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1358 p.has_compress_level = true;
1359 use_int_value = true;
1360 break;
1361 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1362 p.has_compress_threads = true;
1363 use_int_value = true;
1364 break;
1365 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1366 p.has_decompress_threads = true;
1367 use_int_value = true;
1368 break;
1369 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1370 p.has_cpu_throttle_initial = true;
1371 use_int_value = true;
1372 break;
1373 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1374 p.has_cpu_throttle_increment = true;
1375 use_int_value = true;
1376 break;
1377 case MIGRATION_PARAMETER_TLS_CREDS:
1378 p.has_tls_creds = true;
1379 p.tls_creds = (char *) valuestr;
1380 break;
1381 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1382 p.has_tls_hostname = true;
1383 p.tls_hostname = (char *) valuestr;
1384 break;
1385 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1386 p.has_max_bandwidth = true;
1387 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1388 if (ret < 0 || valuebw > INT64_MAX
1389 || (size_t)valuebw != valuebw) {
1390 error_setg(&err, "Invalid size %s", valuestr);
1391 goto cleanup;
1393 p.max_bandwidth = valuebw;
1394 break;
1395 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1396 p.has_downtime_limit = true;
1397 use_int_value = true;
1398 break;
1399 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1400 p.has_x_checkpoint_delay = true;
1401 use_int_value = true;
1402 break;
1405 if (use_int_value) {
1406 if (qemu_strtol(valuestr, NULL, 10, &valueint) < 0) {
1407 error_setg(&err, "Unable to parse '%s' as an int",
1408 valuestr);
1409 goto cleanup;
1411 /* Set all integers; only one has_FOO will be set, and
1412 * the code ignores the remaining values */
1413 p.compress_level = valueint;
1414 p.compress_threads = valueint;
1415 p.decompress_threads = valueint;
1416 p.cpu_throttle_initial = valueint;
1417 p.cpu_throttle_increment = valueint;
1418 p.downtime_limit = valueint;
1419 p.x_checkpoint_delay = valueint;
1422 qmp_migrate_set_parameters(&p, &err);
1423 break;
1427 if (i == MIGRATION_PARAMETER__MAX) {
1428 error_setg(&err, QERR_INVALID_PARAMETER, param);
1431 cleanup:
1432 if (err) {
1433 error_report_err(err);
1437 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1439 Error *err = NULL;
1440 const char *protocol = qdict_get_str(qdict, "protocol");
1441 const char *hostname = qdict_get_str(qdict, "hostname");
1442 bool has_port = qdict_haskey(qdict, "port");
1443 int port = qdict_get_try_int(qdict, "port", -1);
1444 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1445 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1446 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1448 qmp_client_migrate_info(protocol, hostname,
1449 has_port, port, has_tls_port, tls_port,
1450 !!cert_subject, cert_subject, &err);
1451 hmp_handle_error(mon, &err);
1454 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1456 Error *err = NULL;
1457 qmp_migrate_start_postcopy(&err);
1458 hmp_handle_error(mon, &err);
1461 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1463 Error *err = NULL;
1465 qmp_x_colo_lost_heartbeat(&err);
1466 hmp_handle_error(mon, &err);
1469 void hmp_set_password(Monitor *mon, const QDict *qdict)
1471 const char *protocol = qdict_get_str(qdict, "protocol");
1472 const char *password = qdict_get_str(qdict, "password");
1473 const char *connected = qdict_get_try_str(qdict, "connected");
1474 Error *err = NULL;
1476 qmp_set_password(protocol, password, !!connected, connected, &err);
1477 hmp_handle_error(mon, &err);
1480 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1482 const char *protocol = qdict_get_str(qdict, "protocol");
1483 const char *whenstr = qdict_get_str(qdict, "time");
1484 Error *err = NULL;
1486 qmp_expire_password(protocol, whenstr, &err);
1487 hmp_handle_error(mon, &err);
1490 void hmp_eject(Monitor *mon, const QDict *qdict)
1492 bool force = qdict_get_try_bool(qdict, "force", false);
1493 const char *device = qdict_get_str(qdict, "device");
1494 Error *err = NULL;
1496 qmp_eject(true, device, false, NULL, true, force, &err);
1497 hmp_handle_error(mon, &err);
1500 static void hmp_change_read_arg(void *opaque, const char *password,
1501 void *readline_opaque)
1503 qmp_change_vnc_password(password, NULL);
1504 monitor_read_command(opaque, 1);
1507 void hmp_change(Monitor *mon, const QDict *qdict)
1509 const char *device = qdict_get_str(qdict, "device");
1510 const char *target = qdict_get_str(qdict, "target");
1511 const char *arg = qdict_get_try_str(qdict, "arg");
1512 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1513 BlockdevChangeReadOnlyMode read_only_mode = 0;
1514 Error *err = NULL;
1516 if (strcmp(device, "vnc") == 0) {
1517 if (read_only) {
1518 monitor_printf(mon,
1519 "Parameter 'read-only-mode' is invalid for VNC\n");
1520 return;
1522 if (strcmp(target, "passwd") == 0 ||
1523 strcmp(target, "password") == 0) {
1524 if (!arg) {
1525 monitor_read_password(mon, hmp_change_read_arg, NULL);
1526 return;
1529 qmp_change("vnc", target, !!arg, arg, &err);
1530 } else {
1531 if (read_only) {
1532 read_only_mode =
1533 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup,
1534 read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX,
1535 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1536 if (err) {
1537 hmp_handle_error(mon, &err);
1538 return;
1542 qmp_blockdev_change_medium(true, device, false, NULL, target,
1543 !!arg, arg, !!read_only, read_only_mode,
1544 &err);
1545 if (err &&
1546 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
1547 error_free(err);
1548 monitor_read_block_device_key(mon, device, NULL, NULL);
1549 return;
1553 hmp_handle_error(mon, &err);
1556 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1558 Error *err = NULL;
1559 BlockIOThrottle throttle = {
1560 .has_device = true,
1561 .device = (char *) qdict_get_str(qdict, "device"),
1562 .bps = qdict_get_int(qdict, "bps"),
1563 .bps_rd = qdict_get_int(qdict, "bps_rd"),
1564 .bps_wr = qdict_get_int(qdict, "bps_wr"),
1565 .iops = qdict_get_int(qdict, "iops"),
1566 .iops_rd = qdict_get_int(qdict, "iops_rd"),
1567 .iops_wr = qdict_get_int(qdict, "iops_wr"),
1570 qmp_block_set_io_throttle(&throttle, &err);
1571 hmp_handle_error(mon, &err);
1574 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1576 Error *error = NULL;
1577 const char *device = qdict_get_str(qdict, "device");
1578 const char *base = qdict_get_try_str(qdict, "base");
1579 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1581 qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
1582 false, NULL, qdict_haskey(qdict, "speed"), speed,
1583 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1585 hmp_handle_error(mon, &error);
1588 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1590 Error *error = NULL;
1591 const char *device = qdict_get_str(qdict, "device");
1592 int64_t value = qdict_get_int(qdict, "speed");
1594 qmp_block_job_set_speed(device, value, &error);
1596 hmp_handle_error(mon, &error);
1599 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1601 Error *error = NULL;
1602 const char *device = qdict_get_str(qdict, "device");
1603 bool force = qdict_get_try_bool(qdict, "force", false);
1605 qmp_block_job_cancel(device, true, force, &error);
1607 hmp_handle_error(mon, &error);
1610 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1612 Error *error = NULL;
1613 const char *device = qdict_get_str(qdict, "device");
1615 qmp_block_job_pause(device, &error);
1617 hmp_handle_error(mon, &error);
1620 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1622 Error *error = NULL;
1623 const char *device = qdict_get_str(qdict, "device");
1625 qmp_block_job_resume(device, &error);
1627 hmp_handle_error(mon, &error);
1630 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1632 Error *error = NULL;
1633 const char *device = qdict_get_str(qdict, "device");
1635 qmp_block_job_complete(device, &error);
1637 hmp_handle_error(mon, &error);
1640 typedef struct HMPMigrationStatus
1642 QEMUTimer *timer;
1643 Monitor *mon;
1644 bool is_block_migration;
1645 } HMPMigrationStatus;
1647 static void hmp_migrate_status_cb(void *opaque)
1649 HMPMigrationStatus *status = opaque;
1650 MigrationInfo *info;
1652 info = qmp_query_migrate(NULL);
1653 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1654 info->status == MIGRATION_STATUS_SETUP) {
1655 if (info->has_disk) {
1656 int progress;
1658 if (info->disk->remaining) {
1659 progress = info->disk->transferred * 100 / info->disk->total;
1660 } else {
1661 progress = 100;
1664 monitor_printf(status->mon, "Completed %d %%\r", progress);
1665 monitor_flush(status->mon);
1668 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1669 } else {
1670 if (status->is_block_migration) {
1671 monitor_printf(status->mon, "\n");
1673 if (info->has_error_desc) {
1674 error_report("%s", info->error_desc);
1676 monitor_resume(status->mon);
1677 timer_del(status->timer);
1678 g_free(status);
1681 qapi_free_MigrationInfo(info);
1684 void hmp_migrate(Monitor *mon, const QDict *qdict)
1686 bool detach = qdict_get_try_bool(qdict, "detach", false);
1687 bool blk = qdict_get_try_bool(qdict, "blk", false);
1688 bool inc = qdict_get_try_bool(qdict, "inc", false);
1689 const char *uri = qdict_get_str(qdict, "uri");
1690 Error *err = NULL;
1692 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1693 if (err) {
1694 error_report_err(err);
1695 return;
1698 if (!detach) {
1699 HMPMigrationStatus *status;
1701 if (monitor_suspend(mon) < 0) {
1702 monitor_printf(mon, "terminal does not allow synchronous "
1703 "migration, continuing detached\n");
1704 return;
1707 status = g_malloc0(sizeof(*status));
1708 status->mon = mon;
1709 status->is_block_migration = blk || inc;
1710 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1711 status);
1712 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1716 void hmp_device_add(Monitor *mon, const QDict *qdict)
1718 Error *err = NULL;
1720 qmp_device_add((QDict *)qdict, NULL, &err);
1721 hmp_handle_error(mon, &err);
1724 void hmp_device_del(Monitor *mon, const QDict *qdict)
1726 const char *id = qdict_get_str(qdict, "id");
1727 Error *err = NULL;
1729 qmp_device_del(id, &err);
1730 hmp_handle_error(mon, &err);
1733 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1735 Error *err = NULL;
1736 bool paging = qdict_get_try_bool(qdict, "paging", false);
1737 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
1738 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
1739 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
1740 const char *file = qdict_get_str(qdict, "filename");
1741 bool has_begin = qdict_haskey(qdict, "begin");
1742 bool has_length = qdict_haskey(qdict, "length");
1743 bool has_detach = qdict_haskey(qdict, "detach");
1744 int64_t begin = 0;
1745 int64_t length = 0;
1746 bool detach = false;
1747 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1748 char *prot;
1750 if (zlib + lzo + snappy > 1) {
1751 error_setg(&err, "only one of '-z|-l|-s' can be set");
1752 hmp_handle_error(mon, &err);
1753 return;
1756 if (zlib) {
1757 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1760 if (lzo) {
1761 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1764 if (snappy) {
1765 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1768 if (has_begin) {
1769 begin = qdict_get_int(qdict, "begin");
1771 if (has_length) {
1772 length = qdict_get_int(qdict, "length");
1774 if (has_detach) {
1775 detach = qdict_get_bool(qdict, "detach");
1778 prot = g_strconcat("file:", file, NULL);
1780 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
1781 has_length, length, true, dump_format, &err);
1782 hmp_handle_error(mon, &err);
1783 g_free(prot);
1786 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1788 Error *err = NULL;
1789 QemuOpts *opts;
1791 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1792 if (err) {
1793 goto out;
1796 netdev_add(opts, &err);
1797 if (err) {
1798 qemu_opts_del(opts);
1801 out:
1802 hmp_handle_error(mon, &err);
1805 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1807 const char *id = qdict_get_str(qdict, "id");
1808 Error *err = NULL;
1810 qmp_netdev_del(id, &err);
1811 hmp_handle_error(mon, &err);
1814 void hmp_object_add(Monitor *mon, const QDict *qdict)
1816 Error *err = NULL;
1817 QemuOpts *opts;
1818 Object *obj = NULL;
1820 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1821 if (err) {
1822 hmp_handle_error(mon, &err);
1823 return;
1826 obj = user_creatable_add_opts(opts, &err);
1827 qemu_opts_del(opts);
1829 if (err) {
1830 hmp_handle_error(mon, &err);
1832 if (obj) {
1833 object_unref(obj);
1837 void hmp_getfd(Monitor *mon, const QDict *qdict)
1839 const char *fdname = qdict_get_str(qdict, "fdname");
1840 Error *err = NULL;
1842 qmp_getfd(fdname, &err);
1843 hmp_handle_error(mon, &err);
1846 void hmp_closefd(Monitor *mon, const QDict *qdict)
1848 const char *fdname = qdict_get_str(qdict, "fdname");
1849 Error *err = NULL;
1851 qmp_closefd(fdname, &err);
1852 hmp_handle_error(mon, &err);
1855 void hmp_sendkey(Monitor *mon, const QDict *qdict)
1857 const char *keys = qdict_get_str(qdict, "keys");
1858 KeyValueList *keylist, *head = NULL, *tmp = NULL;
1859 int has_hold_time = qdict_haskey(qdict, "hold-time");
1860 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1861 Error *err = NULL;
1862 char *separator;
1863 int keyname_len;
1865 while (1) {
1866 separator = strchr(keys, '-');
1867 keyname_len = separator ? separator - keys : strlen(keys);
1869 /* Be compatible with old interface, convert user inputted "<" */
1870 if (keys[0] == '<' && keyname_len == 1) {
1871 keys = "less";
1872 keyname_len = 4;
1875 keylist = g_malloc0(sizeof(*keylist));
1876 keylist->value = g_malloc0(sizeof(*keylist->value));
1878 if (!head) {
1879 head = keylist;
1881 if (tmp) {
1882 tmp->next = keylist;
1884 tmp = keylist;
1886 if (strstart(keys, "0x", NULL)) {
1887 char *endp;
1888 int value = strtoul(keys, &endp, 0);
1889 assert(endp <= keys + keyname_len);
1890 if (endp != keys + keyname_len) {
1891 goto err_out;
1893 keylist->value->type = KEY_VALUE_KIND_NUMBER;
1894 keylist->value->u.number.data = value;
1895 } else {
1896 int idx = index_from_key(keys, keyname_len);
1897 if (idx == Q_KEY_CODE__MAX) {
1898 goto err_out;
1900 keylist->value->type = KEY_VALUE_KIND_QCODE;
1901 keylist->value->u.qcode.data = idx;
1904 if (!separator) {
1905 break;
1907 keys = separator + 1;
1910 qmp_send_key(head, has_hold_time, hold_time, &err);
1911 hmp_handle_error(mon, &err);
1913 out:
1914 qapi_free_KeyValueList(head);
1915 return;
1917 err_out:
1918 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
1919 goto out;
1922 void hmp_screendump(Monitor *mon, const QDict *qdict)
1924 const char *filename = qdict_get_str(qdict, "filename");
1925 Error *err = NULL;
1927 qmp_screendump(filename, &err);
1928 hmp_handle_error(mon, &err);
1931 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1933 const char *uri = qdict_get_str(qdict, "uri");
1934 bool writable = qdict_get_try_bool(qdict, "writable", false);
1935 bool all = qdict_get_try_bool(qdict, "all", false);
1936 Error *local_err = NULL;
1937 BlockInfoList *block_list, *info;
1938 SocketAddress *addr;
1940 if (writable && !all) {
1941 error_setg(&local_err, "-w only valid together with -a");
1942 goto exit;
1945 /* First check if the address is valid and start the server. */
1946 addr = socket_parse(uri, &local_err);
1947 if (local_err != NULL) {
1948 goto exit;
1951 qmp_nbd_server_start(addr, false, NULL, &local_err);
1952 qapi_free_SocketAddress(addr);
1953 if (local_err != NULL) {
1954 goto exit;
1957 if (!all) {
1958 return;
1961 /* Then try adding all block devices. If one fails, close all and
1962 * exit.
1964 block_list = qmp_query_block(NULL);
1966 for (info = block_list; info; info = info->next) {
1967 if (!info->value->has_inserted) {
1968 continue;
1971 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1973 if (local_err != NULL) {
1974 qmp_nbd_server_stop(NULL);
1975 break;
1979 qapi_free_BlockInfoList(block_list);
1981 exit:
1982 hmp_handle_error(mon, &local_err);
1985 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1987 const char *device = qdict_get_str(qdict, "device");
1988 bool writable = qdict_get_try_bool(qdict, "writable", false);
1989 Error *local_err = NULL;
1991 qmp_nbd_server_add(device, true, writable, &local_err);
1993 if (local_err != NULL) {
1994 hmp_handle_error(mon, &local_err);
1998 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
2000 Error *err = NULL;
2002 qmp_nbd_server_stop(&err);
2003 hmp_handle_error(mon, &err);
2006 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
2008 int cpuid;
2009 Error *err = NULL;
2011 cpuid = qdict_get_int(qdict, "id");
2012 qmp_cpu_add(cpuid, &err);
2013 hmp_handle_error(mon, &err);
2016 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2018 const char *args = qdict_get_str(qdict, "args");
2019 Error *err = NULL;
2020 QemuOpts *opts;
2022 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
2023 if (opts == NULL) {
2024 error_setg(&err, "Parsing chardev args failed");
2025 } else {
2026 qemu_chr_new_from_opts(opts, &err);
2027 qemu_opts_del(opts);
2029 hmp_handle_error(mon, &err);
2032 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2034 Error *local_err = NULL;
2036 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
2037 hmp_handle_error(mon, &local_err);
2040 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
2042 BlockBackend *blk;
2043 BlockBackend *local_blk = NULL;
2044 AioContext *aio_context;
2045 const char* device = qdict_get_str(qdict, "device");
2046 const char* command = qdict_get_str(qdict, "command");
2047 Error *err = NULL;
2049 blk = blk_by_name(device);
2050 if (!blk) {
2051 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
2052 if (bs) {
2053 blk = local_blk = blk_new();
2054 blk_insert_bs(blk, bs);
2055 } else {
2056 goto fail;
2060 aio_context = blk_get_aio_context(blk);
2061 aio_context_acquire(aio_context);
2063 qemuio_command(blk, command);
2065 aio_context_release(aio_context);
2067 fail:
2068 blk_unref(local_blk);
2069 hmp_handle_error(mon, &err);
2072 void hmp_object_del(Monitor *mon, const QDict *qdict)
2074 const char *id = qdict_get_str(qdict, "id");
2075 Error *err = NULL;
2077 user_creatable_del(id, &err);
2078 hmp_handle_error(mon, &err);
2081 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
2083 Error *err = NULL;
2084 MemdevList *memdev_list = qmp_query_memdev(&err);
2085 MemdevList *m = memdev_list;
2086 Visitor *v;
2087 char *str;
2089 while (m) {
2090 v = string_output_visitor_new(false, &str);
2091 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
2092 monitor_printf(mon, "memory backend: %s\n", m->value->id);
2093 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
2094 monitor_printf(mon, " merge: %s\n",
2095 m->value->merge ? "true" : "false");
2096 monitor_printf(mon, " dump: %s\n",
2097 m->value->dump ? "true" : "false");
2098 monitor_printf(mon, " prealloc: %s\n",
2099 m->value->prealloc ? "true" : "false");
2100 monitor_printf(mon, " policy: %s\n",
2101 HostMemPolicy_lookup[m->value->policy]);
2102 visit_complete(v, &str);
2103 monitor_printf(mon, " host nodes: %s\n", str);
2105 g_free(str);
2106 visit_free(v);
2107 m = m->next;
2110 monitor_printf(mon, "\n");
2112 qapi_free_MemdevList(memdev_list);
2115 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2117 Error *err = NULL;
2118 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2119 MemoryDeviceInfoList *info;
2120 MemoryDeviceInfo *value;
2121 PCDIMMDeviceInfo *di;
2123 for (info = info_list; info; info = info->next) {
2124 value = info->value;
2126 if (value) {
2127 switch (value->type) {
2128 case MEMORY_DEVICE_INFO_KIND_DIMM:
2129 di = value->u.dimm.data;
2131 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2132 MemoryDeviceInfoKind_lookup[value->type],
2133 di->id ? di->id : "");
2134 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2135 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2136 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2137 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2138 monitor_printf(mon, " memdev: %s\n", di->memdev);
2139 monitor_printf(mon, " hotplugged: %s\n",
2140 di->hotplugged ? "true" : "false");
2141 monitor_printf(mon, " hotpluggable: %s\n",
2142 di->hotpluggable ? "true" : "false");
2143 break;
2144 default:
2145 break;
2150 qapi_free_MemoryDeviceInfoList(info_list);
2153 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2155 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2156 IOThreadInfoList *info;
2157 IOThreadInfo *value;
2159 for (info = info_list; info; info = info->next) {
2160 value = info->value;
2161 monitor_printf(mon, "%s:\n", value->id);
2162 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
2163 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2164 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
2165 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
2168 qapi_free_IOThreadInfoList(info_list);
2171 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2173 const char *path = qdict_get_try_str(qdict, "path");
2174 ObjectPropertyInfoList *list;
2175 Error *err = NULL;
2177 if (path == NULL) {
2178 monitor_printf(mon, "/\n");
2179 return;
2182 list = qmp_qom_list(path, &err);
2183 if (err == NULL) {
2184 ObjectPropertyInfoList *start = list;
2185 while (list != NULL) {
2186 ObjectPropertyInfo *value = list->value;
2188 monitor_printf(mon, "%s (%s)\n",
2189 value->name, value->type);
2190 list = list->next;
2192 qapi_free_ObjectPropertyInfoList(start);
2194 hmp_handle_error(mon, &err);
2197 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2199 const char *path = qdict_get_str(qdict, "path");
2200 const char *property = qdict_get_str(qdict, "property");
2201 const char *value = qdict_get_str(qdict, "value");
2202 Error *err = NULL;
2203 bool ambiguous = false;
2204 Object *obj;
2206 obj = object_resolve_path(path, &ambiguous);
2207 if (obj == NULL) {
2208 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2209 "Device '%s' not found", path);
2210 } else {
2211 if (ambiguous) {
2212 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2214 object_property_parse(obj, value, property, &err);
2216 hmp_handle_error(mon, &err);
2219 void hmp_rocker(Monitor *mon, const QDict *qdict)
2221 const char *name = qdict_get_str(qdict, "name");
2222 RockerSwitch *rocker;
2223 Error *err = NULL;
2225 rocker = qmp_query_rocker(name, &err);
2226 if (err != NULL) {
2227 hmp_handle_error(mon, &err);
2228 return;
2231 monitor_printf(mon, "name: %s\n", rocker->name);
2232 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2233 monitor_printf(mon, "ports: %d\n", rocker->ports);
2235 qapi_free_RockerSwitch(rocker);
2238 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2240 RockerPortList *list, *port;
2241 const char *name = qdict_get_str(qdict, "name");
2242 Error *err = NULL;
2244 list = qmp_query_rocker_ports(name, &err);
2245 if (err != NULL) {
2246 hmp_handle_error(mon, &err);
2247 return;
2250 monitor_printf(mon, " ena/ speed/ auto\n");
2251 monitor_printf(mon, " port link duplex neg?\n");
2253 for (port = list; port; port = port->next) {
2254 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2255 port->value->name,
2256 port->value->enabled ? port->value->link_up ?
2257 "up" : "down" : "!ena",
2258 port->value->speed == 10000 ? "10G" : "??",
2259 port->value->duplex ? "FD" : "HD",
2260 port->value->autoneg ? "Yes" : "No");
2263 qapi_free_RockerPortList(list);
2266 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2268 RockerOfDpaFlowList *list, *info;
2269 const char *name = qdict_get_str(qdict, "name");
2270 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2271 Error *err = NULL;
2273 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2274 if (err != NULL) {
2275 hmp_handle_error(mon, &err);
2276 return;
2279 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2281 for (info = list; info; info = info->next) {
2282 RockerOfDpaFlow *flow = info->value;
2283 RockerOfDpaFlowKey *key = flow->key;
2284 RockerOfDpaFlowMask *mask = flow->mask;
2285 RockerOfDpaFlowAction *action = flow->action;
2287 if (flow->hits) {
2288 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2289 key->priority, key->tbl_id, flow->hits);
2290 } else {
2291 monitor_printf(mon, "%-4d %-3d ",
2292 key->priority, key->tbl_id);
2295 if (key->has_in_pport) {
2296 monitor_printf(mon, " pport %d", key->in_pport);
2297 if (mask->has_in_pport) {
2298 monitor_printf(mon, "(0x%x)", mask->in_pport);
2302 if (key->has_vlan_id) {
2303 monitor_printf(mon, " vlan %d",
2304 key->vlan_id & VLAN_VID_MASK);
2305 if (mask->has_vlan_id) {
2306 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2310 if (key->has_tunnel_id) {
2311 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2312 if (mask->has_tunnel_id) {
2313 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2317 if (key->has_eth_type) {
2318 switch (key->eth_type) {
2319 case 0x0806:
2320 monitor_printf(mon, " ARP");
2321 break;
2322 case 0x0800:
2323 monitor_printf(mon, " IP");
2324 break;
2325 case 0x86dd:
2326 monitor_printf(mon, " IPv6");
2327 break;
2328 case 0x8809:
2329 monitor_printf(mon, " LACP");
2330 break;
2331 case 0x88cc:
2332 monitor_printf(mon, " LLDP");
2333 break;
2334 default:
2335 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2336 break;
2340 if (key->has_eth_src) {
2341 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2342 (mask->has_eth_src) &&
2343 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2344 monitor_printf(mon, " src <any mcast/bcast>");
2345 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2346 (mask->has_eth_src) &&
2347 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2348 monitor_printf(mon, " src <any ucast>");
2349 } else {
2350 monitor_printf(mon, " src %s", key->eth_src);
2351 if (mask->has_eth_src) {
2352 monitor_printf(mon, "(%s)", mask->eth_src);
2357 if (key->has_eth_dst) {
2358 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2359 (mask->has_eth_dst) &&
2360 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2361 monitor_printf(mon, " dst <any mcast/bcast>");
2362 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2363 (mask->has_eth_dst) &&
2364 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2365 monitor_printf(mon, " dst <any ucast>");
2366 } else {
2367 monitor_printf(mon, " dst %s", key->eth_dst);
2368 if (mask->has_eth_dst) {
2369 monitor_printf(mon, "(%s)", mask->eth_dst);
2374 if (key->has_ip_proto) {
2375 monitor_printf(mon, " proto %d", key->ip_proto);
2376 if (mask->has_ip_proto) {
2377 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2381 if (key->has_ip_tos) {
2382 monitor_printf(mon, " TOS %d", key->ip_tos);
2383 if (mask->has_ip_tos) {
2384 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2388 if (key->has_ip_dst) {
2389 monitor_printf(mon, " dst %s", key->ip_dst);
2392 if (action->has_goto_tbl || action->has_group_id ||
2393 action->has_new_vlan_id) {
2394 monitor_printf(mon, " -->");
2397 if (action->has_new_vlan_id) {
2398 monitor_printf(mon, " apply new vlan %d",
2399 ntohs(action->new_vlan_id));
2402 if (action->has_group_id) {
2403 monitor_printf(mon, " write group 0x%08x", action->group_id);
2406 if (action->has_goto_tbl) {
2407 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2410 monitor_printf(mon, "\n");
2413 qapi_free_RockerOfDpaFlowList(list);
2416 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2418 RockerOfDpaGroupList *list, *g;
2419 const char *name = qdict_get_str(qdict, "name");
2420 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2421 Error *err = NULL;
2422 bool set = false;
2424 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2425 if (err != NULL) {
2426 hmp_handle_error(mon, &err);
2427 return;
2430 monitor_printf(mon, "id (decode) --> buckets\n");
2432 for (g = list; g; g = g->next) {
2433 RockerOfDpaGroup *group = g->value;
2435 monitor_printf(mon, "0x%08x", group->id);
2437 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2438 group->type == 1 ? "L2 rewrite" :
2439 group->type == 2 ? "L3 unicast" :
2440 group->type == 3 ? "L2 multicast" :
2441 group->type == 4 ? "L2 flood" :
2442 group->type == 5 ? "L3 interface" :
2443 group->type == 6 ? "L3 multicast" :
2444 group->type == 7 ? "L3 ECMP" :
2445 group->type == 8 ? "L2 overlay" :
2446 "unknown");
2448 if (group->has_vlan_id) {
2449 monitor_printf(mon, " vlan %d", group->vlan_id);
2452 if (group->has_pport) {
2453 monitor_printf(mon, " pport %d", group->pport);
2456 if (group->has_index) {
2457 monitor_printf(mon, " index %d", group->index);
2460 monitor_printf(mon, ") -->");
2462 if (group->has_set_vlan_id && group->set_vlan_id) {
2463 set = true;
2464 monitor_printf(mon, " set vlan %d",
2465 group->set_vlan_id & VLAN_VID_MASK);
2468 if (group->has_set_eth_src) {
2469 if (!set) {
2470 set = true;
2471 monitor_printf(mon, " set");
2473 monitor_printf(mon, " src %s", group->set_eth_src);
2476 if (group->has_set_eth_dst) {
2477 if (!set) {
2478 set = true;
2479 monitor_printf(mon, " set");
2481 monitor_printf(mon, " dst %s", group->set_eth_dst);
2484 set = false;
2486 if (group->has_ttl_check && group->ttl_check) {
2487 monitor_printf(mon, " check TTL");
2490 if (group->has_group_id && group->group_id) {
2491 monitor_printf(mon, " group id 0x%08x", group->group_id);
2494 if (group->has_pop_vlan && group->pop_vlan) {
2495 monitor_printf(mon, " pop vlan");
2498 if (group->has_out_pport) {
2499 monitor_printf(mon, " out pport %d", group->out_pport);
2502 if (group->has_group_ids) {
2503 struct uint32List *id;
2505 monitor_printf(mon, " groups [");
2506 for (id = group->group_ids; id; id = id->next) {
2507 monitor_printf(mon, "0x%08x", id->value);
2508 if (id->next) {
2509 monitor_printf(mon, ",");
2512 monitor_printf(mon, "]");
2515 monitor_printf(mon, "\n");
2518 qapi_free_RockerOfDpaGroupList(list);
2521 void hmp_info_dump(Monitor *mon, const QDict *qdict)
2523 DumpQueryResult *result = qmp_query_dump(NULL);
2525 assert(result && result->status < DUMP_STATUS__MAX);
2526 monitor_printf(mon, "Status: %s\n", DumpStatus_lookup[result->status]);
2528 if (result->status == DUMP_STATUS_ACTIVE) {
2529 float percent = 0;
2530 assert(result->total != 0);
2531 percent = 100.0 * result->completed / result->total;
2532 monitor_printf(mon, "Finished: %.2f %%\n", percent);
2535 qapi_free_DumpQueryResult(result);
2538 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
2540 Error *err = NULL;
2541 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
2542 HotpluggableCPUList *saved = l;
2543 CpuInstanceProperties *c;
2545 if (err != NULL) {
2546 hmp_handle_error(mon, &err);
2547 return;
2550 monitor_printf(mon, "Hotpluggable CPUs:\n");
2551 while (l) {
2552 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
2553 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
2554 l->value->vcpus_count);
2555 if (l->value->has_qom_path) {
2556 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
2559 c = l->value->props;
2560 monitor_printf(mon, " CPUInstance Properties:\n");
2561 if (c->has_node_id) {
2562 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
2564 if (c->has_socket_id) {
2565 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
2567 if (c->has_core_id) {
2568 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
2570 if (c->has_thread_id) {
2571 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
2574 l = l->next;
2577 qapi_free_HotpluggableCPUList(saved);