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