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);
312 if (info
->has_disk
) {
313 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
314 info
->disk
->transferred
>> 10);
315 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
316 info
->disk
->remaining
>> 10);
317 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
318 info
->disk
->total
>> 10);
321 if (info
->has_xbzrle_cache
) {
322 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
323 info
->xbzrle_cache
->cache_size
);
324 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
325 info
->xbzrle_cache
->bytes
>> 10);
326 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
327 info
->xbzrle_cache
->pages
);
328 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
" pages\n",
329 info
->xbzrle_cache
->cache_miss
);
330 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
331 info
->xbzrle_cache
->cache_miss_rate
);
332 monitor_printf(mon
, "xbzrle encoding rate: %0.2f\n",
333 info
->xbzrle_cache
->encoding_rate
);
334 monitor_printf(mon
, "xbzrle overflow: %" PRIu64
"\n",
335 info
->xbzrle_cache
->overflow
);
338 if (info
->has_compression
) {
339 monitor_printf(mon
, "compression pages: %" PRIu64
" pages\n",
340 info
->compression
->pages
);
341 monitor_printf(mon
, "compression busy: %" PRIu64
"\n",
342 info
->compression
->busy
);
343 monitor_printf(mon
, "compression busy rate: %0.2f\n",
344 info
->compression
->busy_rate
);
345 monitor_printf(mon
, "compressed size: %" PRIu64
" kbytes\n",
346 info
->compression
->compressed_size
>> 10);
347 monitor_printf(mon
, "compression rate: %0.2f\n",
348 info
->compression
->compression_rate
);
351 if (info
->has_cpu_throttle_percentage
) {
352 monitor_printf(mon
, "cpu throttle percentage: %" PRIu64
"\n",
353 info
->cpu_throttle_percentage
);
356 if (info
->has_postcopy_blocktime
) {
357 monitor_printf(mon
, "postcopy blocktime: %u\n",
358 info
->postcopy_blocktime
);
361 if (info
->has_postcopy_vcpu_blocktime
) {
364 v
= string_output_visitor_new(false, &str
);
365 visit_type_uint32List(v
, NULL
, &info
->postcopy_vcpu_blocktime
,
367 visit_complete(v
, &str
);
368 monitor_printf(mon
, "postcopy vcpu blocktime: %s\n", str
);
372 if (info
->has_socket_address
) {
373 SocketAddressList
*addr
;
375 monitor_printf(mon
, "socket address: [\n");
377 for (addr
= info
->socket_address
; addr
; addr
= addr
->next
) {
378 char *s
= SocketAddress_to_str(addr
->value
);
379 monitor_printf(mon
, "\t%s\n", s
);
382 monitor_printf(mon
, "]\n");
385 if (info
->has_vfio
) {
386 monitor_printf(mon
, "vfio device transferred: %" PRIu64
" kbytes\n",
387 info
->vfio
->transferred
>> 10);
390 qapi_free_MigrationInfo(info
);
393 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
395 MigrationCapabilityStatusList
*caps
, *cap
;
397 caps
= qmp_query_migrate_capabilities(NULL
);
400 for (cap
= caps
; cap
; cap
= cap
->next
) {
401 monitor_printf(mon
, "%s: %s\n",
402 MigrationCapability_str(cap
->value
->capability
),
403 cap
->value
->state
? "on" : "off");
407 qapi_free_MigrationCapabilityStatusList(caps
);
410 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
412 MigrationParameters
*params
;
414 params
= qmp_query_migrate_parameters(NULL
);
417 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
418 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL
),
419 params
->announce_initial
);
420 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
421 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX
),
422 params
->announce_max
);
423 monitor_printf(mon
, "%s: %" PRIu64
"\n",
424 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS
),
425 params
->announce_rounds
);
426 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
427 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP
),
428 params
->announce_step
);
429 assert(params
->has_compress_level
);
430 monitor_printf(mon
, "%s: %u\n",
431 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL
),
432 params
->compress_level
);
433 assert(params
->has_compress_threads
);
434 monitor_printf(mon
, "%s: %u\n",
435 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS
),
436 params
->compress_threads
);
437 assert(params
->has_compress_wait_thread
);
438 monitor_printf(mon
, "%s: %s\n",
439 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD
),
440 params
->compress_wait_thread
? "on" : "off");
441 assert(params
->has_decompress_threads
);
442 monitor_printf(mon
, "%s: %u\n",
443 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS
),
444 params
->decompress_threads
);
445 assert(params
->has_throttle_trigger_threshold
);
446 monitor_printf(mon
, "%s: %u\n",
447 MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD
),
448 params
->throttle_trigger_threshold
);
449 assert(params
->has_cpu_throttle_initial
);
450 monitor_printf(mon
, "%s: %u\n",
451 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
),
452 params
->cpu_throttle_initial
);
453 assert(params
->has_cpu_throttle_increment
);
454 monitor_printf(mon
, "%s: %u\n",
455 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
),
456 params
->cpu_throttle_increment
);
457 assert(params
->has_cpu_throttle_tailslow
);
458 monitor_printf(mon
, "%s: %s\n",
459 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW
),
460 params
->cpu_throttle_tailslow
? "on" : "off");
461 assert(params
->has_max_cpu_throttle
);
462 monitor_printf(mon
, "%s: %u\n",
463 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE
),
464 params
->max_cpu_throttle
);
465 assert(params
->has_tls_creds
);
466 monitor_printf(mon
, "%s: '%s'\n",
467 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS
),
469 assert(params
->has_tls_hostname
);
470 monitor_printf(mon
, "%s: '%s'\n",
471 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME
),
472 params
->tls_hostname
);
473 assert(params
->has_max_bandwidth
);
474 monitor_printf(mon
, "%s: %" PRIu64
" bytes/second\n",
475 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH
),
476 params
->max_bandwidth
);
477 assert(params
->has_downtime_limit
);
478 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
479 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT
),
480 params
->downtime_limit
);
481 assert(params
->has_x_checkpoint_delay
);
482 monitor_printf(mon
, "%s: %u ms\n",
483 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
),
484 params
->x_checkpoint_delay
);
485 assert(params
->has_block_incremental
);
486 monitor_printf(mon
, "%s: %s\n",
487 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL
),
488 params
->block_incremental
? "on" : "off");
489 monitor_printf(mon
, "%s: %u\n",
490 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS
),
491 params
->multifd_channels
);
492 monitor_printf(mon
, "%s: %s\n",
493 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION
),
494 MultiFDCompression_str(params
->multifd_compression
));
495 monitor_printf(mon
, "%s: %" PRIu64
" bytes\n",
496 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
),
497 params
->xbzrle_cache_size
);
498 monitor_printf(mon
, "%s: %" PRIu64
"\n",
499 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH
),
500 params
->max_postcopy_bandwidth
);
501 monitor_printf(mon
, "%s: '%s'\n",
502 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ
),
505 if (params
->has_block_bitmap_mapping
) {
506 const BitmapMigrationNodeAliasList
*bmnal
;
508 monitor_printf(mon
, "%s:\n",
509 MigrationParameter_str(
510 MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING
));
512 for (bmnal
= params
->block_bitmap_mapping
;
516 const BitmapMigrationNodeAlias
*bmna
= bmnal
->value
;
517 const BitmapMigrationBitmapAliasList
*bmbal
;
519 monitor_printf(mon
, " '%s' -> '%s'\n",
520 bmna
->node_name
, bmna
->alias
);
522 for (bmbal
= bmna
->bitmaps
; bmbal
; bmbal
= bmbal
->next
) {
523 const BitmapMigrationBitmapAlias
*bmba
= bmbal
->value
;
525 monitor_printf(mon
, " '%s' -> '%s'\n",
526 bmba
->name
, bmba
->alias
);
532 qapi_free_MigrationParameters(params
);
537 /* Helper for hmp_info_vnc_clients, _servers */
538 static void hmp_info_VncBasicInfo(Monitor
*mon
, VncBasicInfo
*info
,
541 monitor_printf(mon
, " %s: %s:%s (%s%s)\n",
545 NetworkAddressFamily_str(info
->family
),
546 info
->websocket
? " (Websocket)" : "");
549 /* Helper displaying and auth and crypt info */
550 static void hmp_info_vnc_authcrypt(Monitor
*mon
, const char *indent
,
552 VncVencryptSubAuth
*vencrypt
)
554 monitor_printf(mon
, "%sAuth: %s (Sub: %s)\n", indent
,
555 VncPrimaryAuth_str(auth
),
556 vencrypt
? VncVencryptSubAuth_str(*vencrypt
) : "none");
559 static void hmp_info_vnc_clients(Monitor
*mon
, VncClientInfoList
*client
)
562 VncClientInfo
*cinfo
= client
->value
;
564 hmp_info_VncBasicInfo(mon
, qapi_VncClientInfo_base(cinfo
), "Client");
565 monitor_printf(mon
, " x509_dname: %s\n",
566 cinfo
->has_x509_dname
?
567 cinfo
->x509_dname
: "none");
568 monitor_printf(mon
, " sasl_username: %s\n",
569 cinfo
->has_sasl_username
?
570 cinfo
->sasl_username
: "none");
572 client
= client
->next
;
576 static void hmp_info_vnc_servers(Monitor
*mon
, VncServerInfo2List
*server
)
579 VncServerInfo2
*sinfo
= server
->value
;
580 hmp_info_VncBasicInfo(mon
, qapi_VncServerInfo2_base(sinfo
), "Server");
581 hmp_info_vnc_authcrypt(mon
, " ", sinfo
->auth
,
582 sinfo
->has_vencrypt
? &sinfo
->vencrypt
: NULL
);
583 server
= server
->next
;
587 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
589 VncInfo2List
*info2l
, *info2l_head
;
592 info2l
= qmp_query_vnc_servers(&err
);
593 info2l_head
= info2l
;
594 if (hmp_handle_error(mon
, err
)) {
598 monitor_printf(mon
, "None\n");
603 VncInfo2
*info
= info2l
->value
;
604 monitor_printf(mon
, "%s:\n", info
->id
);
605 hmp_info_vnc_servers(mon
, info
->server
);
606 hmp_info_vnc_clients(mon
, info
->clients
);
608 /* The server entry displays its auth, we only
609 * need to display in the case of 'reverse' connections
610 * where there's no server.
612 hmp_info_vnc_authcrypt(mon
, " ", info
->auth
,
613 info
->has_vencrypt
? &info
->vencrypt
: NULL
);
615 if (info
->has_display
) {
616 monitor_printf(mon
, " Display: %s\n", info
->display
);
618 info2l
= info2l
->next
;
621 qapi_free_VncInfo2List(info2l_head
);
627 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
629 SpiceChannelList
*chan
;
631 const char *channel_name
;
632 const char * const channel_names
[] = {
633 [SPICE_CHANNEL_MAIN
] = "main",
634 [SPICE_CHANNEL_DISPLAY
] = "display",
635 [SPICE_CHANNEL_INPUTS
] = "inputs",
636 [SPICE_CHANNEL_CURSOR
] = "cursor",
637 [SPICE_CHANNEL_PLAYBACK
] = "playback",
638 [SPICE_CHANNEL_RECORD
] = "record",
639 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
640 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
641 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
642 [SPICE_CHANNEL_PORT
] = "port",
644 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
645 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
646 * as quick fix for build failures with older versions. */
647 [SPICE_CHANNEL_WEBDAV
] = "webdav",
651 info
= qmp_query_spice(NULL
);
653 if (!info
->enabled
) {
654 monitor_printf(mon
, "Server: disabled\n");
658 monitor_printf(mon
, "Server:\n");
659 if (info
->has_port
) {
660 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
661 info
->host
, info
->port
);
663 if (info
->has_tls_port
) {
664 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
665 info
->host
, info
->tls_port
);
667 monitor_printf(mon
, " migrated: %s\n",
668 info
->migrated
? "true" : "false");
669 monitor_printf(mon
, " auth: %s\n", info
->auth
);
670 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
671 monitor_printf(mon
, " mouse-mode: %s\n",
672 SpiceQueryMouseMode_str(info
->mouse_mode
));
674 if (!info
->has_channels
|| info
->channels
== NULL
) {
675 monitor_printf(mon
, "Channels: none\n");
677 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
678 monitor_printf(mon
, "Channel:\n");
679 monitor_printf(mon
, " address: %s:%s%s\n",
680 chan
->value
->host
, chan
->value
->port
,
681 chan
->value
->tls
? " [tls]" : "");
682 monitor_printf(mon
, " session: %" PRId64
"\n",
683 chan
->value
->connection_id
);
684 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
685 chan
->value
->channel_type
, chan
->value
->channel_id
);
687 channel_name
= "unknown";
688 if (chan
->value
->channel_type
> 0 &&
689 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
690 channel_names
[chan
->value
->channel_type
]) {
691 channel_name
= channel_names
[chan
->value
->channel_type
];
694 monitor_printf(mon
, " channel name: %s\n", channel_name
);
699 qapi_free_SpiceInfo(info
);
703 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
708 info
= qmp_query_balloon(&err
);
709 if (hmp_handle_error(mon
, err
)) {
713 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
715 qapi_free_BalloonInfo(info
);
718 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
720 PciMemoryRegionList
*region
;
722 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
723 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
724 dev
->slot
, dev
->function
);
725 monitor_printf(mon
, " ");
727 if (dev
->class_info
->has_desc
) {
728 monitor_printf(mon
, "%s", dev
->class_info
->desc
);
730 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
733 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
734 dev
->id
->vendor
, dev
->id
->device
);
735 if (dev
->id
->has_subsystem_vendor
&& dev
->id
->has_subsystem
) {
736 monitor_printf(mon
, " PCI subsystem %04" PRIx64
":%04" PRIx64
"\n",
737 dev
->id
->subsystem_vendor
, dev
->id
->subsystem
);
741 monitor_printf(mon
, " IRQ %" PRId64
", pin %c\n",
742 dev
->irq
, (char)('A' + dev
->irq_pin
- 1));
745 if (dev
->has_pci_bridge
) {
746 monitor_printf(mon
, " BUS %" PRId64
".\n",
747 dev
->pci_bridge
->bus
->number
);
748 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
749 dev
->pci_bridge
->bus
->secondary
);
750 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
751 dev
->pci_bridge
->bus
->subordinate
);
753 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
754 dev
->pci_bridge
->bus
->io_range
->base
,
755 dev
->pci_bridge
->bus
->io_range
->limit
);
758 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
759 dev
->pci_bridge
->bus
->memory_range
->base
,
760 dev
->pci_bridge
->bus
->memory_range
->limit
);
762 monitor_printf(mon
, " prefetchable memory range "
763 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
764 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
765 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
768 for (region
= dev
->regions
; region
; region
= region
->next
) {
771 addr
= region
->value
->address
;
772 size
= region
->value
->size
;
774 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
776 if (!strcmp(region
->value
->type
, "io")) {
777 monitor_printf(mon
, "I/O at 0x%04" PRIx64
778 " [0x%04" PRIx64
"].\n",
779 addr
, addr
+ size
- 1);
781 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
782 " [0x%08" PRIx64
"].\n",
783 region
->value
->mem_type_64
? 64 : 32,
784 region
->value
->prefetch
? " prefetchable" : "",
785 addr
, addr
+ size
- 1);
789 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
791 if (dev
->has_pci_bridge
) {
792 if (dev
->pci_bridge
->has_devices
) {
793 PciDeviceInfoList
*cdev
;
794 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
795 hmp_info_pci_device(mon
, cdev
->value
);
801 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
803 InterruptStatsProvider
*intc
;
804 InterruptStatsProviderClass
*k
;
805 Monitor
*mon
= opaque
;
807 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
808 intc
= INTERRUPT_STATS_PROVIDER(obj
);
809 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
811 k
->print_info(intc
, mon
);
813 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
814 object_get_typename(obj
));
821 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
823 object_child_foreach_recursive(object_get_root(),
824 hmp_info_pic_foreach
, mon
);
827 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
829 PciInfoList
*info_list
, *info
;
832 info_list
= qmp_query_pci(&err
);
834 monitor_printf(mon
, "PCI devices not supported\n");
839 for (info
= info_list
; info
; info
= info
->next
) {
840 PciDeviceInfoList
*dev
;
842 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
843 hmp_info_pci_device(mon
, dev
->value
);
847 qapi_free_PciInfoList(info_list
);
850 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
853 TPMInfoList
*info_list
, *info
;
856 TPMPassthroughOptions
*tpo
;
857 TPMEmulatorOptions
*teo
;
859 info_list
= qmp_query_tpm(&err
);
861 monitor_printf(mon
, "TPM device not supported\n");
867 monitor_printf(mon
, "TPM device:\n");
870 for (info
= info_list
; info
; info
= info
->next
) {
871 TPMInfo
*ti
= info
->value
;
872 monitor_printf(mon
, " tpm%d: model=%s\n",
873 c
, TpmModel_str(ti
->model
));
875 monitor_printf(mon
, " \\ %s: type=%s",
876 ti
->id
, TpmType_str(ti
->options
->type
));
878 switch (ti
->options
->type
) {
879 case TPM_TYPE_PASSTHROUGH
:
880 tpo
= ti
->options
->u
.passthrough
.data
;
881 monitor_printf(mon
, "%s%s%s%s",
882 tpo
->has_path
? ",path=" : "",
883 tpo
->has_path
? tpo
->path
: "",
884 tpo
->has_cancel_path
? ",cancel-path=" : "",
885 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
887 case TPM_TYPE_EMULATOR
:
888 teo
= ti
->options
->u
.emulator
.data
;
889 monitor_printf(mon
, ",chardev=%s", teo
->chardev
);
894 monitor_printf(mon
, "\n");
897 qapi_free_TPMInfoList(info_list
);
899 monitor_printf(mon
, "TPM device not supported\n");
900 #endif /* CONFIG_TPM */
903 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
905 monitor_suspend(mon
);
909 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
914 void hmp_sync_profile(Monitor
*mon
, const QDict
*qdict
)
916 const char *op
= qdict_get_try_str(qdict
, "op");
919 bool on
= qsp_is_enabled();
921 monitor_printf(mon
, "sync-profile is %s\n", on
? "on" : "off");
924 if (!strcmp(op
, "on")) {
926 } else if (!strcmp(op
, "off")) {
928 } else if (!strcmp(op
, "reset")) {
933 error_setg(&err
, QERR_INVALID_PARAMETER
, op
);
934 hmp_handle_error(mon
, err
);
938 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
940 qmp_system_reset(NULL
);
943 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
945 qmp_system_powerdown(NULL
);
948 void hmp_exit_preconfig(Monitor
*mon
, const QDict
*qdict
)
952 qmp_x_exit_preconfig(&err
);
953 hmp_handle_error(mon
, err
);
956 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
960 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
961 use it are converted to the QAPI */
962 cpu_index
= qdict_get_int(qdict
, "index");
963 if (monitor_set_cpu(mon
, cpu_index
) < 0) {
964 monitor_printf(mon
, "invalid CPU index\n");
968 void hmp_memsave(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");
974 int cpu_index
= monitor_get_cpu_index(mon
);
977 monitor_printf(mon
, "No CPU available\n");
981 qmp_memsave(addr
, size
, filename
, true, cpu_index
, &err
);
982 hmp_handle_error(mon
, err
);
985 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
987 uint32_t size
= qdict_get_int(qdict
, "size");
988 const char *filename
= qdict_get_str(qdict
, "filename");
989 uint64_t addr
= qdict_get_int(qdict
, "val");
992 qmp_pmemsave(addr
, size
, filename
, &err
);
993 hmp_handle_error(mon
, err
);
996 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
998 const char *chardev
= qdict_get_str(qdict
, "device");
999 const char *data
= qdict_get_str(qdict
, "data");
1002 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
1004 hmp_handle_error(mon
, err
);
1007 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
1009 uint32_t size
= qdict_get_int(qdict
, "size");
1010 const char *chardev
= qdict_get_str(qdict
, "device");
1015 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
1016 if (hmp_handle_error(mon
, err
)) {
1020 for (i
= 0; data
[i
]; i
++) {
1021 unsigned char ch
= data
[i
];
1024 monitor_printf(mon
, "\\\\");
1025 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
1026 monitor_printf(mon
, "\\u%04X", ch
);
1028 monitor_printf(mon
, "%c", ch
);
1032 monitor_printf(mon
, "\n");
1036 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
1041 hmp_handle_error(mon
, err
);
1044 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
1048 qmp_system_wakeup(&err
);
1049 hmp_handle_error(mon
, err
);
1052 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
1056 qmp_inject_nmi(&err
);
1057 hmp_handle_error(mon
, err
);
1060 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
1062 const char *name
= qdict_get_str(qdict
, "name");
1063 bool up
= qdict_get_bool(qdict
, "up");
1066 qmp_set_link(name
, up
, &err
);
1067 hmp_handle_error(mon
, err
);
1070 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1072 int64_t value
= qdict_get_int(qdict
, "value");
1075 qmp_balloon(value
, &err
);
1076 hmp_handle_error(mon
, err
);
1079 void hmp_loadvm(Monitor
*mon
, const QDict
*qdict
)
1081 int saved_vm_running
= runstate_is_running();
1082 const char *name
= qdict_get_str(qdict
, "name");
1085 vm_stop(RUN_STATE_RESTORE_VM
);
1087 if (load_snapshot(name
, NULL
, false, NULL
, &err
) && saved_vm_running
) {
1090 hmp_handle_error(mon
, err
);
1093 void hmp_savevm(Monitor
*mon
, const QDict
*qdict
)
1097 save_snapshot(qdict_get_try_str(qdict
, "name"),
1098 true, NULL
, false, NULL
, &err
);
1099 hmp_handle_error(mon
, err
);
1102 void hmp_delvm(Monitor
*mon
, const QDict
*qdict
)
1105 const char *name
= qdict_get_str(qdict
, "name");
1107 delete_snapshot(name
, false, NULL
, &err
);
1108 hmp_handle_error(mon
, err
);
1111 void hmp_announce_self(Monitor
*mon
, const QDict
*qdict
)
1113 const char *interfaces_str
= qdict_get_try_str(qdict
, "interfaces");
1114 const char *id
= qdict_get_try_str(qdict
, "id");
1115 AnnounceParameters
*params
= QAPI_CLONE(AnnounceParameters
,
1116 migrate_announce_params());
1118 qapi_free_strList(params
->interfaces
);
1119 params
->interfaces
= strList_from_comma_list(interfaces_str
);
1120 params
->has_interfaces
= params
->interfaces
!= NULL
;
1121 params
->id
= g_strdup(id
);
1122 params
->has_id
= !!params
->id
;
1123 qmp_announce_self(params
, NULL
);
1124 qapi_free_AnnounceParameters(params
);
1127 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1129 qmp_migrate_cancel(NULL
);
1132 void hmp_migrate_continue(Monitor
*mon
, const QDict
*qdict
)
1135 const char *state
= qdict_get_str(qdict
, "state");
1136 int val
= qapi_enum_parse(&MigrationStatus_lookup
, state
, -1, &err
);
1139 qmp_migrate_continue(val
, &err
);
1142 hmp_handle_error(mon
, err
);
1145 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1148 const char *uri
= qdict_get_str(qdict
, "uri");
1150 qmp_migrate_incoming(uri
, &err
);
1152 hmp_handle_error(mon
, err
);
1155 void hmp_migrate_recover(Monitor
*mon
, const QDict
*qdict
)
1158 const char *uri
= qdict_get_str(qdict
, "uri");
1160 qmp_migrate_recover(uri
, &err
);
1162 hmp_handle_error(mon
, err
);
1165 void hmp_migrate_pause(Monitor
*mon
, const QDict
*qdict
)
1169 qmp_migrate_pause(&err
);
1171 hmp_handle_error(mon
, err
);
1175 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1177 const char *cap
= qdict_get_str(qdict
, "capability");
1178 bool state
= qdict_get_bool(qdict
, "state");
1180 MigrationCapabilityStatusList
*caps
= NULL
;
1181 MigrationCapabilityStatus
*value
;
1184 val
= qapi_enum_parse(&MigrationCapability_lookup
, cap
, -1, &err
);
1189 value
= g_malloc0(sizeof(*value
));
1190 value
->capability
= val
;
1191 value
->state
= state
;
1192 QAPI_LIST_PREPEND(caps
, value
);
1193 qmp_migrate_set_capabilities(caps
, &err
);
1194 qapi_free_MigrationCapabilityStatusList(caps
);
1197 hmp_handle_error(mon
, err
);
1200 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1202 const char *param
= qdict_get_str(qdict
, "parameter");
1203 const char *valuestr
= qdict_get_str(qdict
, "value");
1204 Visitor
*v
= string_input_visitor_new(valuestr
);
1205 MigrateSetParameters
*p
= g_new0(MigrateSetParameters
, 1);
1206 uint64_t valuebw
= 0;
1207 uint64_t cache_size
;
1211 val
= qapi_enum_parse(&MigrationParameter_lookup
, param
, -1, &err
);
1217 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1218 p
->has_compress_level
= true;
1219 visit_type_uint8(v
, param
, &p
->compress_level
, &err
);
1221 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1222 p
->has_compress_threads
= true;
1223 visit_type_uint8(v
, param
, &p
->compress_threads
, &err
);
1225 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD
:
1226 p
->has_compress_wait_thread
= true;
1227 visit_type_bool(v
, param
, &p
->compress_wait_thread
, &err
);
1229 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1230 p
->has_decompress_threads
= true;
1231 visit_type_uint8(v
, param
, &p
->decompress_threads
, &err
);
1233 case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD
:
1234 p
->has_throttle_trigger_threshold
= true;
1235 visit_type_uint8(v
, param
, &p
->throttle_trigger_threshold
, &err
);
1237 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1238 p
->has_cpu_throttle_initial
= true;
1239 visit_type_uint8(v
, param
, &p
->cpu_throttle_initial
, &err
);
1241 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1242 p
->has_cpu_throttle_increment
= true;
1243 visit_type_uint8(v
, param
, &p
->cpu_throttle_increment
, &err
);
1245 case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW
:
1246 p
->has_cpu_throttle_tailslow
= true;
1247 visit_type_bool(v
, param
, &p
->cpu_throttle_tailslow
, &err
);
1249 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE
:
1250 p
->has_max_cpu_throttle
= true;
1251 visit_type_uint8(v
, param
, &p
->max_cpu_throttle
, &err
);
1253 case MIGRATION_PARAMETER_TLS_CREDS
:
1254 p
->has_tls_creds
= true;
1255 p
->tls_creds
= g_new0(StrOrNull
, 1);
1256 p
->tls_creds
->type
= QTYPE_QSTRING
;
1257 visit_type_str(v
, param
, &p
->tls_creds
->u
.s
, &err
);
1259 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1260 p
->has_tls_hostname
= true;
1261 p
->tls_hostname
= g_new0(StrOrNull
, 1);
1262 p
->tls_hostname
->type
= QTYPE_QSTRING
;
1263 visit_type_str(v
, param
, &p
->tls_hostname
->u
.s
, &err
);
1265 case MIGRATION_PARAMETER_TLS_AUTHZ
:
1266 p
->has_tls_authz
= true;
1267 p
->tls_authz
= g_new0(StrOrNull
, 1);
1268 p
->tls_authz
->type
= QTYPE_QSTRING
;
1269 visit_type_str(v
, param
, &p
->tls_authz
->u
.s
, &err
);
1271 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1272 p
->has_max_bandwidth
= true;
1274 * Can't use visit_type_size() here, because it
1275 * defaults to Bytes rather than Mebibytes.
1277 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
1278 if (ret
< 0 || valuebw
> INT64_MAX
1279 || (size_t)valuebw
!= valuebw
) {
1280 error_setg(&err
, "Invalid size %s", valuestr
);
1283 p
->max_bandwidth
= valuebw
;
1285 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1286 p
->has_downtime_limit
= true;
1287 visit_type_size(v
, param
, &p
->downtime_limit
, &err
);
1289 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
1290 p
->has_x_checkpoint_delay
= true;
1291 visit_type_uint32(v
, param
, &p
->x_checkpoint_delay
, &err
);
1293 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL
:
1294 p
->has_block_incremental
= true;
1295 visit_type_bool(v
, param
, &p
->block_incremental
, &err
);
1297 case MIGRATION_PARAMETER_MULTIFD_CHANNELS
:
1298 p
->has_multifd_channels
= true;
1299 visit_type_uint8(v
, param
, &p
->multifd_channels
, &err
);
1301 case MIGRATION_PARAMETER_MULTIFD_COMPRESSION
:
1302 p
->has_multifd_compression
= true;
1303 visit_type_MultiFDCompression(v
, param
, &p
->multifd_compression
,
1306 case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL
:
1307 p
->has_multifd_zlib_level
= true;
1308 visit_type_uint8(v
, param
, &p
->multifd_zlib_level
, &err
);
1310 case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL
:
1311 p
->has_multifd_zstd_level
= true;
1312 visit_type_uint8(v
, param
, &p
->multifd_zstd_level
, &err
);
1315 case MIGRATION_PARAMETER_ZERO_COPY_SEND
:
1316 p
->has_zero_copy_send
= true;
1317 visit_type_bool(v
, param
, &p
->zero_copy_send
, &err
);
1320 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
:
1321 p
->has_xbzrle_cache_size
= true;
1322 if (!visit_type_size(v
, param
, &cache_size
, &err
)) {
1325 if (cache_size
> INT64_MAX
|| (size_t)cache_size
!= cache_size
) {
1326 error_setg(&err
, "Invalid size %s", valuestr
);
1329 p
->xbzrle_cache_size
= cache_size
;
1331 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH
:
1332 p
->has_max_postcopy_bandwidth
= true;
1333 visit_type_size(v
, param
, &p
->max_postcopy_bandwidth
, &err
);
1335 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL
:
1336 p
->has_announce_initial
= true;
1337 visit_type_size(v
, param
, &p
->announce_initial
, &err
);
1339 case MIGRATION_PARAMETER_ANNOUNCE_MAX
:
1340 p
->has_announce_max
= true;
1341 visit_type_size(v
, param
, &p
->announce_max
, &err
);
1343 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS
:
1344 p
->has_announce_rounds
= true;
1345 visit_type_size(v
, param
, &p
->announce_rounds
, &err
);
1347 case MIGRATION_PARAMETER_ANNOUNCE_STEP
:
1348 p
->has_announce_step
= true;
1349 visit_type_size(v
, param
, &p
->announce_step
, &err
);
1351 case MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING
:
1352 error_setg(&err
, "The block-bitmap-mapping parameter can only be set "
1363 qmp_migrate_set_parameters(p
, &err
);
1366 qapi_free_MigrateSetParameters(p
);
1368 hmp_handle_error(mon
, err
);
1371 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1374 const char *protocol
= qdict_get_str(qdict
, "protocol");
1375 const char *hostname
= qdict_get_str(qdict
, "hostname");
1376 bool has_port
= qdict_haskey(qdict
, "port");
1377 int port
= qdict_get_try_int(qdict
, "port", -1);
1378 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1379 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1380 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1382 qmp_client_migrate_info(protocol
, hostname
,
1383 has_port
, port
, has_tls_port
, tls_port
,
1384 !!cert_subject
, cert_subject
, &err
);
1385 hmp_handle_error(mon
, err
);
1388 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1391 qmp_migrate_start_postcopy(&err
);
1392 hmp_handle_error(mon
, err
);
1395 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1399 qmp_x_colo_lost_heartbeat(&err
);
1400 hmp_handle_error(mon
, err
);
1403 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1405 const char *protocol
= qdict_get_str(qdict
, "protocol");
1406 const char *password
= qdict_get_str(qdict
, "password");
1407 const char *display
= qdict_get_try_str(qdict
, "display");
1408 const char *connected
= qdict_get_try_str(qdict
, "connected");
1411 SetPasswordOptions opts
= {
1412 .password
= (char *)password
,
1413 .has_connected
= !!connected
,
1416 opts
.connected
= qapi_enum_parse(&SetPasswordAction_lookup
, connected
,
1417 SET_PASSWORD_ACTION_KEEP
, &err
);
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
.has_display
= !!display
;
1430 opts
.u
.vnc
.display
= (char *)display
;
1433 qmp_set_password(&opts
, &err
);
1436 hmp_handle_error(mon
, err
);
1439 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1441 const char *protocol
= qdict_get_str(qdict
, "protocol");
1442 const char *whenstr
= qdict_get_str(qdict
, "time");
1443 const char *display
= qdict_get_try_str(qdict
, "display");
1446 ExpirePasswordOptions opts
= {
1447 .time
= (char *)whenstr
,
1450 opts
.protocol
= qapi_enum_parse(&DisplayProtocol_lookup
, protocol
,
1451 DISPLAY_PROTOCOL_VNC
, &err
);
1456 if (opts
.protocol
== DISPLAY_PROTOCOL_VNC
) {
1457 opts
.u
.vnc
.has_display
= !!display
;
1458 opts
.u
.vnc
.display
= (char *)display
;
1461 qmp_expire_password(&opts
, &err
);
1464 hmp_handle_error(mon
, err
);
1469 static void hmp_change_read_arg(void *opaque
, const char *password
,
1470 void *readline_opaque
)
1472 qmp_change_vnc_password(password
, NULL
);
1473 monitor_read_command(opaque
, 1);
1477 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1479 const char *device
= qdict_get_str(qdict
, "device");
1480 const char *target
= qdict_get_str(qdict
, "target");
1481 const char *arg
= qdict_get_try_str(qdict
, "arg");
1482 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1483 bool force
= qdict_get_try_bool(qdict
, "force", false);
1484 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1488 if (strcmp(device
, "vnc") == 0) {
1491 "Parameter 'read-only-mode' is invalid for VNC\n");
1494 if (strcmp(target
, "passwd") == 0 ||
1495 strcmp(target
, "password") == 0) {
1497 MonitorHMP
*hmp_mon
= container_of(mon
, MonitorHMP
, common
);
1498 monitor_read_password(hmp_mon
, hmp_change_read_arg
, NULL
);
1501 qmp_change_vnc_password(arg
, &err
);
1504 monitor_printf(mon
, "Expected 'password' after 'vnc'\n");
1511 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup
,
1513 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1519 qmp_blockdev_change_medium(true, device
, false, NULL
, target
,
1520 !!arg
, arg
, true, force
,
1521 !!read_only
, read_only_mode
,
1526 hmp_handle_error(mon
, err
);
1529 typedef struct HMPMigrationStatus
{
1532 bool is_block_migration
;
1533 } HMPMigrationStatus
;
1535 static void hmp_migrate_status_cb(void *opaque
)
1537 HMPMigrationStatus
*status
= opaque
;
1538 MigrationInfo
*info
;
1540 info
= qmp_query_migrate(NULL
);
1541 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1542 info
->status
== MIGRATION_STATUS_SETUP
) {
1543 if (info
->has_disk
) {
1546 if (info
->disk
->remaining
) {
1547 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1552 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1553 monitor_flush(status
->mon
);
1556 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1558 if (status
->is_block_migration
) {
1559 monitor_printf(status
->mon
, "\n");
1561 if (info
->has_error_desc
) {
1562 error_report("%s", info
->error_desc
);
1564 monitor_resume(status
->mon
);
1565 timer_free(status
->timer
);
1569 qapi_free_MigrationInfo(info
);
1572 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1574 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1575 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1576 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1577 bool resume
= qdict_get_try_bool(qdict
, "resume", false);
1578 const char *uri
= qdict_get_str(qdict
, "uri");
1581 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
,
1582 false, false, true, resume
, &err
);
1583 if (hmp_handle_error(mon
, err
)) {
1588 HMPMigrationStatus
*status
;
1590 if (monitor_suspend(mon
) < 0) {
1591 monitor_printf(mon
, "terminal does not allow synchronous "
1592 "migration, continuing detached\n");
1596 status
= g_malloc0(sizeof(*status
));
1598 status
->is_block_migration
= blk
|| inc
;
1599 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1601 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1605 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1609 const char *type
= qdict_get_try_str(qdict
, "type");
1611 if (type
&& is_help_option(type
)) {
1615 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1620 netdev_add(opts
, &err
);
1622 qemu_opts_del(opts
);
1626 hmp_handle_error(mon
, err
);
1629 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1631 const char *id
= qdict_get_str(qdict
, "id");
1634 qmp_netdev_del(id
, &err
);
1635 hmp_handle_error(mon
, err
);
1638 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
1640 const char *options
= qdict_get_str(qdict
, "object");
1643 user_creatable_add_from_str(options
, &err
);
1644 hmp_handle_error(mon
, err
);
1647 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1649 const char *fdname
= qdict_get_str(qdict
, "fdname");
1652 qmp_getfd(fdname
, &err
);
1653 hmp_handle_error(mon
, err
);
1656 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1658 const char *fdname
= qdict_get_str(qdict
, "fdname");
1661 qmp_closefd(fdname
, &err
);
1662 hmp_handle_error(mon
, err
);
1665 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
1667 const char *keys
= qdict_get_str(qdict
, "keys");
1669 KeyValueList
*head
= NULL
, **tail
= &head
;
1670 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1671 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1673 const char *separator
;
1677 separator
= qemu_strchrnul(keys
, '-');
1678 keyname_len
= separator
- keys
;
1680 /* Be compatible with old interface, convert user inputted "<" */
1681 if (keys
[0] == '<' && keyname_len
== 1) {
1686 v
= g_malloc0(sizeof(*v
));
1688 if (strstart(keys
, "0x", NULL
)) {
1690 int value
= strtoul(keys
, &endp
, 0);
1691 assert(endp
<= keys
+ keyname_len
);
1692 if (endp
!= keys
+ keyname_len
) {
1695 v
->type
= KEY_VALUE_KIND_NUMBER
;
1696 v
->u
.number
.data
= value
;
1698 int idx
= index_from_key(keys
, keyname_len
);
1699 if (idx
== Q_KEY_CODE__MAX
) {
1702 v
->type
= KEY_VALUE_KIND_QCODE
;
1703 v
->u
.qcode
.data
= idx
;
1705 QAPI_LIST_APPEND(tail
, v
);
1711 keys
= separator
+ 1;
1714 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1715 hmp_handle_error(mon
, err
);
1718 qapi_free_KeyValue(v
);
1719 qapi_free_KeyValueList(head
);
1723 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
1728 hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
1730 const char *filename
= qdict_get_str(qdict
, "filename");
1731 const char *id
= qdict_get_try_str(qdict
, "device");
1732 int64_t head
= qdict_get_try_int(qdict
, "head", 0);
1733 const char *input_format
= qdict_get_try_str(qdict
, "format");
1737 format
= qapi_enum_parse(&ImageFormat_lookup
, input_format
,
1738 IMAGE_FORMAT_PPM
, &err
);
1743 qmp_screendump(filename
, id
!= NULL
, id
, id
!= NULL
, head
,
1744 input_format
!= NULL
, format
, &err
);
1746 hmp_handle_error(mon
, err
);
1749 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
1751 const char *args
= qdict_get_str(qdict
, "args");
1755 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
1757 error_setg(&err
, "Parsing chardev args failed");
1759 qemu_chr_new_from_opts(opts
, NULL
, &err
);
1760 qemu_opts_del(opts
);
1762 hmp_handle_error(mon
, err
);
1765 void hmp_chardev_change(Monitor
*mon
, const QDict
*qdict
)
1767 const char *args
= qdict_get_str(qdict
, "args");
1770 ChardevBackend
*backend
= NULL
;
1771 ChardevReturn
*ret
= NULL
;
1772 QemuOpts
*opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
,
1775 error_setg(&err
, "Parsing chardev args failed");
1779 id
= qdict_get_str(qdict
, "id");
1780 if (qemu_opts_id(opts
)) {
1781 error_setg(&err
, "Unexpected 'id' parameter");
1785 backend
= qemu_chr_parse_opts(opts
, &err
);
1790 ret
= qmp_chardev_change(id
, backend
, &err
);
1793 qapi_free_ChardevReturn(ret
);
1794 qapi_free_ChardevBackend(backend
);
1795 qemu_opts_del(opts
);
1796 hmp_handle_error(mon
, err
);
1799 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
1801 Error
*local_err
= NULL
;
1803 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
1804 hmp_handle_error(mon
, local_err
);
1807 void hmp_chardev_send_break(Monitor
*mon
, const QDict
*qdict
)
1809 Error
*local_err
= NULL
;
1811 qmp_chardev_send_break(qdict_get_str(qdict
, "id"), &local_err
);
1812 hmp_handle_error(mon
, local_err
);
1815 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
1817 const char *id
= qdict_get_str(qdict
, "id");
1820 user_creatable_del(id
, &err
);
1821 hmp_handle_error(mon
, err
);
1824 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
1827 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
1828 MemoryDeviceInfoList
*info
;
1829 VirtioPMEMDeviceInfo
*vpi
;
1830 VirtioMEMDeviceInfo
*vmi
;
1831 MemoryDeviceInfo
*value
;
1832 PCDIMMDeviceInfo
*di
;
1833 SgxEPCDeviceInfo
*se
;
1835 for (info
= info_list
; info
; info
= info
->next
) {
1836 value
= info
->value
;
1839 switch (value
->type
) {
1840 case MEMORY_DEVICE_INFO_KIND_DIMM
:
1841 case MEMORY_DEVICE_INFO_KIND_NVDIMM
:
1842 di
= value
->type
== MEMORY_DEVICE_INFO_KIND_DIMM
?
1843 value
->u
.dimm
.data
: value
->u
.nvdimm
.data
;
1844 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1845 MemoryDeviceInfoKind_str(value
->type
),
1846 di
->id
? di
->id
: "");
1847 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
1848 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
1849 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
1850 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
1851 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
1852 monitor_printf(mon
, " hotplugged: %s\n",
1853 di
->hotplugged
? "true" : "false");
1854 monitor_printf(mon
, " hotpluggable: %s\n",
1855 di
->hotpluggable
? "true" : "false");
1857 case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM
:
1858 vpi
= value
->u
.virtio_pmem
.data
;
1859 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1860 MemoryDeviceInfoKind_str(value
->type
),
1861 vpi
->id
? vpi
->id
: "");
1862 monitor_printf(mon
, " memaddr: 0x%" PRIx64
"\n", vpi
->memaddr
);
1863 monitor_printf(mon
, " size: %" PRIu64
"\n", vpi
->size
);
1864 monitor_printf(mon
, " memdev: %s\n", vpi
->memdev
);
1866 case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM
:
1867 vmi
= value
->u
.virtio_mem
.data
;
1868 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1869 MemoryDeviceInfoKind_str(value
->type
),
1870 vmi
->id
? vmi
->id
: "");
1871 monitor_printf(mon
, " memaddr: 0x%" PRIx64
"\n", vmi
->memaddr
);
1872 monitor_printf(mon
, " node: %" PRId64
"\n", vmi
->node
);
1873 monitor_printf(mon
, " requested-size: %" PRIu64
"\n",
1874 vmi
->requested_size
);
1875 monitor_printf(mon
, " size: %" PRIu64
"\n", vmi
->size
);
1876 monitor_printf(mon
, " max-size: %" PRIu64
"\n", vmi
->max_size
);
1877 monitor_printf(mon
, " block-size: %" PRIu64
"\n",
1879 monitor_printf(mon
, " memdev: %s\n", vmi
->memdev
);
1881 case MEMORY_DEVICE_INFO_KIND_SGX_EPC
:
1882 se
= value
->u
.sgx_epc
.data
;
1883 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1884 MemoryDeviceInfoKind_str(value
->type
),
1885 se
->id
? se
->id
: "");
1886 monitor_printf(mon
, " memaddr: 0x%" PRIx64
"\n", se
->memaddr
);
1887 monitor_printf(mon
, " size: %" PRIu64
"\n", se
->size
);
1888 monitor_printf(mon
, " node: %" PRId64
"\n", se
->node
);
1889 monitor_printf(mon
, " memdev: %s\n", se
->memdev
);
1892 g_assert_not_reached();
1897 qapi_free_MemoryDeviceInfoList(info_list
);
1898 hmp_handle_error(mon
, err
);
1901 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
1903 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
1904 IOThreadInfoList
*info
;
1905 IOThreadInfo
*value
;
1907 for (info
= info_list
; info
; info
= info
->next
) {
1908 value
= info
->value
;
1909 monitor_printf(mon
, "%s:\n", value
->id
);
1910 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
1911 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
1912 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
1913 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
1914 monitor_printf(mon
, " aio-max-batch=%" PRId64
"\n",
1915 value
->aio_max_batch
);
1918 qapi_free_IOThreadInfoList(info_list
);
1921 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
1923 const char *name
= qdict_get_str(qdict
, "name");
1924 RockerSwitch
*rocker
;
1927 rocker
= qmp_query_rocker(name
, &err
);
1928 if (hmp_handle_error(mon
, err
)) {
1932 monitor_printf(mon
, "name: %s\n", rocker
->name
);
1933 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
1934 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
1936 qapi_free_RockerSwitch(rocker
);
1939 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
1941 RockerPortList
*list
, *port
;
1942 const char *name
= qdict_get_str(qdict
, "name");
1945 list
= qmp_query_rocker_ports(name
, &err
);
1946 if (hmp_handle_error(mon
, err
)) {
1950 monitor_printf(mon
, " ena/ speed/ auto\n");
1951 monitor_printf(mon
, " port link duplex neg?\n");
1953 for (port
= list
; port
; port
= port
->next
) {
1954 monitor_printf(mon
, "%10s %-4s %-3s %2s %s\n",
1956 port
->value
->enabled
? port
->value
->link_up
?
1957 "up" : "down" : "!ena",
1958 port
->value
->speed
== 10000 ? "10G" : "??",
1959 port
->value
->duplex
? "FD" : "HD",
1960 port
->value
->autoneg
? "Yes" : "No");
1963 qapi_free_RockerPortList(list
);
1966 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
1968 RockerOfDpaFlowList
*list
, *info
;
1969 const char *name
= qdict_get_str(qdict
, "name");
1970 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
1973 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
1974 if (hmp_handle_error(mon
, err
)) {
1978 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
1980 for (info
= list
; info
; info
= info
->next
) {
1981 RockerOfDpaFlow
*flow
= info
->value
;
1982 RockerOfDpaFlowKey
*key
= flow
->key
;
1983 RockerOfDpaFlowMask
*mask
= flow
->mask
;
1984 RockerOfDpaFlowAction
*action
= flow
->action
;
1987 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
1988 key
->priority
, key
->tbl_id
, flow
->hits
);
1990 monitor_printf(mon
, "%-4d %-3d ",
1991 key
->priority
, key
->tbl_id
);
1994 if (key
->has_in_pport
) {
1995 monitor_printf(mon
, " pport %d", key
->in_pport
);
1996 if (mask
->has_in_pport
) {
1997 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2001 if (key
->has_vlan_id
) {
2002 monitor_printf(mon
, " vlan %d",
2003 key
->vlan_id
& VLAN_VID_MASK
);
2004 if (mask
->has_vlan_id
) {
2005 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2009 if (key
->has_tunnel_id
) {
2010 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2011 if (mask
->has_tunnel_id
) {
2012 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2016 if (key
->has_eth_type
) {
2017 switch (key
->eth_type
) {
2019 monitor_printf(mon
, " ARP");
2022 monitor_printf(mon
, " IP");
2025 monitor_printf(mon
, " IPv6");
2028 monitor_printf(mon
, " LACP");
2031 monitor_printf(mon
, " LLDP");
2034 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2039 if (key
->has_eth_src
) {
2040 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2041 (mask
->has_eth_src
) &&
2042 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2043 monitor_printf(mon
, " src <any mcast/bcast>");
2044 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2045 (mask
->has_eth_src
) &&
2046 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2047 monitor_printf(mon
, " src <any ucast>");
2049 monitor_printf(mon
, " src %s", key
->eth_src
);
2050 if (mask
->has_eth_src
) {
2051 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2056 if (key
->has_eth_dst
) {
2057 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2058 (mask
->has_eth_dst
) &&
2059 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2060 monitor_printf(mon
, " dst <any mcast/bcast>");
2061 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2062 (mask
->has_eth_dst
) &&
2063 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2064 monitor_printf(mon
, " dst <any ucast>");
2066 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2067 if (mask
->has_eth_dst
) {
2068 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2073 if (key
->has_ip_proto
) {
2074 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2075 if (mask
->has_ip_proto
) {
2076 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2080 if (key
->has_ip_tos
) {
2081 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2082 if (mask
->has_ip_tos
) {
2083 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2087 if (key
->has_ip_dst
) {
2088 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2091 if (action
->has_goto_tbl
|| action
->has_group_id
||
2092 action
->has_new_vlan_id
) {
2093 monitor_printf(mon
, " -->");
2096 if (action
->has_new_vlan_id
) {
2097 monitor_printf(mon
, " apply new vlan %d",
2098 ntohs(action
->new_vlan_id
));
2101 if (action
->has_group_id
) {
2102 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2105 if (action
->has_goto_tbl
) {
2106 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2109 monitor_printf(mon
, "\n");
2112 qapi_free_RockerOfDpaFlowList(list
);
2115 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2117 RockerOfDpaGroupList
*list
, *g
;
2118 const char *name
= qdict_get_str(qdict
, "name");
2119 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2122 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
2123 if (hmp_handle_error(mon
, err
)) {
2127 monitor_printf(mon
, "id (decode) --> buckets\n");
2129 for (g
= list
; g
; g
= g
->next
) {
2130 RockerOfDpaGroup
*group
= g
->value
;
2133 monitor_printf(mon
, "0x%08x", group
->id
);
2135 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2136 group
->type
== 1 ? "L2 rewrite" :
2137 group
->type
== 2 ? "L3 unicast" :
2138 group
->type
== 3 ? "L2 multicast" :
2139 group
->type
== 4 ? "L2 flood" :
2140 group
->type
== 5 ? "L3 interface" :
2141 group
->type
== 6 ? "L3 multicast" :
2142 group
->type
== 7 ? "L3 ECMP" :
2143 group
->type
== 8 ? "L2 overlay" :
2146 if (group
->has_vlan_id
) {
2147 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2150 if (group
->has_pport
) {
2151 monitor_printf(mon
, " pport %d", group
->pport
);
2154 if (group
->has_index
) {
2155 monitor_printf(mon
, " index %d", group
->index
);
2158 monitor_printf(mon
, ") -->");
2160 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2162 monitor_printf(mon
, " set vlan %d",
2163 group
->set_vlan_id
& VLAN_VID_MASK
);
2166 if (group
->has_set_eth_src
) {
2169 monitor_printf(mon
, " set");
2171 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2174 if (group
->has_set_eth_dst
) {
2176 monitor_printf(mon
, " set");
2178 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2181 if (group
->has_ttl_check
&& group
->ttl_check
) {
2182 monitor_printf(mon
, " check TTL");
2185 if (group
->has_group_id
&& group
->group_id
) {
2186 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2189 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2190 monitor_printf(mon
, " pop vlan");
2193 if (group
->has_out_pport
) {
2194 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2197 if (group
->has_group_ids
) {
2198 struct uint32List
*id
;
2200 monitor_printf(mon
, " groups [");
2201 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2202 monitor_printf(mon
, "0x%08x", id
->value
);
2204 monitor_printf(mon
, ",");
2207 monitor_printf(mon
, "]");
2210 monitor_printf(mon
, "\n");
2213 qapi_free_RockerOfDpaGroupList(list
);
2216 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
2219 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
2221 monitor_printf(mon
, "%s\n", info
->guid
);
2223 hmp_handle_error(mon
, err
);
2224 qapi_free_GuidInfo(info
);
2227 void hmp_info_memory_size_summary(Monitor
*mon
, const QDict
*qdict
)
2230 MemoryInfo
*info
= qmp_query_memory_size_summary(&err
);
2232 monitor_printf(mon
, "base memory: %" PRIu64
"\n",
2235 if (info
->has_plugged_memory
) {
2236 monitor_printf(mon
, "plugged memory: %" PRIu64
"\n",
2237 info
->plugged_memory
);
2240 qapi_free_MemoryInfo(info
);
2242 hmp_handle_error(mon
, err
);
2245 static void print_stats_schema_value(Monitor
*mon
, StatsSchemaValue
*value
)
2247 const char *unit
= NULL
;
2248 monitor_printf(mon
, " %s (%s%s", value
->name
, StatsType_str(value
->type
),
2249 value
->has_unit
|| value
->exponent
? ", " : "");
2251 if (value
->has_unit
) {
2252 if (value
->unit
== STATS_UNIT_SECONDS
) {
2254 } else if (value
->unit
== STATS_UNIT_BYTES
) {
2259 if (unit
&& value
->base
== 10 &&
2260 value
->exponent
>= -18 && value
->exponent
<= 18 &&
2261 value
->exponent
% 3 == 0) {
2262 monitor_printf(mon
, "%s", si_prefix(value
->exponent
));
2263 } else if (unit
&& value
->base
== 2 &&
2264 value
->exponent
>= 0 && value
->exponent
<= 60 &&
2265 value
->exponent
% 10 == 0) {
2267 monitor_printf(mon
, "%s", iec_binary_prefix(value
->exponent
));
2268 } else if (value
->exponent
) {
2269 /* Use exponential notation and write the unit's English name */
2270 monitor_printf(mon
, "* %d^%d%s",
2271 value
->base
, value
->exponent
,
2272 value
->has_unit
? " " : "");
2276 if (value
->has_unit
) {
2277 monitor_printf(mon
, "%s", unit
? unit
: StatsUnit_str(value
->unit
));
2280 /* Print bucket size for linear histograms */
2281 if (value
->type
== STATS_TYPE_LINEAR_HISTOGRAM
&& value
->has_bucket_size
) {
2282 monitor_printf(mon
, ", bucket size=%d", value
->bucket_size
);
2284 monitor_printf(mon
, ")");
2287 static StatsSchemaValueList
*find_schema_value_list(
2288 StatsSchemaList
*list
, StatsProvider provider
,
2291 StatsSchemaList
*node
;
2293 for (node
= list
; node
; node
= node
->next
) {
2294 if (node
->value
->provider
== provider
&&
2295 node
->value
->target
== target
) {
2296 return node
->value
->stats
;
2302 static void print_stats_results(Monitor
*mon
, StatsTarget target
,
2304 StatsResult
*result
,
2305 StatsSchemaList
*schema
)
2307 /* Find provider schema */
2308 StatsSchemaValueList
*schema_value_list
=
2309 find_schema_value_list(schema
, result
->provider
, target
);
2310 StatsList
*stats_list
;
2312 if (!schema_value_list
) {
2313 monitor_printf(mon
, "failed to find schema list for %s\n",
2314 StatsProvider_str(result
->provider
));
2318 if (show_provider
) {
2319 monitor_printf(mon
, "provider: %s\n",
2320 StatsProvider_str(result
->provider
));
2323 for (stats_list
= result
->stats
; stats_list
;
2324 stats_list
= stats_list
->next
,
2325 schema_value_list
= schema_value_list
->next
) {
2327 Stats
*stats
= stats_list
->value
;
2328 StatsValue
*stats_value
= stats
->value
;
2329 StatsSchemaValue
*schema_value
= schema_value_list
->value
;
2331 /* Find schema entry */
2332 while (!g_str_equal(stats
->name
, schema_value
->name
)) {
2333 if (!schema_value_list
->next
) {
2334 monitor_printf(mon
, "failed to find schema entry for %s\n",
2338 schema_value_list
= schema_value_list
->next
;
2339 schema_value
= schema_value_list
->value
;
2342 print_stats_schema_value(mon
, schema_value
);
2344 if (stats_value
->type
== QTYPE_QNUM
) {
2345 monitor_printf(mon
, ": %" PRId64
"\n", stats_value
->u
.scalar
);
2346 } else if (stats_value
->type
== QTYPE_QLIST
) {
2350 monitor_printf(mon
, ": ");
2351 for (list
= stats_value
->u
.list
, i
= 1;
2353 list
= list
->next
, i
++) {
2354 monitor_printf(mon
, "[%d]=%" PRId64
" ", i
, list
->value
);
2356 monitor_printf(mon
, "\n");
2361 /* Create the StatsFilter that is needed for an "info stats" invocation. */
2362 static StatsFilter
*stats_filter(StatsTarget target
, const char *names
,
2363 int cpu_index
, StatsProvider provider
)
2365 StatsFilter
*filter
= g_malloc0(sizeof(*filter
));
2366 StatsProvider provider_idx
;
2367 StatsRequestList
*request_list
= NULL
;
2369 filter
->target
= target
;
2371 case STATS_TARGET_VM
:
2373 case STATS_TARGET_VCPU
:
2375 strList
*vcpu_list
= NULL
;
2376 CPUState
*cpu
= qemu_get_cpu(cpu_index
);
2377 char *canonical_path
= object_get_canonical_path(OBJECT(cpu
));
2379 QAPI_LIST_PREPEND(vcpu_list
, canonical_path
);
2380 filter
->u
.vcpu
.has_vcpus
= true;
2381 filter
->u
.vcpu
.vcpus
= vcpu_list
;
2388 if (!names
&& provider
== STATS_PROVIDER__MAX
) {
2393 * "info stats" can only query either one or all the providers. Querying
2394 * by name, but not by provider, requires the creation of one filter per
2397 for (provider_idx
= 0; provider_idx
< STATS_PROVIDER__MAX
; provider_idx
++) {
2398 if (provider
== STATS_PROVIDER__MAX
|| provider
== provider_idx
) {
2399 StatsRequest
*request
= g_new0(StatsRequest
, 1);
2400 request
->provider
= provider_idx
;
2401 if (names
&& !g_str_equal(names
, "*")) {
2402 request
->has_names
= true;
2403 request
->names
= strList_from_comma_list(names
);
2405 QAPI_LIST_PREPEND(request_list
, request
);
2409 filter
->has_providers
= true;
2410 filter
->providers
= request_list
;
2414 void hmp_info_stats(Monitor
*mon
, const QDict
*qdict
)
2416 const char *target_str
= qdict_get_str(qdict
, "target");
2417 const char *provider_str
= qdict_get_try_str(qdict
, "provider");
2418 const char *names
= qdict_get_try_str(qdict
, "names");
2420 StatsProvider provider
= STATS_PROVIDER__MAX
;
2423 g_autoptr(StatsSchemaList
) schema
= NULL
;
2424 g_autoptr(StatsResultList
) stats
= NULL
;
2425 g_autoptr(StatsFilter
) filter
= NULL
;
2426 StatsResultList
*entry
;
2428 target
= qapi_enum_parse(&StatsTarget_lookup
, target_str
, -1, &err
);
2430 monitor_printf(mon
, "invalid stats target %s\n", target_str
);
2434 provider
= qapi_enum_parse(&StatsProvider_lookup
, provider_str
, -1, &err
);
2436 monitor_printf(mon
, "invalid stats provider %s\n", provider_str
);
2441 schema
= qmp_query_stats_schemas(provider_str
? true : false,
2448 case STATS_TARGET_VM
:
2449 filter
= stats_filter(target
, names
, -1, provider
);
2451 case STATS_TARGET_VCPU
: {}
2452 int cpu_index
= monitor_get_cpu_index(mon
);
2453 filter
= stats_filter(target
, names
, cpu_index
, provider
);
2459 stats
= qmp_query_stats(filter
, &err
);
2463 for (entry
= stats
; entry
; entry
= entry
->next
) {
2464 print_stats_results(mon
, target
, provider_str
== NULL
, entry
->value
, schema
);
2469 monitor_printf(mon
, "%s\n", error_get_pretty(err
));