sev/i386: add command to initialize the memory encryption context
[qemu/ar7.git] / hmp.c
blobba9e299ee2ee3c66caff53ab6d9e185ffba8b14d
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 "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"
49 #include "qemu-io.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"
57 #ifdef CONFIG_SPICE
58 #include <spice/enums.h>
59 #endif
61 static void hmp_handle_error(Monitor *mon, Error **errp)
63 assert(errp);
64 if (*errp) {
65 error_report_err(*errp);
69 void hmp_info_name(Monitor *mon, const QDict *qdict)
71 NameInfo *info;
73 info = qmp_query_name(NULL);
74 if (info->has_name) {
75 monitor_printf(mon, "%s\n", info->name);
77 qapi_free_NameInfo(info);
80 void hmp_info_version(Monitor *mon, const QDict *qdict)
82 VersionInfo *info;
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,
88 info->package);
90 qapi_free_VersionInfo(info);
93 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
95 KvmInfo *info;
97 info = qmp_query_kvm(NULL);
98 monitor_printf(mon, "kvm support: ");
99 if (info->present) {
100 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
101 } else {
102 monitor_printf(mon, "not compiled\n");
105 qapi_free_KvmInfo(info);
108 void hmp_info_status(Monitor *mon, const QDict *qdict)
110 StatusInfo *info;
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)
129 UuidInfo *info;
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);
154 if (!mice_list) {
155 monitor_printf(mon, "No mouse devices connected\n");
156 return;
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)
171 MigrationInfo *info;
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);
196 } else {
197 monitor_printf(mon, "\n");
200 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
201 info->total_time);
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",
208 info->downtime);
210 if (info->has_setup_time) {
211 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
212 info->setup_time);
216 if (info->has_ram) {
217 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
218 info->ram->transferred >> 10);
219 monitor_printf(mon, "throughput: %0.2f mbps\n",
220 info->ram->mbps);
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",
228 info->ram->skipped);
229 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
230 info->ram->normal);
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);
238 if (info->ram->dirty_pages_rate) {
239 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
240 info->ram->dirty_pages_rate);
242 if (info->ram->postcopy_requests) {
243 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
244 info->ram->postcopy_requests);
248 if (info->has_disk) {
249 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
250 info->disk->transferred >> 10);
251 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
252 info->disk->remaining >> 10);
253 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
254 info->disk->total >> 10);
257 if (info->has_xbzrle_cache) {
258 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
259 info->xbzrle_cache->cache_size);
260 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
261 info->xbzrle_cache->bytes >> 10);
262 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
263 info->xbzrle_cache->pages);
264 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
265 info->xbzrle_cache->cache_miss);
266 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
267 info->xbzrle_cache->cache_miss_rate);
268 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
269 info->xbzrle_cache->overflow);
272 if (info->has_cpu_throttle_percentage) {
273 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
274 info->cpu_throttle_percentage);
277 qapi_free_MigrationInfo(info);
278 qapi_free_MigrationCapabilityStatusList(caps);
281 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
283 MigrationCapabilityStatusList *caps, *cap;
285 caps = qmp_query_migrate_capabilities(NULL);
287 if (caps) {
288 for (cap = caps; cap; cap = cap->next) {
289 monitor_printf(mon, "%s: %s\n",
290 MigrationCapability_str(cap->value->capability),
291 cap->value->state ? "on" : "off");
295 qapi_free_MigrationCapabilityStatusList(caps);
298 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
300 MigrationParameters *params;
302 params = qmp_query_migrate_parameters(NULL);
304 if (params) {
305 assert(params->has_compress_level);
306 monitor_printf(mon, "%s: %u\n",
307 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
308 params->compress_level);
309 assert(params->has_compress_threads);
310 monitor_printf(mon, "%s: %u\n",
311 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
312 params->compress_threads);
313 assert(params->has_decompress_threads);
314 monitor_printf(mon, "%s: %u\n",
315 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
316 params->decompress_threads);
317 assert(params->has_cpu_throttle_initial);
318 monitor_printf(mon, "%s: %u\n",
319 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
320 params->cpu_throttle_initial);
321 assert(params->has_cpu_throttle_increment);
322 monitor_printf(mon, "%s: %u\n",
323 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
324 params->cpu_throttle_increment);
325 assert(params->has_tls_creds);
326 monitor_printf(mon, "%s: '%s'\n",
327 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
328 params->tls_creds);
329 assert(params->has_tls_hostname);
330 monitor_printf(mon, "%s: '%s'\n",
331 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
332 params->tls_hostname);
333 assert(params->has_max_bandwidth);
334 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
335 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
336 params->max_bandwidth);
337 assert(params->has_downtime_limit);
338 monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n",
339 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
340 params->downtime_limit);
341 assert(params->has_x_checkpoint_delay);
342 monitor_printf(mon, "%s: %u\n",
343 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
344 params->x_checkpoint_delay);
345 assert(params->has_block_incremental);
346 monitor_printf(mon, "%s: %s\n",
347 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
348 params->block_incremental ? "on" : "off");
349 monitor_printf(mon, "%s: %u\n",
350 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_CHANNELS),
351 params->x_multifd_channels);
352 monitor_printf(mon, "%s: %u\n",
353 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT),
354 params->x_multifd_page_count);
355 monitor_printf(mon, "%s: %" PRIu64 "\n",
356 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
357 params->xbzrle_cache_size);
360 qapi_free_MigrationParameters(params);
363 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
365 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
366 qmp_query_migrate_cache_size(NULL) >> 10);
369 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
371 CpuInfoFastList *cpu_list, *cpu;
373 cpu_list = qmp_query_cpus_fast(NULL);
375 for (cpu = cpu_list; cpu; cpu = cpu->next) {
376 int active = ' ';
378 if (cpu->value->cpu_index == monitor_get_cpu_index()) {
379 active = '*';
382 monitor_printf(mon, "%c CPU #%" PRId64 ":", active,
383 cpu->value->cpu_index);
384 monitor_printf(mon, " thread-id=%" PRId64 "\n", cpu->value->thread_id);
387 qapi_free_CpuInfoFastList(cpu_list);
390 static void print_block_info(Monitor *mon, BlockInfo *info,
391 BlockDeviceInfo *inserted, bool verbose)
393 ImageInfo *image_info;
395 assert(!info || !info->has_inserted || info->inserted == inserted);
397 if (info && *info->device) {
398 monitor_printf(mon, "%s", info->device);
399 if (inserted && inserted->has_node_name) {
400 monitor_printf(mon, " (%s)", inserted->node_name);
402 } else {
403 assert(info || inserted);
404 monitor_printf(mon, "%s",
405 inserted && inserted->has_node_name ? inserted->node_name
406 : info && info->has_qdev ? info->qdev
407 : "<anonymous>");
410 if (inserted) {
411 monitor_printf(mon, ": %s (%s%s%s)\n",
412 inserted->file,
413 inserted->drv,
414 inserted->ro ? ", read-only" : "",
415 inserted->encrypted ? ", encrypted" : "");
416 } else {
417 monitor_printf(mon, ": [not inserted]\n");
420 if (info) {
421 if (info->has_qdev) {
422 monitor_printf(mon, " Attached to: %s\n", info->qdev);
424 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
425 monitor_printf(mon, " I/O status: %s\n",
426 BlockDeviceIoStatus_str(info->io_status));
429 if (info->removable) {
430 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
431 info->locked ? "" : "not ",
432 info->tray_open ? "open" : "closed");
437 if (!inserted) {
438 return;
441 monitor_printf(mon, " Cache mode: %s%s%s\n",
442 inserted->cache->writeback ? "writeback" : "writethrough",
443 inserted->cache->direct ? ", direct" : "",
444 inserted->cache->no_flush ? ", ignore flushes" : "");
446 if (inserted->has_backing_file) {
447 monitor_printf(mon,
448 " Backing file: %s "
449 "(chain depth: %" PRId64 ")\n",
450 inserted->backing_file,
451 inserted->backing_file_depth);
454 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
455 monitor_printf(mon, " Detect zeroes: %s\n",
456 BlockdevDetectZeroesOptions_str(inserted->detect_zeroes));
459 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
460 inserted->iops || inserted->iops_rd || inserted->iops_wr)
462 monitor_printf(mon, " I/O throttling: bps=%" PRId64
463 " bps_rd=%" PRId64 " bps_wr=%" PRId64
464 " bps_max=%" PRId64
465 " bps_rd_max=%" PRId64
466 " bps_wr_max=%" PRId64
467 " iops=%" PRId64 " iops_rd=%" PRId64
468 " iops_wr=%" PRId64
469 " iops_max=%" PRId64
470 " iops_rd_max=%" PRId64
471 " iops_wr_max=%" PRId64
472 " iops_size=%" PRId64
473 " group=%s\n",
474 inserted->bps,
475 inserted->bps_rd,
476 inserted->bps_wr,
477 inserted->bps_max,
478 inserted->bps_rd_max,
479 inserted->bps_wr_max,
480 inserted->iops,
481 inserted->iops_rd,
482 inserted->iops_wr,
483 inserted->iops_max,
484 inserted->iops_rd_max,
485 inserted->iops_wr_max,
486 inserted->iops_size,
487 inserted->group);
490 if (verbose) {
491 monitor_printf(mon, "\nImages:\n");
492 image_info = inserted->image;
493 while (1) {
494 bdrv_image_info_dump((fprintf_function)monitor_printf,
495 mon, image_info);
496 if (image_info->has_backing_image) {
497 image_info = image_info->backing_image;
498 } else {
499 break;
505 void hmp_info_block(Monitor *mon, const QDict *qdict)
507 BlockInfoList *block_list, *info;
508 BlockDeviceInfoList *blockdev_list, *blockdev;
509 const char *device = qdict_get_try_str(qdict, "device");
510 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
511 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
512 bool printed = false;
514 /* Print BlockBackend information */
515 if (!nodes) {
516 block_list = qmp_query_block(NULL);
517 } else {
518 block_list = NULL;
521 for (info = block_list; info; info = info->next) {
522 if (device && strcmp(device, info->value->device)) {
523 continue;
526 if (info != block_list) {
527 monitor_printf(mon, "\n");
530 print_block_info(mon, info->value, info->value->has_inserted
531 ? info->value->inserted : NULL,
532 verbose);
533 printed = true;
536 qapi_free_BlockInfoList(block_list);
538 if ((!device && !nodes) || printed) {
539 return;
542 /* Print node information */
543 blockdev_list = qmp_query_named_block_nodes(NULL);
544 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
545 assert(blockdev->value->has_node_name);
546 if (device && strcmp(device, blockdev->value->node_name)) {
547 continue;
550 if (blockdev != blockdev_list) {
551 monitor_printf(mon, "\n");
554 print_block_info(mon, NULL, blockdev->value, verbose);
556 qapi_free_BlockDeviceInfoList(blockdev_list);
559 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
561 BlockStatsList *stats_list, *stats;
563 stats_list = qmp_query_blockstats(false, false, NULL);
565 for (stats = stats_list; stats; stats = stats->next) {
566 if (!stats->value->has_device) {
567 continue;
570 monitor_printf(mon, "%s:", stats->value->device);
571 monitor_printf(mon, " rd_bytes=%" PRId64
572 " wr_bytes=%" PRId64
573 " rd_operations=%" PRId64
574 " wr_operations=%" PRId64
575 " flush_operations=%" PRId64
576 " wr_total_time_ns=%" PRId64
577 " rd_total_time_ns=%" PRId64
578 " flush_total_time_ns=%" PRId64
579 " rd_merged=%" PRId64
580 " wr_merged=%" PRId64
581 " idle_time_ns=%" PRId64
582 "\n",
583 stats->value->stats->rd_bytes,
584 stats->value->stats->wr_bytes,
585 stats->value->stats->rd_operations,
586 stats->value->stats->wr_operations,
587 stats->value->stats->flush_operations,
588 stats->value->stats->wr_total_time_ns,
589 stats->value->stats->rd_total_time_ns,
590 stats->value->stats->flush_total_time_ns,
591 stats->value->stats->rd_merged,
592 stats->value->stats->wr_merged,
593 stats->value->stats->idle_time_ns);
596 qapi_free_BlockStatsList(stats_list);
599 /* Helper for hmp_info_vnc_clients, _servers */
600 static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
601 const char *name)
603 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
604 name,
605 info->host,
606 info->service,
607 NetworkAddressFamily_str(info->family),
608 info->websocket ? " (Websocket)" : "");
611 /* Helper displaying and auth and crypt info */
612 static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
613 VncPrimaryAuth auth,
614 VncVencryptSubAuth *vencrypt)
616 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
617 VncPrimaryAuth_str(auth),
618 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
621 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
623 while (client) {
624 VncClientInfo *cinfo = client->value;
626 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
627 monitor_printf(mon, " x509_dname: %s\n",
628 cinfo->has_x509_dname ?
629 cinfo->x509_dname : "none");
630 monitor_printf(mon, " sasl_username: %s\n",
631 cinfo->has_sasl_username ?
632 cinfo->sasl_username : "none");
634 client = client->next;
638 static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
640 while (server) {
641 VncServerInfo2 *sinfo = server->value;
642 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
643 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
644 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
645 server = server->next;
649 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
651 VncInfo2List *info2l;
652 Error *err = NULL;
654 info2l = qmp_query_vnc_servers(&err);
655 if (err) {
656 hmp_handle_error(mon, &err);
657 return;
659 if (!info2l) {
660 monitor_printf(mon, "None\n");
661 return;
664 while (info2l) {
665 VncInfo2 *info = info2l->value;
666 monitor_printf(mon, "%s:\n", info->id);
667 hmp_info_vnc_servers(mon, info->server);
668 hmp_info_vnc_clients(mon, info->clients);
669 if (!info->server) {
670 /* The server entry displays its auth, we only
671 * need to display in the case of 'reverse' connections
672 * where there's no server.
674 hmp_info_vnc_authcrypt(mon, " ", info->auth,
675 info->has_vencrypt ? &info->vencrypt : NULL);
677 if (info->has_display) {
678 monitor_printf(mon, " Display: %s\n", info->display);
680 info2l = info2l->next;
683 qapi_free_VncInfo2List(info2l);
687 #ifdef CONFIG_SPICE
688 void hmp_info_spice(Monitor *mon, const QDict *qdict)
690 SpiceChannelList *chan;
691 SpiceInfo *info;
692 const char *channel_name;
693 const char * const channel_names[] = {
694 [SPICE_CHANNEL_MAIN] = "main",
695 [SPICE_CHANNEL_DISPLAY] = "display",
696 [SPICE_CHANNEL_INPUTS] = "inputs",
697 [SPICE_CHANNEL_CURSOR] = "cursor",
698 [SPICE_CHANNEL_PLAYBACK] = "playback",
699 [SPICE_CHANNEL_RECORD] = "record",
700 [SPICE_CHANNEL_TUNNEL] = "tunnel",
701 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
702 [SPICE_CHANNEL_USBREDIR] = "usbredir",
703 [SPICE_CHANNEL_PORT] = "port",
704 #if 0
705 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
706 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
707 * as quick fix for build failures with older versions. */
708 [SPICE_CHANNEL_WEBDAV] = "webdav",
709 #endif
712 info = qmp_query_spice(NULL);
714 if (!info->enabled) {
715 monitor_printf(mon, "Server: disabled\n");
716 goto out;
719 monitor_printf(mon, "Server:\n");
720 if (info->has_port) {
721 monitor_printf(mon, " address: %s:%" PRId64 "\n",
722 info->host, info->port);
724 if (info->has_tls_port) {
725 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
726 info->host, info->tls_port);
728 monitor_printf(mon, " migrated: %s\n",
729 info->migrated ? "true" : "false");
730 monitor_printf(mon, " auth: %s\n", info->auth);
731 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
732 monitor_printf(mon, " mouse-mode: %s\n",
733 SpiceQueryMouseMode_str(info->mouse_mode));
735 if (!info->has_channels || info->channels == NULL) {
736 monitor_printf(mon, "Channels: none\n");
737 } else {
738 for (chan = info->channels; chan; chan = chan->next) {
739 monitor_printf(mon, "Channel:\n");
740 monitor_printf(mon, " address: %s:%s%s\n",
741 chan->value->host, chan->value->port,
742 chan->value->tls ? " [tls]" : "");
743 monitor_printf(mon, " session: %" PRId64 "\n",
744 chan->value->connection_id);
745 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
746 chan->value->channel_type, chan->value->channel_id);
748 channel_name = "unknown";
749 if (chan->value->channel_type > 0 &&
750 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
751 channel_names[chan->value->channel_type]) {
752 channel_name = channel_names[chan->value->channel_type];
755 monitor_printf(mon, " channel name: %s\n", channel_name);
759 out:
760 qapi_free_SpiceInfo(info);
762 #endif
764 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
766 BalloonInfo *info;
767 Error *err = NULL;
769 info = qmp_query_balloon(&err);
770 if (err) {
771 hmp_handle_error(mon, &err);
772 return;
775 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
777 qapi_free_BalloonInfo(info);
780 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
782 PciMemoryRegionList *region;
784 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
785 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
786 dev->slot, dev->function);
787 monitor_printf(mon, " ");
789 if (dev->class_info->has_desc) {
790 monitor_printf(mon, "%s", dev->class_info->desc);
791 } else {
792 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
795 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
796 dev->id->vendor, dev->id->device);
798 if (dev->has_irq) {
799 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
802 if (dev->has_pci_bridge) {
803 monitor_printf(mon, " BUS %" PRId64 ".\n",
804 dev->pci_bridge->bus->number);
805 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
806 dev->pci_bridge->bus->secondary);
807 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
808 dev->pci_bridge->bus->subordinate);
810 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
811 dev->pci_bridge->bus->io_range->base,
812 dev->pci_bridge->bus->io_range->limit);
814 monitor_printf(mon,
815 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
816 dev->pci_bridge->bus->memory_range->base,
817 dev->pci_bridge->bus->memory_range->limit);
819 monitor_printf(mon, " prefetchable memory range "
820 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
821 dev->pci_bridge->bus->prefetchable_range->base,
822 dev->pci_bridge->bus->prefetchable_range->limit);
825 for (region = dev->regions; region; region = region->next) {
826 uint64_t addr, size;
828 addr = region->value->address;
829 size = region->value->size;
831 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
833 if (!strcmp(region->value->type, "io")) {
834 monitor_printf(mon, "I/O at 0x%04" PRIx64
835 " [0x%04" PRIx64 "].\n",
836 addr, addr + size - 1);
837 } else {
838 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
839 " [0x%08" PRIx64 "].\n",
840 region->value->mem_type_64 ? 64 : 32,
841 region->value->prefetch ? " prefetchable" : "",
842 addr, addr + size - 1);
846 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
848 if (dev->has_pci_bridge) {
849 if (dev->pci_bridge->has_devices) {
850 PciDeviceInfoList *cdev;
851 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
852 hmp_info_pci_device(mon, cdev->value);
858 static int hmp_info_irq_foreach(Object *obj, void *opaque)
860 InterruptStatsProvider *intc;
861 InterruptStatsProviderClass *k;
862 Monitor *mon = opaque;
864 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
865 intc = INTERRUPT_STATS_PROVIDER(obj);
866 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
867 uint64_t *irq_counts;
868 unsigned int nb_irqs, i;
869 if (k->get_statistics &&
870 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
871 if (nb_irqs > 0) {
872 monitor_printf(mon, "IRQ statistics for %s:\n",
873 object_get_typename(obj));
874 for (i = 0; i < nb_irqs; i++) {
875 if (irq_counts[i] > 0) {
876 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
877 irq_counts[i]);
881 } else {
882 monitor_printf(mon, "IRQ statistics not available for %s.\n",
883 object_get_typename(obj));
887 return 0;
890 void hmp_info_irq(Monitor *mon, const QDict *qdict)
892 object_child_foreach_recursive(object_get_root(),
893 hmp_info_irq_foreach, mon);
896 static int hmp_info_pic_foreach(Object *obj, void *opaque)
898 InterruptStatsProvider *intc;
899 InterruptStatsProviderClass *k;
900 Monitor *mon = opaque;
902 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
903 intc = INTERRUPT_STATS_PROVIDER(obj);
904 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
905 if (k->print_info) {
906 k->print_info(intc, mon);
907 } else {
908 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
909 object_get_typename(obj));
913 return 0;
916 void hmp_info_pic(Monitor *mon, const QDict *qdict)
918 object_child_foreach_recursive(object_get_root(),
919 hmp_info_pic_foreach, mon);
922 void hmp_info_pci(Monitor *mon, const QDict *qdict)
924 PciInfoList *info_list, *info;
925 Error *err = NULL;
927 info_list = qmp_query_pci(&err);
928 if (err) {
929 monitor_printf(mon, "PCI devices not supported\n");
930 error_free(err);
931 return;
934 for (info = info_list; info; info = info->next) {
935 PciDeviceInfoList *dev;
937 for (dev = info->value->devices; dev; dev = dev->next) {
938 hmp_info_pci_device(mon, dev->value);
942 qapi_free_PciInfoList(info_list);
945 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
947 BlockJobInfoList *list;
948 Error *err = NULL;
950 list = qmp_query_block_jobs(&err);
951 assert(!err);
953 if (!list) {
954 monitor_printf(mon, "No active jobs\n");
955 return;
958 while (list) {
959 if (strcmp(list->value->type, "stream") == 0) {
960 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
961 " of %" PRId64 " bytes, speed limit %" PRId64
962 " bytes/s\n",
963 list->value->device,
964 list->value->offset,
965 list->value->len,
966 list->value->speed);
967 } else {
968 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
969 " of %" PRId64 " bytes, speed limit %" PRId64
970 " bytes/s\n",
971 list->value->type,
972 list->value->device,
973 list->value->offset,
974 list->value->len,
975 list->value->speed);
977 list = list->next;
980 qapi_free_BlockJobInfoList(list);
983 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
985 TPMInfoList *info_list, *info;
986 Error *err = NULL;
987 unsigned int c = 0;
988 TPMPassthroughOptions *tpo;
989 TPMEmulatorOptions *teo;
991 info_list = qmp_query_tpm(&err);
992 if (err) {
993 monitor_printf(mon, "TPM device not supported\n");
994 error_free(err);
995 return;
998 if (info_list) {
999 monitor_printf(mon, "TPM device:\n");
1002 for (info = info_list; info; info = info->next) {
1003 TPMInfo *ti = info->value;
1004 monitor_printf(mon, " tpm%d: model=%s\n",
1005 c, TpmModel_str(ti->model));
1007 monitor_printf(mon, " \\ %s: type=%s",
1008 ti->id, TpmTypeOptionsKind_str(ti->options->type));
1010 switch (ti->options->type) {
1011 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
1012 tpo = ti->options->u.passthrough.data;
1013 monitor_printf(mon, "%s%s%s%s",
1014 tpo->has_path ? ",path=" : "",
1015 tpo->has_path ? tpo->path : "",
1016 tpo->has_cancel_path ? ",cancel-path=" : "",
1017 tpo->has_cancel_path ? tpo->cancel_path : "");
1018 break;
1019 case TPM_TYPE_OPTIONS_KIND_EMULATOR:
1020 teo = ti->options->u.emulator.data;
1021 monitor_printf(mon, ",chardev=%s", teo->chardev);
1022 break;
1023 case TPM_TYPE_OPTIONS_KIND__MAX:
1024 break;
1026 monitor_printf(mon, "\n");
1027 c++;
1029 qapi_free_TPMInfoList(info_list);
1032 void hmp_quit(Monitor *mon, const QDict *qdict)
1034 monitor_suspend(mon);
1035 qmp_quit(NULL);
1038 void hmp_stop(Monitor *mon, const QDict *qdict)
1040 qmp_stop(NULL);
1043 void hmp_system_reset(Monitor *mon, const QDict *qdict)
1045 qmp_system_reset(NULL);
1048 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
1050 qmp_system_powerdown(NULL);
1053 void hmp_cpu(Monitor *mon, const QDict *qdict)
1055 int64_t cpu_index;
1057 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1058 use it are converted to the QAPI */
1059 cpu_index = qdict_get_int(qdict, "index");
1060 if (monitor_set_cpu(cpu_index) < 0) {
1061 monitor_printf(mon, "invalid CPU index\n");
1065 void hmp_memsave(Monitor *mon, const QDict *qdict)
1067 uint32_t size = qdict_get_int(qdict, "size");
1068 const char *filename = qdict_get_str(qdict, "filename");
1069 uint64_t addr = qdict_get_int(qdict, "val");
1070 Error *err = NULL;
1071 int cpu_index = monitor_get_cpu_index();
1073 if (cpu_index < 0) {
1074 monitor_printf(mon, "No CPU available\n");
1075 return;
1078 qmp_memsave(addr, size, filename, true, cpu_index, &err);
1079 hmp_handle_error(mon, &err);
1082 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1084 uint32_t size = qdict_get_int(qdict, "size");
1085 const char *filename = qdict_get_str(qdict, "filename");
1086 uint64_t addr = qdict_get_int(qdict, "val");
1087 Error *err = NULL;
1089 qmp_pmemsave(addr, size, filename, &err);
1090 hmp_handle_error(mon, &err);
1093 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1095 const char *chardev = qdict_get_str(qdict, "device");
1096 const char *data = qdict_get_str(qdict, "data");
1097 Error *err = NULL;
1099 qmp_ringbuf_write(chardev, data, false, 0, &err);
1101 hmp_handle_error(mon, &err);
1104 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
1106 uint32_t size = qdict_get_int(qdict, "size");
1107 const char *chardev = qdict_get_str(qdict, "device");
1108 char *data;
1109 Error *err = NULL;
1110 int i;
1112 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1113 if (err) {
1114 hmp_handle_error(mon, &err);
1115 return;
1118 for (i = 0; data[i]; i++) {
1119 unsigned char ch = data[i];
1121 if (ch == '\\') {
1122 monitor_printf(mon, "\\\\");
1123 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1124 monitor_printf(mon, "\\u%04X", ch);
1125 } else {
1126 monitor_printf(mon, "%c", ch);
1130 monitor_printf(mon, "\n");
1131 g_free(data);
1134 void hmp_cont(Monitor *mon, const QDict *qdict)
1136 Error *err = NULL;
1138 qmp_cont(&err);
1139 hmp_handle_error(mon, &err);
1142 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1144 qmp_system_wakeup(NULL);
1147 void hmp_nmi(Monitor *mon, const QDict *qdict)
1149 Error *err = NULL;
1151 qmp_inject_nmi(&err);
1152 hmp_handle_error(mon, &err);
1155 void hmp_set_link(Monitor *mon, const QDict *qdict)
1157 const char *name = qdict_get_str(qdict, "name");
1158 bool up = qdict_get_bool(qdict, "up");
1159 Error *err = NULL;
1161 qmp_set_link(name, up, &err);
1162 hmp_handle_error(mon, &err);
1165 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1167 const char *device = qdict_get_str(qdict, "device");
1168 const char *password = qdict_get_str(qdict, "password");
1169 Error *err = NULL;
1171 qmp_block_passwd(true, device, false, NULL, password, &err);
1172 hmp_handle_error(mon, &err);
1175 void hmp_balloon(Monitor *mon, const QDict *qdict)
1177 int64_t value = qdict_get_int(qdict, "value");
1178 Error *err = NULL;
1180 qmp_balloon(value, &err);
1181 hmp_handle_error(mon, &err);
1184 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1186 const char *device = qdict_get_str(qdict, "device");
1187 int64_t size = qdict_get_int(qdict, "size");
1188 Error *err = NULL;
1190 qmp_block_resize(true, device, false, NULL, size, &err);
1191 hmp_handle_error(mon, &err);
1194 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1196 const char *filename = qdict_get_str(qdict, "target");
1197 const char *format = qdict_get_try_str(qdict, "format");
1198 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1199 bool full = qdict_get_try_bool(qdict, "full", false);
1200 Error *err = NULL;
1201 DriveMirror mirror = {
1202 .device = (char *)qdict_get_str(qdict, "device"),
1203 .target = (char *)filename,
1204 .has_format = !!format,
1205 .format = (char *)format,
1206 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1207 .has_mode = true,
1208 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1209 .unmap = true,
1212 if (!filename) {
1213 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1214 hmp_handle_error(mon, &err);
1215 return;
1217 qmp_drive_mirror(&mirror, &err);
1218 hmp_handle_error(mon, &err);
1221 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1223 const char *device = qdict_get_str(qdict, "device");
1224 const char *filename = qdict_get_str(qdict, "target");
1225 const char *format = qdict_get_try_str(qdict, "format");
1226 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1227 bool full = qdict_get_try_bool(qdict, "full", false);
1228 bool compress = qdict_get_try_bool(qdict, "compress", false);
1229 Error *err = NULL;
1230 DriveBackup backup = {
1231 .device = (char *)device,
1232 .target = (char *)filename,
1233 .has_format = !!format,
1234 .format = (char *)format,
1235 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1236 .has_mode = true,
1237 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1238 .has_compress = !!compress,
1239 .compress = compress,
1242 if (!filename) {
1243 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1244 hmp_handle_error(mon, &err);
1245 return;
1248 qmp_drive_backup(&backup, &err);
1249 hmp_handle_error(mon, &err);
1252 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1254 const char *device = qdict_get_str(qdict, "device");
1255 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1256 const char *format = qdict_get_try_str(qdict, "format");
1257 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1258 enum NewImageMode mode;
1259 Error *err = NULL;
1261 if (!filename) {
1262 /* In the future, if 'snapshot-file' is not specified, the snapshot
1263 will be taken internally. Today it's actually required. */
1264 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1265 hmp_handle_error(mon, &err);
1266 return;
1269 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1270 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1271 filename, false, NULL,
1272 !!format, format,
1273 true, mode, &err);
1274 hmp_handle_error(mon, &err);
1277 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1279 const char *device = qdict_get_str(qdict, "device");
1280 const char *name = qdict_get_str(qdict, "name");
1281 Error *err = NULL;
1283 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1284 hmp_handle_error(mon, &err);
1287 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1289 const char *device = qdict_get_str(qdict, "device");
1290 const char *name = qdict_get_str(qdict, "name");
1291 const char *id = qdict_get_try_str(qdict, "id");
1292 Error *err = NULL;
1294 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1295 true, name, &err);
1296 hmp_handle_error(mon, &err);
1299 void hmp_loadvm(Monitor *mon, const QDict *qdict)
1301 int saved_vm_running = runstate_is_running();
1302 const char *name = qdict_get_str(qdict, "name");
1303 Error *err = NULL;
1305 vm_stop(RUN_STATE_RESTORE_VM);
1307 if (load_snapshot(name, &err) == 0 && saved_vm_running) {
1308 vm_start();
1310 hmp_handle_error(mon, &err);
1313 void hmp_savevm(Monitor *mon, const QDict *qdict)
1315 Error *err = NULL;
1317 save_snapshot(qdict_get_try_str(qdict, "name"), &err);
1318 hmp_handle_error(mon, &err);
1321 void hmp_delvm(Monitor *mon, const QDict *qdict)
1323 BlockDriverState *bs;
1324 Error *err;
1325 const char *name = qdict_get_str(qdict, "name");
1327 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
1328 error_reportf_err(err,
1329 "Error while deleting snapshot on device '%s': ",
1330 bdrv_get_device_name(bs));
1334 void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
1336 BlockDriverState *bs, *bs1;
1337 BdrvNextIterator it1;
1338 QEMUSnapshotInfo *sn_tab, *sn;
1339 bool no_snapshot = true;
1340 int nb_sns, i;
1341 int total;
1342 int *global_snapshots;
1343 AioContext *aio_context;
1345 typedef struct SnapshotEntry {
1346 QEMUSnapshotInfo sn;
1347 QTAILQ_ENTRY(SnapshotEntry) next;
1348 } SnapshotEntry;
1350 typedef struct ImageEntry {
1351 const char *imagename;
1352 QTAILQ_ENTRY(ImageEntry) next;
1353 QTAILQ_HEAD(, SnapshotEntry) snapshots;
1354 } ImageEntry;
1356 QTAILQ_HEAD(, ImageEntry) image_list =
1357 QTAILQ_HEAD_INITIALIZER(image_list);
1359 ImageEntry *image_entry, *next_ie;
1360 SnapshotEntry *snapshot_entry;
1362 bs = bdrv_all_find_vmstate_bs();
1363 if (!bs) {
1364 monitor_printf(mon, "No available block device supports snapshots\n");
1365 return;
1367 aio_context = bdrv_get_aio_context(bs);
1369 aio_context_acquire(aio_context);
1370 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
1371 aio_context_release(aio_context);
1373 if (nb_sns < 0) {
1374 monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
1375 return;
1378 for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) {
1379 int bs1_nb_sns = 0;
1380 ImageEntry *ie;
1381 SnapshotEntry *se;
1382 AioContext *ctx = bdrv_get_aio_context(bs1);
1384 aio_context_acquire(ctx);
1385 if (bdrv_can_snapshot(bs1)) {
1386 sn = NULL;
1387 bs1_nb_sns = bdrv_snapshot_list(bs1, &sn);
1388 if (bs1_nb_sns > 0) {
1389 no_snapshot = false;
1390 ie = g_new0(ImageEntry, 1);
1391 ie->imagename = bdrv_get_device_name(bs1);
1392 QTAILQ_INIT(&ie->snapshots);
1393 QTAILQ_INSERT_TAIL(&image_list, ie, next);
1394 for (i = 0; i < bs1_nb_sns; i++) {
1395 se = g_new0(SnapshotEntry, 1);
1396 se->sn = sn[i];
1397 QTAILQ_INSERT_TAIL(&ie->snapshots, se, next);
1400 g_free(sn);
1402 aio_context_release(ctx);
1405 if (no_snapshot) {
1406 monitor_printf(mon, "There is no snapshot available.\n");
1407 return;
1410 global_snapshots = g_new0(int, nb_sns);
1411 total = 0;
1412 for (i = 0; i < nb_sns; i++) {
1413 SnapshotEntry *next_sn;
1414 if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) {
1415 global_snapshots[total] = i;
1416 total++;
1417 QTAILQ_FOREACH(image_entry, &image_list, next) {
1418 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots,
1419 next, next_sn) {
1420 if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) {
1421 QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry,
1422 next);
1423 g_free(snapshot_entry);
1430 monitor_printf(mon, "List of snapshots present on all disks:\n");
1432 if (total > 0) {
1433 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1434 monitor_printf(mon, "\n");
1435 for (i = 0; i < total; i++) {
1436 sn = &sn_tab[global_snapshots[i]];
1437 /* The ID is not guaranteed to be the same on all images, so
1438 * overwrite it.
1440 pstrcpy(sn->id_str, sizeof(sn->id_str), "--");
1441 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, sn);
1442 monitor_printf(mon, "\n");
1444 } else {
1445 monitor_printf(mon, "None\n");
1448 QTAILQ_FOREACH(image_entry, &image_list, next) {
1449 if (QTAILQ_EMPTY(&image_entry->snapshots)) {
1450 continue;
1452 monitor_printf(mon,
1453 "\nList of partial (non-loadable) snapshots on '%s':\n",
1454 image_entry->imagename);
1455 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1456 monitor_printf(mon, "\n");
1457 QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) {
1458 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon,
1459 &snapshot_entry->sn);
1460 monitor_printf(mon, "\n");
1464 QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) {
1465 SnapshotEntry *next_sn;
1466 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next,
1467 next_sn) {
1468 g_free(snapshot_entry);
1470 g_free(image_entry);
1472 g_free(sn_tab);
1473 g_free(global_snapshots);
1477 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1479 qmp_migrate_cancel(NULL);
1482 void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1484 Error *err = NULL;
1485 const char *state = qdict_get_str(qdict, "state");
1486 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1488 if (val >= 0) {
1489 qmp_migrate_continue(val, &err);
1492 hmp_handle_error(mon, &err);
1495 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1497 Error *err = NULL;
1498 const char *uri = qdict_get_str(qdict, "uri");
1500 qmp_migrate_incoming(uri, &err);
1502 hmp_handle_error(mon, &err);
1505 /* Kept for backwards compatibility */
1506 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1508 double value = qdict_get_double(qdict, "value");
1509 qmp_migrate_set_downtime(value, NULL);
1512 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1514 int64_t value = qdict_get_int(qdict, "value");
1515 Error *err = NULL;
1517 qmp_migrate_set_cache_size(value, &err);
1518 hmp_handle_error(mon, &err);
1521 /* Kept for backwards compatibility */
1522 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1524 int64_t value = qdict_get_int(qdict, "value");
1525 qmp_migrate_set_speed(value, NULL);
1528 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1530 const char *cap = qdict_get_str(qdict, "capability");
1531 bool state = qdict_get_bool(qdict, "state");
1532 Error *err = NULL;
1533 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1534 int val;
1536 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
1537 if (val < 0) {
1538 goto end;
1541 caps->value = g_malloc0(sizeof(*caps->value));
1542 caps->value->capability = val;
1543 caps->value->state = state;
1544 caps->next = NULL;
1545 qmp_migrate_set_capabilities(caps, &err);
1547 end:
1548 qapi_free_MigrationCapabilityStatusList(caps);
1549 hmp_handle_error(mon, &err);
1552 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1554 const char *param = qdict_get_str(qdict, "parameter");
1555 const char *valuestr = qdict_get_str(qdict, "value");
1556 Visitor *v = string_input_visitor_new(valuestr);
1557 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
1558 uint64_t valuebw = 0;
1559 uint64_t cache_size;
1560 Error *err = NULL;
1561 int val, ret;
1563 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
1564 if (val < 0) {
1565 goto cleanup;
1568 switch (val) {
1569 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1570 p->has_compress_level = true;
1571 visit_type_int(v, param, &p->compress_level, &err);
1572 break;
1573 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1574 p->has_compress_threads = true;
1575 visit_type_int(v, param, &p->compress_threads, &err);
1576 break;
1577 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1578 p->has_decompress_threads = true;
1579 visit_type_int(v, param, &p->decompress_threads, &err);
1580 break;
1581 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1582 p->has_cpu_throttle_initial = true;
1583 visit_type_int(v, param, &p->cpu_throttle_initial, &err);
1584 break;
1585 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1586 p->has_cpu_throttle_increment = true;
1587 visit_type_int(v, param, &p->cpu_throttle_increment, &err);
1588 break;
1589 case MIGRATION_PARAMETER_TLS_CREDS:
1590 p->has_tls_creds = true;
1591 p->tls_creds = g_new0(StrOrNull, 1);
1592 p->tls_creds->type = QTYPE_QSTRING;
1593 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1594 break;
1595 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1596 p->has_tls_hostname = true;
1597 p->tls_hostname = g_new0(StrOrNull, 1);
1598 p->tls_hostname->type = QTYPE_QSTRING;
1599 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1600 break;
1601 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1602 p->has_max_bandwidth = true;
1604 * Can't use visit_type_size() here, because it
1605 * defaults to Bytes rather than Mebibytes.
1607 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1608 if (ret < 0 || valuebw > INT64_MAX
1609 || (size_t)valuebw != valuebw) {
1610 error_setg(&err, "Invalid size %s", valuestr);
1611 break;
1613 p->max_bandwidth = valuebw;
1614 break;
1615 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1616 p->has_downtime_limit = true;
1617 visit_type_int(v, param, &p->downtime_limit, &err);
1618 break;
1619 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1620 p->has_x_checkpoint_delay = true;
1621 visit_type_int(v, param, &p->x_checkpoint_delay, &err);
1622 break;
1623 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1624 p->has_block_incremental = true;
1625 visit_type_bool(v, param, &p->block_incremental, &err);
1626 break;
1627 case MIGRATION_PARAMETER_X_MULTIFD_CHANNELS:
1628 p->has_x_multifd_channels = true;
1629 visit_type_int(v, param, &p->x_multifd_channels, &err);
1630 break;
1631 case MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT:
1632 p->has_x_multifd_page_count = true;
1633 visit_type_int(v, param, &p->x_multifd_page_count, &err);
1634 break;
1635 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1636 p->has_xbzrle_cache_size = true;
1637 visit_type_size(v, param, &cache_size, &err);
1638 if (err || cache_size > INT64_MAX
1639 || (size_t)cache_size != cache_size) {
1640 error_setg(&err, "Invalid size %s", valuestr);
1641 break;
1643 p->xbzrle_cache_size = cache_size;
1644 break;
1645 default:
1646 assert(0);
1649 if (err) {
1650 goto cleanup;
1653 qmp_migrate_set_parameters(p, &err);
1655 cleanup:
1656 qapi_free_MigrateSetParameters(p);
1657 visit_free(v);
1658 hmp_handle_error(mon, &err);
1661 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1663 Error *err = NULL;
1664 const char *protocol = qdict_get_str(qdict, "protocol");
1665 const char *hostname = qdict_get_str(qdict, "hostname");
1666 bool has_port = qdict_haskey(qdict, "port");
1667 int port = qdict_get_try_int(qdict, "port", -1);
1668 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1669 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1670 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1672 qmp_client_migrate_info(protocol, hostname,
1673 has_port, port, has_tls_port, tls_port,
1674 !!cert_subject, cert_subject, &err);
1675 hmp_handle_error(mon, &err);
1678 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1680 Error *err = NULL;
1681 qmp_migrate_start_postcopy(&err);
1682 hmp_handle_error(mon, &err);
1685 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1687 Error *err = NULL;
1689 qmp_x_colo_lost_heartbeat(&err);
1690 hmp_handle_error(mon, &err);
1693 void hmp_set_password(Monitor *mon, const QDict *qdict)
1695 const char *protocol = qdict_get_str(qdict, "protocol");
1696 const char *password = qdict_get_str(qdict, "password");
1697 const char *connected = qdict_get_try_str(qdict, "connected");
1698 Error *err = NULL;
1700 qmp_set_password(protocol, password, !!connected, connected, &err);
1701 hmp_handle_error(mon, &err);
1704 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1706 const char *protocol = qdict_get_str(qdict, "protocol");
1707 const char *whenstr = qdict_get_str(qdict, "time");
1708 Error *err = NULL;
1710 qmp_expire_password(protocol, whenstr, &err);
1711 hmp_handle_error(mon, &err);
1714 void hmp_eject(Monitor *mon, const QDict *qdict)
1716 bool force = qdict_get_try_bool(qdict, "force", false);
1717 const char *device = qdict_get_str(qdict, "device");
1718 Error *err = NULL;
1720 qmp_eject(true, device, false, NULL, true, force, &err);
1721 hmp_handle_error(mon, &err);
1724 static void hmp_change_read_arg(void *opaque, const char *password,
1725 void *readline_opaque)
1727 qmp_change_vnc_password(password, NULL);
1728 monitor_read_command(opaque, 1);
1731 void hmp_change(Monitor *mon, const QDict *qdict)
1733 const char *device = qdict_get_str(qdict, "device");
1734 const char *target = qdict_get_str(qdict, "target");
1735 const char *arg = qdict_get_try_str(qdict, "arg");
1736 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1737 BlockdevChangeReadOnlyMode read_only_mode = 0;
1738 Error *err = NULL;
1740 if (strcmp(device, "vnc") == 0) {
1741 if (read_only) {
1742 monitor_printf(mon,
1743 "Parameter 'read-only-mode' is invalid for VNC\n");
1744 return;
1746 if (strcmp(target, "passwd") == 0 ||
1747 strcmp(target, "password") == 0) {
1748 if (!arg) {
1749 monitor_read_password(mon, hmp_change_read_arg, NULL);
1750 return;
1753 qmp_change("vnc", target, !!arg, arg, &err);
1754 } else {
1755 if (read_only) {
1756 read_only_mode =
1757 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
1758 read_only,
1759 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1760 if (err) {
1761 hmp_handle_error(mon, &err);
1762 return;
1766 qmp_blockdev_change_medium(true, device, false, NULL, target,
1767 !!arg, arg, !!read_only, read_only_mode,
1768 &err);
1771 hmp_handle_error(mon, &err);
1774 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1776 Error *err = NULL;
1777 BlockIOThrottle throttle = {
1778 .has_device = true,
1779 .device = (char *) qdict_get_str(qdict, "device"),
1780 .bps = qdict_get_int(qdict, "bps"),
1781 .bps_rd = qdict_get_int(qdict, "bps_rd"),
1782 .bps_wr = qdict_get_int(qdict, "bps_wr"),
1783 .iops = qdict_get_int(qdict, "iops"),
1784 .iops_rd = qdict_get_int(qdict, "iops_rd"),
1785 .iops_wr = qdict_get_int(qdict, "iops_wr"),
1788 qmp_block_set_io_throttle(&throttle, &err);
1789 hmp_handle_error(mon, &err);
1792 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1794 Error *error = NULL;
1795 const char *device = qdict_get_str(qdict, "device");
1796 const char *base = qdict_get_try_str(qdict, "base");
1797 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1799 qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
1800 false, NULL, qdict_haskey(qdict, "speed"), speed,
1801 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1803 hmp_handle_error(mon, &error);
1806 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1808 Error *error = NULL;
1809 const char *device = qdict_get_str(qdict, "device");
1810 int64_t value = qdict_get_int(qdict, "speed");
1812 qmp_block_job_set_speed(device, value, &error);
1814 hmp_handle_error(mon, &error);
1817 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1819 Error *error = NULL;
1820 const char *device = qdict_get_str(qdict, "device");
1821 bool force = qdict_get_try_bool(qdict, "force", false);
1823 qmp_block_job_cancel(device, true, force, &error);
1825 hmp_handle_error(mon, &error);
1828 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1830 Error *error = NULL;
1831 const char *device = qdict_get_str(qdict, "device");
1833 qmp_block_job_pause(device, &error);
1835 hmp_handle_error(mon, &error);
1838 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1840 Error *error = NULL;
1841 const char *device = qdict_get_str(qdict, "device");
1843 qmp_block_job_resume(device, &error);
1845 hmp_handle_error(mon, &error);
1848 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1850 Error *error = NULL;
1851 const char *device = qdict_get_str(qdict, "device");
1853 qmp_block_job_complete(device, &error);
1855 hmp_handle_error(mon, &error);
1858 typedef struct HMPMigrationStatus
1860 QEMUTimer *timer;
1861 Monitor *mon;
1862 bool is_block_migration;
1863 } HMPMigrationStatus;
1865 static void hmp_migrate_status_cb(void *opaque)
1867 HMPMigrationStatus *status = opaque;
1868 MigrationInfo *info;
1870 info = qmp_query_migrate(NULL);
1871 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1872 info->status == MIGRATION_STATUS_SETUP) {
1873 if (info->has_disk) {
1874 int progress;
1876 if (info->disk->remaining) {
1877 progress = info->disk->transferred * 100 / info->disk->total;
1878 } else {
1879 progress = 100;
1882 monitor_printf(status->mon, "Completed %d %%\r", progress);
1883 monitor_flush(status->mon);
1886 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1887 } else {
1888 if (status->is_block_migration) {
1889 monitor_printf(status->mon, "\n");
1891 if (info->has_error_desc) {
1892 error_report("%s", info->error_desc);
1894 monitor_resume(status->mon);
1895 timer_del(status->timer);
1896 g_free(status);
1899 qapi_free_MigrationInfo(info);
1902 void hmp_migrate(Monitor *mon, const QDict *qdict)
1904 bool detach = qdict_get_try_bool(qdict, "detach", false);
1905 bool blk = qdict_get_try_bool(qdict, "blk", false);
1906 bool inc = qdict_get_try_bool(qdict, "inc", false);
1907 const char *uri = qdict_get_str(qdict, "uri");
1908 Error *err = NULL;
1910 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1911 if (err) {
1912 hmp_handle_error(mon, &err);
1913 return;
1916 if (!detach) {
1917 HMPMigrationStatus *status;
1919 if (monitor_suspend(mon) < 0) {
1920 monitor_printf(mon, "terminal does not allow synchronous "
1921 "migration, continuing detached\n");
1922 return;
1925 status = g_malloc0(sizeof(*status));
1926 status->mon = mon;
1927 status->is_block_migration = blk || inc;
1928 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1929 status);
1930 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1934 void hmp_device_add(Monitor *mon, const QDict *qdict)
1936 Error *err = NULL;
1938 qmp_device_add((QDict *)qdict, NULL, &err);
1939 hmp_handle_error(mon, &err);
1942 void hmp_device_del(Monitor *mon, const QDict *qdict)
1944 const char *id = qdict_get_str(qdict, "id");
1945 Error *err = NULL;
1947 qmp_device_del(id, &err);
1948 hmp_handle_error(mon, &err);
1951 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1953 Error *err = NULL;
1954 bool paging = qdict_get_try_bool(qdict, "paging", false);
1955 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
1956 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
1957 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
1958 const char *file = qdict_get_str(qdict, "filename");
1959 bool has_begin = qdict_haskey(qdict, "begin");
1960 bool has_length = qdict_haskey(qdict, "length");
1961 bool has_detach = qdict_haskey(qdict, "detach");
1962 int64_t begin = 0;
1963 int64_t length = 0;
1964 bool detach = false;
1965 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1966 char *prot;
1968 if (zlib + lzo + snappy > 1) {
1969 error_setg(&err, "only one of '-z|-l|-s' can be set");
1970 hmp_handle_error(mon, &err);
1971 return;
1974 if (zlib) {
1975 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1978 if (lzo) {
1979 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1982 if (snappy) {
1983 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1986 if (has_begin) {
1987 begin = qdict_get_int(qdict, "begin");
1989 if (has_length) {
1990 length = qdict_get_int(qdict, "length");
1992 if (has_detach) {
1993 detach = qdict_get_bool(qdict, "detach");
1996 prot = g_strconcat("file:", file, NULL);
1998 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
1999 has_length, length, true, dump_format, &err);
2000 hmp_handle_error(mon, &err);
2001 g_free(prot);
2004 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
2006 Error *err = NULL;
2007 QemuOpts *opts;
2009 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
2010 if (err) {
2011 goto out;
2014 netdev_add(opts, &err);
2015 if (err) {
2016 qemu_opts_del(opts);
2019 out:
2020 hmp_handle_error(mon, &err);
2023 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
2025 const char *id = qdict_get_str(qdict, "id");
2026 Error *err = NULL;
2028 qmp_netdev_del(id, &err);
2029 hmp_handle_error(mon, &err);
2032 void hmp_object_add(Monitor *mon, const QDict *qdict)
2034 Error *err = NULL;
2035 QemuOpts *opts;
2036 Object *obj = NULL;
2038 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
2039 if (err) {
2040 hmp_handle_error(mon, &err);
2041 return;
2044 obj = user_creatable_add_opts(opts, &err);
2045 qemu_opts_del(opts);
2047 if (err) {
2048 hmp_handle_error(mon, &err);
2050 if (obj) {
2051 object_unref(obj);
2055 void hmp_getfd(Monitor *mon, const QDict *qdict)
2057 const char *fdname = qdict_get_str(qdict, "fdname");
2058 Error *err = NULL;
2060 qmp_getfd(fdname, &err);
2061 hmp_handle_error(mon, &err);
2064 void hmp_closefd(Monitor *mon, const QDict *qdict)
2066 const char *fdname = qdict_get_str(qdict, "fdname");
2067 Error *err = NULL;
2069 qmp_closefd(fdname, &err);
2070 hmp_handle_error(mon, &err);
2073 void hmp_sendkey(Monitor *mon, const QDict *qdict)
2075 const char *keys = qdict_get_str(qdict, "keys");
2076 KeyValueList *keylist, *head = NULL, *tmp = NULL;
2077 int has_hold_time = qdict_haskey(qdict, "hold-time");
2078 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
2079 Error *err = NULL;
2080 char *separator;
2081 int keyname_len;
2083 while (1) {
2084 separator = strchr(keys, '-');
2085 keyname_len = separator ? separator - keys : strlen(keys);
2087 /* Be compatible with old interface, convert user inputted "<" */
2088 if (keys[0] == '<' && keyname_len == 1) {
2089 keys = "less";
2090 keyname_len = 4;
2093 keylist = g_malloc0(sizeof(*keylist));
2094 keylist->value = g_malloc0(sizeof(*keylist->value));
2096 if (!head) {
2097 head = keylist;
2099 if (tmp) {
2100 tmp->next = keylist;
2102 tmp = keylist;
2104 if (strstart(keys, "0x", NULL)) {
2105 char *endp;
2106 int value = strtoul(keys, &endp, 0);
2107 assert(endp <= keys + keyname_len);
2108 if (endp != keys + keyname_len) {
2109 goto err_out;
2111 keylist->value->type = KEY_VALUE_KIND_NUMBER;
2112 keylist->value->u.number.data = value;
2113 } else {
2114 int idx = index_from_key(keys, keyname_len);
2115 if (idx == Q_KEY_CODE__MAX) {
2116 goto err_out;
2118 keylist->value->type = KEY_VALUE_KIND_QCODE;
2119 keylist->value->u.qcode.data = idx;
2122 if (!separator) {
2123 break;
2125 keys = separator + 1;
2128 qmp_send_key(head, has_hold_time, hold_time, &err);
2129 hmp_handle_error(mon, &err);
2131 out:
2132 qapi_free_KeyValueList(head);
2133 return;
2135 err_out:
2136 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
2137 goto out;
2140 void hmp_screendump(Monitor *mon, const QDict *qdict)
2142 const char *filename = qdict_get_str(qdict, "filename");
2143 const char *id = qdict_get_try_str(qdict, "device");
2144 int64_t head = qdict_get_try_int(qdict, "head", 0);
2145 Error *err = NULL;
2147 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
2148 hmp_handle_error(mon, &err);
2151 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
2153 const char *uri = qdict_get_str(qdict, "uri");
2154 bool writable = qdict_get_try_bool(qdict, "writable", false);
2155 bool all = qdict_get_try_bool(qdict, "all", false);
2156 Error *local_err = NULL;
2157 BlockInfoList *block_list, *info;
2158 SocketAddress *addr;
2160 if (writable && !all) {
2161 error_setg(&local_err, "-w only valid together with -a");
2162 goto exit;
2165 /* First check if the address is valid and start the server. */
2166 addr = socket_parse(uri, &local_err);
2167 if (local_err != NULL) {
2168 goto exit;
2171 nbd_server_start(addr, NULL, &local_err);
2172 qapi_free_SocketAddress(addr);
2173 if (local_err != NULL) {
2174 goto exit;
2177 if (!all) {
2178 return;
2181 /* Then try adding all block devices. If one fails, close all and
2182 * exit.
2184 block_list = qmp_query_block(NULL);
2186 for (info = block_list; info; info = info->next) {
2187 if (!info->value->has_inserted) {
2188 continue;
2191 qmp_nbd_server_add(info->value->device, false, NULL,
2192 true, writable, &local_err);
2194 if (local_err != NULL) {
2195 qmp_nbd_server_stop(NULL);
2196 break;
2200 qapi_free_BlockInfoList(block_list);
2202 exit:
2203 hmp_handle_error(mon, &local_err);
2206 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
2208 const char *device = qdict_get_str(qdict, "device");
2209 const char *name = qdict_get_try_str(qdict, "name");
2210 bool writable = qdict_get_try_bool(qdict, "writable", false);
2211 Error *local_err = NULL;
2213 qmp_nbd_server_add(device, !!name, name, true, writable, &local_err);
2214 hmp_handle_error(mon, &local_err);
2217 void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict)
2219 const char *name = qdict_get_str(qdict, "name");
2220 bool force = qdict_get_try_bool(qdict, "force", false);
2221 Error *err = NULL;
2223 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
2224 qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err);
2225 hmp_handle_error(mon, &err);
2228 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
2230 Error *err = NULL;
2232 qmp_nbd_server_stop(&err);
2233 hmp_handle_error(mon, &err);
2236 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
2238 int cpuid;
2239 Error *err = NULL;
2241 cpuid = qdict_get_int(qdict, "id");
2242 qmp_cpu_add(cpuid, &err);
2243 hmp_handle_error(mon, &err);
2246 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2248 const char *args = qdict_get_str(qdict, "args");
2249 Error *err = NULL;
2250 QemuOpts *opts;
2252 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
2253 if (opts == NULL) {
2254 error_setg(&err, "Parsing chardev args failed");
2255 } else {
2256 qemu_chr_new_from_opts(opts, &err);
2257 qemu_opts_del(opts);
2259 hmp_handle_error(mon, &err);
2262 void hmp_chardev_change(Monitor *mon, const QDict *qdict)
2264 const char *args = qdict_get_str(qdict, "args");
2265 const char *id;
2266 Error *err = NULL;
2267 ChardevBackend *backend = NULL;
2268 ChardevReturn *ret = NULL;
2269 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
2270 true);
2271 if (!opts) {
2272 error_setg(&err, "Parsing chardev args failed");
2273 goto end;
2276 id = qdict_get_str(qdict, "id");
2277 if (qemu_opts_id(opts)) {
2278 error_setg(&err, "Unexpected 'id' parameter");
2279 goto end;
2282 backend = qemu_chr_parse_opts(opts, &err);
2283 if (!backend) {
2284 goto end;
2287 ret = qmp_chardev_change(id, backend, &err);
2289 end:
2290 qapi_free_ChardevReturn(ret);
2291 qapi_free_ChardevBackend(backend);
2292 qemu_opts_del(opts);
2293 hmp_handle_error(mon, &err);
2296 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2298 Error *local_err = NULL;
2300 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
2301 hmp_handle_error(mon, &local_err);
2304 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
2306 Error *local_err = NULL;
2308 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
2309 hmp_handle_error(mon, &local_err);
2312 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
2314 BlockBackend *blk;
2315 BlockBackend *local_blk = NULL;
2316 const char* device = qdict_get_str(qdict, "device");
2317 const char* command = qdict_get_str(qdict, "command");
2318 Error *err = NULL;
2319 int ret;
2321 blk = blk_by_name(device);
2322 if (!blk) {
2323 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
2324 if (bs) {
2325 blk = local_blk = blk_new(0, BLK_PERM_ALL);
2326 ret = blk_insert_bs(blk, bs, &err);
2327 if (ret < 0) {
2328 goto fail;
2330 } else {
2331 goto fail;
2336 * Notably absent: Proper permission management. This is sad, but it seems
2337 * almost impossible to achieve without changing the semantics and thereby
2338 * limiting the use cases of the qemu-io HMP command.
2340 * In an ideal world we would unconditionally create a new BlockBackend for
2341 * qemuio_command(), but we have commands like 'reopen' and want them to
2342 * take effect on the exact BlockBackend whose name the user passed instead
2343 * of just on a temporary copy of it.
2345 * Another problem is that deleting the temporary BlockBackend involves
2346 * draining all requests on it first, but some qemu-iotests cases want to
2347 * issue multiple aio_read/write requests and expect them to complete in
2348 * the background while the monitor has already returned.
2350 * This is also what prevents us from saving the original permissions and
2351 * restoring them later: We can't revoke permissions until all requests
2352 * have completed, and we don't know when that is nor can we really let
2353 * anything else run before we have revoken them to avoid race conditions.
2355 * What happens now is that command() in qemu-io-cmds.c can extend the
2356 * permissions if necessary for the qemu-io command. And they simply stay
2357 * extended, possibly resulting in a read-only guest device keeping write
2358 * permissions. Ugly, but it appears to be the lesser evil.
2360 qemuio_command(blk, command);
2362 fail:
2363 blk_unref(local_blk);
2364 hmp_handle_error(mon, &err);
2367 void hmp_object_del(Monitor *mon, const QDict *qdict)
2369 const char *id = qdict_get_str(qdict, "id");
2370 Error *err = NULL;
2372 user_creatable_del(id, &err);
2373 hmp_handle_error(mon, &err);
2376 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
2378 Error *err = NULL;
2379 MemdevList *memdev_list = qmp_query_memdev(&err);
2380 MemdevList *m = memdev_list;
2381 Visitor *v;
2382 char *str;
2384 while (m) {
2385 v = string_output_visitor_new(false, &str);
2386 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
2387 monitor_printf(mon, "memory backend: %s\n", m->value->id);
2388 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
2389 monitor_printf(mon, " merge: %s\n",
2390 m->value->merge ? "true" : "false");
2391 monitor_printf(mon, " dump: %s\n",
2392 m->value->dump ? "true" : "false");
2393 monitor_printf(mon, " prealloc: %s\n",
2394 m->value->prealloc ? "true" : "false");
2395 monitor_printf(mon, " policy: %s\n",
2396 HostMemPolicy_str(m->value->policy));
2397 visit_complete(v, &str);
2398 monitor_printf(mon, " host nodes: %s\n", str);
2400 g_free(str);
2401 visit_free(v);
2402 m = m->next;
2405 monitor_printf(mon, "\n");
2407 qapi_free_MemdevList(memdev_list);
2408 hmp_handle_error(mon, &err);
2411 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2413 Error *err = NULL;
2414 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2415 MemoryDeviceInfoList *info;
2416 MemoryDeviceInfo *value;
2417 PCDIMMDeviceInfo *di;
2419 for (info = info_list; info; info = info->next) {
2420 value = info->value;
2422 if (value) {
2423 switch (value->type) {
2424 case MEMORY_DEVICE_INFO_KIND_DIMM:
2425 di = value->u.dimm.data;
2427 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2428 MemoryDeviceInfoKind_str(value->type),
2429 di->id ? di->id : "");
2430 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2431 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2432 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2433 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2434 monitor_printf(mon, " memdev: %s\n", di->memdev);
2435 monitor_printf(mon, " hotplugged: %s\n",
2436 di->hotplugged ? "true" : "false");
2437 monitor_printf(mon, " hotpluggable: %s\n",
2438 di->hotpluggable ? "true" : "false");
2439 break;
2440 default:
2441 break;
2446 qapi_free_MemoryDeviceInfoList(info_list);
2447 hmp_handle_error(mon, &err);
2450 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2452 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2453 IOThreadInfoList *info;
2454 IOThreadInfo *value;
2456 for (info = info_list; info; info = info->next) {
2457 value = info->value;
2458 monitor_printf(mon, "%s:\n", value->id);
2459 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
2460 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2461 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
2462 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
2465 qapi_free_IOThreadInfoList(info_list);
2468 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2470 const char *path = qdict_get_try_str(qdict, "path");
2471 ObjectPropertyInfoList *list;
2472 Error *err = NULL;
2474 if (path == NULL) {
2475 monitor_printf(mon, "/\n");
2476 return;
2479 list = qmp_qom_list(path, &err);
2480 if (err == NULL) {
2481 ObjectPropertyInfoList *start = list;
2482 while (list != NULL) {
2483 ObjectPropertyInfo *value = list->value;
2485 monitor_printf(mon, "%s (%s)\n",
2486 value->name, value->type);
2487 list = list->next;
2489 qapi_free_ObjectPropertyInfoList(start);
2491 hmp_handle_error(mon, &err);
2494 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2496 const char *path = qdict_get_str(qdict, "path");
2497 const char *property = qdict_get_str(qdict, "property");
2498 const char *value = qdict_get_str(qdict, "value");
2499 Error *err = NULL;
2500 bool ambiguous = false;
2501 Object *obj;
2503 obj = object_resolve_path(path, &ambiguous);
2504 if (obj == NULL) {
2505 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2506 "Device '%s' not found", path);
2507 } else {
2508 if (ambiguous) {
2509 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2511 object_property_parse(obj, value, property, &err);
2513 hmp_handle_error(mon, &err);
2516 void hmp_rocker(Monitor *mon, const QDict *qdict)
2518 const char *name = qdict_get_str(qdict, "name");
2519 RockerSwitch *rocker;
2520 Error *err = NULL;
2522 rocker = qmp_query_rocker(name, &err);
2523 if (err != NULL) {
2524 hmp_handle_error(mon, &err);
2525 return;
2528 monitor_printf(mon, "name: %s\n", rocker->name);
2529 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2530 monitor_printf(mon, "ports: %d\n", rocker->ports);
2532 qapi_free_RockerSwitch(rocker);
2535 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2537 RockerPortList *list, *port;
2538 const char *name = qdict_get_str(qdict, "name");
2539 Error *err = NULL;
2541 list = qmp_query_rocker_ports(name, &err);
2542 if (err != NULL) {
2543 hmp_handle_error(mon, &err);
2544 return;
2547 monitor_printf(mon, " ena/ speed/ auto\n");
2548 monitor_printf(mon, " port link duplex neg?\n");
2550 for (port = list; port; port = port->next) {
2551 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2552 port->value->name,
2553 port->value->enabled ? port->value->link_up ?
2554 "up" : "down" : "!ena",
2555 port->value->speed == 10000 ? "10G" : "??",
2556 port->value->duplex ? "FD" : "HD",
2557 port->value->autoneg ? "Yes" : "No");
2560 qapi_free_RockerPortList(list);
2563 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2565 RockerOfDpaFlowList *list, *info;
2566 const char *name = qdict_get_str(qdict, "name");
2567 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2568 Error *err = NULL;
2570 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2571 if (err != NULL) {
2572 hmp_handle_error(mon, &err);
2573 return;
2576 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2578 for (info = list; info; info = info->next) {
2579 RockerOfDpaFlow *flow = info->value;
2580 RockerOfDpaFlowKey *key = flow->key;
2581 RockerOfDpaFlowMask *mask = flow->mask;
2582 RockerOfDpaFlowAction *action = flow->action;
2584 if (flow->hits) {
2585 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2586 key->priority, key->tbl_id, flow->hits);
2587 } else {
2588 monitor_printf(mon, "%-4d %-3d ",
2589 key->priority, key->tbl_id);
2592 if (key->has_in_pport) {
2593 monitor_printf(mon, " pport %d", key->in_pport);
2594 if (mask->has_in_pport) {
2595 monitor_printf(mon, "(0x%x)", mask->in_pport);
2599 if (key->has_vlan_id) {
2600 monitor_printf(mon, " vlan %d",
2601 key->vlan_id & VLAN_VID_MASK);
2602 if (mask->has_vlan_id) {
2603 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2607 if (key->has_tunnel_id) {
2608 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2609 if (mask->has_tunnel_id) {
2610 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2614 if (key->has_eth_type) {
2615 switch (key->eth_type) {
2616 case 0x0806:
2617 monitor_printf(mon, " ARP");
2618 break;
2619 case 0x0800:
2620 monitor_printf(mon, " IP");
2621 break;
2622 case 0x86dd:
2623 monitor_printf(mon, " IPv6");
2624 break;
2625 case 0x8809:
2626 monitor_printf(mon, " LACP");
2627 break;
2628 case 0x88cc:
2629 monitor_printf(mon, " LLDP");
2630 break;
2631 default:
2632 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2633 break;
2637 if (key->has_eth_src) {
2638 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2639 (mask->has_eth_src) &&
2640 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2641 monitor_printf(mon, " src <any mcast/bcast>");
2642 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2643 (mask->has_eth_src) &&
2644 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2645 monitor_printf(mon, " src <any ucast>");
2646 } else {
2647 monitor_printf(mon, " src %s", key->eth_src);
2648 if (mask->has_eth_src) {
2649 monitor_printf(mon, "(%s)", mask->eth_src);
2654 if (key->has_eth_dst) {
2655 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2656 (mask->has_eth_dst) &&
2657 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2658 monitor_printf(mon, " dst <any mcast/bcast>");
2659 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2660 (mask->has_eth_dst) &&
2661 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2662 monitor_printf(mon, " dst <any ucast>");
2663 } else {
2664 monitor_printf(mon, " dst %s", key->eth_dst);
2665 if (mask->has_eth_dst) {
2666 monitor_printf(mon, "(%s)", mask->eth_dst);
2671 if (key->has_ip_proto) {
2672 monitor_printf(mon, " proto %d", key->ip_proto);
2673 if (mask->has_ip_proto) {
2674 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2678 if (key->has_ip_tos) {
2679 monitor_printf(mon, " TOS %d", key->ip_tos);
2680 if (mask->has_ip_tos) {
2681 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2685 if (key->has_ip_dst) {
2686 monitor_printf(mon, " dst %s", key->ip_dst);
2689 if (action->has_goto_tbl || action->has_group_id ||
2690 action->has_new_vlan_id) {
2691 monitor_printf(mon, " -->");
2694 if (action->has_new_vlan_id) {
2695 monitor_printf(mon, " apply new vlan %d",
2696 ntohs(action->new_vlan_id));
2699 if (action->has_group_id) {
2700 monitor_printf(mon, " write group 0x%08x", action->group_id);
2703 if (action->has_goto_tbl) {
2704 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2707 monitor_printf(mon, "\n");
2710 qapi_free_RockerOfDpaFlowList(list);
2713 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2715 RockerOfDpaGroupList *list, *g;
2716 const char *name = qdict_get_str(qdict, "name");
2717 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2718 Error *err = NULL;
2719 bool set = false;
2721 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2722 if (err != NULL) {
2723 hmp_handle_error(mon, &err);
2724 return;
2727 monitor_printf(mon, "id (decode) --> buckets\n");
2729 for (g = list; g; g = g->next) {
2730 RockerOfDpaGroup *group = g->value;
2732 monitor_printf(mon, "0x%08x", group->id);
2734 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2735 group->type == 1 ? "L2 rewrite" :
2736 group->type == 2 ? "L3 unicast" :
2737 group->type == 3 ? "L2 multicast" :
2738 group->type == 4 ? "L2 flood" :
2739 group->type == 5 ? "L3 interface" :
2740 group->type == 6 ? "L3 multicast" :
2741 group->type == 7 ? "L3 ECMP" :
2742 group->type == 8 ? "L2 overlay" :
2743 "unknown");
2745 if (group->has_vlan_id) {
2746 monitor_printf(mon, " vlan %d", group->vlan_id);
2749 if (group->has_pport) {
2750 monitor_printf(mon, " pport %d", group->pport);
2753 if (group->has_index) {
2754 monitor_printf(mon, " index %d", group->index);
2757 monitor_printf(mon, ") -->");
2759 if (group->has_set_vlan_id && group->set_vlan_id) {
2760 set = true;
2761 monitor_printf(mon, " set vlan %d",
2762 group->set_vlan_id & VLAN_VID_MASK);
2765 if (group->has_set_eth_src) {
2766 if (!set) {
2767 set = true;
2768 monitor_printf(mon, " set");
2770 monitor_printf(mon, " src %s", group->set_eth_src);
2773 if (group->has_set_eth_dst) {
2774 if (!set) {
2775 set = true;
2776 monitor_printf(mon, " set");
2778 monitor_printf(mon, " dst %s", group->set_eth_dst);
2781 set = false;
2783 if (group->has_ttl_check && group->ttl_check) {
2784 monitor_printf(mon, " check TTL");
2787 if (group->has_group_id && group->group_id) {
2788 monitor_printf(mon, " group id 0x%08x", group->group_id);
2791 if (group->has_pop_vlan && group->pop_vlan) {
2792 monitor_printf(mon, " pop vlan");
2795 if (group->has_out_pport) {
2796 monitor_printf(mon, " out pport %d", group->out_pport);
2799 if (group->has_group_ids) {
2800 struct uint32List *id;
2802 monitor_printf(mon, " groups [");
2803 for (id = group->group_ids; id; id = id->next) {
2804 monitor_printf(mon, "0x%08x", id->value);
2805 if (id->next) {
2806 monitor_printf(mon, ",");
2809 monitor_printf(mon, "]");
2812 monitor_printf(mon, "\n");
2815 qapi_free_RockerOfDpaGroupList(list);
2818 void hmp_info_dump(Monitor *mon, const QDict *qdict)
2820 DumpQueryResult *result = qmp_query_dump(NULL);
2822 assert(result && result->status < DUMP_STATUS__MAX);
2823 monitor_printf(mon, "Status: %s\n", DumpStatus_str(result->status));
2825 if (result->status == DUMP_STATUS_ACTIVE) {
2826 float percent = 0;
2827 assert(result->total != 0);
2828 percent = 100.0 * result->completed / result->total;
2829 monitor_printf(mon, "Finished: %.2f %%\n", percent);
2832 qapi_free_DumpQueryResult(result);
2835 void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
2837 ram_block_dump(mon);
2840 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
2842 Error *err = NULL;
2843 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
2844 HotpluggableCPUList *saved = l;
2845 CpuInstanceProperties *c;
2847 if (err != NULL) {
2848 hmp_handle_error(mon, &err);
2849 return;
2852 monitor_printf(mon, "Hotpluggable CPUs:\n");
2853 while (l) {
2854 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
2855 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
2856 l->value->vcpus_count);
2857 if (l->value->has_qom_path) {
2858 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
2861 c = l->value->props;
2862 monitor_printf(mon, " CPUInstance Properties:\n");
2863 if (c->has_node_id) {
2864 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
2866 if (c->has_socket_id) {
2867 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
2869 if (c->has_core_id) {
2870 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
2872 if (c->has_thread_id) {
2873 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
2876 l = l->next;
2879 qapi_free_HotpluggableCPUList(saved);
2882 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
2884 Error *err = NULL;
2885 GuidInfo *info = qmp_query_vm_generation_id(&err);
2886 if (info) {
2887 monitor_printf(mon, "%s\n", info->guid);
2889 hmp_handle_error(mon, &err);
2890 qapi_free_GuidInfo(info);
2893 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
2895 Error *err = NULL;
2896 MemoryInfo *info = qmp_query_memory_size_summary(&err);
2897 if (info) {
2898 monitor_printf(mon, "base memory: %" PRIu64 "\n",
2899 info->base_memory);
2901 if (info->has_plugged_memory) {
2902 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
2903 info->plugged_memory);
2906 qapi_free_MemoryInfo(info);
2908 hmp_handle_error(mon, &err);