2 * Human Monitor Interface
4 * Copyright IBM, Corp. 2011
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.
19 #include "sysemu/char.h"
20 #include "sysemu/block-backend.h"
21 #include "qemu/option.h"
22 #include "qemu/timer.h"
23 #include "qmp-commands.h"
24 #include "qemu/sockets.h"
25 #include "monitor/monitor.h"
26 #include "monitor/qdev.h"
27 #include "qapi/opts-visitor.h"
28 #include "qapi/qmp/qerror.h"
29 #include "qapi/string-output-visitor.h"
30 #include "qapi-visit.h"
31 #include "ui/console.h"
32 #include "block/qapi.h"
36 #include <spice/enums.h>
39 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
43 monitor_printf(mon
, "%s\n", error_get_pretty(*errp
));
48 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
52 info
= qmp_query_name(NULL
);
54 monitor_printf(mon
, "%s\n", info
->name
);
56 qapi_free_NameInfo(info
);
59 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
63 info
= qmp_query_version(NULL
);
65 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
66 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
69 qapi_free_VersionInfo(info
);
72 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
76 info
= qmp_query_kvm(NULL
);
77 monitor_printf(mon
, "kvm support: ");
79 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
81 monitor_printf(mon
, "not compiled\n");
84 qapi_free_KvmInfo(info
);
87 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
91 info
= qmp_query_status(NULL
);
93 monitor_printf(mon
, "VM status: %s%s",
94 info
->running
? "running" : "paused",
95 info
->singlestep
? " (single step mode)" : "");
97 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
98 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
101 monitor_printf(mon
, "\n");
103 qapi_free_StatusInfo(info
);
106 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
110 info
= qmp_query_uuid(NULL
);
111 monitor_printf(mon
, "%s\n", info
->UUID
);
112 qapi_free_UuidInfo(info
);
115 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
117 ChardevInfoList
*char_info
, *info
;
119 char_info
= qmp_query_chardev(NULL
);
120 for (info
= char_info
; info
; info
= info
->next
) {
121 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
122 info
->value
->filename
);
125 qapi_free_ChardevInfoList(char_info
);
128 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
130 MouseInfoList
*mice_list
, *mouse
;
132 mice_list
= qmp_query_mice(NULL
);
134 monitor_printf(mon
, "No mouse devices connected\n");
138 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
139 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
140 mouse
->value
->current
? '*' : ' ',
141 mouse
->value
->index
, mouse
->value
->name
,
142 mouse
->value
->absolute
? " (absolute)" : "");
145 qapi_free_MouseInfoList(mice_list
);
148 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
151 MigrationCapabilityStatusList
*caps
, *cap
;
153 info
= qmp_query_migrate(NULL
);
154 caps
= qmp_query_migrate_capabilities(NULL
);
156 /* do not display parameters during setup */
157 if (info
->has_status
&& caps
) {
158 monitor_printf(mon
, "capabilities: ");
159 for (cap
= caps
; cap
; cap
= cap
->next
) {
160 monitor_printf(mon
, "%s: %s ",
161 MigrationCapability_lookup
[cap
->value
->capability
],
162 cap
->value
->state
? "on" : "off");
164 monitor_printf(mon
, "\n");
167 if (info
->has_status
) {
168 monitor_printf(mon
, "Migration status: %s\n",
169 MigrationStatus_lookup
[info
->status
]);
170 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
172 if (info
->has_expected_downtime
) {
173 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
174 info
->expected_downtime
);
176 if (info
->has_downtime
) {
177 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
180 if (info
->has_setup_time
) {
181 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
187 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
188 info
->ram
->transferred
>> 10);
189 monitor_printf(mon
, "throughput: %0.2f mbps\n",
191 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
192 info
->ram
->remaining
>> 10);
193 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
194 info
->ram
->total
>> 10);
195 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
196 info
->ram
->duplicate
);
197 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
199 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
201 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
202 info
->ram
->normal_bytes
>> 10);
203 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
204 info
->ram
->dirty_sync_count
);
205 if (info
->ram
->dirty_pages_rate
) {
206 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
207 info
->ram
->dirty_pages_rate
);
211 if (info
->has_disk
) {
212 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
213 info
->disk
->transferred
>> 10);
214 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
215 info
->disk
->remaining
>> 10);
216 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
217 info
->disk
->total
>> 10);
220 if (info
->has_xbzrle_cache
) {
221 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
222 info
->xbzrle_cache
->cache_size
);
223 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
224 info
->xbzrle_cache
->bytes
>> 10);
225 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
226 info
->xbzrle_cache
->pages
);
227 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
228 info
->xbzrle_cache
->cache_miss
);
229 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
230 info
->xbzrle_cache
->cache_miss_rate
);
231 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
232 info
->xbzrle_cache
->overflow
);
235 qapi_free_MigrationInfo(info
);
236 qapi_free_MigrationCapabilityStatusList(caps
);
239 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
241 MigrationCapabilityStatusList
*caps
, *cap
;
243 caps
= qmp_query_migrate_capabilities(NULL
);
246 monitor_printf(mon
, "capabilities: ");
247 for (cap
= caps
; cap
; cap
= cap
->next
) {
248 monitor_printf(mon
, "%s: %s ",
249 MigrationCapability_lookup
[cap
->value
->capability
],
250 cap
->value
->state
? "on" : "off");
252 monitor_printf(mon
, "\n");
255 qapi_free_MigrationCapabilityStatusList(caps
);
258 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
260 MigrationParameters
*params
;
262 params
= qmp_query_migrate_parameters(NULL
);
265 monitor_printf(mon
, "parameters:");
266 monitor_printf(mon
, " %s: %" PRId64
,
267 MigrationParameter_lookup
[MIGRATION_PARAMETER_COMPRESS_LEVEL
],
268 params
->compress_level
);
269 monitor_printf(mon
, " %s: %" PRId64
,
270 MigrationParameter_lookup
[MIGRATION_PARAMETER_COMPRESS_THREADS
],
271 params
->compress_threads
);
272 monitor_printf(mon
, " %s: %" PRId64
,
273 MigrationParameter_lookup
[MIGRATION_PARAMETER_DECOMPRESS_THREADS
],
274 params
->decompress_threads
);
275 monitor_printf(mon
, "\n");
278 qapi_free_MigrationParameters(params
);
281 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
283 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
284 qmp_query_migrate_cache_size(NULL
) >> 10);
287 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
289 CpuInfoList
*cpu_list
, *cpu
;
291 cpu_list
= qmp_query_cpus(NULL
);
293 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
296 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
300 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
302 if (cpu
->value
->has_pc
) {
303 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->pc
);
305 if (cpu
->value
->has_nip
) {
306 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->nip
);
308 if (cpu
->value
->has_npc
) {
309 monitor_printf(mon
, " npc=0x%016" PRIx64
, cpu
->value
->npc
);
311 if (cpu
->value
->has_PC
) {
312 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->PC
);
315 if (cpu
->value
->halted
) {
316 monitor_printf(mon
, " (halted)");
319 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
322 qapi_free_CpuInfoList(cpu_list
);
325 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
326 BlockDeviceInfo
*inserted
, bool verbose
)
328 ImageInfo
*image_info
;
330 assert(!info
|| !info
->has_inserted
|| info
->inserted
== inserted
);
333 monitor_printf(mon
, "%s", info
->device
);
334 if (inserted
&& inserted
->has_node_name
) {
335 monitor_printf(mon
, " (%s)", inserted
->node_name
);
339 monitor_printf(mon
, "%s",
340 inserted
->has_node_name
341 ? inserted
->node_name
346 monitor_printf(mon
, ": %s (%s%s%s)\n",
349 inserted
->ro
? ", read-only" : "",
350 inserted
->encrypted
? ", encrypted" : "");
352 monitor_printf(mon
, ": [not inserted]\n");
356 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
357 monitor_printf(mon
, " I/O status: %s\n",
358 BlockDeviceIoStatus_lookup
[info
->io_status
]);
361 if (info
->removable
) {
362 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
363 info
->locked
? "" : "not ",
364 info
->tray_open
? "open" : "closed");
373 monitor_printf(mon
, " Cache mode: %s%s%s\n",
374 inserted
->cache
->writeback
? "writeback" : "writethrough",
375 inserted
->cache
->direct
? ", direct" : "",
376 inserted
->cache
->no_flush
? ", ignore flushes" : "");
378 if (inserted
->has_backing_file
) {
381 "(chain depth: %" PRId64
")\n",
382 inserted
->backing_file
,
383 inserted
->backing_file_depth
);
386 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
387 monitor_printf(mon
, " Detect zeroes: %s\n",
388 BlockdevDetectZeroesOptions_lookup
[inserted
->detect_zeroes
]);
391 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
392 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
394 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
395 " bps_rd=%" PRId64
" bps_wr=%" PRId64
397 " bps_rd_max=%" PRId64
398 " bps_wr_max=%" PRId64
399 " iops=%" PRId64
" iops_rd=%" PRId64
402 " iops_rd_max=%" PRId64
403 " iops_wr_max=%" PRId64
404 " iops_size=%" PRId64
410 inserted
->bps_rd_max
,
411 inserted
->bps_wr_max
,
416 inserted
->iops_rd_max
,
417 inserted
->iops_wr_max
,
423 monitor_printf(mon
, "\nImages:\n");
424 image_info
= inserted
->image
;
426 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
428 if (image_info
->has_backing_image
) {
429 image_info
= image_info
->backing_image
;
437 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
439 BlockInfoList
*block_list
, *info
;
440 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
441 const char *device
= qdict_get_try_str(qdict
, "device");
442 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
443 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
444 bool printed
= false;
446 /* Print BlockBackend information */
448 block_list
= qmp_query_block(NULL
);
453 for (info
= block_list
; info
; info
= info
->next
) {
454 if (device
&& strcmp(device
, info
->value
->device
)) {
458 if (info
!= block_list
) {
459 monitor_printf(mon
, "\n");
462 print_block_info(mon
, info
->value
, info
->value
->has_inserted
463 ? info
->value
->inserted
: NULL
,
468 qapi_free_BlockInfoList(block_list
);
470 if ((!device
&& !nodes
) || printed
) {
474 /* Print node information */
475 blockdev_list
= qmp_query_named_block_nodes(NULL
);
476 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
477 assert(blockdev
->value
->has_node_name
);
478 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
482 if (blockdev
!= blockdev_list
) {
483 monitor_printf(mon
, "\n");
486 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
488 qapi_free_BlockDeviceInfoList(blockdev_list
);
491 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
493 BlockStatsList
*stats_list
, *stats
;
495 stats_list
= qmp_query_blockstats(false, false, NULL
);
497 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
498 if (!stats
->value
->has_device
) {
502 monitor_printf(mon
, "%s:", stats
->value
->device
);
503 monitor_printf(mon
, " rd_bytes=%" PRId64
505 " rd_operations=%" PRId64
506 " wr_operations=%" PRId64
507 " flush_operations=%" PRId64
508 " wr_total_time_ns=%" PRId64
509 " rd_total_time_ns=%" PRId64
510 " flush_total_time_ns=%" PRId64
511 " rd_merged=%" PRId64
512 " wr_merged=%" PRId64
514 stats
->value
->stats
->rd_bytes
,
515 stats
->value
->stats
->wr_bytes
,
516 stats
->value
->stats
->rd_operations
,
517 stats
->value
->stats
->wr_operations
,
518 stats
->value
->stats
->flush_operations
,
519 stats
->value
->stats
->wr_total_time_ns
,
520 stats
->value
->stats
->rd_total_time_ns
,
521 stats
->value
->stats
->flush_total_time_ns
,
522 stats
->value
->stats
->rd_merged
,
523 stats
->value
->stats
->wr_merged
);
526 qapi_free_BlockStatsList(stats_list
);
529 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
533 VncClientInfoList
*client
;
535 info
= qmp_query_vnc(&err
);
537 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
542 if (!info
->enabled
) {
543 monitor_printf(mon
, "Server: disabled\n");
547 monitor_printf(mon
, "Server:\n");
548 if (info
->has_host
&& info
->has_service
) {
549 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
551 if (info
->has_auth
) {
552 monitor_printf(mon
, " auth: %s\n", info
->auth
);
555 if (!info
->has_clients
|| info
->clients
== NULL
) {
556 monitor_printf(mon
, "Client: none\n");
558 for (client
= info
->clients
; client
; client
= client
->next
) {
559 monitor_printf(mon
, "Client:\n");
560 monitor_printf(mon
, " address: %s:%s\n",
561 client
->value
->base
->host
,
562 client
->value
->base
->service
);
563 monitor_printf(mon
, " x509_dname: %s\n",
564 client
->value
->x509_dname
?
565 client
->value
->x509_dname
: "none");
566 monitor_printf(mon
, " username: %s\n",
567 client
->value
->has_sasl_username
?
568 client
->value
->sasl_username
: "none");
573 qapi_free_VncInfo(info
);
577 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
579 SpiceChannelList
*chan
;
581 const char *channel_name
;
582 const char * const channel_names
[] = {
583 [SPICE_CHANNEL_MAIN
] = "main",
584 [SPICE_CHANNEL_DISPLAY
] = "display",
585 [SPICE_CHANNEL_INPUTS
] = "inputs",
586 [SPICE_CHANNEL_CURSOR
] = "cursor",
587 [SPICE_CHANNEL_PLAYBACK
] = "playback",
588 [SPICE_CHANNEL_RECORD
] = "record",
589 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
590 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
591 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
592 [SPICE_CHANNEL_PORT
] = "port",
594 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
595 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
596 * as quick fix for build failures with older versions. */
597 [SPICE_CHANNEL_WEBDAV
] = "webdav",
601 info
= qmp_query_spice(NULL
);
603 if (!info
->enabled
) {
604 monitor_printf(mon
, "Server: disabled\n");
608 monitor_printf(mon
, "Server:\n");
609 if (info
->has_port
) {
610 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
611 info
->host
, info
->port
);
613 if (info
->has_tls_port
) {
614 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
615 info
->host
, info
->tls_port
);
617 monitor_printf(mon
, " migrated: %s\n",
618 info
->migrated
? "true" : "false");
619 monitor_printf(mon
, " auth: %s\n", info
->auth
);
620 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
621 monitor_printf(mon
, " mouse-mode: %s\n",
622 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
624 if (!info
->has_channels
|| info
->channels
== NULL
) {
625 monitor_printf(mon
, "Channels: none\n");
627 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
628 monitor_printf(mon
, "Channel:\n");
629 monitor_printf(mon
, " address: %s:%s%s\n",
630 chan
->value
->base
->host
, chan
->value
->base
->port
,
631 chan
->value
->tls
? " [tls]" : "");
632 monitor_printf(mon
, " session: %" PRId64
"\n",
633 chan
->value
->connection_id
);
634 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
635 chan
->value
->channel_type
, chan
->value
->channel_id
);
637 channel_name
= "unknown";
638 if (chan
->value
->channel_type
> 0 &&
639 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
640 channel_names
[chan
->value
->channel_type
]) {
641 channel_name
= channel_names
[chan
->value
->channel_type
];
644 monitor_printf(mon
, " channel name: %s\n", channel_name
);
649 qapi_free_SpiceInfo(info
);
653 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
658 info
= qmp_query_balloon(&err
);
660 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
665 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
667 qapi_free_BalloonInfo(info
);
670 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
672 PciMemoryRegionList
*region
;
674 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
675 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
676 dev
->slot
, dev
->function
);
677 monitor_printf(mon
, " ");
679 if (dev
->class_info
->has_desc
) {
680 monitor_printf(mon
, "%s", dev
->class_info
->desc
);
682 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
685 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
686 dev
->id
->vendor
, dev
->id
->device
);
689 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
692 if (dev
->has_pci_bridge
) {
693 monitor_printf(mon
, " BUS %" PRId64
".\n",
694 dev
->pci_bridge
->bus
->number
);
695 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
696 dev
->pci_bridge
->bus
->secondary
);
697 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
698 dev
->pci_bridge
->bus
->subordinate
);
700 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
701 dev
->pci_bridge
->bus
->io_range
->base
,
702 dev
->pci_bridge
->bus
->io_range
->limit
);
705 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
706 dev
->pci_bridge
->bus
->memory_range
->base
,
707 dev
->pci_bridge
->bus
->memory_range
->limit
);
709 monitor_printf(mon
, " prefetchable memory range "
710 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
711 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
712 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
715 for (region
= dev
->regions
; region
; region
= region
->next
) {
718 addr
= region
->value
->address
;
719 size
= region
->value
->size
;
721 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
723 if (!strcmp(region
->value
->type
, "io")) {
724 monitor_printf(mon
, "I/O at 0x%04" PRIx64
725 " [0x%04" PRIx64
"].\n",
726 addr
, addr
+ size
- 1);
728 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
729 " [0x%08" PRIx64
"].\n",
730 region
->value
->mem_type_64
? 64 : 32,
731 region
->value
->prefetch
? " prefetchable" : "",
732 addr
, addr
+ size
- 1);
736 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
738 if (dev
->has_pci_bridge
) {
739 if (dev
->pci_bridge
->has_devices
) {
740 PciDeviceInfoList
*cdev
;
741 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
742 hmp_info_pci_device(mon
, cdev
->value
);
748 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
750 PciInfoList
*info_list
, *info
;
753 info_list
= qmp_query_pci(&err
);
755 monitor_printf(mon
, "PCI devices not supported\n");
760 for (info
= info_list
; info
; info
= info
->next
) {
761 PciDeviceInfoList
*dev
;
763 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
764 hmp_info_pci_device(mon
, dev
->value
);
768 qapi_free_PciInfoList(info_list
);
771 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
773 BlockJobInfoList
*list
;
776 list
= qmp_query_block_jobs(&err
);
780 monitor_printf(mon
, "No active jobs\n");
785 if (strcmp(list
->value
->type
, "stream") == 0) {
786 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
787 " of %" PRId64
" bytes, speed limit %" PRId64
794 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
795 " of %" PRId64
" bytes, speed limit %" PRId64
806 qapi_free_BlockJobInfoList(list
);
809 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
811 TPMInfoList
*info_list
, *info
;
814 TPMPassthroughOptions
*tpo
;
816 info_list
= qmp_query_tpm(&err
);
818 monitor_printf(mon
, "TPM device not supported\n");
824 monitor_printf(mon
, "TPM device:\n");
827 for (info
= info_list
; info
; info
= info
->next
) {
828 TPMInfo
*ti
= info
->value
;
829 monitor_printf(mon
, " tpm%d: model=%s\n",
830 c
, TpmModel_lookup
[ti
->model
]);
832 monitor_printf(mon
, " \\ %s: type=%s",
833 ti
->id
, TpmTypeOptionsKind_lookup
[ti
->options
->kind
]);
835 switch (ti
->options
->kind
) {
836 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
837 tpo
= ti
->options
->passthrough
;
838 monitor_printf(mon
, "%s%s%s%s",
839 tpo
->has_path
? ",path=" : "",
840 tpo
->has_path
? tpo
->path
: "",
841 tpo
->has_cancel_path
? ",cancel-path=" : "",
842 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
844 case TPM_TYPE_OPTIONS_KIND_MAX
:
847 monitor_printf(mon
, "\n");
850 qapi_free_TPMInfoList(info_list
);
853 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
855 monitor_suspend(mon
);
859 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
864 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
866 qmp_system_reset(NULL
);
869 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
871 qmp_system_powerdown(NULL
);
874 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
878 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
879 use it are converted to the QAPI */
880 cpu_index
= qdict_get_int(qdict
, "index");
881 if (monitor_set_cpu(cpu_index
) < 0) {
882 monitor_printf(mon
, "invalid CPU index\n");
886 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
888 uint32_t size
= qdict_get_int(qdict
, "size");
889 const char *filename
= qdict_get_str(qdict
, "filename");
890 uint64_t addr
= qdict_get_int(qdict
, "val");
893 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &err
);
894 hmp_handle_error(mon
, &err
);
897 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
899 uint32_t size
= qdict_get_int(qdict
, "size");
900 const char *filename
= qdict_get_str(qdict
, "filename");
901 uint64_t addr
= qdict_get_int(qdict
, "val");
904 qmp_pmemsave(addr
, size
, filename
, &err
);
905 hmp_handle_error(mon
, &err
);
908 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
910 const char *chardev
= qdict_get_str(qdict
, "device");
911 const char *data
= qdict_get_str(qdict
, "data");
914 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
916 hmp_handle_error(mon
, &err
);
919 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
921 uint32_t size
= qdict_get_int(qdict
, "size");
922 const char *chardev
= qdict_get_str(qdict
, "device");
927 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
929 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
934 for (i
= 0; data
[i
]; i
++) {
935 unsigned char ch
= data
[i
];
938 monitor_printf(mon
, "\\\\");
939 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
940 monitor_printf(mon
, "\\u%04X", ch
);
942 monitor_printf(mon
, "%c", ch
);
946 monitor_printf(mon
, "\n");
950 static void hmp_cont_cb(void *opaque
, int err
)
957 static bool key_is_missing(const BlockInfo
*bdev
)
959 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
962 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
964 BlockInfoList
*bdev_list
, *bdev
;
967 bdev_list
= qmp_query_block(NULL
);
968 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
969 if (key_is_missing(bdev
->value
)) {
970 monitor_read_block_device_key(mon
, bdev
->value
->device
,
977 hmp_handle_error(mon
, &err
);
980 qapi_free_BlockInfoList(bdev_list
);
983 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
985 qmp_system_wakeup(NULL
);
988 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
992 qmp_inject_nmi(&err
);
993 hmp_handle_error(mon
, &err
);
996 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
998 const char *name
= qdict_get_str(qdict
, "name");
999 bool up
= qdict_get_bool(qdict
, "up");
1002 qmp_set_link(name
, up
, &err
);
1003 hmp_handle_error(mon
, &err
);
1006 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
1008 const char *device
= qdict_get_str(qdict
, "device");
1009 const char *password
= qdict_get_str(qdict
, "password");
1012 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
1013 hmp_handle_error(mon
, &err
);
1016 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1018 int64_t value
= qdict_get_int(qdict
, "value");
1021 qmp_balloon(value
, &err
);
1023 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(err
));
1028 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
1030 const char *device
= qdict_get_str(qdict
, "device");
1031 int64_t size
= qdict_get_int(qdict
, "size");
1034 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
1035 hmp_handle_error(mon
, &err
);
1038 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
1040 const char *device
= qdict_get_str(qdict
, "device");
1041 const char *filename
= qdict_get_str(qdict
, "target");
1042 const char *format
= qdict_get_try_str(qdict
, "format");
1043 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1044 bool full
= qdict_get_try_bool(qdict
, "full", false);
1045 enum NewImageMode mode
;
1049 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1050 hmp_handle_error(mon
, &err
);
1055 mode
= NEW_IMAGE_MODE_EXISTING
;
1057 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1060 qmp_drive_mirror(device
, filename
, !!format
, format
,
1061 false, NULL
, false, NULL
,
1062 full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1063 true, mode
, false, 0, false, 0, false, 0,
1064 false, 0, false, 0, false, true, &err
);
1065 hmp_handle_error(mon
, &err
);
1068 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
1070 const char *device
= qdict_get_str(qdict
, "device");
1071 const char *filename
= qdict_get_str(qdict
, "target");
1072 const char *format
= qdict_get_try_str(qdict
, "format");
1073 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1074 bool full
= qdict_get_try_bool(qdict
, "full", false);
1075 enum NewImageMode mode
;
1079 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1080 hmp_handle_error(mon
, &err
);
1085 mode
= NEW_IMAGE_MODE_EXISTING
;
1087 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1090 qmp_drive_backup(device
, filename
, !!format
, format
,
1091 full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1092 true, mode
, false, 0, false, NULL
,
1093 false, 0, false, 0, &err
);
1094 hmp_handle_error(mon
, &err
);
1097 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
1099 const char *device
= qdict_get_str(qdict
, "device");
1100 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
1101 const char *format
= qdict_get_try_str(qdict
, "format");
1102 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1103 enum NewImageMode mode
;
1107 /* In the future, if 'snapshot-file' is not specified, the snapshot
1108 will be taken internally. Today it's actually required. */
1109 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
1110 hmp_handle_error(mon
, &err
);
1114 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1115 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
1116 filename
, false, NULL
,
1119 hmp_handle_error(mon
, &err
);
1122 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1124 const char *device
= qdict_get_str(qdict
, "device");
1125 const char *name
= qdict_get_str(qdict
, "name");
1128 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1129 hmp_handle_error(mon
, &err
);
1132 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1134 const char *device
= qdict_get_str(qdict
, "device");
1135 const char *name
= qdict_get_str(qdict
, "name");
1136 const char *id
= qdict_get_try_str(qdict
, "id");
1139 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1141 hmp_handle_error(mon
, &err
);
1144 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1146 qmp_migrate_cancel(NULL
);
1149 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1152 const char *uri
= qdict_get_str(qdict
, "uri");
1154 qmp_migrate_incoming(uri
, &err
);
1156 hmp_handle_error(mon
, &err
);
1159 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1161 double value
= qdict_get_double(qdict
, "value");
1162 qmp_migrate_set_downtime(value
, NULL
);
1165 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1167 int64_t value
= qdict_get_int(qdict
, "value");
1170 qmp_migrate_set_cache_size(value
, &err
);
1172 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
1178 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1180 int64_t value
= qdict_get_int(qdict
, "value");
1181 qmp_migrate_set_speed(value
, NULL
);
1184 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1186 const char *cap
= qdict_get_str(qdict
, "capability");
1187 bool state
= qdict_get_bool(qdict
, "state");
1189 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1192 for (i
= 0; i
< MIGRATION_CAPABILITY_MAX
; i
++) {
1193 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
1194 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1195 caps
->value
->capability
= i
;
1196 caps
->value
->state
= state
;
1198 qmp_migrate_set_capabilities(caps
, &err
);
1203 if (i
== MIGRATION_CAPABILITY_MAX
) {
1204 error_setg(&err
, QERR_INVALID_PARAMETER
, cap
);
1207 qapi_free_MigrationCapabilityStatusList(caps
);
1210 monitor_printf(mon
, "migrate_set_capability: %s\n",
1211 error_get_pretty(err
));
1216 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1218 const char *param
= qdict_get_str(qdict
, "parameter");
1219 int value
= qdict_get_int(qdict
, "value");
1221 bool has_compress_level
= false;
1222 bool has_compress_threads
= false;
1223 bool has_decompress_threads
= false;
1226 for (i
= 0; i
< MIGRATION_PARAMETER_MAX
; i
++) {
1227 if (strcmp(param
, MigrationParameter_lookup
[i
]) == 0) {
1229 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1230 has_compress_level
= true;
1232 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1233 has_compress_threads
= true;
1235 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1236 has_decompress_threads
= true;
1239 qmp_migrate_set_parameters(has_compress_level
, value
,
1240 has_compress_threads
, value
,
1241 has_decompress_threads
, value
,
1247 if (i
== MIGRATION_PARAMETER_MAX
) {
1248 error_setg(&err
, QERR_INVALID_PARAMETER
, param
);
1252 monitor_printf(mon
, "migrate_set_parameter: %s\n",
1253 error_get_pretty(err
));
1258 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1261 const char *protocol
= qdict_get_str(qdict
, "protocol");
1262 const char *hostname
= qdict_get_str(qdict
, "hostname");
1263 bool has_port
= qdict_haskey(qdict
, "port");
1264 int port
= qdict_get_try_int(qdict
, "port", -1);
1265 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1266 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1267 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1269 qmp_client_migrate_info(protocol
, hostname
,
1270 has_port
, port
, has_tls_port
, tls_port
,
1271 !!cert_subject
, cert_subject
, &err
);
1272 hmp_handle_error(mon
, &err
);
1275 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1277 const char *protocol
= qdict_get_str(qdict
, "protocol");
1278 const char *password
= qdict_get_str(qdict
, "password");
1279 const char *connected
= qdict_get_try_str(qdict
, "connected");
1282 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1283 hmp_handle_error(mon
, &err
);
1286 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1288 const char *protocol
= qdict_get_str(qdict
, "protocol");
1289 const char *whenstr
= qdict_get_str(qdict
, "time");
1292 qmp_expire_password(protocol
, whenstr
, &err
);
1293 hmp_handle_error(mon
, &err
);
1296 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1298 bool force
= qdict_get_try_bool(qdict
, "force", false);
1299 const char *device
= qdict_get_str(qdict
, "device");
1302 qmp_eject(device
, true, force
, &err
);
1303 hmp_handle_error(mon
, &err
);
1306 static void hmp_change_read_arg(void *opaque
, const char *password
,
1307 void *readline_opaque
)
1309 qmp_change_vnc_password(password
, NULL
);
1310 monitor_read_command(opaque
, 1);
1313 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1315 const char *device
= qdict_get_str(qdict
, "device");
1316 const char *target
= qdict_get_str(qdict
, "target");
1317 const char *arg
= qdict_get_try_str(qdict
, "arg");
1320 if (strcmp(device
, "vnc") == 0 &&
1321 (strcmp(target
, "passwd") == 0 ||
1322 strcmp(target
, "password") == 0)) {
1324 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1329 qmp_change(device
, target
, !!arg
, arg
, &err
);
1331 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
1333 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
1336 hmp_handle_error(mon
, &err
);
1339 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1343 qmp_block_set_io_throttle(qdict_get_str(qdict
, "device"),
1344 qdict_get_int(qdict
, "bps"),
1345 qdict_get_int(qdict
, "bps_rd"),
1346 qdict_get_int(qdict
, "bps_wr"),
1347 qdict_get_int(qdict
, "iops"),
1348 qdict_get_int(qdict
, "iops_rd"),
1349 qdict_get_int(qdict
, "iops_wr"),
1350 false, /* no burst max via HMP */
1362 false, /* No default I/O size */
1366 hmp_handle_error(mon
, &err
);
1369 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1371 Error
*error
= NULL
;
1372 const char *device
= qdict_get_str(qdict
, "device");
1373 const char *base
= qdict_get_try_str(qdict
, "base");
1374 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1376 qmp_block_stream(device
, base
!= NULL
, base
, false, NULL
,
1377 qdict_haskey(qdict
, "speed"), speed
,
1378 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1380 hmp_handle_error(mon
, &error
);
1383 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1385 Error
*error
= NULL
;
1386 const char *device
= qdict_get_str(qdict
, "device");
1387 int64_t value
= qdict_get_int(qdict
, "speed");
1389 qmp_block_job_set_speed(device
, value
, &error
);
1391 hmp_handle_error(mon
, &error
);
1394 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1396 Error
*error
= NULL
;
1397 const char *device
= qdict_get_str(qdict
, "device");
1398 bool force
= qdict_get_try_bool(qdict
, "force", false);
1400 qmp_block_job_cancel(device
, true, force
, &error
);
1402 hmp_handle_error(mon
, &error
);
1405 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1407 Error
*error
= NULL
;
1408 const char *device
= qdict_get_str(qdict
, "device");
1410 qmp_block_job_pause(device
, &error
);
1412 hmp_handle_error(mon
, &error
);
1415 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1417 Error
*error
= NULL
;
1418 const char *device
= qdict_get_str(qdict
, "device");
1420 qmp_block_job_resume(device
, &error
);
1422 hmp_handle_error(mon
, &error
);
1425 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1427 Error
*error
= NULL
;
1428 const char *device
= qdict_get_str(qdict
, "device");
1430 qmp_block_job_complete(device
, &error
);
1432 hmp_handle_error(mon
, &error
);
1435 typedef struct HMPMigrationStatus
1439 bool is_block_migration
;
1440 } HMPMigrationStatus
;
1442 static void hmp_migrate_status_cb(void *opaque
)
1444 HMPMigrationStatus
*status
= opaque
;
1445 MigrationInfo
*info
;
1447 info
= qmp_query_migrate(NULL
);
1448 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1449 info
->status
== MIGRATION_STATUS_SETUP
) {
1450 if (info
->has_disk
) {
1453 if (info
->disk
->remaining
) {
1454 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1459 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1460 monitor_flush(status
->mon
);
1463 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1465 if (status
->is_block_migration
) {
1466 monitor_printf(status
->mon
, "\n");
1468 monitor_resume(status
->mon
);
1469 timer_del(status
->timer
);
1473 qapi_free_MigrationInfo(info
);
1476 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1478 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1479 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1480 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1481 const char *uri
= qdict_get_str(qdict
, "uri");
1484 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1486 monitor_printf(mon
, "migrate: %s\n", error_get_pretty(err
));
1492 HMPMigrationStatus
*status
;
1494 if (monitor_suspend(mon
) < 0) {
1495 monitor_printf(mon
, "terminal does not allow synchronous "
1496 "migration, continuing detached\n");
1500 status
= g_malloc0(sizeof(*status
));
1502 status
->is_block_migration
= blk
|| inc
;
1503 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1505 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1509 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
1513 qmp_device_add((QDict
*)qdict
, NULL
, &err
);
1514 hmp_handle_error(mon
, &err
);
1517 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1519 const char *id
= qdict_get_str(qdict
, "id");
1522 qmp_device_del(id
, &err
);
1523 hmp_handle_error(mon
, &err
);
1526 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1529 bool paging
= qdict_get_try_bool(qdict
, "paging", false);
1530 bool zlib
= qdict_get_try_bool(qdict
, "zlib", false);
1531 bool lzo
= qdict_get_try_bool(qdict
, "lzo", false);
1532 bool snappy
= qdict_get_try_bool(qdict
, "snappy", false);
1533 const char *file
= qdict_get_str(qdict
, "filename");
1534 bool has_begin
= qdict_haskey(qdict
, "begin");
1535 bool has_length
= qdict_haskey(qdict
, "length");
1538 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1541 if (zlib
+ lzo
+ snappy
> 1) {
1542 error_setg(&err
, "only one of '-z|-l|-s' can be set");
1543 hmp_handle_error(mon
, &err
);
1548 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
1552 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
1556 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
1560 begin
= qdict_get_int(qdict
, "begin");
1563 length
= qdict_get_int(qdict
, "length");
1566 prot
= g_strconcat("file:", file
, NULL
);
1568 qmp_dump_guest_memory(paging
, prot
, has_begin
, begin
, has_length
, length
,
1569 true, dump_format
, &err
);
1570 hmp_handle_error(mon
, &err
);
1574 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1579 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1584 netdev_add(opts
, &err
);
1586 qemu_opts_del(opts
);
1590 hmp_handle_error(mon
, &err
);
1593 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1595 const char *id
= qdict_get_str(qdict
, "id");
1598 qmp_netdev_del(id
, &err
);
1599 hmp_handle_error(mon
, &err
);
1602 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
1605 Error
*err_end
= NULL
;
1613 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
1618 ov
= opts_visitor_new(opts
);
1619 pdict
= qdict_clone_shallow(qdict
);
1621 visit_start_struct(opts_get_visitor(ov
), &dummy
, NULL
, NULL
, 0, &err
);
1626 qdict_del(pdict
, "qom-type");
1627 visit_type_str(opts_get_visitor(ov
), &type
, "qom-type", &err
);
1632 qdict_del(pdict
, "id");
1633 visit_type_str(opts_get_visitor(ov
), &id
, "id", &err
);
1638 object_add(type
, id
, pdict
, opts_get_visitor(ov
), &err
);
1641 visit_end_struct(opts_get_visitor(ov
), &err_end
);
1642 if (!err
&& err_end
) {
1643 qmp_object_del(id
, NULL
);
1645 error_propagate(&err
, err_end
);
1647 opts_visitor_cleanup(ov
);
1650 qemu_opts_del(opts
);
1656 hmp_handle_error(mon
, &err
);
1659 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1661 const char *fdname
= qdict_get_str(qdict
, "fdname");
1664 qmp_getfd(fdname
, &err
);
1665 hmp_handle_error(mon
, &err
);
1668 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1670 const char *fdname
= qdict_get_str(qdict
, "fdname");
1673 qmp_closefd(fdname
, &err
);
1674 hmp_handle_error(mon
, &err
);
1677 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
1679 const char *keys
= qdict_get_str(qdict
, "keys");
1680 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
1681 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1682 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1684 char keyname_buf
[16];
1689 separator
= strchr(keys
, '-');
1690 keyname_len
= separator
? separator
- keys
: strlen(keys
);
1691 pstrcpy(keyname_buf
, sizeof(keyname_buf
), keys
);
1693 /* Be compatible with old interface, convert user inputted "<" */
1694 if (!strncmp(keyname_buf
, "<", 1) && keyname_len
== 1) {
1695 pstrcpy(keyname_buf
, sizeof(keyname_buf
), "less");
1698 keyname_buf
[keyname_len
] = 0;
1700 keylist
= g_malloc0(sizeof(*keylist
));
1701 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
1707 tmp
->next
= keylist
;
1711 if (strstart(keyname_buf
, "0x", NULL
)) {
1713 int value
= strtoul(keyname_buf
, &endp
, 0);
1714 if (*endp
!= '\0') {
1717 keylist
->value
->kind
= KEY_VALUE_KIND_NUMBER
;
1718 keylist
->value
->number
= value
;
1720 int idx
= index_from_key(keyname_buf
);
1721 if (idx
== Q_KEY_CODE_MAX
) {
1724 keylist
->value
->kind
= KEY_VALUE_KIND_QCODE
;
1725 keylist
->value
->qcode
= idx
;
1731 keys
= separator
+ 1;
1734 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1735 hmp_handle_error(mon
, &err
);
1738 qapi_free_KeyValueList(head
);
1742 monitor_printf(mon
, "invalid parameter: %s\n", keyname_buf
);
1746 void hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
1748 const char *filename
= qdict_get_str(qdict
, "filename");
1751 qmp_screendump(filename
, &err
);
1752 hmp_handle_error(mon
, &err
);
1755 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
1757 const char *uri
= qdict_get_str(qdict
, "uri");
1758 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
1759 bool all
= qdict_get_try_bool(qdict
, "all", false);
1760 Error
*local_err
= NULL
;
1761 BlockInfoList
*block_list
, *info
;
1762 SocketAddress
*addr
;
1764 if (writable
&& !all
) {
1765 error_setg(&local_err
, "-w only valid together with -a");
1769 /* First check if the address is valid and start the server. */
1770 addr
= socket_parse(uri
, &local_err
);
1771 if (local_err
!= NULL
) {
1775 qmp_nbd_server_start(addr
, &local_err
);
1776 qapi_free_SocketAddress(addr
);
1777 if (local_err
!= NULL
) {
1785 /* Then try adding all block devices. If one fails, close all and
1788 block_list
= qmp_query_block(NULL
);
1790 for (info
= block_list
; info
; info
= info
->next
) {
1791 if (!info
->value
->has_inserted
) {
1795 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
1797 if (local_err
!= NULL
) {
1798 qmp_nbd_server_stop(NULL
);
1803 qapi_free_BlockInfoList(block_list
);
1806 hmp_handle_error(mon
, &local_err
);
1809 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
1811 const char *device
= qdict_get_str(qdict
, "device");
1812 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
1813 Error
*local_err
= NULL
;
1815 qmp_nbd_server_add(device
, true, writable
, &local_err
);
1817 if (local_err
!= NULL
) {
1818 hmp_handle_error(mon
, &local_err
);
1822 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
1826 qmp_nbd_server_stop(&err
);
1827 hmp_handle_error(mon
, &err
);
1830 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
1835 cpuid
= qdict_get_int(qdict
, "id");
1836 qmp_cpu_add(cpuid
, &err
);
1837 hmp_handle_error(mon
, &err
);
1840 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
1842 const char *args
= qdict_get_str(qdict
, "args");
1846 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
1848 error_setg(&err
, "Parsing chardev args failed");
1850 qemu_chr_new_from_opts(opts
, NULL
, &err
);
1852 hmp_handle_error(mon
, &err
);
1855 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
1857 Error
*local_err
= NULL
;
1859 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
1860 hmp_handle_error(mon
, &local_err
);
1863 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
1866 const char* device
= qdict_get_str(qdict
, "device");
1867 const char* command
= qdict_get_str(qdict
, "command");
1870 blk
= blk_by_name(device
);
1872 qemuio_command(blk
, command
);
1874 error_set(&err
, ERROR_CLASS_DEVICE_NOT_FOUND
,
1875 "Device '%s' not found", device
);
1878 hmp_handle_error(mon
, &err
);
1881 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
1883 const char *id
= qdict_get_str(qdict
, "id");
1886 qmp_object_del(id
, &err
);
1887 hmp_handle_error(mon
, &err
);
1890 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
1893 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
1894 MemdevList
*m
= memdev_list
;
1895 StringOutputVisitor
*ov
;
1901 ov
= string_output_visitor_new(false);
1902 visit_type_uint16List(string_output_get_visitor(ov
),
1903 &m
->value
->host_nodes
, NULL
, NULL
);
1904 monitor_printf(mon
, "memory backend: %d\n", i
);
1905 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
1906 monitor_printf(mon
, " merge: %s\n",
1907 m
->value
->merge
? "true" : "false");
1908 monitor_printf(mon
, " dump: %s\n",
1909 m
->value
->dump
? "true" : "false");
1910 monitor_printf(mon
, " prealloc: %s\n",
1911 m
->value
->prealloc
? "true" : "false");
1912 monitor_printf(mon
, " policy: %s\n",
1913 HostMemPolicy_lookup
[m
->value
->policy
]);
1914 str
= string_output_get_string(ov
);
1915 monitor_printf(mon
, " host nodes: %s\n", str
);
1918 string_output_visitor_cleanup(ov
);
1923 monitor_printf(mon
, "\n");
1925 qapi_free_MemdevList(memdev_list
);
1928 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
1931 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
1932 MemoryDeviceInfoList
*info
;
1933 MemoryDeviceInfo
*value
;
1934 PCDIMMDeviceInfo
*di
;
1936 for (info
= info_list
; info
; info
= info
->next
) {
1937 value
= info
->value
;
1940 switch (value
->kind
) {
1941 case MEMORY_DEVICE_INFO_KIND_DIMM
:
1944 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1945 MemoryDeviceInfoKind_lookup
[value
->kind
],
1946 di
->id
? di
->id
: "");
1947 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
1948 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
1949 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
1950 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
1951 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
1952 monitor_printf(mon
, " hotplugged: %s\n",
1953 di
->hotplugged
? "true" : "false");
1954 monitor_printf(mon
, " hotpluggable: %s\n",
1955 di
->hotpluggable
? "true" : "false");
1963 qapi_free_MemoryDeviceInfoList(info_list
);
1966 void hmp_qom_list(Monitor
*mon
, const QDict
*qdict
)
1968 const char *path
= qdict_get_try_str(qdict
, "path");
1969 ObjectPropertyInfoList
*list
;
1973 monitor_printf(mon
, "/\n");
1977 list
= qmp_qom_list(path
, &err
);
1979 ObjectPropertyInfoList
*start
= list
;
1980 while (list
!= NULL
) {
1981 ObjectPropertyInfo
*value
= list
->value
;
1983 monitor_printf(mon
, "%s (%s)\n",
1984 value
->name
, value
->type
);
1987 qapi_free_ObjectPropertyInfoList(start
);
1989 hmp_handle_error(mon
, &err
);
1992 void hmp_qom_set(Monitor
*mon
, const QDict
*qdict
)
1994 const char *path
= qdict_get_str(qdict
, "path");
1995 const char *property
= qdict_get_str(qdict
, "property");
1996 const char *value
= qdict_get_str(qdict
, "value");
1998 bool ambiguous
= false;
2001 obj
= object_resolve_path(path
, &ambiguous
);
2003 error_set(&err
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2004 "Device '%s' not found", path
);
2007 monitor_printf(mon
, "Warning: Path '%s' is ambiguous\n", path
);
2009 object_property_parse(obj
, value
, property
, &err
);
2011 hmp_handle_error(mon
, &err
);
2014 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
2016 const char *name
= qdict_get_str(qdict
, "name");
2017 RockerSwitch
*rocker
;
2020 rocker
= qmp_query_rocker(name
, &errp
);
2022 hmp_handle_error(mon
, &errp
);
2026 monitor_printf(mon
, "name: %s\n", rocker
->name
);
2027 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
2028 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
2030 qapi_free_RockerSwitch(rocker
);
2033 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
2035 RockerPortList
*list
, *port
;
2036 const char *name
= qdict_get_str(qdict
, "name");
2039 list
= qmp_query_rocker_ports(name
, &errp
);
2041 hmp_handle_error(mon
, &errp
);
2045 monitor_printf(mon
, " ena/ speed/ auto\n");
2046 monitor_printf(mon
, " port link duplex neg?\n");
2048 for (port
= list
; port
; port
= port
->next
) {
2049 monitor_printf(mon
, "%10s %-4s %-3s %2s %-3s\n",
2051 port
->value
->enabled
? port
->value
->link_up
?
2052 "up" : "down" : "!ena",
2053 port
->value
->speed
== 10000 ? "10G" : "??",
2054 port
->value
->duplex
? "FD" : "HD",
2055 port
->value
->autoneg
? "Yes" : "No");
2058 qapi_free_RockerPortList(list
);
2061 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
2063 RockerOfDpaFlowList
*list
, *info
;
2064 const char *name
= qdict_get_str(qdict
, "name");
2065 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
2068 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &errp
);
2070 hmp_handle_error(mon
, &errp
);
2074 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
2076 for (info
= list
; info
; info
= info
->next
) {
2077 RockerOfDpaFlow
*flow
= info
->value
;
2078 RockerOfDpaFlowKey
*key
= flow
->key
;
2079 RockerOfDpaFlowMask
*mask
= flow
->mask
;
2080 RockerOfDpaFlowAction
*action
= flow
->action
;
2083 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
2084 key
->priority
, key
->tbl_id
, flow
->hits
);
2086 monitor_printf(mon
, "%-4d %-3d ",
2087 key
->priority
, key
->tbl_id
);
2090 if (key
->has_in_pport
) {
2091 monitor_printf(mon
, " pport %d", key
->in_pport
);
2092 if (mask
->has_in_pport
) {
2093 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2097 if (key
->has_vlan_id
) {
2098 monitor_printf(mon
, " vlan %d",
2099 key
->vlan_id
& VLAN_VID_MASK
);
2100 if (mask
->has_vlan_id
) {
2101 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2105 if (key
->has_tunnel_id
) {
2106 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2107 if (mask
->has_tunnel_id
) {
2108 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2112 if (key
->has_eth_type
) {
2113 switch (key
->eth_type
) {
2115 monitor_printf(mon
, " ARP");
2118 monitor_printf(mon
, " IP");
2121 monitor_printf(mon
, " IPv6");
2124 monitor_printf(mon
, " LACP");
2127 monitor_printf(mon
, " LLDP");
2130 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2135 if (key
->has_eth_src
) {
2136 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2137 (mask
->has_eth_src
) &&
2138 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2139 monitor_printf(mon
, " src <any mcast/bcast>");
2140 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2141 (mask
->has_eth_src
) &&
2142 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2143 monitor_printf(mon
, " src <any ucast>");
2145 monitor_printf(mon
, " src %s", key
->eth_src
);
2146 if (mask
->has_eth_src
) {
2147 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2152 if (key
->has_eth_dst
) {
2153 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2154 (mask
->has_eth_dst
) &&
2155 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2156 monitor_printf(mon
, " dst <any mcast/bcast>");
2157 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2158 (mask
->has_eth_dst
) &&
2159 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2160 monitor_printf(mon
, " dst <any ucast>");
2162 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2163 if (mask
->has_eth_dst
) {
2164 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2169 if (key
->has_ip_proto
) {
2170 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2171 if (mask
->has_ip_proto
) {
2172 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2176 if (key
->has_ip_tos
) {
2177 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2178 if (mask
->has_ip_tos
) {
2179 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2183 if (key
->has_ip_dst
) {
2184 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2187 if (action
->has_goto_tbl
|| action
->has_group_id
||
2188 action
->has_new_vlan_id
) {
2189 monitor_printf(mon
, " -->");
2192 if (action
->has_new_vlan_id
) {
2193 monitor_printf(mon
, " apply new vlan %d",
2194 ntohs(action
->new_vlan_id
));
2197 if (action
->has_group_id
) {
2198 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2201 if (action
->has_goto_tbl
) {
2202 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2205 monitor_printf(mon
, "\n");
2208 qapi_free_RockerOfDpaFlowList(list
);
2211 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2213 RockerOfDpaGroupList
*list
, *g
;
2214 const char *name
= qdict_get_str(qdict
, "name");
2215 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2219 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &errp
);
2221 hmp_handle_error(mon
, &errp
);
2225 monitor_printf(mon
, "id (decode) --> buckets\n");
2227 for (g
= list
; g
; g
= g
->next
) {
2228 RockerOfDpaGroup
*group
= g
->value
;
2230 monitor_printf(mon
, "0x%08x", group
->id
);
2232 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2233 group
->type
== 1 ? "L2 rewrite" :
2234 group
->type
== 2 ? "L3 unicast" :
2235 group
->type
== 3 ? "L2 multicast" :
2236 group
->type
== 4 ? "L2 flood" :
2237 group
->type
== 5 ? "L3 interface" :
2238 group
->type
== 6 ? "L3 multicast" :
2239 group
->type
== 7 ? "L3 ECMP" :
2240 group
->type
== 8 ? "L2 overlay" :
2243 if (group
->has_vlan_id
) {
2244 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2247 if (group
->has_pport
) {
2248 monitor_printf(mon
, " pport %d", group
->pport
);
2251 if (group
->has_index
) {
2252 monitor_printf(mon
, " index %d", group
->index
);
2255 monitor_printf(mon
, ") -->");
2257 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2259 monitor_printf(mon
, " set vlan %d",
2260 group
->set_vlan_id
& VLAN_VID_MASK
);
2263 if (group
->has_set_eth_src
) {
2266 monitor_printf(mon
, " set");
2268 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2271 if (group
->has_set_eth_dst
) {
2274 monitor_printf(mon
, " set");
2276 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2281 if (group
->has_ttl_check
&& group
->ttl_check
) {
2282 monitor_printf(mon
, " check TTL");
2285 if (group
->has_group_id
&& group
->group_id
) {
2286 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2289 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2290 monitor_printf(mon
, " pop vlan");
2293 if (group
->has_out_pport
) {
2294 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2297 if (group
->has_group_ids
) {
2298 struct uint32List
*id
;
2300 monitor_printf(mon
, " groups [");
2301 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2302 monitor_printf(mon
, "0x%08x", id
->value
);
2304 monitor_printf(mon
, ",");
2307 monitor_printf(mon
, "]");
2310 monitor_printf(mon
, "\n");
2313 qapi_free_RockerOfDpaGroupList(list
);