tests/tcg: extend SSE tests to AVX
[qemu.git] / monitor / hmp-cmds.c
blobbab86c5537e1f5addcbb1d634e9b55d849897d0d
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-internal.h"
29 #include "qapi/error.h"
30 #include "qapi/clone-visitor.h"
31 #include "qapi/opts-visitor.h"
32 #include "qapi/qapi-builtin-visit.h"
33 #include "qapi/qapi-commands-block.h"
34 #include "qapi/qapi-commands-char.h"
35 #include "qapi/qapi-commands-control.h"
36 #include "qapi/qapi-commands-machine.h"
37 #include "qapi/qapi-commands-migration.h"
38 #include "qapi/qapi-commands-misc.h"
39 #include "qapi/qapi-commands-net.h"
40 #include "qapi/qapi-commands-pci.h"
41 #include "qapi/qapi-commands-rocker.h"
42 #include "qapi/qapi-commands-run-state.h"
43 #include "qapi/qapi-commands-stats.h"
44 #include "qapi/qapi-commands-tpm.h"
45 #include "qapi/qapi-commands-ui.h"
46 #include "qapi/qapi-commands-virtio.h"
47 #include "qapi/qapi-visit-virtio.h"
48 #include "qapi/qapi-visit-net.h"
49 #include "qapi/qapi-visit-migration.h"
50 #include "qapi/qmp/qdict.h"
51 #include "qapi/qmp/qerror.h"
52 #include "qapi/string-input-visitor.h"
53 #include "qapi/string-output-visitor.h"
54 #include "qom/object_interfaces.h"
55 #include "ui/console.h"
56 #include "qemu/cutils.h"
57 #include "qemu/error-report.h"
58 #include "hw/core/cpu.h"
59 #include "hw/intc/intc.h"
60 #include "migration/snapshot.h"
61 #include "migration/misc.h"
63 #ifdef CONFIG_SPICE
64 #include <spice/enums.h>
65 #endif
67 bool hmp_handle_error(Monitor *mon, Error *err)
69 if (err) {
70 error_reportf_err(err, "Error: ");
71 return true;
73 return false;
77 * Produce a strList from a comma separated list.
78 * A NULL or empty input string return NULL.
80 static strList *strList_from_comma_list(const char *in)
82 strList *res = NULL;
83 strList **tail = &res;
85 while (in && in[0]) {
86 char *comma = strchr(in, ',');
87 char *value;
89 if (comma) {
90 value = g_strndup(in, comma - in);
91 in = comma + 1; /* skip the , */
92 } else {
93 value = g_strdup(in);
94 in = NULL;
96 QAPI_LIST_APPEND(tail, value);
99 return res;
102 void hmp_info_name(Monitor *mon, const QDict *qdict)
104 NameInfo *info;
106 info = qmp_query_name(NULL);
107 if (info->has_name) {
108 monitor_printf(mon, "%s\n", info->name);
110 qapi_free_NameInfo(info);
113 void hmp_info_version(Monitor *mon, const QDict *qdict)
115 VersionInfo *info;
117 info = qmp_query_version(NULL);
119 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
120 info->qemu->major, info->qemu->minor, info->qemu->micro,
121 info->package);
123 qapi_free_VersionInfo(info);
126 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
128 KvmInfo *info;
130 info = qmp_query_kvm(NULL);
131 monitor_printf(mon, "kvm support: ");
132 if (info->present) {
133 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
134 } else {
135 monitor_printf(mon, "not compiled\n");
138 qapi_free_KvmInfo(info);
141 void hmp_info_status(Monitor *mon, const QDict *qdict)
143 StatusInfo *info;
145 info = qmp_query_status(NULL);
147 monitor_printf(mon, "VM status: %s%s",
148 info->running ? "running" : "paused",
149 info->singlestep ? " (single step mode)" : "");
151 if (!info->running && info->status != RUN_STATE_PAUSED) {
152 monitor_printf(mon, " (%s)", RunState_str(info->status));
155 monitor_printf(mon, "\n");
157 qapi_free_StatusInfo(info);
160 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
162 UuidInfo *info;
164 info = qmp_query_uuid(NULL);
165 monitor_printf(mon, "%s\n", info->UUID);
166 qapi_free_UuidInfo(info);
169 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
171 ChardevInfoList *char_info, *info;
173 char_info = qmp_query_chardev(NULL);
174 for (info = char_info; info; info = info->next) {
175 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
176 info->value->filename);
179 qapi_free_ChardevInfoList(char_info);
182 void hmp_info_mice(Monitor *mon, const QDict *qdict)
184 MouseInfoList *mice_list, *mouse;
186 mice_list = qmp_query_mice(NULL);
187 if (!mice_list) {
188 monitor_printf(mon, "No mouse devices connected\n");
189 return;
192 for (mouse = mice_list; mouse; mouse = mouse->next) {
193 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
194 mouse->value->current ? '*' : ' ',
195 mouse->value->index, mouse->value->name,
196 mouse->value->absolute ? " (absolute)" : "");
199 qapi_free_MouseInfoList(mice_list);
202 static char *SocketAddress_to_str(SocketAddress *addr)
204 switch (addr->type) {
205 case SOCKET_ADDRESS_TYPE_INET:
206 return g_strdup_printf("tcp:%s:%s",
207 addr->u.inet.host,
208 addr->u.inet.port);
209 case SOCKET_ADDRESS_TYPE_UNIX:
210 return g_strdup_printf("unix:%s",
211 addr->u.q_unix.path);
212 case SOCKET_ADDRESS_TYPE_FD:
213 return g_strdup_printf("fd:%s", addr->u.fd.str);
214 case SOCKET_ADDRESS_TYPE_VSOCK:
215 return g_strdup_printf("tcp:%s:%s",
216 addr->u.vsock.cid,
217 addr->u.vsock.port);
218 default:
219 return g_strdup("unknown address type");
223 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
225 MigrationInfo *info;
227 info = qmp_query_migrate(NULL);
229 migration_global_dump(mon);
231 if (info->blocked_reasons) {
232 strList *reasons = info->blocked_reasons;
233 monitor_printf(mon, "Outgoing migration blocked:\n");
234 while (reasons) {
235 monitor_printf(mon, " %s\n", reasons->value);
236 reasons = reasons->next;
240 if (info->has_status) {
241 monitor_printf(mon, "Migration status: %s",
242 MigrationStatus_str(info->status));
243 if (info->status == MIGRATION_STATUS_FAILED &&
244 info->has_error_desc) {
245 monitor_printf(mon, " (%s)\n", info->error_desc);
246 } else {
247 monitor_printf(mon, "\n");
250 monitor_printf(mon, "total time: %" PRIu64 " ms\n",
251 info->total_time);
252 if (info->has_expected_downtime) {
253 monitor_printf(mon, "expected downtime: %" PRIu64 " ms\n",
254 info->expected_downtime);
256 if (info->has_downtime) {
257 monitor_printf(mon, "downtime: %" PRIu64 " ms\n",
258 info->downtime);
260 if (info->has_setup_time) {
261 monitor_printf(mon, "setup: %" PRIu64 " ms\n",
262 info->setup_time);
266 if (info->has_ram) {
267 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
268 info->ram->transferred >> 10);
269 monitor_printf(mon, "throughput: %0.2f mbps\n",
270 info->ram->mbps);
271 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
272 info->ram->remaining >> 10);
273 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
274 info->ram->total >> 10);
275 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
276 info->ram->duplicate);
277 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
278 info->ram->skipped);
279 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
280 info->ram->normal);
281 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
282 info->ram->normal_bytes >> 10);
283 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
284 info->ram->dirty_sync_count);
285 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
286 info->ram->page_size >> 10);
287 monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n",
288 info->ram->multifd_bytes >> 10);
289 monitor_printf(mon, "pages-per-second: %" PRIu64 "\n",
290 info->ram->pages_per_second);
292 if (info->ram->dirty_pages_rate) {
293 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
294 info->ram->dirty_pages_rate);
296 if (info->ram->postcopy_requests) {
297 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
298 info->ram->postcopy_requests);
300 if (info->ram->precopy_bytes) {
301 monitor_printf(mon, "precopy ram: %" PRIu64 " kbytes\n",
302 info->ram->precopy_bytes >> 10);
304 if (info->ram->downtime_bytes) {
305 monitor_printf(mon, "downtime ram: %" PRIu64 " kbytes\n",
306 info->ram->downtime_bytes >> 10);
308 if (info->ram->postcopy_bytes) {
309 monitor_printf(mon, "postcopy ram: %" PRIu64 " kbytes\n",
310 info->ram->postcopy_bytes >> 10);
312 if (info->ram->dirty_sync_missed_zero_copy) {
313 monitor_printf(mon,
314 "Zero-copy-send fallbacks happened: %" PRIu64 " times\n",
315 info->ram->dirty_sync_missed_zero_copy);
319 if (info->has_disk) {
320 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
321 info->disk->transferred >> 10);
322 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
323 info->disk->remaining >> 10);
324 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
325 info->disk->total >> 10);
328 if (info->has_xbzrle_cache) {
329 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
330 info->xbzrle_cache->cache_size);
331 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
332 info->xbzrle_cache->bytes >> 10);
333 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
334 info->xbzrle_cache->pages);
335 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 " pages\n",
336 info->xbzrle_cache->cache_miss);
337 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
338 info->xbzrle_cache->cache_miss_rate);
339 monitor_printf(mon, "xbzrle encoding rate: %0.2f\n",
340 info->xbzrle_cache->encoding_rate);
341 monitor_printf(mon, "xbzrle overflow: %" PRIu64 "\n",
342 info->xbzrle_cache->overflow);
345 if (info->has_compression) {
346 monitor_printf(mon, "compression pages: %" PRIu64 " pages\n",
347 info->compression->pages);
348 monitor_printf(mon, "compression busy: %" PRIu64 "\n",
349 info->compression->busy);
350 monitor_printf(mon, "compression busy rate: %0.2f\n",
351 info->compression->busy_rate);
352 monitor_printf(mon, "compressed size: %" PRIu64 " kbytes\n",
353 info->compression->compressed_size >> 10);
354 monitor_printf(mon, "compression rate: %0.2f\n",
355 info->compression->compression_rate);
358 if (info->has_cpu_throttle_percentage) {
359 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
360 info->cpu_throttle_percentage);
363 if (info->has_postcopy_blocktime) {
364 monitor_printf(mon, "postcopy blocktime: %u\n",
365 info->postcopy_blocktime);
368 if (info->has_postcopy_vcpu_blocktime) {
369 Visitor *v;
370 char *str;
371 v = string_output_visitor_new(false, &str);
372 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime,
373 &error_abort);
374 visit_complete(v, &str);
375 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
376 g_free(str);
377 visit_free(v);
379 if (info->has_socket_address) {
380 SocketAddressList *addr;
382 monitor_printf(mon, "socket address: [\n");
384 for (addr = info->socket_address; addr; addr = addr->next) {
385 char *s = SocketAddress_to_str(addr->value);
386 monitor_printf(mon, "\t%s\n", s);
387 g_free(s);
389 monitor_printf(mon, "]\n");
392 if (info->has_vfio) {
393 monitor_printf(mon, "vfio device transferred: %" PRIu64 " kbytes\n",
394 info->vfio->transferred >> 10);
397 qapi_free_MigrationInfo(info);
400 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
402 MigrationCapabilityStatusList *caps, *cap;
404 caps = qmp_query_migrate_capabilities(NULL);
406 if (caps) {
407 for (cap = caps; cap; cap = cap->next) {
408 monitor_printf(mon, "%s: %s\n",
409 MigrationCapability_str(cap->value->capability),
410 cap->value->state ? "on" : "off");
414 qapi_free_MigrationCapabilityStatusList(caps);
417 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
419 MigrationParameters *params;
421 params = qmp_query_migrate_parameters(NULL);
423 if (params) {
424 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
425 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL),
426 params->announce_initial);
427 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
428 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX),
429 params->announce_max);
430 monitor_printf(mon, "%s: %" PRIu64 "\n",
431 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS),
432 params->announce_rounds);
433 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
434 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP),
435 params->announce_step);
436 assert(params->has_compress_level);
437 monitor_printf(mon, "%s: %u\n",
438 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
439 params->compress_level);
440 assert(params->has_compress_threads);
441 monitor_printf(mon, "%s: %u\n",
442 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
443 params->compress_threads);
444 assert(params->has_compress_wait_thread);
445 monitor_printf(mon, "%s: %s\n",
446 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD),
447 params->compress_wait_thread ? "on" : "off");
448 assert(params->has_decompress_threads);
449 monitor_printf(mon, "%s: %u\n",
450 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
451 params->decompress_threads);
452 assert(params->has_throttle_trigger_threshold);
453 monitor_printf(mon, "%s: %u\n",
454 MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD),
455 params->throttle_trigger_threshold);
456 assert(params->has_cpu_throttle_initial);
457 monitor_printf(mon, "%s: %u\n",
458 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
459 params->cpu_throttle_initial);
460 assert(params->has_cpu_throttle_increment);
461 monitor_printf(mon, "%s: %u\n",
462 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
463 params->cpu_throttle_increment);
464 assert(params->has_cpu_throttle_tailslow);
465 monitor_printf(mon, "%s: %s\n",
466 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW),
467 params->cpu_throttle_tailslow ? "on" : "off");
468 assert(params->has_max_cpu_throttle);
469 monitor_printf(mon, "%s: %u\n",
470 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE),
471 params->max_cpu_throttle);
472 assert(params->has_tls_creds);
473 monitor_printf(mon, "%s: '%s'\n",
474 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
475 params->tls_creds);
476 assert(params->has_tls_hostname);
477 monitor_printf(mon, "%s: '%s'\n",
478 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
479 params->tls_hostname);
480 assert(params->has_max_bandwidth);
481 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
482 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
483 params->max_bandwidth);
484 assert(params->has_downtime_limit);
485 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
486 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
487 params->downtime_limit);
488 assert(params->has_x_checkpoint_delay);
489 monitor_printf(mon, "%s: %u ms\n",
490 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
491 params->x_checkpoint_delay);
492 assert(params->has_block_incremental);
493 monitor_printf(mon, "%s: %s\n",
494 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
495 params->block_incremental ? "on" : "off");
496 monitor_printf(mon, "%s: %u\n",
497 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS),
498 params->multifd_channels);
499 monitor_printf(mon, "%s: %s\n",
500 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION),
501 MultiFDCompression_str(params->multifd_compression));
502 monitor_printf(mon, "%s: %" PRIu64 " bytes\n",
503 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
504 params->xbzrle_cache_size);
505 monitor_printf(mon, "%s: %" PRIu64 "\n",
506 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
507 params->max_postcopy_bandwidth);
508 monitor_printf(mon, "%s: '%s'\n",
509 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
510 params->tls_authz);
512 if (params->has_block_bitmap_mapping) {
513 const BitmapMigrationNodeAliasList *bmnal;
515 monitor_printf(mon, "%s:\n",
516 MigrationParameter_str(
517 MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING));
519 for (bmnal = params->block_bitmap_mapping;
520 bmnal;
521 bmnal = bmnal->next)
523 const BitmapMigrationNodeAlias *bmna = bmnal->value;
524 const BitmapMigrationBitmapAliasList *bmbal;
526 monitor_printf(mon, " '%s' -> '%s'\n",
527 bmna->node_name, bmna->alias);
529 for (bmbal = bmna->bitmaps; bmbal; bmbal = bmbal->next) {
530 const BitmapMigrationBitmapAlias *bmba = bmbal->value;
532 monitor_printf(mon, " '%s' -> '%s'\n",
533 bmba->name, bmba->alias);
539 qapi_free_MigrationParameters(params);
543 #ifdef CONFIG_VNC
544 /* Helper for hmp_info_vnc_clients, _servers */
545 static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
546 const char *name)
548 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
549 name,
550 info->host,
551 info->service,
552 NetworkAddressFamily_str(info->family),
553 info->websocket ? " (Websocket)" : "");
556 /* Helper displaying and auth and crypt info */
557 static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
558 VncPrimaryAuth auth,
559 VncVencryptSubAuth *vencrypt)
561 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
562 VncPrimaryAuth_str(auth),
563 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
566 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
568 while (client) {
569 VncClientInfo *cinfo = client->value;
571 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
572 monitor_printf(mon, " x509_dname: %s\n",
573 cinfo->has_x509_dname ?
574 cinfo->x509_dname : "none");
575 monitor_printf(mon, " sasl_username: %s\n",
576 cinfo->has_sasl_username ?
577 cinfo->sasl_username : "none");
579 client = client->next;
583 static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
585 while (server) {
586 VncServerInfo2 *sinfo = server->value;
587 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
588 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
589 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
590 server = server->next;
594 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
596 VncInfo2List *info2l, *info2l_head;
597 Error *err = NULL;
599 info2l = qmp_query_vnc_servers(&err);
600 info2l_head = info2l;
601 if (hmp_handle_error(mon, err)) {
602 return;
604 if (!info2l) {
605 monitor_printf(mon, "None\n");
606 return;
609 while (info2l) {
610 VncInfo2 *info = info2l->value;
611 monitor_printf(mon, "%s:\n", info->id);
612 hmp_info_vnc_servers(mon, info->server);
613 hmp_info_vnc_clients(mon, info->clients);
614 if (!info->server) {
615 /* The server entry displays its auth, we only
616 * need to display in the case of 'reverse' connections
617 * where there's no server.
619 hmp_info_vnc_authcrypt(mon, " ", info->auth,
620 info->has_vencrypt ? &info->vencrypt : NULL);
622 if (info->has_display) {
623 monitor_printf(mon, " Display: %s\n", info->display);
625 info2l = info2l->next;
628 qapi_free_VncInfo2List(info2l_head);
631 #endif
633 #ifdef CONFIG_SPICE
634 void hmp_info_spice(Monitor *mon, const QDict *qdict)
636 SpiceChannelList *chan;
637 SpiceInfo *info;
638 const char *channel_name;
639 const char * const channel_names[] = {
640 [SPICE_CHANNEL_MAIN] = "main",
641 [SPICE_CHANNEL_DISPLAY] = "display",
642 [SPICE_CHANNEL_INPUTS] = "inputs",
643 [SPICE_CHANNEL_CURSOR] = "cursor",
644 [SPICE_CHANNEL_PLAYBACK] = "playback",
645 [SPICE_CHANNEL_RECORD] = "record",
646 [SPICE_CHANNEL_TUNNEL] = "tunnel",
647 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
648 [SPICE_CHANNEL_USBREDIR] = "usbredir",
649 [SPICE_CHANNEL_PORT] = "port",
650 #if 0
651 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
652 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
653 * as quick fix for build failures with older versions. */
654 [SPICE_CHANNEL_WEBDAV] = "webdav",
655 #endif
658 info = qmp_query_spice(NULL);
660 if (!info->enabled) {
661 monitor_printf(mon, "Server: disabled\n");
662 goto out;
665 monitor_printf(mon, "Server:\n");
666 if (info->has_port) {
667 monitor_printf(mon, " address: %s:%" PRId64 "\n",
668 info->host, info->port);
670 if (info->has_tls_port) {
671 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
672 info->host, info->tls_port);
674 monitor_printf(mon, " migrated: %s\n",
675 info->migrated ? "true" : "false");
676 monitor_printf(mon, " auth: %s\n", info->auth);
677 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
678 monitor_printf(mon, " mouse-mode: %s\n",
679 SpiceQueryMouseMode_str(info->mouse_mode));
681 if (!info->has_channels || info->channels == NULL) {
682 monitor_printf(mon, "Channels: none\n");
683 } else {
684 for (chan = info->channels; chan; chan = chan->next) {
685 monitor_printf(mon, "Channel:\n");
686 monitor_printf(mon, " address: %s:%s%s\n",
687 chan->value->host, chan->value->port,
688 chan->value->tls ? " [tls]" : "");
689 monitor_printf(mon, " session: %" PRId64 "\n",
690 chan->value->connection_id);
691 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
692 chan->value->channel_type, chan->value->channel_id);
694 channel_name = "unknown";
695 if (chan->value->channel_type > 0 &&
696 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
697 channel_names[chan->value->channel_type]) {
698 channel_name = channel_names[chan->value->channel_type];
701 monitor_printf(mon, " channel name: %s\n", channel_name);
705 out:
706 qapi_free_SpiceInfo(info);
708 #endif
710 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
712 BalloonInfo *info;
713 Error *err = NULL;
715 info = qmp_query_balloon(&err);
716 if (hmp_handle_error(mon, err)) {
717 return;
720 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
722 qapi_free_BalloonInfo(info);
725 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
727 PciMemoryRegionList *region;
729 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
730 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
731 dev->slot, dev->function);
732 monitor_printf(mon, " ");
734 if (dev->class_info->has_desc) {
735 monitor_puts(mon, dev->class_info->desc);
736 } else {
737 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
740 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
741 dev->id->vendor, dev->id->device);
742 if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) {
743 monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n",
744 dev->id->subsystem_vendor, dev->id->subsystem);
747 if (dev->has_irq) {
748 monitor_printf(mon, " IRQ %" PRId64 ", pin %c\n",
749 dev->irq, (char)('A' + dev->irq_pin - 1));
752 if (dev->has_pci_bridge) {
753 monitor_printf(mon, " BUS %" PRId64 ".\n",
754 dev->pci_bridge->bus->number);
755 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
756 dev->pci_bridge->bus->secondary);
757 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
758 dev->pci_bridge->bus->subordinate);
760 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
761 dev->pci_bridge->bus->io_range->base,
762 dev->pci_bridge->bus->io_range->limit);
764 monitor_printf(mon,
765 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
766 dev->pci_bridge->bus->memory_range->base,
767 dev->pci_bridge->bus->memory_range->limit);
769 monitor_printf(mon, " prefetchable memory range "
770 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
771 dev->pci_bridge->bus->prefetchable_range->base,
772 dev->pci_bridge->bus->prefetchable_range->limit);
775 for (region = dev->regions; region; region = region->next) {
776 uint64_t addr, size;
778 addr = region->value->address;
779 size = region->value->size;
781 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
783 if (!strcmp(region->value->type, "io")) {
784 monitor_printf(mon, "I/O at 0x%04" PRIx64
785 " [0x%04" PRIx64 "].\n",
786 addr, addr + size - 1);
787 } else {
788 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
789 " [0x%08" PRIx64 "].\n",
790 region->value->mem_type_64 ? 64 : 32,
791 region->value->prefetch ? " prefetchable" : "",
792 addr, addr + size - 1);
796 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
798 if (dev->has_pci_bridge) {
799 if (dev->pci_bridge->has_devices) {
800 PciDeviceInfoList *cdev;
801 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
802 hmp_info_pci_device(mon, cdev->value);
808 static int hmp_info_pic_foreach(Object *obj, void *opaque)
810 InterruptStatsProvider *intc;
811 InterruptStatsProviderClass *k;
812 Monitor *mon = opaque;
814 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
815 intc = INTERRUPT_STATS_PROVIDER(obj);
816 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
817 if (k->print_info) {
818 k->print_info(intc, mon);
819 } else {
820 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
821 object_get_typename(obj));
825 return 0;
828 void hmp_info_pic(Monitor *mon, const QDict *qdict)
830 object_child_foreach_recursive(object_get_root(),
831 hmp_info_pic_foreach, mon);
834 void hmp_info_pci(Monitor *mon, const QDict *qdict)
836 PciInfoList *info_list, *info;
837 Error *err = NULL;
839 info_list = qmp_query_pci(&err);
840 if (err) {
841 monitor_printf(mon, "PCI devices not supported\n");
842 error_free(err);
843 return;
846 for (info = info_list; info; info = info->next) {
847 PciDeviceInfoList *dev;
849 for (dev = info->value->devices; dev; dev = dev->next) {
850 hmp_info_pci_device(mon, dev->value);
854 qapi_free_PciInfoList(info_list);
857 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
859 #ifdef CONFIG_TPM
860 TPMInfoList *info_list, *info;
861 Error *err = NULL;
862 unsigned int c = 0;
863 TPMPassthroughOptions *tpo;
864 TPMEmulatorOptions *teo;
866 info_list = qmp_query_tpm(&err);
867 if (err) {
868 monitor_printf(mon, "TPM device not supported\n");
869 error_free(err);
870 return;
873 if (info_list) {
874 monitor_printf(mon, "TPM device:\n");
877 for (info = info_list; info; info = info->next) {
878 TPMInfo *ti = info->value;
879 monitor_printf(mon, " tpm%d: model=%s\n",
880 c, TpmModel_str(ti->model));
882 monitor_printf(mon, " \\ %s: type=%s",
883 ti->id, TpmType_str(ti->options->type));
885 switch (ti->options->type) {
886 case TPM_TYPE_PASSTHROUGH:
887 tpo = ti->options->u.passthrough.data;
888 monitor_printf(mon, "%s%s%s%s",
889 tpo->has_path ? ",path=" : "",
890 tpo->has_path ? tpo->path : "",
891 tpo->has_cancel_path ? ",cancel-path=" : "",
892 tpo->has_cancel_path ? tpo->cancel_path : "");
893 break;
894 case TPM_TYPE_EMULATOR:
895 teo = ti->options->u.emulator.data;
896 monitor_printf(mon, ",chardev=%s", teo->chardev);
897 break;
898 case TPM_TYPE__MAX:
899 break;
901 monitor_printf(mon, "\n");
902 c++;
904 qapi_free_TPMInfoList(info_list);
905 #else
906 monitor_printf(mon, "TPM device not supported\n");
907 #endif /* CONFIG_TPM */
910 void hmp_quit(Monitor *mon, const QDict *qdict)
912 monitor_suspend(mon);
913 qmp_quit(NULL);
916 void hmp_stop(Monitor *mon, const QDict *qdict)
918 qmp_stop(NULL);
921 void hmp_sync_profile(Monitor *mon, const QDict *qdict)
923 const char *op = qdict_get_try_str(qdict, "op");
925 if (op == NULL) {
926 bool on = qsp_is_enabled();
928 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off");
929 return;
931 if (!strcmp(op, "on")) {
932 qsp_enable();
933 } else if (!strcmp(op, "off")) {
934 qsp_disable();
935 } else if (!strcmp(op, "reset")) {
936 qsp_reset();
937 } else {
938 Error *err = NULL;
940 error_setg(&err, QERR_INVALID_PARAMETER, op);
941 hmp_handle_error(mon, err);
945 void hmp_system_reset(Monitor *mon, const QDict *qdict)
947 qmp_system_reset(NULL);
950 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
952 qmp_system_powerdown(NULL);
955 void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
957 Error *err = NULL;
959 qmp_x_exit_preconfig(&err);
960 hmp_handle_error(mon, err);
963 void hmp_cpu(Monitor *mon, const QDict *qdict)
965 int64_t cpu_index;
967 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
968 use it are converted to the QAPI */
969 cpu_index = qdict_get_int(qdict, "index");
970 if (monitor_set_cpu(mon, cpu_index) < 0) {
971 monitor_printf(mon, "invalid CPU index\n");
975 void hmp_memsave(Monitor *mon, const QDict *qdict)
977 uint32_t size = qdict_get_int(qdict, "size");
978 const char *filename = qdict_get_str(qdict, "filename");
979 uint64_t addr = qdict_get_int(qdict, "val");
980 Error *err = NULL;
981 int cpu_index = monitor_get_cpu_index(mon);
983 if (cpu_index < 0) {
984 monitor_printf(mon, "No CPU available\n");
985 return;
988 qmp_memsave(addr, size, filename, true, cpu_index, &err);
989 hmp_handle_error(mon, err);
992 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
994 uint32_t size = qdict_get_int(qdict, "size");
995 const char *filename = qdict_get_str(qdict, "filename");
996 uint64_t addr = qdict_get_int(qdict, "val");
997 Error *err = NULL;
999 qmp_pmemsave(addr, size, filename, &err);
1000 hmp_handle_error(mon, err);
1003 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1005 const char *chardev = qdict_get_str(qdict, "device");
1006 const char *data = qdict_get_str(qdict, "data");
1007 Error *err = NULL;
1009 qmp_ringbuf_write(chardev, data, false, 0, &err);
1011 hmp_handle_error(mon, err);
1014 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
1016 uint32_t size = qdict_get_int(qdict, "size");
1017 const char *chardev = qdict_get_str(qdict, "device");
1018 char *data;
1019 Error *err = NULL;
1020 int i;
1022 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1023 if (hmp_handle_error(mon, err)) {
1024 return;
1027 for (i = 0; data[i]; i++) {
1028 unsigned char ch = data[i];
1030 if (ch == '\\') {
1031 monitor_printf(mon, "\\\\");
1032 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1033 monitor_printf(mon, "\\u%04X", ch);
1034 } else {
1035 monitor_printf(mon, "%c", ch);
1039 monitor_printf(mon, "\n");
1040 g_free(data);
1043 void hmp_cont(Monitor *mon, const QDict *qdict)
1045 Error *err = NULL;
1047 qmp_cont(&err);
1048 hmp_handle_error(mon, err);
1051 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1053 Error *err = NULL;
1055 qmp_system_wakeup(&err);
1056 hmp_handle_error(mon, err);
1059 void hmp_nmi(Monitor *mon, const QDict *qdict)
1061 Error *err = NULL;
1063 qmp_inject_nmi(&err);
1064 hmp_handle_error(mon, err);
1067 void hmp_set_link(Monitor *mon, const QDict *qdict)
1069 const char *name = qdict_get_str(qdict, "name");
1070 bool up = qdict_get_bool(qdict, "up");
1071 Error *err = NULL;
1073 qmp_set_link(name, up, &err);
1074 hmp_handle_error(mon, err);
1077 void hmp_balloon(Monitor *mon, const QDict *qdict)
1079 int64_t value = qdict_get_int(qdict, "value");
1080 Error *err = NULL;
1082 qmp_balloon(value, &err);
1083 hmp_handle_error(mon, err);
1086 void hmp_loadvm(Monitor *mon, const QDict *qdict)
1088 int saved_vm_running = runstate_is_running();
1089 const char *name = qdict_get_str(qdict, "name");
1090 Error *err = NULL;
1092 vm_stop(RUN_STATE_RESTORE_VM);
1094 if (load_snapshot(name, NULL, false, NULL, &err) && saved_vm_running) {
1095 vm_start();
1097 hmp_handle_error(mon, err);
1100 void hmp_savevm(Monitor *mon, const QDict *qdict)
1102 Error *err = NULL;
1104 save_snapshot(qdict_get_try_str(qdict, "name"),
1105 true, NULL, false, NULL, &err);
1106 hmp_handle_error(mon, err);
1109 void hmp_delvm(Monitor *mon, const QDict *qdict)
1111 Error *err = NULL;
1112 const char *name = qdict_get_str(qdict, "name");
1114 delete_snapshot(name, false, NULL, &err);
1115 hmp_handle_error(mon, err);
1118 void hmp_announce_self(Monitor *mon, const QDict *qdict)
1120 const char *interfaces_str = qdict_get_try_str(qdict, "interfaces");
1121 const char *id = qdict_get_try_str(qdict, "id");
1122 AnnounceParameters *params = QAPI_CLONE(AnnounceParameters,
1123 migrate_announce_params());
1125 qapi_free_strList(params->interfaces);
1126 params->interfaces = strList_from_comma_list(interfaces_str);
1127 params->has_interfaces = params->interfaces != NULL;
1128 params->id = g_strdup(id);
1129 params->has_id = !!params->id;
1130 qmp_announce_self(params, NULL);
1131 qapi_free_AnnounceParameters(params);
1134 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1136 qmp_migrate_cancel(NULL);
1139 void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1141 Error *err = NULL;
1142 const char *state = qdict_get_str(qdict, "state");
1143 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1145 if (val >= 0) {
1146 qmp_migrate_continue(val, &err);
1149 hmp_handle_error(mon, err);
1152 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1154 Error *err = NULL;
1155 const char *uri = qdict_get_str(qdict, "uri");
1157 qmp_migrate_incoming(uri, &err);
1159 hmp_handle_error(mon, err);
1162 void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
1164 Error *err = NULL;
1165 const char *uri = qdict_get_str(qdict, "uri");
1167 qmp_migrate_recover(uri, &err);
1169 hmp_handle_error(mon, err);
1172 void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
1174 Error *err = NULL;
1176 qmp_migrate_pause(&err);
1178 hmp_handle_error(mon, err);
1182 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1184 const char *cap = qdict_get_str(qdict, "capability");
1185 bool state = qdict_get_bool(qdict, "state");
1186 Error *err = NULL;
1187 MigrationCapabilityStatusList *caps = NULL;
1188 MigrationCapabilityStatus *value;
1189 int val;
1191 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
1192 if (val < 0) {
1193 goto end;
1196 value = g_malloc0(sizeof(*value));
1197 value->capability = val;
1198 value->state = state;
1199 QAPI_LIST_PREPEND(caps, value);
1200 qmp_migrate_set_capabilities(caps, &err);
1201 qapi_free_MigrationCapabilityStatusList(caps);
1203 end:
1204 hmp_handle_error(mon, err);
1207 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1209 const char *param = qdict_get_str(qdict, "parameter");
1210 const char *valuestr = qdict_get_str(qdict, "value");
1211 Visitor *v = string_input_visitor_new(valuestr);
1212 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
1213 uint64_t valuebw = 0;
1214 uint64_t cache_size;
1215 Error *err = NULL;
1216 int val, ret;
1218 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
1219 if (val < 0) {
1220 goto cleanup;
1223 switch (val) {
1224 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1225 p->has_compress_level = true;
1226 visit_type_uint8(v, param, &p->compress_level, &err);
1227 break;
1228 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1229 p->has_compress_threads = true;
1230 visit_type_uint8(v, param, &p->compress_threads, &err);
1231 break;
1232 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD:
1233 p->has_compress_wait_thread = true;
1234 visit_type_bool(v, param, &p->compress_wait_thread, &err);
1235 break;
1236 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1237 p->has_decompress_threads = true;
1238 visit_type_uint8(v, param, &p->decompress_threads, &err);
1239 break;
1240 case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD:
1241 p->has_throttle_trigger_threshold = true;
1242 visit_type_uint8(v, param, &p->throttle_trigger_threshold, &err);
1243 break;
1244 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1245 p->has_cpu_throttle_initial = true;
1246 visit_type_uint8(v, param, &p->cpu_throttle_initial, &err);
1247 break;
1248 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1249 p->has_cpu_throttle_increment = true;
1250 visit_type_uint8(v, param, &p->cpu_throttle_increment, &err);
1251 break;
1252 case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW:
1253 p->has_cpu_throttle_tailslow = true;
1254 visit_type_bool(v, param, &p->cpu_throttle_tailslow, &err);
1255 break;
1256 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE:
1257 p->has_max_cpu_throttle = true;
1258 visit_type_uint8(v, param, &p->max_cpu_throttle, &err);
1259 break;
1260 case MIGRATION_PARAMETER_TLS_CREDS:
1261 p->has_tls_creds = true;
1262 p->tls_creds = g_new0(StrOrNull, 1);
1263 p->tls_creds->type = QTYPE_QSTRING;
1264 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1265 break;
1266 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1267 p->has_tls_hostname = true;
1268 p->tls_hostname = g_new0(StrOrNull, 1);
1269 p->tls_hostname->type = QTYPE_QSTRING;
1270 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1271 break;
1272 case MIGRATION_PARAMETER_TLS_AUTHZ:
1273 p->has_tls_authz = true;
1274 p->tls_authz = g_new0(StrOrNull, 1);
1275 p->tls_authz->type = QTYPE_QSTRING;
1276 visit_type_str(v, param, &p->tls_authz->u.s, &err);
1277 break;
1278 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1279 p->has_max_bandwidth = true;
1281 * Can't use visit_type_size() here, because it
1282 * defaults to Bytes rather than Mebibytes.
1284 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1285 if (ret < 0 || valuebw > INT64_MAX
1286 || (size_t)valuebw != valuebw) {
1287 error_setg(&err, "Invalid size %s", valuestr);
1288 break;
1290 p->max_bandwidth = valuebw;
1291 break;
1292 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1293 p->has_downtime_limit = true;
1294 visit_type_size(v, param, &p->downtime_limit, &err);
1295 break;
1296 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1297 p->has_x_checkpoint_delay = true;
1298 visit_type_uint32(v, param, &p->x_checkpoint_delay, &err);
1299 break;
1300 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1301 p->has_block_incremental = true;
1302 visit_type_bool(v, param, &p->block_incremental, &err);
1303 break;
1304 case MIGRATION_PARAMETER_MULTIFD_CHANNELS:
1305 p->has_multifd_channels = true;
1306 visit_type_uint8(v, param, &p->multifd_channels, &err);
1307 break;
1308 case MIGRATION_PARAMETER_MULTIFD_COMPRESSION:
1309 p->has_multifd_compression = true;
1310 visit_type_MultiFDCompression(v, param, &p->multifd_compression,
1311 &err);
1312 break;
1313 case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL:
1314 p->has_multifd_zlib_level = true;
1315 visit_type_uint8(v, param, &p->multifd_zlib_level, &err);
1316 break;
1317 case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL:
1318 p->has_multifd_zstd_level = true;
1319 visit_type_uint8(v, param, &p->multifd_zstd_level, &err);
1320 break;
1321 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1322 p->has_xbzrle_cache_size = true;
1323 if (!visit_type_size(v, param, &cache_size, &err)) {
1324 break;
1326 if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) {
1327 error_setg(&err, "Invalid size %s", valuestr);
1328 break;
1330 p->xbzrle_cache_size = cache_size;
1331 break;
1332 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH:
1333 p->has_max_postcopy_bandwidth = true;
1334 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err);
1335 break;
1336 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL:
1337 p->has_announce_initial = true;
1338 visit_type_size(v, param, &p->announce_initial, &err);
1339 break;
1340 case MIGRATION_PARAMETER_ANNOUNCE_MAX:
1341 p->has_announce_max = true;
1342 visit_type_size(v, param, &p->announce_max, &err);
1343 break;
1344 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS:
1345 p->has_announce_rounds = true;
1346 visit_type_size(v, param, &p->announce_rounds, &err);
1347 break;
1348 case MIGRATION_PARAMETER_ANNOUNCE_STEP:
1349 p->has_announce_step = true;
1350 visit_type_size(v, param, &p->announce_step, &err);
1351 break;
1352 case MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING:
1353 error_setg(&err, "The block-bitmap-mapping parameter can only be set "
1354 "through QMP");
1355 break;
1356 default:
1357 assert(0);
1360 if (err) {
1361 goto cleanup;
1364 qmp_migrate_set_parameters(p, &err);
1366 cleanup:
1367 qapi_free_MigrateSetParameters(p);
1368 visit_free(v);
1369 hmp_handle_error(mon, err);
1372 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1374 Error *err = NULL;
1375 const char *protocol = qdict_get_str(qdict, "protocol");
1376 const char *hostname = qdict_get_str(qdict, "hostname");
1377 bool has_port = qdict_haskey(qdict, "port");
1378 int port = qdict_get_try_int(qdict, "port", -1);
1379 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1380 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1381 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1383 qmp_client_migrate_info(protocol, hostname,
1384 has_port, port, has_tls_port, tls_port,
1385 !!cert_subject, cert_subject, &err);
1386 hmp_handle_error(mon, err);
1389 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1391 Error *err = NULL;
1392 qmp_migrate_start_postcopy(&err);
1393 hmp_handle_error(mon, err);
1396 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1398 Error *err = NULL;
1400 qmp_x_colo_lost_heartbeat(&err);
1401 hmp_handle_error(mon, err);
1404 void hmp_set_password(Monitor *mon, const QDict *qdict)
1406 const char *protocol = qdict_get_str(qdict, "protocol");
1407 const char *password = qdict_get_str(qdict, "password");
1408 const char *display = qdict_get_try_str(qdict, "display");
1409 const char *connected = qdict_get_try_str(qdict, "connected");
1410 Error *err = NULL;
1412 SetPasswordOptions opts = {
1413 .password = (char *)password,
1414 .has_connected = !!connected,
1417 opts.connected = qapi_enum_parse(&SetPasswordAction_lookup, connected,
1418 SET_PASSWORD_ACTION_KEEP, &err);
1419 if (err) {
1420 goto out;
1423 opts.protocol = qapi_enum_parse(&DisplayProtocol_lookup, protocol,
1424 DISPLAY_PROTOCOL_VNC, &err);
1425 if (err) {
1426 goto out;
1429 if (opts.protocol == DISPLAY_PROTOCOL_VNC) {
1430 opts.u.vnc.has_display = !!display;
1431 opts.u.vnc.display = (char *)display;
1434 qmp_set_password(&opts, &err);
1436 out:
1437 hmp_handle_error(mon, err);
1440 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1442 const char *protocol = qdict_get_str(qdict, "protocol");
1443 const char *whenstr = qdict_get_str(qdict, "time");
1444 const char *display = qdict_get_try_str(qdict, "display");
1445 Error *err = NULL;
1447 ExpirePasswordOptions opts = {
1448 .time = (char *)whenstr,
1451 opts.protocol = qapi_enum_parse(&DisplayProtocol_lookup, protocol,
1452 DISPLAY_PROTOCOL_VNC, &err);
1453 if (err) {
1454 goto out;
1457 if (opts.protocol == DISPLAY_PROTOCOL_VNC) {
1458 opts.u.vnc.has_display = !!display;
1459 opts.u.vnc.display = (char *)display;
1462 qmp_expire_password(&opts, &err);
1464 out:
1465 hmp_handle_error(mon, err);
1469 #ifdef CONFIG_VNC
1470 static void hmp_change_read_arg(void *opaque, const char *password,
1471 void *readline_opaque)
1473 qmp_change_vnc_password(password, NULL);
1474 monitor_read_command(opaque, 1);
1476 #endif
1478 void hmp_change(Monitor *mon, const QDict *qdict)
1480 const char *device = qdict_get_str(qdict, "device");
1481 const char *target = qdict_get_str(qdict, "target");
1482 const char *arg = qdict_get_try_str(qdict, "arg");
1483 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1484 bool force = qdict_get_try_bool(qdict, "force", false);
1485 BlockdevChangeReadOnlyMode read_only_mode = 0;
1486 Error *err = NULL;
1488 #ifdef CONFIG_VNC
1489 if (strcmp(device, "vnc") == 0) {
1490 if (read_only) {
1491 monitor_printf(mon,
1492 "Parameter 'read-only-mode' is invalid for VNC\n");
1493 return;
1495 if (strcmp(target, "passwd") == 0 ||
1496 strcmp(target, "password") == 0) {
1497 if (!arg) {
1498 MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
1499 monitor_read_password(hmp_mon, hmp_change_read_arg, NULL);
1500 return;
1501 } else {
1502 qmp_change_vnc_password(arg, &err);
1504 } else {
1505 monitor_printf(mon, "Expected 'password' after 'vnc'\n");
1507 } else
1508 #endif
1510 if (read_only) {
1511 read_only_mode =
1512 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
1513 read_only,
1514 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1515 if (err) {
1516 goto end;
1520 qmp_blockdev_change_medium(true, device, false, NULL, target,
1521 !!arg, arg, true, force,
1522 !!read_only, read_only_mode,
1523 &err);
1526 end:
1527 hmp_handle_error(mon, err);
1530 typedef struct HMPMigrationStatus {
1531 QEMUTimer *timer;
1532 Monitor *mon;
1533 bool is_block_migration;
1534 } HMPMigrationStatus;
1536 static void hmp_migrate_status_cb(void *opaque)
1538 HMPMigrationStatus *status = opaque;
1539 MigrationInfo *info;
1541 info = qmp_query_migrate(NULL);
1542 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1543 info->status == MIGRATION_STATUS_SETUP) {
1544 if (info->has_disk) {
1545 int progress;
1547 if (info->disk->remaining) {
1548 progress = info->disk->transferred * 100 / info->disk->total;
1549 } else {
1550 progress = 100;
1553 monitor_printf(status->mon, "Completed %d %%\r", progress);
1554 monitor_flush(status->mon);
1557 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1558 } else {
1559 if (status->is_block_migration) {
1560 monitor_printf(status->mon, "\n");
1562 if (info->has_error_desc) {
1563 error_report("%s", info->error_desc);
1565 monitor_resume(status->mon);
1566 timer_free(status->timer);
1567 g_free(status);
1570 qapi_free_MigrationInfo(info);
1573 void hmp_migrate(Monitor *mon, const QDict *qdict)
1575 bool detach = qdict_get_try_bool(qdict, "detach", false);
1576 bool blk = qdict_get_try_bool(qdict, "blk", false);
1577 bool inc = qdict_get_try_bool(qdict, "inc", false);
1578 bool resume = qdict_get_try_bool(qdict, "resume", false);
1579 const char *uri = qdict_get_str(qdict, "uri");
1580 Error *err = NULL;
1582 qmp_migrate(uri, !!blk, blk, !!inc, inc,
1583 false, false, true, resume, &err);
1584 if (hmp_handle_error(mon, err)) {
1585 return;
1588 if (!detach) {
1589 HMPMigrationStatus *status;
1591 if (monitor_suspend(mon) < 0) {
1592 monitor_printf(mon, "terminal does not allow synchronous "
1593 "migration, continuing detached\n");
1594 return;
1597 status = g_malloc0(sizeof(*status));
1598 status->mon = mon;
1599 status->is_block_migration = blk || inc;
1600 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1601 status);
1602 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1606 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1608 Error *err = NULL;
1609 QemuOpts *opts;
1610 const char *type = qdict_get_try_str(qdict, "type");
1612 if (type && is_help_option(type)) {
1613 show_netdevs();
1614 return;
1616 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1617 if (err) {
1618 goto out;
1621 netdev_add(opts, &err);
1622 if (err) {
1623 qemu_opts_del(opts);
1626 out:
1627 hmp_handle_error(mon, err);
1630 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1632 const char *id = qdict_get_str(qdict, "id");
1633 Error *err = NULL;
1635 qmp_netdev_del(id, &err);
1636 hmp_handle_error(mon, err);
1639 void hmp_object_add(Monitor *mon, const QDict *qdict)
1641 const char *options = qdict_get_str(qdict, "object");
1642 Error *err = NULL;
1644 user_creatable_add_from_str(options, &err);
1645 hmp_handle_error(mon, err);
1648 void hmp_getfd(Monitor *mon, const QDict *qdict)
1650 const char *fdname = qdict_get_str(qdict, "fdname");
1651 Error *err = NULL;
1653 qmp_getfd(fdname, &err);
1654 hmp_handle_error(mon, err);
1657 void hmp_closefd(Monitor *mon, const QDict *qdict)
1659 const char *fdname = qdict_get_str(qdict, "fdname");
1660 Error *err = NULL;
1662 qmp_closefd(fdname, &err);
1663 hmp_handle_error(mon, err);
1666 void hmp_sendkey(Monitor *mon, const QDict *qdict)
1668 const char *keys = qdict_get_str(qdict, "keys");
1669 KeyValue *v = NULL;
1670 KeyValueList *head = NULL, **tail = &head;
1671 int has_hold_time = qdict_haskey(qdict, "hold-time");
1672 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1673 Error *err = NULL;
1674 const char *separator;
1675 int keyname_len;
1677 while (1) {
1678 separator = qemu_strchrnul(keys, '-');
1679 keyname_len = separator - keys;
1681 /* Be compatible with old interface, convert user inputted "<" */
1682 if (keys[0] == '<' && keyname_len == 1) {
1683 keys = "less";
1684 keyname_len = 4;
1687 v = g_malloc0(sizeof(*v));
1689 if (strstart(keys, "0x", NULL)) {
1690 char *endp;
1691 int value = strtoul(keys, &endp, 0);
1692 assert(endp <= keys + keyname_len);
1693 if (endp != keys + keyname_len) {
1694 goto err_out;
1696 v->type = KEY_VALUE_KIND_NUMBER;
1697 v->u.number.data = value;
1698 } else {
1699 int idx = index_from_key(keys, keyname_len);
1700 if (idx == Q_KEY_CODE__MAX) {
1701 goto err_out;
1703 v->type = KEY_VALUE_KIND_QCODE;
1704 v->u.qcode.data = idx;
1706 QAPI_LIST_APPEND(tail, v);
1707 v = NULL;
1709 if (!*separator) {
1710 break;
1712 keys = separator + 1;
1715 qmp_send_key(head, has_hold_time, hold_time, &err);
1716 hmp_handle_error(mon, err);
1718 out:
1719 qapi_free_KeyValue(v);
1720 qapi_free_KeyValueList(head);
1721 return;
1723 err_out:
1724 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
1725 goto out;
1728 void coroutine_fn
1729 hmp_screendump(Monitor *mon, const QDict *qdict)
1731 const char *filename = qdict_get_str(qdict, "filename");
1732 const char *id = qdict_get_try_str(qdict, "device");
1733 int64_t head = qdict_get_try_int(qdict, "head", 0);
1734 const char *input_format = qdict_get_try_str(qdict, "format");
1735 Error *err = NULL;
1736 ImageFormat format;
1738 format = qapi_enum_parse(&ImageFormat_lookup, input_format,
1739 IMAGE_FORMAT_PPM, &err);
1740 if (err) {
1741 goto end;
1744 qmp_screendump(filename, id != NULL, id, id != NULL, head,
1745 input_format != NULL, format, &err);
1746 end:
1747 hmp_handle_error(mon, err);
1750 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1752 const char *args = qdict_get_str(qdict, "args");
1753 Error *err = NULL;
1754 QemuOpts *opts;
1756 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
1757 if (opts == NULL) {
1758 error_setg(&err, "Parsing chardev args failed");
1759 } else {
1760 qemu_chr_new_from_opts(opts, NULL, &err);
1761 qemu_opts_del(opts);
1763 hmp_handle_error(mon, err);
1766 void hmp_chardev_change(Monitor *mon, const QDict *qdict)
1768 const char *args = qdict_get_str(qdict, "args");
1769 const char *id;
1770 Error *err = NULL;
1771 ChardevBackend *backend = NULL;
1772 ChardevReturn *ret = NULL;
1773 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
1774 true);
1775 if (!opts) {
1776 error_setg(&err, "Parsing chardev args failed");
1777 goto end;
1780 id = qdict_get_str(qdict, "id");
1781 if (qemu_opts_id(opts)) {
1782 error_setg(&err, "Unexpected 'id' parameter");
1783 goto end;
1786 backend = qemu_chr_parse_opts(opts, &err);
1787 if (!backend) {
1788 goto end;
1791 ret = qmp_chardev_change(id, backend, &err);
1793 end:
1794 qapi_free_ChardevReturn(ret);
1795 qapi_free_ChardevBackend(backend);
1796 qemu_opts_del(opts);
1797 hmp_handle_error(mon, err);
1800 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1802 Error *local_err = NULL;
1804 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1805 hmp_handle_error(mon, local_err);
1808 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
1810 Error *local_err = NULL;
1812 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
1813 hmp_handle_error(mon, local_err);
1816 void hmp_object_del(Monitor *mon, const QDict *qdict)
1818 const char *id = qdict_get_str(qdict, "id");
1819 Error *err = NULL;
1821 user_creatable_del(id, &err);
1822 hmp_handle_error(mon, err);
1825 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
1827 Error *err = NULL;
1828 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
1829 MemoryDeviceInfoList *info;
1830 VirtioPMEMDeviceInfo *vpi;
1831 VirtioMEMDeviceInfo *vmi;
1832 MemoryDeviceInfo *value;
1833 PCDIMMDeviceInfo *di;
1834 SgxEPCDeviceInfo *se;
1836 for (info = info_list; info; info = info->next) {
1837 value = info->value;
1839 if (value) {
1840 switch (value->type) {
1841 case MEMORY_DEVICE_INFO_KIND_DIMM:
1842 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
1843 di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ?
1844 value->u.dimm.data : value->u.nvdimm.data;
1845 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1846 MemoryDeviceInfoKind_str(value->type),
1847 di->id ? di->id : "");
1848 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
1849 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
1850 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
1851 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
1852 monitor_printf(mon, " memdev: %s\n", di->memdev);
1853 monitor_printf(mon, " hotplugged: %s\n",
1854 di->hotplugged ? "true" : "false");
1855 monitor_printf(mon, " hotpluggable: %s\n",
1856 di->hotpluggable ? "true" : "false");
1857 break;
1858 case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM:
1859 vpi = value->u.virtio_pmem.data;
1860 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1861 MemoryDeviceInfoKind_str(value->type),
1862 vpi->id ? vpi->id : "");
1863 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->memaddr);
1864 monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size);
1865 monitor_printf(mon, " memdev: %s\n", vpi->memdev);
1866 break;
1867 case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM:
1868 vmi = value->u.virtio_mem.data;
1869 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1870 MemoryDeviceInfoKind_str(value->type),
1871 vmi->id ? vmi->id : "");
1872 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vmi->memaddr);
1873 monitor_printf(mon, " node: %" PRId64 "\n", vmi->node);
1874 monitor_printf(mon, " requested-size: %" PRIu64 "\n",
1875 vmi->requested_size);
1876 monitor_printf(mon, " size: %" PRIu64 "\n", vmi->size);
1877 monitor_printf(mon, " max-size: %" PRIu64 "\n", vmi->max_size);
1878 monitor_printf(mon, " block-size: %" PRIu64 "\n",
1879 vmi->block_size);
1880 monitor_printf(mon, " memdev: %s\n", vmi->memdev);
1881 break;
1882 case MEMORY_DEVICE_INFO_KIND_SGX_EPC:
1883 se = value->u.sgx_epc.data;
1884 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1885 MemoryDeviceInfoKind_str(value->type),
1886 se->id ? se->id : "");
1887 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", se->memaddr);
1888 monitor_printf(mon, " size: %" PRIu64 "\n", se->size);
1889 monitor_printf(mon, " node: %" PRId64 "\n", se->node);
1890 monitor_printf(mon, " memdev: %s\n", se->memdev);
1891 break;
1892 default:
1893 g_assert_not_reached();
1898 qapi_free_MemoryDeviceInfoList(info_list);
1899 hmp_handle_error(mon, err);
1902 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
1904 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
1905 IOThreadInfoList *info;
1906 IOThreadInfo *value;
1908 for (info = info_list; info; info = info->next) {
1909 value = info->value;
1910 monitor_printf(mon, "%s:\n", value->id);
1911 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
1912 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
1913 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
1914 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
1915 monitor_printf(mon, " aio-max-batch=%" PRId64 "\n",
1916 value->aio_max_batch);
1919 qapi_free_IOThreadInfoList(info_list);
1922 void hmp_rocker(Monitor *mon, const QDict *qdict)
1924 const char *name = qdict_get_str(qdict, "name");
1925 RockerSwitch *rocker;
1926 Error *err = NULL;
1928 rocker = qmp_query_rocker(name, &err);
1929 if (hmp_handle_error(mon, err)) {
1930 return;
1933 monitor_printf(mon, "name: %s\n", rocker->name);
1934 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
1935 monitor_printf(mon, "ports: %d\n", rocker->ports);
1937 qapi_free_RockerSwitch(rocker);
1940 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
1942 RockerPortList *list, *port;
1943 const char *name = qdict_get_str(qdict, "name");
1944 Error *err = NULL;
1946 list = qmp_query_rocker_ports(name, &err);
1947 if (hmp_handle_error(mon, err)) {
1948 return;
1951 monitor_printf(mon, " ena/ speed/ auto\n");
1952 monitor_printf(mon, " port link duplex neg?\n");
1954 for (port = list; port; port = port->next) {
1955 monitor_printf(mon, "%10s %-4s %-3s %2s %s\n",
1956 port->value->name,
1957 port->value->enabled ? port->value->link_up ?
1958 "up" : "down" : "!ena",
1959 port->value->speed == 10000 ? "10G" : "??",
1960 port->value->duplex ? "FD" : "HD",
1961 port->value->autoneg ? "Yes" : "No");
1964 qapi_free_RockerPortList(list);
1967 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
1969 RockerOfDpaFlowList *list, *info;
1970 const char *name = qdict_get_str(qdict, "name");
1971 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
1972 Error *err = NULL;
1974 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
1975 if (hmp_handle_error(mon, err)) {
1976 return;
1979 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
1981 for (info = list; info; info = info->next) {
1982 RockerOfDpaFlow *flow = info->value;
1983 RockerOfDpaFlowKey *key = flow->key;
1984 RockerOfDpaFlowMask *mask = flow->mask;
1985 RockerOfDpaFlowAction *action = flow->action;
1987 if (flow->hits) {
1988 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
1989 key->priority, key->tbl_id, flow->hits);
1990 } else {
1991 monitor_printf(mon, "%-4d %-3d ",
1992 key->priority, key->tbl_id);
1995 if (key->has_in_pport) {
1996 monitor_printf(mon, " pport %d", key->in_pport);
1997 if (mask->has_in_pport) {
1998 monitor_printf(mon, "(0x%x)", mask->in_pport);
2002 if (key->has_vlan_id) {
2003 monitor_printf(mon, " vlan %d",
2004 key->vlan_id & VLAN_VID_MASK);
2005 if (mask->has_vlan_id) {
2006 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2010 if (key->has_tunnel_id) {
2011 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2012 if (mask->has_tunnel_id) {
2013 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2017 if (key->has_eth_type) {
2018 switch (key->eth_type) {
2019 case 0x0806:
2020 monitor_printf(mon, " ARP");
2021 break;
2022 case 0x0800:
2023 monitor_printf(mon, " IP");
2024 break;
2025 case 0x86dd:
2026 monitor_printf(mon, " IPv6");
2027 break;
2028 case 0x8809:
2029 monitor_printf(mon, " LACP");
2030 break;
2031 case 0x88cc:
2032 monitor_printf(mon, " LLDP");
2033 break;
2034 default:
2035 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2036 break;
2040 if (key->has_eth_src) {
2041 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2042 (mask->has_eth_src) &&
2043 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2044 monitor_printf(mon, " src <any mcast/bcast>");
2045 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2046 (mask->has_eth_src) &&
2047 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2048 monitor_printf(mon, " src <any ucast>");
2049 } else {
2050 monitor_printf(mon, " src %s", key->eth_src);
2051 if (mask->has_eth_src) {
2052 monitor_printf(mon, "(%s)", mask->eth_src);
2057 if (key->has_eth_dst) {
2058 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2059 (mask->has_eth_dst) &&
2060 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2061 monitor_printf(mon, " dst <any mcast/bcast>");
2062 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2063 (mask->has_eth_dst) &&
2064 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2065 monitor_printf(mon, " dst <any ucast>");
2066 } else {
2067 monitor_printf(mon, " dst %s", key->eth_dst);
2068 if (mask->has_eth_dst) {
2069 monitor_printf(mon, "(%s)", mask->eth_dst);
2074 if (key->has_ip_proto) {
2075 monitor_printf(mon, " proto %d", key->ip_proto);
2076 if (mask->has_ip_proto) {
2077 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2081 if (key->has_ip_tos) {
2082 monitor_printf(mon, " TOS %d", key->ip_tos);
2083 if (mask->has_ip_tos) {
2084 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2088 if (key->has_ip_dst) {
2089 monitor_printf(mon, " dst %s", key->ip_dst);
2092 if (action->has_goto_tbl || action->has_group_id ||
2093 action->has_new_vlan_id) {
2094 monitor_printf(mon, " -->");
2097 if (action->has_new_vlan_id) {
2098 monitor_printf(mon, " apply new vlan %d",
2099 ntohs(action->new_vlan_id));
2102 if (action->has_group_id) {
2103 monitor_printf(mon, " write group 0x%08x", action->group_id);
2106 if (action->has_goto_tbl) {
2107 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2110 monitor_printf(mon, "\n");
2113 qapi_free_RockerOfDpaFlowList(list);
2116 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2118 RockerOfDpaGroupList *list, *g;
2119 const char *name = qdict_get_str(qdict, "name");
2120 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2121 Error *err = NULL;
2123 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2124 if (hmp_handle_error(mon, err)) {
2125 return;
2128 monitor_printf(mon, "id (decode) --> buckets\n");
2130 for (g = list; g; g = g->next) {
2131 RockerOfDpaGroup *group = g->value;
2132 bool set = false;
2134 monitor_printf(mon, "0x%08x", group->id);
2136 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2137 group->type == 1 ? "L2 rewrite" :
2138 group->type == 2 ? "L3 unicast" :
2139 group->type == 3 ? "L2 multicast" :
2140 group->type == 4 ? "L2 flood" :
2141 group->type == 5 ? "L3 interface" :
2142 group->type == 6 ? "L3 multicast" :
2143 group->type == 7 ? "L3 ECMP" :
2144 group->type == 8 ? "L2 overlay" :
2145 "unknown");
2147 if (group->has_vlan_id) {
2148 monitor_printf(mon, " vlan %d", group->vlan_id);
2151 if (group->has_pport) {
2152 monitor_printf(mon, " pport %d", group->pport);
2155 if (group->has_index) {
2156 monitor_printf(mon, " index %d", group->index);
2159 monitor_printf(mon, ") -->");
2161 if (group->has_set_vlan_id && group->set_vlan_id) {
2162 set = true;
2163 monitor_printf(mon, " set vlan %d",
2164 group->set_vlan_id & VLAN_VID_MASK);
2167 if (group->has_set_eth_src) {
2168 if (!set) {
2169 set = true;
2170 monitor_printf(mon, " set");
2172 monitor_printf(mon, " src %s", group->set_eth_src);
2175 if (group->has_set_eth_dst) {
2176 if (!set) {
2177 monitor_printf(mon, " set");
2179 monitor_printf(mon, " dst %s", group->set_eth_dst);
2182 if (group->has_ttl_check && group->ttl_check) {
2183 monitor_printf(mon, " check TTL");
2186 if (group->has_group_id && group->group_id) {
2187 monitor_printf(mon, " group id 0x%08x", group->group_id);
2190 if (group->has_pop_vlan && group->pop_vlan) {
2191 monitor_printf(mon, " pop vlan");
2194 if (group->has_out_pport) {
2195 monitor_printf(mon, " out pport %d", group->out_pport);
2198 if (group->has_group_ids) {
2199 struct uint32List *id;
2201 monitor_printf(mon, " groups [");
2202 for (id = group->group_ids; id; id = id->next) {
2203 monitor_printf(mon, "0x%08x", id->value);
2204 if (id->next) {
2205 monitor_printf(mon, ",");
2208 monitor_printf(mon, "]");
2211 monitor_printf(mon, "\n");
2214 qapi_free_RockerOfDpaGroupList(list);
2217 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
2219 Error *err = NULL;
2220 GuidInfo *info = qmp_query_vm_generation_id(&err);
2221 if (info) {
2222 monitor_printf(mon, "%s\n", info->guid);
2224 hmp_handle_error(mon, err);
2225 qapi_free_GuidInfo(info);
2228 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
2230 Error *err = NULL;
2231 MemoryInfo *info = qmp_query_memory_size_summary(&err);
2232 if (info) {
2233 monitor_printf(mon, "base memory: %" PRIu64 "\n",
2234 info->base_memory);
2236 if (info->has_plugged_memory) {
2237 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
2238 info->plugged_memory);
2241 qapi_free_MemoryInfo(info);
2243 hmp_handle_error(mon, err);
2246 static void print_stats_schema_value(Monitor *mon, StatsSchemaValue *value)
2248 const char *unit = NULL;
2249 monitor_printf(mon, " %s (%s%s", value->name, StatsType_str(value->type),
2250 value->has_unit || value->exponent ? ", " : "");
2252 if (value->has_unit) {
2253 if (value->unit == STATS_UNIT_SECONDS) {
2254 unit = "s";
2255 } else if (value->unit == STATS_UNIT_BYTES) {
2256 unit = "B";
2260 if (unit && value->base == 10 &&
2261 value->exponent >= -18 && value->exponent <= 18 &&
2262 value->exponent % 3 == 0) {
2263 monitor_puts(mon, si_prefix(value->exponent));
2264 } else if (unit && value->base == 2 &&
2265 value->exponent >= 0 && value->exponent <= 60 &&
2266 value->exponent % 10 == 0) {
2268 monitor_puts(mon, iec_binary_prefix(value->exponent));
2269 } else if (value->exponent) {
2270 /* Use exponential notation and write the unit's English name */
2271 monitor_printf(mon, "* %d^%d%s",
2272 value->base, value->exponent,
2273 value->has_unit ? " " : "");
2274 unit = NULL;
2277 if (value->has_unit) {
2278 monitor_puts(mon, unit ? unit : StatsUnit_str(value->unit));
2281 /* Print bucket size for linear histograms */
2282 if (value->type == STATS_TYPE_LINEAR_HISTOGRAM && value->has_bucket_size) {
2283 monitor_printf(mon, ", bucket size=%d", value->bucket_size);
2285 monitor_printf(mon, ")");
2288 static StatsSchemaValueList *find_schema_value_list(
2289 StatsSchemaList *list, StatsProvider provider,
2290 StatsTarget target)
2292 StatsSchemaList *node;
2294 for (node = list; node; node = node->next) {
2295 if (node->value->provider == provider &&
2296 node->value->target == target) {
2297 return node->value->stats;
2300 return NULL;
2303 static void print_stats_results(Monitor *mon, StatsTarget target,
2304 bool show_provider,
2305 StatsResult *result,
2306 StatsSchemaList *schema)
2308 /* Find provider schema */
2309 StatsSchemaValueList *schema_value_list =
2310 find_schema_value_list(schema, result->provider, target);
2311 StatsList *stats_list;
2313 if (!schema_value_list) {
2314 monitor_printf(mon, "failed to find schema list for %s\n",
2315 StatsProvider_str(result->provider));
2316 return;
2319 if (show_provider) {
2320 monitor_printf(mon, "provider: %s\n",
2321 StatsProvider_str(result->provider));
2324 for (stats_list = result->stats; stats_list;
2325 stats_list = stats_list->next,
2326 schema_value_list = schema_value_list->next) {
2328 Stats *stats = stats_list->value;
2329 StatsValue *stats_value = stats->value;
2330 StatsSchemaValue *schema_value = schema_value_list->value;
2332 /* Find schema entry */
2333 while (!g_str_equal(stats->name, schema_value->name)) {
2334 if (!schema_value_list->next) {
2335 monitor_printf(mon, "failed to find schema entry for %s\n",
2336 stats->name);
2337 return;
2339 schema_value_list = schema_value_list->next;
2340 schema_value = schema_value_list->value;
2343 print_stats_schema_value(mon, schema_value);
2345 if (stats_value->type == QTYPE_QNUM) {
2346 monitor_printf(mon, ": %" PRId64 "\n", stats_value->u.scalar);
2347 } else if (stats_value->type == QTYPE_QBOOL) {
2348 monitor_printf(mon, ": %s\n", stats_value->u.boolean ? "yes" : "no");
2349 } else if (stats_value->type == QTYPE_QLIST) {
2350 uint64List *list;
2351 int i;
2353 monitor_printf(mon, ": ");
2354 for (list = stats_value->u.list, i = 1;
2355 list;
2356 list = list->next, i++) {
2357 monitor_printf(mon, "[%d]=%" PRId64 " ", i, list->value);
2359 monitor_printf(mon, "\n");
2364 /* Create the StatsFilter that is needed for an "info stats" invocation. */
2365 static StatsFilter *stats_filter(StatsTarget target, const char *names,
2366 int cpu_index, StatsProvider provider)
2368 StatsFilter *filter = g_malloc0(sizeof(*filter));
2369 StatsProvider provider_idx;
2370 StatsRequestList *request_list = NULL;
2372 filter->target = target;
2373 switch (target) {
2374 case STATS_TARGET_VM:
2375 break;
2376 case STATS_TARGET_VCPU:
2378 strList *vcpu_list = NULL;
2379 CPUState *cpu = qemu_get_cpu(cpu_index);
2380 char *canonical_path = object_get_canonical_path(OBJECT(cpu));
2382 QAPI_LIST_PREPEND(vcpu_list, canonical_path);
2383 filter->u.vcpu.has_vcpus = true;
2384 filter->u.vcpu.vcpus = vcpu_list;
2385 break;
2387 default:
2388 break;
2391 if (!names && provider == STATS_PROVIDER__MAX) {
2392 return filter;
2396 * "info stats" can only query either one or all the providers. Querying
2397 * by name, but not by provider, requires the creation of one filter per
2398 * provider.
2400 for (provider_idx = 0; provider_idx < STATS_PROVIDER__MAX; provider_idx++) {
2401 if (provider == STATS_PROVIDER__MAX || provider == provider_idx) {
2402 StatsRequest *request = g_new0(StatsRequest, 1);
2403 request->provider = provider_idx;
2404 if (names && !g_str_equal(names, "*")) {
2405 request->has_names = true;
2406 request->names = strList_from_comma_list(names);
2408 QAPI_LIST_PREPEND(request_list, request);
2412 filter->has_providers = true;
2413 filter->providers = request_list;
2414 return filter;
2417 void hmp_info_stats(Monitor *mon, const QDict *qdict)
2419 const char *target_str = qdict_get_str(qdict, "target");
2420 const char *provider_str = qdict_get_try_str(qdict, "provider");
2421 const char *names = qdict_get_try_str(qdict, "names");
2423 StatsProvider provider = STATS_PROVIDER__MAX;
2424 StatsTarget target;
2425 Error *err = NULL;
2426 g_autoptr(StatsSchemaList) schema = NULL;
2427 g_autoptr(StatsResultList) stats = NULL;
2428 g_autoptr(StatsFilter) filter = NULL;
2429 StatsResultList *entry;
2431 target = qapi_enum_parse(&StatsTarget_lookup, target_str, -1, &err);
2432 if (err) {
2433 monitor_printf(mon, "invalid stats target %s\n", target_str);
2434 goto exit_no_print;
2436 if (provider_str) {
2437 provider = qapi_enum_parse(&StatsProvider_lookup, provider_str, -1, &err);
2438 if (err) {
2439 monitor_printf(mon, "invalid stats provider %s\n", provider_str);
2440 goto exit_no_print;
2444 schema = qmp_query_stats_schemas(provider_str ? true : false,
2445 provider, &err);
2446 if (err) {
2447 goto exit;
2450 switch (target) {
2451 case STATS_TARGET_VM:
2452 filter = stats_filter(target, names, -1, provider);
2453 break;
2454 case STATS_TARGET_VCPU: {}
2455 int cpu_index = monitor_get_cpu_index(mon);
2456 filter = stats_filter(target, names, cpu_index, provider);
2457 break;
2458 default:
2459 abort();
2462 stats = qmp_query_stats(filter, &err);
2463 if (err) {
2464 goto exit;
2466 for (entry = stats; entry; entry = entry->next) {
2467 print_stats_results(mon, target, provider_str == NULL, entry->value, schema);
2470 exit:
2471 if (err) {
2472 monitor_printf(mon, "%s\n", error_get_pretty(err));
2474 exit_no_print:
2475 error_free(err);
2478 static void hmp_virtio_dump_protocols(Monitor *mon,
2479 VhostDeviceProtocols *pcol)
2481 strList *pcol_list = pcol->protocols;
2482 while (pcol_list) {
2483 monitor_printf(mon, "\t%s", pcol_list->value);
2484 pcol_list = pcol_list->next;
2485 if (pcol_list != NULL) {
2486 monitor_printf(mon, ",\n");
2489 monitor_printf(mon, "\n");
2490 if (pcol->has_unknown_protocols) {
2491 monitor_printf(mon, " unknown-protocols(0x%016"PRIx64")\n",
2492 pcol->unknown_protocols);
2496 static void hmp_virtio_dump_status(Monitor *mon,
2497 VirtioDeviceStatus *status)
2499 strList *status_list = status->statuses;
2500 while (status_list) {
2501 monitor_printf(mon, "\t%s", status_list->value);
2502 status_list = status_list->next;
2503 if (status_list != NULL) {
2504 monitor_printf(mon, ",\n");
2507 monitor_printf(mon, "\n");
2508 if (status->has_unknown_statuses) {
2509 monitor_printf(mon, " unknown-statuses(0x%016"PRIx32")\n",
2510 status->unknown_statuses);
2514 static void hmp_virtio_dump_features(Monitor *mon,
2515 VirtioDeviceFeatures *features)
2517 strList *transport_list = features->transports;
2518 while (transport_list) {
2519 monitor_printf(mon, "\t%s", transport_list->value);
2520 transport_list = transport_list->next;
2521 if (transport_list != NULL) {
2522 monitor_printf(mon, ",\n");
2526 monitor_printf(mon, "\n");
2527 strList *list = features->dev_features;
2528 if (list) {
2529 while (list) {
2530 monitor_printf(mon, "\t%s", list->value);
2531 list = list->next;
2532 if (list != NULL) {
2533 monitor_printf(mon, ",\n");
2536 monitor_printf(mon, "\n");
2539 if (features->has_unknown_dev_features) {
2540 monitor_printf(mon, " unknown-features(0x%016"PRIx64")\n",
2541 features->unknown_dev_features);
2545 void hmp_virtio_query(Monitor *mon, const QDict *qdict)
2547 Error *err = NULL;
2548 VirtioInfoList *list = qmp_x_query_virtio(&err);
2549 VirtioInfoList *node;
2551 if (err != NULL) {
2552 hmp_handle_error(mon, err);
2553 return;
2556 if (list == NULL) {
2557 monitor_printf(mon, "No VirtIO devices\n");
2558 return;
2561 node = list;
2562 while (node) {
2563 monitor_printf(mon, "%s [%s]\n", node->value->path,
2564 node->value->name);
2565 node = node->next;
2567 qapi_free_VirtioInfoList(list);
2570 void hmp_virtio_status(Monitor *mon, const QDict *qdict)
2572 Error *err = NULL;
2573 const char *path = qdict_get_try_str(qdict, "path");
2574 VirtioStatus *s = qmp_x_query_virtio_status(path, &err);
2576 if (err != NULL) {
2577 hmp_handle_error(mon, err);
2578 return;
2581 monitor_printf(mon, "%s:\n", path);
2582 monitor_printf(mon, " device_name: %s %s\n",
2583 s->name, s->has_vhost_dev ? "(vhost)" : "");
2584 monitor_printf(mon, " device_id: %d\n", s->device_id);
2585 monitor_printf(mon, " vhost_started: %s\n",
2586 s->vhost_started ? "true" : "false");
2587 monitor_printf(mon, " bus_name: %s\n", s->bus_name);
2588 monitor_printf(mon, " broken: %s\n",
2589 s->broken ? "true" : "false");
2590 monitor_printf(mon, " disabled: %s\n",
2591 s->disabled ? "true" : "false");
2592 monitor_printf(mon, " disable_legacy_check: %s\n",
2593 s->disable_legacy_check ? "true" : "false");
2594 monitor_printf(mon, " started: %s\n",
2595 s->started ? "true" : "false");
2596 monitor_printf(mon, " use_started: %s\n",
2597 s->use_started ? "true" : "false");
2598 monitor_printf(mon, " start_on_kick: %s\n",
2599 s->start_on_kick ? "true" : "false");
2600 monitor_printf(mon, " use_guest_notifier_mask: %s\n",
2601 s->use_guest_notifier_mask ? "true" : "false");
2602 monitor_printf(mon, " vm_running: %s\n",
2603 s->vm_running ? "true" : "false");
2604 monitor_printf(mon, " num_vqs: %"PRId64"\n", s->num_vqs);
2605 monitor_printf(mon, " queue_sel: %d\n",
2606 s->queue_sel);
2607 monitor_printf(mon, " isr: %d\n", s->isr);
2608 monitor_printf(mon, " endianness: %s\n",
2609 s->device_endian);
2610 monitor_printf(mon, " status:\n");
2611 hmp_virtio_dump_status(mon, s->status);
2612 monitor_printf(mon, " Guest features:\n");
2613 hmp_virtio_dump_features(mon, s->guest_features);
2614 monitor_printf(mon, " Host features:\n");
2615 hmp_virtio_dump_features(mon, s->host_features);
2616 monitor_printf(mon, " Backend features:\n");
2617 hmp_virtio_dump_features(mon, s->backend_features);
2619 if (s->has_vhost_dev) {
2620 monitor_printf(mon, " VHost:\n");
2621 monitor_printf(mon, " nvqs: %d\n",
2622 s->vhost_dev->nvqs);
2623 monitor_printf(mon, " vq_index: %"PRId64"\n",
2624 s->vhost_dev->vq_index);
2625 monitor_printf(mon, " max_queues: %"PRId64"\n",
2626 s->vhost_dev->max_queues);
2627 monitor_printf(mon, " n_mem_sections: %"PRId64"\n",
2628 s->vhost_dev->n_mem_sections);
2629 monitor_printf(mon, " n_tmp_sections: %"PRId64"\n",
2630 s->vhost_dev->n_tmp_sections);
2631 monitor_printf(mon, " backend_cap: %"PRId64"\n",
2632 s->vhost_dev->backend_cap);
2633 monitor_printf(mon, " log_enabled: %s\n",
2634 s->vhost_dev->log_enabled ? "true" : "false");
2635 monitor_printf(mon, " log_size: %"PRId64"\n",
2636 s->vhost_dev->log_size);
2637 monitor_printf(mon, " Features:\n");
2638 hmp_virtio_dump_features(mon, s->vhost_dev->features);
2639 monitor_printf(mon, " Acked features:\n");
2640 hmp_virtio_dump_features(mon, s->vhost_dev->acked_features);
2641 monitor_printf(mon, " Backend features:\n");
2642 hmp_virtio_dump_features(mon, s->vhost_dev->backend_features);
2643 monitor_printf(mon, " Protocol features:\n");
2644 hmp_virtio_dump_protocols(mon, s->vhost_dev->protocol_features);
2647 qapi_free_VirtioStatus(s);
2650 void hmp_vhost_queue_status(Monitor *mon, const QDict *qdict)
2652 Error *err = NULL;
2653 const char *path = qdict_get_try_str(qdict, "path");
2654 int queue = qdict_get_int(qdict, "queue");
2655 VirtVhostQueueStatus *s =
2656 qmp_x_query_virtio_vhost_queue_status(path, queue, &err);
2658 if (err != NULL) {
2659 hmp_handle_error(mon, err);
2660 return;
2663 monitor_printf(mon, "%s:\n", path);
2664 monitor_printf(mon, " device_name: %s (vhost)\n",
2665 s->name);
2666 monitor_printf(mon, " kick: %"PRId64"\n", s->kick);
2667 monitor_printf(mon, " call: %"PRId64"\n", s->call);
2668 monitor_printf(mon, " VRing:\n");
2669 monitor_printf(mon, " num: %"PRId64"\n", s->num);
2670 monitor_printf(mon, " desc: 0x%016"PRIx64"\n", s->desc);
2671 monitor_printf(mon, " desc_phys: 0x%016"PRIx64"\n",
2672 s->desc_phys);
2673 monitor_printf(mon, " desc_size: %"PRId32"\n", s->desc_size);
2674 monitor_printf(mon, " avail: 0x%016"PRIx64"\n", s->avail);
2675 monitor_printf(mon, " avail_phys: 0x%016"PRIx64"\n",
2676 s->avail_phys);
2677 monitor_printf(mon, " avail_size: %"PRId32"\n", s->avail_size);
2678 monitor_printf(mon, " used: 0x%016"PRIx64"\n", s->used);
2679 monitor_printf(mon, " used_phys: 0x%016"PRIx64"\n",
2680 s->used_phys);
2681 monitor_printf(mon, " used_size: %"PRId32"\n", s->used_size);
2683 qapi_free_VirtVhostQueueStatus(s);
2686 void hmp_virtio_queue_status(Monitor *mon, const QDict *qdict)
2688 Error *err = NULL;
2689 const char *path = qdict_get_try_str(qdict, "path");
2690 int queue = qdict_get_int(qdict, "queue");
2691 VirtQueueStatus *s = qmp_x_query_virtio_queue_status(path, queue, &err);
2693 if (err != NULL) {
2694 hmp_handle_error(mon, err);
2695 return;
2698 monitor_printf(mon, "%s:\n", path);
2699 monitor_printf(mon, " device_name: %s\n", s->name);
2700 monitor_printf(mon, " queue_index: %d\n", s->queue_index);
2701 monitor_printf(mon, " inuse: %d\n", s->inuse);
2702 monitor_printf(mon, " used_idx: %d\n", s->used_idx);
2703 monitor_printf(mon, " signalled_used: %d\n",
2704 s->signalled_used);
2705 monitor_printf(mon, " signalled_used_valid: %s\n",
2706 s->signalled_used_valid ? "true" : "false");
2707 if (s->has_last_avail_idx) {
2708 monitor_printf(mon, " last_avail_idx: %d\n",
2709 s->last_avail_idx);
2711 if (s->has_shadow_avail_idx) {
2712 monitor_printf(mon, " shadow_avail_idx: %d\n",
2713 s->shadow_avail_idx);
2715 monitor_printf(mon, " VRing:\n");
2716 monitor_printf(mon, " num: %"PRId32"\n", s->vring_num);
2717 monitor_printf(mon, " num_default: %"PRId32"\n",
2718 s->vring_num_default);
2719 monitor_printf(mon, " align: %"PRId32"\n",
2720 s->vring_align);
2721 monitor_printf(mon, " desc: 0x%016"PRIx64"\n",
2722 s->vring_desc);
2723 monitor_printf(mon, " avail: 0x%016"PRIx64"\n",
2724 s->vring_avail);
2725 monitor_printf(mon, " used: 0x%016"PRIx64"\n",
2726 s->vring_used);
2728 qapi_free_VirtQueueStatus(s);
2731 void hmp_virtio_queue_element(Monitor *mon, const QDict *qdict)
2733 Error *err = NULL;
2734 const char *path = qdict_get_try_str(qdict, "path");
2735 int queue = qdict_get_int(qdict, "queue");
2736 int index = qdict_get_try_int(qdict, "index", -1);
2737 VirtioQueueElement *e;
2738 VirtioRingDescList *list;
2740 e = qmp_x_query_virtio_queue_element(path, queue, index != -1,
2741 index, &err);
2742 if (err != NULL) {
2743 hmp_handle_error(mon, err);
2744 return;
2747 monitor_printf(mon, "%s:\n", path);
2748 monitor_printf(mon, " device_name: %s\n", e->name);
2749 monitor_printf(mon, " index: %d\n", e->index);
2750 monitor_printf(mon, " desc:\n");
2751 monitor_printf(mon, " descs:\n");
2753 list = e->descs;
2754 while (list) {
2755 monitor_printf(mon, " addr 0x%"PRIx64" len %d",
2756 list->value->addr, list->value->len);
2757 if (list->value->flags) {
2758 strList *flag = list->value->flags;
2759 monitor_printf(mon, " (");
2760 while (flag) {
2761 monitor_printf(mon, "%s", flag->value);
2762 flag = flag->next;
2763 if (flag) {
2764 monitor_printf(mon, ", ");
2767 monitor_printf(mon, ")");
2769 list = list->next;
2770 if (list) {
2771 monitor_printf(mon, ",\n");
2774 monitor_printf(mon, "\n");
2775 monitor_printf(mon, " avail:\n");
2776 monitor_printf(mon, " flags: %d\n", e->avail->flags);
2777 monitor_printf(mon, " idx: %d\n", e->avail->idx);
2778 monitor_printf(mon, " ring: %d\n", e->avail->ring);
2779 monitor_printf(mon, " used:\n");
2780 monitor_printf(mon, " flags: %d\n", e->used->flags);
2781 monitor_printf(mon, " idx: %d\n", e->used->idx);
2783 qapi_free_VirtioQueueElement(e);