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