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