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-rocker.h"
41 #include "qapi/qapi-commands-run-state.h"
42 #include "qapi/qapi-commands-stats.h"
43 #include "qapi/qapi-commands-tpm.h"
44 #include "qapi/qapi-commands-ui.h"
45 #include "qapi/qapi-commands-virtio.h"
46 #include "qapi/qapi-visit-virtio.h"
47 #include "qapi/qapi-visit-net.h"
48 #include "qapi/qapi-visit-migration.h"
49 #include "qapi/qmp/qdict.h"
50 #include "qapi/qmp/qerror.h"
51 #include "qapi/string-input-visitor.h"
52 #include "qapi/string-output-visitor.h"
53 #include "qom/object_interfaces.h"
54 #include "ui/console.h"
55 #include "qemu/cutils.h"
56 #include "qemu/error-report.h"
57 #include "hw/core/cpu.h"
58 #include "hw/intc/intc.h"
59 #include "migration/snapshot.h"
60 #include "migration/misc.h"
63 #include <spice/enums.h>
66 bool hmp_handle_error(Monitor
*mon
, Error
*err
)
69 error_reportf_err(err
, "Error: ");
76 * Produce a strList from a comma separated list.
77 * A NULL or empty input string return NULL.
79 static strList
*strList_from_comma_list(const char *in
)
82 strList
**tail
= &res
;
85 char *comma
= strchr(in
, ',');
89 value
= g_strndup(in
, comma
- in
);
90 in
= comma
+ 1; /* skip the , */
95 QAPI_LIST_APPEND(tail
, value
);
101 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
105 info
= qmp_query_name(NULL
);
107 monitor_printf(mon
, "%s\n", info
->name
);
109 qapi_free_NameInfo(info
);
112 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
116 info
= qmp_query_version(NULL
);
118 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
119 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
122 qapi_free_VersionInfo(info
);
125 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
129 info
= qmp_query_kvm(NULL
);
130 monitor_printf(mon
, "kvm support: ");
132 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
134 monitor_printf(mon
, "not compiled\n");
137 qapi_free_KvmInfo(info
);
140 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
144 info
= qmp_query_status(NULL
);
146 monitor_printf(mon
, "VM status: %s%s",
147 info
->running
? "running" : "paused",
148 info
->singlestep
? " (single step mode)" : "");
150 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
151 monitor_printf(mon
, " (%s)", RunState_str(info
->status
));
154 monitor_printf(mon
, "\n");
156 qapi_free_StatusInfo(info
);
159 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
163 info
= qmp_query_uuid(NULL
);
164 monitor_printf(mon
, "%s\n", info
->UUID
);
165 qapi_free_UuidInfo(info
);
168 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
170 ChardevInfoList
*char_info
, *info
;
172 char_info
= qmp_query_chardev(NULL
);
173 for (info
= char_info
; info
; info
= info
->next
) {
174 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
175 info
->value
->filename
);
178 qapi_free_ChardevInfoList(char_info
);
181 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
183 MouseInfoList
*mice_list
, *mouse
;
185 mice_list
= qmp_query_mice(NULL
);
187 monitor_printf(mon
, "No mouse devices connected\n");
191 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
192 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
193 mouse
->value
->current
? '*' : ' ',
194 mouse
->value
->index
, mouse
->value
->name
,
195 mouse
->value
->absolute
? " (absolute)" : "");
198 qapi_free_MouseInfoList(mice_list
);
201 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
205 info
= qmp_query_migrate(NULL
);
207 migration_global_dump(mon
);
209 if (info
->blocked_reasons
) {
210 strList
*reasons
= info
->blocked_reasons
;
211 monitor_printf(mon
, "Outgoing migration blocked:\n");
213 monitor_printf(mon
, " %s\n", reasons
->value
);
214 reasons
= reasons
->next
;
218 if (info
->has_status
) {
219 monitor_printf(mon
, "Migration status: %s",
220 MigrationStatus_str(info
->status
));
221 if (info
->status
== MIGRATION_STATUS_FAILED
&& info
->error_desc
) {
222 monitor_printf(mon
, " (%s)\n", info
->error_desc
);
224 monitor_printf(mon
, "\n");
227 monitor_printf(mon
, "total time: %" PRIu64
" ms\n",
229 if (info
->has_expected_downtime
) {
230 monitor_printf(mon
, "expected downtime: %" PRIu64
" ms\n",
231 info
->expected_downtime
);
233 if (info
->has_downtime
) {
234 monitor_printf(mon
, "downtime: %" PRIu64
" ms\n",
237 if (info
->has_setup_time
) {
238 monitor_printf(mon
, "setup: %" PRIu64
" ms\n",
244 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
245 info
->ram
->transferred
>> 10);
246 monitor_printf(mon
, "throughput: %0.2f mbps\n",
248 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
249 info
->ram
->remaining
>> 10);
250 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
251 info
->ram
->total
>> 10);
252 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
253 info
->ram
->duplicate
);
254 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
256 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
258 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
259 info
->ram
->normal_bytes
>> 10);
260 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
261 info
->ram
->dirty_sync_count
);
262 monitor_printf(mon
, "page size: %" PRIu64
" kbytes\n",
263 info
->ram
->page_size
>> 10);
264 monitor_printf(mon
, "multifd bytes: %" PRIu64
" kbytes\n",
265 info
->ram
->multifd_bytes
>> 10);
266 monitor_printf(mon
, "pages-per-second: %" PRIu64
"\n",
267 info
->ram
->pages_per_second
);
269 if (info
->ram
->dirty_pages_rate
) {
270 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
271 info
->ram
->dirty_pages_rate
);
273 if (info
->ram
->postcopy_requests
) {
274 monitor_printf(mon
, "postcopy request count: %" PRIu64
"\n",
275 info
->ram
->postcopy_requests
);
277 if (info
->ram
->precopy_bytes
) {
278 monitor_printf(mon
, "precopy ram: %" PRIu64
" kbytes\n",
279 info
->ram
->precopy_bytes
>> 10);
281 if (info
->ram
->downtime_bytes
) {
282 monitor_printf(mon
, "downtime ram: %" PRIu64
" kbytes\n",
283 info
->ram
->downtime_bytes
>> 10);
285 if (info
->ram
->postcopy_bytes
) {
286 monitor_printf(mon
, "postcopy ram: %" PRIu64
" kbytes\n",
287 info
->ram
->postcopy_bytes
>> 10);
289 if (info
->ram
->dirty_sync_missed_zero_copy
) {
291 "Zero-copy-send fallbacks happened: %" PRIu64
" times\n",
292 info
->ram
->dirty_sync_missed_zero_copy
);
297 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
298 info
->disk
->transferred
>> 10);
299 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
300 info
->disk
->remaining
>> 10);
301 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
302 info
->disk
->total
>> 10);
305 if (info
->xbzrle_cache
) {
306 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
307 info
->xbzrle_cache
->cache_size
);
308 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
309 info
->xbzrle_cache
->bytes
>> 10);
310 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
311 info
->xbzrle_cache
->pages
);
312 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
" pages\n",
313 info
->xbzrle_cache
->cache_miss
);
314 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
315 info
->xbzrle_cache
->cache_miss_rate
);
316 monitor_printf(mon
, "xbzrle encoding rate: %0.2f\n",
317 info
->xbzrle_cache
->encoding_rate
);
318 monitor_printf(mon
, "xbzrle overflow: %" PRIu64
"\n",
319 info
->xbzrle_cache
->overflow
);
322 if (info
->compression
) {
323 monitor_printf(mon
, "compression pages: %" PRIu64
" pages\n",
324 info
->compression
->pages
);
325 monitor_printf(mon
, "compression busy: %" PRIu64
"\n",
326 info
->compression
->busy
);
327 monitor_printf(mon
, "compression busy rate: %0.2f\n",
328 info
->compression
->busy_rate
);
329 monitor_printf(mon
, "compressed size: %" PRIu64
" kbytes\n",
330 info
->compression
->compressed_size
>> 10);
331 monitor_printf(mon
, "compression rate: %0.2f\n",
332 info
->compression
->compression_rate
);
335 if (info
->has_cpu_throttle_percentage
) {
336 monitor_printf(mon
, "cpu throttle percentage: %" PRIu64
"\n",
337 info
->cpu_throttle_percentage
);
340 if (info
->has_postcopy_blocktime
) {
341 monitor_printf(mon
, "postcopy blocktime: %u\n",
342 info
->postcopy_blocktime
);
345 if (info
->has_postcopy_vcpu_blocktime
) {
348 v
= string_output_visitor_new(false, &str
);
349 visit_type_uint32List(v
, NULL
, &info
->postcopy_vcpu_blocktime
,
351 visit_complete(v
, &str
);
352 monitor_printf(mon
, "postcopy vcpu blocktime: %s\n", str
);
356 if (info
->has_socket_address
) {
357 SocketAddressList
*addr
;
359 monitor_printf(mon
, "socket address: [\n");
361 for (addr
= info
->socket_address
; addr
; addr
= addr
->next
) {
362 char *s
= socket_uri(addr
->value
);
363 monitor_printf(mon
, "\t%s\n", s
);
366 monitor_printf(mon
, "]\n");
370 monitor_printf(mon
, "vfio device transferred: %" PRIu64
" kbytes\n",
371 info
->vfio
->transferred
>> 10);
374 qapi_free_MigrationInfo(info
);
377 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
379 MigrationCapabilityStatusList
*caps
, *cap
;
381 caps
= qmp_query_migrate_capabilities(NULL
);
384 for (cap
= caps
; cap
; cap
= cap
->next
) {
385 monitor_printf(mon
, "%s: %s\n",
386 MigrationCapability_str(cap
->value
->capability
),
387 cap
->value
->state
? "on" : "off");
391 qapi_free_MigrationCapabilityStatusList(caps
);
394 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
396 MigrationParameters
*params
;
398 params
= qmp_query_migrate_parameters(NULL
);
401 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
402 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL
),
403 params
->announce_initial
);
404 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
405 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX
),
406 params
->announce_max
);
407 monitor_printf(mon
, "%s: %" PRIu64
"\n",
408 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS
),
409 params
->announce_rounds
);
410 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
411 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP
),
412 params
->announce_step
);
413 assert(params
->has_compress_level
);
414 monitor_printf(mon
, "%s: %u\n",
415 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL
),
416 params
->compress_level
);
417 assert(params
->has_compress_threads
);
418 monitor_printf(mon
, "%s: %u\n",
419 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS
),
420 params
->compress_threads
);
421 assert(params
->has_compress_wait_thread
);
422 monitor_printf(mon
, "%s: %s\n",
423 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD
),
424 params
->compress_wait_thread
? "on" : "off");
425 assert(params
->has_decompress_threads
);
426 monitor_printf(mon
, "%s: %u\n",
427 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS
),
428 params
->decompress_threads
);
429 assert(params
->has_throttle_trigger_threshold
);
430 monitor_printf(mon
, "%s: %u\n",
431 MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD
),
432 params
->throttle_trigger_threshold
);
433 assert(params
->has_cpu_throttle_initial
);
434 monitor_printf(mon
, "%s: %u\n",
435 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
),
436 params
->cpu_throttle_initial
);
437 assert(params
->has_cpu_throttle_increment
);
438 monitor_printf(mon
, "%s: %u\n",
439 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
),
440 params
->cpu_throttle_increment
);
441 assert(params
->has_cpu_throttle_tailslow
);
442 monitor_printf(mon
, "%s: %s\n",
443 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW
),
444 params
->cpu_throttle_tailslow
? "on" : "off");
445 assert(params
->has_max_cpu_throttle
);
446 monitor_printf(mon
, "%s: %u\n",
447 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE
),
448 params
->max_cpu_throttle
);
449 assert(params
->tls_creds
);
450 monitor_printf(mon
, "%s: '%s'\n",
451 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS
),
453 assert(params
->tls_hostname
);
454 monitor_printf(mon
, "%s: '%s'\n",
455 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME
),
456 params
->tls_hostname
);
457 assert(params
->has_max_bandwidth
);
458 monitor_printf(mon
, "%s: %" PRIu64
" bytes/second\n",
459 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH
),
460 params
->max_bandwidth
);
461 assert(params
->has_downtime_limit
);
462 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
463 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT
),
464 params
->downtime_limit
);
465 assert(params
->has_x_checkpoint_delay
);
466 monitor_printf(mon
, "%s: %u ms\n",
467 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
),
468 params
->x_checkpoint_delay
);
469 assert(params
->has_block_incremental
);
470 monitor_printf(mon
, "%s: %s\n",
471 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL
),
472 params
->block_incremental
? "on" : "off");
473 monitor_printf(mon
, "%s: %u\n",
474 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS
),
475 params
->multifd_channels
);
476 monitor_printf(mon
, "%s: %s\n",
477 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION
),
478 MultiFDCompression_str(params
->multifd_compression
));
479 monitor_printf(mon
, "%s: %" PRIu64
" bytes\n",
480 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
),
481 params
->xbzrle_cache_size
);
482 monitor_printf(mon
, "%s: %" PRIu64
"\n",
483 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH
),
484 params
->max_postcopy_bandwidth
);
485 monitor_printf(mon
, "%s: '%s'\n",
486 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ
),
489 if (params
->has_block_bitmap_mapping
) {
490 const BitmapMigrationNodeAliasList
*bmnal
;
492 monitor_printf(mon
, "%s:\n",
493 MigrationParameter_str(
494 MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING
));
496 for (bmnal
= params
->block_bitmap_mapping
;
500 const BitmapMigrationNodeAlias
*bmna
= bmnal
->value
;
501 const BitmapMigrationBitmapAliasList
*bmbal
;
503 monitor_printf(mon
, " '%s' -> '%s'\n",
504 bmna
->node_name
, bmna
->alias
);
506 for (bmbal
= bmna
->bitmaps
; bmbal
; bmbal
= bmbal
->next
) {
507 const BitmapMigrationBitmapAlias
*bmba
= bmbal
->value
;
509 monitor_printf(mon
, " '%s' -> '%s'\n",
510 bmba
->name
, bmba
->alias
);
516 qapi_free_MigrationParameters(params
);
521 /* Helper for hmp_info_vnc_clients, _servers */
522 static void hmp_info_VncBasicInfo(Monitor
*mon
, VncBasicInfo
*info
,
525 monitor_printf(mon
, " %s: %s:%s (%s%s)\n",
529 NetworkAddressFamily_str(info
->family
),
530 info
->websocket
? " (Websocket)" : "");
533 /* Helper displaying and auth and crypt info */
534 static void hmp_info_vnc_authcrypt(Monitor
*mon
, const char *indent
,
536 VncVencryptSubAuth
*vencrypt
)
538 monitor_printf(mon
, "%sAuth: %s (Sub: %s)\n", indent
,
539 VncPrimaryAuth_str(auth
),
540 vencrypt
? VncVencryptSubAuth_str(*vencrypt
) : "none");
543 static void hmp_info_vnc_clients(Monitor
*mon
, VncClientInfoList
*client
)
546 VncClientInfo
*cinfo
= client
->value
;
548 hmp_info_VncBasicInfo(mon
, qapi_VncClientInfo_base(cinfo
), "Client");
549 monitor_printf(mon
, " x509_dname: %s\n",
550 cinfo
->x509_dname
?: "none");
551 monitor_printf(mon
, " sasl_username: %s\n",
552 cinfo
->sasl_username
?: "none");
554 client
= client
->next
;
558 static void hmp_info_vnc_servers(Monitor
*mon
, VncServerInfo2List
*server
)
561 VncServerInfo2
*sinfo
= server
->value
;
562 hmp_info_VncBasicInfo(mon
, qapi_VncServerInfo2_base(sinfo
), "Server");
563 hmp_info_vnc_authcrypt(mon
, " ", sinfo
->auth
,
564 sinfo
->has_vencrypt
? &sinfo
->vencrypt
: NULL
);
565 server
= server
->next
;
569 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
571 VncInfo2List
*info2l
, *info2l_head
;
574 info2l
= qmp_query_vnc_servers(&err
);
575 info2l_head
= info2l
;
576 if (hmp_handle_error(mon
, err
)) {
580 monitor_printf(mon
, "None\n");
585 VncInfo2
*info
= info2l
->value
;
586 monitor_printf(mon
, "%s:\n", info
->id
);
587 hmp_info_vnc_servers(mon
, info
->server
);
588 hmp_info_vnc_clients(mon
, info
->clients
);
590 /* The server entry displays its auth, we only
591 * need to display in the case of 'reverse' connections
592 * where there's no server.
594 hmp_info_vnc_authcrypt(mon
, " ", info
->auth
,
595 info
->has_vencrypt
? &info
->vencrypt
: NULL
);
598 monitor_printf(mon
, " Display: %s\n", info
->display
);
600 info2l
= info2l
->next
;
603 qapi_free_VncInfo2List(info2l_head
);
609 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
611 SpiceChannelList
*chan
;
613 const char *channel_name
;
614 const char * const channel_names
[] = {
615 [SPICE_CHANNEL_MAIN
] = "main",
616 [SPICE_CHANNEL_DISPLAY
] = "display",
617 [SPICE_CHANNEL_INPUTS
] = "inputs",
618 [SPICE_CHANNEL_CURSOR
] = "cursor",
619 [SPICE_CHANNEL_PLAYBACK
] = "playback",
620 [SPICE_CHANNEL_RECORD
] = "record",
621 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
622 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
623 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
624 [SPICE_CHANNEL_PORT
] = "port",
626 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
627 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
628 * as quick fix for build failures with older versions. */
629 [SPICE_CHANNEL_WEBDAV
] = "webdav",
633 info
= qmp_query_spice(NULL
);
635 if (!info
->enabled
) {
636 monitor_printf(mon
, "Server: disabled\n");
640 monitor_printf(mon
, "Server:\n");
641 if (info
->has_port
) {
642 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
643 info
->host
, info
->port
);
645 if (info
->has_tls_port
) {
646 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
647 info
->host
, info
->tls_port
);
649 monitor_printf(mon
, " migrated: %s\n",
650 info
->migrated
? "true" : "false");
651 monitor_printf(mon
, " auth: %s\n", info
->auth
);
652 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
653 monitor_printf(mon
, " mouse-mode: %s\n",
654 SpiceQueryMouseMode_str(info
->mouse_mode
));
656 if (!info
->has_channels
|| info
->channels
== NULL
) {
657 monitor_printf(mon
, "Channels: none\n");
659 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
660 monitor_printf(mon
, "Channel:\n");
661 monitor_printf(mon
, " address: %s:%s%s\n",
662 chan
->value
->host
, chan
->value
->port
,
663 chan
->value
->tls
? " [tls]" : "");
664 monitor_printf(mon
, " session: %" PRId64
"\n",
665 chan
->value
->connection_id
);
666 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
667 chan
->value
->channel_type
, chan
->value
->channel_id
);
669 channel_name
= "unknown";
670 if (chan
->value
->channel_type
> 0 &&
671 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
672 channel_names
[chan
->value
->channel_type
]) {
673 channel_name
= channel_names
[chan
->value
->channel_type
];
676 monitor_printf(mon
, " channel name: %s\n", channel_name
);
681 qapi_free_SpiceInfo(info
);
685 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
690 info
= qmp_query_balloon(&err
);
691 if (hmp_handle_error(mon
, err
)) {
695 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
697 qapi_free_BalloonInfo(info
);
700 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
702 InterruptStatsProvider
*intc
;
703 InterruptStatsProviderClass
*k
;
704 Monitor
*mon
= opaque
;
706 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
707 intc
= INTERRUPT_STATS_PROVIDER(obj
);
708 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
710 k
->print_info(intc
, mon
);
712 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
713 object_get_typename(obj
));
720 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
722 object_child_foreach_recursive(object_get_root(),
723 hmp_info_pic_foreach
, mon
);
726 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
729 TPMInfoList
*info_list
, *info
;
732 TPMPassthroughOptions
*tpo
;
733 TPMEmulatorOptions
*teo
;
735 info_list
= qmp_query_tpm(&err
);
737 monitor_printf(mon
, "TPM device not supported\n");
743 monitor_printf(mon
, "TPM device:\n");
746 for (info
= info_list
; info
; info
= info
->next
) {
747 TPMInfo
*ti
= info
->value
;
748 monitor_printf(mon
, " tpm%d: model=%s\n",
749 c
, TpmModel_str(ti
->model
));
751 monitor_printf(mon
, " \\ %s: type=%s",
752 ti
->id
, TpmType_str(ti
->options
->type
));
754 switch (ti
->options
->type
) {
755 case TPM_TYPE_PASSTHROUGH
:
756 tpo
= ti
->options
->u
.passthrough
.data
;
757 monitor_printf(mon
, "%s%s%s%s",
758 tpo
->path
? ",path=" : "",
760 tpo
->cancel_path
? ",cancel-path=" : "",
761 tpo
->cancel_path
?: "");
763 case TPM_TYPE_EMULATOR
:
764 teo
= ti
->options
->u
.emulator
.data
;
765 monitor_printf(mon
, ",chardev=%s", teo
->chardev
);
770 monitor_printf(mon
, "\n");
773 qapi_free_TPMInfoList(info_list
);
775 monitor_printf(mon
, "TPM device not supported\n");
776 #endif /* CONFIG_TPM */
779 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
781 monitor_suspend(mon
);
785 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
790 void hmp_sync_profile(Monitor
*mon
, const QDict
*qdict
)
792 const char *op
= qdict_get_try_str(qdict
, "op");
795 bool on
= qsp_is_enabled();
797 monitor_printf(mon
, "sync-profile is %s\n", on
? "on" : "off");
800 if (!strcmp(op
, "on")) {
802 } else if (!strcmp(op
, "off")) {
804 } else if (!strcmp(op
, "reset")) {
809 error_setg(&err
, QERR_INVALID_PARAMETER
, op
);
810 hmp_handle_error(mon
, err
);
814 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
816 qmp_system_reset(NULL
);
819 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
821 qmp_system_powerdown(NULL
);
824 void hmp_exit_preconfig(Monitor
*mon
, const QDict
*qdict
)
828 qmp_x_exit_preconfig(&err
);
829 hmp_handle_error(mon
, err
);
832 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
836 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
837 use it are converted to the QAPI */
838 cpu_index
= qdict_get_int(qdict
, "index");
839 if (monitor_set_cpu(mon
, cpu_index
) < 0) {
840 monitor_printf(mon
, "invalid CPU index\n");
844 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
846 uint32_t size
= qdict_get_int(qdict
, "size");
847 const char *filename
= qdict_get_str(qdict
, "filename");
848 uint64_t addr
= qdict_get_int(qdict
, "val");
850 int cpu_index
= monitor_get_cpu_index(mon
);
853 monitor_printf(mon
, "No CPU available\n");
857 qmp_memsave(addr
, size
, filename
, true, cpu_index
, &err
);
858 hmp_handle_error(mon
, err
);
861 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
863 uint32_t size
= qdict_get_int(qdict
, "size");
864 const char *filename
= qdict_get_str(qdict
, "filename");
865 uint64_t addr
= qdict_get_int(qdict
, "val");
868 qmp_pmemsave(addr
, size
, filename
, &err
);
869 hmp_handle_error(mon
, err
);
872 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
874 const char *chardev
= qdict_get_str(qdict
, "device");
875 const char *data
= qdict_get_str(qdict
, "data");
878 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
880 hmp_handle_error(mon
, err
);
883 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
885 uint32_t size
= qdict_get_int(qdict
, "size");
886 const char *chardev
= qdict_get_str(qdict
, "device");
891 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
892 if (hmp_handle_error(mon
, err
)) {
896 for (i
= 0; data
[i
]; i
++) {
897 unsigned char ch
= data
[i
];
900 monitor_printf(mon
, "\\\\");
901 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
902 monitor_printf(mon
, "\\u%04X", ch
);
904 monitor_printf(mon
, "%c", ch
);
908 monitor_printf(mon
, "\n");
912 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
917 hmp_handle_error(mon
, err
);
920 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
924 qmp_system_wakeup(&err
);
925 hmp_handle_error(mon
, err
);
928 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
932 qmp_inject_nmi(&err
);
933 hmp_handle_error(mon
, err
);
936 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
938 const char *name
= qdict_get_str(qdict
, "name");
939 bool up
= qdict_get_bool(qdict
, "up");
942 qmp_set_link(name
, up
, &err
);
943 hmp_handle_error(mon
, err
);
946 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
948 int64_t value
= qdict_get_int(qdict
, "value");
951 qmp_balloon(value
, &err
);
952 hmp_handle_error(mon
, err
);
955 void hmp_loadvm(Monitor
*mon
, const QDict
*qdict
)
957 int saved_vm_running
= runstate_is_running();
958 const char *name
= qdict_get_str(qdict
, "name");
961 vm_stop(RUN_STATE_RESTORE_VM
);
963 if (load_snapshot(name
, NULL
, false, NULL
, &err
) && saved_vm_running
) {
966 hmp_handle_error(mon
, err
);
969 void hmp_savevm(Monitor
*mon
, const QDict
*qdict
)
973 save_snapshot(qdict_get_try_str(qdict
, "name"),
974 true, NULL
, false, NULL
, &err
);
975 hmp_handle_error(mon
, err
);
978 void hmp_delvm(Monitor
*mon
, const QDict
*qdict
)
981 const char *name
= qdict_get_str(qdict
, "name");
983 delete_snapshot(name
, false, NULL
, &err
);
984 hmp_handle_error(mon
, err
);
987 void hmp_announce_self(Monitor
*mon
, const QDict
*qdict
)
989 const char *interfaces_str
= qdict_get_try_str(qdict
, "interfaces");
990 const char *id
= qdict_get_try_str(qdict
, "id");
991 AnnounceParameters
*params
= QAPI_CLONE(AnnounceParameters
,
992 migrate_announce_params());
994 qapi_free_strList(params
->interfaces
);
995 params
->interfaces
= strList_from_comma_list(interfaces_str
);
996 params
->has_interfaces
= params
->interfaces
!= NULL
;
997 params
->id
= g_strdup(id
);
998 qmp_announce_self(params
, NULL
);
999 qapi_free_AnnounceParameters(params
);
1002 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1004 qmp_migrate_cancel(NULL
);
1007 void hmp_migrate_continue(Monitor
*mon
, const QDict
*qdict
)
1010 const char *state
= qdict_get_str(qdict
, "state");
1011 int val
= qapi_enum_parse(&MigrationStatus_lookup
, state
, -1, &err
);
1014 qmp_migrate_continue(val
, &err
);
1017 hmp_handle_error(mon
, err
);
1020 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1023 const char *uri
= qdict_get_str(qdict
, "uri");
1025 qmp_migrate_incoming(uri
, &err
);
1027 hmp_handle_error(mon
, err
);
1030 void hmp_migrate_recover(Monitor
*mon
, const QDict
*qdict
)
1033 const char *uri
= qdict_get_str(qdict
, "uri");
1035 qmp_migrate_recover(uri
, &err
);
1037 hmp_handle_error(mon
, err
);
1040 void hmp_migrate_pause(Monitor
*mon
, const QDict
*qdict
)
1044 qmp_migrate_pause(&err
);
1046 hmp_handle_error(mon
, err
);
1050 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1052 const char *cap
= qdict_get_str(qdict
, "capability");
1053 bool state
= qdict_get_bool(qdict
, "state");
1055 MigrationCapabilityStatusList
*caps
= NULL
;
1056 MigrationCapabilityStatus
*value
;
1059 val
= qapi_enum_parse(&MigrationCapability_lookup
, cap
, -1, &err
);
1064 value
= g_malloc0(sizeof(*value
));
1065 value
->capability
= val
;
1066 value
->state
= state
;
1067 QAPI_LIST_PREPEND(caps
, value
);
1068 qmp_migrate_set_capabilities(caps
, &err
);
1069 qapi_free_MigrationCapabilityStatusList(caps
);
1072 hmp_handle_error(mon
, err
);
1075 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1077 const char *param
= qdict_get_str(qdict
, "parameter");
1078 const char *valuestr
= qdict_get_str(qdict
, "value");
1079 Visitor
*v
= string_input_visitor_new(valuestr
);
1080 MigrateSetParameters
*p
= g_new0(MigrateSetParameters
, 1);
1081 uint64_t valuebw
= 0;
1082 uint64_t cache_size
;
1086 val
= qapi_enum_parse(&MigrationParameter_lookup
, param
, -1, &err
);
1092 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1093 p
->has_compress_level
= true;
1094 visit_type_uint8(v
, param
, &p
->compress_level
, &err
);
1096 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1097 p
->has_compress_threads
= true;
1098 visit_type_uint8(v
, param
, &p
->compress_threads
, &err
);
1100 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD
:
1101 p
->has_compress_wait_thread
= true;
1102 visit_type_bool(v
, param
, &p
->compress_wait_thread
, &err
);
1104 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1105 p
->has_decompress_threads
= true;
1106 visit_type_uint8(v
, param
, &p
->decompress_threads
, &err
);
1108 case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD
:
1109 p
->has_throttle_trigger_threshold
= true;
1110 visit_type_uint8(v
, param
, &p
->throttle_trigger_threshold
, &err
);
1112 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1113 p
->has_cpu_throttle_initial
= true;
1114 visit_type_uint8(v
, param
, &p
->cpu_throttle_initial
, &err
);
1116 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1117 p
->has_cpu_throttle_increment
= true;
1118 visit_type_uint8(v
, param
, &p
->cpu_throttle_increment
, &err
);
1120 case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW
:
1121 p
->has_cpu_throttle_tailslow
= true;
1122 visit_type_bool(v
, param
, &p
->cpu_throttle_tailslow
, &err
);
1124 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE
:
1125 p
->has_max_cpu_throttle
= true;
1126 visit_type_uint8(v
, param
, &p
->max_cpu_throttle
, &err
);
1128 case MIGRATION_PARAMETER_TLS_CREDS
:
1129 p
->tls_creds
= g_new0(StrOrNull
, 1);
1130 p
->tls_creds
->type
= QTYPE_QSTRING
;
1131 visit_type_str(v
, param
, &p
->tls_creds
->u
.s
, &err
);
1133 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1134 p
->tls_hostname
= g_new0(StrOrNull
, 1);
1135 p
->tls_hostname
->type
= QTYPE_QSTRING
;
1136 visit_type_str(v
, param
, &p
->tls_hostname
->u
.s
, &err
);
1138 case MIGRATION_PARAMETER_TLS_AUTHZ
:
1139 p
->tls_authz
= g_new0(StrOrNull
, 1);
1140 p
->tls_authz
->type
= QTYPE_QSTRING
;
1141 visit_type_str(v
, param
, &p
->tls_authz
->u
.s
, &err
);
1143 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1144 p
->has_max_bandwidth
= true;
1146 * Can't use visit_type_size() here, because it
1147 * defaults to Bytes rather than Mebibytes.
1149 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
1150 if (ret
< 0 || valuebw
> INT64_MAX
1151 || (size_t)valuebw
!= valuebw
) {
1152 error_setg(&err
, "Invalid size %s", valuestr
);
1155 p
->max_bandwidth
= valuebw
;
1157 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1158 p
->has_downtime_limit
= true;
1159 visit_type_size(v
, param
, &p
->downtime_limit
, &err
);
1161 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
1162 p
->has_x_checkpoint_delay
= true;
1163 visit_type_uint32(v
, param
, &p
->x_checkpoint_delay
, &err
);
1165 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL
:
1166 p
->has_block_incremental
= true;
1167 visit_type_bool(v
, param
, &p
->block_incremental
, &err
);
1169 case MIGRATION_PARAMETER_MULTIFD_CHANNELS
:
1170 p
->has_multifd_channels
= true;
1171 visit_type_uint8(v
, param
, &p
->multifd_channels
, &err
);
1173 case MIGRATION_PARAMETER_MULTIFD_COMPRESSION
:
1174 p
->has_multifd_compression
= true;
1175 visit_type_MultiFDCompression(v
, param
, &p
->multifd_compression
,
1178 case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL
:
1179 p
->has_multifd_zlib_level
= true;
1180 visit_type_uint8(v
, param
, &p
->multifd_zlib_level
, &err
);
1182 case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL
:
1183 p
->has_multifd_zstd_level
= true;
1184 visit_type_uint8(v
, param
, &p
->multifd_zstd_level
, &err
);
1186 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
:
1187 p
->has_xbzrle_cache_size
= true;
1188 if (!visit_type_size(v
, param
, &cache_size
, &err
)) {
1191 if (cache_size
> INT64_MAX
|| (size_t)cache_size
!= cache_size
) {
1192 error_setg(&err
, "Invalid size %s", valuestr
);
1195 p
->xbzrle_cache_size
= cache_size
;
1197 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH
:
1198 p
->has_max_postcopy_bandwidth
= true;
1199 visit_type_size(v
, param
, &p
->max_postcopy_bandwidth
, &err
);
1201 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL
:
1202 p
->has_announce_initial
= true;
1203 visit_type_size(v
, param
, &p
->announce_initial
, &err
);
1205 case MIGRATION_PARAMETER_ANNOUNCE_MAX
:
1206 p
->has_announce_max
= true;
1207 visit_type_size(v
, param
, &p
->announce_max
, &err
);
1209 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS
:
1210 p
->has_announce_rounds
= true;
1211 visit_type_size(v
, param
, &p
->announce_rounds
, &err
);
1213 case MIGRATION_PARAMETER_ANNOUNCE_STEP
:
1214 p
->has_announce_step
= true;
1215 visit_type_size(v
, param
, &p
->announce_step
, &err
);
1217 case MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING
:
1218 error_setg(&err
, "The block-bitmap-mapping parameter can only be set "
1229 qmp_migrate_set_parameters(p
, &err
);
1232 qapi_free_MigrateSetParameters(p
);
1234 hmp_handle_error(mon
, err
);
1237 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1240 const char *protocol
= qdict_get_str(qdict
, "protocol");
1241 const char *hostname
= qdict_get_str(qdict
, "hostname");
1242 bool has_port
= qdict_haskey(qdict
, "port");
1243 int port
= qdict_get_try_int(qdict
, "port", -1);
1244 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1245 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1246 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1248 qmp_client_migrate_info(protocol
, hostname
,
1249 has_port
, port
, has_tls_port
, tls_port
,
1250 cert_subject
, &err
);
1251 hmp_handle_error(mon
, err
);
1254 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1257 qmp_migrate_start_postcopy(&err
);
1258 hmp_handle_error(mon
, err
);
1261 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1265 qmp_x_colo_lost_heartbeat(&err
);
1266 hmp_handle_error(mon
, err
);
1269 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1271 const char *protocol
= qdict_get_str(qdict
, "protocol");
1272 const char *password
= qdict_get_str(qdict
, "password");
1273 const char *display
= qdict_get_try_str(qdict
, "display");
1274 const char *connected
= qdict_get_try_str(qdict
, "connected");
1277 SetPasswordOptions opts
= {
1278 .password
= (char *)password
,
1279 .has_connected
= !!connected
,
1282 opts
.connected
= qapi_enum_parse(&SetPasswordAction_lookup
, connected
,
1283 SET_PASSWORD_ACTION_KEEP
, &err
);
1288 opts
.protocol
= qapi_enum_parse(&DisplayProtocol_lookup
, protocol
,
1289 DISPLAY_PROTOCOL_VNC
, &err
);
1294 if (opts
.protocol
== DISPLAY_PROTOCOL_VNC
) {
1295 opts
.u
.vnc
.display
= (char *)display
;
1298 qmp_set_password(&opts
, &err
);
1301 hmp_handle_error(mon
, err
);
1304 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1306 const char *protocol
= qdict_get_str(qdict
, "protocol");
1307 const char *whenstr
= qdict_get_str(qdict
, "time");
1308 const char *display
= qdict_get_try_str(qdict
, "display");
1311 ExpirePasswordOptions opts
= {
1312 .time
= (char *)whenstr
,
1315 opts
.protocol
= qapi_enum_parse(&DisplayProtocol_lookup
, protocol
,
1316 DISPLAY_PROTOCOL_VNC
, &err
);
1321 if (opts
.protocol
== DISPLAY_PROTOCOL_VNC
) {
1322 opts
.u
.vnc
.display
= (char *)display
;
1325 qmp_expire_password(&opts
, &err
);
1328 hmp_handle_error(mon
, err
);
1333 static void hmp_change_read_arg(void *opaque
, const char *password
,
1334 void *readline_opaque
)
1336 qmp_change_vnc_password(password
, NULL
);
1337 monitor_read_command(opaque
, 1);
1341 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1343 const char *device
= qdict_get_str(qdict
, "device");
1344 const char *target
= qdict_get_str(qdict
, "target");
1345 const char *arg
= qdict_get_try_str(qdict
, "arg");
1346 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1347 bool force
= qdict_get_try_bool(qdict
, "force", false);
1348 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1352 if (strcmp(device
, "vnc") == 0) {
1355 "Parameter 'read-only-mode' is invalid for VNC\n");
1358 if (strcmp(target
, "passwd") == 0 ||
1359 strcmp(target
, "password") == 0) {
1361 MonitorHMP
*hmp_mon
= container_of(mon
, MonitorHMP
, common
);
1362 monitor_read_password(hmp_mon
, hmp_change_read_arg
, NULL
);
1365 qmp_change_vnc_password(arg
, &err
);
1368 monitor_printf(mon
, "Expected 'password' after 'vnc'\n");
1375 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup
,
1377 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1383 qmp_blockdev_change_medium(device
, NULL
, target
, arg
, true, force
,
1384 !!read_only
, read_only_mode
,
1389 hmp_handle_error(mon
, err
);
1392 typedef struct HMPMigrationStatus
{
1395 bool is_block_migration
;
1396 } HMPMigrationStatus
;
1398 static void hmp_migrate_status_cb(void *opaque
)
1400 HMPMigrationStatus
*status
= opaque
;
1401 MigrationInfo
*info
;
1403 info
= qmp_query_migrate(NULL
);
1404 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1405 info
->status
== MIGRATION_STATUS_SETUP
) {
1409 if (info
->disk
->remaining
) {
1410 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1415 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1416 monitor_flush(status
->mon
);
1419 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1421 if (status
->is_block_migration
) {
1422 monitor_printf(status
->mon
, "\n");
1424 if (info
->error_desc
) {
1425 error_report("%s", info
->error_desc
);
1427 monitor_resume(status
->mon
);
1428 timer_free(status
->timer
);
1432 qapi_free_MigrationInfo(info
);
1435 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1437 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1438 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1439 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1440 bool resume
= qdict_get_try_bool(qdict
, "resume", false);
1441 const char *uri
= qdict_get_str(qdict
, "uri");
1444 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
,
1445 false, false, true, resume
, &err
);
1446 if (hmp_handle_error(mon
, err
)) {
1451 HMPMigrationStatus
*status
;
1453 if (monitor_suspend(mon
) < 0) {
1454 monitor_printf(mon
, "terminal does not allow synchronous "
1455 "migration, continuing detached\n");
1459 status
= g_malloc0(sizeof(*status
));
1461 status
->is_block_migration
= blk
|| inc
;
1462 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1464 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1468 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1472 const char *type
= qdict_get_try_str(qdict
, "type");
1474 if (type
&& is_help_option(type
)) {
1478 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1483 netdev_add(opts
, &err
);
1485 qemu_opts_del(opts
);
1489 hmp_handle_error(mon
, err
);
1492 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1494 const char *id
= qdict_get_str(qdict
, "id");
1497 qmp_netdev_del(id
, &err
);
1498 hmp_handle_error(mon
, err
);
1501 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
1503 const char *options
= qdict_get_str(qdict
, "object");
1506 user_creatable_add_from_str(options
, &err
);
1507 hmp_handle_error(mon
, err
);
1510 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1512 const char *fdname
= qdict_get_str(qdict
, "fdname");
1515 qmp_getfd(fdname
, &err
);
1516 hmp_handle_error(mon
, err
);
1519 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1521 const char *fdname
= qdict_get_str(qdict
, "fdname");
1524 qmp_closefd(fdname
, &err
);
1525 hmp_handle_error(mon
, err
);
1528 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
1530 const char *keys
= qdict_get_str(qdict
, "keys");
1532 KeyValueList
*head
= NULL
, **tail
= &head
;
1533 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1534 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1536 const char *separator
;
1540 separator
= qemu_strchrnul(keys
, '-');
1541 keyname_len
= separator
- keys
;
1543 /* Be compatible with old interface, convert user inputted "<" */
1544 if (keys
[0] == '<' && keyname_len
== 1) {
1549 v
= g_malloc0(sizeof(*v
));
1551 if (strstart(keys
, "0x", NULL
)) {
1553 int value
= strtoul(keys
, &endp
, 0);
1554 assert(endp
<= keys
+ keyname_len
);
1555 if (endp
!= keys
+ keyname_len
) {
1558 v
->type
= KEY_VALUE_KIND_NUMBER
;
1559 v
->u
.number
.data
= value
;
1561 int idx
= index_from_key(keys
, keyname_len
);
1562 if (idx
== Q_KEY_CODE__MAX
) {
1565 v
->type
= KEY_VALUE_KIND_QCODE
;
1566 v
->u
.qcode
.data
= idx
;
1568 QAPI_LIST_APPEND(tail
, v
);
1574 keys
= separator
+ 1;
1577 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1578 hmp_handle_error(mon
, err
);
1581 qapi_free_KeyValue(v
);
1582 qapi_free_KeyValueList(head
);
1586 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
1591 hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
1593 const char *filename
= qdict_get_str(qdict
, "filename");
1594 const char *id
= qdict_get_try_str(qdict
, "device");
1595 int64_t head
= qdict_get_try_int(qdict
, "head", 0);
1596 const char *input_format
= qdict_get_try_str(qdict
, "format");
1600 format
= qapi_enum_parse(&ImageFormat_lookup
, input_format
,
1601 IMAGE_FORMAT_PPM
, &err
);
1606 qmp_screendump(filename
, id
, id
!= NULL
, head
,
1607 input_format
!= NULL
, format
, &err
);
1609 hmp_handle_error(mon
, err
);
1612 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
1614 const char *args
= qdict_get_str(qdict
, "args");
1618 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
1620 error_setg(&err
, "Parsing chardev args failed");
1622 qemu_chr_new_from_opts(opts
, NULL
, &err
);
1623 qemu_opts_del(opts
);
1625 hmp_handle_error(mon
, err
);
1628 void hmp_chardev_change(Monitor
*mon
, const QDict
*qdict
)
1630 const char *args
= qdict_get_str(qdict
, "args");
1633 ChardevBackend
*backend
= NULL
;
1634 ChardevReturn
*ret
= NULL
;
1635 QemuOpts
*opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
,
1638 error_setg(&err
, "Parsing chardev args failed");
1642 id
= qdict_get_str(qdict
, "id");
1643 if (qemu_opts_id(opts
)) {
1644 error_setg(&err
, "Unexpected 'id' parameter");
1648 backend
= qemu_chr_parse_opts(opts
, &err
);
1653 ret
= qmp_chardev_change(id
, backend
, &err
);
1656 qapi_free_ChardevReturn(ret
);
1657 qapi_free_ChardevBackend(backend
);
1658 qemu_opts_del(opts
);
1659 hmp_handle_error(mon
, err
);
1662 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
1664 Error
*local_err
= NULL
;
1666 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
1667 hmp_handle_error(mon
, local_err
);
1670 void hmp_chardev_send_break(Monitor
*mon
, const QDict
*qdict
)
1672 Error
*local_err
= NULL
;
1674 qmp_chardev_send_break(qdict_get_str(qdict
, "id"), &local_err
);
1675 hmp_handle_error(mon
, local_err
);
1678 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
1680 const char *id
= qdict_get_str(qdict
, "id");
1683 user_creatable_del(id
, &err
);
1684 hmp_handle_error(mon
, err
);
1687 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
1690 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
1691 MemoryDeviceInfoList
*info
;
1692 VirtioPMEMDeviceInfo
*vpi
;
1693 VirtioMEMDeviceInfo
*vmi
;
1694 MemoryDeviceInfo
*value
;
1695 PCDIMMDeviceInfo
*di
;
1696 SgxEPCDeviceInfo
*se
;
1698 for (info
= info_list
; info
; info
= info
->next
) {
1699 value
= info
->value
;
1702 switch (value
->type
) {
1703 case MEMORY_DEVICE_INFO_KIND_DIMM
:
1704 case MEMORY_DEVICE_INFO_KIND_NVDIMM
:
1705 di
= value
->type
== MEMORY_DEVICE_INFO_KIND_DIMM
?
1706 value
->u
.dimm
.data
: value
->u
.nvdimm
.data
;
1707 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1708 MemoryDeviceInfoKind_str(value
->type
),
1709 di
->id
? di
->id
: "");
1710 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
1711 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
1712 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
1713 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
1714 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
1715 monitor_printf(mon
, " hotplugged: %s\n",
1716 di
->hotplugged
? "true" : "false");
1717 monitor_printf(mon
, " hotpluggable: %s\n",
1718 di
->hotpluggable
? "true" : "false");
1720 case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM
:
1721 vpi
= value
->u
.virtio_pmem
.data
;
1722 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1723 MemoryDeviceInfoKind_str(value
->type
),
1724 vpi
->id
? vpi
->id
: "");
1725 monitor_printf(mon
, " memaddr: 0x%" PRIx64
"\n", vpi
->memaddr
);
1726 monitor_printf(mon
, " size: %" PRIu64
"\n", vpi
->size
);
1727 monitor_printf(mon
, " memdev: %s\n", vpi
->memdev
);
1729 case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM
:
1730 vmi
= value
->u
.virtio_mem
.data
;
1731 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1732 MemoryDeviceInfoKind_str(value
->type
),
1733 vmi
->id
? vmi
->id
: "");
1734 monitor_printf(mon
, " memaddr: 0x%" PRIx64
"\n", vmi
->memaddr
);
1735 monitor_printf(mon
, " node: %" PRId64
"\n", vmi
->node
);
1736 monitor_printf(mon
, " requested-size: %" PRIu64
"\n",
1737 vmi
->requested_size
);
1738 monitor_printf(mon
, " size: %" PRIu64
"\n", vmi
->size
);
1739 monitor_printf(mon
, " max-size: %" PRIu64
"\n", vmi
->max_size
);
1740 monitor_printf(mon
, " block-size: %" PRIu64
"\n",
1742 monitor_printf(mon
, " memdev: %s\n", vmi
->memdev
);
1744 case MEMORY_DEVICE_INFO_KIND_SGX_EPC
:
1745 se
= value
->u
.sgx_epc
.data
;
1746 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1747 MemoryDeviceInfoKind_str(value
->type
),
1748 se
->id
? se
->id
: "");
1749 monitor_printf(mon
, " memaddr: 0x%" PRIx64
"\n", se
->memaddr
);
1750 monitor_printf(mon
, " size: %" PRIu64
"\n", se
->size
);
1751 monitor_printf(mon
, " node: %" PRId64
"\n", se
->node
);
1752 monitor_printf(mon
, " memdev: %s\n", se
->memdev
);
1755 g_assert_not_reached();
1760 qapi_free_MemoryDeviceInfoList(info_list
);
1761 hmp_handle_error(mon
, err
);
1764 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
1766 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
1767 IOThreadInfoList
*info
;
1768 IOThreadInfo
*value
;
1770 for (info
= info_list
; info
; info
= info
->next
) {
1771 value
= info
->value
;
1772 monitor_printf(mon
, "%s:\n", value
->id
);
1773 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
1774 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
1775 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
1776 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
1777 monitor_printf(mon
, " aio-max-batch=%" PRId64
"\n",
1778 value
->aio_max_batch
);
1781 qapi_free_IOThreadInfoList(info_list
);
1784 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
1786 const char *name
= qdict_get_str(qdict
, "name");
1787 RockerSwitch
*rocker
;
1790 rocker
= qmp_query_rocker(name
, &err
);
1791 if (hmp_handle_error(mon
, err
)) {
1795 monitor_printf(mon
, "name: %s\n", rocker
->name
);
1796 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
1797 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
1799 qapi_free_RockerSwitch(rocker
);
1802 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
1804 RockerPortList
*list
, *port
;
1805 const char *name
= qdict_get_str(qdict
, "name");
1808 list
= qmp_query_rocker_ports(name
, &err
);
1809 if (hmp_handle_error(mon
, err
)) {
1813 monitor_printf(mon
, " ena/ speed/ auto\n");
1814 monitor_printf(mon
, " port link duplex neg?\n");
1816 for (port
= list
; port
; port
= port
->next
) {
1817 monitor_printf(mon
, "%10s %-4s %-3s %2s %s\n",
1819 port
->value
->enabled
? port
->value
->link_up
?
1820 "up" : "down" : "!ena",
1821 port
->value
->speed
== 10000 ? "10G" : "??",
1822 port
->value
->duplex
? "FD" : "HD",
1823 port
->value
->autoneg
? "Yes" : "No");
1826 qapi_free_RockerPortList(list
);
1829 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
1831 RockerOfDpaFlowList
*list
, *info
;
1832 const char *name
= qdict_get_str(qdict
, "name");
1833 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
1836 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
1837 if (hmp_handle_error(mon
, err
)) {
1841 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
1843 for (info
= list
; info
; info
= info
->next
) {
1844 RockerOfDpaFlow
*flow
= info
->value
;
1845 RockerOfDpaFlowKey
*key
= flow
->key
;
1846 RockerOfDpaFlowMask
*mask
= flow
->mask
;
1847 RockerOfDpaFlowAction
*action
= flow
->action
;
1850 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
1851 key
->priority
, key
->tbl_id
, flow
->hits
);
1853 monitor_printf(mon
, "%-4d %-3d ",
1854 key
->priority
, key
->tbl_id
);
1857 if (key
->has_in_pport
) {
1858 monitor_printf(mon
, " pport %d", key
->in_pport
);
1859 if (mask
->has_in_pport
) {
1860 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
1864 if (key
->has_vlan_id
) {
1865 monitor_printf(mon
, " vlan %d",
1866 key
->vlan_id
& VLAN_VID_MASK
);
1867 if (mask
->has_vlan_id
) {
1868 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
1872 if (key
->has_tunnel_id
) {
1873 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
1874 if (mask
->has_tunnel_id
) {
1875 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
1879 if (key
->has_eth_type
) {
1880 switch (key
->eth_type
) {
1882 monitor_printf(mon
, " ARP");
1885 monitor_printf(mon
, " IP");
1888 monitor_printf(mon
, " IPv6");
1891 monitor_printf(mon
, " LACP");
1894 monitor_printf(mon
, " LLDP");
1897 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
1903 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
1905 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
1906 monitor_printf(mon
, " src <any mcast/bcast>");
1907 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
1909 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
1910 monitor_printf(mon
, " src <any ucast>");
1912 monitor_printf(mon
, " src %s", key
->eth_src
);
1913 if (mask
->eth_src
) {
1914 monitor_printf(mon
, "(%s)", mask
->eth_src
);
1920 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
1922 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
1923 monitor_printf(mon
, " dst <any mcast/bcast>");
1924 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
1926 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
1927 monitor_printf(mon
, " dst <any ucast>");
1929 monitor_printf(mon
, " dst %s", key
->eth_dst
);
1930 if (mask
->eth_dst
) {
1931 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
1936 if (key
->has_ip_proto
) {
1937 monitor_printf(mon
, " proto %d", key
->ip_proto
);
1938 if (mask
->has_ip_proto
) {
1939 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
1943 if (key
->has_ip_tos
) {
1944 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
1945 if (mask
->has_ip_tos
) {
1946 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
1951 monitor_printf(mon
, " dst %s", key
->ip_dst
);
1954 if (action
->has_goto_tbl
|| action
->has_group_id
||
1955 action
->has_new_vlan_id
) {
1956 monitor_printf(mon
, " -->");
1959 if (action
->has_new_vlan_id
) {
1960 monitor_printf(mon
, " apply new vlan %d",
1961 ntohs(action
->new_vlan_id
));
1964 if (action
->has_group_id
) {
1965 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
1968 if (action
->has_goto_tbl
) {
1969 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
1972 monitor_printf(mon
, "\n");
1975 qapi_free_RockerOfDpaFlowList(list
);
1978 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
1980 RockerOfDpaGroupList
*list
, *g
;
1981 const char *name
= qdict_get_str(qdict
, "name");
1982 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
1985 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
1986 if (hmp_handle_error(mon
, err
)) {
1990 monitor_printf(mon
, "id (decode) --> buckets\n");
1992 for (g
= list
; g
; g
= g
->next
) {
1993 RockerOfDpaGroup
*group
= g
->value
;
1996 monitor_printf(mon
, "0x%08x", group
->id
);
1998 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
1999 group
->type
== 1 ? "L2 rewrite" :
2000 group
->type
== 2 ? "L3 unicast" :
2001 group
->type
== 3 ? "L2 multicast" :
2002 group
->type
== 4 ? "L2 flood" :
2003 group
->type
== 5 ? "L3 interface" :
2004 group
->type
== 6 ? "L3 multicast" :
2005 group
->type
== 7 ? "L3 ECMP" :
2006 group
->type
== 8 ? "L2 overlay" :
2009 if (group
->has_vlan_id
) {
2010 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2013 if (group
->has_pport
) {
2014 monitor_printf(mon
, " pport %d", group
->pport
);
2017 if (group
->has_index
) {
2018 monitor_printf(mon
, " index %d", group
->index
);
2021 monitor_printf(mon
, ") -->");
2023 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2025 monitor_printf(mon
, " set vlan %d",
2026 group
->set_vlan_id
& VLAN_VID_MASK
);
2029 if (group
->set_eth_src
) {
2032 monitor_printf(mon
, " set");
2034 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2037 if (group
->set_eth_dst
) {
2039 monitor_printf(mon
, " set");
2041 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2044 if (group
->has_ttl_check
&& group
->ttl_check
) {
2045 monitor_printf(mon
, " check TTL");
2048 if (group
->has_group_id
&& group
->group_id
) {
2049 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2052 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2053 monitor_printf(mon
, " pop vlan");
2056 if (group
->has_out_pport
) {
2057 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2060 if (group
->has_group_ids
) {
2061 struct uint32List
*id
;
2063 monitor_printf(mon
, " groups [");
2064 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2065 monitor_printf(mon
, "0x%08x", id
->value
);
2067 monitor_printf(mon
, ",");
2070 monitor_printf(mon
, "]");
2073 monitor_printf(mon
, "\n");
2076 qapi_free_RockerOfDpaGroupList(list
);
2079 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
2082 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
2084 monitor_printf(mon
, "%s\n", info
->guid
);
2086 hmp_handle_error(mon
, err
);
2087 qapi_free_GuidInfo(info
);
2090 void hmp_info_memory_size_summary(Monitor
*mon
, const QDict
*qdict
)
2093 MemoryInfo
*info
= qmp_query_memory_size_summary(&err
);
2095 monitor_printf(mon
, "base memory: %" PRIu64
"\n",
2098 if (info
->has_plugged_memory
) {
2099 monitor_printf(mon
, "plugged memory: %" PRIu64
"\n",
2100 info
->plugged_memory
);
2103 qapi_free_MemoryInfo(info
);
2105 hmp_handle_error(mon
, err
);
2108 static void print_stats_schema_value(Monitor
*mon
, StatsSchemaValue
*value
)
2110 const char *unit
= NULL
;
2111 monitor_printf(mon
, " %s (%s%s", value
->name
, StatsType_str(value
->type
),
2112 value
->has_unit
|| value
->exponent
? ", " : "");
2114 if (value
->has_unit
) {
2115 if (value
->unit
== STATS_UNIT_SECONDS
) {
2117 } else if (value
->unit
== STATS_UNIT_BYTES
) {
2122 if (unit
&& value
->base
== 10 &&
2123 value
->exponent
>= -18 && value
->exponent
<= 18 &&
2124 value
->exponent
% 3 == 0) {
2125 monitor_puts(mon
, si_prefix(value
->exponent
));
2126 } else if (unit
&& value
->base
== 2 &&
2127 value
->exponent
>= 0 && value
->exponent
<= 60 &&
2128 value
->exponent
% 10 == 0) {
2130 monitor_puts(mon
, iec_binary_prefix(value
->exponent
));
2131 } else if (value
->exponent
) {
2132 /* Use exponential notation and write the unit's English name */
2133 monitor_printf(mon
, "* %d^%d%s",
2134 value
->base
, value
->exponent
,
2135 value
->has_unit
? " " : "");
2139 if (value
->has_unit
) {
2140 monitor_puts(mon
, unit
? unit
: StatsUnit_str(value
->unit
));
2143 /* Print bucket size for linear histograms */
2144 if (value
->type
== STATS_TYPE_LINEAR_HISTOGRAM
&& value
->has_bucket_size
) {
2145 monitor_printf(mon
, ", bucket size=%d", value
->bucket_size
);
2147 monitor_printf(mon
, ")");
2150 static StatsSchemaValueList
*find_schema_value_list(
2151 StatsSchemaList
*list
, StatsProvider provider
,
2154 StatsSchemaList
*node
;
2156 for (node
= list
; node
; node
= node
->next
) {
2157 if (node
->value
->provider
== provider
&&
2158 node
->value
->target
== target
) {
2159 return node
->value
->stats
;
2165 static void print_stats_results(Monitor
*mon
, StatsTarget target
,
2167 StatsResult
*result
,
2168 StatsSchemaList
*schema
)
2170 /* Find provider schema */
2171 StatsSchemaValueList
*schema_value_list
=
2172 find_schema_value_list(schema
, result
->provider
, target
);
2173 StatsList
*stats_list
;
2175 if (!schema_value_list
) {
2176 monitor_printf(mon
, "failed to find schema list for %s\n",
2177 StatsProvider_str(result
->provider
));
2181 if (show_provider
) {
2182 monitor_printf(mon
, "provider: %s\n",
2183 StatsProvider_str(result
->provider
));
2186 for (stats_list
= result
->stats
; stats_list
;
2187 stats_list
= stats_list
->next
,
2188 schema_value_list
= schema_value_list
->next
) {
2190 Stats
*stats
= stats_list
->value
;
2191 StatsValue
*stats_value
= stats
->value
;
2192 StatsSchemaValue
*schema_value
= schema_value_list
->value
;
2194 /* Find schema entry */
2195 while (!g_str_equal(stats
->name
, schema_value
->name
)) {
2196 if (!schema_value_list
->next
) {
2197 monitor_printf(mon
, "failed to find schema entry for %s\n",
2201 schema_value_list
= schema_value_list
->next
;
2202 schema_value
= schema_value_list
->value
;
2205 print_stats_schema_value(mon
, schema_value
);
2207 if (stats_value
->type
== QTYPE_QNUM
) {
2208 monitor_printf(mon
, ": %" PRId64
"\n", stats_value
->u
.scalar
);
2209 } else if (stats_value
->type
== QTYPE_QBOOL
) {
2210 monitor_printf(mon
, ": %s\n", stats_value
->u
.boolean
? "yes" : "no");
2211 } else if (stats_value
->type
== QTYPE_QLIST
) {
2215 monitor_printf(mon
, ": ");
2216 for (list
= stats_value
->u
.list
, i
= 1;
2218 list
= list
->next
, i
++) {
2219 monitor_printf(mon
, "[%d]=%" PRId64
" ", i
, list
->value
);
2221 monitor_printf(mon
, "\n");
2226 /* Create the StatsFilter that is needed for an "info stats" invocation. */
2227 static StatsFilter
*stats_filter(StatsTarget target
, const char *names
,
2228 int cpu_index
, StatsProvider provider
)
2230 StatsFilter
*filter
= g_malloc0(sizeof(*filter
));
2231 StatsProvider provider_idx
;
2232 StatsRequestList
*request_list
= NULL
;
2234 filter
->target
= target
;
2236 case STATS_TARGET_VM
:
2238 case STATS_TARGET_VCPU
:
2240 strList
*vcpu_list
= NULL
;
2241 CPUState
*cpu
= qemu_get_cpu(cpu_index
);
2242 char *canonical_path
= object_get_canonical_path(OBJECT(cpu
));
2244 QAPI_LIST_PREPEND(vcpu_list
, canonical_path
);
2245 filter
->u
.vcpu
.has_vcpus
= true;
2246 filter
->u
.vcpu
.vcpus
= vcpu_list
;
2253 if (!names
&& provider
== STATS_PROVIDER__MAX
) {
2258 * "info stats" can only query either one or all the providers. Querying
2259 * by name, but not by provider, requires the creation of one filter per
2262 for (provider_idx
= 0; provider_idx
< STATS_PROVIDER__MAX
; provider_idx
++) {
2263 if (provider
== STATS_PROVIDER__MAX
|| provider
== provider_idx
) {
2264 StatsRequest
*request
= g_new0(StatsRequest
, 1);
2265 request
->provider
= provider_idx
;
2266 if (names
&& !g_str_equal(names
, "*")) {
2267 request
->has_names
= true;
2268 request
->names
= strList_from_comma_list(names
);
2270 QAPI_LIST_PREPEND(request_list
, request
);
2274 filter
->has_providers
= true;
2275 filter
->providers
= request_list
;
2279 void hmp_info_stats(Monitor
*mon
, const QDict
*qdict
)
2281 const char *target_str
= qdict_get_str(qdict
, "target");
2282 const char *provider_str
= qdict_get_try_str(qdict
, "provider");
2283 const char *names
= qdict_get_try_str(qdict
, "names");
2285 StatsProvider provider
= STATS_PROVIDER__MAX
;
2288 g_autoptr(StatsSchemaList
) schema
= NULL
;
2289 g_autoptr(StatsResultList
) stats
= NULL
;
2290 g_autoptr(StatsFilter
) filter
= NULL
;
2291 StatsResultList
*entry
;
2293 target
= qapi_enum_parse(&StatsTarget_lookup
, target_str
, -1, &err
);
2295 monitor_printf(mon
, "invalid stats target %s\n", target_str
);
2299 provider
= qapi_enum_parse(&StatsProvider_lookup
, provider_str
, -1, &err
);
2301 monitor_printf(mon
, "invalid stats provider %s\n", provider_str
);
2306 schema
= qmp_query_stats_schemas(provider_str
? true : false,
2313 case STATS_TARGET_VM
:
2314 filter
= stats_filter(target
, names
, -1, provider
);
2316 case STATS_TARGET_VCPU
: {}
2317 int cpu_index
= monitor_get_cpu_index(mon
);
2318 filter
= stats_filter(target
, names
, cpu_index
, provider
);
2324 stats
= qmp_query_stats(filter
, &err
);
2328 for (entry
= stats
; entry
; entry
= entry
->next
) {
2329 print_stats_results(mon
, target
, provider_str
== NULL
, entry
->value
, schema
);
2334 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
2340 static void hmp_virtio_dump_protocols(Monitor
*mon
,
2341 VhostDeviceProtocols
*pcol
)
2343 strList
*pcol_list
= pcol
->protocols
;
2345 monitor_printf(mon
, "\t%s", pcol_list
->value
);
2346 pcol_list
= pcol_list
->next
;
2347 if (pcol_list
!= NULL
) {
2348 monitor_printf(mon
, ",\n");
2351 monitor_printf(mon
, "\n");
2352 if (pcol
->has_unknown_protocols
) {
2353 monitor_printf(mon
, " unknown-protocols(0x%016"PRIx64
")\n",
2354 pcol
->unknown_protocols
);
2358 static void hmp_virtio_dump_status(Monitor
*mon
,
2359 VirtioDeviceStatus
*status
)
2361 strList
*status_list
= status
->statuses
;
2362 while (status_list
) {
2363 monitor_printf(mon
, "\t%s", status_list
->value
);
2364 status_list
= status_list
->next
;
2365 if (status_list
!= NULL
) {
2366 monitor_printf(mon
, ",\n");
2369 monitor_printf(mon
, "\n");
2370 if (status
->has_unknown_statuses
) {
2371 monitor_printf(mon
, " unknown-statuses(0x%016"PRIx32
")\n",
2372 status
->unknown_statuses
);
2376 static void hmp_virtio_dump_features(Monitor
*mon
,
2377 VirtioDeviceFeatures
*features
)
2379 strList
*transport_list
= features
->transports
;
2380 while (transport_list
) {
2381 monitor_printf(mon
, "\t%s", transport_list
->value
);
2382 transport_list
= transport_list
->next
;
2383 if (transport_list
!= NULL
) {
2384 monitor_printf(mon
, ",\n");
2388 monitor_printf(mon
, "\n");
2389 strList
*list
= features
->dev_features
;
2392 monitor_printf(mon
, "\t%s", list
->value
);
2395 monitor_printf(mon
, ",\n");
2398 monitor_printf(mon
, "\n");
2401 if (features
->has_unknown_dev_features
) {
2402 monitor_printf(mon
, " unknown-features(0x%016"PRIx64
")\n",
2403 features
->unknown_dev_features
);
2407 void hmp_virtio_query(Monitor
*mon
, const QDict
*qdict
)
2410 VirtioInfoList
*list
= qmp_x_query_virtio(&err
);
2411 VirtioInfoList
*node
;
2414 hmp_handle_error(mon
, err
);
2419 monitor_printf(mon
, "No VirtIO devices\n");
2425 monitor_printf(mon
, "%s [%s]\n", node
->value
->path
,
2429 qapi_free_VirtioInfoList(list
);
2432 void hmp_virtio_status(Monitor
*mon
, const QDict
*qdict
)
2435 const char *path
= qdict_get_try_str(qdict
, "path");
2436 VirtioStatus
*s
= qmp_x_query_virtio_status(path
, &err
);
2439 hmp_handle_error(mon
, err
);
2443 monitor_printf(mon
, "%s:\n", path
);
2444 monitor_printf(mon
, " device_name: %s %s\n",
2445 s
->name
, s
->vhost_dev
? "(vhost)" : "");
2446 monitor_printf(mon
, " device_id: %d\n", s
->device_id
);
2447 monitor_printf(mon
, " vhost_started: %s\n",
2448 s
->vhost_started
? "true" : "false");
2449 monitor_printf(mon
, " bus_name: %s\n", s
->bus_name
);
2450 monitor_printf(mon
, " broken: %s\n",
2451 s
->broken
? "true" : "false");
2452 monitor_printf(mon
, " disabled: %s\n",
2453 s
->disabled
? "true" : "false");
2454 monitor_printf(mon
, " disable_legacy_check: %s\n",
2455 s
->disable_legacy_check
? "true" : "false");
2456 monitor_printf(mon
, " started: %s\n",
2457 s
->started
? "true" : "false");
2458 monitor_printf(mon
, " use_started: %s\n",
2459 s
->use_started
? "true" : "false");
2460 monitor_printf(mon
, " start_on_kick: %s\n",
2461 s
->start_on_kick
? "true" : "false");
2462 monitor_printf(mon
, " use_guest_notifier_mask: %s\n",
2463 s
->use_guest_notifier_mask
? "true" : "false");
2464 monitor_printf(mon
, " vm_running: %s\n",
2465 s
->vm_running
? "true" : "false");
2466 monitor_printf(mon
, " num_vqs: %"PRId64
"\n", s
->num_vqs
);
2467 monitor_printf(mon
, " queue_sel: %d\n",
2469 monitor_printf(mon
, " isr: %d\n", s
->isr
);
2470 monitor_printf(mon
, " endianness: %s\n",
2472 monitor_printf(mon
, " status:\n");
2473 hmp_virtio_dump_status(mon
, s
->status
);
2474 monitor_printf(mon
, " Guest features:\n");
2475 hmp_virtio_dump_features(mon
, s
->guest_features
);
2476 monitor_printf(mon
, " Host features:\n");
2477 hmp_virtio_dump_features(mon
, s
->host_features
);
2478 monitor_printf(mon
, " Backend features:\n");
2479 hmp_virtio_dump_features(mon
, s
->backend_features
);
2482 monitor_printf(mon
, " VHost:\n");
2483 monitor_printf(mon
, " nvqs: %d\n",
2484 s
->vhost_dev
->nvqs
);
2485 monitor_printf(mon
, " vq_index: %"PRId64
"\n",
2486 s
->vhost_dev
->vq_index
);
2487 monitor_printf(mon
, " max_queues: %"PRId64
"\n",
2488 s
->vhost_dev
->max_queues
);
2489 monitor_printf(mon
, " n_mem_sections: %"PRId64
"\n",
2490 s
->vhost_dev
->n_mem_sections
);
2491 monitor_printf(mon
, " n_tmp_sections: %"PRId64
"\n",
2492 s
->vhost_dev
->n_tmp_sections
);
2493 monitor_printf(mon
, " backend_cap: %"PRId64
"\n",
2494 s
->vhost_dev
->backend_cap
);
2495 monitor_printf(mon
, " log_enabled: %s\n",
2496 s
->vhost_dev
->log_enabled
? "true" : "false");
2497 monitor_printf(mon
, " log_size: %"PRId64
"\n",
2498 s
->vhost_dev
->log_size
);
2499 monitor_printf(mon
, " Features:\n");
2500 hmp_virtio_dump_features(mon
, s
->vhost_dev
->features
);
2501 monitor_printf(mon
, " Acked features:\n");
2502 hmp_virtio_dump_features(mon
, s
->vhost_dev
->acked_features
);
2503 monitor_printf(mon
, " Backend features:\n");
2504 hmp_virtio_dump_features(mon
, s
->vhost_dev
->backend_features
);
2505 monitor_printf(mon
, " Protocol features:\n");
2506 hmp_virtio_dump_protocols(mon
, s
->vhost_dev
->protocol_features
);
2509 qapi_free_VirtioStatus(s
);
2512 void hmp_vhost_queue_status(Monitor
*mon
, const QDict
*qdict
)
2515 const char *path
= qdict_get_try_str(qdict
, "path");
2516 int queue
= qdict_get_int(qdict
, "queue");
2517 VirtVhostQueueStatus
*s
=
2518 qmp_x_query_virtio_vhost_queue_status(path
, queue
, &err
);
2521 hmp_handle_error(mon
, err
);
2525 monitor_printf(mon
, "%s:\n", path
);
2526 monitor_printf(mon
, " device_name: %s (vhost)\n",
2528 monitor_printf(mon
, " kick: %"PRId64
"\n", s
->kick
);
2529 monitor_printf(mon
, " call: %"PRId64
"\n", s
->call
);
2530 monitor_printf(mon
, " VRing:\n");
2531 monitor_printf(mon
, " num: %"PRId64
"\n", s
->num
);
2532 monitor_printf(mon
, " desc: 0x%016"PRIx64
"\n", s
->desc
);
2533 monitor_printf(mon
, " desc_phys: 0x%016"PRIx64
"\n",
2535 monitor_printf(mon
, " desc_size: %"PRId32
"\n", s
->desc_size
);
2536 monitor_printf(mon
, " avail: 0x%016"PRIx64
"\n", s
->avail
);
2537 monitor_printf(mon
, " avail_phys: 0x%016"PRIx64
"\n",
2539 monitor_printf(mon
, " avail_size: %"PRId32
"\n", s
->avail_size
);
2540 monitor_printf(mon
, " used: 0x%016"PRIx64
"\n", s
->used
);
2541 monitor_printf(mon
, " used_phys: 0x%016"PRIx64
"\n",
2543 monitor_printf(mon
, " used_size: %"PRId32
"\n", s
->used_size
);
2545 qapi_free_VirtVhostQueueStatus(s
);
2548 void hmp_virtio_queue_status(Monitor
*mon
, const QDict
*qdict
)
2551 const char *path
= qdict_get_try_str(qdict
, "path");
2552 int queue
= qdict_get_int(qdict
, "queue");
2553 VirtQueueStatus
*s
= qmp_x_query_virtio_queue_status(path
, queue
, &err
);
2556 hmp_handle_error(mon
, err
);
2560 monitor_printf(mon
, "%s:\n", path
);
2561 monitor_printf(mon
, " device_name: %s\n", s
->name
);
2562 monitor_printf(mon
, " queue_index: %d\n", s
->queue_index
);
2563 monitor_printf(mon
, " inuse: %d\n", s
->inuse
);
2564 monitor_printf(mon
, " used_idx: %d\n", s
->used_idx
);
2565 monitor_printf(mon
, " signalled_used: %d\n",
2567 monitor_printf(mon
, " signalled_used_valid: %s\n",
2568 s
->signalled_used_valid
? "true" : "false");
2569 if (s
->has_last_avail_idx
) {
2570 monitor_printf(mon
, " last_avail_idx: %d\n",
2573 if (s
->has_shadow_avail_idx
) {
2574 monitor_printf(mon
, " shadow_avail_idx: %d\n",
2575 s
->shadow_avail_idx
);
2577 monitor_printf(mon
, " VRing:\n");
2578 monitor_printf(mon
, " num: %"PRId32
"\n", s
->vring_num
);
2579 monitor_printf(mon
, " num_default: %"PRId32
"\n",
2580 s
->vring_num_default
);
2581 monitor_printf(mon
, " align: %"PRId32
"\n",
2583 monitor_printf(mon
, " desc: 0x%016"PRIx64
"\n",
2585 monitor_printf(mon
, " avail: 0x%016"PRIx64
"\n",
2587 monitor_printf(mon
, " used: 0x%016"PRIx64
"\n",
2590 qapi_free_VirtQueueStatus(s
);
2593 void hmp_virtio_queue_element(Monitor
*mon
, const QDict
*qdict
)
2596 const char *path
= qdict_get_try_str(qdict
, "path");
2597 int queue
= qdict_get_int(qdict
, "queue");
2598 int index
= qdict_get_try_int(qdict
, "index", -1);
2599 VirtioQueueElement
*e
;
2600 VirtioRingDescList
*list
;
2602 e
= qmp_x_query_virtio_queue_element(path
, queue
, index
!= -1,
2605 hmp_handle_error(mon
, err
);
2609 monitor_printf(mon
, "%s:\n", path
);
2610 monitor_printf(mon
, " device_name: %s\n", e
->name
);
2611 monitor_printf(mon
, " index: %d\n", e
->index
);
2612 monitor_printf(mon
, " desc:\n");
2613 monitor_printf(mon
, " descs:\n");
2617 monitor_printf(mon
, " addr 0x%"PRIx64
" len %d",
2618 list
->value
->addr
, list
->value
->len
);
2619 if (list
->value
->flags
) {
2620 strList
*flag
= list
->value
->flags
;
2621 monitor_printf(mon
, " (");
2623 monitor_printf(mon
, "%s", flag
->value
);
2626 monitor_printf(mon
, ", ");
2629 monitor_printf(mon
, ")");
2633 monitor_printf(mon
, ",\n");
2636 monitor_printf(mon
, "\n");
2637 monitor_printf(mon
, " avail:\n");
2638 monitor_printf(mon
, " flags: %d\n", e
->avail
->flags
);
2639 monitor_printf(mon
, " idx: %d\n", e
->avail
->idx
);
2640 monitor_printf(mon
, " ring: %d\n", e
->avail
->ring
);
2641 monitor_printf(mon
, " used:\n");
2642 monitor_printf(mon
, " flags: %d\n", e
->used
->flags
);
2643 monitor_printf(mon
, " idx: %d\n", e
->used
->idx
);
2645 qapi_free_VirtioQueueElement(e
);