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