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 "migration/snapshot.h"
55 #include "migration/misc.h"
58 #include <spice/enums.h>
61 static void hmp_handle_error(Monitor *mon, Error **errp)
65 error_reportf_err(*errp, "Error: ");
69 void hmp_info_name(Monitor *mon, const QDict *qdict)
73 info = qmp_query_name(NULL);
75 monitor_printf(mon, "%s\n", info->name);
77 qapi_free_NameInfo(info);
80 void hmp_info_version(Monitor *mon, const QDict *qdict)
84 info = qmp_query_version(NULL);
86 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
87 info->qemu->major, info->qemu->minor, info->qemu->micro,
90 qapi_free_VersionInfo(info);
93 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
97 info = qmp_query_kvm(NULL);
98 monitor_printf(mon, "kvm support: ");
100 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
102 monitor_printf(mon, "not compiled\n");
105 qapi_free_KvmInfo(info);
108 void hmp_info_status(Monitor *mon, const QDict *qdict)
112 info = qmp_query_status(NULL);
114 monitor_printf(mon, "VM status: %s%s",
115 info->running ? "running" : "paused",
116 info->singlestep ? " (single step mode)" : "");
118 if (!info->running && info->status != RUN_STATE_PAUSED) {
119 monitor_printf(mon, " (%s)", RunState_str(info->status));
122 monitor_printf(mon, "\n");
124 qapi_free_StatusInfo(info);
127 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
131 info = qmp_query_uuid(NULL);
132 monitor_printf(mon, "%s\n", info->UUID);
133 qapi_free_UuidInfo(info);
136 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
138 ChardevInfoList *char_info, *info;
140 char_info = qmp_query_chardev(NULL);
141 for (info = char_info; info; info = info->next) {
142 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
143 info->value->filename);
146 qapi_free_ChardevInfoList(char_info);
149 void hmp_info_mice(Monitor *mon, const QDict *qdict)
151 MouseInfoList *mice_list, *mouse;
153 mice_list = qmp_query_mice(NULL);
155 monitor_printf(mon, "No mouse devices connected\n");
159 for (mouse = mice_list; mouse; mouse = mouse->next) {
160 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
161 mouse->value->current ? '*' : ' ',
162 mouse->value->index, mouse->value->name,
163 mouse->value->absolute ? " (absolute)" : "");
166 qapi_free_MouseInfoList(mice_list);
169 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
172 MigrationCapabilityStatusList *caps, *cap;
174 info = qmp_query_migrate(NULL);
175 caps = qmp_query_migrate_capabilities(NULL);
177 migration_global_dump(mon);
179 /* do not display parameters during setup */
180 if (info->has_status && caps) {
181 monitor_printf(mon, "capabilities: ");
182 for (cap = caps; cap; cap = cap->next) {
183 monitor_printf(mon, "%s: %s ",
184 MigrationCapability_str(cap->value->capability),
185 cap->value->state ? "on" : "off");
187 monitor_printf(mon, "\n");
190 if (info->has_status) {
191 monitor_printf(mon, "Migration status: %s",
192 MigrationStatus_str(info->status));
193 if (info->status == MIGRATION_STATUS_FAILED &&
194 info->has_error_desc) {
195 monitor_printf(mon, " (%s)\n", info->error_desc);
197 monitor_printf(mon, "\n");
200 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
202 if (info->has_expected_downtime) {
203 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
204 info->expected_downtime);
206 if (info->has_downtime) {
207 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
210 if (info->has_setup_time) {
211 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
217 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
218 info->ram->transferred >> 10);
219 monitor_printf(mon, "throughput: %0.2f mbps\n",
221 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
222 info->ram->remaining >> 10);
223 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
224 info->ram->total >> 10);
225 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
226 info->ram->duplicate);
227 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
229 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
231 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
232 info->ram->normal_bytes >> 10);
233 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
234 info->ram->dirty_sync_count);
235 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
236 info->ram->page_size >> 10);
237 monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n",
238 info->ram->multifd_bytes >> 10);
239 monitor_printf(mon, "pages-per-second: %" PRIu64 "\n",
240 info->ram->pages_per_second);
242 if (info->ram->dirty_pages_rate) {
243 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
244 info->ram->dirty_pages_rate);
246 if (info->ram->postcopy_requests) {
247 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
248 info->ram->postcopy_requests);
252 if (info->has_disk) {
253 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
254 info->disk->transferred >> 10);
255 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
256 info->disk->remaining >> 10);
257 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
258 info->disk->total >> 10);
261 if (info->has_xbzrle_cache) {
262 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
263 info->xbzrle_cache->cache_size);
264 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
265 info->xbzrle_cache->bytes >> 10);
266 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
267 info->xbzrle_cache->pages);
268 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
269 info->xbzrle_cache->cache_miss);
270 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
271 info->xbzrle_cache->cache_miss_rate);
272 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
273 info->xbzrle_cache->overflow);
276 if (info->has_compression) {
277 monitor_printf(mon, "compression pages: %" PRIu64 " pages\n",
278 info->compression->pages);
279 monitor_printf(mon, "compression busy: %" PRIu64 "\n",
280 info->compression->busy);
281 monitor_printf(mon, "compression busy rate: %0.2f\n",
282 info->compression->busy_rate);
283 monitor_printf(mon, "compressed size: %" PRIu64 "\n",
284 info->compression->compressed_size);
285 monitor_printf(mon, "compression rate: %0.2f\n",
286 info->compression->compression_rate);
289 if (info->has_cpu_throttle_percentage) {
290 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
291 info->cpu_throttle_percentage);
294 if (info->has_postcopy_blocktime) {
295 monitor_printf(mon, "postcopy blocktime: %u\n",
296 info->postcopy_blocktime);
299 if (info->has_postcopy_vcpu_blocktime) {
302 v = string_output_visitor_new(false, &str);
303 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NULL);
304 visit_complete(v, &str);
305 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
309 qapi_free_MigrationInfo(info);
310 qapi_free_MigrationCapabilityStatusList(caps);
313 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
315 MigrationCapabilityStatusList *caps, *cap;
317 caps = qmp_query_migrate_capabilities(NULL);
320 for (cap = caps; cap; cap = cap->next) {
321 monitor_printf(mon, "%s: %s\n",
322 MigrationCapability_str(cap->value->capability),
323 cap->value->state ? "on" : "off");
327 qapi_free_MigrationCapabilityStatusList(caps);
330 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
332 MigrationParameters *params;
334 params = qmp_query_migrate_parameters(NULL);
337 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
338 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL),
339 params->announce_initial);
340 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
341 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX),
342 params->announce_max);
343 monitor_printf(mon, "%s: %" PRIu64 "\n",
344 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS),
345 params->announce_rounds);
346 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
347 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP),
348 params->announce_step);
349 assert(params->has_compress_level);
350 monitor_printf(mon, "%s: %u\n",
351 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
352 params->compress_level);
353 assert(params->has_compress_threads);
354 monitor_printf(mon, "%s: %u\n",
355 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
356 params->compress_threads);
357 assert(params->has_compress_wait_thread);
358 monitor_printf(mon, "%s: %s\n",
359 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD),
360 params->compress_wait_thread ? "on" : "off");
361 assert(params->has_decompress_threads);
362 monitor_printf(mon, "%s: %u\n",
363 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
364 params->decompress_threads);
365 assert(params->has_cpu_throttle_initial);
366 monitor_printf(mon, "%s: %u\n",
367 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
368 params->cpu_throttle_initial);
369 assert(params->has_cpu_throttle_increment);
370 monitor_printf(mon, "%s: %u\n",
371 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
372 params->cpu_throttle_increment);
373 assert(params->has_max_cpu_throttle);
374 monitor_printf(mon, "%s: %u\n",
375 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE),
376 params->max_cpu_throttle);
377 assert(params->has_tls_creds);
378 monitor_printf(mon, "%s: '%s'\n",
379 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
381 assert(params->has_tls_hostname);
382 monitor_printf(mon, "%s: '%s'\n",
383 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
384 params->tls_hostname);
385 assert(params->has_max_bandwidth);
386 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
387 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
388 params->max_bandwidth);
389 assert(params->has_downtime_limit);
390 monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n",
391 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
392 params->downtime_limit);
393 assert(params->has_x_checkpoint_delay);
394 monitor_printf(mon, "%s: %u\n",
395 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
396 params->x_checkpoint_delay);
397 assert(params->has_block_incremental);
398 monitor_printf(mon, "%s: %s\n",
399 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
400 params->block_incremental ? "on" : "off");
401 monitor_printf(mon, "%s: %u\n",
402 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_CHANNELS),
403 params->x_multifd_channels);
404 monitor_printf(mon, "%s: %u\n",
405 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT),
406 params->x_multifd_page_count);
407 monitor_printf(mon, "%s: %" PRIu64 "\n",
408 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
409 params->xbzrle_cache_size);
410 monitor_printf(mon, "%s: %" PRIu64 "\n",
411 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
412 params->max_postcopy_bandwidth);
415 qapi_free_MigrationParameters(params);
418 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
420 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
421 qmp_query_migrate_cache_size(NULL) >> 10);
424 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
426 CpuInfoFastList *cpu_list, *cpu;
428 cpu_list = qmp_query_cpus_fast(NULL);
430 for (cpu = cpu_list; cpu; cpu = cpu->next) {
433 if (cpu->value->cpu_index == monitor_get_cpu_index()) {
437 monitor_printf(mon, "%c CPU #%" PRId64 ":", active,
438 cpu->value->cpu_index);
439 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
442 qapi_free_CpuInfoFastList(cpu_list);
445 static void print_block_info(Monitor *mon, BlockInfo *info,
446 BlockDeviceInfo *inserted, bool verbose)
448 ImageInfo *image_info;
450 assert(!info || !info->has_inserted || info->inserted == inserted);
452 if (info && *info->device) {
453 monitor_printf(mon, "%s", info->device);
454 if (inserted && inserted->has_node_name) {
455 monitor_printf(mon, " (%s)", inserted->node_name);
458 assert(info || inserted);
459 monitor_printf(mon, "%s",
460 inserted && inserted->has_node_name ? inserted->node_name
461 : info && info->has_qdev ? info->qdev
466 monitor_printf(mon, ": %s (%s%s%s)\n",
469 inserted->ro ? ", read-only" : "",
470 inserted->encrypted ? ", encrypted" : "");
472 monitor_printf(mon, ": [not inserted]\n");
476 if (info->has_qdev) {
477 monitor_printf(mon, " Attached to: %s\n", info->qdev);
479 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
480 monitor_printf(mon, " I/O status: %s\n",
481 BlockDeviceIoStatus_str(info->io_status));
484 if (info->removable) {
485 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
486 info->locked ? "" : "not ",
487 info->tray_open ? "open" : "closed");
496 monitor_printf(mon, " Cache mode: %s%s%s\n",
497 inserted->cache->writeback ? "writeback" : "writethrough",
498 inserted->cache->direct ? ", direct" : "",
499 inserted->cache->no_flush ? ", ignore flushes" : "");
501 if (inserted->has_backing_file) {
504 "(chain depth: %" PRId64 ")\n",
505 inserted->backing_file,
506 inserted->backing_file_depth);
509 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
510 monitor_printf(mon, " Detect zeroes: %s\n",
511 BlockdevDetectZeroesOptions_str(inserted->detect_zeroes));
514 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
515 inserted->iops || inserted->iops_rd || inserted->iops_wr)
517 monitor_printf(mon, " I/O throttling: bps=%" PRId64
518 " bps_rd=%" PRId64 " bps_wr=%" PRId64
520 " bps_rd_max=%" PRId64
521 " bps_wr_max=%" PRId64
522 " iops=%" PRId64 " iops_rd=%" PRId64
525 " iops_rd_max=%" PRId64
526 " iops_wr_max=%" PRId64
527 " iops_size=%" PRId64
533 inserted->bps_rd_max,
534 inserted->bps_wr_max,
539 inserted->iops_rd_max,
540 inserted->iops_wr_max,
546 monitor_printf(mon, "\nImages:\n");
547 image_info = inserted->image;
549 bdrv_image_info_dump((fprintf_function)monitor_printf,
551 if (image_info->has_backing_image) {
552 image_info = image_info->backing_image;
560 void hmp_info_block(Monitor *mon, const QDict *qdict)
562 BlockInfoList *block_list, *info;
563 BlockDeviceInfoList *blockdev_list, *blockdev;
564 const char *device = qdict_get_try_str(qdict, "device");
565 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
566 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
567 bool printed = false;
569 /* Print BlockBackend information */
571 block_list = qmp_query_block(NULL);
576 for (info = block_list; info; info = info->next) {
577 if (device && strcmp(device, info->value->device)) {
581 if (info != block_list) {
582 monitor_printf(mon, "\n");
585 print_block_info(mon, info->value, info->value->has_inserted
586 ? info->value->inserted : NULL,
591 qapi_free_BlockInfoList(block_list);
593 if ((!device && !nodes) || printed) {
597 /* Print node information */
598 blockdev_list = qmp_query_named_block_nodes(NULL);
599 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
600 assert(blockdev->value->has_node_name);
601 if (device && strcmp(device, blockdev->value->node_name)) {
605 if (blockdev != blockdev_list) {
606 monitor_printf(mon, "\n");
609 print_block_info(mon, NULL, blockdev->value, verbose);
611 qapi_free_BlockDeviceInfoList(blockdev_list);
614 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
616 BlockStatsList *stats_list, *stats;
618 stats_list = qmp_query_blockstats(false, false, NULL);
620 for (stats = stats_list; stats; stats = stats->next) {
621 if (!stats->value->has_device) {
625 monitor_printf(mon, "%s:", stats->value->device);
626 monitor_printf(mon, " rd_bytes=%" PRId64
628 " rd_operations=%" PRId64
629 " wr_operations=%" PRId64
630 " flush_operations=%" PRId64
631 " wr_total_time_ns=%" PRId64
632 " rd_total_time_ns=%" PRId64
633 " flush_total_time_ns=%" PRId64
634 " rd_merged=%" PRId64
635 " wr_merged=%" PRId64
636 " idle_time_ns=%" PRId64
638 stats->value->stats->rd_bytes,
639 stats->value->stats->wr_bytes,
640 stats->value->stats->rd_operations,
641 stats->value->stats->wr_operations,
642 stats->value->stats->flush_operations,
643 stats->value->stats->wr_total_time_ns,
644 stats->value->stats->rd_total_time_ns,
645 stats->value->stats->flush_total_time_ns,
646 stats->value->stats->rd_merged,
647 stats->value->stats->wr_merged,
648 stats->value->stats->idle_time_ns);
651 qapi_free_BlockStatsList(stats_list);
655 /* Helper for hmp_info_vnc_clients, _servers */
656 static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
659 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
663 NetworkAddressFamily_str(info->family),
664 info->websocket ? " (Websocket)" : "");
667 /* Helper displaying and auth and crypt info */
668 static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
670 VncVencryptSubAuth *vencrypt)
672 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
673 VncPrimaryAuth_str(auth),
674 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
677 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
680 VncClientInfo *cinfo = client->value;
682 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
683 monitor_printf(mon, " x509_dname: %s\n",
684 cinfo->has_x509_dname ?
685 cinfo->x509_dname : "none");
686 monitor_printf(mon, " sasl_username: %s\n",
687 cinfo->has_sasl_username ?
688 cinfo->sasl_username : "none");
690 client = client->next;
694 static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
697 VncServerInfo2 *sinfo = server->value;
698 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
699 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
700 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
701 server = server->next;
705 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
707 VncInfo2List *info2l;
710 info2l = qmp_query_vnc_servers(&err);
712 hmp_handle_error(mon, &err);
716 monitor_printf(mon, "None\n");
721 VncInfo2 *info = info2l->value;
722 monitor_printf(mon, "%s:\n", info->id);
723 hmp_info_vnc_servers(mon, info->server);
724 hmp_info_vnc_clients(mon, info->clients);
726 /* The server entry displays its auth, we only
727 * need to display in the case of 'reverse' connections
728 * where there's no server.
730 hmp_info_vnc_authcrypt(mon, " ", info->auth,
731 info->has_vencrypt ? &info->vencrypt : NULL);
733 if (info->has_display) {
734 monitor_printf(mon, " Display: %s\n", info->display);
736 info2l = info2l->next;
739 qapi_free_VncInfo2List(info2l);
745 void hmp_info_spice(Monitor *mon, const QDict *qdict)
747 SpiceChannelList *chan;
749 const char *channel_name;
750 const char * const channel_names[] = {
751 [SPICE_CHANNEL_MAIN] = "main",
752 [SPICE_CHANNEL_DISPLAY] = "display",
753 [SPICE_CHANNEL_INPUTS] = "inputs",
754 [SPICE_CHANNEL_CURSOR] = "cursor",
755 [SPICE_CHANNEL_PLAYBACK] = "playback",
756 [SPICE_CHANNEL_RECORD] = "record",
757 [SPICE_CHANNEL_TUNNEL] = "tunnel",
758 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
759 [SPICE_CHANNEL_USBREDIR] = "usbredir",
760 [SPICE_CHANNEL_PORT] = "port",
762 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
763 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
764 * as quick fix for build failures with older versions. */
765 [SPICE_CHANNEL_WEBDAV] = "webdav",
769 info = qmp_query_spice(NULL);
771 if (!info->enabled) {
772 monitor_printf(mon, "Server: disabled\n");
776 monitor_printf(mon, "Server:\n");
777 if (info->has_port) {
778 monitor_printf(mon, " address: %s:%" PRId64 "\n",
779 info->host, info->port);
781 if (info->has_tls_port) {
782 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
783 info->host, info->tls_port);
785 monitor_printf(mon, " migrated: %s\n",
786 info->migrated ? "true" : "false");
787 monitor_printf(mon, " auth: %s\n", info->auth);
788 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
789 monitor_printf(mon, " mouse-mode: %s\n",
790 SpiceQueryMouseMode_str(info->mouse_mode));
792 if (!info->has_channels || info->channels == NULL) {
793 monitor_printf(mon, "Channels: none\n");
795 for (chan = info->channels; chan; chan = chan->next) {
796 monitor_printf(mon, "Channel:\n");
797 monitor_printf(mon, " address: %s:%s%s\n",
798 chan->value->host, chan->value->port,
799 chan->value->tls ? " [tls]" : "");
800 monitor_printf(mon, " session: %" PRId64 "\n",
801 chan->value->connection_id);
802 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
803 chan->value->channel_type, chan->value->channel_id);
805 channel_name = "unknown";
806 if (chan->value->channel_type > 0 &&
807 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
808 channel_names[chan->value->channel_type]) {
809 channel_name = channel_names[chan->value->channel_type];
812 monitor_printf(mon, " channel name: %s\n", channel_name);
817 qapi_free_SpiceInfo(info);
821 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
826 info = qmp_query_balloon(&err);
828 hmp_handle_error(mon, &err);
832 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
834 qapi_free_BalloonInfo(info);
837 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
839 PciMemoryRegionList *region;
841 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
842 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
843 dev->slot, dev->function);
844 monitor_printf(mon, " ");
846 if (dev->class_info->has_desc) {
847 monitor_printf(mon, "%s", dev->class_info->desc);
849 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
852 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
853 dev->id->vendor, dev->id->device);
854 if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) {
855 monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n",
856 dev->id->subsystem_vendor, dev->id->subsystem);
860 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
863 if (dev->has_pci_bridge) {
864 monitor_printf(mon, " BUS %" PRId64 ".\n",
865 dev->pci_bridge->bus->number);
866 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
867 dev->pci_bridge->bus->secondary);
868 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
869 dev->pci_bridge->bus->subordinate);
871 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
872 dev->pci_bridge->bus->io_range->base,
873 dev->pci_bridge->bus->io_range->limit);
876 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
877 dev->pci_bridge->bus->memory_range->base,
878 dev->pci_bridge->bus->memory_range->limit);
880 monitor_printf(mon, " prefetchable memory range "
881 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
882 dev->pci_bridge->bus->prefetchable_range->base,
883 dev->pci_bridge->bus->prefetchable_range->limit);
886 for (region = dev->regions; region; region = region->next) {
889 addr = region->value->address;
890 size = region->value->size;
892 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
894 if (!strcmp(region->value->type, "io")) {
895 monitor_printf(mon, "I/O at 0x%04" PRIx64
896 " [0x%04" PRIx64 "].\n",
897 addr, addr + size - 1);
899 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
900 " [0x%08" PRIx64 "].\n",
901 region->value->mem_type_64 ? 64 : 32,
902 region->value->prefetch ? " prefetchable" : "",
903 addr, addr + size - 1);
907 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
909 if (dev->has_pci_bridge) {
910 if (dev->pci_bridge->has_devices) {
911 PciDeviceInfoList *cdev;
912 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
913 hmp_info_pci_device(mon, cdev->value);
919 static int hmp_info_irq_foreach(Object *obj, void *opaque)
921 InterruptStatsProvider *intc;
922 InterruptStatsProviderClass *k;
923 Monitor *mon = opaque;
925 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
926 intc = INTERRUPT_STATS_PROVIDER(obj);
927 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
928 uint64_t *irq_counts;
929 unsigned int nb_irqs, i;
930 if (k->get_statistics &&
931 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
933 monitor_printf(mon, "IRQ statistics for %s:\n",
934 object_get_typename(obj));
935 for (i = 0; i < nb_irqs; i++) {
936 if (irq_counts[i] > 0) {
937 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
943 monitor_printf(mon, "IRQ statistics not available for %s.\n",
944 object_get_typename(obj));
951 void hmp_info_irq(Monitor *mon, const QDict *qdict)
953 object_child_foreach_recursive(object_get_root(),
954 hmp_info_irq_foreach, mon);
957 static int hmp_info_pic_foreach(Object *obj, void *opaque)
959 InterruptStatsProvider *intc;
960 InterruptStatsProviderClass *k;
961 Monitor *mon = opaque;
963 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
964 intc = INTERRUPT_STATS_PROVIDER(obj);
965 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
967 k->print_info(intc, mon);
969 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
970 object_get_typename(obj));
977 void hmp_info_pic(Monitor *mon, const QDict *qdict)
979 object_child_foreach_recursive(object_get_root(),
980 hmp_info_pic_foreach, mon);
983 void hmp_info_pci(Monitor *mon, const QDict *qdict)
985 PciInfoList *info_list, *info;
988 info_list = qmp_query_pci(&err);
990 monitor_printf(mon, "PCI devices not supported\n");
995 for (info = info_list; info; info = info->next) {
996 PciDeviceInfoList *dev;
998 for (dev = info->value->devices; dev; dev = dev->next) {
999 hmp_info_pci_device(mon, dev->value);
1003 qapi_free_PciInfoList(info_list);
1006 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
1008 BlockJobInfoList *list;
1011 list = qmp_query_block_jobs(&err);
1015 monitor_printf(mon, "No active jobs\n");
1020 if (strcmp(list->value->type, "stream") == 0) {
1021 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
1022 " of %" PRId64 " bytes, speed limit %" PRId64
1024 list->value->device,
1025 list->value->offset,
1027 list->value->speed);
1029 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
1030 " of %" PRId64 " bytes, speed limit %" PRId64
1033 list->value->device,
1034 list->value->offset,
1036 list->value->speed);
1041 qapi_free_BlockJobInfoList(list);
1044 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
1046 TPMInfoList *info_list, *info;
1049 TPMPassthroughOptions *tpo;
1050 TPMEmulatorOptions *teo;
1052 info_list = qmp_query_tpm(&err);
1054 monitor_printf(mon, "TPM device not supported\n");
1060 monitor_printf(mon, "TPM device:\n");
1063 for (info = info_list; info; info = info->next) {
1064 TPMInfo *ti = info->value;
1065 monitor_printf(mon, " tpm%d: model=%s\n",
1066 c, TpmModel_str(ti->model));
1068 monitor_printf(mon, " \\ %s: type=%s",
1069 ti->id, TpmTypeOptionsKind_str(ti->options->type));
1071 switch (ti->options->type) {
1072 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
1073 tpo = ti->options->u.passthrough.data;
1074 monitor_printf(mon, "%s%s%s%s",
1075 tpo->has_path ? ",path=" : "",
1076 tpo->has_path ? tpo->path : "",
1077 tpo->has_cancel_path ? ",cancel-path=" : "",
1078 tpo->has_cancel_path ? tpo->cancel_path : "");
1080 case TPM_TYPE_OPTIONS_KIND_EMULATOR:
1081 teo = ti->options->u.emulator.data;
1082 monitor_printf(mon, ",chardev=%s", teo->chardev);
1084 case TPM_TYPE_OPTIONS_KIND__MAX:
1087 monitor_printf(mon, "\n");
1090 qapi_free_TPMInfoList(info_list);
1093 void hmp_quit(Monitor *mon, const QDict *qdict)
1095 monitor_suspend(mon);
1099 void hmp_stop(Monitor *mon, const QDict *qdict)
1104 void hmp_sync_profile(Monitor *mon, const QDict *qdict)
1106 const char *op = qdict_get_try_str(qdict, "op");
1109 bool on = qsp_is_enabled();
1111 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off");
1114 if (!strcmp(op, "on")) {
1116 } else if (!strcmp(op, "off")) {
1118 } else if (!strcmp(op, "reset")) {
1123 error_setg(&err, QERR_INVALID_PARAMETER, op);
1124 hmp_handle_error(mon, &err);
1128 void hmp_system_reset(Monitor *mon, const QDict *qdict)
1130 qmp_system_reset(NULL);
1133 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
1135 qmp_system_powerdown(NULL);
1138 void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
1142 qmp_x_exit_preconfig(&err);
1143 hmp_handle_error(mon, &err);
1146 void hmp_cpu(Monitor *mon, const QDict *qdict)
1150 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1151 use it are converted to the QAPI */
1152 cpu_index = qdict_get_int(qdict, "index");
1153 if (monitor_set_cpu(cpu_index) < 0) {
1154 monitor_printf(mon, "invalid CPU index\n");
1158 void hmp_memsave(Monitor *mon, const QDict *qdict)
1160 uint32_t size = qdict_get_int(qdict, "size");
1161 const char *filename = qdict_get_str(qdict, "filename");
1162 uint64_t addr = qdict_get_int(qdict, "val");
1164 int cpu_index = monitor_get_cpu_index();
1166 if (cpu_index < 0) {
1167 monitor_printf(mon, "No CPU available\n");
1171 qmp_memsave(addr, size, filename, true, cpu_index, &err);
1172 hmp_handle_error(mon, &err);
1175 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1177 uint32_t size = qdict_get_int(qdict, "size");
1178 const char *filename = qdict_get_str(qdict, "filename");
1179 uint64_t addr = qdict_get_int(qdict, "val");
1182 qmp_pmemsave(addr, size, filename, &err);
1183 hmp_handle_error(mon, &err);
1186 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1188 const char *chardev = qdict_get_str(qdict, "device");
1189 const char *data = qdict_get_str(qdict, "data");
1192 qmp_ringbuf_write(chardev, data, false, 0, &err);
1194 hmp_handle_error(mon, &err);
1197 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
1199 uint32_t size = qdict_get_int(qdict, "size");
1200 const char *chardev = qdict_get_str(qdict, "device");
1205 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1207 hmp_handle_error(mon, &err);
1211 for (i = 0; data[i]; i++) {
1212 unsigned char ch = data[i];
1215 monitor_printf(mon, "\\\\");
1216 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1217 monitor_printf(mon, "\\u%04X", ch);
1219 monitor_printf(mon, "%c", ch);
1223 monitor_printf(mon, "\n");
1227 void hmp_cont(Monitor *mon, const QDict *qdict)
1232 hmp_handle_error(mon, &err);
1235 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1239 qmp_system_wakeup(&err);
1240 hmp_handle_error(mon, &err);
1243 void hmp_nmi(Monitor *mon, const QDict *qdict)
1247 qmp_inject_nmi(&err);
1248 hmp_handle_error(mon, &err);
1251 void hmp_set_link(Monitor *mon, const QDict *qdict)
1253 const char *name = qdict_get_str(qdict, "name");
1254 bool up = qdict_get_bool(qdict, "up");
1257 qmp_set_link(name, up, &err);
1258 hmp_handle_error(mon, &err);
1261 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1263 const char *device = qdict_get_str(qdict, "device");
1264 const char *password = qdict_get_str(qdict, "password");
1267 qmp_block_passwd(true, device, false, NULL, password, &err);
1268 hmp_handle_error(mon, &err);
1271 void hmp_balloon(Monitor *mon, const QDict *qdict)
1273 int64_t value = qdict_get_int(qdict, "value");
1276 qmp_balloon(value, &err);
1277 hmp_handle_error(mon, &err);
1280 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1282 const char *device = qdict_get_str(qdict, "device");
1283 int64_t size = qdict_get_int(qdict, "size");
1286 qmp_block_resize(true, device, false, NULL, size, &err);
1287 hmp_handle_error(mon, &err);
1290 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1292 const char *filename = qdict_get_str(qdict, "target");
1293 const char *format = qdict_get_try_str(qdict, "format");
1294 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1295 bool full = qdict_get_try_bool(qdict, "full", false);
1297 DriveMirror mirror = {
1298 .device = (char *)qdict_get_str(qdict, "device"),
1299 .target = (char *)filename,
1300 .has_format = !!format,
1301 .format = (char *)format,
1302 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1304 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1309 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1310 hmp_handle_error(mon, &err);
1313 qmp_drive_mirror(&mirror, &err);
1314 hmp_handle_error(mon, &err);
1317 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1319 const char *device = qdict_get_str(qdict, "device");
1320 const char *filename = qdict_get_str(qdict, "target");
1321 const char *format = qdict_get_try_str(qdict, "format");
1322 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1323 bool full = qdict_get_try_bool(qdict, "full", false);
1324 bool compress = qdict_get_try_bool(qdict, "compress", false);
1326 DriveBackup backup = {
1327 .device = (char *)device,
1328 .target = (char *)filename,
1329 .has_format = !!format,
1330 .format = (char *)format,
1331 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1333 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1334 .has_compress = !!compress,
1335 .compress = compress,
1339 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1340 hmp_handle_error(mon, &err);
1344 qmp_drive_backup(&backup, &err);
1345 hmp_handle_error(mon, &err);
1348 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1350 const char *device = qdict_get_str(qdict, "device");
1351 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1352 const char *format = qdict_get_try_str(qdict, "format");
1353 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1354 enum NewImageMode mode;
1358 /* In the future, if 'snapshot-file' is not specified, the snapshot
1359 will be taken internally. Today it's actually required. */
1360 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1361 hmp_handle_error(mon, &err);
1365 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1366 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1367 filename, false, NULL,
1370 hmp_handle_error(mon, &err);
1373 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1375 const char *device = qdict_get_str(qdict, "device");
1376 const char *name = qdict_get_str(qdict, "name");
1379 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1380 hmp_handle_error(mon, &err);
1383 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1385 const char *device = qdict_get_str(qdict, "device");
1386 const char *name = qdict_get_str(qdict, "name");
1387 const char *id = qdict_get_try_str(qdict, "id");
1390 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1392 hmp_handle_error(mon, &err);
1395 void hmp_loadvm(Monitor *mon, const QDict *qdict)
1397 int saved_vm_running = runstate_is_running();
1398 const char *name = qdict_get_str(qdict, "name");
1401 vm_stop(RUN_STATE_RESTORE_VM);
1403 if (load_snapshot(name, &err) == 0 && saved_vm_running) {
1406 hmp_handle_error(mon, &err);
1409 void hmp_savevm(Monitor *mon, const QDict *qdict)
1413 save_snapshot(qdict_get_try_str(qdict, "name"), &err);
1414 hmp_handle_error(mon, &err);
1417 void hmp_delvm(Monitor *mon, const QDict *qdict)
1419 BlockDriverState *bs;
1421 const char *name = qdict_get_str(qdict, "name");
1423 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
1424 error_reportf_err(err,
1425 "Error while deleting snapshot on device '%s': ",
1426 bdrv_get_device_name(bs));
1430 void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
1432 BlockDriverState *bs, *bs1;
1433 BdrvNextIterator it1;
1434 QEMUSnapshotInfo *sn_tab, *sn;
1435 bool no_snapshot = true;
1438 int *global_snapshots;
1439 AioContext *aio_context;
1441 typedef struct SnapshotEntry {
1442 QEMUSnapshotInfo sn;
1443 QTAILQ_ENTRY(SnapshotEntry) next;
1446 typedef struct ImageEntry {
1447 const char *imagename;
1448 QTAILQ_ENTRY(ImageEntry) next;
1449 QTAILQ_HEAD(, SnapshotEntry) snapshots;
1452 QTAILQ_HEAD(, ImageEntry) image_list =
1453 QTAILQ_HEAD_INITIALIZER(image_list);
1455 ImageEntry *image_entry, *next_ie;
1456 SnapshotEntry *snapshot_entry;
1458 bs = bdrv_all_find_vmstate_bs();
1460 monitor_printf(mon, "No available block device supports snapshots\n");
1463 aio_context = bdrv_get_aio_context(bs);
1465 aio_context_acquire(aio_context);
1466 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
1467 aio_context_release(aio_context);
1470 monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
1474 for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) {
1478 AioContext *ctx = bdrv_get_aio_context(bs1);
1480 aio_context_acquire(ctx);
1481 if (bdrv_can_snapshot(bs1)) {
1483 bs1_nb_sns = bdrv_snapshot_list(bs1, &sn);
1484 if (bs1_nb_sns > 0) {
1485 no_snapshot = false;
1486 ie = g_new0(ImageEntry, 1);
1487 ie->imagename = bdrv_get_device_name(bs1);
1488 QTAILQ_INIT(&ie->snapshots);
1489 QTAILQ_INSERT_TAIL(&image_list, ie, next);
1490 for (i = 0; i < bs1_nb_sns; i++) {
1491 se = g_new0(SnapshotEntry, 1);
1493 QTAILQ_INSERT_TAIL(&ie->snapshots, se, next);
1498 aio_context_release(ctx);
1502 monitor_printf(mon, "There is no snapshot available.\n");
1506 global_snapshots = g_new0(int, nb_sns);
1508 for (i = 0; i < nb_sns; i++) {
1509 SnapshotEntry *next_sn;
1510 if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) {
1511 global_snapshots[total] = i;
1513 QTAILQ_FOREACH(image_entry, &image_list, next) {
1514 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots,
1516 if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) {
1517 QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry,
1519 g_free(snapshot_entry);
1526 monitor_printf(mon, "List of snapshots present on all disks:\n");
1529 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1530 monitor_printf(mon, "\n");
1531 for (i = 0; i < total; i++) {
1532 sn = &sn_tab[global_snapshots[i]];
1533 /* The ID is not guaranteed to be the same on all images, so
1536 pstrcpy(sn->id_str, sizeof(sn->id_str), "--");
1537 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, sn);
1538 monitor_printf(mon, "\n");
1541 monitor_printf(mon, "None\n");
1544 QTAILQ_FOREACH(image_entry, &image_list, next) {
1545 if (QTAILQ_EMPTY(&image_entry->snapshots)) {
1549 "\nList of partial (non-loadable) snapshots on '%s':\n",
1550 image_entry->imagename);
1551 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1552 monitor_printf(mon, "\n");
1553 QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) {
1554 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon,
1555 &snapshot_entry->sn);
1556 monitor_printf(mon, "\n");
1560 QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) {
1561 SnapshotEntry *next_sn;
1562 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next,
1564 g_free(snapshot_entry);
1566 g_free(image_entry);
1569 g_free(global_snapshots);
1573 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1575 qmp_migrate_cancel(NULL);
1578 void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1581 const char *state = qdict_get_str(qdict, "state");
1582 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1585 qmp_migrate_continue(val, &err);
1588 hmp_handle_error(mon, &err);
1591 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1594 const char *uri = qdict_get_str(qdict, "uri");
1596 qmp_migrate_incoming(uri, &err);
1598 hmp_handle_error(mon, &err);
1601 void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
1604 const char *uri = qdict_get_str(qdict, "uri");
1606 qmp_migrate_recover(uri, &err);
1608 hmp_handle_error(mon, &err);
1611 void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
1615 qmp_migrate_pause(&err);
1617 hmp_handle_error(mon, &err);
1620 /* Kept for backwards compatibility */
1621 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1623 double value = qdict_get_double(qdict, "value");
1624 qmp_migrate_set_downtime(value, NULL);
1627 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1629 int64_t value = qdict_get_int(qdict, "value");
1632 qmp_migrate_set_cache_size(value, &err);
1633 hmp_handle_error(mon, &err);
1636 /* Kept for backwards compatibility */
1637 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1639 int64_t value = qdict_get_int(qdict, "value");
1640 qmp_migrate_set_speed(value, NULL);
1643 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1645 const char *cap = qdict_get_str(qdict, "capability");
1646 bool state = qdict_get_bool(qdict, "state");
1648 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1651 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
1656 caps->value = g_malloc0(sizeof(*caps->value));
1657 caps->value->capability = val;
1658 caps->value->state = state;
1660 qmp_migrate_set_capabilities(caps, &err);
1663 qapi_free_MigrationCapabilityStatusList(caps);
1664 hmp_handle_error(mon, &err);
1667 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1669 const char *param = qdict_get_str(qdict, "parameter");
1670 const char *valuestr = qdict_get_str(qdict, "value");
1671 Visitor *v = string_input_visitor_new(valuestr);
1672 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
1673 uint64_t valuebw = 0;
1674 uint64_t cache_size;
1678 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
1684 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1685 p->has_compress_level = true;
1686 visit_type_int(v, param, &p->compress_level, &err);
1688 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1689 p->has_compress_threads = true;
1690 visit_type_int(v, param, &p->compress_threads, &err);
1692 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD:
1693 p->has_compress_wait_thread = true;
1694 visit_type_bool(v, param, &p->compress_wait_thread, &err);
1696 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1697 p->has_decompress_threads = true;
1698 visit_type_int(v, param, &p->decompress_threads, &err);
1700 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1701 p->has_cpu_throttle_initial = true;
1702 visit_type_int(v, param, &p->cpu_throttle_initial, &err);
1704 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1705 p->has_cpu_throttle_increment = true;
1706 visit_type_int(v, param, &p->cpu_throttle_increment, &err);
1708 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE:
1709 p->has_max_cpu_throttle = true;
1710 visit_type_int(v, param, &p->max_cpu_throttle, &err);
1712 case MIGRATION_PARAMETER_TLS_CREDS:
1713 p->has_tls_creds = true;
1714 p->tls_creds = g_new0(StrOrNull, 1);
1715 p->tls_creds->type = QTYPE_QSTRING;
1716 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1718 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1719 p->has_tls_hostname = true;
1720 p->tls_hostname = g_new0(StrOrNull, 1);
1721 p->tls_hostname->type = QTYPE_QSTRING;
1722 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1724 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1725 p->has_max_bandwidth = true;
1727 * Can't use visit_type_size() here, because it
1728 * defaults to Bytes rather than Mebibytes.
1730 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1731 if (ret < 0 || valuebw > INT64_MAX
1732 || (size_t)valuebw != valuebw) {
1733 error_setg(&err, "Invalid size %s", valuestr);
1736 p->max_bandwidth = valuebw;
1738 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1739 p->has_downtime_limit = true;
1740 visit_type_int(v, param, &p->downtime_limit, &err);
1742 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1743 p->has_x_checkpoint_delay = true;
1744 visit_type_int(v, param, &p->x_checkpoint_delay, &err);
1746 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1747 p->has_block_incremental = true;
1748 visit_type_bool(v, param, &p->block_incremental, &err);
1750 case MIGRATION_PARAMETER_X_MULTIFD_CHANNELS:
1751 p->has_x_multifd_channels = true;
1752 visit_type_int(v, param, &p->x_multifd_channels, &err);
1754 case MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT:
1755 p->has_x_multifd_page_count = true;
1756 visit_type_int(v, param, &p->x_multifd_page_count, &err);
1758 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1759 p->has_xbzrle_cache_size = true;
1760 visit_type_size(v, param, &cache_size, &err);
1761 if (err || cache_size > INT64_MAX
1762 || (size_t)cache_size != cache_size) {
1763 error_setg(&err, "Invalid size %s", valuestr);
1766 p->xbzrle_cache_size = cache_size;
1768 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH:
1769 p->has_max_postcopy_bandwidth = true;
1770 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err);
1772 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL:
1773 p->has_announce_initial = true;
1774 visit_type_size(v, param, &p->announce_initial, &err);
1776 case MIGRATION_PARAMETER_ANNOUNCE_MAX:
1777 p->has_announce_max = true;
1778 visit_type_size(v, param, &p->announce_max, &err);
1780 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS:
1781 p->has_announce_rounds = true;
1782 visit_type_size(v, param, &p->announce_rounds, &err);
1784 case MIGRATION_PARAMETER_ANNOUNCE_STEP:
1785 p->has_announce_step = true;
1786 visit_type_size(v, param, &p->announce_step, &err);
1796 qmp_migrate_set_parameters(p, &err);
1799 qapi_free_MigrateSetParameters(p);
1801 hmp_handle_error(mon, &err);
1804 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1807 const char *protocol = qdict_get_str(qdict, "protocol");
1808 const char *hostname = qdict_get_str(qdict, "hostname");
1809 bool has_port = qdict_haskey(qdict, "port");
1810 int port = qdict_get_try_int(qdict, "port", -1);
1811 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1812 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1813 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1815 qmp_client_migrate_info(protocol, hostname,
1816 has_port, port, has_tls_port, tls_port,
1817 !!cert_subject, cert_subject, &err);
1818 hmp_handle_error(mon, &err);
1821 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1824 qmp_migrate_start_postcopy(&err);
1825 hmp_handle_error(mon, &err);
1828 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1832 qmp_x_colo_lost_heartbeat(&err);
1833 hmp_handle_error(mon, &err);
1836 void hmp_set_password(Monitor *mon, const QDict *qdict)
1838 const char *protocol = qdict_get_str(qdict, "protocol");
1839 const char *password = qdict_get_str(qdict, "password");
1840 const char *connected = qdict_get_try_str(qdict, "connected");
1843 qmp_set_password(protocol, password, !!connected, connected, &err);
1844 hmp_handle_error(mon, &err);
1847 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1849 const char *protocol = qdict_get_str(qdict, "protocol");
1850 const char *whenstr = qdict_get_str(qdict, "time");
1853 qmp_expire_password(protocol, whenstr, &err);
1854 hmp_handle_error(mon, &err);
1857 void hmp_eject(Monitor *mon, const QDict *qdict)
1859 bool force = qdict_get_try_bool(qdict, "force", false);
1860 const char *device = qdict_get_str(qdict, "device");
1863 qmp_eject(true, device, false, NULL, true, force, &err);
1864 hmp_handle_error(mon, &err);
1868 static void hmp_change_read_arg(void *opaque, const char *password,
1869 void *readline_opaque)
1871 qmp_change_vnc_password(password, NULL);
1872 monitor_read_command(opaque, 1);
1876 void hmp_change(Monitor *mon, const QDict *qdict)
1878 const char *device = qdict_get_str(qdict, "device");
1879 const char *target = qdict_get_str(qdict, "target");
1880 const char *arg = qdict_get_try_str(qdict, "arg");
1881 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1882 BlockdevChangeReadOnlyMode read_only_mode = 0;
1886 if (strcmp(device, "vnc") == 0) {
1889 "Parameter 'read-only-mode' is invalid for VNC\n");
1892 if (strcmp(target, "passwd") == 0 ||
1893 strcmp(target, "password") == 0) {
1895 monitor_read_password(mon, hmp_change_read_arg, NULL);
1899 qmp_change("vnc", target, !!arg, arg, &err);
1905 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
1907 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1909 hmp_handle_error(mon, &err);
1914 qmp_blockdev_change_medium(true, device, false, NULL, target,
1915 !!arg, arg, !!read_only, read_only_mode,
1919 hmp_handle_error(mon, &err);
1922 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1925 char *device = (char *) qdict_get_str(qdict, "device");
1926 BlockIOThrottle throttle = {
1927 .bps = qdict_get_int(qdict, "bps"),
1928 .bps_rd = qdict_get_int(qdict, "bps_rd"),
1929 .bps_wr = qdict_get_int(qdict, "bps_wr"),
1930 .iops = qdict_get_int(qdict, "iops"),
1931 .iops_rd = qdict_get_int(qdict, "iops_rd"),
1932 .iops_wr = qdict_get_int(qdict, "iops_wr"),
1935 /* qmp_block_set_io_throttle has separate parameters for the
1936 * (deprecated) block device name and the qdev ID but the HMP
1937 * version has only one, so we must decide which one to pass. */
1938 if (blk_by_name(device)) {
1939 throttle.has_device = true;
1940 throttle.device = device;
1942 throttle.has_id = true;
1943 throttle.id = device;
1946 qmp_block_set_io_throttle(&throttle, &err);
1947 hmp_handle_error(mon, &err);
1950 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1952 Error *error = NULL;
1953 const char *device = qdict_get_str(qdict, "device");
1954 const char *base = qdict_get_try_str(qdict, "base");
1955 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1957 qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
1958 false, NULL, qdict_haskey(qdict, "speed"), speed, true,
1959 BLOCKDEV_ON_ERROR_REPORT, false, false, false, false,
1962 hmp_handle_error(mon, &error);
1965 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1967 Error *error = NULL;
1968 const char *device = qdict_get_str(qdict, "device");
1969 int64_t value = qdict_get_int(qdict, "speed");
1971 qmp_block_job_set_speed(device, value, &error);
1973 hmp_handle_error(mon, &error);
1976 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1978 Error *error = NULL;
1979 const char *device = qdict_get_str(qdict, "device");
1980 bool force = qdict_get_try_bool(qdict, "force", false);
1982 qmp_block_job_cancel(device, true, force, &error);
1984 hmp_handle_error(mon, &error);
1987 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1989 Error *error = NULL;
1990 const char *device = qdict_get_str(qdict, "device");
1992 qmp_block_job_pause(device, &error);
1994 hmp_handle_error(mon, &error);
1997 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1999 Error *error = NULL;
2000 const char *device = qdict_get_str(qdict, "device");
2002 qmp_block_job_resume(device, &error);
2004 hmp_handle_error(mon, &error);
2007 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
2009 Error *error = NULL;
2010 const char *device = qdict_get_str(qdict, "device");
2012 qmp_block_job_complete(device, &error);
2014 hmp_handle_error(mon, &error);
2017 typedef struct HMPMigrationStatus
2021 bool is_block_migration;
2022 } HMPMigrationStatus;
2024 static void hmp_migrate_status_cb(void *opaque)
2026 HMPMigrationStatus *status = opaque;
2027 MigrationInfo *info;
2029 info = qmp_query_migrate(NULL);
2030 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
2031 info->status == MIGRATION_STATUS_SETUP) {
2032 if (info->has_disk) {
2035 if (info->disk->remaining) {
2036 progress = info->disk->transferred * 100 / info->disk->total;
2041 monitor_printf(status->mon, "Completed %d %%\r", progress);
2042 monitor_flush(status->mon);
2045 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
2047 if (status->is_block_migration) {
2048 monitor_printf(status->mon, "\n");
2050 if (info->has_error_desc) {
2051 error_report("%s", info->error_desc);
2053 monitor_resume(status->mon);
2054 timer_del(status->timer);
2055 timer_free(status->timer);
2059 qapi_free_MigrationInfo(info);
2062 void hmp_migrate(Monitor *mon, const QDict *qdict)
2064 bool detach = qdict_get_try_bool(qdict, "detach", false);
2065 bool blk = qdict_get_try_bool(qdict, "blk", false);
2066 bool inc = qdict_get_try_bool(qdict, "inc", false);
2067 bool resume = qdict_get_try_bool(qdict, "resume", false);
2068 const char *uri = qdict_get_str(qdict, "uri");
2071 qmp_migrate(uri, !!blk, blk, !!inc, inc,
2072 false, false, true, resume, &err);
2074 hmp_handle_error(mon, &err);
2079 HMPMigrationStatus *status;
2081 if (monitor_suspend(mon) < 0) {
2082 monitor_printf(mon, "terminal does not allow synchronous "
2083 "migration, continuing detached\n");
2087 status = g_malloc0(sizeof(*status));
2089 status->is_block_migration = blk || inc;
2090 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
2092 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
2096 void hmp_device_add(Monitor *mon, const QDict *qdict)
2100 qmp_device_add((QDict *)qdict, NULL, &err);
2101 hmp_handle_error(mon, &err);
2104 void hmp_device_del(Monitor *mon, const QDict *qdict)
2106 const char *id = qdict_get_str(qdict, "id");
2109 qmp_device_del(id, &err);
2110 hmp_handle_error(mon, &err);
2113 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
2116 bool win_dmp = qdict_get_try_bool(qdict, "windmp", false);
2117 bool paging = qdict_get_try_bool(qdict, "paging", false);
2118 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
2119 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
2120 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
2121 const char *file = qdict_get_str(qdict, "filename");
2122 bool has_begin = qdict_haskey(qdict, "begin");
2123 bool has_length = qdict_haskey(qdict, "length");
2124 bool has_detach = qdict_haskey(qdict, "detach");
2127 bool detach = false;
2128 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
2131 if (zlib + lzo + snappy + win_dmp > 1) {
2132 error_setg(&err, "only one of '-z|-l|-s|-w' can be set");
2133 hmp_handle_error(mon, &err);
2138 dump_format = DUMP_GUEST_MEMORY_FORMAT_WIN_DMP;
2142 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
2146 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
2150 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
2154 begin = qdict_get_int(qdict, "begin");
2157 length = qdict_get_int(qdict, "length");
2160 detach = qdict_get_bool(qdict, "detach");
2163 prot = g_strconcat("file:", file, NULL);
2165 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
2166 has_length, length, true, dump_format, &err);
2167 hmp_handle_error(mon, &err);
2171 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
2176 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
2181 netdev_add(opts, &err);
2183 qemu_opts_del(opts);
2187 hmp_handle_error(mon, &err);
2190 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
2192 const char *id = qdict_get_str(qdict, "id");
2195 qmp_netdev_del(id, &err);
2196 hmp_handle_error(mon, &err);
2199 void hmp_object_add(Monitor *mon, const QDict *qdict)
2205 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
2207 hmp_handle_error(mon, &err);
2211 obj = user_creatable_add_opts(opts, &err);
2212 qemu_opts_del(opts);
2215 hmp_handle_error(mon, &err);
2222 void hmp_getfd(Monitor *mon, const QDict *qdict)
2224 const char *fdname = qdict_get_str(qdict, "fdname");
2227 qmp_getfd(fdname, &err);
2228 hmp_handle_error(mon, &err);
2231 void hmp_closefd(Monitor *mon, const QDict *qdict)
2233 const char *fdname = qdict_get_str(qdict, "fdname");
2236 qmp_closefd(fdname, &err);
2237 hmp_handle_error(mon, &err);
2240 void hmp_sendkey(Monitor *mon, const QDict *qdict)
2242 const char *keys = qdict_get_str(qdict, "keys");
2243 KeyValueList *keylist, *head = NULL, *tmp = NULL;
2244 int has_hold_time = qdict_haskey(qdict, "hold-time");
2245 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
2247 const char *separator;
2251 separator = qemu_strchrnul(keys, '-');
2252 keyname_len = separator - keys;
2254 /* Be compatible with old interface, convert user inputted "<" */
2255 if (keys[0] == '<' && keyname_len == 1) {
2260 keylist = g_malloc0(sizeof(*keylist));
2261 keylist->value = g_malloc0(sizeof(*keylist->value));
2267 tmp->next = keylist;
2271 if (strstart(keys, "0x", NULL)) {
2273 int value = strtoul(keys, &endp, 0);
2274 assert(endp <= keys + keyname_len);
2275 if (endp != keys + keyname_len) {
2278 keylist->value->type = KEY_VALUE_KIND_NUMBER;
2279 keylist->value->u.number.data = value;
2281 int idx = index_from_key(keys, keyname_len);
2282 if (idx == Q_KEY_CODE__MAX) {
2285 keylist->value->type = KEY_VALUE_KIND_QCODE;
2286 keylist->value->u.qcode.data = idx;
2292 keys = separator + 1;
2295 qmp_send_key(head, has_hold_time, hold_time, &err);
2296 hmp_handle_error(mon, &err);
2299 qapi_free_KeyValueList(head);
2303 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
2307 void hmp_screendump(Monitor *mon, const QDict *qdict)
2309 const char *filename = qdict_get_str(qdict, "filename");
2310 const char *id = qdict_get_try_str(qdict, "device");
2311 int64_t head = qdict_get_try_int(qdict, "head", 0);
2314 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
2315 hmp_handle_error(mon, &err);
2318 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
2320 const char *uri = qdict_get_str(qdict, "uri");
2321 bool writable = qdict_get_try_bool(qdict, "writable", false);
2322 bool all = qdict_get_try_bool(qdict, "all", false);
2323 Error *local_err = NULL;
2324 BlockInfoList *block_list, *info;
2325 SocketAddress *addr;
2327 if (writable && !all) {
2328 error_setg(&local_err, "-w only valid together with -a");
2332 /* First check if the address is valid and start the server. */
2333 addr = socket_parse(uri, &local_err);
2334 if (local_err != NULL) {
2338 nbd_server_start(addr, NULL, &local_err);
2339 qapi_free_SocketAddress(addr);
2340 if (local_err != NULL) {
2348 /* Then try adding all block devices. If one fails, close all and
2351 block_list = qmp_query_block(NULL);
2353 for (info = block_list; info; info = info->next) {
2354 if (!info->value->has_inserted) {
2358 qmp_nbd_server_add(info->value->device, false, NULL,
2359 true, writable, false, NULL, &local_err);
2361 if (local_err != NULL) {
2362 qmp_nbd_server_stop(NULL);
2367 qapi_free_BlockInfoList(block_list);
2370 hmp_handle_error(mon, &local_err);
2373 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
2375 const char *device = qdict_get_str(qdict, "device");
2376 const char *name = qdict_get_try_str(qdict, "name");
2377 bool writable = qdict_get_try_bool(qdict, "writable", false);
2378 Error *local_err = NULL;
2380 qmp_nbd_server_add(device, !!name, name, true, writable,
2381 false, NULL, &local_err);
2382 hmp_handle_error(mon, &local_err);
2385 void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict)
2387 const char *name = qdict_get_str(qdict, "name");
2388 bool force = qdict_get_try_bool(qdict, "force", false);
2391 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
2392 qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err);
2393 hmp_handle_error(mon, &err);
2396 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
2400 qmp_nbd_server_stop(&err);
2401 hmp_handle_error(mon, &err);
2404 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
2409 error_report("cpu_add is deprecated, please use device_add instead");
2411 cpuid = qdict_get_int(qdict, "id");
2412 qmp_cpu_add(cpuid, &err);
2413 hmp_handle_error(mon, &err);
2416 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2418 const char *args = qdict_get_str(qdict, "args");
2422 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
2424 error_setg(&err, "Parsing chardev args failed");
2426 qemu_chr_new_from_opts(opts, NULL, &err);
2427 qemu_opts_del(opts);
2429 hmp_handle_error(mon, &err);
2432 void hmp_chardev_change(Monitor *mon, const QDict *qdict)
2434 const char *args = qdict_get_str(qdict, "args");
2437 ChardevBackend *backend = NULL;
2438 ChardevReturn *ret = NULL;
2439 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
2442 error_setg(&err, "Parsing chardev args failed");
2446 id = qdict_get_str(qdict, "id");
2447 if (qemu_opts_id(opts)) {
2448 error_setg(&err, "Unexpected 'id' parameter");
2452 backend = qemu_chr_parse_opts(opts, &err);
2457 ret = qmp_chardev_change(id, backend, &err);
2460 qapi_free_ChardevReturn(ret);
2461 qapi_free_ChardevBackend(backend);
2462 qemu_opts_del(opts);
2463 hmp_handle_error(mon, &err);
2466 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2468 Error *local_err = NULL;
2470 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
2471 hmp_handle_error(mon, &local_err);
2474 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
2476 Error *local_err = NULL;
2478 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
2479 hmp_handle_error(mon, &local_err);
2482 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
2485 BlockBackend *local_blk = NULL;
2486 const char* device = qdict_get_str(qdict, "device");
2487 const char* command = qdict_get_str(qdict, "command");
2491 blk = blk_by_name(device);
2493 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
2495 blk = local_blk = blk_new(0, BLK_PERM_ALL);
2496 ret = blk_insert_bs(blk, bs, &err);
2506 * Notably absent: Proper permission management. This is sad, but it seems
2507 * almost impossible to achieve without changing the semantics and thereby
2508 * limiting the use cases of the qemu-io HMP command.
2510 * In an ideal world we would unconditionally create a new BlockBackend for
2511 * qemuio_command(), but we have commands like 'reopen' and want them to
2512 * take effect on the exact BlockBackend whose name the user passed instead
2513 * of just on a temporary copy of it.
2515 * Another problem is that deleting the temporary BlockBackend involves
2516 * draining all requests on it first, but some qemu-iotests cases want to
2517 * issue multiple aio_read/write requests and expect them to complete in
2518 * the background while the monitor has already returned.
2520 * This is also what prevents us from saving the original permissions and
2521 * restoring them later: We can't revoke permissions until all requests
2522 * have completed, and we don't know when that is nor can we really let
2523 * anything else run before we have revoken them to avoid race conditions.
2525 * What happens now is that command() in qemu-io-cmds.c can extend the
2526 * permissions if necessary for the qemu-io command. And they simply stay
2527 * extended, possibly resulting in a read-only guest device keeping write
2528 * permissions. Ugly, but it appears to be the lesser evil.
2530 qemuio_command(blk, command);
2533 blk_unref(local_blk);
2534 hmp_handle_error(mon, &err);
2537 void hmp_object_del(Monitor *mon, const QDict *qdict)
2539 const char *id = qdict_get_str(qdict, "id");
2542 user_creatable_del(id, &err);
2543 hmp_handle_error(mon, &err);
2546 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
2549 MemdevList *memdev_list = qmp_query_memdev(&err);
2550 MemdevList *m = memdev_list;
2555 v = string_output_visitor_new(false, &str);
2556 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
2557 monitor_printf(mon, "memory backend: %s\n", m->value->id);
2558 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
2559 monitor_printf(mon, " merge: %s\n",
2560 m->value->merge ? "true" : "false");
2561 monitor_printf(mon, " dump: %s\n",
2562 m->value->dump ? "true" : "false");
2563 monitor_printf(mon, " prealloc: %s\n",
2564 m->value->prealloc ? "true" : "false");
2565 monitor_printf(mon, " policy: %s\n",
2566 HostMemPolicy_str(m->value->policy));
2567 visit_complete(v, &str);
2568 monitor_printf(mon, " host nodes: %s\n", str);
2575 monitor_printf(mon, "\n");
2577 qapi_free_MemdevList(memdev_list);
2578 hmp_handle_error(mon, &err);
2581 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2584 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2585 MemoryDeviceInfoList *info;
2586 MemoryDeviceInfo *value;
2587 PCDIMMDeviceInfo *di;
2589 for (info = info_list; info; info = info->next) {
2590 value = info->value;
2593 switch (value->type) {
2594 case MEMORY_DEVICE_INFO_KIND_DIMM:
2595 di = value->u.dimm.data;
2598 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
2599 di = value->u.nvdimm.data;
2608 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2609 MemoryDeviceInfoKind_str(value->type),
2610 di->id ? di->id : "");
2611 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2612 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2613 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2614 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2615 monitor_printf(mon, " memdev: %s\n", di->memdev);
2616 monitor_printf(mon, " hotplugged: %s\n",
2617 di->hotplugged ? "true" : "false");
2618 monitor_printf(mon, " hotpluggable: %s\n",
2619 di->hotpluggable ? "true" : "false");
2624 qapi_free_MemoryDeviceInfoList(info_list);
2625 hmp_handle_error(mon, &err);
2628 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2630 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2631 IOThreadInfoList *info;
2632 IOThreadInfo *value;
2634 for (info = info_list; info; info = info->next) {
2635 value = info->value;
2636 monitor_printf(mon, "%s:\n", value->id);
2637 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
2638 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2639 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
2640 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
2643 qapi_free_IOThreadInfoList(info_list);
2646 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2648 const char *path = qdict_get_try_str(qdict, "path");
2649 ObjectPropertyInfoList *list;
2653 monitor_printf(mon, "/\n");
2657 list = qmp_qom_list(path, &err);
2659 ObjectPropertyInfoList *start = list;
2660 while (list != NULL) {
2661 ObjectPropertyInfo *value = list->value;
2663 monitor_printf(mon, "%s (%s)\n",
2664 value->name, value->type);
2667 qapi_free_ObjectPropertyInfoList(start);
2669 hmp_handle_error(mon, &err);
2672 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2674 const char *path = qdict_get_str(qdict, "path");
2675 const char *property = qdict_get_str(qdict, "property");
2676 const char *value = qdict_get_str(qdict, "value");
2678 bool ambiguous = false;
2681 obj = object_resolve_path(path, &ambiguous);
2683 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2684 "Device '%s' not found", path);
2687 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2689 object_property_parse(obj, value, property, &err);
2691 hmp_handle_error(mon, &err);
2694 void hmp_rocker(Monitor *mon, const QDict *qdict)
2696 const char *name = qdict_get_str(qdict, "name");
2697 RockerSwitch *rocker;
2700 rocker = qmp_query_rocker(name, &err);
2702 hmp_handle_error(mon, &err);
2706 monitor_printf(mon, "name: %s\n", rocker->name);
2707 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2708 monitor_printf(mon, "ports: %d\n", rocker->ports);
2710 qapi_free_RockerSwitch(rocker);
2713 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2715 RockerPortList *list, *port;
2716 const char *name = qdict_get_str(qdict, "name");
2719 list = qmp_query_rocker_ports(name, &err);
2721 hmp_handle_error(mon, &err);
2725 monitor_printf(mon, " ena/ speed/ auto\n");
2726 monitor_printf(mon, " port link duplex neg?\n");
2728 for (port = list; port; port = port->next) {
2729 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2731 port->value->enabled ? port->value->link_up ?
2732 "up" : "down" : "!ena",
2733 port->value->speed == 10000 ? "10G" : "??",
2734 port->value->duplex ? "FD" : "HD",
2735 port->value->autoneg ? "Yes" : "No");
2738 qapi_free_RockerPortList(list);
2741 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2743 RockerOfDpaFlowList *list, *info;
2744 const char *name = qdict_get_str(qdict, "name");
2745 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2748 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2750 hmp_handle_error(mon, &err);
2754 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2756 for (info = list; info; info = info->next) {
2757 RockerOfDpaFlow *flow = info->value;
2758 RockerOfDpaFlowKey *key = flow->key;
2759 RockerOfDpaFlowMask *mask = flow->mask;
2760 RockerOfDpaFlowAction *action = flow->action;
2763 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2764 key->priority, key->tbl_id, flow->hits);
2766 monitor_printf(mon, "%-4d %-3d ",
2767 key->priority, key->tbl_id);
2770 if (key->has_in_pport) {
2771 monitor_printf(mon, " pport %d", key->in_pport);
2772 if (mask->has_in_pport) {
2773 monitor_printf(mon, "(0x%x)", mask->in_pport);
2777 if (key->has_vlan_id) {
2778 monitor_printf(mon, " vlan %d",
2779 key->vlan_id & VLAN_VID_MASK);
2780 if (mask->has_vlan_id) {
2781 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2785 if (key->has_tunnel_id) {
2786 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2787 if (mask->has_tunnel_id) {
2788 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2792 if (key->has_eth_type) {
2793 switch (key->eth_type) {
2795 monitor_printf(mon, " ARP");
2798 monitor_printf(mon, " IP");
2801 monitor_printf(mon, " IPv6");
2804 monitor_printf(mon, " LACP");
2807 monitor_printf(mon, " LLDP");
2810 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2815 if (key->has_eth_src) {
2816 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2817 (mask->has_eth_src) &&
2818 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2819 monitor_printf(mon, " src <any mcast/bcast>");
2820 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2821 (mask->has_eth_src) &&
2822 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2823 monitor_printf(mon, " src <any ucast>");
2825 monitor_printf(mon, " src %s", key->eth_src);
2826 if (mask->has_eth_src) {
2827 monitor_printf(mon, "(%s)", mask->eth_src);
2832 if (key->has_eth_dst) {
2833 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2834 (mask->has_eth_dst) &&
2835 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2836 monitor_printf(mon, " dst <any mcast/bcast>");
2837 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2838 (mask->has_eth_dst) &&
2839 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2840 monitor_printf(mon, " dst <any ucast>");
2842 monitor_printf(mon, " dst %s", key->eth_dst);
2843 if (mask->has_eth_dst) {
2844 monitor_printf(mon, "(%s)", mask->eth_dst);
2849 if (key->has_ip_proto) {
2850 monitor_printf(mon, " proto %d", key->ip_proto);
2851 if (mask->has_ip_proto) {
2852 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2856 if (key->has_ip_tos) {
2857 monitor_printf(mon, " TOS %d", key->ip_tos);
2858 if (mask->has_ip_tos) {
2859 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2863 if (key->has_ip_dst) {
2864 monitor_printf(mon, " dst %s", key->ip_dst);
2867 if (action->has_goto_tbl || action->has_group_id ||
2868 action->has_new_vlan_id) {
2869 monitor_printf(mon, " -->");
2872 if (action->has_new_vlan_id) {
2873 monitor_printf(mon, " apply new vlan %d",
2874 ntohs(action->new_vlan_id));
2877 if (action->has_group_id) {
2878 monitor_printf(mon, " write group 0x%08x", action->group_id);
2881 if (action->has_goto_tbl) {
2882 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2885 monitor_printf(mon, "\n");
2888 qapi_free_RockerOfDpaFlowList(list);
2891 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2893 RockerOfDpaGroupList *list, *g;
2894 const char *name = qdict_get_str(qdict, "name");
2895 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2899 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2901 hmp_handle_error(mon, &err);
2905 monitor_printf(mon, "id (decode) --> buckets\n");
2907 for (g = list; g; g = g->next) {
2908 RockerOfDpaGroup *group = g->value;
2910 monitor_printf(mon, "0x%08x", group->id);
2912 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2913 group->type == 1 ? "L2 rewrite" :
2914 group->type == 2 ? "L3 unicast" :
2915 group->type == 3 ? "L2 multicast" :
2916 group->type == 4 ? "L2 flood" :
2917 group->type == 5 ? "L3 interface" :
2918 group->type == 6 ? "L3 multicast" :
2919 group->type == 7 ? "L3 ECMP" :
2920 group->type == 8 ? "L2 overlay" :
2923 if (group->has_vlan_id) {
2924 monitor_printf(mon, " vlan %d", group->vlan_id);
2927 if (group->has_pport) {
2928 monitor_printf(mon, " pport %d", group->pport);
2931 if (group->has_index) {
2932 monitor_printf(mon, " index %d", group->index);
2935 monitor_printf(mon, ") -->");
2937 if (group->has_set_vlan_id && group->set_vlan_id) {
2939 monitor_printf(mon, " set vlan %d",
2940 group->set_vlan_id & VLAN_VID_MASK);
2943 if (group->has_set_eth_src) {
2946 monitor_printf(mon, " set");
2948 monitor_printf(mon, " src %s", group->set_eth_src);
2951 if (group->has_set_eth_dst) {
2954 monitor_printf(mon, " set");
2956 monitor_printf(mon, " dst %s", group->set_eth_dst);
2961 if (group->has_ttl_check && group->ttl_check) {
2962 monitor_printf(mon, " check TTL");
2965 if (group->has_group_id && group->group_id) {
2966 monitor_printf(mon, " group id 0x%08x", group->group_id);
2969 if (group->has_pop_vlan && group->pop_vlan) {
2970 monitor_printf(mon, " pop vlan");
2973 if (group->has_out_pport) {
2974 monitor_printf(mon, " out pport %d", group->out_pport);
2977 if (group->has_group_ids) {
2978 struct uint32List *id;
2980 monitor_printf(mon, " groups [");
2981 for (id = group->group_ids; id; id = id->next) {
2982 monitor_printf(mon, "0x%08x", id->value);
2984 monitor_printf(mon, ",");
2987 monitor_printf(mon, "]");
2990 monitor_printf(mon, "\n");
2993 qapi_free_RockerOfDpaGroupList(list);
2996 void hmp_info_dump(Monitor *mon, const QDict *qdict)
2998 DumpQueryResult *result = qmp_query_dump(NULL);
3000 assert(result && result->status < DUMP_STATUS__MAX);
3001 monitor_printf(mon, "Status: %s\n", DumpStatus_str(result->status));
3003 if (result->status == DUMP_STATUS_ACTIVE) {
3005 assert(result->total != 0);
3006 percent = 100.0 * result->completed / result->total;
3007 monitor_printf(mon, "Finished: %.2f %%\n", percent);
3010 qapi_free_DumpQueryResult(result);
3013 void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
3015 ram_block_dump(mon);
3018 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
3021 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
3022 HotpluggableCPUList *saved = l;
3023 CpuInstanceProperties *c;
3026 hmp_handle_error(mon, &err);
3030 monitor_printf(mon, "Hotpluggable CPUs:\n");
3032 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
3033 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
3034 l->value->vcpus_count);
3035 if (l->value->has_qom_path) {
3036 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
3039 c = l->value->props;
3040 monitor_printf(mon, " CPUInstance Properties:\n");
3041 if (c->has_node_id) {
3042 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
3044 if (c->has_socket_id) {
3045 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
3047 if (c->has_core_id) {
3048 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
3050 if (c->has_thread_id) {
3051 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
3057 qapi_free_HotpluggableCPUList(saved);
3060 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
3063 GuidInfo *info = qmp_query_vm_generation_id(&err);
3065 monitor_printf(mon, "%s\n", info->guid);
3067 hmp_handle_error(mon, &err);
3068 qapi_free_GuidInfo(info);
3071 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
3074 MemoryInfo *info = qmp_query_memory_size_summary(&err);
3076 monitor_printf(mon, "base memory: %" PRIu64 "\n",
3079 if (info->has_plugged_memory) {
3080 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
3081 info->plugged_memory);
3084 qapi_free_MemoryInfo(info);
3086 hmp_handle_error(mon, &err);