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