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_continue(Monitor
*mon
, const QDict
*qdict
)
1501 const char *state
= qdict_get_str(qdict
, "state");
1502 int val
= qapi_enum_parse(&MigrationStatus_lookup
, state
, -1, &err
);
1505 qmp_migrate_continue(val
, &err
);
1508 hmp_handle_error(mon
, &err
);
1511 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1514 const char *uri
= qdict_get_str(qdict
, "uri");
1516 qmp_migrate_incoming(uri
, &err
);
1518 hmp_handle_error(mon
, &err
);
1521 /* Kept for backwards compatibility */
1522 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1524 double value
= qdict_get_double(qdict
, "value");
1525 qmp_migrate_set_downtime(value
, NULL
);
1528 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1530 int64_t value
= qdict_get_int(qdict
, "value");
1533 qmp_migrate_set_cache_size(value
, &err
);
1535 error_report_err(err
);
1540 /* Kept for backwards compatibility */
1541 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1543 int64_t value
= qdict_get_int(qdict
, "value");
1544 qmp_migrate_set_speed(value
, NULL
);
1547 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1549 const char *cap
= qdict_get_str(qdict
, "capability");
1550 bool state
= qdict_get_bool(qdict
, "state");
1552 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1555 val
= qapi_enum_parse(&MigrationCapability_lookup
, cap
, -1, &err
);
1560 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1561 caps
->value
->capability
= val
;
1562 caps
->value
->state
= state
;
1564 qmp_migrate_set_capabilities(caps
, &err
);
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 MigrateSetParameters
*p
= g_new0(MigrateSetParameters
, 1);
1580 uint64_t valuebw
= 0;
1584 val
= qapi_enum_parse(&MigrationParameter_lookup
, param
, -1, &err
);
1590 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1591 p
->has_compress_level
= true;
1592 visit_type_int(v
, param
, &p
->compress_level
, &err
);
1594 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1595 p
->has_compress_threads
= true;
1596 visit_type_int(v
, param
, &p
->compress_threads
, &err
);
1598 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1599 p
->has_decompress_threads
= true;
1600 visit_type_int(v
, param
, &p
->decompress_threads
, &err
);
1602 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1603 p
->has_cpu_throttle_initial
= true;
1604 visit_type_int(v
, param
, &p
->cpu_throttle_initial
, &err
);
1606 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1607 p
->has_cpu_throttle_increment
= true;
1608 visit_type_int(v
, param
, &p
->cpu_throttle_increment
, &err
);
1610 case MIGRATION_PARAMETER_TLS_CREDS
:
1611 p
->has_tls_creds
= true;
1612 p
->tls_creds
= g_new0(StrOrNull
, 1);
1613 p
->tls_creds
->type
= QTYPE_QSTRING
;
1614 visit_type_str(v
, param
, &p
->tls_creds
->u
.s
, &err
);
1616 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1617 p
->has_tls_hostname
= true;
1618 p
->tls_hostname
= g_new0(StrOrNull
, 1);
1619 p
->tls_hostname
->type
= QTYPE_QSTRING
;
1620 visit_type_str(v
, param
, &p
->tls_hostname
->u
.s
, &err
);
1622 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1623 p
->has_max_bandwidth
= true;
1625 * Can't use visit_type_size() here, because it
1626 * defaults to Bytes rather than Mebibytes.
1628 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
1629 if (ret
< 0 || valuebw
> INT64_MAX
1630 || (size_t)valuebw
!= valuebw
) {
1631 error_setg(&err
, "Invalid size %s", valuestr
);
1634 p
->max_bandwidth
= valuebw
;
1636 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1637 p
->has_downtime_limit
= true;
1638 visit_type_int(v
, param
, &p
->downtime_limit
, &err
);
1640 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
1641 p
->has_x_checkpoint_delay
= true;
1642 visit_type_int(v
, param
, &p
->x_checkpoint_delay
, &err
);
1644 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL
:
1645 p
->has_block_incremental
= true;
1646 visit_type_bool(v
, param
, &p
->block_incremental
, &err
);
1648 case MIGRATION_PARAMETER_X_MULTIFD_CHANNELS
:
1649 p
->has_x_multifd_channels
= true;
1650 visit_type_int(v
, param
, &p
->x_multifd_channels
, &err
);
1652 case MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT
:
1653 p
->has_x_multifd_page_count
= true;
1654 visit_type_int(v
, param
, &p
->x_multifd_page_count
, &err
);
1664 qmp_migrate_set_parameters(p
, &err
);
1667 qapi_free_MigrateSetParameters(p
);
1670 error_report_err(err
);
1674 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1677 const char *protocol
= qdict_get_str(qdict
, "protocol");
1678 const char *hostname
= qdict_get_str(qdict
, "hostname");
1679 bool has_port
= qdict_haskey(qdict
, "port");
1680 int port
= qdict_get_try_int(qdict
, "port", -1);
1681 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1682 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1683 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1685 qmp_client_migrate_info(protocol
, hostname
,
1686 has_port
, port
, has_tls_port
, tls_port
,
1687 !!cert_subject
, cert_subject
, &err
);
1688 hmp_handle_error(mon
, &err
);
1691 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1694 qmp_migrate_start_postcopy(&err
);
1695 hmp_handle_error(mon
, &err
);
1698 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1702 qmp_x_colo_lost_heartbeat(&err
);
1703 hmp_handle_error(mon
, &err
);
1706 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1708 const char *protocol
= qdict_get_str(qdict
, "protocol");
1709 const char *password
= qdict_get_str(qdict
, "password");
1710 const char *connected
= qdict_get_try_str(qdict
, "connected");
1713 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1714 hmp_handle_error(mon
, &err
);
1717 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1719 const char *protocol
= qdict_get_str(qdict
, "protocol");
1720 const char *whenstr
= qdict_get_str(qdict
, "time");
1723 qmp_expire_password(protocol
, whenstr
, &err
);
1724 hmp_handle_error(mon
, &err
);
1727 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1729 bool force
= qdict_get_try_bool(qdict
, "force", false);
1730 const char *device
= qdict_get_str(qdict
, "device");
1733 qmp_eject(true, device
, false, NULL
, true, force
, &err
);
1734 hmp_handle_error(mon
, &err
);
1737 static void hmp_change_read_arg(void *opaque
, const char *password
,
1738 void *readline_opaque
)
1740 qmp_change_vnc_password(password
, NULL
);
1741 monitor_read_command(opaque
, 1);
1744 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1746 const char *device
= qdict_get_str(qdict
, "device");
1747 const char *target
= qdict_get_str(qdict
, "target");
1748 const char *arg
= qdict_get_try_str(qdict
, "arg");
1749 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1750 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1753 if (strcmp(device
, "vnc") == 0) {
1756 "Parameter 'read-only-mode' is invalid for VNC\n");
1759 if (strcmp(target
, "passwd") == 0 ||
1760 strcmp(target
, "password") == 0) {
1762 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1766 qmp_change("vnc", target
, !!arg
, arg
, &err
);
1770 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup
,
1772 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1774 hmp_handle_error(mon
, &err
);
1779 qmp_blockdev_change_medium(true, device
, false, NULL
, target
,
1780 !!arg
, arg
, !!read_only
, read_only_mode
,
1784 hmp_handle_error(mon
, &err
);
1787 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1790 BlockIOThrottle throttle
= {
1792 .device
= (char *) qdict_get_str(qdict
, "device"),
1793 .bps
= qdict_get_int(qdict
, "bps"),
1794 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
1795 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
1796 .iops
= qdict_get_int(qdict
, "iops"),
1797 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
1798 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
1801 qmp_block_set_io_throttle(&throttle
, &err
);
1802 hmp_handle_error(mon
, &err
);
1805 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1807 Error
*error
= NULL
;
1808 const char *device
= qdict_get_str(qdict
, "device");
1809 const char *base
= qdict_get_try_str(qdict
, "base");
1810 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1812 qmp_block_stream(true, device
, device
, base
!= NULL
, base
, false, NULL
,
1813 false, NULL
, qdict_haskey(qdict
, "speed"), speed
,
1814 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1816 hmp_handle_error(mon
, &error
);
1819 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1821 Error
*error
= NULL
;
1822 const char *device
= qdict_get_str(qdict
, "device");
1823 int64_t value
= qdict_get_int(qdict
, "speed");
1825 qmp_block_job_set_speed(device
, value
, &error
);
1827 hmp_handle_error(mon
, &error
);
1830 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1832 Error
*error
= NULL
;
1833 const char *device
= qdict_get_str(qdict
, "device");
1834 bool force
= qdict_get_try_bool(qdict
, "force", false);
1836 qmp_block_job_cancel(device
, true, force
, &error
);
1838 hmp_handle_error(mon
, &error
);
1841 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1843 Error
*error
= NULL
;
1844 const char *device
= qdict_get_str(qdict
, "device");
1846 qmp_block_job_pause(device
, &error
);
1848 hmp_handle_error(mon
, &error
);
1851 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1853 Error
*error
= NULL
;
1854 const char *device
= qdict_get_str(qdict
, "device");
1856 qmp_block_job_resume(device
, &error
);
1858 hmp_handle_error(mon
, &error
);
1861 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1863 Error
*error
= NULL
;
1864 const char *device
= qdict_get_str(qdict
, "device");
1866 qmp_block_job_complete(device
, &error
);
1868 hmp_handle_error(mon
, &error
);
1871 typedef struct HMPMigrationStatus
1875 bool is_block_migration
;
1876 } HMPMigrationStatus
;
1878 static void hmp_migrate_status_cb(void *opaque
)
1880 HMPMigrationStatus
*status
= opaque
;
1881 MigrationInfo
*info
;
1883 info
= qmp_query_migrate(NULL
);
1884 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1885 info
->status
== MIGRATION_STATUS_SETUP
) {
1886 if (info
->has_disk
) {
1889 if (info
->disk
->remaining
) {
1890 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1895 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1896 monitor_flush(status
->mon
);
1899 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1901 if (status
->is_block_migration
) {
1902 monitor_printf(status
->mon
, "\n");
1904 if (info
->has_error_desc
) {
1905 error_report("%s", info
->error_desc
);
1907 monitor_resume(status
->mon
);
1908 timer_del(status
->timer
);
1912 qapi_free_MigrationInfo(info
);
1915 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1917 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1918 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1919 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1920 const char *uri
= qdict_get_str(qdict
, "uri");
1923 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1925 error_report_err(err
);
1930 HMPMigrationStatus
*status
;
1932 if (monitor_suspend(mon
) < 0) {
1933 monitor_printf(mon
, "terminal does not allow synchronous "
1934 "migration, continuing detached\n");
1938 status
= g_malloc0(sizeof(*status
));
1940 status
->is_block_migration
= blk
|| inc
;
1941 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1943 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1947 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
1951 qmp_device_add((QDict
*)qdict
, NULL
, &err
);
1952 hmp_handle_error(mon
, &err
);
1955 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1957 const char *id
= qdict_get_str(qdict
, "id");
1960 qmp_device_del(id
, &err
);
1961 hmp_handle_error(mon
, &err
);
1964 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1967 bool paging
= qdict_get_try_bool(qdict
, "paging", false);
1968 bool zlib
= qdict_get_try_bool(qdict
, "zlib", false);
1969 bool lzo
= qdict_get_try_bool(qdict
, "lzo", false);
1970 bool snappy
= qdict_get_try_bool(qdict
, "snappy", false);
1971 const char *file
= qdict_get_str(qdict
, "filename");
1972 bool has_begin
= qdict_haskey(qdict
, "begin");
1973 bool has_length
= qdict_haskey(qdict
, "length");
1974 bool has_detach
= qdict_haskey(qdict
, "detach");
1977 bool detach
= false;
1978 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1981 if (zlib
+ lzo
+ snappy
> 1) {
1982 error_setg(&err
, "only one of '-z|-l|-s' can be set");
1983 hmp_handle_error(mon
, &err
);
1988 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
1992 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
1996 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
2000 begin
= qdict_get_int(qdict
, "begin");
2003 length
= qdict_get_int(qdict
, "length");
2006 detach
= qdict_get_bool(qdict
, "detach");
2009 prot
= g_strconcat("file:", file
, NULL
);
2011 qmp_dump_guest_memory(paging
, prot
, true, detach
, has_begin
, begin
,
2012 has_length
, length
, true, dump_format
, &err
);
2013 hmp_handle_error(mon
, &err
);
2017 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
2022 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
2027 netdev_add(opts
, &err
);
2029 qemu_opts_del(opts
);
2033 hmp_handle_error(mon
, &err
);
2036 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
2038 const char *id
= qdict_get_str(qdict
, "id");
2041 qmp_netdev_del(id
, &err
);
2042 hmp_handle_error(mon
, &err
);
2045 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
2051 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
2053 hmp_handle_error(mon
, &err
);
2057 obj
= user_creatable_add_opts(opts
, &err
);
2058 qemu_opts_del(opts
);
2061 hmp_handle_error(mon
, &err
);
2068 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
2070 const char *fdname
= qdict_get_str(qdict
, "fdname");
2073 qmp_getfd(fdname
, &err
);
2074 hmp_handle_error(mon
, &err
);
2077 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
2079 const char *fdname
= qdict_get_str(qdict
, "fdname");
2082 qmp_closefd(fdname
, &err
);
2083 hmp_handle_error(mon
, &err
);
2086 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
2088 const char *keys
= qdict_get_str(qdict
, "keys");
2089 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
2090 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
2091 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
2097 separator
= strchr(keys
, '-');
2098 keyname_len
= separator
? separator
- keys
: strlen(keys
);
2100 /* Be compatible with old interface, convert user inputted "<" */
2101 if (keys
[0] == '<' && keyname_len
== 1) {
2106 keylist
= g_malloc0(sizeof(*keylist
));
2107 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
2113 tmp
->next
= keylist
;
2117 if (strstart(keys
, "0x", NULL
)) {
2119 int value
= strtoul(keys
, &endp
, 0);
2120 assert(endp
<= keys
+ keyname_len
);
2121 if (endp
!= keys
+ keyname_len
) {
2124 keylist
->value
->type
= KEY_VALUE_KIND_NUMBER
;
2125 keylist
->value
->u
.number
.data
= value
;
2127 int idx
= index_from_key(keys
, keyname_len
);
2128 if (idx
== Q_KEY_CODE__MAX
) {
2131 keylist
->value
->type
= KEY_VALUE_KIND_QCODE
;
2132 keylist
->value
->u
.qcode
.data
= idx
;
2138 keys
= separator
+ 1;
2141 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
2142 hmp_handle_error(mon
, &err
);
2145 qapi_free_KeyValueList(head
);
2149 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
2153 void hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
2155 const char *filename
= qdict_get_str(qdict
, "filename");
2158 qmp_screendump(filename
, &err
);
2159 hmp_handle_error(mon
, &err
);
2162 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
2164 const char *uri
= qdict_get_str(qdict
, "uri");
2165 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2166 bool all
= qdict_get_try_bool(qdict
, "all", false);
2167 Error
*local_err
= NULL
;
2168 BlockInfoList
*block_list
, *info
;
2169 SocketAddress
*addr
;
2171 if (writable
&& !all
) {
2172 error_setg(&local_err
, "-w only valid together with -a");
2176 /* First check if the address is valid and start the server. */
2177 addr
= socket_parse(uri
, &local_err
);
2178 if (local_err
!= NULL
) {
2182 nbd_server_start(addr
, NULL
, &local_err
);
2183 qapi_free_SocketAddress(addr
);
2184 if (local_err
!= NULL
) {
2192 /* Then try adding all block devices. If one fails, close all and
2195 block_list
= qmp_query_block(NULL
);
2197 for (info
= block_list
; info
; info
= info
->next
) {
2198 if (!info
->value
->has_inserted
) {
2202 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
2204 if (local_err
!= NULL
) {
2205 qmp_nbd_server_stop(NULL
);
2210 qapi_free_BlockInfoList(block_list
);
2213 hmp_handle_error(mon
, &local_err
);
2216 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
2218 const char *device
= qdict_get_str(qdict
, "device");
2219 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2220 Error
*local_err
= NULL
;
2222 qmp_nbd_server_add(device
, true, writable
, &local_err
);
2224 if (local_err
!= NULL
) {
2225 hmp_handle_error(mon
, &local_err
);
2229 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
2233 qmp_nbd_server_stop(&err
);
2234 hmp_handle_error(mon
, &err
);
2237 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
2242 cpuid
= qdict_get_int(qdict
, "id");
2243 qmp_cpu_add(cpuid
, &err
);
2244 hmp_handle_error(mon
, &err
);
2247 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
2249 const char *args
= qdict_get_str(qdict
, "args");
2253 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
2255 error_setg(&err
, "Parsing chardev args failed");
2257 qemu_chr_new_from_opts(opts
, &err
);
2258 qemu_opts_del(opts
);
2260 hmp_handle_error(mon
, &err
);
2263 void hmp_chardev_change(Monitor
*mon
, const QDict
*qdict
)
2265 const char *args
= qdict_get_str(qdict
, "args");
2268 ChardevBackend
*backend
= NULL
;
2269 ChardevReturn
*ret
= NULL
;
2270 QemuOpts
*opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
,
2273 error_setg(&err
, "Parsing chardev args failed");
2277 id
= qdict_get_str(qdict
, "id");
2278 if (qemu_opts_id(opts
)) {
2279 error_setg(&err
, "Unexpected 'id' parameter");
2283 backend
= qemu_chr_parse_opts(opts
, &err
);
2288 ret
= qmp_chardev_change(id
, backend
, &err
);
2291 qapi_free_ChardevReturn(ret
);
2292 qapi_free_ChardevBackend(backend
);
2293 qemu_opts_del(opts
);
2294 hmp_handle_error(mon
, &err
);
2297 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
2299 Error
*local_err
= NULL
;
2301 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
2302 hmp_handle_error(mon
, &local_err
);
2305 void hmp_chardev_send_break(Monitor
*mon
, const QDict
*qdict
)
2307 Error
*local_err
= NULL
;
2309 qmp_chardev_send_break(qdict_get_str(qdict
, "id"), &local_err
);
2310 hmp_handle_error(mon
, &local_err
);
2313 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
2316 BlockBackend
*local_blk
= NULL
;
2317 AioContext
*aio_context
;
2318 const char* device
= qdict_get_str(qdict
, "device");
2319 const char* command
= qdict_get_str(qdict
, "command");
2323 blk
= blk_by_name(device
);
2325 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, device
, &err
);
2327 blk
= local_blk
= blk_new(0, BLK_PERM_ALL
);
2328 ret
= blk_insert_bs(blk
, bs
, &err
);
2337 aio_context
= blk_get_aio_context(blk
);
2338 aio_context_acquire(aio_context
);
2341 * Notably absent: Proper permission management. This is sad, but it seems
2342 * almost impossible to achieve without changing the semantics and thereby
2343 * limiting the use cases of the qemu-io HMP command.
2345 * In an ideal world we would unconditionally create a new BlockBackend for
2346 * qemuio_command(), but we have commands like 'reopen' and want them to
2347 * take effect on the exact BlockBackend whose name the user passed instead
2348 * of just on a temporary copy of it.
2350 * Another problem is that deleting the temporary BlockBackend involves
2351 * draining all requests on it first, but some qemu-iotests cases want to
2352 * issue multiple aio_read/write requests and expect them to complete in
2353 * the background while the monitor has already returned.
2355 * This is also what prevents us from saving the original permissions and
2356 * restoring them later: We can't revoke permissions until all requests
2357 * have completed, and we don't know when that is nor can we really let
2358 * anything else run before we have revoken them to avoid race conditions.
2360 * What happens now is that command() in qemu-io-cmds.c can extend the
2361 * permissions if necessary for the qemu-io command. And they simply stay
2362 * extended, possibly resulting in a read-only guest device keeping write
2363 * permissions. Ugly, but it appears to be the lesser evil.
2365 qemuio_command(blk
, command
);
2367 aio_context_release(aio_context
);
2370 blk_unref(local_blk
);
2371 hmp_handle_error(mon
, &err
);
2374 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
2376 const char *id
= qdict_get_str(qdict
, "id");
2379 user_creatable_del(id
, &err
);
2380 hmp_handle_error(mon
, &err
);
2383 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
2386 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
2387 MemdevList
*m
= memdev_list
;
2392 v
= string_output_visitor_new(false, &str
);
2393 visit_type_uint16List(v
, NULL
, &m
->value
->host_nodes
, NULL
);
2394 monitor_printf(mon
, "memory backend: %s\n", m
->value
->id
);
2395 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
2396 monitor_printf(mon
, " merge: %s\n",
2397 m
->value
->merge
? "true" : "false");
2398 monitor_printf(mon
, " dump: %s\n",
2399 m
->value
->dump
? "true" : "false");
2400 monitor_printf(mon
, " prealloc: %s\n",
2401 m
->value
->prealloc
? "true" : "false");
2402 monitor_printf(mon
, " policy: %s\n",
2403 HostMemPolicy_str(m
->value
->policy
));
2404 visit_complete(v
, &str
);
2405 monitor_printf(mon
, " host nodes: %s\n", str
);
2412 monitor_printf(mon
, "\n");
2414 qapi_free_MemdevList(memdev_list
);
2415 hmp_handle_error(mon
, &err
);
2418 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
2421 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
2422 MemoryDeviceInfoList
*info
;
2423 MemoryDeviceInfo
*value
;
2424 PCDIMMDeviceInfo
*di
;
2426 for (info
= info_list
; info
; info
= info
->next
) {
2427 value
= info
->value
;
2430 switch (value
->type
) {
2431 case MEMORY_DEVICE_INFO_KIND_DIMM
:
2432 di
= value
->u
.dimm
.data
;
2434 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
2435 MemoryDeviceInfoKind_str(value
->type
),
2436 di
->id
? di
->id
: "");
2437 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
2438 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
2439 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
2440 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
2441 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
2442 monitor_printf(mon
, " hotplugged: %s\n",
2443 di
->hotplugged
? "true" : "false");
2444 monitor_printf(mon
, " hotpluggable: %s\n",
2445 di
->hotpluggable
? "true" : "false");
2453 qapi_free_MemoryDeviceInfoList(info_list
);
2454 hmp_handle_error(mon
, &err
);
2457 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
2459 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
2460 IOThreadInfoList
*info
;
2461 IOThreadInfo
*value
;
2463 for (info
= info_list
; info
; info
= info
->next
) {
2464 value
= info
->value
;
2465 monitor_printf(mon
, "%s:\n", value
->id
);
2466 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
2467 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
2468 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
2469 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
2472 qapi_free_IOThreadInfoList(info_list
);
2475 void hmp_qom_list(Monitor
*mon
, const QDict
*qdict
)
2477 const char *path
= qdict_get_try_str(qdict
, "path");
2478 ObjectPropertyInfoList
*list
;
2482 monitor_printf(mon
, "/\n");
2486 list
= qmp_qom_list(path
, &err
);
2488 ObjectPropertyInfoList
*start
= list
;
2489 while (list
!= NULL
) {
2490 ObjectPropertyInfo
*value
= list
->value
;
2492 monitor_printf(mon
, "%s (%s)\n",
2493 value
->name
, value
->type
);
2496 qapi_free_ObjectPropertyInfoList(start
);
2498 hmp_handle_error(mon
, &err
);
2501 void hmp_qom_set(Monitor
*mon
, const QDict
*qdict
)
2503 const char *path
= qdict_get_str(qdict
, "path");
2504 const char *property
= qdict_get_str(qdict
, "property");
2505 const char *value
= qdict_get_str(qdict
, "value");
2507 bool ambiguous
= false;
2510 obj
= object_resolve_path(path
, &ambiguous
);
2512 error_set(&err
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2513 "Device '%s' not found", path
);
2516 monitor_printf(mon
, "Warning: Path '%s' is ambiguous\n", path
);
2518 object_property_parse(obj
, value
, property
, &err
);
2520 hmp_handle_error(mon
, &err
);
2523 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
2525 const char *name
= qdict_get_str(qdict
, "name");
2526 RockerSwitch
*rocker
;
2529 rocker
= qmp_query_rocker(name
, &err
);
2531 hmp_handle_error(mon
, &err
);
2535 monitor_printf(mon
, "name: %s\n", rocker
->name
);
2536 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
2537 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
2539 qapi_free_RockerSwitch(rocker
);
2542 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
2544 RockerPortList
*list
, *port
;
2545 const char *name
= qdict_get_str(qdict
, "name");
2548 list
= qmp_query_rocker_ports(name
, &err
);
2550 hmp_handle_error(mon
, &err
);
2554 monitor_printf(mon
, " ena/ speed/ auto\n");
2555 monitor_printf(mon
, " port link duplex neg?\n");
2557 for (port
= list
; port
; port
= port
->next
) {
2558 monitor_printf(mon
, "%10s %-4s %-3s %2s %-3s\n",
2560 port
->value
->enabled
? port
->value
->link_up
?
2561 "up" : "down" : "!ena",
2562 port
->value
->speed
== 10000 ? "10G" : "??",
2563 port
->value
->duplex
? "FD" : "HD",
2564 port
->value
->autoneg
? "Yes" : "No");
2567 qapi_free_RockerPortList(list
);
2570 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
2572 RockerOfDpaFlowList
*list
, *info
;
2573 const char *name
= qdict_get_str(qdict
, "name");
2574 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
2577 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
2579 hmp_handle_error(mon
, &err
);
2583 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
2585 for (info
= list
; info
; info
= info
->next
) {
2586 RockerOfDpaFlow
*flow
= info
->value
;
2587 RockerOfDpaFlowKey
*key
= flow
->key
;
2588 RockerOfDpaFlowMask
*mask
= flow
->mask
;
2589 RockerOfDpaFlowAction
*action
= flow
->action
;
2592 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
2593 key
->priority
, key
->tbl_id
, flow
->hits
);
2595 monitor_printf(mon
, "%-4d %-3d ",
2596 key
->priority
, key
->tbl_id
);
2599 if (key
->has_in_pport
) {
2600 monitor_printf(mon
, " pport %d", key
->in_pport
);
2601 if (mask
->has_in_pport
) {
2602 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2606 if (key
->has_vlan_id
) {
2607 monitor_printf(mon
, " vlan %d",
2608 key
->vlan_id
& VLAN_VID_MASK
);
2609 if (mask
->has_vlan_id
) {
2610 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2614 if (key
->has_tunnel_id
) {
2615 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2616 if (mask
->has_tunnel_id
) {
2617 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2621 if (key
->has_eth_type
) {
2622 switch (key
->eth_type
) {
2624 monitor_printf(mon
, " ARP");
2627 monitor_printf(mon
, " IP");
2630 monitor_printf(mon
, " IPv6");
2633 monitor_printf(mon
, " LACP");
2636 monitor_printf(mon
, " LLDP");
2639 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2644 if (key
->has_eth_src
) {
2645 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2646 (mask
->has_eth_src
) &&
2647 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2648 monitor_printf(mon
, " src <any mcast/bcast>");
2649 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2650 (mask
->has_eth_src
) &&
2651 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2652 monitor_printf(mon
, " src <any ucast>");
2654 monitor_printf(mon
, " src %s", key
->eth_src
);
2655 if (mask
->has_eth_src
) {
2656 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2661 if (key
->has_eth_dst
) {
2662 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2663 (mask
->has_eth_dst
) &&
2664 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2665 monitor_printf(mon
, " dst <any mcast/bcast>");
2666 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2667 (mask
->has_eth_dst
) &&
2668 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2669 monitor_printf(mon
, " dst <any ucast>");
2671 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2672 if (mask
->has_eth_dst
) {
2673 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2678 if (key
->has_ip_proto
) {
2679 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2680 if (mask
->has_ip_proto
) {
2681 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2685 if (key
->has_ip_tos
) {
2686 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2687 if (mask
->has_ip_tos
) {
2688 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2692 if (key
->has_ip_dst
) {
2693 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2696 if (action
->has_goto_tbl
|| action
->has_group_id
||
2697 action
->has_new_vlan_id
) {
2698 monitor_printf(mon
, " -->");
2701 if (action
->has_new_vlan_id
) {
2702 monitor_printf(mon
, " apply new vlan %d",
2703 ntohs(action
->new_vlan_id
));
2706 if (action
->has_group_id
) {
2707 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2710 if (action
->has_goto_tbl
) {
2711 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2714 monitor_printf(mon
, "\n");
2717 qapi_free_RockerOfDpaFlowList(list
);
2720 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2722 RockerOfDpaGroupList
*list
, *g
;
2723 const char *name
= qdict_get_str(qdict
, "name");
2724 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2728 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
2730 hmp_handle_error(mon
, &err
);
2734 monitor_printf(mon
, "id (decode) --> buckets\n");
2736 for (g
= list
; g
; g
= g
->next
) {
2737 RockerOfDpaGroup
*group
= g
->value
;
2739 monitor_printf(mon
, "0x%08x", group
->id
);
2741 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2742 group
->type
== 1 ? "L2 rewrite" :
2743 group
->type
== 2 ? "L3 unicast" :
2744 group
->type
== 3 ? "L2 multicast" :
2745 group
->type
== 4 ? "L2 flood" :
2746 group
->type
== 5 ? "L3 interface" :
2747 group
->type
== 6 ? "L3 multicast" :
2748 group
->type
== 7 ? "L3 ECMP" :
2749 group
->type
== 8 ? "L2 overlay" :
2752 if (group
->has_vlan_id
) {
2753 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2756 if (group
->has_pport
) {
2757 monitor_printf(mon
, " pport %d", group
->pport
);
2760 if (group
->has_index
) {
2761 monitor_printf(mon
, " index %d", group
->index
);
2764 monitor_printf(mon
, ") -->");
2766 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2768 monitor_printf(mon
, " set vlan %d",
2769 group
->set_vlan_id
& VLAN_VID_MASK
);
2772 if (group
->has_set_eth_src
) {
2775 monitor_printf(mon
, " set");
2777 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2780 if (group
->has_set_eth_dst
) {
2783 monitor_printf(mon
, " set");
2785 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2790 if (group
->has_ttl_check
&& group
->ttl_check
) {
2791 monitor_printf(mon
, " check TTL");
2794 if (group
->has_group_id
&& group
->group_id
) {
2795 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2798 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2799 monitor_printf(mon
, " pop vlan");
2802 if (group
->has_out_pport
) {
2803 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2806 if (group
->has_group_ids
) {
2807 struct uint32List
*id
;
2809 monitor_printf(mon
, " groups [");
2810 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2811 monitor_printf(mon
, "0x%08x", id
->value
);
2813 monitor_printf(mon
, ",");
2816 monitor_printf(mon
, "]");
2819 monitor_printf(mon
, "\n");
2822 qapi_free_RockerOfDpaGroupList(list
);
2825 void hmp_info_dump(Monitor
*mon
, const QDict
*qdict
)
2827 DumpQueryResult
*result
= qmp_query_dump(NULL
);
2829 assert(result
&& result
->status
< DUMP_STATUS__MAX
);
2830 monitor_printf(mon
, "Status: %s\n", DumpStatus_str(result
->status
));
2832 if (result
->status
== DUMP_STATUS_ACTIVE
) {
2834 assert(result
->total
!= 0);
2835 percent
= 100.0 * result
->completed
/ result
->total
;
2836 monitor_printf(mon
, "Finished: %.2f %%\n", percent
);
2839 qapi_free_DumpQueryResult(result
);
2842 void hmp_info_ramblock(Monitor
*mon
, const QDict
*qdict
)
2844 ram_block_dump(mon
);
2847 void hmp_hotpluggable_cpus(Monitor
*mon
, const QDict
*qdict
)
2850 HotpluggableCPUList
*l
= qmp_query_hotpluggable_cpus(&err
);
2851 HotpluggableCPUList
*saved
= l
;
2852 CpuInstanceProperties
*c
;
2855 hmp_handle_error(mon
, &err
);
2859 monitor_printf(mon
, "Hotpluggable CPUs:\n");
2861 monitor_printf(mon
, " type: \"%s\"\n", l
->value
->type
);
2862 monitor_printf(mon
, " vcpus_count: \"%" PRIu64
"\"\n",
2863 l
->value
->vcpus_count
);
2864 if (l
->value
->has_qom_path
) {
2865 monitor_printf(mon
, " qom_path: \"%s\"\n", l
->value
->qom_path
);
2868 c
= l
->value
->props
;
2869 monitor_printf(mon
, " CPUInstance Properties:\n");
2870 if (c
->has_node_id
) {
2871 monitor_printf(mon
, " node-id: \"%" PRIu64
"\"\n", c
->node_id
);
2873 if (c
->has_socket_id
) {
2874 monitor_printf(mon
, " socket-id: \"%" PRIu64
"\"\n", c
->socket_id
);
2876 if (c
->has_core_id
) {
2877 monitor_printf(mon
, " core-id: \"%" PRIu64
"\"\n", c
->core_id
);
2879 if (c
->has_thread_id
) {
2880 monitor_printf(mon
, " thread-id: \"%" PRIu64
"\"\n", c
->thread_id
);
2886 qapi_free_HotpluggableCPUList(saved
);
2889 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
2892 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
2894 monitor_printf(mon
, "%s\n", info
->guid
);
2896 hmp_handle_error(mon
, &err
);
2897 qapi_free_GuidInfo(info
);
2900 void hmp_info_memory_size_summary(Monitor
*mon
, const QDict
*qdict
)
2903 MemoryInfo
*info
= qmp_query_memory_size_summary(&err
);
2905 monitor_printf(mon
, "base memory: %" PRIu64
"\n",
2908 if (info
->has_plugged_memory
) {
2909 monitor_printf(mon
, "plugged memory: %" PRIu64
"\n",
2910 info
->plugged_memory
);
2913 qapi_free_MemoryInfo(info
);
2915 hmp_handle_error(mon
, &err
);