tests/acpi: allow changes for microvm/APIC.pcie
[qemu/ar7.git] / monitor / hmp-cmds.c
blob9789f4277f50e7d91d3a90aa165a62b0e47e1f28
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 "monitor/monitor-internal.h"
28 #include "qapi/error.h"
29 #include "qapi/clone-visitor.h"
30 #include "qapi/opts-visitor.h"
31 #include "qapi/qapi-builtin-visit.h"
32 #include "qapi/qapi-commands-block.h"
33 #include "qapi/qapi-commands-char.h"
34 #include "qapi/qapi-commands-control.h"
35 #include "qapi/qapi-commands-machine.h"
36 #include "qapi/qapi-commands-migration.h"
37 #include "qapi/qapi-commands-misc.h"
38 #include "qapi/qapi-commands-net.h"
39 #include "qapi/qapi-commands-pci.h"
40 #include "qapi/qapi-commands-rocker.h"
41 #include "qapi/qapi-commands-run-state.h"
42 #include "qapi/qapi-commands-tpm.h"
43 #include "qapi/qapi-commands-ui.h"
44 #include "qapi/qapi-visit-net.h"
45 #include "qapi/qapi-visit-migration.h"
46 #include "qapi/qmp/qdict.h"
47 #include "qapi/qmp/qerror.h"
48 #include "qapi/string-input-visitor.h"
49 #include "qapi/string-output-visitor.h"
50 #include "qom/object_interfaces.h"
51 #include "ui/console.h"
52 #include "qemu/cutils.h"
53 #include "qemu/error-report.h"
54 #include "exec/ramlist.h"
55 #include "hw/intc/intc.h"
56 #include "hw/rdma/rdma.h"
57 #include "migration/snapshot.h"
58 #include "migration/misc.h"
60 #ifdef CONFIG_SPICE
61 #include <spice/enums.h>
62 #endif
64 void hmp_handle_error(Monitor *mon, Error *err)
66 if (err) {
67 error_reportf_err(err, "Error: ");
72 * Produce a strList from a comma separated list.
73 * A NULL or empty input string return NULL.
75 static strList *strList_from_comma_list(const char *in)
77 strList *res = NULL;
78 strList **hook = &res;
80 while (in && in[0]) {
81 char *comma = strchr(in, ',');
82 *hook = g_new0(strList, 1);
84 if (comma) {
85 (*hook)->value = g_strndup(in, comma - in);
86 in = comma + 1; /* skip the , */
87 } else {
88 (*hook)->value = g_strdup(in);
89 in = NULL;
91 hook = &(*hook)->next;
94 return res;
97 void hmp_info_name(Monitor *mon, const QDict *qdict)
99 NameInfo *info;
101 info = qmp_query_name(NULL);
102 if (info->has_name) {
103 monitor_printf(mon, "%s\n", info->name);
105 qapi_free_NameInfo(info);
108 void hmp_info_version(Monitor *mon, const QDict *qdict)
110 VersionInfo *info;
112 info = qmp_query_version(NULL);
114 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
115 info->qemu->major, info->qemu->minor, info->qemu->micro,
116 info->package);
118 qapi_free_VersionInfo(info);
121 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
123 KvmInfo *info;
125 info = qmp_query_kvm(NULL);
126 monitor_printf(mon, "kvm support: ");
127 if (info->present) {
128 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
129 } else {
130 monitor_printf(mon, "not compiled\n");
133 qapi_free_KvmInfo(info);
136 void hmp_info_status(Monitor *mon, const QDict *qdict)
138 StatusInfo *info;
140 info = qmp_query_status(NULL);
142 monitor_printf(mon, "VM status: %s%s",
143 info->running ? "running" : "paused",
144 info->singlestep ? " (single step mode)" : "");
146 if (!info->running && info->status != RUN_STATE_PAUSED) {
147 monitor_printf(mon, " (%s)", RunState_str(info->status));
150 monitor_printf(mon, "\n");
152 qapi_free_StatusInfo(info);
155 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
157 UuidInfo *info;
159 info = qmp_query_uuid(NULL);
160 monitor_printf(mon, "%s\n", info->UUID);
161 qapi_free_UuidInfo(info);
164 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
166 ChardevInfoList *char_info, *info;
168 char_info = qmp_query_chardev(NULL);
169 for (info = char_info; info; info = info->next) {
170 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
171 info->value->filename);
174 qapi_free_ChardevInfoList(char_info);
177 void hmp_info_mice(Monitor *mon, const QDict *qdict)
179 MouseInfoList *mice_list, *mouse;
181 mice_list = qmp_query_mice(NULL);
182 if (!mice_list) {
183 monitor_printf(mon, "No mouse devices connected\n");
184 return;
187 for (mouse = mice_list; mouse; mouse = mouse->next) {
188 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
189 mouse->value->current ? '*' : ' ',
190 mouse->value->index, mouse->value->name,
191 mouse->value->absolute ? " (absolute)" : "");
194 qapi_free_MouseInfoList(mice_list);
197 static char *SocketAddress_to_str(SocketAddress *addr)
199 switch (addr->type) {
200 case SOCKET_ADDRESS_TYPE_INET:
201 return g_strdup_printf("tcp:%s:%s",
202 addr->u.inet.host,
203 addr->u.inet.port);
204 case SOCKET_ADDRESS_TYPE_UNIX:
205 return g_strdup_printf("unix:%s",
206 addr->u.q_unix.path);
207 case SOCKET_ADDRESS_TYPE_FD:
208 return g_strdup_printf("fd:%s", addr->u.fd.str);
209 case SOCKET_ADDRESS_TYPE_VSOCK:
210 return g_strdup_printf("tcp:%s:%s",
211 addr->u.vsock.cid,
212 addr->u.vsock.port);
213 default:
214 return g_strdup("unknown address type");
218 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
220 MigrationInfo *info;
222 info = qmp_query_migrate(NULL);
224 migration_global_dump(mon);
226 if (info->has_status) {
227 monitor_printf(mon, "Migration status: %s",
228 MigrationStatus_str(info->status));
229 if (info->status == MIGRATION_STATUS_FAILED &&
230 info->has_error_desc) {
231 monitor_printf(mon, " (%s)\n", info->error_desc);
232 } else {
233 monitor_printf(mon, "\n");
236 monitor_printf(mon, "total time: %" PRIu64 " ms\n",
237 info->total_time);
238 if (info->has_expected_downtime) {
239 monitor_printf(mon, "expected downtime: %" PRIu64 " ms\n",
240 info->expected_downtime);
242 if (info->has_downtime) {
243 monitor_printf(mon, "downtime: %" PRIu64 " ms\n",
244 info->downtime);
246 if (info->has_setup_time) {
247 monitor_printf(mon, "setup: %" PRIu64 " ms\n",
248 info->setup_time);
252 if (info->has_ram) {
253 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
254 info->ram->transferred >> 10);
255 monitor_printf(mon, "throughput: %0.2f mbps\n",
256 info->ram->mbps);
257 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
258 info->ram->remaining >> 10);
259 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
260 info->ram->total >> 10);
261 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
262 info->ram->duplicate);
263 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
264 info->ram->skipped);
265 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
266 info->ram->normal);
267 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
268 info->ram->normal_bytes >> 10);
269 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
270 info->ram->dirty_sync_count);
271 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
272 info->ram->page_size >> 10);
273 monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n",
274 info->ram->multifd_bytes >> 10);
275 monitor_printf(mon, "pages-per-second: %" PRIu64 "\n",
276 info->ram->pages_per_second);
278 if (info->ram->dirty_pages_rate) {
279 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
280 info->ram->dirty_pages_rate);
282 if (info->ram->postcopy_requests) {
283 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
284 info->ram->postcopy_requests);
288 if (info->has_disk) {
289 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
290 info->disk->transferred >> 10);
291 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
292 info->disk->remaining >> 10);
293 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
294 info->disk->total >> 10);
297 if (info->has_xbzrle_cache) {
298 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
299 info->xbzrle_cache->cache_size);
300 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
301 info->xbzrle_cache->bytes >> 10);
302 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
303 info->xbzrle_cache->pages);
304 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 " pages\n",
305 info->xbzrle_cache->cache_miss);
306 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
307 info->xbzrle_cache->cache_miss_rate);
308 monitor_printf(mon, "xbzrle encoding rate: %0.2f\n",
309 info->xbzrle_cache->encoding_rate);
310 monitor_printf(mon, "xbzrle overflow: %" PRIu64 "\n",
311 info->xbzrle_cache->overflow);
314 if (info->has_compression) {
315 monitor_printf(mon, "compression pages: %" PRIu64 " pages\n",
316 info->compression->pages);
317 monitor_printf(mon, "compression busy: %" PRIu64 "\n",
318 info->compression->busy);
319 monitor_printf(mon, "compression busy rate: %0.2f\n",
320 info->compression->busy_rate);
321 monitor_printf(mon, "compressed size: %" PRIu64 " kbytes\n",
322 info->compression->compressed_size >> 10);
323 monitor_printf(mon, "compression rate: %0.2f\n",
324 info->compression->compression_rate);
327 if (info->has_cpu_throttle_percentage) {
328 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
329 info->cpu_throttle_percentage);
332 if (info->has_postcopy_blocktime) {
333 monitor_printf(mon, "postcopy blocktime: %u\n",
334 info->postcopy_blocktime);
337 if (info->has_postcopy_vcpu_blocktime) {
338 Visitor *v;
339 char *str;
340 v = string_output_visitor_new(false, &str);
341 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime,
342 &error_abort);
343 visit_complete(v, &str);
344 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
345 g_free(str);
346 visit_free(v);
348 if (info->has_socket_address) {
349 SocketAddressList *addr;
351 monitor_printf(mon, "socket address: [\n");
353 for (addr = info->socket_address; addr; addr = addr->next) {
354 char *s = SocketAddress_to_str(addr->value);
355 monitor_printf(mon, "\t%s\n", s);
356 g_free(s);
358 monitor_printf(mon, "]\n");
360 qapi_free_MigrationInfo(info);
363 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
365 MigrationCapabilityStatusList *caps, *cap;
367 caps = qmp_query_migrate_capabilities(NULL);
369 if (caps) {
370 for (cap = caps; cap; cap = cap->next) {
371 monitor_printf(mon, "%s: %s\n",
372 MigrationCapability_str(cap->value->capability),
373 cap->value->state ? "on" : "off");
377 qapi_free_MigrationCapabilityStatusList(caps);
380 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
382 MigrationParameters *params;
384 params = qmp_query_migrate_parameters(NULL);
386 if (params) {
387 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
388 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL),
389 params->announce_initial);
390 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
391 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX),
392 params->announce_max);
393 monitor_printf(mon, "%s: %" PRIu64 "\n",
394 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS),
395 params->announce_rounds);
396 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
397 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP),
398 params->announce_step);
399 assert(params->has_compress_level);
400 monitor_printf(mon, "%s: %u\n",
401 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
402 params->compress_level);
403 assert(params->has_compress_threads);
404 monitor_printf(mon, "%s: %u\n",
405 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
406 params->compress_threads);
407 assert(params->has_compress_wait_thread);
408 monitor_printf(mon, "%s: %s\n",
409 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD),
410 params->compress_wait_thread ? "on" : "off");
411 assert(params->has_decompress_threads);
412 monitor_printf(mon, "%s: %u\n",
413 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
414 params->decompress_threads);
415 assert(params->has_throttle_trigger_threshold);
416 monitor_printf(mon, "%s: %u\n",
417 MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD),
418 params->throttle_trigger_threshold);
419 assert(params->has_cpu_throttle_initial);
420 monitor_printf(mon, "%s: %u\n",
421 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
422 params->cpu_throttle_initial);
423 assert(params->has_cpu_throttle_increment);
424 monitor_printf(mon, "%s: %u\n",
425 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
426 params->cpu_throttle_increment);
427 assert(params->has_cpu_throttle_tailslow);
428 monitor_printf(mon, "%s: %s\n",
429 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW),
430 params->cpu_throttle_tailslow ? "on" : "off");
431 assert(params->has_max_cpu_throttle);
432 monitor_printf(mon, "%s: %u\n",
433 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE),
434 params->max_cpu_throttle);
435 assert(params->has_tls_creds);
436 monitor_printf(mon, "%s: '%s'\n",
437 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
438 params->tls_creds);
439 assert(params->has_tls_hostname);
440 monitor_printf(mon, "%s: '%s'\n",
441 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
442 params->tls_hostname);
443 assert(params->has_max_bandwidth);
444 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
445 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
446 params->max_bandwidth);
447 assert(params->has_downtime_limit);
448 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
449 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
450 params->downtime_limit);
451 assert(params->has_x_checkpoint_delay);
452 monitor_printf(mon, "%s: %u ms\n",
453 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
454 params->x_checkpoint_delay);
455 assert(params->has_block_incremental);
456 monitor_printf(mon, "%s: %s\n",
457 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
458 params->block_incremental ? "on" : "off");
459 monitor_printf(mon, "%s: %u\n",
460 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS),
461 params->multifd_channels);
462 monitor_printf(mon, "%s: %s\n",
463 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION),
464 MultiFDCompression_str(params->multifd_compression));
465 monitor_printf(mon, "%s: %" PRIu64 " bytes\n",
466 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
467 params->xbzrle_cache_size);
468 monitor_printf(mon, "%s: %" PRIu64 "\n",
469 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
470 params->max_postcopy_bandwidth);
471 monitor_printf(mon, "%s: '%s'\n",
472 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
473 params->tls_authz);
475 if (params->has_block_bitmap_mapping) {
476 const BitmapMigrationNodeAliasList *bmnal;
478 monitor_printf(mon, "%s:\n",
479 MigrationParameter_str(
480 MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING));
482 for (bmnal = params->block_bitmap_mapping;
483 bmnal;
484 bmnal = bmnal->next)
486 const BitmapMigrationNodeAlias *bmna = bmnal->value;
487 const BitmapMigrationBitmapAliasList *bmbal;
489 monitor_printf(mon, " '%s' -> '%s'\n",
490 bmna->node_name, bmna->alias);
492 for (bmbal = bmna->bitmaps; bmbal; bmbal = bmbal->next) {
493 const BitmapMigrationBitmapAlias *bmba = bmbal->value;
495 monitor_printf(mon, " '%s' -> '%s'\n",
496 bmba->name, bmba->alias);
502 qapi_free_MigrationParameters(params);
505 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
507 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
508 qmp_query_migrate_cache_size(NULL) >> 10);
512 #ifdef CONFIG_VNC
513 /* Helper for hmp_info_vnc_clients, _servers */
514 static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
515 const char *name)
517 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
518 name,
519 info->host,
520 info->service,
521 NetworkAddressFamily_str(info->family),
522 info->websocket ? " (Websocket)" : "");
525 /* Helper displaying and auth and crypt info */
526 static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
527 VncPrimaryAuth auth,
528 VncVencryptSubAuth *vencrypt)
530 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
531 VncPrimaryAuth_str(auth),
532 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
535 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
537 while (client) {
538 VncClientInfo *cinfo = client->value;
540 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
541 monitor_printf(mon, " x509_dname: %s\n",
542 cinfo->has_x509_dname ?
543 cinfo->x509_dname : "none");
544 monitor_printf(mon, " sasl_username: %s\n",
545 cinfo->has_sasl_username ?
546 cinfo->sasl_username : "none");
548 client = client->next;
552 static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
554 while (server) {
555 VncServerInfo2 *sinfo = server->value;
556 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
557 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
558 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
559 server = server->next;
563 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
565 VncInfo2List *info2l, *info2l_head;
566 Error *err = NULL;
568 info2l = qmp_query_vnc_servers(&err);
569 info2l_head = info2l;
570 if (err) {
571 hmp_handle_error(mon, err);
572 return;
574 if (!info2l) {
575 monitor_printf(mon, "None\n");
576 return;
579 while (info2l) {
580 VncInfo2 *info = info2l->value;
581 monitor_printf(mon, "%s:\n", info->id);
582 hmp_info_vnc_servers(mon, info->server);
583 hmp_info_vnc_clients(mon, info->clients);
584 if (!info->server) {
585 /* The server entry displays its auth, we only
586 * need to display in the case of 'reverse' connections
587 * where there's no server.
589 hmp_info_vnc_authcrypt(mon, " ", info->auth,
590 info->has_vencrypt ? &info->vencrypt : NULL);
592 if (info->has_display) {
593 monitor_printf(mon, " Display: %s\n", info->display);
595 info2l = info2l->next;
598 qapi_free_VncInfo2List(info2l_head);
601 #endif
603 #ifdef CONFIG_SPICE
604 void hmp_info_spice(Monitor *mon, const QDict *qdict)
606 SpiceChannelList *chan;
607 SpiceInfo *info;
608 const char *channel_name;
609 const char * const channel_names[] = {
610 [SPICE_CHANNEL_MAIN] = "main",
611 [SPICE_CHANNEL_DISPLAY] = "display",
612 [SPICE_CHANNEL_INPUTS] = "inputs",
613 [SPICE_CHANNEL_CURSOR] = "cursor",
614 [SPICE_CHANNEL_PLAYBACK] = "playback",
615 [SPICE_CHANNEL_RECORD] = "record",
616 [SPICE_CHANNEL_TUNNEL] = "tunnel",
617 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
618 [SPICE_CHANNEL_USBREDIR] = "usbredir",
619 [SPICE_CHANNEL_PORT] = "port",
620 #if 0
621 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
622 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
623 * as quick fix for build failures with older versions. */
624 [SPICE_CHANNEL_WEBDAV] = "webdav",
625 #endif
628 info = qmp_query_spice(NULL);
630 if (!info->enabled) {
631 monitor_printf(mon, "Server: disabled\n");
632 goto out;
635 monitor_printf(mon, "Server:\n");
636 if (info->has_port) {
637 monitor_printf(mon, " address: %s:%" PRId64 "\n",
638 info->host, info->port);
640 if (info->has_tls_port) {
641 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
642 info->host, info->tls_port);
644 monitor_printf(mon, " migrated: %s\n",
645 info->migrated ? "true" : "false");
646 monitor_printf(mon, " auth: %s\n", info->auth);
647 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
648 monitor_printf(mon, " mouse-mode: %s\n",
649 SpiceQueryMouseMode_str(info->mouse_mode));
651 if (!info->has_channels || info->channels == NULL) {
652 monitor_printf(mon, "Channels: none\n");
653 } else {
654 for (chan = info->channels; chan; chan = chan->next) {
655 monitor_printf(mon, "Channel:\n");
656 monitor_printf(mon, " address: %s:%s%s\n",
657 chan->value->host, chan->value->port,
658 chan->value->tls ? " [tls]" : "");
659 monitor_printf(mon, " session: %" PRId64 "\n",
660 chan->value->connection_id);
661 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
662 chan->value->channel_type, chan->value->channel_id);
664 channel_name = "unknown";
665 if (chan->value->channel_type > 0 &&
666 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
667 channel_names[chan->value->channel_type]) {
668 channel_name = channel_names[chan->value->channel_type];
671 monitor_printf(mon, " channel name: %s\n", channel_name);
675 out:
676 qapi_free_SpiceInfo(info);
678 #endif
680 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
682 BalloonInfo *info;
683 Error *err = NULL;
685 info = qmp_query_balloon(&err);
686 if (err) {
687 hmp_handle_error(mon, err);
688 return;
691 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
693 qapi_free_BalloonInfo(info);
696 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
698 PciMemoryRegionList *region;
700 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
701 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
702 dev->slot, dev->function);
703 monitor_printf(mon, " ");
705 if (dev->class_info->has_desc) {
706 monitor_printf(mon, "%s", dev->class_info->desc);
707 } else {
708 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
711 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
712 dev->id->vendor, dev->id->device);
713 if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) {
714 monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n",
715 dev->id->subsystem_vendor, dev->id->subsystem);
718 if (dev->has_irq) {
719 monitor_printf(mon, " IRQ %" PRId64 ", pin %c\n",
720 dev->irq, (char)('A' + dev->irq_pin - 1));
723 if (dev->has_pci_bridge) {
724 monitor_printf(mon, " BUS %" PRId64 ".\n",
725 dev->pci_bridge->bus->number);
726 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
727 dev->pci_bridge->bus->secondary);
728 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
729 dev->pci_bridge->bus->subordinate);
731 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
732 dev->pci_bridge->bus->io_range->base,
733 dev->pci_bridge->bus->io_range->limit);
735 monitor_printf(mon,
736 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
737 dev->pci_bridge->bus->memory_range->base,
738 dev->pci_bridge->bus->memory_range->limit);
740 monitor_printf(mon, " prefetchable memory range "
741 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
742 dev->pci_bridge->bus->prefetchable_range->base,
743 dev->pci_bridge->bus->prefetchable_range->limit);
746 for (region = dev->regions; region; region = region->next) {
747 uint64_t addr, size;
749 addr = region->value->address;
750 size = region->value->size;
752 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
754 if (!strcmp(region->value->type, "io")) {
755 monitor_printf(mon, "I/O at 0x%04" PRIx64
756 " [0x%04" PRIx64 "].\n",
757 addr, addr + size - 1);
758 } else {
759 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
760 " [0x%08" PRIx64 "].\n",
761 region->value->mem_type_64 ? 64 : 32,
762 region->value->prefetch ? " prefetchable" : "",
763 addr, addr + size - 1);
767 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
769 if (dev->has_pci_bridge) {
770 if (dev->pci_bridge->has_devices) {
771 PciDeviceInfoList *cdev;
772 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
773 hmp_info_pci_device(mon, cdev->value);
779 static int hmp_info_irq_foreach(Object *obj, void *opaque)
781 InterruptStatsProvider *intc;
782 InterruptStatsProviderClass *k;
783 Monitor *mon = opaque;
785 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
786 intc = INTERRUPT_STATS_PROVIDER(obj);
787 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
788 uint64_t *irq_counts;
789 unsigned int nb_irqs, i;
790 if (k->get_statistics &&
791 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
792 if (nb_irqs > 0) {
793 monitor_printf(mon, "IRQ statistics for %s:\n",
794 object_get_typename(obj));
795 for (i = 0; i < nb_irqs; i++) {
796 if (irq_counts[i] > 0) {
797 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
798 irq_counts[i]);
802 } else {
803 monitor_printf(mon, "IRQ statistics not available for %s.\n",
804 object_get_typename(obj));
808 return 0;
811 void hmp_info_irq(Monitor *mon, const QDict *qdict)
813 object_child_foreach_recursive(object_get_root(),
814 hmp_info_irq_foreach, mon);
817 static int hmp_info_pic_foreach(Object *obj, void *opaque)
819 InterruptStatsProvider *intc;
820 InterruptStatsProviderClass *k;
821 Monitor *mon = opaque;
823 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
824 intc = INTERRUPT_STATS_PROVIDER(obj);
825 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
826 if (k->print_info) {
827 k->print_info(intc, mon);
828 } else {
829 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
830 object_get_typename(obj));
834 return 0;
837 void hmp_info_pic(Monitor *mon, const QDict *qdict)
839 object_child_foreach_recursive(object_get_root(),
840 hmp_info_pic_foreach, mon);
843 static int hmp_info_rdma_foreach(Object *obj, void *opaque)
845 RdmaProvider *rdma;
846 RdmaProviderClass *k;
847 Monitor *mon = opaque;
849 if (object_dynamic_cast(obj, INTERFACE_RDMA_PROVIDER)) {
850 rdma = RDMA_PROVIDER(obj);
851 k = RDMA_PROVIDER_GET_CLASS(obj);
852 if (k->print_statistics) {
853 k->print_statistics(mon, rdma);
854 } else {
855 monitor_printf(mon, "RDMA statistics not available for %s.\n",
856 object_get_typename(obj));
860 return 0;
863 void hmp_info_rdma(Monitor *mon, const QDict *qdict)
865 object_child_foreach_recursive(object_get_root(),
866 hmp_info_rdma_foreach, mon);
869 void hmp_info_pci(Monitor *mon, const QDict *qdict)
871 PciInfoList *info_list, *info;
872 Error *err = NULL;
874 info_list = qmp_query_pci(&err);
875 if (err) {
876 monitor_printf(mon, "PCI devices not supported\n");
877 error_free(err);
878 return;
881 for (info = info_list; info; info = info->next) {
882 PciDeviceInfoList *dev;
884 for (dev = info->value->devices; dev; dev = dev->next) {
885 hmp_info_pci_device(mon, dev->value);
889 qapi_free_PciInfoList(info_list);
892 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
894 TPMInfoList *info_list, *info;
895 Error *err = NULL;
896 unsigned int c = 0;
897 TPMPassthroughOptions *tpo;
898 TPMEmulatorOptions *teo;
900 info_list = qmp_query_tpm(&err);
901 if (err) {
902 monitor_printf(mon, "TPM device not supported\n");
903 error_free(err);
904 return;
907 if (info_list) {
908 monitor_printf(mon, "TPM device:\n");
911 for (info = info_list; info; info = info->next) {
912 TPMInfo *ti = info->value;
913 monitor_printf(mon, " tpm%d: model=%s\n",
914 c, TpmModel_str(ti->model));
916 monitor_printf(mon, " \\ %s: type=%s",
917 ti->id, TpmTypeOptionsKind_str(ti->options->type));
919 switch (ti->options->type) {
920 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
921 tpo = ti->options->u.passthrough.data;
922 monitor_printf(mon, "%s%s%s%s",
923 tpo->has_path ? ",path=" : "",
924 tpo->has_path ? tpo->path : "",
925 tpo->has_cancel_path ? ",cancel-path=" : "",
926 tpo->has_cancel_path ? tpo->cancel_path : "");
927 break;
928 case TPM_TYPE_OPTIONS_KIND_EMULATOR:
929 teo = ti->options->u.emulator.data;
930 monitor_printf(mon, ",chardev=%s", teo->chardev);
931 break;
932 case TPM_TYPE_OPTIONS_KIND__MAX:
933 break;
935 monitor_printf(mon, "\n");
936 c++;
938 qapi_free_TPMInfoList(info_list);
941 void hmp_quit(Monitor *mon, const QDict *qdict)
943 monitor_suspend(mon);
944 qmp_quit(NULL);
947 void hmp_stop(Monitor *mon, const QDict *qdict)
949 qmp_stop(NULL);
952 void hmp_sync_profile(Monitor *mon, const QDict *qdict)
954 const char *op = qdict_get_try_str(qdict, "op");
956 if (op == NULL) {
957 bool on = qsp_is_enabled();
959 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off");
960 return;
962 if (!strcmp(op, "on")) {
963 qsp_enable();
964 } else if (!strcmp(op, "off")) {
965 qsp_disable();
966 } else if (!strcmp(op, "reset")) {
967 qsp_reset();
968 } else {
969 Error *err = NULL;
971 error_setg(&err, QERR_INVALID_PARAMETER, op);
972 hmp_handle_error(mon, err);
976 void hmp_system_reset(Monitor *mon, const QDict *qdict)
978 qmp_system_reset(NULL);
981 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
983 qmp_system_powerdown(NULL);
986 void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
988 Error *err = NULL;
990 qmp_x_exit_preconfig(&err);
991 hmp_handle_error(mon, err);
994 void hmp_cpu(Monitor *mon, const QDict *qdict)
996 int64_t cpu_index;
998 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
999 use it are converted to the QAPI */
1000 cpu_index = qdict_get_int(qdict, "index");
1001 if (monitor_set_cpu(mon, cpu_index) < 0) {
1002 monitor_printf(mon, "invalid CPU index\n");
1006 void hmp_memsave(Monitor *mon, const QDict *qdict)
1008 uint32_t size = qdict_get_int(qdict, "size");
1009 const char *filename = qdict_get_str(qdict, "filename");
1010 uint64_t addr = qdict_get_int(qdict, "val");
1011 Error *err = NULL;
1012 int cpu_index = monitor_get_cpu_index(mon);
1014 if (cpu_index < 0) {
1015 monitor_printf(mon, "No CPU available\n");
1016 return;
1019 qmp_memsave(addr, size, filename, true, cpu_index, &err);
1020 hmp_handle_error(mon, err);
1023 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1025 uint32_t size = qdict_get_int(qdict, "size");
1026 const char *filename = qdict_get_str(qdict, "filename");
1027 uint64_t addr = qdict_get_int(qdict, "val");
1028 Error *err = NULL;
1030 qmp_pmemsave(addr, size, filename, &err);
1031 hmp_handle_error(mon, err);
1034 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1036 const char *chardev = qdict_get_str(qdict, "device");
1037 const char *data = qdict_get_str(qdict, "data");
1038 Error *err = NULL;
1040 qmp_ringbuf_write(chardev, data, false, 0, &err);
1042 hmp_handle_error(mon, err);
1045 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
1047 uint32_t size = qdict_get_int(qdict, "size");
1048 const char *chardev = qdict_get_str(qdict, "device");
1049 char *data;
1050 Error *err = NULL;
1051 int i;
1053 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1054 if (err) {
1055 hmp_handle_error(mon, err);
1056 return;
1059 for (i = 0; data[i]; i++) {
1060 unsigned char ch = data[i];
1062 if (ch == '\\') {
1063 monitor_printf(mon, "\\\\");
1064 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1065 monitor_printf(mon, "\\u%04X", ch);
1066 } else {
1067 monitor_printf(mon, "%c", ch);
1071 monitor_printf(mon, "\n");
1072 g_free(data);
1075 void hmp_cont(Monitor *mon, const QDict *qdict)
1077 Error *err = NULL;
1079 qmp_cont(&err);
1080 hmp_handle_error(mon, err);
1083 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1085 Error *err = NULL;
1087 qmp_system_wakeup(&err);
1088 hmp_handle_error(mon, err);
1091 void hmp_nmi(Monitor *mon, const QDict *qdict)
1093 Error *err = NULL;
1095 qmp_inject_nmi(&err);
1096 hmp_handle_error(mon, err);
1099 void hmp_set_link(Monitor *mon, const QDict *qdict)
1101 const char *name = qdict_get_str(qdict, "name");
1102 bool up = qdict_get_bool(qdict, "up");
1103 Error *err = NULL;
1105 qmp_set_link(name, up, &err);
1106 hmp_handle_error(mon, err);
1109 void hmp_balloon(Monitor *mon, const QDict *qdict)
1111 int64_t value = qdict_get_int(qdict, "value");
1112 Error *err = NULL;
1114 qmp_balloon(value, &err);
1115 hmp_handle_error(mon, err);
1118 void hmp_loadvm(Monitor *mon, const QDict *qdict)
1120 int saved_vm_running = runstate_is_running();
1121 const char *name = qdict_get_str(qdict, "name");
1122 Error *err = NULL;
1124 vm_stop(RUN_STATE_RESTORE_VM);
1126 if (load_snapshot(name, &err) == 0 && saved_vm_running) {
1127 vm_start();
1129 hmp_handle_error(mon, err);
1132 void hmp_savevm(Monitor *mon, const QDict *qdict)
1134 Error *err = NULL;
1136 save_snapshot(qdict_get_try_str(qdict, "name"), &err);
1137 hmp_handle_error(mon, err);
1140 void hmp_delvm(Monitor *mon, const QDict *qdict)
1142 BlockDriverState *bs;
1143 Error *err = NULL;
1144 const char *name = qdict_get_str(qdict, "name");
1146 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
1147 error_prepend(&err,
1148 "deleting snapshot on device '%s': ",
1149 bdrv_get_device_name(bs));
1151 hmp_handle_error(mon, err);
1154 void hmp_announce_self(Monitor *mon, const QDict *qdict)
1156 const char *interfaces_str = qdict_get_try_str(qdict, "interfaces");
1157 const char *id = qdict_get_try_str(qdict, "id");
1158 AnnounceParameters *params = QAPI_CLONE(AnnounceParameters,
1159 migrate_announce_params());
1161 qapi_free_strList(params->interfaces);
1162 params->interfaces = strList_from_comma_list(interfaces_str);
1163 params->has_interfaces = params->interfaces != NULL;
1164 params->id = g_strdup(id);
1165 params->has_id = !!params->id;
1166 qmp_announce_self(params, NULL);
1167 qapi_free_AnnounceParameters(params);
1170 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1172 qmp_migrate_cancel(NULL);
1175 void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1177 Error *err = NULL;
1178 const char *state = qdict_get_str(qdict, "state");
1179 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1181 if (val >= 0) {
1182 qmp_migrate_continue(val, &err);
1185 hmp_handle_error(mon, err);
1188 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1190 Error *err = NULL;
1191 const char *uri = qdict_get_str(qdict, "uri");
1193 qmp_migrate_incoming(uri, &err);
1195 hmp_handle_error(mon, err);
1198 void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
1200 Error *err = NULL;
1201 const char *uri = qdict_get_str(qdict, "uri");
1203 qmp_migrate_recover(uri, &err);
1205 hmp_handle_error(mon, err);
1208 void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
1210 Error *err = NULL;
1212 qmp_migrate_pause(&err);
1214 hmp_handle_error(mon, err);
1217 /* Kept for backwards compatibility */
1218 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1220 Error *err = NULL;
1222 double value = qdict_get_double(qdict, "value");
1223 qmp_migrate_set_downtime(value, &err);
1224 hmp_handle_error(mon, err);
1227 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1229 int64_t value = qdict_get_int(qdict, "value");
1230 Error *err = NULL;
1232 qmp_migrate_set_cache_size(value, &err);
1233 hmp_handle_error(mon, err);
1236 /* Kept for backwards compatibility */
1237 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1239 Error *err = NULL;
1241 int64_t value = qdict_get_int(qdict, "value");
1242 qmp_migrate_set_speed(value, &err);
1243 hmp_handle_error(mon, err);
1246 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1248 const char *cap = qdict_get_str(qdict, "capability");
1249 bool state = qdict_get_bool(qdict, "state");
1250 Error *err = NULL;
1251 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1252 int val;
1254 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
1255 if (val < 0) {
1256 goto end;
1259 caps->value = g_malloc0(sizeof(*caps->value));
1260 caps->value->capability = val;
1261 caps->value->state = state;
1262 caps->next = NULL;
1263 qmp_migrate_set_capabilities(caps, &err);
1265 end:
1266 qapi_free_MigrationCapabilityStatusList(caps);
1267 hmp_handle_error(mon, err);
1270 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1272 const char *param = qdict_get_str(qdict, "parameter");
1273 const char *valuestr = qdict_get_str(qdict, "value");
1274 Visitor *v = string_input_visitor_new(valuestr);
1275 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
1276 uint64_t valuebw = 0;
1277 uint64_t cache_size;
1278 Error *err = NULL;
1279 int val, ret;
1281 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
1282 if (val < 0) {
1283 goto cleanup;
1286 switch (val) {
1287 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1288 p->has_compress_level = true;
1289 visit_type_int(v, param, &p->compress_level, &err);
1290 break;
1291 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1292 p->has_compress_threads = true;
1293 visit_type_int(v, param, &p->compress_threads, &err);
1294 break;
1295 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD:
1296 p->has_compress_wait_thread = true;
1297 visit_type_bool(v, param, &p->compress_wait_thread, &err);
1298 break;
1299 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1300 p->has_decompress_threads = true;
1301 visit_type_int(v, param, &p->decompress_threads, &err);
1302 break;
1303 case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD:
1304 p->has_throttle_trigger_threshold = true;
1305 visit_type_int(v, param, &p->throttle_trigger_threshold, &err);
1306 break;
1307 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1308 p->has_cpu_throttle_initial = true;
1309 visit_type_int(v, param, &p->cpu_throttle_initial, &err);
1310 break;
1311 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1312 p->has_cpu_throttle_increment = true;
1313 visit_type_int(v, param, &p->cpu_throttle_increment, &err);
1314 break;
1315 case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW:
1316 p->has_cpu_throttle_tailslow = true;
1317 visit_type_bool(v, param, &p->cpu_throttle_tailslow, &err);
1318 break;
1319 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE:
1320 p->has_max_cpu_throttle = true;
1321 visit_type_int(v, param, &p->max_cpu_throttle, &err);
1322 break;
1323 case MIGRATION_PARAMETER_TLS_CREDS:
1324 p->has_tls_creds = true;
1325 p->tls_creds = g_new0(StrOrNull, 1);
1326 p->tls_creds->type = QTYPE_QSTRING;
1327 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1328 break;
1329 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1330 p->has_tls_hostname = true;
1331 p->tls_hostname = g_new0(StrOrNull, 1);
1332 p->tls_hostname->type = QTYPE_QSTRING;
1333 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1334 break;
1335 case MIGRATION_PARAMETER_TLS_AUTHZ:
1336 p->has_tls_authz = true;
1337 p->tls_authz = g_new0(StrOrNull, 1);
1338 p->tls_authz->type = QTYPE_QSTRING;
1339 visit_type_str(v, param, &p->tls_authz->u.s, &err);
1340 break;
1341 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1342 p->has_max_bandwidth = true;
1344 * Can't use visit_type_size() here, because it
1345 * defaults to Bytes rather than Mebibytes.
1347 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1348 if (ret < 0 || valuebw > INT64_MAX
1349 || (size_t)valuebw != valuebw) {
1350 error_setg(&err, "Invalid size %s", valuestr);
1351 break;
1353 p->max_bandwidth = valuebw;
1354 break;
1355 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1356 p->has_downtime_limit = true;
1357 visit_type_int(v, param, &p->downtime_limit, &err);
1358 break;
1359 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1360 p->has_x_checkpoint_delay = true;
1361 visit_type_int(v, param, &p->x_checkpoint_delay, &err);
1362 break;
1363 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1364 p->has_block_incremental = true;
1365 visit_type_bool(v, param, &p->block_incremental, &err);
1366 break;
1367 case MIGRATION_PARAMETER_MULTIFD_CHANNELS:
1368 p->has_multifd_channels = true;
1369 visit_type_int(v, param, &p->multifd_channels, &err);
1370 break;
1371 case MIGRATION_PARAMETER_MULTIFD_COMPRESSION:
1372 p->has_multifd_compression = true;
1373 visit_type_MultiFDCompression(v, param, &p->multifd_compression,
1374 &err);
1375 break;
1376 case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL:
1377 p->has_multifd_zlib_level = true;
1378 visit_type_int(v, param, &p->multifd_zlib_level, &err);
1379 break;
1380 case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL:
1381 p->has_multifd_zstd_level = true;
1382 visit_type_int(v, param, &p->multifd_zstd_level, &err);
1383 break;
1384 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1385 p->has_xbzrle_cache_size = true;
1386 if (!visit_type_size(v, param, &cache_size, &err)) {
1387 break;
1389 if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) {
1390 error_setg(&err, "Invalid size %s", valuestr);
1391 break;
1393 p->xbzrle_cache_size = cache_size;
1394 break;
1395 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH:
1396 p->has_max_postcopy_bandwidth = true;
1397 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err);
1398 break;
1399 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL:
1400 p->has_announce_initial = true;
1401 visit_type_size(v, param, &p->announce_initial, &err);
1402 break;
1403 case MIGRATION_PARAMETER_ANNOUNCE_MAX:
1404 p->has_announce_max = true;
1405 visit_type_size(v, param, &p->announce_max, &err);
1406 break;
1407 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS:
1408 p->has_announce_rounds = true;
1409 visit_type_size(v, param, &p->announce_rounds, &err);
1410 break;
1411 case MIGRATION_PARAMETER_ANNOUNCE_STEP:
1412 p->has_announce_step = true;
1413 visit_type_size(v, param, &p->announce_step, &err);
1414 break;
1415 case MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING:
1416 error_setg(&err, "The block-bitmap-mapping parameter can only be set "
1417 "through QMP");
1418 break;
1419 default:
1420 assert(0);
1423 if (err) {
1424 goto cleanup;
1427 qmp_migrate_set_parameters(p, &err);
1429 cleanup:
1430 qapi_free_MigrateSetParameters(p);
1431 visit_free(v);
1432 hmp_handle_error(mon, err);
1435 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1437 Error *err = NULL;
1438 const char *protocol = qdict_get_str(qdict, "protocol");
1439 const char *hostname = qdict_get_str(qdict, "hostname");
1440 bool has_port = qdict_haskey(qdict, "port");
1441 int port = qdict_get_try_int(qdict, "port", -1);
1442 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1443 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1444 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1446 qmp_client_migrate_info(protocol, hostname,
1447 has_port, port, has_tls_port, tls_port,
1448 !!cert_subject, cert_subject, &err);
1449 hmp_handle_error(mon, err);
1452 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1454 Error *err = NULL;
1455 qmp_migrate_start_postcopy(&err);
1456 hmp_handle_error(mon, err);
1459 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1461 Error *err = NULL;
1463 qmp_x_colo_lost_heartbeat(&err);
1464 hmp_handle_error(mon, err);
1467 void hmp_set_password(Monitor *mon, const QDict *qdict)
1469 const char *protocol = qdict_get_str(qdict, "protocol");
1470 const char *password = qdict_get_str(qdict, "password");
1471 const char *connected = qdict_get_try_str(qdict, "connected");
1472 Error *err = NULL;
1474 qmp_set_password(protocol, password, !!connected, connected, &err);
1475 hmp_handle_error(mon, err);
1478 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1480 const char *protocol = qdict_get_str(qdict, "protocol");
1481 const char *whenstr = qdict_get_str(qdict, "time");
1482 Error *err = NULL;
1484 qmp_expire_password(protocol, whenstr, &err);
1485 hmp_handle_error(mon, err);
1489 #ifdef CONFIG_VNC
1490 static void hmp_change_read_arg(void *opaque, const char *password,
1491 void *readline_opaque)
1493 qmp_change_vnc_password(password, NULL);
1494 monitor_read_command(opaque, 1);
1496 #endif
1498 void hmp_change(Monitor *mon, const QDict *qdict)
1500 const char *device = qdict_get_str(qdict, "device");
1501 const char *target = qdict_get_str(qdict, "target");
1502 const char *arg = qdict_get_try_str(qdict, "arg");
1503 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1504 BlockdevChangeReadOnlyMode read_only_mode = 0;
1505 Error *err = NULL;
1507 #ifdef CONFIG_VNC
1508 if (strcmp(device, "vnc") == 0) {
1509 if (read_only) {
1510 monitor_printf(mon,
1511 "Parameter 'read-only-mode' is invalid for VNC\n");
1512 return;
1514 if (strcmp(target, "passwd") == 0 ||
1515 strcmp(target, "password") == 0) {
1516 if (!arg) {
1517 MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
1518 monitor_read_password(hmp_mon, hmp_change_read_arg, NULL);
1519 return;
1522 qmp_change("vnc", target, !!arg, arg, &err);
1523 } else
1524 #endif
1526 if (read_only) {
1527 read_only_mode =
1528 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
1529 read_only,
1530 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1531 if (err) {
1532 goto end;
1536 qmp_blockdev_change_medium(true, device, false, NULL, target,
1537 !!arg, arg, !!read_only, read_only_mode,
1538 &err);
1541 end:
1542 hmp_handle_error(mon, err);
1545 typedef struct HMPMigrationStatus
1547 QEMUTimer *timer;
1548 Monitor *mon;
1549 bool is_block_migration;
1550 } HMPMigrationStatus;
1552 static void hmp_migrate_status_cb(void *opaque)
1554 HMPMigrationStatus *status = opaque;
1555 MigrationInfo *info;
1557 info = qmp_query_migrate(NULL);
1558 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1559 info->status == MIGRATION_STATUS_SETUP) {
1560 if (info->has_disk) {
1561 int progress;
1563 if (info->disk->remaining) {
1564 progress = info->disk->transferred * 100 / info->disk->total;
1565 } else {
1566 progress = 100;
1569 monitor_printf(status->mon, "Completed %d %%\r", progress);
1570 monitor_flush(status->mon);
1573 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1574 } else {
1575 if (status->is_block_migration) {
1576 monitor_printf(status->mon, "\n");
1578 if (info->has_error_desc) {
1579 error_report("%s", info->error_desc);
1581 monitor_resume(status->mon);
1582 timer_del(status->timer);
1583 timer_free(status->timer);
1584 g_free(status);
1587 qapi_free_MigrationInfo(info);
1590 void hmp_migrate(Monitor *mon, const QDict *qdict)
1592 bool detach = qdict_get_try_bool(qdict, "detach", false);
1593 bool blk = qdict_get_try_bool(qdict, "blk", false);
1594 bool inc = qdict_get_try_bool(qdict, "inc", false);
1595 bool resume = qdict_get_try_bool(qdict, "resume", false);
1596 const char *uri = qdict_get_str(qdict, "uri");
1597 Error *err = NULL;
1599 qmp_migrate(uri, !!blk, blk, !!inc, inc,
1600 false, false, true, resume, &err);
1601 if (err) {
1602 hmp_handle_error(mon, err);
1603 return;
1606 if (!detach) {
1607 HMPMigrationStatus *status;
1609 if (monitor_suspend(mon) < 0) {
1610 monitor_printf(mon, "terminal does not allow synchronous "
1611 "migration, continuing detached\n");
1612 return;
1615 status = g_malloc0(sizeof(*status));
1616 status->mon = mon;
1617 status->is_block_migration = blk || inc;
1618 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1619 status);
1620 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1624 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1626 Error *err = NULL;
1627 QemuOpts *opts;
1629 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1630 if (err) {
1631 goto out;
1634 netdev_add(opts, &err);
1635 if (err) {
1636 qemu_opts_del(opts);
1639 out:
1640 hmp_handle_error(mon, err);
1643 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1645 const char *id = qdict_get_str(qdict, "id");
1646 Error *err = NULL;
1648 qmp_netdev_del(id, &err);
1649 hmp_handle_error(mon, err);
1652 void hmp_object_add(Monitor *mon, const QDict *qdict)
1654 Error *err = NULL;
1655 QemuOpts *opts;
1656 Object *obj = NULL;
1658 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1659 if (err) {
1660 goto end;
1663 obj = user_creatable_add_opts(opts, &err);
1664 qemu_opts_del(opts);
1666 end:
1667 hmp_handle_error(mon, err);
1669 if (obj) {
1670 object_unref(obj);
1674 void hmp_getfd(Monitor *mon, const QDict *qdict)
1676 const char *fdname = qdict_get_str(qdict, "fdname");
1677 Error *err = NULL;
1679 qmp_getfd(fdname, &err);
1680 hmp_handle_error(mon, err);
1683 void hmp_closefd(Monitor *mon, const QDict *qdict)
1685 const char *fdname = qdict_get_str(qdict, "fdname");
1686 Error *err = NULL;
1688 qmp_closefd(fdname, &err);
1689 hmp_handle_error(mon, err);
1692 void hmp_sendkey(Monitor *mon, const QDict *qdict)
1694 const char *keys = qdict_get_str(qdict, "keys");
1695 KeyValueList *keylist, *head = NULL, *tmp = NULL;
1696 int has_hold_time = qdict_haskey(qdict, "hold-time");
1697 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1698 Error *err = NULL;
1699 const char *separator;
1700 int keyname_len;
1702 while (1) {
1703 separator = qemu_strchrnul(keys, '-');
1704 keyname_len = separator - keys;
1706 /* Be compatible with old interface, convert user inputted "<" */
1707 if (keys[0] == '<' && keyname_len == 1) {
1708 keys = "less";
1709 keyname_len = 4;
1712 keylist = g_malloc0(sizeof(*keylist));
1713 keylist->value = g_malloc0(sizeof(*keylist->value));
1715 if (!head) {
1716 head = keylist;
1718 if (tmp) {
1719 tmp->next = keylist;
1721 tmp = keylist;
1723 if (strstart(keys, "0x", NULL)) {
1724 char *endp;
1725 int value = strtoul(keys, &endp, 0);
1726 assert(endp <= keys + keyname_len);
1727 if (endp != keys + keyname_len) {
1728 goto err_out;
1730 keylist->value->type = KEY_VALUE_KIND_NUMBER;
1731 keylist->value->u.number.data = value;
1732 } else {
1733 int idx = index_from_key(keys, keyname_len);
1734 if (idx == Q_KEY_CODE__MAX) {
1735 goto err_out;
1737 keylist->value->type = KEY_VALUE_KIND_QCODE;
1738 keylist->value->u.qcode.data = idx;
1741 if (!*separator) {
1742 break;
1744 keys = separator + 1;
1747 qmp_send_key(head, has_hold_time, hold_time, &err);
1748 hmp_handle_error(mon, err);
1750 out:
1751 qapi_free_KeyValueList(head);
1752 return;
1754 err_out:
1755 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
1756 goto out;
1759 void hmp_screendump(Monitor *mon, const QDict *qdict)
1761 const char *filename = qdict_get_str(qdict, "filename");
1762 const char *id = qdict_get_try_str(qdict, "device");
1763 int64_t head = qdict_get_try_int(qdict, "head", 0);
1764 Error *err = NULL;
1766 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
1767 hmp_handle_error(mon, err);
1770 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1772 const char *args = qdict_get_str(qdict, "args");
1773 Error *err = NULL;
1774 QemuOpts *opts;
1776 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
1777 if (opts == NULL) {
1778 error_setg(&err, "Parsing chardev args failed");
1779 } else {
1780 qemu_chr_new_from_opts(opts, NULL, &err);
1781 qemu_opts_del(opts);
1783 hmp_handle_error(mon, err);
1786 void hmp_chardev_change(Monitor *mon, const QDict *qdict)
1788 const char *args = qdict_get_str(qdict, "args");
1789 const char *id;
1790 Error *err = NULL;
1791 ChardevBackend *backend = NULL;
1792 ChardevReturn *ret = NULL;
1793 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
1794 true);
1795 if (!opts) {
1796 error_setg(&err, "Parsing chardev args failed");
1797 goto end;
1800 id = qdict_get_str(qdict, "id");
1801 if (qemu_opts_id(opts)) {
1802 error_setg(&err, "Unexpected 'id' parameter");
1803 goto end;
1806 backend = qemu_chr_parse_opts(opts, &err);
1807 if (!backend) {
1808 goto end;
1811 ret = qmp_chardev_change(id, backend, &err);
1813 end:
1814 qapi_free_ChardevReturn(ret);
1815 qapi_free_ChardevBackend(backend);
1816 qemu_opts_del(opts);
1817 hmp_handle_error(mon, err);
1820 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1822 Error *local_err = NULL;
1824 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1825 hmp_handle_error(mon, local_err);
1828 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
1830 Error *local_err = NULL;
1832 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
1833 hmp_handle_error(mon, local_err);
1836 void hmp_object_del(Monitor *mon, const QDict *qdict)
1838 const char *id = qdict_get_str(qdict, "id");
1839 Error *err = NULL;
1841 user_creatable_del(id, &err);
1842 hmp_handle_error(mon, err);
1845 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
1847 Error *err = NULL;
1848 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
1849 MemoryDeviceInfoList *info;
1850 VirtioPMEMDeviceInfo *vpi;
1851 VirtioMEMDeviceInfo *vmi;
1852 MemoryDeviceInfo *value;
1853 PCDIMMDeviceInfo *di;
1855 for (info = info_list; info; info = info->next) {
1856 value = info->value;
1858 if (value) {
1859 switch (value->type) {
1860 case MEMORY_DEVICE_INFO_KIND_DIMM:
1861 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
1862 di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ?
1863 value->u.dimm.data : value->u.nvdimm.data;
1864 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1865 MemoryDeviceInfoKind_str(value->type),
1866 di->id ? di->id : "");
1867 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
1868 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
1869 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
1870 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
1871 monitor_printf(mon, " memdev: %s\n", di->memdev);
1872 monitor_printf(mon, " hotplugged: %s\n",
1873 di->hotplugged ? "true" : "false");
1874 monitor_printf(mon, " hotpluggable: %s\n",
1875 di->hotpluggable ? "true" : "false");
1876 break;
1877 case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM:
1878 vpi = value->u.virtio_pmem.data;
1879 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1880 MemoryDeviceInfoKind_str(value->type),
1881 vpi->id ? vpi->id : "");
1882 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->memaddr);
1883 monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size);
1884 monitor_printf(mon, " memdev: %s\n", vpi->memdev);
1885 break;
1886 case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM:
1887 vmi = value->u.virtio_mem.data;
1888 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1889 MemoryDeviceInfoKind_str(value->type),
1890 vmi->id ? vmi->id : "");
1891 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vmi->memaddr);
1892 monitor_printf(mon, " node: %" PRId64 "\n", vmi->node);
1893 monitor_printf(mon, " requested-size: %" PRIu64 "\n",
1894 vmi->requested_size);
1895 monitor_printf(mon, " size: %" PRIu64 "\n", vmi->size);
1896 monitor_printf(mon, " max-size: %" PRIu64 "\n", vmi->max_size);
1897 monitor_printf(mon, " block-size: %" PRIu64 "\n",
1898 vmi->block_size);
1899 monitor_printf(mon, " memdev: %s\n", vmi->memdev);
1900 break;
1901 default:
1902 g_assert_not_reached();
1907 qapi_free_MemoryDeviceInfoList(info_list);
1908 hmp_handle_error(mon, err);
1911 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
1913 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
1914 IOThreadInfoList *info;
1915 IOThreadInfo *value;
1917 for (info = info_list; info; info = info->next) {
1918 value = info->value;
1919 monitor_printf(mon, "%s:\n", value->id);
1920 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
1921 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
1922 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
1923 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
1926 qapi_free_IOThreadInfoList(info_list);
1929 void hmp_rocker(Monitor *mon, const QDict *qdict)
1931 const char *name = qdict_get_str(qdict, "name");
1932 RockerSwitch *rocker;
1933 Error *err = NULL;
1935 rocker = qmp_query_rocker(name, &err);
1936 if (err != NULL) {
1937 hmp_handle_error(mon, err);
1938 return;
1941 monitor_printf(mon, "name: %s\n", rocker->name);
1942 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
1943 monitor_printf(mon, "ports: %d\n", rocker->ports);
1945 qapi_free_RockerSwitch(rocker);
1948 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
1950 RockerPortList *list, *port;
1951 const char *name = qdict_get_str(qdict, "name");
1952 Error *err = NULL;
1954 list = qmp_query_rocker_ports(name, &err);
1955 if (err != NULL) {
1956 hmp_handle_error(mon, err);
1957 return;
1960 monitor_printf(mon, " ena/ speed/ auto\n");
1961 monitor_printf(mon, " port link duplex neg?\n");
1963 for (port = list; port; port = port->next) {
1964 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
1965 port->value->name,
1966 port->value->enabled ? port->value->link_up ?
1967 "up" : "down" : "!ena",
1968 port->value->speed == 10000 ? "10G" : "??",
1969 port->value->duplex ? "FD" : "HD",
1970 port->value->autoneg ? "Yes" : "No");
1973 qapi_free_RockerPortList(list);
1976 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
1978 RockerOfDpaFlowList *list, *info;
1979 const char *name = qdict_get_str(qdict, "name");
1980 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
1981 Error *err = NULL;
1983 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
1984 if (err != NULL) {
1985 hmp_handle_error(mon, err);
1986 return;
1989 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
1991 for (info = list; info; info = info->next) {
1992 RockerOfDpaFlow *flow = info->value;
1993 RockerOfDpaFlowKey *key = flow->key;
1994 RockerOfDpaFlowMask *mask = flow->mask;
1995 RockerOfDpaFlowAction *action = flow->action;
1997 if (flow->hits) {
1998 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
1999 key->priority, key->tbl_id, flow->hits);
2000 } else {
2001 monitor_printf(mon, "%-4d %-3d ",
2002 key->priority, key->tbl_id);
2005 if (key->has_in_pport) {
2006 monitor_printf(mon, " pport %d", key->in_pport);
2007 if (mask->has_in_pport) {
2008 monitor_printf(mon, "(0x%x)", mask->in_pport);
2012 if (key->has_vlan_id) {
2013 monitor_printf(mon, " vlan %d",
2014 key->vlan_id & VLAN_VID_MASK);
2015 if (mask->has_vlan_id) {
2016 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2020 if (key->has_tunnel_id) {
2021 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2022 if (mask->has_tunnel_id) {
2023 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2027 if (key->has_eth_type) {
2028 switch (key->eth_type) {
2029 case 0x0806:
2030 monitor_printf(mon, " ARP");
2031 break;
2032 case 0x0800:
2033 monitor_printf(mon, " IP");
2034 break;
2035 case 0x86dd:
2036 monitor_printf(mon, " IPv6");
2037 break;
2038 case 0x8809:
2039 monitor_printf(mon, " LACP");
2040 break;
2041 case 0x88cc:
2042 monitor_printf(mon, " LLDP");
2043 break;
2044 default:
2045 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2046 break;
2050 if (key->has_eth_src) {
2051 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2052 (mask->has_eth_src) &&
2053 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2054 monitor_printf(mon, " src <any mcast/bcast>");
2055 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2056 (mask->has_eth_src) &&
2057 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2058 monitor_printf(mon, " src <any ucast>");
2059 } else {
2060 monitor_printf(mon, " src %s", key->eth_src);
2061 if (mask->has_eth_src) {
2062 monitor_printf(mon, "(%s)", mask->eth_src);
2067 if (key->has_eth_dst) {
2068 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2069 (mask->has_eth_dst) &&
2070 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2071 monitor_printf(mon, " dst <any mcast/bcast>");
2072 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2073 (mask->has_eth_dst) &&
2074 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2075 monitor_printf(mon, " dst <any ucast>");
2076 } else {
2077 monitor_printf(mon, " dst %s", key->eth_dst);
2078 if (mask->has_eth_dst) {
2079 monitor_printf(mon, "(%s)", mask->eth_dst);
2084 if (key->has_ip_proto) {
2085 monitor_printf(mon, " proto %d", key->ip_proto);
2086 if (mask->has_ip_proto) {
2087 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2091 if (key->has_ip_tos) {
2092 monitor_printf(mon, " TOS %d", key->ip_tos);
2093 if (mask->has_ip_tos) {
2094 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2098 if (key->has_ip_dst) {
2099 monitor_printf(mon, " dst %s", key->ip_dst);
2102 if (action->has_goto_tbl || action->has_group_id ||
2103 action->has_new_vlan_id) {
2104 monitor_printf(mon, " -->");
2107 if (action->has_new_vlan_id) {
2108 monitor_printf(mon, " apply new vlan %d",
2109 ntohs(action->new_vlan_id));
2112 if (action->has_group_id) {
2113 monitor_printf(mon, " write group 0x%08x", action->group_id);
2116 if (action->has_goto_tbl) {
2117 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2120 monitor_printf(mon, "\n");
2123 qapi_free_RockerOfDpaFlowList(list);
2126 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2128 RockerOfDpaGroupList *list, *g;
2129 const char *name = qdict_get_str(qdict, "name");
2130 uint8_t type = qdict_get_try_int(qdict, "type", 9);
2131 Error *err = NULL;
2133 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2134 if (err != NULL) {
2135 hmp_handle_error(mon, err);
2136 return;
2139 monitor_printf(mon, "id (decode) --> buckets\n");
2141 for (g = list; g; g = g->next) {
2142 RockerOfDpaGroup *group = g->value;
2143 bool set = false;
2145 monitor_printf(mon, "0x%08x", group->id);
2147 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2148 group->type == 1 ? "L2 rewrite" :
2149 group->type == 2 ? "L3 unicast" :
2150 group->type == 3 ? "L2 multicast" :
2151 group->type == 4 ? "L2 flood" :
2152 group->type == 5 ? "L3 interface" :
2153 group->type == 6 ? "L3 multicast" :
2154 group->type == 7 ? "L3 ECMP" :
2155 group->type == 8 ? "L2 overlay" :
2156 "unknown");
2158 if (group->has_vlan_id) {
2159 monitor_printf(mon, " vlan %d", group->vlan_id);
2162 if (group->has_pport) {
2163 monitor_printf(mon, " pport %d", group->pport);
2166 if (group->has_index) {
2167 monitor_printf(mon, " index %d", group->index);
2170 monitor_printf(mon, ") -->");
2172 if (group->has_set_vlan_id && group->set_vlan_id) {
2173 set = true;
2174 monitor_printf(mon, " set vlan %d",
2175 group->set_vlan_id & VLAN_VID_MASK);
2178 if (group->has_set_eth_src) {
2179 if (!set) {
2180 set = true;
2181 monitor_printf(mon, " set");
2183 monitor_printf(mon, " src %s", group->set_eth_src);
2186 if (group->has_set_eth_dst) {
2187 if (!set) {
2188 monitor_printf(mon, " set");
2190 monitor_printf(mon, " dst %s", group->set_eth_dst);
2193 if (group->has_ttl_check && group->ttl_check) {
2194 monitor_printf(mon, " check TTL");
2197 if (group->has_group_id && group->group_id) {
2198 monitor_printf(mon, " group id 0x%08x", group->group_id);
2201 if (group->has_pop_vlan && group->pop_vlan) {
2202 monitor_printf(mon, " pop vlan");
2205 if (group->has_out_pport) {
2206 monitor_printf(mon, " out pport %d", group->out_pport);
2209 if (group->has_group_ids) {
2210 struct uint32List *id;
2212 monitor_printf(mon, " groups [");
2213 for (id = group->group_ids; id; id = id->next) {
2214 monitor_printf(mon, "0x%08x", id->value);
2215 if (id->next) {
2216 monitor_printf(mon, ",");
2219 monitor_printf(mon, "]");
2222 monitor_printf(mon, "\n");
2225 qapi_free_RockerOfDpaGroupList(list);
2228 void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
2230 ram_block_dump(mon);
2233 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
2235 Error *err = NULL;
2236 GuidInfo *info = qmp_query_vm_generation_id(&err);
2237 if (info) {
2238 monitor_printf(mon, "%s\n", info->guid);
2240 hmp_handle_error(mon, err);
2241 qapi_free_GuidInfo(info);
2244 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
2246 Error *err = NULL;
2247 MemoryInfo *info = qmp_query_memory_size_summary(&err);
2248 if (info) {
2249 monitor_printf(mon, "base memory: %" PRIu64 "\n",
2250 info->base_memory);
2252 if (info->has_plugged_memory) {
2253 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
2254 info->plugged_memory);
2257 qapi_free_MemoryInfo(info);
2259 hmp_handle_error(mon, err);