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 "exec/target_page.h"
16 #include "qapi/clone-visitor.h"
17 #include "qapi/error.h"
18 #include "qapi/qapi-commands-migration.h"
19 #include "qapi/qapi-visit-migration.h"
20 #include "qapi/qmp/qerror.h"
21 #include "qapi/qmp/qnull.h"
22 #include "sysemu/runstate.h"
23 #include "migration/colo.h"
24 #include "migration/misc.h"
25 #include "migration.h"
26 #include "migration-stats.h"
27 #include "qemu-file.h"
30 #include "sysemu/kvm.h"
32 /* Maximum migrate downtime set to 2000 seconds */
33 #define MAX_MIGRATE_DOWNTIME_SECONDS 2000
34 #define MAX_MIGRATE_DOWNTIME (MAX_MIGRATE_DOWNTIME_SECONDS * 1000)
36 #define MAX_THROTTLE (128 << 20) /* Migration transfer speed throttling */
38 /* Time in milliseconds we are allowed to stop the source,
39 * for sending the last part */
40 #define DEFAULT_MIGRATE_SET_DOWNTIME 300
42 /* Default compression thread count */
43 #define DEFAULT_MIGRATE_COMPRESS_THREAD_COUNT 8
44 /* Default decompression thread count, usually decompression is at
45 * least 4 times as fast as compression.*/
46 #define DEFAULT_MIGRATE_DECOMPRESS_THREAD_COUNT 2
47 /*0: means nocompress, 1: best speed, ... 9: best compress ratio */
48 #define DEFAULT_MIGRATE_COMPRESS_LEVEL 1
49 /* Define default autoconverge cpu throttle migration parameters */
50 #define DEFAULT_MIGRATE_THROTTLE_TRIGGER_THRESHOLD 50
51 #define DEFAULT_MIGRATE_CPU_THROTTLE_INITIAL 20
52 #define DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT 10
53 #define DEFAULT_MIGRATE_MAX_CPU_THROTTLE 99
55 /* Migration XBZRLE default cache size */
56 #define DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE (64 * 1024 * 1024)
58 /* The delay time (in ms) between two COLO checkpoints */
59 #define DEFAULT_MIGRATE_X_CHECKPOINT_DELAY (200 * 100)
60 #define DEFAULT_MIGRATE_MULTIFD_CHANNELS 2
61 #define DEFAULT_MIGRATE_MULTIFD_COMPRESSION MULTIFD_COMPRESSION_NONE
62 /* 0: means nocompress, 1: best speed, ... 9: best compress ratio */
63 #define DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL 1
64 /* 0: means nocompress, 1: best speed, ... 20: best compress ratio */
65 #define DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL 1
67 /* Background transfer rate for postcopy, 0 means unlimited, note
68 * that page requests can still exceed this limit.
70 #define DEFAULT_MIGRATE_MAX_POSTCOPY_BANDWIDTH 0
73 * Parameters for self_announce_delay giving a stream of RARP/ARP
74 * packets after migration.
76 #define DEFAULT_MIGRATE_ANNOUNCE_INITIAL 50
77 #define DEFAULT_MIGRATE_ANNOUNCE_MAX 550
78 #define DEFAULT_MIGRATE_ANNOUNCE_ROUNDS 5
79 #define DEFAULT_MIGRATE_ANNOUNCE_STEP 100
81 #define DEFINE_PROP_MIG_CAP(name, x) \
82 DEFINE_PROP_BOOL(name, MigrationState, capabilities[x], false)
84 #define DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD 1000 /* milliseconds */
85 #define DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT 1 /* MB/s */
87 Property migration_properties
[] = {
88 DEFINE_PROP_BOOL("store-global-state", MigrationState
,
89 store_global_state
, true),
90 DEFINE_PROP_BOOL("send-configuration", MigrationState
,
91 send_configuration
, true),
92 DEFINE_PROP_BOOL("send-section-footer", MigrationState
,
93 send_section_footer
, true),
94 DEFINE_PROP_BOOL("decompress-error-check", MigrationState
,
95 decompress_error_check
, true),
96 DEFINE_PROP_BOOL("multifd-flush-after-each-section", MigrationState
,
97 multifd_flush_after_each_section
, false),
98 DEFINE_PROP_UINT8("x-clear-bitmap-shift", MigrationState
,
99 clear_bitmap_shift
, CLEAR_BITMAP_SHIFT_DEFAULT
),
100 DEFINE_PROP_BOOL("x-preempt-pre-7-2", MigrationState
,
101 preempt_pre_7_2
, false),
103 /* Migration parameters */
104 DEFINE_PROP_UINT8("x-compress-level", MigrationState
,
105 parameters
.compress_level
,
106 DEFAULT_MIGRATE_COMPRESS_LEVEL
),
107 DEFINE_PROP_UINT8("x-compress-threads", MigrationState
,
108 parameters
.compress_threads
,
109 DEFAULT_MIGRATE_COMPRESS_THREAD_COUNT
),
110 DEFINE_PROP_BOOL("x-compress-wait-thread", MigrationState
,
111 parameters
.compress_wait_thread
, true),
112 DEFINE_PROP_UINT8("x-decompress-threads", MigrationState
,
113 parameters
.decompress_threads
,
114 DEFAULT_MIGRATE_DECOMPRESS_THREAD_COUNT
),
115 DEFINE_PROP_UINT8("x-throttle-trigger-threshold", MigrationState
,
116 parameters
.throttle_trigger_threshold
,
117 DEFAULT_MIGRATE_THROTTLE_TRIGGER_THRESHOLD
),
118 DEFINE_PROP_UINT8("x-cpu-throttle-initial", MigrationState
,
119 parameters
.cpu_throttle_initial
,
120 DEFAULT_MIGRATE_CPU_THROTTLE_INITIAL
),
121 DEFINE_PROP_UINT8("x-cpu-throttle-increment", MigrationState
,
122 parameters
.cpu_throttle_increment
,
123 DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT
),
124 DEFINE_PROP_BOOL("x-cpu-throttle-tailslow", MigrationState
,
125 parameters
.cpu_throttle_tailslow
, false),
126 DEFINE_PROP_SIZE("x-max-bandwidth", MigrationState
,
127 parameters
.max_bandwidth
, MAX_THROTTLE
),
128 DEFINE_PROP_UINT64("x-downtime-limit", MigrationState
,
129 parameters
.downtime_limit
,
130 DEFAULT_MIGRATE_SET_DOWNTIME
),
131 DEFINE_PROP_UINT32("x-checkpoint-delay", MigrationState
,
132 parameters
.x_checkpoint_delay
,
133 DEFAULT_MIGRATE_X_CHECKPOINT_DELAY
),
134 DEFINE_PROP_UINT8("multifd-channels", MigrationState
,
135 parameters
.multifd_channels
,
136 DEFAULT_MIGRATE_MULTIFD_CHANNELS
),
137 DEFINE_PROP_MULTIFD_COMPRESSION("multifd-compression", MigrationState
,
138 parameters
.multifd_compression
,
139 DEFAULT_MIGRATE_MULTIFD_COMPRESSION
),
140 DEFINE_PROP_UINT8("multifd-zlib-level", MigrationState
,
141 parameters
.multifd_zlib_level
,
142 DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL
),
143 DEFINE_PROP_UINT8("multifd-zstd-level", MigrationState
,
144 parameters
.multifd_zstd_level
,
145 DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL
),
146 DEFINE_PROP_SIZE("xbzrle-cache-size", MigrationState
,
147 parameters
.xbzrle_cache_size
,
148 DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE
),
149 DEFINE_PROP_SIZE("max-postcopy-bandwidth", MigrationState
,
150 parameters
.max_postcopy_bandwidth
,
151 DEFAULT_MIGRATE_MAX_POSTCOPY_BANDWIDTH
),
152 DEFINE_PROP_UINT8("max-cpu-throttle", MigrationState
,
153 parameters
.max_cpu_throttle
,
154 DEFAULT_MIGRATE_MAX_CPU_THROTTLE
),
155 DEFINE_PROP_SIZE("announce-initial", MigrationState
,
156 parameters
.announce_initial
,
157 DEFAULT_MIGRATE_ANNOUNCE_INITIAL
),
158 DEFINE_PROP_SIZE("announce-max", MigrationState
,
159 parameters
.announce_max
,
160 DEFAULT_MIGRATE_ANNOUNCE_MAX
),
161 DEFINE_PROP_SIZE("announce-rounds", MigrationState
,
162 parameters
.announce_rounds
,
163 DEFAULT_MIGRATE_ANNOUNCE_ROUNDS
),
164 DEFINE_PROP_SIZE("announce-step", MigrationState
,
165 parameters
.announce_step
,
166 DEFAULT_MIGRATE_ANNOUNCE_STEP
),
167 DEFINE_PROP_STRING("tls-creds", MigrationState
, parameters
.tls_creds
),
168 DEFINE_PROP_STRING("tls-hostname", MigrationState
, parameters
.tls_hostname
),
169 DEFINE_PROP_STRING("tls-authz", MigrationState
, parameters
.tls_authz
),
170 DEFINE_PROP_UINT64("x-vcpu-dirty-limit-period", MigrationState
,
171 parameters
.x_vcpu_dirty_limit_period
,
172 DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD
),
173 DEFINE_PROP_UINT64("vcpu-dirty-limit", MigrationState
,
174 parameters
.vcpu_dirty_limit
,
175 DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT
),
177 /* Migration capabilities */
178 DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE
),
179 DEFINE_PROP_MIG_CAP("x-rdma-pin-all", MIGRATION_CAPABILITY_RDMA_PIN_ALL
),
180 DEFINE_PROP_MIG_CAP("x-auto-converge", MIGRATION_CAPABILITY_AUTO_CONVERGE
),
181 DEFINE_PROP_MIG_CAP("x-zero-blocks", MIGRATION_CAPABILITY_ZERO_BLOCKS
),
182 DEFINE_PROP_MIG_CAP("x-compress", MIGRATION_CAPABILITY_COMPRESS
),
183 DEFINE_PROP_MIG_CAP("x-events", MIGRATION_CAPABILITY_EVENTS
),
184 DEFINE_PROP_MIG_CAP("x-postcopy-ram", MIGRATION_CAPABILITY_POSTCOPY_RAM
),
185 DEFINE_PROP_MIG_CAP("x-postcopy-preempt",
186 MIGRATION_CAPABILITY_POSTCOPY_PREEMPT
),
187 DEFINE_PROP_MIG_CAP("x-colo", MIGRATION_CAPABILITY_X_COLO
),
188 DEFINE_PROP_MIG_CAP("x-release-ram", MIGRATION_CAPABILITY_RELEASE_RAM
),
189 DEFINE_PROP_MIG_CAP("x-block", MIGRATION_CAPABILITY_BLOCK
),
190 DEFINE_PROP_MIG_CAP("x-return-path", MIGRATION_CAPABILITY_RETURN_PATH
),
191 DEFINE_PROP_MIG_CAP("x-multifd", MIGRATION_CAPABILITY_MULTIFD
),
192 DEFINE_PROP_MIG_CAP("x-background-snapshot",
193 MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT
),
195 DEFINE_PROP_MIG_CAP("x-zero-copy-send",
196 MIGRATION_CAPABILITY_ZERO_COPY_SEND
),
198 DEFINE_PROP_MIG_CAP("x-switchover-ack",
199 MIGRATION_CAPABILITY_SWITCHOVER_ACK
),
200 DEFINE_PROP_MIG_CAP("x-dirty-limit", MIGRATION_CAPABILITY_DIRTY_LIMIT
),
201 DEFINE_PROP_END_OF_LIST(),
204 bool migrate_auto_converge(void)
206 MigrationState
*s
= migrate_get_current();
208 return s
->capabilities
[MIGRATION_CAPABILITY_AUTO_CONVERGE
];
211 bool migrate_background_snapshot(void)
213 MigrationState
*s
= migrate_get_current();
215 return s
->capabilities
[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT
];
218 bool migrate_block(void)
220 MigrationState
*s
= migrate_get_current();
222 return s
->capabilities
[MIGRATION_CAPABILITY_BLOCK
];
225 bool migrate_colo(void)
227 MigrationState
*s
= migrate_get_current();
229 return s
->capabilities
[MIGRATION_CAPABILITY_X_COLO
];
232 bool migrate_compress(void)
234 MigrationState
*s
= migrate_get_current();
236 return s
->capabilities
[MIGRATION_CAPABILITY_COMPRESS
];
239 bool migrate_dirty_bitmaps(void)
241 MigrationState
*s
= migrate_get_current();
243 return s
->capabilities
[MIGRATION_CAPABILITY_DIRTY_BITMAPS
];
246 bool migrate_dirty_limit(void)
248 MigrationState
*s
= migrate_get_current();
250 return s
->capabilities
[MIGRATION_CAPABILITY_DIRTY_LIMIT
];
253 bool migrate_events(void)
255 MigrationState
*s
= migrate_get_current();
257 return s
->capabilities
[MIGRATION_CAPABILITY_EVENTS
];
260 bool migrate_ignore_shared(void)
262 MigrationState
*s
= migrate_get_current();
264 return s
->capabilities
[MIGRATION_CAPABILITY_X_IGNORE_SHARED
];
267 bool migrate_late_block_activate(void)
269 MigrationState
*s
= migrate_get_current();
271 return s
->capabilities
[MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE
];
274 bool migrate_multifd(void)
276 MigrationState
*s
= migrate_get_current();
278 return s
->capabilities
[MIGRATION_CAPABILITY_MULTIFD
];
281 bool migrate_pause_before_switchover(void)
283 MigrationState
*s
= migrate_get_current();
285 return s
->capabilities
[MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER
];
288 bool migrate_postcopy_blocktime(void)
290 MigrationState
*s
= migrate_get_current();
292 return s
->capabilities
[MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME
];
295 bool migrate_postcopy_preempt(void)
297 MigrationState
*s
= migrate_get_current();
299 return s
->capabilities
[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT
];
302 bool migrate_postcopy_ram(void)
304 MigrationState
*s
= migrate_get_current();
306 return s
->capabilities
[MIGRATION_CAPABILITY_POSTCOPY_RAM
];
309 bool migrate_rdma_pin_all(void)
311 MigrationState
*s
= migrate_get_current();
313 return s
->capabilities
[MIGRATION_CAPABILITY_RDMA_PIN_ALL
];
316 bool migrate_release_ram(void)
318 MigrationState
*s
= migrate_get_current();
320 return s
->capabilities
[MIGRATION_CAPABILITY_RELEASE_RAM
];
323 bool migrate_return_path(void)
325 MigrationState
*s
= migrate_get_current();
327 return s
->capabilities
[MIGRATION_CAPABILITY_RETURN_PATH
];
330 bool migrate_switchover_ack(void)
332 MigrationState
*s
= migrate_get_current();
334 return s
->capabilities
[MIGRATION_CAPABILITY_SWITCHOVER_ACK
];
337 bool migrate_validate_uuid(void)
339 MigrationState
*s
= migrate_get_current();
341 return s
->capabilities
[MIGRATION_CAPABILITY_VALIDATE_UUID
];
344 bool migrate_xbzrle(void)
346 MigrationState
*s
= migrate_get_current();
348 return s
->capabilities
[MIGRATION_CAPABILITY_XBZRLE
];
351 bool migrate_zero_blocks(void)
353 MigrationState
*s
= migrate_get_current();
355 return s
->capabilities
[MIGRATION_CAPABILITY_ZERO_BLOCKS
];
358 bool migrate_zero_copy_send(void)
360 MigrationState
*s
= migrate_get_current();
362 return s
->capabilities
[MIGRATION_CAPABILITY_ZERO_COPY_SEND
];
365 /* pseudo capabilities */
367 bool migrate_multifd_flush_after_each_section(void)
369 MigrationState
*s
= migrate_get_current();
371 return s
->multifd_flush_after_each_section
;
374 bool migrate_postcopy(void)
376 return migrate_postcopy_ram() || migrate_dirty_bitmaps();
379 bool migrate_tls(void)
381 MigrationState
*s
= migrate_get_current();
383 return s
->parameters
.tls_creds
&& *s
->parameters
.tls_creds
;
386 typedef enum WriteTrackingSupport
{
387 WT_SUPPORT_UNKNOWN
= 0,
389 WT_SUPPORT_AVAILABLE
,
390 WT_SUPPORT_COMPATIBLE
391 } WriteTrackingSupport
;
394 WriteTrackingSupport
migrate_query_write_tracking(void)
396 /* Check if kernel supports required UFFD features */
397 if (!ram_write_tracking_available()) {
398 return WT_SUPPORT_ABSENT
;
401 * Check if current memory configuration is
402 * compatible with required UFFD features.
404 if (!ram_write_tracking_compatible()) {
405 return WT_SUPPORT_AVAILABLE
;
408 return WT_SUPPORT_COMPATIBLE
;
411 /* Migration capabilities set */
412 struct MigrateCapsSet
{
413 int size
; /* Capability set size */
414 MigrationCapability caps
[]; /* Variadic array of capabilities */
416 typedef struct MigrateCapsSet MigrateCapsSet
;
418 /* Define and initialize MigrateCapsSet */
419 #define INITIALIZE_MIGRATE_CAPS_SET(_name, ...) \
420 MigrateCapsSet _name = { \
421 .size = sizeof((int []) { __VA_ARGS__ }) / sizeof(int), \
422 .caps = { __VA_ARGS__ } \
425 /* Background-snapshot compatibility check list */
427 INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snapshot
,
428 MIGRATION_CAPABILITY_POSTCOPY_RAM
,
429 MIGRATION_CAPABILITY_DIRTY_BITMAPS
,
430 MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME
,
431 MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE
,
432 MIGRATION_CAPABILITY_RETURN_PATH
,
433 MIGRATION_CAPABILITY_MULTIFD
,
434 MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER
,
435 MIGRATION_CAPABILITY_AUTO_CONVERGE
,
436 MIGRATION_CAPABILITY_RELEASE_RAM
,
437 MIGRATION_CAPABILITY_RDMA_PIN_ALL
,
438 MIGRATION_CAPABILITY_COMPRESS
,
439 MIGRATION_CAPABILITY_XBZRLE
,
440 MIGRATION_CAPABILITY_X_COLO
,
441 MIGRATION_CAPABILITY_VALIDATE_UUID
,
442 MIGRATION_CAPABILITY_ZERO_COPY_SEND
);
444 static bool migrate_incoming_started(void)
446 return !!migration_incoming_get_current()->transport_data
;
450 * @migration_caps_check - check capability compatibility
452 * @old_caps: old capability list
453 * @new_caps: new capability list
454 * @errp: set *errp if the check failed, with reason
456 * Returns true if check passed, otherwise false.
458 bool migrate_caps_check(bool *old_caps
, bool *new_caps
, Error
**errp
)
460 MigrationIncomingState
*mis
= migration_incoming_get_current();
463 #ifndef CONFIG_LIVE_BLOCK_MIGRATION
464 if (new_caps
[MIGRATION_CAPABILITY_BLOCK
]) {
465 error_setg(errp
, "QEMU compiled without old-style (blk/-b, inc/-i) "
467 error_append_hint(errp
, "Use drive_mirror+NBD instead.\n");
472 #ifndef CONFIG_REPLICATION
473 if (new_caps
[MIGRATION_CAPABILITY_X_COLO
]) {
474 error_setg(errp
, "QEMU compiled without replication module"
475 " can't enable COLO");
476 error_append_hint(errp
, "Please enable replication before COLO.\n");
481 if (new_caps
[MIGRATION_CAPABILITY_POSTCOPY_RAM
]) {
482 /* This check is reasonably expensive, so only when it's being
483 * set the first time, also it's only the destination that needs
486 if (!old_caps
[MIGRATION_CAPABILITY_POSTCOPY_RAM
] &&
487 runstate_check(RUN_STATE_INMIGRATE
) &&
488 !postcopy_ram_supported_by_host(mis
, errp
)) {
489 error_prepend(errp
, "Postcopy is not supported: ");
493 if (new_caps
[MIGRATION_CAPABILITY_X_IGNORE_SHARED
]) {
494 error_setg(errp
, "Postcopy is not compatible with ignore-shared");
498 if (new_caps
[MIGRATION_CAPABILITY_MULTIFD
]) {
499 error_setg(errp
, "Postcopy is not yet compatible with multifd");
504 if (new_caps
[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT
]) {
505 WriteTrackingSupport wt_support
;
508 * Check if 'background-snapshot' capability is supported by
509 * host kernel and compatible with guest memory configuration.
511 wt_support
= migrate_query_write_tracking();
512 if (wt_support
< WT_SUPPORT_AVAILABLE
) {
513 error_setg(errp
, "Background-snapshot is not supported by host kernel");
516 if (wt_support
< WT_SUPPORT_COMPATIBLE
) {
517 error_setg(errp
, "Background-snapshot is not compatible "
518 "with guest memory configuration");
523 * Check if there are any migration capabilities
524 * incompatible with 'background-snapshot'.
526 for (idx
= 0; idx
< check_caps_background_snapshot
.size
; idx
++) {
527 int incomp_cap
= check_caps_background_snapshot
.caps
[idx
];
528 if (new_caps
[incomp_cap
]) {
530 "Background-snapshot is not compatible with %s",
531 MigrationCapability_str(incomp_cap
));
538 if (new_caps
[MIGRATION_CAPABILITY_ZERO_COPY_SEND
] &&
539 (!new_caps
[MIGRATION_CAPABILITY_MULTIFD
] ||
540 new_caps
[MIGRATION_CAPABILITY_COMPRESS
] ||
541 new_caps
[MIGRATION_CAPABILITY_XBZRLE
] ||
542 migrate_multifd_compression() ||
545 "Zero copy only available for non-compressed non-TLS multifd migration");
549 if (new_caps
[MIGRATION_CAPABILITY_ZERO_COPY_SEND
]) {
551 "Zero copy currently only available on Linux");
556 if (new_caps
[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT
]) {
557 if (!new_caps
[MIGRATION_CAPABILITY_POSTCOPY_RAM
]) {
558 error_setg(errp
, "Postcopy preempt requires postcopy-ram");
563 * Preempt mode requires urgent pages to be sent in separate
564 * channel, OTOH compression logic will disorder all pages into
565 * different compression channels, which is not compatible with the
566 * preempt assumptions on channel assignments.
568 if (new_caps
[MIGRATION_CAPABILITY_COMPRESS
]) {
569 error_setg(errp
, "Postcopy preempt not compatible with compress");
573 if (migrate_incoming_started()) {
575 "Postcopy preempt must be set before incoming starts");
580 if (new_caps
[MIGRATION_CAPABILITY_MULTIFD
]) {
581 if (new_caps
[MIGRATION_CAPABILITY_COMPRESS
]) {
582 error_setg(errp
, "Multifd is not compatible with compress");
585 if (migrate_incoming_started()) {
586 error_setg(errp
, "Multifd must be set before incoming starts");
591 if (new_caps
[MIGRATION_CAPABILITY_SWITCHOVER_ACK
]) {
592 if (!new_caps
[MIGRATION_CAPABILITY_RETURN_PATH
]) {
593 error_setg(errp
, "Capability 'switchover-ack' requires capability "
598 if (new_caps
[MIGRATION_CAPABILITY_DIRTY_LIMIT
]) {
599 if (new_caps
[MIGRATION_CAPABILITY_AUTO_CONVERGE
]) {
600 error_setg(errp
, "dirty-limit conflicts with auto-converge"
601 " either of then available currently");
605 if (!kvm_enabled() || !kvm_dirty_ring_enabled()) {
606 error_setg(errp
, "dirty-limit requires KVM with accelerator"
607 " property 'dirty-ring-size' set");
615 bool migrate_cap_set(int cap
, bool value
, Error
**errp
)
617 MigrationState
*s
= migrate_get_current();
618 bool new_caps
[MIGRATION_CAPABILITY__MAX
];
620 if (migration_is_running(s
->state
)) {
621 error_setg(errp
, QERR_MIGRATION_ACTIVE
);
625 memcpy(new_caps
, s
->capabilities
, sizeof(new_caps
));
626 new_caps
[cap
] = value
;
628 if (!migrate_caps_check(s
->capabilities
, new_caps
, errp
)) {
631 s
->capabilities
[cap
] = value
;
635 MigrationCapabilityStatusList
*qmp_query_migrate_capabilities(Error
**errp
)
637 MigrationCapabilityStatusList
*head
= NULL
, **tail
= &head
;
638 MigrationCapabilityStatus
*caps
;
639 MigrationState
*s
= migrate_get_current();
642 for (i
= 0; i
< MIGRATION_CAPABILITY__MAX
; i
++) {
643 #ifndef CONFIG_LIVE_BLOCK_MIGRATION
644 if (i
== MIGRATION_CAPABILITY_BLOCK
) {
648 caps
= g_malloc0(sizeof(*caps
));
649 caps
->capability
= i
;
650 caps
->state
= s
->capabilities
[i
];
651 QAPI_LIST_APPEND(tail
, caps
);
657 void qmp_migrate_set_capabilities(MigrationCapabilityStatusList
*params
,
660 MigrationState
*s
= migrate_get_current();
661 MigrationCapabilityStatusList
*cap
;
662 bool new_caps
[MIGRATION_CAPABILITY__MAX
];
664 if (migration_is_running(s
->state
) || migration_in_colo_state()) {
665 error_setg(errp
, QERR_MIGRATION_ACTIVE
);
669 memcpy(new_caps
, s
->capabilities
, sizeof(new_caps
));
670 for (cap
= params
; cap
; cap
= cap
->next
) {
671 new_caps
[cap
->value
->capability
] = cap
->value
->state
;
674 if (!migrate_caps_check(s
->capabilities
, new_caps
, errp
)) {
678 for (cap
= params
; cap
; cap
= cap
->next
) {
679 s
->capabilities
[cap
->value
->capability
] = cap
->value
->state
;
685 const BitmapMigrationNodeAliasList
*migrate_block_bitmap_mapping(void)
687 MigrationState
*s
= migrate_get_current();
689 return s
->parameters
.block_bitmap_mapping
;
692 bool migrate_has_block_bitmap_mapping(void)
694 MigrationState
*s
= migrate_get_current();
696 return s
->parameters
.has_block_bitmap_mapping
;
699 bool migrate_block_incremental(void)
701 MigrationState
*s
= migrate_get_current();
703 return s
->parameters
.block_incremental
;
706 uint32_t migrate_checkpoint_delay(void)
708 MigrationState
*s
= migrate_get_current();
710 return s
->parameters
.x_checkpoint_delay
;
713 int migrate_compress_level(void)
715 MigrationState
*s
= migrate_get_current();
717 return s
->parameters
.compress_level
;
720 int migrate_compress_threads(void)
722 MigrationState
*s
= migrate_get_current();
724 return s
->parameters
.compress_threads
;
727 int migrate_compress_wait_thread(void)
729 MigrationState
*s
= migrate_get_current();
731 return s
->parameters
.compress_wait_thread
;
734 uint8_t migrate_cpu_throttle_increment(void)
736 MigrationState
*s
= migrate_get_current();
738 return s
->parameters
.cpu_throttle_increment
;
741 uint8_t migrate_cpu_throttle_initial(void)
743 MigrationState
*s
= migrate_get_current();
745 return s
->parameters
.cpu_throttle_initial
;
748 bool migrate_cpu_throttle_tailslow(void)
750 MigrationState
*s
= migrate_get_current();
752 return s
->parameters
.cpu_throttle_tailslow
;
755 int migrate_decompress_threads(void)
757 MigrationState
*s
= migrate_get_current();
759 return s
->parameters
.decompress_threads
;
762 uint64_t migrate_downtime_limit(void)
764 MigrationState
*s
= migrate_get_current();
766 return s
->parameters
.downtime_limit
;
769 uint8_t migrate_max_cpu_throttle(void)
771 MigrationState
*s
= migrate_get_current();
773 return s
->parameters
.max_cpu_throttle
;
776 uint64_t migrate_max_bandwidth(void)
778 MigrationState
*s
= migrate_get_current();
780 return s
->parameters
.max_bandwidth
;
783 uint64_t migrate_max_postcopy_bandwidth(void)
785 MigrationState
*s
= migrate_get_current();
787 return s
->parameters
.max_postcopy_bandwidth
;
790 int migrate_multifd_channels(void)
792 MigrationState
*s
= migrate_get_current();
794 return s
->parameters
.multifd_channels
;
797 MultiFDCompression
migrate_multifd_compression(void)
799 MigrationState
*s
= migrate_get_current();
801 assert(s
->parameters
.multifd_compression
< MULTIFD_COMPRESSION__MAX
);
802 return s
->parameters
.multifd_compression
;
805 int migrate_multifd_zlib_level(void)
807 MigrationState
*s
= migrate_get_current();
809 return s
->parameters
.multifd_zlib_level
;
812 int migrate_multifd_zstd_level(void)
814 MigrationState
*s
= migrate_get_current();
816 return s
->parameters
.multifd_zstd_level
;
819 uint8_t migrate_throttle_trigger_threshold(void)
821 MigrationState
*s
= migrate_get_current();
823 return s
->parameters
.throttle_trigger_threshold
;
826 const char *migrate_tls_authz(void)
828 MigrationState
*s
= migrate_get_current();
830 return s
->parameters
.tls_authz
;
833 const char *migrate_tls_creds(void)
835 MigrationState
*s
= migrate_get_current();
837 return s
->parameters
.tls_creds
;
840 const char *migrate_tls_hostname(void)
842 MigrationState
*s
= migrate_get_current();
844 return s
->parameters
.tls_hostname
;
847 uint64_t migrate_xbzrle_cache_size(void)
849 MigrationState
*s
= migrate_get_current();
851 return s
->parameters
.xbzrle_cache_size
;
854 /* parameter setters */
856 void migrate_set_block_incremental(bool value
)
858 MigrationState
*s
= migrate_get_current();
860 s
->parameters
.block_incremental
= value
;
863 /* parameters helpers */
865 void block_cleanup_parameters(void)
867 MigrationState
*s
= migrate_get_current();
869 if (s
->must_remove_block_options
) {
870 /* setting to false can never fail */
871 migrate_cap_set(MIGRATION_CAPABILITY_BLOCK
, false, &error_abort
);
872 migrate_set_block_incremental(false);
873 s
->must_remove_block_options
= false;
877 AnnounceParameters
*migrate_announce_params(void)
879 static AnnounceParameters ap
;
881 MigrationState
*s
= migrate_get_current();
883 ap
.initial
= s
->parameters
.announce_initial
;
884 ap
.max
= s
->parameters
.announce_max
;
885 ap
.rounds
= s
->parameters
.announce_rounds
;
886 ap
.step
= s
->parameters
.announce_step
;
891 MigrationParameters
*qmp_query_migrate_parameters(Error
**errp
)
893 MigrationParameters
*params
;
894 MigrationState
*s
= migrate_get_current();
896 /* TODO use QAPI_CLONE() instead of duplicating it inline */
897 params
= g_malloc0(sizeof(*params
));
898 params
->has_compress_level
= true;
899 params
->compress_level
= s
->parameters
.compress_level
;
900 params
->has_compress_threads
= true;
901 params
->compress_threads
= s
->parameters
.compress_threads
;
902 params
->has_compress_wait_thread
= true;
903 params
->compress_wait_thread
= s
->parameters
.compress_wait_thread
;
904 params
->has_decompress_threads
= true;
905 params
->decompress_threads
= s
->parameters
.decompress_threads
;
906 params
->has_throttle_trigger_threshold
= true;
907 params
->throttle_trigger_threshold
= s
->parameters
.throttle_trigger_threshold
;
908 params
->has_cpu_throttle_initial
= true;
909 params
->cpu_throttle_initial
= s
->parameters
.cpu_throttle_initial
;
910 params
->has_cpu_throttle_increment
= true;
911 params
->cpu_throttle_increment
= s
->parameters
.cpu_throttle_increment
;
912 params
->has_cpu_throttle_tailslow
= true;
913 params
->cpu_throttle_tailslow
= s
->parameters
.cpu_throttle_tailslow
;
914 params
->tls_creds
= g_strdup(s
->parameters
.tls_creds
);
915 params
->tls_hostname
= g_strdup(s
->parameters
.tls_hostname
);
916 params
->tls_authz
= g_strdup(s
->parameters
.tls_authz
?
917 s
->parameters
.tls_authz
: "");
918 params
->has_max_bandwidth
= true;
919 params
->max_bandwidth
= s
->parameters
.max_bandwidth
;
920 params
->has_downtime_limit
= true;
921 params
->downtime_limit
= s
->parameters
.downtime_limit
;
922 params
->has_x_checkpoint_delay
= true;
923 params
->x_checkpoint_delay
= s
->parameters
.x_checkpoint_delay
;
924 params
->has_block_incremental
= true;
925 params
->block_incremental
= s
->parameters
.block_incremental
;
926 params
->has_multifd_channels
= true;
927 params
->multifd_channels
= s
->parameters
.multifd_channels
;
928 params
->has_multifd_compression
= true;
929 params
->multifd_compression
= s
->parameters
.multifd_compression
;
930 params
->has_multifd_zlib_level
= true;
931 params
->multifd_zlib_level
= s
->parameters
.multifd_zlib_level
;
932 params
->has_multifd_zstd_level
= true;
933 params
->multifd_zstd_level
= s
->parameters
.multifd_zstd_level
;
934 params
->has_xbzrle_cache_size
= true;
935 params
->xbzrle_cache_size
= s
->parameters
.xbzrle_cache_size
;
936 params
->has_max_postcopy_bandwidth
= true;
937 params
->max_postcopy_bandwidth
= s
->parameters
.max_postcopy_bandwidth
;
938 params
->has_max_cpu_throttle
= true;
939 params
->max_cpu_throttle
= s
->parameters
.max_cpu_throttle
;
940 params
->has_announce_initial
= true;
941 params
->announce_initial
= s
->parameters
.announce_initial
;
942 params
->has_announce_max
= true;
943 params
->announce_max
= s
->parameters
.announce_max
;
944 params
->has_announce_rounds
= true;
945 params
->announce_rounds
= s
->parameters
.announce_rounds
;
946 params
->has_announce_step
= true;
947 params
->announce_step
= s
->parameters
.announce_step
;
949 if (s
->parameters
.has_block_bitmap_mapping
) {
950 params
->has_block_bitmap_mapping
= true;
951 params
->block_bitmap_mapping
=
952 QAPI_CLONE(BitmapMigrationNodeAliasList
,
953 s
->parameters
.block_bitmap_mapping
);
956 params
->has_x_vcpu_dirty_limit_period
= true;
957 params
->x_vcpu_dirty_limit_period
= s
->parameters
.x_vcpu_dirty_limit_period
;
958 params
->has_vcpu_dirty_limit
= true;
959 params
->vcpu_dirty_limit
= s
->parameters
.vcpu_dirty_limit
;
964 void migrate_params_init(MigrationParameters
*params
)
966 params
->tls_hostname
= g_strdup("");
967 params
->tls_creds
= g_strdup("");
969 /* Set has_* up only for parameter checks */
970 params
->has_compress_level
= true;
971 params
->has_compress_threads
= true;
972 params
->has_compress_wait_thread
= true;
973 params
->has_decompress_threads
= true;
974 params
->has_throttle_trigger_threshold
= true;
975 params
->has_cpu_throttle_initial
= true;
976 params
->has_cpu_throttle_increment
= true;
977 params
->has_cpu_throttle_tailslow
= true;
978 params
->has_max_bandwidth
= true;
979 params
->has_downtime_limit
= true;
980 params
->has_x_checkpoint_delay
= true;
981 params
->has_block_incremental
= true;
982 params
->has_multifd_channels
= true;
983 params
->has_multifd_compression
= true;
984 params
->has_multifd_zlib_level
= true;
985 params
->has_multifd_zstd_level
= true;
986 params
->has_xbzrle_cache_size
= true;
987 params
->has_max_postcopy_bandwidth
= true;
988 params
->has_max_cpu_throttle
= true;
989 params
->has_announce_initial
= true;
990 params
->has_announce_max
= true;
991 params
->has_announce_rounds
= true;
992 params
->has_announce_step
= true;
993 params
->has_x_vcpu_dirty_limit_period
= true;
994 params
->has_vcpu_dirty_limit
= true;
998 * Check whether the parameters are valid. Error will be put into errp
999 * (if provided). Return true if valid, otherwise false.
1001 bool migrate_params_check(MigrationParameters
*params
, Error
**errp
)
1003 if (params
->has_compress_level
&&
1004 (params
->compress_level
> 9)) {
1005 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "compress_level",
1006 "a value between 0 and 9");
1010 if (params
->has_compress_threads
&& (params
->compress_threads
< 1)) {
1011 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1013 "a value between 1 and 255");
1017 if (params
->has_decompress_threads
&& (params
->decompress_threads
< 1)) {
1018 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1019 "decompress_threads",
1020 "a value between 1 and 255");
1024 if (params
->has_throttle_trigger_threshold
&&
1025 (params
->throttle_trigger_threshold
< 1 ||
1026 params
->throttle_trigger_threshold
> 100)) {
1027 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1028 "throttle_trigger_threshold",
1029 "an integer in the range of 1 to 100");
1033 if (params
->has_cpu_throttle_initial
&&
1034 (params
->cpu_throttle_initial
< 1 ||
1035 params
->cpu_throttle_initial
> 99)) {
1036 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1037 "cpu_throttle_initial",
1038 "an integer in the range of 1 to 99");
1042 if (params
->has_cpu_throttle_increment
&&
1043 (params
->cpu_throttle_increment
< 1 ||
1044 params
->cpu_throttle_increment
> 99)) {
1045 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1046 "cpu_throttle_increment",
1047 "an integer in the range of 1 to 99");
1051 if (params
->has_max_bandwidth
&& (params
->max_bandwidth
> SIZE_MAX
)) {
1052 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1054 "an integer in the range of 0 to "stringify(SIZE_MAX
)
1059 if (params
->has_downtime_limit
&&
1060 (params
->downtime_limit
> MAX_MIGRATE_DOWNTIME
)) {
1061 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1063 "an integer in the range of 0 to "
1064 stringify(MAX_MIGRATE_DOWNTIME
)" ms");
1068 /* x_checkpoint_delay is now always positive */
1070 if (params
->has_multifd_channels
&& (params
->multifd_channels
< 1)) {
1071 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1073 "a value between 1 and 255");
1077 if (params
->has_multifd_zlib_level
&&
1078 (params
->multifd_zlib_level
> 9)) {
1079 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "multifd_zlib_level",
1080 "a value between 0 and 9");
1084 if (params
->has_multifd_zstd_level
&&
1085 (params
->multifd_zstd_level
> 20)) {
1086 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "multifd_zstd_level",
1087 "a value between 0 and 20");
1091 if (params
->has_xbzrle_cache_size
&&
1092 (params
->xbzrle_cache_size
< qemu_target_page_size() ||
1093 !is_power_of_2(params
->xbzrle_cache_size
))) {
1094 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1095 "xbzrle_cache_size",
1096 "a power of two no less than the target page size");
1100 if (params
->has_max_cpu_throttle
&&
1101 (params
->max_cpu_throttle
< params
->cpu_throttle_initial
||
1102 params
->max_cpu_throttle
> 99)) {
1103 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1105 "an integer in the range of cpu_throttle_initial to 99");
1109 if (params
->has_announce_initial
&&
1110 params
->announce_initial
> 100000) {
1111 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1113 "a value between 0 and 100000");
1116 if (params
->has_announce_max
&&
1117 params
->announce_max
> 100000) {
1118 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1120 "a value between 0 and 100000");
1123 if (params
->has_announce_rounds
&&
1124 params
->announce_rounds
> 1000) {
1125 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1127 "a value between 0 and 1000");
1130 if (params
->has_announce_step
&&
1131 (params
->announce_step
< 1 ||
1132 params
->announce_step
> 10000)) {
1133 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1135 "a value between 0 and 10000");
1139 if (params
->has_block_bitmap_mapping
&&
1140 !check_dirty_bitmap_mig_alias_map(params
->block_bitmap_mapping
, errp
)) {
1141 error_prepend(errp
, "Invalid mapping given for block-bitmap-mapping: ");
1146 if (migrate_zero_copy_send() &&
1147 ((params
->has_multifd_compression
&& params
->multifd_compression
) ||
1148 (params
->tls_creds
&& *params
->tls_creds
))) {
1150 "Zero copy only available for non-compressed non-TLS multifd migration");
1155 if (params
->has_x_vcpu_dirty_limit_period
&&
1156 (params
->x_vcpu_dirty_limit_period
< 1 ||
1157 params
->x_vcpu_dirty_limit_period
> 1000)) {
1158 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1159 "x-vcpu-dirty-limit-period",
1160 "a value between 1 and 1000");
1164 if (params
->has_vcpu_dirty_limit
&&
1165 (params
->vcpu_dirty_limit
< 1)) {
1166 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
1168 "is invalid, it must greater then 1 MB/s");
1175 static void migrate_params_test_apply(MigrateSetParameters
*params
,
1176 MigrationParameters
*dest
)
1178 *dest
= migrate_get_current()->parameters
;
1180 /* TODO use QAPI_CLONE() instead of duplicating it inline */
1182 if (params
->has_compress_level
) {
1183 dest
->compress_level
= params
->compress_level
;
1186 if (params
->has_compress_threads
) {
1187 dest
->compress_threads
= params
->compress_threads
;
1190 if (params
->has_compress_wait_thread
) {
1191 dest
->compress_wait_thread
= params
->compress_wait_thread
;
1194 if (params
->has_decompress_threads
) {
1195 dest
->decompress_threads
= params
->decompress_threads
;
1198 if (params
->has_throttle_trigger_threshold
) {
1199 dest
->throttle_trigger_threshold
= params
->throttle_trigger_threshold
;
1202 if (params
->has_cpu_throttle_initial
) {
1203 dest
->cpu_throttle_initial
= params
->cpu_throttle_initial
;
1206 if (params
->has_cpu_throttle_increment
) {
1207 dest
->cpu_throttle_increment
= params
->cpu_throttle_increment
;
1210 if (params
->has_cpu_throttle_tailslow
) {
1211 dest
->cpu_throttle_tailslow
= params
->cpu_throttle_tailslow
;
1214 if (params
->tls_creds
) {
1215 assert(params
->tls_creds
->type
== QTYPE_QSTRING
);
1216 dest
->tls_creds
= params
->tls_creds
->u
.s
;
1219 if (params
->tls_hostname
) {
1220 assert(params
->tls_hostname
->type
== QTYPE_QSTRING
);
1221 dest
->tls_hostname
= params
->tls_hostname
->u
.s
;
1224 if (params
->has_max_bandwidth
) {
1225 dest
->max_bandwidth
= params
->max_bandwidth
;
1228 if (params
->has_downtime_limit
) {
1229 dest
->downtime_limit
= params
->downtime_limit
;
1232 if (params
->has_x_checkpoint_delay
) {
1233 dest
->x_checkpoint_delay
= params
->x_checkpoint_delay
;
1236 if (params
->has_block_incremental
) {
1237 dest
->block_incremental
= params
->block_incremental
;
1239 if (params
->has_multifd_channels
) {
1240 dest
->multifd_channels
= params
->multifd_channels
;
1242 if (params
->has_multifd_compression
) {
1243 dest
->multifd_compression
= params
->multifd_compression
;
1245 if (params
->has_xbzrle_cache_size
) {
1246 dest
->xbzrle_cache_size
= params
->xbzrle_cache_size
;
1248 if (params
->has_max_postcopy_bandwidth
) {
1249 dest
->max_postcopy_bandwidth
= params
->max_postcopy_bandwidth
;
1251 if (params
->has_max_cpu_throttle
) {
1252 dest
->max_cpu_throttle
= params
->max_cpu_throttle
;
1254 if (params
->has_announce_initial
) {
1255 dest
->announce_initial
= params
->announce_initial
;
1257 if (params
->has_announce_max
) {
1258 dest
->announce_max
= params
->announce_max
;
1260 if (params
->has_announce_rounds
) {
1261 dest
->announce_rounds
= params
->announce_rounds
;
1263 if (params
->has_announce_step
) {
1264 dest
->announce_step
= params
->announce_step
;
1267 if (params
->has_block_bitmap_mapping
) {
1268 dest
->has_block_bitmap_mapping
= true;
1269 dest
->block_bitmap_mapping
= params
->block_bitmap_mapping
;
1272 if (params
->has_x_vcpu_dirty_limit_period
) {
1273 dest
->x_vcpu_dirty_limit_period
=
1274 params
->x_vcpu_dirty_limit_period
;
1276 if (params
->has_vcpu_dirty_limit
) {
1277 dest
->vcpu_dirty_limit
= params
->vcpu_dirty_limit
;
1281 static void migrate_params_apply(MigrateSetParameters
*params
, Error
**errp
)
1283 MigrationState
*s
= migrate_get_current();
1285 /* TODO use QAPI_CLONE() instead of duplicating it inline */
1287 if (params
->has_compress_level
) {
1288 s
->parameters
.compress_level
= params
->compress_level
;
1291 if (params
->has_compress_threads
) {
1292 s
->parameters
.compress_threads
= params
->compress_threads
;
1295 if (params
->has_compress_wait_thread
) {
1296 s
->parameters
.compress_wait_thread
= params
->compress_wait_thread
;
1299 if (params
->has_decompress_threads
) {
1300 s
->parameters
.decompress_threads
= params
->decompress_threads
;
1303 if (params
->has_throttle_trigger_threshold
) {
1304 s
->parameters
.throttle_trigger_threshold
= params
->throttle_trigger_threshold
;
1307 if (params
->has_cpu_throttle_initial
) {
1308 s
->parameters
.cpu_throttle_initial
= params
->cpu_throttle_initial
;
1311 if (params
->has_cpu_throttle_increment
) {
1312 s
->parameters
.cpu_throttle_increment
= params
->cpu_throttle_increment
;
1315 if (params
->has_cpu_throttle_tailslow
) {
1316 s
->parameters
.cpu_throttle_tailslow
= params
->cpu_throttle_tailslow
;
1319 if (params
->tls_creds
) {
1320 g_free(s
->parameters
.tls_creds
);
1321 assert(params
->tls_creds
->type
== QTYPE_QSTRING
);
1322 s
->parameters
.tls_creds
= g_strdup(params
->tls_creds
->u
.s
);
1325 if (params
->tls_hostname
) {
1326 g_free(s
->parameters
.tls_hostname
);
1327 assert(params
->tls_hostname
->type
== QTYPE_QSTRING
);
1328 s
->parameters
.tls_hostname
= g_strdup(params
->tls_hostname
->u
.s
);
1331 if (params
->tls_authz
) {
1332 g_free(s
->parameters
.tls_authz
);
1333 assert(params
->tls_authz
->type
== QTYPE_QSTRING
);
1334 s
->parameters
.tls_authz
= g_strdup(params
->tls_authz
->u
.s
);
1337 if (params
->has_max_bandwidth
) {
1338 s
->parameters
.max_bandwidth
= params
->max_bandwidth
;
1339 if (s
->to_dst_file
&& !migration_in_postcopy()) {
1340 migration_rate_set(s
->parameters
.max_bandwidth
);
1344 if (params
->has_downtime_limit
) {
1345 s
->parameters
.downtime_limit
= params
->downtime_limit
;
1348 if (params
->has_x_checkpoint_delay
) {
1349 s
->parameters
.x_checkpoint_delay
= params
->x_checkpoint_delay
;
1350 colo_checkpoint_delay_set();
1353 if (params
->has_block_incremental
) {
1354 s
->parameters
.block_incremental
= params
->block_incremental
;
1356 if (params
->has_multifd_channels
) {
1357 s
->parameters
.multifd_channels
= params
->multifd_channels
;
1359 if (params
->has_multifd_compression
) {
1360 s
->parameters
.multifd_compression
= params
->multifd_compression
;
1362 if (params
->has_xbzrle_cache_size
) {
1363 s
->parameters
.xbzrle_cache_size
= params
->xbzrle_cache_size
;
1364 xbzrle_cache_resize(params
->xbzrle_cache_size
, errp
);
1366 if (params
->has_max_postcopy_bandwidth
) {
1367 s
->parameters
.max_postcopy_bandwidth
= params
->max_postcopy_bandwidth
;
1368 if (s
->to_dst_file
&& migration_in_postcopy()) {
1369 migration_rate_set(s
->parameters
.max_postcopy_bandwidth
);
1372 if (params
->has_max_cpu_throttle
) {
1373 s
->parameters
.max_cpu_throttle
= params
->max_cpu_throttle
;
1375 if (params
->has_announce_initial
) {
1376 s
->parameters
.announce_initial
= params
->announce_initial
;
1378 if (params
->has_announce_max
) {
1379 s
->parameters
.announce_max
= params
->announce_max
;
1381 if (params
->has_announce_rounds
) {
1382 s
->parameters
.announce_rounds
= params
->announce_rounds
;
1384 if (params
->has_announce_step
) {
1385 s
->parameters
.announce_step
= params
->announce_step
;
1388 if (params
->has_block_bitmap_mapping
) {
1389 qapi_free_BitmapMigrationNodeAliasList(
1390 s
->parameters
.block_bitmap_mapping
);
1392 s
->parameters
.has_block_bitmap_mapping
= true;
1393 s
->parameters
.block_bitmap_mapping
=
1394 QAPI_CLONE(BitmapMigrationNodeAliasList
,
1395 params
->block_bitmap_mapping
);
1398 if (params
->has_x_vcpu_dirty_limit_period
) {
1399 s
->parameters
.x_vcpu_dirty_limit_period
=
1400 params
->x_vcpu_dirty_limit_period
;
1402 if (params
->has_vcpu_dirty_limit
) {
1403 s
->parameters
.vcpu_dirty_limit
= params
->vcpu_dirty_limit
;
1407 void qmp_migrate_set_parameters(MigrateSetParameters
*params
, Error
**errp
)
1409 MigrationParameters tmp
;
1411 /* TODO Rewrite "" to null instead */
1412 if (params
->tls_creds
1413 && params
->tls_creds
->type
== QTYPE_QNULL
) {
1414 qobject_unref(params
->tls_creds
->u
.n
);
1415 params
->tls_creds
->type
= QTYPE_QSTRING
;
1416 params
->tls_creds
->u
.s
= strdup("");
1418 /* TODO Rewrite "" to null instead */
1419 if (params
->tls_hostname
1420 && params
->tls_hostname
->type
== QTYPE_QNULL
) {
1421 qobject_unref(params
->tls_hostname
->u
.n
);
1422 params
->tls_hostname
->type
= QTYPE_QSTRING
;
1423 params
->tls_hostname
->u
.s
= strdup("");
1426 migrate_params_test_apply(params
, &tmp
);
1428 if (!migrate_params_check(&tmp
, errp
)) {
1429 /* Invalid parameter */
1433 migrate_params_apply(params
, errp
);