ui: Factor out hmp_change_vnc(), and move to ui/ui-hmp-cmds.c
[qemu.git] / monitor / hmp-cmds.c
blob1dba973092737e0c5010c600d23c4f8daf996b66
1 /*
2 * Human Monitor Interface commands
4 * Copyright IBM, Corp. 2011
6 * Authors:
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"
18 #include "net/net.h"
19 #include "net/eth.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)
62 if (err) {
63 error_reportf_err(err, "Error: ");
64 return true;
66 return false;
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)
75 strList *res = NULL;
76 strList **tail = &res;
78 while (in && in[0]) {
79 char *comma = strchr(in, ',');
80 char *value;
82 if (comma) {
83 value = g_strndup(in, comma - in);
84 in = comma + 1; /* skip the , */
85 } else {
86 value = g_strdup(in);
87 in = NULL;
89 QAPI_LIST_APPEND(tail, value);
92 return res;
95 void hmp_info_name(Monitor *mon, const QDict *qdict)
97 NameInfo *info;
99 info = qmp_query_name(NULL);
100 if (info->name) {
101 monitor_printf(mon, "%s\n", info->name);
103 qapi_free_NameInfo(info);
106 void hmp_info_version(Monitor *mon, const QDict *qdict)
108 VersionInfo *info;
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,
114 info->package);
116 qapi_free_VersionInfo(info);
119 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
121 KvmInfo *info;
123 info = qmp_query_kvm(NULL);
124 monitor_printf(mon, "kvm support: ");
125 if (info->present) {
126 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
127 } else {
128 monitor_printf(mon, "not compiled\n");
131 qapi_free_KvmInfo(info);
134 void hmp_info_status(Monitor *mon, const QDict *qdict)
136 StatusInfo *info;
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)
155 UuidInfo *info;
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)
177 MigrationInfo *info;
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");
186 while (reasons) {
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);
197 } else {
198 monitor_printf(mon, "\n");
201 monitor_printf(mon, "total time: %" PRIu64 " ms\n",
202 info->total_time);
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",
209 info->downtime);
211 if (info->has_setup_time) {
212 monitor_printf(mon, "setup: %" PRIu64 " ms\n",
213 info->setup_time);
217 if (info->ram) {
218 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
219 info->ram->transferred >> 10);
220 monitor_printf(mon, "throughput: %0.2f mbps\n",
221 info->ram->mbps);
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",
229 info->ram->skipped);
230 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
231 info->ram->normal);
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) {
264 monitor_printf(mon,
265 "Zero-copy-send fallbacks happened: %" PRIu64 " times\n",
266 info->ram->dirty_sync_missed_zero_copy);
270 if (info->disk) {
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) {
320 Visitor *v;
321 char *str;
322 v = string_output_visitor_new(false, &str);
323 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime,
324 &error_abort);
325 visit_complete(v, &str);
326 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
327 g_free(str);
328 visit_free(v);
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);
338 g_free(s);
340 monitor_printf(mon, "]\n");
343 if (info->vfio) {
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);
357 if (caps) {
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);
374 if (params) {
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),
426 params->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),
461 params->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;
471 bmnal;
472 bmnal = bmnal->next)
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)
495 BalloonInfo *info;
496 Error *err = NULL;
498 info = qmp_query_balloon(&err);
499 if (hmp_handle_error(mon, err)) {
500 return;
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);
517 if (k->print_info) {
518 k->print_info(intc, mon);
519 } else {
520 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
521 object_get_typename(obj));
525 return 0;
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)
536 #ifdef CONFIG_TPM
537 TPMInfoList *info_list, *info;
538 Error *err = NULL;
539 unsigned int c = 0;
540 TPMPassthroughOptions *tpo;
541 TPMEmulatorOptions *teo;
543 info_list = qmp_query_tpm(&err);
544 if (err) {
545 monitor_printf(mon, "TPM device not supported\n");
546 error_free(err);
547 return;
550 if (info_list) {
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=" : "",
567 tpo->path ?: "",
568 tpo->cancel_path ? ",cancel-path=" : "",
569 tpo->cancel_path ?: "");
570 break;
571 case TPM_TYPE_EMULATOR:
572 teo = ti->options->u.emulator.data;
573 monitor_printf(mon, ",chardev=%s", teo->chardev);
574 break;
575 case TPM_TYPE__MAX:
576 break;
578 monitor_printf(mon, "\n");
579 c++;
581 qapi_free_TPMInfoList(info_list);
582 #else
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);
590 qmp_quit(NULL);
593 void hmp_stop(Monitor *mon, const QDict *qdict)
595 qmp_stop(NULL);
598 void hmp_sync_profile(Monitor *mon, const QDict *qdict)
600 const char *op = qdict_get_try_str(qdict, "op");
602 if (op == NULL) {
603 bool on = qsp_is_enabled();
605 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off");
606 return;
608 if (!strcmp(op, "on")) {
609 qsp_enable();
610 } else if (!strcmp(op, "off")) {
611 qsp_disable();
612 } else if (!strcmp(op, "reset")) {
613 qsp_reset();
614 } else {
615 Error *err = NULL;
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)
634 Error *err = NULL;
636 qmp_x_exit_preconfig(&err);
637 hmp_handle_error(mon, err);
640 void hmp_cpu(Monitor *mon, const QDict *qdict)
642 int64_t cpu_index;
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");
657 Error *err = NULL;
658 int cpu_index = monitor_get_cpu_index(mon);
660 if (cpu_index < 0) {
661 monitor_printf(mon, "No CPU available\n");
662 return;
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");
674 Error *err = NULL;
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");
684 Error *err = NULL;
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");
695 char *data;
696 Error *err = NULL;
697 int i;
699 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
700 if (hmp_handle_error(mon, err)) {
701 return;
704 for (i = 0; data[i]; i++) {
705 unsigned char ch = data[i];
707 if (ch == '\\') {
708 monitor_printf(mon, "\\\\");
709 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
710 monitor_printf(mon, "\\u%04X", ch);
711 } else {
712 monitor_printf(mon, "%c", ch);
716 monitor_printf(mon, "\n");
717 g_free(data);
720 void hmp_cont(Monitor *mon, const QDict *qdict)
722 Error *err = NULL;
724 qmp_cont(&err);
725 hmp_handle_error(mon, err);
728 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
730 Error *err = NULL;
732 qmp_system_wakeup(&err);
733 hmp_handle_error(mon, err);
736 void hmp_nmi(Monitor *mon, const QDict *qdict)
738 Error *err = NULL;
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");
748 Error *err = NULL;
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");
757 Error *err = NULL;
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");
767 Error *err = NULL;
769 vm_stop(RUN_STATE_RESTORE_VM);
771 if (load_snapshot(name, NULL, false, NULL, &err) && saved_vm_running) {
772 vm_start();
774 hmp_handle_error(mon, err);
777 void hmp_savevm(Monitor *mon, const QDict *qdict)
779 Error *err = NULL;
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)
788 Error *err = NULL;
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)
817 Error *err = NULL;
818 const char *state = qdict_get_str(qdict, "state");
819 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
821 if (val >= 0) {
822 qmp_migrate_continue(val, &err);
825 hmp_handle_error(mon, err);
828 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
830 Error *err = NULL;
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)
840 Error *err = NULL;
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)
850 Error *err = NULL;
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");
862 Error *err = NULL;
863 MigrationCapabilityStatusList *caps = NULL;
864 MigrationCapabilityStatus *value;
865 int val;
867 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
868 if (val < 0) {
869 goto end;
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);
879 end:
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;
890 uint64_t cache_size;
891 Error *err = NULL;
892 int val, ret;
894 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
895 if (val < 0) {
896 goto cleanup;
899 switch (val) {
900 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
901 p->has_compress_level = true;
902 visit_type_uint8(v, param, &p->compress_level, &err);
903 break;
904 case MIGRATION_PARAMETER_COMPRESS_THREADS:
905 p->has_compress_threads = true;
906 visit_type_uint8(v, param, &p->compress_threads, &err);
907 break;
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);
911 break;
912 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
913 p->has_decompress_threads = true;
914 visit_type_uint8(v, param, &p->decompress_threads, &err);
915 break;
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);
919 break;
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);
923 break;
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);
927 break;
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);
931 break;
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);
935 break;
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);
940 break;
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);
945 break;
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);
950 break;
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);
961 break;
963 p->max_bandwidth = valuebw;
964 break;
965 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
966 p->has_downtime_limit = true;
967 visit_type_size(v, param, &p->downtime_limit, &err);
968 break;
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);
972 break;
973 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
974 p->has_block_incremental = true;
975 visit_type_bool(v, param, &p->block_incremental, &err);
976 break;
977 case MIGRATION_PARAMETER_MULTIFD_CHANNELS:
978 p->has_multifd_channels = true;
979 visit_type_uint8(v, param, &p->multifd_channels, &err);
980 break;
981 case MIGRATION_PARAMETER_MULTIFD_COMPRESSION:
982 p->has_multifd_compression = true;
983 visit_type_MultiFDCompression(v, param, &p->multifd_compression,
984 &err);
985 break;
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);
989 break;
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);
993 break;
994 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
995 p->has_xbzrle_cache_size = true;
996 if (!visit_type_size(v, param, &cache_size, &err)) {
997 break;
999 if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) {
1000 error_setg(&err, "Invalid size %s", valuestr);
1001 break;
1003 p->xbzrle_cache_size = cache_size;
1004 break;
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);
1008 break;
1009 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL:
1010 p->has_announce_initial = true;
1011 visit_type_size(v, param, &p->announce_initial, &err);
1012 break;
1013 case MIGRATION_PARAMETER_ANNOUNCE_MAX:
1014 p->has_announce_max = true;
1015 visit_type_size(v, param, &p->announce_max, &err);
1016 break;
1017 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS:
1018 p->has_announce_rounds = true;
1019 visit_type_size(v, param, &p->announce_rounds, &err);
1020 break;
1021 case MIGRATION_PARAMETER_ANNOUNCE_STEP:
1022 p->has_announce_step = true;
1023 visit_type_size(v, param, &p->announce_step, &err);
1024 break;
1025 case MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING:
1026 error_setg(&err, "The block-bitmap-mapping parameter can only be set "
1027 "through QMP");
1028 break;
1029 default:
1030 assert(0);
1033 if (err) {
1034 goto cleanup;
1037 qmp_migrate_set_parameters(p, &err);
1039 cleanup:
1040 qapi_free_MigrateSetParameters(p);
1041 visit_free(v);
1042 hmp_handle_error(mon, err);
1045 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1047 Error *err = NULL;
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)
1064 Error *err = NULL;
1065 qmp_migrate_start_postcopy(&err);
1066 hmp_handle_error(mon, err);
1069 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1071 Error *err = NULL;
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;
1085 Error *err = NULL;
1087 #ifdef CONFIG_VNC
1088 if (strcmp(device, "vnc") == 0) {
1089 hmp_change_vnc(mon, device, target, arg, read_only, force, &err);
1090 } else
1091 #endif
1093 if (read_only) {
1094 read_only_mode =
1095 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
1096 read_only,
1097 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1098 if (err) {
1099 goto end;
1103 qmp_blockdev_change_medium(device, NULL, target, arg, true, force,
1104 !!read_only, read_only_mode,
1105 &err);
1108 end:
1109 hmp_handle_error(mon, err);
1112 typedef struct HMPMigrationStatus {
1113 QEMUTimer *timer;
1114 Monitor *mon;
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) {
1126 if (info->disk) {
1127 int progress;
1129 if (info->disk->remaining) {
1130 progress = info->disk->transferred * 100 / info->disk->total;
1131 } else {
1132 progress = 100;
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);
1140 } else {
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);
1149 g_free(status);
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");
1162 Error *err = NULL;
1164 qmp_migrate(uri, !!blk, blk, !!inc, inc,
1165 false, false, true, resume, &err);
1166 if (hmp_handle_error(mon, err)) {
1167 return;
1170 if (!detach) {
1171 HMPMigrationStatus *status;
1173 if (monitor_suspend(mon) < 0) {
1174 monitor_printf(mon, "terminal does not allow synchronous "
1175 "migration, continuing detached\n");
1176 return;
1179 status = g_malloc0(sizeof(*status));
1180 status->mon = mon;
1181 status->is_block_migration = blk || inc;
1182 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1183 status);
1184 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1188 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1190 Error *err = NULL;
1191 QemuOpts *opts;
1192 const char *type = qdict_get_try_str(qdict, "type");
1194 if (type && is_help_option(type)) {
1195 show_netdevs();
1196 return;
1198 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1199 if (err) {
1200 goto out;
1203 netdev_add(opts, &err);
1204 if (err) {
1205 qemu_opts_del(opts);
1208 out:
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");
1215 Error *err = NULL;
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");
1224 Error *err = NULL;
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");
1233 Error *err = NULL;
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");
1242 Error *err = NULL;
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");
1251 Error *err = NULL;
1252 QemuOpts *opts;
1254 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
1255 if (opts == NULL) {
1256 error_setg(&err, "Parsing chardev args failed");
1257 } else {
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");
1267 const char *id;
1268 Error *err = NULL;
1269 ChardevBackend *backend = NULL;
1270 ChardevReturn *ret = NULL;
1271 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
1272 true);
1273 if (!opts) {
1274 error_setg(&err, "Parsing chardev args failed");
1275 goto end;
1278 id = qdict_get_str(qdict, "id");
1279 if (qemu_opts_id(opts)) {
1280 error_setg(&err, "Unexpected 'id' parameter");
1281 goto end;
1284 backend = qemu_chr_parse_opts(opts, &err);
1285 if (!backend) {
1286 goto end;
1289 ret = qmp_chardev_change(id, backend, &err);
1291 end:
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");
1317 Error *err = NULL;
1319 user_creatable_del(id, &err);
1320 hmp_handle_error(mon, err);
1323 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
1325 Error *err = NULL;
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;
1337 if (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");
1355 break;
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);
1364 break;
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",
1377 vmi->block_size);
1378 monitor_printf(mon, " memdev: %s\n", vmi->memdev);
1379 break;
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);
1389 break;
1390 default:
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;
1424 Error *err = NULL;
1426 rocker = qmp_query_rocker(name, &err);
1427 if (hmp_handle_error(mon, err)) {
1428 return;
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");
1442 Error *err = NULL;
1444 list = qmp_query_rocker_ports(name, &err);
1445 if (hmp_handle_error(mon, err)) {
1446 return;
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",
1454 port->value->name,
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);
1470 Error *err = NULL;
1472 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
1473 if (hmp_handle_error(mon, err)) {
1474 return;
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;
1485 if (flow->hits) {
1486 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
1487 key->priority, key->tbl_id, flow->hits);
1488 } else {
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) {
1517 case 0x0806:
1518 monitor_printf(mon, " ARP");
1519 break;
1520 case 0x0800:
1521 monitor_printf(mon, " IP");
1522 break;
1523 case 0x86dd:
1524 monitor_printf(mon, " IPv6");
1525 break;
1526 case 0x8809:
1527 monitor_printf(mon, " LACP");
1528 break;
1529 case 0x88cc:
1530 monitor_printf(mon, " LLDP");
1531 break;
1532 default:
1533 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
1534 break;
1538 if (key->eth_src) {
1539 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
1540 mask->eth_src &&
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) &&
1544 mask->eth_src &&
1545 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
1546 monitor_printf(mon, " src <any ucast>");
1547 } else {
1548 monitor_printf(mon, " src %s", key->eth_src);
1549 if (mask->eth_src) {
1550 monitor_printf(mon, "(%s)", mask->eth_src);
1555 if (key->eth_dst) {
1556 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
1557 mask->eth_dst &&
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) &&
1561 mask->eth_dst &&
1562 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
1563 monitor_printf(mon, " dst <any ucast>");
1564 } else {
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);
1586 if (key->ip_dst) {
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);
1619 Error *err = NULL;
1621 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
1622 if (hmp_handle_error(mon, err)) {
1623 return;
1626 monitor_printf(mon, "id (decode) --> buckets\n");
1628 for (g = list; g; g = g->next) {
1629 RockerOfDpaGroup *group = g->value;
1630 bool set = false;
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" :
1643 "unknown");
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) {
1660 set = true;
1661 monitor_printf(mon, " set vlan %d",
1662 group->set_vlan_id & VLAN_VID_MASK);
1665 if (group->set_eth_src) {
1666 if (!set) {
1667 set = true;
1668 monitor_printf(mon, " set");
1670 monitor_printf(mon, " src %s", group->set_eth_src);
1673 if (group->set_eth_dst) {
1674 if (!set) {
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);
1702 if (id->next) {
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)
1717 Error *err = NULL;
1718 GuidInfo *info = qmp_query_vm_generation_id(&err);
1719 if (info) {
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)
1728 Error *err = NULL;
1729 MemoryInfo *info = qmp_query_memory_size_summary(&err);
1730 if (info) {
1731 monitor_printf(mon, "base memory: %" PRIu64 "\n",
1732 info->base_memory);
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) {
1752 unit = "s";
1753 } else if (value->unit == STATS_UNIT_BYTES) {
1754 unit = "B";
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 ? " " : "");
1772 unit = NULL;
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,
1788 StatsTarget target)
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;
1798 return NULL;
1801 static void print_stats_results(Monitor *mon, StatsTarget target,
1802 bool show_provider,
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));
1814 return;
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",
1834 stats->name);
1835 return;
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) {
1848 uint64List *list;
1849 int i;
1851 monitor_printf(mon, ": ");
1852 for (list = stats_value->u.list, i = 1;
1853 list;
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;
1871 switch (target) {
1872 case STATS_TARGET_VM:
1873 break;
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;
1883 break;
1885 default:
1886 break;
1889 if (!names && provider == STATS_PROVIDER__MAX) {
1890 return filter;
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
1896 * provider.
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;
1912 return filter;
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;
1922 StatsTarget target;
1923 Error *err = NULL;
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);
1930 if (err) {
1931 monitor_printf(mon, "invalid stats target %s\n", target_str);
1932 goto exit_no_print;
1934 if (provider_str) {
1935 provider = qapi_enum_parse(&StatsProvider_lookup, provider_str, -1, &err);
1936 if (err) {
1937 monitor_printf(mon, "invalid stats provider %s\n", provider_str);
1938 goto exit_no_print;
1942 schema = qmp_query_stats_schemas(provider_str ? true : false,
1943 provider, &err);
1944 if (err) {
1945 goto exit;
1948 switch (target) {
1949 case STATS_TARGET_VM:
1950 filter = stats_filter(target, names, -1, provider);
1951 break;
1952 case STATS_TARGET_VCPU: {}
1953 int cpu_index = monitor_get_cpu_index(mon);
1954 filter = stats_filter(target, names, cpu_index, provider);
1955 break;
1956 default:
1957 abort();
1960 stats = qmp_query_stats(filter, &err);
1961 if (err) {
1962 goto exit;
1964 for (entry = stats; entry; entry = entry->next) {
1965 print_stats_results(mon, target, provider_str == NULL, entry->value, schema);
1968 exit:
1969 if (err) {
1970 monitor_printf(mon, "%s\n", error_get_pretty(err));
1972 exit_no_print:
1973 error_free(err);
1976 static void hmp_virtio_dump_protocols(Monitor *mon,
1977 VhostDeviceProtocols *pcol)
1979 strList *pcol_list = pcol->protocols;
1980 while (pcol_list) {
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;
2026 if (list) {
2027 while (list) {
2028 monitor_printf(mon, "\t%s", list->value);
2029 list = list->next;
2030 if (list != NULL) {
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)
2045 Error *err = NULL;
2046 VirtioInfoList *list = qmp_x_query_virtio(&err);
2047 VirtioInfoList *node;
2049 if (err != NULL) {
2050 hmp_handle_error(mon, err);
2051 return;
2054 if (list == NULL) {
2055 monitor_printf(mon, "No VirtIO devices\n");
2056 return;
2059 node = list;
2060 while (node) {
2061 monitor_printf(mon, "%s [%s]\n", node->value->path,
2062 node->value->name);
2063 node = node->next;
2065 qapi_free_VirtioInfoList(list);
2068 void hmp_virtio_status(Monitor *mon, const QDict *qdict)
2070 Error *err = NULL;
2071 const char *path = qdict_get_try_str(qdict, "path");
2072 VirtioStatus *s = qmp_x_query_virtio_status(path, &err);
2074 if (err != NULL) {
2075 hmp_handle_error(mon, err);
2076 return;
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",
2104 s->queue_sel);
2105 monitor_printf(mon, " isr: %d\n", s->isr);
2106 monitor_printf(mon, " endianness: %s\n",
2107 s->device_endian);
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);
2117 if (s->vhost_dev) {
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)
2150 Error *err = NULL;
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);
2156 if (err != NULL) {
2157 hmp_handle_error(mon, err);
2158 return;
2161 monitor_printf(mon, "%s:\n", path);
2162 monitor_printf(mon, " device_name: %s (vhost)\n",
2163 s->name);
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",
2170 s->desc_phys);
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",
2174 s->avail_phys);
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",
2178 s->used_phys);
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)
2186 Error *err = NULL;
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);
2191 if (err != NULL) {
2192 hmp_handle_error(mon, err);
2193 return;
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",
2202 s->signalled_used);
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",
2207 s->last_avail_idx);
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",
2218 s->vring_align);
2219 monitor_printf(mon, " desc: 0x%016"PRIx64"\n",
2220 s->vring_desc);
2221 monitor_printf(mon, " avail: 0x%016"PRIx64"\n",
2222 s->vring_avail);
2223 monitor_printf(mon, " used: 0x%016"PRIx64"\n",
2224 s->vring_used);
2226 qapi_free_VirtQueueStatus(s);
2229 void hmp_virtio_queue_element(Monitor *mon, const QDict *qdict)
2231 Error *err = NULL;
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,
2239 index, &err);
2240 if (err != NULL) {
2241 hmp_handle_error(mon, err);
2242 return;
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");
2251 list = e->descs;
2252 while (list) {
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, " (");
2258 while (flag) {
2259 monitor_printf(mon, "%s", flag->value);
2260 flag = flag->next;
2261 if (flag) {
2262 monitor_printf(mon, ", ");
2265 monitor_printf(mon, ")");
2267 list = list->next;
2268 if (list) {
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);