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