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.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-virtio.h"
45 #include "qapi/qapi-visit-virtio.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 "qemu/cutils.h"
54 #include "qemu/error-report.h"
55 #include "hw/core/cpu.h"
56 #include "hw/intc/intc.h"
57 #include "migration/snapshot.h"
58 #include "migration/misc.h"
60 bool hmp_handle_error(Monitor
*mon
, Error
*err
)
63 error_reportf_err(err
, "Error: ");
70 * Produce a strList from a comma separated list.
71 * A NULL or empty input string return NULL.
73 static strList
*strList_from_comma_list(const char *in
)
76 strList
**tail
= &res
;
79 char *comma
= strchr(in
, ',');
83 value
= g_strndup(in
, comma
- in
);
84 in
= comma
+ 1; /* skip the , */
89 QAPI_LIST_APPEND(tail
, value
);
95 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
99 info
= qmp_query_name(NULL
);
101 monitor_printf(mon
, "%s\n", info
->name
);
103 qapi_free_NameInfo(info
);
106 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
110 info
= qmp_query_version(NULL
);
112 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
113 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
116 qapi_free_VersionInfo(info
);
119 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
123 info
= qmp_query_kvm(NULL
);
124 monitor_printf(mon
, "kvm support: ");
126 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
128 monitor_printf(mon
, "not compiled\n");
131 qapi_free_KvmInfo(info
);
134 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
138 info
= qmp_query_status(NULL
);
140 monitor_printf(mon
, "VM status: %s%s",
141 info
->running
? "running" : "paused",
142 info
->singlestep
? " (single step mode)" : "");
144 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
145 monitor_printf(mon
, " (%s)", RunState_str(info
->status
));
148 monitor_printf(mon
, "\n");
150 qapi_free_StatusInfo(info
);
153 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
157 info
= qmp_query_uuid(NULL
);
158 monitor_printf(mon
, "%s\n", info
->UUID
);
159 qapi_free_UuidInfo(info
);
162 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
164 ChardevInfoList
*char_info
, *info
;
166 char_info
= qmp_query_chardev(NULL
);
167 for (info
= char_info
; info
; info
= info
->next
) {
168 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
169 info
->value
->filename
);
172 qapi_free_ChardevInfoList(char_info
);
175 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
179 info
= qmp_query_migrate(NULL
);
181 migration_global_dump(mon
);
183 if (info
->blocked_reasons
) {
184 strList
*reasons
= info
->blocked_reasons
;
185 monitor_printf(mon
, "Outgoing migration blocked:\n");
187 monitor_printf(mon
, " %s\n", reasons
->value
);
188 reasons
= reasons
->next
;
192 if (info
->has_status
) {
193 monitor_printf(mon
, "Migration status: %s",
194 MigrationStatus_str(info
->status
));
195 if (info
->status
== MIGRATION_STATUS_FAILED
&& info
->error_desc
) {
196 monitor_printf(mon
, " (%s)\n", info
->error_desc
);
198 monitor_printf(mon
, "\n");
201 monitor_printf(mon
, "total time: %" PRIu64
" ms\n",
203 if (info
->has_expected_downtime
) {
204 monitor_printf(mon
, "expected downtime: %" PRIu64
" ms\n",
205 info
->expected_downtime
);
207 if (info
->has_downtime
) {
208 monitor_printf(mon
, "downtime: %" PRIu64
" ms\n",
211 if (info
->has_setup_time
) {
212 monitor_printf(mon
, "setup: %" PRIu64
" ms\n",
218 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
219 info
->ram
->transferred
>> 10);
220 monitor_printf(mon
, "throughput: %0.2f mbps\n",
222 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
223 info
->ram
->remaining
>> 10);
224 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
225 info
->ram
->total
>> 10);
226 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
227 info
->ram
->duplicate
);
228 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
230 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
232 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
233 info
->ram
->normal_bytes
>> 10);
234 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
235 info
->ram
->dirty_sync_count
);
236 monitor_printf(mon
, "page size: %" PRIu64
" kbytes\n",
237 info
->ram
->page_size
>> 10);
238 monitor_printf(mon
, "multifd bytes: %" PRIu64
" kbytes\n",
239 info
->ram
->multifd_bytes
>> 10);
240 monitor_printf(mon
, "pages-per-second: %" PRIu64
"\n",
241 info
->ram
->pages_per_second
);
243 if (info
->ram
->dirty_pages_rate
) {
244 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
245 info
->ram
->dirty_pages_rate
);
247 if (info
->ram
->postcopy_requests
) {
248 monitor_printf(mon
, "postcopy request count: %" PRIu64
"\n",
249 info
->ram
->postcopy_requests
);
251 if (info
->ram
->precopy_bytes
) {
252 monitor_printf(mon
, "precopy ram: %" PRIu64
" kbytes\n",
253 info
->ram
->precopy_bytes
>> 10);
255 if (info
->ram
->downtime_bytes
) {
256 monitor_printf(mon
, "downtime ram: %" PRIu64
" kbytes\n",
257 info
->ram
->downtime_bytes
>> 10);
259 if (info
->ram
->postcopy_bytes
) {
260 monitor_printf(mon
, "postcopy ram: %" PRIu64
" kbytes\n",
261 info
->ram
->postcopy_bytes
>> 10);
263 if (info
->ram
->dirty_sync_missed_zero_copy
) {
265 "Zero-copy-send fallbacks happened: %" PRIu64
" times\n",
266 info
->ram
->dirty_sync_missed_zero_copy
);
271 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
272 info
->disk
->transferred
>> 10);
273 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
274 info
->disk
->remaining
>> 10);
275 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
276 info
->disk
->total
>> 10);
279 if (info
->xbzrle_cache
) {
280 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
281 info
->xbzrle_cache
->cache_size
);
282 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
283 info
->xbzrle_cache
->bytes
>> 10);
284 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
285 info
->xbzrle_cache
->pages
);
286 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
" pages\n",
287 info
->xbzrle_cache
->cache_miss
);
288 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
289 info
->xbzrle_cache
->cache_miss_rate
);
290 monitor_printf(mon
, "xbzrle encoding rate: %0.2f\n",
291 info
->xbzrle_cache
->encoding_rate
);
292 monitor_printf(mon
, "xbzrle overflow: %" PRIu64
"\n",
293 info
->xbzrle_cache
->overflow
);
296 if (info
->compression
) {
297 monitor_printf(mon
, "compression pages: %" PRIu64
" pages\n",
298 info
->compression
->pages
);
299 monitor_printf(mon
, "compression busy: %" PRIu64
"\n",
300 info
->compression
->busy
);
301 monitor_printf(mon
, "compression busy rate: %0.2f\n",
302 info
->compression
->busy_rate
);
303 monitor_printf(mon
, "compressed size: %" PRIu64
" kbytes\n",
304 info
->compression
->compressed_size
>> 10);
305 monitor_printf(mon
, "compression rate: %0.2f\n",
306 info
->compression
->compression_rate
);
309 if (info
->has_cpu_throttle_percentage
) {
310 monitor_printf(mon
, "cpu throttle percentage: %" PRIu64
"\n",
311 info
->cpu_throttle_percentage
);
314 if (info
->has_postcopy_blocktime
) {
315 monitor_printf(mon
, "postcopy blocktime: %u\n",
316 info
->postcopy_blocktime
);
319 if (info
->has_postcopy_vcpu_blocktime
) {
322 v
= string_output_visitor_new(false, &str
);
323 visit_type_uint32List(v
, NULL
, &info
->postcopy_vcpu_blocktime
,
325 visit_complete(v
, &str
);
326 monitor_printf(mon
, "postcopy vcpu blocktime: %s\n", str
);
330 if (info
->has_socket_address
) {
331 SocketAddressList
*addr
;
333 monitor_printf(mon
, "socket address: [\n");
335 for (addr
= info
->socket_address
; addr
; addr
= addr
->next
) {
336 char *s
= socket_uri(addr
->value
);
337 monitor_printf(mon
, "\t%s\n", s
);
340 monitor_printf(mon
, "]\n");
344 monitor_printf(mon
, "vfio device transferred: %" PRIu64
" kbytes\n",
345 info
->vfio
->transferred
>> 10);
348 qapi_free_MigrationInfo(info
);
351 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
353 MigrationCapabilityStatusList
*caps
, *cap
;
355 caps
= qmp_query_migrate_capabilities(NULL
);
358 for (cap
= caps
; cap
; cap
= cap
->next
) {
359 monitor_printf(mon
, "%s: %s\n",
360 MigrationCapability_str(cap
->value
->capability
),
361 cap
->value
->state
? "on" : "off");
365 qapi_free_MigrationCapabilityStatusList(caps
);
368 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
370 MigrationParameters
*params
;
372 params
= qmp_query_migrate_parameters(NULL
);
375 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
376 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL
),
377 params
->announce_initial
);
378 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
379 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX
),
380 params
->announce_max
);
381 monitor_printf(mon
, "%s: %" PRIu64
"\n",
382 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS
),
383 params
->announce_rounds
);
384 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
385 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP
),
386 params
->announce_step
);
387 assert(params
->has_compress_level
);
388 monitor_printf(mon
, "%s: %u\n",
389 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL
),
390 params
->compress_level
);
391 assert(params
->has_compress_threads
);
392 monitor_printf(mon
, "%s: %u\n",
393 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS
),
394 params
->compress_threads
);
395 assert(params
->has_compress_wait_thread
);
396 monitor_printf(mon
, "%s: %s\n",
397 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD
),
398 params
->compress_wait_thread
? "on" : "off");
399 assert(params
->has_decompress_threads
);
400 monitor_printf(mon
, "%s: %u\n",
401 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS
),
402 params
->decompress_threads
);
403 assert(params
->has_throttle_trigger_threshold
);
404 monitor_printf(mon
, "%s: %u\n",
405 MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD
),
406 params
->throttle_trigger_threshold
);
407 assert(params
->has_cpu_throttle_initial
);
408 monitor_printf(mon
, "%s: %u\n",
409 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
),
410 params
->cpu_throttle_initial
);
411 assert(params
->has_cpu_throttle_increment
);
412 monitor_printf(mon
, "%s: %u\n",
413 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
),
414 params
->cpu_throttle_increment
);
415 assert(params
->has_cpu_throttle_tailslow
);
416 monitor_printf(mon
, "%s: %s\n",
417 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW
),
418 params
->cpu_throttle_tailslow
? "on" : "off");
419 assert(params
->has_max_cpu_throttle
);
420 monitor_printf(mon
, "%s: %u\n",
421 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE
),
422 params
->max_cpu_throttle
);
423 assert(params
->tls_creds
);
424 monitor_printf(mon
, "%s: '%s'\n",
425 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS
),
427 assert(params
->tls_hostname
);
428 monitor_printf(mon
, "%s: '%s'\n",
429 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME
),
430 params
->tls_hostname
);
431 assert(params
->has_max_bandwidth
);
432 monitor_printf(mon
, "%s: %" PRIu64
" bytes/second\n",
433 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH
),
434 params
->max_bandwidth
);
435 assert(params
->has_downtime_limit
);
436 monitor_printf(mon
, "%s: %" PRIu64
" ms\n",
437 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT
),
438 params
->downtime_limit
);
439 assert(params
->has_x_checkpoint_delay
);
440 monitor_printf(mon
, "%s: %u ms\n",
441 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
),
442 params
->x_checkpoint_delay
);
443 assert(params
->has_block_incremental
);
444 monitor_printf(mon
, "%s: %s\n",
445 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL
),
446 params
->block_incremental
? "on" : "off");
447 monitor_printf(mon
, "%s: %u\n",
448 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS
),
449 params
->multifd_channels
);
450 monitor_printf(mon
, "%s: %s\n",
451 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION
),
452 MultiFDCompression_str(params
->multifd_compression
));
453 monitor_printf(mon
, "%s: %" PRIu64
" bytes\n",
454 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
),
455 params
->xbzrle_cache_size
);
456 monitor_printf(mon
, "%s: %" PRIu64
"\n",
457 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH
),
458 params
->max_postcopy_bandwidth
);
459 monitor_printf(mon
, "%s: '%s'\n",
460 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ
),
463 if (params
->has_block_bitmap_mapping
) {
464 const BitmapMigrationNodeAliasList
*bmnal
;
466 monitor_printf(mon
, "%s:\n",
467 MigrationParameter_str(
468 MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING
));
470 for (bmnal
= params
->block_bitmap_mapping
;
474 const BitmapMigrationNodeAlias
*bmna
= bmnal
->value
;
475 const BitmapMigrationBitmapAliasList
*bmbal
;
477 monitor_printf(mon
, " '%s' -> '%s'\n",
478 bmna
->node_name
, bmna
->alias
);
480 for (bmbal
= bmna
->bitmaps
; bmbal
; bmbal
= bmbal
->next
) {
481 const BitmapMigrationBitmapAlias
*bmba
= bmbal
->value
;
483 monitor_printf(mon
, " '%s' -> '%s'\n",
484 bmba
->name
, bmba
->alias
);
490 qapi_free_MigrationParameters(params
);
493 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
498 info
= qmp_query_balloon(&err
);
499 if (hmp_handle_error(mon
, err
)) {
503 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
505 qapi_free_BalloonInfo(info
);
508 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
510 InterruptStatsProvider
*intc
;
511 InterruptStatsProviderClass
*k
;
512 Monitor
*mon
= opaque
;
514 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
515 intc
= INTERRUPT_STATS_PROVIDER(obj
);
516 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
518 k
->print_info(intc
, mon
);
520 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
521 object_get_typename(obj
));
528 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
530 object_child_foreach_recursive(object_get_root(),
531 hmp_info_pic_foreach
, mon
);
534 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
537 TPMInfoList
*info_list
, *info
;
540 TPMPassthroughOptions
*tpo
;
541 TPMEmulatorOptions
*teo
;
543 info_list
= qmp_query_tpm(&err
);
545 monitor_printf(mon
, "TPM device not supported\n");
551 monitor_printf(mon
, "TPM device:\n");
554 for (info
= info_list
; info
; info
= info
->next
) {
555 TPMInfo
*ti
= info
->value
;
556 monitor_printf(mon
, " tpm%d: model=%s\n",
557 c
, TpmModel_str(ti
->model
));
559 monitor_printf(mon
, " \\ %s: type=%s",
560 ti
->id
, TpmType_str(ti
->options
->type
));
562 switch (ti
->options
->type
) {
563 case TPM_TYPE_PASSTHROUGH
:
564 tpo
= ti
->options
->u
.passthrough
.data
;
565 monitor_printf(mon
, "%s%s%s%s",
566 tpo
->path
? ",path=" : "",
568 tpo
->cancel_path
? ",cancel-path=" : "",
569 tpo
->cancel_path
?: "");
571 case TPM_TYPE_EMULATOR
:
572 teo
= ti
->options
->u
.emulator
.data
;
573 monitor_printf(mon
, ",chardev=%s", teo
->chardev
);
578 monitor_printf(mon
, "\n");
581 qapi_free_TPMInfoList(info_list
);
583 monitor_printf(mon
, "TPM device not supported\n");
584 #endif /* CONFIG_TPM */
587 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
589 monitor_suspend(mon
);
593 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
598 void hmp_sync_profile(Monitor
*mon
, const QDict
*qdict
)
600 const char *op
= qdict_get_try_str(qdict
, "op");
603 bool on
= qsp_is_enabled();
605 monitor_printf(mon
, "sync-profile is %s\n", on
? "on" : "off");
608 if (!strcmp(op
, "on")) {
610 } else if (!strcmp(op
, "off")) {
612 } else if (!strcmp(op
, "reset")) {
617 error_setg(&err
, QERR_INVALID_PARAMETER
, op
);
618 hmp_handle_error(mon
, err
);
622 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
624 qmp_system_reset(NULL
);
627 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
629 qmp_system_powerdown(NULL
);
632 void hmp_exit_preconfig(Monitor
*mon
, const QDict
*qdict
)
636 qmp_x_exit_preconfig(&err
);
637 hmp_handle_error(mon
, err
);
640 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
644 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
645 use it are converted to the QAPI */
646 cpu_index
= qdict_get_int(qdict
, "index");
647 if (monitor_set_cpu(mon
, cpu_index
) < 0) {
648 monitor_printf(mon
, "invalid CPU index\n");
652 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
654 uint32_t size
= qdict_get_int(qdict
, "size");
655 const char *filename
= qdict_get_str(qdict
, "filename");
656 uint64_t addr
= qdict_get_int(qdict
, "val");
658 int cpu_index
= monitor_get_cpu_index(mon
);
661 monitor_printf(mon
, "No CPU available\n");
665 qmp_memsave(addr
, size
, filename
, true, cpu_index
, &err
);
666 hmp_handle_error(mon
, err
);
669 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
671 uint32_t size
= qdict_get_int(qdict
, "size");
672 const char *filename
= qdict_get_str(qdict
, "filename");
673 uint64_t addr
= qdict_get_int(qdict
, "val");
676 qmp_pmemsave(addr
, size
, filename
, &err
);
677 hmp_handle_error(mon
, err
);
680 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
682 const char *chardev
= qdict_get_str(qdict
, "device");
683 const char *data
= qdict_get_str(qdict
, "data");
686 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
688 hmp_handle_error(mon
, err
);
691 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
693 uint32_t size
= qdict_get_int(qdict
, "size");
694 const char *chardev
= qdict_get_str(qdict
, "device");
699 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
700 if (hmp_handle_error(mon
, err
)) {
704 for (i
= 0; data
[i
]; i
++) {
705 unsigned char ch
= data
[i
];
708 monitor_printf(mon
, "\\\\");
709 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
710 monitor_printf(mon
, "\\u%04X", ch
);
712 monitor_printf(mon
, "%c", ch
);
716 monitor_printf(mon
, "\n");
720 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
725 hmp_handle_error(mon
, err
);
728 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
732 qmp_system_wakeup(&err
);
733 hmp_handle_error(mon
, err
);
736 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
740 qmp_inject_nmi(&err
);
741 hmp_handle_error(mon
, err
);
744 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
746 const char *name
= qdict_get_str(qdict
, "name");
747 bool up
= qdict_get_bool(qdict
, "up");
750 qmp_set_link(name
, up
, &err
);
751 hmp_handle_error(mon
, err
);
754 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
756 int64_t value
= qdict_get_int(qdict
, "value");
759 qmp_balloon(value
, &err
);
760 hmp_handle_error(mon
, err
);
763 void hmp_loadvm(Monitor
*mon
, const QDict
*qdict
)
765 int saved_vm_running
= runstate_is_running();
766 const char *name
= qdict_get_str(qdict
, "name");
769 vm_stop(RUN_STATE_RESTORE_VM
);
771 if (load_snapshot(name
, NULL
, false, NULL
, &err
) && saved_vm_running
) {
774 hmp_handle_error(mon
, err
);
777 void hmp_savevm(Monitor
*mon
, const QDict
*qdict
)
781 save_snapshot(qdict_get_try_str(qdict
, "name"),
782 true, NULL
, false, NULL
, &err
);
783 hmp_handle_error(mon
, err
);
786 void hmp_delvm(Monitor
*mon
, const QDict
*qdict
)
789 const char *name
= qdict_get_str(qdict
, "name");
791 delete_snapshot(name
, false, NULL
, &err
);
792 hmp_handle_error(mon
, err
);
795 void hmp_announce_self(Monitor
*mon
, const QDict
*qdict
)
797 const char *interfaces_str
= qdict_get_try_str(qdict
, "interfaces");
798 const char *id
= qdict_get_try_str(qdict
, "id");
799 AnnounceParameters
*params
= QAPI_CLONE(AnnounceParameters
,
800 migrate_announce_params());
802 qapi_free_strList(params
->interfaces
);
803 params
->interfaces
= strList_from_comma_list(interfaces_str
);
804 params
->has_interfaces
= params
->interfaces
!= NULL
;
805 params
->id
= g_strdup(id
);
806 qmp_announce_self(params
, NULL
);
807 qapi_free_AnnounceParameters(params
);
810 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
812 qmp_migrate_cancel(NULL
);
815 void hmp_migrate_continue(Monitor
*mon
, const QDict
*qdict
)
818 const char *state
= qdict_get_str(qdict
, "state");
819 int val
= qapi_enum_parse(&MigrationStatus_lookup
, state
, -1, &err
);
822 qmp_migrate_continue(val
, &err
);
825 hmp_handle_error(mon
, err
);
828 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
831 const char *uri
= qdict_get_str(qdict
, "uri");
833 qmp_migrate_incoming(uri
, &err
);
835 hmp_handle_error(mon
, err
);
838 void hmp_migrate_recover(Monitor
*mon
, const QDict
*qdict
)
841 const char *uri
= qdict_get_str(qdict
, "uri");
843 qmp_migrate_recover(uri
, &err
);
845 hmp_handle_error(mon
, err
);
848 void hmp_migrate_pause(Monitor
*mon
, const QDict
*qdict
)
852 qmp_migrate_pause(&err
);
854 hmp_handle_error(mon
, err
);
858 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
860 const char *cap
= qdict_get_str(qdict
, "capability");
861 bool state
= qdict_get_bool(qdict
, "state");
863 MigrationCapabilityStatusList
*caps
= NULL
;
864 MigrationCapabilityStatus
*value
;
867 val
= qapi_enum_parse(&MigrationCapability_lookup
, cap
, -1, &err
);
872 value
= g_malloc0(sizeof(*value
));
873 value
->capability
= val
;
874 value
->state
= state
;
875 QAPI_LIST_PREPEND(caps
, value
);
876 qmp_migrate_set_capabilities(caps
, &err
);
877 qapi_free_MigrationCapabilityStatusList(caps
);
880 hmp_handle_error(mon
, err
);
883 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
885 const char *param
= qdict_get_str(qdict
, "parameter");
886 const char *valuestr
= qdict_get_str(qdict
, "value");
887 Visitor
*v
= string_input_visitor_new(valuestr
);
888 MigrateSetParameters
*p
= g_new0(MigrateSetParameters
, 1);
889 uint64_t valuebw
= 0;
894 val
= qapi_enum_parse(&MigrationParameter_lookup
, param
, -1, &err
);
900 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
901 p
->has_compress_level
= true;
902 visit_type_uint8(v
, param
, &p
->compress_level
, &err
);
904 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
905 p
->has_compress_threads
= true;
906 visit_type_uint8(v
, param
, &p
->compress_threads
, &err
);
908 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD
:
909 p
->has_compress_wait_thread
= true;
910 visit_type_bool(v
, param
, &p
->compress_wait_thread
, &err
);
912 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
913 p
->has_decompress_threads
= true;
914 visit_type_uint8(v
, param
, &p
->decompress_threads
, &err
);
916 case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD
:
917 p
->has_throttle_trigger_threshold
= true;
918 visit_type_uint8(v
, param
, &p
->throttle_trigger_threshold
, &err
);
920 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
921 p
->has_cpu_throttle_initial
= true;
922 visit_type_uint8(v
, param
, &p
->cpu_throttle_initial
, &err
);
924 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
925 p
->has_cpu_throttle_increment
= true;
926 visit_type_uint8(v
, param
, &p
->cpu_throttle_increment
, &err
);
928 case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW
:
929 p
->has_cpu_throttle_tailslow
= true;
930 visit_type_bool(v
, param
, &p
->cpu_throttle_tailslow
, &err
);
932 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE
:
933 p
->has_max_cpu_throttle
= true;
934 visit_type_uint8(v
, param
, &p
->max_cpu_throttle
, &err
);
936 case MIGRATION_PARAMETER_TLS_CREDS
:
937 p
->tls_creds
= g_new0(StrOrNull
, 1);
938 p
->tls_creds
->type
= QTYPE_QSTRING
;
939 visit_type_str(v
, param
, &p
->tls_creds
->u
.s
, &err
);
941 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
942 p
->tls_hostname
= g_new0(StrOrNull
, 1);
943 p
->tls_hostname
->type
= QTYPE_QSTRING
;
944 visit_type_str(v
, param
, &p
->tls_hostname
->u
.s
, &err
);
946 case MIGRATION_PARAMETER_TLS_AUTHZ
:
947 p
->tls_authz
= g_new0(StrOrNull
, 1);
948 p
->tls_authz
->type
= QTYPE_QSTRING
;
949 visit_type_str(v
, param
, &p
->tls_authz
->u
.s
, &err
);
951 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
952 p
->has_max_bandwidth
= true;
954 * Can't use visit_type_size() here, because it
955 * defaults to Bytes rather than Mebibytes.
957 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
958 if (ret
< 0 || valuebw
> INT64_MAX
959 || (size_t)valuebw
!= valuebw
) {
960 error_setg(&err
, "Invalid size %s", valuestr
);
963 p
->max_bandwidth
= valuebw
;
965 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
966 p
->has_downtime_limit
= true;
967 visit_type_size(v
, param
, &p
->downtime_limit
, &err
);
969 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
970 p
->has_x_checkpoint_delay
= true;
971 visit_type_uint32(v
, param
, &p
->x_checkpoint_delay
, &err
);
973 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL
:
974 p
->has_block_incremental
= true;
975 visit_type_bool(v
, param
, &p
->block_incremental
, &err
);
977 case MIGRATION_PARAMETER_MULTIFD_CHANNELS
:
978 p
->has_multifd_channels
= true;
979 visit_type_uint8(v
, param
, &p
->multifd_channels
, &err
);
981 case MIGRATION_PARAMETER_MULTIFD_COMPRESSION
:
982 p
->has_multifd_compression
= true;
983 visit_type_MultiFDCompression(v
, param
, &p
->multifd_compression
,
986 case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL
:
987 p
->has_multifd_zlib_level
= true;
988 visit_type_uint8(v
, param
, &p
->multifd_zlib_level
, &err
);
990 case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL
:
991 p
->has_multifd_zstd_level
= true;
992 visit_type_uint8(v
, param
, &p
->multifd_zstd_level
, &err
);
994 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE
:
995 p
->has_xbzrle_cache_size
= true;
996 if (!visit_type_size(v
, param
, &cache_size
, &err
)) {
999 if (cache_size
> INT64_MAX
|| (size_t)cache_size
!= cache_size
) {
1000 error_setg(&err
, "Invalid size %s", valuestr
);
1003 p
->xbzrle_cache_size
= cache_size
;
1005 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH
:
1006 p
->has_max_postcopy_bandwidth
= true;
1007 visit_type_size(v
, param
, &p
->max_postcopy_bandwidth
, &err
);
1009 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL
:
1010 p
->has_announce_initial
= true;
1011 visit_type_size(v
, param
, &p
->announce_initial
, &err
);
1013 case MIGRATION_PARAMETER_ANNOUNCE_MAX
:
1014 p
->has_announce_max
= true;
1015 visit_type_size(v
, param
, &p
->announce_max
, &err
);
1017 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS
:
1018 p
->has_announce_rounds
= true;
1019 visit_type_size(v
, param
, &p
->announce_rounds
, &err
);
1021 case MIGRATION_PARAMETER_ANNOUNCE_STEP
:
1022 p
->has_announce_step
= true;
1023 visit_type_size(v
, param
, &p
->announce_step
, &err
);
1025 case MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING
:
1026 error_setg(&err
, "The block-bitmap-mapping parameter can only be set "
1037 qmp_migrate_set_parameters(p
, &err
);
1040 qapi_free_MigrateSetParameters(p
);
1042 hmp_handle_error(mon
, err
);
1045 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1048 const char *protocol
= qdict_get_str(qdict
, "protocol");
1049 const char *hostname
= qdict_get_str(qdict
, "hostname");
1050 bool has_port
= qdict_haskey(qdict
, "port");
1051 int port
= qdict_get_try_int(qdict
, "port", -1);
1052 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1053 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1054 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1056 qmp_client_migrate_info(protocol
, hostname
,
1057 has_port
, port
, has_tls_port
, tls_port
,
1058 cert_subject
, &err
);
1059 hmp_handle_error(mon
, err
);
1062 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1065 qmp_migrate_start_postcopy(&err
);
1066 hmp_handle_error(mon
, err
);
1069 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1073 qmp_x_colo_lost_heartbeat(&err
);
1074 hmp_handle_error(mon
, err
);
1077 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1079 const char *device
= qdict_get_str(qdict
, "device");
1080 const char *target
= qdict_get_str(qdict
, "target");
1081 const char *arg
= qdict_get_try_str(qdict
, "arg");
1082 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1083 bool force
= qdict_get_try_bool(qdict
, "force", false);
1084 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1088 if (strcmp(device
, "vnc") == 0) {
1089 hmp_change_vnc(mon
, device
, target
, arg
, read_only
, force
, &err
);
1095 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup
,
1097 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1103 qmp_blockdev_change_medium(device
, NULL
, target
, arg
, true, force
,
1104 !!read_only
, read_only_mode
,
1109 hmp_handle_error(mon
, err
);
1112 typedef struct HMPMigrationStatus
{
1115 bool is_block_migration
;
1116 } HMPMigrationStatus
;
1118 static void hmp_migrate_status_cb(void *opaque
)
1120 HMPMigrationStatus
*status
= opaque
;
1121 MigrationInfo
*info
;
1123 info
= qmp_query_migrate(NULL
);
1124 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1125 info
->status
== MIGRATION_STATUS_SETUP
) {
1129 if (info
->disk
->remaining
) {
1130 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1135 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1136 monitor_flush(status
->mon
);
1139 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1141 if (status
->is_block_migration
) {
1142 monitor_printf(status
->mon
, "\n");
1144 if (info
->error_desc
) {
1145 error_report("%s", info
->error_desc
);
1147 monitor_resume(status
->mon
);
1148 timer_free(status
->timer
);
1152 qapi_free_MigrationInfo(info
);
1155 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1157 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1158 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1159 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1160 bool resume
= qdict_get_try_bool(qdict
, "resume", false);
1161 const char *uri
= qdict_get_str(qdict
, "uri");
1164 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
,
1165 false, false, true, resume
, &err
);
1166 if (hmp_handle_error(mon
, err
)) {
1171 HMPMigrationStatus
*status
;
1173 if (monitor_suspend(mon
) < 0) {
1174 monitor_printf(mon
, "terminal does not allow synchronous "
1175 "migration, continuing detached\n");
1179 status
= g_malloc0(sizeof(*status
));
1181 status
->is_block_migration
= blk
|| inc
;
1182 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1184 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1188 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1192 const char *type
= qdict_get_try_str(qdict
, "type");
1194 if (type
&& is_help_option(type
)) {
1198 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1203 netdev_add(opts
, &err
);
1205 qemu_opts_del(opts
);
1209 hmp_handle_error(mon
, err
);
1212 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1214 const char *id
= qdict_get_str(qdict
, "id");
1217 qmp_netdev_del(id
, &err
);
1218 hmp_handle_error(mon
, err
);
1221 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
1223 const char *options
= qdict_get_str(qdict
, "object");
1226 user_creatable_add_from_str(options
, &err
);
1227 hmp_handle_error(mon
, err
);
1230 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1232 const char *fdname
= qdict_get_str(qdict
, "fdname");
1235 qmp_getfd(fdname
, &err
);
1236 hmp_handle_error(mon
, err
);
1239 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1241 const char *fdname
= qdict_get_str(qdict
, "fdname");
1244 qmp_closefd(fdname
, &err
);
1245 hmp_handle_error(mon
, err
);
1248 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
1250 const char *args
= qdict_get_str(qdict
, "args");
1254 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
1256 error_setg(&err
, "Parsing chardev args failed");
1258 qemu_chr_new_from_opts(opts
, NULL
, &err
);
1259 qemu_opts_del(opts
);
1261 hmp_handle_error(mon
, err
);
1264 void hmp_chardev_change(Monitor
*mon
, const QDict
*qdict
)
1266 const char *args
= qdict_get_str(qdict
, "args");
1269 ChardevBackend
*backend
= NULL
;
1270 ChardevReturn
*ret
= NULL
;
1271 QemuOpts
*opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
,
1274 error_setg(&err
, "Parsing chardev args failed");
1278 id
= qdict_get_str(qdict
, "id");
1279 if (qemu_opts_id(opts
)) {
1280 error_setg(&err
, "Unexpected 'id' parameter");
1284 backend
= qemu_chr_parse_opts(opts
, &err
);
1289 ret
= qmp_chardev_change(id
, backend
, &err
);
1292 qapi_free_ChardevReturn(ret
);
1293 qapi_free_ChardevBackend(backend
);
1294 qemu_opts_del(opts
);
1295 hmp_handle_error(mon
, err
);
1298 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
1300 Error
*local_err
= NULL
;
1302 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
1303 hmp_handle_error(mon
, local_err
);
1306 void hmp_chardev_send_break(Monitor
*mon
, const QDict
*qdict
)
1308 Error
*local_err
= NULL
;
1310 qmp_chardev_send_break(qdict_get_str(qdict
, "id"), &local_err
);
1311 hmp_handle_error(mon
, local_err
);
1314 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
1316 const char *id
= qdict_get_str(qdict
, "id");
1319 user_creatable_del(id
, &err
);
1320 hmp_handle_error(mon
, err
);
1323 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
1326 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
1327 MemoryDeviceInfoList
*info
;
1328 VirtioPMEMDeviceInfo
*vpi
;
1329 VirtioMEMDeviceInfo
*vmi
;
1330 MemoryDeviceInfo
*value
;
1331 PCDIMMDeviceInfo
*di
;
1332 SgxEPCDeviceInfo
*se
;
1334 for (info
= info_list
; info
; info
= info
->next
) {
1335 value
= info
->value
;
1338 switch (value
->type
) {
1339 case MEMORY_DEVICE_INFO_KIND_DIMM
:
1340 case MEMORY_DEVICE_INFO_KIND_NVDIMM
:
1341 di
= value
->type
== MEMORY_DEVICE_INFO_KIND_DIMM
?
1342 value
->u
.dimm
.data
: value
->u
.nvdimm
.data
;
1343 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1344 MemoryDeviceInfoKind_str(value
->type
),
1345 di
->id
? di
->id
: "");
1346 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
1347 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
1348 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
1349 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
1350 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
1351 monitor_printf(mon
, " hotplugged: %s\n",
1352 di
->hotplugged
? "true" : "false");
1353 monitor_printf(mon
, " hotpluggable: %s\n",
1354 di
->hotpluggable
? "true" : "false");
1356 case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM
:
1357 vpi
= value
->u
.virtio_pmem
.data
;
1358 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1359 MemoryDeviceInfoKind_str(value
->type
),
1360 vpi
->id
? vpi
->id
: "");
1361 monitor_printf(mon
, " memaddr: 0x%" PRIx64
"\n", vpi
->memaddr
);
1362 monitor_printf(mon
, " size: %" PRIu64
"\n", vpi
->size
);
1363 monitor_printf(mon
, " memdev: %s\n", vpi
->memdev
);
1365 case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM
:
1366 vmi
= value
->u
.virtio_mem
.data
;
1367 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1368 MemoryDeviceInfoKind_str(value
->type
),
1369 vmi
->id
? vmi
->id
: "");
1370 monitor_printf(mon
, " memaddr: 0x%" PRIx64
"\n", vmi
->memaddr
);
1371 monitor_printf(mon
, " node: %" PRId64
"\n", vmi
->node
);
1372 monitor_printf(mon
, " requested-size: %" PRIu64
"\n",
1373 vmi
->requested_size
);
1374 monitor_printf(mon
, " size: %" PRIu64
"\n", vmi
->size
);
1375 monitor_printf(mon
, " max-size: %" PRIu64
"\n", vmi
->max_size
);
1376 monitor_printf(mon
, " block-size: %" PRIu64
"\n",
1378 monitor_printf(mon
, " memdev: %s\n", vmi
->memdev
);
1380 case MEMORY_DEVICE_INFO_KIND_SGX_EPC
:
1381 se
= value
->u
.sgx_epc
.data
;
1382 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1383 MemoryDeviceInfoKind_str(value
->type
),
1384 se
->id
? se
->id
: "");
1385 monitor_printf(mon
, " memaddr: 0x%" PRIx64
"\n", se
->memaddr
);
1386 monitor_printf(mon
, " size: %" PRIu64
"\n", se
->size
);
1387 monitor_printf(mon
, " node: %" PRId64
"\n", se
->node
);
1388 monitor_printf(mon
, " memdev: %s\n", se
->memdev
);
1391 g_assert_not_reached();
1396 qapi_free_MemoryDeviceInfoList(info_list
);
1397 hmp_handle_error(mon
, err
);
1400 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
1402 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
1403 IOThreadInfoList
*info
;
1404 IOThreadInfo
*value
;
1406 for (info
= info_list
; info
; info
= info
->next
) {
1407 value
= info
->value
;
1408 monitor_printf(mon
, "%s:\n", value
->id
);
1409 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
1410 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
1411 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
1412 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
1413 monitor_printf(mon
, " aio-max-batch=%" PRId64
"\n",
1414 value
->aio_max_batch
);
1417 qapi_free_IOThreadInfoList(info_list
);
1420 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
1422 const char *name
= qdict_get_str(qdict
, "name");
1423 RockerSwitch
*rocker
;
1426 rocker
= qmp_query_rocker(name
, &err
);
1427 if (hmp_handle_error(mon
, err
)) {
1431 monitor_printf(mon
, "name: %s\n", rocker
->name
);
1432 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
1433 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
1435 qapi_free_RockerSwitch(rocker
);
1438 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
1440 RockerPortList
*list
, *port
;
1441 const char *name
= qdict_get_str(qdict
, "name");
1444 list
= qmp_query_rocker_ports(name
, &err
);
1445 if (hmp_handle_error(mon
, err
)) {
1449 monitor_printf(mon
, " ena/ speed/ auto\n");
1450 monitor_printf(mon
, " port link duplex neg?\n");
1452 for (port
= list
; port
; port
= port
->next
) {
1453 monitor_printf(mon
, "%10s %-4s %-3s %2s %s\n",
1455 port
->value
->enabled
? port
->value
->link_up
?
1456 "up" : "down" : "!ena",
1457 port
->value
->speed
== 10000 ? "10G" : "??",
1458 port
->value
->duplex
? "FD" : "HD",
1459 port
->value
->autoneg
? "Yes" : "No");
1462 qapi_free_RockerPortList(list
);
1465 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
1467 RockerOfDpaFlowList
*list
, *info
;
1468 const char *name
= qdict_get_str(qdict
, "name");
1469 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
1472 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
1473 if (hmp_handle_error(mon
, err
)) {
1477 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
1479 for (info
= list
; info
; info
= info
->next
) {
1480 RockerOfDpaFlow
*flow
= info
->value
;
1481 RockerOfDpaFlowKey
*key
= flow
->key
;
1482 RockerOfDpaFlowMask
*mask
= flow
->mask
;
1483 RockerOfDpaFlowAction
*action
= flow
->action
;
1486 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
1487 key
->priority
, key
->tbl_id
, flow
->hits
);
1489 monitor_printf(mon
, "%-4d %-3d ",
1490 key
->priority
, key
->tbl_id
);
1493 if (key
->has_in_pport
) {
1494 monitor_printf(mon
, " pport %d", key
->in_pport
);
1495 if (mask
->has_in_pport
) {
1496 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
1500 if (key
->has_vlan_id
) {
1501 monitor_printf(mon
, " vlan %d",
1502 key
->vlan_id
& VLAN_VID_MASK
);
1503 if (mask
->has_vlan_id
) {
1504 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
1508 if (key
->has_tunnel_id
) {
1509 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
1510 if (mask
->has_tunnel_id
) {
1511 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
1515 if (key
->has_eth_type
) {
1516 switch (key
->eth_type
) {
1518 monitor_printf(mon
, " ARP");
1521 monitor_printf(mon
, " IP");
1524 monitor_printf(mon
, " IPv6");
1527 monitor_printf(mon
, " LACP");
1530 monitor_printf(mon
, " LLDP");
1533 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
1539 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
1541 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
1542 monitor_printf(mon
, " src <any mcast/bcast>");
1543 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
1545 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
1546 monitor_printf(mon
, " src <any ucast>");
1548 monitor_printf(mon
, " src %s", key
->eth_src
);
1549 if (mask
->eth_src
) {
1550 monitor_printf(mon
, "(%s)", mask
->eth_src
);
1556 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
1558 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
1559 monitor_printf(mon
, " dst <any mcast/bcast>");
1560 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
1562 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
1563 monitor_printf(mon
, " dst <any ucast>");
1565 monitor_printf(mon
, " dst %s", key
->eth_dst
);
1566 if (mask
->eth_dst
) {
1567 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
1572 if (key
->has_ip_proto
) {
1573 monitor_printf(mon
, " proto %d", key
->ip_proto
);
1574 if (mask
->has_ip_proto
) {
1575 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
1579 if (key
->has_ip_tos
) {
1580 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
1581 if (mask
->has_ip_tos
) {
1582 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
1587 monitor_printf(mon
, " dst %s", key
->ip_dst
);
1590 if (action
->has_goto_tbl
|| action
->has_group_id
||
1591 action
->has_new_vlan_id
) {
1592 monitor_printf(mon
, " -->");
1595 if (action
->has_new_vlan_id
) {
1596 monitor_printf(mon
, " apply new vlan %d",
1597 ntohs(action
->new_vlan_id
));
1600 if (action
->has_group_id
) {
1601 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
1604 if (action
->has_goto_tbl
) {
1605 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
1608 monitor_printf(mon
, "\n");
1611 qapi_free_RockerOfDpaFlowList(list
);
1614 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
1616 RockerOfDpaGroupList
*list
, *g
;
1617 const char *name
= qdict_get_str(qdict
, "name");
1618 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
1621 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
1622 if (hmp_handle_error(mon
, err
)) {
1626 monitor_printf(mon
, "id (decode) --> buckets\n");
1628 for (g
= list
; g
; g
= g
->next
) {
1629 RockerOfDpaGroup
*group
= g
->value
;
1632 monitor_printf(mon
, "0x%08x", group
->id
);
1634 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
1635 group
->type
== 1 ? "L2 rewrite" :
1636 group
->type
== 2 ? "L3 unicast" :
1637 group
->type
== 3 ? "L2 multicast" :
1638 group
->type
== 4 ? "L2 flood" :
1639 group
->type
== 5 ? "L3 interface" :
1640 group
->type
== 6 ? "L3 multicast" :
1641 group
->type
== 7 ? "L3 ECMP" :
1642 group
->type
== 8 ? "L2 overlay" :
1645 if (group
->has_vlan_id
) {
1646 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
1649 if (group
->has_pport
) {
1650 monitor_printf(mon
, " pport %d", group
->pport
);
1653 if (group
->has_index
) {
1654 monitor_printf(mon
, " index %d", group
->index
);
1657 monitor_printf(mon
, ") -->");
1659 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
1661 monitor_printf(mon
, " set vlan %d",
1662 group
->set_vlan_id
& VLAN_VID_MASK
);
1665 if (group
->set_eth_src
) {
1668 monitor_printf(mon
, " set");
1670 monitor_printf(mon
, " src %s", group
->set_eth_src
);
1673 if (group
->set_eth_dst
) {
1675 monitor_printf(mon
, " set");
1677 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
1680 if (group
->has_ttl_check
&& group
->ttl_check
) {
1681 monitor_printf(mon
, " check TTL");
1684 if (group
->has_group_id
&& group
->group_id
) {
1685 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
1688 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
1689 monitor_printf(mon
, " pop vlan");
1692 if (group
->has_out_pport
) {
1693 monitor_printf(mon
, " out pport %d", group
->out_pport
);
1696 if (group
->has_group_ids
) {
1697 struct uint32List
*id
;
1699 monitor_printf(mon
, " groups [");
1700 for (id
= group
->group_ids
; id
; id
= id
->next
) {
1701 monitor_printf(mon
, "0x%08x", id
->value
);
1703 monitor_printf(mon
, ",");
1706 monitor_printf(mon
, "]");
1709 monitor_printf(mon
, "\n");
1712 qapi_free_RockerOfDpaGroupList(list
);
1715 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
1718 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
1720 monitor_printf(mon
, "%s\n", info
->guid
);
1722 hmp_handle_error(mon
, err
);
1723 qapi_free_GuidInfo(info
);
1726 void hmp_info_memory_size_summary(Monitor
*mon
, const QDict
*qdict
)
1729 MemoryInfo
*info
= qmp_query_memory_size_summary(&err
);
1731 monitor_printf(mon
, "base memory: %" PRIu64
"\n",
1734 if (info
->has_plugged_memory
) {
1735 monitor_printf(mon
, "plugged memory: %" PRIu64
"\n",
1736 info
->plugged_memory
);
1739 qapi_free_MemoryInfo(info
);
1741 hmp_handle_error(mon
, err
);
1744 static void print_stats_schema_value(Monitor
*mon
, StatsSchemaValue
*value
)
1746 const char *unit
= NULL
;
1747 monitor_printf(mon
, " %s (%s%s", value
->name
, StatsType_str(value
->type
),
1748 value
->has_unit
|| value
->exponent
? ", " : "");
1750 if (value
->has_unit
) {
1751 if (value
->unit
== STATS_UNIT_SECONDS
) {
1753 } else if (value
->unit
== STATS_UNIT_BYTES
) {
1758 if (unit
&& value
->base
== 10 &&
1759 value
->exponent
>= -18 && value
->exponent
<= 18 &&
1760 value
->exponent
% 3 == 0) {
1761 monitor_puts(mon
, si_prefix(value
->exponent
));
1762 } else if (unit
&& value
->base
== 2 &&
1763 value
->exponent
>= 0 && value
->exponent
<= 60 &&
1764 value
->exponent
% 10 == 0) {
1766 monitor_puts(mon
, iec_binary_prefix(value
->exponent
));
1767 } else if (value
->exponent
) {
1768 /* Use exponential notation and write the unit's English name */
1769 monitor_printf(mon
, "* %d^%d%s",
1770 value
->base
, value
->exponent
,
1771 value
->has_unit
? " " : "");
1775 if (value
->has_unit
) {
1776 monitor_puts(mon
, unit
? unit
: StatsUnit_str(value
->unit
));
1779 /* Print bucket size for linear histograms */
1780 if (value
->type
== STATS_TYPE_LINEAR_HISTOGRAM
&& value
->has_bucket_size
) {
1781 monitor_printf(mon
, ", bucket size=%d", value
->bucket_size
);
1783 monitor_printf(mon
, ")");
1786 static StatsSchemaValueList
*find_schema_value_list(
1787 StatsSchemaList
*list
, StatsProvider provider
,
1790 StatsSchemaList
*node
;
1792 for (node
= list
; node
; node
= node
->next
) {
1793 if (node
->value
->provider
== provider
&&
1794 node
->value
->target
== target
) {
1795 return node
->value
->stats
;
1801 static void print_stats_results(Monitor
*mon
, StatsTarget target
,
1803 StatsResult
*result
,
1804 StatsSchemaList
*schema
)
1806 /* Find provider schema */
1807 StatsSchemaValueList
*schema_value_list
=
1808 find_schema_value_list(schema
, result
->provider
, target
);
1809 StatsList
*stats_list
;
1811 if (!schema_value_list
) {
1812 monitor_printf(mon
, "failed to find schema list for %s\n",
1813 StatsProvider_str(result
->provider
));
1817 if (show_provider
) {
1818 monitor_printf(mon
, "provider: %s\n",
1819 StatsProvider_str(result
->provider
));
1822 for (stats_list
= result
->stats
; stats_list
;
1823 stats_list
= stats_list
->next
,
1824 schema_value_list
= schema_value_list
->next
) {
1826 Stats
*stats
= stats_list
->value
;
1827 StatsValue
*stats_value
= stats
->value
;
1828 StatsSchemaValue
*schema_value
= schema_value_list
->value
;
1830 /* Find schema entry */
1831 while (!g_str_equal(stats
->name
, schema_value
->name
)) {
1832 if (!schema_value_list
->next
) {
1833 monitor_printf(mon
, "failed to find schema entry for %s\n",
1837 schema_value_list
= schema_value_list
->next
;
1838 schema_value
= schema_value_list
->value
;
1841 print_stats_schema_value(mon
, schema_value
);
1843 if (stats_value
->type
== QTYPE_QNUM
) {
1844 monitor_printf(mon
, ": %" PRId64
"\n", stats_value
->u
.scalar
);
1845 } else if (stats_value
->type
== QTYPE_QBOOL
) {
1846 monitor_printf(mon
, ": %s\n", stats_value
->u
.boolean
? "yes" : "no");
1847 } else if (stats_value
->type
== QTYPE_QLIST
) {
1851 monitor_printf(mon
, ": ");
1852 for (list
= stats_value
->u
.list
, i
= 1;
1854 list
= list
->next
, i
++) {
1855 monitor_printf(mon
, "[%d]=%" PRId64
" ", i
, list
->value
);
1857 monitor_printf(mon
, "\n");
1862 /* Create the StatsFilter that is needed for an "info stats" invocation. */
1863 static StatsFilter
*stats_filter(StatsTarget target
, const char *names
,
1864 int cpu_index
, StatsProvider provider
)
1866 StatsFilter
*filter
= g_malloc0(sizeof(*filter
));
1867 StatsProvider provider_idx
;
1868 StatsRequestList
*request_list
= NULL
;
1870 filter
->target
= target
;
1872 case STATS_TARGET_VM
:
1874 case STATS_TARGET_VCPU
:
1876 strList
*vcpu_list
= NULL
;
1877 CPUState
*cpu
= qemu_get_cpu(cpu_index
);
1878 char *canonical_path
= object_get_canonical_path(OBJECT(cpu
));
1880 QAPI_LIST_PREPEND(vcpu_list
, canonical_path
);
1881 filter
->u
.vcpu
.has_vcpus
= true;
1882 filter
->u
.vcpu
.vcpus
= vcpu_list
;
1889 if (!names
&& provider
== STATS_PROVIDER__MAX
) {
1894 * "info stats" can only query either one or all the providers. Querying
1895 * by name, but not by provider, requires the creation of one filter per
1898 for (provider_idx
= 0; provider_idx
< STATS_PROVIDER__MAX
; provider_idx
++) {
1899 if (provider
== STATS_PROVIDER__MAX
|| provider
== provider_idx
) {
1900 StatsRequest
*request
= g_new0(StatsRequest
, 1);
1901 request
->provider
= provider_idx
;
1902 if (names
&& !g_str_equal(names
, "*")) {
1903 request
->has_names
= true;
1904 request
->names
= strList_from_comma_list(names
);
1906 QAPI_LIST_PREPEND(request_list
, request
);
1910 filter
->has_providers
= true;
1911 filter
->providers
= request_list
;
1915 void hmp_info_stats(Monitor
*mon
, const QDict
*qdict
)
1917 const char *target_str
= qdict_get_str(qdict
, "target");
1918 const char *provider_str
= qdict_get_try_str(qdict
, "provider");
1919 const char *names
= qdict_get_try_str(qdict
, "names");
1921 StatsProvider provider
= STATS_PROVIDER__MAX
;
1924 g_autoptr(StatsSchemaList
) schema
= NULL
;
1925 g_autoptr(StatsResultList
) stats
= NULL
;
1926 g_autoptr(StatsFilter
) filter
= NULL
;
1927 StatsResultList
*entry
;
1929 target
= qapi_enum_parse(&StatsTarget_lookup
, target_str
, -1, &err
);
1931 monitor_printf(mon
, "invalid stats target %s\n", target_str
);
1935 provider
= qapi_enum_parse(&StatsProvider_lookup
, provider_str
, -1, &err
);
1937 monitor_printf(mon
, "invalid stats provider %s\n", provider_str
);
1942 schema
= qmp_query_stats_schemas(provider_str
? true : false,
1949 case STATS_TARGET_VM
:
1950 filter
= stats_filter(target
, names
, -1, provider
);
1952 case STATS_TARGET_VCPU
: {}
1953 int cpu_index
= monitor_get_cpu_index(mon
);
1954 filter
= stats_filter(target
, names
, cpu_index
, provider
);
1960 stats
= qmp_query_stats(filter
, &err
);
1964 for (entry
= stats
; entry
; entry
= entry
->next
) {
1965 print_stats_results(mon
, target
, provider_str
== NULL
, entry
->value
, schema
);
1970 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
1976 static void hmp_virtio_dump_protocols(Monitor
*mon
,
1977 VhostDeviceProtocols
*pcol
)
1979 strList
*pcol_list
= pcol
->protocols
;
1981 monitor_printf(mon
, "\t%s", pcol_list
->value
);
1982 pcol_list
= pcol_list
->next
;
1983 if (pcol_list
!= NULL
) {
1984 monitor_printf(mon
, ",\n");
1987 monitor_printf(mon
, "\n");
1988 if (pcol
->has_unknown_protocols
) {
1989 monitor_printf(mon
, " unknown-protocols(0x%016"PRIx64
")\n",
1990 pcol
->unknown_protocols
);
1994 static void hmp_virtio_dump_status(Monitor
*mon
,
1995 VirtioDeviceStatus
*status
)
1997 strList
*status_list
= status
->statuses
;
1998 while (status_list
) {
1999 monitor_printf(mon
, "\t%s", status_list
->value
);
2000 status_list
= status_list
->next
;
2001 if (status_list
!= NULL
) {
2002 monitor_printf(mon
, ",\n");
2005 monitor_printf(mon
, "\n");
2006 if (status
->has_unknown_statuses
) {
2007 monitor_printf(mon
, " unknown-statuses(0x%016"PRIx32
")\n",
2008 status
->unknown_statuses
);
2012 static void hmp_virtio_dump_features(Monitor
*mon
,
2013 VirtioDeviceFeatures
*features
)
2015 strList
*transport_list
= features
->transports
;
2016 while (transport_list
) {
2017 monitor_printf(mon
, "\t%s", transport_list
->value
);
2018 transport_list
= transport_list
->next
;
2019 if (transport_list
!= NULL
) {
2020 monitor_printf(mon
, ",\n");
2024 monitor_printf(mon
, "\n");
2025 strList
*list
= features
->dev_features
;
2028 monitor_printf(mon
, "\t%s", list
->value
);
2031 monitor_printf(mon
, ",\n");
2034 monitor_printf(mon
, "\n");
2037 if (features
->has_unknown_dev_features
) {
2038 monitor_printf(mon
, " unknown-features(0x%016"PRIx64
")\n",
2039 features
->unknown_dev_features
);
2043 void hmp_virtio_query(Monitor
*mon
, const QDict
*qdict
)
2046 VirtioInfoList
*list
= qmp_x_query_virtio(&err
);
2047 VirtioInfoList
*node
;
2050 hmp_handle_error(mon
, err
);
2055 monitor_printf(mon
, "No VirtIO devices\n");
2061 monitor_printf(mon
, "%s [%s]\n", node
->value
->path
,
2065 qapi_free_VirtioInfoList(list
);
2068 void hmp_virtio_status(Monitor
*mon
, const QDict
*qdict
)
2071 const char *path
= qdict_get_try_str(qdict
, "path");
2072 VirtioStatus
*s
= qmp_x_query_virtio_status(path
, &err
);
2075 hmp_handle_error(mon
, err
);
2079 monitor_printf(mon
, "%s:\n", path
);
2080 monitor_printf(mon
, " device_name: %s %s\n",
2081 s
->name
, s
->vhost_dev
? "(vhost)" : "");
2082 monitor_printf(mon
, " device_id: %d\n", s
->device_id
);
2083 monitor_printf(mon
, " vhost_started: %s\n",
2084 s
->vhost_started
? "true" : "false");
2085 monitor_printf(mon
, " bus_name: %s\n", s
->bus_name
);
2086 monitor_printf(mon
, " broken: %s\n",
2087 s
->broken
? "true" : "false");
2088 monitor_printf(mon
, " disabled: %s\n",
2089 s
->disabled
? "true" : "false");
2090 monitor_printf(mon
, " disable_legacy_check: %s\n",
2091 s
->disable_legacy_check
? "true" : "false");
2092 monitor_printf(mon
, " started: %s\n",
2093 s
->started
? "true" : "false");
2094 monitor_printf(mon
, " use_started: %s\n",
2095 s
->use_started
? "true" : "false");
2096 monitor_printf(mon
, " start_on_kick: %s\n",
2097 s
->start_on_kick
? "true" : "false");
2098 monitor_printf(mon
, " use_guest_notifier_mask: %s\n",
2099 s
->use_guest_notifier_mask
? "true" : "false");
2100 monitor_printf(mon
, " vm_running: %s\n",
2101 s
->vm_running
? "true" : "false");
2102 monitor_printf(mon
, " num_vqs: %"PRId64
"\n", s
->num_vqs
);
2103 monitor_printf(mon
, " queue_sel: %d\n",
2105 monitor_printf(mon
, " isr: %d\n", s
->isr
);
2106 monitor_printf(mon
, " endianness: %s\n",
2108 monitor_printf(mon
, " status:\n");
2109 hmp_virtio_dump_status(mon
, s
->status
);
2110 monitor_printf(mon
, " Guest features:\n");
2111 hmp_virtio_dump_features(mon
, s
->guest_features
);
2112 monitor_printf(mon
, " Host features:\n");
2113 hmp_virtio_dump_features(mon
, s
->host_features
);
2114 monitor_printf(mon
, " Backend features:\n");
2115 hmp_virtio_dump_features(mon
, s
->backend_features
);
2118 monitor_printf(mon
, " VHost:\n");
2119 monitor_printf(mon
, " nvqs: %d\n",
2120 s
->vhost_dev
->nvqs
);
2121 monitor_printf(mon
, " vq_index: %"PRId64
"\n",
2122 s
->vhost_dev
->vq_index
);
2123 monitor_printf(mon
, " max_queues: %"PRId64
"\n",
2124 s
->vhost_dev
->max_queues
);
2125 monitor_printf(mon
, " n_mem_sections: %"PRId64
"\n",
2126 s
->vhost_dev
->n_mem_sections
);
2127 monitor_printf(mon
, " n_tmp_sections: %"PRId64
"\n",
2128 s
->vhost_dev
->n_tmp_sections
);
2129 monitor_printf(mon
, " backend_cap: %"PRId64
"\n",
2130 s
->vhost_dev
->backend_cap
);
2131 monitor_printf(mon
, " log_enabled: %s\n",
2132 s
->vhost_dev
->log_enabled
? "true" : "false");
2133 monitor_printf(mon
, " log_size: %"PRId64
"\n",
2134 s
->vhost_dev
->log_size
);
2135 monitor_printf(mon
, " Features:\n");
2136 hmp_virtio_dump_features(mon
, s
->vhost_dev
->features
);
2137 monitor_printf(mon
, " Acked features:\n");
2138 hmp_virtio_dump_features(mon
, s
->vhost_dev
->acked_features
);
2139 monitor_printf(mon
, " Backend features:\n");
2140 hmp_virtio_dump_features(mon
, s
->vhost_dev
->backend_features
);
2141 monitor_printf(mon
, " Protocol features:\n");
2142 hmp_virtio_dump_protocols(mon
, s
->vhost_dev
->protocol_features
);
2145 qapi_free_VirtioStatus(s
);
2148 void hmp_vhost_queue_status(Monitor
*mon
, const QDict
*qdict
)
2151 const char *path
= qdict_get_try_str(qdict
, "path");
2152 int queue
= qdict_get_int(qdict
, "queue");
2153 VirtVhostQueueStatus
*s
=
2154 qmp_x_query_virtio_vhost_queue_status(path
, queue
, &err
);
2157 hmp_handle_error(mon
, err
);
2161 monitor_printf(mon
, "%s:\n", path
);
2162 monitor_printf(mon
, " device_name: %s (vhost)\n",
2164 monitor_printf(mon
, " kick: %"PRId64
"\n", s
->kick
);
2165 monitor_printf(mon
, " call: %"PRId64
"\n", s
->call
);
2166 monitor_printf(mon
, " VRing:\n");
2167 monitor_printf(mon
, " num: %"PRId64
"\n", s
->num
);
2168 monitor_printf(mon
, " desc: 0x%016"PRIx64
"\n", s
->desc
);
2169 monitor_printf(mon
, " desc_phys: 0x%016"PRIx64
"\n",
2171 monitor_printf(mon
, " desc_size: %"PRId32
"\n", s
->desc_size
);
2172 monitor_printf(mon
, " avail: 0x%016"PRIx64
"\n", s
->avail
);
2173 monitor_printf(mon
, " avail_phys: 0x%016"PRIx64
"\n",
2175 monitor_printf(mon
, " avail_size: %"PRId32
"\n", s
->avail_size
);
2176 monitor_printf(mon
, " used: 0x%016"PRIx64
"\n", s
->used
);
2177 monitor_printf(mon
, " used_phys: 0x%016"PRIx64
"\n",
2179 monitor_printf(mon
, " used_size: %"PRId32
"\n", s
->used_size
);
2181 qapi_free_VirtVhostQueueStatus(s
);
2184 void hmp_virtio_queue_status(Monitor
*mon
, const QDict
*qdict
)
2187 const char *path
= qdict_get_try_str(qdict
, "path");
2188 int queue
= qdict_get_int(qdict
, "queue");
2189 VirtQueueStatus
*s
= qmp_x_query_virtio_queue_status(path
, queue
, &err
);
2192 hmp_handle_error(mon
, err
);
2196 monitor_printf(mon
, "%s:\n", path
);
2197 monitor_printf(mon
, " device_name: %s\n", s
->name
);
2198 monitor_printf(mon
, " queue_index: %d\n", s
->queue_index
);
2199 monitor_printf(mon
, " inuse: %d\n", s
->inuse
);
2200 monitor_printf(mon
, " used_idx: %d\n", s
->used_idx
);
2201 monitor_printf(mon
, " signalled_used: %d\n",
2203 monitor_printf(mon
, " signalled_used_valid: %s\n",
2204 s
->signalled_used_valid
? "true" : "false");
2205 if (s
->has_last_avail_idx
) {
2206 monitor_printf(mon
, " last_avail_idx: %d\n",
2209 if (s
->has_shadow_avail_idx
) {
2210 monitor_printf(mon
, " shadow_avail_idx: %d\n",
2211 s
->shadow_avail_idx
);
2213 monitor_printf(mon
, " VRing:\n");
2214 monitor_printf(mon
, " num: %"PRId32
"\n", s
->vring_num
);
2215 monitor_printf(mon
, " num_default: %"PRId32
"\n",
2216 s
->vring_num_default
);
2217 monitor_printf(mon
, " align: %"PRId32
"\n",
2219 monitor_printf(mon
, " desc: 0x%016"PRIx64
"\n",
2221 monitor_printf(mon
, " avail: 0x%016"PRIx64
"\n",
2223 monitor_printf(mon
, " used: 0x%016"PRIx64
"\n",
2226 qapi_free_VirtQueueStatus(s
);
2229 void hmp_virtio_queue_element(Monitor
*mon
, const QDict
*qdict
)
2232 const char *path
= qdict_get_try_str(qdict
, "path");
2233 int queue
= qdict_get_int(qdict
, "queue");
2234 int index
= qdict_get_try_int(qdict
, "index", -1);
2235 VirtioQueueElement
*e
;
2236 VirtioRingDescList
*list
;
2238 e
= qmp_x_query_virtio_queue_element(path
, queue
, index
!= -1,
2241 hmp_handle_error(mon
, err
);
2245 monitor_printf(mon
, "%s:\n", path
);
2246 monitor_printf(mon
, " device_name: %s\n", e
->name
);
2247 monitor_printf(mon
, " index: %d\n", e
->index
);
2248 monitor_printf(mon
, " desc:\n");
2249 monitor_printf(mon
, " descs:\n");
2253 monitor_printf(mon
, " addr 0x%"PRIx64
" len %d",
2254 list
->value
->addr
, list
->value
->len
);
2255 if (list
->value
->flags
) {
2256 strList
*flag
= list
->value
->flags
;
2257 monitor_printf(mon
, " (");
2259 monitor_printf(mon
, "%s", flag
->value
);
2262 monitor_printf(mon
, ", ");
2265 monitor_printf(mon
, ")");
2269 monitor_printf(mon
, ",\n");
2272 monitor_printf(mon
, "\n");
2273 monitor_printf(mon
, " avail:\n");
2274 monitor_printf(mon
, " flags: %d\n", e
->avail
->flags
);
2275 monitor_printf(mon
, " idx: %d\n", e
->avail
->idx
);
2276 monitor_printf(mon
, " ring: %d\n", e
->avail
->ring
);
2277 monitor_printf(mon
, " used:\n");
2278 monitor_printf(mon
, " flags: %d\n", e
->used
->flags
);
2279 monitor_printf(mon
, " idx: %d\n", e
->used
->idx
);
2281 qapi_free_VirtioQueueElement(e
);