]> git.proxmox.com Git - mirror_qemu.git/blame - monitor/hmp-cmds.c
esp: ensure that do_cmd is set to zero before submitting an ESP select command
[mirror_qemu.git] / monitor / hmp-cmds.c
CommitLineData
48a32bed 1/*
f1b3ccfa 2 * Human Monitor Interface commands
48a32bed
AL
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 *
6b620ca3
PB
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.
48a32bed
AL
14 */
15
d38ea87a 16#include "qemu/osdep.h"
275307aa 17#include "monitor/hmp.h"
1422e32d 18#include "net/net.h"
fafa4d50 19#include "net/eth.h"
8228e353 20#include "chardev/char.h"
4c7b7e9b 21#include "sysemu/block-backend.h"
54d31236 22#include "sysemu/runstate.h"
213dcb06 23#include "qemu/config-file.h"
1de7afc9
PB
24#include "qemu/option.h"
25#include "qemu/timer.h"
1de7afc9 26#include "qemu/sockets.h"
ad6f932f 27#include "qemu/help_option.h"
5bce308a 28#include "monitor/monitor-internal.h"
e688df6b 29#include "qapi/error.h"
08528271 30#include "qapi/clone-visitor.h"
cff8b2c6 31#include "qapi/opts-visitor.h"
eb815e24 32#include "qapi/qapi-builtin-visit.h"
112ed241
MA
33#include "qapi/qapi-commands-block.h"
34#include "qapi/qapi-commands-char.h"
fa4dcf57 35#include "qapi/qapi-commands-control.h"
a83e24ba 36#include "qapi/qapi-commands-machine.h"
112ed241
MA
37#include "qapi/qapi-commands-migration.h"
38#include "qapi/qapi-commands-misc.h"
39#include "qapi/qapi-commands-net.h"
61c7f987 40#include "qapi/qapi-commands-pci.h"
112ed241
MA
41#include "qapi/qapi-commands-rocker.h"
42#include "qapi/qapi-commands-run-state.h"
43#include "qapi/qapi-commands-tpm.h"
44#include "qapi/qapi-commands-ui.h"
08528271 45#include "qapi/qapi-visit-net.h"
96eef042 46#include "qapi/qapi-visit-migration.h"
452fcdbc 47#include "qapi/qmp/qdict.h"
cc7a8ea7 48#include "qapi/qmp/qerror.h"
f4a06d13 49#include "qapi/string-input-visitor.h"
eb1539b2 50#include "qapi/string-output-visitor.h"
90998d58 51#include "qom/object_interfaces.h"
28ecbaee 52#include "ui/console.h"
f348b6d1 53#include "qemu/cutils.h"
d59ce6f3 54#include "qemu/error-report.h"
be9b23c4 55#include "exec/ramlist.h"
61b97833 56#include "hw/intc/intc.h"
f4b2c02a 57#include "hw/rdma/rdma.h"
5e22479a 58#include "migration/snapshot.h"
9d18af93 59#include "migration/misc.h"
48a32bed 60
22fa7da0
CR
61#ifdef CONFIG_SPICE
62#include <spice/enums.h>
63#endif
64
187c6147 65void hmp_handle_error(Monitor *mon, Error *err)
0cfd6a9a 66{
187c6147
VSO
67 if (err) {
68 error_reportf_err(err, "Error: ");
0cfd6a9a
LC
69 }
70}
71
08528271
DDAG
72/*
73 * Produce a strList from a comma separated list.
74 * A NULL or empty input string return NULL.
75 */
76static strList *strList_from_comma_list(const char *in)
77{
78 strList *res = NULL;
c3033fd3 79 strList **tail = &res;
08528271
DDAG
80
81 while (in && in[0]) {
82 char *comma = strchr(in, ',');
c3033fd3 83 char *value;
08528271
DDAG
84
85 if (comma) {
c3033fd3 86 value = g_strndup(in, comma - in);
08528271
DDAG
87 in = comma + 1; /* skip the , */
88 } else {
c3033fd3 89 value = g_strdup(in);
08528271
DDAG
90 in = NULL;
91 }
c3033fd3 92 QAPI_LIST_APPEND(tail, value);
08528271
DDAG
93 }
94
95 return res;
96}
97
84f2d0ea 98void hmp_info_name(Monitor *mon, const QDict *qdict)
48a32bed
AL
99{
100 NameInfo *info;
101
102 info = qmp_query_name(NULL);
103 if (info->has_name) {
104 monitor_printf(mon, "%s\n", info->name);
105 }
106 qapi_free_NameInfo(info);
107}
b9c15f16 108
84f2d0ea 109void hmp_info_version(Monitor *mon, const QDict *qdict)
b9c15f16
LC
110{
111 VersionInfo *info;
112
113 info = qmp_query_version(NULL);
114
115 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
4752cdbb 116 info->qemu->major, info->qemu->minor, info->qemu->micro,
b9c15f16
LC
117 info->package);
118
119 qapi_free_VersionInfo(info);
120}
292a2602 121
84f2d0ea 122void hmp_info_kvm(Monitor *mon, const QDict *qdict)
292a2602
LC
123{
124 KvmInfo *info;
125
126 info = qmp_query_kvm(NULL);
127 monitor_printf(mon, "kvm support: ");
128 if (info->present) {
129 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
130 } else {
131 monitor_printf(mon, "not compiled\n");
132 }
133
134 qapi_free_KvmInfo(info);
135}
136
84f2d0ea 137void hmp_info_status(Monitor *mon, const QDict *qdict)
1fa9a5e4
LC
138{
139 StatusInfo *info;
140
141 info = qmp_query_status(NULL);
142
143 monitor_printf(mon, "VM status: %s%s",
144 info->running ? "running" : "paused",
145 info->singlestep ? " (single step mode)" : "");
146
147 if (!info->running && info->status != RUN_STATE_PAUSED) {
977c736f 148 monitor_printf(mon, " (%s)", RunState_str(info->status));
1fa9a5e4
LC
149 }
150
151 monitor_printf(mon, "\n");
152
153 qapi_free_StatusInfo(info);
154}
155
84f2d0ea 156void hmp_info_uuid(Monitor *mon, const QDict *qdict)
efab767e
LC
157{
158 UuidInfo *info;
159
160 info = qmp_query_uuid(NULL);
161 monitor_printf(mon, "%s\n", info->UUID);
162 qapi_free_UuidInfo(info);
163}
c5a415a0 164
84f2d0ea 165void hmp_info_chardev(Monitor *mon, const QDict *qdict)
c5a415a0
LC
166{
167 ChardevInfoList *char_info, *info;
168
169 char_info = qmp_query_chardev(NULL);
170 for (info = char_info; info; info = info->next) {
171 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
172 info->value->filename);
173 }
174
175 qapi_free_ChardevInfoList(char_info);
176}
7a7f325e 177
84f2d0ea 178void hmp_info_mice(Monitor *mon, const QDict *qdict)
e235cec3
LC
179{
180 MouseInfoList *mice_list, *mouse;
181
182 mice_list = qmp_query_mice(NULL);
183 if (!mice_list) {
184 monitor_printf(mon, "No mouse devices connected\n");
185 return;
186 }
187
188 for (mouse = mice_list; mouse; mouse = mouse->next) {
189 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
190 mouse->value->current ? '*' : ' ',
191 mouse->value->index, mouse->value->name,
192 mouse->value->absolute ? " (absolute)" : "");
193 }
194
195 qapi_free_MouseInfoList(mice_list);
196}
197
9aca82ba
JQ
198static char *SocketAddress_to_str(SocketAddress *addr)
199{
200 switch (addr->type) {
201 case SOCKET_ADDRESS_TYPE_INET:
202 return g_strdup_printf("tcp:%s:%s",
203 addr->u.inet.host,
204 addr->u.inet.port);
205 case SOCKET_ADDRESS_TYPE_UNIX:
206 return g_strdup_printf("unix:%s",
207 addr->u.q_unix.path);
208 case SOCKET_ADDRESS_TYPE_FD:
209 return g_strdup_printf("fd:%s", addr->u.fd.str);
210 case SOCKET_ADDRESS_TYPE_VSOCK:
211 return g_strdup_printf("tcp:%s:%s",
212 addr->u.vsock.cid,
213 addr->u.vsock.port);
214 default:
215 return g_strdup("unknown address type");
216 }
217}
218
84f2d0ea 219void hmp_info_migrate(Monitor *mon, const QDict *qdict)
791e7c82
LC
220{
221 MigrationInfo *info;
222
223 info = qmp_query_migrate(NULL);
bbf6da32 224
9d18af93
PX
225 migration_global_dump(mon);
226
a64aec72
DDAG
227 if (info->blocked) {
228 strList *reasons = info->blocked_reasons;
229 monitor_printf(mon, "Outgoing migration blocked:\n");
230 while (reasons) {
231 monitor_printf(mon, " %s\n", reasons->value);
232 reasons = reasons->next;
233 }
234 }
235
791e7c82 236 if (info->has_status) {
d59ce6f3 237 monitor_printf(mon, "Migration status: %s",
977c736f 238 MigrationStatus_str(info->status));
d59ce6f3
DB
239 if (info->status == MIGRATION_STATUS_FAILED &&
240 info->has_error_desc) {
241 monitor_printf(mon, " (%s)\n", info->error_desc);
242 } else {
243 monitor_printf(mon, "\n");
244 }
245
7ac5529a 246 monitor_printf(mon, "total time: %" PRIu64 " ms\n",
7aa939af 247 info->total_time);
2c52ddf1 248 if (info->has_expected_downtime) {
7ac5529a 249 monitor_printf(mon, "expected downtime: %" PRIu64 " ms\n",
2c52ddf1
JQ
250 info->expected_downtime);
251 }
9c5a9fcf 252 if (info->has_downtime) {
7ac5529a 253 monitor_printf(mon, "downtime: %" PRIu64 " ms\n",
9c5a9fcf
JQ
254 info->downtime);
255 }
ed4fbd10 256 if (info->has_setup_time) {
7ac5529a 257 monitor_printf(mon, "setup: %" PRIu64 " ms\n",
ed4fbd10
MH
258 info->setup_time);
259 }
791e7c82
LC
260 }
261
262 if (info->has_ram) {
263 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
264 info->ram->transferred >> 10);
7e114f8c
MH
265 monitor_printf(mon, "throughput: %0.2f mbps\n",
266 info->ram->mbps);
791e7c82
LC
267 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
268 info->ram->remaining >> 10);
269 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
270 info->ram->total >> 10);
004d4c10
OW
271 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
272 info->ram->duplicate);
f1c72795
PL
273 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
274 info->ram->skipped);
004d4c10
OW
275 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
276 info->ram->normal);
277 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
278 info->ram->normal_bytes >> 10);
58570ed8
C
279 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
280 info->ram->dirty_sync_count);
030ce1f8
CF
281 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
282 info->ram->page_size >> 10);
a61c45bd
JQ
283 monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n",
284 info->ram->multifd_bytes >> 10);
aecbfe9c
XG
285 monitor_printf(mon, "pages-per-second: %" PRIu64 "\n",
286 info->ram->pages_per_second);
030ce1f8 287
8d017193
JQ
288 if (info->ram->dirty_pages_rate) {
289 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
290 info->ram->dirty_pages_rate);
291 }
d3bf5418
DDAG
292 if (info->ram->postcopy_requests) {
293 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
294 info->ram->postcopy_requests);
295 }
791e7c82
LC
296 }
297
298 if (info->has_disk) {
299 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
300 info->disk->transferred >> 10);
301 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
302 info->disk->remaining >> 10);
303 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
304 info->disk->total >> 10);
305 }
306
f36d55af
OW
307 if (info->has_xbzrle_cache) {
308 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
309 info->xbzrle_cache->cache_size);
310 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
311 info->xbzrle_cache->bytes >> 10);
312 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
313 info->xbzrle_cache->pages);
afb5d01c 314 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 " pages\n",
f36d55af 315 info->xbzrle_cache->cache_miss);
8bc39233
C
316 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
317 info->xbzrle_cache->cache_miss_rate);
e460a4b1
WW
318 monitor_printf(mon, "xbzrle encoding rate: %0.2f\n",
319 info->xbzrle_cache->encoding_rate);
06b1c6f8 320 monitor_printf(mon, "xbzrle overflow: %" PRIu64 "\n",
f36d55af
OW
321 info->xbzrle_cache->overflow);
322 }
323
76e03000
XG
324 if (info->has_compression) {
325 monitor_printf(mon, "compression pages: %" PRIu64 " pages\n",
326 info->compression->pages);
327 monitor_printf(mon, "compression busy: %" PRIu64 "\n",
328 info->compression->busy);
329 monitor_printf(mon, "compression busy rate: %0.2f\n",
330 info->compression->busy_rate);
afb5d01c
MZ
331 monitor_printf(mon, "compressed size: %" PRIu64 " kbytes\n",
332 info->compression->compressed_size >> 10);
76e03000
XG
333 monitor_printf(mon, "compression rate: %0.2f\n",
334 info->compression->compression_rate);
335 }
336
d85a31d1 337 if (info->has_cpu_throttle_percentage) {
4782893e 338 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
d85a31d1 339 info->cpu_throttle_percentage);
4782893e
JH
340 }
341
65ace060
AP
342 if (info->has_postcopy_blocktime) {
343 monitor_printf(mon, "postcopy blocktime: %u\n",
344 info->postcopy_blocktime);
345 }
346
347 if (info->has_postcopy_vcpu_blocktime) {
348 Visitor *v;
349 char *str;
350 v = string_output_visitor_new(false, &str);
1f584248
MA
351 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime,
352 &error_abort);
65ace060
AP
353 visit_complete(v, &str);
354 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
355 g_free(str);
356 visit_free(v);
357 }
9aca82ba
JQ
358 if (info->has_socket_address) {
359 SocketAddressList *addr;
360
361 monitor_printf(mon, "socket address: [\n");
362
363 for (addr = info->socket_address; addr; addr = addr->next) {
364 char *s = SocketAddress_to_str(addr->value);
365 monitor_printf(mon, "\t%s\n", s);
366 g_free(s);
367 }
368 monitor_printf(mon, "]\n");
369 }
3710586c
KW
370
371 if (info->has_vfio) {
372 monitor_printf(mon, "vfio device transferred: %" PRIu64 " kbytes\n",
373 info->vfio->transferred >> 10);
374 }
375
791e7c82 376 qapi_free_MigrationInfo(info);
bbf6da32
OW
377}
378
84f2d0ea 379void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
bbf6da32
OW
380{
381 MigrationCapabilityStatusList *caps, *cap;
382
383 caps = qmp_query_migrate_capabilities(NULL);
384
385 if (caps) {
bbf6da32 386 for (cap = caps; cap; cap = cap->next) {
d80a0169 387 monitor_printf(mon, "%s: %s\n",
977c736f 388 MigrationCapability_str(cap->value->capability),
bbf6da32
OW
389 cap->value->state ? "on" : "off");
390 }
bbf6da32
OW
391 }
392
393 qapi_free_MigrationCapabilityStatusList(caps);
791e7c82
LC
394}
395
50e9a629
LL
396void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
397{
398 MigrationParameters *params;
399
400 params = qmp_query_migrate_parameters(NULL);
401
402 if (params) {
ee3d96ba
DDAG
403 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
404 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL),
405 params->announce_initial);
406 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
407 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX),
408 params->announce_max);
409 monitor_printf(mon, "%s: %" PRIu64 "\n",
410 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS),
411 params->announce_rounds);
412 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
413 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP),
414 params->announce_step);
de63ab61 415 assert(params->has_compress_level);
741d4086 416 monitor_printf(mon, "%s: %u\n",
977c736f 417 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
50e9a629 418 params->compress_level);
de63ab61 419 assert(params->has_compress_threads);
741d4086 420 monitor_printf(mon, "%s: %u\n",
977c736f 421 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
50e9a629 422 params->compress_threads);
1d58872a
XG
423 assert(params->has_compress_wait_thread);
424 monitor_printf(mon, "%s: %s\n",
425 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD),
426 params->compress_wait_thread ? "on" : "off");
de63ab61 427 assert(params->has_decompress_threads);
741d4086 428 monitor_printf(mon, "%s: %u\n",
977c736f 429 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
50e9a629 430 params->decompress_threads);
dc14a470
KZ
431 assert(params->has_throttle_trigger_threshold);
432 monitor_printf(mon, "%s: %u\n",
433 MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD),
434 params->throttle_trigger_threshold);
de63ab61 435 assert(params->has_cpu_throttle_initial);
741d4086 436 monitor_printf(mon, "%s: %u\n",
977c736f 437 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
d85a31d1 438 params->cpu_throttle_initial);
de63ab61 439 assert(params->has_cpu_throttle_increment);
741d4086 440 monitor_printf(mon, "%s: %u\n",
977c736f 441 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
d85a31d1 442 params->cpu_throttle_increment);
cbbf8182
KZ
443 assert(params->has_cpu_throttle_tailslow);
444 monitor_printf(mon, "%s: %s\n",
445 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW),
446 params->cpu_throttle_tailslow ? "on" : "off");
4cbc9c7f
LQ
447 assert(params->has_max_cpu_throttle);
448 monitor_printf(mon, "%s: %u\n",
449 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE),
450 params->max_cpu_throttle);
8cc99dcd 451 assert(params->has_tls_creds);
2c02468c 452 monitor_printf(mon, "%s: '%s'\n",
977c736f 453 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
8cc99dcd
MA
454 params->tls_creds);
455 assert(params->has_tls_hostname);
2c02468c 456 monitor_printf(mon, "%s: '%s'\n",
977c736f 457 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
8cc99dcd 458 params->tls_hostname);
2ff30257 459 assert(params->has_max_bandwidth);
741d4086 460 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
977c736f 461 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
2ff30257
AA
462 params->max_bandwidth);
463 assert(params->has_downtime_limit);
39337f12 464 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
977c736f 465 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
2ff30257 466 params->downtime_limit);
fe39a4d4 467 assert(params->has_x_checkpoint_delay);
39337f12 468 monitor_printf(mon, "%s: %u ms\n",
977c736f 469 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
68b53591 470 params->x_checkpoint_delay);
2833c59b
JQ
471 assert(params->has_block_incremental);
472 monitor_printf(mon, "%s: %s\n",
977c736f
MA
473 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
474 params->block_incremental ? "on" : "off");
741d4086 475 monitor_printf(mon, "%s: %u\n",
cbfd6c95
JQ
476 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS),
477 params->multifd_channels);
96eef042
JQ
478 monitor_printf(mon, "%s: %s\n",
479 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION),
480 MultiFDCompression_str(params->multifd_compression));
39337f12 481 monitor_printf(mon, "%s: %" PRIu64 " bytes\n",
73af8dd8
JQ
482 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
483 params->xbzrle_cache_size);
7e555c6c
DDAG
484 monitor_printf(mon, "%s: %" PRIu64 "\n",
485 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
486 params->max_postcopy_bandwidth);
7cd75cbd 487 monitor_printf(mon, "%s: '%s'\n",
d2f1d29b 488 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
7cd75cbd 489 params->tls_authz);
31e4c354
HR
490
491 if (params->has_block_bitmap_mapping) {
492 const BitmapMigrationNodeAliasList *bmnal;
493
494 monitor_printf(mon, "%s:\n",
495 MigrationParameter_str(
496 MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING));
497
498 for (bmnal = params->block_bitmap_mapping;
499 bmnal;
500 bmnal = bmnal->next)
501 {
502 const BitmapMigrationNodeAlias *bmna = bmnal->value;
503 const BitmapMigrationBitmapAliasList *bmbal;
504
505 monitor_printf(mon, " '%s' -> '%s'\n",
506 bmna->node_name, bmna->alias);
507
508 for (bmbal = bmna->bitmaps; bmbal; bmbal = bmbal->next) {
509 const BitmapMigrationBitmapAlias *bmba = bmbal->value;
510
511 monitor_printf(mon, " '%s' -> '%s'\n",
512 bmba->name, bmba->alias);
513 }
514 }
515 }
50e9a629
LL
516 }
517
518 qapi_free_MigrationParameters(params);
519}
520
f11f57e4 521
05eb4a25 522#ifdef CONFIG_VNC
0a9667ec
DDAG
523/* Helper for hmp_info_vnc_clients, _servers */
524static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
525 const char *name)
526{
527 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
528 name,
529 info->host,
530 info->service,
977c736f 531 NetworkAddressFamily_str(info->family),
0a9667ec
DDAG
532 info->websocket ? " (Websocket)" : "");
533}
534
535/* Helper displaying and auth and crypt info */
536static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
537 VncPrimaryAuth auth,
538 VncVencryptSubAuth *vencrypt)
539{
540 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
977c736f
MA
541 VncPrimaryAuth_str(auth),
542 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
0a9667ec
DDAG
543}
544
545static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
546{
547 while (client) {
548 VncClientInfo *cinfo = client->value;
549
550 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
551 monitor_printf(mon, " x509_dname: %s\n",
552 cinfo->has_x509_dname ?
553 cinfo->x509_dname : "none");
554 monitor_printf(mon, " sasl_username: %s\n",
555 cinfo->has_sasl_username ?
556 cinfo->sasl_username : "none");
557
558 client = client->next;
559 }
560}
561
562static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
563{
564 while (server) {
565 VncServerInfo2 *sinfo = server->value;
566 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
567 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
568 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
569 server = server->next;
570 }
571}
572
84f2d0ea 573void hmp_info_vnc(Monitor *mon, const QDict *qdict)
2b54aa87 574{
d4ff1093 575 VncInfo2List *info2l, *info2l_head;
2b54aa87 576 Error *err = NULL;
2b54aa87 577
0a9667ec 578 info2l = qmp_query_vnc_servers(&err);
d4ff1093 579 info2l_head = info2l;
2b54aa87 580 if (err) {
187c6147 581 hmp_handle_error(mon, err);
2b54aa87
LC
582 return;
583 }
0a9667ec
DDAG
584 if (!info2l) {
585 monitor_printf(mon, "None\n");
586 return;
2b54aa87
LC
587 }
588
0a9667ec
DDAG
589 while (info2l) {
590 VncInfo2 *info = info2l->value;
591 monitor_printf(mon, "%s:\n", info->id);
592 hmp_info_vnc_servers(mon, info->server);
593 hmp_info_vnc_clients(mon, info->clients);
594 if (!info->server) {
595 /* The server entry displays its auth, we only
596 * need to display in the case of 'reverse' connections
597 * where there's no server.
598 */
599 hmp_info_vnc_authcrypt(mon, " ", info->auth,
600 info->has_vencrypt ? &info->vencrypt : NULL);
601 }
602 if (info->has_display) {
603 monitor_printf(mon, " Display: %s\n", info->display);
2b54aa87 604 }
0a9667ec 605 info2l = info2l->next;
2b54aa87
LC
606 }
607
d4ff1093 608 qapi_free_VncInfo2List(info2l_head);
0a9667ec 609
2b54aa87 610}
05eb4a25 611#endif
2b54aa87 612
206addd5 613#ifdef CONFIG_SPICE
84f2d0ea 614void hmp_info_spice(Monitor *mon, const QDict *qdict)
d1f29646
LC
615{
616 SpiceChannelList *chan;
617 SpiceInfo *info;
22fa7da0
CR
618 const char *channel_name;
619 const char * const channel_names[] = {
620 [SPICE_CHANNEL_MAIN] = "main",
621 [SPICE_CHANNEL_DISPLAY] = "display",
622 [SPICE_CHANNEL_INPUTS] = "inputs",
623 [SPICE_CHANNEL_CURSOR] = "cursor",
624 [SPICE_CHANNEL_PLAYBACK] = "playback",
625 [SPICE_CHANNEL_RECORD] = "record",
626 [SPICE_CHANNEL_TUNNEL] = "tunnel",
627 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
628 [SPICE_CHANNEL_USBREDIR] = "usbredir",
629 [SPICE_CHANNEL_PORT] = "port",
7c6044a9
GH
630#if 0
631 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
632 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
633 * as quick fix for build failures with older versions. */
22fa7da0 634 [SPICE_CHANNEL_WEBDAV] = "webdav",
7c6044a9 635#endif
22fa7da0 636 };
d1f29646
LC
637
638 info = qmp_query_spice(NULL);
639
640 if (!info->enabled) {
641 monitor_printf(mon, "Server: disabled\n");
642 goto out;
643 }
644
645 monitor_printf(mon, "Server:\n");
646 if (info->has_port) {
647 monitor_printf(mon, " address: %s:%" PRId64 "\n",
648 info->host, info->port);
649 }
650 if (info->has_tls_port) {
651 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
652 info->host, info->tls_port);
653 }
61c4efe2
YH
654 monitor_printf(mon, " migrated: %s\n",
655 info->migrated ? "true" : "false");
d1f29646
LC
656 monitor_printf(mon, " auth: %s\n", info->auth);
657 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
4efee029 658 monitor_printf(mon, " mouse-mode: %s\n",
977c736f 659 SpiceQueryMouseMode_str(info->mouse_mode));
d1f29646
LC
660
661 if (!info->has_channels || info->channels == NULL) {
662 monitor_printf(mon, "Channels: none\n");
663 } else {
664 for (chan = info->channels; chan; chan = chan->next) {
665 monitor_printf(mon, "Channel:\n");
666 monitor_printf(mon, " address: %s:%s%s\n",
ddf21908 667 chan->value->host, chan->value->port,
d1f29646
LC
668 chan->value->tls ? " [tls]" : "");
669 monitor_printf(mon, " session: %" PRId64 "\n",
670 chan->value->connection_id);
671 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
672 chan->value->channel_type, chan->value->channel_id);
22fa7da0
CR
673
674 channel_name = "unknown";
675 if (chan->value->channel_type > 0 &&
676 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
677 channel_names[chan->value->channel_type]) {
678 channel_name = channel_names[chan->value->channel_type];
679 }
680
681 monitor_printf(mon, " channel name: %s\n", channel_name);
d1f29646
LC
682 }
683 }
684
685out:
686 qapi_free_SpiceInfo(info);
687}
206addd5 688#endif
d1f29646 689
84f2d0ea 690void hmp_info_balloon(Monitor *mon, const QDict *qdict)
96637bcd
LC
691{
692 BalloonInfo *info;
693 Error *err = NULL;
694
695 info = qmp_query_balloon(&err);
696 if (err) {
187c6147 697 hmp_handle_error(mon, err);
96637bcd
LC
698 return;
699 }
700
01ceb97e 701 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
96637bcd
LC
702
703 qapi_free_BalloonInfo(info);
704}
705
79627472
LC
706static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
707{
708 PciMemoryRegionList *region;
709
710 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
711 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
712 dev->slot, dev->function);
713 monitor_printf(mon, " ");
714
9fa02cd1
EB
715 if (dev->class_info->has_desc) {
716 monitor_printf(mon, "%s", dev->class_info->desc);
79627472 717 } else {
9fa02cd1 718 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
79627472
LC
719 }
720
721 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
9fa02cd1 722 dev->id->vendor, dev->id->device);
18613dc6
DL
723 if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) {
724 monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n",
725 dev->id->subsystem_vendor, dev->id->subsystem);
726 }
79627472
LC
727
728 if (dev->has_irq) {
12fcf49c
PX
729 monitor_printf(mon, " IRQ %" PRId64 ", pin %c\n",
730 dev->irq, (char)('A' + dev->irq_pin - 1));
79627472
LC
731 }
732
733 if (dev->has_pci_bridge) {
734 monitor_printf(mon, " BUS %" PRId64 ".\n",
9fa02cd1 735 dev->pci_bridge->bus->number);
79627472 736 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
9fa02cd1 737 dev->pci_bridge->bus->secondary);
79627472 738 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
9fa02cd1 739 dev->pci_bridge->bus->subordinate);
79627472
LC
740
741 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
9fa02cd1
EB
742 dev->pci_bridge->bus->io_range->base,
743 dev->pci_bridge->bus->io_range->limit);
79627472
LC
744
745 monitor_printf(mon,
746 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
9fa02cd1
EB
747 dev->pci_bridge->bus->memory_range->base,
748 dev->pci_bridge->bus->memory_range->limit);
79627472
LC
749
750 monitor_printf(mon, " prefetchable memory range "
751 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
9fa02cd1
EB
752 dev->pci_bridge->bus->prefetchable_range->base,
753 dev->pci_bridge->bus->prefetchable_range->limit);
79627472
LC
754 }
755
756 for (region = dev->regions; region; region = region->next) {
757 uint64_t addr, size;
758
759 addr = region->value->address;
760 size = region->value->size;
761
762 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
763
764 if (!strcmp(region->value->type, "io")) {
765 monitor_printf(mon, "I/O at 0x%04" PRIx64
766 " [0x%04" PRIx64 "].\n",
767 addr, addr + size - 1);
768 } else {
769 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
770 " [0x%08" PRIx64 "].\n",
771 region->value->mem_type_64 ? 64 : 32,
772 region->value->prefetch ? " prefetchable" : "",
773 addr, addr + size - 1);
774 }
775 }
776
777 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
778
779 if (dev->has_pci_bridge) {
780 if (dev->pci_bridge->has_devices) {
781 PciDeviceInfoList *cdev;
782 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
783 hmp_info_pci_device(mon, cdev->value);
784 }
785 }
786 }
787}
788
61b97833
HP
789static int hmp_info_irq_foreach(Object *obj, void *opaque)
790{
791 InterruptStatsProvider *intc;
792 InterruptStatsProviderClass *k;
793 Monitor *mon = opaque;
794
795 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
796 intc = INTERRUPT_STATS_PROVIDER(obj);
797 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
798 uint64_t *irq_counts;
799 unsigned int nb_irqs, i;
800 if (k->get_statistics &&
801 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
802 if (nb_irqs > 0) {
803 monitor_printf(mon, "IRQ statistics for %s:\n",
804 object_get_typename(obj));
805 for (i = 0; i < nb_irqs; i++) {
806 if (irq_counts[i] > 0) {
807 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
808 irq_counts[i]);
809 }
810 }
811 }
812 } else {
813 monitor_printf(mon, "IRQ statistics not available for %s.\n",
814 object_get_typename(obj));
815 }
816 }
817
818 return 0;
819}
820
821void hmp_info_irq(Monitor *mon, const QDict *qdict)
822{
823 object_child_foreach_recursive(object_get_root(),
824 hmp_info_irq_foreach, mon);
825}
826
827static int hmp_info_pic_foreach(Object *obj, void *opaque)
828{
829 InterruptStatsProvider *intc;
830 InterruptStatsProviderClass *k;
831 Monitor *mon = opaque;
832
833 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
834 intc = INTERRUPT_STATS_PROVIDER(obj);
835 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
836 if (k->print_info) {
837 k->print_info(intc, mon);
838 } else {
839 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
840 object_get_typename(obj));
841 }
842 }
843
844 return 0;
845}
846
847void hmp_info_pic(Monitor *mon, const QDict *qdict)
848{
849 object_child_foreach_recursive(object_get_root(),
850 hmp_info_pic_foreach, mon);
851}
852
f4b2c02a
YS
853static int hmp_info_rdma_foreach(Object *obj, void *opaque)
854{
855 RdmaProvider *rdma;
856 RdmaProviderClass *k;
857 Monitor *mon = opaque;
858
859 if (object_dynamic_cast(obj, INTERFACE_RDMA_PROVIDER)) {
860 rdma = RDMA_PROVIDER(obj);
861 k = RDMA_PROVIDER_GET_CLASS(obj);
862 if (k->print_statistics) {
863 k->print_statistics(mon, rdma);
864 } else {
865 monitor_printf(mon, "RDMA statistics not available for %s.\n",
866 object_get_typename(obj));
867 }
868 }
869
870 return 0;
871}
872
873void hmp_info_rdma(Monitor *mon, const QDict *qdict)
874{
875 object_child_foreach_recursive(object_get_root(),
876 hmp_info_rdma_foreach, mon);
877}
878
84f2d0ea 879void hmp_info_pci(Monitor *mon, const QDict *qdict)
79627472 880{
f46cee37 881 PciInfoList *info_list, *info;
79627472
LC
882 Error *err = NULL;
883
f46cee37 884 info_list = qmp_query_pci(&err);
79627472
LC
885 if (err) {
886 monitor_printf(mon, "PCI devices not supported\n");
887 error_free(err);
888 return;
889 }
890
f46cee37 891 for (info = info_list; info; info = info->next) {
79627472
LC
892 PciDeviceInfoList *dev;
893
894 for (dev = info->value->devices; dev; dev = dev->next) {
895 hmp_info_pci_device(mon, dev->value);
896 }
897 }
898
f46cee37 899 qapi_free_PciInfoList(info_list);
79627472
LC
900}
901
d1a0cf73
SB
902void hmp_info_tpm(Monitor *mon, const QDict *qdict)
903{
904 TPMInfoList *info_list, *info;
905 Error *err = NULL;
906 unsigned int c = 0;
907 TPMPassthroughOptions *tpo;
f4ede81e 908 TPMEmulatorOptions *teo;
d1a0cf73
SB
909
910 info_list = qmp_query_tpm(&err);
911 if (err) {
912 monitor_printf(mon, "TPM device not supported\n");
913 error_free(err);
914 return;
915 }
916
917 if (info_list) {
918 monitor_printf(mon, "TPM device:\n");
919 }
920
921 for (info = info_list; info; info = info->next) {
922 TPMInfo *ti = info->value;
923 monitor_printf(mon, " tpm%d: model=%s\n",
977c736f 924 c, TpmModel_str(ti->model));
d1a0cf73
SB
925
926 monitor_printf(mon, " \\ %s: type=%s",
977c736f 927 ti->id, TpmTypeOptionsKind_str(ti->options->type));
d1a0cf73 928
ce21131a 929 switch (ti->options->type) {
88ca7bcf 930 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
32bafa8f 931 tpo = ti->options->u.passthrough.data;
d1a0cf73
SB
932 monitor_printf(mon, "%s%s%s%s",
933 tpo->has_path ? ",path=" : "",
934 tpo->has_path ? tpo->path : "",
935 tpo->has_cancel_path ? ",cancel-path=" : "",
936 tpo->has_cancel_path ? tpo->cancel_path : "");
937 break;
f4ede81e
AV
938 case TPM_TYPE_OPTIONS_KIND_EMULATOR:
939 teo = ti->options->u.emulator.data;
940 monitor_printf(mon, ",chardev=%s", teo->chardev);
941 break;
7fb1cf16 942 case TPM_TYPE_OPTIONS_KIND__MAX:
d1a0cf73
SB
943 break;
944 }
945 monitor_printf(mon, "\n");
946 c++;
947 }
948 qapi_free_TPMInfoList(info_list);
949}
950
7a7f325e
LC
951void hmp_quit(Monitor *mon, const QDict *qdict)
952{
953 monitor_suspend(mon);
954 qmp_quit(NULL);
955}
5f158f21
LC
956
957void hmp_stop(Monitor *mon, const QDict *qdict)
958{
959 qmp_stop(NULL);
960}
38d22653 961
dd12e1bb
EC
962void hmp_sync_profile(Monitor *mon, const QDict *qdict)
963{
964 const char *op = qdict_get_try_str(qdict, "op");
965
966 if (op == NULL) {
967 bool on = qsp_is_enabled();
968
969 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off");
970 return;
971 }
972 if (!strcmp(op, "on")) {
973 qsp_enable();
974 } else if (!strcmp(op, "off")) {
975 qsp_disable();
976 } else if (!strcmp(op, "reset")) {
977 qsp_reset();
978 } else {
979 Error *err = NULL;
980
981 error_setg(&err, QERR_INVALID_PARAMETER, op);
187c6147 982 hmp_handle_error(mon, err);
dd12e1bb
EC
983 }
984}
985
38d22653
LC
986void hmp_system_reset(Monitor *mon, const QDict *qdict)
987{
988 qmp_system_reset(NULL);
989}
5bc465e4
LC
990
991void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
992{
993 qmp_system_powerdown(NULL);
994}
755f1968 995
8e8581e6
DDAG
996void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
997{
998 Error *err = NULL;
999
361ac948 1000 qmp_x_exit_preconfig(&err);
187c6147 1001 hmp_handle_error(mon, err);
8e8581e6
DDAG
1002}
1003
755f1968
LC
1004void hmp_cpu(Monitor *mon, const QDict *qdict)
1005{
1006 int64_t cpu_index;
1007
1008 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1009 use it are converted to the QAPI */
1010 cpu_index = qdict_get_int(qdict, "index");
dcba65f8 1011 if (monitor_set_cpu(mon, cpu_index) < 0) {
755f1968
LC
1012 monitor_printf(mon, "invalid CPU index\n");
1013 }
1014}
0cfd6a9a
LC
1015
1016void hmp_memsave(Monitor *mon, const QDict *qdict)
1017{
1018 uint32_t size = qdict_get_int(qdict, "size");
1019 const char *filename = qdict_get_str(qdict, "filename");
1020 uint64_t addr = qdict_get_int(qdict, "val");
e940f543 1021 Error *err = NULL;
87e6f4a4 1022 int cpu_index = monitor_get_cpu_index(mon);
0cfd6a9a 1023
854e67fe
TH
1024 if (cpu_index < 0) {
1025 monitor_printf(mon, "No CPU available\n");
1026 return;
1027 }
1028
1029 qmp_memsave(addr, size, filename, true, cpu_index, &err);
187c6147 1030 hmp_handle_error(mon, err);
0cfd6a9a 1031}
6d3962bf
LC
1032
1033void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1034{
1035 uint32_t size = qdict_get_int(qdict, "size");
1036 const char *filename = qdict_get_str(qdict, "filename");
1037 uint64_t addr = qdict_get_int(qdict, "val");
e940f543 1038 Error *err = NULL;
6d3962bf 1039
e940f543 1040 qmp_pmemsave(addr, size, filename, &err);
187c6147 1041 hmp_handle_error(mon, err);
1f590cf9
LL
1042}
1043
3949e594 1044void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1f590cf9 1045{
1f590cf9
LL
1046 const char *chardev = qdict_get_str(qdict, "device");
1047 const char *data = qdict_get_str(qdict, "data");
e940f543 1048 Error *err = NULL;
1f590cf9 1049
e940f543 1050 qmp_ringbuf_write(chardev, data, false, 0, &err);
1f590cf9 1051
187c6147 1052 hmp_handle_error(mon, err);
6d3962bf 1053}
e42e818b 1054
3949e594 1055void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
49b6d722
LL
1056{
1057 uint32_t size = qdict_get_int(qdict, "size");
1058 const char *chardev = qdict_get_str(qdict, "device");
3ab651fc 1059 char *data;
e940f543 1060 Error *err = NULL;
543f3412 1061 int i;
49b6d722 1062
e940f543
MA
1063 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1064 if (err) {
187c6147 1065 hmp_handle_error(mon, err);
49b6d722
LL
1066 return;
1067 }
1068
543f3412
MA
1069 for (i = 0; data[i]; i++) {
1070 unsigned char ch = data[i];
1071
1072 if (ch == '\\') {
1073 monitor_printf(mon, "\\\\");
1074 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1075 monitor_printf(mon, "\\u%04X", ch);
1076 } else {
1077 monitor_printf(mon, "%c", ch);
1078 }
1079
1080 }
1081 monitor_printf(mon, "\n");
3ab651fc 1082 g_free(data);
49b6d722
LL
1083}
1084
e42e818b
LC
1085void hmp_cont(Monitor *mon, const QDict *qdict)
1086{
e940f543 1087 Error *err = NULL;
e42e818b 1088
e940f543 1089 qmp_cont(&err);
187c6147 1090 hmp_handle_error(mon, err);
e42e818b 1091}
ab49ab5c 1092
9b9df25a
GH
1093void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1094{
fb064112
DHB
1095 Error *err = NULL;
1096
1097 qmp_system_wakeup(&err);
187c6147 1098 hmp_handle_error(mon, err);
9b9df25a
GH
1099}
1100
3e5a50d6 1101void hmp_nmi(Monitor *mon, const QDict *qdict)
ab49ab5c 1102{
e940f543 1103 Error *err = NULL;
ab49ab5c 1104
e940f543 1105 qmp_inject_nmi(&err);
187c6147 1106 hmp_handle_error(mon, err);
ab49ab5c 1107}
4b37156c
LC
1108
1109void hmp_set_link(Monitor *mon, const QDict *qdict)
1110{
1111 const char *name = qdict_get_str(qdict, "name");
34acbc95 1112 bool up = qdict_get_bool(qdict, "up");
e940f543 1113 Error *err = NULL;
4b37156c 1114
e940f543 1115 qmp_set_link(name, up, &err);
187c6147 1116 hmp_handle_error(mon, err);
4b37156c 1117}
a4dea8a9 1118
d72f3264
LC
1119void hmp_balloon(Monitor *mon, const QDict *qdict)
1120{
1121 int64_t value = qdict_get_int(qdict, "value");
e940f543 1122 Error *err = NULL;
d72f3264 1123
e940f543 1124 qmp_balloon(value, &err);
187c6147 1125 hmp_handle_error(mon, err);
d72f3264 1126}
5e7caacb 1127
52b26205
JQ
1128void hmp_loadvm(Monitor *mon, const QDict *qdict)
1129{
1130 int saved_vm_running = runstate_is_running();
1131 const char *name = qdict_get_str(qdict, "name");
927d6638 1132 Error *err = NULL;
52b26205
JQ
1133
1134 vm_stop(RUN_STATE_RESTORE_VM);
1135
f1a9fcdd 1136 if (!load_snapshot(name, NULL, false, NULL, &err) && saved_vm_running) {
52b26205
JQ
1137 vm_start();
1138 }
187c6147 1139 hmp_handle_error(mon, err);
52b26205
JQ
1140}
1141
d9c7d137
JQ
1142void hmp_savevm(Monitor *mon, const QDict *qdict)
1143{
927d6638
JQ
1144 Error *err = NULL;
1145
f1a9fcdd
DB
1146 save_snapshot(qdict_get_try_str(qdict, "name"),
1147 true, NULL, false, NULL, &err);
187c6147 1148 hmp_handle_error(mon, err);
d9c7d137
JQ
1149}
1150
d905bb7b
JQ
1151void hmp_delvm(Monitor *mon, const QDict *qdict)
1152{
32cd6550 1153 Error *err = NULL;
d905bb7b
JQ
1154 const char *name = qdict_get_str(qdict, "name");
1155
bef7e9e2 1156 delete_snapshot(name, false, NULL, &err);
187c6147 1157 hmp_handle_error(mon, err);
d905bb7b
JQ
1158}
1159
544f6ea3
DDAG
1160void hmp_announce_self(Monitor *mon, const QDict *qdict)
1161{
08528271 1162 const char *interfaces_str = qdict_get_try_str(qdict, "interfaces");
c6644548 1163 const char *id = qdict_get_try_str(qdict, "id");
08528271
DDAG
1164 AnnounceParameters *params = QAPI_CLONE(AnnounceParameters,
1165 migrate_announce_params());
1166
1167 qapi_free_strList(params->interfaces);
1168 params->interfaces = strList_from_comma_list(interfaces_str);
1169 params->has_interfaces = params->interfaces != NULL;
c6644548
DDAG
1170 params->id = g_strdup(id);
1171 params->has_id = !!params->id;
08528271
DDAG
1172 qmp_announce_self(params, NULL);
1173 qapi_free_AnnounceParameters(params);
544f6ea3
DDAG
1174}
1175
6cdedb07
LC
1176void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1177{
1178 qmp_migrate_cancel(NULL);
1179}
4f0a993b 1180
94ae12cb
DDAG
1181void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1182{
1183 Error *err = NULL;
1184 const char *state = qdict_get_str(qdict, "state");
1185 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1186
1187 if (val >= 0) {
1188 qmp_migrate_continue(val, &err);
1189 }
1190
187c6147 1191 hmp_handle_error(mon, err);
94ae12cb
DDAG
1192}
1193
bf1ae1f4
DDAG
1194void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1195{
1196 Error *err = NULL;
1197 const char *uri = qdict_get_str(qdict, "uri");
1198
1199 qmp_migrate_incoming(uri, &err);
1200
187c6147 1201 hmp_handle_error(mon, err);
bf1ae1f4
DDAG
1202}
1203
3b563c4b
PX
1204void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
1205{
1206 Error *err = NULL;
1207 const char *uri = qdict_get_str(qdict, "uri");
1208
1209 qmp_migrate_recover(uri, &err);
1210
187c6147 1211 hmp_handle_error(mon, err);
3b563c4b
PX
1212}
1213
d37297dc
PX
1214void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
1215{
1216 Error *err = NULL;
1217
1218 qmp_migrate_pause(&err);
1219
187c6147 1220 hmp_handle_error(mon, err);
d37297dc
PX
1221}
1222
fbf796fd 1223
00458433
OW
1224void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1225{
1226 const char *cap = qdict_get_str(qdict, "capability");
1227 bool state = qdict_get_bool(qdict, "state");
1228 Error *err = NULL;
54aa3de7
EB
1229 MigrationCapabilityStatusList *caps = NULL;
1230 MigrationCapabilityStatus *value;
8e615e34 1231 int val;
00458433 1232
f7abe0ec 1233 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
8e615e34
MAL
1234 if (val < 0) {
1235 goto end;
00458433
OW
1236 }
1237
54aa3de7
EB
1238 value = g_malloc0(sizeof(*value));
1239 value->capability = val;
1240 value->state = state;
1241 QAPI_LIST_PREPEND(caps, value);
8e615e34 1242 qmp_migrate_set_capabilities(caps, &err);
54aa3de7 1243 qapi_free_MigrationCapabilityStatusList(caps);
00458433 1244
8e615e34 1245end:
187c6147 1246 hmp_handle_error(mon, err);
00458433
OW
1247}
1248
50e9a629
LL
1249void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1250{
1251 const char *param = qdict_get_str(qdict, "parameter");
69ef1f36 1252 const char *valuestr = qdict_get_str(qdict, "value");
f4a06d13 1253 Visitor *v = string_input_visitor_new(valuestr);
1bda8b3c 1254 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
f46bfdbf 1255 uint64_t valuebw = 0;
73af8dd8 1256 uint64_t cache_size;
50e9a629 1257 Error *err = NULL;
262517b7 1258 int val, ret;
69ef1f36 1259
f7abe0ec 1260 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
262517b7
MAL
1261 if (val < 0) {
1262 goto cleanup;
1263 }
1264
1265 switch (val) {
1266 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1267 p->has_compress_level = true;
ec17de0a 1268 visit_type_uint8(v, param, &p->compress_level, &err);
262517b7
MAL
1269 break;
1270 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1271 p->has_compress_threads = true;
ec17de0a 1272 visit_type_uint8(v, param, &p->compress_threads, &err);
262517b7 1273 break;
1d58872a
XG
1274 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD:
1275 p->has_compress_wait_thread = true;
1276 visit_type_bool(v, param, &p->compress_wait_thread, &err);
1277 break;
262517b7
MAL
1278 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1279 p->has_decompress_threads = true;
ec17de0a 1280 visit_type_uint8(v, param, &p->decompress_threads, &err);
262517b7 1281 break;
dc14a470
KZ
1282 case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD:
1283 p->has_throttle_trigger_threshold = true;
ec17de0a 1284 visit_type_uint8(v, param, &p->throttle_trigger_threshold, &err);
33ee3d96 1285 break;
262517b7
MAL
1286 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1287 p->has_cpu_throttle_initial = true;
ec17de0a 1288 visit_type_uint8(v, param, &p->cpu_throttle_initial, &err);
262517b7
MAL
1289 break;
1290 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1291 p->has_cpu_throttle_increment = true;
ec17de0a 1292 visit_type_uint8(v, param, &p->cpu_throttle_increment, &err);
262517b7 1293 break;
cbbf8182
KZ
1294 case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW:
1295 p->has_cpu_throttle_tailslow = true;
1296 visit_type_bool(v, param, &p->cpu_throttle_tailslow, &err);
1297 break;
4cbc9c7f
LQ
1298 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE:
1299 p->has_max_cpu_throttle = true;
ec17de0a 1300 visit_type_uint8(v, param, &p->max_cpu_throttle, &err);
4cbc9c7f 1301 break;
262517b7
MAL
1302 case MIGRATION_PARAMETER_TLS_CREDS:
1303 p->has_tls_creds = true;
1304 p->tls_creds = g_new0(StrOrNull, 1);
1305 p->tls_creds->type = QTYPE_QSTRING;
1306 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1307 break;
1308 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1309 p->has_tls_hostname = true;
1310 p->tls_hostname = g_new0(StrOrNull, 1);
1311 p->tls_hostname->type = QTYPE_QSTRING;
1312 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1313 break;
d2f1d29b
DB
1314 case MIGRATION_PARAMETER_TLS_AUTHZ:
1315 p->has_tls_authz = true;
1316 p->tls_authz = g_new0(StrOrNull, 1);
1317 p->tls_authz->type = QTYPE_QSTRING;
1318 visit_type_str(v, param, &p->tls_authz->u.s, &err);
1319 break;
262517b7
MAL
1320 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1321 p->has_max_bandwidth = true;
1322 /*
1323 * Can't use visit_type_size() here, because it
1324 * defaults to Bytes rather than Mebibytes.
1325 */
1326 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1327 if (ret < 0 || valuebw > INT64_MAX
1328 || (size_t)valuebw != valuebw) {
1329 error_setg(&err, "Invalid size %s", valuestr);
50e9a629
LL
1330 break;
1331 }
262517b7
MAL
1332 p->max_bandwidth = valuebw;
1333 break;
1334 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1335 p->has_downtime_limit = true;
ec17de0a 1336 visit_type_size(v, param, &p->downtime_limit, &err);
262517b7
MAL
1337 break;
1338 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1339 p->has_x_checkpoint_delay = true;
ec17de0a 1340 visit_type_uint32(v, param, &p->x_checkpoint_delay, &err);
262517b7
MAL
1341 break;
1342 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1343 p->has_block_incremental = true;
1344 visit_type_bool(v, param, &p->block_incremental, &err);
1345 break;
cbfd6c95
JQ
1346 case MIGRATION_PARAMETER_MULTIFD_CHANNELS:
1347 p->has_multifd_channels = true;
ec17de0a 1348 visit_type_uint8(v, param, &p->multifd_channels, &err);
4075fb1c 1349 break;
96eef042
JQ
1350 case MIGRATION_PARAMETER_MULTIFD_COMPRESSION:
1351 p->has_multifd_compression = true;
3c4b89c3
MA
1352 visit_type_MultiFDCompression(v, param, &p->multifd_compression,
1353 &err);
96eef042 1354 break;
9004db48
JQ
1355 case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL:
1356 p->has_multifd_zlib_level = true;
ec17de0a 1357 visit_type_uint8(v, param, &p->multifd_zlib_level, &err);
9004db48 1358 break;
6a9ad154
JQ
1359 case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL:
1360 p->has_multifd_zstd_level = true;
ec17de0a 1361 visit_type_uint8(v, param, &p->multifd_zstd_level, &err);
6a9ad154 1362 break;
73af8dd8
JQ
1363 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1364 p->has_xbzrle_cache_size = true;
62a35aaa 1365 if (!visit_type_size(v, param, &cache_size, &err)) {
d013283a
JQ
1366 break;
1367 }
1368 if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) {
73af8dd8
JQ
1369 error_setg(&err, "Invalid size %s", valuestr);
1370 break;
1371 }
1372 p->xbzrle_cache_size = cache_size;
1373 break;
7e555c6c
DDAG
1374 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH:
1375 p->has_max_postcopy_bandwidth = true;
1376 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err);
1377 break;
ee3d96ba
DDAG
1378 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL:
1379 p->has_announce_initial = true;
1380 visit_type_size(v, param, &p->announce_initial, &err);
1381 break;
1382 case MIGRATION_PARAMETER_ANNOUNCE_MAX:
1383 p->has_announce_max = true;
1384 visit_type_size(v, param, &p->announce_max, &err);
1385 break;
1386 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS:
1387 p->has_announce_rounds = true;
1388 visit_type_size(v, param, &p->announce_rounds, &err);
1389 break;
1390 case MIGRATION_PARAMETER_ANNOUNCE_STEP:
1391 p->has_announce_step = true;
1392 visit_type_size(v, param, &p->announce_step, &err);
1393 break;
31e4c354
HR
1394 case MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING:
1395 error_setg(&err, "The block-bitmap-mapping parameter can only be set "
1396 "through QMP");
1397 break;
262517b7
MAL
1398 default:
1399 assert(0);
50e9a629
LL
1400 }
1401
262517b7
MAL
1402 if (err) {
1403 goto cleanup;
50e9a629
LL
1404 }
1405
262517b7
MAL
1406 qmp_migrate_set_parameters(p, &err);
1407
69ef1f36 1408 cleanup:
1bda8b3c 1409 qapi_free_MigrateSetParameters(p);
f4a06d13 1410 visit_free(v);
187c6147 1411 hmp_handle_error(mon, err);
50e9a629
LL
1412}
1413
b8a185bc
MA
1414void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1415{
1416 Error *err = NULL;
1417 const char *protocol = qdict_get_str(qdict, "protocol");
1418 const char *hostname = qdict_get_str(qdict, "hostname");
1419 bool has_port = qdict_haskey(qdict, "port");
1420 int port = qdict_get_try_int(qdict, "port", -1);
1421 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1422 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1423 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1424
1425 qmp_client_migrate_info(protocol, hostname,
1426 has_port, port, has_tls_port, tls_port,
1427 !!cert_subject, cert_subject, &err);
187c6147 1428 hmp_handle_error(mon, err);
b8a185bc
MA
1429}
1430
4886a1bc
DDAG
1431void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1432{
1433 Error *err = NULL;
1434 qmp_migrate_start_postcopy(&err);
187c6147 1435 hmp_handle_error(mon, err);
4886a1bc
DDAG
1436}
1437
d89e666e
HZ
1438void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1439{
1440 Error *err = NULL;
1441
1442 qmp_x_colo_lost_heartbeat(&err);
187c6147 1443 hmp_handle_error(mon, err);
d89e666e
HZ
1444}
1445
fbf796fd
LC
1446void hmp_set_password(Monitor *mon, const QDict *qdict)
1447{
1448 const char *protocol = qdict_get_str(qdict, "protocol");
1449 const char *password = qdict_get_str(qdict, "password");
1450 const char *connected = qdict_get_try_str(qdict, "connected");
1451 Error *err = NULL;
1452
1453 qmp_set_password(protocol, password, !!connected, connected, &err);
187c6147 1454 hmp_handle_error(mon, err);
fbf796fd 1455}
9ad5372d
LC
1456
1457void hmp_expire_password(Monitor *mon, const QDict *qdict)
1458{
1459 const char *protocol = qdict_get_str(qdict, "protocol");
1460 const char *whenstr = qdict_get_str(qdict, "time");
1461 Error *err = NULL;
1462
1463 qmp_expire_password(protocol, whenstr, &err);
187c6147 1464 hmp_handle_error(mon, err);
9ad5372d 1465}
c245b6a3 1466
333a96ec 1467
05eb4a25 1468#ifdef CONFIG_VNC
c60bf339
SH
1469static void hmp_change_read_arg(void *opaque, const char *password,
1470 void *readline_opaque)
333a96ec
LC
1471{
1472 qmp_change_vnc_password(password, NULL);
c60bf339 1473 monitor_read_command(opaque, 1);
333a96ec 1474}
05eb4a25 1475#endif
333a96ec 1476
333a96ec
LC
1477void hmp_change(Monitor *mon, const QDict *qdict)
1478{
1479 const char *device = qdict_get_str(qdict, "device");
1480 const char *target = qdict_get_str(qdict, "target");
1481 const char *arg = qdict_get_try_str(qdict, "arg");
baead0ab
HR
1482 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1483 BlockdevChangeReadOnlyMode read_only_mode = 0;
333a96ec
LC
1484 Error *err = NULL;
1485
05eb4a25 1486#ifdef CONFIG_VNC
10686749 1487 if (strcmp(device, "vnc") == 0) {
baead0ab
HR
1488 if (read_only) {
1489 monitor_printf(mon,
1490 "Parameter 'read-only-mode' is invalid for VNC\n");
1491 return;
1492 }
10686749
HR
1493 if (strcmp(target, "passwd") == 0 ||
1494 strcmp(target, "password") == 0) {
cfb5387a 1495 if (arg) {
ea73f370 1496 MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
5f9dba16 1497 monitor_read_password(hmp_mon, hmp_change_read_arg, NULL);
10686749 1498 return;
cfb5387a
PB
1499 } else {
1500 qmp_change_vnc_password(arg, &err);
10686749 1501 }
cfb5387a
PB
1502 } else {
1503 monitor_printf(mon, "Expected 'password' after 'vnc'\n");
10686749 1504 }
05eb4a25
MAL
1505 } else
1506#endif
1507 {
baead0ab
HR
1508 if (read_only) {
1509 read_only_mode =
f7abe0ec 1510 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
06c60b6c 1511 read_only,
baead0ab
HR
1512 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1513 if (err) {
ac9c95b1 1514 goto end;
baead0ab
HR
1515 }
1516 }
1517
70e2cb3b
KW
1518 qmp_blockdev_change_medium(true, device, false, NULL, target,
1519 !!arg, arg, !!read_only, read_only_mode,
1520 &err);
333a96ec
LC
1521 }
1522
ac9c95b1 1523end:
187c6147 1524 hmp_handle_error(mon, err);
333a96ec 1525}
80047da5 1526
d22b854d 1527typedef struct HMPMigrationStatus {
e1c37d0e
LC
1528 QEMUTimer *timer;
1529 Monitor *mon;
1530 bool is_block_migration;
e49f35bd 1531} HMPMigrationStatus;
e1c37d0e
LC
1532
1533static void hmp_migrate_status_cb(void *opaque)
1534{
e49f35bd 1535 HMPMigrationStatus *status = opaque;
e1c37d0e
LC
1536 MigrationInfo *info;
1537
1538 info = qmp_query_migrate(NULL);
24b8c39b
HZ
1539 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1540 info->status == MIGRATION_STATUS_SETUP) {
e1c37d0e
LC
1541 if (info->has_disk) {
1542 int progress;
1543
1544 if (info->disk->remaining) {
1545 progress = info->disk->transferred * 100 / info->disk->total;
1546 } else {
1547 progress = 100;
1548 }
1549
1550 monitor_printf(status->mon, "Completed %d %%\r", progress);
1551 monitor_flush(status->mon);
1552 }
1553
bc72ad67 1554 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
e1c37d0e
LC
1555 } else {
1556 if (status->is_block_migration) {
1557 monitor_printf(status->mon, "\n");
1558 }
d59ce6f3
DB
1559 if (info->has_error_desc) {
1560 error_report("%s", info->error_desc);
1561 }
e1c37d0e 1562 monitor_resume(status->mon);
d34a10af 1563 timer_free(status->timer);
e1c37d0e
LC
1564 g_free(status);
1565 }
1566
1567 qapi_free_MigrationInfo(info);
1568}
1569
1570void hmp_migrate(Monitor *mon, const QDict *qdict)
1571{
34acbc95
EB
1572 bool detach = qdict_get_try_bool(qdict, "detach", false);
1573 bool blk = qdict_get_try_bool(qdict, "blk", false);
1574 bool inc = qdict_get_try_bool(qdict, "inc", false);
7a4da28b 1575 bool resume = qdict_get_try_bool(qdict, "resume", false);
e1c37d0e
LC
1576 const char *uri = qdict_get_str(qdict, "uri");
1577 Error *err = NULL;
1578
7a4da28b
PX
1579 qmp_migrate(uri, !!blk, blk, !!inc, inc,
1580 false, false, true, resume, &err);
e1c37d0e 1581 if (err) {
187c6147 1582 hmp_handle_error(mon, err);
e1c37d0e
LC
1583 return;
1584 }
1585
1586 if (!detach) {
e49f35bd 1587 HMPMigrationStatus *status;
e1c37d0e
LC
1588
1589 if (monitor_suspend(mon) < 0) {
1590 monitor_printf(mon, "terminal does not allow synchronous "
1591 "migration, continuing detached\n");
1592 return;
1593 }
1594
1595 status = g_malloc0(sizeof(*status));
1596 status->mon = mon;
1597 status->is_block_migration = blk || inc;
bc72ad67 1598 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
e1c37d0e 1599 status);
bc72ad67 1600 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
e1c37d0e
LC
1601 }
1602}
a15fef21 1603
928059a3
LC
1604void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1605{
1606 Error *err = NULL;
1607 QemuOpts *opts;
ad6f932f 1608 const char *type = qdict_get_try_str(qdict, "type");
928059a3 1609
ad6f932f
PB
1610 if (type && is_help_option(type)) {
1611 show_netdevs();
1612 return;
1613 }
928059a3 1614 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
84d18f06 1615 if (err) {
928059a3
LC
1616 goto out;
1617 }
1618
1619 netdev_add(opts, &err);
84d18f06 1620 if (err) {
928059a3
LC
1621 qemu_opts_del(opts);
1622 }
1623
1624out:
187c6147 1625 hmp_handle_error(mon, err);
928059a3 1626}
5f964155
LC
1627
1628void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1629{
1630 const char *id = qdict_get_str(qdict, "id");
1631 Error *err = NULL;
1632
1633 qmp_netdev_del(id, &err);
187c6147 1634 hmp_handle_error(mon, err);
5f964155 1635}
208c9d1b 1636
cff8b2c6
PB
1637void hmp_object_add(Monitor *mon, const QDict *qdict)
1638{
da0a932b 1639 const char *options = qdict_get_str(qdict, "object");
cff8b2c6 1640 Error *err = NULL;
cff8b2c6 1641
da0a932b 1642 user_creatable_add_from_str(options, &err);
0705ecc4 1643 hmp_handle_error(mon, err);
cff8b2c6
PB
1644}
1645
208c9d1b
CB
1646void hmp_getfd(Monitor *mon, const QDict *qdict)
1647{
1648 const char *fdname = qdict_get_str(qdict, "fdname");
e940f543 1649 Error *err = NULL;
208c9d1b 1650
e940f543 1651 qmp_getfd(fdname, &err);
187c6147 1652 hmp_handle_error(mon, err);
208c9d1b
CB
1653}
1654
1655void hmp_closefd(Monitor *mon, const QDict *qdict)
1656{
1657 const char *fdname = qdict_get_str(qdict, "fdname");
e940f543 1658 Error *err = NULL;
208c9d1b 1659
e940f543 1660 qmp_closefd(fdname, &err);
187c6147 1661 hmp_handle_error(mon, err);
208c9d1b 1662}
e4c8f004 1663
3e5a50d6 1664void hmp_sendkey(Monitor *mon, const QDict *qdict)
e4c8f004
AK
1665{
1666 const char *keys = qdict_get_str(qdict, "keys");
95b3a8c8
EB
1667 KeyValue *v = NULL;
1668 KeyValueList *head = NULL, **tail = &head;
e4c8f004
AK
1669 int has_hold_time = qdict_haskey(qdict, "hold-time");
1670 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1671 Error *err = NULL;
5c99fa37 1672 const char *separator;
9f328977 1673 int keyname_len;
e4c8f004
AK
1674
1675 while (1) {
5c99fa37
KF
1676 separator = qemu_strchrnul(keys, '-');
1677 keyname_len = separator - keys;
e4c8f004
AK
1678
1679 /* Be compatible with old interface, convert user inputted "<" */
64ffbe04
WB
1680 if (keys[0] == '<' && keyname_len == 1) {
1681 keys = "less";
e4c8f004
AK
1682 keyname_len = 4;
1683 }
e4c8f004 1684
95b3a8c8 1685 v = g_malloc0(sizeof(*v));
e4c8f004 1686
64ffbe04 1687 if (strstart(keys, "0x", NULL)) {
9f328977 1688 char *endp;
64ffbe04
WB
1689 int value = strtoul(keys, &endp, 0);
1690 assert(endp <= keys + keyname_len);
1691 if (endp != keys + keyname_len) {
9f328977
LC
1692 goto err_out;
1693 }
95b3a8c8
EB
1694 v->type = KEY_VALUE_KIND_NUMBER;
1695 v->u.number.data = value;
9f328977 1696 } else {
64ffbe04 1697 int idx = index_from_key(keys, keyname_len);
7fb1cf16 1698 if (idx == Q_KEY_CODE__MAX) {
9f328977
LC
1699 goto err_out;
1700 }
95b3a8c8
EB
1701 v->type = KEY_VALUE_KIND_QCODE;
1702 v->u.qcode.data = idx;
9f328977 1703 }
95b3a8c8
EB
1704 QAPI_LIST_APPEND(tail, v);
1705 v = NULL;
9f328977 1706
5c99fa37 1707 if (!*separator) {
e4c8f004
AK
1708 break;
1709 }
1710 keys = separator + 1;
1711 }
1712
9f328977 1713 qmp_send_key(head, has_hold_time, hold_time, &err);
187c6147 1714 hmp_handle_error(mon, err);
9f328977
LC
1715
1716out:
95b3a8c8 1717 qapi_free_KeyValue(v);
9f328977
LC
1718 qapi_free_KeyValueList(head);
1719 return;
1720
1721err_out:
64ffbe04 1722 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
9f328977 1723 goto out;
e4c8f004 1724}
ad39cf6d 1725
0d9b90ce
MAL
1726void coroutine_fn
1727hmp_screendump(Monitor *mon, const QDict *qdict)
ad39cf6d
LC
1728{
1729 const char *filename = qdict_get_str(qdict, "filename");
f771c544
TH
1730 const char *id = qdict_get_try_str(qdict, "device");
1731 int64_t head = qdict_get_try_int(qdict, "head", 0);
ad39cf6d
LC
1732 Error *err = NULL;
1733
f771c544 1734 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
187c6147 1735 hmp_handle_error(mon, err);
ad39cf6d 1736}
4057725f 1737
f1088908
GH
1738void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1739{
1740 const char *args = qdict_get_str(qdict, "args");
1741 Error *err = NULL;
1742 QemuOpts *opts;
1743
70b94331 1744 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
f1088908 1745 if (opts == NULL) {
312fd5f2 1746 error_setg(&err, "Parsing chardev args failed");
f1088908 1747 } else {
4ad6f6cb 1748 qemu_chr_new_from_opts(opts, NULL, &err);
0a73336d 1749 qemu_opts_del(opts);
f1088908 1750 }
187c6147 1751 hmp_handle_error(mon, err);
f1088908
GH
1752}
1753
75b60160
AN
1754void hmp_chardev_change(Monitor *mon, const QDict *qdict)
1755{
1756 const char *args = qdict_get_str(qdict, "args");
1757 const char *id;
1758 Error *err = NULL;
1759 ChardevBackend *backend = NULL;
1760 ChardevReturn *ret = NULL;
1761 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
1762 true);
1763 if (!opts) {
1764 error_setg(&err, "Parsing chardev args failed");
1765 goto end;
1766 }
1767
1768 id = qdict_get_str(qdict, "id");
1769 if (qemu_opts_id(opts)) {
1770 error_setg(&err, "Unexpected 'id' parameter");
1771 goto end;
1772 }
1773
1774 backend = qemu_chr_parse_opts(opts, &err);
1775 if (!backend) {
1776 goto end;
1777 }
1778
1779 ret = qmp_chardev_change(id, backend, &err);
1780
1781end:
1782 qapi_free_ChardevReturn(ret);
1783 qapi_free_ChardevBackend(backend);
1784 qemu_opts_del(opts);
187c6147 1785 hmp_handle_error(mon, err);
75b60160
AN
1786}
1787
f1088908
GH
1788void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1789{
1790 Error *local_err = NULL;
1791
1792 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
187c6147 1793 hmp_handle_error(mon, local_err);
f1088908 1794}
587da2c3 1795
bd1d5ad9
SF
1796void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
1797{
1798 Error *local_err = NULL;
1799
1800 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
187c6147 1801 hmp_handle_error(mon, local_err);
bd1d5ad9
SF
1802}
1803
ab2d0531
PB
1804void hmp_object_del(Monitor *mon, const QDict *qdict)
1805{
1806 const char *id = qdict_get_str(qdict, "id");
1807 Error *err = NULL;
1808
90998d58 1809 user_creatable_del(id, &err);
187c6147 1810 hmp_handle_error(mon, err);
ab2d0531 1811}
eb1539b2 1812
a631892f
ZG
1813void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
1814{
1815 Error *err = NULL;
1816 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
1817 MemoryDeviceInfoList *info;
d766b22b 1818 VirtioPMEMDeviceInfo *vpi;
2e70874b 1819 VirtioMEMDeviceInfo *vmi;
a631892f
ZG
1820 MemoryDeviceInfo *value;
1821 PCDIMMDeviceInfo *di;
1822
1823 for (info = info_list; info; info = info->next) {
1824 value = info->value;
1825
1826 if (value) {
1fd5d4fe 1827 switch (value->type) {
a631892f 1828 case MEMORY_DEVICE_INFO_KIND_DIMM:
6388e18d 1829 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
d766b22b
DH
1830 di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ?
1831 value->u.dimm.data : value->u.nvdimm.data;
a631892f 1832 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
977c736f 1833 MemoryDeviceInfoKind_str(value->type),
a631892f
ZG
1834 di->id ? di->id : "");
1835 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
1836 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
1837 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
1838 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
1839 monitor_printf(mon, " memdev: %s\n", di->memdev);
1840 monitor_printf(mon, " hotplugged: %s\n",
1841 di->hotplugged ? "true" : "false");
1842 monitor_printf(mon, " hotpluggable: %s\n",
1843 di->hotpluggable ? "true" : "false");
d766b22b
DH
1844 break;
1845 case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM:
1846 vpi = value->u.virtio_pmem.data;
1847 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1848 MemoryDeviceInfoKind_str(value->type),
1849 vpi->id ? vpi->id : "");
1850 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->memaddr);
1851 monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size);
1852 monitor_printf(mon, " memdev: %s\n", vpi->memdev);
1853 break;
2e70874b
DH
1854 case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM:
1855 vmi = value->u.virtio_mem.data;
1856 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1857 MemoryDeviceInfoKind_str(value->type),
1858 vmi->id ? vmi->id : "");
1859 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vmi->memaddr);
1860 monitor_printf(mon, " node: %" PRId64 "\n", vmi->node);
1861 monitor_printf(mon, " requested-size: %" PRIu64 "\n",
1862 vmi->requested_size);
1863 monitor_printf(mon, " size: %" PRIu64 "\n", vmi->size);
1864 monitor_printf(mon, " max-size: %" PRIu64 "\n", vmi->max_size);
1865 monitor_printf(mon, " block-size: %" PRIu64 "\n",
1866 vmi->block_size);
1867 monitor_printf(mon, " memdev: %s\n", vmi->memdev);
1868 break;
d766b22b
DH
1869 default:
1870 g_assert_not_reached();
a631892f
ZG
1871 }
1872 }
1873 }
1874
1875 qapi_free_MemoryDeviceInfoList(info_list);
187c6147 1876 hmp_handle_error(mon, err);
a631892f 1877}
89d7fa9e 1878
62313160
TW
1879void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
1880{
1881 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
1882 IOThreadInfoList *info;
5fc00480 1883 IOThreadInfo *value;
62313160
TW
1884
1885 for (info = info_list; info; info = info->next) {
5fc00480
PH
1886 value = info->value;
1887 monitor_printf(mon, "%s:\n", value->id);
1888 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
1889 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
1890 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
1891 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
62313160
TW
1892 }
1893
1894 qapi_free_IOThreadInfoList(info_list);
1895}
1896
fafa4d50
SF
1897void hmp_rocker(Monitor *mon, const QDict *qdict)
1898{
1899 const char *name = qdict_get_str(qdict, "name");
1900 RockerSwitch *rocker;
533fdaed 1901 Error *err = NULL;
fafa4d50 1902
533fdaed
MA
1903 rocker = qmp_query_rocker(name, &err);
1904 if (err != NULL) {
187c6147 1905 hmp_handle_error(mon, err);
fafa4d50
SF
1906 return;
1907 }
1908
1909 monitor_printf(mon, "name: %s\n", rocker->name);
1910 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
1911 monitor_printf(mon, "ports: %d\n", rocker->ports);
1912
1913 qapi_free_RockerSwitch(rocker);
1914}
1915
1916void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
1917{
1918 RockerPortList *list, *port;
1919 const char *name = qdict_get_str(qdict, "name");
533fdaed 1920 Error *err = NULL;
fafa4d50 1921
533fdaed
MA
1922 list = qmp_query_rocker_ports(name, &err);
1923 if (err != NULL) {
187c6147 1924 hmp_handle_error(mon, err);
fafa4d50
SF
1925 return;
1926 }
1927
1928 monitor_printf(mon, " ena/ speed/ auto\n");
1929 monitor_printf(mon, " port link duplex neg?\n");
1930
1931 for (port = list; port; port = port->next) {
1932 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
1933 port->value->name,
1934 port->value->enabled ? port->value->link_up ?
1935 "up" : "down" : "!ena",
1936 port->value->speed == 10000 ? "10G" : "??",
1937 port->value->duplex ? "FD" : "HD",
1938 port->value->autoneg ? "Yes" : "No");
1939 }
1940
1941 qapi_free_RockerPortList(list);
1942}
1943
1944void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
1945{
1946 RockerOfDpaFlowList *list, *info;
1947 const char *name = qdict_get_str(qdict, "name");
1948 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
533fdaed 1949 Error *err = NULL;
fafa4d50 1950
533fdaed
MA
1951 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
1952 if (err != NULL) {
187c6147 1953 hmp_handle_error(mon, err);
fafa4d50
SF
1954 return;
1955 }
1956
1957 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
1958
1959 for (info = list; info; info = info->next) {
1960 RockerOfDpaFlow *flow = info->value;
1961 RockerOfDpaFlowKey *key = flow->key;
1962 RockerOfDpaFlowMask *mask = flow->mask;
1963 RockerOfDpaFlowAction *action = flow->action;
1964
1965 if (flow->hits) {
1966 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
1967 key->priority, key->tbl_id, flow->hits);
1968 } else {
1969 monitor_printf(mon, "%-4d %-3d ",
1970 key->priority, key->tbl_id);
1971 }
1972
1973 if (key->has_in_pport) {
1974 monitor_printf(mon, " pport %d", key->in_pport);
1975 if (mask->has_in_pport) {
1976 monitor_printf(mon, "(0x%x)", mask->in_pport);
1977 }
1978 }
1979
1980 if (key->has_vlan_id) {
1981 monitor_printf(mon, " vlan %d",
1982 key->vlan_id & VLAN_VID_MASK);
1983 if (mask->has_vlan_id) {
1984 monitor_printf(mon, "(0x%x)", mask->vlan_id);
1985 }
1986 }
1987
1988 if (key->has_tunnel_id) {
1989 monitor_printf(mon, " tunnel %d", key->tunnel_id);
1990 if (mask->has_tunnel_id) {
1991 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
1992 }
1993 }
1994
1995 if (key->has_eth_type) {
1996 switch (key->eth_type) {
1997 case 0x0806:
1998 monitor_printf(mon, " ARP");
1999 break;
2000 case 0x0800:
2001 monitor_printf(mon, " IP");
2002 break;
2003 case 0x86dd:
2004 monitor_printf(mon, " IPv6");
2005 break;
2006 case 0x8809:
2007 monitor_printf(mon, " LACP");
2008 break;
2009 case 0x88cc:
2010 monitor_printf(mon, " LLDP");
2011 break;
2012 default:
2013 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2014 break;
2015 }
2016 }
2017
2018 if (key->has_eth_src) {
2019 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2020 (mask->has_eth_src) &&
2021 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2022 monitor_printf(mon, " src <any mcast/bcast>");
2023 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2024 (mask->has_eth_src) &&
2025 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2026 monitor_printf(mon, " src <any ucast>");
2027 } else {
2028 monitor_printf(mon, " src %s", key->eth_src);
2029 if (mask->has_eth_src) {
2030 monitor_printf(mon, "(%s)", mask->eth_src);
2031 }
2032 }
2033 }
2034
2035 if (key->has_eth_dst) {
2036 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2037 (mask->has_eth_dst) &&
2038 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2039 monitor_printf(mon, " dst <any mcast/bcast>");
2040 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2041 (mask->has_eth_dst) &&
2042 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2043 monitor_printf(mon, " dst <any ucast>");
2044 } else {
2045 monitor_printf(mon, " dst %s", key->eth_dst);
2046 if (mask->has_eth_dst) {
2047 monitor_printf(mon, "(%s)", mask->eth_dst);
2048 }
2049 }
2050 }
2051
2052 if (key->has_ip_proto) {
2053 monitor_printf(mon, " proto %d", key->ip_proto);
2054 if (mask->has_ip_proto) {
2055 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2056 }
2057 }
2058
2059 if (key->has_ip_tos) {
2060 monitor_printf(mon, " TOS %d", key->ip_tos);
2061 if (mask->has_ip_tos) {
2062 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2063 }
2064 }
2065
2066 if (key->has_ip_dst) {
2067 monitor_printf(mon, " dst %s", key->ip_dst);
2068 }
2069
2070 if (action->has_goto_tbl || action->has_group_id ||
2071 action->has_new_vlan_id) {
2072 monitor_printf(mon, " -->");
2073 }
2074
2075 if (action->has_new_vlan_id) {
2076 monitor_printf(mon, " apply new vlan %d",
2077 ntohs(action->new_vlan_id));
2078 }
2079
2080 if (action->has_group_id) {
2081 monitor_printf(mon, " write group 0x%08x", action->group_id);
2082 }
2083
2084 if (action->has_goto_tbl) {
2085 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2086 }
2087
2088 monitor_printf(mon, "\n");
2089 }
2090
2091 qapi_free_RockerOfDpaFlowList(list);
2092}
2093
2094void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2095{
2096 RockerOfDpaGroupList *list, *g;
2097 const char *name = qdict_get_str(qdict, "name");
2098 uint8_t type = qdict_get_try_int(qdict, "type", 9);
533fdaed 2099 Error *err = NULL;
fafa4d50 2100
533fdaed
MA
2101 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2102 if (err != NULL) {
187c6147 2103 hmp_handle_error(mon, err);
fafa4d50
SF
2104 return;
2105 }
2106
2107 monitor_printf(mon, "id (decode) --> buckets\n");
2108
2109 for (g = list; g; g = g->next) {
2110 RockerOfDpaGroup *group = g->value;
916c9250 2111 bool set = false;
fafa4d50
SF
2112
2113 monitor_printf(mon, "0x%08x", group->id);
2114
2115 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2116 group->type == 1 ? "L2 rewrite" :
2117 group->type == 2 ? "L3 unicast" :
2118 group->type == 3 ? "L2 multicast" :
2119 group->type == 4 ? "L2 flood" :
2120 group->type == 5 ? "L3 interface" :
2121 group->type == 6 ? "L3 multicast" :
2122 group->type == 7 ? "L3 ECMP" :
2123 group->type == 8 ? "L2 overlay" :
2124 "unknown");
2125
2126 if (group->has_vlan_id) {
2127 monitor_printf(mon, " vlan %d", group->vlan_id);
2128 }
2129
2130 if (group->has_pport) {
2131 monitor_printf(mon, " pport %d", group->pport);
2132 }
2133
2134 if (group->has_index) {
2135 monitor_printf(mon, " index %d", group->index);
2136 }
2137
2138 monitor_printf(mon, ") -->");
2139
2140 if (group->has_set_vlan_id && group->set_vlan_id) {
2141 set = true;
2142 monitor_printf(mon, " set vlan %d",
2143 group->set_vlan_id & VLAN_VID_MASK);
2144 }
2145
2146 if (group->has_set_eth_src) {
2147 if (!set) {
2148 set = true;
2149 monitor_printf(mon, " set");
2150 }
2151 monitor_printf(mon, " src %s", group->set_eth_src);
2152 }
2153
2154 if (group->has_set_eth_dst) {
2155 if (!set) {
fafa4d50
SF
2156 monitor_printf(mon, " set");
2157 }
2158 monitor_printf(mon, " dst %s", group->set_eth_dst);
2159 }
2160
fafa4d50
SF
2161 if (group->has_ttl_check && group->ttl_check) {
2162 monitor_printf(mon, " check TTL");
2163 }
2164
2165 if (group->has_group_id && group->group_id) {
2166 monitor_printf(mon, " group id 0x%08x", group->group_id);
2167 }
2168
2169 if (group->has_pop_vlan && group->pop_vlan) {
2170 monitor_printf(mon, " pop vlan");
2171 }
2172
2173 if (group->has_out_pport) {
2174 monitor_printf(mon, " out pport %d", group->out_pport);
2175 }
2176
2177 if (group->has_group_ids) {
2178 struct uint32List *id;
2179
2180 monitor_printf(mon, " groups [");
2181 for (id = group->group_ids; id; id = id->next) {
2182 monitor_printf(mon, "0x%08x", id->value);
2183 if (id->next) {
2184 monitor_printf(mon, ",");
2185 }
2186 }
2187 monitor_printf(mon, "]");
2188 }
2189
2190 monitor_printf(mon, "\n");
2191 }
2192
2193 qapi_free_RockerOfDpaGroupList(list);
2194}
4a6b52d6 2195
be9b23c4
PX
2196void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
2197{
2198 ram_block_dump(mon);
2199}
2200
39164c13
IM
2201void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
2202{
72d9196f
BW
2203 Error *err = NULL;
2204 GuidInfo *info = qmp_query_vm_generation_id(&err);
39164c13
IM
2205 if (info) {
2206 monitor_printf(mon, "%s\n", info->guid);
2207 }
187c6147 2208 hmp_handle_error(mon, err);
39164c13
IM
2209 qapi_free_GuidInfo(info);
2210}
d0f63c1e
VG
2211
2212void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
2213{
2214 Error *err = NULL;
2215 MemoryInfo *info = qmp_query_memory_size_summary(&err);
2216 if (info) {
2217 monitor_printf(mon, "base memory: %" PRIu64 "\n",
2218 info->base_memory);
2219
2220 if (info->has_plugged_memory) {
2221 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
2222 info->plugged_memory);
2223 }
2224
2225 qapi_free_MemoryInfo(info);
2226 }
187c6147 2227 hmp_handle_error(mon, err);
d0f63c1e 2228}