2 * Human Monitor Interface
4 * Copyright IBM, Corp. 2011
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"
20 #include "chardev/char.h"
21 #include "sysemu/block-backend.h"
22 #include "sysemu/sysemu.h"
23 #include "qemu/config-file.h"
24 #include "qemu/option.h"
25 #include "qemu/timer.h"
26 #include "qemu/sockets.h"
27 #include "monitor/monitor.h"
28 #include "monitor/qdev.h"
29 #include "qapi/error.h"
30 #include "qapi/opts-visitor.h"
31 #include "qapi/qapi-builtin-visit.h"
32 #include "qapi/qapi-commands-block.h"
33 #include "qapi/qapi-commands-char.h"
34 #include "qapi/qapi-commands-migration.h"
35 #include "qapi/qapi-commands-misc.h"
36 #include "qapi/qapi-commands-net.h"
37 #include "qapi/qapi-commands-rocker.h"
38 #include "qapi/qapi-commands-run-state.h"
39 #include "qapi/qapi-commands-tpm.h"
40 #include "qapi/qapi-commands-ui.h"
41 #include "qapi/qmp/qdict.h"
42 #include "qapi/qmp/qerror.h"
43 #include "qapi/string-input-visitor.h"
44 #include "qapi/string-output-visitor.h"
45 #include "qom/object_interfaces.h"
46 #include "ui/console.h"
47 #include "block/nbd.h"
48 #include "block/qapi.h"
50 #include "qemu/cutils.h"
51 #include "qemu/error-report.h"
52 #include "exec/ramlist.h"
53 #include "hw/intc/intc.h"
54 #include "hw/rdma/rdma.h"
55 #include "migration/snapshot.h"
56 #include "migration/misc.h"
59 #include <spice/enums.h>
62 static void hmp_handle_error(Monitor *mon, Error **errp)
66 error_reportf_err(*errp, "Error: ");
70 void hmp_info_name(Monitor *mon, const QDict *qdict)
74 info = qmp_query_name(NULL);
76 monitor_printf(mon, "%s\n", info->name);
78 qapi_free_NameInfo(info);
81 void hmp_info_version(Monitor *mon, const QDict *qdict)
85 info = qmp_query_version(NULL);
87 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
88 info->qemu->major, info->qemu->minor, info->qemu->micro,
91 qapi_free_VersionInfo(info);
94 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
98 info = qmp_query_kvm(NULL);
99 monitor_printf(mon, "kvm support: ");
101 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
103 monitor_printf(mon, "not compiled\n");
106 qapi_free_KvmInfo(info);
109 void hmp_info_status(Monitor *mon, const QDict *qdict)
113 info = qmp_query_status(NULL);
115 monitor_printf(mon, "VM status: %s%s",
116 info->running ? "running" : "paused",
117 info->singlestep ? " (single step mode)" : "");
119 if (!info->running && info->status != RUN_STATE_PAUSED) {
120 monitor_printf(mon, " (%s)", RunState_str(info->status));
123 monitor_printf(mon, "\n");
125 qapi_free_StatusInfo(info);
128 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
132 info = qmp_query_uuid(NULL);
133 monitor_printf(mon, "%s\n", info->UUID);
134 qapi_free_UuidInfo(info);
137 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
139 ChardevInfoList *char_info, *info;
141 char_info = qmp_query_chardev(NULL);
142 for (info = char_info; info; info = info->next) {
143 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
144 info->value->filename);
147 qapi_free_ChardevInfoList(char_info);
150 void hmp_info_mice(Monitor *mon, const QDict *qdict)
152 MouseInfoList *mice_list, *mouse;
154 mice_list = qmp_query_mice(NULL);
156 monitor_printf(mon, "No mouse devices connected\n");
160 for (mouse = mice_list; mouse; mouse = mouse->next) {
161 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
162 mouse->value->current ? '*' : ' ',
163 mouse->value->index, mouse->value->name,
164 mouse->value->absolute ? " (absolute)" : "");
167 qapi_free_MouseInfoList(mice_list);
170 static char *SocketAddress_to_str(SocketAddress *addr)
172 switch (addr->type) {
173 case SOCKET_ADDRESS_TYPE_INET:
174 return g_strdup_printf("tcp:%s:%s",
177 case SOCKET_ADDRESS_TYPE_UNIX:
178 return g_strdup_printf("unix:%s",
179 addr->u.q_unix.path);
180 case SOCKET_ADDRESS_TYPE_FD:
181 return g_strdup_printf("fd:%s", addr->u.fd.str);
182 case SOCKET_ADDRESS_TYPE_VSOCK:
183 return g_strdup_printf("tcp:%s:%s",
187 return g_strdup("unknown address type");
191 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
194 MigrationCapabilityStatusList *caps, *cap;
196 info = qmp_query_migrate(NULL);
197 caps = qmp_query_migrate_capabilities(NULL);
199 migration_global_dump(mon);
201 /* do not display parameters during setup */
202 if (info->has_status && caps) {
203 monitor_printf(mon, "capabilities: ");
204 for (cap = caps; cap; cap = cap->next) {
205 monitor_printf(mon, "%s: %s ",
206 MigrationCapability_str(cap->value->capability),
207 cap->value->state ? "on" : "off");
209 monitor_printf(mon, "\n");
212 if (info->has_status) {
213 monitor_printf(mon, "Migration status: %s",
214 MigrationStatus_str(info->status));
215 if (info->status == MIGRATION_STATUS_FAILED &&
216 info->has_error_desc) {
217 monitor_printf(mon, " (%s)\n", info->error_desc);
219 monitor_printf(mon, "\n");
222 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
224 if (info->has_expected_downtime) {
225 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
226 info->expected_downtime);
228 if (info->has_downtime) {
229 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
232 if (info->has_setup_time) {
233 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
239 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
240 info->ram->transferred >> 10);
241 monitor_printf(mon, "throughput: %0.2f mbps\n",
243 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
244 info->ram->remaining >> 10);
245 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
246 info->ram->total >> 10);
247 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
248 info->ram->duplicate);
249 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
251 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
253 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
254 info->ram->normal_bytes >> 10);
255 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
256 info->ram->dirty_sync_count);
257 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
258 info->ram->page_size >> 10);
259 monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n",
260 info->ram->multifd_bytes >> 10);
261 monitor_printf(mon, "pages-per-second: %" PRIu64 "\n",
262 info->ram->pages_per_second);
264 if (info->ram->dirty_pages_rate) {
265 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
266 info->ram->dirty_pages_rate);
268 if (info->ram->postcopy_requests) {
269 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
270 info->ram->postcopy_requests);
274 if (info->has_disk) {
275 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
276 info->disk->transferred >> 10);
277 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
278 info->disk->remaining >> 10);
279 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
280 info->disk->total >> 10);
283 if (info->has_xbzrle_cache) {
284 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
285 info->xbzrle_cache->cache_size);
286 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
287 info->xbzrle_cache->bytes >> 10);
288 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
289 info->xbzrle_cache->pages);
290 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
291 info->xbzrle_cache->cache_miss);
292 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
293 info->xbzrle_cache->cache_miss_rate);
294 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
295 info->xbzrle_cache->overflow);
298 if (info->has_compression) {
299 monitor_printf(mon, "compression pages: %" PRIu64 " pages\n",
300 info->compression->pages);
301 monitor_printf(mon, "compression busy: %" PRIu64 "\n",
302 info->compression->busy);
303 monitor_printf(mon, "compression busy rate: %0.2f\n",
304 info->compression->busy_rate);
305 monitor_printf(mon, "compressed size: %" PRIu64 "\n",
306 info->compression->compressed_size);
307 monitor_printf(mon, "compression rate: %0.2f\n",
308 info->compression->compression_rate);
311 if (info->has_cpu_throttle_percentage) {
312 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
313 info->cpu_throttle_percentage);
316 if (info->has_postcopy_blocktime) {
317 monitor_printf(mon, "postcopy blocktime: %u\n",
318 info->postcopy_blocktime);
321 if (info->has_postcopy_vcpu_blocktime) {
324 v = string_output_visitor_new(false, &str);
325 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NULL);
326 visit_complete(v, &str);
327 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
331 if (info->has_socket_address) {
332 SocketAddressList *addr;
334 monitor_printf(mon, "socket address: [\n");
336 for (addr = info->socket_address; addr; addr = addr->next) {
337 char *s = SocketAddress_to_str(addr->value);
338 monitor_printf(mon, "\t%s\n", s);
341 monitor_printf(mon, "]\n");
343 qapi_free_MigrationInfo(info);
344 qapi_free_MigrationCapabilityStatusList(caps);
347 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
349 MigrationCapabilityStatusList *caps, *cap;
351 caps = qmp_query_migrate_capabilities(NULL);
354 for (cap = caps; cap; cap = cap->next) {
355 monitor_printf(mon, "%s: %s\n",
356 MigrationCapability_str(cap->value->capability),
357 cap->value->state ? "on" : "off");
361 qapi_free_MigrationCapabilityStatusList(caps);
364 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
366 MigrationParameters *params;
368 params = qmp_query_migrate_parameters(NULL);
371 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
372 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL),
373 params->announce_initial);
374 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
375 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX),
376 params->announce_max);
377 monitor_printf(mon, "%s: %" PRIu64 "\n",
378 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS),
379 params->announce_rounds);
380 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
381 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP),
382 params->announce_step);
383 assert(params->has_compress_level);
384 monitor_printf(mon, "%s: %u\n",
385 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
386 params->compress_level);
387 assert(params->has_compress_threads);
388 monitor_printf(mon, "%s: %u\n",
389 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
390 params->compress_threads);
391 assert(params->has_compress_wait_thread);
392 monitor_printf(mon, "%s: %s\n",
393 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD),
394 params->compress_wait_thread ? "on" : "off");
395 assert(params->has_decompress_threads);
396 monitor_printf(mon, "%s: %u\n",
397 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
398 params->decompress_threads);
399 assert(params->has_cpu_throttle_initial);
400 monitor_printf(mon, "%s: %u\n",
401 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
402 params->cpu_throttle_initial);
403 assert(params->has_cpu_throttle_increment);
404 monitor_printf(mon, "%s: %u\n",
405 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
406 params->cpu_throttle_increment);
407 assert(params->has_max_cpu_throttle);
408 monitor_printf(mon, "%s: %u\n",
409 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE),
410 params->max_cpu_throttle);
411 assert(params->has_tls_creds);
412 monitor_printf(mon, "%s: '%s'\n",
413 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
415 assert(params->has_tls_hostname);
416 monitor_printf(mon, "%s: '%s'\n",
417 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
418 params->tls_hostname);
419 assert(params->has_max_bandwidth);
420 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
421 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
422 params->max_bandwidth);
423 assert(params->has_downtime_limit);
424 monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n",
425 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
426 params->downtime_limit);
427 assert(params->has_x_checkpoint_delay);
428 monitor_printf(mon, "%s: %u\n",
429 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
430 params->x_checkpoint_delay);
431 assert(params->has_block_incremental);
432 monitor_printf(mon, "%s: %s\n",
433 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
434 params->block_incremental ? "on" : "off");
435 monitor_printf(mon, "%s: %u\n",
436 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS),
437 params->multifd_channels);
438 monitor_printf(mon, "%s: %" PRIu64 "\n",
439 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
440 params->xbzrle_cache_size);
441 monitor_printf(mon, "%s: %" PRIu64 "\n",
442 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
443 params->max_postcopy_bandwidth);
446 qapi_free_MigrationParameters(params);
449 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
451 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
452 qmp_query_migrate_cache_size(NULL) >> 10);
455 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
457 CpuInfoFastList *cpu_list, *cpu;
459 cpu_list = qmp_query_cpus_fast(NULL);
461 for (cpu = cpu_list; cpu; cpu = cpu->next) {
464 if (cpu->value->cpu_index == monitor_get_cpu_index()) {
468 monitor_printf(mon, "%c CPU #%" PRId64 ":", active,
469 cpu->value->cpu_index);
470 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
473 qapi_free_CpuInfoFastList(cpu_list);
476 static void print_block_info(Monitor *mon, BlockInfo *info,
477 BlockDeviceInfo *inserted, bool verbose)
479 ImageInfo *image_info;
481 assert(!info || !info->has_inserted || info->inserted == inserted);
483 if (info && *info->device) {
484 monitor_printf(mon, "%s", info->device);
485 if (inserted && inserted->has_node_name) {
486 monitor_printf(mon, " (%s)", inserted->node_name);
489 assert(info || inserted);
490 monitor_printf(mon, "%s",
491 inserted && inserted->has_node_name ? inserted->node_name
492 : info && info->has_qdev ? info->qdev
497 monitor_printf(mon, ": %s (%s%s%s)\n",
500 inserted->ro ? ", read-only" : "",
501 inserted->encrypted ? ", encrypted" : "");
503 monitor_printf(mon, ": [not inserted]\n");
507 if (info->has_qdev) {
508 monitor_printf(mon, " Attached to: %s\n", info->qdev);
510 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
511 monitor_printf(mon, " I/O status: %s\n",
512 BlockDeviceIoStatus_str(info->io_status));
515 if (info->removable) {
516 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
517 info->locked ? "" : "not ",
518 info->tray_open ? "open" : "closed");
527 monitor_printf(mon, " Cache mode: %s%s%s\n",
528 inserted->cache->writeback ? "writeback" : "writethrough",
529 inserted->cache->direct ? ", direct" : "",
530 inserted->cache->no_flush ? ", ignore flushes" : "");
532 if (inserted->has_backing_file) {
535 "(chain depth: %" PRId64 ")\n",
536 inserted->backing_file,
537 inserted->backing_file_depth);
540 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
541 monitor_printf(mon, " Detect zeroes: %s\n",
542 BlockdevDetectZeroesOptions_str(inserted->detect_zeroes));
545 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
546 inserted->iops || inserted->iops_rd || inserted->iops_wr)
548 monitor_printf(mon, " I/O throttling: bps=%" PRId64
549 " bps_rd=%" PRId64 " bps_wr=%" PRId64
551 " bps_rd_max=%" PRId64
552 " bps_wr_max=%" PRId64
553 " iops=%" PRId64 " iops_rd=%" PRId64
556 " iops_rd_max=%" PRId64
557 " iops_wr_max=%" PRId64
558 " iops_size=%" PRId64
564 inserted->bps_rd_max,
565 inserted->bps_wr_max,
570 inserted->iops_rd_max,
571 inserted->iops_wr_max,
577 monitor_printf(mon, "\nImages:\n");
578 image_info = inserted->image;
580 bdrv_image_info_dump((fprintf_function)monitor_printf,
582 if (image_info->has_backing_image) {
583 image_info = image_info->backing_image;
591 void hmp_info_block(Monitor *mon, const QDict *qdict)
593 BlockInfoList *block_list, *info;
594 BlockDeviceInfoList *blockdev_list, *blockdev;
595 const char *device = qdict_get_try_str(qdict, "device");
596 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
597 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
598 bool printed = false;
600 /* Print BlockBackend information */
602 block_list = qmp_query_block(NULL);
607 for (info = block_list; info; info = info->next) {
608 if (device && strcmp(device, info->value->device)) {
612 if (info != block_list) {
613 monitor_printf(mon, "\n");
616 print_block_info(mon, info->value, info->value->has_inserted
617 ? info->value->inserted : NULL,
622 qapi_free_BlockInfoList(block_list);
624 if ((!device && !nodes) || printed) {
628 /* Print node information */
629 blockdev_list = qmp_query_named_block_nodes(NULL);
630 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
631 assert(blockdev->value->has_node_name);
632 if (device && strcmp(device, blockdev->value->node_name)) {
636 if (blockdev != blockdev_list) {
637 monitor_printf(mon, "\n");
640 print_block_info(mon, NULL, blockdev->value, verbose);
642 qapi_free_BlockDeviceInfoList(blockdev_list);
645 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
647 BlockStatsList *stats_list, *stats;
649 stats_list = qmp_query_blockstats(false, false, NULL);
651 for (stats = stats_list; stats; stats = stats->next) {
652 if (!stats->value->has_device) {
656 monitor_printf(mon, "%s:", stats->value->device);
657 monitor_printf(mon, " rd_bytes=%" PRId64
659 " rd_operations=%" PRId64
660 " wr_operations=%" PRId64
661 " flush_operations=%" PRId64
662 " wr_total_time_ns=%" PRId64
663 " rd_total_time_ns=%" PRId64
664 " flush_total_time_ns=%" PRId64
665 " rd_merged=%" PRId64
666 " wr_merged=%" PRId64
667 " idle_time_ns=%" PRId64
669 stats->value->stats->rd_bytes,
670 stats->value->stats->wr_bytes,
671 stats->value->stats->rd_operations,
672 stats->value->stats->wr_operations,
673 stats->value->stats->flush_operations,
674 stats->value->stats->wr_total_time_ns,
675 stats->value->stats->rd_total_time_ns,
676 stats->value->stats->flush_total_time_ns,
677 stats->value->stats->rd_merged,
678 stats->value->stats->wr_merged,
679 stats->value->stats->idle_time_ns);
682 qapi_free_BlockStatsList(stats_list);
686 /* Helper for hmp_info_vnc_clients, _servers */
687 static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
690 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
694 NetworkAddressFamily_str(info->family),
695 info->websocket ? " (Websocket)" : "");
698 /* Helper displaying and auth and crypt info */
699 static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
701 VncVencryptSubAuth *vencrypt)
703 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
704 VncPrimaryAuth_str(auth),
705 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
708 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
711 VncClientInfo *cinfo = client->value;
713 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
714 monitor_printf(mon, " x509_dname: %s\n",
715 cinfo->has_x509_dname ?
716 cinfo->x509_dname : "none");
717 monitor_printf(mon, " sasl_username: %s\n",
718 cinfo->has_sasl_username ?
719 cinfo->sasl_username : "none");
721 client = client->next;
725 static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
728 VncServerInfo2 *sinfo = server->value;
729 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
730 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
731 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
732 server = server->next;
736 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
738 VncInfo2List *info2l;
741 info2l = qmp_query_vnc_servers(&err);
743 hmp_handle_error(mon, &err);
747 monitor_printf(mon, "None\n");
752 VncInfo2 *info = info2l->value;
753 monitor_printf(mon, "%s:\n", info->id);
754 hmp_info_vnc_servers(mon, info->server);
755 hmp_info_vnc_clients(mon, info->clients);
757 /* The server entry displays its auth, we only
758 * need to display in the case of 'reverse' connections
759 * where there's no server.
761 hmp_info_vnc_authcrypt(mon, " ", info->auth,
762 info->has_vencrypt ? &info->vencrypt : NULL);
764 if (info->has_display) {
765 monitor_printf(mon, " Display: %s\n", info->display);
767 info2l = info2l->next;
770 qapi_free_VncInfo2List(info2l);
776 void hmp_info_spice(Monitor *mon, const QDict *qdict)
778 SpiceChannelList *chan;
780 const char *channel_name;
781 const char * const channel_names[] = {
782 [SPICE_CHANNEL_MAIN] = "main",
783 [SPICE_CHANNEL_DISPLAY] = "display",
784 [SPICE_CHANNEL_INPUTS] = "inputs",
785 [SPICE_CHANNEL_CURSOR] = "cursor",
786 [SPICE_CHANNEL_PLAYBACK] = "playback",
787 [SPICE_CHANNEL_RECORD] = "record",
788 [SPICE_CHANNEL_TUNNEL] = "tunnel",
789 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
790 [SPICE_CHANNEL_USBREDIR] = "usbredir",
791 [SPICE_CHANNEL_PORT] = "port",
793 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
794 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
795 * as quick fix for build failures with older versions. */
796 [SPICE_CHANNEL_WEBDAV] = "webdav",
800 info = qmp_query_spice(NULL);
802 if (!info->enabled) {
803 monitor_printf(mon, "Server: disabled\n");
807 monitor_printf(mon, "Server:\n");
808 if (info->has_port) {
809 monitor_printf(mon, " address: %s:%" PRId64 "\n",
810 info->host, info->port);
812 if (info->has_tls_port) {
813 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
814 info->host, info->tls_port);
816 monitor_printf(mon, " migrated: %s\n",
817 info->migrated ? "true" : "false");
818 monitor_printf(mon, " auth: %s\n", info->auth);
819 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
820 monitor_printf(mon, " mouse-mode: %s\n",
821 SpiceQueryMouseMode_str(info->mouse_mode));
823 if (!info->has_channels || info->channels == NULL) {
824 monitor_printf(mon, "Channels: none\n");
826 for (chan = info->channels; chan; chan = chan->next) {
827 monitor_printf(mon, "Channel:\n");
828 monitor_printf(mon, " address: %s:%s%s\n",
829 chan->value->host, chan->value->port,
830 chan->value->tls ? " [tls]" : "");
831 monitor_printf(mon, " session: %" PRId64 "\n",
832 chan->value->connection_id);
833 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
834 chan->value->channel_type, chan->value->channel_id);
836 channel_name = "unknown";
837 if (chan->value->channel_type > 0 &&
838 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
839 channel_names[chan->value->channel_type]) {
840 channel_name = channel_names[chan->value->channel_type];
843 monitor_printf(mon, " channel name: %s\n", channel_name);
848 qapi_free_SpiceInfo(info);
852 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
857 info = qmp_query_balloon(&err);
859 hmp_handle_error(mon, &err);
863 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
865 qapi_free_BalloonInfo(info);
868 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
870 PciMemoryRegionList *region;
872 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
873 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
874 dev->slot, dev->function);
875 monitor_printf(mon, " ");
877 if (dev->class_info->has_desc) {
878 monitor_printf(mon, "%s", dev->class_info->desc);
880 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
883 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
884 dev->id->vendor, dev->id->device);
885 if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) {
886 monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n",
887 dev->id->subsystem_vendor, dev->id->subsystem);
891 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
894 if (dev->has_pci_bridge) {
895 monitor_printf(mon, " BUS %" PRId64 ".\n",
896 dev->pci_bridge->bus->number);
897 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
898 dev->pci_bridge->bus->secondary);
899 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
900 dev->pci_bridge->bus->subordinate);
902 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
903 dev->pci_bridge->bus->io_range->base,
904 dev->pci_bridge->bus->io_range->limit);
907 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
908 dev->pci_bridge->bus->memory_range->base,
909 dev->pci_bridge->bus->memory_range->limit);
911 monitor_printf(mon, " prefetchable memory range "
912 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
913 dev->pci_bridge->bus->prefetchable_range->base,
914 dev->pci_bridge->bus->prefetchable_range->limit);
917 for (region = dev->regions; region; region = region->next) {
920 addr = region->value->address;
921 size = region->value->size;
923 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
925 if (!strcmp(region->value->type, "io")) {
926 monitor_printf(mon, "I/O at 0x%04" PRIx64
927 " [0x%04" PRIx64 "].\n",
928 addr, addr + size - 1);
930 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
931 " [0x%08" PRIx64 "].\n",
932 region->value->mem_type_64 ? 64 : 32,
933 region->value->prefetch ? " prefetchable" : "",
934 addr, addr + size - 1);
938 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
940 if (dev->has_pci_bridge) {
941 if (dev->pci_bridge->has_devices) {
942 PciDeviceInfoList *cdev;
943 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
944 hmp_info_pci_device(mon, cdev->value);
950 static int hmp_info_irq_foreach(Object *obj, void *opaque)
952 InterruptStatsProvider *intc;
953 InterruptStatsProviderClass *k;
954 Monitor *mon = opaque;
956 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
957 intc = INTERRUPT_STATS_PROVIDER(obj);
958 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
959 uint64_t *irq_counts;
960 unsigned int nb_irqs, i;
961 if (k->get_statistics &&
962 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
964 monitor_printf(mon, "IRQ statistics for %s:\n",
965 object_get_typename(obj));
966 for (i = 0; i < nb_irqs; i++) {
967 if (irq_counts[i] > 0) {
968 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
974 monitor_printf(mon, "IRQ statistics not available for %s.\n",
975 object_get_typename(obj));
982 void hmp_info_irq(Monitor *mon, const QDict *qdict)
984 object_child_foreach_recursive(object_get_root(),
985 hmp_info_irq_foreach, mon);
988 static int hmp_info_pic_foreach(Object *obj, void *opaque)
990 InterruptStatsProvider *intc;
991 InterruptStatsProviderClass *k;
992 Monitor *mon = opaque;
994 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
995 intc = INTERRUPT_STATS_PROVIDER(obj);
996 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
998 k->print_info(intc, mon);
1000 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
1001 object_get_typename(obj));
1008 void hmp_info_pic(Monitor *mon, const QDict *qdict)
1010 object_child_foreach_recursive(object_get_root(),
1011 hmp_info_pic_foreach, mon);
1014 static int hmp_info_rdma_foreach(Object *obj, void *opaque)
1017 RdmaProviderClass *k;
1018 Monitor *mon = opaque;
1020 if (object_dynamic_cast(obj, INTERFACE_RDMA_PROVIDER)) {
1021 rdma = RDMA_PROVIDER(obj);
1022 k = RDMA_PROVIDER_GET_CLASS(obj);
1023 if (k->print_statistics) {
1024 k->print_statistics(mon, rdma);
1026 monitor_printf(mon, "RDMA statistics not available for %s.\n",
1027 object_get_typename(obj));
1034 void hmp_info_rdma(Monitor *mon, const QDict *qdict)
1036 object_child_foreach_recursive(object_get_root(),
1037 hmp_info_rdma_foreach, mon);
1040 void hmp_info_pci(Monitor *mon, const QDict *qdict)
1042 PciInfoList *info_list, *info;
1045 info_list = qmp_query_pci(&err);
1047 monitor_printf(mon, "PCI devices not supported\n");
1052 for (info = info_list; info; info = info->next) {
1053 PciDeviceInfoList *dev;
1055 for (dev = info->value->devices; dev; dev = dev->next) {
1056 hmp_info_pci_device(mon, dev->value);
1060 qapi_free_PciInfoList(info_list);
1063 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
1065 BlockJobInfoList *list;
1068 list = qmp_query_block_jobs(&err);
1072 monitor_printf(mon, "No active jobs\n");
1077 if (strcmp(list->value->type, "stream") == 0) {
1078 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
1079 " of %" PRId64 " bytes, speed limit %" PRId64
1081 list->value->device,
1082 list->value->offset,
1084 list->value->speed);
1086 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
1087 " of %" PRId64 " bytes, speed limit %" PRId64
1090 list->value->device,
1091 list->value->offset,
1093 list->value->speed);
1098 qapi_free_BlockJobInfoList(list);
1101 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
1103 TPMInfoList *info_list, *info;
1106 TPMPassthroughOptions *tpo;
1107 TPMEmulatorOptions *teo;
1109 info_list = qmp_query_tpm(&err);
1111 monitor_printf(mon, "TPM device not supported\n");
1117 monitor_printf(mon, "TPM device:\n");
1120 for (info = info_list; info; info = info->next) {
1121 TPMInfo *ti = info->value;
1122 monitor_printf(mon, " tpm%d: model=%s\n",
1123 c, TpmModel_str(ti->model));
1125 monitor_printf(mon, " \\ %s: type=%s",
1126 ti->id, TpmTypeOptionsKind_str(ti->options->type));
1128 switch (ti->options->type) {
1129 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
1130 tpo = ti->options->u.passthrough.data;
1131 monitor_printf(mon, "%s%s%s%s",
1132 tpo->has_path ? ",path=" : "",
1133 tpo->has_path ? tpo->path : "",
1134 tpo->has_cancel_path ? ",cancel-path=" : "",
1135 tpo->has_cancel_path ? tpo->cancel_path : "");
1137 case TPM_TYPE_OPTIONS_KIND_EMULATOR:
1138 teo = ti->options->u.emulator.data;
1139 monitor_printf(mon, ",chardev=%s", teo->chardev);
1141 case TPM_TYPE_OPTIONS_KIND__MAX:
1144 monitor_printf(mon, "\n");
1147 qapi_free_TPMInfoList(info_list);
1150 void hmp_quit(Monitor *mon, const QDict *qdict)
1152 monitor_suspend(mon);
1156 void hmp_stop(Monitor *mon, const QDict *qdict)
1161 void hmp_sync_profile(Monitor *mon, const QDict *qdict)
1163 const char *op = qdict_get_try_str(qdict, "op");
1166 bool on = qsp_is_enabled();
1168 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off");
1171 if (!strcmp(op, "on")) {
1173 } else if (!strcmp(op, "off")) {
1175 } else if (!strcmp(op, "reset")) {
1180 error_setg(&err, QERR_INVALID_PARAMETER, op);
1181 hmp_handle_error(mon, &err);
1185 void hmp_system_reset(Monitor *mon, const QDict *qdict)
1187 qmp_system_reset(NULL);
1190 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
1192 qmp_system_powerdown(NULL);
1195 void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
1199 qmp_x_exit_preconfig(&err);
1200 hmp_handle_error(mon, &err);
1203 void hmp_cpu(Monitor *mon, const QDict *qdict)
1207 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1208 use it are converted to the QAPI */
1209 cpu_index = qdict_get_int(qdict, "index");
1210 if (monitor_set_cpu(cpu_index) < 0) {
1211 monitor_printf(mon, "invalid CPU index\n");
1215 void hmp_memsave(Monitor *mon, const QDict *qdict)
1217 uint32_t size = qdict_get_int(qdict, "size");
1218 const char *filename = qdict_get_str(qdict, "filename");
1219 uint64_t addr = qdict_get_int(qdict, "val");
1221 int cpu_index = monitor_get_cpu_index();
1223 if (cpu_index < 0) {
1224 monitor_printf(mon, "No CPU available\n");
1228 qmp_memsave(addr, size, filename, true, cpu_index, &err);
1229 hmp_handle_error(mon, &err);
1232 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1234 uint32_t size = qdict_get_int(qdict, "size");
1235 const char *filename = qdict_get_str(qdict, "filename");
1236 uint64_t addr = qdict_get_int(qdict, "val");
1239 qmp_pmemsave(addr, size, filename, &err);
1240 hmp_handle_error(mon, &err);
1243 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1245 const char *chardev = qdict_get_str(qdict, "device");
1246 const char *data = qdict_get_str(qdict, "data");
1249 qmp_ringbuf_write(chardev, data, false, 0, &err);
1251 hmp_handle_error(mon, &err);
1254 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
1256 uint32_t size = qdict_get_int(qdict, "size");
1257 const char *chardev = qdict_get_str(qdict, "device");
1262 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1264 hmp_handle_error(mon, &err);
1268 for (i = 0; data[i]; i++) {
1269 unsigned char ch = data[i];
1272 monitor_printf(mon, "\\\\");
1273 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1274 monitor_printf(mon, "\\u%04X", ch);
1276 monitor_printf(mon, "%c", ch);
1280 monitor_printf(mon, "\n");
1284 void hmp_cont(Monitor *mon, const QDict *qdict)
1289 hmp_handle_error(mon, &err);
1292 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1296 qmp_system_wakeup(&err);
1297 hmp_handle_error(mon, &err);
1300 void hmp_nmi(Monitor *mon, const QDict *qdict)
1304 qmp_inject_nmi(&err);
1305 hmp_handle_error(mon, &err);
1308 void hmp_set_link(Monitor *mon, const QDict *qdict)
1310 const char *name = qdict_get_str(qdict, "name");
1311 bool up = qdict_get_bool(qdict, "up");
1314 qmp_set_link(name, up, &err);
1315 hmp_handle_error(mon, &err);
1318 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1320 const char *device = qdict_get_str(qdict, "device");
1321 const char *password = qdict_get_str(qdict, "password");
1324 qmp_block_passwd(true, device, false, NULL, password, &err);
1325 hmp_handle_error(mon, &err);
1328 void hmp_balloon(Monitor *mon, const QDict *qdict)
1330 int64_t value = qdict_get_int(qdict, "value");
1333 qmp_balloon(value, &err);
1334 hmp_handle_error(mon, &err);
1337 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1339 const char *device = qdict_get_str(qdict, "device");
1340 int64_t size = qdict_get_int(qdict, "size");
1343 qmp_block_resize(true, device, false, NULL, size, &err);
1344 hmp_handle_error(mon, &err);
1347 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1349 const char *filename = qdict_get_str(qdict, "target");
1350 const char *format = qdict_get_try_str(qdict, "format");
1351 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1352 bool full = qdict_get_try_bool(qdict, "full", false);
1354 DriveMirror mirror = {
1355 .device = (char *)qdict_get_str(qdict, "device"),
1356 .target = (char *)filename,
1357 .has_format = !!format,
1358 .format = (char *)format,
1359 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1361 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1366 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1367 hmp_handle_error(mon, &err);
1370 qmp_drive_mirror(&mirror, &err);
1371 hmp_handle_error(mon, &err);
1374 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1376 const char *device = qdict_get_str(qdict, "device");
1377 const char *filename = qdict_get_str(qdict, "target");
1378 const char *format = qdict_get_try_str(qdict, "format");
1379 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1380 bool full = qdict_get_try_bool(qdict, "full", false);
1381 bool compress = qdict_get_try_bool(qdict, "compress", false);
1383 DriveBackup backup = {
1384 .device = (char *)device,
1385 .target = (char *)filename,
1386 .has_format = !!format,
1387 .format = (char *)format,
1388 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1390 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1391 .has_compress = !!compress,
1392 .compress = compress,
1396 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1397 hmp_handle_error(mon, &err);
1401 qmp_drive_backup(&backup, &err);
1402 hmp_handle_error(mon, &err);
1405 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1407 const char *device = qdict_get_str(qdict, "device");
1408 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1409 const char *format = qdict_get_try_str(qdict, "format");
1410 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1411 enum NewImageMode mode;
1415 /* In the future, if 'snapshot-file' is not specified, the snapshot
1416 will be taken internally. Today it's actually required. */
1417 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1418 hmp_handle_error(mon, &err);
1422 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1423 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1424 filename, false, NULL,
1427 hmp_handle_error(mon, &err);
1430 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1432 const char *device = qdict_get_str(qdict, "device");
1433 const char *name = qdict_get_str(qdict, "name");
1436 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1437 hmp_handle_error(mon, &err);
1440 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1442 const char *device = qdict_get_str(qdict, "device");
1443 const char *name = qdict_get_str(qdict, "name");
1444 const char *id = qdict_get_try_str(qdict, "id");
1447 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1449 hmp_handle_error(mon, &err);
1452 void hmp_loadvm(Monitor *mon, const QDict *qdict)
1454 int saved_vm_running = runstate_is_running();
1455 const char *name = qdict_get_str(qdict, "name");
1458 vm_stop(RUN_STATE_RESTORE_VM);
1460 if (load_snapshot(name, &err) == 0 && saved_vm_running) {
1463 hmp_handle_error(mon, &err);
1466 void hmp_savevm(Monitor *mon, const QDict *qdict)
1470 save_snapshot(qdict_get_try_str(qdict, "name"), &err);
1471 hmp_handle_error(mon, &err);
1474 void hmp_delvm(Monitor *mon, const QDict *qdict)
1476 BlockDriverState *bs;
1478 const char *name = qdict_get_str(qdict, "name");
1480 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
1481 error_reportf_err(err,
1482 "Error while deleting snapshot on device '%s': ",
1483 bdrv_get_device_name(bs));
1487 void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
1489 BlockDriverState *bs, *bs1;
1490 BdrvNextIterator it1;
1491 QEMUSnapshotInfo *sn_tab, *sn;
1492 bool no_snapshot = true;
1495 int *global_snapshots;
1496 AioContext *aio_context;
1498 typedef struct SnapshotEntry {
1499 QEMUSnapshotInfo sn;
1500 QTAILQ_ENTRY(SnapshotEntry) next;
1503 typedef struct ImageEntry {
1504 const char *imagename;
1505 QTAILQ_ENTRY(ImageEntry) next;
1506 QTAILQ_HEAD(, SnapshotEntry) snapshots;
1509 QTAILQ_HEAD(, ImageEntry) image_list =
1510 QTAILQ_HEAD_INITIALIZER(image_list);
1512 ImageEntry *image_entry, *next_ie;
1513 SnapshotEntry *snapshot_entry;
1515 bs = bdrv_all_find_vmstate_bs();
1517 monitor_printf(mon, "No available block device supports snapshots\n");
1520 aio_context = bdrv_get_aio_context(bs);
1522 aio_context_acquire(aio_context);
1523 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
1524 aio_context_release(aio_context);
1527 monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
1531 for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) {
1535 AioContext *ctx = bdrv_get_aio_context(bs1);
1537 aio_context_acquire(ctx);
1538 if (bdrv_can_snapshot(bs1)) {
1540 bs1_nb_sns = bdrv_snapshot_list(bs1, &sn);
1541 if (bs1_nb_sns > 0) {
1542 no_snapshot = false;
1543 ie = g_new0(ImageEntry, 1);
1544 ie->imagename = bdrv_get_device_name(bs1);
1545 QTAILQ_INIT(&ie->snapshots);
1546 QTAILQ_INSERT_TAIL(&image_list, ie, next);
1547 for (i = 0; i < bs1_nb_sns; i++) {
1548 se = g_new0(SnapshotEntry, 1);
1550 QTAILQ_INSERT_TAIL(&ie->snapshots, se, next);
1555 aio_context_release(ctx);
1559 monitor_printf(mon, "There is no snapshot available.\n");
1563 global_snapshots = g_new0(int, nb_sns);
1565 for (i = 0; i < nb_sns; i++) {
1566 SnapshotEntry *next_sn;
1567 if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) {
1568 global_snapshots[total] = i;
1570 QTAILQ_FOREACH(image_entry, &image_list, next) {
1571 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots,
1573 if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) {
1574 QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry,
1576 g_free(snapshot_entry);
1583 monitor_printf(mon, "List of snapshots present on all disks:\n");
1586 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1587 monitor_printf(mon, "\n");
1588 for (i = 0; i < total; i++) {
1589 sn = &sn_tab[global_snapshots[i]];
1590 /* The ID is not guaranteed to be the same on all images, so
1593 pstrcpy(sn->id_str, sizeof(sn->id_str), "--");
1594 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, sn);
1595 monitor_printf(mon, "\n");
1598 monitor_printf(mon, "None\n");
1601 QTAILQ_FOREACH(image_entry, &image_list, next) {
1602 if (QTAILQ_EMPTY(&image_entry->snapshots)) {
1606 "\nList of partial (non-loadable) snapshots on '%s':\n",
1607 image_entry->imagename);
1608 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1609 monitor_printf(mon, "\n");
1610 QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) {
1611 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon,
1612 &snapshot_entry->sn);
1613 monitor_printf(mon, "\n");
1617 QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) {
1618 SnapshotEntry *next_sn;
1619 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next,
1621 g_free(snapshot_entry);
1623 g_free(image_entry);
1626 g_free(global_snapshots);
1630 void hmp_announce_self(Monitor *mon, const QDict *qdict)
1632 qmp_announce_self(migrate_announce_params(), NULL);
1635 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1637 qmp_migrate_cancel(NULL);
1640 void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1643 const char *state = qdict_get_str(qdict, "state");
1644 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1647 qmp_migrate_continue(val, &err);
1650 hmp_handle_error(mon, &err);
1653 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1656 const char *uri = qdict_get_str(qdict, "uri");
1658 qmp_migrate_incoming(uri, &err);
1660 hmp_handle_error(mon, &err);
1663 void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
1666 const char *uri = qdict_get_str(qdict, "uri");
1668 qmp_migrate_recover(uri, &err);
1670 hmp_handle_error(mon, &err);
1673 void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
1677 qmp_migrate_pause(&err);
1679 hmp_handle_error(mon, &err);
1682 /* Kept for backwards compatibility */
1683 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1685 double value = qdict_get_double(qdict, "value");
1686 qmp_migrate_set_downtime(value, NULL);
1689 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1691 int64_t value = qdict_get_int(qdict, "value");
1694 qmp_migrate_set_cache_size(value, &err);
1695 hmp_handle_error(mon, &err);
1698 /* Kept for backwards compatibility */
1699 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1701 int64_t value = qdict_get_int(qdict, "value");
1702 qmp_migrate_set_speed(value, NULL);
1705 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1707 const char *cap = qdict_get_str(qdict, "capability");
1708 bool state = qdict_get_bool(qdict, "state");
1710 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1713 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
1718 caps->value = g_malloc0(sizeof(*caps->value));
1719 caps->value->capability = val;
1720 caps->value->state = state;
1722 qmp_migrate_set_capabilities(caps, &err);
1725 qapi_free_MigrationCapabilityStatusList(caps);
1726 hmp_handle_error(mon, &err);
1729 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1731 const char *param = qdict_get_str(qdict, "parameter");
1732 const char *valuestr = qdict_get_str(qdict, "value");
1733 Visitor *v = string_input_visitor_new(valuestr);
1734 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
1735 uint64_t valuebw = 0;
1736 uint64_t cache_size;
1740 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
1746 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1747 p->has_compress_level = true;
1748 visit_type_int(v, param, &p->compress_level, &err);
1750 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1751 p->has_compress_threads = true;
1752 visit_type_int(v, param, &p->compress_threads, &err);
1754 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD:
1755 p->has_compress_wait_thread = true;
1756 visit_type_bool(v, param, &p->compress_wait_thread, &err);
1758 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1759 p->has_decompress_threads = true;
1760 visit_type_int(v, param, &p->decompress_threads, &err);
1762 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1763 p->has_cpu_throttle_initial = true;
1764 visit_type_int(v, param, &p->cpu_throttle_initial, &err);
1766 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1767 p->has_cpu_throttle_increment = true;
1768 visit_type_int(v, param, &p->cpu_throttle_increment, &err);
1770 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE:
1771 p->has_max_cpu_throttle = true;
1772 visit_type_int(v, param, &p->max_cpu_throttle, &err);
1774 case MIGRATION_PARAMETER_TLS_CREDS:
1775 p->has_tls_creds = true;
1776 p->tls_creds = g_new0(StrOrNull, 1);
1777 p->tls_creds->type = QTYPE_QSTRING;
1778 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1780 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1781 p->has_tls_hostname = true;
1782 p->tls_hostname = g_new0(StrOrNull, 1);
1783 p->tls_hostname->type = QTYPE_QSTRING;
1784 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1786 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1787 p->has_max_bandwidth = true;
1789 * Can't use visit_type_size() here, because it
1790 * defaults to Bytes rather than Mebibytes.
1792 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1793 if (ret < 0 || valuebw > INT64_MAX
1794 || (size_t)valuebw != valuebw) {
1795 error_setg(&err, "Invalid size %s", valuestr);
1798 p->max_bandwidth = valuebw;
1800 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1801 p->has_downtime_limit = true;
1802 visit_type_int(v, param, &p->downtime_limit, &err);
1804 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1805 p->has_x_checkpoint_delay = true;
1806 visit_type_int(v, param, &p->x_checkpoint_delay, &err);
1808 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1809 p->has_block_incremental = true;
1810 visit_type_bool(v, param, &p->block_incremental, &err);
1812 case MIGRATION_PARAMETER_MULTIFD_CHANNELS:
1813 p->has_multifd_channels = true;
1814 visit_type_int(v, param, &p->multifd_channels, &err);
1816 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1817 p->has_xbzrle_cache_size = true;
1818 visit_type_size(v, param, &cache_size, &err);
1819 if (err || cache_size > INT64_MAX
1820 || (size_t)cache_size != cache_size) {
1821 error_setg(&err, "Invalid size %s", valuestr);
1824 p->xbzrle_cache_size = cache_size;
1826 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH:
1827 p->has_max_postcopy_bandwidth = true;
1828 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err);
1830 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL:
1831 p->has_announce_initial = true;
1832 visit_type_size(v, param, &p->announce_initial, &err);
1834 case MIGRATION_PARAMETER_ANNOUNCE_MAX:
1835 p->has_announce_max = true;
1836 visit_type_size(v, param, &p->announce_max, &err);
1838 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS:
1839 p->has_announce_rounds = true;
1840 visit_type_size(v, param, &p->announce_rounds, &err);
1842 case MIGRATION_PARAMETER_ANNOUNCE_STEP:
1843 p->has_announce_step = true;
1844 visit_type_size(v, param, &p->announce_step, &err);
1854 qmp_migrate_set_parameters(p, &err);
1857 qapi_free_MigrateSetParameters(p);
1859 hmp_handle_error(mon, &err);
1862 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1865 const char *protocol = qdict_get_str(qdict, "protocol");
1866 const char *hostname = qdict_get_str(qdict, "hostname");
1867 bool has_port = qdict_haskey(qdict, "port");
1868 int port = qdict_get_try_int(qdict, "port", -1);
1869 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1870 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1871 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1873 qmp_client_migrate_info(protocol, hostname,
1874 has_port, port, has_tls_port, tls_port,
1875 !!cert_subject, cert_subject, &err);
1876 hmp_handle_error(mon, &err);
1879 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1882 qmp_migrate_start_postcopy(&err);
1883 hmp_handle_error(mon, &err);
1886 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1890 qmp_x_colo_lost_heartbeat(&err);
1891 hmp_handle_error(mon, &err);
1894 void hmp_set_password(Monitor *mon, const QDict *qdict)
1896 const char *protocol = qdict_get_str(qdict, "protocol");
1897 const char *password = qdict_get_str(qdict, "password");
1898 const char *connected = qdict_get_try_str(qdict, "connected");
1901 qmp_set_password(protocol, password, !!connected, connected, &err);
1902 hmp_handle_error(mon, &err);
1905 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1907 const char *protocol = qdict_get_str(qdict, "protocol");
1908 const char *whenstr = qdict_get_str(qdict, "time");
1911 qmp_expire_password(protocol, whenstr, &err);
1912 hmp_handle_error(mon, &err);
1915 void hmp_eject(Monitor *mon, const QDict *qdict)
1917 bool force = qdict_get_try_bool(qdict, "force", false);
1918 const char *device = qdict_get_str(qdict, "device");
1921 qmp_eject(true, device, false, NULL, true, force, &err);
1922 hmp_handle_error(mon, &err);
1926 static void hmp_change_read_arg(void *opaque, const char *password,
1927 void *readline_opaque)
1929 qmp_change_vnc_password(password, NULL);
1930 monitor_read_command(opaque, 1);
1934 void hmp_change(Monitor *mon, const QDict *qdict)
1936 const char *device = qdict_get_str(qdict, "device");
1937 const char *target = qdict_get_str(qdict, "target");
1938 const char *arg = qdict_get_try_str(qdict, "arg");
1939 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1940 BlockdevChangeReadOnlyMode read_only_mode = 0;
1944 if (strcmp(device, "vnc") == 0) {
1947 "Parameter 'read-only-mode' is invalid for VNC\n");
1950 if (strcmp(target, "passwd") == 0 ||
1951 strcmp(target, "password") == 0) {
1953 monitor_read_password(mon, hmp_change_read_arg, NULL);
1957 qmp_change("vnc", target, !!arg, arg, &err);
1963 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
1965 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1967 hmp_handle_error(mon, &err);
1972 qmp_blockdev_change_medium(true, device, false, NULL, target,
1973 !!arg, arg, !!read_only, read_only_mode,
1977 hmp_handle_error(mon, &err);
1980 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1983 char *device = (char *) qdict_get_str(qdict, "device");
1984 BlockIOThrottle throttle = {
1985 .bps = qdict_get_int(qdict, "bps"),
1986 .bps_rd = qdict_get_int(qdict, "bps_rd"),
1987 .bps_wr = qdict_get_int(qdict, "bps_wr"),
1988 .iops = qdict_get_int(qdict, "iops"),
1989 .iops_rd = qdict_get_int(qdict, "iops_rd"),
1990 .iops_wr = qdict_get_int(qdict, "iops_wr"),
1993 /* qmp_block_set_io_throttle has separate parameters for the
1994 * (deprecated) block device name and the qdev ID but the HMP
1995 * version has only one, so we must decide which one to pass. */
1996 if (blk_by_name(device)) {
1997 throttle.has_device = true;
1998 throttle.device = device;
2000 throttle.has_id = true;
2001 throttle.id = device;
2004 qmp_block_set_io_throttle(&throttle, &err);
2005 hmp_handle_error(mon, &err);
2008 void hmp_block_stream(Monitor *mon, const QDict *qdict)
2010 Error *error = NULL;
2011 const char *device = qdict_get_str(qdict, "device");
2012 const char *base = qdict_get_try_str(qdict, "base");
2013 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
2015 qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
2016 false, NULL, qdict_haskey(qdict, "speed"), speed, true,
2017 BLOCKDEV_ON_ERROR_REPORT, false, false, false, false,
2020 hmp_handle_error(mon, &error);
2023 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
2025 Error *error = NULL;
2026 const char *device = qdict_get_str(qdict, "device");
2027 int64_t value = qdict_get_int(qdict, "speed");
2029 qmp_block_job_set_speed(device, value, &error);
2031 hmp_handle_error(mon, &error);
2034 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
2036 Error *error = NULL;
2037 const char *device = qdict_get_str(qdict, "device");
2038 bool force = qdict_get_try_bool(qdict, "force", false);
2040 qmp_block_job_cancel(device, true, force, &error);
2042 hmp_handle_error(mon, &error);
2045 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
2047 Error *error = NULL;
2048 const char *device = qdict_get_str(qdict, "device");
2050 qmp_block_job_pause(device, &error);
2052 hmp_handle_error(mon, &error);
2055 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
2057 Error *error = NULL;
2058 const char *device = qdict_get_str(qdict, "device");
2060 qmp_block_job_resume(device, &error);
2062 hmp_handle_error(mon, &error);
2065 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
2067 Error *error = NULL;
2068 const char *device = qdict_get_str(qdict, "device");
2070 qmp_block_job_complete(device, &error);
2072 hmp_handle_error(mon, &error);
2075 typedef struct HMPMigrationStatus
2079 bool is_block_migration;
2080 } HMPMigrationStatus;
2082 static void hmp_migrate_status_cb(void *opaque)
2084 HMPMigrationStatus *status = opaque;
2085 MigrationInfo *info;
2087 info = qmp_query_migrate(NULL);
2088 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
2089 info->status == MIGRATION_STATUS_SETUP) {
2090 if (info->has_disk) {
2093 if (info->disk->remaining) {
2094 progress = info->disk->transferred * 100 / info->disk->total;
2099 monitor_printf(status->mon, "Completed %d %%\r", progress);
2100 monitor_flush(status->mon);
2103 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
2105 if (status->is_block_migration) {
2106 monitor_printf(status->mon, "\n");
2108 if (info->has_error_desc) {
2109 error_report("%s", info->error_desc);
2111 monitor_resume(status->mon);
2112 timer_del(status->timer);
2113 timer_free(status->timer);
2117 qapi_free_MigrationInfo(info);
2120 void hmp_migrate(Monitor *mon, const QDict *qdict)
2122 bool detach = qdict_get_try_bool(qdict, "detach", false);
2123 bool blk = qdict_get_try_bool(qdict, "blk", false);
2124 bool inc = qdict_get_try_bool(qdict, "inc", false);
2125 bool resume = qdict_get_try_bool(qdict, "resume", false);
2126 const char *uri = qdict_get_str(qdict, "uri");
2129 qmp_migrate(uri, !!blk, blk, !!inc, inc,
2130 false, false, true, resume, &err);
2132 hmp_handle_error(mon, &err);
2137 HMPMigrationStatus *status;
2139 if (monitor_suspend(mon) < 0) {
2140 monitor_printf(mon, "terminal does not allow synchronous "
2141 "migration, continuing detached\n");
2145 status = g_malloc0(sizeof(*status));
2147 status->is_block_migration = blk || inc;
2148 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
2150 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
2154 void hmp_device_add(Monitor *mon, const QDict *qdict)
2158 qmp_device_add((QDict *)qdict, NULL, &err);
2159 hmp_handle_error(mon, &err);
2162 void hmp_device_del(Monitor *mon, const QDict *qdict)
2164 const char *id = qdict_get_str(qdict, "id");
2167 qmp_device_del(id, &err);
2168 hmp_handle_error(mon, &err);
2171 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
2174 bool win_dmp = qdict_get_try_bool(qdict, "windmp", false);
2175 bool paging = qdict_get_try_bool(qdict, "paging", false);
2176 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
2177 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
2178 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
2179 const char *file = qdict_get_str(qdict, "filename");
2180 bool has_begin = qdict_haskey(qdict, "begin");
2181 bool has_length = qdict_haskey(qdict, "length");
2182 bool has_detach = qdict_haskey(qdict, "detach");
2185 bool detach = false;
2186 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
2189 if (zlib + lzo + snappy + win_dmp > 1) {
2190 error_setg(&err, "only one of '-z|-l|-s|-w' can be set");
2191 hmp_handle_error(mon, &err);
2196 dump_format = DUMP_GUEST_MEMORY_FORMAT_WIN_DMP;
2200 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
2204 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
2208 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
2212 begin = qdict_get_int(qdict, "begin");
2215 length = qdict_get_int(qdict, "length");
2218 detach = qdict_get_bool(qdict, "detach");
2221 prot = g_strconcat("file:", file, NULL);
2223 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
2224 has_length, length, true, dump_format, &err);
2225 hmp_handle_error(mon, &err);
2229 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
2234 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
2239 netdev_add(opts, &err);
2241 qemu_opts_del(opts);
2245 hmp_handle_error(mon, &err);
2248 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
2250 const char *id = qdict_get_str(qdict, "id");
2253 qmp_netdev_del(id, &err);
2254 hmp_handle_error(mon, &err);
2257 void hmp_object_add(Monitor *mon, const QDict *qdict)
2263 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
2265 hmp_handle_error(mon, &err);
2269 obj = user_creatable_add_opts(opts, &err);
2270 qemu_opts_del(opts);
2273 hmp_handle_error(mon, &err);
2280 void hmp_getfd(Monitor *mon, const QDict *qdict)
2282 const char *fdname = qdict_get_str(qdict, "fdname");
2285 qmp_getfd(fdname, &err);
2286 hmp_handle_error(mon, &err);
2289 void hmp_closefd(Monitor *mon, const QDict *qdict)
2291 const char *fdname = qdict_get_str(qdict, "fdname");
2294 qmp_closefd(fdname, &err);
2295 hmp_handle_error(mon, &err);
2298 void hmp_sendkey(Monitor *mon, const QDict *qdict)
2300 const char *keys = qdict_get_str(qdict, "keys");
2301 KeyValueList *keylist, *head = NULL, *tmp = NULL;
2302 int has_hold_time = qdict_haskey(qdict, "hold-time");
2303 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
2305 const char *separator;
2309 separator = qemu_strchrnul(keys, '-');
2310 keyname_len = separator - keys;
2312 /* Be compatible with old interface, convert user inputted "<" */
2313 if (keys[0] == '<' && keyname_len == 1) {
2318 keylist = g_malloc0(sizeof(*keylist));
2319 keylist->value = g_malloc0(sizeof(*keylist->value));
2325 tmp->next = keylist;
2329 if (strstart(keys, "0x", NULL)) {
2331 int value = strtoul(keys, &endp, 0);
2332 assert(endp <= keys + keyname_len);
2333 if (endp != keys + keyname_len) {
2336 keylist->value->type = KEY_VALUE_KIND_NUMBER;
2337 keylist->value->u.number.data = value;
2339 int idx = index_from_key(keys, keyname_len);
2340 if (idx == Q_KEY_CODE__MAX) {
2343 keylist->value->type = KEY_VALUE_KIND_QCODE;
2344 keylist->value->u.qcode.data = idx;
2350 keys = separator + 1;
2353 qmp_send_key(head, has_hold_time, hold_time, &err);
2354 hmp_handle_error(mon, &err);
2357 qapi_free_KeyValueList(head);
2361 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
2365 void hmp_screendump(Monitor *mon, const QDict *qdict)
2367 const char *filename = qdict_get_str(qdict, "filename");
2368 const char *id = qdict_get_try_str(qdict, "device");
2369 int64_t head = qdict_get_try_int(qdict, "head", 0);
2372 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
2373 hmp_handle_error(mon, &err);
2376 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
2378 const char *uri = qdict_get_str(qdict, "uri");
2379 bool writable = qdict_get_try_bool(qdict, "writable", false);
2380 bool all = qdict_get_try_bool(qdict, "all", false);
2381 Error *local_err = NULL;
2382 BlockInfoList *block_list, *info;
2383 SocketAddress *addr;
2385 if (writable && !all) {
2386 error_setg(&local_err, "-w only valid together with -a");
2390 /* First check if the address is valid and start the server. */
2391 addr = socket_parse(uri, &local_err);
2392 if (local_err != NULL) {
2396 nbd_server_start(addr, NULL, NULL, &local_err);
2397 qapi_free_SocketAddress(addr);
2398 if (local_err != NULL) {
2406 /* Then try adding all block devices. If one fails, close all and
2409 block_list = qmp_query_block(NULL);
2411 for (info = block_list; info; info = info->next) {
2412 if (!info->value->has_inserted) {
2416 qmp_nbd_server_add(info->value->device, false, NULL,
2417 true, writable, false, NULL, &local_err);
2419 if (local_err != NULL) {
2420 qmp_nbd_server_stop(NULL);
2425 qapi_free_BlockInfoList(block_list);
2428 hmp_handle_error(mon, &local_err);
2431 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
2433 const char *device = qdict_get_str(qdict, "device");
2434 const char *name = qdict_get_try_str(qdict, "name");
2435 bool writable = qdict_get_try_bool(qdict, "writable", false);
2436 Error *local_err = NULL;
2438 qmp_nbd_server_add(device, !!name, name, true, writable,
2439 false, NULL, &local_err);
2440 hmp_handle_error(mon, &local_err);
2443 void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict)
2445 const char *name = qdict_get_str(qdict, "name");
2446 bool force = qdict_get_try_bool(qdict, "force", false);
2449 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
2450 qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err);
2451 hmp_handle_error(mon, &err);
2454 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
2458 qmp_nbd_server_stop(&err);
2459 hmp_handle_error(mon, &err);
2462 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
2467 error_report("cpu_add is deprecated, please use device_add instead");
2469 cpuid = qdict_get_int(qdict, "id");
2470 qmp_cpu_add(cpuid, &err);
2471 hmp_handle_error(mon, &err);
2474 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2476 const char *args = qdict_get_str(qdict, "args");
2480 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
2482 error_setg(&err, "Parsing chardev args failed");
2484 qemu_chr_new_from_opts(opts, NULL, &err);
2485 qemu_opts_del(opts);
2487 hmp_handle_error(mon, &err);
2490 void hmp_chardev_change(Monitor *mon, const QDict *qdict)
2492 const char *args = qdict_get_str(qdict, "args");
2495 ChardevBackend *backend = NULL;
2496 ChardevReturn *ret = NULL;
2497 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
2500 error_setg(&err, "Parsing chardev args failed");
2504 id = qdict_get_str(qdict, "id");
2505 if (qemu_opts_id(opts)) {
2506 error_setg(&err, "Unexpected 'id' parameter");
2510 backend = qemu_chr_parse_opts(opts, &err);
2515 ret = qmp_chardev_change(id, backend, &err);
2518 qapi_free_ChardevReturn(ret);
2519 qapi_free_ChardevBackend(backend);
2520 qemu_opts_del(opts);
2521 hmp_handle_error(mon, &err);
2524 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2526 Error *local_err = NULL;
2528 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
2529 hmp_handle_error(mon, &local_err);
2532 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
2534 Error *local_err = NULL;
2536 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
2537 hmp_handle_error(mon, &local_err);
2540 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
2543 BlockBackend *local_blk = NULL;
2544 const char* device = qdict_get_str(qdict, "device");
2545 const char* command = qdict_get_str(qdict, "command");
2549 blk = blk_by_name(device);
2551 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
2553 blk = local_blk = blk_new(0, BLK_PERM_ALL);
2554 ret = blk_insert_bs(blk, bs, &err);
2564 * Notably absent: Proper permission management. This is sad, but it seems
2565 * almost impossible to achieve without changing the semantics and thereby
2566 * limiting the use cases of the qemu-io HMP command.
2568 * In an ideal world we would unconditionally create a new BlockBackend for
2569 * qemuio_command(), but we have commands like 'reopen' and want them to
2570 * take effect on the exact BlockBackend whose name the user passed instead
2571 * of just on a temporary copy of it.
2573 * Another problem is that deleting the temporary BlockBackend involves
2574 * draining all requests on it first, but some qemu-iotests cases want to
2575 * issue multiple aio_read/write requests and expect them to complete in
2576 * the background while the monitor has already returned.
2578 * This is also what prevents us from saving the original permissions and
2579 * restoring them later: We can't revoke permissions until all requests
2580 * have completed, and we don't know when that is nor can we really let
2581 * anything else run before we have revoken them to avoid race conditions.
2583 * What happens now is that command() in qemu-io-cmds.c can extend the
2584 * permissions if necessary for the qemu-io command. And they simply stay
2585 * extended, possibly resulting in a read-only guest device keeping write
2586 * permissions. Ugly, but it appears to be the lesser evil.
2588 qemuio_command(blk, command);
2591 blk_unref(local_blk);
2592 hmp_handle_error(mon, &err);
2595 void hmp_object_del(Monitor *mon, const QDict *qdict)
2597 const char *id = qdict_get_str(qdict, "id");
2600 user_creatable_del(id, &err);
2601 hmp_handle_error(mon, &err);
2604 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
2607 MemdevList *memdev_list = qmp_query_memdev(&err);
2608 MemdevList *m = memdev_list;
2613 v = string_output_visitor_new(false, &str);
2614 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
2615 monitor_printf(mon, "memory backend: %s\n", m->value->id);
2616 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
2617 monitor_printf(mon, " merge: %s\n",
2618 m->value->merge ? "true" : "false");
2619 monitor_printf(mon, " dump: %s\n",
2620 m->value->dump ? "true" : "false");
2621 monitor_printf(mon, " prealloc: %s\n",
2622 m->value->prealloc ? "true" : "false");
2623 monitor_printf(mon, " policy: %s\n",
2624 HostMemPolicy_str(m->value->policy));
2625 visit_complete(v, &str);
2626 monitor_printf(mon, " host nodes: %s\n", str);
2633 monitor_printf(mon, "\n");
2635 qapi_free_MemdevList(memdev_list);
2636 hmp_handle_error(mon, &err);
2639 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2642 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2643 MemoryDeviceInfoList *info;
2644 MemoryDeviceInfo *value;
2645 PCDIMMDeviceInfo *di;
2647 for (info = info_list; info; info = info->next) {
2648 value = info->value;
2651 switch (value->type) {
2652 case MEMORY_DEVICE_INFO_KIND_DIMM:
2653 di = value->u.dimm.data;
2656 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
2657 di = value->u.nvdimm.data;
2666 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2667 MemoryDeviceInfoKind_str(value->type),
2668 di->id ? di->id : "");
2669 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2670 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2671 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2672 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2673 monitor_printf(mon, " memdev: %s\n", di->memdev);
2674 monitor_printf(mon, " hotplugged: %s\n",
2675 di->hotplugged ? "true" : "false");
2676 monitor_printf(mon, " hotpluggable: %s\n",
2677 di->hotpluggable ? "true" : "false");
2682 qapi_free_MemoryDeviceInfoList(info_list);
2683 hmp_handle_error(mon, &err);
2686 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2688 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2689 IOThreadInfoList *info;
2690 IOThreadInfo *value;
2692 for (info = info_list; info; info = info->next) {
2693 value = info->value;
2694 monitor_printf(mon, "%s:\n", value->id);
2695 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
2696 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2697 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
2698 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
2701 qapi_free_IOThreadInfoList(info_list);
2704 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2706 const char *path = qdict_get_try_str(qdict, "path");
2707 ObjectPropertyInfoList *list;
2711 monitor_printf(mon, "/\n");
2715 list = qmp_qom_list(path, &err);
2717 ObjectPropertyInfoList *start = list;
2718 while (list != NULL) {
2719 ObjectPropertyInfo *value = list->value;
2721 monitor_printf(mon, "%s (%s)\n",
2722 value->name, value->type);
2725 qapi_free_ObjectPropertyInfoList(start);
2727 hmp_handle_error(mon, &err);
2730 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2732 const char *path = qdict_get_str(qdict, "path");
2733 const char *property = qdict_get_str(qdict, "property");
2734 const char *value = qdict_get_str(qdict, "value");
2736 bool ambiguous = false;
2739 obj = object_resolve_path(path, &ambiguous);
2741 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2742 "Device '%s' not found", path);
2745 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2747 object_property_parse(obj, value, property, &err);
2749 hmp_handle_error(mon, &err);
2752 void hmp_rocker(Monitor *mon, const QDict *qdict)
2754 const char *name = qdict_get_str(qdict, "name");
2755 RockerSwitch *rocker;
2758 rocker = qmp_query_rocker(name, &err);
2760 hmp_handle_error(mon, &err);
2764 monitor_printf(mon, "name: %s\n", rocker->name);
2765 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2766 monitor_printf(mon, "ports: %d\n", rocker->ports);
2768 qapi_free_RockerSwitch(rocker);
2771 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2773 RockerPortList *list, *port;
2774 const char *name = qdict_get_str(qdict, "name");
2777 list = qmp_query_rocker_ports(name, &err);
2779 hmp_handle_error(mon, &err);
2783 monitor_printf(mon, " ena/ speed/ auto\n");
2784 monitor_printf(mon, " port link duplex neg?\n");
2786 for (port = list; port; port = port->next) {
2787 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2789 port->value->enabled ? port->value->link_up ?
2790 "up" : "down" : "!ena",
2791 port->value->speed == 10000 ? "10G" : "??",
2792 port->value->duplex ? "FD" : "HD",
2793 port->value->autoneg ? "Yes" : "No");
2796 qapi_free_RockerPortList(list);
2799 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2801 RockerOfDpaFlowList *list, *info;
2802 const char *name = qdict_get_str(qdict, "name");
2803 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2806 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2808 hmp_handle_error(mon, &err);
2812 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2814 for (info = list; info; info = info->next) {
2815 RockerOfDpaFlow *flow = info->value;
2816 RockerOfDpaFlowKey *key = flow->key;
2817 RockerOfDpaFlowMask *mask = flow->mask;
2818 RockerOfDpaFlowAction *action = flow->action;
2821 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2822 key->priority, key->tbl_id, flow->hits);
2824 monitor_printf(mon, "%-4d %-3d ",
2825 key->priority, key->tbl_id);
2828 if (key->has_in_pport) {
2829 monitor_printf(mon, " pport %d", key->in_pport);
2830 if (mask->has_in_pport) {
2831 monitor_printf(mon, "(0x%x)", mask->in_pport);
2835 if (key->has_vlan_id) {
2836 monitor_printf(mon, " vlan %d",
2837 key->vlan_id & VLAN_VID_MASK);
2838 if (mask->has_vlan_id) {
2839 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2843 if (key->has_tunnel_id) {
2844 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2845 if (mask->has_tunnel_id) {
2846 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2850 if (key->has_eth_type) {
2851 switch (key->eth_type) {
2853 monitor_printf(mon, " ARP");
2856 monitor_printf(mon, " IP");
2859 monitor_printf(mon, " IPv6");
2862 monitor_printf(mon, " LACP");
2865 monitor_printf(mon, " LLDP");
2868 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2873 if (key->has_eth_src) {
2874 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2875 (mask->has_eth_src) &&
2876 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2877 monitor_printf(mon, " src <any mcast/bcast>");
2878 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2879 (mask->has_eth_src) &&
2880 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2881 monitor_printf(mon, " src <any ucast>");
2883 monitor_printf(mon, " src %s", key->eth_src);
2884 if (mask->has_eth_src) {
2885 monitor_printf(mon, "(%s)", mask->eth_src);
2890 if (key->has_eth_dst) {
2891 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2892 (mask->has_eth_dst) &&
2893 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2894 monitor_printf(mon, " dst <any mcast/bcast>");
2895 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2896 (mask->has_eth_dst) &&
2897 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2898 monitor_printf(mon, " dst <any ucast>");
2900 monitor_printf(mon, " dst %s", key->eth_dst);
2901 if (mask->has_eth_dst) {
2902 monitor_printf(mon, "(%s)", mask->eth_dst);
2907 if (key->has_ip_proto) {
2908 monitor_printf(mon, " proto %d", key->ip_proto);
2909 if (mask->has_ip_proto) {
2910 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2914 if (key->has_ip_tos) {
2915 monitor_printf(mon, " TOS %d", key->ip_tos);
2916 if (mask->has_ip_tos) {
2917 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2921 if (key->has_ip_dst) {
2922 monitor_printf(mon, " dst %s", key->ip_dst);
2925 if (action->has_goto_tbl || action->has_group_id ||
2926 action->has_new_vlan_id) {
2927 monitor_printf(mon, " -->");
2930 if (action->has_new_vlan_id) {
2931 monitor_printf(mon, " apply new vlan %d",
2932 ntohs(action->new_vlan_id));
2935 if (action->has_group_id) {
2936 monitor_printf(mon, " write group 0x%08x", action->group_id);
2939 if (action->has_goto_tbl) {
2940 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2943 monitor_printf(mon, "\n");
2946 qapi_free_RockerOfDpaFlowList(list);
2949 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2951 RockerOfDpaGroupList *list, *g;
2952 const char *name = qdict_get_str(qdict, "name");
2953 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2957 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2959 hmp_handle_error(mon, &err);
2963 monitor_printf(mon, "id (decode) --> buckets\n");
2965 for (g = list; g; g = g->next) {
2966 RockerOfDpaGroup *group = g->value;
2968 monitor_printf(mon, "0x%08x", group->id);
2970 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2971 group->type == 1 ? "L2 rewrite" :
2972 group->type == 2 ? "L3 unicast" :
2973 group->type == 3 ? "L2 multicast" :
2974 group->type == 4 ? "L2 flood" :
2975 group->type == 5 ? "L3 interface" :
2976 group->type == 6 ? "L3 multicast" :
2977 group->type == 7 ? "L3 ECMP" :
2978 group->type == 8 ? "L2 overlay" :
2981 if (group->has_vlan_id) {
2982 monitor_printf(mon, " vlan %d", group->vlan_id);
2985 if (group->has_pport) {
2986 monitor_printf(mon, " pport %d", group->pport);
2989 if (group->has_index) {
2990 monitor_printf(mon, " index %d", group->index);
2993 monitor_printf(mon, ") -->");
2995 if (group->has_set_vlan_id && group->set_vlan_id) {
2997 monitor_printf(mon, " set vlan %d",
2998 group->set_vlan_id & VLAN_VID_MASK);
3001 if (group->has_set_eth_src) {
3004 monitor_printf(mon, " set");
3006 monitor_printf(mon, " src %s", group->set_eth_src);
3009 if (group->has_set_eth_dst) {
3012 monitor_printf(mon, " set");
3014 monitor_printf(mon, " dst %s", group->set_eth_dst);
3019 if (group->has_ttl_check && group->ttl_check) {
3020 monitor_printf(mon, " check TTL");
3023 if (group->has_group_id && group->group_id) {
3024 monitor_printf(mon, " group id 0x%08x", group->group_id);
3027 if (group->has_pop_vlan && group->pop_vlan) {
3028 monitor_printf(mon, " pop vlan");
3031 if (group->has_out_pport) {
3032 monitor_printf(mon, " out pport %d", group->out_pport);
3035 if (group->has_group_ids) {
3036 struct uint32List *id;
3038 monitor_printf(mon, " groups [");
3039 for (id = group->group_ids; id; id = id->next) {
3040 monitor_printf(mon, "0x%08x", id->value);
3042 monitor_printf(mon, ",");
3045 monitor_printf(mon, "]");
3048 monitor_printf(mon, "\n");
3051 qapi_free_RockerOfDpaGroupList(list);
3054 void hmp_info_dump(Monitor *mon, const QDict *qdict)
3056 DumpQueryResult *result = qmp_query_dump(NULL);
3058 assert(result && result->status < DUMP_STATUS__MAX);
3059 monitor_printf(mon, "Status: %s\n", DumpStatus_str(result->status));
3061 if (result->status == DUMP_STATUS_ACTIVE) {
3063 assert(result->total != 0);
3064 percent = 100.0 * result->completed / result->total;
3065 monitor_printf(mon, "Finished: %.2f %%\n", percent);
3068 qapi_free_DumpQueryResult(result);
3071 void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
3073 ram_block_dump(mon);
3076 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
3079 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
3080 HotpluggableCPUList *saved = l;
3081 CpuInstanceProperties *c;
3084 hmp_handle_error(mon, &err);
3088 monitor_printf(mon, "Hotpluggable CPUs:\n");
3090 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
3091 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
3092 l->value->vcpus_count);
3093 if (l->value->has_qom_path) {
3094 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
3097 c = l->value->props;
3098 monitor_printf(mon, " CPUInstance Properties:\n");
3099 if (c->has_node_id) {
3100 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
3102 if (c->has_socket_id) {
3103 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
3105 if (c->has_core_id) {
3106 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
3108 if (c->has_thread_id) {
3109 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
3115 qapi_free_HotpluggableCPUList(saved);
3118 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
3121 GuidInfo *info = qmp_query_vm_generation_id(&err);
3123 monitor_printf(mon, "%s\n", info->guid);
3125 hmp_handle_error(mon, &err);
3126 qapi_free_GuidInfo(info);
3129 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
3132 MemoryInfo *info = qmp_query_memory_size_summary(&err);
3134 monitor_printf(mon, "base memory: %" PRIu64 "\n",
3137 if (info->has_plugged_memory) {
3138 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
3139 info->plugged_memory);
3142 qapi_free_MemoryInfo(info);
3144 hmp_handle_error(mon, &err);