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