hmp/migration: add migrate_recover command
[qemu/ar7.git] / hmp.c
blob2a36c1cf8d9e48e16fcbd5db23b19b4020f7b476
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);
375 qapi_free_MigrationParameters(params);
378 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
380 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
381 qmp_query_migrate_cache_size(NULL) >> 10);
384 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
386 CpuInfoFastList *cpu_list, *cpu;
388 cpu_list = qmp_query_cpus_fast(NULL);
390 for (cpu = cpu_list; cpu; cpu = cpu->next) {
391 int active = ' ';
393 if (cpu->value->cpu_index == monitor_get_cpu_index()) {
394 active = '*';
397 monitor_printf(mon, "%c CPU #%" PRId64 ":", active,
398 cpu->value->cpu_index);
399 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
402 qapi_free_CpuInfoFastList(cpu_list);
405 static void print_block_info(Monitor *mon, BlockInfo *info,
406 BlockDeviceInfo *inserted, bool verbose)
408 ImageInfo *image_info;
410 assert(!info || !info->has_inserted || info->inserted == inserted);
412 if (info && *info->device) {
413 monitor_printf(mon, "%s", info->device);
414 if (inserted && inserted->has_node_name) {
415 monitor_printf(mon, " (%s)", inserted->node_name);
417 } else {
418 assert(info || inserted);
419 monitor_printf(mon, "%s",
420 inserted && inserted->has_node_name ? inserted->node_name
421 : info && info->has_qdev ? info->qdev
422 : "<anonymous>");
425 if (inserted) {
426 monitor_printf(mon, ": %s (%s%s%s)\n",
427 inserted->file,
428 inserted->drv,
429 inserted->ro ? ", read-only" : "",
430 inserted->encrypted ? ", encrypted" : "");
431 } else {
432 monitor_printf(mon, ": [not inserted]\n");
435 if (info) {
436 if (info->has_qdev) {
437 monitor_printf(mon, " Attached to: %s\n", info->qdev);
439 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
440 monitor_printf(mon, " I/O status: %s\n",
441 BlockDeviceIoStatus_str(info->io_status));
444 if (info->removable) {
445 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
446 info->locked ? "" : "not ",
447 info->tray_open ? "open" : "closed");
452 if (!inserted) {
453 return;
456 monitor_printf(mon, " Cache mode: %s%s%s\n",
457 inserted->cache->writeback ? "writeback" : "writethrough",
458 inserted->cache->direct ? ", direct" : "",
459 inserted->cache->no_flush ? ", ignore flushes" : "");
461 if (inserted->has_backing_file) {
462 monitor_printf(mon,
463 " Backing file: %s "
464 "(chain depth: %" PRId64 ")\n",
465 inserted->backing_file,
466 inserted->backing_file_depth);
469 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
470 monitor_printf(mon, " Detect zeroes: %s\n",
471 BlockdevDetectZeroesOptions_str(inserted->detect_zeroes));
474 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
475 inserted->iops || inserted->iops_rd || inserted->iops_wr)
477 monitor_printf(mon, " I/O throttling: bps=%" PRId64
478 " bps_rd=%" PRId64 " bps_wr=%" PRId64
479 " bps_max=%" PRId64
480 " bps_rd_max=%" PRId64
481 " bps_wr_max=%" PRId64
482 " iops=%" PRId64 " iops_rd=%" PRId64
483 " iops_wr=%" PRId64
484 " iops_max=%" PRId64
485 " iops_rd_max=%" PRId64
486 " iops_wr_max=%" PRId64
487 " iops_size=%" PRId64
488 " group=%s\n",
489 inserted->bps,
490 inserted->bps_rd,
491 inserted->bps_wr,
492 inserted->bps_max,
493 inserted->bps_rd_max,
494 inserted->bps_wr_max,
495 inserted->iops,
496 inserted->iops_rd,
497 inserted->iops_wr,
498 inserted->iops_max,
499 inserted->iops_rd_max,
500 inserted->iops_wr_max,
501 inserted->iops_size,
502 inserted->group);
505 if (verbose) {
506 monitor_printf(mon, "\nImages:\n");
507 image_info = inserted->image;
508 while (1) {
509 bdrv_image_info_dump((fprintf_function)monitor_printf,
510 mon, image_info);
511 if (image_info->has_backing_image) {
512 image_info = image_info->backing_image;
513 } else {
514 break;
520 void hmp_info_block(Monitor *mon, const QDict *qdict)
522 BlockInfoList *block_list, *info;
523 BlockDeviceInfoList *blockdev_list, *blockdev;
524 const char *device = qdict_get_try_str(qdict, "device");
525 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
526 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
527 bool printed = false;
529 /* Print BlockBackend information */
530 if (!nodes) {
531 block_list = qmp_query_block(NULL);
532 } else {
533 block_list = NULL;
536 for (info = block_list; info; info = info->next) {
537 if (device && strcmp(device, info->value->device)) {
538 continue;
541 if (info != block_list) {
542 monitor_printf(mon, "\n");
545 print_block_info(mon, info->value, info->value->has_inserted
546 ? info->value->inserted : NULL,
547 verbose);
548 printed = true;
551 qapi_free_BlockInfoList(block_list);
553 if ((!device && !nodes) || printed) {
554 return;
557 /* Print node information */
558 blockdev_list = qmp_query_named_block_nodes(NULL);
559 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
560 assert(blockdev->value->has_node_name);
561 if (device && strcmp(device, blockdev->value->node_name)) {
562 continue;
565 if (blockdev != blockdev_list) {
566 monitor_printf(mon, "\n");
569 print_block_info(mon, NULL, blockdev->value, verbose);
571 qapi_free_BlockDeviceInfoList(blockdev_list);
574 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
576 BlockStatsList *stats_list, *stats;
578 stats_list = qmp_query_blockstats(false, false, NULL);
580 for (stats = stats_list; stats; stats = stats->next) {
581 if (!stats->value->has_device) {
582 continue;
585 monitor_printf(mon, "%s:", stats->value->device);
586 monitor_printf(mon, " rd_bytes=%" PRId64
587 " wr_bytes=%" PRId64
588 " rd_operations=%" PRId64
589 " wr_operations=%" PRId64
590 " flush_operations=%" PRId64
591 " wr_total_time_ns=%" PRId64
592 " rd_total_time_ns=%" PRId64
593 " flush_total_time_ns=%" PRId64
594 " rd_merged=%" PRId64
595 " wr_merged=%" PRId64
596 " idle_time_ns=%" PRId64
597 "\n",
598 stats->value->stats->rd_bytes,
599 stats->value->stats->wr_bytes,
600 stats->value->stats->rd_operations,
601 stats->value->stats->wr_operations,
602 stats->value->stats->flush_operations,
603 stats->value->stats->wr_total_time_ns,
604 stats->value->stats->rd_total_time_ns,
605 stats->value->stats->flush_total_time_ns,
606 stats->value->stats->rd_merged,
607 stats->value->stats->wr_merged,
608 stats->value->stats->idle_time_ns);
611 qapi_free_BlockStatsList(stats_list);
614 /* Helper for hmp_info_vnc_clients, _servers */
615 static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
616 const char *name)
618 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
619 name,
620 info->host,
621 info->service,
622 NetworkAddressFamily_str(info->family),
623 info->websocket ? " (Websocket)" : "");
626 /* Helper displaying and auth and crypt info */
627 static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
628 VncPrimaryAuth auth,
629 VncVencryptSubAuth *vencrypt)
631 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
632 VncPrimaryAuth_str(auth),
633 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
636 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
638 while (client) {
639 VncClientInfo *cinfo = client->value;
641 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
642 monitor_printf(mon, " x509_dname: %s\n",
643 cinfo->has_x509_dname ?
644 cinfo->x509_dname : "none");
645 monitor_printf(mon, " sasl_username: %s\n",
646 cinfo->has_sasl_username ?
647 cinfo->sasl_username : "none");
649 client = client->next;
653 static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
655 while (server) {
656 VncServerInfo2 *sinfo = server->value;
657 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
658 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
659 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
660 server = server->next;
664 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
666 VncInfo2List *info2l;
667 Error *err = NULL;
669 info2l = qmp_query_vnc_servers(&err);
670 if (err) {
671 hmp_handle_error(mon, &err);
672 return;
674 if (!info2l) {
675 monitor_printf(mon, "None\n");
676 return;
679 while (info2l) {
680 VncInfo2 *info = info2l->value;
681 monitor_printf(mon, "%s:\n", info->id);
682 hmp_info_vnc_servers(mon, info->server);
683 hmp_info_vnc_clients(mon, info->clients);
684 if (!info->server) {
685 /* The server entry displays its auth, we only
686 * need to display in the case of 'reverse' connections
687 * where there's no server.
689 hmp_info_vnc_authcrypt(mon, " ", info->auth,
690 info->has_vencrypt ? &info->vencrypt : NULL);
692 if (info->has_display) {
693 monitor_printf(mon, " Display: %s\n", info->display);
695 info2l = info2l->next;
698 qapi_free_VncInfo2List(info2l);
702 #ifdef CONFIG_SPICE
703 void hmp_info_spice(Monitor *mon, const QDict *qdict)
705 SpiceChannelList *chan;
706 SpiceInfo *info;
707 const char *channel_name;
708 const char * const channel_names[] = {
709 [SPICE_CHANNEL_MAIN] = "main",
710 [SPICE_CHANNEL_DISPLAY] = "display",
711 [SPICE_CHANNEL_INPUTS] = "inputs",
712 [SPICE_CHANNEL_CURSOR] = "cursor",
713 [SPICE_CHANNEL_PLAYBACK] = "playback",
714 [SPICE_CHANNEL_RECORD] = "record",
715 [SPICE_CHANNEL_TUNNEL] = "tunnel",
716 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
717 [SPICE_CHANNEL_USBREDIR] = "usbredir",
718 [SPICE_CHANNEL_PORT] = "port",
719 #if 0
720 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
721 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
722 * as quick fix for build failures with older versions. */
723 [SPICE_CHANNEL_WEBDAV] = "webdav",
724 #endif
727 info = qmp_query_spice(NULL);
729 if (!info->enabled) {
730 monitor_printf(mon, "Server: disabled\n");
731 goto out;
734 monitor_printf(mon, "Server:\n");
735 if (info->has_port) {
736 monitor_printf(mon, " address: %s:%" PRId64 "\n",
737 info->host, info->port);
739 if (info->has_tls_port) {
740 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
741 info->host, info->tls_port);
743 monitor_printf(mon, " migrated: %s\n",
744 info->migrated ? "true" : "false");
745 monitor_printf(mon, " auth: %s\n", info->auth);
746 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
747 monitor_printf(mon, " mouse-mode: %s\n",
748 SpiceQueryMouseMode_str(info->mouse_mode));
750 if (!info->has_channels || info->channels == NULL) {
751 monitor_printf(mon, "Channels: none\n");
752 } else {
753 for (chan = info->channels; chan; chan = chan->next) {
754 monitor_printf(mon, "Channel:\n");
755 monitor_printf(mon, " address: %s:%s%s\n",
756 chan->value->host, chan->value->port,
757 chan->value->tls ? " [tls]" : "");
758 monitor_printf(mon, " session: %" PRId64 "\n",
759 chan->value->connection_id);
760 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
761 chan->value->channel_type, chan->value->channel_id);
763 channel_name = "unknown";
764 if (chan->value->channel_type > 0 &&
765 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
766 channel_names[chan->value->channel_type]) {
767 channel_name = channel_names[chan->value->channel_type];
770 monitor_printf(mon, " channel name: %s\n", channel_name);
774 out:
775 qapi_free_SpiceInfo(info);
777 #endif
779 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
781 BalloonInfo *info;
782 Error *err = NULL;
784 info = qmp_query_balloon(&err);
785 if (err) {
786 hmp_handle_error(mon, &err);
787 return;
790 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
792 qapi_free_BalloonInfo(info);
795 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
797 PciMemoryRegionList *region;
799 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
800 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
801 dev->slot, dev->function);
802 monitor_printf(mon, " ");
804 if (dev->class_info->has_desc) {
805 monitor_printf(mon, "%s", dev->class_info->desc);
806 } else {
807 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
810 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
811 dev->id->vendor, dev->id->device);
813 if (dev->has_irq) {
814 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
817 if (dev->has_pci_bridge) {
818 monitor_printf(mon, " BUS %" PRId64 ".\n",
819 dev->pci_bridge->bus->number);
820 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
821 dev->pci_bridge->bus->secondary);
822 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
823 dev->pci_bridge->bus->subordinate);
825 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
826 dev->pci_bridge->bus->io_range->base,
827 dev->pci_bridge->bus->io_range->limit);
829 monitor_printf(mon,
830 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
831 dev->pci_bridge->bus->memory_range->base,
832 dev->pci_bridge->bus->memory_range->limit);
834 monitor_printf(mon, " prefetchable memory range "
835 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
836 dev->pci_bridge->bus->prefetchable_range->base,
837 dev->pci_bridge->bus->prefetchable_range->limit);
840 for (region = dev->regions; region; region = region->next) {
841 uint64_t addr, size;
843 addr = region->value->address;
844 size = region->value->size;
846 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
848 if (!strcmp(region->value->type, "io")) {
849 monitor_printf(mon, "I/O at 0x%04" PRIx64
850 " [0x%04" PRIx64 "].\n",
851 addr, addr + size - 1);
852 } else {
853 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
854 " [0x%08" PRIx64 "].\n",
855 region->value->mem_type_64 ? 64 : 32,
856 region->value->prefetch ? " prefetchable" : "",
857 addr, addr + size - 1);
861 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
863 if (dev->has_pci_bridge) {
864 if (dev->pci_bridge->has_devices) {
865 PciDeviceInfoList *cdev;
866 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
867 hmp_info_pci_device(mon, cdev->value);
873 static int hmp_info_irq_foreach(Object *obj, void *opaque)
875 InterruptStatsProvider *intc;
876 InterruptStatsProviderClass *k;
877 Monitor *mon = opaque;
879 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
880 intc = INTERRUPT_STATS_PROVIDER(obj);
881 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
882 uint64_t *irq_counts;
883 unsigned int nb_irqs, i;
884 if (k->get_statistics &&
885 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
886 if (nb_irqs > 0) {
887 monitor_printf(mon, "IRQ statistics for %s:\n",
888 object_get_typename(obj));
889 for (i = 0; i < nb_irqs; i++) {
890 if (irq_counts[i] > 0) {
891 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
892 irq_counts[i]);
896 } else {
897 monitor_printf(mon, "IRQ statistics not available for %s.\n",
898 object_get_typename(obj));
902 return 0;
905 void hmp_info_irq(Monitor *mon, const QDict *qdict)
907 object_child_foreach_recursive(object_get_root(),
908 hmp_info_irq_foreach, mon);
911 static int hmp_info_pic_foreach(Object *obj, void *opaque)
913 InterruptStatsProvider *intc;
914 InterruptStatsProviderClass *k;
915 Monitor *mon = opaque;
917 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
918 intc = INTERRUPT_STATS_PROVIDER(obj);
919 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
920 if (k->print_info) {
921 k->print_info(intc, mon);
922 } else {
923 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
924 object_get_typename(obj));
928 return 0;
931 void hmp_info_pic(Monitor *mon, const QDict *qdict)
933 object_child_foreach_recursive(object_get_root(),
934 hmp_info_pic_foreach, mon);
937 void hmp_info_pci(Monitor *mon, const QDict *qdict)
939 PciInfoList *info_list, *info;
940 Error *err = NULL;
942 info_list = qmp_query_pci(&err);
943 if (err) {
944 monitor_printf(mon, "PCI devices not supported\n");
945 error_free(err);
946 return;
949 for (info = info_list; info; info = info->next) {
950 PciDeviceInfoList *dev;
952 for (dev = info->value->devices; dev; dev = dev->next) {
953 hmp_info_pci_device(mon, dev->value);
957 qapi_free_PciInfoList(info_list);
960 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
962 BlockJobInfoList *list;
963 Error *err = NULL;
965 list = qmp_query_block_jobs(&err);
966 assert(!err);
968 if (!list) {
969 monitor_printf(mon, "No active jobs\n");
970 return;
973 while (list) {
974 if (strcmp(list->value->type, "stream") == 0) {
975 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
976 " of %" PRId64 " bytes, speed limit %" PRId64
977 " bytes/s\n",
978 list->value->device,
979 list->value->offset,
980 list->value->len,
981 list->value->speed);
982 } else {
983 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
984 " of %" PRId64 " bytes, speed limit %" PRId64
985 " bytes/s\n",
986 list->value->type,
987 list->value->device,
988 list->value->offset,
989 list->value->len,
990 list->value->speed);
992 list = list->next;
995 qapi_free_BlockJobInfoList(list);
998 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
1000 TPMInfoList *info_list, *info;
1001 Error *err = NULL;
1002 unsigned int c = 0;
1003 TPMPassthroughOptions *tpo;
1004 TPMEmulatorOptions *teo;
1006 info_list = qmp_query_tpm(&err);
1007 if (err) {
1008 monitor_printf(mon, "TPM device not supported\n");
1009 error_free(err);
1010 return;
1013 if (info_list) {
1014 monitor_printf(mon, "TPM device:\n");
1017 for (info = info_list; info; info = info->next) {
1018 TPMInfo *ti = info->value;
1019 monitor_printf(mon, " tpm%d: model=%s\n",
1020 c, TpmModel_str(ti->model));
1022 monitor_printf(mon, " \\ %s: type=%s",
1023 ti->id, TpmTypeOptionsKind_str(ti->options->type));
1025 switch (ti->options->type) {
1026 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
1027 tpo = ti->options->u.passthrough.data;
1028 monitor_printf(mon, "%s%s%s%s",
1029 tpo->has_path ? ",path=" : "",
1030 tpo->has_path ? tpo->path : "",
1031 tpo->has_cancel_path ? ",cancel-path=" : "",
1032 tpo->has_cancel_path ? tpo->cancel_path : "");
1033 break;
1034 case TPM_TYPE_OPTIONS_KIND_EMULATOR:
1035 teo = ti->options->u.emulator.data;
1036 monitor_printf(mon, ",chardev=%s", teo->chardev);
1037 break;
1038 case TPM_TYPE_OPTIONS_KIND__MAX:
1039 break;
1041 monitor_printf(mon, "\n");
1042 c++;
1044 qapi_free_TPMInfoList(info_list);
1047 void hmp_quit(Monitor *mon, const QDict *qdict)
1049 monitor_suspend(mon);
1050 qmp_quit(NULL);
1053 void hmp_stop(Monitor *mon, const QDict *qdict)
1055 qmp_stop(NULL);
1058 void hmp_system_reset(Monitor *mon, const QDict *qdict)
1060 qmp_system_reset(NULL);
1063 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
1065 qmp_system_powerdown(NULL);
1068 void hmp_cpu(Monitor *mon, const QDict *qdict)
1070 int64_t cpu_index;
1072 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1073 use it are converted to the QAPI */
1074 cpu_index = qdict_get_int(qdict, "index");
1075 if (monitor_set_cpu(cpu_index) < 0) {
1076 monitor_printf(mon, "invalid CPU index\n");
1080 void hmp_memsave(Monitor *mon, const QDict *qdict)
1082 uint32_t size = qdict_get_int(qdict, "size");
1083 const char *filename = qdict_get_str(qdict, "filename");
1084 uint64_t addr = qdict_get_int(qdict, "val");
1085 Error *err = NULL;
1086 int cpu_index = monitor_get_cpu_index();
1088 if (cpu_index < 0) {
1089 monitor_printf(mon, "No CPU available\n");
1090 return;
1093 qmp_memsave(addr, size, filename, true, cpu_index, &err);
1094 hmp_handle_error(mon, &err);
1097 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1099 uint32_t size = qdict_get_int(qdict, "size");
1100 const char *filename = qdict_get_str(qdict, "filename");
1101 uint64_t addr = qdict_get_int(qdict, "val");
1102 Error *err = NULL;
1104 qmp_pmemsave(addr, size, filename, &err);
1105 hmp_handle_error(mon, &err);
1108 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1110 const char *chardev = qdict_get_str(qdict, "device");
1111 const char *data = qdict_get_str(qdict, "data");
1112 Error *err = NULL;
1114 qmp_ringbuf_write(chardev, data, false, 0, &err);
1116 hmp_handle_error(mon, &err);
1119 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
1121 uint32_t size = qdict_get_int(qdict, "size");
1122 const char *chardev = qdict_get_str(qdict, "device");
1123 char *data;
1124 Error *err = NULL;
1125 int i;
1127 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1128 if (err) {
1129 hmp_handle_error(mon, &err);
1130 return;
1133 for (i = 0; data[i]; i++) {
1134 unsigned char ch = data[i];
1136 if (ch == '\\') {
1137 monitor_printf(mon, "\\\\");
1138 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1139 monitor_printf(mon, "\\u%04X", ch);
1140 } else {
1141 monitor_printf(mon, "%c", ch);
1145 monitor_printf(mon, "\n");
1146 g_free(data);
1149 void hmp_cont(Monitor *mon, const QDict *qdict)
1151 Error *err = NULL;
1153 qmp_cont(&err);
1154 hmp_handle_error(mon, &err);
1157 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1159 qmp_system_wakeup(NULL);
1162 void hmp_nmi(Monitor *mon, const QDict *qdict)
1164 Error *err = NULL;
1166 qmp_inject_nmi(&err);
1167 hmp_handle_error(mon, &err);
1170 void hmp_set_link(Monitor *mon, const QDict *qdict)
1172 const char *name = qdict_get_str(qdict, "name");
1173 bool up = qdict_get_bool(qdict, "up");
1174 Error *err = NULL;
1176 qmp_set_link(name, up, &err);
1177 hmp_handle_error(mon, &err);
1180 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1182 const char *device = qdict_get_str(qdict, "device");
1183 const char *password = qdict_get_str(qdict, "password");
1184 Error *err = NULL;
1186 qmp_block_passwd(true, device, false, NULL, password, &err);
1187 hmp_handle_error(mon, &err);
1190 void hmp_balloon(Monitor *mon, const QDict *qdict)
1192 int64_t value = qdict_get_int(qdict, "value");
1193 Error *err = NULL;
1195 qmp_balloon(value, &err);
1196 hmp_handle_error(mon, &err);
1199 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1201 const char *device = qdict_get_str(qdict, "device");
1202 int64_t size = qdict_get_int(qdict, "size");
1203 Error *err = NULL;
1205 qmp_block_resize(true, device, false, NULL, size, &err);
1206 hmp_handle_error(mon, &err);
1209 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1211 const char *filename = qdict_get_str(qdict, "target");
1212 const char *format = qdict_get_try_str(qdict, "format");
1213 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1214 bool full = qdict_get_try_bool(qdict, "full", false);
1215 Error *err = NULL;
1216 DriveMirror mirror = {
1217 .device = (char *)qdict_get_str(qdict, "device"),
1218 .target = (char *)filename,
1219 .has_format = !!format,
1220 .format = (char *)format,
1221 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1222 .has_mode = true,
1223 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1224 .unmap = true,
1227 if (!filename) {
1228 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1229 hmp_handle_error(mon, &err);
1230 return;
1232 qmp_drive_mirror(&mirror, &err);
1233 hmp_handle_error(mon, &err);
1236 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1238 const char *device = qdict_get_str(qdict, "device");
1239 const char *filename = qdict_get_str(qdict, "target");
1240 const char *format = qdict_get_try_str(qdict, "format");
1241 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1242 bool full = qdict_get_try_bool(qdict, "full", false);
1243 bool compress = qdict_get_try_bool(qdict, "compress", false);
1244 Error *err = NULL;
1245 DriveBackup backup = {
1246 .device = (char *)device,
1247 .target = (char *)filename,
1248 .has_format = !!format,
1249 .format = (char *)format,
1250 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1251 .has_mode = true,
1252 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1253 .has_compress = !!compress,
1254 .compress = compress,
1257 if (!filename) {
1258 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1259 hmp_handle_error(mon, &err);
1260 return;
1263 qmp_drive_backup(&backup, &err);
1264 hmp_handle_error(mon, &err);
1267 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1269 const char *device = qdict_get_str(qdict, "device");
1270 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1271 const char *format = qdict_get_try_str(qdict, "format");
1272 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1273 enum NewImageMode mode;
1274 Error *err = NULL;
1276 if (!filename) {
1277 /* In the future, if 'snapshot-file' is not specified, the snapshot
1278 will be taken internally. Today it's actually required. */
1279 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1280 hmp_handle_error(mon, &err);
1281 return;
1284 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1285 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1286 filename, false, NULL,
1287 !!format, format,
1288 true, mode, &err);
1289 hmp_handle_error(mon, &err);
1292 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1294 const char *device = qdict_get_str(qdict, "device");
1295 const char *name = qdict_get_str(qdict, "name");
1296 Error *err = NULL;
1298 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1299 hmp_handle_error(mon, &err);
1302 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1304 const char *device = qdict_get_str(qdict, "device");
1305 const char *name = qdict_get_str(qdict, "name");
1306 const char *id = qdict_get_try_str(qdict, "id");
1307 Error *err = NULL;
1309 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1310 true, name, &err);
1311 hmp_handle_error(mon, &err);
1314 void hmp_loadvm(Monitor *mon, const QDict *qdict)
1316 int saved_vm_running = runstate_is_running();
1317 const char *name = qdict_get_str(qdict, "name");
1318 Error *err = NULL;
1320 vm_stop(RUN_STATE_RESTORE_VM);
1322 if (load_snapshot(name, &err) == 0 && saved_vm_running) {
1323 vm_start();
1325 hmp_handle_error(mon, &err);
1328 void hmp_savevm(Monitor *mon, const QDict *qdict)
1330 Error *err = NULL;
1332 save_snapshot(qdict_get_try_str(qdict, "name"), &err);
1333 hmp_handle_error(mon, &err);
1336 void hmp_delvm(Monitor *mon, const QDict *qdict)
1338 BlockDriverState *bs;
1339 Error *err = NULL;
1340 const char *name = qdict_get_str(qdict, "name");
1342 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
1343 error_reportf_err(err,
1344 "Error while deleting snapshot on device '%s': ",
1345 bdrv_get_device_name(bs));
1349 void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
1351 BlockDriverState *bs, *bs1;
1352 BdrvNextIterator it1;
1353 QEMUSnapshotInfo *sn_tab, *sn;
1354 bool no_snapshot = true;
1355 int nb_sns, i;
1356 int total;
1357 int *global_snapshots;
1358 AioContext *aio_context;
1360 typedef struct SnapshotEntry {
1361 QEMUSnapshotInfo sn;
1362 QTAILQ_ENTRY(SnapshotEntry) next;
1363 } SnapshotEntry;
1365 typedef struct ImageEntry {
1366 const char *imagename;
1367 QTAILQ_ENTRY(ImageEntry) next;
1368 QTAILQ_HEAD(, SnapshotEntry) snapshots;
1369 } ImageEntry;
1371 QTAILQ_HEAD(, ImageEntry) image_list =
1372 QTAILQ_HEAD_INITIALIZER(image_list);
1374 ImageEntry *image_entry, *next_ie;
1375 SnapshotEntry *snapshot_entry;
1377 bs = bdrv_all_find_vmstate_bs();
1378 if (!bs) {
1379 monitor_printf(mon, "No available block device supports snapshots\n");
1380 return;
1382 aio_context = bdrv_get_aio_context(bs);
1384 aio_context_acquire(aio_context);
1385 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
1386 aio_context_release(aio_context);
1388 if (nb_sns < 0) {
1389 monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
1390 return;
1393 for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) {
1394 int bs1_nb_sns = 0;
1395 ImageEntry *ie;
1396 SnapshotEntry *se;
1397 AioContext *ctx = bdrv_get_aio_context(bs1);
1399 aio_context_acquire(ctx);
1400 if (bdrv_can_snapshot(bs1)) {
1401 sn = NULL;
1402 bs1_nb_sns = bdrv_snapshot_list(bs1, &sn);
1403 if (bs1_nb_sns > 0) {
1404 no_snapshot = false;
1405 ie = g_new0(ImageEntry, 1);
1406 ie->imagename = bdrv_get_device_name(bs1);
1407 QTAILQ_INIT(&ie->snapshots);
1408 QTAILQ_INSERT_TAIL(&image_list, ie, next);
1409 for (i = 0; i < bs1_nb_sns; i++) {
1410 se = g_new0(SnapshotEntry, 1);
1411 se->sn = sn[i];
1412 QTAILQ_INSERT_TAIL(&ie->snapshots, se, next);
1415 g_free(sn);
1417 aio_context_release(ctx);
1420 if (no_snapshot) {
1421 monitor_printf(mon, "There is no snapshot available.\n");
1422 return;
1425 global_snapshots = g_new0(int, nb_sns);
1426 total = 0;
1427 for (i = 0; i < nb_sns; i++) {
1428 SnapshotEntry *next_sn;
1429 if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) {
1430 global_snapshots[total] = i;
1431 total++;
1432 QTAILQ_FOREACH(image_entry, &image_list, next) {
1433 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots,
1434 next, next_sn) {
1435 if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) {
1436 QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry,
1437 next);
1438 g_free(snapshot_entry);
1445 monitor_printf(mon, "List of snapshots present on all disks:\n");
1447 if (total > 0) {
1448 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1449 monitor_printf(mon, "\n");
1450 for (i = 0; i < total; i++) {
1451 sn = &sn_tab[global_snapshots[i]];
1452 /* The ID is not guaranteed to be the same on all images, so
1453 * overwrite it.
1455 pstrcpy(sn->id_str, sizeof(sn->id_str), "--");
1456 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, sn);
1457 monitor_printf(mon, "\n");
1459 } else {
1460 monitor_printf(mon, "None\n");
1463 QTAILQ_FOREACH(image_entry, &image_list, next) {
1464 if (QTAILQ_EMPTY(&image_entry->snapshots)) {
1465 continue;
1467 monitor_printf(mon,
1468 "\nList of partial (non-loadable) snapshots on '%s':\n",
1469 image_entry->imagename);
1470 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1471 monitor_printf(mon, "\n");
1472 QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) {
1473 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon,
1474 &snapshot_entry->sn);
1475 monitor_printf(mon, "\n");
1479 QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) {
1480 SnapshotEntry *next_sn;
1481 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next,
1482 next_sn) {
1483 g_free(snapshot_entry);
1485 g_free(image_entry);
1487 g_free(sn_tab);
1488 g_free(global_snapshots);
1492 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1494 qmp_migrate_cancel(NULL);
1497 void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1499 Error *err = NULL;
1500 const char *state = qdict_get_str(qdict, "state");
1501 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1503 if (val >= 0) {
1504 qmp_migrate_continue(val, &err);
1507 hmp_handle_error(mon, &err);
1510 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1512 Error *err = NULL;
1513 const char *uri = qdict_get_str(qdict, "uri");
1515 qmp_migrate_incoming(uri, &err);
1517 hmp_handle_error(mon, &err);
1520 void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
1522 Error *err = NULL;
1523 const char *uri = qdict_get_str(qdict, "uri");
1525 qmp_migrate_recover(uri, &err);
1527 hmp_handle_error(mon, &err);
1530 /* Kept for backwards compatibility */
1531 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1533 double value = qdict_get_double(qdict, "value");
1534 qmp_migrate_set_downtime(value, NULL);
1537 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1539 int64_t value = qdict_get_int(qdict, "value");
1540 Error *err = NULL;
1542 qmp_migrate_set_cache_size(value, &err);
1543 hmp_handle_error(mon, &err);
1546 /* Kept for backwards compatibility */
1547 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1549 int64_t value = qdict_get_int(qdict, "value");
1550 qmp_migrate_set_speed(value, NULL);
1553 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1555 const char *cap = qdict_get_str(qdict, "capability");
1556 bool state = qdict_get_bool(qdict, "state");
1557 Error *err = NULL;
1558 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1559 int val;
1561 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
1562 if (val < 0) {
1563 goto end;
1566 caps->value = g_malloc0(sizeof(*caps->value));
1567 caps->value->capability = val;
1568 caps->value->state = state;
1569 caps->next = NULL;
1570 qmp_migrate_set_capabilities(caps, &err);
1572 end:
1573 qapi_free_MigrationCapabilityStatusList(caps);
1574 hmp_handle_error(mon, &err);
1577 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1579 const char *param = qdict_get_str(qdict, "parameter");
1580 const char *valuestr = qdict_get_str(qdict, "value");
1581 Visitor *v = string_input_visitor_new(valuestr);
1582 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
1583 uint64_t valuebw = 0;
1584 uint64_t cache_size;
1585 Error *err = NULL;
1586 int val, ret;
1588 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
1589 if (val < 0) {
1590 goto cleanup;
1593 switch (val) {
1594 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1595 p->has_compress_level = true;
1596 visit_type_int(v, param, &p->compress_level, &err);
1597 break;
1598 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1599 p->has_compress_threads = true;
1600 visit_type_int(v, param, &p->compress_threads, &err);
1601 break;
1602 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1603 p->has_decompress_threads = true;
1604 visit_type_int(v, param, &p->decompress_threads, &err);
1605 break;
1606 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1607 p->has_cpu_throttle_initial = true;
1608 visit_type_int(v, param, &p->cpu_throttle_initial, &err);
1609 break;
1610 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1611 p->has_cpu_throttle_increment = true;
1612 visit_type_int(v, param, &p->cpu_throttle_increment, &err);
1613 break;
1614 case MIGRATION_PARAMETER_TLS_CREDS:
1615 p->has_tls_creds = true;
1616 p->tls_creds = g_new0(StrOrNull, 1);
1617 p->tls_creds->type = QTYPE_QSTRING;
1618 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1619 break;
1620 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1621 p->has_tls_hostname = true;
1622 p->tls_hostname = g_new0(StrOrNull, 1);
1623 p->tls_hostname->type = QTYPE_QSTRING;
1624 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1625 break;
1626 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1627 p->has_max_bandwidth = true;
1629 * Can't use visit_type_size() here, because it
1630 * defaults to Bytes rather than Mebibytes.
1632 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1633 if (ret < 0 || valuebw > INT64_MAX
1634 || (size_t)valuebw != valuebw) {
1635 error_setg(&err, "Invalid size %s", valuestr);
1636 break;
1638 p->max_bandwidth = valuebw;
1639 break;
1640 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1641 p->has_downtime_limit = true;
1642 visit_type_int(v, param, &p->downtime_limit, &err);
1643 break;
1644 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1645 p->has_x_checkpoint_delay = true;
1646 visit_type_int(v, param, &p->x_checkpoint_delay, &err);
1647 break;
1648 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1649 p->has_block_incremental = true;
1650 visit_type_bool(v, param, &p->block_incremental, &err);
1651 break;
1652 case MIGRATION_PARAMETER_X_MULTIFD_CHANNELS:
1653 p->has_x_multifd_channels = true;
1654 visit_type_int(v, param, &p->x_multifd_channels, &err);
1655 break;
1656 case MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT:
1657 p->has_x_multifd_page_count = true;
1658 visit_type_int(v, param, &p->x_multifd_page_count, &err);
1659 break;
1660 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1661 p->has_xbzrle_cache_size = true;
1662 visit_type_size(v, param, &cache_size, &err);
1663 if (err || cache_size > INT64_MAX
1664 || (size_t)cache_size != cache_size) {
1665 error_setg(&err, "Invalid size %s", valuestr);
1666 break;
1668 p->xbzrle_cache_size = cache_size;
1669 break;
1670 default:
1671 assert(0);
1674 if (err) {
1675 goto cleanup;
1678 qmp_migrate_set_parameters(p, &err);
1680 cleanup:
1681 qapi_free_MigrateSetParameters(p);
1682 visit_free(v);
1683 hmp_handle_error(mon, &err);
1686 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1688 Error *err = NULL;
1689 const char *protocol = qdict_get_str(qdict, "protocol");
1690 const char *hostname = qdict_get_str(qdict, "hostname");
1691 bool has_port = qdict_haskey(qdict, "port");
1692 int port = qdict_get_try_int(qdict, "port", -1);
1693 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1694 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1695 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1697 qmp_client_migrate_info(protocol, hostname,
1698 has_port, port, has_tls_port, tls_port,
1699 !!cert_subject, cert_subject, &err);
1700 hmp_handle_error(mon, &err);
1703 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1705 Error *err = NULL;
1706 qmp_migrate_start_postcopy(&err);
1707 hmp_handle_error(mon, &err);
1710 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1712 Error *err = NULL;
1714 qmp_x_colo_lost_heartbeat(&err);
1715 hmp_handle_error(mon, &err);
1718 void hmp_set_password(Monitor *mon, const QDict *qdict)
1720 const char *protocol = qdict_get_str(qdict, "protocol");
1721 const char *password = qdict_get_str(qdict, "password");
1722 const char *connected = qdict_get_try_str(qdict, "connected");
1723 Error *err = NULL;
1725 qmp_set_password(protocol, password, !!connected, connected, &err);
1726 hmp_handle_error(mon, &err);
1729 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1731 const char *protocol = qdict_get_str(qdict, "protocol");
1732 const char *whenstr = qdict_get_str(qdict, "time");
1733 Error *err = NULL;
1735 qmp_expire_password(protocol, whenstr, &err);
1736 hmp_handle_error(mon, &err);
1739 void hmp_eject(Monitor *mon, const QDict *qdict)
1741 bool force = qdict_get_try_bool(qdict, "force", false);
1742 const char *device = qdict_get_str(qdict, "device");
1743 Error *err = NULL;
1745 qmp_eject(true, device, false, NULL, true, force, &err);
1746 hmp_handle_error(mon, &err);
1749 static void hmp_change_read_arg(void *opaque, const char *password,
1750 void *readline_opaque)
1752 qmp_change_vnc_password(password, NULL);
1753 monitor_read_command(opaque, 1);
1756 void hmp_change(Monitor *mon, const QDict *qdict)
1758 const char *device = qdict_get_str(qdict, "device");
1759 const char *target = qdict_get_str(qdict, "target");
1760 const char *arg = qdict_get_try_str(qdict, "arg");
1761 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1762 BlockdevChangeReadOnlyMode read_only_mode = 0;
1763 Error *err = NULL;
1765 if (strcmp(device, "vnc") == 0) {
1766 if (read_only) {
1767 monitor_printf(mon,
1768 "Parameter 'read-only-mode' is invalid for VNC\n");
1769 return;
1771 if (strcmp(target, "passwd") == 0 ||
1772 strcmp(target, "password") == 0) {
1773 if (!arg) {
1774 monitor_read_password(mon, hmp_change_read_arg, NULL);
1775 return;
1778 qmp_change("vnc", target, !!arg, arg, &err);
1779 } else {
1780 if (read_only) {
1781 read_only_mode =
1782 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
1783 read_only,
1784 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1785 if (err) {
1786 hmp_handle_error(mon, &err);
1787 return;
1791 qmp_blockdev_change_medium(true, device, false, NULL, target,
1792 !!arg, arg, !!read_only, read_only_mode,
1793 &err);
1796 hmp_handle_error(mon, &err);
1799 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1801 Error *err = NULL;
1802 char *device = (char *) qdict_get_str(qdict, "device");
1803 BlockIOThrottle throttle = {
1804 .bps = qdict_get_int(qdict, "bps"),
1805 .bps_rd = qdict_get_int(qdict, "bps_rd"),
1806 .bps_wr = qdict_get_int(qdict, "bps_wr"),
1807 .iops = qdict_get_int(qdict, "iops"),
1808 .iops_rd = qdict_get_int(qdict, "iops_rd"),
1809 .iops_wr = qdict_get_int(qdict, "iops_wr"),
1812 /* qmp_block_set_io_throttle has separate parameters for the
1813 * (deprecated) block device name and the qdev ID but the HMP
1814 * version has only one, so we must decide which one to pass. */
1815 if (blk_by_name(device)) {
1816 throttle.has_device = true;
1817 throttle.device = device;
1818 } else {
1819 throttle.has_id = true;
1820 throttle.id = device;
1823 qmp_block_set_io_throttle(&throttle, &err);
1824 hmp_handle_error(mon, &err);
1827 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1829 Error *error = NULL;
1830 const char *device = qdict_get_str(qdict, "device");
1831 const char *base = qdict_get_try_str(qdict, "base");
1832 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1834 qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
1835 false, NULL, qdict_haskey(qdict, "speed"), speed,
1836 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1838 hmp_handle_error(mon, &error);
1841 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1843 Error *error = NULL;
1844 const char *device = qdict_get_str(qdict, "device");
1845 int64_t value = qdict_get_int(qdict, "speed");
1847 qmp_block_job_set_speed(device, value, &error);
1849 hmp_handle_error(mon, &error);
1852 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1854 Error *error = NULL;
1855 const char *device = qdict_get_str(qdict, "device");
1856 bool force = qdict_get_try_bool(qdict, "force", false);
1858 qmp_block_job_cancel(device, true, force, &error);
1860 hmp_handle_error(mon, &error);
1863 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1865 Error *error = NULL;
1866 const char *device = qdict_get_str(qdict, "device");
1868 qmp_block_job_pause(device, &error);
1870 hmp_handle_error(mon, &error);
1873 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1875 Error *error = NULL;
1876 const char *device = qdict_get_str(qdict, "device");
1878 qmp_block_job_resume(device, &error);
1880 hmp_handle_error(mon, &error);
1883 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1885 Error *error = NULL;
1886 const char *device = qdict_get_str(qdict, "device");
1888 qmp_block_job_complete(device, &error);
1890 hmp_handle_error(mon, &error);
1893 typedef struct HMPMigrationStatus
1895 QEMUTimer *timer;
1896 Monitor *mon;
1897 bool is_block_migration;
1898 } HMPMigrationStatus;
1900 static void hmp_migrate_status_cb(void *opaque)
1902 HMPMigrationStatus *status = opaque;
1903 MigrationInfo *info;
1905 info = qmp_query_migrate(NULL);
1906 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1907 info->status == MIGRATION_STATUS_SETUP) {
1908 if (info->has_disk) {
1909 int progress;
1911 if (info->disk->remaining) {
1912 progress = info->disk->transferred * 100 / info->disk->total;
1913 } else {
1914 progress = 100;
1917 monitor_printf(status->mon, "Completed %d %%\r", progress);
1918 monitor_flush(status->mon);
1921 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1922 } else {
1923 if (status->is_block_migration) {
1924 monitor_printf(status->mon, "\n");
1926 if (info->has_error_desc) {
1927 error_report("%s", info->error_desc);
1929 monitor_resume(status->mon);
1930 timer_del(status->timer);
1931 g_free(status);
1934 qapi_free_MigrationInfo(info);
1937 void hmp_migrate(Monitor *mon, const QDict *qdict)
1939 bool detach = qdict_get_try_bool(qdict, "detach", false);
1940 bool blk = qdict_get_try_bool(qdict, "blk", false);
1941 bool inc = qdict_get_try_bool(qdict, "inc", false);
1942 bool resume = qdict_get_try_bool(qdict, "resume", false);
1943 const char *uri = qdict_get_str(qdict, "uri");
1944 Error *err = NULL;
1946 qmp_migrate(uri, !!blk, blk, !!inc, inc,
1947 false, false, true, resume, &err);
1948 if (err) {
1949 hmp_handle_error(mon, &err);
1950 return;
1953 if (!detach) {
1954 HMPMigrationStatus *status;
1956 if (monitor_suspend(mon) < 0) {
1957 monitor_printf(mon, "terminal does not allow synchronous "
1958 "migration, continuing detached\n");
1959 return;
1962 status = g_malloc0(sizeof(*status));
1963 status->mon = mon;
1964 status->is_block_migration = blk || inc;
1965 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1966 status);
1967 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1971 void hmp_device_add(Monitor *mon, const QDict *qdict)
1973 Error *err = NULL;
1975 qmp_device_add((QDict *)qdict, NULL, &err);
1976 hmp_handle_error(mon, &err);
1979 void hmp_device_del(Monitor *mon, const QDict *qdict)
1981 const char *id = qdict_get_str(qdict, "id");
1982 Error *err = NULL;
1984 qmp_device_del(id, &err);
1985 hmp_handle_error(mon, &err);
1988 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1990 Error *err = NULL;
1991 bool paging = qdict_get_try_bool(qdict, "paging", false);
1992 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
1993 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
1994 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
1995 const char *file = qdict_get_str(qdict, "filename");
1996 bool has_begin = qdict_haskey(qdict, "begin");
1997 bool has_length = qdict_haskey(qdict, "length");
1998 bool has_detach = qdict_haskey(qdict, "detach");
1999 int64_t begin = 0;
2000 int64_t length = 0;
2001 bool detach = false;
2002 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
2003 char *prot;
2005 if (zlib + lzo + snappy > 1) {
2006 error_setg(&err, "only one of '-z|-l|-s' can be set");
2007 hmp_handle_error(mon, &err);
2008 return;
2011 if (zlib) {
2012 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
2015 if (lzo) {
2016 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
2019 if (snappy) {
2020 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
2023 if (has_begin) {
2024 begin = qdict_get_int(qdict, "begin");
2026 if (has_length) {
2027 length = qdict_get_int(qdict, "length");
2029 if (has_detach) {
2030 detach = qdict_get_bool(qdict, "detach");
2033 prot = g_strconcat("file:", file, NULL);
2035 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
2036 has_length, length, true, dump_format, &err);
2037 hmp_handle_error(mon, &err);
2038 g_free(prot);
2041 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
2043 Error *err = NULL;
2044 QemuOpts *opts;
2046 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
2047 if (err) {
2048 goto out;
2051 netdev_add(opts, &err);
2052 if (err) {
2053 qemu_opts_del(opts);
2056 out:
2057 hmp_handle_error(mon, &err);
2060 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
2062 const char *id = qdict_get_str(qdict, "id");
2063 Error *err = NULL;
2065 qmp_netdev_del(id, &err);
2066 hmp_handle_error(mon, &err);
2069 void hmp_object_add(Monitor *mon, const QDict *qdict)
2071 Error *err = NULL;
2072 QemuOpts *opts;
2073 Object *obj = NULL;
2075 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
2076 if (err) {
2077 hmp_handle_error(mon, &err);
2078 return;
2081 obj = user_creatable_add_opts(opts, &err);
2082 qemu_opts_del(opts);
2084 if (err) {
2085 hmp_handle_error(mon, &err);
2087 if (obj) {
2088 object_unref(obj);
2092 void hmp_getfd(Monitor *mon, const QDict *qdict)
2094 const char *fdname = qdict_get_str(qdict, "fdname");
2095 Error *err = NULL;
2097 qmp_getfd(fdname, &err);
2098 hmp_handle_error(mon, &err);
2101 void hmp_closefd(Monitor *mon, const QDict *qdict)
2103 const char *fdname = qdict_get_str(qdict, "fdname");
2104 Error *err = NULL;
2106 qmp_closefd(fdname, &err);
2107 hmp_handle_error(mon, &err);
2110 void hmp_sendkey(Monitor *mon, const QDict *qdict)
2112 const char *keys = qdict_get_str(qdict, "keys");
2113 KeyValueList *keylist, *head = NULL, *tmp = NULL;
2114 int has_hold_time = qdict_haskey(qdict, "hold-time");
2115 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
2116 Error *err = NULL;
2117 char *separator;
2118 int keyname_len;
2120 while (1) {
2121 separator = strchr(keys, '-');
2122 keyname_len = separator ? separator - keys : strlen(keys);
2124 /* Be compatible with old interface, convert user inputted "<" */
2125 if (keys[0] == '<' && keyname_len == 1) {
2126 keys = "less";
2127 keyname_len = 4;
2130 keylist = g_malloc0(sizeof(*keylist));
2131 keylist->value = g_malloc0(sizeof(*keylist->value));
2133 if (!head) {
2134 head = keylist;
2136 if (tmp) {
2137 tmp->next = keylist;
2139 tmp = keylist;
2141 if (strstart(keys, "0x", NULL)) {
2142 char *endp;
2143 int value = strtoul(keys, &endp, 0);
2144 assert(endp <= keys + keyname_len);
2145 if (endp != keys + keyname_len) {
2146 goto err_out;
2148 keylist->value->type = KEY_VALUE_KIND_NUMBER;
2149 keylist->value->u.number.data = value;
2150 } else {
2151 int idx = index_from_key(keys, keyname_len);
2152 if (idx == Q_KEY_CODE__MAX) {
2153 goto err_out;
2155 keylist->value->type = KEY_VALUE_KIND_QCODE;
2156 keylist->value->u.qcode.data = idx;
2159 if (!separator) {
2160 break;
2162 keys = separator + 1;
2165 qmp_send_key(head, has_hold_time, hold_time, &err);
2166 hmp_handle_error(mon, &err);
2168 out:
2169 qapi_free_KeyValueList(head);
2170 return;
2172 err_out:
2173 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
2174 goto out;
2177 void hmp_screendump(Monitor *mon, const QDict *qdict)
2179 const char *filename = qdict_get_str(qdict, "filename");
2180 const char *id = qdict_get_try_str(qdict, "device");
2181 int64_t head = qdict_get_try_int(qdict, "head", 0);
2182 Error *err = NULL;
2184 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
2185 hmp_handle_error(mon, &err);
2188 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
2190 const char *uri = qdict_get_str(qdict, "uri");
2191 bool writable = qdict_get_try_bool(qdict, "writable", false);
2192 bool all = qdict_get_try_bool(qdict, "all", false);
2193 Error *local_err = NULL;
2194 BlockInfoList *block_list, *info;
2195 SocketAddress *addr;
2197 if (writable && !all) {
2198 error_setg(&local_err, "-w only valid together with -a");
2199 goto exit;
2202 /* First check if the address is valid and start the server. */
2203 addr = socket_parse(uri, &local_err);
2204 if (local_err != NULL) {
2205 goto exit;
2208 nbd_server_start(addr, NULL, &local_err);
2209 qapi_free_SocketAddress(addr);
2210 if (local_err != NULL) {
2211 goto exit;
2214 if (!all) {
2215 return;
2218 /* Then try adding all block devices. If one fails, close all and
2219 * exit.
2221 block_list = qmp_query_block(NULL);
2223 for (info = block_list; info; info = info->next) {
2224 if (!info->value->has_inserted) {
2225 continue;
2228 qmp_nbd_server_add(info->value->device, false, NULL,
2229 true, writable, &local_err);
2231 if (local_err != NULL) {
2232 qmp_nbd_server_stop(NULL);
2233 break;
2237 qapi_free_BlockInfoList(block_list);
2239 exit:
2240 hmp_handle_error(mon, &local_err);
2243 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
2245 const char *device = qdict_get_str(qdict, "device");
2246 const char *name = qdict_get_try_str(qdict, "name");
2247 bool writable = qdict_get_try_bool(qdict, "writable", false);
2248 Error *local_err = NULL;
2250 qmp_nbd_server_add(device, !!name, name, true, writable, &local_err);
2251 hmp_handle_error(mon, &local_err);
2254 void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict)
2256 const char *name = qdict_get_str(qdict, "name");
2257 bool force = qdict_get_try_bool(qdict, "force", false);
2258 Error *err = NULL;
2260 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
2261 qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err);
2262 hmp_handle_error(mon, &err);
2265 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
2267 Error *err = NULL;
2269 qmp_nbd_server_stop(&err);
2270 hmp_handle_error(mon, &err);
2273 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
2275 int cpuid;
2276 Error *err = NULL;
2278 cpuid = qdict_get_int(qdict, "id");
2279 qmp_cpu_add(cpuid, &err);
2280 hmp_handle_error(mon, &err);
2283 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2285 const char *args = qdict_get_str(qdict, "args");
2286 Error *err = NULL;
2287 QemuOpts *opts;
2289 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
2290 if (opts == NULL) {
2291 error_setg(&err, "Parsing chardev args failed");
2292 } else {
2293 qemu_chr_new_from_opts(opts, &err);
2294 qemu_opts_del(opts);
2296 hmp_handle_error(mon, &err);
2299 void hmp_chardev_change(Monitor *mon, const QDict *qdict)
2301 const char *args = qdict_get_str(qdict, "args");
2302 const char *id;
2303 Error *err = NULL;
2304 ChardevBackend *backend = NULL;
2305 ChardevReturn *ret = NULL;
2306 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
2307 true);
2308 if (!opts) {
2309 error_setg(&err, "Parsing chardev args failed");
2310 goto end;
2313 id = qdict_get_str(qdict, "id");
2314 if (qemu_opts_id(opts)) {
2315 error_setg(&err, "Unexpected 'id' parameter");
2316 goto end;
2319 backend = qemu_chr_parse_opts(opts, &err);
2320 if (!backend) {
2321 goto end;
2324 ret = qmp_chardev_change(id, backend, &err);
2326 end:
2327 qapi_free_ChardevReturn(ret);
2328 qapi_free_ChardevBackend(backend);
2329 qemu_opts_del(opts);
2330 hmp_handle_error(mon, &err);
2333 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2335 Error *local_err = NULL;
2337 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
2338 hmp_handle_error(mon, &local_err);
2341 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
2343 Error *local_err = NULL;
2345 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
2346 hmp_handle_error(mon, &local_err);
2349 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
2351 BlockBackend *blk;
2352 BlockBackend *local_blk = NULL;
2353 const char* device = qdict_get_str(qdict, "device");
2354 const char* command = qdict_get_str(qdict, "command");
2355 Error *err = NULL;
2356 int ret;
2358 blk = blk_by_name(device);
2359 if (!blk) {
2360 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
2361 if (bs) {
2362 blk = local_blk = blk_new(0, BLK_PERM_ALL);
2363 ret = blk_insert_bs(blk, bs, &err);
2364 if (ret < 0) {
2365 goto fail;
2367 } else {
2368 goto fail;
2373 * Notably absent: Proper permission management. This is sad, but it seems
2374 * almost impossible to achieve without changing the semantics and thereby
2375 * limiting the use cases of the qemu-io HMP command.
2377 * In an ideal world we would unconditionally create a new BlockBackend for
2378 * qemuio_command(), but we have commands like 'reopen' and want them to
2379 * take effect on the exact BlockBackend whose name the user passed instead
2380 * of just on a temporary copy of it.
2382 * Another problem is that deleting the temporary BlockBackend involves
2383 * draining all requests on it first, but some qemu-iotests cases want to
2384 * issue multiple aio_read/write requests and expect them to complete in
2385 * the background while the monitor has already returned.
2387 * This is also what prevents us from saving the original permissions and
2388 * restoring them later: We can't revoke permissions until all requests
2389 * have completed, and we don't know when that is nor can we really let
2390 * anything else run before we have revoken them to avoid race conditions.
2392 * What happens now is that command() in qemu-io-cmds.c can extend the
2393 * permissions if necessary for the qemu-io command. And they simply stay
2394 * extended, possibly resulting in a read-only guest device keeping write
2395 * permissions. Ugly, but it appears to be the lesser evil.
2397 qemuio_command(blk, command);
2399 fail:
2400 blk_unref(local_blk);
2401 hmp_handle_error(mon, &err);
2404 void hmp_object_del(Monitor *mon, const QDict *qdict)
2406 const char *id = qdict_get_str(qdict, "id");
2407 Error *err = NULL;
2409 user_creatable_del(id, &err);
2410 hmp_handle_error(mon, &err);
2413 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
2415 Error *err = NULL;
2416 MemdevList *memdev_list = qmp_query_memdev(&err);
2417 MemdevList *m = memdev_list;
2418 Visitor *v;
2419 char *str;
2421 while (m) {
2422 v = string_output_visitor_new(false, &str);
2423 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
2424 monitor_printf(mon, "memory backend: %s\n", m->value->id);
2425 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
2426 monitor_printf(mon, " merge: %s\n",
2427 m->value->merge ? "true" : "false");
2428 monitor_printf(mon, " dump: %s\n",
2429 m->value->dump ? "true" : "false");
2430 monitor_printf(mon, " prealloc: %s\n",
2431 m->value->prealloc ? "true" : "false");
2432 monitor_printf(mon, " policy: %s\n",
2433 HostMemPolicy_str(m->value->policy));
2434 visit_complete(v, &str);
2435 monitor_printf(mon, " host nodes: %s\n", str);
2437 g_free(str);
2438 visit_free(v);
2439 m = m->next;
2442 monitor_printf(mon, "\n");
2444 qapi_free_MemdevList(memdev_list);
2445 hmp_handle_error(mon, &err);
2448 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2450 Error *err = NULL;
2451 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2452 MemoryDeviceInfoList *info;
2453 MemoryDeviceInfo *value;
2454 PCDIMMDeviceInfo *di;
2456 for (info = info_list; info; info = info->next) {
2457 value = info->value;
2459 if (value) {
2460 switch (value->type) {
2461 case MEMORY_DEVICE_INFO_KIND_DIMM:
2462 di = value->u.dimm.data;
2463 break;
2465 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
2466 di = value->u.nvdimm.data;
2467 break;
2469 default:
2470 di = NULL;
2471 break;
2474 if (di) {
2475 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2476 MemoryDeviceInfoKind_str(value->type),
2477 di->id ? di->id : "");
2478 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2479 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2480 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2481 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2482 monitor_printf(mon, " memdev: %s\n", di->memdev);
2483 monitor_printf(mon, " hotplugged: %s\n",
2484 di->hotplugged ? "true" : "false");
2485 monitor_printf(mon, " hotpluggable: %s\n",
2486 di->hotpluggable ? "true" : "false");
2491 qapi_free_MemoryDeviceInfoList(info_list);
2492 hmp_handle_error(mon, &err);
2495 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2497 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2498 IOThreadInfoList *info;
2499 IOThreadInfo *value;
2501 for (info = info_list; info; info = info->next) {
2502 value = info->value;
2503 monitor_printf(mon, "%s:\n", value->id);
2504 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
2505 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2506 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
2507 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
2510 qapi_free_IOThreadInfoList(info_list);
2513 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2515 const char *path = qdict_get_try_str(qdict, "path");
2516 ObjectPropertyInfoList *list;
2517 Error *err = NULL;
2519 if (path == NULL) {
2520 monitor_printf(mon, "/\n");
2521 return;
2524 list = qmp_qom_list(path, &err);
2525 if (err == NULL) {
2526 ObjectPropertyInfoList *start = list;
2527 while (list != NULL) {
2528 ObjectPropertyInfo *value = list->value;
2530 monitor_printf(mon, "%s (%s)\n",
2531 value->name, value->type);
2532 list = list->next;
2534 qapi_free_ObjectPropertyInfoList(start);
2536 hmp_handle_error(mon, &err);
2539 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2541 const char *path = qdict_get_str(qdict, "path");
2542 const char *property = qdict_get_str(qdict, "property");
2543 const char *value = qdict_get_str(qdict, "value");
2544 Error *err = NULL;
2545 bool ambiguous = false;
2546 Object *obj;
2548 obj = object_resolve_path(path, &ambiguous);
2549 if (obj == NULL) {
2550 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2551 "Device '%s' not found", path);
2552 } else {
2553 if (ambiguous) {
2554 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2556 object_property_parse(obj, value, property, &err);
2558 hmp_handle_error(mon, &err);
2561 void hmp_rocker(Monitor *mon, const QDict *qdict)
2563 const char *name = qdict_get_str(qdict, "name");
2564 RockerSwitch *rocker;
2565 Error *err = NULL;
2567 rocker = qmp_query_rocker(name, &err);
2568 if (err != NULL) {
2569 hmp_handle_error(mon, &err);
2570 return;
2573 monitor_printf(mon, "name: %s\n", rocker->name);
2574 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2575 monitor_printf(mon, "ports: %d\n", rocker->ports);
2577 qapi_free_RockerSwitch(rocker);
2580 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2582 RockerPortList *list, *port;
2583 const char *name = qdict_get_str(qdict, "name");
2584 Error *err = NULL;
2586 list = qmp_query_rocker_ports(name, &err);
2587 if (err != NULL) {
2588 hmp_handle_error(mon, &err);
2589 return;
2592 monitor_printf(mon, " ena/ speed/ auto\n");
2593 monitor_printf(mon, " port link duplex neg?\n");
2595 for (port = list; port; port = port->next) {
2596 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2597 port->value->name,
2598 port->value->enabled ? port->value->link_up ?
2599 "up" : "down" : "!ena",
2600 port->value->speed == 10000 ? "10G" : "??",
2601 port->value->duplex ? "FD" : "HD",
2602 port->value->autoneg ? "Yes" : "No");
2605 qapi_free_RockerPortList(list);
2608 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2610 RockerOfDpaFlowList *list, *info;
2611 const char *name = qdict_get_str(qdict, "name");
2612 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2613 Error *err = NULL;
2615 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2616 if (err != NULL) {
2617 hmp_handle_error(mon, &err);
2618 return;
2621 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2623 for (info = list; info; info = info->next) {
2624 RockerOfDpaFlow *flow = info->value;
2625 RockerOfDpaFlowKey *key = flow->key;
2626 RockerOfDpaFlowMask *mask = flow->mask;
2627 RockerOfDpaFlowAction *action = flow->action;
2629 if (flow->hits) {
2630 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2631 key->priority, key->tbl_id, flow->hits);
2632 } else {
2633 monitor_printf(mon, "%-4d %-3d ",
2634 key->priority, key->tbl_id);
2637 if (key->has_in_pport) {
2638 monitor_printf(mon, " pport %d", key->in_pport);
2639 if (mask->has_in_pport) {
2640 monitor_printf(mon, "(0x%x)", mask->in_pport);
2644 if (key->has_vlan_id) {
2645 monitor_printf(mon, " vlan %d",
2646 key->vlan_id & VLAN_VID_MASK);
2647 if (mask->has_vlan_id) {
2648 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2652 if (key->has_tunnel_id) {
2653 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2654 if (mask->has_tunnel_id) {
2655 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2659 if (key->has_eth_type) {
2660 switch (key->eth_type) {
2661 case 0x0806:
2662 monitor_printf(mon, " ARP");
2663 break;
2664 case 0x0800:
2665 monitor_printf(mon, " IP");
2666 break;
2667 case 0x86dd:
2668 monitor_printf(mon, " IPv6");
2669 break;
2670 case 0x8809:
2671 monitor_printf(mon, " LACP");
2672 break;
2673 case 0x88cc:
2674 monitor_printf(mon, " LLDP");
2675 break;
2676 default:
2677 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2678 break;
2682 if (key->has_eth_src) {
2683 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2684 (mask->has_eth_src) &&
2685 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2686 monitor_printf(mon, " src <any mcast/bcast>");
2687 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2688 (mask->has_eth_src) &&
2689 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2690 monitor_printf(mon, " src <any ucast>");
2691 } else {
2692 monitor_printf(mon, " src %s", key->eth_src);
2693 if (mask->has_eth_src) {
2694 monitor_printf(mon, "(%s)", mask->eth_src);
2699 if (key->has_eth_dst) {
2700 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2701 (mask->has_eth_dst) &&
2702 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2703 monitor_printf(mon, " dst <any mcast/bcast>");
2704 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2705 (mask->has_eth_dst) &&
2706 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2707 monitor_printf(mon, " dst <any ucast>");
2708 } else {
2709 monitor_printf(mon, " dst %s", key->eth_dst);
2710 if (mask->has_eth_dst) {
2711 monitor_printf(mon, "(%s)", mask->eth_dst);
2716 if (key->has_ip_proto) {
2717 monitor_printf(mon, " proto %d", key->ip_proto);
2718 if (mask->has_ip_proto) {
2719 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2723 if (key->has_ip_tos) {
2724 monitor_printf(mon, " TOS %d", key->ip_tos);
2725 if (mask->has_ip_tos) {
2726 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2730 if (key->has_ip_dst) {
2731 monitor_printf(mon, " dst %s", key->ip_dst);
2734 if (action->has_goto_tbl || action->has_group_id ||
2735 action->has_new_vlan_id) {
2736 monitor_printf(mon, " -->");
2739 if (action->has_new_vlan_id) {
2740 monitor_printf(mon, " apply new vlan %d",
2741 ntohs(action->new_vlan_id));
2744 if (action->has_group_id) {
2745 monitor_printf(mon, " write group 0x%08x", action->group_id);
2748 if (action->has_goto_tbl) {
2749 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2752 monitor_printf(mon, "\n");
2755 qapi_free_RockerOfDpaFlowList(list);
2758 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2760 RockerOfDpaGroupList *list, *g;
2761 const char *name = qdict_get_str(qdict, "name");
2762 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2763 Error *err = NULL;
2764 bool set = false;
2766 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2767 if (err != NULL) {
2768 hmp_handle_error(mon, &err);
2769 return;
2772 monitor_printf(mon, "id (decode) --> buckets\n");
2774 for (g = list; g; g = g->next) {
2775 RockerOfDpaGroup *group = g->value;
2777 monitor_printf(mon, "0x%08x", group->id);
2779 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2780 group->type == 1 ? "L2 rewrite" :
2781 group->type == 2 ? "L3 unicast" :
2782 group->type == 3 ? "L2 multicast" :
2783 group->type == 4 ? "L2 flood" :
2784 group->type == 5 ? "L3 interface" :
2785 group->type == 6 ? "L3 multicast" :
2786 group->type == 7 ? "L3 ECMP" :
2787 group->type == 8 ? "L2 overlay" :
2788 "unknown");
2790 if (group->has_vlan_id) {
2791 monitor_printf(mon, " vlan %d", group->vlan_id);
2794 if (group->has_pport) {
2795 monitor_printf(mon, " pport %d", group->pport);
2798 if (group->has_index) {
2799 monitor_printf(mon, " index %d", group->index);
2802 monitor_printf(mon, ") -->");
2804 if (group->has_set_vlan_id && group->set_vlan_id) {
2805 set = true;
2806 monitor_printf(mon, " set vlan %d",
2807 group->set_vlan_id & VLAN_VID_MASK);
2810 if (group->has_set_eth_src) {
2811 if (!set) {
2812 set = true;
2813 monitor_printf(mon, " set");
2815 monitor_printf(mon, " src %s", group->set_eth_src);
2818 if (group->has_set_eth_dst) {
2819 if (!set) {
2820 set = true;
2821 monitor_printf(mon, " set");
2823 monitor_printf(mon, " dst %s", group->set_eth_dst);
2826 set = false;
2828 if (group->has_ttl_check && group->ttl_check) {
2829 monitor_printf(mon, " check TTL");
2832 if (group->has_group_id && group->group_id) {
2833 monitor_printf(mon, " group id 0x%08x", group->group_id);
2836 if (group->has_pop_vlan && group->pop_vlan) {
2837 monitor_printf(mon, " pop vlan");
2840 if (group->has_out_pport) {
2841 monitor_printf(mon, " out pport %d", group->out_pport);
2844 if (group->has_group_ids) {
2845 struct uint32List *id;
2847 monitor_printf(mon, " groups [");
2848 for (id = group->group_ids; id; id = id->next) {
2849 monitor_printf(mon, "0x%08x", id->value);
2850 if (id->next) {
2851 monitor_printf(mon, ",");
2854 monitor_printf(mon, "]");
2857 monitor_printf(mon, "\n");
2860 qapi_free_RockerOfDpaGroupList(list);
2863 void hmp_info_dump(Monitor *mon, const QDict *qdict)
2865 DumpQueryResult *result = qmp_query_dump(NULL);
2867 assert(result && result->status < DUMP_STATUS__MAX);
2868 monitor_printf(mon, "Status: %s\n", DumpStatus_str(result->status));
2870 if (result->status == DUMP_STATUS_ACTIVE) {
2871 float percent = 0;
2872 assert(result->total != 0);
2873 percent = 100.0 * result->completed / result->total;
2874 monitor_printf(mon, "Finished: %.2f %%\n", percent);
2877 qapi_free_DumpQueryResult(result);
2880 void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
2882 ram_block_dump(mon);
2885 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
2887 Error *err = NULL;
2888 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
2889 HotpluggableCPUList *saved = l;
2890 CpuInstanceProperties *c;
2892 if (err != NULL) {
2893 hmp_handle_error(mon, &err);
2894 return;
2897 monitor_printf(mon, "Hotpluggable CPUs:\n");
2898 while (l) {
2899 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
2900 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
2901 l->value->vcpus_count);
2902 if (l->value->has_qom_path) {
2903 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
2906 c = l->value->props;
2907 monitor_printf(mon, " CPUInstance Properties:\n");
2908 if (c->has_node_id) {
2909 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
2911 if (c->has_socket_id) {
2912 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
2914 if (c->has_core_id) {
2915 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
2917 if (c->has_thread_id) {
2918 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
2921 l = l->next;
2924 qapi_free_HotpluggableCPUList(saved);
2927 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
2929 Error *err = NULL;
2930 GuidInfo *info = qmp_query_vm_generation_id(&err);
2931 if (info) {
2932 monitor_printf(mon, "%s\n", info->guid);
2934 hmp_handle_error(mon, &err);
2935 qapi_free_GuidInfo(info);
2938 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
2940 Error *err = NULL;
2941 MemoryInfo *info = qmp_query_memory_size_summary(&err);
2942 if (info) {
2943 monitor_printf(mon, "base memory: %" PRIu64 "\n",
2944 info->base_memory);
2946 if (info->has_plugged_memory) {
2947 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
2948 info->plugged_memory);
2951 qapi_free_MemoryInfo(info);
2953 hmp_handle_error(mon, &err);