1 /* 2 * QEMU migration capabilities 3 * 4 * Copyright (c) 2012-2023 Red Hat Inc 5 * 6 * Authors: 7 * Orit Wasserman <owasserm@redhat.com> 8 * Juan Quintela <quintela@redhat.com> 9 * 10 * This work is licensed under the terms of the GNU GPL, version 2 or later. 11 * See the COPYING file in the top-level directory. 12 */ 13 14 #include "qemu/osdep.h" 15 #include "exec/target_page.h" 16 #include "qapi/clone-visitor.h" 17 #include "qapi/error.h" 18 #include "qapi/qapi-commands-migration.h" 19 #include "qapi/qapi-visit-migration.h" 20 #include "qapi/qmp/qerror.h" 21 #include "qapi/qmp/qnull.h" 22 #include "sysemu/runstate.h" 23 #include "migration/colo.h" 24 #include "migration/misc.h" 25 #include "migration.h" 26 #include "migration-stats.h" 27 #include "qemu-file.h" 28 #include "ram.h" 29 #include "options.h" 30 #include "sysemu/kvm.h" 31 32 /* Maximum migrate downtime set to 2000 seconds */ 33 #define MAX_MIGRATE_DOWNTIME_SECONDS 2000 34 #define MAX_MIGRATE_DOWNTIME (MAX_MIGRATE_DOWNTIME_SECONDS * 1000) 35 36 #define MAX_THROTTLE (128 << 20) /* Migration transfer speed throttling */ 37 38 /* Time in milliseconds we are allowed to stop the source, 39 * for sending the last part */ 40 #define DEFAULT_MIGRATE_SET_DOWNTIME 300 41 42 /* Default compression thread count */ 43 #define DEFAULT_MIGRATE_COMPRESS_THREAD_COUNT 8 44 /* Default decompression thread count, usually decompression is at 45 * least 4 times as fast as compression.*/ 46 #define DEFAULT_MIGRATE_DECOMPRESS_THREAD_COUNT 2 47 /*0: means nocompress, 1: best speed, ... 9: best compress ratio */ 48 #define DEFAULT_MIGRATE_COMPRESS_LEVEL 1 49 /* Define default autoconverge cpu throttle migration parameters */ 50 #define DEFAULT_MIGRATE_THROTTLE_TRIGGER_THRESHOLD 50 51 #define DEFAULT_MIGRATE_CPU_THROTTLE_INITIAL 20 52 #define DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT 10 53 #define DEFAULT_MIGRATE_MAX_CPU_THROTTLE 99 54 55 /* Migration XBZRLE default cache size */ 56 #define DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE (64 * 1024 * 1024) 57 58 /* The delay time (in ms) between two COLO checkpoints */ 59 #define DEFAULT_MIGRATE_X_CHECKPOINT_DELAY (200 * 100) 60 #define DEFAULT_MIGRATE_MULTIFD_CHANNELS 2 61 #define DEFAULT_MIGRATE_MULTIFD_COMPRESSION MULTIFD_COMPRESSION_NONE 62 /* 0: means nocompress, 1: best speed, ... 9: best compress ratio */ 63 #define DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL 1 64 /* 0: means nocompress, 1: best speed, ... 20: best compress ratio */ 65 #define DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL 1 66 67 /* Background transfer rate for postcopy, 0 means unlimited, note 68 * that page requests can still exceed this limit. 69 */ 70 #define DEFAULT_MIGRATE_MAX_POSTCOPY_BANDWIDTH 0 71 72 /* 73 * Parameters for self_announce_delay giving a stream of RARP/ARP 74 * packets after migration. 75 */ 76 #define DEFAULT_MIGRATE_ANNOUNCE_INITIAL 50 77 #define DEFAULT_MIGRATE_ANNOUNCE_MAX 550 78 #define DEFAULT_MIGRATE_ANNOUNCE_ROUNDS 5 79 #define DEFAULT_MIGRATE_ANNOUNCE_STEP 100 80 81 #define DEFINE_PROP_MIG_CAP(name, x) \ 82 DEFINE_PROP_BOOL(name, MigrationState, capabilities[x], false) 83 84 #define DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD 1000 /* milliseconds */ 85 #define DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT 1 /* MB/s */ 86 87 Property migration_properties[] = { 88 DEFINE_PROP_BOOL("store-global-state", MigrationState, 89 store_global_state, true), 90 DEFINE_PROP_BOOL("send-configuration", MigrationState, 91 send_configuration, true), 92 DEFINE_PROP_BOOL("send-section-footer", MigrationState, 93 send_section_footer, true), 94 DEFINE_PROP_BOOL("decompress-error-check", MigrationState, 95 decompress_error_check, true), 96 DEFINE_PROP_BOOL("multifd-flush-after-each-section", MigrationState, 97 multifd_flush_after_each_section, false), 98 DEFINE_PROP_UINT8("x-clear-bitmap-shift", MigrationState, 99 clear_bitmap_shift, CLEAR_BITMAP_SHIFT_DEFAULT), 100 DEFINE_PROP_BOOL("x-preempt-pre-7-2", MigrationState, 101 preempt_pre_7_2, false), 102 103 /* Migration parameters */ 104 DEFINE_PROP_UINT8("x-compress-level", MigrationState, 105 parameters.compress_level, 106 DEFAULT_MIGRATE_COMPRESS_LEVEL), 107 DEFINE_PROP_UINT8("x-compress-threads", MigrationState, 108 parameters.compress_threads, 109 DEFAULT_MIGRATE_COMPRESS_THREAD_COUNT), 110 DEFINE_PROP_BOOL("x-compress-wait-thread", MigrationState, 111 parameters.compress_wait_thread, true), 112 DEFINE_PROP_UINT8("x-decompress-threads", MigrationState, 113 parameters.decompress_threads, 114 DEFAULT_MIGRATE_DECOMPRESS_THREAD_COUNT), 115 DEFINE_PROP_UINT8("x-throttle-trigger-threshold", MigrationState, 116 parameters.throttle_trigger_threshold, 117 DEFAULT_MIGRATE_THROTTLE_TRIGGER_THRESHOLD), 118 DEFINE_PROP_UINT8("x-cpu-throttle-initial", MigrationState, 119 parameters.cpu_throttle_initial, 120 DEFAULT_MIGRATE_CPU_THROTTLE_INITIAL), 121 DEFINE_PROP_UINT8("x-cpu-throttle-increment", MigrationState, 122 parameters.cpu_throttle_increment, 123 DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT), 124 DEFINE_PROP_BOOL("x-cpu-throttle-tailslow", MigrationState, 125 parameters.cpu_throttle_tailslow, false), 126 DEFINE_PROP_SIZE("x-max-bandwidth", MigrationState, 127 parameters.max_bandwidth, MAX_THROTTLE), 128 DEFINE_PROP_SIZE("avail-switchover-bandwidth", MigrationState, 129 parameters.avail_switchover_bandwidth, 0), 130 DEFINE_PROP_UINT64("x-downtime-limit", MigrationState, 131 parameters.downtime_limit, 132 DEFAULT_MIGRATE_SET_DOWNTIME), 133 DEFINE_PROP_UINT32("x-checkpoint-delay", MigrationState, 134 parameters.x_checkpoint_delay, 135 DEFAULT_MIGRATE_X_CHECKPOINT_DELAY), 136 DEFINE_PROP_UINT8("multifd-channels", MigrationState, 137 parameters.multifd_channels, 138 DEFAULT_MIGRATE_MULTIFD_CHANNELS), 139 DEFINE_PROP_MULTIFD_COMPRESSION("multifd-compression", MigrationState, 140 parameters.multifd_compression, 141 DEFAULT_MIGRATE_MULTIFD_COMPRESSION), 142 DEFINE_PROP_UINT8("multifd-zlib-level", MigrationState, 143 parameters.multifd_zlib_level, 144 DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL), 145 DEFINE_PROP_UINT8("multifd-zstd-level", MigrationState, 146 parameters.multifd_zstd_level, 147 DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL), 148 DEFINE_PROP_SIZE("xbzrle-cache-size", MigrationState, 149 parameters.xbzrle_cache_size, 150 DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE), 151 DEFINE_PROP_SIZE("max-postcopy-bandwidth", MigrationState, 152 parameters.max_postcopy_bandwidth, 153 DEFAULT_MIGRATE_MAX_POSTCOPY_BANDWIDTH), 154 DEFINE_PROP_UINT8("max-cpu-throttle", MigrationState, 155 parameters.max_cpu_throttle, 156 DEFAULT_MIGRATE_MAX_CPU_THROTTLE), 157 DEFINE_PROP_SIZE("announce-initial", MigrationState, 158 parameters.announce_initial, 159 DEFAULT_MIGRATE_ANNOUNCE_INITIAL), 160 DEFINE_PROP_SIZE("announce-max", MigrationState, 161 parameters.announce_max, 162 DEFAULT_MIGRATE_ANNOUNCE_MAX), 163 DEFINE_PROP_SIZE("announce-rounds", MigrationState, 164 parameters.announce_rounds, 165 DEFAULT_MIGRATE_ANNOUNCE_ROUNDS), 166 DEFINE_PROP_SIZE("announce-step", MigrationState, 167 parameters.announce_step, 168 DEFAULT_MIGRATE_ANNOUNCE_STEP), 169 DEFINE_PROP_STRING("tls-creds", MigrationState, parameters.tls_creds), 170 DEFINE_PROP_STRING("tls-hostname", MigrationState, parameters.tls_hostname), 171 DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz), 172 DEFINE_PROP_UINT64("x-vcpu-dirty-limit-period", MigrationState, 173 parameters.x_vcpu_dirty_limit_period, 174 DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD), 175 DEFINE_PROP_UINT64("vcpu-dirty-limit", MigrationState, 176 parameters.vcpu_dirty_limit, 177 DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT), 178 179 /* Migration capabilities */ 180 DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE), 181 DEFINE_PROP_MIG_CAP("x-rdma-pin-all", MIGRATION_CAPABILITY_RDMA_PIN_ALL), 182 DEFINE_PROP_MIG_CAP("x-auto-converge", MIGRATION_CAPABILITY_AUTO_CONVERGE), 183 DEFINE_PROP_MIG_CAP("x-zero-blocks", MIGRATION_CAPABILITY_ZERO_BLOCKS), 184 DEFINE_PROP_MIG_CAP("x-compress", MIGRATION_CAPABILITY_COMPRESS), 185 DEFINE_PROP_MIG_CAP("x-events", MIGRATION_CAPABILITY_EVENTS), 186 DEFINE_PROP_MIG_CAP("x-postcopy-ram", MIGRATION_CAPABILITY_POSTCOPY_RAM), 187 DEFINE_PROP_MIG_CAP("x-postcopy-preempt", 188 MIGRATION_CAPABILITY_POSTCOPY_PREEMPT), 189 DEFINE_PROP_MIG_CAP("x-colo", MIGRATION_CAPABILITY_X_COLO), 190 DEFINE_PROP_MIG_CAP("x-release-ram", MIGRATION_CAPABILITY_RELEASE_RAM), 191 DEFINE_PROP_MIG_CAP("x-block", MIGRATION_CAPABILITY_BLOCK), 192 DEFINE_PROP_MIG_CAP("x-return-path", MIGRATION_CAPABILITY_RETURN_PATH), 193 DEFINE_PROP_MIG_CAP("x-multifd", MIGRATION_CAPABILITY_MULTIFD), 194 DEFINE_PROP_MIG_CAP("x-background-snapshot", 195 MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT), 196 #ifdef CONFIG_LINUX 197 DEFINE_PROP_MIG_CAP("x-zero-copy-send", 198 MIGRATION_CAPABILITY_ZERO_COPY_SEND), 199 #endif 200 DEFINE_PROP_MIG_CAP("x-switchover-ack", 201 MIGRATION_CAPABILITY_SWITCHOVER_ACK), 202 DEFINE_PROP_MIG_CAP("x-dirty-limit", MIGRATION_CAPABILITY_DIRTY_LIMIT), 203 DEFINE_PROP_END_OF_LIST(), 204 }; 205 206 bool migrate_auto_converge(void) 207 { 208 MigrationState *s = migrate_get_current(); 209 210 return s->capabilities[MIGRATION_CAPABILITY_AUTO_CONVERGE]; 211 } 212 213 bool migrate_background_snapshot(void) 214 { 215 MigrationState *s = migrate_get_current(); 216 217 return s->capabilities[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT]; 218 } 219 220 bool migrate_block(void) 221 { 222 MigrationState *s = migrate_get_current(); 223 224 return s->capabilities[MIGRATION_CAPABILITY_BLOCK]; 225 } 226 227 bool migrate_colo(void) 228 { 229 MigrationState *s = migrate_get_current(); 230 231 return s->capabilities[MIGRATION_CAPABILITY_X_COLO]; 232 } 233 234 bool migrate_compress(void) 235 { 236 MigrationState *s = migrate_get_current(); 237 238 return s->capabilities[MIGRATION_CAPABILITY_COMPRESS]; 239 } 240 241 bool migrate_dirty_bitmaps(void) 242 { 243 MigrationState *s = migrate_get_current(); 244 245 return s->capabilities[MIGRATION_CAPABILITY_DIRTY_BITMAPS]; 246 } 247 248 bool migrate_dirty_limit(void) 249 { 250 MigrationState *s = migrate_get_current(); 251 252 return s->capabilities[MIGRATION_CAPABILITY_DIRTY_LIMIT]; 253 } 254 255 bool migrate_events(void) 256 { 257 MigrationState *s = migrate_get_current(); 258 259 return s->capabilities[MIGRATION_CAPABILITY_EVENTS]; 260 } 261 262 bool migrate_ignore_shared(void) 263 { 264 MigrationState *s = migrate_get_current(); 265 266 return s->capabilities[MIGRATION_CAPABILITY_X_IGNORE_SHARED]; 267 } 268 269 bool migrate_late_block_activate(void) 270 { 271 MigrationState *s = migrate_get_current(); 272 273 return s->capabilities[MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE]; 274 } 275 276 bool migrate_multifd(void) 277 { 278 MigrationState *s = migrate_get_current(); 279 280 return s->capabilities[MIGRATION_CAPABILITY_MULTIFD]; 281 } 282 283 bool migrate_pause_before_switchover(void) 284 { 285 MigrationState *s = migrate_get_current(); 286 287 return s->capabilities[MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER]; 288 } 289 290 bool migrate_postcopy_blocktime(void) 291 { 292 MigrationState *s = migrate_get_current(); 293 294 return s->capabilities[MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME]; 295 } 296 297 bool migrate_postcopy_preempt(void) 298 { 299 MigrationState *s = migrate_get_current(); 300 301 return s->capabilities[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT]; 302 } 303 304 bool migrate_postcopy_ram(void) 305 { 306 MigrationState *s = migrate_get_current(); 307 308 return s->capabilities[MIGRATION_CAPABILITY_POSTCOPY_RAM]; 309 } 310 311 bool migrate_rdma_pin_all(void) 312 { 313 MigrationState *s = migrate_get_current(); 314 315 return s->capabilities[MIGRATION_CAPABILITY_RDMA_PIN_ALL]; 316 } 317 318 bool migrate_release_ram(void) 319 { 320 MigrationState *s = migrate_get_current(); 321 322 return s->capabilities[MIGRATION_CAPABILITY_RELEASE_RAM]; 323 } 324 325 bool migrate_return_path(void) 326 { 327 MigrationState *s = migrate_get_current(); 328 329 return s->capabilities[MIGRATION_CAPABILITY_RETURN_PATH]; 330 } 331 332 bool migrate_switchover_ack(void) 333 { 334 MigrationState *s = migrate_get_current(); 335 336 return s->capabilities[MIGRATION_CAPABILITY_SWITCHOVER_ACK]; 337 } 338 339 bool migrate_validate_uuid(void) 340 { 341 MigrationState *s = migrate_get_current(); 342 343 return s->capabilities[MIGRATION_CAPABILITY_VALIDATE_UUID]; 344 } 345 346 bool migrate_xbzrle(void) 347 { 348 MigrationState *s = migrate_get_current(); 349 350 return s->capabilities[MIGRATION_CAPABILITY_XBZRLE]; 351 } 352 353 bool migrate_zero_blocks(void) 354 { 355 MigrationState *s = migrate_get_current(); 356 357 return s->capabilities[MIGRATION_CAPABILITY_ZERO_BLOCKS]; 358 } 359 360 bool migrate_zero_copy_send(void) 361 { 362 MigrationState *s = migrate_get_current(); 363 364 return s->capabilities[MIGRATION_CAPABILITY_ZERO_COPY_SEND]; 365 } 366 367 /* pseudo capabilities */ 368 369 bool migrate_multifd_flush_after_each_section(void) 370 { 371 MigrationState *s = migrate_get_current(); 372 373 return s->multifd_flush_after_each_section; 374 } 375 376 bool migrate_postcopy(void) 377 { 378 return migrate_postcopy_ram() || migrate_dirty_bitmaps(); 379 } 380 381 bool migrate_rdma(void) 382 { 383 MigrationState *s = migrate_get_current(); 384 385 return s->rdma_migration; 386 } 387 388 bool migrate_tls(void) 389 { 390 MigrationState *s = migrate_get_current(); 391 392 return s->parameters.tls_creds && *s->parameters.tls_creds; 393 } 394 395 typedef enum WriteTrackingSupport { 396 WT_SUPPORT_UNKNOWN = 0, 397 WT_SUPPORT_ABSENT, 398 WT_SUPPORT_AVAILABLE, 399 WT_SUPPORT_COMPATIBLE 400 } WriteTrackingSupport; 401 402 static 403 WriteTrackingSupport migrate_query_write_tracking(void) 404 { 405 /* Check if kernel supports required UFFD features */ 406 if (!ram_write_tracking_available()) { 407 return WT_SUPPORT_ABSENT; 408 } 409 /* 410 * Check if current memory configuration is 411 * compatible with required UFFD features. 412 */ 413 if (!ram_write_tracking_compatible()) { 414 return WT_SUPPORT_AVAILABLE; 415 } 416 417 return WT_SUPPORT_COMPATIBLE; 418 } 419 420 /* Migration capabilities set */ 421 struct MigrateCapsSet { 422 int size; /* Capability set size */ 423 MigrationCapability caps[]; /* Variadic array of capabilities */ 424 }; 425 typedef struct MigrateCapsSet MigrateCapsSet; 426 427 /* Define and initialize MigrateCapsSet */ 428 #define INITIALIZE_MIGRATE_CAPS_SET(_name, ...) \ 429 MigrateCapsSet _name = { \ 430 .size = sizeof((int []) { __VA_ARGS__ }) / sizeof(int), \ 431 .caps = { __VA_ARGS__ } \ 432 } 433 434 /* Background-snapshot compatibility check list */ 435 static const 436 INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snapshot, 437 MIGRATION_CAPABILITY_POSTCOPY_RAM, 438 MIGRATION_CAPABILITY_DIRTY_BITMAPS, 439 MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME, 440 MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE, 441 MIGRATION_CAPABILITY_RETURN_PATH, 442 MIGRATION_CAPABILITY_MULTIFD, 443 MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER, 444 MIGRATION_CAPABILITY_AUTO_CONVERGE, 445 MIGRATION_CAPABILITY_RELEASE_RAM, 446 MIGRATION_CAPABILITY_RDMA_PIN_ALL, 447 MIGRATION_CAPABILITY_COMPRESS, 448 MIGRATION_CAPABILITY_XBZRLE, 449 MIGRATION_CAPABILITY_X_COLO, 450 MIGRATION_CAPABILITY_VALIDATE_UUID, 451 MIGRATION_CAPABILITY_ZERO_COPY_SEND); 452 453 static bool migrate_incoming_started(void) 454 { 455 return !!migration_incoming_get_current()->transport_data; 456 } 457 458 /** 459 * @migration_caps_check - check capability compatibility 460 * 461 * @old_caps: old capability list 462 * @new_caps: new capability list 463 * @errp: set *errp if the check failed, with reason 464 * 465 * Returns true if check passed, otherwise false. 466 */ 467 bool migrate_caps_check(bool *old_caps, bool *new_caps, Error **errp) 468 { 469 MigrationIncomingState *mis = migration_incoming_get_current(); 470 471 ERRP_GUARD(); 472 #ifndef CONFIG_LIVE_BLOCK_MIGRATION 473 if (new_caps[MIGRATION_CAPABILITY_BLOCK]) { 474 error_setg(errp, "QEMU compiled without old-style (blk/-b, inc/-i) " 475 "block migration"); 476 error_append_hint(errp, "Use drive_mirror+NBD instead.\n"); 477 return false; 478 } 479 #endif 480 481 #ifndef CONFIG_REPLICATION 482 if (new_caps[MIGRATION_CAPABILITY_X_COLO]) { 483 error_setg(errp, "QEMU compiled without replication module" 484 " can't enable COLO"); 485 error_append_hint(errp, "Please enable replication before COLO.\n"); 486 return false; 487 } 488 #endif 489 490 if (new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) { 491 /* This check is reasonably expensive, so only when it's being 492 * set the first time, also it's only the destination that needs 493 * special support. 494 */ 495 if (!old_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM] && 496 runstate_check(RUN_STATE_INMIGRATE) && 497 !postcopy_ram_supported_by_host(mis, errp)) { 498 error_prepend(errp, "Postcopy is not supported: "); 499 return false; 500 } 501 502 if (new_caps[MIGRATION_CAPABILITY_X_IGNORE_SHARED]) { 503 error_setg(errp, "Postcopy is not compatible with ignore-shared"); 504 return false; 505 } 506 507 if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) { 508 error_setg(errp, "Postcopy is not yet compatible with multifd"); 509 return false; 510 } 511 } 512 513 if (new_caps[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT]) { 514 WriteTrackingSupport wt_support; 515 int idx; 516 /* 517 * Check if 'background-snapshot' capability is supported by 518 * host kernel and compatible with guest memory configuration. 519 */ 520 wt_support = migrate_query_write_tracking(); 521 if (wt_support < WT_SUPPORT_AVAILABLE) { 522 error_setg(errp, "Background-snapshot is not supported by host kernel"); 523 return false; 524 } 525 if (wt_support < WT_SUPPORT_COMPATIBLE) { 526 error_setg(errp, "Background-snapshot is not compatible " 527 "with guest memory configuration"); 528 return false; 529 } 530 531 /* 532 * Check if there are any migration capabilities 533 * incompatible with 'background-snapshot'. 534 */ 535 for (idx = 0; idx < check_caps_background_snapshot.size; idx++) { 536 int incomp_cap = check_caps_background_snapshot.caps[idx]; 537 if (new_caps[incomp_cap]) { 538 error_setg(errp, 539 "Background-snapshot is not compatible with %s", 540 MigrationCapability_str(incomp_cap)); 541 return false; 542 } 543 } 544 } 545 546 #ifdef CONFIG_LINUX 547 if (new_caps[MIGRATION_CAPABILITY_ZERO_COPY_SEND] && 548 (!new_caps[MIGRATION_CAPABILITY_MULTIFD] || 549 new_caps[MIGRATION_CAPABILITY_COMPRESS] || 550 new_caps[MIGRATION_CAPABILITY_XBZRLE] || 551 migrate_multifd_compression() || 552 migrate_tls())) { 553 error_setg(errp, 554 "Zero copy only available for non-compressed non-TLS multifd migration"); 555 return false; 556 } 557 #else 558 if (new_caps[MIGRATION_CAPABILITY_ZERO_COPY_SEND]) { 559 error_setg(errp, 560 "Zero copy currently only available on Linux"); 561 return false; 562 } 563 #endif 564 565 if (new_caps[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT]) { 566 if (!new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) { 567 error_setg(errp, "Postcopy preempt requires postcopy-ram"); 568 return false; 569 } 570 571 /* 572 * Preempt mode requires urgent pages to be sent in separate 573 * channel, OTOH compression logic will disorder all pages into 574 * different compression channels, which is not compatible with the 575 * preempt assumptions on channel assignments. 576 */ 577 if (new_caps[MIGRATION_CAPABILITY_COMPRESS]) { 578 error_setg(errp, "Postcopy preempt not compatible with compress"); 579 return false; 580 } 581 582 if (migrate_incoming_started()) { 583 error_setg(errp, 584 "Postcopy preempt must be set before incoming starts"); 585 return false; 586 } 587 } 588 589 if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) { 590 if (new_caps[MIGRATION_CAPABILITY_COMPRESS]) { 591 error_setg(errp, "Multifd is not compatible with compress"); 592 return false; 593 } 594 if (migrate_incoming_started()) { 595 error_setg(errp, "Multifd must be set before incoming starts"); 596 return false; 597 } 598 } 599 600 if (new_caps[MIGRATION_CAPABILITY_SWITCHOVER_ACK]) { 601 if (!new_caps[MIGRATION_CAPABILITY_RETURN_PATH]) { 602 error_setg(errp, "Capability 'switchover-ack' requires capability " 603 "'return-path'"); 604 return false; 605 } 606 } 607 if (new_caps[MIGRATION_CAPABILITY_DIRTY_LIMIT]) { 608 if (new_caps[MIGRATION_CAPABILITY_AUTO_CONVERGE]) { 609 error_setg(errp, "dirty-limit conflicts with auto-converge" 610 " either of then available currently"); 611 return false; 612 } 613 614 if (!kvm_enabled() || !kvm_dirty_ring_enabled()) { 615 error_setg(errp, "dirty-limit requires KVM with accelerator" 616 " property 'dirty-ring-size' set"); 617 return false; 618 } 619 } 620 621 if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) { 622 if (new_caps[MIGRATION_CAPABILITY_XBZRLE]) { 623 error_setg(errp, "Multifd is not compatible with xbzrle"); 624 return false; 625 } 626 } 627 628 if (new_caps[MIGRATION_CAPABILITY_COMPRESS]) { 629 if (new_caps[MIGRATION_CAPABILITY_XBZRLE]) { 630 error_setg(errp, "Compression is not compatible with xbzrle"); 631 return false; 632 } 633 } 634 635 return true; 636 } 637 638 bool migrate_cap_set(int cap, bool value, Error **errp) 639 { 640 MigrationState *s = migrate_get_current(); 641 bool new_caps[MIGRATION_CAPABILITY__MAX]; 642 643 if (migration_is_running(s->state)) { 644 error_setg(errp, QERR_MIGRATION_ACTIVE); 645 return false; 646 } 647 648 memcpy(new_caps, s->capabilities, sizeof(new_caps)); 649 new_caps[cap] = value; 650 651 if (!migrate_caps_check(s->capabilities, new_caps, errp)) { 652 return false; 653 } 654 s->capabilities[cap] = value; 655 return true; 656 } 657 658 MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp) 659 { 660 MigrationCapabilityStatusList *head = NULL, **tail = &head; 661 MigrationCapabilityStatus *caps; 662 MigrationState *s = migrate_get_current(); 663 int i; 664 665 for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) { 666 #ifndef CONFIG_LIVE_BLOCK_MIGRATION 667 if (i == MIGRATION_CAPABILITY_BLOCK) { 668 continue; 669 } 670 #endif 671 caps = g_malloc0(sizeof(*caps)); 672 caps->capability = i; 673 caps->state = s->capabilities[i]; 674 QAPI_LIST_APPEND(tail, caps); 675 } 676 677 return head; 678 } 679 680 void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params, 681 Error **errp) 682 { 683 MigrationState *s = migrate_get_current(); 684 MigrationCapabilityStatusList *cap; 685 bool new_caps[MIGRATION_CAPABILITY__MAX]; 686 687 if (migration_is_running(s->state) || migration_in_colo_state()) { 688 error_setg(errp, QERR_MIGRATION_ACTIVE); 689 return; 690 } 691 692 memcpy(new_caps, s->capabilities, sizeof(new_caps)); 693 for (cap = params; cap; cap = cap->next) { 694 new_caps[cap->value->capability] = cap->value->state; 695 } 696 697 if (!migrate_caps_check(s->capabilities, new_caps, errp)) { 698 return; 699 } 700 701 for (cap = params; cap; cap = cap->next) { 702 s->capabilities[cap->value->capability] = cap->value->state; 703 } 704 } 705 706 /* parameters */ 707 708 const BitmapMigrationNodeAliasList *migrate_block_bitmap_mapping(void) 709 { 710 MigrationState *s = migrate_get_current(); 711 712 return s->parameters.block_bitmap_mapping; 713 } 714 715 bool migrate_has_block_bitmap_mapping(void) 716 { 717 MigrationState *s = migrate_get_current(); 718 719 return s->parameters.has_block_bitmap_mapping; 720 } 721 722 bool migrate_block_incremental(void) 723 { 724 MigrationState *s = migrate_get_current(); 725 726 return s->parameters.block_incremental; 727 } 728 729 uint32_t migrate_checkpoint_delay(void) 730 { 731 MigrationState *s = migrate_get_current(); 732 733 return s->parameters.x_checkpoint_delay; 734 } 735 736 int migrate_compress_level(void) 737 { 738 MigrationState *s = migrate_get_current(); 739 740 return s->parameters.compress_level; 741 } 742 743 int migrate_compress_threads(void) 744 { 745 MigrationState *s = migrate_get_current(); 746 747 return s->parameters.compress_threads; 748 } 749 750 int migrate_compress_wait_thread(void) 751 { 752 MigrationState *s = migrate_get_current(); 753 754 return s->parameters.compress_wait_thread; 755 } 756 757 uint8_t migrate_cpu_throttle_increment(void) 758 { 759 MigrationState *s = migrate_get_current(); 760 761 return s->parameters.cpu_throttle_increment; 762 } 763 764 uint8_t migrate_cpu_throttle_initial(void) 765 { 766 MigrationState *s = migrate_get_current(); 767 768 return s->parameters.cpu_throttle_initial; 769 } 770 771 bool migrate_cpu_throttle_tailslow(void) 772 { 773 MigrationState *s = migrate_get_current(); 774 775 return s->parameters.cpu_throttle_tailslow; 776 } 777 778 int migrate_decompress_threads(void) 779 { 780 MigrationState *s = migrate_get_current(); 781 782 return s->parameters.decompress_threads; 783 } 784 785 uint64_t migrate_downtime_limit(void) 786 { 787 MigrationState *s = migrate_get_current(); 788 789 return s->parameters.downtime_limit; 790 } 791 792 uint8_t migrate_max_cpu_throttle(void) 793 { 794 MigrationState *s = migrate_get_current(); 795 796 return s->parameters.max_cpu_throttle; 797 } 798 799 uint64_t migrate_max_bandwidth(void) 800 { 801 MigrationState *s = migrate_get_current(); 802 803 return s->parameters.max_bandwidth; 804 } 805 806 uint64_t migrate_avail_switchover_bandwidth(void) 807 { 808 MigrationState *s = migrate_get_current(); 809 810 return s->parameters.avail_switchover_bandwidth; 811 } 812 813 uint64_t migrate_max_postcopy_bandwidth(void) 814 { 815 MigrationState *s = migrate_get_current(); 816 817 return s->parameters.max_postcopy_bandwidth; 818 } 819 820 int migrate_multifd_channels(void) 821 { 822 MigrationState *s = migrate_get_current(); 823 824 return s->parameters.multifd_channels; 825 } 826 827 MultiFDCompression migrate_multifd_compression(void) 828 { 829 MigrationState *s = migrate_get_current(); 830 831 assert(s->parameters.multifd_compression < MULTIFD_COMPRESSION__MAX); 832 return s->parameters.multifd_compression; 833 } 834 835 int migrate_multifd_zlib_level(void) 836 { 837 MigrationState *s = migrate_get_current(); 838 839 return s->parameters.multifd_zlib_level; 840 } 841 842 int migrate_multifd_zstd_level(void) 843 { 844 MigrationState *s = migrate_get_current(); 845 846 return s->parameters.multifd_zstd_level; 847 } 848 849 uint8_t migrate_throttle_trigger_threshold(void) 850 { 851 MigrationState *s = migrate_get_current(); 852 853 return s->parameters.throttle_trigger_threshold; 854 } 855 856 const char *migrate_tls_authz(void) 857 { 858 MigrationState *s = migrate_get_current(); 859 860 return s->parameters.tls_authz; 861 } 862 863 const char *migrate_tls_creds(void) 864 { 865 MigrationState *s = migrate_get_current(); 866 867 return s->parameters.tls_creds; 868 } 869 870 const char *migrate_tls_hostname(void) 871 { 872 MigrationState *s = migrate_get_current(); 873 874 return s->parameters.tls_hostname; 875 } 876 877 uint64_t migrate_xbzrle_cache_size(void) 878 { 879 MigrationState *s = migrate_get_current(); 880 881 return s->parameters.xbzrle_cache_size; 882 } 883 884 /* parameter setters */ 885 886 void migrate_set_block_incremental(bool value) 887 { 888 MigrationState *s = migrate_get_current(); 889 890 s->parameters.block_incremental = value; 891 } 892 893 /* parameters helpers */ 894 895 void block_cleanup_parameters(void) 896 { 897 MigrationState *s = migrate_get_current(); 898 899 if (s->must_remove_block_options) { 900 /* setting to false can never fail */ 901 migrate_cap_set(MIGRATION_CAPABILITY_BLOCK, false, &error_abort); 902 migrate_set_block_incremental(false); 903 s->must_remove_block_options = false; 904 } 905 } 906 907 AnnounceParameters *migrate_announce_params(void) 908 { 909 static AnnounceParameters ap; 910 911 MigrationState *s = migrate_get_current(); 912 913 ap.initial = s->parameters.announce_initial; 914 ap.max = s->parameters.announce_max; 915 ap.rounds = s->parameters.announce_rounds; 916 ap.step = s->parameters.announce_step; 917 918 return ≈ 919 } 920 921 MigrationParameters *qmp_query_migrate_parameters(Error **errp) 922 { 923 MigrationParameters *params; 924 MigrationState *s = migrate_get_current(); 925 926 /* TODO use QAPI_CLONE() instead of duplicating it inline */ 927 params = g_malloc0(sizeof(*params)); 928 params->has_compress_level = true; 929 params->compress_level = s->parameters.compress_level; 930 params->has_compress_threads = true; 931 params->compress_threads = s->parameters.compress_threads; 932 params->has_compress_wait_thread = true; 933 params->compress_wait_thread = s->parameters.compress_wait_thread; 934 params->has_decompress_threads = true; 935 params->decompress_threads = s->parameters.decompress_threads; 936 params->has_throttle_trigger_threshold = true; 937 params->throttle_trigger_threshold = s->parameters.throttle_trigger_threshold; 938 params->has_cpu_throttle_initial = true; 939 params->cpu_throttle_initial = s->parameters.cpu_throttle_initial; 940 params->has_cpu_throttle_increment = true; 941 params->cpu_throttle_increment = s->parameters.cpu_throttle_increment; 942 params->has_cpu_throttle_tailslow = true; 943 params->cpu_throttle_tailslow = s->parameters.cpu_throttle_tailslow; 944 params->tls_creds = g_strdup(s->parameters.tls_creds); 945 params->tls_hostname = g_strdup(s->parameters.tls_hostname); 946 params->tls_authz = g_strdup(s->parameters.tls_authz ? 947 s->parameters.tls_authz : ""); 948 params->has_max_bandwidth = true; 949 params->max_bandwidth = s->parameters.max_bandwidth; 950 params->has_avail_switchover_bandwidth = true; 951 params->avail_switchover_bandwidth = s->parameters.avail_switchover_bandwidth; 952 params->has_downtime_limit = true; 953 params->downtime_limit = s->parameters.downtime_limit; 954 params->has_x_checkpoint_delay = true; 955 params->x_checkpoint_delay = s->parameters.x_checkpoint_delay; 956 params->has_block_incremental = true; 957 params->block_incremental = s->parameters.block_incremental; 958 params->has_multifd_channels = true; 959 params->multifd_channels = s->parameters.multifd_channels; 960 params->has_multifd_compression = true; 961 params->multifd_compression = s->parameters.multifd_compression; 962 params->has_multifd_zlib_level = true; 963 params->multifd_zlib_level = s->parameters.multifd_zlib_level; 964 params->has_multifd_zstd_level = true; 965 params->multifd_zstd_level = s->parameters.multifd_zstd_level; 966 params->has_xbzrle_cache_size = true; 967 params->xbzrle_cache_size = s->parameters.xbzrle_cache_size; 968 params->has_max_postcopy_bandwidth = true; 969 params->max_postcopy_bandwidth = s->parameters.max_postcopy_bandwidth; 970 params->has_max_cpu_throttle = true; 971 params->max_cpu_throttle = s->parameters.max_cpu_throttle; 972 params->has_announce_initial = true; 973 params->announce_initial = s->parameters.announce_initial; 974 params->has_announce_max = true; 975 params->announce_max = s->parameters.announce_max; 976 params->has_announce_rounds = true; 977 params->announce_rounds = s->parameters.announce_rounds; 978 params->has_announce_step = true; 979 params->announce_step = s->parameters.announce_step; 980 981 if (s->parameters.has_block_bitmap_mapping) { 982 params->has_block_bitmap_mapping = true; 983 params->block_bitmap_mapping = 984 QAPI_CLONE(BitmapMigrationNodeAliasList, 985 s->parameters.block_bitmap_mapping); 986 } 987 988 params->has_x_vcpu_dirty_limit_period = true; 989 params->x_vcpu_dirty_limit_period = s->parameters.x_vcpu_dirty_limit_period; 990 params->has_vcpu_dirty_limit = true; 991 params->vcpu_dirty_limit = s->parameters.vcpu_dirty_limit; 992 993 return params; 994 } 995 996 void migrate_params_init(MigrationParameters *params) 997 { 998 params->tls_hostname = g_strdup(""); 999 params->tls_creds = g_strdup(""); 1000 1001 /* Set has_* up only for parameter checks */ 1002 params->has_compress_level = true; 1003 params->has_compress_threads = true; 1004 params->has_compress_wait_thread = true; 1005 params->has_decompress_threads = true; 1006 params->has_throttle_trigger_threshold = true; 1007 params->has_cpu_throttle_initial = true; 1008 params->has_cpu_throttle_increment = true; 1009 params->has_cpu_throttle_tailslow = true; 1010 params->has_max_bandwidth = true; 1011 params->has_downtime_limit = true; 1012 params->has_x_checkpoint_delay = true; 1013 params->has_block_incremental = true; 1014 params->has_multifd_channels = true; 1015 params->has_multifd_compression = true; 1016 params->has_multifd_zlib_level = true; 1017 params->has_multifd_zstd_level = true; 1018 params->has_xbzrle_cache_size = true; 1019 params->has_max_postcopy_bandwidth = true; 1020 params->has_max_cpu_throttle = true; 1021 params->has_announce_initial = true; 1022 params->has_announce_max = true; 1023 params->has_announce_rounds = true; 1024 params->has_announce_step = true; 1025 params->has_x_vcpu_dirty_limit_period = true; 1026 params->has_vcpu_dirty_limit = true; 1027 } 1028 1029 /* 1030 * Check whether the parameters are valid. Error will be put into errp 1031 * (if provided). Return true if valid, otherwise false. 1032 */ 1033 bool migrate_params_check(MigrationParameters *params, Error **errp) 1034 { 1035 if (params->has_compress_level && 1036 (params->compress_level > 9)) { 1037 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level", 1038 "a value between 0 and 9"); 1039 return false; 1040 } 1041 1042 if (params->has_compress_threads && (params->compress_threads < 1)) { 1043 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 1044 "compress_threads", 1045 "a value between 1 and 255"); 1046 return false; 1047 } 1048 1049 if (params->has_decompress_threads && (params->decompress_threads < 1)) { 1050 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 1051 "decompress_threads", 1052 "a value between 1 and 255"); 1053 return false; 1054 } 1055 1056 if (params->has_throttle_trigger_threshold && 1057 (params->throttle_trigger_threshold < 1 || 1058 params->throttle_trigger_threshold > 100)) { 1059 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 1060 "throttle_trigger_threshold", 1061 "an integer in the range of 1 to 100"); 1062 return false; 1063 } 1064 1065 if (params->has_cpu_throttle_initial && 1066 (params->cpu_throttle_initial < 1 || 1067 params->cpu_throttle_initial > 99)) { 1068 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 1069 "cpu_throttle_initial", 1070 "an integer in the range of 1 to 99"); 1071 return false; 1072 } 1073 1074 if (params->has_cpu_throttle_increment && 1075 (params->cpu_throttle_increment < 1 || 1076 params->cpu_throttle_increment > 99)) { 1077 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 1078 "cpu_throttle_increment", 1079 "an integer in the range of 1 to 99"); 1080 return false; 1081 } 1082 1083 if (params->has_max_bandwidth && (params->max_bandwidth > SIZE_MAX)) { 1084 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 1085 "max_bandwidth", 1086 "an integer in the range of 0 to "stringify(SIZE_MAX) 1087 " bytes/second"); 1088 return false; 1089 } 1090 1091 if (params->has_avail_switchover_bandwidth && 1092 (params->avail_switchover_bandwidth > SIZE_MAX)) { 1093 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 1094 "avail_switchover_bandwidth", 1095 "an integer in the range of 0 to "stringify(SIZE_MAX) 1096 " bytes/second"); 1097 return false; 1098 } 1099 1100 if (params->has_downtime_limit && 1101 (params->downtime_limit > MAX_MIGRATE_DOWNTIME)) { 1102 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 1103 "downtime_limit", 1104 "an integer in the range of 0 to " 1105 stringify(MAX_MIGRATE_DOWNTIME)" ms"); 1106 return false; 1107 } 1108 1109 /* x_checkpoint_delay is now always positive */ 1110 1111 if (params->has_multifd_channels && (params->multifd_channels < 1)) { 1112 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 1113 "multifd_channels", 1114 "a value between 1 and 255"); 1115 return false; 1116 } 1117 1118 if (params->has_multifd_zlib_level && 1119 (params->multifd_zlib_level > 9)) { 1120 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "multifd_zlib_level", 1121 "a value between 0 and 9"); 1122 return false; 1123 } 1124 1125 if (params->has_multifd_zstd_level && 1126 (params->multifd_zstd_level > 20)) { 1127 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "multifd_zstd_level", 1128 "a value between 0 and 20"); 1129 return false; 1130 } 1131 1132 if (params->has_xbzrle_cache_size && 1133 (params->xbzrle_cache_size < qemu_target_page_size() || 1134 !is_power_of_2(params->xbzrle_cache_size))) { 1135 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 1136 "xbzrle_cache_size", 1137 "a power of two no less than the target page size"); 1138 return false; 1139 } 1140 1141 if (params->has_max_cpu_throttle && 1142 (params->max_cpu_throttle < params->cpu_throttle_initial || 1143 params->max_cpu_throttle > 99)) { 1144 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 1145 "max_cpu_throttle", 1146 "an integer in the range of cpu_throttle_initial to 99"); 1147 return false; 1148 } 1149 1150 if (params->has_announce_initial && 1151 params->announce_initial > 100000) { 1152 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 1153 "announce_initial", 1154 "a value between 0 and 100000"); 1155 return false; 1156 } 1157 if (params->has_announce_max && 1158 params->announce_max > 100000) { 1159 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 1160 "announce_max", 1161 "a value between 0 and 100000"); 1162 return false; 1163 } 1164 if (params->has_announce_rounds && 1165 params->announce_rounds > 1000) { 1166 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 1167 "announce_rounds", 1168 "a value between 0 and 1000"); 1169 return false; 1170 } 1171 if (params->has_announce_step && 1172 (params->announce_step < 1 || 1173 params->announce_step > 10000)) { 1174 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 1175 "announce_step", 1176 "a value between 0 and 10000"); 1177 return false; 1178 } 1179 1180 if (params->has_block_bitmap_mapping && 1181 !check_dirty_bitmap_mig_alias_map(params->block_bitmap_mapping, errp)) { 1182 error_prepend(errp, "Invalid mapping given for block-bitmap-mapping: "); 1183 return false; 1184 } 1185 1186 #ifdef CONFIG_LINUX 1187 if (migrate_zero_copy_send() && 1188 ((params->has_multifd_compression && params->multifd_compression) || 1189 (params->tls_creds && *params->tls_creds))) { 1190 error_setg(errp, 1191 "Zero copy only available for non-compressed non-TLS multifd migration"); 1192 return false; 1193 } 1194 #endif 1195 1196 if (params->has_x_vcpu_dirty_limit_period && 1197 (params->x_vcpu_dirty_limit_period < 1 || 1198 params->x_vcpu_dirty_limit_period > 1000)) { 1199 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 1200 "x-vcpu-dirty-limit-period", 1201 "a value between 1 and 1000"); 1202 return false; 1203 } 1204 1205 if (params->has_vcpu_dirty_limit && 1206 (params->vcpu_dirty_limit < 1)) { 1207 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 1208 "vcpu_dirty_limit", 1209 "is invalid, it must greater then 1 MB/s"); 1210 return false; 1211 } 1212 1213 return true; 1214 } 1215 1216 static void migrate_params_test_apply(MigrateSetParameters *params, 1217 MigrationParameters *dest) 1218 { 1219 *dest = migrate_get_current()->parameters; 1220 1221 /* TODO use QAPI_CLONE() instead of duplicating it inline */ 1222 1223 if (params->has_compress_level) { 1224 dest->compress_level = params->compress_level; 1225 } 1226 1227 if (params->has_compress_threads) { 1228 dest->compress_threads = params->compress_threads; 1229 } 1230 1231 if (params->has_compress_wait_thread) { 1232 dest->compress_wait_thread = params->compress_wait_thread; 1233 } 1234 1235 if (params->has_decompress_threads) { 1236 dest->decompress_threads = params->decompress_threads; 1237 } 1238 1239 if (params->has_throttle_trigger_threshold) { 1240 dest->throttle_trigger_threshold = params->throttle_trigger_threshold; 1241 } 1242 1243 if (params->has_cpu_throttle_initial) { 1244 dest->cpu_throttle_initial = params->cpu_throttle_initial; 1245 } 1246 1247 if (params->has_cpu_throttle_increment) { 1248 dest->cpu_throttle_increment = params->cpu_throttle_increment; 1249 } 1250 1251 if (params->has_cpu_throttle_tailslow) { 1252 dest->cpu_throttle_tailslow = params->cpu_throttle_tailslow; 1253 } 1254 1255 if (params->tls_creds) { 1256 assert(params->tls_creds->type == QTYPE_QSTRING); 1257 dest->tls_creds = params->tls_creds->u.s; 1258 } 1259 1260 if (params->tls_hostname) { 1261 assert(params->tls_hostname->type == QTYPE_QSTRING); 1262 dest->tls_hostname = params->tls_hostname->u.s; 1263 } 1264 1265 if (params->has_max_bandwidth) { 1266 dest->max_bandwidth = params->max_bandwidth; 1267 } 1268 1269 if (params->has_avail_switchover_bandwidth) { 1270 dest->avail_switchover_bandwidth = params->avail_switchover_bandwidth; 1271 } 1272 1273 if (params->has_downtime_limit) { 1274 dest->downtime_limit = params->downtime_limit; 1275 } 1276 1277 if (params->has_x_checkpoint_delay) { 1278 dest->x_checkpoint_delay = params->x_checkpoint_delay; 1279 } 1280 1281 if (params->has_block_incremental) { 1282 dest->block_incremental = params->block_incremental; 1283 } 1284 if (params->has_multifd_channels) { 1285 dest->multifd_channels = params->multifd_channels; 1286 } 1287 if (params->has_multifd_compression) { 1288 dest->multifd_compression = params->multifd_compression; 1289 } 1290 if (params->has_xbzrle_cache_size) { 1291 dest->xbzrle_cache_size = params->xbzrle_cache_size; 1292 } 1293 if (params->has_max_postcopy_bandwidth) { 1294 dest->max_postcopy_bandwidth = params->max_postcopy_bandwidth; 1295 } 1296 if (params->has_max_cpu_throttle) { 1297 dest->max_cpu_throttle = params->max_cpu_throttle; 1298 } 1299 if (params->has_announce_initial) { 1300 dest->announce_initial = params->announce_initial; 1301 } 1302 if (params->has_announce_max) { 1303 dest->announce_max = params->announce_max; 1304 } 1305 if (params->has_announce_rounds) { 1306 dest->announce_rounds = params->announce_rounds; 1307 } 1308 if (params->has_announce_step) { 1309 dest->announce_step = params->announce_step; 1310 } 1311 1312 if (params->has_block_bitmap_mapping) { 1313 dest->has_block_bitmap_mapping = true; 1314 dest->block_bitmap_mapping = params->block_bitmap_mapping; 1315 } 1316 1317 if (params->has_x_vcpu_dirty_limit_period) { 1318 dest->x_vcpu_dirty_limit_period = 1319 params->x_vcpu_dirty_limit_period; 1320 } 1321 if (params->has_vcpu_dirty_limit) { 1322 dest->vcpu_dirty_limit = params->vcpu_dirty_limit; 1323 } 1324 } 1325 1326 static void migrate_params_apply(MigrateSetParameters *params, Error **errp) 1327 { 1328 MigrationState *s = migrate_get_current(); 1329 1330 /* TODO use QAPI_CLONE() instead of duplicating it inline */ 1331 1332 if (params->has_compress_level) { 1333 s->parameters.compress_level = params->compress_level; 1334 } 1335 1336 if (params->has_compress_threads) { 1337 s->parameters.compress_threads = params->compress_threads; 1338 } 1339 1340 if (params->has_compress_wait_thread) { 1341 s->parameters.compress_wait_thread = params->compress_wait_thread; 1342 } 1343 1344 if (params->has_decompress_threads) { 1345 s->parameters.decompress_threads = params->decompress_threads; 1346 } 1347 1348 if (params->has_throttle_trigger_threshold) { 1349 s->parameters.throttle_trigger_threshold = params->throttle_trigger_threshold; 1350 } 1351 1352 if (params->has_cpu_throttle_initial) { 1353 s->parameters.cpu_throttle_initial = params->cpu_throttle_initial; 1354 } 1355 1356 if (params->has_cpu_throttle_increment) { 1357 s->parameters.cpu_throttle_increment = params->cpu_throttle_increment; 1358 } 1359 1360 if (params->has_cpu_throttle_tailslow) { 1361 s->parameters.cpu_throttle_tailslow = params->cpu_throttle_tailslow; 1362 } 1363 1364 if (params->tls_creds) { 1365 g_free(s->parameters.tls_creds); 1366 assert(params->tls_creds->type == QTYPE_QSTRING); 1367 s->parameters.tls_creds = g_strdup(params->tls_creds->u.s); 1368 } 1369 1370 if (params->tls_hostname) { 1371 g_free(s->parameters.tls_hostname); 1372 assert(params->tls_hostname->type == QTYPE_QSTRING); 1373 s->parameters.tls_hostname = g_strdup(params->tls_hostname->u.s); 1374 } 1375 1376 if (params->tls_authz) { 1377 g_free(s->parameters.tls_authz); 1378 assert(params->tls_authz->type == QTYPE_QSTRING); 1379 s->parameters.tls_authz = g_strdup(params->tls_authz->u.s); 1380 } 1381 1382 if (params->has_max_bandwidth) { 1383 s->parameters.max_bandwidth = params->max_bandwidth; 1384 if (s->to_dst_file && !migration_in_postcopy()) { 1385 migration_rate_set(s->parameters.max_bandwidth); 1386 } 1387 } 1388 1389 if (params->has_avail_switchover_bandwidth) { 1390 s->parameters.avail_switchover_bandwidth = params->avail_switchover_bandwidth; 1391 } 1392 1393 if (params->has_downtime_limit) { 1394 s->parameters.downtime_limit = params->downtime_limit; 1395 } 1396 1397 if (params->has_x_checkpoint_delay) { 1398 s->parameters.x_checkpoint_delay = params->x_checkpoint_delay; 1399 colo_checkpoint_delay_set(); 1400 } 1401 1402 if (params->has_block_incremental) { 1403 s->parameters.block_incremental = params->block_incremental; 1404 } 1405 if (params->has_multifd_channels) { 1406 s->parameters.multifd_channels = params->multifd_channels; 1407 } 1408 if (params->has_multifd_compression) { 1409 s->parameters.multifd_compression = params->multifd_compression; 1410 } 1411 if (params->has_xbzrle_cache_size) { 1412 s->parameters.xbzrle_cache_size = params->xbzrle_cache_size; 1413 xbzrle_cache_resize(params->xbzrle_cache_size, errp); 1414 } 1415 if (params->has_max_postcopy_bandwidth) { 1416 s->parameters.max_postcopy_bandwidth = params->max_postcopy_bandwidth; 1417 if (s->to_dst_file && migration_in_postcopy()) { 1418 migration_rate_set(s->parameters.max_postcopy_bandwidth); 1419 } 1420 } 1421 if (params->has_max_cpu_throttle) { 1422 s->parameters.max_cpu_throttle = params->max_cpu_throttle; 1423 } 1424 if (params->has_announce_initial) { 1425 s->parameters.announce_initial = params->announce_initial; 1426 } 1427 if (params->has_announce_max) { 1428 s->parameters.announce_max = params->announce_max; 1429 } 1430 if (params->has_announce_rounds) { 1431 s->parameters.announce_rounds = params->announce_rounds; 1432 } 1433 if (params->has_announce_step) { 1434 s->parameters.announce_step = params->announce_step; 1435 } 1436 1437 if (params->has_block_bitmap_mapping) { 1438 qapi_free_BitmapMigrationNodeAliasList( 1439 s->parameters.block_bitmap_mapping); 1440 1441 s->parameters.has_block_bitmap_mapping = true; 1442 s->parameters.block_bitmap_mapping = 1443 QAPI_CLONE(BitmapMigrationNodeAliasList, 1444 params->block_bitmap_mapping); 1445 } 1446 1447 if (params->has_x_vcpu_dirty_limit_period) { 1448 s->parameters.x_vcpu_dirty_limit_period = 1449 params->x_vcpu_dirty_limit_period; 1450 } 1451 if (params->has_vcpu_dirty_limit) { 1452 s->parameters.vcpu_dirty_limit = params->vcpu_dirty_limit; 1453 } 1454 } 1455 1456 void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp) 1457 { 1458 MigrationParameters tmp; 1459 1460 /* TODO Rewrite "" to null instead for all three tls_* parameters */ 1461 if (params->tls_creds 1462 && params->tls_creds->type == QTYPE_QNULL) { 1463 qobject_unref(params->tls_creds->u.n); 1464 params->tls_creds->type = QTYPE_QSTRING; 1465 params->tls_creds->u.s = strdup(""); 1466 } 1467 if (params->tls_hostname 1468 && params->tls_hostname->type == QTYPE_QNULL) { 1469 qobject_unref(params->tls_hostname->u.n); 1470 params->tls_hostname->type = QTYPE_QSTRING; 1471 params->tls_hostname->u.s = strdup(""); 1472 } 1473 if (params->tls_authz 1474 && params->tls_authz->type == QTYPE_QNULL) { 1475 qobject_unref(params->tls_authz->u.n); 1476 params->tls_authz->type = QTYPE_QSTRING; 1477 params->tls_authz->u.s = strdup(""); 1478 } 1479 1480 migrate_params_test_apply(params, &tmp); 1481 1482 if (!migrate_params_check(&tmp, errp)) { 1483 /* Invalid parameter */ 1484 return; 1485 } 1486 1487 migrate_params_apply(params, errp); 1488 } 1489