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"
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/clone-visitor.h"
31 #include "qapi/opts-visitor.h"
32 #include "qapi/qapi-builtin-visit.h"
33 #include "qapi/qapi-commands-block.h"
34 #include "qapi/qapi-commands-char.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-rocker.h"
39 #include "qapi/qapi-commands-run-state.h"
40 #include "qapi/qapi-commands-tpm.h"
41 #include "qapi/qapi-commands-ui.h"
42 #include "qapi/qapi-visit-net.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 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
68 error_reportf_err(*errp
, "Error: ");
73 * Produce a strList from a comma separated list.
74 * A NULL or empty input string return NULL.
76 static strList
*strList_from_comma_list(const char *in
)
79 strList
**hook
= &res
;
82 char *comma
= strchr(in
, ',');
83 *hook
= g_new0(strList
, 1);
86 (*hook
)->value
= g_strndup(in
, comma
- in
);
87 in
= comma
+ 1; /* skip the , */
89 (*hook
)->value
= g_strdup(in
);
92 hook
= &(*hook
)->next
;
98 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
102 info
= qmp_query_name(NULL
);
103 if (info
->has_name
) {
104 monitor_printf(mon
, "%s\n", info
->name
);
106 qapi_free_NameInfo(info
);
109 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
113 info
= qmp_query_version(NULL
);
115 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
116 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
119 qapi_free_VersionInfo(info
);
122 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
126 info
= qmp_query_kvm(NULL
);
127 monitor_printf(mon
, "kvm support: ");
129 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
131 monitor_printf(mon
, "not compiled\n");
134 qapi_free_KvmInfo(info
);
137 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
141 info
= qmp_query_status(NULL
);
143 monitor_printf(mon
, "VM status: %s%s",
144 info
->running
? "running" : "paused",
145 info
->singlestep
? " (single step mode)" : "");
147 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
148 monitor_printf(mon
, " (%s)", RunState_str(info
->status
));
151 monitor_printf(mon
, "\n");
153 qapi_free_StatusInfo(info
);
156 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
160 info
= qmp_query_uuid(NULL
);
161 monitor_printf(mon
, "%s\n", info
->UUID
);
162 qapi_free_UuidInfo(info
);
165 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
167 ChardevInfoList
*char_info
, *info
;
169 char_info
= qmp_query_chardev(NULL
);
170 for (info
= char_info
; info
; info
= info
->next
) {
171 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
172 info
->value
->filename
);
175 qapi_free_ChardevInfoList(char_info
);
178 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
180 MouseInfoList
*mice_list
, *mouse
;
182 mice_list
= qmp_query_mice(NULL
);
184 monitor_printf(mon
, "No mouse devices connected\n");
188 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
189 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
190 mouse
->value
->current
? '*' : ' ',
191 mouse
->value
->index
, mouse
->value
->name
,
192 mouse
->value
->absolute
? " (absolute)" : "");
195 qapi_free_MouseInfoList(mice_list
);
198 static char *SocketAddress_to_str(SocketAddress
*addr
)
200 switch (addr
->type
) {
201 case SOCKET_ADDRESS_TYPE_INET
:
202 return g_strdup_printf("tcp:%s:%s",
205 case SOCKET_ADDRESS_TYPE_UNIX
:
206 return g_strdup_printf("unix:%s",
207 addr
->u
.q_unix
.path
);
208 case SOCKET_ADDRESS_TYPE_FD
:
209 return g_strdup_printf("fd:%s", addr
->u
.fd
.str
);
210 case SOCKET_ADDRESS_TYPE_VSOCK
:
211 return g_strdup_printf("tcp:%s:%s",
215 return g_strdup("unknown address type");
219 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
222 MigrationCapabilityStatusList
*caps
, *cap
;
224 info
= qmp_query_migrate(NULL
);
225 caps
= qmp_query_migrate_capabilities(NULL
);
227 migration_global_dump(mon
);
229 /* do not display parameters during setup */
230 if (info
->has_status
&& caps
) {
231 monitor_printf(mon
, "capabilities: ");
232 for (cap
= caps
; cap
; cap
= cap
->next
) {
233 monitor_printf(mon
, "%s: %s ",
234 MigrationCapability_str(cap
->value
->capability
),
235 cap
->value
->state
? "on" : "off");
237 monitor_printf(mon
, "\n");
240 if (info
->has_status
) {
241 monitor_printf(mon
, "Migration status: %s",
242 MigrationStatus_str(info
->status
));
243 if (info
->status
== MIGRATION_STATUS_FAILED
&&
244 info
->has_error_desc
) {
245 monitor_printf(mon
, " (%s)\n", info
->error_desc
);
247 monitor_printf(mon
, "\n");
250 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
252 if (info
->has_expected_downtime
) {
253 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
254 info
->expected_downtime
);
256 if (info
->has_downtime
) {
257 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
260 if (info
->has_setup_time
) {
261 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
267 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
268 info
->ram
->transferred
>> 10);
269 monitor_printf(mon
, "throughput: %0.2f mbps\n",
271 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
272 info
->ram
->remaining
>> 10);
273 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
274 info
->ram
->total
>> 10);
275 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
276 info
->ram
->duplicate
);
277 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
279 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
281 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
282 info
->ram
->normal_bytes
>> 10);
283 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
284 info
->ram
->dirty_sync_count
);
285 monitor_printf(mon
, "page size: %" PRIu64
" kbytes\n",
286 info
->ram
->page_size
>> 10);
287 monitor_printf(mon
, "multifd bytes: %" PRIu64
" kbytes\n",
288 info
->ram
->multifd_bytes
>> 10);
289 monitor_printf(mon
, "pages-per-second: %" PRIu64
"\n",
290 info
->ram
->pages_per_second
);
292 if (info
->ram
->dirty_pages_rate
) {
293 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
294 info
->ram
->dirty_pages_rate
);
296 if (info
->ram
->postcopy_requests
) {
297 monitor_printf(mon
, "postcopy request count: %" PRIu64
"\n",
298 info
->ram
->postcopy_requests
);
302 if (info
->has_disk
) {
303 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
304 info
->disk
->transferred
>> 10);
305 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
306 info
->disk
->remaining
>> 10);
307 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
308 info
->disk
->total
>> 10);
311 if (info
->has_xbzrle_cache
) {
312 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
313 info
->xbzrle_cache
->cache_size
);
314 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
315 info
->xbzrle_cache
->bytes
>> 10);
316 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
317 info
->xbzrle_cache
->pages
);
318 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
319 info
->xbzrle_cache
->cache_miss
);
320 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
321 info
->xbzrle_cache
->cache_miss_rate
);
322 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
323 info
->xbzrle_cache
->overflow
);
326 if (info
->has_compression
) {
327 monitor_printf(mon
, "compression pages: %" PRIu64
" pages\n",
328 info
->compression
->pages
);
329 monitor_printf(mon
, "compression busy: %" PRIu64
"\n",
330 info
->compression
->busy
);
331 monitor_printf(mon
, "compression busy rate: %0.2f\n",
332 info
->compression
->busy_rate
);
333 monitor_printf(mon
, "compressed size: %" PRIu64
"\n",
334 info
->compression
->compressed_size
);
335 monitor_printf(mon
, "compression rate: %0.2f\n",
336 info
->compression
->compression_rate
);
339 if (info
->has_cpu_throttle_percentage
) {
340 monitor_printf(mon
, "cpu throttle percentage: %" PRIu64
"\n",
341 info
->cpu_throttle_percentage
);
344 if (info
->has_postcopy_blocktime
) {
345 monitor_printf(mon
, "postcopy blocktime: %u\n",
346 info
->postcopy_blocktime
);
349 if (info
->has_postcopy_vcpu_blocktime
) {
352 v
= string_output_visitor_new(false, &str
);
353 visit_type_uint32List(v
, NULL
, &info
->postcopy_vcpu_blocktime
, NULL
);
354 visit_complete(v
, &str
);
355 monitor_printf(mon
, "postcopy vcpu blocktime: %s\n", str
);
359 if (info
->has_socket_address
) {
360 SocketAddressList
*addr
;
362 monitor_printf(mon
, "socket address: [\n");
364 for (addr
= info
->socket_address
; addr
; addr
= addr
->next
) {
365 char *s
= SocketAddress_to_str(addr
->value
);
366 monitor_printf(mon
, "\t%s\n", s
);
369 monitor_printf(mon
, "]\n");
371 qapi_free_MigrationInfo(info
);
372 qapi_free_MigrationCapabilityStatusList(caps
);
375 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
377 MigrationCapabilityStatusList
*caps
, *cap
;
379 caps
= qmp_query_migrate_capabilities(NULL
);
382 for (cap
= caps
; cap
; cap
= cap
->next
) {
383 monitor_printf(mon
, "%s: %s\n",
384 MigrationCapability_str(cap
->value
->capability
),
385 cap
->value
->state
? "on" : "off");
389 qapi_free_MigrationCapabilityStatusList(caps
);
392 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
394 MigrationParameters
*params
;
396 params
= qmp_query_migrate_parameters(NULL
);
399 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
400 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL
),
401 params
->announce_initial
);
402 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
403 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX
),
404 params
->announce_max
);
405 monitor_printf(mon
, "%s: %" PRIu64
"\n",
406 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS
),
407 params
->announce_rounds
);
408 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
409 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP
),
410 params
->announce_step
);
411 assert(params
->has_compress_level
);
412 monitor_printf(mon
, "%s: %u\n",
413 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL
),
414 params
->compress_level
);
415 assert(params
->has_compress_threads
);
416 monitor_printf(mon
, "%s: %u\n",
417 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS
),
418 params
->compress_threads
);
419 assert(params
->has_compress_wait_thread
);
420 monitor_printf(mon
, "%s: %s\n",
421 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD
),
422 params
->compress_wait_thread
? "on" : "off");
423 assert(params
->has_decompress_threads
);
424 monitor_printf(mon
, "%s: %u\n",
425 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS
),
426 params
->decompress_threads
);
427 assert(params
->has_cpu_throttle_initial
);
428 monitor_printf(mon
, "%s: %u\n",
429 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
),
430 params
->cpu_throttle_initial
);
431 assert(params
->has_cpu_throttle_increment
);
432 monitor_printf(mon
, "%s: %u\n",
433 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
),
434 params
->cpu_throttle_increment
);
435 assert(params
->has_max_cpu_throttle
);
436 monitor_printf(mon
, "%s: %u\n",
437 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE
),
438 params
->max_cpu_throttle
);
439 assert(params
->has_tls_creds
);
440 monitor_printf(mon
, "%s: '%s'\n",
441 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS
),
443 assert(params
->has_tls_hostname
);
444 monitor_printf(mon
, "%s: '%s'\n",
445 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME
),
446 params
->tls_hostname
);
447 assert(params
->has_max_bandwidth
);
448 monitor_printf(mon
, "%s: %" PRIu64
" bytes/second\n",
449 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH
),
450 params
->max_bandwidth
);
451 assert(params
->has_downtime_limit
);
452 monitor_printf(mon
, "%s: %" PRIu64
" milliseconds\n",
453 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT
),
454 params
->downtime_limit
);
455 assert(params
->has_x_checkpoint_delay
);
456 monitor_printf(mon
, "%s: %u\n",
457 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
),
458 params
->x_checkpoint_delay
);
459 assert(params
->has_block_incremental
);
460 monitor_printf(mon
, "%s: %s\n",
461 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL
),
462 params
->block_incremental
? "on" : "off");
463 monitor_printf(mon
, "%s: %u\n",
464 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS
),
465 params
->multifd_channels
);
466 monitor_printf(mon
, "%s: %" PRIu64
"\n",
467 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
),
468 params
->xbzrle_cache_size
);
469 monitor_printf(mon
, "%s: %" PRIu64
"\n",
470 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH
),
471 params
->max_postcopy_bandwidth
);
472 monitor_printf(mon
, " %s: '%s'\n",
473 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ
),
474 params
->has_tls_authz
? params
->tls_authz
: "");
477 qapi_free_MigrationParameters(params
);
480 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
482 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
483 qmp_query_migrate_cache_size(NULL
) >> 10);
486 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
488 CpuInfoFastList
*cpu_list
, *cpu
;
490 cpu_list
= qmp_query_cpus_fast(NULL
);
492 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
495 if (cpu
->value
->cpu_index
== monitor_get_cpu_index()) {
499 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
,
500 cpu
->value
->cpu_index
);
501 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
504 qapi_free_CpuInfoFastList(cpu_list
);
507 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
508 BlockDeviceInfo
*inserted
, bool verbose
)
510 ImageInfo
*image_info
;
512 assert(!info
|| !info
->has_inserted
|| info
->inserted
== inserted
);
514 if (info
&& *info
->device
) {
515 monitor_printf(mon
, "%s", info
->device
);
516 if (inserted
&& inserted
->has_node_name
) {
517 monitor_printf(mon
, " (%s)", inserted
->node_name
);
520 assert(info
|| inserted
);
521 monitor_printf(mon
, "%s",
522 inserted
&& inserted
->has_node_name
? inserted
->node_name
523 : info
&& info
->has_qdev
? info
->qdev
528 monitor_printf(mon
, ": %s (%s%s%s)\n",
531 inserted
->ro
? ", read-only" : "",
532 inserted
->encrypted
? ", encrypted" : "");
534 monitor_printf(mon
, ": [not inserted]\n");
538 if (info
->has_qdev
) {
539 monitor_printf(mon
, " Attached to: %s\n", info
->qdev
);
541 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
542 monitor_printf(mon
, " I/O status: %s\n",
543 BlockDeviceIoStatus_str(info
->io_status
));
546 if (info
->removable
) {
547 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
548 info
->locked
? "" : "not ",
549 info
->tray_open
? "open" : "closed");
558 monitor_printf(mon
, " Cache mode: %s%s%s\n",
559 inserted
->cache
->writeback
? "writeback" : "writethrough",
560 inserted
->cache
->direct
? ", direct" : "",
561 inserted
->cache
->no_flush
? ", ignore flushes" : "");
563 if (inserted
->has_backing_file
) {
566 "(chain depth: %" PRId64
")\n",
567 inserted
->backing_file
,
568 inserted
->backing_file_depth
);
571 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
572 monitor_printf(mon
, " Detect zeroes: %s\n",
573 BlockdevDetectZeroesOptions_str(inserted
->detect_zeroes
));
576 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
577 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
579 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
580 " bps_rd=%" PRId64
" bps_wr=%" PRId64
582 " bps_rd_max=%" PRId64
583 " bps_wr_max=%" PRId64
584 " iops=%" PRId64
" iops_rd=%" PRId64
587 " iops_rd_max=%" PRId64
588 " iops_wr_max=%" PRId64
589 " iops_size=%" PRId64
595 inserted
->bps_rd_max
,
596 inserted
->bps_wr_max
,
601 inserted
->iops_rd_max
,
602 inserted
->iops_wr_max
,
608 monitor_printf(mon
, "\nImages:\n");
609 image_info
= inserted
->image
;
611 bdrv_image_info_dump(image_info
);
612 if (image_info
->has_backing_image
) {
613 image_info
= image_info
->backing_image
;
621 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
623 BlockInfoList
*block_list
, *info
;
624 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
625 const char *device
= qdict_get_try_str(qdict
, "device");
626 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
627 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
628 bool printed
= false;
630 /* Print BlockBackend information */
632 block_list
= qmp_query_block(NULL
);
637 for (info
= block_list
; info
; info
= info
->next
) {
638 if (device
&& strcmp(device
, info
->value
->device
)) {
642 if (info
!= block_list
) {
643 monitor_printf(mon
, "\n");
646 print_block_info(mon
, info
->value
, info
->value
->has_inserted
647 ? info
->value
->inserted
: NULL
,
652 qapi_free_BlockInfoList(block_list
);
654 if ((!device
&& !nodes
) || printed
) {
658 /* Print node information */
659 blockdev_list
= qmp_query_named_block_nodes(NULL
);
660 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
661 assert(blockdev
->value
->has_node_name
);
662 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
666 if (blockdev
!= blockdev_list
) {
667 monitor_printf(mon
, "\n");
670 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
672 qapi_free_BlockDeviceInfoList(blockdev_list
);
675 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
677 BlockStatsList
*stats_list
, *stats
;
679 stats_list
= qmp_query_blockstats(false, false, NULL
);
681 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
682 if (!stats
->value
->has_device
) {
686 monitor_printf(mon
, "%s:", stats
->value
->device
);
687 monitor_printf(mon
, " rd_bytes=%" PRId64
689 " rd_operations=%" PRId64
690 " wr_operations=%" PRId64
691 " flush_operations=%" PRId64
692 " wr_total_time_ns=%" PRId64
693 " rd_total_time_ns=%" PRId64
694 " flush_total_time_ns=%" PRId64
695 " rd_merged=%" PRId64
696 " wr_merged=%" PRId64
697 " idle_time_ns=%" PRId64
699 stats
->value
->stats
->rd_bytes
,
700 stats
->value
->stats
->wr_bytes
,
701 stats
->value
->stats
->rd_operations
,
702 stats
->value
->stats
->wr_operations
,
703 stats
->value
->stats
->flush_operations
,
704 stats
->value
->stats
->wr_total_time_ns
,
705 stats
->value
->stats
->rd_total_time_ns
,
706 stats
->value
->stats
->flush_total_time_ns
,
707 stats
->value
->stats
->rd_merged
,
708 stats
->value
->stats
->wr_merged
,
709 stats
->value
->stats
->idle_time_ns
);
712 qapi_free_BlockStatsList(stats_list
);
716 /* Helper for hmp_info_vnc_clients, _servers */
717 static void hmp_info_VncBasicInfo(Monitor
*mon
, VncBasicInfo
*info
,
720 monitor_printf(mon
, " %s: %s:%s (%s%s)\n",
724 NetworkAddressFamily_str(info
->family
),
725 info
->websocket
? " (Websocket)" : "");
728 /* Helper displaying and auth and crypt info */
729 static void hmp_info_vnc_authcrypt(Monitor
*mon
, const char *indent
,
731 VncVencryptSubAuth
*vencrypt
)
733 monitor_printf(mon
, "%sAuth: %s (Sub: %s)\n", indent
,
734 VncPrimaryAuth_str(auth
),
735 vencrypt
? VncVencryptSubAuth_str(*vencrypt
) : "none");
738 static void hmp_info_vnc_clients(Monitor
*mon
, VncClientInfoList
*client
)
741 VncClientInfo
*cinfo
= client
->value
;
743 hmp_info_VncBasicInfo(mon
, qapi_VncClientInfo_base(cinfo
), "Client");
744 monitor_printf(mon
, " x509_dname: %s\n",
745 cinfo
->has_x509_dname
?
746 cinfo
->x509_dname
: "none");
747 monitor_printf(mon
, " sasl_username: %s\n",
748 cinfo
->has_sasl_username
?
749 cinfo
->sasl_username
: "none");
751 client
= client
->next
;
755 static void hmp_info_vnc_servers(Monitor
*mon
, VncServerInfo2List
*server
)
758 VncServerInfo2
*sinfo
= server
->value
;
759 hmp_info_VncBasicInfo(mon
, qapi_VncServerInfo2_base(sinfo
), "Server");
760 hmp_info_vnc_authcrypt(mon
, " ", sinfo
->auth
,
761 sinfo
->has_vencrypt
? &sinfo
->vencrypt
: NULL
);
762 server
= server
->next
;
766 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
768 VncInfo2List
*info2l
;
771 info2l
= qmp_query_vnc_servers(&err
);
773 hmp_handle_error(mon
, &err
);
777 monitor_printf(mon
, "None\n");
782 VncInfo2
*info
= info2l
->value
;
783 monitor_printf(mon
, "%s:\n", info
->id
);
784 hmp_info_vnc_servers(mon
, info
->server
);
785 hmp_info_vnc_clients(mon
, info
->clients
);
787 /* The server entry displays its auth, we only
788 * need to display in the case of 'reverse' connections
789 * where there's no server.
791 hmp_info_vnc_authcrypt(mon
, " ", info
->auth
,
792 info
->has_vencrypt
? &info
->vencrypt
: NULL
);
794 if (info
->has_display
) {
795 monitor_printf(mon
, " Display: %s\n", info
->display
);
797 info2l
= info2l
->next
;
800 qapi_free_VncInfo2List(info2l
);
806 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
808 SpiceChannelList
*chan
;
810 const char *channel_name
;
811 const char * const channel_names
[] = {
812 [SPICE_CHANNEL_MAIN
] = "main",
813 [SPICE_CHANNEL_DISPLAY
] = "display",
814 [SPICE_CHANNEL_INPUTS
] = "inputs",
815 [SPICE_CHANNEL_CURSOR
] = "cursor",
816 [SPICE_CHANNEL_PLAYBACK
] = "playback",
817 [SPICE_CHANNEL_RECORD
] = "record",
818 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
819 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
820 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
821 [SPICE_CHANNEL_PORT
] = "port",
823 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
824 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
825 * as quick fix for build failures with older versions. */
826 [SPICE_CHANNEL_WEBDAV
] = "webdav",
830 info
= qmp_query_spice(NULL
);
832 if (!info
->enabled
) {
833 monitor_printf(mon
, "Server: disabled\n");
837 monitor_printf(mon
, "Server:\n");
838 if (info
->has_port
) {
839 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
840 info
->host
, info
->port
);
842 if (info
->has_tls_port
) {
843 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
844 info
->host
, info
->tls_port
);
846 monitor_printf(mon
, " migrated: %s\n",
847 info
->migrated
? "true" : "false");
848 monitor_printf(mon
, " auth: %s\n", info
->auth
);
849 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
850 monitor_printf(mon
, " mouse-mode: %s\n",
851 SpiceQueryMouseMode_str(info
->mouse_mode
));
853 if (!info
->has_channels
|| info
->channels
== NULL
) {
854 monitor_printf(mon
, "Channels: none\n");
856 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
857 monitor_printf(mon
, "Channel:\n");
858 monitor_printf(mon
, " address: %s:%s%s\n",
859 chan
->value
->host
, chan
->value
->port
,
860 chan
->value
->tls
? " [tls]" : "");
861 monitor_printf(mon
, " session: %" PRId64
"\n",
862 chan
->value
->connection_id
);
863 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
864 chan
->value
->channel_type
, chan
->value
->channel_id
);
866 channel_name
= "unknown";
867 if (chan
->value
->channel_type
> 0 &&
868 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
869 channel_names
[chan
->value
->channel_type
]) {
870 channel_name
= channel_names
[chan
->value
->channel_type
];
873 monitor_printf(mon
, " channel name: %s\n", channel_name
);
878 qapi_free_SpiceInfo(info
);
882 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
887 info
= qmp_query_balloon(&err
);
889 hmp_handle_error(mon
, &err
);
893 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
895 qapi_free_BalloonInfo(info
);
898 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
900 PciMemoryRegionList
*region
;
902 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
903 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
904 dev
->slot
, dev
->function
);
905 monitor_printf(mon
, " ");
907 if (dev
->class_info
->has_desc
) {
908 monitor_printf(mon
, "%s", dev
->class_info
->desc
);
910 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
913 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
914 dev
->id
->vendor
, dev
->id
->device
);
915 if (dev
->id
->has_subsystem_vendor
&& dev
->id
->has_subsystem
) {
916 monitor_printf(mon
, " PCI subsystem %04" PRIx64
":%04" PRIx64
"\n",
917 dev
->id
->subsystem_vendor
, dev
->id
->subsystem
);
921 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
924 if (dev
->has_pci_bridge
) {
925 monitor_printf(mon
, " BUS %" PRId64
".\n",
926 dev
->pci_bridge
->bus
->number
);
927 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
928 dev
->pci_bridge
->bus
->secondary
);
929 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
930 dev
->pci_bridge
->bus
->subordinate
);
932 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
933 dev
->pci_bridge
->bus
->io_range
->base
,
934 dev
->pci_bridge
->bus
->io_range
->limit
);
937 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
938 dev
->pci_bridge
->bus
->memory_range
->base
,
939 dev
->pci_bridge
->bus
->memory_range
->limit
);
941 monitor_printf(mon
, " prefetchable memory range "
942 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
943 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
944 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
947 for (region
= dev
->regions
; region
; region
= region
->next
) {
950 addr
= region
->value
->address
;
951 size
= region
->value
->size
;
953 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
955 if (!strcmp(region
->value
->type
, "io")) {
956 monitor_printf(mon
, "I/O at 0x%04" PRIx64
957 " [0x%04" PRIx64
"].\n",
958 addr
, addr
+ size
- 1);
960 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
961 " [0x%08" PRIx64
"].\n",
962 region
->value
->mem_type_64
? 64 : 32,
963 region
->value
->prefetch
? " prefetchable" : "",
964 addr
, addr
+ size
- 1);
968 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
970 if (dev
->has_pci_bridge
) {
971 if (dev
->pci_bridge
->has_devices
) {
972 PciDeviceInfoList
*cdev
;
973 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
974 hmp_info_pci_device(mon
, cdev
->value
);
980 static int hmp_info_irq_foreach(Object
*obj
, void *opaque
)
982 InterruptStatsProvider
*intc
;
983 InterruptStatsProviderClass
*k
;
984 Monitor
*mon
= opaque
;
986 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
987 intc
= INTERRUPT_STATS_PROVIDER(obj
);
988 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
989 uint64_t *irq_counts
;
990 unsigned int nb_irqs
, i
;
991 if (k
->get_statistics
&&
992 k
->get_statistics(intc
, &irq_counts
, &nb_irqs
)) {
994 monitor_printf(mon
, "IRQ statistics for %s:\n",
995 object_get_typename(obj
));
996 for (i
= 0; i
< nb_irqs
; i
++) {
997 if (irq_counts
[i
] > 0) {
998 monitor_printf(mon
, "%2d: %" PRId64
"\n", i
,
1004 monitor_printf(mon
, "IRQ statistics not available for %s.\n",
1005 object_get_typename(obj
));
1012 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
)
1014 object_child_foreach_recursive(object_get_root(),
1015 hmp_info_irq_foreach
, mon
);
1018 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
1020 InterruptStatsProvider
*intc
;
1021 InterruptStatsProviderClass
*k
;
1022 Monitor
*mon
= opaque
;
1024 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
1025 intc
= INTERRUPT_STATS_PROVIDER(obj
);
1026 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
1027 if (k
->print_info
) {
1028 k
->print_info(intc
, mon
);
1030 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
1031 object_get_typename(obj
));
1038 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
1040 object_child_foreach_recursive(object_get_root(),
1041 hmp_info_pic_foreach
, mon
);
1044 static int hmp_info_rdma_foreach(Object
*obj
, void *opaque
)
1047 RdmaProviderClass
*k
;
1048 Monitor
*mon
= opaque
;
1050 if (object_dynamic_cast(obj
, INTERFACE_RDMA_PROVIDER
)) {
1051 rdma
= RDMA_PROVIDER(obj
);
1052 k
= RDMA_PROVIDER_GET_CLASS(obj
);
1053 if (k
->print_statistics
) {
1054 k
->print_statistics(mon
, rdma
);
1056 monitor_printf(mon
, "RDMA statistics not available for %s.\n",
1057 object_get_typename(obj
));
1064 void hmp_info_rdma(Monitor
*mon
, const QDict
*qdict
)
1066 object_child_foreach_recursive(object_get_root(),
1067 hmp_info_rdma_foreach
, mon
);
1070 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
1072 PciInfoList
*info_list
, *info
;
1075 info_list
= qmp_query_pci(&err
);
1077 monitor_printf(mon
, "PCI devices not supported\n");
1082 for (info
= info_list
; info
; info
= info
->next
) {
1083 PciDeviceInfoList
*dev
;
1085 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
1086 hmp_info_pci_device(mon
, dev
->value
);
1090 qapi_free_PciInfoList(info_list
);
1093 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
1095 BlockJobInfoList
*list
;
1098 list
= qmp_query_block_jobs(&err
);
1102 monitor_printf(mon
, "No active jobs\n");
1107 if (strcmp(list
->value
->type
, "stream") == 0) {
1108 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
1109 " of %" PRId64
" bytes, speed limit %" PRId64
1111 list
->value
->device
,
1112 list
->value
->offset
,
1114 list
->value
->speed
);
1116 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
1117 " of %" PRId64
" bytes, speed limit %" PRId64
1120 list
->value
->device
,
1121 list
->value
->offset
,
1123 list
->value
->speed
);
1128 qapi_free_BlockJobInfoList(list
);
1131 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
1133 TPMInfoList
*info_list
, *info
;
1136 TPMPassthroughOptions
*tpo
;
1137 TPMEmulatorOptions
*teo
;
1139 info_list
= qmp_query_tpm(&err
);
1141 monitor_printf(mon
, "TPM device not supported\n");
1147 monitor_printf(mon
, "TPM device:\n");
1150 for (info
= info_list
; info
; info
= info
->next
) {
1151 TPMInfo
*ti
= info
->value
;
1152 monitor_printf(mon
, " tpm%d: model=%s\n",
1153 c
, TpmModel_str(ti
->model
));
1155 monitor_printf(mon
, " \\ %s: type=%s",
1156 ti
->id
, TpmTypeOptionsKind_str(ti
->options
->type
));
1158 switch (ti
->options
->type
) {
1159 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
1160 tpo
= ti
->options
->u
.passthrough
.data
;
1161 monitor_printf(mon
, "%s%s%s%s",
1162 tpo
->has_path
? ",path=" : "",
1163 tpo
->has_path
? tpo
->path
: "",
1164 tpo
->has_cancel_path
? ",cancel-path=" : "",
1165 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
1167 case TPM_TYPE_OPTIONS_KIND_EMULATOR
:
1168 teo
= ti
->options
->u
.emulator
.data
;
1169 monitor_printf(mon
, ",chardev=%s", teo
->chardev
);
1171 case TPM_TYPE_OPTIONS_KIND__MAX
:
1174 monitor_printf(mon
, "\n");
1177 qapi_free_TPMInfoList(info_list
);
1180 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
1182 monitor_suspend(mon
);
1186 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
1191 void hmp_sync_profile(Monitor
*mon
, const QDict
*qdict
)
1193 const char *op
= qdict_get_try_str(qdict
, "op");
1196 bool on
= qsp_is_enabled();
1198 monitor_printf(mon
, "sync-profile is %s\n", on
? "on" : "off");
1201 if (!strcmp(op
, "on")) {
1203 } else if (!strcmp(op
, "off")) {
1205 } else if (!strcmp(op
, "reset")) {
1210 error_setg(&err
, QERR_INVALID_PARAMETER
, op
);
1211 hmp_handle_error(mon
, &err
);
1215 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
1217 qmp_system_reset(NULL
);
1220 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
1222 qmp_system_powerdown(NULL
);
1225 void hmp_exit_preconfig(Monitor
*mon
, const QDict
*qdict
)
1229 qmp_x_exit_preconfig(&err
);
1230 hmp_handle_error(mon
, &err
);
1233 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
1237 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1238 use it are converted to the QAPI */
1239 cpu_index
= qdict_get_int(qdict
, "index");
1240 if (monitor_set_cpu(cpu_index
) < 0) {
1241 monitor_printf(mon
, "invalid CPU index\n");
1245 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
1247 uint32_t size
= qdict_get_int(qdict
, "size");
1248 const char *filename
= qdict_get_str(qdict
, "filename");
1249 uint64_t addr
= qdict_get_int(qdict
, "val");
1251 int cpu_index
= monitor_get_cpu_index();
1253 if (cpu_index
< 0) {
1254 monitor_printf(mon
, "No CPU available\n");
1258 qmp_memsave(addr
, size
, filename
, true, cpu_index
, &err
);
1259 hmp_handle_error(mon
, &err
);
1262 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
1264 uint32_t size
= qdict_get_int(qdict
, "size");
1265 const char *filename
= qdict_get_str(qdict
, "filename");
1266 uint64_t addr
= qdict_get_int(qdict
, "val");
1269 qmp_pmemsave(addr
, size
, filename
, &err
);
1270 hmp_handle_error(mon
, &err
);
1273 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
1275 const char *chardev
= qdict_get_str(qdict
, "device");
1276 const char *data
= qdict_get_str(qdict
, "data");
1279 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
1281 hmp_handle_error(mon
, &err
);
1284 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
1286 uint32_t size
= qdict_get_int(qdict
, "size");
1287 const char *chardev
= qdict_get_str(qdict
, "device");
1292 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
1294 hmp_handle_error(mon
, &err
);
1298 for (i
= 0; data
[i
]; i
++) {
1299 unsigned char ch
= data
[i
];
1302 monitor_printf(mon
, "\\\\");
1303 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
1304 monitor_printf(mon
, "\\u%04X", ch
);
1306 monitor_printf(mon
, "%c", ch
);
1310 monitor_printf(mon
, "\n");
1314 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
1319 hmp_handle_error(mon
, &err
);
1322 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
1326 qmp_system_wakeup(&err
);
1327 hmp_handle_error(mon
, &err
);
1330 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
1334 qmp_inject_nmi(&err
);
1335 hmp_handle_error(mon
, &err
);
1338 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
1340 const char *name
= qdict_get_str(qdict
, "name");
1341 bool up
= qdict_get_bool(qdict
, "up");
1344 qmp_set_link(name
, up
, &err
);
1345 hmp_handle_error(mon
, &err
);
1348 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
1350 const char *device
= qdict_get_str(qdict
, "device");
1351 const char *password
= qdict_get_str(qdict
, "password");
1354 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
1355 hmp_handle_error(mon
, &err
);
1358 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1360 int64_t value
= qdict_get_int(qdict
, "value");
1363 qmp_balloon(value
, &err
);
1364 hmp_handle_error(mon
, &err
);
1367 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
1369 const char *device
= qdict_get_str(qdict
, "device");
1370 int64_t size
= qdict_get_int(qdict
, "size");
1373 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
1374 hmp_handle_error(mon
, &err
);
1377 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
1379 const char *filename
= qdict_get_str(qdict
, "target");
1380 const char *format
= qdict_get_try_str(qdict
, "format");
1381 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1382 bool full
= qdict_get_try_bool(qdict
, "full", false);
1384 DriveMirror mirror
= {
1385 .device
= (char *)qdict_get_str(qdict
, "device"),
1386 .target
= (char *)filename
,
1387 .has_format
= !!format
,
1388 .format
= (char *)format
,
1389 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1391 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1396 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1397 hmp_handle_error(mon
, &err
);
1400 qmp_drive_mirror(&mirror
, &err
);
1401 hmp_handle_error(mon
, &err
);
1404 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
1406 const char *device
= qdict_get_str(qdict
, "device");
1407 const char *filename
= qdict_get_str(qdict
, "target");
1408 const char *format
= qdict_get_try_str(qdict
, "format");
1409 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1410 bool full
= qdict_get_try_bool(qdict
, "full", false);
1411 bool compress
= qdict_get_try_bool(qdict
, "compress", false);
1413 DriveBackup backup
= {
1414 .device
= (char *)device
,
1415 .target
= (char *)filename
,
1416 .has_format
= !!format
,
1417 .format
= (char *)format
,
1418 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1420 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1421 .has_compress
= !!compress
,
1422 .compress
= compress
,
1426 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1427 hmp_handle_error(mon
, &err
);
1431 qmp_drive_backup(&backup
, &err
);
1432 hmp_handle_error(mon
, &err
);
1435 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
1437 const char *device
= qdict_get_str(qdict
, "device");
1438 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
1439 const char *format
= qdict_get_try_str(qdict
, "format");
1440 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1441 enum NewImageMode mode
;
1445 /* In the future, if 'snapshot-file' is not specified, the snapshot
1446 will be taken internally. Today it's actually required. */
1447 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
1448 hmp_handle_error(mon
, &err
);
1452 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1453 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
1454 filename
, false, NULL
,
1457 hmp_handle_error(mon
, &err
);
1460 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1462 const char *device
= qdict_get_str(qdict
, "device");
1463 const char *name
= qdict_get_str(qdict
, "name");
1466 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1467 hmp_handle_error(mon
, &err
);
1470 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1472 const char *device
= qdict_get_str(qdict
, "device");
1473 const char *name
= qdict_get_str(qdict
, "name");
1474 const char *id
= qdict_get_try_str(qdict
, "id");
1477 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1479 hmp_handle_error(mon
, &err
);
1482 void hmp_loadvm(Monitor
*mon
, const QDict
*qdict
)
1484 int saved_vm_running
= runstate_is_running();
1485 const char *name
= qdict_get_str(qdict
, "name");
1488 vm_stop(RUN_STATE_RESTORE_VM
);
1490 if (load_snapshot(name
, &err
) == 0 && saved_vm_running
) {
1493 hmp_handle_error(mon
, &err
);
1496 void hmp_savevm(Monitor
*mon
, const QDict
*qdict
)
1500 save_snapshot(qdict_get_try_str(qdict
, "name"), &err
);
1501 hmp_handle_error(mon
, &err
);
1504 void hmp_delvm(Monitor
*mon
, const QDict
*qdict
)
1506 BlockDriverState
*bs
;
1508 const char *name
= qdict_get_str(qdict
, "name");
1510 if (bdrv_all_delete_snapshot(name
, &bs
, &err
) < 0) {
1512 "deleting snapshot on device '%s': ",
1513 bdrv_get_device_name(bs
));
1515 hmp_handle_error(mon
, &err
);
1518 void hmp_info_snapshots(Monitor
*mon
, const QDict
*qdict
)
1520 BlockDriverState
*bs
, *bs1
;
1521 BdrvNextIterator it1
;
1522 QEMUSnapshotInfo
*sn_tab
, *sn
;
1523 bool no_snapshot
= true;
1526 int *global_snapshots
;
1527 AioContext
*aio_context
;
1529 typedef struct SnapshotEntry
{
1530 QEMUSnapshotInfo sn
;
1531 QTAILQ_ENTRY(SnapshotEntry
) next
;
1534 typedef struct ImageEntry
{
1535 const char *imagename
;
1536 QTAILQ_ENTRY(ImageEntry
) next
;
1537 QTAILQ_HEAD(, SnapshotEntry
) snapshots
;
1540 QTAILQ_HEAD(, ImageEntry
) image_list
=
1541 QTAILQ_HEAD_INITIALIZER(image_list
);
1543 ImageEntry
*image_entry
, *next_ie
;
1544 SnapshotEntry
*snapshot_entry
;
1546 bs
= bdrv_all_find_vmstate_bs();
1548 monitor_printf(mon
, "No available block device supports snapshots\n");
1551 aio_context
= bdrv_get_aio_context(bs
);
1553 aio_context_acquire(aio_context
);
1554 nb_sns
= bdrv_snapshot_list(bs
, &sn_tab
);
1555 aio_context_release(aio_context
);
1558 monitor_printf(mon
, "bdrv_snapshot_list: error %d\n", nb_sns
);
1562 for (bs1
= bdrv_first(&it1
); bs1
; bs1
= bdrv_next(&it1
)) {
1566 AioContext
*ctx
= bdrv_get_aio_context(bs1
);
1568 aio_context_acquire(ctx
);
1569 if (bdrv_can_snapshot(bs1
)) {
1571 bs1_nb_sns
= bdrv_snapshot_list(bs1
, &sn
);
1572 if (bs1_nb_sns
> 0) {
1573 no_snapshot
= false;
1574 ie
= g_new0(ImageEntry
, 1);
1575 ie
->imagename
= bdrv_get_device_name(bs1
);
1576 QTAILQ_INIT(&ie
->snapshots
);
1577 QTAILQ_INSERT_TAIL(&image_list
, ie
, next
);
1578 for (i
= 0; i
< bs1_nb_sns
; i
++) {
1579 se
= g_new0(SnapshotEntry
, 1);
1581 QTAILQ_INSERT_TAIL(&ie
->snapshots
, se
, next
);
1586 aio_context_release(ctx
);
1590 monitor_printf(mon
, "There is no snapshot available.\n");
1594 global_snapshots
= g_new0(int, nb_sns
);
1596 for (i
= 0; i
< nb_sns
; i
++) {
1597 SnapshotEntry
*next_sn
;
1598 if (bdrv_all_find_snapshot(sn_tab
[i
].name
, &bs1
) == 0) {
1599 global_snapshots
[total
] = i
;
1601 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1602 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
,
1604 if (!strcmp(sn_tab
[i
].name
, snapshot_entry
->sn
.name
)) {
1605 QTAILQ_REMOVE(&image_entry
->snapshots
, snapshot_entry
,
1607 g_free(snapshot_entry
);
1614 monitor_printf(mon
, "List of snapshots present on all disks:\n");
1617 bdrv_snapshot_dump(NULL
);
1618 monitor_printf(mon
, "\n");
1619 for (i
= 0; i
< total
; i
++) {
1620 sn
= &sn_tab
[global_snapshots
[i
]];
1621 /* The ID is not guaranteed to be the same on all images, so
1624 pstrcpy(sn
->id_str
, sizeof(sn
->id_str
), "--");
1625 bdrv_snapshot_dump(sn
);
1626 monitor_printf(mon
, "\n");
1629 monitor_printf(mon
, "None\n");
1632 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1633 if (QTAILQ_EMPTY(&image_entry
->snapshots
)) {
1637 "\nList of partial (non-loadable) snapshots on '%s':\n",
1638 image_entry
->imagename
);
1639 bdrv_snapshot_dump(NULL
);
1640 monitor_printf(mon
, "\n");
1641 QTAILQ_FOREACH(snapshot_entry
, &image_entry
->snapshots
, next
) {
1642 bdrv_snapshot_dump(&snapshot_entry
->sn
);
1643 monitor_printf(mon
, "\n");
1647 QTAILQ_FOREACH_SAFE(image_entry
, &image_list
, next
, next_ie
) {
1648 SnapshotEntry
*next_sn
;
1649 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
, next
,
1651 g_free(snapshot_entry
);
1653 g_free(image_entry
);
1656 g_free(global_snapshots
);
1660 void hmp_announce_self(Monitor
*mon
, const QDict
*qdict
)
1662 const char *interfaces_str
= qdict_get_try_str(qdict
, "interfaces");
1663 const char *id
= qdict_get_try_str(qdict
, "id");
1664 AnnounceParameters
*params
= QAPI_CLONE(AnnounceParameters
,
1665 migrate_announce_params());
1667 qapi_free_strList(params
->interfaces
);
1668 params
->interfaces
= strList_from_comma_list(interfaces_str
);
1669 params
->has_interfaces
= params
->interfaces
!= NULL
;
1670 params
->id
= g_strdup(id
);
1671 params
->has_id
= !!params
->id
;
1672 qmp_announce_self(params
, NULL
);
1673 qapi_free_AnnounceParameters(params
);
1676 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1678 qmp_migrate_cancel(NULL
);
1681 void hmp_migrate_continue(Monitor
*mon
, const QDict
*qdict
)
1684 const char *state
= qdict_get_str(qdict
, "state");
1685 int val
= qapi_enum_parse(&MigrationStatus_lookup
, state
, -1, &err
);
1688 qmp_migrate_continue(val
, &err
);
1691 hmp_handle_error(mon
, &err
);
1694 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1697 const char *uri
= qdict_get_str(qdict
, "uri");
1699 qmp_migrate_incoming(uri
, &err
);
1701 hmp_handle_error(mon
, &err
);
1704 void hmp_migrate_recover(Monitor
*mon
, const QDict
*qdict
)
1707 const char *uri
= qdict_get_str(qdict
, "uri");
1709 qmp_migrate_recover(uri
, &err
);
1711 hmp_handle_error(mon
, &err
);
1714 void hmp_migrate_pause(Monitor
*mon
, const QDict
*qdict
)
1718 qmp_migrate_pause(&err
);
1720 hmp_handle_error(mon
, &err
);
1723 /* Kept for backwards compatibility */
1724 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1726 double value
= qdict_get_double(qdict
, "value");
1727 qmp_migrate_set_downtime(value
, NULL
);
1730 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1732 int64_t value
= qdict_get_int(qdict
, "value");
1735 qmp_migrate_set_cache_size(value
, &err
);
1736 hmp_handle_error(mon
, &err
);
1739 /* Kept for backwards compatibility */
1740 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1742 int64_t value
= qdict_get_int(qdict
, "value");
1743 qmp_migrate_set_speed(value
, NULL
);
1746 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1748 const char *cap
= qdict_get_str(qdict
, "capability");
1749 bool state
= qdict_get_bool(qdict
, "state");
1751 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1754 val
= qapi_enum_parse(&MigrationCapability_lookup
, cap
, -1, &err
);
1759 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1760 caps
->value
->capability
= val
;
1761 caps
->value
->state
= state
;
1763 qmp_migrate_set_capabilities(caps
, &err
);
1766 qapi_free_MigrationCapabilityStatusList(caps
);
1767 hmp_handle_error(mon
, &err
);
1770 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1772 const char *param
= qdict_get_str(qdict
, "parameter");
1773 const char *valuestr
= qdict_get_str(qdict
, "value");
1774 Visitor
*v
= string_input_visitor_new(valuestr
);
1775 MigrateSetParameters
*p
= g_new0(MigrateSetParameters
, 1);
1776 uint64_t valuebw
= 0;
1777 uint64_t cache_size
;
1781 val
= qapi_enum_parse(&MigrationParameter_lookup
, param
, -1, &err
);
1787 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1788 p
->has_compress_level
= true;
1789 visit_type_int(v
, param
, &p
->compress_level
, &err
);
1791 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1792 p
->has_compress_threads
= true;
1793 visit_type_int(v
, param
, &p
->compress_threads
, &err
);
1795 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD
:
1796 p
->has_compress_wait_thread
= true;
1797 visit_type_bool(v
, param
, &p
->compress_wait_thread
, &err
);
1799 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1800 p
->has_decompress_threads
= true;
1801 visit_type_int(v
, param
, &p
->decompress_threads
, &err
);
1803 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1804 p
->has_cpu_throttle_initial
= true;
1805 visit_type_int(v
, param
, &p
->cpu_throttle_initial
, &err
);
1807 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1808 p
->has_cpu_throttle_increment
= true;
1809 visit_type_int(v
, param
, &p
->cpu_throttle_increment
, &err
);
1811 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE
:
1812 p
->has_max_cpu_throttle
= true;
1813 visit_type_int(v
, param
, &p
->max_cpu_throttle
, &err
);
1815 case MIGRATION_PARAMETER_TLS_CREDS
:
1816 p
->has_tls_creds
= true;
1817 p
->tls_creds
= g_new0(StrOrNull
, 1);
1818 p
->tls_creds
->type
= QTYPE_QSTRING
;
1819 visit_type_str(v
, param
, &p
->tls_creds
->u
.s
, &err
);
1821 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1822 p
->has_tls_hostname
= true;
1823 p
->tls_hostname
= g_new0(StrOrNull
, 1);
1824 p
->tls_hostname
->type
= QTYPE_QSTRING
;
1825 visit_type_str(v
, param
, &p
->tls_hostname
->u
.s
, &err
);
1827 case MIGRATION_PARAMETER_TLS_AUTHZ
:
1828 p
->has_tls_authz
= true;
1829 p
->tls_authz
= g_new0(StrOrNull
, 1);
1830 p
->tls_authz
->type
= QTYPE_QSTRING
;
1831 visit_type_str(v
, param
, &p
->tls_authz
->u
.s
, &err
);
1833 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1834 p
->has_max_bandwidth
= true;
1836 * Can't use visit_type_size() here, because it
1837 * defaults to Bytes rather than Mebibytes.
1839 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
1840 if (ret
< 0 || valuebw
> INT64_MAX
1841 || (size_t)valuebw
!= valuebw
) {
1842 error_setg(&err
, "Invalid size %s", valuestr
);
1845 p
->max_bandwidth
= valuebw
;
1847 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1848 p
->has_downtime_limit
= true;
1849 visit_type_int(v
, param
, &p
->downtime_limit
, &err
);
1851 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
1852 p
->has_x_checkpoint_delay
= true;
1853 visit_type_int(v
, param
, &p
->x_checkpoint_delay
, &err
);
1855 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL
:
1856 p
->has_block_incremental
= true;
1857 visit_type_bool(v
, param
, &p
->block_incremental
, &err
);
1859 case MIGRATION_PARAMETER_MULTIFD_CHANNELS
:
1860 p
->has_multifd_channels
= true;
1861 visit_type_int(v
, param
, &p
->multifd_channels
, &err
);
1863 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
:
1864 p
->has_xbzrle_cache_size
= true;
1865 visit_type_size(v
, param
, &cache_size
, &err
);
1869 if (cache_size
> INT64_MAX
|| (size_t)cache_size
!= cache_size
) {
1870 error_setg(&err
, "Invalid size %s", valuestr
);
1873 p
->xbzrle_cache_size
= cache_size
;
1875 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH
:
1876 p
->has_max_postcopy_bandwidth
= true;
1877 visit_type_size(v
, param
, &p
->max_postcopy_bandwidth
, &err
);
1879 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL
:
1880 p
->has_announce_initial
= true;
1881 visit_type_size(v
, param
, &p
->announce_initial
, &err
);
1883 case MIGRATION_PARAMETER_ANNOUNCE_MAX
:
1884 p
->has_announce_max
= true;
1885 visit_type_size(v
, param
, &p
->announce_max
, &err
);
1887 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS
:
1888 p
->has_announce_rounds
= true;
1889 visit_type_size(v
, param
, &p
->announce_rounds
, &err
);
1891 case MIGRATION_PARAMETER_ANNOUNCE_STEP
:
1892 p
->has_announce_step
= true;
1893 visit_type_size(v
, param
, &p
->announce_step
, &err
);
1903 qmp_migrate_set_parameters(p
, &err
);
1906 qapi_free_MigrateSetParameters(p
);
1908 hmp_handle_error(mon
, &err
);
1911 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1914 const char *protocol
= qdict_get_str(qdict
, "protocol");
1915 const char *hostname
= qdict_get_str(qdict
, "hostname");
1916 bool has_port
= qdict_haskey(qdict
, "port");
1917 int port
= qdict_get_try_int(qdict
, "port", -1);
1918 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1919 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1920 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1922 qmp_client_migrate_info(protocol
, hostname
,
1923 has_port
, port
, has_tls_port
, tls_port
,
1924 !!cert_subject
, cert_subject
, &err
);
1925 hmp_handle_error(mon
, &err
);
1928 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1931 qmp_migrate_start_postcopy(&err
);
1932 hmp_handle_error(mon
, &err
);
1935 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1939 qmp_x_colo_lost_heartbeat(&err
);
1940 hmp_handle_error(mon
, &err
);
1943 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1945 const char *protocol
= qdict_get_str(qdict
, "protocol");
1946 const char *password
= qdict_get_str(qdict
, "password");
1947 const char *connected
= qdict_get_try_str(qdict
, "connected");
1950 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1951 hmp_handle_error(mon
, &err
);
1954 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1956 const char *protocol
= qdict_get_str(qdict
, "protocol");
1957 const char *whenstr
= qdict_get_str(qdict
, "time");
1960 qmp_expire_password(protocol
, whenstr
, &err
);
1961 hmp_handle_error(mon
, &err
);
1964 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1966 bool force
= qdict_get_try_bool(qdict
, "force", false);
1967 const char *device
= qdict_get_str(qdict
, "device");
1970 qmp_eject(true, device
, false, NULL
, true, force
, &err
);
1971 hmp_handle_error(mon
, &err
);
1975 static void hmp_change_read_arg(void *opaque
, const char *password
,
1976 void *readline_opaque
)
1978 qmp_change_vnc_password(password
, NULL
);
1979 monitor_read_command(opaque
, 1);
1983 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1985 MonitorHMP
*hmp_mon
= container_of(mon
, MonitorHMP
, common
);
1986 const char *device
= qdict_get_str(qdict
, "device");
1987 const char *target
= qdict_get_str(qdict
, "target");
1988 const char *arg
= qdict_get_try_str(qdict
, "arg");
1989 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1990 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1994 if (strcmp(device
, "vnc") == 0) {
1997 "Parameter 'read-only-mode' is invalid for VNC\n");
2000 if (strcmp(target
, "passwd") == 0 ||
2001 strcmp(target
, "password") == 0) {
2003 monitor_read_password(hmp_mon
, hmp_change_read_arg
, NULL
);
2007 qmp_change("vnc", target
, !!arg
, arg
, &err
);
2013 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup
,
2015 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
2017 hmp_handle_error(mon
, &err
);
2022 qmp_blockdev_change_medium(true, device
, false, NULL
, target
,
2023 !!arg
, arg
, !!read_only
, read_only_mode
,
2027 hmp_handle_error(mon
, &err
);
2030 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
2033 char *device
= (char *) qdict_get_str(qdict
, "device");
2034 BlockIOThrottle throttle
= {
2035 .bps
= qdict_get_int(qdict
, "bps"),
2036 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
2037 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
2038 .iops
= qdict_get_int(qdict
, "iops"),
2039 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
2040 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
2043 /* qmp_block_set_io_throttle has separate parameters for the
2044 * (deprecated) block device name and the qdev ID but the HMP
2045 * version has only one, so we must decide which one to pass. */
2046 if (blk_by_name(device
)) {
2047 throttle
.has_device
= true;
2048 throttle
.device
= device
;
2050 throttle
.has_id
= true;
2051 throttle
.id
= device
;
2054 qmp_block_set_io_throttle(&throttle
, &err
);
2055 hmp_handle_error(mon
, &err
);
2058 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
2060 Error
*error
= NULL
;
2061 const char *device
= qdict_get_str(qdict
, "device");
2062 const char *base
= qdict_get_try_str(qdict
, "base");
2063 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
2065 qmp_block_stream(true, device
, device
, base
!= NULL
, base
, false, NULL
,
2066 false, NULL
, qdict_haskey(qdict
, "speed"), speed
, true,
2067 BLOCKDEV_ON_ERROR_REPORT
, false, false, false, false,
2070 hmp_handle_error(mon
, &error
);
2073 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
2075 Error
*error
= NULL
;
2076 const char *device
= qdict_get_str(qdict
, "device");
2077 int64_t value
= qdict_get_int(qdict
, "speed");
2079 qmp_block_job_set_speed(device
, value
, &error
);
2081 hmp_handle_error(mon
, &error
);
2084 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
2086 Error
*error
= NULL
;
2087 const char *device
= qdict_get_str(qdict
, "device");
2088 bool force
= qdict_get_try_bool(qdict
, "force", false);
2090 qmp_block_job_cancel(device
, true, force
, &error
);
2092 hmp_handle_error(mon
, &error
);
2095 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
2097 Error
*error
= NULL
;
2098 const char *device
= qdict_get_str(qdict
, "device");
2100 qmp_block_job_pause(device
, &error
);
2102 hmp_handle_error(mon
, &error
);
2105 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
2107 Error
*error
= NULL
;
2108 const char *device
= qdict_get_str(qdict
, "device");
2110 qmp_block_job_resume(device
, &error
);
2112 hmp_handle_error(mon
, &error
);
2115 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
2117 Error
*error
= NULL
;
2118 const char *device
= qdict_get_str(qdict
, "device");
2120 qmp_block_job_complete(device
, &error
);
2122 hmp_handle_error(mon
, &error
);
2125 typedef struct HMPMigrationStatus
2129 bool is_block_migration
;
2130 } HMPMigrationStatus
;
2132 static void hmp_migrate_status_cb(void *opaque
)
2134 HMPMigrationStatus
*status
= opaque
;
2135 MigrationInfo
*info
;
2137 info
= qmp_query_migrate(NULL
);
2138 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
2139 info
->status
== MIGRATION_STATUS_SETUP
) {
2140 if (info
->has_disk
) {
2143 if (info
->disk
->remaining
) {
2144 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
2149 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
2150 monitor_flush(status
->mon
);
2153 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
2155 if (status
->is_block_migration
) {
2156 monitor_printf(status
->mon
, "\n");
2158 if (info
->has_error_desc
) {
2159 error_report("%s", info
->error_desc
);
2161 monitor_resume(status
->mon
);
2162 timer_del(status
->timer
);
2163 timer_free(status
->timer
);
2167 qapi_free_MigrationInfo(info
);
2170 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
2172 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
2173 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
2174 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
2175 bool resume
= qdict_get_try_bool(qdict
, "resume", false);
2176 const char *uri
= qdict_get_str(qdict
, "uri");
2179 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
,
2180 false, false, true, resume
, &err
);
2182 hmp_handle_error(mon
, &err
);
2187 HMPMigrationStatus
*status
;
2189 if (monitor_suspend(mon
) < 0) {
2190 monitor_printf(mon
, "terminal does not allow synchronous "
2191 "migration, continuing detached\n");
2195 status
= g_malloc0(sizeof(*status
));
2197 status
->is_block_migration
= blk
|| inc
;
2198 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
2200 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
2204 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
2208 qmp_device_add((QDict
*)qdict
, NULL
, &err
);
2209 hmp_handle_error(mon
, &err
);
2212 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
2214 const char *id
= qdict_get_str(qdict
, "id");
2217 qmp_device_del(id
, &err
);
2218 hmp_handle_error(mon
, &err
);
2221 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
2224 bool win_dmp
= qdict_get_try_bool(qdict
, "windmp", false);
2225 bool paging
= qdict_get_try_bool(qdict
, "paging", false);
2226 bool zlib
= qdict_get_try_bool(qdict
, "zlib", false);
2227 bool lzo
= qdict_get_try_bool(qdict
, "lzo", false);
2228 bool snappy
= qdict_get_try_bool(qdict
, "snappy", false);
2229 const char *file
= qdict_get_str(qdict
, "filename");
2230 bool has_begin
= qdict_haskey(qdict
, "begin");
2231 bool has_length
= qdict_haskey(qdict
, "length");
2232 bool has_detach
= qdict_haskey(qdict
, "detach");
2235 bool detach
= false;
2236 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
2239 if (zlib
+ lzo
+ snappy
+ win_dmp
> 1) {
2240 error_setg(&err
, "only one of '-z|-l|-s|-w' can be set");
2241 hmp_handle_error(mon
, &err
);
2246 dump_format
= DUMP_GUEST_MEMORY_FORMAT_WIN_DMP
;
2250 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
2254 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
2258 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
2262 begin
= qdict_get_int(qdict
, "begin");
2265 length
= qdict_get_int(qdict
, "length");
2268 detach
= qdict_get_bool(qdict
, "detach");
2271 prot
= g_strconcat("file:", file
, NULL
);
2273 qmp_dump_guest_memory(paging
, prot
, true, detach
, has_begin
, begin
,
2274 has_length
, length
, true, dump_format
, &err
);
2275 hmp_handle_error(mon
, &err
);
2279 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
2284 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
2289 netdev_add(opts
, &err
);
2291 qemu_opts_del(opts
);
2295 hmp_handle_error(mon
, &err
);
2298 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
2300 const char *id
= qdict_get_str(qdict
, "id");
2303 qmp_netdev_del(id
, &err
);
2304 hmp_handle_error(mon
, &err
);
2307 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
2313 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
2315 hmp_handle_error(mon
, &err
);
2319 obj
= user_creatable_add_opts(opts
, &err
);
2320 qemu_opts_del(opts
);
2323 hmp_handle_error(mon
, &err
);
2330 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
2332 const char *fdname
= qdict_get_str(qdict
, "fdname");
2335 qmp_getfd(fdname
, &err
);
2336 hmp_handle_error(mon
, &err
);
2339 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
2341 const char *fdname
= qdict_get_str(qdict
, "fdname");
2344 qmp_closefd(fdname
, &err
);
2345 hmp_handle_error(mon
, &err
);
2348 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
2350 const char *keys
= qdict_get_str(qdict
, "keys");
2351 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
2352 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
2353 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
2355 const char *separator
;
2359 separator
= qemu_strchrnul(keys
, '-');
2360 keyname_len
= separator
- keys
;
2362 /* Be compatible with old interface, convert user inputted "<" */
2363 if (keys
[0] == '<' && keyname_len
== 1) {
2368 keylist
= g_malloc0(sizeof(*keylist
));
2369 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
2375 tmp
->next
= keylist
;
2379 if (strstart(keys
, "0x", NULL
)) {
2381 int value
= strtoul(keys
, &endp
, 0);
2382 assert(endp
<= keys
+ keyname_len
);
2383 if (endp
!= keys
+ keyname_len
) {
2386 keylist
->value
->type
= KEY_VALUE_KIND_NUMBER
;
2387 keylist
->value
->u
.number
.data
= value
;
2389 int idx
= index_from_key(keys
, keyname_len
);
2390 if (idx
== Q_KEY_CODE__MAX
) {
2393 keylist
->value
->type
= KEY_VALUE_KIND_QCODE
;
2394 keylist
->value
->u
.qcode
.data
= idx
;
2400 keys
= separator
+ 1;
2403 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
2404 hmp_handle_error(mon
, &err
);
2407 qapi_free_KeyValueList(head
);
2411 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
2415 void hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
2417 const char *filename
= qdict_get_str(qdict
, "filename");
2418 const char *id
= qdict_get_try_str(qdict
, "device");
2419 int64_t head
= qdict_get_try_int(qdict
, "head", 0);
2422 qmp_screendump(filename
, id
!= NULL
, id
, id
!= NULL
, head
, &err
);
2423 hmp_handle_error(mon
, &err
);
2426 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
2428 const char *uri
= qdict_get_str(qdict
, "uri");
2429 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2430 bool all
= qdict_get_try_bool(qdict
, "all", false);
2431 Error
*local_err
= NULL
;
2432 BlockInfoList
*block_list
, *info
;
2433 SocketAddress
*addr
;
2435 if (writable
&& !all
) {
2436 error_setg(&local_err
, "-w only valid together with -a");
2440 /* First check if the address is valid and start the server. */
2441 addr
= socket_parse(uri
, &local_err
);
2442 if (local_err
!= NULL
) {
2446 nbd_server_start(addr
, NULL
, NULL
, &local_err
);
2447 qapi_free_SocketAddress(addr
);
2448 if (local_err
!= NULL
) {
2456 /* Then try adding all block devices. If one fails, close all and
2459 block_list
= qmp_query_block(NULL
);
2461 for (info
= block_list
; info
; info
= info
->next
) {
2462 if (!info
->value
->has_inserted
) {
2466 qmp_nbd_server_add(info
->value
->device
, false, NULL
,
2467 true, writable
, false, NULL
, &local_err
);
2469 if (local_err
!= NULL
) {
2470 qmp_nbd_server_stop(NULL
);
2475 qapi_free_BlockInfoList(block_list
);
2478 hmp_handle_error(mon
, &local_err
);
2481 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
2483 const char *device
= qdict_get_str(qdict
, "device");
2484 const char *name
= qdict_get_try_str(qdict
, "name");
2485 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2486 Error
*local_err
= NULL
;
2488 qmp_nbd_server_add(device
, !!name
, name
, true, writable
,
2489 false, NULL
, &local_err
);
2490 hmp_handle_error(mon
, &local_err
);
2493 void hmp_nbd_server_remove(Monitor
*mon
, const QDict
*qdict
)
2495 const char *name
= qdict_get_str(qdict
, "name");
2496 bool force
= qdict_get_try_bool(qdict
, "force", false);
2499 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
2500 qmp_nbd_server_remove(name
, force
, NBD_SERVER_REMOVE_MODE_HARD
, &err
);
2501 hmp_handle_error(mon
, &err
);
2504 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
2508 qmp_nbd_server_stop(&err
);
2509 hmp_handle_error(mon
, &err
);
2512 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
2517 error_report("cpu_add is deprecated, please use device_add instead");
2519 cpuid
= qdict_get_int(qdict
, "id");
2520 qmp_cpu_add(cpuid
, &err
);
2521 hmp_handle_error(mon
, &err
);
2524 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
2526 const char *args
= qdict_get_str(qdict
, "args");
2530 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
2532 error_setg(&err
, "Parsing chardev args failed");
2534 qemu_chr_new_from_opts(opts
, NULL
, &err
);
2535 qemu_opts_del(opts
);
2537 hmp_handle_error(mon
, &err
);
2540 void hmp_chardev_change(Monitor
*mon
, const QDict
*qdict
)
2542 const char *args
= qdict_get_str(qdict
, "args");
2545 ChardevBackend
*backend
= NULL
;
2546 ChardevReturn
*ret
= NULL
;
2547 QemuOpts
*opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
,
2550 error_setg(&err
, "Parsing chardev args failed");
2554 id
= qdict_get_str(qdict
, "id");
2555 if (qemu_opts_id(opts
)) {
2556 error_setg(&err
, "Unexpected 'id' parameter");
2560 backend
= qemu_chr_parse_opts(opts
, &err
);
2565 ret
= qmp_chardev_change(id
, backend
, &err
);
2568 qapi_free_ChardevReturn(ret
);
2569 qapi_free_ChardevBackend(backend
);
2570 qemu_opts_del(opts
);
2571 hmp_handle_error(mon
, &err
);
2574 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
2576 Error
*local_err
= NULL
;
2578 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
2579 hmp_handle_error(mon
, &local_err
);
2582 void hmp_chardev_send_break(Monitor
*mon
, const QDict
*qdict
)
2584 Error
*local_err
= NULL
;
2586 qmp_chardev_send_break(qdict_get_str(qdict
, "id"), &local_err
);
2587 hmp_handle_error(mon
, &local_err
);
2590 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
2593 BlockBackend
*local_blk
= NULL
;
2594 const char* device
= qdict_get_str(qdict
, "device");
2595 const char* command
= qdict_get_str(qdict
, "command");
2599 blk
= blk_by_name(device
);
2601 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, device
, &err
);
2603 blk
= local_blk
= blk_new(bdrv_get_aio_context(bs
),
2605 ret
= blk_insert_bs(blk
, bs
, &err
);
2615 * Notably absent: Proper permission management. This is sad, but it seems
2616 * almost impossible to achieve without changing the semantics and thereby
2617 * limiting the use cases of the qemu-io HMP command.
2619 * In an ideal world we would unconditionally create a new BlockBackend for
2620 * qemuio_command(), but we have commands like 'reopen' and want them to
2621 * take effect on the exact BlockBackend whose name the user passed instead
2622 * of just on a temporary copy of it.
2624 * Another problem is that deleting the temporary BlockBackend involves
2625 * draining all requests on it first, but some qemu-iotests cases want to
2626 * issue multiple aio_read/write requests and expect them to complete in
2627 * the background while the monitor has already returned.
2629 * This is also what prevents us from saving the original permissions and
2630 * restoring them later: We can't revoke permissions until all requests
2631 * have completed, and we don't know when that is nor can we really let
2632 * anything else run before we have revoken them to avoid race conditions.
2634 * What happens now is that command() in qemu-io-cmds.c can extend the
2635 * permissions if necessary for the qemu-io command. And they simply stay
2636 * extended, possibly resulting in a read-only guest device keeping write
2637 * permissions. Ugly, but it appears to be the lesser evil.
2639 qemuio_command(blk
, command
);
2642 blk_unref(local_blk
);
2643 hmp_handle_error(mon
, &err
);
2646 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
2648 const char *id
= qdict_get_str(qdict
, "id");
2651 user_creatable_del(id
, &err
);
2652 hmp_handle_error(mon
, &err
);
2655 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
2658 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
2659 MemdevList
*m
= memdev_list
;
2664 v
= string_output_visitor_new(false, &str
);
2665 visit_type_uint16List(v
, NULL
, &m
->value
->host_nodes
, NULL
);
2666 monitor_printf(mon
, "memory backend: %s\n", m
->value
->id
);
2667 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
2668 monitor_printf(mon
, " merge: %s\n",
2669 m
->value
->merge
? "true" : "false");
2670 monitor_printf(mon
, " dump: %s\n",
2671 m
->value
->dump
? "true" : "false");
2672 monitor_printf(mon
, " prealloc: %s\n",
2673 m
->value
->prealloc
? "true" : "false");
2674 monitor_printf(mon
, " policy: %s\n",
2675 HostMemPolicy_str(m
->value
->policy
));
2676 visit_complete(v
, &str
);
2677 monitor_printf(mon
, " host nodes: %s\n", str
);
2684 monitor_printf(mon
, "\n");
2686 qapi_free_MemdevList(memdev_list
);
2687 hmp_handle_error(mon
, &err
);
2690 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
2693 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
2694 MemoryDeviceInfoList
*info
;
2695 MemoryDeviceInfo
*value
;
2696 PCDIMMDeviceInfo
*di
;
2698 for (info
= info_list
; info
; info
= info
->next
) {
2699 value
= info
->value
;
2702 switch (value
->type
) {
2703 case MEMORY_DEVICE_INFO_KIND_DIMM
:
2704 di
= value
->u
.dimm
.data
;
2707 case MEMORY_DEVICE_INFO_KIND_NVDIMM
:
2708 di
= value
->u
.nvdimm
.data
;
2717 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
2718 MemoryDeviceInfoKind_str(value
->type
),
2719 di
->id
? di
->id
: "");
2720 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
2721 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
2722 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
2723 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
2724 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
2725 monitor_printf(mon
, " hotplugged: %s\n",
2726 di
->hotplugged
? "true" : "false");
2727 monitor_printf(mon
, " hotpluggable: %s\n",
2728 di
->hotpluggable
? "true" : "false");
2733 qapi_free_MemoryDeviceInfoList(info_list
);
2734 hmp_handle_error(mon
, &err
);
2737 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
2739 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
2740 IOThreadInfoList
*info
;
2741 IOThreadInfo
*value
;
2743 for (info
= info_list
; info
; info
= info
->next
) {
2744 value
= info
->value
;
2745 monitor_printf(mon
, "%s:\n", value
->id
);
2746 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
2747 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
2748 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
2749 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
2752 qapi_free_IOThreadInfoList(info_list
);
2755 void hmp_qom_list(Monitor
*mon
, const QDict
*qdict
)
2757 const char *path
= qdict_get_try_str(qdict
, "path");
2758 ObjectPropertyInfoList
*list
;
2762 monitor_printf(mon
, "/\n");
2766 list
= qmp_qom_list(path
, &err
);
2768 ObjectPropertyInfoList
*start
= list
;
2769 while (list
!= NULL
) {
2770 ObjectPropertyInfo
*value
= list
->value
;
2772 monitor_printf(mon
, "%s (%s)\n",
2773 value
->name
, value
->type
);
2776 qapi_free_ObjectPropertyInfoList(start
);
2778 hmp_handle_error(mon
, &err
);
2781 void hmp_qom_set(Monitor
*mon
, const QDict
*qdict
)
2783 const char *path
= qdict_get_str(qdict
, "path");
2784 const char *property
= qdict_get_str(qdict
, "property");
2785 const char *value
= qdict_get_str(qdict
, "value");
2787 bool ambiguous
= false;
2790 obj
= object_resolve_path(path
, &ambiguous
);
2792 error_set(&err
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2793 "Device '%s' not found", path
);
2796 monitor_printf(mon
, "Warning: Path '%s' is ambiguous\n", path
);
2798 object_property_parse(obj
, value
, property
, &err
);
2800 hmp_handle_error(mon
, &err
);
2803 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
2805 const char *name
= qdict_get_str(qdict
, "name");
2806 RockerSwitch
*rocker
;
2809 rocker
= qmp_query_rocker(name
, &err
);
2811 hmp_handle_error(mon
, &err
);
2815 monitor_printf(mon
, "name: %s\n", rocker
->name
);
2816 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
2817 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
2819 qapi_free_RockerSwitch(rocker
);
2822 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
2824 RockerPortList
*list
, *port
;
2825 const char *name
= qdict_get_str(qdict
, "name");
2828 list
= qmp_query_rocker_ports(name
, &err
);
2830 hmp_handle_error(mon
, &err
);
2834 monitor_printf(mon
, " ena/ speed/ auto\n");
2835 monitor_printf(mon
, " port link duplex neg?\n");
2837 for (port
= list
; port
; port
= port
->next
) {
2838 monitor_printf(mon
, "%10s %-4s %-3s %2s %-3s\n",
2840 port
->value
->enabled
? port
->value
->link_up
?
2841 "up" : "down" : "!ena",
2842 port
->value
->speed
== 10000 ? "10G" : "??",
2843 port
->value
->duplex
? "FD" : "HD",
2844 port
->value
->autoneg
? "Yes" : "No");
2847 qapi_free_RockerPortList(list
);
2850 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
2852 RockerOfDpaFlowList
*list
, *info
;
2853 const char *name
= qdict_get_str(qdict
, "name");
2854 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
2857 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
2859 hmp_handle_error(mon
, &err
);
2863 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
2865 for (info
= list
; info
; info
= info
->next
) {
2866 RockerOfDpaFlow
*flow
= info
->value
;
2867 RockerOfDpaFlowKey
*key
= flow
->key
;
2868 RockerOfDpaFlowMask
*mask
= flow
->mask
;
2869 RockerOfDpaFlowAction
*action
= flow
->action
;
2872 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
2873 key
->priority
, key
->tbl_id
, flow
->hits
);
2875 monitor_printf(mon
, "%-4d %-3d ",
2876 key
->priority
, key
->tbl_id
);
2879 if (key
->has_in_pport
) {
2880 monitor_printf(mon
, " pport %d", key
->in_pport
);
2881 if (mask
->has_in_pport
) {
2882 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2886 if (key
->has_vlan_id
) {
2887 monitor_printf(mon
, " vlan %d",
2888 key
->vlan_id
& VLAN_VID_MASK
);
2889 if (mask
->has_vlan_id
) {
2890 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2894 if (key
->has_tunnel_id
) {
2895 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2896 if (mask
->has_tunnel_id
) {
2897 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2901 if (key
->has_eth_type
) {
2902 switch (key
->eth_type
) {
2904 monitor_printf(mon
, " ARP");
2907 monitor_printf(mon
, " IP");
2910 monitor_printf(mon
, " IPv6");
2913 monitor_printf(mon
, " LACP");
2916 monitor_printf(mon
, " LLDP");
2919 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2924 if (key
->has_eth_src
) {
2925 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2926 (mask
->has_eth_src
) &&
2927 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2928 monitor_printf(mon
, " src <any mcast/bcast>");
2929 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2930 (mask
->has_eth_src
) &&
2931 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2932 monitor_printf(mon
, " src <any ucast>");
2934 monitor_printf(mon
, " src %s", key
->eth_src
);
2935 if (mask
->has_eth_src
) {
2936 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2941 if (key
->has_eth_dst
) {
2942 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2943 (mask
->has_eth_dst
) &&
2944 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2945 monitor_printf(mon
, " dst <any mcast/bcast>");
2946 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2947 (mask
->has_eth_dst
) &&
2948 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2949 monitor_printf(mon
, " dst <any ucast>");
2951 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2952 if (mask
->has_eth_dst
) {
2953 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2958 if (key
->has_ip_proto
) {
2959 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2960 if (mask
->has_ip_proto
) {
2961 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2965 if (key
->has_ip_tos
) {
2966 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2967 if (mask
->has_ip_tos
) {
2968 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2972 if (key
->has_ip_dst
) {
2973 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2976 if (action
->has_goto_tbl
|| action
->has_group_id
||
2977 action
->has_new_vlan_id
) {
2978 monitor_printf(mon
, " -->");
2981 if (action
->has_new_vlan_id
) {
2982 monitor_printf(mon
, " apply new vlan %d",
2983 ntohs(action
->new_vlan_id
));
2986 if (action
->has_group_id
) {
2987 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2990 if (action
->has_goto_tbl
) {
2991 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2994 monitor_printf(mon
, "\n");
2997 qapi_free_RockerOfDpaFlowList(list
);
3000 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
3002 RockerOfDpaGroupList
*list
, *g
;
3003 const char *name
= qdict_get_str(qdict
, "name");
3004 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
3008 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
3010 hmp_handle_error(mon
, &err
);
3014 monitor_printf(mon
, "id (decode) --> buckets\n");
3016 for (g
= list
; g
; g
= g
->next
) {
3017 RockerOfDpaGroup
*group
= g
->value
;
3019 monitor_printf(mon
, "0x%08x", group
->id
);
3021 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
3022 group
->type
== 1 ? "L2 rewrite" :
3023 group
->type
== 2 ? "L3 unicast" :
3024 group
->type
== 3 ? "L2 multicast" :
3025 group
->type
== 4 ? "L2 flood" :
3026 group
->type
== 5 ? "L3 interface" :
3027 group
->type
== 6 ? "L3 multicast" :
3028 group
->type
== 7 ? "L3 ECMP" :
3029 group
->type
== 8 ? "L2 overlay" :
3032 if (group
->has_vlan_id
) {
3033 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
3036 if (group
->has_pport
) {
3037 monitor_printf(mon
, " pport %d", group
->pport
);
3040 if (group
->has_index
) {
3041 monitor_printf(mon
, " index %d", group
->index
);
3044 monitor_printf(mon
, ") -->");
3046 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
3048 monitor_printf(mon
, " set vlan %d",
3049 group
->set_vlan_id
& VLAN_VID_MASK
);
3052 if (group
->has_set_eth_src
) {
3055 monitor_printf(mon
, " set");
3057 monitor_printf(mon
, " src %s", group
->set_eth_src
);
3060 if (group
->has_set_eth_dst
) {
3063 monitor_printf(mon
, " set");
3065 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
3070 if (group
->has_ttl_check
&& group
->ttl_check
) {
3071 monitor_printf(mon
, " check TTL");
3074 if (group
->has_group_id
&& group
->group_id
) {
3075 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
3078 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
3079 monitor_printf(mon
, " pop vlan");
3082 if (group
->has_out_pport
) {
3083 monitor_printf(mon
, " out pport %d", group
->out_pport
);
3086 if (group
->has_group_ids
) {
3087 struct uint32List
*id
;
3089 monitor_printf(mon
, " groups [");
3090 for (id
= group
->group_ids
; id
; id
= id
->next
) {
3091 monitor_printf(mon
, "0x%08x", id
->value
);
3093 monitor_printf(mon
, ",");
3096 monitor_printf(mon
, "]");
3099 monitor_printf(mon
, "\n");
3102 qapi_free_RockerOfDpaGroupList(list
);
3105 void hmp_info_dump(Monitor
*mon
, const QDict
*qdict
)
3107 DumpQueryResult
*result
= qmp_query_dump(NULL
);
3109 assert(result
&& result
->status
< DUMP_STATUS__MAX
);
3110 monitor_printf(mon
, "Status: %s\n", DumpStatus_str(result
->status
));
3112 if (result
->status
== DUMP_STATUS_ACTIVE
) {
3114 assert(result
->total
!= 0);
3115 percent
= 100.0 * result
->completed
/ result
->total
;
3116 monitor_printf(mon
, "Finished: %.2f %%\n", percent
);
3119 qapi_free_DumpQueryResult(result
);
3122 void hmp_info_ramblock(Monitor
*mon
, const QDict
*qdict
)
3124 ram_block_dump(mon
);
3127 void hmp_hotpluggable_cpus(Monitor
*mon
, const QDict
*qdict
)
3130 HotpluggableCPUList
*l
= qmp_query_hotpluggable_cpus(&err
);
3131 HotpluggableCPUList
*saved
= l
;
3132 CpuInstanceProperties
*c
;
3135 hmp_handle_error(mon
, &err
);
3139 monitor_printf(mon
, "Hotpluggable CPUs:\n");
3141 monitor_printf(mon
, " type: \"%s\"\n", l
->value
->type
);
3142 monitor_printf(mon
, " vcpus_count: \"%" PRIu64
"\"\n",
3143 l
->value
->vcpus_count
);
3144 if (l
->value
->has_qom_path
) {
3145 monitor_printf(mon
, " qom_path: \"%s\"\n", l
->value
->qom_path
);
3148 c
= l
->value
->props
;
3149 monitor_printf(mon
, " CPUInstance Properties:\n");
3150 if (c
->has_node_id
) {
3151 monitor_printf(mon
, " node-id: \"%" PRIu64
"\"\n", c
->node_id
);
3153 if (c
->has_socket_id
) {
3154 monitor_printf(mon
, " socket-id: \"%" PRIu64
"\"\n", c
->socket_id
);
3156 if (c
->has_core_id
) {
3157 monitor_printf(mon
, " core-id: \"%" PRIu64
"\"\n", c
->core_id
);
3159 if (c
->has_thread_id
) {
3160 monitor_printf(mon
, " thread-id: \"%" PRIu64
"\"\n", c
->thread_id
);
3166 qapi_free_HotpluggableCPUList(saved
);
3169 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
3172 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
3174 monitor_printf(mon
, "%s\n", info
->guid
);
3176 hmp_handle_error(mon
, &err
);
3177 qapi_free_GuidInfo(info
);
3180 void hmp_info_memory_size_summary(Monitor
*mon
, const QDict
*qdict
)
3183 MemoryInfo
*info
= qmp_query_memory_size_summary(&err
);
3185 monitor_printf(mon
, "base memory: %" PRIu64
"\n",
3188 if (info
->has_plugged_memory
) {
3189 monitor_printf(mon
, "plugged memory: %" PRIu64
"\n",
3190 info
->plugged_memory
);
3193 qapi_free_MemoryInfo(info
);
3195 hmp_handle_error(mon
, &err
);