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