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