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 "sysemu/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-output-visitor.h"
33 #include "qapi/util.h"
34 #include "qapi-visit.h"
35 #include "qom/object_interfaces.h"
36 #include "ui/console.h"
37 #include "block/nbd.h"
38 #include "block/qapi.h"
40 #include "qemu/cutils.h"
41 #include "qemu/error-report.h"
42 #include "exec/ramlist.h"
43 #include "hw/intc/intc.h"
46 #include <spice/enums.h>
49 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
53 error_report_err(*errp
);
57 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
61 info
= qmp_query_name(NULL
);
63 monitor_printf(mon
, "%s\n", info
->name
);
65 qapi_free_NameInfo(info
);
68 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
72 info
= qmp_query_version(NULL
);
74 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
75 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
78 qapi_free_VersionInfo(info
);
81 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
85 info
= qmp_query_kvm(NULL
);
86 monitor_printf(mon
, "kvm support: ");
88 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
90 monitor_printf(mon
, "not compiled\n");
93 qapi_free_KvmInfo(info
);
96 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
100 info
= qmp_query_status(NULL
);
102 monitor_printf(mon
, "VM status: %s%s",
103 info
->running
? "running" : "paused",
104 info
->singlestep
? " (single step mode)" : "");
106 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
107 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
110 monitor_printf(mon
, "\n");
112 qapi_free_StatusInfo(info
);
115 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
119 info
= qmp_query_uuid(NULL
);
120 monitor_printf(mon
, "%s\n", info
->UUID
);
121 qapi_free_UuidInfo(info
);
124 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
126 ChardevInfoList
*char_info
, *info
;
128 char_info
= qmp_query_chardev(NULL
);
129 for (info
= char_info
; info
; info
= info
->next
) {
130 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
131 info
->value
->filename
);
134 qapi_free_ChardevInfoList(char_info
);
137 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
139 MouseInfoList
*mice_list
, *mouse
;
141 mice_list
= qmp_query_mice(NULL
);
143 monitor_printf(mon
, "No mouse devices connected\n");
147 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
148 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
149 mouse
->value
->current
? '*' : ' ',
150 mouse
->value
->index
, mouse
->value
->name
,
151 mouse
->value
->absolute
? " (absolute)" : "");
154 qapi_free_MouseInfoList(mice_list
);
157 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
160 MigrationCapabilityStatusList
*caps
, *cap
;
162 info
= qmp_query_migrate(NULL
);
163 caps
= qmp_query_migrate_capabilities(NULL
);
165 /* do not display parameters during setup */
166 if (info
->has_status
&& caps
) {
167 monitor_printf(mon
, "capabilities: ");
168 for (cap
= caps
; cap
; cap
= cap
->next
) {
169 monitor_printf(mon
, "%s: %s ",
170 MigrationCapability_lookup
[cap
->value
->capability
],
171 cap
->value
->state
? "on" : "off");
173 monitor_printf(mon
, "\n");
176 if (info
->has_status
) {
177 monitor_printf(mon
, "Migration status: %s",
178 MigrationStatus_lookup
[info
->status
]);
179 if (info
->status
== MIGRATION_STATUS_FAILED
&&
180 info
->has_error_desc
) {
181 monitor_printf(mon
, " (%s)\n", info
->error_desc
);
183 monitor_printf(mon
, "\n");
186 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
188 if (info
->has_expected_downtime
) {
189 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
190 info
->expected_downtime
);
192 if (info
->has_downtime
) {
193 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
196 if (info
->has_setup_time
) {
197 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
203 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
204 info
->ram
->transferred
>> 10);
205 monitor_printf(mon
, "throughput: %0.2f mbps\n",
207 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
208 info
->ram
->remaining
>> 10);
209 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
210 info
->ram
->total
>> 10);
211 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
212 info
->ram
->duplicate
);
213 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
215 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
217 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
218 info
->ram
->normal_bytes
>> 10);
219 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
220 info
->ram
->dirty_sync_count
);
221 monitor_printf(mon
, "page size: %" PRIu64
" kbytes\n",
222 info
->ram
->page_size
>> 10);
224 if (info
->ram
->dirty_pages_rate
) {
225 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
226 info
->ram
->dirty_pages_rate
);
228 if (info
->ram
->postcopy_requests
) {
229 monitor_printf(mon
, "postcopy request count: %" PRIu64
"\n",
230 info
->ram
->postcopy_requests
);
234 if (info
->has_disk
) {
235 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
236 info
->disk
->transferred
>> 10);
237 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
238 info
->disk
->remaining
>> 10);
239 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
240 info
->disk
->total
>> 10);
243 if (info
->has_xbzrle_cache
) {
244 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
245 info
->xbzrle_cache
->cache_size
);
246 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
247 info
->xbzrle_cache
->bytes
>> 10);
248 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
249 info
->xbzrle_cache
->pages
);
250 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
251 info
->xbzrle_cache
->cache_miss
);
252 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
253 info
->xbzrle_cache
->cache_miss_rate
);
254 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
255 info
->xbzrle_cache
->overflow
);
258 if (info
->has_cpu_throttle_percentage
) {
259 monitor_printf(mon
, "cpu throttle percentage: %" PRIu64
"\n",
260 info
->cpu_throttle_percentage
);
263 qapi_free_MigrationInfo(info
);
264 qapi_free_MigrationCapabilityStatusList(caps
);
267 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
269 MigrationCapabilityStatusList
*caps
, *cap
;
271 caps
= qmp_query_migrate_capabilities(NULL
);
274 for (cap
= caps
; cap
; cap
= cap
->next
) {
275 monitor_printf(mon
, "%s: %s\n",
276 MigrationCapability_lookup
[cap
->value
->capability
],
277 cap
->value
->state
? "on" : "off");
281 qapi_free_MigrationCapabilityStatusList(caps
);
284 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
286 MigrationParameters
*params
;
288 params
= qmp_query_migrate_parameters(NULL
);
291 assert(params
->has_compress_level
);
292 monitor_printf(mon
, "%s: %" PRId64
"\n",
293 MigrationParameter_lookup
[MIGRATION_PARAMETER_COMPRESS_LEVEL
],
294 params
->compress_level
);
295 assert(params
->has_compress_threads
);
296 monitor_printf(mon
, "%s: %" PRId64
"\n",
297 MigrationParameter_lookup
[MIGRATION_PARAMETER_COMPRESS_THREADS
],
298 params
->compress_threads
);
299 assert(params
->has_decompress_threads
);
300 monitor_printf(mon
, "%s: %" PRId64
"\n",
301 MigrationParameter_lookup
[MIGRATION_PARAMETER_DECOMPRESS_THREADS
],
302 params
->decompress_threads
);
303 assert(params
->has_cpu_throttle_initial
);
304 monitor_printf(mon
, "%s: %" PRId64
"\n",
305 MigrationParameter_lookup
[MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
],
306 params
->cpu_throttle_initial
);
307 assert(params
->has_cpu_throttle_increment
);
308 monitor_printf(mon
, "%s: %" PRId64
"\n",
309 MigrationParameter_lookup
[MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
],
310 params
->cpu_throttle_increment
);
311 monitor_printf(mon
, "%s: '%s'\n",
312 MigrationParameter_lookup
[MIGRATION_PARAMETER_TLS_CREDS
],
313 params
->has_tls_creds
? params
->tls_creds
: "");
314 monitor_printf(mon
, "%s: '%s'\n",
315 MigrationParameter_lookup
[MIGRATION_PARAMETER_TLS_HOSTNAME
],
316 params
->has_tls_hostname
? params
->tls_hostname
: "");
317 assert(params
->has_max_bandwidth
);
318 monitor_printf(mon
, "%s: %" PRId64
" bytes/second\n",
319 MigrationParameter_lookup
[MIGRATION_PARAMETER_MAX_BANDWIDTH
],
320 params
->max_bandwidth
);
321 assert(params
->has_downtime_limit
);
322 monitor_printf(mon
, "%s: %" PRId64
" milliseconds\n",
323 MigrationParameter_lookup
[MIGRATION_PARAMETER_DOWNTIME_LIMIT
],
324 params
->downtime_limit
);
325 assert(params
->has_x_checkpoint_delay
);
326 monitor_printf(mon
, "%s: %" PRId64
"\n",
327 MigrationParameter_lookup
[MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
],
328 params
->x_checkpoint_delay
);
331 qapi_free_MigrationParameters(params
);
334 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
336 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
337 qmp_query_migrate_cache_size(NULL
) >> 10);
340 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
342 CpuInfoList
*cpu_list
, *cpu
;
344 cpu_list
= qmp_query_cpus(NULL
);
346 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
349 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
353 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
355 switch (cpu
->value
->arch
) {
356 case CPU_INFO_ARCH_X86
:
357 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->u
.x86
.pc
);
359 case CPU_INFO_ARCH_PPC
:
360 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->u
.ppc
.nip
);
362 case CPU_INFO_ARCH_SPARC
:
363 monitor_printf(mon
, " pc=0x%016" PRIx64
,
364 cpu
->value
->u
.q_sparc
.pc
);
365 monitor_printf(mon
, " npc=0x%016" PRIx64
,
366 cpu
->value
->u
.q_sparc
.npc
);
368 case CPU_INFO_ARCH_MIPS
:
369 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.q_mips
.PC
);
371 case CPU_INFO_ARCH_TRICORE
:
372 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.tricore
.PC
);
378 if (cpu
->value
->halted
) {
379 monitor_printf(mon
, " (halted)");
382 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
385 qapi_free_CpuInfoList(cpu_list
);
388 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
389 BlockDeviceInfo
*inserted
, bool verbose
)
391 ImageInfo
*image_info
;
393 assert(!info
|| !info
->has_inserted
|| info
->inserted
== inserted
);
396 monitor_printf(mon
, "%s", info
->device
);
397 if (inserted
&& inserted
->has_node_name
) {
398 monitor_printf(mon
, " (%s)", inserted
->node_name
);
402 monitor_printf(mon
, "%s",
403 inserted
->has_node_name
404 ? inserted
->node_name
409 monitor_printf(mon
, ": %s (%s%s%s)\n",
412 inserted
->ro
? ", read-only" : "",
413 inserted
->encrypted
? ", encrypted" : "");
415 monitor_printf(mon
, ": [not inserted]\n");
419 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
420 monitor_printf(mon
, " I/O status: %s\n",
421 BlockDeviceIoStatus_lookup
[info
->io_status
]);
424 if (info
->removable
) {
425 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
426 info
->locked
? "" : "not ",
427 info
->tray_open
? "open" : "closed");
436 monitor_printf(mon
, " Cache mode: %s%s%s\n",
437 inserted
->cache
->writeback
? "writeback" : "writethrough",
438 inserted
->cache
->direct
? ", direct" : "",
439 inserted
->cache
->no_flush
? ", ignore flushes" : "");
441 if (inserted
->has_backing_file
) {
444 "(chain depth: %" PRId64
")\n",
445 inserted
->backing_file
,
446 inserted
->backing_file_depth
);
449 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
450 monitor_printf(mon
, " Detect zeroes: %s\n",
451 BlockdevDetectZeroesOptions_lookup
[inserted
->detect_zeroes
]);
454 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
455 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
457 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
458 " bps_rd=%" PRId64
" bps_wr=%" PRId64
460 " bps_rd_max=%" PRId64
461 " bps_wr_max=%" PRId64
462 " iops=%" PRId64
" iops_rd=%" PRId64
465 " iops_rd_max=%" PRId64
466 " iops_wr_max=%" PRId64
467 " iops_size=%" PRId64
473 inserted
->bps_rd_max
,
474 inserted
->bps_wr_max
,
479 inserted
->iops_rd_max
,
480 inserted
->iops_wr_max
,
486 monitor_printf(mon
, "\nImages:\n");
487 image_info
= inserted
->image
;
489 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
491 if (image_info
->has_backing_image
) {
492 image_info
= image_info
->backing_image
;
500 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
502 BlockInfoList
*block_list
, *info
;
503 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
504 const char *device
= qdict_get_try_str(qdict
, "device");
505 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
506 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
507 bool printed
= false;
509 /* Print BlockBackend information */
511 block_list
= qmp_query_block(NULL
);
516 for (info
= block_list
; info
; info
= info
->next
) {
517 if (device
&& strcmp(device
, info
->value
->device
)) {
521 if (info
!= block_list
) {
522 monitor_printf(mon
, "\n");
525 print_block_info(mon
, info
->value
, info
->value
->has_inserted
526 ? info
->value
->inserted
: NULL
,
531 qapi_free_BlockInfoList(block_list
);
533 if ((!device
&& !nodes
) || printed
) {
537 /* Print node information */
538 blockdev_list
= qmp_query_named_block_nodes(NULL
);
539 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
540 assert(blockdev
->value
->has_node_name
);
541 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
545 if (blockdev
!= blockdev_list
) {
546 monitor_printf(mon
, "\n");
549 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
551 qapi_free_BlockDeviceInfoList(blockdev_list
);
554 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
556 BlockStatsList
*stats_list
, *stats
;
558 stats_list
= qmp_query_blockstats(false, false, NULL
);
560 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
561 if (!stats
->value
->has_device
) {
565 monitor_printf(mon
, "%s:", stats
->value
->device
);
566 monitor_printf(mon
, " rd_bytes=%" PRId64
568 " rd_operations=%" PRId64
569 " wr_operations=%" PRId64
570 " flush_operations=%" PRId64
571 " wr_total_time_ns=%" PRId64
572 " rd_total_time_ns=%" PRId64
573 " flush_total_time_ns=%" PRId64
574 " rd_merged=%" PRId64
575 " wr_merged=%" PRId64
576 " idle_time_ns=%" PRId64
578 stats
->value
->stats
->rd_bytes
,
579 stats
->value
->stats
->wr_bytes
,
580 stats
->value
->stats
->rd_operations
,
581 stats
->value
->stats
->wr_operations
,
582 stats
->value
->stats
->flush_operations
,
583 stats
->value
->stats
->wr_total_time_ns
,
584 stats
->value
->stats
->rd_total_time_ns
,
585 stats
->value
->stats
->flush_total_time_ns
,
586 stats
->value
->stats
->rd_merged
,
587 stats
->value
->stats
->wr_merged
,
588 stats
->value
->stats
->idle_time_ns
);
591 qapi_free_BlockStatsList(stats_list
);
594 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
598 VncClientInfoList
*client
;
600 info
= qmp_query_vnc(&err
);
602 error_report_err(err
);
606 if (!info
->enabled
) {
607 monitor_printf(mon
, "Server: disabled\n");
611 monitor_printf(mon
, "Server:\n");
612 if (info
->has_host
&& info
->has_service
) {
613 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
615 if (info
->has_auth
) {
616 monitor_printf(mon
, " auth: %s\n", info
->auth
);
619 if (!info
->has_clients
|| info
->clients
== NULL
) {
620 monitor_printf(mon
, "Client: none\n");
622 for (client
= info
->clients
; client
; client
= client
->next
) {
623 monitor_printf(mon
, "Client:\n");
624 monitor_printf(mon
, " address: %s:%s\n",
626 client
->value
->service
);
627 monitor_printf(mon
, " x509_dname: %s\n",
628 client
->value
->x509_dname
?
629 client
->value
->x509_dname
: "none");
630 monitor_printf(mon
, " username: %s\n",
631 client
->value
->has_sasl_username
?
632 client
->value
->sasl_username
: "none");
637 qapi_free_VncInfo(info
);
641 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
643 SpiceChannelList
*chan
;
645 const char *channel_name
;
646 const char * const channel_names
[] = {
647 [SPICE_CHANNEL_MAIN
] = "main",
648 [SPICE_CHANNEL_DISPLAY
] = "display",
649 [SPICE_CHANNEL_INPUTS
] = "inputs",
650 [SPICE_CHANNEL_CURSOR
] = "cursor",
651 [SPICE_CHANNEL_PLAYBACK
] = "playback",
652 [SPICE_CHANNEL_RECORD
] = "record",
653 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
654 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
655 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
656 [SPICE_CHANNEL_PORT
] = "port",
658 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
659 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
660 * as quick fix for build failures with older versions. */
661 [SPICE_CHANNEL_WEBDAV
] = "webdav",
665 info
= qmp_query_spice(NULL
);
667 if (!info
->enabled
) {
668 monitor_printf(mon
, "Server: disabled\n");
672 monitor_printf(mon
, "Server:\n");
673 if (info
->has_port
) {
674 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
675 info
->host
, info
->port
);
677 if (info
->has_tls_port
) {
678 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
679 info
->host
, info
->tls_port
);
681 monitor_printf(mon
, " migrated: %s\n",
682 info
->migrated
? "true" : "false");
683 monitor_printf(mon
, " auth: %s\n", info
->auth
);
684 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
685 monitor_printf(mon
, " mouse-mode: %s\n",
686 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
688 if (!info
->has_channels
|| info
->channels
== NULL
) {
689 monitor_printf(mon
, "Channels: none\n");
691 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
692 monitor_printf(mon
, "Channel:\n");
693 monitor_printf(mon
, " address: %s:%s%s\n",
694 chan
->value
->host
, chan
->value
->port
,
695 chan
->value
->tls
? " [tls]" : "");
696 monitor_printf(mon
, " session: %" PRId64
"\n",
697 chan
->value
->connection_id
);
698 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
699 chan
->value
->channel_type
, chan
->value
->channel_id
);
701 channel_name
= "unknown";
702 if (chan
->value
->channel_type
> 0 &&
703 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
704 channel_names
[chan
->value
->channel_type
]) {
705 channel_name
= channel_names
[chan
->value
->channel_type
];
708 monitor_printf(mon
, " channel name: %s\n", channel_name
);
713 qapi_free_SpiceInfo(info
);
717 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
722 info
= qmp_query_balloon(&err
);
724 error_report_err(err
);
728 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
730 qapi_free_BalloonInfo(info
);
733 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
735 PciMemoryRegionList
*region
;
737 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
738 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
739 dev
->slot
, dev
->function
);
740 monitor_printf(mon
, " ");
742 if (dev
->class_info
->has_desc
) {
743 monitor_printf(mon
, "%s", dev
->class_info
->desc
);
745 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
748 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
749 dev
->id
->vendor
, dev
->id
->device
);
752 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
755 if (dev
->has_pci_bridge
) {
756 monitor_printf(mon
, " BUS %" PRId64
".\n",
757 dev
->pci_bridge
->bus
->number
);
758 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
759 dev
->pci_bridge
->bus
->secondary
);
760 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
761 dev
->pci_bridge
->bus
->subordinate
);
763 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
764 dev
->pci_bridge
->bus
->io_range
->base
,
765 dev
->pci_bridge
->bus
->io_range
->limit
);
768 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
769 dev
->pci_bridge
->bus
->memory_range
->base
,
770 dev
->pci_bridge
->bus
->memory_range
->limit
);
772 monitor_printf(mon
, " prefetchable memory range "
773 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
774 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
775 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
778 for (region
= dev
->regions
; region
; region
= region
->next
) {
781 addr
= region
->value
->address
;
782 size
= region
->value
->size
;
784 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
786 if (!strcmp(region
->value
->type
, "io")) {
787 monitor_printf(mon
, "I/O at 0x%04" PRIx64
788 " [0x%04" PRIx64
"].\n",
789 addr
, addr
+ size
- 1);
791 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
792 " [0x%08" PRIx64
"].\n",
793 region
->value
->mem_type_64
? 64 : 32,
794 region
->value
->prefetch
? " prefetchable" : "",
795 addr
, addr
+ size
- 1);
799 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
801 if (dev
->has_pci_bridge
) {
802 if (dev
->pci_bridge
->has_devices
) {
803 PciDeviceInfoList
*cdev
;
804 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
805 hmp_info_pci_device(mon
, cdev
->value
);
811 static int hmp_info_irq_foreach(Object
*obj
, void *opaque
)
813 InterruptStatsProvider
*intc
;
814 InterruptStatsProviderClass
*k
;
815 Monitor
*mon
= opaque
;
817 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
818 intc
= INTERRUPT_STATS_PROVIDER(obj
);
819 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
820 uint64_t *irq_counts
;
821 unsigned int nb_irqs
, i
;
822 if (k
->get_statistics
&&
823 k
->get_statistics(intc
, &irq_counts
, &nb_irqs
)) {
825 monitor_printf(mon
, "IRQ statistics for %s:\n",
826 object_get_typename(obj
));
827 for (i
= 0; i
< nb_irqs
; i
++) {
828 if (irq_counts
[i
] > 0) {
829 monitor_printf(mon
, "%2d: %" PRId64
"\n", i
,
835 monitor_printf(mon
, "IRQ statistics not available for %s.\n",
836 object_get_typename(obj
));
843 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
)
845 object_child_foreach_recursive(object_get_root(),
846 hmp_info_irq_foreach
, mon
);
849 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
851 InterruptStatsProvider
*intc
;
852 InterruptStatsProviderClass
*k
;
853 Monitor
*mon
= opaque
;
855 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
856 intc
= INTERRUPT_STATS_PROVIDER(obj
);
857 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
859 k
->print_info(intc
, mon
);
861 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
862 object_get_typename(obj
));
869 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
871 object_child_foreach_recursive(object_get_root(),
872 hmp_info_pic_foreach
, mon
);
875 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
877 PciInfoList
*info_list
, *info
;
880 info_list
= qmp_query_pci(&err
);
882 monitor_printf(mon
, "PCI devices not supported\n");
887 for (info
= info_list
; info
; info
= info
->next
) {
888 PciDeviceInfoList
*dev
;
890 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
891 hmp_info_pci_device(mon
, dev
->value
);
895 qapi_free_PciInfoList(info_list
);
898 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
900 BlockJobInfoList
*list
;
903 list
= qmp_query_block_jobs(&err
);
907 monitor_printf(mon
, "No active jobs\n");
912 if (strcmp(list
->value
->type
, "stream") == 0) {
913 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
914 " of %" PRId64
" bytes, speed limit %" PRId64
921 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
922 " of %" PRId64
" bytes, speed limit %" PRId64
933 qapi_free_BlockJobInfoList(list
);
936 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
938 TPMInfoList
*info_list
, *info
;
941 TPMPassthroughOptions
*tpo
;
943 info_list
= qmp_query_tpm(&err
);
945 monitor_printf(mon
, "TPM device not supported\n");
951 monitor_printf(mon
, "TPM device:\n");
954 for (info
= info_list
; info
; info
= info
->next
) {
955 TPMInfo
*ti
= info
->value
;
956 monitor_printf(mon
, " tpm%d: model=%s\n",
957 c
, TpmModel_lookup
[ti
->model
]);
959 monitor_printf(mon
, " \\ %s: type=%s",
960 ti
->id
, TpmTypeOptionsKind_lookup
[ti
->options
->type
]);
962 switch (ti
->options
->type
) {
963 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
964 tpo
= ti
->options
->u
.passthrough
.data
;
965 monitor_printf(mon
, "%s%s%s%s",
966 tpo
->has_path
? ",path=" : "",
967 tpo
->has_path
? tpo
->path
: "",
968 tpo
->has_cancel_path
? ",cancel-path=" : "",
969 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
971 case TPM_TYPE_OPTIONS_KIND__MAX
:
974 monitor_printf(mon
, "\n");
977 qapi_free_TPMInfoList(info_list
);
980 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
982 monitor_suspend(mon
);
986 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
991 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
993 qmp_system_reset(NULL
);
996 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
998 qmp_system_powerdown(NULL
);
1001 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
1005 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1006 use it are converted to the QAPI */
1007 cpu_index
= qdict_get_int(qdict
, "index");
1008 if (monitor_set_cpu(cpu_index
) < 0) {
1009 monitor_printf(mon
, "invalid CPU index\n");
1013 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
1015 uint32_t size
= qdict_get_int(qdict
, "size");
1016 const char *filename
= qdict_get_str(qdict
, "filename");
1017 uint64_t addr
= qdict_get_int(qdict
, "val");
1019 int cpu_index
= monitor_get_cpu_index();
1021 if (cpu_index
< 0) {
1022 monitor_printf(mon
, "No CPU available\n");
1026 qmp_memsave(addr
, size
, filename
, true, cpu_index
, &err
);
1027 hmp_handle_error(mon
, &err
);
1030 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
1032 uint32_t size
= qdict_get_int(qdict
, "size");
1033 const char *filename
= qdict_get_str(qdict
, "filename");
1034 uint64_t addr
= qdict_get_int(qdict
, "val");
1037 qmp_pmemsave(addr
, size
, filename
, &err
);
1038 hmp_handle_error(mon
, &err
);
1041 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
1043 const char *chardev
= qdict_get_str(qdict
, "device");
1044 const char *data
= qdict_get_str(qdict
, "data");
1047 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
1049 hmp_handle_error(mon
, &err
);
1052 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
1054 uint32_t size
= qdict_get_int(qdict
, "size");
1055 const char *chardev
= qdict_get_str(qdict
, "device");
1060 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
1062 error_report_err(err
);
1066 for (i
= 0; data
[i
]; i
++) {
1067 unsigned char ch
= data
[i
];
1070 monitor_printf(mon
, "\\\\");
1071 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
1072 monitor_printf(mon
, "\\u%04X", ch
);
1074 monitor_printf(mon
, "%c", ch
);
1078 monitor_printf(mon
, "\n");
1082 static void hmp_cont_cb(void *opaque
, int err
)
1089 static bool key_is_missing(const BlockInfo
*bdev
)
1091 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
1094 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
1096 BlockInfoList
*bdev_list
, *bdev
;
1099 bdev_list
= qmp_query_block(NULL
);
1100 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
1101 if (key_is_missing(bdev
->value
)) {
1102 monitor_read_block_device_key(mon
, bdev
->value
->device
,
1109 hmp_handle_error(mon
, &err
);
1112 qapi_free_BlockInfoList(bdev_list
);
1115 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
1117 qmp_system_wakeup(NULL
);
1120 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
1124 qmp_inject_nmi(&err
);
1125 hmp_handle_error(mon
, &err
);
1128 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
1130 const char *name
= qdict_get_str(qdict
, "name");
1131 bool up
= qdict_get_bool(qdict
, "up");
1134 qmp_set_link(name
, up
, &err
);
1135 hmp_handle_error(mon
, &err
);
1138 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
1140 const char *device
= qdict_get_str(qdict
, "device");
1141 const char *password
= qdict_get_str(qdict
, "password");
1144 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
1145 hmp_handle_error(mon
, &err
);
1148 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1150 int64_t value
= qdict_get_int(qdict
, "value");
1153 qmp_balloon(value
, &err
);
1155 error_report_err(err
);
1159 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
1161 const char *device
= qdict_get_str(qdict
, "device");
1162 int64_t size
= qdict_get_int(qdict
, "size");
1165 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
1166 hmp_handle_error(mon
, &err
);
1169 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
1171 const char *filename
= qdict_get_str(qdict
, "target");
1172 const char *format
= qdict_get_try_str(qdict
, "format");
1173 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1174 bool full
= qdict_get_try_bool(qdict
, "full", false);
1176 DriveMirror mirror
= {
1177 .device
= (char *)qdict_get_str(qdict
, "device"),
1178 .target
= (char *)filename
,
1179 .has_format
= !!format
,
1180 .format
= (char *)format
,
1181 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1183 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1188 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1189 hmp_handle_error(mon
, &err
);
1192 qmp_drive_mirror(&mirror
, &err
);
1193 hmp_handle_error(mon
, &err
);
1196 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
1198 const char *device
= qdict_get_str(qdict
, "device");
1199 const char *filename
= qdict_get_str(qdict
, "target");
1200 const char *format
= qdict_get_try_str(qdict
, "format");
1201 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1202 bool full
= qdict_get_try_bool(qdict
, "full", false);
1203 bool compress
= qdict_get_try_bool(qdict
, "compress", false);
1205 DriveBackup backup
= {
1206 .device
= (char *)device
,
1207 .target
= (char *)filename
,
1208 .has_format
= !!format
,
1209 .format
= (char *)format
,
1210 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1212 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1213 .has_compress
= !!compress
,
1214 .compress
= compress
,
1218 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1219 hmp_handle_error(mon
, &err
);
1223 qmp_drive_backup(&backup
, &err
);
1224 hmp_handle_error(mon
, &err
);
1227 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
1229 const char *device
= qdict_get_str(qdict
, "device");
1230 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
1231 const char *format
= qdict_get_try_str(qdict
, "format");
1232 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1233 enum NewImageMode mode
;
1237 /* In the future, if 'snapshot-file' is not specified, the snapshot
1238 will be taken internally. Today it's actually required. */
1239 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
1240 hmp_handle_error(mon
, &err
);
1244 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1245 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
1246 filename
, false, NULL
,
1249 hmp_handle_error(mon
, &err
);
1252 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1254 const char *device
= qdict_get_str(qdict
, "device");
1255 const char *name
= qdict_get_str(qdict
, "name");
1258 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1259 hmp_handle_error(mon
, &err
);
1262 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1264 const char *device
= qdict_get_str(qdict
, "device");
1265 const char *name
= qdict_get_str(qdict
, "name");
1266 const char *id
= qdict_get_try_str(qdict
, "id");
1269 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1271 hmp_handle_error(mon
, &err
);
1274 void hmp_loadvm(Monitor
*mon
, const QDict
*qdict
)
1276 int saved_vm_running
= runstate_is_running();
1277 const char *name
= qdict_get_str(qdict
, "name");
1280 vm_stop(RUN_STATE_RESTORE_VM
);
1282 if (load_vmstate(name
, &err
) == 0 && saved_vm_running
) {
1285 hmp_handle_error(mon
, &err
);
1288 void hmp_savevm(Monitor
*mon
, const QDict
*qdict
)
1292 save_vmstate(qdict_get_try_str(qdict
, "name"), &err
);
1293 hmp_handle_error(mon
, &err
);
1296 void hmp_delvm(Monitor
*mon
, const QDict
*qdict
)
1298 BlockDriverState
*bs
;
1300 const char *name
= qdict_get_str(qdict
, "name");
1302 if (bdrv_all_delete_snapshot(name
, &bs
, &err
) < 0) {
1303 error_reportf_err(err
,
1304 "Error while deleting snapshot on device '%s': ",
1305 bdrv_get_device_name(bs
));
1309 void hmp_info_snapshots(Monitor
*mon
, const QDict
*qdict
)
1311 BlockDriverState
*bs
, *bs1
;
1312 BdrvNextIterator it1
;
1313 QEMUSnapshotInfo
*sn_tab
, *sn
;
1314 bool no_snapshot
= true;
1317 int *global_snapshots
;
1318 AioContext
*aio_context
;
1320 typedef struct SnapshotEntry
{
1321 QEMUSnapshotInfo sn
;
1322 QTAILQ_ENTRY(SnapshotEntry
) next
;
1325 typedef struct ImageEntry
{
1326 const char *imagename
;
1327 QTAILQ_ENTRY(ImageEntry
) next
;
1328 QTAILQ_HEAD(, SnapshotEntry
) snapshots
;
1331 QTAILQ_HEAD(, ImageEntry
) image_list
=
1332 QTAILQ_HEAD_INITIALIZER(image_list
);
1334 ImageEntry
*image_entry
, *next_ie
;
1335 SnapshotEntry
*snapshot_entry
;
1337 bs
= bdrv_all_find_vmstate_bs();
1339 monitor_printf(mon
, "No available block device supports snapshots\n");
1342 aio_context
= bdrv_get_aio_context(bs
);
1344 aio_context_acquire(aio_context
);
1345 nb_sns
= bdrv_snapshot_list(bs
, &sn_tab
);
1346 aio_context_release(aio_context
);
1349 monitor_printf(mon
, "bdrv_snapshot_list: error %d\n", nb_sns
);
1353 for (bs1
= bdrv_first(&it1
); bs1
; bs1
= bdrv_next(&it1
)) {
1357 AioContext
*ctx
= bdrv_get_aio_context(bs1
);
1359 aio_context_acquire(ctx
);
1360 if (bdrv_can_snapshot(bs1
)) {
1362 bs1_nb_sns
= bdrv_snapshot_list(bs1
, &sn
);
1363 if (bs1_nb_sns
> 0) {
1364 no_snapshot
= false;
1365 ie
= g_new0(ImageEntry
, 1);
1366 ie
->imagename
= bdrv_get_device_name(bs1
);
1367 QTAILQ_INIT(&ie
->snapshots
);
1368 QTAILQ_INSERT_TAIL(&image_list
, ie
, next
);
1369 for (i
= 0; i
< bs1_nb_sns
; i
++) {
1370 se
= g_new0(SnapshotEntry
, 1);
1372 QTAILQ_INSERT_TAIL(&ie
->snapshots
, se
, next
);
1377 aio_context_release(ctx
);
1381 monitor_printf(mon
, "There is no snapshot available.\n");
1385 global_snapshots
= g_new0(int, nb_sns
);
1387 for (i
= 0; i
< nb_sns
; i
++) {
1388 SnapshotEntry
*next_sn
;
1389 if (bdrv_all_find_snapshot(sn_tab
[i
].name
, &bs1
) == 0) {
1390 global_snapshots
[total
] = i
;
1392 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1393 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
,
1395 if (!strcmp(sn_tab
[i
].name
, snapshot_entry
->sn
.name
)) {
1396 QTAILQ_REMOVE(&image_entry
->snapshots
, snapshot_entry
,
1398 g_free(snapshot_entry
);
1405 monitor_printf(mon
, "List of snapshots present on all disks:\n");
1408 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1409 monitor_printf(mon
, "\n");
1410 for (i
= 0; i
< total
; i
++) {
1411 sn
= &sn_tab
[global_snapshots
[i
]];
1412 /* The ID is not guaranteed to be the same on all images, so
1415 pstrcpy(sn
->id_str
, sizeof(sn
->id_str
), "--");
1416 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, sn
);
1417 monitor_printf(mon
, "\n");
1420 monitor_printf(mon
, "None\n");
1423 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1424 if (QTAILQ_EMPTY(&image_entry
->snapshots
)) {
1428 "\nList of partial (non-loadable) snapshots on '%s':\n",
1429 image_entry
->imagename
);
1430 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1431 monitor_printf(mon
, "\n");
1432 QTAILQ_FOREACH(snapshot_entry
, &image_entry
->snapshots
, next
) {
1433 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
,
1434 &snapshot_entry
->sn
);
1435 monitor_printf(mon
, "\n");
1439 QTAILQ_FOREACH_SAFE(image_entry
, &image_list
, next
, next_ie
) {
1440 SnapshotEntry
*next_sn
;
1441 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
, next
,
1443 g_free(snapshot_entry
);
1445 g_free(image_entry
);
1448 g_free(global_snapshots
);
1452 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1454 qmp_migrate_cancel(NULL
);
1457 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1460 const char *uri
= qdict_get_str(qdict
, "uri");
1462 qmp_migrate_incoming(uri
, &err
);
1464 hmp_handle_error(mon
, &err
);
1467 /* Kept for backwards compatibility */
1468 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1470 double value
= qdict_get_double(qdict
, "value");
1471 qmp_migrate_set_downtime(value
, NULL
);
1474 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1476 int64_t value
= qdict_get_int(qdict
, "value");
1479 qmp_migrate_set_cache_size(value
, &err
);
1481 error_report_err(err
);
1486 /* Kept for backwards compatibility */
1487 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1489 int64_t value
= qdict_get_int(qdict
, "value");
1490 qmp_migrate_set_speed(value
, NULL
);
1493 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1495 const char *cap
= qdict_get_str(qdict
, "capability");
1496 bool state
= qdict_get_bool(qdict
, "state");
1498 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1501 for (i
= 0; i
< MIGRATION_CAPABILITY__MAX
; i
++) {
1502 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
1503 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1504 caps
->value
->capability
= i
;
1505 caps
->value
->state
= state
;
1507 qmp_migrate_set_capabilities(caps
, &err
);
1512 if (i
== MIGRATION_CAPABILITY__MAX
) {
1513 error_setg(&err
, QERR_INVALID_PARAMETER
, cap
);
1516 qapi_free_MigrationCapabilityStatusList(caps
);
1519 error_report_err(err
);
1523 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1525 const char *param
= qdict_get_str(qdict
, "parameter");
1526 const char *valuestr
= qdict_get_str(qdict
, "value");
1527 uint64_t valuebw
= 0;
1530 bool use_int_value
= false;
1533 for (i
= 0; i
< MIGRATION_PARAMETER__MAX
; i
++) {
1534 if (strcmp(param
, MigrationParameter_lookup
[i
]) == 0) {
1535 MigrationParameters p
= { 0 };
1537 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1538 p
.has_compress_level
= true;
1539 use_int_value
= true;
1541 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1542 p
.has_compress_threads
= true;
1543 use_int_value
= true;
1545 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1546 p
.has_decompress_threads
= true;
1547 use_int_value
= true;
1549 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1550 p
.has_cpu_throttle_initial
= true;
1551 use_int_value
= true;
1553 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1554 p
.has_cpu_throttle_increment
= true;
1555 use_int_value
= true;
1557 case MIGRATION_PARAMETER_TLS_CREDS
:
1558 p
.has_tls_creds
= true;
1559 p
.tls_creds
= (char *) valuestr
;
1561 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1562 p
.has_tls_hostname
= true;
1563 p
.tls_hostname
= (char *) valuestr
;
1565 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1566 p
.has_max_bandwidth
= true;
1567 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
1568 if (ret
< 0 || valuebw
> INT64_MAX
1569 || (size_t)valuebw
!= valuebw
) {
1570 error_setg(&err
, "Invalid size %s", valuestr
);
1573 p
.max_bandwidth
= valuebw
;
1575 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1576 p
.has_downtime_limit
= true;
1577 use_int_value
= true;
1579 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
1580 p
.has_x_checkpoint_delay
= true;
1581 use_int_value
= true;
1585 if (use_int_value
) {
1586 if (qemu_strtol(valuestr
, NULL
, 10, &valueint
) < 0) {
1587 error_setg(&err
, "Unable to parse '%s' as an int",
1591 /* Set all integers; only one has_FOO will be set, and
1592 * the code ignores the remaining values */
1593 p
.compress_level
= valueint
;
1594 p
.compress_threads
= valueint
;
1595 p
.decompress_threads
= valueint
;
1596 p
.cpu_throttle_initial
= valueint
;
1597 p
.cpu_throttle_increment
= valueint
;
1598 p
.downtime_limit
= valueint
;
1599 p
.x_checkpoint_delay
= valueint
;
1602 qmp_migrate_set_parameters(&p
, &err
);
1607 if (i
== MIGRATION_PARAMETER__MAX
) {
1608 error_setg(&err
, QERR_INVALID_PARAMETER
, param
);
1613 error_report_err(err
);
1617 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1620 const char *protocol
= qdict_get_str(qdict
, "protocol");
1621 const char *hostname
= qdict_get_str(qdict
, "hostname");
1622 bool has_port
= qdict_haskey(qdict
, "port");
1623 int port
= qdict_get_try_int(qdict
, "port", -1);
1624 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1625 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1626 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1628 qmp_client_migrate_info(protocol
, hostname
,
1629 has_port
, port
, has_tls_port
, tls_port
,
1630 !!cert_subject
, cert_subject
, &err
);
1631 hmp_handle_error(mon
, &err
);
1634 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1637 qmp_migrate_start_postcopy(&err
);
1638 hmp_handle_error(mon
, &err
);
1641 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1645 qmp_x_colo_lost_heartbeat(&err
);
1646 hmp_handle_error(mon
, &err
);
1649 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1651 const char *protocol
= qdict_get_str(qdict
, "protocol");
1652 const char *password
= qdict_get_str(qdict
, "password");
1653 const char *connected
= qdict_get_try_str(qdict
, "connected");
1656 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1657 hmp_handle_error(mon
, &err
);
1660 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1662 const char *protocol
= qdict_get_str(qdict
, "protocol");
1663 const char *whenstr
= qdict_get_str(qdict
, "time");
1666 qmp_expire_password(protocol
, whenstr
, &err
);
1667 hmp_handle_error(mon
, &err
);
1670 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1672 bool force
= qdict_get_try_bool(qdict
, "force", false);
1673 const char *device
= qdict_get_str(qdict
, "device");
1676 qmp_eject(true, device
, false, NULL
, true, force
, &err
);
1677 hmp_handle_error(mon
, &err
);
1680 static void hmp_change_read_arg(void *opaque
, const char *password
,
1681 void *readline_opaque
)
1683 qmp_change_vnc_password(password
, NULL
);
1684 monitor_read_command(opaque
, 1);
1687 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1689 const char *device
= qdict_get_str(qdict
, "device");
1690 const char *target
= qdict_get_str(qdict
, "target");
1691 const char *arg
= qdict_get_try_str(qdict
, "arg");
1692 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1693 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1696 if (strcmp(device
, "vnc") == 0) {
1699 "Parameter 'read-only-mode' is invalid for VNC\n");
1702 if (strcmp(target
, "passwd") == 0 ||
1703 strcmp(target
, "password") == 0) {
1705 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1709 qmp_change("vnc", target
, !!arg
, arg
, &err
);
1713 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup
,
1714 read_only
, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX
,
1715 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1717 hmp_handle_error(mon
, &err
);
1722 qmp_blockdev_change_medium(true, device
, false, NULL
, target
,
1723 !!arg
, arg
, !!read_only
, read_only_mode
,
1726 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
1728 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
1733 hmp_handle_error(mon
, &err
);
1736 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1739 BlockIOThrottle throttle
= {
1741 .device
= (char *) qdict_get_str(qdict
, "device"),
1742 .bps
= qdict_get_int(qdict
, "bps"),
1743 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
1744 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
1745 .iops
= qdict_get_int(qdict
, "iops"),
1746 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
1747 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
1750 qmp_block_set_io_throttle(&throttle
, &err
);
1751 hmp_handle_error(mon
, &err
);
1754 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1756 Error
*error
= NULL
;
1757 const char *device
= qdict_get_str(qdict
, "device");
1758 const char *base
= qdict_get_try_str(qdict
, "base");
1759 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1761 qmp_block_stream(true, device
, device
, base
!= NULL
, base
, false, NULL
,
1762 false, NULL
, qdict_haskey(qdict
, "speed"), speed
,
1763 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1765 hmp_handle_error(mon
, &error
);
1768 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1770 Error
*error
= NULL
;
1771 const char *device
= qdict_get_str(qdict
, "device");
1772 int64_t value
= qdict_get_int(qdict
, "speed");
1774 qmp_block_job_set_speed(device
, value
, &error
);
1776 hmp_handle_error(mon
, &error
);
1779 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1781 Error
*error
= NULL
;
1782 const char *device
= qdict_get_str(qdict
, "device");
1783 bool force
= qdict_get_try_bool(qdict
, "force", false);
1785 qmp_block_job_cancel(device
, true, force
, &error
);
1787 hmp_handle_error(mon
, &error
);
1790 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1792 Error
*error
= NULL
;
1793 const char *device
= qdict_get_str(qdict
, "device");
1795 qmp_block_job_pause(device
, &error
);
1797 hmp_handle_error(mon
, &error
);
1800 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1802 Error
*error
= NULL
;
1803 const char *device
= qdict_get_str(qdict
, "device");
1805 qmp_block_job_resume(device
, &error
);
1807 hmp_handle_error(mon
, &error
);
1810 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1812 Error
*error
= NULL
;
1813 const char *device
= qdict_get_str(qdict
, "device");
1815 qmp_block_job_complete(device
, &error
);
1817 hmp_handle_error(mon
, &error
);
1820 typedef struct HMPMigrationStatus
1824 bool is_block_migration
;
1825 } HMPMigrationStatus
;
1827 static void hmp_migrate_status_cb(void *opaque
)
1829 HMPMigrationStatus
*status
= opaque
;
1830 MigrationInfo
*info
;
1832 info
= qmp_query_migrate(NULL
);
1833 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1834 info
->status
== MIGRATION_STATUS_SETUP
) {
1835 if (info
->has_disk
) {
1838 if (info
->disk
->remaining
) {
1839 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1844 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1845 monitor_flush(status
->mon
);
1848 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1850 if (status
->is_block_migration
) {
1851 monitor_printf(status
->mon
, "\n");
1853 if (info
->has_error_desc
) {
1854 error_report("%s", info
->error_desc
);
1856 monitor_resume(status
->mon
);
1857 timer_del(status
->timer
);
1861 qapi_free_MigrationInfo(info
);
1864 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1866 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1867 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1868 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1869 const char *uri
= qdict_get_str(qdict
, "uri");
1872 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1874 error_report_err(err
);
1879 HMPMigrationStatus
*status
;
1881 if (monitor_suspend(mon
) < 0) {
1882 monitor_printf(mon
, "terminal does not allow synchronous "
1883 "migration, continuing detached\n");
1887 status
= g_malloc0(sizeof(*status
));
1889 status
->is_block_migration
= blk
|| inc
;
1890 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1892 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1896 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
1900 qmp_device_add((QDict
*)qdict
, NULL
, &err
);
1901 hmp_handle_error(mon
, &err
);
1904 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1906 const char *id
= qdict_get_str(qdict
, "id");
1909 qmp_device_del(id
, &err
);
1910 hmp_handle_error(mon
, &err
);
1913 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1916 bool paging
= qdict_get_try_bool(qdict
, "paging", false);
1917 bool zlib
= qdict_get_try_bool(qdict
, "zlib", false);
1918 bool lzo
= qdict_get_try_bool(qdict
, "lzo", false);
1919 bool snappy
= qdict_get_try_bool(qdict
, "snappy", false);
1920 const char *file
= qdict_get_str(qdict
, "filename");
1921 bool has_begin
= qdict_haskey(qdict
, "begin");
1922 bool has_length
= qdict_haskey(qdict
, "length");
1923 bool has_detach
= qdict_haskey(qdict
, "detach");
1926 bool detach
= false;
1927 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1930 if (zlib
+ lzo
+ snappy
> 1) {
1931 error_setg(&err
, "only one of '-z|-l|-s' can be set");
1932 hmp_handle_error(mon
, &err
);
1937 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
1941 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
1945 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
1949 begin
= qdict_get_int(qdict
, "begin");
1952 length
= qdict_get_int(qdict
, "length");
1955 detach
= qdict_get_bool(qdict
, "detach");
1958 prot
= g_strconcat("file:", file
, NULL
);
1960 qmp_dump_guest_memory(paging
, prot
, true, detach
, has_begin
, begin
,
1961 has_length
, length
, true, dump_format
, &err
);
1962 hmp_handle_error(mon
, &err
);
1966 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1971 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1976 netdev_add(opts
, &err
);
1978 qemu_opts_del(opts
);
1982 hmp_handle_error(mon
, &err
);
1985 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1987 const char *id
= qdict_get_str(qdict
, "id");
1990 qmp_netdev_del(id
, &err
);
1991 hmp_handle_error(mon
, &err
);
1994 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
2000 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
2002 hmp_handle_error(mon
, &err
);
2006 obj
= user_creatable_add_opts(opts
, &err
);
2007 qemu_opts_del(opts
);
2010 hmp_handle_error(mon
, &err
);
2017 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
2019 const char *fdname
= qdict_get_str(qdict
, "fdname");
2022 qmp_getfd(fdname
, &err
);
2023 hmp_handle_error(mon
, &err
);
2026 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
2028 const char *fdname
= qdict_get_str(qdict
, "fdname");
2031 qmp_closefd(fdname
, &err
);
2032 hmp_handle_error(mon
, &err
);
2035 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
2037 const char *keys
= qdict_get_str(qdict
, "keys");
2038 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
2039 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
2040 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
2046 separator
= strchr(keys
, '-');
2047 keyname_len
= separator
? separator
- keys
: strlen(keys
);
2049 /* Be compatible with old interface, convert user inputted "<" */
2050 if (keys
[0] == '<' && keyname_len
== 1) {
2055 keylist
= g_malloc0(sizeof(*keylist
));
2056 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
2062 tmp
->next
= keylist
;
2066 if (strstart(keys
, "0x", NULL
)) {
2068 int value
= strtoul(keys
, &endp
, 0);
2069 assert(endp
<= keys
+ keyname_len
);
2070 if (endp
!= keys
+ keyname_len
) {
2073 keylist
->value
->type
= KEY_VALUE_KIND_NUMBER
;
2074 keylist
->value
->u
.number
.data
= value
;
2076 int idx
= index_from_key(keys
, keyname_len
);
2077 if (idx
== Q_KEY_CODE__MAX
) {
2080 keylist
->value
->type
= KEY_VALUE_KIND_QCODE
;
2081 keylist
->value
->u
.qcode
.data
= idx
;
2087 keys
= separator
+ 1;
2090 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
2091 hmp_handle_error(mon
, &err
);
2094 qapi_free_KeyValueList(head
);
2098 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
2102 void hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
2104 const char *filename
= qdict_get_str(qdict
, "filename");
2107 qmp_screendump(filename
, &err
);
2108 hmp_handle_error(mon
, &err
);
2111 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
2113 const char *uri
= qdict_get_str(qdict
, "uri");
2114 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2115 bool all
= qdict_get_try_bool(qdict
, "all", false);
2116 Error
*local_err
= NULL
;
2117 BlockInfoList
*block_list
, *info
;
2118 SocketAddress
*addr
;
2120 if (writable
&& !all
) {
2121 error_setg(&local_err
, "-w only valid together with -a");
2125 /* First check if the address is valid and start the server. */
2126 addr
= socket_parse(uri
, &local_err
);
2127 if (local_err
!= NULL
) {
2131 nbd_server_start(addr
, NULL
, &local_err
);
2132 qapi_free_SocketAddress(addr
);
2133 if (local_err
!= NULL
) {
2141 /* Then try adding all block devices. If one fails, close all and
2144 block_list
= qmp_query_block(NULL
);
2146 for (info
= block_list
; info
; info
= info
->next
) {
2147 if (!info
->value
->has_inserted
) {
2151 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
2153 if (local_err
!= NULL
) {
2154 qmp_nbd_server_stop(NULL
);
2159 qapi_free_BlockInfoList(block_list
);
2162 hmp_handle_error(mon
, &local_err
);
2165 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
2167 const char *device
= qdict_get_str(qdict
, "device");
2168 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2169 Error
*local_err
= NULL
;
2171 qmp_nbd_server_add(device
, true, writable
, &local_err
);
2173 if (local_err
!= NULL
) {
2174 hmp_handle_error(mon
, &local_err
);
2178 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
2182 qmp_nbd_server_stop(&err
);
2183 hmp_handle_error(mon
, &err
);
2186 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
2191 cpuid
= qdict_get_int(qdict
, "id");
2192 qmp_cpu_add(cpuid
, &err
);
2193 hmp_handle_error(mon
, &err
);
2196 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
2198 const char *args
= qdict_get_str(qdict
, "args");
2202 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
2204 error_setg(&err
, "Parsing chardev args failed");
2206 qemu_chr_new_from_opts(opts
, &err
);
2207 qemu_opts_del(opts
);
2209 hmp_handle_error(mon
, &err
);
2212 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
2214 Error
*local_err
= NULL
;
2216 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
2217 hmp_handle_error(mon
, &local_err
);
2220 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
2223 BlockBackend
*local_blk
= NULL
;
2224 AioContext
*aio_context
;
2225 const char* device
= qdict_get_str(qdict
, "device");
2226 const char* command
= qdict_get_str(qdict
, "command");
2230 blk
= blk_by_name(device
);
2232 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, device
, &err
);
2234 blk
= local_blk
= blk_new(0, BLK_PERM_ALL
);
2235 ret
= blk_insert_bs(blk
, bs
, &err
);
2244 aio_context
= blk_get_aio_context(blk
);
2245 aio_context_acquire(aio_context
);
2248 * Notably absent: Proper permission management. This is sad, but it seems
2249 * almost impossible to achieve without changing the semantics and thereby
2250 * limiting the use cases of the qemu-io HMP command.
2252 * In an ideal world we would unconditionally create a new BlockBackend for
2253 * qemuio_command(), but we have commands like 'reopen' and want them to
2254 * take effect on the exact BlockBackend whose name the user passed instead
2255 * of just on a temporary copy of it.
2257 * Another problem is that deleting the temporary BlockBackend involves
2258 * draining all requests on it first, but some qemu-iotests cases want to
2259 * issue multiple aio_read/write requests and expect them to complete in
2260 * the background while the monitor has already returned.
2262 * This is also what prevents us from saving the original permissions and
2263 * restoring them later: We can't revoke permissions until all requests
2264 * have completed, and we don't know when that is nor can we really let
2265 * anything else run before we have revoken them to avoid race conditions.
2267 * What happens now is that command() in qemu-io-cmds.c can extend the
2268 * permissions if necessary for the qemu-io command. And they simply stay
2269 * extended, possibly resulting in a read-only guest device keeping write
2270 * permissions. Ugly, but it appears to be the lesser evil.
2272 qemuio_command(blk
, command
);
2274 aio_context_release(aio_context
);
2277 blk_unref(local_blk
);
2278 hmp_handle_error(mon
, &err
);
2281 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
2283 const char *id
= qdict_get_str(qdict
, "id");
2286 user_creatable_del(id
, &err
);
2287 hmp_handle_error(mon
, &err
);
2290 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
2293 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
2294 MemdevList
*m
= memdev_list
;
2299 v
= string_output_visitor_new(false, &str
);
2300 visit_type_uint16List(v
, NULL
, &m
->value
->host_nodes
, NULL
);
2301 monitor_printf(mon
, "memory backend: %s\n", m
->value
->id
);
2302 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
2303 monitor_printf(mon
, " merge: %s\n",
2304 m
->value
->merge
? "true" : "false");
2305 monitor_printf(mon
, " dump: %s\n",
2306 m
->value
->dump
? "true" : "false");
2307 monitor_printf(mon
, " prealloc: %s\n",
2308 m
->value
->prealloc
? "true" : "false");
2309 monitor_printf(mon
, " policy: %s\n",
2310 HostMemPolicy_lookup
[m
->value
->policy
]);
2311 visit_complete(v
, &str
);
2312 monitor_printf(mon
, " host nodes: %s\n", str
);
2319 monitor_printf(mon
, "\n");
2321 qapi_free_MemdevList(memdev_list
);
2324 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
2327 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
2328 MemoryDeviceInfoList
*info
;
2329 MemoryDeviceInfo
*value
;
2330 PCDIMMDeviceInfo
*di
;
2332 for (info
= info_list
; info
; info
= info
->next
) {
2333 value
= info
->value
;
2336 switch (value
->type
) {
2337 case MEMORY_DEVICE_INFO_KIND_DIMM
:
2338 di
= value
->u
.dimm
.data
;
2340 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
2341 MemoryDeviceInfoKind_lookup
[value
->type
],
2342 di
->id
? di
->id
: "");
2343 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
2344 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
2345 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
2346 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
2347 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
2348 monitor_printf(mon
, " hotplugged: %s\n",
2349 di
->hotplugged
? "true" : "false");
2350 monitor_printf(mon
, " hotpluggable: %s\n",
2351 di
->hotpluggable
? "true" : "false");
2359 qapi_free_MemoryDeviceInfoList(info_list
);
2362 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
2364 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
2365 IOThreadInfoList
*info
;
2366 IOThreadInfo
*value
;
2368 for (info
= info_list
; info
; info
= info
->next
) {
2369 value
= info
->value
;
2370 monitor_printf(mon
, "%s:\n", value
->id
);
2371 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
2372 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
2373 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
2374 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
2377 qapi_free_IOThreadInfoList(info_list
);
2380 void hmp_qom_list(Monitor
*mon
, const QDict
*qdict
)
2382 const char *path
= qdict_get_try_str(qdict
, "path");
2383 ObjectPropertyInfoList
*list
;
2387 monitor_printf(mon
, "/\n");
2391 list
= qmp_qom_list(path
, &err
);
2393 ObjectPropertyInfoList
*start
= list
;
2394 while (list
!= NULL
) {
2395 ObjectPropertyInfo
*value
= list
->value
;
2397 monitor_printf(mon
, "%s (%s)\n",
2398 value
->name
, value
->type
);
2401 qapi_free_ObjectPropertyInfoList(start
);
2403 hmp_handle_error(mon
, &err
);
2406 void hmp_qom_set(Monitor
*mon
, const QDict
*qdict
)
2408 const char *path
= qdict_get_str(qdict
, "path");
2409 const char *property
= qdict_get_str(qdict
, "property");
2410 const char *value
= qdict_get_str(qdict
, "value");
2412 bool ambiguous
= false;
2415 obj
= object_resolve_path(path
, &ambiguous
);
2417 error_set(&err
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2418 "Device '%s' not found", path
);
2421 monitor_printf(mon
, "Warning: Path '%s' is ambiguous\n", path
);
2423 object_property_parse(obj
, value
, property
, &err
);
2425 hmp_handle_error(mon
, &err
);
2428 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
2430 const char *name
= qdict_get_str(qdict
, "name");
2431 RockerSwitch
*rocker
;
2434 rocker
= qmp_query_rocker(name
, &err
);
2436 hmp_handle_error(mon
, &err
);
2440 monitor_printf(mon
, "name: %s\n", rocker
->name
);
2441 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
2442 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
2444 qapi_free_RockerSwitch(rocker
);
2447 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
2449 RockerPortList
*list
, *port
;
2450 const char *name
= qdict_get_str(qdict
, "name");
2453 list
= qmp_query_rocker_ports(name
, &err
);
2455 hmp_handle_error(mon
, &err
);
2459 monitor_printf(mon
, " ena/ speed/ auto\n");
2460 monitor_printf(mon
, " port link duplex neg?\n");
2462 for (port
= list
; port
; port
= port
->next
) {
2463 monitor_printf(mon
, "%10s %-4s %-3s %2s %-3s\n",
2465 port
->value
->enabled
? port
->value
->link_up
?
2466 "up" : "down" : "!ena",
2467 port
->value
->speed
== 10000 ? "10G" : "??",
2468 port
->value
->duplex
? "FD" : "HD",
2469 port
->value
->autoneg
? "Yes" : "No");
2472 qapi_free_RockerPortList(list
);
2475 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
2477 RockerOfDpaFlowList
*list
, *info
;
2478 const char *name
= qdict_get_str(qdict
, "name");
2479 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
2482 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
2484 hmp_handle_error(mon
, &err
);
2488 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
2490 for (info
= list
; info
; info
= info
->next
) {
2491 RockerOfDpaFlow
*flow
= info
->value
;
2492 RockerOfDpaFlowKey
*key
= flow
->key
;
2493 RockerOfDpaFlowMask
*mask
= flow
->mask
;
2494 RockerOfDpaFlowAction
*action
= flow
->action
;
2497 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
2498 key
->priority
, key
->tbl_id
, flow
->hits
);
2500 monitor_printf(mon
, "%-4d %-3d ",
2501 key
->priority
, key
->tbl_id
);
2504 if (key
->has_in_pport
) {
2505 monitor_printf(mon
, " pport %d", key
->in_pport
);
2506 if (mask
->has_in_pport
) {
2507 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2511 if (key
->has_vlan_id
) {
2512 monitor_printf(mon
, " vlan %d",
2513 key
->vlan_id
& VLAN_VID_MASK
);
2514 if (mask
->has_vlan_id
) {
2515 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2519 if (key
->has_tunnel_id
) {
2520 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2521 if (mask
->has_tunnel_id
) {
2522 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2526 if (key
->has_eth_type
) {
2527 switch (key
->eth_type
) {
2529 monitor_printf(mon
, " ARP");
2532 monitor_printf(mon
, " IP");
2535 monitor_printf(mon
, " IPv6");
2538 monitor_printf(mon
, " LACP");
2541 monitor_printf(mon
, " LLDP");
2544 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2549 if (key
->has_eth_src
) {
2550 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2551 (mask
->has_eth_src
) &&
2552 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2553 monitor_printf(mon
, " src <any mcast/bcast>");
2554 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2555 (mask
->has_eth_src
) &&
2556 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2557 monitor_printf(mon
, " src <any ucast>");
2559 monitor_printf(mon
, " src %s", key
->eth_src
);
2560 if (mask
->has_eth_src
) {
2561 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2566 if (key
->has_eth_dst
) {
2567 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2568 (mask
->has_eth_dst
) &&
2569 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2570 monitor_printf(mon
, " dst <any mcast/bcast>");
2571 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2572 (mask
->has_eth_dst
) &&
2573 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2574 monitor_printf(mon
, " dst <any ucast>");
2576 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2577 if (mask
->has_eth_dst
) {
2578 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2583 if (key
->has_ip_proto
) {
2584 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2585 if (mask
->has_ip_proto
) {
2586 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2590 if (key
->has_ip_tos
) {
2591 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2592 if (mask
->has_ip_tos
) {
2593 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2597 if (key
->has_ip_dst
) {
2598 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2601 if (action
->has_goto_tbl
|| action
->has_group_id
||
2602 action
->has_new_vlan_id
) {
2603 monitor_printf(mon
, " -->");
2606 if (action
->has_new_vlan_id
) {
2607 monitor_printf(mon
, " apply new vlan %d",
2608 ntohs(action
->new_vlan_id
));
2611 if (action
->has_group_id
) {
2612 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2615 if (action
->has_goto_tbl
) {
2616 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2619 monitor_printf(mon
, "\n");
2622 qapi_free_RockerOfDpaFlowList(list
);
2625 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2627 RockerOfDpaGroupList
*list
, *g
;
2628 const char *name
= qdict_get_str(qdict
, "name");
2629 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2633 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
2635 hmp_handle_error(mon
, &err
);
2639 monitor_printf(mon
, "id (decode) --> buckets\n");
2641 for (g
= list
; g
; g
= g
->next
) {
2642 RockerOfDpaGroup
*group
= g
->value
;
2644 monitor_printf(mon
, "0x%08x", group
->id
);
2646 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2647 group
->type
== 1 ? "L2 rewrite" :
2648 group
->type
== 2 ? "L3 unicast" :
2649 group
->type
== 3 ? "L2 multicast" :
2650 group
->type
== 4 ? "L2 flood" :
2651 group
->type
== 5 ? "L3 interface" :
2652 group
->type
== 6 ? "L3 multicast" :
2653 group
->type
== 7 ? "L3 ECMP" :
2654 group
->type
== 8 ? "L2 overlay" :
2657 if (group
->has_vlan_id
) {
2658 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2661 if (group
->has_pport
) {
2662 monitor_printf(mon
, " pport %d", group
->pport
);
2665 if (group
->has_index
) {
2666 monitor_printf(mon
, " index %d", group
->index
);
2669 monitor_printf(mon
, ") -->");
2671 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2673 monitor_printf(mon
, " set vlan %d",
2674 group
->set_vlan_id
& VLAN_VID_MASK
);
2677 if (group
->has_set_eth_src
) {
2680 monitor_printf(mon
, " set");
2682 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2685 if (group
->has_set_eth_dst
) {
2688 monitor_printf(mon
, " set");
2690 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2695 if (group
->has_ttl_check
&& group
->ttl_check
) {
2696 monitor_printf(mon
, " check TTL");
2699 if (group
->has_group_id
&& group
->group_id
) {
2700 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2703 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2704 monitor_printf(mon
, " pop vlan");
2707 if (group
->has_out_pport
) {
2708 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2711 if (group
->has_group_ids
) {
2712 struct uint32List
*id
;
2714 monitor_printf(mon
, " groups [");
2715 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2716 monitor_printf(mon
, "0x%08x", id
->value
);
2718 monitor_printf(mon
, ",");
2721 monitor_printf(mon
, "]");
2724 monitor_printf(mon
, "\n");
2727 qapi_free_RockerOfDpaGroupList(list
);
2730 void hmp_info_dump(Monitor
*mon
, const QDict
*qdict
)
2732 DumpQueryResult
*result
= qmp_query_dump(NULL
);
2734 assert(result
&& result
->status
< DUMP_STATUS__MAX
);
2735 monitor_printf(mon
, "Status: %s\n", DumpStatus_lookup
[result
->status
]);
2737 if (result
->status
== DUMP_STATUS_ACTIVE
) {
2739 assert(result
->total
!= 0);
2740 percent
= 100.0 * result
->completed
/ result
->total
;
2741 monitor_printf(mon
, "Finished: %.2f %%\n", percent
);
2744 qapi_free_DumpQueryResult(result
);
2747 void hmp_info_ramblock(Monitor
*mon
, const QDict
*qdict
)
2749 ram_block_dump(mon
);
2752 void hmp_hotpluggable_cpus(Monitor
*mon
, const QDict
*qdict
)
2755 HotpluggableCPUList
*l
= qmp_query_hotpluggable_cpus(&err
);
2756 HotpluggableCPUList
*saved
= l
;
2757 CpuInstanceProperties
*c
;
2760 hmp_handle_error(mon
, &err
);
2764 monitor_printf(mon
, "Hotpluggable CPUs:\n");
2766 monitor_printf(mon
, " type: \"%s\"\n", l
->value
->type
);
2767 monitor_printf(mon
, " vcpus_count: \"%" PRIu64
"\"\n",
2768 l
->value
->vcpus_count
);
2769 if (l
->value
->has_qom_path
) {
2770 monitor_printf(mon
, " qom_path: \"%s\"\n", l
->value
->qom_path
);
2773 c
= l
->value
->props
;
2774 monitor_printf(mon
, " CPUInstance Properties:\n");
2775 if (c
->has_node_id
) {
2776 monitor_printf(mon
, " node-id: \"%" PRIu64
"\"\n", c
->node_id
);
2778 if (c
->has_socket_id
) {
2779 monitor_printf(mon
, " socket-id: \"%" PRIu64
"\"\n", c
->socket_id
);
2781 if (c
->has_core_id
) {
2782 monitor_printf(mon
, " core-id: \"%" PRIu64
"\"\n", c
->core_id
);
2784 if (c
->has_thread_id
) {
2785 monitor_printf(mon
, " thread-id: \"%" PRIu64
"\"\n", c
->thread_id
);
2791 qapi_free_HotpluggableCPUList(saved
);
2794 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
2797 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
2799 monitor_printf(mon
, "%s\n", info
->guid
);
2801 hmp_handle_error(mon
, &err
);
2802 qapi_free_GuidInfo(info
);