migration: Give one error if trying to set COMPRESSION and XBZRLE
[qemu/ar7.git] / migration / options.c
blob37fa1cfe742718e9ef6791624083c073bff0dc02
1 /*
2 * QEMU migration capabilities
4 * Copyright (c) 2012-2023 Red Hat Inc
6 * Authors:
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"
28 #include "ram.h"
29 #include "options.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_SIZE("avail-switchover-bandwidth", MigrationState,
129 parameters.avail_switchover_bandwidth, 0),
130 DEFINE_PROP_UINT64("x-downtime-limit", MigrationState,
131 parameters.downtime_limit,
132 DEFAULT_MIGRATE_SET_DOWNTIME),
133 DEFINE_PROP_UINT32("x-checkpoint-delay", MigrationState,
134 parameters.x_checkpoint_delay,
135 DEFAULT_MIGRATE_X_CHECKPOINT_DELAY),
136 DEFINE_PROP_UINT8("multifd-channels", MigrationState,
137 parameters.multifd_channels,
138 DEFAULT_MIGRATE_MULTIFD_CHANNELS),
139 DEFINE_PROP_MULTIFD_COMPRESSION("multifd-compression", MigrationState,
140 parameters.multifd_compression,
141 DEFAULT_MIGRATE_MULTIFD_COMPRESSION),
142 DEFINE_PROP_UINT8("multifd-zlib-level", MigrationState,
143 parameters.multifd_zlib_level,
144 DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL),
145 DEFINE_PROP_UINT8("multifd-zstd-level", MigrationState,
146 parameters.multifd_zstd_level,
147 DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL),
148 DEFINE_PROP_SIZE("xbzrle-cache-size", MigrationState,
149 parameters.xbzrle_cache_size,
150 DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE),
151 DEFINE_PROP_SIZE("max-postcopy-bandwidth", MigrationState,
152 parameters.max_postcopy_bandwidth,
153 DEFAULT_MIGRATE_MAX_POSTCOPY_BANDWIDTH),
154 DEFINE_PROP_UINT8("max-cpu-throttle", MigrationState,
155 parameters.max_cpu_throttle,
156 DEFAULT_MIGRATE_MAX_CPU_THROTTLE),
157 DEFINE_PROP_SIZE("announce-initial", MigrationState,
158 parameters.announce_initial,
159 DEFAULT_MIGRATE_ANNOUNCE_INITIAL),
160 DEFINE_PROP_SIZE("announce-max", MigrationState,
161 parameters.announce_max,
162 DEFAULT_MIGRATE_ANNOUNCE_MAX),
163 DEFINE_PROP_SIZE("announce-rounds", MigrationState,
164 parameters.announce_rounds,
165 DEFAULT_MIGRATE_ANNOUNCE_ROUNDS),
166 DEFINE_PROP_SIZE("announce-step", MigrationState,
167 parameters.announce_step,
168 DEFAULT_MIGRATE_ANNOUNCE_STEP),
169 DEFINE_PROP_STRING("tls-creds", MigrationState, parameters.tls_creds),
170 DEFINE_PROP_STRING("tls-hostname", MigrationState, parameters.tls_hostname),
171 DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz),
172 DEFINE_PROP_UINT64("x-vcpu-dirty-limit-period", MigrationState,
173 parameters.x_vcpu_dirty_limit_period,
174 DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD),
175 DEFINE_PROP_UINT64("vcpu-dirty-limit", MigrationState,
176 parameters.vcpu_dirty_limit,
177 DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT),
179 /* Migration capabilities */
180 DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE),
181 DEFINE_PROP_MIG_CAP("x-rdma-pin-all", MIGRATION_CAPABILITY_RDMA_PIN_ALL),
182 DEFINE_PROP_MIG_CAP("x-auto-converge", MIGRATION_CAPABILITY_AUTO_CONVERGE),
183 DEFINE_PROP_MIG_CAP("x-zero-blocks", MIGRATION_CAPABILITY_ZERO_BLOCKS),
184 DEFINE_PROP_MIG_CAP("x-compress", MIGRATION_CAPABILITY_COMPRESS),
185 DEFINE_PROP_MIG_CAP("x-events", MIGRATION_CAPABILITY_EVENTS),
186 DEFINE_PROP_MIG_CAP("x-postcopy-ram", MIGRATION_CAPABILITY_POSTCOPY_RAM),
187 DEFINE_PROP_MIG_CAP("x-postcopy-preempt",
188 MIGRATION_CAPABILITY_POSTCOPY_PREEMPT),
189 DEFINE_PROP_MIG_CAP("x-colo", MIGRATION_CAPABILITY_X_COLO),
190 DEFINE_PROP_MIG_CAP("x-release-ram", MIGRATION_CAPABILITY_RELEASE_RAM),
191 DEFINE_PROP_MIG_CAP("x-block", MIGRATION_CAPABILITY_BLOCK),
192 DEFINE_PROP_MIG_CAP("x-return-path", MIGRATION_CAPABILITY_RETURN_PATH),
193 DEFINE_PROP_MIG_CAP("x-multifd", MIGRATION_CAPABILITY_MULTIFD),
194 DEFINE_PROP_MIG_CAP("x-background-snapshot",
195 MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT),
196 #ifdef CONFIG_LINUX
197 DEFINE_PROP_MIG_CAP("x-zero-copy-send",
198 MIGRATION_CAPABILITY_ZERO_COPY_SEND),
199 #endif
200 DEFINE_PROP_MIG_CAP("x-switchover-ack",
201 MIGRATION_CAPABILITY_SWITCHOVER_ACK),
202 DEFINE_PROP_MIG_CAP("x-dirty-limit", MIGRATION_CAPABILITY_DIRTY_LIMIT),
203 DEFINE_PROP_END_OF_LIST(),
206 bool migrate_auto_converge(void)
208 MigrationState *s = migrate_get_current();
210 return s->capabilities[MIGRATION_CAPABILITY_AUTO_CONVERGE];
213 bool migrate_background_snapshot(void)
215 MigrationState *s = migrate_get_current();
217 return s->capabilities[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT];
220 bool migrate_block(void)
222 MigrationState *s = migrate_get_current();
224 return s->capabilities[MIGRATION_CAPABILITY_BLOCK];
227 bool migrate_colo(void)
229 MigrationState *s = migrate_get_current();
231 return s->capabilities[MIGRATION_CAPABILITY_X_COLO];
234 bool migrate_compress(void)
236 MigrationState *s = migrate_get_current();
238 return s->capabilities[MIGRATION_CAPABILITY_COMPRESS];
241 bool migrate_dirty_bitmaps(void)
243 MigrationState *s = migrate_get_current();
245 return s->capabilities[MIGRATION_CAPABILITY_DIRTY_BITMAPS];
248 bool migrate_dirty_limit(void)
250 MigrationState *s = migrate_get_current();
252 return s->capabilities[MIGRATION_CAPABILITY_DIRTY_LIMIT];
255 bool migrate_events(void)
257 MigrationState *s = migrate_get_current();
259 return s->capabilities[MIGRATION_CAPABILITY_EVENTS];
262 bool migrate_ignore_shared(void)
264 MigrationState *s = migrate_get_current();
266 return s->capabilities[MIGRATION_CAPABILITY_X_IGNORE_SHARED];
269 bool migrate_late_block_activate(void)
271 MigrationState *s = migrate_get_current();
273 return s->capabilities[MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE];
276 bool migrate_multifd(void)
278 MigrationState *s = migrate_get_current();
280 return s->capabilities[MIGRATION_CAPABILITY_MULTIFD];
283 bool migrate_pause_before_switchover(void)
285 MigrationState *s = migrate_get_current();
287 return s->capabilities[MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER];
290 bool migrate_postcopy_blocktime(void)
292 MigrationState *s = migrate_get_current();
294 return s->capabilities[MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME];
297 bool migrate_postcopy_preempt(void)
299 MigrationState *s = migrate_get_current();
301 return s->capabilities[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT];
304 bool migrate_postcopy_ram(void)
306 MigrationState *s = migrate_get_current();
308 return s->capabilities[MIGRATION_CAPABILITY_POSTCOPY_RAM];
311 bool migrate_rdma_pin_all(void)
313 MigrationState *s = migrate_get_current();
315 return s->capabilities[MIGRATION_CAPABILITY_RDMA_PIN_ALL];
318 bool migrate_release_ram(void)
320 MigrationState *s = migrate_get_current();
322 return s->capabilities[MIGRATION_CAPABILITY_RELEASE_RAM];
325 bool migrate_return_path(void)
327 MigrationState *s = migrate_get_current();
329 return s->capabilities[MIGRATION_CAPABILITY_RETURN_PATH];
332 bool migrate_switchover_ack(void)
334 MigrationState *s = migrate_get_current();
336 return s->capabilities[MIGRATION_CAPABILITY_SWITCHOVER_ACK];
339 bool migrate_validate_uuid(void)
341 MigrationState *s = migrate_get_current();
343 return s->capabilities[MIGRATION_CAPABILITY_VALIDATE_UUID];
346 bool migrate_xbzrle(void)
348 MigrationState *s = migrate_get_current();
350 return s->capabilities[MIGRATION_CAPABILITY_XBZRLE];
353 bool migrate_zero_blocks(void)
355 MigrationState *s = migrate_get_current();
357 return s->capabilities[MIGRATION_CAPABILITY_ZERO_BLOCKS];
360 bool migrate_zero_copy_send(void)
362 MigrationState *s = migrate_get_current();
364 return s->capabilities[MIGRATION_CAPABILITY_ZERO_COPY_SEND];
367 /* pseudo capabilities */
369 bool migrate_multifd_flush_after_each_section(void)
371 MigrationState *s = migrate_get_current();
373 return s->multifd_flush_after_each_section;
376 bool migrate_postcopy(void)
378 return migrate_postcopy_ram() || migrate_dirty_bitmaps();
381 bool migrate_rdma(void)
383 MigrationState *s = migrate_get_current();
385 return s->rdma_migration;
388 bool migrate_tls(void)
390 MigrationState *s = migrate_get_current();
392 return s->parameters.tls_creds && *s->parameters.tls_creds;
395 typedef enum WriteTrackingSupport {
396 WT_SUPPORT_UNKNOWN = 0,
397 WT_SUPPORT_ABSENT,
398 WT_SUPPORT_AVAILABLE,
399 WT_SUPPORT_COMPATIBLE
400 } WriteTrackingSupport;
402 static
403 WriteTrackingSupport migrate_query_write_tracking(void)
405 /* Check if kernel supports required UFFD features */
406 if (!ram_write_tracking_available()) {
407 return WT_SUPPORT_ABSENT;
410 * Check if current memory configuration is
411 * compatible with required UFFD features.
413 if (!ram_write_tracking_compatible()) {
414 return WT_SUPPORT_AVAILABLE;
417 return WT_SUPPORT_COMPATIBLE;
420 /* Migration capabilities set */
421 struct MigrateCapsSet {
422 int size; /* Capability set size */
423 MigrationCapability caps[]; /* Variadic array of capabilities */
425 typedef struct MigrateCapsSet MigrateCapsSet;
427 /* Define and initialize MigrateCapsSet */
428 #define INITIALIZE_MIGRATE_CAPS_SET(_name, ...) \
429 MigrateCapsSet _name = { \
430 .size = sizeof((int []) { __VA_ARGS__ }) / sizeof(int), \
431 .caps = { __VA_ARGS__ } \
434 /* Background-snapshot compatibility check list */
435 static const
436 INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snapshot,
437 MIGRATION_CAPABILITY_POSTCOPY_RAM,
438 MIGRATION_CAPABILITY_DIRTY_BITMAPS,
439 MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME,
440 MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE,
441 MIGRATION_CAPABILITY_RETURN_PATH,
442 MIGRATION_CAPABILITY_MULTIFD,
443 MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER,
444 MIGRATION_CAPABILITY_AUTO_CONVERGE,
445 MIGRATION_CAPABILITY_RELEASE_RAM,
446 MIGRATION_CAPABILITY_RDMA_PIN_ALL,
447 MIGRATION_CAPABILITY_COMPRESS,
448 MIGRATION_CAPABILITY_XBZRLE,
449 MIGRATION_CAPABILITY_X_COLO,
450 MIGRATION_CAPABILITY_VALIDATE_UUID,
451 MIGRATION_CAPABILITY_ZERO_COPY_SEND);
453 static bool migrate_incoming_started(void)
455 return !!migration_incoming_get_current()->transport_data;
459 * @migration_caps_check - check capability compatibility
461 * @old_caps: old capability list
462 * @new_caps: new capability list
463 * @errp: set *errp if the check failed, with reason
465 * Returns true if check passed, otherwise false.
467 bool migrate_caps_check(bool *old_caps, bool *new_caps, Error **errp)
469 MigrationIncomingState *mis = migration_incoming_get_current();
471 ERRP_GUARD();
472 #ifndef CONFIG_LIVE_BLOCK_MIGRATION
473 if (new_caps[MIGRATION_CAPABILITY_BLOCK]) {
474 error_setg(errp, "QEMU compiled without old-style (blk/-b, inc/-i) "
475 "block migration");
476 error_append_hint(errp, "Use drive_mirror+NBD instead.\n");
477 return false;
479 #endif
481 #ifndef CONFIG_REPLICATION
482 if (new_caps[MIGRATION_CAPABILITY_X_COLO]) {
483 error_setg(errp, "QEMU compiled without replication module"
484 " can't enable COLO");
485 error_append_hint(errp, "Please enable replication before COLO.\n");
486 return false;
488 #endif
490 if (new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) {
491 /* This check is reasonably expensive, so only when it's being
492 * set the first time, also it's only the destination that needs
493 * special support.
495 if (!old_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM] &&
496 runstate_check(RUN_STATE_INMIGRATE) &&
497 !postcopy_ram_supported_by_host(mis, errp)) {
498 error_prepend(errp, "Postcopy is not supported: ");
499 return false;
502 if (new_caps[MIGRATION_CAPABILITY_X_IGNORE_SHARED]) {
503 error_setg(errp, "Postcopy is not compatible with ignore-shared");
504 return false;
507 if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) {
508 error_setg(errp, "Postcopy is not yet compatible with multifd");
509 return false;
513 if (new_caps[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT]) {
514 WriteTrackingSupport wt_support;
515 int idx;
517 * Check if 'background-snapshot' capability is supported by
518 * host kernel and compatible with guest memory configuration.
520 wt_support = migrate_query_write_tracking();
521 if (wt_support < WT_SUPPORT_AVAILABLE) {
522 error_setg(errp, "Background-snapshot is not supported by host kernel");
523 return false;
525 if (wt_support < WT_SUPPORT_COMPATIBLE) {
526 error_setg(errp, "Background-snapshot is not compatible "
527 "with guest memory configuration");
528 return false;
532 * Check if there are any migration capabilities
533 * incompatible with 'background-snapshot'.
535 for (idx = 0; idx < check_caps_background_snapshot.size; idx++) {
536 int incomp_cap = check_caps_background_snapshot.caps[idx];
537 if (new_caps[incomp_cap]) {
538 error_setg(errp,
539 "Background-snapshot is not compatible with %s",
540 MigrationCapability_str(incomp_cap));
541 return false;
546 #ifdef CONFIG_LINUX
547 if (new_caps[MIGRATION_CAPABILITY_ZERO_COPY_SEND] &&
548 (!new_caps[MIGRATION_CAPABILITY_MULTIFD] ||
549 new_caps[MIGRATION_CAPABILITY_COMPRESS] ||
550 new_caps[MIGRATION_CAPABILITY_XBZRLE] ||
551 migrate_multifd_compression() ||
552 migrate_tls())) {
553 error_setg(errp,
554 "Zero copy only available for non-compressed non-TLS multifd migration");
555 return false;
557 #else
558 if (new_caps[MIGRATION_CAPABILITY_ZERO_COPY_SEND]) {
559 error_setg(errp,
560 "Zero copy currently only available on Linux");
561 return false;
563 #endif
565 if (new_caps[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT]) {
566 if (!new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) {
567 error_setg(errp, "Postcopy preempt requires postcopy-ram");
568 return false;
572 * Preempt mode requires urgent pages to be sent in separate
573 * channel, OTOH compression logic will disorder all pages into
574 * different compression channels, which is not compatible with the
575 * preempt assumptions on channel assignments.
577 if (new_caps[MIGRATION_CAPABILITY_COMPRESS]) {
578 error_setg(errp, "Postcopy preempt not compatible with compress");
579 return false;
582 if (migrate_incoming_started()) {
583 error_setg(errp,
584 "Postcopy preempt must be set before incoming starts");
585 return false;
589 if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) {
590 if (new_caps[MIGRATION_CAPABILITY_COMPRESS]) {
591 error_setg(errp, "Multifd is not compatible with compress");
592 return false;
594 if (migrate_incoming_started()) {
595 error_setg(errp, "Multifd must be set before incoming starts");
596 return false;
600 if (new_caps[MIGRATION_CAPABILITY_SWITCHOVER_ACK]) {
601 if (!new_caps[MIGRATION_CAPABILITY_RETURN_PATH]) {
602 error_setg(errp, "Capability 'switchover-ack' requires capability "
603 "'return-path'");
604 return false;
607 if (new_caps[MIGRATION_CAPABILITY_DIRTY_LIMIT]) {
608 if (new_caps[MIGRATION_CAPABILITY_AUTO_CONVERGE]) {
609 error_setg(errp, "dirty-limit conflicts with auto-converge"
610 " either of then available currently");
611 return false;
614 if (!kvm_enabled() || !kvm_dirty_ring_enabled()) {
615 error_setg(errp, "dirty-limit requires KVM with accelerator"
616 " property 'dirty-ring-size' set");
617 return false;
621 if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) {
622 if (new_caps[MIGRATION_CAPABILITY_XBZRLE]) {
623 error_setg(errp, "Multifd is not compatible with xbzrle");
624 return false;
628 if (new_caps[MIGRATION_CAPABILITY_COMPRESS]) {
629 if (new_caps[MIGRATION_CAPABILITY_XBZRLE]) {
630 error_setg(errp, "Compression is not compatible with xbzrle");
631 return false;
635 return true;
638 bool migrate_cap_set(int cap, bool value, Error **errp)
640 MigrationState *s = migrate_get_current();
641 bool new_caps[MIGRATION_CAPABILITY__MAX];
643 if (migration_is_running(s->state)) {
644 error_setg(errp, QERR_MIGRATION_ACTIVE);
645 return false;
648 memcpy(new_caps, s->capabilities, sizeof(new_caps));
649 new_caps[cap] = value;
651 if (!migrate_caps_check(s->capabilities, new_caps, errp)) {
652 return false;
654 s->capabilities[cap] = value;
655 return true;
658 MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp)
660 MigrationCapabilityStatusList *head = NULL, **tail = &head;
661 MigrationCapabilityStatus *caps;
662 MigrationState *s = migrate_get_current();
663 int i;
665 for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
666 #ifndef CONFIG_LIVE_BLOCK_MIGRATION
667 if (i == MIGRATION_CAPABILITY_BLOCK) {
668 continue;
670 #endif
671 caps = g_malloc0(sizeof(*caps));
672 caps->capability = i;
673 caps->state = s->capabilities[i];
674 QAPI_LIST_APPEND(tail, caps);
677 return head;
680 void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
681 Error **errp)
683 MigrationState *s = migrate_get_current();
684 MigrationCapabilityStatusList *cap;
685 bool new_caps[MIGRATION_CAPABILITY__MAX];
687 if (migration_is_running(s->state) || migration_in_colo_state()) {
688 error_setg(errp, QERR_MIGRATION_ACTIVE);
689 return;
692 memcpy(new_caps, s->capabilities, sizeof(new_caps));
693 for (cap = params; cap; cap = cap->next) {
694 new_caps[cap->value->capability] = cap->value->state;
697 if (!migrate_caps_check(s->capabilities, new_caps, errp)) {
698 return;
701 for (cap = params; cap; cap = cap->next) {
702 s->capabilities[cap->value->capability] = cap->value->state;
706 /* parameters */
708 const BitmapMigrationNodeAliasList *migrate_block_bitmap_mapping(void)
710 MigrationState *s = migrate_get_current();
712 return s->parameters.block_bitmap_mapping;
715 bool migrate_has_block_bitmap_mapping(void)
717 MigrationState *s = migrate_get_current();
719 return s->parameters.has_block_bitmap_mapping;
722 bool migrate_block_incremental(void)
724 MigrationState *s = migrate_get_current();
726 return s->parameters.block_incremental;
729 uint32_t migrate_checkpoint_delay(void)
731 MigrationState *s = migrate_get_current();
733 return s->parameters.x_checkpoint_delay;
736 int migrate_compress_level(void)
738 MigrationState *s = migrate_get_current();
740 return s->parameters.compress_level;
743 int migrate_compress_threads(void)
745 MigrationState *s = migrate_get_current();
747 return s->parameters.compress_threads;
750 int migrate_compress_wait_thread(void)
752 MigrationState *s = migrate_get_current();
754 return s->parameters.compress_wait_thread;
757 uint8_t migrate_cpu_throttle_increment(void)
759 MigrationState *s = migrate_get_current();
761 return s->parameters.cpu_throttle_increment;
764 uint8_t migrate_cpu_throttle_initial(void)
766 MigrationState *s = migrate_get_current();
768 return s->parameters.cpu_throttle_initial;
771 bool migrate_cpu_throttle_tailslow(void)
773 MigrationState *s = migrate_get_current();
775 return s->parameters.cpu_throttle_tailslow;
778 int migrate_decompress_threads(void)
780 MigrationState *s = migrate_get_current();
782 return s->parameters.decompress_threads;
785 uint64_t migrate_downtime_limit(void)
787 MigrationState *s = migrate_get_current();
789 return s->parameters.downtime_limit;
792 uint8_t migrate_max_cpu_throttle(void)
794 MigrationState *s = migrate_get_current();
796 return s->parameters.max_cpu_throttle;
799 uint64_t migrate_max_bandwidth(void)
801 MigrationState *s = migrate_get_current();
803 return s->parameters.max_bandwidth;
806 uint64_t migrate_avail_switchover_bandwidth(void)
808 MigrationState *s = migrate_get_current();
810 return s->parameters.avail_switchover_bandwidth;
813 uint64_t migrate_max_postcopy_bandwidth(void)
815 MigrationState *s = migrate_get_current();
817 return s->parameters.max_postcopy_bandwidth;
820 int migrate_multifd_channels(void)
822 MigrationState *s = migrate_get_current();
824 return s->parameters.multifd_channels;
827 MultiFDCompression migrate_multifd_compression(void)
829 MigrationState *s = migrate_get_current();
831 assert(s->parameters.multifd_compression < MULTIFD_COMPRESSION__MAX);
832 return s->parameters.multifd_compression;
835 int migrate_multifd_zlib_level(void)
837 MigrationState *s = migrate_get_current();
839 return s->parameters.multifd_zlib_level;
842 int migrate_multifd_zstd_level(void)
844 MigrationState *s = migrate_get_current();
846 return s->parameters.multifd_zstd_level;
849 uint8_t migrate_throttle_trigger_threshold(void)
851 MigrationState *s = migrate_get_current();
853 return s->parameters.throttle_trigger_threshold;
856 const char *migrate_tls_authz(void)
858 MigrationState *s = migrate_get_current();
860 return s->parameters.tls_authz;
863 const char *migrate_tls_creds(void)
865 MigrationState *s = migrate_get_current();
867 return s->parameters.tls_creds;
870 const char *migrate_tls_hostname(void)
872 MigrationState *s = migrate_get_current();
874 return s->parameters.tls_hostname;
877 uint64_t migrate_xbzrle_cache_size(void)
879 MigrationState *s = migrate_get_current();
881 return s->parameters.xbzrle_cache_size;
884 /* parameter setters */
886 void migrate_set_block_incremental(bool value)
888 MigrationState *s = migrate_get_current();
890 s->parameters.block_incremental = value;
893 /* parameters helpers */
895 void block_cleanup_parameters(void)
897 MigrationState *s = migrate_get_current();
899 if (s->must_remove_block_options) {
900 /* setting to false can never fail */
901 migrate_cap_set(MIGRATION_CAPABILITY_BLOCK, false, &error_abort);
902 migrate_set_block_incremental(false);
903 s->must_remove_block_options = false;
907 AnnounceParameters *migrate_announce_params(void)
909 static AnnounceParameters ap;
911 MigrationState *s = migrate_get_current();
913 ap.initial = s->parameters.announce_initial;
914 ap.max = s->parameters.announce_max;
915 ap.rounds = s->parameters.announce_rounds;
916 ap.step = s->parameters.announce_step;
918 return &ap;
921 MigrationParameters *qmp_query_migrate_parameters(Error **errp)
923 MigrationParameters *params;
924 MigrationState *s = migrate_get_current();
926 /* TODO use QAPI_CLONE() instead of duplicating it inline */
927 params = g_malloc0(sizeof(*params));
928 params->has_compress_level = true;
929 params->compress_level = s->parameters.compress_level;
930 params->has_compress_threads = true;
931 params->compress_threads = s->parameters.compress_threads;
932 params->has_compress_wait_thread = true;
933 params->compress_wait_thread = s->parameters.compress_wait_thread;
934 params->has_decompress_threads = true;
935 params->decompress_threads = s->parameters.decompress_threads;
936 params->has_throttle_trigger_threshold = true;
937 params->throttle_trigger_threshold = s->parameters.throttle_trigger_threshold;
938 params->has_cpu_throttle_initial = true;
939 params->cpu_throttle_initial = s->parameters.cpu_throttle_initial;
940 params->has_cpu_throttle_increment = true;
941 params->cpu_throttle_increment = s->parameters.cpu_throttle_increment;
942 params->has_cpu_throttle_tailslow = true;
943 params->cpu_throttle_tailslow = s->parameters.cpu_throttle_tailslow;
944 params->tls_creds = g_strdup(s->parameters.tls_creds);
945 params->tls_hostname = g_strdup(s->parameters.tls_hostname);
946 params->tls_authz = g_strdup(s->parameters.tls_authz ?
947 s->parameters.tls_authz : "");
948 params->has_max_bandwidth = true;
949 params->max_bandwidth = s->parameters.max_bandwidth;
950 params->has_avail_switchover_bandwidth = true;
951 params->avail_switchover_bandwidth = s->parameters.avail_switchover_bandwidth;
952 params->has_downtime_limit = true;
953 params->downtime_limit = s->parameters.downtime_limit;
954 params->has_x_checkpoint_delay = true;
955 params->x_checkpoint_delay = s->parameters.x_checkpoint_delay;
956 params->has_block_incremental = true;
957 params->block_incremental = s->parameters.block_incremental;
958 params->has_multifd_channels = true;
959 params->multifd_channels = s->parameters.multifd_channels;
960 params->has_multifd_compression = true;
961 params->multifd_compression = s->parameters.multifd_compression;
962 params->has_multifd_zlib_level = true;
963 params->multifd_zlib_level = s->parameters.multifd_zlib_level;
964 params->has_multifd_zstd_level = true;
965 params->multifd_zstd_level = s->parameters.multifd_zstd_level;
966 params->has_xbzrle_cache_size = true;
967 params->xbzrle_cache_size = s->parameters.xbzrle_cache_size;
968 params->has_max_postcopy_bandwidth = true;
969 params->max_postcopy_bandwidth = s->parameters.max_postcopy_bandwidth;
970 params->has_max_cpu_throttle = true;
971 params->max_cpu_throttle = s->parameters.max_cpu_throttle;
972 params->has_announce_initial = true;
973 params->announce_initial = s->parameters.announce_initial;
974 params->has_announce_max = true;
975 params->announce_max = s->parameters.announce_max;
976 params->has_announce_rounds = true;
977 params->announce_rounds = s->parameters.announce_rounds;
978 params->has_announce_step = true;
979 params->announce_step = s->parameters.announce_step;
981 if (s->parameters.has_block_bitmap_mapping) {
982 params->has_block_bitmap_mapping = true;
983 params->block_bitmap_mapping =
984 QAPI_CLONE(BitmapMigrationNodeAliasList,
985 s->parameters.block_bitmap_mapping);
988 params->has_x_vcpu_dirty_limit_period = true;
989 params->x_vcpu_dirty_limit_period = s->parameters.x_vcpu_dirty_limit_period;
990 params->has_vcpu_dirty_limit = true;
991 params->vcpu_dirty_limit = s->parameters.vcpu_dirty_limit;
993 return params;
996 void migrate_params_init(MigrationParameters *params)
998 params->tls_hostname = g_strdup("");
999 params->tls_creds = g_strdup("");
1001 /* Set has_* up only for parameter checks */
1002 params->has_compress_level = true;
1003 params->has_compress_threads = true;
1004 params->has_compress_wait_thread = true;
1005 params->has_decompress_threads = true;
1006 params->has_throttle_trigger_threshold = true;
1007 params->has_cpu_throttle_initial = true;
1008 params->has_cpu_throttle_increment = true;
1009 params->has_cpu_throttle_tailslow = true;
1010 params->has_max_bandwidth = true;
1011 params->has_downtime_limit = true;
1012 params->has_x_checkpoint_delay = true;
1013 params->has_block_incremental = true;
1014 params->has_multifd_channels = true;
1015 params->has_multifd_compression = true;
1016 params->has_multifd_zlib_level = true;
1017 params->has_multifd_zstd_level = true;
1018 params->has_xbzrle_cache_size = true;
1019 params->has_max_postcopy_bandwidth = true;
1020 params->has_max_cpu_throttle = true;
1021 params->has_announce_initial = true;
1022 params->has_announce_max = true;
1023 params->has_announce_rounds = true;
1024 params->has_announce_step = true;
1025 params->has_x_vcpu_dirty_limit_period = true;
1026 params->has_vcpu_dirty_limit = true;
1030 * Check whether the parameters are valid. Error will be put into errp
1031 * (if provided). Return true if valid, otherwise false.
1033 bool migrate_params_check(MigrationParameters *params, Error **errp)
1035 if (params->has_compress_level &&
1036 (params->compress_level > 9)) {
1037 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level",
1038 "a value between 0 and 9");
1039 return false;
1042 if (params->has_compress_threads && (params->compress_threads < 1)) {
1043 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1044 "compress_threads",
1045 "a value between 1 and 255");
1046 return false;
1049 if (params->has_decompress_threads && (params->decompress_threads < 1)) {
1050 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1051 "decompress_threads",
1052 "a value between 1 and 255");
1053 return false;
1056 if (params->has_throttle_trigger_threshold &&
1057 (params->throttle_trigger_threshold < 1 ||
1058 params->throttle_trigger_threshold > 100)) {
1059 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1060 "throttle_trigger_threshold",
1061 "an integer in the range of 1 to 100");
1062 return false;
1065 if (params->has_cpu_throttle_initial &&
1066 (params->cpu_throttle_initial < 1 ||
1067 params->cpu_throttle_initial > 99)) {
1068 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1069 "cpu_throttle_initial",
1070 "an integer in the range of 1 to 99");
1071 return false;
1074 if (params->has_cpu_throttle_increment &&
1075 (params->cpu_throttle_increment < 1 ||
1076 params->cpu_throttle_increment > 99)) {
1077 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1078 "cpu_throttle_increment",
1079 "an integer in the range of 1 to 99");
1080 return false;
1083 if (params->has_max_bandwidth && (params->max_bandwidth > SIZE_MAX)) {
1084 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1085 "max_bandwidth",
1086 "an integer in the range of 0 to "stringify(SIZE_MAX)
1087 " bytes/second");
1088 return false;
1091 if (params->has_avail_switchover_bandwidth &&
1092 (params->avail_switchover_bandwidth > SIZE_MAX)) {
1093 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1094 "avail_switchover_bandwidth",
1095 "an integer in the range of 0 to "stringify(SIZE_MAX)
1096 " bytes/second");
1097 return false;
1100 if (params->has_downtime_limit &&
1101 (params->downtime_limit > MAX_MIGRATE_DOWNTIME)) {
1102 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1103 "downtime_limit",
1104 "an integer in the range of 0 to "
1105 stringify(MAX_MIGRATE_DOWNTIME)" ms");
1106 return false;
1109 /* x_checkpoint_delay is now always positive */
1111 if (params->has_multifd_channels && (params->multifd_channels < 1)) {
1112 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1113 "multifd_channels",
1114 "a value between 1 and 255");
1115 return false;
1118 if (params->has_multifd_zlib_level &&
1119 (params->multifd_zlib_level > 9)) {
1120 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "multifd_zlib_level",
1121 "a value between 0 and 9");
1122 return false;
1125 if (params->has_multifd_zstd_level &&
1126 (params->multifd_zstd_level > 20)) {
1127 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "multifd_zstd_level",
1128 "a value between 0 and 20");
1129 return false;
1132 if (params->has_xbzrle_cache_size &&
1133 (params->xbzrle_cache_size < qemu_target_page_size() ||
1134 !is_power_of_2(params->xbzrle_cache_size))) {
1135 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1136 "xbzrle_cache_size",
1137 "a power of two no less than the target page size");
1138 return false;
1141 if (params->has_max_cpu_throttle &&
1142 (params->max_cpu_throttle < params->cpu_throttle_initial ||
1143 params->max_cpu_throttle > 99)) {
1144 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1145 "max_cpu_throttle",
1146 "an integer in the range of cpu_throttle_initial to 99");
1147 return false;
1150 if (params->has_announce_initial &&
1151 params->announce_initial > 100000) {
1152 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1153 "announce_initial",
1154 "a value between 0 and 100000");
1155 return false;
1157 if (params->has_announce_max &&
1158 params->announce_max > 100000) {
1159 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1160 "announce_max",
1161 "a value between 0 and 100000");
1162 return false;
1164 if (params->has_announce_rounds &&
1165 params->announce_rounds > 1000) {
1166 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1167 "announce_rounds",
1168 "a value between 0 and 1000");
1169 return false;
1171 if (params->has_announce_step &&
1172 (params->announce_step < 1 ||
1173 params->announce_step > 10000)) {
1174 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1175 "announce_step",
1176 "a value between 0 and 10000");
1177 return false;
1180 if (params->has_block_bitmap_mapping &&
1181 !check_dirty_bitmap_mig_alias_map(params->block_bitmap_mapping, errp)) {
1182 error_prepend(errp, "Invalid mapping given for block-bitmap-mapping: ");
1183 return false;
1186 #ifdef CONFIG_LINUX
1187 if (migrate_zero_copy_send() &&
1188 ((params->has_multifd_compression && params->multifd_compression) ||
1189 (params->tls_creds && *params->tls_creds))) {
1190 error_setg(errp,
1191 "Zero copy only available for non-compressed non-TLS multifd migration");
1192 return false;
1194 #endif
1196 if (params->has_x_vcpu_dirty_limit_period &&
1197 (params->x_vcpu_dirty_limit_period < 1 ||
1198 params->x_vcpu_dirty_limit_period > 1000)) {
1199 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1200 "x-vcpu-dirty-limit-period",
1201 "a value between 1 and 1000");
1202 return false;
1205 if (params->has_vcpu_dirty_limit &&
1206 (params->vcpu_dirty_limit < 1)) {
1207 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1208 "vcpu_dirty_limit",
1209 "is invalid, it must greater then 1 MB/s");
1210 return false;
1213 return true;
1216 static void migrate_params_test_apply(MigrateSetParameters *params,
1217 MigrationParameters *dest)
1219 *dest = migrate_get_current()->parameters;
1221 /* TODO use QAPI_CLONE() instead of duplicating it inline */
1223 if (params->has_compress_level) {
1224 dest->compress_level = params->compress_level;
1227 if (params->has_compress_threads) {
1228 dest->compress_threads = params->compress_threads;
1231 if (params->has_compress_wait_thread) {
1232 dest->compress_wait_thread = params->compress_wait_thread;
1235 if (params->has_decompress_threads) {
1236 dest->decompress_threads = params->decompress_threads;
1239 if (params->has_throttle_trigger_threshold) {
1240 dest->throttle_trigger_threshold = params->throttle_trigger_threshold;
1243 if (params->has_cpu_throttle_initial) {
1244 dest->cpu_throttle_initial = params->cpu_throttle_initial;
1247 if (params->has_cpu_throttle_increment) {
1248 dest->cpu_throttle_increment = params->cpu_throttle_increment;
1251 if (params->has_cpu_throttle_tailslow) {
1252 dest->cpu_throttle_tailslow = params->cpu_throttle_tailslow;
1255 if (params->tls_creds) {
1256 assert(params->tls_creds->type == QTYPE_QSTRING);
1257 dest->tls_creds = params->tls_creds->u.s;
1260 if (params->tls_hostname) {
1261 assert(params->tls_hostname->type == QTYPE_QSTRING);
1262 dest->tls_hostname = params->tls_hostname->u.s;
1265 if (params->has_max_bandwidth) {
1266 dest->max_bandwidth = params->max_bandwidth;
1269 if (params->has_avail_switchover_bandwidth) {
1270 dest->avail_switchover_bandwidth = params->avail_switchover_bandwidth;
1273 if (params->has_downtime_limit) {
1274 dest->downtime_limit = params->downtime_limit;
1277 if (params->has_x_checkpoint_delay) {
1278 dest->x_checkpoint_delay = params->x_checkpoint_delay;
1281 if (params->has_block_incremental) {
1282 dest->block_incremental = params->block_incremental;
1284 if (params->has_multifd_channels) {
1285 dest->multifd_channels = params->multifd_channels;
1287 if (params->has_multifd_compression) {
1288 dest->multifd_compression = params->multifd_compression;
1290 if (params->has_xbzrle_cache_size) {
1291 dest->xbzrle_cache_size = params->xbzrle_cache_size;
1293 if (params->has_max_postcopy_bandwidth) {
1294 dest->max_postcopy_bandwidth = params->max_postcopy_bandwidth;
1296 if (params->has_max_cpu_throttle) {
1297 dest->max_cpu_throttle = params->max_cpu_throttle;
1299 if (params->has_announce_initial) {
1300 dest->announce_initial = params->announce_initial;
1302 if (params->has_announce_max) {
1303 dest->announce_max = params->announce_max;
1305 if (params->has_announce_rounds) {
1306 dest->announce_rounds = params->announce_rounds;
1308 if (params->has_announce_step) {
1309 dest->announce_step = params->announce_step;
1312 if (params->has_block_bitmap_mapping) {
1313 dest->has_block_bitmap_mapping = true;
1314 dest->block_bitmap_mapping = params->block_bitmap_mapping;
1317 if (params->has_x_vcpu_dirty_limit_period) {
1318 dest->x_vcpu_dirty_limit_period =
1319 params->x_vcpu_dirty_limit_period;
1321 if (params->has_vcpu_dirty_limit) {
1322 dest->vcpu_dirty_limit = params->vcpu_dirty_limit;
1326 static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
1328 MigrationState *s = migrate_get_current();
1330 /* TODO use QAPI_CLONE() instead of duplicating it inline */
1332 if (params->has_compress_level) {
1333 s->parameters.compress_level = params->compress_level;
1336 if (params->has_compress_threads) {
1337 s->parameters.compress_threads = params->compress_threads;
1340 if (params->has_compress_wait_thread) {
1341 s->parameters.compress_wait_thread = params->compress_wait_thread;
1344 if (params->has_decompress_threads) {
1345 s->parameters.decompress_threads = params->decompress_threads;
1348 if (params->has_throttle_trigger_threshold) {
1349 s->parameters.throttle_trigger_threshold = params->throttle_trigger_threshold;
1352 if (params->has_cpu_throttle_initial) {
1353 s->parameters.cpu_throttle_initial = params->cpu_throttle_initial;
1356 if (params->has_cpu_throttle_increment) {
1357 s->parameters.cpu_throttle_increment = params->cpu_throttle_increment;
1360 if (params->has_cpu_throttle_tailslow) {
1361 s->parameters.cpu_throttle_tailslow = params->cpu_throttle_tailslow;
1364 if (params->tls_creds) {
1365 g_free(s->parameters.tls_creds);
1366 assert(params->tls_creds->type == QTYPE_QSTRING);
1367 s->parameters.tls_creds = g_strdup(params->tls_creds->u.s);
1370 if (params->tls_hostname) {
1371 g_free(s->parameters.tls_hostname);
1372 assert(params->tls_hostname->type == QTYPE_QSTRING);
1373 s->parameters.tls_hostname = g_strdup(params->tls_hostname->u.s);
1376 if (params->tls_authz) {
1377 g_free(s->parameters.tls_authz);
1378 assert(params->tls_authz->type == QTYPE_QSTRING);
1379 s->parameters.tls_authz = g_strdup(params->tls_authz->u.s);
1382 if (params->has_max_bandwidth) {
1383 s->parameters.max_bandwidth = params->max_bandwidth;
1384 if (s->to_dst_file && !migration_in_postcopy()) {
1385 migration_rate_set(s->parameters.max_bandwidth);
1389 if (params->has_avail_switchover_bandwidth) {
1390 s->parameters.avail_switchover_bandwidth = params->avail_switchover_bandwidth;
1393 if (params->has_downtime_limit) {
1394 s->parameters.downtime_limit = params->downtime_limit;
1397 if (params->has_x_checkpoint_delay) {
1398 s->parameters.x_checkpoint_delay = params->x_checkpoint_delay;
1399 colo_checkpoint_delay_set();
1402 if (params->has_block_incremental) {
1403 s->parameters.block_incremental = params->block_incremental;
1405 if (params->has_multifd_channels) {
1406 s->parameters.multifd_channels = params->multifd_channels;
1408 if (params->has_multifd_compression) {
1409 s->parameters.multifd_compression = params->multifd_compression;
1411 if (params->has_xbzrle_cache_size) {
1412 s->parameters.xbzrle_cache_size = params->xbzrle_cache_size;
1413 xbzrle_cache_resize(params->xbzrle_cache_size, errp);
1415 if (params->has_max_postcopy_bandwidth) {
1416 s->parameters.max_postcopy_bandwidth = params->max_postcopy_bandwidth;
1417 if (s->to_dst_file && migration_in_postcopy()) {
1418 migration_rate_set(s->parameters.max_postcopy_bandwidth);
1421 if (params->has_max_cpu_throttle) {
1422 s->parameters.max_cpu_throttle = params->max_cpu_throttle;
1424 if (params->has_announce_initial) {
1425 s->parameters.announce_initial = params->announce_initial;
1427 if (params->has_announce_max) {
1428 s->parameters.announce_max = params->announce_max;
1430 if (params->has_announce_rounds) {
1431 s->parameters.announce_rounds = params->announce_rounds;
1433 if (params->has_announce_step) {
1434 s->parameters.announce_step = params->announce_step;
1437 if (params->has_block_bitmap_mapping) {
1438 qapi_free_BitmapMigrationNodeAliasList(
1439 s->parameters.block_bitmap_mapping);
1441 s->parameters.has_block_bitmap_mapping = true;
1442 s->parameters.block_bitmap_mapping =
1443 QAPI_CLONE(BitmapMigrationNodeAliasList,
1444 params->block_bitmap_mapping);
1447 if (params->has_x_vcpu_dirty_limit_period) {
1448 s->parameters.x_vcpu_dirty_limit_period =
1449 params->x_vcpu_dirty_limit_period;
1451 if (params->has_vcpu_dirty_limit) {
1452 s->parameters.vcpu_dirty_limit = params->vcpu_dirty_limit;
1456 void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp)
1458 MigrationParameters tmp;
1460 /* TODO Rewrite "" to null instead for all three tls_* parameters */
1461 if (params->tls_creds
1462 && params->tls_creds->type == QTYPE_QNULL) {
1463 qobject_unref(params->tls_creds->u.n);
1464 params->tls_creds->type = QTYPE_QSTRING;
1465 params->tls_creds->u.s = strdup("");
1467 if (params->tls_hostname
1468 && params->tls_hostname->type == QTYPE_QNULL) {
1469 qobject_unref(params->tls_hostname->u.n);
1470 params->tls_hostname->type = QTYPE_QSTRING;
1471 params->tls_hostname->u.s = strdup("");
1473 if (params->tls_authz
1474 && params->tls_authz->type == QTYPE_QNULL) {
1475 qobject_unref(params->tls_authz->u.n);
1476 params->tls_authz->type = QTYPE_QSTRING;
1477 params->tls_authz->u.s = strdup("");
1480 migrate_params_test_apply(params, &tmp);
1482 if (!migrate_params_check(&tmp, errp)) {
1483 /* Invalid parameter */
1484 return;
1487 migrate_params_apply(params, errp);