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