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.
16 #include "qemu/osdep.h"
20 #include "chardev/char.h"
21 #include "sysemu/block-backend.h"
22 #include "sysemu/sysemu.h"
23 #include "qemu/config-file.h"
24 #include "qemu/option.h"
25 #include "qemu/timer.h"
26 #include "qmp-commands.h"
27 #include "qemu/sockets.h"
28 #include "monitor/monitor.h"
29 #include "monitor/qdev.h"
30 #include "qapi/opts-visitor.h"
31 #include "qapi/qmp/qerror.h"
32 #include "qapi/string-input-visitor.h"
33 #include "qapi/string-output-visitor.h"
34 #include "qapi/util.h"
35 #include "qapi-visit.h"
36 #include "qom/object_interfaces.h"
37 #include "ui/console.h"
38 #include "block/nbd.h"
39 #include "block/qapi.h"
41 #include "qemu/cutils.h"
42 #include "qemu/error-report.h"
43 #include "exec/ramlist.h"
44 #include "hw/intc/intc.h"
45 #include "migration/snapshot.h"
46 #include "migration/misc.h"
49 #include <spice/enums.h>
52 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
56 error_report_err(*errp
);
60 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
64 info
= qmp_query_name(NULL
);
66 monitor_printf(mon
, "%s\n", info
->name
);
68 qapi_free_NameInfo(info
);
71 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
75 info
= qmp_query_version(NULL
);
77 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
78 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
81 qapi_free_VersionInfo(info
);
84 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
88 info
= qmp_query_kvm(NULL
);
89 monitor_printf(mon
, "kvm support: ");
91 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
93 monitor_printf(mon
, "not compiled\n");
96 qapi_free_KvmInfo(info
);
99 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
103 info
= qmp_query_status(NULL
);
105 monitor_printf(mon
, "VM status: %s%s",
106 info
->running
? "running" : "paused",
107 info
->singlestep
? " (single step mode)" : "");
109 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
110 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
113 monitor_printf(mon
, "\n");
115 qapi_free_StatusInfo(info
);
118 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
122 info
= qmp_query_uuid(NULL
);
123 monitor_printf(mon
, "%s\n", info
->UUID
);
124 qapi_free_UuidInfo(info
);
127 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
129 ChardevInfoList
*char_info
, *info
;
131 char_info
= qmp_query_chardev(NULL
);
132 for (info
= char_info
; info
; info
= info
->next
) {
133 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
134 info
->value
->filename
);
137 qapi_free_ChardevInfoList(char_info
);
140 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
142 MouseInfoList
*mice_list
, *mouse
;
144 mice_list
= qmp_query_mice(NULL
);
146 monitor_printf(mon
, "No mouse devices connected\n");
150 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
151 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
152 mouse
->value
->current
? '*' : ' ',
153 mouse
->value
->index
, mouse
->value
->name
,
154 mouse
->value
->absolute
? " (absolute)" : "");
157 qapi_free_MouseInfoList(mice_list
);
160 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
163 MigrationCapabilityStatusList
*caps
, *cap
;
165 info
= qmp_query_migrate(NULL
);
166 caps
= qmp_query_migrate_capabilities(NULL
);
168 migration_global_dump(mon
);
170 /* do not display parameters during setup */
171 if (info
->has_status
&& caps
) {
172 monitor_printf(mon
, "capabilities: ");
173 for (cap
= caps
; cap
; cap
= cap
->next
) {
174 monitor_printf(mon
, "%s: %s ",
175 MigrationCapability_lookup
[cap
->value
->capability
],
176 cap
->value
->state
? "on" : "off");
178 monitor_printf(mon
, "\n");
181 if (info
->has_status
) {
182 monitor_printf(mon
, "Migration status: %s",
183 MigrationStatus_lookup
[info
->status
]);
184 if (info
->status
== MIGRATION_STATUS_FAILED
&&
185 info
->has_error_desc
) {
186 monitor_printf(mon
, " (%s)\n", info
->error_desc
);
188 monitor_printf(mon
, "\n");
191 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
193 if (info
->has_expected_downtime
) {
194 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
195 info
->expected_downtime
);
197 if (info
->has_downtime
) {
198 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
201 if (info
->has_setup_time
) {
202 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
208 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
209 info
->ram
->transferred
>> 10);
210 monitor_printf(mon
, "throughput: %0.2f mbps\n",
212 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
213 info
->ram
->remaining
>> 10);
214 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
215 info
->ram
->total
>> 10);
216 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
217 info
->ram
->duplicate
);
218 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
220 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
222 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
223 info
->ram
->normal_bytes
>> 10);
224 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
225 info
->ram
->dirty_sync_count
);
226 monitor_printf(mon
, "page size: %" PRIu64
" kbytes\n",
227 info
->ram
->page_size
>> 10);
229 if (info
->ram
->dirty_pages_rate
) {
230 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
231 info
->ram
->dirty_pages_rate
);
233 if (info
->ram
->postcopy_requests
) {
234 monitor_printf(mon
, "postcopy request count: %" PRIu64
"\n",
235 info
->ram
->postcopy_requests
);
239 if (info
->has_disk
) {
240 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
241 info
->disk
->transferred
>> 10);
242 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
243 info
->disk
->remaining
>> 10);
244 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
245 info
->disk
->total
>> 10);
248 if (info
->has_xbzrle_cache
) {
249 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
250 info
->xbzrle_cache
->cache_size
);
251 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
252 info
->xbzrle_cache
->bytes
>> 10);
253 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
254 info
->xbzrle_cache
->pages
);
255 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
256 info
->xbzrle_cache
->cache_miss
);
257 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
258 info
->xbzrle_cache
->cache_miss_rate
);
259 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
260 info
->xbzrle_cache
->overflow
);
263 if (info
->has_cpu_throttle_percentage
) {
264 monitor_printf(mon
, "cpu throttle percentage: %" PRIu64
"\n",
265 info
->cpu_throttle_percentage
);
268 qapi_free_MigrationInfo(info
);
269 qapi_free_MigrationCapabilityStatusList(caps
);
272 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
274 MigrationCapabilityStatusList
*caps
, *cap
;
276 caps
= qmp_query_migrate_capabilities(NULL
);
279 for (cap
= caps
; cap
; cap
= cap
->next
) {
280 monitor_printf(mon
, "%s: %s\n",
281 MigrationCapability_lookup
[cap
->value
->capability
],
282 cap
->value
->state
? "on" : "off");
286 qapi_free_MigrationCapabilityStatusList(caps
);
289 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
291 MigrationParameters
*params
;
293 params
= qmp_query_migrate_parameters(NULL
);
296 assert(params
->has_compress_level
);
297 monitor_printf(mon
, "%s: %" PRId64
"\n",
298 MigrationParameter_lookup
[MIGRATION_PARAMETER_COMPRESS_LEVEL
],
299 params
->compress_level
);
300 assert(params
->has_compress_threads
);
301 monitor_printf(mon
, "%s: %" PRId64
"\n",
302 MigrationParameter_lookup
[MIGRATION_PARAMETER_COMPRESS_THREADS
],
303 params
->compress_threads
);
304 assert(params
->has_decompress_threads
);
305 monitor_printf(mon
, "%s: %" PRId64
"\n",
306 MigrationParameter_lookup
[MIGRATION_PARAMETER_DECOMPRESS_THREADS
],
307 params
->decompress_threads
);
308 assert(params
->has_cpu_throttle_initial
);
309 monitor_printf(mon
, "%s: %" PRId64
"\n",
310 MigrationParameter_lookup
[MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
],
311 params
->cpu_throttle_initial
);
312 assert(params
->has_cpu_throttle_increment
);
313 monitor_printf(mon
, "%s: %" PRId64
"\n",
314 MigrationParameter_lookup
[MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
],
315 params
->cpu_throttle_increment
);
316 monitor_printf(mon
, "%s: '%s'\n",
317 MigrationParameter_lookup
[MIGRATION_PARAMETER_TLS_CREDS
],
318 params
->has_tls_creds
? params
->tls_creds
: "");
319 monitor_printf(mon
, "%s: '%s'\n",
320 MigrationParameter_lookup
[MIGRATION_PARAMETER_TLS_HOSTNAME
],
321 params
->has_tls_hostname
? params
->tls_hostname
: "");
322 assert(params
->has_max_bandwidth
);
323 monitor_printf(mon
, "%s: %" PRId64
" bytes/second\n",
324 MigrationParameter_lookup
[MIGRATION_PARAMETER_MAX_BANDWIDTH
],
325 params
->max_bandwidth
);
326 assert(params
->has_downtime_limit
);
327 monitor_printf(mon
, "%s: %" PRId64
" milliseconds\n",
328 MigrationParameter_lookup
[MIGRATION_PARAMETER_DOWNTIME_LIMIT
],
329 params
->downtime_limit
);
330 assert(params
->has_x_checkpoint_delay
);
331 monitor_printf(mon
, "%s: %" PRId64
"\n",
332 MigrationParameter_lookup
[MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
],
333 params
->x_checkpoint_delay
);
334 assert(params
->has_block_incremental
);
335 monitor_printf(mon
, "%s: %s\n",
336 MigrationParameter_lookup
[MIGRATION_PARAMETER_BLOCK_INCREMENTAL
],
337 params
->block_incremental
? "on" : "off");
340 qapi_free_MigrationParameters(params
);
343 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
345 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
346 qmp_query_migrate_cache_size(NULL
) >> 10);
349 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
351 CpuInfoList
*cpu_list
, *cpu
;
353 cpu_list
= qmp_query_cpus(NULL
);
355 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
358 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
362 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
364 switch (cpu
->value
->arch
) {
365 case CPU_INFO_ARCH_X86
:
366 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->u
.x86
.pc
);
368 case CPU_INFO_ARCH_PPC
:
369 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->u
.ppc
.nip
);
371 case CPU_INFO_ARCH_SPARC
:
372 monitor_printf(mon
, " pc=0x%016" PRIx64
,
373 cpu
->value
->u
.q_sparc
.pc
);
374 monitor_printf(mon
, " npc=0x%016" PRIx64
,
375 cpu
->value
->u
.q_sparc
.npc
);
377 case CPU_INFO_ARCH_MIPS
:
378 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.q_mips
.PC
);
380 case CPU_INFO_ARCH_TRICORE
:
381 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.tricore
.PC
);
387 if (cpu
->value
->halted
) {
388 monitor_printf(mon
, " (halted)");
391 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
394 qapi_free_CpuInfoList(cpu_list
);
397 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
398 BlockDeviceInfo
*inserted
, bool verbose
)
400 ImageInfo
*image_info
;
402 assert(!info
|| !info
->has_inserted
|| info
->inserted
== inserted
);
405 monitor_printf(mon
, "%s", info
->device
);
406 if (inserted
&& inserted
->has_node_name
) {
407 monitor_printf(mon
, " (%s)", inserted
->node_name
);
411 monitor_printf(mon
, "%s",
412 inserted
->has_node_name
413 ? inserted
->node_name
418 monitor_printf(mon
, ": %s (%s%s%s)\n",
421 inserted
->ro
? ", read-only" : "",
422 inserted
->encrypted
? ", encrypted" : "");
424 monitor_printf(mon
, ": [not inserted]\n");
428 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
429 monitor_printf(mon
, " I/O status: %s\n",
430 BlockDeviceIoStatus_lookup
[info
->io_status
]);
433 if (info
->removable
) {
434 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
435 info
->locked
? "" : "not ",
436 info
->tray_open
? "open" : "closed");
445 monitor_printf(mon
, " Cache mode: %s%s%s\n",
446 inserted
->cache
->writeback
? "writeback" : "writethrough",
447 inserted
->cache
->direct
? ", direct" : "",
448 inserted
->cache
->no_flush
? ", ignore flushes" : "");
450 if (inserted
->has_backing_file
) {
453 "(chain depth: %" PRId64
")\n",
454 inserted
->backing_file
,
455 inserted
->backing_file_depth
);
458 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
459 monitor_printf(mon
, " Detect zeroes: %s\n",
460 BlockdevDetectZeroesOptions_lookup
[inserted
->detect_zeroes
]);
463 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
464 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
466 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
467 " bps_rd=%" PRId64
" bps_wr=%" PRId64
469 " bps_rd_max=%" PRId64
470 " bps_wr_max=%" PRId64
471 " iops=%" PRId64
" iops_rd=%" PRId64
474 " iops_rd_max=%" PRId64
475 " iops_wr_max=%" PRId64
476 " iops_size=%" PRId64
482 inserted
->bps_rd_max
,
483 inserted
->bps_wr_max
,
488 inserted
->iops_rd_max
,
489 inserted
->iops_wr_max
,
495 monitor_printf(mon
, "\nImages:\n");
496 image_info
= inserted
->image
;
498 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
500 if (image_info
->has_backing_image
) {
501 image_info
= image_info
->backing_image
;
509 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
511 BlockInfoList
*block_list
, *info
;
512 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
513 const char *device
= qdict_get_try_str(qdict
, "device");
514 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
515 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
516 bool printed
= false;
518 /* Print BlockBackend information */
520 block_list
= qmp_query_block(NULL
);
525 for (info
= block_list
; info
; info
= info
->next
) {
526 if (device
&& strcmp(device
, info
->value
->device
)) {
530 if (info
!= block_list
) {
531 monitor_printf(mon
, "\n");
534 print_block_info(mon
, info
->value
, info
->value
->has_inserted
535 ? info
->value
->inserted
: NULL
,
540 qapi_free_BlockInfoList(block_list
);
542 if ((!device
&& !nodes
) || printed
) {
546 /* Print node information */
547 blockdev_list
= qmp_query_named_block_nodes(NULL
);
548 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
549 assert(blockdev
->value
->has_node_name
);
550 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
554 if (blockdev
!= blockdev_list
) {
555 monitor_printf(mon
, "\n");
558 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
560 qapi_free_BlockDeviceInfoList(blockdev_list
);
563 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
565 BlockStatsList
*stats_list
, *stats
;
567 stats_list
= qmp_query_blockstats(false, false, NULL
);
569 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
570 if (!stats
->value
->has_device
) {
574 monitor_printf(mon
, "%s:", stats
->value
->device
);
575 monitor_printf(mon
, " rd_bytes=%" PRId64
577 " rd_operations=%" PRId64
578 " wr_operations=%" PRId64
579 " flush_operations=%" PRId64
580 " wr_total_time_ns=%" PRId64
581 " rd_total_time_ns=%" PRId64
582 " flush_total_time_ns=%" PRId64
583 " rd_merged=%" PRId64
584 " wr_merged=%" PRId64
585 " idle_time_ns=%" PRId64
587 stats
->value
->stats
->rd_bytes
,
588 stats
->value
->stats
->wr_bytes
,
589 stats
->value
->stats
->rd_operations
,
590 stats
->value
->stats
->wr_operations
,
591 stats
->value
->stats
->flush_operations
,
592 stats
->value
->stats
->wr_total_time_ns
,
593 stats
->value
->stats
->rd_total_time_ns
,
594 stats
->value
->stats
->flush_total_time_ns
,
595 stats
->value
->stats
->rd_merged
,
596 stats
->value
->stats
->wr_merged
,
597 stats
->value
->stats
->idle_time_ns
);
600 qapi_free_BlockStatsList(stats_list
);
603 /* Helper for hmp_info_vnc_clients, _servers */
604 static void hmp_info_VncBasicInfo(Monitor
*mon
, VncBasicInfo
*info
,
607 monitor_printf(mon
, " %s: %s:%s (%s%s)\n",
611 NetworkAddressFamily_lookup
[info
->family
],
612 info
->websocket
? " (Websocket)" : "");
615 /* Helper displaying and auth and crypt info */
616 static void hmp_info_vnc_authcrypt(Monitor
*mon
, const char *indent
,
618 VncVencryptSubAuth
*vencrypt
)
620 monitor_printf(mon
, "%sAuth: %s (Sub: %s)\n", indent
,
621 VncPrimaryAuth_lookup
[auth
],
622 vencrypt
? VncVencryptSubAuth_lookup
[*vencrypt
] : "none");
625 static void hmp_info_vnc_clients(Monitor
*mon
, VncClientInfoList
*client
)
628 VncClientInfo
*cinfo
= client
->value
;
630 hmp_info_VncBasicInfo(mon
, qapi_VncClientInfo_base(cinfo
), "Client");
631 monitor_printf(mon
, " x509_dname: %s\n",
632 cinfo
->has_x509_dname
?
633 cinfo
->x509_dname
: "none");
634 monitor_printf(mon
, " sasl_username: %s\n",
635 cinfo
->has_sasl_username
?
636 cinfo
->sasl_username
: "none");
638 client
= client
->next
;
642 static void hmp_info_vnc_servers(Monitor
*mon
, VncServerInfo2List
*server
)
645 VncServerInfo2
*sinfo
= server
->value
;
646 hmp_info_VncBasicInfo(mon
, qapi_VncServerInfo2_base(sinfo
), "Server");
647 hmp_info_vnc_authcrypt(mon
, " ", sinfo
->auth
,
648 sinfo
->has_vencrypt
? &sinfo
->vencrypt
: NULL
);
649 server
= server
->next
;
653 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
655 VncInfo2List
*info2l
;
658 info2l
= qmp_query_vnc_servers(&err
);
660 error_report_err(err
);
664 monitor_printf(mon
, "None\n");
669 VncInfo2
*info
= info2l
->value
;
670 monitor_printf(mon
, "%s:\n", info
->id
);
671 hmp_info_vnc_servers(mon
, info
->server
);
672 hmp_info_vnc_clients(mon
, info
->clients
);
674 /* The server entry displays its auth, we only
675 * need to display in the case of 'reverse' connections
676 * where there's no server.
678 hmp_info_vnc_authcrypt(mon
, " ", info
->auth
,
679 info
->has_vencrypt
? &info
->vencrypt
: NULL
);
681 if (info
->has_display
) {
682 monitor_printf(mon
, " Display: %s\n", info
->display
);
684 info2l
= info2l
->next
;
687 qapi_free_VncInfo2List(info2l
);
692 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
694 SpiceChannelList
*chan
;
696 const char *channel_name
;
697 const char * const channel_names
[] = {
698 [SPICE_CHANNEL_MAIN
] = "main",
699 [SPICE_CHANNEL_DISPLAY
] = "display",
700 [SPICE_CHANNEL_INPUTS
] = "inputs",
701 [SPICE_CHANNEL_CURSOR
] = "cursor",
702 [SPICE_CHANNEL_PLAYBACK
] = "playback",
703 [SPICE_CHANNEL_RECORD
] = "record",
704 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
705 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
706 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
707 [SPICE_CHANNEL_PORT
] = "port",
709 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
710 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
711 * as quick fix for build failures with older versions. */
712 [SPICE_CHANNEL_WEBDAV
] = "webdav",
716 info
= qmp_query_spice(NULL
);
718 if (!info
->enabled
) {
719 monitor_printf(mon
, "Server: disabled\n");
723 monitor_printf(mon
, "Server:\n");
724 if (info
->has_port
) {
725 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
726 info
->host
, info
->port
);
728 if (info
->has_tls_port
) {
729 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
730 info
->host
, info
->tls_port
);
732 monitor_printf(mon
, " migrated: %s\n",
733 info
->migrated
? "true" : "false");
734 monitor_printf(mon
, " auth: %s\n", info
->auth
);
735 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
736 monitor_printf(mon
, " mouse-mode: %s\n",
737 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
739 if (!info
->has_channels
|| info
->channels
== NULL
) {
740 monitor_printf(mon
, "Channels: none\n");
742 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
743 monitor_printf(mon
, "Channel:\n");
744 monitor_printf(mon
, " address: %s:%s%s\n",
745 chan
->value
->host
, chan
->value
->port
,
746 chan
->value
->tls
? " [tls]" : "");
747 monitor_printf(mon
, " session: %" PRId64
"\n",
748 chan
->value
->connection_id
);
749 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
750 chan
->value
->channel_type
, chan
->value
->channel_id
);
752 channel_name
= "unknown";
753 if (chan
->value
->channel_type
> 0 &&
754 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
755 channel_names
[chan
->value
->channel_type
]) {
756 channel_name
= channel_names
[chan
->value
->channel_type
];
759 monitor_printf(mon
, " channel name: %s\n", channel_name
);
764 qapi_free_SpiceInfo(info
);
768 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
773 info
= qmp_query_balloon(&err
);
775 error_report_err(err
);
779 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
781 qapi_free_BalloonInfo(info
);
784 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
786 PciMemoryRegionList
*region
;
788 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
789 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
790 dev
->slot
, dev
->function
);
791 monitor_printf(mon
, " ");
793 if (dev
->class_info
->has_desc
) {
794 monitor_printf(mon
, "%s", dev
->class_info
->desc
);
796 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
799 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
800 dev
->id
->vendor
, dev
->id
->device
);
803 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
806 if (dev
->has_pci_bridge
) {
807 monitor_printf(mon
, " BUS %" PRId64
".\n",
808 dev
->pci_bridge
->bus
->number
);
809 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
810 dev
->pci_bridge
->bus
->secondary
);
811 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
812 dev
->pci_bridge
->bus
->subordinate
);
814 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
815 dev
->pci_bridge
->bus
->io_range
->base
,
816 dev
->pci_bridge
->bus
->io_range
->limit
);
819 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
820 dev
->pci_bridge
->bus
->memory_range
->base
,
821 dev
->pci_bridge
->bus
->memory_range
->limit
);
823 monitor_printf(mon
, " prefetchable memory range "
824 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
825 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
826 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
829 for (region
= dev
->regions
; region
; region
= region
->next
) {
832 addr
= region
->value
->address
;
833 size
= region
->value
->size
;
835 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
837 if (!strcmp(region
->value
->type
, "io")) {
838 monitor_printf(mon
, "I/O at 0x%04" PRIx64
839 " [0x%04" PRIx64
"].\n",
840 addr
, addr
+ size
- 1);
842 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
843 " [0x%08" PRIx64
"].\n",
844 region
->value
->mem_type_64
? 64 : 32,
845 region
->value
->prefetch
? " prefetchable" : "",
846 addr
, addr
+ size
- 1);
850 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
852 if (dev
->has_pci_bridge
) {
853 if (dev
->pci_bridge
->has_devices
) {
854 PciDeviceInfoList
*cdev
;
855 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
856 hmp_info_pci_device(mon
, cdev
->value
);
862 static int hmp_info_irq_foreach(Object
*obj
, void *opaque
)
864 InterruptStatsProvider
*intc
;
865 InterruptStatsProviderClass
*k
;
866 Monitor
*mon
= opaque
;
868 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
869 intc
= INTERRUPT_STATS_PROVIDER(obj
);
870 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
871 uint64_t *irq_counts
;
872 unsigned int nb_irqs
, i
;
873 if (k
->get_statistics
&&
874 k
->get_statistics(intc
, &irq_counts
, &nb_irqs
)) {
876 monitor_printf(mon
, "IRQ statistics for %s:\n",
877 object_get_typename(obj
));
878 for (i
= 0; i
< nb_irqs
; i
++) {
879 if (irq_counts
[i
] > 0) {
880 monitor_printf(mon
, "%2d: %" PRId64
"\n", i
,
886 monitor_printf(mon
, "IRQ statistics not available for %s.\n",
887 object_get_typename(obj
));
894 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
)
896 object_child_foreach_recursive(object_get_root(),
897 hmp_info_irq_foreach
, mon
);
900 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
902 InterruptStatsProvider
*intc
;
903 InterruptStatsProviderClass
*k
;
904 Monitor
*mon
= opaque
;
906 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
907 intc
= INTERRUPT_STATS_PROVIDER(obj
);
908 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
910 k
->print_info(intc
, mon
);
912 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
913 object_get_typename(obj
));
920 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
922 object_child_foreach_recursive(object_get_root(),
923 hmp_info_pic_foreach
, mon
);
926 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
928 PciInfoList
*info_list
, *info
;
931 info_list
= qmp_query_pci(&err
);
933 monitor_printf(mon
, "PCI devices not supported\n");
938 for (info
= info_list
; info
; info
= info
->next
) {
939 PciDeviceInfoList
*dev
;
941 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
942 hmp_info_pci_device(mon
, dev
->value
);
946 qapi_free_PciInfoList(info_list
);
949 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
951 BlockJobInfoList
*list
;
954 list
= qmp_query_block_jobs(&err
);
958 monitor_printf(mon
, "No active jobs\n");
963 if (strcmp(list
->value
->type
, "stream") == 0) {
964 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
965 " of %" PRId64
" bytes, speed limit %" PRId64
972 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
973 " of %" PRId64
" bytes, speed limit %" PRId64
984 qapi_free_BlockJobInfoList(list
);
987 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
989 TPMInfoList
*info_list
, *info
;
992 TPMPassthroughOptions
*tpo
;
994 info_list
= qmp_query_tpm(&err
);
996 monitor_printf(mon
, "TPM device not supported\n");
1002 monitor_printf(mon
, "TPM device:\n");
1005 for (info
= info_list
; info
; info
= info
->next
) {
1006 TPMInfo
*ti
= info
->value
;
1007 monitor_printf(mon
, " tpm%d: model=%s\n",
1008 c
, TpmModel_lookup
[ti
->model
]);
1010 monitor_printf(mon
, " \\ %s: type=%s",
1011 ti
->id
, TpmTypeOptionsKind_lookup
[ti
->options
->type
]);
1013 switch (ti
->options
->type
) {
1014 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
1015 tpo
= ti
->options
->u
.passthrough
.data
;
1016 monitor_printf(mon
, "%s%s%s%s",
1017 tpo
->has_path
? ",path=" : "",
1018 tpo
->has_path
? tpo
->path
: "",
1019 tpo
->has_cancel_path
? ",cancel-path=" : "",
1020 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
1022 case TPM_TYPE_OPTIONS_KIND__MAX
:
1025 monitor_printf(mon
, "\n");
1028 qapi_free_TPMInfoList(info_list
);
1031 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
1033 monitor_suspend(mon
);
1037 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
1042 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
1044 qmp_system_reset(NULL
);
1047 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
1049 qmp_system_powerdown(NULL
);
1052 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
1056 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1057 use it are converted to the QAPI */
1058 cpu_index
= qdict_get_int(qdict
, "index");
1059 if (monitor_set_cpu(cpu_index
) < 0) {
1060 monitor_printf(mon
, "invalid CPU index\n");
1064 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
1066 uint32_t size
= qdict_get_int(qdict
, "size");
1067 const char *filename
= qdict_get_str(qdict
, "filename");
1068 uint64_t addr
= qdict_get_int(qdict
, "val");
1070 int cpu_index
= monitor_get_cpu_index();
1072 if (cpu_index
< 0) {
1073 monitor_printf(mon
, "No CPU available\n");
1077 qmp_memsave(addr
, size
, filename
, true, cpu_index
, &err
);
1078 hmp_handle_error(mon
, &err
);
1081 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
1083 uint32_t size
= qdict_get_int(qdict
, "size");
1084 const char *filename
= qdict_get_str(qdict
, "filename");
1085 uint64_t addr
= qdict_get_int(qdict
, "val");
1088 qmp_pmemsave(addr
, size
, filename
, &err
);
1089 hmp_handle_error(mon
, &err
);
1092 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
1094 const char *chardev
= qdict_get_str(qdict
, "device");
1095 const char *data
= qdict_get_str(qdict
, "data");
1098 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
1100 hmp_handle_error(mon
, &err
);
1103 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
1105 uint32_t size
= qdict_get_int(qdict
, "size");
1106 const char *chardev
= qdict_get_str(qdict
, "device");
1111 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
1113 error_report_err(err
);
1117 for (i
= 0; data
[i
]; i
++) {
1118 unsigned char ch
= data
[i
];
1121 monitor_printf(mon
, "\\\\");
1122 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
1123 monitor_printf(mon
, "\\u%04X", ch
);
1125 monitor_printf(mon
, "%c", ch
);
1129 monitor_printf(mon
, "\n");
1133 static void hmp_cont_cb(void *opaque
, int err
)
1140 static bool key_is_missing(const BlockInfo
*bdev
)
1142 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
1145 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
1147 BlockInfoList
*bdev_list
, *bdev
;
1150 bdev_list
= qmp_query_block(NULL
);
1151 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
1152 if (key_is_missing(bdev
->value
)) {
1153 monitor_read_block_device_key(mon
, bdev
->value
->device
,
1160 hmp_handle_error(mon
, &err
);
1163 qapi_free_BlockInfoList(bdev_list
);
1166 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
1168 qmp_system_wakeup(NULL
);
1171 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
1175 qmp_inject_nmi(&err
);
1176 hmp_handle_error(mon
, &err
);
1179 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
1181 const char *name
= qdict_get_str(qdict
, "name");
1182 bool up
= qdict_get_bool(qdict
, "up");
1185 qmp_set_link(name
, up
, &err
);
1186 hmp_handle_error(mon
, &err
);
1189 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
1191 const char *device
= qdict_get_str(qdict
, "device");
1192 const char *password
= qdict_get_str(qdict
, "password");
1195 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
1196 hmp_handle_error(mon
, &err
);
1199 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1201 int64_t value
= qdict_get_int(qdict
, "value");
1204 qmp_balloon(value
, &err
);
1206 error_report_err(err
);
1210 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
1212 const char *device
= qdict_get_str(qdict
, "device");
1213 int64_t size
= qdict_get_int(qdict
, "size");
1216 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
1217 hmp_handle_error(mon
, &err
);
1220 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
1222 const char *filename
= qdict_get_str(qdict
, "target");
1223 const char *format
= qdict_get_try_str(qdict
, "format");
1224 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1225 bool full
= qdict_get_try_bool(qdict
, "full", false);
1227 DriveMirror mirror
= {
1228 .device
= (char *)qdict_get_str(qdict
, "device"),
1229 .target
= (char *)filename
,
1230 .has_format
= !!format
,
1231 .format
= (char *)format
,
1232 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1234 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1239 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1240 hmp_handle_error(mon
, &err
);
1243 qmp_drive_mirror(&mirror
, &err
);
1244 hmp_handle_error(mon
, &err
);
1247 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
1249 const char *device
= qdict_get_str(qdict
, "device");
1250 const char *filename
= qdict_get_str(qdict
, "target");
1251 const char *format
= qdict_get_try_str(qdict
, "format");
1252 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1253 bool full
= qdict_get_try_bool(qdict
, "full", false);
1254 bool compress
= qdict_get_try_bool(qdict
, "compress", false);
1256 DriveBackup backup
= {
1257 .device
= (char *)device
,
1258 .target
= (char *)filename
,
1259 .has_format
= !!format
,
1260 .format
= (char *)format
,
1261 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1263 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1264 .has_compress
= !!compress
,
1265 .compress
= compress
,
1269 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1270 hmp_handle_error(mon
, &err
);
1274 qmp_drive_backup(&backup
, &err
);
1275 hmp_handle_error(mon
, &err
);
1278 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
1280 const char *device
= qdict_get_str(qdict
, "device");
1281 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
1282 const char *format
= qdict_get_try_str(qdict
, "format");
1283 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1284 enum NewImageMode mode
;
1288 /* In the future, if 'snapshot-file' is not specified, the snapshot
1289 will be taken internally. Today it's actually required. */
1290 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
1291 hmp_handle_error(mon
, &err
);
1295 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1296 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
1297 filename
, false, NULL
,
1300 hmp_handle_error(mon
, &err
);
1303 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1305 const char *device
= qdict_get_str(qdict
, "device");
1306 const char *name
= qdict_get_str(qdict
, "name");
1309 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1310 hmp_handle_error(mon
, &err
);
1313 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1315 const char *device
= qdict_get_str(qdict
, "device");
1316 const char *name
= qdict_get_str(qdict
, "name");
1317 const char *id
= qdict_get_try_str(qdict
, "id");
1320 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1322 hmp_handle_error(mon
, &err
);
1325 void hmp_loadvm(Monitor
*mon
, const QDict
*qdict
)
1327 int saved_vm_running
= runstate_is_running();
1328 const char *name
= qdict_get_str(qdict
, "name");
1331 vm_stop(RUN_STATE_RESTORE_VM
);
1333 if (load_snapshot(name
, &err
) == 0 && saved_vm_running
) {
1336 hmp_handle_error(mon
, &err
);
1339 void hmp_savevm(Monitor
*mon
, const QDict
*qdict
)
1343 save_snapshot(qdict_get_try_str(qdict
, "name"), &err
);
1344 hmp_handle_error(mon
, &err
);
1347 void hmp_delvm(Monitor
*mon
, const QDict
*qdict
)
1349 BlockDriverState
*bs
;
1351 const char *name
= qdict_get_str(qdict
, "name");
1353 if (bdrv_all_delete_snapshot(name
, &bs
, &err
) < 0) {
1354 error_reportf_err(err
,
1355 "Error while deleting snapshot on device '%s': ",
1356 bdrv_get_device_name(bs
));
1360 void hmp_info_snapshots(Monitor
*mon
, const QDict
*qdict
)
1362 BlockDriverState
*bs
, *bs1
;
1363 BdrvNextIterator it1
;
1364 QEMUSnapshotInfo
*sn_tab
, *sn
;
1365 bool no_snapshot
= true;
1368 int *global_snapshots
;
1369 AioContext
*aio_context
;
1371 typedef struct SnapshotEntry
{
1372 QEMUSnapshotInfo sn
;
1373 QTAILQ_ENTRY(SnapshotEntry
) next
;
1376 typedef struct ImageEntry
{
1377 const char *imagename
;
1378 QTAILQ_ENTRY(ImageEntry
) next
;
1379 QTAILQ_HEAD(, SnapshotEntry
) snapshots
;
1382 QTAILQ_HEAD(, ImageEntry
) image_list
=
1383 QTAILQ_HEAD_INITIALIZER(image_list
);
1385 ImageEntry
*image_entry
, *next_ie
;
1386 SnapshotEntry
*snapshot_entry
;
1388 bs
= bdrv_all_find_vmstate_bs();
1390 monitor_printf(mon
, "No available block device supports snapshots\n");
1393 aio_context
= bdrv_get_aio_context(bs
);
1395 aio_context_acquire(aio_context
);
1396 nb_sns
= bdrv_snapshot_list(bs
, &sn_tab
);
1397 aio_context_release(aio_context
);
1400 monitor_printf(mon
, "bdrv_snapshot_list: error %d\n", nb_sns
);
1404 for (bs1
= bdrv_first(&it1
); bs1
; bs1
= bdrv_next(&it1
)) {
1408 AioContext
*ctx
= bdrv_get_aio_context(bs1
);
1410 aio_context_acquire(ctx
);
1411 if (bdrv_can_snapshot(bs1
)) {
1413 bs1_nb_sns
= bdrv_snapshot_list(bs1
, &sn
);
1414 if (bs1_nb_sns
> 0) {
1415 no_snapshot
= false;
1416 ie
= g_new0(ImageEntry
, 1);
1417 ie
->imagename
= bdrv_get_device_name(bs1
);
1418 QTAILQ_INIT(&ie
->snapshots
);
1419 QTAILQ_INSERT_TAIL(&image_list
, ie
, next
);
1420 for (i
= 0; i
< bs1_nb_sns
; i
++) {
1421 se
= g_new0(SnapshotEntry
, 1);
1423 QTAILQ_INSERT_TAIL(&ie
->snapshots
, se
, next
);
1428 aio_context_release(ctx
);
1432 monitor_printf(mon
, "There is no snapshot available.\n");
1436 global_snapshots
= g_new0(int, nb_sns
);
1438 for (i
= 0; i
< nb_sns
; i
++) {
1439 SnapshotEntry
*next_sn
;
1440 if (bdrv_all_find_snapshot(sn_tab
[i
].name
, &bs1
) == 0) {
1441 global_snapshots
[total
] = i
;
1443 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1444 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
,
1446 if (!strcmp(sn_tab
[i
].name
, snapshot_entry
->sn
.name
)) {
1447 QTAILQ_REMOVE(&image_entry
->snapshots
, snapshot_entry
,
1449 g_free(snapshot_entry
);
1456 monitor_printf(mon
, "List of snapshots present on all disks:\n");
1459 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1460 monitor_printf(mon
, "\n");
1461 for (i
= 0; i
< total
; i
++) {
1462 sn
= &sn_tab
[global_snapshots
[i
]];
1463 /* The ID is not guaranteed to be the same on all images, so
1466 pstrcpy(sn
->id_str
, sizeof(sn
->id_str
), "--");
1467 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, sn
);
1468 monitor_printf(mon
, "\n");
1471 monitor_printf(mon
, "None\n");
1474 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1475 if (QTAILQ_EMPTY(&image_entry
->snapshots
)) {
1479 "\nList of partial (non-loadable) snapshots on '%s':\n",
1480 image_entry
->imagename
);
1481 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1482 monitor_printf(mon
, "\n");
1483 QTAILQ_FOREACH(snapshot_entry
, &image_entry
->snapshots
, next
) {
1484 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
,
1485 &snapshot_entry
->sn
);
1486 monitor_printf(mon
, "\n");
1490 QTAILQ_FOREACH_SAFE(image_entry
, &image_list
, next
, next_ie
) {
1491 SnapshotEntry
*next_sn
;
1492 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
, next
,
1494 g_free(snapshot_entry
);
1496 g_free(image_entry
);
1499 g_free(global_snapshots
);
1503 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1505 qmp_migrate_cancel(NULL
);
1508 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1511 const char *uri
= qdict_get_str(qdict
, "uri");
1513 qmp_migrate_incoming(uri
, &err
);
1515 hmp_handle_error(mon
, &err
);
1518 /* Kept for backwards compatibility */
1519 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1521 double value
= qdict_get_double(qdict
, "value");
1522 qmp_migrate_set_downtime(value
, NULL
);
1525 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1527 int64_t value
= qdict_get_int(qdict
, "value");
1530 qmp_migrate_set_cache_size(value
, &err
);
1532 error_report_err(err
);
1537 /* Kept for backwards compatibility */
1538 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1540 int64_t value
= qdict_get_int(qdict
, "value");
1541 qmp_migrate_set_speed(value
, NULL
);
1544 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1546 const char *cap
= qdict_get_str(qdict
, "capability");
1547 bool state
= qdict_get_bool(qdict
, "state");
1549 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1552 for (i
= 0; i
< MIGRATION_CAPABILITY__MAX
; i
++) {
1553 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
1554 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1555 caps
->value
->capability
= i
;
1556 caps
->value
->state
= state
;
1558 qmp_migrate_set_capabilities(caps
, &err
);
1563 if (i
== MIGRATION_CAPABILITY__MAX
) {
1564 error_setg(&err
, QERR_INVALID_PARAMETER
, cap
);
1567 qapi_free_MigrationCapabilityStatusList(caps
);
1570 error_report_err(err
);
1574 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1576 const char *param
= qdict_get_str(qdict
, "parameter");
1577 const char *valuestr
= qdict_get_str(qdict
, "value");
1578 Visitor
*v
= string_input_visitor_new(valuestr
);
1579 uint64_t valuebw
= 0;
1580 int64_t valueint
= 0;
1581 bool valuebool
= false;
1583 bool use_int_value
= false;
1586 for (i
= 0; i
< MIGRATION_PARAMETER__MAX
; i
++) {
1587 if (strcmp(param
, MigrationParameter_lookup
[i
]) == 0) {
1588 MigrationParameters p
= { 0 };
1590 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1591 p
.has_compress_level
= true;
1592 use_int_value
= true;
1594 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1595 p
.has_compress_threads
= true;
1596 use_int_value
= true;
1598 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1599 p
.has_decompress_threads
= true;
1600 use_int_value
= true;
1602 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1603 p
.has_cpu_throttle_initial
= true;
1604 use_int_value
= true;
1606 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1607 p
.has_cpu_throttle_increment
= true;
1608 use_int_value
= true;
1610 case MIGRATION_PARAMETER_TLS_CREDS
:
1611 p
.has_tls_creds
= true;
1612 p
.tls_creds
= (char *) valuestr
;
1614 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1615 p
.has_tls_hostname
= true;
1616 p
.tls_hostname
= (char *) valuestr
;
1618 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1619 p
.has_max_bandwidth
= true;
1620 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
1621 if (ret
< 0 || valuebw
> INT64_MAX
1622 || (size_t)valuebw
!= valuebw
) {
1623 error_setg(&err
, "Invalid size %s", valuestr
);
1626 p
.max_bandwidth
= valuebw
;
1628 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1629 p
.has_downtime_limit
= true;
1630 use_int_value
= true;
1632 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
1633 p
.has_x_checkpoint_delay
= true;
1634 use_int_value
= true;
1636 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL
:
1637 p
.has_block_incremental
= true;
1638 visit_type_bool(v
, param
, &valuebool
, &err
);
1642 p
.block_incremental
= valuebool
;
1646 if (use_int_value
) {
1647 visit_type_int(v
, param
, &valueint
, &err
);
1651 /* Set all integers; only one has_FOO will be set, and
1652 * the code ignores the remaining values */
1653 p
.compress_level
= valueint
;
1654 p
.compress_threads
= valueint
;
1655 p
.decompress_threads
= valueint
;
1656 p
.cpu_throttle_initial
= valueint
;
1657 p
.cpu_throttle_increment
= valueint
;
1658 p
.downtime_limit
= valueint
;
1659 p
.x_checkpoint_delay
= valueint
;
1662 qmp_migrate_set_parameters(&p
, &err
);
1667 if (i
== MIGRATION_PARAMETER__MAX
) {
1668 error_setg(&err
, QERR_INVALID_PARAMETER
, param
);
1674 error_report_err(err
);
1678 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1681 const char *protocol
= qdict_get_str(qdict
, "protocol");
1682 const char *hostname
= qdict_get_str(qdict
, "hostname");
1683 bool has_port
= qdict_haskey(qdict
, "port");
1684 int port
= qdict_get_try_int(qdict
, "port", -1);
1685 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1686 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1687 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1689 qmp_client_migrate_info(protocol
, hostname
,
1690 has_port
, port
, has_tls_port
, tls_port
,
1691 !!cert_subject
, cert_subject
, &err
);
1692 hmp_handle_error(mon
, &err
);
1695 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1698 qmp_migrate_start_postcopy(&err
);
1699 hmp_handle_error(mon
, &err
);
1702 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1706 qmp_x_colo_lost_heartbeat(&err
);
1707 hmp_handle_error(mon
, &err
);
1710 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1712 const char *protocol
= qdict_get_str(qdict
, "protocol");
1713 const char *password
= qdict_get_str(qdict
, "password");
1714 const char *connected
= qdict_get_try_str(qdict
, "connected");
1717 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1718 hmp_handle_error(mon
, &err
);
1721 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1723 const char *protocol
= qdict_get_str(qdict
, "protocol");
1724 const char *whenstr
= qdict_get_str(qdict
, "time");
1727 qmp_expire_password(protocol
, whenstr
, &err
);
1728 hmp_handle_error(mon
, &err
);
1731 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1733 bool force
= qdict_get_try_bool(qdict
, "force", false);
1734 const char *device
= qdict_get_str(qdict
, "device");
1737 qmp_eject(true, device
, false, NULL
, true, force
, &err
);
1738 hmp_handle_error(mon
, &err
);
1741 static void hmp_change_read_arg(void *opaque
, const char *password
,
1742 void *readline_opaque
)
1744 qmp_change_vnc_password(password
, NULL
);
1745 monitor_read_command(opaque
, 1);
1748 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1750 const char *device
= qdict_get_str(qdict
, "device");
1751 const char *target
= qdict_get_str(qdict
, "target");
1752 const char *arg
= qdict_get_try_str(qdict
, "arg");
1753 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1754 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1757 if (strcmp(device
, "vnc") == 0) {
1760 "Parameter 'read-only-mode' is invalid for VNC\n");
1763 if (strcmp(target
, "passwd") == 0 ||
1764 strcmp(target
, "password") == 0) {
1766 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1770 qmp_change("vnc", target
, !!arg
, arg
, &err
);
1774 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup
,
1775 read_only
, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX
,
1776 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1778 hmp_handle_error(mon
, &err
);
1783 qmp_blockdev_change_medium(true, device
, false, NULL
, target
,
1784 !!arg
, arg
, !!read_only
, read_only_mode
,
1787 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
1789 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
1794 hmp_handle_error(mon
, &err
);
1797 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1800 BlockIOThrottle throttle
= {
1802 .device
= (char *) qdict_get_str(qdict
, "device"),
1803 .bps
= qdict_get_int(qdict
, "bps"),
1804 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
1805 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
1806 .iops
= qdict_get_int(qdict
, "iops"),
1807 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
1808 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
1811 qmp_block_set_io_throttle(&throttle
, &err
);
1812 hmp_handle_error(mon
, &err
);
1815 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1817 Error
*error
= NULL
;
1818 const char *device
= qdict_get_str(qdict
, "device");
1819 const char *base
= qdict_get_try_str(qdict
, "base");
1820 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1822 qmp_block_stream(true, device
, device
, base
!= NULL
, base
, false, NULL
,
1823 false, NULL
, qdict_haskey(qdict
, "speed"), speed
,
1824 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1826 hmp_handle_error(mon
, &error
);
1829 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1831 Error
*error
= NULL
;
1832 const char *device
= qdict_get_str(qdict
, "device");
1833 int64_t value
= qdict_get_int(qdict
, "speed");
1835 qmp_block_job_set_speed(device
, value
, &error
);
1837 hmp_handle_error(mon
, &error
);
1840 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1842 Error
*error
= NULL
;
1843 const char *device
= qdict_get_str(qdict
, "device");
1844 bool force
= qdict_get_try_bool(qdict
, "force", false);
1846 qmp_block_job_cancel(device
, true, force
, &error
);
1848 hmp_handle_error(mon
, &error
);
1851 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1853 Error
*error
= NULL
;
1854 const char *device
= qdict_get_str(qdict
, "device");
1856 qmp_block_job_pause(device
, &error
);
1858 hmp_handle_error(mon
, &error
);
1861 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1863 Error
*error
= NULL
;
1864 const char *device
= qdict_get_str(qdict
, "device");
1866 qmp_block_job_resume(device
, &error
);
1868 hmp_handle_error(mon
, &error
);
1871 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1873 Error
*error
= NULL
;
1874 const char *device
= qdict_get_str(qdict
, "device");
1876 qmp_block_job_complete(device
, &error
);
1878 hmp_handle_error(mon
, &error
);
1881 typedef struct HMPMigrationStatus
1885 bool is_block_migration
;
1886 } HMPMigrationStatus
;
1888 static void hmp_migrate_status_cb(void *opaque
)
1890 HMPMigrationStatus
*status
= opaque
;
1891 MigrationInfo
*info
;
1893 info
= qmp_query_migrate(NULL
);
1894 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1895 info
->status
== MIGRATION_STATUS_SETUP
) {
1896 if (info
->has_disk
) {
1899 if (info
->disk
->remaining
) {
1900 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1905 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1906 monitor_flush(status
->mon
);
1909 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1911 if (status
->is_block_migration
) {
1912 monitor_printf(status
->mon
, "\n");
1914 if (info
->has_error_desc
) {
1915 error_report("%s", info
->error_desc
);
1917 monitor_resume(status
->mon
);
1918 timer_del(status
->timer
);
1922 qapi_free_MigrationInfo(info
);
1925 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1927 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1928 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1929 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1930 const char *uri
= qdict_get_str(qdict
, "uri");
1933 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1935 error_report_err(err
);
1940 HMPMigrationStatus
*status
;
1942 if (monitor_suspend(mon
) < 0) {
1943 monitor_printf(mon
, "terminal does not allow synchronous "
1944 "migration, continuing detached\n");
1948 status
= g_malloc0(sizeof(*status
));
1950 status
->is_block_migration
= blk
|| inc
;
1951 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1953 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1957 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
1961 qmp_device_add((QDict
*)qdict
, NULL
, &err
);
1962 hmp_handle_error(mon
, &err
);
1965 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1967 const char *id
= qdict_get_str(qdict
, "id");
1970 qmp_device_del(id
, &err
);
1971 hmp_handle_error(mon
, &err
);
1974 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1977 bool paging
= qdict_get_try_bool(qdict
, "paging", false);
1978 bool zlib
= qdict_get_try_bool(qdict
, "zlib", false);
1979 bool lzo
= qdict_get_try_bool(qdict
, "lzo", false);
1980 bool snappy
= qdict_get_try_bool(qdict
, "snappy", false);
1981 const char *file
= qdict_get_str(qdict
, "filename");
1982 bool has_begin
= qdict_haskey(qdict
, "begin");
1983 bool has_length
= qdict_haskey(qdict
, "length");
1984 bool has_detach
= qdict_haskey(qdict
, "detach");
1987 bool detach
= false;
1988 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1991 if (zlib
+ lzo
+ snappy
> 1) {
1992 error_setg(&err
, "only one of '-z|-l|-s' can be set");
1993 hmp_handle_error(mon
, &err
);
1998 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
2002 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
2006 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
2010 begin
= qdict_get_int(qdict
, "begin");
2013 length
= qdict_get_int(qdict
, "length");
2016 detach
= qdict_get_bool(qdict
, "detach");
2019 prot
= g_strconcat("file:", file
, NULL
);
2021 qmp_dump_guest_memory(paging
, prot
, true, detach
, has_begin
, begin
,
2022 has_length
, length
, true, dump_format
, &err
);
2023 hmp_handle_error(mon
, &err
);
2027 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
2032 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
2037 netdev_add(opts
, &err
);
2039 qemu_opts_del(opts
);
2043 hmp_handle_error(mon
, &err
);
2046 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
2048 const char *id
= qdict_get_str(qdict
, "id");
2051 qmp_netdev_del(id
, &err
);
2052 hmp_handle_error(mon
, &err
);
2055 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
2061 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
2063 hmp_handle_error(mon
, &err
);
2067 obj
= user_creatable_add_opts(opts
, &err
);
2068 qemu_opts_del(opts
);
2071 hmp_handle_error(mon
, &err
);
2078 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
2080 const char *fdname
= qdict_get_str(qdict
, "fdname");
2083 qmp_getfd(fdname
, &err
);
2084 hmp_handle_error(mon
, &err
);
2087 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
2089 const char *fdname
= qdict_get_str(qdict
, "fdname");
2092 qmp_closefd(fdname
, &err
);
2093 hmp_handle_error(mon
, &err
);
2096 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
2098 const char *keys
= qdict_get_str(qdict
, "keys");
2099 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
2100 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
2101 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
2107 separator
= strchr(keys
, '-');
2108 keyname_len
= separator
? separator
- keys
: strlen(keys
);
2110 /* Be compatible with old interface, convert user inputted "<" */
2111 if (keys
[0] == '<' && keyname_len
== 1) {
2116 keylist
= g_malloc0(sizeof(*keylist
));
2117 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
2123 tmp
->next
= keylist
;
2127 if (strstart(keys
, "0x", NULL
)) {
2129 int value
= strtoul(keys
, &endp
, 0);
2130 assert(endp
<= keys
+ keyname_len
);
2131 if (endp
!= keys
+ keyname_len
) {
2134 keylist
->value
->type
= KEY_VALUE_KIND_NUMBER
;
2135 keylist
->value
->u
.number
.data
= value
;
2137 int idx
= index_from_key(keys
, keyname_len
);
2138 if (idx
== Q_KEY_CODE__MAX
) {
2141 keylist
->value
->type
= KEY_VALUE_KIND_QCODE
;
2142 keylist
->value
->u
.qcode
.data
= idx
;
2148 keys
= separator
+ 1;
2151 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
2152 hmp_handle_error(mon
, &err
);
2155 qapi_free_KeyValueList(head
);
2159 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
2163 void hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
2165 const char *filename
= qdict_get_str(qdict
, "filename");
2168 qmp_screendump(filename
, &err
);
2169 hmp_handle_error(mon
, &err
);
2172 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
2174 const char *uri
= qdict_get_str(qdict
, "uri");
2175 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2176 bool all
= qdict_get_try_bool(qdict
, "all", false);
2177 Error
*local_err
= NULL
;
2178 BlockInfoList
*block_list
, *info
;
2179 SocketAddress
*addr
;
2181 if (writable
&& !all
) {
2182 error_setg(&local_err
, "-w only valid together with -a");
2186 /* First check if the address is valid and start the server. */
2187 addr
= socket_parse(uri
, &local_err
);
2188 if (local_err
!= NULL
) {
2192 nbd_server_start(addr
, NULL
, &local_err
);
2193 qapi_free_SocketAddress(addr
);
2194 if (local_err
!= NULL
) {
2202 /* Then try adding all block devices. If one fails, close all and
2205 block_list
= qmp_query_block(NULL
);
2207 for (info
= block_list
; info
; info
= info
->next
) {
2208 if (!info
->value
->has_inserted
) {
2212 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
2214 if (local_err
!= NULL
) {
2215 qmp_nbd_server_stop(NULL
);
2220 qapi_free_BlockInfoList(block_list
);
2223 hmp_handle_error(mon
, &local_err
);
2226 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
2228 const char *device
= qdict_get_str(qdict
, "device");
2229 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2230 Error
*local_err
= NULL
;
2232 qmp_nbd_server_add(device
, true, writable
, &local_err
);
2234 if (local_err
!= NULL
) {
2235 hmp_handle_error(mon
, &local_err
);
2239 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
2243 qmp_nbd_server_stop(&err
);
2244 hmp_handle_error(mon
, &err
);
2247 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
2252 cpuid
= qdict_get_int(qdict
, "id");
2253 qmp_cpu_add(cpuid
, &err
);
2254 hmp_handle_error(mon
, &err
);
2257 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
2259 const char *args
= qdict_get_str(qdict
, "args");
2263 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
2265 error_setg(&err
, "Parsing chardev args failed");
2267 qemu_chr_new_from_opts(opts
, &err
);
2268 qemu_opts_del(opts
);
2270 hmp_handle_error(mon
, &err
);
2273 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
2275 Error
*local_err
= NULL
;
2277 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
2278 hmp_handle_error(mon
, &local_err
);
2281 void hmp_chardev_send_break(Monitor
*mon
, const QDict
*qdict
)
2283 Error
*local_err
= NULL
;
2285 qmp_chardev_send_break(qdict_get_str(qdict
, "id"), &local_err
);
2286 hmp_handle_error(mon
, &local_err
);
2289 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
2292 BlockBackend
*local_blk
= NULL
;
2293 AioContext
*aio_context
;
2294 const char* device
= qdict_get_str(qdict
, "device");
2295 const char* command
= qdict_get_str(qdict
, "command");
2299 blk
= blk_by_name(device
);
2301 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, device
, &err
);
2303 blk
= local_blk
= blk_new(0, BLK_PERM_ALL
);
2304 ret
= blk_insert_bs(blk
, bs
, &err
);
2313 aio_context
= blk_get_aio_context(blk
);
2314 aio_context_acquire(aio_context
);
2317 * Notably absent: Proper permission management. This is sad, but it seems
2318 * almost impossible to achieve without changing the semantics and thereby
2319 * limiting the use cases of the qemu-io HMP command.
2321 * In an ideal world we would unconditionally create a new BlockBackend for
2322 * qemuio_command(), but we have commands like 'reopen' and want them to
2323 * take effect on the exact BlockBackend whose name the user passed instead
2324 * of just on a temporary copy of it.
2326 * Another problem is that deleting the temporary BlockBackend involves
2327 * draining all requests on it first, but some qemu-iotests cases want to
2328 * issue multiple aio_read/write requests and expect them to complete in
2329 * the background while the monitor has already returned.
2331 * This is also what prevents us from saving the original permissions and
2332 * restoring them later: We can't revoke permissions until all requests
2333 * have completed, and we don't know when that is nor can we really let
2334 * anything else run before we have revoken them to avoid race conditions.
2336 * What happens now is that command() in qemu-io-cmds.c can extend the
2337 * permissions if necessary for the qemu-io command. And they simply stay
2338 * extended, possibly resulting in a read-only guest device keeping write
2339 * permissions. Ugly, but it appears to be the lesser evil.
2341 qemuio_command(blk
, command
);
2343 aio_context_release(aio_context
);
2346 blk_unref(local_blk
);
2347 hmp_handle_error(mon
, &err
);
2350 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
2352 const char *id
= qdict_get_str(qdict
, "id");
2355 user_creatable_del(id
, &err
);
2356 hmp_handle_error(mon
, &err
);
2359 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
2362 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
2363 MemdevList
*m
= memdev_list
;
2368 v
= string_output_visitor_new(false, &str
);
2369 visit_type_uint16List(v
, NULL
, &m
->value
->host_nodes
, NULL
);
2370 monitor_printf(mon
, "memory backend: %s\n", m
->value
->id
);
2371 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
2372 monitor_printf(mon
, " merge: %s\n",
2373 m
->value
->merge
? "true" : "false");
2374 monitor_printf(mon
, " dump: %s\n",
2375 m
->value
->dump
? "true" : "false");
2376 monitor_printf(mon
, " prealloc: %s\n",
2377 m
->value
->prealloc
? "true" : "false");
2378 monitor_printf(mon
, " policy: %s\n",
2379 HostMemPolicy_lookup
[m
->value
->policy
]);
2380 visit_complete(v
, &str
);
2381 monitor_printf(mon
, " host nodes: %s\n", str
);
2388 monitor_printf(mon
, "\n");
2390 qapi_free_MemdevList(memdev_list
);
2393 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
2396 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
2397 MemoryDeviceInfoList
*info
;
2398 MemoryDeviceInfo
*value
;
2399 PCDIMMDeviceInfo
*di
;
2401 for (info
= info_list
; info
; info
= info
->next
) {
2402 value
= info
->value
;
2405 switch (value
->type
) {
2406 case MEMORY_DEVICE_INFO_KIND_DIMM
:
2407 di
= value
->u
.dimm
.data
;
2409 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
2410 MemoryDeviceInfoKind_lookup
[value
->type
],
2411 di
->id
? di
->id
: "");
2412 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
2413 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
2414 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
2415 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
2416 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
2417 monitor_printf(mon
, " hotplugged: %s\n",
2418 di
->hotplugged
? "true" : "false");
2419 monitor_printf(mon
, " hotpluggable: %s\n",
2420 di
->hotpluggable
? "true" : "false");
2428 qapi_free_MemoryDeviceInfoList(info_list
);
2431 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
2433 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
2434 IOThreadInfoList
*info
;
2435 IOThreadInfo
*value
;
2437 for (info
= info_list
; info
; info
= info
->next
) {
2438 value
= info
->value
;
2439 monitor_printf(mon
, "%s:\n", value
->id
);
2440 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
2441 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
2442 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
2443 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
2446 qapi_free_IOThreadInfoList(info_list
);
2449 void hmp_qom_list(Monitor
*mon
, const QDict
*qdict
)
2451 const char *path
= qdict_get_try_str(qdict
, "path");
2452 ObjectPropertyInfoList
*list
;
2456 monitor_printf(mon
, "/\n");
2460 list
= qmp_qom_list(path
, &err
);
2462 ObjectPropertyInfoList
*start
= list
;
2463 while (list
!= NULL
) {
2464 ObjectPropertyInfo
*value
= list
->value
;
2466 monitor_printf(mon
, "%s (%s)\n",
2467 value
->name
, value
->type
);
2470 qapi_free_ObjectPropertyInfoList(start
);
2472 hmp_handle_error(mon
, &err
);
2475 void hmp_qom_set(Monitor
*mon
, const QDict
*qdict
)
2477 const char *path
= qdict_get_str(qdict
, "path");
2478 const char *property
= qdict_get_str(qdict
, "property");
2479 const char *value
= qdict_get_str(qdict
, "value");
2481 bool ambiguous
= false;
2484 obj
= object_resolve_path(path
, &ambiguous
);
2486 error_set(&err
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2487 "Device '%s' not found", path
);
2490 monitor_printf(mon
, "Warning: Path '%s' is ambiguous\n", path
);
2492 object_property_parse(obj
, value
, property
, &err
);
2494 hmp_handle_error(mon
, &err
);
2497 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
2499 const char *name
= qdict_get_str(qdict
, "name");
2500 RockerSwitch
*rocker
;
2503 rocker
= qmp_query_rocker(name
, &err
);
2505 hmp_handle_error(mon
, &err
);
2509 monitor_printf(mon
, "name: %s\n", rocker
->name
);
2510 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
2511 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
2513 qapi_free_RockerSwitch(rocker
);
2516 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
2518 RockerPortList
*list
, *port
;
2519 const char *name
= qdict_get_str(qdict
, "name");
2522 list
= qmp_query_rocker_ports(name
, &err
);
2524 hmp_handle_error(mon
, &err
);
2528 monitor_printf(mon
, " ena/ speed/ auto\n");
2529 monitor_printf(mon
, " port link duplex neg?\n");
2531 for (port
= list
; port
; port
= port
->next
) {
2532 monitor_printf(mon
, "%10s %-4s %-3s %2s %-3s\n",
2534 port
->value
->enabled
? port
->value
->link_up
?
2535 "up" : "down" : "!ena",
2536 port
->value
->speed
== 10000 ? "10G" : "??",
2537 port
->value
->duplex
? "FD" : "HD",
2538 port
->value
->autoneg
? "Yes" : "No");
2541 qapi_free_RockerPortList(list
);
2544 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
2546 RockerOfDpaFlowList
*list
, *info
;
2547 const char *name
= qdict_get_str(qdict
, "name");
2548 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
2551 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
2553 hmp_handle_error(mon
, &err
);
2557 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
2559 for (info
= list
; info
; info
= info
->next
) {
2560 RockerOfDpaFlow
*flow
= info
->value
;
2561 RockerOfDpaFlowKey
*key
= flow
->key
;
2562 RockerOfDpaFlowMask
*mask
= flow
->mask
;
2563 RockerOfDpaFlowAction
*action
= flow
->action
;
2566 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
2567 key
->priority
, key
->tbl_id
, flow
->hits
);
2569 monitor_printf(mon
, "%-4d %-3d ",
2570 key
->priority
, key
->tbl_id
);
2573 if (key
->has_in_pport
) {
2574 monitor_printf(mon
, " pport %d", key
->in_pport
);
2575 if (mask
->has_in_pport
) {
2576 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2580 if (key
->has_vlan_id
) {
2581 monitor_printf(mon
, " vlan %d",
2582 key
->vlan_id
& VLAN_VID_MASK
);
2583 if (mask
->has_vlan_id
) {
2584 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2588 if (key
->has_tunnel_id
) {
2589 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2590 if (mask
->has_tunnel_id
) {
2591 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2595 if (key
->has_eth_type
) {
2596 switch (key
->eth_type
) {
2598 monitor_printf(mon
, " ARP");
2601 monitor_printf(mon
, " IP");
2604 monitor_printf(mon
, " IPv6");
2607 monitor_printf(mon
, " LACP");
2610 monitor_printf(mon
, " LLDP");
2613 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2618 if (key
->has_eth_src
) {
2619 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2620 (mask
->has_eth_src
) &&
2621 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2622 monitor_printf(mon
, " src <any mcast/bcast>");
2623 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2624 (mask
->has_eth_src
) &&
2625 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2626 monitor_printf(mon
, " src <any ucast>");
2628 monitor_printf(mon
, " src %s", key
->eth_src
);
2629 if (mask
->has_eth_src
) {
2630 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2635 if (key
->has_eth_dst
) {
2636 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2637 (mask
->has_eth_dst
) &&
2638 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2639 monitor_printf(mon
, " dst <any mcast/bcast>");
2640 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2641 (mask
->has_eth_dst
) &&
2642 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2643 monitor_printf(mon
, " dst <any ucast>");
2645 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2646 if (mask
->has_eth_dst
) {
2647 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2652 if (key
->has_ip_proto
) {
2653 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2654 if (mask
->has_ip_proto
) {
2655 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2659 if (key
->has_ip_tos
) {
2660 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2661 if (mask
->has_ip_tos
) {
2662 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2666 if (key
->has_ip_dst
) {
2667 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2670 if (action
->has_goto_tbl
|| action
->has_group_id
||
2671 action
->has_new_vlan_id
) {
2672 monitor_printf(mon
, " -->");
2675 if (action
->has_new_vlan_id
) {
2676 monitor_printf(mon
, " apply new vlan %d",
2677 ntohs(action
->new_vlan_id
));
2680 if (action
->has_group_id
) {
2681 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2684 if (action
->has_goto_tbl
) {
2685 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2688 monitor_printf(mon
, "\n");
2691 qapi_free_RockerOfDpaFlowList(list
);
2694 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2696 RockerOfDpaGroupList
*list
, *g
;
2697 const char *name
= qdict_get_str(qdict
, "name");
2698 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2702 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
2704 hmp_handle_error(mon
, &err
);
2708 monitor_printf(mon
, "id (decode) --> buckets\n");
2710 for (g
= list
; g
; g
= g
->next
) {
2711 RockerOfDpaGroup
*group
= g
->value
;
2713 monitor_printf(mon
, "0x%08x", group
->id
);
2715 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2716 group
->type
== 1 ? "L2 rewrite" :
2717 group
->type
== 2 ? "L3 unicast" :
2718 group
->type
== 3 ? "L2 multicast" :
2719 group
->type
== 4 ? "L2 flood" :
2720 group
->type
== 5 ? "L3 interface" :
2721 group
->type
== 6 ? "L3 multicast" :
2722 group
->type
== 7 ? "L3 ECMP" :
2723 group
->type
== 8 ? "L2 overlay" :
2726 if (group
->has_vlan_id
) {
2727 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2730 if (group
->has_pport
) {
2731 monitor_printf(mon
, " pport %d", group
->pport
);
2734 if (group
->has_index
) {
2735 monitor_printf(mon
, " index %d", group
->index
);
2738 monitor_printf(mon
, ") -->");
2740 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2742 monitor_printf(mon
, " set vlan %d",
2743 group
->set_vlan_id
& VLAN_VID_MASK
);
2746 if (group
->has_set_eth_src
) {
2749 monitor_printf(mon
, " set");
2751 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2754 if (group
->has_set_eth_dst
) {
2757 monitor_printf(mon
, " set");
2759 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2764 if (group
->has_ttl_check
&& group
->ttl_check
) {
2765 monitor_printf(mon
, " check TTL");
2768 if (group
->has_group_id
&& group
->group_id
) {
2769 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2772 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2773 monitor_printf(mon
, " pop vlan");
2776 if (group
->has_out_pport
) {
2777 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2780 if (group
->has_group_ids
) {
2781 struct uint32List
*id
;
2783 monitor_printf(mon
, " groups [");
2784 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2785 monitor_printf(mon
, "0x%08x", id
->value
);
2787 monitor_printf(mon
, ",");
2790 monitor_printf(mon
, "]");
2793 monitor_printf(mon
, "\n");
2796 qapi_free_RockerOfDpaGroupList(list
);
2799 void hmp_info_dump(Monitor
*mon
, const QDict
*qdict
)
2801 DumpQueryResult
*result
= qmp_query_dump(NULL
);
2803 assert(result
&& result
->status
< DUMP_STATUS__MAX
);
2804 monitor_printf(mon
, "Status: %s\n", DumpStatus_lookup
[result
->status
]);
2806 if (result
->status
== DUMP_STATUS_ACTIVE
) {
2808 assert(result
->total
!= 0);
2809 percent
= 100.0 * result
->completed
/ result
->total
;
2810 monitor_printf(mon
, "Finished: %.2f %%\n", percent
);
2813 qapi_free_DumpQueryResult(result
);
2816 void hmp_info_ramblock(Monitor
*mon
, const QDict
*qdict
)
2818 ram_block_dump(mon
);
2821 void hmp_hotpluggable_cpus(Monitor
*mon
, const QDict
*qdict
)
2824 HotpluggableCPUList
*l
= qmp_query_hotpluggable_cpus(&err
);
2825 HotpluggableCPUList
*saved
= l
;
2826 CpuInstanceProperties
*c
;
2829 hmp_handle_error(mon
, &err
);
2833 monitor_printf(mon
, "Hotpluggable CPUs:\n");
2835 monitor_printf(mon
, " type: \"%s\"\n", l
->value
->type
);
2836 monitor_printf(mon
, " vcpus_count: \"%" PRIu64
"\"\n",
2837 l
->value
->vcpus_count
);
2838 if (l
->value
->has_qom_path
) {
2839 monitor_printf(mon
, " qom_path: \"%s\"\n", l
->value
->qom_path
);
2842 c
= l
->value
->props
;
2843 monitor_printf(mon
, " CPUInstance Properties:\n");
2844 if (c
->has_node_id
) {
2845 monitor_printf(mon
, " node-id: \"%" PRIu64
"\"\n", c
->node_id
);
2847 if (c
->has_socket_id
) {
2848 monitor_printf(mon
, " socket-id: \"%" PRIu64
"\"\n", c
->socket_id
);
2850 if (c
->has_core_id
) {
2851 monitor_printf(mon
, " core-id: \"%" PRIu64
"\"\n", c
->core_id
);
2853 if (c
->has_thread_id
) {
2854 monitor_printf(mon
, " thread-id: \"%" PRIu64
"\"\n", c
->thread_id
);
2860 qapi_free_HotpluggableCPUList(saved
);
2863 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
2866 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
2868 monitor_printf(mon
, "%s\n", info
->guid
);
2870 hmp_handle_error(mon
, &err
);
2871 qapi_free_GuidInfo(info
);