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 if (info
->has_postcopy_blocktime
) {
268 monitor_printf(mon
, "postcopy blocktime: %" PRId64
"\n",
269 info
->postcopy_blocktime
);
272 if (info
->has_postcopy_vcpu_blocktime
) {
275 v
= string_output_visitor_new(false, &str
);
276 visit_type_int64List(v
, NULL
, &info
->postcopy_vcpu_blocktime
, NULL
);
277 visit_complete(v
, &str
);
278 monitor_printf(mon
, "postcopy vcpu blocktime: %s\n", str
);
282 qapi_free_MigrationInfo(info
);
283 qapi_free_MigrationCapabilityStatusList(caps
);
286 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
288 MigrationCapabilityStatusList
*caps
, *cap
;
290 caps
= qmp_query_migrate_capabilities(NULL
);
293 for (cap
= caps
; cap
; cap
= cap
->next
) {
294 monitor_printf(mon
, "%s: %s\n",
295 MigrationCapability_str(cap
->value
->capability
),
296 cap
->value
->state
? "on" : "off");
300 qapi_free_MigrationCapabilityStatusList(caps
);
303 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
305 MigrationParameters
*params
;
307 params
= qmp_query_migrate_parameters(NULL
);
310 assert(params
->has_compress_level
);
311 monitor_printf(mon
, "%s: %u\n",
312 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL
),
313 params
->compress_level
);
314 assert(params
->has_compress_threads
);
315 monitor_printf(mon
, "%s: %u\n",
316 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS
),
317 params
->compress_threads
);
318 assert(params
->has_decompress_threads
);
319 monitor_printf(mon
, "%s: %u\n",
320 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS
),
321 params
->decompress_threads
);
322 assert(params
->has_cpu_throttle_initial
);
323 monitor_printf(mon
, "%s: %u\n",
324 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
),
325 params
->cpu_throttle_initial
);
326 assert(params
->has_cpu_throttle_increment
);
327 monitor_printf(mon
, "%s: %u\n",
328 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
),
329 params
->cpu_throttle_increment
);
330 assert(params
->has_tls_creds
);
331 monitor_printf(mon
, "%s: '%s'\n",
332 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS
),
334 assert(params
->has_tls_hostname
);
335 monitor_printf(mon
, "%s: '%s'\n",
336 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME
),
337 params
->tls_hostname
);
338 assert(params
->has_max_bandwidth
);
339 monitor_printf(mon
, "%s: %" PRIu64
" bytes/second\n",
340 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH
),
341 params
->max_bandwidth
);
342 assert(params
->has_downtime_limit
);
343 monitor_printf(mon
, "%s: %" PRIu64
" milliseconds\n",
344 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT
),
345 params
->downtime_limit
);
346 assert(params
->has_x_checkpoint_delay
);
347 monitor_printf(mon
, "%s: %u\n",
348 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
),
349 params
->x_checkpoint_delay
);
350 assert(params
->has_block_incremental
);
351 monitor_printf(mon
, "%s: %s\n",
352 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL
),
353 params
->block_incremental
? "on" : "off");
354 monitor_printf(mon
, "%s: %u\n",
355 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_CHANNELS
),
356 params
->x_multifd_channels
);
357 monitor_printf(mon
, "%s: %u\n",
358 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT
),
359 params
->x_multifd_page_count
);
360 monitor_printf(mon
, "%s: %" PRIu64
"\n",
361 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
),
362 params
->xbzrle_cache_size
);
365 qapi_free_MigrationParameters(params
);
368 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
370 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
371 qmp_query_migrate_cache_size(NULL
) >> 10);
374 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
376 CpuInfoList
*cpu_list
, *cpu
;
378 cpu_list
= qmp_query_cpus(NULL
);
380 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
383 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
387 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
389 switch (cpu
->value
->arch
) {
390 case CPU_INFO_ARCH_X86
:
391 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->u
.x86
.pc
);
393 case CPU_INFO_ARCH_PPC
:
394 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->u
.ppc
.nip
);
396 case CPU_INFO_ARCH_SPARC
:
397 monitor_printf(mon
, " pc=0x%016" PRIx64
,
398 cpu
->value
->u
.q_sparc
.pc
);
399 monitor_printf(mon
, " npc=0x%016" PRIx64
,
400 cpu
->value
->u
.q_sparc
.npc
);
402 case CPU_INFO_ARCH_MIPS
:
403 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.q_mips
.PC
);
405 case CPU_INFO_ARCH_TRICORE
:
406 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.tricore
.PC
);
412 if (cpu
->value
->halted
) {
413 monitor_printf(mon
, " (halted)");
416 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
419 qapi_free_CpuInfoList(cpu_list
);
422 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
423 BlockDeviceInfo
*inserted
, bool verbose
)
425 ImageInfo
*image_info
;
427 assert(!info
|| !info
->has_inserted
|| info
->inserted
== inserted
);
429 if (info
&& *info
->device
) {
430 monitor_printf(mon
, "%s", info
->device
);
431 if (inserted
&& inserted
->has_node_name
) {
432 monitor_printf(mon
, " (%s)", inserted
->node_name
);
435 assert(info
|| inserted
);
436 monitor_printf(mon
, "%s",
437 inserted
&& inserted
->has_node_name
? inserted
->node_name
438 : info
&& info
->has_qdev
? info
->qdev
443 monitor_printf(mon
, ": %s (%s%s%s)\n",
446 inserted
->ro
? ", read-only" : "",
447 inserted
->encrypted
? ", encrypted" : "");
449 monitor_printf(mon
, ": [not inserted]\n");
453 if (info
->has_qdev
) {
454 monitor_printf(mon
, " Attached to: %s\n", info
->qdev
);
456 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
457 monitor_printf(mon
, " I/O status: %s\n",
458 BlockDeviceIoStatus_str(info
->io_status
));
461 if (info
->removable
) {
462 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
463 info
->locked
? "" : "not ",
464 info
->tray_open
? "open" : "closed");
473 monitor_printf(mon
, " Cache mode: %s%s%s\n",
474 inserted
->cache
->writeback
? "writeback" : "writethrough",
475 inserted
->cache
->direct
? ", direct" : "",
476 inserted
->cache
->no_flush
? ", ignore flushes" : "");
478 if (inserted
->has_backing_file
) {
481 "(chain depth: %" PRId64
")\n",
482 inserted
->backing_file
,
483 inserted
->backing_file_depth
);
486 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
487 monitor_printf(mon
, " Detect zeroes: %s\n",
488 BlockdevDetectZeroesOptions_str(inserted
->detect_zeroes
));
491 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
492 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
494 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
495 " bps_rd=%" PRId64
" bps_wr=%" PRId64
497 " bps_rd_max=%" PRId64
498 " bps_wr_max=%" PRId64
499 " iops=%" PRId64
" iops_rd=%" PRId64
502 " iops_rd_max=%" PRId64
503 " iops_wr_max=%" PRId64
504 " iops_size=%" PRId64
510 inserted
->bps_rd_max
,
511 inserted
->bps_wr_max
,
516 inserted
->iops_rd_max
,
517 inserted
->iops_wr_max
,
523 monitor_printf(mon
, "\nImages:\n");
524 image_info
= inserted
->image
;
526 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
528 if (image_info
->has_backing_image
) {
529 image_info
= image_info
->backing_image
;
537 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
539 BlockInfoList
*block_list
, *info
;
540 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
541 const char *device
= qdict_get_try_str(qdict
, "device");
542 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
543 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
544 bool printed
= false;
546 /* Print BlockBackend information */
548 block_list
= qmp_query_block(NULL
);
553 for (info
= block_list
; info
; info
= info
->next
) {
554 if (device
&& strcmp(device
, info
->value
->device
)) {
558 if (info
!= block_list
) {
559 monitor_printf(mon
, "\n");
562 print_block_info(mon
, info
->value
, info
->value
->has_inserted
563 ? info
->value
->inserted
: NULL
,
568 qapi_free_BlockInfoList(block_list
);
570 if ((!device
&& !nodes
) || printed
) {
574 /* Print node information */
575 blockdev_list
= qmp_query_named_block_nodes(NULL
);
576 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
577 assert(blockdev
->value
->has_node_name
);
578 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
582 if (blockdev
!= blockdev_list
) {
583 monitor_printf(mon
, "\n");
586 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
588 qapi_free_BlockDeviceInfoList(blockdev_list
);
591 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
593 BlockStatsList
*stats_list
, *stats
;
595 stats_list
= qmp_query_blockstats(false, false, NULL
);
597 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
598 if (!stats
->value
->has_device
) {
602 monitor_printf(mon
, "%s:", stats
->value
->device
);
603 monitor_printf(mon
, " rd_bytes=%" PRId64
605 " rd_operations=%" PRId64
606 " wr_operations=%" PRId64
607 " flush_operations=%" PRId64
608 " wr_total_time_ns=%" PRId64
609 " rd_total_time_ns=%" PRId64
610 " flush_total_time_ns=%" PRId64
611 " rd_merged=%" PRId64
612 " wr_merged=%" PRId64
613 " idle_time_ns=%" PRId64
615 stats
->value
->stats
->rd_bytes
,
616 stats
->value
->stats
->wr_bytes
,
617 stats
->value
->stats
->rd_operations
,
618 stats
->value
->stats
->wr_operations
,
619 stats
->value
->stats
->flush_operations
,
620 stats
->value
->stats
->wr_total_time_ns
,
621 stats
->value
->stats
->rd_total_time_ns
,
622 stats
->value
->stats
->flush_total_time_ns
,
623 stats
->value
->stats
->rd_merged
,
624 stats
->value
->stats
->wr_merged
,
625 stats
->value
->stats
->idle_time_ns
);
628 qapi_free_BlockStatsList(stats_list
);
631 /* Helper for hmp_info_vnc_clients, _servers */
632 static void hmp_info_VncBasicInfo(Monitor
*mon
, VncBasicInfo
*info
,
635 monitor_printf(mon
, " %s: %s:%s (%s%s)\n",
639 NetworkAddressFamily_str(info
->family
),
640 info
->websocket
? " (Websocket)" : "");
643 /* Helper displaying and auth and crypt info */
644 static void hmp_info_vnc_authcrypt(Monitor
*mon
, const char *indent
,
646 VncVencryptSubAuth
*vencrypt
)
648 monitor_printf(mon
, "%sAuth: %s (Sub: %s)\n", indent
,
649 VncPrimaryAuth_str(auth
),
650 vencrypt
? VncVencryptSubAuth_str(*vencrypt
) : "none");
653 static void hmp_info_vnc_clients(Monitor
*mon
, VncClientInfoList
*client
)
656 VncClientInfo
*cinfo
= client
->value
;
658 hmp_info_VncBasicInfo(mon
, qapi_VncClientInfo_base(cinfo
), "Client");
659 monitor_printf(mon
, " x509_dname: %s\n",
660 cinfo
->has_x509_dname
?
661 cinfo
->x509_dname
: "none");
662 monitor_printf(mon
, " sasl_username: %s\n",
663 cinfo
->has_sasl_username
?
664 cinfo
->sasl_username
: "none");
666 client
= client
->next
;
670 static void hmp_info_vnc_servers(Monitor
*mon
, VncServerInfo2List
*server
)
673 VncServerInfo2
*sinfo
= server
->value
;
674 hmp_info_VncBasicInfo(mon
, qapi_VncServerInfo2_base(sinfo
), "Server");
675 hmp_info_vnc_authcrypt(mon
, " ", sinfo
->auth
,
676 sinfo
->has_vencrypt
? &sinfo
->vencrypt
: NULL
);
677 server
= server
->next
;
681 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
683 VncInfo2List
*info2l
;
686 info2l
= qmp_query_vnc_servers(&err
);
688 hmp_handle_error(mon
, &err
);
692 monitor_printf(mon
, "None\n");
697 VncInfo2
*info
= info2l
->value
;
698 monitor_printf(mon
, "%s:\n", info
->id
);
699 hmp_info_vnc_servers(mon
, info
->server
);
700 hmp_info_vnc_clients(mon
, info
->clients
);
702 /* The server entry displays its auth, we only
703 * need to display in the case of 'reverse' connections
704 * where there's no server.
706 hmp_info_vnc_authcrypt(mon
, " ", info
->auth
,
707 info
->has_vencrypt
? &info
->vencrypt
: NULL
);
709 if (info
->has_display
) {
710 monitor_printf(mon
, " Display: %s\n", info
->display
);
712 info2l
= info2l
->next
;
715 qapi_free_VncInfo2List(info2l
);
720 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
722 SpiceChannelList
*chan
;
724 const char *channel_name
;
725 const char * const channel_names
[] = {
726 [SPICE_CHANNEL_MAIN
] = "main",
727 [SPICE_CHANNEL_DISPLAY
] = "display",
728 [SPICE_CHANNEL_INPUTS
] = "inputs",
729 [SPICE_CHANNEL_CURSOR
] = "cursor",
730 [SPICE_CHANNEL_PLAYBACK
] = "playback",
731 [SPICE_CHANNEL_RECORD
] = "record",
732 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
733 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
734 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
735 [SPICE_CHANNEL_PORT
] = "port",
737 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
738 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
739 * as quick fix for build failures with older versions. */
740 [SPICE_CHANNEL_WEBDAV
] = "webdav",
744 info
= qmp_query_spice(NULL
);
746 if (!info
->enabled
) {
747 monitor_printf(mon
, "Server: disabled\n");
751 monitor_printf(mon
, "Server:\n");
752 if (info
->has_port
) {
753 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
754 info
->host
, info
->port
);
756 if (info
->has_tls_port
) {
757 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
758 info
->host
, info
->tls_port
);
760 monitor_printf(mon
, " migrated: %s\n",
761 info
->migrated
? "true" : "false");
762 monitor_printf(mon
, " auth: %s\n", info
->auth
);
763 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
764 monitor_printf(mon
, " mouse-mode: %s\n",
765 SpiceQueryMouseMode_str(info
->mouse_mode
));
767 if (!info
->has_channels
|| info
->channels
== NULL
) {
768 monitor_printf(mon
, "Channels: none\n");
770 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
771 monitor_printf(mon
, "Channel:\n");
772 monitor_printf(mon
, " address: %s:%s%s\n",
773 chan
->value
->host
, chan
->value
->port
,
774 chan
->value
->tls
? " [tls]" : "");
775 monitor_printf(mon
, " session: %" PRId64
"\n",
776 chan
->value
->connection_id
);
777 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
778 chan
->value
->channel_type
, chan
->value
->channel_id
);
780 channel_name
= "unknown";
781 if (chan
->value
->channel_type
> 0 &&
782 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
783 channel_names
[chan
->value
->channel_type
]) {
784 channel_name
= channel_names
[chan
->value
->channel_type
];
787 monitor_printf(mon
, " channel name: %s\n", channel_name
);
792 qapi_free_SpiceInfo(info
);
796 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
801 info
= qmp_query_balloon(&err
);
803 hmp_handle_error(mon
, &err
);
807 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
809 qapi_free_BalloonInfo(info
);
812 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
814 PciMemoryRegionList
*region
;
816 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
817 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
818 dev
->slot
, dev
->function
);
819 monitor_printf(mon
, " ");
821 if (dev
->class_info
->has_desc
) {
822 monitor_printf(mon
, "%s", dev
->class_info
->desc
);
824 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
827 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
828 dev
->id
->vendor
, dev
->id
->device
);
831 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
834 if (dev
->has_pci_bridge
) {
835 monitor_printf(mon
, " BUS %" PRId64
".\n",
836 dev
->pci_bridge
->bus
->number
);
837 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
838 dev
->pci_bridge
->bus
->secondary
);
839 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
840 dev
->pci_bridge
->bus
->subordinate
);
842 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
843 dev
->pci_bridge
->bus
->io_range
->base
,
844 dev
->pci_bridge
->bus
->io_range
->limit
);
847 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
848 dev
->pci_bridge
->bus
->memory_range
->base
,
849 dev
->pci_bridge
->bus
->memory_range
->limit
);
851 monitor_printf(mon
, " prefetchable memory range "
852 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
853 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
854 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
857 for (region
= dev
->regions
; region
; region
= region
->next
) {
860 addr
= region
->value
->address
;
861 size
= region
->value
->size
;
863 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
865 if (!strcmp(region
->value
->type
, "io")) {
866 monitor_printf(mon
, "I/O at 0x%04" PRIx64
867 " [0x%04" PRIx64
"].\n",
868 addr
, addr
+ size
- 1);
870 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
871 " [0x%08" PRIx64
"].\n",
872 region
->value
->mem_type_64
? 64 : 32,
873 region
->value
->prefetch
? " prefetchable" : "",
874 addr
, addr
+ size
- 1);
878 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
880 if (dev
->has_pci_bridge
) {
881 if (dev
->pci_bridge
->has_devices
) {
882 PciDeviceInfoList
*cdev
;
883 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
884 hmp_info_pci_device(mon
, cdev
->value
);
890 static int hmp_info_irq_foreach(Object
*obj
, void *opaque
)
892 InterruptStatsProvider
*intc
;
893 InterruptStatsProviderClass
*k
;
894 Monitor
*mon
= opaque
;
896 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
897 intc
= INTERRUPT_STATS_PROVIDER(obj
);
898 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
899 uint64_t *irq_counts
;
900 unsigned int nb_irqs
, i
;
901 if (k
->get_statistics
&&
902 k
->get_statistics(intc
, &irq_counts
, &nb_irqs
)) {
904 monitor_printf(mon
, "IRQ statistics for %s:\n",
905 object_get_typename(obj
));
906 for (i
= 0; i
< nb_irqs
; i
++) {
907 if (irq_counts
[i
] > 0) {
908 monitor_printf(mon
, "%2d: %" PRId64
"\n", i
,
914 monitor_printf(mon
, "IRQ statistics not available for %s.\n",
915 object_get_typename(obj
));
922 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
)
924 object_child_foreach_recursive(object_get_root(),
925 hmp_info_irq_foreach
, mon
);
928 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
930 InterruptStatsProvider
*intc
;
931 InterruptStatsProviderClass
*k
;
932 Monitor
*mon
= opaque
;
934 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
935 intc
= INTERRUPT_STATS_PROVIDER(obj
);
936 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
938 k
->print_info(intc
, mon
);
940 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
941 object_get_typename(obj
));
948 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
950 object_child_foreach_recursive(object_get_root(),
951 hmp_info_pic_foreach
, mon
);
954 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
956 PciInfoList
*info_list
, *info
;
959 info_list
= qmp_query_pci(&err
);
961 monitor_printf(mon
, "PCI devices not supported\n");
966 for (info
= info_list
; info
; info
= info
->next
) {
967 PciDeviceInfoList
*dev
;
969 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
970 hmp_info_pci_device(mon
, dev
->value
);
974 qapi_free_PciInfoList(info_list
);
977 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
979 BlockJobInfoList
*list
;
982 list
= qmp_query_block_jobs(&err
);
986 monitor_printf(mon
, "No active jobs\n");
991 if (strcmp(list
->value
->type
, "stream") == 0) {
992 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
993 " of %" PRId64
" bytes, speed limit %" PRId64
1000 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
1001 " of %" PRId64
" bytes, speed limit %" PRId64
1004 list
->value
->device
,
1005 list
->value
->offset
,
1007 list
->value
->speed
);
1012 qapi_free_BlockJobInfoList(list
);
1015 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
1017 TPMInfoList
*info_list
, *info
;
1020 TPMPassthroughOptions
*tpo
;
1021 TPMEmulatorOptions
*teo
;
1023 info_list
= qmp_query_tpm(&err
);
1025 monitor_printf(mon
, "TPM device not supported\n");
1031 monitor_printf(mon
, "TPM device:\n");
1034 for (info
= info_list
; info
; info
= info
->next
) {
1035 TPMInfo
*ti
= info
->value
;
1036 monitor_printf(mon
, " tpm%d: model=%s\n",
1037 c
, TpmModel_str(ti
->model
));
1039 monitor_printf(mon
, " \\ %s: type=%s",
1040 ti
->id
, TpmTypeOptionsKind_str(ti
->options
->type
));
1042 switch (ti
->options
->type
) {
1043 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
1044 tpo
= ti
->options
->u
.passthrough
.data
;
1045 monitor_printf(mon
, "%s%s%s%s",
1046 tpo
->has_path
? ",path=" : "",
1047 tpo
->has_path
? tpo
->path
: "",
1048 tpo
->has_cancel_path
? ",cancel-path=" : "",
1049 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
1051 case TPM_TYPE_OPTIONS_KIND_EMULATOR
:
1052 teo
= ti
->options
->u
.emulator
.data
;
1053 monitor_printf(mon
, ",chardev=%s", teo
->chardev
);
1055 case TPM_TYPE_OPTIONS_KIND__MAX
:
1058 monitor_printf(mon
, "\n");
1061 qapi_free_TPMInfoList(info_list
);
1064 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
1066 monitor_suspend(mon
);
1070 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
1075 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
1077 qmp_system_reset(NULL
);
1080 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
1082 qmp_system_powerdown(NULL
);
1085 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
1089 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1090 use it are converted to the QAPI */
1091 cpu_index
= qdict_get_int(qdict
, "index");
1092 if (monitor_set_cpu(cpu_index
) < 0) {
1093 monitor_printf(mon
, "invalid CPU index\n");
1097 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
1099 uint32_t size
= qdict_get_int(qdict
, "size");
1100 const char *filename
= qdict_get_str(qdict
, "filename");
1101 uint64_t addr
= qdict_get_int(qdict
, "val");
1103 int cpu_index
= monitor_get_cpu_index();
1105 if (cpu_index
< 0) {
1106 monitor_printf(mon
, "No CPU available\n");
1110 qmp_memsave(addr
, size
, filename
, true, cpu_index
, &err
);
1111 hmp_handle_error(mon
, &err
);
1114 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
1116 uint32_t size
= qdict_get_int(qdict
, "size");
1117 const char *filename
= qdict_get_str(qdict
, "filename");
1118 uint64_t addr
= qdict_get_int(qdict
, "val");
1121 qmp_pmemsave(addr
, size
, filename
, &err
);
1122 hmp_handle_error(mon
, &err
);
1125 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
1127 const char *chardev
= qdict_get_str(qdict
, "device");
1128 const char *data
= qdict_get_str(qdict
, "data");
1131 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
1133 hmp_handle_error(mon
, &err
);
1136 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
1138 uint32_t size
= qdict_get_int(qdict
, "size");
1139 const char *chardev
= qdict_get_str(qdict
, "device");
1144 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
1146 hmp_handle_error(mon
, &err
);
1150 for (i
= 0; data
[i
]; i
++) {
1151 unsigned char ch
= data
[i
];
1154 monitor_printf(mon
, "\\\\");
1155 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
1156 monitor_printf(mon
, "\\u%04X", ch
);
1158 monitor_printf(mon
, "%c", ch
);
1162 monitor_printf(mon
, "\n");
1166 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
1171 hmp_handle_error(mon
, &err
);
1174 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
1176 qmp_system_wakeup(NULL
);
1179 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
1183 qmp_inject_nmi(&err
);
1184 hmp_handle_error(mon
, &err
);
1187 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
1189 const char *name
= qdict_get_str(qdict
, "name");
1190 bool up
= qdict_get_bool(qdict
, "up");
1193 qmp_set_link(name
, up
, &err
);
1194 hmp_handle_error(mon
, &err
);
1197 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
1199 const char *device
= qdict_get_str(qdict
, "device");
1200 const char *password
= qdict_get_str(qdict
, "password");
1203 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
1204 hmp_handle_error(mon
, &err
);
1207 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1209 int64_t value
= qdict_get_int(qdict
, "value");
1212 qmp_balloon(value
, &err
);
1213 hmp_handle_error(mon
, &err
);
1216 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
1218 const char *device
= qdict_get_str(qdict
, "device");
1219 int64_t size
= qdict_get_int(qdict
, "size");
1222 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
1223 hmp_handle_error(mon
, &err
);
1226 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
1228 const char *filename
= qdict_get_str(qdict
, "target");
1229 const char *format
= qdict_get_try_str(qdict
, "format");
1230 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1231 bool full
= qdict_get_try_bool(qdict
, "full", false);
1233 DriveMirror mirror
= {
1234 .device
= (char *)qdict_get_str(qdict
, "device"),
1235 .target
= (char *)filename
,
1236 .has_format
= !!format
,
1237 .format
= (char *)format
,
1238 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1240 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1245 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1246 hmp_handle_error(mon
, &err
);
1249 qmp_drive_mirror(&mirror
, &err
);
1250 hmp_handle_error(mon
, &err
);
1253 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
1255 const char *device
= qdict_get_str(qdict
, "device");
1256 const char *filename
= qdict_get_str(qdict
, "target");
1257 const char *format
= qdict_get_try_str(qdict
, "format");
1258 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1259 bool full
= qdict_get_try_bool(qdict
, "full", false);
1260 bool compress
= qdict_get_try_bool(qdict
, "compress", false);
1262 DriveBackup backup
= {
1263 .device
= (char *)device
,
1264 .target
= (char *)filename
,
1265 .has_format
= !!format
,
1266 .format
= (char *)format
,
1267 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1269 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1270 .has_compress
= !!compress
,
1271 .compress
= compress
,
1275 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1276 hmp_handle_error(mon
, &err
);
1280 qmp_drive_backup(&backup
, &err
);
1281 hmp_handle_error(mon
, &err
);
1284 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
1286 const char *device
= qdict_get_str(qdict
, "device");
1287 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
1288 const char *format
= qdict_get_try_str(qdict
, "format");
1289 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1290 enum NewImageMode mode
;
1294 /* In the future, if 'snapshot-file' is not specified, the snapshot
1295 will be taken internally. Today it's actually required. */
1296 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
1297 hmp_handle_error(mon
, &err
);
1301 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1302 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
1303 filename
, false, NULL
,
1306 hmp_handle_error(mon
, &err
);
1309 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1311 const char *device
= qdict_get_str(qdict
, "device");
1312 const char *name
= qdict_get_str(qdict
, "name");
1315 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1316 hmp_handle_error(mon
, &err
);
1319 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1321 const char *device
= qdict_get_str(qdict
, "device");
1322 const char *name
= qdict_get_str(qdict
, "name");
1323 const char *id
= qdict_get_try_str(qdict
, "id");
1326 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1328 hmp_handle_error(mon
, &err
);
1331 void hmp_loadvm(Monitor
*mon
, const QDict
*qdict
)
1333 int saved_vm_running
= runstate_is_running();
1334 const char *name
= qdict_get_str(qdict
, "name");
1337 vm_stop(RUN_STATE_RESTORE_VM
);
1339 if (load_snapshot(name
, &err
) == 0 && saved_vm_running
) {
1342 hmp_handle_error(mon
, &err
);
1345 void hmp_savevm(Monitor
*mon
, const QDict
*qdict
)
1349 save_snapshot(qdict_get_try_str(qdict
, "name"), &err
);
1350 hmp_handle_error(mon
, &err
);
1353 void hmp_delvm(Monitor
*mon
, const QDict
*qdict
)
1355 BlockDriverState
*bs
;
1357 const char *name
= qdict_get_str(qdict
, "name");
1359 if (bdrv_all_delete_snapshot(name
, &bs
, &err
) < 0) {
1360 error_reportf_err(err
,
1361 "Error while deleting snapshot on device '%s': ",
1362 bdrv_get_device_name(bs
));
1366 void hmp_info_snapshots(Monitor
*mon
, const QDict
*qdict
)
1368 BlockDriverState
*bs
, *bs1
;
1369 BdrvNextIterator it1
;
1370 QEMUSnapshotInfo
*sn_tab
, *sn
;
1371 bool no_snapshot
= true;
1374 int *global_snapshots
;
1375 AioContext
*aio_context
;
1377 typedef struct SnapshotEntry
{
1378 QEMUSnapshotInfo sn
;
1379 QTAILQ_ENTRY(SnapshotEntry
) next
;
1382 typedef struct ImageEntry
{
1383 const char *imagename
;
1384 QTAILQ_ENTRY(ImageEntry
) next
;
1385 QTAILQ_HEAD(, SnapshotEntry
) snapshots
;
1388 QTAILQ_HEAD(, ImageEntry
) image_list
=
1389 QTAILQ_HEAD_INITIALIZER(image_list
);
1391 ImageEntry
*image_entry
, *next_ie
;
1392 SnapshotEntry
*snapshot_entry
;
1394 bs
= bdrv_all_find_vmstate_bs();
1396 monitor_printf(mon
, "No available block device supports snapshots\n");
1399 aio_context
= bdrv_get_aio_context(bs
);
1401 aio_context_acquire(aio_context
);
1402 nb_sns
= bdrv_snapshot_list(bs
, &sn_tab
);
1403 aio_context_release(aio_context
);
1406 monitor_printf(mon
, "bdrv_snapshot_list: error %d\n", nb_sns
);
1410 for (bs1
= bdrv_first(&it1
); bs1
; bs1
= bdrv_next(&it1
)) {
1414 AioContext
*ctx
= bdrv_get_aio_context(bs1
);
1416 aio_context_acquire(ctx
);
1417 if (bdrv_can_snapshot(bs1
)) {
1419 bs1_nb_sns
= bdrv_snapshot_list(bs1
, &sn
);
1420 if (bs1_nb_sns
> 0) {
1421 no_snapshot
= false;
1422 ie
= g_new0(ImageEntry
, 1);
1423 ie
->imagename
= bdrv_get_device_name(bs1
);
1424 QTAILQ_INIT(&ie
->snapshots
);
1425 QTAILQ_INSERT_TAIL(&image_list
, ie
, next
);
1426 for (i
= 0; i
< bs1_nb_sns
; i
++) {
1427 se
= g_new0(SnapshotEntry
, 1);
1429 QTAILQ_INSERT_TAIL(&ie
->snapshots
, se
, next
);
1434 aio_context_release(ctx
);
1438 monitor_printf(mon
, "There is no snapshot available.\n");
1442 global_snapshots
= g_new0(int, nb_sns
);
1444 for (i
= 0; i
< nb_sns
; i
++) {
1445 SnapshotEntry
*next_sn
;
1446 if (bdrv_all_find_snapshot(sn_tab
[i
].name
, &bs1
) == 0) {
1447 global_snapshots
[total
] = i
;
1449 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1450 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
,
1452 if (!strcmp(sn_tab
[i
].name
, snapshot_entry
->sn
.name
)) {
1453 QTAILQ_REMOVE(&image_entry
->snapshots
, snapshot_entry
,
1455 g_free(snapshot_entry
);
1462 monitor_printf(mon
, "List of snapshots present on all disks:\n");
1465 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1466 monitor_printf(mon
, "\n");
1467 for (i
= 0; i
< total
; i
++) {
1468 sn
= &sn_tab
[global_snapshots
[i
]];
1469 /* The ID is not guaranteed to be the same on all images, so
1472 pstrcpy(sn
->id_str
, sizeof(sn
->id_str
), "--");
1473 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, sn
);
1474 monitor_printf(mon
, "\n");
1477 monitor_printf(mon
, "None\n");
1480 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1481 if (QTAILQ_EMPTY(&image_entry
->snapshots
)) {
1485 "\nList of partial (non-loadable) snapshots on '%s':\n",
1486 image_entry
->imagename
);
1487 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1488 monitor_printf(mon
, "\n");
1489 QTAILQ_FOREACH(snapshot_entry
, &image_entry
->snapshots
, next
) {
1490 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
,
1491 &snapshot_entry
->sn
);
1492 monitor_printf(mon
, "\n");
1496 QTAILQ_FOREACH_SAFE(image_entry
, &image_list
, next
, next_ie
) {
1497 SnapshotEntry
*next_sn
;
1498 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
, next
,
1500 g_free(snapshot_entry
);
1502 g_free(image_entry
);
1505 g_free(global_snapshots
);
1509 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1511 qmp_migrate_cancel(NULL
);
1514 void hmp_migrate_continue(Monitor
*mon
, const QDict
*qdict
)
1517 const char *state
= qdict_get_str(qdict
, "state");
1518 int val
= qapi_enum_parse(&MigrationStatus_lookup
, state
, -1, &err
);
1521 qmp_migrate_continue(val
, &err
);
1524 hmp_handle_error(mon
, &err
);
1527 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1530 const char *uri
= qdict_get_str(qdict
, "uri");
1532 qmp_migrate_incoming(uri
, &err
);
1534 hmp_handle_error(mon
, &err
);
1537 /* Kept for backwards compatibility */
1538 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1540 double value
= qdict_get_double(qdict
, "value");
1541 qmp_migrate_set_downtime(value
, NULL
);
1544 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1546 int64_t value
= qdict_get_int(qdict
, "value");
1549 qmp_migrate_set_cache_size(value
, &err
);
1550 hmp_handle_error(mon
, &err
);
1553 /* Kept for backwards compatibility */
1554 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1556 int64_t value
= qdict_get_int(qdict
, "value");
1557 qmp_migrate_set_speed(value
, NULL
);
1560 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1562 const char *cap
= qdict_get_str(qdict
, "capability");
1563 bool state
= qdict_get_bool(qdict
, "state");
1565 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1568 val
= qapi_enum_parse(&MigrationCapability_lookup
, cap
, -1, &err
);
1573 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1574 caps
->value
->capability
= val
;
1575 caps
->value
->state
= state
;
1577 qmp_migrate_set_capabilities(caps
, &err
);
1580 qapi_free_MigrationCapabilityStatusList(caps
);
1581 hmp_handle_error(mon
, &err
);
1584 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1586 const char *param
= qdict_get_str(qdict
, "parameter");
1587 const char *valuestr
= qdict_get_str(qdict
, "value");
1588 Visitor
*v
= string_input_visitor_new(valuestr
);
1589 MigrateSetParameters
*p
= g_new0(MigrateSetParameters
, 1);
1590 uint64_t valuebw
= 0;
1591 uint64_t cache_size
;
1595 val
= qapi_enum_parse(&MigrationParameter_lookup
, param
, -1, &err
);
1601 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1602 p
->has_compress_level
= true;
1603 visit_type_int(v
, param
, &p
->compress_level
, &err
);
1605 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1606 p
->has_compress_threads
= true;
1607 visit_type_int(v
, param
, &p
->compress_threads
, &err
);
1609 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1610 p
->has_decompress_threads
= true;
1611 visit_type_int(v
, param
, &p
->decompress_threads
, &err
);
1613 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1614 p
->has_cpu_throttle_initial
= true;
1615 visit_type_int(v
, param
, &p
->cpu_throttle_initial
, &err
);
1617 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1618 p
->has_cpu_throttle_increment
= true;
1619 visit_type_int(v
, param
, &p
->cpu_throttle_increment
, &err
);
1621 case MIGRATION_PARAMETER_TLS_CREDS
:
1622 p
->has_tls_creds
= true;
1623 p
->tls_creds
= g_new0(StrOrNull
, 1);
1624 p
->tls_creds
->type
= QTYPE_QSTRING
;
1625 visit_type_str(v
, param
, &p
->tls_creds
->u
.s
, &err
);
1627 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1628 p
->has_tls_hostname
= true;
1629 p
->tls_hostname
= g_new0(StrOrNull
, 1);
1630 p
->tls_hostname
->type
= QTYPE_QSTRING
;
1631 visit_type_str(v
, param
, &p
->tls_hostname
->u
.s
, &err
);
1633 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1634 p
->has_max_bandwidth
= true;
1636 * Can't use visit_type_size() here, because it
1637 * defaults to Bytes rather than Mebibytes.
1639 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
1640 if (ret
< 0 || valuebw
> INT64_MAX
1641 || (size_t)valuebw
!= valuebw
) {
1642 error_setg(&err
, "Invalid size %s", valuestr
);
1645 p
->max_bandwidth
= valuebw
;
1647 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1648 p
->has_downtime_limit
= true;
1649 visit_type_int(v
, param
, &p
->downtime_limit
, &err
);
1651 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
1652 p
->has_x_checkpoint_delay
= true;
1653 visit_type_int(v
, param
, &p
->x_checkpoint_delay
, &err
);
1655 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL
:
1656 p
->has_block_incremental
= true;
1657 visit_type_bool(v
, param
, &p
->block_incremental
, &err
);
1659 case MIGRATION_PARAMETER_X_MULTIFD_CHANNELS
:
1660 p
->has_x_multifd_channels
= true;
1661 visit_type_int(v
, param
, &p
->x_multifd_channels
, &err
);
1663 case MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT
:
1664 p
->has_x_multifd_page_count
= true;
1665 visit_type_int(v
, param
, &p
->x_multifd_page_count
, &err
);
1667 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
:
1668 p
->has_xbzrle_cache_size
= true;
1669 visit_type_size(v
, param
, &cache_size
, &err
);
1670 if (err
|| cache_size
> INT64_MAX
1671 || (size_t)cache_size
!= cache_size
) {
1672 error_setg(&err
, "Invalid size %s", valuestr
);
1675 p
->xbzrle_cache_size
= cache_size
;
1685 qmp_migrate_set_parameters(p
, &err
);
1688 qapi_free_MigrateSetParameters(p
);
1690 hmp_handle_error(mon
, &err
);
1693 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1696 const char *protocol
= qdict_get_str(qdict
, "protocol");
1697 const char *hostname
= qdict_get_str(qdict
, "hostname");
1698 bool has_port
= qdict_haskey(qdict
, "port");
1699 int port
= qdict_get_try_int(qdict
, "port", -1);
1700 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1701 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1702 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1704 qmp_client_migrate_info(protocol
, hostname
,
1705 has_port
, port
, has_tls_port
, tls_port
,
1706 !!cert_subject
, cert_subject
, &err
);
1707 hmp_handle_error(mon
, &err
);
1710 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1713 qmp_migrate_start_postcopy(&err
);
1714 hmp_handle_error(mon
, &err
);
1717 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1721 qmp_x_colo_lost_heartbeat(&err
);
1722 hmp_handle_error(mon
, &err
);
1725 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1727 const char *protocol
= qdict_get_str(qdict
, "protocol");
1728 const char *password
= qdict_get_str(qdict
, "password");
1729 const char *connected
= qdict_get_try_str(qdict
, "connected");
1732 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1733 hmp_handle_error(mon
, &err
);
1736 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1738 const char *protocol
= qdict_get_str(qdict
, "protocol");
1739 const char *whenstr
= qdict_get_str(qdict
, "time");
1742 qmp_expire_password(protocol
, whenstr
, &err
);
1743 hmp_handle_error(mon
, &err
);
1746 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1748 bool force
= qdict_get_try_bool(qdict
, "force", false);
1749 const char *device
= qdict_get_str(qdict
, "device");
1752 qmp_eject(true, device
, false, NULL
, true, force
, &err
);
1753 hmp_handle_error(mon
, &err
);
1756 static void hmp_change_read_arg(void *opaque
, const char *password
,
1757 void *readline_opaque
)
1759 qmp_change_vnc_password(password
, NULL
);
1760 monitor_read_command(opaque
, 1);
1763 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1765 const char *device
= qdict_get_str(qdict
, "device");
1766 const char *target
= qdict_get_str(qdict
, "target");
1767 const char *arg
= qdict_get_try_str(qdict
, "arg");
1768 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1769 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1772 if (strcmp(device
, "vnc") == 0) {
1775 "Parameter 'read-only-mode' is invalid for VNC\n");
1778 if (strcmp(target
, "passwd") == 0 ||
1779 strcmp(target
, "password") == 0) {
1781 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1785 qmp_change("vnc", target
, !!arg
, arg
, &err
);
1789 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup
,
1791 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1793 hmp_handle_error(mon
, &err
);
1798 qmp_blockdev_change_medium(true, device
, false, NULL
, target
,
1799 !!arg
, arg
, !!read_only
, read_only_mode
,
1803 hmp_handle_error(mon
, &err
);
1806 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1809 BlockIOThrottle throttle
= {
1811 .device
= (char *) qdict_get_str(qdict
, "device"),
1812 .bps
= qdict_get_int(qdict
, "bps"),
1813 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
1814 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
1815 .iops
= qdict_get_int(qdict
, "iops"),
1816 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
1817 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
1820 qmp_block_set_io_throttle(&throttle
, &err
);
1821 hmp_handle_error(mon
, &err
);
1824 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1826 Error
*error
= NULL
;
1827 const char *device
= qdict_get_str(qdict
, "device");
1828 const char *base
= qdict_get_try_str(qdict
, "base");
1829 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1831 qmp_block_stream(true, device
, device
, base
!= NULL
, base
, false, NULL
,
1832 false, NULL
, qdict_haskey(qdict
, "speed"), speed
,
1833 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1835 hmp_handle_error(mon
, &error
);
1838 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1840 Error
*error
= NULL
;
1841 const char *device
= qdict_get_str(qdict
, "device");
1842 int64_t value
= qdict_get_int(qdict
, "speed");
1844 qmp_block_job_set_speed(device
, value
, &error
);
1846 hmp_handle_error(mon
, &error
);
1849 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1851 Error
*error
= NULL
;
1852 const char *device
= qdict_get_str(qdict
, "device");
1853 bool force
= qdict_get_try_bool(qdict
, "force", false);
1855 qmp_block_job_cancel(device
, true, force
, &error
);
1857 hmp_handle_error(mon
, &error
);
1860 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1862 Error
*error
= NULL
;
1863 const char *device
= qdict_get_str(qdict
, "device");
1865 qmp_block_job_pause(device
, &error
);
1867 hmp_handle_error(mon
, &error
);
1870 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1872 Error
*error
= NULL
;
1873 const char *device
= qdict_get_str(qdict
, "device");
1875 qmp_block_job_resume(device
, &error
);
1877 hmp_handle_error(mon
, &error
);
1880 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1882 Error
*error
= NULL
;
1883 const char *device
= qdict_get_str(qdict
, "device");
1885 qmp_block_job_complete(device
, &error
);
1887 hmp_handle_error(mon
, &error
);
1890 typedef struct HMPMigrationStatus
1894 bool is_block_migration
;
1895 } HMPMigrationStatus
;
1897 static void hmp_migrate_status_cb(void *opaque
)
1899 HMPMigrationStatus
*status
= opaque
;
1900 MigrationInfo
*info
;
1902 info
= qmp_query_migrate(NULL
);
1903 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1904 info
->status
== MIGRATION_STATUS_SETUP
) {
1905 if (info
->has_disk
) {
1908 if (info
->disk
->remaining
) {
1909 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1914 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1915 monitor_flush(status
->mon
);
1918 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1920 if (status
->is_block_migration
) {
1921 monitor_printf(status
->mon
, "\n");
1923 if (info
->has_error_desc
) {
1924 error_report("%s", info
->error_desc
);
1926 monitor_resume(status
->mon
);
1927 timer_del(status
->timer
);
1931 qapi_free_MigrationInfo(info
);
1934 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1936 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1937 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1938 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1939 const char *uri
= qdict_get_str(qdict
, "uri");
1942 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1944 hmp_handle_error(mon
, &err
);
1949 HMPMigrationStatus
*status
;
1951 if (monitor_suspend(mon
) < 0) {
1952 monitor_printf(mon
, "terminal does not allow synchronous "
1953 "migration, continuing detached\n");
1957 status
= g_malloc0(sizeof(*status
));
1959 status
->is_block_migration
= blk
|| inc
;
1960 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1962 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1966 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
1970 qmp_device_add((QDict
*)qdict
, NULL
, &err
);
1971 hmp_handle_error(mon
, &err
);
1974 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1976 const char *id
= qdict_get_str(qdict
, "id");
1979 qmp_device_del(id
, &err
);
1980 hmp_handle_error(mon
, &err
);
1983 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1986 bool paging
= qdict_get_try_bool(qdict
, "paging", false);
1987 bool zlib
= qdict_get_try_bool(qdict
, "zlib", false);
1988 bool lzo
= qdict_get_try_bool(qdict
, "lzo", false);
1989 bool snappy
= qdict_get_try_bool(qdict
, "snappy", false);
1990 const char *file
= qdict_get_str(qdict
, "filename");
1991 bool has_begin
= qdict_haskey(qdict
, "begin");
1992 bool has_length
= qdict_haskey(qdict
, "length");
1993 bool has_detach
= qdict_haskey(qdict
, "detach");
1996 bool detach
= false;
1997 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
2000 if (zlib
+ lzo
+ snappy
> 1) {
2001 error_setg(&err
, "only one of '-z|-l|-s' can be set");
2002 hmp_handle_error(mon
, &err
);
2007 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
2011 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
2015 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
2019 begin
= qdict_get_int(qdict
, "begin");
2022 length
= qdict_get_int(qdict
, "length");
2025 detach
= qdict_get_bool(qdict
, "detach");
2028 prot
= g_strconcat("file:", file
, NULL
);
2030 qmp_dump_guest_memory(paging
, prot
, true, detach
, has_begin
, begin
,
2031 has_length
, length
, true, dump_format
, &err
);
2032 hmp_handle_error(mon
, &err
);
2036 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
2041 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
2046 netdev_add(opts
, &err
);
2048 qemu_opts_del(opts
);
2052 hmp_handle_error(mon
, &err
);
2055 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
2057 const char *id
= qdict_get_str(qdict
, "id");
2060 qmp_netdev_del(id
, &err
);
2061 hmp_handle_error(mon
, &err
);
2064 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
2070 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
2072 hmp_handle_error(mon
, &err
);
2076 obj
= user_creatable_add_opts(opts
, &err
);
2077 qemu_opts_del(opts
);
2080 hmp_handle_error(mon
, &err
);
2087 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
2089 const char *fdname
= qdict_get_str(qdict
, "fdname");
2092 qmp_getfd(fdname
, &err
);
2093 hmp_handle_error(mon
, &err
);
2096 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
2098 const char *fdname
= qdict_get_str(qdict
, "fdname");
2101 qmp_closefd(fdname
, &err
);
2102 hmp_handle_error(mon
, &err
);
2105 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
2107 const char *keys
= qdict_get_str(qdict
, "keys");
2108 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
2109 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
2110 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
2116 separator
= strchr(keys
, '-');
2117 keyname_len
= separator
? separator
- keys
: strlen(keys
);
2119 /* Be compatible with old interface, convert user inputted "<" */
2120 if (keys
[0] == '<' && keyname_len
== 1) {
2125 keylist
= g_malloc0(sizeof(*keylist
));
2126 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
2132 tmp
->next
= keylist
;
2136 if (strstart(keys
, "0x", NULL
)) {
2138 int value
= strtoul(keys
, &endp
, 0);
2139 assert(endp
<= keys
+ keyname_len
);
2140 if (endp
!= keys
+ keyname_len
) {
2143 keylist
->value
->type
= KEY_VALUE_KIND_NUMBER
;
2144 keylist
->value
->u
.number
.data
= value
;
2146 int idx
= index_from_key(keys
, keyname_len
);
2147 if (idx
== Q_KEY_CODE__MAX
) {
2150 keylist
->value
->type
= KEY_VALUE_KIND_QCODE
;
2151 keylist
->value
->u
.qcode
.data
= idx
;
2157 keys
= separator
+ 1;
2160 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
2161 hmp_handle_error(mon
, &err
);
2164 qapi_free_KeyValueList(head
);
2168 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
2172 void hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
2174 const char *filename
= qdict_get_str(qdict
, "filename");
2177 qmp_screendump(filename
, &err
);
2178 hmp_handle_error(mon
, &err
);
2181 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
2183 const char *uri
= qdict_get_str(qdict
, "uri");
2184 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2185 bool all
= qdict_get_try_bool(qdict
, "all", false);
2186 Error
*local_err
= NULL
;
2187 BlockInfoList
*block_list
, *info
;
2188 SocketAddress
*addr
;
2190 if (writable
&& !all
) {
2191 error_setg(&local_err
, "-w only valid together with -a");
2195 /* First check if the address is valid and start the server. */
2196 addr
= socket_parse(uri
, &local_err
);
2197 if (local_err
!= NULL
) {
2201 nbd_server_start(addr
, NULL
, &local_err
);
2202 qapi_free_SocketAddress(addr
);
2203 if (local_err
!= NULL
) {
2211 /* Then try adding all block devices. If one fails, close all and
2214 block_list
= qmp_query_block(NULL
);
2216 for (info
= block_list
; info
; info
= info
->next
) {
2217 if (!info
->value
->has_inserted
) {
2221 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
2223 if (local_err
!= NULL
) {
2224 qmp_nbd_server_stop(NULL
);
2229 qapi_free_BlockInfoList(block_list
);
2232 hmp_handle_error(mon
, &local_err
);
2235 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
2237 const char *device
= qdict_get_str(qdict
, "device");
2238 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2239 Error
*local_err
= NULL
;
2241 qmp_nbd_server_add(device
, true, writable
, &local_err
);
2243 if (local_err
!= NULL
) {
2244 hmp_handle_error(mon
, &local_err
);
2248 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
2252 qmp_nbd_server_stop(&err
);
2253 hmp_handle_error(mon
, &err
);
2256 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
2261 cpuid
= qdict_get_int(qdict
, "id");
2262 qmp_cpu_add(cpuid
, &err
);
2263 hmp_handle_error(mon
, &err
);
2266 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
2268 const char *args
= qdict_get_str(qdict
, "args");
2272 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
2274 error_setg(&err
, "Parsing chardev args failed");
2276 qemu_chr_new_from_opts(opts
, &err
);
2277 qemu_opts_del(opts
);
2279 hmp_handle_error(mon
, &err
);
2282 void hmp_chardev_change(Monitor
*mon
, const QDict
*qdict
)
2284 const char *args
= qdict_get_str(qdict
, "args");
2287 ChardevBackend
*backend
= NULL
;
2288 ChardevReturn
*ret
= NULL
;
2289 QemuOpts
*opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
,
2292 error_setg(&err
, "Parsing chardev args failed");
2296 id
= qdict_get_str(qdict
, "id");
2297 if (qemu_opts_id(opts
)) {
2298 error_setg(&err
, "Unexpected 'id' parameter");
2302 backend
= qemu_chr_parse_opts(opts
, &err
);
2307 ret
= qmp_chardev_change(id
, backend
, &err
);
2310 qapi_free_ChardevReturn(ret
);
2311 qapi_free_ChardevBackend(backend
);
2312 qemu_opts_del(opts
);
2313 hmp_handle_error(mon
, &err
);
2316 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
2318 Error
*local_err
= NULL
;
2320 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
2321 hmp_handle_error(mon
, &local_err
);
2324 void hmp_chardev_send_break(Monitor
*mon
, const QDict
*qdict
)
2326 Error
*local_err
= NULL
;
2328 qmp_chardev_send_break(qdict_get_str(qdict
, "id"), &local_err
);
2329 hmp_handle_error(mon
, &local_err
);
2332 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
2335 BlockBackend
*local_blk
= NULL
;
2336 const char* device
= qdict_get_str(qdict
, "device");
2337 const char* command
= qdict_get_str(qdict
, "command");
2341 blk
= blk_by_name(device
);
2343 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, device
, &err
);
2345 blk
= local_blk
= blk_new(0, BLK_PERM_ALL
);
2346 ret
= blk_insert_bs(blk
, bs
, &err
);
2356 * Notably absent: Proper permission management. This is sad, but it seems
2357 * almost impossible to achieve without changing the semantics and thereby
2358 * limiting the use cases of the qemu-io HMP command.
2360 * In an ideal world we would unconditionally create a new BlockBackend for
2361 * qemuio_command(), but we have commands like 'reopen' and want them to
2362 * take effect on the exact BlockBackend whose name the user passed instead
2363 * of just on a temporary copy of it.
2365 * Another problem is that deleting the temporary BlockBackend involves
2366 * draining all requests on it first, but some qemu-iotests cases want to
2367 * issue multiple aio_read/write requests and expect them to complete in
2368 * the background while the monitor has already returned.
2370 * This is also what prevents us from saving the original permissions and
2371 * restoring them later: We can't revoke permissions until all requests
2372 * have completed, and we don't know when that is nor can we really let
2373 * anything else run before we have revoken them to avoid race conditions.
2375 * What happens now is that command() in qemu-io-cmds.c can extend the
2376 * permissions if necessary for the qemu-io command. And they simply stay
2377 * extended, possibly resulting in a read-only guest device keeping write
2378 * permissions. Ugly, but it appears to be the lesser evil.
2380 qemuio_command(blk
, command
);
2383 blk_unref(local_blk
);
2384 hmp_handle_error(mon
, &err
);
2387 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
2389 const char *id
= qdict_get_str(qdict
, "id");
2392 user_creatable_del(id
, &err
);
2393 hmp_handle_error(mon
, &err
);
2396 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
2399 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
2400 MemdevList
*m
= memdev_list
;
2405 v
= string_output_visitor_new(false, &str
);
2406 visit_type_uint16List(v
, NULL
, &m
->value
->host_nodes
, NULL
);
2407 monitor_printf(mon
, "memory backend: %s\n", m
->value
->id
);
2408 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
2409 monitor_printf(mon
, " merge: %s\n",
2410 m
->value
->merge
? "true" : "false");
2411 monitor_printf(mon
, " dump: %s\n",
2412 m
->value
->dump
? "true" : "false");
2413 monitor_printf(mon
, " prealloc: %s\n",
2414 m
->value
->prealloc
? "true" : "false");
2415 monitor_printf(mon
, " policy: %s\n",
2416 HostMemPolicy_str(m
->value
->policy
));
2417 visit_complete(v
, &str
);
2418 monitor_printf(mon
, " host nodes: %s\n", str
);
2425 monitor_printf(mon
, "\n");
2427 qapi_free_MemdevList(memdev_list
);
2428 hmp_handle_error(mon
, &err
);
2431 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
2434 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
2435 MemoryDeviceInfoList
*info
;
2436 MemoryDeviceInfo
*value
;
2437 PCDIMMDeviceInfo
*di
;
2439 for (info
= info_list
; info
; info
= info
->next
) {
2440 value
= info
->value
;
2443 switch (value
->type
) {
2444 case MEMORY_DEVICE_INFO_KIND_DIMM
:
2445 di
= value
->u
.dimm
.data
;
2447 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
2448 MemoryDeviceInfoKind_str(value
->type
),
2449 di
->id
? di
->id
: "");
2450 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
2451 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
2452 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
2453 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
2454 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
2455 monitor_printf(mon
, " hotplugged: %s\n",
2456 di
->hotplugged
? "true" : "false");
2457 monitor_printf(mon
, " hotpluggable: %s\n",
2458 di
->hotpluggable
? "true" : "false");
2466 qapi_free_MemoryDeviceInfoList(info_list
);
2467 hmp_handle_error(mon
, &err
);
2470 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
2472 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
2473 IOThreadInfoList
*info
;
2474 IOThreadInfo
*value
;
2476 for (info
= info_list
; info
; info
= info
->next
) {
2477 value
= info
->value
;
2478 monitor_printf(mon
, "%s:\n", value
->id
);
2479 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
2480 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
2481 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
2482 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
2485 qapi_free_IOThreadInfoList(info_list
);
2488 void hmp_qom_list(Monitor
*mon
, const QDict
*qdict
)
2490 const char *path
= qdict_get_try_str(qdict
, "path");
2491 ObjectPropertyInfoList
*list
;
2495 monitor_printf(mon
, "/\n");
2499 list
= qmp_qom_list(path
, &err
);
2501 ObjectPropertyInfoList
*start
= list
;
2502 while (list
!= NULL
) {
2503 ObjectPropertyInfo
*value
= list
->value
;
2505 monitor_printf(mon
, "%s (%s)\n",
2506 value
->name
, value
->type
);
2509 qapi_free_ObjectPropertyInfoList(start
);
2511 hmp_handle_error(mon
, &err
);
2514 void hmp_qom_set(Monitor
*mon
, const QDict
*qdict
)
2516 const char *path
= qdict_get_str(qdict
, "path");
2517 const char *property
= qdict_get_str(qdict
, "property");
2518 const char *value
= qdict_get_str(qdict
, "value");
2520 bool ambiguous
= false;
2523 obj
= object_resolve_path(path
, &ambiguous
);
2525 error_set(&err
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2526 "Device '%s' not found", path
);
2529 monitor_printf(mon
, "Warning: Path '%s' is ambiguous\n", path
);
2531 object_property_parse(obj
, value
, property
, &err
);
2533 hmp_handle_error(mon
, &err
);
2536 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
2538 const char *name
= qdict_get_str(qdict
, "name");
2539 RockerSwitch
*rocker
;
2542 rocker
= qmp_query_rocker(name
, &err
);
2544 hmp_handle_error(mon
, &err
);
2548 monitor_printf(mon
, "name: %s\n", rocker
->name
);
2549 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
2550 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
2552 qapi_free_RockerSwitch(rocker
);
2555 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
2557 RockerPortList
*list
, *port
;
2558 const char *name
= qdict_get_str(qdict
, "name");
2561 list
= qmp_query_rocker_ports(name
, &err
);
2563 hmp_handle_error(mon
, &err
);
2567 monitor_printf(mon
, " ena/ speed/ auto\n");
2568 monitor_printf(mon
, " port link duplex neg?\n");
2570 for (port
= list
; port
; port
= port
->next
) {
2571 monitor_printf(mon
, "%10s %-4s %-3s %2s %-3s\n",
2573 port
->value
->enabled
? port
->value
->link_up
?
2574 "up" : "down" : "!ena",
2575 port
->value
->speed
== 10000 ? "10G" : "??",
2576 port
->value
->duplex
? "FD" : "HD",
2577 port
->value
->autoneg
? "Yes" : "No");
2580 qapi_free_RockerPortList(list
);
2583 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
2585 RockerOfDpaFlowList
*list
, *info
;
2586 const char *name
= qdict_get_str(qdict
, "name");
2587 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
2590 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
2592 hmp_handle_error(mon
, &err
);
2596 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
2598 for (info
= list
; info
; info
= info
->next
) {
2599 RockerOfDpaFlow
*flow
= info
->value
;
2600 RockerOfDpaFlowKey
*key
= flow
->key
;
2601 RockerOfDpaFlowMask
*mask
= flow
->mask
;
2602 RockerOfDpaFlowAction
*action
= flow
->action
;
2605 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
2606 key
->priority
, key
->tbl_id
, flow
->hits
);
2608 monitor_printf(mon
, "%-4d %-3d ",
2609 key
->priority
, key
->tbl_id
);
2612 if (key
->has_in_pport
) {
2613 monitor_printf(mon
, " pport %d", key
->in_pport
);
2614 if (mask
->has_in_pport
) {
2615 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2619 if (key
->has_vlan_id
) {
2620 monitor_printf(mon
, " vlan %d",
2621 key
->vlan_id
& VLAN_VID_MASK
);
2622 if (mask
->has_vlan_id
) {
2623 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2627 if (key
->has_tunnel_id
) {
2628 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2629 if (mask
->has_tunnel_id
) {
2630 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2634 if (key
->has_eth_type
) {
2635 switch (key
->eth_type
) {
2637 monitor_printf(mon
, " ARP");
2640 monitor_printf(mon
, " IP");
2643 monitor_printf(mon
, " IPv6");
2646 monitor_printf(mon
, " LACP");
2649 monitor_printf(mon
, " LLDP");
2652 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2657 if (key
->has_eth_src
) {
2658 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2659 (mask
->has_eth_src
) &&
2660 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2661 monitor_printf(mon
, " src <any mcast/bcast>");
2662 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2663 (mask
->has_eth_src
) &&
2664 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2665 monitor_printf(mon
, " src <any ucast>");
2667 monitor_printf(mon
, " src %s", key
->eth_src
);
2668 if (mask
->has_eth_src
) {
2669 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2674 if (key
->has_eth_dst
) {
2675 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2676 (mask
->has_eth_dst
) &&
2677 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2678 monitor_printf(mon
, " dst <any mcast/bcast>");
2679 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2680 (mask
->has_eth_dst
) &&
2681 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2682 monitor_printf(mon
, " dst <any ucast>");
2684 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2685 if (mask
->has_eth_dst
) {
2686 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2691 if (key
->has_ip_proto
) {
2692 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2693 if (mask
->has_ip_proto
) {
2694 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2698 if (key
->has_ip_tos
) {
2699 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2700 if (mask
->has_ip_tos
) {
2701 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2705 if (key
->has_ip_dst
) {
2706 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2709 if (action
->has_goto_tbl
|| action
->has_group_id
||
2710 action
->has_new_vlan_id
) {
2711 monitor_printf(mon
, " -->");
2714 if (action
->has_new_vlan_id
) {
2715 monitor_printf(mon
, " apply new vlan %d",
2716 ntohs(action
->new_vlan_id
));
2719 if (action
->has_group_id
) {
2720 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2723 if (action
->has_goto_tbl
) {
2724 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2727 monitor_printf(mon
, "\n");
2730 qapi_free_RockerOfDpaFlowList(list
);
2733 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2735 RockerOfDpaGroupList
*list
, *g
;
2736 const char *name
= qdict_get_str(qdict
, "name");
2737 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2741 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
2743 hmp_handle_error(mon
, &err
);
2747 monitor_printf(mon
, "id (decode) --> buckets\n");
2749 for (g
= list
; g
; g
= g
->next
) {
2750 RockerOfDpaGroup
*group
= g
->value
;
2752 monitor_printf(mon
, "0x%08x", group
->id
);
2754 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2755 group
->type
== 1 ? "L2 rewrite" :
2756 group
->type
== 2 ? "L3 unicast" :
2757 group
->type
== 3 ? "L2 multicast" :
2758 group
->type
== 4 ? "L2 flood" :
2759 group
->type
== 5 ? "L3 interface" :
2760 group
->type
== 6 ? "L3 multicast" :
2761 group
->type
== 7 ? "L3 ECMP" :
2762 group
->type
== 8 ? "L2 overlay" :
2765 if (group
->has_vlan_id
) {
2766 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2769 if (group
->has_pport
) {
2770 monitor_printf(mon
, " pport %d", group
->pport
);
2773 if (group
->has_index
) {
2774 monitor_printf(mon
, " index %d", group
->index
);
2777 monitor_printf(mon
, ") -->");
2779 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2781 monitor_printf(mon
, " set vlan %d",
2782 group
->set_vlan_id
& VLAN_VID_MASK
);
2785 if (group
->has_set_eth_src
) {
2788 monitor_printf(mon
, " set");
2790 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2793 if (group
->has_set_eth_dst
) {
2796 monitor_printf(mon
, " set");
2798 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2803 if (group
->has_ttl_check
&& group
->ttl_check
) {
2804 monitor_printf(mon
, " check TTL");
2807 if (group
->has_group_id
&& group
->group_id
) {
2808 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2811 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2812 monitor_printf(mon
, " pop vlan");
2815 if (group
->has_out_pport
) {
2816 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2819 if (group
->has_group_ids
) {
2820 struct uint32List
*id
;
2822 monitor_printf(mon
, " groups [");
2823 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2824 monitor_printf(mon
, "0x%08x", id
->value
);
2826 monitor_printf(mon
, ",");
2829 monitor_printf(mon
, "]");
2832 monitor_printf(mon
, "\n");
2835 qapi_free_RockerOfDpaGroupList(list
);
2838 void hmp_info_dump(Monitor
*mon
, const QDict
*qdict
)
2840 DumpQueryResult
*result
= qmp_query_dump(NULL
);
2842 assert(result
&& result
->status
< DUMP_STATUS__MAX
);
2843 monitor_printf(mon
, "Status: %s\n", DumpStatus_str(result
->status
));
2845 if (result
->status
== DUMP_STATUS_ACTIVE
) {
2847 assert(result
->total
!= 0);
2848 percent
= 100.0 * result
->completed
/ result
->total
;
2849 monitor_printf(mon
, "Finished: %.2f %%\n", percent
);
2852 qapi_free_DumpQueryResult(result
);
2855 void hmp_info_ramblock(Monitor
*mon
, const QDict
*qdict
)
2857 ram_block_dump(mon
);
2860 void hmp_hotpluggable_cpus(Monitor
*mon
, const QDict
*qdict
)
2863 HotpluggableCPUList
*l
= qmp_query_hotpluggable_cpus(&err
);
2864 HotpluggableCPUList
*saved
= l
;
2865 CpuInstanceProperties
*c
;
2868 hmp_handle_error(mon
, &err
);
2872 monitor_printf(mon
, "Hotpluggable CPUs:\n");
2874 monitor_printf(mon
, " type: \"%s\"\n", l
->value
->type
);
2875 monitor_printf(mon
, " vcpus_count: \"%" PRIu64
"\"\n",
2876 l
->value
->vcpus_count
);
2877 if (l
->value
->has_qom_path
) {
2878 monitor_printf(mon
, " qom_path: \"%s\"\n", l
->value
->qom_path
);
2881 c
= l
->value
->props
;
2882 monitor_printf(mon
, " CPUInstance Properties:\n");
2883 if (c
->has_node_id
) {
2884 monitor_printf(mon
, " node-id: \"%" PRIu64
"\"\n", c
->node_id
);
2886 if (c
->has_socket_id
) {
2887 monitor_printf(mon
, " socket-id: \"%" PRIu64
"\"\n", c
->socket_id
);
2889 if (c
->has_core_id
) {
2890 monitor_printf(mon
, " core-id: \"%" PRIu64
"\"\n", c
->core_id
);
2892 if (c
->has_thread_id
) {
2893 monitor_printf(mon
, " thread-id: \"%" PRIu64
"\"\n", c
->thread_id
);
2899 qapi_free_HotpluggableCPUList(saved
);
2902 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
2905 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
2907 monitor_printf(mon
, "%s\n", info
->guid
);
2909 hmp_handle_error(mon
, &err
);
2910 qapi_free_GuidInfo(info
);
2913 void hmp_info_memory_size_summary(Monitor
*mon
, const QDict
*qdict
)
2916 MemoryInfo
*info
= qmp_query_memory_size_summary(&err
);
2918 monitor_printf(mon
, "base memory: %" PRIu64
"\n",
2921 if (info
->has_plugged_memory
) {
2922 monitor_printf(mon
, "plugged memory: %" PRIu64
"\n",
2923 info
->plugged_memory
);
2926 qapi_free_MemoryInfo(info
);
2928 hmp_handle_error(mon
, &err
);