i386-softmmu.mak: remove all CONFIG_* except boards definitions
[qemu/armbru.git] / hmp.c
blobc2ad3f8251e9173c9bf1516e0101227314c3efdc
1 /*
2 * Human Monitor Interface
4 * Copyright IBM, Corp. 2011
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
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.
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 "qemu/sockets.h"
27 #include "monitor/monitor.h"
28 #include "monitor/qdev.h"
29 #include "qapi/error.h"
30 #include "qapi/opts-visitor.h"
31 #include "qapi/qapi-builtin-visit.h"
32 #include "qapi/qapi-commands-block.h"
33 #include "qapi/qapi-commands-char.h"
34 #include "qapi/qapi-commands-migration.h"
35 #include "qapi/qapi-commands-misc.h"
36 #include "qapi/qapi-commands-net.h"
37 #include "qapi/qapi-commands-rocker.h"
38 #include "qapi/qapi-commands-run-state.h"
39 #include "qapi/qapi-commands-tpm.h"
40 #include "qapi/qapi-commands-ui.h"
41 #include "qapi/qmp/qdict.h"
42 #include "qapi/qmp/qerror.h"
43 #include "qapi/string-input-visitor.h"
44 #include "qapi/string-output-visitor.h"
45 #include "qom/object_interfaces.h"
46 #include "ui/console.h"
47 #include "block/nbd.h"
48 #include "block/qapi.h"
49 #include "qemu-io.h"
50 #include "qemu/cutils.h"
51 #include "qemu/error-report.h"
52 #include "exec/ramlist.h"
53 #include "hw/intc/intc.h"
54 #include "migration/snapshot.h"
55 #include "migration/misc.h"
57 #ifdef CONFIG_SPICE
58 #include <spice/enums.h>
59 #endif
61 static void hmp_handle_error(Monitor *mon, Error **errp)
63 assert(errp);
64 if (*errp) {
65 error_reportf_err(*errp, "Error: ");
69 void hmp_info_name(Monitor *mon, const QDict *qdict)
71 NameInfo *info;
73 info = qmp_query_name(NULL);
74 if (info->has_name) {
75 monitor_printf(mon, "%s\n", info->name);
77 qapi_free_NameInfo(info);
80 void hmp_info_version(Monitor *mon, const QDict *qdict)
82 VersionInfo *info;
84 info = qmp_query_version(NULL);
86 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
87 info->qemu->major, info->qemu->minor, info->qemu->micro,
88 info->package);
90 qapi_free_VersionInfo(info);
93 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
95 KvmInfo *info;
97 info = qmp_query_kvm(NULL);
98 monitor_printf(mon, "kvm support: ");
99 if (info->present) {
100 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
101 } else {
102 monitor_printf(mon, "not compiled\n");
105 qapi_free_KvmInfo(info);
108 void hmp_info_status(Monitor *mon, const QDict *qdict)
110 StatusInfo *info;
112 info = qmp_query_status(NULL);
114 monitor_printf(mon, "VM status: %s%s",
115 info->running ? "running" : "paused",
116 info->singlestep ? " (single step mode)" : "");
118 if (!info->running && info->status != RUN_STATE_PAUSED) {
119 monitor_printf(mon, " (%s)", RunState_str(info->status));
122 monitor_printf(mon, "\n");
124 qapi_free_StatusInfo(info);
127 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
129 UuidInfo *info;
131 info = qmp_query_uuid(NULL);
132 monitor_printf(mon, "%s\n", info->UUID);
133 qapi_free_UuidInfo(info);
136 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
138 ChardevInfoList *char_info, *info;
140 char_info = qmp_query_chardev(NULL);
141 for (info = char_info; info; info = info->next) {
142 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
143 info->value->filename);
146 qapi_free_ChardevInfoList(char_info);
149 void hmp_info_mice(Monitor *mon, const QDict *qdict)
151 MouseInfoList *mice_list, *mouse;
153 mice_list = qmp_query_mice(NULL);
154 if (!mice_list) {
155 monitor_printf(mon, "No mouse devices connected\n");
156 return;
159 for (mouse = mice_list; mouse; mouse = mouse->next) {
160 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
161 mouse->value->current ? '*' : ' ',
162 mouse->value->index, mouse->value->name,
163 mouse->value->absolute ? " (absolute)" : "");
166 qapi_free_MouseInfoList(mice_list);
169 static char *SocketAddress_to_str(SocketAddress *addr)
171 switch (addr->type) {
172 case SOCKET_ADDRESS_TYPE_INET:
173 return g_strdup_printf("tcp:%s:%s",
174 addr->u.inet.host,
175 addr->u.inet.port);
176 case SOCKET_ADDRESS_TYPE_UNIX:
177 return g_strdup_printf("unix:%s",
178 addr->u.q_unix.path);
179 case SOCKET_ADDRESS_TYPE_FD:
180 return g_strdup_printf("fd:%s", addr->u.fd.str);
181 case SOCKET_ADDRESS_TYPE_VSOCK:
182 return g_strdup_printf("tcp:%s:%s",
183 addr->u.vsock.cid,
184 addr->u.vsock.port);
185 default:
186 return g_strdup("unknown address type");
190 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
192 MigrationInfo *info;
193 MigrationCapabilityStatusList *caps, *cap;
195 info = qmp_query_migrate(NULL);
196 caps = qmp_query_migrate_capabilities(NULL);
198 migration_global_dump(mon);
200 /* do not display parameters during setup */
201 if (info->has_status && caps) {
202 monitor_printf(mon, "capabilities: ");
203 for (cap = caps; cap; cap = cap->next) {
204 monitor_printf(mon, "%s: %s ",
205 MigrationCapability_str(cap->value->capability),
206 cap->value->state ? "on" : "off");
208 monitor_printf(mon, "\n");
211 if (info->has_status) {
212 monitor_printf(mon, "Migration status: %s",
213 MigrationStatus_str(info->status));
214 if (info->status == MIGRATION_STATUS_FAILED &&
215 info->has_error_desc) {
216 monitor_printf(mon, " (%s)\n", info->error_desc);
217 } else {
218 monitor_printf(mon, "\n");
221 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
222 info->total_time);
223 if (info->has_expected_downtime) {
224 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
225 info->expected_downtime);
227 if (info->has_downtime) {
228 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
229 info->downtime);
231 if (info->has_setup_time) {
232 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
233 info->setup_time);
237 if (info->has_ram) {
238 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
239 info->ram->transferred >> 10);
240 monitor_printf(mon, "throughput: %0.2f mbps\n",
241 info->ram->mbps);
242 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
243 info->ram->remaining >> 10);
244 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
245 info->ram->total >> 10);
246 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
247 info->ram->duplicate);
248 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
249 info->ram->skipped);
250 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
251 info->ram->normal);
252 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
253 info->ram->normal_bytes >> 10);
254 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
255 info->ram->dirty_sync_count);
256 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
257 info->ram->page_size >> 10);
258 monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n",
259 info->ram->multifd_bytes >> 10);
260 monitor_printf(mon, "pages-per-second: %" PRIu64 "\n",
261 info->ram->pages_per_second);
263 if (info->ram->dirty_pages_rate) {
264 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
265 info->ram->dirty_pages_rate);
267 if (info->ram->postcopy_requests) {
268 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
269 info->ram->postcopy_requests);
273 if (info->has_disk) {
274 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
275 info->disk->transferred >> 10);
276 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
277 info->disk->remaining >> 10);
278 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
279 info->disk->total >> 10);
282 if (info->has_xbzrle_cache) {
283 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
284 info->xbzrle_cache->cache_size);
285 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
286 info->xbzrle_cache->bytes >> 10);
287 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
288 info->xbzrle_cache->pages);
289 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
290 info->xbzrle_cache->cache_miss);
291 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
292 info->xbzrle_cache->cache_miss_rate);
293 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
294 info->xbzrle_cache->overflow);
297 if (info->has_compression) {
298 monitor_printf(mon, "compression pages: %" PRIu64 " pages\n",
299 info->compression->pages);
300 monitor_printf(mon, "compression busy: %" PRIu64 "\n",
301 info->compression->busy);
302 monitor_printf(mon, "compression busy rate: %0.2f\n",
303 info->compression->busy_rate);
304 monitor_printf(mon, "compressed size: %" PRIu64 "\n",
305 info->compression->compressed_size);
306 monitor_printf(mon, "compression rate: %0.2f\n",
307 info->compression->compression_rate);
310 if (info->has_cpu_throttle_percentage) {
311 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
312 info->cpu_throttle_percentage);
315 if (info->has_postcopy_blocktime) {
316 monitor_printf(mon, "postcopy blocktime: %u\n",
317 info->postcopy_blocktime);
320 if (info->has_postcopy_vcpu_blocktime) {
321 Visitor *v;
322 char *str;
323 v = string_output_visitor_new(false, &str);
324 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NULL);
325 visit_complete(v, &str);
326 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
327 g_free(str);
328 visit_free(v);
330 if (info->has_socket_address) {
331 SocketAddressList *addr;
333 monitor_printf(mon, "socket address: [\n");
335 for (addr = info->socket_address; addr; addr = addr->next) {
336 char *s = SocketAddress_to_str(addr->value);
337 monitor_printf(mon, "\t%s\n", s);
338 g_free(s);
340 monitor_printf(mon, "]\n");
342 qapi_free_MigrationInfo(info);
343 qapi_free_MigrationCapabilityStatusList(caps);
346 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
348 MigrationCapabilityStatusList *caps, *cap;
350 caps = qmp_query_migrate_capabilities(NULL);
352 if (caps) {
353 for (cap = caps; cap; cap = cap->next) {
354 monitor_printf(mon, "%s: %s\n",
355 MigrationCapability_str(cap->value->capability),
356 cap->value->state ? "on" : "off");
360 qapi_free_MigrationCapabilityStatusList(caps);
363 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
365 MigrationParameters *params;
367 params = qmp_query_migrate_parameters(NULL);
369 if (params) {
370 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
371 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL),
372 params->announce_initial);
373 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
374 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX),
375 params->announce_max);
376 monitor_printf(mon, "%s: %" PRIu64 "\n",
377 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS),
378 params->announce_rounds);
379 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
380 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP),
381 params->announce_step);
382 assert(params->has_compress_level);
383 monitor_printf(mon, "%s: %u\n",
384 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
385 params->compress_level);
386 assert(params->has_compress_threads);
387 monitor_printf(mon, "%s: %u\n",
388 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
389 params->compress_threads);
390 assert(params->has_compress_wait_thread);
391 monitor_printf(mon, "%s: %s\n",
392 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD),
393 params->compress_wait_thread ? "on" : "off");
394 assert(params->has_decompress_threads);
395 monitor_printf(mon, "%s: %u\n",
396 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
397 params->decompress_threads);
398 assert(params->has_cpu_throttle_initial);
399 monitor_printf(mon, "%s: %u\n",
400 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
401 params->cpu_throttle_initial);
402 assert(params->has_cpu_throttle_increment);
403 monitor_printf(mon, "%s: %u\n",
404 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
405 params->cpu_throttle_increment);
406 assert(params->has_max_cpu_throttle);
407 monitor_printf(mon, "%s: %u\n",
408 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE),
409 params->max_cpu_throttle);
410 assert(params->has_tls_creds);
411 monitor_printf(mon, "%s: '%s'\n",
412 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
413 params->tls_creds);
414 assert(params->has_tls_hostname);
415 monitor_printf(mon, "%s: '%s'\n",
416 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
417 params->tls_hostname);
418 assert(params->has_max_bandwidth);
419 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
420 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
421 params->max_bandwidth);
422 assert(params->has_downtime_limit);
423 monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n",
424 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
425 params->downtime_limit);
426 assert(params->has_x_checkpoint_delay);
427 monitor_printf(mon, "%s: %u\n",
428 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
429 params->x_checkpoint_delay);
430 assert(params->has_block_incremental);
431 monitor_printf(mon, "%s: %s\n",
432 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
433 params->block_incremental ? "on" : "off");
434 monitor_printf(mon, "%s: %u\n",
435 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_CHANNELS),
436 params->x_multifd_channels);
437 monitor_printf(mon, "%s: %u\n",
438 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT),
439 params->x_multifd_page_count);
440 monitor_printf(mon, "%s: %" PRIu64 "\n",
441 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
442 params->xbzrle_cache_size);
443 monitor_printf(mon, "%s: %" PRIu64 "\n",
444 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
445 params->max_postcopy_bandwidth);
448 qapi_free_MigrationParameters(params);
451 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
453 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
454 qmp_query_migrate_cache_size(NULL) >> 10);
457 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
459 CpuInfoFastList *cpu_list, *cpu;
461 cpu_list = qmp_query_cpus_fast(NULL);
463 for (cpu = cpu_list; cpu; cpu = cpu->next) {
464 int active = ' ';
466 if (cpu->value->cpu_index == monitor_get_cpu_index()) {
467 active = '*';
470 monitor_printf(mon, "%c CPU #%" PRId64 ":", active,
471 cpu->value->cpu_index);
472 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
475 qapi_free_CpuInfoFastList(cpu_list);
478 static void print_block_info(Monitor *mon, BlockInfo *info,
479 BlockDeviceInfo *inserted, bool verbose)
481 ImageInfo *image_info;
483 assert(!info || !info->has_inserted || info->inserted == inserted);
485 if (info && *info->device) {
486 monitor_printf(mon, "%s", info->device);
487 if (inserted && inserted->has_node_name) {
488 monitor_printf(mon, " (%s)", inserted->node_name);
490 } else {
491 assert(info || inserted);
492 monitor_printf(mon, "%s",
493 inserted && inserted->has_node_name ? inserted->node_name
494 : info && info->has_qdev ? info->qdev
495 : "<anonymous>");
498 if (inserted) {
499 monitor_printf(mon, ": %s (%s%s%s)\n",
500 inserted->file,
501 inserted->drv,
502 inserted->ro ? ", read-only" : "",
503 inserted->encrypted ? ", encrypted" : "");
504 } else {
505 monitor_printf(mon, ": [not inserted]\n");
508 if (info) {
509 if (info->has_qdev) {
510 monitor_printf(mon, " Attached to: %s\n", info->qdev);
512 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
513 monitor_printf(mon, " I/O status: %s\n",
514 BlockDeviceIoStatus_str(info->io_status));
517 if (info->removable) {
518 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
519 info->locked ? "" : "not ",
520 info->tray_open ? "open" : "closed");
525 if (!inserted) {
526 return;
529 monitor_printf(mon, " Cache mode: %s%s%s\n",
530 inserted->cache->writeback ? "writeback" : "writethrough",
531 inserted->cache->direct ? ", direct" : "",
532 inserted->cache->no_flush ? ", ignore flushes" : "");
534 if (inserted->has_backing_file) {
535 monitor_printf(mon,
536 " Backing file: %s "
537 "(chain depth: %" PRId64 ")\n",
538 inserted->backing_file,
539 inserted->backing_file_depth);
542 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
543 monitor_printf(mon, " Detect zeroes: %s\n",
544 BlockdevDetectZeroesOptions_str(inserted->detect_zeroes));
547 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
548 inserted->iops || inserted->iops_rd || inserted->iops_wr)
550 monitor_printf(mon, " I/O throttling: bps=%" PRId64
551 " bps_rd=%" PRId64 " bps_wr=%" PRId64
552 " bps_max=%" PRId64
553 " bps_rd_max=%" PRId64
554 " bps_wr_max=%" PRId64
555 " iops=%" PRId64 " iops_rd=%" PRId64
556 " iops_wr=%" PRId64
557 " iops_max=%" PRId64
558 " iops_rd_max=%" PRId64
559 " iops_wr_max=%" PRId64
560 " iops_size=%" PRId64
561 " group=%s\n",
562 inserted->bps,
563 inserted->bps_rd,
564 inserted->bps_wr,
565 inserted->bps_max,
566 inserted->bps_rd_max,
567 inserted->bps_wr_max,
568 inserted->iops,
569 inserted->iops_rd,
570 inserted->iops_wr,
571 inserted->iops_max,
572 inserted->iops_rd_max,
573 inserted->iops_wr_max,
574 inserted->iops_size,
575 inserted->group);
578 if (verbose) {
579 monitor_printf(mon, "\nImages:\n");
580 image_info = inserted->image;
581 while (1) {
582 bdrv_image_info_dump((fprintf_function)monitor_printf,
583 mon, image_info);
584 if (image_info->has_backing_image) {
585 image_info = image_info->backing_image;
586 } else {
587 break;
593 void hmp_info_block(Monitor *mon, const QDict *qdict)
595 BlockInfoList *block_list, *info;
596 BlockDeviceInfoList *blockdev_list, *blockdev;
597 const char *device = qdict_get_try_str(qdict, "device");
598 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
599 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
600 bool printed = false;
602 /* Print BlockBackend information */
603 if (!nodes) {
604 block_list = qmp_query_block(NULL);
605 } else {
606 block_list = NULL;
609 for (info = block_list; info; info = info->next) {
610 if (device && strcmp(device, info->value->device)) {
611 continue;
614 if (info != block_list) {
615 monitor_printf(mon, "\n");
618 print_block_info(mon, info->value, info->value->has_inserted
619 ? info->value->inserted : NULL,
620 verbose);
621 printed = true;
624 qapi_free_BlockInfoList(block_list);
626 if ((!device && !nodes) || printed) {
627 return;
630 /* Print node information */
631 blockdev_list = qmp_query_named_block_nodes(NULL);
632 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
633 assert(blockdev->value->has_node_name);
634 if (device && strcmp(device, blockdev->value->node_name)) {
635 continue;
638 if (blockdev != blockdev_list) {
639 monitor_printf(mon, "\n");
642 print_block_info(mon, NULL, blockdev->value, verbose);
644 qapi_free_BlockDeviceInfoList(blockdev_list);
647 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
649 BlockStatsList *stats_list, *stats;
651 stats_list = qmp_query_blockstats(false, false, NULL);
653 for (stats = stats_list; stats; stats = stats->next) {
654 if (!stats->value->has_device) {
655 continue;
658 monitor_printf(mon, "%s:", stats->value->device);
659 monitor_printf(mon, " rd_bytes=%" PRId64
660 " wr_bytes=%" PRId64
661 " rd_operations=%" PRId64
662 " wr_operations=%" PRId64
663 " flush_operations=%" PRId64
664 " wr_total_time_ns=%" PRId64
665 " rd_total_time_ns=%" PRId64
666 " flush_total_time_ns=%" PRId64
667 " rd_merged=%" PRId64
668 " wr_merged=%" PRId64
669 " idle_time_ns=%" PRId64
670 "\n",
671 stats->value->stats->rd_bytes,
672 stats->value->stats->wr_bytes,
673 stats->value->stats->rd_operations,
674 stats->value->stats->wr_operations,
675 stats->value->stats->flush_operations,
676 stats->value->stats->wr_total_time_ns,
677 stats->value->stats->rd_total_time_ns,
678 stats->value->stats->flush_total_time_ns,
679 stats->value->stats->rd_merged,
680 stats->value->stats->wr_merged,
681 stats->value->stats->idle_time_ns);
684 qapi_free_BlockStatsList(stats_list);
687 #ifdef CONFIG_VNC
688 /* Helper for hmp_info_vnc_clients, _servers */
689 static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
690 const char *name)
692 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
693 name,
694 info->host,
695 info->service,
696 NetworkAddressFamily_str(info->family),
697 info->websocket ? " (Websocket)" : "");
700 /* Helper displaying and auth and crypt info */
701 static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
702 VncPrimaryAuth auth,
703 VncVencryptSubAuth *vencrypt)
705 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
706 VncPrimaryAuth_str(auth),
707 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
710 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
712 while (client) {
713 VncClientInfo *cinfo = client->value;
715 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
716 monitor_printf(mon, " x509_dname: %s\n",
717 cinfo->has_x509_dname ?
718 cinfo->x509_dname : "none");
719 monitor_printf(mon, " sasl_username: %s\n",
720 cinfo->has_sasl_username ?
721 cinfo->sasl_username : "none");
723 client = client->next;
727 static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
729 while (server) {
730 VncServerInfo2 *sinfo = server->value;
731 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
732 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
733 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
734 server = server->next;
738 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
740 VncInfo2List *info2l;
741 Error *err = NULL;
743 info2l = qmp_query_vnc_servers(&err);
744 if (err) {
745 hmp_handle_error(mon, &err);
746 return;
748 if (!info2l) {
749 monitor_printf(mon, "None\n");
750 return;
753 while (info2l) {
754 VncInfo2 *info = info2l->value;
755 monitor_printf(mon, "%s:\n", info->id);
756 hmp_info_vnc_servers(mon, info->server);
757 hmp_info_vnc_clients(mon, info->clients);
758 if (!info->server) {
759 /* The server entry displays its auth, we only
760 * need to display in the case of 'reverse' connections
761 * where there's no server.
763 hmp_info_vnc_authcrypt(mon, " ", info->auth,
764 info->has_vencrypt ? &info->vencrypt : NULL);
766 if (info->has_display) {
767 monitor_printf(mon, " Display: %s\n", info->display);
769 info2l = info2l->next;
772 qapi_free_VncInfo2List(info2l);
775 #endif
777 #ifdef CONFIG_SPICE
778 void hmp_info_spice(Monitor *mon, const QDict *qdict)
780 SpiceChannelList *chan;
781 SpiceInfo *info;
782 const char *channel_name;
783 const char * const channel_names[] = {
784 [SPICE_CHANNEL_MAIN] = "main",
785 [SPICE_CHANNEL_DISPLAY] = "display",
786 [SPICE_CHANNEL_INPUTS] = "inputs",
787 [SPICE_CHANNEL_CURSOR] = "cursor",
788 [SPICE_CHANNEL_PLAYBACK] = "playback",
789 [SPICE_CHANNEL_RECORD] = "record",
790 [SPICE_CHANNEL_TUNNEL] = "tunnel",
791 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
792 [SPICE_CHANNEL_USBREDIR] = "usbredir",
793 [SPICE_CHANNEL_PORT] = "port",
794 #if 0
795 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
796 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
797 * as quick fix for build failures with older versions. */
798 [SPICE_CHANNEL_WEBDAV] = "webdav",
799 #endif
802 info = qmp_query_spice(NULL);
804 if (!info->enabled) {
805 monitor_printf(mon, "Server: disabled\n");
806 goto out;
809 monitor_printf(mon, "Server:\n");
810 if (info->has_port) {
811 monitor_printf(mon, " address: %s:%" PRId64 "\n",
812 info->host, info->port);
814 if (info->has_tls_port) {
815 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
816 info->host, info->tls_port);
818 monitor_printf(mon, " migrated: %s\n",
819 info->migrated ? "true" : "false");
820 monitor_printf(mon, " auth: %s\n", info->auth);
821 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
822 monitor_printf(mon, " mouse-mode: %s\n",
823 SpiceQueryMouseMode_str(info->mouse_mode));
825 if (!info->has_channels || info->channels == NULL) {
826 monitor_printf(mon, "Channels: none\n");
827 } else {
828 for (chan = info->channels; chan; chan = chan->next) {
829 monitor_printf(mon, "Channel:\n");
830 monitor_printf(mon, " address: %s:%s%s\n",
831 chan->value->host, chan->value->port,
832 chan->value->tls ? " [tls]" : "");
833 monitor_printf(mon, " session: %" PRId64 "\n",
834 chan->value->connection_id);
835 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
836 chan->value->channel_type, chan->value->channel_id);
838 channel_name = "unknown";
839 if (chan->value->channel_type > 0 &&
840 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
841 channel_names[chan->value->channel_type]) {
842 channel_name = channel_names[chan->value->channel_type];
845 monitor_printf(mon, " channel name: %s\n", channel_name);
849 out:
850 qapi_free_SpiceInfo(info);
852 #endif
854 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
856 BalloonInfo *info;
857 Error *err = NULL;
859 info = qmp_query_balloon(&err);
860 if (err) {
861 hmp_handle_error(mon, &err);
862 return;
865 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
867 qapi_free_BalloonInfo(info);
870 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
872 PciMemoryRegionList *region;
874 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
875 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
876 dev->slot, dev->function);
877 monitor_printf(mon, " ");
879 if (dev->class_info->has_desc) {
880 monitor_printf(mon, "%s", dev->class_info->desc);
881 } else {
882 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
885 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
886 dev->id->vendor, dev->id->device);
887 if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) {
888 monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n",
889 dev->id->subsystem_vendor, dev->id->subsystem);
892 if (dev->has_irq) {
893 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
896 if (dev->has_pci_bridge) {
897 monitor_printf(mon, " BUS %" PRId64 ".\n",
898 dev->pci_bridge->bus->number);
899 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
900 dev->pci_bridge->bus->secondary);
901 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
902 dev->pci_bridge->bus->subordinate);
904 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
905 dev->pci_bridge->bus->io_range->base,
906 dev->pci_bridge->bus->io_range->limit);
908 monitor_printf(mon,
909 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
910 dev->pci_bridge->bus->memory_range->base,
911 dev->pci_bridge->bus->memory_range->limit);
913 monitor_printf(mon, " prefetchable memory range "
914 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
915 dev->pci_bridge->bus->prefetchable_range->base,
916 dev->pci_bridge->bus->prefetchable_range->limit);
919 for (region = dev->regions; region; region = region->next) {
920 uint64_t addr, size;
922 addr = region->value->address;
923 size = region->value->size;
925 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
927 if (!strcmp(region->value->type, "io")) {
928 monitor_printf(mon, "I/O at 0x%04" PRIx64
929 " [0x%04" PRIx64 "].\n",
930 addr, addr + size - 1);
931 } else {
932 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
933 " [0x%08" PRIx64 "].\n",
934 region->value->mem_type_64 ? 64 : 32,
935 region->value->prefetch ? " prefetchable" : "",
936 addr, addr + size - 1);
940 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
942 if (dev->has_pci_bridge) {
943 if (dev->pci_bridge->has_devices) {
944 PciDeviceInfoList *cdev;
945 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
946 hmp_info_pci_device(mon, cdev->value);
952 static int hmp_info_irq_foreach(Object *obj, void *opaque)
954 InterruptStatsProvider *intc;
955 InterruptStatsProviderClass *k;
956 Monitor *mon = opaque;
958 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
959 intc = INTERRUPT_STATS_PROVIDER(obj);
960 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
961 uint64_t *irq_counts;
962 unsigned int nb_irqs, i;
963 if (k->get_statistics &&
964 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
965 if (nb_irqs > 0) {
966 monitor_printf(mon, "IRQ statistics for %s:\n",
967 object_get_typename(obj));
968 for (i = 0; i < nb_irqs; i++) {
969 if (irq_counts[i] > 0) {
970 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
971 irq_counts[i]);
975 } else {
976 monitor_printf(mon, "IRQ statistics not available for %s.\n",
977 object_get_typename(obj));
981 return 0;
984 void hmp_info_irq(Monitor *mon, const QDict *qdict)
986 object_child_foreach_recursive(object_get_root(),
987 hmp_info_irq_foreach, mon);
990 static int hmp_info_pic_foreach(Object *obj, void *opaque)
992 InterruptStatsProvider *intc;
993 InterruptStatsProviderClass *k;
994 Monitor *mon = opaque;
996 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
997 intc = INTERRUPT_STATS_PROVIDER(obj);
998 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
999 if (k->print_info) {
1000 k->print_info(intc, mon);
1001 } else {
1002 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
1003 object_get_typename(obj));
1007 return 0;
1010 void hmp_info_pic(Monitor *mon, const QDict *qdict)
1012 object_child_foreach_recursive(object_get_root(),
1013 hmp_info_pic_foreach, mon);
1016 void hmp_info_pci(Monitor *mon, const QDict *qdict)
1018 PciInfoList *info_list, *info;
1019 Error *err = NULL;
1021 info_list = qmp_query_pci(&err);
1022 if (err) {
1023 monitor_printf(mon, "PCI devices not supported\n");
1024 error_free(err);
1025 return;
1028 for (info = info_list; info; info = info->next) {
1029 PciDeviceInfoList *dev;
1031 for (dev = info->value->devices; dev; dev = dev->next) {
1032 hmp_info_pci_device(mon, dev->value);
1036 qapi_free_PciInfoList(info_list);
1039 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
1041 BlockJobInfoList *list;
1042 Error *err = NULL;
1044 list = qmp_query_block_jobs(&err);
1045 assert(!err);
1047 if (!list) {
1048 monitor_printf(mon, "No active jobs\n");
1049 return;
1052 while (list) {
1053 if (strcmp(list->value->type, "stream") == 0) {
1054 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
1055 " of %" PRId64 " bytes, speed limit %" PRId64
1056 " bytes/s\n",
1057 list->value->device,
1058 list->value->offset,
1059 list->value->len,
1060 list->value->speed);
1061 } else {
1062 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
1063 " of %" PRId64 " bytes, speed limit %" PRId64
1064 " bytes/s\n",
1065 list->value->type,
1066 list->value->device,
1067 list->value->offset,
1068 list->value->len,
1069 list->value->speed);
1071 list = list->next;
1074 qapi_free_BlockJobInfoList(list);
1077 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
1079 TPMInfoList *info_list, *info;
1080 Error *err = NULL;
1081 unsigned int c = 0;
1082 TPMPassthroughOptions *tpo;
1083 TPMEmulatorOptions *teo;
1085 info_list = qmp_query_tpm(&err);
1086 if (err) {
1087 monitor_printf(mon, "TPM device not supported\n");
1088 error_free(err);
1089 return;
1092 if (info_list) {
1093 monitor_printf(mon, "TPM device:\n");
1096 for (info = info_list; info; info = info->next) {
1097 TPMInfo *ti = info->value;
1098 monitor_printf(mon, " tpm%d: model=%s\n",
1099 c, TpmModel_str(ti->model));
1101 monitor_printf(mon, " \\ %s: type=%s",
1102 ti->id, TpmTypeOptionsKind_str(ti->options->type));
1104 switch (ti->options->type) {
1105 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
1106 tpo = ti->options->u.passthrough.data;
1107 monitor_printf(mon, "%s%s%s%s",
1108 tpo->has_path ? ",path=" : "",
1109 tpo->has_path ? tpo->path : "",
1110 tpo->has_cancel_path ? ",cancel-path=" : "",
1111 tpo->has_cancel_path ? tpo->cancel_path : "");
1112 break;
1113 case TPM_TYPE_OPTIONS_KIND_EMULATOR:
1114 teo = ti->options->u.emulator.data;
1115 monitor_printf(mon, ",chardev=%s", teo->chardev);
1116 break;
1117 case TPM_TYPE_OPTIONS_KIND__MAX:
1118 break;
1120 monitor_printf(mon, "\n");
1121 c++;
1123 qapi_free_TPMInfoList(info_list);
1126 void hmp_quit(Monitor *mon, const QDict *qdict)
1128 monitor_suspend(mon);
1129 qmp_quit(NULL);
1132 void hmp_stop(Monitor *mon, const QDict *qdict)
1134 qmp_stop(NULL);
1137 void hmp_sync_profile(Monitor *mon, const QDict *qdict)
1139 const char *op = qdict_get_try_str(qdict, "op");
1141 if (op == NULL) {
1142 bool on = qsp_is_enabled();
1144 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off");
1145 return;
1147 if (!strcmp(op, "on")) {
1148 qsp_enable();
1149 } else if (!strcmp(op, "off")) {
1150 qsp_disable();
1151 } else if (!strcmp(op, "reset")) {
1152 qsp_reset();
1153 } else {
1154 Error *err = NULL;
1156 error_setg(&err, QERR_INVALID_PARAMETER, op);
1157 hmp_handle_error(mon, &err);
1161 void hmp_system_reset(Monitor *mon, const QDict *qdict)
1163 qmp_system_reset(NULL);
1166 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
1168 qmp_system_powerdown(NULL);
1171 void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
1173 Error *err = NULL;
1175 qmp_x_exit_preconfig(&err);
1176 hmp_handle_error(mon, &err);
1179 void hmp_cpu(Monitor *mon, const QDict *qdict)
1181 int64_t cpu_index;
1183 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1184 use it are converted to the QAPI */
1185 cpu_index = qdict_get_int(qdict, "index");
1186 if (monitor_set_cpu(cpu_index) < 0) {
1187 monitor_printf(mon, "invalid CPU index\n");
1191 void hmp_memsave(Monitor *mon, const QDict *qdict)
1193 uint32_t size = qdict_get_int(qdict, "size");
1194 const char *filename = qdict_get_str(qdict, "filename");
1195 uint64_t addr = qdict_get_int(qdict, "val");
1196 Error *err = NULL;
1197 int cpu_index = monitor_get_cpu_index();
1199 if (cpu_index < 0) {
1200 monitor_printf(mon, "No CPU available\n");
1201 return;
1204 qmp_memsave(addr, size, filename, true, cpu_index, &err);
1205 hmp_handle_error(mon, &err);
1208 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1210 uint32_t size = qdict_get_int(qdict, "size");
1211 const char *filename = qdict_get_str(qdict, "filename");
1212 uint64_t addr = qdict_get_int(qdict, "val");
1213 Error *err = NULL;
1215 qmp_pmemsave(addr, size, filename, &err);
1216 hmp_handle_error(mon, &err);
1219 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1221 const char *chardev = qdict_get_str(qdict, "device");
1222 const char *data = qdict_get_str(qdict, "data");
1223 Error *err = NULL;
1225 qmp_ringbuf_write(chardev, data, false, 0, &err);
1227 hmp_handle_error(mon, &err);
1230 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
1232 uint32_t size = qdict_get_int(qdict, "size");
1233 const char *chardev = qdict_get_str(qdict, "device");
1234 char *data;
1235 Error *err = NULL;
1236 int i;
1238 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1239 if (err) {
1240 hmp_handle_error(mon, &err);
1241 return;
1244 for (i = 0; data[i]; i++) {
1245 unsigned char ch = data[i];
1247 if (ch == '\\') {
1248 monitor_printf(mon, "\\\\");
1249 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1250 monitor_printf(mon, "\\u%04X", ch);
1251 } else {
1252 monitor_printf(mon, "%c", ch);
1256 monitor_printf(mon, "\n");
1257 g_free(data);
1260 void hmp_cont(Monitor *mon, const QDict *qdict)
1262 Error *err = NULL;
1264 qmp_cont(&err);
1265 hmp_handle_error(mon, &err);
1268 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1270 Error *err = NULL;
1272 qmp_system_wakeup(&err);
1273 hmp_handle_error(mon, &err);
1276 void hmp_nmi(Monitor *mon, const QDict *qdict)
1278 Error *err = NULL;
1280 qmp_inject_nmi(&err);
1281 hmp_handle_error(mon, &err);
1284 void hmp_set_link(Monitor *mon, const QDict *qdict)
1286 const char *name = qdict_get_str(qdict, "name");
1287 bool up = qdict_get_bool(qdict, "up");
1288 Error *err = NULL;
1290 qmp_set_link(name, up, &err);
1291 hmp_handle_error(mon, &err);
1294 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1296 const char *device = qdict_get_str(qdict, "device");
1297 const char *password = qdict_get_str(qdict, "password");
1298 Error *err = NULL;
1300 qmp_block_passwd(true, device, false, NULL, password, &err);
1301 hmp_handle_error(mon, &err);
1304 void hmp_balloon(Monitor *mon, const QDict *qdict)
1306 int64_t value = qdict_get_int(qdict, "value");
1307 Error *err = NULL;
1309 qmp_balloon(value, &err);
1310 hmp_handle_error(mon, &err);
1313 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1315 const char *device = qdict_get_str(qdict, "device");
1316 int64_t size = qdict_get_int(qdict, "size");
1317 Error *err = NULL;
1319 qmp_block_resize(true, device, false, NULL, size, &err);
1320 hmp_handle_error(mon, &err);
1323 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1325 const char *filename = qdict_get_str(qdict, "target");
1326 const char *format = qdict_get_try_str(qdict, "format");
1327 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1328 bool full = qdict_get_try_bool(qdict, "full", false);
1329 Error *err = NULL;
1330 DriveMirror mirror = {
1331 .device = (char *)qdict_get_str(qdict, "device"),
1332 .target = (char *)filename,
1333 .has_format = !!format,
1334 .format = (char *)format,
1335 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1336 .has_mode = true,
1337 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1338 .unmap = true,
1341 if (!filename) {
1342 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1343 hmp_handle_error(mon, &err);
1344 return;
1346 qmp_drive_mirror(&mirror, &err);
1347 hmp_handle_error(mon, &err);
1350 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1352 const char *device = qdict_get_str(qdict, "device");
1353 const char *filename = qdict_get_str(qdict, "target");
1354 const char *format = qdict_get_try_str(qdict, "format");
1355 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1356 bool full = qdict_get_try_bool(qdict, "full", false);
1357 bool compress = qdict_get_try_bool(qdict, "compress", false);
1358 Error *err = NULL;
1359 DriveBackup backup = {
1360 .device = (char *)device,
1361 .target = (char *)filename,
1362 .has_format = !!format,
1363 .format = (char *)format,
1364 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1365 .has_mode = true,
1366 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1367 .has_compress = !!compress,
1368 .compress = compress,
1371 if (!filename) {
1372 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1373 hmp_handle_error(mon, &err);
1374 return;
1377 qmp_drive_backup(&backup, &err);
1378 hmp_handle_error(mon, &err);
1381 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1383 const char *device = qdict_get_str(qdict, "device");
1384 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1385 const char *format = qdict_get_try_str(qdict, "format");
1386 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1387 enum NewImageMode mode;
1388 Error *err = NULL;
1390 if (!filename) {
1391 /* In the future, if 'snapshot-file' is not specified, the snapshot
1392 will be taken internally. Today it's actually required. */
1393 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1394 hmp_handle_error(mon, &err);
1395 return;
1398 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1399 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1400 filename, false, NULL,
1401 !!format, format,
1402 true, mode, &err);
1403 hmp_handle_error(mon, &err);
1406 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1408 const char *device = qdict_get_str(qdict, "device");
1409 const char *name = qdict_get_str(qdict, "name");
1410 Error *err = NULL;
1412 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1413 hmp_handle_error(mon, &err);
1416 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1418 const char *device = qdict_get_str(qdict, "device");
1419 const char *name = qdict_get_str(qdict, "name");
1420 const char *id = qdict_get_try_str(qdict, "id");
1421 Error *err = NULL;
1423 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1424 true, name, &err);
1425 hmp_handle_error(mon, &err);
1428 void hmp_loadvm(Monitor *mon, const QDict *qdict)
1430 int saved_vm_running = runstate_is_running();
1431 const char *name = qdict_get_str(qdict, "name");
1432 Error *err = NULL;
1434 vm_stop(RUN_STATE_RESTORE_VM);
1436 if (load_snapshot(name, &err) == 0 && saved_vm_running) {
1437 vm_start();
1439 hmp_handle_error(mon, &err);
1442 void hmp_savevm(Monitor *mon, const QDict *qdict)
1444 Error *err = NULL;
1446 save_snapshot(qdict_get_try_str(qdict, "name"), &err);
1447 hmp_handle_error(mon, &err);
1450 void hmp_delvm(Monitor *mon, const QDict *qdict)
1452 BlockDriverState *bs;
1453 Error *err = NULL;
1454 const char *name = qdict_get_str(qdict, "name");
1456 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
1457 error_reportf_err(err,
1458 "Error while deleting snapshot on device '%s': ",
1459 bdrv_get_device_name(bs));
1463 void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
1465 BlockDriverState *bs, *bs1;
1466 BdrvNextIterator it1;
1467 QEMUSnapshotInfo *sn_tab, *sn;
1468 bool no_snapshot = true;
1469 int nb_sns, i;
1470 int total;
1471 int *global_snapshots;
1472 AioContext *aio_context;
1474 typedef struct SnapshotEntry {
1475 QEMUSnapshotInfo sn;
1476 QTAILQ_ENTRY(SnapshotEntry) next;
1477 } SnapshotEntry;
1479 typedef struct ImageEntry {
1480 const char *imagename;
1481 QTAILQ_ENTRY(ImageEntry) next;
1482 QTAILQ_HEAD(, SnapshotEntry) snapshots;
1483 } ImageEntry;
1485 QTAILQ_HEAD(, ImageEntry) image_list =
1486 QTAILQ_HEAD_INITIALIZER(image_list);
1488 ImageEntry *image_entry, *next_ie;
1489 SnapshotEntry *snapshot_entry;
1491 bs = bdrv_all_find_vmstate_bs();
1492 if (!bs) {
1493 monitor_printf(mon, "No available block device supports snapshots\n");
1494 return;
1496 aio_context = bdrv_get_aio_context(bs);
1498 aio_context_acquire(aio_context);
1499 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
1500 aio_context_release(aio_context);
1502 if (nb_sns < 0) {
1503 monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
1504 return;
1507 for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) {
1508 int bs1_nb_sns = 0;
1509 ImageEntry *ie;
1510 SnapshotEntry *se;
1511 AioContext *ctx = bdrv_get_aio_context(bs1);
1513 aio_context_acquire(ctx);
1514 if (bdrv_can_snapshot(bs1)) {
1515 sn = NULL;
1516 bs1_nb_sns = bdrv_snapshot_list(bs1, &sn);
1517 if (bs1_nb_sns > 0) {
1518 no_snapshot = false;
1519 ie = g_new0(ImageEntry, 1);
1520 ie->imagename = bdrv_get_device_name(bs1);
1521 QTAILQ_INIT(&ie->snapshots);
1522 QTAILQ_INSERT_TAIL(&image_list, ie, next);
1523 for (i = 0; i < bs1_nb_sns; i++) {
1524 se = g_new0(SnapshotEntry, 1);
1525 se->sn = sn[i];
1526 QTAILQ_INSERT_TAIL(&ie->snapshots, se, next);
1529 g_free(sn);
1531 aio_context_release(ctx);
1534 if (no_snapshot) {
1535 monitor_printf(mon, "There is no snapshot available.\n");
1536 return;
1539 global_snapshots = g_new0(int, nb_sns);
1540 total = 0;
1541 for (i = 0; i < nb_sns; i++) {
1542 SnapshotEntry *next_sn;
1543 if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) {
1544 global_snapshots[total] = i;
1545 total++;
1546 QTAILQ_FOREACH(image_entry, &image_list, next) {
1547 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots,
1548 next, next_sn) {
1549 if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) {
1550 QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry,
1551 next);
1552 g_free(snapshot_entry);
1559 monitor_printf(mon, "List of snapshots present on all disks:\n");
1561 if (total > 0) {
1562 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1563 monitor_printf(mon, "\n");
1564 for (i = 0; i < total; i++) {
1565 sn = &sn_tab[global_snapshots[i]];
1566 /* The ID is not guaranteed to be the same on all images, so
1567 * overwrite it.
1569 pstrcpy(sn->id_str, sizeof(sn->id_str), "--");
1570 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, sn);
1571 monitor_printf(mon, "\n");
1573 } else {
1574 monitor_printf(mon, "None\n");
1577 QTAILQ_FOREACH(image_entry, &image_list, next) {
1578 if (QTAILQ_EMPTY(&image_entry->snapshots)) {
1579 continue;
1581 monitor_printf(mon,
1582 "\nList of partial (non-loadable) snapshots on '%s':\n",
1583 image_entry->imagename);
1584 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1585 monitor_printf(mon, "\n");
1586 QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) {
1587 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon,
1588 &snapshot_entry->sn);
1589 monitor_printf(mon, "\n");
1593 QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) {
1594 SnapshotEntry *next_sn;
1595 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next,
1596 next_sn) {
1597 g_free(snapshot_entry);
1599 g_free(image_entry);
1601 g_free(sn_tab);
1602 g_free(global_snapshots);
1606 void hmp_announce_self(Monitor *mon, const QDict *qdict)
1608 qmp_announce_self(migrate_announce_params(), NULL);
1611 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1613 qmp_migrate_cancel(NULL);
1616 void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1618 Error *err = NULL;
1619 const char *state = qdict_get_str(qdict, "state");
1620 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1622 if (val >= 0) {
1623 qmp_migrate_continue(val, &err);
1626 hmp_handle_error(mon, &err);
1629 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1631 Error *err = NULL;
1632 const char *uri = qdict_get_str(qdict, "uri");
1634 qmp_migrate_incoming(uri, &err);
1636 hmp_handle_error(mon, &err);
1639 void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
1641 Error *err = NULL;
1642 const char *uri = qdict_get_str(qdict, "uri");
1644 qmp_migrate_recover(uri, &err);
1646 hmp_handle_error(mon, &err);
1649 void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
1651 Error *err = NULL;
1653 qmp_migrate_pause(&err);
1655 hmp_handle_error(mon, &err);
1658 /* Kept for backwards compatibility */
1659 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1661 double value = qdict_get_double(qdict, "value");
1662 qmp_migrate_set_downtime(value, NULL);
1665 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1667 int64_t value = qdict_get_int(qdict, "value");
1668 Error *err = NULL;
1670 qmp_migrate_set_cache_size(value, &err);
1671 hmp_handle_error(mon, &err);
1674 /* Kept for backwards compatibility */
1675 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1677 int64_t value = qdict_get_int(qdict, "value");
1678 qmp_migrate_set_speed(value, NULL);
1681 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1683 const char *cap = qdict_get_str(qdict, "capability");
1684 bool state = qdict_get_bool(qdict, "state");
1685 Error *err = NULL;
1686 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1687 int val;
1689 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
1690 if (val < 0) {
1691 goto end;
1694 caps->value = g_malloc0(sizeof(*caps->value));
1695 caps->value->capability = val;
1696 caps->value->state = state;
1697 caps->next = NULL;
1698 qmp_migrate_set_capabilities(caps, &err);
1700 end:
1701 qapi_free_MigrationCapabilityStatusList(caps);
1702 hmp_handle_error(mon, &err);
1705 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1707 const char *param = qdict_get_str(qdict, "parameter");
1708 const char *valuestr = qdict_get_str(qdict, "value");
1709 Visitor *v = string_input_visitor_new(valuestr);
1710 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
1711 uint64_t valuebw = 0;
1712 uint64_t cache_size;
1713 Error *err = NULL;
1714 int val, ret;
1716 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
1717 if (val < 0) {
1718 goto cleanup;
1721 switch (val) {
1722 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1723 p->has_compress_level = true;
1724 visit_type_int(v, param, &p->compress_level, &err);
1725 break;
1726 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1727 p->has_compress_threads = true;
1728 visit_type_int(v, param, &p->compress_threads, &err);
1729 break;
1730 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD:
1731 p->has_compress_wait_thread = true;
1732 visit_type_bool(v, param, &p->compress_wait_thread, &err);
1733 break;
1734 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1735 p->has_decompress_threads = true;
1736 visit_type_int(v, param, &p->decompress_threads, &err);
1737 break;
1738 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1739 p->has_cpu_throttle_initial = true;
1740 visit_type_int(v, param, &p->cpu_throttle_initial, &err);
1741 break;
1742 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1743 p->has_cpu_throttle_increment = true;
1744 visit_type_int(v, param, &p->cpu_throttle_increment, &err);
1745 break;
1746 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE:
1747 p->has_max_cpu_throttle = true;
1748 visit_type_int(v, param, &p->max_cpu_throttle, &err);
1749 break;
1750 case MIGRATION_PARAMETER_TLS_CREDS:
1751 p->has_tls_creds = true;
1752 p->tls_creds = g_new0(StrOrNull, 1);
1753 p->tls_creds->type = QTYPE_QSTRING;
1754 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1755 break;
1756 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1757 p->has_tls_hostname = true;
1758 p->tls_hostname = g_new0(StrOrNull, 1);
1759 p->tls_hostname->type = QTYPE_QSTRING;
1760 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1761 break;
1762 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1763 p->has_max_bandwidth = true;
1765 * Can't use visit_type_size() here, because it
1766 * defaults to Bytes rather than Mebibytes.
1768 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1769 if (ret < 0 || valuebw > INT64_MAX
1770 || (size_t)valuebw != valuebw) {
1771 error_setg(&err, "Invalid size %s", valuestr);
1772 break;
1774 p->max_bandwidth = valuebw;
1775 break;
1776 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1777 p->has_downtime_limit = true;
1778 visit_type_int(v, param, &p->downtime_limit, &err);
1779 break;
1780 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1781 p->has_x_checkpoint_delay = true;
1782 visit_type_int(v, param, &p->x_checkpoint_delay, &err);
1783 break;
1784 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1785 p->has_block_incremental = true;
1786 visit_type_bool(v, param, &p->block_incremental, &err);
1787 break;
1788 case MIGRATION_PARAMETER_X_MULTIFD_CHANNELS:
1789 p->has_x_multifd_channels = true;
1790 visit_type_int(v, param, &p->x_multifd_channels, &err);
1791 break;
1792 case MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT:
1793 p->has_x_multifd_page_count = true;
1794 visit_type_int(v, param, &p->x_multifd_page_count, &err);
1795 break;
1796 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1797 p->has_xbzrle_cache_size = true;
1798 visit_type_size(v, param, &cache_size, &err);
1799 if (err || cache_size > INT64_MAX
1800 || (size_t)cache_size != cache_size) {
1801 error_setg(&err, "Invalid size %s", valuestr);
1802 break;
1804 p->xbzrle_cache_size = cache_size;
1805 break;
1806 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH:
1807 p->has_max_postcopy_bandwidth = true;
1808 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err);
1809 break;
1810 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL:
1811 p->has_announce_initial = true;
1812 visit_type_size(v, param, &p->announce_initial, &err);
1813 break;
1814 case MIGRATION_PARAMETER_ANNOUNCE_MAX:
1815 p->has_announce_max = true;
1816 visit_type_size(v, param, &p->announce_max, &err);
1817 break;
1818 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS:
1819 p->has_announce_rounds = true;
1820 visit_type_size(v, param, &p->announce_rounds, &err);
1821 break;
1822 case MIGRATION_PARAMETER_ANNOUNCE_STEP:
1823 p->has_announce_step = true;
1824 visit_type_size(v, param, &p->announce_step, &err);
1825 break;
1826 default:
1827 assert(0);
1830 if (err) {
1831 goto cleanup;
1834 qmp_migrate_set_parameters(p, &err);
1836 cleanup:
1837 qapi_free_MigrateSetParameters(p);
1838 visit_free(v);
1839 hmp_handle_error(mon, &err);
1842 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1844 Error *err = NULL;
1845 const char *protocol = qdict_get_str(qdict, "protocol");
1846 const char *hostname = qdict_get_str(qdict, "hostname");
1847 bool has_port = qdict_haskey(qdict, "port");
1848 int port = qdict_get_try_int(qdict, "port", -1);
1849 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1850 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1851 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1853 qmp_client_migrate_info(protocol, hostname,
1854 has_port, port, has_tls_port, tls_port,
1855 !!cert_subject, cert_subject, &err);
1856 hmp_handle_error(mon, &err);
1859 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1861 Error *err = NULL;
1862 qmp_migrate_start_postcopy(&err);
1863 hmp_handle_error(mon, &err);
1866 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1868 Error *err = NULL;
1870 qmp_x_colo_lost_heartbeat(&err);
1871 hmp_handle_error(mon, &err);
1874 void hmp_set_password(Monitor *mon, const QDict *qdict)
1876 const char *protocol = qdict_get_str(qdict, "protocol");
1877 const char *password = qdict_get_str(qdict, "password");
1878 const char *connected = qdict_get_try_str(qdict, "connected");
1879 Error *err = NULL;
1881 qmp_set_password(protocol, password, !!connected, connected, &err);
1882 hmp_handle_error(mon, &err);
1885 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1887 const char *protocol = qdict_get_str(qdict, "protocol");
1888 const char *whenstr = qdict_get_str(qdict, "time");
1889 Error *err = NULL;
1891 qmp_expire_password(protocol, whenstr, &err);
1892 hmp_handle_error(mon, &err);
1895 void hmp_eject(Monitor *mon, const QDict *qdict)
1897 bool force = qdict_get_try_bool(qdict, "force", false);
1898 const char *device = qdict_get_str(qdict, "device");
1899 Error *err = NULL;
1901 qmp_eject(true, device, false, NULL, true, force, &err);
1902 hmp_handle_error(mon, &err);
1905 #ifdef CONFIG_VNC
1906 static void hmp_change_read_arg(void *opaque, const char *password,
1907 void *readline_opaque)
1909 qmp_change_vnc_password(password, NULL);
1910 monitor_read_command(opaque, 1);
1912 #endif
1914 void hmp_change(Monitor *mon, const QDict *qdict)
1916 const char *device = qdict_get_str(qdict, "device");
1917 const char *target = qdict_get_str(qdict, "target");
1918 const char *arg = qdict_get_try_str(qdict, "arg");
1919 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1920 BlockdevChangeReadOnlyMode read_only_mode = 0;
1921 Error *err = NULL;
1923 #ifdef CONFIG_VNC
1924 if (strcmp(device, "vnc") == 0) {
1925 if (read_only) {
1926 monitor_printf(mon,
1927 "Parameter 'read-only-mode' is invalid for VNC\n");
1928 return;
1930 if (strcmp(target, "passwd") == 0 ||
1931 strcmp(target, "password") == 0) {
1932 if (!arg) {
1933 monitor_read_password(mon, hmp_change_read_arg, NULL);
1934 return;
1937 qmp_change("vnc", target, !!arg, arg, &err);
1938 } else
1939 #endif
1941 if (read_only) {
1942 read_only_mode =
1943 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
1944 read_only,
1945 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1946 if (err) {
1947 hmp_handle_error(mon, &err);
1948 return;
1952 qmp_blockdev_change_medium(true, device, false, NULL, target,
1953 !!arg, arg, !!read_only, read_only_mode,
1954 &err);
1957 hmp_handle_error(mon, &err);
1960 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1962 Error *err = NULL;
1963 char *device = (char *) qdict_get_str(qdict, "device");
1964 BlockIOThrottle throttle = {
1965 .bps = qdict_get_int(qdict, "bps"),
1966 .bps_rd = qdict_get_int(qdict, "bps_rd"),
1967 .bps_wr = qdict_get_int(qdict, "bps_wr"),
1968 .iops = qdict_get_int(qdict, "iops"),
1969 .iops_rd = qdict_get_int(qdict, "iops_rd"),
1970 .iops_wr = qdict_get_int(qdict, "iops_wr"),
1973 /* qmp_block_set_io_throttle has separate parameters for the
1974 * (deprecated) block device name and the qdev ID but the HMP
1975 * version has only one, so we must decide which one to pass. */
1976 if (blk_by_name(device)) {
1977 throttle.has_device = true;
1978 throttle.device = device;
1979 } else {
1980 throttle.has_id = true;
1981 throttle.id = device;
1984 qmp_block_set_io_throttle(&throttle, &err);
1985 hmp_handle_error(mon, &err);
1988 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1990 Error *error = NULL;
1991 const char *device = qdict_get_str(qdict, "device");
1992 const char *base = qdict_get_try_str(qdict, "base");
1993 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1995 qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
1996 false, NULL, qdict_haskey(qdict, "speed"), speed, true,
1997 BLOCKDEV_ON_ERROR_REPORT, false, false, false, false,
1998 &error);
2000 hmp_handle_error(mon, &error);
2003 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
2005 Error *error = NULL;
2006 const char *device = qdict_get_str(qdict, "device");
2007 int64_t value = qdict_get_int(qdict, "speed");
2009 qmp_block_job_set_speed(device, value, &error);
2011 hmp_handle_error(mon, &error);
2014 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
2016 Error *error = NULL;
2017 const char *device = qdict_get_str(qdict, "device");
2018 bool force = qdict_get_try_bool(qdict, "force", false);
2020 qmp_block_job_cancel(device, true, force, &error);
2022 hmp_handle_error(mon, &error);
2025 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
2027 Error *error = NULL;
2028 const char *device = qdict_get_str(qdict, "device");
2030 qmp_block_job_pause(device, &error);
2032 hmp_handle_error(mon, &error);
2035 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
2037 Error *error = NULL;
2038 const char *device = qdict_get_str(qdict, "device");
2040 qmp_block_job_resume(device, &error);
2042 hmp_handle_error(mon, &error);
2045 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
2047 Error *error = NULL;
2048 const char *device = qdict_get_str(qdict, "device");
2050 qmp_block_job_complete(device, &error);
2052 hmp_handle_error(mon, &error);
2055 typedef struct HMPMigrationStatus
2057 QEMUTimer *timer;
2058 Monitor *mon;
2059 bool is_block_migration;
2060 } HMPMigrationStatus;
2062 static void hmp_migrate_status_cb(void *opaque)
2064 HMPMigrationStatus *status = opaque;
2065 MigrationInfo *info;
2067 info = qmp_query_migrate(NULL);
2068 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
2069 info->status == MIGRATION_STATUS_SETUP) {
2070 if (info->has_disk) {
2071 int progress;
2073 if (info->disk->remaining) {
2074 progress = info->disk->transferred * 100 / info->disk->total;
2075 } else {
2076 progress = 100;
2079 monitor_printf(status->mon, "Completed %d %%\r", progress);
2080 monitor_flush(status->mon);
2083 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
2084 } else {
2085 if (status->is_block_migration) {
2086 monitor_printf(status->mon, "\n");
2088 if (info->has_error_desc) {
2089 error_report("%s", info->error_desc);
2091 monitor_resume(status->mon);
2092 timer_del(status->timer);
2093 timer_free(status->timer);
2094 g_free(status);
2097 qapi_free_MigrationInfo(info);
2100 void hmp_migrate(Monitor *mon, const QDict *qdict)
2102 bool detach = qdict_get_try_bool(qdict, "detach", false);
2103 bool blk = qdict_get_try_bool(qdict, "blk", false);
2104 bool inc = qdict_get_try_bool(qdict, "inc", false);
2105 bool resume = qdict_get_try_bool(qdict, "resume", false);
2106 const char *uri = qdict_get_str(qdict, "uri");
2107 Error *err = NULL;
2109 qmp_migrate(uri, !!blk, blk, !!inc, inc,
2110 false, false, true, resume, &err);
2111 if (err) {
2112 hmp_handle_error(mon, &err);
2113 return;
2116 if (!detach) {
2117 HMPMigrationStatus *status;
2119 if (monitor_suspend(mon) < 0) {
2120 monitor_printf(mon, "terminal does not allow synchronous "
2121 "migration, continuing detached\n");
2122 return;
2125 status = g_malloc0(sizeof(*status));
2126 status->mon = mon;
2127 status->is_block_migration = blk || inc;
2128 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
2129 status);
2130 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
2134 void hmp_device_add(Monitor *mon, const QDict *qdict)
2136 Error *err = NULL;
2138 qmp_device_add((QDict *)qdict, NULL, &err);
2139 hmp_handle_error(mon, &err);
2142 void hmp_device_del(Monitor *mon, const QDict *qdict)
2144 const char *id = qdict_get_str(qdict, "id");
2145 Error *err = NULL;
2147 qmp_device_del(id, &err);
2148 hmp_handle_error(mon, &err);
2151 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
2153 Error *err = NULL;
2154 bool win_dmp = qdict_get_try_bool(qdict, "windmp", false);
2155 bool paging = qdict_get_try_bool(qdict, "paging", false);
2156 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
2157 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
2158 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
2159 const char *file = qdict_get_str(qdict, "filename");
2160 bool has_begin = qdict_haskey(qdict, "begin");
2161 bool has_length = qdict_haskey(qdict, "length");
2162 bool has_detach = qdict_haskey(qdict, "detach");
2163 int64_t begin = 0;
2164 int64_t length = 0;
2165 bool detach = false;
2166 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
2167 char *prot;
2169 if (zlib + lzo + snappy + win_dmp > 1) {
2170 error_setg(&err, "only one of '-z|-l|-s|-w' can be set");
2171 hmp_handle_error(mon, &err);
2172 return;
2175 if (win_dmp) {
2176 dump_format = DUMP_GUEST_MEMORY_FORMAT_WIN_DMP;
2179 if (zlib) {
2180 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
2183 if (lzo) {
2184 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
2187 if (snappy) {
2188 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
2191 if (has_begin) {
2192 begin = qdict_get_int(qdict, "begin");
2194 if (has_length) {
2195 length = qdict_get_int(qdict, "length");
2197 if (has_detach) {
2198 detach = qdict_get_bool(qdict, "detach");
2201 prot = g_strconcat("file:", file, NULL);
2203 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
2204 has_length, length, true, dump_format, &err);
2205 hmp_handle_error(mon, &err);
2206 g_free(prot);
2209 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
2211 Error *err = NULL;
2212 QemuOpts *opts;
2214 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
2215 if (err) {
2216 goto out;
2219 netdev_add(opts, &err);
2220 if (err) {
2221 qemu_opts_del(opts);
2224 out:
2225 hmp_handle_error(mon, &err);
2228 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
2230 const char *id = qdict_get_str(qdict, "id");
2231 Error *err = NULL;
2233 qmp_netdev_del(id, &err);
2234 hmp_handle_error(mon, &err);
2237 void hmp_object_add(Monitor *mon, const QDict *qdict)
2239 Error *err = NULL;
2240 QemuOpts *opts;
2241 Object *obj = NULL;
2243 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
2244 if (err) {
2245 hmp_handle_error(mon, &err);
2246 return;
2249 obj = user_creatable_add_opts(opts, &err);
2250 qemu_opts_del(opts);
2252 if (err) {
2253 hmp_handle_error(mon, &err);
2255 if (obj) {
2256 object_unref(obj);
2260 void hmp_getfd(Monitor *mon, const QDict *qdict)
2262 const char *fdname = qdict_get_str(qdict, "fdname");
2263 Error *err = NULL;
2265 qmp_getfd(fdname, &err);
2266 hmp_handle_error(mon, &err);
2269 void hmp_closefd(Monitor *mon, const QDict *qdict)
2271 const char *fdname = qdict_get_str(qdict, "fdname");
2272 Error *err = NULL;
2274 qmp_closefd(fdname, &err);
2275 hmp_handle_error(mon, &err);
2278 void hmp_sendkey(Monitor *mon, const QDict *qdict)
2280 const char *keys = qdict_get_str(qdict, "keys");
2281 KeyValueList *keylist, *head = NULL, *tmp = NULL;
2282 int has_hold_time = qdict_haskey(qdict, "hold-time");
2283 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
2284 Error *err = NULL;
2285 const char *separator;
2286 int keyname_len;
2288 while (1) {
2289 separator = qemu_strchrnul(keys, '-');
2290 keyname_len = separator - keys;
2292 /* Be compatible with old interface, convert user inputted "<" */
2293 if (keys[0] == '<' && keyname_len == 1) {
2294 keys = "less";
2295 keyname_len = 4;
2298 keylist = g_malloc0(sizeof(*keylist));
2299 keylist->value = g_malloc0(sizeof(*keylist->value));
2301 if (!head) {
2302 head = keylist;
2304 if (tmp) {
2305 tmp->next = keylist;
2307 tmp = keylist;
2309 if (strstart(keys, "0x", NULL)) {
2310 char *endp;
2311 int value = strtoul(keys, &endp, 0);
2312 assert(endp <= keys + keyname_len);
2313 if (endp != keys + keyname_len) {
2314 goto err_out;
2316 keylist->value->type = KEY_VALUE_KIND_NUMBER;
2317 keylist->value->u.number.data = value;
2318 } else {
2319 int idx = index_from_key(keys, keyname_len);
2320 if (idx == Q_KEY_CODE__MAX) {
2321 goto err_out;
2323 keylist->value->type = KEY_VALUE_KIND_QCODE;
2324 keylist->value->u.qcode.data = idx;
2327 if (!*separator) {
2328 break;
2330 keys = separator + 1;
2333 qmp_send_key(head, has_hold_time, hold_time, &err);
2334 hmp_handle_error(mon, &err);
2336 out:
2337 qapi_free_KeyValueList(head);
2338 return;
2340 err_out:
2341 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
2342 goto out;
2345 void hmp_screendump(Monitor *mon, const QDict *qdict)
2347 const char *filename = qdict_get_str(qdict, "filename");
2348 const char *id = qdict_get_try_str(qdict, "device");
2349 int64_t head = qdict_get_try_int(qdict, "head", 0);
2350 Error *err = NULL;
2352 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
2353 hmp_handle_error(mon, &err);
2356 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
2358 const char *uri = qdict_get_str(qdict, "uri");
2359 bool writable = qdict_get_try_bool(qdict, "writable", false);
2360 bool all = qdict_get_try_bool(qdict, "all", false);
2361 Error *local_err = NULL;
2362 BlockInfoList *block_list, *info;
2363 SocketAddress *addr;
2365 if (writable && !all) {
2366 error_setg(&local_err, "-w only valid together with -a");
2367 goto exit;
2370 /* First check if the address is valid and start the server. */
2371 addr = socket_parse(uri, &local_err);
2372 if (local_err != NULL) {
2373 goto exit;
2376 nbd_server_start(addr, NULL, &local_err);
2377 qapi_free_SocketAddress(addr);
2378 if (local_err != NULL) {
2379 goto exit;
2382 if (!all) {
2383 return;
2386 /* Then try adding all block devices. If one fails, close all and
2387 * exit.
2389 block_list = qmp_query_block(NULL);
2391 for (info = block_list; info; info = info->next) {
2392 if (!info->value->has_inserted) {
2393 continue;
2396 qmp_nbd_server_add(info->value->device, false, NULL,
2397 true, writable, false, NULL, &local_err);
2399 if (local_err != NULL) {
2400 qmp_nbd_server_stop(NULL);
2401 break;
2405 qapi_free_BlockInfoList(block_list);
2407 exit:
2408 hmp_handle_error(mon, &local_err);
2411 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
2413 const char *device = qdict_get_str(qdict, "device");
2414 const char *name = qdict_get_try_str(qdict, "name");
2415 bool writable = qdict_get_try_bool(qdict, "writable", false);
2416 Error *local_err = NULL;
2418 qmp_nbd_server_add(device, !!name, name, true, writable,
2419 false, NULL, &local_err);
2420 hmp_handle_error(mon, &local_err);
2423 void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict)
2425 const char *name = qdict_get_str(qdict, "name");
2426 bool force = qdict_get_try_bool(qdict, "force", false);
2427 Error *err = NULL;
2429 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
2430 qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err);
2431 hmp_handle_error(mon, &err);
2434 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
2436 Error *err = NULL;
2438 qmp_nbd_server_stop(&err);
2439 hmp_handle_error(mon, &err);
2442 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
2444 int cpuid;
2445 Error *err = NULL;
2447 error_report("cpu_add is deprecated, please use device_add instead");
2449 cpuid = qdict_get_int(qdict, "id");
2450 qmp_cpu_add(cpuid, &err);
2451 hmp_handle_error(mon, &err);
2454 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2456 const char *args = qdict_get_str(qdict, "args");
2457 Error *err = NULL;
2458 QemuOpts *opts;
2460 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
2461 if (opts == NULL) {
2462 error_setg(&err, "Parsing chardev args failed");
2463 } else {
2464 qemu_chr_new_from_opts(opts, NULL, &err);
2465 qemu_opts_del(opts);
2467 hmp_handle_error(mon, &err);
2470 void hmp_chardev_change(Monitor *mon, const QDict *qdict)
2472 const char *args = qdict_get_str(qdict, "args");
2473 const char *id;
2474 Error *err = NULL;
2475 ChardevBackend *backend = NULL;
2476 ChardevReturn *ret = NULL;
2477 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
2478 true);
2479 if (!opts) {
2480 error_setg(&err, "Parsing chardev args failed");
2481 goto end;
2484 id = qdict_get_str(qdict, "id");
2485 if (qemu_opts_id(opts)) {
2486 error_setg(&err, "Unexpected 'id' parameter");
2487 goto end;
2490 backend = qemu_chr_parse_opts(opts, &err);
2491 if (!backend) {
2492 goto end;
2495 ret = qmp_chardev_change(id, backend, &err);
2497 end:
2498 qapi_free_ChardevReturn(ret);
2499 qapi_free_ChardevBackend(backend);
2500 qemu_opts_del(opts);
2501 hmp_handle_error(mon, &err);
2504 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2506 Error *local_err = NULL;
2508 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
2509 hmp_handle_error(mon, &local_err);
2512 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
2514 Error *local_err = NULL;
2516 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
2517 hmp_handle_error(mon, &local_err);
2520 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
2522 BlockBackend *blk;
2523 BlockBackend *local_blk = NULL;
2524 const char* device = qdict_get_str(qdict, "device");
2525 const char* command = qdict_get_str(qdict, "command");
2526 Error *err = NULL;
2527 int ret;
2529 blk = blk_by_name(device);
2530 if (!blk) {
2531 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
2532 if (bs) {
2533 blk = local_blk = blk_new(0, BLK_PERM_ALL);
2534 ret = blk_insert_bs(blk, bs, &err);
2535 if (ret < 0) {
2536 goto fail;
2538 } else {
2539 goto fail;
2544 * Notably absent: Proper permission management. This is sad, but it seems
2545 * almost impossible to achieve without changing the semantics and thereby
2546 * limiting the use cases of the qemu-io HMP command.
2548 * In an ideal world we would unconditionally create a new BlockBackend for
2549 * qemuio_command(), but we have commands like 'reopen' and want them to
2550 * take effect on the exact BlockBackend whose name the user passed instead
2551 * of just on a temporary copy of it.
2553 * Another problem is that deleting the temporary BlockBackend involves
2554 * draining all requests on it first, but some qemu-iotests cases want to
2555 * issue multiple aio_read/write requests and expect them to complete in
2556 * the background while the monitor has already returned.
2558 * This is also what prevents us from saving the original permissions and
2559 * restoring them later: We can't revoke permissions until all requests
2560 * have completed, and we don't know when that is nor can we really let
2561 * anything else run before we have revoken them to avoid race conditions.
2563 * What happens now is that command() in qemu-io-cmds.c can extend the
2564 * permissions if necessary for the qemu-io command. And they simply stay
2565 * extended, possibly resulting in a read-only guest device keeping write
2566 * permissions. Ugly, but it appears to be the lesser evil.
2568 qemuio_command(blk, command);
2570 fail:
2571 blk_unref(local_blk);
2572 hmp_handle_error(mon, &err);
2575 void hmp_object_del(Monitor *mon, const QDict *qdict)
2577 const char *id = qdict_get_str(qdict, "id");
2578 Error *err = NULL;
2580 user_creatable_del(id, &err);
2581 hmp_handle_error(mon, &err);
2584 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
2586 Error *err = NULL;
2587 MemdevList *memdev_list = qmp_query_memdev(&err);
2588 MemdevList *m = memdev_list;
2589 Visitor *v;
2590 char *str;
2592 while (m) {
2593 v = string_output_visitor_new(false, &str);
2594 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
2595 monitor_printf(mon, "memory backend: %s\n", m->value->id);
2596 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
2597 monitor_printf(mon, " merge: %s\n",
2598 m->value->merge ? "true" : "false");
2599 monitor_printf(mon, " dump: %s\n",
2600 m->value->dump ? "true" : "false");
2601 monitor_printf(mon, " prealloc: %s\n",
2602 m->value->prealloc ? "true" : "false");
2603 monitor_printf(mon, " policy: %s\n",
2604 HostMemPolicy_str(m->value->policy));
2605 visit_complete(v, &str);
2606 monitor_printf(mon, " host nodes: %s\n", str);
2608 g_free(str);
2609 visit_free(v);
2610 m = m->next;
2613 monitor_printf(mon, "\n");
2615 qapi_free_MemdevList(memdev_list);
2616 hmp_handle_error(mon, &err);
2619 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2621 Error *err = NULL;
2622 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2623 MemoryDeviceInfoList *info;
2624 MemoryDeviceInfo *value;
2625 PCDIMMDeviceInfo *di;
2627 for (info = info_list; info; info = info->next) {
2628 value = info->value;
2630 if (value) {
2631 switch (value->type) {
2632 case MEMORY_DEVICE_INFO_KIND_DIMM:
2633 di = value->u.dimm.data;
2634 break;
2636 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
2637 di = value->u.nvdimm.data;
2638 break;
2640 default:
2641 di = NULL;
2642 break;
2645 if (di) {
2646 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2647 MemoryDeviceInfoKind_str(value->type),
2648 di->id ? di->id : "");
2649 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2650 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2651 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2652 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2653 monitor_printf(mon, " memdev: %s\n", di->memdev);
2654 monitor_printf(mon, " hotplugged: %s\n",
2655 di->hotplugged ? "true" : "false");
2656 monitor_printf(mon, " hotpluggable: %s\n",
2657 di->hotpluggable ? "true" : "false");
2662 qapi_free_MemoryDeviceInfoList(info_list);
2663 hmp_handle_error(mon, &err);
2666 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2668 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2669 IOThreadInfoList *info;
2670 IOThreadInfo *value;
2672 for (info = info_list; info; info = info->next) {
2673 value = info->value;
2674 monitor_printf(mon, "%s:\n", value->id);
2675 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
2676 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2677 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
2678 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
2681 qapi_free_IOThreadInfoList(info_list);
2684 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2686 const char *path = qdict_get_try_str(qdict, "path");
2687 ObjectPropertyInfoList *list;
2688 Error *err = NULL;
2690 if (path == NULL) {
2691 monitor_printf(mon, "/\n");
2692 return;
2695 list = qmp_qom_list(path, &err);
2696 if (err == NULL) {
2697 ObjectPropertyInfoList *start = list;
2698 while (list != NULL) {
2699 ObjectPropertyInfo *value = list->value;
2701 monitor_printf(mon, "%s (%s)\n",
2702 value->name, value->type);
2703 list = list->next;
2705 qapi_free_ObjectPropertyInfoList(start);
2707 hmp_handle_error(mon, &err);
2710 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2712 const char *path = qdict_get_str(qdict, "path");
2713 const char *property = qdict_get_str(qdict, "property");
2714 const char *value = qdict_get_str(qdict, "value");
2715 Error *err = NULL;
2716 bool ambiguous = false;
2717 Object *obj;
2719 obj = object_resolve_path(path, &ambiguous);
2720 if (obj == NULL) {
2721 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2722 "Device '%s' not found", path);
2723 } else {
2724 if (ambiguous) {
2725 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2727 object_property_parse(obj, value, property, &err);
2729 hmp_handle_error(mon, &err);
2732 void hmp_rocker(Monitor *mon, const QDict *qdict)
2734 const char *name = qdict_get_str(qdict, "name");
2735 RockerSwitch *rocker;
2736 Error *err = NULL;
2738 rocker = qmp_query_rocker(name, &err);
2739 if (err != NULL) {
2740 hmp_handle_error(mon, &err);
2741 return;
2744 monitor_printf(mon, "name: %s\n", rocker->name);
2745 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2746 monitor_printf(mon, "ports: %d\n", rocker->ports);
2748 qapi_free_RockerSwitch(rocker);
2751 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2753 RockerPortList *list, *port;
2754 const char *name = qdict_get_str(qdict, "name");
2755 Error *err = NULL;
2757 list = qmp_query_rocker_ports(name, &err);
2758 if (err != NULL) {
2759 hmp_handle_error(mon, &err);
2760 return;
2763 monitor_printf(mon, " ena/ speed/ auto\n");
2764 monitor_printf(mon, " port link duplex neg?\n");
2766 for (port = list; port; port = port->next) {
2767 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2768 port->value->name,
2769 port->value->enabled ? port->value->link_up ?
2770 "up" : "down" : "!ena",
2771 port->value->speed == 10000 ? "10G" : "??",
2772 port->value->duplex ? "FD" : "HD",
2773 port->value->autoneg ? "Yes" : "No");
2776 qapi_free_RockerPortList(list);
2779 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2781 RockerOfDpaFlowList *list, *info;
2782 const char *name = qdict_get_str(qdict, "name");
2783 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2784 Error *err = NULL;
2786 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2787 if (err != NULL) {
2788 hmp_handle_error(mon, &err);
2789 return;
2792 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2794 for (info = list; info; info = info->next) {
2795 RockerOfDpaFlow *flow = info->value;
2796 RockerOfDpaFlowKey *key = flow->key;
2797 RockerOfDpaFlowMask *mask = flow->mask;
2798 RockerOfDpaFlowAction *action = flow->action;
2800 if (flow->hits) {
2801 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2802 key->priority, key->tbl_id, flow->hits);
2803 } else {
2804 monitor_printf(mon, "%-4d %-3d ",
2805 key->priority, key->tbl_id);
2808 if (key->has_in_pport) {
2809 monitor_printf(mon, " pport %d", key->in_pport);
2810 if (mask->has_in_pport) {
2811 monitor_printf(mon, "(0x%x)", mask->in_pport);
2815 if (key->has_vlan_id) {
2816 monitor_printf(mon, " vlan %d",
2817 key->vlan_id & VLAN_VID_MASK);
2818 if (mask->has_vlan_id) {
2819 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2823 if (key->has_tunnel_id) {
2824 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2825 if (mask->has_tunnel_id) {
2826 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2830 if (key->has_eth_type) {
2831 switch (key->eth_type) {
2832 case 0x0806:
2833 monitor_printf(mon, " ARP");
2834 break;
2835 case 0x0800:
2836 monitor_printf(mon, " IP");
2837 break;
2838 case 0x86dd:
2839 monitor_printf(mon, " IPv6");
2840 break;
2841 case 0x8809:
2842 monitor_printf(mon, " LACP");
2843 break;
2844 case 0x88cc:
2845 monitor_printf(mon, " LLDP");
2846 break;
2847 default:
2848 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2849 break;
2853 if (key->has_eth_src) {
2854 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2855 (mask->has_eth_src) &&
2856 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2857 monitor_printf(mon, " src <any mcast/bcast>");
2858 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2859 (mask->has_eth_src) &&
2860 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2861 monitor_printf(mon, " src <any ucast>");
2862 } else {
2863 monitor_printf(mon, " src %s", key->eth_src);
2864 if (mask->has_eth_src) {
2865 monitor_printf(mon, "(%s)", mask->eth_src);
2870 if (key->has_eth_dst) {
2871 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2872 (mask->has_eth_dst) &&
2873 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2874 monitor_printf(mon, " dst <any mcast/bcast>");
2875 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2876 (mask->has_eth_dst) &&
2877 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2878 monitor_printf(mon, " dst <any ucast>");
2879 } else {
2880 monitor_printf(mon, " dst %s", key->eth_dst);
2881 if (mask->has_eth_dst) {
2882 monitor_printf(mon, "(%s)", mask->eth_dst);
2887 if (key->has_ip_proto) {
2888 monitor_printf(mon, " proto %d", key->ip_proto);
2889 if (mask->has_ip_proto) {
2890 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2894 if (key->has_ip_tos) {
2895 monitor_printf(mon, " TOS %d", key->ip_tos);
2896 if (mask->has_ip_tos) {
2897 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2901 if (key->has_ip_dst) {
2902 monitor_printf(mon, " dst %s", key->ip_dst);
2905 if (action->has_goto_tbl || action->has_group_id ||
2906 action->has_new_vlan_id) {
2907 monitor_printf(mon, " -->");
2910 if (action->has_new_vlan_id) {
2911 monitor_printf(mon, " apply new vlan %d",
2912 ntohs(action->new_vlan_id));
2915 if (action->has_group_id) {
2916 monitor_printf(mon, " write group 0x%08x", action->group_id);
2919 if (action->has_goto_tbl) {
2920 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2923 monitor_printf(mon, "\n");
2926 qapi_free_RockerOfDpaFlowList(list);
2929 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2931 RockerOfDpaGroupList *list, *g;
2932 const char *name = qdict_get_str(qdict, "name");
2933 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2934 Error *err = NULL;
2935 bool set = false;
2937 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2938 if (err != NULL) {
2939 hmp_handle_error(mon, &err);
2940 return;
2943 monitor_printf(mon, "id (decode) --> buckets\n");
2945 for (g = list; g; g = g->next) {
2946 RockerOfDpaGroup *group = g->value;
2948 monitor_printf(mon, "0x%08x", group->id);
2950 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2951 group->type == 1 ? "L2 rewrite" :
2952 group->type == 2 ? "L3 unicast" :
2953 group->type == 3 ? "L2 multicast" :
2954 group->type == 4 ? "L2 flood" :
2955 group->type == 5 ? "L3 interface" :
2956 group->type == 6 ? "L3 multicast" :
2957 group->type == 7 ? "L3 ECMP" :
2958 group->type == 8 ? "L2 overlay" :
2959 "unknown");
2961 if (group->has_vlan_id) {
2962 monitor_printf(mon, " vlan %d", group->vlan_id);
2965 if (group->has_pport) {
2966 monitor_printf(mon, " pport %d", group->pport);
2969 if (group->has_index) {
2970 monitor_printf(mon, " index %d", group->index);
2973 monitor_printf(mon, ") -->");
2975 if (group->has_set_vlan_id && group->set_vlan_id) {
2976 set = true;
2977 monitor_printf(mon, " set vlan %d",
2978 group->set_vlan_id & VLAN_VID_MASK);
2981 if (group->has_set_eth_src) {
2982 if (!set) {
2983 set = true;
2984 monitor_printf(mon, " set");
2986 monitor_printf(mon, " src %s", group->set_eth_src);
2989 if (group->has_set_eth_dst) {
2990 if (!set) {
2991 set = true;
2992 monitor_printf(mon, " set");
2994 monitor_printf(mon, " dst %s", group->set_eth_dst);
2997 set = false;
2999 if (group->has_ttl_check && group->ttl_check) {
3000 monitor_printf(mon, " check TTL");
3003 if (group->has_group_id && group->group_id) {
3004 monitor_printf(mon, " group id 0x%08x", group->group_id);
3007 if (group->has_pop_vlan && group->pop_vlan) {
3008 monitor_printf(mon, " pop vlan");
3011 if (group->has_out_pport) {
3012 monitor_printf(mon, " out pport %d", group->out_pport);
3015 if (group->has_group_ids) {
3016 struct uint32List *id;
3018 monitor_printf(mon, " groups [");
3019 for (id = group->group_ids; id; id = id->next) {
3020 monitor_printf(mon, "0x%08x", id->value);
3021 if (id->next) {
3022 monitor_printf(mon, ",");
3025 monitor_printf(mon, "]");
3028 monitor_printf(mon, "\n");
3031 qapi_free_RockerOfDpaGroupList(list);
3034 void hmp_info_dump(Monitor *mon, const QDict *qdict)
3036 DumpQueryResult *result = qmp_query_dump(NULL);
3038 assert(result && result->status < DUMP_STATUS__MAX);
3039 monitor_printf(mon, "Status: %s\n", DumpStatus_str(result->status));
3041 if (result->status == DUMP_STATUS_ACTIVE) {
3042 float percent = 0;
3043 assert(result->total != 0);
3044 percent = 100.0 * result->completed / result->total;
3045 monitor_printf(mon, "Finished: %.2f %%\n", percent);
3048 qapi_free_DumpQueryResult(result);
3051 void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
3053 ram_block_dump(mon);
3056 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
3058 Error *err = NULL;
3059 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
3060 HotpluggableCPUList *saved = l;
3061 CpuInstanceProperties *c;
3063 if (err != NULL) {
3064 hmp_handle_error(mon, &err);
3065 return;
3068 monitor_printf(mon, "Hotpluggable CPUs:\n");
3069 while (l) {
3070 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
3071 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
3072 l->value->vcpus_count);
3073 if (l->value->has_qom_path) {
3074 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
3077 c = l->value->props;
3078 monitor_printf(mon, " CPUInstance Properties:\n");
3079 if (c->has_node_id) {
3080 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
3082 if (c->has_socket_id) {
3083 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
3085 if (c->has_core_id) {
3086 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
3088 if (c->has_thread_id) {
3089 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
3092 l = l->next;
3095 qapi_free_HotpluggableCPUList(saved);
3098 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
3100 Error *err = NULL;
3101 GuidInfo *info = qmp_query_vm_generation_id(&err);
3102 if (info) {
3103 monitor_printf(mon, "%s\n", info->guid);
3105 hmp_handle_error(mon, &err);
3106 qapi_free_GuidInfo(info);
3109 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
3111 Error *err = NULL;
3112 MemoryInfo *info = qmp_query_memory_size_summary(&err);
3113 if (info) {
3114 monitor_printf(mon, "base memory: %" PRIu64 "\n",
3115 info->base_memory);
3117 if (info->has_plugged_memory) {
3118 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
3119 info->plugged_memory);
3122 qapi_free_MemoryInfo(info);
3124 hmp_handle_error(mon, &err);