2 * Human Monitor Interface
4 * Copyright IBM, Corp. 2011
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
16 #include "qemu/osdep.h"
20 #include "chardev/char.h"
21 #include "sysemu/block-backend.h"
22 #include "sysemu/sysemu.h"
23 #include "qemu/config-file.h"
24 #include "qemu/option.h"
25 #include "qemu/timer.h"
26 #include "qmp-commands.h"
27 #include "qemu/sockets.h"
28 #include "monitor/monitor.h"
29 #include "monitor/qdev.h"
30 #include "qapi/opts-visitor.h"
31 #include "qapi/qmp/qerror.h"
32 #include "qapi/string-input-visitor.h"
33 #include "qapi/string-output-visitor.h"
34 #include "qapi/util.h"
35 #include "qapi-visit.h"
36 #include "qom/object_interfaces.h"
37 #include "ui/console.h"
38 #include "block/nbd.h"
39 #include "block/qapi.h"
41 #include "qemu/cutils.h"
42 #include "qemu/error-report.h"
43 #include "exec/ramlist.h"
44 #include "hw/intc/intc.h"
45 #include "migration/snapshot.h"
48 #include <spice/enums.h>
51 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
55 error_report_err(*errp
);
59 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
63 info
= qmp_query_name(NULL
);
65 monitor_printf(mon
, "%s\n", info
->name
);
67 qapi_free_NameInfo(info
);
70 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
74 info
= qmp_query_version(NULL
);
76 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
77 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
80 qapi_free_VersionInfo(info
);
83 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
87 info
= qmp_query_kvm(NULL
);
88 monitor_printf(mon
, "kvm support: ");
90 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
92 monitor_printf(mon
, "not compiled\n");
95 qapi_free_KvmInfo(info
);
98 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
102 info
= qmp_query_status(NULL
);
104 monitor_printf(mon
, "VM status: %s%s",
105 info
->running
? "running" : "paused",
106 info
->singlestep
? " (single step mode)" : "");
108 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
109 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
112 monitor_printf(mon
, "\n");
114 qapi_free_StatusInfo(info
);
117 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
121 info
= qmp_query_uuid(NULL
);
122 monitor_printf(mon
, "%s\n", info
->UUID
);
123 qapi_free_UuidInfo(info
);
126 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
128 ChardevInfoList
*char_info
, *info
;
130 char_info
= qmp_query_chardev(NULL
);
131 for (info
= char_info
; info
; info
= info
->next
) {
132 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
133 info
->value
->filename
);
136 qapi_free_ChardevInfoList(char_info
);
139 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
141 MouseInfoList
*mice_list
, *mouse
;
143 mice_list
= qmp_query_mice(NULL
);
145 monitor_printf(mon
, "No mouse devices connected\n");
149 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
150 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
151 mouse
->value
->current
? '*' : ' ',
152 mouse
->value
->index
, mouse
->value
->name
,
153 mouse
->value
->absolute
? " (absolute)" : "");
156 qapi_free_MouseInfoList(mice_list
);
159 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
162 MigrationCapabilityStatusList
*caps
, *cap
;
164 info
= qmp_query_migrate(NULL
);
165 caps
= qmp_query_migrate_capabilities(NULL
);
167 /* do not display parameters during setup */
168 if (info
->has_status
&& caps
) {
169 monitor_printf(mon
, "capabilities: ");
170 for (cap
= caps
; cap
; cap
= cap
->next
) {
171 monitor_printf(mon
, "%s: %s ",
172 MigrationCapability_lookup
[cap
->value
->capability
],
173 cap
->value
->state
? "on" : "off");
175 monitor_printf(mon
, "\n");
178 if (info
->has_status
) {
179 monitor_printf(mon
, "Migration status: %s",
180 MigrationStatus_lookup
[info
->status
]);
181 if (info
->status
== MIGRATION_STATUS_FAILED
&&
182 info
->has_error_desc
) {
183 monitor_printf(mon
, " (%s)\n", info
->error_desc
);
185 monitor_printf(mon
, "\n");
188 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
190 if (info
->has_expected_downtime
) {
191 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
192 info
->expected_downtime
);
194 if (info
->has_downtime
) {
195 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
198 if (info
->has_setup_time
) {
199 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
205 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
206 info
->ram
->transferred
>> 10);
207 monitor_printf(mon
, "throughput: %0.2f mbps\n",
209 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
210 info
->ram
->remaining
>> 10);
211 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
212 info
->ram
->total
>> 10);
213 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
214 info
->ram
->duplicate
);
215 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
217 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
219 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
220 info
->ram
->normal_bytes
>> 10);
221 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
222 info
->ram
->dirty_sync_count
);
223 monitor_printf(mon
, "page size: %" PRIu64
" kbytes\n",
224 info
->ram
->page_size
>> 10);
226 if (info
->ram
->dirty_pages_rate
) {
227 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
228 info
->ram
->dirty_pages_rate
);
230 if (info
->ram
->postcopy_requests
) {
231 monitor_printf(mon
, "postcopy request count: %" PRIu64
"\n",
232 info
->ram
->postcopy_requests
);
236 if (info
->has_disk
) {
237 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
238 info
->disk
->transferred
>> 10);
239 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
240 info
->disk
->remaining
>> 10);
241 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
242 info
->disk
->total
>> 10);
245 if (info
->has_xbzrle_cache
) {
246 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
247 info
->xbzrle_cache
->cache_size
);
248 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
249 info
->xbzrle_cache
->bytes
>> 10);
250 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
251 info
->xbzrle_cache
->pages
);
252 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
253 info
->xbzrle_cache
->cache_miss
);
254 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
255 info
->xbzrle_cache
->cache_miss_rate
);
256 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
257 info
->xbzrle_cache
->overflow
);
260 if (info
->has_cpu_throttle_percentage
) {
261 monitor_printf(mon
, "cpu throttle percentage: %" PRIu64
"\n",
262 info
->cpu_throttle_percentage
);
265 qapi_free_MigrationInfo(info
);
266 qapi_free_MigrationCapabilityStatusList(caps
);
269 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
271 MigrationCapabilityStatusList
*caps
, *cap
;
273 caps
= qmp_query_migrate_capabilities(NULL
);
276 for (cap
= caps
; cap
; cap
= cap
->next
) {
277 monitor_printf(mon
, "%s: %s\n",
278 MigrationCapability_lookup
[cap
->value
->capability
],
279 cap
->value
->state
? "on" : "off");
283 qapi_free_MigrationCapabilityStatusList(caps
);
286 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
288 MigrationParameters
*params
;
290 params
= qmp_query_migrate_parameters(NULL
);
293 assert(params
->has_compress_level
);
294 monitor_printf(mon
, "%s: %" PRId64
"\n",
295 MigrationParameter_lookup
[MIGRATION_PARAMETER_COMPRESS_LEVEL
],
296 params
->compress_level
);
297 assert(params
->has_compress_threads
);
298 monitor_printf(mon
, "%s: %" PRId64
"\n",
299 MigrationParameter_lookup
[MIGRATION_PARAMETER_COMPRESS_THREADS
],
300 params
->compress_threads
);
301 assert(params
->has_decompress_threads
);
302 monitor_printf(mon
, "%s: %" PRId64
"\n",
303 MigrationParameter_lookup
[MIGRATION_PARAMETER_DECOMPRESS_THREADS
],
304 params
->decompress_threads
);
305 assert(params
->has_cpu_throttle_initial
);
306 monitor_printf(mon
, "%s: %" PRId64
"\n",
307 MigrationParameter_lookup
[MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
],
308 params
->cpu_throttle_initial
);
309 assert(params
->has_cpu_throttle_increment
);
310 monitor_printf(mon
, "%s: %" PRId64
"\n",
311 MigrationParameter_lookup
[MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
],
312 params
->cpu_throttle_increment
);
313 monitor_printf(mon
, "%s: '%s'\n",
314 MigrationParameter_lookup
[MIGRATION_PARAMETER_TLS_CREDS
],
315 params
->has_tls_creds
? params
->tls_creds
: "");
316 monitor_printf(mon
, "%s: '%s'\n",
317 MigrationParameter_lookup
[MIGRATION_PARAMETER_TLS_HOSTNAME
],
318 params
->has_tls_hostname
? params
->tls_hostname
: "");
319 assert(params
->has_max_bandwidth
);
320 monitor_printf(mon
, "%s: %" PRId64
" bytes/second\n",
321 MigrationParameter_lookup
[MIGRATION_PARAMETER_MAX_BANDWIDTH
],
322 params
->max_bandwidth
);
323 assert(params
->has_downtime_limit
);
324 monitor_printf(mon
, "%s: %" PRId64
" milliseconds\n",
325 MigrationParameter_lookup
[MIGRATION_PARAMETER_DOWNTIME_LIMIT
],
326 params
->downtime_limit
);
327 assert(params
->has_x_checkpoint_delay
);
328 monitor_printf(mon
, "%s: %" PRId64
"\n",
329 MigrationParameter_lookup
[MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
],
330 params
->x_checkpoint_delay
);
331 assert(params
->has_block_incremental
);
332 monitor_printf(mon
, "%s: %s\n",
333 MigrationParameter_lookup
[MIGRATION_PARAMETER_BLOCK_INCREMENTAL
],
334 params
->block_incremental
? "on" : "off");
337 qapi_free_MigrationParameters(params
);
340 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
342 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
343 qmp_query_migrate_cache_size(NULL
) >> 10);
346 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
348 CpuInfoList
*cpu_list
, *cpu
;
350 cpu_list
= qmp_query_cpus(NULL
);
352 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
355 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
359 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
361 switch (cpu
->value
->arch
) {
362 case CPU_INFO_ARCH_X86
:
363 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->u
.x86
.pc
);
365 case CPU_INFO_ARCH_PPC
:
366 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->u
.ppc
.nip
);
368 case CPU_INFO_ARCH_SPARC
:
369 monitor_printf(mon
, " pc=0x%016" PRIx64
,
370 cpu
->value
->u
.q_sparc
.pc
);
371 monitor_printf(mon
, " npc=0x%016" PRIx64
,
372 cpu
->value
->u
.q_sparc
.npc
);
374 case CPU_INFO_ARCH_MIPS
:
375 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.q_mips
.PC
);
377 case CPU_INFO_ARCH_TRICORE
:
378 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.tricore
.PC
);
384 if (cpu
->value
->halted
) {
385 monitor_printf(mon
, " (halted)");
388 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
391 qapi_free_CpuInfoList(cpu_list
);
394 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
395 BlockDeviceInfo
*inserted
, bool verbose
)
397 ImageInfo
*image_info
;
399 assert(!info
|| !info
->has_inserted
|| info
->inserted
== inserted
);
402 monitor_printf(mon
, "%s", info
->device
);
403 if (inserted
&& inserted
->has_node_name
) {
404 monitor_printf(mon
, " (%s)", inserted
->node_name
);
408 monitor_printf(mon
, "%s",
409 inserted
->has_node_name
410 ? inserted
->node_name
415 monitor_printf(mon
, ": %s (%s%s%s)\n",
418 inserted
->ro
? ", read-only" : "",
419 inserted
->encrypted
? ", encrypted" : "");
421 monitor_printf(mon
, ": [not inserted]\n");
425 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
426 monitor_printf(mon
, " I/O status: %s\n",
427 BlockDeviceIoStatus_lookup
[info
->io_status
]);
430 if (info
->removable
) {
431 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
432 info
->locked
? "" : "not ",
433 info
->tray_open
? "open" : "closed");
442 monitor_printf(mon
, " Cache mode: %s%s%s\n",
443 inserted
->cache
->writeback
? "writeback" : "writethrough",
444 inserted
->cache
->direct
? ", direct" : "",
445 inserted
->cache
->no_flush
? ", ignore flushes" : "");
447 if (inserted
->has_backing_file
) {
450 "(chain depth: %" PRId64
")\n",
451 inserted
->backing_file
,
452 inserted
->backing_file_depth
);
455 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
456 monitor_printf(mon
, " Detect zeroes: %s\n",
457 BlockdevDetectZeroesOptions_lookup
[inserted
->detect_zeroes
]);
460 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
461 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
463 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
464 " bps_rd=%" PRId64
" bps_wr=%" PRId64
466 " bps_rd_max=%" PRId64
467 " bps_wr_max=%" PRId64
468 " iops=%" PRId64
" iops_rd=%" PRId64
471 " iops_rd_max=%" PRId64
472 " iops_wr_max=%" PRId64
473 " iops_size=%" PRId64
479 inserted
->bps_rd_max
,
480 inserted
->bps_wr_max
,
485 inserted
->iops_rd_max
,
486 inserted
->iops_wr_max
,
492 monitor_printf(mon
, "\nImages:\n");
493 image_info
= inserted
->image
;
495 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
497 if (image_info
->has_backing_image
) {
498 image_info
= image_info
->backing_image
;
506 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
508 BlockInfoList
*block_list
, *info
;
509 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
510 const char *device
= qdict_get_try_str(qdict
, "device");
511 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
512 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
513 bool printed
= false;
515 /* Print BlockBackend information */
517 block_list
= qmp_query_block(NULL
);
522 for (info
= block_list
; info
; info
= info
->next
) {
523 if (device
&& strcmp(device
, info
->value
->device
)) {
527 if (info
!= block_list
) {
528 monitor_printf(mon
, "\n");
531 print_block_info(mon
, info
->value
, info
->value
->has_inserted
532 ? info
->value
->inserted
: NULL
,
537 qapi_free_BlockInfoList(block_list
);
539 if ((!device
&& !nodes
) || printed
) {
543 /* Print node information */
544 blockdev_list
= qmp_query_named_block_nodes(NULL
);
545 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
546 assert(blockdev
->value
->has_node_name
);
547 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
551 if (blockdev
!= blockdev_list
) {
552 monitor_printf(mon
, "\n");
555 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
557 qapi_free_BlockDeviceInfoList(blockdev_list
);
560 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
562 BlockStatsList
*stats_list
, *stats
;
564 stats_list
= qmp_query_blockstats(false, false, NULL
);
566 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
567 if (!stats
->value
->has_device
) {
571 monitor_printf(mon
, "%s:", stats
->value
->device
);
572 monitor_printf(mon
, " rd_bytes=%" PRId64
574 " rd_operations=%" PRId64
575 " wr_operations=%" PRId64
576 " flush_operations=%" PRId64
577 " wr_total_time_ns=%" PRId64
578 " rd_total_time_ns=%" PRId64
579 " flush_total_time_ns=%" PRId64
580 " rd_merged=%" PRId64
581 " wr_merged=%" PRId64
582 " idle_time_ns=%" PRId64
584 stats
->value
->stats
->rd_bytes
,
585 stats
->value
->stats
->wr_bytes
,
586 stats
->value
->stats
->rd_operations
,
587 stats
->value
->stats
->wr_operations
,
588 stats
->value
->stats
->flush_operations
,
589 stats
->value
->stats
->wr_total_time_ns
,
590 stats
->value
->stats
->rd_total_time_ns
,
591 stats
->value
->stats
->flush_total_time_ns
,
592 stats
->value
->stats
->rd_merged
,
593 stats
->value
->stats
->wr_merged
,
594 stats
->value
->stats
->idle_time_ns
);
597 qapi_free_BlockStatsList(stats_list
);
600 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
604 VncClientInfoList
*client
;
606 info
= qmp_query_vnc(&err
);
608 error_report_err(err
);
612 if (!info
->enabled
) {
613 monitor_printf(mon
, "Server: disabled\n");
617 monitor_printf(mon
, "Server:\n");
618 if (info
->has_host
&& info
->has_service
) {
619 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
621 if (info
->has_auth
) {
622 monitor_printf(mon
, " auth: %s\n", info
->auth
);
625 if (!info
->has_clients
|| info
->clients
== NULL
) {
626 monitor_printf(mon
, "Client: none\n");
628 for (client
= info
->clients
; client
; client
= client
->next
) {
629 monitor_printf(mon
, "Client:\n");
630 monitor_printf(mon
, " address: %s:%s\n",
632 client
->value
->service
);
633 monitor_printf(mon
, " x509_dname: %s\n",
634 client
->value
->x509_dname
?
635 client
->value
->x509_dname
: "none");
636 monitor_printf(mon
, " username: %s\n",
637 client
->value
->has_sasl_username
?
638 client
->value
->sasl_username
: "none");
643 qapi_free_VncInfo(info
);
647 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
649 SpiceChannelList
*chan
;
651 const char *channel_name
;
652 const char * const channel_names
[] = {
653 [SPICE_CHANNEL_MAIN
] = "main",
654 [SPICE_CHANNEL_DISPLAY
] = "display",
655 [SPICE_CHANNEL_INPUTS
] = "inputs",
656 [SPICE_CHANNEL_CURSOR
] = "cursor",
657 [SPICE_CHANNEL_PLAYBACK
] = "playback",
658 [SPICE_CHANNEL_RECORD
] = "record",
659 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
660 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
661 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
662 [SPICE_CHANNEL_PORT
] = "port",
664 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
665 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
666 * as quick fix for build failures with older versions. */
667 [SPICE_CHANNEL_WEBDAV
] = "webdav",
671 info
= qmp_query_spice(NULL
);
673 if (!info
->enabled
) {
674 monitor_printf(mon
, "Server: disabled\n");
678 monitor_printf(mon
, "Server:\n");
679 if (info
->has_port
) {
680 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
681 info
->host
, info
->port
);
683 if (info
->has_tls_port
) {
684 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
685 info
->host
, info
->tls_port
);
687 monitor_printf(mon
, " migrated: %s\n",
688 info
->migrated
? "true" : "false");
689 monitor_printf(mon
, " auth: %s\n", info
->auth
);
690 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
691 monitor_printf(mon
, " mouse-mode: %s\n",
692 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
694 if (!info
->has_channels
|| info
->channels
== NULL
) {
695 monitor_printf(mon
, "Channels: none\n");
697 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
698 monitor_printf(mon
, "Channel:\n");
699 monitor_printf(mon
, " address: %s:%s%s\n",
700 chan
->value
->host
, chan
->value
->port
,
701 chan
->value
->tls
? " [tls]" : "");
702 monitor_printf(mon
, " session: %" PRId64
"\n",
703 chan
->value
->connection_id
);
704 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
705 chan
->value
->channel_type
, chan
->value
->channel_id
);
707 channel_name
= "unknown";
708 if (chan
->value
->channel_type
> 0 &&
709 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
710 channel_names
[chan
->value
->channel_type
]) {
711 channel_name
= channel_names
[chan
->value
->channel_type
];
714 monitor_printf(mon
, " channel name: %s\n", channel_name
);
719 qapi_free_SpiceInfo(info
);
723 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
728 info
= qmp_query_balloon(&err
);
730 error_report_err(err
);
734 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
736 qapi_free_BalloonInfo(info
);
739 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
741 PciMemoryRegionList
*region
;
743 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
744 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
745 dev
->slot
, dev
->function
);
746 monitor_printf(mon
, " ");
748 if (dev
->class_info
->has_desc
) {
749 monitor_printf(mon
, "%s", dev
->class_info
->desc
);
751 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
754 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
755 dev
->id
->vendor
, dev
->id
->device
);
758 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
761 if (dev
->has_pci_bridge
) {
762 monitor_printf(mon
, " BUS %" PRId64
".\n",
763 dev
->pci_bridge
->bus
->number
);
764 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
765 dev
->pci_bridge
->bus
->secondary
);
766 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
767 dev
->pci_bridge
->bus
->subordinate
);
769 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
770 dev
->pci_bridge
->bus
->io_range
->base
,
771 dev
->pci_bridge
->bus
->io_range
->limit
);
774 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
775 dev
->pci_bridge
->bus
->memory_range
->base
,
776 dev
->pci_bridge
->bus
->memory_range
->limit
);
778 monitor_printf(mon
, " prefetchable memory range "
779 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
780 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
781 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
784 for (region
= dev
->regions
; region
; region
= region
->next
) {
787 addr
= region
->value
->address
;
788 size
= region
->value
->size
;
790 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
792 if (!strcmp(region
->value
->type
, "io")) {
793 monitor_printf(mon
, "I/O at 0x%04" PRIx64
794 " [0x%04" PRIx64
"].\n",
795 addr
, addr
+ size
- 1);
797 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
798 " [0x%08" PRIx64
"].\n",
799 region
->value
->mem_type_64
? 64 : 32,
800 region
->value
->prefetch
? " prefetchable" : "",
801 addr
, addr
+ size
- 1);
805 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
807 if (dev
->has_pci_bridge
) {
808 if (dev
->pci_bridge
->has_devices
) {
809 PciDeviceInfoList
*cdev
;
810 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
811 hmp_info_pci_device(mon
, cdev
->value
);
817 static int hmp_info_irq_foreach(Object
*obj
, void *opaque
)
819 InterruptStatsProvider
*intc
;
820 InterruptStatsProviderClass
*k
;
821 Monitor
*mon
= opaque
;
823 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
824 intc
= INTERRUPT_STATS_PROVIDER(obj
);
825 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
826 uint64_t *irq_counts
;
827 unsigned int nb_irqs
, i
;
828 if (k
->get_statistics
&&
829 k
->get_statistics(intc
, &irq_counts
, &nb_irqs
)) {
831 monitor_printf(mon
, "IRQ statistics for %s:\n",
832 object_get_typename(obj
));
833 for (i
= 0; i
< nb_irqs
; i
++) {
834 if (irq_counts
[i
] > 0) {
835 monitor_printf(mon
, "%2d: %" PRId64
"\n", i
,
841 monitor_printf(mon
, "IRQ statistics not available for %s.\n",
842 object_get_typename(obj
));
849 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
)
851 object_child_foreach_recursive(object_get_root(),
852 hmp_info_irq_foreach
, mon
);
855 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
857 InterruptStatsProvider
*intc
;
858 InterruptStatsProviderClass
*k
;
859 Monitor
*mon
= opaque
;
861 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
862 intc
= INTERRUPT_STATS_PROVIDER(obj
);
863 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
865 k
->print_info(intc
, mon
);
867 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
868 object_get_typename(obj
));
875 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
877 object_child_foreach_recursive(object_get_root(),
878 hmp_info_pic_foreach
, mon
);
881 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
883 PciInfoList
*info_list
, *info
;
886 info_list
= qmp_query_pci(&err
);
888 monitor_printf(mon
, "PCI devices not supported\n");
893 for (info
= info_list
; info
; info
= info
->next
) {
894 PciDeviceInfoList
*dev
;
896 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
897 hmp_info_pci_device(mon
, dev
->value
);
901 qapi_free_PciInfoList(info_list
);
904 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
906 BlockJobInfoList
*list
;
909 list
= qmp_query_block_jobs(&err
);
913 monitor_printf(mon
, "No active jobs\n");
918 if (strcmp(list
->value
->type
, "stream") == 0) {
919 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
920 " of %" PRId64
" bytes, speed limit %" PRId64
927 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
928 " of %" PRId64
" bytes, speed limit %" PRId64
939 qapi_free_BlockJobInfoList(list
);
942 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
944 TPMInfoList
*info_list
, *info
;
947 TPMPassthroughOptions
*tpo
;
949 info_list
= qmp_query_tpm(&err
);
951 monitor_printf(mon
, "TPM device not supported\n");
957 monitor_printf(mon
, "TPM device:\n");
960 for (info
= info_list
; info
; info
= info
->next
) {
961 TPMInfo
*ti
= info
->value
;
962 monitor_printf(mon
, " tpm%d: model=%s\n",
963 c
, TpmModel_lookup
[ti
->model
]);
965 monitor_printf(mon
, " \\ %s: type=%s",
966 ti
->id
, TpmTypeOptionsKind_lookup
[ti
->options
->type
]);
968 switch (ti
->options
->type
) {
969 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
970 tpo
= ti
->options
->u
.passthrough
.data
;
971 monitor_printf(mon
, "%s%s%s%s",
972 tpo
->has_path
? ",path=" : "",
973 tpo
->has_path
? tpo
->path
: "",
974 tpo
->has_cancel_path
? ",cancel-path=" : "",
975 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
977 case TPM_TYPE_OPTIONS_KIND__MAX
:
980 monitor_printf(mon
, "\n");
983 qapi_free_TPMInfoList(info_list
);
986 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
988 monitor_suspend(mon
);
992 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
997 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
999 qmp_system_reset(NULL
);
1002 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
1004 qmp_system_powerdown(NULL
);
1007 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
1011 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1012 use it are converted to the QAPI */
1013 cpu_index
= qdict_get_int(qdict
, "index");
1014 if (monitor_set_cpu(cpu_index
) < 0) {
1015 monitor_printf(mon
, "invalid CPU index\n");
1019 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
1021 uint32_t size
= qdict_get_int(qdict
, "size");
1022 const char *filename
= qdict_get_str(qdict
, "filename");
1023 uint64_t addr
= qdict_get_int(qdict
, "val");
1025 int cpu_index
= monitor_get_cpu_index();
1027 if (cpu_index
< 0) {
1028 monitor_printf(mon
, "No CPU available\n");
1032 qmp_memsave(addr
, size
, filename
, true, cpu_index
, &err
);
1033 hmp_handle_error(mon
, &err
);
1036 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
1038 uint32_t size
= qdict_get_int(qdict
, "size");
1039 const char *filename
= qdict_get_str(qdict
, "filename");
1040 uint64_t addr
= qdict_get_int(qdict
, "val");
1043 qmp_pmemsave(addr
, size
, filename
, &err
);
1044 hmp_handle_error(mon
, &err
);
1047 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
1049 const char *chardev
= qdict_get_str(qdict
, "device");
1050 const char *data
= qdict_get_str(qdict
, "data");
1053 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
1055 hmp_handle_error(mon
, &err
);
1058 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
1060 uint32_t size
= qdict_get_int(qdict
, "size");
1061 const char *chardev
= qdict_get_str(qdict
, "device");
1066 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
1068 error_report_err(err
);
1072 for (i
= 0; data
[i
]; i
++) {
1073 unsigned char ch
= data
[i
];
1076 monitor_printf(mon
, "\\\\");
1077 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
1078 monitor_printf(mon
, "\\u%04X", ch
);
1080 monitor_printf(mon
, "%c", ch
);
1084 monitor_printf(mon
, "\n");
1088 static void hmp_cont_cb(void *opaque
, int err
)
1095 static bool key_is_missing(const BlockInfo
*bdev
)
1097 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
1100 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
1102 BlockInfoList
*bdev_list
, *bdev
;
1105 bdev_list
= qmp_query_block(NULL
);
1106 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
1107 if (key_is_missing(bdev
->value
)) {
1108 monitor_read_block_device_key(mon
, bdev
->value
->device
,
1115 hmp_handle_error(mon
, &err
);
1118 qapi_free_BlockInfoList(bdev_list
);
1121 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
1123 qmp_system_wakeup(NULL
);
1126 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
1130 qmp_inject_nmi(&err
);
1131 hmp_handle_error(mon
, &err
);
1134 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
1136 const char *name
= qdict_get_str(qdict
, "name");
1137 bool up
= qdict_get_bool(qdict
, "up");
1140 qmp_set_link(name
, up
, &err
);
1141 hmp_handle_error(mon
, &err
);
1144 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
1146 const char *device
= qdict_get_str(qdict
, "device");
1147 const char *password
= qdict_get_str(qdict
, "password");
1150 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
1151 hmp_handle_error(mon
, &err
);
1154 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1156 int64_t value
= qdict_get_int(qdict
, "value");
1159 qmp_balloon(value
, &err
);
1161 error_report_err(err
);
1165 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
1167 const char *device
= qdict_get_str(qdict
, "device");
1168 int64_t size
= qdict_get_int(qdict
, "size");
1171 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
1172 hmp_handle_error(mon
, &err
);
1175 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
1177 const char *filename
= qdict_get_str(qdict
, "target");
1178 const char *format
= qdict_get_try_str(qdict
, "format");
1179 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1180 bool full
= qdict_get_try_bool(qdict
, "full", false);
1182 DriveMirror mirror
= {
1183 .device
= (char *)qdict_get_str(qdict
, "device"),
1184 .target
= (char *)filename
,
1185 .has_format
= !!format
,
1186 .format
= (char *)format
,
1187 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1189 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1194 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1195 hmp_handle_error(mon
, &err
);
1198 qmp_drive_mirror(&mirror
, &err
);
1199 hmp_handle_error(mon
, &err
);
1202 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
1204 const char *device
= qdict_get_str(qdict
, "device");
1205 const char *filename
= qdict_get_str(qdict
, "target");
1206 const char *format
= qdict_get_try_str(qdict
, "format");
1207 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1208 bool full
= qdict_get_try_bool(qdict
, "full", false);
1209 bool compress
= qdict_get_try_bool(qdict
, "compress", false);
1211 DriveBackup backup
= {
1212 .device
= (char *)device
,
1213 .target
= (char *)filename
,
1214 .has_format
= !!format
,
1215 .format
= (char *)format
,
1216 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1218 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1219 .has_compress
= !!compress
,
1220 .compress
= compress
,
1224 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1225 hmp_handle_error(mon
, &err
);
1229 qmp_drive_backup(&backup
, &err
);
1230 hmp_handle_error(mon
, &err
);
1233 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
1235 const char *device
= qdict_get_str(qdict
, "device");
1236 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
1237 const char *format
= qdict_get_try_str(qdict
, "format");
1238 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1239 enum NewImageMode mode
;
1243 /* In the future, if 'snapshot-file' is not specified, the snapshot
1244 will be taken internally. Today it's actually required. */
1245 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
1246 hmp_handle_error(mon
, &err
);
1250 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1251 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
1252 filename
, false, NULL
,
1255 hmp_handle_error(mon
, &err
);
1258 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1260 const char *device
= qdict_get_str(qdict
, "device");
1261 const char *name
= qdict_get_str(qdict
, "name");
1264 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1265 hmp_handle_error(mon
, &err
);
1268 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1270 const char *device
= qdict_get_str(qdict
, "device");
1271 const char *name
= qdict_get_str(qdict
, "name");
1272 const char *id
= qdict_get_try_str(qdict
, "id");
1275 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1277 hmp_handle_error(mon
, &err
);
1280 void hmp_loadvm(Monitor
*mon
, const QDict
*qdict
)
1282 int saved_vm_running
= runstate_is_running();
1283 const char *name
= qdict_get_str(qdict
, "name");
1286 vm_stop(RUN_STATE_RESTORE_VM
);
1288 if (load_snapshot(name
, &err
) == 0 && saved_vm_running
) {
1291 hmp_handle_error(mon
, &err
);
1294 void hmp_savevm(Monitor
*mon
, const QDict
*qdict
)
1298 save_snapshot(qdict_get_try_str(qdict
, "name"), &err
);
1299 hmp_handle_error(mon
, &err
);
1302 void hmp_delvm(Monitor
*mon
, const QDict
*qdict
)
1304 BlockDriverState
*bs
;
1306 const char *name
= qdict_get_str(qdict
, "name");
1308 if (bdrv_all_delete_snapshot(name
, &bs
, &err
) < 0) {
1309 error_reportf_err(err
,
1310 "Error while deleting snapshot on device '%s': ",
1311 bdrv_get_device_name(bs
));
1315 void hmp_info_snapshots(Monitor
*mon
, const QDict
*qdict
)
1317 BlockDriverState
*bs
, *bs1
;
1318 BdrvNextIterator it1
;
1319 QEMUSnapshotInfo
*sn_tab
, *sn
;
1320 bool no_snapshot
= true;
1323 int *global_snapshots
;
1324 AioContext
*aio_context
;
1326 typedef struct SnapshotEntry
{
1327 QEMUSnapshotInfo sn
;
1328 QTAILQ_ENTRY(SnapshotEntry
) next
;
1331 typedef struct ImageEntry
{
1332 const char *imagename
;
1333 QTAILQ_ENTRY(ImageEntry
) next
;
1334 QTAILQ_HEAD(, SnapshotEntry
) snapshots
;
1337 QTAILQ_HEAD(, ImageEntry
) image_list
=
1338 QTAILQ_HEAD_INITIALIZER(image_list
);
1340 ImageEntry
*image_entry
, *next_ie
;
1341 SnapshotEntry
*snapshot_entry
;
1343 bs
= bdrv_all_find_vmstate_bs();
1345 monitor_printf(mon
, "No available block device supports snapshots\n");
1348 aio_context
= bdrv_get_aio_context(bs
);
1350 aio_context_acquire(aio_context
);
1351 nb_sns
= bdrv_snapshot_list(bs
, &sn_tab
);
1352 aio_context_release(aio_context
);
1355 monitor_printf(mon
, "bdrv_snapshot_list: error %d\n", nb_sns
);
1359 for (bs1
= bdrv_first(&it1
); bs1
; bs1
= bdrv_next(&it1
)) {
1363 AioContext
*ctx
= bdrv_get_aio_context(bs1
);
1365 aio_context_acquire(ctx
);
1366 if (bdrv_can_snapshot(bs1
)) {
1368 bs1_nb_sns
= bdrv_snapshot_list(bs1
, &sn
);
1369 if (bs1_nb_sns
> 0) {
1370 no_snapshot
= false;
1371 ie
= g_new0(ImageEntry
, 1);
1372 ie
->imagename
= bdrv_get_device_name(bs1
);
1373 QTAILQ_INIT(&ie
->snapshots
);
1374 QTAILQ_INSERT_TAIL(&image_list
, ie
, next
);
1375 for (i
= 0; i
< bs1_nb_sns
; i
++) {
1376 se
= g_new0(SnapshotEntry
, 1);
1378 QTAILQ_INSERT_TAIL(&ie
->snapshots
, se
, next
);
1383 aio_context_release(ctx
);
1387 monitor_printf(mon
, "There is no snapshot available.\n");
1391 global_snapshots
= g_new0(int, nb_sns
);
1393 for (i
= 0; i
< nb_sns
; i
++) {
1394 SnapshotEntry
*next_sn
;
1395 if (bdrv_all_find_snapshot(sn_tab
[i
].name
, &bs1
) == 0) {
1396 global_snapshots
[total
] = i
;
1398 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1399 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
,
1401 if (!strcmp(sn_tab
[i
].name
, snapshot_entry
->sn
.name
)) {
1402 QTAILQ_REMOVE(&image_entry
->snapshots
, snapshot_entry
,
1404 g_free(snapshot_entry
);
1411 monitor_printf(mon
, "List of snapshots present on all disks:\n");
1414 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1415 monitor_printf(mon
, "\n");
1416 for (i
= 0; i
< total
; i
++) {
1417 sn
= &sn_tab
[global_snapshots
[i
]];
1418 /* The ID is not guaranteed to be the same on all images, so
1421 pstrcpy(sn
->id_str
, sizeof(sn
->id_str
), "--");
1422 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, sn
);
1423 monitor_printf(mon
, "\n");
1426 monitor_printf(mon
, "None\n");
1429 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1430 if (QTAILQ_EMPTY(&image_entry
->snapshots
)) {
1434 "\nList of partial (non-loadable) snapshots on '%s':\n",
1435 image_entry
->imagename
);
1436 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1437 monitor_printf(mon
, "\n");
1438 QTAILQ_FOREACH(snapshot_entry
, &image_entry
->snapshots
, next
) {
1439 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
,
1440 &snapshot_entry
->sn
);
1441 monitor_printf(mon
, "\n");
1445 QTAILQ_FOREACH_SAFE(image_entry
, &image_list
, next
, next_ie
) {
1446 SnapshotEntry
*next_sn
;
1447 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
, next
,
1449 g_free(snapshot_entry
);
1451 g_free(image_entry
);
1454 g_free(global_snapshots
);
1458 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1460 qmp_migrate_cancel(NULL
);
1463 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1466 const char *uri
= qdict_get_str(qdict
, "uri");
1468 qmp_migrate_incoming(uri
, &err
);
1470 hmp_handle_error(mon
, &err
);
1473 /* Kept for backwards compatibility */
1474 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1476 double value
= qdict_get_double(qdict
, "value");
1477 qmp_migrate_set_downtime(value
, NULL
);
1480 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1482 int64_t value
= qdict_get_int(qdict
, "value");
1485 qmp_migrate_set_cache_size(value
, &err
);
1487 error_report_err(err
);
1492 /* Kept for backwards compatibility */
1493 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1495 int64_t value
= qdict_get_int(qdict
, "value");
1496 qmp_migrate_set_speed(value
, NULL
);
1499 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1501 const char *cap
= qdict_get_str(qdict
, "capability");
1502 bool state
= qdict_get_bool(qdict
, "state");
1504 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1507 for (i
= 0; i
< MIGRATION_CAPABILITY__MAX
; i
++) {
1508 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
1509 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1510 caps
->value
->capability
= i
;
1511 caps
->value
->state
= state
;
1513 qmp_migrate_set_capabilities(caps
, &err
);
1518 if (i
== MIGRATION_CAPABILITY__MAX
) {
1519 error_setg(&err
, QERR_INVALID_PARAMETER
, cap
);
1522 qapi_free_MigrationCapabilityStatusList(caps
);
1525 error_report_err(err
);
1529 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1531 const char *param
= qdict_get_str(qdict
, "parameter");
1532 const char *valuestr
= qdict_get_str(qdict
, "value");
1533 Visitor
*v
= string_input_visitor_new(valuestr
);
1534 uint64_t valuebw
= 0;
1535 int64_t valueint
= 0;
1536 bool valuebool
= false;
1538 bool use_int_value
= false;
1541 for (i
= 0; i
< MIGRATION_PARAMETER__MAX
; i
++) {
1542 if (strcmp(param
, MigrationParameter_lookup
[i
]) == 0) {
1543 MigrationParameters p
= { 0 };
1545 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1546 p
.has_compress_level
= true;
1547 use_int_value
= true;
1549 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1550 p
.has_compress_threads
= true;
1551 use_int_value
= true;
1553 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1554 p
.has_decompress_threads
= true;
1555 use_int_value
= true;
1557 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1558 p
.has_cpu_throttle_initial
= true;
1559 use_int_value
= true;
1561 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1562 p
.has_cpu_throttle_increment
= true;
1563 use_int_value
= true;
1565 case MIGRATION_PARAMETER_TLS_CREDS
:
1566 p
.has_tls_creds
= true;
1567 p
.tls_creds
= (char *) valuestr
;
1569 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1570 p
.has_tls_hostname
= true;
1571 p
.tls_hostname
= (char *) valuestr
;
1573 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1574 p
.has_max_bandwidth
= true;
1575 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
1576 if (ret
< 0 || valuebw
> INT64_MAX
1577 || (size_t)valuebw
!= valuebw
) {
1578 error_setg(&err
, "Invalid size %s", valuestr
);
1581 p
.max_bandwidth
= valuebw
;
1583 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1584 p
.has_downtime_limit
= true;
1585 use_int_value
= true;
1587 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
1588 p
.has_x_checkpoint_delay
= true;
1589 use_int_value
= true;
1591 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL
:
1592 p
.has_block_incremental
= true;
1593 visit_type_bool(v
, param
, &valuebool
, &err
);
1597 p
.block_incremental
= valuebool
;
1601 if (use_int_value
) {
1602 visit_type_int(v
, param
, &valueint
, &err
);
1606 /* Set all integers; only one has_FOO will be set, and
1607 * the code ignores the remaining values */
1608 p
.compress_level
= valueint
;
1609 p
.compress_threads
= valueint
;
1610 p
.decompress_threads
= valueint
;
1611 p
.cpu_throttle_initial
= valueint
;
1612 p
.cpu_throttle_increment
= valueint
;
1613 p
.downtime_limit
= valueint
;
1614 p
.x_checkpoint_delay
= valueint
;
1617 qmp_migrate_set_parameters(&p
, &err
);
1622 if (i
== MIGRATION_PARAMETER__MAX
) {
1623 error_setg(&err
, QERR_INVALID_PARAMETER
, param
);
1629 error_report_err(err
);
1633 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1636 const char *protocol
= qdict_get_str(qdict
, "protocol");
1637 const char *hostname
= qdict_get_str(qdict
, "hostname");
1638 bool has_port
= qdict_haskey(qdict
, "port");
1639 int port
= qdict_get_try_int(qdict
, "port", -1);
1640 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1641 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1642 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1644 qmp_client_migrate_info(protocol
, hostname
,
1645 has_port
, port
, has_tls_port
, tls_port
,
1646 !!cert_subject
, cert_subject
, &err
);
1647 hmp_handle_error(mon
, &err
);
1650 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1653 qmp_migrate_start_postcopy(&err
);
1654 hmp_handle_error(mon
, &err
);
1657 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1661 qmp_x_colo_lost_heartbeat(&err
);
1662 hmp_handle_error(mon
, &err
);
1665 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1667 const char *protocol
= qdict_get_str(qdict
, "protocol");
1668 const char *password
= qdict_get_str(qdict
, "password");
1669 const char *connected
= qdict_get_try_str(qdict
, "connected");
1672 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1673 hmp_handle_error(mon
, &err
);
1676 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1678 const char *protocol
= qdict_get_str(qdict
, "protocol");
1679 const char *whenstr
= qdict_get_str(qdict
, "time");
1682 qmp_expire_password(protocol
, whenstr
, &err
);
1683 hmp_handle_error(mon
, &err
);
1686 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1688 bool force
= qdict_get_try_bool(qdict
, "force", false);
1689 const char *device
= qdict_get_str(qdict
, "device");
1692 qmp_eject(true, device
, false, NULL
, true, force
, &err
);
1693 hmp_handle_error(mon
, &err
);
1696 static void hmp_change_read_arg(void *opaque
, const char *password
,
1697 void *readline_opaque
)
1699 qmp_change_vnc_password(password
, NULL
);
1700 monitor_read_command(opaque
, 1);
1703 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1705 const char *device
= qdict_get_str(qdict
, "device");
1706 const char *target
= qdict_get_str(qdict
, "target");
1707 const char *arg
= qdict_get_try_str(qdict
, "arg");
1708 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1709 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1712 if (strcmp(device
, "vnc") == 0) {
1715 "Parameter 'read-only-mode' is invalid for VNC\n");
1718 if (strcmp(target
, "passwd") == 0 ||
1719 strcmp(target
, "password") == 0) {
1721 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1725 qmp_change("vnc", target
, !!arg
, arg
, &err
);
1729 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup
,
1730 read_only
, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX
,
1731 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1733 hmp_handle_error(mon
, &err
);
1738 qmp_blockdev_change_medium(true, device
, false, NULL
, target
,
1739 !!arg
, arg
, !!read_only
, read_only_mode
,
1742 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
1744 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
1749 hmp_handle_error(mon
, &err
);
1752 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1755 BlockIOThrottle throttle
= {
1757 .device
= (char *) qdict_get_str(qdict
, "device"),
1758 .bps
= qdict_get_int(qdict
, "bps"),
1759 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
1760 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
1761 .iops
= qdict_get_int(qdict
, "iops"),
1762 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
1763 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
1766 qmp_block_set_io_throttle(&throttle
, &err
);
1767 hmp_handle_error(mon
, &err
);
1770 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1772 Error
*error
= NULL
;
1773 const char *device
= qdict_get_str(qdict
, "device");
1774 const char *base
= qdict_get_try_str(qdict
, "base");
1775 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1777 qmp_block_stream(true, device
, device
, base
!= NULL
, base
, false, NULL
,
1778 false, NULL
, qdict_haskey(qdict
, "speed"), speed
,
1779 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1781 hmp_handle_error(mon
, &error
);
1784 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1786 Error
*error
= NULL
;
1787 const char *device
= qdict_get_str(qdict
, "device");
1788 int64_t value
= qdict_get_int(qdict
, "speed");
1790 qmp_block_job_set_speed(device
, value
, &error
);
1792 hmp_handle_error(mon
, &error
);
1795 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1797 Error
*error
= NULL
;
1798 const char *device
= qdict_get_str(qdict
, "device");
1799 bool force
= qdict_get_try_bool(qdict
, "force", false);
1801 qmp_block_job_cancel(device
, true, force
, &error
);
1803 hmp_handle_error(mon
, &error
);
1806 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1808 Error
*error
= NULL
;
1809 const char *device
= qdict_get_str(qdict
, "device");
1811 qmp_block_job_pause(device
, &error
);
1813 hmp_handle_error(mon
, &error
);
1816 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1818 Error
*error
= NULL
;
1819 const char *device
= qdict_get_str(qdict
, "device");
1821 qmp_block_job_resume(device
, &error
);
1823 hmp_handle_error(mon
, &error
);
1826 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1828 Error
*error
= NULL
;
1829 const char *device
= qdict_get_str(qdict
, "device");
1831 qmp_block_job_complete(device
, &error
);
1833 hmp_handle_error(mon
, &error
);
1836 typedef struct HMPMigrationStatus
1840 bool is_block_migration
;
1841 } HMPMigrationStatus
;
1843 static void hmp_migrate_status_cb(void *opaque
)
1845 HMPMigrationStatus
*status
= opaque
;
1846 MigrationInfo
*info
;
1848 info
= qmp_query_migrate(NULL
);
1849 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1850 info
->status
== MIGRATION_STATUS_SETUP
) {
1851 if (info
->has_disk
) {
1854 if (info
->disk
->remaining
) {
1855 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1860 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1861 monitor_flush(status
->mon
);
1864 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1866 if (status
->is_block_migration
) {
1867 monitor_printf(status
->mon
, "\n");
1869 if (info
->has_error_desc
) {
1870 error_report("%s", info
->error_desc
);
1872 monitor_resume(status
->mon
);
1873 timer_del(status
->timer
);
1877 qapi_free_MigrationInfo(info
);
1880 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1882 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1883 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1884 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1885 const char *uri
= qdict_get_str(qdict
, "uri");
1888 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1890 error_report_err(err
);
1895 HMPMigrationStatus
*status
;
1897 if (monitor_suspend(mon
) < 0) {
1898 monitor_printf(mon
, "terminal does not allow synchronous "
1899 "migration, continuing detached\n");
1903 status
= g_malloc0(sizeof(*status
));
1905 status
->is_block_migration
= blk
|| inc
;
1906 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1908 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1912 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
1916 qmp_device_add((QDict
*)qdict
, NULL
, &err
);
1917 hmp_handle_error(mon
, &err
);
1920 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1922 const char *id
= qdict_get_str(qdict
, "id");
1925 qmp_device_del(id
, &err
);
1926 hmp_handle_error(mon
, &err
);
1929 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1932 bool paging
= qdict_get_try_bool(qdict
, "paging", false);
1933 bool zlib
= qdict_get_try_bool(qdict
, "zlib", false);
1934 bool lzo
= qdict_get_try_bool(qdict
, "lzo", false);
1935 bool snappy
= qdict_get_try_bool(qdict
, "snappy", false);
1936 const char *file
= qdict_get_str(qdict
, "filename");
1937 bool has_begin
= qdict_haskey(qdict
, "begin");
1938 bool has_length
= qdict_haskey(qdict
, "length");
1939 bool has_detach
= qdict_haskey(qdict
, "detach");
1942 bool detach
= false;
1943 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1946 if (zlib
+ lzo
+ snappy
> 1) {
1947 error_setg(&err
, "only one of '-z|-l|-s' can be set");
1948 hmp_handle_error(mon
, &err
);
1953 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
1957 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
1961 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
1965 begin
= qdict_get_int(qdict
, "begin");
1968 length
= qdict_get_int(qdict
, "length");
1971 detach
= qdict_get_bool(qdict
, "detach");
1974 prot
= g_strconcat("file:", file
, NULL
);
1976 qmp_dump_guest_memory(paging
, prot
, true, detach
, has_begin
, begin
,
1977 has_length
, length
, true, dump_format
, &err
);
1978 hmp_handle_error(mon
, &err
);
1982 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1987 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1992 netdev_add(opts
, &err
);
1994 qemu_opts_del(opts
);
1998 hmp_handle_error(mon
, &err
);
2001 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
2003 const char *id
= qdict_get_str(qdict
, "id");
2006 qmp_netdev_del(id
, &err
);
2007 hmp_handle_error(mon
, &err
);
2010 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
2016 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
2018 hmp_handle_error(mon
, &err
);
2022 obj
= user_creatable_add_opts(opts
, &err
);
2023 qemu_opts_del(opts
);
2026 hmp_handle_error(mon
, &err
);
2033 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
2035 const char *fdname
= qdict_get_str(qdict
, "fdname");
2038 qmp_getfd(fdname
, &err
);
2039 hmp_handle_error(mon
, &err
);
2042 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
2044 const char *fdname
= qdict_get_str(qdict
, "fdname");
2047 qmp_closefd(fdname
, &err
);
2048 hmp_handle_error(mon
, &err
);
2051 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
2053 const char *keys
= qdict_get_str(qdict
, "keys");
2054 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
2055 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
2056 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
2062 separator
= strchr(keys
, '-');
2063 keyname_len
= separator
? separator
- keys
: strlen(keys
);
2065 /* Be compatible with old interface, convert user inputted "<" */
2066 if (keys
[0] == '<' && keyname_len
== 1) {
2071 keylist
= g_malloc0(sizeof(*keylist
));
2072 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
2078 tmp
->next
= keylist
;
2082 if (strstart(keys
, "0x", NULL
)) {
2084 int value
= strtoul(keys
, &endp
, 0);
2085 assert(endp
<= keys
+ keyname_len
);
2086 if (endp
!= keys
+ keyname_len
) {
2089 keylist
->value
->type
= KEY_VALUE_KIND_NUMBER
;
2090 keylist
->value
->u
.number
.data
= value
;
2092 int idx
= index_from_key(keys
, keyname_len
);
2093 if (idx
== Q_KEY_CODE__MAX
) {
2096 keylist
->value
->type
= KEY_VALUE_KIND_QCODE
;
2097 keylist
->value
->u
.qcode
.data
= idx
;
2103 keys
= separator
+ 1;
2106 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
2107 hmp_handle_error(mon
, &err
);
2110 qapi_free_KeyValueList(head
);
2114 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
2118 void hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
2120 const char *filename
= qdict_get_str(qdict
, "filename");
2123 qmp_screendump(filename
, &err
);
2124 hmp_handle_error(mon
, &err
);
2127 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
2129 const char *uri
= qdict_get_str(qdict
, "uri");
2130 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2131 bool all
= qdict_get_try_bool(qdict
, "all", false);
2132 Error
*local_err
= NULL
;
2133 BlockInfoList
*block_list
, *info
;
2134 SocketAddress
*addr
;
2136 if (writable
&& !all
) {
2137 error_setg(&local_err
, "-w only valid together with -a");
2141 /* First check if the address is valid and start the server. */
2142 addr
= socket_parse(uri
, &local_err
);
2143 if (local_err
!= NULL
) {
2147 nbd_server_start(addr
, NULL
, &local_err
);
2148 qapi_free_SocketAddress(addr
);
2149 if (local_err
!= NULL
) {
2157 /* Then try adding all block devices. If one fails, close all and
2160 block_list
= qmp_query_block(NULL
);
2162 for (info
= block_list
; info
; info
= info
->next
) {
2163 if (!info
->value
->has_inserted
) {
2167 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
2169 if (local_err
!= NULL
) {
2170 qmp_nbd_server_stop(NULL
);
2175 qapi_free_BlockInfoList(block_list
);
2178 hmp_handle_error(mon
, &local_err
);
2181 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
2183 const char *device
= qdict_get_str(qdict
, "device");
2184 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2185 Error
*local_err
= NULL
;
2187 qmp_nbd_server_add(device
, true, writable
, &local_err
);
2189 if (local_err
!= NULL
) {
2190 hmp_handle_error(mon
, &local_err
);
2194 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
2198 qmp_nbd_server_stop(&err
);
2199 hmp_handle_error(mon
, &err
);
2202 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
2207 cpuid
= qdict_get_int(qdict
, "id");
2208 qmp_cpu_add(cpuid
, &err
);
2209 hmp_handle_error(mon
, &err
);
2212 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
2214 const char *args
= qdict_get_str(qdict
, "args");
2218 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
2220 error_setg(&err
, "Parsing chardev args failed");
2222 qemu_chr_new_from_opts(opts
, &err
);
2223 qemu_opts_del(opts
);
2225 hmp_handle_error(mon
, &err
);
2228 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
2230 Error
*local_err
= NULL
;
2232 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
2233 hmp_handle_error(mon
, &local_err
);
2236 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
2239 BlockBackend
*local_blk
= NULL
;
2240 AioContext
*aio_context
;
2241 const char* device
= qdict_get_str(qdict
, "device");
2242 const char* command
= qdict_get_str(qdict
, "command");
2246 blk
= blk_by_name(device
);
2248 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, device
, &err
);
2250 blk
= local_blk
= blk_new(0, BLK_PERM_ALL
);
2251 ret
= blk_insert_bs(blk
, bs
, &err
);
2260 aio_context
= blk_get_aio_context(blk
);
2261 aio_context_acquire(aio_context
);
2264 * Notably absent: Proper permission management. This is sad, but it seems
2265 * almost impossible to achieve without changing the semantics and thereby
2266 * limiting the use cases of the qemu-io HMP command.
2268 * In an ideal world we would unconditionally create a new BlockBackend for
2269 * qemuio_command(), but we have commands like 'reopen' and want them to
2270 * take effect on the exact BlockBackend whose name the user passed instead
2271 * of just on a temporary copy of it.
2273 * Another problem is that deleting the temporary BlockBackend involves
2274 * draining all requests on it first, but some qemu-iotests cases want to
2275 * issue multiple aio_read/write requests and expect them to complete in
2276 * the background while the monitor has already returned.
2278 * This is also what prevents us from saving the original permissions and
2279 * restoring them later: We can't revoke permissions until all requests
2280 * have completed, and we don't know when that is nor can we really let
2281 * anything else run before we have revoken them to avoid race conditions.
2283 * What happens now is that command() in qemu-io-cmds.c can extend the
2284 * permissions if necessary for the qemu-io command. And they simply stay
2285 * extended, possibly resulting in a read-only guest device keeping write
2286 * permissions. Ugly, but it appears to be the lesser evil.
2288 qemuio_command(blk
, command
);
2290 aio_context_release(aio_context
);
2293 blk_unref(local_blk
);
2294 hmp_handle_error(mon
, &err
);
2297 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
2299 const char *id
= qdict_get_str(qdict
, "id");
2302 user_creatable_del(id
, &err
);
2303 hmp_handle_error(mon
, &err
);
2306 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
2309 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
2310 MemdevList
*m
= memdev_list
;
2315 v
= string_output_visitor_new(false, &str
);
2316 visit_type_uint16List(v
, NULL
, &m
->value
->host_nodes
, NULL
);
2317 monitor_printf(mon
, "memory backend: %s\n", m
->value
->id
);
2318 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
2319 monitor_printf(mon
, " merge: %s\n",
2320 m
->value
->merge
? "true" : "false");
2321 monitor_printf(mon
, " dump: %s\n",
2322 m
->value
->dump
? "true" : "false");
2323 monitor_printf(mon
, " prealloc: %s\n",
2324 m
->value
->prealloc
? "true" : "false");
2325 monitor_printf(mon
, " policy: %s\n",
2326 HostMemPolicy_lookup
[m
->value
->policy
]);
2327 visit_complete(v
, &str
);
2328 monitor_printf(mon
, " host nodes: %s\n", str
);
2335 monitor_printf(mon
, "\n");
2337 qapi_free_MemdevList(memdev_list
);
2340 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
2343 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
2344 MemoryDeviceInfoList
*info
;
2345 MemoryDeviceInfo
*value
;
2346 PCDIMMDeviceInfo
*di
;
2348 for (info
= info_list
; info
; info
= info
->next
) {
2349 value
= info
->value
;
2352 switch (value
->type
) {
2353 case MEMORY_DEVICE_INFO_KIND_DIMM
:
2354 di
= value
->u
.dimm
.data
;
2356 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
2357 MemoryDeviceInfoKind_lookup
[value
->type
],
2358 di
->id
? di
->id
: "");
2359 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
2360 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
2361 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
2362 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
2363 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
2364 monitor_printf(mon
, " hotplugged: %s\n",
2365 di
->hotplugged
? "true" : "false");
2366 monitor_printf(mon
, " hotpluggable: %s\n",
2367 di
->hotpluggable
? "true" : "false");
2375 qapi_free_MemoryDeviceInfoList(info_list
);
2378 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
2380 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
2381 IOThreadInfoList
*info
;
2382 IOThreadInfo
*value
;
2384 for (info
= info_list
; info
; info
= info
->next
) {
2385 value
= info
->value
;
2386 monitor_printf(mon
, "%s:\n", value
->id
);
2387 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
2388 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
2389 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
2390 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
2393 qapi_free_IOThreadInfoList(info_list
);
2396 void hmp_qom_list(Monitor
*mon
, const QDict
*qdict
)
2398 const char *path
= qdict_get_try_str(qdict
, "path");
2399 ObjectPropertyInfoList
*list
;
2403 monitor_printf(mon
, "/\n");
2407 list
= qmp_qom_list(path
, &err
);
2409 ObjectPropertyInfoList
*start
= list
;
2410 while (list
!= NULL
) {
2411 ObjectPropertyInfo
*value
= list
->value
;
2413 monitor_printf(mon
, "%s (%s)\n",
2414 value
->name
, value
->type
);
2417 qapi_free_ObjectPropertyInfoList(start
);
2419 hmp_handle_error(mon
, &err
);
2422 void hmp_qom_set(Monitor
*mon
, const QDict
*qdict
)
2424 const char *path
= qdict_get_str(qdict
, "path");
2425 const char *property
= qdict_get_str(qdict
, "property");
2426 const char *value
= qdict_get_str(qdict
, "value");
2428 bool ambiguous
= false;
2431 obj
= object_resolve_path(path
, &ambiguous
);
2433 error_set(&err
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2434 "Device '%s' not found", path
);
2437 monitor_printf(mon
, "Warning: Path '%s' is ambiguous\n", path
);
2439 object_property_parse(obj
, value
, property
, &err
);
2441 hmp_handle_error(mon
, &err
);
2444 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
2446 const char *name
= qdict_get_str(qdict
, "name");
2447 RockerSwitch
*rocker
;
2450 rocker
= qmp_query_rocker(name
, &err
);
2452 hmp_handle_error(mon
, &err
);
2456 monitor_printf(mon
, "name: %s\n", rocker
->name
);
2457 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
2458 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
2460 qapi_free_RockerSwitch(rocker
);
2463 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
2465 RockerPortList
*list
, *port
;
2466 const char *name
= qdict_get_str(qdict
, "name");
2469 list
= qmp_query_rocker_ports(name
, &err
);
2471 hmp_handle_error(mon
, &err
);
2475 monitor_printf(mon
, " ena/ speed/ auto\n");
2476 monitor_printf(mon
, " port link duplex neg?\n");
2478 for (port
= list
; port
; port
= port
->next
) {
2479 monitor_printf(mon
, "%10s %-4s %-3s %2s %-3s\n",
2481 port
->value
->enabled
? port
->value
->link_up
?
2482 "up" : "down" : "!ena",
2483 port
->value
->speed
== 10000 ? "10G" : "??",
2484 port
->value
->duplex
? "FD" : "HD",
2485 port
->value
->autoneg
? "Yes" : "No");
2488 qapi_free_RockerPortList(list
);
2491 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
2493 RockerOfDpaFlowList
*list
, *info
;
2494 const char *name
= qdict_get_str(qdict
, "name");
2495 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
2498 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
2500 hmp_handle_error(mon
, &err
);
2504 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
2506 for (info
= list
; info
; info
= info
->next
) {
2507 RockerOfDpaFlow
*flow
= info
->value
;
2508 RockerOfDpaFlowKey
*key
= flow
->key
;
2509 RockerOfDpaFlowMask
*mask
= flow
->mask
;
2510 RockerOfDpaFlowAction
*action
= flow
->action
;
2513 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
2514 key
->priority
, key
->tbl_id
, flow
->hits
);
2516 monitor_printf(mon
, "%-4d %-3d ",
2517 key
->priority
, key
->tbl_id
);
2520 if (key
->has_in_pport
) {
2521 monitor_printf(mon
, " pport %d", key
->in_pport
);
2522 if (mask
->has_in_pport
) {
2523 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2527 if (key
->has_vlan_id
) {
2528 monitor_printf(mon
, " vlan %d",
2529 key
->vlan_id
& VLAN_VID_MASK
);
2530 if (mask
->has_vlan_id
) {
2531 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2535 if (key
->has_tunnel_id
) {
2536 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2537 if (mask
->has_tunnel_id
) {
2538 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2542 if (key
->has_eth_type
) {
2543 switch (key
->eth_type
) {
2545 monitor_printf(mon
, " ARP");
2548 monitor_printf(mon
, " IP");
2551 monitor_printf(mon
, " IPv6");
2554 monitor_printf(mon
, " LACP");
2557 monitor_printf(mon
, " LLDP");
2560 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2565 if (key
->has_eth_src
) {
2566 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2567 (mask
->has_eth_src
) &&
2568 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2569 monitor_printf(mon
, " src <any mcast/bcast>");
2570 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2571 (mask
->has_eth_src
) &&
2572 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2573 monitor_printf(mon
, " src <any ucast>");
2575 monitor_printf(mon
, " src %s", key
->eth_src
);
2576 if (mask
->has_eth_src
) {
2577 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2582 if (key
->has_eth_dst
) {
2583 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2584 (mask
->has_eth_dst
) &&
2585 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2586 monitor_printf(mon
, " dst <any mcast/bcast>");
2587 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2588 (mask
->has_eth_dst
) &&
2589 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2590 monitor_printf(mon
, " dst <any ucast>");
2592 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2593 if (mask
->has_eth_dst
) {
2594 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2599 if (key
->has_ip_proto
) {
2600 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2601 if (mask
->has_ip_proto
) {
2602 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2606 if (key
->has_ip_tos
) {
2607 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2608 if (mask
->has_ip_tos
) {
2609 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2613 if (key
->has_ip_dst
) {
2614 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2617 if (action
->has_goto_tbl
|| action
->has_group_id
||
2618 action
->has_new_vlan_id
) {
2619 monitor_printf(mon
, " -->");
2622 if (action
->has_new_vlan_id
) {
2623 monitor_printf(mon
, " apply new vlan %d",
2624 ntohs(action
->new_vlan_id
));
2627 if (action
->has_group_id
) {
2628 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2631 if (action
->has_goto_tbl
) {
2632 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2635 monitor_printf(mon
, "\n");
2638 qapi_free_RockerOfDpaFlowList(list
);
2641 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2643 RockerOfDpaGroupList
*list
, *g
;
2644 const char *name
= qdict_get_str(qdict
, "name");
2645 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2649 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
2651 hmp_handle_error(mon
, &err
);
2655 monitor_printf(mon
, "id (decode) --> buckets\n");
2657 for (g
= list
; g
; g
= g
->next
) {
2658 RockerOfDpaGroup
*group
= g
->value
;
2660 monitor_printf(mon
, "0x%08x", group
->id
);
2662 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2663 group
->type
== 1 ? "L2 rewrite" :
2664 group
->type
== 2 ? "L3 unicast" :
2665 group
->type
== 3 ? "L2 multicast" :
2666 group
->type
== 4 ? "L2 flood" :
2667 group
->type
== 5 ? "L3 interface" :
2668 group
->type
== 6 ? "L3 multicast" :
2669 group
->type
== 7 ? "L3 ECMP" :
2670 group
->type
== 8 ? "L2 overlay" :
2673 if (group
->has_vlan_id
) {
2674 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2677 if (group
->has_pport
) {
2678 monitor_printf(mon
, " pport %d", group
->pport
);
2681 if (group
->has_index
) {
2682 monitor_printf(mon
, " index %d", group
->index
);
2685 monitor_printf(mon
, ") -->");
2687 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2689 monitor_printf(mon
, " set vlan %d",
2690 group
->set_vlan_id
& VLAN_VID_MASK
);
2693 if (group
->has_set_eth_src
) {
2696 monitor_printf(mon
, " set");
2698 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2701 if (group
->has_set_eth_dst
) {
2704 monitor_printf(mon
, " set");
2706 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2711 if (group
->has_ttl_check
&& group
->ttl_check
) {
2712 monitor_printf(mon
, " check TTL");
2715 if (group
->has_group_id
&& group
->group_id
) {
2716 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2719 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2720 monitor_printf(mon
, " pop vlan");
2723 if (group
->has_out_pport
) {
2724 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2727 if (group
->has_group_ids
) {
2728 struct uint32List
*id
;
2730 monitor_printf(mon
, " groups [");
2731 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2732 monitor_printf(mon
, "0x%08x", id
->value
);
2734 monitor_printf(mon
, ",");
2737 monitor_printf(mon
, "]");
2740 monitor_printf(mon
, "\n");
2743 qapi_free_RockerOfDpaGroupList(list
);
2746 void hmp_info_dump(Monitor
*mon
, const QDict
*qdict
)
2748 DumpQueryResult
*result
= qmp_query_dump(NULL
);
2750 assert(result
&& result
->status
< DUMP_STATUS__MAX
);
2751 monitor_printf(mon
, "Status: %s\n", DumpStatus_lookup
[result
->status
]);
2753 if (result
->status
== DUMP_STATUS_ACTIVE
) {
2755 assert(result
->total
!= 0);
2756 percent
= 100.0 * result
->completed
/ result
->total
;
2757 monitor_printf(mon
, "Finished: %.2f %%\n", percent
);
2760 qapi_free_DumpQueryResult(result
);
2763 void hmp_info_ramblock(Monitor
*mon
, const QDict
*qdict
)
2765 ram_block_dump(mon
);
2768 void hmp_hotpluggable_cpus(Monitor
*mon
, const QDict
*qdict
)
2771 HotpluggableCPUList
*l
= qmp_query_hotpluggable_cpus(&err
);
2772 HotpluggableCPUList
*saved
= l
;
2773 CpuInstanceProperties
*c
;
2776 hmp_handle_error(mon
, &err
);
2780 monitor_printf(mon
, "Hotpluggable CPUs:\n");
2782 monitor_printf(mon
, " type: \"%s\"\n", l
->value
->type
);
2783 monitor_printf(mon
, " vcpus_count: \"%" PRIu64
"\"\n",
2784 l
->value
->vcpus_count
);
2785 if (l
->value
->has_qom_path
) {
2786 monitor_printf(mon
, " qom_path: \"%s\"\n", l
->value
->qom_path
);
2789 c
= l
->value
->props
;
2790 monitor_printf(mon
, " CPUInstance Properties:\n");
2791 if (c
->has_node_id
) {
2792 monitor_printf(mon
, " node-id: \"%" PRIu64
"\"\n", c
->node_id
);
2794 if (c
->has_socket_id
) {
2795 monitor_printf(mon
, " socket-id: \"%" PRIu64
"\"\n", c
->socket_id
);
2797 if (c
->has_core_id
) {
2798 monitor_printf(mon
, " core-id: \"%" PRIu64
"\"\n", c
->core_id
);
2800 if (c
->has_thread_id
) {
2801 monitor_printf(mon
, " thread-id: \"%" PRIu64
"\"\n", c
->thread_id
);
2807 qapi_free_HotpluggableCPUList(saved
);
2810 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
2813 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
2815 monitor_printf(mon
, "%s\n", info
->guid
);
2817 hmp_handle_error(mon
, &err
);
2818 qapi_free_GuidInfo(info
);