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-visit.h"
35 #include "qom/object_interfaces.h"
36 #include "ui/console.h"
37 #include "block/nbd.h"
38 #include "block/qapi.h"
40 #include "qemu/cutils.h"
41 #include "qemu/error-report.h"
42 #include "exec/ramlist.h"
43 #include "hw/intc/intc.h"
44 #include "migration/snapshot.h"
45 #include "migration/misc.h"
48 #include <spice/enums.h>
51 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
55 error_report_err(*errp
);
59 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
63 info
= qmp_query_name(NULL
);
65 monitor_printf(mon
, "%s\n", info
->name
);
67 qapi_free_NameInfo(info
);
70 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
74 info
= qmp_query_version(NULL
);
76 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
77 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
80 qapi_free_VersionInfo(info
);
83 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
87 info
= qmp_query_kvm(NULL
);
88 monitor_printf(mon
, "kvm support: ");
90 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
92 monitor_printf(mon
, "not compiled\n");
95 qapi_free_KvmInfo(info
);
98 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
102 info
= qmp_query_status(NULL
);
104 monitor_printf(mon
, "VM status: %s%s",
105 info
->running
? "running" : "paused",
106 info
->singlestep
? " (single step mode)" : "");
108 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
109 monitor_printf(mon
, " (%s)", RunState_str(info
->status
));
112 monitor_printf(mon
, "\n");
114 qapi_free_StatusInfo(info
);
117 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
121 info
= qmp_query_uuid(NULL
);
122 monitor_printf(mon
, "%s\n", info
->UUID
);
123 qapi_free_UuidInfo(info
);
126 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
128 ChardevInfoList
*char_info
, *info
;
130 char_info
= qmp_query_chardev(NULL
);
131 for (info
= char_info
; info
; info
= info
->next
) {
132 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
133 info
->value
->filename
);
136 qapi_free_ChardevInfoList(char_info
);
139 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
141 MouseInfoList
*mice_list
, *mouse
;
143 mice_list
= qmp_query_mice(NULL
);
145 monitor_printf(mon
, "No mouse devices connected\n");
149 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
150 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
151 mouse
->value
->current
? '*' : ' ',
152 mouse
->value
->index
, mouse
->value
->name
,
153 mouse
->value
->absolute
? " (absolute)" : "");
156 qapi_free_MouseInfoList(mice_list
);
159 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
162 MigrationCapabilityStatusList
*caps
, *cap
;
164 info
= qmp_query_migrate(NULL
);
165 caps
= qmp_query_migrate_capabilities(NULL
);
167 migration_global_dump(mon
);
169 /* do not display parameters during setup */
170 if (info
->has_status
&& caps
) {
171 monitor_printf(mon
, "capabilities: ");
172 for (cap
= caps
; cap
; cap
= cap
->next
) {
173 monitor_printf(mon
, "%s: %s ",
174 MigrationCapability_str(cap
->value
->capability
),
175 cap
->value
->state
? "on" : "off");
177 monitor_printf(mon
, "\n");
180 if (info
->has_status
) {
181 monitor_printf(mon
, "Migration status: %s",
182 MigrationStatus_str(info
->status
));
183 if (info
->status
== MIGRATION_STATUS_FAILED
&&
184 info
->has_error_desc
) {
185 monitor_printf(mon
, " (%s)\n", info
->error_desc
);
187 monitor_printf(mon
, "\n");
190 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
192 if (info
->has_expected_downtime
) {
193 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
194 info
->expected_downtime
);
196 if (info
->has_downtime
) {
197 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
200 if (info
->has_setup_time
) {
201 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
207 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
208 info
->ram
->transferred
>> 10);
209 monitor_printf(mon
, "throughput: %0.2f mbps\n",
211 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
212 info
->ram
->remaining
>> 10);
213 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
214 info
->ram
->total
>> 10);
215 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
216 info
->ram
->duplicate
);
217 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
219 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
221 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
222 info
->ram
->normal_bytes
>> 10);
223 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
224 info
->ram
->dirty_sync_count
);
225 monitor_printf(mon
, "page size: %" PRIu64
" kbytes\n",
226 info
->ram
->page_size
>> 10);
228 if (info
->ram
->dirty_pages_rate
) {
229 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
230 info
->ram
->dirty_pages_rate
);
232 if (info
->ram
->postcopy_requests
) {
233 monitor_printf(mon
, "postcopy request count: %" PRIu64
"\n",
234 info
->ram
->postcopy_requests
);
238 if (info
->has_disk
) {
239 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
240 info
->disk
->transferred
>> 10);
241 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
242 info
->disk
->remaining
>> 10);
243 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
244 info
->disk
->total
>> 10);
247 if (info
->has_xbzrle_cache
) {
248 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
249 info
->xbzrle_cache
->cache_size
);
250 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
251 info
->xbzrle_cache
->bytes
>> 10);
252 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
253 info
->xbzrle_cache
->pages
);
254 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
255 info
->xbzrle_cache
->cache_miss
);
256 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
257 info
->xbzrle_cache
->cache_miss_rate
);
258 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
259 info
->xbzrle_cache
->overflow
);
262 if (info
->has_cpu_throttle_percentage
) {
263 monitor_printf(mon
, "cpu throttle percentage: %" PRIu64
"\n",
264 info
->cpu_throttle_percentage
);
267 qapi_free_MigrationInfo(info
);
268 qapi_free_MigrationCapabilityStatusList(caps
);
271 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
273 MigrationCapabilityStatusList
*caps
, *cap
;
275 caps
= qmp_query_migrate_capabilities(NULL
);
278 for (cap
= caps
; cap
; cap
= cap
->next
) {
279 monitor_printf(mon
, "%s: %s\n",
280 MigrationCapability_str(cap
->value
->capability
),
281 cap
->value
->state
? "on" : "off");
285 qapi_free_MigrationCapabilityStatusList(caps
);
288 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
290 MigrationParameters
*params
;
292 params
= qmp_query_migrate_parameters(NULL
);
295 assert(params
->has_compress_level
);
296 monitor_printf(mon
, "%s: %" PRId64
"\n",
297 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL
),
298 params
->compress_level
);
299 assert(params
->has_compress_threads
);
300 monitor_printf(mon
, "%s: %" PRId64
"\n",
301 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS
),
302 params
->compress_threads
);
303 assert(params
->has_decompress_threads
);
304 monitor_printf(mon
, "%s: %" PRId64
"\n",
305 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS
),
306 params
->decompress_threads
);
307 assert(params
->has_cpu_throttle_initial
);
308 monitor_printf(mon
, "%s: %" PRId64
"\n",
309 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
),
310 params
->cpu_throttle_initial
);
311 assert(params
->has_cpu_throttle_increment
);
312 monitor_printf(mon
, "%s: %" PRId64
"\n",
313 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
),
314 params
->cpu_throttle_increment
);
315 assert(params
->has_tls_creds
);
316 monitor_printf(mon
, "%s: '%s'\n",
317 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS
),
319 assert(params
->has_tls_hostname
);
320 monitor_printf(mon
, "%s: '%s'\n",
321 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME
),
322 params
->tls_hostname
);
323 assert(params
->has_max_bandwidth
);
324 monitor_printf(mon
, "%s: %" PRId64
" bytes/second\n",
325 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH
),
326 params
->max_bandwidth
);
327 assert(params
->has_downtime_limit
);
328 monitor_printf(mon
, "%s: %" PRId64
" milliseconds\n",
329 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT
),
330 params
->downtime_limit
);
331 assert(params
->has_x_checkpoint_delay
);
332 monitor_printf(mon
, "%s: %" PRId64
"\n",
333 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
),
334 params
->x_checkpoint_delay
);
335 assert(params
->has_block_incremental
);
336 monitor_printf(mon
, "%s: %s\n",
337 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL
),
338 params
->block_incremental
? "on" : "off");
339 monitor_printf(mon
, "%s: %" PRId64
"\n",
340 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_CHANNELS
),
341 params
->x_multifd_channels
);
342 monitor_printf(mon
, "%s: %" PRId64
"\n",
343 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT
),
344 params
->x_multifd_page_count
);
347 qapi_free_MigrationParameters(params
);
350 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
352 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
353 qmp_query_migrate_cache_size(NULL
) >> 10);
356 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
358 CpuInfoList
*cpu_list
, *cpu
;
360 cpu_list
= qmp_query_cpus(NULL
);
362 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
365 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
369 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
371 switch (cpu
->value
->arch
) {
372 case CPU_INFO_ARCH_X86
:
373 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->u
.x86
.pc
);
375 case CPU_INFO_ARCH_PPC
:
376 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->u
.ppc
.nip
);
378 case CPU_INFO_ARCH_SPARC
:
379 monitor_printf(mon
, " pc=0x%016" PRIx64
,
380 cpu
->value
->u
.q_sparc
.pc
);
381 monitor_printf(mon
, " npc=0x%016" PRIx64
,
382 cpu
->value
->u
.q_sparc
.npc
);
384 case CPU_INFO_ARCH_MIPS
:
385 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.q_mips
.PC
);
387 case CPU_INFO_ARCH_TRICORE
:
388 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.tricore
.PC
);
394 if (cpu
->value
->halted
) {
395 monitor_printf(mon
, " (halted)");
398 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
401 qapi_free_CpuInfoList(cpu_list
);
404 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
405 BlockDeviceInfo
*inserted
, bool verbose
)
407 ImageInfo
*image_info
;
409 assert(!info
|| !info
->has_inserted
|| info
->inserted
== inserted
);
411 if (info
&& *info
->device
) {
412 monitor_printf(mon
, "%s", info
->device
);
413 if (inserted
&& inserted
->has_node_name
) {
414 monitor_printf(mon
, " (%s)", inserted
->node_name
);
417 assert(info
|| inserted
);
418 monitor_printf(mon
, "%s",
419 inserted
&& inserted
->has_node_name
? inserted
->node_name
420 : info
&& info
->has_qdev
? info
->qdev
425 monitor_printf(mon
, ": %s (%s%s%s)\n",
428 inserted
->ro
? ", read-only" : "",
429 inserted
->encrypted
? ", encrypted" : "");
431 monitor_printf(mon
, ": [not inserted]\n");
435 if (info
->has_qdev
) {
436 monitor_printf(mon
, " Attached to: %s\n", info
->qdev
);
438 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
439 monitor_printf(mon
, " I/O status: %s\n",
440 BlockDeviceIoStatus_str(info
->io_status
));
443 if (info
->removable
) {
444 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
445 info
->locked
? "" : "not ",
446 info
->tray_open
? "open" : "closed");
455 monitor_printf(mon
, " Cache mode: %s%s%s\n",
456 inserted
->cache
->writeback
? "writeback" : "writethrough",
457 inserted
->cache
->direct
? ", direct" : "",
458 inserted
->cache
->no_flush
? ", ignore flushes" : "");
460 if (inserted
->has_backing_file
) {
463 "(chain depth: %" PRId64
")\n",
464 inserted
->backing_file
,
465 inserted
->backing_file_depth
);
468 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
469 monitor_printf(mon
, " Detect zeroes: %s\n",
470 BlockdevDetectZeroesOptions_str(inserted
->detect_zeroes
));
473 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
474 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
476 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
477 " bps_rd=%" PRId64
" bps_wr=%" PRId64
479 " bps_rd_max=%" PRId64
480 " bps_wr_max=%" PRId64
481 " iops=%" PRId64
" iops_rd=%" PRId64
484 " iops_rd_max=%" PRId64
485 " iops_wr_max=%" PRId64
486 " iops_size=%" PRId64
492 inserted
->bps_rd_max
,
493 inserted
->bps_wr_max
,
498 inserted
->iops_rd_max
,
499 inserted
->iops_wr_max
,
505 monitor_printf(mon
, "\nImages:\n");
506 image_info
= inserted
->image
;
508 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
510 if (image_info
->has_backing_image
) {
511 image_info
= image_info
->backing_image
;
519 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
521 BlockInfoList
*block_list
, *info
;
522 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
523 const char *device
= qdict_get_try_str(qdict
, "device");
524 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
525 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
526 bool printed
= false;
528 /* Print BlockBackend information */
530 block_list
= qmp_query_block(NULL
);
535 for (info
= block_list
; info
; info
= info
->next
) {
536 if (device
&& strcmp(device
, info
->value
->device
)) {
540 if (info
!= block_list
) {
541 monitor_printf(mon
, "\n");
544 print_block_info(mon
, info
->value
, info
->value
->has_inserted
545 ? info
->value
->inserted
: NULL
,
550 qapi_free_BlockInfoList(block_list
);
552 if ((!device
&& !nodes
) || printed
) {
556 /* Print node information */
557 blockdev_list
= qmp_query_named_block_nodes(NULL
);
558 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
559 assert(blockdev
->value
->has_node_name
);
560 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
564 if (blockdev
!= blockdev_list
) {
565 monitor_printf(mon
, "\n");
568 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
570 qapi_free_BlockDeviceInfoList(blockdev_list
);
573 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
575 BlockStatsList
*stats_list
, *stats
;
577 stats_list
= qmp_query_blockstats(false, false, NULL
);
579 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
580 if (!stats
->value
->has_device
) {
584 monitor_printf(mon
, "%s:", stats
->value
->device
);
585 monitor_printf(mon
, " rd_bytes=%" PRId64
587 " rd_operations=%" PRId64
588 " wr_operations=%" PRId64
589 " flush_operations=%" PRId64
590 " wr_total_time_ns=%" PRId64
591 " rd_total_time_ns=%" PRId64
592 " flush_total_time_ns=%" PRId64
593 " rd_merged=%" PRId64
594 " wr_merged=%" PRId64
595 " idle_time_ns=%" PRId64
597 stats
->value
->stats
->rd_bytes
,
598 stats
->value
->stats
->wr_bytes
,
599 stats
->value
->stats
->rd_operations
,
600 stats
->value
->stats
->wr_operations
,
601 stats
->value
->stats
->flush_operations
,
602 stats
->value
->stats
->wr_total_time_ns
,
603 stats
->value
->stats
->rd_total_time_ns
,
604 stats
->value
->stats
->flush_total_time_ns
,
605 stats
->value
->stats
->rd_merged
,
606 stats
->value
->stats
->wr_merged
,
607 stats
->value
->stats
->idle_time_ns
);
610 qapi_free_BlockStatsList(stats_list
);
613 /* Helper for hmp_info_vnc_clients, _servers */
614 static void hmp_info_VncBasicInfo(Monitor
*mon
, VncBasicInfo
*info
,
617 monitor_printf(mon
, " %s: %s:%s (%s%s)\n",
621 NetworkAddressFamily_str(info
->family
),
622 info
->websocket
? " (Websocket)" : "");
625 /* Helper displaying and auth and crypt info */
626 static void hmp_info_vnc_authcrypt(Monitor
*mon
, const char *indent
,
628 VncVencryptSubAuth
*vencrypt
)
630 monitor_printf(mon
, "%sAuth: %s (Sub: %s)\n", indent
,
631 VncPrimaryAuth_str(auth
),
632 vencrypt
? VncVencryptSubAuth_str(*vencrypt
) : "none");
635 static void hmp_info_vnc_clients(Monitor
*mon
, VncClientInfoList
*client
)
638 VncClientInfo
*cinfo
= client
->value
;
640 hmp_info_VncBasicInfo(mon
, qapi_VncClientInfo_base(cinfo
), "Client");
641 monitor_printf(mon
, " x509_dname: %s\n",
642 cinfo
->has_x509_dname
?
643 cinfo
->x509_dname
: "none");
644 monitor_printf(mon
, " sasl_username: %s\n",
645 cinfo
->has_sasl_username
?
646 cinfo
->sasl_username
: "none");
648 client
= client
->next
;
652 static void hmp_info_vnc_servers(Monitor
*mon
, VncServerInfo2List
*server
)
655 VncServerInfo2
*sinfo
= server
->value
;
656 hmp_info_VncBasicInfo(mon
, qapi_VncServerInfo2_base(sinfo
), "Server");
657 hmp_info_vnc_authcrypt(mon
, " ", sinfo
->auth
,
658 sinfo
->has_vencrypt
? &sinfo
->vencrypt
: NULL
);
659 server
= server
->next
;
663 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
665 VncInfo2List
*info2l
;
668 info2l
= qmp_query_vnc_servers(&err
);
670 error_report_err(err
);
674 monitor_printf(mon
, "None\n");
679 VncInfo2
*info
= info2l
->value
;
680 monitor_printf(mon
, "%s:\n", info
->id
);
681 hmp_info_vnc_servers(mon
, info
->server
);
682 hmp_info_vnc_clients(mon
, info
->clients
);
684 /* The server entry displays its auth, we only
685 * need to display in the case of 'reverse' connections
686 * where there's no server.
688 hmp_info_vnc_authcrypt(mon
, " ", info
->auth
,
689 info
->has_vencrypt
? &info
->vencrypt
: NULL
);
691 if (info
->has_display
) {
692 monitor_printf(mon
, " Display: %s\n", info
->display
);
694 info2l
= info2l
->next
;
697 qapi_free_VncInfo2List(info2l
);
702 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
704 SpiceChannelList
*chan
;
706 const char *channel_name
;
707 const char * const channel_names
[] = {
708 [SPICE_CHANNEL_MAIN
] = "main",
709 [SPICE_CHANNEL_DISPLAY
] = "display",
710 [SPICE_CHANNEL_INPUTS
] = "inputs",
711 [SPICE_CHANNEL_CURSOR
] = "cursor",
712 [SPICE_CHANNEL_PLAYBACK
] = "playback",
713 [SPICE_CHANNEL_RECORD
] = "record",
714 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
715 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
716 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
717 [SPICE_CHANNEL_PORT
] = "port",
719 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
720 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
721 * as quick fix for build failures with older versions. */
722 [SPICE_CHANNEL_WEBDAV
] = "webdav",
726 info
= qmp_query_spice(NULL
);
728 if (!info
->enabled
) {
729 monitor_printf(mon
, "Server: disabled\n");
733 monitor_printf(mon
, "Server:\n");
734 if (info
->has_port
) {
735 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
736 info
->host
, info
->port
);
738 if (info
->has_tls_port
) {
739 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
740 info
->host
, info
->tls_port
);
742 monitor_printf(mon
, " migrated: %s\n",
743 info
->migrated
? "true" : "false");
744 monitor_printf(mon
, " auth: %s\n", info
->auth
);
745 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
746 monitor_printf(mon
, " mouse-mode: %s\n",
747 SpiceQueryMouseMode_str(info
->mouse_mode
));
749 if (!info
->has_channels
|| info
->channels
== NULL
) {
750 monitor_printf(mon
, "Channels: none\n");
752 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
753 monitor_printf(mon
, "Channel:\n");
754 monitor_printf(mon
, " address: %s:%s%s\n",
755 chan
->value
->host
, chan
->value
->port
,
756 chan
->value
->tls
? " [tls]" : "");
757 monitor_printf(mon
, " session: %" PRId64
"\n",
758 chan
->value
->connection_id
);
759 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
760 chan
->value
->channel_type
, chan
->value
->channel_id
);
762 channel_name
= "unknown";
763 if (chan
->value
->channel_type
> 0 &&
764 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
765 channel_names
[chan
->value
->channel_type
]) {
766 channel_name
= channel_names
[chan
->value
->channel_type
];
769 monitor_printf(mon
, " channel name: %s\n", channel_name
);
774 qapi_free_SpiceInfo(info
);
778 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
783 info
= qmp_query_balloon(&err
);
785 error_report_err(err
);
789 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
791 qapi_free_BalloonInfo(info
);
794 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
796 PciMemoryRegionList
*region
;
798 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
799 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
800 dev
->slot
, dev
->function
);
801 monitor_printf(mon
, " ");
803 if (dev
->class_info
->has_desc
) {
804 monitor_printf(mon
, "%s", dev
->class_info
->desc
);
806 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
809 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
810 dev
->id
->vendor
, dev
->id
->device
);
813 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
816 if (dev
->has_pci_bridge
) {
817 monitor_printf(mon
, " BUS %" PRId64
".\n",
818 dev
->pci_bridge
->bus
->number
);
819 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
820 dev
->pci_bridge
->bus
->secondary
);
821 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
822 dev
->pci_bridge
->bus
->subordinate
);
824 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
825 dev
->pci_bridge
->bus
->io_range
->base
,
826 dev
->pci_bridge
->bus
->io_range
->limit
);
829 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
830 dev
->pci_bridge
->bus
->memory_range
->base
,
831 dev
->pci_bridge
->bus
->memory_range
->limit
);
833 monitor_printf(mon
, " prefetchable memory range "
834 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
835 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
836 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
839 for (region
= dev
->regions
; region
; region
= region
->next
) {
842 addr
= region
->value
->address
;
843 size
= region
->value
->size
;
845 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
847 if (!strcmp(region
->value
->type
, "io")) {
848 monitor_printf(mon
, "I/O at 0x%04" PRIx64
849 " [0x%04" PRIx64
"].\n",
850 addr
, addr
+ size
- 1);
852 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
853 " [0x%08" PRIx64
"].\n",
854 region
->value
->mem_type_64
? 64 : 32,
855 region
->value
->prefetch
? " prefetchable" : "",
856 addr
, addr
+ size
- 1);
860 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
862 if (dev
->has_pci_bridge
) {
863 if (dev
->pci_bridge
->has_devices
) {
864 PciDeviceInfoList
*cdev
;
865 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
866 hmp_info_pci_device(mon
, cdev
->value
);
872 static int hmp_info_irq_foreach(Object
*obj
, void *opaque
)
874 InterruptStatsProvider
*intc
;
875 InterruptStatsProviderClass
*k
;
876 Monitor
*mon
= opaque
;
878 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
879 intc
= INTERRUPT_STATS_PROVIDER(obj
);
880 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
881 uint64_t *irq_counts
;
882 unsigned int nb_irqs
, i
;
883 if (k
->get_statistics
&&
884 k
->get_statistics(intc
, &irq_counts
, &nb_irqs
)) {
886 monitor_printf(mon
, "IRQ statistics for %s:\n",
887 object_get_typename(obj
));
888 for (i
= 0; i
< nb_irqs
; i
++) {
889 if (irq_counts
[i
] > 0) {
890 monitor_printf(mon
, "%2d: %" PRId64
"\n", i
,
896 monitor_printf(mon
, "IRQ statistics not available for %s.\n",
897 object_get_typename(obj
));
904 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
)
906 object_child_foreach_recursive(object_get_root(),
907 hmp_info_irq_foreach
, mon
);
910 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
912 InterruptStatsProvider
*intc
;
913 InterruptStatsProviderClass
*k
;
914 Monitor
*mon
= opaque
;
916 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
917 intc
= INTERRUPT_STATS_PROVIDER(obj
);
918 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
920 k
->print_info(intc
, mon
);
922 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
923 object_get_typename(obj
));
930 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
932 object_child_foreach_recursive(object_get_root(),
933 hmp_info_pic_foreach
, mon
);
936 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
938 PciInfoList
*info_list
, *info
;
941 info_list
= qmp_query_pci(&err
);
943 monitor_printf(mon
, "PCI devices not supported\n");
948 for (info
= info_list
; info
; info
= info
->next
) {
949 PciDeviceInfoList
*dev
;
951 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
952 hmp_info_pci_device(mon
, dev
->value
);
956 qapi_free_PciInfoList(info_list
);
959 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
961 BlockJobInfoList
*list
;
964 list
= qmp_query_block_jobs(&err
);
968 monitor_printf(mon
, "No active jobs\n");
973 if (strcmp(list
->value
->type
, "stream") == 0) {
974 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
975 " of %" PRId64
" bytes, speed limit %" PRId64
982 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
983 " of %" PRId64
" bytes, speed limit %" PRId64
994 qapi_free_BlockJobInfoList(list
);
997 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
999 TPMInfoList
*info_list
, *info
;
1002 TPMPassthroughOptions
*tpo
;
1003 TPMEmulatorOptions
*teo
;
1005 info_list
= qmp_query_tpm(&err
);
1007 monitor_printf(mon
, "TPM device not supported\n");
1013 monitor_printf(mon
, "TPM device:\n");
1016 for (info
= info_list
; info
; info
= info
->next
) {
1017 TPMInfo
*ti
= info
->value
;
1018 monitor_printf(mon
, " tpm%d: model=%s\n",
1019 c
, TpmModel_str(ti
->model
));
1021 monitor_printf(mon
, " \\ %s: type=%s",
1022 ti
->id
, TpmTypeOptionsKind_str(ti
->options
->type
));
1024 switch (ti
->options
->type
) {
1025 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
1026 tpo
= ti
->options
->u
.passthrough
.data
;
1027 monitor_printf(mon
, "%s%s%s%s",
1028 tpo
->has_path
? ",path=" : "",
1029 tpo
->has_path
? tpo
->path
: "",
1030 tpo
->has_cancel_path
? ",cancel-path=" : "",
1031 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
1033 case TPM_TYPE_OPTIONS_KIND_EMULATOR
:
1034 teo
= ti
->options
->u
.emulator
.data
;
1035 monitor_printf(mon
, ",chardev=%s", teo
->chardev
);
1037 case TPM_TYPE_OPTIONS_KIND__MAX
:
1040 monitor_printf(mon
, "\n");
1043 qapi_free_TPMInfoList(info_list
);
1046 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
1048 monitor_suspend(mon
);
1052 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
1057 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
1059 qmp_system_reset(NULL
);
1062 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
1064 qmp_system_powerdown(NULL
);
1067 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
1071 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1072 use it are converted to the QAPI */
1073 cpu_index
= qdict_get_int(qdict
, "index");
1074 if (monitor_set_cpu(cpu_index
) < 0) {
1075 monitor_printf(mon
, "invalid CPU index\n");
1079 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
1081 uint32_t size
= qdict_get_int(qdict
, "size");
1082 const char *filename
= qdict_get_str(qdict
, "filename");
1083 uint64_t addr
= qdict_get_int(qdict
, "val");
1085 int cpu_index
= monitor_get_cpu_index();
1087 if (cpu_index
< 0) {
1088 monitor_printf(mon
, "No CPU available\n");
1092 qmp_memsave(addr
, size
, filename
, true, cpu_index
, &err
);
1093 hmp_handle_error(mon
, &err
);
1096 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
1098 uint32_t size
= qdict_get_int(qdict
, "size");
1099 const char *filename
= qdict_get_str(qdict
, "filename");
1100 uint64_t addr
= qdict_get_int(qdict
, "val");
1103 qmp_pmemsave(addr
, size
, filename
, &err
);
1104 hmp_handle_error(mon
, &err
);
1107 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
1109 const char *chardev
= qdict_get_str(qdict
, "device");
1110 const char *data
= qdict_get_str(qdict
, "data");
1113 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
1115 hmp_handle_error(mon
, &err
);
1118 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
1120 uint32_t size
= qdict_get_int(qdict
, "size");
1121 const char *chardev
= qdict_get_str(qdict
, "device");
1126 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
1128 error_report_err(err
);
1132 for (i
= 0; data
[i
]; i
++) {
1133 unsigned char ch
= data
[i
];
1136 monitor_printf(mon
, "\\\\");
1137 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
1138 monitor_printf(mon
, "\\u%04X", ch
);
1140 monitor_printf(mon
, "%c", ch
);
1144 monitor_printf(mon
, "\n");
1148 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
1153 hmp_handle_error(mon
, &err
);
1156 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
1158 qmp_system_wakeup(NULL
);
1161 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
1165 qmp_inject_nmi(&err
);
1166 hmp_handle_error(mon
, &err
);
1169 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
1171 const char *name
= qdict_get_str(qdict
, "name");
1172 bool up
= qdict_get_bool(qdict
, "up");
1175 qmp_set_link(name
, up
, &err
);
1176 hmp_handle_error(mon
, &err
);
1179 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
1181 const char *device
= qdict_get_str(qdict
, "device");
1182 const char *password
= qdict_get_str(qdict
, "password");
1185 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
1186 hmp_handle_error(mon
, &err
);
1189 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1191 int64_t value
= qdict_get_int(qdict
, "value");
1194 qmp_balloon(value
, &err
);
1196 error_report_err(err
);
1200 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
1202 const char *device
= qdict_get_str(qdict
, "device");
1203 int64_t size
= qdict_get_int(qdict
, "size");
1206 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
1207 hmp_handle_error(mon
, &err
);
1210 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
1212 const char *filename
= qdict_get_str(qdict
, "target");
1213 const char *format
= qdict_get_try_str(qdict
, "format");
1214 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1215 bool full
= qdict_get_try_bool(qdict
, "full", false);
1217 DriveMirror mirror
= {
1218 .device
= (char *)qdict_get_str(qdict
, "device"),
1219 .target
= (char *)filename
,
1220 .has_format
= !!format
,
1221 .format
= (char *)format
,
1222 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1224 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1229 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1230 hmp_handle_error(mon
, &err
);
1233 qmp_drive_mirror(&mirror
, &err
);
1234 hmp_handle_error(mon
, &err
);
1237 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
1239 const char *device
= qdict_get_str(qdict
, "device");
1240 const char *filename
= qdict_get_str(qdict
, "target");
1241 const char *format
= qdict_get_try_str(qdict
, "format");
1242 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1243 bool full
= qdict_get_try_bool(qdict
, "full", false);
1244 bool compress
= qdict_get_try_bool(qdict
, "compress", false);
1246 DriveBackup backup
= {
1247 .device
= (char *)device
,
1248 .target
= (char *)filename
,
1249 .has_format
= !!format
,
1250 .format
= (char *)format
,
1251 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1253 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1254 .has_compress
= !!compress
,
1255 .compress
= compress
,
1259 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1260 hmp_handle_error(mon
, &err
);
1264 qmp_drive_backup(&backup
, &err
);
1265 hmp_handle_error(mon
, &err
);
1268 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
1270 const char *device
= qdict_get_str(qdict
, "device");
1271 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
1272 const char *format
= qdict_get_try_str(qdict
, "format");
1273 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1274 enum NewImageMode mode
;
1278 /* In the future, if 'snapshot-file' is not specified, the snapshot
1279 will be taken internally. Today it's actually required. */
1280 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
1281 hmp_handle_error(mon
, &err
);
1285 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1286 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
1287 filename
, false, NULL
,
1290 hmp_handle_error(mon
, &err
);
1293 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1295 const char *device
= qdict_get_str(qdict
, "device");
1296 const char *name
= qdict_get_str(qdict
, "name");
1299 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1300 hmp_handle_error(mon
, &err
);
1303 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1305 const char *device
= qdict_get_str(qdict
, "device");
1306 const char *name
= qdict_get_str(qdict
, "name");
1307 const char *id
= qdict_get_try_str(qdict
, "id");
1310 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1312 hmp_handle_error(mon
, &err
);
1315 void hmp_loadvm(Monitor
*mon
, const QDict
*qdict
)
1317 int saved_vm_running
= runstate_is_running();
1318 const char *name
= qdict_get_str(qdict
, "name");
1321 vm_stop(RUN_STATE_RESTORE_VM
);
1323 if (load_snapshot(name
, &err
) == 0 && saved_vm_running
) {
1326 hmp_handle_error(mon
, &err
);
1329 void hmp_savevm(Monitor
*mon
, const QDict
*qdict
)
1333 save_snapshot(qdict_get_try_str(qdict
, "name"), &err
);
1334 hmp_handle_error(mon
, &err
);
1337 void hmp_delvm(Monitor
*mon
, const QDict
*qdict
)
1339 BlockDriverState
*bs
;
1341 const char *name
= qdict_get_str(qdict
, "name");
1343 if (bdrv_all_delete_snapshot(name
, &bs
, &err
) < 0) {
1344 error_reportf_err(err
,
1345 "Error while deleting snapshot on device '%s': ",
1346 bdrv_get_device_name(bs
));
1350 void hmp_info_snapshots(Monitor
*mon
, const QDict
*qdict
)
1352 BlockDriverState
*bs
, *bs1
;
1353 BdrvNextIterator it1
;
1354 QEMUSnapshotInfo
*sn_tab
, *sn
;
1355 bool no_snapshot
= true;
1358 int *global_snapshots
;
1359 AioContext
*aio_context
;
1361 typedef struct SnapshotEntry
{
1362 QEMUSnapshotInfo sn
;
1363 QTAILQ_ENTRY(SnapshotEntry
) next
;
1366 typedef struct ImageEntry
{
1367 const char *imagename
;
1368 QTAILQ_ENTRY(ImageEntry
) next
;
1369 QTAILQ_HEAD(, SnapshotEntry
) snapshots
;
1372 QTAILQ_HEAD(, ImageEntry
) image_list
=
1373 QTAILQ_HEAD_INITIALIZER(image_list
);
1375 ImageEntry
*image_entry
, *next_ie
;
1376 SnapshotEntry
*snapshot_entry
;
1378 bs
= bdrv_all_find_vmstate_bs();
1380 monitor_printf(mon
, "No available block device supports snapshots\n");
1383 aio_context
= bdrv_get_aio_context(bs
);
1385 aio_context_acquire(aio_context
);
1386 nb_sns
= bdrv_snapshot_list(bs
, &sn_tab
);
1387 aio_context_release(aio_context
);
1390 monitor_printf(mon
, "bdrv_snapshot_list: error %d\n", nb_sns
);
1394 for (bs1
= bdrv_first(&it1
); bs1
; bs1
= bdrv_next(&it1
)) {
1398 AioContext
*ctx
= bdrv_get_aio_context(bs1
);
1400 aio_context_acquire(ctx
);
1401 if (bdrv_can_snapshot(bs1
)) {
1403 bs1_nb_sns
= bdrv_snapshot_list(bs1
, &sn
);
1404 if (bs1_nb_sns
> 0) {
1405 no_snapshot
= false;
1406 ie
= g_new0(ImageEntry
, 1);
1407 ie
->imagename
= bdrv_get_device_name(bs1
);
1408 QTAILQ_INIT(&ie
->snapshots
);
1409 QTAILQ_INSERT_TAIL(&image_list
, ie
, next
);
1410 for (i
= 0; i
< bs1_nb_sns
; i
++) {
1411 se
= g_new0(SnapshotEntry
, 1);
1413 QTAILQ_INSERT_TAIL(&ie
->snapshots
, se
, next
);
1418 aio_context_release(ctx
);
1422 monitor_printf(mon
, "There is no snapshot available.\n");
1426 global_snapshots
= g_new0(int, nb_sns
);
1428 for (i
= 0; i
< nb_sns
; i
++) {
1429 SnapshotEntry
*next_sn
;
1430 if (bdrv_all_find_snapshot(sn_tab
[i
].name
, &bs1
) == 0) {
1431 global_snapshots
[total
] = i
;
1433 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1434 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
,
1436 if (!strcmp(sn_tab
[i
].name
, snapshot_entry
->sn
.name
)) {
1437 QTAILQ_REMOVE(&image_entry
->snapshots
, snapshot_entry
,
1439 g_free(snapshot_entry
);
1446 monitor_printf(mon
, "List of snapshots present on all disks:\n");
1449 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1450 monitor_printf(mon
, "\n");
1451 for (i
= 0; i
< total
; i
++) {
1452 sn
= &sn_tab
[global_snapshots
[i
]];
1453 /* The ID is not guaranteed to be the same on all images, so
1456 pstrcpy(sn
->id_str
, sizeof(sn
->id_str
), "--");
1457 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, sn
);
1458 monitor_printf(mon
, "\n");
1461 monitor_printf(mon
, "None\n");
1464 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1465 if (QTAILQ_EMPTY(&image_entry
->snapshots
)) {
1469 "\nList of partial (non-loadable) snapshots on '%s':\n",
1470 image_entry
->imagename
);
1471 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1472 monitor_printf(mon
, "\n");
1473 QTAILQ_FOREACH(snapshot_entry
, &image_entry
->snapshots
, next
) {
1474 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
,
1475 &snapshot_entry
->sn
);
1476 monitor_printf(mon
, "\n");
1480 QTAILQ_FOREACH_SAFE(image_entry
, &image_list
, next
, next_ie
) {
1481 SnapshotEntry
*next_sn
;
1482 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
, next
,
1484 g_free(snapshot_entry
);
1486 g_free(image_entry
);
1489 g_free(global_snapshots
);
1493 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1495 qmp_migrate_cancel(NULL
);
1498 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1501 const char *uri
= qdict_get_str(qdict
, "uri");
1503 qmp_migrate_incoming(uri
, &err
);
1505 hmp_handle_error(mon
, &err
);
1508 /* Kept for backwards compatibility */
1509 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1511 double value
= qdict_get_double(qdict
, "value");
1512 qmp_migrate_set_downtime(value
, NULL
);
1515 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1517 int64_t value
= qdict_get_int(qdict
, "value");
1520 qmp_migrate_set_cache_size(value
, &err
);
1522 error_report_err(err
);
1527 /* Kept for backwards compatibility */
1528 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1530 int64_t value
= qdict_get_int(qdict
, "value");
1531 qmp_migrate_set_speed(value
, NULL
);
1534 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1536 const char *cap
= qdict_get_str(qdict
, "capability");
1537 bool state
= qdict_get_bool(qdict
, "state");
1539 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1542 val
= qapi_enum_parse(&MigrationCapability_lookup
, cap
, -1, &err
);
1547 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1548 caps
->value
->capability
= val
;
1549 caps
->value
->state
= state
;
1551 qmp_migrate_set_capabilities(caps
, &err
);
1554 qapi_free_MigrationCapabilityStatusList(caps
);
1557 error_report_err(err
);
1561 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1563 const char *param
= qdict_get_str(qdict
, "parameter");
1564 const char *valuestr
= qdict_get_str(qdict
, "value");
1565 Visitor
*v
= string_input_visitor_new(valuestr
);
1566 MigrateSetParameters
*p
= g_new0(MigrateSetParameters
, 1);
1567 uint64_t valuebw
= 0;
1571 val
= qapi_enum_parse(&MigrationParameter_lookup
, param
, -1, &err
);
1577 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1578 p
->has_compress_level
= true;
1579 visit_type_int(v
, param
, &p
->compress_level
, &err
);
1581 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1582 p
->has_compress_threads
= true;
1583 visit_type_int(v
, param
, &p
->compress_threads
, &err
);
1585 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1586 p
->has_decompress_threads
= true;
1587 visit_type_int(v
, param
, &p
->decompress_threads
, &err
);
1589 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1590 p
->has_cpu_throttle_initial
= true;
1591 visit_type_int(v
, param
, &p
->cpu_throttle_initial
, &err
);
1593 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1594 p
->has_cpu_throttle_increment
= true;
1595 visit_type_int(v
, param
, &p
->cpu_throttle_increment
, &err
);
1597 case MIGRATION_PARAMETER_TLS_CREDS
:
1598 p
->has_tls_creds
= true;
1599 p
->tls_creds
= g_new0(StrOrNull
, 1);
1600 p
->tls_creds
->type
= QTYPE_QSTRING
;
1601 visit_type_str(v
, param
, &p
->tls_creds
->u
.s
, &err
);
1603 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1604 p
->has_tls_hostname
= true;
1605 p
->tls_hostname
= g_new0(StrOrNull
, 1);
1606 p
->tls_hostname
->type
= QTYPE_QSTRING
;
1607 visit_type_str(v
, param
, &p
->tls_hostname
->u
.s
, &err
);
1609 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1610 p
->has_max_bandwidth
= true;
1612 * Can't use visit_type_size() here, because it
1613 * defaults to Bytes rather than Mebibytes.
1615 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
1616 if (ret
< 0 || valuebw
> INT64_MAX
1617 || (size_t)valuebw
!= valuebw
) {
1618 error_setg(&err
, "Invalid size %s", valuestr
);
1621 p
->max_bandwidth
= valuebw
;
1623 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1624 p
->has_downtime_limit
= true;
1625 visit_type_int(v
, param
, &p
->downtime_limit
, &err
);
1627 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
1628 p
->has_x_checkpoint_delay
= true;
1629 visit_type_int(v
, param
, &p
->x_checkpoint_delay
, &err
);
1631 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL
:
1632 p
->has_block_incremental
= true;
1633 visit_type_bool(v
, param
, &p
->block_incremental
, &err
);
1635 case MIGRATION_PARAMETER_X_MULTIFD_CHANNELS
:
1636 p
->has_x_multifd_channels
= true;
1637 visit_type_int(v
, param
, &p
->x_multifd_channels
, &err
);
1639 case MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT
:
1640 p
->has_x_multifd_page_count
= true;
1641 visit_type_int(v
, param
, &p
->x_multifd_page_count
, &err
);
1651 qmp_migrate_set_parameters(p
, &err
);
1654 qapi_free_MigrateSetParameters(p
);
1657 error_report_err(err
);
1661 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1664 const char *protocol
= qdict_get_str(qdict
, "protocol");
1665 const char *hostname
= qdict_get_str(qdict
, "hostname");
1666 bool has_port
= qdict_haskey(qdict
, "port");
1667 int port
= qdict_get_try_int(qdict
, "port", -1);
1668 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1669 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1670 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1672 qmp_client_migrate_info(protocol
, hostname
,
1673 has_port
, port
, has_tls_port
, tls_port
,
1674 !!cert_subject
, cert_subject
, &err
);
1675 hmp_handle_error(mon
, &err
);
1678 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1681 qmp_migrate_start_postcopy(&err
);
1682 hmp_handle_error(mon
, &err
);
1685 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1689 qmp_x_colo_lost_heartbeat(&err
);
1690 hmp_handle_error(mon
, &err
);
1693 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1695 const char *protocol
= qdict_get_str(qdict
, "protocol");
1696 const char *password
= qdict_get_str(qdict
, "password");
1697 const char *connected
= qdict_get_try_str(qdict
, "connected");
1700 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1701 hmp_handle_error(mon
, &err
);
1704 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1706 const char *protocol
= qdict_get_str(qdict
, "protocol");
1707 const char *whenstr
= qdict_get_str(qdict
, "time");
1710 qmp_expire_password(protocol
, whenstr
, &err
);
1711 hmp_handle_error(mon
, &err
);
1714 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1716 bool force
= qdict_get_try_bool(qdict
, "force", false);
1717 const char *device
= qdict_get_str(qdict
, "device");
1720 qmp_eject(true, device
, false, NULL
, true, force
, &err
);
1721 hmp_handle_error(mon
, &err
);
1724 static void hmp_change_read_arg(void *opaque
, const char *password
,
1725 void *readline_opaque
)
1727 qmp_change_vnc_password(password
, NULL
);
1728 monitor_read_command(opaque
, 1);
1731 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1733 const char *device
= qdict_get_str(qdict
, "device");
1734 const char *target
= qdict_get_str(qdict
, "target");
1735 const char *arg
= qdict_get_try_str(qdict
, "arg");
1736 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1737 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1740 if (strcmp(device
, "vnc") == 0) {
1743 "Parameter 'read-only-mode' is invalid for VNC\n");
1746 if (strcmp(target
, "passwd") == 0 ||
1747 strcmp(target
, "password") == 0) {
1749 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1753 qmp_change("vnc", target
, !!arg
, arg
, &err
);
1757 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup
,
1759 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1761 hmp_handle_error(mon
, &err
);
1766 qmp_blockdev_change_medium(true, device
, false, NULL
, target
,
1767 !!arg
, arg
, !!read_only
, read_only_mode
,
1771 hmp_handle_error(mon
, &err
);
1774 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1777 BlockIOThrottle throttle
= {
1779 .device
= (char *) qdict_get_str(qdict
, "device"),
1780 .bps
= qdict_get_int(qdict
, "bps"),
1781 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
1782 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
1783 .iops
= qdict_get_int(qdict
, "iops"),
1784 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
1785 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
1788 qmp_block_set_io_throttle(&throttle
, &err
);
1789 hmp_handle_error(mon
, &err
);
1792 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1794 Error
*error
= NULL
;
1795 const char *device
= qdict_get_str(qdict
, "device");
1796 const char *base
= qdict_get_try_str(qdict
, "base");
1797 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1799 qmp_block_stream(true, device
, device
, base
!= NULL
, base
, false, NULL
,
1800 false, NULL
, qdict_haskey(qdict
, "speed"), speed
,
1801 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1803 hmp_handle_error(mon
, &error
);
1806 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1808 Error
*error
= NULL
;
1809 const char *device
= qdict_get_str(qdict
, "device");
1810 int64_t value
= qdict_get_int(qdict
, "speed");
1812 qmp_block_job_set_speed(device
, value
, &error
);
1814 hmp_handle_error(mon
, &error
);
1817 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1819 Error
*error
= NULL
;
1820 const char *device
= qdict_get_str(qdict
, "device");
1821 bool force
= qdict_get_try_bool(qdict
, "force", false);
1823 qmp_block_job_cancel(device
, true, force
, &error
);
1825 hmp_handle_error(mon
, &error
);
1828 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1830 Error
*error
= NULL
;
1831 const char *device
= qdict_get_str(qdict
, "device");
1833 qmp_block_job_pause(device
, &error
);
1835 hmp_handle_error(mon
, &error
);
1838 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1840 Error
*error
= NULL
;
1841 const char *device
= qdict_get_str(qdict
, "device");
1843 qmp_block_job_resume(device
, &error
);
1845 hmp_handle_error(mon
, &error
);
1848 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1850 Error
*error
= NULL
;
1851 const char *device
= qdict_get_str(qdict
, "device");
1853 qmp_block_job_complete(device
, &error
);
1855 hmp_handle_error(mon
, &error
);
1858 typedef struct HMPMigrationStatus
1862 bool is_block_migration
;
1863 } HMPMigrationStatus
;
1865 static void hmp_migrate_status_cb(void *opaque
)
1867 HMPMigrationStatus
*status
= opaque
;
1868 MigrationInfo
*info
;
1870 info
= qmp_query_migrate(NULL
);
1871 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1872 info
->status
== MIGRATION_STATUS_SETUP
) {
1873 if (info
->has_disk
) {
1876 if (info
->disk
->remaining
) {
1877 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1882 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1883 monitor_flush(status
->mon
);
1886 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1888 if (status
->is_block_migration
) {
1889 monitor_printf(status
->mon
, "\n");
1891 if (info
->has_error_desc
) {
1892 error_report("%s", info
->error_desc
);
1894 monitor_resume(status
->mon
);
1895 timer_del(status
->timer
);
1899 qapi_free_MigrationInfo(info
);
1902 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1904 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1905 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1906 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1907 const char *uri
= qdict_get_str(qdict
, "uri");
1910 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1912 error_report_err(err
);
1917 HMPMigrationStatus
*status
;
1919 if (monitor_suspend(mon
) < 0) {
1920 monitor_printf(mon
, "terminal does not allow synchronous "
1921 "migration, continuing detached\n");
1925 status
= g_malloc0(sizeof(*status
));
1927 status
->is_block_migration
= blk
|| inc
;
1928 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1930 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1934 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
1938 qmp_device_add((QDict
*)qdict
, NULL
, &err
);
1939 hmp_handle_error(mon
, &err
);
1942 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1944 const char *id
= qdict_get_str(qdict
, "id");
1947 qmp_device_del(id
, &err
);
1948 hmp_handle_error(mon
, &err
);
1951 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1954 bool paging
= qdict_get_try_bool(qdict
, "paging", false);
1955 bool zlib
= qdict_get_try_bool(qdict
, "zlib", false);
1956 bool lzo
= qdict_get_try_bool(qdict
, "lzo", false);
1957 bool snappy
= qdict_get_try_bool(qdict
, "snappy", false);
1958 const char *file
= qdict_get_str(qdict
, "filename");
1959 bool has_begin
= qdict_haskey(qdict
, "begin");
1960 bool has_length
= qdict_haskey(qdict
, "length");
1961 bool has_detach
= qdict_haskey(qdict
, "detach");
1964 bool detach
= false;
1965 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1968 if (zlib
+ lzo
+ snappy
> 1) {
1969 error_setg(&err
, "only one of '-z|-l|-s' can be set");
1970 hmp_handle_error(mon
, &err
);
1975 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
1979 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
1983 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
1987 begin
= qdict_get_int(qdict
, "begin");
1990 length
= qdict_get_int(qdict
, "length");
1993 detach
= qdict_get_bool(qdict
, "detach");
1996 prot
= g_strconcat("file:", file
, NULL
);
1998 qmp_dump_guest_memory(paging
, prot
, true, detach
, has_begin
, begin
,
1999 has_length
, length
, true, dump_format
, &err
);
2000 hmp_handle_error(mon
, &err
);
2004 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
2009 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
2014 netdev_add(opts
, &err
);
2016 qemu_opts_del(opts
);
2020 hmp_handle_error(mon
, &err
);
2023 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
2025 const char *id
= qdict_get_str(qdict
, "id");
2028 qmp_netdev_del(id
, &err
);
2029 hmp_handle_error(mon
, &err
);
2032 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
2038 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
2040 hmp_handle_error(mon
, &err
);
2044 obj
= user_creatable_add_opts(opts
, &err
);
2045 qemu_opts_del(opts
);
2048 hmp_handle_error(mon
, &err
);
2055 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
2057 const char *fdname
= qdict_get_str(qdict
, "fdname");
2060 qmp_getfd(fdname
, &err
);
2061 hmp_handle_error(mon
, &err
);
2064 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
2066 const char *fdname
= qdict_get_str(qdict
, "fdname");
2069 qmp_closefd(fdname
, &err
);
2070 hmp_handle_error(mon
, &err
);
2073 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
2075 const char *keys
= qdict_get_str(qdict
, "keys");
2076 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
2077 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
2078 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
2084 separator
= strchr(keys
, '-');
2085 keyname_len
= separator
? separator
- keys
: strlen(keys
);
2087 /* Be compatible with old interface, convert user inputted "<" */
2088 if (keys
[0] == '<' && keyname_len
== 1) {
2093 keylist
= g_malloc0(sizeof(*keylist
));
2094 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
2100 tmp
->next
= keylist
;
2104 if (strstart(keys
, "0x", NULL
)) {
2106 int value
= strtoul(keys
, &endp
, 0);
2107 assert(endp
<= keys
+ keyname_len
);
2108 if (endp
!= keys
+ keyname_len
) {
2111 keylist
->value
->type
= KEY_VALUE_KIND_NUMBER
;
2112 keylist
->value
->u
.number
.data
= value
;
2114 int idx
= index_from_key(keys
, keyname_len
);
2115 if (idx
== Q_KEY_CODE__MAX
) {
2118 keylist
->value
->type
= KEY_VALUE_KIND_QCODE
;
2119 keylist
->value
->u
.qcode
.data
= idx
;
2125 keys
= separator
+ 1;
2128 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
2129 hmp_handle_error(mon
, &err
);
2132 qapi_free_KeyValueList(head
);
2136 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
2140 void hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
2142 const char *filename
= qdict_get_str(qdict
, "filename");
2145 qmp_screendump(filename
, &err
);
2146 hmp_handle_error(mon
, &err
);
2149 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
2151 const char *uri
= qdict_get_str(qdict
, "uri");
2152 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2153 bool all
= qdict_get_try_bool(qdict
, "all", false);
2154 Error
*local_err
= NULL
;
2155 BlockInfoList
*block_list
, *info
;
2156 SocketAddress
*addr
;
2158 if (writable
&& !all
) {
2159 error_setg(&local_err
, "-w only valid together with -a");
2163 /* First check if the address is valid and start the server. */
2164 addr
= socket_parse(uri
, &local_err
);
2165 if (local_err
!= NULL
) {
2169 nbd_server_start(addr
, NULL
, &local_err
);
2170 qapi_free_SocketAddress(addr
);
2171 if (local_err
!= NULL
) {
2179 /* Then try adding all block devices. If one fails, close all and
2182 block_list
= qmp_query_block(NULL
);
2184 for (info
= block_list
; info
; info
= info
->next
) {
2185 if (!info
->value
->has_inserted
) {
2189 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
2191 if (local_err
!= NULL
) {
2192 qmp_nbd_server_stop(NULL
);
2197 qapi_free_BlockInfoList(block_list
);
2200 hmp_handle_error(mon
, &local_err
);
2203 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
2205 const char *device
= qdict_get_str(qdict
, "device");
2206 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2207 Error
*local_err
= NULL
;
2209 qmp_nbd_server_add(device
, true, writable
, &local_err
);
2211 if (local_err
!= NULL
) {
2212 hmp_handle_error(mon
, &local_err
);
2216 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
2220 qmp_nbd_server_stop(&err
);
2221 hmp_handle_error(mon
, &err
);
2224 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
2229 cpuid
= qdict_get_int(qdict
, "id");
2230 qmp_cpu_add(cpuid
, &err
);
2231 hmp_handle_error(mon
, &err
);
2234 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
2236 const char *args
= qdict_get_str(qdict
, "args");
2240 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
2242 error_setg(&err
, "Parsing chardev args failed");
2244 qemu_chr_new_from_opts(opts
, &err
);
2245 qemu_opts_del(opts
);
2247 hmp_handle_error(mon
, &err
);
2250 void hmp_chardev_change(Monitor
*mon
, const QDict
*qdict
)
2252 const char *args
= qdict_get_str(qdict
, "args");
2255 ChardevBackend
*backend
= NULL
;
2256 ChardevReturn
*ret
= NULL
;
2257 QemuOpts
*opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
,
2260 error_setg(&err
, "Parsing chardev args failed");
2264 id
= qdict_get_str(qdict
, "id");
2265 if (qemu_opts_id(opts
)) {
2266 error_setg(&err
, "Unexpected 'id' parameter");
2270 backend
= qemu_chr_parse_opts(opts
, &err
);
2275 ret
= qmp_chardev_change(id
, backend
, &err
);
2278 qapi_free_ChardevReturn(ret
);
2279 qapi_free_ChardevBackend(backend
);
2280 qemu_opts_del(opts
);
2281 hmp_handle_error(mon
, &err
);
2284 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
2286 Error
*local_err
= NULL
;
2288 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
2289 hmp_handle_error(mon
, &local_err
);
2292 void hmp_chardev_send_break(Monitor
*mon
, const QDict
*qdict
)
2294 Error
*local_err
= NULL
;
2296 qmp_chardev_send_break(qdict_get_str(qdict
, "id"), &local_err
);
2297 hmp_handle_error(mon
, &local_err
);
2300 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
2303 BlockBackend
*local_blk
= NULL
;
2304 AioContext
*aio_context
;
2305 const char* device
= qdict_get_str(qdict
, "device");
2306 const char* command
= qdict_get_str(qdict
, "command");
2310 blk
= blk_by_name(device
);
2312 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, device
, &err
);
2314 blk
= local_blk
= blk_new(0, BLK_PERM_ALL
);
2315 ret
= blk_insert_bs(blk
, bs
, &err
);
2324 aio_context
= blk_get_aio_context(blk
);
2325 aio_context_acquire(aio_context
);
2328 * Notably absent: Proper permission management. This is sad, but it seems
2329 * almost impossible to achieve without changing the semantics and thereby
2330 * limiting the use cases of the qemu-io HMP command.
2332 * In an ideal world we would unconditionally create a new BlockBackend for
2333 * qemuio_command(), but we have commands like 'reopen' and want them to
2334 * take effect on the exact BlockBackend whose name the user passed instead
2335 * of just on a temporary copy of it.
2337 * Another problem is that deleting the temporary BlockBackend involves
2338 * draining all requests on it first, but some qemu-iotests cases want to
2339 * issue multiple aio_read/write requests and expect them to complete in
2340 * the background while the monitor has already returned.
2342 * This is also what prevents us from saving the original permissions and
2343 * restoring them later: We can't revoke permissions until all requests
2344 * have completed, and we don't know when that is nor can we really let
2345 * anything else run before we have revoken them to avoid race conditions.
2347 * What happens now is that command() in qemu-io-cmds.c can extend the
2348 * permissions if necessary for the qemu-io command. And they simply stay
2349 * extended, possibly resulting in a read-only guest device keeping write
2350 * permissions. Ugly, but it appears to be the lesser evil.
2352 qemuio_command(blk
, command
);
2354 aio_context_release(aio_context
);
2357 blk_unref(local_blk
);
2358 hmp_handle_error(mon
, &err
);
2361 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
2363 const char *id
= qdict_get_str(qdict
, "id");
2366 user_creatable_del(id
, &err
);
2367 hmp_handle_error(mon
, &err
);
2370 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
2373 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
2374 MemdevList
*m
= memdev_list
;
2379 v
= string_output_visitor_new(false, &str
);
2380 visit_type_uint16List(v
, NULL
, &m
->value
->host_nodes
, NULL
);
2381 monitor_printf(mon
, "memory backend: %s\n", m
->value
->id
);
2382 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
2383 monitor_printf(mon
, " merge: %s\n",
2384 m
->value
->merge
? "true" : "false");
2385 monitor_printf(mon
, " dump: %s\n",
2386 m
->value
->dump
? "true" : "false");
2387 monitor_printf(mon
, " prealloc: %s\n",
2388 m
->value
->prealloc
? "true" : "false");
2389 monitor_printf(mon
, " policy: %s\n",
2390 HostMemPolicy_str(m
->value
->policy
));
2391 visit_complete(v
, &str
);
2392 monitor_printf(mon
, " host nodes: %s\n", str
);
2399 monitor_printf(mon
, "\n");
2401 qapi_free_MemdevList(memdev_list
);
2402 hmp_handle_error(mon
, &err
);
2405 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
2408 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
2409 MemoryDeviceInfoList
*info
;
2410 MemoryDeviceInfo
*value
;
2411 PCDIMMDeviceInfo
*di
;
2413 for (info
= info_list
; info
; info
= info
->next
) {
2414 value
= info
->value
;
2417 switch (value
->type
) {
2418 case MEMORY_DEVICE_INFO_KIND_DIMM
:
2419 di
= value
->u
.dimm
.data
;
2421 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
2422 MemoryDeviceInfoKind_str(value
->type
),
2423 di
->id
? di
->id
: "");
2424 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
2425 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
2426 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
2427 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
2428 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
2429 monitor_printf(mon
, " hotplugged: %s\n",
2430 di
->hotplugged
? "true" : "false");
2431 monitor_printf(mon
, " hotpluggable: %s\n",
2432 di
->hotpluggable
? "true" : "false");
2440 qapi_free_MemoryDeviceInfoList(info_list
);
2441 hmp_handle_error(mon
, &err
);
2444 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
2446 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
2447 IOThreadInfoList
*info
;
2448 IOThreadInfo
*value
;
2450 for (info
= info_list
; info
; info
= info
->next
) {
2451 value
= info
->value
;
2452 monitor_printf(mon
, "%s:\n", value
->id
);
2453 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
2454 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
2455 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
2456 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
2459 qapi_free_IOThreadInfoList(info_list
);
2462 void hmp_qom_list(Monitor
*mon
, const QDict
*qdict
)
2464 const char *path
= qdict_get_try_str(qdict
, "path");
2465 ObjectPropertyInfoList
*list
;
2469 monitor_printf(mon
, "/\n");
2473 list
= qmp_qom_list(path
, &err
);
2475 ObjectPropertyInfoList
*start
= list
;
2476 while (list
!= NULL
) {
2477 ObjectPropertyInfo
*value
= list
->value
;
2479 monitor_printf(mon
, "%s (%s)\n",
2480 value
->name
, value
->type
);
2483 qapi_free_ObjectPropertyInfoList(start
);
2485 hmp_handle_error(mon
, &err
);
2488 void hmp_qom_set(Monitor
*mon
, const QDict
*qdict
)
2490 const char *path
= qdict_get_str(qdict
, "path");
2491 const char *property
= qdict_get_str(qdict
, "property");
2492 const char *value
= qdict_get_str(qdict
, "value");
2494 bool ambiguous
= false;
2497 obj
= object_resolve_path(path
, &ambiguous
);
2499 error_set(&err
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2500 "Device '%s' not found", path
);
2503 monitor_printf(mon
, "Warning: Path '%s' is ambiguous\n", path
);
2505 object_property_parse(obj
, value
, property
, &err
);
2507 hmp_handle_error(mon
, &err
);
2510 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
2512 const char *name
= qdict_get_str(qdict
, "name");
2513 RockerSwitch
*rocker
;
2516 rocker
= qmp_query_rocker(name
, &err
);
2518 hmp_handle_error(mon
, &err
);
2522 monitor_printf(mon
, "name: %s\n", rocker
->name
);
2523 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
2524 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
2526 qapi_free_RockerSwitch(rocker
);
2529 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
2531 RockerPortList
*list
, *port
;
2532 const char *name
= qdict_get_str(qdict
, "name");
2535 list
= qmp_query_rocker_ports(name
, &err
);
2537 hmp_handle_error(mon
, &err
);
2541 monitor_printf(mon
, " ena/ speed/ auto\n");
2542 monitor_printf(mon
, " port link duplex neg?\n");
2544 for (port
= list
; port
; port
= port
->next
) {
2545 monitor_printf(mon
, "%10s %-4s %-3s %2s %-3s\n",
2547 port
->value
->enabled
? port
->value
->link_up
?
2548 "up" : "down" : "!ena",
2549 port
->value
->speed
== 10000 ? "10G" : "??",
2550 port
->value
->duplex
? "FD" : "HD",
2551 port
->value
->autoneg
? "Yes" : "No");
2554 qapi_free_RockerPortList(list
);
2557 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
2559 RockerOfDpaFlowList
*list
, *info
;
2560 const char *name
= qdict_get_str(qdict
, "name");
2561 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
2564 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
2566 hmp_handle_error(mon
, &err
);
2570 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
2572 for (info
= list
; info
; info
= info
->next
) {
2573 RockerOfDpaFlow
*flow
= info
->value
;
2574 RockerOfDpaFlowKey
*key
= flow
->key
;
2575 RockerOfDpaFlowMask
*mask
= flow
->mask
;
2576 RockerOfDpaFlowAction
*action
= flow
->action
;
2579 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
2580 key
->priority
, key
->tbl_id
, flow
->hits
);
2582 monitor_printf(mon
, "%-4d %-3d ",
2583 key
->priority
, key
->tbl_id
);
2586 if (key
->has_in_pport
) {
2587 monitor_printf(mon
, " pport %d", key
->in_pport
);
2588 if (mask
->has_in_pport
) {
2589 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2593 if (key
->has_vlan_id
) {
2594 monitor_printf(mon
, " vlan %d",
2595 key
->vlan_id
& VLAN_VID_MASK
);
2596 if (mask
->has_vlan_id
) {
2597 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2601 if (key
->has_tunnel_id
) {
2602 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2603 if (mask
->has_tunnel_id
) {
2604 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2608 if (key
->has_eth_type
) {
2609 switch (key
->eth_type
) {
2611 monitor_printf(mon
, " ARP");
2614 monitor_printf(mon
, " IP");
2617 monitor_printf(mon
, " IPv6");
2620 monitor_printf(mon
, " LACP");
2623 monitor_printf(mon
, " LLDP");
2626 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2631 if (key
->has_eth_src
) {
2632 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2633 (mask
->has_eth_src
) &&
2634 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2635 monitor_printf(mon
, " src <any mcast/bcast>");
2636 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2637 (mask
->has_eth_src
) &&
2638 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2639 monitor_printf(mon
, " src <any ucast>");
2641 monitor_printf(mon
, " src %s", key
->eth_src
);
2642 if (mask
->has_eth_src
) {
2643 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2648 if (key
->has_eth_dst
) {
2649 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2650 (mask
->has_eth_dst
) &&
2651 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2652 monitor_printf(mon
, " dst <any mcast/bcast>");
2653 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2654 (mask
->has_eth_dst
) &&
2655 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2656 monitor_printf(mon
, " dst <any ucast>");
2658 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2659 if (mask
->has_eth_dst
) {
2660 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2665 if (key
->has_ip_proto
) {
2666 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2667 if (mask
->has_ip_proto
) {
2668 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2672 if (key
->has_ip_tos
) {
2673 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2674 if (mask
->has_ip_tos
) {
2675 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2679 if (key
->has_ip_dst
) {
2680 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2683 if (action
->has_goto_tbl
|| action
->has_group_id
||
2684 action
->has_new_vlan_id
) {
2685 monitor_printf(mon
, " -->");
2688 if (action
->has_new_vlan_id
) {
2689 monitor_printf(mon
, " apply new vlan %d",
2690 ntohs(action
->new_vlan_id
));
2693 if (action
->has_group_id
) {
2694 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2697 if (action
->has_goto_tbl
) {
2698 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2701 monitor_printf(mon
, "\n");
2704 qapi_free_RockerOfDpaFlowList(list
);
2707 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2709 RockerOfDpaGroupList
*list
, *g
;
2710 const char *name
= qdict_get_str(qdict
, "name");
2711 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2715 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
2717 hmp_handle_error(mon
, &err
);
2721 monitor_printf(mon
, "id (decode) --> buckets\n");
2723 for (g
= list
; g
; g
= g
->next
) {
2724 RockerOfDpaGroup
*group
= g
->value
;
2726 monitor_printf(mon
, "0x%08x", group
->id
);
2728 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2729 group
->type
== 1 ? "L2 rewrite" :
2730 group
->type
== 2 ? "L3 unicast" :
2731 group
->type
== 3 ? "L2 multicast" :
2732 group
->type
== 4 ? "L2 flood" :
2733 group
->type
== 5 ? "L3 interface" :
2734 group
->type
== 6 ? "L3 multicast" :
2735 group
->type
== 7 ? "L3 ECMP" :
2736 group
->type
== 8 ? "L2 overlay" :
2739 if (group
->has_vlan_id
) {
2740 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2743 if (group
->has_pport
) {
2744 monitor_printf(mon
, " pport %d", group
->pport
);
2747 if (group
->has_index
) {
2748 monitor_printf(mon
, " index %d", group
->index
);
2751 monitor_printf(mon
, ") -->");
2753 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2755 monitor_printf(mon
, " set vlan %d",
2756 group
->set_vlan_id
& VLAN_VID_MASK
);
2759 if (group
->has_set_eth_src
) {
2762 monitor_printf(mon
, " set");
2764 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2767 if (group
->has_set_eth_dst
) {
2770 monitor_printf(mon
, " set");
2772 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2777 if (group
->has_ttl_check
&& group
->ttl_check
) {
2778 monitor_printf(mon
, " check TTL");
2781 if (group
->has_group_id
&& group
->group_id
) {
2782 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2785 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2786 monitor_printf(mon
, " pop vlan");
2789 if (group
->has_out_pport
) {
2790 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2793 if (group
->has_group_ids
) {
2794 struct uint32List
*id
;
2796 monitor_printf(mon
, " groups [");
2797 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2798 monitor_printf(mon
, "0x%08x", id
->value
);
2800 monitor_printf(mon
, ",");
2803 monitor_printf(mon
, "]");
2806 monitor_printf(mon
, "\n");
2809 qapi_free_RockerOfDpaGroupList(list
);
2812 void hmp_info_dump(Monitor
*mon
, const QDict
*qdict
)
2814 DumpQueryResult
*result
= qmp_query_dump(NULL
);
2816 assert(result
&& result
->status
< DUMP_STATUS__MAX
);
2817 monitor_printf(mon
, "Status: %s\n", DumpStatus_str(result
->status
));
2819 if (result
->status
== DUMP_STATUS_ACTIVE
) {
2821 assert(result
->total
!= 0);
2822 percent
= 100.0 * result
->completed
/ result
->total
;
2823 monitor_printf(mon
, "Finished: %.2f %%\n", percent
);
2826 qapi_free_DumpQueryResult(result
);
2829 void hmp_info_ramblock(Monitor
*mon
, const QDict
*qdict
)
2831 ram_block_dump(mon
);
2834 void hmp_hotpluggable_cpus(Monitor
*mon
, const QDict
*qdict
)
2837 HotpluggableCPUList
*l
= qmp_query_hotpluggable_cpus(&err
);
2838 HotpluggableCPUList
*saved
= l
;
2839 CpuInstanceProperties
*c
;
2842 hmp_handle_error(mon
, &err
);
2846 monitor_printf(mon
, "Hotpluggable CPUs:\n");
2848 monitor_printf(mon
, " type: \"%s\"\n", l
->value
->type
);
2849 monitor_printf(mon
, " vcpus_count: \"%" PRIu64
"\"\n",
2850 l
->value
->vcpus_count
);
2851 if (l
->value
->has_qom_path
) {
2852 monitor_printf(mon
, " qom_path: \"%s\"\n", l
->value
->qom_path
);
2855 c
= l
->value
->props
;
2856 monitor_printf(mon
, " CPUInstance Properties:\n");
2857 if (c
->has_node_id
) {
2858 monitor_printf(mon
, " node-id: \"%" PRIu64
"\"\n", c
->node_id
);
2860 if (c
->has_socket_id
) {
2861 monitor_printf(mon
, " socket-id: \"%" PRIu64
"\"\n", c
->socket_id
);
2863 if (c
->has_core_id
) {
2864 monitor_printf(mon
, " core-id: \"%" PRIu64
"\"\n", c
->core_id
);
2866 if (c
->has_thread_id
) {
2867 monitor_printf(mon
, " thread-id: \"%" PRIu64
"\"\n", c
->thread_id
);
2873 qapi_free_HotpluggableCPUList(saved
);
2876 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
2879 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
2881 monitor_printf(mon
, "%s\n", info
->guid
);
2883 hmp_handle_error(mon
, &err
);
2884 qapi_free_GuidInfo(info
);
2887 void hmp_info_memory_size_summary(Monitor
*mon
, const QDict
*qdict
)
2890 MemoryInfo
*info
= qmp_query_memory_size_summary(&err
);
2892 monitor_printf(mon
, "base memory: %" PRIu64
"\n",
2895 if (info
->has_plugged_memory
) {
2896 monitor_printf(mon
, "plugged memory: %" PRIu64
"\n",
2897 info
->plugged_memory
);
2900 qapi_free_MemoryInfo(info
);
2902 hmp_handle_error(mon
, &err
);