qapi: Belatedly update CompatPolicy documentation for unstable
[qemu/kevin.git] / migration / options.c
blob42fb8189563073ea5a8d6389547081539dd420f0
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 return true;
624 bool migrate_cap_set(int cap, bool value, Error **errp)
626 MigrationState *s = migrate_get_current();
627 bool new_caps[MIGRATION_CAPABILITY__MAX];
629 if (migration_is_running(s->state)) {
630 error_setg(errp, QERR_MIGRATION_ACTIVE);
631 return false;
634 memcpy(new_caps, s->capabilities, sizeof(new_caps));
635 new_caps[cap] = value;
637 if (!migrate_caps_check(s->capabilities, new_caps, errp)) {
638 return false;
640 s->capabilities[cap] = value;
641 return true;
644 MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp)
646 MigrationCapabilityStatusList *head = NULL, **tail = &head;
647 MigrationCapabilityStatus *caps;
648 MigrationState *s = migrate_get_current();
649 int i;
651 for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
652 #ifndef CONFIG_LIVE_BLOCK_MIGRATION
653 if (i == MIGRATION_CAPABILITY_BLOCK) {
654 continue;
656 #endif
657 caps = g_malloc0(sizeof(*caps));
658 caps->capability = i;
659 caps->state = s->capabilities[i];
660 QAPI_LIST_APPEND(tail, caps);
663 return head;
666 void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
667 Error **errp)
669 MigrationState *s = migrate_get_current();
670 MigrationCapabilityStatusList *cap;
671 bool new_caps[MIGRATION_CAPABILITY__MAX];
673 if (migration_is_running(s->state) || migration_in_colo_state()) {
674 error_setg(errp, QERR_MIGRATION_ACTIVE);
675 return;
678 memcpy(new_caps, s->capabilities, sizeof(new_caps));
679 for (cap = params; cap; cap = cap->next) {
680 new_caps[cap->value->capability] = cap->value->state;
683 if (!migrate_caps_check(s->capabilities, new_caps, errp)) {
684 return;
687 for (cap = params; cap; cap = cap->next) {
688 s->capabilities[cap->value->capability] = cap->value->state;
692 /* parameters */
694 const BitmapMigrationNodeAliasList *migrate_block_bitmap_mapping(void)
696 MigrationState *s = migrate_get_current();
698 return s->parameters.block_bitmap_mapping;
701 bool migrate_has_block_bitmap_mapping(void)
703 MigrationState *s = migrate_get_current();
705 return s->parameters.has_block_bitmap_mapping;
708 bool migrate_block_incremental(void)
710 MigrationState *s = migrate_get_current();
712 return s->parameters.block_incremental;
715 uint32_t migrate_checkpoint_delay(void)
717 MigrationState *s = migrate_get_current();
719 return s->parameters.x_checkpoint_delay;
722 int migrate_compress_level(void)
724 MigrationState *s = migrate_get_current();
726 return s->parameters.compress_level;
729 int migrate_compress_threads(void)
731 MigrationState *s = migrate_get_current();
733 return s->parameters.compress_threads;
736 int migrate_compress_wait_thread(void)
738 MigrationState *s = migrate_get_current();
740 return s->parameters.compress_wait_thread;
743 uint8_t migrate_cpu_throttle_increment(void)
745 MigrationState *s = migrate_get_current();
747 return s->parameters.cpu_throttle_increment;
750 uint8_t migrate_cpu_throttle_initial(void)
752 MigrationState *s = migrate_get_current();
754 return s->parameters.cpu_throttle_initial;
757 bool migrate_cpu_throttle_tailslow(void)
759 MigrationState *s = migrate_get_current();
761 return s->parameters.cpu_throttle_tailslow;
764 int migrate_decompress_threads(void)
766 MigrationState *s = migrate_get_current();
768 return s->parameters.decompress_threads;
771 uint64_t migrate_downtime_limit(void)
773 MigrationState *s = migrate_get_current();
775 return s->parameters.downtime_limit;
778 uint8_t migrate_max_cpu_throttle(void)
780 MigrationState *s = migrate_get_current();
782 return s->parameters.max_cpu_throttle;
785 uint64_t migrate_max_bandwidth(void)
787 MigrationState *s = migrate_get_current();
789 return s->parameters.max_bandwidth;
792 uint64_t migrate_avail_switchover_bandwidth(void)
794 MigrationState *s = migrate_get_current();
796 return s->parameters.avail_switchover_bandwidth;
799 uint64_t migrate_max_postcopy_bandwidth(void)
801 MigrationState *s = migrate_get_current();
803 return s->parameters.max_postcopy_bandwidth;
806 int migrate_multifd_channels(void)
808 MigrationState *s = migrate_get_current();
810 return s->parameters.multifd_channels;
813 MultiFDCompression migrate_multifd_compression(void)
815 MigrationState *s = migrate_get_current();
817 assert(s->parameters.multifd_compression < MULTIFD_COMPRESSION__MAX);
818 return s->parameters.multifd_compression;
821 int migrate_multifd_zlib_level(void)
823 MigrationState *s = migrate_get_current();
825 return s->parameters.multifd_zlib_level;
828 int migrate_multifd_zstd_level(void)
830 MigrationState *s = migrate_get_current();
832 return s->parameters.multifd_zstd_level;
835 uint8_t migrate_throttle_trigger_threshold(void)
837 MigrationState *s = migrate_get_current();
839 return s->parameters.throttle_trigger_threshold;
842 const char *migrate_tls_authz(void)
844 MigrationState *s = migrate_get_current();
846 return s->parameters.tls_authz;
849 const char *migrate_tls_creds(void)
851 MigrationState *s = migrate_get_current();
853 return s->parameters.tls_creds;
856 const char *migrate_tls_hostname(void)
858 MigrationState *s = migrate_get_current();
860 return s->parameters.tls_hostname;
863 uint64_t migrate_xbzrle_cache_size(void)
865 MigrationState *s = migrate_get_current();
867 return s->parameters.xbzrle_cache_size;
870 /* parameter setters */
872 void migrate_set_block_incremental(bool value)
874 MigrationState *s = migrate_get_current();
876 s->parameters.block_incremental = value;
879 /* parameters helpers */
881 void block_cleanup_parameters(void)
883 MigrationState *s = migrate_get_current();
885 if (s->must_remove_block_options) {
886 /* setting to false can never fail */
887 migrate_cap_set(MIGRATION_CAPABILITY_BLOCK, false, &error_abort);
888 migrate_set_block_incremental(false);
889 s->must_remove_block_options = false;
893 AnnounceParameters *migrate_announce_params(void)
895 static AnnounceParameters ap;
897 MigrationState *s = migrate_get_current();
899 ap.initial = s->parameters.announce_initial;
900 ap.max = s->parameters.announce_max;
901 ap.rounds = s->parameters.announce_rounds;
902 ap.step = s->parameters.announce_step;
904 return &ap;
907 MigrationParameters *qmp_query_migrate_parameters(Error **errp)
909 MigrationParameters *params;
910 MigrationState *s = migrate_get_current();
912 /* TODO use QAPI_CLONE() instead of duplicating it inline */
913 params = g_malloc0(sizeof(*params));
914 params->has_compress_level = true;
915 params->compress_level = s->parameters.compress_level;
916 params->has_compress_threads = true;
917 params->compress_threads = s->parameters.compress_threads;
918 params->has_compress_wait_thread = true;
919 params->compress_wait_thread = s->parameters.compress_wait_thread;
920 params->has_decompress_threads = true;
921 params->decompress_threads = s->parameters.decompress_threads;
922 params->has_throttle_trigger_threshold = true;
923 params->throttle_trigger_threshold = s->parameters.throttle_trigger_threshold;
924 params->has_cpu_throttle_initial = true;
925 params->cpu_throttle_initial = s->parameters.cpu_throttle_initial;
926 params->has_cpu_throttle_increment = true;
927 params->cpu_throttle_increment = s->parameters.cpu_throttle_increment;
928 params->has_cpu_throttle_tailslow = true;
929 params->cpu_throttle_tailslow = s->parameters.cpu_throttle_tailslow;
930 params->tls_creds = g_strdup(s->parameters.tls_creds);
931 params->tls_hostname = g_strdup(s->parameters.tls_hostname);
932 params->tls_authz = g_strdup(s->parameters.tls_authz ?
933 s->parameters.tls_authz : "");
934 params->has_max_bandwidth = true;
935 params->max_bandwidth = s->parameters.max_bandwidth;
936 params->has_avail_switchover_bandwidth = true;
937 params->avail_switchover_bandwidth = s->parameters.avail_switchover_bandwidth;
938 params->has_downtime_limit = true;
939 params->downtime_limit = s->parameters.downtime_limit;
940 params->has_x_checkpoint_delay = true;
941 params->x_checkpoint_delay = s->parameters.x_checkpoint_delay;
942 params->has_block_incremental = true;
943 params->block_incremental = s->parameters.block_incremental;
944 params->has_multifd_channels = true;
945 params->multifd_channels = s->parameters.multifd_channels;
946 params->has_multifd_compression = true;
947 params->multifd_compression = s->parameters.multifd_compression;
948 params->has_multifd_zlib_level = true;
949 params->multifd_zlib_level = s->parameters.multifd_zlib_level;
950 params->has_multifd_zstd_level = true;
951 params->multifd_zstd_level = s->parameters.multifd_zstd_level;
952 params->has_xbzrle_cache_size = true;
953 params->xbzrle_cache_size = s->parameters.xbzrle_cache_size;
954 params->has_max_postcopy_bandwidth = true;
955 params->max_postcopy_bandwidth = s->parameters.max_postcopy_bandwidth;
956 params->has_max_cpu_throttle = true;
957 params->max_cpu_throttle = s->parameters.max_cpu_throttle;
958 params->has_announce_initial = true;
959 params->announce_initial = s->parameters.announce_initial;
960 params->has_announce_max = true;
961 params->announce_max = s->parameters.announce_max;
962 params->has_announce_rounds = true;
963 params->announce_rounds = s->parameters.announce_rounds;
964 params->has_announce_step = true;
965 params->announce_step = s->parameters.announce_step;
967 if (s->parameters.has_block_bitmap_mapping) {
968 params->has_block_bitmap_mapping = true;
969 params->block_bitmap_mapping =
970 QAPI_CLONE(BitmapMigrationNodeAliasList,
971 s->parameters.block_bitmap_mapping);
974 params->has_x_vcpu_dirty_limit_period = true;
975 params->x_vcpu_dirty_limit_period = s->parameters.x_vcpu_dirty_limit_period;
976 params->has_vcpu_dirty_limit = true;
977 params->vcpu_dirty_limit = s->parameters.vcpu_dirty_limit;
979 return params;
982 void migrate_params_init(MigrationParameters *params)
984 params->tls_hostname = g_strdup("");
985 params->tls_creds = g_strdup("");
987 /* Set has_* up only for parameter checks */
988 params->has_compress_level = true;
989 params->has_compress_threads = true;
990 params->has_compress_wait_thread = true;
991 params->has_decompress_threads = true;
992 params->has_throttle_trigger_threshold = true;
993 params->has_cpu_throttle_initial = true;
994 params->has_cpu_throttle_increment = true;
995 params->has_cpu_throttle_tailslow = true;
996 params->has_max_bandwidth = true;
997 params->has_downtime_limit = true;
998 params->has_x_checkpoint_delay = true;
999 params->has_block_incremental = true;
1000 params->has_multifd_channels = true;
1001 params->has_multifd_compression = true;
1002 params->has_multifd_zlib_level = true;
1003 params->has_multifd_zstd_level = true;
1004 params->has_xbzrle_cache_size = true;
1005 params->has_max_postcopy_bandwidth = true;
1006 params->has_max_cpu_throttle = true;
1007 params->has_announce_initial = true;
1008 params->has_announce_max = true;
1009 params->has_announce_rounds = true;
1010 params->has_announce_step = true;
1011 params->has_x_vcpu_dirty_limit_period = true;
1012 params->has_vcpu_dirty_limit = true;
1016 * Check whether the parameters are valid. Error will be put into errp
1017 * (if provided). Return true if valid, otherwise false.
1019 bool migrate_params_check(MigrationParameters *params, Error **errp)
1021 if (params->has_compress_level &&
1022 (params->compress_level > 9)) {
1023 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level",
1024 "a value between 0 and 9");
1025 return false;
1028 if (params->has_compress_threads && (params->compress_threads < 1)) {
1029 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1030 "compress_threads",
1031 "a value between 1 and 255");
1032 return false;
1035 if (params->has_decompress_threads && (params->decompress_threads < 1)) {
1036 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1037 "decompress_threads",
1038 "a value between 1 and 255");
1039 return false;
1042 if (params->has_throttle_trigger_threshold &&
1043 (params->throttle_trigger_threshold < 1 ||
1044 params->throttle_trigger_threshold > 100)) {
1045 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1046 "throttle_trigger_threshold",
1047 "an integer in the range of 1 to 100");
1048 return false;
1051 if (params->has_cpu_throttle_initial &&
1052 (params->cpu_throttle_initial < 1 ||
1053 params->cpu_throttle_initial > 99)) {
1054 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1055 "cpu_throttle_initial",
1056 "an integer in the range of 1 to 99");
1057 return false;
1060 if (params->has_cpu_throttle_increment &&
1061 (params->cpu_throttle_increment < 1 ||
1062 params->cpu_throttle_increment > 99)) {
1063 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1064 "cpu_throttle_increment",
1065 "an integer in the range of 1 to 99");
1066 return false;
1069 if (params->has_max_bandwidth && (params->max_bandwidth > SIZE_MAX)) {
1070 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1071 "max_bandwidth",
1072 "an integer in the range of 0 to "stringify(SIZE_MAX)
1073 " bytes/second");
1074 return false;
1077 if (params->has_avail_switchover_bandwidth &&
1078 (params->avail_switchover_bandwidth > SIZE_MAX)) {
1079 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1080 "avail_switchover_bandwidth",
1081 "an integer in the range of 0 to "stringify(SIZE_MAX)
1082 " bytes/second");
1083 return false;
1086 if (params->has_downtime_limit &&
1087 (params->downtime_limit > MAX_MIGRATE_DOWNTIME)) {
1088 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1089 "downtime_limit",
1090 "an integer in the range of 0 to "
1091 stringify(MAX_MIGRATE_DOWNTIME)" ms");
1092 return false;
1095 /* x_checkpoint_delay is now always positive */
1097 if (params->has_multifd_channels && (params->multifd_channels < 1)) {
1098 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1099 "multifd_channels",
1100 "a value between 1 and 255");
1101 return false;
1104 if (params->has_multifd_zlib_level &&
1105 (params->multifd_zlib_level > 9)) {
1106 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "multifd_zlib_level",
1107 "a value between 0 and 9");
1108 return false;
1111 if (params->has_multifd_zstd_level &&
1112 (params->multifd_zstd_level > 20)) {
1113 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "multifd_zstd_level",
1114 "a value between 0 and 20");
1115 return false;
1118 if (params->has_xbzrle_cache_size &&
1119 (params->xbzrle_cache_size < qemu_target_page_size() ||
1120 !is_power_of_2(params->xbzrle_cache_size))) {
1121 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1122 "xbzrle_cache_size",
1123 "a power of two no less than the target page size");
1124 return false;
1127 if (params->has_max_cpu_throttle &&
1128 (params->max_cpu_throttle < params->cpu_throttle_initial ||
1129 params->max_cpu_throttle > 99)) {
1130 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1131 "max_cpu_throttle",
1132 "an integer in the range of cpu_throttle_initial to 99");
1133 return false;
1136 if (params->has_announce_initial &&
1137 params->announce_initial > 100000) {
1138 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1139 "announce_initial",
1140 "a value between 0 and 100000");
1141 return false;
1143 if (params->has_announce_max &&
1144 params->announce_max > 100000) {
1145 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1146 "announce_max",
1147 "a value between 0 and 100000");
1148 return false;
1150 if (params->has_announce_rounds &&
1151 params->announce_rounds > 1000) {
1152 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1153 "announce_rounds",
1154 "a value between 0 and 1000");
1155 return false;
1157 if (params->has_announce_step &&
1158 (params->announce_step < 1 ||
1159 params->announce_step > 10000)) {
1160 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1161 "announce_step",
1162 "a value between 0 and 10000");
1163 return false;
1166 if (params->has_block_bitmap_mapping &&
1167 !check_dirty_bitmap_mig_alias_map(params->block_bitmap_mapping, errp)) {
1168 error_prepend(errp, "Invalid mapping given for block-bitmap-mapping: ");
1169 return false;
1172 #ifdef CONFIG_LINUX
1173 if (migrate_zero_copy_send() &&
1174 ((params->has_multifd_compression && params->multifd_compression) ||
1175 (params->tls_creds && *params->tls_creds))) {
1176 error_setg(errp,
1177 "Zero copy only available for non-compressed non-TLS multifd migration");
1178 return false;
1180 #endif
1182 if (params->has_x_vcpu_dirty_limit_period &&
1183 (params->x_vcpu_dirty_limit_period < 1 ||
1184 params->x_vcpu_dirty_limit_period > 1000)) {
1185 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1186 "x-vcpu-dirty-limit-period",
1187 "a value between 1 and 1000");
1188 return false;
1191 if (params->has_vcpu_dirty_limit &&
1192 (params->vcpu_dirty_limit < 1)) {
1193 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
1194 "vcpu_dirty_limit",
1195 "is invalid, it must greater then 1 MB/s");
1196 return false;
1199 return true;
1202 static void migrate_params_test_apply(MigrateSetParameters *params,
1203 MigrationParameters *dest)
1205 *dest = migrate_get_current()->parameters;
1207 /* TODO use QAPI_CLONE() instead of duplicating it inline */
1209 if (params->has_compress_level) {
1210 dest->compress_level = params->compress_level;
1213 if (params->has_compress_threads) {
1214 dest->compress_threads = params->compress_threads;
1217 if (params->has_compress_wait_thread) {
1218 dest->compress_wait_thread = params->compress_wait_thread;
1221 if (params->has_decompress_threads) {
1222 dest->decompress_threads = params->decompress_threads;
1225 if (params->has_throttle_trigger_threshold) {
1226 dest->throttle_trigger_threshold = params->throttle_trigger_threshold;
1229 if (params->has_cpu_throttle_initial) {
1230 dest->cpu_throttle_initial = params->cpu_throttle_initial;
1233 if (params->has_cpu_throttle_increment) {
1234 dest->cpu_throttle_increment = params->cpu_throttle_increment;
1237 if (params->has_cpu_throttle_tailslow) {
1238 dest->cpu_throttle_tailslow = params->cpu_throttle_tailslow;
1241 if (params->tls_creds) {
1242 assert(params->tls_creds->type == QTYPE_QSTRING);
1243 dest->tls_creds = params->tls_creds->u.s;
1246 if (params->tls_hostname) {
1247 assert(params->tls_hostname->type == QTYPE_QSTRING);
1248 dest->tls_hostname = params->tls_hostname->u.s;
1251 if (params->has_max_bandwidth) {
1252 dest->max_bandwidth = params->max_bandwidth;
1255 if (params->has_avail_switchover_bandwidth) {
1256 dest->avail_switchover_bandwidth = params->avail_switchover_bandwidth;
1259 if (params->has_downtime_limit) {
1260 dest->downtime_limit = params->downtime_limit;
1263 if (params->has_x_checkpoint_delay) {
1264 dest->x_checkpoint_delay = params->x_checkpoint_delay;
1267 if (params->has_block_incremental) {
1268 dest->block_incremental = params->block_incremental;
1270 if (params->has_multifd_channels) {
1271 dest->multifd_channels = params->multifd_channels;
1273 if (params->has_multifd_compression) {
1274 dest->multifd_compression = params->multifd_compression;
1276 if (params->has_xbzrle_cache_size) {
1277 dest->xbzrle_cache_size = params->xbzrle_cache_size;
1279 if (params->has_max_postcopy_bandwidth) {
1280 dest->max_postcopy_bandwidth = params->max_postcopy_bandwidth;
1282 if (params->has_max_cpu_throttle) {
1283 dest->max_cpu_throttle = params->max_cpu_throttle;
1285 if (params->has_announce_initial) {
1286 dest->announce_initial = params->announce_initial;
1288 if (params->has_announce_max) {
1289 dest->announce_max = params->announce_max;
1291 if (params->has_announce_rounds) {
1292 dest->announce_rounds = params->announce_rounds;
1294 if (params->has_announce_step) {
1295 dest->announce_step = params->announce_step;
1298 if (params->has_block_bitmap_mapping) {
1299 dest->has_block_bitmap_mapping = true;
1300 dest->block_bitmap_mapping = params->block_bitmap_mapping;
1303 if (params->has_x_vcpu_dirty_limit_period) {
1304 dest->x_vcpu_dirty_limit_period =
1305 params->x_vcpu_dirty_limit_period;
1307 if (params->has_vcpu_dirty_limit) {
1308 dest->vcpu_dirty_limit = params->vcpu_dirty_limit;
1312 static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
1314 MigrationState *s = migrate_get_current();
1316 /* TODO use QAPI_CLONE() instead of duplicating it inline */
1318 if (params->has_compress_level) {
1319 s->parameters.compress_level = params->compress_level;
1322 if (params->has_compress_threads) {
1323 s->parameters.compress_threads = params->compress_threads;
1326 if (params->has_compress_wait_thread) {
1327 s->parameters.compress_wait_thread = params->compress_wait_thread;
1330 if (params->has_decompress_threads) {
1331 s->parameters.decompress_threads = params->decompress_threads;
1334 if (params->has_throttle_trigger_threshold) {
1335 s->parameters.throttle_trigger_threshold = params->throttle_trigger_threshold;
1338 if (params->has_cpu_throttle_initial) {
1339 s->parameters.cpu_throttle_initial = params->cpu_throttle_initial;
1342 if (params->has_cpu_throttle_increment) {
1343 s->parameters.cpu_throttle_increment = params->cpu_throttle_increment;
1346 if (params->has_cpu_throttle_tailslow) {
1347 s->parameters.cpu_throttle_tailslow = params->cpu_throttle_tailslow;
1350 if (params->tls_creds) {
1351 g_free(s->parameters.tls_creds);
1352 assert(params->tls_creds->type == QTYPE_QSTRING);
1353 s->parameters.tls_creds = g_strdup(params->tls_creds->u.s);
1356 if (params->tls_hostname) {
1357 g_free(s->parameters.tls_hostname);
1358 assert(params->tls_hostname->type == QTYPE_QSTRING);
1359 s->parameters.tls_hostname = g_strdup(params->tls_hostname->u.s);
1362 if (params->tls_authz) {
1363 g_free(s->parameters.tls_authz);
1364 assert(params->tls_authz->type == QTYPE_QSTRING);
1365 s->parameters.tls_authz = g_strdup(params->tls_authz->u.s);
1368 if (params->has_max_bandwidth) {
1369 s->parameters.max_bandwidth = params->max_bandwidth;
1370 if (s->to_dst_file && !migration_in_postcopy()) {
1371 migration_rate_set(s->parameters.max_bandwidth);
1375 if (params->has_avail_switchover_bandwidth) {
1376 s->parameters.avail_switchover_bandwidth = params->avail_switchover_bandwidth;
1379 if (params->has_downtime_limit) {
1380 s->parameters.downtime_limit = params->downtime_limit;
1383 if (params->has_x_checkpoint_delay) {
1384 s->parameters.x_checkpoint_delay = params->x_checkpoint_delay;
1385 colo_checkpoint_delay_set();
1388 if (params->has_block_incremental) {
1389 s->parameters.block_incremental = params->block_incremental;
1391 if (params->has_multifd_channels) {
1392 s->parameters.multifd_channels = params->multifd_channels;
1394 if (params->has_multifd_compression) {
1395 s->parameters.multifd_compression = params->multifd_compression;
1397 if (params->has_xbzrle_cache_size) {
1398 s->parameters.xbzrle_cache_size = params->xbzrle_cache_size;
1399 xbzrle_cache_resize(params->xbzrle_cache_size, errp);
1401 if (params->has_max_postcopy_bandwidth) {
1402 s->parameters.max_postcopy_bandwidth = params->max_postcopy_bandwidth;
1403 if (s->to_dst_file && migration_in_postcopy()) {
1404 migration_rate_set(s->parameters.max_postcopy_bandwidth);
1407 if (params->has_max_cpu_throttle) {
1408 s->parameters.max_cpu_throttle = params->max_cpu_throttle;
1410 if (params->has_announce_initial) {
1411 s->parameters.announce_initial = params->announce_initial;
1413 if (params->has_announce_max) {
1414 s->parameters.announce_max = params->announce_max;
1416 if (params->has_announce_rounds) {
1417 s->parameters.announce_rounds = params->announce_rounds;
1419 if (params->has_announce_step) {
1420 s->parameters.announce_step = params->announce_step;
1423 if (params->has_block_bitmap_mapping) {
1424 qapi_free_BitmapMigrationNodeAliasList(
1425 s->parameters.block_bitmap_mapping);
1427 s->parameters.has_block_bitmap_mapping = true;
1428 s->parameters.block_bitmap_mapping =
1429 QAPI_CLONE(BitmapMigrationNodeAliasList,
1430 params->block_bitmap_mapping);
1433 if (params->has_x_vcpu_dirty_limit_period) {
1434 s->parameters.x_vcpu_dirty_limit_period =
1435 params->x_vcpu_dirty_limit_period;
1437 if (params->has_vcpu_dirty_limit) {
1438 s->parameters.vcpu_dirty_limit = params->vcpu_dirty_limit;
1442 void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp)
1444 MigrationParameters tmp;
1446 /* TODO Rewrite "" to null instead for all three tls_* parameters */
1447 if (params->tls_creds
1448 && params->tls_creds->type == QTYPE_QNULL) {
1449 qobject_unref(params->tls_creds->u.n);
1450 params->tls_creds->type = QTYPE_QSTRING;
1451 params->tls_creds->u.s = strdup("");
1453 if (params->tls_hostname
1454 && params->tls_hostname->type == QTYPE_QNULL) {
1455 qobject_unref(params->tls_hostname->u.n);
1456 params->tls_hostname->type = QTYPE_QSTRING;
1457 params->tls_hostname->u.s = strdup("");
1459 if (params->tls_authz
1460 && params->tls_authz->type == QTYPE_QNULL) {
1461 qobject_unref(params->tls_authz->u.n);
1462 params->tls_authz->type = QTYPE_QSTRING;
1463 params->tls_authz->u.s = strdup("");
1466 migrate_params_test_apply(params, &tmp);
1468 if (!migrate_params_check(&tmp, errp)) {
1469 /* Invalid parameter */
1470 return;
1473 migrate_params_apply(params, errp);