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