2 * Human Monitor Interface commands
4 * Copyright IBM, Corp. 2011
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
16 #include "qemu/osdep.h"
17 #include "monitor/hmp.h"
20 #include "chardev/char.h"
21 #include "sysemu/block-backend.h"
22 #include "sysemu/runstate.h"
23 #include "qemu/config-file.h"
24 #include "qemu/option.h"
25 #include "qemu/timer.h"
26 #include "qemu/sockets.h"
27 #include "qemu/help_option.h"
28 #include "monitor/monitor-internal.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-control.h"
36 #include "qapi/qapi-commands-machine.h"
37 #include "qapi/qapi-commands-migration.h"
38 #include "qapi/qapi-commands-misc.h"
39 #include "qapi/qapi-commands-net.h"
40 #include "qapi/qapi-commands-pci.h"
41 #include "qapi/qapi-commands-rocker.h"
42 #include "qapi/qapi-commands-run-state.h"
43 #include "qapi/qapi-commands-stats.h"
44 #include "qapi/qapi-commands-tpm.h"
45 #include "qapi/qapi-commands-ui.h"
46 #include "qapi/qapi-commands-virtio.h"
47 #include "qapi/qapi-visit-virtio.h"
48 #include "qapi/qapi-visit-net.h"
49 #include "qapi/qapi-visit-migration.h"
50 #include "qapi/qmp/qdict.h"
51 #include "qapi/qmp/qerror.h"
52 #include "qapi/string-input-visitor.h"
53 #include "qapi/string-output-visitor.h"
54 #include "qom/object_interfaces.h"
55 #include "ui/console.h"
56 #include "qemu/cutils.h"
57 #include "qemu/error-report.h"
58 #include "hw/core/cpu.h"
59 #include "hw/intc/intc.h"
60 #include "migration/snapshot.h"
61 #include "migration/misc.h"
64 #include <spice/enums.h>
67 bool hmp_handle_error(Monitor
*mon
, Error
*err
)
70 error_reportf_err(err
, "Error: ");
77 * Produce a strList from a comma separated list.
78 * A NULL or empty input string return NULL.
80 static strList
*strList_from_comma_list(const char *in
)
83 strList
**tail
= &res
;
86 char *comma
= strchr(in
, ',');
90 value
= g_strndup(in
, comma
- in
);
91 in
= comma
+ 1; /* skip the , */
96 QAPI_LIST_APPEND(tail
, value
);
102 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
106 info
= qmp_query_name(NULL
);
108 monitor_printf(mon
, "%s\n", info
->name
);
110 qapi_free_NameInfo(info
);
113 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
117 info
= qmp_query_version(NULL
);
119 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
120 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
123 qapi_free_VersionInfo(info
);
126 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
130 info
= qmp_query_kvm(NULL
);
131 monitor_printf(mon
, "kvm support: ");
133 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
135 monitor_printf(mon
, "not compiled\n");
138 qapi_free_KvmInfo(info
);
141 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
145 info
= qmp_query_status(NULL
);
147 monitor_printf(mon
, "VM status: %s%s",
148 info
->running
? "running" : "paused",
149 info
->singlestep
? " (single step mode)" : "");
151 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
152 monitor_printf(mon
, " (%s)", RunState_str(info
->status
));
155 monitor_printf(mon
, "\n");
157 qapi_free_StatusInfo(info
);
160 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
164 info
= qmp_query_uuid(NULL
);
165 monitor_printf(mon
, "%s\n", info
->UUID
);
166 qapi_free_UuidInfo(info
);
169 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
171 ChardevInfoList
*char_info
, *info
;
173 char_info
= qmp_query_chardev(NULL
);
174 for (info
= char_info
; info
; info
= info
->next
) {
175 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
176 info
->value
->filename
);
179 qapi_free_ChardevInfoList(char_info
);
182 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
184 MouseInfoList
*mice_list
, *mouse
;
186 mice_list
= qmp_query_mice(NULL
);
188 monitor_printf(mon
, "No mouse devices connected\n");
192 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
193 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
194 mouse
->value
->current
? '*' : ' ',
195 mouse
->value
->index
, mouse
->value
->name
,
196 mouse
->value
->absolute
? " (absolute)" : "");
199 qapi_free_MouseInfoList(mice_list
);
202 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
206 info
= qmp_query_migrate(NULL
);
208 migration_global_dump(mon
);
210 if (info
->blocked_reasons
) {
211 strList
*reasons
= info
->blocked_reasons
;
212 monitor_printf(mon
, "Outgoing migration blocked:\n");
214 monitor_printf(mon
, " %s\n", reasons
->value
);
215 reasons
= reasons
->next
;
219 if (info
->has_status
) {
220 monitor_printf(mon
, "Migration status: %s",
221 MigrationStatus_str(info
->status
));
222 if (info
->status
== MIGRATION_STATUS_FAILED
&& info
->error_desc
) {
223 monitor_printf(mon
, " (%s)\n", info
->error_desc
);
225 monitor_printf(mon
, "\n");
228 monitor_printf(mon
, "total time: %" PRIu64
" ms\n",
230 if (info
->has_expected_downtime
) {
231 monitor_printf(mon
, "expected downtime: %" PRIu64
" ms\n",
232 info
->expected_downtime
);
234 if (info
->has_downtime
) {
235 monitor_printf(mon
, "downtime: %" PRIu64
" ms\n",
238 if (info
->has_setup_time
) {
239 monitor_printf(mon
, "setup: %" PRIu64
" ms\n",
245 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
246 info
->ram
->transferred
>> 10);
247 monitor_printf(mon
, "throughput: %0.2f mbps\n",
249 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
250 info
->ram
->remaining
>> 10);
251 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
252 info
->ram
->total
>> 10);
253 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
254 info
->ram
->duplicate
);
255 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
257 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
259 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
260 info
->ram
->normal_bytes
>> 10);
261 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
262 info
->ram
->dirty_sync_count
);
263 monitor_printf(mon
, "page size: %" PRIu64
" kbytes\n",
264 info
->ram
->page_size
>> 10);
265 monitor_printf(mon
, "multifd bytes: %" PRIu64
" kbytes\n",
266 info
->ram
->multifd_bytes
>> 10);
267 monitor_printf(mon
, "pages-per-second: %" PRIu64
"\n",
268 info
->ram
->pages_per_second
);
270 if (info
->ram
->dirty_pages_rate
) {
271 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
272 info
->ram
->dirty_pages_rate
);
274 if (info
->ram
->postcopy_requests
) {
275 monitor_printf(mon
, "postcopy request count: %" PRIu64
"\n",
276 info
->ram
->postcopy_requests
);
278 if (info
->ram
->precopy_bytes
) {
279 monitor_printf(mon
, "precopy ram: %" PRIu64
" kbytes\n",
280 info
->ram
->precopy_bytes
>> 10);
282 if (info
->ram
->downtime_bytes
) {
283 monitor_printf(mon
, "downtime ram: %" PRIu64
" kbytes\n",
284 info
->ram
->downtime_bytes
>> 10);
286 if (info
->ram
->postcopy_bytes
) {
287 monitor_printf(mon
, "postcopy ram: %" PRIu64
" kbytes\n",
288 info
->ram
->postcopy_bytes
>> 10);
290 if (info
->ram
->dirty_sync_missed_zero_copy
) {
292 "Zero-copy-send fallbacks happened: %" PRIu64
" times\n",
293 info
->ram
->dirty_sync_missed_zero_copy
);
298 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
299 info
->disk
->transferred
>> 10);
300 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
301 info
->disk
->remaining
>> 10);
302 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
303 info
->disk
->total
>> 10);
306 if (info
->xbzrle_cache
) {
307 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
308 info
->xbzrle_cache
->cache_size
);
309 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
310 info
->xbzrle_cache
->bytes
>> 10);
311 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
312 info
->xbzrle_cache
->pages
);
313 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
" pages\n",
314 info
->xbzrle_cache
->cache_miss
);
315 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
316 info
->xbzrle_cache
->cache_miss_rate
);
317 monitor_printf(mon
, "xbzrle encoding rate: %0.2f\n",
318 info
->xbzrle_cache
->encoding_rate
);
319 monitor_printf(mon
, "xbzrle overflow: %" PRIu64
"\n",
320 info
->xbzrle_cache
->overflow
);
323 if (info
->compression
) {
324 monitor_printf(mon
, "compression pages: %" PRIu64
" pages\n",
325 info
->compression
->pages
);
326 monitor_printf(mon
, "compression busy: %" PRIu64
"\n",
327 info
->compression
->busy
);
328 monitor_printf(mon
, "compression busy rate: %0.2f\n",
329 info
->compression
->busy_rate
);
330 monitor_printf(mon
, "compressed size: %" PRIu64
" kbytes\n",
331 info
->compression
->compressed_size
>> 10);
332 monitor_printf(mon
, "compression rate: %0.2f\n",
333 info
->compression
->compression_rate
);
336 if (info
->has_cpu_throttle_percentage
) {
337 monitor_printf(mon
, "cpu throttle percentage: %" PRIu64
"\n",
338 info
->cpu_throttle_percentage
);
341 if (info
->has_postcopy_blocktime
) {
342 monitor_printf(mon
, "postcopy blocktime: %u\n",
343 info
->postcopy_blocktime
);
346 if (info
->has_postcopy_vcpu_blocktime
) {
349 v
= string_output_visitor_new(false, &str
);
350 visit_type_uint32List(v
, NULL
, &info
->postcopy_vcpu_blocktime
,
352 visit_complete(v
, &str
);
353 monitor_printf(mon
, "postcopy vcpu blocktime: %s\n", str
);
357 if (info
->has_socket_address
) {
358 SocketAddressList
*addr
;
360 monitor_printf(mon
, "socket address: [\n");
362 for (addr
= info
->socket_address
; addr
; addr
= addr
->next
) {
363 char *s
= socket_uri(addr
->value
);
364 monitor_printf(mon
, "\t%s\n", s
);
367 monitor_printf(mon
, "]\n");
371 monitor_printf(mon
, "vfio device transferred: %" PRIu64
" kbytes\n",
372 info
->vfio
->transferred
>> 10);
375 qapi_free_MigrationInfo(info
);
378 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
380 MigrationCapabilityStatusList
*caps
, *cap
;
382 caps
= qmp_query_migrate_capabilities(NULL
);
385 for (cap
= caps
; cap
; cap
= cap
->next
) {
386 monitor_printf(mon
, "%s: %s\n",
387 MigrationCapability_str(cap
->value
->capability
),
388 cap
->value
->state
? "on" : "off");
392 qapi_free_MigrationCapabilityStatusList(caps
);
395 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
397 MigrationParameters
*params
;
399 params
= qmp_query_migrate_parameters(NULL
);
402 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
403 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL
),
404 params
->announce_initial
);
405 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
406 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX
),
407 params
->announce_max
);
408 monitor_printf(mon
, "%s: %" PRIu64
"\n",
409 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS
),
410 params
->announce_rounds
);
411 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
412 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP
),
413 params
->announce_step
);
414 assert(params
->has_compress_level
);
415 monitor_printf(mon
, "%s: %u\n",
416 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL
),
417 params
->compress_level
);
418 assert(params
->has_compress_threads
);
419 monitor_printf(mon
, "%s: %u\n",
420 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS
),
421 params
->compress_threads
);
422 assert(params
->has_compress_wait_thread
);
423 monitor_printf(mon
, "%s: %s\n",
424 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD
),
425 params
->compress_wait_thread
? "on" : "off");
426 assert(params
->has_decompress_threads
);
427 monitor_printf(mon
, "%s: %u\n",
428 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS
),
429 params
->decompress_threads
);
430 assert(params
->has_throttle_trigger_threshold
);
431 monitor_printf(mon
, "%s: %u\n",
432 MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD
),
433 params
->throttle_trigger_threshold
);
434 assert(params
->has_cpu_throttle_initial
);
435 monitor_printf(mon
, "%s: %u\n",
436 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
),
437 params
->cpu_throttle_initial
);
438 assert(params
->has_cpu_throttle_increment
);
439 monitor_printf(mon
, "%s: %u\n",
440 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
),
441 params
->cpu_throttle_increment
);
442 assert(params
->has_cpu_throttle_tailslow
);
443 monitor_printf(mon
, "%s: %s\n",
444 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW
),
445 params
->cpu_throttle_tailslow
? "on" : "off");
446 assert(params
->has_max_cpu_throttle
);
447 monitor_printf(mon
, "%s: %u\n",
448 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE
),
449 params
->max_cpu_throttle
);
450 assert(params
->tls_creds
);
451 monitor_printf(mon
, "%s: '%s'\n",
452 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS
),
454 assert(params
->tls_hostname
);
455 monitor_printf(mon
, "%s: '%s'\n",
456 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME
),
457 params
->tls_hostname
);
458 assert(params
->has_max_bandwidth
);
459 monitor_printf(mon
, "%s: %" PRIu64
" bytes/second\n",
460 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH
),
461 params
->max_bandwidth
);
462 assert(params
->has_downtime_limit
);
463 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
464 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT
),
465 params
->downtime_limit
);
466 assert(params
->has_x_checkpoint_delay
);
467 monitor_printf(mon
, "%s: %u ms\n",
468 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
),
469 params
->x_checkpoint_delay
);
470 assert(params
->has_block_incremental
);
471 monitor_printf(mon
, "%s: %s\n",
472 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL
),
473 params
->block_incremental
? "on" : "off");
474 monitor_printf(mon
, "%s: %u\n",
475 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS
),
476 params
->multifd_channels
);
477 monitor_printf(mon
, "%s: %s\n",
478 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION
),
479 MultiFDCompression_str(params
->multifd_compression
));
480 monitor_printf(mon
, "%s: %" PRIu64
" bytes\n",
481 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
),
482 params
->xbzrle_cache_size
);
483 monitor_printf(mon
, "%s: %" PRIu64
"\n",
484 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH
),
485 params
->max_postcopy_bandwidth
);
486 monitor_printf(mon
, "%s: '%s'\n",
487 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ
),
490 if (params
->has_block_bitmap_mapping
) {
491 const BitmapMigrationNodeAliasList
*bmnal
;
493 monitor_printf(mon
, "%s:\n",
494 MigrationParameter_str(
495 MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING
));
497 for (bmnal
= params
->block_bitmap_mapping
;
501 const BitmapMigrationNodeAlias
*bmna
= bmnal
->value
;
502 const BitmapMigrationBitmapAliasList
*bmbal
;
504 monitor_printf(mon
, " '%s' -> '%s'\n",
505 bmna
->node_name
, bmna
->alias
);
507 for (bmbal
= bmna
->bitmaps
; bmbal
; bmbal
= bmbal
->next
) {
508 const BitmapMigrationBitmapAlias
*bmba
= bmbal
->value
;
510 monitor_printf(mon
, " '%s' -> '%s'\n",
511 bmba
->name
, bmba
->alias
);
517 qapi_free_MigrationParameters(params
);
522 /* Helper for hmp_info_vnc_clients, _servers */
523 static void hmp_info_VncBasicInfo(Monitor
*mon
, VncBasicInfo
*info
,
526 monitor_printf(mon
, " %s: %s:%s (%s%s)\n",
530 NetworkAddressFamily_str(info
->family
),
531 info
->websocket
? " (Websocket)" : "");
534 /* Helper displaying and auth and crypt info */
535 static void hmp_info_vnc_authcrypt(Monitor
*mon
, const char *indent
,
537 VncVencryptSubAuth
*vencrypt
)
539 monitor_printf(mon
, "%sAuth: %s (Sub: %s)\n", indent
,
540 VncPrimaryAuth_str(auth
),
541 vencrypt
? VncVencryptSubAuth_str(*vencrypt
) : "none");
544 static void hmp_info_vnc_clients(Monitor
*mon
, VncClientInfoList
*client
)
547 VncClientInfo
*cinfo
= client
->value
;
549 hmp_info_VncBasicInfo(mon
, qapi_VncClientInfo_base(cinfo
), "Client");
550 monitor_printf(mon
, " x509_dname: %s\n",
551 cinfo
->x509_dname
?: "none");
552 monitor_printf(mon
, " sasl_username: %s\n",
553 cinfo
->sasl_username
?: "none");
555 client
= client
->next
;
559 static void hmp_info_vnc_servers(Monitor
*mon
, VncServerInfo2List
*server
)
562 VncServerInfo2
*sinfo
= server
->value
;
563 hmp_info_VncBasicInfo(mon
, qapi_VncServerInfo2_base(sinfo
), "Server");
564 hmp_info_vnc_authcrypt(mon
, " ", sinfo
->auth
,
565 sinfo
->has_vencrypt
? &sinfo
->vencrypt
: NULL
);
566 server
= server
->next
;
570 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
572 VncInfo2List
*info2l
, *info2l_head
;
575 info2l
= qmp_query_vnc_servers(&err
);
576 info2l_head
= info2l
;
577 if (hmp_handle_error(mon
, err
)) {
581 monitor_printf(mon
, "None\n");
586 VncInfo2
*info
= info2l
->value
;
587 monitor_printf(mon
, "%s:\n", info
->id
);
588 hmp_info_vnc_servers(mon
, info
->server
);
589 hmp_info_vnc_clients(mon
, info
->clients
);
591 /* The server entry displays its auth, we only
592 * need to display in the case of 'reverse' connections
593 * where there's no server.
595 hmp_info_vnc_authcrypt(mon
, " ", info
->auth
,
596 info
->has_vencrypt
? &info
->vencrypt
: NULL
);
599 monitor_printf(mon
, " Display: %s\n", info
->display
);
601 info2l
= info2l
->next
;
604 qapi_free_VncInfo2List(info2l_head
);
610 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
612 SpiceChannelList
*chan
;
614 const char *channel_name
;
615 const char * const channel_names
[] = {
616 [SPICE_CHANNEL_MAIN
] = "main",
617 [SPICE_CHANNEL_DISPLAY
] = "display",
618 [SPICE_CHANNEL_INPUTS
] = "inputs",
619 [SPICE_CHANNEL_CURSOR
] = "cursor",
620 [SPICE_CHANNEL_PLAYBACK
] = "playback",
621 [SPICE_CHANNEL_RECORD
] = "record",
622 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
623 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
624 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
625 [SPICE_CHANNEL_PORT
] = "port",
627 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
628 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
629 * as quick fix for build failures with older versions. */
630 [SPICE_CHANNEL_WEBDAV
] = "webdav",
634 info
= qmp_query_spice(NULL
);
636 if (!info
->enabled
) {
637 monitor_printf(mon
, "Server: disabled\n");
641 monitor_printf(mon
, "Server:\n");
642 if (info
->has_port
) {
643 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
644 info
->host
, info
->port
);
646 if (info
->has_tls_port
) {
647 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
648 info
->host
, info
->tls_port
);
650 monitor_printf(mon
, " migrated: %s\n",
651 info
->migrated
? "true" : "false");
652 monitor_printf(mon
, " auth: %s\n", info
->auth
);
653 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
654 monitor_printf(mon
, " mouse-mode: %s\n",
655 SpiceQueryMouseMode_str(info
->mouse_mode
));
657 if (!info
->has_channels
|| info
->channels
== NULL
) {
658 monitor_printf(mon
, "Channels: none\n");
660 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
661 monitor_printf(mon
, "Channel:\n");
662 monitor_printf(mon
, " address: %s:%s%s\n",
663 chan
->value
->host
, chan
->value
->port
,
664 chan
->value
->tls
? " [tls]" : "");
665 monitor_printf(mon
, " session: %" PRId64
"\n",
666 chan
->value
->connection_id
);
667 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
668 chan
->value
->channel_type
, chan
->value
->channel_id
);
670 channel_name
= "unknown";
671 if (chan
->value
->channel_type
> 0 &&
672 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
673 channel_names
[chan
->value
->channel_type
]) {
674 channel_name
= channel_names
[chan
->value
->channel_type
];
677 monitor_printf(mon
, " channel name: %s\n", channel_name
);
682 qapi_free_SpiceInfo(info
);
686 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
691 info
= qmp_query_balloon(&err
);
692 if (hmp_handle_error(mon
, err
)) {
696 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
698 qapi_free_BalloonInfo(info
);
701 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
703 PciMemoryRegionList
*region
;
705 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
706 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
707 dev
->slot
, dev
->function
);
708 monitor_printf(mon
, " ");
710 if (dev
->class_info
->desc
) {
711 monitor_puts(mon
, dev
->class_info
->desc
);
713 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
716 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
717 dev
->id
->vendor
, dev
->id
->device
);
718 if (dev
->id
->has_subsystem_vendor
&& dev
->id
->has_subsystem
) {
719 monitor_printf(mon
, " PCI subsystem %04" PRIx64
":%04" PRIx64
"\n",
720 dev
->id
->subsystem_vendor
, dev
->id
->subsystem
);
724 monitor_printf(mon
, " IRQ %" PRId64
", pin %c\n",
725 dev
->irq
, (char)('A' + dev
->irq_pin
- 1));
728 if (dev
->pci_bridge
) {
729 monitor_printf(mon
, " BUS %" PRId64
".\n",
730 dev
->pci_bridge
->bus
->number
);
731 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
732 dev
->pci_bridge
->bus
->secondary
);
733 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
734 dev
->pci_bridge
->bus
->subordinate
);
736 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
737 dev
->pci_bridge
->bus
->io_range
->base
,
738 dev
->pci_bridge
->bus
->io_range
->limit
);
741 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
742 dev
->pci_bridge
->bus
->memory_range
->base
,
743 dev
->pci_bridge
->bus
->memory_range
->limit
);
745 monitor_printf(mon
, " prefetchable memory range "
746 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
747 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
748 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
751 for (region
= dev
->regions
; region
; region
= region
->next
) {
754 addr
= region
->value
->address
;
755 size
= region
->value
->size
;
757 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
759 if (!strcmp(region
->value
->type
, "io")) {
760 monitor_printf(mon
, "I/O at 0x%04" PRIx64
761 " [0x%04" PRIx64
"].\n",
762 addr
, addr
+ size
- 1);
764 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
765 " [0x%08" PRIx64
"].\n",
766 region
->value
->mem_type_64
? 64 : 32,
767 region
->value
->prefetch
? " prefetchable" : "",
768 addr
, addr
+ size
- 1);
772 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
774 if (dev
->pci_bridge
) {
775 if (dev
->pci_bridge
->has_devices
) {
776 PciDeviceInfoList
*cdev
;
777 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
778 hmp_info_pci_device(mon
, cdev
->value
);
784 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
786 InterruptStatsProvider
*intc
;
787 InterruptStatsProviderClass
*k
;
788 Monitor
*mon
= opaque
;
790 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
791 intc
= INTERRUPT_STATS_PROVIDER(obj
);
792 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
794 k
->print_info(intc
, mon
);
796 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
797 object_get_typename(obj
));
804 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
806 object_child_foreach_recursive(object_get_root(),
807 hmp_info_pic_foreach
, mon
);
810 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
812 PciInfoList
*info_list
, *info
;
815 info_list
= qmp_query_pci(&err
);
817 monitor_printf(mon
, "PCI devices not supported\n");
822 for (info
= info_list
; info
; info
= info
->next
) {
823 PciDeviceInfoList
*dev
;
825 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
826 hmp_info_pci_device(mon
, dev
->value
);
830 qapi_free_PciInfoList(info_list
);
833 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
836 TPMInfoList
*info_list
, *info
;
839 TPMPassthroughOptions
*tpo
;
840 TPMEmulatorOptions
*teo
;
842 info_list
= qmp_query_tpm(&err
);
844 monitor_printf(mon
, "TPM device not supported\n");
850 monitor_printf(mon
, "TPM device:\n");
853 for (info
= info_list
; info
; info
= info
->next
) {
854 TPMInfo
*ti
= info
->value
;
855 monitor_printf(mon
, " tpm%d: model=%s\n",
856 c
, TpmModel_str(ti
->model
));
858 monitor_printf(mon
, " \\ %s: type=%s",
859 ti
->id
, TpmType_str(ti
->options
->type
));
861 switch (ti
->options
->type
) {
862 case TPM_TYPE_PASSTHROUGH
:
863 tpo
= ti
->options
->u
.passthrough
.data
;
864 monitor_printf(mon
, "%s%s%s%s",
865 tpo
->path
? ",path=" : "",
867 tpo
->cancel_path
? ",cancel-path=" : "",
868 tpo
->cancel_path
?: "");
870 case TPM_TYPE_EMULATOR
:
871 teo
= ti
->options
->u
.emulator
.data
;
872 monitor_printf(mon
, ",chardev=%s", teo
->chardev
);
877 monitor_printf(mon
, "\n");
880 qapi_free_TPMInfoList(info_list
);
882 monitor_printf(mon
, "TPM device not supported\n");
883 #endif /* CONFIG_TPM */
886 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
888 monitor_suspend(mon
);
892 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
897 void hmp_sync_profile(Monitor
*mon
, const QDict
*qdict
)
899 const char *op
= qdict_get_try_str(qdict
, "op");
902 bool on
= qsp_is_enabled();
904 monitor_printf(mon
, "sync-profile is %s\n", on
? "on" : "off");
907 if (!strcmp(op
, "on")) {
909 } else if (!strcmp(op
, "off")) {
911 } else if (!strcmp(op
, "reset")) {
916 error_setg(&err
, QERR_INVALID_PARAMETER
, op
);
917 hmp_handle_error(mon
, err
);
921 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
923 qmp_system_reset(NULL
);
926 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
928 qmp_system_powerdown(NULL
);
931 void hmp_exit_preconfig(Monitor
*mon
, const QDict
*qdict
)
935 qmp_x_exit_preconfig(&err
);
936 hmp_handle_error(mon
, err
);
939 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
943 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
944 use it are converted to the QAPI */
945 cpu_index
= qdict_get_int(qdict
, "index");
946 if (monitor_set_cpu(mon
, cpu_index
) < 0) {
947 monitor_printf(mon
, "invalid CPU index\n");
951 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
953 uint32_t size
= qdict_get_int(qdict
, "size");
954 const char *filename
= qdict_get_str(qdict
, "filename");
955 uint64_t addr
= qdict_get_int(qdict
, "val");
957 int cpu_index
= monitor_get_cpu_index(mon
);
960 monitor_printf(mon
, "No CPU available\n");
964 qmp_memsave(addr
, size
, filename
, true, cpu_index
, &err
);
965 hmp_handle_error(mon
, err
);
968 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
970 uint32_t size
= qdict_get_int(qdict
, "size");
971 const char *filename
= qdict_get_str(qdict
, "filename");
972 uint64_t addr
= qdict_get_int(qdict
, "val");
975 qmp_pmemsave(addr
, size
, filename
, &err
);
976 hmp_handle_error(mon
, err
);
979 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
981 const char *chardev
= qdict_get_str(qdict
, "device");
982 const char *data
= qdict_get_str(qdict
, "data");
985 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
987 hmp_handle_error(mon
, err
);
990 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
992 uint32_t size
= qdict_get_int(qdict
, "size");
993 const char *chardev
= qdict_get_str(qdict
, "device");
998 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
999 if (hmp_handle_error(mon
, err
)) {
1003 for (i
= 0; data
[i
]; i
++) {
1004 unsigned char ch
= data
[i
];
1007 monitor_printf(mon
, "\\\\");
1008 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
1009 monitor_printf(mon
, "\\u%04X", ch
);
1011 monitor_printf(mon
, "%c", ch
);
1015 monitor_printf(mon
, "\n");
1019 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
1024 hmp_handle_error(mon
, err
);
1027 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
1031 qmp_system_wakeup(&err
);
1032 hmp_handle_error(mon
, err
);
1035 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
1039 qmp_inject_nmi(&err
);
1040 hmp_handle_error(mon
, err
);
1043 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
1045 const char *name
= qdict_get_str(qdict
, "name");
1046 bool up
= qdict_get_bool(qdict
, "up");
1049 qmp_set_link(name
, up
, &err
);
1050 hmp_handle_error(mon
, err
);
1053 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1055 int64_t value
= qdict_get_int(qdict
, "value");
1058 qmp_balloon(value
, &err
);
1059 hmp_handle_error(mon
, err
);
1062 void hmp_loadvm(Monitor
*mon
, const QDict
*qdict
)
1064 int saved_vm_running
= runstate_is_running();
1065 const char *name
= qdict_get_str(qdict
, "name");
1068 vm_stop(RUN_STATE_RESTORE_VM
);
1070 if (load_snapshot(name
, NULL
, false, NULL
, &err
) && saved_vm_running
) {
1073 hmp_handle_error(mon
, err
);
1076 void hmp_savevm(Monitor
*mon
, const QDict
*qdict
)
1080 save_snapshot(qdict_get_try_str(qdict
, "name"),
1081 true, NULL
, false, NULL
, &err
);
1082 hmp_handle_error(mon
, err
);
1085 void hmp_delvm(Monitor
*mon
, const QDict
*qdict
)
1088 const char *name
= qdict_get_str(qdict
, "name");
1090 delete_snapshot(name
, false, NULL
, &err
);
1091 hmp_handle_error(mon
, err
);
1094 void hmp_announce_self(Monitor
*mon
, const QDict
*qdict
)
1096 const char *interfaces_str
= qdict_get_try_str(qdict
, "interfaces");
1097 const char *id
= qdict_get_try_str(qdict
, "id");
1098 AnnounceParameters
*params
= QAPI_CLONE(AnnounceParameters
,
1099 migrate_announce_params());
1101 qapi_free_strList(params
->interfaces
);
1102 params
->interfaces
= strList_from_comma_list(interfaces_str
);
1103 params
->has_interfaces
= params
->interfaces
!= NULL
;
1104 params
->id
= g_strdup(id
);
1105 qmp_announce_self(params
, NULL
);
1106 qapi_free_AnnounceParameters(params
);
1109 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1111 qmp_migrate_cancel(NULL
);
1114 void hmp_migrate_continue(Monitor
*mon
, const QDict
*qdict
)
1117 const char *state
= qdict_get_str(qdict
, "state");
1118 int val
= qapi_enum_parse(&MigrationStatus_lookup
, state
, -1, &err
);
1121 qmp_migrate_continue(val
, &err
);
1124 hmp_handle_error(mon
, err
);
1127 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1130 const char *uri
= qdict_get_str(qdict
, "uri");
1132 qmp_migrate_incoming(uri
, &err
);
1134 hmp_handle_error(mon
, err
);
1137 void hmp_migrate_recover(Monitor
*mon
, const QDict
*qdict
)
1140 const char *uri
= qdict_get_str(qdict
, "uri");
1142 qmp_migrate_recover(uri
, &err
);
1144 hmp_handle_error(mon
, err
);
1147 void hmp_migrate_pause(Monitor
*mon
, const QDict
*qdict
)
1151 qmp_migrate_pause(&err
);
1153 hmp_handle_error(mon
, err
);
1157 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1159 const char *cap
= qdict_get_str(qdict
, "capability");
1160 bool state
= qdict_get_bool(qdict
, "state");
1162 MigrationCapabilityStatusList
*caps
= NULL
;
1163 MigrationCapabilityStatus
*value
;
1166 val
= qapi_enum_parse(&MigrationCapability_lookup
, cap
, -1, &err
);
1171 value
= g_malloc0(sizeof(*value
));
1172 value
->capability
= val
;
1173 value
->state
= state
;
1174 QAPI_LIST_PREPEND(caps
, value
);
1175 qmp_migrate_set_capabilities(caps
, &err
);
1176 qapi_free_MigrationCapabilityStatusList(caps
);
1179 hmp_handle_error(mon
, err
);
1182 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1184 const char *param
= qdict_get_str(qdict
, "parameter");
1185 const char *valuestr
= qdict_get_str(qdict
, "value");
1186 Visitor
*v
= string_input_visitor_new(valuestr
);
1187 MigrateSetParameters
*p
= g_new0(MigrateSetParameters
, 1);
1188 uint64_t valuebw
= 0;
1189 uint64_t cache_size
;
1193 val
= qapi_enum_parse(&MigrationParameter_lookup
, param
, -1, &err
);
1199 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1200 p
->has_compress_level
= true;
1201 visit_type_uint8(v
, param
, &p
->compress_level
, &err
);
1203 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1204 p
->has_compress_threads
= true;
1205 visit_type_uint8(v
, param
, &p
->compress_threads
, &err
);
1207 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD
:
1208 p
->has_compress_wait_thread
= true;
1209 visit_type_bool(v
, param
, &p
->compress_wait_thread
, &err
);
1211 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1212 p
->has_decompress_threads
= true;
1213 visit_type_uint8(v
, param
, &p
->decompress_threads
, &err
);
1215 case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD
:
1216 p
->has_throttle_trigger_threshold
= true;
1217 visit_type_uint8(v
, param
, &p
->throttle_trigger_threshold
, &err
);
1219 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1220 p
->has_cpu_throttle_initial
= true;
1221 visit_type_uint8(v
, param
, &p
->cpu_throttle_initial
, &err
);
1223 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1224 p
->has_cpu_throttle_increment
= true;
1225 visit_type_uint8(v
, param
, &p
->cpu_throttle_increment
, &err
);
1227 case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW
:
1228 p
->has_cpu_throttle_tailslow
= true;
1229 visit_type_bool(v
, param
, &p
->cpu_throttle_tailslow
, &err
);
1231 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE
:
1232 p
->has_max_cpu_throttle
= true;
1233 visit_type_uint8(v
, param
, &p
->max_cpu_throttle
, &err
);
1235 case MIGRATION_PARAMETER_TLS_CREDS
:
1236 p
->tls_creds
= g_new0(StrOrNull
, 1);
1237 p
->tls_creds
->type
= QTYPE_QSTRING
;
1238 visit_type_str(v
, param
, &p
->tls_creds
->u
.s
, &err
);
1240 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1241 p
->tls_hostname
= g_new0(StrOrNull
, 1);
1242 p
->tls_hostname
->type
= QTYPE_QSTRING
;
1243 visit_type_str(v
, param
, &p
->tls_hostname
->u
.s
, &err
);
1245 case MIGRATION_PARAMETER_TLS_AUTHZ
:
1246 p
->tls_authz
= g_new0(StrOrNull
, 1);
1247 p
->tls_authz
->type
= QTYPE_QSTRING
;
1248 visit_type_str(v
, param
, &p
->tls_authz
->u
.s
, &err
);
1250 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1251 p
->has_max_bandwidth
= true;
1253 * Can't use visit_type_size() here, because it
1254 * defaults to Bytes rather than Mebibytes.
1256 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
1257 if (ret
< 0 || valuebw
> INT64_MAX
1258 || (size_t)valuebw
!= valuebw
) {
1259 error_setg(&err
, "Invalid size %s", valuestr
);
1262 p
->max_bandwidth
= valuebw
;
1264 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1265 p
->has_downtime_limit
= true;
1266 visit_type_size(v
, param
, &p
->downtime_limit
, &err
);
1268 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
1269 p
->has_x_checkpoint_delay
= true;
1270 visit_type_uint32(v
, param
, &p
->x_checkpoint_delay
, &err
);
1272 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL
:
1273 p
->has_block_incremental
= true;
1274 visit_type_bool(v
, param
, &p
->block_incremental
, &err
);
1276 case MIGRATION_PARAMETER_MULTIFD_CHANNELS
:
1277 p
->has_multifd_channels
= true;
1278 visit_type_uint8(v
, param
, &p
->multifd_channels
, &err
);
1280 case MIGRATION_PARAMETER_MULTIFD_COMPRESSION
:
1281 p
->has_multifd_compression
= true;
1282 visit_type_MultiFDCompression(v
, param
, &p
->multifd_compression
,
1285 case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL
:
1286 p
->has_multifd_zlib_level
= true;
1287 visit_type_uint8(v
, param
, &p
->multifd_zlib_level
, &err
);
1289 case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL
:
1290 p
->has_multifd_zstd_level
= true;
1291 visit_type_uint8(v
, param
, &p
->multifd_zstd_level
, &err
);
1293 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
:
1294 p
->has_xbzrle_cache_size
= true;
1295 if (!visit_type_size(v
, param
, &cache_size
, &err
)) {
1298 if (cache_size
> INT64_MAX
|| (size_t)cache_size
!= cache_size
) {
1299 error_setg(&err
, "Invalid size %s", valuestr
);
1302 p
->xbzrle_cache_size
= cache_size
;
1304 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH
:
1305 p
->has_max_postcopy_bandwidth
= true;
1306 visit_type_size(v
, param
, &p
->max_postcopy_bandwidth
, &err
);
1308 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL
:
1309 p
->has_announce_initial
= true;
1310 visit_type_size(v
, param
, &p
->announce_initial
, &err
);
1312 case MIGRATION_PARAMETER_ANNOUNCE_MAX
:
1313 p
->has_announce_max
= true;
1314 visit_type_size(v
, param
, &p
->announce_max
, &err
);
1316 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS
:
1317 p
->has_announce_rounds
= true;
1318 visit_type_size(v
, param
, &p
->announce_rounds
, &err
);
1320 case MIGRATION_PARAMETER_ANNOUNCE_STEP
:
1321 p
->has_announce_step
= true;
1322 visit_type_size(v
, param
, &p
->announce_step
, &err
);
1324 case MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING
:
1325 error_setg(&err
, "The block-bitmap-mapping parameter can only be set "
1336 qmp_migrate_set_parameters(p
, &err
);
1339 qapi_free_MigrateSetParameters(p
);
1341 hmp_handle_error(mon
, err
);
1344 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1347 const char *protocol
= qdict_get_str(qdict
, "protocol");
1348 const char *hostname
= qdict_get_str(qdict
, "hostname");
1349 bool has_port
= qdict_haskey(qdict
, "port");
1350 int port
= qdict_get_try_int(qdict
, "port", -1);
1351 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1352 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1353 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1355 qmp_client_migrate_info(protocol
, hostname
,
1356 has_port
, port
, has_tls_port
, tls_port
,
1357 cert_subject
, &err
);
1358 hmp_handle_error(mon
, err
);
1361 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1364 qmp_migrate_start_postcopy(&err
);
1365 hmp_handle_error(mon
, err
);
1368 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1372 qmp_x_colo_lost_heartbeat(&err
);
1373 hmp_handle_error(mon
, err
);
1376 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1378 const char *protocol
= qdict_get_str(qdict
, "protocol");
1379 const char *password
= qdict_get_str(qdict
, "password");
1380 const char *display
= qdict_get_try_str(qdict
, "display");
1381 const char *connected
= qdict_get_try_str(qdict
, "connected");
1384 SetPasswordOptions opts
= {
1385 .password
= (char *)password
,
1386 .has_connected
= !!connected
,
1389 opts
.connected
= qapi_enum_parse(&SetPasswordAction_lookup
, connected
,
1390 SET_PASSWORD_ACTION_KEEP
, &err
);
1395 opts
.protocol
= qapi_enum_parse(&DisplayProtocol_lookup
, protocol
,
1396 DISPLAY_PROTOCOL_VNC
, &err
);
1401 if (opts
.protocol
== DISPLAY_PROTOCOL_VNC
) {
1402 opts
.u
.vnc
.display
= (char *)display
;
1405 qmp_set_password(&opts
, &err
);
1408 hmp_handle_error(mon
, err
);
1411 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1413 const char *protocol
= qdict_get_str(qdict
, "protocol");
1414 const char *whenstr
= qdict_get_str(qdict
, "time");
1415 const char *display
= qdict_get_try_str(qdict
, "display");
1418 ExpirePasswordOptions opts
= {
1419 .time
= (char *)whenstr
,
1422 opts
.protocol
= qapi_enum_parse(&DisplayProtocol_lookup
, protocol
,
1423 DISPLAY_PROTOCOL_VNC
, &err
);
1428 if (opts
.protocol
== DISPLAY_PROTOCOL_VNC
) {
1429 opts
.u
.vnc
.display
= (char *)display
;
1432 qmp_expire_password(&opts
, &err
);
1435 hmp_handle_error(mon
, err
);
1440 static void hmp_change_read_arg(void *opaque
, const char *password
,
1441 void *readline_opaque
)
1443 qmp_change_vnc_password(password
, NULL
);
1444 monitor_read_command(opaque
, 1);
1448 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1450 const char *device
= qdict_get_str(qdict
, "device");
1451 const char *target
= qdict_get_str(qdict
, "target");
1452 const char *arg
= qdict_get_try_str(qdict
, "arg");
1453 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1454 bool force
= qdict_get_try_bool(qdict
, "force", false);
1455 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1459 if (strcmp(device
, "vnc") == 0) {
1462 "Parameter 'read-only-mode' is invalid for VNC\n");
1465 if (strcmp(target
, "passwd") == 0 ||
1466 strcmp(target
, "password") == 0) {
1468 MonitorHMP
*hmp_mon
= container_of(mon
, MonitorHMP
, common
);
1469 monitor_read_password(hmp_mon
, hmp_change_read_arg
, NULL
);
1472 qmp_change_vnc_password(arg
, &err
);
1475 monitor_printf(mon
, "Expected 'password' after 'vnc'\n");
1482 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup
,
1484 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1490 qmp_blockdev_change_medium(device
, NULL
, target
, arg
, true, force
,
1491 !!read_only
, read_only_mode
,
1496 hmp_handle_error(mon
, err
);
1499 typedef struct HMPMigrationStatus
{
1502 bool is_block_migration
;
1503 } HMPMigrationStatus
;
1505 static void hmp_migrate_status_cb(void *opaque
)
1507 HMPMigrationStatus
*status
= opaque
;
1508 MigrationInfo
*info
;
1510 info
= qmp_query_migrate(NULL
);
1511 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1512 info
->status
== MIGRATION_STATUS_SETUP
) {
1516 if (info
->disk
->remaining
) {
1517 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1522 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1523 monitor_flush(status
->mon
);
1526 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1528 if (status
->is_block_migration
) {
1529 monitor_printf(status
->mon
, "\n");
1531 if (info
->error_desc
) {
1532 error_report("%s", info
->error_desc
);
1534 monitor_resume(status
->mon
);
1535 timer_free(status
->timer
);
1539 qapi_free_MigrationInfo(info
);
1542 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1544 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1545 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1546 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1547 bool resume
= qdict_get_try_bool(qdict
, "resume", false);
1548 const char *uri
= qdict_get_str(qdict
, "uri");
1551 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
,
1552 false, false, true, resume
, &err
);
1553 if (hmp_handle_error(mon
, err
)) {
1558 HMPMigrationStatus
*status
;
1560 if (monitor_suspend(mon
) < 0) {
1561 monitor_printf(mon
, "terminal does not allow synchronous "
1562 "migration, continuing detached\n");
1566 status
= g_malloc0(sizeof(*status
));
1568 status
->is_block_migration
= blk
|| inc
;
1569 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1571 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1575 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1579 const char *type
= qdict_get_try_str(qdict
, "type");
1581 if (type
&& is_help_option(type
)) {
1585 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1590 netdev_add(opts
, &err
);
1592 qemu_opts_del(opts
);
1596 hmp_handle_error(mon
, err
);
1599 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1601 const char *id
= qdict_get_str(qdict
, "id");
1604 qmp_netdev_del(id
, &err
);
1605 hmp_handle_error(mon
, err
);
1608 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
1610 const char *options
= qdict_get_str(qdict
, "object");
1613 user_creatable_add_from_str(options
, &err
);
1614 hmp_handle_error(mon
, err
);
1617 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1619 const char *fdname
= qdict_get_str(qdict
, "fdname");
1622 qmp_getfd(fdname
, &err
);
1623 hmp_handle_error(mon
, err
);
1626 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1628 const char *fdname
= qdict_get_str(qdict
, "fdname");
1631 qmp_closefd(fdname
, &err
);
1632 hmp_handle_error(mon
, err
);
1635 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
1637 const char *keys
= qdict_get_str(qdict
, "keys");
1639 KeyValueList
*head
= NULL
, **tail
= &head
;
1640 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1641 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1643 const char *separator
;
1647 separator
= qemu_strchrnul(keys
, '-');
1648 keyname_len
= separator
- keys
;
1650 /* Be compatible with old interface, convert user inputted "<" */
1651 if (keys
[0] == '<' && keyname_len
== 1) {
1656 v
= g_malloc0(sizeof(*v
));
1658 if (strstart(keys
, "0x", NULL
)) {
1660 int value
= strtoul(keys
, &endp
, 0);
1661 assert(endp
<= keys
+ keyname_len
);
1662 if (endp
!= keys
+ keyname_len
) {
1665 v
->type
= KEY_VALUE_KIND_NUMBER
;
1666 v
->u
.number
.data
= value
;
1668 int idx
= index_from_key(keys
, keyname_len
);
1669 if (idx
== Q_KEY_CODE__MAX
) {
1672 v
->type
= KEY_VALUE_KIND_QCODE
;
1673 v
->u
.qcode
.data
= idx
;
1675 QAPI_LIST_APPEND(tail
, v
);
1681 keys
= separator
+ 1;
1684 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1685 hmp_handle_error(mon
, err
);
1688 qapi_free_KeyValue(v
);
1689 qapi_free_KeyValueList(head
);
1693 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
1698 hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
1700 const char *filename
= qdict_get_str(qdict
, "filename");
1701 const char *id
= qdict_get_try_str(qdict
, "device");
1702 int64_t head
= qdict_get_try_int(qdict
, "head", 0);
1703 const char *input_format
= qdict_get_try_str(qdict
, "format");
1707 format
= qapi_enum_parse(&ImageFormat_lookup
, input_format
,
1708 IMAGE_FORMAT_PPM
, &err
);
1713 qmp_screendump(filename
, id
, id
!= NULL
, head
,
1714 input_format
!= NULL
, format
, &err
);
1716 hmp_handle_error(mon
, err
);
1719 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
1721 const char *args
= qdict_get_str(qdict
, "args");
1725 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
1727 error_setg(&err
, "Parsing chardev args failed");
1729 qemu_chr_new_from_opts(opts
, NULL
, &err
);
1730 qemu_opts_del(opts
);
1732 hmp_handle_error(mon
, err
);
1735 void hmp_chardev_change(Monitor
*mon
, const QDict
*qdict
)
1737 const char *args
= qdict_get_str(qdict
, "args");
1740 ChardevBackend
*backend
= NULL
;
1741 ChardevReturn
*ret
= NULL
;
1742 QemuOpts
*opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
,
1745 error_setg(&err
, "Parsing chardev args failed");
1749 id
= qdict_get_str(qdict
, "id");
1750 if (qemu_opts_id(opts
)) {
1751 error_setg(&err
, "Unexpected 'id' parameter");
1755 backend
= qemu_chr_parse_opts(opts
, &err
);
1760 ret
= qmp_chardev_change(id
, backend
, &err
);
1763 qapi_free_ChardevReturn(ret
);
1764 qapi_free_ChardevBackend(backend
);
1765 qemu_opts_del(opts
);
1766 hmp_handle_error(mon
, err
);
1769 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
1771 Error
*local_err
= NULL
;
1773 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
1774 hmp_handle_error(mon
, local_err
);
1777 void hmp_chardev_send_break(Monitor
*mon
, const QDict
*qdict
)
1779 Error
*local_err
= NULL
;
1781 qmp_chardev_send_break(qdict_get_str(qdict
, "id"), &local_err
);
1782 hmp_handle_error(mon
, local_err
);
1785 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
1787 const char *id
= qdict_get_str(qdict
, "id");
1790 user_creatable_del(id
, &err
);
1791 hmp_handle_error(mon
, err
);
1794 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
1797 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
1798 MemoryDeviceInfoList
*info
;
1799 VirtioPMEMDeviceInfo
*vpi
;
1800 VirtioMEMDeviceInfo
*vmi
;
1801 MemoryDeviceInfo
*value
;
1802 PCDIMMDeviceInfo
*di
;
1803 SgxEPCDeviceInfo
*se
;
1805 for (info
= info_list
; info
; info
= info
->next
) {
1806 value
= info
->value
;
1809 switch (value
->type
) {
1810 case MEMORY_DEVICE_INFO_KIND_DIMM
:
1811 case MEMORY_DEVICE_INFO_KIND_NVDIMM
:
1812 di
= value
->type
== MEMORY_DEVICE_INFO_KIND_DIMM
?
1813 value
->u
.dimm
.data
: value
->u
.nvdimm
.data
;
1814 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1815 MemoryDeviceInfoKind_str(value
->type
),
1816 di
->id
? di
->id
: "");
1817 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
1818 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
1819 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
1820 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
1821 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
1822 monitor_printf(mon
, " hotplugged: %s\n",
1823 di
->hotplugged
? "true" : "false");
1824 monitor_printf(mon
, " hotpluggable: %s\n",
1825 di
->hotpluggable
? "true" : "false");
1827 case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM
:
1828 vpi
= value
->u
.virtio_pmem
.data
;
1829 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1830 MemoryDeviceInfoKind_str(value
->type
),
1831 vpi
->id
? vpi
->id
: "");
1832 monitor_printf(mon
, " memaddr: 0x%" PRIx64
"\n", vpi
->memaddr
);
1833 monitor_printf(mon
, " size: %" PRIu64
"\n", vpi
->size
);
1834 monitor_printf(mon
, " memdev: %s\n", vpi
->memdev
);
1836 case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM
:
1837 vmi
= value
->u
.virtio_mem
.data
;
1838 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1839 MemoryDeviceInfoKind_str(value
->type
),
1840 vmi
->id
? vmi
->id
: "");
1841 monitor_printf(mon
, " memaddr: 0x%" PRIx64
"\n", vmi
->memaddr
);
1842 monitor_printf(mon
, " node: %" PRId64
"\n", vmi
->node
);
1843 monitor_printf(mon
, " requested-size: %" PRIu64
"\n",
1844 vmi
->requested_size
);
1845 monitor_printf(mon
, " size: %" PRIu64
"\n", vmi
->size
);
1846 monitor_printf(mon
, " max-size: %" PRIu64
"\n", vmi
->max_size
);
1847 monitor_printf(mon
, " block-size: %" PRIu64
"\n",
1849 monitor_printf(mon
, " memdev: %s\n", vmi
->memdev
);
1851 case MEMORY_DEVICE_INFO_KIND_SGX_EPC
:
1852 se
= value
->u
.sgx_epc
.data
;
1853 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1854 MemoryDeviceInfoKind_str(value
->type
),
1855 se
->id
? se
->id
: "");
1856 monitor_printf(mon
, " memaddr: 0x%" PRIx64
"\n", se
->memaddr
);
1857 monitor_printf(mon
, " size: %" PRIu64
"\n", se
->size
);
1858 monitor_printf(mon
, " node: %" PRId64
"\n", se
->node
);
1859 monitor_printf(mon
, " memdev: %s\n", se
->memdev
);
1862 g_assert_not_reached();
1867 qapi_free_MemoryDeviceInfoList(info_list
);
1868 hmp_handle_error(mon
, err
);
1871 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
1873 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
1874 IOThreadInfoList
*info
;
1875 IOThreadInfo
*value
;
1877 for (info
= info_list
; info
; info
= info
->next
) {
1878 value
= info
->value
;
1879 monitor_printf(mon
, "%s:\n", value
->id
);
1880 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
1881 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
1882 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
1883 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
1884 monitor_printf(mon
, " aio-max-batch=%" PRId64
"\n",
1885 value
->aio_max_batch
);
1888 qapi_free_IOThreadInfoList(info_list
);
1891 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
1893 const char *name
= qdict_get_str(qdict
, "name");
1894 RockerSwitch
*rocker
;
1897 rocker
= qmp_query_rocker(name
, &err
);
1898 if (hmp_handle_error(mon
, err
)) {
1902 monitor_printf(mon
, "name: %s\n", rocker
->name
);
1903 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
1904 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
1906 qapi_free_RockerSwitch(rocker
);
1909 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
1911 RockerPortList
*list
, *port
;
1912 const char *name
= qdict_get_str(qdict
, "name");
1915 list
= qmp_query_rocker_ports(name
, &err
);
1916 if (hmp_handle_error(mon
, err
)) {
1920 monitor_printf(mon
, " ena/ speed/ auto\n");
1921 monitor_printf(mon
, " port link duplex neg?\n");
1923 for (port
= list
; port
; port
= port
->next
) {
1924 monitor_printf(mon
, "%10s %-4s %-3s %2s %s\n",
1926 port
->value
->enabled
? port
->value
->link_up
?
1927 "up" : "down" : "!ena",
1928 port
->value
->speed
== 10000 ? "10G" : "??",
1929 port
->value
->duplex
? "FD" : "HD",
1930 port
->value
->autoneg
? "Yes" : "No");
1933 qapi_free_RockerPortList(list
);
1936 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
1938 RockerOfDpaFlowList
*list
, *info
;
1939 const char *name
= qdict_get_str(qdict
, "name");
1940 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
1943 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
1944 if (hmp_handle_error(mon
, err
)) {
1948 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
1950 for (info
= list
; info
; info
= info
->next
) {
1951 RockerOfDpaFlow
*flow
= info
->value
;
1952 RockerOfDpaFlowKey
*key
= flow
->key
;
1953 RockerOfDpaFlowMask
*mask
= flow
->mask
;
1954 RockerOfDpaFlowAction
*action
= flow
->action
;
1957 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
1958 key
->priority
, key
->tbl_id
, flow
->hits
);
1960 monitor_printf(mon
, "%-4d %-3d ",
1961 key
->priority
, key
->tbl_id
);
1964 if (key
->has_in_pport
) {
1965 monitor_printf(mon
, " pport %d", key
->in_pport
);
1966 if (mask
->has_in_pport
) {
1967 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
1971 if (key
->has_vlan_id
) {
1972 monitor_printf(mon
, " vlan %d",
1973 key
->vlan_id
& VLAN_VID_MASK
);
1974 if (mask
->has_vlan_id
) {
1975 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
1979 if (key
->has_tunnel_id
) {
1980 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
1981 if (mask
->has_tunnel_id
) {
1982 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
1986 if (key
->has_eth_type
) {
1987 switch (key
->eth_type
) {
1989 monitor_printf(mon
, " ARP");
1992 monitor_printf(mon
, " IP");
1995 monitor_printf(mon
, " IPv6");
1998 monitor_printf(mon
, " LACP");
2001 monitor_printf(mon
, " LLDP");
2004 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2010 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2012 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2013 monitor_printf(mon
, " src <any mcast/bcast>");
2014 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2016 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2017 monitor_printf(mon
, " src <any ucast>");
2019 monitor_printf(mon
, " src %s", key
->eth_src
);
2020 if (mask
->eth_src
) {
2021 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2027 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2029 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2030 monitor_printf(mon
, " dst <any mcast/bcast>");
2031 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2033 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2034 monitor_printf(mon
, " dst <any ucast>");
2036 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2037 if (mask
->eth_dst
) {
2038 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2043 if (key
->has_ip_proto
) {
2044 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2045 if (mask
->has_ip_proto
) {
2046 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2050 if (key
->has_ip_tos
) {
2051 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2052 if (mask
->has_ip_tos
) {
2053 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2058 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2061 if (action
->has_goto_tbl
|| action
->has_group_id
||
2062 action
->has_new_vlan_id
) {
2063 monitor_printf(mon
, " -->");
2066 if (action
->has_new_vlan_id
) {
2067 monitor_printf(mon
, " apply new vlan %d",
2068 ntohs(action
->new_vlan_id
));
2071 if (action
->has_group_id
) {
2072 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2075 if (action
->has_goto_tbl
) {
2076 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2079 monitor_printf(mon
, "\n");
2082 qapi_free_RockerOfDpaFlowList(list
);
2085 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2087 RockerOfDpaGroupList
*list
, *g
;
2088 const char *name
= qdict_get_str(qdict
, "name");
2089 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2092 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
2093 if (hmp_handle_error(mon
, err
)) {
2097 monitor_printf(mon
, "id (decode) --> buckets\n");
2099 for (g
= list
; g
; g
= g
->next
) {
2100 RockerOfDpaGroup
*group
= g
->value
;
2103 monitor_printf(mon
, "0x%08x", group
->id
);
2105 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2106 group
->type
== 1 ? "L2 rewrite" :
2107 group
->type
== 2 ? "L3 unicast" :
2108 group
->type
== 3 ? "L2 multicast" :
2109 group
->type
== 4 ? "L2 flood" :
2110 group
->type
== 5 ? "L3 interface" :
2111 group
->type
== 6 ? "L3 multicast" :
2112 group
->type
== 7 ? "L3 ECMP" :
2113 group
->type
== 8 ? "L2 overlay" :
2116 if (group
->has_vlan_id
) {
2117 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2120 if (group
->has_pport
) {
2121 monitor_printf(mon
, " pport %d", group
->pport
);
2124 if (group
->has_index
) {
2125 monitor_printf(mon
, " index %d", group
->index
);
2128 monitor_printf(mon
, ") -->");
2130 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2132 monitor_printf(mon
, " set vlan %d",
2133 group
->set_vlan_id
& VLAN_VID_MASK
);
2136 if (group
->set_eth_src
) {
2139 monitor_printf(mon
, " set");
2141 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2144 if (group
->set_eth_dst
) {
2146 monitor_printf(mon
, " set");
2148 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2151 if (group
->has_ttl_check
&& group
->ttl_check
) {
2152 monitor_printf(mon
, " check TTL");
2155 if (group
->has_group_id
&& group
->group_id
) {
2156 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2159 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2160 monitor_printf(mon
, " pop vlan");
2163 if (group
->has_out_pport
) {
2164 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2167 if (group
->has_group_ids
) {
2168 struct uint32List
*id
;
2170 monitor_printf(mon
, " groups [");
2171 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2172 monitor_printf(mon
, "0x%08x", id
->value
);
2174 monitor_printf(mon
, ",");
2177 monitor_printf(mon
, "]");
2180 monitor_printf(mon
, "\n");
2183 qapi_free_RockerOfDpaGroupList(list
);
2186 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
2189 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
2191 monitor_printf(mon
, "%s\n", info
->guid
);
2193 hmp_handle_error(mon
, err
);
2194 qapi_free_GuidInfo(info
);
2197 void hmp_info_memory_size_summary(Monitor
*mon
, const QDict
*qdict
)
2200 MemoryInfo
*info
= qmp_query_memory_size_summary(&err
);
2202 monitor_printf(mon
, "base memory: %" PRIu64
"\n",
2205 if (info
->has_plugged_memory
) {
2206 monitor_printf(mon
, "plugged memory: %" PRIu64
"\n",
2207 info
->plugged_memory
);
2210 qapi_free_MemoryInfo(info
);
2212 hmp_handle_error(mon
, err
);
2215 static void print_stats_schema_value(Monitor
*mon
, StatsSchemaValue
*value
)
2217 const char *unit
= NULL
;
2218 monitor_printf(mon
, " %s (%s%s", value
->name
, StatsType_str(value
->type
),
2219 value
->has_unit
|| value
->exponent
? ", " : "");
2221 if (value
->has_unit
) {
2222 if (value
->unit
== STATS_UNIT_SECONDS
) {
2224 } else if (value
->unit
== STATS_UNIT_BYTES
) {
2229 if (unit
&& value
->base
== 10 &&
2230 value
->exponent
>= -18 && value
->exponent
<= 18 &&
2231 value
->exponent
% 3 == 0) {
2232 monitor_puts(mon
, si_prefix(value
->exponent
));
2233 } else if (unit
&& value
->base
== 2 &&
2234 value
->exponent
>= 0 && value
->exponent
<= 60 &&
2235 value
->exponent
% 10 == 0) {
2237 monitor_puts(mon
, iec_binary_prefix(value
->exponent
));
2238 } else if (value
->exponent
) {
2239 /* Use exponential notation and write the unit's English name */
2240 monitor_printf(mon
, "* %d^%d%s",
2241 value
->base
, value
->exponent
,
2242 value
->has_unit
? " " : "");
2246 if (value
->has_unit
) {
2247 monitor_puts(mon
, unit
? unit
: StatsUnit_str(value
->unit
));
2250 /* Print bucket size for linear histograms */
2251 if (value
->type
== STATS_TYPE_LINEAR_HISTOGRAM
&& value
->has_bucket_size
) {
2252 monitor_printf(mon
, ", bucket size=%d", value
->bucket_size
);
2254 monitor_printf(mon
, ")");
2257 static StatsSchemaValueList
*find_schema_value_list(
2258 StatsSchemaList
*list
, StatsProvider provider
,
2261 StatsSchemaList
*node
;
2263 for (node
= list
; node
; node
= node
->next
) {
2264 if (node
->value
->provider
== provider
&&
2265 node
->value
->target
== target
) {
2266 return node
->value
->stats
;
2272 static void print_stats_results(Monitor
*mon
, StatsTarget target
,
2274 StatsResult
*result
,
2275 StatsSchemaList
*schema
)
2277 /* Find provider schema */
2278 StatsSchemaValueList
*schema_value_list
=
2279 find_schema_value_list(schema
, result
->provider
, target
);
2280 StatsList
*stats_list
;
2282 if (!schema_value_list
) {
2283 monitor_printf(mon
, "failed to find schema list for %s\n",
2284 StatsProvider_str(result
->provider
));
2288 if (show_provider
) {
2289 monitor_printf(mon
, "provider: %s\n",
2290 StatsProvider_str(result
->provider
));
2293 for (stats_list
= result
->stats
; stats_list
;
2294 stats_list
= stats_list
->next
,
2295 schema_value_list
= schema_value_list
->next
) {
2297 Stats
*stats
= stats_list
->value
;
2298 StatsValue
*stats_value
= stats
->value
;
2299 StatsSchemaValue
*schema_value
= schema_value_list
->value
;
2301 /* Find schema entry */
2302 while (!g_str_equal(stats
->name
, schema_value
->name
)) {
2303 if (!schema_value_list
->next
) {
2304 monitor_printf(mon
, "failed to find schema entry for %s\n",
2308 schema_value_list
= schema_value_list
->next
;
2309 schema_value
= schema_value_list
->value
;
2312 print_stats_schema_value(mon
, schema_value
);
2314 if (stats_value
->type
== QTYPE_QNUM
) {
2315 monitor_printf(mon
, ": %" PRId64
"\n", stats_value
->u
.scalar
);
2316 } else if (stats_value
->type
== QTYPE_QBOOL
) {
2317 monitor_printf(mon
, ": %s\n", stats_value
->u
.boolean
? "yes" : "no");
2318 } else if (stats_value
->type
== QTYPE_QLIST
) {
2322 monitor_printf(mon
, ": ");
2323 for (list
= stats_value
->u
.list
, i
= 1;
2325 list
= list
->next
, i
++) {
2326 monitor_printf(mon
, "[%d]=%" PRId64
" ", i
, list
->value
);
2328 monitor_printf(mon
, "\n");
2333 /* Create the StatsFilter that is needed for an "info stats" invocation. */
2334 static StatsFilter
*stats_filter(StatsTarget target
, const char *names
,
2335 int cpu_index
, StatsProvider provider
)
2337 StatsFilter
*filter
= g_malloc0(sizeof(*filter
));
2338 StatsProvider provider_idx
;
2339 StatsRequestList
*request_list
= NULL
;
2341 filter
->target
= target
;
2343 case STATS_TARGET_VM
:
2345 case STATS_TARGET_VCPU
:
2347 strList
*vcpu_list
= NULL
;
2348 CPUState
*cpu
= qemu_get_cpu(cpu_index
);
2349 char *canonical_path
= object_get_canonical_path(OBJECT(cpu
));
2351 QAPI_LIST_PREPEND(vcpu_list
, canonical_path
);
2352 filter
->u
.vcpu
.has_vcpus
= true;
2353 filter
->u
.vcpu
.vcpus
= vcpu_list
;
2360 if (!names
&& provider
== STATS_PROVIDER__MAX
) {
2365 * "info stats" can only query either one or all the providers. Querying
2366 * by name, but not by provider, requires the creation of one filter per
2369 for (provider_idx
= 0; provider_idx
< STATS_PROVIDER__MAX
; provider_idx
++) {
2370 if (provider
== STATS_PROVIDER__MAX
|| provider
== provider_idx
) {
2371 StatsRequest
*request
= g_new0(StatsRequest
, 1);
2372 request
->provider
= provider_idx
;
2373 if (names
&& !g_str_equal(names
, "*")) {
2374 request
->has_names
= true;
2375 request
->names
= strList_from_comma_list(names
);
2377 QAPI_LIST_PREPEND(request_list
, request
);
2381 filter
->has_providers
= true;
2382 filter
->providers
= request_list
;
2386 void hmp_info_stats(Monitor
*mon
, const QDict
*qdict
)
2388 const char *target_str
= qdict_get_str(qdict
, "target");
2389 const char *provider_str
= qdict_get_try_str(qdict
, "provider");
2390 const char *names
= qdict_get_try_str(qdict
, "names");
2392 StatsProvider provider
= STATS_PROVIDER__MAX
;
2395 g_autoptr(StatsSchemaList
) schema
= NULL
;
2396 g_autoptr(StatsResultList
) stats
= NULL
;
2397 g_autoptr(StatsFilter
) filter
= NULL
;
2398 StatsResultList
*entry
;
2400 target
= qapi_enum_parse(&StatsTarget_lookup
, target_str
, -1, &err
);
2402 monitor_printf(mon
, "invalid stats target %s\n", target_str
);
2406 provider
= qapi_enum_parse(&StatsProvider_lookup
, provider_str
, -1, &err
);
2408 monitor_printf(mon
, "invalid stats provider %s\n", provider_str
);
2413 schema
= qmp_query_stats_schemas(provider_str
? true : false,
2420 case STATS_TARGET_VM
:
2421 filter
= stats_filter(target
, names
, -1, provider
);
2423 case STATS_TARGET_VCPU
: {}
2424 int cpu_index
= monitor_get_cpu_index(mon
);
2425 filter
= stats_filter(target
, names
, cpu_index
, provider
);
2431 stats
= qmp_query_stats(filter
, &err
);
2435 for (entry
= stats
; entry
; entry
= entry
->next
) {
2436 print_stats_results(mon
, target
, provider_str
== NULL
, entry
->value
, schema
);
2441 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
2447 static void hmp_virtio_dump_protocols(Monitor
*mon
,
2448 VhostDeviceProtocols
*pcol
)
2450 strList
*pcol_list
= pcol
->protocols
;
2452 monitor_printf(mon
, "\t%s", pcol_list
->value
);
2453 pcol_list
= pcol_list
->next
;
2454 if (pcol_list
!= NULL
) {
2455 monitor_printf(mon
, ",\n");
2458 monitor_printf(mon
, "\n");
2459 if (pcol
->has_unknown_protocols
) {
2460 monitor_printf(mon
, " unknown-protocols(0x%016"PRIx64
")\n",
2461 pcol
->unknown_protocols
);
2465 static void hmp_virtio_dump_status(Monitor
*mon
,
2466 VirtioDeviceStatus
*status
)
2468 strList
*status_list
= status
->statuses
;
2469 while (status_list
) {
2470 monitor_printf(mon
, "\t%s", status_list
->value
);
2471 status_list
= status_list
->next
;
2472 if (status_list
!= NULL
) {
2473 monitor_printf(mon
, ",\n");
2476 monitor_printf(mon
, "\n");
2477 if (status
->has_unknown_statuses
) {
2478 monitor_printf(mon
, " unknown-statuses(0x%016"PRIx32
")\n",
2479 status
->unknown_statuses
);
2483 static void hmp_virtio_dump_features(Monitor
*mon
,
2484 VirtioDeviceFeatures
*features
)
2486 strList
*transport_list
= features
->transports
;
2487 while (transport_list
) {
2488 monitor_printf(mon
, "\t%s", transport_list
->value
);
2489 transport_list
= transport_list
->next
;
2490 if (transport_list
!= NULL
) {
2491 monitor_printf(mon
, ",\n");
2495 monitor_printf(mon
, "\n");
2496 strList
*list
= features
->dev_features
;
2499 monitor_printf(mon
, "\t%s", list
->value
);
2502 monitor_printf(mon
, ",\n");
2505 monitor_printf(mon
, "\n");
2508 if (features
->has_unknown_dev_features
) {
2509 monitor_printf(mon
, " unknown-features(0x%016"PRIx64
")\n",
2510 features
->unknown_dev_features
);
2514 void hmp_virtio_query(Monitor
*mon
, const QDict
*qdict
)
2517 VirtioInfoList
*list
= qmp_x_query_virtio(&err
);
2518 VirtioInfoList
*node
;
2521 hmp_handle_error(mon
, err
);
2526 monitor_printf(mon
, "No VirtIO devices\n");
2532 monitor_printf(mon
, "%s [%s]\n", node
->value
->path
,
2536 qapi_free_VirtioInfoList(list
);
2539 void hmp_virtio_status(Monitor
*mon
, const QDict
*qdict
)
2542 const char *path
= qdict_get_try_str(qdict
, "path");
2543 VirtioStatus
*s
= qmp_x_query_virtio_status(path
, &err
);
2546 hmp_handle_error(mon
, err
);
2550 monitor_printf(mon
, "%s:\n", path
);
2551 monitor_printf(mon
, " device_name: %s %s\n",
2552 s
->name
, s
->vhost_dev
? "(vhost)" : "");
2553 monitor_printf(mon
, " device_id: %d\n", s
->device_id
);
2554 monitor_printf(mon
, " vhost_started: %s\n",
2555 s
->vhost_started
? "true" : "false");
2556 monitor_printf(mon
, " bus_name: %s\n", s
->bus_name
);
2557 monitor_printf(mon
, " broken: %s\n",
2558 s
->broken
? "true" : "false");
2559 monitor_printf(mon
, " disabled: %s\n",
2560 s
->disabled
? "true" : "false");
2561 monitor_printf(mon
, " disable_legacy_check: %s\n",
2562 s
->disable_legacy_check
? "true" : "false");
2563 monitor_printf(mon
, " started: %s\n",
2564 s
->started
? "true" : "false");
2565 monitor_printf(mon
, " use_started: %s\n",
2566 s
->use_started
? "true" : "false");
2567 monitor_printf(mon
, " start_on_kick: %s\n",
2568 s
->start_on_kick
? "true" : "false");
2569 monitor_printf(mon
, " use_guest_notifier_mask: %s\n",
2570 s
->use_guest_notifier_mask
? "true" : "false");
2571 monitor_printf(mon
, " vm_running: %s\n",
2572 s
->vm_running
? "true" : "false");
2573 monitor_printf(mon
, " num_vqs: %"PRId64
"\n", s
->num_vqs
);
2574 monitor_printf(mon
, " queue_sel: %d\n",
2576 monitor_printf(mon
, " isr: %d\n", s
->isr
);
2577 monitor_printf(mon
, " endianness: %s\n",
2579 monitor_printf(mon
, " status:\n");
2580 hmp_virtio_dump_status(mon
, s
->status
);
2581 monitor_printf(mon
, " Guest features:\n");
2582 hmp_virtio_dump_features(mon
, s
->guest_features
);
2583 monitor_printf(mon
, " Host features:\n");
2584 hmp_virtio_dump_features(mon
, s
->host_features
);
2585 monitor_printf(mon
, " Backend features:\n");
2586 hmp_virtio_dump_features(mon
, s
->backend_features
);
2589 monitor_printf(mon
, " VHost:\n");
2590 monitor_printf(mon
, " nvqs: %d\n",
2591 s
->vhost_dev
->nvqs
);
2592 monitor_printf(mon
, " vq_index: %"PRId64
"\n",
2593 s
->vhost_dev
->vq_index
);
2594 monitor_printf(mon
, " max_queues: %"PRId64
"\n",
2595 s
->vhost_dev
->max_queues
);
2596 monitor_printf(mon
, " n_mem_sections: %"PRId64
"\n",
2597 s
->vhost_dev
->n_mem_sections
);
2598 monitor_printf(mon
, " n_tmp_sections: %"PRId64
"\n",
2599 s
->vhost_dev
->n_tmp_sections
);
2600 monitor_printf(mon
, " backend_cap: %"PRId64
"\n",
2601 s
->vhost_dev
->backend_cap
);
2602 monitor_printf(mon
, " log_enabled: %s\n",
2603 s
->vhost_dev
->log_enabled
? "true" : "false");
2604 monitor_printf(mon
, " log_size: %"PRId64
"\n",
2605 s
->vhost_dev
->log_size
);
2606 monitor_printf(mon
, " Features:\n");
2607 hmp_virtio_dump_features(mon
, s
->vhost_dev
->features
);
2608 monitor_printf(mon
, " Acked features:\n");
2609 hmp_virtio_dump_features(mon
, s
->vhost_dev
->acked_features
);
2610 monitor_printf(mon
, " Backend features:\n");
2611 hmp_virtio_dump_features(mon
, s
->vhost_dev
->backend_features
);
2612 monitor_printf(mon
, " Protocol features:\n");
2613 hmp_virtio_dump_protocols(mon
, s
->vhost_dev
->protocol_features
);
2616 qapi_free_VirtioStatus(s
);
2619 void hmp_vhost_queue_status(Monitor
*mon
, const QDict
*qdict
)
2622 const char *path
= qdict_get_try_str(qdict
, "path");
2623 int queue
= qdict_get_int(qdict
, "queue");
2624 VirtVhostQueueStatus
*s
=
2625 qmp_x_query_virtio_vhost_queue_status(path
, queue
, &err
);
2628 hmp_handle_error(mon
, err
);
2632 monitor_printf(mon
, "%s:\n", path
);
2633 monitor_printf(mon
, " device_name: %s (vhost)\n",
2635 monitor_printf(mon
, " kick: %"PRId64
"\n", s
->kick
);
2636 monitor_printf(mon
, " call: %"PRId64
"\n", s
->call
);
2637 monitor_printf(mon
, " VRing:\n");
2638 monitor_printf(mon
, " num: %"PRId64
"\n", s
->num
);
2639 monitor_printf(mon
, " desc: 0x%016"PRIx64
"\n", s
->desc
);
2640 monitor_printf(mon
, " desc_phys: 0x%016"PRIx64
"\n",
2642 monitor_printf(mon
, " desc_size: %"PRId32
"\n", s
->desc_size
);
2643 monitor_printf(mon
, " avail: 0x%016"PRIx64
"\n", s
->avail
);
2644 monitor_printf(mon
, " avail_phys: 0x%016"PRIx64
"\n",
2646 monitor_printf(mon
, " avail_size: %"PRId32
"\n", s
->avail_size
);
2647 monitor_printf(mon
, " used: 0x%016"PRIx64
"\n", s
->used
);
2648 monitor_printf(mon
, " used_phys: 0x%016"PRIx64
"\n",
2650 monitor_printf(mon
, " used_size: %"PRId32
"\n", s
->used_size
);
2652 qapi_free_VirtVhostQueueStatus(s
);
2655 void hmp_virtio_queue_status(Monitor
*mon
, const QDict
*qdict
)
2658 const char *path
= qdict_get_try_str(qdict
, "path");
2659 int queue
= qdict_get_int(qdict
, "queue");
2660 VirtQueueStatus
*s
= qmp_x_query_virtio_queue_status(path
, queue
, &err
);
2663 hmp_handle_error(mon
, err
);
2667 monitor_printf(mon
, "%s:\n", path
);
2668 monitor_printf(mon
, " device_name: %s\n", s
->name
);
2669 monitor_printf(mon
, " queue_index: %d\n", s
->queue_index
);
2670 monitor_printf(mon
, " inuse: %d\n", s
->inuse
);
2671 monitor_printf(mon
, " used_idx: %d\n", s
->used_idx
);
2672 monitor_printf(mon
, " signalled_used: %d\n",
2674 monitor_printf(mon
, " signalled_used_valid: %s\n",
2675 s
->signalled_used_valid
? "true" : "false");
2676 if (s
->has_last_avail_idx
) {
2677 monitor_printf(mon
, " last_avail_idx: %d\n",
2680 if (s
->has_shadow_avail_idx
) {
2681 monitor_printf(mon
, " shadow_avail_idx: %d\n",
2682 s
->shadow_avail_idx
);
2684 monitor_printf(mon
, " VRing:\n");
2685 monitor_printf(mon
, " num: %"PRId32
"\n", s
->vring_num
);
2686 monitor_printf(mon
, " num_default: %"PRId32
"\n",
2687 s
->vring_num_default
);
2688 monitor_printf(mon
, " align: %"PRId32
"\n",
2690 monitor_printf(mon
, " desc: 0x%016"PRIx64
"\n",
2692 monitor_printf(mon
, " avail: 0x%016"PRIx64
"\n",
2694 monitor_printf(mon
, " used: 0x%016"PRIx64
"\n",
2697 qapi_free_VirtQueueStatus(s
);
2700 void hmp_virtio_queue_element(Monitor
*mon
, const QDict
*qdict
)
2703 const char *path
= qdict_get_try_str(qdict
, "path");
2704 int queue
= qdict_get_int(qdict
, "queue");
2705 int index
= qdict_get_try_int(qdict
, "index", -1);
2706 VirtioQueueElement
*e
;
2707 VirtioRingDescList
*list
;
2709 e
= qmp_x_query_virtio_queue_element(path
, queue
, index
!= -1,
2712 hmp_handle_error(mon
, err
);
2716 monitor_printf(mon
, "%s:\n", path
);
2717 monitor_printf(mon
, " device_name: %s\n", e
->name
);
2718 monitor_printf(mon
, " index: %d\n", e
->index
);
2719 monitor_printf(mon
, " desc:\n");
2720 monitor_printf(mon
, " descs:\n");
2724 monitor_printf(mon
, " addr 0x%"PRIx64
" len %d",
2725 list
->value
->addr
, list
->value
->len
);
2726 if (list
->value
->flags
) {
2727 strList
*flag
= list
->value
->flags
;
2728 monitor_printf(mon
, " (");
2730 monitor_printf(mon
, "%s", flag
->value
);
2733 monitor_printf(mon
, ", ");
2736 monitor_printf(mon
, ")");
2740 monitor_printf(mon
, ",\n");
2743 monitor_printf(mon
, "\n");
2744 monitor_printf(mon
, " avail:\n");
2745 monitor_printf(mon
, " flags: %d\n", e
->avail
->flags
);
2746 monitor_printf(mon
, " idx: %d\n", e
->avail
->idx
);
2747 monitor_printf(mon
, " ring: %d\n", e
->avail
->ring
);
2748 monitor_printf(mon
, " used:\n");
2749 monitor_printf(mon
, " flags: %d\n", e
->used
->flags
);
2750 monitor_printf(mon
, " idx: %d\n", e
->used
->idx
);
2752 qapi_free_VirtioQueueElement(e
);