xref: /openbmc/qemu/monitor/hmp-cmds.c (revision 1061f8dd808cc185736094759bd8a2b919435195)
1 /*
2  * Human Monitor Interface commands
3  *
4  * Copyright IBM, Corp. 2011
5  *
6  * Authors:
7  *  Anthony Liguori   <aliguori@us.ibm.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.  See
10  * the COPYING file in the top-level directory.
11  *
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.
14  */
15 
16 #include "qemu/osdep.h"
17 #include "monitor/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/runstate.h"
23 #include "qemu/config-file.h"
24 #include "qemu/option.h"
25 #include "qemu/timer.h"
26 #include "qemu/sockets.h"
27 #include "monitor/monitor-internal.h"
28 #include "qapi/error.h"
29 #include "qapi/clone-visitor.h"
30 #include "qapi/opts-visitor.h"
31 #include "qapi/qapi-builtin-visit.h"
32 #include "qapi/qapi-commands-block.h"
33 #include "qapi/qapi-commands-char.h"
34 #include "qapi/qapi-commands-control.h"
35 #include "qapi/qapi-commands-migration.h"
36 #include "qapi/qapi-commands-misc.h"
37 #include "qapi/qapi-commands-net.h"
38 #include "qapi/qapi-commands-rocker.h"
39 #include "qapi/qapi-commands-run-state.h"
40 #include "qapi/qapi-commands-tpm.h"
41 #include "qapi/qapi-commands-ui.h"
42 #include "qapi/qapi-visit-net.h"
43 #include "qapi/qapi-visit-migration.h"
44 #include "qapi/qmp/qdict.h"
45 #include "qapi/qmp/qerror.h"
46 #include "qapi/string-input-visitor.h"
47 #include "qapi/string-output-visitor.h"
48 #include "qom/object_interfaces.h"
49 #include "ui/console.h"
50 #include "block/qapi.h"
51 #include "qemu/cutils.h"
52 #include "qemu/error-report.h"
53 #include "exec/ramlist.h"
54 #include "hw/intc/intc.h"
55 #include "hw/rdma/rdma.h"
56 #include "migration/snapshot.h"
57 #include "migration/misc.h"
58 
59 #ifdef CONFIG_SPICE
60 #include <spice/enums.h>
61 #endif
62 
63 void hmp_handle_error(Monitor *mon, Error *err)
64 {
65     if (err) {
66         error_reportf_err(err, "Error: ");
67     }
68 }
69 
70 /*
71  * Produce a strList from a comma separated list.
72  * A NULL or empty input string return NULL.
73  */
74 static strList *strList_from_comma_list(const char *in)
75 {
76     strList *res = NULL;
77     strList **hook = &res;
78 
79     while (in && in[0]) {
80         char *comma = strchr(in, ',');
81         *hook = g_new0(strList, 1);
82 
83         if (comma) {
84             (*hook)->value = g_strndup(in, comma - in);
85             in = comma + 1; /* skip the , */
86         } else {
87             (*hook)->value = g_strdup(in);
88             in = NULL;
89         }
90         hook = &(*hook)->next;
91     }
92 
93     return res;
94 }
95 
96 void hmp_info_name(Monitor *mon, const QDict *qdict)
97 {
98     NameInfo *info;
99 
100     info = qmp_query_name(NULL);
101     if (info->has_name) {
102         monitor_printf(mon, "%s\n", info->name);
103     }
104     qapi_free_NameInfo(info);
105 }
106 
107 void hmp_info_version(Monitor *mon, const QDict *qdict)
108 {
109     VersionInfo *info;
110 
111     info = qmp_query_version(NULL);
112 
113     monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
114                    info->qemu->major, info->qemu->minor, info->qemu->micro,
115                    info->package);
116 
117     qapi_free_VersionInfo(info);
118 }
119 
120 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
121 {
122     KvmInfo *info;
123 
124     info = qmp_query_kvm(NULL);
125     monitor_printf(mon, "kvm support: ");
126     if (info->present) {
127         monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
128     } else {
129         monitor_printf(mon, "not compiled\n");
130     }
131 
132     qapi_free_KvmInfo(info);
133 }
134 
135 void hmp_info_status(Monitor *mon, const QDict *qdict)
136 {
137     StatusInfo *info;
138 
139     info = qmp_query_status(NULL);
140 
141     monitor_printf(mon, "VM status: %s%s",
142                    info->running ? "running" : "paused",
143                    info->singlestep ? " (single step mode)" : "");
144 
145     if (!info->running && info->status != RUN_STATE_PAUSED) {
146         monitor_printf(mon, " (%s)", RunState_str(info->status));
147     }
148 
149     monitor_printf(mon, "\n");
150 
151     qapi_free_StatusInfo(info);
152 }
153 
154 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
155 {
156     UuidInfo *info;
157 
158     info = qmp_query_uuid(NULL);
159     monitor_printf(mon, "%s\n", info->UUID);
160     qapi_free_UuidInfo(info);
161 }
162 
163 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
164 {
165     ChardevInfoList *char_info, *info;
166 
167     char_info = qmp_query_chardev(NULL);
168     for (info = char_info; info; info = info->next) {
169         monitor_printf(mon, "%s: filename=%s\n", info->value->label,
170                                                  info->value->filename);
171     }
172 
173     qapi_free_ChardevInfoList(char_info);
174 }
175 
176 void hmp_info_mice(Monitor *mon, const QDict *qdict)
177 {
178     MouseInfoList *mice_list, *mouse;
179 
180     mice_list = qmp_query_mice(NULL);
181     if (!mice_list) {
182         monitor_printf(mon, "No mouse devices connected\n");
183         return;
184     }
185 
186     for (mouse = mice_list; mouse; mouse = mouse->next) {
187         monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
188                        mouse->value->current ? '*' : ' ',
189                        mouse->value->index, mouse->value->name,
190                        mouse->value->absolute ? " (absolute)" : "");
191     }
192 
193     qapi_free_MouseInfoList(mice_list);
194 }
195 
196 static char *SocketAddress_to_str(SocketAddress *addr)
197 {
198     switch (addr->type) {
199     case SOCKET_ADDRESS_TYPE_INET:
200         return g_strdup_printf("tcp:%s:%s",
201                                addr->u.inet.host,
202                                addr->u.inet.port);
203     case SOCKET_ADDRESS_TYPE_UNIX:
204         return g_strdup_printf("unix:%s",
205                                addr->u.q_unix.path);
206     case SOCKET_ADDRESS_TYPE_FD:
207         return g_strdup_printf("fd:%s", addr->u.fd.str);
208     case SOCKET_ADDRESS_TYPE_VSOCK:
209         return g_strdup_printf("tcp:%s:%s",
210                                addr->u.vsock.cid,
211                                addr->u.vsock.port);
212     default:
213         return g_strdup("unknown address type");
214     }
215 }
216 
217 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
218 {
219     MigrationInfo *info;
220 
221     info = qmp_query_migrate(NULL);
222 
223     migration_global_dump(mon);
224 
225     if (info->has_status) {
226         monitor_printf(mon, "Migration status: %s",
227                        MigrationStatus_str(info->status));
228         if (info->status == MIGRATION_STATUS_FAILED &&
229             info->has_error_desc) {
230             monitor_printf(mon, " (%s)\n", info->error_desc);
231         } else {
232             monitor_printf(mon, "\n");
233         }
234 
235         monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
236                        info->total_time);
237         if (info->has_expected_downtime) {
238             monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
239                            info->expected_downtime);
240         }
241         if (info->has_downtime) {
242             monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
243                            info->downtime);
244         }
245         if (info->has_setup_time) {
246             monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
247                            info->setup_time);
248         }
249     }
250 
251     if (info->has_ram) {
252         monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
253                        info->ram->transferred >> 10);
254         monitor_printf(mon, "throughput: %0.2f mbps\n",
255                        info->ram->mbps);
256         monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
257                        info->ram->remaining >> 10);
258         monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
259                        info->ram->total >> 10);
260         monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
261                        info->ram->duplicate);
262         monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
263                        info->ram->skipped);
264         monitor_printf(mon, "normal: %" PRIu64 " pages\n",
265                        info->ram->normal);
266         monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
267                        info->ram->normal_bytes >> 10);
268         monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
269                        info->ram->dirty_sync_count);
270         monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
271                        info->ram->page_size >> 10);
272         monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n",
273                        info->ram->multifd_bytes >> 10);
274         monitor_printf(mon, "pages-per-second: %" PRIu64 "\n",
275                        info->ram->pages_per_second);
276 
277         if (info->ram->dirty_pages_rate) {
278             monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
279                            info->ram->dirty_pages_rate);
280         }
281         if (info->ram->postcopy_requests) {
282             monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
283                            info->ram->postcopy_requests);
284         }
285     }
286 
287     if (info->has_disk) {
288         monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
289                        info->disk->transferred >> 10);
290         monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
291                        info->disk->remaining >> 10);
292         monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
293                        info->disk->total >> 10);
294     }
295 
296     if (info->has_xbzrle_cache) {
297         monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
298                        info->xbzrle_cache->cache_size);
299         monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
300                        info->xbzrle_cache->bytes >> 10);
301         monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
302                        info->xbzrle_cache->pages);
303         monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
304                        info->xbzrle_cache->cache_miss);
305         monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
306                        info->xbzrle_cache->cache_miss_rate);
307         monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
308                        info->xbzrle_cache->overflow);
309     }
310 
311     if (info->has_compression) {
312         monitor_printf(mon, "compression pages: %" PRIu64 " pages\n",
313                        info->compression->pages);
314         monitor_printf(mon, "compression busy: %" PRIu64 "\n",
315                        info->compression->busy);
316         monitor_printf(mon, "compression busy rate: %0.2f\n",
317                        info->compression->busy_rate);
318         monitor_printf(mon, "compressed size: %" PRIu64 "\n",
319                        info->compression->compressed_size);
320         monitor_printf(mon, "compression rate: %0.2f\n",
321                        info->compression->compression_rate);
322     }
323 
324     if (info->has_cpu_throttle_percentage) {
325         monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
326                        info->cpu_throttle_percentage);
327     }
328 
329     if (info->has_postcopy_blocktime) {
330         monitor_printf(mon, "postcopy blocktime: %u\n",
331                        info->postcopy_blocktime);
332     }
333 
334     if (info->has_postcopy_vcpu_blocktime) {
335         Visitor *v;
336         char *str;
337         v = string_output_visitor_new(false, &str);
338         visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NULL);
339         visit_complete(v, &str);
340         monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
341         g_free(str);
342         visit_free(v);
343     }
344     if (info->has_socket_address) {
345         SocketAddressList *addr;
346 
347         monitor_printf(mon, "socket address: [\n");
348 
349         for (addr = info->socket_address; addr; addr = addr->next) {
350             char *s = SocketAddress_to_str(addr->value);
351             monitor_printf(mon, "\t%s\n", s);
352             g_free(s);
353         }
354         monitor_printf(mon, "]\n");
355     }
356     qapi_free_MigrationInfo(info);
357 }
358 
359 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
360 {
361     MigrationCapabilityStatusList *caps, *cap;
362 
363     caps = qmp_query_migrate_capabilities(NULL);
364 
365     if (caps) {
366         for (cap = caps; cap; cap = cap->next) {
367             monitor_printf(mon, "%s: %s\n",
368                            MigrationCapability_str(cap->value->capability),
369                            cap->value->state ? "on" : "off");
370         }
371     }
372 
373     qapi_free_MigrationCapabilityStatusList(caps);
374 }
375 
376 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
377 {
378     MigrationParameters *params;
379 
380     params = qmp_query_migrate_parameters(NULL);
381 
382     if (params) {
383         monitor_printf(mon, "%s: %" PRIu64 " ms\n",
384             MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL),
385             params->announce_initial);
386         monitor_printf(mon, "%s: %" PRIu64 " ms\n",
387             MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX),
388             params->announce_max);
389         monitor_printf(mon, "%s: %" PRIu64 "\n",
390             MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS),
391             params->announce_rounds);
392         monitor_printf(mon, "%s: %" PRIu64 " ms\n",
393             MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP),
394             params->announce_step);
395         assert(params->has_compress_level);
396         monitor_printf(mon, "%s: %u\n",
397             MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
398             params->compress_level);
399         assert(params->has_compress_threads);
400         monitor_printf(mon, "%s: %u\n",
401             MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
402             params->compress_threads);
403         assert(params->has_compress_wait_thread);
404         monitor_printf(mon, "%s: %s\n",
405             MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD),
406             params->compress_wait_thread ? "on" : "off");
407         assert(params->has_decompress_threads);
408         monitor_printf(mon, "%s: %u\n",
409             MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
410             params->decompress_threads);
411         assert(params->has_cpu_throttle_initial);
412         monitor_printf(mon, "%s: %u\n",
413             MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
414             params->cpu_throttle_initial);
415         assert(params->has_cpu_throttle_increment);
416         monitor_printf(mon, "%s: %u\n",
417             MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
418             params->cpu_throttle_increment);
419         assert(params->has_max_cpu_throttle);
420         monitor_printf(mon, "%s: %u\n",
421             MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE),
422             params->max_cpu_throttle);
423         assert(params->has_tls_creds);
424         monitor_printf(mon, "%s: '%s'\n",
425             MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
426             params->tls_creds);
427         assert(params->has_tls_hostname);
428         monitor_printf(mon, "%s: '%s'\n",
429             MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
430             params->tls_hostname);
431         assert(params->has_max_bandwidth);
432         monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
433             MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
434             params->max_bandwidth);
435         assert(params->has_downtime_limit);
436         monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n",
437             MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
438             params->downtime_limit);
439         assert(params->has_x_checkpoint_delay);
440         monitor_printf(mon, "%s: %u\n",
441             MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
442             params->x_checkpoint_delay);
443         assert(params->has_block_incremental);
444         monitor_printf(mon, "%s: %s\n",
445             MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
446             params->block_incremental ? "on" : "off");
447         monitor_printf(mon, "%s: %u\n",
448             MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS),
449             params->multifd_channels);
450         monitor_printf(mon, "%s: %s\n",
451             MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION),
452             MultiFDCompression_str(params->multifd_compression));
453         monitor_printf(mon, "%s: %" PRIu64 "\n",
454             MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
455             params->xbzrle_cache_size);
456         monitor_printf(mon, "%s: %" PRIu64 "\n",
457             MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
458             params->max_postcopy_bandwidth);
459         monitor_printf(mon, " %s: '%s'\n",
460             MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
461             params->has_tls_authz ? params->tls_authz : "");
462     }
463 
464     qapi_free_MigrationParameters(params);
465 }
466 
467 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
468 {
469     monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
470                    qmp_query_migrate_cache_size(NULL) >> 10);
471 }
472 
473 static void print_block_info(Monitor *mon, BlockInfo *info,
474                              BlockDeviceInfo *inserted, bool verbose)
475 {
476     ImageInfo *image_info;
477 
478     assert(!info || !info->has_inserted || info->inserted == inserted);
479 
480     if (info && *info->device) {
481         monitor_printf(mon, "%s", info->device);
482         if (inserted && inserted->has_node_name) {
483             monitor_printf(mon, " (%s)", inserted->node_name);
484         }
485     } else {
486         assert(info || inserted);
487         monitor_printf(mon, "%s",
488                        inserted && inserted->has_node_name ? inserted->node_name
489                        : info && info->has_qdev ? info->qdev
490                        : "<anonymous>");
491     }
492 
493     if (inserted) {
494         monitor_printf(mon, ": %s (%s%s%s)\n",
495                        inserted->file,
496                        inserted->drv,
497                        inserted->ro ? ", read-only" : "",
498                        inserted->encrypted ? ", encrypted" : "");
499     } else {
500         monitor_printf(mon, ": [not inserted]\n");
501     }
502 
503     if (info) {
504         if (info->has_qdev) {
505             monitor_printf(mon, "    Attached to:      %s\n", info->qdev);
506         }
507         if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
508             monitor_printf(mon, "    I/O status:       %s\n",
509                            BlockDeviceIoStatus_str(info->io_status));
510         }
511 
512         if (info->removable) {
513             monitor_printf(mon, "    Removable device: %slocked, tray %s\n",
514                            info->locked ? "" : "not ",
515                            info->tray_open ? "open" : "closed");
516         }
517     }
518 
519 
520     if (!inserted) {
521         return;
522     }
523 
524     monitor_printf(mon, "    Cache mode:       %s%s%s\n",
525                    inserted->cache->writeback ? "writeback" : "writethrough",
526                    inserted->cache->direct ? ", direct" : "",
527                    inserted->cache->no_flush ? ", ignore flushes" : "");
528 
529     if (inserted->has_backing_file) {
530         monitor_printf(mon,
531                        "    Backing file:     %s "
532                        "(chain depth: %" PRId64 ")\n",
533                        inserted->backing_file,
534                        inserted->backing_file_depth);
535     }
536 
537     if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
538         monitor_printf(mon, "    Detect zeroes:    %s\n",
539                 BlockdevDetectZeroesOptions_str(inserted->detect_zeroes));
540     }
541 
542     if (inserted->bps  || inserted->bps_rd  || inserted->bps_wr  ||
543         inserted->iops || inserted->iops_rd || inserted->iops_wr)
544     {
545         monitor_printf(mon, "    I/O throttling:   bps=%" PRId64
546                         " bps_rd=%" PRId64  " bps_wr=%" PRId64
547                         " bps_max=%" PRId64
548                         " bps_rd_max=%" PRId64
549                         " bps_wr_max=%" PRId64
550                         " iops=%" PRId64 " iops_rd=%" PRId64
551                         " iops_wr=%" PRId64
552                         " iops_max=%" PRId64
553                         " iops_rd_max=%" PRId64
554                         " iops_wr_max=%" PRId64
555                         " iops_size=%" PRId64
556                         " group=%s\n",
557                         inserted->bps,
558                         inserted->bps_rd,
559                         inserted->bps_wr,
560                         inserted->bps_max,
561                         inserted->bps_rd_max,
562                         inserted->bps_wr_max,
563                         inserted->iops,
564                         inserted->iops_rd,
565                         inserted->iops_wr,
566                         inserted->iops_max,
567                         inserted->iops_rd_max,
568                         inserted->iops_wr_max,
569                         inserted->iops_size,
570                         inserted->group);
571     }
572 
573     if (verbose) {
574         monitor_printf(mon, "\nImages:\n");
575         image_info = inserted->image;
576         while (1) {
577                 bdrv_image_info_dump(image_info);
578             if (image_info->has_backing_image) {
579                 image_info = image_info->backing_image;
580             } else {
581                 break;
582             }
583         }
584     }
585 }
586 
587 void hmp_info_block(Monitor *mon, const QDict *qdict)
588 {
589     BlockInfoList *block_list, *info;
590     BlockDeviceInfoList *blockdev_list, *blockdev;
591     const char *device = qdict_get_try_str(qdict, "device");
592     bool verbose = qdict_get_try_bool(qdict, "verbose", false);
593     bool nodes = qdict_get_try_bool(qdict, "nodes", false);
594     bool printed = false;
595 
596     /* Print BlockBackend information */
597     if (!nodes) {
598         block_list = qmp_query_block(NULL);
599     } else {
600         block_list = NULL;
601     }
602 
603     for (info = block_list; info; info = info->next) {
604         if (device && strcmp(device, info->value->device)) {
605             continue;
606         }
607 
608         if (info != block_list) {
609             monitor_printf(mon, "\n");
610         }
611 
612         print_block_info(mon, info->value, info->value->has_inserted
613                                            ? info->value->inserted : NULL,
614                          verbose);
615         printed = true;
616     }
617 
618     qapi_free_BlockInfoList(block_list);
619 
620     if ((!device && !nodes) || printed) {
621         return;
622     }
623 
624     /* Print node information */
625     blockdev_list = qmp_query_named_block_nodes(false, false, NULL);
626     for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
627         assert(blockdev->value->has_node_name);
628         if (device && strcmp(device, blockdev->value->node_name)) {
629             continue;
630         }
631 
632         if (blockdev != blockdev_list) {
633             monitor_printf(mon, "\n");
634         }
635 
636         print_block_info(mon, NULL, blockdev->value, verbose);
637     }
638     qapi_free_BlockDeviceInfoList(blockdev_list);
639 }
640 
641 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
642 {
643     BlockStatsList *stats_list, *stats;
644 
645     stats_list = qmp_query_blockstats(false, false, NULL);
646 
647     for (stats = stats_list; stats; stats = stats->next) {
648         if (!stats->value->has_device) {
649             continue;
650         }
651 
652         monitor_printf(mon, "%s:", stats->value->device);
653         monitor_printf(mon, " rd_bytes=%" PRId64
654                        " wr_bytes=%" PRId64
655                        " rd_operations=%" PRId64
656                        " wr_operations=%" PRId64
657                        " flush_operations=%" PRId64
658                        " wr_total_time_ns=%" PRId64
659                        " rd_total_time_ns=%" PRId64
660                        " flush_total_time_ns=%" PRId64
661                        " rd_merged=%" PRId64
662                        " wr_merged=%" PRId64
663                        " idle_time_ns=%" PRId64
664                        "\n",
665                        stats->value->stats->rd_bytes,
666                        stats->value->stats->wr_bytes,
667                        stats->value->stats->rd_operations,
668                        stats->value->stats->wr_operations,
669                        stats->value->stats->flush_operations,
670                        stats->value->stats->wr_total_time_ns,
671                        stats->value->stats->rd_total_time_ns,
672                        stats->value->stats->flush_total_time_ns,
673                        stats->value->stats->rd_merged,
674                        stats->value->stats->wr_merged,
675                        stats->value->stats->idle_time_ns);
676     }
677 
678     qapi_free_BlockStatsList(stats_list);
679 }
680 
681 #ifdef CONFIG_VNC
682 /* Helper for hmp_info_vnc_clients, _servers */
683 static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
684                                   const char *name)
685 {
686     monitor_printf(mon, "  %s: %s:%s (%s%s)\n",
687                    name,
688                    info->host,
689                    info->service,
690                    NetworkAddressFamily_str(info->family),
691                    info->websocket ? " (Websocket)" : "");
692 }
693 
694 /* Helper displaying and auth and crypt info */
695 static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
696                                    VncPrimaryAuth auth,
697                                    VncVencryptSubAuth *vencrypt)
698 {
699     monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
700                    VncPrimaryAuth_str(auth),
701                    vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
702 }
703 
704 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
705 {
706     while (client) {
707         VncClientInfo *cinfo = client->value;
708 
709         hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
710         monitor_printf(mon, "    x509_dname: %s\n",
711                        cinfo->has_x509_dname ?
712                        cinfo->x509_dname : "none");
713         monitor_printf(mon, "    sasl_username: %s\n",
714                        cinfo->has_sasl_username ?
715                        cinfo->sasl_username : "none");
716 
717         client = client->next;
718     }
719 }
720 
721 static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
722 {
723     while (server) {
724         VncServerInfo2 *sinfo = server->value;
725         hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
726         hmp_info_vnc_authcrypt(mon, "    ", sinfo->auth,
727                                sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
728         server = server->next;
729     }
730 }
731 
732 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
733 {
734     VncInfo2List *info2l;
735     Error *err = NULL;
736 
737     info2l = qmp_query_vnc_servers(&err);
738     if (err) {
739         hmp_handle_error(mon, err);
740         return;
741     }
742     if (!info2l) {
743         monitor_printf(mon, "None\n");
744         return;
745     }
746 
747     while (info2l) {
748         VncInfo2 *info = info2l->value;
749         monitor_printf(mon, "%s:\n", info->id);
750         hmp_info_vnc_servers(mon, info->server);
751         hmp_info_vnc_clients(mon, info->clients);
752         if (!info->server) {
753             /* The server entry displays its auth, we only
754              * need to display in the case of 'reverse' connections
755              * where there's no server.
756              */
757             hmp_info_vnc_authcrypt(mon, "  ", info->auth,
758                                info->has_vencrypt ? &info->vencrypt : NULL);
759         }
760         if (info->has_display) {
761             monitor_printf(mon, "  Display: %s\n", info->display);
762         }
763         info2l = info2l->next;
764     }
765 
766     qapi_free_VncInfo2List(info2l);
767 
768 }
769 #endif
770 
771 #ifdef CONFIG_SPICE
772 void hmp_info_spice(Monitor *mon, const QDict *qdict)
773 {
774     SpiceChannelList *chan;
775     SpiceInfo *info;
776     const char *channel_name;
777     const char * const channel_names[] = {
778         [SPICE_CHANNEL_MAIN] = "main",
779         [SPICE_CHANNEL_DISPLAY] = "display",
780         [SPICE_CHANNEL_INPUTS] = "inputs",
781         [SPICE_CHANNEL_CURSOR] = "cursor",
782         [SPICE_CHANNEL_PLAYBACK] = "playback",
783         [SPICE_CHANNEL_RECORD] = "record",
784         [SPICE_CHANNEL_TUNNEL] = "tunnel",
785         [SPICE_CHANNEL_SMARTCARD] = "smartcard",
786         [SPICE_CHANNEL_USBREDIR] = "usbredir",
787         [SPICE_CHANNEL_PORT] = "port",
788 #if 0
789         /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
790          * no easy way to #ifdef (SPICE_CHANNEL_* is a enum).  Disable
791          * as quick fix for build failures with older versions. */
792         [SPICE_CHANNEL_WEBDAV] = "webdav",
793 #endif
794     };
795 
796     info = qmp_query_spice(NULL);
797 
798     if (!info->enabled) {
799         monitor_printf(mon, "Server: disabled\n");
800         goto out;
801     }
802 
803     monitor_printf(mon, "Server:\n");
804     if (info->has_port) {
805         monitor_printf(mon, "     address: %s:%" PRId64 "\n",
806                        info->host, info->port);
807     }
808     if (info->has_tls_port) {
809         monitor_printf(mon, "     address: %s:%" PRId64 " [tls]\n",
810                        info->host, info->tls_port);
811     }
812     monitor_printf(mon, "    migrated: %s\n",
813                    info->migrated ? "true" : "false");
814     monitor_printf(mon, "        auth: %s\n", info->auth);
815     monitor_printf(mon, "    compiled: %s\n", info->compiled_version);
816     monitor_printf(mon, "  mouse-mode: %s\n",
817                    SpiceQueryMouseMode_str(info->mouse_mode));
818 
819     if (!info->has_channels || info->channels == NULL) {
820         monitor_printf(mon, "Channels: none\n");
821     } else {
822         for (chan = info->channels; chan; chan = chan->next) {
823             monitor_printf(mon, "Channel:\n");
824             monitor_printf(mon, "     address: %s:%s%s\n",
825                            chan->value->host, chan->value->port,
826                            chan->value->tls ? " [tls]" : "");
827             monitor_printf(mon, "     session: %" PRId64 "\n",
828                            chan->value->connection_id);
829             monitor_printf(mon, "     channel: %" PRId64 ":%" PRId64 "\n",
830                            chan->value->channel_type, chan->value->channel_id);
831 
832             channel_name = "unknown";
833             if (chan->value->channel_type > 0 &&
834                 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
835                 channel_names[chan->value->channel_type]) {
836                 channel_name = channel_names[chan->value->channel_type];
837             }
838 
839             monitor_printf(mon, "     channel name: %s\n", channel_name);
840         }
841     }
842 
843 out:
844     qapi_free_SpiceInfo(info);
845 }
846 #endif
847 
848 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
849 {
850     BalloonInfo *info;
851     Error *err = NULL;
852 
853     info = qmp_query_balloon(&err);
854     if (err) {
855         hmp_handle_error(mon, err);
856         return;
857     }
858 
859     monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
860 
861     qapi_free_BalloonInfo(info);
862 }
863 
864 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
865 {
866     PciMemoryRegionList *region;
867 
868     monitor_printf(mon, "  Bus %2" PRId64 ", ", dev->bus);
869     monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
870                    dev->slot, dev->function);
871     monitor_printf(mon, "    ");
872 
873     if (dev->class_info->has_desc) {
874         monitor_printf(mon, "%s", dev->class_info->desc);
875     } else {
876         monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
877     }
878 
879     monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
880                    dev->id->vendor, dev->id->device);
881     if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) {
882         monitor_printf(mon, "      PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n",
883                        dev->id->subsystem_vendor, dev->id->subsystem);
884     }
885 
886     if (dev->has_irq) {
887         monitor_printf(mon, "      IRQ %" PRId64 ".\n", dev->irq);
888     }
889 
890     if (dev->has_pci_bridge) {
891         monitor_printf(mon, "      BUS %" PRId64 ".\n",
892                        dev->pci_bridge->bus->number);
893         monitor_printf(mon, "      secondary bus %" PRId64 ".\n",
894                        dev->pci_bridge->bus->secondary);
895         monitor_printf(mon, "      subordinate bus %" PRId64 ".\n",
896                        dev->pci_bridge->bus->subordinate);
897 
898         monitor_printf(mon, "      IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
899                        dev->pci_bridge->bus->io_range->base,
900                        dev->pci_bridge->bus->io_range->limit);
901 
902         monitor_printf(mon,
903                        "      memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
904                        dev->pci_bridge->bus->memory_range->base,
905                        dev->pci_bridge->bus->memory_range->limit);
906 
907         monitor_printf(mon, "      prefetchable memory range "
908                        "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
909                        dev->pci_bridge->bus->prefetchable_range->base,
910                        dev->pci_bridge->bus->prefetchable_range->limit);
911     }
912 
913     for (region = dev->regions; region; region = region->next) {
914         uint64_t addr, size;
915 
916         addr = region->value->address;
917         size = region->value->size;
918 
919         monitor_printf(mon, "      BAR%" PRId64 ": ", region->value->bar);
920 
921         if (!strcmp(region->value->type, "io")) {
922             monitor_printf(mon, "I/O at 0x%04" PRIx64
923                                 " [0x%04" PRIx64 "].\n",
924                            addr, addr + size - 1);
925         } else {
926             monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
927                                " [0x%08" PRIx64 "].\n",
928                            region->value->mem_type_64 ? 64 : 32,
929                            region->value->prefetch ? " prefetchable" : "",
930                            addr, addr + size - 1);
931         }
932     }
933 
934     monitor_printf(mon, "      id \"%s\"\n", dev->qdev_id);
935 
936     if (dev->has_pci_bridge) {
937         if (dev->pci_bridge->has_devices) {
938             PciDeviceInfoList *cdev;
939             for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
940                 hmp_info_pci_device(mon, cdev->value);
941             }
942         }
943     }
944 }
945 
946 static int hmp_info_irq_foreach(Object *obj, void *opaque)
947 {
948     InterruptStatsProvider *intc;
949     InterruptStatsProviderClass *k;
950     Monitor *mon = opaque;
951 
952     if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
953         intc = INTERRUPT_STATS_PROVIDER(obj);
954         k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
955         uint64_t *irq_counts;
956         unsigned int nb_irqs, i;
957         if (k->get_statistics &&
958             k->get_statistics(intc, &irq_counts, &nb_irqs)) {
959             if (nb_irqs > 0) {
960                 monitor_printf(mon, "IRQ statistics for %s:\n",
961                                object_get_typename(obj));
962                 for (i = 0; i < nb_irqs; i++) {
963                     if (irq_counts[i] > 0) {
964                         monitor_printf(mon, "%2d: %" PRId64 "\n", i,
965                                        irq_counts[i]);
966                     }
967                 }
968             }
969         } else {
970             monitor_printf(mon, "IRQ statistics not available for %s.\n",
971                            object_get_typename(obj));
972         }
973     }
974 
975     return 0;
976 }
977 
978 void hmp_info_irq(Monitor *mon, const QDict *qdict)
979 {
980     object_child_foreach_recursive(object_get_root(),
981                                    hmp_info_irq_foreach, mon);
982 }
983 
984 static int hmp_info_pic_foreach(Object *obj, void *opaque)
985 {
986     InterruptStatsProvider *intc;
987     InterruptStatsProviderClass *k;
988     Monitor *mon = opaque;
989 
990     if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
991         intc = INTERRUPT_STATS_PROVIDER(obj);
992         k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
993         if (k->print_info) {
994             k->print_info(intc, mon);
995         } else {
996             monitor_printf(mon, "Interrupt controller information not available for %s.\n",
997                            object_get_typename(obj));
998         }
999     }
1000 
1001     return 0;
1002 }
1003 
1004 void hmp_info_pic(Monitor *mon, const QDict *qdict)
1005 {
1006     object_child_foreach_recursive(object_get_root(),
1007                                    hmp_info_pic_foreach, mon);
1008 }
1009 
1010 static int hmp_info_rdma_foreach(Object *obj, void *opaque)
1011 {
1012     RdmaProvider *rdma;
1013     RdmaProviderClass *k;
1014     Monitor *mon = opaque;
1015 
1016     if (object_dynamic_cast(obj, INTERFACE_RDMA_PROVIDER)) {
1017         rdma = RDMA_PROVIDER(obj);
1018         k = RDMA_PROVIDER_GET_CLASS(obj);
1019         if (k->print_statistics) {
1020             k->print_statistics(mon, rdma);
1021         } else {
1022             monitor_printf(mon, "RDMA statistics not available for %s.\n",
1023                            object_get_typename(obj));
1024         }
1025     }
1026 
1027     return 0;
1028 }
1029 
1030 void hmp_info_rdma(Monitor *mon, const QDict *qdict)
1031 {
1032     object_child_foreach_recursive(object_get_root(),
1033                                    hmp_info_rdma_foreach, mon);
1034 }
1035 
1036 void hmp_info_pci(Monitor *mon, const QDict *qdict)
1037 {
1038     PciInfoList *info_list, *info;
1039     Error *err = NULL;
1040 
1041     info_list = qmp_query_pci(&err);
1042     if (err) {
1043         monitor_printf(mon, "PCI devices not supported\n");
1044         error_free(err);
1045         return;
1046     }
1047 
1048     for (info = info_list; info; info = info->next) {
1049         PciDeviceInfoList *dev;
1050 
1051         for (dev = info->value->devices; dev; dev = dev->next) {
1052             hmp_info_pci_device(mon, dev->value);
1053         }
1054     }
1055 
1056     qapi_free_PciInfoList(info_list);
1057 }
1058 
1059 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
1060 {
1061     BlockJobInfoList *list;
1062     Error *err = NULL;
1063 
1064     list = qmp_query_block_jobs(&err);
1065     assert(!err);
1066 
1067     if (!list) {
1068         monitor_printf(mon, "No active jobs\n");
1069         return;
1070     }
1071 
1072     while (list) {
1073         if (strcmp(list->value->type, "stream") == 0) {
1074             monitor_printf(mon, "Streaming device %s: Completed %" PRId64
1075                            " of %" PRId64 " bytes, speed limit %" PRId64
1076                            " bytes/s\n",
1077                            list->value->device,
1078                            list->value->offset,
1079                            list->value->len,
1080                            list->value->speed);
1081         } else {
1082             monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
1083                            " of %" PRId64 " bytes, speed limit %" PRId64
1084                            " bytes/s\n",
1085                            list->value->type,
1086                            list->value->device,
1087                            list->value->offset,
1088                            list->value->len,
1089                            list->value->speed);
1090         }
1091         list = list->next;
1092     }
1093 
1094     qapi_free_BlockJobInfoList(list);
1095 }
1096 
1097 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
1098 {
1099     TPMInfoList *info_list, *info;
1100     Error *err = NULL;
1101     unsigned int c = 0;
1102     TPMPassthroughOptions *tpo;
1103     TPMEmulatorOptions *teo;
1104 
1105     info_list = qmp_query_tpm(&err);
1106     if (err) {
1107         monitor_printf(mon, "TPM device not supported\n");
1108         error_free(err);
1109         return;
1110     }
1111 
1112     if (info_list) {
1113         monitor_printf(mon, "TPM device:\n");
1114     }
1115 
1116     for (info = info_list; info; info = info->next) {
1117         TPMInfo *ti = info->value;
1118         monitor_printf(mon, " tpm%d: model=%s\n",
1119                        c, TpmModel_str(ti->model));
1120 
1121         monitor_printf(mon, "  \\ %s: type=%s",
1122                        ti->id, TpmTypeOptionsKind_str(ti->options->type));
1123 
1124         switch (ti->options->type) {
1125         case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
1126             tpo = ti->options->u.passthrough.data;
1127             monitor_printf(mon, "%s%s%s%s",
1128                            tpo->has_path ? ",path=" : "",
1129                            tpo->has_path ? tpo->path : "",
1130                            tpo->has_cancel_path ? ",cancel-path=" : "",
1131                            tpo->has_cancel_path ? tpo->cancel_path : "");
1132             break;
1133         case TPM_TYPE_OPTIONS_KIND_EMULATOR:
1134             teo = ti->options->u.emulator.data;
1135             monitor_printf(mon, ",chardev=%s", teo->chardev);
1136             break;
1137         case TPM_TYPE_OPTIONS_KIND__MAX:
1138             break;
1139         }
1140         monitor_printf(mon, "\n");
1141         c++;
1142     }
1143     qapi_free_TPMInfoList(info_list);
1144 }
1145 
1146 void hmp_quit(Monitor *mon, const QDict *qdict)
1147 {
1148     monitor_suspend(mon);
1149     qmp_quit(NULL);
1150 }
1151 
1152 void hmp_stop(Monitor *mon, const QDict *qdict)
1153 {
1154     qmp_stop(NULL);
1155 }
1156 
1157 void hmp_sync_profile(Monitor *mon, const QDict *qdict)
1158 {
1159     const char *op = qdict_get_try_str(qdict, "op");
1160 
1161     if (op == NULL) {
1162         bool on = qsp_is_enabled();
1163 
1164         monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off");
1165         return;
1166     }
1167     if (!strcmp(op, "on")) {
1168         qsp_enable();
1169     } else if (!strcmp(op, "off")) {
1170         qsp_disable();
1171     } else if (!strcmp(op, "reset")) {
1172         qsp_reset();
1173     } else {
1174         Error *err = NULL;
1175 
1176         error_setg(&err, QERR_INVALID_PARAMETER, op);
1177         hmp_handle_error(mon, err);
1178     }
1179 }
1180 
1181 void hmp_system_reset(Monitor *mon, const QDict *qdict)
1182 {
1183     qmp_system_reset(NULL);
1184 }
1185 
1186 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
1187 {
1188     qmp_system_powerdown(NULL);
1189 }
1190 
1191 void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
1192 {
1193     Error *err = NULL;
1194 
1195     qmp_x_exit_preconfig(&err);
1196     hmp_handle_error(mon, err);
1197 }
1198 
1199 void hmp_cpu(Monitor *mon, const QDict *qdict)
1200 {
1201     int64_t cpu_index;
1202 
1203     /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1204             use it are converted to the QAPI */
1205     cpu_index = qdict_get_int(qdict, "index");
1206     if (monitor_set_cpu(cpu_index) < 0) {
1207         monitor_printf(mon, "invalid CPU index\n");
1208     }
1209 }
1210 
1211 void hmp_memsave(Monitor *mon, const QDict *qdict)
1212 {
1213     uint32_t size = qdict_get_int(qdict, "size");
1214     const char *filename = qdict_get_str(qdict, "filename");
1215     uint64_t addr = qdict_get_int(qdict, "val");
1216     Error *err = NULL;
1217     int cpu_index = monitor_get_cpu_index();
1218 
1219     if (cpu_index < 0) {
1220         monitor_printf(mon, "No CPU available\n");
1221         return;
1222     }
1223 
1224     qmp_memsave(addr, size, filename, true, cpu_index, &err);
1225     hmp_handle_error(mon, err);
1226 }
1227 
1228 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1229 {
1230     uint32_t size = qdict_get_int(qdict, "size");
1231     const char *filename = qdict_get_str(qdict, "filename");
1232     uint64_t addr = qdict_get_int(qdict, "val");
1233     Error *err = NULL;
1234 
1235     qmp_pmemsave(addr, size, filename, &err);
1236     hmp_handle_error(mon, err);
1237 }
1238 
1239 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1240 {
1241     const char *chardev = qdict_get_str(qdict, "device");
1242     const char *data = qdict_get_str(qdict, "data");
1243     Error *err = NULL;
1244 
1245     qmp_ringbuf_write(chardev, data, false, 0, &err);
1246 
1247     hmp_handle_error(mon, err);
1248 }
1249 
1250 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
1251 {
1252     uint32_t size = qdict_get_int(qdict, "size");
1253     const char *chardev = qdict_get_str(qdict, "device");
1254     char *data;
1255     Error *err = NULL;
1256     int i;
1257 
1258     data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1259     if (err) {
1260         hmp_handle_error(mon, err);
1261         return;
1262     }
1263 
1264     for (i = 0; data[i]; i++) {
1265         unsigned char ch = data[i];
1266 
1267         if (ch == '\\') {
1268             monitor_printf(mon, "\\\\");
1269         } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1270             monitor_printf(mon, "\\u%04X", ch);
1271         } else {
1272             monitor_printf(mon, "%c", ch);
1273         }
1274 
1275     }
1276     monitor_printf(mon, "\n");
1277     g_free(data);
1278 }
1279 
1280 void hmp_cont(Monitor *mon, const QDict *qdict)
1281 {
1282     Error *err = NULL;
1283 
1284     qmp_cont(&err);
1285     hmp_handle_error(mon, err);
1286 }
1287 
1288 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1289 {
1290     Error *err = NULL;
1291 
1292     qmp_system_wakeup(&err);
1293     hmp_handle_error(mon, err);
1294 }
1295 
1296 void hmp_nmi(Monitor *mon, const QDict *qdict)
1297 {
1298     Error *err = NULL;
1299 
1300     qmp_inject_nmi(&err);
1301     hmp_handle_error(mon, err);
1302 }
1303 
1304 void hmp_set_link(Monitor *mon, const QDict *qdict)
1305 {
1306     const char *name = qdict_get_str(qdict, "name");
1307     bool up = qdict_get_bool(qdict, "up");
1308     Error *err = NULL;
1309 
1310     qmp_set_link(name, up, &err);
1311     hmp_handle_error(mon, err);
1312 }
1313 
1314 void hmp_balloon(Monitor *mon, const QDict *qdict)
1315 {
1316     int64_t value = qdict_get_int(qdict, "value");
1317     Error *err = NULL;
1318 
1319     qmp_balloon(value, &err);
1320     hmp_handle_error(mon, err);
1321 }
1322 
1323 void hmp_loadvm(Monitor *mon, const QDict *qdict)
1324 {
1325     int saved_vm_running  = runstate_is_running();
1326     const char *name = qdict_get_str(qdict, "name");
1327     Error *err = NULL;
1328 
1329     vm_stop(RUN_STATE_RESTORE_VM);
1330 
1331     if (load_snapshot(name, &err) == 0 && saved_vm_running) {
1332         vm_start();
1333     }
1334     hmp_handle_error(mon, err);
1335 }
1336 
1337 void hmp_savevm(Monitor *mon, const QDict *qdict)
1338 {
1339     Error *err = NULL;
1340 
1341     save_snapshot(qdict_get_try_str(qdict, "name"), &err);
1342     hmp_handle_error(mon, err);
1343 }
1344 
1345 void hmp_delvm(Monitor *mon, const QDict *qdict)
1346 {
1347     BlockDriverState *bs;
1348     Error *err = NULL;
1349     const char *name = qdict_get_str(qdict, "name");
1350 
1351     if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
1352         error_prepend(&err,
1353                       "deleting snapshot on device '%s': ",
1354                       bdrv_get_device_name(bs));
1355     }
1356     hmp_handle_error(mon, err);
1357 }
1358 
1359 void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
1360 {
1361     BlockDriverState *bs, *bs1;
1362     BdrvNextIterator it1;
1363     QEMUSnapshotInfo *sn_tab, *sn;
1364     bool no_snapshot = true;
1365     int nb_sns, i;
1366     int total;
1367     int *global_snapshots;
1368     AioContext *aio_context;
1369 
1370     typedef struct SnapshotEntry {
1371         QEMUSnapshotInfo sn;
1372         QTAILQ_ENTRY(SnapshotEntry) next;
1373     } SnapshotEntry;
1374 
1375     typedef struct ImageEntry {
1376         const char *imagename;
1377         QTAILQ_ENTRY(ImageEntry) next;
1378         QTAILQ_HEAD(, SnapshotEntry) snapshots;
1379     } ImageEntry;
1380 
1381     QTAILQ_HEAD(, ImageEntry) image_list =
1382         QTAILQ_HEAD_INITIALIZER(image_list);
1383 
1384     ImageEntry *image_entry, *next_ie;
1385     SnapshotEntry *snapshot_entry;
1386 
1387     bs = bdrv_all_find_vmstate_bs();
1388     if (!bs) {
1389         monitor_printf(mon, "No available block device supports snapshots\n");
1390         return;
1391     }
1392     aio_context = bdrv_get_aio_context(bs);
1393 
1394     aio_context_acquire(aio_context);
1395     nb_sns = bdrv_snapshot_list(bs, &sn_tab);
1396     aio_context_release(aio_context);
1397 
1398     if (nb_sns < 0) {
1399         monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
1400         return;
1401     }
1402 
1403     for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) {
1404         int bs1_nb_sns = 0;
1405         ImageEntry *ie;
1406         SnapshotEntry *se;
1407         AioContext *ctx = bdrv_get_aio_context(bs1);
1408 
1409         aio_context_acquire(ctx);
1410         if (bdrv_can_snapshot(bs1)) {
1411             sn = NULL;
1412             bs1_nb_sns = bdrv_snapshot_list(bs1, &sn);
1413             if (bs1_nb_sns > 0) {
1414                 no_snapshot = false;
1415                 ie = g_new0(ImageEntry, 1);
1416                 ie->imagename = bdrv_get_device_name(bs1);
1417                 QTAILQ_INIT(&ie->snapshots);
1418                 QTAILQ_INSERT_TAIL(&image_list, ie, next);
1419                 for (i = 0; i < bs1_nb_sns; i++) {
1420                     se = g_new0(SnapshotEntry, 1);
1421                     se->sn = sn[i];
1422                     QTAILQ_INSERT_TAIL(&ie->snapshots, se, next);
1423                 }
1424             }
1425             g_free(sn);
1426         }
1427         aio_context_release(ctx);
1428     }
1429 
1430     if (no_snapshot) {
1431         monitor_printf(mon, "There is no snapshot available.\n");
1432         return;
1433     }
1434 
1435     global_snapshots = g_new0(int, nb_sns);
1436     total = 0;
1437     for (i = 0; i < nb_sns; i++) {
1438         SnapshotEntry *next_sn;
1439         if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) {
1440             global_snapshots[total] = i;
1441             total++;
1442             QTAILQ_FOREACH(image_entry, &image_list, next) {
1443                 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots,
1444                                     next, next_sn) {
1445                     if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) {
1446                         QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry,
1447                                       next);
1448                         g_free(snapshot_entry);
1449                     }
1450                 }
1451             }
1452         }
1453     }
1454 
1455     monitor_printf(mon, "List of snapshots present on all disks:\n");
1456 
1457     if (total > 0) {
1458         bdrv_snapshot_dump(NULL);
1459         monitor_printf(mon, "\n");
1460         for (i = 0; i < total; i++) {
1461             sn = &sn_tab[global_snapshots[i]];
1462             /* The ID is not guaranteed to be the same on all images, so
1463              * overwrite it.
1464              */
1465             pstrcpy(sn->id_str, sizeof(sn->id_str), "--");
1466             bdrv_snapshot_dump(sn);
1467             monitor_printf(mon, "\n");
1468         }
1469     } else {
1470         monitor_printf(mon, "None\n");
1471     }
1472 
1473     QTAILQ_FOREACH(image_entry, &image_list, next) {
1474         if (QTAILQ_EMPTY(&image_entry->snapshots)) {
1475             continue;
1476         }
1477         monitor_printf(mon,
1478                        "\nList of partial (non-loadable) snapshots on '%s':\n",
1479                        image_entry->imagename);
1480         bdrv_snapshot_dump(NULL);
1481         monitor_printf(mon, "\n");
1482         QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) {
1483             bdrv_snapshot_dump(&snapshot_entry->sn);
1484             monitor_printf(mon, "\n");
1485         }
1486     }
1487 
1488     QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) {
1489         SnapshotEntry *next_sn;
1490         QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next,
1491                             next_sn) {
1492             g_free(snapshot_entry);
1493         }
1494         g_free(image_entry);
1495     }
1496     g_free(sn_tab);
1497     g_free(global_snapshots);
1498 
1499 }
1500 
1501 void hmp_announce_self(Monitor *mon, const QDict *qdict)
1502 {
1503     const char *interfaces_str = qdict_get_try_str(qdict, "interfaces");
1504     const char *id = qdict_get_try_str(qdict, "id");
1505     AnnounceParameters *params = QAPI_CLONE(AnnounceParameters,
1506                                             migrate_announce_params());
1507 
1508     qapi_free_strList(params->interfaces);
1509     params->interfaces = strList_from_comma_list(interfaces_str);
1510     params->has_interfaces = params->interfaces != NULL;
1511     params->id = g_strdup(id);
1512     params->has_id = !!params->id;
1513     qmp_announce_self(params, NULL);
1514     qapi_free_AnnounceParameters(params);
1515 }
1516 
1517 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1518 {
1519     qmp_migrate_cancel(NULL);
1520 }
1521 
1522 void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1523 {
1524     Error *err = NULL;
1525     const char *state = qdict_get_str(qdict, "state");
1526     int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1527 
1528     if (val >= 0) {
1529         qmp_migrate_continue(val, &err);
1530     }
1531 
1532     hmp_handle_error(mon, err);
1533 }
1534 
1535 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1536 {
1537     Error *err = NULL;
1538     const char *uri = qdict_get_str(qdict, "uri");
1539 
1540     qmp_migrate_incoming(uri, &err);
1541 
1542     hmp_handle_error(mon, err);
1543 }
1544 
1545 void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
1546 {
1547     Error *err = NULL;
1548     const char *uri = qdict_get_str(qdict, "uri");
1549 
1550     qmp_migrate_recover(uri, &err);
1551 
1552     hmp_handle_error(mon, err);
1553 }
1554 
1555 void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
1556 {
1557     Error *err = NULL;
1558 
1559     qmp_migrate_pause(&err);
1560 
1561     hmp_handle_error(mon, err);
1562 }
1563 
1564 /* Kept for backwards compatibility */
1565 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1566 {
1567     double value = qdict_get_double(qdict, "value");
1568     qmp_migrate_set_downtime(value, NULL);
1569 }
1570 
1571 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1572 {
1573     int64_t value = qdict_get_int(qdict, "value");
1574     Error *err = NULL;
1575 
1576     qmp_migrate_set_cache_size(value, &err);
1577     hmp_handle_error(mon, err);
1578 }
1579 
1580 /* Kept for backwards compatibility */
1581 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1582 {
1583     int64_t value = qdict_get_int(qdict, "value");
1584     qmp_migrate_set_speed(value, NULL);
1585 }
1586 
1587 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1588 {
1589     const char *cap = qdict_get_str(qdict, "capability");
1590     bool state = qdict_get_bool(qdict, "state");
1591     Error *err = NULL;
1592     MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1593     int val;
1594 
1595     val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
1596     if (val < 0) {
1597         goto end;
1598     }
1599 
1600     caps->value = g_malloc0(sizeof(*caps->value));
1601     caps->value->capability = val;
1602     caps->value->state = state;
1603     caps->next = NULL;
1604     qmp_migrate_set_capabilities(caps, &err);
1605 
1606 end:
1607     qapi_free_MigrationCapabilityStatusList(caps);
1608     hmp_handle_error(mon, err);
1609 }
1610 
1611 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1612 {
1613     const char *param = qdict_get_str(qdict, "parameter");
1614     const char *valuestr = qdict_get_str(qdict, "value");
1615     Visitor *v = string_input_visitor_new(valuestr);
1616     MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
1617     uint64_t valuebw = 0;
1618     uint64_t cache_size;
1619     MultiFDCompression compress_type;
1620     Error *err = NULL;
1621     int val, ret;
1622 
1623     val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
1624     if (val < 0) {
1625         goto cleanup;
1626     }
1627 
1628     switch (val) {
1629     case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1630         p->has_compress_level = true;
1631         visit_type_int(v, param, &p->compress_level, &err);
1632         break;
1633     case MIGRATION_PARAMETER_COMPRESS_THREADS:
1634         p->has_compress_threads = true;
1635         visit_type_int(v, param, &p->compress_threads, &err);
1636         break;
1637     case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD:
1638         p->has_compress_wait_thread = true;
1639         visit_type_bool(v, param, &p->compress_wait_thread, &err);
1640         break;
1641     case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1642         p->has_decompress_threads = true;
1643         visit_type_int(v, param, &p->decompress_threads, &err);
1644         break;
1645     case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1646         p->has_cpu_throttle_initial = true;
1647         visit_type_int(v, param, &p->cpu_throttle_initial, &err);
1648         break;
1649     case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1650         p->has_cpu_throttle_increment = true;
1651         visit_type_int(v, param, &p->cpu_throttle_increment, &err);
1652         break;
1653     case MIGRATION_PARAMETER_MAX_CPU_THROTTLE:
1654         p->has_max_cpu_throttle = true;
1655         visit_type_int(v, param, &p->max_cpu_throttle, &err);
1656         break;
1657     case MIGRATION_PARAMETER_TLS_CREDS:
1658         p->has_tls_creds = true;
1659         p->tls_creds = g_new0(StrOrNull, 1);
1660         p->tls_creds->type = QTYPE_QSTRING;
1661         visit_type_str(v, param, &p->tls_creds->u.s, &err);
1662         break;
1663     case MIGRATION_PARAMETER_TLS_HOSTNAME:
1664         p->has_tls_hostname = true;
1665         p->tls_hostname = g_new0(StrOrNull, 1);
1666         p->tls_hostname->type = QTYPE_QSTRING;
1667         visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1668         break;
1669     case MIGRATION_PARAMETER_TLS_AUTHZ:
1670         p->has_tls_authz = true;
1671         p->tls_authz = g_new0(StrOrNull, 1);
1672         p->tls_authz->type = QTYPE_QSTRING;
1673         visit_type_str(v, param, &p->tls_authz->u.s, &err);
1674         break;
1675     case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1676         p->has_max_bandwidth = true;
1677         /*
1678          * Can't use visit_type_size() here, because it
1679          * defaults to Bytes rather than Mebibytes.
1680          */
1681         ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1682         if (ret < 0 || valuebw > INT64_MAX
1683             || (size_t)valuebw != valuebw) {
1684             error_setg(&err, "Invalid size %s", valuestr);
1685             break;
1686         }
1687         p->max_bandwidth = valuebw;
1688         break;
1689     case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1690         p->has_downtime_limit = true;
1691         visit_type_int(v, param, &p->downtime_limit, &err);
1692         break;
1693     case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1694         p->has_x_checkpoint_delay = true;
1695         visit_type_int(v, param, &p->x_checkpoint_delay, &err);
1696         break;
1697     case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1698         p->has_block_incremental = true;
1699         visit_type_bool(v, param, &p->block_incremental, &err);
1700         break;
1701     case MIGRATION_PARAMETER_MULTIFD_CHANNELS:
1702         p->has_multifd_channels = true;
1703         visit_type_int(v, param, &p->multifd_channels, &err);
1704         break;
1705     case MIGRATION_PARAMETER_MULTIFD_COMPRESSION:
1706         p->has_multifd_compression = true;
1707         visit_type_MultiFDCompression(v, param, &compress_type, &err);
1708         if (err) {
1709             break;
1710         }
1711         p->multifd_compression = compress_type;
1712         break;
1713     case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL:
1714         p->has_multifd_zlib_level = true;
1715         visit_type_int(v, param, &p->multifd_zlib_level, &err);
1716         break;
1717     case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL:
1718         p->has_multifd_zstd_level = true;
1719         visit_type_int(v, param, &p->multifd_zstd_level, &err);
1720         break;
1721     case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1722         p->has_xbzrle_cache_size = true;
1723         visit_type_size(v, param, &cache_size, &err);
1724         if (err) {
1725             break;
1726         }
1727         if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) {
1728             error_setg(&err, "Invalid size %s", valuestr);
1729             break;
1730         }
1731         p->xbzrle_cache_size = cache_size;
1732         break;
1733     case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH:
1734         p->has_max_postcopy_bandwidth = true;
1735         visit_type_size(v, param, &p->max_postcopy_bandwidth, &err);
1736         break;
1737     case MIGRATION_PARAMETER_ANNOUNCE_INITIAL:
1738         p->has_announce_initial = true;
1739         visit_type_size(v, param, &p->announce_initial, &err);
1740         break;
1741     case MIGRATION_PARAMETER_ANNOUNCE_MAX:
1742         p->has_announce_max = true;
1743         visit_type_size(v, param, &p->announce_max, &err);
1744         break;
1745     case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS:
1746         p->has_announce_rounds = true;
1747         visit_type_size(v, param, &p->announce_rounds, &err);
1748         break;
1749     case MIGRATION_PARAMETER_ANNOUNCE_STEP:
1750         p->has_announce_step = true;
1751         visit_type_size(v, param, &p->announce_step, &err);
1752         break;
1753     default:
1754         assert(0);
1755     }
1756 
1757     if (err) {
1758         goto cleanup;
1759     }
1760 
1761     qmp_migrate_set_parameters(p, &err);
1762 
1763  cleanup:
1764     qapi_free_MigrateSetParameters(p);
1765     visit_free(v);
1766     hmp_handle_error(mon, err);
1767 }
1768 
1769 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1770 {
1771     Error *err = NULL;
1772     const char *protocol = qdict_get_str(qdict, "protocol");
1773     const char *hostname = qdict_get_str(qdict, "hostname");
1774     bool has_port        = qdict_haskey(qdict, "port");
1775     int port             = qdict_get_try_int(qdict, "port", -1);
1776     bool has_tls_port    = qdict_haskey(qdict, "tls-port");
1777     int tls_port         = qdict_get_try_int(qdict, "tls-port", -1);
1778     const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1779 
1780     qmp_client_migrate_info(protocol, hostname,
1781                             has_port, port, has_tls_port, tls_port,
1782                             !!cert_subject, cert_subject, &err);
1783     hmp_handle_error(mon, err);
1784 }
1785 
1786 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1787 {
1788     Error *err = NULL;
1789     qmp_migrate_start_postcopy(&err);
1790     hmp_handle_error(mon, err);
1791 }
1792 
1793 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1794 {
1795     Error *err = NULL;
1796 
1797     qmp_x_colo_lost_heartbeat(&err);
1798     hmp_handle_error(mon, err);
1799 }
1800 
1801 void hmp_set_password(Monitor *mon, const QDict *qdict)
1802 {
1803     const char *protocol  = qdict_get_str(qdict, "protocol");
1804     const char *password  = qdict_get_str(qdict, "password");
1805     const char *connected = qdict_get_try_str(qdict, "connected");
1806     Error *err = NULL;
1807 
1808     qmp_set_password(protocol, password, !!connected, connected, &err);
1809     hmp_handle_error(mon, err);
1810 }
1811 
1812 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1813 {
1814     const char *protocol  = qdict_get_str(qdict, "protocol");
1815     const char *whenstr = qdict_get_str(qdict, "time");
1816     Error *err = NULL;
1817 
1818     qmp_expire_password(protocol, whenstr, &err);
1819     hmp_handle_error(mon, err);
1820 }
1821 
1822 
1823 #ifdef CONFIG_VNC
1824 static void hmp_change_read_arg(void *opaque, const char *password,
1825                                 void *readline_opaque)
1826 {
1827     qmp_change_vnc_password(password, NULL);
1828     monitor_read_command(opaque, 1);
1829 }
1830 #endif
1831 
1832 void hmp_change(Monitor *mon, const QDict *qdict)
1833 {
1834     const char *device = qdict_get_str(qdict, "device");
1835     const char *target = qdict_get_str(qdict, "target");
1836     const char *arg = qdict_get_try_str(qdict, "arg");
1837     const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1838     BlockdevChangeReadOnlyMode read_only_mode = 0;
1839     Error *err = NULL;
1840 
1841 #ifdef CONFIG_VNC
1842     if (strcmp(device, "vnc") == 0) {
1843         if (read_only) {
1844             monitor_printf(mon,
1845                            "Parameter 'read-only-mode' is invalid for VNC\n");
1846             return;
1847         }
1848         if (strcmp(target, "passwd") == 0 ||
1849             strcmp(target, "password") == 0) {
1850             if (!arg) {
1851                 MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
1852                 monitor_read_password(hmp_mon, hmp_change_read_arg, NULL);
1853                 return;
1854             }
1855         }
1856         qmp_change("vnc", target, !!arg, arg, &err);
1857     } else
1858 #endif
1859     {
1860         if (read_only) {
1861             read_only_mode =
1862                 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
1863                                 read_only,
1864                                 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1865             if (err) {
1866                 hmp_handle_error(mon, err);
1867                 return;
1868             }
1869         }
1870 
1871         qmp_blockdev_change_medium(true, device, false, NULL, target,
1872                                    !!arg, arg, !!read_only, read_only_mode,
1873                                    &err);
1874     }
1875 
1876     hmp_handle_error(mon, err);
1877 }
1878 
1879 typedef struct HMPMigrationStatus
1880 {
1881     QEMUTimer *timer;
1882     Monitor *mon;
1883     bool is_block_migration;
1884 } HMPMigrationStatus;
1885 
1886 static void hmp_migrate_status_cb(void *opaque)
1887 {
1888     HMPMigrationStatus *status = opaque;
1889     MigrationInfo *info;
1890 
1891     info = qmp_query_migrate(NULL);
1892     if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1893         info->status == MIGRATION_STATUS_SETUP) {
1894         if (info->has_disk) {
1895             int progress;
1896 
1897             if (info->disk->remaining) {
1898                 progress = info->disk->transferred * 100 / info->disk->total;
1899             } else {
1900                 progress = 100;
1901             }
1902 
1903             monitor_printf(status->mon, "Completed %d %%\r", progress);
1904             monitor_flush(status->mon);
1905         }
1906 
1907         timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1908     } else {
1909         if (status->is_block_migration) {
1910             monitor_printf(status->mon, "\n");
1911         }
1912         if (info->has_error_desc) {
1913             error_report("%s", info->error_desc);
1914         }
1915         monitor_resume(status->mon);
1916         timer_del(status->timer);
1917         timer_free(status->timer);
1918         g_free(status);
1919     }
1920 
1921     qapi_free_MigrationInfo(info);
1922 }
1923 
1924 void hmp_migrate(Monitor *mon, const QDict *qdict)
1925 {
1926     bool detach = qdict_get_try_bool(qdict, "detach", false);
1927     bool blk = qdict_get_try_bool(qdict, "blk", false);
1928     bool inc = qdict_get_try_bool(qdict, "inc", false);
1929     bool resume = qdict_get_try_bool(qdict, "resume", false);
1930     const char *uri = qdict_get_str(qdict, "uri");
1931     Error *err = NULL;
1932 
1933     qmp_migrate(uri, !!blk, blk, !!inc, inc,
1934                 false, false, true, resume, &err);
1935     if (err) {
1936         hmp_handle_error(mon, err);
1937         return;
1938     }
1939 
1940     if (!detach) {
1941         HMPMigrationStatus *status;
1942 
1943         if (monitor_suspend(mon) < 0) {
1944             monitor_printf(mon, "terminal does not allow synchronous "
1945                            "migration, continuing detached\n");
1946             return;
1947         }
1948 
1949         status = g_malloc0(sizeof(*status));
1950         status->mon = mon;
1951         status->is_block_migration = blk || inc;
1952         status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1953                                           status);
1954         timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1955     }
1956 }
1957 
1958 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1959 {
1960     Error *err = NULL;
1961     QemuOpts *opts;
1962 
1963     opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1964     if (err) {
1965         goto out;
1966     }
1967 
1968     netdev_add(opts, &err);
1969     if (err) {
1970         qemu_opts_del(opts);
1971     }
1972 
1973 out:
1974     hmp_handle_error(mon, err);
1975 }
1976 
1977 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1978 {
1979     const char *id = qdict_get_str(qdict, "id");
1980     Error *err = NULL;
1981 
1982     qmp_netdev_del(id, &err);
1983     hmp_handle_error(mon, err);
1984 }
1985 
1986 void hmp_object_add(Monitor *mon, const QDict *qdict)
1987 {
1988     Error *err = NULL;
1989     QemuOpts *opts;
1990     Object *obj = NULL;
1991 
1992     opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1993     if (err) {
1994         hmp_handle_error(mon, err);
1995         return;
1996     }
1997 
1998     obj = user_creatable_add_opts(opts, &err);
1999     qemu_opts_del(opts);
2000 
2001     if (err) {
2002         hmp_handle_error(mon, err);
2003     }
2004     if (obj) {
2005         object_unref(obj);
2006     }
2007 }
2008 
2009 void hmp_getfd(Monitor *mon, const QDict *qdict)
2010 {
2011     const char *fdname = qdict_get_str(qdict, "fdname");
2012     Error *err = NULL;
2013 
2014     qmp_getfd(fdname, &err);
2015     hmp_handle_error(mon, err);
2016 }
2017 
2018 void hmp_closefd(Monitor *mon, const QDict *qdict)
2019 {
2020     const char *fdname = qdict_get_str(qdict, "fdname");
2021     Error *err = NULL;
2022 
2023     qmp_closefd(fdname, &err);
2024     hmp_handle_error(mon, err);
2025 }
2026 
2027 void hmp_sendkey(Monitor *mon, const QDict *qdict)
2028 {
2029     const char *keys = qdict_get_str(qdict, "keys");
2030     KeyValueList *keylist, *head = NULL, *tmp = NULL;
2031     int has_hold_time = qdict_haskey(qdict, "hold-time");
2032     int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
2033     Error *err = NULL;
2034     const char *separator;
2035     int keyname_len;
2036 
2037     while (1) {
2038         separator = qemu_strchrnul(keys, '-');
2039         keyname_len = separator - keys;
2040 
2041         /* Be compatible with old interface, convert user inputted "<" */
2042         if (keys[0] == '<' && keyname_len == 1) {
2043             keys = "less";
2044             keyname_len = 4;
2045         }
2046 
2047         keylist = g_malloc0(sizeof(*keylist));
2048         keylist->value = g_malloc0(sizeof(*keylist->value));
2049 
2050         if (!head) {
2051             head = keylist;
2052         }
2053         if (tmp) {
2054             tmp->next = keylist;
2055         }
2056         tmp = keylist;
2057 
2058         if (strstart(keys, "0x", NULL)) {
2059             char *endp;
2060             int value = strtoul(keys, &endp, 0);
2061             assert(endp <= keys + keyname_len);
2062             if (endp != keys + keyname_len) {
2063                 goto err_out;
2064             }
2065             keylist->value->type = KEY_VALUE_KIND_NUMBER;
2066             keylist->value->u.number.data = value;
2067         } else {
2068             int idx = index_from_key(keys, keyname_len);
2069             if (idx == Q_KEY_CODE__MAX) {
2070                 goto err_out;
2071             }
2072             keylist->value->type = KEY_VALUE_KIND_QCODE;
2073             keylist->value->u.qcode.data = idx;
2074         }
2075 
2076         if (!*separator) {
2077             break;
2078         }
2079         keys = separator + 1;
2080     }
2081 
2082     qmp_send_key(head, has_hold_time, hold_time, &err);
2083     hmp_handle_error(mon, err);
2084 
2085 out:
2086     qapi_free_KeyValueList(head);
2087     return;
2088 
2089 err_out:
2090     monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
2091     goto out;
2092 }
2093 
2094 void hmp_screendump(Monitor *mon, const QDict *qdict)
2095 {
2096     const char *filename = qdict_get_str(qdict, "filename");
2097     const char *id = qdict_get_try_str(qdict, "device");
2098     int64_t head = qdict_get_try_int(qdict, "head", 0);
2099     Error *err = NULL;
2100 
2101     qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
2102     hmp_handle_error(mon, err);
2103 }
2104 
2105 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2106 {
2107     const char *args = qdict_get_str(qdict, "args");
2108     Error *err = NULL;
2109     QemuOpts *opts;
2110 
2111     opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
2112     if (opts == NULL) {
2113         error_setg(&err, "Parsing chardev args failed");
2114     } else {
2115         qemu_chr_new_from_opts(opts, NULL, &err);
2116         qemu_opts_del(opts);
2117     }
2118     hmp_handle_error(mon, err);
2119 }
2120 
2121 void hmp_chardev_change(Monitor *mon, const QDict *qdict)
2122 {
2123     const char *args = qdict_get_str(qdict, "args");
2124     const char *id;
2125     Error *err = NULL;
2126     ChardevBackend *backend = NULL;
2127     ChardevReturn *ret = NULL;
2128     QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
2129                                              true);
2130     if (!opts) {
2131         error_setg(&err, "Parsing chardev args failed");
2132         goto end;
2133     }
2134 
2135     id = qdict_get_str(qdict, "id");
2136     if (qemu_opts_id(opts)) {
2137         error_setg(&err, "Unexpected 'id' parameter");
2138         goto end;
2139     }
2140 
2141     backend = qemu_chr_parse_opts(opts, &err);
2142     if (!backend) {
2143         goto end;
2144     }
2145 
2146     ret = qmp_chardev_change(id, backend, &err);
2147 
2148 end:
2149     qapi_free_ChardevReturn(ret);
2150     qapi_free_ChardevBackend(backend);
2151     qemu_opts_del(opts);
2152     hmp_handle_error(mon, err);
2153 }
2154 
2155 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2156 {
2157     Error *local_err = NULL;
2158 
2159     qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
2160     hmp_handle_error(mon, local_err);
2161 }
2162 
2163 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
2164 {
2165     Error *local_err = NULL;
2166 
2167     qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
2168     hmp_handle_error(mon, local_err);
2169 }
2170 
2171 void hmp_object_del(Monitor *mon, const QDict *qdict)
2172 {
2173     const char *id = qdict_get_str(qdict, "id");
2174     Error *err = NULL;
2175 
2176     user_creatable_del(id, &err);
2177     hmp_handle_error(mon, err);
2178 }
2179 
2180 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2181 {
2182     Error *err = NULL;
2183     MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2184     MemoryDeviceInfoList *info;
2185     VirtioPMEMDeviceInfo *vpi;
2186     MemoryDeviceInfo *value;
2187     PCDIMMDeviceInfo *di;
2188 
2189     for (info = info_list; info; info = info->next) {
2190         value = info->value;
2191 
2192         if (value) {
2193             switch (value->type) {
2194             case MEMORY_DEVICE_INFO_KIND_DIMM:
2195             case MEMORY_DEVICE_INFO_KIND_NVDIMM:
2196                 di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ?
2197                      value->u.dimm.data : value->u.nvdimm.data;
2198                 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2199                                MemoryDeviceInfoKind_str(value->type),
2200                                di->id ? di->id : "");
2201                 monitor_printf(mon, "  addr: 0x%" PRIx64 "\n", di->addr);
2202                 monitor_printf(mon, "  slot: %" PRId64 "\n", di->slot);
2203                 monitor_printf(mon, "  node: %" PRId64 "\n", di->node);
2204                 monitor_printf(mon, "  size: %" PRIu64 "\n", di->size);
2205                 monitor_printf(mon, "  memdev: %s\n", di->memdev);
2206                 monitor_printf(mon, "  hotplugged: %s\n",
2207                                di->hotplugged ? "true" : "false");
2208                 monitor_printf(mon, "  hotpluggable: %s\n",
2209                                di->hotpluggable ? "true" : "false");
2210                 break;
2211             case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM:
2212                 vpi = value->u.virtio_pmem.data;
2213                 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2214                                MemoryDeviceInfoKind_str(value->type),
2215                                vpi->id ? vpi->id : "");
2216                 monitor_printf(mon, "  memaddr: 0x%" PRIx64 "\n", vpi->memaddr);
2217                 monitor_printf(mon, "  size: %" PRIu64 "\n", vpi->size);
2218                 monitor_printf(mon, "  memdev: %s\n", vpi->memdev);
2219                 break;
2220             default:
2221                 g_assert_not_reached();
2222             }
2223         }
2224     }
2225 
2226     qapi_free_MemoryDeviceInfoList(info_list);
2227     hmp_handle_error(mon, err);
2228 }
2229 
2230 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2231 {
2232     IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2233     IOThreadInfoList *info;
2234     IOThreadInfo *value;
2235 
2236     for (info = info_list; info; info = info->next) {
2237         value = info->value;
2238         monitor_printf(mon, "%s:\n", value->id);
2239         monitor_printf(mon, "  thread_id=%" PRId64 "\n", value->thread_id);
2240         monitor_printf(mon, "  poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2241         monitor_printf(mon, "  poll-grow=%" PRId64 "\n", value->poll_grow);
2242         monitor_printf(mon, "  poll-shrink=%" PRId64 "\n", value->poll_shrink);
2243     }
2244 
2245     qapi_free_IOThreadInfoList(info_list);
2246 }
2247 
2248 void hmp_rocker(Monitor *mon, const QDict *qdict)
2249 {
2250     const char *name = qdict_get_str(qdict, "name");
2251     RockerSwitch *rocker;
2252     Error *err = NULL;
2253 
2254     rocker = qmp_query_rocker(name, &err);
2255     if (err != NULL) {
2256         hmp_handle_error(mon, err);
2257         return;
2258     }
2259 
2260     monitor_printf(mon, "name: %s\n", rocker->name);
2261     monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2262     monitor_printf(mon, "ports: %d\n", rocker->ports);
2263 
2264     qapi_free_RockerSwitch(rocker);
2265 }
2266 
2267 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2268 {
2269     RockerPortList *list, *port;
2270     const char *name = qdict_get_str(qdict, "name");
2271     Error *err = NULL;
2272 
2273     list = qmp_query_rocker_ports(name, &err);
2274     if (err != NULL) {
2275         hmp_handle_error(mon, err);
2276         return;
2277     }
2278 
2279     monitor_printf(mon, "            ena/    speed/ auto\n");
2280     monitor_printf(mon, "      port  link    duplex neg?\n");
2281 
2282     for (port = list; port; port = port->next) {
2283         monitor_printf(mon, "%10s  %-4s   %-3s  %2s  %-3s\n",
2284                        port->value->name,
2285                        port->value->enabled ? port->value->link_up ?
2286                        "up" : "down" : "!ena",
2287                        port->value->speed == 10000 ? "10G" : "??",
2288                        port->value->duplex ? "FD" : "HD",
2289                        port->value->autoneg ? "Yes" : "No");
2290     }
2291 
2292     qapi_free_RockerPortList(list);
2293 }
2294 
2295 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2296 {
2297     RockerOfDpaFlowList *list, *info;
2298     const char *name = qdict_get_str(qdict, "name");
2299     uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2300     Error *err = NULL;
2301 
2302     list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2303     if (err != NULL) {
2304         hmp_handle_error(mon, err);
2305         return;
2306     }
2307 
2308     monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2309 
2310     for (info = list; info; info = info->next) {
2311         RockerOfDpaFlow *flow = info->value;
2312         RockerOfDpaFlowKey *key = flow->key;
2313         RockerOfDpaFlowMask *mask = flow->mask;
2314         RockerOfDpaFlowAction *action = flow->action;
2315 
2316         if (flow->hits) {
2317             monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2318                            key->priority, key->tbl_id, flow->hits);
2319         } else {
2320             monitor_printf(mon, "%-4d %-3d     ",
2321                            key->priority, key->tbl_id);
2322         }
2323 
2324         if (key->has_in_pport) {
2325             monitor_printf(mon, " pport %d", key->in_pport);
2326             if (mask->has_in_pport) {
2327                 monitor_printf(mon, "(0x%x)", mask->in_pport);
2328             }
2329         }
2330 
2331         if (key->has_vlan_id) {
2332             monitor_printf(mon, " vlan %d",
2333                            key->vlan_id & VLAN_VID_MASK);
2334             if (mask->has_vlan_id) {
2335                 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2336             }
2337         }
2338 
2339         if (key->has_tunnel_id) {
2340             monitor_printf(mon, " tunnel %d", key->tunnel_id);
2341             if (mask->has_tunnel_id) {
2342                 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2343             }
2344         }
2345 
2346         if (key->has_eth_type) {
2347             switch (key->eth_type) {
2348             case 0x0806:
2349                 monitor_printf(mon, " ARP");
2350                 break;
2351             case 0x0800:
2352                 monitor_printf(mon, " IP");
2353                 break;
2354             case 0x86dd:
2355                 monitor_printf(mon, " IPv6");
2356                 break;
2357             case 0x8809:
2358                 monitor_printf(mon, " LACP");
2359                 break;
2360             case 0x88cc:
2361                 monitor_printf(mon, " LLDP");
2362                 break;
2363             default:
2364                 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2365                 break;
2366             }
2367         }
2368 
2369         if (key->has_eth_src) {
2370             if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2371                 (mask->has_eth_src) &&
2372                 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2373                 monitor_printf(mon, " src <any mcast/bcast>");
2374             } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2375                 (mask->has_eth_src) &&
2376                 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2377                 monitor_printf(mon, " src <any ucast>");
2378             } else {
2379                 monitor_printf(mon, " src %s", key->eth_src);
2380                 if (mask->has_eth_src) {
2381                     monitor_printf(mon, "(%s)", mask->eth_src);
2382                 }
2383             }
2384         }
2385 
2386         if (key->has_eth_dst) {
2387             if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2388                 (mask->has_eth_dst) &&
2389                 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2390                 monitor_printf(mon, " dst <any mcast/bcast>");
2391             } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2392                 (mask->has_eth_dst) &&
2393                 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2394                 monitor_printf(mon, " dst <any ucast>");
2395             } else {
2396                 monitor_printf(mon, " dst %s", key->eth_dst);
2397                 if (mask->has_eth_dst) {
2398                     monitor_printf(mon, "(%s)", mask->eth_dst);
2399                 }
2400             }
2401         }
2402 
2403         if (key->has_ip_proto) {
2404             monitor_printf(mon, " proto %d", key->ip_proto);
2405             if (mask->has_ip_proto) {
2406                 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2407             }
2408         }
2409 
2410         if (key->has_ip_tos) {
2411             monitor_printf(mon, " TOS %d", key->ip_tos);
2412             if (mask->has_ip_tos) {
2413                 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2414             }
2415         }
2416 
2417         if (key->has_ip_dst) {
2418             monitor_printf(mon, " dst %s", key->ip_dst);
2419         }
2420 
2421         if (action->has_goto_tbl || action->has_group_id ||
2422             action->has_new_vlan_id) {
2423             monitor_printf(mon, " -->");
2424         }
2425 
2426         if (action->has_new_vlan_id) {
2427             monitor_printf(mon, " apply new vlan %d",
2428                            ntohs(action->new_vlan_id));
2429         }
2430 
2431         if (action->has_group_id) {
2432             monitor_printf(mon, " write group 0x%08x", action->group_id);
2433         }
2434 
2435         if (action->has_goto_tbl) {
2436             monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2437         }
2438 
2439         monitor_printf(mon, "\n");
2440     }
2441 
2442     qapi_free_RockerOfDpaFlowList(list);
2443 }
2444 
2445 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2446 {
2447     RockerOfDpaGroupList *list, *g;
2448     const char *name = qdict_get_str(qdict, "name");
2449     uint8_t type = qdict_get_try_int(qdict, "type", 9);
2450     Error *err = NULL;
2451 
2452     list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2453     if (err != NULL) {
2454         hmp_handle_error(mon, err);
2455         return;
2456     }
2457 
2458     monitor_printf(mon, "id (decode) --> buckets\n");
2459 
2460     for (g = list; g; g = g->next) {
2461         RockerOfDpaGroup *group = g->value;
2462         bool set = false;
2463 
2464         monitor_printf(mon, "0x%08x", group->id);
2465 
2466         monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2467                                          group->type == 1 ? "L2 rewrite" :
2468                                          group->type == 2 ? "L3 unicast" :
2469                                          group->type == 3 ? "L2 multicast" :
2470                                          group->type == 4 ? "L2 flood" :
2471                                          group->type == 5 ? "L3 interface" :
2472                                          group->type == 6 ? "L3 multicast" :
2473                                          group->type == 7 ? "L3 ECMP" :
2474                                          group->type == 8 ? "L2 overlay" :
2475                                          "unknown");
2476 
2477         if (group->has_vlan_id) {
2478             monitor_printf(mon, " vlan %d", group->vlan_id);
2479         }
2480 
2481         if (group->has_pport) {
2482             monitor_printf(mon, " pport %d", group->pport);
2483         }
2484 
2485         if (group->has_index) {
2486             monitor_printf(mon, " index %d", group->index);
2487         }
2488 
2489         monitor_printf(mon, ") -->");
2490 
2491         if (group->has_set_vlan_id && group->set_vlan_id) {
2492             set = true;
2493             monitor_printf(mon, " set vlan %d",
2494                            group->set_vlan_id & VLAN_VID_MASK);
2495         }
2496 
2497         if (group->has_set_eth_src) {
2498             if (!set) {
2499                 set = true;
2500                 monitor_printf(mon, " set");
2501             }
2502             monitor_printf(mon, " src %s", group->set_eth_src);
2503         }
2504 
2505         if (group->has_set_eth_dst) {
2506             if (!set) {
2507                 monitor_printf(mon, " set");
2508             }
2509             monitor_printf(mon, " dst %s", group->set_eth_dst);
2510         }
2511 
2512         if (group->has_ttl_check && group->ttl_check) {
2513             monitor_printf(mon, " check TTL");
2514         }
2515 
2516         if (group->has_group_id && group->group_id) {
2517             monitor_printf(mon, " group id 0x%08x", group->group_id);
2518         }
2519 
2520         if (group->has_pop_vlan && group->pop_vlan) {
2521             monitor_printf(mon, " pop vlan");
2522         }
2523 
2524         if (group->has_out_pport) {
2525             monitor_printf(mon, " out pport %d", group->out_pport);
2526         }
2527 
2528         if (group->has_group_ids) {
2529             struct uint32List *id;
2530 
2531             monitor_printf(mon, " groups [");
2532             for (id = group->group_ids; id; id = id->next) {
2533                 monitor_printf(mon, "0x%08x", id->value);
2534                 if (id->next) {
2535                     monitor_printf(mon, ",");
2536                 }
2537             }
2538             monitor_printf(mon, "]");
2539         }
2540 
2541         monitor_printf(mon, "\n");
2542     }
2543 
2544     qapi_free_RockerOfDpaGroupList(list);
2545 }
2546 
2547 void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
2548 {
2549     ram_block_dump(mon);
2550 }
2551 
2552 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
2553 {
2554     Error *err = NULL;
2555     GuidInfo *info = qmp_query_vm_generation_id(&err);
2556     if (info) {
2557         monitor_printf(mon, "%s\n", info->guid);
2558     }
2559     hmp_handle_error(mon, err);
2560     qapi_free_GuidInfo(info);
2561 }
2562 
2563 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
2564 {
2565     Error *err = NULL;
2566     MemoryInfo *info = qmp_query_memory_size_summary(&err);
2567     if (info) {
2568         monitor_printf(mon, "base memory: %" PRIu64 "\n",
2569                        info->base_memory);
2570 
2571         if (info->has_plugged_memory) {
2572             monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
2573                            info->plugged_memory);
2574         }
2575 
2576         qapi_free_MemoryInfo(info);
2577     }
2578     hmp_handle_error(mon, err);
2579 }
2580