1 /* 2 * Human Monitor Interface commands 3 * 4 * Copyright IBM, Corp. 2011 5 * 6 * Authors: 7 * Anthony Liguori <aliguori@us.ibm.com> 8 * 9 * This work is licensed under the terms of the GNU GPL, version 2. See 10 * the COPYING file in the top-level directory. 11 * 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. 14 */ 15 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-migration.h" 36 #include "qapi/qapi-commands-misc.h" 37 #include "qapi/qapi-commands-net.h" 38 #include "qapi/qapi-commands-rocker.h" 39 #include "qapi/qapi-commands-run-state.h" 40 #include "qapi/qapi-commands-tpm.h" 41 #include "qapi/qapi-commands-ui.h" 42 #include "qapi/qapi-visit-net.h" 43 #include "qapi/qapi-visit-migration.h" 44 #include "qapi/qmp/qdict.h" 45 #include "qapi/qmp/qerror.h" 46 #include "qapi/string-input-visitor.h" 47 #include "qapi/string-output-visitor.h" 48 #include "qom/object_interfaces.h" 49 #include "ui/console.h" 50 #include "qemu/cutils.h" 51 #include "qemu/error-report.h" 52 #include "exec/ramlist.h" 53 #include "hw/intc/intc.h" 54 #include "hw/rdma/rdma.h" 55 #include "migration/snapshot.h" 56 #include "migration/misc.h" 57 58 #ifdef CONFIG_SPICE 59 #include <spice/enums.h> 60 #endif 61 62 void hmp_handle_error(Monitor *mon, Error *err) 63 { 64 if (err) { 65 error_reportf_err(err, "Error: "); 66 } 67 } 68 69 /* 70 * Produce a strList from a comma separated list. 71 * A NULL or empty input string return NULL. 72 */ 73 static strList *strList_from_comma_list(const char *in) 74 { 75 strList *res = NULL; 76 strList **hook = &res; 77 78 while (in && in[0]) { 79 char *comma = strchr(in, ','); 80 *hook = g_new0(strList, 1); 81 82 if (comma) { 83 (*hook)->value = g_strndup(in, comma - in); 84 in = comma + 1; /* skip the , */ 85 } else { 86 (*hook)->value = g_strdup(in); 87 in = NULL; 88 } 89 hook = &(*hook)->next; 90 } 91 92 return res; 93 } 94 95 void hmp_info_name(Monitor *mon, const QDict *qdict) 96 { 97 NameInfo *info; 98 99 info = qmp_query_name(NULL); 100 if (info->has_name) { 101 monitor_printf(mon, "%s\n", info->name); 102 } 103 qapi_free_NameInfo(info); 104 } 105 106 void hmp_info_version(Monitor *mon, const QDict *qdict) 107 { 108 VersionInfo *info; 109 110 info = qmp_query_version(NULL); 111 112 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n", 113 info->qemu->major, info->qemu->minor, info->qemu->micro, 114 info->package); 115 116 qapi_free_VersionInfo(info); 117 } 118 119 void hmp_info_kvm(Monitor *mon, const QDict *qdict) 120 { 121 KvmInfo *info; 122 123 info = qmp_query_kvm(NULL); 124 monitor_printf(mon, "kvm support: "); 125 if (info->present) { 126 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled"); 127 } else { 128 monitor_printf(mon, "not compiled\n"); 129 } 130 131 qapi_free_KvmInfo(info); 132 } 133 134 void hmp_info_status(Monitor *mon, const QDict *qdict) 135 { 136 StatusInfo *info; 137 138 info = qmp_query_status(NULL); 139 140 monitor_printf(mon, "VM status: %s%s", 141 info->running ? "running" : "paused", 142 info->singlestep ? " (single step mode)" : ""); 143 144 if (!info->running && info->status != RUN_STATE_PAUSED) { 145 monitor_printf(mon, " (%s)", RunState_str(info->status)); 146 } 147 148 monitor_printf(mon, "\n"); 149 150 qapi_free_StatusInfo(info); 151 } 152 153 void hmp_info_uuid(Monitor *mon, const QDict *qdict) 154 { 155 UuidInfo *info; 156 157 info = qmp_query_uuid(NULL); 158 monitor_printf(mon, "%s\n", info->UUID); 159 qapi_free_UuidInfo(info); 160 } 161 162 void hmp_info_chardev(Monitor *mon, const QDict *qdict) 163 { 164 ChardevInfoList *char_info, *info; 165 166 char_info = qmp_query_chardev(NULL); 167 for (info = char_info; info; info = info->next) { 168 monitor_printf(mon, "%s: filename=%s\n", info->value->label, 169 info->value->filename); 170 } 171 172 qapi_free_ChardevInfoList(char_info); 173 } 174 175 void hmp_info_mice(Monitor *mon, const QDict *qdict) 176 { 177 MouseInfoList *mice_list, *mouse; 178 179 mice_list = qmp_query_mice(NULL); 180 if (!mice_list) { 181 monitor_printf(mon, "No mouse devices connected\n"); 182 return; 183 } 184 185 for (mouse = mice_list; mouse; mouse = mouse->next) { 186 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n", 187 mouse->value->current ? '*' : ' ', 188 mouse->value->index, mouse->value->name, 189 mouse->value->absolute ? " (absolute)" : ""); 190 } 191 192 qapi_free_MouseInfoList(mice_list); 193 } 194 195 static char *SocketAddress_to_str(SocketAddress *addr) 196 { 197 switch (addr->type) { 198 case SOCKET_ADDRESS_TYPE_INET: 199 return g_strdup_printf("tcp:%s:%s", 200 addr->u.inet.host, 201 addr->u.inet.port); 202 case SOCKET_ADDRESS_TYPE_UNIX: 203 return g_strdup_printf("unix:%s", 204 addr->u.q_unix.path); 205 case SOCKET_ADDRESS_TYPE_FD: 206 return g_strdup_printf("fd:%s", addr->u.fd.str); 207 case SOCKET_ADDRESS_TYPE_VSOCK: 208 return g_strdup_printf("tcp:%s:%s", 209 addr->u.vsock.cid, 210 addr->u.vsock.port); 211 default: 212 return g_strdup("unknown address type"); 213 } 214 } 215 216 void hmp_info_migrate(Monitor *mon, const QDict *qdict) 217 { 218 MigrationInfo *info; 219 220 info = qmp_query_migrate(NULL); 221 222 migration_global_dump(mon); 223 224 if (info->has_status) { 225 monitor_printf(mon, "Migration status: %s", 226 MigrationStatus_str(info->status)); 227 if (info->status == MIGRATION_STATUS_FAILED && 228 info->has_error_desc) { 229 monitor_printf(mon, " (%s)\n", info->error_desc); 230 } else { 231 monitor_printf(mon, "\n"); 232 } 233 234 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n", 235 info->total_time); 236 if (info->has_expected_downtime) { 237 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n", 238 info->expected_downtime); 239 } 240 if (info->has_downtime) { 241 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n", 242 info->downtime); 243 } 244 if (info->has_setup_time) { 245 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n", 246 info->setup_time); 247 } 248 } 249 250 if (info->has_ram) { 251 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n", 252 info->ram->transferred >> 10); 253 monitor_printf(mon, "throughput: %0.2f mbps\n", 254 info->ram->mbps); 255 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n", 256 info->ram->remaining >> 10); 257 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", 258 info->ram->total >> 10); 259 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n", 260 info->ram->duplicate); 261 monitor_printf(mon, "skipped: %" PRIu64 " pages\n", 262 info->ram->skipped); 263 monitor_printf(mon, "normal: %" PRIu64 " pages\n", 264 info->ram->normal); 265 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n", 266 info->ram->normal_bytes >> 10); 267 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n", 268 info->ram->dirty_sync_count); 269 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n", 270 info->ram->page_size >> 10); 271 monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n", 272 info->ram->multifd_bytes >> 10); 273 monitor_printf(mon, "pages-per-second: %" PRIu64 "\n", 274 info->ram->pages_per_second); 275 276 if (info->ram->dirty_pages_rate) { 277 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n", 278 info->ram->dirty_pages_rate); 279 } 280 if (info->ram->postcopy_requests) { 281 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n", 282 info->ram->postcopy_requests); 283 } 284 } 285 286 if (info->has_disk) { 287 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n", 288 info->disk->transferred >> 10); 289 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n", 290 info->disk->remaining >> 10); 291 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n", 292 info->disk->total >> 10); 293 } 294 295 if (info->has_xbzrle_cache) { 296 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n", 297 info->xbzrle_cache->cache_size); 298 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n", 299 info->xbzrle_cache->bytes >> 10); 300 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n", 301 info->xbzrle_cache->pages); 302 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n", 303 info->xbzrle_cache->cache_miss); 304 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n", 305 info->xbzrle_cache->cache_miss_rate); 306 monitor_printf(mon, "xbzrle overflow: %" PRIu64 "\n", 307 info->xbzrle_cache->overflow); 308 } 309 310 if (info->has_compression) { 311 monitor_printf(mon, "compression pages: %" PRIu64 " pages\n", 312 info->compression->pages); 313 monitor_printf(mon, "compression busy: %" PRIu64 "\n", 314 info->compression->busy); 315 monitor_printf(mon, "compression busy rate: %0.2f\n", 316 info->compression->busy_rate); 317 monitor_printf(mon, "compressed size: %" PRIu64 "\n", 318 info->compression->compressed_size); 319 monitor_printf(mon, "compression rate: %0.2f\n", 320 info->compression->compression_rate); 321 } 322 323 if (info->has_cpu_throttle_percentage) { 324 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n", 325 info->cpu_throttle_percentage); 326 } 327 328 if (info->has_postcopy_blocktime) { 329 monitor_printf(mon, "postcopy blocktime: %u\n", 330 info->postcopy_blocktime); 331 } 332 333 if (info->has_postcopy_vcpu_blocktime) { 334 Visitor *v; 335 char *str; 336 v = string_output_visitor_new(false, &str); 337 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NULL); 338 visit_complete(v, &str); 339 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str); 340 g_free(str); 341 visit_free(v); 342 } 343 if (info->has_socket_address) { 344 SocketAddressList *addr; 345 346 monitor_printf(mon, "socket address: [\n"); 347 348 for (addr = info->socket_address; addr; addr = addr->next) { 349 char *s = SocketAddress_to_str(addr->value); 350 monitor_printf(mon, "\t%s\n", s); 351 g_free(s); 352 } 353 monitor_printf(mon, "]\n"); 354 } 355 qapi_free_MigrationInfo(info); 356 } 357 358 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict) 359 { 360 MigrationCapabilityStatusList *caps, *cap; 361 362 caps = qmp_query_migrate_capabilities(NULL); 363 364 if (caps) { 365 for (cap = caps; cap; cap = cap->next) { 366 monitor_printf(mon, "%s: %s\n", 367 MigrationCapability_str(cap->value->capability), 368 cap->value->state ? "on" : "off"); 369 } 370 } 371 372 qapi_free_MigrationCapabilityStatusList(caps); 373 } 374 375 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) 376 { 377 MigrationParameters *params; 378 379 params = qmp_query_migrate_parameters(NULL); 380 381 if (params) { 382 monitor_printf(mon, "%s: %" PRIu64 " ms\n", 383 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL), 384 params->announce_initial); 385 monitor_printf(mon, "%s: %" PRIu64 " ms\n", 386 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX), 387 params->announce_max); 388 monitor_printf(mon, "%s: %" PRIu64 "\n", 389 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS), 390 params->announce_rounds); 391 monitor_printf(mon, "%s: %" PRIu64 " ms\n", 392 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP), 393 params->announce_step); 394 assert(params->has_compress_level); 395 monitor_printf(mon, "%s: %u\n", 396 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL), 397 params->compress_level); 398 assert(params->has_compress_threads); 399 monitor_printf(mon, "%s: %u\n", 400 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS), 401 params->compress_threads); 402 assert(params->has_compress_wait_thread); 403 monitor_printf(mon, "%s: %s\n", 404 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD), 405 params->compress_wait_thread ? "on" : "off"); 406 assert(params->has_decompress_threads); 407 monitor_printf(mon, "%s: %u\n", 408 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS), 409 params->decompress_threads); 410 assert(params->has_throttle_trigger_threshold); 411 monitor_printf(mon, "%s: %u\n", 412 MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD), 413 params->throttle_trigger_threshold); 414 assert(params->has_cpu_throttle_initial); 415 monitor_printf(mon, "%s: %u\n", 416 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL), 417 params->cpu_throttle_initial); 418 assert(params->has_cpu_throttle_increment); 419 monitor_printf(mon, "%s: %u\n", 420 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT), 421 params->cpu_throttle_increment); 422 assert(params->has_max_cpu_throttle); 423 monitor_printf(mon, "%s: %u\n", 424 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE), 425 params->max_cpu_throttle); 426 assert(params->has_tls_creds); 427 monitor_printf(mon, "%s: '%s'\n", 428 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS), 429 params->tls_creds); 430 assert(params->has_tls_hostname); 431 monitor_printf(mon, "%s: '%s'\n", 432 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME), 433 params->tls_hostname); 434 assert(params->has_max_bandwidth); 435 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n", 436 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH), 437 params->max_bandwidth); 438 assert(params->has_downtime_limit); 439 monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n", 440 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT), 441 params->downtime_limit); 442 assert(params->has_x_checkpoint_delay); 443 monitor_printf(mon, "%s: %u\n", 444 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY), 445 params->x_checkpoint_delay); 446 assert(params->has_block_incremental); 447 monitor_printf(mon, "%s: %s\n", 448 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL), 449 params->block_incremental ? "on" : "off"); 450 monitor_printf(mon, "%s: %u\n", 451 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS), 452 params->multifd_channels); 453 monitor_printf(mon, "%s: %s\n", 454 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION), 455 MultiFDCompression_str(params->multifd_compression)); 456 monitor_printf(mon, "%s: %" PRIu64 "\n", 457 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE), 458 params->xbzrle_cache_size); 459 monitor_printf(mon, "%s: %" PRIu64 "\n", 460 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH), 461 params->max_postcopy_bandwidth); 462 monitor_printf(mon, "%s: '%s'\n", 463 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ), 464 params->tls_authz); 465 } 466 467 qapi_free_MigrationParameters(params); 468 } 469 470 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict) 471 { 472 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n", 473 qmp_query_migrate_cache_size(NULL) >> 10); 474 } 475 476 477 #ifdef CONFIG_VNC 478 /* Helper for hmp_info_vnc_clients, _servers */ 479 static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info, 480 const char *name) 481 { 482 monitor_printf(mon, " %s: %s:%s (%s%s)\n", 483 name, 484 info->host, 485 info->service, 486 NetworkAddressFamily_str(info->family), 487 info->websocket ? " (Websocket)" : ""); 488 } 489 490 /* Helper displaying and auth and crypt info */ 491 static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent, 492 VncPrimaryAuth auth, 493 VncVencryptSubAuth *vencrypt) 494 { 495 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent, 496 VncPrimaryAuth_str(auth), 497 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none"); 498 } 499 500 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client) 501 { 502 while (client) { 503 VncClientInfo *cinfo = client->value; 504 505 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client"); 506 monitor_printf(mon, " x509_dname: %s\n", 507 cinfo->has_x509_dname ? 508 cinfo->x509_dname : "none"); 509 monitor_printf(mon, " sasl_username: %s\n", 510 cinfo->has_sasl_username ? 511 cinfo->sasl_username : "none"); 512 513 client = client->next; 514 } 515 } 516 517 static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server) 518 { 519 while (server) { 520 VncServerInfo2 *sinfo = server->value; 521 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server"); 522 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth, 523 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL); 524 server = server->next; 525 } 526 } 527 528 void hmp_info_vnc(Monitor *mon, const QDict *qdict) 529 { 530 VncInfo2List *info2l, *info2l_head; 531 Error *err = NULL; 532 533 info2l = qmp_query_vnc_servers(&err); 534 info2l_head = info2l; 535 if (err) { 536 hmp_handle_error(mon, err); 537 return; 538 } 539 if (!info2l) { 540 monitor_printf(mon, "None\n"); 541 return; 542 } 543 544 while (info2l) { 545 VncInfo2 *info = info2l->value; 546 monitor_printf(mon, "%s:\n", info->id); 547 hmp_info_vnc_servers(mon, info->server); 548 hmp_info_vnc_clients(mon, info->clients); 549 if (!info->server) { 550 /* The server entry displays its auth, we only 551 * need to display in the case of 'reverse' connections 552 * where there's no server. 553 */ 554 hmp_info_vnc_authcrypt(mon, " ", info->auth, 555 info->has_vencrypt ? &info->vencrypt : NULL); 556 } 557 if (info->has_display) { 558 monitor_printf(mon, " Display: %s\n", info->display); 559 } 560 info2l = info2l->next; 561 } 562 563 qapi_free_VncInfo2List(info2l_head); 564 565 } 566 #endif 567 568 #ifdef CONFIG_SPICE 569 void hmp_info_spice(Monitor *mon, const QDict *qdict) 570 { 571 SpiceChannelList *chan; 572 SpiceInfo *info; 573 const char *channel_name; 574 const char * const channel_names[] = { 575 [SPICE_CHANNEL_MAIN] = "main", 576 [SPICE_CHANNEL_DISPLAY] = "display", 577 [SPICE_CHANNEL_INPUTS] = "inputs", 578 [SPICE_CHANNEL_CURSOR] = "cursor", 579 [SPICE_CHANNEL_PLAYBACK] = "playback", 580 [SPICE_CHANNEL_RECORD] = "record", 581 [SPICE_CHANNEL_TUNNEL] = "tunnel", 582 [SPICE_CHANNEL_SMARTCARD] = "smartcard", 583 [SPICE_CHANNEL_USBREDIR] = "usbredir", 584 [SPICE_CHANNEL_PORT] = "port", 585 #if 0 586 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7, 587 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable 588 * as quick fix for build failures with older versions. */ 589 [SPICE_CHANNEL_WEBDAV] = "webdav", 590 #endif 591 }; 592 593 info = qmp_query_spice(NULL); 594 595 if (!info->enabled) { 596 monitor_printf(mon, "Server: disabled\n"); 597 goto out; 598 } 599 600 monitor_printf(mon, "Server:\n"); 601 if (info->has_port) { 602 monitor_printf(mon, " address: %s:%" PRId64 "\n", 603 info->host, info->port); 604 } 605 if (info->has_tls_port) { 606 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n", 607 info->host, info->tls_port); 608 } 609 monitor_printf(mon, " migrated: %s\n", 610 info->migrated ? "true" : "false"); 611 monitor_printf(mon, " auth: %s\n", info->auth); 612 monitor_printf(mon, " compiled: %s\n", info->compiled_version); 613 monitor_printf(mon, " mouse-mode: %s\n", 614 SpiceQueryMouseMode_str(info->mouse_mode)); 615 616 if (!info->has_channels || info->channels == NULL) { 617 monitor_printf(mon, "Channels: none\n"); 618 } else { 619 for (chan = info->channels; chan; chan = chan->next) { 620 monitor_printf(mon, "Channel:\n"); 621 monitor_printf(mon, " address: %s:%s%s\n", 622 chan->value->host, chan->value->port, 623 chan->value->tls ? " [tls]" : ""); 624 monitor_printf(mon, " session: %" PRId64 "\n", 625 chan->value->connection_id); 626 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n", 627 chan->value->channel_type, chan->value->channel_id); 628 629 channel_name = "unknown"; 630 if (chan->value->channel_type > 0 && 631 chan->value->channel_type < ARRAY_SIZE(channel_names) && 632 channel_names[chan->value->channel_type]) { 633 channel_name = channel_names[chan->value->channel_type]; 634 } 635 636 monitor_printf(mon, " channel name: %s\n", channel_name); 637 } 638 } 639 640 out: 641 qapi_free_SpiceInfo(info); 642 } 643 #endif 644 645 void hmp_info_balloon(Monitor *mon, const QDict *qdict) 646 { 647 BalloonInfo *info; 648 Error *err = NULL; 649 650 info = qmp_query_balloon(&err); 651 if (err) { 652 hmp_handle_error(mon, err); 653 return; 654 } 655 656 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20); 657 658 qapi_free_BalloonInfo(info); 659 } 660 661 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) 662 { 663 PciMemoryRegionList *region; 664 665 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus); 666 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n", 667 dev->slot, dev->function); 668 monitor_printf(mon, " "); 669 670 if (dev->class_info->has_desc) { 671 monitor_printf(mon, "%s", dev->class_info->desc); 672 } else { 673 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class); 674 } 675 676 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n", 677 dev->id->vendor, dev->id->device); 678 if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) { 679 monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n", 680 dev->id->subsystem_vendor, dev->id->subsystem); 681 } 682 683 if (dev->has_irq) { 684 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq); 685 } 686 687 if (dev->has_pci_bridge) { 688 monitor_printf(mon, " BUS %" PRId64 ".\n", 689 dev->pci_bridge->bus->number); 690 monitor_printf(mon, " secondary bus %" PRId64 ".\n", 691 dev->pci_bridge->bus->secondary); 692 monitor_printf(mon, " subordinate bus %" PRId64 ".\n", 693 dev->pci_bridge->bus->subordinate); 694 695 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n", 696 dev->pci_bridge->bus->io_range->base, 697 dev->pci_bridge->bus->io_range->limit); 698 699 monitor_printf(mon, 700 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n", 701 dev->pci_bridge->bus->memory_range->base, 702 dev->pci_bridge->bus->memory_range->limit); 703 704 monitor_printf(mon, " prefetchable memory range " 705 "[0x%08"PRIx64", 0x%08"PRIx64"]\n", 706 dev->pci_bridge->bus->prefetchable_range->base, 707 dev->pci_bridge->bus->prefetchable_range->limit); 708 } 709 710 for (region = dev->regions; region; region = region->next) { 711 uint64_t addr, size; 712 713 addr = region->value->address; 714 size = region->value->size; 715 716 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar); 717 718 if (!strcmp(region->value->type, "io")) { 719 monitor_printf(mon, "I/O at 0x%04" PRIx64 720 " [0x%04" PRIx64 "].\n", 721 addr, addr + size - 1); 722 } else { 723 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64 724 " [0x%08" PRIx64 "].\n", 725 region->value->mem_type_64 ? 64 : 32, 726 region->value->prefetch ? " prefetchable" : "", 727 addr, addr + size - 1); 728 } 729 } 730 731 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id); 732 733 if (dev->has_pci_bridge) { 734 if (dev->pci_bridge->has_devices) { 735 PciDeviceInfoList *cdev; 736 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) { 737 hmp_info_pci_device(mon, cdev->value); 738 } 739 } 740 } 741 } 742 743 static int hmp_info_irq_foreach(Object *obj, void *opaque) 744 { 745 InterruptStatsProvider *intc; 746 InterruptStatsProviderClass *k; 747 Monitor *mon = opaque; 748 749 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) { 750 intc = INTERRUPT_STATS_PROVIDER(obj); 751 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj); 752 uint64_t *irq_counts; 753 unsigned int nb_irqs, i; 754 if (k->get_statistics && 755 k->get_statistics(intc, &irq_counts, &nb_irqs)) { 756 if (nb_irqs > 0) { 757 monitor_printf(mon, "IRQ statistics for %s:\n", 758 object_get_typename(obj)); 759 for (i = 0; i < nb_irqs; i++) { 760 if (irq_counts[i] > 0) { 761 monitor_printf(mon, "%2d: %" PRId64 "\n", i, 762 irq_counts[i]); 763 } 764 } 765 } 766 } else { 767 monitor_printf(mon, "IRQ statistics not available for %s.\n", 768 object_get_typename(obj)); 769 } 770 } 771 772 return 0; 773 } 774 775 void hmp_info_irq(Monitor *mon, const QDict *qdict) 776 { 777 object_child_foreach_recursive(object_get_root(), 778 hmp_info_irq_foreach, mon); 779 } 780 781 static int hmp_info_pic_foreach(Object *obj, void *opaque) 782 { 783 InterruptStatsProvider *intc; 784 InterruptStatsProviderClass *k; 785 Monitor *mon = opaque; 786 787 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) { 788 intc = INTERRUPT_STATS_PROVIDER(obj); 789 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj); 790 if (k->print_info) { 791 k->print_info(intc, mon); 792 } else { 793 monitor_printf(mon, "Interrupt controller information not available for %s.\n", 794 object_get_typename(obj)); 795 } 796 } 797 798 return 0; 799 } 800 801 void hmp_info_pic(Monitor *mon, const QDict *qdict) 802 { 803 object_child_foreach_recursive(object_get_root(), 804 hmp_info_pic_foreach, mon); 805 } 806 807 static int hmp_info_rdma_foreach(Object *obj, void *opaque) 808 { 809 RdmaProvider *rdma; 810 RdmaProviderClass *k; 811 Monitor *mon = opaque; 812 813 if (object_dynamic_cast(obj, INTERFACE_RDMA_PROVIDER)) { 814 rdma = RDMA_PROVIDER(obj); 815 k = RDMA_PROVIDER_GET_CLASS(obj); 816 if (k->print_statistics) { 817 k->print_statistics(mon, rdma); 818 } else { 819 monitor_printf(mon, "RDMA statistics not available for %s.\n", 820 object_get_typename(obj)); 821 } 822 } 823 824 return 0; 825 } 826 827 void hmp_info_rdma(Monitor *mon, const QDict *qdict) 828 { 829 object_child_foreach_recursive(object_get_root(), 830 hmp_info_rdma_foreach, mon); 831 } 832 833 void hmp_info_pci(Monitor *mon, const QDict *qdict) 834 { 835 PciInfoList *info_list, *info; 836 Error *err = NULL; 837 838 info_list = qmp_query_pci(&err); 839 if (err) { 840 monitor_printf(mon, "PCI devices not supported\n"); 841 error_free(err); 842 return; 843 } 844 845 for (info = info_list; info; info = info->next) { 846 PciDeviceInfoList *dev; 847 848 for (dev = info->value->devices; dev; dev = dev->next) { 849 hmp_info_pci_device(mon, dev->value); 850 } 851 } 852 853 qapi_free_PciInfoList(info_list); 854 } 855 856 void hmp_info_tpm(Monitor *mon, const QDict *qdict) 857 { 858 TPMInfoList *info_list, *info; 859 Error *err = NULL; 860 unsigned int c = 0; 861 TPMPassthroughOptions *tpo; 862 TPMEmulatorOptions *teo; 863 864 info_list = qmp_query_tpm(&err); 865 if (err) { 866 monitor_printf(mon, "TPM device not supported\n"); 867 error_free(err); 868 return; 869 } 870 871 if (info_list) { 872 monitor_printf(mon, "TPM device:\n"); 873 } 874 875 for (info = info_list; info; info = info->next) { 876 TPMInfo *ti = info->value; 877 monitor_printf(mon, " tpm%d: model=%s\n", 878 c, TpmModel_str(ti->model)); 879 880 monitor_printf(mon, " \\ %s: type=%s", 881 ti->id, TpmTypeOptionsKind_str(ti->options->type)); 882 883 switch (ti->options->type) { 884 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH: 885 tpo = ti->options->u.passthrough.data; 886 monitor_printf(mon, "%s%s%s%s", 887 tpo->has_path ? ",path=" : "", 888 tpo->has_path ? tpo->path : "", 889 tpo->has_cancel_path ? ",cancel-path=" : "", 890 tpo->has_cancel_path ? tpo->cancel_path : ""); 891 break; 892 case TPM_TYPE_OPTIONS_KIND_EMULATOR: 893 teo = ti->options->u.emulator.data; 894 monitor_printf(mon, ",chardev=%s", teo->chardev); 895 break; 896 case TPM_TYPE_OPTIONS_KIND__MAX: 897 break; 898 } 899 monitor_printf(mon, "\n"); 900 c++; 901 } 902 qapi_free_TPMInfoList(info_list); 903 } 904 905 void hmp_quit(Monitor *mon, const QDict *qdict) 906 { 907 monitor_suspend(mon); 908 qmp_quit(NULL); 909 } 910 911 void hmp_stop(Monitor *mon, const QDict *qdict) 912 { 913 qmp_stop(NULL); 914 } 915 916 void hmp_sync_profile(Monitor *mon, const QDict *qdict) 917 { 918 const char *op = qdict_get_try_str(qdict, "op"); 919 920 if (op == NULL) { 921 bool on = qsp_is_enabled(); 922 923 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off"); 924 return; 925 } 926 if (!strcmp(op, "on")) { 927 qsp_enable(); 928 } else if (!strcmp(op, "off")) { 929 qsp_disable(); 930 } else if (!strcmp(op, "reset")) { 931 qsp_reset(); 932 } else { 933 Error *err = NULL; 934 935 error_setg(&err, QERR_INVALID_PARAMETER, op); 936 hmp_handle_error(mon, err); 937 } 938 } 939 940 void hmp_system_reset(Monitor *mon, const QDict *qdict) 941 { 942 qmp_system_reset(NULL); 943 } 944 945 void hmp_system_powerdown(Monitor *mon, const QDict *qdict) 946 { 947 qmp_system_powerdown(NULL); 948 } 949 950 void hmp_exit_preconfig(Monitor *mon, const QDict *qdict) 951 { 952 Error *err = NULL; 953 954 qmp_x_exit_preconfig(&err); 955 hmp_handle_error(mon, err); 956 } 957 958 void hmp_cpu(Monitor *mon, const QDict *qdict) 959 { 960 int64_t cpu_index; 961 962 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that 963 use it are converted to the QAPI */ 964 cpu_index = qdict_get_int(qdict, "index"); 965 if (monitor_set_cpu(cpu_index) < 0) { 966 monitor_printf(mon, "invalid CPU index\n"); 967 } 968 } 969 970 void hmp_memsave(Monitor *mon, const QDict *qdict) 971 { 972 uint32_t size = qdict_get_int(qdict, "size"); 973 const char *filename = qdict_get_str(qdict, "filename"); 974 uint64_t addr = qdict_get_int(qdict, "val"); 975 Error *err = NULL; 976 int cpu_index = monitor_get_cpu_index(); 977 978 if (cpu_index < 0) { 979 monitor_printf(mon, "No CPU available\n"); 980 return; 981 } 982 983 qmp_memsave(addr, size, filename, true, cpu_index, &err); 984 hmp_handle_error(mon, err); 985 } 986 987 void hmp_pmemsave(Monitor *mon, const QDict *qdict) 988 { 989 uint32_t size = qdict_get_int(qdict, "size"); 990 const char *filename = qdict_get_str(qdict, "filename"); 991 uint64_t addr = qdict_get_int(qdict, "val"); 992 Error *err = NULL; 993 994 qmp_pmemsave(addr, size, filename, &err); 995 hmp_handle_error(mon, err); 996 } 997 998 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict) 999 { 1000 const char *chardev = qdict_get_str(qdict, "device"); 1001 const char *data = qdict_get_str(qdict, "data"); 1002 Error *err = NULL; 1003 1004 qmp_ringbuf_write(chardev, data, false, 0, &err); 1005 1006 hmp_handle_error(mon, err); 1007 } 1008 1009 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict) 1010 { 1011 uint32_t size = qdict_get_int(qdict, "size"); 1012 const char *chardev = qdict_get_str(qdict, "device"); 1013 char *data; 1014 Error *err = NULL; 1015 int i; 1016 1017 data = qmp_ringbuf_read(chardev, size, false, 0, &err); 1018 if (err) { 1019 hmp_handle_error(mon, err); 1020 return; 1021 } 1022 1023 for (i = 0; data[i]; i++) { 1024 unsigned char ch = data[i]; 1025 1026 if (ch == '\\') { 1027 monitor_printf(mon, "\\\\"); 1028 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) { 1029 monitor_printf(mon, "\\u%04X", ch); 1030 } else { 1031 monitor_printf(mon, "%c", ch); 1032 } 1033 1034 } 1035 monitor_printf(mon, "\n"); 1036 g_free(data); 1037 } 1038 1039 void hmp_cont(Monitor *mon, const QDict *qdict) 1040 { 1041 Error *err = NULL; 1042 1043 qmp_cont(&err); 1044 hmp_handle_error(mon, err); 1045 } 1046 1047 void hmp_system_wakeup(Monitor *mon, const QDict *qdict) 1048 { 1049 Error *err = NULL; 1050 1051 qmp_system_wakeup(&err); 1052 hmp_handle_error(mon, err); 1053 } 1054 1055 void hmp_nmi(Monitor *mon, const QDict *qdict) 1056 { 1057 Error *err = NULL; 1058 1059 qmp_inject_nmi(&err); 1060 hmp_handle_error(mon, err); 1061 } 1062 1063 void hmp_set_link(Monitor *mon, const QDict *qdict) 1064 { 1065 const char *name = qdict_get_str(qdict, "name"); 1066 bool up = qdict_get_bool(qdict, "up"); 1067 Error *err = NULL; 1068 1069 qmp_set_link(name, up, &err); 1070 hmp_handle_error(mon, err); 1071 } 1072 1073 void hmp_balloon(Monitor *mon, const QDict *qdict) 1074 { 1075 int64_t value = qdict_get_int(qdict, "value"); 1076 Error *err = NULL; 1077 1078 qmp_balloon(value, &err); 1079 hmp_handle_error(mon, err); 1080 } 1081 1082 void hmp_loadvm(Monitor *mon, const QDict *qdict) 1083 { 1084 int saved_vm_running = runstate_is_running(); 1085 const char *name = qdict_get_str(qdict, "name"); 1086 Error *err = NULL; 1087 1088 vm_stop(RUN_STATE_RESTORE_VM); 1089 1090 if (load_snapshot(name, &err) == 0 && saved_vm_running) { 1091 vm_start(); 1092 } 1093 hmp_handle_error(mon, err); 1094 } 1095 1096 void hmp_savevm(Monitor *mon, const QDict *qdict) 1097 { 1098 Error *err = NULL; 1099 1100 save_snapshot(qdict_get_try_str(qdict, "name"), &err); 1101 hmp_handle_error(mon, err); 1102 } 1103 1104 void hmp_delvm(Monitor *mon, const QDict *qdict) 1105 { 1106 BlockDriverState *bs; 1107 Error *err = NULL; 1108 const char *name = qdict_get_str(qdict, "name"); 1109 1110 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) { 1111 error_prepend(&err, 1112 "deleting snapshot on device '%s': ", 1113 bdrv_get_device_name(bs)); 1114 } 1115 hmp_handle_error(mon, err); 1116 } 1117 1118 void hmp_announce_self(Monitor *mon, const QDict *qdict) 1119 { 1120 const char *interfaces_str = qdict_get_try_str(qdict, "interfaces"); 1121 const char *id = qdict_get_try_str(qdict, "id"); 1122 AnnounceParameters *params = QAPI_CLONE(AnnounceParameters, 1123 migrate_announce_params()); 1124 1125 qapi_free_strList(params->interfaces); 1126 params->interfaces = strList_from_comma_list(interfaces_str); 1127 params->has_interfaces = params->interfaces != NULL; 1128 params->id = g_strdup(id); 1129 params->has_id = !!params->id; 1130 qmp_announce_self(params, NULL); 1131 qapi_free_AnnounceParameters(params); 1132 } 1133 1134 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict) 1135 { 1136 qmp_migrate_cancel(NULL); 1137 } 1138 1139 void hmp_migrate_continue(Monitor *mon, const QDict *qdict) 1140 { 1141 Error *err = NULL; 1142 const char *state = qdict_get_str(qdict, "state"); 1143 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err); 1144 1145 if (val >= 0) { 1146 qmp_migrate_continue(val, &err); 1147 } 1148 1149 hmp_handle_error(mon, err); 1150 } 1151 1152 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict) 1153 { 1154 Error *err = NULL; 1155 const char *uri = qdict_get_str(qdict, "uri"); 1156 1157 qmp_migrate_incoming(uri, &err); 1158 1159 hmp_handle_error(mon, err); 1160 } 1161 1162 void hmp_migrate_recover(Monitor *mon, const QDict *qdict) 1163 { 1164 Error *err = NULL; 1165 const char *uri = qdict_get_str(qdict, "uri"); 1166 1167 qmp_migrate_recover(uri, &err); 1168 1169 hmp_handle_error(mon, err); 1170 } 1171 1172 void hmp_migrate_pause(Monitor *mon, const QDict *qdict) 1173 { 1174 Error *err = NULL; 1175 1176 qmp_migrate_pause(&err); 1177 1178 hmp_handle_error(mon, err); 1179 } 1180 1181 /* Kept for backwards compatibility */ 1182 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict) 1183 { 1184 double value = qdict_get_double(qdict, "value"); 1185 qmp_migrate_set_downtime(value, NULL); 1186 } 1187 1188 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict) 1189 { 1190 int64_t value = qdict_get_int(qdict, "value"); 1191 Error *err = NULL; 1192 1193 qmp_migrate_set_cache_size(value, &err); 1194 hmp_handle_error(mon, err); 1195 } 1196 1197 /* Kept for backwards compatibility */ 1198 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict) 1199 { 1200 int64_t value = qdict_get_int(qdict, "value"); 1201 qmp_migrate_set_speed(value, NULL); 1202 } 1203 1204 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict) 1205 { 1206 const char *cap = qdict_get_str(qdict, "capability"); 1207 bool state = qdict_get_bool(qdict, "state"); 1208 Error *err = NULL; 1209 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps)); 1210 int val; 1211 1212 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err); 1213 if (val < 0) { 1214 goto end; 1215 } 1216 1217 caps->value = g_malloc0(sizeof(*caps->value)); 1218 caps->value->capability = val; 1219 caps->value->state = state; 1220 caps->next = NULL; 1221 qmp_migrate_set_capabilities(caps, &err); 1222 1223 end: 1224 qapi_free_MigrationCapabilityStatusList(caps); 1225 hmp_handle_error(mon, err); 1226 } 1227 1228 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) 1229 { 1230 const char *param = qdict_get_str(qdict, "parameter"); 1231 const char *valuestr = qdict_get_str(qdict, "value"); 1232 Visitor *v = string_input_visitor_new(valuestr); 1233 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1); 1234 uint64_t valuebw = 0; 1235 uint64_t cache_size; 1236 MultiFDCompression compress_type; 1237 Error *err = NULL; 1238 int val, ret; 1239 1240 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err); 1241 if (val < 0) { 1242 goto cleanup; 1243 } 1244 1245 switch (val) { 1246 case MIGRATION_PARAMETER_COMPRESS_LEVEL: 1247 p->has_compress_level = true; 1248 visit_type_int(v, param, &p->compress_level, &err); 1249 break; 1250 case MIGRATION_PARAMETER_COMPRESS_THREADS: 1251 p->has_compress_threads = true; 1252 visit_type_int(v, param, &p->compress_threads, &err); 1253 break; 1254 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD: 1255 p->has_compress_wait_thread = true; 1256 visit_type_bool(v, param, &p->compress_wait_thread, &err); 1257 break; 1258 case MIGRATION_PARAMETER_DECOMPRESS_THREADS: 1259 p->has_decompress_threads = true; 1260 visit_type_int(v, param, &p->decompress_threads, &err); 1261 break; 1262 case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD: 1263 p->has_throttle_trigger_threshold = true; 1264 visit_type_int(v, param, &p->throttle_trigger_threshold, &err); 1265 break; 1266 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL: 1267 p->has_cpu_throttle_initial = true; 1268 visit_type_int(v, param, &p->cpu_throttle_initial, &err); 1269 break; 1270 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT: 1271 p->has_cpu_throttle_increment = true; 1272 visit_type_int(v, param, &p->cpu_throttle_increment, &err); 1273 break; 1274 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE: 1275 p->has_max_cpu_throttle = true; 1276 visit_type_int(v, param, &p->max_cpu_throttle, &err); 1277 break; 1278 case MIGRATION_PARAMETER_TLS_CREDS: 1279 p->has_tls_creds = true; 1280 p->tls_creds = g_new0(StrOrNull, 1); 1281 p->tls_creds->type = QTYPE_QSTRING; 1282 visit_type_str(v, param, &p->tls_creds->u.s, &err); 1283 break; 1284 case MIGRATION_PARAMETER_TLS_HOSTNAME: 1285 p->has_tls_hostname = true; 1286 p->tls_hostname = g_new0(StrOrNull, 1); 1287 p->tls_hostname->type = QTYPE_QSTRING; 1288 visit_type_str(v, param, &p->tls_hostname->u.s, &err); 1289 break; 1290 case MIGRATION_PARAMETER_TLS_AUTHZ: 1291 p->has_tls_authz = true; 1292 p->tls_authz = g_new0(StrOrNull, 1); 1293 p->tls_authz->type = QTYPE_QSTRING; 1294 visit_type_str(v, param, &p->tls_authz->u.s, &err); 1295 break; 1296 case MIGRATION_PARAMETER_MAX_BANDWIDTH: 1297 p->has_max_bandwidth = true; 1298 /* 1299 * Can't use visit_type_size() here, because it 1300 * defaults to Bytes rather than Mebibytes. 1301 */ 1302 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw); 1303 if (ret < 0 || valuebw > INT64_MAX 1304 || (size_t)valuebw != valuebw) { 1305 error_setg(&err, "Invalid size %s", valuestr); 1306 break; 1307 } 1308 p->max_bandwidth = valuebw; 1309 break; 1310 case MIGRATION_PARAMETER_DOWNTIME_LIMIT: 1311 p->has_downtime_limit = true; 1312 visit_type_int(v, param, &p->downtime_limit, &err); 1313 break; 1314 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY: 1315 p->has_x_checkpoint_delay = true; 1316 visit_type_int(v, param, &p->x_checkpoint_delay, &err); 1317 break; 1318 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL: 1319 p->has_block_incremental = true; 1320 visit_type_bool(v, param, &p->block_incremental, &err); 1321 break; 1322 case MIGRATION_PARAMETER_MULTIFD_CHANNELS: 1323 p->has_multifd_channels = true; 1324 visit_type_int(v, param, &p->multifd_channels, &err); 1325 break; 1326 case MIGRATION_PARAMETER_MULTIFD_COMPRESSION: 1327 p->has_multifd_compression = true; 1328 visit_type_MultiFDCompression(v, param, &compress_type, &err); 1329 if (err) { 1330 break; 1331 } 1332 p->multifd_compression = compress_type; 1333 break; 1334 case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL: 1335 p->has_multifd_zlib_level = true; 1336 visit_type_int(v, param, &p->multifd_zlib_level, &err); 1337 break; 1338 case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL: 1339 p->has_multifd_zstd_level = true; 1340 visit_type_int(v, param, &p->multifd_zstd_level, &err); 1341 break; 1342 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE: 1343 p->has_xbzrle_cache_size = true; 1344 visit_type_size(v, param, &cache_size, &err); 1345 if (err) { 1346 break; 1347 } 1348 if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) { 1349 error_setg(&err, "Invalid size %s", valuestr); 1350 break; 1351 } 1352 p->xbzrle_cache_size = cache_size; 1353 break; 1354 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH: 1355 p->has_max_postcopy_bandwidth = true; 1356 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err); 1357 break; 1358 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL: 1359 p->has_announce_initial = true; 1360 visit_type_size(v, param, &p->announce_initial, &err); 1361 break; 1362 case MIGRATION_PARAMETER_ANNOUNCE_MAX: 1363 p->has_announce_max = true; 1364 visit_type_size(v, param, &p->announce_max, &err); 1365 break; 1366 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS: 1367 p->has_announce_rounds = true; 1368 visit_type_size(v, param, &p->announce_rounds, &err); 1369 break; 1370 case MIGRATION_PARAMETER_ANNOUNCE_STEP: 1371 p->has_announce_step = true; 1372 visit_type_size(v, param, &p->announce_step, &err); 1373 break; 1374 default: 1375 assert(0); 1376 } 1377 1378 if (err) { 1379 goto cleanup; 1380 } 1381 1382 qmp_migrate_set_parameters(p, &err); 1383 1384 cleanup: 1385 qapi_free_MigrateSetParameters(p); 1386 visit_free(v); 1387 hmp_handle_error(mon, err); 1388 } 1389 1390 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict) 1391 { 1392 Error *err = NULL; 1393 const char *protocol = qdict_get_str(qdict, "protocol"); 1394 const char *hostname = qdict_get_str(qdict, "hostname"); 1395 bool has_port = qdict_haskey(qdict, "port"); 1396 int port = qdict_get_try_int(qdict, "port", -1); 1397 bool has_tls_port = qdict_haskey(qdict, "tls-port"); 1398 int tls_port = qdict_get_try_int(qdict, "tls-port", -1); 1399 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject"); 1400 1401 qmp_client_migrate_info(protocol, hostname, 1402 has_port, port, has_tls_port, tls_port, 1403 !!cert_subject, cert_subject, &err); 1404 hmp_handle_error(mon, err); 1405 } 1406 1407 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict) 1408 { 1409 Error *err = NULL; 1410 qmp_migrate_start_postcopy(&err); 1411 hmp_handle_error(mon, err); 1412 } 1413 1414 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict) 1415 { 1416 Error *err = NULL; 1417 1418 qmp_x_colo_lost_heartbeat(&err); 1419 hmp_handle_error(mon, err); 1420 } 1421 1422 void hmp_set_password(Monitor *mon, const QDict *qdict) 1423 { 1424 const char *protocol = qdict_get_str(qdict, "protocol"); 1425 const char *password = qdict_get_str(qdict, "password"); 1426 const char *connected = qdict_get_try_str(qdict, "connected"); 1427 Error *err = NULL; 1428 1429 qmp_set_password(protocol, password, !!connected, connected, &err); 1430 hmp_handle_error(mon, err); 1431 } 1432 1433 void hmp_expire_password(Monitor *mon, const QDict *qdict) 1434 { 1435 const char *protocol = qdict_get_str(qdict, "protocol"); 1436 const char *whenstr = qdict_get_str(qdict, "time"); 1437 Error *err = NULL; 1438 1439 qmp_expire_password(protocol, whenstr, &err); 1440 hmp_handle_error(mon, err); 1441 } 1442 1443 1444 #ifdef CONFIG_VNC 1445 static void hmp_change_read_arg(void *opaque, const char *password, 1446 void *readline_opaque) 1447 { 1448 qmp_change_vnc_password(password, NULL); 1449 monitor_read_command(opaque, 1); 1450 } 1451 #endif 1452 1453 void hmp_change(Monitor *mon, const QDict *qdict) 1454 { 1455 const char *device = qdict_get_str(qdict, "device"); 1456 const char *target = qdict_get_str(qdict, "target"); 1457 const char *arg = qdict_get_try_str(qdict, "arg"); 1458 const char *read_only = qdict_get_try_str(qdict, "read-only-mode"); 1459 BlockdevChangeReadOnlyMode read_only_mode = 0; 1460 Error *err = NULL; 1461 1462 #ifdef CONFIG_VNC 1463 if (strcmp(device, "vnc") == 0) { 1464 if (read_only) { 1465 monitor_printf(mon, 1466 "Parameter 'read-only-mode' is invalid for VNC\n"); 1467 return; 1468 } 1469 if (strcmp(target, "passwd") == 0 || 1470 strcmp(target, "password") == 0) { 1471 if (!arg) { 1472 MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common); 1473 monitor_read_password(hmp_mon, hmp_change_read_arg, NULL); 1474 return; 1475 } 1476 } 1477 qmp_change("vnc", target, !!arg, arg, &err); 1478 } else 1479 #endif 1480 { 1481 if (read_only) { 1482 read_only_mode = 1483 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup, 1484 read_only, 1485 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err); 1486 if (err) { 1487 hmp_handle_error(mon, err); 1488 return; 1489 } 1490 } 1491 1492 qmp_blockdev_change_medium(true, device, false, NULL, target, 1493 !!arg, arg, !!read_only, read_only_mode, 1494 &err); 1495 } 1496 1497 hmp_handle_error(mon, err); 1498 } 1499 1500 typedef struct HMPMigrationStatus 1501 { 1502 QEMUTimer *timer; 1503 Monitor *mon; 1504 bool is_block_migration; 1505 } HMPMigrationStatus; 1506 1507 static void hmp_migrate_status_cb(void *opaque) 1508 { 1509 HMPMigrationStatus *status = opaque; 1510 MigrationInfo *info; 1511 1512 info = qmp_query_migrate(NULL); 1513 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE || 1514 info->status == MIGRATION_STATUS_SETUP) { 1515 if (info->has_disk) { 1516 int progress; 1517 1518 if (info->disk->remaining) { 1519 progress = info->disk->transferred * 100 / info->disk->total; 1520 } else { 1521 progress = 100; 1522 } 1523 1524 monitor_printf(status->mon, "Completed %d %%\r", progress); 1525 monitor_flush(status->mon); 1526 } 1527 1528 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000); 1529 } else { 1530 if (status->is_block_migration) { 1531 monitor_printf(status->mon, "\n"); 1532 } 1533 if (info->has_error_desc) { 1534 error_report("%s", info->error_desc); 1535 } 1536 monitor_resume(status->mon); 1537 timer_del(status->timer); 1538 timer_free(status->timer); 1539 g_free(status); 1540 } 1541 1542 qapi_free_MigrationInfo(info); 1543 } 1544 1545 void hmp_migrate(Monitor *mon, const QDict *qdict) 1546 { 1547 bool detach = qdict_get_try_bool(qdict, "detach", false); 1548 bool blk = qdict_get_try_bool(qdict, "blk", false); 1549 bool inc = qdict_get_try_bool(qdict, "inc", false); 1550 bool resume = qdict_get_try_bool(qdict, "resume", false); 1551 const char *uri = qdict_get_str(qdict, "uri"); 1552 Error *err = NULL; 1553 1554 qmp_migrate(uri, !!blk, blk, !!inc, inc, 1555 false, false, true, resume, &err); 1556 if (err) { 1557 hmp_handle_error(mon, err); 1558 return; 1559 } 1560 1561 if (!detach) { 1562 HMPMigrationStatus *status; 1563 1564 if (monitor_suspend(mon) < 0) { 1565 monitor_printf(mon, "terminal does not allow synchronous " 1566 "migration, continuing detached\n"); 1567 return; 1568 } 1569 1570 status = g_malloc0(sizeof(*status)); 1571 status->mon = mon; 1572 status->is_block_migration = blk || inc; 1573 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb, 1574 status); 1575 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME)); 1576 } 1577 } 1578 1579 void hmp_netdev_add(Monitor *mon, const QDict *qdict) 1580 { 1581 Error *err = NULL; 1582 QemuOpts *opts; 1583 1584 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err); 1585 if (err) { 1586 goto out; 1587 } 1588 1589 netdev_add(opts, &err); 1590 if (err) { 1591 qemu_opts_del(opts); 1592 } 1593 1594 out: 1595 hmp_handle_error(mon, err); 1596 } 1597 1598 void hmp_netdev_del(Monitor *mon, const QDict *qdict) 1599 { 1600 const char *id = qdict_get_str(qdict, "id"); 1601 Error *err = NULL; 1602 1603 qmp_netdev_del(id, &err); 1604 hmp_handle_error(mon, err); 1605 } 1606 1607 void hmp_object_add(Monitor *mon, const QDict *qdict) 1608 { 1609 Error *err = NULL; 1610 QemuOpts *opts; 1611 Object *obj = NULL; 1612 1613 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err); 1614 if (err) { 1615 hmp_handle_error(mon, err); 1616 return; 1617 } 1618 1619 obj = user_creatable_add_opts(opts, &err); 1620 qemu_opts_del(opts); 1621 1622 if (err) { 1623 hmp_handle_error(mon, err); 1624 } 1625 if (obj) { 1626 object_unref(obj); 1627 } 1628 } 1629 1630 void hmp_getfd(Monitor *mon, const QDict *qdict) 1631 { 1632 const char *fdname = qdict_get_str(qdict, "fdname"); 1633 Error *err = NULL; 1634 1635 qmp_getfd(fdname, &err); 1636 hmp_handle_error(mon, err); 1637 } 1638 1639 void hmp_closefd(Monitor *mon, const QDict *qdict) 1640 { 1641 const char *fdname = qdict_get_str(qdict, "fdname"); 1642 Error *err = NULL; 1643 1644 qmp_closefd(fdname, &err); 1645 hmp_handle_error(mon, err); 1646 } 1647 1648 void hmp_sendkey(Monitor *mon, const QDict *qdict) 1649 { 1650 const char *keys = qdict_get_str(qdict, "keys"); 1651 KeyValueList *keylist, *head = NULL, *tmp = NULL; 1652 int has_hold_time = qdict_haskey(qdict, "hold-time"); 1653 int hold_time = qdict_get_try_int(qdict, "hold-time", -1); 1654 Error *err = NULL; 1655 const char *separator; 1656 int keyname_len; 1657 1658 while (1) { 1659 separator = qemu_strchrnul(keys, '-'); 1660 keyname_len = separator - keys; 1661 1662 /* Be compatible with old interface, convert user inputted "<" */ 1663 if (keys[0] == '<' && keyname_len == 1) { 1664 keys = "less"; 1665 keyname_len = 4; 1666 } 1667 1668 keylist = g_malloc0(sizeof(*keylist)); 1669 keylist->value = g_malloc0(sizeof(*keylist->value)); 1670 1671 if (!head) { 1672 head = keylist; 1673 } 1674 if (tmp) { 1675 tmp->next = keylist; 1676 } 1677 tmp = keylist; 1678 1679 if (strstart(keys, "0x", NULL)) { 1680 char *endp; 1681 int value = strtoul(keys, &endp, 0); 1682 assert(endp <= keys + keyname_len); 1683 if (endp != keys + keyname_len) { 1684 goto err_out; 1685 } 1686 keylist->value->type = KEY_VALUE_KIND_NUMBER; 1687 keylist->value->u.number.data = value; 1688 } else { 1689 int idx = index_from_key(keys, keyname_len); 1690 if (idx == Q_KEY_CODE__MAX) { 1691 goto err_out; 1692 } 1693 keylist->value->type = KEY_VALUE_KIND_QCODE; 1694 keylist->value->u.qcode.data = idx; 1695 } 1696 1697 if (!*separator) { 1698 break; 1699 } 1700 keys = separator + 1; 1701 } 1702 1703 qmp_send_key(head, has_hold_time, hold_time, &err); 1704 hmp_handle_error(mon, err); 1705 1706 out: 1707 qapi_free_KeyValueList(head); 1708 return; 1709 1710 err_out: 1711 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys); 1712 goto out; 1713 } 1714 1715 void hmp_screendump(Monitor *mon, const QDict *qdict) 1716 { 1717 const char *filename = qdict_get_str(qdict, "filename"); 1718 const char *id = qdict_get_try_str(qdict, "device"); 1719 int64_t head = qdict_get_try_int(qdict, "head", 0); 1720 Error *err = NULL; 1721 1722 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err); 1723 hmp_handle_error(mon, err); 1724 } 1725 1726 void hmp_chardev_add(Monitor *mon, const QDict *qdict) 1727 { 1728 const char *args = qdict_get_str(qdict, "args"); 1729 Error *err = NULL; 1730 QemuOpts *opts; 1731 1732 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true); 1733 if (opts == NULL) { 1734 error_setg(&err, "Parsing chardev args failed"); 1735 } else { 1736 qemu_chr_new_from_opts(opts, NULL, &err); 1737 qemu_opts_del(opts); 1738 } 1739 hmp_handle_error(mon, err); 1740 } 1741 1742 void hmp_chardev_change(Monitor *mon, const QDict *qdict) 1743 { 1744 const char *args = qdict_get_str(qdict, "args"); 1745 const char *id; 1746 Error *err = NULL; 1747 ChardevBackend *backend = NULL; 1748 ChardevReturn *ret = NULL; 1749 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, 1750 true); 1751 if (!opts) { 1752 error_setg(&err, "Parsing chardev args failed"); 1753 goto end; 1754 } 1755 1756 id = qdict_get_str(qdict, "id"); 1757 if (qemu_opts_id(opts)) { 1758 error_setg(&err, "Unexpected 'id' parameter"); 1759 goto end; 1760 } 1761 1762 backend = qemu_chr_parse_opts(opts, &err); 1763 if (!backend) { 1764 goto end; 1765 } 1766 1767 ret = qmp_chardev_change(id, backend, &err); 1768 1769 end: 1770 qapi_free_ChardevReturn(ret); 1771 qapi_free_ChardevBackend(backend); 1772 qemu_opts_del(opts); 1773 hmp_handle_error(mon, err); 1774 } 1775 1776 void hmp_chardev_remove(Monitor *mon, const QDict *qdict) 1777 { 1778 Error *local_err = NULL; 1779 1780 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err); 1781 hmp_handle_error(mon, local_err); 1782 } 1783 1784 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict) 1785 { 1786 Error *local_err = NULL; 1787 1788 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err); 1789 hmp_handle_error(mon, local_err); 1790 } 1791 1792 void hmp_object_del(Monitor *mon, const QDict *qdict) 1793 { 1794 const char *id = qdict_get_str(qdict, "id"); 1795 Error *err = NULL; 1796 1797 user_creatable_del(id, &err); 1798 hmp_handle_error(mon, err); 1799 } 1800 1801 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) 1802 { 1803 Error *err = NULL; 1804 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err); 1805 MemoryDeviceInfoList *info; 1806 VirtioPMEMDeviceInfo *vpi; 1807 MemoryDeviceInfo *value; 1808 PCDIMMDeviceInfo *di; 1809 1810 for (info = info_list; info; info = info->next) { 1811 value = info->value; 1812 1813 if (value) { 1814 switch (value->type) { 1815 case MEMORY_DEVICE_INFO_KIND_DIMM: 1816 case MEMORY_DEVICE_INFO_KIND_NVDIMM: 1817 di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ? 1818 value->u.dimm.data : value->u.nvdimm.data; 1819 monitor_printf(mon, "Memory device [%s]: \"%s\"\n", 1820 MemoryDeviceInfoKind_str(value->type), 1821 di->id ? di->id : ""); 1822 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr); 1823 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot); 1824 monitor_printf(mon, " node: %" PRId64 "\n", di->node); 1825 monitor_printf(mon, " size: %" PRIu64 "\n", di->size); 1826 monitor_printf(mon, " memdev: %s\n", di->memdev); 1827 monitor_printf(mon, " hotplugged: %s\n", 1828 di->hotplugged ? "true" : "false"); 1829 monitor_printf(mon, " hotpluggable: %s\n", 1830 di->hotpluggable ? "true" : "false"); 1831 break; 1832 case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM: 1833 vpi = value->u.virtio_pmem.data; 1834 monitor_printf(mon, "Memory device [%s]: \"%s\"\n", 1835 MemoryDeviceInfoKind_str(value->type), 1836 vpi->id ? vpi->id : ""); 1837 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->memaddr); 1838 monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size); 1839 monitor_printf(mon, " memdev: %s\n", vpi->memdev); 1840 break; 1841 default: 1842 g_assert_not_reached(); 1843 } 1844 } 1845 } 1846 1847 qapi_free_MemoryDeviceInfoList(info_list); 1848 hmp_handle_error(mon, err); 1849 } 1850 1851 void hmp_info_iothreads(Monitor *mon, const QDict *qdict) 1852 { 1853 IOThreadInfoList *info_list = qmp_query_iothreads(NULL); 1854 IOThreadInfoList *info; 1855 IOThreadInfo *value; 1856 1857 for (info = info_list; info; info = info->next) { 1858 value = info->value; 1859 monitor_printf(mon, "%s:\n", value->id); 1860 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id); 1861 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns); 1862 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow); 1863 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink); 1864 } 1865 1866 qapi_free_IOThreadInfoList(info_list); 1867 } 1868 1869 void hmp_rocker(Monitor *mon, const QDict *qdict) 1870 { 1871 const char *name = qdict_get_str(qdict, "name"); 1872 RockerSwitch *rocker; 1873 Error *err = NULL; 1874 1875 rocker = qmp_query_rocker(name, &err); 1876 if (err != NULL) { 1877 hmp_handle_error(mon, err); 1878 return; 1879 } 1880 1881 monitor_printf(mon, "name: %s\n", rocker->name); 1882 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id); 1883 monitor_printf(mon, "ports: %d\n", rocker->ports); 1884 1885 qapi_free_RockerSwitch(rocker); 1886 } 1887 1888 void hmp_rocker_ports(Monitor *mon, const QDict *qdict) 1889 { 1890 RockerPortList *list, *port; 1891 const char *name = qdict_get_str(qdict, "name"); 1892 Error *err = NULL; 1893 1894 list = qmp_query_rocker_ports(name, &err); 1895 if (err != NULL) { 1896 hmp_handle_error(mon, err); 1897 return; 1898 } 1899 1900 monitor_printf(mon, " ena/ speed/ auto\n"); 1901 monitor_printf(mon, " port link duplex neg?\n"); 1902 1903 for (port = list; port; port = port->next) { 1904 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n", 1905 port->value->name, 1906 port->value->enabled ? port->value->link_up ? 1907 "up" : "down" : "!ena", 1908 port->value->speed == 10000 ? "10G" : "??", 1909 port->value->duplex ? "FD" : "HD", 1910 port->value->autoneg ? "Yes" : "No"); 1911 } 1912 1913 qapi_free_RockerPortList(list); 1914 } 1915 1916 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict) 1917 { 1918 RockerOfDpaFlowList *list, *info; 1919 const char *name = qdict_get_str(qdict, "name"); 1920 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1); 1921 Error *err = NULL; 1922 1923 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err); 1924 if (err != NULL) { 1925 hmp_handle_error(mon, err); 1926 return; 1927 } 1928 1929 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n"); 1930 1931 for (info = list; info; info = info->next) { 1932 RockerOfDpaFlow *flow = info->value; 1933 RockerOfDpaFlowKey *key = flow->key; 1934 RockerOfDpaFlowMask *mask = flow->mask; 1935 RockerOfDpaFlowAction *action = flow->action; 1936 1937 if (flow->hits) { 1938 monitor_printf(mon, "%-4d %-3d %-4" PRIu64, 1939 key->priority, key->tbl_id, flow->hits); 1940 } else { 1941 monitor_printf(mon, "%-4d %-3d ", 1942 key->priority, key->tbl_id); 1943 } 1944 1945 if (key->has_in_pport) { 1946 monitor_printf(mon, " pport %d", key->in_pport); 1947 if (mask->has_in_pport) { 1948 monitor_printf(mon, "(0x%x)", mask->in_pport); 1949 } 1950 } 1951 1952 if (key->has_vlan_id) { 1953 monitor_printf(mon, " vlan %d", 1954 key->vlan_id & VLAN_VID_MASK); 1955 if (mask->has_vlan_id) { 1956 monitor_printf(mon, "(0x%x)", mask->vlan_id); 1957 } 1958 } 1959 1960 if (key->has_tunnel_id) { 1961 monitor_printf(mon, " tunnel %d", key->tunnel_id); 1962 if (mask->has_tunnel_id) { 1963 monitor_printf(mon, "(0x%x)", mask->tunnel_id); 1964 } 1965 } 1966 1967 if (key->has_eth_type) { 1968 switch (key->eth_type) { 1969 case 0x0806: 1970 monitor_printf(mon, " ARP"); 1971 break; 1972 case 0x0800: 1973 monitor_printf(mon, " IP"); 1974 break; 1975 case 0x86dd: 1976 monitor_printf(mon, " IPv6"); 1977 break; 1978 case 0x8809: 1979 monitor_printf(mon, " LACP"); 1980 break; 1981 case 0x88cc: 1982 monitor_printf(mon, " LLDP"); 1983 break; 1984 default: 1985 monitor_printf(mon, " eth type 0x%04x", key->eth_type); 1986 break; 1987 } 1988 } 1989 1990 if (key->has_eth_src) { 1991 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) && 1992 (mask->has_eth_src) && 1993 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { 1994 monitor_printf(mon, " src <any mcast/bcast>"); 1995 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) && 1996 (mask->has_eth_src) && 1997 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { 1998 monitor_printf(mon, " src <any ucast>"); 1999 } else { 2000 monitor_printf(mon, " src %s", key->eth_src); 2001 if (mask->has_eth_src) { 2002 monitor_printf(mon, "(%s)", mask->eth_src); 2003 } 2004 } 2005 } 2006 2007 if (key->has_eth_dst) { 2008 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) && 2009 (mask->has_eth_dst) && 2010 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { 2011 monitor_printf(mon, " dst <any mcast/bcast>"); 2012 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) && 2013 (mask->has_eth_dst) && 2014 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { 2015 monitor_printf(mon, " dst <any ucast>"); 2016 } else { 2017 monitor_printf(mon, " dst %s", key->eth_dst); 2018 if (mask->has_eth_dst) { 2019 monitor_printf(mon, "(%s)", mask->eth_dst); 2020 } 2021 } 2022 } 2023 2024 if (key->has_ip_proto) { 2025 monitor_printf(mon, " proto %d", key->ip_proto); 2026 if (mask->has_ip_proto) { 2027 monitor_printf(mon, "(0x%x)", mask->ip_proto); 2028 } 2029 } 2030 2031 if (key->has_ip_tos) { 2032 monitor_printf(mon, " TOS %d", key->ip_tos); 2033 if (mask->has_ip_tos) { 2034 monitor_printf(mon, "(0x%x)", mask->ip_tos); 2035 } 2036 } 2037 2038 if (key->has_ip_dst) { 2039 monitor_printf(mon, " dst %s", key->ip_dst); 2040 } 2041 2042 if (action->has_goto_tbl || action->has_group_id || 2043 action->has_new_vlan_id) { 2044 monitor_printf(mon, " -->"); 2045 } 2046 2047 if (action->has_new_vlan_id) { 2048 monitor_printf(mon, " apply new vlan %d", 2049 ntohs(action->new_vlan_id)); 2050 } 2051 2052 if (action->has_group_id) { 2053 monitor_printf(mon, " write group 0x%08x", action->group_id); 2054 } 2055 2056 if (action->has_goto_tbl) { 2057 monitor_printf(mon, " goto tbl %d", action->goto_tbl); 2058 } 2059 2060 monitor_printf(mon, "\n"); 2061 } 2062 2063 qapi_free_RockerOfDpaFlowList(list); 2064 } 2065 2066 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict) 2067 { 2068 RockerOfDpaGroupList *list, *g; 2069 const char *name = qdict_get_str(qdict, "name"); 2070 uint8_t type = qdict_get_try_int(qdict, "type", 9); 2071 Error *err = NULL; 2072 2073 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err); 2074 if (err != NULL) { 2075 hmp_handle_error(mon, err); 2076 return; 2077 } 2078 2079 monitor_printf(mon, "id (decode) --> buckets\n"); 2080 2081 for (g = list; g; g = g->next) { 2082 RockerOfDpaGroup *group = g->value; 2083 bool set = false; 2084 2085 monitor_printf(mon, "0x%08x", group->id); 2086 2087 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" : 2088 group->type == 1 ? "L2 rewrite" : 2089 group->type == 2 ? "L3 unicast" : 2090 group->type == 3 ? "L2 multicast" : 2091 group->type == 4 ? "L2 flood" : 2092 group->type == 5 ? "L3 interface" : 2093 group->type == 6 ? "L3 multicast" : 2094 group->type == 7 ? "L3 ECMP" : 2095 group->type == 8 ? "L2 overlay" : 2096 "unknown"); 2097 2098 if (group->has_vlan_id) { 2099 monitor_printf(mon, " vlan %d", group->vlan_id); 2100 } 2101 2102 if (group->has_pport) { 2103 monitor_printf(mon, " pport %d", group->pport); 2104 } 2105 2106 if (group->has_index) { 2107 monitor_printf(mon, " index %d", group->index); 2108 } 2109 2110 monitor_printf(mon, ") -->"); 2111 2112 if (group->has_set_vlan_id && group->set_vlan_id) { 2113 set = true; 2114 monitor_printf(mon, " set vlan %d", 2115 group->set_vlan_id & VLAN_VID_MASK); 2116 } 2117 2118 if (group->has_set_eth_src) { 2119 if (!set) { 2120 set = true; 2121 monitor_printf(mon, " set"); 2122 } 2123 monitor_printf(mon, " src %s", group->set_eth_src); 2124 } 2125 2126 if (group->has_set_eth_dst) { 2127 if (!set) { 2128 monitor_printf(mon, " set"); 2129 } 2130 monitor_printf(mon, " dst %s", group->set_eth_dst); 2131 } 2132 2133 if (group->has_ttl_check && group->ttl_check) { 2134 monitor_printf(mon, " check TTL"); 2135 } 2136 2137 if (group->has_group_id && group->group_id) { 2138 monitor_printf(mon, " group id 0x%08x", group->group_id); 2139 } 2140 2141 if (group->has_pop_vlan && group->pop_vlan) { 2142 monitor_printf(mon, " pop vlan"); 2143 } 2144 2145 if (group->has_out_pport) { 2146 monitor_printf(mon, " out pport %d", group->out_pport); 2147 } 2148 2149 if (group->has_group_ids) { 2150 struct uint32List *id; 2151 2152 monitor_printf(mon, " groups ["); 2153 for (id = group->group_ids; id; id = id->next) { 2154 monitor_printf(mon, "0x%08x", id->value); 2155 if (id->next) { 2156 monitor_printf(mon, ","); 2157 } 2158 } 2159 monitor_printf(mon, "]"); 2160 } 2161 2162 monitor_printf(mon, "\n"); 2163 } 2164 2165 qapi_free_RockerOfDpaGroupList(list); 2166 } 2167 2168 void hmp_info_ramblock(Monitor *mon, const QDict *qdict) 2169 { 2170 ram_block_dump(mon); 2171 } 2172 2173 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict) 2174 { 2175 Error *err = NULL; 2176 GuidInfo *info = qmp_query_vm_generation_id(&err); 2177 if (info) { 2178 monitor_printf(mon, "%s\n", info->guid); 2179 } 2180 hmp_handle_error(mon, err); 2181 qapi_free_GuidInfo(info); 2182 } 2183 2184 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict) 2185 { 2186 Error *err = NULL; 2187 MemoryInfo *info = qmp_query_memory_size_summary(&err); 2188 if (info) { 2189 monitor_printf(mon, "base memory: %" PRIu64 "\n", 2190 info->base_memory); 2191 2192 if (info->has_plugged_memory) { 2193 monitor_printf(mon, "plugged memory: %" PRIu64 "\n", 2194 info->plugged_memory); 2195 } 2196 2197 qapi_free_MemoryInfo(info); 2198 } 2199 hmp_handle_error(mon, err); 2200 } 2201