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
)
484 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
)
1108 if (params
->has_compress_level
&&
1109 (params
->compress_level
> 9)) {
1110 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "compress_level",
1111 "a value between 0 and 9");
1115 if (params
->has_compress_threads
&& (params
->compress_threads
< 1)) {
1116 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1118 "a value between 1 and 255");
1122 if (params
->has_decompress_threads
&& (params
->decompress_threads
< 1)) {
1123 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1124 "decompress_threads",
1125 "a value between 1 and 255");
1129 if (params
->has_throttle_trigger_threshold
&&
1130 (params
->throttle_trigger_threshold
< 1 ||
1131 params
->throttle_trigger_threshold
> 100)) {
1132 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1133 "throttle_trigger_threshold",
1134 "an integer in the range of 1 to 100");
1138 if (params
->has_cpu_throttle_initial
&&
1139 (params
->cpu_throttle_initial
< 1 ||
1140 params
->cpu_throttle_initial
> 99)) {
1141 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1142 "cpu_throttle_initial",
1143 "an integer in the range of 1 to 99");
1147 if (params
->has_cpu_throttle_increment
&&
1148 (params
->cpu_throttle_increment
< 1 ||
1149 params
->cpu_throttle_increment
> 99)) {
1150 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1151 "cpu_throttle_increment",
1152 "an integer in the range of 1 to 99");
1156 if (params
->has_max_bandwidth
&& (params
->max_bandwidth
> SIZE_MAX
)) {
1157 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1159 "an integer in the range of 0 to "stringify(SIZE_MAX
)
1164 if (params
->has_avail_switchover_bandwidth
&&
1165 (params
->avail_switchover_bandwidth
> SIZE_MAX
)) {
1166 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1167 "avail_switchover_bandwidth",
1168 "an integer in the range of 0 to "stringify(SIZE_MAX
)
1173 if (params
->has_downtime_limit
&&
1174 (params
->downtime_limit
> MAX_MIGRATE_DOWNTIME
)) {
1175 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1177 "an integer in the range of 0 to "
1178 stringify(MAX_MIGRATE_DOWNTIME
)" ms");
1182 /* x_checkpoint_delay is now always positive */
1184 if (params
->has_multifd_channels
&& (params
->multifd_channels
< 1)) {
1185 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1187 "a value between 1 and 255");
1191 if (params
->has_multifd_zlib_level
&&
1192 (params
->multifd_zlib_level
> 9)) {
1193 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "multifd_zlib_level",
1194 "a value between 0 and 9");
1198 if (params
->has_multifd_zstd_level
&&
1199 (params
->multifd_zstd_level
> 20)) {
1200 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "multifd_zstd_level",
1201 "a value between 0 and 20");
1205 if (params
->has_xbzrle_cache_size
&&
1206 (params
->xbzrle_cache_size
< qemu_target_page_size() ||
1207 !is_power_of_2(params
->xbzrle_cache_size
))) {
1208 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1209 "xbzrle_cache_size",
1210 "a power of two no less than the target page size");
1214 if (params
->has_max_cpu_throttle
&&
1215 (params
->max_cpu_throttle
< params
->cpu_throttle_initial
||
1216 params
->max_cpu_throttle
> 99)) {
1217 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1219 "an integer in the range of cpu_throttle_initial to 99");
1223 if (params
->has_announce_initial
&&
1224 params
->announce_initial
> 100000) {
1225 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1227 "a value between 0 and 100000");
1230 if (params
->has_announce_max
&&
1231 params
->announce_max
> 100000) {
1232 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1234 "a value between 0 and 100000");
1237 if (params
->has_announce_rounds
&&
1238 params
->announce_rounds
> 1000) {
1239 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1241 "a value between 0 and 1000");
1244 if (params
->has_announce_step
&&
1245 (params
->announce_step
< 1 ||
1246 params
->announce_step
> 10000)) {
1247 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1249 "a value between 0 and 10000");
1253 if (params
->has_block_bitmap_mapping
&&
1254 !check_dirty_bitmap_mig_alias_map(params
->block_bitmap_mapping
, errp
)) {
1255 error_prepend(errp
, "Invalid mapping given for block-bitmap-mapping: ");
1260 if (migrate_zero_copy_send() &&
1261 ((params
->has_multifd_compression
&& params
->multifd_compression
) ||
1262 (params
->tls_creds
&& *params
->tls_creds
))) {
1264 "Zero copy only available for non-compressed non-TLS multifd migration");
1269 if (migrate_mapped_ram() &&
1270 (migrate_multifd_compression() || migrate_tls())) {
1272 "Mapped-ram only available for non-compressed non-TLS multifd migration");
1276 if (params
->has_x_vcpu_dirty_limit_period
&&
1277 (params
->x_vcpu_dirty_limit_period
< 1 ||
1278 params
->x_vcpu_dirty_limit_period
> 1000)) {
1279 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1280 "x-vcpu-dirty-limit-period",
1281 "a value between 1 and 1000");
1285 if (params
->has_vcpu_dirty_limit
&&
1286 (params
->vcpu_dirty_limit
< 1)) {
1287 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1289 "is invalid, it must greater then 1 MB/s");
1296 static void migrate_params_test_apply(MigrateSetParameters
*params
,
1297 MigrationParameters
*dest
)
1299 *dest
= migrate_get_current()->parameters
;
1301 /* TODO use QAPI_CLONE() instead of duplicating it inline */
1303 if (params
->has_compress_level
) {
1304 dest
->compress_level
= params
->compress_level
;
1307 if (params
->has_compress_threads
) {
1308 dest
->compress_threads
= params
->compress_threads
;
1311 if (params
->has_compress_wait_thread
) {
1312 dest
->compress_wait_thread
= params
->compress_wait_thread
;
1315 if (params
->has_decompress_threads
) {
1316 dest
->decompress_threads
= params
->decompress_threads
;
1319 if (params
->has_throttle_trigger_threshold
) {
1320 dest
->throttle_trigger_threshold
= params
->throttle_trigger_threshold
;
1323 if (params
->has_cpu_throttle_initial
) {
1324 dest
->cpu_throttle_initial
= params
->cpu_throttle_initial
;
1327 if (params
->has_cpu_throttle_increment
) {
1328 dest
->cpu_throttle_increment
= params
->cpu_throttle_increment
;
1331 if (params
->has_cpu_throttle_tailslow
) {
1332 dest
->cpu_throttle_tailslow
= params
->cpu_throttle_tailslow
;
1335 if (params
->tls_creds
) {
1336 assert(params
->tls_creds
->type
== QTYPE_QSTRING
);
1337 dest
->tls_creds
= params
->tls_creds
->u
.s
;
1340 if (params
->tls_hostname
) {
1341 assert(params
->tls_hostname
->type
== QTYPE_QSTRING
);
1342 dest
->tls_hostname
= params
->tls_hostname
->u
.s
;
1345 if (params
->has_max_bandwidth
) {
1346 dest
->max_bandwidth
= params
->max_bandwidth
;
1349 if (params
->has_avail_switchover_bandwidth
) {
1350 dest
->avail_switchover_bandwidth
= params
->avail_switchover_bandwidth
;
1353 if (params
->has_downtime_limit
) {
1354 dest
->downtime_limit
= params
->downtime_limit
;
1357 if (params
->has_x_checkpoint_delay
) {
1358 dest
->x_checkpoint_delay
= params
->x_checkpoint_delay
;
1361 if (params
->has_block_incremental
) {
1362 dest
->block_incremental
= params
->block_incremental
;
1364 if (params
->has_multifd_channels
) {
1365 dest
->multifd_channels
= params
->multifd_channels
;
1367 if (params
->has_multifd_compression
) {
1368 dest
->multifd_compression
= params
->multifd_compression
;
1370 if (params
->has_multifd_zlib_level
) {
1371 dest
->multifd_zlib_level
= params
->multifd_zlib_level
;
1373 if (params
->has_multifd_zstd_level
) {
1374 dest
->multifd_zstd_level
= params
->multifd_zstd_level
;
1376 if (params
->has_xbzrle_cache_size
) {
1377 dest
->xbzrle_cache_size
= params
->xbzrle_cache_size
;
1379 if (params
->has_max_postcopy_bandwidth
) {
1380 dest
->max_postcopy_bandwidth
= params
->max_postcopy_bandwidth
;
1382 if (params
->has_max_cpu_throttle
) {
1383 dest
->max_cpu_throttle
= params
->max_cpu_throttle
;
1385 if (params
->has_announce_initial
) {
1386 dest
->announce_initial
= params
->announce_initial
;
1388 if (params
->has_announce_max
) {
1389 dest
->announce_max
= params
->announce_max
;
1391 if (params
->has_announce_rounds
) {
1392 dest
->announce_rounds
= params
->announce_rounds
;
1394 if (params
->has_announce_step
) {
1395 dest
->announce_step
= params
->announce_step
;
1398 if (params
->has_block_bitmap_mapping
) {
1399 dest
->has_block_bitmap_mapping
= true;
1400 dest
->block_bitmap_mapping
= params
->block_bitmap_mapping
;
1403 if (params
->has_x_vcpu_dirty_limit_period
) {
1404 dest
->x_vcpu_dirty_limit_period
=
1405 params
->x_vcpu_dirty_limit_period
;
1407 if (params
->has_vcpu_dirty_limit
) {
1408 dest
->vcpu_dirty_limit
= params
->vcpu_dirty_limit
;
1411 if (params
->has_mode
) {
1412 dest
->mode
= params
->mode
;
1415 if (params
->has_zero_page_detection
) {
1416 dest
->zero_page_detection
= params
->zero_page_detection
;
1420 static void migrate_params_apply(MigrateSetParameters
*params
, Error
**errp
)
1422 MigrationState
*s
= migrate_get_current();
1424 /* TODO use QAPI_CLONE() instead of duplicating it inline */
1426 if (params
->has_compress_level
) {
1427 warn_report("old compression is deprecated;"
1428 " use multifd compression methods instead");
1429 s
->parameters
.compress_level
= params
->compress_level
;
1432 if (params
->has_compress_threads
) {
1433 warn_report("old compression is deprecated;"
1434 " use multifd compression methods instead");
1435 s
->parameters
.compress_threads
= params
->compress_threads
;
1438 if (params
->has_compress_wait_thread
) {
1439 warn_report("old compression is deprecated;"
1440 " use multifd compression methods instead");
1441 s
->parameters
.compress_wait_thread
= params
->compress_wait_thread
;
1444 if (params
->has_decompress_threads
) {
1445 warn_report("old compression is deprecated;"
1446 " use multifd compression methods instead");
1447 s
->parameters
.decompress_threads
= params
->decompress_threads
;
1450 if (params
->has_throttle_trigger_threshold
) {
1451 s
->parameters
.throttle_trigger_threshold
= params
->throttle_trigger_threshold
;
1454 if (params
->has_cpu_throttle_initial
) {
1455 s
->parameters
.cpu_throttle_initial
= params
->cpu_throttle_initial
;
1458 if (params
->has_cpu_throttle_increment
) {
1459 s
->parameters
.cpu_throttle_increment
= params
->cpu_throttle_increment
;
1462 if (params
->has_cpu_throttle_tailslow
) {
1463 s
->parameters
.cpu_throttle_tailslow
= params
->cpu_throttle_tailslow
;
1466 if (params
->tls_creds
) {
1467 g_free(s
->parameters
.tls_creds
);
1468 assert(params
->tls_creds
->type
== QTYPE_QSTRING
);
1469 s
->parameters
.tls_creds
= g_strdup(params
->tls_creds
->u
.s
);
1472 if (params
->tls_hostname
) {
1473 g_free(s
->parameters
.tls_hostname
);
1474 assert(params
->tls_hostname
->type
== QTYPE_QSTRING
);
1475 s
->parameters
.tls_hostname
= g_strdup(params
->tls_hostname
->u
.s
);
1478 if (params
->tls_authz
) {
1479 g_free(s
->parameters
.tls_authz
);
1480 assert(params
->tls_authz
->type
== QTYPE_QSTRING
);
1481 s
->parameters
.tls_authz
= g_strdup(params
->tls_authz
->u
.s
);
1484 if (params
->has_max_bandwidth
) {
1485 s
->parameters
.max_bandwidth
= params
->max_bandwidth
;
1486 if (s
->to_dst_file
&& !migration_in_postcopy()) {
1487 migration_rate_set(s
->parameters
.max_bandwidth
);
1491 if (params
->has_avail_switchover_bandwidth
) {
1492 s
->parameters
.avail_switchover_bandwidth
= params
->avail_switchover_bandwidth
;
1495 if (params
->has_downtime_limit
) {
1496 s
->parameters
.downtime_limit
= params
->downtime_limit
;
1499 if (params
->has_x_checkpoint_delay
) {
1500 s
->parameters
.x_checkpoint_delay
= params
->x_checkpoint_delay
;
1501 colo_checkpoint_delay_set();
1504 if (params
->has_block_incremental
) {
1505 warn_report("block migration is deprecated;"
1506 " use blockdev-mirror with NBD instead");
1507 s
->parameters
.block_incremental
= params
->block_incremental
;
1509 if (params
->has_multifd_channels
) {
1510 s
->parameters
.multifd_channels
= params
->multifd_channels
;
1512 if (params
->has_multifd_compression
) {
1513 s
->parameters
.multifd_compression
= params
->multifd_compression
;
1515 if (params
->has_multifd_zlib_level
) {
1516 s
->parameters
.multifd_zlib_level
= params
->multifd_zlib_level
;
1518 if (params
->has_multifd_zstd_level
) {
1519 s
->parameters
.multifd_zstd_level
= params
->multifd_zstd_level
;
1521 if (params
->has_xbzrle_cache_size
) {
1522 s
->parameters
.xbzrle_cache_size
= params
->xbzrle_cache_size
;
1523 xbzrle_cache_resize(params
->xbzrle_cache_size
, errp
);
1525 if (params
->has_max_postcopy_bandwidth
) {
1526 s
->parameters
.max_postcopy_bandwidth
= params
->max_postcopy_bandwidth
;
1527 if (s
->to_dst_file
&& migration_in_postcopy()) {
1528 migration_rate_set(s
->parameters
.max_postcopy_bandwidth
);
1531 if (params
->has_max_cpu_throttle
) {
1532 s
->parameters
.max_cpu_throttle
= params
->max_cpu_throttle
;
1534 if (params
->has_announce_initial
) {
1535 s
->parameters
.announce_initial
= params
->announce_initial
;
1537 if (params
->has_announce_max
) {
1538 s
->parameters
.announce_max
= params
->announce_max
;
1540 if (params
->has_announce_rounds
) {
1541 s
->parameters
.announce_rounds
= params
->announce_rounds
;
1543 if (params
->has_announce_step
) {
1544 s
->parameters
.announce_step
= params
->announce_step
;
1547 if (params
->has_block_bitmap_mapping
) {
1548 qapi_free_BitmapMigrationNodeAliasList(
1549 s
->parameters
.block_bitmap_mapping
);
1551 s
->parameters
.has_block_bitmap_mapping
= true;
1552 s
->parameters
.block_bitmap_mapping
=
1553 QAPI_CLONE(BitmapMigrationNodeAliasList
,
1554 params
->block_bitmap_mapping
);
1557 if (params
->has_x_vcpu_dirty_limit_period
) {
1558 s
->parameters
.x_vcpu_dirty_limit_period
=
1559 params
->x_vcpu_dirty_limit_period
;
1561 if (params
->has_vcpu_dirty_limit
) {
1562 s
->parameters
.vcpu_dirty_limit
= params
->vcpu_dirty_limit
;
1565 if (params
->has_mode
) {
1566 s
->parameters
.mode
= params
->mode
;
1569 if (params
->has_zero_page_detection
) {
1570 s
->parameters
.zero_page_detection
= params
->zero_page_detection
;
1574 void qmp_migrate_set_parameters(MigrateSetParameters
*params
, Error
**errp
)
1576 MigrationParameters tmp
;
1578 /* TODO Rewrite "" to null instead for all three tls_* parameters */
1579 if (params
->tls_creds
1580 && params
->tls_creds
->type
== QTYPE_QNULL
) {
1581 qobject_unref(params
->tls_creds
->u
.n
);
1582 params
->tls_creds
->type
= QTYPE_QSTRING
;
1583 params
->tls_creds
->u
.s
= strdup("");
1585 if (params
->tls_hostname
1586 && params
->tls_hostname
->type
== QTYPE_QNULL
) {
1587 qobject_unref(params
->tls_hostname
->u
.n
);
1588 params
->tls_hostname
->type
= QTYPE_QSTRING
;
1589 params
->tls_hostname
->u
.s
= strdup("");
1591 if (params
->tls_authz
1592 && params
->tls_authz
->type
== QTYPE_QNULL
) {
1593 qobject_unref(params
->tls_authz
->u
.n
);
1594 params
->tls_authz
->type
= QTYPE_QSTRING
;
1595 params
->tls_authz
->u
.s
= strdup("");
1598 migrate_params_test_apply(params
, &tmp
);
1600 if (!migrate_params_check(&tmp
, errp
)) {
1601 /* Invalid parameter */
1605 migrate_params_apply(params
, errp
);