aspeed: initialize the SCU controller first
[qemu/ar7.git] / hmp.c
blobf601099f90772b29405d34959a895f9f3ba6d701
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_report_err(*errp);
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 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
171 MigrationInfo *info;
172 MigrationCapabilityStatusList *caps, *cap;
174 info = qmp_query_migrate(NULL);
175 caps = qmp_query_migrate_capabilities(NULL);
177 migration_global_dump(mon);
179 /* do not display parameters during setup */
180 if (info->has_status && caps) {
181 monitor_printf(mon, "capabilities: ");
182 for (cap = caps; cap; cap = cap->next) {
183 monitor_printf(mon, "%s: %s ",
184 MigrationCapability_str(cap->value->capability),
185 cap->value->state ? "on" : "off");
187 monitor_printf(mon, "\n");
190 if (info->has_status) {
191 monitor_printf(mon, "Migration status: %s",
192 MigrationStatus_str(info->status));
193 if (info->status == MIGRATION_STATUS_FAILED &&
194 info->has_error_desc) {
195 monitor_printf(mon, " (%s)\n", info->error_desc);
196 } else {
197 monitor_printf(mon, "\n");
200 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
201 info->total_time);
202 if (info->has_expected_downtime) {
203 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
204 info->expected_downtime);
206 if (info->has_downtime) {
207 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
208 info->downtime);
210 if (info->has_setup_time) {
211 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
212 info->setup_time);
216 if (info->has_ram) {
217 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
218 info->ram->transferred >> 10);
219 monitor_printf(mon, "throughput: %0.2f mbps\n",
220 info->ram->mbps);
221 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
222 info->ram->remaining >> 10);
223 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
224 info->ram->total >> 10);
225 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
226 info->ram->duplicate);
227 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
228 info->ram->skipped);
229 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
230 info->ram->normal);
231 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
232 info->ram->normal_bytes >> 10);
233 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
234 info->ram->dirty_sync_count);
235 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
236 info->ram->page_size >> 10);
238 if (info->ram->dirty_pages_rate) {
239 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
240 info->ram->dirty_pages_rate);
242 if (info->ram->postcopy_requests) {
243 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
244 info->ram->postcopy_requests);
248 if (info->has_disk) {
249 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
250 info->disk->transferred >> 10);
251 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
252 info->disk->remaining >> 10);
253 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
254 info->disk->total >> 10);
257 if (info->has_xbzrle_cache) {
258 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
259 info->xbzrle_cache->cache_size);
260 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
261 info->xbzrle_cache->bytes >> 10);
262 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
263 info->xbzrle_cache->pages);
264 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
265 info->xbzrle_cache->cache_miss);
266 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
267 info->xbzrle_cache->cache_miss_rate);
268 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
269 info->xbzrle_cache->overflow);
272 if (info->has_cpu_throttle_percentage) {
273 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
274 info->cpu_throttle_percentage);
277 if (info->has_postcopy_blocktime) {
278 monitor_printf(mon, "postcopy blocktime: %u\n",
279 info->postcopy_blocktime);
282 if (info->has_postcopy_vcpu_blocktime) {
283 Visitor *v;
284 char *str;
285 v = string_output_visitor_new(false, &str);
286 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NULL);
287 visit_complete(v, &str);
288 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
289 g_free(str);
290 visit_free(v);
292 qapi_free_MigrationInfo(info);
293 qapi_free_MigrationCapabilityStatusList(caps);
296 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
298 MigrationCapabilityStatusList *caps, *cap;
300 caps = qmp_query_migrate_capabilities(NULL);
302 if (caps) {
303 for (cap = caps; cap; cap = cap->next) {
304 monitor_printf(mon, "%s: %s\n",
305 MigrationCapability_str(cap->value->capability),
306 cap->value->state ? "on" : "off");
310 qapi_free_MigrationCapabilityStatusList(caps);
313 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
315 MigrationParameters *params;
317 params = qmp_query_migrate_parameters(NULL);
319 if (params) {
320 assert(params->has_compress_level);
321 monitor_printf(mon, "%s: %u\n",
322 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
323 params->compress_level);
324 assert(params->has_compress_threads);
325 monitor_printf(mon, "%s: %u\n",
326 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
327 params->compress_threads);
328 assert(params->has_decompress_threads);
329 monitor_printf(mon, "%s: %u\n",
330 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
331 params->decompress_threads);
332 assert(params->has_cpu_throttle_initial);
333 monitor_printf(mon, "%s: %u\n",
334 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
335 params->cpu_throttle_initial);
336 assert(params->has_cpu_throttle_increment);
337 monitor_printf(mon, "%s: %u\n",
338 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
339 params->cpu_throttle_increment);
340 assert(params->has_tls_creds);
341 monitor_printf(mon, "%s: '%s'\n",
342 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
343 params->tls_creds);
344 assert(params->has_tls_hostname);
345 monitor_printf(mon, "%s: '%s'\n",
346 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
347 params->tls_hostname);
348 assert(params->has_max_bandwidth);
349 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
350 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
351 params->max_bandwidth);
352 assert(params->has_downtime_limit);
353 monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n",
354 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
355 params->downtime_limit);
356 assert(params->has_x_checkpoint_delay);
357 monitor_printf(mon, "%s: %u\n",
358 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
359 params->x_checkpoint_delay);
360 assert(params->has_block_incremental);
361 monitor_printf(mon, "%s: %s\n",
362 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
363 params->block_incremental ? "on" : "off");
364 monitor_printf(mon, "%s: %u\n",
365 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_CHANNELS),
366 params->x_multifd_channels);
367 monitor_printf(mon, "%s: %u\n",
368 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT),
369 params->x_multifd_page_count);
370 monitor_printf(mon, "%s: %" PRIu64 "\n",
371 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
372 params->xbzrle_cache_size);
373 monitor_printf(mon, "%s: %" PRIu64 "\n",
374 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
375 params->max_postcopy_bandwidth);
378 qapi_free_MigrationParameters(params);
381 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
383 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
384 qmp_query_migrate_cache_size(NULL) >> 10);
387 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
389 CpuInfoFastList *cpu_list, *cpu;
391 cpu_list = qmp_query_cpus_fast(NULL);
393 for (cpu = cpu_list; cpu; cpu = cpu->next) {
394 int active = ' ';
396 if (cpu->value->cpu_index == monitor_get_cpu_index()) {
397 active = '*';
400 monitor_printf(mon, "%c CPU #%" PRId64 ":", active,
401 cpu->value->cpu_index);
402 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
405 qapi_free_CpuInfoFastList(cpu_list);
408 static void print_block_info(Monitor *mon, BlockInfo *info,
409 BlockDeviceInfo *inserted, bool verbose)
411 ImageInfo *image_info;
413 assert(!info || !info->has_inserted || info->inserted == inserted);
415 if (info && *info->device) {
416 monitor_printf(mon, "%s", info->device);
417 if (inserted && inserted->has_node_name) {
418 monitor_printf(mon, " (%s)", inserted->node_name);
420 } else {
421 assert(info || inserted);
422 monitor_printf(mon, "%s",
423 inserted && inserted->has_node_name ? inserted->node_name
424 : info && info->has_qdev ? info->qdev
425 : "<anonymous>");
428 if (inserted) {
429 monitor_printf(mon, ": %s (%s%s%s)\n",
430 inserted->file,
431 inserted->drv,
432 inserted->ro ? ", read-only" : "",
433 inserted->encrypted ? ", encrypted" : "");
434 } else {
435 monitor_printf(mon, ": [not inserted]\n");
438 if (info) {
439 if (info->has_qdev) {
440 monitor_printf(mon, " Attached to: %s\n", info->qdev);
442 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
443 monitor_printf(mon, " I/O status: %s\n",
444 BlockDeviceIoStatus_str(info->io_status));
447 if (info->removable) {
448 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
449 info->locked ? "" : "not ",
450 info->tray_open ? "open" : "closed");
455 if (!inserted) {
456 return;
459 monitor_printf(mon, " Cache mode: %s%s%s\n",
460 inserted->cache->writeback ? "writeback" : "writethrough",
461 inserted->cache->direct ? ", direct" : "",
462 inserted->cache->no_flush ? ", ignore flushes" : "");
464 if (inserted->has_backing_file) {
465 monitor_printf(mon,
466 " Backing file: %s "
467 "(chain depth: %" PRId64 ")\n",
468 inserted->backing_file,
469 inserted->backing_file_depth);
472 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
473 monitor_printf(mon, " Detect zeroes: %s\n",
474 BlockdevDetectZeroesOptions_str(inserted->detect_zeroes));
477 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
478 inserted->iops || inserted->iops_rd || inserted->iops_wr)
480 monitor_printf(mon, " I/O throttling: bps=%" PRId64
481 " bps_rd=%" PRId64 " bps_wr=%" PRId64
482 " bps_max=%" PRId64
483 " bps_rd_max=%" PRId64
484 " bps_wr_max=%" PRId64
485 " iops=%" PRId64 " iops_rd=%" PRId64
486 " iops_wr=%" PRId64
487 " iops_max=%" PRId64
488 " iops_rd_max=%" PRId64
489 " iops_wr_max=%" PRId64
490 " iops_size=%" PRId64
491 " group=%s\n",
492 inserted->bps,
493 inserted->bps_rd,
494 inserted->bps_wr,
495 inserted->bps_max,
496 inserted->bps_rd_max,
497 inserted->bps_wr_max,
498 inserted->iops,
499 inserted->iops_rd,
500 inserted->iops_wr,
501 inserted->iops_max,
502 inserted->iops_rd_max,
503 inserted->iops_wr_max,
504 inserted->iops_size,
505 inserted->group);
508 if (verbose) {
509 monitor_printf(mon, "\nImages:\n");
510 image_info = inserted->image;
511 while (1) {
512 bdrv_image_info_dump((fprintf_function)monitor_printf,
513 mon, image_info);
514 if (image_info->has_backing_image) {
515 image_info = image_info->backing_image;
516 } else {
517 break;
523 void hmp_info_block(Monitor *mon, const QDict *qdict)
525 BlockInfoList *block_list, *info;
526 BlockDeviceInfoList *blockdev_list, *blockdev;
527 const char *device = qdict_get_try_str(qdict, "device");
528 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
529 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
530 bool printed = false;
532 /* Print BlockBackend information */
533 if (!nodes) {
534 block_list = qmp_query_block(NULL);
535 } else {
536 block_list = NULL;
539 for (info = block_list; info; info = info->next) {
540 if (device && strcmp(device, info->value->device)) {
541 continue;
544 if (info != block_list) {
545 monitor_printf(mon, "\n");
548 print_block_info(mon, info->value, info->value->has_inserted
549 ? info->value->inserted : NULL,
550 verbose);
551 printed = true;
554 qapi_free_BlockInfoList(block_list);
556 if ((!device && !nodes) || printed) {
557 return;
560 /* Print node information */
561 blockdev_list = qmp_query_named_block_nodes(NULL);
562 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
563 assert(blockdev->value->has_node_name);
564 if (device && strcmp(device, blockdev->value->node_name)) {
565 continue;
568 if (blockdev != blockdev_list) {
569 monitor_printf(mon, "\n");
572 print_block_info(mon, NULL, blockdev->value, verbose);
574 qapi_free_BlockDeviceInfoList(blockdev_list);
577 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
579 BlockStatsList *stats_list, *stats;
581 stats_list = qmp_query_blockstats(false, false, NULL);
583 for (stats = stats_list; stats; stats = stats->next) {
584 if (!stats->value->has_device) {
585 continue;
588 monitor_printf(mon, "%s:", stats->value->device);
589 monitor_printf(mon, " rd_bytes=%" PRId64
590 " wr_bytes=%" PRId64
591 " rd_operations=%" PRId64
592 " wr_operations=%" PRId64
593 " flush_operations=%" PRId64
594 " wr_total_time_ns=%" PRId64
595 " rd_total_time_ns=%" PRId64
596 " flush_total_time_ns=%" PRId64
597 " rd_merged=%" PRId64
598 " wr_merged=%" PRId64
599 " idle_time_ns=%" PRId64
600 "\n",
601 stats->value->stats->rd_bytes,
602 stats->value->stats->wr_bytes,
603 stats->value->stats->rd_operations,
604 stats->value->stats->wr_operations,
605 stats->value->stats->flush_operations,
606 stats->value->stats->wr_total_time_ns,
607 stats->value->stats->rd_total_time_ns,
608 stats->value->stats->flush_total_time_ns,
609 stats->value->stats->rd_merged,
610 stats->value->stats->wr_merged,
611 stats->value->stats->idle_time_ns);
614 qapi_free_BlockStatsList(stats_list);
617 /* Helper for hmp_info_vnc_clients, _servers */
618 static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
619 const char *name)
621 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
622 name,
623 info->host,
624 info->service,
625 NetworkAddressFamily_str(info->family),
626 info->websocket ? " (Websocket)" : "");
629 /* Helper displaying and auth and crypt info */
630 static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
631 VncPrimaryAuth auth,
632 VncVencryptSubAuth *vencrypt)
634 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
635 VncPrimaryAuth_str(auth),
636 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
639 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
641 while (client) {
642 VncClientInfo *cinfo = client->value;
644 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
645 monitor_printf(mon, " x509_dname: %s\n",
646 cinfo->has_x509_dname ?
647 cinfo->x509_dname : "none");
648 monitor_printf(mon, " sasl_username: %s\n",
649 cinfo->has_sasl_username ?
650 cinfo->sasl_username : "none");
652 client = client->next;
656 static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
658 while (server) {
659 VncServerInfo2 *sinfo = server->value;
660 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
661 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
662 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
663 server = server->next;
667 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
669 VncInfo2List *info2l;
670 Error *err = NULL;
672 info2l = qmp_query_vnc_servers(&err);
673 if (err) {
674 hmp_handle_error(mon, &err);
675 return;
677 if (!info2l) {
678 monitor_printf(mon, "None\n");
679 return;
682 while (info2l) {
683 VncInfo2 *info = info2l->value;
684 monitor_printf(mon, "%s:\n", info->id);
685 hmp_info_vnc_servers(mon, info->server);
686 hmp_info_vnc_clients(mon, info->clients);
687 if (!info->server) {
688 /* The server entry displays its auth, we only
689 * need to display in the case of 'reverse' connections
690 * where there's no server.
692 hmp_info_vnc_authcrypt(mon, " ", info->auth,
693 info->has_vencrypt ? &info->vencrypt : NULL);
695 if (info->has_display) {
696 monitor_printf(mon, " Display: %s\n", info->display);
698 info2l = info2l->next;
701 qapi_free_VncInfo2List(info2l);
705 #ifdef CONFIG_SPICE
706 void hmp_info_spice(Monitor *mon, const QDict *qdict)
708 SpiceChannelList *chan;
709 SpiceInfo *info;
710 const char *channel_name;
711 const char * const channel_names[] = {
712 [SPICE_CHANNEL_MAIN] = "main",
713 [SPICE_CHANNEL_DISPLAY] = "display",
714 [SPICE_CHANNEL_INPUTS] = "inputs",
715 [SPICE_CHANNEL_CURSOR] = "cursor",
716 [SPICE_CHANNEL_PLAYBACK] = "playback",
717 [SPICE_CHANNEL_RECORD] = "record",
718 [SPICE_CHANNEL_TUNNEL] = "tunnel",
719 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
720 [SPICE_CHANNEL_USBREDIR] = "usbredir",
721 [SPICE_CHANNEL_PORT] = "port",
722 #if 0
723 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
724 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
725 * as quick fix for build failures with older versions. */
726 [SPICE_CHANNEL_WEBDAV] = "webdav",
727 #endif
730 info = qmp_query_spice(NULL);
732 if (!info->enabled) {
733 monitor_printf(mon, "Server: disabled\n");
734 goto out;
737 monitor_printf(mon, "Server:\n");
738 if (info->has_port) {
739 monitor_printf(mon, " address: %s:%" PRId64 "\n",
740 info->host, info->port);
742 if (info->has_tls_port) {
743 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
744 info->host, info->tls_port);
746 monitor_printf(mon, " migrated: %s\n",
747 info->migrated ? "true" : "false");
748 monitor_printf(mon, " auth: %s\n", info->auth);
749 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
750 monitor_printf(mon, " mouse-mode: %s\n",
751 SpiceQueryMouseMode_str(info->mouse_mode));
753 if (!info->has_channels || info->channels == NULL) {
754 monitor_printf(mon, "Channels: none\n");
755 } else {
756 for (chan = info->channels; chan; chan = chan->next) {
757 monitor_printf(mon, "Channel:\n");
758 monitor_printf(mon, " address: %s:%s%s\n",
759 chan->value->host, chan->value->port,
760 chan->value->tls ? " [tls]" : "");
761 monitor_printf(mon, " session: %" PRId64 "\n",
762 chan->value->connection_id);
763 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
764 chan->value->channel_type, chan->value->channel_id);
766 channel_name = "unknown";
767 if (chan->value->channel_type > 0 &&
768 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
769 channel_names[chan->value->channel_type]) {
770 channel_name = channel_names[chan->value->channel_type];
773 monitor_printf(mon, " channel name: %s\n", channel_name);
777 out:
778 qapi_free_SpiceInfo(info);
780 #endif
782 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
784 BalloonInfo *info;
785 Error *err = NULL;
787 info = qmp_query_balloon(&err);
788 if (err) {
789 hmp_handle_error(mon, &err);
790 return;
793 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
795 qapi_free_BalloonInfo(info);
798 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
800 PciMemoryRegionList *region;
802 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
803 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
804 dev->slot, dev->function);
805 monitor_printf(mon, " ");
807 if (dev->class_info->has_desc) {
808 monitor_printf(mon, "%s", dev->class_info->desc);
809 } else {
810 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
813 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
814 dev->id->vendor, dev->id->device);
816 if (dev->has_irq) {
817 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
820 if (dev->has_pci_bridge) {
821 monitor_printf(mon, " BUS %" PRId64 ".\n",
822 dev->pci_bridge->bus->number);
823 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
824 dev->pci_bridge->bus->secondary);
825 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
826 dev->pci_bridge->bus->subordinate);
828 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
829 dev->pci_bridge->bus->io_range->base,
830 dev->pci_bridge->bus->io_range->limit);
832 monitor_printf(mon,
833 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
834 dev->pci_bridge->bus->memory_range->base,
835 dev->pci_bridge->bus->memory_range->limit);
837 monitor_printf(mon, " prefetchable memory range "
838 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
839 dev->pci_bridge->bus->prefetchable_range->base,
840 dev->pci_bridge->bus->prefetchable_range->limit);
843 for (region = dev->regions; region; region = region->next) {
844 uint64_t addr, size;
846 addr = region->value->address;
847 size = region->value->size;
849 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
851 if (!strcmp(region->value->type, "io")) {
852 monitor_printf(mon, "I/O at 0x%04" PRIx64
853 " [0x%04" PRIx64 "].\n",
854 addr, addr + size - 1);
855 } else {
856 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
857 " [0x%08" PRIx64 "].\n",
858 region->value->mem_type_64 ? 64 : 32,
859 region->value->prefetch ? " prefetchable" : "",
860 addr, addr + size - 1);
864 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
866 if (dev->has_pci_bridge) {
867 if (dev->pci_bridge->has_devices) {
868 PciDeviceInfoList *cdev;
869 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
870 hmp_info_pci_device(mon, cdev->value);
876 static int hmp_info_irq_foreach(Object *obj, void *opaque)
878 InterruptStatsProvider *intc;
879 InterruptStatsProviderClass *k;
880 Monitor *mon = opaque;
882 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
883 intc = INTERRUPT_STATS_PROVIDER(obj);
884 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
885 uint64_t *irq_counts;
886 unsigned int nb_irqs, i;
887 if (k->get_statistics &&
888 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
889 if (nb_irqs > 0) {
890 monitor_printf(mon, "IRQ statistics for %s:\n",
891 object_get_typename(obj));
892 for (i = 0; i < nb_irqs; i++) {
893 if (irq_counts[i] > 0) {
894 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
895 irq_counts[i]);
899 } else {
900 monitor_printf(mon, "IRQ statistics not available for %s.\n",
901 object_get_typename(obj));
905 return 0;
908 void hmp_info_irq(Monitor *mon, const QDict *qdict)
910 object_child_foreach_recursive(object_get_root(),
911 hmp_info_irq_foreach, mon);
914 static int hmp_info_pic_foreach(Object *obj, void *opaque)
916 InterruptStatsProvider *intc;
917 InterruptStatsProviderClass *k;
918 Monitor *mon = opaque;
920 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
921 intc = INTERRUPT_STATS_PROVIDER(obj);
922 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
923 if (k->print_info) {
924 k->print_info(intc, mon);
925 } else {
926 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
927 object_get_typename(obj));
931 return 0;
934 void hmp_info_pic(Monitor *mon, const QDict *qdict)
936 object_child_foreach_recursive(object_get_root(),
937 hmp_info_pic_foreach, mon);
940 void hmp_info_pci(Monitor *mon, const QDict *qdict)
942 PciInfoList *info_list, *info;
943 Error *err = NULL;
945 info_list = qmp_query_pci(&err);
946 if (err) {
947 monitor_printf(mon, "PCI devices not supported\n");
948 error_free(err);
949 return;
952 for (info = info_list; info; info = info->next) {
953 PciDeviceInfoList *dev;
955 for (dev = info->value->devices; dev; dev = dev->next) {
956 hmp_info_pci_device(mon, dev->value);
960 qapi_free_PciInfoList(info_list);
963 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
965 BlockJobInfoList *list;
966 Error *err = NULL;
968 list = qmp_query_block_jobs(&err);
969 assert(!err);
971 if (!list) {
972 monitor_printf(mon, "No active jobs\n");
973 return;
976 while (list) {
977 if (strcmp(list->value->type, "stream") == 0) {
978 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
979 " of %" PRId64 " bytes, speed limit %" PRId64
980 " bytes/s\n",
981 list->value->device,
982 list->value->offset,
983 list->value->len,
984 list->value->speed);
985 } else {
986 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
987 " of %" PRId64 " bytes, speed limit %" PRId64
988 " bytes/s\n",
989 list->value->type,
990 list->value->device,
991 list->value->offset,
992 list->value->len,
993 list->value->speed);
995 list = list->next;
998 qapi_free_BlockJobInfoList(list);
1001 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
1003 TPMInfoList *info_list, *info;
1004 Error *err = NULL;
1005 unsigned int c = 0;
1006 TPMPassthroughOptions *tpo;
1007 TPMEmulatorOptions *teo;
1009 info_list = qmp_query_tpm(&err);
1010 if (err) {
1011 monitor_printf(mon, "TPM device not supported\n");
1012 error_free(err);
1013 return;
1016 if (info_list) {
1017 monitor_printf(mon, "TPM device:\n");
1020 for (info = info_list; info; info = info->next) {
1021 TPMInfo *ti = info->value;
1022 monitor_printf(mon, " tpm%d: model=%s\n",
1023 c, TpmModel_str(ti->model));
1025 monitor_printf(mon, " \\ %s: type=%s",
1026 ti->id, TpmTypeOptionsKind_str(ti->options->type));
1028 switch (ti->options->type) {
1029 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
1030 tpo = ti->options->u.passthrough.data;
1031 monitor_printf(mon, "%s%s%s%s",
1032 tpo->has_path ? ",path=" : "",
1033 tpo->has_path ? tpo->path : "",
1034 tpo->has_cancel_path ? ",cancel-path=" : "",
1035 tpo->has_cancel_path ? tpo->cancel_path : "");
1036 break;
1037 case TPM_TYPE_OPTIONS_KIND_EMULATOR:
1038 teo = ti->options->u.emulator.data;
1039 monitor_printf(mon, ",chardev=%s", teo->chardev);
1040 break;
1041 case TPM_TYPE_OPTIONS_KIND__MAX:
1042 break;
1044 monitor_printf(mon, "\n");
1045 c++;
1047 qapi_free_TPMInfoList(info_list);
1050 void hmp_quit(Monitor *mon, const QDict *qdict)
1052 monitor_suspend(mon);
1053 qmp_quit(NULL);
1056 void hmp_stop(Monitor *mon, const QDict *qdict)
1058 qmp_stop(NULL);
1061 void hmp_system_reset(Monitor *mon, const QDict *qdict)
1063 qmp_system_reset(NULL);
1066 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
1068 qmp_system_powerdown(NULL);
1071 void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
1073 Error *err = NULL;
1075 qmp_exit_preconfig(&err);
1076 hmp_handle_error(mon, &err);
1079 void hmp_cpu(Monitor *mon, const QDict *qdict)
1081 int64_t cpu_index;
1083 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1084 use it are converted to the QAPI */
1085 cpu_index = qdict_get_int(qdict, "index");
1086 if (monitor_set_cpu(cpu_index) < 0) {
1087 monitor_printf(mon, "invalid CPU index\n");
1091 void hmp_memsave(Monitor *mon, const QDict *qdict)
1093 uint32_t size = qdict_get_int(qdict, "size");
1094 const char *filename = qdict_get_str(qdict, "filename");
1095 uint64_t addr = qdict_get_int(qdict, "val");
1096 Error *err = NULL;
1097 int cpu_index = monitor_get_cpu_index();
1099 if (cpu_index < 0) {
1100 monitor_printf(mon, "No CPU available\n");
1101 return;
1104 qmp_memsave(addr, size, filename, true, cpu_index, &err);
1105 hmp_handle_error(mon, &err);
1108 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1110 uint32_t size = qdict_get_int(qdict, "size");
1111 const char *filename = qdict_get_str(qdict, "filename");
1112 uint64_t addr = qdict_get_int(qdict, "val");
1113 Error *err = NULL;
1115 qmp_pmemsave(addr, size, filename, &err);
1116 hmp_handle_error(mon, &err);
1119 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1121 const char *chardev = qdict_get_str(qdict, "device");
1122 const char *data = qdict_get_str(qdict, "data");
1123 Error *err = NULL;
1125 qmp_ringbuf_write(chardev, data, false, 0, &err);
1127 hmp_handle_error(mon, &err);
1130 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
1132 uint32_t size = qdict_get_int(qdict, "size");
1133 const char *chardev = qdict_get_str(qdict, "device");
1134 char *data;
1135 Error *err = NULL;
1136 int i;
1138 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1139 if (err) {
1140 hmp_handle_error(mon, &err);
1141 return;
1144 for (i = 0; data[i]; i++) {
1145 unsigned char ch = data[i];
1147 if (ch == '\\') {
1148 monitor_printf(mon, "\\\\");
1149 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1150 monitor_printf(mon, "\\u%04X", ch);
1151 } else {
1152 monitor_printf(mon, "%c", ch);
1156 monitor_printf(mon, "\n");
1157 g_free(data);
1160 void hmp_cont(Monitor *mon, const QDict *qdict)
1162 Error *err = NULL;
1164 qmp_cont(&err);
1165 hmp_handle_error(mon, &err);
1168 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1170 qmp_system_wakeup(NULL);
1173 void hmp_nmi(Monitor *mon, const QDict *qdict)
1175 Error *err = NULL;
1177 qmp_inject_nmi(&err);
1178 hmp_handle_error(mon, &err);
1181 void hmp_set_link(Monitor *mon, const QDict *qdict)
1183 const char *name = qdict_get_str(qdict, "name");
1184 bool up = qdict_get_bool(qdict, "up");
1185 Error *err = NULL;
1187 qmp_set_link(name, up, &err);
1188 hmp_handle_error(mon, &err);
1191 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1193 const char *device = qdict_get_str(qdict, "device");
1194 const char *password = qdict_get_str(qdict, "password");
1195 Error *err = NULL;
1197 qmp_block_passwd(true, device, false, NULL, password, &err);
1198 hmp_handle_error(mon, &err);
1201 void hmp_balloon(Monitor *mon, const QDict *qdict)
1203 int64_t value = qdict_get_int(qdict, "value");
1204 Error *err = NULL;
1206 qmp_balloon(value, &err);
1207 hmp_handle_error(mon, &err);
1210 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1212 const char *device = qdict_get_str(qdict, "device");
1213 int64_t size = qdict_get_int(qdict, "size");
1214 Error *err = NULL;
1216 qmp_block_resize(true, device, false, NULL, size, &err);
1217 hmp_handle_error(mon, &err);
1220 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1222 const char *filename = qdict_get_str(qdict, "target");
1223 const char *format = qdict_get_try_str(qdict, "format");
1224 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1225 bool full = qdict_get_try_bool(qdict, "full", false);
1226 Error *err = NULL;
1227 DriveMirror mirror = {
1228 .device = (char *)qdict_get_str(qdict, "device"),
1229 .target = (char *)filename,
1230 .has_format = !!format,
1231 .format = (char *)format,
1232 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1233 .has_mode = true,
1234 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1235 .unmap = true,
1238 if (!filename) {
1239 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1240 hmp_handle_error(mon, &err);
1241 return;
1243 qmp_drive_mirror(&mirror, &err);
1244 hmp_handle_error(mon, &err);
1247 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1249 const char *device = qdict_get_str(qdict, "device");
1250 const char *filename = qdict_get_str(qdict, "target");
1251 const char *format = qdict_get_try_str(qdict, "format");
1252 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1253 bool full = qdict_get_try_bool(qdict, "full", false);
1254 bool compress = qdict_get_try_bool(qdict, "compress", false);
1255 Error *err = NULL;
1256 DriveBackup backup = {
1257 .device = (char *)device,
1258 .target = (char *)filename,
1259 .has_format = !!format,
1260 .format = (char *)format,
1261 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1262 .has_mode = true,
1263 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1264 .has_compress = !!compress,
1265 .compress = compress,
1268 if (!filename) {
1269 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1270 hmp_handle_error(mon, &err);
1271 return;
1274 qmp_drive_backup(&backup, &err);
1275 hmp_handle_error(mon, &err);
1278 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1280 const char *device = qdict_get_str(qdict, "device");
1281 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1282 const char *format = qdict_get_try_str(qdict, "format");
1283 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1284 enum NewImageMode mode;
1285 Error *err = NULL;
1287 if (!filename) {
1288 /* In the future, if 'snapshot-file' is not specified, the snapshot
1289 will be taken internally. Today it's actually required. */
1290 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1291 hmp_handle_error(mon, &err);
1292 return;
1295 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1296 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1297 filename, false, NULL,
1298 !!format, format,
1299 true, mode, &err);
1300 hmp_handle_error(mon, &err);
1303 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1305 const char *device = qdict_get_str(qdict, "device");
1306 const char *name = qdict_get_str(qdict, "name");
1307 Error *err = NULL;
1309 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1310 hmp_handle_error(mon, &err);
1313 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1315 const char *device = qdict_get_str(qdict, "device");
1316 const char *name = qdict_get_str(qdict, "name");
1317 const char *id = qdict_get_try_str(qdict, "id");
1318 Error *err = NULL;
1320 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1321 true, name, &err);
1322 hmp_handle_error(mon, &err);
1325 void hmp_loadvm(Monitor *mon, const QDict *qdict)
1327 int saved_vm_running = runstate_is_running();
1328 const char *name = qdict_get_str(qdict, "name");
1329 Error *err = NULL;
1331 vm_stop(RUN_STATE_RESTORE_VM);
1333 if (load_snapshot(name, &err) == 0 && saved_vm_running) {
1334 vm_start();
1336 hmp_handle_error(mon, &err);
1339 void hmp_savevm(Monitor *mon, const QDict *qdict)
1341 Error *err = NULL;
1343 save_snapshot(qdict_get_try_str(qdict, "name"), &err);
1344 hmp_handle_error(mon, &err);
1347 void hmp_delvm(Monitor *mon, const QDict *qdict)
1349 BlockDriverState *bs;
1350 Error *err = NULL;
1351 const char *name = qdict_get_str(qdict, "name");
1353 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
1354 error_reportf_err(err,
1355 "Error while deleting snapshot on device '%s': ",
1356 bdrv_get_device_name(bs));
1360 void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
1362 BlockDriverState *bs, *bs1;
1363 BdrvNextIterator it1;
1364 QEMUSnapshotInfo *sn_tab, *sn;
1365 bool no_snapshot = true;
1366 int nb_sns, i;
1367 int total;
1368 int *global_snapshots;
1369 AioContext *aio_context;
1371 typedef struct SnapshotEntry {
1372 QEMUSnapshotInfo sn;
1373 QTAILQ_ENTRY(SnapshotEntry) next;
1374 } SnapshotEntry;
1376 typedef struct ImageEntry {
1377 const char *imagename;
1378 QTAILQ_ENTRY(ImageEntry) next;
1379 QTAILQ_HEAD(, SnapshotEntry) snapshots;
1380 } ImageEntry;
1382 QTAILQ_HEAD(, ImageEntry) image_list =
1383 QTAILQ_HEAD_INITIALIZER(image_list);
1385 ImageEntry *image_entry, *next_ie;
1386 SnapshotEntry *snapshot_entry;
1388 bs = bdrv_all_find_vmstate_bs();
1389 if (!bs) {
1390 monitor_printf(mon, "No available block device supports snapshots\n");
1391 return;
1393 aio_context = bdrv_get_aio_context(bs);
1395 aio_context_acquire(aio_context);
1396 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
1397 aio_context_release(aio_context);
1399 if (nb_sns < 0) {
1400 monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
1401 return;
1404 for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) {
1405 int bs1_nb_sns = 0;
1406 ImageEntry *ie;
1407 SnapshotEntry *se;
1408 AioContext *ctx = bdrv_get_aio_context(bs1);
1410 aio_context_acquire(ctx);
1411 if (bdrv_can_snapshot(bs1)) {
1412 sn = NULL;
1413 bs1_nb_sns = bdrv_snapshot_list(bs1, &sn);
1414 if (bs1_nb_sns > 0) {
1415 no_snapshot = false;
1416 ie = g_new0(ImageEntry, 1);
1417 ie->imagename = bdrv_get_device_name(bs1);
1418 QTAILQ_INIT(&ie->snapshots);
1419 QTAILQ_INSERT_TAIL(&image_list, ie, next);
1420 for (i = 0; i < bs1_nb_sns; i++) {
1421 se = g_new0(SnapshotEntry, 1);
1422 se->sn = sn[i];
1423 QTAILQ_INSERT_TAIL(&ie->snapshots, se, next);
1426 g_free(sn);
1428 aio_context_release(ctx);
1431 if (no_snapshot) {
1432 monitor_printf(mon, "There is no snapshot available.\n");
1433 return;
1436 global_snapshots = g_new0(int, nb_sns);
1437 total = 0;
1438 for (i = 0; i < nb_sns; i++) {
1439 SnapshotEntry *next_sn;
1440 if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) {
1441 global_snapshots[total] = i;
1442 total++;
1443 QTAILQ_FOREACH(image_entry, &image_list, next) {
1444 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots,
1445 next, next_sn) {
1446 if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) {
1447 QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry,
1448 next);
1449 g_free(snapshot_entry);
1456 monitor_printf(mon, "List of snapshots present on all disks:\n");
1458 if (total > 0) {
1459 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1460 monitor_printf(mon, "\n");
1461 for (i = 0; i < total; i++) {
1462 sn = &sn_tab[global_snapshots[i]];
1463 /* The ID is not guaranteed to be the same on all images, so
1464 * overwrite it.
1466 pstrcpy(sn->id_str, sizeof(sn->id_str), "--");
1467 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, sn);
1468 monitor_printf(mon, "\n");
1470 } else {
1471 monitor_printf(mon, "None\n");
1474 QTAILQ_FOREACH(image_entry, &image_list, next) {
1475 if (QTAILQ_EMPTY(&image_entry->snapshots)) {
1476 continue;
1478 monitor_printf(mon,
1479 "\nList of partial (non-loadable) snapshots on '%s':\n",
1480 image_entry->imagename);
1481 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1482 monitor_printf(mon, "\n");
1483 QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) {
1484 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon,
1485 &snapshot_entry->sn);
1486 monitor_printf(mon, "\n");
1490 QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) {
1491 SnapshotEntry *next_sn;
1492 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next,
1493 next_sn) {
1494 g_free(snapshot_entry);
1496 g_free(image_entry);
1498 g_free(sn_tab);
1499 g_free(global_snapshots);
1503 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1505 qmp_migrate_cancel(NULL);
1508 void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1510 Error *err = NULL;
1511 const char *state = qdict_get_str(qdict, "state");
1512 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1514 if (val >= 0) {
1515 qmp_migrate_continue(val, &err);
1518 hmp_handle_error(mon, &err);
1521 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1523 Error *err = NULL;
1524 const char *uri = qdict_get_str(qdict, "uri");
1526 qmp_migrate_incoming(uri, &err);
1528 hmp_handle_error(mon, &err);
1531 void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
1533 Error *err = NULL;
1534 const char *uri = qdict_get_str(qdict, "uri");
1536 qmp_migrate_recover(uri, &err);
1538 hmp_handle_error(mon, &err);
1541 void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
1543 Error *err = NULL;
1545 qmp_migrate_pause(&err);
1547 hmp_handle_error(mon, &err);
1550 /* Kept for backwards compatibility */
1551 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1553 double value = qdict_get_double(qdict, "value");
1554 qmp_migrate_set_downtime(value, NULL);
1557 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1559 int64_t value = qdict_get_int(qdict, "value");
1560 Error *err = NULL;
1562 qmp_migrate_set_cache_size(value, &err);
1563 hmp_handle_error(mon, &err);
1566 /* Kept for backwards compatibility */
1567 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1569 int64_t value = qdict_get_int(qdict, "value");
1570 qmp_migrate_set_speed(value, NULL);
1573 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1575 const char *cap = qdict_get_str(qdict, "capability");
1576 bool state = qdict_get_bool(qdict, "state");
1577 Error *err = NULL;
1578 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1579 int val;
1581 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
1582 if (val < 0) {
1583 goto end;
1586 caps->value = g_malloc0(sizeof(*caps->value));
1587 caps->value->capability = val;
1588 caps->value->state = state;
1589 caps->next = NULL;
1590 qmp_migrate_set_capabilities(caps, &err);
1592 end:
1593 qapi_free_MigrationCapabilityStatusList(caps);
1594 hmp_handle_error(mon, &err);
1597 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1599 const char *param = qdict_get_str(qdict, "parameter");
1600 const char *valuestr = qdict_get_str(qdict, "value");
1601 Visitor *v = string_input_visitor_new(valuestr);
1602 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
1603 uint64_t valuebw = 0;
1604 uint64_t cache_size;
1605 Error *err = NULL;
1606 int val, ret;
1608 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
1609 if (val < 0) {
1610 goto cleanup;
1613 switch (val) {
1614 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1615 p->has_compress_level = true;
1616 visit_type_int(v, param, &p->compress_level, &err);
1617 break;
1618 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1619 p->has_compress_threads = true;
1620 visit_type_int(v, param, &p->compress_threads, &err);
1621 break;
1622 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1623 p->has_decompress_threads = true;
1624 visit_type_int(v, param, &p->decompress_threads, &err);
1625 break;
1626 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1627 p->has_cpu_throttle_initial = true;
1628 visit_type_int(v, param, &p->cpu_throttle_initial, &err);
1629 break;
1630 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1631 p->has_cpu_throttle_increment = true;
1632 visit_type_int(v, param, &p->cpu_throttle_increment, &err);
1633 break;
1634 case MIGRATION_PARAMETER_TLS_CREDS:
1635 p->has_tls_creds = true;
1636 p->tls_creds = g_new0(StrOrNull, 1);
1637 p->tls_creds->type = QTYPE_QSTRING;
1638 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1639 break;
1640 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1641 p->has_tls_hostname = true;
1642 p->tls_hostname = g_new0(StrOrNull, 1);
1643 p->tls_hostname->type = QTYPE_QSTRING;
1644 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1645 break;
1646 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1647 p->has_max_bandwidth = true;
1649 * Can't use visit_type_size() here, because it
1650 * defaults to Bytes rather than Mebibytes.
1652 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1653 if (ret < 0 || valuebw > INT64_MAX
1654 || (size_t)valuebw != valuebw) {
1655 error_setg(&err, "Invalid size %s", valuestr);
1656 break;
1658 p->max_bandwidth = valuebw;
1659 break;
1660 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1661 p->has_downtime_limit = true;
1662 visit_type_int(v, param, &p->downtime_limit, &err);
1663 break;
1664 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1665 p->has_x_checkpoint_delay = true;
1666 visit_type_int(v, param, &p->x_checkpoint_delay, &err);
1667 break;
1668 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1669 p->has_block_incremental = true;
1670 visit_type_bool(v, param, &p->block_incremental, &err);
1671 break;
1672 case MIGRATION_PARAMETER_X_MULTIFD_CHANNELS:
1673 p->has_x_multifd_channels = true;
1674 visit_type_int(v, param, &p->x_multifd_channels, &err);
1675 break;
1676 case MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT:
1677 p->has_x_multifd_page_count = true;
1678 visit_type_int(v, param, &p->x_multifd_page_count, &err);
1679 break;
1680 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1681 p->has_xbzrle_cache_size = true;
1682 visit_type_size(v, param, &cache_size, &err);
1683 if (err || cache_size > INT64_MAX
1684 || (size_t)cache_size != cache_size) {
1685 error_setg(&err, "Invalid size %s", valuestr);
1686 break;
1688 p->xbzrle_cache_size = cache_size;
1689 break;
1690 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH:
1691 p->has_max_postcopy_bandwidth = true;
1692 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err);
1693 break;
1694 default:
1695 assert(0);
1698 if (err) {
1699 goto cleanup;
1702 qmp_migrate_set_parameters(p, &err);
1704 cleanup:
1705 qapi_free_MigrateSetParameters(p);
1706 visit_free(v);
1707 hmp_handle_error(mon, &err);
1710 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1712 Error *err = NULL;
1713 const char *protocol = qdict_get_str(qdict, "protocol");
1714 const char *hostname = qdict_get_str(qdict, "hostname");
1715 bool has_port = qdict_haskey(qdict, "port");
1716 int port = qdict_get_try_int(qdict, "port", -1);
1717 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1718 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1719 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1721 qmp_client_migrate_info(protocol, hostname,
1722 has_port, port, has_tls_port, tls_port,
1723 !!cert_subject, cert_subject, &err);
1724 hmp_handle_error(mon, &err);
1727 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1729 Error *err = NULL;
1730 qmp_migrate_start_postcopy(&err);
1731 hmp_handle_error(mon, &err);
1734 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1736 Error *err = NULL;
1738 qmp_x_colo_lost_heartbeat(&err);
1739 hmp_handle_error(mon, &err);
1742 void hmp_set_password(Monitor *mon, const QDict *qdict)
1744 const char *protocol = qdict_get_str(qdict, "protocol");
1745 const char *password = qdict_get_str(qdict, "password");
1746 const char *connected = qdict_get_try_str(qdict, "connected");
1747 Error *err = NULL;
1749 qmp_set_password(protocol, password, !!connected, connected, &err);
1750 hmp_handle_error(mon, &err);
1753 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1755 const char *protocol = qdict_get_str(qdict, "protocol");
1756 const char *whenstr = qdict_get_str(qdict, "time");
1757 Error *err = NULL;
1759 qmp_expire_password(protocol, whenstr, &err);
1760 hmp_handle_error(mon, &err);
1763 void hmp_eject(Monitor *mon, const QDict *qdict)
1765 bool force = qdict_get_try_bool(qdict, "force", false);
1766 const char *device = qdict_get_str(qdict, "device");
1767 Error *err = NULL;
1769 qmp_eject(true, device, false, NULL, true, force, &err);
1770 hmp_handle_error(mon, &err);
1773 static void hmp_change_read_arg(void *opaque, const char *password,
1774 void *readline_opaque)
1776 qmp_change_vnc_password(password, NULL);
1777 monitor_read_command(opaque, 1);
1780 void hmp_change(Monitor *mon, const QDict *qdict)
1782 const char *device = qdict_get_str(qdict, "device");
1783 const char *target = qdict_get_str(qdict, "target");
1784 const char *arg = qdict_get_try_str(qdict, "arg");
1785 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1786 BlockdevChangeReadOnlyMode read_only_mode = 0;
1787 Error *err = NULL;
1789 if (strcmp(device, "vnc") == 0) {
1790 if (read_only) {
1791 monitor_printf(mon,
1792 "Parameter 'read-only-mode' is invalid for VNC\n");
1793 return;
1795 if (strcmp(target, "passwd") == 0 ||
1796 strcmp(target, "password") == 0) {
1797 if (!arg) {
1798 monitor_read_password(mon, hmp_change_read_arg, NULL);
1799 return;
1802 qmp_change("vnc", target, !!arg, arg, &err);
1803 } else {
1804 if (read_only) {
1805 read_only_mode =
1806 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
1807 read_only,
1808 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1809 if (err) {
1810 hmp_handle_error(mon, &err);
1811 return;
1815 qmp_blockdev_change_medium(true, device, false, NULL, target,
1816 !!arg, arg, !!read_only, read_only_mode,
1817 &err);
1820 hmp_handle_error(mon, &err);
1823 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1825 Error *err = NULL;
1826 char *device = (char *) qdict_get_str(qdict, "device");
1827 BlockIOThrottle throttle = {
1828 .bps = qdict_get_int(qdict, "bps"),
1829 .bps_rd = qdict_get_int(qdict, "bps_rd"),
1830 .bps_wr = qdict_get_int(qdict, "bps_wr"),
1831 .iops = qdict_get_int(qdict, "iops"),
1832 .iops_rd = qdict_get_int(qdict, "iops_rd"),
1833 .iops_wr = qdict_get_int(qdict, "iops_wr"),
1836 /* qmp_block_set_io_throttle has separate parameters for the
1837 * (deprecated) block device name and the qdev ID but the HMP
1838 * version has only one, so we must decide which one to pass. */
1839 if (blk_by_name(device)) {
1840 throttle.has_device = true;
1841 throttle.device = device;
1842 } else {
1843 throttle.has_id = true;
1844 throttle.id = device;
1847 qmp_block_set_io_throttle(&throttle, &err);
1848 hmp_handle_error(mon, &err);
1851 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1853 Error *error = NULL;
1854 const char *device = qdict_get_str(qdict, "device");
1855 const char *base = qdict_get_try_str(qdict, "base");
1856 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1858 qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
1859 false, NULL, qdict_haskey(qdict, "speed"), speed,
1860 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1862 hmp_handle_error(mon, &error);
1865 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1867 Error *error = NULL;
1868 const char *device = qdict_get_str(qdict, "device");
1869 int64_t value = qdict_get_int(qdict, "speed");
1871 qmp_block_job_set_speed(device, value, &error);
1873 hmp_handle_error(mon, &error);
1876 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1878 Error *error = NULL;
1879 const char *device = qdict_get_str(qdict, "device");
1880 bool force = qdict_get_try_bool(qdict, "force", false);
1882 qmp_block_job_cancel(device, true, force, &error);
1884 hmp_handle_error(mon, &error);
1887 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1889 Error *error = NULL;
1890 const char *device = qdict_get_str(qdict, "device");
1892 qmp_block_job_pause(device, &error);
1894 hmp_handle_error(mon, &error);
1897 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1899 Error *error = NULL;
1900 const char *device = qdict_get_str(qdict, "device");
1902 qmp_block_job_resume(device, &error);
1904 hmp_handle_error(mon, &error);
1907 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1909 Error *error = NULL;
1910 const char *device = qdict_get_str(qdict, "device");
1912 qmp_block_job_complete(device, &error);
1914 hmp_handle_error(mon, &error);
1917 typedef struct HMPMigrationStatus
1919 QEMUTimer *timer;
1920 Monitor *mon;
1921 bool is_block_migration;
1922 } HMPMigrationStatus;
1924 static void hmp_migrate_status_cb(void *opaque)
1926 HMPMigrationStatus *status = opaque;
1927 MigrationInfo *info;
1929 info = qmp_query_migrate(NULL);
1930 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1931 info->status == MIGRATION_STATUS_SETUP) {
1932 if (info->has_disk) {
1933 int progress;
1935 if (info->disk->remaining) {
1936 progress = info->disk->transferred * 100 / info->disk->total;
1937 } else {
1938 progress = 100;
1941 monitor_printf(status->mon, "Completed %d %%\r", progress);
1942 monitor_flush(status->mon);
1945 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1946 } else {
1947 if (status->is_block_migration) {
1948 monitor_printf(status->mon, "\n");
1950 if (info->has_error_desc) {
1951 error_report("%s", info->error_desc);
1953 monitor_resume(status->mon);
1954 timer_del(status->timer);
1955 g_free(status);
1958 qapi_free_MigrationInfo(info);
1961 void hmp_migrate(Monitor *mon, const QDict *qdict)
1963 bool detach = qdict_get_try_bool(qdict, "detach", false);
1964 bool blk = qdict_get_try_bool(qdict, "blk", false);
1965 bool inc = qdict_get_try_bool(qdict, "inc", false);
1966 bool resume = qdict_get_try_bool(qdict, "resume", false);
1967 const char *uri = qdict_get_str(qdict, "uri");
1968 Error *err = NULL;
1970 qmp_migrate(uri, !!blk, blk, !!inc, inc,
1971 false, false, true, resume, &err);
1972 if (err) {
1973 hmp_handle_error(mon, &err);
1974 return;
1977 if (!detach) {
1978 HMPMigrationStatus *status;
1980 if (monitor_suspend(mon) < 0) {
1981 monitor_printf(mon, "terminal does not allow synchronous "
1982 "migration, continuing detached\n");
1983 return;
1986 status = g_malloc0(sizeof(*status));
1987 status->mon = mon;
1988 status->is_block_migration = blk || inc;
1989 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1990 status);
1991 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1995 void hmp_device_add(Monitor *mon, const QDict *qdict)
1997 Error *err = NULL;
1999 qmp_device_add((QDict *)qdict, NULL, &err);
2000 hmp_handle_error(mon, &err);
2003 void hmp_device_del(Monitor *mon, const QDict *qdict)
2005 const char *id = qdict_get_str(qdict, "id");
2006 Error *err = NULL;
2008 qmp_device_del(id, &err);
2009 hmp_handle_error(mon, &err);
2012 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
2014 Error *err = NULL;
2015 bool paging = qdict_get_try_bool(qdict, "paging", false);
2016 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
2017 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
2018 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
2019 const char *file = qdict_get_str(qdict, "filename");
2020 bool has_begin = qdict_haskey(qdict, "begin");
2021 bool has_length = qdict_haskey(qdict, "length");
2022 bool has_detach = qdict_haskey(qdict, "detach");
2023 int64_t begin = 0;
2024 int64_t length = 0;
2025 bool detach = false;
2026 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
2027 char *prot;
2029 if (zlib + lzo + snappy > 1) {
2030 error_setg(&err, "only one of '-z|-l|-s' can be set");
2031 hmp_handle_error(mon, &err);
2032 return;
2035 if (zlib) {
2036 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
2039 if (lzo) {
2040 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
2043 if (snappy) {
2044 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
2047 if (has_begin) {
2048 begin = qdict_get_int(qdict, "begin");
2050 if (has_length) {
2051 length = qdict_get_int(qdict, "length");
2053 if (has_detach) {
2054 detach = qdict_get_bool(qdict, "detach");
2057 prot = g_strconcat("file:", file, NULL);
2059 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
2060 has_length, length, true, dump_format, &err);
2061 hmp_handle_error(mon, &err);
2062 g_free(prot);
2065 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
2067 Error *err = NULL;
2068 QemuOpts *opts;
2070 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
2071 if (err) {
2072 goto out;
2075 netdev_add(opts, &err);
2076 if (err) {
2077 qemu_opts_del(opts);
2080 out:
2081 hmp_handle_error(mon, &err);
2084 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
2086 const char *id = qdict_get_str(qdict, "id");
2087 Error *err = NULL;
2089 qmp_netdev_del(id, &err);
2090 hmp_handle_error(mon, &err);
2093 void hmp_object_add(Monitor *mon, const QDict *qdict)
2095 Error *err = NULL;
2096 QemuOpts *opts;
2097 Object *obj = NULL;
2099 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
2100 if (err) {
2101 hmp_handle_error(mon, &err);
2102 return;
2105 obj = user_creatable_add_opts(opts, &err);
2106 qemu_opts_del(opts);
2108 if (err) {
2109 hmp_handle_error(mon, &err);
2111 if (obj) {
2112 object_unref(obj);
2116 void hmp_getfd(Monitor *mon, const QDict *qdict)
2118 const char *fdname = qdict_get_str(qdict, "fdname");
2119 Error *err = NULL;
2121 qmp_getfd(fdname, &err);
2122 hmp_handle_error(mon, &err);
2125 void hmp_closefd(Monitor *mon, const QDict *qdict)
2127 const char *fdname = qdict_get_str(qdict, "fdname");
2128 Error *err = NULL;
2130 qmp_closefd(fdname, &err);
2131 hmp_handle_error(mon, &err);
2134 void hmp_sendkey(Monitor *mon, const QDict *qdict)
2136 const char *keys = qdict_get_str(qdict, "keys");
2137 KeyValueList *keylist, *head = NULL, *tmp = NULL;
2138 int has_hold_time = qdict_haskey(qdict, "hold-time");
2139 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
2140 Error *err = NULL;
2141 char *separator;
2142 int keyname_len;
2144 while (1) {
2145 separator = strchr(keys, '-');
2146 keyname_len = separator ? separator - keys : strlen(keys);
2148 /* Be compatible with old interface, convert user inputted "<" */
2149 if (keys[0] == '<' && keyname_len == 1) {
2150 keys = "less";
2151 keyname_len = 4;
2154 keylist = g_malloc0(sizeof(*keylist));
2155 keylist->value = g_malloc0(sizeof(*keylist->value));
2157 if (!head) {
2158 head = keylist;
2160 if (tmp) {
2161 tmp->next = keylist;
2163 tmp = keylist;
2165 if (strstart(keys, "0x", NULL)) {
2166 char *endp;
2167 int value = strtoul(keys, &endp, 0);
2168 assert(endp <= keys + keyname_len);
2169 if (endp != keys + keyname_len) {
2170 goto err_out;
2172 keylist->value->type = KEY_VALUE_KIND_NUMBER;
2173 keylist->value->u.number.data = value;
2174 } else {
2175 int idx = index_from_key(keys, keyname_len);
2176 if (idx == Q_KEY_CODE__MAX) {
2177 goto err_out;
2179 keylist->value->type = KEY_VALUE_KIND_QCODE;
2180 keylist->value->u.qcode.data = idx;
2183 if (!separator) {
2184 break;
2186 keys = separator + 1;
2189 qmp_send_key(head, has_hold_time, hold_time, &err);
2190 hmp_handle_error(mon, &err);
2192 out:
2193 qapi_free_KeyValueList(head);
2194 return;
2196 err_out:
2197 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
2198 goto out;
2201 void hmp_screendump(Monitor *mon, const QDict *qdict)
2203 const char *filename = qdict_get_str(qdict, "filename");
2204 const char *id = qdict_get_try_str(qdict, "device");
2205 int64_t head = qdict_get_try_int(qdict, "head", 0);
2206 Error *err = NULL;
2208 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
2209 hmp_handle_error(mon, &err);
2212 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
2214 const char *uri = qdict_get_str(qdict, "uri");
2215 bool writable = qdict_get_try_bool(qdict, "writable", false);
2216 bool all = qdict_get_try_bool(qdict, "all", false);
2217 Error *local_err = NULL;
2218 BlockInfoList *block_list, *info;
2219 SocketAddress *addr;
2221 if (writable && !all) {
2222 error_setg(&local_err, "-w only valid together with -a");
2223 goto exit;
2226 /* First check if the address is valid and start the server. */
2227 addr = socket_parse(uri, &local_err);
2228 if (local_err != NULL) {
2229 goto exit;
2232 nbd_server_start(addr, NULL, &local_err);
2233 qapi_free_SocketAddress(addr);
2234 if (local_err != NULL) {
2235 goto exit;
2238 if (!all) {
2239 return;
2242 /* Then try adding all block devices. If one fails, close all and
2243 * exit.
2245 block_list = qmp_query_block(NULL);
2247 for (info = block_list; info; info = info->next) {
2248 if (!info->value->has_inserted) {
2249 continue;
2252 qmp_nbd_server_add(info->value->device, false, NULL,
2253 true, writable, &local_err);
2255 if (local_err != NULL) {
2256 qmp_nbd_server_stop(NULL);
2257 break;
2261 qapi_free_BlockInfoList(block_list);
2263 exit:
2264 hmp_handle_error(mon, &local_err);
2267 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
2269 const char *device = qdict_get_str(qdict, "device");
2270 const char *name = qdict_get_try_str(qdict, "name");
2271 bool writable = qdict_get_try_bool(qdict, "writable", false);
2272 Error *local_err = NULL;
2274 qmp_nbd_server_add(device, !!name, name, true, writable, &local_err);
2275 hmp_handle_error(mon, &local_err);
2278 void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict)
2280 const char *name = qdict_get_str(qdict, "name");
2281 bool force = qdict_get_try_bool(qdict, "force", false);
2282 Error *err = NULL;
2284 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
2285 qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err);
2286 hmp_handle_error(mon, &err);
2289 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
2291 Error *err = NULL;
2293 qmp_nbd_server_stop(&err);
2294 hmp_handle_error(mon, &err);
2297 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
2299 int cpuid;
2300 Error *err = NULL;
2302 cpuid = qdict_get_int(qdict, "id");
2303 qmp_cpu_add(cpuid, &err);
2304 hmp_handle_error(mon, &err);
2307 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2309 const char *args = qdict_get_str(qdict, "args");
2310 Error *err = NULL;
2311 QemuOpts *opts;
2313 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
2314 if (opts == NULL) {
2315 error_setg(&err, "Parsing chardev args failed");
2316 } else {
2317 qemu_chr_new_from_opts(opts, &err);
2318 qemu_opts_del(opts);
2320 hmp_handle_error(mon, &err);
2323 void hmp_chardev_change(Monitor *mon, const QDict *qdict)
2325 const char *args = qdict_get_str(qdict, "args");
2326 const char *id;
2327 Error *err = NULL;
2328 ChardevBackend *backend = NULL;
2329 ChardevReturn *ret = NULL;
2330 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
2331 true);
2332 if (!opts) {
2333 error_setg(&err, "Parsing chardev args failed");
2334 goto end;
2337 id = qdict_get_str(qdict, "id");
2338 if (qemu_opts_id(opts)) {
2339 error_setg(&err, "Unexpected 'id' parameter");
2340 goto end;
2343 backend = qemu_chr_parse_opts(opts, &err);
2344 if (!backend) {
2345 goto end;
2348 ret = qmp_chardev_change(id, backend, &err);
2350 end:
2351 qapi_free_ChardevReturn(ret);
2352 qapi_free_ChardevBackend(backend);
2353 qemu_opts_del(opts);
2354 hmp_handle_error(mon, &err);
2357 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2359 Error *local_err = NULL;
2361 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
2362 hmp_handle_error(mon, &local_err);
2365 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
2367 Error *local_err = NULL;
2369 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
2370 hmp_handle_error(mon, &local_err);
2373 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
2375 BlockBackend *blk;
2376 BlockBackend *local_blk = NULL;
2377 const char* device = qdict_get_str(qdict, "device");
2378 const char* command = qdict_get_str(qdict, "command");
2379 Error *err = NULL;
2380 int ret;
2382 blk = blk_by_name(device);
2383 if (!blk) {
2384 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
2385 if (bs) {
2386 blk = local_blk = blk_new(0, BLK_PERM_ALL);
2387 ret = blk_insert_bs(blk, bs, &err);
2388 if (ret < 0) {
2389 goto fail;
2391 } else {
2392 goto fail;
2397 * Notably absent: Proper permission management. This is sad, but it seems
2398 * almost impossible to achieve without changing the semantics and thereby
2399 * limiting the use cases of the qemu-io HMP command.
2401 * In an ideal world we would unconditionally create a new BlockBackend for
2402 * qemuio_command(), but we have commands like 'reopen' and want them to
2403 * take effect on the exact BlockBackend whose name the user passed instead
2404 * of just on a temporary copy of it.
2406 * Another problem is that deleting the temporary BlockBackend involves
2407 * draining all requests on it first, but some qemu-iotests cases want to
2408 * issue multiple aio_read/write requests and expect them to complete in
2409 * the background while the monitor has already returned.
2411 * This is also what prevents us from saving the original permissions and
2412 * restoring them later: We can't revoke permissions until all requests
2413 * have completed, and we don't know when that is nor can we really let
2414 * anything else run before we have revoken them to avoid race conditions.
2416 * What happens now is that command() in qemu-io-cmds.c can extend the
2417 * permissions if necessary for the qemu-io command. And they simply stay
2418 * extended, possibly resulting in a read-only guest device keeping write
2419 * permissions. Ugly, but it appears to be the lesser evil.
2421 qemuio_command(blk, command);
2423 fail:
2424 blk_unref(local_blk);
2425 hmp_handle_error(mon, &err);
2428 void hmp_object_del(Monitor *mon, const QDict *qdict)
2430 const char *id = qdict_get_str(qdict, "id");
2431 Error *err = NULL;
2433 user_creatable_del(id, &err);
2434 hmp_handle_error(mon, &err);
2437 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
2439 Error *err = NULL;
2440 MemdevList *memdev_list = qmp_query_memdev(&err);
2441 MemdevList *m = memdev_list;
2442 Visitor *v;
2443 char *str;
2445 while (m) {
2446 v = string_output_visitor_new(false, &str);
2447 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
2448 monitor_printf(mon, "memory backend: %s\n", m->value->id);
2449 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
2450 monitor_printf(mon, " merge: %s\n",
2451 m->value->merge ? "true" : "false");
2452 monitor_printf(mon, " dump: %s\n",
2453 m->value->dump ? "true" : "false");
2454 monitor_printf(mon, " prealloc: %s\n",
2455 m->value->prealloc ? "true" : "false");
2456 monitor_printf(mon, " policy: %s\n",
2457 HostMemPolicy_str(m->value->policy));
2458 visit_complete(v, &str);
2459 monitor_printf(mon, " host nodes: %s\n", str);
2461 g_free(str);
2462 visit_free(v);
2463 m = m->next;
2466 monitor_printf(mon, "\n");
2468 qapi_free_MemdevList(memdev_list);
2469 hmp_handle_error(mon, &err);
2472 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2474 Error *err = NULL;
2475 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2476 MemoryDeviceInfoList *info;
2477 MemoryDeviceInfo *value;
2478 PCDIMMDeviceInfo *di;
2480 for (info = info_list; info; info = info->next) {
2481 value = info->value;
2483 if (value) {
2484 switch (value->type) {
2485 case MEMORY_DEVICE_INFO_KIND_DIMM:
2486 di = value->u.dimm.data;
2487 break;
2489 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
2490 di = value->u.nvdimm.data;
2491 break;
2493 default:
2494 di = NULL;
2495 break;
2498 if (di) {
2499 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2500 MemoryDeviceInfoKind_str(value->type),
2501 di->id ? di->id : "");
2502 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2503 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2504 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2505 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2506 monitor_printf(mon, " memdev: %s\n", di->memdev);
2507 monitor_printf(mon, " hotplugged: %s\n",
2508 di->hotplugged ? "true" : "false");
2509 monitor_printf(mon, " hotpluggable: %s\n",
2510 di->hotpluggable ? "true" : "false");
2515 qapi_free_MemoryDeviceInfoList(info_list);
2516 hmp_handle_error(mon, &err);
2519 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2521 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2522 IOThreadInfoList *info;
2523 IOThreadInfo *value;
2525 for (info = info_list; info; info = info->next) {
2526 value = info->value;
2527 monitor_printf(mon, "%s:\n", value->id);
2528 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
2529 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2530 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
2531 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
2534 qapi_free_IOThreadInfoList(info_list);
2537 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2539 const char *path = qdict_get_try_str(qdict, "path");
2540 ObjectPropertyInfoList *list;
2541 Error *err = NULL;
2543 if (path == NULL) {
2544 monitor_printf(mon, "/\n");
2545 return;
2548 list = qmp_qom_list(path, &err);
2549 if (err == NULL) {
2550 ObjectPropertyInfoList *start = list;
2551 while (list != NULL) {
2552 ObjectPropertyInfo *value = list->value;
2554 monitor_printf(mon, "%s (%s)\n",
2555 value->name, value->type);
2556 list = list->next;
2558 qapi_free_ObjectPropertyInfoList(start);
2560 hmp_handle_error(mon, &err);
2563 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2565 const char *path = qdict_get_str(qdict, "path");
2566 const char *property = qdict_get_str(qdict, "property");
2567 const char *value = qdict_get_str(qdict, "value");
2568 Error *err = NULL;
2569 bool ambiguous = false;
2570 Object *obj;
2572 obj = object_resolve_path(path, &ambiguous);
2573 if (obj == NULL) {
2574 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2575 "Device '%s' not found", path);
2576 } else {
2577 if (ambiguous) {
2578 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2580 object_property_parse(obj, value, property, &err);
2582 hmp_handle_error(mon, &err);
2585 void hmp_rocker(Monitor *mon, const QDict *qdict)
2587 const char *name = qdict_get_str(qdict, "name");
2588 RockerSwitch *rocker;
2589 Error *err = NULL;
2591 rocker = qmp_query_rocker(name, &err);
2592 if (err != NULL) {
2593 hmp_handle_error(mon, &err);
2594 return;
2597 monitor_printf(mon, "name: %s\n", rocker->name);
2598 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2599 monitor_printf(mon, "ports: %d\n", rocker->ports);
2601 qapi_free_RockerSwitch(rocker);
2604 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2606 RockerPortList *list, *port;
2607 const char *name = qdict_get_str(qdict, "name");
2608 Error *err = NULL;
2610 list = qmp_query_rocker_ports(name, &err);
2611 if (err != NULL) {
2612 hmp_handle_error(mon, &err);
2613 return;
2616 monitor_printf(mon, " ena/ speed/ auto\n");
2617 monitor_printf(mon, " port link duplex neg?\n");
2619 for (port = list; port; port = port->next) {
2620 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2621 port->value->name,
2622 port->value->enabled ? port->value->link_up ?
2623 "up" : "down" : "!ena",
2624 port->value->speed == 10000 ? "10G" : "??",
2625 port->value->duplex ? "FD" : "HD",
2626 port->value->autoneg ? "Yes" : "No");
2629 qapi_free_RockerPortList(list);
2632 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2634 RockerOfDpaFlowList *list, *info;
2635 const char *name = qdict_get_str(qdict, "name");
2636 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2637 Error *err = NULL;
2639 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2640 if (err != NULL) {
2641 hmp_handle_error(mon, &err);
2642 return;
2645 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2647 for (info = list; info; info = info->next) {
2648 RockerOfDpaFlow *flow = info->value;
2649 RockerOfDpaFlowKey *key = flow->key;
2650 RockerOfDpaFlowMask *mask = flow->mask;
2651 RockerOfDpaFlowAction *action = flow->action;
2653 if (flow->hits) {
2654 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2655 key->priority, key->tbl_id, flow->hits);
2656 } else {
2657 monitor_printf(mon, "%-4d %-3d ",
2658 key->priority, key->tbl_id);
2661 if (key->has_in_pport) {
2662 monitor_printf(mon, " pport %d", key->in_pport);
2663 if (mask->has_in_pport) {
2664 monitor_printf(mon, "(0x%x)", mask->in_pport);
2668 if (key->has_vlan_id) {
2669 monitor_printf(mon, " vlan %d",
2670 key->vlan_id & VLAN_VID_MASK);
2671 if (mask->has_vlan_id) {
2672 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2676 if (key->has_tunnel_id) {
2677 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2678 if (mask->has_tunnel_id) {
2679 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2683 if (key->has_eth_type) {
2684 switch (key->eth_type) {
2685 case 0x0806:
2686 monitor_printf(mon, " ARP");
2687 break;
2688 case 0x0800:
2689 monitor_printf(mon, " IP");
2690 break;
2691 case 0x86dd:
2692 monitor_printf(mon, " IPv6");
2693 break;
2694 case 0x8809:
2695 monitor_printf(mon, " LACP");
2696 break;
2697 case 0x88cc:
2698 monitor_printf(mon, " LLDP");
2699 break;
2700 default:
2701 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2702 break;
2706 if (key->has_eth_src) {
2707 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2708 (mask->has_eth_src) &&
2709 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2710 monitor_printf(mon, " src <any mcast/bcast>");
2711 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2712 (mask->has_eth_src) &&
2713 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2714 monitor_printf(mon, " src <any ucast>");
2715 } else {
2716 monitor_printf(mon, " src %s", key->eth_src);
2717 if (mask->has_eth_src) {
2718 monitor_printf(mon, "(%s)", mask->eth_src);
2723 if (key->has_eth_dst) {
2724 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2725 (mask->has_eth_dst) &&
2726 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2727 monitor_printf(mon, " dst <any mcast/bcast>");
2728 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2729 (mask->has_eth_dst) &&
2730 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2731 monitor_printf(mon, " dst <any ucast>");
2732 } else {
2733 monitor_printf(mon, " dst %s", key->eth_dst);
2734 if (mask->has_eth_dst) {
2735 monitor_printf(mon, "(%s)", mask->eth_dst);
2740 if (key->has_ip_proto) {
2741 monitor_printf(mon, " proto %d", key->ip_proto);
2742 if (mask->has_ip_proto) {
2743 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2747 if (key->has_ip_tos) {
2748 monitor_printf(mon, " TOS %d", key->ip_tos);
2749 if (mask->has_ip_tos) {
2750 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2754 if (key->has_ip_dst) {
2755 monitor_printf(mon, " dst %s", key->ip_dst);
2758 if (action->has_goto_tbl || action->has_group_id ||
2759 action->has_new_vlan_id) {
2760 monitor_printf(mon, " -->");
2763 if (action->has_new_vlan_id) {
2764 monitor_printf(mon, " apply new vlan %d",
2765 ntohs(action->new_vlan_id));
2768 if (action->has_group_id) {
2769 monitor_printf(mon, " write group 0x%08x", action->group_id);
2772 if (action->has_goto_tbl) {
2773 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2776 monitor_printf(mon, "\n");
2779 qapi_free_RockerOfDpaFlowList(list);
2782 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2784 RockerOfDpaGroupList *list, *g;
2785 const char *name = qdict_get_str(qdict, "name");
2786 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2787 Error *err = NULL;
2788 bool set = false;
2790 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2791 if (err != NULL) {
2792 hmp_handle_error(mon, &err);
2793 return;
2796 monitor_printf(mon, "id (decode) --> buckets\n");
2798 for (g = list; g; g = g->next) {
2799 RockerOfDpaGroup *group = g->value;
2801 monitor_printf(mon, "0x%08x", group->id);
2803 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2804 group->type == 1 ? "L2 rewrite" :
2805 group->type == 2 ? "L3 unicast" :
2806 group->type == 3 ? "L2 multicast" :
2807 group->type == 4 ? "L2 flood" :
2808 group->type == 5 ? "L3 interface" :
2809 group->type == 6 ? "L3 multicast" :
2810 group->type == 7 ? "L3 ECMP" :
2811 group->type == 8 ? "L2 overlay" :
2812 "unknown");
2814 if (group->has_vlan_id) {
2815 monitor_printf(mon, " vlan %d", group->vlan_id);
2818 if (group->has_pport) {
2819 monitor_printf(mon, " pport %d", group->pport);
2822 if (group->has_index) {
2823 monitor_printf(mon, " index %d", group->index);
2826 monitor_printf(mon, ") -->");
2828 if (group->has_set_vlan_id && group->set_vlan_id) {
2829 set = true;
2830 monitor_printf(mon, " set vlan %d",
2831 group->set_vlan_id & VLAN_VID_MASK);
2834 if (group->has_set_eth_src) {
2835 if (!set) {
2836 set = true;
2837 monitor_printf(mon, " set");
2839 monitor_printf(mon, " src %s", group->set_eth_src);
2842 if (group->has_set_eth_dst) {
2843 if (!set) {
2844 set = true;
2845 monitor_printf(mon, " set");
2847 monitor_printf(mon, " dst %s", group->set_eth_dst);
2850 set = false;
2852 if (group->has_ttl_check && group->ttl_check) {
2853 monitor_printf(mon, " check TTL");
2856 if (group->has_group_id && group->group_id) {
2857 monitor_printf(mon, " group id 0x%08x", group->group_id);
2860 if (group->has_pop_vlan && group->pop_vlan) {
2861 monitor_printf(mon, " pop vlan");
2864 if (group->has_out_pport) {
2865 monitor_printf(mon, " out pport %d", group->out_pport);
2868 if (group->has_group_ids) {
2869 struct uint32List *id;
2871 monitor_printf(mon, " groups [");
2872 for (id = group->group_ids; id; id = id->next) {
2873 monitor_printf(mon, "0x%08x", id->value);
2874 if (id->next) {
2875 monitor_printf(mon, ",");
2878 monitor_printf(mon, "]");
2881 monitor_printf(mon, "\n");
2884 qapi_free_RockerOfDpaGroupList(list);
2887 void hmp_info_dump(Monitor *mon, const QDict *qdict)
2889 DumpQueryResult *result = qmp_query_dump(NULL);
2891 assert(result && result->status < DUMP_STATUS__MAX);
2892 monitor_printf(mon, "Status: %s\n", DumpStatus_str(result->status));
2894 if (result->status == DUMP_STATUS_ACTIVE) {
2895 float percent = 0;
2896 assert(result->total != 0);
2897 percent = 100.0 * result->completed / result->total;
2898 monitor_printf(mon, "Finished: %.2f %%\n", percent);
2901 qapi_free_DumpQueryResult(result);
2904 void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
2906 ram_block_dump(mon);
2909 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
2911 Error *err = NULL;
2912 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
2913 HotpluggableCPUList *saved = l;
2914 CpuInstanceProperties *c;
2916 if (err != NULL) {
2917 hmp_handle_error(mon, &err);
2918 return;
2921 monitor_printf(mon, "Hotpluggable CPUs:\n");
2922 while (l) {
2923 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
2924 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
2925 l->value->vcpus_count);
2926 if (l->value->has_qom_path) {
2927 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
2930 c = l->value->props;
2931 monitor_printf(mon, " CPUInstance Properties:\n");
2932 if (c->has_node_id) {
2933 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
2935 if (c->has_socket_id) {
2936 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
2938 if (c->has_core_id) {
2939 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
2941 if (c->has_thread_id) {
2942 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
2945 l = l->next;
2948 qapi_free_HotpluggableCPUList(saved);
2951 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
2953 Error *err = NULL;
2954 GuidInfo *info = qmp_query_vm_generation_id(&err);
2955 if (info) {
2956 monitor_printf(mon, "%s\n", info->guid);
2958 hmp_handle_error(mon, &err);
2959 qapi_free_GuidInfo(info);
2962 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
2964 Error *err = NULL;
2965 MemoryInfo *info = qmp_query_memory_size_summary(&err);
2966 if (info) {
2967 monitor_printf(mon, "base memory: %" PRIu64 "\n",
2968 info->base_memory);
2970 if (info->has_plugged_memory) {
2971 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
2972 info->plugged_memory);
2975 qapi_free_MemoryInfo(info);
2977 hmp_handle_error(mon, &err);