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