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
);
345 monitor_printf(mon
, "%s: %" PRId64
"\n",
346 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
),
347 params
->xbzrle_cache_size
);
350 qapi_free_MigrationParameters(params
);
353 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
355 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
356 qmp_query_migrate_cache_size(NULL
) >> 10);
359 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
361 CpuInfoList
*cpu_list
, *cpu
;
363 cpu_list
= qmp_query_cpus(NULL
);
365 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
368 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
372 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
374 switch (cpu
->value
->arch
) {
375 case CPU_INFO_ARCH_X86
:
376 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->u
.x86
.pc
);
378 case CPU_INFO_ARCH_PPC
:
379 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->u
.ppc
.nip
);
381 case CPU_INFO_ARCH_SPARC
:
382 monitor_printf(mon
, " pc=0x%016" PRIx64
,
383 cpu
->value
->u
.q_sparc
.pc
);
384 monitor_printf(mon
, " npc=0x%016" PRIx64
,
385 cpu
->value
->u
.q_sparc
.npc
);
387 case CPU_INFO_ARCH_MIPS
:
388 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.q_mips
.PC
);
390 case CPU_INFO_ARCH_TRICORE
:
391 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.tricore
.PC
);
397 if (cpu
->value
->halted
) {
398 monitor_printf(mon
, " (halted)");
401 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
404 qapi_free_CpuInfoList(cpu_list
);
407 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
408 BlockDeviceInfo
*inserted
, bool verbose
)
410 ImageInfo
*image_info
;
412 assert(!info
|| !info
->has_inserted
|| info
->inserted
== inserted
);
414 if (info
&& *info
->device
) {
415 monitor_printf(mon
, "%s", info
->device
);
416 if (inserted
&& inserted
->has_node_name
) {
417 monitor_printf(mon
, " (%s)", inserted
->node_name
);
420 assert(info
|| inserted
);
421 monitor_printf(mon
, "%s",
422 inserted
&& inserted
->has_node_name
? inserted
->node_name
423 : info
&& info
->has_qdev
? info
->qdev
428 monitor_printf(mon
, ": %s (%s%s%s)\n",
431 inserted
->ro
? ", read-only" : "",
432 inserted
->encrypted
? ", encrypted" : "");
434 monitor_printf(mon
, ": [not inserted]\n");
438 if (info
->has_qdev
) {
439 monitor_printf(mon
, " Attached to: %s\n", info
->qdev
);
441 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
442 monitor_printf(mon
, " I/O status: %s\n",
443 BlockDeviceIoStatus_str(info
->io_status
));
446 if (info
->removable
) {
447 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
448 info
->locked
? "" : "not ",
449 info
->tray_open
? "open" : "closed");
458 monitor_printf(mon
, " Cache mode: %s%s%s\n",
459 inserted
->cache
->writeback
? "writeback" : "writethrough",
460 inserted
->cache
->direct
? ", direct" : "",
461 inserted
->cache
->no_flush
? ", ignore flushes" : "");
463 if (inserted
->has_backing_file
) {
466 "(chain depth: %" PRId64
")\n",
467 inserted
->backing_file
,
468 inserted
->backing_file_depth
);
471 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
472 monitor_printf(mon
, " Detect zeroes: %s\n",
473 BlockdevDetectZeroesOptions_str(inserted
->detect_zeroes
));
476 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
477 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
479 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
480 " bps_rd=%" PRId64
" bps_wr=%" PRId64
482 " bps_rd_max=%" PRId64
483 " bps_wr_max=%" PRId64
484 " iops=%" PRId64
" iops_rd=%" PRId64
487 " iops_rd_max=%" PRId64
488 " iops_wr_max=%" PRId64
489 " iops_size=%" PRId64
495 inserted
->bps_rd_max
,
496 inserted
->bps_wr_max
,
501 inserted
->iops_rd_max
,
502 inserted
->iops_wr_max
,
508 monitor_printf(mon
, "\nImages:\n");
509 image_info
= inserted
->image
;
511 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
513 if (image_info
->has_backing_image
) {
514 image_info
= image_info
->backing_image
;
522 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
524 BlockInfoList
*block_list
, *info
;
525 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
526 const char *device
= qdict_get_try_str(qdict
, "device");
527 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
528 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
529 bool printed
= false;
531 /* Print BlockBackend information */
533 block_list
= qmp_query_block(NULL
);
538 for (info
= block_list
; info
; info
= info
->next
) {
539 if (device
&& strcmp(device
, info
->value
->device
)) {
543 if (info
!= block_list
) {
544 monitor_printf(mon
, "\n");
547 print_block_info(mon
, info
->value
, info
->value
->has_inserted
548 ? info
->value
->inserted
: NULL
,
553 qapi_free_BlockInfoList(block_list
);
555 if ((!device
&& !nodes
) || printed
) {
559 /* Print node information */
560 blockdev_list
= qmp_query_named_block_nodes(NULL
);
561 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
562 assert(blockdev
->value
->has_node_name
);
563 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
567 if (blockdev
!= blockdev_list
) {
568 monitor_printf(mon
, "\n");
571 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
573 qapi_free_BlockDeviceInfoList(blockdev_list
);
576 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
578 BlockStatsList
*stats_list
, *stats
;
580 stats_list
= qmp_query_blockstats(false, false, NULL
);
582 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
583 if (!stats
->value
->has_device
) {
587 monitor_printf(mon
, "%s:", stats
->value
->device
);
588 monitor_printf(mon
, " rd_bytes=%" PRId64
590 " rd_operations=%" PRId64
591 " wr_operations=%" PRId64
592 " flush_operations=%" PRId64
593 " wr_total_time_ns=%" PRId64
594 " rd_total_time_ns=%" PRId64
595 " flush_total_time_ns=%" PRId64
596 " rd_merged=%" PRId64
597 " wr_merged=%" PRId64
598 " idle_time_ns=%" PRId64
600 stats
->value
->stats
->rd_bytes
,
601 stats
->value
->stats
->wr_bytes
,
602 stats
->value
->stats
->rd_operations
,
603 stats
->value
->stats
->wr_operations
,
604 stats
->value
->stats
->flush_operations
,
605 stats
->value
->stats
->wr_total_time_ns
,
606 stats
->value
->stats
->rd_total_time_ns
,
607 stats
->value
->stats
->flush_total_time_ns
,
608 stats
->value
->stats
->rd_merged
,
609 stats
->value
->stats
->wr_merged
,
610 stats
->value
->stats
->idle_time_ns
);
613 qapi_free_BlockStatsList(stats_list
);
616 /* Helper for hmp_info_vnc_clients, _servers */
617 static void hmp_info_VncBasicInfo(Monitor
*mon
, VncBasicInfo
*info
,
620 monitor_printf(mon
, " %s: %s:%s (%s%s)\n",
624 NetworkAddressFamily_str(info
->family
),
625 info
->websocket
? " (Websocket)" : "");
628 /* Helper displaying and auth and crypt info */
629 static void hmp_info_vnc_authcrypt(Monitor
*mon
, const char *indent
,
631 VncVencryptSubAuth
*vencrypt
)
633 monitor_printf(mon
, "%sAuth: %s (Sub: %s)\n", indent
,
634 VncPrimaryAuth_str(auth
),
635 vencrypt
? VncVencryptSubAuth_str(*vencrypt
) : "none");
638 static void hmp_info_vnc_clients(Monitor
*mon
, VncClientInfoList
*client
)
641 VncClientInfo
*cinfo
= client
->value
;
643 hmp_info_VncBasicInfo(mon
, qapi_VncClientInfo_base(cinfo
), "Client");
644 monitor_printf(mon
, " x509_dname: %s\n",
645 cinfo
->has_x509_dname
?
646 cinfo
->x509_dname
: "none");
647 monitor_printf(mon
, " sasl_username: %s\n",
648 cinfo
->has_sasl_username
?
649 cinfo
->sasl_username
: "none");
651 client
= client
->next
;
655 static void hmp_info_vnc_servers(Monitor
*mon
, VncServerInfo2List
*server
)
658 VncServerInfo2
*sinfo
= server
->value
;
659 hmp_info_VncBasicInfo(mon
, qapi_VncServerInfo2_base(sinfo
), "Server");
660 hmp_info_vnc_authcrypt(mon
, " ", sinfo
->auth
,
661 sinfo
->has_vencrypt
? &sinfo
->vencrypt
: NULL
);
662 server
= server
->next
;
666 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
668 VncInfo2List
*info2l
;
671 info2l
= qmp_query_vnc_servers(&err
);
673 error_report_err(err
);
677 monitor_printf(mon
, "None\n");
682 VncInfo2
*info
= info2l
->value
;
683 monitor_printf(mon
, "%s:\n", info
->id
);
684 hmp_info_vnc_servers(mon
, info
->server
);
685 hmp_info_vnc_clients(mon
, info
->clients
);
687 /* The server entry displays its auth, we only
688 * need to display in the case of 'reverse' connections
689 * where there's no server.
691 hmp_info_vnc_authcrypt(mon
, " ", info
->auth
,
692 info
->has_vencrypt
? &info
->vencrypt
: NULL
);
694 if (info
->has_display
) {
695 monitor_printf(mon
, " Display: %s\n", info
->display
);
697 info2l
= info2l
->next
;
700 qapi_free_VncInfo2List(info2l
);
705 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
707 SpiceChannelList
*chan
;
709 const char *channel_name
;
710 const char * const channel_names
[] = {
711 [SPICE_CHANNEL_MAIN
] = "main",
712 [SPICE_CHANNEL_DISPLAY
] = "display",
713 [SPICE_CHANNEL_INPUTS
] = "inputs",
714 [SPICE_CHANNEL_CURSOR
] = "cursor",
715 [SPICE_CHANNEL_PLAYBACK
] = "playback",
716 [SPICE_CHANNEL_RECORD
] = "record",
717 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
718 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
719 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
720 [SPICE_CHANNEL_PORT
] = "port",
722 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
723 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
724 * as quick fix for build failures with older versions. */
725 [SPICE_CHANNEL_WEBDAV
] = "webdav",
729 info
= qmp_query_spice(NULL
);
731 if (!info
->enabled
) {
732 monitor_printf(mon
, "Server: disabled\n");
736 monitor_printf(mon
, "Server:\n");
737 if (info
->has_port
) {
738 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
739 info
->host
, info
->port
);
741 if (info
->has_tls_port
) {
742 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
743 info
->host
, info
->tls_port
);
745 monitor_printf(mon
, " migrated: %s\n",
746 info
->migrated
? "true" : "false");
747 monitor_printf(mon
, " auth: %s\n", info
->auth
);
748 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
749 monitor_printf(mon
, " mouse-mode: %s\n",
750 SpiceQueryMouseMode_str(info
->mouse_mode
));
752 if (!info
->has_channels
|| info
->channels
== NULL
) {
753 monitor_printf(mon
, "Channels: none\n");
755 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
756 monitor_printf(mon
, "Channel:\n");
757 monitor_printf(mon
, " address: %s:%s%s\n",
758 chan
->value
->host
, chan
->value
->port
,
759 chan
->value
->tls
? " [tls]" : "");
760 monitor_printf(mon
, " session: %" PRId64
"\n",
761 chan
->value
->connection_id
);
762 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
763 chan
->value
->channel_type
, chan
->value
->channel_id
);
765 channel_name
= "unknown";
766 if (chan
->value
->channel_type
> 0 &&
767 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
768 channel_names
[chan
->value
->channel_type
]) {
769 channel_name
= channel_names
[chan
->value
->channel_type
];
772 monitor_printf(mon
, " channel name: %s\n", channel_name
);
777 qapi_free_SpiceInfo(info
);
781 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
786 info
= qmp_query_balloon(&err
);
788 error_report_err(err
);
792 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
794 qapi_free_BalloonInfo(info
);
797 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
799 PciMemoryRegionList
*region
;
801 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
802 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
803 dev
->slot
, dev
->function
);
804 monitor_printf(mon
, " ");
806 if (dev
->class_info
->has_desc
) {
807 monitor_printf(mon
, "%s", dev
->class_info
->desc
);
809 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
812 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
813 dev
->id
->vendor
, dev
->id
->device
);
816 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
819 if (dev
->has_pci_bridge
) {
820 monitor_printf(mon
, " BUS %" PRId64
".\n",
821 dev
->pci_bridge
->bus
->number
);
822 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
823 dev
->pci_bridge
->bus
->secondary
);
824 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
825 dev
->pci_bridge
->bus
->subordinate
);
827 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
828 dev
->pci_bridge
->bus
->io_range
->base
,
829 dev
->pci_bridge
->bus
->io_range
->limit
);
832 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
833 dev
->pci_bridge
->bus
->memory_range
->base
,
834 dev
->pci_bridge
->bus
->memory_range
->limit
);
836 monitor_printf(mon
, " prefetchable memory range "
837 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
838 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
839 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
842 for (region
= dev
->regions
; region
; region
= region
->next
) {
845 addr
= region
->value
->address
;
846 size
= region
->value
->size
;
848 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
850 if (!strcmp(region
->value
->type
, "io")) {
851 monitor_printf(mon
, "I/O at 0x%04" PRIx64
852 " [0x%04" PRIx64
"].\n",
853 addr
, addr
+ size
- 1);
855 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
856 " [0x%08" PRIx64
"].\n",
857 region
->value
->mem_type_64
? 64 : 32,
858 region
->value
->prefetch
? " prefetchable" : "",
859 addr
, addr
+ size
- 1);
863 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
865 if (dev
->has_pci_bridge
) {
866 if (dev
->pci_bridge
->has_devices
) {
867 PciDeviceInfoList
*cdev
;
868 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
869 hmp_info_pci_device(mon
, cdev
->value
);
875 static int hmp_info_irq_foreach(Object
*obj
, void *opaque
)
877 InterruptStatsProvider
*intc
;
878 InterruptStatsProviderClass
*k
;
879 Monitor
*mon
= opaque
;
881 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
882 intc
= INTERRUPT_STATS_PROVIDER(obj
);
883 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
884 uint64_t *irq_counts
;
885 unsigned int nb_irqs
, i
;
886 if (k
->get_statistics
&&
887 k
->get_statistics(intc
, &irq_counts
, &nb_irqs
)) {
889 monitor_printf(mon
, "IRQ statistics for %s:\n",
890 object_get_typename(obj
));
891 for (i
= 0; i
< nb_irqs
; i
++) {
892 if (irq_counts
[i
] > 0) {
893 monitor_printf(mon
, "%2d: %" PRId64
"\n", i
,
899 monitor_printf(mon
, "IRQ statistics not available for %s.\n",
900 object_get_typename(obj
));
907 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
)
909 object_child_foreach_recursive(object_get_root(),
910 hmp_info_irq_foreach
, mon
);
913 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
915 InterruptStatsProvider
*intc
;
916 InterruptStatsProviderClass
*k
;
917 Monitor
*mon
= opaque
;
919 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
920 intc
= INTERRUPT_STATS_PROVIDER(obj
);
921 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
923 k
->print_info(intc
, mon
);
925 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
926 object_get_typename(obj
));
933 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
935 object_child_foreach_recursive(object_get_root(),
936 hmp_info_pic_foreach
, mon
);
939 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
941 PciInfoList
*info_list
, *info
;
944 info_list
= qmp_query_pci(&err
);
946 monitor_printf(mon
, "PCI devices not supported\n");
951 for (info
= info_list
; info
; info
= info
->next
) {
952 PciDeviceInfoList
*dev
;
954 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
955 hmp_info_pci_device(mon
, dev
->value
);
959 qapi_free_PciInfoList(info_list
);
962 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
964 BlockJobInfoList
*list
;
967 list
= qmp_query_block_jobs(&err
);
971 monitor_printf(mon
, "No active jobs\n");
976 if (strcmp(list
->value
->type
, "stream") == 0) {
977 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
978 " of %" PRId64
" bytes, speed limit %" PRId64
985 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
986 " of %" PRId64
" bytes, speed limit %" PRId64
997 qapi_free_BlockJobInfoList(list
);
1000 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
1002 TPMInfoList
*info_list
, *info
;
1005 TPMPassthroughOptions
*tpo
;
1006 TPMEmulatorOptions
*teo
;
1008 info_list
= qmp_query_tpm(&err
);
1010 monitor_printf(mon
, "TPM device not supported\n");
1016 monitor_printf(mon
, "TPM device:\n");
1019 for (info
= info_list
; info
; info
= info
->next
) {
1020 TPMInfo
*ti
= info
->value
;
1021 monitor_printf(mon
, " tpm%d: model=%s\n",
1022 c
, TpmModel_str(ti
->model
));
1024 monitor_printf(mon
, " \\ %s: type=%s",
1025 ti
->id
, TpmTypeOptionsKind_str(ti
->options
->type
));
1027 switch (ti
->options
->type
) {
1028 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
1029 tpo
= ti
->options
->u
.passthrough
.data
;
1030 monitor_printf(mon
, "%s%s%s%s",
1031 tpo
->has_path
? ",path=" : "",
1032 tpo
->has_path
? tpo
->path
: "",
1033 tpo
->has_cancel_path
? ",cancel-path=" : "",
1034 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
1036 case TPM_TYPE_OPTIONS_KIND_EMULATOR
:
1037 teo
= ti
->options
->u
.emulator
.data
;
1038 monitor_printf(mon
, ",chardev=%s", teo
->chardev
);
1040 case TPM_TYPE_OPTIONS_KIND__MAX
:
1043 monitor_printf(mon
, "\n");
1046 qapi_free_TPMInfoList(info_list
);
1049 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
1051 monitor_suspend(mon
);
1055 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
1060 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
1062 qmp_system_reset(NULL
);
1065 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
1067 qmp_system_powerdown(NULL
);
1070 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
1074 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1075 use it are converted to the QAPI */
1076 cpu_index
= qdict_get_int(qdict
, "index");
1077 if (monitor_set_cpu(cpu_index
) < 0) {
1078 monitor_printf(mon
, "invalid CPU index\n");
1082 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
1084 uint32_t size
= qdict_get_int(qdict
, "size");
1085 const char *filename
= qdict_get_str(qdict
, "filename");
1086 uint64_t addr
= qdict_get_int(qdict
, "val");
1088 int cpu_index
= monitor_get_cpu_index();
1090 if (cpu_index
< 0) {
1091 monitor_printf(mon
, "No CPU available\n");
1095 qmp_memsave(addr
, size
, filename
, true, cpu_index
, &err
);
1096 hmp_handle_error(mon
, &err
);
1099 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
1101 uint32_t size
= qdict_get_int(qdict
, "size");
1102 const char *filename
= qdict_get_str(qdict
, "filename");
1103 uint64_t addr
= qdict_get_int(qdict
, "val");
1106 qmp_pmemsave(addr
, size
, filename
, &err
);
1107 hmp_handle_error(mon
, &err
);
1110 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
1112 const char *chardev
= qdict_get_str(qdict
, "device");
1113 const char *data
= qdict_get_str(qdict
, "data");
1116 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
1118 hmp_handle_error(mon
, &err
);
1121 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
1123 uint32_t size
= qdict_get_int(qdict
, "size");
1124 const char *chardev
= qdict_get_str(qdict
, "device");
1129 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
1131 error_report_err(err
);
1135 for (i
= 0; data
[i
]; i
++) {
1136 unsigned char ch
= data
[i
];
1139 monitor_printf(mon
, "\\\\");
1140 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
1141 monitor_printf(mon
, "\\u%04X", ch
);
1143 monitor_printf(mon
, "%c", ch
);
1147 monitor_printf(mon
, "\n");
1151 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
1156 hmp_handle_error(mon
, &err
);
1159 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
1161 qmp_system_wakeup(NULL
);
1164 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
1168 qmp_inject_nmi(&err
);
1169 hmp_handle_error(mon
, &err
);
1172 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
1174 const char *name
= qdict_get_str(qdict
, "name");
1175 bool up
= qdict_get_bool(qdict
, "up");
1178 qmp_set_link(name
, up
, &err
);
1179 hmp_handle_error(mon
, &err
);
1182 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
1184 const char *device
= qdict_get_str(qdict
, "device");
1185 const char *password
= qdict_get_str(qdict
, "password");
1188 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
1189 hmp_handle_error(mon
, &err
);
1192 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1194 int64_t value
= qdict_get_int(qdict
, "value");
1197 qmp_balloon(value
, &err
);
1199 error_report_err(err
);
1203 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
1205 const char *device
= qdict_get_str(qdict
, "device");
1206 int64_t size
= qdict_get_int(qdict
, "size");
1209 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
1210 hmp_handle_error(mon
, &err
);
1213 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
1215 const char *filename
= qdict_get_str(qdict
, "target");
1216 const char *format
= qdict_get_try_str(qdict
, "format");
1217 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1218 bool full
= qdict_get_try_bool(qdict
, "full", false);
1220 DriveMirror mirror
= {
1221 .device
= (char *)qdict_get_str(qdict
, "device"),
1222 .target
= (char *)filename
,
1223 .has_format
= !!format
,
1224 .format
= (char *)format
,
1225 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1227 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1232 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1233 hmp_handle_error(mon
, &err
);
1236 qmp_drive_mirror(&mirror
, &err
);
1237 hmp_handle_error(mon
, &err
);
1240 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
1242 const char *device
= qdict_get_str(qdict
, "device");
1243 const char *filename
= qdict_get_str(qdict
, "target");
1244 const char *format
= qdict_get_try_str(qdict
, "format");
1245 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1246 bool full
= qdict_get_try_bool(qdict
, "full", false);
1247 bool compress
= qdict_get_try_bool(qdict
, "compress", false);
1249 DriveBackup backup
= {
1250 .device
= (char *)device
,
1251 .target
= (char *)filename
,
1252 .has_format
= !!format
,
1253 .format
= (char *)format
,
1254 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1256 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1257 .has_compress
= !!compress
,
1258 .compress
= compress
,
1262 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1263 hmp_handle_error(mon
, &err
);
1267 qmp_drive_backup(&backup
, &err
);
1268 hmp_handle_error(mon
, &err
);
1271 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
1273 const char *device
= qdict_get_str(qdict
, "device");
1274 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
1275 const char *format
= qdict_get_try_str(qdict
, "format");
1276 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1277 enum NewImageMode mode
;
1281 /* In the future, if 'snapshot-file' is not specified, the snapshot
1282 will be taken internally. Today it's actually required. */
1283 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
1284 hmp_handle_error(mon
, &err
);
1288 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1289 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
1290 filename
, false, NULL
,
1293 hmp_handle_error(mon
, &err
);
1296 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1298 const char *device
= qdict_get_str(qdict
, "device");
1299 const char *name
= qdict_get_str(qdict
, "name");
1302 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1303 hmp_handle_error(mon
, &err
);
1306 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1308 const char *device
= qdict_get_str(qdict
, "device");
1309 const char *name
= qdict_get_str(qdict
, "name");
1310 const char *id
= qdict_get_try_str(qdict
, "id");
1313 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1315 hmp_handle_error(mon
, &err
);
1318 void hmp_loadvm(Monitor
*mon
, const QDict
*qdict
)
1320 int saved_vm_running
= runstate_is_running();
1321 const char *name
= qdict_get_str(qdict
, "name");
1324 vm_stop(RUN_STATE_RESTORE_VM
);
1326 if (load_snapshot(name
, &err
) == 0 && saved_vm_running
) {
1329 hmp_handle_error(mon
, &err
);
1332 void hmp_savevm(Monitor
*mon
, const QDict
*qdict
)
1336 save_snapshot(qdict_get_try_str(qdict
, "name"), &err
);
1337 hmp_handle_error(mon
, &err
);
1340 void hmp_delvm(Monitor
*mon
, const QDict
*qdict
)
1342 BlockDriverState
*bs
;
1344 const char *name
= qdict_get_str(qdict
, "name");
1346 if (bdrv_all_delete_snapshot(name
, &bs
, &err
) < 0) {
1347 error_reportf_err(err
,
1348 "Error while deleting snapshot on device '%s': ",
1349 bdrv_get_device_name(bs
));
1353 void hmp_info_snapshots(Monitor
*mon
, const QDict
*qdict
)
1355 BlockDriverState
*bs
, *bs1
;
1356 BdrvNextIterator it1
;
1357 QEMUSnapshotInfo
*sn_tab
, *sn
;
1358 bool no_snapshot
= true;
1361 int *global_snapshots
;
1362 AioContext
*aio_context
;
1364 typedef struct SnapshotEntry
{
1365 QEMUSnapshotInfo sn
;
1366 QTAILQ_ENTRY(SnapshotEntry
) next
;
1369 typedef struct ImageEntry
{
1370 const char *imagename
;
1371 QTAILQ_ENTRY(ImageEntry
) next
;
1372 QTAILQ_HEAD(, SnapshotEntry
) snapshots
;
1375 QTAILQ_HEAD(, ImageEntry
) image_list
=
1376 QTAILQ_HEAD_INITIALIZER(image_list
);
1378 ImageEntry
*image_entry
, *next_ie
;
1379 SnapshotEntry
*snapshot_entry
;
1381 bs
= bdrv_all_find_vmstate_bs();
1383 monitor_printf(mon
, "No available block device supports snapshots\n");
1386 aio_context
= bdrv_get_aio_context(bs
);
1388 aio_context_acquire(aio_context
);
1389 nb_sns
= bdrv_snapshot_list(bs
, &sn_tab
);
1390 aio_context_release(aio_context
);
1393 monitor_printf(mon
, "bdrv_snapshot_list: error %d\n", nb_sns
);
1397 for (bs1
= bdrv_first(&it1
); bs1
; bs1
= bdrv_next(&it1
)) {
1401 AioContext
*ctx
= bdrv_get_aio_context(bs1
);
1403 aio_context_acquire(ctx
);
1404 if (bdrv_can_snapshot(bs1
)) {
1406 bs1_nb_sns
= bdrv_snapshot_list(bs1
, &sn
);
1407 if (bs1_nb_sns
> 0) {
1408 no_snapshot
= false;
1409 ie
= g_new0(ImageEntry
, 1);
1410 ie
->imagename
= bdrv_get_device_name(bs1
);
1411 QTAILQ_INIT(&ie
->snapshots
);
1412 QTAILQ_INSERT_TAIL(&image_list
, ie
, next
);
1413 for (i
= 0; i
< bs1_nb_sns
; i
++) {
1414 se
= g_new0(SnapshotEntry
, 1);
1416 QTAILQ_INSERT_TAIL(&ie
->snapshots
, se
, next
);
1421 aio_context_release(ctx
);
1425 monitor_printf(mon
, "There is no snapshot available.\n");
1429 global_snapshots
= g_new0(int, nb_sns
);
1431 for (i
= 0; i
< nb_sns
; i
++) {
1432 SnapshotEntry
*next_sn
;
1433 if (bdrv_all_find_snapshot(sn_tab
[i
].name
, &bs1
) == 0) {
1434 global_snapshots
[total
] = i
;
1436 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1437 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
,
1439 if (!strcmp(sn_tab
[i
].name
, snapshot_entry
->sn
.name
)) {
1440 QTAILQ_REMOVE(&image_entry
->snapshots
, snapshot_entry
,
1442 g_free(snapshot_entry
);
1449 monitor_printf(mon
, "List of snapshots present on all disks:\n");
1452 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1453 monitor_printf(mon
, "\n");
1454 for (i
= 0; i
< total
; i
++) {
1455 sn
= &sn_tab
[global_snapshots
[i
]];
1456 /* The ID is not guaranteed to be the same on all images, so
1459 pstrcpy(sn
->id_str
, sizeof(sn
->id_str
), "--");
1460 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, sn
);
1461 monitor_printf(mon
, "\n");
1464 monitor_printf(mon
, "None\n");
1467 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1468 if (QTAILQ_EMPTY(&image_entry
->snapshots
)) {
1472 "\nList of partial (non-loadable) snapshots on '%s':\n",
1473 image_entry
->imagename
);
1474 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1475 monitor_printf(mon
, "\n");
1476 QTAILQ_FOREACH(snapshot_entry
, &image_entry
->snapshots
, next
) {
1477 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
,
1478 &snapshot_entry
->sn
);
1479 monitor_printf(mon
, "\n");
1483 QTAILQ_FOREACH_SAFE(image_entry
, &image_list
, next
, next_ie
) {
1484 SnapshotEntry
*next_sn
;
1485 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
, next
,
1487 g_free(snapshot_entry
);
1489 g_free(image_entry
);
1492 g_free(global_snapshots
);
1496 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1498 qmp_migrate_cancel(NULL
);
1501 void hmp_migrate_continue(Monitor
*mon
, const QDict
*qdict
)
1504 const char *state
= qdict_get_str(qdict
, "state");
1505 int val
= qapi_enum_parse(&MigrationStatus_lookup
, state
, -1, &err
);
1508 qmp_migrate_continue(val
, &err
);
1511 hmp_handle_error(mon
, &err
);
1514 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1517 const char *uri
= qdict_get_str(qdict
, "uri");
1519 qmp_migrate_incoming(uri
, &err
);
1521 hmp_handle_error(mon
, &err
);
1524 /* Kept for backwards compatibility */
1525 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1527 double value
= qdict_get_double(qdict
, "value");
1528 qmp_migrate_set_downtime(value
, NULL
);
1531 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1533 int64_t value
= qdict_get_int(qdict
, "value");
1536 qmp_migrate_set_cache_size(value
, &err
);
1538 error_report_err(err
);
1543 /* Kept for backwards compatibility */
1544 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1546 int64_t value
= qdict_get_int(qdict
, "value");
1547 qmp_migrate_set_speed(value
, NULL
);
1550 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1552 const char *cap
= qdict_get_str(qdict
, "capability");
1553 bool state
= qdict_get_bool(qdict
, "state");
1555 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1558 val
= qapi_enum_parse(&MigrationCapability_lookup
, cap
, -1, &err
);
1563 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1564 caps
->value
->capability
= val
;
1565 caps
->value
->state
= state
;
1567 qmp_migrate_set_capabilities(caps
, &err
);
1570 qapi_free_MigrationCapabilityStatusList(caps
);
1573 error_report_err(err
);
1577 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1579 const char *param
= qdict_get_str(qdict
, "parameter");
1580 const char *valuestr
= qdict_get_str(qdict
, "value");
1581 Visitor
*v
= string_input_visitor_new(valuestr
);
1582 MigrateSetParameters
*p
= g_new0(MigrateSetParameters
, 1);
1583 uint64_t valuebw
= 0;
1584 uint64_t cache_size
;
1588 val
= qapi_enum_parse(&MigrationParameter_lookup
, param
, -1, &err
);
1594 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1595 p
->has_compress_level
= true;
1596 visit_type_int(v
, param
, &p
->compress_level
, &err
);
1598 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1599 p
->has_compress_threads
= true;
1600 visit_type_int(v
, param
, &p
->compress_threads
, &err
);
1602 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1603 p
->has_decompress_threads
= true;
1604 visit_type_int(v
, param
, &p
->decompress_threads
, &err
);
1606 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1607 p
->has_cpu_throttle_initial
= true;
1608 visit_type_int(v
, param
, &p
->cpu_throttle_initial
, &err
);
1610 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1611 p
->has_cpu_throttle_increment
= true;
1612 visit_type_int(v
, param
, &p
->cpu_throttle_increment
, &err
);
1614 case MIGRATION_PARAMETER_TLS_CREDS
:
1615 p
->has_tls_creds
= true;
1616 p
->tls_creds
= g_new0(StrOrNull
, 1);
1617 p
->tls_creds
->type
= QTYPE_QSTRING
;
1618 visit_type_str(v
, param
, &p
->tls_creds
->u
.s
, &err
);
1620 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1621 p
->has_tls_hostname
= true;
1622 p
->tls_hostname
= g_new0(StrOrNull
, 1);
1623 p
->tls_hostname
->type
= QTYPE_QSTRING
;
1624 visit_type_str(v
, param
, &p
->tls_hostname
->u
.s
, &err
);
1626 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1627 p
->has_max_bandwidth
= true;
1629 * Can't use visit_type_size() here, because it
1630 * defaults to Bytes rather than Mebibytes.
1632 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
1633 if (ret
< 0 || valuebw
> INT64_MAX
1634 || (size_t)valuebw
!= valuebw
) {
1635 error_setg(&err
, "Invalid size %s", valuestr
);
1638 p
->max_bandwidth
= valuebw
;
1640 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1641 p
->has_downtime_limit
= true;
1642 visit_type_int(v
, param
, &p
->downtime_limit
, &err
);
1644 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
1645 p
->has_x_checkpoint_delay
= true;
1646 visit_type_int(v
, param
, &p
->x_checkpoint_delay
, &err
);
1648 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL
:
1649 p
->has_block_incremental
= true;
1650 visit_type_bool(v
, param
, &p
->block_incremental
, &err
);
1652 case MIGRATION_PARAMETER_X_MULTIFD_CHANNELS
:
1653 p
->has_x_multifd_channels
= true;
1654 visit_type_int(v
, param
, &p
->x_multifd_channels
, &err
);
1656 case MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT
:
1657 p
->has_x_multifd_page_count
= true;
1658 visit_type_int(v
, param
, &p
->x_multifd_page_count
, &err
);
1660 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
:
1661 p
->has_xbzrle_cache_size
= true;
1662 visit_type_size(v
, param
, &cache_size
, &err
);
1663 if (err
|| cache_size
> INT64_MAX
1664 || (size_t)cache_size
!= cache_size
) {
1665 error_setg(&err
, "Invalid size %s", valuestr
);
1668 p
->xbzrle_cache_size
= cache_size
;
1678 qmp_migrate_set_parameters(p
, &err
);
1681 qapi_free_MigrateSetParameters(p
);
1684 error_report_err(err
);
1688 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1691 const char *protocol
= qdict_get_str(qdict
, "protocol");
1692 const char *hostname
= qdict_get_str(qdict
, "hostname");
1693 bool has_port
= qdict_haskey(qdict
, "port");
1694 int port
= qdict_get_try_int(qdict
, "port", -1);
1695 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1696 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1697 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1699 qmp_client_migrate_info(protocol
, hostname
,
1700 has_port
, port
, has_tls_port
, tls_port
,
1701 !!cert_subject
, cert_subject
, &err
);
1702 hmp_handle_error(mon
, &err
);
1705 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1708 qmp_migrate_start_postcopy(&err
);
1709 hmp_handle_error(mon
, &err
);
1712 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1716 qmp_x_colo_lost_heartbeat(&err
);
1717 hmp_handle_error(mon
, &err
);
1720 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1722 const char *protocol
= qdict_get_str(qdict
, "protocol");
1723 const char *password
= qdict_get_str(qdict
, "password");
1724 const char *connected
= qdict_get_try_str(qdict
, "connected");
1727 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1728 hmp_handle_error(mon
, &err
);
1731 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1733 const char *protocol
= qdict_get_str(qdict
, "protocol");
1734 const char *whenstr
= qdict_get_str(qdict
, "time");
1737 qmp_expire_password(protocol
, whenstr
, &err
);
1738 hmp_handle_error(mon
, &err
);
1741 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1743 bool force
= qdict_get_try_bool(qdict
, "force", false);
1744 const char *device
= qdict_get_str(qdict
, "device");
1747 qmp_eject(true, device
, false, NULL
, true, force
, &err
);
1748 hmp_handle_error(mon
, &err
);
1751 static void hmp_change_read_arg(void *opaque
, const char *password
,
1752 void *readline_opaque
)
1754 qmp_change_vnc_password(password
, NULL
);
1755 monitor_read_command(opaque
, 1);
1758 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1760 const char *device
= qdict_get_str(qdict
, "device");
1761 const char *target
= qdict_get_str(qdict
, "target");
1762 const char *arg
= qdict_get_try_str(qdict
, "arg");
1763 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1764 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1767 if (strcmp(device
, "vnc") == 0) {
1770 "Parameter 'read-only-mode' is invalid for VNC\n");
1773 if (strcmp(target
, "passwd") == 0 ||
1774 strcmp(target
, "password") == 0) {
1776 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1780 qmp_change("vnc", target
, !!arg
, arg
, &err
);
1784 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup
,
1786 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1788 hmp_handle_error(mon
, &err
);
1793 qmp_blockdev_change_medium(true, device
, false, NULL
, target
,
1794 !!arg
, arg
, !!read_only
, read_only_mode
,
1798 hmp_handle_error(mon
, &err
);
1801 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1804 BlockIOThrottle throttle
= {
1806 .device
= (char *) qdict_get_str(qdict
, "device"),
1807 .bps
= qdict_get_int(qdict
, "bps"),
1808 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
1809 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
1810 .iops
= qdict_get_int(qdict
, "iops"),
1811 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
1812 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
1815 qmp_block_set_io_throttle(&throttle
, &err
);
1816 hmp_handle_error(mon
, &err
);
1819 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1821 Error
*error
= NULL
;
1822 const char *device
= qdict_get_str(qdict
, "device");
1823 const char *base
= qdict_get_try_str(qdict
, "base");
1824 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1826 qmp_block_stream(true, device
, device
, base
!= NULL
, base
, false, NULL
,
1827 false, NULL
, qdict_haskey(qdict
, "speed"), speed
,
1828 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1830 hmp_handle_error(mon
, &error
);
1833 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1835 Error
*error
= NULL
;
1836 const char *device
= qdict_get_str(qdict
, "device");
1837 int64_t value
= qdict_get_int(qdict
, "speed");
1839 qmp_block_job_set_speed(device
, value
, &error
);
1841 hmp_handle_error(mon
, &error
);
1844 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1846 Error
*error
= NULL
;
1847 const char *device
= qdict_get_str(qdict
, "device");
1848 bool force
= qdict_get_try_bool(qdict
, "force", false);
1850 qmp_block_job_cancel(device
, true, force
, &error
);
1852 hmp_handle_error(mon
, &error
);
1855 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1857 Error
*error
= NULL
;
1858 const char *device
= qdict_get_str(qdict
, "device");
1860 qmp_block_job_pause(device
, &error
);
1862 hmp_handle_error(mon
, &error
);
1865 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1867 Error
*error
= NULL
;
1868 const char *device
= qdict_get_str(qdict
, "device");
1870 qmp_block_job_resume(device
, &error
);
1872 hmp_handle_error(mon
, &error
);
1875 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1877 Error
*error
= NULL
;
1878 const char *device
= qdict_get_str(qdict
, "device");
1880 qmp_block_job_complete(device
, &error
);
1882 hmp_handle_error(mon
, &error
);
1885 typedef struct HMPMigrationStatus
1889 bool is_block_migration
;
1890 } HMPMigrationStatus
;
1892 static void hmp_migrate_status_cb(void *opaque
)
1894 HMPMigrationStatus
*status
= opaque
;
1895 MigrationInfo
*info
;
1897 info
= qmp_query_migrate(NULL
);
1898 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1899 info
->status
== MIGRATION_STATUS_SETUP
) {
1900 if (info
->has_disk
) {
1903 if (info
->disk
->remaining
) {
1904 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1909 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1910 monitor_flush(status
->mon
);
1913 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1915 if (status
->is_block_migration
) {
1916 monitor_printf(status
->mon
, "\n");
1918 if (info
->has_error_desc
) {
1919 error_report("%s", info
->error_desc
);
1921 monitor_resume(status
->mon
);
1922 timer_del(status
->timer
);
1926 qapi_free_MigrationInfo(info
);
1929 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1931 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1932 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1933 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1934 const char *uri
= qdict_get_str(qdict
, "uri");
1937 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1939 error_report_err(err
);
1944 HMPMigrationStatus
*status
;
1946 if (monitor_suspend(mon
) < 0) {
1947 monitor_printf(mon
, "terminal does not allow synchronous "
1948 "migration, continuing detached\n");
1952 status
= g_malloc0(sizeof(*status
));
1954 status
->is_block_migration
= blk
|| inc
;
1955 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1957 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1961 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
1965 qmp_device_add((QDict
*)qdict
, NULL
, &err
);
1966 hmp_handle_error(mon
, &err
);
1969 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1971 const char *id
= qdict_get_str(qdict
, "id");
1974 qmp_device_del(id
, &err
);
1975 hmp_handle_error(mon
, &err
);
1978 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1981 bool paging
= qdict_get_try_bool(qdict
, "paging", false);
1982 bool zlib
= qdict_get_try_bool(qdict
, "zlib", false);
1983 bool lzo
= qdict_get_try_bool(qdict
, "lzo", false);
1984 bool snappy
= qdict_get_try_bool(qdict
, "snappy", false);
1985 const char *file
= qdict_get_str(qdict
, "filename");
1986 bool has_begin
= qdict_haskey(qdict
, "begin");
1987 bool has_length
= qdict_haskey(qdict
, "length");
1988 bool has_detach
= qdict_haskey(qdict
, "detach");
1991 bool detach
= false;
1992 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1995 if (zlib
+ lzo
+ snappy
> 1) {
1996 error_setg(&err
, "only one of '-z|-l|-s' can be set");
1997 hmp_handle_error(mon
, &err
);
2002 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
2006 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
2010 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
2014 begin
= qdict_get_int(qdict
, "begin");
2017 length
= qdict_get_int(qdict
, "length");
2020 detach
= qdict_get_bool(qdict
, "detach");
2023 prot
= g_strconcat("file:", file
, NULL
);
2025 qmp_dump_guest_memory(paging
, prot
, true, detach
, has_begin
, begin
,
2026 has_length
, length
, true, dump_format
, &err
);
2027 hmp_handle_error(mon
, &err
);
2031 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
2036 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
2041 netdev_add(opts
, &err
);
2043 qemu_opts_del(opts
);
2047 hmp_handle_error(mon
, &err
);
2050 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
2052 const char *id
= qdict_get_str(qdict
, "id");
2055 qmp_netdev_del(id
, &err
);
2056 hmp_handle_error(mon
, &err
);
2059 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
2065 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
2067 hmp_handle_error(mon
, &err
);
2071 obj
= user_creatable_add_opts(opts
, &err
);
2072 qemu_opts_del(opts
);
2075 hmp_handle_error(mon
, &err
);
2082 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
2084 const char *fdname
= qdict_get_str(qdict
, "fdname");
2087 qmp_getfd(fdname
, &err
);
2088 hmp_handle_error(mon
, &err
);
2091 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
2093 const char *fdname
= qdict_get_str(qdict
, "fdname");
2096 qmp_closefd(fdname
, &err
);
2097 hmp_handle_error(mon
, &err
);
2100 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
2102 const char *keys
= qdict_get_str(qdict
, "keys");
2103 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
2104 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
2105 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
2111 separator
= strchr(keys
, '-');
2112 keyname_len
= separator
? separator
- keys
: strlen(keys
);
2114 /* Be compatible with old interface, convert user inputted "<" */
2115 if (keys
[0] == '<' && keyname_len
== 1) {
2120 keylist
= g_malloc0(sizeof(*keylist
));
2121 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
2127 tmp
->next
= keylist
;
2131 if (strstart(keys
, "0x", NULL
)) {
2133 int value
= strtoul(keys
, &endp
, 0);
2134 assert(endp
<= keys
+ keyname_len
);
2135 if (endp
!= keys
+ keyname_len
) {
2138 keylist
->value
->type
= KEY_VALUE_KIND_NUMBER
;
2139 keylist
->value
->u
.number
.data
= value
;
2141 int idx
= index_from_key(keys
, keyname_len
);
2142 if (idx
== Q_KEY_CODE__MAX
) {
2145 keylist
->value
->type
= KEY_VALUE_KIND_QCODE
;
2146 keylist
->value
->u
.qcode
.data
= idx
;
2152 keys
= separator
+ 1;
2155 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
2156 hmp_handle_error(mon
, &err
);
2159 qapi_free_KeyValueList(head
);
2163 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
2167 void hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
2169 const char *filename
= qdict_get_str(qdict
, "filename");
2172 qmp_screendump(filename
, &err
);
2173 hmp_handle_error(mon
, &err
);
2176 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
2178 const char *uri
= qdict_get_str(qdict
, "uri");
2179 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2180 bool all
= qdict_get_try_bool(qdict
, "all", false);
2181 Error
*local_err
= NULL
;
2182 BlockInfoList
*block_list
, *info
;
2183 SocketAddress
*addr
;
2185 if (writable
&& !all
) {
2186 error_setg(&local_err
, "-w only valid together with -a");
2190 /* First check if the address is valid and start the server. */
2191 addr
= socket_parse(uri
, &local_err
);
2192 if (local_err
!= NULL
) {
2196 nbd_server_start(addr
, NULL
, &local_err
);
2197 qapi_free_SocketAddress(addr
);
2198 if (local_err
!= NULL
) {
2206 /* Then try adding all block devices. If one fails, close all and
2209 block_list
= qmp_query_block(NULL
);
2211 for (info
= block_list
; info
; info
= info
->next
) {
2212 if (!info
->value
->has_inserted
) {
2216 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
2218 if (local_err
!= NULL
) {
2219 qmp_nbd_server_stop(NULL
);
2224 qapi_free_BlockInfoList(block_list
);
2227 hmp_handle_error(mon
, &local_err
);
2230 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
2232 const char *device
= qdict_get_str(qdict
, "device");
2233 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2234 Error
*local_err
= NULL
;
2236 qmp_nbd_server_add(device
, true, writable
, &local_err
);
2238 if (local_err
!= NULL
) {
2239 hmp_handle_error(mon
, &local_err
);
2243 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
2247 qmp_nbd_server_stop(&err
);
2248 hmp_handle_error(mon
, &err
);
2251 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
2256 cpuid
= qdict_get_int(qdict
, "id");
2257 qmp_cpu_add(cpuid
, &err
);
2258 hmp_handle_error(mon
, &err
);
2261 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
2263 const char *args
= qdict_get_str(qdict
, "args");
2267 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
2269 error_setg(&err
, "Parsing chardev args failed");
2271 qemu_chr_new_from_opts(opts
, &err
);
2272 qemu_opts_del(opts
);
2274 hmp_handle_error(mon
, &err
);
2277 void hmp_chardev_change(Monitor
*mon
, const QDict
*qdict
)
2279 const char *args
= qdict_get_str(qdict
, "args");
2282 ChardevBackend
*backend
= NULL
;
2283 ChardevReturn
*ret
= NULL
;
2284 QemuOpts
*opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
,
2287 error_setg(&err
, "Parsing chardev args failed");
2291 id
= qdict_get_str(qdict
, "id");
2292 if (qemu_opts_id(opts
)) {
2293 error_setg(&err
, "Unexpected 'id' parameter");
2297 backend
= qemu_chr_parse_opts(opts
, &err
);
2302 ret
= qmp_chardev_change(id
, backend
, &err
);
2305 qapi_free_ChardevReturn(ret
);
2306 qapi_free_ChardevBackend(backend
);
2307 qemu_opts_del(opts
);
2308 hmp_handle_error(mon
, &err
);
2311 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
2313 Error
*local_err
= NULL
;
2315 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
2316 hmp_handle_error(mon
, &local_err
);
2319 void hmp_chardev_send_break(Monitor
*mon
, const QDict
*qdict
)
2321 Error
*local_err
= NULL
;
2323 qmp_chardev_send_break(qdict_get_str(qdict
, "id"), &local_err
);
2324 hmp_handle_error(mon
, &local_err
);
2327 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
2330 BlockBackend
*local_blk
= NULL
;
2331 AioContext
*aio_context
;
2332 const char* device
= qdict_get_str(qdict
, "device");
2333 const char* command
= qdict_get_str(qdict
, "command");
2337 blk
= blk_by_name(device
);
2339 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, device
, &err
);
2341 blk
= local_blk
= blk_new(0, BLK_PERM_ALL
);
2342 ret
= blk_insert_bs(blk
, bs
, &err
);
2351 aio_context
= blk_get_aio_context(blk
);
2352 aio_context_acquire(aio_context
);
2355 * Notably absent: Proper permission management. This is sad, but it seems
2356 * almost impossible to achieve without changing the semantics and thereby
2357 * limiting the use cases of the qemu-io HMP command.
2359 * In an ideal world we would unconditionally create a new BlockBackend for
2360 * qemuio_command(), but we have commands like 'reopen' and want them to
2361 * take effect on the exact BlockBackend whose name the user passed instead
2362 * of just on a temporary copy of it.
2364 * Another problem is that deleting the temporary BlockBackend involves
2365 * draining all requests on it first, but some qemu-iotests cases want to
2366 * issue multiple aio_read/write requests and expect them to complete in
2367 * the background while the monitor has already returned.
2369 * This is also what prevents us from saving the original permissions and
2370 * restoring them later: We can't revoke permissions until all requests
2371 * have completed, and we don't know when that is nor can we really let
2372 * anything else run before we have revoken them to avoid race conditions.
2374 * What happens now is that command() in qemu-io-cmds.c can extend the
2375 * permissions if necessary for the qemu-io command. And they simply stay
2376 * extended, possibly resulting in a read-only guest device keeping write
2377 * permissions. Ugly, but it appears to be the lesser evil.
2379 qemuio_command(blk
, command
);
2381 aio_context_release(aio_context
);
2384 blk_unref(local_blk
);
2385 hmp_handle_error(mon
, &err
);
2388 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
2390 const char *id
= qdict_get_str(qdict
, "id");
2393 user_creatable_del(id
, &err
);
2394 hmp_handle_error(mon
, &err
);
2397 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
2400 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
2401 MemdevList
*m
= memdev_list
;
2406 v
= string_output_visitor_new(false, &str
);
2407 visit_type_uint16List(v
, NULL
, &m
->value
->host_nodes
, NULL
);
2408 monitor_printf(mon
, "memory backend: %s\n", m
->value
->id
);
2409 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
2410 monitor_printf(mon
, " merge: %s\n",
2411 m
->value
->merge
? "true" : "false");
2412 monitor_printf(mon
, " dump: %s\n",
2413 m
->value
->dump
? "true" : "false");
2414 monitor_printf(mon
, " prealloc: %s\n",
2415 m
->value
->prealloc
? "true" : "false");
2416 monitor_printf(mon
, " policy: %s\n",
2417 HostMemPolicy_str(m
->value
->policy
));
2418 visit_complete(v
, &str
);
2419 monitor_printf(mon
, " host nodes: %s\n", str
);
2426 monitor_printf(mon
, "\n");
2428 qapi_free_MemdevList(memdev_list
);
2429 hmp_handle_error(mon
, &err
);
2432 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
2435 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
2436 MemoryDeviceInfoList
*info
;
2437 MemoryDeviceInfo
*value
;
2438 PCDIMMDeviceInfo
*di
;
2440 for (info
= info_list
; info
; info
= info
->next
) {
2441 value
= info
->value
;
2444 switch (value
->type
) {
2445 case MEMORY_DEVICE_INFO_KIND_DIMM
:
2446 di
= value
->u
.dimm
.data
;
2448 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
2449 MemoryDeviceInfoKind_str(value
->type
),
2450 di
->id
? di
->id
: "");
2451 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
2452 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
2453 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
2454 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
2455 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
2456 monitor_printf(mon
, " hotplugged: %s\n",
2457 di
->hotplugged
? "true" : "false");
2458 monitor_printf(mon
, " hotpluggable: %s\n",
2459 di
->hotpluggable
? "true" : "false");
2467 qapi_free_MemoryDeviceInfoList(info_list
);
2468 hmp_handle_error(mon
, &err
);
2471 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
2473 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
2474 IOThreadInfoList
*info
;
2475 IOThreadInfo
*value
;
2477 for (info
= info_list
; info
; info
= info
->next
) {
2478 value
= info
->value
;
2479 monitor_printf(mon
, "%s:\n", value
->id
);
2480 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
2481 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
2482 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
2483 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
2486 qapi_free_IOThreadInfoList(info_list
);
2489 void hmp_qom_list(Monitor
*mon
, const QDict
*qdict
)
2491 const char *path
= qdict_get_try_str(qdict
, "path");
2492 ObjectPropertyInfoList
*list
;
2496 monitor_printf(mon
, "/\n");
2500 list
= qmp_qom_list(path
, &err
);
2502 ObjectPropertyInfoList
*start
= list
;
2503 while (list
!= NULL
) {
2504 ObjectPropertyInfo
*value
= list
->value
;
2506 monitor_printf(mon
, "%s (%s)\n",
2507 value
->name
, value
->type
);
2510 qapi_free_ObjectPropertyInfoList(start
);
2512 hmp_handle_error(mon
, &err
);
2515 void hmp_qom_set(Monitor
*mon
, const QDict
*qdict
)
2517 const char *path
= qdict_get_str(qdict
, "path");
2518 const char *property
= qdict_get_str(qdict
, "property");
2519 const char *value
= qdict_get_str(qdict
, "value");
2521 bool ambiguous
= false;
2524 obj
= object_resolve_path(path
, &ambiguous
);
2526 error_set(&err
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2527 "Device '%s' not found", path
);
2530 monitor_printf(mon
, "Warning: Path '%s' is ambiguous\n", path
);
2532 object_property_parse(obj
, value
, property
, &err
);
2534 hmp_handle_error(mon
, &err
);
2537 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
2539 const char *name
= qdict_get_str(qdict
, "name");
2540 RockerSwitch
*rocker
;
2543 rocker
= qmp_query_rocker(name
, &err
);
2545 hmp_handle_error(mon
, &err
);
2549 monitor_printf(mon
, "name: %s\n", rocker
->name
);
2550 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
2551 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
2553 qapi_free_RockerSwitch(rocker
);
2556 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
2558 RockerPortList
*list
, *port
;
2559 const char *name
= qdict_get_str(qdict
, "name");
2562 list
= qmp_query_rocker_ports(name
, &err
);
2564 hmp_handle_error(mon
, &err
);
2568 monitor_printf(mon
, " ena/ speed/ auto\n");
2569 monitor_printf(mon
, " port link duplex neg?\n");
2571 for (port
= list
; port
; port
= port
->next
) {
2572 monitor_printf(mon
, "%10s %-4s %-3s %2s %-3s\n",
2574 port
->value
->enabled
? port
->value
->link_up
?
2575 "up" : "down" : "!ena",
2576 port
->value
->speed
== 10000 ? "10G" : "??",
2577 port
->value
->duplex
? "FD" : "HD",
2578 port
->value
->autoneg
? "Yes" : "No");
2581 qapi_free_RockerPortList(list
);
2584 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
2586 RockerOfDpaFlowList
*list
, *info
;
2587 const char *name
= qdict_get_str(qdict
, "name");
2588 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
2591 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
2593 hmp_handle_error(mon
, &err
);
2597 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
2599 for (info
= list
; info
; info
= info
->next
) {
2600 RockerOfDpaFlow
*flow
= info
->value
;
2601 RockerOfDpaFlowKey
*key
= flow
->key
;
2602 RockerOfDpaFlowMask
*mask
= flow
->mask
;
2603 RockerOfDpaFlowAction
*action
= flow
->action
;
2606 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
2607 key
->priority
, key
->tbl_id
, flow
->hits
);
2609 monitor_printf(mon
, "%-4d %-3d ",
2610 key
->priority
, key
->tbl_id
);
2613 if (key
->has_in_pport
) {
2614 monitor_printf(mon
, " pport %d", key
->in_pport
);
2615 if (mask
->has_in_pport
) {
2616 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2620 if (key
->has_vlan_id
) {
2621 monitor_printf(mon
, " vlan %d",
2622 key
->vlan_id
& VLAN_VID_MASK
);
2623 if (mask
->has_vlan_id
) {
2624 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2628 if (key
->has_tunnel_id
) {
2629 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2630 if (mask
->has_tunnel_id
) {
2631 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2635 if (key
->has_eth_type
) {
2636 switch (key
->eth_type
) {
2638 monitor_printf(mon
, " ARP");
2641 monitor_printf(mon
, " IP");
2644 monitor_printf(mon
, " IPv6");
2647 monitor_printf(mon
, " LACP");
2650 monitor_printf(mon
, " LLDP");
2653 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2658 if (key
->has_eth_src
) {
2659 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2660 (mask
->has_eth_src
) &&
2661 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2662 monitor_printf(mon
, " src <any mcast/bcast>");
2663 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2664 (mask
->has_eth_src
) &&
2665 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2666 monitor_printf(mon
, " src <any ucast>");
2668 monitor_printf(mon
, " src %s", key
->eth_src
);
2669 if (mask
->has_eth_src
) {
2670 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2675 if (key
->has_eth_dst
) {
2676 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2677 (mask
->has_eth_dst
) &&
2678 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2679 monitor_printf(mon
, " dst <any mcast/bcast>");
2680 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2681 (mask
->has_eth_dst
) &&
2682 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2683 monitor_printf(mon
, " dst <any ucast>");
2685 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2686 if (mask
->has_eth_dst
) {
2687 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2692 if (key
->has_ip_proto
) {
2693 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2694 if (mask
->has_ip_proto
) {
2695 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2699 if (key
->has_ip_tos
) {
2700 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2701 if (mask
->has_ip_tos
) {
2702 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2706 if (key
->has_ip_dst
) {
2707 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2710 if (action
->has_goto_tbl
|| action
->has_group_id
||
2711 action
->has_new_vlan_id
) {
2712 monitor_printf(mon
, " -->");
2715 if (action
->has_new_vlan_id
) {
2716 monitor_printf(mon
, " apply new vlan %d",
2717 ntohs(action
->new_vlan_id
));
2720 if (action
->has_group_id
) {
2721 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2724 if (action
->has_goto_tbl
) {
2725 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2728 monitor_printf(mon
, "\n");
2731 qapi_free_RockerOfDpaFlowList(list
);
2734 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2736 RockerOfDpaGroupList
*list
, *g
;
2737 const char *name
= qdict_get_str(qdict
, "name");
2738 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2742 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
2744 hmp_handle_error(mon
, &err
);
2748 monitor_printf(mon
, "id (decode) --> buckets\n");
2750 for (g
= list
; g
; g
= g
->next
) {
2751 RockerOfDpaGroup
*group
= g
->value
;
2753 monitor_printf(mon
, "0x%08x", group
->id
);
2755 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2756 group
->type
== 1 ? "L2 rewrite" :
2757 group
->type
== 2 ? "L3 unicast" :
2758 group
->type
== 3 ? "L2 multicast" :
2759 group
->type
== 4 ? "L2 flood" :
2760 group
->type
== 5 ? "L3 interface" :
2761 group
->type
== 6 ? "L3 multicast" :
2762 group
->type
== 7 ? "L3 ECMP" :
2763 group
->type
== 8 ? "L2 overlay" :
2766 if (group
->has_vlan_id
) {
2767 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2770 if (group
->has_pport
) {
2771 monitor_printf(mon
, " pport %d", group
->pport
);
2774 if (group
->has_index
) {
2775 monitor_printf(mon
, " index %d", group
->index
);
2778 monitor_printf(mon
, ") -->");
2780 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2782 monitor_printf(mon
, " set vlan %d",
2783 group
->set_vlan_id
& VLAN_VID_MASK
);
2786 if (group
->has_set_eth_src
) {
2789 monitor_printf(mon
, " set");
2791 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2794 if (group
->has_set_eth_dst
) {
2797 monitor_printf(mon
, " set");
2799 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2804 if (group
->has_ttl_check
&& group
->ttl_check
) {
2805 monitor_printf(mon
, " check TTL");
2808 if (group
->has_group_id
&& group
->group_id
) {
2809 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2812 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2813 monitor_printf(mon
, " pop vlan");
2816 if (group
->has_out_pport
) {
2817 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2820 if (group
->has_group_ids
) {
2821 struct uint32List
*id
;
2823 monitor_printf(mon
, " groups [");
2824 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2825 monitor_printf(mon
, "0x%08x", id
->value
);
2827 monitor_printf(mon
, ",");
2830 monitor_printf(mon
, "]");
2833 monitor_printf(mon
, "\n");
2836 qapi_free_RockerOfDpaGroupList(list
);
2839 void hmp_info_dump(Monitor
*mon
, const QDict
*qdict
)
2841 DumpQueryResult
*result
= qmp_query_dump(NULL
);
2843 assert(result
&& result
->status
< DUMP_STATUS__MAX
);
2844 monitor_printf(mon
, "Status: %s\n", DumpStatus_str(result
->status
));
2846 if (result
->status
== DUMP_STATUS_ACTIVE
) {
2848 assert(result
->total
!= 0);
2849 percent
= 100.0 * result
->completed
/ result
->total
;
2850 monitor_printf(mon
, "Finished: %.2f %%\n", percent
);
2853 qapi_free_DumpQueryResult(result
);
2856 void hmp_info_ramblock(Monitor
*mon
, const QDict
*qdict
)
2858 ram_block_dump(mon
);
2861 void hmp_hotpluggable_cpus(Monitor
*mon
, const QDict
*qdict
)
2864 HotpluggableCPUList
*l
= qmp_query_hotpluggable_cpus(&err
);
2865 HotpluggableCPUList
*saved
= l
;
2866 CpuInstanceProperties
*c
;
2869 hmp_handle_error(mon
, &err
);
2873 monitor_printf(mon
, "Hotpluggable CPUs:\n");
2875 monitor_printf(mon
, " type: \"%s\"\n", l
->value
->type
);
2876 monitor_printf(mon
, " vcpus_count: \"%" PRIu64
"\"\n",
2877 l
->value
->vcpus_count
);
2878 if (l
->value
->has_qom_path
) {
2879 monitor_printf(mon
, " qom_path: \"%s\"\n", l
->value
->qom_path
);
2882 c
= l
->value
->props
;
2883 monitor_printf(mon
, " CPUInstance Properties:\n");
2884 if (c
->has_node_id
) {
2885 monitor_printf(mon
, " node-id: \"%" PRIu64
"\"\n", c
->node_id
);
2887 if (c
->has_socket_id
) {
2888 monitor_printf(mon
, " socket-id: \"%" PRIu64
"\"\n", c
->socket_id
);
2890 if (c
->has_core_id
) {
2891 monitor_printf(mon
, " core-id: \"%" PRIu64
"\"\n", c
->core_id
);
2893 if (c
->has_thread_id
) {
2894 monitor_printf(mon
, " thread-id: \"%" PRIu64
"\"\n", c
->thread_id
);
2900 qapi_free_HotpluggableCPUList(saved
);
2903 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
2906 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
2908 monitor_printf(mon
, "%s\n", info
->guid
);
2910 hmp_handle_error(mon
, &err
);
2911 qapi_free_GuidInfo(info
);
2914 void hmp_info_memory_size_summary(Monitor
*mon
, const QDict
*qdict
)
2917 MemoryInfo
*info
= qmp_query_memory_size_summary(&err
);
2919 monitor_printf(mon
, "base memory: %" PRIu64
"\n",
2922 if (info
->has_plugged_memory
) {
2923 monitor_printf(mon
, "plugged memory: %" PRIu64
"\n",
2924 info
->plugged_memory
);
2927 qapi_free_MemoryInfo(info
);
2929 hmp_handle_error(mon
, &err
);