]> git.ipfire.org Git - thirdparty/qemu.git/blame - monitor/hmp-cmds.c
monitor: Add allow_hmp parameter to monitor_init()
[thirdparty/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"
5bce308a 27#include "monitor/monitor-internal.h"
e688df6b 28#include "qapi/error.h"
08528271 29#include "qapi/clone-visitor.h"
cff8b2c6 30#include "qapi/opts-visitor.h"
eb815e24 31#include "qapi/qapi-builtin-visit.h"
112ed241
MA
32#include "qapi/qapi-commands-block.h"
33#include "qapi/qapi-commands-char.h"
fa4dcf57 34#include "qapi/qapi-commands-control.h"
112ed241
MA
35#include "qapi/qapi-commands-migration.h"
36#include "qapi/qapi-commands-misc.h"
37#include "qapi/qapi-commands-net.h"
38#include "qapi/qapi-commands-rocker.h"
39#include "qapi/qapi-commands-run-state.h"
40#include "qapi/qapi-commands-tpm.h"
41#include "qapi/qapi-commands-ui.h"
08528271 42#include "qapi/qapi-visit-net.h"
96eef042 43#include "qapi/qapi-visit-migration.h"
452fcdbc 44#include "qapi/qmp/qdict.h"
cc7a8ea7 45#include "qapi/qmp/qerror.h"
f4a06d13 46#include "qapi/string-input-visitor.h"
eb1539b2 47#include "qapi/string-output-visitor.h"
90998d58 48#include "qom/object_interfaces.h"
28ecbaee 49#include "ui/console.h"
bd269ebc 50#include "block/nbd.h"
bd093a36 51#include "block/qapi.h"
587da2c3 52#include "qemu-io.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
7aa939af
JQ
237 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
238 info->total_time);
2c52ddf1
JQ
239 if (info->has_expected_downtime) {
240 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
241 info->expected_downtime);
242 }
9c5a9fcf
JQ
243 if (info->has_downtime) {
244 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
245 info->downtime);
246 }
ed4fbd10
MH
247 if (info->has_setup_time) {
248 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
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);
305 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
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);
f36d55af
OW
309 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
310 info->xbzrle_cache->overflow);
311 }
312
76e03000
XG
313 if (info->has_compression) {
314 monitor_printf(mon, "compression pages: %" PRIu64 " pages\n",
315 info->compression->pages);
316 monitor_printf(mon, "compression busy: %" PRIu64 "\n",
317 info->compression->busy);
318 monitor_printf(mon, "compression busy rate: %0.2f\n",
319 info->compression->busy_rate);
320 monitor_printf(mon, "compressed size: %" PRIu64 "\n",
321 info->compression->compressed_size);
322 monitor_printf(mon, "compression rate: %0.2f\n",
323 info->compression->compression_rate);
324 }
325
d85a31d1 326 if (info->has_cpu_throttle_percentage) {
4782893e 327 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
d85a31d1 328 info->cpu_throttle_percentage);
4782893e
JH
329 }
330
65ace060
AP
331 if (info->has_postcopy_blocktime) {
332 monitor_printf(mon, "postcopy blocktime: %u\n",
333 info->postcopy_blocktime);
334 }
335
336 if (info->has_postcopy_vcpu_blocktime) {
337 Visitor *v;
338 char *str;
339 v = string_output_visitor_new(false, &str);
340 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NULL);
341 visit_complete(v, &str);
342 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
343 g_free(str);
344 visit_free(v);
345 }
9aca82ba
JQ
346 if (info->has_socket_address) {
347 SocketAddressList *addr;
348
349 monitor_printf(mon, "socket address: [\n");
350
351 for (addr = info->socket_address; addr; addr = addr->next) {
352 char *s = SocketAddress_to_str(addr->value);
353 monitor_printf(mon, "\t%s\n", s);
354 g_free(s);
355 }
356 monitor_printf(mon, "]\n");
357 }
791e7c82 358 qapi_free_MigrationInfo(info);
bbf6da32
OW
359}
360
84f2d0ea 361void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
bbf6da32
OW
362{
363 MigrationCapabilityStatusList *caps, *cap;
364
365 caps = qmp_query_migrate_capabilities(NULL);
366
367 if (caps) {
bbf6da32 368 for (cap = caps; cap; cap = cap->next) {
d80a0169 369 monitor_printf(mon, "%s: %s\n",
977c736f 370 MigrationCapability_str(cap->value->capability),
bbf6da32
OW
371 cap->value->state ? "on" : "off");
372 }
bbf6da32
OW
373 }
374
375 qapi_free_MigrationCapabilityStatusList(caps);
791e7c82
LC
376}
377
50e9a629
LL
378void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
379{
380 MigrationParameters *params;
381
382 params = qmp_query_migrate_parameters(NULL);
383
384 if (params) {
ee3d96ba
DDAG
385 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
386 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL),
387 params->announce_initial);
388 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
389 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX),
390 params->announce_max);
391 monitor_printf(mon, "%s: %" PRIu64 "\n",
392 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS),
393 params->announce_rounds);
394 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
395 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP),
396 params->announce_step);
de63ab61 397 assert(params->has_compress_level);
741d4086 398 monitor_printf(mon, "%s: %u\n",
977c736f 399 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
50e9a629 400 params->compress_level);
de63ab61 401 assert(params->has_compress_threads);
741d4086 402 monitor_printf(mon, "%s: %u\n",
977c736f 403 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
50e9a629 404 params->compress_threads);
1d58872a
XG
405 assert(params->has_compress_wait_thread);
406 monitor_printf(mon, "%s: %s\n",
407 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD),
408 params->compress_wait_thread ? "on" : "off");
de63ab61 409 assert(params->has_decompress_threads);
741d4086 410 monitor_printf(mon, "%s: %u\n",
977c736f 411 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
50e9a629 412 params->decompress_threads);
de63ab61 413 assert(params->has_cpu_throttle_initial);
741d4086 414 monitor_printf(mon, "%s: %u\n",
977c736f 415 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
d85a31d1 416 params->cpu_throttle_initial);
de63ab61 417 assert(params->has_cpu_throttle_increment);
741d4086 418 monitor_printf(mon, "%s: %u\n",
977c736f 419 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
d85a31d1 420 params->cpu_throttle_increment);
4cbc9c7f
LQ
421 assert(params->has_max_cpu_throttle);
422 monitor_printf(mon, "%s: %u\n",
423 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE),
424 params->max_cpu_throttle);
8cc99dcd 425 assert(params->has_tls_creds);
2c02468c 426 monitor_printf(mon, "%s: '%s'\n",
977c736f 427 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
8cc99dcd
MA
428 params->tls_creds);
429 assert(params->has_tls_hostname);
2c02468c 430 monitor_printf(mon, "%s: '%s'\n",
977c736f 431 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
8cc99dcd 432 params->tls_hostname);
2ff30257 433 assert(params->has_max_bandwidth);
741d4086 434 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
977c736f 435 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
2ff30257
AA
436 params->max_bandwidth);
437 assert(params->has_downtime_limit);
741d4086 438 monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n",
977c736f 439 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
2ff30257 440 params->downtime_limit);
fe39a4d4 441 assert(params->has_x_checkpoint_delay);
741d4086 442 monitor_printf(mon, "%s: %u\n",
977c736f 443 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
68b53591 444 params->x_checkpoint_delay);
2833c59b
JQ
445 assert(params->has_block_incremental);
446 monitor_printf(mon, "%s: %s\n",
977c736f
MA
447 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
448 params->block_incremental ? "on" : "off");
741d4086 449 monitor_printf(mon, "%s: %u\n",
cbfd6c95
JQ
450 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS),
451 params->multifd_channels);
96eef042
JQ
452 monitor_printf(mon, "%s: %s\n",
453 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION),
454 MultiFDCompression_str(params->multifd_compression));
741d4086 455 monitor_printf(mon, "%s: %" PRIu64 "\n",
73af8dd8
JQ
456 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
457 params->xbzrle_cache_size);
7e555c6c
DDAG
458 monitor_printf(mon, "%s: %" PRIu64 "\n",
459 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
460 params->max_postcopy_bandwidth);
d2f1d29b
DB
461 monitor_printf(mon, " %s: '%s'\n",
462 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
463 params->has_tls_authz ? params->tls_authz : "");
50e9a629
LL
464 }
465
466 qapi_free_MigrationParameters(params);
467}
468
84f2d0ea 469void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
9e1ba4cc
OW
470{
471 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
472 qmp_query_migrate_cache_size(NULL) >> 10);
473}
474
289b276c
KW
475static void print_block_info(Monitor *mon, BlockInfo *info,
476 BlockDeviceInfo *inserted, bool verbose)
b2023818 477{
bd093a36 478 ImageInfo *image_info;
b2023818 479
8d6adccd
KW
480 assert(!info || !info->has_inserted || info->inserted == inserted);
481
ec18b0a9 482 if (info && *info->device) {
8d6adccd
KW
483 monitor_printf(mon, "%s", info->device);
484 if (inserted && inserted->has_node_name) {
485 monitor_printf(mon, " (%s)", inserted->node_name);
486 }
487 } else {
ec18b0a9 488 assert(info || inserted);
8d6adccd 489 monitor_printf(mon, "%s",
ec18b0a9
KW
490 inserted && inserted->has_node_name ? inserted->node_name
491 : info && info->has_qdev ? info->qdev
8d6adccd
KW
492 : "<anonymous>");
493 }
494
289b276c
KW
495 if (inserted) {
496 monitor_printf(mon, ": %s (%s%s%s)\n",
497 inserted->file,
498 inserted->drv,
499 inserted->ro ? ", read-only" : "",
500 inserted->encrypted ? ", encrypted" : "");
501 } else {
502 monitor_printf(mon, ": [not inserted]\n");
503 }
b2023818 504
8d6adccd 505 if (info) {
46eade7b
KW
506 if (info->has_qdev) {
507 monitor_printf(mon, " Attached to: %s\n", info->qdev);
508 }
8d6adccd
KW
509 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
510 monitor_printf(mon, " I/O status: %s\n",
977c736f 511 BlockDeviceIoStatus_str(info->io_status));
8d6adccd 512 }
b2023818 513
8d6adccd
KW
514 if (info->removable) {
515 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
516 info->locked ? "" : "not ",
517 info->tray_open ? "open" : "closed");
518 }
289b276c 519 }
fbe2e26c 520
b2023818 521
289b276c
KW
522 if (!inserted) {
523 return;
524 }
b2023818 525
289b276c
KW
526 monitor_printf(mon, " Cache mode: %s%s%s\n",
527 inserted->cache->writeback ? "writeback" : "writethrough",
528 inserted->cache->direct ? ", direct" : "",
529 inserted->cache->no_flush ? ", ignore flushes" : "");
530
531 if (inserted->has_backing_file) {
532 monitor_printf(mon,
533 " Backing file: %s "
534 "(chain depth: %" PRId64 ")\n",
535 inserted->backing_file,
536 inserted->backing_file_depth);
537 }
727f005e 538
289b276c
KW
539 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
540 monitor_printf(mon, " Detect zeroes: %s\n",
977c736f 541 BlockdevDetectZeroesOptions_str(inserted->detect_zeroes));
289b276c 542 }
fbe2e26c 543
289b276c
KW
544 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
545 inserted->iops || inserted->iops_rd || inserted->iops_wr)
546 {
547 monitor_printf(mon, " I/O throttling: bps=%" PRId64
548 " bps_rd=%" PRId64 " bps_wr=%" PRId64
549 " bps_max=%" PRId64
550 " bps_rd_max=%" PRId64
551 " bps_wr_max=%" PRId64
552 " iops=%" PRId64 " iops_rd=%" PRId64
553 " iops_wr=%" PRId64
554 " iops_max=%" PRId64
555 " iops_rd_max=%" PRId64
556 " iops_wr_max=%" PRId64
b8fe1694
AG
557 " iops_size=%" PRId64
558 " group=%s\n",
289b276c
KW
559 inserted->bps,
560 inserted->bps_rd,
561 inserted->bps_wr,
562 inserted->bps_max,
563 inserted->bps_rd_max,
564 inserted->bps_wr_max,
565 inserted->iops,
566 inserted->iops_rd,
567 inserted->iops_wr,
568 inserted->iops_max,
569 inserted->iops_rd_max,
570 inserted->iops_wr_max,
b8fe1694
AG
571 inserted->iops_size,
572 inserted->group);
289b276c 573 }
fbe2e26c 574
9419874f 575 if (verbose) {
289b276c
KW
576 monitor_printf(mon, "\nImages:\n");
577 image_info = inserted->image;
578 while (1) {
e1ce7d74 579 bdrv_image_info_dump(image_info);
289b276c
KW
580 if (image_info->has_backing_image) {
581 image_info = image_info->backing_image;
582 } else {
583 break;
584 }
585 }
586 }
587}
9e193c5a 588
289b276c
KW
589void hmp_info_block(Monitor *mon, const QDict *qdict)
590{
591 BlockInfoList *block_list, *info;
e6bb31ec 592 BlockDeviceInfoList *blockdev_list, *blockdev;
289b276c 593 const char *device = qdict_get_try_str(qdict, "device");
34acbc95
EB
594 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
595 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
e6bb31ec 596 bool printed = false;
9e193c5a 597
e6bb31ec
KW
598 /* Print BlockBackend information */
599 if (!nodes) {
f19e44bc 600 block_list = qmp_query_block(NULL);
e6bb31ec
KW
601 } else {
602 block_list = NULL;
603 }
fbe2e26c 604
289b276c
KW
605 for (info = block_list; info; info = info->next) {
606 if (device && strcmp(device, info->value->device)) {
607 continue;
465bee1d
PL
608 }
609
289b276c
KW
610 if (info != block_list) {
611 monitor_printf(mon, "\n");
fbe2e26c 612 }
bd093a36 613
289b276c
KW
614 print_block_info(mon, info->value, info->value->has_inserted
615 ? info->value->inserted : NULL,
616 verbose);
e6bb31ec 617 printed = true;
b2023818
LC
618 }
619
620 qapi_free_BlockInfoList(block_list);
e6bb31ec
KW
621
622 if ((!device && !nodes) || printed) {
623 return;
624 }
625
626 /* Print node information */
facda544 627 blockdev_list = qmp_query_named_block_nodes(false, false, NULL);
e6bb31ec
KW
628 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
629 assert(blockdev->value->has_node_name);
630 if (device && strcmp(device, blockdev->value->node_name)) {
631 continue;
632 }
633
634 if (blockdev != blockdev_list) {
635 monitor_printf(mon, "\n");
636 }
637
638 print_block_info(mon, NULL, blockdev->value, verbose);
639 }
640 qapi_free_BlockDeviceInfoList(blockdev_list);
b2023818
LC
641}
642
84f2d0ea 643void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
f11f57e4
LC
644{
645 BlockStatsList *stats_list, *stats;
646
f71eaa74 647 stats_list = qmp_query_blockstats(false, false, NULL);
f11f57e4
LC
648
649 for (stats = stats_list; stats; stats = stats->next) {
650 if (!stats->value->has_device) {
651 continue;
652 }
653
654 monitor_printf(mon, "%s:", stats->value->device);
655 monitor_printf(mon, " rd_bytes=%" PRId64
656 " wr_bytes=%" PRId64
657 " rd_operations=%" PRId64
658 " wr_operations=%" PRId64
659 " flush_operations=%" PRId64
660 " wr_total_time_ns=%" PRId64
661 " rd_total_time_ns=%" PRId64
662 " flush_total_time_ns=%" PRId64
f4564d53
PL
663 " rd_merged=%" PRId64
664 " wr_merged=%" PRId64
cb38fffb 665 " idle_time_ns=%" PRId64
f11f57e4
LC
666 "\n",
667 stats->value->stats->rd_bytes,
668 stats->value->stats->wr_bytes,
669 stats->value->stats->rd_operations,
670 stats->value->stats->wr_operations,
671 stats->value->stats->flush_operations,
672 stats->value->stats->wr_total_time_ns,
673 stats->value->stats->rd_total_time_ns,
f4564d53
PL
674 stats->value->stats->flush_total_time_ns,
675 stats->value->stats->rd_merged,
cb38fffb
AG
676 stats->value->stats->wr_merged,
677 stats->value->stats->idle_time_ns);
f11f57e4
LC
678 }
679
680 qapi_free_BlockStatsList(stats_list);
681}
682
05eb4a25 683#ifdef CONFIG_VNC
0a9667ec
DDAG
684/* Helper for hmp_info_vnc_clients, _servers */
685static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
686 const char *name)
687{
688 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
689 name,
690 info->host,
691 info->service,
977c736f 692 NetworkAddressFamily_str(info->family),
0a9667ec
DDAG
693 info->websocket ? " (Websocket)" : "");
694}
695
696/* Helper displaying and auth and crypt info */
697static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
698 VncPrimaryAuth auth,
699 VncVencryptSubAuth *vencrypt)
700{
701 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
977c736f
MA
702 VncPrimaryAuth_str(auth),
703 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
0a9667ec
DDAG
704}
705
706static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
707{
708 while (client) {
709 VncClientInfo *cinfo = client->value;
710
711 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
712 monitor_printf(mon, " x509_dname: %s\n",
713 cinfo->has_x509_dname ?
714 cinfo->x509_dname : "none");
715 monitor_printf(mon, " sasl_username: %s\n",
716 cinfo->has_sasl_username ?
717 cinfo->sasl_username : "none");
718
719 client = client->next;
720 }
721}
722
723static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
724{
725 while (server) {
726 VncServerInfo2 *sinfo = server->value;
727 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
728 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
729 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
730 server = server->next;
731 }
732}
733
84f2d0ea 734void hmp_info_vnc(Monitor *mon, const QDict *qdict)
2b54aa87 735{
0a9667ec 736 VncInfo2List *info2l;
2b54aa87 737 Error *err = NULL;
2b54aa87 738
0a9667ec 739 info2l = qmp_query_vnc_servers(&err);
2b54aa87 740 if (err) {
187c6147 741 hmp_handle_error(mon, err);
2b54aa87
LC
742 return;
743 }
0a9667ec
DDAG
744 if (!info2l) {
745 monitor_printf(mon, "None\n");
746 return;
2b54aa87
LC
747 }
748
0a9667ec
DDAG
749 while (info2l) {
750 VncInfo2 *info = info2l->value;
751 monitor_printf(mon, "%s:\n", info->id);
752 hmp_info_vnc_servers(mon, info->server);
753 hmp_info_vnc_clients(mon, info->clients);
754 if (!info->server) {
755 /* The server entry displays its auth, we only
756 * need to display in the case of 'reverse' connections
757 * where there's no server.
758 */
759 hmp_info_vnc_authcrypt(mon, " ", info->auth,
760 info->has_vencrypt ? &info->vencrypt : NULL);
761 }
762 if (info->has_display) {
763 monitor_printf(mon, " Display: %s\n", info->display);
2b54aa87 764 }
0a9667ec 765 info2l = info2l->next;
2b54aa87
LC
766 }
767
0a9667ec
DDAG
768 qapi_free_VncInfo2List(info2l);
769
2b54aa87 770}
05eb4a25 771#endif
2b54aa87 772
206addd5 773#ifdef CONFIG_SPICE
84f2d0ea 774void hmp_info_spice(Monitor *mon, const QDict *qdict)
d1f29646
LC
775{
776 SpiceChannelList *chan;
777 SpiceInfo *info;
22fa7da0
CR
778 const char *channel_name;
779 const char * const channel_names[] = {
780 [SPICE_CHANNEL_MAIN] = "main",
781 [SPICE_CHANNEL_DISPLAY] = "display",
782 [SPICE_CHANNEL_INPUTS] = "inputs",
783 [SPICE_CHANNEL_CURSOR] = "cursor",
784 [SPICE_CHANNEL_PLAYBACK] = "playback",
785 [SPICE_CHANNEL_RECORD] = "record",
786 [SPICE_CHANNEL_TUNNEL] = "tunnel",
787 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
788 [SPICE_CHANNEL_USBREDIR] = "usbredir",
789 [SPICE_CHANNEL_PORT] = "port",
7c6044a9
GH
790#if 0
791 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
792 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
793 * as quick fix for build failures with older versions. */
22fa7da0 794 [SPICE_CHANNEL_WEBDAV] = "webdav",
7c6044a9 795#endif
22fa7da0 796 };
d1f29646
LC
797
798 info = qmp_query_spice(NULL);
799
800 if (!info->enabled) {
801 monitor_printf(mon, "Server: disabled\n");
802 goto out;
803 }
804
805 monitor_printf(mon, "Server:\n");
806 if (info->has_port) {
807 monitor_printf(mon, " address: %s:%" PRId64 "\n",
808 info->host, info->port);
809 }
810 if (info->has_tls_port) {
811 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
812 info->host, info->tls_port);
813 }
61c4efe2
YH
814 monitor_printf(mon, " migrated: %s\n",
815 info->migrated ? "true" : "false");
d1f29646
LC
816 monitor_printf(mon, " auth: %s\n", info->auth);
817 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
4efee029 818 monitor_printf(mon, " mouse-mode: %s\n",
977c736f 819 SpiceQueryMouseMode_str(info->mouse_mode));
d1f29646
LC
820
821 if (!info->has_channels || info->channels == NULL) {
822 monitor_printf(mon, "Channels: none\n");
823 } else {
824 for (chan = info->channels; chan; chan = chan->next) {
825 monitor_printf(mon, "Channel:\n");
826 monitor_printf(mon, " address: %s:%s%s\n",
ddf21908 827 chan->value->host, chan->value->port,
d1f29646
LC
828 chan->value->tls ? " [tls]" : "");
829 monitor_printf(mon, " session: %" PRId64 "\n",
830 chan->value->connection_id);
831 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
832 chan->value->channel_type, chan->value->channel_id);
22fa7da0
CR
833
834 channel_name = "unknown";
835 if (chan->value->channel_type > 0 &&
836 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
837 channel_names[chan->value->channel_type]) {
838 channel_name = channel_names[chan->value->channel_type];
839 }
840
841 monitor_printf(mon, " channel name: %s\n", channel_name);
d1f29646
LC
842 }
843 }
844
845out:
846 qapi_free_SpiceInfo(info);
847}
206addd5 848#endif
d1f29646 849
84f2d0ea 850void hmp_info_balloon(Monitor *mon, const QDict *qdict)
96637bcd
LC
851{
852 BalloonInfo *info;
853 Error *err = NULL;
854
855 info = qmp_query_balloon(&err);
856 if (err) {
187c6147 857 hmp_handle_error(mon, err);
96637bcd
LC
858 return;
859 }
860
01ceb97e 861 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
96637bcd
LC
862
863 qapi_free_BalloonInfo(info);
864}
865
79627472
LC
866static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
867{
868 PciMemoryRegionList *region;
869
870 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
871 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
872 dev->slot, dev->function);
873 monitor_printf(mon, " ");
874
9fa02cd1
EB
875 if (dev->class_info->has_desc) {
876 monitor_printf(mon, "%s", dev->class_info->desc);
79627472 877 } else {
9fa02cd1 878 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
79627472
LC
879 }
880
881 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
9fa02cd1 882 dev->id->vendor, dev->id->device);
18613dc6
DL
883 if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) {
884 monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n",
885 dev->id->subsystem_vendor, dev->id->subsystem);
886 }
79627472
LC
887
888 if (dev->has_irq) {
889 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
890 }
891
892 if (dev->has_pci_bridge) {
893 monitor_printf(mon, " BUS %" PRId64 ".\n",
9fa02cd1 894 dev->pci_bridge->bus->number);
79627472 895 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
9fa02cd1 896 dev->pci_bridge->bus->secondary);
79627472 897 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
9fa02cd1 898 dev->pci_bridge->bus->subordinate);
79627472
LC
899
900 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
9fa02cd1
EB
901 dev->pci_bridge->bus->io_range->base,
902 dev->pci_bridge->bus->io_range->limit);
79627472
LC
903
904 monitor_printf(mon,
905 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
9fa02cd1
EB
906 dev->pci_bridge->bus->memory_range->base,
907 dev->pci_bridge->bus->memory_range->limit);
79627472
LC
908
909 monitor_printf(mon, " prefetchable memory range "
910 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
9fa02cd1
EB
911 dev->pci_bridge->bus->prefetchable_range->base,
912 dev->pci_bridge->bus->prefetchable_range->limit);
79627472
LC
913 }
914
915 for (region = dev->regions; region; region = region->next) {
916 uint64_t addr, size;
917
918 addr = region->value->address;
919 size = region->value->size;
920
921 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
922
923 if (!strcmp(region->value->type, "io")) {
924 monitor_printf(mon, "I/O at 0x%04" PRIx64
925 " [0x%04" PRIx64 "].\n",
926 addr, addr + size - 1);
927 } else {
928 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
929 " [0x%08" PRIx64 "].\n",
930 region->value->mem_type_64 ? 64 : 32,
931 region->value->prefetch ? " prefetchable" : "",
932 addr, addr + size - 1);
933 }
934 }
935
936 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
937
938 if (dev->has_pci_bridge) {
939 if (dev->pci_bridge->has_devices) {
940 PciDeviceInfoList *cdev;
941 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
942 hmp_info_pci_device(mon, cdev->value);
943 }
944 }
945 }
946}
947
61b97833
HP
948static int hmp_info_irq_foreach(Object *obj, void *opaque)
949{
950 InterruptStatsProvider *intc;
951 InterruptStatsProviderClass *k;
952 Monitor *mon = opaque;
953
954 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
955 intc = INTERRUPT_STATS_PROVIDER(obj);
956 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
957 uint64_t *irq_counts;
958 unsigned int nb_irqs, i;
959 if (k->get_statistics &&
960 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
961 if (nb_irqs > 0) {
962 monitor_printf(mon, "IRQ statistics for %s:\n",
963 object_get_typename(obj));
964 for (i = 0; i < nb_irqs; i++) {
965 if (irq_counts[i] > 0) {
966 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
967 irq_counts[i]);
968 }
969 }
970 }
971 } else {
972 monitor_printf(mon, "IRQ statistics not available for %s.\n",
973 object_get_typename(obj));
974 }
975 }
976
977 return 0;
978}
979
980void hmp_info_irq(Monitor *mon, const QDict *qdict)
981{
982 object_child_foreach_recursive(object_get_root(),
983 hmp_info_irq_foreach, mon);
984}
985
986static int hmp_info_pic_foreach(Object *obj, void *opaque)
987{
988 InterruptStatsProvider *intc;
989 InterruptStatsProviderClass *k;
990 Monitor *mon = opaque;
991
992 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
993 intc = INTERRUPT_STATS_PROVIDER(obj);
994 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
995 if (k->print_info) {
996 k->print_info(intc, mon);
997 } else {
998 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
999 object_get_typename(obj));
1000 }
1001 }
1002
1003 return 0;
1004}
1005
1006void hmp_info_pic(Monitor *mon, const QDict *qdict)
1007{
1008 object_child_foreach_recursive(object_get_root(),
1009 hmp_info_pic_foreach, mon);
1010}
1011
f4b2c02a
YS
1012static int hmp_info_rdma_foreach(Object *obj, void *opaque)
1013{
1014 RdmaProvider *rdma;
1015 RdmaProviderClass *k;
1016 Monitor *mon = opaque;
1017
1018 if (object_dynamic_cast(obj, INTERFACE_RDMA_PROVIDER)) {
1019 rdma = RDMA_PROVIDER(obj);
1020 k = RDMA_PROVIDER_GET_CLASS(obj);
1021 if (k->print_statistics) {
1022 k->print_statistics(mon, rdma);
1023 } else {
1024 monitor_printf(mon, "RDMA statistics not available for %s.\n",
1025 object_get_typename(obj));
1026 }
1027 }
1028
1029 return 0;
1030}
1031
1032void hmp_info_rdma(Monitor *mon, const QDict *qdict)
1033{
1034 object_child_foreach_recursive(object_get_root(),
1035 hmp_info_rdma_foreach, mon);
1036}
1037
84f2d0ea 1038void hmp_info_pci(Monitor *mon, const QDict *qdict)
79627472 1039{
f46cee37 1040 PciInfoList *info_list, *info;
79627472
LC
1041 Error *err = NULL;
1042
f46cee37 1043 info_list = qmp_query_pci(&err);
79627472
LC
1044 if (err) {
1045 monitor_printf(mon, "PCI devices not supported\n");
1046 error_free(err);
1047 return;
1048 }
1049
f46cee37 1050 for (info = info_list; info; info = info->next) {
79627472
LC
1051 PciDeviceInfoList *dev;
1052
1053 for (dev = info->value->devices; dev; dev = dev->next) {
1054 hmp_info_pci_device(mon, dev->value);
1055 }
1056 }
1057
f46cee37 1058 qapi_free_PciInfoList(info_list);
79627472
LC
1059}
1060
84f2d0ea 1061void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
fb5458cd
SH
1062{
1063 BlockJobInfoList *list;
1064 Error *err = NULL;
1065
1066 list = qmp_query_block_jobs(&err);
1067 assert(!err);
1068
1069 if (!list) {
1070 monitor_printf(mon, "No active jobs\n");
1071 return;
1072 }
1073
1074 while (list) {
1075 if (strcmp(list->value->type, "stream") == 0) {
1076 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
1077 " of %" PRId64 " bytes, speed limit %" PRId64
1078 " bytes/s\n",
1079 list->value->device,
1080 list->value->offset,
1081 list->value->len,
1082 list->value->speed);
1083 } else {
1084 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
1085 " of %" PRId64 " bytes, speed limit %" PRId64
1086 " bytes/s\n",
1087 list->value->type,
1088 list->value->device,
1089 list->value->offset,
1090 list->value->len,
1091 list->value->speed);
1092 }
1093 list = list->next;
1094 }
93bb1315
GA
1095
1096 qapi_free_BlockJobInfoList(list);
fb5458cd
SH
1097}
1098
d1a0cf73
SB
1099void hmp_info_tpm(Monitor *mon, const QDict *qdict)
1100{
1101 TPMInfoList *info_list, *info;
1102 Error *err = NULL;
1103 unsigned int c = 0;
1104 TPMPassthroughOptions *tpo;
f4ede81e 1105 TPMEmulatorOptions *teo;
d1a0cf73
SB
1106
1107 info_list = qmp_query_tpm(&err);
1108 if (err) {
1109 monitor_printf(mon, "TPM device not supported\n");
1110 error_free(err);
1111 return;
1112 }
1113
1114 if (info_list) {
1115 monitor_printf(mon, "TPM device:\n");
1116 }
1117
1118 for (info = info_list; info; info = info->next) {
1119 TPMInfo *ti = info->value;
1120 monitor_printf(mon, " tpm%d: model=%s\n",
977c736f 1121 c, TpmModel_str(ti->model));
d1a0cf73
SB
1122
1123 monitor_printf(mon, " \\ %s: type=%s",
977c736f 1124 ti->id, TpmTypeOptionsKind_str(ti->options->type));
d1a0cf73 1125
ce21131a 1126 switch (ti->options->type) {
88ca7bcf 1127 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
32bafa8f 1128 tpo = ti->options->u.passthrough.data;
d1a0cf73
SB
1129 monitor_printf(mon, "%s%s%s%s",
1130 tpo->has_path ? ",path=" : "",
1131 tpo->has_path ? tpo->path : "",
1132 tpo->has_cancel_path ? ",cancel-path=" : "",
1133 tpo->has_cancel_path ? tpo->cancel_path : "");
1134 break;
f4ede81e
AV
1135 case TPM_TYPE_OPTIONS_KIND_EMULATOR:
1136 teo = ti->options->u.emulator.data;
1137 monitor_printf(mon, ",chardev=%s", teo->chardev);
1138 break;
7fb1cf16 1139 case TPM_TYPE_OPTIONS_KIND__MAX:
d1a0cf73
SB
1140 break;
1141 }
1142 monitor_printf(mon, "\n");
1143 c++;
1144 }
1145 qapi_free_TPMInfoList(info_list);
1146}
1147
7a7f325e
LC
1148void hmp_quit(Monitor *mon, const QDict *qdict)
1149{
1150 monitor_suspend(mon);
1151 qmp_quit(NULL);
1152}
5f158f21
LC
1153
1154void hmp_stop(Monitor *mon, const QDict *qdict)
1155{
1156 qmp_stop(NULL);
1157}
38d22653 1158
dd12e1bb
EC
1159void hmp_sync_profile(Monitor *mon, const QDict *qdict)
1160{
1161 const char *op = qdict_get_try_str(qdict, "op");
1162
1163 if (op == NULL) {
1164 bool on = qsp_is_enabled();
1165
1166 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off");
1167 return;
1168 }
1169 if (!strcmp(op, "on")) {
1170 qsp_enable();
1171 } else if (!strcmp(op, "off")) {
1172 qsp_disable();
1173 } else if (!strcmp(op, "reset")) {
1174 qsp_reset();
1175 } else {
1176 Error *err = NULL;
1177
1178 error_setg(&err, QERR_INVALID_PARAMETER, op);
187c6147 1179 hmp_handle_error(mon, err);
dd12e1bb
EC
1180 }
1181}
1182
38d22653
LC
1183void hmp_system_reset(Monitor *mon, const QDict *qdict)
1184{
1185 qmp_system_reset(NULL);
1186}
5bc465e4
LC
1187
1188void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
1189{
1190 qmp_system_powerdown(NULL);
1191}
755f1968 1192
8e8581e6
DDAG
1193void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
1194{
1195 Error *err = NULL;
1196
361ac948 1197 qmp_x_exit_preconfig(&err);
187c6147 1198 hmp_handle_error(mon, err);
8e8581e6
DDAG
1199}
1200
755f1968
LC
1201void hmp_cpu(Monitor *mon, const QDict *qdict)
1202{
1203 int64_t cpu_index;
1204
1205 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1206 use it are converted to the QAPI */
1207 cpu_index = qdict_get_int(qdict, "index");
1208 if (monitor_set_cpu(cpu_index) < 0) {
1209 monitor_printf(mon, "invalid CPU index\n");
1210 }
1211}
0cfd6a9a
LC
1212
1213void hmp_memsave(Monitor *mon, const QDict *qdict)
1214{
1215 uint32_t size = qdict_get_int(qdict, "size");
1216 const char *filename = qdict_get_str(qdict, "filename");
1217 uint64_t addr = qdict_get_int(qdict, "val");
e940f543 1218 Error *err = NULL;
854e67fe 1219 int cpu_index = monitor_get_cpu_index();
0cfd6a9a 1220
854e67fe
TH
1221 if (cpu_index < 0) {
1222 monitor_printf(mon, "No CPU available\n");
1223 return;
1224 }
1225
1226 qmp_memsave(addr, size, filename, true, cpu_index, &err);
187c6147 1227 hmp_handle_error(mon, err);
0cfd6a9a 1228}
6d3962bf
LC
1229
1230void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1231{
1232 uint32_t size = qdict_get_int(qdict, "size");
1233 const char *filename = qdict_get_str(qdict, "filename");
1234 uint64_t addr = qdict_get_int(qdict, "val");
e940f543 1235 Error *err = NULL;
6d3962bf 1236
e940f543 1237 qmp_pmemsave(addr, size, filename, &err);
187c6147 1238 hmp_handle_error(mon, err);
1f590cf9
LL
1239}
1240
3949e594 1241void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1f590cf9 1242{
1f590cf9
LL
1243 const char *chardev = qdict_get_str(qdict, "device");
1244 const char *data = qdict_get_str(qdict, "data");
e940f543 1245 Error *err = NULL;
1f590cf9 1246
e940f543 1247 qmp_ringbuf_write(chardev, data, false, 0, &err);
1f590cf9 1248
187c6147 1249 hmp_handle_error(mon, err);
6d3962bf 1250}
e42e818b 1251
3949e594 1252void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
49b6d722
LL
1253{
1254 uint32_t size = qdict_get_int(qdict, "size");
1255 const char *chardev = qdict_get_str(qdict, "device");
3ab651fc 1256 char *data;
e940f543 1257 Error *err = NULL;
543f3412 1258 int i;
49b6d722 1259
e940f543
MA
1260 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1261 if (err) {
187c6147 1262 hmp_handle_error(mon, err);
49b6d722
LL
1263 return;
1264 }
1265
543f3412
MA
1266 for (i = 0; data[i]; i++) {
1267 unsigned char ch = data[i];
1268
1269 if (ch == '\\') {
1270 monitor_printf(mon, "\\\\");
1271 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1272 monitor_printf(mon, "\\u%04X", ch);
1273 } else {
1274 monitor_printf(mon, "%c", ch);
1275 }
1276
1277 }
1278 monitor_printf(mon, "\n");
3ab651fc 1279 g_free(data);
49b6d722
LL
1280}
1281
e42e818b
LC
1282void hmp_cont(Monitor *mon, const QDict *qdict)
1283{
e940f543 1284 Error *err = NULL;
e42e818b 1285
e940f543 1286 qmp_cont(&err);
187c6147 1287 hmp_handle_error(mon, err);
e42e818b 1288}
ab49ab5c 1289
9b9df25a
GH
1290void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1291{
fb064112
DHB
1292 Error *err = NULL;
1293
1294 qmp_system_wakeup(&err);
187c6147 1295 hmp_handle_error(mon, err);
9b9df25a
GH
1296}
1297
3e5a50d6 1298void hmp_nmi(Monitor *mon, const QDict *qdict)
ab49ab5c 1299{
e940f543 1300 Error *err = NULL;
ab49ab5c 1301
e940f543 1302 qmp_inject_nmi(&err);
187c6147 1303 hmp_handle_error(mon, err);
ab49ab5c 1304}
4b37156c
LC
1305
1306void hmp_set_link(Monitor *mon, const QDict *qdict)
1307{
1308 const char *name = qdict_get_str(qdict, "name");
34acbc95 1309 bool up = qdict_get_bool(qdict, "up");
e940f543 1310 Error *err = NULL;
4b37156c 1311
e940f543 1312 qmp_set_link(name, up, &err);
187c6147 1313 hmp_handle_error(mon, err);
4b37156c 1314}
a4dea8a9
LC
1315
1316void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1317{
1318 const char *device = qdict_get_str(qdict, "device");
1319 const char *password = qdict_get_str(qdict, "password");
e940f543 1320 Error *err = NULL;
a4dea8a9 1321
e940f543 1322 qmp_block_passwd(true, device, false, NULL, password, &err);
187c6147 1323 hmp_handle_error(mon, err);
a4dea8a9 1324}
d72f3264
LC
1325
1326void hmp_balloon(Monitor *mon, const QDict *qdict)
1327{
1328 int64_t value = qdict_get_int(qdict, "value");
e940f543 1329 Error *err = NULL;
d72f3264 1330
e940f543 1331 qmp_balloon(value, &err);
187c6147 1332 hmp_handle_error(mon, err);
d72f3264 1333}
5e7caacb
LC
1334
1335void hmp_block_resize(Monitor *mon, const QDict *qdict)
1336{
1337 const char *device = qdict_get_str(qdict, "device");
1338 int64_t size = qdict_get_int(qdict, "size");
e940f543 1339 Error *err = NULL;
5e7caacb 1340
e940f543 1341 qmp_block_resize(true, device, false, NULL, size, &err);
187c6147 1342 hmp_handle_error(mon, err);
5e7caacb 1343}
6106e249 1344
d9b902db
PB
1345void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1346{
d9b902db
PB
1347 const char *filename = qdict_get_str(qdict, "target");
1348 const char *format = qdict_get_try_str(qdict, "format");
34acbc95
EB
1349 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1350 bool full = qdict_get_try_bool(qdict, "full", false);
e940f543 1351 Error *err = NULL;
faecd40a
EB
1352 DriveMirror mirror = {
1353 .device = (char *)qdict_get_str(qdict, "device"),
1354 .target = (char *)filename,
1355 .has_format = !!format,
1356 .format = (char *)format,
1357 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1358 .has_mode = true,
1359 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1360 .unmap = true,
1361 };
d9b902db
PB
1362
1363 if (!filename) {
c6bd8c70 1364 error_setg(&err, QERR_MISSING_PARAMETER, "target");
187c6147 1365 hmp_handle_error(mon, err);
d9b902db
PB
1366 return;
1367 }
faecd40a 1368 qmp_drive_mirror(&mirror, &err);
187c6147 1369 hmp_handle_error(mon, err);
d9b902db
PB
1370}
1371
de90930a
SH
1372void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1373{
1374 const char *device = qdict_get_str(qdict, "device");
1375 const char *filename = qdict_get_str(qdict, "target");
1376 const char *format = qdict_get_try_str(qdict, "format");
34acbc95
EB
1377 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1378 bool full = qdict_get_try_bool(qdict, "full", false);
13b9414b 1379 bool compress = qdict_get_try_bool(qdict, "compress", false);
e940f543 1380 Error *err = NULL;
81206a89
PB
1381 DriveBackup backup = {
1382 .device = (char *)device,
1383 .target = (char *)filename,
1384 .has_format = !!format,
1385 .format = (char *)format,
1386 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1387 .has_mode = true,
1388 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
13b9414b
PB
1389 .has_compress = !!compress,
1390 .compress = compress,
81206a89 1391 };
de90930a
SH
1392
1393 if (!filename) {
c6bd8c70 1394 error_setg(&err, QERR_MISSING_PARAMETER, "target");
187c6147 1395 hmp_handle_error(mon, err);
de90930a
SH
1396 return;
1397 }
1398
81206a89 1399 qmp_drive_backup(&backup, &err);
187c6147 1400 hmp_handle_error(mon, err);
de90930a
SH
1401}
1402
6106e249
LC
1403void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1404{
1405 const char *device = qdict_get_str(qdict, "device");
1406 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1407 const char *format = qdict_get_try_str(qdict, "format");
34acbc95 1408 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
6cc2a415 1409 enum NewImageMode mode;
e940f543 1410 Error *err = NULL;
6106e249
LC
1411
1412 if (!filename) {
1413 /* In the future, if 'snapshot-file' is not specified, the snapshot
1414 will be taken internally. Today it's actually required. */
c6bd8c70 1415 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
187c6147 1416 hmp_handle_error(mon, err);
6106e249
LC
1417 return;
1418 }
1419
6cc2a415 1420 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
0901f67e
BC
1421 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1422 filename, false, NULL,
1423 !!format, format,
e940f543 1424 true, mode, &err);
187c6147 1425 hmp_handle_error(mon, err);
6106e249 1426}
6cdedb07 1427
775ca88e
WX
1428void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1429{
1430 const char *device = qdict_get_str(qdict, "device");
1431 const char *name = qdict_get_str(qdict, "name");
e940f543 1432 Error *err = NULL;
775ca88e 1433
e940f543 1434 qmp_blockdev_snapshot_internal_sync(device, name, &err);
187c6147 1435 hmp_handle_error(mon, err);
775ca88e
WX
1436}
1437
7a4ed2ee
WX
1438void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1439{
1440 const char *device = qdict_get_str(qdict, "device");
1441 const char *name = qdict_get_str(qdict, "name");
1442 const char *id = qdict_get_try_str(qdict, "id");
e940f543 1443 Error *err = NULL;
7a4ed2ee
WX
1444
1445 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
e940f543 1446 true, name, &err);
187c6147 1447 hmp_handle_error(mon, err);
7a4ed2ee
WX
1448}
1449
52b26205
JQ
1450void hmp_loadvm(Monitor *mon, const QDict *qdict)
1451{
1452 int saved_vm_running = runstate_is_running();
1453 const char *name = qdict_get_str(qdict, "name");
927d6638 1454 Error *err = NULL;
52b26205
JQ
1455
1456 vm_stop(RUN_STATE_RESTORE_VM);
1457
5e22479a 1458 if (load_snapshot(name, &err) == 0 && saved_vm_running) {
52b26205
JQ
1459 vm_start();
1460 }
187c6147 1461 hmp_handle_error(mon, err);
52b26205
JQ
1462}
1463
d9c7d137
JQ
1464void hmp_savevm(Monitor *mon, const QDict *qdict)
1465{
927d6638
JQ
1466 Error *err = NULL;
1467
5e22479a 1468 save_snapshot(qdict_get_try_str(qdict, "name"), &err);
187c6147 1469 hmp_handle_error(mon, err);
d9c7d137
JQ
1470}
1471
d905bb7b
JQ
1472void hmp_delvm(Monitor *mon, const QDict *qdict)
1473{
1474 BlockDriverState *bs;
32cd6550 1475 Error *err = NULL;
d905bb7b
JQ
1476 const char *name = qdict_get_str(qdict, "name");
1477
1478 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
b4e492db
CR
1479 error_prepend(&err,
1480 "deleting snapshot on device '%s': ",
1481 bdrv_get_device_name(bs));
d905bb7b 1482 }
187c6147 1483 hmp_handle_error(mon, err);
d905bb7b
JQ
1484}
1485
66830618
JQ
1486void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
1487{
1488 BlockDriverState *bs, *bs1;
1489 BdrvNextIterator it1;
1490 QEMUSnapshotInfo *sn_tab, *sn;
1491 bool no_snapshot = true;
1492 int nb_sns, i;
1493 int total;
1494 int *global_snapshots;
1495 AioContext *aio_context;
1496
1497 typedef struct SnapshotEntry {
1498 QEMUSnapshotInfo sn;
1499 QTAILQ_ENTRY(SnapshotEntry) next;
1500 } SnapshotEntry;
1501
1502 typedef struct ImageEntry {
1503 const char *imagename;
1504 QTAILQ_ENTRY(ImageEntry) next;
1505 QTAILQ_HEAD(, SnapshotEntry) snapshots;
1506 } ImageEntry;
1507
1508 QTAILQ_HEAD(, ImageEntry) image_list =
1509 QTAILQ_HEAD_INITIALIZER(image_list);
1510
1511 ImageEntry *image_entry, *next_ie;
1512 SnapshotEntry *snapshot_entry;
1513
1514 bs = bdrv_all_find_vmstate_bs();
1515 if (!bs) {
1516 monitor_printf(mon, "No available block device supports snapshots\n");
1517 return;
1518 }
1519 aio_context = bdrv_get_aio_context(bs);
1520
1521 aio_context_acquire(aio_context);
1522 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
1523 aio_context_release(aio_context);
1524
1525 if (nb_sns < 0) {
1526 monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
1527 return;
1528 }
1529
1530 for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) {
1531 int bs1_nb_sns = 0;
1532 ImageEntry *ie;
1533 SnapshotEntry *se;
1534 AioContext *ctx = bdrv_get_aio_context(bs1);
1535
1536 aio_context_acquire(ctx);
1537 if (bdrv_can_snapshot(bs1)) {
1538 sn = NULL;
1539 bs1_nb_sns = bdrv_snapshot_list(bs1, &sn);
1540 if (bs1_nb_sns > 0) {
1541 no_snapshot = false;
1542 ie = g_new0(ImageEntry, 1);
1543 ie->imagename = bdrv_get_device_name(bs1);
1544 QTAILQ_INIT(&ie->snapshots);
1545 QTAILQ_INSERT_TAIL(&image_list, ie, next);
1546 for (i = 0; i < bs1_nb_sns; i++) {
1547 se = g_new0(SnapshotEntry, 1);
1548 se->sn = sn[i];
1549 QTAILQ_INSERT_TAIL(&ie->snapshots, se, next);
1550 }
1551 }
1552 g_free(sn);
1553 }
1554 aio_context_release(ctx);
1555 }
1556
1557 if (no_snapshot) {
1558 monitor_printf(mon, "There is no snapshot available.\n");
1559 return;
1560 }
1561
1562 global_snapshots = g_new0(int, nb_sns);
1563 total = 0;
1564 for (i = 0; i < nb_sns; i++) {
1565 SnapshotEntry *next_sn;
1566 if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) {
1567 global_snapshots[total] = i;
1568 total++;
1569 QTAILQ_FOREACH(image_entry, &image_list, next) {
1570 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots,
1571 next, next_sn) {
1572 if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) {
1573 QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry,
1574 next);
1575 g_free(snapshot_entry);
1576 }
1577 }
1578 }
1579 }
1580 }
1581
1582 monitor_printf(mon, "List of snapshots present on all disks:\n");
1583
1584 if (total > 0) {
e1ce7d74 1585 bdrv_snapshot_dump(NULL);
66830618
JQ
1586 monitor_printf(mon, "\n");
1587 for (i = 0; i < total; i++) {
1588 sn = &sn_tab[global_snapshots[i]];
1589 /* The ID is not guaranteed to be the same on all images, so
1590 * overwrite it.
1591 */
1592 pstrcpy(sn->id_str, sizeof(sn->id_str), "--");
e1ce7d74 1593 bdrv_snapshot_dump(sn);
66830618
JQ
1594 monitor_printf(mon, "\n");
1595 }
1596 } else {
1597 monitor_printf(mon, "None\n");
1598 }
1599
1600 QTAILQ_FOREACH(image_entry, &image_list, next) {
1601 if (QTAILQ_EMPTY(&image_entry->snapshots)) {
1602 continue;
1603 }
1604 monitor_printf(mon,
1605 "\nList of partial (non-loadable) snapshots on '%s':\n",
1606 image_entry->imagename);
e1ce7d74 1607 bdrv_snapshot_dump(NULL);
66830618
JQ
1608 monitor_printf(mon, "\n");
1609 QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) {
e1ce7d74 1610 bdrv_snapshot_dump(&snapshot_entry->sn);
66830618
JQ
1611 monitor_printf(mon, "\n");
1612 }
1613 }
1614
1615 QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) {
1616 SnapshotEntry *next_sn;
1617 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next,
1618 next_sn) {
1619 g_free(snapshot_entry);
1620 }
1621 g_free(image_entry);
1622 }
1623 g_free(sn_tab);
1624 g_free(global_snapshots);
1625
1626}
1627
544f6ea3
DDAG
1628void hmp_announce_self(Monitor *mon, const QDict *qdict)
1629{
08528271 1630 const char *interfaces_str = qdict_get_try_str(qdict, "interfaces");
c6644548 1631 const char *id = qdict_get_try_str(qdict, "id");
08528271
DDAG
1632 AnnounceParameters *params = QAPI_CLONE(AnnounceParameters,
1633 migrate_announce_params());
1634
1635 qapi_free_strList(params->interfaces);
1636 params->interfaces = strList_from_comma_list(interfaces_str);
1637 params->has_interfaces = params->interfaces != NULL;
c6644548
DDAG
1638 params->id = g_strdup(id);
1639 params->has_id = !!params->id;
08528271
DDAG
1640 qmp_announce_self(params, NULL);
1641 qapi_free_AnnounceParameters(params);
544f6ea3
DDAG
1642}
1643
6cdedb07
LC
1644void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1645{
1646 qmp_migrate_cancel(NULL);
1647}
4f0a993b 1648
94ae12cb
DDAG
1649void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1650{
1651 Error *err = NULL;
1652 const char *state = qdict_get_str(qdict, "state");
1653 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1654
1655 if (val >= 0) {
1656 qmp_migrate_continue(val, &err);
1657 }
1658
187c6147 1659 hmp_handle_error(mon, err);
94ae12cb
DDAG
1660}
1661
bf1ae1f4
DDAG
1662void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1663{
1664 Error *err = NULL;
1665 const char *uri = qdict_get_str(qdict, "uri");
1666
1667 qmp_migrate_incoming(uri, &err);
1668
187c6147 1669 hmp_handle_error(mon, err);
bf1ae1f4
DDAG
1670}
1671
3b563c4b
PX
1672void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
1673{
1674 Error *err = NULL;
1675 const char *uri = qdict_get_str(qdict, "uri");
1676
1677 qmp_migrate_recover(uri, &err);
1678
187c6147 1679 hmp_handle_error(mon, err);
3b563c4b
PX
1680}
1681
d37297dc
PX
1682void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
1683{
1684 Error *err = NULL;
1685
1686 qmp_migrate_pause(&err);
1687
187c6147 1688 hmp_handle_error(mon, err);
d37297dc
PX
1689}
1690
2ff30257 1691/* Kept for backwards compatibility */
4f0a993b
LC
1692void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1693{
1694 double value = qdict_get_double(qdict, "value");
1695 qmp_migrate_set_downtime(value, NULL);
1696}
3dc85383 1697
9e1ba4cc
OW
1698void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1699{
1700 int64_t value = qdict_get_int(qdict, "value");
1701 Error *err = NULL;
1702
1703 qmp_migrate_set_cache_size(value, &err);
187c6147 1704 hmp_handle_error(mon, err);
9e1ba4cc
OW
1705}
1706
2ff30257 1707/* Kept for backwards compatibility */
3dc85383
LC
1708void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1709{
1710 int64_t value = qdict_get_int(qdict, "value");
1711 qmp_migrate_set_speed(value, NULL);
1712}
fbf796fd 1713
00458433
OW
1714void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1715{
1716 const char *cap = qdict_get_str(qdict, "capability");
1717 bool state = qdict_get_bool(qdict, "state");
1718 Error *err = NULL;
1719 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
8e615e34 1720 int val;
00458433 1721
f7abe0ec 1722 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
8e615e34
MAL
1723 if (val < 0) {
1724 goto end;
00458433
OW
1725 }
1726
8e615e34
MAL
1727 caps->value = g_malloc0(sizeof(*caps->value));
1728 caps->value->capability = val;
1729 caps->value->state = state;
1730 caps->next = NULL;
1731 qmp_migrate_set_capabilities(caps, &err);
00458433 1732
8e615e34 1733end:
00458433 1734 qapi_free_MigrationCapabilityStatusList(caps);
187c6147 1735 hmp_handle_error(mon, err);
00458433
OW
1736}
1737
50e9a629
LL
1738void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1739{
1740 const char *param = qdict_get_str(qdict, "parameter");
69ef1f36 1741 const char *valuestr = qdict_get_str(qdict, "value");
f4a06d13 1742 Visitor *v = string_input_visitor_new(valuestr);
1bda8b3c 1743 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
f46bfdbf 1744 uint64_t valuebw = 0;
73af8dd8 1745 uint64_t cache_size;
96eef042 1746 MultiFDCompression compress_type;
50e9a629 1747 Error *err = NULL;
262517b7 1748 int val, ret;
69ef1f36 1749
f7abe0ec 1750 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
262517b7
MAL
1751 if (val < 0) {
1752 goto cleanup;
1753 }
1754
1755 switch (val) {
1756 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1757 p->has_compress_level = true;
1758 visit_type_int(v, param, &p->compress_level, &err);
1759 break;
1760 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1761 p->has_compress_threads = true;
1762 visit_type_int(v, param, &p->compress_threads, &err);
1763 break;
1d58872a
XG
1764 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD:
1765 p->has_compress_wait_thread = true;
1766 visit_type_bool(v, param, &p->compress_wait_thread, &err);
1767 break;
262517b7
MAL
1768 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1769 p->has_decompress_threads = true;
1770 visit_type_int(v, param, &p->decompress_threads, &err);
1771 break;
1772 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1773 p->has_cpu_throttle_initial = true;
1774 visit_type_int(v, param, &p->cpu_throttle_initial, &err);
1775 break;
1776 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1777 p->has_cpu_throttle_increment = true;
1778 visit_type_int(v, param, &p->cpu_throttle_increment, &err);
1779 break;
4cbc9c7f
LQ
1780 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE:
1781 p->has_max_cpu_throttle = true;
1782 visit_type_int(v, param, &p->max_cpu_throttle, &err);
1783 break;
262517b7
MAL
1784 case MIGRATION_PARAMETER_TLS_CREDS:
1785 p->has_tls_creds = true;
1786 p->tls_creds = g_new0(StrOrNull, 1);
1787 p->tls_creds->type = QTYPE_QSTRING;
1788 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1789 break;
1790 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1791 p->has_tls_hostname = true;
1792 p->tls_hostname = g_new0(StrOrNull, 1);
1793 p->tls_hostname->type = QTYPE_QSTRING;
1794 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1795 break;
d2f1d29b
DB
1796 case MIGRATION_PARAMETER_TLS_AUTHZ:
1797 p->has_tls_authz = true;
1798 p->tls_authz = g_new0(StrOrNull, 1);
1799 p->tls_authz->type = QTYPE_QSTRING;
1800 visit_type_str(v, param, &p->tls_authz->u.s, &err);
1801 break;
262517b7
MAL
1802 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1803 p->has_max_bandwidth = true;
1804 /*
1805 * Can't use visit_type_size() here, because it
1806 * defaults to Bytes rather than Mebibytes.
1807 */
1808 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1809 if (ret < 0 || valuebw > INT64_MAX
1810 || (size_t)valuebw != valuebw) {
1811 error_setg(&err, "Invalid size %s", valuestr);
50e9a629
LL
1812 break;
1813 }
262517b7
MAL
1814 p->max_bandwidth = valuebw;
1815 break;
1816 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1817 p->has_downtime_limit = true;
1818 visit_type_int(v, param, &p->downtime_limit, &err);
1819 break;
1820 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1821 p->has_x_checkpoint_delay = true;
1822 visit_type_int(v, param, &p->x_checkpoint_delay, &err);
1823 break;
1824 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1825 p->has_block_incremental = true;
1826 visit_type_bool(v, param, &p->block_incremental, &err);
1827 break;
cbfd6c95
JQ
1828 case MIGRATION_PARAMETER_MULTIFD_CHANNELS:
1829 p->has_multifd_channels = true;
1830 visit_type_int(v, param, &p->multifd_channels, &err);
4075fb1c 1831 break;
96eef042
JQ
1832 case MIGRATION_PARAMETER_MULTIFD_COMPRESSION:
1833 p->has_multifd_compression = true;
1834 visit_type_MultiFDCompression(v, param, &compress_type, &err);
1835 if (err) {
1836 break;
1837 }
1838 p->multifd_compression = compress_type;
1839 break;
9004db48
JQ
1840 case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL:
1841 p->has_multifd_zlib_level = true;
1842 visit_type_int(v, param, &p->multifd_zlib_level, &err);
1843 break;
6a9ad154
JQ
1844 case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL:
1845 p->has_multifd_zstd_level = true;
1846 visit_type_int(v, param, &p->multifd_zstd_level, &err);
1847 break;
73af8dd8
JQ
1848 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1849 p->has_xbzrle_cache_size = true;
1850 visit_type_size(v, param, &cache_size, &err);
d013283a
JQ
1851 if (err) {
1852 break;
1853 }
1854 if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) {
73af8dd8
JQ
1855 error_setg(&err, "Invalid size %s", valuestr);
1856 break;
1857 }
1858 p->xbzrle_cache_size = cache_size;
1859 break;
7e555c6c
DDAG
1860 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH:
1861 p->has_max_postcopy_bandwidth = true;
1862 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err);
1863 break;
ee3d96ba
DDAG
1864 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL:
1865 p->has_announce_initial = true;
1866 visit_type_size(v, param, &p->announce_initial, &err);
1867 break;
1868 case MIGRATION_PARAMETER_ANNOUNCE_MAX:
1869 p->has_announce_max = true;
1870 visit_type_size(v, param, &p->announce_max, &err);
1871 break;
1872 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS:
1873 p->has_announce_rounds = true;
1874 visit_type_size(v, param, &p->announce_rounds, &err);
1875 break;
1876 case MIGRATION_PARAMETER_ANNOUNCE_STEP:
1877 p->has_announce_step = true;
1878 visit_type_size(v, param, &p->announce_step, &err);
1879 break;
262517b7
MAL
1880 default:
1881 assert(0);
50e9a629
LL
1882 }
1883
262517b7
MAL
1884 if (err) {
1885 goto cleanup;
50e9a629
LL
1886 }
1887
262517b7
MAL
1888 qmp_migrate_set_parameters(p, &err);
1889
69ef1f36 1890 cleanup:
1bda8b3c 1891 qapi_free_MigrateSetParameters(p);
f4a06d13 1892 visit_free(v);
187c6147 1893 hmp_handle_error(mon, err);
50e9a629
LL
1894}
1895
b8a185bc
MA
1896void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1897{
1898 Error *err = NULL;
1899 const char *protocol = qdict_get_str(qdict, "protocol");
1900 const char *hostname = qdict_get_str(qdict, "hostname");
1901 bool has_port = qdict_haskey(qdict, "port");
1902 int port = qdict_get_try_int(qdict, "port", -1);
1903 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1904 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1905 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1906
1907 qmp_client_migrate_info(protocol, hostname,
1908 has_port, port, has_tls_port, tls_port,
1909 !!cert_subject, cert_subject, &err);
187c6147 1910 hmp_handle_error(mon, err);
b8a185bc
MA
1911}
1912
4886a1bc
DDAG
1913void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1914{
1915 Error *err = NULL;
1916 qmp_migrate_start_postcopy(&err);
187c6147 1917 hmp_handle_error(mon, err);
4886a1bc
DDAG
1918}
1919
d89e666e
HZ
1920void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1921{
1922 Error *err = NULL;
1923
1924 qmp_x_colo_lost_heartbeat(&err);
187c6147 1925 hmp_handle_error(mon, err);
d89e666e
HZ
1926}
1927
fbf796fd
LC
1928void hmp_set_password(Monitor *mon, const QDict *qdict)
1929{
1930 const char *protocol = qdict_get_str(qdict, "protocol");
1931 const char *password = qdict_get_str(qdict, "password");
1932 const char *connected = qdict_get_try_str(qdict, "connected");
1933 Error *err = NULL;
1934
1935 qmp_set_password(protocol, password, !!connected, connected, &err);
187c6147 1936 hmp_handle_error(mon, err);
fbf796fd 1937}
9ad5372d
LC
1938
1939void hmp_expire_password(Monitor *mon, const QDict *qdict)
1940{
1941 const char *protocol = qdict_get_str(qdict, "protocol");
1942 const char *whenstr = qdict_get_str(qdict, "time");
1943 Error *err = NULL;
1944
1945 qmp_expire_password(protocol, whenstr, &err);
187c6147 1946 hmp_handle_error(mon, err);
9ad5372d 1947}
c245b6a3
LC
1948
1949void hmp_eject(Monitor *mon, const QDict *qdict)
1950{
34acbc95 1951 bool force = qdict_get_try_bool(qdict, "force", false);
c245b6a3
LC
1952 const char *device = qdict_get_str(qdict, "device");
1953 Error *err = NULL;
1954
fbe2d816 1955 qmp_eject(true, device, false, NULL, true, force, &err);
187c6147 1956 hmp_handle_error(mon, err);
c245b6a3 1957}
333a96ec 1958
05eb4a25 1959#ifdef CONFIG_VNC
c60bf339
SH
1960static void hmp_change_read_arg(void *opaque, const char *password,
1961 void *readline_opaque)
333a96ec
LC
1962{
1963 qmp_change_vnc_password(password, NULL);
c60bf339 1964 monitor_read_command(opaque, 1);
333a96ec 1965}
05eb4a25 1966#endif
333a96ec 1967
333a96ec
LC
1968void hmp_change(Monitor *mon, const QDict *qdict)
1969{
1970 const char *device = qdict_get_str(qdict, "device");
1971 const char *target = qdict_get_str(qdict, "target");
1972 const char *arg = qdict_get_try_str(qdict, "arg");
baead0ab
HR
1973 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1974 BlockdevChangeReadOnlyMode read_only_mode = 0;
333a96ec
LC
1975 Error *err = NULL;
1976
05eb4a25 1977#ifdef CONFIG_VNC
10686749 1978 if (strcmp(device, "vnc") == 0) {
baead0ab
HR
1979 if (read_only) {
1980 monitor_printf(mon,
1981 "Parameter 'read-only-mode' is invalid for VNC\n");
1982 return;
1983 }
10686749
HR
1984 if (strcmp(target, "passwd") == 0 ||
1985 strcmp(target, "password") == 0) {
1986 if (!arg) {
ea73f370 1987 MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
5f9dba16 1988 monitor_read_password(hmp_mon, hmp_change_read_arg, NULL);
10686749
HR
1989 return;
1990 }
1991 }
1992 qmp_change("vnc", target, !!arg, arg, &err);
05eb4a25
MAL
1993 } else
1994#endif
1995 {
baead0ab
HR
1996 if (read_only) {
1997 read_only_mode =
f7abe0ec 1998 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
06c60b6c 1999 read_only,
baead0ab
HR
2000 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
2001 if (err) {
187c6147 2002 hmp_handle_error(mon, err);
baead0ab
HR
2003 return;
2004 }
2005 }
2006
70e2cb3b
KW
2007 qmp_blockdev_change_medium(true, device, false, NULL, target,
2008 !!arg, arg, !!read_only, read_only_mode,
2009 &err);
333a96ec
LC
2010 }
2011
187c6147 2012 hmp_handle_error(mon, err);
333a96ec 2013}
80047da5
LC
2014
2015void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
2016{
2017 Error *err = NULL;
83592184 2018 char *device = (char *) qdict_get_str(qdict, "device");
4dc9397b 2019 BlockIOThrottle throttle = {
4dc9397b
EB
2020 .bps = qdict_get_int(qdict, "bps"),
2021 .bps_rd = qdict_get_int(qdict, "bps_rd"),
2022 .bps_wr = qdict_get_int(qdict, "bps_wr"),
2023 .iops = qdict_get_int(qdict, "iops"),
2024 .iops_rd = qdict_get_int(qdict, "iops_rd"),
2025 .iops_wr = qdict_get_int(qdict, "iops_wr"),
2026 };
80047da5 2027
83592184
AG
2028 /* qmp_block_set_io_throttle has separate parameters for the
2029 * (deprecated) block device name and the qdev ID but the HMP
2030 * version has only one, so we must decide which one to pass. */
2031 if (blk_by_name(device)) {
2032 throttle.has_device = true;
2033 throttle.device = device;
2034 } else {
2035 throttle.has_id = true;
2036 throttle.id = device;
2037 }
2038
4dc9397b 2039 qmp_block_set_io_throttle(&throttle, &err);
187c6147 2040 hmp_handle_error(mon, err);
80047da5 2041}
12bd451f
SH
2042
2043void hmp_block_stream(Monitor *mon, const QDict *qdict)
2044{
2045 Error *error = NULL;
2046 const char *device = qdict_get_str(qdict, "device");
2047 const char *base = qdict_get_try_str(qdict, "base");
c83c66c3 2048 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
12bd451f 2049
11d6fbe0 2050 qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
241ca1ab
JS
2051 false, NULL, qdict_haskey(qdict, "speed"), speed, true,
2052 BLOCKDEV_ON_ERROR_REPORT, false, false, false, false,
2053 &error);
12bd451f 2054
187c6147 2055 hmp_handle_error(mon, error);
12bd451f 2056}
2d47c6e9
SH
2057
2058void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
2059{
2060 Error *error = NULL;
2061 const char *device = qdict_get_str(qdict, "device");
c6db2395 2062 int64_t value = qdict_get_int(qdict, "speed");
2d47c6e9
SH
2063
2064 qmp_block_job_set_speed(device, value, &error);
2065
187c6147 2066 hmp_handle_error(mon, error);
2d47c6e9 2067}
370521a1
SH
2068
2069void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
2070{
2071 Error *error = NULL;
2072 const char *device = qdict_get_str(qdict, "device");
34acbc95 2073 bool force = qdict_get_try_bool(qdict, "force", false);
370521a1 2074
6e37fb81
PB
2075 qmp_block_job_cancel(device, true, force, &error);
2076
187c6147 2077 hmp_handle_error(mon, error);
6e37fb81
PB
2078}
2079
2080void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
2081{
2082 Error *error = NULL;
2083 const char *device = qdict_get_str(qdict, "device");
2084
2085 qmp_block_job_pause(device, &error);
2086
187c6147 2087 hmp_handle_error(mon, error);
6e37fb81
PB
2088}
2089
2090void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
2091{
2092 Error *error = NULL;
2093 const char *device = qdict_get_str(qdict, "device");
2094
2095 qmp_block_job_resume(device, &error);
370521a1 2096
187c6147 2097 hmp_handle_error(mon, error);
370521a1 2098}
e1c37d0e 2099
aeae883b
PB
2100void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
2101{
2102 Error *error = NULL;
2103 const char *device = qdict_get_str(qdict, "device");
2104
2105 qmp_block_job_complete(device, &error);
2106
187c6147 2107 hmp_handle_error(mon, error);
aeae883b
PB
2108}
2109
e49f35bd 2110typedef struct HMPMigrationStatus
e1c37d0e
LC
2111{
2112 QEMUTimer *timer;
2113 Monitor *mon;
2114 bool is_block_migration;
e49f35bd 2115} HMPMigrationStatus;
e1c37d0e
LC
2116
2117static void hmp_migrate_status_cb(void *opaque)
2118{
e49f35bd 2119 HMPMigrationStatus *status = opaque;
e1c37d0e
LC
2120 MigrationInfo *info;
2121
2122 info = qmp_query_migrate(NULL);
24b8c39b
HZ
2123 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
2124 info->status == MIGRATION_STATUS_SETUP) {
e1c37d0e
LC
2125 if (info->has_disk) {
2126 int progress;
2127
2128 if (info->disk->remaining) {
2129 progress = info->disk->transferred * 100 / info->disk->total;
2130 } else {
2131 progress = 100;
2132 }
2133
2134 monitor_printf(status->mon, "Completed %d %%\r", progress);
2135 monitor_flush(status->mon);
2136 }
2137
bc72ad67 2138 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
e1c37d0e
LC
2139 } else {
2140 if (status->is_block_migration) {
2141 monitor_printf(status->mon, "\n");
2142 }
d59ce6f3
DB
2143 if (info->has_error_desc) {
2144 error_report("%s", info->error_desc);
2145 }
e1c37d0e 2146 monitor_resume(status->mon);
bc72ad67 2147 timer_del(status->timer);
d34a10af 2148 timer_free(status->timer);
e1c37d0e
LC
2149 g_free(status);
2150 }
2151
2152 qapi_free_MigrationInfo(info);
2153}
2154
2155void hmp_migrate(Monitor *mon, const QDict *qdict)
2156{
34acbc95
EB
2157 bool detach = qdict_get_try_bool(qdict, "detach", false);
2158 bool blk = qdict_get_try_bool(qdict, "blk", false);
2159 bool inc = qdict_get_try_bool(qdict, "inc", false);
7a4da28b 2160 bool resume = qdict_get_try_bool(qdict, "resume", false);
e1c37d0e
LC
2161 const char *uri = qdict_get_str(qdict, "uri");
2162 Error *err = NULL;
2163
7a4da28b
PX
2164 qmp_migrate(uri, !!blk, blk, !!inc, inc,
2165 false, false, true, resume, &err);
e1c37d0e 2166 if (err) {
187c6147 2167 hmp_handle_error(mon, err);
e1c37d0e
LC
2168 return;
2169 }
2170
2171 if (!detach) {
e49f35bd 2172 HMPMigrationStatus *status;
e1c37d0e
LC
2173
2174 if (monitor_suspend(mon) < 0) {
2175 monitor_printf(mon, "terminal does not allow synchronous "
2176 "migration, continuing detached\n");
2177 return;
2178 }
2179
2180 status = g_malloc0(sizeof(*status));
2181 status->mon = mon;
2182 status->is_block_migration = blk || inc;
bc72ad67 2183 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
e1c37d0e 2184 status);
bc72ad67 2185 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
e1c37d0e
LC
2186 }
2187}
a15fef21 2188
928059a3
LC
2189void hmp_netdev_add(Monitor *mon, const QDict *qdict)
2190{
2191 Error *err = NULL;
2192 QemuOpts *opts;
2193
2194 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
84d18f06 2195 if (err) {
928059a3
LC
2196 goto out;
2197 }
2198
2199 netdev_add(opts, &err);
84d18f06 2200 if (err) {
928059a3
LC
2201 qemu_opts_del(opts);
2202 }
2203
2204out:
187c6147 2205 hmp_handle_error(mon, err);
928059a3 2206}
5f964155
LC
2207
2208void hmp_netdev_del(Monitor *mon, const QDict *qdict)
2209{
2210 const char *id = qdict_get_str(qdict, "id");
2211 Error *err = NULL;
2212
2213 qmp_netdev_del(id, &err);
187c6147 2214 hmp_handle_error(mon, err);
5f964155 2215}
208c9d1b 2216
cff8b2c6
PB
2217void hmp_object_add(Monitor *mon, const QDict *qdict)
2218{
2219 Error *err = NULL;
2220 QemuOpts *opts;
90998d58 2221 Object *obj = NULL;
cff8b2c6
PB
2222
2223 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
2224 if (err) {
187c6147 2225 hmp_handle_error(mon, err);
90998d58 2226 return;
cff8b2c6
PB
2227 }
2228
3a464105 2229 obj = user_creatable_add_opts(opts, &err);
90998d58 2230 qemu_opts_del(opts);
cff8b2c6 2231
cff8b2c6 2232 if (err) {
187c6147 2233 hmp_handle_error(mon, err);
cff8b2c6 2234 }
90998d58
DB
2235 if (obj) {
2236 object_unref(obj);
cff8b2c6 2237 }
cff8b2c6
PB
2238}
2239
208c9d1b
CB
2240void hmp_getfd(Monitor *mon, const QDict *qdict)
2241{
2242 const char *fdname = qdict_get_str(qdict, "fdname");
e940f543 2243 Error *err = NULL;
208c9d1b 2244
e940f543 2245 qmp_getfd(fdname, &err);
187c6147 2246 hmp_handle_error(mon, err);
208c9d1b
CB
2247}
2248
2249void hmp_closefd(Monitor *mon, const QDict *qdict)
2250{
2251 const char *fdname = qdict_get_str(qdict, "fdname");
e940f543 2252 Error *err = NULL;
208c9d1b 2253
e940f543 2254 qmp_closefd(fdname, &err);
187c6147 2255 hmp_handle_error(mon, err);
208c9d1b 2256}
e4c8f004 2257
3e5a50d6 2258void hmp_sendkey(Monitor *mon, const QDict *qdict)
e4c8f004
AK
2259{
2260 const char *keys = qdict_get_str(qdict, "keys");
9f328977 2261 KeyValueList *keylist, *head = NULL, *tmp = NULL;
e4c8f004
AK
2262 int has_hold_time = qdict_haskey(qdict, "hold-time");
2263 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
2264 Error *err = NULL;
5c99fa37 2265 const char *separator;
9f328977 2266 int keyname_len;
e4c8f004
AK
2267
2268 while (1) {
5c99fa37
KF
2269 separator = qemu_strchrnul(keys, '-');
2270 keyname_len = separator - keys;
e4c8f004
AK
2271
2272 /* Be compatible with old interface, convert user inputted "<" */
64ffbe04
WB
2273 if (keys[0] == '<' && keyname_len == 1) {
2274 keys = "less";
e4c8f004
AK
2275 keyname_len = 4;
2276 }
e4c8f004 2277
e4c8f004 2278 keylist = g_malloc0(sizeof(*keylist));
9f328977 2279 keylist->value = g_malloc0(sizeof(*keylist->value));
e4c8f004
AK
2280
2281 if (!head) {
2282 head = keylist;
2283 }
2284 if (tmp) {
2285 tmp->next = keylist;
2286 }
2287 tmp = keylist;
2288
64ffbe04 2289 if (strstart(keys, "0x", NULL)) {
9f328977 2290 char *endp;
64ffbe04
WB
2291 int value = strtoul(keys, &endp, 0);
2292 assert(endp <= keys + keyname_len);
2293 if (endp != keys + keyname_len) {
9f328977
LC
2294 goto err_out;
2295 }
568c73a4 2296 keylist->value->type = KEY_VALUE_KIND_NUMBER;
32bafa8f 2297 keylist->value->u.number.data = value;
9f328977 2298 } else {
64ffbe04 2299 int idx = index_from_key(keys, keyname_len);
7fb1cf16 2300 if (idx == Q_KEY_CODE__MAX) {
9f328977
LC
2301 goto err_out;
2302 }
568c73a4 2303 keylist->value->type = KEY_VALUE_KIND_QCODE;
32bafa8f 2304 keylist->value->u.qcode.data = idx;
9f328977
LC
2305 }
2306
5c99fa37 2307 if (!*separator) {
e4c8f004
AK
2308 break;
2309 }
2310 keys = separator + 1;
2311 }
2312
9f328977 2313 qmp_send_key(head, has_hold_time, hold_time, &err);
187c6147 2314 hmp_handle_error(mon, err);
9f328977
LC
2315
2316out:
2317 qapi_free_KeyValueList(head);
2318 return;
2319
2320err_out:
64ffbe04 2321 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
9f328977 2322 goto out;
e4c8f004 2323}
ad39cf6d 2324
3e5a50d6 2325void hmp_screendump(Monitor *mon, const QDict *qdict)
ad39cf6d
LC
2326{
2327 const char *filename = qdict_get_str(qdict, "filename");
f771c544
TH
2328 const char *id = qdict_get_try_str(qdict, "device");
2329 int64_t head = qdict_get_try_int(qdict, "head", 0);
ad39cf6d
LC
2330 Error *err = NULL;
2331
f771c544 2332 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
187c6147 2333 hmp_handle_error(mon, err);
ad39cf6d 2334}
4057725f
PB
2335
2336void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
2337{
2338 const char *uri = qdict_get_str(qdict, "uri");
34acbc95
EB
2339 bool writable = qdict_get_try_bool(qdict, "writable", false);
2340 bool all = qdict_get_try_bool(qdict, "all", false);
4057725f
PB
2341 Error *local_err = NULL;
2342 BlockInfoList *block_list, *info;
bd269ebc 2343 SocketAddress *addr;
c62d24e9 2344 BlockExportNbd export;
4057725f
PB
2345
2346 if (writable && !all) {
2347 error_setg(&local_err, "-w only valid together with -a");
2348 goto exit;
2349 }
2350
2351 /* First check if the address is valid and start the server. */
2352 addr = socket_parse(uri, &local_err);
2353 if (local_err != NULL) {
2354 goto exit;
2355 }
2356
00019455 2357 nbd_server_start(addr, NULL, NULL, &local_err);
bd269ebc 2358 qapi_free_SocketAddress(addr);
4057725f
PB
2359 if (local_err != NULL) {
2360 goto exit;
2361 }
2362
2363 if (!all) {
2364 return;
2365 }
2366
2367 /* Then try adding all block devices. If one fails, close all and
2368 * exit.
2369 */
2370 block_list = qmp_query_block(NULL);
2371
2372 for (info = block_list; info; info = info->next) {
2373 if (!info->value->has_inserted) {
2374 continue;
2375 }
2376
c62d24e9
KW
2377 export = (BlockExportNbd) {
2378 .device = info->value->device,
2379 .has_writable = true,
2380 .writable = writable,
2381 };
2382
2383 qmp_nbd_server_add(&export, &local_err);
4057725f
PB
2384
2385 if (local_err != NULL) {
2386 qmp_nbd_server_stop(NULL);
2387 break;
2388 }
2389 }
2390
2391 qapi_free_BlockInfoList(block_list);
2392
2393exit:
187c6147 2394 hmp_handle_error(mon, local_err);
4057725f
PB
2395}
2396
2397void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
2398{
2399 const char *device = qdict_get_str(qdict, "device");
dba49323 2400 const char *name = qdict_get_try_str(qdict, "name");
34acbc95 2401 bool writable = qdict_get_try_bool(qdict, "writable", false);
4057725f
PB
2402 Error *local_err = NULL;
2403
c62d24e9
KW
2404 BlockExportNbd export = {
2405 .device = (char *) device,
2406 .has_name = !!name,
2407 .name = (char *) name,
2408 .has_writable = true,
2409 .writable = writable,
2410 };
2411
2412 qmp_nbd_server_add(&export, &local_err);
187c6147 2413 hmp_handle_error(mon, local_err);
08fb10a7 2414}
4057725f 2415
08fb10a7
EB
2416void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict)
2417{
2418 const char *name = qdict_get_str(qdict, "name");
2419 bool force = qdict_get_try_bool(qdict, "force", false);
2420 Error *err = NULL;
2421
2422 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
2423 qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err);
187c6147 2424 hmp_handle_error(mon, err);
4057725f
PB
2425}
2426
2427void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
2428{
e940f543 2429 Error *err = NULL;
4057725f 2430
e940f543 2431 qmp_nbd_server_stop(&err);
187c6147 2432 hmp_handle_error(mon, err);
4057725f 2433}
f1088908
GH
2434
2435void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2436{
2437 const char *args = qdict_get_str(qdict, "args");
2438 Error *err = NULL;
2439 QemuOpts *opts;
2440
70b94331 2441 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
f1088908 2442 if (opts == NULL) {
312fd5f2 2443 error_setg(&err, "Parsing chardev args failed");
f1088908 2444 } else {
4ad6f6cb 2445 qemu_chr_new_from_opts(opts, NULL, &err);
0a73336d 2446 qemu_opts_del(opts);
f1088908 2447 }
187c6147 2448 hmp_handle_error(mon, err);
f1088908
GH
2449}
2450
75b60160
AN
2451void hmp_chardev_change(Monitor *mon, const QDict *qdict)
2452{
2453 const char *args = qdict_get_str(qdict, "args");
2454 const char *id;
2455 Error *err = NULL;
2456 ChardevBackend *backend = NULL;
2457 ChardevReturn *ret = NULL;
2458 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
2459 true);
2460 if (!opts) {
2461 error_setg(&err, "Parsing chardev args failed");
2462 goto end;
2463 }
2464
2465 id = qdict_get_str(qdict, "id");
2466 if (qemu_opts_id(opts)) {
2467 error_setg(&err, "Unexpected 'id' parameter");
2468 goto end;
2469 }
2470
2471 backend = qemu_chr_parse_opts(opts, &err);
2472 if (!backend) {
2473 goto end;
2474 }
2475
2476 ret = qmp_chardev_change(id, backend, &err);
2477
2478end:
2479 qapi_free_ChardevReturn(ret);
2480 qapi_free_ChardevBackend(backend);
2481 qemu_opts_del(opts);
187c6147 2482 hmp_handle_error(mon, err);
75b60160
AN
2483}
2484
f1088908
GH
2485void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2486{
2487 Error *local_err = NULL;
2488
2489 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
187c6147 2490 hmp_handle_error(mon, local_err);
f1088908 2491}
587da2c3 2492
bd1d5ad9
SF
2493void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
2494{
2495 Error *local_err = NULL;
2496
2497 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
187c6147 2498 hmp_handle_error(mon, local_err);
bd1d5ad9
SF
2499}
2500
587da2c3
KW
2501void hmp_qemu_io(Monitor *mon, const QDict *qdict)
2502{
4c7b7e9b 2503 BlockBackend *blk;
e7f98f2f 2504 BlockBackend *local_blk = NULL;
89b6fc45 2505 bool qdev = qdict_get_try_bool(qdict, "qdev", false);
587da2c3
KW
2506 const char* device = qdict_get_str(qdict, "device");
2507 const char* command = qdict_get_str(qdict, "command");
2508 Error *err = NULL;
d7086422 2509 int ret;
587da2c3 2510
89b6fc45
KW
2511 if (qdev) {
2512 blk = blk_by_qdev_id(device, &err);
2513 if (!blk) {
2514 goto fail;
2515 }
2516 } else {
2517 blk = blk_by_name(device);
2518 if (!blk) {
2519 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
2520 if (bs) {
2521 blk = local_blk = blk_new(bdrv_get_aio_context(bs),
2522 0, BLK_PERM_ALL);
2523 ret = blk_insert_bs(blk, bs, &err);
2524 if (ret < 0) {
2525 goto fail;
2526 }
2527 } else {
d7086422
KW
2528 goto fail;
2529 }
e7f98f2f
KW
2530 }
2531 }
2532
887354bd
KW
2533 /*
2534 * Notably absent: Proper permission management. This is sad, but it seems
2535 * almost impossible to achieve without changing the semantics and thereby
2536 * limiting the use cases of the qemu-io HMP command.
2537 *
2538 * In an ideal world we would unconditionally create a new BlockBackend for
2539 * qemuio_command(), but we have commands like 'reopen' and want them to
2540 * take effect on the exact BlockBackend whose name the user passed instead
2541 * of just on a temporary copy of it.
2542 *
2543 * Another problem is that deleting the temporary BlockBackend involves
2544 * draining all requests on it first, but some qemu-iotests cases want to
2545 * issue multiple aio_read/write requests and expect them to complete in
2546 * the background while the monitor has already returned.
2547 *
2548 * This is also what prevents us from saving the original permissions and
2549 * restoring them later: We can't revoke permissions until all requests
2550 * have completed, and we don't know when that is nor can we really let
2551 * anything else run before we have revoken them to avoid race conditions.
2552 *
2553 * What happens now is that command() in qemu-io-cmds.c can extend the
2554 * permissions if necessary for the qemu-io command. And they simply stay
2555 * extended, possibly resulting in a read-only guest device keeping write
2556 * permissions. Ugly, but it appears to be the lesser evil.
2557 */
1813d330 2558 qemuio_command(blk, command);
587da2c3 2559
e7f98f2f
KW
2560fail:
2561 blk_unref(local_blk);
187c6147 2562 hmp_handle_error(mon, err);
587da2c3 2563}
ab2d0531
PB
2564
2565void hmp_object_del(Monitor *mon, const QDict *qdict)
2566{
2567 const char *id = qdict_get_str(qdict, "id");
2568 Error *err = NULL;
2569
90998d58 2570 user_creatable_del(id, &err);
187c6147 2571 hmp_handle_error(mon, err);
ab2d0531 2572}
eb1539b2 2573
a631892f
ZG
2574void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2575{
2576 Error *err = NULL;
2577 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2578 MemoryDeviceInfoList *info;
d766b22b 2579 VirtioPMEMDeviceInfo *vpi;
a631892f
ZG
2580 MemoryDeviceInfo *value;
2581 PCDIMMDeviceInfo *di;
2582
2583 for (info = info_list; info; info = info->next) {
2584 value = info->value;
2585
2586 if (value) {
1fd5d4fe 2587 switch (value->type) {
a631892f 2588 case MEMORY_DEVICE_INFO_KIND_DIMM:
6388e18d 2589 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
d766b22b
DH
2590 di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ?
2591 value->u.dimm.data : value->u.nvdimm.data;
a631892f 2592 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
977c736f 2593 MemoryDeviceInfoKind_str(value->type),
a631892f
ZG
2594 di->id ? di->id : "");
2595 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2596 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2597 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2598 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2599 monitor_printf(mon, " memdev: %s\n", di->memdev);
2600 monitor_printf(mon, " hotplugged: %s\n",
2601 di->hotplugged ? "true" : "false");
2602 monitor_printf(mon, " hotpluggable: %s\n",
2603 di->hotpluggable ? "true" : "false");
d766b22b
DH
2604 break;
2605 case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM:
2606 vpi = value->u.virtio_pmem.data;
2607 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2608 MemoryDeviceInfoKind_str(value->type),
2609 vpi->id ? vpi->id : "");
2610 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->memaddr);
2611 monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size);
2612 monitor_printf(mon, " memdev: %s\n", vpi->memdev);
2613 break;
2614 default:
2615 g_assert_not_reached();
a631892f
ZG
2616 }
2617 }
2618 }
2619
2620 qapi_free_MemoryDeviceInfoList(info_list);
187c6147 2621 hmp_handle_error(mon, err);
a631892f 2622}
89d7fa9e 2623
62313160
TW
2624void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2625{
2626 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2627 IOThreadInfoList *info;
5fc00480 2628 IOThreadInfo *value;
62313160
TW
2629
2630 for (info = info_list; info; info = info->next) {
5fc00480
PH
2631 value = info->value;
2632 monitor_printf(mon, "%s:\n", value->id);
2633 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
2634 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2635 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
2636 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
62313160
TW
2637 }
2638
2639 qapi_free_IOThreadInfoList(info_list);
2640}
2641
fafa4d50
SF
2642void hmp_rocker(Monitor *mon, const QDict *qdict)
2643{
2644 const char *name = qdict_get_str(qdict, "name");
2645 RockerSwitch *rocker;
533fdaed 2646 Error *err = NULL;
fafa4d50 2647
533fdaed
MA
2648 rocker = qmp_query_rocker(name, &err);
2649 if (err != NULL) {
187c6147 2650 hmp_handle_error(mon, err);
fafa4d50
SF
2651 return;
2652 }
2653
2654 monitor_printf(mon, "name: %s\n", rocker->name);
2655 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2656 monitor_printf(mon, "ports: %d\n", rocker->ports);
2657
2658 qapi_free_RockerSwitch(rocker);
2659}
2660
2661void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2662{
2663 RockerPortList *list, *port;
2664 const char *name = qdict_get_str(qdict, "name");
533fdaed 2665 Error *err = NULL;
fafa4d50 2666
533fdaed
MA
2667 list = qmp_query_rocker_ports(name, &err);
2668 if (err != NULL) {
187c6147 2669 hmp_handle_error(mon, err);
fafa4d50
SF
2670 return;
2671 }
2672
2673 monitor_printf(mon, " ena/ speed/ auto\n");
2674 monitor_printf(mon, " port link duplex neg?\n");
2675
2676 for (port = list; port; port = port->next) {
2677 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2678 port->value->name,
2679 port->value->enabled ? port->value->link_up ?
2680 "up" : "down" : "!ena",
2681 port->value->speed == 10000 ? "10G" : "??",
2682 port->value->duplex ? "FD" : "HD",
2683 port->value->autoneg ? "Yes" : "No");
2684 }
2685
2686 qapi_free_RockerPortList(list);
2687}
2688
2689void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2690{
2691 RockerOfDpaFlowList *list, *info;
2692 const char *name = qdict_get_str(qdict, "name");
2693 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
533fdaed 2694 Error *err = NULL;
fafa4d50 2695
533fdaed
MA
2696 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2697 if (err != NULL) {
187c6147 2698 hmp_handle_error(mon, err);
fafa4d50
SF
2699 return;
2700 }
2701
2702 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2703
2704 for (info = list; info; info = info->next) {
2705 RockerOfDpaFlow *flow = info->value;
2706 RockerOfDpaFlowKey *key = flow->key;
2707 RockerOfDpaFlowMask *mask = flow->mask;
2708 RockerOfDpaFlowAction *action = flow->action;
2709
2710 if (flow->hits) {
2711 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2712 key->priority, key->tbl_id, flow->hits);
2713 } else {
2714 monitor_printf(mon, "%-4d %-3d ",
2715 key->priority, key->tbl_id);
2716 }
2717
2718 if (key->has_in_pport) {
2719 monitor_printf(mon, " pport %d", key->in_pport);
2720 if (mask->has_in_pport) {
2721 monitor_printf(mon, "(0x%x)", mask->in_pport);
2722 }
2723 }
2724
2725 if (key->has_vlan_id) {
2726 monitor_printf(mon, " vlan %d",
2727 key->vlan_id & VLAN_VID_MASK);
2728 if (mask->has_vlan_id) {
2729 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2730 }
2731 }
2732
2733 if (key->has_tunnel_id) {
2734 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2735 if (mask->has_tunnel_id) {
2736 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2737 }
2738 }
2739
2740 if (key->has_eth_type) {
2741 switch (key->eth_type) {
2742 case 0x0806:
2743 monitor_printf(mon, " ARP");
2744 break;
2745 case 0x0800:
2746 monitor_printf(mon, " IP");
2747 break;
2748 case 0x86dd:
2749 monitor_printf(mon, " IPv6");
2750 break;
2751 case 0x8809:
2752 monitor_printf(mon, " LACP");
2753 break;
2754 case 0x88cc:
2755 monitor_printf(mon, " LLDP");
2756 break;
2757 default:
2758 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2759 break;
2760 }
2761 }
2762
2763 if (key->has_eth_src) {
2764 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2765 (mask->has_eth_src) &&
2766 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2767 monitor_printf(mon, " src <any mcast/bcast>");
2768 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2769 (mask->has_eth_src) &&
2770 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2771 monitor_printf(mon, " src <any ucast>");
2772 } else {
2773 monitor_printf(mon, " src %s", key->eth_src);
2774 if (mask->has_eth_src) {
2775 monitor_printf(mon, "(%s)", mask->eth_src);
2776 }
2777 }
2778 }
2779
2780 if (key->has_eth_dst) {
2781 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2782 (mask->has_eth_dst) &&
2783 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2784 monitor_printf(mon, " dst <any mcast/bcast>");
2785 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2786 (mask->has_eth_dst) &&
2787 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2788 monitor_printf(mon, " dst <any ucast>");
2789 } else {
2790 monitor_printf(mon, " dst %s", key->eth_dst);
2791 if (mask->has_eth_dst) {
2792 monitor_printf(mon, "(%s)", mask->eth_dst);
2793 }
2794 }
2795 }
2796
2797 if (key->has_ip_proto) {
2798 monitor_printf(mon, " proto %d", key->ip_proto);
2799 if (mask->has_ip_proto) {
2800 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2801 }
2802 }
2803
2804 if (key->has_ip_tos) {
2805 monitor_printf(mon, " TOS %d", key->ip_tos);
2806 if (mask->has_ip_tos) {
2807 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2808 }
2809 }
2810
2811 if (key->has_ip_dst) {
2812 monitor_printf(mon, " dst %s", key->ip_dst);
2813 }
2814
2815 if (action->has_goto_tbl || action->has_group_id ||
2816 action->has_new_vlan_id) {
2817 monitor_printf(mon, " -->");
2818 }
2819
2820 if (action->has_new_vlan_id) {
2821 monitor_printf(mon, " apply new vlan %d",
2822 ntohs(action->new_vlan_id));
2823 }
2824
2825 if (action->has_group_id) {
2826 monitor_printf(mon, " write group 0x%08x", action->group_id);
2827 }
2828
2829 if (action->has_goto_tbl) {
2830 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2831 }
2832
2833 monitor_printf(mon, "\n");
2834 }
2835
2836 qapi_free_RockerOfDpaFlowList(list);
2837}
2838
2839void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2840{
2841 RockerOfDpaGroupList *list, *g;
2842 const char *name = qdict_get_str(qdict, "name");
2843 uint8_t type = qdict_get_try_int(qdict, "type", 9);
533fdaed 2844 Error *err = NULL;
fafa4d50
SF
2845 bool set = false;
2846
533fdaed
MA
2847 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2848 if (err != NULL) {
187c6147 2849 hmp_handle_error(mon, err);
fafa4d50
SF
2850 return;
2851 }
2852
2853 monitor_printf(mon, "id (decode) --> buckets\n");
2854
2855 for (g = list; g; g = g->next) {
2856 RockerOfDpaGroup *group = g->value;
2857
2858 monitor_printf(mon, "0x%08x", group->id);
2859
2860 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2861 group->type == 1 ? "L2 rewrite" :
2862 group->type == 2 ? "L3 unicast" :
2863 group->type == 3 ? "L2 multicast" :
2864 group->type == 4 ? "L2 flood" :
2865 group->type == 5 ? "L3 interface" :
2866 group->type == 6 ? "L3 multicast" :
2867 group->type == 7 ? "L3 ECMP" :
2868 group->type == 8 ? "L2 overlay" :
2869 "unknown");
2870
2871 if (group->has_vlan_id) {
2872 monitor_printf(mon, " vlan %d", group->vlan_id);
2873 }
2874
2875 if (group->has_pport) {
2876 monitor_printf(mon, " pport %d", group->pport);
2877 }
2878
2879 if (group->has_index) {
2880 monitor_printf(mon, " index %d", group->index);
2881 }
2882
2883 monitor_printf(mon, ") -->");
2884
2885 if (group->has_set_vlan_id && group->set_vlan_id) {
2886 set = true;
2887 monitor_printf(mon, " set vlan %d",
2888 group->set_vlan_id & VLAN_VID_MASK);
2889 }
2890
2891 if (group->has_set_eth_src) {
2892 if (!set) {
2893 set = true;
2894 monitor_printf(mon, " set");
2895 }
2896 monitor_printf(mon, " src %s", group->set_eth_src);
2897 }
2898
2899 if (group->has_set_eth_dst) {
2900 if (!set) {
2901 set = true;
2902 monitor_printf(mon, " set");
2903 }
2904 monitor_printf(mon, " dst %s", group->set_eth_dst);
2905 }
2906
2907 set = false;
2908
2909 if (group->has_ttl_check && group->ttl_check) {
2910 monitor_printf(mon, " check TTL");
2911 }
2912
2913 if (group->has_group_id && group->group_id) {
2914 monitor_printf(mon, " group id 0x%08x", group->group_id);
2915 }
2916
2917 if (group->has_pop_vlan && group->pop_vlan) {
2918 monitor_printf(mon, " pop vlan");
2919 }
2920
2921 if (group->has_out_pport) {
2922 monitor_printf(mon, " out pport %d", group->out_pport);
2923 }
2924
2925 if (group->has_group_ids) {
2926 struct uint32List *id;
2927
2928 monitor_printf(mon, " groups [");
2929 for (id = group->group_ids; id; id = id->next) {
2930 monitor_printf(mon, "0x%08x", id->value);
2931 if (id->next) {
2932 monitor_printf(mon, ",");
2933 }
2934 }
2935 monitor_printf(mon, "]");
2936 }
2937
2938 monitor_printf(mon, "\n");
2939 }
2940
2941 qapi_free_RockerOfDpaGroupList(list);
2942}
4a6b52d6 2943
be9b23c4
PX
2944void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
2945{
2946 ram_block_dump(mon);
2947}
2948
39164c13
IM
2949void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
2950{
72d9196f
BW
2951 Error *err = NULL;
2952 GuidInfo *info = qmp_query_vm_generation_id(&err);
39164c13
IM
2953 if (info) {
2954 monitor_printf(mon, "%s\n", info->guid);
2955 }
187c6147 2956 hmp_handle_error(mon, err);
39164c13
IM
2957 qapi_free_GuidInfo(info);
2958}
d0f63c1e
VG
2959
2960void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
2961{
2962 Error *err = NULL;
2963 MemoryInfo *info = qmp_query_memory_size_summary(&err);
2964 if (info) {
2965 monitor_printf(mon, "base memory: %" PRIu64 "\n",
2966 info->base_memory);
2967
2968 if (info->has_plugged_memory) {
2969 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
2970 info->plugged_memory);
2971 }
2972
2973 qapi_free_MemoryInfo(info);
2974 }
187c6147 2975 hmp_handle_error(mon, err);
d0f63c1e 2976}