migration: don't close a file descriptor while it can be in use
[qemu/ar7.git] / hmp.c
blobbe75e7118cf6a2630eb37102f4490caab835ed91
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 "sysemu/char.h"
21 #include "sysemu/block-backend.h"
22 #include "qemu/config-file.h"
23 #include "qemu/option.h"
24 #include "qemu/timer.h"
25 #include "qmp-commands.h"
26 #include "qemu/sockets.h"
27 #include "monitor/monitor.h"
28 #include "monitor/qdev.h"
29 #include "qapi/opts-visitor.h"
30 #include "qapi/qmp/qerror.h"
31 #include "qapi/string-output-visitor.h"
32 #include "qapi/util.h"
33 #include "qapi-visit.h"
34 #include "qom/object_interfaces.h"
35 #include "ui/console.h"
36 #include "block/qapi.h"
37 #include "qemu-io.h"
38 #include "qemu/cutils.h"
39 #include "qemu/error-report.h"
40 #include "hw/intc/intc.h"
42 #ifdef CONFIG_SPICE
43 #include <spice/enums.h>
44 #endif
46 static void hmp_handle_error(Monitor *mon, Error **errp)
48 assert(errp);
49 if (*errp) {
50 error_report_err(*errp);
54 void hmp_info_name(Monitor *mon, const QDict *qdict)
56 NameInfo *info;
58 info = qmp_query_name(NULL);
59 if (info->has_name) {
60 monitor_printf(mon, "%s\n", info->name);
62 qapi_free_NameInfo(info);
65 void hmp_info_version(Monitor *mon, const QDict *qdict)
67 VersionInfo *info;
69 info = qmp_query_version(NULL);
71 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
72 info->qemu->major, info->qemu->minor, info->qemu->micro,
73 info->package);
75 qapi_free_VersionInfo(info);
78 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
80 KvmInfo *info;
82 info = qmp_query_kvm(NULL);
83 monitor_printf(mon, "kvm support: ");
84 if (info->present) {
85 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
86 } else {
87 monitor_printf(mon, "not compiled\n");
90 qapi_free_KvmInfo(info);
93 void hmp_info_status(Monitor *mon, const QDict *qdict)
95 StatusInfo *info;
97 info = qmp_query_status(NULL);
99 monitor_printf(mon, "VM status: %s%s",
100 info->running ? "running" : "paused",
101 info->singlestep ? " (single step mode)" : "");
103 if (!info->running && info->status != RUN_STATE_PAUSED) {
104 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
107 monitor_printf(mon, "\n");
109 qapi_free_StatusInfo(info);
112 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
114 UuidInfo *info;
116 info = qmp_query_uuid(NULL);
117 monitor_printf(mon, "%s\n", info->UUID);
118 qapi_free_UuidInfo(info);
121 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
123 ChardevInfoList *char_info, *info;
125 char_info = qmp_query_chardev(NULL);
126 for (info = char_info; info; info = info->next) {
127 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
128 info->value->filename);
131 qapi_free_ChardevInfoList(char_info);
134 void hmp_info_mice(Monitor *mon, const QDict *qdict)
136 MouseInfoList *mice_list, *mouse;
138 mice_list = qmp_query_mice(NULL);
139 if (!mice_list) {
140 monitor_printf(mon, "No mouse devices connected\n");
141 return;
144 for (mouse = mice_list; mouse; mouse = mouse->next) {
145 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
146 mouse->value->current ? '*' : ' ',
147 mouse->value->index, mouse->value->name,
148 mouse->value->absolute ? " (absolute)" : "");
151 qapi_free_MouseInfoList(mice_list);
154 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
156 MigrationInfo *info;
157 MigrationCapabilityStatusList *caps, *cap;
159 info = qmp_query_migrate(NULL);
160 caps = qmp_query_migrate_capabilities(NULL);
162 /* do not display parameters during setup */
163 if (info->has_status && caps) {
164 monitor_printf(mon, "capabilities: ");
165 for (cap = caps; cap; cap = cap->next) {
166 monitor_printf(mon, "%s: %s ",
167 MigrationCapability_lookup[cap->value->capability],
168 cap->value->state ? "on" : "off");
170 monitor_printf(mon, "\n");
173 if (info->has_status) {
174 monitor_printf(mon, "Migration status: %s",
175 MigrationStatus_lookup[info->status]);
176 if (info->status == MIGRATION_STATUS_FAILED &&
177 info->has_error_desc) {
178 monitor_printf(mon, " (%s)\n", info->error_desc);
179 } else {
180 monitor_printf(mon, "\n");
183 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
184 info->total_time);
185 if (info->has_expected_downtime) {
186 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
187 info->expected_downtime);
189 if (info->has_downtime) {
190 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
191 info->downtime);
193 if (info->has_setup_time) {
194 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
195 info->setup_time);
199 if (info->has_ram) {
200 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
201 info->ram->transferred >> 10);
202 monitor_printf(mon, "throughput: %0.2f mbps\n",
203 info->ram->mbps);
204 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
205 info->ram->remaining >> 10);
206 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
207 info->ram->total >> 10);
208 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
209 info->ram->duplicate);
210 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
211 info->ram->skipped);
212 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
213 info->ram->normal);
214 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
215 info->ram->normal_bytes >> 10);
216 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
217 info->ram->dirty_sync_count);
218 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
219 info->ram->page_size >> 10);
221 if (info->ram->dirty_pages_rate) {
222 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
223 info->ram->dirty_pages_rate);
225 if (info->ram->postcopy_requests) {
226 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
227 info->ram->postcopy_requests);
231 if (info->has_disk) {
232 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
233 info->disk->transferred >> 10);
234 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
235 info->disk->remaining >> 10);
236 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
237 info->disk->total >> 10);
240 if (info->has_xbzrle_cache) {
241 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
242 info->xbzrle_cache->cache_size);
243 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
244 info->xbzrle_cache->bytes >> 10);
245 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
246 info->xbzrle_cache->pages);
247 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
248 info->xbzrle_cache->cache_miss);
249 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
250 info->xbzrle_cache->cache_miss_rate);
251 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
252 info->xbzrle_cache->overflow);
255 if (info->has_cpu_throttle_percentage) {
256 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
257 info->cpu_throttle_percentage);
260 qapi_free_MigrationInfo(info);
261 qapi_free_MigrationCapabilityStatusList(caps);
264 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
266 MigrationCapabilityStatusList *caps, *cap;
268 caps = qmp_query_migrate_capabilities(NULL);
270 if (caps) {
271 monitor_printf(mon, "capabilities: ");
272 for (cap = caps; cap; cap = cap->next) {
273 monitor_printf(mon, "%s: %s ",
274 MigrationCapability_lookup[cap->value->capability],
275 cap->value->state ? "on" : "off");
277 monitor_printf(mon, "\n");
280 qapi_free_MigrationCapabilityStatusList(caps);
283 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
285 MigrationParameters *params;
287 params = qmp_query_migrate_parameters(NULL);
289 if (params) {
290 monitor_printf(mon, "parameters:");
291 assert(params->has_compress_level);
292 monitor_printf(mon, " %s: %" PRId64,
293 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_LEVEL],
294 params->compress_level);
295 assert(params->has_compress_threads);
296 monitor_printf(mon, " %s: %" PRId64,
297 MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_THREADS],
298 params->compress_threads);
299 assert(params->has_decompress_threads);
300 monitor_printf(mon, " %s: %" PRId64,
301 MigrationParameter_lookup[MIGRATION_PARAMETER_DECOMPRESS_THREADS],
302 params->decompress_threads);
303 assert(params->has_cpu_throttle_initial);
304 monitor_printf(mon, " %s: %" PRId64,
305 MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL],
306 params->cpu_throttle_initial);
307 assert(params->has_cpu_throttle_increment);
308 monitor_printf(mon, " %s: %" PRId64,
309 MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT],
310 params->cpu_throttle_increment);
311 monitor_printf(mon, " %s: '%s'",
312 MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_CREDS],
313 params->has_tls_creds ? params->tls_creds : "");
314 monitor_printf(mon, " %s: '%s'",
315 MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_HOSTNAME],
316 params->has_tls_hostname ? params->tls_hostname : "");
317 assert(params->has_max_bandwidth);
318 monitor_printf(mon, " %s: %" PRId64 " bytes/second",
319 MigrationParameter_lookup[MIGRATION_PARAMETER_MAX_BANDWIDTH],
320 params->max_bandwidth);
321 assert(params->has_downtime_limit);
322 monitor_printf(mon, " %s: %" PRId64 " milliseconds",
323 MigrationParameter_lookup[MIGRATION_PARAMETER_DOWNTIME_LIMIT],
324 params->downtime_limit);
325 assert(params->has_x_checkpoint_delay);
326 monitor_printf(mon, " %s: %" PRId64,
327 MigrationParameter_lookup[MIGRATION_PARAMETER_X_CHECKPOINT_DELAY],
328 params->x_checkpoint_delay);
329 monitor_printf(mon, "\n");
332 qapi_free_MigrationParameters(params);
335 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
337 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
338 qmp_query_migrate_cache_size(NULL) >> 10);
341 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
343 CpuInfoList *cpu_list, *cpu;
345 cpu_list = qmp_query_cpus(NULL);
347 for (cpu = cpu_list; cpu; cpu = cpu->next) {
348 int active = ' ';
350 if (cpu->value->CPU == monitor_get_cpu_index()) {
351 active = '*';
354 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
356 switch (cpu->value->arch) {
357 case CPU_INFO_ARCH_X86:
358 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->u.x86.pc);
359 break;
360 case CPU_INFO_ARCH_PPC:
361 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->u.ppc.nip);
362 break;
363 case CPU_INFO_ARCH_SPARC:
364 monitor_printf(mon, " pc=0x%016" PRIx64,
365 cpu->value->u.q_sparc.pc);
366 monitor_printf(mon, " npc=0x%016" PRIx64,
367 cpu->value->u.q_sparc.npc);
368 break;
369 case CPU_INFO_ARCH_MIPS:
370 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.q_mips.PC);
371 break;
372 case CPU_INFO_ARCH_TRICORE:
373 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.tricore.PC);
374 break;
375 default:
376 break;
379 if (cpu->value->halted) {
380 monitor_printf(mon, " (halted)");
383 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
386 qapi_free_CpuInfoList(cpu_list);
389 static void print_block_info(Monitor *mon, BlockInfo *info,
390 BlockDeviceInfo *inserted, bool verbose)
392 ImageInfo *image_info;
394 assert(!info || !info->has_inserted || info->inserted == inserted);
396 if (info) {
397 monitor_printf(mon, "%s", info->device);
398 if (inserted && inserted->has_node_name) {
399 monitor_printf(mon, " (%s)", inserted->node_name);
401 } else {
402 assert(inserted);
403 monitor_printf(mon, "%s",
404 inserted->has_node_name
405 ? inserted->node_name
406 : "<anonymous>");
409 if (inserted) {
410 monitor_printf(mon, ": %s (%s%s%s)\n",
411 inserted->file,
412 inserted->drv,
413 inserted->ro ? ", read-only" : "",
414 inserted->encrypted ? ", encrypted" : "");
415 } else {
416 monitor_printf(mon, ": [not inserted]\n");
419 if (info) {
420 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
421 monitor_printf(mon, " I/O status: %s\n",
422 BlockDeviceIoStatus_lookup[info->io_status]);
425 if (info->removable) {
426 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
427 info->locked ? "" : "not ",
428 info->tray_open ? "open" : "closed");
433 if (!inserted) {
434 return;
437 monitor_printf(mon, " Cache mode: %s%s%s\n",
438 inserted->cache->writeback ? "writeback" : "writethrough",
439 inserted->cache->direct ? ", direct" : "",
440 inserted->cache->no_flush ? ", ignore flushes" : "");
442 if (inserted->has_backing_file) {
443 monitor_printf(mon,
444 " Backing file: %s "
445 "(chain depth: %" PRId64 ")\n",
446 inserted->backing_file,
447 inserted->backing_file_depth);
450 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
451 monitor_printf(mon, " Detect zeroes: %s\n",
452 BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]);
455 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
456 inserted->iops || inserted->iops_rd || inserted->iops_wr)
458 monitor_printf(mon, " I/O throttling: bps=%" PRId64
459 " bps_rd=%" PRId64 " bps_wr=%" PRId64
460 " bps_max=%" PRId64
461 " bps_rd_max=%" PRId64
462 " bps_wr_max=%" PRId64
463 " iops=%" PRId64 " iops_rd=%" PRId64
464 " iops_wr=%" PRId64
465 " iops_max=%" PRId64
466 " iops_rd_max=%" PRId64
467 " iops_wr_max=%" PRId64
468 " iops_size=%" PRId64
469 " group=%s\n",
470 inserted->bps,
471 inserted->bps_rd,
472 inserted->bps_wr,
473 inserted->bps_max,
474 inserted->bps_rd_max,
475 inserted->bps_wr_max,
476 inserted->iops,
477 inserted->iops_rd,
478 inserted->iops_wr,
479 inserted->iops_max,
480 inserted->iops_rd_max,
481 inserted->iops_wr_max,
482 inserted->iops_size,
483 inserted->group);
486 if (verbose) {
487 monitor_printf(mon, "\nImages:\n");
488 image_info = inserted->image;
489 while (1) {
490 bdrv_image_info_dump((fprintf_function)monitor_printf,
491 mon, image_info);
492 if (image_info->has_backing_image) {
493 image_info = image_info->backing_image;
494 } else {
495 break;
501 void hmp_info_block(Monitor *mon, const QDict *qdict)
503 BlockInfoList *block_list, *info;
504 BlockDeviceInfoList *blockdev_list, *blockdev;
505 const char *device = qdict_get_try_str(qdict, "device");
506 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
507 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
508 bool printed = false;
510 /* Print BlockBackend information */
511 if (!nodes) {
512 block_list = qmp_query_block(NULL);
513 } else {
514 block_list = NULL;
517 for (info = block_list; info; info = info->next) {
518 if (device && strcmp(device, info->value->device)) {
519 continue;
522 if (info != block_list) {
523 monitor_printf(mon, "\n");
526 print_block_info(mon, info->value, info->value->has_inserted
527 ? info->value->inserted : NULL,
528 verbose);
529 printed = true;
532 qapi_free_BlockInfoList(block_list);
534 if ((!device && !nodes) || printed) {
535 return;
538 /* Print node information */
539 blockdev_list = qmp_query_named_block_nodes(NULL);
540 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
541 assert(blockdev->value->has_node_name);
542 if (device && strcmp(device, blockdev->value->node_name)) {
543 continue;
546 if (blockdev != blockdev_list) {
547 monitor_printf(mon, "\n");
550 print_block_info(mon, NULL, blockdev->value, verbose);
552 qapi_free_BlockDeviceInfoList(blockdev_list);
555 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
557 BlockStatsList *stats_list, *stats;
559 stats_list = qmp_query_blockstats(false, false, NULL);
561 for (stats = stats_list; stats; stats = stats->next) {
562 if (!stats->value->has_device) {
563 continue;
566 monitor_printf(mon, "%s:", stats->value->device);
567 monitor_printf(mon, " rd_bytes=%" PRId64
568 " wr_bytes=%" PRId64
569 " rd_operations=%" PRId64
570 " wr_operations=%" PRId64
571 " flush_operations=%" PRId64
572 " wr_total_time_ns=%" PRId64
573 " rd_total_time_ns=%" PRId64
574 " flush_total_time_ns=%" PRId64
575 " rd_merged=%" PRId64
576 " wr_merged=%" PRId64
577 " idle_time_ns=%" PRId64
578 "\n",
579 stats->value->stats->rd_bytes,
580 stats->value->stats->wr_bytes,
581 stats->value->stats->rd_operations,
582 stats->value->stats->wr_operations,
583 stats->value->stats->flush_operations,
584 stats->value->stats->wr_total_time_ns,
585 stats->value->stats->rd_total_time_ns,
586 stats->value->stats->flush_total_time_ns,
587 stats->value->stats->rd_merged,
588 stats->value->stats->wr_merged,
589 stats->value->stats->idle_time_ns);
592 qapi_free_BlockStatsList(stats_list);
595 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
597 VncInfo *info;
598 Error *err = NULL;
599 VncClientInfoList *client;
601 info = qmp_query_vnc(&err);
602 if (err) {
603 error_report_err(err);
604 return;
607 if (!info->enabled) {
608 monitor_printf(mon, "Server: disabled\n");
609 goto out;
612 monitor_printf(mon, "Server:\n");
613 if (info->has_host && info->has_service) {
614 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
616 if (info->has_auth) {
617 monitor_printf(mon, " auth: %s\n", info->auth);
620 if (!info->has_clients || info->clients == NULL) {
621 monitor_printf(mon, "Client: none\n");
622 } else {
623 for (client = info->clients; client; client = client->next) {
624 monitor_printf(mon, "Client:\n");
625 monitor_printf(mon, " address: %s:%s\n",
626 client->value->host,
627 client->value->service);
628 monitor_printf(mon, " x509_dname: %s\n",
629 client->value->x509_dname ?
630 client->value->x509_dname : "none");
631 monitor_printf(mon, " username: %s\n",
632 client->value->has_sasl_username ?
633 client->value->sasl_username : "none");
637 out:
638 qapi_free_VncInfo(info);
641 #ifdef CONFIG_SPICE
642 void hmp_info_spice(Monitor *mon, const QDict *qdict)
644 SpiceChannelList *chan;
645 SpiceInfo *info;
646 const char *channel_name;
647 const char * const channel_names[] = {
648 [SPICE_CHANNEL_MAIN] = "main",
649 [SPICE_CHANNEL_DISPLAY] = "display",
650 [SPICE_CHANNEL_INPUTS] = "inputs",
651 [SPICE_CHANNEL_CURSOR] = "cursor",
652 [SPICE_CHANNEL_PLAYBACK] = "playback",
653 [SPICE_CHANNEL_RECORD] = "record",
654 [SPICE_CHANNEL_TUNNEL] = "tunnel",
655 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
656 [SPICE_CHANNEL_USBREDIR] = "usbredir",
657 [SPICE_CHANNEL_PORT] = "port",
658 #if 0
659 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
660 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
661 * as quick fix for build failures with older versions. */
662 [SPICE_CHANNEL_WEBDAV] = "webdav",
663 #endif
666 info = qmp_query_spice(NULL);
668 if (!info->enabled) {
669 monitor_printf(mon, "Server: disabled\n");
670 goto out;
673 monitor_printf(mon, "Server:\n");
674 if (info->has_port) {
675 monitor_printf(mon, " address: %s:%" PRId64 "\n",
676 info->host, info->port);
678 if (info->has_tls_port) {
679 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
680 info->host, info->tls_port);
682 monitor_printf(mon, " migrated: %s\n",
683 info->migrated ? "true" : "false");
684 monitor_printf(mon, " auth: %s\n", info->auth);
685 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
686 monitor_printf(mon, " mouse-mode: %s\n",
687 SpiceQueryMouseMode_lookup[info->mouse_mode]);
689 if (!info->has_channels || info->channels == NULL) {
690 monitor_printf(mon, "Channels: none\n");
691 } else {
692 for (chan = info->channels; chan; chan = chan->next) {
693 monitor_printf(mon, "Channel:\n");
694 monitor_printf(mon, " address: %s:%s%s\n",
695 chan->value->host, chan->value->port,
696 chan->value->tls ? " [tls]" : "");
697 monitor_printf(mon, " session: %" PRId64 "\n",
698 chan->value->connection_id);
699 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
700 chan->value->channel_type, chan->value->channel_id);
702 channel_name = "unknown";
703 if (chan->value->channel_type > 0 &&
704 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
705 channel_names[chan->value->channel_type]) {
706 channel_name = channel_names[chan->value->channel_type];
709 monitor_printf(mon, " channel name: %s\n", channel_name);
713 out:
714 qapi_free_SpiceInfo(info);
716 #endif
718 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
720 BalloonInfo *info;
721 Error *err = NULL;
723 info = qmp_query_balloon(&err);
724 if (err) {
725 error_report_err(err);
726 return;
729 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
731 qapi_free_BalloonInfo(info);
734 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
736 PciMemoryRegionList *region;
738 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
739 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
740 dev->slot, dev->function);
741 monitor_printf(mon, " ");
743 if (dev->class_info->has_desc) {
744 monitor_printf(mon, "%s", dev->class_info->desc);
745 } else {
746 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
749 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
750 dev->id->vendor, dev->id->device);
752 if (dev->has_irq) {
753 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
756 if (dev->has_pci_bridge) {
757 monitor_printf(mon, " BUS %" PRId64 ".\n",
758 dev->pci_bridge->bus->number);
759 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
760 dev->pci_bridge->bus->secondary);
761 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
762 dev->pci_bridge->bus->subordinate);
764 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
765 dev->pci_bridge->bus->io_range->base,
766 dev->pci_bridge->bus->io_range->limit);
768 monitor_printf(mon,
769 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
770 dev->pci_bridge->bus->memory_range->base,
771 dev->pci_bridge->bus->memory_range->limit);
773 monitor_printf(mon, " prefetchable memory range "
774 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
775 dev->pci_bridge->bus->prefetchable_range->base,
776 dev->pci_bridge->bus->prefetchable_range->limit);
779 for (region = dev->regions; region; region = region->next) {
780 uint64_t addr, size;
782 addr = region->value->address;
783 size = region->value->size;
785 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
787 if (!strcmp(region->value->type, "io")) {
788 monitor_printf(mon, "I/O at 0x%04" PRIx64
789 " [0x%04" PRIx64 "].\n",
790 addr, addr + size - 1);
791 } else {
792 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
793 " [0x%08" PRIx64 "].\n",
794 region->value->mem_type_64 ? 64 : 32,
795 region->value->prefetch ? " prefetchable" : "",
796 addr, addr + size - 1);
800 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
802 if (dev->has_pci_bridge) {
803 if (dev->pci_bridge->has_devices) {
804 PciDeviceInfoList *cdev;
805 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
806 hmp_info_pci_device(mon, cdev->value);
812 static int hmp_info_irq_foreach(Object *obj, void *opaque)
814 InterruptStatsProvider *intc;
815 InterruptStatsProviderClass *k;
816 Monitor *mon = opaque;
818 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
819 intc = INTERRUPT_STATS_PROVIDER(obj);
820 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
821 uint64_t *irq_counts;
822 unsigned int nb_irqs, i;
823 if (k->get_statistics &&
824 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
825 if (nb_irqs > 0) {
826 monitor_printf(mon, "IRQ statistics for %s:\n",
827 object_get_typename(obj));
828 for (i = 0; i < nb_irqs; i++) {
829 if (irq_counts[i] > 0) {
830 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
831 irq_counts[i]);
835 } else {
836 monitor_printf(mon, "IRQ statistics not available for %s.\n",
837 object_get_typename(obj));
841 return 0;
844 void hmp_info_irq(Monitor *mon, const QDict *qdict)
846 object_child_foreach_recursive(object_get_root(),
847 hmp_info_irq_foreach, mon);
850 static int hmp_info_pic_foreach(Object *obj, void *opaque)
852 InterruptStatsProvider *intc;
853 InterruptStatsProviderClass *k;
854 Monitor *mon = opaque;
856 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
857 intc = INTERRUPT_STATS_PROVIDER(obj);
858 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
859 if (k->print_info) {
860 k->print_info(intc, mon);
861 } else {
862 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
863 object_get_typename(obj));
867 return 0;
870 void hmp_info_pic(Monitor *mon, const QDict *qdict)
872 object_child_foreach_recursive(object_get_root(),
873 hmp_info_pic_foreach, mon);
876 void hmp_info_pci(Monitor *mon, const QDict *qdict)
878 PciInfoList *info_list, *info;
879 Error *err = NULL;
881 info_list = qmp_query_pci(&err);
882 if (err) {
883 monitor_printf(mon, "PCI devices not supported\n");
884 error_free(err);
885 return;
888 for (info = info_list; info; info = info->next) {
889 PciDeviceInfoList *dev;
891 for (dev = info->value->devices; dev; dev = dev->next) {
892 hmp_info_pci_device(mon, dev->value);
896 qapi_free_PciInfoList(info_list);
899 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
901 BlockJobInfoList *list;
902 Error *err = NULL;
904 list = qmp_query_block_jobs(&err);
905 assert(!err);
907 if (!list) {
908 monitor_printf(mon, "No active jobs\n");
909 return;
912 while (list) {
913 if (strcmp(list->value->type, "stream") == 0) {
914 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
915 " of %" PRId64 " bytes, speed limit %" PRId64
916 " bytes/s\n",
917 list->value->device,
918 list->value->offset,
919 list->value->len,
920 list->value->speed);
921 } else {
922 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
923 " of %" PRId64 " bytes, speed limit %" PRId64
924 " bytes/s\n",
925 list->value->type,
926 list->value->device,
927 list->value->offset,
928 list->value->len,
929 list->value->speed);
931 list = list->next;
934 qapi_free_BlockJobInfoList(list);
937 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
939 TPMInfoList *info_list, *info;
940 Error *err = NULL;
941 unsigned int c = 0;
942 TPMPassthroughOptions *tpo;
944 info_list = qmp_query_tpm(&err);
945 if (err) {
946 monitor_printf(mon, "TPM device not supported\n");
947 error_free(err);
948 return;
951 if (info_list) {
952 monitor_printf(mon, "TPM device:\n");
955 for (info = info_list; info; info = info->next) {
956 TPMInfo *ti = info->value;
957 monitor_printf(mon, " tpm%d: model=%s\n",
958 c, TpmModel_lookup[ti->model]);
960 monitor_printf(mon, " \\ %s: type=%s",
961 ti->id, TpmTypeOptionsKind_lookup[ti->options->type]);
963 switch (ti->options->type) {
964 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
965 tpo = ti->options->u.passthrough.data;
966 monitor_printf(mon, "%s%s%s%s",
967 tpo->has_path ? ",path=" : "",
968 tpo->has_path ? tpo->path : "",
969 tpo->has_cancel_path ? ",cancel-path=" : "",
970 tpo->has_cancel_path ? tpo->cancel_path : "");
971 break;
972 case TPM_TYPE_OPTIONS_KIND__MAX:
973 break;
975 monitor_printf(mon, "\n");
976 c++;
978 qapi_free_TPMInfoList(info_list);
981 void hmp_quit(Monitor *mon, const QDict *qdict)
983 monitor_suspend(mon);
984 qmp_quit(NULL);
987 void hmp_stop(Monitor *mon, const QDict *qdict)
989 qmp_stop(NULL);
992 void hmp_system_reset(Monitor *mon, const QDict *qdict)
994 qmp_system_reset(NULL);
997 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
999 qmp_system_powerdown(NULL);
1002 void hmp_cpu(Monitor *mon, const QDict *qdict)
1004 int64_t cpu_index;
1006 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1007 use it are converted to the QAPI */
1008 cpu_index = qdict_get_int(qdict, "index");
1009 if (monitor_set_cpu(cpu_index) < 0) {
1010 monitor_printf(mon, "invalid CPU index\n");
1014 void hmp_memsave(Monitor *mon, const QDict *qdict)
1016 uint32_t size = qdict_get_int(qdict, "size");
1017 const char *filename = qdict_get_str(qdict, "filename");
1018 uint64_t addr = qdict_get_int(qdict, "val");
1019 Error *err = NULL;
1020 int cpu_index = monitor_get_cpu_index();
1022 if (cpu_index < 0) {
1023 monitor_printf(mon, "No CPU available\n");
1024 return;
1027 qmp_memsave(addr, size, filename, true, cpu_index, &err);
1028 hmp_handle_error(mon, &err);
1031 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1033 uint32_t size = qdict_get_int(qdict, "size");
1034 const char *filename = qdict_get_str(qdict, "filename");
1035 uint64_t addr = qdict_get_int(qdict, "val");
1036 Error *err = NULL;
1038 qmp_pmemsave(addr, size, filename, &err);
1039 hmp_handle_error(mon, &err);
1042 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1044 const char *chardev = qdict_get_str(qdict, "device");
1045 const char *data = qdict_get_str(qdict, "data");
1046 Error *err = NULL;
1048 qmp_ringbuf_write(chardev, data, false, 0, &err);
1050 hmp_handle_error(mon, &err);
1053 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
1055 uint32_t size = qdict_get_int(qdict, "size");
1056 const char *chardev = qdict_get_str(qdict, "device");
1057 char *data;
1058 Error *err = NULL;
1059 int i;
1061 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1062 if (err) {
1063 error_report_err(err);
1064 return;
1067 for (i = 0; data[i]; i++) {
1068 unsigned char ch = data[i];
1070 if (ch == '\\') {
1071 monitor_printf(mon, "\\\\");
1072 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1073 monitor_printf(mon, "\\u%04X", ch);
1074 } else {
1075 monitor_printf(mon, "%c", ch);
1079 monitor_printf(mon, "\n");
1080 g_free(data);
1083 static void hmp_cont_cb(void *opaque, int err)
1085 if (!err) {
1086 qmp_cont(NULL);
1090 static bool key_is_missing(const BlockInfo *bdev)
1092 return (bdev->inserted && bdev->inserted->encryption_key_missing);
1095 void hmp_cont(Monitor *mon, const QDict *qdict)
1097 BlockInfoList *bdev_list, *bdev;
1098 Error *err = NULL;
1100 bdev_list = qmp_query_block(NULL);
1101 for (bdev = bdev_list; bdev; bdev = bdev->next) {
1102 if (key_is_missing(bdev->value)) {
1103 monitor_read_block_device_key(mon, bdev->value->device,
1104 hmp_cont_cb, NULL);
1105 goto out;
1109 qmp_cont(&err);
1110 hmp_handle_error(mon, &err);
1112 out:
1113 qapi_free_BlockInfoList(bdev_list);
1116 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1118 qmp_system_wakeup(NULL);
1121 void hmp_nmi(Monitor *mon, const QDict *qdict)
1123 Error *err = NULL;
1125 qmp_inject_nmi(&err);
1126 hmp_handle_error(mon, &err);
1129 void hmp_set_link(Monitor *mon, const QDict *qdict)
1131 const char *name = qdict_get_str(qdict, "name");
1132 bool up = qdict_get_bool(qdict, "up");
1133 Error *err = NULL;
1135 qmp_set_link(name, up, &err);
1136 hmp_handle_error(mon, &err);
1139 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1141 const char *device = qdict_get_str(qdict, "device");
1142 const char *password = qdict_get_str(qdict, "password");
1143 Error *err = NULL;
1145 qmp_block_passwd(true, device, false, NULL, password, &err);
1146 hmp_handle_error(mon, &err);
1149 void hmp_balloon(Monitor *mon, const QDict *qdict)
1151 int64_t value = qdict_get_int(qdict, "value");
1152 Error *err = NULL;
1154 qmp_balloon(value, &err);
1155 if (err) {
1156 error_report_err(err);
1160 void hmp_block_resize(Monitor *mon, const QDict *qdict)
1162 const char *device = qdict_get_str(qdict, "device");
1163 int64_t size = qdict_get_int(qdict, "size");
1164 Error *err = NULL;
1166 qmp_block_resize(true, device, false, NULL, size, &err);
1167 hmp_handle_error(mon, &err);
1170 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1172 const char *filename = qdict_get_str(qdict, "target");
1173 const char *format = qdict_get_try_str(qdict, "format");
1174 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1175 bool full = qdict_get_try_bool(qdict, "full", false);
1176 Error *err = NULL;
1177 DriveMirror mirror = {
1178 .device = (char *)qdict_get_str(qdict, "device"),
1179 .target = (char *)filename,
1180 .has_format = !!format,
1181 .format = (char *)format,
1182 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1183 .has_mode = true,
1184 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1185 .unmap = true,
1188 if (!filename) {
1189 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1190 hmp_handle_error(mon, &err);
1191 return;
1193 qmp_drive_mirror(&mirror, &err);
1194 hmp_handle_error(mon, &err);
1197 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1199 const char *device = qdict_get_str(qdict, "device");
1200 const char *filename = qdict_get_str(qdict, "target");
1201 const char *format = qdict_get_try_str(qdict, "format");
1202 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1203 bool full = qdict_get_try_bool(qdict, "full", false);
1204 bool compress = qdict_get_try_bool(qdict, "compress", false);
1205 Error *err = NULL;
1206 DriveBackup backup = {
1207 .device = (char *)device,
1208 .target = (char *)filename,
1209 .has_format = !!format,
1210 .format = (char *)format,
1211 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1212 .has_mode = true,
1213 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1214 .has_compress = !!compress,
1215 .compress = compress,
1218 if (!filename) {
1219 error_setg(&err, QERR_MISSING_PARAMETER, "target");
1220 hmp_handle_error(mon, &err);
1221 return;
1224 qmp_drive_backup(&backup, &err);
1225 hmp_handle_error(mon, &err);
1228 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1230 const char *device = qdict_get_str(qdict, "device");
1231 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1232 const char *format = qdict_get_try_str(qdict, "format");
1233 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1234 enum NewImageMode mode;
1235 Error *err = NULL;
1237 if (!filename) {
1238 /* In the future, if 'snapshot-file' is not specified, the snapshot
1239 will be taken internally. Today it's actually required. */
1240 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
1241 hmp_handle_error(mon, &err);
1242 return;
1245 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
1246 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1247 filename, false, NULL,
1248 !!format, format,
1249 true, mode, &err);
1250 hmp_handle_error(mon, &err);
1253 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1255 const char *device = qdict_get_str(qdict, "device");
1256 const char *name = qdict_get_str(qdict, "name");
1257 Error *err = NULL;
1259 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1260 hmp_handle_error(mon, &err);
1263 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1265 const char *device = qdict_get_str(qdict, "device");
1266 const char *name = qdict_get_str(qdict, "name");
1267 const char *id = qdict_get_try_str(qdict, "id");
1268 Error *err = NULL;
1270 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1271 true, name, &err);
1272 hmp_handle_error(mon, &err);
1275 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1277 qmp_migrate_cancel(NULL);
1280 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1282 Error *err = NULL;
1283 const char *uri = qdict_get_str(qdict, "uri");
1285 qmp_migrate_incoming(uri, &err);
1287 hmp_handle_error(mon, &err);
1290 /* Kept for backwards compatibility */
1291 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1293 double value = qdict_get_double(qdict, "value");
1294 qmp_migrate_set_downtime(value, NULL);
1297 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1299 int64_t value = qdict_get_int(qdict, "value");
1300 Error *err = NULL;
1302 qmp_migrate_set_cache_size(value, &err);
1303 if (err) {
1304 error_report_err(err);
1305 return;
1309 /* Kept for backwards compatibility */
1310 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1312 int64_t value = qdict_get_int(qdict, "value");
1313 qmp_migrate_set_speed(value, NULL);
1316 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1318 const char *cap = qdict_get_str(qdict, "capability");
1319 bool state = qdict_get_bool(qdict, "state");
1320 Error *err = NULL;
1321 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1322 int i;
1324 for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
1325 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1326 caps->value = g_malloc0(sizeof(*caps->value));
1327 caps->value->capability = i;
1328 caps->value->state = state;
1329 caps->next = NULL;
1330 qmp_migrate_set_capabilities(caps, &err);
1331 break;
1335 if (i == MIGRATION_CAPABILITY__MAX) {
1336 error_setg(&err, QERR_INVALID_PARAMETER, cap);
1339 qapi_free_MigrationCapabilityStatusList(caps);
1341 if (err) {
1342 error_report_err(err);
1346 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1348 const char *param = qdict_get_str(qdict, "parameter");
1349 const char *valuestr = qdict_get_str(qdict, "value");
1350 uint64_t valuebw = 0;
1351 long valueint = 0;
1352 Error *err = NULL;
1353 bool use_int_value = false;
1354 int i, ret;
1356 for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
1357 if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
1358 MigrationParameters p = { 0 };
1359 switch (i) {
1360 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1361 p.has_compress_level = true;
1362 use_int_value = true;
1363 break;
1364 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1365 p.has_compress_threads = true;
1366 use_int_value = true;
1367 break;
1368 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1369 p.has_decompress_threads = true;
1370 use_int_value = true;
1371 break;
1372 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1373 p.has_cpu_throttle_initial = true;
1374 use_int_value = true;
1375 break;
1376 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1377 p.has_cpu_throttle_increment = true;
1378 use_int_value = true;
1379 break;
1380 case MIGRATION_PARAMETER_TLS_CREDS:
1381 p.has_tls_creds = true;
1382 p.tls_creds = (char *) valuestr;
1383 break;
1384 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1385 p.has_tls_hostname = true;
1386 p.tls_hostname = (char *) valuestr;
1387 break;
1388 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1389 p.has_max_bandwidth = true;
1390 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1391 if (ret < 0 || valuebw > INT64_MAX
1392 || (size_t)valuebw != valuebw) {
1393 error_setg(&err, "Invalid size %s", valuestr);
1394 goto cleanup;
1396 p.max_bandwidth = valuebw;
1397 break;
1398 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1399 p.has_downtime_limit = true;
1400 use_int_value = true;
1401 break;
1402 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1403 p.has_x_checkpoint_delay = true;
1404 use_int_value = true;
1405 break;
1408 if (use_int_value) {
1409 if (qemu_strtol(valuestr, NULL, 10, &valueint) < 0) {
1410 error_setg(&err, "Unable to parse '%s' as an int",
1411 valuestr);
1412 goto cleanup;
1414 /* Set all integers; only one has_FOO will be set, and
1415 * the code ignores the remaining values */
1416 p.compress_level = valueint;
1417 p.compress_threads = valueint;
1418 p.decompress_threads = valueint;
1419 p.cpu_throttle_initial = valueint;
1420 p.cpu_throttle_increment = valueint;
1421 p.downtime_limit = valueint;
1422 p.x_checkpoint_delay = valueint;
1425 qmp_migrate_set_parameters(&p, &err);
1426 break;
1430 if (i == MIGRATION_PARAMETER__MAX) {
1431 error_setg(&err, QERR_INVALID_PARAMETER, param);
1434 cleanup:
1435 if (err) {
1436 error_report_err(err);
1440 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1442 Error *err = NULL;
1443 const char *protocol = qdict_get_str(qdict, "protocol");
1444 const char *hostname = qdict_get_str(qdict, "hostname");
1445 bool has_port = qdict_haskey(qdict, "port");
1446 int port = qdict_get_try_int(qdict, "port", -1);
1447 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1448 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1449 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1451 qmp_client_migrate_info(protocol, hostname,
1452 has_port, port, has_tls_port, tls_port,
1453 !!cert_subject, cert_subject, &err);
1454 hmp_handle_error(mon, &err);
1457 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1459 Error *err = NULL;
1460 qmp_migrate_start_postcopy(&err);
1461 hmp_handle_error(mon, &err);
1464 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1466 Error *err = NULL;
1468 qmp_x_colo_lost_heartbeat(&err);
1469 hmp_handle_error(mon, &err);
1472 void hmp_set_password(Monitor *mon, const QDict *qdict)
1474 const char *protocol = qdict_get_str(qdict, "protocol");
1475 const char *password = qdict_get_str(qdict, "password");
1476 const char *connected = qdict_get_try_str(qdict, "connected");
1477 Error *err = NULL;
1479 qmp_set_password(protocol, password, !!connected, connected, &err);
1480 hmp_handle_error(mon, &err);
1483 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1485 const char *protocol = qdict_get_str(qdict, "protocol");
1486 const char *whenstr = qdict_get_str(qdict, "time");
1487 Error *err = NULL;
1489 qmp_expire_password(protocol, whenstr, &err);
1490 hmp_handle_error(mon, &err);
1493 void hmp_eject(Monitor *mon, const QDict *qdict)
1495 bool force = qdict_get_try_bool(qdict, "force", false);
1496 const char *device = qdict_get_str(qdict, "device");
1497 Error *err = NULL;
1499 qmp_eject(true, device, false, NULL, true, force, &err);
1500 hmp_handle_error(mon, &err);
1503 static void hmp_change_read_arg(void *opaque, const char *password,
1504 void *readline_opaque)
1506 qmp_change_vnc_password(password, NULL);
1507 monitor_read_command(opaque, 1);
1510 void hmp_change(Monitor *mon, const QDict *qdict)
1512 const char *device = qdict_get_str(qdict, "device");
1513 const char *target = qdict_get_str(qdict, "target");
1514 const char *arg = qdict_get_try_str(qdict, "arg");
1515 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1516 BlockdevChangeReadOnlyMode read_only_mode = 0;
1517 Error *err = NULL;
1519 if (strcmp(device, "vnc") == 0) {
1520 if (read_only) {
1521 monitor_printf(mon,
1522 "Parameter 'read-only-mode' is invalid for VNC\n");
1523 return;
1525 if (strcmp(target, "passwd") == 0 ||
1526 strcmp(target, "password") == 0) {
1527 if (!arg) {
1528 monitor_read_password(mon, hmp_change_read_arg, NULL);
1529 return;
1532 qmp_change("vnc", target, !!arg, arg, &err);
1533 } else {
1534 if (read_only) {
1535 read_only_mode =
1536 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup,
1537 read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX,
1538 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1539 if (err) {
1540 hmp_handle_error(mon, &err);
1541 return;
1545 qmp_blockdev_change_medium(true, device, false, NULL, target,
1546 !!arg, arg, !!read_only, read_only_mode,
1547 &err);
1548 if (err &&
1549 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
1550 error_free(err);
1551 monitor_read_block_device_key(mon, device, NULL, NULL);
1552 return;
1556 hmp_handle_error(mon, &err);
1559 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1561 Error *err = NULL;
1562 BlockIOThrottle throttle = {
1563 .has_device = true,
1564 .device = (char *) qdict_get_str(qdict, "device"),
1565 .bps = qdict_get_int(qdict, "bps"),
1566 .bps_rd = qdict_get_int(qdict, "bps_rd"),
1567 .bps_wr = qdict_get_int(qdict, "bps_wr"),
1568 .iops = qdict_get_int(qdict, "iops"),
1569 .iops_rd = qdict_get_int(qdict, "iops_rd"),
1570 .iops_wr = qdict_get_int(qdict, "iops_wr"),
1573 qmp_block_set_io_throttle(&throttle, &err);
1574 hmp_handle_error(mon, &err);
1577 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1579 Error *error = NULL;
1580 const char *device = qdict_get_str(qdict, "device");
1581 const char *base = qdict_get_try_str(qdict, "base");
1582 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1584 qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
1585 false, NULL, qdict_haskey(qdict, "speed"), speed,
1586 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1588 hmp_handle_error(mon, &error);
1591 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1593 Error *error = NULL;
1594 const char *device = qdict_get_str(qdict, "device");
1595 int64_t value = qdict_get_int(qdict, "speed");
1597 qmp_block_job_set_speed(device, value, &error);
1599 hmp_handle_error(mon, &error);
1602 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1604 Error *error = NULL;
1605 const char *device = qdict_get_str(qdict, "device");
1606 bool force = qdict_get_try_bool(qdict, "force", false);
1608 qmp_block_job_cancel(device, true, force, &error);
1610 hmp_handle_error(mon, &error);
1613 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1615 Error *error = NULL;
1616 const char *device = qdict_get_str(qdict, "device");
1618 qmp_block_job_pause(device, &error);
1620 hmp_handle_error(mon, &error);
1623 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1625 Error *error = NULL;
1626 const char *device = qdict_get_str(qdict, "device");
1628 qmp_block_job_resume(device, &error);
1630 hmp_handle_error(mon, &error);
1633 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1635 Error *error = NULL;
1636 const char *device = qdict_get_str(qdict, "device");
1638 qmp_block_job_complete(device, &error);
1640 hmp_handle_error(mon, &error);
1643 typedef struct HMPMigrationStatus
1645 QEMUTimer *timer;
1646 Monitor *mon;
1647 bool is_block_migration;
1648 } HMPMigrationStatus;
1650 static void hmp_migrate_status_cb(void *opaque)
1652 HMPMigrationStatus *status = opaque;
1653 MigrationInfo *info;
1655 info = qmp_query_migrate(NULL);
1656 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1657 info->status == MIGRATION_STATUS_SETUP) {
1658 if (info->has_disk) {
1659 int progress;
1661 if (info->disk->remaining) {
1662 progress = info->disk->transferred * 100 / info->disk->total;
1663 } else {
1664 progress = 100;
1667 monitor_printf(status->mon, "Completed %d %%\r", progress);
1668 monitor_flush(status->mon);
1671 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1672 } else {
1673 if (status->is_block_migration) {
1674 monitor_printf(status->mon, "\n");
1676 if (info->has_error_desc) {
1677 error_report("%s", info->error_desc);
1679 monitor_resume(status->mon);
1680 timer_del(status->timer);
1681 g_free(status);
1684 qapi_free_MigrationInfo(info);
1687 void hmp_migrate(Monitor *mon, const QDict *qdict)
1689 bool detach = qdict_get_try_bool(qdict, "detach", false);
1690 bool blk = qdict_get_try_bool(qdict, "blk", false);
1691 bool inc = qdict_get_try_bool(qdict, "inc", false);
1692 const char *uri = qdict_get_str(qdict, "uri");
1693 Error *err = NULL;
1695 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1696 if (err) {
1697 error_report_err(err);
1698 return;
1701 if (!detach) {
1702 HMPMigrationStatus *status;
1704 if (monitor_suspend(mon) < 0) {
1705 monitor_printf(mon, "terminal does not allow synchronous "
1706 "migration, continuing detached\n");
1707 return;
1710 status = g_malloc0(sizeof(*status));
1711 status->mon = mon;
1712 status->is_block_migration = blk || inc;
1713 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1714 status);
1715 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1719 void hmp_device_add(Monitor *mon, const QDict *qdict)
1721 Error *err = NULL;
1723 qmp_device_add((QDict *)qdict, NULL, &err);
1724 hmp_handle_error(mon, &err);
1727 void hmp_device_del(Monitor *mon, const QDict *qdict)
1729 const char *id = qdict_get_str(qdict, "id");
1730 Error *err = NULL;
1732 qmp_device_del(id, &err);
1733 hmp_handle_error(mon, &err);
1736 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1738 Error *err = NULL;
1739 bool paging = qdict_get_try_bool(qdict, "paging", false);
1740 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
1741 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
1742 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
1743 const char *file = qdict_get_str(qdict, "filename");
1744 bool has_begin = qdict_haskey(qdict, "begin");
1745 bool has_length = qdict_haskey(qdict, "length");
1746 bool has_detach = qdict_haskey(qdict, "detach");
1747 int64_t begin = 0;
1748 int64_t length = 0;
1749 bool detach = false;
1750 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1751 char *prot;
1753 if (zlib + lzo + snappy > 1) {
1754 error_setg(&err, "only one of '-z|-l|-s' can be set");
1755 hmp_handle_error(mon, &err);
1756 return;
1759 if (zlib) {
1760 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1763 if (lzo) {
1764 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1767 if (snappy) {
1768 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1771 if (has_begin) {
1772 begin = qdict_get_int(qdict, "begin");
1774 if (has_length) {
1775 length = qdict_get_int(qdict, "length");
1777 if (has_detach) {
1778 detach = qdict_get_bool(qdict, "detach");
1781 prot = g_strconcat("file:", file, NULL);
1783 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
1784 has_length, length, true, dump_format, &err);
1785 hmp_handle_error(mon, &err);
1786 g_free(prot);
1789 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1791 Error *err = NULL;
1792 QemuOpts *opts;
1794 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1795 if (err) {
1796 goto out;
1799 netdev_add(opts, &err);
1800 if (err) {
1801 qemu_opts_del(opts);
1804 out:
1805 hmp_handle_error(mon, &err);
1808 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1810 const char *id = qdict_get_str(qdict, "id");
1811 Error *err = NULL;
1813 qmp_netdev_del(id, &err);
1814 hmp_handle_error(mon, &err);
1817 void hmp_object_add(Monitor *mon, const QDict *qdict)
1819 Error *err = NULL;
1820 QemuOpts *opts;
1821 Object *obj = NULL;
1823 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1824 if (err) {
1825 hmp_handle_error(mon, &err);
1826 return;
1829 obj = user_creatable_add_opts(opts, &err);
1830 qemu_opts_del(opts);
1832 if (err) {
1833 hmp_handle_error(mon, &err);
1835 if (obj) {
1836 object_unref(obj);
1840 void hmp_getfd(Monitor *mon, const QDict *qdict)
1842 const char *fdname = qdict_get_str(qdict, "fdname");
1843 Error *err = NULL;
1845 qmp_getfd(fdname, &err);
1846 hmp_handle_error(mon, &err);
1849 void hmp_closefd(Monitor *mon, const QDict *qdict)
1851 const char *fdname = qdict_get_str(qdict, "fdname");
1852 Error *err = NULL;
1854 qmp_closefd(fdname, &err);
1855 hmp_handle_error(mon, &err);
1858 void hmp_sendkey(Monitor *mon, const QDict *qdict)
1860 const char *keys = qdict_get_str(qdict, "keys");
1861 KeyValueList *keylist, *head = NULL, *tmp = NULL;
1862 int has_hold_time = qdict_haskey(qdict, "hold-time");
1863 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1864 Error *err = NULL;
1865 char *separator;
1866 int keyname_len;
1868 while (1) {
1869 separator = strchr(keys, '-');
1870 keyname_len = separator ? separator - keys : strlen(keys);
1872 /* Be compatible with old interface, convert user inputted "<" */
1873 if (keys[0] == '<' && keyname_len == 1) {
1874 keys = "less";
1875 keyname_len = 4;
1878 keylist = g_malloc0(sizeof(*keylist));
1879 keylist->value = g_malloc0(sizeof(*keylist->value));
1881 if (!head) {
1882 head = keylist;
1884 if (tmp) {
1885 tmp->next = keylist;
1887 tmp = keylist;
1889 if (strstart(keys, "0x", NULL)) {
1890 char *endp;
1891 int value = strtoul(keys, &endp, 0);
1892 assert(endp <= keys + keyname_len);
1893 if (endp != keys + keyname_len) {
1894 goto err_out;
1896 keylist->value->type = KEY_VALUE_KIND_NUMBER;
1897 keylist->value->u.number.data = value;
1898 } else {
1899 int idx = index_from_key(keys, keyname_len);
1900 if (idx == Q_KEY_CODE__MAX) {
1901 goto err_out;
1903 keylist->value->type = KEY_VALUE_KIND_QCODE;
1904 keylist->value->u.qcode.data = idx;
1907 if (!separator) {
1908 break;
1910 keys = separator + 1;
1913 qmp_send_key(head, has_hold_time, hold_time, &err);
1914 hmp_handle_error(mon, &err);
1916 out:
1917 qapi_free_KeyValueList(head);
1918 return;
1920 err_out:
1921 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
1922 goto out;
1925 void hmp_screendump(Monitor *mon, const QDict *qdict)
1927 const char *filename = qdict_get_str(qdict, "filename");
1928 Error *err = NULL;
1930 qmp_screendump(filename, &err);
1931 hmp_handle_error(mon, &err);
1934 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1936 const char *uri = qdict_get_str(qdict, "uri");
1937 bool writable = qdict_get_try_bool(qdict, "writable", false);
1938 bool all = qdict_get_try_bool(qdict, "all", false);
1939 Error *local_err = NULL;
1940 BlockInfoList *block_list, *info;
1941 SocketAddress *addr;
1943 if (writable && !all) {
1944 error_setg(&local_err, "-w only valid together with -a");
1945 goto exit;
1948 /* First check if the address is valid and start the server. */
1949 addr = socket_parse(uri, &local_err);
1950 if (local_err != NULL) {
1951 goto exit;
1954 qmp_nbd_server_start(addr, false, NULL, &local_err);
1955 qapi_free_SocketAddress(addr);
1956 if (local_err != NULL) {
1957 goto exit;
1960 if (!all) {
1961 return;
1964 /* Then try adding all block devices. If one fails, close all and
1965 * exit.
1967 block_list = qmp_query_block(NULL);
1969 for (info = block_list; info; info = info->next) {
1970 if (!info->value->has_inserted) {
1971 continue;
1974 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1976 if (local_err != NULL) {
1977 qmp_nbd_server_stop(NULL);
1978 break;
1982 qapi_free_BlockInfoList(block_list);
1984 exit:
1985 hmp_handle_error(mon, &local_err);
1988 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1990 const char *device = qdict_get_str(qdict, "device");
1991 bool writable = qdict_get_try_bool(qdict, "writable", false);
1992 Error *local_err = NULL;
1994 qmp_nbd_server_add(device, true, writable, &local_err);
1996 if (local_err != NULL) {
1997 hmp_handle_error(mon, &local_err);
2001 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
2003 Error *err = NULL;
2005 qmp_nbd_server_stop(&err);
2006 hmp_handle_error(mon, &err);
2009 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
2011 int cpuid;
2012 Error *err = NULL;
2014 cpuid = qdict_get_int(qdict, "id");
2015 qmp_cpu_add(cpuid, &err);
2016 hmp_handle_error(mon, &err);
2019 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2021 const char *args = qdict_get_str(qdict, "args");
2022 Error *err = NULL;
2023 QemuOpts *opts;
2025 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
2026 if (opts == NULL) {
2027 error_setg(&err, "Parsing chardev args failed");
2028 } else {
2029 qemu_chr_new_from_opts(opts, &err);
2030 qemu_opts_del(opts);
2032 hmp_handle_error(mon, &err);
2035 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2037 Error *local_err = NULL;
2039 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
2040 hmp_handle_error(mon, &local_err);
2043 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
2045 BlockBackend *blk;
2046 BlockBackend *local_blk = NULL;
2047 AioContext *aio_context;
2048 const char* device = qdict_get_str(qdict, "device");
2049 const char* command = qdict_get_str(qdict, "command");
2050 Error *err = NULL;
2051 int ret;
2053 blk = blk_by_name(device);
2054 if (!blk) {
2055 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
2056 if (bs) {
2057 blk = local_blk = blk_new(0, BLK_PERM_ALL);
2058 ret = blk_insert_bs(blk, bs, &err);
2059 if (ret < 0) {
2060 goto fail;
2062 } else {
2063 goto fail;
2067 aio_context = blk_get_aio_context(blk);
2068 aio_context_acquire(aio_context);
2071 * Notably absent: Proper permission management. This is sad, but it seems
2072 * almost impossible to achieve without changing the semantics and thereby
2073 * limiting the use cases of the qemu-io HMP command.
2075 * In an ideal world we would unconditionally create a new BlockBackend for
2076 * qemuio_command(), but we have commands like 'reopen' and want them to
2077 * take effect on the exact BlockBackend whose name the user passed instead
2078 * of just on a temporary copy of it.
2080 * Another problem is that deleting the temporary BlockBackend involves
2081 * draining all requests on it first, but some qemu-iotests cases want to
2082 * issue multiple aio_read/write requests and expect them to complete in
2083 * the background while the monitor has already returned.
2085 * This is also what prevents us from saving the original permissions and
2086 * restoring them later: We can't revoke permissions until all requests
2087 * have completed, and we don't know when that is nor can we really let
2088 * anything else run before we have revoken them to avoid race conditions.
2090 * What happens now is that command() in qemu-io-cmds.c can extend the
2091 * permissions if necessary for the qemu-io command. And they simply stay
2092 * extended, possibly resulting in a read-only guest device keeping write
2093 * permissions. Ugly, but it appears to be the lesser evil.
2095 qemuio_command(blk, command);
2097 aio_context_release(aio_context);
2099 fail:
2100 blk_unref(local_blk);
2101 hmp_handle_error(mon, &err);
2104 void hmp_object_del(Monitor *mon, const QDict *qdict)
2106 const char *id = qdict_get_str(qdict, "id");
2107 Error *err = NULL;
2109 user_creatable_del(id, &err);
2110 hmp_handle_error(mon, &err);
2113 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
2115 Error *err = NULL;
2116 MemdevList *memdev_list = qmp_query_memdev(&err);
2117 MemdevList *m = memdev_list;
2118 Visitor *v;
2119 char *str;
2121 while (m) {
2122 v = string_output_visitor_new(false, &str);
2123 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
2124 monitor_printf(mon, "memory backend: %s\n", m->value->id);
2125 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
2126 monitor_printf(mon, " merge: %s\n",
2127 m->value->merge ? "true" : "false");
2128 monitor_printf(mon, " dump: %s\n",
2129 m->value->dump ? "true" : "false");
2130 monitor_printf(mon, " prealloc: %s\n",
2131 m->value->prealloc ? "true" : "false");
2132 monitor_printf(mon, " policy: %s\n",
2133 HostMemPolicy_lookup[m->value->policy]);
2134 visit_complete(v, &str);
2135 monitor_printf(mon, " host nodes: %s\n", str);
2137 g_free(str);
2138 visit_free(v);
2139 m = m->next;
2142 monitor_printf(mon, "\n");
2144 qapi_free_MemdevList(memdev_list);
2147 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2149 Error *err = NULL;
2150 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2151 MemoryDeviceInfoList *info;
2152 MemoryDeviceInfo *value;
2153 PCDIMMDeviceInfo *di;
2155 for (info = info_list; info; info = info->next) {
2156 value = info->value;
2158 if (value) {
2159 switch (value->type) {
2160 case MEMORY_DEVICE_INFO_KIND_DIMM:
2161 di = value->u.dimm.data;
2163 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2164 MemoryDeviceInfoKind_lookup[value->type],
2165 di->id ? di->id : "");
2166 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2167 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2168 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2169 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2170 monitor_printf(mon, " memdev: %s\n", di->memdev);
2171 monitor_printf(mon, " hotplugged: %s\n",
2172 di->hotplugged ? "true" : "false");
2173 monitor_printf(mon, " hotpluggable: %s\n",
2174 di->hotpluggable ? "true" : "false");
2175 break;
2176 default:
2177 break;
2182 qapi_free_MemoryDeviceInfoList(info_list);
2185 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2187 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2188 IOThreadInfoList *info;
2189 IOThreadInfo *value;
2191 for (info = info_list; info; info = info->next) {
2192 value = info->value;
2193 monitor_printf(mon, "%s:\n", value->id);
2194 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
2195 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2196 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
2197 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
2200 qapi_free_IOThreadInfoList(info_list);
2203 void hmp_qom_list(Monitor *mon, const QDict *qdict)
2205 const char *path = qdict_get_try_str(qdict, "path");
2206 ObjectPropertyInfoList *list;
2207 Error *err = NULL;
2209 if (path == NULL) {
2210 monitor_printf(mon, "/\n");
2211 return;
2214 list = qmp_qom_list(path, &err);
2215 if (err == NULL) {
2216 ObjectPropertyInfoList *start = list;
2217 while (list != NULL) {
2218 ObjectPropertyInfo *value = list->value;
2220 monitor_printf(mon, "%s (%s)\n",
2221 value->name, value->type);
2222 list = list->next;
2224 qapi_free_ObjectPropertyInfoList(start);
2226 hmp_handle_error(mon, &err);
2229 void hmp_qom_set(Monitor *mon, const QDict *qdict)
2231 const char *path = qdict_get_str(qdict, "path");
2232 const char *property = qdict_get_str(qdict, "property");
2233 const char *value = qdict_get_str(qdict, "value");
2234 Error *err = NULL;
2235 bool ambiguous = false;
2236 Object *obj;
2238 obj = object_resolve_path(path, &ambiguous);
2239 if (obj == NULL) {
2240 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2241 "Device '%s' not found", path);
2242 } else {
2243 if (ambiguous) {
2244 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2246 object_property_parse(obj, value, property, &err);
2248 hmp_handle_error(mon, &err);
2251 void hmp_rocker(Monitor *mon, const QDict *qdict)
2253 const char *name = qdict_get_str(qdict, "name");
2254 RockerSwitch *rocker;
2255 Error *err = NULL;
2257 rocker = qmp_query_rocker(name, &err);
2258 if (err != NULL) {
2259 hmp_handle_error(mon, &err);
2260 return;
2263 monitor_printf(mon, "name: %s\n", rocker->name);
2264 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2265 monitor_printf(mon, "ports: %d\n", rocker->ports);
2267 qapi_free_RockerSwitch(rocker);
2270 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2272 RockerPortList *list, *port;
2273 const char *name = qdict_get_str(qdict, "name");
2274 Error *err = NULL;
2276 list = qmp_query_rocker_ports(name, &err);
2277 if (err != NULL) {
2278 hmp_handle_error(mon, &err);
2279 return;
2282 monitor_printf(mon, " ena/ speed/ auto\n");
2283 monitor_printf(mon, " port link duplex neg?\n");
2285 for (port = list; port; port = port->next) {
2286 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2287 port->value->name,
2288 port->value->enabled ? port->value->link_up ?
2289 "up" : "down" : "!ena",
2290 port->value->speed == 10000 ? "10G" : "??",
2291 port->value->duplex ? "FD" : "HD",
2292 port->value->autoneg ? "Yes" : "No");
2295 qapi_free_RockerPortList(list);
2298 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2300 RockerOfDpaFlowList *list, *info;
2301 const char *name = qdict_get_str(qdict, "name");
2302 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
2303 Error *err = NULL;
2305 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2306 if (err != NULL) {
2307 hmp_handle_error(mon, &err);
2308 return;
2311 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2313 for (info = list; info; info = info->next) {
2314 RockerOfDpaFlow *flow = info->value;
2315 RockerOfDpaFlowKey *key = flow->key;
2316 RockerOfDpaFlowMask *mask = flow->mask;
2317 RockerOfDpaFlowAction *action = flow->action;
2319 if (flow->hits) {
2320 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2321 key->priority, key->tbl_id, flow->hits);
2322 } else {
2323 monitor_printf(mon, "%-4d %-3d ",
2324 key->priority, key->tbl_id);
2327 if (key->has_in_pport) {
2328 monitor_printf(mon, " pport %d", key->in_pport);
2329 if (mask->has_in_pport) {
2330 monitor_printf(mon, "(0x%x)", mask->in_pport);
2334 if (key->has_vlan_id) {
2335 monitor_printf(mon, " vlan %d",
2336 key->vlan_id & VLAN_VID_MASK);
2337 if (mask->has_vlan_id) {
2338 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2342 if (key->has_tunnel_id) {
2343 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2344 if (mask->has_tunnel_id) {
2345 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2349 if (key->has_eth_type) {
2350 switch (key->eth_type) {
2351 case 0x0806:
2352 monitor_printf(mon, " ARP");
2353 break;
2354 case 0x0800:
2355 monitor_printf(mon, " IP");
2356 break;
2357 case 0x86dd:
2358 monitor_printf(mon, " IPv6");
2359 break;
2360 case 0x8809:
2361 monitor_printf(mon, " LACP");
2362 break;
2363 case 0x88cc:
2364 monitor_printf(mon, " LLDP");
2365 break;
2366 default:
2367 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2368 break;
2372 if (key->has_eth_src) {
2373 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2374 (mask->has_eth_src) &&
2375 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2376 monitor_printf(mon, " src <any mcast/bcast>");
2377 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2378 (mask->has_eth_src) &&
2379 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2380 monitor_printf(mon, " src <any ucast>");
2381 } else {
2382 monitor_printf(mon, " src %s", key->eth_src);
2383 if (mask->has_eth_src) {
2384 monitor_printf(mon, "(%s)", mask->eth_src);
2389 if (key->has_eth_dst) {
2390 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2391 (mask->has_eth_dst) &&
2392 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2393 monitor_printf(mon, " dst <any mcast/bcast>");
2394 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2395 (mask->has_eth_dst) &&
2396 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2397 monitor_printf(mon, " dst <any ucast>");
2398 } else {
2399 monitor_printf(mon, " dst %s", key->eth_dst);
2400 if (mask->has_eth_dst) {
2401 monitor_printf(mon, "(%s)", mask->eth_dst);
2406 if (key->has_ip_proto) {
2407 monitor_printf(mon, " proto %d", key->ip_proto);
2408 if (mask->has_ip_proto) {
2409 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2413 if (key->has_ip_tos) {
2414 monitor_printf(mon, " TOS %d", key->ip_tos);
2415 if (mask->has_ip_tos) {
2416 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2420 if (key->has_ip_dst) {
2421 monitor_printf(mon, " dst %s", key->ip_dst);
2424 if (action->has_goto_tbl || action->has_group_id ||
2425 action->has_new_vlan_id) {
2426 monitor_printf(mon, " -->");
2429 if (action->has_new_vlan_id) {
2430 monitor_printf(mon, " apply new vlan %d",
2431 ntohs(action->new_vlan_id));
2434 if (action->has_group_id) {
2435 monitor_printf(mon, " write group 0x%08x", action->group_id);
2438 if (action->has_goto_tbl) {
2439 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2442 monitor_printf(mon, "\n");
2445 qapi_free_RockerOfDpaFlowList(list);
2448 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2450 RockerOfDpaGroupList *list, *g;
2451 const char *name = qdict_get_str(qdict, "name");
2452 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2453 Error *err = NULL;
2454 bool set = false;
2456 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2457 if (err != NULL) {
2458 hmp_handle_error(mon, &err);
2459 return;
2462 monitor_printf(mon, "id (decode) --> buckets\n");
2464 for (g = list; g; g = g->next) {
2465 RockerOfDpaGroup *group = g->value;
2467 monitor_printf(mon, "0x%08x", group->id);
2469 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2470 group->type == 1 ? "L2 rewrite" :
2471 group->type == 2 ? "L3 unicast" :
2472 group->type == 3 ? "L2 multicast" :
2473 group->type == 4 ? "L2 flood" :
2474 group->type == 5 ? "L3 interface" :
2475 group->type == 6 ? "L3 multicast" :
2476 group->type == 7 ? "L3 ECMP" :
2477 group->type == 8 ? "L2 overlay" :
2478 "unknown");
2480 if (group->has_vlan_id) {
2481 monitor_printf(mon, " vlan %d", group->vlan_id);
2484 if (group->has_pport) {
2485 monitor_printf(mon, " pport %d", group->pport);
2488 if (group->has_index) {
2489 monitor_printf(mon, " index %d", group->index);
2492 monitor_printf(mon, ") -->");
2494 if (group->has_set_vlan_id && group->set_vlan_id) {
2495 set = true;
2496 monitor_printf(mon, " set vlan %d",
2497 group->set_vlan_id & VLAN_VID_MASK);
2500 if (group->has_set_eth_src) {
2501 if (!set) {
2502 set = true;
2503 monitor_printf(mon, " set");
2505 monitor_printf(mon, " src %s", group->set_eth_src);
2508 if (group->has_set_eth_dst) {
2509 if (!set) {
2510 set = true;
2511 monitor_printf(mon, " set");
2513 monitor_printf(mon, " dst %s", group->set_eth_dst);
2516 set = false;
2518 if (group->has_ttl_check && group->ttl_check) {
2519 monitor_printf(mon, " check TTL");
2522 if (group->has_group_id && group->group_id) {
2523 monitor_printf(mon, " group id 0x%08x", group->group_id);
2526 if (group->has_pop_vlan && group->pop_vlan) {
2527 monitor_printf(mon, " pop vlan");
2530 if (group->has_out_pport) {
2531 monitor_printf(mon, " out pport %d", group->out_pport);
2534 if (group->has_group_ids) {
2535 struct uint32List *id;
2537 monitor_printf(mon, " groups [");
2538 for (id = group->group_ids; id; id = id->next) {
2539 monitor_printf(mon, "0x%08x", id->value);
2540 if (id->next) {
2541 monitor_printf(mon, ",");
2544 monitor_printf(mon, "]");
2547 monitor_printf(mon, "\n");
2550 qapi_free_RockerOfDpaGroupList(list);
2553 void hmp_info_dump(Monitor *mon, const QDict *qdict)
2555 DumpQueryResult *result = qmp_query_dump(NULL);
2557 assert(result && result->status < DUMP_STATUS__MAX);
2558 monitor_printf(mon, "Status: %s\n", DumpStatus_lookup[result->status]);
2560 if (result->status == DUMP_STATUS_ACTIVE) {
2561 float percent = 0;
2562 assert(result->total != 0);
2563 percent = 100.0 * result->completed / result->total;
2564 monitor_printf(mon, "Finished: %.2f %%\n", percent);
2567 qapi_free_DumpQueryResult(result);
2570 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
2572 Error *err = NULL;
2573 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
2574 HotpluggableCPUList *saved = l;
2575 CpuInstanceProperties *c;
2577 if (err != NULL) {
2578 hmp_handle_error(mon, &err);
2579 return;
2582 monitor_printf(mon, "Hotpluggable CPUs:\n");
2583 while (l) {
2584 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
2585 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
2586 l->value->vcpus_count);
2587 if (l->value->has_qom_path) {
2588 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
2591 c = l->value->props;
2592 monitor_printf(mon, " CPUInstance Properties:\n");
2593 if (c->has_node_id) {
2594 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
2596 if (c->has_socket_id) {
2597 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
2599 if (c->has_core_id) {
2600 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
2602 if (c->has_thread_id) {
2603 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
2606 l = l->next;
2609 qapi_free_HotpluggableCPUList(saved);
2612 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
2614 Error *err = NULL;
2615 GuidInfo *info = qmp_query_vm_generation_id(&err);
2616 if (info) {
2617 monitor_printf(mon, "%s\n", info->guid);
2619 hmp_handle_error(mon, &err);
2620 qapi_free_GuidInfo(info);