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