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-visit-net.h"
47 #include "qapi/qapi-visit-migration.h"
48 #include "qapi/qmp/qdict.h"
49 #include "qapi/qmp/qerror.h"
50 #include "qapi/string-input-visitor.h"
51 #include "qapi/string-output-visitor.h"
52 #include "qom/object_interfaces.h"
53 #include "ui/console.h"
54 #include "qemu/cutils.h"
55 #include "qemu/error-report.h"
56 #include "hw/core/cpu.h"
57 #include "hw/intc/intc.h"
58 #include "migration/snapshot.h"
59 #include "migration/misc.h"
62 #include <spice/enums.h>
65 bool hmp_handle_error(Monitor
*mon
, Error
*err
)
68 error_reportf_err(err
, "Error: ");
75 * Produce a strList from a comma separated list.
76 * A NULL or empty input string return NULL.
78 static strList
*strList_from_comma_list(const char *in
)
81 strList
**tail
= &res
;
84 char *comma
= strchr(in
, ',');
88 value
= g_strndup(in
, comma
- in
);
89 in
= comma
+ 1; /* skip the , */
94 QAPI_LIST_APPEND(tail
, value
);
100 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
104 info
= qmp_query_name(NULL
);
105 if (info
->has_name
) {
106 monitor_printf(mon
, "%s\n", info
->name
);
108 qapi_free_NameInfo(info
);
111 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
115 info
= qmp_query_version(NULL
);
117 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
118 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
121 qapi_free_VersionInfo(info
);
124 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
128 info
= qmp_query_kvm(NULL
);
129 monitor_printf(mon
, "kvm support: ");
131 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
133 monitor_printf(mon
, "not compiled\n");
136 qapi_free_KvmInfo(info
);
139 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
143 info
= qmp_query_status(NULL
);
145 monitor_printf(mon
, "VM status: %s%s",
146 info
->running
? "running" : "paused",
147 info
->singlestep
? " (single step mode)" : "");
149 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
150 monitor_printf(mon
, " (%s)", RunState_str(info
->status
));
153 monitor_printf(mon
, "\n");
155 qapi_free_StatusInfo(info
);
158 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
162 info
= qmp_query_uuid(NULL
);
163 monitor_printf(mon
, "%s\n", info
->UUID
);
164 qapi_free_UuidInfo(info
);
167 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
169 ChardevInfoList
*char_info
, *info
;
171 char_info
= qmp_query_chardev(NULL
);
172 for (info
= char_info
; info
; info
= info
->next
) {
173 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
174 info
->value
->filename
);
177 qapi_free_ChardevInfoList(char_info
);
180 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
182 MouseInfoList
*mice_list
, *mouse
;
184 mice_list
= qmp_query_mice(NULL
);
186 monitor_printf(mon
, "No mouse devices connected\n");
190 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
191 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
192 mouse
->value
->current
? '*' : ' ',
193 mouse
->value
->index
, mouse
->value
->name
,
194 mouse
->value
->absolute
? " (absolute)" : "");
197 qapi_free_MouseInfoList(mice_list
);
200 static char *SocketAddress_to_str(SocketAddress
*addr
)
202 switch (addr
->type
) {
203 case SOCKET_ADDRESS_TYPE_INET
:
204 return g_strdup_printf("tcp:%s:%s",
207 case SOCKET_ADDRESS_TYPE_UNIX
:
208 return g_strdup_printf("unix:%s",
209 addr
->u
.q_unix
.path
);
210 case SOCKET_ADDRESS_TYPE_FD
:
211 return g_strdup_printf("fd:%s", addr
->u
.fd
.str
);
212 case SOCKET_ADDRESS_TYPE_VSOCK
:
213 return g_strdup_printf("tcp:%s:%s",
217 return g_strdup("unknown address type");
221 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
225 info
= qmp_query_migrate(NULL
);
227 migration_global_dump(mon
);
229 if (info
->blocked_reasons
) {
230 strList
*reasons
= info
->blocked_reasons
;
231 monitor_printf(mon
, "Outgoing migration blocked:\n");
233 monitor_printf(mon
, " %s\n", reasons
->value
);
234 reasons
= reasons
->next
;
238 if (info
->has_status
) {
239 monitor_printf(mon
, "Migration status: %s",
240 MigrationStatus_str(info
->status
));
241 if (info
->status
== MIGRATION_STATUS_FAILED
&&
242 info
->has_error_desc
) {
243 monitor_printf(mon
, " (%s)\n", info
->error_desc
);
245 monitor_printf(mon
, "\n");
248 monitor_printf(mon
, "total time: %" PRIu64
" ms\n",
250 if (info
->has_expected_downtime
) {
251 monitor_printf(mon
, "expected downtime: %" PRIu64
" ms\n",
252 info
->expected_downtime
);
254 if (info
->has_downtime
) {
255 monitor_printf(mon
, "downtime: %" PRIu64
" ms\n",
258 if (info
->has_setup_time
) {
259 monitor_printf(mon
, "setup: %" PRIu64
" ms\n",
265 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
266 info
->ram
->transferred
>> 10);
267 monitor_printf(mon
, "throughput: %0.2f mbps\n",
269 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
270 info
->ram
->remaining
>> 10);
271 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
272 info
->ram
->total
>> 10);
273 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
274 info
->ram
->duplicate
);
275 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
277 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
279 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
280 info
->ram
->normal_bytes
>> 10);
281 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
282 info
->ram
->dirty_sync_count
);
283 monitor_printf(mon
, "page size: %" PRIu64
" kbytes\n",
284 info
->ram
->page_size
>> 10);
285 monitor_printf(mon
, "multifd bytes: %" PRIu64
" kbytes\n",
286 info
->ram
->multifd_bytes
>> 10);
287 monitor_printf(mon
, "pages-per-second: %" PRIu64
"\n",
288 info
->ram
->pages_per_second
);
290 if (info
->ram
->dirty_pages_rate
) {
291 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
292 info
->ram
->dirty_pages_rate
);
294 if (info
->ram
->postcopy_requests
) {
295 monitor_printf(mon
, "postcopy request count: %" PRIu64
"\n",
296 info
->ram
->postcopy_requests
);
298 if (info
->ram
->precopy_bytes
) {
299 monitor_printf(mon
, "precopy ram: %" PRIu64
" kbytes\n",
300 info
->ram
->precopy_bytes
>> 10);
302 if (info
->ram
->downtime_bytes
) {
303 monitor_printf(mon
, "downtime ram: %" PRIu64
" kbytes\n",
304 info
->ram
->downtime_bytes
>> 10);
306 if (info
->ram
->postcopy_bytes
) {
307 monitor_printf(mon
, "postcopy ram: %" PRIu64
" kbytes\n",
308 info
->ram
->postcopy_bytes
>> 10);
310 if (info
->ram
->dirty_sync_missed_zero_copy
) {
312 "Zero-copy-send fallbacks happened: %" PRIu64
" times\n",
313 info
->ram
->dirty_sync_missed_zero_copy
);
317 if (info
->has_disk
) {
318 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
319 info
->disk
->transferred
>> 10);
320 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
321 info
->disk
->remaining
>> 10);
322 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
323 info
->disk
->total
>> 10);
326 if (info
->has_xbzrle_cache
) {
327 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
328 info
->xbzrle_cache
->cache_size
);
329 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
330 info
->xbzrle_cache
->bytes
>> 10);
331 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
332 info
->xbzrle_cache
->pages
);
333 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
" pages\n",
334 info
->xbzrle_cache
->cache_miss
);
335 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
336 info
->xbzrle_cache
->cache_miss_rate
);
337 monitor_printf(mon
, "xbzrle encoding rate: %0.2f\n",
338 info
->xbzrle_cache
->encoding_rate
);
339 monitor_printf(mon
, "xbzrle overflow: %" PRIu64
"\n",
340 info
->xbzrle_cache
->overflow
);
343 if (info
->has_compression
) {
344 monitor_printf(mon
, "compression pages: %" PRIu64
" pages\n",
345 info
->compression
->pages
);
346 monitor_printf(mon
, "compression busy: %" PRIu64
"\n",
347 info
->compression
->busy
);
348 monitor_printf(mon
, "compression busy rate: %0.2f\n",
349 info
->compression
->busy_rate
);
350 monitor_printf(mon
, "compressed size: %" PRIu64
" kbytes\n",
351 info
->compression
->compressed_size
>> 10);
352 monitor_printf(mon
, "compression rate: %0.2f\n",
353 info
->compression
->compression_rate
);
356 if (info
->has_cpu_throttle_percentage
) {
357 monitor_printf(mon
, "cpu throttle percentage: %" PRIu64
"\n",
358 info
->cpu_throttle_percentage
);
361 if (info
->has_postcopy_blocktime
) {
362 monitor_printf(mon
, "postcopy blocktime: %u\n",
363 info
->postcopy_blocktime
);
366 if (info
->has_postcopy_vcpu_blocktime
) {
369 v
= string_output_visitor_new(false, &str
);
370 visit_type_uint32List(v
, NULL
, &info
->postcopy_vcpu_blocktime
,
372 visit_complete(v
, &str
);
373 monitor_printf(mon
, "postcopy vcpu blocktime: %s\n", str
);
377 if (info
->has_socket_address
) {
378 SocketAddressList
*addr
;
380 monitor_printf(mon
, "socket address: [\n");
382 for (addr
= info
->socket_address
; addr
; addr
= addr
->next
) {
383 char *s
= SocketAddress_to_str(addr
->value
);
384 monitor_printf(mon
, "\t%s\n", s
);
387 monitor_printf(mon
, "]\n");
390 if (info
->has_vfio
) {
391 monitor_printf(mon
, "vfio device transferred: %" PRIu64
" kbytes\n",
392 info
->vfio
->transferred
>> 10);
395 qapi_free_MigrationInfo(info
);
398 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
400 MigrationCapabilityStatusList
*caps
, *cap
;
402 caps
= qmp_query_migrate_capabilities(NULL
);
405 for (cap
= caps
; cap
; cap
= cap
->next
) {
406 monitor_printf(mon
, "%s: %s\n",
407 MigrationCapability_str(cap
->value
->capability
),
408 cap
->value
->state
? "on" : "off");
412 qapi_free_MigrationCapabilityStatusList(caps
);
415 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
417 MigrationParameters
*params
;
419 params
= qmp_query_migrate_parameters(NULL
);
422 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
423 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL
),
424 params
->announce_initial
);
425 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
426 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX
),
427 params
->announce_max
);
428 monitor_printf(mon
, "%s: %" PRIu64
"\n",
429 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS
),
430 params
->announce_rounds
);
431 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
432 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP
),
433 params
->announce_step
);
434 assert(params
->has_compress_level
);
435 monitor_printf(mon
, "%s: %u\n",
436 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL
),
437 params
->compress_level
);
438 assert(params
->has_compress_threads
);
439 monitor_printf(mon
, "%s: %u\n",
440 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS
),
441 params
->compress_threads
);
442 assert(params
->has_compress_wait_thread
);
443 monitor_printf(mon
, "%s: %s\n",
444 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD
),
445 params
->compress_wait_thread
? "on" : "off");
446 assert(params
->has_decompress_threads
);
447 monitor_printf(mon
, "%s: %u\n",
448 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS
),
449 params
->decompress_threads
);
450 assert(params
->has_throttle_trigger_threshold
);
451 monitor_printf(mon
, "%s: %u\n",
452 MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD
),
453 params
->throttle_trigger_threshold
);
454 assert(params
->has_cpu_throttle_initial
);
455 monitor_printf(mon
, "%s: %u\n",
456 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
),
457 params
->cpu_throttle_initial
);
458 assert(params
->has_cpu_throttle_increment
);
459 monitor_printf(mon
, "%s: %u\n",
460 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
),
461 params
->cpu_throttle_increment
);
462 assert(params
->has_cpu_throttle_tailslow
);
463 monitor_printf(mon
, "%s: %s\n",
464 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW
),
465 params
->cpu_throttle_tailslow
? "on" : "off");
466 assert(params
->has_max_cpu_throttle
);
467 monitor_printf(mon
, "%s: %u\n",
468 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE
),
469 params
->max_cpu_throttle
);
470 assert(params
->has_tls_creds
);
471 monitor_printf(mon
, "%s: '%s'\n",
472 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS
),
474 assert(params
->has_tls_hostname
);
475 monitor_printf(mon
, "%s: '%s'\n",
476 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME
),
477 params
->tls_hostname
);
478 assert(params
->has_max_bandwidth
);
479 monitor_printf(mon
, "%s: %" PRIu64
" bytes/second\n",
480 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH
),
481 params
->max_bandwidth
);
482 assert(params
->has_downtime_limit
);
483 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
484 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT
),
485 params
->downtime_limit
);
486 assert(params
->has_x_checkpoint_delay
);
487 monitor_printf(mon
, "%s: %u ms\n",
488 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
),
489 params
->x_checkpoint_delay
);
490 assert(params
->has_block_incremental
);
491 monitor_printf(mon
, "%s: %s\n",
492 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL
),
493 params
->block_incremental
? "on" : "off");
494 monitor_printf(mon
, "%s: %u\n",
495 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS
),
496 params
->multifd_channels
);
497 monitor_printf(mon
, "%s: %s\n",
498 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION
),
499 MultiFDCompression_str(params
->multifd_compression
));
500 monitor_printf(mon
, "%s: %" PRIu64
" bytes\n",
501 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
),
502 params
->xbzrle_cache_size
);
503 monitor_printf(mon
, "%s: %" PRIu64
"\n",
504 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH
),
505 params
->max_postcopy_bandwidth
);
506 monitor_printf(mon
, "%s: '%s'\n",
507 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ
),
510 if (params
->has_block_bitmap_mapping
) {
511 const BitmapMigrationNodeAliasList
*bmnal
;
513 monitor_printf(mon
, "%s:\n",
514 MigrationParameter_str(
515 MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING
));
517 for (bmnal
= params
->block_bitmap_mapping
;
521 const BitmapMigrationNodeAlias
*bmna
= bmnal
->value
;
522 const BitmapMigrationBitmapAliasList
*bmbal
;
524 monitor_printf(mon
, " '%s' -> '%s'\n",
525 bmna
->node_name
, bmna
->alias
);
527 for (bmbal
= bmna
->bitmaps
; bmbal
; bmbal
= bmbal
->next
) {
528 const BitmapMigrationBitmapAlias
*bmba
= bmbal
->value
;
530 monitor_printf(mon
, " '%s' -> '%s'\n",
531 bmba
->name
, bmba
->alias
);
537 qapi_free_MigrationParameters(params
);
542 /* Helper for hmp_info_vnc_clients, _servers */
543 static void hmp_info_VncBasicInfo(Monitor
*mon
, VncBasicInfo
*info
,
546 monitor_printf(mon
, " %s: %s:%s (%s%s)\n",
550 NetworkAddressFamily_str(info
->family
),
551 info
->websocket
? " (Websocket)" : "");
554 /* Helper displaying and auth and crypt info */
555 static void hmp_info_vnc_authcrypt(Monitor
*mon
, const char *indent
,
557 VncVencryptSubAuth
*vencrypt
)
559 monitor_printf(mon
, "%sAuth: %s (Sub: %s)\n", indent
,
560 VncPrimaryAuth_str(auth
),
561 vencrypt
? VncVencryptSubAuth_str(*vencrypt
) : "none");
564 static void hmp_info_vnc_clients(Monitor
*mon
, VncClientInfoList
*client
)
567 VncClientInfo
*cinfo
= client
->value
;
569 hmp_info_VncBasicInfo(mon
, qapi_VncClientInfo_base(cinfo
), "Client");
570 monitor_printf(mon
, " x509_dname: %s\n",
571 cinfo
->has_x509_dname
?
572 cinfo
->x509_dname
: "none");
573 monitor_printf(mon
, " sasl_username: %s\n",
574 cinfo
->has_sasl_username
?
575 cinfo
->sasl_username
: "none");
577 client
= client
->next
;
581 static void hmp_info_vnc_servers(Monitor
*mon
, VncServerInfo2List
*server
)
584 VncServerInfo2
*sinfo
= server
->value
;
585 hmp_info_VncBasicInfo(mon
, qapi_VncServerInfo2_base(sinfo
), "Server");
586 hmp_info_vnc_authcrypt(mon
, " ", sinfo
->auth
,
587 sinfo
->has_vencrypt
? &sinfo
->vencrypt
: NULL
);
588 server
= server
->next
;
592 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
594 VncInfo2List
*info2l
, *info2l_head
;
597 info2l
= qmp_query_vnc_servers(&err
);
598 info2l_head
= info2l
;
599 if (hmp_handle_error(mon
, err
)) {
603 monitor_printf(mon
, "None\n");
608 VncInfo2
*info
= info2l
->value
;
609 monitor_printf(mon
, "%s:\n", info
->id
);
610 hmp_info_vnc_servers(mon
, info
->server
);
611 hmp_info_vnc_clients(mon
, info
->clients
);
613 /* The server entry displays its auth, we only
614 * need to display in the case of 'reverse' connections
615 * where there's no server.
617 hmp_info_vnc_authcrypt(mon
, " ", info
->auth
,
618 info
->has_vencrypt
? &info
->vencrypt
: NULL
);
620 if (info
->has_display
) {
621 monitor_printf(mon
, " Display: %s\n", info
->display
);
623 info2l
= info2l
->next
;
626 qapi_free_VncInfo2List(info2l_head
);
632 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
634 SpiceChannelList
*chan
;
636 const char *channel_name
;
637 const char * const channel_names
[] = {
638 [SPICE_CHANNEL_MAIN
] = "main",
639 [SPICE_CHANNEL_DISPLAY
] = "display",
640 [SPICE_CHANNEL_INPUTS
] = "inputs",
641 [SPICE_CHANNEL_CURSOR
] = "cursor",
642 [SPICE_CHANNEL_PLAYBACK
] = "playback",
643 [SPICE_CHANNEL_RECORD
] = "record",
644 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
645 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
646 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
647 [SPICE_CHANNEL_PORT
] = "port",
649 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
650 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
651 * as quick fix for build failures with older versions. */
652 [SPICE_CHANNEL_WEBDAV
] = "webdav",
656 info
= qmp_query_spice(NULL
);
658 if (!info
->enabled
) {
659 monitor_printf(mon
, "Server: disabled\n");
663 monitor_printf(mon
, "Server:\n");
664 if (info
->has_port
) {
665 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
666 info
->host
, info
->port
);
668 if (info
->has_tls_port
) {
669 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
670 info
->host
, info
->tls_port
);
672 monitor_printf(mon
, " migrated: %s\n",
673 info
->migrated
? "true" : "false");
674 monitor_printf(mon
, " auth: %s\n", info
->auth
);
675 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
676 monitor_printf(mon
, " mouse-mode: %s\n",
677 SpiceQueryMouseMode_str(info
->mouse_mode
));
679 if (!info
->has_channels
|| info
->channels
== NULL
) {
680 monitor_printf(mon
, "Channels: none\n");
682 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
683 monitor_printf(mon
, "Channel:\n");
684 monitor_printf(mon
, " address: %s:%s%s\n",
685 chan
->value
->host
, chan
->value
->port
,
686 chan
->value
->tls
? " [tls]" : "");
687 monitor_printf(mon
, " session: %" PRId64
"\n",
688 chan
->value
->connection_id
);
689 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
690 chan
->value
->channel_type
, chan
->value
->channel_id
);
692 channel_name
= "unknown";
693 if (chan
->value
->channel_type
> 0 &&
694 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
695 channel_names
[chan
->value
->channel_type
]) {
696 channel_name
= channel_names
[chan
->value
->channel_type
];
699 monitor_printf(mon
, " channel name: %s\n", channel_name
);
704 qapi_free_SpiceInfo(info
);
708 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
713 info
= qmp_query_balloon(&err
);
714 if (hmp_handle_error(mon
, err
)) {
718 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
720 qapi_free_BalloonInfo(info
);
723 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
725 PciMemoryRegionList
*region
;
727 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
728 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
729 dev
->slot
, dev
->function
);
730 monitor_printf(mon
, " ");
732 if (dev
->class_info
->has_desc
) {
733 monitor_printf(mon
, "%s", dev
->class_info
->desc
);
735 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
738 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
739 dev
->id
->vendor
, dev
->id
->device
);
740 if (dev
->id
->has_subsystem_vendor
&& dev
->id
->has_subsystem
) {
741 monitor_printf(mon
, " PCI subsystem %04" PRIx64
":%04" PRIx64
"\n",
742 dev
->id
->subsystem_vendor
, dev
->id
->subsystem
);
746 monitor_printf(mon
, " IRQ %" PRId64
", pin %c\n",
747 dev
->irq
, (char)('A' + dev
->irq_pin
- 1));
750 if (dev
->has_pci_bridge
) {
751 monitor_printf(mon
, " BUS %" PRId64
".\n",
752 dev
->pci_bridge
->bus
->number
);
753 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
754 dev
->pci_bridge
->bus
->secondary
);
755 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
756 dev
->pci_bridge
->bus
->subordinate
);
758 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
759 dev
->pci_bridge
->bus
->io_range
->base
,
760 dev
->pci_bridge
->bus
->io_range
->limit
);
763 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
764 dev
->pci_bridge
->bus
->memory_range
->base
,
765 dev
->pci_bridge
->bus
->memory_range
->limit
);
767 monitor_printf(mon
, " prefetchable memory range "
768 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
769 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
770 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
773 for (region
= dev
->regions
; region
; region
= region
->next
) {
776 addr
= region
->value
->address
;
777 size
= region
->value
->size
;
779 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
781 if (!strcmp(region
->value
->type
, "io")) {
782 monitor_printf(mon
, "I/O at 0x%04" PRIx64
783 " [0x%04" PRIx64
"].\n",
784 addr
, addr
+ size
- 1);
786 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
787 " [0x%08" PRIx64
"].\n",
788 region
->value
->mem_type_64
? 64 : 32,
789 region
->value
->prefetch
? " prefetchable" : "",
790 addr
, addr
+ size
- 1);
794 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
796 if (dev
->has_pci_bridge
) {
797 if (dev
->pci_bridge
->has_devices
) {
798 PciDeviceInfoList
*cdev
;
799 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
800 hmp_info_pci_device(mon
, cdev
->value
);
806 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
808 InterruptStatsProvider
*intc
;
809 InterruptStatsProviderClass
*k
;
810 Monitor
*mon
= opaque
;
812 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
813 intc
= INTERRUPT_STATS_PROVIDER(obj
);
814 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
816 k
->print_info(intc
, mon
);
818 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
819 object_get_typename(obj
));
826 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
828 object_child_foreach_recursive(object_get_root(),
829 hmp_info_pic_foreach
, mon
);
832 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
834 PciInfoList
*info_list
, *info
;
837 info_list
= qmp_query_pci(&err
);
839 monitor_printf(mon
, "PCI devices not supported\n");
844 for (info
= info_list
; info
; info
= info
->next
) {
845 PciDeviceInfoList
*dev
;
847 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
848 hmp_info_pci_device(mon
, dev
->value
);
852 qapi_free_PciInfoList(info_list
);
855 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
858 TPMInfoList
*info_list
, *info
;
861 TPMPassthroughOptions
*tpo
;
862 TPMEmulatorOptions
*teo
;
864 info_list
= qmp_query_tpm(&err
);
866 monitor_printf(mon
, "TPM device not supported\n");
872 monitor_printf(mon
, "TPM device:\n");
875 for (info
= info_list
; info
; info
= info
->next
) {
876 TPMInfo
*ti
= info
->value
;
877 monitor_printf(mon
, " tpm%d: model=%s\n",
878 c
, TpmModel_str(ti
->model
));
880 monitor_printf(mon
, " \\ %s: type=%s",
881 ti
->id
, TpmType_str(ti
->options
->type
));
883 switch (ti
->options
->type
) {
884 case TPM_TYPE_PASSTHROUGH
:
885 tpo
= ti
->options
->u
.passthrough
.data
;
886 monitor_printf(mon
, "%s%s%s%s",
887 tpo
->has_path
? ",path=" : "",
888 tpo
->has_path
? tpo
->path
: "",
889 tpo
->has_cancel_path
? ",cancel-path=" : "",
890 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
892 case TPM_TYPE_EMULATOR
:
893 teo
= ti
->options
->u
.emulator
.data
;
894 monitor_printf(mon
, ",chardev=%s", teo
->chardev
);
899 monitor_printf(mon
, "\n");
902 qapi_free_TPMInfoList(info_list
);
904 monitor_printf(mon
, "TPM device not supported\n");
905 #endif /* CONFIG_TPM */
908 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
910 monitor_suspend(mon
);
914 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
919 void hmp_sync_profile(Monitor
*mon
, const QDict
*qdict
)
921 const char *op
= qdict_get_try_str(qdict
, "op");
924 bool on
= qsp_is_enabled();
926 monitor_printf(mon
, "sync-profile is %s\n", on
? "on" : "off");
929 if (!strcmp(op
, "on")) {
931 } else if (!strcmp(op
, "off")) {
933 } else if (!strcmp(op
, "reset")) {
938 error_setg(&err
, QERR_INVALID_PARAMETER
, op
);
939 hmp_handle_error(mon
, err
);
943 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
945 qmp_system_reset(NULL
);
948 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
950 qmp_system_powerdown(NULL
);
953 void hmp_exit_preconfig(Monitor
*mon
, const QDict
*qdict
)
957 qmp_x_exit_preconfig(&err
);
958 hmp_handle_error(mon
, err
);
961 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
965 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
966 use it are converted to the QAPI */
967 cpu_index
= qdict_get_int(qdict
, "index");
968 if (monitor_set_cpu(mon
, cpu_index
) < 0) {
969 monitor_printf(mon
, "invalid CPU index\n");
973 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
975 uint32_t size
= qdict_get_int(qdict
, "size");
976 const char *filename
= qdict_get_str(qdict
, "filename");
977 uint64_t addr
= qdict_get_int(qdict
, "val");
979 int cpu_index
= monitor_get_cpu_index(mon
);
982 monitor_printf(mon
, "No CPU available\n");
986 qmp_memsave(addr
, size
, filename
, true, cpu_index
, &err
);
987 hmp_handle_error(mon
, err
);
990 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
992 uint32_t size
= qdict_get_int(qdict
, "size");
993 const char *filename
= qdict_get_str(qdict
, "filename");
994 uint64_t addr
= qdict_get_int(qdict
, "val");
997 qmp_pmemsave(addr
, size
, filename
, &err
);
998 hmp_handle_error(mon
, err
);
1001 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
1003 const char *chardev
= qdict_get_str(qdict
, "device");
1004 const char *data
= qdict_get_str(qdict
, "data");
1007 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
1009 hmp_handle_error(mon
, err
);
1012 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
1014 uint32_t size
= qdict_get_int(qdict
, "size");
1015 const char *chardev
= qdict_get_str(qdict
, "device");
1020 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
1021 if (hmp_handle_error(mon
, err
)) {
1025 for (i
= 0; data
[i
]; i
++) {
1026 unsigned char ch
= data
[i
];
1029 monitor_printf(mon
, "\\\\");
1030 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
1031 monitor_printf(mon
, "\\u%04X", ch
);
1033 monitor_printf(mon
, "%c", ch
);
1037 monitor_printf(mon
, "\n");
1041 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
1046 hmp_handle_error(mon
, err
);
1049 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
1053 qmp_system_wakeup(&err
);
1054 hmp_handle_error(mon
, err
);
1057 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
1061 qmp_inject_nmi(&err
);
1062 hmp_handle_error(mon
, err
);
1065 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
1067 const char *name
= qdict_get_str(qdict
, "name");
1068 bool up
= qdict_get_bool(qdict
, "up");
1071 qmp_set_link(name
, up
, &err
);
1072 hmp_handle_error(mon
, err
);
1075 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1077 int64_t value
= qdict_get_int(qdict
, "value");
1080 qmp_balloon(value
, &err
);
1081 hmp_handle_error(mon
, err
);
1084 void hmp_loadvm(Monitor
*mon
, const QDict
*qdict
)
1086 int saved_vm_running
= runstate_is_running();
1087 const char *name
= qdict_get_str(qdict
, "name");
1090 vm_stop(RUN_STATE_RESTORE_VM
);
1092 if (load_snapshot(name
, NULL
, false, NULL
, &err
) && saved_vm_running
) {
1095 hmp_handle_error(mon
, err
);
1098 void hmp_savevm(Monitor
*mon
, const QDict
*qdict
)
1102 save_snapshot(qdict_get_try_str(qdict
, "name"),
1103 true, NULL
, false, NULL
, &err
);
1104 hmp_handle_error(mon
, err
);
1107 void hmp_delvm(Monitor
*mon
, const QDict
*qdict
)
1110 const char *name
= qdict_get_str(qdict
, "name");
1112 delete_snapshot(name
, false, NULL
, &err
);
1113 hmp_handle_error(mon
, err
);
1116 void hmp_announce_self(Monitor
*mon
, const QDict
*qdict
)
1118 const char *interfaces_str
= qdict_get_try_str(qdict
, "interfaces");
1119 const char *id
= qdict_get_try_str(qdict
, "id");
1120 AnnounceParameters
*params
= QAPI_CLONE(AnnounceParameters
,
1121 migrate_announce_params());
1123 qapi_free_strList(params
->interfaces
);
1124 params
->interfaces
= strList_from_comma_list(interfaces_str
);
1125 params
->has_interfaces
= params
->interfaces
!= NULL
;
1126 params
->id
= g_strdup(id
);
1127 params
->has_id
= !!params
->id
;
1128 qmp_announce_self(params
, NULL
);
1129 qapi_free_AnnounceParameters(params
);
1132 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1134 qmp_migrate_cancel(NULL
);
1137 void hmp_migrate_continue(Monitor
*mon
, const QDict
*qdict
)
1140 const char *state
= qdict_get_str(qdict
, "state");
1141 int val
= qapi_enum_parse(&MigrationStatus_lookup
, state
, -1, &err
);
1144 qmp_migrate_continue(val
, &err
);
1147 hmp_handle_error(mon
, err
);
1150 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1153 const char *uri
= qdict_get_str(qdict
, "uri");
1155 qmp_migrate_incoming(uri
, &err
);
1157 hmp_handle_error(mon
, err
);
1160 void hmp_migrate_recover(Monitor
*mon
, const QDict
*qdict
)
1163 const char *uri
= qdict_get_str(qdict
, "uri");
1165 qmp_migrate_recover(uri
, &err
);
1167 hmp_handle_error(mon
, err
);
1170 void hmp_migrate_pause(Monitor
*mon
, const QDict
*qdict
)
1174 qmp_migrate_pause(&err
);
1176 hmp_handle_error(mon
, err
);
1180 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1182 const char *cap
= qdict_get_str(qdict
, "capability");
1183 bool state
= qdict_get_bool(qdict
, "state");
1185 MigrationCapabilityStatusList
*caps
= NULL
;
1186 MigrationCapabilityStatus
*value
;
1189 val
= qapi_enum_parse(&MigrationCapability_lookup
, cap
, -1, &err
);
1194 value
= g_malloc0(sizeof(*value
));
1195 value
->capability
= val
;
1196 value
->state
= state
;
1197 QAPI_LIST_PREPEND(caps
, value
);
1198 qmp_migrate_set_capabilities(caps
, &err
);
1199 qapi_free_MigrationCapabilityStatusList(caps
);
1202 hmp_handle_error(mon
, err
);
1205 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1207 const char *param
= qdict_get_str(qdict
, "parameter");
1208 const char *valuestr
= qdict_get_str(qdict
, "value");
1209 Visitor
*v
= string_input_visitor_new(valuestr
);
1210 MigrateSetParameters
*p
= g_new0(MigrateSetParameters
, 1);
1211 uint64_t valuebw
= 0;
1212 uint64_t cache_size
;
1216 val
= qapi_enum_parse(&MigrationParameter_lookup
, param
, -1, &err
);
1222 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1223 p
->has_compress_level
= true;
1224 visit_type_uint8(v
, param
, &p
->compress_level
, &err
);
1226 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1227 p
->has_compress_threads
= true;
1228 visit_type_uint8(v
, param
, &p
->compress_threads
, &err
);
1230 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD
:
1231 p
->has_compress_wait_thread
= true;
1232 visit_type_bool(v
, param
, &p
->compress_wait_thread
, &err
);
1234 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1235 p
->has_decompress_threads
= true;
1236 visit_type_uint8(v
, param
, &p
->decompress_threads
, &err
);
1238 case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD
:
1239 p
->has_throttle_trigger_threshold
= true;
1240 visit_type_uint8(v
, param
, &p
->throttle_trigger_threshold
, &err
);
1242 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1243 p
->has_cpu_throttle_initial
= true;
1244 visit_type_uint8(v
, param
, &p
->cpu_throttle_initial
, &err
);
1246 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1247 p
->has_cpu_throttle_increment
= true;
1248 visit_type_uint8(v
, param
, &p
->cpu_throttle_increment
, &err
);
1250 case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW
:
1251 p
->has_cpu_throttle_tailslow
= true;
1252 visit_type_bool(v
, param
, &p
->cpu_throttle_tailslow
, &err
);
1254 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE
:
1255 p
->has_max_cpu_throttle
= true;
1256 visit_type_uint8(v
, param
, &p
->max_cpu_throttle
, &err
);
1258 case MIGRATION_PARAMETER_TLS_CREDS
:
1259 p
->has_tls_creds
= true;
1260 p
->tls_creds
= g_new0(StrOrNull
, 1);
1261 p
->tls_creds
->type
= QTYPE_QSTRING
;
1262 visit_type_str(v
, param
, &p
->tls_creds
->u
.s
, &err
);
1264 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1265 p
->has_tls_hostname
= true;
1266 p
->tls_hostname
= g_new0(StrOrNull
, 1);
1267 p
->tls_hostname
->type
= QTYPE_QSTRING
;
1268 visit_type_str(v
, param
, &p
->tls_hostname
->u
.s
, &err
);
1270 case MIGRATION_PARAMETER_TLS_AUTHZ
:
1271 p
->has_tls_authz
= true;
1272 p
->tls_authz
= g_new0(StrOrNull
, 1);
1273 p
->tls_authz
->type
= QTYPE_QSTRING
;
1274 visit_type_str(v
, param
, &p
->tls_authz
->u
.s
, &err
);
1276 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1277 p
->has_max_bandwidth
= true;
1279 * Can't use visit_type_size() here, because it
1280 * defaults to Bytes rather than Mebibytes.
1282 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
1283 if (ret
< 0 || valuebw
> INT64_MAX
1284 || (size_t)valuebw
!= valuebw
) {
1285 error_setg(&err
, "Invalid size %s", valuestr
);
1288 p
->max_bandwidth
= valuebw
;
1290 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1291 p
->has_downtime_limit
= true;
1292 visit_type_size(v
, param
, &p
->downtime_limit
, &err
);
1294 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
1295 p
->has_x_checkpoint_delay
= true;
1296 visit_type_uint32(v
, param
, &p
->x_checkpoint_delay
, &err
);
1298 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL
:
1299 p
->has_block_incremental
= true;
1300 visit_type_bool(v
, param
, &p
->block_incremental
, &err
);
1302 case MIGRATION_PARAMETER_MULTIFD_CHANNELS
:
1303 p
->has_multifd_channels
= true;
1304 visit_type_uint8(v
, param
, &p
->multifd_channels
, &err
);
1306 case MIGRATION_PARAMETER_MULTIFD_COMPRESSION
:
1307 p
->has_multifd_compression
= true;
1308 visit_type_MultiFDCompression(v
, param
, &p
->multifd_compression
,
1311 case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL
:
1312 p
->has_multifd_zlib_level
= true;
1313 visit_type_uint8(v
, param
, &p
->multifd_zlib_level
, &err
);
1315 case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL
:
1316 p
->has_multifd_zstd_level
= true;
1317 visit_type_uint8(v
, param
, &p
->multifd_zstd_level
, &err
);
1319 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
:
1320 p
->has_xbzrle_cache_size
= true;
1321 if (!visit_type_size(v
, param
, &cache_size
, &err
)) {
1324 if (cache_size
> INT64_MAX
|| (size_t)cache_size
!= cache_size
) {
1325 error_setg(&err
, "Invalid size %s", valuestr
);
1328 p
->xbzrle_cache_size
= cache_size
;
1330 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH
:
1331 p
->has_max_postcopy_bandwidth
= true;
1332 visit_type_size(v
, param
, &p
->max_postcopy_bandwidth
, &err
);
1334 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL
:
1335 p
->has_announce_initial
= true;
1336 visit_type_size(v
, param
, &p
->announce_initial
, &err
);
1338 case MIGRATION_PARAMETER_ANNOUNCE_MAX
:
1339 p
->has_announce_max
= true;
1340 visit_type_size(v
, param
, &p
->announce_max
, &err
);
1342 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS
:
1343 p
->has_announce_rounds
= true;
1344 visit_type_size(v
, param
, &p
->announce_rounds
, &err
);
1346 case MIGRATION_PARAMETER_ANNOUNCE_STEP
:
1347 p
->has_announce_step
= true;
1348 visit_type_size(v
, param
, &p
->announce_step
, &err
);
1350 case MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING
:
1351 error_setg(&err
, "The block-bitmap-mapping parameter can only be set "
1362 qmp_migrate_set_parameters(p
, &err
);
1365 qapi_free_MigrateSetParameters(p
);
1367 hmp_handle_error(mon
, err
);
1370 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1373 const char *protocol
= qdict_get_str(qdict
, "protocol");
1374 const char *hostname
= qdict_get_str(qdict
, "hostname");
1375 bool has_port
= qdict_haskey(qdict
, "port");
1376 int port
= qdict_get_try_int(qdict
, "port", -1);
1377 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1378 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1379 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1381 qmp_client_migrate_info(protocol
, hostname
,
1382 has_port
, port
, has_tls_port
, tls_port
,
1383 !!cert_subject
, cert_subject
, &err
);
1384 hmp_handle_error(mon
, err
);
1387 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1390 qmp_migrate_start_postcopy(&err
);
1391 hmp_handle_error(mon
, err
);
1394 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1398 qmp_x_colo_lost_heartbeat(&err
);
1399 hmp_handle_error(mon
, err
);
1402 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1404 const char *protocol
= qdict_get_str(qdict
, "protocol");
1405 const char *password
= qdict_get_str(qdict
, "password");
1406 const char *display
= qdict_get_try_str(qdict
, "display");
1407 const char *connected
= qdict_get_try_str(qdict
, "connected");
1410 SetPasswordOptions opts
= {
1411 .password
= (char *)password
,
1412 .has_connected
= !!connected
,
1415 opts
.connected
= qapi_enum_parse(&SetPasswordAction_lookup
, connected
,
1416 SET_PASSWORD_ACTION_KEEP
, &err
);
1421 opts
.protocol
= qapi_enum_parse(&DisplayProtocol_lookup
, protocol
,
1422 DISPLAY_PROTOCOL_VNC
, &err
);
1427 if (opts
.protocol
== DISPLAY_PROTOCOL_VNC
) {
1428 opts
.u
.vnc
.has_display
= !!display
;
1429 opts
.u
.vnc
.display
= (char *)display
;
1432 qmp_set_password(&opts
, &err
);
1435 hmp_handle_error(mon
, err
);
1438 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1440 const char *protocol
= qdict_get_str(qdict
, "protocol");
1441 const char *whenstr
= qdict_get_str(qdict
, "time");
1442 const char *display
= qdict_get_try_str(qdict
, "display");
1445 ExpirePasswordOptions opts
= {
1446 .time
= (char *)whenstr
,
1449 opts
.protocol
= qapi_enum_parse(&DisplayProtocol_lookup
, protocol
,
1450 DISPLAY_PROTOCOL_VNC
, &err
);
1455 if (opts
.protocol
== DISPLAY_PROTOCOL_VNC
) {
1456 opts
.u
.vnc
.has_display
= !!display
;
1457 opts
.u
.vnc
.display
= (char *)display
;
1460 qmp_expire_password(&opts
, &err
);
1463 hmp_handle_error(mon
, err
);
1468 static void hmp_change_read_arg(void *opaque
, const char *password
,
1469 void *readline_opaque
)
1471 qmp_change_vnc_password(password
, NULL
);
1472 monitor_read_command(opaque
, 1);
1476 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1478 const char *device
= qdict_get_str(qdict
, "device");
1479 const char *target
= qdict_get_str(qdict
, "target");
1480 const char *arg
= qdict_get_try_str(qdict
, "arg");
1481 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1482 bool force
= qdict_get_try_bool(qdict
, "force", false);
1483 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1487 if (strcmp(device
, "vnc") == 0) {
1490 "Parameter 'read-only-mode' is invalid for VNC\n");
1493 if (strcmp(target
, "passwd") == 0 ||
1494 strcmp(target
, "password") == 0) {
1496 MonitorHMP
*hmp_mon
= container_of(mon
, MonitorHMP
, common
);
1497 monitor_read_password(hmp_mon
, hmp_change_read_arg
, NULL
);
1500 qmp_change_vnc_password(arg
, &err
);
1503 monitor_printf(mon
, "Expected 'password' after 'vnc'\n");
1510 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup
,
1512 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1518 qmp_blockdev_change_medium(true, device
, false, NULL
, target
,
1519 !!arg
, arg
, true, force
,
1520 !!read_only
, read_only_mode
,
1525 hmp_handle_error(mon
, err
);
1528 typedef struct HMPMigrationStatus
{
1531 bool is_block_migration
;
1532 } HMPMigrationStatus
;
1534 static void hmp_migrate_status_cb(void *opaque
)
1536 HMPMigrationStatus
*status
= opaque
;
1537 MigrationInfo
*info
;
1539 info
= qmp_query_migrate(NULL
);
1540 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1541 info
->status
== MIGRATION_STATUS_SETUP
) {
1542 if (info
->has_disk
) {
1545 if (info
->disk
->remaining
) {
1546 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1551 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1552 monitor_flush(status
->mon
);
1555 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1557 if (status
->is_block_migration
) {
1558 monitor_printf(status
->mon
, "\n");
1560 if (info
->has_error_desc
) {
1561 error_report("%s", info
->error_desc
);
1563 monitor_resume(status
->mon
);
1564 timer_free(status
->timer
);
1568 qapi_free_MigrationInfo(info
);
1571 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1573 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1574 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1575 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1576 bool resume
= qdict_get_try_bool(qdict
, "resume", false);
1577 const char *uri
= qdict_get_str(qdict
, "uri");
1580 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
,
1581 false, false, true, resume
, &err
);
1582 if (hmp_handle_error(mon
, err
)) {
1587 HMPMigrationStatus
*status
;
1589 if (monitor_suspend(mon
) < 0) {
1590 monitor_printf(mon
, "terminal does not allow synchronous "
1591 "migration, continuing detached\n");
1595 status
= g_malloc0(sizeof(*status
));
1597 status
->is_block_migration
= blk
|| inc
;
1598 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1600 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1604 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1608 const char *type
= qdict_get_try_str(qdict
, "type");
1610 if (type
&& is_help_option(type
)) {
1614 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1619 netdev_add(opts
, &err
);
1621 qemu_opts_del(opts
);
1625 hmp_handle_error(mon
, err
);
1628 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1630 const char *id
= qdict_get_str(qdict
, "id");
1633 qmp_netdev_del(id
, &err
);
1634 hmp_handle_error(mon
, err
);
1637 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
1639 const char *options
= qdict_get_str(qdict
, "object");
1642 user_creatable_add_from_str(options
, &err
);
1643 hmp_handle_error(mon
, err
);
1646 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1648 const char *fdname
= qdict_get_str(qdict
, "fdname");
1651 qmp_getfd(fdname
, &err
);
1652 hmp_handle_error(mon
, err
);
1655 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1657 const char *fdname
= qdict_get_str(qdict
, "fdname");
1660 qmp_closefd(fdname
, &err
);
1661 hmp_handle_error(mon
, err
);
1664 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
1666 const char *keys
= qdict_get_str(qdict
, "keys");
1668 KeyValueList
*head
= NULL
, **tail
= &head
;
1669 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1670 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1672 const char *separator
;
1676 separator
= qemu_strchrnul(keys
, '-');
1677 keyname_len
= separator
- keys
;
1679 /* Be compatible with old interface, convert user inputted "<" */
1680 if (keys
[0] == '<' && keyname_len
== 1) {
1685 v
= g_malloc0(sizeof(*v
));
1687 if (strstart(keys
, "0x", NULL
)) {
1689 int value
= strtoul(keys
, &endp
, 0);
1690 assert(endp
<= keys
+ keyname_len
);
1691 if (endp
!= keys
+ keyname_len
) {
1694 v
->type
= KEY_VALUE_KIND_NUMBER
;
1695 v
->u
.number
.data
= value
;
1697 int idx
= index_from_key(keys
, keyname_len
);
1698 if (idx
== Q_KEY_CODE__MAX
) {
1701 v
->type
= KEY_VALUE_KIND_QCODE
;
1702 v
->u
.qcode
.data
= idx
;
1704 QAPI_LIST_APPEND(tail
, v
);
1710 keys
= separator
+ 1;
1713 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1714 hmp_handle_error(mon
, err
);
1717 qapi_free_KeyValue(v
);
1718 qapi_free_KeyValueList(head
);
1722 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
1727 hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
1729 const char *filename
= qdict_get_str(qdict
, "filename");
1730 const char *id
= qdict_get_try_str(qdict
, "device");
1731 int64_t head
= qdict_get_try_int(qdict
, "head", 0);
1732 const char *input_format
= qdict_get_try_str(qdict
, "format");
1736 format
= qapi_enum_parse(&ImageFormat_lookup
, input_format
,
1737 IMAGE_FORMAT_PPM
, &err
);
1742 qmp_screendump(filename
, id
!= NULL
, id
, id
!= NULL
, head
,
1743 input_format
!= NULL
, format
, &err
);
1745 hmp_handle_error(mon
, err
);
1748 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
1750 const char *args
= qdict_get_str(qdict
, "args");
1754 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
1756 error_setg(&err
, "Parsing chardev args failed");
1758 qemu_chr_new_from_opts(opts
, NULL
, &err
);
1759 qemu_opts_del(opts
);
1761 hmp_handle_error(mon
, err
);
1764 void hmp_chardev_change(Monitor
*mon
, const QDict
*qdict
)
1766 const char *args
= qdict_get_str(qdict
, "args");
1769 ChardevBackend
*backend
= NULL
;
1770 ChardevReturn
*ret
= NULL
;
1771 QemuOpts
*opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
,
1774 error_setg(&err
, "Parsing chardev args failed");
1778 id
= qdict_get_str(qdict
, "id");
1779 if (qemu_opts_id(opts
)) {
1780 error_setg(&err
, "Unexpected 'id' parameter");
1784 backend
= qemu_chr_parse_opts(opts
, &err
);
1789 ret
= qmp_chardev_change(id
, backend
, &err
);
1792 qapi_free_ChardevReturn(ret
);
1793 qapi_free_ChardevBackend(backend
);
1794 qemu_opts_del(opts
);
1795 hmp_handle_error(mon
, err
);
1798 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
1800 Error
*local_err
= NULL
;
1802 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
1803 hmp_handle_error(mon
, local_err
);
1806 void hmp_chardev_send_break(Monitor
*mon
, const QDict
*qdict
)
1808 Error
*local_err
= NULL
;
1810 qmp_chardev_send_break(qdict_get_str(qdict
, "id"), &local_err
);
1811 hmp_handle_error(mon
, local_err
);
1814 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
1816 const char *id
= qdict_get_str(qdict
, "id");
1819 user_creatable_del(id
, &err
);
1820 hmp_handle_error(mon
, err
);
1823 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
1826 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
1827 MemoryDeviceInfoList
*info
;
1828 VirtioPMEMDeviceInfo
*vpi
;
1829 VirtioMEMDeviceInfo
*vmi
;
1830 MemoryDeviceInfo
*value
;
1831 PCDIMMDeviceInfo
*di
;
1832 SgxEPCDeviceInfo
*se
;
1834 for (info
= info_list
; info
; info
= info
->next
) {
1835 value
= info
->value
;
1838 switch (value
->type
) {
1839 case MEMORY_DEVICE_INFO_KIND_DIMM
:
1840 case MEMORY_DEVICE_INFO_KIND_NVDIMM
:
1841 di
= value
->type
== MEMORY_DEVICE_INFO_KIND_DIMM
?
1842 value
->u
.dimm
.data
: value
->u
.nvdimm
.data
;
1843 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1844 MemoryDeviceInfoKind_str(value
->type
),
1845 di
->id
? di
->id
: "");
1846 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
1847 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
1848 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
1849 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
1850 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
1851 monitor_printf(mon
, " hotplugged: %s\n",
1852 di
->hotplugged
? "true" : "false");
1853 monitor_printf(mon
, " hotpluggable: %s\n",
1854 di
->hotpluggable
? "true" : "false");
1856 case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM
:
1857 vpi
= value
->u
.virtio_pmem
.data
;
1858 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1859 MemoryDeviceInfoKind_str(value
->type
),
1860 vpi
->id
? vpi
->id
: "");
1861 monitor_printf(mon
, " memaddr: 0x%" PRIx64
"\n", vpi
->memaddr
);
1862 monitor_printf(mon
, " size: %" PRIu64
"\n", vpi
->size
);
1863 monitor_printf(mon
, " memdev: %s\n", vpi
->memdev
);
1865 case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM
:
1866 vmi
= value
->u
.virtio_mem
.data
;
1867 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1868 MemoryDeviceInfoKind_str(value
->type
),
1869 vmi
->id
? vmi
->id
: "");
1870 monitor_printf(mon
, " memaddr: 0x%" PRIx64
"\n", vmi
->memaddr
);
1871 monitor_printf(mon
, " node: %" PRId64
"\n", vmi
->node
);
1872 monitor_printf(mon
, " requested-size: %" PRIu64
"\n",
1873 vmi
->requested_size
);
1874 monitor_printf(mon
, " size: %" PRIu64
"\n", vmi
->size
);
1875 monitor_printf(mon
, " max-size: %" PRIu64
"\n", vmi
->max_size
);
1876 monitor_printf(mon
, " block-size: %" PRIu64
"\n",
1878 monitor_printf(mon
, " memdev: %s\n", vmi
->memdev
);
1880 case MEMORY_DEVICE_INFO_KIND_SGX_EPC
:
1881 se
= value
->u
.sgx_epc
.data
;
1882 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1883 MemoryDeviceInfoKind_str(value
->type
),
1884 se
->id
? se
->id
: "");
1885 monitor_printf(mon
, " memaddr: 0x%" PRIx64
"\n", se
->memaddr
);
1886 monitor_printf(mon
, " size: %" PRIu64
"\n", se
->size
);
1887 monitor_printf(mon
, " node: %" PRId64
"\n", se
->node
);
1888 monitor_printf(mon
, " memdev: %s\n", se
->memdev
);
1891 g_assert_not_reached();
1896 qapi_free_MemoryDeviceInfoList(info_list
);
1897 hmp_handle_error(mon
, err
);
1900 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
1902 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
1903 IOThreadInfoList
*info
;
1904 IOThreadInfo
*value
;
1906 for (info
= info_list
; info
; info
= info
->next
) {
1907 value
= info
->value
;
1908 monitor_printf(mon
, "%s:\n", value
->id
);
1909 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
1910 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
1911 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
1912 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
1913 monitor_printf(mon
, " aio-max-batch=%" PRId64
"\n",
1914 value
->aio_max_batch
);
1917 qapi_free_IOThreadInfoList(info_list
);
1920 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
1922 const char *name
= qdict_get_str(qdict
, "name");
1923 RockerSwitch
*rocker
;
1926 rocker
= qmp_query_rocker(name
, &err
);
1927 if (hmp_handle_error(mon
, err
)) {
1931 monitor_printf(mon
, "name: %s\n", rocker
->name
);
1932 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
1933 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
1935 qapi_free_RockerSwitch(rocker
);
1938 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
1940 RockerPortList
*list
, *port
;
1941 const char *name
= qdict_get_str(qdict
, "name");
1944 list
= qmp_query_rocker_ports(name
, &err
);
1945 if (hmp_handle_error(mon
, err
)) {
1949 monitor_printf(mon
, " ena/ speed/ auto\n");
1950 monitor_printf(mon
, " port link duplex neg?\n");
1952 for (port
= list
; port
; port
= port
->next
) {
1953 monitor_printf(mon
, "%10s %-4s %-3s %2s %s\n",
1955 port
->value
->enabled
? port
->value
->link_up
?
1956 "up" : "down" : "!ena",
1957 port
->value
->speed
== 10000 ? "10G" : "??",
1958 port
->value
->duplex
? "FD" : "HD",
1959 port
->value
->autoneg
? "Yes" : "No");
1962 qapi_free_RockerPortList(list
);
1965 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
1967 RockerOfDpaFlowList
*list
, *info
;
1968 const char *name
= qdict_get_str(qdict
, "name");
1969 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
1972 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
1973 if (hmp_handle_error(mon
, err
)) {
1977 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
1979 for (info
= list
; info
; info
= info
->next
) {
1980 RockerOfDpaFlow
*flow
= info
->value
;
1981 RockerOfDpaFlowKey
*key
= flow
->key
;
1982 RockerOfDpaFlowMask
*mask
= flow
->mask
;
1983 RockerOfDpaFlowAction
*action
= flow
->action
;
1986 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
1987 key
->priority
, key
->tbl_id
, flow
->hits
);
1989 monitor_printf(mon
, "%-4d %-3d ",
1990 key
->priority
, key
->tbl_id
);
1993 if (key
->has_in_pport
) {
1994 monitor_printf(mon
, " pport %d", key
->in_pport
);
1995 if (mask
->has_in_pport
) {
1996 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2000 if (key
->has_vlan_id
) {
2001 monitor_printf(mon
, " vlan %d",
2002 key
->vlan_id
& VLAN_VID_MASK
);
2003 if (mask
->has_vlan_id
) {
2004 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2008 if (key
->has_tunnel_id
) {
2009 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2010 if (mask
->has_tunnel_id
) {
2011 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2015 if (key
->has_eth_type
) {
2016 switch (key
->eth_type
) {
2018 monitor_printf(mon
, " ARP");
2021 monitor_printf(mon
, " IP");
2024 monitor_printf(mon
, " IPv6");
2027 monitor_printf(mon
, " LACP");
2030 monitor_printf(mon
, " LLDP");
2033 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2038 if (key
->has_eth_src
) {
2039 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2040 (mask
->has_eth_src
) &&
2041 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2042 monitor_printf(mon
, " src <any mcast/bcast>");
2043 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2044 (mask
->has_eth_src
) &&
2045 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2046 monitor_printf(mon
, " src <any ucast>");
2048 monitor_printf(mon
, " src %s", key
->eth_src
);
2049 if (mask
->has_eth_src
) {
2050 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2055 if (key
->has_eth_dst
) {
2056 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2057 (mask
->has_eth_dst
) &&
2058 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2059 monitor_printf(mon
, " dst <any mcast/bcast>");
2060 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2061 (mask
->has_eth_dst
) &&
2062 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2063 monitor_printf(mon
, " dst <any ucast>");
2065 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2066 if (mask
->has_eth_dst
) {
2067 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2072 if (key
->has_ip_proto
) {
2073 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2074 if (mask
->has_ip_proto
) {
2075 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2079 if (key
->has_ip_tos
) {
2080 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2081 if (mask
->has_ip_tos
) {
2082 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2086 if (key
->has_ip_dst
) {
2087 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2090 if (action
->has_goto_tbl
|| action
->has_group_id
||
2091 action
->has_new_vlan_id
) {
2092 monitor_printf(mon
, " -->");
2095 if (action
->has_new_vlan_id
) {
2096 monitor_printf(mon
, " apply new vlan %d",
2097 ntohs(action
->new_vlan_id
));
2100 if (action
->has_group_id
) {
2101 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2104 if (action
->has_goto_tbl
) {
2105 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2108 monitor_printf(mon
, "\n");
2111 qapi_free_RockerOfDpaFlowList(list
);
2114 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2116 RockerOfDpaGroupList
*list
, *g
;
2117 const char *name
= qdict_get_str(qdict
, "name");
2118 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2121 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
2122 if (hmp_handle_error(mon
, err
)) {
2126 monitor_printf(mon
, "id (decode) --> buckets\n");
2128 for (g
= list
; g
; g
= g
->next
) {
2129 RockerOfDpaGroup
*group
= g
->value
;
2132 monitor_printf(mon
, "0x%08x", group
->id
);
2134 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2135 group
->type
== 1 ? "L2 rewrite" :
2136 group
->type
== 2 ? "L3 unicast" :
2137 group
->type
== 3 ? "L2 multicast" :
2138 group
->type
== 4 ? "L2 flood" :
2139 group
->type
== 5 ? "L3 interface" :
2140 group
->type
== 6 ? "L3 multicast" :
2141 group
->type
== 7 ? "L3 ECMP" :
2142 group
->type
== 8 ? "L2 overlay" :
2145 if (group
->has_vlan_id
) {
2146 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2149 if (group
->has_pport
) {
2150 monitor_printf(mon
, " pport %d", group
->pport
);
2153 if (group
->has_index
) {
2154 monitor_printf(mon
, " index %d", group
->index
);
2157 monitor_printf(mon
, ") -->");
2159 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2161 monitor_printf(mon
, " set vlan %d",
2162 group
->set_vlan_id
& VLAN_VID_MASK
);
2165 if (group
->has_set_eth_src
) {
2168 monitor_printf(mon
, " set");
2170 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2173 if (group
->has_set_eth_dst
) {
2175 monitor_printf(mon
, " set");
2177 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2180 if (group
->has_ttl_check
&& group
->ttl_check
) {
2181 monitor_printf(mon
, " check TTL");
2184 if (group
->has_group_id
&& group
->group_id
) {
2185 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2188 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2189 monitor_printf(mon
, " pop vlan");
2192 if (group
->has_out_pport
) {
2193 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2196 if (group
->has_group_ids
) {
2197 struct uint32List
*id
;
2199 monitor_printf(mon
, " groups [");
2200 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2201 monitor_printf(mon
, "0x%08x", id
->value
);
2203 monitor_printf(mon
, ",");
2206 monitor_printf(mon
, "]");
2209 monitor_printf(mon
, "\n");
2212 qapi_free_RockerOfDpaGroupList(list
);
2215 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
2218 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
2220 monitor_printf(mon
, "%s\n", info
->guid
);
2222 hmp_handle_error(mon
, err
);
2223 qapi_free_GuidInfo(info
);
2226 void hmp_info_memory_size_summary(Monitor
*mon
, const QDict
*qdict
)
2229 MemoryInfo
*info
= qmp_query_memory_size_summary(&err
);
2231 monitor_printf(mon
, "base memory: %" PRIu64
"\n",
2234 if (info
->has_plugged_memory
) {
2235 monitor_printf(mon
, "plugged memory: %" PRIu64
"\n",
2236 info
->plugged_memory
);
2239 qapi_free_MemoryInfo(info
);
2241 hmp_handle_error(mon
, err
);
2244 static void print_stats_schema_value(Monitor
*mon
, StatsSchemaValue
*value
)
2246 const char *unit
= NULL
;
2247 monitor_printf(mon
, " %s (%s%s", value
->name
, StatsType_str(value
->type
),
2248 value
->has_unit
|| value
->exponent
? ", " : "");
2250 if (value
->has_unit
) {
2251 if (value
->unit
== STATS_UNIT_SECONDS
) {
2253 } else if (value
->unit
== STATS_UNIT_BYTES
) {
2258 if (unit
&& value
->base
== 10 &&
2259 value
->exponent
>= -18 && value
->exponent
<= 18 &&
2260 value
->exponent
% 3 == 0) {
2261 monitor_printf(mon
, "%s", si_prefix(value
->exponent
));
2262 } else if (unit
&& value
->base
== 2 &&
2263 value
->exponent
>= 0 && value
->exponent
<= 60 &&
2264 value
->exponent
% 10 == 0) {
2266 monitor_printf(mon
, "%s", iec_binary_prefix(value
->exponent
));
2267 } else if (value
->exponent
) {
2268 /* Use exponential notation and write the unit's English name */
2269 monitor_printf(mon
, "* %d^%d%s",
2270 value
->base
, value
->exponent
,
2271 value
->has_unit
? " " : "");
2275 if (value
->has_unit
) {
2276 monitor_printf(mon
, "%s", unit
? unit
: StatsUnit_str(value
->unit
));
2279 /* Print bucket size for linear histograms */
2280 if (value
->type
== STATS_TYPE_LINEAR_HISTOGRAM
&& value
->has_bucket_size
) {
2281 monitor_printf(mon
, ", bucket size=%d", value
->bucket_size
);
2283 monitor_printf(mon
, ")");
2286 static StatsSchemaValueList
*find_schema_value_list(
2287 StatsSchemaList
*list
, StatsProvider provider
,
2290 StatsSchemaList
*node
;
2292 for (node
= list
; node
; node
= node
->next
) {
2293 if (node
->value
->provider
== provider
&&
2294 node
->value
->target
== target
) {
2295 return node
->value
->stats
;
2301 static void print_stats_results(Monitor
*mon
, StatsTarget target
,
2303 StatsResult
*result
,
2304 StatsSchemaList
*schema
)
2306 /* Find provider schema */
2307 StatsSchemaValueList
*schema_value_list
=
2308 find_schema_value_list(schema
, result
->provider
, target
);
2309 StatsList
*stats_list
;
2311 if (!schema_value_list
) {
2312 monitor_printf(mon
, "failed to find schema list for %s\n",
2313 StatsProvider_str(result
->provider
));
2317 if (show_provider
) {
2318 monitor_printf(mon
, "provider: %s\n",
2319 StatsProvider_str(result
->provider
));
2322 for (stats_list
= result
->stats
; stats_list
;
2323 stats_list
= stats_list
->next
,
2324 schema_value_list
= schema_value_list
->next
) {
2326 Stats
*stats
= stats_list
->value
;
2327 StatsValue
*stats_value
= stats
->value
;
2328 StatsSchemaValue
*schema_value
= schema_value_list
->value
;
2330 /* Find schema entry */
2331 while (!g_str_equal(stats
->name
, schema_value
->name
)) {
2332 if (!schema_value_list
->next
) {
2333 monitor_printf(mon
, "failed to find schema entry for %s\n",
2337 schema_value_list
= schema_value_list
->next
;
2338 schema_value
= schema_value_list
->value
;
2341 print_stats_schema_value(mon
, schema_value
);
2343 if (stats_value
->type
== QTYPE_QNUM
) {
2344 monitor_printf(mon
, ": %" PRId64
"\n", stats_value
->u
.scalar
);
2345 } else if (stats_value
->type
== QTYPE_QBOOL
) {
2346 monitor_printf(mon
, ": %s\n", stats_value
->u
.boolean
? "yes" : "no");
2347 } else if (stats_value
->type
== QTYPE_QLIST
) {
2351 monitor_printf(mon
, ": ");
2352 for (list
= stats_value
->u
.list
, i
= 1;
2354 list
= list
->next
, i
++) {
2355 monitor_printf(mon
, "[%d]=%" PRId64
" ", i
, list
->value
);
2357 monitor_printf(mon
, "\n");
2362 /* Create the StatsFilter that is needed for an "info stats" invocation. */
2363 static StatsFilter
*stats_filter(StatsTarget target
, const char *names
,
2364 int cpu_index
, StatsProvider provider
)
2366 StatsFilter
*filter
= g_malloc0(sizeof(*filter
));
2367 StatsProvider provider_idx
;
2368 StatsRequestList
*request_list
= NULL
;
2370 filter
->target
= target
;
2372 case STATS_TARGET_VM
:
2374 case STATS_TARGET_VCPU
:
2376 strList
*vcpu_list
= NULL
;
2377 CPUState
*cpu
= qemu_get_cpu(cpu_index
);
2378 char *canonical_path
= object_get_canonical_path(OBJECT(cpu
));
2380 QAPI_LIST_PREPEND(vcpu_list
, canonical_path
);
2381 filter
->u
.vcpu
.has_vcpus
= true;
2382 filter
->u
.vcpu
.vcpus
= vcpu_list
;
2389 if (!names
&& provider
== STATS_PROVIDER__MAX
) {
2394 * "info stats" can only query either one or all the providers. Querying
2395 * by name, but not by provider, requires the creation of one filter per
2398 for (provider_idx
= 0; provider_idx
< STATS_PROVIDER__MAX
; provider_idx
++) {
2399 if (provider
== STATS_PROVIDER__MAX
|| provider
== provider_idx
) {
2400 StatsRequest
*request
= g_new0(StatsRequest
, 1);
2401 request
->provider
= provider_idx
;
2402 if (names
&& !g_str_equal(names
, "*")) {
2403 request
->has_names
= true;
2404 request
->names
= strList_from_comma_list(names
);
2406 QAPI_LIST_PREPEND(request_list
, request
);
2410 filter
->has_providers
= true;
2411 filter
->providers
= request_list
;
2415 void hmp_info_stats(Monitor
*mon
, const QDict
*qdict
)
2417 const char *target_str
= qdict_get_str(qdict
, "target");
2418 const char *provider_str
= qdict_get_try_str(qdict
, "provider");
2419 const char *names
= qdict_get_try_str(qdict
, "names");
2421 StatsProvider provider
= STATS_PROVIDER__MAX
;
2424 g_autoptr(StatsSchemaList
) schema
= NULL
;
2425 g_autoptr(StatsResultList
) stats
= NULL
;
2426 g_autoptr(StatsFilter
) filter
= NULL
;
2427 StatsResultList
*entry
;
2429 target
= qapi_enum_parse(&StatsTarget_lookup
, target_str
, -1, &err
);
2431 monitor_printf(mon
, "invalid stats target %s\n", target_str
);
2435 provider
= qapi_enum_parse(&StatsProvider_lookup
, provider_str
, -1, &err
);
2437 monitor_printf(mon
, "invalid stats provider %s\n", provider_str
);
2442 schema
= qmp_query_stats_schemas(provider_str
? true : false,
2449 case STATS_TARGET_VM
:
2450 filter
= stats_filter(target
, names
, -1, provider
);
2452 case STATS_TARGET_VCPU
: {}
2453 int cpu_index
= monitor_get_cpu_index(mon
);
2454 filter
= stats_filter(target
, names
, cpu_index
, provider
);
2460 stats
= qmp_query_stats(filter
, &err
);
2464 for (entry
= stats
; entry
; entry
= entry
->next
) {
2465 print_stats_results(mon
, target
, provider_str
== NULL
, entry
->value
, schema
);
2470 monitor_printf(mon
, "%s\n", error_get_pretty(err
));