hw/char: remove legacy interface escc_init()
[qemu/rayw.git] / hmp.c
blob7870d6a3004e1e980ea955729e6747ecea7b61ce
1 /*
2 * Human Monitor Interface
4 * Copyright IBM, Corp. 2011
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
16 #include "qemu/osdep.h"
17 #include "hmp.h"
18 #include "net/net.h"
19 #include "net/eth.h"
20 #include "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 "qmp-commands.h"
27 #include "qemu/sockets.h"
28 #include "monitor/monitor.h"
29 #include "monitor/qdev.h"
30 #include "qapi/error.h"
31 #include "qapi/opts-visitor.h"
32 #include "qapi/qmp/qdict.h"
33 #include "qapi/qmp/qerror.h"
34 #include "qapi/string-input-visitor.h"
35 #include "qapi/string-output-visitor.h"
36 #include "qapi-visit.h"
37 #include "qom/object_interfaces.h"
38 #include "ui/console.h"
39 #include "block/nbd.h"
40 #include "block/qapi.h"
41 #include "qemu-io.h"
42 #include "qemu/cutils.h"
43 #include "qemu/error-report.h"
44 #include "exec/ramlist.h"
45 #include "hw/intc/intc.h"
46 #include "migration/snapshot.h"
47 #include "migration/misc.h"
49 #ifdef CONFIG_SPICE
50 #include <spice/enums.h>
51 #endif
53 static void hmp_handle_error(Monitor *mon, Error **errp)
55 assert(errp);
56 if (*errp) {
57 error_report_err(*errp);
61 void hmp_info_name(Monitor *mon, const QDict *qdict)
63 NameInfo *info;
65 info = qmp_query_name(NULL);
66 if (info->has_name) {
67 monitor_printf(mon, "%s\n", info->name);
69 qapi_free_NameInfo(info);
72 void hmp_info_version(Monitor *mon, const QDict *qdict)
74 VersionInfo *info;
76 info = qmp_query_version(NULL);
78 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
79 info->qemu->major, info->qemu->minor, info->qemu->micro,
80 info->package);
82 qapi_free_VersionInfo(info);
85 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
87 KvmInfo *info;
89 info = qmp_query_kvm(NULL);
90 monitor_printf(mon, "kvm support: ");
91 if (info->present) {
92 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
93 } else {
94 monitor_printf(mon, "not compiled\n");
97 qapi_free_KvmInfo(info);
100 void hmp_info_status(Monitor *mon, const QDict *qdict)
102 StatusInfo *info;
104 info = qmp_query_status(NULL);
106 monitor_printf(mon, "VM status: %s%s",
107 info->running ? "running" : "paused",
108 info->singlestep ? " (single step mode)" : "");
110 if (!info->running && info->status != RUN_STATE_PAUSED) {
111 monitor_printf(mon, " (%s)", RunState_str(info->status));
114 monitor_printf(mon, "\n");
116 qapi_free_StatusInfo(info);
119 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
121 UuidInfo *info;
123 info = qmp_query_uuid(NULL);
124 monitor_printf(mon, "%s\n", info->UUID);
125 qapi_free_UuidInfo(info);
128 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
130 ChardevInfoList *char_info, *info;
132 char_info = qmp_query_chardev(NULL);
133 for (info = char_info; info; info = info->next) {
134 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
135 info->value->filename);
138 qapi_free_ChardevInfoList(char_info);
141 void hmp_info_mice(Monitor *mon, const QDict *qdict)
143 MouseInfoList *mice_list, *mouse;
145 mice_list = qmp_query_mice(NULL);
146 if (!mice_list) {
147 monitor_printf(mon, "No mouse devices connected\n");
148 return;
151 for (mouse = mice_list; mouse; mouse = mouse->next) {
152 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
153 mouse->value->current ? '*' : ' ',
154 mouse->value->index, mouse->value->name,
155 mouse->value->absolute ? " (absolute)" : "");
158 qapi_free_MouseInfoList(mice_list);
161 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
163 MigrationInfo *info;
164 MigrationCapabilityStatusList *caps, *cap;
166 info = qmp_query_migrate(NULL);
167 caps = qmp_query_migrate_capabilities(NULL);
169 migration_global_dump(mon);
171 /* do not display parameters during setup */
172 if (info->has_status && caps) {
173 monitor_printf(mon, "capabilities: ");
174 for (cap = caps; cap; cap = cap->next) {
175 monitor_printf(mon, "%s: %s ",
176 MigrationCapability_str(cap->value->capability),
177 cap->value->state ? "on" : "off");
179 monitor_printf(mon, "\n");
182 if (info->has_status) {
183 monitor_printf(mon, "Migration status: %s",
184 MigrationStatus_str(info->status));
185 if (info->status == MIGRATION_STATUS_FAILED &&
186 info->has_error_desc) {
187 monitor_printf(mon, " (%s)\n", info->error_desc);
188 } else {
189 monitor_printf(mon, "\n");
192 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
193 info->total_time);
194 if (info->has_expected_downtime) {
195 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
196 info->expected_downtime);
198 if (info->has_downtime) {
199 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
200 info->downtime);
202 if (info->has_setup_time) {
203 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
204 info->setup_time);
208 if (info->has_ram) {
209 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
210 info->ram->transferred >> 10);
211 monitor_printf(mon, "throughput: %0.2f mbps\n",
212 info->ram->mbps);
213 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
214 info->ram->remaining >> 10);
215 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
216 info->ram->total >> 10);
217 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
218 info->ram->duplicate);
219 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
220 info->ram->skipped);
221 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
222 info->ram->normal);
223 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
224 info->ram->normal_bytes >> 10);
225 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
226 info->ram->dirty_sync_count);
227 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
228 info->ram->page_size >> 10);
230 if (info->ram->dirty_pages_rate) {
231 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
232 info->ram->dirty_pages_rate);
234 if (info->ram->postcopy_requests) {
235 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
236 info->ram->postcopy_requests);
240 if (info->has_disk) {
241 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
242 info->disk->transferred >> 10);
243 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
244 info->disk->remaining >> 10);
245 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
246 info->disk->total >> 10);
249 if (info->has_xbzrle_cache) {
250 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
251 info->xbzrle_cache->cache_size);
252 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
253 info->xbzrle_cache->bytes >> 10);
254 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
255 info->xbzrle_cache->pages);
256 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
257 info->xbzrle_cache->cache_miss);
258 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
259 info->xbzrle_cache->cache_miss_rate);
260 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
261 info->xbzrle_cache->overflow);
264 if (info->has_cpu_throttle_percentage) {
265 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
266 info->cpu_throttle_percentage);
269 qapi_free_MigrationInfo(info);
270 qapi_free_MigrationCapabilityStatusList(caps);
273 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
275 MigrationCapabilityStatusList *caps, *cap;
277 caps = qmp_query_migrate_capabilities(NULL);
279 if (caps) {
280 for (cap = caps; cap; cap = cap->next) {
281 monitor_printf(mon, "%s: %s\n",
282 MigrationCapability_str(cap->value->capability),
283 cap->value->state ? "on" : "off");
287 qapi_free_MigrationCapabilityStatusList(caps);
290 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
292 MigrationParameters *params;
294 params = qmp_query_migrate_parameters(NULL);
296 if (params) {
297 assert(params->has_compress_level);
298 monitor_printf(mon, "%s: %u\n",
299 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
300 params->compress_level);
301 assert(params->has_compress_threads);
302 monitor_printf(mon, "%s: %u\n",
303 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
304 params->compress_threads);
305 assert(params->has_decompress_threads);
306 monitor_printf(mon, "%s: %u\n",
307 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
308 params->decompress_threads);
309 assert(params->has_cpu_throttle_initial);
310 monitor_printf(mon, "%s: %u\n",
311 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
312 params->cpu_throttle_initial);
313 assert(params->has_cpu_throttle_increment);
314 monitor_printf(mon, "%s: %u\n",
315 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
316 params->cpu_throttle_increment);
317 assert(params->has_tls_creds);
318 monitor_printf(mon, "%s: '%s'\n",
319 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
320 params->tls_creds);
321 assert(params->has_tls_hostname);
322 monitor_printf(mon, "%s: '%s'\n",
323 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
324 params->tls_hostname);
325 assert(params->has_max_bandwidth);
326 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
327 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
328 params->max_bandwidth);
329 assert(params->has_downtime_limit);
330 monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n",
331 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
332 params->downtime_limit);
333 assert(params->has_x_checkpoint_delay);
334 monitor_printf(mon, "%s: %u\n",
335 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
336 params->x_checkpoint_delay);
337 assert(params->has_block_incremental);
338 monitor_printf(mon, "%s: %s\n",
339 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
340 params->block_incremental ? "on" : "off");
341 monitor_printf(mon, "%s: %u\n",
342 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_CHANNELS),
343 params->x_multifd_channels);
344 monitor_printf(mon, "%s: %u\n",
345 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT),
346 params->x_multifd_page_count);
347 monitor_printf(mon, "%s: %" PRIu64 "\n",
348 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
349 params->xbzrle_cache_size);
352 qapi_free_MigrationParameters(params);
355 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
357 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
358 qmp_query_migrate_cache_size(NULL) >> 10);
361 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
363 CpuInfoList *cpu_list, *cpu;
365 cpu_list = qmp_query_cpus(NULL);
367 for (cpu = cpu_list; cpu; cpu = cpu->next) {
368 int active = ' ';
370 if (cpu->value->CPU == monitor_get_cpu_index()) {
371 active = '*';
374 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
376 switch (cpu->value->arch) {
377 case CPU_INFO_ARCH_X86:
378 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->u.x86.pc);
379 break;
380 case CPU_INFO_ARCH_PPC:
381 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->u.ppc.nip);
382 break;
383 case CPU_INFO_ARCH_SPARC:
384 monitor_printf(mon, " pc=0x%016" PRIx64,
385 cpu->value->u.q_sparc.pc);
386 monitor_printf(mon, " npc=0x%016" PRIx64,
387 cpu->value->u.q_sparc.npc);
388 break;
389 case CPU_INFO_ARCH_MIPS:
390 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.q_mips.PC);
391 break;
392 case CPU_INFO_ARCH_TRICORE:
393 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.tricore.PC);
394 break;
395 default:
396 break;
399 if (cpu->value->halted) {
400 monitor_printf(mon, " (halted)");
403 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
406 qapi_free_CpuInfoList(cpu_list);
409 static void print_block_info(Monitor *mon, BlockInfo *info,
410 BlockDeviceInfo *inserted, bool verbose)
412 ImageInfo *image_info;
414 assert(!info || !info->has_inserted || info->inserted == inserted);
416 if (info && *info->device) {
417 monitor_printf(mon, "%s", info->device);
418 if (inserted && inserted->has_node_name) {
419 monitor_printf(mon, " (%s)", inserted->node_name);
421 } else {
422 assert(info || inserted);
423 monitor_printf(mon, "%s",
424 inserted && inserted->has_node_name ? inserted->node_name
425 : info && info->has_qdev ? info->qdev
426 : "<anonymous>");
429 if (inserted) {
430 monitor_printf(mon, ": %s (%s%s%s)\n",
431 inserted->file,
432 inserted->drv,
433 inserted->ro ? ", read-only" : "",
434 inserted->encrypted ? ", encrypted" : "");
435 } else {
436 monitor_printf(mon, ": [not inserted]\n");
439 if (info) {
440 if (info->has_qdev) {
441 monitor_printf(mon, " Attached to: %s\n", info->qdev);
443 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
444 monitor_printf(mon, " I/O status: %s\n",
445 BlockDeviceIoStatus_str(info->io_status));
448 if (info->removable) {
449 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
450 info->locked ? "" : "not ",
451 info->tray_open ? "open" : "closed");
456 if (!inserted) {
457 return;
460 monitor_printf(mon, " Cache mode: %s%s%s\n",
461 inserted->cache->writeback ? "writeback" : "writethrough",
462 inserted->cache->direct ? ", direct" : "",
463 inserted->cache->no_flush ? ", ignore flushes" : "");
465 if (inserted->has_backing_file) {
466 monitor_printf(mon,
467 " Backing file: %s "
468 "(chain depth: %" PRId64 ")\n",
469 inserted->backing_file,
470 inserted->backing_file_depth);
473 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
474 monitor_printf(mon, " Detect zeroes: %s\n",
475 BlockdevDetectZeroesOptions_str(inserted->detect_zeroes));
478 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
479 inserted->iops || inserted->iops_rd || inserted->iops_wr)
481 monitor_printf(mon, " I/O throttling: bps=%" PRId64
482 " bps_rd=%" PRId64 " bps_wr=%" PRId64
483 " bps_max=%" PRId64
484 " bps_rd_max=%" PRId64
485 " bps_wr_max=%" PRId64
486 " iops=%" PRId64 " iops_rd=%" PRId64
487 " iops_wr=%" PRId64
488 " iops_max=%" PRId64
489 " iops_rd_max=%" PRId64
490 " iops_wr_max=%" PRId64
491 " iops_size=%" PRId64
492 " group=%s\n",
493 inserted->bps,
494 inserted->bps_rd,
495 inserted->bps_wr,
496 inserted->bps_max,
497 inserted->bps_rd_max,
498 inserted->bps_wr_max,
499 inserted->iops,
500 inserted->iops_rd,
501 inserted->iops_wr,
502 inserted->iops_max,
503 inserted->iops_rd_max,
504 inserted->iops_wr_max,
505 inserted->iops_size,
506 inserted->group);
509 if (verbose) {
510 monitor_printf(mon, "\nImages:\n");
511 image_info = inserted->image;
512 while (1) {
513 bdrv_image_info_dump((fprintf_function)monitor_printf,
514 mon, image_info);
515 if (image_info->has_backing_image) {
516 image_info = image_info->backing_image;
517 } else {
518 break;
524 void hmp_info_block(Monitor *mon, const QDict *qdict)
526 BlockInfoList *block_list, *info;
527 BlockDeviceInfoList *blockdev_list, *blockdev;
528 const char *device = qdict_get_try_str(qdict, "device");
529 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
530 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
531 bool printed = false;
533 /* Print BlockBackend information */
534 if (!nodes) {
535 block_list = qmp_query_block(NULL);
536 } else {
537 block_list = NULL;
540 for (info = block_list; info; info = info->next) {
541 if (device && strcmp(device, info->value->device)) {
542 continue;
545 if (info != block_list) {
546 monitor_printf(mon, "\n");
549 print_block_info(mon, info->value, info->value->has_inserted
550 ? info->value->inserted : NULL,
551 verbose);
552 printed = true;
555 qapi_free_BlockInfoList(block_list);
557 if ((!device && !nodes) || printed) {
558 return;
561 /* Print node information */
562 blockdev_list = qmp_query_named_block_nodes(NULL);
563 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
564 assert(blockdev->value->has_node_name);
565 if (device && strcmp(device, blockdev->value->node_name)) {
566 continue;
569 if (blockdev != blockdev_list) {
570 monitor_printf(mon, "\n");
573 print_block_info(mon, NULL, blockdev->value, verbose);
575 qapi_free_BlockDeviceInfoList(blockdev_list);
578 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
580 BlockStatsList *stats_list, *stats;
582 stats_list = qmp_query_blockstats(false, false, NULL);
584 for (stats = stats_list; stats; stats = stats->next) {
585 if (!stats->value->has_device) {
586 continue;
589 monitor_printf(mon, "%s:", stats->value->device);
590 monitor_printf(mon, " rd_bytes=%" PRId64
591 " wr_bytes=%" PRId64
592 " rd_operations=%" PRId64
593 " wr_operations=%" PRId64
594 " flush_operations=%" PRId64
595 " wr_total_time_ns=%" PRId64
596 " rd_total_time_ns=%" PRId64
597 " flush_total_time_ns=%" PRId64
598 " rd_merged=%" PRId64
599 " wr_merged=%" PRId64
600 " idle_time_ns=%" PRId64
601 "\n",
602 stats->value->stats->rd_bytes,
603 stats->value->stats->wr_bytes,
604 stats->value->stats->rd_operations,
605 stats->value->stats->wr_operations,
606 stats->value->stats->flush_operations,
607 stats->value->stats->wr_total_time_ns,
608 stats->value->stats->rd_total_time_ns,
609 stats->value->stats->flush_total_time_ns,
610 stats->value->stats->rd_merged,
611 stats->value->stats->wr_merged,
612 stats->value->stats->idle_time_ns);
615 qapi_free_BlockStatsList(stats_list);
618 /* Helper for hmp_info_vnc_clients, _servers */
619 static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
620 const char *name)
622 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
623 name,
624 info->host,
625 info->service,
626 NetworkAddressFamily_str(info->family),
627 info->websocket ? " (Websocket)" : "");
630 /* Helper displaying and auth and crypt info */
631 static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
632 VncPrimaryAuth auth,
633 VncVencryptSubAuth *vencrypt)
635 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
636 VncPrimaryAuth_str(auth),
637 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
640 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
642 while (client) {
643 VncClientInfo *cinfo = client->value;
645 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
646 monitor_printf(mon, " x509_dname: %s\n",
647 cinfo->has_x509_dname ?
648 cinfo->x509_dname : "none");
649 monitor_printf(mon, " sasl_username: %s\n",
650 cinfo->has_sasl_username ?
651 cinfo->sasl_username : "none");
653 client = client->next;
657 static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
659 while (server) {
660 VncServerInfo2 *sinfo = server->value;
661 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
662 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
663 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
664 server = server->next;
668 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
670 VncInfo2List *info2l;
671 Error *err = NULL;
673 info2l = qmp_query_vnc_servers(&err);
674 if (err) {
675 hmp_handle_error(mon, &err);
676 return;
678 if (!info2l) {
679 monitor_printf(mon, "None\n");
680 return;
683 while (info2l) {
684 VncInfo2 *info = info2l->value;
685 monitor_printf(mon, "%s:\n", info->id);
686 hmp_info_vnc_servers(mon, info->server);
687 hmp_info_vnc_clients(mon, info->clients);
688 if (!info->server) {
689 /* The server entry displays its auth, we only
690 * need to display in the case of 'reverse' connections
691 * where there's no server.
693 hmp_info_vnc_authcrypt(mon, " ", info->auth,
694 info->has_vencrypt ? &info->vencrypt : NULL);
696 if (info->has_display) {
697 monitor_printf(mon, " Display: %s\n", info->display);
699 info2l = info2l->next;
702 qapi_free_VncInfo2List(info2l);
706 #ifdef CONFIG_SPICE
707 void hmp_info_spice(Monitor *mon, const QDict *qdict)
709 SpiceChannelList *chan;
710 SpiceInfo *info;
711 const char *channel_name;
712 const char * const channel_names[] = {
713 [SPICE_CHANNEL_MAIN] = "main",
714 [SPICE_CHANNEL_DISPLAY] = "display",
715 [SPICE_CHANNEL_INPUTS] = "inputs",
716 [SPICE_CHANNEL_CURSOR] = "cursor",
717 [SPICE_CHANNEL_PLAYBACK] = "playback",
718 [SPICE_CHANNEL_RECORD] = "record",
719 [SPICE_CHANNEL_TUNNEL] = "tunnel",
720 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
721 [SPICE_CHANNEL_USBREDIR] = "usbredir",
722 [SPICE_CHANNEL_PORT] = "port",
723 #if 0
724 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
725 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
726 * as quick fix for build failures with older versions. */
727 [SPICE_CHANNEL_WEBDAV] = "webdav",
728 #endif
731 info = qmp_query_spice(NULL);
733 if (!info->enabled) {
734 monitor_printf(mon, "Server: disabled\n");
735 goto out;
738 monitor_printf(mon, "Server:\n");
739 if (info->has_port) {
740 monitor_printf(mon, " address: %s:%" PRId64 "\n",
741 info->host, info->port);
743 if (info->has_tls_port) {
744 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
745 info->host, info->tls_port);
747 monitor_printf(mon, " migrated: %s\n",
748 info->migrated ? "true" : "false");
749 monitor_printf(mon, " auth: %s\n", info->auth);
750 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
751 monitor_printf(mon, " mouse-mode: %s\n",
752 SpiceQueryMouseMode_str(info->mouse_mode));
754 if (!info->has_channels || info->channels == NULL) {
755 monitor_printf(mon, "Channels: none\n");
756 } else {
757 for (chan = info->channels; chan; chan = chan->next) {
758 monitor_printf(mon, "Channel:\n");
759 monitor_printf(mon, " address: %s:%s%s\n",
760 chan->value->host, chan->value->port,
761 chan->value->tls ? " [tls]" : "");
762 monitor_printf(mon, " session: %" PRId64 "\n",
763 chan->value->connection_id);
764 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
765 chan->value->channel_type, chan->value->channel_id);
767 channel_name = "unknown";
768 if (chan->value->channel_type > 0 &&
769 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
770 channel_names[chan->value->channel_type]) {
771 channel_name = channel_names[chan->value->channel_type];
774 monitor_printf(mon, " channel name: %s\n", channel_name);
778 out:
779 qapi_free_SpiceInfo(info);
781 #endif
783 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
785 BalloonInfo *info;
786 Error *err = NULL;
788 info = qmp_query_balloon(&err);
789 if (err) {
790 hmp_handle_error(mon, &err);
791 return;
794 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
796 qapi_free_BalloonInfo(info);
799 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
801 PciMemoryRegionList *region;
803 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
804 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
805 dev->slot, dev->function);
806 monitor_printf(mon, " ");
808 if (dev->class_info->has_desc) {
809 monitor_printf(mon, "%s", dev->class_info->desc);
810 } else {
811 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
814 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
815 dev->id->vendor, dev->id->device);
817 if (dev->has_irq) {
818 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
821 if (dev->has_pci_bridge) {
822 monitor_printf(mon, " BUS %" PRId64 ".\n",
823 dev->pci_bridge->bus->number);
824 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
825 dev->pci_bridge->bus->secondary);
826 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
827 dev->pci_bridge->bus->subordinate);
829 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
830 dev->pci_bridge->bus->io_range->base,
831 dev->pci_bridge->bus->io_range->limit);
833 monitor_printf(mon,
834 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
835 dev->pci_bridge->bus->memory_range->base,
836 dev->pci_bridge->bus->memory_range->limit);
838 monitor_printf(mon, " prefetchable memory range "
839 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
840 dev->pci_bridge->bus->prefetchable_range->base,
841 dev->pci_bridge->bus->prefetchable_range->limit);
844 for (region = dev->regions; region; region = region->next) {
845 uint64_t addr, size;
847 addr = region->value->address;
848 size = region->value->size;
850 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
852 if (!strcmp(region->value->type, "io")) {
853 monitor_printf(mon, "I/O at 0x%04" PRIx64
854 " [0x%04" PRIx64 "].\n",
855 addr, addr + size - 1);
856 } else {
857 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
858 " [0x%08" PRIx64 "].\n",
859 region->value->mem_type_64 ? 64 : 32,
860 region->value->prefetch ? " prefetchable" : "",
861 addr, addr + size - 1);
865 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
867 if (dev->has_pci_bridge) {
868 if (dev->pci_bridge->has_devices) {
869 PciDeviceInfoList *cdev;
870 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
871 hmp_info_pci_device(mon, cdev->value);
877 static int hmp_info_irq_foreach(Object *obj, void *opaque)
879 InterruptStatsProvider *intc;
880 InterruptStatsProviderClass *k;
881 Monitor *mon = opaque;
883 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
884 intc = INTERRUPT_STATS_PROVIDER(obj);
885 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
886 uint64_t *irq_counts;
887 unsigned int nb_irqs, i;
888 if (k->get_statistics &&
889 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
890 if (nb_irqs > 0) {
891 monitor_printf(mon, "IRQ statistics for %s:\n",
892 object_get_typename(obj));
893 for (i = 0; i < nb_irqs; i++) {
894 if (irq_counts[i] > 0) {
895 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
896 irq_counts[i]);
900 } else {
901 monitor_printf(mon, "IRQ statistics not available for %s.\n",
902 object_get_typename(obj));
906 return 0;
909 void hmp_info_irq(Monitor *mon, const QDict *qdict)
911 object_child_foreach_recursive(object_get_root(),
912 hmp_info_irq_foreach, mon);
915 static int hmp_info_pic_foreach(Object *obj, void *opaque)
917 InterruptStatsProvider *intc;
918 InterruptStatsProviderClass *k;
919 Monitor *mon = opaque;
921 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
922 intc = INTERRUPT_STATS_PROVIDER(obj);
923 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
924 if (k->print_info) {
925 k->print_info(intc, mon);
926 } else {
927 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
928 object_get_typename(obj));
932 return 0;
935 void hmp_info_pic(Monitor *mon, const QDict *qdict)
937 object_child_foreach_recursive(object_get_root(),
938 hmp_info_pic_foreach, mon);
941 void hmp_info_pci(Monitor *mon, const QDict *qdict)
943 PciInfoList *info_list, *info;
944 Error *err = NULL;
946 info_list = qmp_query_pci(&err);
947 if (err) {
948 monitor_printf(mon, "PCI devices not supported\n");
949 error_free(err);
950 return;
953 for (info = info_list; info; info = info->next) {
954 PciDeviceInfoList *dev;
956 for (dev = info->value->devices; dev; dev = dev->next) {
957 hmp_info_pci_device(mon, dev->value);
961 qapi_free_PciInfoList(info_list);
964 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
966 BlockJobInfoList *list;
967 Error *err = NULL;
969 list = qmp_query_block_jobs(&err);
970 assert(!err);
972 if (!list) {
973 monitor_printf(mon, "No active jobs\n");
974 return;
977 while (list) {
978 if (strcmp(list->value->type, "stream") == 0) {
979 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
980 " of %" PRId64 " bytes, speed limit %" PRId64
981 " bytes/s\n",
982 list->value->device,
983 list->value->offset,
984 list->value->len,
985 list->value->speed);
986 } else {
987 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
988 " of %" PRId64 " bytes, speed limit %" PRId64
989 " bytes/s\n",
990 list->value->type,
991 list->value->device,
992 list->value->offset,
993 list->value->len,
994 list->value->speed);
996 list = list->next;
999 qapi_free_BlockJobInfoList(list);
1002 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
1004 TPMInfoList *info_list, *info;
1005 Error *err = NULL;
1006 unsigned int c = 0;
1007 TPMPassthroughOptions *tpo;
1008 TPMEmulatorOptions *teo;
1010 info_list = qmp_query_tpm(&err);
1011 if (err) {
1012 monitor_printf(mon, "TPM device not supported\n");
1013 error_free(err);
1014 return;
1017 if (info_list) {
1018 monitor_printf(mon, "TPM device:\n");
1021 for (info = info_list; info; info = info->next) {
1022 TPMInfo *ti = info->value;
1023 monitor_printf(mon, " tpm%d: model=%s\n",
1024 c, TpmModel_str(ti->model));
1026 monitor_printf(mon, " \\ %s: type=%s",
1027 ti->id, TpmTypeOptionsKind_str(ti->options->type));
1029 switch (ti->options->type) {
1030 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
1031 tpo = ti->options->u.passthrough.data;
1032 monitor_printf(mon, "%s%s%s%s",
1033 tpo->has_path ? ",path=" : "",
1034 tpo->has_path ? tpo->path : "",
1035 tpo->has_cancel_path ? ",cancel-path=" : "",
1036 tpo->has_cancel_path ? tpo->cancel_path : "");
1037 break;
1038 case TPM_TYPE_OPTIONS_KIND_EMULATOR:
1039 teo = ti->options->u.emulator.data;
1040 monitor_printf(mon, ",chardev=%s", teo->chardev);
1041 break;
1042 case TPM_TYPE_OPTIONS_KIND__MAX:
1043 break;
1045 monitor_printf(mon, "\n");
1046 c++;
1048 qapi_free_TPMInfoList(info_list);
1051 void hmp_quit(Monitor *mon, const QDict *qdict)
1053 monitor_suspend(mon);
1054 qmp_quit(NULL);
1057 void hmp_stop(Monitor *mon, const QDict *qdict)
1059 qmp_stop(NULL);
1062 void hmp_system_reset(Monitor *mon, const QDict *qdict)
1064 qmp_system_reset(NULL);
1067 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
1069 qmp_system_powerdown(NULL);
1072 void hmp_cpu(Monitor *mon, const QDict *qdict)
1074 int64_t cpu_index;
1076 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1077 use it are converted to the QAPI */
1078 cpu_index = qdict_get_int(qdict, "index");
1079 if (monitor_set_cpu(cpu_index) < 0) {
1080 monitor_printf(mon, "invalid CPU index\n");
1084 void hmp_memsave(Monitor *mon, const QDict *qdict)
1086 uint32_t size = qdict_get_int(qdict, "size");
1087 const char *filename = qdict_get_str(qdict, "filename");
1088 uint64_t addr = qdict_get_int(qdict, "val");
1089 Error *err = NULL;
1090 int cpu_index = monitor_get_cpu_index();
1092 if (cpu_index < 0) {
1093 monitor_printf(mon, "No CPU available\n");
1094 return;
1097 qmp_memsave(addr, size, filename, true, cpu_index, &err);
1098 hmp_handle_error(mon, &err);
1101 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1103 uint32_t size = qdict_get_int(qdict, "size");
1104 const char *filename = qdict_get_str(qdict, "filename");
1105 uint64_t addr = qdict_get_int(qdict, "val");
1106 Error *err = NULL;
1108 qmp_pmemsave(addr, size, filename, &err);
1109 hmp_handle_error(mon, &err);
1112 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1114 const char *chardev = qdict_get_str(qdict, "device");
1115 const char *data = qdict_get_str(qdict, "data");
1116 Error *err = NULL;
1118 qmp_ringbuf_write(chardev, data, false, 0, &err);
1120 hmp_handle_error(mon, &err);
1123 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
1125 uint32_t size = qdict_get_int(qdict, "size");
1126 const char *chardev = qdict_get_str(qdict, "device");
1127 char *data;
1128 Error *err = NULL;
1129 int i;
1131 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1132 if (err) {
1133 hmp_handle_error(mon, &err);
1134 return;
1137 for (i = 0; data[i]; i++) {
1138 unsigned char ch = data[i];
1140 if (ch == '\\') {
1141 monitor_printf(mon, "\\\\");
1142 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1143 monitor_printf(mon, "\\u%04X", ch);
1144 } else {
1145 monitor_printf(mon, "%c", ch);
1149 monitor_printf(mon, "\n");
1150 g_free(data);
1153 void hmp_cont(Monitor *mon, const QDict *qdict)
1155 Error *err = NULL;
1157 qmp_cont(&err);
1158 hmp_handle_error(mon, &err);
1161 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1163 qmp_system_wakeup(NULL);
1166 void hmp_nmi(Monitor *mon, const QDict *qdict)
1168 Error *err = NULL;
1170 qmp_inject_nmi(&err);
1171 hmp_handle_error(mon, &err);
1174 void hmp_set_link(Monitor *mon, const QDict *qdict)
1176 const char *name = qdict_get_str(qdict, "name");
1177 bool up = qdict_get_bool(qdict, "up");
1178 Error *err = NULL;
1180 qmp_set_link(name, up, &err);
1181 hmp_handle_error(mon, &err);
1184 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1186 const char *device = qdict_get_str(qdict, "device");
1187 const char *password = qdict_get_str(qdict, "password");
1188 Error *err = NULL;
1190 qmp_block_passwd(true, device, false, NULL, password, &err);
1191 hmp_handle_error(mon, &err);
1194 void hmp_balloon(Monitor *mon, const QDict *qdict)
1196 int64_t value = qdict_get_int(qdict, "value");
1197 Error *err = NULL;
1199 qmp_balloon(value, &err);
1200 hmp_handle_error(mon, &err);
1203 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1205 const char *device = qdict_get_str(qdict, "device");
1206 int64_t size = qdict_get_int(qdict, "size");
1207 Error *err = NULL;
1209 qmp_block_resize(true, device, false, NULL, size, &err);
1210 hmp_handle_error(mon, &err);
1213 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1215 const char *filename = qdict_get_str(qdict, "target");
1216 const char *format = qdict_get_try_str(qdict, "format");
1217 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1218 bool full = qdict_get_try_bool(qdict, "full", false);
1219 Error *err = NULL;
1220 DriveMirror mirror = {
1221 .device = (char *)qdict_get_str(qdict, "device"),
1222 .target = (char *)filename,
1223 .has_format = !!format,
1224 .format = (char *)format,
1225 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1226 .has_mode = true,
1227 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1228 .unmap = true,
1231 if (!filename) {
1232 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1233 hmp_handle_error(mon, &err);
1234 return;
1236 qmp_drive_mirror(&mirror, &err);
1237 hmp_handle_error(mon, &err);
1240 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1242 const char *device = qdict_get_str(qdict, "device");
1243 const char *filename = qdict_get_str(qdict, "target");
1244 const char *format = qdict_get_try_str(qdict, "format");
1245 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1246 bool full = qdict_get_try_bool(qdict, "full", false);
1247 bool compress = qdict_get_try_bool(qdict, "compress", false);
1248 Error *err = NULL;
1249 DriveBackup backup = {
1250 .device = (char *)device,
1251 .target = (char *)filename,
1252 .has_format = !!format,
1253 .format = (char *)format,
1254 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1255 .has_mode = true,
1256 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1257 .has_compress = !!compress,
1258 .compress = compress,
1261 if (!filename) {
1262 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1263 hmp_handle_error(mon, &err);
1264 return;
1267 qmp_drive_backup(&backup, &err);
1268 hmp_handle_error(mon, &err);
1271 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1273 const char *device = qdict_get_str(qdict, "device");
1274 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1275 const char *format = qdict_get_try_str(qdict, "format");
1276 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1277 enum NewImageMode mode;
1278 Error *err = NULL;
1280 if (!filename) {
1281 /* In the future, if 'snapshot-file' is not specified, the snapshot
1282 will be taken internally. Today it's actually required. */
1283 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1284 hmp_handle_error(mon, &err);
1285 return;
1288 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1289 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1290 filename, false, NULL,
1291 !!format, format,
1292 true, mode, &err);
1293 hmp_handle_error(mon, &err);
1296 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1298 const char *device = qdict_get_str(qdict, "device");
1299 const char *name = qdict_get_str(qdict, "name");
1300 Error *err = NULL;
1302 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1303 hmp_handle_error(mon, &err);
1306 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1308 const char *device = qdict_get_str(qdict, "device");
1309 const char *name = qdict_get_str(qdict, "name");
1310 const char *id = qdict_get_try_str(qdict, "id");
1311 Error *err = NULL;
1313 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1314 true, name, &err);
1315 hmp_handle_error(mon, &err);
1318 void hmp_loadvm(Monitor *mon, const QDict *qdict)
1320 int saved_vm_running = runstate_is_running();
1321 const char *name = qdict_get_str(qdict, "name");
1322 Error *err = NULL;
1324 vm_stop(RUN_STATE_RESTORE_VM);
1326 if (load_snapshot(name, &err) == 0 && saved_vm_running) {
1327 vm_start();
1329 hmp_handle_error(mon, &err);
1332 void hmp_savevm(Monitor *mon, const QDict *qdict)
1334 Error *err = NULL;
1336 save_snapshot(qdict_get_try_str(qdict, "name"), &err);
1337 hmp_handle_error(mon, &err);
1340 void hmp_delvm(Monitor *mon, const QDict *qdict)
1342 BlockDriverState *bs;
1343 Error *err;
1344 const char *name = qdict_get_str(qdict, "name");
1346 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
1347 error_reportf_err(err,
1348 "Error while deleting snapshot on device '%s': ",
1349 bdrv_get_device_name(bs));
1353 void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
1355 BlockDriverState *bs, *bs1;
1356 BdrvNextIterator it1;
1357 QEMUSnapshotInfo *sn_tab, *sn;
1358 bool no_snapshot = true;
1359 int nb_sns, i;
1360 int total;
1361 int *global_snapshots;
1362 AioContext *aio_context;
1364 typedef struct SnapshotEntry {
1365 QEMUSnapshotInfo sn;
1366 QTAILQ_ENTRY(SnapshotEntry) next;
1367 } SnapshotEntry;
1369 typedef struct ImageEntry {
1370 const char *imagename;
1371 QTAILQ_ENTRY(ImageEntry) next;
1372 QTAILQ_HEAD(, SnapshotEntry) snapshots;
1373 } ImageEntry;
1375 QTAILQ_HEAD(, ImageEntry) image_list =
1376 QTAILQ_HEAD_INITIALIZER(image_list);
1378 ImageEntry *image_entry, *next_ie;
1379 SnapshotEntry *snapshot_entry;
1381 bs = bdrv_all_find_vmstate_bs();
1382 if (!bs) {
1383 monitor_printf(mon, "No available block device supports snapshots\n");
1384 return;
1386 aio_context = bdrv_get_aio_context(bs);
1388 aio_context_acquire(aio_context);
1389 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
1390 aio_context_release(aio_context);
1392 if (nb_sns < 0) {
1393 monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
1394 return;
1397 for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) {
1398 int bs1_nb_sns = 0;
1399 ImageEntry *ie;
1400 SnapshotEntry *se;
1401 AioContext *ctx = bdrv_get_aio_context(bs1);
1403 aio_context_acquire(ctx);
1404 if (bdrv_can_snapshot(bs1)) {
1405 sn = NULL;
1406 bs1_nb_sns = bdrv_snapshot_list(bs1, &sn);
1407 if (bs1_nb_sns > 0) {
1408 no_snapshot = false;
1409 ie = g_new0(ImageEntry, 1);
1410 ie->imagename = bdrv_get_device_name(bs1);
1411 QTAILQ_INIT(&ie->snapshots);
1412 QTAILQ_INSERT_TAIL(&image_list, ie, next);
1413 for (i = 0; i < bs1_nb_sns; i++) {
1414 se = g_new0(SnapshotEntry, 1);
1415 se->sn = sn[i];
1416 QTAILQ_INSERT_TAIL(&ie->snapshots, se, next);
1419 g_free(sn);
1421 aio_context_release(ctx);
1424 if (no_snapshot) {
1425 monitor_printf(mon, "There is no snapshot available.\n");
1426 return;
1429 global_snapshots = g_new0(int, nb_sns);
1430 total = 0;
1431 for (i = 0; i < nb_sns; i++) {
1432 SnapshotEntry *next_sn;
1433 if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) {
1434 global_snapshots[total] = i;
1435 total++;
1436 QTAILQ_FOREACH(image_entry, &image_list, next) {
1437 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots,
1438 next, next_sn) {
1439 if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) {
1440 QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry,
1441 next);
1442 g_free(snapshot_entry);
1449 monitor_printf(mon, "List of snapshots present on all disks:\n");
1451 if (total > 0) {
1452 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1453 monitor_printf(mon, "\n");
1454 for (i = 0; i < total; i++) {
1455 sn = &sn_tab[global_snapshots[i]];
1456 /* The ID is not guaranteed to be the same on all images, so
1457 * overwrite it.
1459 pstrcpy(sn->id_str, sizeof(sn->id_str), "--");
1460 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, sn);
1461 monitor_printf(mon, "\n");
1463 } else {
1464 monitor_printf(mon, "None\n");
1467 QTAILQ_FOREACH(image_entry, &image_list, next) {
1468 if (QTAILQ_EMPTY(&image_entry->snapshots)) {
1469 continue;
1471 monitor_printf(mon,
1472 "\nList of partial (non-loadable) snapshots on '%s':\n",
1473 image_entry->imagename);
1474 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1475 monitor_printf(mon, "\n");
1476 QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) {
1477 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon,
1478 &snapshot_entry->sn);
1479 monitor_printf(mon, "\n");
1483 QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) {
1484 SnapshotEntry *next_sn;
1485 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next,
1486 next_sn) {
1487 g_free(snapshot_entry);
1489 g_free(image_entry);
1491 g_free(sn_tab);
1492 g_free(global_snapshots);
1496 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1498 qmp_migrate_cancel(NULL);
1501 void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1503 Error *err = NULL;
1504 const char *state = qdict_get_str(qdict, "state");
1505 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1507 if (val >= 0) {
1508 qmp_migrate_continue(val, &err);
1511 hmp_handle_error(mon, &err);
1514 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1516 Error *err = NULL;
1517 const char *uri = qdict_get_str(qdict, "uri");
1519 qmp_migrate_incoming(uri, &err);
1521 hmp_handle_error(mon, &err);
1524 /* Kept for backwards compatibility */
1525 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1527 double value = qdict_get_double(qdict, "value");
1528 qmp_migrate_set_downtime(value, NULL);
1531 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1533 int64_t value = qdict_get_int(qdict, "value");
1534 Error *err = NULL;
1536 qmp_migrate_set_cache_size(value, &err);
1537 hmp_handle_error(mon, &err);
1540 /* Kept for backwards compatibility */
1541 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1543 int64_t value = qdict_get_int(qdict, "value");
1544 qmp_migrate_set_speed(value, NULL);
1547 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1549 const char *cap = qdict_get_str(qdict, "capability");
1550 bool state = qdict_get_bool(qdict, "state");
1551 Error *err = NULL;
1552 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1553 int val;
1555 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
1556 if (val < 0) {
1557 goto end;
1560 caps->value = g_malloc0(sizeof(*caps->value));
1561 caps->value->capability = val;
1562 caps->value->state = state;
1563 caps->next = NULL;
1564 qmp_migrate_set_capabilities(caps, &err);
1566 end:
1567 qapi_free_MigrationCapabilityStatusList(caps);
1568 hmp_handle_error(mon, &err);
1571 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1573 const char *param = qdict_get_str(qdict, "parameter");
1574 const char *valuestr = qdict_get_str(qdict, "value");
1575 Visitor *v = string_input_visitor_new(valuestr);
1576 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
1577 uint64_t valuebw = 0;
1578 uint64_t cache_size;
1579 Error *err = NULL;
1580 int val, ret;
1582 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
1583 if (val < 0) {
1584 goto cleanup;
1587 switch (val) {
1588 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1589 p->has_compress_level = true;
1590 visit_type_int(v, param, &p->compress_level, &err);
1591 break;
1592 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1593 p->has_compress_threads = true;
1594 visit_type_int(v, param, &p->compress_threads, &err);
1595 break;
1596 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1597 p->has_decompress_threads = true;
1598 visit_type_int(v, param, &p->decompress_threads, &err);
1599 break;
1600 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1601 p->has_cpu_throttle_initial = true;
1602 visit_type_int(v, param, &p->cpu_throttle_initial, &err);
1603 break;
1604 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1605 p->has_cpu_throttle_increment = true;
1606 visit_type_int(v, param, &p->cpu_throttle_increment, &err);
1607 break;
1608 case MIGRATION_PARAMETER_TLS_CREDS:
1609 p->has_tls_creds = true;
1610 p->tls_creds = g_new0(StrOrNull, 1);
1611 p->tls_creds->type = QTYPE_QSTRING;
1612 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1613 break;
1614 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1615 p->has_tls_hostname = true;
1616 p->tls_hostname = g_new0(StrOrNull, 1);
1617 p->tls_hostname->type = QTYPE_QSTRING;
1618 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1619 break;
1620 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1621 p->has_max_bandwidth = true;
1623 * Can't use visit_type_size() here, because it
1624 * defaults to Bytes rather than Mebibytes.
1626 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1627 if (ret < 0 || valuebw > INT64_MAX
1628 || (size_t)valuebw != valuebw) {
1629 error_setg(&err, "Invalid size %s", valuestr);
1630 break;
1632 p->max_bandwidth = valuebw;
1633 break;
1634 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1635 p->has_downtime_limit = true;
1636 visit_type_int(v, param, &p->downtime_limit, &err);
1637 break;
1638 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1639 p->has_x_checkpoint_delay = true;
1640 visit_type_int(v, param, &p->x_checkpoint_delay, &err);
1641 break;
1642 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1643 p->has_block_incremental = true;
1644 visit_type_bool(v, param, &p->block_incremental, &err);
1645 break;
1646 case MIGRATION_PARAMETER_X_MULTIFD_CHANNELS:
1647 p->has_x_multifd_channels = true;
1648 visit_type_int(v, param, &p->x_multifd_channels, &err);
1649 break;
1650 case MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT:
1651 p->has_x_multifd_page_count = true;
1652 visit_type_int(v, param, &p->x_multifd_page_count, &err);
1653 break;
1654 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1655 p->has_xbzrle_cache_size = true;
1656 visit_type_size(v, param, &cache_size, &err);
1657 if (err || cache_size > INT64_MAX
1658 || (size_t)cache_size != cache_size) {
1659 error_setg(&err, "Invalid size %s", valuestr);
1660 break;
1662 p->xbzrle_cache_size = cache_size;
1663 break;
1664 default:
1665 assert(0);
1668 if (err) {
1669 goto cleanup;
1672 qmp_migrate_set_parameters(p, &err);
1674 cleanup:
1675 qapi_free_MigrateSetParameters(p);
1676 visit_free(v);
1677 hmp_handle_error(mon, &err);
1680 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1682 Error *err = NULL;
1683 const char *protocol = qdict_get_str(qdict, "protocol");
1684 const char *hostname = qdict_get_str(qdict, "hostname");
1685 bool has_port = qdict_haskey(qdict, "port");
1686 int port = qdict_get_try_int(qdict, "port", -1);
1687 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1688 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1689 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1691 qmp_client_migrate_info(protocol, hostname,
1692 has_port, port, has_tls_port, tls_port,
1693 !!cert_subject, cert_subject, &err);
1694 hmp_handle_error(mon, &err);
1697 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1699 Error *err = NULL;
1700 qmp_migrate_start_postcopy(&err);
1701 hmp_handle_error(mon, &err);
1704 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1706 Error *err = NULL;
1708 qmp_x_colo_lost_heartbeat(&err);
1709 hmp_handle_error(mon, &err);
1712 void hmp_set_password(Monitor *mon, const QDict *qdict)
1714 const char *protocol = qdict_get_str(qdict, "protocol");
1715 const char *password = qdict_get_str(qdict, "password");
1716 const char *connected = qdict_get_try_str(qdict, "connected");
1717 Error *err = NULL;
1719 qmp_set_password(protocol, password, !!connected, connected, &err);
1720 hmp_handle_error(mon, &err);
1723 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1725 const char *protocol = qdict_get_str(qdict, "protocol");
1726 const char *whenstr = qdict_get_str(qdict, "time");
1727 Error *err = NULL;
1729 qmp_expire_password(protocol, whenstr, &err);
1730 hmp_handle_error(mon, &err);
1733 void hmp_eject(Monitor *mon, const QDict *qdict)
1735 bool force = qdict_get_try_bool(qdict, "force", false);
1736 const char *device = qdict_get_str(qdict, "device");
1737 Error *err = NULL;
1739 qmp_eject(true, device, false, NULL, true, force, &err);
1740 hmp_handle_error(mon, &err);
1743 static void hmp_change_read_arg(void *opaque, const char *password,
1744 void *readline_opaque)
1746 qmp_change_vnc_password(password, NULL);
1747 monitor_read_command(opaque, 1);
1750 void hmp_change(Monitor *mon, const QDict *qdict)
1752 const char *device = qdict_get_str(qdict, "device");
1753 const char *target = qdict_get_str(qdict, "target");
1754 const char *arg = qdict_get_try_str(qdict, "arg");
1755 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1756 BlockdevChangeReadOnlyMode read_only_mode = 0;
1757 Error *err = NULL;
1759 if (strcmp(device, "vnc") == 0) {
1760 if (read_only) {
1761 monitor_printf(mon,
1762 "Parameter 'read-only-mode' is invalid for VNC\n");
1763 return;
1765 if (strcmp(target, "passwd") == 0 ||
1766 strcmp(target, "password") == 0) {
1767 if (!arg) {
1768 monitor_read_password(mon, hmp_change_read_arg, NULL);
1769 return;
1772 qmp_change("vnc", target, !!arg, arg, &err);
1773 } else {
1774 if (read_only) {
1775 read_only_mode =
1776 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
1777 read_only,
1778 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1779 if (err) {
1780 hmp_handle_error(mon, &err);
1781 return;
1785 qmp_blockdev_change_medium(true, device, false, NULL, target,
1786 !!arg, arg, !!read_only, read_only_mode,
1787 &err);
1790 hmp_handle_error(mon, &err);
1793 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1795 Error *err = NULL;
1796 BlockIOThrottle throttle = {
1797 .has_device = true,
1798 .device = (char *) qdict_get_str(qdict, "device"),
1799 .bps = qdict_get_int(qdict, "bps"),
1800 .bps_rd = qdict_get_int(qdict, "bps_rd"),
1801 .bps_wr = qdict_get_int(qdict, "bps_wr"),
1802 .iops = qdict_get_int(qdict, "iops"),
1803 .iops_rd = qdict_get_int(qdict, "iops_rd"),
1804 .iops_wr = qdict_get_int(qdict, "iops_wr"),
1807 qmp_block_set_io_throttle(&throttle, &err);
1808 hmp_handle_error(mon, &err);
1811 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1813 Error *error = NULL;
1814 const char *device = qdict_get_str(qdict, "device");
1815 const char *base = qdict_get_try_str(qdict, "base");
1816 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1818 qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
1819 false, NULL, qdict_haskey(qdict, "speed"), speed,
1820 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1822 hmp_handle_error(mon, &error);
1825 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1827 Error *error = NULL;
1828 const char *device = qdict_get_str(qdict, "device");
1829 int64_t value = qdict_get_int(qdict, "speed");
1831 qmp_block_job_set_speed(device, value, &error);
1833 hmp_handle_error(mon, &error);
1836 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1838 Error *error = NULL;
1839 const char *device = qdict_get_str(qdict, "device");
1840 bool force = qdict_get_try_bool(qdict, "force", false);
1842 qmp_block_job_cancel(device, true, force, &error);
1844 hmp_handle_error(mon, &error);
1847 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1849 Error *error = NULL;
1850 const char *device = qdict_get_str(qdict, "device");
1852 qmp_block_job_pause(device, &error);
1854 hmp_handle_error(mon, &error);
1857 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1859 Error *error = NULL;
1860 const char *device = qdict_get_str(qdict, "device");
1862 qmp_block_job_resume(device, &error);
1864 hmp_handle_error(mon, &error);
1867 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1869 Error *error = NULL;
1870 const char *device = qdict_get_str(qdict, "device");
1872 qmp_block_job_complete(device, &error);
1874 hmp_handle_error(mon, &error);
1877 typedef struct HMPMigrationStatus
1879 QEMUTimer *timer;
1880 Monitor *mon;
1881 bool is_block_migration;
1882 } HMPMigrationStatus;
1884 static void hmp_migrate_status_cb(void *opaque)
1886 HMPMigrationStatus *status = opaque;
1887 MigrationInfo *info;
1889 info = qmp_query_migrate(NULL);
1890 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1891 info->status == MIGRATION_STATUS_SETUP) {
1892 if (info->has_disk) {
1893 int progress;
1895 if (info->disk->remaining) {
1896 progress = info->disk->transferred * 100 / info->disk->total;
1897 } else {
1898 progress = 100;
1901 monitor_printf(status->mon, "Completed %d %%\r", progress);
1902 monitor_flush(status->mon);
1905 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1906 } else {
1907 if (status->is_block_migration) {
1908 monitor_printf(status->mon, "\n");
1910 if (info->has_error_desc) {
1911 error_report("%s", info->error_desc);
1913 monitor_resume(status->mon);
1914 timer_del(status->timer);
1915 g_free(status);
1918 qapi_free_MigrationInfo(info);
1921 void hmp_migrate(Monitor *mon, const QDict *qdict)
1923 bool detach = qdict_get_try_bool(qdict, "detach", false);
1924 bool blk = qdict_get_try_bool(qdict, "blk", false);
1925 bool inc = qdict_get_try_bool(qdict, "inc", false);
1926 const char *uri = qdict_get_str(qdict, "uri");
1927 Error *err = NULL;
1929 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1930 if (err) {
1931 hmp_handle_error(mon, &err);
1932 return;
1935 if (!detach) {
1936 HMPMigrationStatus *status;
1938 if (monitor_suspend(mon) < 0) {
1939 monitor_printf(mon, "terminal does not allow synchronous "
1940 "migration, continuing detached\n");
1941 return;
1944 status = g_malloc0(sizeof(*status));
1945 status->mon = mon;
1946 status->is_block_migration = blk || inc;
1947 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1948 status);
1949 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1953 void hmp_device_add(Monitor *mon, const QDict *qdict)
1955 Error *err = NULL;
1957 qmp_device_add((QDict *)qdict, NULL, &err);
1958 hmp_handle_error(mon, &err);
1961 void hmp_device_del(Monitor *mon, const QDict *qdict)
1963 const char *id = qdict_get_str(qdict, "id");
1964 Error *err = NULL;
1966 qmp_device_del(id, &err);
1967 hmp_handle_error(mon, &err);
1970 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1972 Error *err = NULL;
1973 bool paging = qdict_get_try_bool(qdict, "paging", false);
1974 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
1975 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
1976 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
1977 const char *file = qdict_get_str(qdict, "filename");
1978 bool has_begin = qdict_haskey(qdict, "begin");
1979 bool has_length = qdict_haskey(qdict, "length");
1980 bool has_detach = qdict_haskey(qdict, "detach");
1981 int64_t begin = 0;
1982 int64_t length = 0;
1983 bool detach = false;
1984 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1985 char *prot;
1987 if (zlib + lzo + snappy > 1) {
1988 error_setg(&err, "only one of '-z|-l|-s' can be set");
1989 hmp_handle_error(mon, &err);
1990 return;
1993 if (zlib) {
1994 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1997 if (lzo) {
1998 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
2001 if (snappy) {
2002 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
2005 if (has_begin) {
2006 begin = qdict_get_int(qdict, "begin");
2008 if (has_length) {
2009 length = qdict_get_int(qdict, "length");
2011 if (has_detach) {
2012 detach = qdict_get_bool(qdict, "detach");
2015 prot = g_strconcat("file:", file, NULL);
2017 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
2018 has_length, length, true, dump_format, &err);
2019 hmp_handle_error(mon, &err);
2020 g_free(prot);
2023 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
2025 Error *err = NULL;
2026 QemuOpts *opts;
2028 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
2029 if (err) {
2030 goto out;
2033 netdev_add(opts, &err);
2034 if (err) {
2035 qemu_opts_del(opts);
2038 out:
2039 hmp_handle_error(mon, &err);
2042 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
2044 const char *id = qdict_get_str(qdict, "id");
2045 Error *err = NULL;
2047 qmp_netdev_del(id, &err);
2048 hmp_handle_error(mon, &err);
2051 void hmp_object_add(Monitor *mon, const QDict *qdict)
2053 Error *err = NULL;
2054 QemuOpts *opts;
2055 Object *obj = NULL;
2057 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
2058 if (err) {
2059 hmp_handle_error(mon, &err);
2060 return;
2063 obj = user_creatable_add_opts(opts, &err);
2064 qemu_opts_del(opts);
2066 if (err) {
2067 hmp_handle_error(mon, &err);
2069 if (obj) {
2070 object_unref(obj);
2074 void hmp_getfd(Monitor *mon, const QDict *qdict)
2076 const char *fdname = qdict_get_str(qdict, "fdname");
2077 Error *err = NULL;
2079 qmp_getfd(fdname, &err);
2080 hmp_handle_error(mon, &err);
2083 void hmp_closefd(Monitor *mon, const QDict *qdict)
2085 const char *fdname = qdict_get_str(qdict, "fdname");
2086 Error *err = NULL;
2088 qmp_closefd(fdname, &err);
2089 hmp_handle_error(mon, &err);
2092 void hmp_sendkey(Monitor *mon, const QDict *qdict)
2094 const char *keys = qdict_get_str(qdict, "keys");
2095 KeyValueList *keylist, *head = NULL, *tmp = NULL;
2096 int has_hold_time = qdict_haskey(qdict, "hold-time");
2097 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
2098 Error *err = NULL;
2099 char *separator;
2100 int keyname_len;
2102 while (1) {
2103 separator = strchr(keys, '-');
2104 keyname_len = separator ? separator - keys : strlen(keys);
2106 /* Be compatible with old interface, convert user inputted "<" */
2107 if (keys[0] == '<' && keyname_len == 1) {
2108 keys = "less";
2109 keyname_len = 4;
2112 keylist = g_malloc0(sizeof(*keylist));
2113 keylist->value = g_malloc0(sizeof(*keylist->value));
2115 if (!head) {
2116 head = keylist;
2118 if (tmp) {
2119 tmp->next = keylist;
2121 tmp = keylist;
2123 if (strstart(keys, "0x", NULL)) {
2124 char *endp;
2125 int value = strtoul(keys, &endp, 0);
2126 assert(endp <= keys + keyname_len);
2127 if (endp != keys + keyname_len) {
2128 goto err_out;
2130 keylist->value->type = KEY_VALUE_KIND_NUMBER;
2131 keylist->value->u.number.data = value;
2132 } else {
2133 int idx = index_from_key(keys, keyname_len);
2134 if (idx == Q_KEY_CODE__MAX) {
2135 goto err_out;
2137 keylist->value->type = KEY_VALUE_KIND_QCODE;
2138 keylist->value->u.qcode.data = idx;
2141 if (!separator) {
2142 break;
2144 keys = separator + 1;
2147 qmp_send_key(head, has_hold_time, hold_time, &err);
2148 hmp_handle_error(mon, &err);
2150 out:
2151 qapi_free_KeyValueList(head);
2152 return;
2154 err_out:
2155 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
2156 goto out;
2159 void hmp_screendump(Monitor *mon, const QDict *qdict)
2161 const char *filename = qdict_get_str(qdict, "filename");
2162 Error *err = NULL;
2164 qmp_screendump(filename, &err);
2165 hmp_handle_error(mon, &err);
2168 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
2170 const char *uri = qdict_get_str(qdict, "uri");
2171 bool writable = qdict_get_try_bool(qdict, "writable", false);
2172 bool all = qdict_get_try_bool(qdict, "all", false);
2173 Error *local_err = NULL;
2174 BlockInfoList *block_list, *info;
2175 SocketAddress *addr;
2177 if (writable && !all) {
2178 error_setg(&local_err, "-w only valid together with -a");
2179 goto exit;
2182 /* First check if the address is valid and start the server. */
2183 addr = socket_parse(uri, &local_err);
2184 if (local_err != NULL) {
2185 goto exit;
2188 nbd_server_start(addr, NULL, &local_err);
2189 qapi_free_SocketAddress(addr);
2190 if (local_err != NULL) {
2191 goto exit;
2194 if (!all) {
2195 return;
2198 /* Then try adding all block devices. If one fails, close all and
2199 * exit.
2201 block_list = qmp_query_block(NULL);
2203 for (info = block_list; info; info = info->next) {
2204 if (!info->value->has_inserted) {
2205 continue;
2208 qmp_nbd_server_add(info->value->device, false, NULL,
2209 true, writable, &local_err);
2211 if (local_err != NULL) {
2212 qmp_nbd_server_stop(NULL);
2213 break;
2217 qapi_free_BlockInfoList(block_list);
2219 exit:
2220 hmp_handle_error(mon, &local_err);
2223 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
2225 const char *device = qdict_get_str(qdict, "device");
2226 const char *name = qdict_get_try_str(qdict, "name");
2227 bool writable = qdict_get_try_bool(qdict, "writable", false);
2228 Error *local_err = NULL;
2230 qmp_nbd_server_add(device, !!name, name, true, writable, &local_err);
2231 hmp_handle_error(mon, &local_err);
2234 void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict)
2236 const char *name = qdict_get_str(qdict, "name");
2237 bool force = qdict_get_try_bool(qdict, "force", false);
2238 Error *err = NULL;
2240 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
2241 qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err);
2242 hmp_handle_error(mon, &err);
2245 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
2247 Error *err = NULL;
2249 qmp_nbd_server_stop(&err);
2250 hmp_handle_error(mon, &err);
2253 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
2255 int cpuid;
2256 Error *err = NULL;
2258 cpuid = qdict_get_int(qdict, "id");
2259 qmp_cpu_add(cpuid, &err);
2260 hmp_handle_error(mon, &err);
2263 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2265 const char *args = qdict_get_str(qdict, "args");
2266 Error *err = NULL;
2267 QemuOpts *opts;
2269 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
2270 if (opts == NULL) {
2271 error_setg(&err, "Parsing chardev args failed");
2272 } else {
2273 qemu_chr_new_from_opts(opts, &err);
2274 qemu_opts_del(opts);
2276 hmp_handle_error(mon, &err);
2279 void hmp_chardev_change(Monitor *mon, const QDict *qdict)
2281 const char *args = qdict_get_str(qdict, "args");
2282 const char *id;
2283 Error *err = NULL;
2284 ChardevBackend *backend = NULL;
2285 ChardevReturn *ret = NULL;
2286 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
2287 true);
2288 if (!opts) {
2289 error_setg(&err, "Parsing chardev args failed");
2290 goto end;
2293 id = qdict_get_str(qdict, "id");
2294 if (qemu_opts_id(opts)) {
2295 error_setg(&err, "Unexpected 'id' parameter");
2296 goto end;
2299 backend = qemu_chr_parse_opts(opts, &err);
2300 if (!backend) {
2301 goto end;
2304 ret = qmp_chardev_change(id, backend, &err);
2306 end:
2307 qapi_free_ChardevReturn(ret);
2308 qapi_free_ChardevBackend(backend);
2309 qemu_opts_del(opts);
2310 hmp_handle_error(mon, &err);
2313 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2315 Error *local_err = NULL;
2317 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
2318 hmp_handle_error(mon, &local_err);
2321 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
2323 Error *local_err = NULL;
2325 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
2326 hmp_handle_error(mon, &local_err);
2329 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
2331 BlockBackend *blk;
2332 BlockBackend *local_blk = NULL;
2333 const char* device = qdict_get_str(qdict, "device");
2334 const char* command = qdict_get_str(qdict, "command");
2335 Error *err = NULL;
2336 int ret;
2338 blk = blk_by_name(device);
2339 if (!blk) {
2340 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
2341 if (bs) {
2342 blk = local_blk = blk_new(0, BLK_PERM_ALL);
2343 ret = blk_insert_bs(blk, bs, &err);
2344 if (ret < 0) {
2345 goto fail;
2347 } else {
2348 goto fail;
2353 * Notably absent: Proper permission management. This is sad, but it seems
2354 * almost impossible to achieve without changing the semantics and thereby
2355 * limiting the use cases of the qemu-io HMP command.
2357 * In an ideal world we would unconditionally create a new BlockBackend for
2358 * qemuio_command(), but we have commands like 'reopen' and want them to
2359 * take effect on the exact BlockBackend whose name the user passed instead
2360 * of just on a temporary copy of it.
2362 * Another problem is that deleting the temporary BlockBackend involves
2363 * draining all requests on it first, but some qemu-iotests cases want to
2364 * issue multiple aio_read/write requests and expect them to complete in
2365 * the background while the monitor has already returned.
2367 * This is also what prevents us from saving the original permissions and
2368 * restoring them later: We can't revoke permissions until all requests
2369 * have completed, and we don't know when that is nor can we really let
2370 * anything else run before we have revoken them to avoid race conditions.
2372 * What happens now is that command() in qemu-io-cmds.c can extend the
2373 * permissions if necessary for the qemu-io command. And they simply stay
2374 * extended, possibly resulting in a read-only guest device keeping write
2375 * permissions. Ugly, but it appears to be the lesser evil.
2377 qemuio_command(blk, command);
2379 fail:
2380 blk_unref(local_blk);
2381 hmp_handle_error(mon, &err);
2384 void hmp_object_del(Monitor *mon, const QDict *qdict)
2386 const char *id = qdict_get_str(qdict, "id");
2387 Error *err = NULL;
2389 user_creatable_del(id, &err);
2390 hmp_handle_error(mon, &err);
2393 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
2395 Error *err = NULL;
2396 MemdevList *memdev_list = qmp_query_memdev(&err);
2397 MemdevList *m = memdev_list;
2398 Visitor *v;
2399 char *str;
2401 while (m) {
2402 v = string_output_visitor_new(false, &str);
2403 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
2404 monitor_printf(mon, "memory backend: %s\n", m->value->id);
2405 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
2406 monitor_printf(mon, " merge: %s\n",
2407 m->value->merge ? "true" : "false");
2408 monitor_printf(mon, " dump: %s\n",
2409 m->value->dump ? "true" : "false");
2410 monitor_printf(mon, " prealloc: %s\n",
2411 m->value->prealloc ? "true" : "false");
2412 monitor_printf(mon, " policy: %s\n",
2413 HostMemPolicy_str(m->value->policy));
2414 visit_complete(v, &str);
2415 monitor_printf(mon, " host nodes: %s\n", str);
2417 g_free(str);
2418 visit_free(v);
2419 m = m->next;
2422 monitor_printf(mon, "\n");
2424 qapi_free_MemdevList(memdev_list);
2425 hmp_handle_error(mon, &err);
2428 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2430 Error *err = NULL;
2431 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2432 MemoryDeviceInfoList *info;
2433 MemoryDeviceInfo *value;
2434 PCDIMMDeviceInfo *di;
2436 for (info = info_list; info; info = info->next) {
2437 value = info->value;
2439 if (value) {
2440 switch (value->type) {
2441 case MEMORY_DEVICE_INFO_KIND_DIMM:
2442 di = value->u.dimm.data;
2444 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2445 MemoryDeviceInfoKind_str(value->type),
2446 di->id ? di->id : "");
2447 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2448 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2449 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2450 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2451 monitor_printf(mon, " memdev: %s\n", di->memdev);
2452 monitor_printf(mon, " hotplugged: %s\n",
2453 di->hotplugged ? "true" : "false");
2454 monitor_printf(mon, " hotpluggable: %s\n",
2455 di->hotpluggable ? "true" : "false");
2456 break;
2457 default:
2458 break;
2463 qapi_free_MemoryDeviceInfoList(info_list);
2464 hmp_handle_error(mon, &err);
2467 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2469 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2470 IOThreadInfoList *info;
2471 IOThreadInfo *value;
2473 for (info = info_list; info; info = info->next) {
2474 value = info->value;
2475 monitor_printf(mon, "%s:\n", value->id);
2476 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
2477 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2478 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
2479 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
2482 qapi_free_IOThreadInfoList(info_list);
2485 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2487 const char *path = qdict_get_try_str(qdict, "path");
2488 ObjectPropertyInfoList *list;
2489 Error *err = NULL;
2491 if (path == NULL) {
2492 monitor_printf(mon, "/\n");
2493 return;
2496 list = qmp_qom_list(path, &err);
2497 if (err == NULL) {
2498 ObjectPropertyInfoList *start = list;
2499 while (list != NULL) {
2500 ObjectPropertyInfo *value = list->value;
2502 monitor_printf(mon, "%s (%s)\n",
2503 value->name, value->type);
2504 list = list->next;
2506 qapi_free_ObjectPropertyInfoList(start);
2508 hmp_handle_error(mon, &err);
2511 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2513 const char *path = qdict_get_str(qdict, "path");
2514 const char *property = qdict_get_str(qdict, "property");
2515 const char *value = qdict_get_str(qdict, "value");
2516 Error *err = NULL;
2517 bool ambiguous = false;
2518 Object *obj;
2520 obj = object_resolve_path(path, &ambiguous);
2521 if (obj == NULL) {
2522 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2523 "Device '%s' not found", path);
2524 } else {
2525 if (ambiguous) {
2526 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2528 object_property_parse(obj, value, property, &err);
2530 hmp_handle_error(mon, &err);
2533 void hmp_rocker(Monitor *mon, const QDict *qdict)
2535 const char *name = qdict_get_str(qdict, "name");
2536 RockerSwitch *rocker;
2537 Error *err = NULL;
2539 rocker = qmp_query_rocker(name, &err);
2540 if (err != NULL) {
2541 hmp_handle_error(mon, &err);
2542 return;
2545 monitor_printf(mon, "name: %s\n", rocker->name);
2546 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2547 monitor_printf(mon, "ports: %d\n", rocker->ports);
2549 qapi_free_RockerSwitch(rocker);
2552 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2554 RockerPortList *list, *port;
2555 const char *name = qdict_get_str(qdict, "name");
2556 Error *err = NULL;
2558 list = qmp_query_rocker_ports(name, &err);
2559 if (err != NULL) {
2560 hmp_handle_error(mon, &err);
2561 return;
2564 monitor_printf(mon, " ena/ speed/ auto\n");
2565 monitor_printf(mon, " port link duplex neg?\n");
2567 for (port = list; port; port = port->next) {
2568 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2569 port->value->name,
2570 port->value->enabled ? port->value->link_up ?
2571 "up" : "down" : "!ena",
2572 port->value->speed == 10000 ? "10G" : "??",
2573 port->value->duplex ? "FD" : "HD",
2574 port->value->autoneg ? "Yes" : "No");
2577 qapi_free_RockerPortList(list);
2580 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2582 RockerOfDpaFlowList *list, *info;
2583 const char *name = qdict_get_str(qdict, "name");
2584 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2585 Error *err = NULL;
2587 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2588 if (err != NULL) {
2589 hmp_handle_error(mon, &err);
2590 return;
2593 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2595 for (info = list; info; info = info->next) {
2596 RockerOfDpaFlow *flow = info->value;
2597 RockerOfDpaFlowKey *key = flow->key;
2598 RockerOfDpaFlowMask *mask = flow->mask;
2599 RockerOfDpaFlowAction *action = flow->action;
2601 if (flow->hits) {
2602 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2603 key->priority, key->tbl_id, flow->hits);
2604 } else {
2605 monitor_printf(mon, "%-4d %-3d ",
2606 key->priority, key->tbl_id);
2609 if (key->has_in_pport) {
2610 monitor_printf(mon, " pport %d", key->in_pport);
2611 if (mask->has_in_pport) {
2612 monitor_printf(mon, "(0x%x)", mask->in_pport);
2616 if (key->has_vlan_id) {
2617 monitor_printf(mon, " vlan %d",
2618 key->vlan_id & VLAN_VID_MASK);
2619 if (mask->has_vlan_id) {
2620 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2624 if (key->has_tunnel_id) {
2625 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2626 if (mask->has_tunnel_id) {
2627 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2631 if (key->has_eth_type) {
2632 switch (key->eth_type) {
2633 case 0x0806:
2634 monitor_printf(mon, " ARP");
2635 break;
2636 case 0x0800:
2637 monitor_printf(mon, " IP");
2638 break;
2639 case 0x86dd:
2640 monitor_printf(mon, " IPv6");
2641 break;
2642 case 0x8809:
2643 monitor_printf(mon, " LACP");
2644 break;
2645 case 0x88cc:
2646 monitor_printf(mon, " LLDP");
2647 break;
2648 default:
2649 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2650 break;
2654 if (key->has_eth_src) {
2655 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2656 (mask->has_eth_src) &&
2657 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2658 monitor_printf(mon, " src <any mcast/bcast>");
2659 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2660 (mask->has_eth_src) &&
2661 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2662 monitor_printf(mon, " src <any ucast>");
2663 } else {
2664 monitor_printf(mon, " src %s", key->eth_src);
2665 if (mask->has_eth_src) {
2666 monitor_printf(mon, "(%s)", mask->eth_src);
2671 if (key->has_eth_dst) {
2672 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2673 (mask->has_eth_dst) &&
2674 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2675 monitor_printf(mon, " dst <any mcast/bcast>");
2676 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2677 (mask->has_eth_dst) &&
2678 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2679 monitor_printf(mon, " dst <any ucast>");
2680 } else {
2681 monitor_printf(mon, " dst %s", key->eth_dst);
2682 if (mask->has_eth_dst) {
2683 monitor_printf(mon, "(%s)", mask->eth_dst);
2688 if (key->has_ip_proto) {
2689 monitor_printf(mon, " proto %d", key->ip_proto);
2690 if (mask->has_ip_proto) {
2691 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2695 if (key->has_ip_tos) {
2696 monitor_printf(mon, " TOS %d", key->ip_tos);
2697 if (mask->has_ip_tos) {
2698 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2702 if (key->has_ip_dst) {
2703 monitor_printf(mon, " dst %s", key->ip_dst);
2706 if (action->has_goto_tbl || action->has_group_id ||
2707 action->has_new_vlan_id) {
2708 monitor_printf(mon, " -->");
2711 if (action->has_new_vlan_id) {
2712 monitor_printf(mon, " apply new vlan %d",
2713 ntohs(action->new_vlan_id));
2716 if (action->has_group_id) {
2717 monitor_printf(mon, " write group 0x%08x", action->group_id);
2720 if (action->has_goto_tbl) {
2721 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2724 monitor_printf(mon, "\n");
2727 qapi_free_RockerOfDpaFlowList(list);
2730 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2732 RockerOfDpaGroupList *list, *g;
2733 const char *name = qdict_get_str(qdict, "name");
2734 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2735 Error *err = NULL;
2736 bool set = false;
2738 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2739 if (err != NULL) {
2740 hmp_handle_error(mon, &err);
2741 return;
2744 monitor_printf(mon, "id (decode) --> buckets\n");
2746 for (g = list; g; g = g->next) {
2747 RockerOfDpaGroup *group = g->value;
2749 monitor_printf(mon, "0x%08x", group->id);
2751 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2752 group->type == 1 ? "L2 rewrite" :
2753 group->type == 2 ? "L3 unicast" :
2754 group->type == 3 ? "L2 multicast" :
2755 group->type == 4 ? "L2 flood" :
2756 group->type == 5 ? "L3 interface" :
2757 group->type == 6 ? "L3 multicast" :
2758 group->type == 7 ? "L3 ECMP" :
2759 group->type == 8 ? "L2 overlay" :
2760 "unknown");
2762 if (group->has_vlan_id) {
2763 monitor_printf(mon, " vlan %d", group->vlan_id);
2766 if (group->has_pport) {
2767 monitor_printf(mon, " pport %d", group->pport);
2770 if (group->has_index) {
2771 monitor_printf(mon, " index %d", group->index);
2774 monitor_printf(mon, ") -->");
2776 if (group->has_set_vlan_id && group->set_vlan_id) {
2777 set = true;
2778 monitor_printf(mon, " set vlan %d",
2779 group->set_vlan_id & VLAN_VID_MASK);
2782 if (group->has_set_eth_src) {
2783 if (!set) {
2784 set = true;
2785 monitor_printf(mon, " set");
2787 monitor_printf(mon, " src %s", group->set_eth_src);
2790 if (group->has_set_eth_dst) {
2791 if (!set) {
2792 set = true;
2793 monitor_printf(mon, " set");
2795 monitor_printf(mon, " dst %s", group->set_eth_dst);
2798 set = false;
2800 if (group->has_ttl_check && group->ttl_check) {
2801 monitor_printf(mon, " check TTL");
2804 if (group->has_group_id && group->group_id) {
2805 monitor_printf(mon, " group id 0x%08x", group->group_id);
2808 if (group->has_pop_vlan && group->pop_vlan) {
2809 monitor_printf(mon, " pop vlan");
2812 if (group->has_out_pport) {
2813 monitor_printf(mon, " out pport %d", group->out_pport);
2816 if (group->has_group_ids) {
2817 struct uint32List *id;
2819 monitor_printf(mon, " groups [");
2820 for (id = group->group_ids; id; id = id->next) {
2821 monitor_printf(mon, "0x%08x", id->value);
2822 if (id->next) {
2823 monitor_printf(mon, ",");
2826 monitor_printf(mon, "]");
2829 monitor_printf(mon, "\n");
2832 qapi_free_RockerOfDpaGroupList(list);
2835 void hmp_info_dump(Monitor *mon, const QDict *qdict)
2837 DumpQueryResult *result = qmp_query_dump(NULL);
2839 assert(result && result->status < DUMP_STATUS__MAX);
2840 monitor_printf(mon, "Status: %s\n", DumpStatus_str(result->status));
2842 if (result->status == DUMP_STATUS_ACTIVE) {
2843 float percent = 0;
2844 assert(result->total != 0);
2845 percent = 100.0 * result->completed / result->total;
2846 monitor_printf(mon, "Finished: %.2f %%\n", percent);
2849 qapi_free_DumpQueryResult(result);
2852 void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
2854 ram_block_dump(mon);
2857 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
2859 Error *err = NULL;
2860 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
2861 HotpluggableCPUList *saved = l;
2862 CpuInstanceProperties *c;
2864 if (err != NULL) {
2865 hmp_handle_error(mon, &err);
2866 return;
2869 monitor_printf(mon, "Hotpluggable CPUs:\n");
2870 while (l) {
2871 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
2872 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
2873 l->value->vcpus_count);
2874 if (l->value->has_qom_path) {
2875 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
2878 c = l->value->props;
2879 monitor_printf(mon, " CPUInstance Properties:\n");
2880 if (c->has_node_id) {
2881 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
2883 if (c->has_socket_id) {
2884 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
2886 if (c->has_core_id) {
2887 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
2889 if (c->has_thread_id) {
2890 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
2893 l = l->next;
2896 qapi_free_HotpluggableCPUList(saved);
2899 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
2901 Error *err = NULL;
2902 GuidInfo *info = qmp_query_vm_generation_id(&err);
2903 if (info) {
2904 monitor_printf(mon, "%s\n", info->guid);
2906 hmp_handle_error(mon, &err);
2907 qapi_free_GuidInfo(info);
2910 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
2912 Error *err = NULL;
2913 MemoryInfo *info = qmp_query_memory_size_summary(&err);
2914 if (info) {
2915 monitor_printf(mon, "base memory: %" PRIu64 "\n",
2916 info->base_memory);
2918 if (info->has_plugged_memory) {
2919 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
2920 info->plugged_memory);
2923 qapi_free_MemoryInfo(info);
2925 hmp_handle_error(mon, &err);