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