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