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/qapi.h"
39 #include "qemu/cutils.h"
40 #include "qemu/error-report.h"
41 #include "hw/intc/intc.h"
44 #include <spice/enums.h>
47 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
51 error_report_err(*errp
);
55 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
59 info
= qmp_query_name(NULL
);
61 monitor_printf(mon
, "%s\n", info
->name
);
63 qapi_free_NameInfo(info
);
66 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
70 info
= qmp_query_version(NULL
);
72 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
73 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
76 qapi_free_VersionInfo(info
);
79 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
83 info
= qmp_query_kvm(NULL
);
84 monitor_printf(mon
, "kvm support: ");
86 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
88 monitor_printf(mon
, "not compiled\n");
91 qapi_free_KvmInfo(info
);
94 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
98 info
= qmp_query_status(NULL
);
100 monitor_printf(mon
, "VM status: %s%s",
101 info
->running
? "running" : "paused",
102 info
->singlestep
? " (single step mode)" : "");
104 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
105 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
108 monitor_printf(mon
, "\n");
110 qapi_free_StatusInfo(info
);
113 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
117 info
= qmp_query_uuid(NULL
);
118 monitor_printf(mon
, "%s\n", info
->UUID
);
119 qapi_free_UuidInfo(info
);
122 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
124 ChardevInfoList
*char_info
, *info
;
126 char_info
= qmp_query_chardev(NULL
);
127 for (info
= char_info
; info
; info
= info
->next
) {
128 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
129 info
->value
->filename
);
132 qapi_free_ChardevInfoList(char_info
);
135 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
137 MouseInfoList
*mice_list
, *mouse
;
139 mice_list
= qmp_query_mice(NULL
);
141 monitor_printf(mon
, "No mouse devices connected\n");
145 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
146 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
147 mouse
->value
->current
? '*' : ' ',
148 mouse
->value
->index
, mouse
->value
->name
,
149 mouse
->value
->absolute
? " (absolute)" : "");
152 qapi_free_MouseInfoList(mice_list
);
155 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
158 MigrationCapabilityStatusList
*caps
, *cap
;
160 info
= qmp_query_migrate(NULL
);
161 caps
= qmp_query_migrate_capabilities(NULL
);
163 /* do not display parameters during setup */
164 if (info
->has_status
&& caps
) {
165 monitor_printf(mon
, "capabilities: ");
166 for (cap
= caps
; cap
; cap
= cap
->next
) {
167 monitor_printf(mon
, "%s: %s ",
168 MigrationCapability_lookup
[cap
->value
->capability
],
169 cap
->value
->state
? "on" : "off");
171 monitor_printf(mon
, "\n");
174 if (info
->has_status
) {
175 monitor_printf(mon
, "Migration status: %s",
176 MigrationStatus_lookup
[info
->status
]);
177 if (info
->status
== MIGRATION_STATUS_FAILED
&&
178 info
->has_error_desc
) {
179 monitor_printf(mon
, " (%s)\n", info
->error_desc
);
181 monitor_printf(mon
, "\n");
184 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
186 if (info
->has_expected_downtime
) {
187 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
188 info
->expected_downtime
);
190 if (info
->has_downtime
) {
191 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
194 if (info
->has_setup_time
) {
195 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
201 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
202 info
->ram
->transferred
>> 10);
203 monitor_printf(mon
, "throughput: %0.2f mbps\n",
205 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
206 info
->ram
->remaining
>> 10);
207 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
208 info
->ram
->total
>> 10);
209 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
210 info
->ram
->duplicate
);
211 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
213 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
215 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
216 info
->ram
->normal_bytes
>> 10);
217 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
218 info
->ram
->dirty_sync_count
);
219 monitor_printf(mon
, "page size: %" PRIu64
" kbytes\n",
220 info
->ram
->page_size
>> 10);
222 if (info
->ram
->dirty_pages_rate
) {
223 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
224 info
->ram
->dirty_pages_rate
);
226 if (info
->ram
->postcopy_requests
) {
227 monitor_printf(mon
, "postcopy request count: %" PRIu64
"\n",
228 info
->ram
->postcopy_requests
);
232 if (info
->has_disk
) {
233 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
234 info
->disk
->transferred
>> 10);
235 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
236 info
->disk
->remaining
>> 10);
237 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
238 info
->disk
->total
>> 10);
241 if (info
->has_xbzrle_cache
) {
242 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
243 info
->xbzrle_cache
->cache_size
);
244 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
245 info
->xbzrle_cache
->bytes
>> 10);
246 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
247 info
->xbzrle_cache
->pages
);
248 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
249 info
->xbzrle_cache
->cache_miss
);
250 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
251 info
->xbzrle_cache
->cache_miss_rate
);
252 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
253 info
->xbzrle_cache
->overflow
);
256 if (info
->has_cpu_throttle_percentage
) {
257 monitor_printf(mon
, "cpu throttle percentage: %" PRIu64
"\n",
258 info
->cpu_throttle_percentage
);
261 qapi_free_MigrationInfo(info
);
262 qapi_free_MigrationCapabilityStatusList(caps
);
265 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
267 MigrationCapabilityStatusList
*caps
, *cap
;
269 caps
= qmp_query_migrate_capabilities(NULL
);
272 for (cap
= caps
; cap
; cap
= cap
->next
) {
273 monitor_printf(mon
, "%s: %s\n",
274 MigrationCapability_lookup
[cap
->value
->capability
],
275 cap
->value
->state
? "on" : "off");
279 qapi_free_MigrationCapabilityStatusList(caps
);
282 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
284 MigrationParameters
*params
;
286 params
= qmp_query_migrate_parameters(NULL
);
289 assert(params
->has_compress_level
);
290 monitor_printf(mon
, "%s: %" PRId64
"\n",
291 MigrationParameter_lookup
[MIGRATION_PARAMETER_COMPRESS_LEVEL
],
292 params
->compress_level
);
293 assert(params
->has_compress_threads
);
294 monitor_printf(mon
, "%s: %" PRId64
"\n",
295 MigrationParameter_lookup
[MIGRATION_PARAMETER_COMPRESS_THREADS
],
296 params
->compress_threads
);
297 assert(params
->has_decompress_threads
);
298 monitor_printf(mon
, "%s: %" PRId64
"\n",
299 MigrationParameter_lookup
[MIGRATION_PARAMETER_DECOMPRESS_THREADS
],
300 params
->decompress_threads
);
301 assert(params
->has_cpu_throttle_initial
);
302 monitor_printf(mon
, "%s: %" PRId64
"\n",
303 MigrationParameter_lookup
[MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
],
304 params
->cpu_throttle_initial
);
305 assert(params
->has_cpu_throttle_increment
);
306 monitor_printf(mon
, "%s: %" PRId64
"\n",
307 MigrationParameter_lookup
[MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
],
308 params
->cpu_throttle_increment
);
309 monitor_printf(mon
, "%s: '%s'\n",
310 MigrationParameter_lookup
[MIGRATION_PARAMETER_TLS_CREDS
],
311 params
->has_tls_creds
? params
->tls_creds
: "");
312 monitor_printf(mon
, "%s: '%s'\n",
313 MigrationParameter_lookup
[MIGRATION_PARAMETER_TLS_HOSTNAME
],
314 params
->has_tls_hostname
? params
->tls_hostname
: "");
315 assert(params
->has_max_bandwidth
);
316 monitor_printf(mon
, "%s: %" PRId64
" bytes/second\n",
317 MigrationParameter_lookup
[MIGRATION_PARAMETER_MAX_BANDWIDTH
],
318 params
->max_bandwidth
);
319 assert(params
->has_downtime_limit
);
320 monitor_printf(mon
, "%s: %" PRId64
" milliseconds\n",
321 MigrationParameter_lookup
[MIGRATION_PARAMETER_DOWNTIME_LIMIT
],
322 params
->downtime_limit
);
323 assert(params
->has_x_checkpoint_delay
);
324 monitor_printf(mon
, "%s: %" PRId64
"\n",
325 MigrationParameter_lookup
[MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
],
326 params
->x_checkpoint_delay
);
329 qapi_free_MigrationParameters(params
);
332 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
334 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
335 qmp_query_migrate_cache_size(NULL
) >> 10);
338 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
340 CpuInfoList
*cpu_list
, *cpu
;
342 cpu_list
= qmp_query_cpus(NULL
);
344 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
347 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
351 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
353 switch (cpu
->value
->arch
) {
354 case CPU_INFO_ARCH_X86
:
355 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->u
.x86
.pc
);
357 case CPU_INFO_ARCH_PPC
:
358 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->u
.ppc
.nip
);
360 case CPU_INFO_ARCH_SPARC
:
361 monitor_printf(mon
, " pc=0x%016" PRIx64
,
362 cpu
->value
->u
.q_sparc
.pc
);
363 monitor_printf(mon
, " npc=0x%016" PRIx64
,
364 cpu
->value
->u
.q_sparc
.npc
);
366 case CPU_INFO_ARCH_MIPS
:
367 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.q_mips
.PC
);
369 case CPU_INFO_ARCH_TRICORE
:
370 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.tricore
.PC
);
376 if (cpu
->value
->halted
) {
377 monitor_printf(mon
, " (halted)");
380 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
383 qapi_free_CpuInfoList(cpu_list
);
386 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
387 BlockDeviceInfo
*inserted
, bool verbose
)
389 ImageInfo
*image_info
;
391 assert(!info
|| !info
->has_inserted
|| info
->inserted
== inserted
);
394 monitor_printf(mon
, "%s", info
->device
);
395 if (inserted
&& inserted
->has_node_name
) {
396 monitor_printf(mon
, " (%s)", inserted
->node_name
);
400 monitor_printf(mon
, "%s",
401 inserted
->has_node_name
402 ? inserted
->node_name
407 monitor_printf(mon
, ": %s (%s%s%s)\n",
410 inserted
->ro
? ", read-only" : "",
411 inserted
->encrypted
? ", encrypted" : "");
413 monitor_printf(mon
, ": [not inserted]\n");
417 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
418 monitor_printf(mon
, " I/O status: %s\n",
419 BlockDeviceIoStatus_lookup
[info
->io_status
]);
422 if (info
->removable
) {
423 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
424 info
->locked
? "" : "not ",
425 info
->tray_open
? "open" : "closed");
434 monitor_printf(mon
, " Cache mode: %s%s%s\n",
435 inserted
->cache
->writeback
? "writeback" : "writethrough",
436 inserted
->cache
->direct
? ", direct" : "",
437 inserted
->cache
->no_flush
? ", ignore flushes" : "");
439 if (inserted
->has_backing_file
) {
442 "(chain depth: %" PRId64
")\n",
443 inserted
->backing_file
,
444 inserted
->backing_file_depth
);
447 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
448 monitor_printf(mon
, " Detect zeroes: %s\n",
449 BlockdevDetectZeroesOptions_lookup
[inserted
->detect_zeroes
]);
452 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
453 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
455 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
456 " bps_rd=%" PRId64
" bps_wr=%" PRId64
458 " bps_rd_max=%" PRId64
459 " bps_wr_max=%" PRId64
460 " iops=%" PRId64
" iops_rd=%" PRId64
463 " iops_rd_max=%" PRId64
464 " iops_wr_max=%" PRId64
465 " iops_size=%" PRId64
471 inserted
->bps_rd_max
,
472 inserted
->bps_wr_max
,
477 inserted
->iops_rd_max
,
478 inserted
->iops_wr_max
,
484 monitor_printf(mon
, "\nImages:\n");
485 image_info
= inserted
->image
;
487 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
489 if (image_info
->has_backing_image
) {
490 image_info
= image_info
->backing_image
;
498 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
500 BlockInfoList
*block_list
, *info
;
501 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
502 const char *device
= qdict_get_try_str(qdict
, "device");
503 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
504 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
505 bool printed
= false;
507 /* Print BlockBackend information */
509 block_list
= qmp_query_block(NULL
);
514 for (info
= block_list
; info
; info
= info
->next
) {
515 if (device
&& strcmp(device
, info
->value
->device
)) {
519 if (info
!= block_list
) {
520 monitor_printf(mon
, "\n");
523 print_block_info(mon
, info
->value
, info
->value
->has_inserted
524 ? info
->value
->inserted
: NULL
,
529 qapi_free_BlockInfoList(block_list
);
531 if ((!device
&& !nodes
) || printed
) {
535 /* Print node information */
536 blockdev_list
= qmp_query_named_block_nodes(NULL
);
537 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
538 assert(blockdev
->value
->has_node_name
);
539 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
543 if (blockdev
!= blockdev_list
) {
544 monitor_printf(mon
, "\n");
547 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
549 qapi_free_BlockDeviceInfoList(blockdev_list
);
552 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
554 BlockStatsList
*stats_list
, *stats
;
556 stats_list
= qmp_query_blockstats(false, false, NULL
);
558 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
559 if (!stats
->value
->has_device
) {
563 monitor_printf(mon
, "%s:", stats
->value
->device
);
564 monitor_printf(mon
, " rd_bytes=%" PRId64
566 " rd_operations=%" PRId64
567 " wr_operations=%" PRId64
568 " flush_operations=%" PRId64
569 " wr_total_time_ns=%" PRId64
570 " rd_total_time_ns=%" PRId64
571 " flush_total_time_ns=%" PRId64
572 " rd_merged=%" PRId64
573 " wr_merged=%" PRId64
574 " idle_time_ns=%" PRId64
576 stats
->value
->stats
->rd_bytes
,
577 stats
->value
->stats
->wr_bytes
,
578 stats
->value
->stats
->rd_operations
,
579 stats
->value
->stats
->wr_operations
,
580 stats
->value
->stats
->flush_operations
,
581 stats
->value
->stats
->wr_total_time_ns
,
582 stats
->value
->stats
->rd_total_time_ns
,
583 stats
->value
->stats
->flush_total_time_ns
,
584 stats
->value
->stats
->rd_merged
,
585 stats
->value
->stats
->wr_merged
,
586 stats
->value
->stats
->idle_time_ns
);
589 qapi_free_BlockStatsList(stats_list
);
592 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
596 VncClientInfoList
*client
;
598 info
= qmp_query_vnc(&err
);
600 error_report_err(err
);
604 if (!info
->enabled
) {
605 monitor_printf(mon
, "Server: disabled\n");
609 monitor_printf(mon
, "Server:\n");
610 if (info
->has_host
&& info
->has_service
) {
611 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
613 if (info
->has_auth
) {
614 monitor_printf(mon
, " auth: %s\n", info
->auth
);
617 if (!info
->has_clients
|| info
->clients
== NULL
) {
618 monitor_printf(mon
, "Client: none\n");
620 for (client
= info
->clients
; client
; client
= client
->next
) {
621 monitor_printf(mon
, "Client:\n");
622 monitor_printf(mon
, " address: %s:%s\n",
624 client
->value
->service
);
625 monitor_printf(mon
, " x509_dname: %s\n",
626 client
->value
->x509_dname
?
627 client
->value
->x509_dname
: "none");
628 monitor_printf(mon
, " username: %s\n",
629 client
->value
->has_sasl_username
?
630 client
->value
->sasl_username
: "none");
635 qapi_free_VncInfo(info
);
639 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
641 SpiceChannelList
*chan
;
643 const char *channel_name
;
644 const char * const channel_names
[] = {
645 [SPICE_CHANNEL_MAIN
] = "main",
646 [SPICE_CHANNEL_DISPLAY
] = "display",
647 [SPICE_CHANNEL_INPUTS
] = "inputs",
648 [SPICE_CHANNEL_CURSOR
] = "cursor",
649 [SPICE_CHANNEL_PLAYBACK
] = "playback",
650 [SPICE_CHANNEL_RECORD
] = "record",
651 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
652 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
653 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
654 [SPICE_CHANNEL_PORT
] = "port",
656 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
657 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
658 * as quick fix for build failures with older versions. */
659 [SPICE_CHANNEL_WEBDAV
] = "webdav",
663 info
= qmp_query_spice(NULL
);
665 if (!info
->enabled
) {
666 monitor_printf(mon
, "Server: disabled\n");
670 monitor_printf(mon
, "Server:\n");
671 if (info
->has_port
) {
672 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
673 info
->host
, info
->port
);
675 if (info
->has_tls_port
) {
676 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
677 info
->host
, info
->tls_port
);
679 monitor_printf(mon
, " migrated: %s\n",
680 info
->migrated
? "true" : "false");
681 monitor_printf(mon
, " auth: %s\n", info
->auth
);
682 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
683 monitor_printf(mon
, " mouse-mode: %s\n",
684 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
686 if (!info
->has_channels
|| info
->channels
== NULL
) {
687 monitor_printf(mon
, "Channels: none\n");
689 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
690 monitor_printf(mon
, "Channel:\n");
691 monitor_printf(mon
, " address: %s:%s%s\n",
692 chan
->value
->host
, chan
->value
->port
,
693 chan
->value
->tls
? " [tls]" : "");
694 monitor_printf(mon
, " session: %" PRId64
"\n",
695 chan
->value
->connection_id
);
696 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
697 chan
->value
->channel_type
, chan
->value
->channel_id
);
699 channel_name
= "unknown";
700 if (chan
->value
->channel_type
> 0 &&
701 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
702 channel_names
[chan
->value
->channel_type
]) {
703 channel_name
= channel_names
[chan
->value
->channel_type
];
706 monitor_printf(mon
, " channel name: %s\n", channel_name
);
711 qapi_free_SpiceInfo(info
);
715 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
720 info
= qmp_query_balloon(&err
);
722 error_report_err(err
);
726 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
728 qapi_free_BalloonInfo(info
);
731 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
733 PciMemoryRegionList
*region
;
735 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
736 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
737 dev
->slot
, dev
->function
);
738 monitor_printf(mon
, " ");
740 if (dev
->class_info
->has_desc
) {
741 monitor_printf(mon
, "%s", dev
->class_info
->desc
);
743 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
746 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
747 dev
->id
->vendor
, dev
->id
->device
);
750 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
753 if (dev
->has_pci_bridge
) {
754 monitor_printf(mon
, " BUS %" PRId64
".\n",
755 dev
->pci_bridge
->bus
->number
);
756 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
757 dev
->pci_bridge
->bus
->secondary
);
758 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
759 dev
->pci_bridge
->bus
->subordinate
);
761 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
762 dev
->pci_bridge
->bus
->io_range
->base
,
763 dev
->pci_bridge
->bus
->io_range
->limit
);
766 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
767 dev
->pci_bridge
->bus
->memory_range
->base
,
768 dev
->pci_bridge
->bus
->memory_range
->limit
);
770 monitor_printf(mon
, " prefetchable memory range "
771 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
772 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
773 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
776 for (region
= dev
->regions
; region
; region
= region
->next
) {
779 addr
= region
->value
->address
;
780 size
= region
->value
->size
;
782 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
784 if (!strcmp(region
->value
->type
, "io")) {
785 monitor_printf(mon
, "I/O at 0x%04" PRIx64
786 " [0x%04" PRIx64
"].\n",
787 addr
, addr
+ size
- 1);
789 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
790 " [0x%08" PRIx64
"].\n",
791 region
->value
->mem_type_64
? 64 : 32,
792 region
->value
->prefetch
? " prefetchable" : "",
793 addr
, addr
+ size
- 1);
797 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
799 if (dev
->has_pci_bridge
) {
800 if (dev
->pci_bridge
->has_devices
) {
801 PciDeviceInfoList
*cdev
;
802 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
803 hmp_info_pci_device(mon
, cdev
->value
);
809 static int hmp_info_irq_foreach(Object
*obj
, void *opaque
)
811 InterruptStatsProvider
*intc
;
812 InterruptStatsProviderClass
*k
;
813 Monitor
*mon
= opaque
;
815 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
816 intc
= INTERRUPT_STATS_PROVIDER(obj
);
817 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
818 uint64_t *irq_counts
;
819 unsigned int nb_irqs
, i
;
820 if (k
->get_statistics
&&
821 k
->get_statistics(intc
, &irq_counts
, &nb_irqs
)) {
823 monitor_printf(mon
, "IRQ statistics for %s:\n",
824 object_get_typename(obj
));
825 for (i
= 0; i
< nb_irqs
; i
++) {
826 if (irq_counts
[i
] > 0) {
827 monitor_printf(mon
, "%2d: %" PRId64
"\n", i
,
833 monitor_printf(mon
, "IRQ statistics not available for %s.\n",
834 object_get_typename(obj
));
841 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
)
843 object_child_foreach_recursive(object_get_root(),
844 hmp_info_irq_foreach
, mon
);
847 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
849 InterruptStatsProvider
*intc
;
850 InterruptStatsProviderClass
*k
;
851 Monitor
*mon
= opaque
;
853 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
854 intc
= INTERRUPT_STATS_PROVIDER(obj
);
855 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
857 k
->print_info(intc
, mon
);
859 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
860 object_get_typename(obj
));
867 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
869 object_child_foreach_recursive(object_get_root(),
870 hmp_info_pic_foreach
, mon
);
873 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
875 PciInfoList
*info_list
, *info
;
878 info_list
= qmp_query_pci(&err
);
880 monitor_printf(mon
, "PCI devices not supported\n");
885 for (info
= info_list
; info
; info
= info
->next
) {
886 PciDeviceInfoList
*dev
;
888 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
889 hmp_info_pci_device(mon
, dev
->value
);
893 qapi_free_PciInfoList(info_list
);
896 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
898 BlockJobInfoList
*list
;
901 list
= qmp_query_block_jobs(&err
);
905 monitor_printf(mon
, "No active jobs\n");
910 if (strcmp(list
->value
->type
, "stream") == 0) {
911 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
912 " of %" PRId64
" bytes, speed limit %" PRId64
919 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
920 " of %" PRId64
" bytes, speed limit %" PRId64
931 qapi_free_BlockJobInfoList(list
);
934 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
936 TPMInfoList
*info_list
, *info
;
939 TPMPassthroughOptions
*tpo
;
941 info_list
= qmp_query_tpm(&err
);
943 monitor_printf(mon
, "TPM device not supported\n");
949 monitor_printf(mon
, "TPM device:\n");
952 for (info
= info_list
; info
; info
= info
->next
) {
953 TPMInfo
*ti
= info
->value
;
954 monitor_printf(mon
, " tpm%d: model=%s\n",
955 c
, TpmModel_lookup
[ti
->model
]);
957 monitor_printf(mon
, " \\ %s: type=%s",
958 ti
->id
, TpmTypeOptionsKind_lookup
[ti
->options
->type
]);
960 switch (ti
->options
->type
) {
961 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
962 tpo
= ti
->options
->u
.passthrough
.data
;
963 monitor_printf(mon
, "%s%s%s%s",
964 tpo
->has_path
? ",path=" : "",
965 tpo
->has_path
? tpo
->path
: "",
966 tpo
->has_cancel_path
? ",cancel-path=" : "",
967 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
969 case TPM_TYPE_OPTIONS_KIND__MAX
:
972 monitor_printf(mon
, "\n");
975 qapi_free_TPMInfoList(info_list
);
978 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
980 monitor_suspend(mon
);
984 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
989 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
991 qmp_system_reset(NULL
);
994 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
996 qmp_system_powerdown(NULL
);
999 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
1003 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1004 use it are converted to the QAPI */
1005 cpu_index
= qdict_get_int(qdict
, "index");
1006 if (monitor_set_cpu(cpu_index
) < 0) {
1007 monitor_printf(mon
, "invalid CPU index\n");
1011 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
1013 uint32_t size
= qdict_get_int(qdict
, "size");
1014 const char *filename
= qdict_get_str(qdict
, "filename");
1015 uint64_t addr
= qdict_get_int(qdict
, "val");
1017 int cpu_index
= monitor_get_cpu_index();
1019 if (cpu_index
< 0) {
1020 monitor_printf(mon
, "No CPU available\n");
1024 qmp_memsave(addr
, size
, filename
, true, cpu_index
, &err
);
1025 hmp_handle_error(mon
, &err
);
1028 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
1030 uint32_t size
= qdict_get_int(qdict
, "size");
1031 const char *filename
= qdict_get_str(qdict
, "filename");
1032 uint64_t addr
= qdict_get_int(qdict
, "val");
1035 qmp_pmemsave(addr
, size
, filename
, &err
);
1036 hmp_handle_error(mon
, &err
);
1039 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
1041 const char *chardev
= qdict_get_str(qdict
, "device");
1042 const char *data
= qdict_get_str(qdict
, "data");
1045 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
1047 hmp_handle_error(mon
, &err
);
1050 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
1052 uint32_t size
= qdict_get_int(qdict
, "size");
1053 const char *chardev
= qdict_get_str(qdict
, "device");
1058 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
1060 error_report_err(err
);
1064 for (i
= 0; data
[i
]; i
++) {
1065 unsigned char ch
= data
[i
];
1068 monitor_printf(mon
, "\\\\");
1069 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
1070 monitor_printf(mon
, "\\u%04X", ch
);
1072 monitor_printf(mon
, "%c", ch
);
1076 monitor_printf(mon
, "\n");
1080 static void hmp_cont_cb(void *opaque
, int err
)
1087 static bool key_is_missing(const BlockInfo
*bdev
)
1089 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
1092 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
1094 BlockInfoList
*bdev_list
, *bdev
;
1097 bdev_list
= qmp_query_block(NULL
);
1098 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
1099 if (key_is_missing(bdev
->value
)) {
1100 monitor_read_block_device_key(mon
, bdev
->value
->device
,
1107 hmp_handle_error(mon
, &err
);
1110 qapi_free_BlockInfoList(bdev_list
);
1113 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
1115 qmp_system_wakeup(NULL
);
1118 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
1122 qmp_inject_nmi(&err
);
1123 hmp_handle_error(mon
, &err
);
1126 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
1128 const char *name
= qdict_get_str(qdict
, "name");
1129 bool up
= qdict_get_bool(qdict
, "up");
1132 qmp_set_link(name
, up
, &err
);
1133 hmp_handle_error(mon
, &err
);
1136 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
1138 const char *device
= qdict_get_str(qdict
, "device");
1139 const char *password
= qdict_get_str(qdict
, "password");
1142 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
1143 hmp_handle_error(mon
, &err
);
1146 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1148 int64_t value
= qdict_get_int(qdict
, "value");
1151 qmp_balloon(value
, &err
);
1153 error_report_err(err
);
1157 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
1159 const char *device
= qdict_get_str(qdict
, "device");
1160 int64_t size
= qdict_get_int(qdict
, "size");
1163 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
1164 hmp_handle_error(mon
, &err
);
1167 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
1169 const char *filename
= qdict_get_str(qdict
, "target");
1170 const char *format
= qdict_get_try_str(qdict
, "format");
1171 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1172 bool full
= qdict_get_try_bool(qdict
, "full", false);
1174 DriveMirror mirror
= {
1175 .device
= (char *)qdict_get_str(qdict
, "device"),
1176 .target
= (char *)filename
,
1177 .has_format
= !!format
,
1178 .format
= (char *)format
,
1179 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1181 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1186 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1187 hmp_handle_error(mon
, &err
);
1190 qmp_drive_mirror(&mirror
, &err
);
1191 hmp_handle_error(mon
, &err
);
1194 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
1196 const char *device
= qdict_get_str(qdict
, "device");
1197 const char *filename
= qdict_get_str(qdict
, "target");
1198 const char *format
= qdict_get_try_str(qdict
, "format");
1199 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1200 bool full
= qdict_get_try_bool(qdict
, "full", false);
1201 bool compress
= qdict_get_try_bool(qdict
, "compress", false);
1203 DriveBackup backup
= {
1204 .device
= (char *)device
,
1205 .target
= (char *)filename
,
1206 .has_format
= !!format
,
1207 .format
= (char *)format
,
1208 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1210 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1211 .has_compress
= !!compress
,
1212 .compress
= compress
,
1216 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1217 hmp_handle_error(mon
, &err
);
1221 qmp_drive_backup(&backup
, &err
);
1222 hmp_handle_error(mon
, &err
);
1225 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
1227 const char *device
= qdict_get_str(qdict
, "device");
1228 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
1229 const char *format
= qdict_get_try_str(qdict
, "format");
1230 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1231 enum NewImageMode mode
;
1235 /* In the future, if 'snapshot-file' is not specified, the snapshot
1236 will be taken internally. Today it's actually required. */
1237 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
1238 hmp_handle_error(mon
, &err
);
1242 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1243 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
1244 filename
, false, NULL
,
1247 hmp_handle_error(mon
, &err
);
1250 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1252 const char *device
= qdict_get_str(qdict
, "device");
1253 const char *name
= qdict_get_str(qdict
, "name");
1256 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1257 hmp_handle_error(mon
, &err
);
1260 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1262 const char *device
= qdict_get_str(qdict
, "device");
1263 const char *name
= qdict_get_str(qdict
, "name");
1264 const char *id
= qdict_get_try_str(qdict
, "id");
1267 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1269 hmp_handle_error(mon
, &err
);
1272 void hmp_loadvm(Monitor
*mon
, const QDict
*qdict
)
1274 int saved_vm_running
= runstate_is_running();
1275 const char *name
= qdict_get_str(qdict
, "name");
1277 vm_stop(RUN_STATE_RESTORE_VM
);
1279 if (load_vmstate(name
) == 0 && saved_vm_running
) {
1284 void hmp_savevm(Monitor
*mon
, const QDict
*qdict
)
1286 save_vmstate(qdict_get_try_str(qdict
, "name"));
1289 void hmp_delvm(Monitor
*mon
, const QDict
*qdict
)
1291 BlockDriverState
*bs
;
1293 const char *name
= qdict_get_str(qdict
, "name");
1295 if (bdrv_all_delete_snapshot(name
, &bs
, &err
) < 0) {
1296 error_reportf_err(err
,
1297 "Error while deleting snapshot on device '%s': ",
1298 bdrv_get_device_name(bs
));
1302 void hmp_info_snapshots(Monitor
*mon
, const QDict
*qdict
)
1304 BlockDriverState
*bs
, *bs1
;
1305 BdrvNextIterator it1
;
1306 QEMUSnapshotInfo
*sn_tab
, *sn
;
1307 bool no_snapshot
= true;
1310 int *global_snapshots
;
1311 AioContext
*aio_context
;
1313 typedef struct SnapshotEntry
{
1314 QEMUSnapshotInfo sn
;
1315 QTAILQ_ENTRY(SnapshotEntry
) next
;
1318 typedef struct ImageEntry
{
1319 const char *imagename
;
1320 QTAILQ_ENTRY(ImageEntry
) next
;
1321 QTAILQ_HEAD(, SnapshotEntry
) snapshots
;
1324 QTAILQ_HEAD(, ImageEntry
) image_list
=
1325 QTAILQ_HEAD_INITIALIZER(image_list
);
1327 ImageEntry
*image_entry
, *next_ie
;
1328 SnapshotEntry
*snapshot_entry
;
1330 bs
= bdrv_all_find_vmstate_bs();
1332 monitor_printf(mon
, "No available block device supports snapshots\n");
1335 aio_context
= bdrv_get_aio_context(bs
);
1337 aio_context_acquire(aio_context
);
1338 nb_sns
= bdrv_snapshot_list(bs
, &sn_tab
);
1339 aio_context_release(aio_context
);
1342 monitor_printf(mon
, "bdrv_snapshot_list: error %d\n", nb_sns
);
1346 for (bs1
= bdrv_first(&it1
); bs1
; bs1
= bdrv_next(&it1
)) {
1350 AioContext
*ctx
= bdrv_get_aio_context(bs1
);
1352 aio_context_acquire(ctx
);
1353 if (bdrv_can_snapshot(bs1
)) {
1355 bs1_nb_sns
= bdrv_snapshot_list(bs1
, &sn
);
1356 if (bs1_nb_sns
> 0) {
1357 no_snapshot
= false;
1358 ie
= g_new0(ImageEntry
, 1);
1359 ie
->imagename
= bdrv_get_device_name(bs1
);
1360 QTAILQ_INIT(&ie
->snapshots
);
1361 QTAILQ_INSERT_TAIL(&image_list
, ie
, next
);
1362 for (i
= 0; i
< bs1_nb_sns
; i
++) {
1363 se
= g_new0(SnapshotEntry
, 1);
1365 QTAILQ_INSERT_TAIL(&ie
->snapshots
, se
, next
);
1370 aio_context_release(ctx
);
1374 monitor_printf(mon
, "There is no snapshot available.\n");
1378 global_snapshots
= g_new0(int, nb_sns
);
1380 for (i
= 0; i
< nb_sns
; i
++) {
1381 SnapshotEntry
*next_sn
;
1382 if (bdrv_all_find_snapshot(sn_tab
[i
].name
, &bs1
) == 0) {
1383 global_snapshots
[total
] = i
;
1385 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1386 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
,
1388 if (!strcmp(sn_tab
[i
].name
, snapshot_entry
->sn
.name
)) {
1389 QTAILQ_REMOVE(&image_entry
->snapshots
, snapshot_entry
,
1391 g_free(snapshot_entry
);
1398 monitor_printf(mon
, "List of snapshots present on all disks:\n");
1401 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1402 monitor_printf(mon
, "\n");
1403 for (i
= 0; i
< total
; i
++) {
1404 sn
= &sn_tab
[global_snapshots
[i
]];
1405 /* The ID is not guaranteed to be the same on all images, so
1408 pstrcpy(sn
->id_str
, sizeof(sn
->id_str
), "--");
1409 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, sn
);
1410 monitor_printf(mon
, "\n");
1413 monitor_printf(mon
, "None\n");
1416 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1417 if (QTAILQ_EMPTY(&image_entry
->snapshots
)) {
1421 "\nList of partial (non-loadable) snapshots on '%s':\n",
1422 image_entry
->imagename
);
1423 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
, NULL
);
1424 monitor_printf(mon
, "\n");
1425 QTAILQ_FOREACH(snapshot_entry
, &image_entry
->snapshots
, next
) {
1426 bdrv_snapshot_dump((fprintf_function
)monitor_printf
, mon
,
1427 &snapshot_entry
->sn
);
1428 monitor_printf(mon
, "\n");
1432 QTAILQ_FOREACH_SAFE(image_entry
, &image_list
, next
, next_ie
) {
1433 SnapshotEntry
*next_sn
;
1434 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
, next
,
1436 g_free(snapshot_entry
);
1438 g_free(image_entry
);
1441 g_free(global_snapshots
);
1445 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1447 qmp_migrate_cancel(NULL
);
1450 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1453 const char *uri
= qdict_get_str(qdict
, "uri");
1455 qmp_migrate_incoming(uri
, &err
);
1457 hmp_handle_error(mon
, &err
);
1460 /* Kept for backwards compatibility */
1461 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1463 double value
= qdict_get_double(qdict
, "value");
1464 qmp_migrate_set_downtime(value
, NULL
);
1467 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1469 int64_t value
= qdict_get_int(qdict
, "value");
1472 qmp_migrate_set_cache_size(value
, &err
);
1474 error_report_err(err
);
1479 /* Kept for backwards compatibility */
1480 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1482 int64_t value
= qdict_get_int(qdict
, "value");
1483 qmp_migrate_set_speed(value
, NULL
);
1486 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1488 const char *cap
= qdict_get_str(qdict
, "capability");
1489 bool state
= qdict_get_bool(qdict
, "state");
1491 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1494 for (i
= 0; i
< MIGRATION_CAPABILITY__MAX
; i
++) {
1495 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
1496 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1497 caps
->value
->capability
= i
;
1498 caps
->value
->state
= state
;
1500 qmp_migrate_set_capabilities(caps
, &err
);
1505 if (i
== MIGRATION_CAPABILITY__MAX
) {
1506 error_setg(&err
, QERR_INVALID_PARAMETER
, cap
);
1509 qapi_free_MigrationCapabilityStatusList(caps
);
1512 error_report_err(err
);
1516 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1518 const char *param
= qdict_get_str(qdict
, "parameter");
1519 const char *valuestr
= qdict_get_str(qdict
, "value");
1520 uint64_t valuebw
= 0;
1523 bool use_int_value
= false;
1526 for (i
= 0; i
< MIGRATION_PARAMETER__MAX
; i
++) {
1527 if (strcmp(param
, MigrationParameter_lookup
[i
]) == 0) {
1528 MigrationParameters p
= { 0 };
1530 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1531 p
.has_compress_level
= true;
1532 use_int_value
= true;
1534 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1535 p
.has_compress_threads
= true;
1536 use_int_value
= true;
1538 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1539 p
.has_decompress_threads
= true;
1540 use_int_value
= true;
1542 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1543 p
.has_cpu_throttle_initial
= true;
1544 use_int_value
= true;
1546 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1547 p
.has_cpu_throttle_increment
= true;
1548 use_int_value
= true;
1550 case MIGRATION_PARAMETER_TLS_CREDS
:
1551 p
.has_tls_creds
= true;
1552 p
.tls_creds
= (char *) valuestr
;
1554 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1555 p
.has_tls_hostname
= true;
1556 p
.tls_hostname
= (char *) valuestr
;
1558 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1559 p
.has_max_bandwidth
= true;
1560 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
1561 if (ret
< 0 || valuebw
> INT64_MAX
1562 || (size_t)valuebw
!= valuebw
) {
1563 error_setg(&err
, "Invalid size %s", valuestr
);
1566 p
.max_bandwidth
= valuebw
;
1568 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1569 p
.has_downtime_limit
= true;
1570 use_int_value
= true;
1572 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
1573 p
.has_x_checkpoint_delay
= true;
1574 use_int_value
= true;
1578 if (use_int_value
) {
1579 if (qemu_strtol(valuestr
, NULL
, 10, &valueint
) < 0) {
1580 error_setg(&err
, "Unable to parse '%s' as an int",
1584 /* Set all integers; only one has_FOO will be set, and
1585 * the code ignores the remaining values */
1586 p
.compress_level
= valueint
;
1587 p
.compress_threads
= valueint
;
1588 p
.decompress_threads
= valueint
;
1589 p
.cpu_throttle_initial
= valueint
;
1590 p
.cpu_throttle_increment
= valueint
;
1591 p
.downtime_limit
= valueint
;
1592 p
.x_checkpoint_delay
= valueint
;
1595 qmp_migrate_set_parameters(&p
, &err
);
1600 if (i
== MIGRATION_PARAMETER__MAX
) {
1601 error_setg(&err
, QERR_INVALID_PARAMETER
, param
);
1606 error_report_err(err
);
1610 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1613 const char *protocol
= qdict_get_str(qdict
, "protocol");
1614 const char *hostname
= qdict_get_str(qdict
, "hostname");
1615 bool has_port
= qdict_haskey(qdict
, "port");
1616 int port
= qdict_get_try_int(qdict
, "port", -1);
1617 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1618 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1619 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1621 qmp_client_migrate_info(protocol
, hostname
,
1622 has_port
, port
, has_tls_port
, tls_port
,
1623 !!cert_subject
, cert_subject
, &err
);
1624 hmp_handle_error(mon
, &err
);
1627 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1630 qmp_migrate_start_postcopy(&err
);
1631 hmp_handle_error(mon
, &err
);
1634 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1638 qmp_x_colo_lost_heartbeat(&err
);
1639 hmp_handle_error(mon
, &err
);
1642 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1644 const char *protocol
= qdict_get_str(qdict
, "protocol");
1645 const char *password
= qdict_get_str(qdict
, "password");
1646 const char *connected
= qdict_get_try_str(qdict
, "connected");
1649 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1650 hmp_handle_error(mon
, &err
);
1653 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1655 const char *protocol
= qdict_get_str(qdict
, "protocol");
1656 const char *whenstr
= qdict_get_str(qdict
, "time");
1659 qmp_expire_password(protocol
, whenstr
, &err
);
1660 hmp_handle_error(mon
, &err
);
1663 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1665 bool force
= qdict_get_try_bool(qdict
, "force", false);
1666 const char *device
= qdict_get_str(qdict
, "device");
1669 qmp_eject(true, device
, false, NULL
, true, force
, &err
);
1670 hmp_handle_error(mon
, &err
);
1673 static void hmp_change_read_arg(void *opaque
, const char *password
,
1674 void *readline_opaque
)
1676 qmp_change_vnc_password(password
, NULL
);
1677 monitor_read_command(opaque
, 1);
1680 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1682 const char *device
= qdict_get_str(qdict
, "device");
1683 const char *target
= qdict_get_str(qdict
, "target");
1684 const char *arg
= qdict_get_try_str(qdict
, "arg");
1685 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1686 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1689 if (strcmp(device
, "vnc") == 0) {
1692 "Parameter 'read-only-mode' is invalid for VNC\n");
1695 if (strcmp(target
, "passwd") == 0 ||
1696 strcmp(target
, "password") == 0) {
1698 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1702 qmp_change("vnc", target
, !!arg
, arg
, &err
);
1706 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup
,
1707 read_only
, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX
,
1708 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1710 hmp_handle_error(mon
, &err
);
1715 qmp_blockdev_change_medium(true, device
, false, NULL
, target
,
1716 !!arg
, arg
, !!read_only
, read_only_mode
,
1719 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
1721 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
1726 hmp_handle_error(mon
, &err
);
1729 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1732 BlockIOThrottle throttle
= {
1734 .device
= (char *) qdict_get_str(qdict
, "device"),
1735 .bps
= qdict_get_int(qdict
, "bps"),
1736 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
1737 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
1738 .iops
= qdict_get_int(qdict
, "iops"),
1739 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
1740 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
1743 qmp_block_set_io_throttle(&throttle
, &err
);
1744 hmp_handle_error(mon
, &err
);
1747 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1749 Error
*error
= NULL
;
1750 const char *device
= qdict_get_str(qdict
, "device");
1751 const char *base
= qdict_get_try_str(qdict
, "base");
1752 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1754 qmp_block_stream(true, device
, device
, base
!= NULL
, base
, false, NULL
,
1755 false, NULL
, qdict_haskey(qdict
, "speed"), speed
,
1756 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1758 hmp_handle_error(mon
, &error
);
1761 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1763 Error
*error
= NULL
;
1764 const char *device
= qdict_get_str(qdict
, "device");
1765 int64_t value
= qdict_get_int(qdict
, "speed");
1767 qmp_block_job_set_speed(device
, value
, &error
);
1769 hmp_handle_error(mon
, &error
);
1772 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1774 Error
*error
= NULL
;
1775 const char *device
= qdict_get_str(qdict
, "device");
1776 bool force
= qdict_get_try_bool(qdict
, "force", false);
1778 qmp_block_job_cancel(device
, true, force
, &error
);
1780 hmp_handle_error(mon
, &error
);
1783 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1785 Error
*error
= NULL
;
1786 const char *device
= qdict_get_str(qdict
, "device");
1788 qmp_block_job_pause(device
, &error
);
1790 hmp_handle_error(mon
, &error
);
1793 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1795 Error
*error
= NULL
;
1796 const char *device
= qdict_get_str(qdict
, "device");
1798 qmp_block_job_resume(device
, &error
);
1800 hmp_handle_error(mon
, &error
);
1803 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1805 Error
*error
= NULL
;
1806 const char *device
= qdict_get_str(qdict
, "device");
1808 qmp_block_job_complete(device
, &error
);
1810 hmp_handle_error(mon
, &error
);
1813 typedef struct HMPMigrationStatus
1817 bool is_block_migration
;
1818 } HMPMigrationStatus
;
1820 static void hmp_migrate_status_cb(void *opaque
)
1822 HMPMigrationStatus
*status
= opaque
;
1823 MigrationInfo
*info
;
1825 info
= qmp_query_migrate(NULL
);
1826 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1827 info
->status
== MIGRATION_STATUS_SETUP
) {
1828 if (info
->has_disk
) {
1831 if (info
->disk
->remaining
) {
1832 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1837 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1838 monitor_flush(status
->mon
);
1841 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1843 if (status
->is_block_migration
) {
1844 monitor_printf(status
->mon
, "\n");
1846 if (info
->has_error_desc
) {
1847 error_report("%s", info
->error_desc
);
1849 monitor_resume(status
->mon
);
1850 timer_del(status
->timer
);
1854 qapi_free_MigrationInfo(info
);
1857 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1859 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1860 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1861 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1862 const char *uri
= qdict_get_str(qdict
, "uri");
1865 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1867 error_report_err(err
);
1872 HMPMigrationStatus
*status
;
1874 if (monitor_suspend(mon
) < 0) {
1875 monitor_printf(mon
, "terminal does not allow synchronous "
1876 "migration, continuing detached\n");
1880 status
= g_malloc0(sizeof(*status
));
1882 status
->is_block_migration
= blk
|| inc
;
1883 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1885 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1889 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
1893 qmp_device_add((QDict
*)qdict
, NULL
, &err
);
1894 hmp_handle_error(mon
, &err
);
1897 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1899 const char *id
= qdict_get_str(qdict
, "id");
1902 qmp_device_del(id
, &err
);
1903 hmp_handle_error(mon
, &err
);
1906 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1909 bool paging
= qdict_get_try_bool(qdict
, "paging", false);
1910 bool zlib
= qdict_get_try_bool(qdict
, "zlib", false);
1911 bool lzo
= qdict_get_try_bool(qdict
, "lzo", false);
1912 bool snappy
= qdict_get_try_bool(qdict
, "snappy", false);
1913 const char *file
= qdict_get_str(qdict
, "filename");
1914 bool has_begin
= qdict_haskey(qdict
, "begin");
1915 bool has_length
= qdict_haskey(qdict
, "length");
1916 bool has_detach
= qdict_haskey(qdict
, "detach");
1919 bool detach
= false;
1920 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1923 if (zlib
+ lzo
+ snappy
> 1) {
1924 error_setg(&err
, "only one of '-z|-l|-s' can be set");
1925 hmp_handle_error(mon
, &err
);
1930 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
1934 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
1938 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
1942 begin
= qdict_get_int(qdict
, "begin");
1945 length
= qdict_get_int(qdict
, "length");
1948 detach
= qdict_get_bool(qdict
, "detach");
1951 prot
= g_strconcat("file:", file
, NULL
);
1953 qmp_dump_guest_memory(paging
, prot
, true, detach
, has_begin
, begin
,
1954 has_length
, length
, true, dump_format
, &err
);
1955 hmp_handle_error(mon
, &err
);
1959 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1964 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1969 netdev_add(opts
, &err
);
1971 qemu_opts_del(opts
);
1975 hmp_handle_error(mon
, &err
);
1978 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1980 const char *id
= qdict_get_str(qdict
, "id");
1983 qmp_netdev_del(id
, &err
);
1984 hmp_handle_error(mon
, &err
);
1987 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
1993 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
1995 hmp_handle_error(mon
, &err
);
1999 obj
= user_creatable_add_opts(opts
, &err
);
2000 qemu_opts_del(opts
);
2003 hmp_handle_error(mon
, &err
);
2010 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
2012 const char *fdname
= qdict_get_str(qdict
, "fdname");
2015 qmp_getfd(fdname
, &err
);
2016 hmp_handle_error(mon
, &err
);
2019 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
2021 const char *fdname
= qdict_get_str(qdict
, "fdname");
2024 qmp_closefd(fdname
, &err
);
2025 hmp_handle_error(mon
, &err
);
2028 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
2030 const char *keys
= qdict_get_str(qdict
, "keys");
2031 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
2032 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
2033 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
2039 separator
= strchr(keys
, '-');
2040 keyname_len
= separator
? separator
- keys
: strlen(keys
);
2042 /* Be compatible with old interface, convert user inputted "<" */
2043 if (keys
[0] == '<' && keyname_len
== 1) {
2048 keylist
= g_malloc0(sizeof(*keylist
));
2049 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
2055 tmp
->next
= keylist
;
2059 if (strstart(keys
, "0x", NULL
)) {
2061 int value
= strtoul(keys
, &endp
, 0);
2062 assert(endp
<= keys
+ keyname_len
);
2063 if (endp
!= keys
+ keyname_len
) {
2066 keylist
->value
->type
= KEY_VALUE_KIND_NUMBER
;
2067 keylist
->value
->u
.number
.data
= value
;
2069 int idx
= index_from_key(keys
, keyname_len
);
2070 if (idx
== Q_KEY_CODE__MAX
) {
2073 keylist
->value
->type
= KEY_VALUE_KIND_QCODE
;
2074 keylist
->value
->u
.qcode
.data
= idx
;
2080 keys
= separator
+ 1;
2083 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
2084 hmp_handle_error(mon
, &err
);
2087 qapi_free_KeyValueList(head
);
2091 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
2095 void hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
2097 const char *filename
= qdict_get_str(qdict
, "filename");
2100 qmp_screendump(filename
, &err
);
2101 hmp_handle_error(mon
, &err
);
2104 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
2106 const char *uri
= qdict_get_str(qdict
, "uri");
2107 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2108 bool all
= qdict_get_try_bool(qdict
, "all", false);
2109 Error
*local_err
= NULL
;
2110 BlockInfoList
*block_list
, *info
;
2111 SocketAddress
*addr
;
2113 if (writable
&& !all
) {
2114 error_setg(&local_err
, "-w only valid together with -a");
2118 /* First check if the address is valid and start the server. */
2119 addr
= socket_parse(uri
, &local_err
);
2120 if (local_err
!= NULL
) {
2124 qmp_nbd_server_start(addr
, false, NULL
, &local_err
);
2125 qapi_free_SocketAddress(addr
);
2126 if (local_err
!= NULL
) {
2134 /* Then try adding all block devices. If one fails, close all and
2137 block_list
= qmp_query_block(NULL
);
2139 for (info
= block_list
; info
; info
= info
->next
) {
2140 if (!info
->value
->has_inserted
) {
2144 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
2146 if (local_err
!= NULL
) {
2147 qmp_nbd_server_stop(NULL
);
2152 qapi_free_BlockInfoList(block_list
);
2155 hmp_handle_error(mon
, &local_err
);
2158 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
2160 const char *device
= qdict_get_str(qdict
, "device");
2161 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2162 Error
*local_err
= NULL
;
2164 qmp_nbd_server_add(device
, true, writable
, &local_err
);
2166 if (local_err
!= NULL
) {
2167 hmp_handle_error(mon
, &local_err
);
2171 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
2175 qmp_nbd_server_stop(&err
);
2176 hmp_handle_error(mon
, &err
);
2179 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
2184 cpuid
= qdict_get_int(qdict
, "id");
2185 qmp_cpu_add(cpuid
, &err
);
2186 hmp_handle_error(mon
, &err
);
2189 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
2191 const char *args
= qdict_get_str(qdict
, "args");
2195 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
2197 error_setg(&err
, "Parsing chardev args failed");
2199 qemu_chr_new_from_opts(opts
, &err
);
2200 qemu_opts_del(opts
);
2202 hmp_handle_error(mon
, &err
);
2205 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
2207 Error
*local_err
= NULL
;
2209 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
2210 hmp_handle_error(mon
, &local_err
);
2213 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
2216 BlockBackend
*local_blk
= NULL
;
2217 AioContext
*aio_context
;
2218 const char* device
= qdict_get_str(qdict
, "device");
2219 const char* command
= qdict_get_str(qdict
, "command");
2223 blk
= blk_by_name(device
);
2225 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, device
, &err
);
2227 blk
= local_blk
= blk_new(0, BLK_PERM_ALL
);
2228 ret
= blk_insert_bs(blk
, bs
, &err
);
2237 aio_context
= blk_get_aio_context(blk
);
2238 aio_context_acquire(aio_context
);
2241 * Notably absent: Proper permission management. This is sad, but it seems
2242 * almost impossible to achieve without changing the semantics and thereby
2243 * limiting the use cases of the qemu-io HMP command.
2245 * In an ideal world we would unconditionally create a new BlockBackend for
2246 * qemuio_command(), but we have commands like 'reopen' and want them to
2247 * take effect on the exact BlockBackend whose name the user passed instead
2248 * of just on a temporary copy of it.
2250 * Another problem is that deleting the temporary BlockBackend involves
2251 * draining all requests on it first, but some qemu-iotests cases want to
2252 * issue multiple aio_read/write requests and expect them to complete in
2253 * the background while the monitor has already returned.
2255 * This is also what prevents us from saving the original permissions and
2256 * restoring them later: We can't revoke permissions until all requests
2257 * have completed, and we don't know when that is nor can we really let
2258 * anything else run before we have revoken them to avoid race conditions.
2260 * What happens now is that command() in qemu-io-cmds.c can extend the
2261 * permissions if necessary for the qemu-io command. And they simply stay
2262 * extended, possibly resulting in a read-only guest device keeping write
2263 * permissions. Ugly, but it appears to be the lesser evil.
2265 qemuio_command(blk
, command
);
2267 aio_context_release(aio_context
);
2270 blk_unref(local_blk
);
2271 hmp_handle_error(mon
, &err
);
2274 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
2276 const char *id
= qdict_get_str(qdict
, "id");
2279 user_creatable_del(id
, &err
);
2280 hmp_handle_error(mon
, &err
);
2283 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
2286 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
2287 MemdevList
*m
= memdev_list
;
2292 v
= string_output_visitor_new(false, &str
);
2293 visit_type_uint16List(v
, NULL
, &m
->value
->host_nodes
, NULL
);
2294 monitor_printf(mon
, "memory backend: %s\n", m
->value
->id
);
2295 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
2296 monitor_printf(mon
, " merge: %s\n",
2297 m
->value
->merge
? "true" : "false");
2298 monitor_printf(mon
, " dump: %s\n",
2299 m
->value
->dump
? "true" : "false");
2300 monitor_printf(mon
, " prealloc: %s\n",
2301 m
->value
->prealloc
? "true" : "false");
2302 monitor_printf(mon
, " policy: %s\n",
2303 HostMemPolicy_lookup
[m
->value
->policy
]);
2304 visit_complete(v
, &str
);
2305 monitor_printf(mon
, " host nodes: %s\n", str
);
2312 monitor_printf(mon
, "\n");
2314 qapi_free_MemdevList(memdev_list
);
2317 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
2320 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
2321 MemoryDeviceInfoList
*info
;
2322 MemoryDeviceInfo
*value
;
2323 PCDIMMDeviceInfo
*di
;
2325 for (info
= info_list
; info
; info
= info
->next
) {
2326 value
= info
->value
;
2329 switch (value
->type
) {
2330 case MEMORY_DEVICE_INFO_KIND_DIMM
:
2331 di
= value
->u
.dimm
.data
;
2333 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
2334 MemoryDeviceInfoKind_lookup
[value
->type
],
2335 di
->id
? di
->id
: "");
2336 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
2337 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
2338 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
2339 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
2340 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
2341 monitor_printf(mon
, " hotplugged: %s\n",
2342 di
->hotplugged
? "true" : "false");
2343 monitor_printf(mon
, " hotpluggable: %s\n",
2344 di
->hotpluggable
? "true" : "false");
2352 qapi_free_MemoryDeviceInfoList(info_list
);
2355 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
2357 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
2358 IOThreadInfoList
*info
;
2359 IOThreadInfo
*value
;
2361 for (info
= info_list
; info
; info
= info
->next
) {
2362 value
= info
->value
;
2363 monitor_printf(mon
, "%s:\n", value
->id
);
2364 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
2365 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
2366 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
2367 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
2370 qapi_free_IOThreadInfoList(info_list
);
2373 void hmp_qom_list(Monitor
*mon
, const QDict
*qdict
)
2375 const char *path
= qdict_get_try_str(qdict
, "path");
2376 ObjectPropertyInfoList
*list
;
2380 monitor_printf(mon
, "/\n");
2384 list
= qmp_qom_list(path
, &err
);
2386 ObjectPropertyInfoList
*start
= list
;
2387 while (list
!= NULL
) {
2388 ObjectPropertyInfo
*value
= list
->value
;
2390 monitor_printf(mon
, "%s (%s)\n",
2391 value
->name
, value
->type
);
2394 qapi_free_ObjectPropertyInfoList(start
);
2396 hmp_handle_error(mon
, &err
);
2399 void hmp_qom_set(Monitor
*mon
, const QDict
*qdict
)
2401 const char *path
= qdict_get_str(qdict
, "path");
2402 const char *property
= qdict_get_str(qdict
, "property");
2403 const char *value
= qdict_get_str(qdict
, "value");
2405 bool ambiguous
= false;
2408 obj
= object_resolve_path(path
, &ambiguous
);
2410 error_set(&err
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2411 "Device '%s' not found", path
);
2414 monitor_printf(mon
, "Warning: Path '%s' is ambiguous\n", path
);
2416 object_property_parse(obj
, value
, property
, &err
);
2418 hmp_handle_error(mon
, &err
);
2421 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
2423 const char *name
= qdict_get_str(qdict
, "name");
2424 RockerSwitch
*rocker
;
2427 rocker
= qmp_query_rocker(name
, &err
);
2429 hmp_handle_error(mon
, &err
);
2433 monitor_printf(mon
, "name: %s\n", rocker
->name
);
2434 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
2435 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
2437 qapi_free_RockerSwitch(rocker
);
2440 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
2442 RockerPortList
*list
, *port
;
2443 const char *name
= qdict_get_str(qdict
, "name");
2446 list
= qmp_query_rocker_ports(name
, &err
);
2448 hmp_handle_error(mon
, &err
);
2452 monitor_printf(mon
, " ena/ speed/ auto\n");
2453 monitor_printf(mon
, " port link duplex neg?\n");
2455 for (port
= list
; port
; port
= port
->next
) {
2456 monitor_printf(mon
, "%10s %-4s %-3s %2s %-3s\n",
2458 port
->value
->enabled
? port
->value
->link_up
?
2459 "up" : "down" : "!ena",
2460 port
->value
->speed
== 10000 ? "10G" : "??",
2461 port
->value
->duplex
? "FD" : "HD",
2462 port
->value
->autoneg
? "Yes" : "No");
2465 qapi_free_RockerPortList(list
);
2468 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
2470 RockerOfDpaFlowList
*list
, *info
;
2471 const char *name
= qdict_get_str(qdict
, "name");
2472 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
2475 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
2477 hmp_handle_error(mon
, &err
);
2481 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
2483 for (info
= list
; info
; info
= info
->next
) {
2484 RockerOfDpaFlow
*flow
= info
->value
;
2485 RockerOfDpaFlowKey
*key
= flow
->key
;
2486 RockerOfDpaFlowMask
*mask
= flow
->mask
;
2487 RockerOfDpaFlowAction
*action
= flow
->action
;
2490 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
2491 key
->priority
, key
->tbl_id
, flow
->hits
);
2493 monitor_printf(mon
, "%-4d %-3d ",
2494 key
->priority
, key
->tbl_id
);
2497 if (key
->has_in_pport
) {
2498 monitor_printf(mon
, " pport %d", key
->in_pport
);
2499 if (mask
->has_in_pport
) {
2500 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2504 if (key
->has_vlan_id
) {
2505 monitor_printf(mon
, " vlan %d",
2506 key
->vlan_id
& VLAN_VID_MASK
);
2507 if (mask
->has_vlan_id
) {
2508 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2512 if (key
->has_tunnel_id
) {
2513 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2514 if (mask
->has_tunnel_id
) {
2515 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2519 if (key
->has_eth_type
) {
2520 switch (key
->eth_type
) {
2522 monitor_printf(mon
, " ARP");
2525 monitor_printf(mon
, " IP");
2528 monitor_printf(mon
, " IPv6");
2531 monitor_printf(mon
, " LACP");
2534 monitor_printf(mon
, " LLDP");
2537 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2542 if (key
->has_eth_src
) {
2543 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2544 (mask
->has_eth_src
) &&
2545 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2546 monitor_printf(mon
, " src <any mcast/bcast>");
2547 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2548 (mask
->has_eth_src
) &&
2549 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2550 monitor_printf(mon
, " src <any ucast>");
2552 monitor_printf(mon
, " src %s", key
->eth_src
);
2553 if (mask
->has_eth_src
) {
2554 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2559 if (key
->has_eth_dst
) {
2560 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2561 (mask
->has_eth_dst
) &&
2562 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2563 monitor_printf(mon
, " dst <any mcast/bcast>");
2564 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2565 (mask
->has_eth_dst
) &&
2566 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2567 monitor_printf(mon
, " dst <any ucast>");
2569 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2570 if (mask
->has_eth_dst
) {
2571 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2576 if (key
->has_ip_proto
) {
2577 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2578 if (mask
->has_ip_proto
) {
2579 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2583 if (key
->has_ip_tos
) {
2584 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2585 if (mask
->has_ip_tos
) {
2586 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2590 if (key
->has_ip_dst
) {
2591 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2594 if (action
->has_goto_tbl
|| action
->has_group_id
||
2595 action
->has_new_vlan_id
) {
2596 monitor_printf(mon
, " -->");
2599 if (action
->has_new_vlan_id
) {
2600 monitor_printf(mon
, " apply new vlan %d",
2601 ntohs(action
->new_vlan_id
));
2604 if (action
->has_group_id
) {
2605 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2608 if (action
->has_goto_tbl
) {
2609 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2612 monitor_printf(mon
, "\n");
2615 qapi_free_RockerOfDpaFlowList(list
);
2618 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2620 RockerOfDpaGroupList
*list
, *g
;
2621 const char *name
= qdict_get_str(qdict
, "name");
2622 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2626 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
2628 hmp_handle_error(mon
, &err
);
2632 monitor_printf(mon
, "id (decode) --> buckets\n");
2634 for (g
= list
; g
; g
= g
->next
) {
2635 RockerOfDpaGroup
*group
= g
->value
;
2637 monitor_printf(mon
, "0x%08x", group
->id
);
2639 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2640 group
->type
== 1 ? "L2 rewrite" :
2641 group
->type
== 2 ? "L3 unicast" :
2642 group
->type
== 3 ? "L2 multicast" :
2643 group
->type
== 4 ? "L2 flood" :
2644 group
->type
== 5 ? "L3 interface" :
2645 group
->type
== 6 ? "L3 multicast" :
2646 group
->type
== 7 ? "L3 ECMP" :
2647 group
->type
== 8 ? "L2 overlay" :
2650 if (group
->has_vlan_id
) {
2651 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2654 if (group
->has_pport
) {
2655 monitor_printf(mon
, " pport %d", group
->pport
);
2658 if (group
->has_index
) {
2659 monitor_printf(mon
, " index %d", group
->index
);
2662 monitor_printf(mon
, ") -->");
2664 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2666 monitor_printf(mon
, " set vlan %d",
2667 group
->set_vlan_id
& VLAN_VID_MASK
);
2670 if (group
->has_set_eth_src
) {
2673 monitor_printf(mon
, " set");
2675 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2678 if (group
->has_set_eth_dst
) {
2681 monitor_printf(mon
, " set");
2683 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2688 if (group
->has_ttl_check
&& group
->ttl_check
) {
2689 monitor_printf(mon
, " check TTL");
2692 if (group
->has_group_id
&& group
->group_id
) {
2693 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2696 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2697 monitor_printf(mon
, " pop vlan");
2700 if (group
->has_out_pport
) {
2701 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2704 if (group
->has_group_ids
) {
2705 struct uint32List
*id
;
2707 monitor_printf(mon
, " groups [");
2708 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2709 monitor_printf(mon
, "0x%08x", id
->value
);
2711 monitor_printf(mon
, ",");
2714 monitor_printf(mon
, "]");
2717 monitor_printf(mon
, "\n");
2720 qapi_free_RockerOfDpaGroupList(list
);
2723 void hmp_info_dump(Monitor
*mon
, const QDict
*qdict
)
2725 DumpQueryResult
*result
= qmp_query_dump(NULL
);
2727 assert(result
&& result
->status
< DUMP_STATUS__MAX
);
2728 monitor_printf(mon
, "Status: %s\n", DumpStatus_lookup
[result
->status
]);
2730 if (result
->status
== DUMP_STATUS_ACTIVE
) {
2732 assert(result
->total
!= 0);
2733 percent
= 100.0 * result
->completed
/ result
->total
;
2734 monitor_printf(mon
, "Finished: %.2f %%\n", percent
);
2737 qapi_free_DumpQueryResult(result
);
2740 void hmp_hotpluggable_cpus(Monitor
*mon
, const QDict
*qdict
)
2743 HotpluggableCPUList
*l
= qmp_query_hotpluggable_cpus(&err
);
2744 HotpluggableCPUList
*saved
= l
;
2745 CpuInstanceProperties
*c
;
2748 hmp_handle_error(mon
, &err
);
2752 monitor_printf(mon
, "Hotpluggable CPUs:\n");
2754 monitor_printf(mon
, " type: \"%s\"\n", l
->value
->type
);
2755 monitor_printf(mon
, " vcpus_count: \"%" PRIu64
"\"\n",
2756 l
->value
->vcpus_count
);
2757 if (l
->value
->has_qom_path
) {
2758 monitor_printf(mon
, " qom_path: \"%s\"\n", l
->value
->qom_path
);
2761 c
= l
->value
->props
;
2762 monitor_printf(mon
, " CPUInstance Properties:\n");
2763 if (c
->has_node_id
) {
2764 monitor_printf(mon
, " node-id: \"%" PRIu64
"\"\n", c
->node_id
);
2766 if (c
->has_socket_id
) {
2767 monitor_printf(mon
, " socket-id: \"%" PRIu64
"\"\n", c
->socket_id
);
2769 if (c
->has_core_id
) {
2770 monitor_printf(mon
, " core-id: \"%" PRIu64
"\"\n", c
->core_id
);
2772 if (c
->has_thread_id
) {
2773 monitor_printf(mon
, " thread-id: \"%" PRIu64
"\"\n", c
->thread_id
);
2779 qapi_free_HotpluggableCPUList(saved
);
2782 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
2785 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
2787 monitor_printf(mon
, "%s\n", info
->guid
);
2789 hmp_handle_error(mon
, &err
);
2790 qapi_free_GuidInfo(info
);