2 * QEMU migration capabilities
4 * Copyright (c) 2012-2023 Red Hat Inc
7 * Orit Wasserman <owasserm@redhat.com>
8 * Juan Quintela <quintela@redhat.com>
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.
14 #include "qemu/osdep.h"
15 #include "qemu/error-report.h"
16 #include "exec/target_page.h"
17 #include "qapi/clone-visitor.h"
18 #include "qapi/error.h"
19 #include "qapi/qapi-commands-migration.h"
20 #include "qapi/qapi-visit-migration.h"
21 #include "qapi/qmp/qerror.h"
22 #include "qapi/qmp/qnull.h"
23 #include "sysemu/runstate.h"
24 #include "migration/colo.h"
25 #include "migration/misc.h"
26 #include "migration.h"
27 #include "migration-stats.h"
28 #include "qemu-file.h"
31 #include "sysemu/kvm.h"
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)
37 #define MAX_THROTTLE (128 << 20) /* Migration transfer speed throttling */
39 /* Time in milliseconds we are allowed to stop the source,
40 * for sending the last part */
41 #define DEFAULT_MIGRATE_SET_DOWNTIME 300
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
56 /* Migration XBZRLE default cache size */
57 #define DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE (64 * 1024 * 1024)
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
68 /* Background transfer rate for postcopy, 0 means unlimited, note
69 * that page requests can still exceed this limit.
71 #define DEFAULT_MIGRATE_MAX_POSTCOPY_BANDWIDTH 0
74 * Parameters for self_announce_delay giving a stream of RARP/ARP
75 * packets after migration.
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
82 #define DEFINE_PROP_MIG_CAP(name, x) \
83 DEFINE_PROP_BOOL(name, MigrationState, capabilities[x], false)
85 #define DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD 1000 /* milliseconds */
86 #define DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT 1 /* MB/s */
88 Property migration_properties
[] = {
89 DEFINE_PROP_BOOL("store-global-state", MigrationState
,
90 store_global_state
, true),
91 DEFINE_PROP_BOOL("send-configuration", MigrationState
,
92 send_configuration
, true),
93 DEFINE_PROP_BOOL("send-section-footer", MigrationState
,
94 send_section_footer
, true),
95 DEFINE_PROP_BOOL("decompress-error-check", MigrationState
,
96 decompress_error_check
, true),
97 DEFINE_PROP_BOOL("multifd-flush-after-each-section", MigrationState
,
98 multifd_flush_after_each_section
, false),
99 DEFINE_PROP_UINT8("x-clear-bitmap-shift", MigrationState
,
100 clear_bitmap_shift
, CLEAR_BITMAP_SHIFT_DEFAULT
),
101 DEFINE_PROP_BOOL("x-preempt-pre-7-2", MigrationState
,
102 preempt_pre_7_2
, false),
104 /* Migration parameters */
105 DEFINE_PROP_UINT8("x-compress-level", MigrationState
,
106 parameters
.compress_level
,
107 DEFAULT_MIGRATE_COMPRESS_LEVEL
),
108 DEFINE_PROP_UINT8("x-compress-threads", MigrationState
,
109 parameters
.compress_threads
,
110 DEFAULT_MIGRATE_COMPRESS_THREAD_COUNT
),
111 DEFINE_PROP_BOOL("x-compress-wait-thread", MigrationState
,
112 parameters
.compress_wait_thread
, true),
113 DEFINE_PROP_UINT8("x-decompress-threads", MigrationState
,
114 parameters
.decompress_threads
,
115 DEFAULT_MIGRATE_DECOMPRESS_THREAD_COUNT
),
116 DEFINE_PROP_UINT8("x-throttle-trigger-threshold", MigrationState
,
117 parameters
.throttle_trigger_threshold
,
118 DEFAULT_MIGRATE_THROTTLE_TRIGGER_THRESHOLD
),
119 DEFINE_PROP_UINT8("x-cpu-throttle-initial", MigrationState
,
120 parameters
.cpu_throttle_initial
,
121 DEFAULT_MIGRATE_CPU_THROTTLE_INITIAL
),
122 DEFINE_PROP_UINT8("x-cpu-throttle-increment", MigrationState
,
123 parameters
.cpu_throttle_increment
,
124 DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT
),
125 DEFINE_PROP_BOOL("x-cpu-throttle-tailslow", MigrationState
,
126 parameters
.cpu_throttle_tailslow
, false),
127 DEFINE_PROP_SIZE("x-max-bandwidth", MigrationState
,
128 parameters
.max_bandwidth
, MAX_THROTTLE
),
129 DEFINE_PROP_SIZE("avail-switchover-bandwidth", MigrationState
,
130 parameters
.avail_switchover_bandwidth
, 0),
131 DEFINE_PROP_UINT64("x-downtime-limit", MigrationState
,
132 parameters
.downtime_limit
,
133 DEFAULT_MIGRATE_SET_DOWNTIME
),
134 DEFINE_PROP_UINT32("x-checkpoint-delay", MigrationState
,
135 parameters
.x_checkpoint_delay
,
136 DEFAULT_MIGRATE_X_CHECKPOINT_DELAY
),
137 DEFINE_PROP_UINT8("multifd-channels", MigrationState
,
138 parameters
.multifd_channels
,
139 DEFAULT_MIGRATE_MULTIFD_CHANNELS
),
140 DEFINE_PROP_MULTIFD_COMPRESSION("multifd-compression", MigrationState
,
141 parameters
.multifd_compression
,
142 DEFAULT_MIGRATE_MULTIFD_COMPRESSION
),
143 DEFINE_PROP_UINT8("multifd-zlib-level", MigrationState
,
144 parameters
.multifd_zlib_level
,
145 DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL
),
146 DEFINE_PROP_UINT8("multifd-zstd-level", MigrationState
,
147 parameters
.multifd_zstd_level
,
148 DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL
),
149 DEFINE_PROP_SIZE("xbzrle-cache-size", MigrationState
,
150 parameters
.xbzrle_cache_size
,
151 DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE
),
152 DEFINE_PROP_SIZE("max-postcopy-bandwidth", MigrationState
,
153 parameters
.max_postcopy_bandwidth
,
154 DEFAULT_MIGRATE_MAX_POSTCOPY_BANDWIDTH
),
155 DEFINE_PROP_UINT8("max-cpu-throttle", MigrationState
,
156 parameters
.max_cpu_throttle
,
157 DEFAULT_MIGRATE_MAX_CPU_THROTTLE
),
158 DEFINE_PROP_SIZE("announce-initial", MigrationState
,
159 parameters
.announce_initial
,
160 DEFAULT_MIGRATE_ANNOUNCE_INITIAL
),
161 DEFINE_PROP_SIZE("announce-max", MigrationState
,
162 parameters
.announce_max
,
163 DEFAULT_MIGRATE_ANNOUNCE_MAX
),
164 DEFINE_PROP_SIZE("announce-rounds", MigrationState
,
165 parameters
.announce_rounds
,
166 DEFAULT_MIGRATE_ANNOUNCE_ROUNDS
),
167 DEFINE_PROP_SIZE("announce-step", MigrationState
,
168 parameters
.announce_step
,
169 DEFAULT_MIGRATE_ANNOUNCE_STEP
),
170 DEFINE_PROP_STRING("tls-creds", MigrationState
, parameters
.tls_creds
),
171 DEFINE_PROP_STRING("tls-hostname", MigrationState
, parameters
.tls_hostname
),
172 DEFINE_PROP_STRING("tls-authz", MigrationState
, parameters
.tls_authz
),
173 DEFINE_PROP_UINT64("x-vcpu-dirty-limit-period", MigrationState
,
174 parameters
.x_vcpu_dirty_limit_period
,
175 DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD
),
176 DEFINE_PROP_UINT64("vcpu-dirty-limit", MigrationState
,
177 parameters
.vcpu_dirty_limit
,
178 DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT
),
179 DEFINE_PROP_MIG_MODE("mode", MigrationState
,
182 DEFINE_PROP_ZERO_PAGE_DETECTION("zero-page-detection", MigrationState
,
183 parameters
.zero_page_detection
,
184 ZERO_PAGE_DETECTION_MULTIFD
),
186 /* Migration capabilities */
187 DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE
),
188 DEFINE_PROP_MIG_CAP("x-rdma-pin-all", MIGRATION_CAPABILITY_RDMA_PIN_ALL
),
189 DEFINE_PROP_MIG_CAP("x-auto-converge", MIGRATION_CAPABILITY_AUTO_CONVERGE
),
190 DEFINE_PROP_MIG_CAP("x-zero-blocks", MIGRATION_CAPABILITY_ZERO_BLOCKS
),
191 DEFINE_PROP_MIG_CAP("x-compress", MIGRATION_CAPABILITY_COMPRESS
),
192 DEFINE_PROP_MIG_CAP("x-events", MIGRATION_CAPABILITY_EVENTS
),
193 DEFINE_PROP_MIG_CAP("x-postcopy-ram", MIGRATION_CAPABILITY_POSTCOPY_RAM
),
194 DEFINE_PROP_MIG_CAP("x-postcopy-preempt",
195 MIGRATION_CAPABILITY_POSTCOPY_PREEMPT
),
196 DEFINE_PROP_MIG_CAP("x-colo", MIGRATION_CAPABILITY_X_COLO
),
197 DEFINE_PROP_MIG_CAP("x-release-ram", MIGRATION_CAPABILITY_RELEASE_RAM
),
198 DEFINE_PROP_MIG_CAP("x-block", MIGRATION_CAPABILITY_BLOCK
),
199 DEFINE_PROP_MIG_CAP("x-return-path", MIGRATION_CAPABILITY_RETURN_PATH
),
200 DEFINE_PROP_MIG_CAP("x-multifd", MIGRATION_CAPABILITY_MULTIFD
),
201 DEFINE_PROP_MIG_CAP("x-background-snapshot",
202 MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT
),
204 DEFINE_PROP_MIG_CAP("x-zero-copy-send",
205 MIGRATION_CAPABILITY_ZERO_COPY_SEND
),
207 DEFINE_PROP_MIG_CAP("x-switchover-ack",
208 MIGRATION_CAPABILITY_SWITCHOVER_ACK
),
209 DEFINE_PROP_MIG_CAP("x-dirty-limit", MIGRATION_CAPABILITY_DIRTY_LIMIT
),
210 DEFINE_PROP_MIG_CAP("mapped-ram", MIGRATION_CAPABILITY_MAPPED_RAM
),
211 DEFINE_PROP_END_OF_LIST(),
214 bool migrate_auto_converge(void)
216 MigrationState
*s
= migrate_get_current();
218 return s
->capabilities
[MIGRATION_CAPABILITY_AUTO_CONVERGE
];
221 bool migrate_background_snapshot(void)
223 MigrationState
*s
= migrate_get_current();
225 return s
->capabilities
[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT
];
228 bool migrate_block(void)
230 MigrationState
*s
= migrate_get_current();
232 return s
->capabilities
[MIGRATION_CAPABILITY_BLOCK
];
235 bool migrate_colo(void)
237 MigrationState
*s
= migrate_get_current();
239 return s
->capabilities
[MIGRATION_CAPABILITY_X_COLO
];
242 bool migrate_compress(void)
244 MigrationState
*s
= migrate_get_current();
246 return s
->capabilities
[MIGRATION_CAPABILITY_COMPRESS
];
249 bool migrate_dirty_bitmaps(void)
251 MigrationState
*s
= migrate_get_current();
253 return s
->capabilities
[MIGRATION_CAPABILITY_DIRTY_BITMAPS
];
256 bool migrate_dirty_limit(void)
258 MigrationState
*s
= migrate_get_current();
260 return s
->capabilities
[MIGRATION_CAPABILITY_DIRTY_LIMIT
];
263 bool migrate_events(void)
265 MigrationState
*s
= migrate_get_current();
267 return s
->capabilities
[MIGRATION_CAPABILITY_EVENTS
];
270 bool migrate_mapped_ram(void)
272 MigrationState
*s
= migrate_get_current();
274 return s
->capabilities
[MIGRATION_CAPABILITY_MAPPED_RAM
];
277 bool migrate_ignore_shared(void)
279 MigrationState
*s
= migrate_get_current();
281 return s
->capabilities
[MIGRATION_CAPABILITY_X_IGNORE_SHARED
];
284 bool migrate_late_block_activate(void)
286 MigrationState
*s
= migrate_get_current();
288 return s
->capabilities
[MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE
];
291 bool migrate_multifd(void)
293 MigrationState
*s
= migrate_get_current();
295 return s
->capabilities
[MIGRATION_CAPABILITY_MULTIFD
];
298 bool migrate_pause_before_switchover(void)
300 MigrationState
*s
= migrate_get_current();
302 return s
->capabilities
[MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER
];
305 bool migrate_postcopy_blocktime(void)
307 MigrationState
*s
= migrate_get_current();
309 return s
->capabilities
[MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME
];
312 bool migrate_postcopy_preempt(void)
314 MigrationState
*s
= migrate_get_current();
316 return s
->capabilities
[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT
];
319 bool migrate_postcopy_ram(void)
321 MigrationState
*s
= migrate_get_current();
323 return s
->capabilities
[MIGRATION_CAPABILITY_POSTCOPY_RAM
];
326 bool migrate_rdma_pin_all(void)
328 MigrationState
*s
= migrate_get_current();
330 return s
->capabilities
[MIGRATION_CAPABILITY_RDMA_PIN_ALL
];
333 bool migrate_release_ram(void)
335 MigrationState
*s
= migrate_get_current();
337 return s
->capabilities
[MIGRATION_CAPABILITY_RELEASE_RAM
];
340 bool migrate_return_path(void)
342 MigrationState
*s
= migrate_get_current();
344 return s
->capabilities
[MIGRATION_CAPABILITY_RETURN_PATH
];
347 bool migrate_switchover_ack(void)
349 MigrationState
*s
= migrate_get_current();
351 return s
->capabilities
[MIGRATION_CAPABILITY_SWITCHOVER_ACK
];
354 bool migrate_validate_uuid(void)
356 MigrationState
*s
= migrate_get_current();
358 return s
->capabilities
[MIGRATION_CAPABILITY_VALIDATE_UUID
];
361 bool migrate_xbzrle(void)
363 MigrationState
*s
= migrate_get_current();
365 return s
->capabilities
[MIGRATION_CAPABILITY_XBZRLE
];
368 bool migrate_zero_blocks(void)
370 MigrationState
*s
= migrate_get_current();
372 return s
->capabilities
[MIGRATION_CAPABILITY_ZERO_BLOCKS
];
375 bool migrate_zero_copy_send(void)
377 MigrationState
*s
= migrate_get_current();
379 return s
->capabilities
[MIGRATION_CAPABILITY_ZERO_COPY_SEND
];
382 /* pseudo capabilities */
384 bool migrate_multifd_flush_after_each_section(void)
386 MigrationState
*s
= migrate_get_current();
388 return s
->multifd_flush_after_each_section
;
391 bool migrate_postcopy(void)
393 return migrate_postcopy_ram() || migrate_dirty_bitmaps();
396 bool migrate_rdma(void)
398 MigrationState
*s
= migrate_get_current();
400 return s
->rdma_migration
;
403 bool migrate_tls(void)
405 MigrationState
*s
= migrate_get_current();
407 return s
->parameters
.tls_creds
&& *s
->parameters
.tls_creds
;
410 typedef enum WriteTrackingSupport
{
411 WT_SUPPORT_UNKNOWN
= 0,
413 WT_SUPPORT_AVAILABLE
,
414 WT_SUPPORT_COMPATIBLE
415 } WriteTrackingSupport
;
418 WriteTrackingSupport
migrate_query_write_tracking(void)
420 /* Check if kernel supports required UFFD features */
421 if (!ram_write_tracking_available()) {
422 return WT_SUPPORT_ABSENT
;
425 * Check if current memory configuration is
426 * compatible with required UFFD features.
428 if (!ram_write_tracking_compatible()) {
429 return WT_SUPPORT_AVAILABLE
;
432 return WT_SUPPORT_COMPATIBLE
;
435 /* Migration capabilities set */
436 struct MigrateCapsSet
{
437 int size
; /* Capability set size */
438 MigrationCapability caps
[]; /* Variadic array of capabilities */
440 typedef struct MigrateCapsSet MigrateCapsSet
;
442 /* Define and initialize MigrateCapsSet */
443 #define INITIALIZE_MIGRATE_CAPS_SET(_name, ...) \
444 MigrateCapsSet _name = { \
445 .size = sizeof((int []) { __VA_ARGS__ }) / sizeof(int), \
446 .caps = { __VA_ARGS__ } \
449 /* Background-snapshot compatibility check list */
451 INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snapshot
,
452 MIGRATION_CAPABILITY_POSTCOPY_RAM
,
453 MIGRATION_CAPABILITY_DIRTY_BITMAPS
,
454 MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME
,
455 MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE
,
456 MIGRATION_CAPABILITY_RETURN_PATH
,
457 MIGRATION_CAPABILITY_MULTIFD
,
458 MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER
,
459 MIGRATION_CAPABILITY_AUTO_CONVERGE
,
460 MIGRATION_CAPABILITY_RELEASE_RAM
,
461 MIGRATION_CAPABILITY_RDMA_PIN_ALL
,
462 MIGRATION_CAPABILITY_COMPRESS
,
463 MIGRATION_CAPABILITY_XBZRLE
,
464 MIGRATION_CAPABILITY_X_COLO
,
465 MIGRATION_CAPABILITY_VALIDATE_UUID
,
466 MIGRATION_CAPABILITY_ZERO_COPY_SEND
);
468 static bool migrate_incoming_started(void)
470 return !!migration_incoming_get_current()->transport_data
;
474 * @migration_caps_check - check capability compatibility
476 * @old_caps: old capability list
477 * @new_caps: new capability list
478 * @errp: set *errp if the check failed, with reason
480 * Returns true if check passed, otherwise false.
482 bool migrate_caps_check(bool *old_caps
, bool *new_caps
, Error
**errp
)
485 MigrationIncomingState
*mis
= migration_incoming_get_current();
487 #ifndef CONFIG_LIVE_BLOCK_MIGRATION
488 if (new_caps
[MIGRATION_CAPABILITY_BLOCK
]) {
489 error_setg(errp
, "QEMU compiled without old-style (blk/-b, inc/-i) "
491 error_append_hint(errp
, "Use blockdev-mirror with NBD instead.\n");
495 if (new_caps
[MIGRATION_CAPABILITY_BLOCK
]) {
496 warn_report("block migration is deprecated;"
497 " use blockdev-mirror with NBD instead");
500 if (new_caps
[MIGRATION_CAPABILITY_COMPRESS
]) {
501 warn_report("old compression method is deprecated;"
502 " use multifd compression methods instead");
505 #ifndef CONFIG_REPLICATION
506 if (new_caps
[MIGRATION_CAPABILITY_X_COLO
]) {
507 error_setg(errp
, "QEMU compiled without replication module"
508 " can't enable COLO");
509 error_append_hint(errp
, "Please enable replication before COLO.\n");
514 if (new_caps
[MIGRATION_CAPABILITY_POSTCOPY_RAM
]) {
515 /* This check is reasonably expensive, so only when it's being
516 * set the first time, also it's only the destination that needs
519 if (!old_caps
[MIGRATION_CAPABILITY_POSTCOPY_RAM
] &&
520 runstate_check(RUN_STATE_INMIGRATE
) &&
521 !postcopy_ram_supported_by_host(mis
, errp
)) {
522 error_prepend(errp
, "Postcopy is not supported: ");
526 if (new_caps
[MIGRATION_CAPABILITY_X_IGNORE_SHARED
]) {
527 error_setg(errp
, "Postcopy is not compatible with ignore-shared");
531 if (new_caps
[MIGRATION_CAPABILITY_MULTIFD
]) {
532 error_setg(errp
, "Postcopy is not yet compatible with multifd");
537 if (new_caps
[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT
]) {
538 WriteTrackingSupport wt_support
;
541 * Check if 'background-snapshot' capability is supported by
542 * host kernel and compatible with guest memory configuration.
544 wt_support
= migrate_query_write_tracking();
545 if (wt_support
< WT_SUPPORT_AVAILABLE
) {
546 error_setg(errp
, "Background-snapshot is not supported by host kernel");
549 if (wt_support
< WT_SUPPORT_COMPATIBLE
) {
550 error_setg(errp
, "Background-snapshot is not compatible "
551 "with guest memory configuration");
556 * Check if there are any migration capabilities
557 * incompatible with 'background-snapshot'.
559 for (idx
= 0; idx
< check_caps_background_snapshot
.size
; idx
++) {
560 int incomp_cap
= check_caps_background_snapshot
.caps
[idx
];
561 if (new_caps
[incomp_cap
]) {
563 "Background-snapshot is not compatible with %s",
564 MigrationCapability_str(incomp_cap
));
571 if (new_caps
[MIGRATION_CAPABILITY_ZERO_COPY_SEND
] &&
572 (!new_caps
[MIGRATION_CAPABILITY_MULTIFD
] ||
573 new_caps
[MIGRATION_CAPABILITY_COMPRESS
] ||
574 new_caps
[MIGRATION_CAPABILITY_XBZRLE
] ||
575 migrate_multifd_compression() ||
578 "Zero copy only available for non-compressed non-TLS multifd migration");
582 if (new_caps
[MIGRATION_CAPABILITY_ZERO_COPY_SEND
]) {
584 "Zero copy currently only available on Linux");
589 if (new_caps
[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT
]) {
590 if (!new_caps
[MIGRATION_CAPABILITY_POSTCOPY_RAM
]) {
591 error_setg(errp
, "Postcopy preempt requires postcopy-ram");
596 * Preempt mode requires urgent pages to be sent in separate
597 * channel, OTOH compression logic will disorder all pages into
598 * different compression channels, which is not compatible with the
599 * preempt assumptions on channel assignments.
601 if (new_caps
[MIGRATION_CAPABILITY_COMPRESS
]) {
602 error_setg(errp
, "Postcopy preempt not compatible with compress");
606 if (migrate_incoming_started()) {
608 "Postcopy preempt must be set before incoming starts");
613 if (new_caps
[MIGRATION_CAPABILITY_MULTIFD
]) {
614 if (new_caps
[MIGRATION_CAPABILITY_COMPRESS
]) {
615 error_setg(errp
, "Multifd is not compatible with compress");
618 if (migrate_incoming_started()) {
619 error_setg(errp
, "Multifd must be set before incoming starts");
624 if (new_caps
[MIGRATION_CAPABILITY_SWITCHOVER_ACK
]) {
625 if (!new_caps
[MIGRATION_CAPABILITY_RETURN_PATH
]) {
626 error_setg(errp
, "Capability 'switchover-ack' requires capability "
631 if (new_caps
[MIGRATION_CAPABILITY_DIRTY_LIMIT
]) {
632 if (new_caps
[MIGRATION_CAPABILITY_AUTO_CONVERGE
]) {
633 error_setg(errp
, "dirty-limit conflicts with auto-converge"
634 " either of then available currently");
638 if (!kvm_enabled() || !kvm_dirty_ring_enabled()) {
639 error_setg(errp
, "dirty-limit requires KVM with accelerator"
640 " property 'dirty-ring-size' set");
645 if (new_caps
[MIGRATION_CAPABILITY_MULTIFD
]) {
646 if (new_caps
[MIGRATION_CAPABILITY_XBZRLE
]) {
647 error_setg(errp
, "Multifd is not compatible with xbzrle");
652 if (new_caps
[MIGRATION_CAPABILITY_COMPRESS
]) {
653 if (new_caps
[MIGRATION_CAPABILITY_XBZRLE
]) {
654 error_setg(errp
, "Compression is not compatible with xbzrle");
659 if (new_caps
[MIGRATION_CAPABILITY_MAPPED_RAM
]) {
660 if (new_caps
[MIGRATION_CAPABILITY_XBZRLE
]) {
662 "Mapped-ram migration is incompatible with xbzrle");
666 if (new_caps
[MIGRATION_CAPABILITY_COMPRESS
]) {
668 "Mapped-ram migration is incompatible with compression");
672 if (new_caps
[MIGRATION_CAPABILITY_POSTCOPY_RAM
]) {
674 "Mapped-ram migration is incompatible with postcopy");
682 bool migrate_cap_set(int cap
, bool value
, Error
**errp
)
684 MigrationState
*s
= migrate_get_current();
685 bool new_caps
[MIGRATION_CAPABILITY__MAX
];
687 if (migration_is_running()) {
688 error_setg(errp
, QERR_MIGRATION_ACTIVE
);
692 memcpy(new_caps
, s
->capabilities
, sizeof(new_caps
));
693 new_caps
[cap
] = value
;
695 if (!migrate_caps_check(s
->capabilities
, new_caps
, errp
)) {
698 s
->capabilities
[cap
] = value
;
702 MigrationCapabilityStatusList
*qmp_query_migrate_capabilities(Error
**errp
)
704 MigrationCapabilityStatusList
*head
= NULL
, **tail
= &head
;
705 MigrationCapabilityStatus
*caps
;
706 MigrationState
*s
= migrate_get_current();
709 for (i
= 0; i
< MIGRATION_CAPABILITY__MAX
; i
++) {
710 #ifndef CONFIG_LIVE_BLOCK_MIGRATION
711 if (i
== MIGRATION_CAPABILITY_BLOCK
) {
715 caps
= g_malloc0(sizeof(*caps
));
716 caps
->capability
= i
;
717 caps
->state
= s
->capabilities
[i
];
718 QAPI_LIST_APPEND(tail
, caps
);
724 void qmp_migrate_set_capabilities(MigrationCapabilityStatusList
*params
,
727 MigrationState
*s
= migrate_get_current();
728 MigrationCapabilityStatusList
*cap
;
729 bool new_caps
[MIGRATION_CAPABILITY__MAX
];
731 if (migration_is_running() || migration_in_colo_state()) {
732 error_setg(errp
, QERR_MIGRATION_ACTIVE
);
736 memcpy(new_caps
, s
->capabilities
, sizeof(new_caps
));
737 for (cap
= params
; cap
; cap
= cap
->next
) {
738 new_caps
[cap
->value
->capability
] = cap
->value
->state
;
741 if (!migrate_caps_check(s
->capabilities
, new_caps
, errp
)) {
745 for (cap
= params
; cap
; cap
= cap
->next
) {
746 s
->capabilities
[cap
->value
->capability
] = cap
->value
->state
;
752 const BitmapMigrationNodeAliasList
*migrate_block_bitmap_mapping(void)
754 MigrationState
*s
= migrate_get_current();
756 return s
->parameters
.block_bitmap_mapping
;
759 bool migrate_has_block_bitmap_mapping(void)
761 MigrationState
*s
= migrate_get_current();
763 return s
->parameters
.has_block_bitmap_mapping
;
766 bool migrate_block_incremental(void)
768 MigrationState
*s
= migrate_get_current();
770 return s
->parameters
.block_incremental
;
773 uint32_t migrate_checkpoint_delay(void)
775 MigrationState
*s
= migrate_get_current();
777 return s
->parameters
.x_checkpoint_delay
;
780 int migrate_compress_level(void)
782 MigrationState
*s
= migrate_get_current();
784 return s
->parameters
.compress_level
;
787 int migrate_compress_threads(void)
789 MigrationState
*s
= migrate_get_current();
791 return s
->parameters
.compress_threads
;
794 int migrate_compress_wait_thread(void)
796 MigrationState
*s
= migrate_get_current();
798 return s
->parameters
.compress_wait_thread
;
801 uint8_t migrate_cpu_throttle_increment(void)
803 MigrationState
*s
= migrate_get_current();
805 return s
->parameters
.cpu_throttle_increment
;
808 uint8_t migrate_cpu_throttle_initial(void)
810 MigrationState
*s
= migrate_get_current();
812 return s
->parameters
.cpu_throttle_initial
;
815 bool migrate_cpu_throttle_tailslow(void)
817 MigrationState
*s
= migrate_get_current();
819 return s
->parameters
.cpu_throttle_tailslow
;
822 int migrate_decompress_threads(void)
824 MigrationState
*s
= migrate_get_current();
826 return s
->parameters
.decompress_threads
;
829 uint64_t migrate_downtime_limit(void)
831 MigrationState
*s
= migrate_get_current();
833 return s
->parameters
.downtime_limit
;
836 uint8_t migrate_max_cpu_throttle(void)
838 MigrationState
*s
= migrate_get_current();
840 return s
->parameters
.max_cpu_throttle
;
843 uint64_t migrate_max_bandwidth(void)
845 MigrationState
*s
= migrate_get_current();
847 return s
->parameters
.max_bandwidth
;
850 uint64_t migrate_avail_switchover_bandwidth(void)
852 MigrationState
*s
= migrate_get_current();
854 return s
->parameters
.avail_switchover_bandwidth
;
857 uint64_t migrate_max_postcopy_bandwidth(void)
859 MigrationState
*s
= migrate_get_current();
861 return s
->parameters
.max_postcopy_bandwidth
;
864 MigMode
migrate_mode(void)
866 MigrationState
*s
= migrate_get_current();
867 MigMode mode
= s
->parameters
.mode
;
869 assert(mode
>= 0 && mode
< MIG_MODE__MAX
);
873 int migrate_multifd_channels(void)
875 MigrationState
*s
= migrate_get_current();
877 return s
->parameters
.multifd_channels
;
880 MultiFDCompression
migrate_multifd_compression(void)
882 MigrationState
*s
= migrate_get_current();
884 assert(s
->parameters
.multifd_compression
< MULTIFD_COMPRESSION__MAX
);
885 return s
->parameters
.multifd_compression
;
888 int migrate_multifd_zlib_level(void)
890 MigrationState
*s
= migrate_get_current();
892 return s
->parameters
.multifd_zlib_level
;
895 int migrate_multifd_zstd_level(void)
897 MigrationState
*s
= migrate_get_current();
899 return s
->parameters
.multifd_zstd_level
;
902 uint8_t migrate_throttle_trigger_threshold(void)
904 MigrationState
*s
= migrate_get_current();
906 return s
->parameters
.throttle_trigger_threshold
;
909 const char *migrate_tls_authz(void)
911 MigrationState
*s
= migrate_get_current();
913 return s
->parameters
.tls_authz
;
916 const char *migrate_tls_creds(void)
918 MigrationState
*s
= migrate_get_current();
920 return s
->parameters
.tls_creds
;
923 const char *migrate_tls_hostname(void)
925 MigrationState
*s
= migrate_get_current();
927 return s
->parameters
.tls_hostname
;
930 uint64_t migrate_vcpu_dirty_limit_period(void)
932 MigrationState
*s
= migrate_get_current();
934 return s
->parameters
.x_vcpu_dirty_limit_period
;
937 uint64_t migrate_xbzrle_cache_size(void)
939 MigrationState
*s
= migrate_get_current();
941 return s
->parameters
.xbzrle_cache_size
;
944 ZeroPageDetection
migrate_zero_page_detection(void)
946 MigrationState
*s
= migrate_get_current();
948 return s
->parameters
.zero_page_detection
;
951 /* parameter setters */
953 void migrate_set_block_incremental(bool value
)
955 MigrationState
*s
= migrate_get_current();
957 s
->parameters
.block_incremental
= value
;
960 /* parameters helpers */
962 void block_cleanup_parameters(void)
964 MigrationState
*s
= migrate_get_current();
966 if (s
->must_remove_block_options
) {
967 /* setting to false can never fail */
968 migrate_cap_set(MIGRATION_CAPABILITY_BLOCK
, false, &error_abort
);
969 migrate_set_block_incremental(false);
970 s
->must_remove_block_options
= false;
974 AnnounceParameters
*migrate_announce_params(void)
976 static AnnounceParameters ap
;
978 MigrationState
*s
= migrate_get_current();
980 ap
.initial
= s
->parameters
.announce_initial
;
981 ap
.max
= s
->parameters
.announce_max
;
982 ap
.rounds
= s
->parameters
.announce_rounds
;
983 ap
.step
= s
->parameters
.announce_step
;
988 MigrationParameters
*qmp_query_migrate_parameters(Error
**errp
)
990 MigrationParameters
*params
;
991 MigrationState
*s
= migrate_get_current();
993 /* TODO use QAPI_CLONE() instead of duplicating it inline */
994 params
= g_malloc0(sizeof(*params
));
995 params
->has_compress_level
= true;
996 params
->compress_level
= s
->parameters
.compress_level
;
997 params
->has_compress_threads
= true;
998 params
->compress_threads
= s
->parameters
.compress_threads
;
999 params
->has_compress_wait_thread
= true;
1000 params
->compress_wait_thread
= s
->parameters
.compress_wait_thread
;
1001 params
->has_decompress_threads
= true;
1002 params
->decompress_threads
= s
->parameters
.decompress_threads
;
1003 params
->has_throttle_trigger_threshold
= true;
1004 params
->throttle_trigger_threshold
= s
->parameters
.throttle_trigger_threshold
;
1005 params
->has_cpu_throttle_initial
= true;
1006 params
->cpu_throttle_initial
= s
->parameters
.cpu_throttle_initial
;
1007 params
->has_cpu_throttle_increment
= true;
1008 params
->cpu_throttle_increment
= s
->parameters
.cpu_throttle_increment
;
1009 params
->has_cpu_throttle_tailslow
= true;
1010 params
->cpu_throttle_tailslow
= s
->parameters
.cpu_throttle_tailslow
;
1011 params
->tls_creds
= g_strdup(s
->parameters
.tls_creds
);
1012 params
->tls_hostname
= g_strdup(s
->parameters
.tls_hostname
);
1013 params
->tls_authz
= g_strdup(s
->parameters
.tls_authz
?
1014 s
->parameters
.tls_authz
: "");
1015 params
->has_max_bandwidth
= true;
1016 params
->max_bandwidth
= s
->parameters
.max_bandwidth
;
1017 params
->has_avail_switchover_bandwidth
= true;
1018 params
->avail_switchover_bandwidth
= s
->parameters
.avail_switchover_bandwidth
;
1019 params
->has_downtime_limit
= true;
1020 params
->downtime_limit
= s
->parameters
.downtime_limit
;
1021 params
->has_x_checkpoint_delay
= true;
1022 params
->x_checkpoint_delay
= s
->parameters
.x_checkpoint_delay
;
1023 params
->has_block_incremental
= true;
1024 params
->block_incremental
= s
->parameters
.block_incremental
;
1025 params
->has_multifd_channels
= true;
1026 params
->multifd_channels
= s
->parameters
.multifd_channels
;
1027 params
->has_multifd_compression
= true;
1028 params
->multifd_compression
= s
->parameters
.multifd_compression
;
1029 params
->has_multifd_zlib_level
= true;
1030 params
->multifd_zlib_level
= s
->parameters
.multifd_zlib_level
;
1031 params
->has_multifd_zstd_level
= true;
1032 params
->multifd_zstd_level
= s
->parameters
.multifd_zstd_level
;
1033 params
->has_xbzrle_cache_size
= true;
1034 params
->xbzrle_cache_size
= s
->parameters
.xbzrle_cache_size
;
1035 params
->has_max_postcopy_bandwidth
= true;
1036 params
->max_postcopy_bandwidth
= s
->parameters
.max_postcopy_bandwidth
;
1037 params
->has_max_cpu_throttle
= true;
1038 params
->max_cpu_throttle
= s
->parameters
.max_cpu_throttle
;
1039 params
->has_announce_initial
= true;
1040 params
->announce_initial
= s
->parameters
.announce_initial
;
1041 params
->has_announce_max
= true;
1042 params
->announce_max
= s
->parameters
.announce_max
;
1043 params
->has_announce_rounds
= true;
1044 params
->announce_rounds
= s
->parameters
.announce_rounds
;
1045 params
->has_announce_step
= true;
1046 params
->announce_step
= s
->parameters
.announce_step
;
1048 if (s
->parameters
.has_block_bitmap_mapping
) {
1049 params
->has_block_bitmap_mapping
= true;
1050 params
->block_bitmap_mapping
=
1051 QAPI_CLONE(BitmapMigrationNodeAliasList
,
1052 s
->parameters
.block_bitmap_mapping
);
1055 params
->has_x_vcpu_dirty_limit_period
= true;
1056 params
->x_vcpu_dirty_limit_period
= s
->parameters
.x_vcpu_dirty_limit_period
;
1057 params
->has_vcpu_dirty_limit
= true;
1058 params
->vcpu_dirty_limit
= s
->parameters
.vcpu_dirty_limit
;
1059 params
->has_mode
= true;
1060 params
->mode
= s
->parameters
.mode
;
1061 params
->has_zero_page_detection
= true;
1062 params
->zero_page_detection
= s
->parameters
.zero_page_detection
;
1067 void migrate_params_init(MigrationParameters
*params
)
1069 params
->tls_hostname
= g_strdup("");
1070 params
->tls_creds
= g_strdup("");
1072 /* Set has_* up only for parameter checks */
1073 params
->has_compress_level
= true;
1074 params
->has_compress_threads
= true;
1075 params
->has_compress_wait_thread
= true;
1076 params
->has_decompress_threads
= true;
1077 params
->has_throttle_trigger_threshold
= true;
1078 params
->has_cpu_throttle_initial
= true;
1079 params
->has_cpu_throttle_increment
= true;
1080 params
->has_cpu_throttle_tailslow
= true;
1081 params
->has_max_bandwidth
= true;
1082 params
->has_downtime_limit
= true;
1083 params
->has_x_checkpoint_delay
= true;
1084 params
->has_block_incremental
= true;
1085 params
->has_multifd_channels
= true;
1086 params
->has_multifd_compression
= true;
1087 params
->has_multifd_zlib_level
= true;
1088 params
->has_multifd_zstd_level
= true;
1089 params
->has_xbzrle_cache_size
= true;
1090 params
->has_max_postcopy_bandwidth
= true;
1091 params
->has_max_cpu_throttle
= true;
1092 params
->has_announce_initial
= true;
1093 params
->has_announce_max
= true;
1094 params
->has_announce_rounds
= true;
1095 params
->has_announce_step
= true;
1096 params
->has_x_vcpu_dirty_limit_period
= true;
1097 params
->has_vcpu_dirty_limit
= true;
1098 params
->has_mode
= true;
1099 params
->has_zero_page_detection
= true;
1103 * Check whether the parameters are valid. Error will be put into errp
1104 * (if provided). Return true if valid, otherwise false.
1106 bool migrate_params_check(MigrationParameters
*params
, Error
**errp
)
1110 if (params
->has_compress_level
&&
1111 (params
->compress_level
> 9)) {
1112 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "compress_level",
1113 "a value between 0 and 9");
1117 if (params
->has_compress_threads
&& (params
->compress_threads
< 1)) {
1118 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1120 "a value between 1 and 255");
1124 if (params
->has_decompress_threads
&& (params
->decompress_threads
< 1)) {
1125 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1126 "decompress_threads",
1127 "a value between 1 and 255");
1131 if (params
->has_throttle_trigger_threshold
&&
1132 (params
->throttle_trigger_threshold
< 1 ||
1133 params
->throttle_trigger_threshold
> 100)) {
1134 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1135 "throttle_trigger_threshold",
1136 "an integer in the range of 1 to 100");
1140 if (params
->has_cpu_throttle_initial
&&
1141 (params
->cpu_throttle_initial
< 1 ||
1142 params
->cpu_throttle_initial
> 99)) {
1143 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1144 "cpu_throttle_initial",
1145 "an integer in the range of 1 to 99");
1149 if (params
->has_cpu_throttle_increment
&&
1150 (params
->cpu_throttle_increment
< 1 ||
1151 params
->cpu_throttle_increment
> 99)) {
1152 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1153 "cpu_throttle_increment",
1154 "an integer in the range of 1 to 99");
1158 if (params
->has_max_bandwidth
&& (params
->max_bandwidth
> SIZE_MAX
)) {
1159 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1161 "an integer in the range of 0 to "stringify(SIZE_MAX
)
1166 if (params
->has_avail_switchover_bandwidth
&&
1167 (params
->avail_switchover_bandwidth
> SIZE_MAX
)) {
1168 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1169 "avail_switchover_bandwidth",
1170 "an integer in the range of 0 to "stringify(SIZE_MAX
)
1175 if (params
->has_downtime_limit
&&
1176 (params
->downtime_limit
> MAX_MIGRATE_DOWNTIME
)) {
1177 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1179 "an integer in the range of 0 to "
1180 stringify(MAX_MIGRATE_DOWNTIME
)" ms");
1184 /* x_checkpoint_delay is now always positive */
1186 if (params
->has_multifd_channels
&& (params
->multifd_channels
< 1)) {
1187 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1189 "a value between 1 and 255");
1193 if (params
->has_multifd_zlib_level
&&
1194 (params
->multifd_zlib_level
> 9)) {
1195 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "multifd_zlib_level",
1196 "a value between 0 and 9");
1200 if (params
->has_multifd_zstd_level
&&
1201 (params
->multifd_zstd_level
> 20)) {
1202 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "multifd_zstd_level",
1203 "a value between 0 and 20");
1207 if (params
->has_xbzrle_cache_size
&&
1208 (params
->xbzrle_cache_size
< qemu_target_page_size() ||
1209 !is_power_of_2(params
->xbzrle_cache_size
))) {
1210 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1211 "xbzrle_cache_size",
1212 "a power of two no less than the target page size");
1216 if (params
->has_max_cpu_throttle
&&
1217 (params
->max_cpu_throttle
< params
->cpu_throttle_initial
||
1218 params
->max_cpu_throttle
> 99)) {
1219 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1221 "an integer in the range of cpu_throttle_initial to 99");
1225 if (params
->has_announce_initial
&&
1226 params
->announce_initial
> 100000) {
1227 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1229 "a value between 0 and 100000");
1232 if (params
->has_announce_max
&&
1233 params
->announce_max
> 100000) {
1234 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1236 "a value between 0 and 100000");
1239 if (params
->has_announce_rounds
&&
1240 params
->announce_rounds
> 1000) {
1241 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1243 "a value between 0 and 1000");
1246 if (params
->has_announce_step
&&
1247 (params
->announce_step
< 1 ||
1248 params
->announce_step
> 10000)) {
1249 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1251 "a value between 0 and 10000");
1255 if (params
->has_block_bitmap_mapping
&&
1256 !check_dirty_bitmap_mig_alias_map(params
->block_bitmap_mapping
, errp
)) {
1257 error_prepend(errp
, "Invalid mapping given for block-bitmap-mapping: ");
1262 if (migrate_zero_copy_send() &&
1263 ((params
->has_multifd_compression
&& params
->multifd_compression
) ||
1264 (params
->tls_creds
&& *params
->tls_creds
))) {
1266 "Zero copy only available for non-compressed non-TLS multifd migration");
1271 if (migrate_mapped_ram() &&
1272 (migrate_multifd_compression() || migrate_tls())) {
1274 "Mapped-ram only available for non-compressed non-TLS multifd migration");
1278 if (params
->has_x_vcpu_dirty_limit_period
&&
1279 (params
->x_vcpu_dirty_limit_period
< 1 ||
1280 params
->x_vcpu_dirty_limit_period
> 1000)) {
1281 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1282 "x-vcpu-dirty-limit-period",
1283 "a value between 1 and 1000");
1287 if (params
->has_vcpu_dirty_limit
&&
1288 (params
->vcpu_dirty_limit
< 1)) {
1289 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1291 "is invalid, it must greater then 1 MB/s");
1298 static void migrate_params_test_apply(MigrateSetParameters
*params
,
1299 MigrationParameters
*dest
)
1301 *dest
= migrate_get_current()->parameters
;
1303 /* TODO use QAPI_CLONE() instead of duplicating it inline */
1305 if (params
->has_compress_level
) {
1306 dest
->compress_level
= params
->compress_level
;
1309 if (params
->has_compress_threads
) {
1310 dest
->compress_threads
= params
->compress_threads
;
1313 if (params
->has_compress_wait_thread
) {
1314 dest
->compress_wait_thread
= params
->compress_wait_thread
;
1317 if (params
->has_decompress_threads
) {
1318 dest
->decompress_threads
= params
->decompress_threads
;
1321 if (params
->has_throttle_trigger_threshold
) {
1322 dest
->throttle_trigger_threshold
= params
->throttle_trigger_threshold
;
1325 if (params
->has_cpu_throttle_initial
) {
1326 dest
->cpu_throttle_initial
= params
->cpu_throttle_initial
;
1329 if (params
->has_cpu_throttle_increment
) {
1330 dest
->cpu_throttle_increment
= params
->cpu_throttle_increment
;
1333 if (params
->has_cpu_throttle_tailslow
) {
1334 dest
->cpu_throttle_tailslow
= params
->cpu_throttle_tailslow
;
1337 if (params
->tls_creds
) {
1338 assert(params
->tls_creds
->type
== QTYPE_QSTRING
);
1339 dest
->tls_creds
= params
->tls_creds
->u
.s
;
1342 if (params
->tls_hostname
) {
1343 assert(params
->tls_hostname
->type
== QTYPE_QSTRING
);
1344 dest
->tls_hostname
= params
->tls_hostname
->u
.s
;
1347 if (params
->has_max_bandwidth
) {
1348 dest
->max_bandwidth
= params
->max_bandwidth
;
1351 if (params
->has_avail_switchover_bandwidth
) {
1352 dest
->avail_switchover_bandwidth
= params
->avail_switchover_bandwidth
;
1355 if (params
->has_downtime_limit
) {
1356 dest
->downtime_limit
= params
->downtime_limit
;
1359 if (params
->has_x_checkpoint_delay
) {
1360 dest
->x_checkpoint_delay
= params
->x_checkpoint_delay
;
1363 if (params
->has_block_incremental
) {
1364 dest
->block_incremental
= params
->block_incremental
;
1366 if (params
->has_multifd_channels
) {
1367 dest
->multifd_channels
= params
->multifd_channels
;
1369 if (params
->has_multifd_compression
) {
1370 dest
->multifd_compression
= params
->multifd_compression
;
1372 if (params
->has_multifd_zlib_level
) {
1373 dest
->multifd_zlib_level
= params
->multifd_zlib_level
;
1375 if (params
->has_multifd_zstd_level
) {
1376 dest
->multifd_zstd_level
= params
->multifd_zstd_level
;
1378 if (params
->has_xbzrle_cache_size
) {
1379 dest
->xbzrle_cache_size
= params
->xbzrle_cache_size
;
1381 if (params
->has_max_postcopy_bandwidth
) {
1382 dest
->max_postcopy_bandwidth
= params
->max_postcopy_bandwidth
;
1384 if (params
->has_max_cpu_throttle
) {
1385 dest
->max_cpu_throttle
= params
->max_cpu_throttle
;
1387 if (params
->has_announce_initial
) {
1388 dest
->announce_initial
= params
->announce_initial
;
1390 if (params
->has_announce_max
) {
1391 dest
->announce_max
= params
->announce_max
;
1393 if (params
->has_announce_rounds
) {
1394 dest
->announce_rounds
= params
->announce_rounds
;
1396 if (params
->has_announce_step
) {
1397 dest
->announce_step
= params
->announce_step
;
1400 if (params
->has_block_bitmap_mapping
) {
1401 dest
->has_block_bitmap_mapping
= true;
1402 dest
->block_bitmap_mapping
= params
->block_bitmap_mapping
;
1405 if (params
->has_x_vcpu_dirty_limit_period
) {
1406 dest
->x_vcpu_dirty_limit_period
=
1407 params
->x_vcpu_dirty_limit_period
;
1409 if (params
->has_vcpu_dirty_limit
) {
1410 dest
->vcpu_dirty_limit
= params
->vcpu_dirty_limit
;
1413 if (params
->has_mode
) {
1414 dest
->mode
= params
->mode
;
1417 if (params
->has_zero_page_detection
) {
1418 dest
->zero_page_detection
= params
->zero_page_detection
;
1422 static void migrate_params_apply(MigrateSetParameters
*params
, Error
**errp
)
1424 MigrationState
*s
= migrate_get_current();
1426 /* TODO use QAPI_CLONE() instead of duplicating it inline */
1428 if (params
->has_compress_level
) {
1429 warn_report("old compression is deprecated;"
1430 " use multifd compression methods instead");
1431 s
->parameters
.compress_level
= params
->compress_level
;
1434 if (params
->has_compress_threads
) {
1435 warn_report("old compression is deprecated;"
1436 " use multifd compression methods instead");
1437 s
->parameters
.compress_threads
= params
->compress_threads
;
1440 if (params
->has_compress_wait_thread
) {
1441 warn_report("old compression is deprecated;"
1442 " use multifd compression methods instead");
1443 s
->parameters
.compress_wait_thread
= params
->compress_wait_thread
;
1446 if (params
->has_decompress_threads
) {
1447 warn_report("old compression is deprecated;"
1448 " use multifd compression methods instead");
1449 s
->parameters
.decompress_threads
= params
->decompress_threads
;
1452 if (params
->has_throttle_trigger_threshold
) {
1453 s
->parameters
.throttle_trigger_threshold
= params
->throttle_trigger_threshold
;
1456 if (params
->has_cpu_throttle_initial
) {
1457 s
->parameters
.cpu_throttle_initial
= params
->cpu_throttle_initial
;
1460 if (params
->has_cpu_throttle_increment
) {
1461 s
->parameters
.cpu_throttle_increment
= params
->cpu_throttle_increment
;
1464 if (params
->has_cpu_throttle_tailslow
) {
1465 s
->parameters
.cpu_throttle_tailslow
= params
->cpu_throttle_tailslow
;
1468 if (params
->tls_creds
) {
1469 g_free(s
->parameters
.tls_creds
);
1470 assert(params
->tls_creds
->type
== QTYPE_QSTRING
);
1471 s
->parameters
.tls_creds
= g_strdup(params
->tls_creds
->u
.s
);
1474 if (params
->tls_hostname
) {
1475 g_free(s
->parameters
.tls_hostname
);
1476 assert(params
->tls_hostname
->type
== QTYPE_QSTRING
);
1477 s
->parameters
.tls_hostname
= g_strdup(params
->tls_hostname
->u
.s
);
1480 if (params
->tls_authz
) {
1481 g_free(s
->parameters
.tls_authz
);
1482 assert(params
->tls_authz
->type
== QTYPE_QSTRING
);
1483 s
->parameters
.tls_authz
= g_strdup(params
->tls_authz
->u
.s
);
1486 if (params
->has_max_bandwidth
) {
1487 s
->parameters
.max_bandwidth
= params
->max_bandwidth
;
1488 if (s
->to_dst_file
&& !migration_in_postcopy()) {
1489 migration_rate_set(s
->parameters
.max_bandwidth
);
1493 if (params
->has_avail_switchover_bandwidth
) {
1494 s
->parameters
.avail_switchover_bandwidth
= params
->avail_switchover_bandwidth
;
1497 if (params
->has_downtime_limit
) {
1498 s
->parameters
.downtime_limit
= params
->downtime_limit
;
1501 if (params
->has_x_checkpoint_delay
) {
1502 s
->parameters
.x_checkpoint_delay
= params
->x_checkpoint_delay
;
1503 colo_checkpoint_delay_set();
1506 if (params
->has_block_incremental
) {
1507 warn_report("block migration is deprecated;"
1508 " use blockdev-mirror with NBD instead");
1509 s
->parameters
.block_incremental
= params
->block_incremental
;
1511 if (params
->has_multifd_channels
) {
1512 s
->parameters
.multifd_channels
= params
->multifd_channels
;
1514 if (params
->has_multifd_compression
) {
1515 s
->parameters
.multifd_compression
= params
->multifd_compression
;
1517 if (params
->has_multifd_zlib_level
) {
1518 s
->parameters
.multifd_zlib_level
= params
->multifd_zlib_level
;
1520 if (params
->has_multifd_zstd_level
) {
1521 s
->parameters
.multifd_zstd_level
= params
->multifd_zstd_level
;
1523 if (params
->has_xbzrle_cache_size
) {
1524 s
->parameters
.xbzrle_cache_size
= params
->xbzrle_cache_size
;
1525 xbzrle_cache_resize(params
->xbzrle_cache_size
, errp
);
1527 if (params
->has_max_postcopy_bandwidth
) {
1528 s
->parameters
.max_postcopy_bandwidth
= params
->max_postcopy_bandwidth
;
1529 if (s
->to_dst_file
&& migration_in_postcopy()) {
1530 migration_rate_set(s
->parameters
.max_postcopy_bandwidth
);
1533 if (params
->has_max_cpu_throttle
) {
1534 s
->parameters
.max_cpu_throttle
= params
->max_cpu_throttle
;
1536 if (params
->has_announce_initial
) {
1537 s
->parameters
.announce_initial
= params
->announce_initial
;
1539 if (params
->has_announce_max
) {
1540 s
->parameters
.announce_max
= params
->announce_max
;
1542 if (params
->has_announce_rounds
) {
1543 s
->parameters
.announce_rounds
= params
->announce_rounds
;
1545 if (params
->has_announce_step
) {
1546 s
->parameters
.announce_step
= params
->announce_step
;
1549 if (params
->has_block_bitmap_mapping
) {
1550 qapi_free_BitmapMigrationNodeAliasList(
1551 s
->parameters
.block_bitmap_mapping
);
1553 s
->parameters
.has_block_bitmap_mapping
= true;
1554 s
->parameters
.block_bitmap_mapping
=
1555 QAPI_CLONE(BitmapMigrationNodeAliasList
,
1556 params
->block_bitmap_mapping
);
1559 if (params
->has_x_vcpu_dirty_limit_period
) {
1560 s
->parameters
.x_vcpu_dirty_limit_period
=
1561 params
->x_vcpu_dirty_limit_period
;
1563 if (params
->has_vcpu_dirty_limit
) {
1564 s
->parameters
.vcpu_dirty_limit
= params
->vcpu_dirty_limit
;
1567 if (params
->has_mode
) {
1568 s
->parameters
.mode
= params
->mode
;
1571 if (params
->has_zero_page_detection
) {
1572 s
->parameters
.zero_page_detection
= params
->zero_page_detection
;
1576 void qmp_migrate_set_parameters(MigrateSetParameters
*params
, Error
**errp
)
1578 MigrationParameters tmp
;
1580 /* TODO Rewrite "" to null instead for all three tls_* parameters */
1581 if (params
->tls_creds
1582 && params
->tls_creds
->type
== QTYPE_QNULL
) {
1583 qobject_unref(params
->tls_creds
->u
.n
);
1584 params
->tls_creds
->type
= QTYPE_QSTRING
;
1585 params
->tls_creds
->u
.s
= strdup("");
1587 if (params
->tls_hostname
1588 && params
->tls_hostname
->type
== QTYPE_QNULL
) {
1589 qobject_unref(params
->tls_hostname
->u
.n
);
1590 params
->tls_hostname
->type
= QTYPE_QSTRING
;
1591 params
->tls_hostname
->u
.s
= strdup("");
1593 if (params
->tls_authz
1594 && params
->tls_authz
->type
== QTYPE_QNULL
) {
1595 qobject_unref(params
->tls_authz
->u
.n
);
1596 params
->tls_authz
->type
= QTYPE_QSTRING
;
1597 params
->tls_authz
->u
.s
= strdup("");
1600 migrate_params_test_apply(params
, &tmp
);
1602 if (!migrate_params_check(&tmp
, errp
)) {
1603 /* Invalid parameter */
1607 migrate_params_apply(params
, errp
);