block: Base permissions on rw state after reopen
[qemu/ar7.git] / hmp.c
blobace729d03f6288371c1bde78a042efd5997c0a1d
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/opts-visitor.h"
31 #include "qapi/qmp/qerror.h"
32 #include "qapi/string-input-visitor.h"
33 #include "qapi/string-output-visitor.h"
34 #include "qapi-visit.h"
35 #include "qom/object_interfaces.h"
36 #include "ui/console.h"
37 #include "block/nbd.h"
38 #include "block/qapi.h"
39 #include "qemu-io.h"
40 #include "qemu/cutils.h"
41 #include "qemu/error-report.h"
42 #include "exec/ramlist.h"
43 #include "hw/intc/intc.h"
44 #include "migration/snapshot.h"
45 #include "migration/misc.h"
47 #ifdef CONFIG_SPICE
48 #include <spice/enums.h>
49 #endif
51 static void hmp_handle_error(Monitor *mon, Error **errp)
53 assert(errp);
54 if (*errp) {
55 error_report_err(*errp);
59 void hmp_info_name(Monitor *mon, const QDict *qdict)
61 NameInfo *info;
63 info = qmp_query_name(NULL);
64 if (info->has_name) {
65 monitor_printf(mon, "%s\n", info->name);
67 qapi_free_NameInfo(info);
70 void hmp_info_version(Monitor *mon, const QDict *qdict)
72 VersionInfo *info;
74 info = qmp_query_version(NULL);
76 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
77 info->qemu->major, info->qemu->minor, info->qemu->micro,
78 info->package);
80 qapi_free_VersionInfo(info);
83 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
85 KvmInfo *info;
87 info = qmp_query_kvm(NULL);
88 monitor_printf(mon, "kvm support: ");
89 if (info->present) {
90 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
91 } else {
92 monitor_printf(mon, "not compiled\n");
95 qapi_free_KvmInfo(info);
98 void hmp_info_status(Monitor *mon, const QDict *qdict)
100 StatusInfo *info;
102 info = qmp_query_status(NULL);
104 monitor_printf(mon, "VM status: %s%s",
105 info->running ? "running" : "paused",
106 info->singlestep ? " (single step mode)" : "");
108 if (!info->running && info->status != RUN_STATE_PAUSED) {
109 monitor_printf(mon, " (%s)", RunState_str(info->status));
112 monitor_printf(mon, "\n");
114 qapi_free_StatusInfo(info);
117 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
119 UuidInfo *info;
121 info = qmp_query_uuid(NULL);
122 monitor_printf(mon, "%s\n", info->UUID);
123 qapi_free_UuidInfo(info);
126 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
128 ChardevInfoList *char_info, *info;
130 char_info = qmp_query_chardev(NULL);
131 for (info = char_info; info; info = info->next) {
132 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
133 info->value->filename);
136 qapi_free_ChardevInfoList(char_info);
139 void hmp_info_mice(Monitor *mon, const QDict *qdict)
141 MouseInfoList *mice_list, *mouse;
143 mice_list = qmp_query_mice(NULL);
144 if (!mice_list) {
145 monitor_printf(mon, "No mouse devices connected\n");
146 return;
149 for (mouse = mice_list; mouse; mouse = mouse->next) {
150 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
151 mouse->value->current ? '*' : ' ',
152 mouse->value->index, mouse->value->name,
153 mouse->value->absolute ? " (absolute)" : "");
156 qapi_free_MouseInfoList(mice_list);
159 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
161 MigrationInfo *info;
162 MigrationCapabilityStatusList *caps, *cap;
164 info = qmp_query_migrate(NULL);
165 caps = qmp_query_migrate_capabilities(NULL);
167 migration_global_dump(mon);
169 /* do not display parameters during setup */
170 if (info->has_status && caps) {
171 monitor_printf(mon, "capabilities: ");
172 for (cap = caps; cap; cap = cap->next) {
173 monitor_printf(mon, "%s: %s ",
174 MigrationCapability_str(cap->value->capability),
175 cap->value->state ? "on" : "off");
177 monitor_printf(mon, "\n");
180 if (info->has_status) {
181 monitor_printf(mon, "Migration status: %s",
182 MigrationStatus_str(info->status));
183 if (info->status == MIGRATION_STATUS_FAILED &&
184 info->has_error_desc) {
185 monitor_printf(mon, " (%s)\n", info->error_desc);
186 } else {
187 monitor_printf(mon, "\n");
190 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
191 info->total_time);
192 if (info->has_expected_downtime) {
193 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
194 info->expected_downtime);
196 if (info->has_downtime) {
197 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
198 info->downtime);
200 if (info->has_setup_time) {
201 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
202 info->setup_time);
206 if (info->has_ram) {
207 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
208 info->ram->transferred >> 10);
209 monitor_printf(mon, "throughput: %0.2f mbps\n",
210 info->ram->mbps);
211 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
212 info->ram->remaining >> 10);
213 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
214 info->ram->total >> 10);
215 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
216 info->ram->duplicate);
217 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
218 info->ram->skipped);
219 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
220 info->ram->normal);
221 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
222 info->ram->normal_bytes >> 10);
223 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
224 info->ram->dirty_sync_count);
225 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
226 info->ram->page_size >> 10);
228 if (info->ram->dirty_pages_rate) {
229 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
230 info->ram->dirty_pages_rate);
232 if (info->ram->postcopy_requests) {
233 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
234 info->ram->postcopy_requests);
238 if (info->has_disk) {
239 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
240 info->disk->transferred >> 10);
241 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
242 info->disk->remaining >> 10);
243 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
244 info->disk->total >> 10);
247 if (info->has_xbzrle_cache) {
248 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
249 info->xbzrle_cache->cache_size);
250 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
251 info->xbzrle_cache->bytes >> 10);
252 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
253 info->xbzrle_cache->pages);
254 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
255 info->xbzrle_cache->cache_miss);
256 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
257 info->xbzrle_cache->cache_miss_rate);
258 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
259 info->xbzrle_cache->overflow);
262 if (info->has_cpu_throttle_percentage) {
263 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
264 info->cpu_throttle_percentage);
267 qapi_free_MigrationInfo(info);
268 qapi_free_MigrationCapabilityStatusList(caps);
271 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
273 MigrationCapabilityStatusList *caps, *cap;
275 caps = qmp_query_migrate_capabilities(NULL);
277 if (caps) {
278 for (cap = caps; cap; cap = cap->next) {
279 monitor_printf(mon, "%s: %s\n",
280 MigrationCapability_str(cap->value->capability),
281 cap->value->state ? "on" : "off");
285 qapi_free_MigrationCapabilityStatusList(caps);
288 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
290 MigrationParameters *params;
292 params = qmp_query_migrate_parameters(NULL);
294 if (params) {
295 assert(params->has_compress_level);
296 monitor_printf(mon, "%s: %" PRId64 "\n",
297 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
298 params->compress_level);
299 assert(params->has_compress_threads);
300 monitor_printf(mon, "%s: %" PRId64 "\n",
301 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
302 params->compress_threads);
303 assert(params->has_decompress_threads);
304 monitor_printf(mon, "%s: %" PRId64 "\n",
305 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
306 params->decompress_threads);
307 assert(params->has_cpu_throttle_initial);
308 monitor_printf(mon, "%s: %" PRId64 "\n",
309 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
310 params->cpu_throttle_initial);
311 assert(params->has_cpu_throttle_increment);
312 monitor_printf(mon, "%s: %" PRId64 "\n",
313 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
314 params->cpu_throttle_increment);
315 assert(params->has_tls_creds);
316 monitor_printf(mon, "%s: '%s'\n",
317 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
318 params->tls_creds);
319 assert(params->has_tls_hostname);
320 monitor_printf(mon, "%s: '%s'\n",
321 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
322 params->tls_hostname);
323 assert(params->has_max_bandwidth);
324 monitor_printf(mon, "%s: %" PRId64 " bytes/second\n",
325 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
326 params->max_bandwidth);
327 assert(params->has_downtime_limit);
328 monitor_printf(mon, "%s: %" PRId64 " milliseconds\n",
329 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
330 params->downtime_limit);
331 assert(params->has_x_checkpoint_delay);
332 monitor_printf(mon, "%s: %" PRId64 "\n",
333 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
334 params->x_checkpoint_delay);
335 assert(params->has_block_incremental);
336 monitor_printf(mon, "%s: %s\n",
337 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
338 params->block_incremental ? "on" : "off");
339 monitor_printf(mon, "%s: %" PRId64 "\n",
340 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_CHANNELS),
341 params->x_multifd_channels);
342 monitor_printf(mon, "%s: %" PRId64 "\n",
343 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT),
344 params->x_multifd_page_count);
347 qapi_free_MigrationParameters(params);
350 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
352 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
353 qmp_query_migrate_cache_size(NULL) >> 10);
356 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
358 CpuInfoList *cpu_list, *cpu;
360 cpu_list = qmp_query_cpus(NULL);
362 for (cpu = cpu_list; cpu; cpu = cpu->next) {
363 int active = ' ';
365 if (cpu->value->CPU == monitor_get_cpu_index()) {
366 active = '*';
369 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
371 switch (cpu->value->arch) {
372 case CPU_INFO_ARCH_X86:
373 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->u.x86.pc);
374 break;
375 case CPU_INFO_ARCH_PPC:
376 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->u.ppc.nip);
377 break;
378 case CPU_INFO_ARCH_SPARC:
379 monitor_printf(mon, " pc=0x%016" PRIx64,
380 cpu->value->u.q_sparc.pc);
381 monitor_printf(mon, " npc=0x%016" PRIx64,
382 cpu->value->u.q_sparc.npc);
383 break;
384 case CPU_INFO_ARCH_MIPS:
385 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.q_mips.PC);
386 break;
387 case CPU_INFO_ARCH_TRICORE:
388 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.tricore.PC);
389 break;
390 default:
391 break;
394 if (cpu->value->halted) {
395 monitor_printf(mon, " (halted)");
398 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
401 qapi_free_CpuInfoList(cpu_list);
404 static void print_block_info(Monitor *mon, BlockInfo *info,
405 BlockDeviceInfo *inserted, bool verbose)
407 ImageInfo *image_info;
409 assert(!info || !info->has_inserted || info->inserted == inserted);
411 if (info && *info->device) {
412 monitor_printf(mon, "%s", info->device);
413 if (inserted && inserted->has_node_name) {
414 monitor_printf(mon, " (%s)", inserted->node_name);
416 } else {
417 assert(info || inserted);
418 monitor_printf(mon, "%s",
419 inserted && inserted->has_node_name ? inserted->node_name
420 : info && info->has_qdev ? info->qdev
421 : "<anonymous>");
424 if (inserted) {
425 monitor_printf(mon, ": %s (%s%s%s)\n",
426 inserted->file,
427 inserted->drv,
428 inserted->ro ? ", read-only" : "",
429 inserted->encrypted ? ", encrypted" : "");
430 } else {
431 monitor_printf(mon, ": [not inserted]\n");
434 if (info) {
435 if (info->has_qdev) {
436 monitor_printf(mon, " Attached to: %s\n", info->qdev);
438 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
439 monitor_printf(mon, " I/O status: %s\n",
440 BlockDeviceIoStatus_str(info->io_status));
443 if (info->removable) {
444 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
445 info->locked ? "" : "not ",
446 info->tray_open ? "open" : "closed");
451 if (!inserted) {
452 return;
455 monitor_printf(mon, " Cache mode: %s%s%s\n",
456 inserted->cache->writeback ? "writeback" : "writethrough",
457 inserted->cache->direct ? ", direct" : "",
458 inserted->cache->no_flush ? ", ignore flushes" : "");
460 if (inserted->has_backing_file) {
461 monitor_printf(mon,
462 " Backing file: %s "
463 "(chain depth: %" PRId64 ")\n",
464 inserted->backing_file,
465 inserted->backing_file_depth);
468 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
469 monitor_printf(mon, " Detect zeroes: %s\n",
470 BlockdevDetectZeroesOptions_str(inserted->detect_zeroes));
473 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
474 inserted->iops || inserted->iops_rd || inserted->iops_wr)
476 monitor_printf(mon, " I/O throttling: bps=%" PRId64
477 " bps_rd=%" PRId64 " bps_wr=%" PRId64
478 " bps_max=%" PRId64
479 " bps_rd_max=%" PRId64
480 " bps_wr_max=%" PRId64
481 " iops=%" PRId64 " iops_rd=%" PRId64
482 " iops_wr=%" PRId64
483 " iops_max=%" PRId64
484 " iops_rd_max=%" PRId64
485 " iops_wr_max=%" PRId64
486 " iops_size=%" PRId64
487 " group=%s\n",
488 inserted->bps,
489 inserted->bps_rd,
490 inserted->bps_wr,
491 inserted->bps_max,
492 inserted->bps_rd_max,
493 inserted->bps_wr_max,
494 inserted->iops,
495 inserted->iops_rd,
496 inserted->iops_wr,
497 inserted->iops_max,
498 inserted->iops_rd_max,
499 inserted->iops_wr_max,
500 inserted->iops_size,
501 inserted->group);
504 if (verbose) {
505 monitor_printf(mon, "\nImages:\n");
506 image_info = inserted->image;
507 while (1) {
508 bdrv_image_info_dump((fprintf_function)monitor_printf,
509 mon, image_info);
510 if (image_info->has_backing_image) {
511 image_info = image_info->backing_image;
512 } else {
513 break;
519 void hmp_info_block(Monitor *mon, const QDict *qdict)
521 BlockInfoList *block_list, *info;
522 BlockDeviceInfoList *blockdev_list, *blockdev;
523 const char *device = qdict_get_try_str(qdict, "device");
524 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
525 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
526 bool printed = false;
528 /* Print BlockBackend information */
529 if (!nodes) {
530 block_list = qmp_query_block(NULL);
531 } else {
532 block_list = NULL;
535 for (info = block_list; info; info = info->next) {
536 if (device && strcmp(device, info->value->device)) {
537 continue;
540 if (info != block_list) {
541 monitor_printf(mon, "\n");
544 print_block_info(mon, info->value, info->value->has_inserted
545 ? info->value->inserted : NULL,
546 verbose);
547 printed = true;
550 qapi_free_BlockInfoList(block_list);
552 if ((!device && !nodes) || printed) {
553 return;
556 /* Print node information */
557 blockdev_list = qmp_query_named_block_nodes(NULL);
558 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
559 assert(blockdev->value->has_node_name);
560 if (device && strcmp(device, blockdev->value->node_name)) {
561 continue;
564 if (blockdev != blockdev_list) {
565 monitor_printf(mon, "\n");
568 print_block_info(mon, NULL, blockdev->value, verbose);
570 qapi_free_BlockDeviceInfoList(blockdev_list);
573 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
575 BlockStatsList *stats_list, *stats;
577 stats_list = qmp_query_blockstats(false, false, NULL);
579 for (stats = stats_list; stats; stats = stats->next) {
580 if (!stats->value->has_device) {
581 continue;
584 monitor_printf(mon, "%s:", stats->value->device);
585 monitor_printf(mon, " rd_bytes=%" PRId64
586 " wr_bytes=%" PRId64
587 " rd_operations=%" PRId64
588 " wr_operations=%" PRId64
589 " flush_operations=%" PRId64
590 " wr_total_time_ns=%" PRId64
591 " rd_total_time_ns=%" PRId64
592 " flush_total_time_ns=%" PRId64
593 " rd_merged=%" PRId64
594 " wr_merged=%" PRId64
595 " idle_time_ns=%" PRId64
596 "\n",
597 stats->value->stats->rd_bytes,
598 stats->value->stats->wr_bytes,
599 stats->value->stats->rd_operations,
600 stats->value->stats->wr_operations,
601 stats->value->stats->flush_operations,
602 stats->value->stats->wr_total_time_ns,
603 stats->value->stats->rd_total_time_ns,
604 stats->value->stats->flush_total_time_ns,
605 stats->value->stats->rd_merged,
606 stats->value->stats->wr_merged,
607 stats->value->stats->idle_time_ns);
610 qapi_free_BlockStatsList(stats_list);
613 /* Helper for hmp_info_vnc_clients, _servers */
614 static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
615 const char *name)
617 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
618 name,
619 info->host,
620 info->service,
621 NetworkAddressFamily_str(info->family),
622 info->websocket ? " (Websocket)" : "");
625 /* Helper displaying and auth and crypt info */
626 static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
627 VncPrimaryAuth auth,
628 VncVencryptSubAuth *vencrypt)
630 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
631 VncPrimaryAuth_str(auth),
632 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
635 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
637 while (client) {
638 VncClientInfo *cinfo = client->value;
640 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
641 monitor_printf(mon, " x509_dname: %s\n",
642 cinfo->has_x509_dname ?
643 cinfo->x509_dname : "none");
644 monitor_printf(mon, " sasl_username: %s\n",
645 cinfo->has_sasl_username ?
646 cinfo->sasl_username : "none");
648 client = client->next;
652 static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
654 while (server) {
655 VncServerInfo2 *sinfo = server->value;
656 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
657 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
658 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
659 server = server->next;
663 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
665 VncInfo2List *info2l;
666 Error *err = NULL;
668 info2l = qmp_query_vnc_servers(&err);
669 if (err) {
670 error_report_err(err);
671 return;
673 if (!info2l) {
674 monitor_printf(mon, "None\n");
675 return;
678 while (info2l) {
679 VncInfo2 *info = info2l->value;
680 monitor_printf(mon, "%s:\n", info->id);
681 hmp_info_vnc_servers(mon, info->server);
682 hmp_info_vnc_clients(mon, info->clients);
683 if (!info->server) {
684 /* The server entry displays its auth, we only
685 * need to display in the case of 'reverse' connections
686 * where there's no server.
688 hmp_info_vnc_authcrypt(mon, " ", info->auth,
689 info->has_vencrypt ? &info->vencrypt : NULL);
691 if (info->has_display) {
692 monitor_printf(mon, " Display: %s\n", info->display);
694 info2l = info2l->next;
697 qapi_free_VncInfo2List(info2l);
701 #ifdef CONFIG_SPICE
702 void hmp_info_spice(Monitor *mon, const QDict *qdict)
704 SpiceChannelList *chan;
705 SpiceInfo *info;
706 const char *channel_name;
707 const char * const channel_names[] = {
708 [SPICE_CHANNEL_MAIN] = "main",
709 [SPICE_CHANNEL_DISPLAY] = "display",
710 [SPICE_CHANNEL_INPUTS] = "inputs",
711 [SPICE_CHANNEL_CURSOR] = "cursor",
712 [SPICE_CHANNEL_PLAYBACK] = "playback",
713 [SPICE_CHANNEL_RECORD] = "record",
714 [SPICE_CHANNEL_TUNNEL] = "tunnel",
715 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
716 [SPICE_CHANNEL_USBREDIR] = "usbredir",
717 [SPICE_CHANNEL_PORT] = "port",
718 #if 0
719 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
720 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
721 * as quick fix for build failures with older versions. */
722 [SPICE_CHANNEL_WEBDAV] = "webdav",
723 #endif
726 info = qmp_query_spice(NULL);
728 if (!info->enabled) {
729 monitor_printf(mon, "Server: disabled\n");
730 goto out;
733 monitor_printf(mon, "Server:\n");
734 if (info->has_port) {
735 monitor_printf(mon, " address: %s:%" PRId64 "\n",
736 info->host, info->port);
738 if (info->has_tls_port) {
739 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
740 info->host, info->tls_port);
742 monitor_printf(mon, " migrated: %s\n",
743 info->migrated ? "true" : "false");
744 monitor_printf(mon, " auth: %s\n", info->auth);
745 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
746 monitor_printf(mon, " mouse-mode: %s\n",
747 SpiceQueryMouseMode_str(info->mouse_mode));
749 if (!info->has_channels || info->channels == NULL) {
750 monitor_printf(mon, "Channels: none\n");
751 } else {
752 for (chan = info->channels; chan; chan = chan->next) {
753 monitor_printf(mon, "Channel:\n");
754 monitor_printf(mon, " address: %s:%s%s\n",
755 chan->value->host, chan->value->port,
756 chan->value->tls ? " [tls]" : "");
757 monitor_printf(mon, " session: %" PRId64 "\n",
758 chan->value->connection_id);
759 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
760 chan->value->channel_type, chan->value->channel_id);
762 channel_name = "unknown";
763 if (chan->value->channel_type > 0 &&
764 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
765 channel_names[chan->value->channel_type]) {
766 channel_name = channel_names[chan->value->channel_type];
769 monitor_printf(mon, " channel name: %s\n", channel_name);
773 out:
774 qapi_free_SpiceInfo(info);
776 #endif
778 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
780 BalloonInfo *info;
781 Error *err = NULL;
783 info = qmp_query_balloon(&err);
784 if (err) {
785 error_report_err(err);
786 return;
789 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
791 qapi_free_BalloonInfo(info);
794 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
796 PciMemoryRegionList *region;
798 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
799 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
800 dev->slot, dev->function);
801 monitor_printf(mon, " ");
803 if (dev->class_info->has_desc) {
804 monitor_printf(mon, "%s", dev->class_info->desc);
805 } else {
806 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
809 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
810 dev->id->vendor, dev->id->device);
812 if (dev->has_irq) {
813 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
816 if (dev->has_pci_bridge) {
817 monitor_printf(mon, " BUS %" PRId64 ".\n",
818 dev->pci_bridge->bus->number);
819 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
820 dev->pci_bridge->bus->secondary);
821 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
822 dev->pci_bridge->bus->subordinate);
824 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
825 dev->pci_bridge->bus->io_range->base,
826 dev->pci_bridge->bus->io_range->limit);
828 monitor_printf(mon,
829 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
830 dev->pci_bridge->bus->memory_range->base,
831 dev->pci_bridge->bus->memory_range->limit);
833 monitor_printf(mon, " prefetchable memory range "
834 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
835 dev->pci_bridge->bus->prefetchable_range->base,
836 dev->pci_bridge->bus->prefetchable_range->limit);
839 for (region = dev->regions; region; region = region->next) {
840 uint64_t addr, size;
842 addr = region->value->address;
843 size = region->value->size;
845 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
847 if (!strcmp(region->value->type, "io")) {
848 monitor_printf(mon, "I/O at 0x%04" PRIx64
849 " [0x%04" PRIx64 "].\n",
850 addr, addr + size - 1);
851 } else {
852 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
853 " [0x%08" PRIx64 "].\n",
854 region->value->mem_type_64 ? 64 : 32,
855 region->value->prefetch ? " prefetchable" : "",
856 addr, addr + size - 1);
860 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
862 if (dev->has_pci_bridge) {
863 if (dev->pci_bridge->has_devices) {
864 PciDeviceInfoList *cdev;
865 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
866 hmp_info_pci_device(mon, cdev->value);
872 static int hmp_info_irq_foreach(Object *obj, void *opaque)
874 InterruptStatsProvider *intc;
875 InterruptStatsProviderClass *k;
876 Monitor *mon = opaque;
878 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
879 intc = INTERRUPT_STATS_PROVIDER(obj);
880 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
881 uint64_t *irq_counts;
882 unsigned int nb_irqs, i;
883 if (k->get_statistics &&
884 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
885 if (nb_irqs > 0) {
886 monitor_printf(mon, "IRQ statistics for %s:\n",
887 object_get_typename(obj));
888 for (i = 0; i < nb_irqs; i++) {
889 if (irq_counts[i] > 0) {
890 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
891 irq_counts[i]);
895 } else {
896 monitor_printf(mon, "IRQ statistics not available for %s.\n",
897 object_get_typename(obj));
901 return 0;
904 void hmp_info_irq(Monitor *mon, const QDict *qdict)
906 object_child_foreach_recursive(object_get_root(),
907 hmp_info_irq_foreach, mon);
910 static int hmp_info_pic_foreach(Object *obj, void *opaque)
912 InterruptStatsProvider *intc;
913 InterruptStatsProviderClass *k;
914 Monitor *mon = opaque;
916 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
917 intc = INTERRUPT_STATS_PROVIDER(obj);
918 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
919 if (k->print_info) {
920 k->print_info(intc, mon);
921 } else {
922 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
923 object_get_typename(obj));
927 return 0;
930 void hmp_info_pic(Monitor *mon, const QDict *qdict)
932 object_child_foreach_recursive(object_get_root(),
933 hmp_info_pic_foreach, mon);
936 void hmp_info_pci(Monitor *mon, const QDict *qdict)
938 PciInfoList *info_list, *info;
939 Error *err = NULL;
941 info_list = qmp_query_pci(&err);
942 if (err) {
943 monitor_printf(mon, "PCI devices not supported\n");
944 error_free(err);
945 return;
948 for (info = info_list; info; info = info->next) {
949 PciDeviceInfoList *dev;
951 for (dev = info->value->devices; dev; dev = dev->next) {
952 hmp_info_pci_device(mon, dev->value);
956 qapi_free_PciInfoList(info_list);
959 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
961 BlockJobInfoList *list;
962 Error *err = NULL;
964 list = qmp_query_block_jobs(&err);
965 assert(!err);
967 if (!list) {
968 monitor_printf(mon, "No active jobs\n");
969 return;
972 while (list) {
973 if (strcmp(list->value->type, "stream") == 0) {
974 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
975 " of %" PRId64 " bytes, speed limit %" PRId64
976 " bytes/s\n",
977 list->value->device,
978 list->value->offset,
979 list->value->len,
980 list->value->speed);
981 } else {
982 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
983 " of %" PRId64 " bytes, speed limit %" PRId64
984 " bytes/s\n",
985 list->value->type,
986 list->value->device,
987 list->value->offset,
988 list->value->len,
989 list->value->speed);
991 list = list->next;
994 qapi_free_BlockJobInfoList(list);
997 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
999 TPMInfoList *info_list, *info;
1000 Error *err = NULL;
1001 unsigned int c = 0;
1002 TPMPassthroughOptions *tpo;
1004 info_list = qmp_query_tpm(&err);
1005 if (err) {
1006 monitor_printf(mon, "TPM device not supported\n");
1007 error_free(err);
1008 return;
1011 if (info_list) {
1012 monitor_printf(mon, "TPM device:\n");
1015 for (info = info_list; info; info = info->next) {
1016 TPMInfo *ti = info->value;
1017 monitor_printf(mon, " tpm%d: model=%s\n",
1018 c, TpmModel_str(ti->model));
1020 monitor_printf(mon, " \\ %s: type=%s",
1021 ti->id, TpmTypeOptionsKind_str(ti->options->type));
1023 switch (ti->options->type) {
1024 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
1025 tpo = ti->options->u.passthrough.data;
1026 monitor_printf(mon, "%s%s%s%s",
1027 tpo->has_path ? ",path=" : "",
1028 tpo->has_path ? tpo->path : "",
1029 tpo->has_cancel_path ? ",cancel-path=" : "",
1030 tpo->has_cancel_path ? tpo->cancel_path : "");
1031 break;
1032 case TPM_TYPE_OPTIONS_KIND__MAX:
1033 break;
1035 monitor_printf(mon, "\n");
1036 c++;
1038 qapi_free_TPMInfoList(info_list);
1041 void hmp_quit(Monitor *mon, const QDict *qdict)
1043 monitor_suspend(mon);
1044 qmp_quit(NULL);
1047 void hmp_stop(Monitor *mon, const QDict *qdict)
1049 qmp_stop(NULL);
1052 void hmp_system_reset(Monitor *mon, const QDict *qdict)
1054 qmp_system_reset(NULL);
1057 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
1059 qmp_system_powerdown(NULL);
1062 void hmp_cpu(Monitor *mon, const QDict *qdict)
1064 int64_t cpu_index;
1066 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1067 use it are converted to the QAPI */
1068 cpu_index = qdict_get_int(qdict, "index");
1069 if (monitor_set_cpu(cpu_index) < 0) {
1070 monitor_printf(mon, "invalid CPU index\n");
1074 void hmp_memsave(Monitor *mon, const QDict *qdict)
1076 uint32_t size = qdict_get_int(qdict, "size");
1077 const char *filename = qdict_get_str(qdict, "filename");
1078 uint64_t addr = qdict_get_int(qdict, "val");
1079 Error *err = NULL;
1080 int cpu_index = monitor_get_cpu_index();
1082 if (cpu_index < 0) {
1083 monitor_printf(mon, "No CPU available\n");
1084 return;
1087 qmp_memsave(addr, size, filename, true, cpu_index, &err);
1088 hmp_handle_error(mon, &err);
1091 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1093 uint32_t size = qdict_get_int(qdict, "size");
1094 const char *filename = qdict_get_str(qdict, "filename");
1095 uint64_t addr = qdict_get_int(qdict, "val");
1096 Error *err = NULL;
1098 qmp_pmemsave(addr, size, filename, &err);
1099 hmp_handle_error(mon, &err);
1102 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1104 const char *chardev = qdict_get_str(qdict, "device");
1105 const char *data = qdict_get_str(qdict, "data");
1106 Error *err = NULL;
1108 qmp_ringbuf_write(chardev, data, false, 0, &err);
1110 hmp_handle_error(mon, &err);
1113 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
1115 uint32_t size = qdict_get_int(qdict, "size");
1116 const char *chardev = qdict_get_str(qdict, "device");
1117 char *data;
1118 Error *err = NULL;
1119 int i;
1121 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1122 if (err) {
1123 error_report_err(err);
1124 return;
1127 for (i = 0; data[i]; i++) {
1128 unsigned char ch = data[i];
1130 if (ch == '\\') {
1131 monitor_printf(mon, "\\\\");
1132 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1133 monitor_printf(mon, "\\u%04X", ch);
1134 } else {
1135 monitor_printf(mon, "%c", ch);
1139 monitor_printf(mon, "\n");
1140 g_free(data);
1143 void hmp_cont(Monitor *mon, const QDict *qdict)
1145 Error *err = NULL;
1147 qmp_cont(&err);
1148 hmp_handle_error(mon, &err);
1151 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1153 qmp_system_wakeup(NULL);
1156 void hmp_nmi(Monitor *mon, const QDict *qdict)
1158 Error *err = NULL;
1160 qmp_inject_nmi(&err);
1161 hmp_handle_error(mon, &err);
1164 void hmp_set_link(Monitor *mon, const QDict *qdict)
1166 const char *name = qdict_get_str(qdict, "name");
1167 bool up = qdict_get_bool(qdict, "up");
1168 Error *err = NULL;
1170 qmp_set_link(name, up, &err);
1171 hmp_handle_error(mon, &err);
1174 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1176 const char *device = qdict_get_str(qdict, "device");
1177 const char *password = qdict_get_str(qdict, "password");
1178 Error *err = NULL;
1180 qmp_block_passwd(true, device, false, NULL, password, &err);
1181 hmp_handle_error(mon, &err);
1184 void hmp_balloon(Monitor *mon, const QDict *qdict)
1186 int64_t value = qdict_get_int(qdict, "value");
1187 Error *err = NULL;
1189 qmp_balloon(value, &err);
1190 if (err) {
1191 error_report_err(err);
1195 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1197 const char *device = qdict_get_str(qdict, "device");
1198 int64_t size = qdict_get_int(qdict, "size");
1199 Error *err = NULL;
1201 qmp_block_resize(true, device, false, NULL, size, &err);
1202 hmp_handle_error(mon, &err);
1205 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1207 const char *filename = qdict_get_str(qdict, "target");
1208 const char *format = qdict_get_try_str(qdict, "format");
1209 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1210 bool full = qdict_get_try_bool(qdict, "full", false);
1211 Error *err = NULL;
1212 DriveMirror mirror = {
1213 .device = (char *)qdict_get_str(qdict, "device"),
1214 .target = (char *)filename,
1215 .has_format = !!format,
1216 .format = (char *)format,
1217 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1218 .has_mode = true,
1219 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1220 .unmap = true,
1223 if (!filename) {
1224 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1225 hmp_handle_error(mon, &err);
1226 return;
1228 qmp_drive_mirror(&mirror, &err);
1229 hmp_handle_error(mon, &err);
1232 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1234 const char *device = qdict_get_str(qdict, "device");
1235 const char *filename = qdict_get_str(qdict, "target");
1236 const char *format = qdict_get_try_str(qdict, "format");
1237 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1238 bool full = qdict_get_try_bool(qdict, "full", false);
1239 bool compress = qdict_get_try_bool(qdict, "compress", false);
1240 Error *err = NULL;
1241 DriveBackup backup = {
1242 .device = (char *)device,
1243 .target = (char *)filename,
1244 .has_format = !!format,
1245 .format = (char *)format,
1246 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1247 .has_mode = true,
1248 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1249 .has_compress = !!compress,
1250 .compress = compress,
1253 if (!filename) {
1254 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1255 hmp_handle_error(mon, &err);
1256 return;
1259 qmp_drive_backup(&backup, &err);
1260 hmp_handle_error(mon, &err);
1263 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1265 const char *device = qdict_get_str(qdict, "device");
1266 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1267 const char *format = qdict_get_try_str(qdict, "format");
1268 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1269 enum NewImageMode mode;
1270 Error *err = NULL;
1272 if (!filename) {
1273 /* In the future, if 'snapshot-file' is not specified, the snapshot
1274 will be taken internally. Today it's actually required. */
1275 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1276 hmp_handle_error(mon, &err);
1277 return;
1280 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1281 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1282 filename, false, NULL,
1283 !!format, format,
1284 true, mode, &err);
1285 hmp_handle_error(mon, &err);
1288 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1290 const char *device = qdict_get_str(qdict, "device");
1291 const char *name = qdict_get_str(qdict, "name");
1292 Error *err = NULL;
1294 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1295 hmp_handle_error(mon, &err);
1298 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1300 const char *device = qdict_get_str(qdict, "device");
1301 const char *name = qdict_get_str(qdict, "name");
1302 const char *id = qdict_get_try_str(qdict, "id");
1303 Error *err = NULL;
1305 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1306 true, name, &err);
1307 hmp_handle_error(mon, &err);
1310 void hmp_loadvm(Monitor *mon, const QDict *qdict)
1312 int saved_vm_running = runstate_is_running();
1313 const char *name = qdict_get_str(qdict, "name");
1314 Error *err = NULL;
1316 vm_stop(RUN_STATE_RESTORE_VM);
1318 if (load_snapshot(name, &err) == 0 && saved_vm_running) {
1319 vm_start();
1321 hmp_handle_error(mon, &err);
1324 void hmp_savevm(Monitor *mon, const QDict *qdict)
1326 Error *err = NULL;
1328 save_snapshot(qdict_get_try_str(qdict, "name"), &err);
1329 hmp_handle_error(mon, &err);
1332 void hmp_delvm(Monitor *mon, const QDict *qdict)
1334 BlockDriverState *bs;
1335 Error *err;
1336 const char *name = qdict_get_str(qdict, "name");
1338 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
1339 error_reportf_err(err,
1340 "Error while deleting snapshot on device '%s': ",
1341 bdrv_get_device_name(bs));
1345 void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
1347 BlockDriverState *bs, *bs1;
1348 BdrvNextIterator it1;
1349 QEMUSnapshotInfo *sn_tab, *sn;
1350 bool no_snapshot = true;
1351 int nb_sns, i;
1352 int total;
1353 int *global_snapshots;
1354 AioContext *aio_context;
1356 typedef struct SnapshotEntry {
1357 QEMUSnapshotInfo sn;
1358 QTAILQ_ENTRY(SnapshotEntry) next;
1359 } SnapshotEntry;
1361 typedef struct ImageEntry {
1362 const char *imagename;
1363 QTAILQ_ENTRY(ImageEntry) next;
1364 QTAILQ_HEAD(, SnapshotEntry) snapshots;
1365 } ImageEntry;
1367 QTAILQ_HEAD(, ImageEntry) image_list =
1368 QTAILQ_HEAD_INITIALIZER(image_list);
1370 ImageEntry *image_entry, *next_ie;
1371 SnapshotEntry *snapshot_entry;
1373 bs = bdrv_all_find_vmstate_bs();
1374 if (!bs) {
1375 monitor_printf(mon, "No available block device supports snapshots\n");
1376 return;
1378 aio_context = bdrv_get_aio_context(bs);
1380 aio_context_acquire(aio_context);
1381 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
1382 aio_context_release(aio_context);
1384 if (nb_sns < 0) {
1385 monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
1386 return;
1389 for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) {
1390 int bs1_nb_sns = 0;
1391 ImageEntry *ie;
1392 SnapshotEntry *se;
1393 AioContext *ctx = bdrv_get_aio_context(bs1);
1395 aio_context_acquire(ctx);
1396 if (bdrv_can_snapshot(bs1)) {
1397 sn = NULL;
1398 bs1_nb_sns = bdrv_snapshot_list(bs1, &sn);
1399 if (bs1_nb_sns > 0) {
1400 no_snapshot = false;
1401 ie = g_new0(ImageEntry, 1);
1402 ie->imagename = bdrv_get_device_name(bs1);
1403 QTAILQ_INIT(&ie->snapshots);
1404 QTAILQ_INSERT_TAIL(&image_list, ie, next);
1405 for (i = 0; i < bs1_nb_sns; i++) {
1406 se = g_new0(SnapshotEntry, 1);
1407 se->sn = sn[i];
1408 QTAILQ_INSERT_TAIL(&ie->snapshots, se, next);
1411 g_free(sn);
1413 aio_context_release(ctx);
1416 if (no_snapshot) {
1417 monitor_printf(mon, "There is no snapshot available.\n");
1418 return;
1421 global_snapshots = g_new0(int, nb_sns);
1422 total = 0;
1423 for (i = 0; i < nb_sns; i++) {
1424 SnapshotEntry *next_sn;
1425 if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) {
1426 global_snapshots[total] = i;
1427 total++;
1428 QTAILQ_FOREACH(image_entry, &image_list, next) {
1429 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots,
1430 next, next_sn) {
1431 if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) {
1432 QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry,
1433 next);
1434 g_free(snapshot_entry);
1441 monitor_printf(mon, "List of snapshots present on all disks:\n");
1443 if (total > 0) {
1444 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1445 monitor_printf(mon, "\n");
1446 for (i = 0; i < total; i++) {
1447 sn = &sn_tab[global_snapshots[i]];
1448 /* The ID is not guaranteed to be the same on all images, so
1449 * overwrite it.
1451 pstrcpy(sn->id_str, sizeof(sn->id_str), "--");
1452 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, sn);
1453 monitor_printf(mon, "\n");
1455 } else {
1456 monitor_printf(mon, "None\n");
1459 QTAILQ_FOREACH(image_entry, &image_list, next) {
1460 if (QTAILQ_EMPTY(&image_entry->snapshots)) {
1461 continue;
1463 monitor_printf(mon,
1464 "\nList of partial (non-loadable) snapshots on '%s':\n",
1465 image_entry->imagename);
1466 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1467 monitor_printf(mon, "\n");
1468 QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) {
1469 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon,
1470 &snapshot_entry->sn);
1471 monitor_printf(mon, "\n");
1475 QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) {
1476 SnapshotEntry *next_sn;
1477 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next,
1478 next_sn) {
1479 g_free(snapshot_entry);
1481 g_free(image_entry);
1483 g_free(sn_tab);
1484 g_free(global_snapshots);
1488 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1490 qmp_migrate_cancel(NULL);
1493 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1495 Error *err = NULL;
1496 const char *uri = qdict_get_str(qdict, "uri");
1498 qmp_migrate_incoming(uri, &err);
1500 hmp_handle_error(mon, &err);
1503 /* Kept for backwards compatibility */
1504 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1506 double value = qdict_get_double(qdict, "value");
1507 qmp_migrate_set_downtime(value, NULL);
1510 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1512 int64_t value = qdict_get_int(qdict, "value");
1513 Error *err = NULL;
1515 qmp_migrate_set_cache_size(value, &err);
1516 if (err) {
1517 error_report_err(err);
1518 return;
1522 /* Kept for backwards compatibility */
1523 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1525 int64_t value = qdict_get_int(qdict, "value");
1526 qmp_migrate_set_speed(value, NULL);
1529 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1531 const char *cap = qdict_get_str(qdict, "capability");
1532 bool state = qdict_get_bool(qdict, "state");
1533 Error *err = NULL;
1534 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1535 int val;
1537 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
1538 if (val < 0) {
1539 goto end;
1542 caps->value = g_malloc0(sizeof(*caps->value));
1543 caps->value->capability = val;
1544 caps->value->state = state;
1545 caps->next = NULL;
1546 qmp_migrate_set_capabilities(caps, &err);
1548 end:
1549 qapi_free_MigrationCapabilityStatusList(caps);
1551 if (err) {
1552 error_report_err(err);
1556 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1558 const char *param = qdict_get_str(qdict, "parameter");
1559 const char *valuestr = qdict_get_str(qdict, "value");
1560 Visitor *v = string_input_visitor_new(valuestr);
1561 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
1562 uint64_t valuebw = 0;
1563 Error *err = NULL;
1564 int val, ret;
1566 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
1567 if (val < 0) {
1568 goto cleanup;
1571 switch (val) {
1572 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1573 p->has_compress_level = true;
1574 visit_type_int(v, param, &p->compress_level, &err);
1575 break;
1576 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1577 p->has_compress_threads = true;
1578 visit_type_int(v, param, &p->compress_threads, &err);
1579 break;
1580 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1581 p->has_decompress_threads = true;
1582 visit_type_int(v, param, &p->decompress_threads, &err);
1583 break;
1584 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1585 p->has_cpu_throttle_initial = true;
1586 visit_type_int(v, param, &p->cpu_throttle_initial, &err);
1587 break;
1588 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1589 p->has_cpu_throttle_increment = true;
1590 visit_type_int(v, param, &p->cpu_throttle_increment, &err);
1591 break;
1592 case MIGRATION_PARAMETER_TLS_CREDS:
1593 p->has_tls_creds = true;
1594 p->tls_creds = g_new0(StrOrNull, 1);
1595 p->tls_creds->type = QTYPE_QSTRING;
1596 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1597 break;
1598 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1599 p->has_tls_hostname = true;
1600 p->tls_hostname = g_new0(StrOrNull, 1);
1601 p->tls_hostname->type = QTYPE_QSTRING;
1602 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1603 break;
1604 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1605 p->has_max_bandwidth = true;
1607 * Can't use visit_type_size() here, because it
1608 * defaults to Bytes rather than Mebibytes.
1610 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1611 if (ret < 0 || valuebw > INT64_MAX
1612 || (size_t)valuebw != valuebw) {
1613 error_setg(&err, "Invalid size %s", valuestr);
1614 break;
1616 p->max_bandwidth = valuebw;
1617 break;
1618 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1619 p->has_downtime_limit = true;
1620 visit_type_int(v, param, &p->downtime_limit, &err);
1621 break;
1622 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1623 p->has_x_checkpoint_delay = true;
1624 visit_type_int(v, param, &p->x_checkpoint_delay, &err);
1625 break;
1626 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1627 p->has_block_incremental = true;
1628 visit_type_bool(v, param, &p->block_incremental, &err);
1629 break;
1630 case MIGRATION_PARAMETER_X_MULTIFD_CHANNELS:
1631 p->has_x_multifd_channels = true;
1632 visit_type_int(v, param, &p->x_multifd_channels, &err);
1633 break;
1634 case MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT:
1635 p->has_x_multifd_page_count = true;
1636 visit_type_int(v, param, &p->x_multifd_page_count, &err);
1637 break;
1638 default:
1639 assert(0);
1642 if (err) {
1643 goto cleanup;
1646 qmp_migrate_set_parameters(p, &err);
1648 cleanup:
1649 qapi_free_MigrateSetParameters(p);
1650 visit_free(v);
1651 if (err) {
1652 error_report_err(err);
1656 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1658 Error *err = NULL;
1659 const char *protocol = qdict_get_str(qdict, "protocol");
1660 const char *hostname = qdict_get_str(qdict, "hostname");
1661 bool has_port = qdict_haskey(qdict, "port");
1662 int port = qdict_get_try_int(qdict, "port", -1);
1663 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1664 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1665 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1667 qmp_client_migrate_info(protocol, hostname,
1668 has_port, port, has_tls_port, tls_port,
1669 !!cert_subject, cert_subject, &err);
1670 hmp_handle_error(mon, &err);
1673 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1675 Error *err = NULL;
1676 qmp_migrate_start_postcopy(&err);
1677 hmp_handle_error(mon, &err);
1680 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1682 Error *err = NULL;
1684 qmp_x_colo_lost_heartbeat(&err);
1685 hmp_handle_error(mon, &err);
1688 void hmp_set_password(Monitor *mon, const QDict *qdict)
1690 const char *protocol = qdict_get_str(qdict, "protocol");
1691 const char *password = qdict_get_str(qdict, "password");
1692 const char *connected = qdict_get_try_str(qdict, "connected");
1693 Error *err = NULL;
1695 qmp_set_password(protocol, password, !!connected, connected, &err);
1696 hmp_handle_error(mon, &err);
1699 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1701 const char *protocol = qdict_get_str(qdict, "protocol");
1702 const char *whenstr = qdict_get_str(qdict, "time");
1703 Error *err = NULL;
1705 qmp_expire_password(protocol, whenstr, &err);
1706 hmp_handle_error(mon, &err);
1709 void hmp_eject(Monitor *mon, const QDict *qdict)
1711 bool force = qdict_get_try_bool(qdict, "force", false);
1712 const char *device = qdict_get_str(qdict, "device");
1713 Error *err = NULL;
1715 qmp_eject(true, device, false, NULL, true, force, &err);
1716 hmp_handle_error(mon, &err);
1719 static void hmp_change_read_arg(void *opaque, const char *password,
1720 void *readline_opaque)
1722 qmp_change_vnc_password(password, NULL);
1723 monitor_read_command(opaque, 1);
1726 void hmp_change(Monitor *mon, const QDict *qdict)
1728 const char *device = qdict_get_str(qdict, "device");
1729 const char *target = qdict_get_str(qdict, "target");
1730 const char *arg = qdict_get_try_str(qdict, "arg");
1731 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1732 BlockdevChangeReadOnlyMode read_only_mode = 0;
1733 Error *err = NULL;
1735 if (strcmp(device, "vnc") == 0) {
1736 if (read_only) {
1737 monitor_printf(mon,
1738 "Parameter 'read-only-mode' is invalid for VNC\n");
1739 return;
1741 if (strcmp(target, "passwd") == 0 ||
1742 strcmp(target, "password") == 0) {
1743 if (!arg) {
1744 monitor_read_password(mon, hmp_change_read_arg, NULL);
1745 return;
1748 qmp_change("vnc", target, !!arg, arg, &err);
1749 } else {
1750 if (read_only) {
1751 read_only_mode =
1752 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
1753 read_only,
1754 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1755 if (err) {
1756 hmp_handle_error(mon, &err);
1757 return;
1761 qmp_blockdev_change_medium(true, device, false, NULL, target,
1762 !!arg, arg, !!read_only, read_only_mode,
1763 &err);
1766 hmp_handle_error(mon, &err);
1769 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1771 Error *err = NULL;
1772 BlockIOThrottle throttle = {
1773 .has_device = true,
1774 .device = (char *) qdict_get_str(qdict, "device"),
1775 .bps = qdict_get_int(qdict, "bps"),
1776 .bps_rd = qdict_get_int(qdict, "bps_rd"),
1777 .bps_wr = qdict_get_int(qdict, "bps_wr"),
1778 .iops = qdict_get_int(qdict, "iops"),
1779 .iops_rd = qdict_get_int(qdict, "iops_rd"),
1780 .iops_wr = qdict_get_int(qdict, "iops_wr"),
1783 qmp_block_set_io_throttle(&throttle, &err);
1784 hmp_handle_error(mon, &err);
1787 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1789 Error *error = NULL;
1790 const char *device = qdict_get_str(qdict, "device");
1791 const char *base = qdict_get_try_str(qdict, "base");
1792 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1794 qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
1795 false, NULL, qdict_haskey(qdict, "speed"), speed,
1796 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1798 hmp_handle_error(mon, &error);
1801 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1803 Error *error = NULL;
1804 const char *device = qdict_get_str(qdict, "device");
1805 int64_t value = qdict_get_int(qdict, "speed");
1807 qmp_block_job_set_speed(device, value, &error);
1809 hmp_handle_error(mon, &error);
1812 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1814 Error *error = NULL;
1815 const char *device = qdict_get_str(qdict, "device");
1816 bool force = qdict_get_try_bool(qdict, "force", false);
1818 qmp_block_job_cancel(device, true, force, &error);
1820 hmp_handle_error(mon, &error);
1823 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1825 Error *error = NULL;
1826 const char *device = qdict_get_str(qdict, "device");
1828 qmp_block_job_pause(device, &error);
1830 hmp_handle_error(mon, &error);
1833 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1835 Error *error = NULL;
1836 const char *device = qdict_get_str(qdict, "device");
1838 qmp_block_job_resume(device, &error);
1840 hmp_handle_error(mon, &error);
1843 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1845 Error *error = NULL;
1846 const char *device = qdict_get_str(qdict, "device");
1848 qmp_block_job_complete(device, &error);
1850 hmp_handle_error(mon, &error);
1853 typedef struct HMPMigrationStatus
1855 QEMUTimer *timer;
1856 Monitor *mon;
1857 bool is_block_migration;
1858 } HMPMigrationStatus;
1860 static void hmp_migrate_status_cb(void *opaque)
1862 HMPMigrationStatus *status = opaque;
1863 MigrationInfo *info;
1865 info = qmp_query_migrate(NULL);
1866 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1867 info->status == MIGRATION_STATUS_SETUP) {
1868 if (info->has_disk) {
1869 int progress;
1871 if (info->disk->remaining) {
1872 progress = info->disk->transferred * 100 / info->disk->total;
1873 } else {
1874 progress = 100;
1877 monitor_printf(status->mon, "Completed %d %%\r", progress);
1878 monitor_flush(status->mon);
1881 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1882 } else {
1883 if (status->is_block_migration) {
1884 monitor_printf(status->mon, "\n");
1886 if (info->has_error_desc) {
1887 error_report("%s", info->error_desc);
1889 monitor_resume(status->mon);
1890 timer_del(status->timer);
1891 g_free(status);
1894 qapi_free_MigrationInfo(info);
1897 void hmp_migrate(Monitor *mon, const QDict *qdict)
1899 bool detach = qdict_get_try_bool(qdict, "detach", false);
1900 bool blk = qdict_get_try_bool(qdict, "blk", false);
1901 bool inc = qdict_get_try_bool(qdict, "inc", false);
1902 const char *uri = qdict_get_str(qdict, "uri");
1903 Error *err = NULL;
1905 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1906 if (err) {
1907 error_report_err(err);
1908 return;
1911 if (!detach) {
1912 HMPMigrationStatus *status;
1914 if (monitor_suspend(mon) < 0) {
1915 monitor_printf(mon, "terminal does not allow synchronous "
1916 "migration, continuing detached\n");
1917 return;
1920 status = g_malloc0(sizeof(*status));
1921 status->mon = mon;
1922 status->is_block_migration = blk || inc;
1923 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1924 status);
1925 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1929 void hmp_device_add(Monitor *mon, const QDict *qdict)
1931 Error *err = NULL;
1933 qmp_device_add((QDict *)qdict, NULL, &err);
1934 hmp_handle_error(mon, &err);
1937 void hmp_device_del(Monitor *mon, const QDict *qdict)
1939 const char *id = qdict_get_str(qdict, "id");
1940 Error *err = NULL;
1942 qmp_device_del(id, &err);
1943 hmp_handle_error(mon, &err);
1946 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1948 Error *err = NULL;
1949 bool paging = qdict_get_try_bool(qdict, "paging", false);
1950 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
1951 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
1952 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
1953 const char *file = qdict_get_str(qdict, "filename");
1954 bool has_begin = qdict_haskey(qdict, "begin");
1955 bool has_length = qdict_haskey(qdict, "length");
1956 bool has_detach = qdict_haskey(qdict, "detach");
1957 int64_t begin = 0;
1958 int64_t length = 0;
1959 bool detach = false;
1960 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1961 char *prot;
1963 if (zlib + lzo + snappy > 1) {
1964 error_setg(&err, "only one of '-z|-l|-s' can be set");
1965 hmp_handle_error(mon, &err);
1966 return;
1969 if (zlib) {
1970 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1973 if (lzo) {
1974 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1977 if (snappy) {
1978 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1981 if (has_begin) {
1982 begin = qdict_get_int(qdict, "begin");
1984 if (has_length) {
1985 length = qdict_get_int(qdict, "length");
1987 if (has_detach) {
1988 detach = qdict_get_bool(qdict, "detach");
1991 prot = g_strconcat("file:", file, NULL);
1993 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
1994 has_length, length, true, dump_format, &err);
1995 hmp_handle_error(mon, &err);
1996 g_free(prot);
1999 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
2001 Error *err = NULL;
2002 QemuOpts *opts;
2004 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
2005 if (err) {
2006 goto out;
2009 netdev_add(opts, &err);
2010 if (err) {
2011 qemu_opts_del(opts);
2014 out:
2015 hmp_handle_error(mon, &err);
2018 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
2020 const char *id = qdict_get_str(qdict, "id");
2021 Error *err = NULL;
2023 qmp_netdev_del(id, &err);
2024 hmp_handle_error(mon, &err);
2027 void hmp_object_add(Monitor *mon, const QDict *qdict)
2029 Error *err = NULL;
2030 QemuOpts *opts;
2031 Object *obj = NULL;
2033 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
2034 if (err) {
2035 hmp_handle_error(mon, &err);
2036 return;
2039 obj = user_creatable_add_opts(opts, &err);
2040 qemu_opts_del(opts);
2042 if (err) {
2043 hmp_handle_error(mon, &err);
2045 if (obj) {
2046 object_unref(obj);
2050 void hmp_getfd(Monitor *mon, const QDict *qdict)
2052 const char *fdname = qdict_get_str(qdict, "fdname");
2053 Error *err = NULL;
2055 qmp_getfd(fdname, &err);
2056 hmp_handle_error(mon, &err);
2059 void hmp_closefd(Monitor *mon, const QDict *qdict)
2061 const char *fdname = qdict_get_str(qdict, "fdname");
2062 Error *err = NULL;
2064 qmp_closefd(fdname, &err);
2065 hmp_handle_error(mon, &err);
2068 void hmp_sendkey(Monitor *mon, const QDict *qdict)
2070 const char *keys = qdict_get_str(qdict, "keys");
2071 KeyValueList *keylist, *head = NULL, *tmp = NULL;
2072 int has_hold_time = qdict_haskey(qdict, "hold-time");
2073 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
2074 Error *err = NULL;
2075 char *separator;
2076 int keyname_len;
2078 while (1) {
2079 separator = strchr(keys, '-');
2080 keyname_len = separator ? separator - keys : strlen(keys);
2082 /* Be compatible with old interface, convert user inputted "<" */
2083 if (keys[0] == '<' && keyname_len == 1) {
2084 keys = "less";
2085 keyname_len = 4;
2088 keylist = g_malloc0(sizeof(*keylist));
2089 keylist->value = g_malloc0(sizeof(*keylist->value));
2091 if (!head) {
2092 head = keylist;
2094 if (tmp) {
2095 tmp->next = keylist;
2097 tmp = keylist;
2099 if (strstart(keys, "0x", NULL)) {
2100 char *endp;
2101 int value = strtoul(keys, &endp, 0);
2102 assert(endp <= keys + keyname_len);
2103 if (endp != keys + keyname_len) {
2104 goto err_out;
2106 keylist->value->type = KEY_VALUE_KIND_NUMBER;
2107 keylist->value->u.number.data = value;
2108 } else {
2109 int idx = index_from_key(keys, keyname_len);
2110 if (idx == Q_KEY_CODE__MAX) {
2111 goto err_out;
2113 keylist->value->type = KEY_VALUE_KIND_QCODE;
2114 keylist->value->u.qcode.data = idx;
2117 if (!separator) {
2118 break;
2120 keys = separator + 1;
2123 qmp_send_key(head, has_hold_time, hold_time, &err);
2124 hmp_handle_error(mon, &err);
2126 out:
2127 qapi_free_KeyValueList(head);
2128 return;
2130 err_out:
2131 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
2132 goto out;
2135 void hmp_screendump(Monitor *mon, const QDict *qdict)
2137 const char *filename = qdict_get_str(qdict, "filename");
2138 Error *err = NULL;
2140 qmp_screendump(filename, &err);
2141 hmp_handle_error(mon, &err);
2144 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
2146 const char *uri = qdict_get_str(qdict, "uri");
2147 bool writable = qdict_get_try_bool(qdict, "writable", false);
2148 bool all = qdict_get_try_bool(qdict, "all", false);
2149 Error *local_err = NULL;
2150 BlockInfoList *block_list, *info;
2151 SocketAddress *addr;
2153 if (writable && !all) {
2154 error_setg(&local_err, "-w only valid together with -a");
2155 goto exit;
2158 /* First check if the address is valid and start the server. */
2159 addr = socket_parse(uri, &local_err);
2160 if (local_err != NULL) {
2161 goto exit;
2164 nbd_server_start(addr, NULL, &local_err);
2165 qapi_free_SocketAddress(addr);
2166 if (local_err != NULL) {
2167 goto exit;
2170 if (!all) {
2171 return;
2174 /* Then try adding all block devices. If one fails, close all and
2175 * exit.
2177 block_list = qmp_query_block(NULL);
2179 for (info = block_list; info; info = info->next) {
2180 if (!info->value->has_inserted) {
2181 continue;
2184 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
2186 if (local_err != NULL) {
2187 qmp_nbd_server_stop(NULL);
2188 break;
2192 qapi_free_BlockInfoList(block_list);
2194 exit:
2195 hmp_handle_error(mon, &local_err);
2198 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
2200 const char *device = qdict_get_str(qdict, "device");
2201 bool writable = qdict_get_try_bool(qdict, "writable", false);
2202 Error *local_err = NULL;
2204 qmp_nbd_server_add(device, true, writable, &local_err);
2206 if (local_err != NULL) {
2207 hmp_handle_error(mon, &local_err);
2211 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
2213 Error *err = NULL;
2215 qmp_nbd_server_stop(&err);
2216 hmp_handle_error(mon, &err);
2219 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
2221 int cpuid;
2222 Error *err = NULL;
2224 cpuid = qdict_get_int(qdict, "id");
2225 qmp_cpu_add(cpuid, &err);
2226 hmp_handle_error(mon, &err);
2229 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2231 const char *args = qdict_get_str(qdict, "args");
2232 Error *err = NULL;
2233 QemuOpts *opts;
2235 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
2236 if (opts == NULL) {
2237 error_setg(&err, "Parsing chardev args failed");
2238 } else {
2239 qemu_chr_new_from_opts(opts, &err);
2240 qemu_opts_del(opts);
2242 hmp_handle_error(mon, &err);
2245 void hmp_chardev_change(Monitor *mon, const QDict *qdict)
2247 const char *args = qdict_get_str(qdict, "args");
2248 const char *id;
2249 Error *err = NULL;
2250 ChardevBackend *backend = NULL;
2251 ChardevReturn *ret = NULL;
2252 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
2253 true);
2254 if (!opts) {
2255 error_setg(&err, "Parsing chardev args failed");
2256 goto end;
2259 id = qdict_get_str(qdict, "id");
2260 if (qemu_opts_id(opts)) {
2261 error_setg(&err, "Unexpected 'id' parameter");
2262 goto end;
2265 backend = qemu_chr_parse_opts(opts, &err);
2266 if (!backend) {
2267 goto end;
2270 ret = qmp_chardev_change(id, backend, &err);
2272 end:
2273 qapi_free_ChardevReturn(ret);
2274 qapi_free_ChardevBackend(backend);
2275 qemu_opts_del(opts);
2276 hmp_handle_error(mon, &err);
2279 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2281 Error *local_err = NULL;
2283 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
2284 hmp_handle_error(mon, &local_err);
2287 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
2289 Error *local_err = NULL;
2291 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
2292 hmp_handle_error(mon, &local_err);
2295 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
2297 BlockBackend *blk;
2298 BlockBackend *local_blk = NULL;
2299 AioContext *aio_context;
2300 const char* device = qdict_get_str(qdict, "device");
2301 const char* command = qdict_get_str(qdict, "command");
2302 Error *err = NULL;
2303 int ret;
2305 blk = blk_by_name(device);
2306 if (!blk) {
2307 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
2308 if (bs) {
2309 blk = local_blk = blk_new(0, BLK_PERM_ALL);
2310 ret = blk_insert_bs(blk, bs, &err);
2311 if (ret < 0) {
2312 goto fail;
2314 } else {
2315 goto fail;
2319 aio_context = blk_get_aio_context(blk);
2320 aio_context_acquire(aio_context);
2323 * Notably absent: Proper permission management. This is sad, but it seems
2324 * almost impossible to achieve without changing the semantics and thereby
2325 * limiting the use cases of the qemu-io HMP command.
2327 * In an ideal world we would unconditionally create a new BlockBackend for
2328 * qemuio_command(), but we have commands like 'reopen' and want them to
2329 * take effect on the exact BlockBackend whose name the user passed instead
2330 * of just on a temporary copy of it.
2332 * Another problem is that deleting the temporary BlockBackend involves
2333 * draining all requests on it first, but some qemu-iotests cases want to
2334 * issue multiple aio_read/write requests and expect them to complete in
2335 * the background while the monitor has already returned.
2337 * This is also what prevents us from saving the original permissions and
2338 * restoring them later: We can't revoke permissions until all requests
2339 * have completed, and we don't know when that is nor can we really let
2340 * anything else run before we have revoken them to avoid race conditions.
2342 * What happens now is that command() in qemu-io-cmds.c can extend the
2343 * permissions if necessary for the qemu-io command. And they simply stay
2344 * extended, possibly resulting in a read-only guest device keeping write
2345 * permissions. Ugly, but it appears to be the lesser evil.
2347 qemuio_command(blk, command);
2349 aio_context_release(aio_context);
2351 fail:
2352 blk_unref(local_blk);
2353 hmp_handle_error(mon, &err);
2356 void hmp_object_del(Monitor *mon, const QDict *qdict)
2358 const char *id = qdict_get_str(qdict, "id");
2359 Error *err = NULL;
2361 user_creatable_del(id, &err);
2362 hmp_handle_error(mon, &err);
2365 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
2367 Error *err = NULL;
2368 MemdevList *memdev_list = qmp_query_memdev(&err);
2369 MemdevList *m = memdev_list;
2370 Visitor *v;
2371 char *str;
2373 while (m) {
2374 v = string_output_visitor_new(false, &str);
2375 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
2376 monitor_printf(mon, "memory backend: %s\n", m->value->id);
2377 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
2378 monitor_printf(mon, " merge: %s\n",
2379 m->value->merge ? "true" : "false");
2380 monitor_printf(mon, " dump: %s\n",
2381 m->value->dump ? "true" : "false");
2382 monitor_printf(mon, " prealloc: %s\n",
2383 m->value->prealloc ? "true" : "false");
2384 monitor_printf(mon, " policy: %s\n",
2385 HostMemPolicy_str(m->value->policy));
2386 visit_complete(v, &str);
2387 monitor_printf(mon, " host nodes: %s\n", str);
2389 g_free(str);
2390 visit_free(v);
2391 m = m->next;
2394 monitor_printf(mon, "\n");
2396 qapi_free_MemdevList(memdev_list);
2399 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2401 Error *err = NULL;
2402 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2403 MemoryDeviceInfoList *info;
2404 MemoryDeviceInfo *value;
2405 PCDIMMDeviceInfo *di;
2407 for (info = info_list; info; info = info->next) {
2408 value = info->value;
2410 if (value) {
2411 switch (value->type) {
2412 case MEMORY_DEVICE_INFO_KIND_DIMM:
2413 di = value->u.dimm.data;
2415 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2416 MemoryDeviceInfoKind_str(value->type),
2417 di->id ? di->id : "");
2418 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2419 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2420 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2421 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2422 monitor_printf(mon, " memdev: %s\n", di->memdev);
2423 monitor_printf(mon, " hotplugged: %s\n",
2424 di->hotplugged ? "true" : "false");
2425 monitor_printf(mon, " hotpluggable: %s\n",
2426 di->hotpluggable ? "true" : "false");
2427 break;
2428 default:
2429 break;
2434 qapi_free_MemoryDeviceInfoList(info_list);
2437 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2439 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2440 IOThreadInfoList *info;
2441 IOThreadInfo *value;
2443 for (info = info_list; info; info = info->next) {
2444 value = info->value;
2445 monitor_printf(mon, "%s:\n", value->id);
2446 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
2447 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2448 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
2449 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
2452 qapi_free_IOThreadInfoList(info_list);
2455 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2457 const char *path = qdict_get_try_str(qdict, "path");
2458 ObjectPropertyInfoList *list;
2459 Error *err = NULL;
2461 if (path == NULL) {
2462 monitor_printf(mon, "/\n");
2463 return;
2466 list = qmp_qom_list(path, &err);
2467 if (err == NULL) {
2468 ObjectPropertyInfoList *start = list;
2469 while (list != NULL) {
2470 ObjectPropertyInfo *value = list->value;
2472 monitor_printf(mon, "%s (%s)\n",
2473 value->name, value->type);
2474 list = list->next;
2476 qapi_free_ObjectPropertyInfoList(start);
2478 hmp_handle_error(mon, &err);
2481 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2483 const char *path = qdict_get_str(qdict, "path");
2484 const char *property = qdict_get_str(qdict, "property");
2485 const char *value = qdict_get_str(qdict, "value");
2486 Error *err = NULL;
2487 bool ambiguous = false;
2488 Object *obj;
2490 obj = object_resolve_path(path, &ambiguous);
2491 if (obj == NULL) {
2492 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2493 "Device '%s' not found", path);
2494 } else {
2495 if (ambiguous) {
2496 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2498 object_property_parse(obj, value, property, &err);
2500 hmp_handle_error(mon, &err);
2503 void hmp_rocker(Monitor *mon, const QDict *qdict)
2505 const char *name = qdict_get_str(qdict, "name");
2506 RockerSwitch *rocker;
2507 Error *err = NULL;
2509 rocker = qmp_query_rocker(name, &err);
2510 if (err != NULL) {
2511 hmp_handle_error(mon, &err);
2512 return;
2515 monitor_printf(mon, "name: %s\n", rocker->name);
2516 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2517 monitor_printf(mon, "ports: %d\n", rocker->ports);
2519 qapi_free_RockerSwitch(rocker);
2522 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2524 RockerPortList *list, *port;
2525 const char *name = qdict_get_str(qdict, "name");
2526 Error *err = NULL;
2528 list = qmp_query_rocker_ports(name, &err);
2529 if (err != NULL) {
2530 hmp_handle_error(mon, &err);
2531 return;
2534 monitor_printf(mon, " ena/ speed/ auto\n");
2535 monitor_printf(mon, " port link duplex neg?\n");
2537 for (port = list; port; port = port->next) {
2538 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2539 port->value->name,
2540 port->value->enabled ? port->value->link_up ?
2541 "up" : "down" : "!ena",
2542 port->value->speed == 10000 ? "10G" : "??",
2543 port->value->duplex ? "FD" : "HD",
2544 port->value->autoneg ? "Yes" : "No");
2547 qapi_free_RockerPortList(list);
2550 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2552 RockerOfDpaFlowList *list, *info;
2553 const char *name = qdict_get_str(qdict, "name");
2554 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2555 Error *err = NULL;
2557 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2558 if (err != NULL) {
2559 hmp_handle_error(mon, &err);
2560 return;
2563 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2565 for (info = list; info; info = info->next) {
2566 RockerOfDpaFlow *flow = info->value;
2567 RockerOfDpaFlowKey *key = flow->key;
2568 RockerOfDpaFlowMask *mask = flow->mask;
2569 RockerOfDpaFlowAction *action = flow->action;
2571 if (flow->hits) {
2572 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2573 key->priority, key->tbl_id, flow->hits);
2574 } else {
2575 monitor_printf(mon, "%-4d %-3d ",
2576 key->priority, key->tbl_id);
2579 if (key->has_in_pport) {
2580 monitor_printf(mon, " pport %d", key->in_pport);
2581 if (mask->has_in_pport) {
2582 monitor_printf(mon, "(0x%x)", mask->in_pport);
2586 if (key->has_vlan_id) {
2587 monitor_printf(mon, " vlan %d",
2588 key->vlan_id & VLAN_VID_MASK);
2589 if (mask->has_vlan_id) {
2590 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2594 if (key->has_tunnel_id) {
2595 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2596 if (mask->has_tunnel_id) {
2597 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2601 if (key->has_eth_type) {
2602 switch (key->eth_type) {
2603 case 0x0806:
2604 monitor_printf(mon, " ARP");
2605 break;
2606 case 0x0800:
2607 monitor_printf(mon, " IP");
2608 break;
2609 case 0x86dd:
2610 monitor_printf(mon, " IPv6");
2611 break;
2612 case 0x8809:
2613 monitor_printf(mon, " LACP");
2614 break;
2615 case 0x88cc:
2616 monitor_printf(mon, " LLDP");
2617 break;
2618 default:
2619 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2620 break;
2624 if (key->has_eth_src) {
2625 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2626 (mask->has_eth_src) &&
2627 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2628 monitor_printf(mon, " src <any mcast/bcast>");
2629 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2630 (mask->has_eth_src) &&
2631 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2632 monitor_printf(mon, " src <any ucast>");
2633 } else {
2634 monitor_printf(mon, " src %s", key->eth_src);
2635 if (mask->has_eth_src) {
2636 monitor_printf(mon, "(%s)", mask->eth_src);
2641 if (key->has_eth_dst) {
2642 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2643 (mask->has_eth_dst) &&
2644 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2645 monitor_printf(mon, " dst <any mcast/bcast>");
2646 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2647 (mask->has_eth_dst) &&
2648 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2649 monitor_printf(mon, " dst <any ucast>");
2650 } else {
2651 monitor_printf(mon, " dst %s", key->eth_dst);
2652 if (mask->has_eth_dst) {
2653 monitor_printf(mon, "(%s)", mask->eth_dst);
2658 if (key->has_ip_proto) {
2659 monitor_printf(mon, " proto %d", key->ip_proto);
2660 if (mask->has_ip_proto) {
2661 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2665 if (key->has_ip_tos) {
2666 monitor_printf(mon, " TOS %d", key->ip_tos);
2667 if (mask->has_ip_tos) {
2668 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2672 if (key->has_ip_dst) {
2673 monitor_printf(mon, " dst %s", key->ip_dst);
2676 if (action->has_goto_tbl || action->has_group_id ||
2677 action->has_new_vlan_id) {
2678 monitor_printf(mon, " -->");
2681 if (action->has_new_vlan_id) {
2682 monitor_printf(mon, " apply new vlan %d",
2683 ntohs(action->new_vlan_id));
2686 if (action->has_group_id) {
2687 monitor_printf(mon, " write group 0x%08x", action->group_id);
2690 if (action->has_goto_tbl) {
2691 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2694 monitor_printf(mon, "\n");
2697 qapi_free_RockerOfDpaFlowList(list);
2700 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2702 RockerOfDpaGroupList *list, *g;
2703 const char *name = qdict_get_str(qdict, "name");
2704 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2705 Error *err = NULL;
2706 bool set = false;
2708 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2709 if (err != NULL) {
2710 hmp_handle_error(mon, &err);
2711 return;
2714 monitor_printf(mon, "id (decode) --> buckets\n");
2716 for (g = list; g; g = g->next) {
2717 RockerOfDpaGroup *group = g->value;
2719 monitor_printf(mon, "0x%08x", group->id);
2721 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2722 group->type == 1 ? "L2 rewrite" :
2723 group->type == 2 ? "L3 unicast" :
2724 group->type == 3 ? "L2 multicast" :
2725 group->type == 4 ? "L2 flood" :
2726 group->type == 5 ? "L3 interface" :
2727 group->type == 6 ? "L3 multicast" :
2728 group->type == 7 ? "L3 ECMP" :
2729 group->type == 8 ? "L2 overlay" :
2730 "unknown");
2732 if (group->has_vlan_id) {
2733 monitor_printf(mon, " vlan %d", group->vlan_id);
2736 if (group->has_pport) {
2737 monitor_printf(mon, " pport %d", group->pport);
2740 if (group->has_index) {
2741 monitor_printf(mon, " index %d", group->index);
2744 monitor_printf(mon, ") -->");
2746 if (group->has_set_vlan_id && group->set_vlan_id) {
2747 set = true;
2748 monitor_printf(mon, " set vlan %d",
2749 group->set_vlan_id & VLAN_VID_MASK);
2752 if (group->has_set_eth_src) {
2753 if (!set) {
2754 set = true;
2755 monitor_printf(mon, " set");
2757 monitor_printf(mon, " src %s", group->set_eth_src);
2760 if (group->has_set_eth_dst) {
2761 if (!set) {
2762 set = true;
2763 monitor_printf(mon, " set");
2765 monitor_printf(mon, " dst %s", group->set_eth_dst);
2768 set = false;
2770 if (group->has_ttl_check && group->ttl_check) {
2771 monitor_printf(mon, " check TTL");
2774 if (group->has_group_id && group->group_id) {
2775 monitor_printf(mon, " group id 0x%08x", group->group_id);
2778 if (group->has_pop_vlan && group->pop_vlan) {
2779 monitor_printf(mon, " pop vlan");
2782 if (group->has_out_pport) {
2783 monitor_printf(mon, " out pport %d", group->out_pport);
2786 if (group->has_group_ids) {
2787 struct uint32List *id;
2789 monitor_printf(mon, " groups [");
2790 for (id = group->group_ids; id; id = id->next) {
2791 monitor_printf(mon, "0x%08x", id->value);
2792 if (id->next) {
2793 monitor_printf(mon, ",");
2796 monitor_printf(mon, "]");
2799 monitor_printf(mon, "\n");
2802 qapi_free_RockerOfDpaGroupList(list);
2805 void hmp_info_dump(Monitor *mon, const QDict *qdict)
2807 DumpQueryResult *result = qmp_query_dump(NULL);
2809 assert(result && result->status < DUMP_STATUS__MAX);
2810 monitor_printf(mon, "Status: %s\n", DumpStatus_str(result->status));
2812 if (result->status == DUMP_STATUS_ACTIVE) {
2813 float percent = 0;
2814 assert(result->total != 0);
2815 percent = 100.0 * result->completed / result->total;
2816 monitor_printf(mon, "Finished: %.2f %%\n", percent);
2819 qapi_free_DumpQueryResult(result);
2822 void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
2824 ram_block_dump(mon);
2827 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
2829 Error *err = NULL;
2830 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
2831 HotpluggableCPUList *saved = l;
2832 CpuInstanceProperties *c;
2834 if (err != NULL) {
2835 hmp_handle_error(mon, &err);
2836 return;
2839 monitor_printf(mon, "Hotpluggable CPUs:\n");
2840 while (l) {
2841 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
2842 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
2843 l->value->vcpus_count);
2844 if (l->value->has_qom_path) {
2845 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
2848 c = l->value->props;
2849 monitor_printf(mon, " CPUInstance Properties:\n");
2850 if (c->has_node_id) {
2851 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
2853 if (c->has_socket_id) {
2854 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
2856 if (c->has_core_id) {
2857 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
2859 if (c->has_thread_id) {
2860 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
2863 l = l->next;
2866 qapi_free_HotpluggableCPUList(saved);
2869 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
2871 Error *err = NULL;
2872 GuidInfo *info = qmp_query_vm_generation_id(&err);
2873 if (info) {
2874 monitor_printf(mon, "%s\n", info->guid);
2876 hmp_handle_error(mon, &err);
2877 qapi_free_GuidInfo(info);
2880 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
2882 Error *err = NULL;
2883 MemoryInfo *info = qmp_query_memory_size_summary(&err);
2884 if (info) {
2885 monitor_printf(mon, "base memory: %" PRIu64 "\n",
2886 info->base_memory);
2888 if (info->has_plugged_memory) {
2889 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
2890 info->plugged_memory);
2893 qapi_free_MemoryInfo(info);
2895 hmp_handle_error(mon, &err);