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