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 "qemu/sockets.h"
27 #include "monitor/monitor.h"
28 #include "monitor/qdev.h"
29 #include "qapi/error.h"
30 #include "qapi/opts-visitor.h"
31 #include "qapi/qapi-builtin-visit.h"
32 #include "qapi/qapi-commands-block.h"
33 #include "qapi/qapi-commands-char.h"
34 #include "qapi/qapi-commands-migration.h"
35 #include "qapi/qapi-commands-misc.h"
36 #include "qapi/qapi-commands-net.h"
37 #include "qapi/qapi-commands-rocker.h"
38 #include "qapi/qapi-commands-run-state.h"
39 #include "qapi/qapi-commands-tpm.h"
40 #include "qapi/qapi-commands-ui.h"
41 #include "qapi/qmp/qdict.h"
42 #include "qapi/qmp/qerror.h"
43 #include "qapi/string-input-visitor.h"
44 #include "qapi/string-output-visitor.h"
45 #include "qom/object_interfaces.h"
46 #include "ui/console.h"
47 #include "block/nbd.h"
48 #include "block/qapi.h"
50 #include "qemu/cutils.h"
51 #include "qemu/error-report.h"
52 #include "exec/ramlist.h"
53 #include "hw/intc/intc.h"
54 #include "migration/snapshot.h"
55 #include "migration/misc.h"
58 #include <spice/enums.h>
61 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
65 error_report_err(*errp
);
69 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
73 info
= qmp_query_name(NULL
);
75 monitor_printf(mon
, "%s\n", info
->name
);
77 qapi_free_NameInfo(info
);
80 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
84 info
= qmp_query_version(NULL
);
86 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
87 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
90 qapi_free_VersionInfo(info
);
93 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
97 info
= qmp_query_kvm(NULL
);
98 monitor_printf(mon
, "kvm support: ");
100 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
102 monitor_printf(mon
, "not compiled\n");
105 qapi_free_KvmInfo(info
);
108 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
112 info
= qmp_query_status(NULL
);
114 monitor_printf(mon
, "VM status: %s%s",
115 info
->running
? "running" : "paused",
116 info
->singlestep
? " (single step mode)" : "");
118 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
119 monitor_printf(mon
, " (%s)", RunState_str(info
->status
));
122 monitor_printf(mon
, "\n");
124 qapi_free_StatusInfo(info
);
127 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
131 info
= qmp_query_uuid(NULL
);
132 monitor_printf(mon
, "%s\n", info
->UUID
);
133 qapi_free_UuidInfo(info
);
136 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
138 ChardevInfoList
*char_info
, *info
;
140 char_info
= qmp_query_chardev(NULL
);
141 for (info
= char_info
; info
; info
= info
->next
) {
142 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
143 info
->value
->filename
);
146 qapi_free_ChardevInfoList(char_info
);
149 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
151 MouseInfoList
*mice_list
, *mouse
;
153 mice_list
= qmp_query_mice(NULL
);
155 monitor_printf(mon
, "No mouse devices connected\n");
159 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
160 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
161 mouse
->value
->current
? '*' : ' ',
162 mouse
->value
->index
, mouse
->value
->name
,
163 mouse
->value
->absolute
? " (absolute)" : "");
166 qapi_free_MouseInfoList(mice_list
);
169 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
172 MigrationCapabilityStatusList
*caps
, *cap
;
174 info
= qmp_query_migrate(NULL
);
175 caps
= qmp_query_migrate_capabilities(NULL
);
177 migration_global_dump(mon
);
179 /* do not display parameters during setup */
180 if (info
->has_status
&& caps
) {
181 monitor_printf(mon
, "capabilities: ");
182 for (cap
= caps
; cap
; cap
= cap
->next
) {
183 monitor_printf(mon
, "%s: %s ",
184 MigrationCapability_str(cap
->value
->capability
),
185 cap
->value
->state
? "on" : "off");
187 monitor_printf(mon
, "\n");
190 if (info
->has_status
) {
191 monitor_printf(mon
, "Migration status: %s",
192 MigrationStatus_str(info
->status
));
193 if (info
->status
== MIGRATION_STATUS_FAILED
&&
194 info
->has_error_desc
) {
195 monitor_printf(mon
, " (%s)\n", info
->error_desc
);
197 monitor_printf(mon
, "\n");
200 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
202 if (info
->has_expected_downtime
) {
203 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
204 info
->expected_downtime
);
206 if (info
->has_downtime
) {
207 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
210 if (info
->has_setup_time
) {
211 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
217 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
218 info
->ram
->transferred
>> 10);
219 monitor_printf(mon
, "throughput: %0.2f mbps\n",
221 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
222 info
->ram
->remaining
>> 10);
223 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
224 info
->ram
->total
>> 10);
225 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
226 info
->ram
->duplicate
);
227 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
229 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
231 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
232 info
->ram
->normal_bytes
>> 10);
233 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
234 info
->ram
->dirty_sync_count
);
235 monitor_printf(mon
, "page size: %" PRIu64
" kbytes\n",
236 info
->ram
->page_size
>> 10);
238 if (info
->ram
->dirty_pages_rate
) {
239 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
240 info
->ram
->dirty_pages_rate
);
242 if (info
->ram
->postcopy_requests
) {
243 monitor_printf(mon
, "postcopy request count: %" PRIu64
"\n",
244 info
->ram
->postcopy_requests
);
248 if (info
->has_disk
) {
249 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
250 info
->disk
->transferred
>> 10);
251 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
252 info
->disk
->remaining
>> 10);
253 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
254 info
->disk
->total
>> 10);
257 if (info
->has_xbzrle_cache
) {
258 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
259 info
->xbzrle_cache
->cache_size
);
260 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
261 info
->xbzrle_cache
->bytes
>> 10);
262 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
263 info
->xbzrle_cache
->pages
);
264 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
265 info
->xbzrle_cache
->cache_miss
);
266 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
267 info
->xbzrle_cache
->cache_miss_rate
);
268 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
269 info
->xbzrle_cache
->overflow
);
272 if (info
->has_cpu_throttle_percentage
) {
273 monitor_printf(mon
, "cpu throttle percentage: %" PRIu64
"\n",
274 info
->cpu_throttle_percentage
);
277 qapi_free_MigrationInfo(info
);
278 qapi_free_MigrationCapabilityStatusList(caps
);
281 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
283 MigrationCapabilityStatusList
*caps
, *cap
;
285 caps
= qmp_query_migrate_capabilities(NULL
);
288 for (cap
= caps
; cap
; cap
= cap
->next
) {
289 monitor_printf(mon
, "%s: %s\n",
290 MigrationCapability_str(cap
->value
->capability
),
291 cap
->value
->state
? "on" : "off");
295 qapi_free_MigrationCapabilityStatusList(caps
);
298 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
300 MigrationParameters
*params
;
302 params
= qmp_query_migrate_parameters(NULL
);
305 assert(params
->has_compress_level
);
306 monitor_printf(mon
, "%s: %u\n",
307 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL
),
308 params
->compress_level
);
309 assert(params
->has_compress_threads
);
310 monitor_printf(mon
, "%s: %u\n",
311 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS
),
312 params
->compress_threads
);
313 assert(params
->has_decompress_threads
);
314 monitor_printf(mon
, "%s: %u\n",
315 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS
),
316 params
->decompress_threads
);
317 assert(params
->has_cpu_throttle_initial
);
318 monitor_printf(mon
, "%s: %u\n",
319 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
),
320 params
->cpu_throttle_initial
);
321 assert(params
->has_cpu_throttle_increment
);
322 monitor_printf(mon
, "%s: %u\n",
323 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
),
324 params
->cpu_throttle_increment
);
325 assert(params
->has_tls_creds
);
326 monitor_printf(mon
, "%s: '%s'\n",
327 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS
),
329 assert(params
->has_tls_hostname
);
330 monitor_printf(mon
, "%s: '%s'\n",
331 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME
),
332 params
->tls_hostname
);
333 assert(params
->has_max_bandwidth
);
334 monitor_printf(mon
, "%s: %" PRIu64
" bytes/second\n",
335 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH
),
336 params
->max_bandwidth
);
337 assert(params
->has_downtime_limit
);
338 monitor_printf(mon
, "%s: %" PRIu64
" milliseconds\n",
339 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT
),
340 params
->downtime_limit
);
341 assert(params
->has_x_checkpoint_delay
);
342 monitor_printf(mon
, "%s: %u\n",
343 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
),
344 params
->x_checkpoint_delay
);
345 assert(params
->has_block_incremental
);
346 monitor_printf(mon
, "%s: %s\n",
347 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL
),
348 params
->block_incremental
? "on" : "off");
349 monitor_printf(mon
, "%s: %u\n",
350 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_CHANNELS
),
351 params
->x_multifd_channels
);
352 monitor_printf(mon
, "%s: %u\n",
353 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT
),
354 params
->x_multifd_page_count
);
355 monitor_printf(mon
, "%s: %" PRIu64
"\n",
356 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
),
357 params
->xbzrle_cache_size
);
360 qapi_free_MigrationParameters(params
);
363 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
365 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
366 qmp_query_migrate_cache_size(NULL
) >> 10);
369 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
371 CpuInfoFastList
*cpu_list
, *cpu
;
373 cpu_list
= qmp_query_cpus_fast(NULL
);
375 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
378 if (cpu
->value
->cpu_index
== monitor_get_cpu_index()) {
382 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
,
383 cpu
->value
->cpu_index
);
384 monitor_printf(mon
, " thread-id=%" PRId64
"\n", cpu
->value
->thread_id
);
387 qapi_free_CpuInfoFastList(cpu_list
);
390 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
391 BlockDeviceInfo
*inserted
, bool verbose
)
393 ImageInfo
*image_info
;
395 assert(!info
|| !info
->has_inserted
|| info
->inserted
== inserted
);
397 if (info
&& *info
->device
) {
398 monitor_printf(mon
, "%s", info
->device
);
399 if (inserted
&& inserted
->has_node_name
) {
400 monitor_printf(mon
, " (%s)", inserted
->node_name
);
403 assert(info
|| inserted
);
404 monitor_printf(mon
, "%s",
405 inserted
&& inserted
->has_node_name
? inserted
->node_name
406 : info
&& info
->has_qdev
? info
->qdev
411 monitor_printf(mon
, ": %s (%s%s%s)\n",
414 inserted
->ro
? ", read-only" : "",
415 inserted
->encrypted
? ", encrypted" : "");
417 monitor_printf(mon
, ": [not inserted]\n");
421 if (info
->has_qdev
) {
422 monitor_printf(mon
, " Attached to: %s\n", info
->qdev
);
424 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
425 monitor_printf(mon
, " I/O status: %s\n",
426 BlockDeviceIoStatus_str(info
->io_status
));
429 if (info
->removable
) {
430 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
431 info
->locked
? "" : "not ",
432 info
->tray_open
? "open" : "closed");
441 monitor_printf(mon
, " Cache mode: %s%s%s\n",
442 inserted
->cache
->writeback
? "writeback" : "writethrough",
443 inserted
->cache
->direct
? ", direct" : "",
444 inserted
->cache
->no_flush
? ", ignore flushes" : "");
446 if (inserted
->has_backing_file
) {
449 "(chain depth: %" PRId64
")\n",
450 inserted
->backing_file
,
451 inserted
->backing_file_depth
);
454 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
455 monitor_printf(mon
, " Detect zeroes: %s\n",
456 BlockdevDetectZeroesOptions_str(inserted
->detect_zeroes
));
459 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
460 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
462 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
463 " bps_rd=%" PRId64
" bps_wr=%" PRId64
465 " bps_rd_max=%" PRId64
466 " bps_wr_max=%" PRId64
467 " iops=%" PRId64
" iops_rd=%" PRId64
470 " iops_rd_max=%" PRId64
471 " iops_wr_max=%" PRId64
472 " iops_size=%" PRId64
478 inserted
->bps_rd_max
,
479 inserted
->bps_wr_max
,
484 inserted
->iops_rd_max
,
485 inserted
->iops_wr_max
,
491 monitor_printf(mon
, "\nImages:\n");
492 image_info
= inserted
->image
;
494 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
496 if (image_info
->has_backing_image
) {
497 image_info
= image_info
->backing_image
;
505 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
507 BlockInfoList
*block_list
, *info
;
508 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
509 const char *device
= qdict_get_try_str(qdict
, "device");
510 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
511 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
512 bool printed
= false;
514 /* Print BlockBackend information */
516 block_list
= qmp_query_block(NULL
);
521 for (info
= block_list
; info
; info
= info
->next
) {
522 if (device
&& strcmp(device
, info
->value
->device
)) {
526 if (info
!= block_list
) {
527 monitor_printf(mon
, "\n");
530 print_block_info(mon
, info
->value
, info
->value
->has_inserted
531 ? info
->value
->inserted
: NULL
,
536 qapi_free_BlockInfoList(block_list
);
538 if ((!device
&& !nodes
) || printed
) {
542 /* Print node information */
543 blockdev_list
= qmp_query_named_block_nodes(NULL
);
544 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
545 assert(blockdev
->value
->has_node_name
);
546 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
550 if (blockdev
!= blockdev_list
) {
551 monitor_printf(mon
, "\n");
554 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
556 qapi_free_BlockDeviceInfoList(blockdev_list
);
559 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
561 BlockStatsList
*stats_list
, *stats
;
563 stats_list
= qmp_query_blockstats(false, false, NULL
);
565 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
566 if (!stats
->value
->has_device
) {
570 monitor_printf(mon
, "%s:", stats
->value
->device
);
571 monitor_printf(mon
, " rd_bytes=%" PRId64
573 " rd_operations=%" PRId64
574 " wr_operations=%" PRId64
575 " flush_operations=%" PRId64
576 " wr_total_time_ns=%" PRId64
577 " rd_total_time_ns=%" PRId64
578 " flush_total_time_ns=%" PRId64
579 " rd_merged=%" PRId64
580 " wr_merged=%" PRId64
581 " idle_time_ns=%" PRId64
583 stats
->value
->stats
->rd_bytes
,
584 stats
->value
->stats
->wr_bytes
,
585 stats
->value
->stats
->rd_operations
,
586 stats
->value
->stats
->wr_operations
,
587 stats
->value
->stats
->flush_operations
,
588 stats
->value
->stats
->wr_total_time_ns
,
589 stats
->value
->stats
->rd_total_time_ns
,
590 stats
->value
->stats
->flush_total_time_ns
,
591 stats
->value
->stats
->rd_merged
,
592 stats
->value
->stats
->wr_merged
,
593 stats
->value
->stats
->idle_time_ns
);
596 qapi_free_BlockStatsList(stats_list
);
599 /* Helper for hmp_info_vnc_clients, _servers */
600 static void hmp_info_VncBasicInfo(Monitor
*mon
, VncBasicInfo
*info
,
603 monitor_printf(mon
, " %s: %s:%s (%s%s)\n",
607 NetworkAddressFamily_str(info
->family
),
608 info
->websocket
? " (Websocket)" : "");
611 /* Helper displaying and auth and crypt info */
612 static void hmp_info_vnc_authcrypt(Monitor
*mon
, const char *indent
,
614 VncVencryptSubAuth
*vencrypt
)
616 monitor_printf(mon
, "%sAuth: %s (Sub: %s)\n", indent
,
617 VncPrimaryAuth_str(auth
),
618 vencrypt
? VncVencryptSubAuth_str(*vencrypt
) : "none");
621 static void hmp_info_vnc_clients(Monitor
*mon
, VncClientInfoList
*client
)
624 VncClientInfo
*cinfo
= client
->value
;
626 hmp_info_VncBasicInfo(mon
, qapi_VncClientInfo_base(cinfo
), "Client");
627 monitor_printf(mon
, " x509_dname: %s\n",
628 cinfo
->has_x509_dname
?
629 cinfo
->x509_dname
: "none");
630 monitor_printf(mon
, " sasl_username: %s\n",
631 cinfo
->has_sasl_username
?
632 cinfo
->sasl_username
: "none");
634 client
= client
->next
;
638 static void hmp_info_vnc_servers(Monitor
*mon
, VncServerInfo2List
*server
)
641 VncServerInfo2
*sinfo
= server
->value
;
642 hmp_info_VncBasicInfo(mon
, qapi_VncServerInfo2_base(sinfo
), "Server");
643 hmp_info_vnc_authcrypt(mon
, " ", sinfo
->auth
,
644 sinfo
->has_vencrypt
? &sinfo
->vencrypt
: NULL
);
645 server
= server
->next
;
649 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
651 VncInfo2List
*info2l
;
654 info2l
= qmp_query_vnc_servers(&err
);
656 hmp_handle_error(mon
, &err
);
660 monitor_printf(mon
, "None\n");
665 VncInfo2
*info
= info2l
->value
;
666 monitor_printf(mon
, "%s:\n", info
->id
);
667 hmp_info_vnc_servers(mon
, info
->server
);
668 hmp_info_vnc_clients(mon
, info
->clients
);
670 /* The server entry displays its auth, we only
671 * need to display in the case of 'reverse' connections
672 * where there's no server.
674 hmp_info_vnc_authcrypt(mon
, " ", info
->auth
,
675 info
->has_vencrypt
? &info
->vencrypt
: NULL
);
677 if (info
->has_display
) {
678 monitor_printf(mon
, " Display: %s\n", info
->display
);
680 info2l
= info2l
->next
;
683 qapi_free_VncInfo2List(info2l
);
688 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
690 SpiceChannelList
*chan
;
692 const char *channel_name
;
693 const char * const channel_names
[] = {
694 [SPICE_CHANNEL_MAIN
] = "main",
695 [SPICE_CHANNEL_DISPLAY
] = "display",
696 [SPICE_CHANNEL_INPUTS
] = "inputs",
697 [SPICE_CHANNEL_CURSOR
] = "cursor",
698 [SPICE_CHANNEL_PLAYBACK
] = "playback",
699 [SPICE_CHANNEL_RECORD
] = "record",
700 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
701 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
702 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
703 [SPICE_CHANNEL_PORT
] = "port",
705 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
706 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
707 * as quick fix for build failures with older versions. */
708 [SPICE_CHANNEL_WEBDAV
] = "webdav",
712 info
= qmp_query_spice(NULL
);
714 if (!info
->enabled
) {
715 monitor_printf(mon
, "Server: disabled\n");
719 monitor_printf(mon
, "Server:\n");
720 if (info
->has_port
) {
721 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
722 info
->host
, info
->port
);
724 if (info
->has_tls_port
) {
725 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
726 info
->host
, info
->tls_port
);
728 monitor_printf(mon
, " migrated: %s\n",
729 info
->migrated
? "true" : "false");
730 monitor_printf(mon
, " auth: %s\n", info
->auth
);
731 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
732 monitor_printf(mon
, " mouse-mode: %s\n",
733 SpiceQueryMouseMode_str(info
->mouse_mode
));
735 if (!info
->has_channels
|| info
->channels
== NULL
) {
736 monitor_printf(mon
, "Channels: none\n");
738 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
739 monitor_printf(mon
, "Channel:\n");
740 monitor_printf(mon
, " address: %s:%s%s\n",
741 chan
->value
->host
, chan
->value
->port
,
742 chan
->value
->tls
? " [tls]" : "");
743 monitor_printf(mon
, " session: %" PRId64
"\n",
744 chan
->value
->connection_id
);
745 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
746 chan
->value
->channel_type
, chan
->value
->channel_id
);
748 channel_name
= "unknown";
749 if (chan
->value
->channel_type
> 0 &&
750 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
751 channel_names
[chan
->value
->channel_type
]) {
752 channel_name
= channel_names
[chan
->value
->channel_type
];
755 monitor_printf(mon
, " channel name: %s\n", channel_name
);
760 qapi_free_SpiceInfo(info
);
764 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
769 info
= qmp_query_balloon(&err
);
771 hmp_handle_error(mon
, &err
);
775 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
777 qapi_free_BalloonInfo(info
);
780 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
782 PciMemoryRegionList
*region
;
784 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
785 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
786 dev
->slot
, dev
->function
);
787 monitor_printf(mon
, " ");
789 if (dev
->class_info
->has_desc
) {
790 monitor_printf(mon
, "%s", dev
->class_info
->desc
);
792 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
795 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
796 dev
->id
->vendor
, dev
->id
->device
);
799 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
802 if (dev
->has_pci_bridge
) {
803 monitor_printf(mon
, " BUS %" PRId64
".\n",
804 dev
->pci_bridge
->bus
->number
);
805 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
806 dev
->pci_bridge
->bus
->secondary
);
807 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
808 dev
->pci_bridge
->bus
->subordinate
);
810 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
811 dev
->pci_bridge
->bus
->io_range
->base
,
812 dev
->pci_bridge
->bus
->io_range
->limit
);
815 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
816 dev
->pci_bridge
->bus
->memory_range
->base
,
817 dev
->pci_bridge
->bus
->memory_range
->limit
);
819 monitor_printf(mon
, " prefetchable memory range "
820 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
821 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
822 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
825 for (region
= dev
->regions
; region
; region
= region
->next
) {
828 addr
= region
->value
->address
;
829 size
= region
->value
->size
;
831 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
833 if (!strcmp(region
->value
->type
, "io")) {
834 monitor_printf(mon
, "I/O at 0x%04" PRIx64
835 " [0x%04" PRIx64
"].\n",
836 addr
, addr
+ size
- 1);
838 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
839 " [0x%08" PRIx64
"].\n",
840 region
->value
->mem_type_64
? 64 : 32,
841 region
->value
->prefetch
? " prefetchable" : "",
842 addr
, addr
+ size
- 1);
846 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
848 if (dev
->has_pci_bridge
) {
849 if (dev
->pci_bridge
->has_devices
) {
850 PciDeviceInfoList
*cdev
;
851 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
852 hmp_info_pci_device(mon
, cdev
->value
);
858 static int hmp_info_irq_foreach(Object
*obj
, void *opaque
)
860 InterruptStatsProvider
*intc
;
861 InterruptStatsProviderClass
*k
;
862 Monitor
*mon
= opaque
;
864 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
865 intc
= INTERRUPT_STATS_PROVIDER(obj
);
866 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
867 uint64_t *irq_counts
;
868 unsigned int nb_irqs
, i
;
869 if (k
->get_statistics
&&
870 k
->get_statistics(intc
, &irq_counts
, &nb_irqs
)) {
872 monitor_printf(mon
, "IRQ statistics for %s:\n",
873 object_get_typename(obj
));
874 for (i
= 0; i
< nb_irqs
; i
++) {
875 if (irq_counts
[i
] > 0) {
876 monitor_printf(mon
, "%2d: %" PRId64
"\n", i
,
882 monitor_printf(mon
, "IRQ statistics not available for %s.\n",
883 object_get_typename(obj
));
890 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
)
892 object_child_foreach_recursive(object_get_root(),
893 hmp_info_irq_foreach
, mon
);
896 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
898 InterruptStatsProvider
*intc
;
899 InterruptStatsProviderClass
*k
;
900 Monitor
*mon
= opaque
;
902 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
903 intc
= INTERRUPT_STATS_PROVIDER(obj
);
904 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
906 k
->print_info(intc
, mon
);
908 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
909 object_get_typename(obj
));
916 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
918 object_child_foreach_recursive(object_get_root(),
919 hmp_info_pic_foreach
, mon
);
922 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
924 PciInfoList
*info_list
, *info
;
927 info_list
= qmp_query_pci(&err
);
929 monitor_printf(mon
, "PCI devices not supported\n");
934 for (info
= info_list
; info
; info
= info
->next
) {
935 PciDeviceInfoList
*dev
;
937 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
938 hmp_info_pci_device(mon
, dev
->value
);
942 qapi_free_PciInfoList(info_list
);
945 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
947 BlockJobInfoList
*list
;
950 list
= qmp_query_block_jobs(&err
);
954 monitor_printf(mon
, "No active jobs\n");
959 if (strcmp(list
->value
->type
, "stream") == 0) {
960 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
961 " of %" PRId64
" bytes, speed limit %" PRId64
968 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
969 " of %" PRId64
" bytes, speed limit %" PRId64
980 qapi_free_BlockJobInfoList(list
);
983 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
985 TPMInfoList
*info_list
, *info
;
988 TPMPassthroughOptions
*tpo
;
989 TPMEmulatorOptions
*teo
;
991 info_list
= qmp_query_tpm(&err
);
993 monitor_printf(mon
, "TPM device not supported\n");
999 monitor_printf(mon
, "TPM device:\n");
1002 for (info
= info_list
; info
; info
= info
->next
) {
1003 TPMInfo
*ti
= info
->value
;
1004 monitor_printf(mon
, " tpm%d: model=%s\n",
1005 c
, TpmModel_str(ti
->model
));
1007 monitor_printf(mon
, " \\ %s: type=%s",
1008 ti
->id
, TpmTypeOptionsKind_str(ti
->options
->type
));
1010 switch (ti
->options
->type
) {
1011 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
1012 tpo
= ti
->options
->u
.passthrough
.data
;
1013 monitor_printf(mon
, "%s%s%s%s",
1014 tpo
->has_path
? ",path=" : "",
1015 tpo
->has_path
? tpo
->path
: "",
1016 tpo
->has_cancel_path
? ",cancel-path=" : "",
1017 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
1019 case TPM_TYPE_OPTIONS_KIND_EMULATOR
:
1020 teo
= ti
->options
->u
.emulator
.data
;
1021 monitor_printf(mon
, ",chardev=%s", teo
->chardev
);
1023 case TPM_TYPE_OPTIONS_KIND__MAX
:
1026 monitor_printf(mon
, "\n");
1029 qapi_free_TPMInfoList(info_list
);
1032 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
1034 monitor_suspend(mon
);
1038 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
1043 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
1045 qmp_system_reset(NULL
);
1048 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
1050 qmp_system_powerdown(NULL
);
1053 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
1057 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1058 use it are converted to the QAPI */
1059 cpu_index
= qdict_get_int(qdict
, "index");
1060 if (monitor_set_cpu(cpu_index
) < 0) {
1061 monitor_printf(mon
, "invalid CPU index\n");
1065 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
1067 uint32_t size
= qdict_get_int(qdict
, "size");
1068 const char *filename
= qdict_get_str(qdict
, "filename");
1069 uint64_t addr
= qdict_get_int(qdict
, "val");
1071 int cpu_index
= monitor_get_cpu_index();
1073 if (cpu_index
< 0) {
1074 monitor_printf(mon
, "No CPU available\n");
1078 qmp_memsave(addr
, size
, filename
, true, cpu_index
, &err
);
1079 hmp_handle_error(mon
, &err
);
1082 void hmp_pmemsave(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");
1089 qmp_pmemsave(addr
, size
, filename
, &err
);
1090 hmp_handle_error(mon
, &err
);
1093 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
1095 const char *chardev
= qdict_get_str(qdict
, "device");
1096 const char *data
= qdict_get_str(qdict
, "data");
1099 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
1101 hmp_handle_error(mon
, &err
);
1104 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
1106 uint32_t size
= qdict_get_int(qdict
, "size");
1107 const char *chardev
= qdict_get_str(qdict
, "device");
1112 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
1114 hmp_handle_error(mon
, &err
);
1118 for (i
= 0; data
[i
]; i
++) {
1119 unsigned char ch
= data
[i
];
1122 monitor_printf(mon
, "\\\\");
1123 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
1124 monitor_printf(mon
, "\\u%04X", ch
);
1126 monitor_printf(mon
, "%c", ch
);
1130 monitor_printf(mon
, "\n");
1134 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
1139 hmp_handle_error(mon
, &err
);
1142 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
1144 qmp_system_wakeup(NULL
);
1147 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
1151 qmp_inject_nmi(&err
);
1152 hmp_handle_error(mon
, &err
);
1155 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
1157 const char *name
= qdict_get_str(qdict
, "name");
1158 bool up
= qdict_get_bool(qdict
, "up");
1161 qmp_set_link(name
, up
, &err
);
1162 hmp_handle_error(mon
, &err
);
1165 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
1167 const char *device
= qdict_get_str(qdict
, "device");
1168 const char *password
= qdict_get_str(qdict
, "password");
1171 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
1172 hmp_handle_error(mon
, &err
);
1175 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1177 int64_t value
= qdict_get_int(qdict
, "value");
1180 qmp_balloon(value
, &err
);
1181 hmp_handle_error(mon
, &err
);
1184 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
1186 const char *device
= qdict_get_str(qdict
, "device");
1187 int64_t size
= qdict_get_int(qdict
, "size");
1190 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
1191 hmp_handle_error(mon
, &err
);
1194 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
1196 const char *filename
= qdict_get_str(qdict
, "target");
1197 const char *format
= qdict_get_try_str(qdict
, "format");
1198 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1199 bool full
= qdict_get_try_bool(qdict
, "full", false);
1201 DriveMirror mirror
= {
1202 .device
= (char *)qdict_get_str(qdict
, "device"),
1203 .target
= (char *)filename
,
1204 .has_format
= !!format
,
1205 .format
= (char *)format
,
1206 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1208 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1213 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1214 hmp_handle_error(mon
, &err
);
1217 qmp_drive_mirror(&mirror
, &err
);
1218 hmp_handle_error(mon
, &err
);
1221 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
1223 const char *device
= qdict_get_str(qdict
, "device");
1224 const char *filename
= qdict_get_str(qdict
, "target");
1225 const char *format
= qdict_get_try_str(qdict
, "format");
1226 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1227 bool full
= qdict_get_try_bool(qdict
, "full", false);
1228 bool compress
= qdict_get_try_bool(qdict
, "compress", false);
1230 DriveBackup backup
= {
1231 .device
= (char *)device
,
1232 .target
= (char *)filename
,
1233 .has_format
= !!format
,
1234 .format
= (char *)format
,
1235 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1237 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1238 .has_compress
= !!compress
,
1239 .compress
= compress
,
1243 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1244 hmp_handle_error(mon
, &err
);
1248 qmp_drive_backup(&backup
, &err
);
1249 hmp_handle_error(mon
, &err
);
1252 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
1254 const char *device
= qdict_get_str(qdict
, "device");
1255 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
1256 const char *format
= qdict_get_try_str(qdict
, "format");
1257 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1258 enum NewImageMode mode
;
1262 /* In the future, if 'snapshot-file' is not specified, the snapshot
1263 will be taken internally. Today it's actually required. */
1264 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
1265 hmp_handle_error(mon
, &err
);
1269 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1270 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
1271 filename
, false, NULL
,
1274 hmp_handle_error(mon
, &err
);
1277 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1279 const char *device
= qdict_get_str(qdict
, "device");
1280 const char *name
= qdict_get_str(qdict
, "name");
1283 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1284 hmp_handle_error(mon
, &err
);
1287 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1289 const char *device
= qdict_get_str(qdict
, "device");
1290 const char *name
= qdict_get_str(qdict
, "name");
1291 const char *id
= qdict_get_try_str(qdict
, "id");
1294 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1296 hmp_handle_error(mon
, &err
);
1299 void hmp_loadvm(Monitor
*mon
, const QDict
*qdict
)
1301 int saved_vm_running
= runstate_is_running();
1302 const char *name
= qdict_get_str(qdict
, "name");
1305 vm_stop(RUN_STATE_RESTORE_VM
);
1307 if (load_snapshot(name
, &err
) == 0 && saved_vm_running
) {
1310 hmp_handle_error(mon
, &err
);
1313 void hmp_savevm(Monitor
*mon
, const QDict
*qdict
)
1317 save_snapshot(qdict_get_try_str(qdict
, "name"), &err
);
1318 hmp_handle_error(mon
, &err
);
1321 void hmp_delvm(Monitor
*mon
, const QDict
*qdict
)
1323 BlockDriverState
*bs
;
1325 const char *name
= qdict_get_str(qdict
, "name");
1327 if (bdrv_all_delete_snapshot(name
, &bs
, &err
) < 0) {
1328 error_reportf_err(err
,
1329 "Error while deleting snapshot on device '%s': ",
1330 bdrv_get_device_name(bs
));
1334 void hmp_info_snapshots(Monitor
*mon
, const QDict
*qdict
)
1336 BlockDriverState
*bs
, *bs1
;
1337 BdrvNextIterator it1
;
1338 QEMUSnapshotInfo
*sn_tab
, *sn
;
1339 bool no_snapshot
= true;
1342 int *global_snapshots
;
1343 AioContext
*aio_context
;
1345 typedef struct SnapshotEntry
{
1346 QEMUSnapshotInfo sn
;
1347 QTAILQ_ENTRY(SnapshotEntry
) next
;
1350 typedef struct ImageEntry
{
1351 const char *imagename
;
1352 QTAILQ_ENTRY(ImageEntry
) next
;
1353 QTAILQ_HEAD(, SnapshotEntry
) snapshots
;
1356 QTAILQ_HEAD(, ImageEntry
) image_list
=
1357 QTAILQ_HEAD_INITIALIZER(image_list
);
1359 ImageEntry
*image_entry
, *next_ie
;
1360 SnapshotEntry
*snapshot_entry
;
1362 bs
= bdrv_all_find_vmstate_bs();
1364 monitor_printf(mon
, "No available block device supports snapshots\n");
1367 aio_context
= bdrv_get_aio_context(bs
);
1369 aio_context_acquire(aio_context
);
1370 nb_sns
= bdrv_snapshot_list(bs
, &sn_tab
);
1371 aio_context_release(aio_context
);
1374 monitor_printf(mon
, "bdrv_snapshot_list: error %d\n", nb_sns
);
1378 for (bs1
= bdrv_first(&it1
); bs1
; bs1
= bdrv_next(&it1
)) {
1382 AioContext
*ctx
= bdrv_get_aio_context(bs1
);
1384 aio_context_acquire(ctx
);
1385 if (bdrv_can_snapshot(bs1
)) {
1387 bs1_nb_sns
= bdrv_snapshot_list(bs1
, &sn
);
1388 if (bs1_nb_sns
> 0) {
1389 no_snapshot
= false;
1390 ie
= g_new0(ImageEntry
, 1);
1391 ie
->imagename
= bdrv_get_device_name(bs1
);
1392 QTAILQ_INIT(&ie
->snapshots
);
1393 QTAILQ_INSERT_TAIL(&image_list
, ie
, next
);
1394 for (i
= 0; i
< bs1_nb_sns
; i
++) {
1395 se
= g_new0(SnapshotEntry
, 1);
1397 QTAILQ_INSERT_TAIL(&ie
->snapshots
, se
, next
);
1402 aio_context_release(ctx
);
1406 monitor_printf(mon
, "There is no snapshot available.\n");
1410 global_snapshots
= g_new0(int, nb_sns
);
1412 for (i
= 0; i
< nb_sns
; i
++) {
1413 SnapshotEntry
*next_sn
;
1414 if (bdrv_all_find_snapshot(sn_tab
[i
].name
, &bs1
) == 0) {
1415 global_snapshots
[total
] = i
;
1417 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1418 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
,
1420 if (!strcmp(sn_tab
[i
].name
, snapshot_entry
->sn
.name
)) {
1421 QTAILQ_REMOVE(&image_entry
->snapshots
, snapshot_entry
,
1423 g_free(snapshot_entry
);
1430 monitor_printf(mon
, "List of snapshots present on all disks:\n");
1433 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1434 monitor_printf(mon
, "\n");
1435 for (i
= 0; i
< total
; i
++) {
1436 sn
= &sn_tab
[global_snapshots
[i
]];
1437 /* The ID is not guaranteed to be the same on all images, so
1440 pstrcpy(sn
->id_str
, sizeof(sn
->id_str
), "--");
1441 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, sn
);
1442 monitor_printf(mon
, "\n");
1445 monitor_printf(mon
, "None\n");
1448 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1449 if (QTAILQ_EMPTY(&image_entry
->snapshots
)) {
1453 "\nList of partial (non-loadable) snapshots on '%s':\n",
1454 image_entry
->imagename
);
1455 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1456 monitor_printf(mon
, "\n");
1457 QTAILQ_FOREACH(snapshot_entry
, &image_entry
->snapshots
, next
) {
1458 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
,
1459 &snapshot_entry
->sn
);
1460 monitor_printf(mon
, "\n");
1464 QTAILQ_FOREACH_SAFE(image_entry
, &image_list
, next
, next_ie
) {
1465 SnapshotEntry
*next_sn
;
1466 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
, next
,
1468 g_free(snapshot_entry
);
1470 g_free(image_entry
);
1473 g_free(global_snapshots
);
1477 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1479 qmp_migrate_cancel(NULL
);
1482 void hmp_migrate_continue(Monitor
*mon
, const QDict
*qdict
)
1485 const char *state
= qdict_get_str(qdict
, "state");
1486 int val
= qapi_enum_parse(&MigrationStatus_lookup
, state
, -1, &err
);
1489 qmp_migrate_continue(val
, &err
);
1492 hmp_handle_error(mon
, &err
);
1495 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1498 const char *uri
= qdict_get_str(qdict
, "uri");
1500 qmp_migrate_incoming(uri
, &err
);
1502 hmp_handle_error(mon
, &err
);
1505 /* Kept for backwards compatibility */
1506 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1508 double value
= qdict_get_double(qdict
, "value");
1509 qmp_migrate_set_downtime(value
, NULL
);
1512 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1514 int64_t value
= qdict_get_int(qdict
, "value");
1517 qmp_migrate_set_cache_size(value
, &err
);
1518 hmp_handle_error(mon
, &err
);
1521 /* Kept for backwards compatibility */
1522 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1524 int64_t value
= qdict_get_int(qdict
, "value");
1525 qmp_migrate_set_speed(value
, NULL
);
1528 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1530 const char *cap
= qdict_get_str(qdict
, "capability");
1531 bool state
= qdict_get_bool(qdict
, "state");
1533 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1536 val
= qapi_enum_parse(&MigrationCapability_lookup
, cap
, -1, &err
);
1541 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1542 caps
->value
->capability
= val
;
1543 caps
->value
->state
= state
;
1545 qmp_migrate_set_capabilities(caps
, &err
);
1548 qapi_free_MigrationCapabilityStatusList(caps
);
1549 hmp_handle_error(mon
, &err
);
1552 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1554 const char *param
= qdict_get_str(qdict
, "parameter");
1555 const char *valuestr
= qdict_get_str(qdict
, "value");
1556 Visitor
*v
= string_input_visitor_new(valuestr
);
1557 MigrateSetParameters
*p
= g_new0(MigrateSetParameters
, 1);
1558 uint64_t valuebw
= 0;
1559 uint64_t cache_size
;
1563 val
= qapi_enum_parse(&MigrationParameter_lookup
, param
, -1, &err
);
1569 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1570 p
->has_compress_level
= true;
1571 visit_type_int(v
, param
, &p
->compress_level
, &err
);
1573 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1574 p
->has_compress_threads
= true;
1575 visit_type_int(v
, param
, &p
->compress_threads
, &err
);
1577 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1578 p
->has_decompress_threads
= true;
1579 visit_type_int(v
, param
, &p
->decompress_threads
, &err
);
1581 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1582 p
->has_cpu_throttle_initial
= true;
1583 visit_type_int(v
, param
, &p
->cpu_throttle_initial
, &err
);
1585 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1586 p
->has_cpu_throttle_increment
= true;
1587 visit_type_int(v
, param
, &p
->cpu_throttle_increment
, &err
);
1589 case MIGRATION_PARAMETER_TLS_CREDS
:
1590 p
->has_tls_creds
= true;
1591 p
->tls_creds
= g_new0(StrOrNull
, 1);
1592 p
->tls_creds
->type
= QTYPE_QSTRING
;
1593 visit_type_str(v
, param
, &p
->tls_creds
->u
.s
, &err
);
1595 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1596 p
->has_tls_hostname
= true;
1597 p
->tls_hostname
= g_new0(StrOrNull
, 1);
1598 p
->tls_hostname
->type
= QTYPE_QSTRING
;
1599 visit_type_str(v
, param
, &p
->tls_hostname
->u
.s
, &err
);
1601 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1602 p
->has_max_bandwidth
= true;
1604 * Can't use visit_type_size() here, because it
1605 * defaults to Bytes rather than Mebibytes.
1607 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
1608 if (ret
< 0 || valuebw
> INT64_MAX
1609 || (size_t)valuebw
!= valuebw
) {
1610 error_setg(&err
, "Invalid size %s", valuestr
);
1613 p
->max_bandwidth
= valuebw
;
1615 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1616 p
->has_downtime_limit
= true;
1617 visit_type_int(v
, param
, &p
->downtime_limit
, &err
);
1619 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
1620 p
->has_x_checkpoint_delay
= true;
1621 visit_type_int(v
, param
, &p
->x_checkpoint_delay
, &err
);
1623 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL
:
1624 p
->has_block_incremental
= true;
1625 visit_type_bool(v
, param
, &p
->block_incremental
, &err
);
1627 case MIGRATION_PARAMETER_X_MULTIFD_CHANNELS
:
1628 p
->has_x_multifd_channels
= true;
1629 visit_type_int(v
, param
, &p
->x_multifd_channels
, &err
);
1631 case MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT
:
1632 p
->has_x_multifd_page_count
= true;
1633 visit_type_int(v
, param
, &p
->x_multifd_page_count
, &err
);
1635 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
:
1636 p
->has_xbzrle_cache_size
= true;
1637 visit_type_size(v
, param
, &cache_size
, &err
);
1638 if (err
|| cache_size
> INT64_MAX
1639 || (size_t)cache_size
!= cache_size
) {
1640 error_setg(&err
, "Invalid size %s", valuestr
);
1643 p
->xbzrle_cache_size
= cache_size
;
1653 qmp_migrate_set_parameters(p
, &err
);
1656 qapi_free_MigrateSetParameters(p
);
1658 hmp_handle_error(mon
, &err
);
1661 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1664 const char *protocol
= qdict_get_str(qdict
, "protocol");
1665 const char *hostname
= qdict_get_str(qdict
, "hostname");
1666 bool has_port
= qdict_haskey(qdict
, "port");
1667 int port
= qdict_get_try_int(qdict
, "port", -1);
1668 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1669 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1670 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1672 qmp_client_migrate_info(protocol
, hostname
,
1673 has_port
, port
, has_tls_port
, tls_port
,
1674 !!cert_subject
, cert_subject
, &err
);
1675 hmp_handle_error(mon
, &err
);
1678 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1681 qmp_migrate_start_postcopy(&err
);
1682 hmp_handle_error(mon
, &err
);
1685 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1689 qmp_x_colo_lost_heartbeat(&err
);
1690 hmp_handle_error(mon
, &err
);
1693 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1695 const char *protocol
= qdict_get_str(qdict
, "protocol");
1696 const char *password
= qdict_get_str(qdict
, "password");
1697 const char *connected
= qdict_get_try_str(qdict
, "connected");
1700 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1701 hmp_handle_error(mon
, &err
);
1704 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1706 const char *protocol
= qdict_get_str(qdict
, "protocol");
1707 const char *whenstr
= qdict_get_str(qdict
, "time");
1710 qmp_expire_password(protocol
, whenstr
, &err
);
1711 hmp_handle_error(mon
, &err
);
1714 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1716 bool force
= qdict_get_try_bool(qdict
, "force", false);
1717 const char *device
= qdict_get_str(qdict
, "device");
1720 qmp_eject(true, device
, false, NULL
, true, force
, &err
);
1721 hmp_handle_error(mon
, &err
);
1724 static void hmp_change_read_arg(void *opaque
, const char *password
,
1725 void *readline_opaque
)
1727 qmp_change_vnc_password(password
, NULL
);
1728 monitor_read_command(opaque
, 1);
1731 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1733 const char *device
= qdict_get_str(qdict
, "device");
1734 const char *target
= qdict_get_str(qdict
, "target");
1735 const char *arg
= qdict_get_try_str(qdict
, "arg");
1736 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1737 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1740 if (strcmp(device
, "vnc") == 0) {
1743 "Parameter 'read-only-mode' is invalid for VNC\n");
1746 if (strcmp(target
, "passwd") == 0 ||
1747 strcmp(target
, "password") == 0) {
1749 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1753 qmp_change("vnc", target
, !!arg
, arg
, &err
);
1757 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup
,
1759 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1761 hmp_handle_error(mon
, &err
);
1766 qmp_blockdev_change_medium(true, device
, false, NULL
, target
,
1767 !!arg
, arg
, !!read_only
, read_only_mode
,
1771 hmp_handle_error(mon
, &err
);
1774 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1777 BlockIOThrottle throttle
= {
1779 .device
= (char *) qdict_get_str(qdict
, "device"),
1780 .bps
= qdict_get_int(qdict
, "bps"),
1781 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
1782 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
1783 .iops
= qdict_get_int(qdict
, "iops"),
1784 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
1785 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
1788 qmp_block_set_io_throttle(&throttle
, &err
);
1789 hmp_handle_error(mon
, &err
);
1792 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1794 Error
*error
= NULL
;
1795 const char *device
= qdict_get_str(qdict
, "device");
1796 const char *base
= qdict_get_try_str(qdict
, "base");
1797 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1799 qmp_block_stream(true, device
, device
, base
!= NULL
, base
, false, NULL
,
1800 false, NULL
, qdict_haskey(qdict
, "speed"), speed
,
1801 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1803 hmp_handle_error(mon
, &error
);
1806 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1808 Error
*error
= NULL
;
1809 const char *device
= qdict_get_str(qdict
, "device");
1810 int64_t value
= qdict_get_int(qdict
, "speed");
1812 qmp_block_job_set_speed(device
, value
, &error
);
1814 hmp_handle_error(mon
, &error
);
1817 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1819 Error
*error
= NULL
;
1820 const char *device
= qdict_get_str(qdict
, "device");
1821 bool force
= qdict_get_try_bool(qdict
, "force", false);
1823 qmp_block_job_cancel(device
, true, force
, &error
);
1825 hmp_handle_error(mon
, &error
);
1828 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1830 Error
*error
= NULL
;
1831 const char *device
= qdict_get_str(qdict
, "device");
1833 qmp_block_job_pause(device
, &error
);
1835 hmp_handle_error(mon
, &error
);
1838 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1840 Error
*error
= NULL
;
1841 const char *device
= qdict_get_str(qdict
, "device");
1843 qmp_block_job_resume(device
, &error
);
1845 hmp_handle_error(mon
, &error
);
1848 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1850 Error
*error
= NULL
;
1851 const char *device
= qdict_get_str(qdict
, "device");
1853 qmp_block_job_complete(device
, &error
);
1855 hmp_handle_error(mon
, &error
);
1858 typedef struct HMPMigrationStatus
1862 bool is_block_migration
;
1863 } HMPMigrationStatus
;
1865 static void hmp_migrate_status_cb(void *opaque
)
1867 HMPMigrationStatus
*status
= opaque
;
1868 MigrationInfo
*info
;
1870 info
= qmp_query_migrate(NULL
);
1871 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1872 info
->status
== MIGRATION_STATUS_SETUP
) {
1873 if (info
->has_disk
) {
1876 if (info
->disk
->remaining
) {
1877 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1882 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1883 monitor_flush(status
->mon
);
1886 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1888 if (status
->is_block_migration
) {
1889 monitor_printf(status
->mon
, "\n");
1891 if (info
->has_error_desc
) {
1892 error_report("%s", info
->error_desc
);
1894 monitor_resume(status
->mon
);
1895 timer_del(status
->timer
);
1899 qapi_free_MigrationInfo(info
);
1902 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1904 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1905 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1906 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1907 const char *uri
= qdict_get_str(qdict
, "uri");
1910 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1912 hmp_handle_error(mon
, &err
);
1917 HMPMigrationStatus
*status
;
1919 if (monitor_suspend(mon
) < 0) {
1920 monitor_printf(mon
, "terminal does not allow synchronous "
1921 "migration, continuing detached\n");
1925 status
= g_malloc0(sizeof(*status
));
1927 status
->is_block_migration
= blk
|| inc
;
1928 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1930 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1934 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
1938 qmp_device_add((QDict
*)qdict
, NULL
, &err
);
1939 hmp_handle_error(mon
, &err
);
1942 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1944 const char *id
= qdict_get_str(qdict
, "id");
1947 qmp_device_del(id
, &err
);
1948 hmp_handle_error(mon
, &err
);
1951 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1954 bool paging
= qdict_get_try_bool(qdict
, "paging", false);
1955 bool zlib
= qdict_get_try_bool(qdict
, "zlib", false);
1956 bool lzo
= qdict_get_try_bool(qdict
, "lzo", false);
1957 bool snappy
= qdict_get_try_bool(qdict
, "snappy", false);
1958 const char *file
= qdict_get_str(qdict
, "filename");
1959 bool has_begin
= qdict_haskey(qdict
, "begin");
1960 bool has_length
= qdict_haskey(qdict
, "length");
1961 bool has_detach
= qdict_haskey(qdict
, "detach");
1964 bool detach
= false;
1965 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1968 if (zlib
+ lzo
+ snappy
> 1) {
1969 error_setg(&err
, "only one of '-z|-l|-s' can be set");
1970 hmp_handle_error(mon
, &err
);
1975 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
1979 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
1983 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
1987 begin
= qdict_get_int(qdict
, "begin");
1990 length
= qdict_get_int(qdict
, "length");
1993 detach
= qdict_get_bool(qdict
, "detach");
1996 prot
= g_strconcat("file:", file
, NULL
);
1998 qmp_dump_guest_memory(paging
, prot
, true, detach
, has_begin
, begin
,
1999 has_length
, length
, true, dump_format
, &err
);
2000 hmp_handle_error(mon
, &err
);
2004 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
2009 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
2014 netdev_add(opts
, &err
);
2016 qemu_opts_del(opts
);
2020 hmp_handle_error(mon
, &err
);
2023 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
2025 const char *id
= qdict_get_str(qdict
, "id");
2028 qmp_netdev_del(id
, &err
);
2029 hmp_handle_error(mon
, &err
);
2032 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
2038 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
2040 hmp_handle_error(mon
, &err
);
2044 obj
= user_creatable_add_opts(opts
, &err
);
2045 qemu_opts_del(opts
);
2048 hmp_handle_error(mon
, &err
);
2055 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
2057 const char *fdname
= qdict_get_str(qdict
, "fdname");
2060 qmp_getfd(fdname
, &err
);
2061 hmp_handle_error(mon
, &err
);
2064 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
2066 const char *fdname
= qdict_get_str(qdict
, "fdname");
2069 qmp_closefd(fdname
, &err
);
2070 hmp_handle_error(mon
, &err
);
2073 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
2075 const char *keys
= qdict_get_str(qdict
, "keys");
2076 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
2077 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
2078 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
2084 separator
= strchr(keys
, '-');
2085 keyname_len
= separator
? separator
- keys
: strlen(keys
);
2087 /* Be compatible with old interface, convert user inputted "<" */
2088 if (keys
[0] == '<' && keyname_len
== 1) {
2093 keylist
= g_malloc0(sizeof(*keylist
));
2094 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
2100 tmp
->next
= keylist
;
2104 if (strstart(keys
, "0x", NULL
)) {
2106 int value
= strtoul(keys
, &endp
, 0);
2107 assert(endp
<= keys
+ keyname_len
);
2108 if (endp
!= keys
+ keyname_len
) {
2111 keylist
->value
->type
= KEY_VALUE_KIND_NUMBER
;
2112 keylist
->value
->u
.number
.data
= value
;
2114 int idx
= index_from_key(keys
, keyname_len
);
2115 if (idx
== Q_KEY_CODE__MAX
) {
2118 keylist
->value
->type
= KEY_VALUE_KIND_QCODE
;
2119 keylist
->value
->u
.qcode
.data
= idx
;
2125 keys
= separator
+ 1;
2128 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
2129 hmp_handle_error(mon
, &err
);
2132 qapi_free_KeyValueList(head
);
2136 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
2140 void hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
2142 const char *filename
= qdict_get_str(qdict
, "filename");
2145 qmp_screendump(filename
, &err
);
2146 hmp_handle_error(mon
, &err
);
2149 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
2151 const char *uri
= qdict_get_str(qdict
, "uri");
2152 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2153 bool all
= qdict_get_try_bool(qdict
, "all", false);
2154 Error
*local_err
= NULL
;
2155 BlockInfoList
*block_list
, *info
;
2156 SocketAddress
*addr
;
2158 if (writable
&& !all
) {
2159 error_setg(&local_err
, "-w only valid together with -a");
2163 /* First check if the address is valid and start the server. */
2164 addr
= socket_parse(uri
, &local_err
);
2165 if (local_err
!= NULL
) {
2169 nbd_server_start(addr
, NULL
, &local_err
);
2170 qapi_free_SocketAddress(addr
);
2171 if (local_err
!= NULL
) {
2179 /* Then try adding all block devices. If one fails, close all and
2182 block_list
= qmp_query_block(NULL
);
2184 for (info
= block_list
; info
; info
= info
->next
) {
2185 if (!info
->value
->has_inserted
) {
2189 qmp_nbd_server_add(info
->value
->device
, false, NULL
,
2190 true, writable
, &local_err
);
2192 if (local_err
!= NULL
) {
2193 qmp_nbd_server_stop(NULL
);
2198 qapi_free_BlockInfoList(block_list
);
2201 hmp_handle_error(mon
, &local_err
);
2204 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
2206 const char *device
= qdict_get_str(qdict
, "device");
2207 const char *name
= qdict_get_try_str(qdict
, "name");
2208 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2209 Error
*local_err
= NULL
;
2211 qmp_nbd_server_add(device
, !!name
, name
, true, writable
, &local_err
);
2212 hmp_handle_error(mon
, &local_err
);
2215 void hmp_nbd_server_remove(Monitor
*mon
, const QDict
*qdict
)
2217 const char *name
= qdict_get_str(qdict
, "name");
2218 bool force
= qdict_get_try_bool(qdict
, "force", false);
2221 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
2222 qmp_nbd_server_remove(name
, force
, NBD_SERVER_REMOVE_MODE_HARD
, &err
);
2223 hmp_handle_error(mon
, &err
);
2226 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
2230 qmp_nbd_server_stop(&err
);
2231 hmp_handle_error(mon
, &err
);
2234 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
2239 cpuid
= qdict_get_int(qdict
, "id");
2240 qmp_cpu_add(cpuid
, &err
);
2241 hmp_handle_error(mon
, &err
);
2244 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
2246 const char *args
= qdict_get_str(qdict
, "args");
2250 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
2252 error_setg(&err
, "Parsing chardev args failed");
2254 qemu_chr_new_from_opts(opts
, &err
);
2255 qemu_opts_del(opts
);
2257 hmp_handle_error(mon
, &err
);
2260 void hmp_chardev_change(Monitor
*mon
, const QDict
*qdict
)
2262 const char *args
= qdict_get_str(qdict
, "args");
2265 ChardevBackend
*backend
= NULL
;
2266 ChardevReturn
*ret
= NULL
;
2267 QemuOpts
*opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
,
2270 error_setg(&err
, "Parsing chardev args failed");
2274 id
= qdict_get_str(qdict
, "id");
2275 if (qemu_opts_id(opts
)) {
2276 error_setg(&err
, "Unexpected 'id' parameter");
2280 backend
= qemu_chr_parse_opts(opts
, &err
);
2285 ret
= qmp_chardev_change(id
, backend
, &err
);
2288 qapi_free_ChardevReturn(ret
);
2289 qapi_free_ChardevBackend(backend
);
2290 qemu_opts_del(opts
);
2291 hmp_handle_error(mon
, &err
);
2294 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
2296 Error
*local_err
= NULL
;
2298 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
2299 hmp_handle_error(mon
, &local_err
);
2302 void hmp_chardev_send_break(Monitor
*mon
, const QDict
*qdict
)
2304 Error
*local_err
= NULL
;
2306 qmp_chardev_send_break(qdict_get_str(qdict
, "id"), &local_err
);
2307 hmp_handle_error(mon
, &local_err
);
2310 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
2313 BlockBackend
*local_blk
= NULL
;
2314 const char* device
= qdict_get_str(qdict
, "device");
2315 const char* command
= qdict_get_str(qdict
, "command");
2319 blk
= blk_by_name(device
);
2321 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, device
, &err
);
2323 blk
= local_blk
= blk_new(0, BLK_PERM_ALL
);
2324 ret
= blk_insert_bs(blk
, bs
, &err
);
2334 * Notably absent: Proper permission management. This is sad, but it seems
2335 * almost impossible to achieve without changing the semantics and thereby
2336 * limiting the use cases of the qemu-io HMP command.
2338 * In an ideal world we would unconditionally create a new BlockBackend for
2339 * qemuio_command(), but we have commands like 'reopen' and want them to
2340 * take effect on the exact BlockBackend whose name the user passed instead
2341 * of just on a temporary copy of it.
2343 * Another problem is that deleting the temporary BlockBackend involves
2344 * draining all requests on it first, but some qemu-iotests cases want to
2345 * issue multiple aio_read/write requests and expect them to complete in
2346 * the background while the monitor has already returned.
2348 * This is also what prevents us from saving the original permissions and
2349 * restoring them later: We can't revoke permissions until all requests
2350 * have completed, and we don't know when that is nor can we really let
2351 * anything else run before we have revoken them to avoid race conditions.
2353 * What happens now is that command() in qemu-io-cmds.c can extend the
2354 * permissions if necessary for the qemu-io command. And they simply stay
2355 * extended, possibly resulting in a read-only guest device keeping write
2356 * permissions. Ugly, but it appears to be the lesser evil.
2358 qemuio_command(blk
, command
);
2361 blk_unref(local_blk
);
2362 hmp_handle_error(mon
, &err
);
2365 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
2367 const char *id
= qdict_get_str(qdict
, "id");
2370 user_creatable_del(id
, &err
);
2371 hmp_handle_error(mon
, &err
);
2374 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
2377 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
2378 MemdevList
*m
= memdev_list
;
2383 v
= string_output_visitor_new(false, &str
);
2384 visit_type_uint16List(v
, NULL
, &m
->value
->host_nodes
, NULL
);
2385 monitor_printf(mon
, "memory backend: %s\n", m
->value
->id
);
2386 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
2387 monitor_printf(mon
, " merge: %s\n",
2388 m
->value
->merge
? "true" : "false");
2389 monitor_printf(mon
, " dump: %s\n",
2390 m
->value
->dump
? "true" : "false");
2391 monitor_printf(mon
, " prealloc: %s\n",
2392 m
->value
->prealloc
? "true" : "false");
2393 monitor_printf(mon
, " policy: %s\n",
2394 HostMemPolicy_str(m
->value
->policy
));
2395 visit_complete(v
, &str
);
2396 monitor_printf(mon
, " host nodes: %s\n", str
);
2403 monitor_printf(mon
, "\n");
2405 qapi_free_MemdevList(memdev_list
);
2406 hmp_handle_error(mon
, &err
);
2409 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
2412 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
2413 MemoryDeviceInfoList
*info
;
2414 MemoryDeviceInfo
*value
;
2415 PCDIMMDeviceInfo
*di
;
2417 for (info
= info_list
; info
; info
= info
->next
) {
2418 value
= info
->value
;
2421 switch (value
->type
) {
2422 case MEMORY_DEVICE_INFO_KIND_DIMM
:
2423 di
= value
->u
.dimm
.data
;
2425 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
2426 MemoryDeviceInfoKind_str(value
->type
),
2427 di
->id
? di
->id
: "");
2428 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
2429 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
2430 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
2431 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
2432 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
2433 monitor_printf(mon
, " hotplugged: %s\n",
2434 di
->hotplugged
? "true" : "false");
2435 monitor_printf(mon
, " hotpluggable: %s\n",
2436 di
->hotpluggable
? "true" : "false");
2444 qapi_free_MemoryDeviceInfoList(info_list
);
2445 hmp_handle_error(mon
, &err
);
2448 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
2450 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
2451 IOThreadInfoList
*info
;
2452 IOThreadInfo
*value
;
2454 for (info
= info_list
; info
; info
= info
->next
) {
2455 value
= info
->value
;
2456 monitor_printf(mon
, "%s:\n", value
->id
);
2457 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
2458 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
2459 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
2460 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
2463 qapi_free_IOThreadInfoList(info_list
);
2466 void hmp_qom_list(Monitor
*mon
, const QDict
*qdict
)
2468 const char *path
= qdict_get_try_str(qdict
, "path");
2469 ObjectPropertyInfoList
*list
;
2473 monitor_printf(mon
, "/\n");
2477 list
= qmp_qom_list(path
, &err
);
2479 ObjectPropertyInfoList
*start
= list
;
2480 while (list
!= NULL
) {
2481 ObjectPropertyInfo
*value
= list
->value
;
2483 monitor_printf(mon
, "%s (%s)\n",
2484 value
->name
, value
->type
);
2487 qapi_free_ObjectPropertyInfoList(start
);
2489 hmp_handle_error(mon
, &err
);
2492 void hmp_qom_set(Monitor
*mon
, const QDict
*qdict
)
2494 const char *path
= qdict_get_str(qdict
, "path");
2495 const char *property
= qdict_get_str(qdict
, "property");
2496 const char *value
= qdict_get_str(qdict
, "value");
2498 bool ambiguous
= false;
2501 obj
= object_resolve_path(path
, &ambiguous
);
2503 error_set(&err
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2504 "Device '%s' not found", path
);
2507 monitor_printf(mon
, "Warning: Path '%s' is ambiguous\n", path
);
2509 object_property_parse(obj
, value
, property
, &err
);
2511 hmp_handle_error(mon
, &err
);
2514 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
2516 const char *name
= qdict_get_str(qdict
, "name");
2517 RockerSwitch
*rocker
;
2520 rocker
= qmp_query_rocker(name
, &err
);
2522 hmp_handle_error(mon
, &err
);
2526 monitor_printf(mon
, "name: %s\n", rocker
->name
);
2527 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
2528 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
2530 qapi_free_RockerSwitch(rocker
);
2533 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
2535 RockerPortList
*list
, *port
;
2536 const char *name
= qdict_get_str(qdict
, "name");
2539 list
= qmp_query_rocker_ports(name
, &err
);
2541 hmp_handle_error(mon
, &err
);
2545 monitor_printf(mon
, " ena/ speed/ auto\n");
2546 monitor_printf(mon
, " port link duplex neg?\n");
2548 for (port
= list
; port
; port
= port
->next
) {
2549 monitor_printf(mon
, "%10s %-4s %-3s %2s %-3s\n",
2551 port
->value
->enabled
? port
->value
->link_up
?
2552 "up" : "down" : "!ena",
2553 port
->value
->speed
== 10000 ? "10G" : "??",
2554 port
->value
->duplex
? "FD" : "HD",
2555 port
->value
->autoneg
? "Yes" : "No");
2558 qapi_free_RockerPortList(list
);
2561 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
2563 RockerOfDpaFlowList
*list
, *info
;
2564 const char *name
= qdict_get_str(qdict
, "name");
2565 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
2568 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
2570 hmp_handle_error(mon
, &err
);
2574 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
2576 for (info
= list
; info
; info
= info
->next
) {
2577 RockerOfDpaFlow
*flow
= info
->value
;
2578 RockerOfDpaFlowKey
*key
= flow
->key
;
2579 RockerOfDpaFlowMask
*mask
= flow
->mask
;
2580 RockerOfDpaFlowAction
*action
= flow
->action
;
2583 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
2584 key
->priority
, key
->tbl_id
, flow
->hits
);
2586 monitor_printf(mon
, "%-4d %-3d ",
2587 key
->priority
, key
->tbl_id
);
2590 if (key
->has_in_pport
) {
2591 monitor_printf(mon
, " pport %d", key
->in_pport
);
2592 if (mask
->has_in_pport
) {
2593 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2597 if (key
->has_vlan_id
) {
2598 monitor_printf(mon
, " vlan %d",
2599 key
->vlan_id
& VLAN_VID_MASK
);
2600 if (mask
->has_vlan_id
) {
2601 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2605 if (key
->has_tunnel_id
) {
2606 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2607 if (mask
->has_tunnel_id
) {
2608 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2612 if (key
->has_eth_type
) {
2613 switch (key
->eth_type
) {
2615 monitor_printf(mon
, " ARP");
2618 monitor_printf(mon
, " IP");
2621 monitor_printf(mon
, " IPv6");
2624 monitor_printf(mon
, " LACP");
2627 monitor_printf(mon
, " LLDP");
2630 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2635 if (key
->has_eth_src
) {
2636 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2637 (mask
->has_eth_src
) &&
2638 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2639 monitor_printf(mon
, " src <any mcast/bcast>");
2640 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2641 (mask
->has_eth_src
) &&
2642 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2643 monitor_printf(mon
, " src <any ucast>");
2645 monitor_printf(mon
, " src %s", key
->eth_src
);
2646 if (mask
->has_eth_src
) {
2647 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2652 if (key
->has_eth_dst
) {
2653 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2654 (mask
->has_eth_dst
) &&
2655 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2656 monitor_printf(mon
, " dst <any mcast/bcast>");
2657 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2658 (mask
->has_eth_dst
) &&
2659 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2660 monitor_printf(mon
, " dst <any ucast>");
2662 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2663 if (mask
->has_eth_dst
) {
2664 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2669 if (key
->has_ip_proto
) {
2670 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2671 if (mask
->has_ip_proto
) {
2672 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2676 if (key
->has_ip_tos
) {
2677 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2678 if (mask
->has_ip_tos
) {
2679 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2683 if (key
->has_ip_dst
) {
2684 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2687 if (action
->has_goto_tbl
|| action
->has_group_id
||
2688 action
->has_new_vlan_id
) {
2689 monitor_printf(mon
, " -->");
2692 if (action
->has_new_vlan_id
) {
2693 monitor_printf(mon
, " apply new vlan %d",
2694 ntohs(action
->new_vlan_id
));
2697 if (action
->has_group_id
) {
2698 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2701 if (action
->has_goto_tbl
) {
2702 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2705 monitor_printf(mon
, "\n");
2708 qapi_free_RockerOfDpaFlowList(list
);
2711 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2713 RockerOfDpaGroupList
*list
, *g
;
2714 const char *name
= qdict_get_str(qdict
, "name");
2715 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2719 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
2721 hmp_handle_error(mon
, &err
);
2725 monitor_printf(mon
, "id (decode) --> buckets\n");
2727 for (g
= list
; g
; g
= g
->next
) {
2728 RockerOfDpaGroup
*group
= g
->value
;
2730 monitor_printf(mon
, "0x%08x", group
->id
);
2732 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2733 group
->type
== 1 ? "L2 rewrite" :
2734 group
->type
== 2 ? "L3 unicast" :
2735 group
->type
== 3 ? "L2 multicast" :
2736 group
->type
== 4 ? "L2 flood" :
2737 group
->type
== 5 ? "L3 interface" :
2738 group
->type
== 6 ? "L3 multicast" :
2739 group
->type
== 7 ? "L3 ECMP" :
2740 group
->type
== 8 ? "L2 overlay" :
2743 if (group
->has_vlan_id
) {
2744 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2747 if (group
->has_pport
) {
2748 monitor_printf(mon
, " pport %d", group
->pport
);
2751 if (group
->has_index
) {
2752 monitor_printf(mon
, " index %d", group
->index
);
2755 monitor_printf(mon
, ") -->");
2757 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2759 monitor_printf(mon
, " set vlan %d",
2760 group
->set_vlan_id
& VLAN_VID_MASK
);
2763 if (group
->has_set_eth_src
) {
2766 monitor_printf(mon
, " set");
2768 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2771 if (group
->has_set_eth_dst
) {
2774 monitor_printf(mon
, " set");
2776 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2781 if (group
->has_ttl_check
&& group
->ttl_check
) {
2782 monitor_printf(mon
, " check TTL");
2785 if (group
->has_group_id
&& group
->group_id
) {
2786 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2789 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2790 monitor_printf(mon
, " pop vlan");
2793 if (group
->has_out_pport
) {
2794 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2797 if (group
->has_group_ids
) {
2798 struct uint32List
*id
;
2800 monitor_printf(mon
, " groups [");
2801 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2802 monitor_printf(mon
, "0x%08x", id
->value
);
2804 monitor_printf(mon
, ",");
2807 monitor_printf(mon
, "]");
2810 monitor_printf(mon
, "\n");
2813 qapi_free_RockerOfDpaGroupList(list
);
2816 void hmp_info_dump(Monitor
*mon
, const QDict
*qdict
)
2818 DumpQueryResult
*result
= qmp_query_dump(NULL
);
2820 assert(result
&& result
->status
< DUMP_STATUS__MAX
);
2821 monitor_printf(mon
, "Status: %s\n", DumpStatus_str(result
->status
));
2823 if (result
->status
== DUMP_STATUS_ACTIVE
) {
2825 assert(result
->total
!= 0);
2826 percent
= 100.0 * result
->completed
/ result
->total
;
2827 monitor_printf(mon
, "Finished: %.2f %%\n", percent
);
2830 qapi_free_DumpQueryResult(result
);
2833 void hmp_info_ramblock(Monitor
*mon
, const QDict
*qdict
)
2835 ram_block_dump(mon
);
2838 void hmp_hotpluggable_cpus(Monitor
*mon
, const QDict
*qdict
)
2841 HotpluggableCPUList
*l
= qmp_query_hotpluggable_cpus(&err
);
2842 HotpluggableCPUList
*saved
= l
;
2843 CpuInstanceProperties
*c
;
2846 hmp_handle_error(mon
, &err
);
2850 monitor_printf(mon
, "Hotpluggable CPUs:\n");
2852 monitor_printf(mon
, " type: \"%s\"\n", l
->value
->type
);
2853 monitor_printf(mon
, " vcpus_count: \"%" PRIu64
"\"\n",
2854 l
->value
->vcpus_count
);
2855 if (l
->value
->has_qom_path
) {
2856 monitor_printf(mon
, " qom_path: \"%s\"\n", l
->value
->qom_path
);
2859 c
= l
->value
->props
;
2860 monitor_printf(mon
, " CPUInstance Properties:\n");
2861 if (c
->has_node_id
) {
2862 monitor_printf(mon
, " node-id: \"%" PRIu64
"\"\n", c
->node_id
);
2864 if (c
->has_socket_id
) {
2865 monitor_printf(mon
, " socket-id: \"%" PRIu64
"\"\n", c
->socket_id
);
2867 if (c
->has_core_id
) {
2868 monitor_printf(mon
, " core-id: \"%" PRIu64
"\"\n", c
->core_id
);
2870 if (c
->has_thread_id
) {
2871 monitor_printf(mon
, " thread-id: \"%" PRIu64
"\"\n", c
->thread_id
);
2877 qapi_free_HotpluggableCPUList(saved
);
2880 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
2883 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
2885 monitor_printf(mon
, "%s\n", info
->guid
);
2887 hmp_handle_error(mon
, &err
);
2888 qapi_free_GuidInfo(info
);
2891 void hmp_info_memory_size_summary(Monitor
*mon
, const QDict
*qdict
)
2894 MemoryInfo
*info
= qmp_query_memory_size_summary(&err
);
2896 monitor_printf(mon
, "base memory: %" PRIu64
"\n",
2899 if (info
->has_plugged_memory
) {
2900 monitor_printf(mon
, "plugged memory: %" PRIu64
"\n",
2901 info
->plugged_memory
);
2904 qapi_free_MemoryInfo(info
);
2906 hmp_handle_error(mon
, &err
);