semihosting: Create semihost_sys_poll_one
[qemu/rayw.git] / monitor / hmp-cmds.c
blobca98df04952bc4cee24b6da235cb1c0d21320872
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-visit-net.h"
47 #include "qapi/qapi-visit-migration.h"
48 #include "qapi/qmp/qdict.h"
49 #include "qapi/qmp/qerror.h"
50 #include "qapi/string-input-visitor.h"
51 #include "qapi/string-output-visitor.h"
52 #include "qom/object_interfaces.h"
53 #include "ui/console.h"
54 #include "qemu/cutils.h"
55 #include "qemu/error-report.h"
56 #include "hw/core/cpu.h"
57 #include "hw/intc/intc.h"
58 #include "migration/snapshot.h"
59 #include "migration/misc.h"
61 #ifdef CONFIG_SPICE
62 #include <spice/enums.h>
63 #endif
65 bool hmp_handle_error(Monitor *mon, Error *err)
67 if (err) {
68 error_reportf_err(err, "Error: ");
69 return true;
71 return false;
75 * Produce a strList from a comma separated list.
76 * A NULL or empty input string return NULL.
78 static strList *strList_from_comma_list(const char *in)
80 strList *res = NULL;
81 strList **tail = &res;
83 while (in && in[0]) {
84 char *comma = strchr(in, ',');
85 char *value;
87 if (comma) {
88 value = g_strndup(in, comma - in);
89 in = comma + 1; /* skip the , */
90 } else {
91 value = g_strdup(in);
92 in = NULL;
94 QAPI_LIST_APPEND(tail, value);
97 return res;
100 void hmp_info_name(Monitor *mon, const QDict *qdict)
102 NameInfo *info;
104 info = qmp_query_name(NULL);
105 if (info->has_name) {
106 monitor_printf(mon, "%s\n", info->name);
108 qapi_free_NameInfo(info);
111 void hmp_info_version(Monitor *mon, const QDict *qdict)
113 VersionInfo *info;
115 info = qmp_query_version(NULL);
117 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
118 info->qemu->major, info->qemu->minor, info->qemu->micro,
119 info->package);
121 qapi_free_VersionInfo(info);
124 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
126 KvmInfo *info;
128 info = qmp_query_kvm(NULL);
129 monitor_printf(mon, "kvm support: ");
130 if (info->present) {
131 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
132 } else {
133 monitor_printf(mon, "not compiled\n");
136 qapi_free_KvmInfo(info);
139 void hmp_info_status(Monitor *mon, const QDict *qdict)
141 StatusInfo *info;
143 info = qmp_query_status(NULL);
145 monitor_printf(mon, "VM status: %s%s",
146 info->running ? "running" : "paused",
147 info->singlestep ? " (single step mode)" : "");
149 if (!info->running && info->status != RUN_STATE_PAUSED) {
150 monitor_printf(mon, " (%s)", RunState_str(info->status));
153 monitor_printf(mon, "\n");
155 qapi_free_StatusInfo(info);
158 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
160 UuidInfo *info;
162 info = qmp_query_uuid(NULL);
163 monitor_printf(mon, "%s\n", info->UUID);
164 qapi_free_UuidInfo(info);
167 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
169 ChardevInfoList *char_info, *info;
171 char_info = qmp_query_chardev(NULL);
172 for (info = char_info; info; info = info->next) {
173 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
174 info->value->filename);
177 qapi_free_ChardevInfoList(char_info);
180 void hmp_info_mice(Monitor *mon, const QDict *qdict)
182 MouseInfoList *mice_list, *mouse;
184 mice_list = qmp_query_mice(NULL);
185 if (!mice_list) {
186 monitor_printf(mon, "No mouse devices connected\n");
187 return;
190 for (mouse = mice_list; mouse; mouse = mouse->next) {
191 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
192 mouse->value->current ? '*' : ' ',
193 mouse->value->index, mouse->value->name,
194 mouse->value->absolute ? " (absolute)" : "");
197 qapi_free_MouseInfoList(mice_list);
200 static char *SocketAddress_to_str(SocketAddress *addr)
202 switch (addr->type) {
203 case SOCKET_ADDRESS_TYPE_INET:
204 return g_strdup_printf("tcp:%s:%s",
205 addr->u.inet.host,
206 addr->u.inet.port);
207 case SOCKET_ADDRESS_TYPE_UNIX:
208 return g_strdup_printf("unix:%s",
209 addr->u.q_unix.path);
210 case SOCKET_ADDRESS_TYPE_FD:
211 return g_strdup_printf("fd:%s", addr->u.fd.str);
212 case SOCKET_ADDRESS_TYPE_VSOCK:
213 return g_strdup_printf("tcp:%s:%s",
214 addr->u.vsock.cid,
215 addr->u.vsock.port);
216 default:
217 return g_strdup("unknown address type");
221 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
223 MigrationInfo *info;
225 info = qmp_query_migrate(NULL);
227 migration_global_dump(mon);
229 if (info->blocked_reasons) {
230 strList *reasons = info->blocked_reasons;
231 monitor_printf(mon, "Outgoing migration blocked:\n");
232 while (reasons) {
233 monitor_printf(mon, " %s\n", reasons->value);
234 reasons = reasons->next;
238 if (info->has_status) {
239 monitor_printf(mon, "Migration status: %s",
240 MigrationStatus_str(info->status));
241 if (info->status == MIGRATION_STATUS_FAILED &&
242 info->has_error_desc) {
243 monitor_printf(mon, " (%s)\n", info->error_desc);
244 } else {
245 monitor_printf(mon, "\n");
248 monitor_printf(mon, "total time: %" PRIu64 " ms\n",
249 info->total_time);
250 if (info->has_expected_downtime) {
251 monitor_printf(mon, "expected downtime: %" PRIu64 " ms\n",
252 info->expected_downtime);
254 if (info->has_downtime) {
255 monitor_printf(mon, "downtime: %" PRIu64 " ms\n",
256 info->downtime);
258 if (info->has_setup_time) {
259 monitor_printf(mon, "setup: %" PRIu64 " ms\n",
260 info->setup_time);
264 if (info->has_ram) {
265 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
266 info->ram->transferred >> 10);
267 monitor_printf(mon, "throughput: %0.2f mbps\n",
268 info->ram->mbps);
269 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
270 info->ram->remaining >> 10);
271 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
272 info->ram->total >> 10);
273 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
274 info->ram->duplicate);
275 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
276 info->ram->skipped);
277 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
278 info->ram->normal);
279 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
280 info->ram->normal_bytes >> 10);
281 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
282 info->ram->dirty_sync_count);
283 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
284 info->ram->page_size >> 10);
285 monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n",
286 info->ram->multifd_bytes >> 10);
287 monitor_printf(mon, "pages-per-second: %" PRIu64 "\n",
288 info->ram->pages_per_second);
290 if (info->ram->dirty_pages_rate) {
291 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
292 info->ram->dirty_pages_rate);
294 if (info->ram->postcopy_requests) {
295 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
296 info->ram->postcopy_requests);
298 if (info->ram->precopy_bytes) {
299 monitor_printf(mon, "precopy ram: %" PRIu64 " kbytes\n",
300 info->ram->precopy_bytes >> 10);
302 if (info->ram->downtime_bytes) {
303 monitor_printf(mon, "downtime ram: %" PRIu64 " kbytes\n",
304 info->ram->downtime_bytes >> 10);
306 if (info->ram->postcopy_bytes) {
307 monitor_printf(mon, "postcopy ram: %" PRIu64 " kbytes\n",
308 info->ram->postcopy_bytes >> 10);
312 if (info->has_disk) {
313 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
314 info->disk->transferred >> 10);
315 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
316 info->disk->remaining >> 10);
317 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
318 info->disk->total >> 10);
321 if (info->has_xbzrle_cache) {
322 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
323 info->xbzrle_cache->cache_size);
324 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
325 info->xbzrle_cache->bytes >> 10);
326 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
327 info->xbzrle_cache->pages);
328 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 " pages\n",
329 info->xbzrle_cache->cache_miss);
330 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
331 info->xbzrle_cache->cache_miss_rate);
332 monitor_printf(mon, "xbzrle encoding rate: %0.2f\n",
333 info->xbzrle_cache->encoding_rate);
334 monitor_printf(mon, "xbzrle overflow: %" PRIu64 "\n",
335 info->xbzrle_cache->overflow);
338 if (info->has_compression) {
339 monitor_printf(mon, "compression pages: %" PRIu64 " pages\n",
340 info->compression->pages);
341 monitor_printf(mon, "compression busy: %" PRIu64 "\n",
342 info->compression->busy);
343 monitor_printf(mon, "compression busy rate: %0.2f\n",
344 info->compression->busy_rate);
345 monitor_printf(mon, "compressed size: %" PRIu64 " kbytes\n",
346 info->compression->compressed_size >> 10);
347 monitor_printf(mon, "compression rate: %0.2f\n",
348 info->compression->compression_rate);
351 if (info->has_cpu_throttle_percentage) {
352 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
353 info->cpu_throttle_percentage);
356 if (info->has_postcopy_blocktime) {
357 monitor_printf(mon, "postcopy blocktime: %u\n",
358 info->postcopy_blocktime);
361 if (info->has_postcopy_vcpu_blocktime) {
362 Visitor *v;
363 char *str;
364 v = string_output_visitor_new(false, &str);
365 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime,
366 &error_abort);
367 visit_complete(v, &str);
368 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
369 g_free(str);
370 visit_free(v);
372 if (info->has_socket_address) {
373 SocketAddressList *addr;
375 monitor_printf(mon, "socket address: [\n");
377 for (addr = info->socket_address; addr; addr = addr->next) {
378 char *s = SocketAddress_to_str(addr->value);
379 monitor_printf(mon, "\t%s\n", s);
380 g_free(s);
382 monitor_printf(mon, "]\n");
385 if (info->has_vfio) {
386 monitor_printf(mon, "vfio device transferred: %" PRIu64 " kbytes\n",
387 info->vfio->transferred >> 10);
390 qapi_free_MigrationInfo(info);
393 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
395 MigrationCapabilityStatusList *caps, *cap;
397 caps = qmp_query_migrate_capabilities(NULL);
399 if (caps) {
400 for (cap = caps; cap; cap = cap->next) {
401 monitor_printf(mon, "%s: %s\n",
402 MigrationCapability_str(cap->value->capability),
403 cap->value->state ? "on" : "off");
407 qapi_free_MigrationCapabilityStatusList(caps);
410 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
412 MigrationParameters *params;
414 params = qmp_query_migrate_parameters(NULL);
416 if (params) {
417 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
418 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL),
419 params->announce_initial);
420 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
421 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX),
422 params->announce_max);
423 monitor_printf(mon, "%s: %" PRIu64 "\n",
424 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS),
425 params->announce_rounds);
426 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
427 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP),
428 params->announce_step);
429 assert(params->has_compress_level);
430 monitor_printf(mon, "%s: %u\n",
431 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
432 params->compress_level);
433 assert(params->has_compress_threads);
434 monitor_printf(mon, "%s: %u\n",
435 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
436 params->compress_threads);
437 assert(params->has_compress_wait_thread);
438 monitor_printf(mon, "%s: %s\n",
439 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD),
440 params->compress_wait_thread ? "on" : "off");
441 assert(params->has_decompress_threads);
442 monitor_printf(mon, "%s: %u\n",
443 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
444 params->decompress_threads);
445 assert(params->has_throttle_trigger_threshold);
446 monitor_printf(mon, "%s: %u\n",
447 MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD),
448 params->throttle_trigger_threshold);
449 assert(params->has_cpu_throttle_initial);
450 monitor_printf(mon, "%s: %u\n",
451 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
452 params->cpu_throttle_initial);
453 assert(params->has_cpu_throttle_increment);
454 monitor_printf(mon, "%s: %u\n",
455 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
456 params->cpu_throttle_increment);
457 assert(params->has_cpu_throttle_tailslow);
458 monitor_printf(mon, "%s: %s\n",
459 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW),
460 params->cpu_throttle_tailslow ? "on" : "off");
461 assert(params->has_max_cpu_throttle);
462 monitor_printf(mon, "%s: %u\n",
463 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE),
464 params->max_cpu_throttle);
465 assert(params->has_tls_creds);
466 monitor_printf(mon, "%s: '%s'\n",
467 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
468 params->tls_creds);
469 assert(params->has_tls_hostname);
470 monitor_printf(mon, "%s: '%s'\n",
471 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
472 params->tls_hostname);
473 assert(params->has_max_bandwidth);
474 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
475 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
476 params->max_bandwidth);
477 assert(params->has_downtime_limit);
478 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
479 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
480 params->downtime_limit);
481 assert(params->has_x_checkpoint_delay);
482 monitor_printf(mon, "%s: %u ms\n",
483 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
484 params->x_checkpoint_delay);
485 assert(params->has_block_incremental);
486 monitor_printf(mon, "%s: %s\n",
487 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
488 params->block_incremental ? "on" : "off");
489 monitor_printf(mon, "%s: %u\n",
490 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS),
491 params->multifd_channels);
492 monitor_printf(mon, "%s: %s\n",
493 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION),
494 MultiFDCompression_str(params->multifd_compression));
495 monitor_printf(mon, "%s: %" PRIu64 " bytes\n",
496 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
497 params->xbzrle_cache_size);
498 monitor_printf(mon, "%s: %" PRIu64 "\n",
499 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
500 params->max_postcopy_bandwidth);
501 monitor_printf(mon, "%s: '%s'\n",
502 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
503 params->tls_authz);
505 if (params->has_block_bitmap_mapping) {
506 const BitmapMigrationNodeAliasList *bmnal;
508 monitor_printf(mon, "%s:\n",
509 MigrationParameter_str(
510 MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING));
512 for (bmnal = params->block_bitmap_mapping;
513 bmnal;
514 bmnal = bmnal->next)
516 const BitmapMigrationNodeAlias *bmna = bmnal->value;
517 const BitmapMigrationBitmapAliasList *bmbal;
519 monitor_printf(mon, " '%s' -> '%s'\n",
520 bmna->node_name, bmna->alias);
522 for (bmbal = bmna->bitmaps; bmbal; bmbal = bmbal->next) {
523 const BitmapMigrationBitmapAlias *bmba = bmbal->value;
525 monitor_printf(mon, " '%s' -> '%s'\n",
526 bmba->name, bmba->alias);
532 qapi_free_MigrationParameters(params);
536 #ifdef CONFIG_VNC
537 /* Helper for hmp_info_vnc_clients, _servers */
538 static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
539 const char *name)
541 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
542 name,
543 info->host,
544 info->service,
545 NetworkAddressFamily_str(info->family),
546 info->websocket ? " (Websocket)" : "");
549 /* Helper displaying and auth and crypt info */
550 static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
551 VncPrimaryAuth auth,
552 VncVencryptSubAuth *vencrypt)
554 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
555 VncPrimaryAuth_str(auth),
556 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
559 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
561 while (client) {
562 VncClientInfo *cinfo = client->value;
564 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
565 monitor_printf(mon, " x509_dname: %s\n",
566 cinfo->has_x509_dname ?
567 cinfo->x509_dname : "none");
568 monitor_printf(mon, " sasl_username: %s\n",
569 cinfo->has_sasl_username ?
570 cinfo->sasl_username : "none");
572 client = client->next;
576 static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
578 while (server) {
579 VncServerInfo2 *sinfo = server->value;
580 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
581 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
582 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
583 server = server->next;
587 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
589 VncInfo2List *info2l, *info2l_head;
590 Error *err = NULL;
592 info2l = qmp_query_vnc_servers(&err);
593 info2l_head = info2l;
594 if (hmp_handle_error(mon, err)) {
595 return;
597 if (!info2l) {
598 monitor_printf(mon, "None\n");
599 return;
602 while (info2l) {
603 VncInfo2 *info = info2l->value;
604 monitor_printf(mon, "%s:\n", info->id);
605 hmp_info_vnc_servers(mon, info->server);
606 hmp_info_vnc_clients(mon, info->clients);
607 if (!info->server) {
608 /* The server entry displays its auth, we only
609 * need to display in the case of 'reverse' connections
610 * where there's no server.
612 hmp_info_vnc_authcrypt(mon, " ", info->auth,
613 info->has_vencrypt ? &info->vencrypt : NULL);
615 if (info->has_display) {
616 monitor_printf(mon, " Display: %s\n", info->display);
618 info2l = info2l->next;
621 qapi_free_VncInfo2List(info2l_head);
624 #endif
626 #ifdef CONFIG_SPICE
627 void hmp_info_spice(Monitor *mon, const QDict *qdict)
629 SpiceChannelList *chan;
630 SpiceInfo *info;
631 const char *channel_name;
632 const char * const channel_names[] = {
633 [SPICE_CHANNEL_MAIN] = "main",
634 [SPICE_CHANNEL_DISPLAY] = "display",
635 [SPICE_CHANNEL_INPUTS] = "inputs",
636 [SPICE_CHANNEL_CURSOR] = "cursor",
637 [SPICE_CHANNEL_PLAYBACK] = "playback",
638 [SPICE_CHANNEL_RECORD] = "record",
639 [SPICE_CHANNEL_TUNNEL] = "tunnel",
640 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
641 [SPICE_CHANNEL_USBREDIR] = "usbredir",
642 [SPICE_CHANNEL_PORT] = "port",
643 #if 0
644 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
645 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
646 * as quick fix for build failures with older versions. */
647 [SPICE_CHANNEL_WEBDAV] = "webdav",
648 #endif
651 info = qmp_query_spice(NULL);
653 if (!info->enabled) {
654 monitor_printf(mon, "Server: disabled\n");
655 goto out;
658 monitor_printf(mon, "Server:\n");
659 if (info->has_port) {
660 monitor_printf(mon, " address: %s:%" PRId64 "\n",
661 info->host, info->port);
663 if (info->has_tls_port) {
664 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
665 info->host, info->tls_port);
667 monitor_printf(mon, " migrated: %s\n",
668 info->migrated ? "true" : "false");
669 monitor_printf(mon, " auth: %s\n", info->auth);
670 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
671 monitor_printf(mon, " mouse-mode: %s\n",
672 SpiceQueryMouseMode_str(info->mouse_mode));
674 if (!info->has_channels || info->channels == NULL) {
675 monitor_printf(mon, "Channels: none\n");
676 } else {
677 for (chan = info->channels; chan; chan = chan->next) {
678 monitor_printf(mon, "Channel:\n");
679 monitor_printf(mon, " address: %s:%s%s\n",
680 chan->value->host, chan->value->port,
681 chan->value->tls ? " [tls]" : "");
682 monitor_printf(mon, " session: %" PRId64 "\n",
683 chan->value->connection_id);
684 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
685 chan->value->channel_type, chan->value->channel_id);
687 channel_name = "unknown";
688 if (chan->value->channel_type > 0 &&
689 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
690 channel_names[chan->value->channel_type]) {
691 channel_name = channel_names[chan->value->channel_type];
694 monitor_printf(mon, " channel name: %s\n", channel_name);
698 out:
699 qapi_free_SpiceInfo(info);
701 #endif
703 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
705 BalloonInfo *info;
706 Error *err = NULL;
708 info = qmp_query_balloon(&err);
709 if (hmp_handle_error(mon, err)) {
710 return;
713 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
715 qapi_free_BalloonInfo(info);
718 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
720 PciMemoryRegionList *region;
722 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
723 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
724 dev->slot, dev->function);
725 monitor_printf(mon, " ");
727 if (dev->class_info->has_desc) {
728 monitor_printf(mon, "%s", dev->class_info->desc);
729 } else {
730 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
733 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
734 dev->id->vendor, dev->id->device);
735 if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) {
736 monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n",
737 dev->id->subsystem_vendor, dev->id->subsystem);
740 if (dev->has_irq) {
741 monitor_printf(mon, " IRQ %" PRId64 ", pin %c\n",
742 dev->irq, (char)('A' + dev->irq_pin - 1));
745 if (dev->has_pci_bridge) {
746 monitor_printf(mon, " BUS %" PRId64 ".\n",
747 dev->pci_bridge->bus->number);
748 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
749 dev->pci_bridge->bus->secondary);
750 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
751 dev->pci_bridge->bus->subordinate);
753 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
754 dev->pci_bridge->bus->io_range->base,
755 dev->pci_bridge->bus->io_range->limit);
757 monitor_printf(mon,
758 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
759 dev->pci_bridge->bus->memory_range->base,
760 dev->pci_bridge->bus->memory_range->limit);
762 monitor_printf(mon, " prefetchable memory range "
763 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
764 dev->pci_bridge->bus->prefetchable_range->base,
765 dev->pci_bridge->bus->prefetchable_range->limit);
768 for (region = dev->regions; region; region = region->next) {
769 uint64_t addr, size;
771 addr = region->value->address;
772 size = region->value->size;
774 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
776 if (!strcmp(region->value->type, "io")) {
777 monitor_printf(mon, "I/O at 0x%04" PRIx64
778 " [0x%04" PRIx64 "].\n",
779 addr, addr + size - 1);
780 } else {
781 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
782 " [0x%08" PRIx64 "].\n",
783 region->value->mem_type_64 ? 64 : 32,
784 region->value->prefetch ? " prefetchable" : "",
785 addr, addr + size - 1);
789 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
791 if (dev->has_pci_bridge) {
792 if (dev->pci_bridge->has_devices) {
793 PciDeviceInfoList *cdev;
794 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
795 hmp_info_pci_device(mon, cdev->value);
801 static int hmp_info_pic_foreach(Object *obj, void *opaque)
803 InterruptStatsProvider *intc;
804 InterruptStatsProviderClass *k;
805 Monitor *mon = opaque;
807 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
808 intc = INTERRUPT_STATS_PROVIDER(obj);
809 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
810 if (k->print_info) {
811 k->print_info(intc, mon);
812 } else {
813 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
814 object_get_typename(obj));
818 return 0;
821 void hmp_info_pic(Monitor *mon, const QDict *qdict)
823 object_child_foreach_recursive(object_get_root(),
824 hmp_info_pic_foreach, mon);
827 void hmp_info_pci(Monitor *mon, const QDict *qdict)
829 PciInfoList *info_list, *info;
830 Error *err = NULL;
832 info_list = qmp_query_pci(&err);
833 if (err) {
834 monitor_printf(mon, "PCI devices not supported\n");
835 error_free(err);
836 return;
839 for (info = info_list; info; info = info->next) {
840 PciDeviceInfoList *dev;
842 for (dev = info->value->devices; dev; dev = dev->next) {
843 hmp_info_pci_device(mon, dev->value);
847 qapi_free_PciInfoList(info_list);
850 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
852 #ifdef CONFIG_TPM
853 TPMInfoList *info_list, *info;
854 Error *err = NULL;
855 unsigned int c = 0;
856 TPMPassthroughOptions *tpo;
857 TPMEmulatorOptions *teo;
859 info_list = qmp_query_tpm(&err);
860 if (err) {
861 monitor_printf(mon, "TPM device not supported\n");
862 error_free(err);
863 return;
866 if (info_list) {
867 monitor_printf(mon, "TPM device:\n");
870 for (info = info_list; info; info = info->next) {
871 TPMInfo *ti = info->value;
872 monitor_printf(mon, " tpm%d: model=%s\n",
873 c, TpmModel_str(ti->model));
875 monitor_printf(mon, " \\ %s: type=%s",
876 ti->id, TpmType_str(ti->options->type));
878 switch (ti->options->type) {
879 case TPM_TYPE_PASSTHROUGH:
880 tpo = ti->options->u.passthrough.data;
881 monitor_printf(mon, "%s%s%s%s",
882 tpo->has_path ? ",path=" : "",
883 tpo->has_path ? tpo->path : "",
884 tpo->has_cancel_path ? ",cancel-path=" : "",
885 tpo->has_cancel_path ? tpo->cancel_path : "");
886 break;
887 case TPM_TYPE_EMULATOR:
888 teo = ti->options->u.emulator.data;
889 monitor_printf(mon, ",chardev=%s", teo->chardev);
890 break;
891 case TPM_TYPE__MAX:
892 break;
894 monitor_printf(mon, "\n");
895 c++;
897 qapi_free_TPMInfoList(info_list);
898 #else
899 monitor_printf(mon, "TPM device not supported\n");
900 #endif /* CONFIG_TPM */
903 void hmp_quit(Monitor *mon, const QDict *qdict)
905 monitor_suspend(mon);
906 qmp_quit(NULL);
909 void hmp_stop(Monitor *mon, const QDict *qdict)
911 qmp_stop(NULL);
914 void hmp_sync_profile(Monitor *mon, const QDict *qdict)
916 const char *op = qdict_get_try_str(qdict, "op");
918 if (op == NULL) {
919 bool on = qsp_is_enabled();
921 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off");
922 return;
924 if (!strcmp(op, "on")) {
925 qsp_enable();
926 } else if (!strcmp(op, "off")) {
927 qsp_disable();
928 } else if (!strcmp(op, "reset")) {
929 qsp_reset();
930 } else {
931 Error *err = NULL;
933 error_setg(&err, QERR_INVALID_PARAMETER, op);
934 hmp_handle_error(mon, err);
938 void hmp_system_reset(Monitor *mon, const QDict *qdict)
940 qmp_system_reset(NULL);
943 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
945 qmp_system_powerdown(NULL);
948 void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
950 Error *err = NULL;
952 qmp_x_exit_preconfig(&err);
953 hmp_handle_error(mon, err);
956 void hmp_cpu(Monitor *mon, const QDict *qdict)
958 int64_t cpu_index;
960 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
961 use it are converted to the QAPI */
962 cpu_index = qdict_get_int(qdict, "index");
963 if (monitor_set_cpu(mon, cpu_index) < 0) {
964 monitor_printf(mon, "invalid CPU index\n");
968 void hmp_memsave(Monitor *mon, const QDict *qdict)
970 uint32_t size = qdict_get_int(qdict, "size");
971 const char *filename = qdict_get_str(qdict, "filename");
972 uint64_t addr = qdict_get_int(qdict, "val");
973 Error *err = NULL;
974 int cpu_index = monitor_get_cpu_index(mon);
976 if (cpu_index < 0) {
977 monitor_printf(mon, "No CPU available\n");
978 return;
981 qmp_memsave(addr, size, filename, true, cpu_index, &err);
982 hmp_handle_error(mon, err);
985 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
987 uint32_t size = qdict_get_int(qdict, "size");
988 const char *filename = qdict_get_str(qdict, "filename");
989 uint64_t addr = qdict_get_int(qdict, "val");
990 Error *err = NULL;
992 qmp_pmemsave(addr, size, filename, &err);
993 hmp_handle_error(mon, err);
996 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
998 const char *chardev = qdict_get_str(qdict, "device");
999 const char *data = qdict_get_str(qdict, "data");
1000 Error *err = NULL;
1002 qmp_ringbuf_write(chardev, data, false, 0, &err);
1004 hmp_handle_error(mon, err);
1007 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
1009 uint32_t size = qdict_get_int(qdict, "size");
1010 const char *chardev = qdict_get_str(qdict, "device");
1011 char *data;
1012 Error *err = NULL;
1013 int i;
1015 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1016 if (hmp_handle_error(mon, err)) {
1017 return;
1020 for (i = 0; data[i]; i++) {
1021 unsigned char ch = data[i];
1023 if (ch == '\\') {
1024 monitor_printf(mon, "\\\\");
1025 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1026 monitor_printf(mon, "\\u%04X", ch);
1027 } else {
1028 monitor_printf(mon, "%c", ch);
1032 monitor_printf(mon, "\n");
1033 g_free(data);
1036 void hmp_cont(Monitor *mon, const QDict *qdict)
1038 Error *err = NULL;
1040 qmp_cont(&err);
1041 hmp_handle_error(mon, err);
1044 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1046 Error *err = NULL;
1048 qmp_system_wakeup(&err);
1049 hmp_handle_error(mon, err);
1052 void hmp_nmi(Monitor *mon, const QDict *qdict)
1054 Error *err = NULL;
1056 qmp_inject_nmi(&err);
1057 hmp_handle_error(mon, err);
1060 void hmp_set_link(Monitor *mon, const QDict *qdict)
1062 const char *name = qdict_get_str(qdict, "name");
1063 bool up = qdict_get_bool(qdict, "up");
1064 Error *err = NULL;
1066 qmp_set_link(name, up, &err);
1067 hmp_handle_error(mon, err);
1070 void hmp_balloon(Monitor *mon, const QDict *qdict)
1072 int64_t value = qdict_get_int(qdict, "value");
1073 Error *err = NULL;
1075 qmp_balloon(value, &err);
1076 hmp_handle_error(mon, err);
1079 void hmp_loadvm(Monitor *mon, const QDict *qdict)
1081 int saved_vm_running = runstate_is_running();
1082 const char *name = qdict_get_str(qdict, "name");
1083 Error *err = NULL;
1085 vm_stop(RUN_STATE_RESTORE_VM);
1087 if (load_snapshot(name, NULL, false, NULL, &err) && saved_vm_running) {
1088 vm_start();
1090 hmp_handle_error(mon, err);
1093 void hmp_savevm(Monitor *mon, const QDict *qdict)
1095 Error *err = NULL;
1097 save_snapshot(qdict_get_try_str(qdict, "name"),
1098 true, NULL, false, NULL, &err);
1099 hmp_handle_error(mon, err);
1102 void hmp_delvm(Monitor *mon, const QDict *qdict)
1104 Error *err = NULL;
1105 const char *name = qdict_get_str(qdict, "name");
1107 delete_snapshot(name, false, NULL, &err);
1108 hmp_handle_error(mon, err);
1111 void hmp_announce_self(Monitor *mon, const QDict *qdict)
1113 const char *interfaces_str = qdict_get_try_str(qdict, "interfaces");
1114 const char *id = qdict_get_try_str(qdict, "id");
1115 AnnounceParameters *params = QAPI_CLONE(AnnounceParameters,
1116 migrate_announce_params());
1118 qapi_free_strList(params->interfaces);
1119 params->interfaces = strList_from_comma_list(interfaces_str);
1120 params->has_interfaces = params->interfaces != NULL;
1121 params->id = g_strdup(id);
1122 params->has_id = !!params->id;
1123 qmp_announce_self(params, NULL);
1124 qapi_free_AnnounceParameters(params);
1127 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1129 qmp_migrate_cancel(NULL);
1132 void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1134 Error *err = NULL;
1135 const char *state = qdict_get_str(qdict, "state");
1136 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1138 if (val >= 0) {
1139 qmp_migrate_continue(val, &err);
1142 hmp_handle_error(mon, err);
1145 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1147 Error *err = NULL;
1148 const char *uri = qdict_get_str(qdict, "uri");
1150 qmp_migrate_incoming(uri, &err);
1152 hmp_handle_error(mon, err);
1155 void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
1157 Error *err = NULL;
1158 const char *uri = qdict_get_str(qdict, "uri");
1160 qmp_migrate_recover(uri, &err);
1162 hmp_handle_error(mon, err);
1165 void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
1167 Error *err = NULL;
1169 qmp_migrate_pause(&err);
1171 hmp_handle_error(mon, err);
1175 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1177 const char *cap = qdict_get_str(qdict, "capability");
1178 bool state = qdict_get_bool(qdict, "state");
1179 Error *err = NULL;
1180 MigrationCapabilityStatusList *caps = NULL;
1181 MigrationCapabilityStatus *value;
1182 int val;
1184 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
1185 if (val < 0) {
1186 goto end;
1189 value = g_malloc0(sizeof(*value));
1190 value->capability = val;
1191 value->state = state;
1192 QAPI_LIST_PREPEND(caps, value);
1193 qmp_migrate_set_capabilities(caps, &err);
1194 qapi_free_MigrationCapabilityStatusList(caps);
1196 end:
1197 hmp_handle_error(mon, err);
1200 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1202 const char *param = qdict_get_str(qdict, "parameter");
1203 const char *valuestr = qdict_get_str(qdict, "value");
1204 Visitor *v = string_input_visitor_new(valuestr);
1205 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
1206 uint64_t valuebw = 0;
1207 uint64_t cache_size;
1208 Error *err = NULL;
1209 int val, ret;
1211 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
1212 if (val < 0) {
1213 goto cleanup;
1216 switch (val) {
1217 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1218 p->has_compress_level = true;
1219 visit_type_uint8(v, param, &p->compress_level, &err);
1220 break;
1221 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1222 p->has_compress_threads = true;
1223 visit_type_uint8(v, param, &p->compress_threads, &err);
1224 break;
1225 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD:
1226 p->has_compress_wait_thread = true;
1227 visit_type_bool(v, param, &p->compress_wait_thread, &err);
1228 break;
1229 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1230 p->has_decompress_threads = true;
1231 visit_type_uint8(v, param, &p->decompress_threads, &err);
1232 break;
1233 case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD:
1234 p->has_throttle_trigger_threshold = true;
1235 visit_type_uint8(v, param, &p->throttle_trigger_threshold, &err);
1236 break;
1237 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1238 p->has_cpu_throttle_initial = true;
1239 visit_type_uint8(v, param, &p->cpu_throttle_initial, &err);
1240 break;
1241 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1242 p->has_cpu_throttle_increment = true;
1243 visit_type_uint8(v, param, &p->cpu_throttle_increment, &err);
1244 break;
1245 case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW:
1246 p->has_cpu_throttle_tailslow = true;
1247 visit_type_bool(v, param, &p->cpu_throttle_tailslow, &err);
1248 break;
1249 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE:
1250 p->has_max_cpu_throttle = true;
1251 visit_type_uint8(v, param, &p->max_cpu_throttle, &err);
1252 break;
1253 case MIGRATION_PARAMETER_TLS_CREDS:
1254 p->has_tls_creds = true;
1255 p->tls_creds = g_new0(StrOrNull, 1);
1256 p->tls_creds->type = QTYPE_QSTRING;
1257 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1258 break;
1259 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1260 p->has_tls_hostname = true;
1261 p->tls_hostname = g_new0(StrOrNull, 1);
1262 p->tls_hostname->type = QTYPE_QSTRING;
1263 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1264 break;
1265 case MIGRATION_PARAMETER_TLS_AUTHZ:
1266 p->has_tls_authz = true;
1267 p->tls_authz = g_new0(StrOrNull, 1);
1268 p->tls_authz->type = QTYPE_QSTRING;
1269 visit_type_str(v, param, &p->tls_authz->u.s, &err);
1270 break;
1271 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1272 p->has_max_bandwidth = true;
1274 * Can't use visit_type_size() here, because it
1275 * defaults to Bytes rather than Mebibytes.
1277 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1278 if (ret < 0 || valuebw > INT64_MAX
1279 || (size_t)valuebw != valuebw) {
1280 error_setg(&err, "Invalid size %s", valuestr);
1281 break;
1283 p->max_bandwidth = valuebw;
1284 break;
1285 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1286 p->has_downtime_limit = true;
1287 visit_type_size(v, param, &p->downtime_limit, &err);
1288 break;
1289 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1290 p->has_x_checkpoint_delay = true;
1291 visit_type_uint32(v, param, &p->x_checkpoint_delay, &err);
1292 break;
1293 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1294 p->has_block_incremental = true;
1295 visit_type_bool(v, param, &p->block_incremental, &err);
1296 break;
1297 case MIGRATION_PARAMETER_MULTIFD_CHANNELS:
1298 p->has_multifd_channels = true;
1299 visit_type_uint8(v, param, &p->multifd_channels, &err);
1300 break;
1301 case MIGRATION_PARAMETER_MULTIFD_COMPRESSION:
1302 p->has_multifd_compression = true;
1303 visit_type_MultiFDCompression(v, param, &p->multifd_compression,
1304 &err);
1305 break;
1306 case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL:
1307 p->has_multifd_zlib_level = true;
1308 visit_type_uint8(v, param, &p->multifd_zlib_level, &err);
1309 break;
1310 case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL:
1311 p->has_multifd_zstd_level = true;
1312 visit_type_uint8(v, param, &p->multifd_zstd_level, &err);
1313 break;
1314 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1315 p->has_xbzrle_cache_size = true;
1316 if (!visit_type_size(v, param, &cache_size, &err)) {
1317 break;
1319 if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) {
1320 error_setg(&err, "Invalid size %s", valuestr);
1321 break;
1323 p->xbzrle_cache_size = cache_size;
1324 break;
1325 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH:
1326 p->has_max_postcopy_bandwidth = true;
1327 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err);
1328 break;
1329 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL:
1330 p->has_announce_initial = true;
1331 visit_type_size(v, param, &p->announce_initial, &err);
1332 break;
1333 case MIGRATION_PARAMETER_ANNOUNCE_MAX:
1334 p->has_announce_max = true;
1335 visit_type_size(v, param, &p->announce_max, &err);
1336 break;
1337 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS:
1338 p->has_announce_rounds = true;
1339 visit_type_size(v, param, &p->announce_rounds, &err);
1340 break;
1341 case MIGRATION_PARAMETER_ANNOUNCE_STEP:
1342 p->has_announce_step = true;
1343 visit_type_size(v, param, &p->announce_step, &err);
1344 break;
1345 case MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING:
1346 error_setg(&err, "The block-bitmap-mapping parameter can only be set "
1347 "through QMP");
1348 break;
1349 default:
1350 assert(0);
1353 if (err) {
1354 goto cleanup;
1357 qmp_migrate_set_parameters(p, &err);
1359 cleanup:
1360 qapi_free_MigrateSetParameters(p);
1361 visit_free(v);
1362 hmp_handle_error(mon, err);
1365 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1367 Error *err = NULL;
1368 const char *protocol = qdict_get_str(qdict, "protocol");
1369 const char *hostname = qdict_get_str(qdict, "hostname");
1370 bool has_port = qdict_haskey(qdict, "port");
1371 int port = qdict_get_try_int(qdict, "port", -1);
1372 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1373 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1374 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1376 qmp_client_migrate_info(protocol, hostname,
1377 has_port, port, has_tls_port, tls_port,
1378 !!cert_subject, cert_subject, &err);
1379 hmp_handle_error(mon, err);
1382 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1384 Error *err = NULL;
1385 qmp_migrate_start_postcopy(&err);
1386 hmp_handle_error(mon, err);
1389 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1391 Error *err = NULL;
1393 qmp_x_colo_lost_heartbeat(&err);
1394 hmp_handle_error(mon, err);
1397 void hmp_set_password(Monitor *mon, const QDict *qdict)
1399 const char *protocol = qdict_get_str(qdict, "protocol");
1400 const char *password = qdict_get_str(qdict, "password");
1401 const char *display = qdict_get_try_str(qdict, "display");
1402 const char *connected = qdict_get_try_str(qdict, "connected");
1403 Error *err = NULL;
1405 SetPasswordOptions opts = {
1406 .password = (char *)password,
1407 .has_connected = !!connected,
1410 opts.connected = qapi_enum_parse(&SetPasswordAction_lookup, connected,
1411 SET_PASSWORD_ACTION_KEEP, &err);
1412 if (err) {
1413 goto out;
1416 opts.protocol = qapi_enum_parse(&DisplayProtocol_lookup, protocol,
1417 DISPLAY_PROTOCOL_VNC, &err);
1418 if (err) {
1419 goto out;
1422 if (opts.protocol == DISPLAY_PROTOCOL_VNC) {
1423 opts.u.vnc.has_display = !!display;
1424 opts.u.vnc.display = (char *)display;
1427 qmp_set_password(&opts, &err);
1429 out:
1430 hmp_handle_error(mon, err);
1433 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1435 const char *protocol = qdict_get_str(qdict, "protocol");
1436 const char *whenstr = qdict_get_str(qdict, "time");
1437 const char *display = qdict_get_try_str(qdict, "display");
1438 Error *err = NULL;
1440 ExpirePasswordOptions opts = {
1441 .time = (char *)whenstr,
1444 opts.protocol = qapi_enum_parse(&DisplayProtocol_lookup, protocol,
1445 DISPLAY_PROTOCOL_VNC, &err);
1446 if (err) {
1447 goto out;
1450 if (opts.protocol == DISPLAY_PROTOCOL_VNC) {
1451 opts.u.vnc.has_display = !!display;
1452 opts.u.vnc.display = (char *)display;
1455 qmp_expire_password(&opts, &err);
1457 out:
1458 hmp_handle_error(mon, err);
1462 #ifdef CONFIG_VNC
1463 static void hmp_change_read_arg(void *opaque, const char *password,
1464 void *readline_opaque)
1466 qmp_change_vnc_password(password, NULL);
1467 monitor_read_command(opaque, 1);
1469 #endif
1471 void hmp_change(Monitor *mon, const QDict *qdict)
1473 const char *device = qdict_get_str(qdict, "device");
1474 const char *target = qdict_get_str(qdict, "target");
1475 const char *arg = qdict_get_try_str(qdict, "arg");
1476 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1477 bool force = qdict_get_try_bool(qdict, "force", false);
1478 BlockdevChangeReadOnlyMode read_only_mode = 0;
1479 Error *err = NULL;
1481 #ifdef CONFIG_VNC
1482 if (strcmp(device, "vnc") == 0) {
1483 if (read_only) {
1484 monitor_printf(mon,
1485 "Parameter 'read-only-mode' is invalid for VNC\n");
1486 return;
1488 if (strcmp(target, "passwd") == 0 ||
1489 strcmp(target, "password") == 0) {
1490 if (!arg) {
1491 MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
1492 monitor_read_password(hmp_mon, hmp_change_read_arg, NULL);
1493 return;
1494 } else {
1495 qmp_change_vnc_password(arg, &err);
1497 } else {
1498 monitor_printf(mon, "Expected 'password' after 'vnc'\n");
1500 } else
1501 #endif
1503 if (read_only) {
1504 read_only_mode =
1505 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
1506 read_only,
1507 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1508 if (err) {
1509 goto end;
1513 qmp_blockdev_change_medium(true, device, false, NULL, target,
1514 !!arg, arg, true, force,
1515 !!read_only, read_only_mode,
1516 &err);
1519 end:
1520 hmp_handle_error(mon, err);
1523 typedef struct HMPMigrationStatus {
1524 QEMUTimer *timer;
1525 Monitor *mon;
1526 bool is_block_migration;
1527 } HMPMigrationStatus;
1529 static void hmp_migrate_status_cb(void *opaque)
1531 HMPMigrationStatus *status = opaque;
1532 MigrationInfo *info;
1534 info = qmp_query_migrate(NULL);
1535 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1536 info->status == MIGRATION_STATUS_SETUP) {
1537 if (info->has_disk) {
1538 int progress;
1540 if (info->disk->remaining) {
1541 progress = info->disk->transferred * 100 / info->disk->total;
1542 } else {
1543 progress = 100;
1546 monitor_printf(status->mon, "Completed %d %%\r", progress);
1547 monitor_flush(status->mon);
1550 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1551 } else {
1552 if (status->is_block_migration) {
1553 monitor_printf(status->mon, "\n");
1555 if (info->has_error_desc) {
1556 error_report("%s", info->error_desc);
1558 monitor_resume(status->mon);
1559 timer_free(status->timer);
1560 g_free(status);
1563 qapi_free_MigrationInfo(info);
1566 void hmp_migrate(Monitor *mon, const QDict *qdict)
1568 bool detach = qdict_get_try_bool(qdict, "detach", false);
1569 bool blk = qdict_get_try_bool(qdict, "blk", false);
1570 bool inc = qdict_get_try_bool(qdict, "inc", false);
1571 bool resume = qdict_get_try_bool(qdict, "resume", false);
1572 const char *uri = qdict_get_str(qdict, "uri");
1573 Error *err = NULL;
1575 qmp_migrate(uri, !!blk, blk, !!inc, inc,
1576 false, false, true, resume, &err);
1577 if (hmp_handle_error(mon, err)) {
1578 return;
1581 if (!detach) {
1582 HMPMigrationStatus *status;
1584 if (monitor_suspend(mon) < 0) {
1585 monitor_printf(mon, "terminal does not allow synchronous "
1586 "migration, continuing detached\n");
1587 return;
1590 status = g_malloc0(sizeof(*status));
1591 status->mon = mon;
1592 status->is_block_migration = blk || inc;
1593 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1594 status);
1595 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1599 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1601 Error *err = NULL;
1602 QemuOpts *opts;
1603 const char *type = qdict_get_try_str(qdict, "type");
1605 if (type && is_help_option(type)) {
1606 show_netdevs();
1607 return;
1609 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1610 if (err) {
1611 goto out;
1614 netdev_add(opts, &err);
1615 if (err) {
1616 qemu_opts_del(opts);
1619 out:
1620 hmp_handle_error(mon, err);
1623 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1625 const char *id = qdict_get_str(qdict, "id");
1626 Error *err = NULL;
1628 qmp_netdev_del(id, &err);
1629 hmp_handle_error(mon, err);
1632 void hmp_object_add(Monitor *mon, const QDict *qdict)
1634 const char *options = qdict_get_str(qdict, "object");
1635 Error *err = NULL;
1637 user_creatable_add_from_str(options, &err);
1638 hmp_handle_error(mon, err);
1641 void hmp_getfd(Monitor *mon, const QDict *qdict)
1643 const char *fdname = qdict_get_str(qdict, "fdname");
1644 Error *err = NULL;
1646 qmp_getfd(fdname, &err);
1647 hmp_handle_error(mon, err);
1650 void hmp_closefd(Monitor *mon, const QDict *qdict)
1652 const char *fdname = qdict_get_str(qdict, "fdname");
1653 Error *err = NULL;
1655 qmp_closefd(fdname, &err);
1656 hmp_handle_error(mon, err);
1659 void hmp_sendkey(Monitor *mon, const QDict *qdict)
1661 const char *keys = qdict_get_str(qdict, "keys");
1662 KeyValue *v = NULL;
1663 KeyValueList *head = NULL, **tail = &head;
1664 int has_hold_time = qdict_haskey(qdict, "hold-time");
1665 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1666 Error *err = NULL;
1667 const char *separator;
1668 int keyname_len;
1670 while (1) {
1671 separator = qemu_strchrnul(keys, '-');
1672 keyname_len = separator - keys;
1674 /* Be compatible with old interface, convert user inputted "<" */
1675 if (keys[0] == '<' && keyname_len == 1) {
1676 keys = "less";
1677 keyname_len = 4;
1680 v = g_malloc0(sizeof(*v));
1682 if (strstart(keys, "0x", NULL)) {
1683 char *endp;
1684 int value = strtoul(keys, &endp, 0);
1685 assert(endp <= keys + keyname_len);
1686 if (endp != keys + keyname_len) {
1687 goto err_out;
1689 v->type = KEY_VALUE_KIND_NUMBER;
1690 v->u.number.data = value;
1691 } else {
1692 int idx = index_from_key(keys, keyname_len);
1693 if (idx == Q_KEY_CODE__MAX) {
1694 goto err_out;
1696 v->type = KEY_VALUE_KIND_QCODE;
1697 v->u.qcode.data = idx;
1699 QAPI_LIST_APPEND(tail, v);
1700 v = NULL;
1702 if (!*separator) {
1703 break;
1705 keys = separator + 1;
1708 qmp_send_key(head, has_hold_time, hold_time, &err);
1709 hmp_handle_error(mon, err);
1711 out:
1712 qapi_free_KeyValue(v);
1713 qapi_free_KeyValueList(head);
1714 return;
1716 err_out:
1717 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
1718 goto out;
1721 void coroutine_fn
1722 hmp_screendump(Monitor *mon, const QDict *qdict)
1724 const char *filename = qdict_get_str(qdict, "filename");
1725 const char *id = qdict_get_try_str(qdict, "device");
1726 int64_t head = qdict_get_try_int(qdict, "head", 0);
1727 const char *input_format = qdict_get_try_str(qdict, "format");
1728 Error *err = NULL;
1729 ImageFormat format;
1731 format = qapi_enum_parse(&ImageFormat_lookup, input_format,
1732 IMAGE_FORMAT_PPM, &err);
1733 if (err) {
1734 goto end;
1737 qmp_screendump(filename, id != NULL, id, id != NULL, head,
1738 input_format != NULL, format, &err);
1739 end:
1740 hmp_handle_error(mon, err);
1743 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1745 const char *args = qdict_get_str(qdict, "args");
1746 Error *err = NULL;
1747 QemuOpts *opts;
1749 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
1750 if (opts == NULL) {
1751 error_setg(&err, "Parsing chardev args failed");
1752 } else {
1753 qemu_chr_new_from_opts(opts, NULL, &err);
1754 qemu_opts_del(opts);
1756 hmp_handle_error(mon, err);
1759 void hmp_chardev_change(Monitor *mon, const QDict *qdict)
1761 const char *args = qdict_get_str(qdict, "args");
1762 const char *id;
1763 Error *err = NULL;
1764 ChardevBackend *backend = NULL;
1765 ChardevReturn *ret = NULL;
1766 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
1767 true);
1768 if (!opts) {
1769 error_setg(&err, "Parsing chardev args failed");
1770 goto end;
1773 id = qdict_get_str(qdict, "id");
1774 if (qemu_opts_id(opts)) {
1775 error_setg(&err, "Unexpected 'id' parameter");
1776 goto end;
1779 backend = qemu_chr_parse_opts(opts, &err);
1780 if (!backend) {
1781 goto end;
1784 ret = qmp_chardev_change(id, backend, &err);
1786 end:
1787 qapi_free_ChardevReturn(ret);
1788 qapi_free_ChardevBackend(backend);
1789 qemu_opts_del(opts);
1790 hmp_handle_error(mon, err);
1793 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1795 Error *local_err = NULL;
1797 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1798 hmp_handle_error(mon, local_err);
1801 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
1803 Error *local_err = NULL;
1805 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
1806 hmp_handle_error(mon, local_err);
1809 void hmp_object_del(Monitor *mon, const QDict *qdict)
1811 const char *id = qdict_get_str(qdict, "id");
1812 Error *err = NULL;
1814 user_creatable_del(id, &err);
1815 hmp_handle_error(mon, err);
1818 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
1820 Error *err = NULL;
1821 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
1822 MemoryDeviceInfoList *info;
1823 VirtioPMEMDeviceInfo *vpi;
1824 VirtioMEMDeviceInfo *vmi;
1825 MemoryDeviceInfo *value;
1826 PCDIMMDeviceInfo *di;
1827 SgxEPCDeviceInfo *se;
1829 for (info = info_list; info; info = info->next) {
1830 value = info->value;
1832 if (value) {
1833 switch (value->type) {
1834 case MEMORY_DEVICE_INFO_KIND_DIMM:
1835 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
1836 di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ?
1837 value->u.dimm.data : value->u.nvdimm.data;
1838 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1839 MemoryDeviceInfoKind_str(value->type),
1840 di->id ? di->id : "");
1841 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
1842 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
1843 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
1844 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
1845 monitor_printf(mon, " memdev: %s\n", di->memdev);
1846 monitor_printf(mon, " hotplugged: %s\n",
1847 di->hotplugged ? "true" : "false");
1848 monitor_printf(mon, " hotpluggable: %s\n",
1849 di->hotpluggable ? "true" : "false");
1850 break;
1851 case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM:
1852 vpi = value->u.virtio_pmem.data;
1853 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1854 MemoryDeviceInfoKind_str(value->type),
1855 vpi->id ? vpi->id : "");
1856 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->memaddr);
1857 monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size);
1858 monitor_printf(mon, " memdev: %s\n", vpi->memdev);
1859 break;
1860 case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM:
1861 vmi = value->u.virtio_mem.data;
1862 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1863 MemoryDeviceInfoKind_str(value->type),
1864 vmi->id ? vmi->id : "");
1865 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vmi->memaddr);
1866 monitor_printf(mon, " node: %" PRId64 "\n", vmi->node);
1867 monitor_printf(mon, " requested-size: %" PRIu64 "\n",
1868 vmi->requested_size);
1869 monitor_printf(mon, " size: %" PRIu64 "\n", vmi->size);
1870 monitor_printf(mon, " max-size: %" PRIu64 "\n", vmi->max_size);
1871 monitor_printf(mon, " block-size: %" PRIu64 "\n",
1872 vmi->block_size);
1873 monitor_printf(mon, " memdev: %s\n", vmi->memdev);
1874 break;
1875 case MEMORY_DEVICE_INFO_KIND_SGX_EPC:
1876 se = value->u.sgx_epc.data;
1877 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1878 MemoryDeviceInfoKind_str(value->type),
1879 se->id ? se->id : "");
1880 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", se->memaddr);
1881 monitor_printf(mon, " size: %" PRIu64 "\n", se->size);
1882 monitor_printf(mon, " node: %" PRId64 "\n", se->node);
1883 monitor_printf(mon, " memdev: %s\n", se->memdev);
1884 break;
1885 default:
1886 g_assert_not_reached();
1891 qapi_free_MemoryDeviceInfoList(info_list);
1892 hmp_handle_error(mon, err);
1895 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
1897 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
1898 IOThreadInfoList *info;
1899 IOThreadInfo *value;
1901 for (info = info_list; info; info = info->next) {
1902 value = info->value;
1903 monitor_printf(mon, "%s:\n", value->id);
1904 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
1905 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
1906 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
1907 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
1908 monitor_printf(mon, " aio-max-batch=%" PRId64 "\n",
1909 value->aio_max_batch);
1912 qapi_free_IOThreadInfoList(info_list);
1915 void hmp_rocker(Monitor *mon, const QDict *qdict)
1917 const char *name = qdict_get_str(qdict, "name");
1918 RockerSwitch *rocker;
1919 Error *err = NULL;
1921 rocker = qmp_query_rocker(name, &err);
1922 if (hmp_handle_error(mon, err)) {
1923 return;
1926 monitor_printf(mon, "name: %s\n", rocker->name);
1927 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
1928 monitor_printf(mon, "ports: %d\n", rocker->ports);
1930 qapi_free_RockerSwitch(rocker);
1933 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
1935 RockerPortList *list, *port;
1936 const char *name = qdict_get_str(qdict, "name");
1937 Error *err = NULL;
1939 list = qmp_query_rocker_ports(name, &err);
1940 if (hmp_handle_error(mon, err)) {
1941 return;
1944 monitor_printf(mon, " ena/ speed/ auto\n");
1945 monitor_printf(mon, " port link duplex neg?\n");
1947 for (port = list; port; port = port->next) {
1948 monitor_printf(mon, "%10s %-4s %-3s %2s %s\n",
1949 port->value->name,
1950 port->value->enabled ? port->value->link_up ?
1951 "up" : "down" : "!ena",
1952 port->value->speed == 10000 ? "10G" : "??",
1953 port->value->duplex ? "FD" : "HD",
1954 port->value->autoneg ? "Yes" : "No");
1957 qapi_free_RockerPortList(list);
1960 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
1962 RockerOfDpaFlowList *list, *info;
1963 const char *name = qdict_get_str(qdict, "name");
1964 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
1965 Error *err = NULL;
1967 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
1968 if (hmp_handle_error(mon, err)) {
1969 return;
1972 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
1974 for (info = list; info; info = info->next) {
1975 RockerOfDpaFlow *flow = info->value;
1976 RockerOfDpaFlowKey *key = flow->key;
1977 RockerOfDpaFlowMask *mask = flow->mask;
1978 RockerOfDpaFlowAction *action = flow->action;
1980 if (flow->hits) {
1981 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
1982 key->priority, key->tbl_id, flow->hits);
1983 } else {
1984 monitor_printf(mon, "%-4d %-3d ",
1985 key->priority, key->tbl_id);
1988 if (key->has_in_pport) {
1989 monitor_printf(mon, " pport %d", key->in_pport);
1990 if (mask->has_in_pport) {
1991 monitor_printf(mon, "(0x%x)", mask->in_pport);
1995 if (key->has_vlan_id) {
1996 monitor_printf(mon, " vlan %d",
1997 key->vlan_id & VLAN_VID_MASK);
1998 if (mask->has_vlan_id) {
1999 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2003 if (key->has_tunnel_id) {
2004 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2005 if (mask->has_tunnel_id) {
2006 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2010 if (key->has_eth_type) {
2011 switch (key->eth_type) {
2012 case 0x0806:
2013 monitor_printf(mon, " ARP");
2014 break;
2015 case 0x0800:
2016 monitor_printf(mon, " IP");
2017 break;
2018 case 0x86dd:
2019 monitor_printf(mon, " IPv6");
2020 break;
2021 case 0x8809:
2022 monitor_printf(mon, " LACP");
2023 break;
2024 case 0x88cc:
2025 monitor_printf(mon, " LLDP");
2026 break;
2027 default:
2028 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2029 break;
2033 if (key->has_eth_src) {
2034 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2035 (mask->has_eth_src) &&
2036 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2037 monitor_printf(mon, " src <any mcast/bcast>");
2038 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2039 (mask->has_eth_src) &&
2040 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2041 monitor_printf(mon, " src <any ucast>");
2042 } else {
2043 monitor_printf(mon, " src %s", key->eth_src);
2044 if (mask->has_eth_src) {
2045 monitor_printf(mon, "(%s)", mask->eth_src);
2050 if (key->has_eth_dst) {
2051 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2052 (mask->has_eth_dst) &&
2053 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2054 monitor_printf(mon, " dst <any mcast/bcast>");
2055 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2056 (mask->has_eth_dst) &&
2057 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2058 monitor_printf(mon, " dst <any ucast>");
2059 } else {
2060 monitor_printf(mon, " dst %s", key->eth_dst);
2061 if (mask->has_eth_dst) {
2062 monitor_printf(mon, "(%s)", mask->eth_dst);
2067 if (key->has_ip_proto) {
2068 monitor_printf(mon, " proto %d", key->ip_proto);
2069 if (mask->has_ip_proto) {
2070 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2074 if (key->has_ip_tos) {
2075 monitor_printf(mon, " TOS %d", key->ip_tos);
2076 if (mask->has_ip_tos) {
2077 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2081 if (key->has_ip_dst) {
2082 monitor_printf(mon, " dst %s", key->ip_dst);
2085 if (action->has_goto_tbl || action->has_group_id ||
2086 action->has_new_vlan_id) {
2087 monitor_printf(mon, " -->");
2090 if (action->has_new_vlan_id) {
2091 monitor_printf(mon, " apply new vlan %d",
2092 ntohs(action->new_vlan_id));
2095 if (action->has_group_id) {
2096 monitor_printf(mon, " write group 0x%08x", action->group_id);
2099 if (action->has_goto_tbl) {
2100 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2103 monitor_printf(mon, "\n");
2106 qapi_free_RockerOfDpaFlowList(list);
2109 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2111 RockerOfDpaGroupList *list, *g;
2112 const char *name = qdict_get_str(qdict, "name");
2113 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2114 Error *err = NULL;
2116 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2117 if (hmp_handle_error(mon, err)) {
2118 return;
2121 monitor_printf(mon, "id (decode) --> buckets\n");
2123 for (g = list; g; g = g->next) {
2124 RockerOfDpaGroup *group = g->value;
2125 bool set = false;
2127 monitor_printf(mon, "0x%08x", group->id);
2129 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2130 group->type == 1 ? "L2 rewrite" :
2131 group->type == 2 ? "L3 unicast" :
2132 group->type == 3 ? "L2 multicast" :
2133 group->type == 4 ? "L2 flood" :
2134 group->type == 5 ? "L3 interface" :
2135 group->type == 6 ? "L3 multicast" :
2136 group->type == 7 ? "L3 ECMP" :
2137 group->type == 8 ? "L2 overlay" :
2138 "unknown");
2140 if (group->has_vlan_id) {
2141 monitor_printf(mon, " vlan %d", group->vlan_id);
2144 if (group->has_pport) {
2145 monitor_printf(mon, " pport %d", group->pport);
2148 if (group->has_index) {
2149 monitor_printf(mon, " index %d", group->index);
2152 monitor_printf(mon, ") -->");
2154 if (group->has_set_vlan_id && group->set_vlan_id) {
2155 set = true;
2156 monitor_printf(mon, " set vlan %d",
2157 group->set_vlan_id & VLAN_VID_MASK);
2160 if (group->has_set_eth_src) {
2161 if (!set) {
2162 set = true;
2163 monitor_printf(mon, " set");
2165 monitor_printf(mon, " src %s", group->set_eth_src);
2168 if (group->has_set_eth_dst) {
2169 if (!set) {
2170 monitor_printf(mon, " set");
2172 monitor_printf(mon, " dst %s", group->set_eth_dst);
2175 if (group->has_ttl_check && group->ttl_check) {
2176 monitor_printf(mon, " check TTL");
2179 if (group->has_group_id && group->group_id) {
2180 monitor_printf(mon, " group id 0x%08x", group->group_id);
2183 if (group->has_pop_vlan && group->pop_vlan) {
2184 monitor_printf(mon, " pop vlan");
2187 if (group->has_out_pport) {
2188 monitor_printf(mon, " out pport %d", group->out_pport);
2191 if (group->has_group_ids) {
2192 struct uint32List *id;
2194 monitor_printf(mon, " groups [");
2195 for (id = group->group_ids; id; id = id->next) {
2196 monitor_printf(mon, "0x%08x", id->value);
2197 if (id->next) {
2198 monitor_printf(mon, ",");
2201 monitor_printf(mon, "]");
2204 monitor_printf(mon, "\n");
2207 qapi_free_RockerOfDpaGroupList(list);
2210 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
2212 Error *err = NULL;
2213 GuidInfo *info = qmp_query_vm_generation_id(&err);
2214 if (info) {
2215 monitor_printf(mon, "%s\n", info->guid);
2217 hmp_handle_error(mon, err);
2218 qapi_free_GuidInfo(info);
2221 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
2223 Error *err = NULL;
2224 MemoryInfo *info = qmp_query_memory_size_summary(&err);
2225 if (info) {
2226 monitor_printf(mon, "base memory: %" PRIu64 "\n",
2227 info->base_memory);
2229 if (info->has_plugged_memory) {
2230 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
2231 info->plugged_memory);
2234 qapi_free_MemoryInfo(info);
2236 hmp_handle_error(mon, err);
2239 static void print_stats_schema_value(Monitor *mon, StatsSchemaValue *value)
2241 const char *unit = NULL;
2242 monitor_printf(mon, " %s (%s%s", value->name, StatsType_str(value->type),
2243 value->has_unit || value->exponent ? ", " : "");
2245 if (value->has_unit) {
2246 if (value->unit == STATS_UNIT_SECONDS) {
2247 unit = "s";
2248 } else if (value->unit == STATS_UNIT_BYTES) {
2249 unit = "B";
2253 if (unit && value->base == 10 &&
2254 value->exponent >= -18 && value->exponent <= 18 &&
2255 value->exponent % 3 == 0) {
2256 monitor_printf(mon, "%s", si_prefix(value->exponent));
2257 } else if (unit && value->base == 2 &&
2258 value->exponent >= 0 && value->exponent <= 60 &&
2259 value->exponent % 10 == 0) {
2261 monitor_printf(mon, "%s", iec_binary_prefix(value->exponent));
2262 } else if (value->exponent) {
2263 /* Use exponential notation and write the unit's English name */
2264 monitor_printf(mon, "* %d^%d%s",
2265 value->base, value->exponent,
2266 value->has_unit ? " " : "");
2267 unit = NULL;
2270 if (value->has_unit) {
2271 monitor_printf(mon, "%s", unit ? unit : StatsUnit_str(value->unit));
2274 /* Print bucket size for linear histograms */
2275 if (value->type == STATS_TYPE_LINEAR_HISTOGRAM && value->has_bucket_size) {
2276 monitor_printf(mon, ", bucket size=%d", value->bucket_size);
2278 monitor_printf(mon, ")");
2281 static StatsSchemaValueList *find_schema_value_list(
2282 StatsSchemaList *list, StatsProvider provider,
2283 StatsTarget target)
2285 StatsSchemaList *node;
2287 for (node = list; node; node = node->next) {
2288 if (node->value->provider == provider &&
2289 node->value->target == target) {
2290 return node->value->stats;
2293 return NULL;
2296 static void print_stats_results(Monitor *mon, StatsTarget target,
2297 bool show_provider,
2298 StatsResult *result,
2299 StatsSchemaList *schema)
2301 /* Find provider schema */
2302 StatsSchemaValueList *schema_value_list =
2303 find_schema_value_list(schema, result->provider, target);
2304 StatsList *stats_list;
2306 if (!schema_value_list) {
2307 monitor_printf(mon, "failed to find schema list for %s\n",
2308 StatsProvider_str(result->provider));
2309 return;
2312 if (show_provider) {
2313 monitor_printf(mon, "provider: %s\n",
2314 StatsProvider_str(result->provider));
2317 for (stats_list = result->stats; stats_list;
2318 stats_list = stats_list->next,
2319 schema_value_list = schema_value_list->next) {
2321 Stats *stats = stats_list->value;
2322 StatsValue *stats_value = stats->value;
2323 StatsSchemaValue *schema_value = schema_value_list->value;
2325 /* Find schema entry */
2326 while (!g_str_equal(stats->name, schema_value->name)) {
2327 if (!schema_value_list->next) {
2328 monitor_printf(mon, "failed to find schema entry for %s\n",
2329 stats->name);
2330 return;
2332 schema_value_list = schema_value_list->next;
2333 schema_value = schema_value_list->value;
2336 print_stats_schema_value(mon, schema_value);
2338 if (stats_value->type == QTYPE_QNUM) {
2339 monitor_printf(mon, ": %" PRId64 "\n", stats_value->u.scalar);
2340 } else if (stats_value->type == QTYPE_QLIST) {
2341 uint64List *list;
2342 int i;
2344 monitor_printf(mon, ": ");
2345 for (list = stats_value->u.list, i = 1;
2346 list;
2347 list = list->next, i++) {
2348 monitor_printf(mon, "[%d]=%" PRId64 " ", i, list->value);
2350 monitor_printf(mon, "\n");
2355 /* Create the StatsFilter that is needed for an "info stats" invocation. */
2356 static StatsFilter *stats_filter(StatsTarget target, const char *names,
2357 int cpu_index, StatsProvider provider)
2359 StatsFilter *filter = g_malloc0(sizeof(*filter));
2360 StatsProvider provider_idx;
2361 StatsRequestList *request_list = NULL;
2363 filter->target = target;
2364 switch (target) {
2365 case STATS_TARGET_VM:
2366 break;
2367 case STATS_TARGET_VCPU:
2369 strList *vcpu_list = NULL;
2370 CPUState *cpu = qemu_get_cpu(cpu_index);
2371 char *canonical_path = object_get_canonical_path(OBJECT(cpu));
2373 QAPI_LIST_PREPEND(vcpu_list, canonical_path);
2374 filter->u.vcpu.has_vcpus = true;
2375 filter->u.vcpu.vcpus = vcpu_list;
2376 break;
2378 default:
2379 break;
2382 if (!names && provider == STATS_PROVIDER__MAX) {
2383 return filter;
2387 * "info stats" can only query either one or all the providers. Querying
2388 * by name, but not by provider, requires the creation of one filter per
2389 * provider.
2391 for (provider_idx = 0; provider_idx < STATS_PROVIDER__MAX; provider_idx++) {
2392 if (provider == STATS_PROVIDER__MAX || provider == provider_idx) {
2393 StatsRequest *request = g_new0(StatsRequest, 1);
2394 request->provider = provider_idx;
2395 if (names && !g_str_equal(names, "*")) {
2396 request->has_names = true;
2397 request->names = strList_from_comma_list(names);
2399 QAPI_LIST_PREPEND(request_list, request);
2403 filter->has_providers = true;
2404 filter->providers = request_list;
2405 return filter;
2408 void hmp_info_stats(Monitor *mon, const QDict *qdict)
2410 const char *target_str = qdict_get_str(qdict, "target");
2411 const char *provider_str = qdict_get_try_str(qdict, "provider");
2412 const char *names = qdict_get_try_str(qdict, "names");
2414 StatsProvider provider = STATS_PROVIDER__MAX;
2415 StatsTarget target;
2416 Error *err = NULL;
2417 g_autoptr(StatsSchemaList) schema = NULL;
2418 g_autoptr(StatsResultList) stats = NULL;
2419 g_autoptr(StatsFilter) filter = NULL;
2420 StatsResultList *entry;
2422 target = qapi_enum_parse(&StatsTarget_lookup, target_str, -1, &err);
2423 if (err) {
2424 monitor_printf(mon, "invalid stats target %s\n", target_str);
2425 goto exit_no_print;
2427 if (provider_str) {
2428 provider = qapi_enum_parse(&StatsProvider_lookup, provider_str, -1, &err);
2429 if (err) {
2430 monitor_printf(mon, "invalid stats provider %s\n", provider_str);
2431 goto exit_no_print;
2435 schema = qmp_query_stats_schemas(provider_str ? true : false,
2436 provider, &err);
2437 if (err) {
2438 goto exit;
2441 switch (target) {
2442 case STATS_TARGET_VM:
2443 filter = stats_filter(target, names, -1, provider);
2444 break;
2445 case STATS_TARGET_VCPU: {}
2446 int cpu_index = monitor_get_cpu_index(mon);
2447 filter = stats_filter(target, names, cpu_index, provider);
2448 break;
2449 default:
2450 abort();
2453 stats = qmp_query_stats(filter, &err);
2454 if (err) {
2455 goto exit;
2457 for (entry = stats; entry; entry = entry->next) {
2458 print_stats_results(mon, target, provider_str == NULL, entry->value, schema);
2461 exit:
2462 if (err) {
2463 monitor_printf(mon, "%s\n", error_get_pretty(err));
2465 exit_no_print:
2466 error_free(err);