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