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