2 * Human Monitor Interface commands
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"
17 #include "monitor/hmp.h"
20 #include "chardev/char.h"
21 #include "sysemu/block-backend.h"
22 #include "sysemu/sysemu.h"
23 #include "qemu/config-file.h"
24 #include "qemu/option.h"
25 #include "qemu/timer.h"
26 #include "qemu/sockets.h"
27 #include "monitor/monitor-internal.h"
28 #include "monitor/qdev.h"
29 #include "qapi/error.h"
30 #include "qapi/opts-visitor.h"
31 #include "qapi/qapi-builtin-visit.h"
32 #include "qapi/qapi-commands-block.h"
33 #include "qapi/qapi-commands-char.h"
34 #include "qapi/qapi-commands-dump.h"
35 #include "qapi/qapi-commands-migration.h"
36 #include "qapi/qapi-commands-misc.h"
37 #include "qapi/qapi-commands-net.h"
38 #include "qapi/qapi-commands-qdev.h"
39 #include "qapi/qapi-commands-rocker.h"
40 #include "qapi/qapi-commands-run-state.h"
41 #include "qapi/qapi-commands-tpm.h"
42 #include "qapi/qapi-commands-ui.h"
43 #include "qapi/qmp/qdict.h"
44 #include "qapi/qmp/qerror.h"
45 #include "qapi/string-input-visitor.h"
46 #include "qapi/string-output-visitor.h"
47 #include "qom/object_interfaces.h"
48 #include "ui/console.h"
49 #include "block/nbd.h"
50 #include "block/qapi.h"
52 #include "qemu/cutils.h"
53 #include "qemu/error-report.h"
54 #include "exec/ramlist.h"
55 #include "hw/intc/intc.h"
56 #include "hw/rdma/rdma.h"
57 #include "migration/snapshot.h"
58 #include "migration/misc.h"
61 #include <spice/enums.h>
64 void hmp_handle_error(Monitor
*mon
, Error
**errp
)
68 error_reportf_err(*errp
, "Error: ");
72 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
76 info
= qmp_query_name(NULL
);
78 monitor_printf(mon
, "%s\n", info
->name
);
80 qapi_free_NameInfo(info
);
83 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
87 info
= qmp_query_version(NULL
);
89 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
90 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
93 qapi_free_VersionInfo(info
);
96 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
100 info
= qmp_query_kvm(NULL
);
101 monitor_printf(mon
, "kvm support: ");
103 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
105 monitor_printf(mon
, "not compiled\n");
108 qapi_free_KvmInfo(info
);
111 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
115 info
= qmp_query_status(NULL
);
117 monitor_printf(mon
, "VM status: %s%s",
118 info
->running
? "running" : "paused",
119 info
->singlestep
? " (single step mode)" : "");
121 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
122 monitor_printf(mon
, " (%s)", RunState_str(info
->status
));
125 monitor_printf(mon
, "\n");
127 qapi_free_StatusInfo(info
);
130 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
134 info
= qmp_query_uuid(NULL
);
135 monitor_printf(mon
, "%s\n", info
->UUID
);
136 qapi_free_UuidInfo(info
);
139 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
141 ChardevInfoList
*char_info
, *info
;
143 char_info
= qmp_query_chardev(NULL
);
144 for (info
= char_info
; info
; info
= info
->next
) {
145 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
146 info
->value
->filename
);
149 qapi_free_ChardevInfoList(char_info
);
152 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
154 MouseInfoList
*mice_list
, *mouse
;
156 mice_list
= qmp_query_mice(NULL
);
158 monitor_printf(mon
, "No mouse devices connected\n");
162 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
163 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
164 mouse
->value
->current
? '*' : ' ',
165 mouse
->value
->index
, mouse
->value
->name
,
166 mouse
->value
->absolute
? " (absolute)" : "");
169 qapi_free_MouseInfoList(mice_list
);
172 static char *SocketAddress_to_str(SocketAddress
*addr
)
174 switch (addr
->type
) {
175 case SOCKET_ADDRESS_TYPE_INET
:
176 return g_strdup_printf("tcp:%s:%s",
179 case SOCKET_ADDRESS_TYPE_UNIX
:
180 return g_strdup_printf("unix:%s",
181 addr
->u
.q_unix
.path
);
182 case SOCKET_ADDRESS_TYPE_FD
:
183 return g_strdup_printf("fd:%s", addr
->u
.fd
.str
);
184 case SOCKET_ADDRESS_TYPE_VSOCK
:
185 return g_strdup_printf("tcp:%s:%s",
189 return g_strdup("unknown address type");
193 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
196 MigrationCapabilityStatusList
*caps
, *cap
;
198 info
= qmp_query_migrate(NULL
);
199 caps
= qmp_query_migrate_capabilities(NULL
);
201 migration_global_dump(mon
);
203 /* do not display parameters during setup */
204 if (info
->has_status
&& caps
) {
205 monitor_printf(mon
, "capabilities: ");
206 for (cap
= caps
; cap
; cap
= cap
->next
) {
207 monitor_printf(mon
, "%s: %s ",
208 MigrationCapability_str(cap
->value
->capability
),
209 cap
->value
->state
? "on" : "off");
211 monitor_printf(mon
, "\n");
214 if (info
->has_status
) {
215 monitor_printf(mon
, "Migration status: %s",
216 MigrationStatus_str(info
->status
));
217 if (info
->status
== MIGRATION_STATUS_FAILED
&&
218 info
->has_error_desc
) {
219 monitor_printf(mon
, " (%s)\n", info
->error_desc
);
221 monitor_printf(mon
, "\n");
224 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
226 if (info
->has_expected_downtime
) {
227 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
228 info
->expected_downtime
);
230 if (info
->has_downtime
) {
231 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
234 if (info
->has_setup_time
) {
235 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
241 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
242 info
->ram
->transferred
>> 10);
243 monitor_printf(mon
, "throughput: %0.2f mbps\n",
245 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
246 info
->ram
->remaining
>> 10);
247 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
248 info
->ram
->total
>> 10);
249 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
250 info
->ram
->duplicate
);
251 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
253 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
255 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
256 info
->ram
->normal_bytes
>> 10);
257 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
258 info
->ram
->dirty_sync_count
);
259 monitor_printf(mon
, "page size: %" PRIu64
" kbytes\n",
260 info
->ram
->page_size
>> 10);
261 monitor_printf(mon
, "multifd bytes: %" PRIu64
" kbytes\n",
262 info
->ram
->multifd_bytes
>> 10);
263 monitor_printf(mon
, "pages-per-second: %" PRIu64
"\n",
264 info
->ram
->pages_per_second
);
266 if (info
->ram
->dirty_pages_rate
) {
267 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
268 info
->ram
->dirty_pages_rate
);
270 if (info
->ram
->postcopy_requests
) {
271 monitor_printf(mon
, "postcopy request count: %" PRIu64
"\n",
272 info
->ram
->postcopy_requests
);
276 if (info
->has_disk
) {
277 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
278 info
->disk
->transferred
>> 10);
279 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
280 info
->disk
->remaining
>> 10);
281 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
282 info
->disk
->total
>> 10);
285 if (info
->has_xbzrle_cache
) {
286 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
287 info
->xbzrle_cache
->cache_size
);
288 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
289 info
->xbzrle_cache
->bytes
>> 10);
290 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
291 info
->xbzrle_cache
->pages
);
292 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
293 info
->xbzrle_cache
->cache_miss
);
294 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
295 info
->xbzrle_cache
->cache_miss_rate
);
296 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
297 info
->xbzrle_cache
->overflow
);
300 if (info
->has_compression
) {
301 monitor_printf(mon
, "compression pages: %" PRIu64
" pages\n",
302 info
->compression
->pages
);
303 monitor_printf(mon
, "compression busy: %" PRIu64
"\n",
304 info
->compression
->busy
);
305 monitor_printf(mon
, "compression busy rate: %0.2f\n",
306 info
->compression
->busy_rate
);
307 monitor_printf(mon
, "compressed size: %" PRIu64
"\n",
308 info
->compression
->compressed_size
);
309 monitor_printf(mon
, "compression rate: %0.2f\n",
310 info
->compression
->compression_rate
);
313 if (info
->has_cpu_throttle_percentage
) {
314 monitor_printf(mon
, "cpu throttle percentage: %" PRIu64
"\n",
315 info
->cpu_throttle_percentage
);
318 if (info
->has_postcopy_blocktime
) {
319 monitor_printf(mon
, "postcopy blocktime: %u\n",
320 info
->postcopy_blocktime
);
323 if (info
->has_postcopy_vcpu_blocktime
) {
326 v
= string_output_visitor_new(false, &str
);
327 visit_type_uint32List(v
, NULL
, &info
->postcopy_vcpu_blocktime
, NULL
);
328 visit_complete(v
, &str
);
329 monitor_printf(mon
, "postcopy vcpu blocktime: %s\n", str
);
333 if (info
->has_socket_address
) {
334 SocketAddressList
*addr
;
336 monitor_printf(mon
, "socket address: [\n");
338 for (addr
= info
->socket_address
; addr
; addr
= addr
->next
) {
339 char *s
= SocketAddress_to_str(addr
->value
);
340 monitor_printf(mon
, "\t%s\n", s
);
343 monitor_printf(mon
, "]\n");
345 qapi_free_MigrationInfo(info
);
346 qapi_free_MigrationCapabilityStatusList(caps
);
349 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
351 MigrationCapabilityStatusList
*caps
, *cap
;
353 caps
= qmp_query_migrate_capabilities(NULL
);
356 for (cap
= caps
; cap
; cap
= cap
->next
) {
357 monitor_printf(mon
, "%s: %s\n",
358 MigrationCapability_str(cap
->value
->capability
),
359 cap
->value
->state
? "on" : "off");
363 qapi_free_MigrationCapabilityStatusList(caps
);
366 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
368 MigrationParameters
*params
;
370 params
= qmp_query_migrate_parameters(NULL
);
373 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
374 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL
),
375 params
->announce_initial
);
376 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
377 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX
),
378 params
->announce_max
);
379 monitor_printf(mon
, "%s: %" PRIu64
"\n",
380 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS
),
381 params
->announce_rounds
);
382 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
383 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP
),
384 params
->announce_step
);
385 assert(params
->has_compress_level
);
386 monitor_printf(mon
, "%s: %u\n",
387 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL
),
388 params
->compress_level
);
389 assert(params
->has_compress_threads
);
390 monitor_printf(mon
, "%s: %u\n",
391 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS
),
392 params
->compress_threads
);
393 assert(params
->has_compress_wait_thread
);
394 monitor_printf(mon
, "%s: %s\n",
395 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD
),
396 params
->compress_wait_thread
? "on" : "off");
397 assert(params
->has_decompress_threads
);
398 monitor_printf(mon
, "%s: %u\n",
399 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS
),
400 params
->decompress_threads
);
401 assert(params
->has_cpu_throttle_initial
);
402 monitor_printf(mon
, "%s: %u\n",
403 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
),
404 params
->cpu_throttle_initial
);
405 assert(params
->has_cpu_throttle_increment
);
406 monitor_printf(mon
, "%s: %u\n",
407 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
),
408 params
->cpu_throttle_increment
);
409 assert(params
->has_max_cpu_throttle
);
410 monitor_printf(mon
, "%s: %u\n",
411 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE
),
412 params
->max_cpu_throttle
);
413 assert(params
->has_tls_creds
);
414 monitor_printf(mon
, "%s: '%s'\n",
415 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS
),
417 assert(params
->has_tls_hostname
);
418 monitor_printf(mon
, "%s: '%s'\n",
419 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME
),
420 params
->tls_hostname
);
421 assert(params
->has_max_bandwidth
);
422 monitor_printf(mon
, "%s: %" PRIu64
" bytes/second\n",
423 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH
),
424 params
->max_bandwidth
);
425 assert(params
->has_downtime_limit
);
426 monitor_printf(mon
, "%s: %" PRIu64
" milliseconds\n",
427 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT
),
428 params
->downtime_limit
);
429 assert(params
->has_x_checkpoint_delay
);
430 monitor_printf(mon
, "%s: %u\n",
431 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
),
432 params
->x_checkpoint_delay
);
433 assert(params
->has_block_incremental
);
434 monitor_printf(mon
, "%s: %s\n",
435 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL
),
436 params
->block_incremental
? "on" : "off");
437 monitor_printf(mon
, "%s: %u\n",
438 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS
),
439 params
->multifd_channels
);
440 monitor_printf(mon
, "%s: %" PRIu64
"\n",
441 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
),
442 params
->xbzrle_cache_size
);
443 monitor_printf(mon
, "%s: %" PRIu64
"\n",
444 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH
),
445 params
->max_postcopy_bandwidth
);
446 monitor_printf(mon
, " %s: '%s'\n",
447 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ
),
448 params
->has_tls_authz
? params
->tls_authz
: "");
451 qapi_free_MigrationParameters(params
);
454 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
456 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
457 qmp_query_migrate_cache_size(NULL
) >> 10);
460 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
461 BlockDeviceInfo
*inserted
, bool verbose
)
463 ImageInfo
*image_info
;
465 assert(!info
|| !info
->has_inserted
|| info
->inserted
== inserted
);
467 if (info
&& *info
->device
) {
468 monitor_printf(mon
, "%s", info
->device
);
469 if (inserted
&& inserted
->has_node_name
) {
470 monitor_printf(mon
, " (%s)", inserted
->node_name
);
473 assert(info
|| inserted
);
474 monitor_printf(mon
, "%s",
475 inserted
&& inserted
->has_node_name
? inserted
->node_name
476 : info
&& info
->has_qdev
? info
->qdev
481 monitor_printf(mon
, ": %s (%s%s%s)\n",
484 inserted
->ro
? ", read-only" : "",
485 inserted
->encrypted
? ", encrypted" : "");
487 monitor_printf(mon
, ": [not inserted]\n");
491 if (info
->has_qdev
) {
492 monitor_printf(mon
, " Attached to: %s\n", info
->qdev
);
494 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
495 monitor_printf(mon
, " I/O status: %s\n",
496 BlockDeviceIoStatus_str(info
->io_status
));
499 if (info
->removable
) {
500 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
501 info
->locked
? "" : "not ",
502 info
->tray_open
? "open" : "closed");
511 monitor_printf(mon
, " Cache mode: %s%s%s\n",
512 inserted
->cache
->writeback
? "writeback" : "writethrough",
513 inserted
->cache
->direct
? ", direct" : "",
514 inserted
->cache
->no_flush
? ", ignore flushes" : "");
516 if (inserted
->has_backing_file
) {
519 "(chain depth: %" PRId64
")\n",
520 inserted
->backing_file
,
521 inserted
->backing_file_depth
);
524 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
525 monitor_printf(mon
, " Detect zeroes: %s\n",
526 BlockdevDetectZeroesOptions_str(inserted
->detect_zeroes
));
529 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
530 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
532 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
533 " bps_rd=%" PRId64
" bps_wr=%" PRId64
535 " bps_rd_max=%" PRId64
536 " bps_wr_max=%" PRId64
537 " iops=%" PRId64
" iops_rd=%" PRId64
540 " iops_rd_max=%" PRId64
541 " iops_wr_max=%" PRId64
542 " iops_size=%" PRId64
548 inserted
->bps_rd_max
,
549 inserted
->bps_wr_max
,
554 inserted
->iops_rd_max
,
555 inserted
->iops_wr_max
,
561 monitor_printf(mon
, "\nImages:\n");
562 image_info
= inserted
->image
;
564 bdrv_image_info_dump(image_info
);
565 if (image_info
->has_backing_image
) {
566 image_info
= image_info
->backing_image
;
574 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
576 BlockInfoList
*block_list
, *info
;
577 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
578 const char *device
= qdict_get_try_str(qdict
, "device");
579 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
580 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
581 bool printed
= false;
583 /* Print BlockBackend information */
585 block_list
= qmp_query_block(NULL
);
590 for (info
= block_list
; info
; info
= info
->next
) {
591 if (device
&& strcmp(device
, info
->value
->device
)) {
595 if (info
!= block_list
) {
596 monitor_printf(mon
, "\n");
599 print_block_info(mon
, info
->value
, info
->value
->has_inserted
600 ? info
->value
->inserted
: NULL
,
605 qapi_free_BlockInfoList(block_list
);
607 if ((!device
&& !nodes
) || printed
) {
611 /* Print node information */
612 blockdev_list
= qmp_query_named_block_nodes(NULL
);
613 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
614 assert(blockdev
->value
->has_node_name
);
615 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
619 if (blockdev
!= blockdev_list
) {
620 monitor_printf(mon
, "\n");
623 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
625 qapi_free_BlockDeviceInfoList(blockdev_list
);
628 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
630 BlockStatsList
*stats_list
, *stats
;
632 stats_list
= qmp_query_blockstats(false, false, NULL
);
634 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
635 if (!stats
->value
->has_device
) {
639 monitor_printf(mon
, "%s:", stats
->value
->device
);
640 monitor_printf(mon
, " rd_bytes=%" PRId64
642 " rd_operations=%" PRId64
643 " wr_operations=%" PRId64
644 " flush_operations=%" PRId64
645 " wr_total_time_ns=%" PRId64
646 " rd_total_time_ns=%" PRId64
647 " flush_total_time_ns=%" PRId64
648 " rd_merged=%" PRId64
649 " wr_merged=%" PRId64
650 " idle_time_ns=%" PRId64
652 stats
->value
->stats
->rd_bytes
,
653 stats
->value
->stats
->wr_bytes
,
654 stats
->value
->stats
->rd_operations
,
655 stats
->value
->stats
->wr_operations
,
656 stats
->value
->stats
->flush_operations
,
657 stats
->value
->stats
->wr_total_time_ns
,
658 stats
->value
->stats
->rd_total_time_ns
,
659 stats
->value
->stats
->flush_total_time_ns
,
660 stats
->value
->stats
->rd_merged
,
661 stats
->value
->stats
->wr_merged
,
662 stats
->value
->stats
->idle_time_ns
);
665 qapi_free_BlockStatsList(stats_list
);
669 /* Helper for hmp_info_vnc_clients, _servers */
670 static void hmp_info_VncBasicInfo(Monitor
*mon
, VncBasicInfo
*info
,
673 monitor_printf(mon
, " %s: %s:%s (%s%s)\n",
677 NetworkAddressFamily_str(info
->family
),
678 info
->websocket
? " (Websocket)" : "");
681 /* Helper displaying and auth and crypt info */
682 static void hmp_info_vnc_authcrypt(Monitor
*mon
, const char *indent
,
684 VncVencryptSubAuth
*vencrypt
)
686 monitor_printf(mon
, "%sAuth: %s (Sub: %s)\n", indent
,
687 VncPrimaryAuth_str(auth
),
688 vencrypt
? VncVencryptSubAuth_str(*vencrypt
) : "none");
691 static void hmp_info_vnc_clients(Monitor
*mon
, VncClientInfoList
*client
)
694 VncClientInfo
*cinfo
= client
->value
;
696 hmp_info_VncBasicInfo(mon
, qapi_VncClientInfo_base(cinfo
), "Client");
697 monitor_printf(mon
, " x509_dname: %s\n",
698 cinfo
->has_x509_dname
?
699 cinfo
->x509_dname
: "none");
700 monitor_printf(mon
, " sasl_username: %s\n",
701 cinfo
->has_sasl_username
?
702 cinfo
->sasl_username
: "none");
704 client
= client
->next
;
708 static void hmp_info_vnc_servers(Monitor
*mon
, VncServerInfo2List
*server
)
711 VncServerInfo2
*sinfo
= server
->value
;
712 hmp_info_VncBasicInfo(mon
, qapi_VncServerInfo2_base(sinfo
), "Server");
713 hmp_info_vnc_authcrypt(mon
, " ", sinfo
->auth
,
714 sinfo
->has_vencrypt
? &sinfo
->vencrypt
: NULL
);
715 server
= server
->next
;
719 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
721 VncInfo2List
*info2l
;
724 info2l
= qmp_query_vnc_servers(&err
);
726 hmp_handle_error(mon
, &err
);
730 monitor_printf(mon
, "None\n");
735 VncInfo2
*info
= info2l
->value
;
736 monitor_printf(mon
, "%s:\n", info
->id
);
737 hmp_info_vnc_servers(mon
, info
->server
);
738 hmp_info_vnc_clients(mon
, info
->clients
);
740 /* The server entry displays its auth, we only
741 * need to display in the case of 'reverse' connections
742 * where there's no server.
744 hmp_info_vnc_authcrypt(mon
, " ", info
->auth
,
745 info
->has_vencrypt
? &info
->vencrypt
: NULL
);
747 if (info
->has_display
) {
748 monitor_printf(mon
, " Display: %s\n", info
->display
);
750 info2l
= info2l
->next
;
753 qapi_free_VncInfo2List(info2l
);
759 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
761 SpiceChannelList
*chan
;
763 const char *channel_name
;
764 const char * const channel_names
[] = {
765 [SPICE_CHANNEL_MAIN
] = "main",
766 [SPICE_CHANNEL_DISPLAY
] = "display",
767 [SPICE_CHANNEL_INPUTS
] = "inputs",
768 [SPICE_CHANNEL_CURSOR
] = "cursor",
769 [SPICE_CHANNEL_PLAYBACK
] = "playback",
770 [SPICE_CHANNEL_RECORD
] = "record",
771 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
772 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
773 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
774 [SPICE_CHANNEL_PORT
] = "port",
776 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
777 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
778 * as quick fix for build failures with older versions. */
779 [SPICE_CHANNEL_WEBDAV
] = "webdav",
783 info
= qmp_query_spice(NULL
);
785 if (!info
->enabled
) {
786 monitor_printf(mon
, "Server: disabled\n");
790 monitor_printf(mon
, "Server:\n");
791 if (info
->has_port
) {
792 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
793 info
->host
, info
->port
);
795 if (info
->has_tls_port
) {
796 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
797 info
->host
, info
->tls_port
);
799 monitor_printf(mon
, " migrated: %s\n",
800 info
->migrated
? "true" : "false");
801 monitor_printf(mon
, " auth: %s\n", info
->auth
);
802 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
803 monitor_printf(mon
, " mouse-mode: %s\n",
804 SpiceQueryMouseMode_str(info
->mouse_mode
));
806 if (!info
->has_channels
|| info
->channels
== NULL
) {
807 monitor_printf(mon
, "Channels: none\n");
809 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
810 monitor_printf(mon
, "Channel:\n");
811 monitor_printf(mon
, " address: %s:%s%s\n",
812 chan
->value
->host
, chan
->value
->port
,
813 chan
->value
->tls
? " [tls]" : "");
814 monitor_printf(mon
, " session: %" PRId64
"\n",
815 chan
->value
->connection_id
);
816 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
817 chan
->value
->channel_type
, chan
->value
->channel_id
);
819 channel_name
= "unknown";
820 if (chan
->value
->channel_type
> 0 &&
821 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
822 channel_names
[chan
->value
->channel_type
]) {
823 channel_name
= channel_names
[chan
->value
->channel_type
];
826 monitor_printf(mon
, " channel name: %s\n", channel_name
);
831 qapi_free_SpiceInfo(info
);
835 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
840 info
= qmp_query_balloon(&err
);
842 hmp_handle_error(mon
, &err
);
846 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
848 qapi_free_BalloonInfo(info
);
851 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
853 PciMemoryRegionList
*region
;
855 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
856 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
857 dev
->slot
, dev
->function
);
858 monitor_printf(mon
, " ");
860 if (dev
->class_info
->has_desc
) {
861 monitor_printf(mon
, "%s", dev
->class_info
->desc
);
863 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
866 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
867 dev
->id
->vendor
, dev
->id
->device
);
868 if (dev
->id
->has_subsystem_vendor
&& dev
->id
->has_subsystem
) {
869 monitor_printf(mon
, " PCI subsystem %04" PRIx64
":%04" PRIx64
"\n",
870 dev
->id
->subsystem_vendor
, dev
->id
->subsystem
);
874 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
877 if (dev
->has_pci_bridge
) {
878 monitor_printf(mon
, " BUS %" PRId64
".\n",
879 dev
->pci_bridge
->bus
->number
);
880 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
881 dev
->pci_bridge
->bus
->secondary
);
882 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
883 dev
->pci_bridge
->bus
->subordinate
);
885 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
886 dev
->pci_bridge
->bus
->io_range
->base
,
887 dev
->pci_bridge
->bus
->io_range
->limit
);
890 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
891 dev
->pci_bridge
->bus
->memory_range
->base
,
892 dev
->pci_bridge
->bus
->memory_range
->limit
);
894 monitor_printf(mon
, " prefetchable memory range "
895 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
896 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
897 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
900 for (region
= dev
->regions
; region
; region
= region
->next
) {
903 addr
= region
->value
->address
;
904 size
= region
->value
->size
;
906 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
908 if (!strcmp(region
->value
->type
, "io")) {
909 monitor_printf(mon
, "I/O at 0x%04" PRIx64
910 " [0x%04" PRIx64
"].\n",
911 addr
, addr
+ size
- 1);
913 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
914 " [0x%08" PRIx64
"].\n",
915 region
->value
->mem_type_64
? 64 : 32,
916 region
->value
->prefetch
? " prefetchable" : "",
917 addr
, addr
+ size
- 1);
921 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
923 if (dev
->has_pci_bridge
) {
924 if (dev
->pci_bridge
->has_devices
) {
925 PciDeviceInfoList
*cdev
;
926 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
927 hmp_info_pci_device(mon
, cdev
->value
);
933 static int hmp_info_irq_foreach(Object
*obj
, void *opaque
)
935 InterruptStatsProvider
*intc
;
936 InterruptStatsProviderClass
*k
;
937 Monitor
*mon
= opaque
;
939 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
940 intc
= INTERRUPT_STATS_PROVIDER(obj
);
941 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
942 uint64_t *irq_counts
;
943 unsigned int nb_irqs
, i
;
944 if (k
->get_statistics
&&
945 k
->get_statistics(intc
, &irq_counts
, &nb_irqs
)) {
947 monitor_printf(mon
, "IRQ statistics for %s:\n",
948 object_get_typename(obj
));
949 for (i
= 0; i
< nb_irqs
; i
++) {
950 if (irq_counts
[i
] > 0) {
951 monitor_printf(mon
, "%2d: %" PRId64
"\n", i
,
957 monitor_printf(mon
, "IRQ statistics not available for %s.\n",
958 object_get_typename(obj
));
965 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
)
967 object_child_foreach_recursive(object_get_root(),
968 hmp_info_irq_foreach
, mon
);
971 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
973 InterruptStatsProvider
*intc
;
974 InterruptStatsProviderClass
*k
;
975 Monitor
*mon
= opaque
;
977 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
978 intc
= INTERRUPT_STATS_PROVIDER(obj
);
979 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
981 k
->print_info(intc
, mon
);
983 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
984 object_get_typename(obj
));
991 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
993 object_child_foreach_recursive(object_get_root(),
994 hmp_info_pic_foreach
, mon
);
997 static int hmp_info_rdma_foreach(Object
*obj
, void *opaque
)
1000 RdmaProviderClass
*k
;
1001 Monitor
*mon
= opaque
;
1003 if (object_dynamic_cast(obj
, INTERFACE_RDMA_PROVIDER
)) {
1004 rdma
= RDMA_PROVIDER(obj
);
1005 k
= RDMA_PROVIDER_GET_CLASS(obj
);
1006 if (k
->print_statistics
) {
1007 k
->print_statistics(mon
, rdma
);
1009 monitor_printf(mon
, "RDMA statistics not available for %s.\n",
1010 object_get_typename(obj
));
1017 void hmp_info_rdma(Monitor
*mon
, const QDict
*qdict
)
1019 object_child_foreach_recursive(object_get_root(),
1020 hmp_info_rdma_foreach
, mon
);
1023 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
1025 PciInfoList
*info_list
, *info
;
1028 info_list
= qmp_query_pci(&err
);
1030 monitor_printf(mon
, "PCI devices not supported\n");
1035 for (info
= info_list
; info
; info
= info
->next
) {
1036 PciDeviceInfoList
*dev
;
1038 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
1039 hmp_info_pci_device(mon
, dev
->value
);
1043 qapi_free_PciInfoList(info_list
);
1046 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
1048 BlockJobInfoList
*list
;
1051 list
= qmp_query_block_jobs(&err
);
1055 monitor_printf(mon
, "No active jobs\n");
1060 if (strcmp(list
->value
->type
, "stream") == 0) {
1061 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
1062 " of %" PRId64
" bytes, speed limit %" PRId64
1064 list
->value
->device
,
1065 list
->value
->offset
,
1067 list
->value
->speed
);
1069 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
1070 " of %" PRId64
" bytes, speed limit %" PRId64
1073 list
->value
->device
,
1074 list
->value
->offset
,
1076 list
->value
->speed
);
1081 qapi_free_BlockJobInfoList(list
);
1084 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
1086 TPMInfoList
*info_list
, *info
;
1089 TPMPassthroughOptions
*tpo
;
1090 TPMEmulatorOptions
*teo
;
1092 info_list
= qmp_query_tpm(&err
);
1094 monitor_printf(mon
, "TPM device not supported\n");
1100 monitor_printf(mon
, "TPM device:\n");
1103 for (info
= info_list
; info
; info
= info
->next
) {
1104 TPMInfo
*ti
= info
->value
;
1105 monitor_printf(mon
, " tpm%d: model=%s\n",
1106 c
, TpmModel_str(ti
->model
));
1108 monitor_printf(mon
, " \\ %s: type=%s",
1109 ti
->id
, TpmTypeOptionsKind_str(ti
->options
->type
));
1111 switch (ti
->options
->type
) {
1112 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
1113 tpo
= ti
->options
->u
.passthrough
.data
;
1114 monitor_printf(mon
, "%s%s%s%s",
1115 tpo
->has_path
? ",path=" : "",
1116 tpo
->has_path
? tpo
->path
: "",
1117 tpo
->has_cancel_path
? ",cancel-path=" : "",
1118 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
1120 case TPM_TYPE_OPTIONS_KIND_EMULATOR
:
1121 teo
= ti
->options
->u
.emulator
.data
;
1122 monitor_printf(mon
, ",chardev=%s", teo
->chardev
);
1124 case TPM_TYPE_OPTIONS_KIND__MAX
:
1127 monitor_printf(mon
, "\n");
1130 qapi_free_TPMInfoList(info_list
);
1133 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
1135 monitor_suspend(mon
);
1139 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
1144 void hmp_sync_profile(Monitor
*mon
, const QDict
*qdict
)
1146 const char *op
= qdict_get_try_str(qdict
, "op");
1149 bool on
= qsp_is_enabled();
1151 monitor_printf(mon
, "sync-profile is %s\n", on
? "on" : "off");
1154 if (!strcmp(op
, "on")) {
1156 } else if (!strcmp(op
, "off")) {
1158 } else if (!strcmp(op
, "reset")) {
1163 error_setg(&err
, QERR_INVALID_PARAMETER
, op
);
1164 hmp_handle_error(mon
, &err
);
1168 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
1170 qmp_system_reset(NULL
);
1173 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
1175 qmp_system_powerdown(NULL
);
1178 void hmp_exit_preconfig(Monitor
*mon
, const QDict
*qdict
)
1182 qmp_x_exit_preconfig(&err
);
1183 hmp_handle_error(mon
, &err
);
1186 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
1190 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1191 use it are converted to the QAPI */
1192 cpu_index
= qdict_get_int(qdict
, "index");
1193 if (monitor_set_cpu(cpu_index
) < 0) {
1194 monitor_printf(mon
, "invalid CPU index\n");
1198 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
1200 uint32_t size
= qdict_get_int(qdict
, "size");
1201 const char *filename
= qdict_get_str(qdict
, "filename");
1202 uint64_t addr
= qdict_get_int(qdict
, "val");
1204 int cpu_index
= monitor_get_cpu_index();
1206 if (cpu_index
< 0) {
1207 monitor_printf(mon
, "No CPU available\n");
1211 qmp_memsave(addr
, size
, filename
, true, cpu_index
, &err
);
1212 hmp_handle_error(mon
, &err
);
1215 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
1217 uint32_t size
= qdict_get_int(qdict
, "size");
1218 const char *filename
= qdict_get_str(qdict
, "filename");
1219 uint64_t addr
= qdict_get_int(qdict
, "val");
1222 qmp_pmemsave(addr
, size
, filename
, &err
);
1223 hmp_handle_error(mon
, &err
);
1226 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
1228 const char *chardev
= qdict_get_str(qdict
, "device");
1229 const char *data
= qdict_get_str(qdict
, "data");
1232 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
1234 hmp_handle_error(mon
, &err
);
1237 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
1239 uint32_t size
= qdict_get_int(qdict
, "size");
1240 const char *chardev
= qdict_get_str(qdict
, "device");
1245 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
1247 hmp_handle_error(mon
, &err
);
1251 for (i
= 0; data
[i
]; i
++) {
1252 unsigned char ch
= data
[i
];
1255 monitor_printf(mon
, "\\\\");
1256 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
1257 monitor_printf(mon
, "\\u%04X", ch
);
1259 monitor_printf(mon
, "%c", ch
);
1263 monitor_printf(mon
, "\n");
1267 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
1272 hmp_handle_error(mon
, &err
);
1275 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
1279 qmp_system_wakeup(&err
);
1280 hmp_handle_error(mon
, &err
);
1283 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
1287 qmp_inject_nmi(&err
);
1288 hmp_handle_error(mon
, &err
);
1291 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
1293 const char *name
= qdict_get_str(qdict
, "name");
1294 bool up
= qdict_get_bool(qdict
, "up");
1297 qmp_set_link(name
, up
, &err
);
1298 hmp_handle_error(mon
, &err
);
1301 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
1303 const char *device
= qdict_get_str(qdict
, "device");
1304 const char *password
= qdict_get_str(qdict
, "password");
1307 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
1308 hmp_handle_error(mon
, &err
);
1311 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1313 int64_t value
= qdict_get_int(qdict
, "value");
1316 qmp_balloon(value
, &err
);
1317 hmp_handle_error(mon
, &err
);
1320 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
1322 const char *device
= qdict_get_str(qdict
, "device");
1323 int64_t size
= qdict_get_int(qdict
, "size");
1326 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
1327 hmp_handle_error(mon
, &err
);
1330 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
1332 const char *filename
= qdict_get_str(qdict
, "target");
1333 const char *format
= qdict_get_try_str(qdict
, "format");
1334 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1335 bool full
= qdict_get_try_bool(qdict
, "full", false);
1337 DriveMirror mirror
= {
1338 .device
= (char *)qdict_get_str(qdict
, "device"),
1339 .target
= (char *)filename
,
1340 .has_format
= !!format
,
1341 .format
= (char *)format
,
1342 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1344 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1349 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1350 hmp_handle_error(mon
, &err
);
1353 qmp_drive_mirror(&mirror
, &err
);
1354 hmp_handle_error(mon
, &err
);
1357 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
1359 const char *device
= qdict_get_str(qdict
, "device");
1360 const char *filename
= qdict_get_str(qdict
, "target");
1361 const char *format
= qdict_get_try_str(qdict
, "format");
1362 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1363 bool full
= qdict_get_try_bool(qdict
, "full", false);
1364 bool compress
= qdict_get_try_bool(qdict
, "compress", false);
1366 DriveBackup backup
= {
1367 .device
= (char *)device
,
1368 .target
= (char *)filename
,
1369 .has_format
= !!format
,
1370 .format
= (char *)format
,
1371 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1373 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1374 .has_compress
= !!compress
,
1375 .compress
= compress
,
1379 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1380 hmp_handle_error(mon
, &err
);
1384 qmp_drive_backup(&backup
, &err
);
1385 hmp_handle_error(mon
, &err
);
1388 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
1390 const char *device
= qdict_get_str(qdict
, "device");
1391 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
1392 const char *format
= qdict_get_try_str(qdict
, "format");
1393 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1394 enum NewImageMode mode
;
1398 /* In the future, if 'snapshot-file' is not specified, the snapshot
1399 will be taken internally. Today it's actually required. */
1400 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
1401 hmp_handle_error(mon
, &err
);
1405 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1406 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
1407 filename
, false, NULL
,
1410 hmp_handle_error(mon
, &err
);
1413 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1415 const char *device
= qdict_get_str(qdict
, "device");
1416 const char *name
= qdict_get_str(qdict
, "name");
1419 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1420 hmp_handle_error(mon
, &err
);
1423 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1425 const char *device
= qdict_get_str(qdict
, "device");
1426 const char *name
= qdict_get_str(qdict
, "name");
1427 const char *id
= qdict_get_try_str(qdict
, "id");
1430 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1432 hmp_handle_error(mon
, &err
);
1435 void hmp_loadvm(Monitor
*mon
, const QDict
*qdict
)
1437 int saved_vm_running
= runstate_is_running();
1438 const char *name
= qdict_get_str(qdict
, "name");
1441 vm_stop(RUN_STATE_RESTORE_VM
);
1443 if (load_snapshot(name
, &err
) == 0 && saved_vm_running
) {
1446 hmp_handle_error(mon
, &err
);
1449 void hmp_savevm(Monitor
*mon
, const QDict
*qdict
)
1453 save_snapshot(qdict_get_try_str(qdict
, "name"), &err
);
1454 hmp_handle_error(mon
, &err
);
1457 void hmp_delvm(Monitor
*mon
, const QDict
*qdict
)
1459 BlockDriverState
*bs
;
1461 const char *name
= qdict_get_str(qdict
, "name");
1463 if (bdrv_all_delete_snapshot(name
, &bs
, &err
) < 0) {
1465 "deleting snapshot on device '%s': ",
1466 bdrv_get_device_name(bs
));
1468 hmp_handle_error(mon
, &err
);
1471 void hmp_info_snapshots(Monitor
*mon
, const QDict
*qdict
)
1473 BlockDriverState
*bs
, *bs1
;
1474 BdrvNextIterator it1
;
1475 QEMUSnapshotInfo
*sn_tab
, *sn
;
1476 bool no_snapshot
= true;
1479 int *global_snapshots
;
1480 AioContext
*aio_context
;
1482 typedef struct SnapshotEntry
{
1483 QEMUSnapshotInfo sn
;
1484 QTAILQ_ENTRY(SnapshotEntry
) next
;
1487 typedef struct ImageEntry
{
1488 const char *imagename
;
1489 QTAILQ_ENTRY(ImageEntry
) next
;
1490 QTAILQ_HEAD(, SnapshotEntry
) snapshots
;
1493 QTAILQ_HEAD(, ImageEntry
) image_list
=
1494 QTAILQ_HEAD_INITIALIZER(image_list
);
1496 ImageEntry
*image_entry
, *next_ie
;
1497 SnapshotEntry
*snapshot_entry
;
1499 bs
= bdrv_all_find_vmstate_bs();
1501 monitor_printf(mon
, "No available block device supports snapshots\n");
1504 aio_context
= bdrv_get_aio_context(bs
);
1506 aio_context_acquire(aio_context
);
1507 nb_sns
= bdrv_snapshot_list(bs
, &sn_tab
);
1508 aio_context_release(aio_context
);
1511 monitor_printf(mon
, "bdrv_snapshot_list: error %d\n", nb_sns
);
1515 for (bs1
= bdrv_first(&it1
); bs1
; bs1
= bdrv_next(&it1
)) {
1519 AioContext
*ctx
= bdrv_get_aio_context(bs1
);
1521 aio_context_acquire(ctx
);
1522 if (bdrv_can_snapshot(bs1
)) {
1524 bs1_nb_sns
= bdrv_snapshot_list(bs1
, &sn
);
1525 if (bs1_nb_sns
> 0) {
1526 no_snapshot
= false;
1527 ie
= g_new0(ImageEntry
, 1);
1528 ie
->imagename
= bdrv_get_device_name(bs1
);
1529 QTAILQ_INIT(&ie
->snapshots
);
1530 QTAILQ_INSERT_TAIL(&image_list
, ie
, next
);
1531 for (i
= 0; i
< bs1_nb_sns
; i
++) {
1532 se
= g_new0(SnapshotEntry
, 1);
1534 QTAILQ_INSERT_TAIL(&ie
->snapshots
, se
, next
);
1539 aio_context_release(ctx
);
1543 monitor_printf(mon
, "There is no snapshot available.\n");
1547 global_snapshots
= g_new0(int, nb_sns
);
1549 for (i
= 0; i
< nb_sns
; i
++) {
1550 SnapshotEntry
*next_sn
;
1551 if (bdrv_all_find_snapshot(sn_tab
[i
].name
, &bs1
) == 0) {
1552 global_snapshots
[total
] = i
;
1554 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1555 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
,
1557 if (!strcmp(sn_tab
[i
].name
, snapshot_entry
->sn
.name
)) {
1558 QTAILQ_REMOVE(&image_entry
->snapshots
, snapshot_entry
,
1560 g_free(snapshot_entry
);
1567 monitor_printf(mon
, "List of snapshots present on all disks:\n");
1570 bdrv_snapshot_dump(NULL
);
1571 monitor_printf(mon
, "\n");
1572 for (i
= 0; i
< total
; i
++) {
1573 sn
= &sn_tab
[global_snapshots
[i
]];
1574 /* The ID is not guaranteed to be the same on all images, so
1577 pstrcpy(sn
->id_str
, sizeof(sn
->id_str
), "--");
1578 bdrv_snapshot_dump(sn
);
1579 monitor_printf(mon
, "\n");
1582 monitor_printf(mon
, "None\n");
1585 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1586 if (QTAILQ_EMPTY(&image_entry
->snapshots
)) {
1590 "\nList of partial (non-loadable) snapshots on '%s':\n",
1591 image_entry
->imagename
);
1592 bdrv_snapshot_dump(NULL
);
1593 monitor_printf(mon
, "\n");
1594 QTAILQ_FOREACH(snapshot_entry
, &image_entry
->snapshots
, next
) {
1595 bdrv_snapshot_dump(&snapshot_entry
->sn
);
1596 monitor_printf(mon
, "\n");
1600 QTAILQ_FOREACH_SAFE(image_entry
, &image_list
, next
, next_ie
) {
1601 SnapshotEntry
*next_sn
;
1602 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
, next
,
1604 g_free(snapshot_entry
);
1606 g_free(image_entry
);
1609 g_free(global_snapshots
);
1613 void hmp_announce_self(Monitor
*mon
, const QDict
*qdict
)
1615 qmp_announce_self(migrate_announce_params(), NULL
);
1618 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1620 qmp_migrate_cancel(NULL
);
1623 void hmp_migrate_continue(Monitor
*mon
, const QDict
*qdict
)
1626 const char *state
= qdict_get_str(qdict
, "state");
1627 int val
= qapi_enum_parse(&MigrationStatus_lookup
, state
, -1, &err
);
1630 qmp_migrate_continue(val
, &err
);
1633 hmp_handle_error(mon
, &err
);
1636 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1639 const char *uri
= qdict_get_str(qdict
, "uri");
1641 qmp_migrate_incoming(uri
, &err
);
1643 hmp_handle_error(mon
, &err
);
1646 void hmp_migrate_recover(Monitor
*mon
, const QDict
*qdict
)
1649 const char *uri
= qdict_get_str(qdict
, "uri");
1651 qmp_migrate_recover(uri
, &err
);
1653 hmp_handle_error(mon
, &err
);
1656 void hmp_migrate_pause(Monitor
*mon
, const QDict
*qdict
)
1660 qmp_migrate_pause(&err
);
1662 hmp_handle_error(mon
, &err
);
1665 /* Kept for backwards compatibility */
1666 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1668 double value
= qdict_get_double(qdict
, "value");
1669 qmp_migrate_set_downtime(value
, NULL
);
1672 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1674 int64_t value
= qdict_get_int(qdict
, "value");
1677 qmp_migrate_set_cache_size(value
, &err
);
1678 hmp_handle_error(mon
, &err
);
1681 /* Kept for backwards compatibility */
1682 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1684 int64_t value
= qdict_get_int(qdict
, "value");
1685 qmp_migrate_set_speed(value
, NULL
);
1688 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1690 const char *cap
= qdict_get_str(qdict
, "capability");
1691 bool state
= qdict_get_bool(qdict
, "state");
1693 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1696 val
= qapi_enum_parse(&MigrationCapability_lookup
, cap
, -1, &err
);
1701 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1702 caps
->value
->capability
= val
;
1703 caps
->value
->state
= state
;
1705 qmp_migrate_set_capabilities(caps
, &err
);
1708 qapi_free_MigrationCapabilityStatusList(caps
);
1709 hmp_handle_error(mon
, &err
);
1712 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1714 const char *param
= qdict_get_str(qdict
, "parameter");
1715 const char *valuestr
= qdict_get_str(qdict
, "value");
1716 Visitor
*v
= string_input_visitor_new(valuestr
);
1717 MigrateSetParameters
*p
= g_new0(MigrateSetParameters
, 1);
1718 uint64_t valuebw
= 0;
1719 uint64_t cache_size
;
1723 val
= qapi_enum_parse(&MigrationParameter_lookup
, param
, -1, &err
);
1729 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1730 p
->has_compress_level
= true;
1731 visit_type_int(v
, param
, &p
->compress_level
, &err
);
1733 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1734 p
->has_compress_threads
= true;
1735 visit_type_int(v
, param
, &p
->compress_threads
, &err
);
1737 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD
:
1738 p
->has_compress_wait_thread
= true;
1739 visit_type_bool(v
, param
, &p
->compress_wait_thread
, &err
);
1741 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1742 p
->has_decompress_threads
= true;
1743 visit_type_int(v
, param
, &p
->decompress_threads
, &err
);
1745 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1746 p
->has_cpu_throttle_initial
= true;
1747 visit_type_int(v
, param
, &p
->cpu_throttle_initial
, &err
);
1749 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1750 p
->has_cpu_throttle_increment
= true;
1751 visit_type_int(v
, param
, &p
->cpu_throttle_increment
, &err
);
1753 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE
:
1754 p
->has_max_cpu_throttle
= true;
1755 visit_type_int(v
, param
, &p
->max_cpu_throttle
, &err
);
1757 case MIGRATION_PARAMETER_TLS_CREDS
:
1758 p
->has_tls_creds
= true;
1759 p
->tls_creds
= g_new0(StrOrNull
, 1);
1760 p
->tls_creds
->type
= QTYPE_QSTRING
;
1761 visit_type_str(v
, param
, &p
->tls_creds
->u
.s
, &err
);
1763 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1764 p
->has_tls_hostname
= true;
1765 p
->tls_hostname
= g_new0(StrOrNull
, 1);
1766 p
->tls_hostname
->type
= QTYPE_QSTRING
;
1767 visit_type_str(v
, param
, &p
->tls_hostname
->u
.s
, &err
);
1769 case MIGRATION_PARAMETER_TLS_AUTHZ
:
1770 p
->has_tls_authz
= true;
1771 p
->tls_authz
= g_new0(StrOrNull
, 1);
1772 p
->tls_authz
->type
= QTYPE_QSTRING
;
1773 visit_type_str(v
, param
, &p
->tls_authz
->u
.s
, &err
);
1775 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1776 p
->has_max_bandwidth
= true;
1778 * Can't use visit_type_size() here, because it
1779 * defaults to Bytes rather than Mebibytes.
1781 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
1782 if (ret
< 0 || valuebw
> INT64_MAX
1783 || (size_t)valuebw
!= valuebw
) {
1784 error_setg(&err
, "Invalid size %s", valuestr
);
1787 p
->max_bandwidth
= valuebw
;
1789 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1790 p
->has_downtime_limit
= true;
1791 visit_type_int(v
, param
, &p
->downtime_limit
, &err
);
1793 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
1794 p
->has_x_checkpoint_delay
= true;
1795 visit_type_int(v
, param
, &p
->x_checkpoint_delay
, &err
);
1797 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL
:
1798 p
->has_block_incremental
= true;
1799 visit_type_bool(v
, param
, &p
->block_incremental
, &err
);
1801 case MIGRATION_PARAMETER_MULTIFD_CHANNELS
:
1802 p
->has_multifd_channels
= true;
1803 visit_type_int(v
, param
, &p
->multifd_channels
, &err
);
1805 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
:
1806 p
->has_xbzrle_cache_size
= true;
1807 visit_type_size(v
, param
, &cache_size
, &err
);
1811 if (cache_size
> INT64_MAX
|| (size_t)cache_size
!= cache_size
) {
1812 error_setg(&err
, "Invalid size %s", valuestr
);
1815 p
->xbzrle_cache_size
= cache_size
;
1817 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH
:
1818 p
->has_max_postcopy_bandwidth
= true;
1819 visit_type_size(v
, param
, &p
->max_postcopy_bandwidth
, &err
);
1821 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL
:
1822 p
->has_announce_initial
= true;
1823 visit_type_size(v
, param
, &p
->announce_initial
, &err
);
1825 case MIGRATION_PARAMETER_ANNOUNCE_MAX
:
1826 p
->has_announce_max
= true;
1827 visit_type_size(v
, param
, &p
->announce_max
, &err
);
1829 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS
:
1830 p
->has_announce_rounds
= true;
1831 visit_type_size(v
, param
, &p
->announce_rounds
, &err
);
1833 case MIGRATION_PARAMETER_ANNOUNCE_STEP
:
1834 p
->has_announce_step
= true;
1835 visit_type_size(v
, param
, &p
->announce_step
, &err
);
1845 qmp_migrate_set_parameters(p
, &err
);
1848 qapi_free_MigrateSetParameters(p
);
1850 hmp_handle_error(mon
, &err
);
1853 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1856 const char *protocol
= qdict_get_str(qdict
, "protocol");
1857 const char *hostname
= qdict_get_str(qdict
, "hostname");
1858 bool has_port
= qdict_haskey(qdict
, "port");
1859 int port
= qdict_get_try_int(qdict
, "port", -1);
1860 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1861 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1862 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1864 qmp_client_migrate_info(protocol
, hostname
,
1865 has_port
, port
, has_tls_port
, tls_port
,
1866 !!cert_subject
, cert_subject
, &err
);
1867 hmp_handle_error(mon
, &err
);
1870 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1873 qmp_migrate_start_postcopy(&err
);
1874 hmp_handle_error(mon
, &err
);
1877 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1881 qmp_x_colo_lost_heartbeat(&err
);
1882 hmp_handle_error(mon
, &err
);
1885 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1887 const char *protocol
= qdict_get_str(qdict
, "protocol");
1888 const char *password
= qdict_get_str(qdict
, "password");
1889 const char *connected
= qdict_get_try_str(qdict
, "connected");
1892 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1893 hmp_handle_error(mon
, &err
);
1896 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1898 const char *protocol
= qdict_get_str(qdict
, "protocol");
1899 const char *whenstr
= qdict_get_str(qdict
, "time");
1902 qmp_expire_password(protocol
, whenstr
, &err
);
1903 hmp_handle_error(mon
, &err
);
1906 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1908 bool force
= qdict_get_try_bool(qdict
, "force", false);
1909 const char *device
= qdict_get_str(qdict
, "device");
1912 qmp_eject(true, device
, false, NULL
, true, force
, &err
);
1913 hmp_handle_error(mon
, &err
);
1917 static void hmp_change_read_arg(void *opaque
, const char *password
,
1918 void *readline_opaque
)
1920 qmp_change_vnc_password(password
, NULL
);
1921 monitor_read_command(opaque
, 1);
1925 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1927 MonitorHMP
*hmp_mon
= container_of(mon
, MonitorHMP
, common
);
1928 const char *device
= qdict_get_str(qdict
, "device");
1929 const char *target
= qdict_get_str(qdict
, "target");
1930 const char *arg
= qdict_get_try_str(qdict
, "arg");
1931 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1932 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1936 if (strcmp(device
, "vnc") == 0) {
1939 "Parameter 'read-only-mode' is invalid for VNC\n");
1942 if (strcmp(target
, "passwd") == 0 ||
1943 strcmp(target
, "password") == 0) {
1945 monitor_read_password(hmp_mon
, hmp_change_read_arg
, NULL
);
1949 qmp_change("vnc", target
, !!arg
, arg
, &err
);
1955 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup
,
1957 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1959 hmp_handle_error(mon
, &err
);
1964 qmp_blockdev_change_medium(true, device
, false, NULL
, target
,
1965 !!arg
, arg
, !!read_only
, read_only_mode
,
1969 hmp_handle_error(mon
, &err
);
1972 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1975 char *device
= (char *) qdict_get_str(qdict
, "device");
1976 BlockIOThrottle throttle
= {
1977 .bps
= qdict_get_int(qdict
, "bps"),
1978 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
1979 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
1980 .iops
= qdict_get_int(qdict
, "iops"),
1981 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
1982 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
1985 /* qmp_block_set_io_throttle has separate parameters for the
1986 * (deprecated) block device name and the qdev ID but the HMP
1987 * version has only one, so we must decide which one to pass. */
1988 if (blk_by_name(device
)) {
1989 throttle
.has_device
= true;
1990 throttle
.device
= device
;
1992 throttle
.has_id
= true;
1993 throttle
.id
= device
;
1996 qmp_block_set_io_throttle(&throttle
, &err
);
1997 hmp_handle_error(mon
, &err
);
2000 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
2002 Error
*error
= NULL
;
2003 const char *device
= qdict_get_str(qdict
, "device");
2004 const char *base
= qdict_get_try_str(qdict
, "base");
2005 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
2007 qmp_block_stream(true, device
, device
, base
!= NULL
, base
, false, NULL
,
2008 false, NULL
, qdict_haskey(qdict
, "speed"), speed
, true,
2009 BLOCKDEV_ON_ERROR_REPORT
, false, false, false, false,
2012 hmp_handle_error(mon
, &error
);
2015 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
2017 Error
*error
= NULL
;
2018 const char *device
= qdict_get_str(qdict
, "device");
2019 int64_t value
= qdict_get_int(qdict
, "speed");
2021 qmp_block_job_set_speed(device
, value
, &error
);
2023 hmp_handle_error(mon
, &error
);
2026 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
2028 Error
*error
= NULL
;
2029 const char *device
= qdict_get_str(qdict
, "device");
2030 bool force
= qdict_get_try_bool(qdict
, "force", false);
2032 qmp_block_job_cancel(device
, true, force
, &error
);
2034 hmp_handle_error(mon
, &error
);
2037 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
2039 Error
*error
= NULL
;
2040 const char *device
= qdict_get_str(qdict
, "device");
2042 qmp_block_job_pause(device
, &error
);
2044 hmp_handle_error(mon
, &error
);
2047 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
2049 Error
*error
= NULL
;
2050 const char *device
= qdict_get_str(qdict
, "device");
2052 qmp_block_job_resume(device
, &error
);
2054 hmp_handle_error(mon
, &error
);
2057 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
2059 Error
*error
= NULL
;
2060 const char *device
= qdict_get_str(qdict
, "device");
2062 qmp_block_job_complete(device
, &error
);
2064 hmp_handle_error(mon
, &error
);
2067 typedef struct HMPMigrationStatus
2071 bool is_block_migration
;
2072 } HMPMigrationStatus
;
2074 static void hmp_migrate_status_cb(void *opaque
)
2076 HMPMigrationStatus
*status
= opaque
;
2077 MigrationInfo
*info
;
2079 info
= qmp_query_migrate(NULL
);
2080 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
2081 info
->status
== MIGRATION_STATUS_SETUP
) {
2082 if (info
->has_disk
) {
2085 if (info
->disk
->remaining
) {
2086 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
2091 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
2092 monitor_flush(status
->mon
);
2095 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
2097 if (status
->is_block_migration
) {
2098 monitor_printf(status
->mon
, "\n");
2100 if (info
->has_error_desc
) {
2101 error_report("%s", info
->error_desc
);
2103 monitor_resume(status
->mon
);
2104 timer_del(status
->timer
);
2105 timer_free(status
->timer
);
2109 qapi_free_MigrationInfo(info
);
2112 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
2114 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
2115 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
2116 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
2117 bool resume
= qdict_get_try_bool(qdict
, "resume", false);
2118 const char *uri
= qdict_get_str(qdict
, "uri");
2121 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
,
2122 false, false, true, resume
, &err
);
2124 hmp_handle_error(mon
, &err
);
2129 HMPMigrationStatus
*status
;
2131 if (monitor_suspend(mon
) < 0) {
2132 monitor_printf(mon
, "terminal does not allow synchronous "
2133 "migration, continuing detached\n");
2137 status
= g_malloc0(sizeof(*status
));
2139 status
->is_block_migration
= blk
|| inc
;
2140 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
2142 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
2146 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
2150 qmp_device_add((QDict
*)qdict
, NULL
, &err
);
2151 hmp_handle_error(mon
, &err
);
2154 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
2156 const char *id
= qdict_get_str(qdict
, "id");
2159 qmp_device_del(id
, &err
);
2160 hmp_handle_error(mon
, &err
);
2163 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
2166 bool win_dmp
= qdict_get_try_bool(qdict
, "windmp", false);
2167 bool paging
= qdict_get_try_bool(qdict
, "paging", false);
2168 bool zlib
= qdict_get_try_bool(qdict
, "zlib", false);
2169 bool lzo
= qdict_get_try_bool(qdict
, "lzo", false);
2170 bool snappy
= qdict_get_try_bool(qdict
, "snappy", false);
2171 const char *file
= qdict_get_str(qdict
, "filename");
2172 bool has_begin
= qdict_haskey(qdict
, "begin");
2173 bool has_length
= qdict_haskey(qdict
, "length");
2174 bool has_detach
= qdict_haskey(qdict
, "detach");
2177 bool detach
= false;
2178 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
2181 if (zlib
+ lzo
+ snappy
+ win_dmp
> 1) {
2182 error_setg(&err
, "only one of '-z|-l|-s|-w' can be set");
2183 hmp_handle_error(mon
, &err
);
2188 dump_format
= DUMP_GUEST_MEMORY_FORMAT_WIN_DMP
;
2192 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
2196 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
2200 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
2204 begin
= qdict_get_int(qdict
, "begin");
2207 length
= qdict_get_int(qdict
, "length");
2210 detach
= qdict_get_bool(qdict
, "detach");
2213 prot
= g_strconcat("file:", file
, NULL
);
2215 qmp_dump_guest_memory(paging
, prot
, true, detach
, has_begin
, begin
,
2216 has_length
, length
, true, dump_format
, &err
);
2217 hmp_handle_error(mon
, &err
);
2221 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
2226 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
2231 netdev_add(opts
, &err
);
2233 qemu_opts_del(opts
);
2237 hmp_handle_error(mon
, &err
);
2240 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
2242 const char *id
= qdict_get_str(qdict
, "id");
2245 qmp_netdev_del(id
, &err
);
2246 hmp_handle_error(mon
, &err
);
2249 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
2255 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
2257 hmp_handle_error(mon
, &err
);
2261 obj
= user_creatable_add_opts(opts
, &err
);
2262 qemu_opts_del(opts
);
2265 hmp_handle_error(mon
, &err
);
2272 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
2274 const char *fdname
= qdict_get_str(qdict
, "fdname");
2277 qmp_getfd(fdname
, &err
);
2278 hmp_handle_error(mon
, &err
);
2281 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
2283 const char *fdname
= qdict_get_str(qdict
, "fdname");
2286 qmp_closefd(fdname
, &err
);
2287 hmp_handle_error(mon
, &err
);
2290 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
2292 const char *keys
= qdict_get_str(qdict
, "keys");
2293 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
2294 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
2295 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
2297 const char *separator
;
2301 separator
= qemu_strchrnul(keys
, '-');
2302 keyname_len
= separator
- keys
;
2304 /* Be compatible with old interface, convert user inputted "<" */
2305 if (keys
[0] == '<' && keyname_len
== 1) {
2310 keylist
= g_malloc0(sizeof(*keylist
));
2311 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
2317 tmp
->next
= keylist
;
2321 if (strstart(keys
, "0x", NULL
)) {
2323 int value
= strtoul(keys
, &endp
, 0);
2324 assert(endp
<= keys
+ keyname_len
);
2325 if (endp
!= keys
+ keyname_len
) {
2328 keylist
->value
->type
= KEY_VALUE_KIND_NUMBER
;
2329 keylist
->value
->u
.number
.data
= value
;
2331 int idx
= index_from_key(keys
, keyname_len
);
2332 if (idx
== Q_KEY_CODE__MAX
) {
2335 keylist
->value
->type
= KEY_VALUE_KIND_QCODE
;
2336 keylist
->value
->u
.qcode
.data
= idx
;
2342 keys
= separator
+ 1;
2345 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
2346 hmp_handle_error(mon
, &err
);
2349 qapi_free_KeyValueList(head
);
2353 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
2357 void hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
2359 const char *filename
= qdict_get_str(qdict
, "filename");
2360 const char *id
= qdict_get_try_str(qdict
, "device");
2361 int64_t head
= qdict_get_try_int(qdict
, "head", 0);
2364 qmp_screendump(filename
, id
!= NULL
, id
, id
!= NULL
, head
, &err
);
2365 hmp_handle_error(mon
, &err
);
2368 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
2370 const char *uri
= qdict_get_str(qdict
, "uri");
2371 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2372 bool all
= qdict_get_try_bool(qdict
, "all", false);
2373 Error
*local_err
= NULL
;
2374 BlockInfoList
*block_list
, *info
;
2375 SocketAddress
*addr
;
2377 if (writable
&& !all
) {
2378 error_setg(&local_err
, "-w only valid together with -a");
2382 /* First check if the address is valid and start the server. */
2383 addr
= socket_parse(uri
, &local_err
);
2384 if (local_err
!= NULL
) {
2388 nbd_server_start(addr
, NULL
, NULL
, &local_err
);
2389 qapi_free_SocketAddress(addr
);
2390 if (local_err
!= NULL
) {
2398 /* Then try adding all block devices. If one fails, close all and
2401 block_list
= qmp_query_block(NULL
);
2403 for (info
= block_list
; info
; info
= info
->next
) {
2404 if (!info
->value
->has_inserted
) {
2408 qmp_nbd_server_add(info
->value
->device
, false, NULL
,
2409 true, writable
, false, NULL
, &local_err
);
2411 if (local_err
!= NULL
) {
2412 qmp_nbd_server_stop(NULL
);
2417 qapi_free_BlockInfoList(block_list
);
2420 hmp_handle_error(mon
, &local_err
);
2423 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
2425 const char *device
= qdict_get_str(qdict
, "device");
2426 const char *name
= qdict_get_try_str(qdict
, "name");
2427 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2428 Error
*local_err
= NULL
;
2430 qmp_nbd_server_add(device
, !!name
, name
, true, writable
,
2431 false, NULL
, &local_err
);
2432 hmp_handle_error(mon
, &local_err
);
2435 void hmp_nbd_server_remove(Monitor
*mon
, const QDict
*qdict
)
2437 const char *name
= qdict_get_str(qdict
, "name");
2438 bool force
= qdict_get_try_bool(qdict
, "force", false);
2441 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
2442 qmp_nbd_server_remove(name
, force
, NBD_SERVER_REMOVE_MODE_HARD
, &err
);
2443 hmp_handle_error(mon
, &err
);
2446 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
2450 qmp_nbd_server_stop(&err
);
2451 hmp_handle_error(mon
, &err
);
2454 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
2456 const char *args
= qdict_get_str(qdict
, "args");
2460 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
2462 error_setg(&err
, "Parsing chardev args failed");
2464 qemu_chr_new_from_opts(opts
, NULL
, &err
);
2465 qemu_opts_del(opts
);
2467 hmp_handle_error(mon
, &err
);
2470 void hmp_chardev_change(Monitor
*mon
, const QDict
*qdict
)
2472 const char *args
= qdict_get_str(qdict
, "args");
2475 ChardevBackend
*backend
= NULL
;
2476 ChardevReturn
*ret
= NULL
;
2477 QemuOpts
*opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
,
2480 error_setg(&err
, "Parsing chardev args failed");
2484 id
= qdict_get_str(qdict
, "id");
2485 if (qemu_opts_id(opts
)) {
2486 error_setg(&err
, "Unexpected 'id' parameter");
2490 backend
= qemu_chr_parse_opts(opts
, &err
);
2495 ret
= qmp_chardev_change(id
, backend
, &err
);
2498 qapi_free_ChardevReturn(ret
);
2499 qapi_free_ChardevBackend(backend
);
2500 qemu_opts_del(opts
);
2501 hmp_handle_error(mon
, &err
);
2504 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
2506 Error
*local_err
= NULL
;
2508 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
2509 hmp_handle_error(mon
, &local_err
);
2512 void hmp_chardev_send_break(Monitor
*mon
, const QDict
*qdict
)
2514 Error
*local_err
= NULL
;
2516 qmp_chardev_send_break(qdict_get_str(qdict
, "id"), &local_err
);
2517 hmp_handle_error(mon
, &local_err
);
2520 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
2523 BlockBackend
*local_blk
= NULL
;
2524 const char* device
= qdict_get_str(qdict
, "device");
2525 const char* command
= qdict_get_str(qdict
, "command");
2529 blk
= blk_by_name(device
);
2531 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, device
, &err
);
2533 blk
= local_blk
= blk_new(bdrv_get_aio_context(bs
),
2535 ret
= blk_insert_bs(blk
, bs
, &err
);
2545 * Notably absent: Proper permission management. This is sad, but it seems
2546 * almost impossible to achieve without changing the semantics and thereby
2547 * limiting the use cases of the qemu-io HMP command.
2549 * In an ideal world we would unconditionally create a new BlockBackend for
2550 * qemuio_command(), but we have commands like 'reopen' and want them to
2551 * take effect on the exact BlockBackend whose name the user passed instead
2552 * of just on a temporary copy of it.
2554 * Another problem is that deleting the temporary BlockBackend involves
2555 * draining all requests on it first, but some qemu-iotests cases want to
2556 * issue multiple aio_read/write requests and expect them to complete in
2557 * the background while the monitor has already returned.
2559 * This is also what prevents us from saving the original permissions and
2560 * restoring them later: We can't revoke permissions until all requests
2561 * have completed, and we don't know when that is nor can we really let
2562 * anything else run before we have revoken them to avoid race conditions.
2564 * What happens now is that command() in qemu-io-cmds.c can extend the
2565 * permissions if necessary for the qemu-io command. And they simply stay
2566 * extended, possibly resulting in a read-only guest device keeping write
2567 * permissions. Ugly, but it appears to be the lesser evil.
2569 qemuio_command(blk
, command
);
2572 blk_unref(local_blk
);
2573 hmp_handle_error(mon
, &err
);
2576 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
2578 const char *id
= qdict_get_str(qdict
, "id");
2581 user_creatable_del(id
, &err
);
2582 hmp_handle_error(mon
, &err
);
2585 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
2588 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
2589 MemoryDeviceInfoList
*info
;
2590 MemoryDeviceInfo
*value
;
2591 PCDIMMDeviceInfo
*di
;
2593 for (info
= info_list
; info
; info
= info
->next
) {
2594 value
= info
->value
;
2597 switch (value
->type
) {
2598 case MEMORY_DEVICE_INFO_KIND_DIMM
:
2599 di
= value
->u
.dimm
.data
;
2602 case MEMORY_DEVICE_INFO_KIND_NVDIMM
:
2603 di
= value
->u
.nvdimm
.data
;
2612 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
2613 MemoryDeviceInfoKind_str(value
->type
),
2614 di
->id
? di
->id
: "");
2615 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
2616 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
2617 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
2618 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
2619 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
2620 monitor_printf(mon
, " hotplugged: %s\n",
2621 di
->hotplugged
? "true" : "false");
2622 monitor_printf(mon
, " hotpluggable: %s\n",
2623 di
->hotpluggable
? "true" : "false");
2628 qapi_free_MemoryDeviceInfoList(info_list
);
2629 hmp_handle_error(mon
, &err
);
2632 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
2634 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
2635 IOThreadInfoList
*info
;
2636 IOThreadInfo
*value
;
2638 for (info
= info_list
; info
; info
= info
->next
) {
2639 value
= info
->value
;
2640 monitor_printf(mon
, "%s:\n", value
->id
);
2641 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
2642 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
2643 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
2644 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
2647 qapi_free_IOThreadInfoList(info_list
);
2650 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
2652 const char *name
= qdict_get_str(qdict
, "name");
2653 RockerSwitch
*rocker
;
2656 rocker
= qmp_query_rocker(name
, &err
);
2658 hmp_handle_error(mon
, &err
);
2662 monitor_printf(mon
, "name: %s\n", rocker
->name
);
2663 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
2664 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
2666 qapi_free_RockerSwitch(rocker
);
2669 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
2671 RockerPortList
*list
, *port
;
2672 const char *name
= qdict_get_str(qdict
, "name");
2675 list
= qmp_query_rocker_ports(name
, &err
);
2677 hmp_handle_error(mon
, &err
);
2681 monitor_printf(mon
, " ena/ speed/ auto\n");
2682 monitor_printf(mon
, " port link duplex neg?\n");
2684 for (port
= list
; port
; port
= port
->next
) {
2685 monitor_printf(mon
, "%10s %-4s %-3s %2s %-3s\n",
2687 port
->value
->enabled
? port
->value
->link_up
?
2688 "up" : "down" : "!ena",
2689 port
->value
->speed
== 10000 ? "10G" : "??",
2690 port
->value
->duplex
? "FD" : "HD",
2691 port
->value
->autoneg
? "Yes" : "No");
2694 qapi_free_RockerPortList(list
);
2697 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
2699 RockerOfDpaFlowList
*list
, *info
;
2700 const char *name
= qdict_get_str(qdict
, "name");
2701 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
2704 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
2706 hmp_handle_error(mon
, &err
);
2710 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
2712 for (info
= list
; info
; info
= info
->next
) {
2713 RockerOfDpaFlow
*flow
= info
->value
;
2714 RockerOfDpaFlowKey
*key
= flow
->key
;
2715 RockerOfDpaFlowMask
*mask
= flow
->mask
;
2716 RockerOfDpaFlowAction
*action
= flow
->action
;
2719 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
2720 key
->priority
, key
->tbl_id
, flow
->hits
);
2722 monitor_printf(mon
, "%-4d %-3d ",
2723 key
->priority
, key
->tbl_id
);
2726 if (key
->has_in_pport
) {
2727 monitor_printf(mon
, " pport %d", key
->in_pport
);
2728 if (mask
->has_in_pport
) {
2729 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2733 if (key
->has_vlan_id
) {
2734 monitor_printf(mon
, " vlan %d",
2735 key
->vlan_id
& VLAN_VID_MASK
);
2736 if (mask
->has_vlan_id
) {
2737 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2741 if (key
->has_tunnel_id
) {
2742 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2743 if (mask
->has_tunnel_id
) {
2744 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2748 if (key
->has_eth_type
) {
2749 switch (key
->eth_type
) {
2751 monitor_printf(mon
, " ARP");
2754 monitor_printf(mon
, " IP");
2757 monitor_printf(mon
, " IPv6");
2760 monitor_printf(mon
, " LACP");
2763 monitor_printf(mon
, " LLDP");
2766 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2771 if (key
->has_eth_src
) {
2772 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2773 (mask
->has_eth_src
) &&
2774 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2775 monitor_printf(mon
, " src <any mcast/bcast>");
2776 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2777 (mask
->has_eth_src
) &&
2778 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2779 monitor_printf(mon
, " src <any ucast>");
2781 monitor_printf(mon
, " src %s", key
->eth_src
);
2782 if (mask
->has_eth_src
) {
2783 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2788 if (key
->has_eth_dst
) {
2789 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2790 (mask
->has_eth_dst
) &&
2791 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2792 monitor_printf(mon
, " dst <any mcast/bcast>");
2793 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2794 (mask
->has_eth_dst
) &&
2795 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2796 monitor_printf(mon
, " dst <any ucast>");
2798 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2799 if (mask
->has_eth_dst
) {
2800 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2805 if (key
->has_ip_proto
) {
2806 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2807 if (mask
->has_ip_proto
) {
2808 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2812 if (key
->has_ip_tos
) {
2813 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2814 if (mask
->has_ip_tos
) {
2815 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2819 if (key
->has_ip_dst
) {
2820 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2823 if (action
->has_goto_tbl
|| action
->has_group_id
||
2824 action
->has_new_vlan_id
) {
2825 monitor_printf(mon
, " -->");
2828 if (action
->has_new_vlan_id
) {
2829 monitor_printf(mon
, " apply new vlan %d",
2830 ntohs(action
->new_vlan_id
));
2833 if (action
->has_group_id
) {
2834 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2837 if (action
->has_goto_tbl
) {
2838 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2841 monitor_printf(mon
, "\n");
2844 qapi_free_RockerOfDpaFlowList(list
);
2847 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2849 RockerOfDpaGroupList
*list
, *g
;
2850 const char *name
= qdict_get_str(qdict
, "name");
2851 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2855 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
2857 hmp_handle_error(mon
, &err
);
2861 monitor_printf(mon
, "id (decode) --> buckets\n");
2863 for (g
= list
; g
; g
= g
->next
) {
2864 RockerOfDpaGroup
*group
= g
->value
;
2866 monitor_printf(mon
, "0x%08x", group
->id
);
2868 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2869 group
->type
== 1 ? "L2 rewrite" :
2870 group
->type
== 2 ? "L3 unicast" :
2871 group
->type
== 3 ? "L2 multicast" :
2872 group
->type
== 4 ? "L2 flood" :
2873 group
->type
== 5 ? "L3 interface" :
2874 group
->type
== 6 ? "L3 multicast" :
2875 group
->type
== 7 ? "L3 ECMP" :
2876 group
->type
== 8 ? "L2 overlay" :
2879 if (group
->has_vlan_id
) {
2880 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2883 if (group
->has_pport
) {
2884 monitor_printf(mon
, " pport %d", group
->pport
);
2887 if (group
->has_index
) {
2888 monitor_printf(mon
, " index %d", group
->index
);
2891 monitor_printf(mon
, ") -->");
2893 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2895 monitor_printf(mon
, " set vlan %d",
2896 group
->set_vlan_id
& VLAN_VID_MASK
);
2899 if (group
->has_set_eth_src
) {
2902 monitor_printf(mon
, " set");
2904 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2907 if (group
->has_set_eth_dst
) {
2910 monitor_printf(mon
, " set");
2912 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2917 if (group
->has_ttl_check
&& group
->ttl_check
) {
2918 monitor_printf(mon
, " check TTL");
2921 if (group
->has_group_id
&& group
->group_id
) {
2922 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2925 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2926 monitor_printf(mon
, " pop vlan");
2929 if (group
->has_out_pport
) {
2930 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2933 if (group
->has_group_ids
) {
2934 struct uint32List
*id
;
2936 monitor_printf(mon
, " groups [");
2937 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2938 monitor_printf(mon
, "0x%08x", id
->value
);
2940 monitor_printf(mon
, ",");
2943 monitor_printf(mon
, "]");
2946 monitor_printf(mon
, "\n");
2949 qapi_free_RockerOfDpaGroupList(list
);
2952 void hmp_info_dump(Monitor
*mon
, const QDict
*qdict
)
2954 DumpQueryResult
*result
= qmp_query_dump(NULL
);
2956 assert(result
&& result
->status
< DUMP_STATUS__MAX
);
2957 monitor_printf(mon
, "Status: %s\n", DumpStatus_str(result
->status
));
2959 if (result
->status
== DUMP_STATUS_ACTIVE
) {
2961 assert(result
->total
!= 0);
2962 percent
= 100.0 * result
->completed
/ result
->total
;
2963 monitor_printf(mon
, "Finished: %.2f %%\n", percent
);
2966 qapi_free_DumpQueryResult(result
);
2969 void hmp_info_ramblock(Monitor
*mon
, const QDict
*qdict
)
2971 ram_block_dump(mon
);
2974 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
2977 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
2979 monitor_printf(mon
, "%s\n", info
->guid
);
2981 hmp_handle_error(mon
, &err
);
2982 qapi_free_GuidInfo(info
);
2985 void hmp_info_memory_size_summary(Monitor
*mon
, const QDict
*qdict
)
2988 MemoryInfo
*info
= qmp_query_memory_size_summary(&err
);
2990 monitor_printf(mon
, "base memory: %" PRIu64
"\n",
2993 if (info
->has_plugged_memory
) {
2994 monitor_printf(mon
, "plugged memory: %" PRIu64
"\n",
2995 info
->plugged_memory
);
2998 qapi_free_MemoryInfo(info
);
3000 hmp_handle_error(mon
, &err
);