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