]> git.proxmox.com Git - mirror_qemu.git/blame - hmp.c
virtio-balloon: convert VMSTATE_VIRTIO_DEVICE
[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"
dccfcd0e 20#include "sysemu/char.h"
4c7b7e9b 21#include "sysemu/block-backend.h"
1de7afc9
PB
22#include "qemu/option.h"
23#include "qemu/timer.h"
48a32bed 24#include "qmp-commands.h"
1de7afc9 25#include "qemu/sockets.h"
83c9089e 26#include "monitor/monitor.h"
318660f8 27#include "monitor/qdev.h"
cff8b2c6 28#include "qapi/opts-visitor.h"
cc7a8ea7 29#include "qapi/qmp/qerror.h"
eb1539b2 30#include "qapi/string-output-visitor.h"
baead0ab 31#include "qapi/util.h"
eb1539b2 32#include "qapi-visit.h"
90998d58 33#include "qom/object_interfaces.h"
28ecbaee 34#include "ui/console.h"
bd093a36 35#include "block/qapi.h"
587da2c3 36#include "qemu-io.h"
f348b6d1 37#include "qemu/cutils.h"
d59ce6f3 38#include "qemu/error-report.h"
48a32bed 39
22fa7da0
CR
40#ifdef CONFIG_SPICE
41#include <spice/enums.h>
42#endif
43
0cfd6a9a
LC
44static void hmp_handle_error(Monitor *mon, Error **errp)
45{
415168e0
MA
46 assert(errp);
47 if (*errp) {
193227f9 48 error_report_err(*errp);
0cfd6a9a
LC
49 }
50}
51
84f2d0ea 52void hmp_info_name(Monitor *mon, const QDict *qdict)
48a32bed
AL
53{
54 NameInfo *info;
55
56 info = qmp_query_name(NULL);
57 if (info->has_name) {
58 monitor_printf(mon, "%s\n", info->name);
59 }
60 qapi_free_NameInfo(info);
61}
b9c15f16 62
84f2d0ea 63void hmp_info_version(Monitor *mon, const QDict *qdict)
b9c15f16
LC
64{
65 VersionInfo *info;
66
67 info = qmp_query_version(NULL);
68
69 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
4752cdbb 70 info->qemu->major, info->qemu->minor, info->qemu->micro,
b9c15f16
LC
71 info->package);
72
73 qapi_free_VersionInfo(info);
74}
292a2602 75
84f2d0ea 76void hmp_info_kvm(Monitor *mon, const QDict *qdict)
292a2602
LC
77{
78 KvmInfo *info;
79
80 info = qmp_query_kvm(NULL);
81 monitor_printf(mon, "kvm support: ");
82 if (info->present) {
83 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
84 } else {
85 monitor_printf(mon, "not compiled\n");
86 }
87
88 qapi_free_KvmInfo(info);
89}
90
84f2d0ea 91void hmp_info_status(Monitor *mon, const QDict *qdict)
1fa9a5e4
LC
92{
93 StatusInfo *info;
94
95 info = qmp_query_status(NULL);
96
97 monitor_printf(mon, "VM status: %s%s",
98 info->running ? "running" : "paused",
99 info->singlestep ? " (single step mode)" : "");
100
101 if (!info->running && info->status != RUN_STATE_PAUSED) {
102 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
103 }
104
105 monitor_printf(mon, "\n");
106
107 qapi_free_StatusInfo(info);
108}
109
84f2d0ea 110void hmp_info_uuid(Monitor *mon, const QDict *qdict)
efab767e
LC
111{
112 UuidInfo *info;
113
114 info = qmp_query_uuid(NULL);
115 monitor_printf(mon, "%s\n", info->UUID);
116 qapi_free_UuidInfo(info);
117}
c5a415a0 118
84f2d0ea 119void hmp_info_chardev(Monitor *mon, const QDict *qdict)
c5a415a0
LC
120{
121 ChardevInfoList *char_info, *info;
122
123 char_info = qmp_query_chardev(NULL);
124 for (info = char_info; info; info = info->next) {
125 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
126 info->value->filename);
127 }
128
129 qapi_free_ChardevInfoList(char_info);
130}
7a7f325e 131
84f2d0ea 132void hmp_info_mice(Monitor *mon, const QDict *qdict)
e235cec3
LC
133{
134 MouseInfoList *mice_list, *mouse;
135
136 mice_list = qmp_query_mice(NULL);
137 if (!mice_list) {
138 monitor_printf(mon, "No mouse devices connected\n");
139 return;
140 }
141
142 for (mouse = mice_list; mouse; mouse = mouse->next) {
143 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
144 mouse->value->current ? '*' : ' ',
145 mouse->value->index, mouse->value->name,
146 mouse->value->absolute ? " (absolute)" : "");
147 }
148
149 qapi_free_MouseInfoList(mice_list);
150}
151
84f2d0ea 152void hmp_info_migrate(Monitor *mon, const QDict *qdict)
791e7c82
LC
153{
154 MigrationInfo *info;
bbf6da32 155 MigrationCapabilityStatusList *caps, *cap;
791e7c82
LC
156
157 info = qmp_query_migrate(NULL);
bbf6da32
OW
158 caps = qmp_query_migrate_capabilities(NULL);
159
160 /* do not display parameters during setup */
161 if (info->has_status && caps) {
162 monitor_printf(mon, "capabilities: ");
163 for (cap = caps; cap; cap = cap->next) {
164 monitor_printf(mon, "%s: %s ",
165 MigrationCapability_lookup[cap->value->capability],
166 cap->value->state ? "on" : "off");
167 }
168 monitor_printf(mon, "\n");
169 }
791e7c82
LC
170
171 if (info->has_status) {
d59ce6f3 172 monitor_printf(mon, "Migration status: %s",
24b8c39b 173 MigrationStatus_lookup[info->status]);
d59ce6f3
DB
174 if (info->status == MIGRATION_STATUS_FAILED &&
175 info->has_error_desc) {
176 monitor_printf(mon, " (%s)\n", info->error_desc);
177 } else {
178 monitor_printf(mon, "\n");
179 }
180
7aa939af
JQ
181 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
182 info->total_time);
2c52ddf1
JQ
183 if (info->has_expected_downtime) {
184 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
185 info->expected_downtime);
186 }
9c5a9fcf
JQ
187 if (info->has_downtime) {
188 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
189 info->downtime);
190 }
ed4fbd10
MH
191 if (info->has_setup_time) {
192 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
193 info->setup_time);
194 }
791e7c82
LC
195 }
196
197 if (info->has_ram) {
198 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
199 info->ram->transferred >> 10);
7e114f8c
MH
200 monitor_printf(mon, "throughput: %0.2f mbps\n",
201 info->ram->mbps);
791e7c82
LC
202 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
203 info->ram->remaining >> 10);
204 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
205 info->ram->total >> 10);
004d4c10
OW
206 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
207 info->ram->duplicate);
f1c72795
PL
208 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
209 info->ram->skipped);
004d4c10
OW
210 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
211 info->ram->normal);
212 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
213 info->ram->normal_bytes >> 10);
58570ed8
C
214 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
215 info->ram->dirty_sync_count);
8d017193
JQ
216 if (info->ram->dirty_pages_rate) {
217 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
218 info->ram->dirty_pages_rate);
219 }
d3bf5418
DDAG
220 if (info->ram->postcopy_requests) {
221 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
222 info->ram->postcopy_requests);
223 }
791e7c82
LC
224 }
225
226 if (info->has_disk) {
227 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
228 info->disk->transferred >> 10);
229 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
230 info->disk->remaining >> 10);
231 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
232 info->disk->total >> 10);
233 }
234
f36d55af
OW
235 if (info->has_xbzrle_cache) {
236 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
237 info->xbzrle_cache->cache_size);
238 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
239 info->xbzrle_cache->bytes >> 10);
240 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
241 info->xbzrle_cache->pages);
242 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
243 info->xbzrle_cache->cache_miss);
8bc39233
C
244 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
245 info->xbzrle_cache->cache_miss_rate);
f36d55af
OW
246 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
247 info->xbzrle_cache->overflow);
248 }
249
d85a31d1 250 if (info->has_cpu_throttle_percentage) {
4782893e 251 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
d85a31d1 252 info->cpu_throttle_percentage);
4782893e
JH
253 }
254
791e7c82 255 qapi_free_MigrationInfo(info);
bbf6da32
OW
256 qapi_free_MigrationCapabilityStatusList(caps);
257}
258
84f2d0ea 259void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
bbf6da32
OW
260{
261 MigrationCapabilityStatusList *caps, *cap;
262
263 caps = qmp_query_migrate_capabilities(NULL);
264
265 if (caps) {
266 monitor_printf(mon, "capabilities: ");
267 for (cap = caps; cap; cap = cap->next) {
268 monitor_printf(mon, "%s: %s ",
269 MigrationCapability_lookup[cap->value->capability],
270 cap->value->state ? "on" : "off");
271 }
272 monitor_printf(mon, "\n");
273 }
274
275 qapi_free_MigrationCapabilityStatusList(caps);
791e7c82
LC
276}
277
50e9a629
LL
278void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
279{
280 MigrationParameters *params;
281
282 params = qmp_query_migrate_parameters(NULL);
283
284 if (params) {
285 monitor_printf(mon, "parameters:");
286 monitor_printf(mon, " %s: %" PRId64,
287 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_LEVEL],
288 params->compress_level);
289 monitor_printf(mon, " %s: %" PRId64,
290 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_THREADS],
291 params->compress_threads);
292 monitor_printf(mon, " %s: %" PRId64,
293 MigrationParameter_lookup[MIGRATION_PARAMETER_DECOMPRESS_THREADS],
294 params->decompress_threads);
1626fee3 295 monitor_printf(mon, " %s: %" PRId64,
d85a31d1
JH
296 MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL],
297 params->cpu_throttle_initial);
1626fee3 298 monitor_printf(mon, " %s: %" PRId64,
d85a31d1
JH
299 MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT],
300 params->cpu_throttle_increment);
69ef1f36
DB
301 monitor_printf(mon, " %s: '%s'",
302 MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_CREDS],
303 params->tls_creds ? : "");
304 monitor_printf(mon, " %s: '%s'",
305 MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_HOSTNAME],
306 params->tls_hostname ? : "");
50e9a629
LL
307 monitor_printf(mon, "\n");
308 }
309
310 qapi_free_MigrationParameters(params);
311}
312
84f2d0ea 313void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
9e1ba4cc
OW
314{
315 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
316 qmp_query_migrate_cache_size(NULL) >> 10);
317}
318
84f2d0ea 319void hmp_info_cpus(Monitor *mon, const QDict *qdict)
de0b36b6
LC
320{
321 CpuInfoList *cpu_list, *cpu;
322
323 cpu_list = qmp_query_cpus(NULL);
324
325 for (cpu = cpu_list; cpu; cpu = cpu->next) {
326 int active = ' ';
327
328 if (cpu->value->CPU == monitor_get_cpu_index()) {
329 active = '*';
330 }
331
852bef0e 332 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
de0b36b6 333
86f4b687
EB
334 switch (cpu->value->arch) {
335 case CPU_INFO_ARCH_X86:
544a3731 336 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->u.x86.pc);
86f4b687
EB
337 break;
338 case CPU_INFO_ARCH_PPC:
544a3731 339 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->u.ppc.nip);
86f4b687
EB
340 break;
341 case CPU_INFO_ARCH_SPARC:
86ae1911 342 monitor_printf(mon, " pc=0x%016" PRIx64,
544a3731 343 cpu->value->u.q_sparc.pc);
86ae1911 344 monitor_printf(mon, " npc=0x%016" PRIx64,
544a3731 345 cpu->value->u.q_sparc.npc);
86f4b687
EB
346 break;
347 case CPU_INFO_ARCH_MIPS:
544a3731 348 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.q_mips.PC);
86f4b687
EB
349 break;
350 case CPU_INFO_ARCH_TRICORE:
544a3731 351 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.tricore.PC);
86f4b687
EB
352 break;
353 default:
354 break;
de0b36b6
LC
355 }
356
357 if (cpu->value->halted) {
358 monitor_printf(mon, " (halted)");
359 }
360
361 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
362 }
363
364 qapi_free_CpuInfoList(cpu_list);
365}
366
289b276c
KW
367static void print_block_info(Monitor *mon, BlockInfo *info,
368 BlockDeviceInfo *inserted, bool verbose)
b2023818 369{
bd093a36 370 ImageInfo *image_info;
b2023818 371
8d6adccd
KW
372 assert(!info || !info->has_inserted || info->inserted == inserted);
373
374 if (info) {
375 monitor_printf(mon, "%s", info->device);
376 if (inserted && inserted->has_node_name) {
377 monitor_printf(mon, " (%s)", inserted->node_name);
378 }
379 } else {
380 assert(inserted);
381 monitor_printf(mon, "%s",
382 inserted->has_node_name
383 ? inserted->node_name
384 : "<anonymous>");
385 }
386
289b276c
KW
387 if (inserted) {
388 monitor_printf(mon, ": %s (%s%s%s)\n",
389 inserted->file,
390 inserted->drv,
391 inserted->ro ? ", read-only" : "",
392 inserted->encrypted ? ", encrypted" : "");
393 } else {
394 monitor_printf(mon, ": [not inserted]\n");
395 }
b2023818 396
8d6adccd
KW
397 if (info) {
398 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
399 monitor_printf(mon, " I/O status: %s\n",
400 BlockDeviceIoStatus_lookup[info->io_status]);
401 }
b2023818 402
8d6adccd
KW
403 if (info->removable) {
404 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
405 info->locked ? "" : "not ",
406 info->tray_open ? "open" : "closed");
407 }
289b276c 408 }
fbe2e26c 409
b2023818 410
289b276c
KW
411 if (!inserted) {
412 return;
413 }
b2023818 414
289b276c
KW
415 monitor_printf(mon, " Cache mode: %s%s%s\n",
416 inserted->cache->writeback ? "writeback" : "writethrough",
417 inserted->cache->direct ? ", direct" : "",
418 inserted->cache->no_flush ? ", ignore flushes" : "");
419
420 if (inserted->has_backing_file) {
421 monitor_printf(mon,
422 " Backing file: %s "
423 "(chain depth: %" PRId64 ")\n",
424 inserted->backing_file,
425 inserted->backing_file_depth);
426 }
727f005e 427
289b276c
KW
428 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
429 monitor_printf(mon, " Detect zeroes: %s\n",
430 BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]);
431 }
fbe2e26c 432
289b276c
KW
433 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
434 inserted->iops || inserted->iops_rd || inserted->iops_wr)
435 {
436 monitor_printf(mon, " I/O throttling: bps=%" PRId64
437 " bps_rd=%" PRId64 " bps_wr=%" PRId64
438 " bps_max=%" PRId64
439 " bps_rd_max=%" PRId64
440 " bps_wr_max=%" PRId64
441 " iops=%" PRId64 " iops_rd=%" PRId64
442 " iops_wr=%" PRId64
443 " iops_max=%" PRId64
444 " iops_rd_max=%" PRId64
445 " iops_wr_max=%" PRId64
b8fe1694
AG
446 " iops_size=%" PRId64
447 " group=%s\n",
289b276c
KW
448 inserted->bps,
449 inserted->bps_rd,
450 inserted->bps_wr,
451 inserted->bps_max,
452 inserted->bps_rd_max,
453 inserted->bps_wr_max,
454 inserted->iops,
455 inserted->iops_rd,
456 inserted->iops_wr,
457 inserted->iops_max,
458 inserted->iops_rd_max,
459 inserted->iops_wr_max,
b8fe1694
AG
460 inserted->iops_size,
461 inserted->group);
289b276c 462 }
fbe2e26c 463
9419874f 464 if (verbose) {
289b276c
KW
465 monitor_printf(mon, "\nImages:\n");
466 image_info = inserted->image;
467 while (1) {
468 bdrv_image_info_dump((fprintf_function)monitor_printf,
469 mon, image_info);
470 if (image_info->has_backing_image) {
471 image_info = image_info->backing_image;
472 } else {
473 break;
474 }
475 }
476 }
477}
9e193c5a 478
289b276c
KW
479void hmp_info_block(Monitor *mon, const QDict *qdict)
480{
481 BlockInfoList *block_list, *info;
e6bb31ec 482 BlockDeviceInfoList *blockdev_list, *blockdev;
289b276c 483 const char *device = qdict_get_try_str(qdict, "device");
34acbc95
EB
484 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
485 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
e6bb31ec 486 bool printed = false;
9e193c5a 487
e6bb31ec
KW
488 /* Print BlockBackend information */
489 if (!nodes) {
f19e44bc 490 block_list = qmp_query_block(NULL);
e6bb31ec
KW
491 } else {
492 block_list = NULL;
493 }
fbe2e26c 494
289b276c
KW
495 for (info = block_list; info; info = info->next) {
496 if (device && strcmp(device, info->value->device)) {
497 continue;
465bee1d
PL
498 }
499
289b276c
KW
500 if (info != block_list) {
501 monitor_printf(mon, "\n");
fbe2e26c 502 }
bd093a36 503
289b276c
KW
504 print_block_info(mon, info->value, info->value->has_inserted
505 ? info->value->inserted : NULL,
506 verbose);
e6bb31ec 507 printed = true;
b2023818
LC
508 }
509
510 qapi_free_BlockInfoList(block_list);
e6bb31ec
KW
511
512 if ((!device && !nodes) || printed) {
513 return;
514 }
515
516 /* Print node information */
517 blockdev_list = qmp_query_named_block_nodes(NULL);
518 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
519 assert(blockdev->value->has_node_name);
520 if (device && strcmp(device, blockdev->value->node_name)) {
521 continue;
522 }
523
524 if (blockdev != blockdev_list) {
525 monitor_printf(mon, "\n");
526 }
527
528 print_block_info(mon, NULL, blockdev->value, verbose);
529 }
530 qapi_free_BlockDeviceInfoList(blockdev_list);
b2023818
LC
531}
532
84f2d0ea 533void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
f11f57e4
LC
534{
535 BlockStatsList *stats_list, *stats;
536
f71eaa74 537 stats_list = qmp_query_blockstats(false, false, NULL);
f11f57e4
LC
538
539 for (stats = stats_list; stats; stats = stats->next) {
540 if (!stats->value->has_device) {
541 continue;
542 }
543
544 monitor_printf(mon, "%s:", stats->value->device);
545 monitor_printf(mon, " rd_bytes=%" PRId64
546 " wr_bytes=%" PRId64
547 " rd_operations=%" PRId64
548 " wr_operations=%" PRId64
549 " flush_operations=%" PRId64
550 " wr_total_time_ns=%" PRId64
551 " rd_total_time_ns=%" PRId64
552 " flush_total_time_ns=%" PRId64
f4564d53
PL
553 " rd_merged=%" PRId64
554 " wr_merged=%" PRId64
cb38fffb 555 " idle_time_ns=%" PRId64
f11f57e4
LC
556 "\n",
557 stats->value->stats->rd_bytes,
558 stats->value->stats->wr_bytes,
559 stats->value->stats->rd_operations,
560 stats->value->stats->wr_operations,
561 stats->value->stats->flush_operations,
562 stats->value->stats->wr_total_time_ns,
563 stats->value->stats->rd_total_time_ns,
f4564d53
PL
564 stats->value->stats->flush_total_time_ns,
565 stats->value->stats->rd_merged,
cb38fffb
AG
566 stats->value->stats->wr_merged,
567 stats->value->stats->idle_time_ns);
f11f57e4
LC
568 }
569
570 qapi_free_BlockStatsList(stats_list);
571}
572
84f2d0ea 573void hmp_info_vnc(Monitor *mon, const QDict *qdict)
2b54aa87
LC
574{
575 VncInfo *info;
576 Error *err = NULL;
577 VncClientInfoList *client;
578
579 info = qmp_query_vnc(&err);
580 if (err) {
193227f9 581 error_report_err(err);
2b54aa87
LC
582 return;
583 }
584
585 if (!info->enabled) {
586 monitor_printf(mon, "Server: disabled\n");
587 goto out;
588 }
589
590 monitor_printf(mon, "Server:\n");
591 if (info->has_host && info->has_service) {
592 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
593 }
594 if (info->has_auth) {
595 monitor_printf(mon, " auth: %s\n", info->auth);
596 }
597
598 if (!info->has_clients || info->clients == NULL) {
599 monitor_printf(mon, "Client: none\n");
600 } else {
601 for (client = info->clients; client; client = client->next) {
602 monitor_printf(mon, "Client:\n");
603 monitor_printf(mon, " address: %s:%s\n",
ddf21908
EB
604 client->value->host,
605 client->value->service);
2b54aa87
LC
606 monitor_printf(mon, " x509_dname: %s\n",
607 client->value->x509_dname ?
608 client->value->x509_dname : "none");
609 monitor_printf(mon, " username: %s\n",
610 client->value->has_sasl_username ?
611 client->value->sasl_username : "none");
612 }
613 }
614
615out:
616 qapi_free_VncInfo(info);
617}
618
206addd5 619#ifdef CONFIG_SPICE
84f2d0ea 620void hmp_info_spice(Monitor *mon, const QDict *qdict)
d1f29646
LC
621{
622 SpiceChannelList *chan;
623 SpiceInfo *info;
22fa7da0
CR
624 const char *channel_name;
625 const char * const channel_names[] = {
626 [SPICE_CHANNEL_MAIN] = "main",
627 [SPICE_CHANNEL_DISPLAY] = "display",
628 [SPICE_CHANNEL_INPUTS] = "inputs",
629 [SPICE_CHANNEL_CURSOR] = "cursor",
630 [SPICE_CHANNEL_PLAYBACK] = "playback",
631 [SPICE_CHANNEL_RECORD] = "record",
632 [SPICE_CHANNEL_TUNNEL] = "tunnel",
633 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
634 [SPICE_CHANNEL_USBREDIR] = "usbredir",
635 [SPICE_CHANNEL_PORT] = "port",
7c6044a9
GH
636#if 0
637 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
638 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
639 * as quick fix for build failures with older versions. */
22fa7da0 640 [SPICE_CHANNEL_WEBDAV] = "webdav",
7c6044a9 641#endif
22fa7da0 642 };
d1f29646
LC
643
644 info = qmp_query_spice(NULL);
645
646 if (!info->enabled) {
647 monitor_printf(mon, "Server: disabled\n");
648 goto out;
649 }
650
651 monitor_printf(mon, "Server:\n");
652 if (info->has_port) {
653 monitor_printf(mon, " address: %s:%" PRId64 "\n",
654 info->host, info->port);
655 }
656 if (info->has_tls_port) {
657 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
658 info->host, info->tls_port);
659 }
61c4efe2
YH
660 monitor_printf(mon, " migrated: %s\n",
661 info->migrated ? "true" : "false");
d1f29646
LC
662 monitor_printf(mon, " auth: %s\n", info->auth);
663 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
4efee029
AL
664 monitor_printf(mon, " mouse-mode: %s\n",
665 SpiceQueryMouseMode_lookup[info->mouse_mode]);
d1f29646
LC
666
667 if (!info->has_channels || info->channels == NULL) {
668 monitor_printf(mon, "Channels: none\n");
669 } else {
670 for (chan = info->channels; chan; chan = chan->next) {
671 monitor_printf(mon, "Channel:\n");
672 monitor_printf(mon, " address: %s:%s%s\n",
ddf21908 673 chan->value->host, chan->value->port,
d1f29646
LC
674 chan->value->tls ? " [tls]" : "");
675 monitor_printf(mon, " session: %" PRId64 "\n",
676 chan->value->connection_id);
677 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
678 chan->value->channel_type, chan->value->channel_id);
22fa7da0
CR
679
680 channel_name = "unknown";
681 if (chan->value->channel_type > 0 &&
682 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
683 channel_names[chan->value->channel_type]) {
684 channel_name = channel_names[chan->value->channel_type];
685 }
686
687 monitor_printf(mon, " channel name: %s\n", channel_name);
d1f29646
LC
688 }
689 }
690
691out:
692 qapi_free_SpiceInfo(info);
693}
206addd5 694#endif
d1f29646 695
84f2d0ea 696void hmp_info_balloon(Monitor *mon, const QDict *qdict)
96637bcd
LC
697{
698 BalloonInfo *info;
699 Error *err = NULL;
700
701 info = qmp_query_balloon(&err);
702 if (err) {
193227f9 703 error_report_err(err);
96637bcd
LC
704 return;
705 }
706
01ceb97e 707 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
96637bcd
LC
708
709 qapi_free_BalloonInfo(info);
710}
711
79627472
LC
712static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
713{
714 PciMemoryRegionList *region;
715
716 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
717 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
718 dev->slot, dev->function);
719 monitor_printf(mon, " ");
720
9fa02cd1
EB
721 if (dev->class_info->has_desc) {
722 monitor_printf(mon, "%s", dev->class_info->desc);
79627472 723 } else {
9fa02cd1 724 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
79627472
LC
725 }
726
727 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
9fa02cd1 728 dev->id->vendor, dev->id->device);
79627472
LC
729
730 if (dev->has_irq) {
731 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
732 }
733
734 if (dev->has_pci_bridge) {
735 monitor_printf(mon, " BUS %" PRId64 ".\n",
9fa02cd1 736 dev->pci_bridge->bus->number);
79627472 737 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
9fa02cd1 738 dev->pci_bridge->bus->secondary);
79627472 739 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
9fa02cd1 740 dev->pci_bridge->bus->subordinate);
79627472
LC
741
742 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
9fa02cd1
EB
743 dev->pci_bridge->bus->io_range->base,
744 dev->pci_bridge->bus->io_range->limit);
79627472
LC
745
746 monitor_printf(mon,
747 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
9fa02cd1
EB
748 dev->pci_bridge->bus->memory_range->base,
749 dev->pci_bridge->bus->memory_range->limit);
79627472
LC
750
751 monitor_printf(mon, " prefetchable memory range "
752 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
9fa02cd1
EB
753 dev->pci_bridge->bus->prefetchable_range->base,
754 dev->pci_bridge->bus->prefetchable_range->limit);
79627472
LC
755 }
756
757 for (region = dev->regions; region; region = region->next) {
758 uint64_t addr, size;
759
760 addr = region->value->address;
761 size = region->value->size;
762
763 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
764
765 if (!strcmp(region->value->type, "io")) {
766 monitor_printf(mon, "I/O at 0x%04" PRIx64
767 " [0x%04" PRIx64 "].\n",
768 addr, addr + size - 1);
769 } else {
770 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
771 " [0x%08" PRIx64 "].\n",
772 region->value->mem_type_64 ? 64 : 32,
773 region->value->prefetch ? " prefetchable" : "",
774 addr, addr + size - 1);
775 }
776 }
777
778 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
779
780 if (dev->has_pci_bridge) {
781 if (dev->pci_bridge->has_devices) {
782 PciDeviceInfoList *cdev;
783 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
784 hmp_info_pci_device(mon, cdev->value);
785 }
786 }
787 }
788}
789
84f2d0ea 790void hmp_info_pci(Monitor *mon, const QDict *qdict)
79627472 791{
f46cee37 792 PciInfoList *info_list, *info;
79627472
LC
793 Error *err = NULL;
794
f46cee37 795 info_list = qmp_query_pci(&err);
79627472
LC
796 if (err) {
797 monitor_printf(mon, "PCI devices not supported\n");
798 error_free(err);
799 return;
800 }
801
f46cee37 802 for (info = info_list; info; info = info->next) {
79627472
LC
803 PciDeviceInfoList *dev;
804
805 for (dev = info->value->devices; dev; dev = dev->next) {
806 hmp_info_pci_device(mon, dev->value);
807 }
808 }
809
f46cee37 810 qapi_free_PciInfoList(info_list);
79627472
LC
811}
812
84f2d0ea 813void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
fb5458cd
SH
814{
815 BlockJobInfoList *list;
816 Error *err = NULL;
817
818 list = qmp_query_block_jobs(&err);
819 assert(!err);
820
821 if (!list) {
822 monitor_printf(mon, "No active jobs\n");
823 return;
824 }
825
826 while (list) {
827 if (strcmp(list->value->type, "stream") == 0) {
828 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
829 " of %" PRId64 " bytes, speed limit %" PRId64
830 " bytes/s\n",
831 list->value->device,
832 list->value->offset,
833 list->value->len,
834 list->value->speed);
835 } else {
836 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
837 " of %" PRId64 " bytes, speed limit %" PRId64
838 " bytes/s\n",
839 list->value->type,
840 list->value->device,
841 list->value->offset,
842 list->value->len,
843 list->value->speed);
844 }
845 list = list->next;
846 }
93bb1315
GA
847
848 qapi_free_BlockJobInfoList(list);
fb5458cd
SH
849}
850
d1a0cf73
SB
851void hmp_info_tpm(Monitor *mon, const QDict *qdict)
852{
853 TPMInfoList *info_list, *info;
854 Error *err = NULL;
855 unsigned int c = 0;
856 TPMPassthroughOptions *tpo;
857
858 info_list = qmp_query_tpm(&err);
859 if (err) {
860 monitor_printf(mon, "TPM device not supported\n");
861 error_free(err);
862 return;
863 }
864
865 if (info_list) {
866 monitor_printf(mon, "TPM device:\n");
867 }
868
869 for (info = info_list; info; info = info->next) {
870 TPMInfo *ti = info->value;
871 monitor_printf(mon, " tpm%d: model=%s\n",
872 c, TpmModel_lookup[ti->model]);
873
874 monitor_printf(mon, " \\ %s: type=%s",
ce21131a 875 ti->id, TpmTypeOptionsKind_lookup[ti->options->type]);
d1a0cf73 876
ce21131a 877 switch (ti->options->type) {
88ca7bcf 878 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
32bafa8f 879 tpo = ti->options->u.passthrough.data;
d1a0cf73
SB
880 monitor_printf(mon, "%s%s%s%s",
881 tpo->has_path ? ",path=" : "",
882 tpo->has_path ? tpo->path : "",
883 tpo->has_cancel_path ? ",cancel-path=" : "",
884 tpo->has_cancel_path ? tpo->cancel_path : "");
885 break;
7fb1cf16 886 case TPM_TYPE_OPTIONS_KIND__MAX:
d1a0cf73
SB
887 break;
888 }
889 monitor_printf(mon, "\n");
890 c++;
891 }
892 qapi_free_TPMInfoList(info_list);
893}
894
7a7f325e
LC
895void hmp_quit(Monitor *mon, const QDict *qdict)
896{
897 monitor_suspend(mon);
898 qmp_quit(NULL);
899}
5f158f21
LC
900
901void hmp_stop(Monitor *mon, const QDict *qdict)
902{
903 qmp_stop(NULL);
904}
38d22653
LC
905
906void hmp_system_reset(Monitor *mon, const QDict *qdict)
907{
908 qmp_system_reset(NULL);
909}
5bc465e4
LC
910
911void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
912{
913 qmp_system_powerdown(NULL);
914}
755f1968
LC
915
916void hmp_cpu(Monitor *mon, const QDict *qdict)
917{
918 int64_t cpu_index;
919
920 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
921 use it are converted to the QAPI */
922 cpu_index = qdict_get_int(qdict, "index");
923 if (monitor_set_cpu(cpu_index) < 0) {
924 monitor_printf(mon, "invalid CPU index\n");
925 }
926}
0cfd6a9a
LC
927
928void hmp_memsave(Monitor *mon, const QDict *qdict)
929{
930 uint32_t size = qdict_get_int(qdict, "size");
931 const char *filename = qdict_get_str(qdict, "filename");
932 uint64_t addr = qdict_get_int(qdict, "val");
e940f543 933 Error *err = NULL;
0cfd6a9a 934
e940f543
MA
935 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &err);
936 hmp_handle_error(mon, &err);
0cfd6a9a 937}
6d3962bf
LC
938
939void hmp_pmemsave(Monitor *mon, const QDict *qdict)
940{
941 uint32_t size = qdict_get_int(qdict, "size");
942 const char *filename = qdict_get_str(qdict, "filename");
943 uint64_t addr = qdict_get_int(qdict, "val");
e940f543 944 Error *err = NULL;
6d3962bf 945
e940f543
MA
946 qmp_pmemsave(addr, size, filename, &err);
947 hmp_handle_error(mon, &err);
1f590cf9
LL
948}
949
3949e594 950void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1f590cf9 951{
1f590cf9
LL
952 const char *chardev = qdict_get_str(qdict, "device");
953 const char *data = qdict_get_str(qdict, "data");
e940f543 954 Error *err = NULL;
1f590cf9 955
e940f543 956 qmp_ringbuf_write(chardev, data, false, 0, &err);
1f590cf9 957
e940f543 958 hmp_handle_error(mon, &err);
6d3962bf 959}
e42e818b 960
3949e594 961void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
49b6d722
LL
962{
963 uint32_t size = qdict_get_int(qdict, "size");
964 const char *chardev = qdict_get_str(qdict, "device");
3ab651fc 965 char *data;
e940f543 966 Error *err = NULL;
543f3412 967 int i;
49b6d722 968
e940f543
MA
969 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
970 if (err) {
193227f9 971 error_report_err(err);
49b6d722
LL
972 return;
973 }
974
543f3412
MA
975 for (i = 0; data[i]; i++) {
976 unsigned char ch = data[i];
977
978 if (ch == '\\') {
979 monitor_printf(mon, "\\\\");
980 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
981 monitor_printf(mon, "\\u%04X", ch);
982 } else {
983 monitor_printf(mon, "%c", ch);
984 }
985
986 }
987 monitor_printf(mon, "\n");
3ab651fc 988 g_free(data);
49b6d722
LL
989}
990
e42e818b
LC
991static void hmp_cont_cb(void *opaque, int err)
992{
e42e818b 993 if (!err) {
8b7f6fbb 994 qmp_cont(NULL);
e42e818b
LC
995 }
996}
997
8b7f6fbb
LC
998static bool key_is_missing(const BlockInfo *bdev)
999{
1000 return (bdev->inserted && bdev->inserted->encryption_key_missing);
1001}
1002
e42e818b
LC
1003void hmp_cont(Monitor *mon, const QDict *qdict)
1004{
8b7f6fbb 1005 BlockInfoList *bdev_list, *bdev;
e940f543 1006 Error *err = NULL;
e42e818b 1007
8b7f6fbb
LC
1008 bdev_list = qmp_query_block(NULL);
1009 for (bdev = bdev_list; bdev; bdev = bdev->next) {
1010 if (key_is_missing(bdev->value)) {
1011 monitor_read_block_device_key(mon, bdev->value->device,
1012 hmp_cont_cb, NULL);
1013 goto out;
e42e818b 1014 }
e42e818b 1015 }
8b7f6fbb 1016
e940f543
MA
1017 qmp_cont(&err);
1018 hmp_handle_error(mon, &err);
8b7f6fbb
LC
1019
1020out:
1021 qapi_free_BlockInfoList(bdev_list);
e42e818b 1022}
ab49ab5c 1023
9b9df25a
GH
1024void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1025{
1026 qmp_system_wakeup(NULL);
1027}
1028
3e5a50d6 1029void hmp_nmi(Monitor *mon, const QDict *qdict)
ab49ab5c 1030{
e940f543 1031 Error *err = NULL;
ab49ab5c 1032
e940f543
MA
1033 qmp_inject_nmi(&err);
1034 hmp_handle_error(mon, &err);
ab49ab5c 1035}
4b37156c
LC
1036
1037void hmp_set_link(Monitor *mon, const QDict *qdict)
1038{
1039 const char *name = qdict_get_str(qdict, "name");
34acbc95 1040 bool up = qdict_get_bool(qdict, "up");
e940f543 1041 Error *err = NULL;
4b37156c 1042
e940f543
MA
1043 qmp_set_link(name, up, &err);
1044 hmp_handle_error(mon, &err);
4b37156c 1045}
a4dea8a9
LC
1046
1047void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1048{
1049 const char *device = qdict_get_str(qdict, "device");
1050 const char *password = qdict_get_str(qdict, "password");
e940f543 1051 Error *err = NULL;
a4dea8a9 1052
e940f543
MA
1053 qmp_block_passwd(true, device, false, NULL, password, &err);
1054 hmp_handle_error(mon, &err);
a4dea8a9 1055}
d72f3264
LC
1056
1057void hmp_balloon(Monitor *mon, const QDict *qdict)
1058{
1059 int64_t value = qdict_get_int(qdict, "value");
e940f543 1060 Error *err = NULL;
d72f3264 1061
e940f543
MA
1062 qmp_balloon(value, &err);
1063 if (err) {
193227f9 1064 error_report_err(err);
d72f3264
LC
1065 }
1066}
5e7caacb
LC
1067
1068void hmp_block_resize(Monitor *mon, const QDict *qdict)
1069{
1070 const char *device = qdict_get_str(qdict, "device");
1071 int64_t size = qdict_get_int(qdict, "size");
e940f543 1072 Error *err = NULL;
5e7caacb 1073
e940f543
MA
1074 qmp_block_resize(true, device, false, NULL, size, &err);
1075 hmp_handle_error(mon, &err);
5e7caacb 1076}
6106e249 1077
d9b902db
PB
1078void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1079{
d9b902db
PB
1080 const char *filename = qdict_get_str(qdict, "target");
1081 const char *format = qdict_get_try_str(qdict, "format");
34acbc95
EB
1082 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1083 bool full = qdict_get_try_bool(qdict, "full", false);
e940f543 1084 Error *err = NULL;
faecd40a
EB
1085 DriveMirror mirror = {
1086 .device = (char *)qdict_get_str(qdict, "device"),
1087 .target = (char *)filename,
1088 .has_format = !!format,
1089 .format = (char *)format,
1090 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1091 .has_mode = true,
1092 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1093 .unmap = true,
1094 };
d9b902db
PB
1095
1096 if (!filename) {
c6bd8c70 1097 error_setg(&err, QERR_MISSING_PARAMETER, "target");
e940f543 1098 hmp_handle_error(mon, &err);
d9b902db
PB
1099 return;
1100 }
faecd40a 1101 qmp_drive_mirror(&mirror, &err);
e940f543 1102 hmp_handle_error(mon, &err);
d9b902db
PB
1103}
1104
de90930a
SH
1105void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1106{
1107 const char *device = qdict_get_str(qdict, "device");
1108 const char *filename = qdict_get_str(qdict, "target");
1109 const char *format = qdict_get_try_str(qdict, "format");
34acbc95
EB
1110 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1111 bool full = qdict_get_try_bool(qdict, "full", false);
13b9414b 1112 bool compress = qdict_get_try_bool(qdict, "compress", false);
e940f543 1113 Error *err = NULL;
81206a89
PB
1114 DriveBackup backup = {
1115 .device = (char *)device,
1116 .target = (char *)filename,
1117 .has_format = !!format,
1118 .format = (char *)format,
1119 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1120 .has_mode = true,
1121 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
13b9414b
PB
1122 .has_compress = !!compress,
1123 .compress = compress,
81206a89 1124 };
de90930a
SH
1125
1126 if (!filename) {
c6bd8c70 1127 error_setg(&err, QERR_MISSING_PARAMETER, "target");
e940f543 1128 hmp_handle_error(mon, &err);
de90930a
SH
1129 return;
1130 }
1131
81206a89 1132 qmp_drive_backup(&backup, &err);
e940f543 1133 hmp_handle_error(mon, &err);
de90930a
SH
1134}
1135
6106e249
LC
1136void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1137{
1138 const char *device = qdict_get_str(qdict, "device");
1139 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1140 const char *format = qdict_get_try_str(qdict, "format");
34acbc95 1141 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
6cc2a415 1142 enum NewImageMode mode;
e940f543 1143 Error *err = NULL;
6106e249
LC
1144
1145 if (!filename) {
1146 /* In the future, if 'snapshot-file' is not specified, the snapshot
1147 will be taken internally. Today it's actually required. */
c6bd8c70 1148 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
e940f543 1149 hmp_handle_error(mon, &err);
6106e249
LC
1150 return;
1151 }
1152
6cc2a415 1153 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
0901f67e
BC
1154 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1155 filename, false, NULL,
1156 !!format, format,
e940f543
MA
1157 true, mode, &err);
1158 hmp_handle_error(mon, &err);
6106e249 1159}
6cdedb07 1160
775ca88e
WX
1161void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1162{
1163 const char *device = qdict_get_str(qdict, "device");
1164 const char *name = qdict_get_str(qdict, "name");
e940f543 1165 Error *err = NULL;
775ca88e 1166
e940f543
MA
1167 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1168 hmp_handle_error(mon, &err);
775ca88e
WX
1169}
1170
7a4ed2ee
WX
1171void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1172{
1173 const char *device = qdict_get_str(qdict, "device");
1174 const char *name = qdict_get_str(qdict, "name");
1175 const char *id = qdict_get_try_str(qdict, "id");
e940f543 1176 Error *err = NULL;
7a4ed2ee
WX
1177
1178 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
e940f543
MA
1179 true, name, &err);
1180 hmp_handle_error(mon, &err);
7a4ed2ee
WX
1181}
1182
6cdedb07
LC
1183void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1184{
1185 qmp_migrate_cancel(NULL);
1186}
4f0a993b 1187
bf1ae1f4
DDAG
1188void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1189{
1190 Error *err = NULL;
1191 const char *uri = qdict_get_str(qdict, "uri");
1192
1193 qmp_migrate_incoming(uri, &err);
1194
1fa57f55 1195 hmp_handle_error(mon, &err);
bf1ae1f4
DDAG
1196}
1197
4f0a993b
LC
1198void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1199{
1200 double value = qdict_get_double(qdict, "value");
1201 qmp_migrate_set_downtime(value, NULL);
1202}
3dc85383 1203
9e1ba4cc
OW
1204void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1205{
1206 int64_t value = qdict_get_int(qdict, "value");
1207 Error *err = NULL;
1208
1209 qmp_migrate_set_cache_size(value, &err);
1210 if (err) {
193227f9 1211 error_report_err(err);
9e1ba4cc
OW
1212 return;
1213 }
1214}
1215
3dc85383
LC
1216void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1217{
1218 int64_t value = qdict_get_int(qdict, "value");
1219 qmp_migrate_set_speed(value, NULL);
1220}
fbf796fd 1221
00458433
OW
1222void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1223{
1224 const char *cap = qdict_get_str(qdict, "capability");
1225 bool state = qdict_get_bool(qdict, "state");
1226 Error *err = NULL;
1227 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1228 int i;
1229
7fb1cf16 1230 for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
00458433
OW
1231 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1232 caps->value = g_malloc0(sizeof(*caps->value));
1233 caps->value->capability = i;
1234 caps->value->state = state;
1235 caps->next = NULL;
1236 qmp_migrate_set_capabilities(caps, &err);
1237 break;
1238 }
1239 }
1240
7fb1cf16 1241 if (i == MIGRATION_CAPABILITY__MAX) {
c6bd8c70 1242 error_setg(&err, QERR_INVALID_PARAMETER, cap);
00458433
OW
1243 }
1244
1245 qapi_free_MigrationCapabilityStatusList(caps);
1246
1247 if (err) {
193227f9 1248 error_report_err(err);
00458433
OW
1249 }
1250}
1251
50e9a629
LL
1252void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1253{
1254 const char *param = qdict_get_str(qdict, "parameter");
69ef1f36
DB
1255 const char *valuestr = qdict_get_str(qdict, "value");
1256 long valueint = 0;
50e9a629
LL
1257 Error *err = NULL;
1258 bool has_compress_level = false;
1259 bool has_compress_threads = false;
1260 bool has_decompress_threads = false;
d85a31d1
JH
1261 bool has_cpu_throttle_initial = false;
1262 bool has_cpu_throttle_increment = false;
69ef1f36
DB
1263 bool has_tls_creds = false;
1264 bool has_tls_hostname = false;
1265 bool use_int_value = false;
50e9a629
LL
1266 int i;
1267
7fb1cf16 1268 for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
50e9a629
LL
1269 if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
1270 switch (i) {
1271 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1272 has_compress_level = true;
69ef1f36 1273 use_int_value = true;
50e9a629
LL
1274 break;
1275 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1276 has_compress_threads = true;
69ef1f36 1277 use_int_value = true;
50e9a629
LL
1278 break;
1279 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1280 has_decompress_threads = true;
69ef1f36 1281 use_int_value = true;
50e9a629 1282 break;
d85a31d1
JH
1283 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1284 has_cpu_throttle_initial = true;
69ef1f36 1285 use_int_value = true;
1626fee3 1286 break;
d85a31d1
JH
1287 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1288 has_cpu_throttle_increment = true;
1626fee3 1289 break;
69ef1f36
DB
1290 case MIGRATION_PARAMETER_TLS_CREDS:
1291 has_tls_creds = true;
1292 break;
1293 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1294 has_tls_hostname = true;
1295 break;
50e9a629 1296 }
69ef1f36
DB
1297
1298 if (use_int_value) {
1299 if (qemu_strtol(valuestr, NULL, 10, &valueint) < 0) {
1300 error_setg(&err, "Unable to parse '%s' as an int",
1301 valuestr);
1302 goto cleanup;
1303 }
1304 }
1305
1306 qmp_migrate_set_parameters(has_compress_level, valueint,
1307 has_compress_threads, valueint,
1308 has_decompress_threads, valueint,
1309 has_cpu_throttle_initial, valueint,
1310 has_cpu_throttle_increment, valueint,
1311 has_tls_creds, valuestr,
1312 has_tls_hostname, valuestr,
50e9a629
LL
1313 &err);
1314 break;
1315 }
1316 }
1317
7fb1cf16 1318 if (i == MIGRATION_PARAMETER__MAX) {
c6bd8c70 1319 error_setg(&err, QERR_INVALID_PARAMETER, param);
50e9a629
LL
1320 }
1321
69ef1f36 1322 cleanup:
50e9a629 1323 if (err) {
193227f9 1324 error_report_err(err);
50e9a629
LL
1325 }
1326}
1327
b8a185bc
MA
1328void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1329{
1330 Error *err = NULL;
1331 const char *protocol = qdict_get_str(qdict, "protocol");
1332 const char *hostname = qdict_get_str(qdict, "hostname");
1333 bool has_port = qdict_haskey(qdict, "port");
1334 int port = qdict_get_try_int(qdict, "port", -1);
1335 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1336 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1337 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1338
1339 qmp_client_migrate_info(protocol, hostname,
1340 has_port, port, has_tls_port, tls_port,
1341 !!cert_subject, cert_subject, &err);
1342 hmp_handle_error(mon, &err);
1343}
1344
4886a1bc
DDAG
1345void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1346{
1347 Error *err = NULL;
1348 qmp_migrate_start_postcopy(&err);
1349 hmp_handle_error(mon, &err);
1350}
1351
fbf796fd
LC
1352void hmp_set_password(Monitor *mon, const QDict *qdict)
1353{
1354 const char *protocol = qdict_get_str(qdict, "protocol");
1355 const char *password = qdict_get_str(qdict, "password");
1356 const char *connected = qdict_get_try_str(qdict, "connected");
1357 Error *err = NULL;
1358
1359 qmp_set_password(protocol, password, !!connected, connected, &err);
1360 hmp_handle_error(mon, &err);
1361}
9ad5372d
LC
1362
1363void hmp_expire_password(Monitor *mon, const QDict *qdict)
1364{
1365 const char *protocol = qdict_get_str(qdict, "protocol");
1366 const char *whenstr = qdict_get_str(qdict, "time");
1367 Error *err = NULL;
1368
1369 qmp_expire_password(protocol, whenstr, &err);
1370 hmp_handle_error(mon, &err);
1371}
c245b6a3
LC
1372
1373void hmp_eject(Monitor *mon, const QDict *qdict)
1374{
34acbc95 1375 bool force = qdict_get_try_bool(qdict, "force", false);
c245b6a3
LC
1376 const char *device = qdict_get_str(qdict, "device");
1377 Error *err = NULL;
1378
fbe2d816 1379 qmp_eject(true, device, false, NULL, true, force, &err);
c245b6a3
LC
1380 hmp_handle_error(mon, &err);
1381}
333a96ec 1382
c60bf339
SH
1383static void hmp_change_read_arg(void *opaque, const char *password,
1384 void *readline_opaque)
333a96ec
LC
1385{
1386 qmp_change_vnc_password(password, NULL);
c60bf339 1387 monitor_read_command(opaque, 1);
333a96ec
LC
1388}
1389
333a96ec
LC
1390void hmp_change(Monitor *mon, const QDict *qdict)
1391{
1392 const char *device = qdict_get_str(qdict, "device");
1393 const char *target = qdict_get_str(qdict, "target");
1394 const char *arg = qdict_get_try_str(qdict, "arg");
baead0ab
HR
1395 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1396 BlockdevChangeReadOnlyMode read_only_mode = 0;
333a96ec
LC
1397 Error *err = NULL;
1398
10686749 1399 if (strcmp(device, "vnc") == 0) {
baead0ab
HR
1400 if (read_only) {
1401 monitor_printf(mon,
1402 "Parameter 'read-only-mode' is invalid for VNC\n");
1403 return;
1404 }
10686749
HR
1405 if (strcmp(target, "passwd") == 0 ||
1406 strcmp(target, "password") == 0) {
1407 if (!arg) {
1408 monitor_read_password(mon, hmp_change_read_arg, NULL);
1409 return;
1410 }
1411 }
1412 qmp_change("vnc", target, !!arg, arg, &err);
1413 } else {
baead0ab
HR
1414 if (read_only) {
1415 read_only_mode =
1416 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup,
7fb1cf16 1417 read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX,
baead0ab
HR
1418 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1419 if (err) {
1420 hmp_handle_error(mon, &err);
1421 return;
1422 }
1423 }
1424
70e2cb3b
KW
1425 qmp_blockdev_change_medium(true, device, false, NULL, target,
1426 !!arg, arg, !!read_only, read_only_mode,
1427 &err);
10686749
HR
1428 if (err &&
1429 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
1430 error_free(err);
1431 monitor_read_block_device_key(mon, device, NULL, NULL);
333a96ec
LC
1432 return;
1433 }
1434 }
1435
333a96ec
LC
1436 hmp_handle_error(mon, &err);
1437}
80047da5
LC
1438
1439void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1440{
1441 Error *err = NULL;
4dc9397b
EB
1442 BlockIOThrottle throttle = {
1443 .device = (char *) qdict_get_str(qdict, "device"),
1444 .bps = qdict_get_int(qdict, "bps"),
1445 .bps_rd = qdict_get_int(qdict, "bps_rd"),
1446 .bps_wr = qdict_get_int(qdict, "bps_wr"),
1447 .iops = qdict_get_int(qdict, "iops"),
1448 .iops_rd = qdict_get_int(qdict, "iops_rd"),
1449 .iops_wr = qdict_get_int(qdict, "iops_wr"),
1450 };
80047da5 1451
4dc9397b 1452 qmp_block_set_io_throttle(&throttle, &err);
80047da5
LC
1453 hmp_handle_error(mon, &err);
1454}
12bd451f
SH
1455
1456void hmp_block_stream(Monitor *mon, const QDict *qdict)
1457{
1458 Error *error = NULL;
1459 const char *device = qdict_get_str(qdict, "device");
1460 const char *base = qdict_get_try_str(qdict, "base");
c83c66c3 1461 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
12bd451f 1462
2323322e 1463 qmp_block_stream(false, NULL, device, base != NULL, base, false, NULL,
1d809098 1464 qdict_haskey(qdict, "speed"), speed,
46663e5e 1465 true, BLOCKDEV_ON_ERROR_REPORT, &error);
12bd451f
SH
1466
1467 hmp_handle_error(mon, &error);
1468}
2d47c6e9
SH
1469
1470void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1471{
1472 Error *error = NULL;
1473 const char *device = qdict_get_str(qdict, "device");
c6db2395 1474 int64_t value = qdict_get_int(qdict, "speed");
2d47c6e9
SH
1475
1476 qmp_block_job_set_speed(device, value, &error);
1477
1478 hmp_handle_error(mon, &error);
1479}
370521a1
SH
1480
1481void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1482{
1483 Error *error = NULL;
1484 const char *device = qdict_get_str(qdict, "device");
34acbc95 1485 bool force = qdict_get_try_bool(qdict, "force", false);
370521a1 1486
6e37fb81
PB
1487 qmp_block_job_cancel(device, true, force, &error);
1488
1489 hmp_handle_error(mon, &error);
1490}
1491
1492void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1493{
1494 Error *error = NULL;
1495 const char *device = qdict_get_str(qdict, "device");
1496
1497 qmp_block_job_pause(device, &error);
1498
1499 hmp_handle_error(mon, &error);
1500}
1501
1502void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1503{
1504 Error *error = NULL;
1505 const char *device = qdict_get_str(qdict, "device");
1506
1507 qmp_block_job_resume(device, &error);
370521a1
SH
1508
1509 hmp_handle_error(mon, &error);
1510}
e1c37d0e 1511
aeae883b
PB
1512void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1513{
1514 Error *error = NULL;
1515 const char *device = qdict_get_str(qdict, "device");
1516
1517 qmp_block_job_complete(device, &error);
1518
1519 hmp_handle_error(mon, &error);
1520}
1521
e49f35bd 1522typedef struct HMPMigrationStatus
e1c37d0e
LC
1523{
1524 QEMUTimer *timer;
1525 Monitor *mon;
1526 bool is_block_migration;
e49f35bd 1527} HMPMigrationStatus;
e1c37d0e
LC
1528
1529static void hmp_migrate_status_cb(void *opaque)
1530{
e49f35bd 1531 HMPMigrationStatus *status = opaque;
e1c37d0e
LC
1532 MigrationInfo *info;
1533
1534 info = qmp_query_migrate(NULL);
24b8c39b
HZ
1535 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1536 info->status == MIGRATION_STATUS_SETUP) {
e1c37d0e
LC
1537 if (info->has_disk) {
1538 int progress;
1539
1540 if (info->disk->remaining) {
1541 progress = info->disk->transferred * 100 / info->disk->total;
1542 } else {
1543 progress = 100;
1544 }
1545
1546 monitor_printf(status->mon, "Completed %d %%\r", progress);
1547 monitor_flush(status->mon);
1548 }
1549
bc72ad67 1550 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
e1c37d0e
LC
1551 } else {
1552 if (status->is_block_migration) {
1553 monitor_printf(status->mon, "\n");
1554 }
d59ce6f3
DB
1555 if (info->has_error_desc) {
1556 error_report("%s", info->error_desc);
1557 }
e1c37d0e 1558 monitor_resume(status->mon);
bc72ad67 1559 timer_del(status->timer);
e1c37d0e
LC
1560 g_free(status);
1561 }
1562
1563 qapi_free_MigrationInfo(info);
1564}
1565
1566void hmp_migrate(Monitor *mon, const QDict *qdict)
1567{
34acbc95
EB
1568 bool detach = qdict_get_try_bool(qdict, "detach", false);
1569 bool blk = qdict_get_try_bool(qdict, "blk", false);
1570 bool inc = qdict_get_try_bool(qdict, "inc", false);
e1c37d0e
LC
1571 const char *uri = qdict_get_str(qdict, "uri");
1572 Error *err = NULL;
1573
1574 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1575 if (err) {
193227f9 1576 error_report_err(err);
e1c37d0e
LC
1577 return;
1578 }
1579
1580 if (!detach) {
e49f35bd 1581 HMPMigrationStatus *status;
e1c37d0e
LC
1582
1583 if (monitor_suspend(mon) < 0) {
1584 monitor_printf(mon, "terminal does not allow synchronous "
1585 "migration, continuing detached\n");
1586 return;
1587 }
1588
1589 status = g_malloc0(sizeof(*status));
1590 status->mon = mon;
1591 status->is_block_migration = blk || inc;
bc72ad67 1592 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
e1c37d0e 1593 status);
bc72ad67 1594 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
e1c37d0e
LC
1595 }
1596}
a15fef21 1597
318660f8
MA
1598void hmp_device_add(Monitor *mon, const QDict *qdict)
1599{
485febc6
MA
1600 Error *err = NULL;
1601
1602 qmp_device_add((QDict *)qdict, NULL, &err);
1603 hmp_handle_error(mon, &err);
318660f8
MA
1604}
1605
a15fef21
LC
1606void hmp_device_del(Monitor *mon, const QDict *qdict)
1607{
1608 const char *id = qdict_get_str(qdict, "id");
1609 Error *err = NULL;
1610
1611 qmp_device_del(id, &err);
1612 hmp_handle_error(mon, &err);
1613}
783e9b48
WC
1614
1615void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1616{
e940f543 1617 Error *err = NULL;
34acbc95
EB
1618 bool paging = qdict_get_try_bool(qdict, "paging", false);
1619 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
1620 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
1621 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
75363769 1622 const char *file = qdict_get_str(qdict, "filename");
783e9b48
WC
1623 bool has_begin = qdict_haskey(qdict, "begin");
1624 bool has_length = qdict_haskey(qdict, "length");
228de9cf 1625 bool has_detach = qdict_haskey(qdict, "detach");
783e9b48
WC
1626 int64_t begin = 0;
1627 int64_t length = 0;
228de9cf 1628 bool detach = false;
b53ccc30 1629 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
75363769 1630 char *prot;
783e9b48 1631
1b7a0f75 1632 if (zlib + lzo + snappy > 1) {
e940f543
MA
1633 error_setg(&err, "only one of '-z|-l|-s' can be set");
1634 hmp_handle_error(mon, &err);
1b7a0f75
QN
1635 return;
1636 }
1637
1638 if (zlib) {
1639 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1640 }
1641
1642 if (lzo) {
1643 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1644 }
1645
1646 if (snappy) {
1647 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1648 }
1649
783e9b48
WC
1650 if (has_begin) {
1651 begin = qdict_get_int(qdict, "begin");
1652 }
1653 if (has_length) {
1654 length = qdict_get_int(qdict, "length");
1655 }
228de9cf
PX
1656 if (has_detach) {
1657 detach = qdict_get_bool(qdict, "detach");
1658 }
783e9b48 1659
75363769
LC
1660 prot = g_strconcat("file:", file, NULL);
1661
228de9cf
PX
1662 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
1663 has_length, length, true, dump_format, &err);
e940f543 1664 hmp_handle_error(mon, &err);
75363769 1665 g_free(prot);
783e9b48 1666}
928059a3
LC
1667
1668void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1669{
1670 Error *err = NULL;
1671 QemuOpts *opts;
1672
1673 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
84d18f06 1674 if (err) {
928059a3
LC
1675 goto out;
1676 }
1677
1678 netdev_add(opts, &err);
84d18f06 1679 if (err) {
928059a3
LC
1680 qemu_opts_del(opts);
1681 }
1682
1683out:
1684 hmp_handle_error(mon, &err);
1685}
5f964155
LC
1686
1687void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1688{
1689 const char *id = qdict_get_str(qdict, "id");
1690 Error *err = NULL;
1691
1692 qmp_netdev_del(id, &err);
1693 hmp_handle_error(mon, &err);
1694}
208c9d1b 1695
cff8b2c6
PB
1696void hmp_object_add(Monitor *mon, const QDict *qdict)
1697{
1698 Error *err = NULL;
1699 QemuOpts *opts;
09204eac 1700 Visitor *v;
90998d58 1701 Object *obj = NULL;
cff8b2c6
PB
1702
1703 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1704 if (err) {
90998d58
DB
1705 hmp_handle_error(mon, &err);
1706 return;
cff8b2c6
PB
1707 }
1708
09204eac
EB
1709 v = opts_visitor_new(opts);
1710 obj = user_creatable_add(qdict, v, &err);
1711 visit_free(v);
90998d58 1712 qemu_opts_del(opts);
cff8b2c6 1713
cff8b2c6 1714 if (err) {
90998d58 1715 hmp_handle_error(mon, &err);
cff8b2c6 1716 }
90998d58
DB
1717 if (obj) {
1718 object_unref(obj);
cff8b2c6 1719 }
cff8b2c6
PB
1720}
1721
208c9d1b
CB
1722void hmp_getfd(Monitor *mon, const QDict *qdict)
1723{
1724 const char *fdname = qdict_get_str(qdict, "fdname");
e940f543 1725 Error *err = NULL;
208c9d1b 1726
e940f543
MA
1727 qmp_getfd(fdname, &err);
1728 hmp_handle_error(mon, &err);
208c9d1b
CB
1729}
1730
1731void hmp_closefd(Monitor *mon, const QDict *qdict)
1732{
1733 const char *fdname = qdict_get_str(qdict, "fdname");
e940f543 1734 Error *err = NULL;
208c9d1b 1735
e940f543
MA
1736 qmp_closefd(fdname, &err);
1737 hmp_handle_error(mon, &err);
208c9d1b 1738}
e4c8f004 1739
3e5a50d6 1740void hmp_sendkey(Monitor *mon, const QDict *qdict)
e4c8f004
AK
1741{
1742 const char *keys = qdict_get_str(qdict, "keys");
9f328977 1743 KeyValueList *keylist, *head = NULL, *tmp = NULL;
e4c8f004
AK
1744 int has_hold_time = qdict_haskey(qdict, "hold-time");
1745 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1746 Error *err = NULL;
e4c8f004 1747 char *separator;
9f328977 1748 int keyname_len;
e4c8f004
AK
1749
1750 while (1) {
1751 separator = strchr(keys, '-');
1752 keyname_len = separator ? separator - keys : strlen(keys);
e4c8f004
AK
1753
1754 /* Be compatible with old interface, convert user inputted "<" */
64ffbe04
WB
1755 if (keys[0] == '<' && keyname_len == 1) {
1756 keys = "less";
e4c8f004
AK
1757 keyname_len = 4;
1758 }
e4c8f004 1759
e4c8f004 1760 keylist = g_malloc0(sizeof(*keylist));
9f328977 1761 keylist->value = g_malloc0(sizeof(*keylist->value));
e4c8f004
AK
1762
1763 if (!head) {
1764 head = keylist;
1765 }
1766 if (tmp) {
1767 tmp->next = keylist;
1768 }
1769 tmp = keylist;
1770
64ffbe04 1771 if (strstart(keys, "0x", NULL)) {
9f328977 1772 char *endp;
64ffbe04
WB
1773 int value = strtoul(keys, &endp, 0);
1774 assert(endp <= keys + keyname_len);
1775 if (endp != keys + keyname_len) {
9f328977
LC
1776 goto err_out;
1777 }
568c73a4 1778 keylist->value->type = KEY_VALUE_KIND_NUMBER;
32bafa8f 1779 keylist->value->u.number.data = value;
9f328977 1780 } else {
64ffbe04 1781 int idx = index_from_key(keys, keyname_len);
7fb1cf16 1782 if (idx == Q_KEY_CODE__MAX) {
9f328977
LC
1783 goto err_out;
1784 }
568c73a4 1785 keylist->value->type = KEY_VALUE_KIND_QCODE;
32bafa8f 1786 keylist->value->u.qcode.data = idx;
9f328977
LC
1787 }
1788
e4c8f004
AK
1789 if (!separator) {
1790 break;
1791 }
1792 keys = separator + 1;
1793 }
1794
9f328977 1795 qmp_send_key(head, has_hold_time, hold_time, &err);
e4c8f004 1796 hmp_handle_error(mon, &err);
9f328977
LC
1797
1798out:
1799 qapi_free_KeyValueList(head);
1800 return;
1801
1802err_out:
64ffbe04 1803 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
9f328977 1804 goto out;
e4c8f004 1805}
ad39cf6d 1806
3e5a50d6 1807void hmp_screendump(Monitor *mon, const QDict *qdict)
ad39cf6d
LC
1808{
1809 const char *filename = qdict_get_str(qdict, "filename");
1810 Error *err = NULL;
1811
1812 qmp_screendump(filename, &err);
1813 hmp_handle_error(mon, &err);
1814}
4057725f
PB
1815
1816void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1817{
1818 const char *uri = qdict_get_str(qdict, "uri");
34acbc95
EB
1819 bool writable = qdict_get_try_bool(qdict, "writable", false);
1820 bool all = qdict_get_try_bool(qdict, "all", false);
4057725f
PB
1821 Error *local_err = NULL;
1822 BlockInfoList *block_list, *info;
1823 SocketAddress *addr;
1824
1825 if (writable && !all) {
1826 error_setg(&local_err, "-w only valid together with -a");
1827 goto exit;
1828 }
1829
1830 /* First check if the address is valid and start the server. */
1831 addr = socket_parse(uri, &local_err);
1832 if (local_err != NULL) {
1833 goto exit;
1834 }
1835
ddffee39 1836 qmp_nbd_server_start(addr, false, NULL, &local_err);
4057725f
PB
1837 qapi_free_SocketAddress(addr);
1838 if (local_err != NULL) {
1839 goto exit;
1840 }
1841
1842 if (!all) {
1843 return;
1844 }
1845
1846 /* Then try adding all block devices. If one fails, close all and
1847 * exit.
1848 */
1849 block_list = qmp_query_block(NULL);
1850
1851 for (info = block_list; info; info = info->next) {
1852 if (!info->value->has_inserted) {
1853 continue;
1854 }
1855
1856 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1857
1858 if (local_err != NULL) {
1859 qmp_nbd_server_stop(NULL);
1860 break;
1861 }
1862 }
1863
1864 qapi_free_BlockInfoList(block_list);
1865
1866exit:
1867 hmp_handle_error(mon, &local_err);
1868}
1869
1870void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1871{
1872 const char *device = qdict_get_str(qdict, "device");
34acbc95 1873 bool writable = qdict_get_try_bool(qdict, "writable", false);
4057725f
PB
1874 Error *local_err = NULL;
1875
1876 qmp_nbd_server_add(device, true, writable, &local_err);
1877
1878 if (local_err != NULL) {
1879 hmp_handle_error(mon, &local_err);
1880 }
1881}
1882
1883void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1884{
e940f543 1885 Error *err = NULL;
4057725f 1886
e940f543
MA
1887 qmp_nbd_server_stop(&err);
1888 hmp_handle_error(mon, &err);
4057725f 1889}
f1088908 1890
abf23329
JH
1891void hmp_cpu_add(Monitor *mon, const QDict *qdict)
1892{
1893 int cpuid;
1894 Error *err = NULL;
1895
1896 cpuid = qdict_get_int(qdict, "id");
1897 qmp_cpu_add(cpuid, &err);
1898 hmp_handle_error(mon, &err);
1899}
1900
f1088908
GH
1901void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1902{
1903 const char *args = qdict_get_str(qdict, "args");
1904 Error *err = NULL;
1905 QemuOpts *opts;
1906
70b94331 1907 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
f1088908 1908 if (opts == NULL) {
312fd5f2 1909 error_setg(&err, "Parsing chardev args failed");
f1088908
GH
1910 } else {
1911 qemu_chr_new_from_opts(opts, NULL, &err);
0a73336d 1912 qemu_opts_del(opts);
f1088908
GH
1913 }
1914 hmp_handle_error(mon, &err);
1915}
1916
1917void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1918{
1919 Error *local_err = NULL;
1920
1921 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1922 hmp_handle_error(mon, &local_err);
1923}
587da2c3
KW
1924
1925void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1926{
4c7b7e9b 1927 BlockBackend *blk;
e7f98f2f 1928 BlockBackend *local_blk = NULL;
1813d330 1929 AioContext *aio_context;
587da2c3
KW
1930 const char* device = qdict_get_str(qdict, "device");
1931 const char* command = qdict_get_str(qdict, "command");
1932 Error *err = NULL;
1933
4c7b7e9b 1934 blk = blk_by_name(device);
e7f98f2f
KW
1935 if (!blk) {
1936 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
1937 if (bs) {
1938 blk = local_blk = blk_new();
1939 blk_insert_bs(blk, bs);
1940 } else {
1941 goto fail;
1942 }
1943 }
1944
1813d330
KW
1945 aio_context = blk_get_aio_context(blk);
1946 aio_context_acquire(aio_context);
479b5998 1947
1813d330 1948 qemuio_command(blk, command);
479b5998 1949
1813d330 1950 aio_context_release(aio_context);
587da2c3 1951
e7f98f2f
KW
1952fail:
1953 blk_unref(local_blk);
587da2c3
KW
1954 hmp_handle_error(mon, &err);
1955}
ab2d0531
PB
1956
1957void hmp_object_del(Monitor *mon, const QDict *qdict)
1958{
1959 const char *id = qdict_get_str(qdict, "id");
1960 Error *err = NULL;
1961
90998d58 1962 user_creatable_del(id, &err);
ab2d0531
PB
1963 hmp_handle_error(mon, &err);
1964}
eb1539b2
HT
1965
1966void hmp_info_memdev(Monitor *mon, const QDict *qdict)
1967{
1968 Error *err = NULL;
1969 MemdevList *memdev_list = qmp_query_memdev(&err);
1970 MemdevList *m = memdev_list;
3b098d56 1971 Visitor *v;
976620ac 1972 char *str;
eb1539b2
HT
1973 int i = 0;
1974
1975
1976 while (m) {
3b098d56
EB
1977 v = string_output_visitor_new(false, &str);
1978 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
8f4e5ac3 1979 monitor_printf(mon, "memory backend: %d\n", i);
eb1539b2
HT
1980 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
1981 monitor_printf(mon, " merge: %s\n",
1982 m->value->merge ? "true" : "false");
1983 monitor_printf(mon, " dump: %s\n",
1984 m->value->dump ? "true" : "false");
1985 monitor_printf(mon, " prealloc: %s\n",
1986 m->value->prealloc ? "true" : "false");
1987 monitor_printf(mon, " policy: %s\n",
1988 HostMemPolicy_lookup[m->value->policy]);
3b098d56 1989 visit_complete(v, &str);
976620ac 1990 monitor_printf(mon, " host nodes: %s\n", str);
eb1539b2 1991
976620ac 1992 g_free(str);
3b098d56 1993 visit_free(v);
eb1539b2
HT
1994 m = m->next;
1995 i++;
1996 }
1997
1998 monitor_printf(mon, "\n");
ecaf54a0
CF
1999
2000 qapi_free_MemdevList(memdev_list);
eb1539b2 2001}
a631892f
ZG
2002
2003void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2004{
2005 Error *err = NULL;
2006 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2007 MemoryDeviceInfoList *info;
2008 MemoryDeviceInfo *value;
2009 PCDIMMDeviceInfo *di;
2010
2011 for (info = info_list; info; info = info->next) {
2012 value = info->value;
2013
2014 if (value) {
1fd5d4fe 2015 switch (value->type) {
a631892f 2016 case MEMORY_DEVICE_INFO_KIND_DIMM:
32bafa8f 2017 di = value->u.dimm.data;
a631892f
ZG
2018
2019 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1fd5d4fe 2020 MemoryDeviceInfoKind_lookup[value->type],
a631892f
ZG
2021 di->id ? di->id : "");
2022 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2023 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2024 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2025 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2026 monitor_printf(mon, " memdev: %s\n", di->memdev);
2027 monitor_printf(mon, " hotplugged: %s\n",
2028 di->hotplugged ? "true" : "false");
2029 monitor_printf(mon, " hotpluggable: %s\n",
2030 di->hotpluggable ? "true" : "false");
2031 break;
2032 default:
2033 break;
2034 }
2035 }
2036 }
2037
2038 qapi_free_MemoryDeviceInfoList(info_list);
2039}
89d7fa9e 2040
62313160
TW
2041void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2042{
2043 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2044 IOThreadInfoList *info;
2045
2046 for (info = info_list; info; info = info->next) {
2047 monitor_printf(mon, "%s: thread_id=%" PRId64 "\n",
2048 info->value->id, info->value->thread_id);
2049 }
2050
2051 qapi_free_IOThreadInfoList(info_list);
2052}
2053
89d7fa9e
AF
2054void hmp_qom_list(Monitor *mon, const QDict *qdict)
2055{
2056 const char *path = qdict_get_try_str(qdict, "path");
2057 ObjectPropertyInfoList *list;
2058 Error *err = NULL;
2059
2060 if (path == NULL) {
2061 monitor_printf(mon, "/\n");
2062 return;
2063 }
2064
2065 list = qmp_qom_list(path, &err);
2066 if (err == NULL) {
2067 ObjectPropertyInfoList *start = list;
2068 while (list != NULL) {
2069 ObjectPropertyInfo *value = list->value;
2070
2071 monitor_printf(mon, "%s (%s)\n",
2072 value->name, value->type);
2073 list = list->next;
2074 }
2075 qapi_free_ObjectPropertyInfoList(start);
2076 }
2077 hmp_handle_error(mon, &err);
2078}
c0e6ee9e
AF
2079
2080void hmp_qom_set(Monitor *mon, const QDict *qdict)
2081{
2082 const char *path = qdict_get_str(qdict, "path");
2083 const char *property = qdict_get_str(qdict, "property");
2084 const char *value = qdict_get_str(qdict, "value");
2085 Error *err = NULL;
2086 bool ambiguous = false;
2087 Object *obj;
2088
2089 obj = object_resolve_path(path, &ambiguous);
2090 if (obj == NULL) {
75158ebb
MA
2091 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2092 "Device '%s' not found", path);
c0e6ee9e
AF
2093 } else {
2094 if (ambiguous) {
2095 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2096 }
2097 object_property_parse(obj, value, property, &err);
2098 }
2099 hmp_handle_error(mon, &err);
2100}
fafa4d50
SF
2101
2102void hmp_rocker(Monitor *mon, const QDict *qdict)
2103{
2104 const char *name = qdict_get_str(qdict, "name");
2105 RockerSwitch *rocker;
533fdaed 2106 Error *err = NULL;
fafa4d50 2107
533fdaed
MA
2108 rocker = qmp_query_rocker(name, &err);
2109 if (err != NULL) {
2110 hmp_handle_error(mon, &err);
fafa4d50
SF
2111 return;
2112 }
2113
2114 monitor_printf(mon, "name: %s\n", rocker->name);
2115 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2116 monitor_printf(mon, "ports: %d\n", rocker->ports);
2117
2118 qapi_free_RockerSwitch(rocker);
2119}
2120
2121void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2122{
2123 RockerPortList *list, *port;
2124 const char *name = qdict_get_str(qdict, "name");
533fdaed 2125 Error *err = NULL;
fafa4d50 2126
533fdaed
MA
2127 list = qmp_query_rocker_ports(name, &err);
2128 if (err != NULL) {
2129 hmp_handle_error(mon, &err);
fafa4d50
SF
2130 return;
2131 }
2132
2133 monitor_printf(mon, " ena/ speed/ auto\n");
2134 monitor_printf(mon, " port link duplex neg?\n");
2135
2136 for (port = list; port; port = port->next) {
2137 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2138 port->value->name,
2139 port->value->enabled ? port->value->link_up ?
2140 "up" : "down" : "!ena",
2141 port->value->speed == 10000 ? "10G" : "??",
2142 port->value->duplex ? "FD" : "HD",
2143 port->value->autoneg ? "Yes" : "No");
2144 }
2145
2146 qapi_free_RockerPortList(list);
2147}
2148
2149void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2150{
2151 RockerOfDpaFlowList *list, *info;
2152 const char *name = qdict_get_str(qdict, "name");
2153 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
533fdaed 2154 Error *err = NULL;
fafa4d50 2155
533fdaed
MA
2156 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2157 if (err != NULL) {
2158 hmp_handle_error(mon, &err);
fafa4d50
SF
2159 return;
2160 }
2161
2162 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2163
2164 for (info = list; info; info = info->next) {
2165 RockerOfDpaFlow *flow = info->value;
2166 RockerOfDpaFlowKey *key = flow->key;
2167 RockerOfDpaFlowMask *mask = flow->mask;
2168 RockerOfDpaFlowAction *action = flow->action;
2169
2170 if (flow->hits) {
2171 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2172 key->priority, key->tbl_id, flow->hits);
2173 } else {
2174 monitor_printf(mon, "%-4d %-3d ",
2175 key->priority, key->tbl_id);
2176 }
2177
2178 if (key->has_in_pport) {
2179 monitor_printf(mon, " pport %d", key->in_pport);
2180 if (mask->has_in_pport) {
2181 monitor_printf(mon, "(0x%x)", mask->in_pport);
2182 }
2183 }
2184
2185 if (key->has_vlan_id) {
2186 monitor_printf(mon, " vlan %d",
2187 key->vlan_id & VLAN_VID_MASK);
2188 if (mask->has_vlan_id) {
2189 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2190 }
2191 }
2192
2193 if (key->has_tunnel_id) {
2194 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2195 if (mask->has_tunnel_id) {
2196 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2197 }
2198 }
2199
2200 if (key->has_eth_type) {
2201 switch (key->eth_type) {
2202 case 0x0806:
2203 monitor_printf(mon, " ARP");
2204 break;
2205 case 0x0800:
2206 monitor_printf(mon, " IP");
2207 break;
2208 case 0x86dd:
2209 monitor_printf(mon, " IPv6");
2210 break;
2211 case 0x8809:
2212 monitor_printf(mon, " LACP");
2213 break;
2214 case 0x88cc:
2215 monitor_printf(mon, " LLDP");
2216 break;
2217 default:
2218 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2219 break;
2220 }
2221 }
2222
2223 if (key->has_eth_src) {
2224 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2225 (mask->has_eth_src) &&
2226 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2227 monitor_printf(mon, " src <any mcast/bcast>");
2228 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2229 (mask->has_eth_src) &&
2230 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2231 monitor_printf(mon, " src <any ucast>");
2232 } else {
2233 monitor_printf(mon, " src %s", key->eth_src);
2234 if (mask->has_eth_src) {
2235 monitor_printf(mon, "(%s)", mask->eth_src);
2236 }
2237 }
2238 }
2239
2240 if (key->has_eth_dst) {
2241 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2242 (mask->has_eth_dst) &&
2243 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2244 monitor_printf(mon, " dst <any mcast/bcast>");
2245 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2246 (mask->has_eth_dst) &&
2247 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2248 monitor_printf(mon, " dst <any ucast>");
2249 } else {
2250 monitor_printf(mon, " dst %s", key->eth_dst);
2251 if (mask->has_eth_dst) {
2252 monitor_printf(mon, "(%s)", mask->eth_dst);
2253 }
2254 }
2255 }
2256
2257 if (key->has_ip_proto) {
2258 monitor_printf(mon, " proto %d", key->ip_proto);
2259 if (mask->has_ip_proto) {
2260 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2261 }
2262 }
2263
2264 if (key->has_ip_tos) {
2265 monitor_printf(mon, " TOS %d", key->ip_tos);
2266 if (mask->has_ip_tos) {
2267 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2268 }
2269 }
2270
2271 if (key->has_ip_dst) {
2272 monitor_printf(mon, " dst %s", key->ip_dst);
2273 }
2274
2275 if (action->has_goto_tbl || action->has_group_id ||
2276 action->has_new_vlan_id) {
2277 monitor_printf(mon, " -->");
2278 }
2279
2280 if (action->has_new_vlan_id) {
2281 monitor_printf(mon, " apply new vlan %d",
2282 ntohs(action->new_vlan_id));
2283 }
2284
2285 if (action->has_group_id) {
2286 monitor_printf(mon, " write group 0x%08x", action->group_id);
2287 }
2288
2289 if (action->has_goto_tbl) {
2290 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2291 }
2292
2293 monitor_printf(mon, "\n");
2294 }
2295
2296 qapi_free_RockerOfDpaFlowList(list);
2297}
2298
2299void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2300{
2301 RockerOfDpaGroupList *list, *g;
2302 const char *name = qdict_get_str(qdict, "name");
2303 uint8_t type = qdict_get_try_int(qdict, "type", 9);
533fdaed 2304 Error *err = NULL;
fafa4d50
SF
2305 bool set = false;
2306
533fdaed
MA
2307 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2308 if (err != NULL) {
2309 hmp_handle_error(mon, &err);
fafa4d50
SF
2310 return;
2311 }
2312
2313 monitor_printf(mon, "id (decode) --> buckets\n");
2314
2315 for (g = list; g; g = g->next) {
2316 RockerOfDpaGroup *group = g->value;
2317
2318 monitor_printf(mon, "0x%08x", group->id);
2319
2320 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2321 group->type == 1 ? "L2 rewrite" :
2322 group->type == 2 ? "L3 unicast" :
2323 group->type == 3 ? "L2 multicast" :
2324 group->type == 4 ? "L2 flood" :
2325 group->type == 5 ? "L3 interface" :
2326 group->type == 6 ? "L3 multicast" :
2327 group->type == 7 ? "L3 ECMP" :
2328 group->type == 8 ? "L2 overlay" :
2329 "unknown");
2330
2331 if (group->has_vlan_id) {
2332 monitor_printf(mon, " vlan %d", group->vlan_id);
2333 }
2334
2335 if (group->has_pport) {
2336 monitor_printf(mon, " pport %d", group->pport);
2337 }
2338
2339 if (group->has_index) {
2340 monitor_printf(mon, " index %d", group->index);
2341 }
2342
2343 monitor_printf(mon, ") -->");
2344
2345 if (group->has_set_vlan_id && group->set_vlan_id) {
2346 set = true;
2347 monitor_printf(mon, " set vlan %d",
2348 group->set_vlan_id & VLAN_VID_MASK);
2349 }
2350
2351 if (group->has_set_eth_src) {
2352 if (!set) {
2353 set = true;
2354 monitor_printf(mon, " set");
2355 }
2356 monitor_printf(mon, " src %s", group->set_eth_src);
2357 }
2358
2359 if (group->has_set_eth_dst) {
2360 if (!set) {
2361 set = true;
2362 monitor_printf(mon, " set");
2363 }
2364 monitor_printf(mon, " dst %s", group->set_eth_dst);
2365 }
2366
2367 set = false;
2368
2369 if (group->has_ttl_check && group->ttl_check) {
2370 monitor_printf(mon, " check TTL");
2371 }
2372
2373 if (group->has_group_id && group->group_id) {
2374 monitor_printf(mon, " group id 0x%08x", group->group_id);
2375 }
2376
2377 if (group->has_pop_vlan && group->pop_vlan) {
2378 monitor_printf(mon, " pop vlan");
2379 }
2380
2381 if (group->has_out_pport) {
2382 monitor_printf(mon, " out pport %d", group->out_pport);
2383 }
2384
2385 if (group->has_group_ids) {
2386 struct uint32List *id;
2387
2388 monitor_printf(mon, " groups [");
2389 for (id = group->group_ids; id; id = id->next) {
2390 monitor_printf(mon, "0x%08x", id->value);
2391 if (id->next) {
2392 monitor_printf(mon, ",");
2393 }
2394 }
2395 monitor_printf(mon, "]");
2396 }
2397
2398 monitor_printf(mon, "\n");
2399 }
2400
2401 qapi_free_RockerOfDpaGroupList(list);
2402}
4a6b52d6
PX
2403
2404void hmp_info_dump(Monitor *mon, const QDict *qdict)
2405{
2406 DumpQueryResult *result = qmp_query_dump(NULL);
2407
2408 assert(result && result->status < DUMP_STATUS__MAX);
2409 monitor_printf(mon, "Status: %s\n", DumpStatus_lookup[result->status]);
2410
2411 if (result->status == DUMP_STATUS_ACTIVE) {
2412 float percent = 0;
2413 assert(result->total != 0);
2414 percent = 100.0 * result->completed / result->total;
2415 monitor_printf(mon, "Finished: %.2f %%\n", percent);
2416 }
2417
2418 qapi_free_DumpQueryResult(result);
2419}
d2d8d46f
BR
2420
2421void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
2422{
2423 Error *err = NULL;
2424 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
2425 HotpluggableCPUList *saved = l;
2426 CpuInstanceProperties *c;
2427
2428 if (err != NULL) {
2429 hmp_handle_error(mon, &err);
2430 return;
2431 }
2432
2433 monitor_printf(mon, "Hotpluggable CPUs:\n");
2434 while (l) {
2435 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
2436 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
2437 l->value->vcpus_count);
2438 if (l->value->has_qom_path) {
2439 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
2440 }
2441
2442 c = l->value->props;
2443 monitor_printf(mon, " CPUInstance Properties:\n");
27393c33
PK
2444 if (c->has_node_id) {
2445 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
d2d8d46f 2446 }
27393c33
PK
2447 if (c->has_socket_id) {
2448 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
d2d8d46f 2449 }
27393c33
PK
2450 if (c->has_core_id) {
2451 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
d2d8d46f 2452 }
27393c33
PK
2453 if (c->has_thread_id) {
2454 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
d2d8d46f
BR
2455 }
2456
2457 l = l->next;
2458 }
2459
2460 qapi_free_HotpluggableCPUList(saved);
2461}