migration: Create x-multifd-channels parameter
[qemu/ar7.git] / hmp.c
blobbebe19ebe4eaf1156cb2472353733fe30d46345e
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);
344 qapi_free_MigrationParameters(params);
347 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
349 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
350 qmp_query_migrate_cache_size(NULL) >> 10);
353 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
355 CpuInfoList *cpu_list, *cpu;
357 cpu_list = qmp_query_cpus(NULL);
359 for (cpu = cpu_list; cpu; cpu = cpu->next) {
360 int active = ' ';
362 if (cpu->value->CPU == monitor_get_cpu_index()) {
363 active = '*';
366 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
368 switch (cpu->value->arch) {
369 case CPU_INFO_ARCH_X86:
370 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->u.x86.pc);
371 break;
372 case CPU_INFO_ARCH_PPC:
373 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->u.ppc.nip);
374 break;
375 case CPU_INFO_ARCH_SPARC:
376 monitor_printf(mon, " pc=0x%016" PRIx64,
377 cpu->value->u.q_sparc.pc);
378 monitor_printf(mon, " npc=0x%016" PRIx64,
379 cpu->value->u.q_sparc.npc);
380 break;
381 case CPU_INFO_ARCH_MIPS:
382 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.q_mips.PC);
383 break;
384 case CPU_INFO_ARCH_TRICORE:
385 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.tricore.PC);
386 break;
387 default:
388 break;
391 if (cpu->value->halted) {
392 monitor_printf(mon, " (halted)");
395 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
398 qapi_free_CpuInfoList(cpu_list);
401 static void print_block_info(Monitor *mon, BlockInfo *info,
402 BlockDeviceInfo *inserted, bool verbose)
404 ImageInfo *image_info;
406 assert(!info || !info->has_inserted || info->inserted == inserted);
408 if (info && *info->device) {
409 monitor_printf(mon, "%s", info->device);
410 if (inserted && inserted->has_node_name) {
411 monitor_printf(mon, " (%s)", inserted->node_name);
413 } else {
414 assert(info || inserted);
415 monitor_printf(mon, "%s",
416 inserted && inserted->has_node_name ? inserted->node_name
417 : info && info->has_qdev ? info->qdev
418 : "<anonymous>");
421 if (inserted) {
422 monitor_printf(mon, ": %s (%s%s%s)\n",
423 inserted->file,
424 inserted->drv,
425 inserted->ro ? ", read-only" : "",
426 inserted->encrypted ? ", encrypted" : "");
427 } else {
428 monitor_printf(mon, ": [not inserted]\n");
431 if (info) {
432 if (info->has_qdev) {
433 monitor_printf(mon, " Attached to: %s\n", info->qdev);
435 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
436 monitor_printf(mon, " I/O status: %s\n",
437 BlockDeviceIoStatus_str(info->io_status));
440 if (info->removable) {
441 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
442 info->locked ? "" : "not ",
443 info->tray_open ? "open" : "closed");
448 if (!inserted) {
449 return;
452 monitor_printf(mon, " Cache mode: %s%s%s\n",
453 inserted->cache->writeback ? "writeback" : "writethrough",
454 inserted->cache->direct ? ", direct" : "",
455 inserted->cache->no_flush ? ", ignore flushes" : "");
457 if (inserted->has_backing_file) {
458 monitor_printf(mon,
459 " Backing file: %s "
460 "(chain depth: %" PRId64 ")\n",
461 inserted->backing_file,
462 inserted->backing_file_depth);
465 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
466 monitor_printf(mon, " Detect zeroes: %s\n",
467 BlockdevDetectZeroesOptions_str(inserted->detect_zeroes));
470 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
471 inserted->iops || inserted->iops_rd || inserted->iops_wr)
473 monitor_printf(mon, " I/O throttling: bps=%" PRId64
474 " bps_rd=%" PRId64 " bps_wr=%" PRId64
475 " bps_max=%" PRId64
476 " bps_rd_max=%" PRId64
477 " bps_wr_max=%" PRId64
478 " iops=%" PRId64 " iops_rd=%" PRId64
479 " iops_wr=%" PRId64
480 " iops_max=%" PRId64
481 " iops_rd_max=%" PRId64
482 " iops_wr_max=%" PRId64
483 " iops_size=%" PRId64
484 " group=%s\n",
485 inserted->bps,
486 inserted->bps_rd,
487 inserted->bps_wr,
488 inserted->bps_max,
489 inserted->bps_rd_max,
490 inserted->bps_wr_max,
491 inserted->iops,
492 inserted->iops_rd,
493 inserted->iops_wr,
494 inserted->iops_max,
495 inserted->iops_rd_max,
496 inserted->iops_wr_max,
497 inserted->iops_size,
498 inserted->group);
501 if (verbose) {
502 monitor_printf(mon, "\nImages:\n");
503 image_info = inserted->image;
504 while (1) {
505 bdrv_image_info_dump((fprintf_function)monitor_printf,
506 mon, image_info);
507 if (image_info->has_backing_image) {
508 image_info = image_info->backing_image;
509 } else {
510 break;
516 void hmp_info_block(Monitor *mon, const QDict *qdict)
518 BlockInfoList *block_list, *info;
519 BlockDeviceInfoList *blockdev_list, *blockdev;
520 const char *device = qdict_get_try_str(qdict, "device");
521 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
522 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
523 bool printed = false;
525 /* Print BlockBackend information */
526 if (!nodes) {
527 block_list = qmp_query_block(NULL);
528 } else {
529 block_list = NULL;
532 for (info = block_list; info; info = info->next) {
533 if (device && strcmp(device, info->value->device)) {
534 continue;
537 if (info != block_list) {
538 monitor_printf(mon, "\n");
541 print_block_info(mon, info->value, info->value->has_inserted
542 ? info->value->inserted : NULL,
543 verbose);
544 printed = true;
547 qapi_free_BlockInfoList(block_list);
549 if ((!device && !nodes) || printed) {
550 return;
553 /* Print node information */
554 blockdev_list = qmp_query_named_block_nodes(NULL);
555 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
556 assert(blockdev->value->has_node_name);
557 if (device && strcmp(device, blockdev->value->node_name)) {
558 continue;
561 if (blockdev != blockdev_list) {
562 monitor_printf(mon, "\n");
565 print_block_info(mon, NULL, blockdev->value, verbose);
567 qapi_free_BlockDeviceInfoList(blockdev_list);
570 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
572 BlockStatsList *stats_list, *stats;
574 stats_list = qmp_query_blockstats(false, false, NULL);
576 for (stats = stats_list; stats; stats = stats->next) {
577 if (!stats->value->has_device) {
578 continue;
581 monitor_printf(mon, "%s:", stats->value->device);
582 monitor_printf(mon, " rd_bytes=%" PRId64
583 " wr_bytes=%" PRId64
584 " rd_operations=%" PRId64
585 " wr_operations=%" PRId64
586 " flush_operations=%" PRId64
587 " wr_total_time_ns=%" PRId64
588 " rd_total_time_ns=%" PRId64
589 " flush_total_time_ns=%" PRId64
590 " rd_merged=%" PRId64
591 " wr_merged=%" PRId64
592 " idle_time_ns=%" PRId64
593 "\n",
594 stats->value->stats->rd_bytes,
595 stats->value->stats->wr_bytes,
596 stats->value->stats->rd_operations,
597 stats->value->stats->wr_operations,
598 stats->value->stats->flush_operations,
599 stats->value->stats->wr_total_time_ns,
600 stats->value->stats->rd_total_time_ns,
601 stats->value->stats->flush_total_time_ns,
602 stats->value->stats->rd_merged,
603 stats->value->stats->wr_merged,
604 stats->value->stats->idle_time_ns);
607 qapi_free_BlockStatsList(stats_list);
610 /* Helper for hmp_info_vnc_clients, _servers */
611 static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
612 const char *name)
614 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
615 name,
616 info->host,
617 info->service,
618 NetworkAddressFamily_str(info->family),
619 info->websocket ? " (Websocket)" : "");
622 /* Helper displaying and auth and crypt info */
623 static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
624 VncPrimaryAuth auth,
625 VncVencryptSubAuth *vencrypt)
627 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
628 VncPrimaryAuth_str(auth),
629 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
632 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
634 while (client) {
635 VncClientInfo *cinfo = client->value;
637 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
638 monitor_printf(mon, " x509_dname: %s\n",
639 cinfo->has_x509_dname ?
640 cinfo->x509_dname : "none");
641 monitor_printf(mon, " sasl_username: %s\n",
642 cinfo->has_sasl_username ?
643 cinfo->sasl_username : "none");
645 client = client->next;
649 static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
651 while (server) {
652 VncServerInfo2 *sinfo = server->value;
653 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
654 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
655 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
656 server = server->next;
660 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
662 VncInfo2List *info2l;
663 Error *err = NULL;
665 info2l = qmp_query_vnc_servers(&err);
666 if (err) {
667 error_report_err(err);
668 return;
670 if (!info2l) {
671 monitor_printf(mon, "None\n");
672 return;
675 while (info2l) {
676 VncInfo2 *info = info2l->value;
677 monitor_printf(mon, "%s:\n", info->id);
678 hmp_info_vnc_servers(mon, info->server);
679 hmp_info_vnc_clients(mon, info->clients);
680 if (!info->server) {
681 /* The server entry displays its auth, we only
682 * need to display in the case of 'reverse' connections
683 * where there's no server.
685 hmp_info_vnc_authcrypt(mon, " ", info->auth,
686 info->has_vencrypt ? &info->vencrypt : NULL);
688 if (info->has_display) {
689 monitor_printf(mon, " Display: %s\n", info->display);
691 info2l = info2l->next;
694 qapi_free_VncInfo2List(info2l);
698 #ifdef CONFIG_SPICE
699 void hmp_info_spice(Monitor *mon, const QDict *qdict)
701 SpiceChannelList *chan;
702 SpiceInfo *info;
703 const char *channel_name;
704 const char * const channel_names[] = {
705 [SPICE_CHANNEL_MAIN] = "main",
706 [SPICE_CHANNEL_DISPLAY] = "display",
707 [SPICE_CHANNEL_INPUTS] = "inputs",
708 [SPICE_CHANNEL_CURSOR] = "cursor",
709 [SPICE_CHANNEL_PLAYBACK] = "playback",
710 [SPICE_CHANNEL_RECORD] = "record",
711 [SPICE_CHANNEL_TUNNEL] = "tunnel",
712 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
713 [SPICE_CHANNEL_USBREDIR] = "usbredir",
714 [SPICE_CHANNEL_PORT] = "port",
715 #if 0
716 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
717 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
718 * as quick fix for build failures with older versions. */
719 [SPICE_CHANNEL_WEBDAV] = "webdav",
720 #endif
723 info = qmp_query_spice(NULL);
725 if (!info->enabled) {
726 monitor_printf(mon, "Server: disabled\n");
727 goto out;
730 monitor_printf(mon, "Server:\n");
731 if (info->has_port) {
732 monitor_printf(mon, " address: %s:%" PRId64 "\n",
733 info->host, info->port);
735 if (info->has_tls_port) {
736 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
737 info->host, info->tls_port);
739 monitor_printf(mon, " migrated: %s\n",
740 info->migrated ? "true" : "false");
741 monitor_printf(mon, " auth: %s\n", info->auth);
742 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
743 monitor_printf(mon, " mouse-mode: %s\n",
744 SpiceQueryMouseMode_str(info->mouse_mode));
746 if (!info->has_channels || info->channels == NULL) {
747 monitor_printf(mon, "Channels: none\n");
748 } else {
749 for (chan = info->channels; chan; chan = chan->next) {
750 monitor_printf(mon, "Channel:\n");
751 monitor_printf(mon, " address: %s:%s%s\n",
752 chan->value->host, chan->value->port,
753 chan->value->tls ? " [tls]" : "");
754 monitor_printf(mon, " session: %" PRId64 "\n",
755 chan->value->connection_id);
756 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
757 chan->value->channel_type, chan->value->channel_id);
759 channel_name = "unknown";
760 if (chan->value->channel_type > 0 &&
761 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
762 channel_names[chan->value->channel_type]) {
763 channel_name = channel_names[chan->value->channel_type];
766 monitor_printf(mon, " channel name: %s\n", channel_name);
770 out:
771 qapi_free_SpiceInfo(info);
773 #endif
775 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
777 BalloonInfo *info;
778 Error *err = NULL;
780 info = qmp_query_balloon(&err);
781 if (err) {
782 error_report_err(err);
783 return;
786 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
788 qapi_free_BalloonInfo(info);
791 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
793 PciMemoryRegionList *region;
795 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
796 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
797 dev->slot, dev->function);
798 monitor_printf(mon, " ");
800 if (dev->class_info->has_desc) {
801 monitor_printf(mon, "%s", dev->class_info->desc);
802 } else {
803 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
806 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
807 dev->id->vendor, dev->id->device);
809 if (dev->has_irq) {
810 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
813 if (dev->has_pci_bridge) {
814 monitor_printf(mon, " BUS %" PRId64 ".\n",
815 dev->pci_bridge->bus->number);
816 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
817 dev->pci_bridge->bus->secondary);
818 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
819 dev->pci_bridge->bus->subordinate);
821 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
822 dev->pci_bridge->bus->io_range->base,
823 dev->pci_bridge->bus->io_range->limit);
825 monitor_printf(mon,
826 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
827 dev->pci_bridge->bus->memory_range->base,
828 dev->pci_bridge->bus->memory_range->limit);
830 monitor_printf(mon, " prefetchable memory range "
831 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
832 dev->pci_bridge->bus->prefetchable_range->base,
833 dev->pci_bridge->bus->prefetchable_range->limit);
836 for (region = dev->regions; region; region = region->next) {
837 uint64_t addr, size;
839 addr = region->value->address;
840 size = region->value->size;
842 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
844 if (!strcmp(region->value->type, "io")) {
845 monitor_printf(mon, "I/O at 0x%04" PRIx64
846 " [0x%04" PRIx64 "].\n",
847 addr, addr + size - 1);
848 } else {
849 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
850 " [0x%08" PRIx64 "].\n",
851 region->value->mem_type_64 ? 64 : 32,
852 region->value->prefetch ? " prefetchable" : "",
853 addr, addr + size - 1);
857 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
859 if (dev->has_pci_bridge) {
860 if (dev->pci_bridge->has_devices) {
861 PciDeviceInfoList *cdev;
862 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
863 hmp_info_pci_device(mon, cdev->value);
869 static int hmp_info_irq_foreach(Object *obj, void *opaque)
871 InterruptStatsProvider *intc;
872 InterruptStatsProviderClass *k;
873 Monitor *mon = opaque;
875 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
876 intc = INTERRUPT_STATS_PROVIDER(obj);
877 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
878 uint64_t *irq_counts;
879 unsigned int nb_irqs, i;
880 if (k->get_statistics &&
881 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
882 if (nb_irqs > 0) {
883 monitor_printf(mon, "IRQ statistics for %s:\n",
884 object_get_typename(obj));
885 for (i = 0; i < nb_irqs; i++) {
886 if (irq_counts[i] > 0) {
887 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
888 irq_counts[i]);
892 } else {
893 monitor_printf(mon, "IRQ statistics not available for %s.\n",
894 object_get_typename(obj));
898 return 0;
901 void hmp_info_irq(Monitor *mon, const QDict *qdict)
903 object_child_foreach_recursive(object_get_root(),
904 hmp_info_irq_foreach, mon);
907 static int hmp_info_pic_foreach(Object *obj, void *opaque)
909 InterruptStatsProvider *intc;
910 InterruptStatsProviderClass *k;
911 Monitor *mon = opaque;
913 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
914 intc = INTERRUPT_STATS_PROVIDER(obj);
915 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
916 if (k->print_info) {
917 k->print_info(intc, mon);
918 } else {
919 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
920 object_get_typename(obj));
924 return 0;
927 void hmp_info_pic(Monitor *mon, const QDict *qdict)
929 object_child_foreach_recursive(object_get_root(),
930 hmp_info_pic_foreach, mon);
933 void hmp_info_pci(Monitor *mon, const QDict *qdict)
935 PciInfoList *info_list, *info;
936 Error *err = NULL;
938 info_list = qmp_query_pci(&err);
939 if (err) {
940 monitor_printf(mon, "PCI devices not supported\n");
941 error_free(err);
942 return;
945 for (info = info_list; info; info = info->next) {
946 PciDeviceInfoList *dev;
948 for (dev = info->value->devices; dev; dev = dev->next) {
949 hmp_info_pci_device(mon, dev->value);
953 qapi_free_PciInfoList(info_list);
956 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
958 BlockJobInfoList *list;
959 Error *err = NULL;
961 list = qmp_query_block_jobs(&err);
962 assert(!err);
964 if (!list) {
965 monitor_printf(mon, "No active jobs\n");
966 return;
969 while (list) {
970 if (strcmp(list->value->type, "stream") == 0) {
971 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
972 " of %" PRId64 " bytes, speed limit %" PRId64
973 " bytes/s\n",
974 list->value->device,
975 list->value->offset,
976 list->value->len,
977 list->value->speed);
978 } else {
979 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
980 " of %" PRId64 " bytes, speed limit %" PRId64
981 " bytes/s\n",
982 list->value->type,
983 list->value->device,
984 list->value->offset,
985 list->value->len,
986 list->value->speed);
988 list = list->next;
991 qapi_free_BlockJobInfoList(list);
994 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
996 TPMInfoList *info_list, *info;
997 Error *err = NULL;
998 unsigned int c = 0;
999 TPMPassthroughOptions *tpo;
1001 info_list = qmp_query_tpm(&err);
1002 if (err) {
1003 monitor_printf(mon, "TPM device not supported\n");
1004 error_free(err);
1005 return;
1008 if (info_list) {
1009 monitor_printf(mon, "TPM device:\n");
1012 for (info = info_list; info; info = info->next) {
1013 TPMInfo *ti = info->value;
1014 monitor_printf(mon, " tpm%d: model=%s\n",
1015 c, TpmModel_str(ti->model));
1017 monitor_printf(mon, " \\ %s: type=%s",
1018 ti->id, TpmTypeOptionsKind_str(ti->options->type));
1020 switch (ti->options->type) {
1021 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
1022 tpo = ti->options->u.passthrough.data;
1023 monitor_printf(mon, "%s%s%s%s",
1024 tpo->has_path ? ",path=" : "",
1025 tpo->has_path ? tpo->path : "",
1026 tpo->has_cancel_path ? ",cancel-path=" : "",
1027 tpo->has_cancel_path ? tpo->cancel_path : "");
1028 break;
1029 case TPM_TYPE_OPTIONS_KIND__MAX:
1030 break;
1032 monitor_printf(mon, "\n");
1033 c++;
1035 qapi_free_TPMInfoList(info_list);
1038 void hmp_quit(Monitor *mon, const QDict *qdict)
1040 monitor_suspend(mon);
1041 qmp_quit(NULL);
1044 void hmp_stop(Monitor *mon, const QDict *qdict)
1046 qmp_stop(NULL);
1049 void hmp_system_reset(Monitor *mon, const QDict *qdict)
1051 qmp_system_reset(NULL);
1054 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
1056 qmp_system_powerdown(NULL);
1059 void hmp_cpu(Monitor *mon, const QDict *qdict)
1061 int64_t cpu_index;
1063 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1064 use it are converted to the QAPI */
1065 cpu_index = qdict_get_int(qdict, "index");
1066 if (monitor_set_cpu(cpu_index) < 0) {
1067 monitor_printf(mon, "invalid CPU index\n");
1071 void hmp_memsave(Monitor *mon, const QDict *qdict)
1073 uint32_t size = qdict_get_int(qdict, "size");
1074 const char *filename = qdict_get_str(qdict, "filename");
1075 uint64_t addr = qdict_get_int(qdict, "val");
1076 Error *err = NULL;
1077 int cpu_index = monitor_get_cpu_index();
1079 if (cpu_index < 0) {
1080 monitor_printf(mon, "No CPU available\n");
1081 return;
1084 qmp_memsave(addr, size, filename, true, cpu_index, &err);
1085 hmp_handle_error(mon, &err);
1088 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1090 uint32_t size = qdict_get_int(qdict, "size");
1091 const char *filename = qdict_get_str(qdict, "filename");
1092 uint64_t addr = qdict_get_int(qdict, "val");
1093 Error *err = NULL;
1095 qmp_pmemsave(addr, size, filename, &err);
1096 hmp_handle_error(mon, &err);
1099 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1101 const char *chardev = qdict_get_str(qdict, "device");
1102 const char *data = qdict_get_str(qdict, "data");
1103 Error *err = NULL;
1105 qmp_ringbuf_write(chardev, data, false, 0, &err);
1107 hmp_handle_error(mon, &err);
1110 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
1112 uint32_t size = qdict_get_int(qdict, "size");
1113 const char *chardev = qdict_get_str(qdict, "device");
1114 char *data;
1115 Error *err = NULL;
1116 int i;
1118 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1119 if (err) {
1120 error_report_err(err);
1121 return;
1124 for (i = 0; data[i]; i++) {
1125 unsigned char ch = data[i];
1127 if (ch == '\\') {
1128 monitor_printf(mon, "\\\\");
1129 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1130 monitor_printf(mon, "\\u%04X", ch);
1131 } else {
1132 monitor_printf(mon, "%c", ch);
1136 monitor_printf(mon, "\n");
1137 g_free(data);
1140 void hmp_cont(Monitor *mon, const QDict *qdict)
1142 Error *err = NULL;
1144 qmp_cont(&err);
1145 hmp_handle_error(mon, &err);
1148 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1150 qmp_system_wakeup(NULL);
1153 void hmp_nmi(Monitor *mon, const QDict *qdict)
1155 Error *err = NULL;
1157 qmp_inject_nmi(&err);
1158 hmp_handle_error(mon, &err);
1161 void hmp_set_link(Monitor *mon, const QDict *qdict)
1163 const char *name = qdict_get_str(qdict, "name");
1164 bool up = qdict_get_bool(qdict, "up");
1165 Error *err = NULL;
1167 qmp_set_link(name, up, &err);
1168 hmp_handle_error(mon, &err);
1171 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1173 const char *device = qdict_get_str(qdict, "device");
1174 const char *password = qdict_get_str(qdict, "password");
1175 Error *err = NULL;
1177 qmp_block_passwd(true, device, false, NULL, password, &err);
1178 hmp_handle_error(mon, &err);
1181 void hmp_balloon(Monitor *mon, const QDict *qdict)
1183 int64_t value = qdict_get_int(qdict, "value");
1184 Error *err = NULL;
1186 qmp_balloon(value, &err);
1187 if (err) {
1188 error_report_err(err);
1192 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1194 const char *device = qdict_get_str(qdict, "device");
1195 int64_t size = qdict_get_int(qdict, "size");
1196 Error *err = NULL;
1198 qmp_block_resize(true, device, false, NULL, size, &err);
1199 hmp_handle_error(mon, &err);
1202 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1204 const char *filename = qdict_get_str(qdict, "target");
1205 const char *format = qdict_get_try_str(qdict, "format");
1206 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1207 bool full = qdict_get_try_bool(qdict, "full", false);
1208 Error *err = NULL;
1209 DriveMirror mirror = {
1210 .device = (char *)qdict_get_str(qdict, "device"),
1211 .target = (char *)filename,
1212 .has_format = !!format,
1213 .format = (char *)format,
1214 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1215 .has_mode = true,
1216 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1217 .unmap = true,
1220 if (!filename) {
1221 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1222 hmp_handle_error(mon, &err);
1223 return;
1225 qmp_drive_mirror(&mirror, &err);
1226 hmp_handle_error(mon, &err);
1229 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1231 const char *device = qdict_get_str(qdict, "device");
1232 const char *filename = qdict_get_str(qdict, "target");
1233 const char *format = qdict_get_try_str(qdict, "format");
1234 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1235 bool full = qdict_get_try_bool(qdict, "full", false);
1236 bool compress = qdict_get_try_bool(qdict, "compress", false);
1237 Error *err = NULL;
1238 DriveBackup backup = {
1239 .device = (char *)device,
1240 .target = (char *)filename,
1241 .has_format = !!format,
1242 .format = (char *)format,
1243 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1244 .has_mode = true,
1245 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1246 .has_compress = !!compress,
1247 .compress = compress,
1250 if (!filename) {
1251 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1252 hmp_handle_error(mon, &err);
1253 return;
1256 qmp_drive_backup(&backup, &err);
1257 hmp_handle_error(mon, &err);
1260 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1262 const char *device = qdict_get_str(qdict, "device");
1263 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1264 const char *format = qdict_get_try_str(qdict, "format");
1265 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1266 enum NewImageMode mode;
1267 Error *err = NULL;
1269 if (!filename) {
1270 /* In the future, if 'snapshot-file' is not specified, the snapshot
1271 will be taken internally. Today it's actually required. */
1272 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1273 hmp_handle_error(mon, &err);
1274 return;
1277 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1278 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1279 filename, false, NULL,
1280 !!format, format,
1281 true, mode, &err);
1282 hmp_handle_error(mon, &err);
1285 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1287 const char *device = qdict_get_str(qdict, "device");
1288 const char *name = qdict_get_str(qdict, "name");
1289 Error *err = NULL;
1291 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1292 hmp_handle_error(mon, &err);
1295 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1297 const char *device = qdict_get_str(qdict, "device");
1298 const char *name = qdict_get_str(qdict, "name");
1299 const char *id = qdict_get_try_str(qdict, "id");
1300 Error *err = NULL;
1302 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1303 true, name, &err);
1304 hmp_handle_error(mon, &err);
1307 void hmp_loadvm(Monitor *mon, const QDict *qdict)
1309 int saved_vm_running = runstate_is_running();
1310 const char *name = qdict_get_str(qdict, "name");
1311 Error *err = NULL;
1313 vm_stop(RUN_STATE_RESTORE_VM);
1315 if (load_snapshot(name, &err) == 0 && saved_vm_running) {
1316 vm_start();
1318 hmp_handle_error(mon, &err);
1321 void hmp_savevm(Monitor *mon, const QDict *qdict)
1323 Error *err = NULL;
1325 save_snapshot(qdict_get_try_str(qdict, "name"), &err);
1326 hmp_handle_error(mon, &err);
1329 void hmp_delvm(Monitor *mon, const QDict *qdict)
1331 BlockDriverState *bs;
1332 Error *err;
1333 const char *name = qdict_get_str(qdict, "name");
1335 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
1336 error_reportf_err(err,
1337 "Error while deleting snapshot on device '%s': ",
1338 bdrv_get_device_name(bs));
1342 void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
1344 BlockDriverState *bs, *bs1;
1345 BdrvNextIterator it1;
1346 QEMUSnapshotInfo *sn_tab, *sn;
1347 bool no_snapshot = true;
1348 int nb_sns, i;
1349 int total;
1350 int *global_snapshots;
1351 AioContext *aio_context;
1353 typedef struct SnapshotEntry {
1354 QEMUSnapshotInfo sn;
1355 QTAILQ_ENTRY(SnapshotEntry) next;
1356 } SnapshotEntry;
1358 typedef struct ImageEntry {
1359 const char *imagename;
1360 QTAILQ_ENTRY(ImageEntry) next;
1361 QTAILQ_HEAD(, SnapshotEntry) snapshots;
1362 } ImageEntry;
1364 QTAILQ_HEAD(, ImageEntry) image_list =
1365 QTAILQ_HEAD_INITIALIZER(image_list);
1367 ImageEntry *image_entry, *next_ie;
1368 SnapshotEntry *snapshot_entry;
1370 bs = bdrv_all_find_vmstate_bs();
1371 if (!bs) {
1372 monitor_printf(mon, "No available block device supports snapshots\n");
1373 return;
1375 aio_context = bdrv_get_aio_context(bs);
1377 aio_context_acquire(aio_context);
1378 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
1379 aio_context_release(aio_context);
1381 if (nb_sns < 0) {
1382 monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
1383 return;
1386 for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) {
1387 int bs1_nb_sns = 0;
1388 ImageEntry *ie;
1389 SnapshotEntry *se;
1390 AioContext *ctx = bdrv_get_aio_context(bs1);
1392 aio_context_acquire(ctx);
1393 if (bdrv_can_snapshot(bs1)) {
1394 sn = NULL;
1395 bs1_nb_sns = bdrv_snapshot_list(bs1, &sn);
1396 if (bs1_nb_sns > 0) {
1397 no_snapshot = false;
1398 ie = g_new0(ImageEntry, 1);
1399 ie->imagename = bdrv_get_device_name(bs1);
1400 QTAILQ_INIT(&ie->snapshots);
1401 QTAILQ_INSERT_TAIL(&image_list, ie, next);
1402 for (i = 0; i < bs1_nb_sns; i++) {
1403 se = g_new0(SnapshotEntry, 1);
1404 se->sn = sn[i];
1405 QTAILQ_INSERT_TAIL(&ie->snapshots, se, next);
1408 g_free(sn);
1410 aio_context_release(ctx);
1413 if (no_snapshot) {
1414 monitor_printf(mon, "There is no snapshot available.\n");
1415 return;
1418 global_snapshots = g_new0(int, nb_sns);
1419 total = 0;
1420 for (i = 0; i < nb_sns; i++) {
1421 SnapshotEntry *next_sn;
1422 if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) {
1423 global_snapshots[total] = i;
1424 total++;
1425 QTAILQ_FOREACH(image_entry, &image_list, next) {
1426 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots,
1427 next, next_sn) {
1428 if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) {
1429 QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry,
1430 next);
1431 g_free(snapshot_entry);
1438 monitor_printf(mon, "List of snapshots present on all disks:\n");
1440 if (total > 0) {
1441 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1442 monitor_printf(mon, "\n");
1443 for (i = 0; i < total; i++) {
1444 sn = &sn_tab[global_snapshots[i]];
1445 /* The ID is not guaranteed to be the same on all images, so
1446 * overwrite it.
1448 pstrcpy(sn->id_str, sizeof(sn->id_str), "--");
1449 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, sn);
1450 monitor_printf(mon, "\n");
1452 } else {
1453 monitor_printf(mon, "None\n");
1456 QTAILQ_FOREACH(image_entry, &image_list, next) {
1457 if (QTAILQ_EMPTY(&image_entry->snapshots)) {
1458 continue;
1460 monitor_printf(mon,
1461 "\nList of partial (non-loadable) snapshots on '%s':\n",
1462 image_entry->imagename);
1463 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1464 monitor_printf(mon, "\n");
1465 QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) {
1466 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon,
1467 &snapshot_entry->sn);
1468 monitor_printf(mon, "\n");
1472 QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) {
1473 SnapshotEntry *next_sn;
1474 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next,
1475 next_sn) {
1476 g_free(snapshot_entry);
1478 g_free(image_entry);
1480 g_free(sn_tab);
1481 g_free(global_snapshots);
1485 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1487 qmp_migrate_cancel(NULL);
1490 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1492 Error *err = NULL;
1493 const char *uri = qdict_get_str(qdict, "uri");
1495 qmp_migrate_incoming(uri, &err);
1497 hmp_handle_error(mon, &err);
1500 /* Kept for backwards compatibility */
1501 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1503 double value = qdict_get_double(qdict, "value");
1504 qmp_migrate_set_downtime(value, NULL);
1507 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1509 int64_t value = qdict_get_int(qdict, "value");
1510 Error *err = NULL;
1512 qmp_migrate_set_cache_size(value, &err);
1513 if (err) {
1514 error_report_err(err);
1515 return;
1519 /* Kept for backwards compatibility */
1520 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1522 int64_t value = qdict_get_int(qdict, "value");
1523 qmp_migrate_set_speed(value, NULL);
1526 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1528 const char *cap = qdict_get_str(qdict, "capability");
1529 bool state = qdict_get_bool(qdict, "state");
1530 Error *err = NULL;
1531 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1532 int val;
1534 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
1535 if (val < 0) {
1536 goto end;
1539 caps->value = g_malloc0(sizeof(*caps->value));
1540 caps->value->capability = val;
1541 caps->value->state = state;
1542 caps->next = NULL;
1543 qmp_migrate_set_capabilities(caps, &err);
1545 end:
1546 qapi_free_MigrationCapabilityStatusList(caps);
1548 if (err) {
1549 error_report_err(err);
1553 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1555 const char *param = qdict_get_str(qdict, "parameter");
1556 const char *valuestr = qdict_get_str(qdict, "value");
1557 Visitor *v = string_input_visitor_new(valuestr);
1558 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
1559 uint64_t valuebw = 0;
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 default:
1632 assert(0);
1635 if (err) {
1636 goto cleanup;
1639 qmp_migrate_set_parameters(p, &err);
1641 cleanup:
1642 qapi_free_MigrateSetParameters(p);
1643 visit_free(v);
1644 if (err) {
1645 error_report_err(err);
1649 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1651 Error *err = NULL;
1652 const char *protocol = qdict_get_str(qdict, "protocol");
1653 const char *hostname = qdict_get_str(qdict, "hostname");
1654 bool has_port = qdict_haskey(qdict, "port");
1655 int port = qdict_get_try_int(qdict, "port", -1);
1656 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1657 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1658 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1660 qmp_client_migrate_info(protocol, hostname,
1661 has_port, port, has_tls_port, tls_port,
1662 !!cert_subject, cert_subject, &err);
1663 hmp_handle_error(mon, &err);
1666 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1668 Error *err = NULL;
1669 qmp_migrate_start_postcopy(&err);
1670 hmp_handle_error(mon, &err);
1673 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1675 Error *err = NULL;
1677 qmp_x_colo_lost_heartbeat(&err);
1678 hmp_handle_error(mon, &err);
1681 void hmp_set_password(Monitor *mon, const QDict *qdict)
1683 const char *protocol = qdict_get_str(qdict, "protocol");
1684 const char *password = qdict_get_str(qdict, "password");
1685 const char *connected = qdict_get_try_str(qdict, "connected");
1686 Error *err = NULL;
1688 qmp_set_password(protocol, password, !!connected, connected, &err);
1689 hmp_handle_error(mon, &err);
1692 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1694 const char *protocol = qdict_get_str(qdict, "protocol");
1695 const char *whenstr = qdict_get_str(qdict, "time");
1696 Error *err = NULL;
1698 qmp_expire_password(protocol, whenstr, &err);
1699 hmp_handle_error(mon, &err);
1702 void hmp_eject(Monitor *mon, const QDict *qdict)
1704 bool force = qdict_get_try_bool(qdict, "force", false);
1705 const char *device = qdict_get_str(qdict, "device");
1706 Error *err = NULL;
1708 qmp_eject(true, device, false, NULL, true, force, &err);
1709 hmp_handle_error(mon, &err);
1712 static void hmp_change_read_arg(void *opaque, const char *password,
1713 void *readline_opaque)
1715 qmp_change_vnc_password(password, NULL);
1716 monitor_read_command(opaque, 1);
1719 void hmp_change(Monitor *mon, const QDict *qdict)
1721 const char *device = qdict_get_str(qdict, "device");
1722 const char *target = qdict_get_str(qdict, "target");
1723 const char *arg = qdict_get_try_str(qdict, "arg");
1724 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1725 BlockdevChangeReadOnlyMode read_only_mode = 0;
1726 Error *err = NULL;
1728 if (strcmp(device, "vnc") == 0) {
1729 if (read_only) {
1730 monitor_printf(mon,
1731 "Parameter 'read-only-mode' is invalid for VNC\n");
1732 return;
1734 if (strcmp(target, "passwd") == 0 ||
1735 strcmp(target, "password") == 0) {
1736 if (!arg) {
1737 monitor_read_password(mon, hmp_change_read_arg, NULL);
1738 return;
1741 qmp_change("vnc", target, !!arg, arg, &err);
1742 } else {
1743 if (read_only) {
1744 read_only_mode =
1745 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
1746 read_only,
1747 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1748 if (err) {
1749 hmp_handle_error(mon, &err);
1750 return;
1754 qmp_blockdev_change_medium(true, device, false, NULL, target,
1755 !!arg, arg, !!read_only, read_only_mode,
1756 &err);
1759 hmp_handle_error(mon, &err);
1762 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1764 Error *err = NULL;
1765 BlockIOThrottle throttle = {
1766 .has_device = true,
1767 .device = (char *) qdict_get_str(qdict, "device"),
1768 .bps = qdict_get_int(qdict, "bps"),
1769 .bps_rd = qdict_get_int(qdict, "bps_rd"),
1770 .bps_wr = qdict_get_int(qdict, "bps_wr"),
1771 .iops = qdict_get_int(qdict, "iops"),
1772 .iops_rd = qdict_get_int(qdict, "iops_rd"),
1773 .iops_wr = qdict_get_int(qdict, "iops_wr"),
1776 qmp_block_set_io_throttle(&throttle, &err);
1777 hmp_handle_error(mon, &err);
1780 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1782 Error *error = NULL;
1783 const char *device = qdict_get_str(qdict, "device");
1784 const char *base = qdict_get_try_str(qdict, "base");
1785 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1787 qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
1788 false, NULL, qdict_haskey(qdict, "speed"), speed,
1789 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1791 hmp_handle_error(mon, &error);
1794 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1796 Error *error = NULL;
1797 const char *device = qdict_get_str(qdict, "device");
1798 int64_t value = qdict_get_int(qdict, "speed");
1800 qmp_block_job_set_speed(device, value, &error);
1802 hmp_handle_error(mon, &error);
1805 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1807 Error *error = NULL;
1808 const char *device = qdict_get_str(qdict, "device");
1809 bool force = qdict_get_try_bool(qdict, "force", false);
1811 qmp_block_job_cancel(device, true, force, &error);
1813 hmp_handle_error(mon, &error);
1816 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1818 Error *error = NULL;
1819 const char *device = qdict_get_str(qdict, "device");
1821 qmp_block_job_pause(device, &error);
1823 hmp_handle_error(mon, &error);
1826 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1828 Error *error = NULL;
1829 const char *device = qdict_get_str(qdict, "device");
1831 qmp_block_job_resume(device, &error);
1833 hmp_handle_error(mon, &error);
1836 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1838 Error *error = NULL;
1839 const char *device = qdict_get_str(qdict, "device");
1841 qmp_block_job_complete(device, &error);
1843 hmp_handle_error(mon, &error);
1846 typedef struct HMPMigrationStatus
1848 QEMUTimer *timer;
1849 Monitor *mon;
1850 bool is_block_migration;
1851 } HMPMigrationStatus;
1853 static void hmp_migrate_status_cb(void *opaque)
1855 HMPMigrationStatus *status = opaque;
1856 MigrationInfo *info;
1858 info = qmp_query_migrate(NULL);
1859 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1860 info->status == MIGRATION_STATUS_SETUP) {
1861 if (info->has_disk) {
1862 int progress;
1864 if (info->disk->remaining) {
1865 progress = info->disk->transferred * 100 / info->disk->total;
1866 } else {
1867 progress = 100;
1870 monitor_printf(status->mon, "Completed %d %%\r", progress);
1871 monitor_flush(status->mon);
1874 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1875 } else {
1876 if (status->is_block_migration) {
1877 monitor_printf(status->mon, "\n");
1879 if (info->has_error_desc) {
1880 error_report("%s", info->error_desc);
1882 monitor_resume(status->mon);
1883 timer_del(status->timer);
1884 g_free(status);
1887 qapi_free_MigrationInfo(info);
1890 void hmp_migrate(Monitor *mon, const QDict *qdict)
1892 bool detach = qdict_get_try_bool(qdict, "detach", false);
1893 bool blk = qdict_get_try_bool(qdict, "blk", false);
1894 bool inc = qdict_get_try_bool(qdict, "inc", false);
1895 const char *uri = qdict_get_str(qdict, "uri");
1896 Error *err = NULL;
1898 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1899 if (err) {
1900 error_report_err(err);
1901 return;
1904 if (!detach) {
1905 HMPMigrationStatus *status;
1907 if (monitor_suspend(mon) < 0) {
1908 monitor_printf(mon, "terminal does not allow synchronous "
1909 "migration, continuing detached\n");
1910 return;
1913 status = g_malloc0(sizeof(*status));
1914 status->mon = mon;
1915 status->is_block_migration = blk || inc;
1916 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1917 status);
1918 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1922 void hmp_device_add(Monitor *mon, const QDict *qdict)
1924 Error *err = NULL;
1926 qmp_device_add((QDict *)qdict, NULL, &err);
1927 hmp_handle_error(mon, &err);
1930 void hmp_device_del(Monitor *mon, const QDict *qdict)
1932 const char *id = qdict_get_str(qdict, "id");
1933 Error *err = NULL;
1935 qmp_device_del(id, &err);
1936 hmp_handle_error(mon, &err);
1939 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1941 Error *err = NULL;
1942 bool paging = qdict_get_try_bool(qdict, "paging", false);
1943 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
1944 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
1945 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
1946 const char *file = qdict_get_str(qdict, "filename");
1947 bool has_begin = qdict_haskey(qdict, "begin");
1948 bool has_length = qdict_haskey(qdict, "length");
1949 bool has_detach = qdict_haskey(qdict, "detach");
1950 int64_t begin = 0;
1951 int64_t length = 0;
1952 bool detach = false;
1953 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1954 char *prot;
1956 if (zlib + lzo + snappy > 1) {
1957 error_setg(&err, "only one of '-z|-l|-s' can be set");
1958 hmp_handle_error(mon, &err);
1959 return;
1962 if (zlib) {
1963 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1966 if (lzo) {
1967 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1970 if (snappy) {
1971 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1974 if (has_begin) {
1975 begin = qdict_get_int(qdict, "begin");
1977 if (has_length) {
1978 length = qdict_get_int(qdict, "length");
1980 if (has_detach) {
1981 detach = qdict_get_bool(qdict, "detach");
1984 prot = g_strconcat("file:", file, NULL);
1986 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
1987 has_length, length, true, dump_format, &err);
1988 hmp_handle_error(mon, &err);
1989 g_free(prot);
1992 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1994 Error *err = NULL;
1995 QemuOpts *opts;
1997 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1998 if (err) {
1999 goto out;
2002 netdev_add(opts, &err);
2003 if (err) {
2004 qemu_opts_del(opts);
2007 out:
2008 hmp_handle_error(mon, &err);
2011 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
2013 const char *id = qdict_get_str(qdict, "id");
2014 Error *err = NULL;
2016 qmp_netdev_del(id, &err);
2017 hmp_handle_error(mon, &err);
2020 void hmp_object_add(Monitor *mon, const QDict *qdict)
2022 Error *err = NULL;
2023 QemuOpts *opts;
2024 Object *obj = NULL;
2026 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
2027 if (err) {
2028 hmp_handle_error(mon, &err);
2029 return;
2032 obj = user_creatable_add_opts(opts, &err);
2033 qemu_opts_del(opts);
2035 if (err) {
2036 hmp_handle_error(mon, &err);
2038 if (obj) {
2039 object_unref(obj);
2043 void hmp_getfd(Monitor *mon, const QDict *qdict)
2045 const char *fdname = qdict_get_str(qdict, "fdname");
2046 Error *err = NULL;
2048 qmp_getfd(fdname, &err);
2049 hmp_handle_error(mon, &err);
2052 void hmp_closefd(Monitor *mon, const QDict *qdict)
2054 const char *fdname = qdict_get_str(qdict, "fdname");
2055 Error *err = NULL;
2057 qmp_closefd(fdname, &err);
2058 hmp_handle_error(mon, &err);
2061 void hmp_sendkey(Monitor *mon, const QDict *qdict)
2063 const char *keys = qdict_get_str(qdict, "keys");
2064 KeyValueList *keylist, *head = NULL, *tmp = NULL;
2065 int has_hold_time = qdict_haskey(qdict, "hold-time");
2066 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
2067 Error *err = NULL;
2068 char *separator;
2069 int keyname_len;
2071 while (1) {
2072 separator = strchr(keys, '-');
2073 keyname_len = separator ? separator - keys : strlen(keys);
2075 /* Be compatible with old interface, convert user inputted "<" */
2076 if (keys[0] == '<' && keyname_len == 1) {
2077 keys = "less";
2078 keyname_len = 4;
2081 keylist = g_malloc0(sizeof(*keylist));
2082 keylist->value = g_malloc0(sizeof(*keylist->value));
2084 if (!head) {
2085 head = keylist;
2087 if (tmp) {
2088 tmp->next = keylist;
2090 tmp = keylist;
2092 if (strstart(keys, "0x", NULL)) {
2093 char *endp;
2094 int value = strtoul(keys, &endp, 0);
2095 assert(endp <= keys + keyname_len);
2096 if (endp != keys + keyname_len) {
2097 goto err_out;
2099 keylist->value->type = KEY_VALUE_KIND_NUMBER;
2100 keylist->value->u.number.data = value;
2101 } else {
2102 int idx = index_from_key(keys, keyname_len);
2103 if (idx == Q_KEY_CODE__MAX) {
2104 goto err_out;
2106 keylist->value->type = KEY_VALUE_KIND_QCODE;
2107 keylist->value->u.qcode.data = idx;
2110 if (!separator) {
2111 break;
2113 keys = separator + 1;
2116 qmp_send_key(head, has_hold_time, hold_time, &err);
2117 hmp_handle_error(mon, &err);
2119 out:
2120 qapi_free_KeyValueList(head);
2121 return;
2123 err_out:
2124 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
2125 goto out;
2128 void hmp_screendump(Monitor *mon, const QDict *qdict)
2130 const char *filename = qdict_get_str(qdict, "filename");
2131 Error *err = NULL;
2133 qmp_screendump(filename, &err);
2134 hmp_handle_error(mon, &err);
2137 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
2139 const char *uri = qdict_get_str(qdict, "uri");
2140 bool writable = qdict_get_try_bool(qdict, "writable", false);
2141 bool all = qdict_get_try_bool(qdict, "all", false);
2142 Error *local_err = NULL;
2143 BlockInfoList *block_list, *info;
2144 SocketAddress *addr;
2146 if (writable && !all) {
2147 error_setg(&local_err, "-w only valid together with -a");
2148 goto exit;
2151 /* First check if the address is valid and start the server. */
2152 addr = socket_parse(uri, &local_err);
2153 if (local_err != NULL) {
2154 goto exit;
2157 nbd_server_start(addr, NULL, &local_err);
2158 qapi_free_SocketAddress(addr);
2159 if (local_err != NULL) {
2160 goto exit;
2163 if (!all) {
2164 return;
2167 /* Then try adding all block devices. If one fails, close all and
2168 * exit.
2170 block_list = qmp_query_block(NULL);
2172 for (info = block_list; info; info = info->next) {
2173 if (!info->value->has_inserted) {
2174 continue;
2177 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
2179 if (local_err != NULL) {
2180 qmp_nbd_server_stop(NULL);
2181 break;
2185 qapi_free_BlockInfoList(block_list);
2187 exit:
2188 hmp_handle_error(mon, &local_err);
2191 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
2193 const char *device = qdict_get_str(qdict, "device");
2194 bool writable = qdict_get_try_bool(qdict, "writable", false);
2195 Error *local_err = NULL;
2197 qmp_nbd_server_add(device, true, writable, &local_err);
2199 if (local_err != NULL) {
2200 hmp_handle_error(mon, &local_err);
2204 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
2206 Error *err = NULL;
2208 qmp_nbd_server_stop(&err);
2209 hmp_handle_error(mon, &err);
2212 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
2214 int cpuid;
2215 Error *err = NULL;
2217 cpuid = qdict_get_int(qdict, "id");
2218 qmp_cpu_add(cpuid, &err);
2219 hmp_handle_error(mon, &err);
2222 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2224 const char *args = qdict_get_str(qdict, "args");
2225 Error *err = NULL;
2226 QemuOpts *opts;
2228 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
2229 if (opts == NULL) {
2230 error_setg(&err, "Parsing chardev args failed");
2231 } else {
2232 qemu_chr_new_from_opts(opts, &err);
2233 qemu_opts_del(opts);
2235 hmp_handle_error(mon, &err);
2238 void hmp_chardev_change(Monitor *mon, const QDict *qdict)
2240 const char *args = qdict_get_str(qdict, "args");
2241 const char *id;
2242 Error *err = NULL;
2243 ChardevBackend *backend = NULL;
2244 ChardevReturn *ret = NULL;
2245 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
2246 true);
2247 if (!opts) {
2248 error_setg(&err, "Parsing chardev args failed");
2249 goto end;
2252 id = qdict_get_str(qdict, "id");
2253 if (qemu_opts_id(opts)) {
2254 error_setg(&err, "Unexpected 'id' parameter");
2255 goto end;
2258 backend = qemu_chr_parse_opts(opts, &err);
2259 if (!backend) {
2260 goto end;
2263 ret = qmp_chardev_change(id, backend, &err);
2265 end:
2266 qapi_free_ChardevReturn(ret);
2267 qapi_free_ChardevBackend(backend);
2268 qemu_opts_del(opts);
2269 hmp_handle_error(mon, &err);
2272 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2274 Error *local_err = NULL;
2276 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
2277 hmp_handle_error(mon, &local_err);
2280 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
2282 Error *local_err = NULL;
2284 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
2285 hmp_handle_error(mon, &local_err);
2288 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
2290 BlockBackend *blk;
2291 BlockBackend *local_blk = NULL;
2292 AioContext *aio_context;
2293 const char* device = qdict_get_str(qdict, "device");
2294 const char* command = qdict_get_str(qdict, "command");
2295 Error *err = NULL;
2296 int ret;
2298 blk = blk_by_name(device);
2299 if (!blk) {
2300 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
2301 if (bs) {
2302 blk = local_blk = blk_new(0, BLK_PERM_ALL);
2303 ret = blk_insert_bs(blk, bs, &err);
2304 if (ret < 0) {
2305 goto fail;
2307 } else {
2308 goto fail;
2312 aio_context = blk_get_aio_context(blk);
2313 aio_context_acquire(aio_context);
2316 * Notably absent: Proper permission management. This is sad, but it seems
2317 * almost impossible to achieve without changing the semantics and thereby
2318 * limiting the use cases of the qemu-io HMP command.
2320 * In an ideal world we would unconditionally create a new BlockBackend for
2321 * qemuio_command(), but we have commands like 'reopen' and want them to
2322 * take effect on the exact BlockBackend whose name the user passed instead
2323 * of just on a temporary copy of it.
2325 * Another problem is that deleting the temporary BlockBackend involves
2326 * draining all requests on it first, but some qemu-iotests cases want to
2327 * issue multiple aio_read/write requests and expect them to complete in
2328 * the background while the monitor has already returned.
2330 * This is also what prevents us from saving the original permissions and
2331 * restoring them later: We can't revoke permissions until all requests
2332 * have completed, and we don't know when that is nor can we really let
2333 * anything else run before we have revoken them to avoid race conditions.
2335 * What happens now is that command() in qemu-io-cmds.c can extend the
2336 * permissions if necessary for the qemu-io command. And they simply stay
2337 * extended, possibly resulting in a read-only guest device keeping write
2338 * permissions. Ugly, but it appears to be the lesser evil.
2340 qemuio_command(blk, command);
2342 aio_context_release(aio_context);
2344 fail:
2345 blk_unref(local_blk);
2346 hmp_handle_error(mon, &err);
2349 void hmp_object_del(Monitor *mon, const QDict *qdict)
2351 const char *id = qdict_get_str(qdict, "id");
2352 Error *err = NULL;
2354 user_creatable_del(id, &err);
2355 hmp_handle_error(mon, &err);
2358 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
2360 Error *err = NULL;
2361 MemdevList *memdev_list = qmp_query_memdev(&err);
2362 MemdevList *m = memdev_list;
2363 Visitor *v;
2364 char *str;
2366 while (m) {
2367 v = string_output_visitor_new(false, &str);
2368 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
2369 monitor_printf(mon, "memory backend: %s\n", m->value->id);
2370 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
2371 monitor_printf(mon, " merge: %s\n",
2372 m->value->merge ? "true" : "false");
2373 monitor_printf(mon, " dump: %s\n",
2374 m->value->dump ? "true" : "false");
2375 monitor_printf(mon, " prealloc: %s\n",
2376 m->value->prealloc ? "true" : "false");
2377 monitor_printf(mon, " policy: %s\n",
2378 HostMemPolicy_str(m->value->policy));
2379 visit_complete(v, &str);
2380 monitor_printf(mon, " host nodes: %s\n", str);
2382 g_free(str);
2383 visit_free(v);
2384 m = m->next;
2387 monitor_printf(mon, "\n");
2389 qapi_free_MemdevList(memdev_list);
2392 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2394 Error *err = NULL;
2395 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2396 MemoryDeviceInfoList *info;
2397 MemoryDeviceInfo *value;
2398 PCDIMMDeviceInfo *di;
2400 for (info = info_list; info; info = info->next) {
2401 value = info->value;
2403 if (value) {
2404 switch (value->type) {
2405 case MEMORY_DEVICE_INFO_KIND_DIMM:
2406 di = value->u.dimm.data;
2408 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2409 MemoryDeviceInfoKind_str(value->type),
2410 di->id ? di->id : "");
2411 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2412 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2413 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2414 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2415 monitor_printf(mon, " memdev: %s\n", di->memdev);
2416 monitor_printf(mon, " hotplugged: %s\n",
2417 di->hotplugged ? "true" : "false");
2418 monitor_printf(mon, " hotpluggable: %s\n",
2419 di->hotpluggable ? "true" : "false");
2420 break;
2421 default:
2422 break;
2427 qapi_free_MemoryDeviceInfoList(info_list);
2430 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2432 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2433 IOThreadInfoList *info;
2434 IOThreadInfo *value;
2436 for (info = info_list; info; info = info->next) {
2437 value = info->value;
2438 monitor_printf(mon, "%s:\n", value->id);
2439 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
2440 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2441 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
2442 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
2445 qapi_free_IOThreadInfoList(info_list);
2448 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2450 const char *path = qdict_get_try_str(qdict, "path");
2451 ObjectPropertyInfoList *list;
2452 Error *err = NULL;
2454 if (path == NULL) {
2455 monitor_printf(mon, "/\n");
2456 return;
2459 list = qmp_qom_list(path, &err);
2460 if (err == NULL) {
2461 ObjectPropertyInfoList *start = list;
2462 while (list != NULL) {
2463 ObjectPropertyInfo *value = list->value;
2465 monitor_printf(mon, "%s (%s)\n",
2466 value->name, value->type);
2467 list = list->next;
2469 qapi_free_ObjectPropertyInfoList(start);
2471 hmp_handle_error(mon, &err);
2474 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2476 const char *path = qdict_get_str(qdict, "path");
2477 const char *property = qdict_get_str(qdict, "property");
2478 const char *value = qdict_get_str(qdict, "value");
2479 Error *err = NULL;
2480 bool ambiguous = false;
2481 Object *obj;
2483 obj = object_resolve_path(path, &ambiguous);
2484 if (obj == NULL) {
2485 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2486 "Device '%s' not found", path);
2487 } else {
2488 if (ambiguous) {
2489 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2491 object_property_parse(obj, value, property, &err);
2493 hmp_handle_error(mon, &err);
2496 void hmp_rocker(Monitor *mon, const QDict *qdict)
2498 const char *name = qdict_get_str(qdict, "name");
2499 RockerSwitch *rocker;
2500 Error *err = NULL;
2502 rocker = qmp_query_rocker(name, &err);
2503 if (err != NULL) {
2504 hmp_handle_error(mon, &err);
2505 return;
2508 monitor_printf(mon, "name: %s\n", rocker->name);
2509 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2510 monitor_printf(mon, "ports: %d\n", rocker->ports);
2512 qapi_free_RockerSwitch(rocker);
2515 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2517 RockerPortList *list, *port;
2518 const char *name = qdict_get_str(qdict, "name");
2519 Error *err = NULL;
2521 list = qmp_query_rocker_ports(name, &err);
2522 if (err != NULL) {
2523 hmp_handle_error(mon, &err);
2524 return;
2527 monitor_printf(mon, " ena/ speed/ auto\n");
2528 monitor_printf(mon, " port link duplex neg?\n");
2530 for (port = list; port; port = port->next) {
2531 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2532 port->value->name,
2533 port->value->enabled ? port->value->link_up ?
2534 "up" : "down" : "!ena",
2535 port->value->speed == 10000 ? "10G" : "??",
2536 port->value->duplex ? "FD" : "HD",
2537 port->value->autoneg ? "Yes" : "No");
2540 qapi_free_RockerPortList(list);
2543 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2545 RockerOfDpaFlowList *list, *info;
2546 const char *name = qdict_get_str(qdict, "name");
2547 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2548 Error *err = NULL;
2550 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2551 if (err != NULL) {
2552 hmp_handle_error(mon, &err);
2553 return;
2556 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2558 for (info = list; info; info = info->next) {
2559 RockerOfDpaFlow *flow = info->value;
2560 RockerOfDpaFlowKey *key = flow->key;
2561 RockerOfDpaFlowMask *mask = flow->mask;
2562 RockerOfDpaFlowAction *action = flow->action;
2564 if (flow->hits) {
2565 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2566 key->priority, key->tbl_id, flow->hits);
2567 } else {
2568 monitor_printf(mon, "%-4d %-3d ",
2569 key->priority, key->tbl_id);
2572 if (key->has_in_pport) {
2573 monitor_printf(mon, " pport %d", key->in_pport);
2574 if (mask->has_in_pport) {
2575 monitor_printf(mon, "(0x%x)", mask->in_pport);
2579 if (key->has_vlan_id) {
2580 monitor_printf(mon, " vlan %d",
2581 key->vlan_id & VLAN_VID_MASK);
2582 if (mask->has_vlan_id) {
2583 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2587 if (key->has_tunnel_id) {
2588 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2589 if (mask->has_tunnel_id) {
2590 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2594 if (key->has_eth_type) {
2595 switch (key->eth_type) {
2596 case 0x0806:
2597 monitor_printf(mon, " ARP");
2598 break;
2599 case 0x0800:
2600 monitor_printf(mon, " IP");
2601 break;
2602 case 0x86dd:
2603 monitor_printf(mon, " IPv6");
2604 break;
2605 case 0x8809:
2606 monitor_printf(mon, " LACP");
2607 break;
2608 case 0x88cc:
2609 monitor_printf(mon, " LLDP");
2610 break;
2611 default:
2612 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2613 break;
2617 if (key->has_eth_src) {
2618 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2619 (mask->has_eth_src) &&
2620 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2621 monitor_printf(mon, " src <any mcast/bcast>");
2622 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2623 (mask->has_eth_src) &&
2624 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2625 monitor_printf(mon, " src <any ucast>");
2626 } else {
2627 monitor_printf(mon, " src %s", key->eth_src);
2628 if (mask->has_eth_src) {
2629 monitor_printf(mon, "(%s)", mask->eth_src);
2634 if (key->has_eth_dst) {
2635 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2636 (mask->has_eth_dst) &&
2637 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2638 monitor_printf(mon, " dst <any mcast/bcast>");
2639 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2640 (mask->has_eth_dst) &&
2641 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2642 monitor_printf(mon, " dst <any ucast>");
2643 } else {
2644 monitor_printf(mon, " dst %s", key->eth_dst);
2645 if (mask->has_eth_dst) {
2646 monitor_printf(mon, "(%s)", mask->eth_dst);
2651 if (key->has_ip_proto) {
2652 monitor_printf(mon, " proto %d", key->ip_proto);
2653 if (mask->has_ip_proto) {
2654 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2658 if (key->has_ip_tos) {
2659 monitor_printf(mon, " TOS %d", key->ip_tos);
2660 if (mask->has_ip_tos) {
2661 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2665 if (key->has_ip_dst) {
2666 monitor_printf(mon, " dst %s", key->ip_dst);
2669 if (action->has_goto_tbl || action->has_group_id ||
2670 action->has_new_vlan_id) {
2671 monitor_printf(mon, " -->");
2674 if (action->has_new_vlan_id) {
2675 monitor_printf(mon, " apply new vlan %d",
2676 ntohs(action->new_vlan_id));
2679 if (action->has_group_id) {
2680 monitor_printf(mon, " write group 0x%08x", action->group_id);
2683 if (action->has_goto_tbl) {
2684 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2687 monitor_printf(mon, "\n");
2690 qapi_free_RockerOfDpaFlowList(list);
2693 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2695 RockerOfDpaGroupList *list, *g;
2696 const char *name = qdict_get_str(qdict, "name");
2697 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2698 Error *err = NULL;
2699 bool set = false;
2701 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2702 if (err != NULL) {
2703 hmp_handle_error(mon, &err);
2704 return;
2707 monitor_printf(mon, "id (decode) --> buckets\n");
2709 for (g = list; g; g = g->next) {
2710 RockerOfDpaGroup *group = g->value;
2712 monitor_printf(mon, "0x%08x", group->id);
2714 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2715 group->type == 1 ? "L2 rewrite" :
2716 group->type == 2 ? "L3 unicast" :
2717 group->type == 3 ? "L2 multicast" :
2718 group->type == 4 ? "L2 flood" :
2719 group->type == 5 ? "L3 interface" :
2720 group->type == 6 ? "L3 multicast" :
2721 group->type == 7 ? "L3 ECMP" :
2722 group->type == 8 ? "L2 overlay" :
2723 "unknown");
2725 if (group->has_vlan_id) {
2726 monitor_printf(mon, " vlan %d", group->vlan_id);
2729 if (group->has_pport) {
2730 monitor_printf(mon, " pport %d", group->pport);
2733 if (group->has_index) {
2734 monitor_printf(mon, " index %d", group->index);
2737 monitor_printf(mon, ") -->");
2739 if (group->has_set_vlan_id && group->set_vlan_id) {
2740 set = true;
2741 monitor_printf(mon, " set vlan %d",
2742 group->set_vlan_id & VLAN_VID_MASK);
2745 if (group->has_set_eth_src) {
2746 if (!set) {
2747 set = true;
2748 monitor_printf(mon, " set");
2750 monitor_printf(mon, " src %s", group->set_eth_src);
2753 if (group->has_set_eth_dst) {
2754 if (!set) {
2755 set = true;
2756 monitor_printf(mon, " set");
2758 monitor_printf(mon, " dst %s", group->set_eth_dst);
2761 set = false;
2763 if (group->has_ttl_check && group->ttl_check) {
2764 monitor_printf(mon, " check TTL");
2767 if (group->has_group_id && group->group_id) {
2768 monitor_printf(mon, " group id 0x%08x", group->group_id);
2771 if (group->has_pop_vlan && group->pop_vlan) {
2772 monitor_printf(mon, " pop vlan");
2775 if (group->has_out_pport) {
2776 monitor_printf(mon, " out pport %d", group->out_pport);
2779 if (group->has_group_ids) {
2780 struct uint32List *id;
2782 monitor_printf(mon, " groups [");
2783 for (id = group->group_ids; id; id = id->next) {
2784 monitor_printf(mon, "0x%08x", id->value);
2785 if (id->next) {
2786 monitor_printf(mon, ",");
2789 monitor_printf(mon, "]");
2792 monitor_printf(mon, "\n");
2795 qapi_free_RockerOfDpaGroupList(list);
2798 void hmp_info_dump(Monitor *mon, const QDict *qdict)
2800 DumpQueryResult *result = qmp_query_dump(NULL);
2802 assert(result && result->status < DUMP_STATUS__MAX);
2803 monitor_printf(mon, "Status: %s\n", DumpStatus_str(result->status));
2805 if (result->status == DUMP_STATUS_ACTIVE) {
2806 float percent = 0;
2807 assert(result->total != 0);
2808 percent = 100.0 * result->completed / result->total;
2809 monitor_printf(mon, "Finished: %.2f %%\n", percent);
2812 qapi_free_DumpQueryResult(result);
2815 void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
2817 ram_block_dump(mon);
2820 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
2822 Error *err = NULL;
2823 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
2824 HotpluggableCPUList *saved = l;
2825 CpuInstanceProperties *c;
2827 if (err != NULL) {
2828 hmp_handle_error(mon, &err);
2829 return;
2832 monitor_printf(mon, "Hotpluggable CPUs:\n");
2833 while (l) {
2834 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
2835 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
2836 l->value->vcpus_count);
2837 if (l->value->has_qom_path) {
2838 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
2841 c = l->value->props;
2842 monitor_printf(mon, " CPUInstance Properties:\n");
2843 if (c->has_node_id) {
2844 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
2846 if (c->has_socket_id) {
2847 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
2849 if (c->has_core_id) {
2850 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
2852 if (c->has_thread_id) {
2853 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
2856 l = l->next;
2859 qapi_free_HotpluggableCPUList(saved);
2862 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
2864 Error *err = NULL;
2865 GuidInfo *info = qmp_query_vm_generation_id(&err);
2866 if (info) {
2867 monitor_printf(mon, "%s\n", info->guid);
2869 hmp_handle_error(mon, &err);
2870 qapi_free_GuidInfo(info);
2873 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
2875 Error *err = NULL;
2876 MemoryInfo *info = qmp_query_memory_size_summary(&err);
2877 if (info) {
2878 monitor_printf(mon, "base memory: %" PRIu64 "\n",
2879 info->base_memory);
2881 if (info->has_plugged_memory) {
2882 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
2883 info->plugged_memory);
2886 qapi_free_MemoryInfo(info);
2888 hmp_handle_error(mon, &err);