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/error.h"
31 #include "qapi/opts-visitor.h"
32 #include "qapi/qmp/qdict.h"
33 #include "qapi/qmp/qerror.h"
34 #include "qapi/string-input-visitor.h"
35 #include "qapi/string-output-visitor.h"
36 #include "qapi-visit.h"
37 #include "qom/object_interfaces.h"
38 #include "ui/console.h"
39 #include "block/nbd.h"
40 #include "block/qapi.h"
42 #include "qemu/cutils.h"
43 #include "qemu/error-report.h"
44 #include "exec/ramlist.h"
45 #include "hw/intc/intc.h"
46 #include "migration/snapshot.h"
47 #include "migration/misc.h"
50 #include <spice/enums.h>
53 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
57 error_report_err(*errp
);
61 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
65 info
= qmp_query_name(NULL
);
67 monitor_printf(mon
, "%s\n", info
->name
);
69 qapi_free_NameInfo(info
);
72 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
76 info
= qmp_query_version(NULL
);
78 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
79 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
82 qapi_free_VersionInfo(info
);
85 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
89 info
= qmp_query_kvm(NULL
);
90 monitor_printf(mon
, "kvm support: ");
92 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
94 monitor_printf(mon
, "not compiled\n");
97 qapi_free_KvmInfo(info
);
100 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
104 info
= qmp_query_status(NULL
);
106 monitor_printf(mon
, "VM status: %s%s",
107 info
->running
? "running" : "paused",
108 info
->singlestep
? " (single step mode)" : "");
110 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
111 monitor_printf(mon
, " (%s)", RunState_str(info
->status
));
114 monitor_printf(mon
, "\n");
116 qapi_free_StatusInfo(info
);
119 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
123 info
= qmp_query_uuid(NULL
);
124 monitor_printf(mon
, "%s\n", info
->UUID
);
125 qapi_free_UuidInfo(info
);
128 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
130 ChardevInfoList
*char_info
, *info
;
132 char_info
= qmp_query_chardev(NULL
);
133 for (info
= char_info
; info
; info
= info
->next
) {
134 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
135 info
->value
->filename
);
138 qapi_free_ChardevInfoList(char_info
);
141 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
143 MouseInfoList
*mice_list
, *mouse
;
145 mice_list
= qmp_query_mice(NULL
);
147 monitor_printf(mon
, "No mouse devices connected\n");
151 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
152 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
153 mouse
->value
->current
? '*' : ' ',
154 mouse
->value
->index
, mouse
->value
->name
,
155 mouse
->value
->absolute
? " (absolute)" : "");
158 qapi_free_MouseInfoList(mice_list
);
161 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
164 MigrationCapabilityStatusList
*caps
, *cap
;
166 info
= qmp_query_migrate(NULL
);
167 caps
= qmp_query_migrate_capabilities(NULL
);
169 migration_global_dump(mon
);
171 /* do not display parameters during setup */
172 if (info
->has_status
&& caps
) {
173 monitor_printf(mon
, "capabilities: ");
174 for (cap
= caps
; cap
; cap
= cap
->next
) {
175 monitor_printf(mon
, "%s: %s ",
176 MigrationCapability_str(cap
->value
->capability
),
177 cap
->value
->state
? "on" : "off");
179 monitor_printf(mon
, "\n");
182 if (info
->has_status
) {
183 monitor_printf(mon
, "Migration status: %s",
184 MigrationStatus_str(info
->status
));
185 if (info
->status
== MIGRATION_STATUS_FAILED
&&
186 info
->has_error_desc
) {
187 monitor_printf(mon
, " (%s)\n", info
->error_desc
);
189 monitor_printf(mon
, "\n");
192 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
194 if (info
->has_expected_downtime
) {
195 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
196 info
->expected_downtime
);
198 if (info
->has_downtime
) {
199 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
202 if (info
->has_setup_time
) {
203 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
209 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
210 info
->ram
->transferred
>> 10);
211 monitor_printf(mon
, "throughput: %0.2f mbps\n",
213 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
214 info
->ram
->remaining
>> 10);
215 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
216 info
->ram
->total
>> 10);
217 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
218 info
->ram
->duplicate
);
219 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
221 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
223 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
224 info
->ram
->normal_bytes
>> 10);
225 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
226 info
->ram
->dirty_sync_count
);
227 monitor_printf(mon
, "page size: %" PRIu64
" kbytes\n",
228 info
->ram
->page_size
>> 10);
230 if (info
->ram
->dirty_pages_rate
) {
231 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
232 info
->ram
->dirty_pages_rate
);
234 if (info
->ram
->postcopy_requests
) {
235 monitor_printf(mon
, "postcopy request count: %" PRIu64
"\n",
236 info
->ram
->postcopy_requests
);
240 if (info
->has_disk
) {
241 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
242 info
->disk
->transferred
>> 10);
243 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
244 info
->disk
->remaining
>> 10);
245 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
246 info
->disk
->total
>> 10);
249 if (info
->has_xbzrle_cache
) {
250 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
251 info
->xbzrle_cache
->cache_size
);
252 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
253 info
->xbzrle_cache
->bytes
>> 10);
254 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
255 info
->xbzrle_cache
->pages
);
256 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
257 info
->xbzrle_cache
->cache_miss
);
258 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
259 info
->xbzrle_cache
->cache_miss_rate
);
260 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
261 info
->xbzrle_cache
->overflow
);
264 if (info
->has_cpu_throttle_percentage
) {
265 monitor_printf(mon
, "cpu throttle percentage: %" PRIu64
"\n",
266 info
->cpu_throttle_percentage
);
269 qapi_free_MigrationInfo(info
);
270 qapi_free_MigrationCapabilityStatusList(caps
);
273 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
275 MigrationCapabilityStatusList
*caps
, *cap
;
277 caps
= qmp_query_migrate_capabilities(NULL
);
280 for (cap
= caps
; cap
; cap
= cap
->next
) {
281 monitor_printf(mon
, "%s: %s\n",
282 MigrationCapability_str(cap
->value
->capability
),
283 cap
->value
->state
? "on" : "off");
287 qapi_free_MigrationCapabilityStatusList(caps
);
290 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
292 MigrationParameters
*params
;
294 params
= qmp_query_migrate_parameters(NULL
);
297 assert(params
->has_compress_level
);
298 monitor_printf(mon
, "%s: %u\n",
299 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL
),
300 params
->compress_level
);
301 assert(params
->has_compress_threads
);
302 monitor_printf(mon
, "%s: %u\n",
303 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS
),
304 params
->compress_threads
);
305 assert(params
->has_decompress_threads
);
306 monitor_printf(mon
, "%s: %u\n",
307 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS
),
308 params
->decompress_threads
);
309 assert(params
->has_cpu_throttle_initial
);
310 monitor_printf(mon
, "%s: %u\n",
311 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
),
312 params
->cpu_throttle_initial
);
313 assert(params
->has_cpu_throttle_increment
);
314 monitor_printf(mon
, "%s: %u\n",
315 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
),
316 params
->cpu_throttle_increment
);
317 assert(params
->has_tls_creds
);
318 monitor_printf(mon
, "%s: '%s'\n",
319 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS
),
321 assert(params
->has_tls_hostname
);
322 monitor_printf(mon
, "%s: '%s'\n",
323 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME
),
324 params
->tls_hostname
);
325 assert(params
->has_max_bandwidth
);
326 monitor_printf(mon
, "%s: %" PRIu64
" bytes/second\n",
327 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH
),
328 params
->max_bandwidth
);
329 assert(params
->has_downtime_limit
);
330 monitor_printf(mon
, "%s: %" PRIu64
" milliseconds\n",
331 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT
),
332 params
->downtime_limit
);
333 assert(params
->has_x_checkpoint_delay
);
334 monitor_printf(mon
, "%s: %u\n",
335 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
),
336 params
->x_checkpoint_delay
);
337 assert(params
->has_block_incremental
);
338 monitor_printf(mon
, "%s: %s\n",
339 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL
),
340 params
->block_incremental
? "on" : "off");
341 monitor_printf(mon
, "%s: %u\n",
342 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_CHANNELS
),
343 params
->x_multifd_channels
);
344 monitor_printf(mon
, "%s: %u\n",
345 MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT
),
346 params
->x_multifd_page_count
);
347 monitor_printf(mon
, "%s: %" PRIu64
"\n",
348 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
),
349 params
->xbzrle_cache_size
);
352 qapi_free_MigrationParameters(params
);
355 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
357 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
358 qmp_query_migrate_cache_size(NULL
) >> 10);
361 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
363 CpuInfoFastList
*cpu_list
, *cpu
;
365 cpu_list
= qmp_query_cpus_fast(NULL
);
367 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
370 if (cpu
->value
->cpu_index
== monitor_get_cpu_index()) {
374 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
,
375 cpu
->value
->cpu_index
);
376 monitor_printf(mon
, " thread-id=%" PRId64
"\n", cpu
->value
->thread_id
);
379 qapi_free_CpuInfoFastList(cpu_list
);
382 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
383 BlockDeviceInfo
*inserted
, bool verbose
)
385 ImageInfo
*image_info
;
387 assert(!info
|| !info
->has_inserted
|| info
->inserted
== inserted
);
389 if (info
&& *info
->device
) {
390 monitor_printf(mon
, "%s", info
->device
);
391 if (inserted
&& inserted
->has_node_name
) {
392 monitor_printf(mon
, " (%s)", inserted
->node_name
);
395 assert(info
|| inserted
);
396 monitor_printf(mon
, "%s",
397 inserted
&& inserted
->has_node_name
? inserted
->node_name
398 : info
&& info
->has_qdev
? info
->qdev
403 monitor_printf(mon
, ": %s (%s%s%s)\n",
406 inserted
->ro
? ", read-only" : "",
407 inserted
->encrypted
? ", encrypted" : "");
409 monitor_printf(mon
, ": [not inserted]\n");
413 if (info
->has_qdev
) {
414 monitor_printf(mon
, " Attached to: %s\n", info
->qdev
);
416 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
417 monitor_printf(mon
, " I/O status: %s\n",
418 BlockDeviceIoStatus_str(info
->io_status
));
421 if (info
->removable
) {
422 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
423 info
->locked
? "" : "not ",
424 info
->tray_open
? "open" : "closed");
433 monitor_printf(mon
, " Cache mode: %s%s%s\n",
434 inserted
->cache
->writeback
? "writeback" : "writethrough",
435 inserted
->cache
->direct
? ", direct" : "",
436 inserted
->cache
->no_flush
? ", ignore flushes" : "");
438 if (inserted
->has_backing_file
) {
441 "(chain depth: %" PRId64
")\n",
442 inserted
->backing_file
,
443 inserted
->backing_file_depth
);
446 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
447 monitor_printf(mon
, " Detect zeroes: %s\n",
448 BlockdevDetectZeroesOptions_str(inserted
->detect_zeroes
));
451 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
452 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
454 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
455 " bps_rd=%" PRId64
" bps_wr=%" PRId64
457 " bps_rd_max=%" PRId64
458 " bps_wr_max=%" PRId64
459 " iops=%" PRId64
" iops_rd=%" PRId64
462 " iops_rd_max=%" PRId64
463 " iops_wr_max=%" PRId64
464 " iops_size=%" PRId64
470 inserted
->bps_rd_max
,
471 inserted
->bps_wr_max
,
476 inserted
->iops_rd_max
,
477 inserted
->iops_wr_max
,
483 monitor_printf(mon
, "\nImages:\n");
484 image_info
= inserted
->image
;
486 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
488 if (image_info
->has_backing_image
) {
489 image_info
= image_info
->backing_image
;
497 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
499 BlockInfoList
*block_list
, *info
;
500 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
501 const char *device
= qdict_get_try_str(qdict
, "device");
502 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
503 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
504 bool printed
= false;
506 /* Print BlockBackend information */
508 block_list
= qmp_query_block(NULL
);
513 for (info
= block_list
; info
; info
= info
->next
) {
514 if (device
&& strcmp(device
, info
->value
->device
)) {
518 if (info
!= block_list
) {
519 monitor_printf(mon
, "\n");
522 print_block_info(mon
, info
->value
, info
->value
->has_inserted
523 ? info
->value
->inserted
: NULL
,
528 qapi_free_BlockInfoList(block_list
);
530 if ((!device
&& !nodes
) || printed
) {
534 /* Print node information */
535 blockdev_list
= qmp_query_named_block_nodes(NULL
);
536 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
537 assert(blockdev
->value
->has_node_name
);
538 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
542 if (blockdev
!= blockdev_list
) {
543 monitor_printf(mon
, "\n");
546 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
548 qapi_free_BlockDeviceInfoList(blockdev_list
);
551 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
553 BlockStatsList
*stats_list
, *stats
;
555 stats_list
= qmp_query_blockstats(false, false, NULL
);
557 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
558 if (!stats
->value
->has_device
) {
562 monitor_printf(mon
, "%s:", stats
->value
->device
);
563 monitor_printf(mon
, " rd_bytes=%" PRId64
565 " rd_operations=%" PRId64
566 " wr_operations=%" PRId64
567 " flush_operations=%" PRId64
568 " wr_total_time_ns=%" PRId64
569 " rd_total_time_ns=%" PRId64
570 " flush_total_time_ns=%" PRId64
571 " rd_merged=%" PRId64
572 " wr_merged=%" PRId64
573 " idle_time_ns=%" PRId64
575 stats
->value
->stats
->rd_bytes
,
576 stats
->value
->stats
->wr_bytes
,
577 stats
->value
->stats
->rd_operations
,
578 stats
->value
->stats
->wr_operations
,
579 stats
->value
->stats
->flush_operations
,
580 stats
->value
->stats
->wr_total_time_ns
,
581 stats
->value
->stats
->rd_total_time_ns
,
582 stats
->value
->stats
->flush_total_time_ns
,
583 stats
->value
->stats
->rd_merged
,
584 stats
->value
->stats
->wr_merged
,
585 stats
->value
->stats
->idle_time_ns
);
588 qapi_free_BlockStatsList(stats_list
);
591 /* Helper for hmp_info_vnc_clients, _servers */
592 static void hmp_info_VncBasicInfo(Monitor
*mon
, VncBasicInfo
*info
,
595 monitor_printf(mon
, " %s: %s:%s (%s%s)\n",
599 NetworkAddressFamily_str(info
->family
),
600 info
->websocket
? " (Websocket)" : "");
603 /* Helper displaying and auth and crypt info */
604 static void hmp_info_vnc_authcrypt(Monitor
*mon
, const char *indent
,
606 VncVencryptSubAuth
*vencrypt
)
608 monitor_printf(mon
, "%sAuth: %s (Sub: %s)\n", indent
,
609 VncPrimaryAuth_str(auth
),
610 vencrypt
? VncVencryptSubAuth_str(*vencrypt
) : "none");
613 static void hmp_info_vnc_clients(Monitor
*mon
, VncClientInfoList
*client
)
616 VncClientInfo
*cinfo
= client
->value
;
618 hmp_info_VncBasicInfo(mon
, qapi_VncClientInfo_base(cinfo
), "Client");
619 monitor_printf(mon
, " x509_dname: %s\n",
620 cinfo
->has_x509_dname
?
621 cinfo
->x509_dname
: "none");
622 monitor_printf(mon
, " sasl_username: %s\n",
623 cinfo
->has_sasl_username
?
624 cinfo
->sasl_username
: "none");
626 client
= client
->next
;
630 static void hmp_info_vnc_servers(Monitor
*mon
, VncServerInfo2List
*server
)
633 VncServerInfo2
*sinfo
= server
->value
;
634 hmp_info_VncBasicInfo(mon
, qapi_VncServerInfo2_base(sinfo
), "Server");
635 hmp_info_vnc_authcrypt(mon
, " ", sinfo
->auth
,
636 sinfo
->has_vencrypt
? &sinfo
->vencrypt
: NULL
);
637 server
= server
->next
;
641 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
643 VncInfo2List
*info2l
;
646 info2l
= qmp_query_vnc_servers(&err
);
648 hmp_handle_error(mon
, &err
);
652 monitor_printf(mon
, "None\n");
657 VncInfo2
*info
= info2l
->value
;
658 monitor_printf(mon
, "%s:\n", info
->id
);
659 hmp_info_vnc_servers(mon
, info
->server
);
660 hmp_info_vnc_clients(mon
, info
->clients
);
662 /* The server entry displays its auth, we only
663 * need to display in the case of 'reverse' connections
664 * where there's no server.
666 hmp_info_vnc_authcrypt(mon
, " ", info
->auth
,
667 info
->has_vencrypt
? &info
->vencrypt
: NULL
);
669 if (info
->has_display
) {
670 monitor_printf(mon
, " Display: %s\n", info
->display
);
672 info2l
= info2l
->next
;
675 qapi_free_VncInfo2List(info2l
);
680 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
682 SpiceChannelList
*chan
;
684 const char *channel_name
;
685 const char * const channel_names
[] = {
686 [SPICE_CHANNEL_MAIN
] = "main",
687 [SPICE_CHANNEL_DISPLAY
] = "display",
688 [SPICE_CHANNEL_INPUTS
] = "inputs",
689 [SPICE_CHANNEL_CURSOR
] = "cursor",
690 [SPICE_CHANNEL_PLAYBACK
] = "playback",
691 [SPICE_CHANNEL_RECORD
] = "record",
692 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
693 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
694 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
695 [SPICE_CHANNEL_PORT
] = "port",
697 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
698 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
699 * as quick fix for build failures with older versions. */
700 [SPICE_CHANNEL_WEBDAV
] = "webdav",
704 info
= qmp_query_spice(NULL
);
706 if (!info
->enabled
) {
707 monitor_printf(mon
, "Server: disabled\n");
711 monitor_printf(mon
, "Server:\n");
712 if (info
->has_port
) {
713 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
714 info
->host
, info
->port
);
716 if (info
->has_tls_port
) {
717 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
718 info
->host
, info
->tls_port
);
720 monitor_printf(mon
, " migrated: %s\n",
721 info
->migrated
? "true" : "false");
722 monitor_printf(mon
, " auth: %s\n", info
->auth
);
723 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
724 monitor_printf(mon
, " mouse-mode: %s\n",
725 SpiceQueryMouseMode_str(info
->mouse_mode
));
727 if (!info
->has_channels
|| info
->channels
== NULL
) {
728 monitor_printf(mon
, "Channels: none\n");
730 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
731 monitor_printf(mon
, "Channel:\n");
732 monitor_printf(mon
, " address: %s:%s%s\n",
733 chan
->value
->host
, chan
->value
->port
,
734 chan
->value
->tls
? " [tls]" : "");
735 monitor_printf(mon
, " session: %" PRId64
"\n",
736 chan
->value
->connection_id
);
737 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
738 chan
->value
->channel_type
, chan
->value
->channel_id
);
740 channel_name
= "unknown";
741 if (chan
->value
->channel_type
> 0 &&
742 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
743 channel_names
[chan
->value
->channel_type
]) {
744 channel_name
= channel_names
[chan
->value
->channel_type
];
747 monitor_printf(mon
, " channel name: %s\n", channel_name
);
752 qapi_free_SpiceInfo(info
);
756 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
761 info
= qmp_query_balloon(&err
);
763 hmp_handle_error(mon
, &err
);
767 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
769 qapi_free_BalloonInfo(info
);
772 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
774 PciMemoryRegionList
*region
;
776 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
777 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
778 dev
->slot
, dev
->function
);
779 monitor_printf(mon
, " ");
781 if (dev
->class_info
->has_desc
) {
782 monitor_printf(mon
, "%s", dev
->class_info
->desc
);
784 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
787 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
788 dev
->id
->vendor
, dev
->id
->device
);
791 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
794 if (dev
->has_pci_bridge
) {
795 monitor_printf(mon
, " BUS %" PRId64
".\n",
796 dev
->pci_bridge
->bus
->number
);
797 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
798 dev
->pci_bridge
->bus
->secondary
);
799 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
800 dev
->pci_bridge
->bus
->subordinate
);
802 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
803 dev
->pci_bridge
->bus
->io_range
->base
,
804 dev
->pci_bridge
->bus
->io_range
->limit
);
807 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
808 dev
->pci_bridge
->bus
->memory_range
->base
,
809 dev
->pci_bridge
->bus
->memory_range
->limit
);
811 monitor_printf(mon
, " prefetchable memory range "
812 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
813 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
814 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
817 for (region
= dev
->regions
; region
; region
= region
->next
) {
820 addr
= region
->value
->address
;
821 size
= region
->value
->size
;
823 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
825 if (!strcmp(region
->value
->type
, "io")) {
826 monitor_printf(mon
, "I/O at 0x%04" PRIx64
827 " [0x%04" PRIx64
"].\n",
828 addr
, addr
+ size
- 1);
830 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
831 " [0x%08" PRIx64
"].\n",
832 region
->value
->mem_type_64
? 64 : 32,
833 region
->value
->prefetch
? " prefetchable" : "",
834 addr
, addr
+ size
- 1);
838 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
840 if (dev
->has_pci_bridge
) {
841 if (dev
->pci_bridge
->has_devices
) {
842 PciDeviceInfoList
*cdev
;
843 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
844 hmp_info_pci_device(mon
, cdev
->value
);
850 static int hmp_info_irq_foreach(Object
*obj
, void *opaque
)
852 InterruptStatsProvider
*intc
;
853 InterruptStatsProviderClass
*k
;
854 Monitor
*mon
= opaque
;
856 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
857 intc
= INTERRUPT_STATS_PROVIDER(obj
);
858 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
859 uint64_t *irq_counts
;
860 unsigned int nb_irqs
, i
;
861 if (k
->get_statistics
&&
862 k
->get_statistics(intc
, &irq_counts
, &nb_irqs
)) {
864 monitor_printf(mon
, "IRQ statistics for %s:\n",
865 object_get_typename(obj
));
866 for (i
= 0; i
< nb_irqs
; i
++) {
867 if (irq_counts
[i
] > 0) {
868 monitor_printf(mon
, "%2d: %" PRId64
"\n", i
,
874 monitor_printf(mon
, "IRQ statistics not available for %s.\n",
875 object_get_typename(obj
));
882 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
)
884 object_child_foreach_recursive(object_get_root(),
885 hmp_info_irq_foreach
, mon
);
888 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
890 InterruptStatsProvider
*intc
;
891 InterruptStatsProviderClass
*k
;
892 Monitor
*mon
= opaque
;
894 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
895 intc
= INTERRUPT_STATS_PROVIDER(obj
);
896 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
898 k
->print_info(intc
, mon
);
900 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
901 object_get_typename(obj
));
908 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
910 object_child_foreach_recursive(object_get_root(),
911 hmp_info_pic_foreach
, mon
);
914 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
916 PciInfoList
*info_list
, *info
;
919 info_list
= qmp_query_pci(&err
);
921 monitor_printf(mon
, "PCI devices not supported\n");
926 for (info
= info_list
; info
; info
= info
->next
) {
927 PciDeviceInfoList
*dev
;
929 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
930 hmp_info_pci_device(mon
, dev
->value
);
934 qapi_free_PciInfoList(info_list
);
937 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
939 BlockJobInfoList
*list
;
942 list
= qmp_query_block_jobs(&err
);
946 monitor_printf(mon
, "No active jobs\n");
951 if (strcmp(list
->value
->type
, "stream") == 0) {
952 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
953 " of %" PRId64
" bytes, speed limit %" PRId64
960 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
961 " of %" PRId64
" bytes, speed limit %" PRId64
972 qapi_free_BlockJobInfoList(list
);
975 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
977 TPMInfoList
*info_list
, *info
;
980 TPMPassthroughOptions
*tpo
;
981 TPMEmulatorOptions
*teo
;
983 info_list
= qmp_query_tpm(&err
);
985 monitor_printf(mon
, "TPM device not supported\n");
991 monitor_printf(mon
, "TPM device:\n");
994 for (info
= info_list
; info
; info
= info
->next
) {
995 TPMInfo
*ti
= info
->value
;
996 monitor_printf(mon
, " tpm%d: model=%s\n",
997 c
, TpmModel_str(ti
->model
));
999 monitor_printf(mon
, " \\ %s: type=%s",
1000 ti
->id
, TpmTypeOptionsKind_str(ti
->options
->type
));
1002 switch (ti
->options
->type
) {
1003 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
1004 tpo
= ti
->options
->u
.passthrough
.data
;
1005 monitor_printf(mon
, "%s%s%s%s",
1006 tpo
->has_path
? ",path=" : "",
1007 tpo
->has_path
? tpo
->path
: "",
1008 tpo
->has_cancel_path
? ",cancel-path=" : "",
1009 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
1011 case TPM_TYPE_OPTIONS_KIND_EMULATOR
:
1012 teo
= ti
->options
->u
.emulator
.data
;
1013 monitor_printf(mon
, ",chardev=%s", teo
->chardev
);
1015 case TPM_TYPE_OPTIONS_KIND__MAX
:
1018 monitor_printf(mon
, "\n");
1021 qapi_free_TPMInfoList(info_list
);
1024 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
1026 monitor_suspend(mon
);
1030 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
1035 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
1037 qmp_system_reset(NULL
);
1040 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
1042 qmp_system_powerdown(NULL
);
1045 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
1049 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1050 use it are converted to the QAPI */
1051 cpu_index
= qdict_get_int(qdict
, "index");
1052 if (monitor_set_cpu(cpu_index
) < 0) {
1053 monitor_printf(mon
, "invalid CPU index\n");
1057 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
1059 uint32_t size
= qdict_get_int(qdict
, "size");
1060 const char *filename
= qdict_get_str(qdict
, "filename");
1061 uint64_t addr
= qdict_get_int(qdict
, "val");
1063 int cpu_index
= monitor_get_cpu_index();
1065 if (cpu_index
< 0) {
1066 monitor_printf(mon
, "No CPU available\n");
1070 qmp_memsave(addr
, size
, filename
, true, cpu_index
, &err
);
1071 hmp_handle_error(mon
, &err
);
1074 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
1076 uint32_t size
= qdict_get_int(qdict
, "size");
1077 const char *filename
= qdict_get_str(qdict
, "filename");
1078 uint64_t addr
= qdict_get_int(qdict
, "val");
1081 qmp_pmemsave(addr
, size
, filename
, &err
);
1082 hmp_handle_error(mon
, &err
);
1085 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
1087 const char *chardev
= qdict_get_str(qdict
, "device");
1088 const char *data
= qdict_get_str(qdict
, "data");
1091 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
1093 hmp_handle_error(mon
, &err
);
1096 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
1098 uint32_t size
= qdict_get_int(qdict
, "size");
1099 const char *chardev
= qdict_get_str(qdict
, "device");
1104 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
1106 hmp_handle_error(mon
, &err
);
1110 for (i
= 0; data
[i
]; i
++) {
1111 unsigned char ch
= data
[i
];
1114 monitor_printf(mon
, "\\\\");
1115 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
1116 monitor_printf(mon
, "\\u%04X", ch
);
1118 monitor_printf(mon
, "%c", ch
);
1122 monitor_printf(mon
, "\n");
1126 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
1131 hmp_handle_error(mon
, &err
);
1134 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
1136 qmp_system_wakeup(NULL
);
1139 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
1143 qmp_inject_nmi(&err
);
1144 hmp_handle_error(mon
, &err
);
1147 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
1149 const char *name
= qdict_get_str(qdict
, "name");
1150 bool up
= qdict_get_bool(qdict
, "up");
1153 qmp_set_link(name
, up
, &err
);
1154 hmp_handle_error(mon
, &err
);
1157 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
1159 const char *device
= qdict_get_str(qdict
, "device");
1160 const char *password
= qdict_get_str(qdict
, "password");
1163 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
1164 hmp_handle_error(mon
, &err
);
1167 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1169 int64_t value
= qdict_get_int(qdict
, "value");
1172 qmp_balloon(value
, &err
);
1173 hmp_handle_error(mon
, &err
);
1176 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
1178 const char *device
= qdict_get_str(qdict
, "device");
1179 int64_t size
= qdict_get_int(qdict
, "size");
1182 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
1183 hmp_handle_error(mon
, &err
);
1186 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
1188 const char *filename
= qdict_get_str(qdict
, "target");
1189 const char *format
= qdict_get_try_str(qdict
, "format");
1190 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1191 bool full
= qdict_get_try_bool(qdict
, "full", false);
1193 DriveMirror mirror
= {
1194 .device
= (char *)qdict_get_str(qdict
, "device"),
1195 .target
= (char *)filename
,
1196 .has_format
= !!format
,
1197 .format
= (char *)format
,
1198 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1200 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1205 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1206 hmp_handle_error(mon
, &err
);
1209 qmp_drive_mirror(&mirror
, &err
);
1210 hmp_handle_error(mon
, &err
);
1213 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
1215 const char *device
= qdict_get_str(qdict
, "device");
1216 const char *filename
= qdict_get_str(qdict
, "target");
1217 const char *format
= qdict_get_try_str(qdict
, "format");
1218 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1219 bool full
= qdict_get_try_bool(qdict
, "full", false);
1220 bool compress
= qdict_get_try_bool(qdict
, "compress", false);
1222 DriveBackup backup
= {
1223 .device
= (char *)device
,
1224 .target
= (char *)filename
,
1225 .has_format
= !!format
,
1226 .format
= (char *)format
,
1227 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1229 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1230 .has_compress
= !!compress
,
1231 .compress
= compress
,
1235 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1236 hmp_handle_error(mon
, &err
);
1240 qmp_drive_backup(&backup
, &err
);
1241 hmp_handle_error(mon
, &err
);
1244 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
1246 const char *device
= qdict_get_str(qdict
, "device");
1247 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
1248 const char *format
= qdict_get_try_str(qdict
, "format");
1249 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1250 enum NewImageMode mode
;
1254 /* In the future, if 'snapshot-file' is not specified, the snapshot
1255 will be taken internally. Today it's actually required. */
1256 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
1257 hmp_handle_error(mon
, &err
);
1261 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1262 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
1263 filename
, false, NULL
,
1266 hmp_handle_error(mon
, &err
);
1269 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1271 const char *device
= qdict_get_str(qdict
, "device");
1272 const char *name
= qdict_get_str(qdict
, "name");
1275 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1276 hmp_handle_error(mon
, &err
);
1279 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1281 const char *device
= qdict_get_str(qdict
, "device");
1282 const char *name
= qdict_get_str(qdict
, "name");
1283 const char *id
= qdict_get_try_str(qdict
, "id");
1286 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1288 hmp_handle_error(mon
, &err
);
1291 void hmp_loadvm(Monitor
*mon
, const QDict
*qdict
)
1293 int saved_vm_running
= runstate_is_running();
1294 const char *name
= qdict_get_str(qdict
, "name");
1297 vm_stop(RUN_STATE_RESTORE_VM
);
1299 if (load_snapshot(name
, &err
) == 0 && saved_vm_running
) {
1302 hmp_handle_error(mon
, &err
);
1305 void hmp_savevm(Monitor
*mon
, const QDict
*qdict
)
1309 save_snapshot(qdict_get_try_str(qdict
, "name"), &err
);
1310 hmp_handle_error(mon
, &err
);
1313 void hmp_delvm(Monitor
*mon
, const QDict
*qdict
)
1315 BlockDriverState
*bs
;
1317 const char *name
= qdict_get_str(qdict
, "name");
1319 if (bdrv_all_delete_snapshot(name
, &bs
, &err
) < 0) {
1320 error_reportf_err(err
,
1321 "Error while deleting snapshot on device '%s': ",
1322 bdrv_get_device_name(bs
));
1326 void hmp_info_snapshots(Monitor
*mon
, const QDict
*qdict
)
1328 BlockDriverState
*bs
, *bs1
;
1329 BdrvNextIterator it1
;
1330 QEMUSnapshotInfo
*sn_tab
, *sn
;
1331 bool no_snapshot
= true;
1334 int *global_snapshots
;
1335 AioContext
*aio_context
;
1337 typedef struct SnapshotEntry
{
1338 QEMUSnapshotInfo sn
;
1339 QTAILQ_ENTRY(SnapshotEntry
) next
;
1342 typedef struct ImageEntry
{
1343 const char *imagename
;
1344 QTAILQ_ENTRY(ImageEntry
) next
;
1345 QTAILQ_HEAD(, SnapshotEntry
) snapshots
;
1348 QTAILQ_HEAD(, ImageEntry
) image_list
=
1349 QTAILQ_HEAD_INITIALIZER(image_list
);
1351 ImageEntry
*image_entry
, *next_ie
;
1352 SnapshotEntry
*snapshot_entry
;
1354 bs
= bdrv_all_find_vmstate_bs();
1356 monitor_printf(mon
, "No available block device supports snapshots\n");
1359 aio_context
= bdrv_get_aio_context(bs
);
1361 aio_context_acquire(aio_context
);
1362 nb_sns
= bdrv_snapshot_list(bs
, &sn_tab
);
1363 aio_context_release(aio_context
);
1366 monitor_printf(mon
, "bdrv_snapshot_list: error %d\n", nb_sns
);
1370 for (bs1
= bdrv_first(&it1
); bs1
; bs1
= bdrv_next(&it1
)) {
1374 AioContext
*ctx
= bdrv_get_aio_context(bs1
);
1376 aio_context_acquire(ctx
);
1377 if (bdrv_can_snapshot(bs1
)) {
1379 bs1_nb_sns
= bdrv_snapshot_list(bs1
, &sn
);
1380 if (bs1_nb_sns
> 0) {
1381 no_snapshot
= false;
1382 ie
= g_new0(ImageEntry
, 1);
1383 ie
->imagename
= bdrv_get_device_name(bs1
);
1384 QTAILQ_INIT(&ie
->snapshots
);
1385 QTAILQ_INSERT_TAIL(&image_list
, ie
, next
);
1386 for (i
= 0; i
< bs1_nb_sns
; i
++) {
1387 se
= g_new0(SnapshotEntry
, 1);
1389 QTAILQ_INSERT_TAIL(&ie
->snapshots
, se
, next
);
1394 aio_context_release(ctx
);
1398 monitor_printf(mon
, "There is no snapshot available.\n");
1402 global_snapshots
= g_new0(int, nb_sns
);
1404 for (i
= 0; i
< nb_sns
; i
++) {
1405 SnapshotEntry
*next_sn
;
1406 if (bdrv_all_find_snapshot(sn_tab
[i
].name
, &bs1
) == 0) {
1407 global_snapshots
[total
] = i
;
1409 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1410 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
,
1412 if (!strcmp(sn_tab
[i
].name
, snapshot_entry
->sn
.name
)) {
1413 QTAILQ_REMOVE(&image_entry
->snapshots
, snapshot_entry
,
1415 g_free(snapshot_entry
);
1422 monitor_printf(mon
, "List of snapshots present on all disks:\n");
1425 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1426 monitor_printf(mon
, "\n");
1427 for (i
= 0; i
< total
; i
++) {
1428 sn
= &sn_tab
[global_snapshots
[i
]];
1429 /* The ID is not guaranteed to be the same on all images, so
1432 pstrcpy(sn
->id_str
, sizeof(sn
->id_str
), "--");
1433 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, sn
);
1434 monitor_printf(mon
, "\n");
1437 monitor_printf(mon
, "None\n");
1440 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1441 if (QTAILQ_EMPTY(&image_entry
->snapshots
)) {
1445 "\nList of partial (non-loadable) snapshots on '%s':\n",
1446 image_entry
->imagename
);
1447 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1448 monitor_printf(mon
, "\n");
1449 QTAILQ_FOREACH(snapshot_entry
, &image_entry
->snapshots
, next
) {
1450 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
,
1451 &snapshot_entry
->sn
);
1452 monitor_printf(mon
, "\n");
1456 QTAILQ_FOREACH_SAFE(image_entry
, &image_list
, next
, next_ie
) {
1457 SnapshotEntry
*next_sn
;
1458 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
, next
,
1460 g_free(snapshot_entry
);
1462 g_free(image_entry
);
1465 g_free(global_snapshots
);
1469 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1471 qmp_migrate_cancel(NULL
);
1474 void hmp_migrate_continue(Monitor
*mon
, const QDict
*qdict
)
1477 const char *state
= qdict_get_str(qdict
, "state");
1478 int val
= qapi_enum_parse(&MigrationStatus_lookup
, state
, -1, &err
);
1481 qmp_migrate_continue(val
, &err
);
1484 hmp_handle_error(mon
, &err
);
1487 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1490 const char *uri
= qdict_get_str(qdict
, "uri");
1492 qmp_migrate_incoming(uri
, &err
);
1494 hmp_handle_error(mon
, &err
);
1497 /* Kept for backwards compatibility */
1498 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1500 double value
= qdict_get_double(qdict
, "value");
1501 qmp_migrate_set_downtime(value
, NULL
);
1504 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1506 int64_t value
= qdict_get_int(qdict
, "value");
1509 qmp_migrate_set_cache_size(value
, &err
);
1510 hmp_handle_error(mon
, &err
);
1513 /* Kept for backwards compatibility */
1514 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1516 int64_t value
= qdict_get_int(qdict
, "value");
1517 qmp_migrate_set_speed(value
, NULL
);
1520 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1522 const char *cap
= qdict_get_str(qdict
, "capability");
1523 bool state
= qdict_get_bool(qdict
, "state");
1525 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1528 val
= qapi_enum_parse(&MigrationCapability_lookup
, cap
, -1, &err
);
1533 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1534 caps
->value
->capability
= val
;
1535 caps
->value
->state
= state
;
1537 qmp_migrate_set_capabilities(caps
, &err
);
1540 qapi_free_MigrationCapabilityStatusList(caps
);
1541 hmp_handle_error(mon
, &err
);
1544 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1546 const char *param
= qdict_get_str(qdict
, "parameter");
1547 const char *valuestr
= qdict_get_str(qdict
, "value");
1548 Visitor
*v
= string_input_visitor_new(valuestr
);
1549 MigrateSetParameters
*p
= g_new0(MigrateSetParameters
, 1);
1550 uint64_t valuebw
= 0;
1551 uint64_t cache_size
;
1555 val
= qapi_enum_parse(&MigrationParameter_lookup
, param
, -1, &err
);
1561 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1562 p
->has_compress_level
= true;
1563 visit_type_int(v
, param
, &p
->compress_level
, &err
);
1565 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1566 p
->has_compress_threads
= true;
1567 visit_type_int(v
, param
, &p
->compress_threads
, &err
);
1569 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1570 p
->has_decompress_threads
= true;
1571 visit_type_int(v
, param
, &p
->decompress_threads
, &err
);
1573 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1574 p
->has_cpu_throttle_initial
= true;
1575 visit_type_int(v
, param
, &p
->cpu_throttle_initial
, &err
);
1577 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1578 p
->has_cpu_throttle_increment
= true;
1579 visit_type_int(v
, param
, &p
->cpu_throttle_increment
, &err
);
1581 case MIGRATION_PARAMETER_TLS_CREDS
:
1582 p
->has_tls_creds
= true;
1583 p
->tls_creds
= g_new0(StrOrNull
, 1);
1584 p
->tls_creds
->type
= QTYPE_QSTRING
;
1585 visit_type_str(v
, param
, &p
->tls_creds
->u
.s
, &err
);
1587 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1588 p
->has_tls_hostname
= true;
1589 p
->tls_hostname
= g_new0(StrOrNull
, 1);
1590 p
->tls_hostname
->type
= QTYPE_QSTRING
;
1591 visit_type_str(v
, param
, &p
->tls_hostname
->u
.s
, &err
);
1593 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1594 p
->has_max_bandwidth
= true;
1596 * Can't use visit_type_size() here, because it
1597 * defaults to Bytes rather than Mebibytes.
1599 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
1600 if (ret
< 0 || valuebw
> INT64_MAX
1601 || (size_t)valuebw
!= valuebw
) {
1602 error_setg(&err
, "Invalid size %s", valuestr
);
1605 p
->max_bandwidth
= valuebw
;
1607 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1608 p
->has_downtime_limit
= true;
1609 visit_type_int(v
, param
, &p
->downtime_limit
, &err
);
1611 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
1612 p
->has_x_checkpoint_delay
= true;
1613 visit_type_int(v
, param
, &p
->x_checkpoint_delay
, &err
);
1615 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL
:
1616 p
->has_block_incremental
= true;
1617 visit_type_bool(v
, param
, &p
->block_incremental
, &err
);
1619 case MIGRATION_PARAMETER_X_MULTIFD_CHANNELS
:
1620 p
->has_x_multifd_channels
= true;
1621 visit_type_int(v
, param
, &p
->x_multifd_channels
, &err
);
1623 case MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT
:
1624 p
->has_x_multifd_page_count
= true;
1625 visit_type_int(v
, param
, &p
->x_multifd_page_count
, &err
);
1627 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
:
1628 p
->has_xbzrle_cache_size
= true;
1629 visit_type_size(v
, param
, &cache_size
, &err
);
1630 if (err
|| cache_size
> INT64_MAX
1631 || (size_t)cache_size
!= cache_size
) {
1632 error_setg(&err
, "Invalid size %s", valuestr
);
1635 p
->xbzrle_cache_size
= cache_size
;
1645 qmp_migrate_set_parameters(p
, &err
);
1648 qapi_free_MigrateSetParameters(p
);
1650 hmp_handle_error(mon
, &err
);
1653 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1656 const char *protocol
= qdict_get_str(qdict
, "protocol");
1657 const char *hostname
= qdict_get_str(qdict
, "hostname");
1658 bool has_port
= qdict_haskey(qdict
, "port");
1659 int port
= qdict_get_try_int(qdict
, "port", -1);
1660 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1661 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1662 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1664 qmp_client_migrate_info(protocol
, hostname
,
1665 has_port
, port
, has_tls_port
, tls_port
,
1666 !!cert_subject
, cert_subject
, &err
);
1667 hmp_handle_error(mon
, &err
);
1670 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1673 qmp_migrate_start_postcopy(&err
);
1674 hmp_handle_error(mon
, &err
);
1677 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1681 qmp_x_colo_lost_heartbeat(&err
);
1682 hmp_handle_error(mon
, &err
);
1685 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1687 const char *protocol
= qdict_get_str(qdict
, "protocol");
1688 const char *password
= qdict_get_str(qdict
, "password");
1689 const char *connected
= qdict_get_try_str(qdict
, "connected");
1692 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1693 hmp_handle_error(mon
, &err
);
1696 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1698 const char *protocol
= qdict_get_str(qdict
, "protocol");
1699 const char *whenstr
= qdict_get_str(qdict
, "time");
1702 qmp_expire_password(protocol
, whenstr
, &err
);
1703 hmp_handle_error(mon
, &err
);
1706 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1708 bool force
= qdict_get_try_bool(qdict
, "force", false);
1709 const char *device
= qdict_get_str(qdict
, "device");
1712 qmp_eject(true, device
, false, NULL
, true, force
, &err
);
1713 hmp_handle_error(mon
, &err
);
1716 static void hmp_change_read_arg(void *opaque
, const char *password
,
1717 void *readline_opaque
)
1719 qmp_change_vnc_password(password
, NULL
);
1720 monitor_read_command(opaque
, 1);
1723 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1725 const char *device
= qdict_get_str(qdict
, "device");
1726 const char *target
= qdict_get_str(qdict
, "target");
1727 const char *arg
= qdict_get_try_str(qdict
, "arg");
1728 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1729 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1732 if (strcmp(device
, "vnc") == 0) {
1735 "Parameter 'read-only-mode' is invalid for VNC\n");
1738 if (strcmp(target
, "passwd") == 0 ||
1739 strcmp(target
, "password") == 0) {
1741 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1745 qmp_change("vnc", target
, !!arg
, arg
, &err
);
1749 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup
,
1751 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1753 hmp_handle_error(mon
, &err
);
1758 qmp_blockdev_change_medium(true, device
, false, NULL
, target
,
1759 !!arg
, arg
, !!read_only
, read_only_mode
,
1763 hmp_handle_error(mon
, &err
);
1766 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1769 BlockIOThrottle throttle
= {
1771 .device
= (char *) qdict_get_str(qdict
, "device"),
1772 .bps
= qdict_get_int(qdict
, "bps"),
1773 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
1774 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
1775 .iops
= qdict_get_int(qdict
, "iops"),
1776 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
1777 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
1780 qmp_block_set_io_throttle(&throttle
, &err
);
1781 hmp_handle_error(mon
, &err
);
1784 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1786 Error
*error
= NULL
;
1787 const char *device
= qdict_get_str(qdict
, "device");
1788 const char *base
= qdict_get_try_str(qdict
, "base");
1789 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1791 qmp_block_stream(true, device
, device
, base
!= NULL
, base
, false, NULL
,
1792 false, NULL
, qdict_haskey(qdict
, "speed"), speed
,
1793 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1795 hmp_handle_error(mon
, &error
);
1798 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1800 Error
*error
= NULL
;
1801 const char *device
= qdict_get_str(qdict
, "device");
1802 int64_t value
= qdict_get_int(qdict
, "speed");
1804 qmp_block_job_set_speed(device
, value
, &error
);
1806 hmp_handle_error(mon
, &error
);
1809 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1811 Error
*error
= NULL
;
1812 const char *device
= qdict_get_str(qdict
, "device");
1813 bool force
= qdict_get_try_bool(qdict
, "force", false);
1815 qmp_block_job_cancel(device
, true, force
, &error
);
1817 hmp_handle_error(mon
, &error
);
1820 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1822 Error
*error
= NULL
;
1823 const char *device
= qdict_get_str(qdict
, "device");
1825 qmp_block_job_pause(device
, &error
);
1827 hmp_handle_error(mon
, &error
);
1830 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1832 Error
*error
= NULL
;
1833 const char *device
= qdict_get_str(qdict
, "device");
1835 qmp_block_job_resume(device
, &error
);
1837 hmp_handle_error(mon
, &error
);
1840 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1842 Error
*error
= NULL
;
1843 const char *device
= qdict_get_str(qdict
, "device");
1845 qmp_block_job_complete(device
, &error
);
1847 hmp_handle_error(mon
, &error
);
1850 typedef struct HMPMigrationStatus
1854 bool is_block_migration
;
1855 } HMPMigrationStatus
;
1857 static void hmp_migrate_status_cb(void *opaque
)
1859 HMPMigrationStatus
*status
= opaque
;
1860 MigrationInfo
*info
;
1862 info
= qmp_query_migrate(NULL
);
1863 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1864 info
->status
== MIGRATION_STATUS_SETUP
) {
1865 if (info
->has_disk
) {
1868 if (info
->disk
->remaining
) {
1869 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1874 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1875 monitor_flush(status
->mon
);
1878 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1880 if (status
->is_block_migration
) {
1881 monitor_printf(status
->mon
, "\n");
1883 if (info
->has_error_desc
) {
1884 error_report("%s", info
->error_desc
);
1886 monitor_resume(status
->mon
);
1887 timer_del(status
->timer
);
1891 qapi_free_MigrationInfo(info
);
1894 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1896 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1897 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1898 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1899 const char *uri
= qdict_get_str(qdict
, "uri");
1902 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1904 hmp_handle_error(mon
, &err
);
1909 HMPMigrationStatus
*status
;
1911 if (monitor_suspend(mon
) < 0) {
1912 monitor_printf(mon
, "terminal does not allow synchronous "
1913 "migration, continuing detached\n");
1917 status
= g_malloc0(sizeof(*status
));
1919 status
->is_block_migration
= blk
|| inc
;
1920 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1922 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1926 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
1930 qmp_device_add((QDict
*)qdict
, NULL
, &err
);
1931 hmp_handle_error(mon
, &err
);
1934 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1936 const char *id
= qdict_get_str(qdict
, "id");
1939 qmp_device_del(id
, &err
);
1940 hmp_handle_error(mon
, &err
);
1943 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1946 bool paging
= qdict_get_try_bool(qdict
, "paging", false);
1947 bool zlib
= qdict_get_try_bool(qdict
, "zlib", false);
1948 bool lzo
= qdict_get_try_bool(qdict
, "lzo", false);
1949 bool snappy
= qdict_get_try_bool(qdict
, "snappy", false);
1950 const char *file
= qdict_get_str(qdict
, "filename");
1951 bool has_begin
= qdict_haskey(qdict
, "begin");
1952 bool has_length
= qdict_haskey(qdict
, "length");
1953 bool has_detach
= qdict_haskey(qdict
, "detach");
1956 bool detach
= false;
1957 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1960 if (zlib
+ lzo
+ snappy
> 1) {
1961 error_setg(&err
, "only one of '-z|-l|-s' can be set");
1962 hmp_handle_error(mon
, &err
);
1967 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
1971 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
1975 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
1979 begin
= qdict_get_int(qdict
, "begin");
1982 length
= qdict_get_int(qdict
, "length");
1985 detach
= qdict_get_bool(qdict
, "detach");
1988 prot
= g_strconcat("file:", file
, NULL
);
1990 qmp_dump_guest_memory(paging
, prot
, true, detach
, has_begin
, begin
,
1991 has_length
, length
, true, dump_format
, &err
);
1992 hmp_handle_error(mon
, &err
);
1996 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
2001 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
2006 netdev_add(opts
, &err
);
2008 qemu_opts_del(opts
);
2012 hmp_handle_error(mon
, &err
);
2015 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
2017 const char *id
= qdict_get_str(qdict
, "id");
2020 qmp_netdev_del(id
, &err
);
2021 hmp_handle_error(mon
, &err
);
2024 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
2030 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
2032 hmp_handle_error(mon
, &err
);
2036 obj
= user_creatable_add_opts(opts
, &err
);
2037 qemu_opts_del(opts
);
2040 hmp_handle_error(mon
, &err
);
2047 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
2049 const char *fdname
= qdict_get_str(qdict
, "fdname");
2052 qmp_getfd(fdname
, &err
);
2053 hmp_handle_error(mon
, &err
);
2056 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
2058 const char *fdname
= qdict_get_str(qdict
, "fdname");
2061 qmp_closefd(fdname
, &err
);
2062 hmp_handle_error(mon
, &err
);
2065 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
2067 const char *keys
= qdict_get_str(qdict
, "keys");
2068 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
2069 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
2070 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
2076 separator
= strchr(keys
, '-');
2077 keyname_len
= separator
? separator
- keys
: strlen(keys
);
2079 /* Be compatible with old interface, convert user inputted "<" */
2080 if (keys
[0] == '<' && keyname_len
== 1) {
2085 keylist
= g_malloc0(sizeof(*keylist
));
2086 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
2092 tmp
->next
= keylist
;
2096 if (strstart(keys
, "0x", NULL
)) {
2098 int value
= strtoul(keys
, &endp
, 0);
2099 assert(endp
<= keys
+ keyname_len
);
2100 if (endp
!= keys
+ keyname_len
) {
2103 keylist
->value
->type
= KEY_VALUE_KIND_NUMBER
;
2104 keylist
->value
->u
.number
.data
= value
;
2106 int idx
= index_from_key(keys
, keyname_len
);
2107 if (idx
== Q_KEY_CODE__MAX
) {
2110 keylist
->value
->type
= KEY_VALUE_KIND_QCODE
;
2111 keylist
->value
->u
.qcode
.data
= idx
;
2117 keys
= separator
+ 1;
2120 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
2121 hmp_handle_error(mon
, &err
);
2124 qapi_free_KeyValueList(head
);
2128 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
2132 void hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
2134 const char *filename
= qdict_get_str(qdict
, "filename");
2137 qmp_screendump(filename
, &err
);
2138 hmp_handle_error(mon
, &err
);
2141 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
2143 const char *uri
= qdict_get_str(qdict
, "uri");
2144 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2145 bool all
= qdict_get_try_bool(qdict
, "all", false);
2146 Error
*local_err
= NULL
;
2147 BlockInfoList
*block_list
, *info
;
2148 SocketAddress
*addr
;
2150 if (writable
&& !all
) {
2151 error_setg(&local_err
, "-w only valid together with -a");
2155 /* First check if the address is valid and start the server. */
2156 addr
= socket_parse(uri
, &local_err
);
2157 if (local_err
!= NULL
) {
2161 nbd_server_start(addr
, NULL
, &local_err
);
2162 qapi_free_SocketAddress(addr
);
2163 if (local_err
!= NULL
) {
2171 /* Then try adding all block devices. If one fails, close all and
2174 block_list
= qmp_query_block(NULL
);
2176 for (info
= block_list
; info
; info
= info
->next
) {
2177 if (!info
->value
->has_inserted
) {
2181 qmp_nbd_server_add(info
->value
->device
, false, NULL
,
2182 true, writable
, &local_err
);
2184 if (local_err
!= NULL
) {
2185 qmp_nbd_server_stop(NULL
);
2190 qapi_free_BlockInfoList(block_list
);
2193 hmp_handle_error(mon
, &local_err
);
2196 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
2198 const char *device
= qdict_get_str(qdict
, "device");
2199 const char *name
= qdict_get_try_str(qdict
, "name");
2200 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2201 Error
*local_err
= NULL
;
2203 qmp_nbd_server_add(device
, !!name
, name
, true, writable
, &local_err
);
2204 hmp_handle_error(mon
, &local_err
);
2207 void hmp_nbd_server_remove(Monitor
*mon
, const QDict
*qdict
)
2209 const char *name
= qdict_get_str(qdict
, "name");
2210 bool force
= qdict_get_try_bool(qdict
, "force", false);
2213 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
2214 qmp_nbd_server_remove(name
, force
, NBD_SERVER_REMOVE_MODE_HARD
, &err
);
2215 hmp_handle_error(mon
, &err
);
2218 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
2222 qmp_nbd_server_stop(&err
);
2223 hmp_handle_error(mon
, &err
);
2226 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
2231 cpuid
= qdict_get_int(qdict
, "id");
2232 qmp_cpu_add(cpuid
, &err
);
2233 hmp_handle_error(mon
, &err
);
2236 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
2238 const char *args
= qdict_get_str(qdict
, "args");
2242 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
2244 error_setg(&err
, "Parsing chardev args failed");
2246 qemu_chr_new_from_opts(opts
, &err
);
2247 qemu_opts_del(opts
);
2249 hmp_handle_error(mon
, &err
);
2252 void hmp_chardev_change(Monitor
*mon
, const QDict
*qdict
)
2254 const char *args
= qdict_get_str(qdict
, "args");
2257 ChardevBackend
*backend
= NULL
;
2258 ChardevReturn
*ret
= NULL
;
2259 QemuOpts
*opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
,
2262 error_setg(&err
, "Parsing chardev args failed");
2266 id
= qdict_get_str(qdict
, "id");
2267 if (qemu_opts_id(opts
)) {
2268 error_setg(&err
, "Unexpected 'id' parameter");
2272 backend
= qemu_chr_parse_opts(opts
, &err
);
2277 ret
= qmp_chardev_change(id
, backend
, &err
);
2280 qapi_free_ChardevReturn(ret
);
2281 qapi_free_ChardevBackend(backend
);
2282 qemu_opts_del(opts
);
2283 hmp_handle_error(mon
, &err
);
2286 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
2288 Error
*local_err
= NULL
;
2290 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
2291 hmp_handle_error(mon
, &local_err
);
2294 void hmp_chardev_send_break(Monitor
*mon
, const QDict
*qdict
)
2296 Error
*local_err
= NULL
;
2298 qmp_chardev_send_break(qdict_get_str(qdict
, "id"), &local_err
);
2299 hmp_handle_error(mon
, &local_err
);
2302 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
2305 BlockBackend
*local_blk
= NULL
;
2306 const char* device
= qdict_get_str(qdict
, "device");
2307 const char* command
= qdict_get_str(qdict
, "command");
2311 blk
= blk_by_name(device
);
2313 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, device
, &err
);
2315 blk
= local_blk
= blk_new(0, BLK_PERM_ALL
);
2316 ret
= blk_insert_bs(blk
, bs
, &err
);
2326 * Notably absent: Proper permission management. This is sad, but it seems
2327 * almost impossible to achieve without changing the semantics and thereby
2328 * limiting the use cases of the qemu-io HMP command.
2330 * In an ideal world we would unconditionally create a new BlockBackend for
2331 * qemuio_command(), but we have commands like 'reopen' and want them to
2332 * take effect on the exact BlockBackend whose name the user passed instead
2333 * of just on a temporary copy of it.
2335 * Another problem is that deleting the temporary BlockBackend involves
2336 * draining all requests on it first, but some qemu-iotests cases want to
2337 * issue multiple aio_read/write requests and expect them to complete in
2338 * the background while the monitor has already returned.
2340 * This is also what prevents us from saving the original permissions and
2341 * restoring them later: We can't revoke permissions until all requests
2342 * have completed, and we don't know when that is nor can we really let
2343 * anything else run before we have revoken them to avoid race conditions.
2345 * What happens now is that command() in qemu-io-cmds.c can extend the
2346 * permissions if necessary for the qemu-io command. And they simply stay
2347 * extended, possibly resulting in a read-only guest device keeping write
2348 * permissions. Ugly, but it appears to be the lesser evil.
2350 qemuio_command(blk
, command
);
2353 blk_unref(local_blk
);
2354 hmp_handle_error(mon
, &err
);
2357 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
2359 const char *id
= qdict_get_str(qdict
, "id");
2362 user_creatable_del(id
, &err
);
2363 hmp_handle_error(mon
, &err
);
2366 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
2369 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
2370 MemdevList
*m
= memdev_list
;
2375 v
= string_output_visitor_new(false, &str
);
2376 visit_type_uint16List(v
, NULL
, &m
->value
->host_nodes
, NULL
);
2377 monitor_printf(mon
, "memory backend: %s\n", m
->value
->id
);
2378 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
2379 monitor_printf(mon
, " merge: %s\n",
2380 m
->value
->merge
? "true" : "false");
2381 monitor_printf(mon
, " dump: %s\n",
2382 m
->value
->dump
? "true" : "false");
2383 monitor_printf(mon
, " prealloc: %s\n",
2384 m
->value
->prealloc
? "true" : "false");
2385 monitor_printf(mon
, " policy: %s\n",
2386 HostMemPolicy_str(m
->value
->policy
));
2387 visit_complete(v
, &str
);
2388 monitor_printf(mon
, " host nodes: %s\n", str
);
2395 monitor_printf(mon
, "\n");
2397 qapi_free_MemdevList(memdev_list
);
2398 hmp_handle_error(mon
, &err
);
2401 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
2404 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
2405 MemoryDeviceInfoList
*info
;
2406 MemoryDeviceInfo
*value
;
2407 PCDIMMDeviceInfo
*di
;
2409 for (info
= info_list
; info
; info
= info
->next
) {
2410 value
= info
->value
;
2413 switch (value
->type
) {
2414 case MEMORY_DEVICE_INFO_KIND_DIMM
:
2415 di
= value
->u
.dimm
.data
;
2417 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
2418 MemoryDeviceInfoKind_str(value
->type
),
2419 di
->id
? di
->id
: "");
2420 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
2421 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
2422 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
2423 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
2424 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
2425 monitor_printf(mon
, " hotplugged: %s\n",
2426 di
->hotplugged
? "true" : "false");
2427 monitor_printf(mon
, " hotpluggable: %s\n",
2428 di
->hotpluggable
? "true" : "false");
2436 qapi_free_MemoryDeviceInfoList(info_list
);
2437 hmp_handle_error(mon
, &err
);
2440 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
2442 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
2443 IOThreadInfoList
*info
;
2444 IOThreadInfo
*value
;
2446 for (info
= info_list
; info
; info
= info
->next
) {
2447 value
= info
->value
;
2448 monitor_printf(mon
, "%s:\n", value
->id
);
2449 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
2450 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
2451 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
2452 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
2455 qapi_free_IOThreadInfoList(info_list
);
2458 void hmp_qom_list(Monitor
*mon
, const QDict
*qdict
)
2460 const char *path
= qdict_get_try_str(qdict
, "path");
2461 ObjectPropertyInfoList
*list
;
2465 monitor_printf(mon
, "/\n");
2469 list
= qmp_qom_list(path
, &err
);
2471 ObjectPropertyInfoList
*start
= list
;
2472 while (list
!= NULL
) {
2473 ObjectPropertyInfo
*value
= list
->value
;
2475 monitor_printf(mon
, "%s (%s)\n",
2476 value
->name
, value
->type
);
2479 qapi_free_ObjectPropertyInfoList(start
);
2481 hmp_handle_error(mon
, &err
);
2484 void hmp_qom_set(Monitor
*mon
, const QDict
*qdict
)
2486 const char *path
= qdict_get_str(qdict
, "path");
2487 const char *property
= qdict_get_str(qdict
, "property");
2488 const char *value
= qdict_get_str(qdict
, "value");
2490 bool ambiguous
= false;
2493 obj
= object_resolve_path(path
, &ambiguous
);
2495 error_set(&err
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2496 "Device '%s' not found", path
);
2499 monitor_printf(mon
, "Warning: Path '%s' is ambiguous\n", path
);
2501 object_property_parse(obj
, value
, property
, &err
);
2503 hmp_handle_error(mon
, &err
);
2506 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
2508 const char *name
= qdict_get_str(qdict
, "name");
2509 RockerSwitch
*rocker
;
2512 rocker
= qmp_query_rocker(name
, &err
);
2514 hmp_handle_error(mon
, &err
);
2518 monitor_printf(mon
, "name: %s\n", rocker
->name
);
2519 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
2520 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
2522 qapi_free_RockerSwitch(rocker
);
2525 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
2527 RockerPortList
*list
, *port
;
2528 const char *name
= qdict_get_str(qdict
, "name");
2531 list
= qmp_query_rocker_ports(name
, &err
);
2533 hmp_handle_error(mon
, &err
);
2537 monitor_printf(mon
, " ena/ speed/ auto\n");
2538 monitor_printf(mon
, " port link duplex neg?\n");
2540 for (port
= list
; port
; port
= port
->next
) {
2541 monitor_printf(mon
, "%10s %-4s %-3s %2s %-3s\n",
2543 port
->value
->enabled
? port
->value
->link_up
?
2544 "up" : "down" : "!ena",
2545 port
->value
->speed
== 10000 ? "10G" : "??",
2546 port
->value
->duplex
? "FD" : "HD",
2547 port
->value
->autoneg
? "Yes" : "No");
2550 qapi_free_RockerPortList(list
);
2553 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
2555 RockerOfDpaFlowList
*list
, *info
;
2556 const char *name
= qdict_get_str(qdict
, "name");
2557 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
2560 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
2562 hmp_handle_error(mon
, &err
);
2566 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
2568 for (info
= list
; info
; info
= info
->next
) {
2569 RockerOfDpaFlow
*flow
= info
->value
;
2570 RockerOfDpaFlowKey
*key
= flow
->key
;
2571 RockerOfDpaFlowMask
*mask
= flow
->mask
;
2572 RockerOfDpaFlowAction
*action
= flow
->action
;
2575 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
2576 key
->priority
, key
->tbl_id
, flow
->hits
);
2578 monitor_printf(mon
, "%-4d %-3d ",
2579 key
->priority
, key
->tbl_id
);
2582 if (key
->has_in_pport
) {
2583 monitor_printf(mon
, " pport %d", key
->in_pport
);
2584 if (mask
->has_in_pport
) {
2585 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2589 if (key
->has_vlan_id
) {
2590 monitor_printf(mon
, " vlan %d",
2591 key
->vlan_id
& VLAN_VID_MASK
);
2592 if (mask
->has_vlan_id
) {
2593 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2597 if (key
->has_tunnel_id
) {
2598 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2599 if (mask
->has_tunnel_id
) {
2600 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2604 if (key
->has_eth_type
) {
2605 switch (key
->eth_type
) {
2607 monitor_printf(mon
, " ARP");
2610 monitor_printf(mon
, " IP");
2613 monitor_printf(mon
, " IPv6");
2616 monitor_printf(mon
, " LACP");
2619 monitor_printf(mon
, " LLDP");
2622 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2627 if (key
->has_eth_src
) {
2628 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2629 (mask
->has_eth_src
) &&
2630 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2631 monitor_printf(mon
, " src <any mcast/bcast>");
2632 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2633 (mask
->has_eth_src
) &&
2634 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2635 monitor_printf(mon
, " src <any ucast>");
2637 monitor_printf(mon
, " src %s", key
->eth_src
);
2638 if (mask
->has_eth_src
) {
2639 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2644 if (key
->has_eth_dst
) {
2645 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2646 (mask
->has_eth_dst
) &&
2647 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2648 monitor_printf(mon
, " dst <any mcast/bcast>");
2649 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2650 (mask
->has_eth_dst
) &&
2651 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2652 monitor_printf(mon
, " dst <any ucast>");
2654 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2655 if (mask
->has_eth_dst
) {
2656 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2661 if (key
->has_ip_proto
) {
2662 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2663 if (mask
->has_ip_proto
) {
2664 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2668 if (key
->has_ip_tos
) {
2669 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2670 if (mask
->has_ip_tos
) {
2671 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2675 if (key
->has_ip_dst
) {
2676 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2679 if (action
->has_goto_tbl
|| action
->has_group_id
||
2680 action
->has_new_vlan_id
) {
2681 monitor_printf(mon
, " -->");
2684 if (action
->has_new_vlan_id
) {
2685 monitor_printf(mon
, " apply new vlan %d",
2686 ntohs(action
->new_vlan_id
));
2689 if (action
->has_group_id
) {
2690 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2693 if (action
->has_goto_tbl
) {
2694 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2697 monitor_printf(mon
, "\n");
2700 qapi_free_RockerOfDpaFlowList(list
);
2703 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2705 RockerOfDpaGroupList
*list
, *g
;
2706 const char *name
= qdict_get_str(qdict
, "name");
2707 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2711 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
2713 hmp_handle_error(mon
, &err
);
2717 monitor_printf(mon
, "id (decode) --> buckets\n");
2719 for (g
= list
; g
; g
= g
->next
) {
2720 RockerOfDpaGroup
*group
= g
->value
;
2722 monitor_printf(mon
, "0x%08x", group
->id
);
2724 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2725 group
->type
== 1 ? "L2 rewrite" :
2726 group
->type
== 2 ? "L3 unicast" :
2727 group
->type
== 3 ? "L2 multicast" :
2728 group
->type
== 4 ? "L2 flood" :
2729 group
->type
== 5 ? "L3 interface" :
2730 group
->type
== 6 ? "L3 multicast" :
2731 group
->type
== 7 ? "L3 ECMP" :
2732 group
->type
== 8 ? "L2 overlay" :
2735 if (group
->has_vlan_id
) {
2736 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2739 if (group
->has_pport
) {
2740 monitor_printf(mon
, " pport %d", group
->pport
);
2743 if (group
->has_index
) {
2744 monitor_printf(mon
, " index %d", group
->index
);
2747 monitor_printf(mon
, ") -->");
2749 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2751 monitor_printf(mon
, " set vlan %d",
2752 group
->set_vlan_id
& VLAN_VID_MASK
);
2755 if (group
->has_set_eth_src
) {
2758 monitor_printf(mon
, " set");
2760 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2763 if (group
->has_set_eth_dst
) {
2766 monitor_printf(mon
, " set");
2768 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2773 if (group
->has_ttl_check
&& group
->ttl_check
) {
2774 monitor_printf(mon
, " check TTL");
2777 if (group
->has_group_id
&& group
->group_id
) {
2778 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2781 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2782 monitor_printf(mon
, " pop vlan");
2785 if (group
->has_out_pport
) {
2786 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2789 if (group
->has_group_ids
) {
2790 struct uint32List
*id
;
2792 monitor_printf(mon
, " groups [");
2793 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2794 monitor_printf(mon
, "0x%08x", id
->value
);
2796 monitor_printf(mon
, ",");
2799 monitor_printf(mon
, "]");
2802 monitor_printf(mon
, "\n");
2805 qapi_free_RockerOfDpaGroupList(list
);
2808 void hmp_info_dump(Monitor
*mon
, const QDict
*qdict
)
2810 DumpQueryResult
*result
= qmp_query_dump(NULL
);
2812 assert(result
&& result
->status
< DUMP_STATUS__MAX
);
2813 monitor_printf(mon
, "Status: %s\n", DumpStatus_str(result
->status
));
2815 if (result
->status
== DUMP_STATUS_ACTIVE
) {
2817 assert(result
->total
!= 0);
2818 percent
= 100.0 * result
->completed
/ result
->total
;
2819 monitor_printf(mon
, "Finished: %.2f %%\n", percent
);
2822 qapi_free_DumpQueryResult(result
);
2825 void hmp_info_ramblock(Monitor
*mon
, const QDict
*qdict
)
2827 ram_block_dump(mon
);
2830 void hmp_hotpluggable_cpus(Monitor
*mon
, const QDict
*qdict
)
2833 HotpluggableCPUList
*l
= qmp_query_hotpluggable_cpus(&err
);
2834 HotpluggableCPUList
*saved
= l
;
2835 CpuInstanceProperties
*c
;
2838 hmp_handle_error(mon
, &err
);
2842 monitor_printf(mon
, "Hotpluggable CPUs:\n");
2844 monitor_printf(mon
, " type: \"%s\"\n", l
->value
->type
);
2845 monitor_printf(mon
, " vcpus_count: \"%" PRIu64
"\"\n",
2846 l
->value
->vcpus_count
);
2847 if (l
->value
->has_qom_path
) {
2848 monitor_printf(mon
, " qom_path: \"%s\"\n", l
->value
->qom_path
);
2851 c
= l
->value
->props
;
2852 monitor_printf(mon
, " CPUInstance Properties:\n");
2853 if (c
->has_node_id
) {
2854 monitor_printf(mon
, " node-id: \"%" PRIu64
"\"\n", c
->node_id
);
2856 if (c
->has_socket_id
) {
2857 monitor_printf(mon
, " socket-id: \"%" PRIu64
"\"\n", c
->socket_id
);
2859 if (c
->has_core_id
) {
2860 monitor_printf(mon
, " core-id: \"%" PRIu64
"\"\n", c
->core_id
);
2862 if (c
->has_thread_id
) {
2863 monitor_printf(mon
, " thread-id: \"%" PRIu64
"\"\n", c
->thread_id
);
2869 qapi_free_HotpluggableCPUList(saved
);
2872 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
2875 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
2877 monitor_printf(mon
, "%s\n", info
->guid
);
2879 hmp_handle_error(mon
, &err
);
2880 qapi_free_GuidInfo(info
);
2883 void hmp_info_memory_size_summary(Monitor
*mon
, const QDict
*qdict
)
2886 MemoryInfo
*info
= qmp_query_memory_size_summary(&err
);
2888 monitor_printf(mon
, "base memory: %" PRIu64
"\n",
2891 if (info
->has_plugged_memory
) {
2892 monitor_printf(mon
, "plugged memory: %" PRIu64
"\n",
2893 info
->plugged_memory
);
2896 qapi_free_MemoryInfo(info
);
2898 hmp_handle_error(mon
, &err
);