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