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 /* Define default autoconverge cpu throttle migration parameters */
44f9436522SJuan Quintela #define DEFAULT_MIGRATE_THROTTLE_TRIGGER_THRESHOLD 50
45f9436522SJuan Quintela #define DEFAULT_MIGRATE_CPU_THROTTLE_INITIAL 20
46f9436522SJuan Quintela #define DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT 10
47f9436522SJuan Quintela #define DEFAULT_MIGRATE_MAX_CPU_THROTTLE 99
48f9436522SJuan Quintela
49f9436522SJuan Quintela /* Migration XBZRLE default cache size */
50f9436522SJuan Quintela #define DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE (64 * 1024 * 1024)
51f9436522SJuan Quintela
52f9436522SJuan Quintela /* The delay time (in ms) between two COLO checkpoints */
53f9436522SJuan Quintela #define DEFAULT_MIGRATE_X_CHECKPOINT_DELAY (200 * 100)
54f9436522SJuan Quintela #define DEFAULT_MIGRATE_MULTIFD_CHANNELS 2
55f9436522SJuan Quintela #define DEFAULT_MIGRATE_MULTIFD_COMPRESSION MULTIFD_COMPRESSION_NONE
56f9436522SJuan Quintela /* 0: means nocompress, 1: best speed, ... 9: best compress ratio */
57f9436522SJuan Quintela #define DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL 1
5886c6eb1fSBryan Zhang /*
5986c6eb1fSBryan Zhang * 1: best speed, ... 9: best compress ratio
6086c6eb1fSBryan Zhang * There is some nuance here. Refer to QATzip documentation to understand
6186c6eb1fSBryan Zhang * the mapping of QATzip levels to standard deflate levels.
6286c6eb1fSBryan Zhang */
6386c6eb1fSBryan Zhang #define DEFAULT_MIGRATE_MULTIFD_QATZIP_LEVEL 1
6486c6eb1fSBryan Zhang
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),
9577c259a4SJuan Quintela DEFINE_PROP_BOOL("multifd-flush-after-each-section", MigrationState,
96294e5a40SJuan Quintela multifd_flush_after_each_section, false),
97f9436522SJuan Quintela DEFINE_PROP_UINT8("x-clear-bitmap-shift", MigrationState,
98f9436522SJuan Quintela clear_bitmap_shift, CLEAR_BITMAP_SHIFT_DEFAULT),
99f9436522SJuan Quintela DEFINE_PROP_BOOL("x-preempt-pre-7-2", MigrationState,
100f9436522SJuan Quintela preempt_pre_7_2, false),
101f9436522SJuan Quintela
102f9436522SJuan Quintela /* Migration parameters */
103f9436522SJuan Quintela DEFINE_PROP_UINT8("x-throttle-trigger-threshold", MigrationState,
104f9436522SJuan Quintela parameters.throttle_trigger_threshold,
105f9436522SJuan Quintela DEFAULT_MIGRATE_THROTTLE_TRIGGER_THRESHOLD),
106f9436522SJuan Quintela DEFINE_PROP_UINT8("x-cpu-throttle-initial", MigrationState,
107f9436522SJuan Quintela parameters.cpu_throttle_initial,
108f9436522SJuan Quintela DEFAULT_MIGRATE_CPU_THROTTLE_INITIAL),
109f9436522SJuan Quintela DEFINE_PROP_UINT8("x-cpu-throttle-increment", MigrationState,
110f9436522SJuan Quintela parameters.cpu_throttle_increment,
111f9436522SJuan Quintela DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT),
112f9436522SJuan Quintela DEFINE_PROP_BOOL("x-cpu-throttle-tailslow", MigrationState,
113f9436522SJuan Quintela parameters.cpu_throttle_tailslow, false),
114f9436522SJuan Quintela DEFINE_PROP_SIZE("x-max-bandwidth", MigrationState,
115f9436522SJuan Quintela parameters.max_bandwidth, MAX_THROTTLE),
1168b239597SPeter Xu DEFINE_PROP_SIZE("avail-switchover-bandwidth", MigrationState,
1178b239597SPeter Xu parameters.avail_switchover_bandwidth, 0),
118f9436522SJuan Quintela DEFINE_PROP_UINT64("x-downtime-limit", MigrationState,
119f9436522SJuan Quintela parameters.downtime_limit,
120f9436522SJuan Quintela DEFAULT_MIGRATE_SET_DOWNTIME),
121f9436522SJuan Quintela DEFINE_PROP_UINT32("x-checkpoint-delay", MigrationState,
122f9436522SJuan Quintela parameters.x_checkpoint_delay,
123f9436522SJuan Quintela DEFAULT_MIGRATE_X_CHECKPOINT_DELAY),
124f9436522SJuan Quintela DEFINE_PROP_UINT8("multifd-channels", MigrationState,
125f9436522SJuan Quintela parameters.multifd_channels,
126f9436522SJuan Quintela DEFAULT_MIGRATE_MULTIFD_CHANNELS),
127f9436522SJuan Quintela DEFINE_PROP_MULTIFD_COMPRESSION("multifd-compression", MigrationState,
128f9436522SJuan Quintela parameters.multifd_compression,
129f9436522SJuan Quintela DEFAULT_MIGRATE_MULTIFD_COMPRESSION),
130f9436522SJuan Quintela DEFINE_PROP_UINT8("multifd-zlib-level", MigrationState,
131f9436522SJuan Quintela parameters.multifd_zlib_level,
132f9436522SJuan Quintela DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL),
13386c6eb1fSBryan Zhang DEFINE_PROP_UINT8("multifd-qatzip-level", MigrationState,
13486c6eb1fSBryan Zhang parameters.multifd_qatzip_level,
13586c6eb1fSBryan Zhang DEFAULT_MIGRATE_MULTIFD_QATZIP_LEVEL),
136f9436522SJuan Quintela DEFINE_PROP_UINT8("multifd-zstd-level", MigrationState,
137f9436522SJuan Quintela parameters.multifd_zstd_level,
138f9436522SJuan Quintela DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL),
139f9436522SJuan Quintela DEFINE_PROP_SIZE("xbzrle-cache-size", MigrationState,
140f9436522SJuan Quintela parameters.xbzrle_cache_size,
141f9436522SJuan Quintela DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE),
142f9436522SJuan Quintela DEFINE_PROP_SIZE("max-postcopy-bandwidth", MigrationState,
143f9436522SJuan Quintela parameters.max_postcopy_bandwidth,
144f9436522SJuan Quintela DEFAULT_MIGRATE_MAX_POSTCOPY_BANDWIDTH),
145f9436522SJuan Quintela DEFINE_PROP_UINT8("max-cpu-throttle", MigrationState,
146f9436522SJuan Quintela parameters.max_cpu_throttle,
147f9436522SJuan Quintela DEFAULT_MIGRATE_MAX_CPU_THROTTLE),
148f9436522SJuan Quintela DEFINE_PROP_SIZE("announce-initial", MigrationState,
149f9436522SJuan Quintela parameters.announce_initial,
150f9436522SJuan Quintela DEFAULT_MIGRATE_ANNOUNCE_INITIAL),
151f9436522SJuan Quintela DEFINE_PROP_SIZE("announce-max", MigrationState,
152f9436522SJuan Quintela parameters.announce_max,
153f9436522SJuan Quintela DEFAULT_MIGRATE_ANNOUNCE_MAX),
154f9436522SJuan Quintela DEFINE_PROP_SIZE("announce-rounds", MigrationState,
155f9436522SJuan Quintela parameters.announce_rounds,
156f9436522SJuan Quintela DEFAULT_MIGRATE_ANNOUNCE_ROUNDS),
157f9436522SJuan Quintela DEFINE_PROP_SIZE("announce-step", MigrationState,
158f9436522SJuan Quintela parameters.announce_step,
159f9436522SJuan Quintela DEFAULT_MIGRATE_ANNOUNCE_STEP),
160f9436522SJuan Quintela DEFINE_PROP_STRING("tls-creds", MigrationState, parameters.tls_creds),
161f9436522SJuan Quintela DEFINE_PROP_STRING("tls-hostname", MigrationState, parameters.tls_hostname),
162f9436522SJuan Quintela DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz),
1634d807857SHyman Huang(黄勇) DEFINE_PROP_UINT64("x-vcpu-dirty-limit-period", MigrationState,
1644d807857SHyman Huang(黄勇) parameters.x_vcpu_dirty_limit_period,
1654d807857SHyman Huang(黄勇) DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD),
16609f9ec99SHyman Huang(黄勇) DEFINE_PROP_UINT64("vcpu-dirty-limit", MigrationState,
16709f9ec99SHyman Huang(黄勇) parameters.vcpu_dirty_limit,
16809f9ec99SHyman Huang(黄勇) DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT),
169eea1e5c9SSteve Sistare DEFINE_PROP_MIG_MODE("mode", MigrationState,
170eea1e5c9SSteve Sistare parameters.mode,
171eea1e5c9SSteve Sistare MIG_MODE_NORMAL),
1725fdbb1dfSHao Xiang DEFINE_PROP_ZERO_PAGE_DETECTION("zero-page-detection", MigrationState,
1735fdbb1dfSHao Xiang parameters.zero_page_detection,
17470c25c92SHao Xiang ZERO_PAGE_DETECTION_MULTIFD),
175f9436522SJuan Quintela
176f9436522SJuan Quintela /* Migration capabilities */
177f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE),
178f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-rdma-pin-all", MIGRATION_CAPABILITY_RDMA_PIN_ALL),
179f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-auto-converge", MIGRATION_CAPABILITY_AUTO_CONVERGE),
180f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-zero-blocks", MIGRATION_CAPABILITY_ZERO_BLOCKS),
181f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-events", MIGRATION_CAPABILITY_EVENTS),
182f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-postcopy-ram", MIGRATION_CAPABILITY_POSTCOPY_RAM),
183f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-postcopy-preempt",
184f9436522SJuan Quintela MIGRATION_CAPABILITY_POSTCOPY_PREEMPT),
185f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-colo", MIGRATION_CAPABILITY_X_COLO),
186f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-release-ram", MIGRATION_CAPABILITY_RELEASE_RAM),
187f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-return-path", MIGRATION_CAPABILITY_RETURN_PATH),
188f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-multifd", MIGRATION_CAPABILITY_MULTIFD),
189f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-background-snapshot",
190f9436522SJuan Quintela MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT),
191f9436522SJuan Quintela #ifdef CONFIG_LINUX
192f9436522SJuan Quintela DEFINE_PROP_MIG_CAP("x-zero-copy-send",
193f9436522SJuan Quintela MIGRATION_CAPABILITY_ZERO_COPY_SEND),
194f9436522SJuan Quintela #endif
1956574232fSAvihai Horon DEFINE_PROP_MIG_CAP("x-switchover-ack",
1966574232fSAvihai Horon MIGRATION_CAPABILITY_SWITCHOVER_ACK),
197dc623955SHyman Huang(黄勇) DEFINE_PROP_MIG_CAP("x-dirty-limit", MIGRATION_CAPABILITY_DIRTY_LIMIT),
1984ed49febSFabiano Rosas DEFINE_PROP_MIG_CAP("mapped-ram", MIGRATION_CAPABILITY_MAPPED_RAM),
199f9436522SJuan Quintela DEFINE_PROP_END_OF_LIST(),
200f9436522SJuan Quintela };
201f9436522SJuan Quintela
migrate_auto_converge(void)2021f0776f1SJuan Quintela bool migrate_auto_converge(void)
2031f0776f1SJuan Quintela {
2048f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
2051f0776f1SJuan Quintela
2061f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_AUTO_CONVERGE];
2071f0776f1SJuan Quintela }
2081f0776f1SJuan Quintela
migrate_background_snapshot(void)2091f0776f1SJuan Quintela bool migrate_background_snapshot(void)
2101f0776f1SJuan Quintela {
2118f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
2121f0776f1SJuan Quintela
2131f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT];
2141f0776f1SJuan Quintela }
2151f0776f1SJuan Quintela
migrate_colo(void)2165e804644SJuan Quintela bool migrate_colo(void)
2175e804644SJuan Quintela {
2185e804644SJuan Quintela MigrationState *s = migrate_get_current();
2198f9c5327SJuan Quintela
2205e804644SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_X_COLO];
2215e804644SJuan Quintela }
2225e804644SJuan Quintela
migrate_dirty_bitmaps(void)2231f0776f1SJuan Quintela bool migrate_dirty_bitmaps(void)
2241f0776f1SJuan Quintela {
2258f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
2261f0776f1SJuan Quintela
2271f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_DIRTY_BITMAPS];
2281f0776f1SJuan Quintela }
2291f0776f1SJuan Quintela
migrate_dirty_limit(void)230dc623955SHyman Huang(黄勇) bool migrate_dirty_limit(void)
231dc623955SHyman Huang(黄勇) {
232dc623955SHyman Huang(黄勇) MigrationState *s = migrate_get_current();
233dc623955SHyman Huang(黄勇)
234dc623955SHyman Huang(黄勇) return s->capabilities[MIGRATION_CAPABILITY_DIRTY_LIMIT];
235dc623955SHyman Huang(黄勇) }
236dc623955SHyman Huang(黄勇)
migrate_events(void)237b890902cSJuan Quintela bool migrate_events(void)
238b890902cSJuan Quintela {
2398f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
240b890902cSJuan Quintela
241b890902cSJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_EVENTS];
242b890902cSJuan Quintela }
243b890902cSJuan Quintela
migrate_mapped_ram(void)2444ed49febSFabiano Rosas bool migrate_mapped_ram(void)
2454ed49febSFabiano Rosas {
2464ed49febSFabiano Rosas MigrationState *s = migrate_get_current();
2474ed49febSFabiano Rosas
2484ed49febSFabiano Rosas return s->capabilities[MIGRATION_CAPABILITY_MAPPED_RAM];
2494ed49febSFabiano Rosas }
2504ed49febSFabiano Rosas
migrate_ignore_shared(void)2511f0776f1SJuan Quintela bool migrate_ignore_shared(void)
2521f0776f1SJuan Quintela {
2538f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
2541f0776f1SJuan Quintela
2551f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_X_IGNORE_SHARED];
2561f0776f1SJuan Quintela }
2571f0776f1SJuan Quintela
migrate_late_block_activate(void)2581f0776f1SJuan Quintela bool migrate_late_block_activate(void)
2591f0776f1SJuan Quintela {
2608f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
2611f0776f1SJuan Quintela
2621f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE];
2631f0776f1SJuan Quintela }
2641f0776f1SJuan Quintela
migrate_multifd(void)26551b07548SJuan Quintela bool migrate_multifd(void)
26651b07548SJuan Quintela {
2678f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
26851b07548SJuan Quintela
26951b07548SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_MULTIFD];
27051b07548SJuan Quintela }
27151b07548SJuan Quintela
migrate_pause_before_switchover(void)2721f0776f1SJuan Quintela bool migrate_pause_before_switchover(void)
2731f0776f1SJuan Quintela {
2748f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
2751f0776f1SJuan Quintela
2761f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER];
2771f0776f1SJuan Quintela }
2781f0776f1SJuan Quintela
migrate_postcopy_blocktime(void)2791f0776f1SJuan Quintela bool migrate_postcopy_blocktime(void)
2801f0776f1SJuan Quintela {
2818f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
2821f0776f1SJuan Quintela
2831f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME];
2841f0776f1SJuan Quintela }
2851f0776f1SJuan Quintela
migrate_postcopy_preempt(void)2861f0776f1SJuan Quintela bool migrate_postcopy_preempt(void)
2871f0776f1SJuan Quintela {
2888f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
2891f0776f1SJuan Quintela
2901f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT];
2911f0776f1SJuan Quintela }
2921f0776f1SJuan Quintela
migrate_postcopy_ram(void)2931f0776f1SJuan Quintela bool migrate_postcopy_ram(void)
2941f0776f1SJuan Quintela {
2958f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
2961f0776f1SJuan Quintela
2971f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_POSTCOPY_RAM];
2981f0776f1SJuan Quintela }
2991f0776f1SJuan Quintela
migrate_rdma_pin_all(void)30017cba690SJuan Quintela bool migrate_rdma_pin_all(void)
30117cba690SJuan Quintela {
30217cba690SJuan Quintela MigrationState *s = migrate_get_current();
30317cba690SJuan Quintela
30417cba690SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_RDMA_PIN_ALL];
30517cba690SJuan Quintela }
30617cba690SJuan Quintela
migrate_release_ram(void)3071f0776f1SJuan Quintela bool migrate_release_ram(void)
3081f0776f1SJuan Quintela {
3098f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
3101f0776f1SJuan Quintela
3111f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_RELEASE_RAM];
3121f0776f1SJuan Quintela }
3131f0776f1SJuan Quintela
migrate_return_path(void)31438ad1110SJuan Quintela bool migrate_return_path(void)
31538ad1110SJuan Quintela {
3168f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
31738ad1110SJuan Quintela
31838ad1110SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_RETURN_PATH];
31938ad1110SJuan Quintela }
32038ad1110SJuan Quintela
migrate_switchover_ack(void)3216574232fSAvihai Horon bool migrate_switchover_ack(void)
3226574232fSAvihai Horon {
3236574232fSAvihai Horon MigrationState *s = migrate_get_current();
3246574232fSAvihai Horon
3256574232fSAvihai Horon return s->capabilities[MIGRATION_CAPABILITY_SWITCHOVER_ACK];
3266574232fSAvihai Horon }
3276574232fSAvihai Horon
migrate_validate_uuid(void)3281f0776f1SJuan Quintela bool migrate_validate_uuid(void)
3291f0776f1SJuan Quintela {
3308f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
3311f0776f1SJuan Quintela
3321f0776f1SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_VALIDATE_UUID];
3331f0776f1SJuan Quintela }
3341f0776f1SJuan Quintela
migrate_xbzrle(void)33587dca0c9SJuan Quintela bool migrate_xbzrle(void)
33687dca0c9SJuan Quintela {
3378f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
33887dca0c9SJuan Quintela
33987dca0c9SJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_XBZRLE];
34087dca0c9SJuan Quintela }
34187dca0c9SJuan Quintela
migrate_zero_copy_send(void)342b4bc342cSJuan Quintela bool migrate_zero_copy_send(void)
343b4bc342cSJuan Quintela {
3448f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
345b4bc342cSJuan Quintela
346b4bc342cSJuan Quintela return s->capabilities[MIGRATION_CAPABILITY_ZERO_COPY_SEND];
347b4bc342cSJuan Quintela }
348f774fde5SJuan Quintela
349f774fde5SJuan Quintela /* pseudo capabilities */
350f774fde5SJuan Quintela
migrate_multifd_flush_after_each_section(void)35177c259a4SJuan Quintela bool migrate_multifd_flush_after_each_section(void)
35277c259a4SJuan Quintela {
35377c259a4SJuan Quintela MigrationState *s = migrate_get_current();
35477c259a4SJuan Quintela
355294e5a40SJuan Quintela return s->multifd_flush_after_each_section;
35677c259a4SJuan Quintela }
35777c259a4SJuan Quintela
migrate_postcopy(void)358f774fde5SJuan Quintela bool migrate_postcopy(void)
359f774fde5SJuan Quintela {
360f774fde5SJuan Quintela return migrate_postcopy_ram() || migrate_dirty_bitmaps();
361f774fde5SJuan Quintela }
362f774fde5SJuan Quintela
migrate_rdma(void)36327fd25b0SJuan Quintela bool migrate_rdma(void)
36427fd25b0SJuan Quintela {
36527fd25b0SJuan Quintela MigrationState *s = migrate_get_current();
36627fd25b0SJuan Quintela
36727fd25b0SJuan Quintela return s->rdma_migration;
36827fd25b0SJuan Quintela }
36927fd25b0SJuan Quintela
migrate_tls(void)37010d4703bSJuan Quintela bool migrate_tls(void)
37110d4703bSJuan Quintela {
3728f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
37310d4703bSJuan Quintela
37410d4703bSJuan Quintela return s->parameters.tls_creds && *s->parameters.tls_creds;
37510d4703bSJuan Quintela }
37610d4703bSJuan Quintela
37777608706SJuan Quintela typedef enum WriteTrackingSupport {
37877608706SJuan Quintela WT_SUPPORT_UNKNOWN = 0,
37977608706SJuan Quintela WT_SUPPORT_ABSENT,
38077608706SJuan Quintela WT_SUPPORT_AVAILABLE,
38177608706SJuan Quintela WT_SUPPORT_COMPATIBLE
38277608706SJuan Quintela } WriteTrackingSupport;
38377608706SJuan Quintela
38477608706SJuan Quintela static
migrate_query_write_tracking(void)38577608706SJuan Quintela WriteTrackingSupport migrate_query_write_tracking(void)
38677608706SJuan Quintela {
38777608706SJuan Quintela /* Check if kernel supports required UFFD features */
38877608706SJuan Quintela if (!ram_write_tracking_available()) {
38977608706SJuan Quintela return WT_SUPPORT_ABSENT;
39077608706SJuan Quintela }
39177608706SJuan Quintela /*
39277608706SJuan Quintela * Check if current memory configuration is
39377608706SJuan Quintela * compatible with required UFFD features.
39477608706SJuan Quintela */
39577608706SJuan Quintela if (!ram_write_tracking_compatible()) {
39677608706SJuan Quintela return WT_SUPPORT_AVAILABLE;
39777608706SJuan Quintela }
39877608706SJuan Quintela
39977608706SJuan Quintela return WT_SUPPORT_COMPATIBLE;
40077608706SJuan Quintela }
40177608706SJuan Quintela
40277608706SJuan Quintela /* Migration capabilities set */
40377608706SJuan Quintela struct MigrateCapsSet {
40477608706SJuan Quintela int size; /* Capability set size */
40577608706SJuan Quintela MigrationCapability caps[]; /* Variadic array of capabilities */
40677608706SJuan Quintela };
40777608706SJuan Quintela typedef struct MigrateCapsSet MigrateCapsSet;
40877608706SJuan Quintela
40977608706SJuan Quintela /* Define and initialize MigrateCapsSet */
41077608706SJuan Quintela #define INITIALIZE_MIGRATE_CAPS_SET(_name, ...) \
41177608706SJuan Quintela MigrateCapsSet _name = { \
41277608706SJuan Quintela .size = sizeof((int []) { __VA_ARGS__ }) / sizeof(int), \
41377608706SJuan Quintela .caps = { __VA_ARGS__ } \
41477608706SJuan Quintela }
41577608706SJuan Quintela
41677608706SJuan Quintela /* Background-snapshot compatibility check list */
41777608706SJuan Quintela static const
41877608706SJuan Quintela INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snapshot,
41977608706SJuan Quintela MIGRATION_CAPABILITY_POSTCOPY_RAM,
42077608706SJuan Quintela MIGRATION_CAPABILITY_DIRTY_BITMAPS,
42177608706SJuan Quintela MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME,
42277608706SJuan Quintela MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE,
42377608706SJuan Quintela MIGRATION_CAPABILITY_RETURN_PATH,
42477608706SJuan Quintela MIGRATION_CAPABILITY_MULTIFD,
42577608706SJuan Quintela MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER,
42677608706SJuan Quintela MIGRATION_CAPABILITY_AUTO_CONVERGE,
42777608706SJuan Quintela MIGRATION_CAPABILITY_RELEASE_RAM,
42877608706SJuan Quintela MIGRATION_CAPABILITY_RDMA_PIN_ALL,
42977608706SJuan Quintela MIGRATION_CAPABILITY_XBZRLE,
43077608706SJuan Quintela MIGRATION_CAPABILITY_X_COLO,
43177608706SJuan Quintela MIGRATION_CAPABILITY_VALIDATE_UUID,
43277608706SJuan Quintela MIGRATION_CAPABILITY_ZERO_COPY_SEND);
43377608706SJuan Quintela
migrate_incoming_started(void)43482137e6cSWei Wang static bool migrate_incoming_started(void)
43582137e6cSWei Wang {
43682137e6cSWei Wang return !!migration_incoming_get_current()->transport_data;
43782137e6cSWei Wang }
43882137e6cSWei Wang
43977608706SJuan Quintela /**
44077608706SJuan Quintela * @migration_caps_check - check capability compatibility
44177608706SJuan Quintela *
44277608706SJuan Quintela * @old_caps: old capability list
44377608706SJuan Quintela * @new_caps: new capability list
44477608706SJuan Quintela * @errp: set *errp if the check failed, with reason
44577608706SJuan Quintela *
44677608706SJuan Quintela * Returns true if check passed, otherwise false.
44777608706SJuan Quintela */
migrate_caps_check(bool * old_caps,bool * new_caps,Error ** errp)44877608706SJuan Quintela bool migrate_caps_check(bool *old_caps, bool *new_caps, Error **errp)
44977608706SJuan Quintela {
45046ff64a8SZhao Liu ERRP_GUARD();
45177608706SJuan Quintela MigrationIncomingState *mis = migration_incoming_get_current();
45277608706SJuan Quintela
453*73581a04SFabiano Rosas if (new_caps[MIGRATION_CAPABILITY_ZERO_BLOCKS]) {
454*73581a04SFabiano Rosas warn_report("zero-blocks capability is deprecated");
455*73581a04SFabiano Rosas }
456*73581a04SFabiano Rosas
45777608706SJuan Quintela #ifndef CONFIG_REPLICATION
45877608706SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_X_COLO]) {
45977608706SJuan Quintela error_setg(errp, "QEMU compiled without replication module"
46077608706SJuan Quintela " can't enable COLO");
46177608706SJuan Quintela error_append_hint(errp, "Please enable replication before COLO.\n");
46277608706SJuan Quintela return false;
46377608706SJuan Quintela }
46477608706SJuan Quintela #endif
46577608706SJuan Quintela
46677608706SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) {
46777608706SJuan Quintela /* This check is reasonably expensive, so only when it's being
46877608706SJuan Quintela * set the first time, also it's only the destination that needs
46977608706SJuan Quintela * special support.
47077608706SJuan Quintela */
47177608706SJuan Quintela if (!old_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM] &&
47277608706SJuan Quintela runstate_check(RUN_STATE_INMIGRATE) &&
47374c38cf7SPeter Xu !postcopy_ram_supported_by_host(mis, errp)) {
47474c38cf7SPeter Xu error_prepend(errp, "Postcopy is not supported: ");
47577608706SJuan Quintela return false;
47677608706SJuan Quintela }
47777608706SJuan Quintela
47877608706SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_X_IGNORE_SHARED]) {
47977608706SJuan Quintela error_setg(errp, "Postcopy is not compatible with ignore-shared");
48077608706SJuan Quintela return false;
48177608706SJuan Quintela }
482b405dfffSLeonardo Bras
483b405dfffSLeonardo Bras if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) {
484b405dfffSLeonardo Bras error_setg(errp, "Postcopy is not yet compatible with multifd");
485b405dfffSLeonardo Bras return false;
486b405dfffSLeonardo Bras }
48777608706SJuan Quintela }
48877608706SJuan Quintela
48977608706SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT]) {
49077608706SJuan Quintela WriteTrackingSupport wt_support;
49177608706SJuan Quintela int idx;
49277608706SJuan Quintela /*
49377608706SJuan Quintela * Check if 'background-snapshot' capability is supported by
49477608706SJuan Quintela * host kernel and compatible with guest memory configuration.
49577608706SJuan Quintela */
49677608706SJuan Quintela wt_support = migrate_query_write_tracking();
49777608706SJuan Quintela if (wt_support < WT_SUPPORT_AVAILABLE) {
49877608706SJuan Quintela error_setg(errp, "Background-snapshot is not supported by host kernel");
49977608706SJuan Quintela return false;
50077608706SJuan Quintela }
50177608706SJuan Quintela if (wt_support < WT_SUPPORT_COMPATIBLE) {
50277608706SJuan Quintela error_setg(errp, "Background-snapshot is not compatible "
50377608706SJuan Quintela "with guest memory configuration");
50477608706SJuan Quintela return false;
50577608706SJuan Quintela }
50677608706SJuan Quintela
50777608706SJuan Quintela /*
50877608706SJuan Quintela * Check if there are any migration capabilities
50977608706SJuan Quintela * incompatible with 'background-snapshot'.
51077608706SJuan Quintela */
51177608706SJuan Quintela for (idx = 0; idx < check_caps_background_snapshot.size; idx++) {
51277608706SJuan Quintela int incomp_cap = check_caps_background_snapshot.caps[idx];
51377608706SJuan Quintela if (new_caps[incomp_cap]) {
51477608706SJuan Quintela error_setg(errp,
51577608706SJuan Quintela "Background-snapshot is not compatible with %s",
51677608706SJuan Quintela MigrationCapability_str(incomp_cap));
51777608706SJuan Quintela return false;
51877608706SJuan Quintela }
51977608706SJuan Quintela }
52077608706SJuan Quintela }
52177608706SJuan Quintela
52277608706SJuan Quintela #ifdef CONFIG_LINUX
52377608706SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_ZERO_COPY_SEND] &&
52477608706SJuan Quintela (!new_caps[MIGRATION_CAPABILITY_MULTIFD] ||
52577608706SJuan Quintela new_caps[MIGRATION_CAPABILITY_XBZRLE] ||
52677608706SJuan Quintela migrate_multifd_compression() ||
52710d4703bSJuan Quintela migrate_tls())) {
52877608706SJuan Quintela error_setg(errp,
52977608706SJuan Quintela "Zero copy only available for non-compressed non-TLS multifd migration");
53077608706SJuan Quintela return false;
53177608706SJuan Quintela }
53277608706SJuan Quintela #else
53377608706SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_ZERO_COPY_SEND]) {
53477608706SJuan Quintela error_setg(errp,
53577608706SJuan Quintela "Zero copy currently only available on Linux");
53677608706SJuan Quintela return false;
53777608706SJuan Quintela }
53877608706SJuan Quintela #endif
53977608706SJuan Quintela
54077608706SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT]) {
54177608706SJuan Quintela if (!new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) {
54277608706SJuan Quintela error_setg(errp, "Postcopy preempt requires postcopy-ram");
54377608706SJuan Quintela return false;
54477608706SJuan Quintela }
54577608706SJuan Quintela
54682137e6cSWei Wang if (migrate_incoming_started()) {
54782137e6cSWei Wang error_setg(errp,
54882137e6cSWei Wang "Postcopy preempt must be set before incoming starts");
54982137e6cSWei Wang return false;
55082137e6cSWei Wang }
55177608706SJuan Quintela }
55277608706SJuan Quintela
55377608706SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) {
55482137e6cSWei Wang if (migrate_incoming_started()) {
55582137e6cSWei Wang error_setg(errp, "Multifd must be set before incoming starts");
55682137e6cSWei Wang return false;
55782137e6cSWei Wang }
55877608706SJuan Quintela }
55977608706SJuan Quintela
5606574232fSAvihai Horon if (new_caps[MIGRATION_CAPABILITY_SWITCHOVER_ACK]) {
5616574232fSAvihai Horon if (!new_caps[MIGRATION_CAPABILITY_RETURN_PATH]) {
5626574232fSAvihai Horon error_setg(errp, "Capability 'switchover-ack' requires capability "
5636574232fSAvihai Horon "'return-path'");
5646574232fSAvihai Horon return false;
5656574232fSAvihai Horon }
5666574232fSAvihai Horon }
567dc623955SHyman Huang(黄勇) if (new_caps[MIGRATION_CAPABILITY_DIRTY_LIMIT]) {
568dc623955SHyman Huang(黄勇) if (new_caps[MIGRATION_CAPABILITY_AUTO_CONVERGE]) {
569dc623955SHyman Huang(黄勇) error_setg(errp, "dirty-limit conflicts with auto-converge"
570dc623955SHyman Huang(黄勇) " either of then available currently");
571dc623955SHyman Huang(黄勇) return false;
572dc623955SHyman Huang(黄勇) }
573dc623955SHyman Huang(黄勇)
574dc623955SHyman Huang(黄勇) if (!kvm_enabled() || !kvm_dirty_ring_enabled()) {
575dc623955SHyman Huang(黄勇) error_setg(errp, "dirty-limit requires KVM with accelerator"
576dc623955SHyman Huang(黄勇) " property 'dirty-ring-size' set");
577dc623955SHyman Huang(黄勇) return false;
578dc623955SHyman Huang(黄勇) }
579dc623955SHyman Huang(黄勇) }
5806574232fSAvihai Horon
581d869f629SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) {
582d869f629SJuan Quintela if (new_caps[MIGRATION_CAPABILITY_XBZRLE]) {
583d869f629SJuan Quintela error_setg(errp, "Multifd is not compatible with xbzrle");
584d869f629SJuan Quintela return false;
585d869f629SJuan Quintela }
586d869f629SJuan Quintela }
587d869f629SJuan Quintela
5884ed49febSFabiano Rosas if (new_caps[MIGRATION_CAPABILITY_MAPPED_RAM]) {
5894ed49febSFabiano Rosas if (new_caps[MIGRATION_CAPABILITY_XBZRLE]) {
5904ed49febSFabiano Rosas error_setg(errp,
5914ed49febSFabiano Rosas "Mapped-ram migration is incompatible with xbzrle");
5924ed49febSFabiano Rosas return false;
5934ed49febSFabiano Rosas }
5944ed49febSFabiano Rosas
5954ed49febSFabiano Rosas if (new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) {
5964ed49febSFabiano Rosas error_setg(errp,
5974ed49febSFabiano Rosas "Mapped-ram migration is incompatible with postcopy");
5984ed49febSFabiano Rosas return false;
5994ed49febSFabiano Rosas }
6004ed49febSFabiano Rosas }
6014ed49febSFabiano Rosas
60277608706SJuan Quintela return true;
60377608706SJuan Quintela }
6044d0c6b69SJuan Quintela
qmp_query_migrate_capabilities(Error ** errp)6054d0c6b69SJuan Quintela MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp)
6064d0c6b69SJuan Quintela {
6074d0c6b69SJuan Quintela MigrationCapabilityStatusList *head = NULL, **tail = &head;
6084d0c6b69SJuan Quintela MigrationCapabilityStatus *caps;
6094d0c6b69SJuan Quintela MigrationState *s = migrate_get_current();
6104d0c6b69SJuan Quintela int i;
6114d0c6b69SJuan Quintela
6124d0c6b69SJuan Quintela for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
6134d0c6b69SJuan Quintela caps = g_malloc0(sizeof(*caps));
6144d0c6b69SJuan Quintela caps->capability = i;
6154d0c6b69SJuan Quintela caps->state = s->capabilities[i];
6164d0c6b69SJuan Quintela QAPI_LIST_APPEND(tail, caps);
6174d0c6b69SJuan Quintela }
6184d0c6b69SJuan Quintela
6194d0c6b69SJuan Quintela return head;
6204d0c6b69SJuan Quintela }
62145c1de13SJuan Quintela
qmp_migrate_set_capabilities(MigrationCapabilityStatusList * params,Error ** errp)62245c1de13SJuan Quintela void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
62345c1de13SJuan Quintela Error **errp)
62445c1de13SJuan Quintela {
62545c1de13SJuan Quintela MigrationState *s = migrate_get_current();
62645c1de13SJuan Quintela MigrationCapabilityStatusList *cap;
62745c1de13SJuan Quintela bool new_caps[MIGRATION_CAPABILITY__MAX];
62845c1de13SJuan Quintela
629aeaafb1eSSteve Sistare if (migration_is_running() || migration_in_colo_state()) {
63000580786SPhilippe Mathieu-Daudé error_setg(errp, "There's a migration process in progress");
63145c1de13SJuan Quintela return;
63245c1de13SJuan Quintela }
63345c1de13SJuan Quintela
63445c1de13SJuan Quintela memcpy(new_caps, s->capabilities, sizeof(new_caps));
63545c1de13SJuan Quintela for (cap = params; cap; cap = cap->next) {
63645c1de13SJuan Quintela new_caps[cap->value->capability] = cap->value->state;
63745c1de13SJuan Quintela }
63845c1de13SJuan Quintela
63945c1de13SJuan Quintela if (!migrate_caps_check(s->capabilities, new_caps, errp)) {
64045c1de13SJuan Quintela return;
64145c1de13SJuan Quintela }
64245c1de13SJuan Quintela
64345c1de13SJuan Quintela for (cap = params; cap; cap = cap->next) {
64445c1de13SJuan Quintela s->capabilities[cap->value->capability] = cap->value->state;
64545c1de13SJuan Quintela }
64645c1de13SJuan Quintela }
6471dfc4b9eSJuan Quintela
6481dfc4b9eSJuan Quintela /* parameters */
6491dfc4b9eSJuan Quintela
migrate_block_bitmap_mapping(void)650b804b35bSJuan Quintela const BitmapMigrationNodeAliasList *migrate_block_bitmap_mapping(void)
651b804b35bSJuan Quintela {
652b804b35bSJuan Quintela MigrationState *s = migrate_get_current();
653b804b35bSJuan Quintela
654b804b35bSJuan Quintela return s->parameters.block_bitmap_mapping;
655b804b35bSJuan Quintela }
656b804b35bSJuan Quintela
migrate_has_block_bitmap_mapping(void)6573cba22c9SJuan Quintela bool migrate_has_block_bitmap_mapping(void)
6583cba22c9SJuan Quintela {
6593cba22c9SJuan Quintela MigrationState *s = migrate_get_current();
6603cba22c9SJuan Quintela
6613cba22c9SJuan Quintela return s->parameters.has_block_bitmap_mapping;
6623cba22c9SJuan Quintela }
6633cba22c9SJuan Quintela
migrate_checkpoint_delay(void)664f94a858fSJuan Quintela uint32_t migrate_checkpoint_delay(void)
665f94a858fSJuan Quintela {
6668f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
667f94a858fSJuan Quintela
668f94a858fSJuan Quintela return s->parameters.x_checkpoint_delay;
669f94a858fSJuan Quintela }
670f94a858fSJuan Quintela
migrate_cpu_throttle_increment(void)6719605c2acSJuan Quintela uint8_t migrate_cpu_throttle_increment(void)
6729605c2acSJuan Quintela {
6738f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
6749605c2acSJuan Quintela
6759605c2acSJuan Quintela return s->parameters.cpu_throttle_increment;
6769605c2acSJuan Quintela }
6779605c2acSJuan Quintela
migrate_cpu_throttle_initial(void)6782a8ec380SJuan Quintela uint8_t migrate_cpu_throttle_initial(void)
6792a8ec380SJuan Quintela {
6808f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
6812a8ec380SJuan Quintela
6822a8ec380SJuan Quintela return s->parameters.cpu_throttle_initial;
6832a8ec380SJuan Quintela }
6842a8ec380SJuan Quintela
migrate_cpu_throttle_tailslow(void)685873f674cSJuan Quintela bool migrate_cpu_throttle_tailslow(void)
686873f674cSJuan Quintela {
6878f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
688873f674cSJuan Quintela
689873f674cSJuan Quintela return s->parameters.cpu_throttle_tailslow;
690873f674cSJuan Quintela }
691873f674cSJuan Quintela
migrate_direct_io(void)692b43b61d5SFabiano Rosas bool migrate_direct_io(void)
693b43b61d5SFabiano Rosas {
694b43b61d5SFabiano Rosas MigrationState *s = migrate_get_current();
695b43b61d5SFabiano Rosas
696b43b61d5SFabiano Rosas /*
697b43b61d5SFabiano Rosas * O_DIRECT is only supported with mapped-ram and multifd.
698b43b61d5SFabiano Rosas *
699b43b61d5SFabiano Rosas * mapped-ram is needed because filesystems impose restrictions on
700b43b61d5SFabiano Rosas * O_DIRECT IO alignment (see MAPPED_RAM_FILE_OFFSET_ALIGNMENT).
701b43b61d5SFabiano Rosas *
702b43b61d5SFabiano Rosas * multifd is needed to keep the unaligned portion of the stream
703b43b61d5SFabiano Rosas * isolated to the main migration thread while multifd channels
704b43b61d5SFabiano Rosas * process the aligned data with O_DIRECT enabled.
705b43b61d5SFabiano Rosas */
706b43b61d5SFabiano Rosas return s->parameters.direct_io &&
707b43b61d5SFabiano Rosas s->capabilities[MIGRATION_CAPABILITY_MAPPED_RAM] &&
708b43b61d5SFabiano Rosas s->capabilities[MIGRATION_CAPABILITY_MULTIFD];
709b43b61d5SFabiano Rosas }
710b43b61d5SFabiano Rosas
migrate_downtime_limit(void)711f5da8ba4SJuan Quintela uint64_t migrate_downtime_limit(void)
712f5da8ba4SJuan Quintela {
713f5da8ba4SJuan Quintela MigrationState *s = migrate_get_current();
714f5da8ba4SJuan Quintela
715f5da8ba4SJuan Quintela return s->parameters.downtime_limit;
716f5da8ba4SJuan Quintela }
717f5da8ba4SJuan Quintela
migrate_max_cpu_throttle(void)71824155bd0SJuan Quintela uint8_t migrate_max_cpu_throttle(void)
71924155bd0SJuan Quintela {
7208f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
72124155bd0SJuan Quintela
72224155bd0SJuan Quintela return s->parameters.max_cpu_throttle;
72324155bd0SJuan Quintela }
72424155bd0SJuan Quintela
migrate_max_bandwidth(void)7259c894df3SJuan Quintela uint64_t migrate_max_bandwidth(void)
7269c894df3SJuan Quintela {
7278f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
7289c894df3SJuan Quintela
7299c894df3SJuan Quintela return s->parameters.max_bandwidth;
7309c894df3SJuan Quintela }
7319c894df3SJuan Quintela
migrate_avail_switchover_bandwidth(void)7328b239597SPeter Xu uint64_t migrate_avail_switchover_bandwidth(void)
7338b239597SPeter Xu {
7348b239597SPeter Xu MigrationState *s = migrate_get_current();
7358b239597SPeter Xu
7368b239597SPeter Xu return s->parameters.avail_switchover_bandwidth;
7378b239597SPeter Xu }
7388b239597SPeter Xu
migrate_max_postcopy_bandwidth(void)73952033349SJuan Quintela uint64_t migrate_max_postcopy_bandwidth(void)
7401dfc4b9eSJuan Quintela {
7418f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
7421dfc4b9eSJuan Quintela
7431dfc4b9eSJuan Quintela return s->parameters.max_postcopy_bandwidth;
7441dfc4b9eSJuan Quintela }
7451dfc4b9eSJuan Quintela
migrate_mode(void)746eea1e5c9SSteve Sistare MigMode migrate_mode(void)
747eea1e5c9SSteve Sistare {
748eea1e5c9SSteve Sistare MigrationState *s = migrate_get_current();
749b12635ffSSteve Sistare MigMode mode = s->parameters.mode;
750eea1e5c9SSteve Sistare
751b12635ffSSteve Sistare assert(mode >= 0 && mode < MIG_MODE__MAX);
752b12635ffSSteve Sistare return mode;
753eea1e5c9SSteve Sistare }
754eea1e5c9SSteve Sistare
migrate_multifd_channels(void)7551dfc4b9eSJuan Quintela int migrate_multifd_channels(void)
7561dfc4b9eSJuan Quintela {
7578f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
7581dfc4b9eSJuan Quintela
7591dfc4b9eSJuan Quintela return s->parameters.multifd_channels;
7601dfc4b9eSJuan Quintela }
7611dfc4b9eSJuan Quintela
migrate_multifd_compression(void)7621dfc4b9eSJuan Quintela MultiFDCompression migrate_multifd_compression(void)
7631dfc4b9eSJuan Quintela {
7648f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
7651dfc4b9eSJuan Quintela
7661dfc4b9eSJuan Quintela assert(s->parameters.multifd_compression < MULTIFD_COMPRESSION__MAX);
7671dfc4b9eSJuan Quintela return s->parameters.multifd_compression;
7681dfc4b9eSJuan Quintela }
7691dfc4b9eSJuan Quintela
migrate_multifd_zlib_level(void)7701dfc4b9eSJuan Quintela int migrate_multifd_zlib_level(void)
7711dfc4b9eSJuan Quintela {
7728f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
7731dfc4b9eSJuan Quintela
7741dfc4b9eSJuan Quintela return s->parameters.multifd_zlib_level;
7751dfc4b9eSJuan Quintela }
7761dfc4b9eSJuan Quintela
migrate_multifd_qatzip_level(void)77786c6eb1fSBryan Zhang int migrate_multifd_qatzip_level(void)
77886c6eb1fSBryan Zhang {
77986c6eb1fSBryan Zhang MigrationState *s = migrate_get_current();
78086c6eb1fSBryan Zhang
78186c6eb1fSBryan Zhang return s->parameters.multifd_qatzip_level;
78286c6eb1fSBryan Zhang }
78386c6eb1fSBryan Zhang
migrate_multifd_zstd_level(void)7841dfc4b9eSJuan Quintela int migrate_multifd_zstd_level(void)
7851dfc4b9eSJuan Quintela {
7868f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
7871dfc4b9eSJuan Quintela
7881dfc4b9eSJuan Quintela return s->parameters.multifd_zstd_level;
7891dfc4b9eSJuan Quintela }
7901dfc4b9eSJuan Quintela
migrate_throttle_trigger_threshold(void)7916499efdbSJuan Quintela uint8_t migrate_throttle_trigger_threshold(void)
7926499efdbSJuan Quintela {
7938f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
7946499efdbSJuan Quintela
7956499efdbSJuan Quintela return s->parameters.throttle_trigger_threshold;
7966499efdbSJuan Quintela }
7976499efdbSJuan Quintela
migrate_tls_authz(void)7982eb0308bSJuan Quintela const char *migrate_tls_authz(void)
7992eb0308bSJuan Quintela {
8002eb0308bSJuan Quintela MigrationState *s = migrate_get_current();
8012eb0308bSJuan Quintela
8022eb0308bSJuan Quintela return s->parameters.tls_authz;
8032eb0308bSJuan Quintela }
8042eb0308bSJuan Quintela
migrate_tls_creds(void)805d5c3e195SJuan Quintela const char *migrate_tls_creds(void)
806d5c3e195SJuan Quintela {
807d5c3e195SJuan Quintela MigrationState *s = migrate_get_current();
808d5c3e195SJuan Quintela
809d5c3e195SJuan Quintela return s->parameters.tls_creds;
810d5c3e195SJuan Quintela }
811d5c3e195SJuan Quintela
migrate_tls_hostname(void)8121f2f366cSJuan Quintela const char *migrate_tls_hostname(void)
8131f2f366cSJuan Quintela {
8141f2f366cSJuan Quintela MigrationState *s = migrate_get_current();
8151f2f366cSJuan Quintela
8161f2f366cSJuan Quintela return s->parameters.tls_hostname;
8171f2f366cSJuan Quintela }
8181f2f366cSJuan Quintela
migrate_vcpu_dirty_limit_period(void)819714f3312SSteve Sistare uint64_t migrate_vcpu_dirty_limit_period(void)
820714f3312SSteve Sistare {
821714f3312SSteve Sistare MigrationState *s = migrate_get_current();
822714f3312SSteve Sistare
823714f3312SSteve Sistare return s->parameters.x_vcpu_dirty_limit_period;
824714f3312SSteve Sistare }
825714f3312SSteve Sistare
migrate_xbzrle_cache_size(void)8261dfc4b9eSJuan Quintela uint64_t migrate_xbzrle_cache_size(void)
8271dfc4b9eSJuan Quintela {
8288f9c5327SJuan Quintela MigrationState *s = migrate_get_current();
8291dfc4b9eSJuan Quintela
8301dfc4b9eSJuan Quintela return s->parameters.xbzrle_cache_size;
8311dfc4b9eSJuan Quintela }
8322682c4eeSJuan Quintela
migrate_zero_page_detection(void)8335fdbb1dfSHao Xiang ZeroPageDetection migrate_zero_page_detection(void)
8345fdbb1dfSHao Xiang {
8355fdbb1dfSHao Xiang MigrationState *s = migrate_get_current();
8365fdbb1dfSHao Xiang
8375fdbb1dfSHao Xiang return s->parameters.zero_page_detection;
8385fdbb1dfSHao Xiang }
8395fdbb1dfSHao Xiang
8402682c4eeSJuan Quintela /* parameters helpers */
8412682c4eeSJuan Quintela
migrate_announce_params(void)8422682c4eeSJuan Quintela AnnounceParameters *migrate_announce_params(void)
8432682c4eeSJuan Quintela {
8442682c4eeSJuan Quintela static AnnounceParameters ap;
8452682c4eeSJuan Quintela
8462682c4eeSJuan Quintela MigrationState *s = migrate_get_current();
8472682c4eeSJuan Quintela
8482682c4eeSJuan Quintela ap.initial = s->parameters.announce_initial;
8492682c4eeSJuan Quintela ap.max = s->parameters.announce_max;
8502682c4eeSJuan Quintela ap.rounds = s->parameters.announce_rounds;
8512682c4eeSJuan Quintela ap.step = s->parameters.announce_step;
8522682c4eeSJuan Quintela
8532682c4eeSJuan Quintela return ≈
8542682c4eeSJuan Quintela }
8559c894df3SJuan Quintela
qmp_query_migrate_parameters(Error ** errp)8569c894df3SJuan Quintela MigrationParameters *qmp_query_migrate_parameters(Error **errp)
8579c894df3SJuan Quintela {
8589c894df3SJuan Quintela MigrationParameters *params;
8599c894df3SJuan Quintela MigrationState *s = migrate_get_current();
8609c894df3SJuan Quintela
8619c894df3SJuan Quintela /* TODO use QAPI_CLONE() instead of duplicating it inline */
8629c894df3SJuan Quintela params = g_malloc0(sizeof(*params));
8639c894df3SJuan Quintela params->has_throttle_trigger_threshold = true;
8649c894df3SJuan Quintela params->throttle_trigger_threshold = s->parameters.throttle_trigger_threshold;
8659c894df3SJuan Quintela params->has_cpu_throttle_initial = true;
8669c894df3SJuan Quintela params->cpu_throttle_initial = s->parameters.cpu_throttle_initial;
8679c894df3SJuan Quintela params->has_cpu_throttle_increment = true;
8689c894df3SJuan Quintela params->cpu_throttle_increment = s->parameters.cpu_throttle_increment;
8699c894df3SJuan Quintela params->has_cpu_throttle_tailslow = true;
8709c894df3SJuan Quintela params->cpu_throttle_tailslow = s->parameters.cpu_throttle_tailslow;
8719c894df3SJuan Quintela params->tls_creds = g_strdup(s->parameters.tls_creds);
8729c894df3SJuan Quintela params->tls_hostname = g_strdup(s->parameters.tls_hostname);
8739c894df3SJuan Quintela params->tls_authz = g_strdup(s->parameters.tls_authz ?
8749c894df3SJuan Quintela s->parameters.tls_authz : "");
8759c894df3SJuan Quintela params->has_max_bandwidth = true;
8769c894df3SJuan Quintela params->max_bandwidth = s->parameters.max_bandwidth;
8778b239597SPeter Xu params->has_avail_switchover_bandwidth = true;
8788b239597SPeter Xu params->avail_switchover_bandwidth = s->parameters.avail_switchover_bandwidth;
8799c894df3SJuan Quintela params->has_downtime_limit = true;
8809c894df3SJuan Quintela params->downtime_limit = s->parameters.downtime_limit;
8819c894df3SJuan Quintela params->has_x_checkpoint_delay = true;
8829c894df3SJuan Quintela params->x_checkpoint_delay = s->parameters.x_checkpoint_delay;
8839c894df3SJuan Quintela params->has_multifd_channels = true;
8849c894df3SJuan Quintela params->multifd_channels = s->parameters.multifd_channels;
8859c894df3SJuan Quintela params->has_multifd_compression = true;
8869c894df3SJuan Quintela params->multifd_compression = s->parameters.multifd_compression;
8879c894df3SJuan Quintela params->has_multifd_zlib_level = true;
8889c894df3SJuan Quintela params->multifd_zlib_level = s->parameters.multifd_zlib_level;
88986c6eb1fSBryan Zhang params->has_multifd_qatzip_level = true;
89086c6eb1fSBryan Zhang params->multifd_qatzip_level = s->parameters.multifd_qatzip_level;
8919c894df3SJuan Quintela params->has_multifd_zstd_level = true;
8929c894df3SJuan Quintela params->multifd_zstd_level = s->parameters.multifd_zstd_level;
8939c894df3SJuan Quintela params->has_xbzrle_cache_size = true;
8949c894df3SJuan Quintela params->xbzrle_cache_size = s->parameters.xbzrle_cache_size;
8959c894df3SJuan Quintela params->has_max_postcopy_bandwidth = true;
8969c894df3SJuan Quintela params->max_postcopy_bandwidth = s->parameters.max_postcopy_bandwidth;
8979c894df3SJuan Quintela params->has_max_cpu_throttle = true;
8989c894df3SJuan Quintela params->max_cpu_throttle = s->parameters.max_cpu_throttle;
8999c894df3SJuan Quintela params->has_announce_initial = true;
9009c894df3SJuan Quintela params->announce_initial = s->parameters.announce_initial;
9019c894df3SJuan Quintela params->has_announce_max = true;
9029c894df3SJuan Quintela params->announce_max = s->parameters.announce_max;
9039c894df3SJuan Quintela params->has_announce_rounds = true;
9049c894df3SJuan Quintela params->announce_rounds = s->parameters.announce_rounds;
9059c894df3SJuan Quintela params->has_announce_step = true;
9069c894df3SJuan Quintela params->announce_step = s->parameters.announce_step;
9079c894df3SJuan Quintela
9089c894df3SJuan Quintela if (s->parameters.has_block_bitmap_mapping) {
9099c894df3SJuan Quintela params->has_block_bitmap_mapping = true;
9109c894df3SJuan Quintela params->block_bitmap_mapping =
9119c894df3SJuan Quintela QAPI_CLONE(BitmapMigrationNodeAliasList,
9129c894df3SJuan Quintela s->parameters.block_bitmap_mapping);
9139c894df3SJuan Quintela }
9149c894df3SJuan Quintela
9154d807857SHyman Huang(黄勇) params->has_x_vcpu_dirty_limit_period = true;
9164d807857SHyman Huang(黄勇) params->x_vcpu_dirty_limit_period = s->parameters.x_vcpu_dirty_limit_period;
91709f9ec99SHyman Huang(黄勇) params->has_vcpu_dirty_limit = true;
91809f9ec99SHyman Huang(黄勇) params->vcpu_dirty_limit = s->parameters.vcpu_dirty_limit;
919eea1e5c9SSteve Sistare params->has_mode = true;
920eea1e5c9SSteve Sistare params->mode = s->parameters.mode;
9215fdbb1dfSHao Xiang params->has_zero_page_detection = true;
9225fdbb1dfSHao Xiang params->zero_page_detection = s->parameters.zero_page_detection;
923b43b61d5SFabiano Rosas params->has_direct_io = true;
924b43b61d5SFabiano Rosas params->direct_io = s->parameters.direct_io;
9254d807857SHyman Huang(黄勇)
9269c894df3SJuan Quintela return params;
9279c894df3SJuan Quintela }
92809d6c965SJuan Quintela
migrate_params_init(MigrationParameters * params)92961a174e2SJuan Quintela void migrate_params_init(MigrationParameters *params)
93061a174e2SJuan Quintela {
93161a174e2SJuan Quintela params->tls_hostname = g_strdup("");
93261a174e2SJuan Quintela params->tls_creds = g_strdup("");
93361a174e2SJuan Quintela
93461a174e2SJuan Quintela /* Set has_* up only for parameter checks */
93561a174e2SJuan Quintela params->has_throttle_trigger_threshold = true;
93661a174e2SJuan Quintela params->has_cpu_throttle_initial = true;
93761a174e2SJuan Quintela params->has_cpu_throttle_increment = true;
93861a174e2SJuan Quintela params->has_cpu_throttle_tailslow = true;
93961a174e2SJuan Quintela params->has_max_bandwidth = true;
94061a174e2SJuan Quintela params->has_downtime_limit = true;
94161a174e2SJuan Quintela params->has_x_checkpoint_delay = true;
94261a174e2SJuan Quintela params->has_multifd_channels = true;
94361a174e2SJuan Quintela params->has_multifd_compression = true;
94461a174e2SJuan Quintela params->has_multifd_zlib_level = true;
94586c6eb1fSBryan Zhang params->has_multifd_qatzip_level = true;
94661a174e2SJuan Quintela params->has_multifd_zstd_level = true;
94761a174e2SJuan Quintela params->has_xbzrle_cache_size = true;
94861a174e2SJuan Quintela params->has_max_postcopy_bandwidth = true;
94961a174e2SJuan Quintela params->has_max_cpu_throttle = true;
95061a174e2SJuan Quintela params->has_announce_initial = true;
95161a174e2SJuan Quintela params->has_announce_max = true;
95261a174e2SJuan Quintela params->has_announce_rounds = true;
95361a174e2SJuan Quintela params->has_announce_step = true;
9544d807857SHyman Huang(黄勇) params->has_x_vcpu_dirty_limit_period = true;
95509f9ec99SHyman Huang(黄勇) params->has_vcpu_dirty_limit = true;
956eea1e5c9SSteve Sistare params->has_mode = true;
9575fdbb1dfSHao Xiang params->has_zero_page_detection = true;
958b43b61d5SFabiano Rosas params->has_direct_io = true;
95961a174e2SJuan Quintela }
96061a174e2SJuan Quintela
96109d6c965SJuan Quintela /*
96209d6c965SJuan Quintela * Check whether the parameters are valid. Error will be put into errp
96309d6c965SJuan Quintela * (if provided). Return true if valid, otherwise false.
96409d6c965SJuan Quintela */
migrate_params_check(MigrationParameters * params,Error ** errp)96509d6c965SJuan Quintela bool migrate_params_check(MigrationParameters *params, Error **errp)
96609d6c965SJuan Quintela {
96735e83a9fSZhao Liu ERRP_GUARD();
96835e83a9fSZhao Liu
96909d6c965SJuan Quintela if (params->has_throttle_trigger_threshold &&
97009d6c965SJuan Quintela (params->throttle_trigger_threshold < 1 ||
97109d6c965SJuan Quintela params->throttle_trigger_threshold > 100)) {
97209d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
97309d6c965SJuan Quintela "throttle_trigger_threshold",
97409d6c965SJuan Quintela "an integer in the range of 1 to 100");
97509d6c965SJuan Quintela return false;
97609d6c965SJuan Quintela }
97709d6c965SJuan Quintela
97809d6c965SJuan Quintela if (params->has_cpu_throttle_initial &&
97909d6c965SJuan Quintela (params->cpu_throttle_initial < 1 ||
98009d6c965SJuan Quintela params->cpu_throttle_initial > 99)) {
98109d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
98209d6c965SJuan Quintela "cpu_throttle_initial",
98309d6c965SJuan Quintela "an integer in the range of 1 to 99");
98409d6c965SJuan Quintela return false;
98509d6c965SJuan Quintela }
98609d6c965SJuan Quintela
98709d6c965SJuan Quintela if (params->has_cpu_throttle_increment &&
98809d6c965SJuan Quintela (params->cpu_throttle_increment < 1 ||
98909d6c965SJuan Quintela params->cpu_throttle_increment > 99)) {
99009d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
99109d6c965SJuan Quintela "cpu_throttle_increment",
99209d6c965SJuan Quintela "an integer in the range of 1 to 99");
99309d6c965SJuan Quintela return false;
99409d6c965SJuan Quintela }
99509d6c965SJuan Quintela
99609d6c965SJuan Quintela if (params->has_max_bandwidth && (params->max_bandwidth > SIZE_MAX)) {
99709d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
99809d6c965SJuan Quintela "max_bandwidth",
99909d6c965SJuan Quintela "an integer in the range of 0 to "stringify(SIZE_MAX)
100009d6c965SJuan Quintela " bytes/second");
100109d6c965SJuan Quintela return false;
100209d6c965SJuan Quintela }
100309d6c965SJuan Quintela
10048b239597SPeter Xu if (params->has_avail_switchover_bandwidth &&
10058b239597SPeter Xu (params->avail_switchover_bandwidth > SIZE_MAX)) {
10068b239597SPeter Xu error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
10078b239597SPeter Xu "avail_switchover_bandwidth",
10088b239597SPeter Xu "an integer in the range of 0 to "stringify(SIZE_MAX)
10098b239597SPeter Xu " bytes/second");
10108b239597SPeter Xu return false;
10118b239597SPeter Xu }
10128b239597SPeter Xu
101309d6c965SJuan Quintela if (params->has_downtime_limit &&
101409d6c965SJuan Quintela (params->downtime_limit > MAX_MIGRATE_DOWNTIME)) {
101509d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
101609d6c965SJuan Quintela "downtime_limit",
101709d6c965SJuan Quintela "an integer in the range of 0 to "
101809d6c965SJuan Quintela stringify(MAX_MIGRATE_DOWNTIME)" ms");
101909d6c965SJuan Quintela return false;
102009d6c965SJuan Quintela }
102109d6c965SJuan Quintela
102209d6c965SJuan Quintela /* x_checkpoint_delay is now always positive */
102309d6c965SJuan Quintela
102409d6c965SJuan Quintela if (params->has_multifd_channels && (params->multifd_channels < 1)) {
102509d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
102609d6c965SJuan Quintela "multifd_channels",
102709d6c965SJuan Quintela "a value between 1 and 255");
102809d6c965SJuan Quintela return false;
102909d6c965SJuan Quintela }
103009d6c965SJuan Quintela
103109d6c965SJuan Quintela if (params->has_multifd_zlib_level &&
103209d6c965SJuan Quintela (params->multifd_zlib_level > 9)) {
103309d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "multifd_zlib_level",
103409d6c965SJuan Quintela "a value between 0 and 9");
103509d6c965SJuan Quintela return false;
103609d6c965SJuan Quintela }
103709d6c965SJuan Quintela
103886c6eb1fSBryan Zhang if (params->has_multifd_qatzip_level &&
103986c6eb1fSBryan Zhang ((params->multifd_qatzip_level > 9) ||
104086c6eb1fSBryan Zhang (params->multifd_qatzip_level < 1))) {
104186c6eb1fSBryan Zhang error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "multifd_qatzip_level",
104286c6eb1fSBryan Zhang "a value between 1 and 9");
104386c6eb1fSBryan Zhang return false;
104486c6eb1fSBryan Zhang }
104586c6eb1fSBryan Zhang
104609d6c965SJuan Quintela if (params->has_multifd_zstd_level &&
104709d6c965SJuan Quintela (params->multifd_zstd_level > 20)) {
104809d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "multifd_zstd_level",
104909d6c965SJuan Quintela "a value between 0 and 20");
105009d6c965SJuan Quintela return false;
105109d6c965SJuan Quintela }
105209d6c965SJuan Quintela
105309d6c965SJuan Quintela if (params->has_xbzrle_cache_size &&
105409d6c965SJuan Quintela (params->xbzrle_cache_size < qemu_target_page_size() ||
105509d6c965SJuan Quintela !is_power_of_2(params->xbzrle_cache_size))) {
105609d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
105709d6c965SJuan Quintela "xbzrle_cache_size",
105809d6c965SJuan Quintela "a power of two no less than the target page size");
105909d6c965SJuan Quintela return false;
106009d6c965SJuan Quintela }
106109d6c965SJuan Quintela
106209d6c965SJuan Quintela if (params->has_max_cpu_throttle &&
106309d6c965SJuan Quintela (params->max_cpu_throttle < params->cpu_throttle_initial ||
106409d6c965SJuan Quintela params->max_cpu_throttle > 99)) {
106509d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
106609d6c965SJuan Quintela "max_cpu_throttle",
106709d6c965SJuan Quintela "an integer in the range of cpu_throttle_initial to 99");
106809d6c965SJuan Quintela return false;
106909d6c965SJuan Quintela }
107009d6c965SJuan Quintela
107109d6c965SJuan Quintela if (params->has_announce_initial &&
107209d6c965SJuan Quintela params->announce_initial > 100000) {
107309d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
107409d6c965SJuan Quintela "announce_initial",
107509d6c965SJuan Quintela "a value between 0 and 100000");
107609d6c965SJuan Quintela return false;
107709d6c965SJuan Quintela }
107809d6c965SJuan Quintela if (params->has_announce_max &&
107909d6c965SJuan Quintela params->announce_max > 100000) {
108009d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
108109d6c965SJuan Quintela "announce_max",
108209d6c965SJuan Quintela "a value between 0 and 100000");
108309d6c965SJuan Quintela return false;
108409d6c965SJuan Quintela }
108509d6c965SJuan Quintela if (params->has_announce_rounds &&
108609d6c965SJuan Quintela params->announce_rounds > 1000) {
108709d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
108809d6c965SJuan Quintela "announce_rounds",
108909d6c965SJuan Quintela "a value between 0 and 1000");
109009d6c965SJuan Quintela return false;
109109d6c965SJuan Quintela }
109209d6c965SJuan Quintela if (params->has_announce_step &&
109309d6c965SJuan Quintela (params->announce_step < 1 ||
109409d6c965SJuan Quintela params->announce_step > 10000)) {
109509d6c965SJuan Quintela error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
109609d6c965SJuan Quintela "announce_step",
109709d6c965SJuan Quintela "a value between 0 and 10000");
109809d6c965SJuan Quintela return false;
109909d6c965SJuan Quintela }
110009d6c965SJuan Quintela
110109d6c965SJuan Quintela if (params->has_block_bitmap_mapping &&
110209d6c965SJuan Quintela !check_dirty_bitmap_mig_alias_map(params->block_bitmap_mapping, errp)) {
110309d6c965SJuan Quintela error_prepend(errp, "Invalid mapping given for block-bitmap-mapping: ");
110409d6c965SJuan Quintela return false;
110509d6c965SJuan Quintela }
110609d6c965SJuan Quintela
110709d6c965SJuan Quintela #ifdef CONFIG_LINUX
110809d6c965SJuan Quintela if (migrate_zero_copy_send() &&
110909d6c965SJuan Quintela ((params->has_multifd_compression && params->multifd_compression) ||
111009d6c965SJuan Quintela (params->tls_creds && *params->tls_creds))) {
111109d6c965SJuan Quintela error_setg(errp,
111209d6c965SJuan Quintela "Zero copy only available for non-compressed non-TLS multifd migration");
111309d6c965SJuan Quintela return false;
111409d6c965SJuan Quintela }
111509d6c965SJuan Quintela #endif
111609d6c965SJuan Quintela
1117f427d90bSFabiano Rosas if (migrate_mapped_ram() &&
1118f427d90bSFabiano Rosas (migrate_multifd_compression() || migrate_tls())) {
1119f427d90bSFabiano Rosas error_setg(errp,
1120f427d90bSFabiano Rosas "Mapped-ram only available for non-compressed non-TLS multifd migration");
1121f427d90bSFabiano Rosas return false;
1122f427d90bSFabiano Rosas }
1123f427d90bSFabiano Rosas
11244d807857SHyman Huang(黄勇) if (params->has_x_vcpu_dirty_limit_period &&
11254d807857SHyman Huang(黄勇) (params->x_vcpu_dirty_limit_period < 1 ||
11264d807857SHyman Huang(黄勇) params->x_vcpu_dirty_limit_period > 1000)) {
11274d807857SHyman Huang(黄勇) error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
11284d807857SHyman Huang(黄勇) "x-vcpu-dirty-limit-period",
11294d807857SHyman Huang(黄勇) "a value between 1 and 1000");
11304d807857SHyman Huang(黄勇) return false;
11314d807857SHyman Huang(黄勇) }
11324d807857SHyman Huang(黄勇)
113309f9ec99SHyman Huang(黄勇) if (params->has_vcpu_dirty_limit &&
113409f9ec99SHyman Huang(黄勇) (params->vcpu_dirty_limit < 1)) {
113545d19d93SPhilippe Mathieu-Daudé error_setg(errp,
113645d19d93SPhilippe Mathieu-Daudé "Parameter 'vcpu_dirty_limit' must be greater than 1 MB/s");
113709f9ec99SHyman Huang(黄勇) return false;
113809f9ec99SHyman Huang(黄勇) }
113909f9ec99SHyman Huang(黄勇)
1140b43b61d5SFabiano Rosas if (params->has_direct_io && params->direct_io && !qemu_has_direct_io()) {
1141b43b61d5SFabiano Rosas error_setg(errp, "No build-time support for direct-io");
1142b43b61d5SFabiano Rosas return false;
1143b43b61d5SFabiano Rosas }
1144b43b61d5SFabiano Rosas
114509d6c965SJuan Quintela return true;
114609d6c965SJuan Quintela }
114709d6c965SJuan Quintela
migrate_params_test_apply(MigrateSetParameters * params,MigrationParameters * dest)114809d6c965SJuan Quintela static void migrate_params_test_apply(MigrateSetParameters *params,
114909d6c965SJuan Quintela MigrationParameters *dest)
115009d6c965SJuan Quintela {
115109d6c965SJuan Quintela *dest = migrate_get_current()->parameters;
115209d6c965SJuan Quintela
115309d6c965SJuan Quintela /* TODO use QAPI_CLONE() instead of duplicating it inline */
115409d6c965SJuan Quintela
115509d6c965SJuan Quintela if (params->has_throttle_trigger_threshold) {
115609d6c965SJuan Quintela dest->throttle_trigger_threshold = params->throttle_trigger_threshold;
115709d6c965SJuan Quintela }
115809d6c965SJuan Quintela
115909d6c965SJuan Quintela if (params->has_cpu_throttle_initial) {
116009d6c965SJuan Quintela dest->cpu_throttle_initial = params->cpu_throttle_initial;
116109d6c965SJuan Quintela }
116209d6c965SJuan Quintela
116309d6c965SJuan Quintela if (params->has_cpu_throttle_increment) {
116409d6c965SJuan Quintela dest->cpu_throttle_increment = params->cpu_throttle_increment;
116509d6c965SJuan Quintela }
116609d6c965SJuan Quintela
116709d6c965SJuan Quintela if (params->has_cpu_throttle_tailslow) {
116809d6c965SJuan Quintela dest->cpu_throttle_tailslow = params->cpu_throttle_tailslow;
116909d6c965SJuan Quintela }
117009d6c965SJuan Quintela
117109d6c965SJuan Quintela if (params->tls_creds) {
117209d6c965SJuan Quintela assert(params->tls_creds->type == QTYPE_QSTRING);
117309d6c965SJuan Quintela dest->tls_creds = params->tls_creds->u.s;
117409d6c965SJuan Quintela }
117509d6c965SJuan Quintela
117609d6c965SJuan Quintela if (params->tls_hostname) {
117709d6c965SJuan Quintela assert(params->tls_hostname->type == QTYPE_QSTRING);
117809d6c965SJuan Quintela dest->tls_hostname = params->tls_hostname->u.s;
117909d6c965SJuan Quintela }
118009d6c965SJuan Quintela
118109d6c965SJuan Quintela if (params->has_max_bandwidth) {
118209d6c965SJuan Quintela dest->max_bandwidth = params->max_bandwidth;
118309d6c965SJuan Quintela }
118409d6c965SJuan Quintela
11858b239597SPeter Xu if (params->has_avail_switchover_bandwidth) {
11868b239597SPeter Xu dest->avail_switchover_bandwidth = params->avail_switchover_bandwidth;
11878b239597SPeter Xu }
11888b239597SPeter Xu
118909d6c965SJuan Quintela if (params->has_downtime_limit) {
119009d6c965SJuan Quintela dest->downtime_limit = params->downtime_limit;
119109d6c965SJuan Quintela }
119209d6c965SJuan Quintela
119309d6c965SJuan Quintela if (params->has_x_checkpoint_delay) {
119409d6c965SJuan Quintela dest->x_checkpoint_delay = params->x_checkpoint_delay;
119509d6c965SJuan Quintela }
119609d6c965SJuan Quintela
119709d6c965SJuan Quintela if (params->has_multifd_channels) {
119809d6c965SJuan Quintela dest->multifd_channels = params->multifd_channels;
119909d6c965SJuan Quintela }
120009d6c965SJuan Quintela if (params->has_multifd_compression) {
120109d6c965SJuan Quintela dest->multifd_compression = params->multifd_compression;
120209d6c965SJuan Quintela }
120386c6eb1fSBryan Zhang if (params->has_multifd_qatzip_level) {
120486c6eb1fSBryan Zhang dest->multifd_qatzip_level = params->multifd_qatzip_level;
120586c6eb1fSBryan Zhang }
1206b4014a2bSBryan Zhang if (params->has_multifd_zlib_level) {
1207b4014a2bSBryan Zhang dest->multifd_zlib_level = params->multifd_zlib_level;
1208b4014a2bSBryan Zhang }
1209b4014a2bSBryan Zhang if (params->has_multifd_zstd_level) {
1210b4014a2bSBryan Zhang dest->multifd_zstd_level = params->multifd_zstd_level;
1211b4014a2bSBryan Zhang }
121209d6c965SJuan Quintela if (params->has_xbzrle_cache_size) {
121309d6c965SJuan Quintela dest->xbzrle_cache_size = params->xbzrle_cache_size;
121409d6c965SJuan Quintela }
121509d6c965SJuan Quintela if (params->has_max_postcopy_bandwidth) {
121609d6c965SJuan Quintela dest->max_postcopy_bandwidth = params->max_postcopy_bandwidth;
121709d6c965SJuan Quintela }
121809d6c965SJuan Quintela if (params->has_max_cpu_throttle) {
121909d6c965SJuan Quintela dest->max_cpu_throttle = params->max_cpu_throttle;
122009d6c965SJuan Quintela }
122109d6c965SJuan Quintela if (params->has_announce_initial) {
122209d6c965SJuan Quintela dest->announce_initial = params->announce_initial;
122309d6c965SJuan Quintela }
122409d6c965SJuan Quintela if (params->has_announce_max) {
122509d6c965SJuan Quintela dest->announce_max = params->announce_max;
122609d6c965SJuan Quintela }
122709d6c965SJuan Quintela if (params->has_announce_rounds) {
122809d6c965SJuan Quintela dest->announce_rounds = params->announce_rounds;
122909d6c965SJuan Quintela }
123009d6c965SJuan Quintela if (params->has_announce_step) {
123109d6c965SJuan Quintela dest->announce_step = params->announce_step;
123209d6c965SJuan Quintela }
123309d6c965SJuan Quintela
123409d6c965SJuan Quintela if (params->has_block_bitmap_mapping) {
123509d6c965SJuan Quintela dest->has_block_bitmap_mapping = true;
123609d6c965SJuan Quintela dest->block_bitmap_mapping = params->block_bitmap_mapping;
123709d6c965SJuan Quintela }
12384d807857SHyman Huang(黄勇)
12394d807857SHyman Huang(黄勇) if (params->has_x_vcpu_dirty_limit_period) {
12404d807857SHyman Huang(黄勇) dest->x_vcpu_dirty_limit_period =
12414d807857SHyman Huang(黄勇) params->x_vcpu_dirty_limit_period;
12424d807857SHyman Huang(黄勇) }
124309f9ec99SHyman Huang(黄勇) if (params->has_vcpu_dirty_limit) {
124409f9ec99SHyman Huang(黄勇) dest->vcpu_dirty_limit = params->vcpu_dirty_limit;
124509f9ec99SHyman Huang(黄勇) }
1246eea1e5c9SSteve Sistare
1247eea1e5c9SSteve Sistare if (params->has_mode) {
1248eea1e5c9SSteve Sistare dest->mode = params->mode;
1249eea1e5c9SSteve Sistare }
12505fdbb1dfSHao Xiang
12515fdbb1dfSHao Xiang if (params->has_zero_page_detection) {
12525fdbb1dfSHao Xiang dest->zero_page_detection = params->zero_page_detection;
12535fdbb1dfSHao Xiang }
1254b43b61d5SFabiano Rosas
1255b43b61d5SFabiano Rosas if (params->has_direct_io) {
1256b43b61d5SFabiano Rosas dest->direct_io = params->direct_io;
1257b43b61d5SFabiano Rosas }
125809d6c965SJuan Quintela }
125909d6c965SJuan Quintela
migrate_params_apply(MigrateSetParameters * params,Error ** errp)126009d6c965SJuan Quintela static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
126109d6c965SJuan Quintela {
126209d6c965SJuan Quintela MigrationState *s = migrate_get_current();
126309d6c965SJuan Quintela
126409d6c965SJuan Quintela /* TODO use QAPI_CLONE() instead of duplicating it inline */
126509d6c965SJuan Quintela
126609d6c965SJuan Quintela if (params->has_throttle_trigger_threshold) {
126709d6c965SJuan Quintela s->parameters.throttle_trigger_threshold = params->throttle_trigger_threshold;
126809d6c965SJuan Quintela }
126909d6c965SJuan Quintela
127009d6c965SJuan Quintela if (params->has_cpu_throttle_initial) {
127109d6c965SJuan Quintela s->parameters.cpu_throttle_initial = params->cpu_throttle_initial;
127209d6c965SJuan Quintela }
127309d6c965SJuan Quintela
127409d6c965SJuan Quintela if (params->has_cpu_throttle_increment) {
127509d6c965SJuan Quintela s->parameters.cpu_throttle_increment = params->cpu_throttle_increment;
127609d6c965SJuan Quintela }
127709d6c965SJuan Quintela
127809d6c965SJuan Quintela if (params->has_cpu_throttle_tailslow) {
127909d6c965SJuan Quintela s->parameters.cpu_throttle_tailslow = params->cpu_throttle_tailslow;
128009d6c965SJuan Quintela }
128109d6c965SJuan Quintela
128209d6c965SJuan Quintela if (params->tls_creds) {
128309d6c965SJuan Quintela g_free(s->parameters.tls_creds);
128409d6c965SJuan Quintela assert(params->tls_creds->type == QTYPE_QSTRING);
128509d6c965SJuan Quintela s->parameters.tls_creds = g_strdup(params->tls_creds->u.s);
128609d6c965SJuan Quintela }
128709d6c965SJuan Quintela
128809d6c965SJuan Quintela if (params->tls_hostname) {
128909d6c965SJuan Quintela g_free(s->parameters.tls_hostname);
129009d6c965SJuan Quintela assert(params->tls_hostname->type == QTYPE_QSTRING);
129109d6c965SJuan Quintela s->parameters.tls_hostname = g_strdup(params->tls_hostname->u.s);
129209d6c965SJuan Quintela }
129309d6c965SJuan Quintela
129409d6c965SJuan Quintela if (params->tls_authz) {
129509d6c965SJuan Quintela g_free(s->parameters.tls_authz);
129609d6c965SJuan Quintela assert(params->tls_authz->type == QTYPE_QSTRING);
129709d6c965SJuan Quintela s->parameters.tls_authz = g_strdup(params->tls_authz->u.s);
129809d6c965SJuan Quintela }
129909d6c965SJuan Quintela
130009d6c965SJuan Quintela if (params->has_max_bandwidth) {
130109d6c965SJuan Quintela s->parameters.max_bandwidth = params->max_bandwidth;
130209d6c965SJuan Quintela if (s->to_dst_file && !migration_in_postcopy()) {
1303e1fde0e0SJuan Quintela migration_rate_set(s->parameters.max_bandwidth);
130409d6c965SJuan Quintela }
130509d6c965SJuan Quintela }
130609d6c965SJuan Quintela
13078b239597SPeter Xu if (params->has_avail_switchover_bandwidth) {
13088b239597SPeter Xu s->parameters.avail_switchover_bandwidth = params->avail_switchover_bandwidth;
13098b239597SPeter Xu }
13108b239597SPeter Xu
131109d6c965SJuan Quintela if (params->has_downtime_limit) {
131209d6c965SJuan Quintela s->parameters.downtime_limit = params->downtime_limit;
131309d6c965SJuan Quintela }
131409d6c965SJuan Quintela
131509d6c965SJuan Quintela if (params->has_x_checkpoint_delay) {
131609d6c965SJuan Quintela s->parameters.x_checkpoint_delay = params->x_checkpoint_delay;
13174332ffcdSVladimir Sementsov-Ogievskiy colo_checkpoint_delay_set();
131809d6c965SJuan Quintela }
131909d6c965SJuan Quintela
132009d6c965SJuan Quintela if (params->has_multifd_channels) {
132109d6c965SJuan Quintela s->parameters.multifd_channels = params->multifd_channels;
132209d6c965SJuan Quintela }
132309d6c965SJuan Quintela if (params->has_multifd_compression) {
132409d6c965SJuan Quintela s->parameters.multifd_compression = params->multifd_compression;
132509d6c965SJuan Quintela }
132686c6eb1fSBryan Zhang if (params->has_multifd_qatzip_level) {
132786c6eb1fSBryan Zhang s->parameters.multifd_qatzip_level = params->multifd_qatzip_level;
132886c6eb1fSBryan Zhang }
1329b4014a2bSBryan Zhang if (params->has_multifd_zlib_level) {
1330b4014a2bSBryan Zhang s->parameters.multifd_zlib_level = params->multifd_zlib_level;
1331b4014a2bSBryan Zhang }
1332b4014a2bSBryan Zhang if (params->has_multifd_zstd_level) {
1333b4014a2bSBryan Zhang s->parameters.multifd_zstd_level = params->multifd_zstd_level;
1334b4014a2bSBryan Zhang }
133509d6c965SJuan Quintela if (params->has_xbzrle_cache_size) {
133609d6c965SJuan Quintela s->parameters.xbzrle_cache_size = params->xbzrle_cache_size;
133709d6c965SJuan Quintela xbzrle_cache_resize(params->xbzrle_cache_size, errp);
133809d6c965SJuan Quintela }
133909d6c965SJuan Quintela if (params->has_max_postcopy_bandwidth) {
134009d6c965SJuan Quintela s->parameters.max_postcopy_bandwidth = params->max_postcopy_bandwidth;
134109d6c965SJuan Quintela if (s->to_dst_file && migration_in_postcopy()) {
1342e1fde0e0SJuan Quintela migration_rate_set(s->parameters.max_postcopy_bandwidth);
134309d6c965SJuan Quintela }
134409d6c965SJuan Quintela }
134509d6c965SJuan Quintela if (params->has_max_cpu_throttle) {
134609d6c965SJuan Quintela s->parameters.max_cpu_throttle = params->max_cpu_throttle;
134709d6c965SJuan Quintela }
134809d6c965SJuan Quintela if (params->has_announce_initial) {
134909d6c965SJuan Quintela s->parameters.announce_initial = params->announce_initial;
135009d6c965SJuan Quintela }
135109d6c965SJuan Quintela if (params->has_announce_max) {
135209d6c965SJuan Quintela s->parameters.announce_max = params->announce_max;
135309d6c965SJuan Quintela }
135409d6c965SJuan Quintela if (params->has_announce_rounds) {
135509d6c965SJuan Quintela s->parameters.announce_rounds = params->announce_rounds;
135609d6c965SJuan Quintela }
135709d6c965SJuan Quintela if (params->has_announce_step) {
135809d6c965SJuan Quintela s->parameters.announce_step = params->announce_step;
135909d6c965SJuan Quintela }
136009d6c965SJuan Quintela
136109d6c965SJuan Quintela if (params->has_block_bitmap_mapping) {
136209d6c965SJuan Quintela qapi_free_BitmapMigrationNodeAliasList(
136309d6c965SJuan Quintela s->parameters.block_bitmap_mapping);
136409d6c965SJuan Quintela
136509d6c965SJuan Quintela s->parameters.has_block_bitmap_mapping = true;
136609d6c965SJuan Quintela s->parameters.block_bitmap_mapping =
136709d6c965SJuan Quintela QAPI_CLONE(BitmapMigrationNodeAliasList,
136809d6c965SJuan Quintela params->block_bitmap_mapping);
136909d6c965SJuan Quintela }
13704d807857SHyman Huang(黄勇)
13714d807857SHyman Huang(黄勇) if (params->has_x_vcpu_dirty_limit_period) {
13724d807857SHyman Huang(黄勇) s->parameters.x_vcpu_dirty_limit_period =
13734d807857SHyman Huang(黄勇) params->x_vcpu_dirty_limit_period;
13744d807857SHyman Huang(黄勇) }
137509f9ec99SHyman Huang(黄勇) if (params->has_vcpu_dirty_limit) {
137609f9ec99SHyman Huang(黄勇) s->parameters.vcpu_dirty_limit = params->vcpu_dirty_limit;
137709f9ec99SHyman Huang(黄勇) }
1378eea1e5c9SSteve Sistare
1379eea1e5c9SSteve Sistare if (params->has_mode) {
1380eea1e5c9SSteve Sistare s->parameters.mode = params->mode;
1381eea1e5c9SSteve Sistare }
13825fdbb1dfSHao Xiang
13835fdbb1dfSHao Xiang if (params->has_zero_page_detection) {
13845fdbb1dfSHao Xiang s->parameters.zero_page_detection = params->zero_page_detection;
13855fdbb1dfSHao Xiang }
1386b43b61d5SFabiano Rosas
1387b43b61d5SFabiano Rosas if (params->has_direct_io) {
1388b43b61d5SFabiano Rosas s->parameters.direct_io = params->direct_io;
1389b43b61d5SFabiano Rosas }
139009d6c965SJuan Quintela }
139109d6c965SJuan Quintela
qmp_migrate_set_parameters(MigrateSetParameters * params,Error ** errp)139209d6c965SJuan Quintela void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp)
139309d6c965SJuan Quintela {
139409d6c965SJuan Quintela MigrationParameters tmp;
139509d6c965SJuan Quintela
139686dec715SPeter Xu /* TODO Rewrite "" to null instead for all three tls_* parameters */
139709d6c965SJuan Quintela if (params->tls_creds
139809d6c965SJuan Quintela && params->tls_creds->type == QTYPE_QNULL) {
139909d6c965SJuan Quintela qobject_unref(params->tls_creds->u.n);
140009d6c965SJuan Quintela params->tls_creds->type = QTYPE_QSTRING;
140109d6c965SJuan Quintela params->tls_creds->u.s = strdup("");
140209d6c965SJuan Quintela }
140309d6c965SJuan Quintela if (params->tls_hostname
140409d6c965SJuan Quintela && params->tls_hostname->type == QTYPE_QNULL) {
140509d6c965SJuan Quintela qobject_unref(params->tls_hostname->u.n);
140609d6c965SJuan Quintela params->tls_hostname->type = QTYPE_QSTRING;
140709d6c965SJuan Quintela params->tls_hostname->u.s = strdup("");
140809d6c965SJuan Quintela }
140986dec715SPeter Xu if (params->tls_authz
141086dec715SPeter Xu && params->tls_authz->type == QTYPE_QNULL) {
141186dec715SPeter Xu qobject_unref(params->tls_authz->u.n);
141286dec715SPeter Xu params->tls_authz->type = QTYPE_QSTRING;
141386dec715SPeter Xu params->tls_authz->u.s = strdup("");
141486dec715SPeter Xu }
141509d6c965SJuan Quintela
141609d6c965SJuan Quintela migrate_params_test_apply(params, &tmp);
141709d6c965SJuan Quintela
141809d6c965SJuan Quintela if (!migrate_params_check(&tmp, errp)) {
141909d6c965SJuan Quintela /* Invalid parameter */
142009d6c965SJuan Quintela return;
142109d6c965SJuan Quintela }
142209d6c965SJuan Quintela
142309d6c965SJuan Quintela migrate_params_apply(params, errp);
142409d6c965SJuan Quintela }
1425