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/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-migration.h"
35 #include "qapi/qapi-commands-misc.h"
36 #include "qapi/qapi-commands-net.h"
37 #include "qapi/qapi-commands-rocker.h"
38 #include "qapi/qapi-commands-run-state.h"
39 #include "qapi/qapi-commands-tpm.h"
40 #include "qapi/qapi-commands-ui.h"
41 #include "qapi/qmp/qdict.h"
42 #include "qapi/qmp/qerror.h"
43 #include "qapi/string-input-visitor.h"
44 #include "qapi/string-output-visitor.h"
45 #include "qom/object_interfaces.h"
46 #include "ui/console.h"
47 #include "block/nbd.h"
48 #include "block/qapi.h"
50 #include "qemu/cutils.h"
51 #include "qemu/error-report.h"
52 #include "exec/ramlist.h"
53 #include "hw/intc/intc.h"
54 #include "hw/rdma/rdma.h"
55 #include "migration/snapshot.h"
56 #include "migration/misc.h"
59 #include <spice/enums.h>
62 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
66 error_reportf_err(*errp
, "Error: ");
70 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
74 info
= qmp_query_name(NULL
);
76 monitor_printf(mon
, "%s\n", info
->name
);
78 qapi_free_NameInfo(info
);
81 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
85 info
= qmp_query_version(NULL
);
87 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
88 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
91 qapi_free_VersionInfo(info
);
94 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
98 info
= qmp_query_kvm(NULL
);
99 monitor_printf(mon
, "kvm support: ");
101 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
103 monitor_printf(mon
, "not compiled\n");
106 qapi_free_KvmInfo(info
);
109 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
113 info
= qmp_query_status(NULL
);
115 monitor_printf(mon
, "VM status: %s%s",
116 info
->running
? "running" : "paused",
117 info
->singlestep
? " (single step mode)" : "");
119 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
120 monitor_printf(mon
, " (%s)", RunState_str(info
->status
));
123 monitor_printf(mon
, "\n");
125 qapi_free_StatusInfo(info
);
128 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
132 info
= qmp_query_uuid(NULL
);
133 monitor_printf(mon
, "%s\n", info
->UUID
);
134 qapi_free_UuidInfo(info
);
137 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
139 ChardevInfoList
*char_info
, *info
;
141 char_info
= qmp_query_chardev(NULL
);
142 for (info
= char_info
; info
; info
= info
->next
) {
143 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
144 info
->value
->filename
);
147 qapi_free_ChardevInfoList(char_info
);
150 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
152 MouseInfoList
*mice_list
, *mouse
;
154 mice_list
= qmp_query_mice(NULL
);
156 monitor_printf(mon
, "No mouse devices connected\n");
160 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
161 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
162 mouse
->value
->current
? '*' : ' ',
163 mouse
->value
->index
, mouse
->value
->name
,
164 mouse
->value
->absolute
? " (absolute)" : "");
167 qapi_free_MouseInfoList(mice_list
);
170 static char *SocketAddress_to_str(SocketAddress
*addr
)
172 switch (addr
->type
) {
173 case SOCKET_ADDRESS_TYPE_INET
:
174 return g_strdup_printf("tcp:%s:%s",
177 case SOCKET_ADDRESS_TYPE_UNIX
:
178 return g_strdup_printf("unix:%s",
179 addr
->u
.q_unix
.path
);
180 case SOCKET_ADDRESS_TYPE_FD
:
181 return g_strdup_printf("fd:%s", addr
->u
.fd
.str
);
182 case SOCKET_ADDRESS_TYPE_VSOCK
:
183 return g_strdup_printf("tcp:%s:%s",
187 return g_strdup("unknown address type");
191 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
194 MigrationCapabilityStatusList
*caps
, *cap
;
196 info
= qmp_query_migrate(NULL
);
197 caps
= qmp_query_migrate_capabilities(NULL
);
199 migration_global_dump(mon
);
201 /* do not display parameters during setup */
202 if (info
->has_status
&& caps
) {
203 monitor_printf(mon
, "capabilities: ");
204 for (cap
= caps
; cap
; cap
= cap
->next
) {
205 monitor_printf(mon
, "%s: %s ",
206 MigrationCapability_str(cap
->value
->capability
),
207 cap
->value
->state
? "on" : "off");
209 monitor_printf(mon
, "\n");
212 if (info
->has_status
) {
213 monitor_printf(mon
, "Migration status: %s",
214 MigrationStatus_str(info
->status
));
215 if (info
->status
== MIGRATION_STATUS_FAILED
&&
216 info
->has_error_desc
) {
217 monitor_printf(mon
, " (%s)\n", info
->error_desc
);
219 monitor_printf(mon
, "\n");
222 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
224 if (info
->has_expected_downtime
) {
225 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
226 info
->expected_downtime
);
228 if (info
->has_downtime
) {
229 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
232 if (info
->has_setup_time
) {
233 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
239 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
240 info
->ram
->transferred
>> 10);
241 monitor_printf(mon
, "throughput: %0.2f mbps\n",
243 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
244 info
->ram
->remaining
>> 10);
245 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
246 info
->ram
->total
>> 10);
247 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
248 info
->ram
->duplicate
);
249 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
251 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
253 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
254 info
->ram
->normal_bytes
>> 10);
255 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
256 info
->ram
->dirty_sync_count
);
257 monitor_printf(mon
, "page size: %" PRIu64
" kbytes\n",
258 info
->ram
->page_size
>> 10);
259 monitor_printf(mon
, "multifd bytes: %" PRIu64
" kbytes\n",
260 info
->ram
->multifd_bytes
>> 10);
261 monitor_printf(mon
, "pages-per-second: %" PRIu64
"\n",
262 info
->ram
->pages_per_second
);
264 if (info
->ram
->dirty_pages_rate
) {
265 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
266 info
->ram
->dirty_pages_rate
);
268 if (info
->ram
->postcopy_requests
) {
269 monitor_printf(mon
, "postcopy request count: %" PRIu64
"\n",
270 info
->ram
->postcopy_requests
);
274 if (info
->has_disk
) {
275 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
276 info
->disk
->transferred
>> 10);
277 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
278 info
->disk
->remaining
>> 10);
279 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
280 info
->disk
->total
>> 10);
283 if (info
->has_xbzrle_cache
) {
284 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
285 info
->xbzrle_cache
->cache_size
);
286 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
287 info
->xbzrle_cache
->bytes
>> 10);
288 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
289 info
->xbzrle_cache
->pages
);
290 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
291 info
->xbzrle_cache
->cache_miss
);
292 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
293 info
->xbzrle_cache
->cache_miss_rate
);
294 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
295 info
->xbzrle_cache
->overflow
);
298 if (info
->has_compression
) {
299 monitor_printf(mon
, "compression pages: %" PRIu64
" pages\n",
300 info
->compression
->pages
);
301 monitor_printf(mon
, "compression busy: %" PRIu64
"\n",
302 info
->compression
->busy
);
303 monitor_printf(mon
, "compression busy rate: %0.2f\n",
304 info
->compression
->busy_rate
);
305 monitor_printf(mon
, "compressed size: %" PRIu64
"\n",
306 info
->compression
->compressed_size
);
307 monitor_printf(mon
, "compression rate: %0.2f\n",
308 info
->compression
->compression_rate
);
311 if (info
->has_cpu_throttle_percentage
) {
312 monitor_printf(mon
, "cpu throttle percentage: %" PRIu64
"\n",
313 info
->cpu_throttle_percentage
);
316 if (info
->has_postcopy_blocktime
) {
317 monitor_printf(mon
, "postcopy blocktime: %u\n",
318 info
->postcopy_blocktime
);
321 if (info
->has_postcopy_vcpu_blocktime
) {
324 v
= string_output_visitor_new(false, &str
);
325 visit_type_uint32List(v
, NULL
, &info
->postcopy_vcpu_blocktime
, NULL
);
326 visit_complete(v
, &str
);
327 monitor_printf(mon
, "postcopy vcpu blocktime: %s\n", str
);
331 if (info
->has_socket_address
) {
332 SocketAddressList
*addr
;
334 monitor_printf(mon
, "socket address: [\n");
336 for (addr
= info
->socket_address
; addr
; addr
= addr
->next
) {
337 char *s
= SocketAddress_to_str(addr
->value
);
338 monitor_printf(mon
, "\t%s\n", s
);
341 monitor_printf(mon
, "]\n");
343 qapi_free_MigrationInfo(info
);
344 qapi_free_MigrationCapabilityStatusList(caps
);
347 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
349 MigrationCapabilityStatusList
*caps
, *cap
;
351 caps
= qmp_query_migrate_capabilities(NULL
);
354 for (cap
= caps
; cap
; cap
= cap
->next
) {
355 monitor_printf(mon
, "%s: %s\n",
356 MigrationCapability_str(cap
->value
->capability
),
357 cap
->value
->state
? "on" : "off");
361 qapi_free_MigrationCapabilityStatusList(caps
);
364 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
366 MigrationParameters
*params
;
368 params
= qmp_query_migrate_parameters(NULL
);
371 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
372 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL
),
373 params
->announce_initial
);
374 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
375 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX
),
376 params
->announce_max
);
377 monitor_printf(mon
, "%s: %" PRIu64
"\n",
378 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS
),
379 params
->announce_rounds
);
380 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
381 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP
),
382 params
->announce_step
);
383 assert(params
->has_compress_level
);
384 monitor_printf(mon
, "%s: %u\n",
385 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL
),
386 params
->compress_level
);
387 assert(params
->has_compress_threads
);
388 monitor_printf(mon
, "%s: %u\n",
389 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS
),
390 params
->compress_threads
);
391 assert(params
->has_compress_wait_thread
);
392 monitor_printf(mon
, "%s: %s\n",
393 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD
),
394 params
->compress_wait_thread
? "on" : "off");
395 assert(params
->has_decompress_threads
);
396 monitor_printf(mon
, "%s: %u\n",
397 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS
),
398 params
->decompress_threads
);
399 assert(params
->has_cpu_throttle_initial
);
400 monitor_printf(mon
, "%s: %u\n",
401 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
),
402 params
->cpu_throttle_initial
);
403 assert(params
->has_cpu_throttle_increment
);
404 monitor_printf(mon
, "%s: %u\n",
405 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
),
406 params
->cpu_throttle_increment
);
407 assert(params
->has_max_cpu_throttle
);
408 monitor_printf(mon
, "%s: %u\n",
409 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE
),
410 params
->max_cpu_throttle
);
411 assert(params
->has_tls_creds
);
412 monitor_printf(mon
, "%s: '%s'\n",
413 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS
),
415 assert(params
->has_tls_hostname
);
416 monitor_printf(mon
, "%s: '%s'\n",
417 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME
),
418 params
->tls_hostname
);
419 assert(params
->has_max_bandwidth
);
420 monitor_printf(mon
, "%s: %" PRIu64
" bytes/second\n",
421 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH
),
422 params
->max_bandwidth
);
423 assert(params
->has_downtime_limit
);
424 monitor_printf(mon
, "%s: %" PRIu64
" milliseconds\n",
425 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT
),
426 params
->downtime_limit
);
427 assert(params
->has_x_checkpoint_delay
);
428 monitor_printf(mon
, "%s: %u\n",
429 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
),
430 params
->x_checkpoint_delay
);
431 assert(params
->has_block_incremental
);
432 monitor_printf(mon
, "%s: %s\n",
433 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL
),
434 params
->block_incremental
? "on" : "off");
435 monitor_printf(mon
, "%s: %u\n",
436 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS
),
437 params
->multifd_channels
);
438 monitor_printf(mon
, "%s: %" PRIu64
"\n",
439 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
),
440 params
->xbzrle_cache_size
);
441 monitor_printf(mon
, "%s: %" PRIu64
"\n",
442 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH
),
443 params
->max_postcopy_bandwidth
);
444 monitor_printf(mon
, " %s: '%s'\n",
445 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ
),
446 params
->has_tls_authz
? params
->tls_authz
: "");
449 qapi_free_MigrationParameters(params
);
452 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
454 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
455 qmp_query_migrate_cache_size(NULL
) >> 10);
458 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
460 CpuInfoFastList
*cpu_list
, *cpu
;
462 cpu_list
= qmp_query_cpus_fast(NULL
);
464 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
467 if (cpu
->value
->cpu_index
== monitor_get_cpu_index()) {
471 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
,
472 cpu
->value
->cpu_index
);
473 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
476 qapi_free_CpuInfoFastList(cpu_list
);
479 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
480 BlockDeviceInfo
*inserted
, bool verbose
)
482 ImageInfo
*image_info
;
484 assert(!info
|| !info
->has_inserted
|| info
->inserted
== inserted
);
486 if (info
&& *info
->device
) {
487 monitor_printf(mon
, "%s", info
->device
);
488 if (inserted
&& inserted
->has_node_name
) {
489 monitor_printf(mon
, " (%s)", inserted
->node_name
);
492 assert(info
|| inserted
);
493 monitor_printf(mon
, "%s",
494 inserted
&& inserted
->has_node_name
? inserted
->node_name
495 : info
&& info
->has_qdev
? info
->qdev
500 monitor_printf(mon
, ": %s (%s%s%s)\n",
503 inserted
->ro
? ", read-only" : "",
504 inserted
->encrypted
? ", encrypted" : "");
506 monitor_printf(mon
, ": [not inserted]\n");
510 if (info
->has_qdev
) {
511 monitor_printf(mon
, " Attached to: %s\n", info
->qdev
);
513 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
514 monitor_printf(mon
, " I/O status: %s\n",
515 BlockDeviceIoStatus_str(info
->io_status
));
518 if (info
->removable
) {
519 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
520 info
->locked
? "" : "not ",
521 info
->tray_open
? "open" : "closed");
530 monitor_printf(mon
, " Cache mode: %s%s%s\n",
531 inserted
->cache
->writeback
? "writeback" : "writethrough",
532 inserted
->cache
->direct
? ", direct" : "",
533 inserted
->cache
->no_flush
? ", ignore flushes" : "");
535 if (inserted
->has_backing_file
) {
538 "(chain depth: %" PRId64
")\n",
539 inserted
->backing_file
,
540 inserted
->backing_file_depth
);
543 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
544 monitor_printf(mon
, " Detect zeroes: %s\n",
545 BlockdevDetectZeroesOptions_str(inserted
->detect_zeroes
));
548 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
549 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
551 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
552 " bps_rd=%" PRId64
" bps_wr=%" PRId64
554 " bps_rd_max=%" PRId64
555 " bps_wr_max=%" PRId64
556 " iops=%" PRId64
" iops_rd=%" PRId64
559 " iops_rd_max=%" PRId64
560 " iops_wr_max=%" PRId64
561 " iops_size=%" PRId64
567 inserted
->bps_rd_max
,
568 inserted
->bps_wr_max
,
573 inserted
->iops_rd_max
,
574 inserted
->iops_wr_max
,
580 monitor_printf(mon
, "\nImages:\n");
581 image_info
= inserted
->image
;
583 bdrv_image_info_dump(image_info
);
584 if (image_info
->has_backing_image
) {
585 image_info
= image_info
->backing_image
;
593 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
595 BlockInfoList
*block_list
, *info
;
596 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
597 const char *device
= qdict_get_try_str(qdict
, "device");
598 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
599 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
600 bool printed
= false;
602 /* Print BlockBackend information */
604 block_list
= qmp_query_block(NULL
);
609 for (info
= block_list
; info
; info
= info
->next
) {
610 if (device
&& strcmp(device
, info
->value
->device
)) {
614 if (info
!= block_list
) {
615 monitor_printf(mon
, "\n");
618 print_block_info(mon
, info
->value
, info
->value
->has_inserted
619 ? info
->value
->inserted
: NULL
,
624 qapi_free_BlockInfoList(block_list
);
626 if ((!device
&& !nodes
) || printed
) {
630 /* Print node information */
631 blockdev_list
= qmp_query_named_block_nodes(NULL
);
632 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
633 assert(blockdev
->value
->has_node_name
);
634 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
638 if (blockdev
!= blockdev_list
) {
639 monitor_printf(mon
, "\n");
642 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
644 qapi_free_BlockDeviceInfoList(blockdev_list
);
647 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
649 BlockStatsList
*stats_list
, *stats
;
651 stats_list
= qmp_query_blockstats(false, false, NULL
);
653 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
654 if (!stats
->value
->has_device
) {
658 monitor_printf(mon
, "%s:", stats
->value
->device
);
659 monitor_printf(mon
, " rd_bytes=%" PRId64
661 " rd_operations=%" PRId64
662 " wr_operations=%" PRId64
663 " flush_operations=%" PRId64
664 " wr_total_time_ns=%" PRId64
665 " rd_total_time_ns=%" PRId64
666 " flush_total_time_ns=%" PRId64
667 " rd_merged=%" PRId64
668 " wr_merged=%" PRId64
669 " idle_time_ns=%" PRId64
671 stats
->value
->stats
->rd_bytes
,
672 stats
->value
->stats
->wr_bytes
,
673 stats
->value
->stats
->rd_operations
,
674 stats
->value
->stats
->wr_operations
,
675 stats
->value
->stats
->flush_operations
,
676 stats
->value
->stats
->wr_total_time_ns
,
677 stats
->value
->stats
->rd_total_time_ns
,
678 stats
->value
->stats
->flush_total_time_ns
,
679 stats
->value
->stats
->rd_merged
,
680 stats
->value
->stats
->wr_merged
,
681 stats
->value
->stats
->idle_time_ns
);
684 qapi_free_BlockStatsList(stats_list
);
688 /* Helper for hmp_info_vnc_clients, _servers */
689 static void hmp_info_VncBasicInfo(Monitor
*mon
, VncBasicInfo
*info
,
692 monitor_printf(mon
, " %s: %s:%s (%s%s)\n",
696 NetworkAddressFamily_str(info
->family
),
697 info
->websocket
? " (Websocket)" : "");
700 /* Helper displaying and auth and crypt info */
701 static void hmp_info_vnc_authcrypt(Monitor
*mon
, const char *indent
,
703 VncVencryptSubAuth
*vencrypt
)
705 monitor_printf(mon
, "%sAuth: %s (Sub: %s)\n", indent
,
706 VncPrimaryAuth_str(auth
),
707 vencrypt
? VncVencryptSubAuth_str(*vencrypt
) : "none");
710 static void hmp_info_vnc_clients(Monitor
*mon
, VncClientInfoList
*client
)
713 VncClientInfo
*cinfo
= client
->value
;
715 hmp_info_VncBasicInfo(mon
, qapi_VncClientInfo_base(cinfo
), "Client");
716 monitor_printf(mon
, " x509_dname: %s\n",
717 cinfo
->has_x509_dname
?
718 cinfo
->x509_dname
: "none");
719 monitor_printf(mon
, " sasl_username: %s\n",
720 cinfo
->has_sasl_username
?
721 cinfo
->sasl_username
: "none");
723 client
= client
->next
;
727 static void hmp_info_vnc_servers(Monitor
*mon
, VncServerInfo2List
*server
)
730 VncServerInfo2
*sinfo
= server
->value
;
731 hmp_info_VncBasicInfo(mon
, qapi_VncServerInfo2_base(sinfo
), "Server");
732 hmp_info_vnc_authcrypt(mon
, " ", sinfo
->auth
,
733 sinfo
->has_vencrypt
? &sinfo
->vencrypt
: NULL
);
734 server
= server
->next
;
738 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
740 VncInfo2List
*info2l
;
743 info2l
= qmp_query_vnc_servers(&err
);
745 hmp_handle_error(mon
, &err
);
749 monitor_printf(mon
, "None\n");
754 VncInfo2
*info
= info2l
->value
;
755 monitor_printf(mon
, "%s:\n", info
->id
);
756 hmp_info_vnc_servers(mon
, info
->server
);
757 hmp_info_vnc_clients(mon
, info
->clients
);
759 /* The server entry displays its auth, we only
760 * need to display in the case of 'reverse' connections
761 * where there's no server.
763 hmp_info_vnc_authcrypt(mon
, " ", info
->auth
,
764 info
->has_vencrypt
? &info
->vencrypt
: NULL
);
766 if (info
->has_display
) {
767 monitor_printf(mon
, " Display: %s\n", info
->display
);
769 info2l
= info2l
->next
;
772 qapi_free_VncInfo2List(info2l
);
778 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
780 SpiceChannelList
*chan
;
782 const char *channel_name
;
783 const char * const channel_names
[] = {
784 [SPICE_CHANNEL_MAIN
] = "main",
785 [SPICE_CHANNEL_DISPLAY
] = "display",
786 [SPICE_CHANNEL_INPUTS
] = "inputs",
787 [SPICE_CHANNEL_CURSOR
] = "cursor",
788 [SPICE_CHANNEL_PLAYBACK
] = "playback",
789 [SPICE_CHANNEL_RECORD
] = "record",
790 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
791 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
792 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
793 [SPICE_CHANNEL_PORT
] = "port",
795 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
796 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
797 * as quick fix for build failures with older versions. */
798 [SPICE_CHANNEL_WEBDAV
] = "webdav",
802 info
= qmp_query_spice(NULL
);
804 if (!info
->enabled
) {
805 monitor_printf(mon
, "Server: disabled\n");
809 monitor_printf(mon
, "Server:\n");
810 if (info
->has_port
) {
811 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
812 info
->host
, info
->port
);
814 if (info
->has_tls_port
) {
815 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
816 info
->host
, info
->tls_port
);
818 monitor_printf(mon
, " migrated: %s\n",
819 info
->migrated
? "true" : "false");
820 monitor_printf(mon
, " auth: %s\n", info
->auth
);
821 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
822 monitor_printf(mon
, " mouse-mode: %s\n",
823 SpiceQueryMouseMode_str(info
->mouse_mode
));
825 if (!info
->has_channels
|| info
->channels
== NULL
) {
826 monitor_printf(mon
, "Channels: none\n");
828 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
829 monitor_printf(mon
, "Channel:\n");
830 monitor_printf(mon
, " address: %s:%s%s\n",
831 chan
->value
->host
, chan
->value
->port
,
832 chan
->value
->tls
? " [tls]" : "");
833 monitor_printf(mon
, " session: %" PRId64
"\n",
834 chan
->value
->connection_id
);
835 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
836 chan
->value
->channel_type
, chan
->value
->channel_id
);
838 channel_name
= "unknown";
839 if (chan
->value
->channel_type
> 0 &&
840 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
841 channel_names
[chan
->value
->channel_type
]) {
842 channel_name
= channel_names
[chan
->value
->channel_type
];
845 monitor_printf(mon
, " channel name: %s\n", channel_name
);
850 qapi_free_SpiceInfo(info
);
854 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
859 info
= qmp_query_balloon(&err
);
861 hmp_handle_error(mon
, &err
);
865 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
867 qapi_free_BalloonInfo(info
);
870 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
872 PciMemoryRegionList
*region
;
874 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
875 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
876 dev
->slot
, dev
->function
);
877 monitor_printf(mon
, " ");
879 if (dev
->class_info
->has_desc
) {
880 monitor_printf(mon
, "%s", dev
->class_info
->desc
);
882 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
885 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
886 dev
->id
->vendor
, dev
->id
->device
);
887 if (dev
->id
->has_subsystem_vendor
&& dev
->id
->has_subsystem
) {
888 monitor_printf(mon
, " PCI subsystem %04" PRIx64
":%04" PRIx64
"\n",
889 dev
->id
->subsystem_vendor
, dev
->id
->subsystem
);
893 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
896 if (dev
->has_pci_bridge
) {
897 monitor_printf(mon
, " BUS %" PRId64
".\n",
898 dev
->pci_bridge
->bus
->number
);
899 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
900 dev
->pci_bridge
->bus
->secondary
);
901 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
902 dev
->pci_bridge
->bus
->subordinate
);
904 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
905 dev
->pci_bridge
->bus
->io_range
->base
,
906 dev
->pci_bridge
->bus
->io_range
->limit
);
909 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
910 dev
->pci_bridge
->bus
->memory_range
->base
,
911 dev
->pci_bridge
->bus
->memory_range
->limit
);
913 monitor_printf(mon
, " prefetchable memory range "
914 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
915 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
916 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
919 for (region
= dev
->regions
; region
; region
= region
->next
) {
922 addr
= region
->value
->address
;
923 size
= region
->value
->size
;
925 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
927 if (!strcmp(region
->value
->type
, "io")) {
928 monitor_printf(mon
, "I/O at 0x%04" PRIx64
929 " [0x%04" PRIx64
"].\n",
930 addr
, addr
+ size
- 1);
932 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
933 " [0x%08" PRIx64
"].\n",
934 region
->value
->mem_type_64
? 64 : 32,
935 region
->value
->prefetch
? " prefetchable" : "",
936 addr
, addr
+ size
- 1);
940 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
942 if (dev
->has_pci_bridge
) {
943 if (dev
->pci_bridge
->has_devices
) {
944 PciDeviceInfoList
*cdev
;
945 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
946 hmp_info_pci_device(mon
, cdev
->value
);
952 static int hmp_info_irq_foreach(Object
*obj
, void *opaque
)
954 InterruptStatsProvider
*intc
;
955 InterruptStatsProviderClass
*k
;
956 Monitor
*mon
= opaque
;
958 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
959 intc
= INTERRUPT_STATS_PROVIDER(obj
);
960 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
961 uint64_t *irq_counts
;
962 unsigned int nb_irqs
, i
;
963 if (k
->get_statistics
&&
964 k
->get_statistics(intc
, &irq_counts
, &nb_irqs
)) {
966 monitor_printf(mon
, "IRQ statistics for %s:\n",
967 object_get_typename(obj
));
968 for (i
= 0; i
< nb_irqs
; i
++) {
969 if (irq_counts
[i
] > 0) {
970 monitor_printf(mon
, "%2d: %" PRId64
"\n", i
,
976 monitor_printf(mon
, "IRQ statistics not available for %s.\n",
977 object_get_typename(obj
));
984 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
)
986 object_child_foreach_recursive(object_get_root(),
987 hmp_info_irq_foreach
, mon
);
990 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
992 InterruptStatsProvider
*intc
;
993 InterruptStatsProviderClass
*k
;
994 Monitor
*mon
= opaque
;
996 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
997 intc
= INTERRUPT_STATS_PROVIDER(obj
);
998 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
1000 k
->print_info(intc
, mon
);
1002 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
1003 object_get_typename(obj
));
1010 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
1012 object_child_foreach_recursive(object_get_root(),
1013 hmp_info_pic_foreach
, mon
);
1016 static int hmp_info_rdma_foreach(Object
*obj
, void *opaque
)
1019 RdmaProviderClass
*k
;
1020 Monitor
*mon
= opaque
;
1022 if (object_dynamic_cast(obj
, INTERFACE_RDMA_PROVIDER
)) {
1023 rdma
= RDMA_PROVIDER(obj
);
1024 k
= RDMA_PROVIDER_GET_CLASS(obj
);
1025 if (k
->print_statistics
) {
1026 k
->print_statistics(mon
, rdma
);
1028 monitor_printf(mon
, "RDMA statistics not available for %s.\n",
1029 object_get_typename(obj
));
1036 void hmp_info_rdma(Monitor
*mon
, const QDict
*qdict
)
1038 object_child_foreach_recursive(object_get_root(),
1039 hmp_info_rdma_foreach
, mon
);
1042 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
1044 PciInfoList
*info_list
, *info
;
1047 info_list
= qmp_query_pci(&err
);
1049 monitor_printf(mon
, "PCI devices not supported\n");
1054 for (info
= info_list
; info
; info
= info
->next
) {
1055 PciDeviceInfoList
*dev
;
1057 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
1058 hmp_info_pci_device(mon
, dev
->value
);
1062 qapi_free_PciInfoList(info_list
);
1065 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
1067 BlockJobInfoList
*list
;
1070 list
= qmp_query_block_jobs(&err
);
1074 monitor_printf(mon
, "No active jobs\n");
1079 if (strcmp(list
->value
->type
, "stream") == 0) {
1080 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
1081 " of %" PRId64
" bytes, speed limit %" PRId64
1083 list
->value
->device
,
1084 list
->value
->offset
,
1086 list
->value
->speed
);
1088 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
1089 " of %" PRId64
" bytes, speed limit %" PRId64
1092 list
->value
->device
,
1093 list
->value
->offset
,
1095 list
->value
->speed
);
1100 qapi_free_BlockJobInfoList(list
);
1103 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
1105 TPMInfoList
*info_list
, *info
;
1108 TPMPassthroughOptions
*tpo
;
1109 TPMEmulatorOptions
*teo
;
1111 info_list
= qmp_query_tpm(&err
);
1113 monitor_printf(mon
, "TPM device not supported\n");
1119 monitor_printf(mon
, "TPM device:\n");
1122 for (info
= info_list
; info
; info
= info
->next
) {
1123 TPMInfo
*ti
= info
->value
;
1124 monitor_printf(mon
, " tpm%d: model=%s\n",
1125 c
, TpmModel_str(ti
->model
));
1127 monitor_printf(mon
, " \\ %s: type=%s",
1128 ti
->id
, TpmTypeOptionsKind_str(ti
->options
->type
));
1130 switch (ti
->options
->type
) {
1131 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
1132 tpo
= ti
->options
->u
.passthrough
.data
;
1133 monitor_printf(mon
, "%s%s%s%s",
1134 tpo
->has_path
? ",path=" : "",
1135 tpo
->has_path
? tpo
->path
: "",
1136 tpo
->has_cancel_path
? ",cancel-path=" : "",
1137 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
1139 case TPM_TYPE_OPTIONS_KIND_EMULATOR
:
1140 teo
= ti
->options
->u
.emulator
.data
;
1141 monitor_printf(mon
, ",chardev=%s", teo
->chardev
);
1143 case TPM_TYPE_OPTIONS_KIND__MAX
:
1146 monitor_printf(mon
, "\n");
1149 qapi_free_TPMInfoList(info_list
);
1152 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
1154 monitor_suspend(mon
);
1158 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
1163 void hmp_sync_profile(Monitor
*mon
, const QDict
*qdict
)
1165 const char *op
= qdict_get_try_str(qdict
, "op");
1168 bool on
= qsp_is_enabled();
1170 monitor_printf(mon
, "sync-profile is %s\n", on
? "on" : "off");
1173 if (!strcmp(op
, "on")) {
1175 } else if (!strcmp(op
, "off")) {
1177 } else if (!strcmp(op
, "reset")) {
1182 error_setg(&err
, QERR_INVALID_PARAMETER
, op
);
1183 hmp_handle_error(mon
, &err
);
1187 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
1189 qmp_system_reset(NULL
);
1192 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
1194 qmp_system_powerdown(NULL
);
1197 void hmp_exit_preconfig(Monitor
*mon
, const QDict
*qdict
)
1201 qmp_x_exit_preconfig(&err
);
1202 hmp_handle_error(mon
, &err
);
1205 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
1209 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1210 use it are converted to the QAPI */
1211 cpu_index
= qdict_get_int(qdict
, "index");
1212 if (monitor_set_cpu(cpu_index
) < 0) {
1213 monitor_printf(mon
, "invalid CPU index\n");
1217 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
1219 uint32_t size
= qdict_get_int(qdict
, "size");
1220 const char *filename
= qdict_get_str(qdict
, "filename");
1221 uint64_t addr
= qdict_get_int(qdict
, "val");
1223 int cpu_index
= monitor_get_cpu_index();
1225 if (cpu_index
< 0) {
1226 monitor_printf(mon
, "No CPU available\n");
1230 qmp_memsave(addr
, size
, filename
, true, cpu_index
, &err
);
1231 hmp_handle_error(mon
, &err
);
1234 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
1236 uint32_t size
= qdict_get_int(qdict
, "size");
1237 const char *filename
= qdict_get_str(qdict
, "filename");
1238 uint64_t addr
= qdict_get_int(qdict
, "val");
1241 qmp_pmemsave(addr
, size
, filename
, &err
);
1242 hmp_handle_error(mon
, &err
);
1245 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
1247 const char *chardev
= qdict_get_str(qdict
, "device");
1248 const char *data
= qdict_get_str(qdict
, "data");
1251 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
1253 hmp_handle_error(mon
, &err
);
1256 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
1258 uint32_t size
= qdict_get_int(qdict
, "size");
1259 const char *chardev
= qdict_get_str(qdict
, "device");
1264 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
1266 hmp_handle_error(mon
, &err
);
1270 for (i
= 0; data
[i
]; i
++) {
1271 unsigned char ch
= data
[i
];
1274 monitor_printf(mon
, "\\\\");
1275 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
1276 monitor_printf(mon
, "\\u%04X", ch
);
1278 monitor_printf(mon
, "%c", ch
);
1282 monitor_printf(mon
, "\n");
1286 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
1291 hmp_handle_error(mon
, &err
);
1294 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
1298 qmp_system_wakeup(&err
);
1299 hmp_handle_error(mon
, &err
);
1302 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
1306 qmp_inject_nmi(&err
);
1307 hmp_handle_error(mon
, &err
);
1310 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
1312 const char *name
= qdict_get_str(qdict
, "name");
1313 bool up
= qdict_get_bool(qdict
, "up");
1316 qmp_set_link(name
, up
, &err
);
1317 hmp_handle_error(mon
, &err
);
1320 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
1322 const char *device
= qdict_get_str(qdict
, "device");
1323 const char *password
= qdict_get_str(qdict
, "password");
1326 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
1327 hmp_handle_error(mon
, &err
);
1330 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1332 int64_t value
= qdict_get_int(qdict
, "value");
1335 qmp_balloon(value
, &err
);
1336 hmp_handle_error(mon
, &err
);
1339 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
1341 const char *device
= qdict_get_str(qdict
, "device");
1342 int64_t size
= qdict_get_int(qdict
, "size");
1345 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
1346 hmp_handle_error(mon
, &err
);
1349 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
1351 const char *filename
= qdict_get_str(qdict
, "target");
1352 const char *format
= qdict_get_try_str(qdict
, "format");
1353 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1354 bool full
= qdict_get_try_bool(qdict
, "full", false);
1356 DriveMirror mirror
= {
1357 .device
= (char *)qdict_get_str(qdict
, "device"),
1358 .target
= (char *)filename
,
1359 .has_format
= !!format
,
1360 .format
= (char *)format
,
1361 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1363 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1368 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1369 hmp_handle_error(mon
, &err
);
1372 qmp_drive_mirror(&mirror
, &err
);
1373 hmp_handle_error(mon
, &err
);
1376 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
1378 const char *device
= qdict_get_str(qdict
, "device");
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);
1383 bool compress
= qdict_get_try_bool(qdict
, "compress", false);
1385 DriveBackup backup
= {
1386 .device
= (char *)device
,
1387 .target
= (char *)filename
,
1388 .has_format
= !!format
,
1389 .format
= (char *)format
,
1390 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1392 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1393 .has_compress
= !!compress
,
1394 .compress
= compress
,
1398 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1399 hmp_handle_error(mon
, &err
);
1403 qmp_drive_backup(&backup
, &err
);
1404 hmp_handle_error(mon
, &err
);
1407 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
1409 const char *device
= qdict_get_str(qdict
, "device");
1410 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
1411 const char *format
= qdict_get_try_str(qdict
, "format");
1412 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1413 enum NewImageMode mode
;
1417 /* In the future, if 'snapshot-file' is not specified, the snapshot
1418 will be taken internally. Today it's actually required. */
1419 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
1420 hmp_handle_error(mon
, &err
);
1424 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1425 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
1426 filename
, false, NULL
,
1429 hmp_handle_error(mon
, &err
);
1432 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1434 const char *device
= qdict_get_str(qdict
, "device");
1435 const char *name
= qdict_get_str(qdict
, "name");
1438 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1439 hmp_handle_error(mon
, &err
);
1442 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1444 const char *device
= qdict_get_str(qdict
, "device");
1445 const char *name
= qdict_get_str(qdict
, "name");
1446 const char *id
= qdict_get_try_str(qdict
, "id");
1449 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1451 hmp_handle_error(mon
, &err
);
1454 void hmp_loadvm(Monitor
*mon
, const QDict
*qdict
)
1456 int saved_vm_running
= runstate_is_running();
1457 const char *name
= qdict_get_str(qdict
, "name");
1460 vm_stop(RUN_STATE_RESTORE_VM
);
1462 if (load_snapshot(name
, &err
) == 0 && saved_vm_running
) {
1465 hmp_handle_error(mon
, &err
);
1468 void hmp_savevm(Monitor
*mon
, const QDict
*qdict
)
1472 save_snapshot(qdict_get_try_str(qdict
, "name"), &err
);
1473 hmp_handle_error(mon
, &err
);
1476 void hmp_delvm(Monitor
*mon
, const QDict
*qdict
)
1478 BlockDriverState
*bs
;
1480 const char *name
= qdict_get_str(qdict
, "name");
1482 if (bdrv_all_delete_snapshot(name
, &bs
, &err
) < 0) {
1484 "deleting snapshot on device '%s': ",
1485 bdrv_get_device_name(bs
));
1487 hmp_handle_error(mon
, &err
);
1490 void hmp_info_snapshots(Monitor
*mon
, const QDict
*qdict
)
1492 BlockDriverState
*bs
, *bs1
;
1493 BdrvNextIterator it1
;
1494 QEMUSnapshotInfo
*sn_tab
, *sn
;
1495 bool no_snapshot
= true;
1498 int *global_snapshots
;
1499 AioContext
*aio_context
;
1501 typedef struct SnapshotEntry
{
1502 QEMUSnapshotInfo sn
;
1503 QTAILQ_ENTRY(SnapshotEntry
) next
;
1506 typedef struct ImageEntry
{
1507 const char *imagename
;
1508 QTAILQ_ENTRY(ImageEntry
) next
;
1509 QTAILQ_HEAD(, SnapshotEntry
) snapshots
;
1512 QTAILQ_HEAD(, ImageEntry
) image_list
=
1513 QTAILQ_HEAD_INITIALIZER(image_list
);
1515 ImageEntry
*image_entry
, *next_ie
;
1516 SnapshotEntry
*snapshot_entry
;
1518 bs
= bdrv_all_find_vmstate_bs();
1520 monitor_printf(mon
, "No available block device supports snapshots\n");
1523 aio_context
= bdrv_get_aio_context(bs
);
1525 aio_context_acquire(aio_context
);
1526 nb_sns
= bdrv_snapshot_list(bs
, &sn_tab
);
1527 aio_context_release(aio_context
);
1530 monitor_printf(mon
, "bdrv_snapshot_list: error %d\n", nb_sns
);
1534 for (bs1
= bdrv_first(&it1
); bs1
; bs1
= bdrv_next(&it1
)) {
1538 AioContext
*ctx
= bdrv_get_aio_context(bs1
);
1540 aio_context_acquire(ctx
);
1541 if (bdrv_can_snapshot(bs1
)) {
1543 bs1_nb_sns
= bdrv_snapshot_list(bs1
, &sn
);
1544 if (bs1_nb_sns
> 0) {
1545 no_snapshot
= false;
1546 ie
= g_new0(ImageEntry
, 1);
1547 ie
->imagename
= bdrv_get_device_name(bs1
);
1548 QTAILQ_INIT(&ie
->snapshots
);
1549 QTAILQ_INSERT_TAIL(&image_list
, ie
, next
);
1550 for (i
= 0; i
< bs1_nb_sns
; i
++) {
1551 se
= g_new0(SnapshotEntry
, 1);
1553 QTAILQ_INSERT_TAIL(&ie
->snapshots
, se
, next
);
1558 aio_context_release(ctx
);
1562 monitor_printf(mon
, "There is no snapshot available.\n");
1566 global_snapshots
= g_new0(int, nb_sns
);
1568 for (i
= 0; i
< nb_sns
; i
++) {
1569 SnapshotEntry
*next_sn
;
1570 if (bdrv_all_find_snapshot(sn_tab
[i
].name
, &bs1
) == 0) {
1571 global_snapshots
[total
] = i
;
1573 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1574 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
,
1576 if (!strcmp(sn_tab
[i
].name
, snapshot_entry
->sn
.name
)) {
1577 QTAILQ_REMOVE(&image_entry
->snapshots
, snapshot_entry
,
1579 g_free(snapshot_entry
);
1586 monitor_printf(mon
, "List of snapshots present on all disks:\n");
1589 bdrv_snapshot_dump(NULL
);
1590 monitor_printf(mon
, "\n");
1591 for (i
= 0; i
< total
; i
++) {
1592 sn
= &sn_tab
[global_snapshots
[i
]];
1593 /* The ID is not guaranteed to be the same on all images, so
1596 pstrcpy(sn
->id_str
, sizeof(sn
->id_str
), "--");
1597 bdrv_snapshot_dump(sn
);
1598 monitor_printf(mon
, "\n");
1601 monitor_printf(mon
, "None\n");
1604 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
1605 if (QTAILQ_EMPTY(&image_entry
->snapshots
)) {
1609 "\nList of partial (non-loadable) snapshots on '%s':\n",
1610 image_entry
->imagename
);
1611 bdrv_snapshot_dump(NULL
);
1612 monitor_printf(mon
, "\n");
1613 QTAILQ_FOREACH(snapshot_entry
, &image_entry
->snapshots
, next
) {
1614 bdrv_snapshot_dump(&snapshot_entry
->sn
);
1615 monitor_printf(mon
, "\n");
1619 QTAILQ_FOREACH_SAFE(image_entry
, &image_list
, next
, next_ie
) {
1620 SnapshotEntry
*next_sn
;
1621 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
, next
,
1623 g_free(snapshot_entry
);
1625 g_free(image_entry
);
1628 g_free(global_snapshots
);
1632 void hmp_announce_self(Monitor
*mon
, const QDict
*qdict
)
1634 qmp_announce_self(migrate_announce_params(), NULL
);
1637 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1639 qmp_migrate_cancel(NULL
);
1642 void hmp_migrate_continue(Monitor
*mon
, const QDict
*qdict
)
1645 const char *state
= qdict_get_str(qdict
, "state");
1646 int val
= qapi_enum_parse(&MigrationStatus_lookup
, state
, -1, &err
);
1649 qmp_migrate_continue(val
, &err
);
1652 hmp_handle_error(mon
, &err
);
1655 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1658 const char *uri
= qdict_get_str(qdict
, "uri");
1660 qmp_migrate_incoming(uri
, &err
);
1662 hmp_handle_error(mon
, &err
);
1665 void hmp_migrate_recover(Monitor
*mon
, const QDict
*qdict
)
1668 const char *uri
= qdict_get_str(qdict
, "uri");
1670 qmp_migrate_recover(uri
, &err
);
1672 hmp_handle_error(mon
, &err
);
1675 void hmp_migrate_pause(Monitor
*mon
, const QDict
*qdict
)
1679 qmp_migrate_pause(&err
);
1681 hmp_handle_error(mon
, &err
);
1684 /* Kept for backwards compatibility */
1685 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1687 double value
= qdict_get_double(qdict
, "value");
1688 qmp_migrate_set_downtime(value
, NULL
);
1691 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1693 int64_t value
= qdict_get_int(qdict
, "value");
1696 qmp_migrate_set_cache_size(value
, &err
);
1697 hmp_handle_error(mon
, &err
);
1700 /* Kept for backwards compatibility */
1701 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1703 int64_t value
= qdict_get_int(qdict
, "value");
1704 qmp_migrate_set_speed(value
, NULL
);
1707 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1709 const char *cap
= qdict_get_str(qdict
, "capability");
1710 bool state
= qdict_get_bool(qdict
, "state");
1712 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1715 val
= qapi_enum_parse(&MigrationCapability_lookup
, cap
, -1, &err
);
1720 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1721 caps
->value
->capability
= val
;
1722 caps
->value
->state
= state
;
1724 qmp_migrate_set_capabilities(caps
, &err
);
1727 qapi_free_MigrationCapabilityStatusList(caps
);
1728 hmp_handle_error(mon
, &err
);
1731 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1733 const char *param
= qdict_get_str(qdict
, "parameter");
1734 const char *valuestr
= qdict_get_str(qdict
, "value");
1735 Visitor
*v
= string_input_visitor_new(valuestr
);
1736 MigrateSetParameters
*p
= g_new0(MigrateSetParameters
, 1);
1737 uint64_t valuebw
= 0;
1738 uint64_t cache_size
;
1742 val
= qapi_enum_parse(&MigrationParameter_lookup
, param
, -1, &err
);
1748 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1749 p
->has_compress_level
= true;
1750 visit_type_int(v
, param
, &p
->compress_level
, &err
);
1752 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1753 p
->has_compress_threads
= true;
1754 visit_type_int(v
, param
, &p
->compress_threads
, &err
);
1756 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD
:
1757 p
->has_compress_wait_thread
= true;
1758 visit_type_bool(v
, param
, &p
->compress_wait_thread
, &err
);
1760 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1761 p
->has_decompress_threads
= true;
1762 visit_type_int(v
, param
, &p
->decompress_threads
, &err
);
1764 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1765 p
->has_cpu_throttle_initial
= true;
1766 visit_type_int(v
, param
, &p
->cpu_throttle_initial
, &err
);
1768 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1769 p
->has_cpu_throttle_increment
= true;
1770 visit_type_int(v
, param
, &p
->cpu_throttle_increment
, &err
);
1772 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE
:
1773 p
->has_max_cpu_throttle
= true;
1774 visit_type_int(v
, param
, &p
->max_cpu_throttle
, &err
);
1776 case MIGRATION_PARAMETER_TLS_CREDS
:
1777 p
->has_tls_creds
= true;
1778 p
->tls_creds
= g_new0(StrOrNull
, 1);
1779 p
->tls_creds
->type
= QTYPE_QSTRING
;
1780 visit_type_str(v
, param
, &p
->tls_creds
->u
.s
, &err
);
1782 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1783 p
->has_tls_hostname
= true;
1784 p
->tls_hostname
= g_new0(StrOrNull
, 1);
1785 p
->tls_hostname
->type
= QTYPE_QSTRING
;
1786 visit_type_str(v
, param
, &p
->tls_hostname
->u
.s
, &err
);
1788 case MIGRATION_PARAMETER_TLS_AUTHZ
:
1789 p
->has_tls_authz
= true;
1790 p
->tls_authz
= g_new0(StrOrNull
, 1);
1791 p
->tls_authz
->type
= QTYPE_QSTRING
;
1792 visit_type_str(v
, param
, &p
->tls_authz
->u
.s
, &err
);
1794 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1795 p
->has_max_bandwidth
= true;
1797 * Can't use visit_type_size() here, because it
1798 * defaults to Bytes rather than Mebibytes.
1800 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
1801 if (ret
< 0 || valuebw
> INT64_MAX
1802 || (size_t)valuebw
!= valuebw
) {
1803 error_setg(&err
, "Invalid size %s", valuestr
);
1806 p
->max_bandwidth
= valuebw
;
1808 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1809 p
->has_downtime_limit
= true;
1810 visit_type_int(v
, param
, &p
->downtime_limit
, &err
);
1812 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
1813 p
->has_x_checkpoint_delay
= true;
1814 visit_type_int(v
, param
, &p
->x_checkpoint_delay
, &err
);
1816 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL
:
1817 p
->has_block_incremental
= true;
1818 visit_type_bool(v
, param
, &p
->block_incremental
, &err
);
1820 case MIGRATION_PARAMETER_MULTIFD_CHANNELS
:
1821 p
->has_multifd_channels
= true;
1822 visit_type_int(v
, param
, &p
->multifd_channels
, &err
);
1824 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
:
1825 p
->has_xbzrle_cache_size
= true;
1826 visit_type_size(v
, param
, &cache_size
, &err
);
1830 if (cache_size
> INT64_MAX
|| (size_t)cache_size
!= cache_size
) {
1831 error_setg(&err
, "Invalid size %s", valuestr
);
1834 p
->xbzrle_cache_size
= cache_size
;
1836 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH
:
1837 p
->has_max_postcopy_bandwidth
= true;
1838 visit_type_size(v
, param
, &p
->max_postcopy_bandwidth
, &err
);
1840 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL
:
1841 p
->has_announce_initial
= true;
1842 visit_type_size(v
, param
, &p
->announce_initial
, &err
);
1844 case MIGRATION_PARAMETER_ANNOUNCE_MAX
:
1845 p
->has_announce_max
= true;
1846 visit_type_size(v
, param
, &p
->announce_max
, &err
);
1848 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS
:
1849 p
->has_announce_rounds
= true;
1850 visit_type_size(v
, param
, &p
->announce_rounds
, &err
);
1852 case MIGRATION_PARAMETER_ANNOUNCE_STEP
:
1853 p
->has_announce_step
= true;
1854 visit_type_size(v
, param
, &p
->announce_step
, &err
);
1864 qmp_migrate_set_parameters(p
, &err
);
1867 qapi_free_MigrateSetParameters(p
);
1869 hmp_handle_error(mon
, &err
);
1872 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1875 const char *protocol
= qdict_get_str(qdict
, "protocol");
1876 const char *hostname
= qdict_get_str(qdict
, "hostname");
1877 bool has_port
= qdict_haskey(qdict
, "port");
1878 int port
= qdict_get_try_int(qdict
, "port", -1);
1879 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1880 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1881 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1883 qmp_client_migrate_info(protocol
, hostname
,
1884 has_port
, port
, has_tls_port
, tls_port
,
1885 !!cert_subject
, cert_subject
, &err
);
1886 hmp_handle_error(mon
, &err
);
1889 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1892 qmp_migrate_start_postcopy(&err
);
1893 hmp_handle_error(mon
, &err
);
1896 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1900 qmp_x_colo_lost_heartbeat(&err
);
1901 hmp_handle_error(mon
, &err
);
1904 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1906 const char *protocol
= qdict_get_str(qdict
, "protocol");
1907 const char *password
= qdict_get_str(qdict
, "password");
1908 const char *connected
= qdict_get_try_str(qdict
, "connected");
1911 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1912 hmp_handle_error(mon
, &err
);
1915 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1917 const char *protocol
= qdict_get_str(qdict
, "protocol");
1918 const char *whenstr
= qdict_get_str(qdict
, "time");
1921 qmp_expire_password(protocol
, whenstr
, &err
);
1922 hmp_handle_error(mon
, &err
);
1925 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1927 bool force
= qdict_get_try_bool(qdict
, "force", false);
1928 const char *device
= qdict_get_str(qdict
, "device");
1931 qmp_eject(true, device
, false, NULL
, true, force
, &err
);
1932 hmp_handle_error(mon
, &err
);
1936 static void hmp_change_read_arg(void *opaque
, const char *password
,
1937 void *readline_opaque
)
1939 qmp_change_vnc_password(password
, NULL
);
1940 monitor_read_command(opaque
, 1);
1944 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1946 MonitorHMP
*hmp_mon
= container_of(mon
, MonitorHMP
, common
);
1947 const char *device
= qdict_get_str(qdict
, "device");
1948 const char *target
= qdict_get_str(qdict
, "target");
1949 const char *arg
= qdict_get_try_str(qdict
, "arg");
1950 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1951 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1955 if (strcmp(device
, "vnc") == 0) {
1958 "Parameter 'read-only-mode' is invalid for VNC\n");
1961 if (strcmp(target
, "passwd") == 0 ||
1962 strcmp(target
, "password") == 0) {
1964 monitor_read_password(hmp_mon
, hmp_change_read_arg
, NULL
);
1968 qmp_change("vnc", target
, !!arg
, arg
, &err
);
1974 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup
,
1976 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1978 hmp_handle_error(mon
, &err
);
1983 qmp_blockdev_change_medium(true, device
, false, NULL
, target
,
1984 !!arg
, arg
, !!read_only
, read_only_mode
,
1988 hmp_handle_error(mon
, &err
);
1991 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1994 char *device
= (char *) qdict_get_str(qdict
, "device");
1995 BlockIOThrottle throttle
= {
1996 .bps
= qdict_get_int(qdict
, "bps"),
1997 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
1998 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
1999 .iops
= qdict_get_int(qdict
, "iops"),
2000 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
2001 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
2004 /* qmp_block_set_io_throttle has separate parameters for the
2005 * (deprecated) block device name and the qdev ID but the HMP
2006 * version has only one, so we must decide which one to pass. */
2007 if (blk_by_name(device
)) {
2008 throttle
.has_device
= true;
2009 throttle
.device
= device
;
2011 throttle
.has_id
= true;
2012 throttle
.id
= device
;
2015 qmp_block_set_io_throttle(&throttle
, &err
);
2016 hmp_handle_error(mon
, &err
);
2019 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
2021 Error
*error
= NULL
;
2022 const char *device
= qdict_get_str(qdict
, "device");
2023 const char *base
= qdict_get_try_str(qdict
, "base");
2024 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
2026 qmp_block_stream(true, device
, device
, base
!= NULL
, base
, false, NULL
,
2027 false, NULL
, qdict_haskey(qdict
, "speed"), speed
, true,
2028 BLOCKDEV_ON_ERROR_REPORT
, false, false, false, false,
2031 hmp_handle_error(mon
, &error
);
2034 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
2036 Error
*error
= NULL
;
2037 const char *device
= qdict_get_str(qdict
, "device");
2038 int64_t value
= qdict_get_int(qdict
, "speed");
2040 qmp_block_job_set_speed(device
, value
, &error
);
2042 hmp_handle_error(mon
, &error
);
2045 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
2047 Error
*error
= NULL
;
2048 const char *device
= qdict_get_str(qdict
, "device");
2049 bool force
= qdict_get_try_bool(qdict
, "force", false);
2051 qmp_block_job_cancel(device
, true, force
, &error
);
2053 hmp_handle_error(mon
, &error
);
2056 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
2058 Error
*error
= NULL
;
2059 const char *device
= qdict_get_str(qdict
, "device");
2061 qmp_block_job_pause(device
, &error
);
2063 hmp_handle_error(mon
, &error
);
2066 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
2068 Error
*error
= NULL
;
2069 const char *device
= qdict_get_str(qdict
, "device");
2071 qmp_block_job_resume(device
, &error
);
2073 hmp_handle_error(mon
, &error
);
2076 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
2078 Error
*error
= NULL
;
2079 const char *device
= qdict_get_str(qdict
, "device");
2081 qmp_block_job_complete(device
, &error
);
2083 hmp_handle_error(mon
, &error
);
2086 typedef struct HMPMigrationStatus
2090 bool is_block_migration
;
2091 } HMPMigrationStatus
;
2093 static void hmp_migrate_status_cb(void *opaque
)
2095 HMPMigrationStatus
*status
= opaque
;
2096 MigrationInfo
*info
;
2098 info
= qmp_query_migrate(NULL
);
2099 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
2100 info
->status
== MIGRATION_STATUS_SETUP
) {
2101 if (info
->has_disk
) {
2104 if (info
->disk
->remaining
) {
2105 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
2110 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
2111 monitor_flush(status
->mon
);
2114 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
2116 if (status
->is_block_migration
) {
2117 monitor_printf(status
->mon
, "\n");
2119 if (info
->has_error_desc
) {
2120 error_report("%s", info
->error_desc
);
2122 monitor_resume(status
->mon
);
2123 timer_del(status
->timer
);
2124 timer_free(status
->timer
);
2128 qapi_free_MigrationInfo(info
);
2131 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
2133 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
2134 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
2135 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
2136 bool resume
= qdict_get_try_bool(qdict
, "resume", false);
2137 const char *uri
= qdict_get_str(qdict
, "uri");
2140 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
,
2141 false, false, true, resume
, &err
);
2143 hmp_handle_error(mon
, &err
);
2148 HMPMigrationStatus
*status
;
2150 if (monitor_suspend(mon
) < 0) {
2151 monitor_printf(mon
, "terminal does not allow synchronous "
2152 "migration, continuing detached\n");
2156 status
= g_malloc0(sizeof(*status
));
2158 status
->is_block_migration
= blk
|| inc
;
2159 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
2161 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
2165 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
2169 qmp_device_add((QDict
*)qdict
, NULL
, &err
);
2170 hmp_handle_error(mon
, &err
);
2173 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
2175 const char *id
= qdict_get_str(qdict
, "id");
2178 qmp_device_del(id
, &err
);
2179 hmp_handle_error(mon
, &err
);
2182 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
2185 bool win_dmp
= qdict_get_try_bool(qdict
, "windmp", false);
2186 bool paging
= qdict_get_try_bool(qdict
, "paging", false);
2187 bool zlib
= qdict_get_try_bool(qdict
, "zlib", false);
2188 bool lzo
= qdict_get_try_bool(qdict
, "lzo", false);
2189 bool snappy
= qdict_get_try_bool(qdict
, "snappy", false);
2190 const char *file
= qdict_get_str(qdict
, "filename");
2191 bool has_begin
= qdict_haskey(qdict
, "begin");
2192 bool has_length
= qdict_haskey(qdict
, "length");
2193 bool has_detach
= qdict_haskey(qdict
, "detach");
2196 bool detach
= false;
2197 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
2200 if (zlib
+ lzo
+ snappy
+ win_dmp
> 1) {
2201 error_setg(&err
, "only one of '-z|-l|-s|-w' can be set");
2202 hmp_handle_error(mon
, &err
);
2207 dump_format
= DUMP_GUEST_MEMORY_FORMAT_WIN_DMP
;
2211 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
2215 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
2219 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
2223 begin
= qdict_get_int(qdict
, "begin");
2226 length
= qdict_get_int(qdict
, "length");
2229 detach
= qdict_get_bool(qdict
, "detach");
2232 prot
= g_strconcat("file:", file
, NULL
);
2234 qmp_dump_guest_memory(paging
, prot
, true, detach
, has_begin
, begin
,
2235 has_length
, length
, true, dump_format
, &err
);
2236 hmp_handle_error(mon
, &err
);
2240 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
2245 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
2250 netdev_add(opts
, &err
);
2252 qemu_opts_del(opts
);
2256 hmp_handle_error(mon
, &err
);
2259 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
2261 const char *id
= qdict_get_str(qdict
, "id");
2264 qmp_netdev_del(id
, &err
);
2265 hmp_handle_error(mon
, &err
);
2268 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
2274 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
2276 hmp_handle_error(mon
, &err
);
2280 obj
= user_creatable_add_opts(opts
, &err
);
2281 qemu_opts_del(opts
);
2284 hmp_handle_error(mon
, &err
);
2291 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
2293 const char *fdname
= qdict_get_str(qdict
, "fdname");
2296 qmp_getfd(fdname
, &err
);
2297 hmp_handle_error(mon
, &err
);
2300 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
2302 const char *fdname
= qdict_get_str(qdict
, "fdname");
2305 qmp_closefd(fdname
, &err
);
2306 hmp_handle_error(mon
, &err
);
2309 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
2311 const char *keys
= qdict_get_str(qdict
, "keys");
2312 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
2313 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
2314 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
2316 const char *separator
;
2320 separator
= qemu_strchrnul(keys
, '-');
2321 keyname_len
= separator
- keys
;
2323 /* Be compatible with old interface, convert user inputted "<" */
2324 if (keys
[0] == '<' && keyname_len
== 1) {
2329 keylist
= g_malloc0(sizeof(*keylist
));
2330 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
2336 tmp
->next
= keylist
;
2340 if (strstart(keys
, "0x", NULL
)) {
2342 int value
= strtoul(keys
, &endp
, 0);
2343 assert(endp
<= keys
+ keyname_len
);
2344 if (endp
!= keys
+ keyname_len
) {
2347 keylist
->value
->type
= KEY_VALUE_KIND_NUMBER
;
2348 keylist
->value
->u
.number
.data
= value
;
2350 int idx
= index_from_key(keys
, keyname_len
);
2351 if (idx
== Q_KEY_CODE__MAX
) {
2354 keylist
->value
->type
= KEY_VALUE_KIND_QCODE
;
2355 keylist
->value
->u
.qcode
.data
= idx
;
2361 keys
= separator
+ 1;
2364 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
2365 hmp_handle_error(mon
, &err
);
2368 qapi_free_KeyValueList(head
);
2372 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
2376 void hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
2378 const char *filename
= qdict_get_str(qdict
, "filename");
2379 const char *id
= qdict_get_try_str(qdict
, "device");
2380 int64_t head
= qdict_get_try_int(qdict
, "head", 0);
2383 qmp_screendump(filename
, id
!= NULL
, id
, id
!= NULL
, head
, &err
);
2384 hmp_handle_error(mon
, &err
);
2387 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
2389 const char *uri
= qdict_get_str(qdict
, "uri");
2390 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2391 bool all
= qdict_get_try_bool(qdict
, "all", false);
2392 Error
*local_err
= NULL
;
2393 BlockInfoList
*block_list
, *info
;
2394 SocketAddress
*addr
;
2396 if (writable
&& !all
) {
2397 error_setg(&local_err
, "-w only valid together with -a");
2401 /* First check if the address is valid and start the server. */
2402 addr
= socket_parse(uri
, &local_err
);
2403 if (local_err
!= NULL
) {
2407 nbd_server_start(addr
, NULL
, NULL
, &local_err
);
2408 qapi_free_SocketAddress(addr
);
2409 if (local_err
!= NULL
) {
2417 /* Then try adding all block devices. If one fails, close all and
2420 block_list
= qmp_query_block(NULL
);
2422 for (info
= block_list
; info
; info
= info
->next
) {
2423 if (!info
->value
->has_inserted
) {
2427 qmp_nbd_server_add(info
->value
->device
, false, NULL
,
2428 true, writable
, false, NULL
, &local_err
);
2430 if (local_err
!= NULL
) {
2431 qmp_nbd_server_stop(NULL
);
2436 qapi_free_BlockInfoList(block_list
);
2439 hmp_handle_error(mon
, &local_err
);
2442 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
2444 const char *device
= qdict_get_str(qdict
, "device");
2445 const char *name
= qdict_get_try_str(qdict
, "name");
2446 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
2447 Error
*local_err
= NULL
;
2449 qmp_nbd_server_add(device
, !!name
, name
, true, writable
,
2450 false, NULL
, &local_err
);
2451 hmp_handle_error(mon
, &local_err
);
2454 void hmp_nbd_server_remove(Monitor
*mon
, const QDict
*qdict
)
2456 const char *name
= qdict_get_str(qdict
, "name");
2457 bool force
= qdict_get_try_bool(qdict
, "force", false);
2460 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
2461 qmp_nbd_server_remove(name
, force
, NBD_SERVER_REMOVE_MODE_HARD
, &err
);
2462 hmp_handle_error(mon
, &err
);
2465 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
2469 qmp_nbd_server_stop(&err
);
2470 hmp_handle_error(mon
, &err
);
2473 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
2478 error_report("cpu_add is deprecated, please use device_add instead");
2480 cpuid
= qdict_get_int(qdict
, "id");
2481 qmp_cpu_add(cpuid
, &err
);
2482 hmp_handle_error(mon
, &err
);
2485 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
2487 const char *args
= qdict_get_str(qdict
, "args");
2491 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
2493 error_setg(&err
, "Parsing chardev args failed");
2495 qemu_chr_new_from_opts(opts
, NULL
, &err
);
2496 qemu_opts_del(opts
);
2498 hmp_handle_error(mon
, &err
);
2501 void hmp_chardev_change(Monitor
*mon
, const QDict
*qdict
)
2503 const char *args
= qdict_get_str(qdict
, "args");
2506 ChardevBackend
*backend
= NULL
;
2507 ChardevReturn
*ret
= NULL
;
2508 QemuOpts
*opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
,
2511 error_setg(&err
, "Parsing chardev args failed");
2515 id
= qdict_get_str(qdict
, "id");
2516 if (qemu_opts_id(opts
)) {
2517 error_setg(&err
, "Unexpected 'id' parameter");
2521 backend
= qemu_chr_parse_opts(opts
, &err
);
2526 ret
= qmp_chardev_change(id
, backend
, &err
);
2529 qapi_free_ChardevReturn(ret
);
2530 qapi_free_ChardevBackend(backend
);
2531 qemu_opts_del(opts
);
2532 hmp_handle_error(mon
, &err
);
2535 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
2537 Error
*local_err
= NULL
;
2539 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
2540 hmp_handle_error(mon
, &local_err
);
2543 void hmp_chardev_send_break(Monitor
*mon
, const QDict
*qdict
)
2545 Error
*local_err
= NULL
;
2547 qmp_chardev_send_break(qdict_get_str(qdict
, "id"), &local_err
);
2548 hmp_handle_error(mon
, &local_err
);
2551 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
2554 BlockBackend
*local_blk
= NULL
;
2555 const char* device
= qdict_get_str(qdict
, "device");
2556 const char* command
= qdict_get_str(qdict
, "command");
2560 blk
= blk_by_name(device
);
2562 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, device
, &err
);
2564 blk
= local_blk
= blk_new(bdrv_get_aio_context(bs
),
2566 ret
= blk_insert_bs(blk
, bs
, &err
);
2576 * Notably absent: Proper permission management. This is sad, but it seems
2577 * almost impossible to achieve without changing the semantics and thereby
2578 * limiting the use cases of the qemu-io HMP command.
2580 * In an ideal world we would unconditionally create a new BlockBackend for
2581 * qemuio_command(), but we have commands like 'reopen' and want them to
2582 * take effect on the exact BlockBackend whose name the user passed instead
2583 * of just on a temporary copy of it.
2585 * Another problem is that deleting the temporary BlockBackend involves
2586 * draining all requests on it first, but some qemu-iotests cases want to
2587 * issue multiple aio_read/write requests and expect them to complete in
2588 * the background while the monitor has already returned.
2590 * This is also what prevents us from saving the original permissions and
2591 * restoring them later: We can't revoke permissions until all requests
2592 * have completed, and we don't know when that is nor can we really let
2593 * anything else run before we have revoken them to avoid race conditions.
2595 * What happens now is that command() in qemu-io-cmds.c can extend the
2596 * permissions if necessary for the qemu-io command. And they simply stay
2597 * extended, possibly resulting in a read-only guest device keeping write
2598 * permissions. Ugly, but it appears to be the lesser evil.
2600 qemuio_command(blk
, command
);
2603 blk_unref(local_blk
);
2604 hmp_handle_error(mon
, &err
);
2607 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
2609 const char *id
= qdict_get_str(qdict
, "id");
2612 user_creatable_del(id
, &err
);
2613 hmp_handle_error(mon
, &err
);
2616 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
2619 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
2620 MemdevList
*m
= memdev_list
;
2625 v
= string_output_visitor_new(false, &str
);
2626 visit_type_uint16List(v
, NULL
, &m
->value
->host_nodes
, NULL
);
2627 monitor_printf(mon
, "memory backend: %s\n", m
->value
->id
);
2628 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
2629 monitor_printf(mon
, " merge: %s\n",
2630 m
->value
->merge
? "true" : "false");
2631 monitor_printf(mon
, " dump: %s\n",
2632 m
->value
->dump
? "true" : "false");
2633 monitor_printf(mon
, " prealloc: %s\n",
2634 m
->value
->prealloc
? "true" : "false");
2635 monitor_printf(mon
, " policy: %s\n",
2636 HostMemPolicy_str(m
->value
->policy
));
2637 visit_complete(v
, &str
);
2638 monitor_printf(mon
, " host nodes: %s\n", str
);
2645 monitor_printf(mon
, "\n");
2647 qapi_free_MemdevList(memdev_list
);
2648 hmp_handle_error(mon
, &err
);
2651 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
2654 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
2655 MemoryDeviceInfoList
*info
;
2656 MemoryDeviceInfo
*value
;
2657 PCDIMMDeviceInfo
*di
;
2659 for (info
= info_list
; info
; info
= info
->next
) {
2660 value
= info
->value
;
2663 switch (value
->type
) {
2664 case MEMORY_DEVICE_INFO_KIND_DIMM
:
2665 di
= value
->u
.dimm
.data
;
2668 case MEMORY_DEVICE_INFO_KIND_NVDIMM
:
2669 di
= value
->u
.nvdimm
.data
;
2678 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
2679 MemoryDeviceInfoKind_str(value
->type
),
2680 di
->id
? di
->id
: "");
2681 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
2682 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
2683 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
2684 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
2685 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
2686 monitor_printf(mon
, " hotplugged: %s\n",
2687 di
->hotplugged
? "true" : "false");
2688 monitor_printf(mon
, " hotpluggable: %s\n",
2689 di
->hotpluggable
? "true" : "false");
2694 qapi_free_MemoryDeviceInfoList(info_list
);
2695 hmp_handle_error(mon
, &err
);
2698 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
2700 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
2701 IOThreadInfoList
*info
;
2702 IOThreadInfo
*value
;
2704 for (info
= info_list
; info
; info
= info
->next
) {
2705 value
= info
->value
;
2706 monitor_printf(mon
, "%s:\n", value
->id
);
2707 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
2708 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
2709 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
2710 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
2713 qapi_free_IOThreadInfoList(info_list
);
2716 void hmp_qom_list(Monitor
*mon
, const QDict
*qdict
)
2718 const char *path
= qdict_get_try_str(qdict
, "path");
2719 ObjectPropertyInfoList
*list
;
2723 monitor_printf(mon
, "/\n");
2727 list
= qmp_qom_list(path
, &err
);
2729 ObjectPropertyInfoList
*start
= list
;
2730 while (list
!= NULL
) {
2731 ObjectPropertyInfo
*value
= list
->value
;
2733 monitor_printf(mon
, "%s (%s)\n",
2734 value
->name
, value
->type
);
2737 qapi_free_ObjectPropertyInfoList(start
);
2739 hmp_handle_error(mon
, &err
);
2742 void hmp_qom_set(Monitor
*mon
, const QDict
*qdict
)
2744 const char *path
= qdict_get_str(qdict
, "path");
2745 const char *property
= qdict_get_str(qdict
, "property");
2746 const char *value
= qdict_get_str(qdict
, "value");
2748 bool ambiguous
= false;
2751 obj
= object_resolve_path(path
, &ambiguous
);
2753 error_set(&err
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2754 "Device '%s' not found", path
);
2757 monitor_printf(mon
, "Warning: Path '%s' is ambiguous\n", path
);
2759 object_property_parse(obj
, value
, property
, &err
);
2761 hmp_handle_error(mon
, &err
);
2764 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
2766 const char *name
= qdict_get_str(qdict
, "name");
2767 RockerSwitch
*rocker
;
2770 rocker
= qmp_query_rocker(name
, &err
);
2772 hmp_handle_error(mon
, &err
);
2776 monitor_printf(mon
, "name: %s\n", rocker
->name
);
2777 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
2778 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
2780 qapi_free_RockerSwitch(rocker
);
2783 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
2785 RockerPortList
*list
, *port
;
2786 const char *name
= qdict_get_str(qdict
, "name");
2789 list
= qmp_query_rocker_ports(name
, &err
);
2791 hmp_handle_error(mon
, &err
);
2795 monitor_printf(mon
, " ena/ speed/ auto\n");
2796 monitor_printf(mon
, " port link duplex neg?\n");
2798 for (port
= list
; port
; port
= port
->next
) {
2799 monitor_printf(mon
, "%10s %-4s %-3s %2s %-3s\n",
2801 port
->value
->enabled
? port
->value
->link_up
?
2802 "up" : "down" : "!ena",
2803 port
->value
->speed
== 10000 ? "10G" : "??",
2804 port
->value
->duplex
? "FD" : "HD",
2805 port
->value
->autoneg
? "Yes" : "No");
2808 qapi_free_RockerPortList(list
);
2811 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
2813 RockerOfDpaFlowList
*list
, *info
;
2814 const char *name
= qdict_get_str(qdict
, "name");
2815 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
2818 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
2820 hmp_handle_error(mon
, &err
);
2824 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
2826 for (info
= list
; info
; info
= info
->next
) {
2827 RockerOfDpaFlow
*flow
= info
->value
;
2828 RockerOfDpaFlowKey
*key
= flow
->key
;
2829 RockerOfDpaFlowMask
*mask
= flow
->mask
;
2830 RockerOfDpaFlowAction
*action
= flow
->action
;
2833 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
2834 key
->priority
, key
->tbl_id
, flow
->hits
);
2836 monitor_printf(mon
, "%-4d %-3d ",
2837 key
->priority
, key
->tbl_id
);
2840 if (key
->has_in_pport
) {
2841 monitor_printf(mon
, " pport %d", key
->in_pport
);
2842 if (mask
->has_in_pport
) {
2843 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2847 if (key
->has_vlan_id
) {
2848 monitor_printf(mon
, " vlan %d",
2849 key
->vlan_id
& VLAN_VID_MASK
);
2850 if (mask
->has_vlan_id
) {
2851 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2855 if (key
->has_tunnel_id
) {
2856 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2857 if (mask
->has_tunnel_id
) {
2858 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2862 if (key
->has_eth_type
) {
2863 switch (key
->eth_type
) {
2865 monitor_printf(mon
, " ARP");
2868 monitor_printf(mon
, " IP");
2871 monitor_printf(mon
, " IPv6");
2874 monitor_printf(mon
, " LACP");
2877 monitor_printf(mon
, " LLDP");
2880 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2885 if (key
->has_eth_src
) {
2886 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2887 (mask
->has_eth_src
) &&
2888 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2889 monitor_printf(mon
, " src <any mcast/bcast>");
2890 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2891 (mask
->has_eth_src
) &&
2892 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2893 monitor_printf(mon
, " src <any ucast>");
2895 monitor_printf(mon
, " src %s", key
->eth_src
);
2896 if (mask
->has_eth_src
) {
2897 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2902 if (key
->has_eth_dst
) {
2903 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2904 (mask
->has_eth_dst
) &&
2905 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2906 monitor_printf(mon
, " dst <any mcast/bcast>");
2907 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2908 (mask
->has_eth_dst
) &&
2909 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2910 monitor_printf(mon
, " dst <any ucast>");
2912 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2913 if (mask
->has_eth_dst
) {
2914 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2919 if (key
->has_ip_proto
) {
2920 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2921 if (mask
->has_ip_proto
) {
2922 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2926 if (key
->has_ip_tos
) {
2927 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2928 if (mask
->has_ip_tos
) {
2929 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2933 if (key
->has_ip_dst
) {
2934 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2937 if (action
->has_goto_tbl
|| action
->has_group_id
||
2938 action
->has_new_vlan_id
) {
2939 monitor_printf(mon
, " -->");
2942 if (action
->has_new_vlan_id
) {
2943 monitor_printf(mon
, " apply new vlan %d",
2944 ntohs(action
->new_vlan_id
));
2947 if (action
->has_group_id
) {
2948 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2951 if (action
->has_goto_tbl
) {
2952 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2955 monitor_printf(mon
, "\n");
2958 qapi_free_RockerOfDpaFlowList(list
);
2961 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2963 RockerOfDpaGroupList
*list
, *g
;
2964 const char *name
= qdict_get_str(qdict
, "name");
2965 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2969 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
2971 hmp_handle_error(mon
, &err
);
2975 monitor_printf(mon
, "id (decode) --> buckets\n");
2977 for (g
= list
; g
; g
= g
->next
) {
2978 RockerOfDpaGroup
*group
= g
->value
;
2980 monitor_printf(mon
, "0x%08x", group
->id
);
2982 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2983 group
->type
== 1 ? "L2 rewrite" :
2984 group
->type
== 2 ? "L3 unicast" :
2985 group
->type
== 3 ? "L2 multicast" :
2986 group
->type
== 4 ? "L2 flood" :
2987 group
->type
== 5 ? "L3 interface" :
2988 group
->type
== 6 ? "L3 multicast" :
2989 group
->type
== 7 ? "L3 ECMP" :
2990 group
->type
== 8 ? "L2 overlay" :
2993 if (group
->has_vlan_id
) {
2994 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2997 if (group
->has_pport
) {
2998 monitor_printf(mon
, " pport %d", group
->pport
);
3001 if (group
->has_index
) {
3002 monitor_printf(mon
, " index %d", group
->index
);
3005 monitor_printf(mon
, ") -->");
3007 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
3009 monitor_printf(mon
, " set vlan %d",
3010 group
->set_vlan_id
& VLAN_VID_MASK
);
3013 if (group
->has_set_eth_src
) {
3016 monitor_printf(mon
, " set");
3018 monitor_printf(mon
, " src %s", group
->set_eth_src
);
3021 if (group
->has_set_eth_dst
) {
3024 monitor_printf(mon
, " set");
3026 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
3031 if (group
->has_ttl_check
&& group
->ttl_check
) {
3032 monitor_printf(mon
, " check TTL");
3035 if (group
->has_group_id
&& group
->group_id
) {
3036 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
3039 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
3040 monitor_printf(mon
, " pop vlan");
3043 if (group
->has_out_pport
) {
3044 monitor_printf(mon
, " out pport %d", group
->out_pport
);
3047 if (group
->has_group_ids
) {
3048 struct uint32List
*id
;
3050 monitor_printf(mon
, " groups [");
3051 for (id
= group
->group_ids
; id
; id
= id
->next
) {
3052 monitor_printf(mon
, "0x%08x", id
->value
);
3054 monitor_printf(mon
, ",");
3057 monitor_printf(mon
, "]");
3060 monitor_printf(mon
, "\n");
3063 qapi_free_RockerOfDpaGroupList(list
);
3066 void hmp_info_dump(Monitor
*mon
, const QDict
*qdict
)
3068 DumpQueryResult
*result
= qmp_query_dump(NULL
);
3070 assert(result
&& result
->status
< DUMP_STATUS__MAX
);
3071 monitor_printf(mon
, "Status: %s\n", DumpStatus_str(result
->status
));
3073 if (result
->status
== DUMP_STATUS_ACTIVE
) {
3075 assert(result
->total
!= 0);
3076 percent
= 100.0 * result
->completed
/ result
->total
;
3077 monitor_printf(mon
, "Finished: %.2f %%\n", percent
);
3080 qapi_free_DumpQueryResult(result
);
3083 void hmp_info_ramblock(Monitor
*mon
, const QDict
*qdict
)
3085 ram_block_dump(mon
);
3088 void hmp_hotpluggable_cpus(Monitor
*mon
, const QDict
*qdict
)
3091 HotpluggableCPUList
*l
= qmp_query_hotpluggable_cpus(&err
);
3092 HotpluggableCPUList
*saved
= l
;
3093 CpuInstanceProperties
*c
;
3096 hmp_handle_error(mon
, &err
);
3100 monitor_printf(mon
, "Hotpluggable CPUs:\n");
3102 monitor_printf(mon
, " type: \"%s\"\n", l
->value
->type
);
3103 monitor_printf(mon
, " vcpus_count: \"%" PRIu64
"\"\n",
3104 l
->value
->vcpus_count
);
3105 if (l
->value
->has_qom_path
) {
3106 monitor_printf(mon
, " qom_path: \"%s\"\n", l
->value
->qom_path
);
3109 c
= l
->value
->props
;
3110 monitor_printf(mon
, " CPUInstance Properties:\n");
3111 if (c
->has_node_id
) {
3112 monitor_printf(mon
, " node-id: \"%" PRIu64
"\"\n", c
->node_id
);
3114 if (c
->has_socket_id
) {
3115 monitor_printf(mon
, " socket-id: \"%" PRIu64
"\"\n", c
->socket_id
);
3117 if (c
->has_core_id
) {
3118 monitor_printf(mon
, " core-id: \"%" PRIu64
"\"\n", c
->core_id
);
3120 if (c
->has_thread_id
) {
3121 monitor_printf(mon
, " thread-id: \"%" PRIu64
"\"\n", c
->thread_id
);
3127 qapi_free_HotpluggableCPUList(saved
);
3130 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
3133 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
3135 monitor_printf(mon
, "%s\n", info
->guid
);
3137 hmp_handle_error(mon
, &err
);
3138 qapi_free_GuidInfo(info
);
3141 void hmp_info_memory_size_summary(Monitor
*mon
, const QDict
*qdict
)
3144 MemoryInfo
*info
= qmp_query_memory_size_summary(&err
);
3146 monitor_printf(mon
, "base memory: %" PRIu64
"\n",
3149 if (info
->has_plugged_memory
) {
3150 monitor_printf(mon
, "plugged memory: %" PRIu64
"\n",
3151 info
->plugged_memory
);
3154 qapi_free_MemoryInfo(info
);
3156 hmp_handle_error(mon
, &err
);