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");
1279 vm_stop(RUN_STATE_RESTORE_VM
);
1281 if (load_vmstate(name
) == 0 && saved_vm_running
) {
1286 void hmp_savevm(Monitor
*mon
, const QDict
*qdict
)
1288 save_vmstate(qdict_get_try_str(qdict
, "name"));
1291 void hmp_delvm(Monitor
*mon
, const QDict
*qdict
)
1293 BlockDriverState
*bs
;
1295 const char *name
= qdict_get_str(qdict
, "name");
1297 if (bdrv_all_delete_snapshot(name
, &bs
, &err
) < 0) {
1298 error_reportf_err(err
,
1299 "Error while deleting snapshot on device '%s': ",
1300 bdrv_get_device_name(bs
));
1304 void hmp_info_snapshots(Monitor
*mon
, const QDict
*qdict
)
1306 BlockDriverState
*bs
, *bs1
;
1307 BdrvNextIterator it1
;
1308 QEMUSnapshotInfo
*sn_tab
, *sn
;
1309 bool no_snapshot
= true;
1312 int *global_snapshots
;
1313 AioContext
*aio_context
;
1315 typedef struct SnapshotEntry
{
1316 QEMUSnapshotInfo sn
;
1317 QTAILQ_ENTRY(SnapshotEntry
) next
;
1320 typedef struct ImageEntry
{
1321 const char *imagename
;
1322 QTAILQ_ENTRY(ImageEntry
) next
;
1323 QTAILQ_HEAD(, SnapshotEntry
) snapshots
;
1326 QTAILQ_HEAD(, ImageEntry
) image_list
=
1327 QTAILQ_HEAD_INITIALIZER(image_list
);
1329 ImageEntry
*image_entry
, *next_ie
;
1330 SnapshotEntry
*snapshot_entry
;
1332 bs
= bdrv_all_find_vmstate_bs();
1334 monitor_printf(mon
, "No available block device supports snapshots\n");
1337 aio_context
= bdrv_get_aio_context(bs
);
1339 aio_context_acquire(aio_context
);
1340 nb_sns
= bdrv_snapshot_list(bs
, &sn_tab
);
1341 aio_context_release(aio_context
);
1344 monitor_printf(mon
, "bdrv_snapshot_list: error %d\n", nb_sns
);
1348 for (bs1
= bdrv_first(&it1
); bs1
; bs1
= bdrv_next(&it1
)) {
1352 AioContext
*ctx
= bdrv_get_aio_context(bs1
);
1354 aio_context_acquire(ctx
);
1355 if (bdrv_can_snapshot(bs1
)) {
1357 bs1_nb_sns
= bdrv_snapshot_list(bs1
, &sn
);
1358 if (bs1_nb_sns
> 0) {
1359 no_snapshot
= false;
1360 ie
= g_new0(ImageEntry
, 1);
1361 ie
->imagename
= bdrv_get_device_name(bs1
);
1362 QTAILQ_INIT(&ie
->snapshots
);
1363 QTAILQ_INSERT_TAIL(&image_list
, ie
, next
);
1364 for (i
= 0; i
< bs1_nb_sns
; i
++) {
1365 se
= g_new0(SnapshotEntry
, 1);
1367 QTAILQ_INSERT_TAIL(&ie
->snapshots
, se
, next
);
1372 aio_context_release(ctx
);
1376 monitor_printf(mon
, "There is no snapshot available.\n");
1380 global_snapshots
= g_new0(int, nb_sns
);
1382 for (i
= 0; i
< nb_sns
; i
++) {
1383 SnapshotEntry
*next_sn
;
1384 if (bdrv_all_find_snapshot(sn_tab
[i
].name
, &bs1
) == 0) {
1385 global_snapshots
[total
] = i
;
1387 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1388 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
,
1390 if (!strcmp(sn_tab
[i
].name
, snapshot_entry
->sn
.name
)) {
1391 QTAILQ_REMOVE(&image_entry
->snapshots
, snapshot_entry
,
1393 g_free(snapshot_entry
);
1400 monitor_printf(mon
, "List of snapshots present on all disks:\n");
1403 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1404 monitor_printf(mon
, "\n");
1405 for (i
= 0; i
< total
; i
++) {
1406 sn
= &sn_tab
[global_snapshots
[i
]];
1407 /* The ID is not guaranteed to be the same on all images, so
1410 pstrcpy(sn
->id_str
, sizeof(sn
->id_str
), "--");
1411 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, sn
);
1412 monitor_printf(mon
, "\n");
1415 monitor_printf(mon
, "None\n");
1418 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1419 if (QTAILQ_EMPTY(&image_entry
->snapshots
)) {
1423 "\nList of partial (non-loadable) snapshots on '%s':\n",
1424 image_entry
->imagename
);
1425 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1426 monitor_printf(mon
, "\n");
1427 QTAILQ_FOREACH(snapshot_entry
, &image_entry
->snapshots
, next
) {
1428 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
,
1429 &snapshot_entry
->sn
);
1430 monitor_printf(mon
, "\n");
1434 QTAILQ_FOREACH_SAFE(image_entry
, &image_list
, next
, next_ie
) {
1435 SnapshotEntry
*next_sn
;
1436 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
, next
,
1438 g_free(snapshot_entry
);
1440 g_free(image_entry
);
1443 g_free(global_snapshots
);
1447 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1449 qmp_migrate_cancel(NULL
);
1452 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1455 const char *uri
= qdict_get_str(qdict
, "uri");
1457 qmp_migrate_incoming(uri
, &err
);
1459 hmp_handle_error(mon
, &err
);
1462 /* Kept for backwards compatibility */
1463 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1465 double value
= qdict_get_double(qdict
, "value");
1466 qmp_migrate_set_downtime(value
, NULL
);
1469 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1471 int64_t value
= qdict_get_int(qdict
, "value");
1474 qmp_migrate_set_cache_size(value
, &err
);
1476 error_report_err(err
);
1481 /* Kept for backwards compatibility */
1482 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1484 int64_t value
= qdict_get_int(qdict
, "value");
1485 qmp_migrate_set_speed(value
, NULL
);
1488 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1490 const char *cap
= qdict_get_str(qdict
, "capability");
1491 bool state
= qdict_get_bool(qdict
, "state");
1493 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1496 for (i
= 0; i
< MIGRATION_CAPABILITY__MAX
; i
++) {
1497 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
1498 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1499 caps
->value
->capability
= i
;
1500 caps
->value
->state
= state
;
1502 qmp_migrate_set_capabilities(caps
, &err
);
1507 if (i
== MIGRATION_CAPABILITY__MAX
) {
1508 error_setg(&err
, QERR_INVALID_PARAMETER
, cap
);
1511 qapi_free_MigrationCapabilityStatusList(caps
);
1514 error_report_err(err
);
1518 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1520 const char *param
= qdict_get_str(qdict
, "parameter");
1521 const char *valuestr
= qdict_get_str(qdict
, "value");
1522 uint64_t valuebw
= 0;
1525 bool use_int_value
= false;
1528 for (i
= 0; i
< MIGRATION_PARAMETER__MAX
; i
++) {
1529 if (strcmp(param
, MigrationParameter_lookup
[i
]) == 0) {
1530 MigrationParameters p
= { 0 };
1532 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1533 p
.has_compress_level
= true;
1534 use_int_value
= true;
1536 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1537 p
.has_compress_threads
= true;
1538 use_int_value
= true;
1540 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1541 p
.has_decompress_threads
= true;
1542 use_int_value
= true;
1544 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1545 p
.has_cpu_throttle_initial
= true;
1546 use_int_value
= true;
1548 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1549 p
.has_cpu_throttle_increment
= true;
1550 use_int_value
= true;
1552 case MIGRATION_PARAMETER_TLS_CREDS
:
1553 p
.has_tls_creds
= true;
1554 p
.tls_creds
= (char *) valuestr
;
1556 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1557 p
.has_tls_hostname
= true;
1558 p
.tls_hostname
= (char *) valuestr
;
1560 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1561 p
.has_max_bandwidth
= true;
1562 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
1563 if (ret
< 0 || valuebw
> INT64_MAX
1564 || (size_t)valuebw
!= valuebw
) {
1565 error_setg(&err
, "Invalid size %s", valuestr
);
1568 p
.max_bandwidth
= valuebw
;
1570 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1571 p
.has_downtime_limit
= true;
1572 use_int_value
= true;
1574 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
1575 p
.has_x_checkpoint_delay
= true;
1576 use_int_value
= true;
1580 if (use_int_value
) {
1581 if (qemu_strtol(valuestr
, NULL
, 10, &valueint
) < 0) {
1582 error_setg(&err
, "Unable to parse '%s' as an int",
1586 /* Set all integers; only one has_FOO will be set, and
1587 * the code ignores the remaining values */
1588 p
.compress_level
= valueint
;
1589 p
.compress_threads
= valueint
;
1590 p
.decompress_threads
= valueint
;
1591 p
.cpu_throttle_initial
= valueint
;
1592 p
.cpu_throttle_increment
= valueint
;
1593 p
.downtime_limit
= valueint
;
1594 p
.x_checkpoint_delay
= valueint
;
1597 qmp_migrate_set_parameters(&p
, &err
);
1602 if (i
== MIGRATION_PARAMETER__MAX
) {
1603 error_setg(&err
, QERR_INVALID_PARAMETER
, param
);
1608 error_report_err(err
);
1612 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1615 const char *protocol
= qdict_get_str(qdict
, "protocol");
1616 const char *hostname
= qdict_get_str(qdict
, "hostname");
1617 bool has_port
= qdict_haskey(qdict
, "port");
1618 int port
= qdict_get_try_int(qdict
, "port", -1);
1619 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1620 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1621 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1623 qmp_client_migrate_info(protocol
, hostname
,
1624 has_port
, port
, has_tls_port
, tls_port
,
1625 !!cert_subject
, cert_subject
, &err
);
1626 hmp_handle_error(mon
, &err
);
1629 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1632 qmp_migrate_start_postcopy(&err
);
1633 hmp_handle_error(mon
, &err
);
1636 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1640 qmp_x_colo_lost_heartbeat(&err
);
1641 hmp_handle_error(mon
, &err
);
1644 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1646 const char *protocol
= qdict_get_str(qdict
, "protocol");
1647 const char *password
= qdict_get_str(qdict
, "password");
1648 const char *connected
= qdict_get_try_str(qdict
, "connected");
1651 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1652 hmp_handle_error(mon
, &err
);
1655 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1657 const char *protocol
= qdict_get_str(qdict
, "protocol");
1658 const char *whenstr
= qdict_get_str(qdict
, "time");
1661 qmp_expire_password(protocol
, whenstr
, &err
);
1662 hmp_handle_error(mon
, &err
);
1665 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1667 bool force
= qdict_get_try_bool(qdict
, "force", false);
1668 const char *device
= qdict_get_str(qdict
, "device");
1671 qmp_eject(true, device
, false, NULL
, true, force
, &err
);
1672 hmp_handle_error(mon
, &err
);
1675 static void hmp_change_read_arg(void *opaque
, const char *password
,
1676 void *readline_opaque
)
1678 qmp_change_vnc_password(password
, NULL
);
1679 monitor_read_command(opaque
, 1);
1682 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1684 const char *device
= qdict_get_str(qdict
, "device");
1685 const char *target
= qdict_get_str(qdict
, "target");
1686 const char *arg
= qdict_get_try_str(qdict
, "arg");
1687 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1688 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1691 if (strcmp(device
, "vnc") == 0) {
1694 "Parameter 'read-only-mode' is invalid for VNC\n");
1697 if (strcmp(target
, "passwd") == 0 ||
1698 strcmp(target
, "password") == 0) {
1700 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1704 qmp_change("vnc", target
, !!arg
, arg
, &err
);
1708 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup
,
1709 read_only
, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX
,
1710 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1712 hmp_handle_error(mon
, &err
);
1717 qmp_blockdev_change_medium(true, device
, false, NULL
, target
,
1718 !!arg
, arg
, !!read_only
, read_only_mode
,
1721 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
1723 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
1728 hmp_handle_error(mon
, &err
);
1731 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1734 BlockIOThrottle throttle
= {
1736 .device
= (char *) qdict_get_str(qdict
, "device"),
1737 .bps
= qdict_get_int(qdict
, "bps"),
1738 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
1739 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
1740 .iops
= qdict_get_int(qdict
, "iops"),
1741 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
1742 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
1745 qmp_block_set_io_throttle(&throttle
, &err
);
1746 hmp_handle_error(mon
, &err
);
1749 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1751 Error
*error
= NULL
;
1752 const char *device
= qdict_get_str(qdict
, "device");
1753 const char *base
= qdict_get_try_str(qdict
, "base");
1754 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1756 qmp_block_stream(true, device
, device
, base
!= NULL
, base
, false, NULL
,
1757 false, NULL
, qdict_haskey(qdict
, "speed"), speed
,
1758 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1760 hmp_handle_error(mon
, &error
);
1763 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1765 Error
*error
= NULL
;
1766 const char *device
= qdict_get_str(qdict
, "device");
1767 int64_t value
= qdict_get_int(qdict
, "speed");
1769 qmp_block_job_set_speed(device
, value
, &error
);
1771 hmp_handle_error(mon
, &error
);
1774 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1776 Error
*error
= NULL
;
1777 const char *device
= qdict_get_str(qdict
, "device");
1778 bool force
= qdict_get_try_bool(qdict
, "force", false);
1780 qmp_block_job_cancel(device
, true, force
, &error
);
1782 hmp_handle_error(mon
, &error
);
1785 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1787 Error
*error
= NULL
;
1788 const char *device
= qdict_get_str(qdict
, "device");
1790 qmp_block_job_pause(device
, &error
);
1792 hmp_handle_error(mon
, &error
);
1795 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1797 Error
*error
= NULL
;
1798 const char *device
= qdict_get_str(qdict
, "device");
1800 qmp_block_job_resume(device
, &error
);
1802 hmp_handle_error(mon
, &error
);
1805 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1807 Error
*error
= NULL
;
1808 const char *device
= qdict_get_str(qdict
, "device");
1810 qmp_block_job_complete(device
, &error
);
1812 hmp_handle_error(mon
, &error
);
1815 typedef struct HMPMigrationStatus
1819 bool is_block_migration
;
1820 } HMPMigrationStatus
;
1822 static void hmp_migrate_status_cb(void *opaque
)
1824 HMPMigrationStatus
*status
= opaque
;
1825 MigrationInfo
*info
;
1827 info
= qmp_query_migrate(NULL
);
1828 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1829 info
->status
== MIGRATION_STATUS_SETUP
) {
1830 if (info
->has_disk
) {
1833 if (info
->disk
->remaining
) {
1834 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1839 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1840 monitor_flush(status
->mon
);
1843 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1845 if (status
->is_block_migration
) {
1846 monitor_printf(status
->mon
, "\n");
1848 if (info
->has_error_desc
) {
1849 error_report("%s", info
->error_desc
);
1851 monitor_resume(status
->mon
);
1852 timer_del(status
->timer
);
1856 qapi_free_MigrationInfo(info
);
1859 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1861 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1862 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1863 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1864 const char *uri
= qdict_get_str(qdict
, "uri");
1867 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1869 error_report_err(err
);
1874 HMPMigrationStatus
*status
;
1876 if (monitor_suspend(mon
) < 0) {
1877 monitor_printf(mon
, "terminal does not allow synchronous "
1878 "migration, continuing detached\n");
1882 status
= g_malloc0(sizeof(*status
));
1884 status
->is_block_migration
= blk
|| inc
;
1885 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1887 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1891 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
1895 qmp_device_add((QDict
*)qdict
, NULL
, &err
);
1896 hmp_handle_error(mon
, &err
);
1899 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1901 const char *id
= qdict_get_str(qdict
, "id");
1904 qmp_device_del(id
, &err
);
1905 hmp_handle_error(mon
, &err
);
1908 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1911 bool paging
= qdict_get_try_bool(qdict
, "paging", false);
1912 bool zlib
= qdict_get_try_bool(qdict
, "zlib", false);
1913 bool lzo
= qdict_get_try_bool(qdict
, "lzo", false);
1914 bool snappy
= qdict_get_try_bool(qdict
, "snappy", false);
1915 const char *file
= qdict_get_str(qdict
, "filename");
1916 bool has_begin
= qdict_haskey(qdict
, "begin");
1917 bool has_length
= qdict_haskey(qdict
, "length");
1918 bool has_detach
= qdict_haskey(qdict
, "detach");
1921 bool detach
= false;
1922 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1925 if (zlib
+ lzo
+ snappy
> 1) {
1926 error_setg(&err
, "only one of '-z|-l|-s' can be set");
1927 hmp_handle_error(mon
, &err
);
1932 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
1936 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
1940 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
1944 begin
= qdict_get_int(qdict
, "begin");
1947 length
= qdict_get_int(qdict
, "length");
1950 detach
= qdict_get_bool(qdict
, "detach");
1953 prot
= g_strconcat("file:", file
, NULL
);
1955 qmp_dump_guest_memory(paging
, prot
, true, detach
, has_begin
, begin
,
1956 has_length
, length
, true, dump_format
, &err
);
1957 hmp_handle_error(mon
, &err
);
1961 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1966 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1971 netdev_add(opts
, &err
);
1973 qemu_opts_del(opts
);
1977 hmp_handle_error(mon
, &err
);
1980 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1982 const char *id
= qdict_get_str(qdict
, "id");
1985 qmp_netdev_del(id
, &err
);
1986 hmp_handle_error(mon
, &err
);
1989 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
1995 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
1997 hmp_handle_error(mon
, &err
);
2001 obj
= user_creatable_add_opts(opts
, &err
);
2002 qemu_opts_del(opts
);
2005 hmp_handle_error(mon
, &err
);
2012 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
2014 const char *fdname
= qdict_get_str(qdict
, "fdname");
2017 qmp_getfd(fdname
, &err
);
2018 hmp_handle_error(mon
, &err
);
2021 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
2023 const char *fdname
= qdict_get_str(qdict
, "fdname");
2026 qmp_closefd(fdname
, &err
);
2027 hmp_handle_error(mon
, &err
);
2030 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
2032 const char *keys
= qdict_get_str(qdict
, "keys");
2033 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
2034 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
2035 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
2041 separator
= strchr(keys
, '-');
2042 keyname_len
= separator
? separator
- keys
: strlen(keys
);
2044 /* Be compatible with old interface, convert user inputted "<" */
2045 if (keys
[0] == '<' && keyname_len
== 1) {
2050 keylist
= g_malloc0(sizeof(*keylist
));
2051 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
2057 tmp
->next
= keylist
;
2061 if (strstart(keys
, "0x", NULL
)) {
2063 int value
= strtoul(keys
, &endp
, 0);
2064 assert(endp
<= keys
+ keyname_len
);
2065 if (endp
!= keys
+ keyname_len
) {
2068 keylist
->value
->type
= KEY_VALUE_KIND_NUMBER
;
2069 keylist
->value
->u
.number
.data
= value
;
2071 int idx
= index_from_key(keys
, keyname_len
);
2072 if (idx
== Q_KEY_CODE__MAX
) {
2075 keylist
->value
->type
= KEY_VALUE_KIND_QCODE
;
2076 keylist
->value
->u
.qcode
.data
= idx
;
2082 keys
= separator
+ 1;
2085 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
2086 hmp_handle_error(mon
, &err
);
2089 qapi_free_KeyValueList(head
);
2093 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
2097 void hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
2099 const char *filename
= qdict_get_str(qdict
, "filename");
2102 qmp_screendump(filename
, &err
);
2103 hmp_handle_error(mon
, &err
);
2106 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
2108 const char *uri
= qdict_get_str(qdict
, "uri");
2109 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2110 bool all
= qdict_get_try_bool(qdict
, "all", false);
2111 Error
*local_err
= NULL
;
2112 BlockInfoList
*block_list
, *info
;
2113 SocketAddress
*addr
;
2115 if (writable
&& !all
) {
2116 error_setg(&local_err
, "-w only valid together with -a");
2120 /* First check if the address is valid and start the server. */
2121 addr
= socket_parse(uri
, &local_err
);
2122 if (local_err
!= NULL
) {
2126 nbd_server_start(addr
, NULL
, &local_err
);
2127 qapi_free_SocketAddress(addr
);
2128 if (local_err
!= NULL
) {
2136 /* Then try adding all block devices. If one fails, close all and
2139 block_list
= qmp_query_block(NULL
);
2141 for (info
= block_list
; info
; info
= info
->next
) {
2142 if (!info
->value
->has_inserted
) {
2146 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
2148 if (local_err
!= NULL
) {
2149 qmp_nbd_server_stop(NULL
);
2154 qapi_free_BlockInfoList(block_list
);
2157 hmp_handle_error(mon
, &local_err
);
2160 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
2162 const char *device
= qdict_get_str(qdict
, "device");
2163 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2164 Error
*local_err
= NULL
;
2166 qmp_nbd_server_add(device
, true, writable
, &local_err
);
2168 if (local_err
!= NULL
) {
2169 hmp_handle_error(mon
, &local_err
);
2173 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
2177 qmp_nbd_server_stop(&err
);
2178 hmp_handle_error(mon
, &err
);
2181 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
2186 cpuid
= qdict_get_int(qdict
, "id");
2187 qmp_cpu_add(cpuid
, &err
);
2188 hmp_handle_error(mon
, &err
);
2191 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
2193 const char *args
= qdict_get_str(qdict
, "args");
2197 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
2199 error_setg(&err
, "Parsing chardev args failed");
2201 qemu_chr_new_from_opts(opts
, &err
);
2202 qemu_opts_del(opts
);
2204 hmp_handle_error(mon
, &err
);
2207 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
2209 Error
*local_err
= NULL
;
2211 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
2212 hmp_handle_error(mon
, &local_err
);
2215 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
2218 BlockBackend
*local_blk
= NULL
;
2219 AioContext
*aio_context
;
2220 const char* device
= qdict_get_str(qdict
, "device");
2221 const char* command
= qdict_get_str(qdict
, "command");
2225 blk
= blk_by_name(device
);
2227 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, device
, &err
);
2229 blk
= local_blk
= blk_new(0, BLK_PERM_ALL
);
2230 ret
= blk_insert_bs(blk
, bs
, &err
);
2239 aio_context
= blk_get_aio_context(blk
);
2240 aio_context_acquire(aio_context
);
2243 * Notably absent: Proper permission management. This is sad, but it seems
2244 * almost impossible to achieve without changing the semantics and thereby
2245 * limiting the use cases of the qemu-io HMP command.
2247 * In an ideal world we would unconditionally create a new BlockBackend for
2248 * qemuio_command(), but we have commands like 'reopen' and want them to
2249 * take effect on the exact BlockBackend whose name the user passed instead
2250 * of just on a temporary copy of it.
2252 * Another problem is that deleting the temporary BlockBackend involves
2253 * draining all requests on it first, but some qemu-iotests cases want to
2254 * issue multiple aio_read/write requests and expect them to complete in
2255 * the background while the monitor has already returned.
2257 * This is also what prevents us from saving the original permissions and
2258 * restoring them later: We can't revoke permissions until all requests
2259 * have completed, and we don't know when that is nor can we really let
2260 * anything else run before we have revoken them to avoid race conditions.
2262 * What happens now is that command() in qemu-io-cmds.c can extend the
2263 * permissions if necessary for the qemu-io command. And they simply stay
2264 * extended, possibly resulting in a read-only guest device keeping write
2265 * permissions. Ugly, but it appears to be the lesser evil.
2267 qemuio_command(blk
, command
);
2269 aio_context_release(aio_context
);
2272 blk_unref(local_blk
);
2273 hmp_handle_error(mon
, &err
);
2276 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
2278 const char *id
= qdict_get_str(qdict
, "id");
2281 user_creatable_del(id
, &err
);
2282 hmp_handle_error(mon
, &err
);
2285 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
2288 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
2289 MemdevList
*m
= memdev_list
;
2294 v
= string_output_visitor_new(false, &str
);
2295 visit_type_uint16List(v
, NULL
, &m
->value
->host_nodes
, NULL
);
2296 monitor_printf(mon
, "memory backend: %s\n", m
->value
->id
);
2297 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
2298 monitor_printf(mon
, " merge: %s\n",
2299 m
->value
->merge
? "true" : "false");
2300 monitor_printf(mon
, " dump: %s\n",
2301 m
->value
->dump
? "true" : "false");
2302 monitor_printf(mon
, " prealloc: %s\n",
2303 m
->value
->prealloc
? "true" : "false");
2304 monitor_printf(mon
, " policy: %s\n",
2305 HostMemPolicy_lookup
[m
->value
->policy
]);
2306 visit_complete(v
, &str
);
2307 monitor_printf(mon
, " host nodes: %s\n", str
);
2314 monitor_printf(mon
, "\n");
2316 qapi_free_MemdevList(memdev_list
);
2319 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
2322 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
2323 MemoryDeviceInfoList
*info
;
2324 MemoryDeviceInfo
*value
;
2325 PCDIMMDeviceInfo
*di
;
2327 for (info
= info_list
; info
; info
= info
->next
) {
2328 value
= info
->value
;
2331 switch (value
->type
) {
2332 case MEMORY_DEVICE_INFO_KIND_DIMM
:
2333 di
= value
->u
.dimm
.data
;
2335 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
2336 MemoryDeviceInfoKind_lookup
[value
->type
],
2337 di
->id
? di
->id
: "");
2338 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
2339 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
2340 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
2341 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
2342 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
2343 monitor_printf(mon
, " hotplugged: %s\n",
2344 di
->hotplugged
? "true" : "false");
2345 monitor_printf(mon
, " hotpluggable: %s\n",
2346 di
->hotpluggable
? "true" : "false");
2354 qapi_free_MemoryDeviceInfoList(info_list
);
2357 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
2359 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
2360 IOThreadInfoList
*info
;
2361 IOThreadInfo
*value
;
2363 for (info
= info_list
; info
; info
= info
->next
) {
2364 value
= info
->value
;
2365 monitor_printf(mon
, "%s:\n", value
->id
);
2366 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
2367 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
2368 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
2369 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
2372 qapi_free_IOThreadInfoList(info_list
);
2375 void hmp_qom_list(Monitor
*mon
, const QDict
*qdict
)
2377 const char *path
= qdict_get_try_str(qdict
, "path");
2378 ObjectPropertyInfoList
*list
;
2382 monitor_printf(mon
, "/\n");
2386 list
= qmp_qom_list(path
, &err
);
2388 ObjectPropertyInfoList
*start
= list
;
2389 while (list
!= NULL
) {
2390 ObjectPropertyInfo
*value
= list
->value
;
2392 monitor_printf(mon
, "%s (%s)\n",
2393 value
->name
, value
->type
);
2396 qapi_free_ObjectPropertyInfoList(start
);
2398 hmp_handle_error(mon
, &err
);
2401 void hmp_qom_set(Monitor
*mon
, const QDict
*qdict
)
2403 const char *path
= qdict_get_str(qdict
, "path");
2404 const char *property
= qdict_get_str(qdict
, "property");
2405 const char *value
= qdict_get_str(qdict
, "value");
2407 bool ambiguous
= false;
2410 obj
= object_resolve_path(path
, &ambiguous
);
2412 error_set(&err
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2413 "Device '%s' not found", path
);
2416 monitor_printf(mon
, "Warning: Path '%s' is ambiguous\n", path
);
2418 object_property_parse(obj
, value
, property
, &err
);
2420 hmp_handle_error(mon
, &err
);
2423 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
2425 const char *name
= qdict_get_str(qdict
, "name");
2426 RockerSwitch
*rocker
;
2429 rocker
= qmp_query_rocker(name
, &err
);
2431 hmp_handle_error(mon
, &err
);
2435 monitor_printf(mon
, "name: %s\n", rocker
->name
);
2436 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
2437 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
2439 qapi_free_RockerSwitch(rocker
);
2442 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
2444 RockerPortList
*list
, *port
;
2445 const char *name
= qdict_get_str(qdict
, "name");
2448 list
= qmp_query_rocker_ports(name
, &err
);
2450 hmp_handle_error(mon
, &err
);
2454 monitor_printf(mon
, " ena/ speed/ auto\n");
2455 monitor_printf(mon
, " port link duplex neg?\n");
2457 for (port
= list
; port
; port
= port
->next
) {
2458 monitor_printf(mon
, "%10s %-4s %-3s %2s %-3s\n",
2460 port
->value
->enabled
? port
->value
->link_up
?
2461 "up" : "down" : "!ena",
2462 port
->value
->speed
== 10000 ? "10G" : "??",
2463 port
->value
->duplex
? "FD" : "HD",
2464 port
->value
->autoneg
? "Yes" : "No");
2467 qapi_free_RockerPortList(list
);
2470 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
2472 RockerOfDpaFlowList
*list
, *info
;
2473 const char *name
= qdict_get_str(qdict
, "name");
2474 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
2477 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
2479 hmp_handle_error(mon
, &err
);
2483 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
2485 for (info
= list
; info
; info
= info
->next
) {
2486 RockerOfDpaFlow
*flow
= info
->value
;
2487 RockerOfDpaFlowKey
*key
= flow
->key
;
2488 RockerOfDpaFlowMask
*mask
= flow
->mask
;
2489 RockerOfDpaFlowAction
*action
= flow
->action
;
2492 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
2493 key
->priority
, key
->tbl_id
, flow
->hits
);
2495 monitor_printf(mon
, "%-4d %-3d ",
2496 key
->priority
, key
->tbl_id
);
2499 if (key
->has_in_pport
) {
2500 monitor_printf(mon
, " pport %d", key
->in_pport
);
2501 if (mask
->has_in_pport
) {
2502 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2506 if (key
->has_vlan_id
) {
2507 monitor_printf(mon
, " vlan %d",
2508 key
->vlan_id
& VLAN_VID_MASK
);
2509 if (mask
->has_vlan_id
) {
2510 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2514 if (key
->has_tunnel_id
) {
2515 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2516 if (mask
->has_tunnel_id
) {
2517 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2521 if (key
->has_eth_type
) {
2522 switch (key
->eth_type
) {
2524 monitor_printf(mon
, " ARP");
2527 monitor_printf(mon
, " IP");
2530 monitor_printf(mon
, " IPv6");
2533 monitor_printf(mon
, " LACP");
2536 monitor_printf(mon
, " LLDP");
2539 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2544 if (key
->has_eth_src
) {
2545 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2546 (mask
->has_eth_src
) &&
2547 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2548 monitor_printf(mon
, " src <any mcast/bcast>");
2549 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2550 (mask
->has_eth_src
) &&
2551 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2552 monitor_printf(mon
, " src <any ucast>");
2554 monitor_printf(mon
, " src %s", key
->eth_src
);
2555 if (mask
->has_eth_src
) {
2556 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2561 if (key
->has_eth_dst
) {
2562 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2563 (mask
->has_eth_dst
) &&
2564 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2565 monitor_printf(mon
, " dst <any mcast/bcast>");
2566 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2567 (mask
->has_eth_dst
) &&
2568 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2569 monitor_printf(mon
, " dst <any ucast>");
2571 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2572 if (mask
->has_eth_dst
) {
2573 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2578 if (key
->has_ip_proto
) {
2579 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2580 if (mask
->has_ip_proto
) {
2581 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2585 if (key
->has_ip_tos
) {
2586 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2587 if (mask
->has_ip_tos
) {
2588 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2592 if (key
->has_ip_dst
) {
2593 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2596 if (action
->has_goto_tbl
|| action
->has_group_id
||
2597 action
->has_new_vlan_id
) {
2598 monitor_printf(mon
, " -->");
2601 if (action
->has_new_vlan_id
) {
2602 monitor_printf(mon
, " apply new vlan %d",
2603 ntohs(action
->new_vlan_id
));
2606 if (action
->has_group_id
) {
2607 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2610 if (action
->has_goto_tbl
) {
2611 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2614 monitor_printf(mon
, "\n");
2617 qapi_free_RockerOfDpaFlowList(list
);
2620 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2622 RockerOfDpaGroupList
*list
, *g
;
2623 const char *name
= qdict_get_str(qdict
, "name");
2624 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2628 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
2630 hmp_handle_error(mon
, &err
);
2634 monitor_printf(mon
, "id (decode) --> buckets\n");
2636 for (g
= list
; g
; g
= g
->next
) {
2637 RockerOfDpaGroup
*group
= g
->value
;
2639 monitor_printf(mon
, "0x%08x", group
->id
);
2641 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2642 group
->type
== 1 ? "L2 rewrite" :
2643 group
->type
== 2 ? "L3 unicast" :
2644 group
->type
== 3 ? "L2 multicast" :
2645 group
->type
== 4 ? "L2 flood" :
2646 group
->type
== 5 ? "L3 interface" :
2647 group
->type
== 6 ? "L3 multicast" :
2648 group
->type
== 7 ? "L3 ECMP" :
2649 group
->type
== 8 ? "L2 overlay" :
2652 if (group
->has_vlan_id
) {
2653 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2656 if (group
->has_pport
) {
2657 monitor_printf(mon
, " pport %d", group
->pport
);
2660 if (group
->has_index
) {
2661 monitor_printf(mon
, " index %d", group
->index
);
2664 monitor_printf(mon
, ") -->");
2666 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2668 monitor_printf(mon
, " set vlan %d",
2669 group
->set_vlan_id
& VLAN_VID_MASK
);
2672 if (group
->has_set_eth_src
) {
2675 monitor_printf(mon
, " set");
2677 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2680 if (group
->has_set_eth_dst
) {
2683 monitor_printf(mon
, " set");
2685 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2690 if (group
->has_ttl_check
&& group
->ttl_check
) {
2691 monitor_printf(mon
, " check TTL");
2694 if (group
->has_group_id
&& group
->group_id
) {
2695 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2698 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2699 monitor_printf(mon
, " pop vlan");
2702 if (group
->has_out_pport
) {
2703 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2706 if (group
->has_group_ids
) {
2707 struct uint32List
*id
;
2709 monitor_printf(mon
, " groups [");
2710 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2711 monitor_printf(mon
, "0x%08x", id
->value
);
2713 monitor_printf(mon
, ",");
2716 monitor_printf(mon
, "]");
2719 monitor_printf(mon
, "\n");
2722 qapi_free_RockerOfDpaGroupList(list
);
2725 void hmp_info_dump(Monitor
*mon
, const QDict
*qdict
)
2727 DumpQueryResult
*result
= qmp_query_dump(NULL
);
2729 assert(result
&& result
->status
< DUMP_STATUS__MAX
);
2730 monitor_printf(mon
, "Status: %s\n", DumpStatus_lookup
[result
->status
]);
2732 if (result
->status
== DUMP_STATUS_ACTIVE
) {
2734 assert(result
->total
!= 0);
2735 percent
= 100.0 * result
->completed
/ result
->total
;
2736 monitor_printf(mon
, "Finished: %.2f %%\n", percent
);
2739 qapi_free_DumpQueryResult(result
);
2742 void hmp_info_ramblock(Monitor
*mon
, const QDict
*qdict
)
2744 ram_block_dump(mon
);
2747 void hmp_hotpluggable_cpus(Monitor
*mon
, const QDict
*qdict
)
2750 HotpluggableCPUList
*l
= qmp_query_hotpluggable_cpus(&err
);
2751 HotpluggableCPUList
*saved
= l
;
2752 CpuInstanceProperties
*c
;
2755 hmp_handle_error(mon
, &err
);
2759 monitor_printf(mon
, "Hotpluggable CPUs:\n");
2761 monitor_printf(mon
, " type: \"%s\"\n", l
->value
->type
);
2762 monitor_printf(mon
, " vcpus_count: \"%" PRIu64
"\"\n",
2763 l
->value
->vcpus_count
);
2764 if (l
->value
->has_qom_path
) {
2765 monitor_printf(mon
, " qom_path: \"%s\"\n", l
->value
->qom_path
);
2768 c
= l
->value
->props
;
2769 monitor_printf(mon
, " CPUInstance Properties:\n");
2770 if (c
->has_node_id
) {
2771 monitor_printf(mon
, " node-id: \"%" PRIu64
"\"\n", c
->node_id
);
2773 if (c
->has_socket_id
) {
2774 monitor_printf(mon
, " socket-id: \"%" PRIu64
"\"\n", c
->socket_id
);
2776 if (c
->has_core_id
) {
2777 monitor_printf(mon
, " core-id: \"%" PRIu64
"\"\n", c
->core_id
);
2779 if (c
->has_thread_id
) {
2780 monitor_printf(mon
, " thread-id: \"%" PRIu64
"\"\n", c
->thread_id
);
2786 qapi_free_HotpluggableCPUList(saved
);
2789 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
2792 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
2794 monitor_printf(mon
, "%s\n", info
->guid
);
2796 hmp_handle_error(mon
, &err
);
2797 qapi_free_GuidInfo(info
);