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