11f0776f1SJuan Quintela /* 21f0776f1SJuan Quintela * QEMU migration capabilities 31f0776f1SJuan Quintela * 41f0776f1SJuan Quintela * Copyright (c) 2012-2023 Red Hat Inc 51f0776f1SJuan Quintela * 61f0776f1SJuan Quintela * Authors: 71f0776f1SJuan Quintela * Orit Wasserman <owasserm@redhat.com> 81f0776f1SJuan Quintela * Juan Quintela <quintela@redhat.com> 91f0776f1SJuan Quintela * 101f0776f1SJuan Quintela * This work is licensed under the terms of the GNU GPL, version 2 or later. 111f0776f1SJuan Quintela * See the COPYING file in the top-level directory. 121f0776f1SJuan Quintela */ 131f0776f1SJuan Quintela 141f0776f1SJuan Quintela #include "qemu/osdep.h" 1566db46caSJuan Quintela #include "qemu/error-report.h" 1609d6c965SJuan Quintela #include "exec/target_page.h" 179c894df3SJuan Quintela #include "qapi/clone-visitor.h" 1877608706SJuan Quintela #include "qapi/error.h" 194d0c6b69SJuan Quintela #include "qapi/qapi-commands-migration.h" 209c894df3SJuan Quintela #include "qapi/qapi-visit-migration.h" 21f80196b7SJuan Quintela #include "qapi/qmp/qerror.h" 2209d6c965SJuan Quintela #include "qapi/qmp/qnull.h" 2377608706SJuan Quintela #include "sysemu/runstate.h" 2409d6c965SJuan Quintela #include "migration/colo.h" 252682c4eeSJuan Quintela #include "migration/misc.h" 261f0776f1SJuan Quintela #include "migration.h" 27e1fde0e0SJuan Quintela #include "migration-stats.h" 2809d6c965SJuan Quintela #include "qemu-file.h" 2977608706SJuan Quintela #include "ram.h" 301f0776f1SJuan Quintela #include "options.h" 31dc623955SHyman Huang(黄勇) #include "sysemu/kvm.h" 321f0776f1SJuan Quintela 3309d6c965SJuan Quintela /* Maximum migrate downtime set to 2000 seconds */ 3409d6c965SJuan Quintela #define MAX_MIGRATE_DOWNTIME_SECONDS 2000 3509d6c965SJuan Quintela #define MAX_MIGRATE_DOWNTIME (MAX_MIGRATE_DOWNTIME_SECONDS * 1000) 3609d6c965SJuan Quintela 37f9436522SJuan Quintela #define MAX_THROTTLE (128 << 20) /* Migration transfer speed throttling */ 38f9436522SJuan Quintela 39f9436522SJuan Quintela /* Time in milliseconds we are allowed to stop the source, 40f9436522SJuan Quintela * for sending the last part */ 41f9436522SJuan Quintela #define DEFAULT_MIGRATE_SET_DOWNTIME 300 42f9436522SJuan Quintela 43f9436522SJuan Quintela /* Default compression thread count */ 44f9436522SJuan Quintela #define DEFAULT_MIGRATE_COMPRESS_THREAD_COUNT 8 45f9436522SJuan Quintela /* Default decompression thread count, usually decompression is at 46f9436522SJuan Quintela * least 4 times as fast as compression.*/ 47f9436522SJuan Quintela #define DEFAULT_MIGRATE_DECOMPRESS_THREAD_COUNT 2 48f9436522SJuan Quintela /*0: means nocompress, 1: best speed, ... 9: best compress ratio */ 49f9436522SJuan Quintela #define DEFAULT_MIGRATE_COMPRESS_LEVEL 1 50f9436522SJuan Quintela /* Define default autoconverge cpu throttle migration parameters */ 51f9436522SJuan Quintela #define DEFAULT_MIGRATE_THROTTLE_TRIGGER_THRESHOLD 50 52f9436522SJuan Quintela #define DEFAULT_MIGRATE_CPU_THROTTLE_INITIAL 20 53f9436522SJuan Quintela #define DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT 10 54f9436522SJuan Quintela #define DEFAULT_MIGRATE_MAX_CPU_THROTTLE 99 55f9436522SJuan Quintela 56f9436522SJuan Quintela /* Migration XBZRLE default cache size */ 57f9436522SJuan Quintela #define DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE (64 * 1024 * 1024) 58f9436522SJuan Quintela 59f9436522SJuan Quintela /* The delay time (in ms) between two COLO checkpoints */ 60f9436522SJuan Quintela #define DEFAULT_MIGRATE_X_CHECKPOINT_DELAY (200 * 100) 61f9436522SJuan Quintela #define DEFAULT_MIGRATE_MULTIFD_CHANNELS 2 62f9436522SJuan Quintela #define DEFAULT_MIGRATE_MULTIFD_COMPRESSION MULTIFD_COMPRESSION_NONE 63f9436522SJuan Quintela /* 0: means nocompress, 1: best speed, ... 9: best compress ratio */ 64f9436522SJuan Quintela #define DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL 1 65f9436522SJuan Quintela /* 0: means nocompress, 1: best speed, ... 20: best compress ratio */ 66f9436522SJuan Quintela #define DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL 1 67f9436522SJuan Quintela 68f9436522SJuan Quintela /* Background transfer rate for postcopy, 0 means unlimited, note 69f9436522SJuan Quintela * that page requests can still exceed this limit. 70f9436522SJuan Quintela */ 71f9436522SJuan Quintela #define DEFAULT_MIGRATE_MAX_POSTCOPY_BANDWIDTH 0 72f9436522SJuan Quintela 73f9436522SJuan Quintela /* 74f9436522SJuan Quintela * Parameters for self_announce_delay giving a stream of RARP/ARP 75f9436522SJuan Quintela * packets after migration. 76f9436522SJuan Quintela */ 77f9436522SJuan Quintela #define DEFAULT_MIGRATE_ANNOUNCE_INITIAL 50 78f9436522SJuan Quintela #define DEFAULT_MIGRATE_ANNOUNCE_MAX 550 79f9436522SJuan Quintela #define DEFAULT_MIGRATE_ANNOUNCE_ROUNDS 5 80f9436522SJuan Quintela #define DEFAULT_MIGRATE_ANNOUNCE_STEP 100 81f9436522SJuan Quintela 82f9436522SJuan Quintela #define DEFINE_PROP_MIG_CAP(name, x) \ 83f9436522SJuan Quintela DEFINE_PROP_BOOL(name, MigrationState, capabilities[x], false) 84f9436522SJuan Quintela 854d807857SHyman Huang(黄勇) #define DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD 1000 /* milliseconds */ 8609f9ec99SHyman Huang(黄勇) #define DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT 1 /* MB/s */ 874d807857SHyman Huang(黄勇) 88f9436522SJuan Quintela Property migration_properties[] = { 89f9436522SJuan Quintela DEFINE_PROP_BOOL("store-global-state", MigrationState, 90f9436522SJuan Quintela store_global_state, true), 91f9436522SJuan Quintela DEFINE_PROP_BOOL("send-configuration", MigrationState, 92f9436522SJuan Quintela send_configuration, true), 93f9436522SJuan Quintela DEFINE_PROP_BOOL("send-section-footer", MigrationState, 94f9436522SJuan Quintela send_section_footer, true), 95f9436522SJuan Quintela DEFINE_PROP_BOOL("decompress-error-check", MigrationState, 96f9436522SJuan Quintela decompress_error_check, true), 9777c259a4SJuan Quintela DEFINE_PROP_BOOL("multifd-flush-after-each-section", MigrationState, 98294e5a40SJuan Quintela multifd_flush_after_each_section, false), 99f9436522SJuan Quintela DEFINE_PROP_UINT8("x-clear-bitmap-shift", MigrationState, 100f9436522SJuan Quintela clear_bitmap_shift, CLEAR_BITMAP_SHIFT_DEFAULT), 101f9436522SJuan Quintela DEFINE_PROP_BOOL("x-preempt-pre-7-2", MigrationState, 102f9436522SJuan Quintela preempt_pre_7_2, false), 103f9436522SJuan Quintela 104f9436522SJuan Quintela /* Migration parameters */ 105f9436522SJuan Quintela DEFINE_PROP_UINT8("x-compress-level", MigrationState, 106f9436522SJuan Quintela parameters.compress_level, 107f9436522SJuan Quintela DEFAULT_MIGRATE_COMPRESS_LEVEL), 108f9436522SJuan Quintela DEFINE_PROP_UINT8("x-compress-threads", MigrationState, 109f9436522SJuan Quintela parameters.compress_threads, 110f9436522SJuan Quintela DEFAULT_MIGRATE_COMPRESS_THREAD_COUNT), 111f9436522SJuan Quintela DEFINE_PROP_BOOL("x-compress-wait-thread", MigrationState, 112f9436522SJuan Quintela parameters.compress_wait_thread, true), 113f9436522SJuan Quintela DEFINE_PROP_UINT8("x-decompress-threads", MigrationState, 114f9436522SJuan Quintela parameters.decompress_threads, 115f9436522SJuan Quintela DEFAULT_MIGRATE_DECOMPRESS_THREAD_COUNT), 116f9436522SJuan Quintela DEFINE_PROP_UINT8("x-throttle-trigger-threshold", MigrationState, 117f9436522SJuan Quintela parameters.throttle_trigger_threshold, 118f9436522SJuan Quintela DEFAULT_MIGRATE_THROTTLE_TRIGGER_THRESHOLD), 119f9436522SJuan Quintela DEFINE_PROP_UINT8("x-cpu-throttle-initial", MigrationState, 120f9436522SJuan Quintela parameters.cpu_throttle_initial, 121f9436522SJuan Quintela DEFAULT_MIGRATE_CPU_THROTTLE_INITIAL), 122f9436522SJuan Quintela DEFINE_PROP_UINT8("x-cpu-throttle-increment", MigrationState, 123f9436522SJuan Quintela parameters.cpu_throttle_increment, 124f9436522SJuan Quintela DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT), 125f9436522SJuan Quintela DEFINE_PROP_BOOL("x-cpu-throttle-tailslow", MigrationState, 126f9436522SJuan Quintela parameters.cpu_throttle_tailslow, false), 127f9436522SJuan Quintela DEFINE_PROP_SIZE("x-max-bandwidth", MigrationState, 128f9436522SJuan Quintela parameters.max_bandwidth, MAX_THROTTLE), 1298b239597SPeter Xu DEFINE_PROP_SIZE("avail-switchover-bandwidth", MigrationState, 1308b239597SPeter Xu parameters.avail_switchover_bandwidth, 0), 131f9436522SJuan Quintela DEFINE_PROP_UINT64("x-downtime-limit", MigrationState, 132f9436522SJuan Quintela parameters.downtime_limit, 133f9436522SJuan Quintela DEFAULT_MIGRATE_SET_DOWNTIME), 134f9436522SJuan Quintela DEFINE_PROP_UINT32("x-checkpoint-delay", MigrationState, 135f9436522SJuan Quintela parameters.x_checkpoint_delay, 136f9436522SJuan Quintela DEFAULT_MIGRATE_X_CHECKPOINT_DELAY), 137f9436522SJuan Quintela DEFINE_PROP_UINT8("multifd-channels", MigrationState, 138f9436522SJuan Quintela parameters.multifd_channels, 139f9436522SJuan Quintela DEFAULT_MIGRATE_MULTIFD_CHANNELS), 140f9436522SJuan Quintela DEFINE_PROP_MULTIFD_COMPRESSION("multifd-compression", MigrationState, 141f9436522SJuan Quintela parameters.multifd_compression, 142f9436522SJuan Quintela DEFAULT_MIGRATE_MULTIFD_COMPRESSION), 143f9436522SJuan Quintela DEFINE_PROP_UINT8("multifd-zlib-level", MigrationState, 144f9436522SJuan Quintela parameters.multifd_zlib_level, 145f9436522SJuan Quintela DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL), 146f9436522SJuan Quintela DEFINE_PROP_UINT8("multifd-zstd-level", MigrationState, 147f9436522SJuan Quintela parameters.multifd_zstd_level, 148f9436522SJuan Quintela DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL), 149f9436522SJuan Quintela DEFINE_PROP_SIZE("xbzrle-cache-size", MigrationState, 150f9436522SJuan Quintela parameters.xbzrle_cache_size, 151f9436522SJuan Quintela DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE), 152f9436522SJuan Quintela DEFINE_PROP_SIZE("max-postcopy-bandwidth", MigrationState, 153f9436522SJuan Quintela parameters.max_postcopy_bandwidth, 154f9436522SJuan Quintela DEFAULT_MIGRATE_MAX_POSTCOPY_BANDWIDTH), 155f9436522SJuan Quintela DEFINE_PROP_UINT8("max-cpu-throttle", MigrationState, 156f9436522SJuan Quintela parameters.max_cpu_throttle, 157f9436522SJuan Quintela DEFAULT_MIGRATE_MAX_CPU_THROTTLE), 158f9436522SJuan Quintela DEFINE_PROP_SIZE("announce-initial", MigrationState, 159f9436522SJuan Quintela parameters.announce_initial, 160f9436522SJuan Quintela DEFAULT_MIGRATE_ANNOUNCE_INITIAL), 161f9436522SJuan Quintela DEFINE_PROP_SIZE("announce-max", MigrationState, 162f9436522SJuan Quintela parameters.announce_max, 163f9436522SJuan Quintela DEFAULT_MIGRATE_ANNOUNCE_MAX), 164f9436522SJuan Quintela DEFINE_PROP_SIZE("announce-rounds", MigrationState, 165f9436522SJuan Quintela parameters.announce_rounds, 166f9436522SJuan Quintela DEFAULT_MIGRATE_ANNOUNCE_ROUNDS), 167f9436522SJuan Quintela DEFINE_PROP_SIZE("announce-step", MigrationState, 168f9436522SJuan Quintela parameters.announce_step, 169f9436522SJuan Quintela DEFAULT_MIGRATE_ANNOUNCE_STEP), 170f9436522SJuan Quintela DEFINE_PROP_STRING("tls-creds", MigrationState, parameters.tls_creds), 171f9436522SJuan Quintela DEFINE_PROP_STRING("tls-hostname", MigrationState, parameters.tls_hostname), 172f9436522SJuan Quintela DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz), 1734d807857SHyman Huang(黄勇) DEFINE_PROP_UINT64("x-vcpu-dirty-limit-period", MigrationState, 1744d807857SHyman Huang(黄勇) parameters.x_vcpu_dirty_limit_period, 1754d807857SHyman Huang(黄勇) DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD), 17609f9ec99SHyman Huang(黄勇) DEFINE_PROP_UINT64("vcpu-dirty-limit", MigrationState, 17709f9ec99SHyman Huang(黄勇) parameters.vcpu_dirty_limit, 17809f9ec99SHyman Huang(黄勇) DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT), 179*eea1e5c9SSteve Sistare DEFINE_PROP_MIG_MODE("mode", MigrationState, 180*eea1e5c9SSteve Sistare parameters.mode, 181*eea1e5c9SSteve Sistare MIG_MODE_NORMAL), 182f9436522SJuan Quintela 183f9436522SJuan Quintela /* Migration capabilities */ 184f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE), 185f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-rdma-pin-all", MIGRATION_CAPABILITY_RDMA_PIN_ALL), 186f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-auto-converge", MIGRATION_CAPABILITY_AUTO_CONVERGE), 187f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-zero-blocks", MIGRATION_CAPABILITY_ZERO_BLOCKS), 188f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-compress", MIGRATION_CAPABILITY_COMPRESS), 189f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-events", MIGRATION_CAPABILITY_EVENTS), 190f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-postcopy-ram", MIGRATION_CAPABILITY_POSTCOPY_RAM), 191f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-postcopy-preempt", 192f9436522SJuan Quintela MIGRATION_CAPABILITY_POSTCOPY_PREEMPT), 193f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-colo", MIGRATION_CAPABILITY_X_COLO), 194f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-release-ram", MIGRATION_CAPABILITY_RELEASE_RAM), 195f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-block", MIGRATION_CAPABILITY_BLOCK), 196f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-return-path", MIGRATION_CAPABILITY_RETURN_PATH), 197f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-multifd", MIGRATION_CAPABILITY_MULTIFD), 198f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-background-snapshot", 199f9436522SJuan Quintela MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT), 200f9436522SJuan Quintela #ifdef CONFIG_LINUX 201f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-zero-copy-send", 202f9436522SJuan Quintela MIGRATION_CAPABILITY_ZERO_COPY_SEND), 203f9436522SJuan Quintela #endif 2046574232fSAvihai Horon DEFINE_PROP_MIG_CAP("x-switchover-ack", 2056574232fSAvihai Horon MIGRATION_CAPABILITY_SWITCHOVER_ACK), 206dc623955SHyman Huang(黄勇) DEFINE_PROP_MIG_CAP("x-dirty-limit", MIGRATION_CAPABILITY_DIRTY_LIMIT), 207f9436522SJuan Quintela DEFINE_PROP_END_OF_LIST(), 208f9436522SJuan Quintela }; 209f9436522SJuan Quintela 2101f0776f1SJuan Quintela bool migrate_auto_converge(void) 2111f0776f1SJuan Quintela { 2128f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 2131f0776f1SJuan Quintela 2141f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_AUTO_CONVERGE]; 2151f0776f1SJuan Quintela } 2161f0776f1SJuan Quintela 2171f0776f1SJuan Quintela bool migrate_background_snapshot(void) 2181f0776f1SJuan Quintela { 2198f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 2201f0776f1SJuan Quintela 2211f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT]; 2221f0776f1SJuan Quintela } 2231f0776f1SJuan Quintela 2249d4b1e5fSJuan Quintela bool migrate_block(void) 2259d4b1e5fSJuan Quintela { 2268f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 2279d4b1e5fSJuan Quintela 2289d4b1e5fSJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_BLOCK]; 2299d4b1e5fSJuan Quintela } 2309d4b1e5fSJuan Quintela 2315e804644SJuan Quintela bool migrate_colo(void) 2325e804644SJuan Quintela { 2335e804644SJuan Quintela MigrationState *s = migrate_get_current(); 2348f9c5327SJuan Quintela 2355e804644SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_X_COLO]; 2365e804644SJuan Quintela } 2375e804644SJuan Quintela 238a7a94d14SJuan Quintela bool migrate_compress(void) 239a7a94d14SJuan Quintela { 2408f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 241a7a94d14SJuan Quintela 242a7a94d14SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_COMPRESS]; 243a7a94d14SJuan Quintela } 244a7a94d14SJuan Quintela 2451f0776f1SJuan Quintela bool migrate_dirty_bitmaps(void) 2461f0776f1SJuan Quintela { 2478f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 2481f0776f1SJuan Quintela 2491f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_DIRTY_BITMAPS]; 2501f0776f1SJuan Quintela } 2511f0776f1SJuan Quintela 252dc623955SHyman Huang(黄勇) bool migrate_dirty_limit(void) 253dc623955SHyman Huang(黄勇) { 254dc623955SHyman Huang(黄勇) MigrationState *s = migrate_get_current(); 255dc623955SHyman Huang(黄勇) 256dc623955SHyman Huang(黄勇) return s->capabilities[MIGRATION_CAPABILITY_DIRTY_LIMIT]; 257dc623955SHyman Huang(黄勇) } 258dc623955SHyman Huang(黄勇) 259b890902cSJuan Quintela bool migrate_events(void) 260b890902cSJuan Quintela { 2618f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 262b890902cSJuan Quintela 263b890902cSJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_EVENTS]; 264b890902cSJuan Quintela } 265b890902cSJuan Quintela 2661f0776f1SJuan Quintela bool migrate_ignore_shared(void) 2671f0776f1SJuan Quintela { 2688f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 2691f0776f1SJuan Quintela 2701f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_X_IGNORE_SHARED]; 2711f0776f1SJuan Quintela } 2721f0776f1SJuan Quintela 2731f0776f1SJuan Quintela bool migrate_late_block_activate(void) 2741f0776f1SJuan Quintela { 2758f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 2761f0776f1SJuan Quintela 2771f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE]; 2781f0776f1SJuan Quintela } 2791f0776f1SJuan Quintela 28051b07548SJuan Quintela bool migrate_multifd(void) 28151b07548SJuan Quintela { 2828f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 28351b07548SJuan Quintela 28451b07548SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_MULTIFD]; 28551b07548SJuan Quintela } 28651b07548SJuan Quintela 2871f0776f1SJuan Quintela bool migrate_pause_before_switchover(void) 2881f0776f1SJuan Quintela { 2898f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 2901f0776f1SJuan Quintela 2911f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER]; 2921f0776f1SJuan Quintela } 2931f0776f1SJuan Quintela 2941f0776f1SJuan Quintela bool migrate_postcopy_blocktime(void) 2951f0776f1SJuan Quintela { 2968f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 2971f0776f1SJuan Quintela 2981f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME]; 2991f0776f1SJuan Quintela } 3001f0776f1SJuan Quintela 3011f0776f1SJuan Quintela bool migrate_postcopy_preempt(void) 3021f0776f1SJuan Quintela { 3038f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 3041f0776f1SJuan Quintela 3051f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT]; 3061f0776f1SJuan Quintela } 3071f0776f1SJuan Quintela 3081f0776f1SJuan Quintela bool migrate_postcopy_ram(void) 3091f0776f1SJuan Quintela { 3108f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 3111f0776f1SJuan Quintela 3121f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_POSTCOPY_RAM]; 3131f0776f1SJuan Quintela } 3141f0776f1SJuan Quintela 31517cba690SJuan Quintela bool migrate_rdma_pin_all(void) 31617cba690SJuan Quintela { 31717cba690SJuan Quintela MigrationState *s = migrate_get_current(); 31817cba690SJuan Quintela 31917cba690SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_RDMA_PIN_ALL]; 32017cba690SJuan Quintela } 32117cba690SJuan Quintela 3221f0776f1SJuan Quintela bool migrate_release_ram(void) 3231f0776f1SJuan Quintela { 3248f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 3251f0776f1SJuan Quintela 3261f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_RELEASE_RAM]; 3271f0776f1SJuan Quintela } 3281f0776f1SJuan Quintela 32938ad1110SJuan Quintela bool migrate_return_path(void) 33038ad1110SJuan Quintela { 3318f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 33238ad1110SJuan Quintela 33338ad1110SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_RETURN_PATH]; 33438ad1110SJuan Quintela } 33538ad1110SJuan Quintela 3366574232fSAvihai Horon bool migrate_switchover_ack(void) 3376574232fSAvihai Horon { 3386574232fSAvihai Horon MigrationState *s = migrate_get_current(); 3396574232fSAvihai Horon 3406574232fSAvihai Horon return s->capabilities[MIGRATION_CAPABILITY_SWITCHOVER_ACK]; 3416574232fSAvihai Horon } 3426574232fSAvihai Horon 3431f0776f1SJuan Quintela bool migrate_validate_uuid(void) 3441f0776f1SJuan Quintela { 3458f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 3461f0776f1SJuan Quintela 3471f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_VALIDATE_UUID]; 3481f0776f1SJuan Quintela } 3491f0776f1SJuan Quintela 35087dca0c9SJuan Quintela bool migrate_xbzrle(void) 35187dca0c9SJuan Quintela { 3528f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 35387dca0c9SJuan Quintela 35487dca0c9SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_XBZRLE]; 35587dca0c9SJuan Quintela } 35687dca0c9SJuan Quintela 3571f0776f1SJuan Quintela bool migrate_zero_blocks(void) 3581f0776f1SJuan Quintela { 3598f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 3601f0776f1SJuan Quintela 3611f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_ZERO_BLOCKS]; 3621f0776f1SJuan Quintela } 363b4bc342cSJuan Quintela 364b4bc342cSJuan Quintela bool migrate_zero_copy_send(void) 365b4bc342cSJuan Quintela { 3668f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 367b4bc342cSJuan Quintela 368b4bc342cSJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_ZERO_COPY_SEND]; 369b4bc342cSJuan Quintela } 370f774fde5SJuan Quintela 371f774fde5SJuan Quintela /* pseudo capabilities */ 372f774fde5SJuan Quintela 37377c259a4SJuan Quintela bool migrate_multifd_flush_after_each_section(void) 37477c259a4SJuan Quintela { 37577c259a4SJuan Quintela MigrationState *s = migrate_get_current(); 37677c259a4SJuan Quintela 377294e5a40SJuan Quintela return s->multifd_flush_after_each_section; 37877c259a4SJuan Quintela } 37977c259a4SJuan Quintela 380f774fde5SJuan Quintela bool migrate_postcopy(void) 381f774fde5SJuan Quintela { 382f774fde5SJuan Quintela return migrate_postcopy_ram() || migrate_dirty_bitmaps(); 383f774fde5SJuan Quintela } 384f774fde5SJuan Quintela 38527fd25b0SJuan Quintela bool migrate_rdma(void) 38627fd25b0SJuan Quintela { 38727fd25b0SJuan Quintela MigrationState *s = migrate_get_current(); 38827fd25b0SJuan Quintela 38927fd25b0SJuan Quintela return s->rdma_migration; 39027fd25b0SJuan Quintela } 39127fd25b0SJuan Quintela 39210d4703bSJuan Quintela bool migrate_tls(void) 39310d4703bSJuan Quintela { 3948f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 39510d4703bSJuan Quintela 39610d4703bSJuan Quintela return s->parameters.tls_creds && *s->parameters.tls_creds; 39710d4703bSJuan Quintela } 39810d4703bSJuan Quintela 39977608706SJuan Quintela typedef enum WriteTrackingSupport { 40077608706SJuan Quintela WT_SUPPORT_UNKNOWN = 0, 40177608706SJuan Quintela WT_SUPPORT_ABSENT, 40277608706SJuan Quintela WT_SUPPORT_AVAILABLE, 40377608706SJuan Quintela WT_SUPPORT_COMPATIBLE 40477608706SJuan Quintela } WriteTrackingSupport; 40577608706SJuan Quintela 40677608706SJuan Quintela static 40777608706SJuan Quintela WriteTrackingSupport migrate_query_write_tracking(void) 40877608706SJuan Quintela { 40977608706SJuan Quintela /* Check if kernel supports required UFFD features */ 41077608706SJuan Quintela if (!ram_write_tracking_available()) { 41177608706SJuan Quintela return WT_SUPPORT_ABSENT; 41277608706SJuan Quintela } 41377608706SJuan Quintela /* 41477608706SJuan Quintela * Check if current memory configuration is 41577608706SJuan Quintela * compatible with required UFFD features. 41677608706SJuan Quintela */ 41777608706SJuan Quintela if (!ram_write_tracking_compatible()) { 41877608706SJuan Quintela return WT_SUPPORT_AVAILABLE; 41977608706SJuan Quintela } 42077608706SJuan Quintela 42177608706SJuan Quintela return WT_SUPPORT_COMPATIBLE; 42277608706SJuan Quintela } 42377608706SJuan Quintela 42477608706SJuan Quintela /* Migration capabilities set */ 42577608706SJuan Quintela struct MigrateCapsSet { 42677608706SJuan Quintela int size; /* Capability set size */ 42777608706SJuan Quintela MigrationCapability caps[]; /* Variadic array of capabilities */ 42877608706SJuan Quintela }; 42977608706SJuan Quintela typedef struct MigrateCapsSet MigrateCapsSet; 43077608706SJuan Quintela 43177608706SJuan Quintela /* Define and initialize MigrateCapsSet */ 43277608706SJuan Quintela #define INITIALIZE_MIGRATE_CAPS_SET(_name, ...) \ 43377608706SJuan Quintela MigrateCapsSet _name = { \ 43477608706SJuan Quintela .size = sizeof((int []) { __VA_ARGS__ }) / sizeof(int), \ 43577608706SJuan Quintela .caps = { __VA_ARGS__ } \ 43677608706SJuan Quintela } 43777608706SJuan Quintela 43877608706SJuan Quintela /* Background-snapshot compatibility check list */ 43977608706SJuan Quintela static const 44077608706SJuan Quintela INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snapshot, 44177608706SJuan Quintela MIGRATION_CAPABILITY_POSTCOPY_RAM, 44277608706SJuan Quintela MIGRATION_CAPABILITY_DIRTY_BITMAPS, 44377608706SJuan Quintela MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME, 44477608706SJuan Quintela MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE, 44577608706SJuan Quintela MIGRATION_CAPABILITY_RETURN_PATH, 44677608706SJuan Quintela MIGRATION_CAPABILITY_MULTIFD, 44777608706SJuan Quintela MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER, 44877608706SJuan Quintela MIGRATION_CAPABILITY_AUTO_CONVERGE, 44977608706SJuan Quintela MIGRATION_CAPABILITY_RELEASE_RAM, 45077608706SJuan Quintela MIGRATION_CAPABILITY_RDMA_PIN_ALL, 45177608706SJuan Quintela MIGRATION_CAPABILITY_COMPRESS, 45277608706SJuan Quintela MIGRATION_CAPABILITY_XBZRLE, 45377608706SJuan Quintela MIGRATION_CAPABILITY_X_COLO, 45477608706SJuan Quintela MIGRATION_CAPABILITY_VALIDATE_UUID, 45577608706SJuan Quintela MIGRATION_CAPABILITY_ZERO_COPY_SEND); 45677608706SJuan Quintela 45782137e6cSWei Wang static bool migrate_incoming_started(void) 45882137e6cSWei Wang { 45982137e6cSWei Wang return !!migration_incoming_get_current()->transport_data; 46082137e6cSWei Wang } 46182137e6cSWei Wang 46277608706SJuan Quintela /** 46377608706SJuan Quintela * @migration_caps_check - check capability compatibility 46477608706SJuan Quintela * 46577608706SJuan Quintela * @old_caps: old capability list 46677608706SJuan Quintela * @new_caps: new capability list 46777608706SJuan Quintela * @errp: set *errp if the check failed, with reason 46877608706SJuan Quintela * 46977608706SJuan Quintela * Returns true if check passed, otherwise false. 47077608706SJuan Quintela */ 47177608706SJuan Quintela bool migrate_caps_check(bool *old_caps, bool *new_caps, Error **errp) 47277608706SJuan Quintela { 47377608706SJuan Quintela MigrationIncomingState *mis = migration_incoming_get_current(); 47477608706SJuan Quintela 47574c38cf7SPeter Xu ERRP_GUARD(); 47677608706SJuan Quintela #ifndef CONFIG_LIVE_BLOCK_MIGRATION 47777608706SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_BLOCK]) { 47877608706SJuan Quintela error_setg(errp, "QEMU compiled without old-style (blk/-b, inc/-i) " 47977608706SJuan Quintela "block migration"); 48066db46caSJuan Quintela error_append_hint(errp, "Use blockdev-mirror with NBD instead.\n"); 48177608706SJuan Quintela return false; 48277608706SJuan Quintela } 48377608706SJuan Quintela #endif 48466db46caSJuan Quintela if (new_caps[MIGRATION_CAPABILITY_BLOCK]) { 48566db46caSJuan Quintela warn_report("block migration is deprecated;" 48666db46caSJuan Quintela " use blockdev-mirror with NBD instead"); 48766db46caSJuan Quintela } 48877608706SJuan Quintela 489864128dfSJuan Quintela if (new_caps[MIGRATION_CAPABILITY_COMPRESS]) { 490864128dfSJuan Quintela warn_report("old compression method is deprecated;" 491864128dfSJuan Quintela " use multifd compression methods instead"); 492864128dfSJuan Quintela } 493864128dfSJuan Quintela 49477608706SJuan Quintela #ifndef CONFIG_REPLICATION 49577608706SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_X_COLO]) { 49677608706SJuan Quintela error_setg(errp, "QEMU compiled without replication module" 49777608706SJuan Quintela " can't enable COLO"); 49877608706SJuan Quintela error_append_hint(errp, "Please enable replication before COLO.\n"); 49977608706SJuan Quintela return false; 50077608706SJuan Quintela } 50177608706SJuan Quintela #endif 50277608706SJuan Quintela 50377608706SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) { 50477608706SJuan Quintela /* This check is reasonably expensive, so only when it's being 50577608706SJuan Quintela * set the first time, also it's only the destination that needs 50677608706SJuan Quintela * special support. 50777608706SJuan Quintela */ 50877608706SJuan Quintela if (!old_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM] && 50977608706SJuan Quintela runstate_check(RUN_STATE_INMIGRATE) && 51074c38cf7SPeter Xu !postcopy_ram_supported_by_host(mis, errp)) { 51174c38cf7SPeter Xu error_prepend(errp, "Postcopy is not supported: "); 51277608706SJuan Quintela return false; 51377608706SJuan Quintela } 51477608706SJuan Quintela 51577608706SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_X_IGNORE_SHARED]) { 51677608706SJuan Quintela error_setg(errp, "Postcopy is not compatible with ignore-shared"); 51777608706SJuan Quintela return false; 51877608706SJuan Quintela } 519b405dfffSLeonardo Bras 520b405dfffSLeonardo Bras if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) { 521b405dfffSLeonardo Bras error_setg(errp, "Postcopy is not yet compatible with multifd"); 522b405dfffSLeonardo Bras return false; 523b405dfffSLeonardo Bras } 52477608706SJuan Quintela } 52577608706SJuan Quintela 52677608706SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT]) { 52777608706SJuan Quintela WriteTrackingSupport wt_support; 52877608706SJuan Quintela int idx; 52977608706SJuan Quintela /* 53077608706SJuan Quintela * Check if 'background-snapshot' capability is supported by 53177608706SJuan Quintela * host kernel and compatible with guest memory configuration. 53277608706SJuan Quintela */ 53377608706SJuan Quintela wt_support = migrate_query_write_tracking(); 53477608706SJuan Quintela if (wt_support < WT_SUPPORT_AVAILABLE) { 53577608706SJuan Quintela error_setg(errp, "Background-snapshot is not supported by host kernel"); 53677608706SJuan Quintela return false; 53777608706SJuan Quintela } 53877608706SJuan Quintela if (wt_support < WT_SUPPORT_COMPATIBLE) { 53977608706SJuan Quintela error_setg(errp, "Background-snapshot is not compatible " 54077608706SJuan Quintela "with guest memory configuration"); 54177608706SJuan Quintela return false; 54277608706SJuan Quintela } 54377608706SJuan Quintela 54477608706SJuan Quintela /* 54577608706SJuan Quintela * Check if there are any migration capabilities 54677608706SJuan Quintela * incompatible with 'background-snapshot'. 54777608706SJuan Quintela */ 54877608706SJuan Quintela for (idx = 0; idx < check_caps_background_snapshot.size; idx++) { 54977608706SJuan Quintela int incomp_cap = check_caps_background_snapshot.caps[idx]; 55077608706SJuan Quintela if (new_caps[incomp_cap]) { 55177608706SJuan Quintela error_setg(errp, 55277608706SJuan Quintela "Background-snapshot is not compatible with %s", 55377608706SJuan Quintela MigrationCapability_str(incomp_cap)); 55477608706SJuan Quintela return false; 55577608706SJuan Quintela } 55677608706SJuan Quintela } 55777608706SJuan Quintela } 55877608706SJuan Quintela 55977608706SJuan Quintela #ifdef CONFIG_LINUX 56077608706SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_ZERO_COPY_SEND] && 56177608706SJuan Quintela (!new_caps[MIGRATION_CAPABILITY_MULTIFD] || 56277608706SJuan Quintela new_caps[MIGRATION_CAPABILITY_COMPRESS] || 56377608706SJuan Quintela new_caps[MIGRATION_CAPABILITY_XBZRLE] || 56477608706SJuan Quintela migrate_multifd_compression() || 56510d4703bSJuan Quintela migrate_tls())) { 56677608706SJuan Quintela error_setg(errp, 56777608706SJuan Quintela "Zero copy only available for non-compressed non-TLS multifd migration"); 56877608706SJuan Quintela return false; 56977608706SJuan Quintela } 57077608706SJuan Quintela #else 57177608706SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_ZERO_COPY_SEND]) { 57277608706SJuan Quintela error_setg(errp, 57377608706SJuan Quintela "Zero copy currently only available on Linux"); 57477608706SJuan Quintela return false; 57577608706SJuan Quintela } 57677608706SJuan Quintela #endif 57777608706SJuan Quintela 57877608706SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT]) { 57977608706SJuan Quintela if (!new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) { 58077608706SJuan Quintela error_setg(errp, "Postcopy preempt requires postcopy-ram"); 58177608706SJuan Quintela return false; 58277608706SJuan Quintela } 58377608706SJuan Quintela 58477608706SJuan Quintela /* 58577608706SJuan Quintela * Preempt mode requires urgent pages to be sent in separate 58677608706SJuan Quintela * channel, OTOH compression logic will disorder all pages into 58777608706SJuan Quintela * different compression channels, which is not compatible with the 58877608706SJuan Quintela * preempt assumptions on channel assignments. 58977608706SJuan Quintela */ 59077608706SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_COMPRESS]) { 59177608706SJuan Quintela error_setg(errp, "Postcopy preempt not compatible with compress"); 59277608706SJuan Quintela return false; 59377608706SJuan Quintela } 59482137e6cSWei Wang 59582137e6cSWei Wang if (migrate_incoming_started()) { 59682137e6cSWei Wang error_setg(errp, 59782137e6cSWei Wang "Postcopy preempt must be set before incoming starts"); 59882137e6cSWei Wang return false; 59982137e6cSWei Wang } 60077608706SJuan Quintela } 60177608706SJuan Quintela 60277608706SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) { 60377608706SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_COMPRESS]) { 60477608706SJuan Quintela error_setg(errp, "Multifd is not compatible with compress"); 60577608706SJuan Quintela return false; 60677608706SJuan Quintela } 60782137e6cSWei Wang if (migrate_incoming_started()) { 60882137e6cSWei Wang error_setg(errp, "Multifd must be set before incoming starts"); 60982137e6cSWei Wang return false; 61082137e6cSWei Wang } 61177608706SJuan Quintela } 61277608706SJuan Quintela 6136574232fSAvihai Horon if (new_caps[MIGRATION_CAPABILITY_SWITCHOVER_ACK]) { 6146574232fSAvihai Horon if (!new_caps[MIGRATION_CAPABILITY_RETURN_PATH]) { 6156574232fSAvihai Horon error_setg(errp, "Capability 'switchover-ack' requires capability " 6166574232fSAvihai Horon "'return-path'"); 6176574232fSAvihai Horon return false; 6186574232fSAvihai Horon } 6196574232fSAvihai Horon } 620dc623955SHyman Huang(黄勇) if (new_caps[MIGRATION_CAPABILITY_DIRTY_LIMIT]) { 621dc623955SHyman Huang(黄勇) if (new_caps[MIGRATION_CAPABILITY_AUTO_CONVERGE]) { 622dc623955SHyman Huang(黄勇) error_setg(errp, "dirty-limit conflicts with auto-converge" 623dc623955SHyman Huang(黄勇) " either of then available currently"); 624dc623955SHyman Huang(黄勇) return false; 625dc623955SHyman Huang(黄勇) } 626dc623955SHyman Huang(黄勇) 627dc623955SHyman Huang(黄勇) if (!kvm_enabled() || !kvm_dirty_ring_enabled()) { 628dc623955SHyman Huang(黄勇) error_setg(errp, "dirty-limit requires KVM with accelerator" 629dc623955SHyman Huang(黄勇) " property 'dirty-ring-size' set"); 630dc623955SHyman Huang(黄勇) return false; 631dc623955SHyman Huang(黄勇) } 632dc623955SHyman Huang(黄勇) } 6336574232fSAvihai Horon 634d869f629SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) { 635d869f629SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_XBZRLE]) { 636d869f629SJuan Quintela error_setg(errp, "Multifd is not compatible with xbzrle"); 637d869f629SJuan Quintela return false; 638d869f629SJuan Quintela } 639d869f629SJuan Quintela } 640d869f629SJuan Quintela 6410e195629SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_COMPRESS]) { 6420e195629SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_XBZRLE]) { 6430e195629SJuan Quintela error_setg(errp, "Compression is not compatible with xbzrle"); 6440e195629SJuan Quintela return false; 6450e195629SJuan Quintela } 6460e195629SJuan Quintela } 6470e195629SJuan Quintela 64877608706SJuan Quintela return true; 64977608706SJuan Quintela } 6504d0c6b69SJuan Quintela 651f80196b7SJuan Quintela bool migrate_cap_set(int cap, bool value, Error **errp) 652f80196b7SJuan Quintela { 653f80196b7SJuan Quintela MigrationState *s = migrate_get_current(); 654f80196b7SJuan Quintela bool new_caps[MIGRATION_CAPABILITY__MAX]; 655f80196b7SJuan Quintela 656f80196b7SJuan Quintela if (migration_is_running(s->state)) { 657f80196b7SJuan Quintela error_setg(errp, QERR_MIGRATION_ACTIVE); 658f80196b7SJuan Quintela return false; 659f80196b7SJuan Quintela } 660f80196b7SJuan Quintela 661f80196b7SJuan Quintela memcpy(new_caps, s->capabilities, sizeof(new_caps)); 662f80196b7SJuan Quintela new_caps[cap] = value; 663f80196b7SJuan Quintela 664f80196b7SJuan Quintela if (!migrate_caps_check(s->capabilities, new_caps, errp)) { 665f80196b7SJuan Quintela return false; 666f80196b7SJuan Quintela } 667f80196b7SJuan Quintela s->capabilities[cap] = value; 668f80196b7SJuan Quintela return true; 669f80196b7SJuan Quintela } 670f80196b7SJuan Quintela 6714d0c6b69SJuan Quintela MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp) 6724d0c6b69SJuan Quintela { 6734d0c6b69SJuan Quintela MigrationCapabilityStatusList *head = NULL, **tail = &head; 6744d0c6b69SJuan Quintela MigrationCapabilityStatus *caps; 6754d0c6b69SJuan Quintela MigrationState *s = migrate_get_current(); 6764d0c6b69SJuan Quintela int i; 6774d0c6b69SJuan Quintela 6784d0c6b69SJuan Quintela for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) { 6794d0c6b69SJuan Quintela #ifndef CONFIG_LIVE_BLOCK_MIGRATION 6804d0c6b69SJuan Quintela if (i == MIGRATION_CAPABILITY_BLOCK) { 6814d0c6b69SJuan Quintela continue; 6824d0c6b69SJuan Quintela } 6834d0c6b69SJuan Quintela #endif 6844d0c6b69SJuan Quintela caps = g_malloc0(sizeof(*caps)); 6854d0c6b69SJuan Quintela caps->capability = i; 6864d0c6b69SJuan Quintela caps->state = s->capabilities[i]; 6874d0c6b69SJuan Quintela QAPI_LIST_APPEND(tail, caps); 6884d0c6b69SJuan Quintela } 6894d0c6b69SJuan Quintela 6904d0c6b69SJuan Quintela return head; 6914d0c6b69SJuan Quintela } 69245c1de13SJuan Quintela 69345c1de13SJuan Quintela void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params, 69445c1de13SJuan Quintela Error **errp) 69545c1de13SJuan Quintela { 69645c1de13SJuan Quintela MigrationState *s = migrate_get_current(); 69745c1de13SJuan Quintela MigrationCapabilityStatusList *cap; 69845c1de13SJuan Quintela bool new_caps[MIGRATION_CAPABILITY__MAX]; 69945c1de13SJuan Quintela 700d70178a8SVladimir Sementsov-Ogievskiy if (migration_is_running(s->state) || migration_in_colo_state()) { 70145c1de13SJuan Quintela error_setg(errp, QERR_MIGRATION_ACTIVE); 70245c1de13SJuan Quintela return; 70345c1de13SJuan Quintela } 70445c1de13SJuan Quintela 70545c1de13SJuan Quintela memcpy(new_caps, s->capabilities, sizeof(new_caps)); 70645c1de13SJuan Quintela for (cap = params; cap; cap = cap->next) { 70745c1de13SJuan Quintela new_caps[cap->value->capability] = cap->value->state; 70845c1de13SJuan Quintela } 70945c1de13SJuan Quintela 71045c1de13SJuan Quintela if (!migrate_caps_check(s->capabilities, new_caps, errp)) { 71145c1de13SJuan Quintela return; 71245c1de13SJuan Quintela } 71345c1de13SJuan Quintela 71445c1de13SJuan Quintela for (cap = params; cap; cap = cap->next) { 71545c1de13SJuan Quintela s->capabilities[cap->value->capability] = cap->value->state; 71645c1de13SJuan Quintela } 71745c1de13SJuan Quintela } 7181dfc4b9eSJuan Quintela 7191dfc4b9eSJuan Quintela /* parameters */ 7201dfc4b9eSJuan Quintela 721b804b35bSJuan Quintela const BitmapMigrationNodeAliasList *migrate_block_bitmap_mapping(void) 722b804b35bSJuan Quintela { 723b804b35bSJuan Quintela MigrationState *s = migrate_get_current(); 724b804b35bSJuan Quintela 725b804b35bSJuan Quintela return s->parameters.block_bitmap_mapping; 726b804b35bSJuan Quintela } 727b804b35bSJuan Quintela 7283cba22c9SJuan Quintela bool migrate_has_block_bitmap_mapping(void) 7293cba22c9SJuan Quintela { 7303cba22c9SJuan Quintela MigrationState *s = migrate_get_current(); 7313cba22c9SJuan Quintela 7323cba22c9SJuan Quintela return s->parameters.has_block_bitmap_mapping; 7333cba22c9SJuan Quintela } 7343cba22c9SJuan Quintela 7356f8be708SJuan Quintela bool migrate_block_incremental(void) 7366f8be708SJuan Quintela { 7378f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 7386f8be708SJuan Quintela 7396f8be708SJuan Quintela return s->parameters.block_incremental; 7406f8be708SJuan Quintela } 7416f8be708SJuan Quintela 742f94a858fSJuan Quintela uint32_t migrate_checkpoint_delay(void) 743f94a858fSJuan Quintela { 7448f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 745f94a858fSJuan Quintela 746f94a858fSJuan Quintela return s->parameters.x_checkpoint_delay; 747f94a858fSJuan Quintela } 748f94a858fSJuan Quintela 7491dfc4b9eSJuan Quintela int migrate_compress_level(void) 7501dfc4b9eSJuan Quintela { 7518f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 7521dfc4b9eSJuan Quintela 7531dfc4b9eSJuan Quintela return s->parameters.compress_level; 7541dfc4b9eSJuan Quintela } 7551dfc4b9eSJuan Quintela 7561dfc4b9eSJuan Quintela int migrate_compress_threads(void) 7571dfc4b9eSJuan Quintela { 7588f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 7591dfc4b9eSJuan Quintela 7601dfc4b9eSJuan Quintela return s->parameters.compress_threads; 7611dfc4b9eSJuan Quintela } 7621dfc4b9eSJuan Quintela 7631dfc4b9eSJuan Quintela int migrate_compress_wait_thread(void) 7641dfc4b9eSJuan Quintela { 7658f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 7661dfc4b9eSJuan Quintela 7671dfc4b9eSJuan Quintela return s->parameters.compress_wait_thread; 7681dfc4b9eSJuan Quintela } 7691dfc4b9eSJuan Quintela 7709605c2acSJuan Quintela uint8_t migrate_cpu_throttle_increment(void) 7719605c2acSJuan Quintela { 7728f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 7739605c2acSJuan Quintela 7749605c2acSJuan Quintela return s->parameters.cpu_throttle_increment; 7759605c2acSJuan Quintela } 7769605c2acSJuan Quintela 7772a8ec380SJuan Quintela uint8_t migrate_cpu_throttle_initial(void) 7782a8ec380SJuan Quintela { 7798f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 7802a8ec380SJuan Quintela 7812a8ec380SJuan Quintela return s->parameters.cpu_throttle_initial; 7822a8ec380SJuan Quintela } 7832a8ec380SJuan Quintela 784873f674cSJuan Quintela bool migrate_cpu_throttle_tailslow(void) 785873f674cSJuan Quintela { 7868f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 787873f674cSJuan Quintela 788873f674cSJuan Quintela return s->parameters.cpu_throttle_tailslow; 789873f674cSJuan Quintela } 790873f674cSJuan Quintela 7911dfc4b9eSJuan Quintela int migrate_decompress_threads(void) 7921dfc4b9eSJuan Quintela { 7938f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 7941dfc4b9eSJuan Quintela 7951dfc4b9eSJuan Quintela return s->parameters.decompress_threads; 7961dfc4b9eSJuan Quintela } 7971dfc4b9eSJuan Quintela 798f5da8ba4SJuan Quintela uint64_t migrate_downtime_limit(void) 799f5da8ba4SJuan Quintela { 800f5da8ba4SJuan Quintela MigrationState *s = migrate_get_current(); 801f5da8ba4SJuan Quintela 802f5da8ba4SJuan Quintela return s->parameters.downtime_limit; 803f5da8ba4SJuan Quintela } 804f5da8ba4SJuan Quintela 80524155bd0SJuan Quintela uint8_t migrate_max_cpu_throttle(void) 80624155bd0SJuan Quintela { 8078f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 80824155bd0SJuan Quintela 80924155bd0SJuan Quintela return s->parameters.max_cpu_throttle; 81024155bd0SJuan Quintela } 81124155bd0SJuan Quintela 8129c894df3SJuan Quintela uint64_t migrate_max_bandwidth(void) 8139c894df3SJuan Quintela { 8148f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 8159c894df3SJuan Quintela 8169c894df3SJuan Quintela return s->parameters.max_bandwidth; 8179c894df3SJuan Quintela } 8189c894df3SJuan Quintela 8198b239597SPeter Xu uint64_t migrate_avail_switchover_bandwidth(void) 8208b239597SPeter Xu { 8218b239597SPeter Xu MigrationState *s = migrate_get_current(); 8228b239597SPeter Xu 8238b239597SPeter Xu return s->parameters.avail_switchover_bandwidth; 8248b239597SPeter Xu } 8258b239597SPeter Xu 82652033349SJuan Quintela uint64_t migrate_max_postcopy_bandwidth(void) 8271dfc4b9eSJuan Quintela { 8288f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 8291dfc4b9eSJuan Quintela 8301dfc4b9eSJuan Quintela return s->parameters.max_postcopy_bandwidth; 8311dfc4b9eSJuan Quintela } 8321dfc4b9eSJuan Quintela 833*eea1e5c9SSteve Sistare MigMode migrate_mode(void) 834*eea1e5c9SSteve Sistare { 835*eea1e5c9SSteve Sistare MigrationState *s = migrate_get_current(); 836*eea1e5c9SSteve Sistare 837*eea1e5c9SSteve Sistare return s->parameters.mode; 838*eea1e5c9SSteve Sistare } 839*eea1e5c9SSteve Sistare 8401dfc4b9eSJuan Quintela int migrate_multifd_channels(void) 8411dfc4b9eSJuan Quintela { 8428f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 8431dfc4b9eSJuan Quintela 8441dfc4b9eSJuan Quintela return s->parameters.multifd_channels; 8451dfc4b9eSJuan Quintela } 8461dfc4b9eSJuan Quintela 8471dfc4b9eSJuan Quintela MultiFDCompression migrate_multifd_compression(void) 8481dfc4b9eSJuan Quintela { 8498f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 8501dfc4b9eSJuan Quintela 8511dfc4b9eSJuan Quintela assert(s->parameters.multifd_compression < MULTIFD_COMPRESSION__MAX); 8521dfc4b9eSJuan Quintela return s->parameters.multifd_compression; 8531dfc4b9eSJuan Quintela } 8541dfc4b9eSJuan Quintela 8551dfc4b9eSJuan Quintela int migrate_multifd_zlib_level(void) 8561dfc4b9eSJuan Quintela { 8578f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 8581dfc4b9eSJuan Quintela 8591dfc4b9eSJuan Quintela return s->parameters.multifd_zlib_level; 8601dfc4b9eSJuan Quintela } 8611dfc4b9eSJuan Quintela 8621dfc4b9eSJuan Quintela int migrate_multifd_zstd_level(void) 8631dfc4b9eSJuan Quintela { 8648f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 8651dfc4b9eSJuan Quintela 8661dfc4b9eSJuan Quintela return s->parameters.multifd_zstd_level; 8671dfc4b9eSJuan Quintela } 8681dfc4b9eSJuan Quintela 8696499efdbSJuan Quintela uint8_t migrate_throttle_trigger_threshold(void) 8706499efdbSJuan Quintela { 8718f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 8726499efdbSJuan Quintela 8736499efdbSJuan Quintela return s->parameters.throttle_trigger_threshold; 8746499efdbSJuan Quintela } 8756499efdbSJuan Quintela 8762eb0308bSJuan Quintela const char *migrate_tls_authz(void) 8772eb0308bSJuan Quintela { 8782eb0308bSJuan Quintela MigrationState *s = migrate_get_current(); 8792eb0308bSJuan Quintela 8802eb0308bSJuan Quintela return s->parameters.tls_authz; 8812eb0308bSJuan Quintela } 8822eb0308bSJuan Quintela 883d5c3e195SJuan Quintela const char *migrate_tls_creds(void) 884d5c3e195SJuan Quintela { 885d5c3e195SJuan Quintela MigrationState *s = migrate_get_current(); 886d5c3e195SJuan Quintela 887d5c3e195SJuan Quintela return s->parameters.tls_creds; 888d5c3e195SJuan Quintela } 889d5c3e195SJuan Quintela 8901f2f366cSJuan Quintela const char *migrate_tls_hostname(void) 8911f2f366cSJuan Quintela { 8921f2f366cSJuan Quintela MigrationState *s = migrate_get_current(); 8931f2f366cSJuan Quintela 8941f2f366cSJuan Quintela return s->parameters.tls_hostname; 8951f2f366cSJuan Quintela } 8961f2f366cSJuan Quintela 8971dfc4b9eSJuan Quintela uint64_t migrate_xbzrle_cache_size(void) 8981dfc4b9eSJuan Quintela { 8998f9c5327SJuan Quintela MigrationState *s = migrate_get_current(); 9001dfc4b9eSJuan Quintela 9011dfc4b9eSJuan Quintela return s->parameters.xbzrle_cache_size; 9021dfc4b9eSJuan Quintela } 9032682c4eeSJuan Quintela 90487c22901SJuan Quintela /* parameter setters */ 90587c22901SJuan Quintela 90687c22901SJuan Quintela void migrate_set_block_incremental(bool value) 90787c22901SJuan Quintela { 90887c22901SJuan Quintela MigrationState *s = migrate_get_current(); 90987c22901SJuan Quintela 91087c22901SJuan Quintela s->parameters.block_incremental = value; 91187c22901SJuan Quintela } 91287c22901SJuan Quintela 9132682c4eeSJuan Quintela /* parameters helpers */ 9142682c4eeSJuan Quintela 915b1a87956SJuan Quintela void block_cleanup_parameters(void) 916b7b73122SJuan Quintela { 917b1a87956SJuan Quintela MigrationState *s = migrate_get_current(); 918b1a87956SJuan Quintela 919b7b73122SJuan Quintela if (s->must_remove_block_options) { 920b7b73122SJuan Quintela /* setting to false can never fail */ 921b7b73122SJuan Quintela migrate_cap_set(MIGRATION_CAPABILITY_BLOCK, false, &error_abort); 922b7b73122SJuan Quintela migrate_set_block_incremental(false); 923b7b73122SJuan Quintela s->must_remove_block_options = false; 924b7b73122SJuan Quintela } 925b7b73122SJuan Quintela } 926b7b73122SJuan Quintela 9272682c4eeSJuan Quintela AnnounceParameters *migrate_announce_params(void) 9282682c4eeSJuan Quintela { 9292682c4eeSJuan Quintela static AnnounceParameters ap; 9302682c4eeSJuan Quintela 9312682c4eeSJuan Quintela MigrationState *s = migrate_get_current(); 9322682c4eeSJuan Quintela 9332682c4eeSJuan Quintela ap.initial = s->parameters.announce_initial; 9342682c4eeSJuan Quintela ap.max = s->parameters.announce_max; 9352682c4eeSJuan Quintela ap.rounds = s->parameters.announce_rounds; 9362682c4eeSJuan Quintela ap.step = s->parameters.announce_step; 9372682c4eeSJuan Quintela 9382682c4eeSJuan Quintela return ≈ 9392682c4eeSJuan Quintela } 9409c894df3SJuan Quintela 9419c894df3SJuan Quintela MigrationParameters *qmp_query_migrate_parameters(Error **errp) 9429c894df3SJuan Quintela { 9439c894df3SJuan Quintela MigrationParameters *params; 9449c894df3SJuan Quintela MigrationState *s = migrate_get_current(); 9459c894df3SJuan Quintela 9469c894df3SJuan Quintela /* TODO use QAPI_CLONE() instead of duplicating it inline */ 9479c894df3SJuan Quintela params = g_malloc0(sizeof(*params)); 9489c894df3SJuan Quintela params->has_compress_level = true; 9499c894df3SJuan Quintela params->compress_level = s->parameters.compress_level; 9509c894df3SJuan Quintela params->has_compress_threads = true; 9519c894df3SJuan Quintela params->compress_threads = s->parameters.compress_threads; 9529c894df3SJuan Quintela params->has_compress_wait_thread = true; 9539c894df3SJuan Quintela params->compress_wait_thread = s->parameters.compress_wait_thread; 9549c894df3SJuan Quintela params->has_decompress_threads = true; 9559c894df3SJuan Quintela params->decompress_threads = s->parameters.decompress_threads; 9569c894df3SJuan Quintela params->has_throttle_trigger_threshold = true; 9579c894df3SJuan Quintela params->throttle_trigger_threshold = s->parameters.throttle_trigger_threshold; 9589c894df3SJuan Quintela params->has_cpu_throttle_initial = true; 9599c894df3SJuan Quintela params->cpu_throttle_initial = s->parameters.cpu_throttle_initial; 9609c894df3SJuan Quintela params->has_cpu_throttle_increment = true; 9619c894df3SJuan Quintela params->cpu_throttle_increment = s->parameters.cpu_throttle_increment; 9629c894df3SJuan Quintela params->has_cpu_throttle_tailslow = true; 9639c894df3SJuan Quintela params->cpu_throttle_tailslow = s->parameters.cpu_throttle_tailslow; 9649c894df3SJuan Quintela params->tls_creds = g_strdup(s->parameters.tls_creds); 9659c894df3SJuan Quintela params->tls_hostname = g_strdup(s->parameters.tls_hostname); 9669c894df3SJuan Quintela params->tls_authz = g_strdup(s->parameters.tls_authz ? 9679c894df3SJuan Quintela s->parameters.tls_authz : ""); 9689c894df3SJuan Quintela params->has_max_bandwidth = true; 9699c894df3SJuan Quintela params->max_bandwidth = s->parameters.max_bandwidth; 9708b239597SPeter Xu params->has_avail_switchover_bandwidth = true; 9718b239597SPeter Xu params->avail_switchover_bandwidth = s->parameters.avail_switchover_bandwidth; 9729c894df3SJuan Quintela params->has_downtime_limit = true; 9739c894df3SJuan Quintela params->downtime_limit = s->parameters.downtime_limit; 9749c894df3SJuan Quintela params->has_x_checkpoint_delay = true; 9759c894df3SJuan Quintela params->x_checkpoint_delay = s->parameters.x_checkpoint_delay; 9769c894df3SJuan Quintela params->has_block_incremental = true; 9779c894df3SJuan Quintela params->block_incremental = s->parameters.block_incremental; 9789c894df3SJuan Quintela params->has_multifd_channels = true; 9799c894df3SJuan Quintela params->multifd_channels = s->parameters.multifd_channels; 9809c894df3SJuan Quintela params->has_multifd_compression = true; 9819c894df3SJuan Quintela params->multifd_compression = s->parameters.multifd_compression; 9829c894df3SJuan Quintela params->has_multifd_zlib_level = true; 9839c894df3SJuan Quintela params->multifd_zlib_level = s->parameters.multifd_zlib_level; 9849c894df3SJuan Quintela params->has_multifd_zstd_level = true; 9859c894df3SJuan Quintela params->multifd_zstd_level = s->parameters.multifd_zstd_level; 9869c894df3SJuan Quintela params->has_xbzrle_cache_size = true; 9879c894df3SJuan Quintela params->xbzrle_cache_size = s->parameters.xbzrle_cache_size; 9889c894df3SJuan Quintela params->has_max_postcopy_bandwidth = true; 9899c894df3SJuan Quintela params->max_postcopy_bandwidth = s->parameters.max_postcopy_bandwidth; 9909c894df3SJuan Quintela params->has_max_cpu_throttle = true; 9919c894df3SJuan Quintela params->max_cpu_throttle = s->parameters.max_cpu_throttle; 9929c894df3SJuan Quintela params->has_announce_initial = true; 9939c894df3SJuan Quintela params->announce_initial = s->parameters.announce_initial; 9949c894df3SJuan Quintela params->has_announce_max = true; 9959c894df3SJuan Quintela params->announce_max = s->parameters.announce_max; 9969c894df3SJuan Quintela params->has_announce_rounds = true; 9979c894df3SJuan Quintela params->announce_rounds = s->parameters.announce_rounds; 9989c894df3SJuan Quintela params->has_announce_step = true; 9999c894df3SJuan Quintela params->announce_step = s->parameters.announce_step; 10009c894df3SJuan Quintela 10019c894df3SJuan Quintela if (s->parameters.has_block_bitmap_mapping) { 10029c894df3SJuan Quintela params->has_block_bitmap_mapping = true; 10039c894df3SJuan Quintela params->block_bitmap_mapping = 10049c894df3SJuan Quintela QAPI_CLONE(BitmapMigrationNodeAliasList, 10059c894df3SJuan Quintela s->parameters.block_bitmap_mapping); 10069c894df3SJuan Quintela } 10079c894df3SJuan Quintela 10084d807857SHyman Huang(黄勇) params->has_x_vcpu_dirty_limit_period = true; 10094d807857SHyman Huang(黄勇) params->x_vcpu_dirty_limit_period = s->parameters.x_vcpu_dirty_limit_period; 101009f9ec99SHyman Huang(黄勇) params->has_vcpu_dirty_limit = true; 101109f9ec99SHyman Huang(黄勇) params->vcpu_dirty_limit = s->parameters.vcpu_dirty_limit; 1012*eea1e5c9SSteve Sistare params->has_mode = true; 1013*eea1e5c9SSteve Sistare params->mode = s->parameters.mode; 10144d807857SHyman Huang(黄勇) 10159c894df3SJuan Quintela return params; 10169c894df3SJuan Quintela } 101709d6c965SJuan Quintela 101861a174e2SJuan Quintela void migrate_params_init(MigrationParameters *params) 101961a174e2SJuan Quintela { 102061a174e2SJuan Quintela params->tls_hostname = g_strdup(""); 102161a174e2SJuan Quintela params->tls_creds = g_strdup(""); 102261a174e2SJuan Quintela 102361a174e2SJuan Quintela /* Set has_* up only for parameter checks */ 102461a174e2SJuan Quintela params->has_compress_level = true; 102561a174e2SJuan Quintela params->has_compress_threads = true; 102661a174e2SJuan Quintela params->has_compress_wait_thread = true; 102761a174e2SJuan Quintela params->has_decompress_threads = true; 102861a174e2SJuan Quintela params->has_throttle_trigger_threshold = true; 102961a174e2SJuan Quintela params->has_cpu_throttle_initial = true; 103061a174e2SJuan Quintela params->has_cpu_throttle_increment = true; 103161a174e2SJuan Quintela params->has_cpu_throttle_tailslow = true; 103261a174e2SJuan Quintela params->has_max_bandwidth = true; 103361a174e2SJuan Quintela params->has_downtime_limit = true; 103461a174e2SJuan Quintela params->has_x_checkpoint_delay = true; 103561a174e2SJuan Quintela params->has_block_incremental = true; 103661a174e2SJuan Quintela params->has_multifd_channels = true; 103761a174e2SJuan Quintela params->has_multifd_compression = true; 103861a174e2SJuan Quintela params->has_multifd_zlib_level = true; 103961a174e2SJuan Quintela params->has_multifd_zstd_level = true; 104061a174e2SJuan Quintela params->has_xbzrle_cache_size = true; 104161a174e2SJuan Quintela params->has_max_postcopy_bandwidth = true; 104261a174e2SJuan Quintela params->has_max_cpu_throttle = true; 104361a174e2SJuan Quintela params->has_announce_initial = true; 104461a174e2SJuan Quintela params->has_announce_max = true; 104561a174e2SJuan Quintela params->has_announce_rounds = true; 104661a174e2SJuan Quintela params->has_announce_step = true; 10474d807857SHyman Huang(黄勇) params->has_x_vcpu_dirty_limit_period = true; 104809f9ec99SHyman Huang(黄勇) params->has_vcpu_dirty_limit = true; 1049*eea1e5c9SSteve Sistare params->has_mode = true; 105061a174e2SJuan Quintela } 105161a174e2SJuan Quintela 105209d6c965SJuan Quintela /* 105309d6c965SJuan Quintela * Check whether the parameters are valid. Error will be put into errp 105409d6c965SJuan Quintela * (if provided). Return true if valid, otherwise false. 105509d6c965SJuan Quintela */ 105609d6c965SJuan Quintela bool migrate_params_check(MigrationParameters *params, Error **errp) 105709d6c965SJuan Quintela { 105809d6c965SJuan Quintela if (params->has_compress_level && 105909d6c965SJuan Quintela (params->compress_level > 9)) { 106009d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level", 106109d6c965SJuan Quintela "a value between 0 and 9"); 106209d6c965SJuan Quintela return false; 106309d6c965SJuan Quintela } 106409d6c965SJuan Quintela 106509d6c965SJuan Quintela if (params->has_compress_threads && (params->compress_threads < 1)) { 106609d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 106709d6c965SJuan Quintela "compress_threads", 106809d6c965SJuan Quintela "a value between 1 and 255"); 106909d6c965SJuan Quintela return false; 107009d6c965SJuan Quintela } 107109d6c965SJuan Quintela 107209d6c965SJuan Quintela if (params->has_decompress_threads && (params->decompress_threads < 1)) { 107309d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 107409d6c965SJuan Quintela "decompress_threads", 107509d6c965SJuan Quintela "a value between 1 and 255"); 107609d6c965SJuan Quintela return false; 107709d6c965SJuan Quintela } 107809d6c965SJuan Quintela 107909d6c965SJuan Quintela if (params->has_throttle_trigger_threshold && 108009d6c965SJuan Quintela (params->throttle_trigger_threshold < 1 || 108109d6c965SJuan Quintela params->throttle_trigger_threshold > 100)) { 108209d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 108309d6c965SJuan Quintela "throttle_trigger_threshold", 108409d6c965SJuan Quintela "an integer in the range of 1 to 100"); 108509d6c965SJuan Quintela return false; 108609d6c965SJuan Quintela } 108709d6c965SJuan Quintela 108809d6c965SJuan Quintela if (params->has_cpu_throttle_initial && 108909d6c965SJuan Quintela (params->cpu_throttle_initial < 1 || 109009d6c965SJuan Quintela params->cpu_throttle_initial > 99)) { 109109d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 109209d6c965SJuan Quintela "cpu_throttle_initial", 109309d6c965SJuan Quintela "an integer in the range of 1 to 99"); 109409d6c965SJuan Quintela return false; 109509d6c965SJuan Quintela } 109609d6c965SJuan Quintela 109709d6c965SJuan Quintela if (params->has_cpu_throttle_increment && 109809d6c965SJuan Quintela (params->cpu_throttle_increment < 1 || 109909d6c965SJuan Quintela params->cpu_throttle_increment > 99)) { 110009d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 110109d6c965SJuan Quintela "cpu_throttle_increment", 110209d6c965SJuan Quintela "an integer in the range of 1 to 99"); 110309d6c965SJuan Quintela return false; 110409d6c965SJuan Quintela } 110509d6c965SJuan Quintela 110609d6c965SJuan Quintela if (params->has_max_bandwidth && (params->max_bandwidth > SIZE_MAX)) { 110709d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 110809d6c965SJuan Quintela "max_bandwidth", 110909d6c965SJuan Quintela "an integer in the range of 0 to "stringify(SIZE_MAX) 111009d6c965SJuan Quintela " bytes/second"); 111109d6c965SJuan Quintela return false; 111209d6c965SJuan Quintela } 111309d6c965SJuan Quintela 11148b239597SPeter Xu if (params->has_avail_switchover_bandwidth && 11158b239597SPeter Xu (params->avail_switchover_bandwidth > SIZE_MAX)) { 11168b239597SPeter Xu error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 11178b239597SPeter Xu "avail_switchover_bandwidth", 11188b239597SPeter Xu "an integer in the range of 0 to "stringify(SIZE_MAX) 11198b239597SPeter Xu " bytes/second"); 11208b239597SPeter Xu return false; 11218b239597SPeter Xu } 11228b239597SPeter Xu 112309d6c965SJuan Quintela if (params->has_downtime_limit && 112409d6c965SJuan Quintela (params->downtime_limit > MAX_MIGRATE_DOWNTIME)) { 112509d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 112609d6c965SJuan Quintela "downtime_limit", 112709d6c965SJuan Quintela "an integer in the range of 0 to " 112809d6c965SJuan Quintela stringify(MAX_MIGRATE_DOWNTIME)" ms"); 112909d6c965SJuan Quintela return false; 113009d6c965SJuan Quintela } 113109d6c965SJuan Quintela 113209d6c965SJuan Quintela /* x_checkpoint_delay is now always positive */ 113309d6c965SJuan Quintela 113409d6c965SJuan Quintela if (params->has_multifd_channels && (params->multifd_channels < 1)) { 113509d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 113609d6c965SJuan Quintela "multifd_channels", 113709d6c965SJuan Quintela "a value between 1 and 255"); 113809d6c965SJuan Quintela return false; 113909d6c965SJuan Quintela } 114009d6c965SJuan Quintela 114109d6c965SJuan Quintela if (params->has_multifd_zlib_level && 114209d6c965SJuan Quintela (params->multifd_zlib_level > 9)) { 114309d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "multifd_zlib_level", 114409d6c965SJuan Quintela "a value between 0 and 9"); 114509d6c965SJuan Quintela return false; 114609d6c965SJuan Quintela } 114709d6c965SJuan Quintela 114809d6c965SJuan Quintela if (params->has_multifd_zstd_level && 114909d6c965SJuan Quintela (params->multifd_zstd_level > 20)) { 115009d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "multifd_zstd_level", 115109d6c965SJuan Quintela "a value between 0 and 20"); 115209d6c965SJuan Quintela return false; 115309d6c965SJuan Quintela } 115409d6c965SJuan Quintela 115509d6c965SJuan Quintela if (params->has_xbzrle_cache_size && 115609d6c965SJuan Quintela (params->xbzrle_cache_size < qemu_target_page_size() || 115709d6c965SJuan Quintela !is_power_of_2(params->xbzrle_cache_size))) { 115809d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 115909d6c965SJuan Quintela "xbzrle_cache_size", 116009d6c965SJuan Quintela "a power of two no less than the target page size"); 116109d6c965SJuan Quintela return false; 116209d6c965SJuan Quintela } 116309d6c965SJuan Quintela 116409d6c965SJuan Quintela if (params->has_max_cpu_throttle && 116509d6c965SJuan Quintela (params->max_cpu_throttle < params->cpu_throttle_initial || 116609d6c965SJuan Quintela params->max_cpu_throttle > 99)) { 116709d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 116809d6c965SJuan Quintela "max_cpu_throttle", 116909d6c965SJuan Quintela "an integer in the range of cpu_throttle_initial to 99"); 117009d6c965SJuan Quintela return false; 117109d6c965SJuan Quintela } 117209d6c965SJuan Quintela 117309d6c965SJuan Quintela if (params->has_announce_initial && 117409d6c965SJuan Quintela params->announce_initial > 100000) { 117509d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 117609d6c965SJuan Quintela "announce_initial", 117709d6c965SJuan Quintela "a value between 0 and 100000"); 117809d6c965SJuan Quintela return false; 117909d6c965SJuan Quintela } 118009d6c965SJuan Quintela if (params->has_announce_max && 118109d6c965SJuan Quintela params->announce_max > 100000) { 118209d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 118309d6c965SJuan Quintela "announce_max", 118409d6c965SJuan Quintela "a value between 0 and 100000"); 118509d6c965SJuan Quintela return false; 118609d6c965SJuan Quintela } 118709d6c965SJuan Quintela if (params->has_announce_rounds && 118809d6c965SJuan Quintela params->announce_rounds > 1000) { 118909d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 119009d6c965SJuan Quintela "announce_rounds", 119109d6c965SJuan Quintela "a value between 0 and 1000"); 119209d6c965SJuan Quintela return false; 119309d6c965SJuan Quintela } 119409d6c965SJuan Quintela if (params->has_announce_step && 119509d6c965SJuan Quintela (params->announce_step < 1 || 119609d6c965SJuan Quintela params->announce_step > 10000)) { 119709d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 119809d6c965SJuan Quintela "announce_step", 119909d6c965SJuan Quintela "a value between 0 and 10000"); 120009d6c965SJuan Quintela return false; 120109d6c965SJuan Quintela } 120209d6c965SJuan Quintela 120309d6c965SJuan Quintela if (params->has_block_bitmap_mapping && 120409d6c965SJuan Quintela !check_dirty_bitmap_mig_alias_map(params->block_bitmap_mapping, errp)) { 120509d6c965SJuan Quintela error_prepend(errp, "Invalid mapping given for block-bitmap-mapping: "); 120609d6c965SJuan Quintela return false; 120709d6c965SJuan Quintela } 120809d6c965SJuan Quintela 120909d6c965SJuan Quintela #ifdef CONFIG_LINUX 121009d6c965SJuan Quintela if (migrate_zero_copy_send() && 121109d6c965SJuan Quintela ((params->has_multifd_compression && params->multifd_compression) || 121209d6c965SJuan Quintela (params->tls_creds && *params->tls_creds))) { 121309d6c965SJuan Quintela error_setg(errp, 121409d6c965SJuan Quintela "Zero copy only available for non-compressed non-TLS multifd migration"); 121509d6c965SJuan Quintela return false; 121609d6c965SJuan Quintela } 121709d6c965SJuan Quintela #endif 121809d6c965SJuan Quintela 12194d807857SHyman Huang(黄勇) if (params->has_x_vcpu_dirty_limit_period && 12204d807857SHyman Huang(黄勇) (params->x_vcpu_dirty_limit_period < 1 || 12214d807857SHyman Huang(黄勇) params->x_vcpu_dirty_limit_period > 1000)) { 12224d807857SHyman Huang(黄勇) error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 12234d807857SHyman Huang(黄勇) "x-vcpu-dirty-limit-period", 12244d807857SHyman Huang(黄勇) "a value between 1 and 1000"); 12254d807857SHyman Huang(黄勇) return false; 12264d807857SHyman Huang(黄勇) } 12274d807857SHyman Huang(黄勇) 122809f9ec99SHyman Huang(黄勇) if (params->has_vcpu_dirty_limit && 122909f9ec99SHyman Huang(黄勇) (params->vcpu_dirty_limit < 1)) { 123009f9ec99SHyman Huang(黄勇) error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 123109f9ec99SHyman Huang(黄勇) "vcpu_dirty_limit", 123209f9ec99SHyman Huang(黄勇) "is invalid, it must greater then 1 MB/s"); 123309f9ec99SHyman Huang(黄勇) return false; 123409f9ec99SHyman Huang(黄勇) } 123509f9ec99SHyman Huang(黄勇) 123609d6c965SJuan Quintela return true; 123709d6c965SJuan Quintela } 123809d6c965SJuan Quintela 123909d6c965SJuan Quintela static void migrate_params_test_apply(MigrateSetParameters *params, 124009d6c965SJuan Quintela MigrationParameters *dest) 124109d6c965SJuan Quintela { 124209d6c965SJuan Quintela *dest = migrate_get_current()->parameters; 124309d6c965SJuan Quintela 124409d6c965SJuan Quintela /* TODO use QAPI_CLONE() instead of duplicating it inline */ 124509d6c965SJuan Quintela 124609d6c965SJuan Quintela if (params->has_compress_level) { 124709d6c965SJuan Quintela dest->compress_level = params->compress_level; 124809d6c965SJuan Quintela } 124909d6c965SJuan Quintela 125009d6c965SJuan Quintela if (params->has_compress_threads) { 125109d6c965SJuan Quintela dest->compress_threads = params->compress_threads; 125209d6c965SJuan Quintela } 125309d6c965SJuan Quintela 125409d6c965SJuan Quintela if (params->has_compress_wait_thread) { 125509d6c965SJuan Quintela dest->compress_wait_thread = params->compress_wait_thread; 125609d6c965SJuan Quintela } 125709d6c965SJuan Quintela 125809d6c965SJuan Quintela if (params->has_decompress_threads) { 125909d6c965SJuan Quintela dest->decompress_threads = params->decompress_threads; 126009d6c965SJuan Quintela } 126109d6c965SJuan Quintela 126209d6c965SJuan Quintela if (params->has_throttle_trigger_threshold) { 126309d6c965SJuan Quintela dest->throttle_trigger_threshold = params->throttle_trigger_threshold; 126409d6c965SJuan Quintela } 126509d6c965SJuan Quintela 126609d6c965SJuan Quintela if (params->has_cpu_throttle_initial) { 126709d6c965SJuan Quintela dest->cpu_throttle_initial = params->cpu_throttle_initial; 126809d6c965SJuan Quintela } 126909d6c965SJuan Quintela 127009d6c965SJuan Quintela if (params->has_cpu_throttle_increment) { 127109d6c965SJuan Quintela dest->cpu_throttle_increment = params->cpu_throttle_increment; 127209d6c965SJuan Quintela } 127309d6c965SJuan Quintela 127409d6c965SJuan Quintela if (params->has_cpu_throttle_tailslow) { 127509d6c965SJuan Quintela dest->cpu_throttle_tailslow = params->cpu_throttle_tailslow; 127609d6c965SJuan Quintela } 127709d6c965SJuan Quintela 127809d6c965SJuan Quintela if (params->tls_creds) { 127909d6c965SJuan Quintela assert(params->tls_creds->type == QTYPE_QSTRING); 128009d6c965SJuan Quintela dest->tls_creds = params->tls_creds->u.s; 128109d6c965SJuan Quintela } 128209d6c965SJuan Quintela 128309d6c965SJuan Quintela if (params->tls_hostname) { 128409d6c965SJuan Quintela assert(params->tls_hostname->type == QTYPE_QSTRING); 128509d6c965SJuan Quintela dest->tls_hostname = params->tls_hostname->u.s; 128609d6c965SJuan Quintela } 128709d6c965SJuan Quintela 128809d6c965SJuan Quintela if (params->has_max_bandwidth) { 128909d6c965SJuan Quintela dest->max_bandwidth = params->max_bandwidth; 129009d6c965SJuan Quintela } 129109d6c965SJuan Quintela 12928b239597SPeter Xu if (params->has_avail_switchover_bandwidth) { 12938b239597SPeter Xu dest->avail_switchover_bandwidth = params->avail_switchover_bandwidth; 12948b239597SPeter Xu } 12958b239597SPeter Xu 129609d6c965SJuan Quintela if (params->has_downtime_limit) { 129709d6c965SJuan Quintela dest->downtime_limit = params->downtime_limit; 129809d6c965SJuan Quintela } 129909d6c965SJuan Quintela 130009d6c965SJuan Quintela if (params->has_x_checkpoint_delay) { 130109d6c965SJuan Quintela dest->x_checkpoint_delay = params->x_checkpoint_delay; 130209d6c965SJuan Quintela } 130309d6c965SJuan Quintela 130409d6c965SJuan Quintela if (params->has_block_incremental) { 130509d6c965SJuan Quintela dest->block_incremental = params->block_incremental; 130609d6c965SJuan Quintela } 130709d6c965SJuan Quintela if (params->has_multifd_channels) { 130809d6c965SJuan Quintela dest->multifd_channels = params->multifd_channels; 130909d6c965SJuan Quintela } 131009d6c965SJuan Quintela if (params->has_multifd_compression) { 131109d6c965SJuan Quintela dest->multifd_compression = params->multifd_compression; 131209d6c965SJuan Quintela } 131309d6c965SJuan Quintela if (params->has_xbzrle_cache_size) { 131409d6c965SJuan Quintela dest->xbzrle_cache_size = params->xbzrle_cache_size; 131509d6c965SJuan Quintela } 131609d6c965SJuan Quintela if (params->has_max_postcopy_bandwidth) { 131709d6c965SJuan Quintela dest->max_postcopy_bandwidth = params->max_postcopy_bandwidth; 131809d6c965SJuan Quintela } 131909d6c965SJuan Quintela if (params->has_max_cpu_throttle) { 132009d6c965SJuan Quintela dest->max_cpu_throttle = params->max_cpu_throttle; 132109d6c965SJuan Quintela } 132209d6c965SJuan Quintela if (params->has_announce_initial) { 132309d6c965SJuan Quintela dest->announce_initial = params->announce_initial; 132409d6c965SJuan Quintela } 132509d6c965SJuan Quintela if (params->has_announce_max) { 132609d6c965SJuan Quintela dest->announce_max = params->announce_max; 132709d6c965SJuan Quintela } 132809d6c965SJuan Quintela if (params->has_announce_rounds) { 132909d6c965SJuan Quintela dest->announce_rounds = params->announce_rounds; 133009d6c965SJuan Quintela } 133109d6c965SJuan Quintela if (params->has_announce_step) { 133209d6c965SJuan Quintela dest->announce_step = params->announce_step; 133309d6c965SJuan Quintela } 133409d6c965SJuan Quintela 133509d6c965SJuan Quintela if (params->has_block_bitmap_mapping) { 133609d6c965SJuan Quintela dest->has_block_bitmap_mapping = true; 133709d6c965SJuan Quintela dest->block_bitmap_mapping = params->block_bitmap_mapping; 133809d6c965SJuan Quintela } 13394d807857SHyman Huang(黄勇) 13404d807857SHyman Huang(黄勇) if (params->has_x_vcpu_dirty_limit_period) { 13414d807857SHyman Huang(黄勇) dest->x_vcpu_dirty_limit_period = 13424d807857SHyman Huang(黄勇) params->x_vcpu_dirty_limit_period; 13434d807857SHyman Huang(黄勇) } 134409f9ec99SHyman Huang(黄勇) if (params->has_vcpu_dirty_limit) { 134509f9ec99SHyman Huang(黄勇) dest->vcpu_dirty_limit = params->vcpu_dirty_limit; 134609f9ec99SHyman Huang(黄勇) } 1347*eea1e5c9SSteve Sistare 1348*eea1e5c9SSteve Sistare if (params->has_mode) { 1349*eea1e5c9SSteve Sistare dest->mode = params->mode; 1350*eea1e5c9SSteve Sistare } 135109d6c965SJuan Quintela } 135209d6c965SJuan Quintela 135309d6c965SJuan Quintela static void migrate_params_apply(MigrateSetParameters *params, Error **errp) 135409d6c965SJuan Quintela { 135509d6c965SJuan Quintela MigrationState *s = migrate_get_current(); 135609d6c965SJuan Quintela 135709d6c965SJuan Quintela /* TODO use QAPI_CLONE() instead of duplicating it inline */ 135809d6c965SJuan Quintela 135909d6c965SJuan Quintela if (params->has_compress_level) { 1360864128dfSJuan Quintela warn_report("old compression is deprecated;" 1361864128dfSJuan Quintela " use multifd compression methods instead"); 136209d6c965SJuan Quintela s->parameters.compress_level = params->compress_level; 136309d6c965SJuan Quintela } 136409d6c965SJuan Quintela 136509d6c965SJuan Quintela if (params->has_compress_threads) { 1366864128dfSJuan Quintela warn_report("old compression is deprecated;" 1367864128dfSJuan Quintela " use multifd compression methods instead"); 136809d6c965SJuan Quintela s->parameters.compress_threads = params->compress_threads; 136909d6c965SJuan Quintela } 137009d6c965SJuan Quintela 137109d6c965SJuan Quintela if (params->has_compress_wait_thread) { 1372864128dfSJuan Quintela warn_report("old compression is deprecated;" 1373864128dfSJuan Quintela " use multifd compression methods instead"); 137409d6c965SJuan Quintela s->parameters.compress_wait_thread = params->compress_wait_thread; 137509d6c965SJuan Quintela } 137609d6c965SJuan Quintela 137709d6c965SJuan Quintela if (params->has_decompress_threads) { 1378864128dfSJuan Quintela warn_report("old compression is deprecated;" 1379864128dfSJuan Quintela " use multifd compression methods instead"); 138009d6c965SJuan Quintela s->parameters.decompress_threads = params->decompress_threads; 138109d6c965SJuan Quintela } 138209d6c965SJuan Quintela 138309d6c965SJuan Quintela if (params->has_throttle_trigger_threshold) { 138409d6c965SJuan Quintela s->parameters.throttle_trigger_threshold = params->throttle_trigger_threshold; 138509d6c965SJuan Quintela } 138609d6c965SJuan Quintela 138709d6c965SJuan Quintela if (params->has_cpu_throttle_initial) { 138809d6c965SJuan Quintela s->parameters.cpu_throttle_initial = params->cpu_throttle_initial; 138909d6c965SJuan Quintela } 139009d6c965SJuan Quintela 139109d6c965SJuan Quintela if (params->has_cpu_throttle_increment) { 139209d6c965SJuan Quintela s->parameters.cpu_throttle_increment = params->cpu_throttle_increment; 139309d6c965SJuan Quintela } 139409d6c965SJuan Quintela 139509d6c965SJuan Quintela if (params->has_cpu_throttle_tailslow) { 139609d6c965SJuan Quintela s->parameters.cpu_throttle_tailslow = params->cpu_throttle_tailslow; 139709d6c965SJuan Quintela } 139809d6c965SJuan Quintela 139909d6c965SJuan Quintela if (params->tls_creds) { 140009d6c965SJuan Quintela g_free(s->parameters.tls_creds); 140109d6c965SJuan Quintela assert(params->tls_creds->type == QTYPE_QSTRING); 140209d6c965SJuan Quintela s->parameters.tls_creds = g_strdup(params->tls_creds->u.s); 140309d6c965SJuan Quintela } 140409d6c965SJuan Quintela 140509d6c965SJuan Quintela if (params->tls_hostname) { 140609d6c965SJuan Quintela g_free(s->parameters.tls_hostname); 140709d6c965SJuan Quintela assert(params->tls_hostname->type == QTYPE_QSTRING); 140809d6c965SJuan Quintela s->parameters.tls_hostname = g_strdup(params->tls_hostname->u.s); 140909d6c965SJuan Quintela } 141009d6c965SJuan Quintela 141109d6c965SJuan Quintela if (params->tls_authz) { 141209d6c965SJuan Quintela g_free(s->parameters.tls_authz); 141309d6c965SJuan Quintela assert(params->tls_authz->type == QTYPE_QSTRING); 141409d6c965SJuan Quintela s->parameters.tls_authz = g_strdup(params->tls_authz->u.s); 141509d6c965SJuan Quintela } 141609d6c965SJuan Quintela 141709d6c965SJuan Quintela if (params->has_max_bandwidth) { 141809d6c965SJuan Quintela s->parameters.max_bandwidth = params->max_bandwidth; 141909d6c965SJuan Quintela if (s->to_dst_file && !migration_in_postcopy()) { 1420e1fde0e0SJuan Quintela migration_rate_set(s->parameters.max_bandwidth); 142109d6c965SJuan Quintela } 142209d6c965SJuan Quintela } 142309d6c965SJuan Quintela 14248b239597SPeter Xu if (params->has_avail_switchover_bandwidth) { 14258b239597SPeter Xu s->parameters.avail_switchover_bandwidth = params->avail_switchover_bandwidth; 14268b239597SPeter Xu } 14278b239597SPeter Xu 142809d6c965SJuan Quintela if (params->has_downtime_limit) { 142909d6c965SJuan Quintela s->parameters.downtime_limit = params->downtime_limit; 143009d6c965SJuan Quintela } 143109d6c965SJuan Quintela 143209d6c965SJuan Quintela if (params->has_x_checkpoint_delay) { 143309d6c965SJuan Quintela s->parameters.x_checkpoint_delay = params->x_checkpoint_delay; 14344332ffcdSVladimir Sementsov-Ogievskiy colo_checkpoint_delay_set(); 143509d6c965SJuan Quintela } 143609d6c965SJuan Quintela 143709d6c965SJuan Quintela if (params->has_block_incremental) { 143866db46caSJuan Quintela warn_report("block migration is deprecated;" 143966db46caSJuan Quintela " use blockdev-mirror with NBD instead"); 144009d6c965SJuan Quintela s->parameters.block_incremental = params->block_incremental; 144109d6c965SJuan Quintela } 144209d6c965SJuan Quintela if (params->has_multifd_channels) { 144309d6c965SJuan Quintela s->parameters.multifd_channels = params->multifd_channels; 144409d6c965SJuan Quintela } 144509d6c965SJuan Quintela if (params->has_multifd_compression) { 144609d6c965SJuan Quintela s->parameters.multifd_compression = params->multifd_compression; 144709d6c965SJuan Quintela } 144809d6c965SJuan Quintela if (params->has_xbzrle_cache_size) { 144909d6c965SJuan Quintela s->parameters.xbzrle_cache_size = params->xbzrle_cache_size; 145009d6c965SJuan Quintela xbzrle_cache_resize(params->xbzrle_cache_size, errp); 145109d6c965SJuan Quintela } 145209d6c965SJuan Quintela if (params->has_max_postcopy_bandwidth) { 145309d6c965SJuan Quintela s->parameters.max_postcopy_bandwidth = params->max_postcopy_bandwidth; 145409d6c965SJuan Quintela if (s->to_dst_file && migration_in_postcopy()) { 1455e1fde0e0SJuan Quintela migration_rate_set(s->parameters.max_postcopy_bandwidth); 145609d6c965SJuan Quintela } 145709d6c965SJuan Quintela } 145809d6c965SJuan Quintela if (params->has_max_cpu_throttle) { 145909d6c965SJuan Quintela s->parameters.max_cpu_throttle = params->max_cpu_throttle; 146009d6c965SJuan Quintela } 146109d6c965SJuan Quintela if (params->has_announce_initial) { 146209d6c965SJuan Quintela s->parameters.announce_initial = params->announce_initial; 146309d6c965SJuan Quintela } 146409d6c965SJuan Quintela if (params->has_announce_max) { 146509d6c965SJuan Quintela s->parameters.announce_max = params->announce_max; 146609d6c965SJuan Quintela } 146709d6c965SJuan Quintela if (params->has_announce_rounds) { 146809d6c965SJuan Quintela s->parameters.announce_rounds = params->announce_rounds; 146909d6c965SJuan Quintela } 147009d6c965SJuan Quintela if (params->has_announce_step) { 147109d6c965SJuan Quintela s->parameters.announce_step = params->announce_step; 147209d6c965SJuan Quintela } 147309d6c965SJuan Quintela 147409d6c965SJuan Quintela if (params->has_block_bitmap_mapping) { 147509d6c965SJuan Quintela qapi_free_BitmapMigrationNodeAliasList( 147609d6c965SJuan Quintela s->parameters.block_bitmap_mapping); 147709d6c965SJuan Quintela 147809d6c965SJuan Quintela s->parameters.has_block_bitmap_mapping = true; 147909d6c965SJuan Quintela s->parameters.block_bitmap_mapping = 148009d6c965SJuan Quintela QAPI_CLONE(BitmapMigrationNodeAliasList, 148109d6c965SJuan Quintela params->block_bitmap_mapping); 148209d6c965SJuan Quintela } 14834d807857SHyman Huang(黄勇) 14844d807857SHyman Huang(黄勇) if (params->has_x_vcpu_dirty_limit_period) { 14854d807857SHyman Huang(黄勇) s->parameters.x_vcpu_dirty_limit_period = 14864d807857SHyman Huang(黄勇) params->x_vcpu_dirty_limit_period; 14874d807857SHyman Huang(黄勇) } 148809f9ec99SHyman Huang(黄勇) if (params->has_vcpu_dirty_limit) { 148909f9ec99SHyman Huang(黄勇) s->parameters.vcpu_dirty_limit = params->vcpu_dirty_limit; 149009f9ec99SHyman Huang(黄勇) } 1491*eea1e5c9SSteve Sistare 1492*eea1e5c9SSteve Sistare if (params->has_mode) { 1493*eea1e5c9SSteve Sistare s->parameters.mode = params->mode; 1494*eea1e5c9SSteve Sistare } 149509d6c965SJuan Quintela } 149609d6c965SJuan Quintela 149709d6c965SJuan Quintela void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp) 149809d6c965SJuan Quintela { 149909d6c965SJuan Quintela MigrationParameters tmp; 150009d6c965SJuan Quintela 150186dec715SPeter Xu /* TODO Rewrite "" to null instead for all three tls_* parameters */ 150209d6c965SJuan Quintela if (params->tls_creds 150309d6c965SJuan Quintela && params->tls_creds->type == QTYPE_QNULL) { 150409d6c965SJuan Quintela qobject_unref(params->tls_creds->u.n); 150509d6c965SJuan Quintela params->tls_creds->type = QTYPE_QSTRING; 150609d6c965SJuan Quintela params->tls_creds->u.s = strdup(""); 150709d6c965SJuan Quintela } 150809d6c965SJuan Quintela if (params->tls_hostname 150909d6c965SJuan Quintela && params->tls_hostname->type == QTYPE_QNULL) { 151009d6c965SJuan Quintela qobject_unref(params->tls_hostname->u.n); 151109d6c965SJuan Quintela params->tls_hostname->type = QTYPE_QSTRING; 151209d6c965SJuan Quintela params->tls_hostname->u.s = strdup(""); 151309d6c965SJuan Quintela } 151486dec715SPeter Xu if (params->tls_authz 151586dec715SPeter Xu && params->tls_authz->type == QTYPE_QNULL) { 151686dec715SPeter Xu qobject_unref(params->tls_authz->u.n); 151786dec715SPeter Xu params->tls_authz->type = QTYPE_QSTRING; 151886dec715SPeter Xu params->tls_authz->u.s = strdup(""); 151986dec715SPeter Xu } 152009d6c965SJuan Quintela 152109d6c965SJuan Quintela migrate_params_test_apply(params, &tmp); 152209d6c965SJuan Quintela 152309d6c965SJuan Quintela if (!migrate_params_check(&tmp, errp)) { 152409d6c965SJuan Quintela /* Invalid parameter */ 152509d6c965SJuan Quintela return; 152609d6c965SJuan Quintela } 152709d6c965SJuan Quintela 152809d6c965SJuan Quintela migrate_params_apply(params, errp); 152909d6c965SJuan Quintela } 1530