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_report_err(*errp);
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);
240 if (info->ram->dirty_pages_rate) {
241 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
242 info->ram->dirty_pages_rate);
244 if (info->ram->postcopy_requests) {
245 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
246 info->ram->postcopy_requests);
250 if (info->has_disk) {
251 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
252 info->disk->transferred >> 10);
253 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
254 info->disk->remaining >> 10);
255 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
256 info->disk->total >> 10);
259 if (info->has_xbzrle_cache) {
260 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
261 info->xbzrle_cache->cache_size);
262 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
263 info->xbzrle_cache->bytes >> 10);
264 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
265 info->xbzrle_cache->pages);
266 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
267 info->xbzrle_cache->cache_miss);
268 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
269 info->xbzrle_cache->cache_miss_rate);
270 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
271 info->xbzrle_cache->overflow);
274 if (info->has_cpu_throttle_percentage) {
275 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
276 info->cpu_throttle_percentage);
279 if (info->has_postcopy_blocktime) {
280 monitor_printf(mon, "postcopy blocktime: %u\n",
281 info->postcopy_blocktime);
284 if (info->has_postcopy_vcpu_blocktime) {
287 v = string_output_visitor_new(false, &str);
288 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NULL);
289 visit_complete(v, &str);
290 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
294 qapi_free_MigrationInfo(info);
295 qapi_free_MigrationCapabilityStatusList(caps);
298 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
300 MigrationCapabilityStatusList *caps, *cap;
302 caps = qmp_query_migrate_capabilities(NULL);
305 for (cap = caps; cap; cap = cap->next) {
306 monitor_printf(mon, "%s: %s\n",
307 MigrationCapability_str(cap->value->capability),
308 cap->value->state ? "on" : "off");
312 qapi_free_MigrationCapabilityStatusList(caps);
315 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
317 MigrationParameters *params;
319 params = qmp_query_migrate_parameters(NULL);
322 assert(params->has_compress_level);
323 monitor_printf(mon, "%s: %u\n",
324 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
325 params->compress_level);
326 assert(params->has_compress_threads);
327 monitor_printf(mon, "%s: %u\n",
328 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
329 params->compress_threads);
330 assert(params->has_compress_wait_thread);
331 monitor_printf(mon, "%s: %s\n",
332 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD),
333 params->compress_wait_thread ? "on" : "off");
334 assert(params->has_decompress_threads);
335 monitor_printf(mon, "%s: %u\n",
336 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
337 params->decompress_threads);
338 assert(params->has_cpu_throttle_initial);
339 monitor_printf(mon, "%s: %u\n",
340 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
341 params->cpu_throttle_initial);
342 assert(params->has_cpu_throttle_increment);
343 monitor_printf(mon, "%s: %u\n",
344 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
345 params->cpu_throttle_increment);
346 assert(params->has_max_cpu_throttle);
347 monitor_printf(mon, "%s: %u\n",
348 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE),
349 params->max_cpu_throttle);
350 assert(params->has_tls_creds);
351 monitor_printf(mon, "%s: '%s'\n",
352 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
354 assert(params->has_tls_hostname);
355 monitor_printf(mon, "%s: '%s'\n",
356 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
357 params->tls_hostname);
358 assert(params->has_max_bandwidth);
359 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
360 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
361 params->max_bandwidth);
362 assert(params->has_downtime_limit);
363 monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n",
364 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
365 params->downtime_limit);
366 assert(params->has_x_checkpoint_delay);
367 monitor_printf(mon, "%s: %u\n",
368 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
369 params->x_checkpoint_delay);
370 assert(params->has_block_incremental);
371 monitor_printf(mon, "%s: %s\n",
372 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
373 params->block_incremental ? "on" : "off");
374 monitor_printf(mon, "%s: %u\n",
375 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_CHANNELS),
376 params->x_multifd_channels);
377 monitor_printf(mon, "%s: %u\n",
378 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT),
379 params->x_multifd_page_count);
380 monitor_printf(mon, "%s: %" PRIu64 "\n",
381 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
382 params->xbzrle_cache_size);
383 monitor_printf(mon, "%s: %" PRIu64 "\n",
384 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
385 params->max_postcopy_bandwidth);
388 qapi_free_MigrationParameters(params);
391 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
393 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
394 qmp_query_migrate_cache_size(NULL) >> 10);
397 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
399 CpuInfoFastList *cpu_list, *cpu;
401 cpu_list = qmp_query_cpus_fast(NULL);
403 for (cpu = cpu_list; cpu; cpu = cpu->next) {
406 if (cpu->value->cpu_index == monitor_get_cpu_index()) {
410 monitor_printf(mon, "%c CPU #%" PRId64 ":", active,
411 cpu->value->cpu_index);
412 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
415 qapi_free_CpuInfoFastList(cpu_list);
418 static void print_block_info(Monitor *mon, BlockInfo *info,
419 BlockDeviceInfo *inserted, bool verbose)
421 ImageInfo *image_info;
423 assert(!info || !info->has_inserted || info->inserted == inserted);
425 if (info && *info->device) {
426 monitor_printf(mon, "%s", info->device);
427 if (inserted && inserted->has_node_name) {
428 monitor_printf(mon, " (%s)", inserted->node_name);
431 assert(info || inserted);
432 monitor_printf(mon, "%s",
433 inserted && inserted->has_node_name ? inserted->node_name
434 : info && info->has_qdev ? info->qdev
439 monitor_printf(mon, ": %s (%s%s%s)\n",
442 inserted->ro ? ", read-only" : "",
443 inserted->encrypted ? ", encrypted" : "");
445 monitor_printf(mon, ": [not inserted]\n");
449 if (info->has_qdev) {
450 monitor_printf(mon, " Attached to: %s\n", info->qdev);
452 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
453 monitor_printf(mon, " I/O status: %s\n",
454 BlockDeviceIoStatus_str(info->io_status));
457 if (info->removable) {
458 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
459 info->locked ? "" : "not ",
460 info->tray_open ? "open" : "closed");
469 monitor_printf(mon, " Cache mode: %s%s%s\n",
470 inserted->cache->writeback ? "writeback" : "writethrough",
471 inserted->cache->direct ? ", direct" : "",
472 inserted->cache->no_flush ? ", ignore flushes" : "");
474 if (inserted->has_backing_file) {
477 "(chain depth: %" PRId64 ")\n",
478 inserted->backing_file,
479 inserted->backing_file_depth);
482 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
483 monitor_printf(mon, " Detect zeroes: %s\n",
484 BlockdevDetectZeroesOptions_str(inserted->detect_zeroes));
487 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
488 inserted->iops || inserted->iops_rd || inserted->iops_wr)
490 monitor_printf(mon, " I/O throttling: bps=%" PRId64
491 " bps_rd=%" PRId64 " bps_wr=%" PRId64
493 " bps_rd_max=%" PRId64
494 " bps_wr_max=%" PRId64
495 " iops=%" PRId64 " iops_rd=%" PRId64
498 " iops_rd_max=%" PRId64
499 " iops_wr_max=%" PRId64
500 " iops_size=%" PRId64
506 inserted->bps_rd_max,
507 inserted->bps_wr_max,
512 inserted->iops_rd_max,
513 inserted->iops_wr_max,
519 monitor_printf(mon, "\nImages:\n");
520 image_info = inserted->image;
522 bdrv_image_info_dump((fprintf_function)monitor_printf,
524 if (image_info->has_backing_image) {
525 image_info = image_info->backing_image;
533 void hmp_info_block(Monitor *mon, const QDict *qdict)
535 BlockInfoList *block_list, *info;
536 BlockDeviceInfoList *blockdev_list, *blockdev;
537 const char *device = qdict_get_try_str(qdict, "device");
538 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
539 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
540 bool printed = false;
542 /* Print BlockBackend information */
544 block_list = qmp_query_block(NULL);
549 for (info = block_list; info; info = info->next) {
550 if (device && strcmp(device, info->value->device)) {
554 if (info != block_list) {
555 monitor_printf(mon, "\n");
558 print_block_info(mon, info->value, info->value->has_inserted
559 ? info->value->inserted : NULL,
564 qapi_free_BlockInfoList(block_list);
566 if ((!device && !nodes) || printed) {
570 /* Print node information */
571 blockdev_list = qmp_query_named_block_nodes(NULL);
572 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
573 assert(blockdev->value->has_node_name);
574 if (device && strcmp(device, blockdev->value->node_name)) {
578 if (blockdev != blockdev_list) {
579 monitor_printf(mon, "\n");
582 print_block_info(mon, NULL, blockdev->value, verbose);
584 qapi_free_BlockDeviceInfoList(blockdev_list);
587 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
589 BlockStatsList *stats_list, *stats;
591 stats_list = qmp_query_blockstats(false, false, NULL);
593 for (stats = stats_list; stats; stats = stats->next) {
594 if (!stats->value->has_device) {
598 monitor_printf(mon, "%s:", stats->value->device);
599 monitor_printf(mon, " rd_bytes=%" PRId64
601 " rd_operations=%" PRId64
602 " wr_operations=%" PRId64
603 " flush_operations=%" PRId64
604 " wr_total_time_ns=%" PRId64
605 " rd_total_time_ns=%" PRId64
606 " flush_total_time_ns=%" PRId64
607 " rd_merged=%" PRId64
608 " wr_merged=%" PRId64
609 " idle_time_ns=%" PRId64
611 stats->value->stats->rd_bytes,
612 stats->value->stats->wr_bytes,
613 stats->value->stats->rd_operations,
614 stats->value->stats->wr_operations,
615 stats->value->stats->flush_operations,
616 stats->value->stats->wr_total_time_ns,
617 stats->value->stats->rd_total_time_ns,
618 stats->value->stats->flush_total_time_ns,
619 stats->value->stats->rd_merged,
620 stats->value->stats->wr_merged,
621 stats->value->stats->idle_time_ns);
624 qapi_free_BlockStatsList(stats_list);
628 /* Helper for hmp_info_vnc_clients, _servers */
629 static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
632 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
636 NetworkAddressFamily_str(info->family),
637 info->websocket ? " (Websocket)" : "");
640 /* Helper displaying and auth and crypt info */
641 static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
643 VncVencryptSubAuth *vencrypt)
645 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
646 VncPrimaryAuth_str(auth),
647 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
650 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
653 VncClientInfo *cinfo = client->value;
655 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
656 monitor_printf(mon, " x509_dname: %s\n",
657 cinfo->has_x509_dname ?
658 cinfo->x509_dname : "none");
659 monitor_printf(mon, " sasl_username: %s\n",
660 cinfo->has_sasl_username ?
661 cinfo->sasl_username : "none");
663 client = client->next;
667 static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
670 VncServerInfo2 *sinfo = server->value;
671 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
672 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
673 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
674 server = server->next;
678 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
680 VncInfo2List *info2l;
683 info2l = qmp_query_vnc_servers(&err);
685 hmp_handle_error(mon, &err);
689 monitor_printf(mon, "None\n");
694 VncInfo2 *info = info2l->value;
695 monitor_printf(mon, "%s:\n", info->id);
696 hmp_info_vnc_servers(mon, info->server);
697 hmp_info_vnc_clients(mon, info->clients);
699 /* The server entry displays its auth, we only
700 * need to display in the case of 'reverse' connections
701 * where there's no server.
703 hmp_info_vnc_authcrypt(mon, " ", info->auth,
704 info->has_vencrypt ? &info->vencrypt : NULL);
706 if (info->has_display) {
707 monitor_printf(mon, " Display: %s\n", info->display);
709 info2l = info2l->next;
712 qapi_free_VncInfo2List(info2l);
718 void hmp_info_spice(Monitor *mon, const QDict *qdict)
720 SpiceChannelList *chan;
722 const char *channel_name;
723 const char * const channel_names[] = {
724 [SPICE_CHANNEL_MAIN] = "main",
725 [SPICE_CHANNEL_DISPLAY] = "display",
726 [SPICE_CHANNEL_INPUTS] = "inputs",
727 [SPICE_CHANNEL_CURSOR] = "cursor",
728 [SPICE_CHANNEL_PLAYBACK] = "playback",
729 [SPICE_CHANNEL_RECORD] = "record",
730 [SPICE_CHANNEL_TUNNEL] = "tunnel",
731 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
732 [SPICE_CHANNEL_USBREDIR] = "usbredir",
733 [SPICE_CHANNEL_PORT] = "port",
735 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
736 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
737 * as quick fix for build failures with older versions. */
738 [SPICE_CHANNEL_WEBDAV] = "webdav",
742 info = qmp_query_spice(NULL);
744 if (!info->enabled) {
745 monitor_printf(mon, "Server: disabled\n");
749 monitor_printf(mon, "Server:\n");
750 if (info->has_port) {
751 monitor_printf(mon, " address: %s:%" PRId64 "\n",
752 info->host, info->port);
754 if (info->has_tls_port) {
755 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
756 info->host, info->tls_port);
758 monitor_printf(mon, " migrated: %s\n",
759 info->migrated ? "true" : "false");
760 monitor_printf(mon, " auth: %s\n", info->auth);
761 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
762 monitor_printf(mon, " mouse-mode: %s\n",
763 SpiceQueryMouseMode_str(info->mouse_mode));
765 if (!info->has_channels || info->channels == NULL) {
766 monitor_printf(mon, "Channels: none\n");
768 for (chan = info->channels; chan; chan = chan->next) {
769 monitor_printf(mon, "Channel:\n");
770 monitor_printf(mon, " address: %s:%s%s\n",
771 chan->value->host, chan->value->port,
772 chan->value->tls ? " [tls]" : "");
773 monitor_printf(mon, " session: %" PRId64 "\n",
774 chan->value->connection_id);
775 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
776 chan->value->channel_type, chan->value->channel_id);
778 channel_name = "unknown";
779 if (chan->value->channel_type > 0 &&
780 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
781 channel_names[chan->value->channel_type]) {
782 channel_name = channel_names[chan->value->channel_type];
785 monitor_printf(mon, " channel name: %s\n", channel_name);
790 qapi_free_SpiceInfo(info);
794 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
799 info = qmp_query_balloon(&err);
801 hmp_handle_error(mon, &err);
805 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
807 qapi_free_BalloonInfo(info);
810 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
812 PciMemoryRegionList *region;
814 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
815 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
816 dev->slot, dev->function);
817 monitor_printf(mon, " ");
819 if (dev->class_info->has_desc) {
820 monitor_printf(mon, "%s", dev->class_info->desc);
822 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
825 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
826 dev->id->vendor, dev->id->device);
827 monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n",
828 dev->id->subsystem_vendor, dev->id->subsystem);
831 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
834 if (dev->has_pci_bridge) {
835 monitor_printf(mon, " BUS %" PRId64 ".\n",
836 dev->pci_bridge->bus->number);
837 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
838 dev->pci_bridge->bus->secondary);
839 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
840 dev->pci_bridge->bus->subordinate);
842 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
843 dev->pci_bridge->bus->io_range->base,
844 dev->pci_bridge->bus->io_range->limit);
847 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
848 dev->pci_bridge->bus->memory_range->base,
849 dev->pci_bridge->bus->memory_range->limit);
851 monitor_printf(mon, " prefetchable memory range "
852 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
853 dev->pci_bridge->bus->prefetchable_range->base,
854 dev->pci_bridge->bus->prefetchable_range->limit);
857 for (region = dev->regions; region; region = region->next) {
860 addr = region->value->address;
861 size = region->value->size;
863 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
865 if (!strcmp(region->value->type, "io")) {
866 monitor_printf(mon, "I/O at 0x%04" PRIx64
867 " [0x%04" PRIx64 "].\n",
868 addr, addr + size - 1);
870 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
871 " [0x%08" PRIx64 "].\n",
872 region->value->mem_type_64 ? 64 : 32,
873 region->value->prefetch ? " prefetchable" : "",
874 addr, addr + size - 1);
878 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
880 if (dev->has_pci_bridge) {
881 if (dev->pci_bridge->has_devices) {
882 PciDeviceInfoList *cdev;
883 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
884 hmp_info_pci_device(mon, cdev->value);
890 static int hmp_info_irq_foreach(Object *obj, void *opaque)
892 InterruptStatsProvider *intc;
893 InterruptStatsProviderClass *k;
894 Monitor *mon = opaque;
896 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
897 intc = INTERRUPT_STATS_PROVIDER(obj);
898 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
899 uint64_t *irq_counts;
900 unsigned int nb_irqs, i;
901 if (k->get_statistics &&
902 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
904 monitor_printf(mon, "IRQ statistics for %s:\n",
905 object_get_typename(obj));
906 for (i = 0; i < nb_irqs; i++) {
907 if (irq_counts[i] > 0) {
908 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
914 monitor_printf(mon, "IRQ statistics not available for %s.\n",
915 object_get_typename(obj));
922 void hmp_info_irq(Monitor *mon, const QDict *qdict)
924 object_child_foreach_recursive(object_get_root(),
925 hmp_info_irq_foreach, mon);
928 static int hmp_info_pic_foreach(Object *obj, void *opaque)
930 InterruptStatsProvider *intc;
931 InterruptStatsProviderClass *k;
932 Monitor *mon = opaque;
934 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
935 intc = INTERRUPT_STATS_PROVIDER(obj);
936 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
938 k->print_info(intc, mon);
940 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
941 object_get_typename(obj));
948 void hmp_info_pic(Monitor *mon, const QDict *qdict)
950 object_child_foreach_recursive(object_get_root(),
951 hmp_info_pic_foreach, mon);
954 void hmp_info_pci(Monitor *mon, const QDict *qdict)
956 PciInfoList *info_list, *info;
959 info_list = qmp_query_pci(&err);
961 monitor_printf(mon, "PCI devices not supported\n");
966 for (info = info_list; info; info = info->next) {
967 PciDeviceInfoList *dev;
969 for (dev = info->value->devices; dev; dev = dev->next) {
970 hmp_info_pci_device(mon, dev->value);
974 qapi_free_PciInfoList(info_list);
977 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
979 BlockJobInfoList *list;
982 list = qmp_query_block_jobs(&err);
986 monitor_printf(mon, "No active jobs\n");
991 if (strcmp(list->value->type, "stream") == 0) {
992 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
993 " of %" PRId64 " bytes, speed limit %" PRId64
1000 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
1001 " of %" PRId64 " bytes, speed limit %" PRId64
1004 list->value->device,
1005 list->value->offset,
1007 list->value->speed);
1012 qapi_free_BlockJobInfoList(list);
1015 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
1017 TPMInfoList *info_list, *info;
1020 TPMPassthroughOptions *tpo;
1021 TPMEmulatorOptions *teo;
1023 info_list = qmp_query_tpm(&err);
1025 monitor_printf(mon, "TPM device not supported\n");
1031 monitor_printf(mon, "TPM device:\n");
1034 for (info = info_list; info; info = info->next) {
1035 TPMInfo *ti = info->value;
1036 monitor_printf(mon, " tpm%d: model=%s\n",
1037 c, TpmModel_str(ti->model));
1039 monitor_printf(mon, " \\ %s: type=%s",
1040 ti->id, TpmTypeOptionsKind_str(ti->options->type));
1042 switch (ti->options->type) {
1043 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
1044 tpo = ti->options->u.passthrough.data;
1045 monitor_printf(mon, "%s%s%s%s",
1046 tpo->has_path ? ",path=" : "",
1047 tpo->has_path ? tpo->path : "",
1048 tpo->has_cancel_path ? ",cancel-path=" : "",
1049 tpo->has_cancel_path ? tpo->cancel_path : "");
1051 case TPM_TYPE_OPTIONS_KIND_EMULATOR:
1052 teo = ti->options->u.emulator.data;
1053 monitor_printf(mon, ",chardev=%s", teo->chardev);
1055 case TPM_TYPE_OPTIONS_KIND__MAX:
1058 monitor_printf(mon, "\n");
1061 qapi_free_TPMInfoList(info_list);
1064 void hmp_quit(Monitor *mon, const QDict *qdict)
1066 monitor_suspend(mon);
1070 void hmp_stop(Monitor *mon, const QDict *qdict)
1075 void hmp_sync_profile(Monitor *mon, const QDict *qdict)
1077 const char *op = qdict_get_try_str(qdict, "op");
1080 bool on = qsp_is_enabled();
1082 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off");
1085 if (!strcmp(op, "on")) {
1087 } else if (!strcmp(op, "off")) {
1089 } else if (!strcmp(op, "reset")) {
1094 error_setg(&err, QERR_INVALID_PARAMETER, op);
1095 hmp_handle_error(mon, &err);
1099 void hmp_system_reset(Monitor *mon, const QDict *qdict)
1101 qmp_system_reset(NULL);
1104 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
1106 qmp_system_powerdown(NULL);
1109 void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
1113 qmp_x_exit_preconfig(&err);
1114 hmp_handle_error(mon, &err);
1117 void hmp_cpu(Monitor *mon, const QDict *qdict)
1121 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1122 use it are converted to the QAPI */
1123 cpu_index = qdict_get_int(qdict, "index");
1124 if (monitor_set_cpu(cpu_index) < 0) {
1125 monitor_printf(mon, "invalid CPU index\n");
1129 void hmp_memsave(Monitor *mon, const QDict *qdict)
1131 uint32_t size = qdict_get_int(qdict, "size");
1132 const char *filename = qdict_get_str(qdict, "filename");
1133 uint64_t addr = qdict_get_int(qdict, "val");
1135 int cpu_index = monitor_get_cpu_index();
1137 if (cpu_index < 0) {
1138 monitor_printf(mon, "No CPU available\n");
1142 qmp_memsave(addr, size, filename, true, cpu_index, &err);
1143 hmp_handle_error(mon, &err);
1146 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1148 uint32_t size = qdict_get_int(qdict, "size");
1149 const char *filename = qdict_get_str(qdict, "filename");
1150 uint64_t addr = qdict_get_int(qdict, "val");
1153 qmp_pmemsave(addr, size, filename, &err);
1154 hmp_handle_error(mon, &err);
1157 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1159 const char *chardev = qdict_get_str(qdict, "device");
1160 const char *data = qdict_get_str(qdict, "data");
1163 qmp_ringbuf_write(chardev, data, false, 0, &err);
1165 hmp_handle_error(mon, &err);
1168 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
1170 uint32_t size = qdict_get_int(qdict, "size");
1171 const char *chardev = qdict_get_str(qdict, "device");
1176 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1178 hmp_handle_error(mon, &err);
1182 for (i = 0; data[i]; i++) {
1183 unsigned char ch = data[i];
1186 monitor_printf(mon, "\\\\");
1187 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1188 monitor_printf(mon, "\\u%04X", ch);
1190 monitor_printf(mon, "%c", ch);
1194 monitor_printf(mon, "\n");
1198 void hmp_cont(Monitor *mon, const QDict *qdict)
1203 hmp_handle_error(mon, &err);
1206 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1208 qmp_system_wakeup(NULL);
1211 void hmp_nmi(Monitor *mon, const QDict *qdict)
1215 qmp_inject_nmi(&err);
1216 hmp_handle_error(mon, &err);
1219 void hmp_set_link(Monitor *mon, const QDict *qdict)
1221 const char *name = qdict_get_str(qdict, "name");
1222 bool up = qdict_get_bool(qdict, "up");
1225 qmp_set_link(name, up, &err);
1226 hmp_handle_error(mon, &err);
1229 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1231 const char *device = qdict_get_str(qdict, "device");
1232 const char *password = qdict_get_str(qdict, "password");
1235 qmp_block_passwd(true, device, false, NULL, password, &err);
1236 hmp_handle_error(mon, &err);
1239 void hmp_balloon(Monitor *mon, const QDict *qdict)
1241 int64_t value = qdict_get_int(qdict, "value");
1244 qmp_balloon(value, &err);
1245 hmp_handle_error(mon, &err);
1248 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1250 const char *device = qdict_get_str(qdict, "device");
1251 int64_t size = qdict_get_int(qdict, "size");
1254 qmp_block_resize(true, device, false, NULL, size, &err);
1255 hmp_handle_error(mon, &err);
1258 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1260 const char *filename = qdict_get_str(qdict, "target");
1261 const char *format = qdict_get_try_str(qdict, "format");
1262 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1263 bool full = qdict_get_try_bool(qdict, "full", false);
1265 DriveMirror mirror = {
1266 .device = (char *)qdict_get_str(qdict, "device"),
1267 .target = (char *)filename,
1268 .has_format = !!format,
1269 .format = (char *)format,
1270 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1272 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1277 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1278 hmp_handle_error(mon, &err);
1281 qmp_drive_mirror(&mirror, &err);
1282 hmp_handle_error(mon, &err);
1285 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1287 const char *device = qdict_get_str(qdict, "device");
1288 const char *filename = qdict_get_str(qdict, "target");
1289 const char *format = qdict_get_try_str(qdict, "format");
1290 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1291 bool full = qdict_get_try_bool(qdict, "full", false);
1292 bool compress = qdict_get_try_bool(qdict, "compress", false);
1294 DriveBackup backup = {
1295 .device = (char *)device,
1296 .target = (char *)filename,
1297 .has_format = !!format,
1298 .format = (char *)format,
1299 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1301 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1302 .has_compress = !!compress,
1303 .compress = compress,
1307 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1308 hmp_handle_error(mon, &err);
1312 qmp_drive_backup(&backup, &err);
1313 hmp_handle_error(mon, &err);
1316 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1318 const char *device = qdict_get_str(qdict, "device");
1319 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1320 const char *format = qdict_get_try_str(qdict, "format");
1321 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1322 enum NewImageMode mode;
1326 /* In the future, if 'snapshot-file' is not specified, the snapshot
1327 will be taken internally. Today it's actually required. */
1328 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1329 hmp_handle_error(mon, &err);
1333 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1334 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1335 filename, false, NULL,
1338 hmp_handle_error(mon, &err);
1341 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1343 const char *device = qdict_get_str(qdict, "device");
1344 const char *name = qdict_get_str(qdict, "name");
1347 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1348 hmp_handle_error(mon, &err);
1351 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1353 const char *device = qdict_get_str(qdict, "device");
1354 const char *name = qdict_get_str(qdict, "name");
1355 const char *id = qdict_get_try_str(qdict, "id");
1358 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1360 hmp_handle_error(mon, &err);
1363 void hmp_loadvm(Monitor *mon, const QDict *qdict)
1365 int saved_vm_running = runstate_is_running();
1366 const char *name = qdict_get_str(qdict, "name");
1369 vm_stop(RUN_STATE_RESTORE_VM);
1371 if (load_snapshot(name, &err) == 0 && saved_vm_running) {
1374 hmp_handle_error(mon, &err);
1377 void hmp_savevm(Monitor *mon, const QDict *qdict)
1381 save_snapshot(qdict_get_try_str(qdict, "name"), &err);
1382 hmp_handle_error(mon, &err);
1385 void hmp_delvm(Monitor *mon, const QDict *qdict)
1387 BlockDriverState *bs;
1389 const char *name = qdict_get_str(qdict, "name");
1391 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
1392 error_reportf_err(err,
1393 "Error while deleting snapshot on device '%s': ",
1394 bdrv_get_device_name(bs));
1398 void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
1400 BlockDriverState *bs, *bs1;
1401 BdrvNextIterator it1;
1402 QEMUSnapshotInfo *sn_tab, *sn;
1403 bool no_snapshot = true;
1406 int *global_snapshots;
1407 AioContext *aio_context;
1409 typedef struct SnapshotEntry {
1410 QEMUSnapshotInfo sn;
1411 QTAILQ_ENTRY(SnapshotEntry) next;
1414 typedef struct ImageEntry {
1415 const char *imagename;
1416 QTAILQ_ENTRY(ImageEntry) next;
1417 QTAILQ_HEAD(, SnapshotEntry) snapshots;
1420 QTAILQ_HEAD(, ImageEntry) image_list =
1421 QTAILQ_HEAD_INITIALIZER(image_list);
1423 ImageEntry *image_entry, *next_ie;
1424 SnapshotEntry *snapshot_entry;
1426 bs = bdrv_all_find_vmstate_bs();
1428 monitor_printf(mon, "No available block device supports snapshots\n");
1431 aio_context = bdrv_get_aio_context(bs);
1433 aio_context_acquire(aio_context);
1434 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
1435 aio_context_release(aio_context);
1438 monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
1442 for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) {
1446 AioContext *ctx = bdrv_get_aio_context(bs1);
1448 aio_context_acquire(ctx);
1449 if (bdrv_can_snapshot(bs1)) {
1451 bs1_nb_sns = bdrv_snapshot_list(bs1, &sn);
1452 if (bs1_nb_sns > 0) {
1453 no_snapshot = false;
1454 ie = g_new0(ImageEntry, 1);
1455 ie->imagename = bdrv_get_device_name(bs1);
1456 QTAILQ_INIT(&ie->snapshots);
1457 QTAILQ_INSERT_TAIL(&image_list, ie, next);
1458 for (i = 0; i < bs1_nb_sns; i++) {
1459 se = g_new0(SnapshotEntry, 1);
1461 QTAILQ_INSERT_TAIL(&ie->snapshots, se, next);
1466 aio_context_release(ctx);
1470 monitor_printf(mon, "There is no snapshot available.\n");
1474 global_snapshots = g_new0(int, nb_sns);
1476 for (i = 0; i < nb_sns; i++) {
1477 SnapshotEntry *next_sn;
1478 if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) {
1479 global_snapshots[total] = i;
1481 QTAILQ_FOREACH(image_entry, &image_list, next) {
1482 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots,
1484 if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) {
1485 QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry,
1487 g_free(snapshot_entry);
1494 monitor_printf(mon, "List of snapshots present on all disks:\n");
1497 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1498 monitor_printf(mon, "\n");
1499 for (i = 0; i < total; i++) {
1500 sn = &sn_tab[global_snapshots[i]];
1501 /* The ID is not guaranteed to be the same on all images, so
1504 pstrcpy(sn->id_str, sizeof(sn->id_str), "--");
1505 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, sn);
1506 monitor_printf(mon, "\n");
1509 monitor_printf(mon, "None\n");
1512 QTAILQ_FOREACH(image_entry, &image_list, next) {
1513 if (QTAILQ_EMPTY(&image_entry->snapshots)) {
1517 "\nList of partial (non-loadable) snapshots on '%s':\n",
1518 image_entry->imagename);
1519 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1520 monitor_printf(mon, "\n");
1521 QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) {
1522 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon,
1523 &snapshot_entry->sn);
1524 monitor_printf(mon, "\n");
1528 QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) {
1529 SnapshotEntry *next_sn;
1530 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next,
1532 g_free(snapshot_entry);
1534 g_free(image_entry);
1537 g_free(global_snapshots);
1541 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1543 qmp_migrate_cancel(NULL);
1546 void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1549 const char *state = qdict_get_str(qdict, "state");
1550 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1553 qmp_migrate_continue(val, &err);
1556 hmp_handle_error(mon, &err);
1559 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1562 const char *uri = qdict_get_str(qdict, "uri");
1564 qmp_migrate_incoming(uri, &err);
1566 hmp_handle_error(mon, &err);
1569 void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
1572 const char *uri = qdict_get_str(qdict, "uri");
1574 qmp_migrate_recover(uri, &err);
1576 hmp_handle_error(mon, &err);
1579 void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
1583 qmp_migrate_pause(&err);
1585 hmp_handle_error(mon, &err);
1588 /* Kept for backwards compatibility */
1589 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1591 double value = qdict_get_double(qdict, "value");
1592 qmp_migrate_set_downtime(value, NULL);
1595 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1597 int64_t value = qdict_get_int(qdict, "value");
1600 qmp_migrate_set_cache_size(value, &err);
1601 hmp_handle_error(mon, &err);
1604 /* Kept for backwards compatibility */
1605 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1607 int64_t value = qdict_get_int(qdict, "value");
1608 qmp_migrate_set_speed(value, NULL);
1611 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1613 const char *cap = qdict_get_str(qdict, "capability");
1614 bool state = qdict_get_bool(qdict, "state");
1616 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1619 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
1624 caps->value = g_malloc0(sizeof(*caps->value));
1625 caps->value->capability = val;
1626 caps->value->state = state;
1628 qmp_migrate_set_capabilities(caps, &err);
1631 qapi_free_MigrationCapabilityStatusList(caps);
1632 hmp_handle_error(mon, &err);
1635 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1637 const char *param = qdict_get_str(qdict, "parameter");
1638 const char *valuestr = qdict_get_str(qdict, "value");
1639 Visitor *v = string_input_visitor_new(valuestr);
1640 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
1641 uint64_t valuebw = 0;
1642 uint64_t cache_size;
1646 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
1652 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1653 p->has_compress_level = true;
1654 visit_type_int(v, param, &p->compress_level, &err);
1656 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1657 p->has_compress_threads = true;
1658 visit_type_int(v, param, &p->compress_threads, &err);
1660 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD:
1661 p->has_compress_wait_thread = true;
1662 visit_type_bool(v, param, &p->compress_wait_thread, &err);
1664 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1665 p->has_decompress_threads = true;
1666 visit_type_int(v, param, &p->decompress_threads, &err);
1668 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1669 p->has_cpu_throttle_initial = true;
1670 visit_type_int(v, param, &p->cpu_throttle_initial, &err);
1672 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1673 p->has_cpu_throttle_increment = true;
1674 visit_type_int(v, param, &p->cpu_throttle_increment, &err);
1676 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE:
1677 p->has_max_cpu_throttle = true;
1678 visit_type_int(v, param, &p->max_cpu_throttle, &err);
1680 case MIGRATION_PARAMETER_TLS_CREDS:
1681 p->has_tls_creds = true;
1682 p->tls_creds = g_new0(StrOrNull, 1);
1683 p->tls_creds->type = QTYPE_QSTRING;
1684 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1686 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1687 p->has_tls_hostname = true;
1688 p->tls_hostname = g_new0(StrOrNull, 1);
1689 p->tls_hostname->type = QTYPE_QSTRING;
1690 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1692 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1693 p->has_max_bandwidth = true;
1695 * Can't use visit_type_size() here, because it
1696 * defaults to Bytes rather than Mebibytes.
1698 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1699 if (ret < 0 || valuebw > INT64_MAX
1700 || (size_t)valuebw != valuebw) {
1701 error_setg(&err, "Invalid size %s", valuestr);
1704 p->max_bandwidth = valuebw;
1706 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1707 p->has_downtime_limit = true;
1708 visit_type_int(v, param, &p->downtime_limit, &err);
1710 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1711 p->has_x_checkpoint_delay = true;
1712 visit_type_int(v, param, &p->x_checkpoint_delay, &err);
1714 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1715 p->has_block_incremental = true;
1716 visit_type_bool(v, param, &p->block_incremental, &err);
1718 case MIGRATION_PARAMETER_X_MULTIFD_CHANNELS:
1719 p->has_x_multifd_channels = true;
1720 visit_type_int(v, param, &p->x_multifd_channels, &err);
1722 case MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT:
1723 p->has_x_multifd_page_count = true;
1724 visit_type_int(v, param, &p->x_multifd_page_count, &err);
1726 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1727 p->has_xbzrle_cache_size = true;
1728 visit_type_size(v, param, &cache_size, &err);
1729 if (err || cache_size > INT64_MAX
1730 || (size_t)cache_size != cache_size) {
1731 error_setg(&err, "Invalid size %s", valuestr);
1734 p->xbzrle_cache_size = cache_size;
1736 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH:
1737 p->has_max_postcopy_bandwidth = true;
1738 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err);
1748 qmp_migrate_set_parameters(p, &err);
1751 qapi_free_MigrateSetParameters(p);
1753 hmp_handle_error(mon, &err);
1756 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1759 const char *protocol = qdict_get_str(qdict, "protocol");
1760 const char *hostname = qdict_get_str(qdict, "hostname");
1761 bool has_port = qdict_haskey(qdict, "port");
1762 int port = qdict_get_try_int(qdict, "port", -1);
1763 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1764 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1765 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1767 qmp_client_migrate_info(protocol, hostname,
1768 has_port, port, has_tls_port, tls_port,
1769 !!cert_subject, cert_subject, &err);
1770 hmp_handle_error(mon, &err);
1773 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1776 qmp_migrate_start_postcopy(&err);
1777 hmp_handle_error(mon, &err);
1780 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1784 qmp_x_colo_lost_heartbeat(&err);
1785 hmp_handle_error(mon, &err);
1788 void hmp_set_password(Monitor *mon, const QDict *qdict)
1790 const char *protocol = qdict_get_str(qdict, "protocol");
1791 const char *password = qdict_get_str(qdict, "password");
1792 const char *connected = qdict_get_try_str(qdict, "connected");
1795 qmp_set_password(protocol, password, !!connected, connected, &err);
1796 hmp_handle_error(mon, &err);
1799 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1801 const char *protocol = qdict_get_str(qdict, "protocol");
1802 const char *whenstr = qdict_get_str(qdict, "time");
1805 qmp_expire_password(protocol, whenstr, &err);
1806 hmp_handle_error(mon, &err);
1809 void hmp_eject(Monitor *mon, const QDict *qdict)
1811 bool force = qdict_get_try_bool(qdict, "force", false);
1812 const char *device = qdict_get_str(qdict, "device");
1815 qmp_eject(true, device, false, NULL, true, force, &err);
1816 hmp_handle_error(mon, &err);
1820 static void hmp_change_read_arg(void *opaque, const char *password,
1821 void *readline_opaque)
1823 qmp_change_vnc_password(password, NULL);
1824 monitor_read_command(opaque, 1);
1828 void hmp_change(Monitor *mon, const QDict *qdict)
1830 const char *device = qdict_get_str(qdict, "device");
1831 const char *target = qdict_get_str(qdict, "target");
1832 const char *arg = qdict_get_try_str(qdict, "arg");
1833 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1834 BlockdevChangeReadOnlyMode read_only_mode = 0;
1838 if (strcmp(device, "vnc") == 0) {
1841 "Parameter 'read-only-mode' is invalid for VNC\n");
1844 if (strcmp(target, "passwd") == 0 ||
1845 strcmp(target, "password") == 0) {
1847 monitor_read_password(mon, hmp_change_read_arg, NULL);
1851 qmp_change("vnc", target, !!arg, arg, &err);
1857 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
1859 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1861 hmp_handle_error(mon, &err);
1866 qmp_blockdev_change_medium(true, device, false, NULL, target,
1867 !!arg, arg, !!read_only, read_only_mode,
1871 hmp_handle_error(mon, &err);
1874 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1877 char *device = (char *) qdict_get_str(qdict, "device");
1878 BlockIOThrottle throttle = {
1879 .bps = qdict_get_int(qdict, "bps"),
1880 .bps_rd = qdict_get_int(qdict, "bps_rd"),
1881 .bps_wr = qdict_get_int(qdict, "bps_wr"),
1882 .iops = qdict_get_int(qdict, "iops"),
1883 .iops_rd = qdict_get_int(qdict, "iops_rd"),
1884 .iops_wr = qdict_get_int(qdict, "iops_wr"),
1887 /* qmp_block_set_io_throttle has separate parameters for the
1888 * (deprecated) block device name and the qdev ID but the HMP
1889 * version has only one, so we must decide which one to pass. */
1890 if (blk_by_name(device)) {
1891 throttle.has_device = true;
1892 throttle.device = device;
1894 throttle.has_id = true;
1895 throttle.id = device;
1898 qmp_block_set_io_throttle(&throttle, &err);
1899 hmp_handle_error(mon, &err);
1902 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1904 Error *error = NULL;
1905 const char *device = qdict_get_str(qdict, "device");
1906 const char *base = qdict_get_try_str(qdict, "base");
1907 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1909 qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
1910 false, NULL, qdict_haskey(qdict, "speed"), speed,
1911 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1913 hmp_handle_error(mon, &error);
1916 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1918 Error *error = NULL;
1919 const char *device = qdict_get_str(qdict, "device");
1920 int64_t value = qdict_get_int(qdict, "speed");
1922 qmp_block_job_set_speed(device, value, &error);
1924 hmp_handle_error(mon, &error);
1927 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1929 Error *error = NULL;
1930 const char *device = qdict_get_str(qdict, "device");
1931 bool force = qdict_get_try_bool(qdict, "force", false);
1933 qmp_block_job_cancel(device, true, force, &error);
1935 hmp_handle_error(mon, &error);
1938 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1940 Error *error = NULL;
1941 const char *device = qdict_get_str(qdict, "device");
1943 qmp_block_job_pause(device, &error);
1945 hmp_handle_error(mon, &error);
1948 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1950 Error *error = NULL;
1951 const char *device = qdict_get_str(qdict, "device");
1953 qmp_block_job_resume(device, &error);
1955 hmp_handle_error(mon, &error);
1958 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1960 Error *error = NULL;
1961 const char *device = qdict_get_str(qdict, "device");
1963 qmp_block_job_complete(device, &error);
1965 hmp_handle_error(mon, &error);
1968 typedef struct HMPMigrationStatus
1972 bool is_block_migration;
1973 } HMPMigrationStatus;
1975 static void hmp_migrate_status_cb(void *opaque)
1977 HMPMigrationStatus *status = opaque;
1978 MigrationInfo *info;
1980 info = qmp_query_migrate(NULL);
1981 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1982 info->status == MIGRATION_STATUS_SETUP) {
1983 if (info->has_disk) {
1986 if (info->disk->remaining) {
1987 progress = info->disk->transferred * 100 / info->disk->total;
1992 monitor_printf(status->mon, "Completed %d %%\r", progress);
1993 monitor_flush(status->mon);
1996 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1998 if (status->is_block_migration) {
1999 monitor_printf(status->mon, "\n");
2001 if (info->has_error_desc) {
2002 error_report("%s", info->error_desc);
2004 monitor_resume(status->mon);
2005 timer_del(status->timer);
2006 timer_free(status->timer);
2010 qapi_free_MigrationInfo(info);
2013 void hmp_migrate(Monitor *mon, const QDict *qdict)
2015 bool detach = qdict_get_try_bool(qdict, "detach", false);
2016 bool blk = qdict_get_try_bool(qdict, "blk", false);
2017 bool inc = qdict_get_try_bool(qdict, "inc", false);
2018 bool resume = qdict_get_try_bool(qdict, "resume", false);
2019 const char *uri = qdict_get_str(qdict, "uri");
2022 qmp_migrate(uri, !!blk, blk, !!inc, inc,
2023 false, false, true, resume, &err);
2025 hmp_handle_error(mon, &err);
2030 HMPMigrationStatus *status;
2032 if (monitor_suspend(mon) < 0) {
2033 monitor_printf(mon, "terminal does not allow synchronous "
2034 "migration, continuing detached\n");
2038 status = g_malloc0(sizeof(*status));
2040 status->is_block_migration = blk || inc;
2041 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
2043 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
2047 void hmp_device_add(Monitor *mon, const QDict *qdict)
2051 qmp_device_add((QDict *)qdict, NULL, &err);
2052 hmp_handle_error(mon, &err);
2055 void hmp_device_del(Monitor *mon, const QDict *qdict)
2057 const char *id = qdict_get_str(qdict, "id");
2060 qmp_device_del(id, &err);
2061 hmp_handle_error(mon, &err);
2064 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
2067 bool win_dmp = qdict_get_try_bool(qdict, "windmp", false);
2068 bool paging = qdict_get_try_bool(qdict, "paging", false);
2069 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
2070 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
2071 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
2072 const char *file = qdict_get_str(qdict, "filename");
2073 bool has_begin = qdict_haskey(qdict, "begin");
2074 bool has_length = qdict_haskey(qdict, "length");
2075 bool has_detach = qdict_haskey(qdict, "detach");
2078 bool detach = false;
2079 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
2082 if (zlib + lzo + snappy + win_dmp > 1) {
2083 error_setg(&err, "only one of '-z|-l|-s|-w' can be set");
2084 hmp_handle_error(mon, &err);
2089 dump_format = DUMP_GUEST_MEMORY_FORMAT_WIN_DMP;
2093 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
2097 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
2101 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
2105 begin = qdict_get_int(qdict, "begin");
2108 length = qdict_get_int(qdict, "length");
2111 detach = qdict_get_bool(qdict, "detach");
2114 prot = g_strconcat("file:", file, NULL);
2116 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
2117 has_length, length, true, dump_format, &err);
2118 hmp_handle_error(mon, &err);
2122 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
2127 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
2132 netdev_add(opts, &err);
2134 qemu_opts_del(opts);
2138 hmp_handle_error(mon, &err);
2141 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
2143 const char *id = qdict_get_str(qdict, "id");
2146 qmp_netdev_del(id, &err);
2147 hmp_handle_error(mon, &err);
2150 void hmp_object_add(Monitor *mon, const QDict *qdict)
2156 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
2158 hmp_handle_error(mon, &err);
2162 obj = user_creatable_add_opts(opts, &err);
2163 qemu_opts_del(opts);
2166 hmp_handle_error(mon, &err);
2173 void hmp_getfd(Monitor *mon, const QDict *qdict)
2175 const char *fdname = qdict_get_str(qdict, "fdname");
2178 qmp_getfd(fdname, &err);
2179 hmp_handle_error(mon, &err);
2182 void hmp_closefd(Monitor *mon, const QDict *qdict)
2184 const char *fdname = qdict_get_str(qdict, "fdname");
2187 qmp_closefd(fdname, &err);
2188 hmp_handle_error(mon, &err);
2191 void hmp_sendkey(Monitor *mon, const QDict *qdict)
2193 const char *keys = qdict_get_str(qdict, "keys");
2194 KeyValueList *keylist, *head = NULL, *tmp = NULL;
2195 int has_hold_time = qdict_haskey(qdict, "hold-time");
2196 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
2198 const char *separator;
2202 separator = qemu_strchrnul(keys, '-');
2203 keyname_len = separator - keys;
2205 /* Be compatible with old interface, convert user inputted "<" */
2206 if (keys[0] == '<' && keyname_len == 1) {
2211 keylist = g_malloc0(sizeof(*keylist));
2212 keylist->value = g_malloc0(sizeof(*keylist->value));
2218 tmp->next = keylist;
2222 if (strstart(keys, "0x", NULL)) {
2224 int value = strtoul(keys, &endp, 0);
2225 assert(endp <= keys + keyname_len);
2226 if (endp != keys + keyname_len) {
2229 keylist->value->type = KEY_VALUE_KIND_NUMBER;
2230 keylist->value->u.number.data = value;
2232 int idx = index_from_key(keys, keyname_len);
2233 if (idx == Q_KEY_CODE__MAX) {
2236 keylist->value->type = KEY_VALUE_KIND_QCODE;
2237 keylist->value->u.qcode.data = idx;
2243 keys = separator + 1;
2246 qmp_send_key(head, has_hold_time, hold_time, &err);
2247 hmp_handle_error(mon, &err);
2250 qapi_free_KeyValueList(head);
2254 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
2258 void hmp_screendump(Monitor *mon, const QDict *qdict)
2260 const char *filename = qdict_get_str(qdict, "filename");
2261 const char *id = qdict_get_try_str(qdict, "device");
2262 int64_t head = qdict_get_try_int(qdict, "head", 0);
2265 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
2266 hmp_handle_error(mon, &err);
2269 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
2271 const char *uri = qdict_get_str(qdict, "uri");
2272 bool writable = qdict_get_try_bool(qdict, "writable", false);
2273 bool all = qdict_get_try_bool(qdict, "all", false);
2274 Error *local_err = NULL;
2275 BlockInfoList *block_list, *info;
2276 SocketAddress *addr;
2278 if (writable && !all) {
2279 error_setg(&local_err, "-w only valid together with -a");
2283 /* First check if the address is valid and start the server. */
2284 addr = socket_parse(uri, &local_err);
2285 if (local_err != NULL) {
2289 nbd_server_start(addr, NULL, &local_err);
2290 qapi_free_SocketAddress(addr);
2291 if (local_err != NULL) {
2299 /* Then try adding all block devices. If one fails, close all and
2302 block_list = qmp_query_block(NULL);
2304 for (info = block_list; info; info = info->next) {
2305 if (!info->value->has_inserted) {
2309 qmp_nbd_server_add(info->value->device, false, NULL,
2310 true, writable, &local_err);
2312 if (local_err != NULL) {
2313 qmp_nbd_server_stop(NULL);
2318 qapi_free_BlockInfoList(block_list);
2321 hmp_handle_error(mon, &local_err);
2324 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
2326 const char *device = qdict_get_str(qdict, "device");
2327 const char *name = qdict_get_try_str(qdict, "name");
2328 bool writable = qdict_get_try_bool(qdict, "writable", false);
2329 Error *local_err = NULL;
2331 qmp_nbd_server_add(device, !!name, name, true, writable, &local_err);
2332 hmp_handle_error(mon, &local_err);
2335 void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict)
2337 const char *name = qdict_get_str(qdict, "name");
2338 bool force = qdict_get_try_bool(qdict, "force", false);
2341 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
2342 qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err);
2343 hmp_handle_error(mon, &err);
2346 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
2350 qmp_nbd_server_stop(&err);
2351 hmp_handle_error(mon, &err);
2354 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
2359 cpuid = qdict_get_int(qdict, "id");
2360 qmp_cpu_add(cpuid, &err);
2361 hmp_handle_error(mon, &err);
2364 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2366 const char *args = qdict_get_str(qdict, "args");
2370 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
2372 error_setg(&err, "Parsing chardev args failed");
2374 qemu_chr_new_from_opts(opts, &err);
2375 qemu_opts_del(opts);
2377 hmp_handle_error(mon, &err);
2380 void hmp_chardev_change(Monitor *mon, const QDict *qdict)
2382 const char *args = qdict_get_str(qdict, "args");
2385 ChardevBackend *backend = NULL;
2386 ChardevReturn *ret = NULL;
2387 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
2390 error_setg(&err, "Parsing chardev args failed");
2394 id = qdict_get_str(qdict, "id");
2395 if (qemu_opts_id(opts)) {
2396 error_setg(&err, "Unexpected 'id' parameter");
2400 backend = qemu_chr_parse_opts(opts, &err);
2405 ret = qmp_chardev_change(id, backend, &err);
2408 qapi_free_ChardevReturn(ret);
2409 qapi_free_ChardevBackend(backend);
2410 qemu_opts_del(opts);
2411 hmp_handle_error(mon, &err);
2414 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2416 Error *local_err = NULL;
2418 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
2419 hmp_handle_error(mon, &local_err);
2422 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
2424 Error *local_err = NULL;
2426 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
2427 hmp_handle_error(mon, &local_err);
2430 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
2433 BlockBackend *local_blk = NULL;
2434 const char* device = qdict_get_str(qdict, "device");
2435 const char* command = qdict_get_str(qdict, "command");
2439 blk = blk_by_name(device);
2441 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
2443 blk = local_blk = blk_new(0, BLK_PERM_ALL);
2444 ret = blk_insert_bs(blk, bs, &err);
2454 * Notably absent: Proper permission management. This is sad, but it seems
2455 * almost impossible to achieve without changing the semantics and thereby
2456 * limiting the use cases of the qemu-io HMP command.
2458 * In an ideal world we would unconditionally create a new BlockBackend for
2459 * qemuio_command(), but we have commands like 'reopen' and want them to
2460 * take effect on the exact BlockBackend whose name the user passed instead
2461 * of just on a temporary copy of it.
2463 * Another problem is that deleting the temporary BlockBackend involves
2464 * draining all requests on it first, but some qemu-iotests cases want to
2465 * issue multiple aio_read/write requests and expect them to complete in
2466 * the background while the monitor has already returned.
2468 * This is also what prevents us from saving the original permissions and
2469 * restoring them later: We can't revoke permissions until all requests
2470 * have completed, and we don't know when that is nor can we really let
2471 * anything else run before we have revoken them to avoid race conditions.
2473 * What happens now is that command() in qemu-io-cmds.c can extend the
2474 * permissions if necessary for the qemu-io command. And they simply stay
2475 * extended, possibly resulting in a read-only guest device keeping write
2476 * permissions. Ugly, but it appears to be the lesser evil.
2478 qemuio_command(blk, command);
2481 blk_unref(local_blk);
2482 hmp_handle_error(mon, &err);
2485 void hmp_object_del(Monitor *mon, const QDict *qdict)
2487 const char *id = qdict_get_str(qdict, "id");
2490 user_creatable_del(id, &err);
2491 hmp_handle_error(mon, &err);
2494 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
2497 MemdevList *memdev_list = qmp_query_memdev(&err);
2498 MemdevList *m = memdev_list;
2503 v = string_output_visitor_new(false, &str);
2504 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
2505 monitor_printf(mon, "memory backend: %s\n", m->value->id);
2506 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
2507 monitor_printf(mon, " merge: %s\n",
2508 m->value->merge ? "true" : "false");
2509 monitor_printf(mon, " dump: %s\n",
2510 m->value->dump ? "true" : "false");
2511 monitor_printf(mon, " prealloc: %s\n",
2512 m->value->prealloc ? "true" : "false");
2513 monitor_printf(mon, " policy: %s\n",
2514 HostMemPolicy_str(m->value->policy));
2515 visit_complete(v, &str);
2516 monitor_printf(mon, " host nodes: %s\n", str);
2523 monitor_printf(mon, "\n");
2525 qapi_free_MemdevList(memdev_list);
2526 hmp_handle_error(mon, &err);
2529 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2532 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2533 MemoryDeviceInfoList *info;
2534 MemoryDeviceInfo *value;
2535 PCDIMMDeviceInfo *di;
2537 for (info = info_list; info; info = info->next) {
2538 value = info->value;
2541 switch (value->type) {
2542 case MEMORY_DEVICE_INFO_KIND_DIMM:
2543 di = value->u.dimm.data;
2546 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
2547 di = value->u.nvdimm.data;
2556 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2557 MemoryDeviceInfoKind_str(value->type),
2558 di->id ? di->id : "");
2559 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2560 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2561 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2562 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2563 monitor_printf(mon, " memdev: %s\n", di->memdev);
2564 monitor_printf(mon, " hotplugged: %s\n",
2565 di->hotplugged ? "true" : "false");
2566 monitor_printf(mon, " hotpluggable: %s\n",
2567 di->hotpluggable ? "true" : "false");
2572 qapi_free_MemoryDeviceInfoList(info_list);
2573 hmp_handle_error(mon, &err);
2576 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2578 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2579 IOThreadInfoList *info;
2580 IOThreadInfo *value;
2582 for (info = info_list; info; info = info->next) {
2583 value = info->value;
2584 monitor_printf(mon, "%s:\n", value->id);
2585 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
2586 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2587 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
2588 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
2591 qapi_free_IOThreadInfoList(info_list);
2594 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2596 const char *path = qdict_get_try_str(qdict, "path");
2597 ObjectPropertyInfoList *list;
2601 monitor_printf(mon, "/\n");
2605 list = qmp_qom_list(path, &err);
2607 ObjectPropertyInfoList *start = list;
2608 while (list != NULL) {
2609 ObjectPropertyInfo *value = list->value;
2611 monitor_printf(mon, "%s (%s)\n",
2612 value->name, value->type);
2615 qapi_free_ObjectPropertyInfoList(start);
2617 hmp_handle_error(mon, &err);
2620 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2622 const char *path = qdict_get_str(qdict, "path");
2623 const char *property = qdict_get_str(qdict, "property");
2624 const char *value = qdict_get_str(qdict, "value");
2626 bool ambiguous = false;
2629 obj = object_resolve_path(path, &ambiguous);
2631 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2632 "Device '%s' not found", path);
2635 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2637 object_property_parse(obj, value, property, &err);
2639 hmp_handle_error(mon, &err);
2642 void hmp_rocker(Monitor *mon, const QDict *qdict)
2644 const char *name = qdict_get_str(qdict, "name");
2645 RockerSwitch *rocker;
2648 rocker = qmp_query_rocker(name, &err);
2650 hmp_handle_error(mon, &err);
2654 monitor_printf(mon, "name: %s\n", rocker->name);
2655 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2656 monitor_printf(mon, "ports: %d\n", rocker->ports);
2658 qapi_free_RockerSwitch(rocker);
2661 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2663 RockerPortList *list, *port;
2664 const char *name = qdict_get_str(qdict, "name");
2667 list = qmp_query_rocker_ports(name, &err);
2669 hmp_handle_error(mon, &err);
2673 monitor_printf(mon, " ena/ speed/ auto\n");
2674 monitor_printf(mon, " port link duplex neg?\n");
2676 for (port = list; port; port = port->next) {
2677 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2679 port->value->enabled ? port->value->link_up ?
2680 "up" : "down" : "!ena",
2681 port->value->speed == 10000 ? "10G" : "??",
2682 port->value->duplex ? "FD" : "HD",
2683 port->value->autoneg ? "Yes" : "No");
2686 qapi_free_RockerPortList(list);
2689 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2691 RockerOfDpaFlowList *list, *info;
2692 const char *name = qdict_get_str(qdict, "name");
2693 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2696 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2698 hmp_handle_error(mon, &err);
2702 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2704 for (info = list; info; info = info->next) {
2705 RockerOfDpaFlow *flow = info->value;
2706 RockerOfDpaFlowKey *key = flow->key;
2707 RockerOfDpaFlowMask *mask = flow->mask;
2708 RockerOfDpaFlowAction *action = flow->action;
2711 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2712 key->priority, key->tbl_id, flow->hits);
2714 monitor_printf(mon, "%-4d %-3d ",
2715 key->priority, key->tbl_id);
2718 if (key->has_in_pport) {
2719 monitor_printf(mon, " pport %d", key->in_pport);
2720 if (mask->has_in_pport) {
2721 monitor_printf(mon, "(0x%x)", mask->in_pport);
2725 if (key->has_vlan_id) {
2726 monitor_printf(mon, " vlan %d",
2727 key->vlan_id & VLAN_VID_MASK);
2728 if (mask->has_vlan_id) {
2729 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2733 if (key->has_tunnel_id) {
2734 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2735 if (mask->has_tunnel_id) {
2736 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2740 if (key->has_eth_type) {
2741 switch (key->eth_type) {
2743 monitor_printf(mon, " ARP");
2746 monitor_printf(mon, " IP");
2749 monitor_printf(mon, " IPv6");
2752 monitor_printf(mon, " LACP");
2755 monitor_printf(mon, " LLDP");
2758 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2763 if (key->has_eth_src) {
2764 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2765 (mask->has_eth_src) &&
2766 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2767 monitor_printf(mon, " src <any mcast/bcast>");
2768 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2769 (mask->has_eth_src) &&
2770 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2771 monitor_printf(mon, " src <any ucast>");
2773 monitor_printf(mon, " src %s", key->eth_src);
2774 if (mask->has_eth_src) {
2775 monitor_printf(mon, "(%s)", mask->eth_src);
2780 if (key->has_eth_dst) {
2781 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2782 (mask->has_eth_dst) &&
2783 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2784 monitor_printf(mon, " dst <any mcast/bcast>");
2785 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2786 (mask->has_eth_dst) &&
2787 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2788 monitor_printf(mon, " dst <any ucast>");
2790 monitor_printf(mon, " dst %s", key->eth_dst);
2791 if (mask->has_eth_dst) {
2792 monitor_printf(mon, "(%s)", mask->eth_dst);
2797 if (key->has_ip_proto) {
2798 monitor_printf(mon, " proto %d", key->ip_proto);
2799 if (mask->has_ip_proto) {
2800 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2804 if (key->has_ip_tos) {
2805 monitor_printf(mon, " TOS %d", key->ip_tos);
2806 if (mask->has_ip_tos) {
2807 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2811 if (key->has_ip_dst) {
2812 monitor_printf(mon, " dst %s", key->ip_dst);
2815 if (action->has_goto_tbl || action->has_group_id ||
2816 action->has_new_vlan_id) {
2817 monitor_printf(mon, " -->");
2820 if (action->has_new_vlan_id) {
2821 monitor_printf(mon, " apply new vlan %d",
2822 ntohs(action->new_vlan_id));
2825 if (action->has_group_id) {
2826 monitor_printf(mon, " write group 0x%08x", action->group_id);
2829 if (action->has_goto_tbl) {
2830 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2833 monitor_printf(mon, "\n");
2836 qapi_free_RockerOfDpaFlowList(list);
2839 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2841 RockerOfDpaGroupList *list, *g;
2842 const char *name = qdict_get_str(qdict, "name");
2843 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2847 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2849 hmp_handle_error(mon, &err);
2853 monitor_printf(mon, "id (decode) --> buckets\n");
2855 for (g = list; g; g = g->next) {
2856 RockerOfDpaGroup *group = g->value;
2858 monitor_printf(mon, "0x%08x", group->id);
2860 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2861 group->type == 1 ? "L2 rewrite" :
2862 group->type == 2 ? "L3 unicast" :
2863 group->type == 3 ? "L2 multicast" :
2864 group->type == 4 ? "L2 flood" :
2865 group->type == 5 ? "L3 interface" :
2866 group->type == 6 ? "L3 multicast" :
2867 group->type == 7 ? "L3 ECMP" :
2868 group->type == 8 ? "L2 overlay" :
2871 if (group->has_vlan_id) {
2872 monitor_printf(mon, " vlan %d", group->vlan_id);
2875 if (group->has_pport) {
2876 monitor_printf(mon, " pport %d", group->pport);
2879 if (group->has_index) {
2880 monitor_printf(mon, " index %d", group->index);
2883 monitor_printf(mon, ") -->");
2885 if (group->has_set_vlan_id && group->set_vlan_id) {
2887 monitor_printf(mon, " set vlan %d",
2888 group->set_vlan_id & VLAN_VID_MASK);
2891 if (group->has_set_eth_src) {
2894 monitor_printf(mon, " set");
2896 monitor_printf(mon, " src %s", group->set_eth_src);
2899 if (group->has_set_eth_dst) {
2902 monitor_printf(mon, " set");
2904 monitor_printf(mon, " dst %s", group->set_eth_dst);
2909 if (group->has_ttl_check && group->ttl_check) {
2910 monitor_printf(mon, " check TTL");
2913 if (group->has_group_id && group->group_id) {
2914 monitor_printf(mon, " group id 0x%08x", group->group_id);
2917 if (group->has_pop_vlan && group->pop_vlan) {
2918 monitor_printf(mon, " pop vlan");
2921 if (group->has_out_pport) {
2922 monitor_printf(mon, " out pport %d", group->out_pport);
2925 if (group->has_group_ids) {
2926 struct uint32List *id;
2928 monitor_printf(mon, " groups [");
2929 for (id = group->group_ids; id; id = id->next) {
2930 monitor_printf(mon, "0x%08x", id->value);
2932 monitor_printf(mon, ",");
2935 monitor_printf(mon, "]");
2938 monitor_printf(mon, "\n");
2941 qapi_free_RockerOfDpaGroupList(list);
2944 void hmp_info_dump(Monitor *mon, const QDict *qdict)
2946 DumpQueryResult *result = qmp_query_dump(NULL);
2948 assert(result && result->status < DUMP_STATUS__MAX);
2949 monitor_printf(mon, "Status: %s\n", DumpStatus_str(result->status));
2951 if (result->status == DUMP_STATUS_ACTIVE) {
2953 assert(result->total != 0);
2954 percent = 100.0 * result->completed / result->total;
2955 monitor_printf(mon, "Finished: %.2f %%\n", percent);
2958 qapi_free_DumpQueryResult(result);
2961 void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
2963 ram_block_dump(mon);
2966 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
2969 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
2970 HotpluggableCPUList *saved = l;
2971 CpuInstanceProperties *c;
2974 hmp_handle_error(mon, &err);
2978 monitor_printf(mon, "Hotpluggable CPUs:\n");
2980 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
2981 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
2982 l->value->vcpus_count);
2983 if (l->value->has_qom_path) {
2984 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
2987 c = l->value->props;
2988 monitor_printf(mon, " CPUInstance Properties:\n");
2989 if (c->has_node_id) {
2990 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
2992 if (c->has_socket_id) {
2993 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
2995 if (c->has_core_id) {
2996 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
2998 if (c->has_thread_id) {
2999 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
3005 qapi_free_HotpluggableCPUList(saved);
3008 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
3011 GuidInfo *info = qmp_query_vm_generation_id(&err);
3013 monitor_printf(mon, "%s\n", info->guid);
3015 hmp_handle_error(mon, &err);
3016 qapi_free_GuidInfo(info);
3019 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
3022 MemoryInfo *info = qmp_query_memory_size_summary(&err);
3024 monitor_printf(mon, "base memory: %" PRIu64 "\n",
3027 if (info->has_plugged_memory) {
3028 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
3029 info->plugged_memory);
3032 qapi_free_MemoryInfo(info);
3034 hmp_handle_error(mon, &err);