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