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