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 "qemu-file.h"
30 /* Maximum migrate downtime set to 2000 seconds */
31 #define MAX_MIGRATE_DOWNTIME_SECONDS 2000
32 #define MAX_MIGRATE_DOWNTIME (MAX_MIGRATE_DOWNTIME_SECONDS * 1000)
34 bool migrate_auto_converge(void)
38 s
= migrate_get_current();
40 return s
->capabilities
[MIGRATION_CAPABILITY_AUTO_CONVERGE
];
43 bool migrate_background_snapshot(void)
47 s
= migrate_get_current();
49 return s
->capabilities
[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT
];
52 bool migrate_block(void)
56 s
= migrate_get_current();
58 return s
->capabilities
[MIGRATION_CAPABILITY_BLOCK
];
61 bool migrate_colo(void)
63 MigrationState
*s
= migrate_get_current();
64 return s
->capabilities
[MIGRATION_CAPABILITY_X_COLO
];
67 bool migrate_compress(void)
71 s
= migrate_get_current();
73 return s
->capabilities
[MIGRATION_CAPABILITY_COMPRESS
];
76 bool migrate_dirty_bitmaps(void)
80 s
= migrate_get_current();
82 return s
->capabilities
[MIGRATION_CAPABILITY_DIRTY_BITMAPS
];
85 bool migrate_events(void)
89 s
= migrate_get_current();
91 return s
->capabilities
[MIGRATION_CAPABILITY_EVENTS
];
94 bool migrate_ignore_shared(void)
98 s
= migrate_get_current();
100 return s
->capabilities
[MIGRATION_CAPABILITY_X_IGNORE_SHARED
];
103 bool migrate_late_block_activate(void)
107 s
= migrate_get_current();
109 return s
->capabilities
[MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE
];
112 bool migrate_multifd(void)
116 s
= migrate_get_current();
118 return s
->capabilities
[MIGRATION_CAPABILITY_MULTIFD
];
121 bool migrate_pause_before_switchover(void)
125 s
= migrate_get_current();
127 return s
->capabilities
[MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER
];
130 bool migrate_postcopy_blocktime(void)
134 s
= migrate_get_current();
136 return s
->capabilities
[MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME
];
139 bool migrate_postcopy_preempt(void)
143 s
= migrate_get_current();
145 return s
->capabilities
[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT
];
148 bool migrate_postcopy_ram(void)
152 s
= migrate_get_current();
154 return s
->capabilities
[MIGRATION_CAPABILITY_POSTCOPY_RAM
];
157 bool migrate_rdma_pin_all(void)
159 MigrationState
*s
= migrate_get_current();
161 return s
->capabilities
[MIGRATION_CAPABILITY_RDMA_PIN_ALL
];
164 bool migrate_release_ram(void)
168 s
= migrate_get_current();
170 return s
->capabilities
[MIGRATION_CAPABILITY_RELEASE_RAM
];
173 bool migrate_return_path(void)
177 s
= migrate_get_current();
179 return s
->capabilities
[MIGRATION_CAPABILITY_RETURN_PATH
];
182 bool migrate_validate_uuid(void)
186 s
= migrate_get_current();
188 return s
->capabilities
[MIGRATION_CAPABILITY_VALIDATE_UUID
];
191 bool migrate_xbzrle(void)
195 s
= migrate_get_current();
197 return s
->capabilities
[MIGRATION_CAPABILITY_XBZRLE
];
200 bool migrate_zero_blocks(void)
204 s
= migrate_get_current();
206 return s
->capabilities
[MIGRATION_CAPABILITY_ZERO_BLOCKS
];
209 bool migrate_zero_copy_send(void)
213 s
= migrate_get_current();
215 return s
->capabilities
[MIGRATION_CAPABILITY_ZERO_COPY_SEND
];
218 /* pseudo capabilities */
220 bool migrate_postcopy(void)
222 return migrate_postcopy_ram() || migrate_dirty_bitmaps();
225 bool migrate_tls(void)
229 s
= migrate_get_current();
231 return s
->parameters
.tls_creds
&& *s
->parameters
.tls_creds
;
234 typedef enum WriteTrackingSupport
{
235 WT_SUPPORT_UNKNOWN
= 0,
237 WT_SUPPORT_AVAILABLE
,
238 WT_SUPPORT_COMPATIBLE
239 } WriteTrackingSupport
;
242 WriteTrackingSupport
migrate_query_write_tracking(void)
244 /* Check if kernel supports required UFFD features */
245 if (!ram_write_tracking_available()) {
246 return WT_SUPPORT_ABSENT
;
249 * Check if current memory configuration is
250 * compatible with required UFFD features.
252 if (!ram_write_tracking_compatible()) {
253 return WT_SUPPORT_AVAILABLE
;
256 return WT_SUPPORT_COMPATIBLE
;
259 /* Migration capabilities set */
260 struct MigrateCapsSet
{
261 int size
; /* Capability set size */
262 MigrationCapability caps
[]; /* Variadic array of capabilities */
264 typedef struct MigrateCapsSet MigrateCapsSet
;
266 /* Define and initialize MigrateCapsSet */
267 #define INITIALIZE_MIGRATE_CAPS_SET(_name, ...) \
268 MigrateCapsSet _name = { \
269 .size = sizeof((int []) { __VA_ARGS__ }) / sizeof(int), \
270 .caps = { __VA_ARGS__ } \
273 /* Background-snapshot compatibility check list */
275 INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snapshot
,
276 MIGRATION_CAPABILITY_POSTCOPY_RAM
,
277 MIGRATION_CAPABILITY_DIRTY_BITMAPS
,
278 MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME
,
279 MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE
,
280 MIGRATION_CAPABILITY_RETURN_PATH
,
281 MIGRATION_CAPABILITY_MULTIFD
,
282 MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER
,
283 MIGRATION_CAPABILITY_AUTO_CONVERGE
,
284 MIGRATION_CAPABILITY_RELEASE_RAM
,
285 MIGRATION_CAPABILITY_RDMA_PIN_ALL
,
286 MIGRATION_CAPABILITY_COMPRESS
,
287 MIGRATION_CAPABILITY_XBZRLE
,
288 MIGRATION_CAPABILITY_X_COLO
,
289 MIGRATION_CAPABILITY_VALIDATE_UUID
,
290 MIGRATION_CAPABILITY_ZERO_COPY_SEND
);
293 * @migration_caps_check - check capability compatibility
295 * @old_caps: old capability list
296 * @new_caps: new capability list
297 * @errp: set *errp if the check failed, with reason
299 * Returns true if check passed, otherwise false.
301 bool migrate_caps_check(bool *old_caps
, bool *new_caps
, Error
**errp
)
303 MigrationIncomingState
*mis
= migration_incoming_get_current();
306 #ifndef CONFIG_LIVE_BLOCK_MIGRATION
307 if (new_caps
[MIGRATION_CAPABILITY_BLOCK
]) {
308 error_setg(errp
, "QEMU compiled without old-style (blk/-b, inc/-i) "
310 error_append_hint(errp
, "Use drive_mirror+NBD instead.\n");
315 #ifndef CONFIG_REPLICATION
316 if (new_caps
[MIGRATION_CAPABILITY_X_COLO
]) {
317 error_setg(errp
, "QEMU compiled without replication module"
318 " can't enable COLO");
319 error_append_hint(errp
, "Please enable replication before COLO.\n");
324 if (new_caps
[MIGRATION_CAPABILITY_POSTCOPY_RAM
]) {
325 /* This check is reasonably expensive, so only when it's being
326 * set the first time, also it's only the destination that needs
329 if (!old_caps
[MIGRATION_CAPABILITY_POSTCOPY_RAM
] &&
330 runstate_check(RUN_STATE_INMIGRATE
) &&
331 !postcopy_ram_supported_by_host(mis
, errp
)) {
332 error_prepend(errp
, "Postcopy is not supported: ");
336 if (new_caps
[MIGRATION_CAPABILITY_X_IGNORE_SHARED
]) {
337 error_setg(errp
, "Postcopy is not compatible with ignore-shared");
341 if (new_caps
[MIGRATION_CAPABILITY_MULTIFD
]) {
342 error_setg(errp
, "Postcopy is not yet compatible with multifd");
347 if (new_caps
[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT
]) {
348 WriteTrackingSupport wt_support
;
351 * Check if 'background-snapshot' capability is supported by
352 * host kernel and compatible with guest memory configuration.
354 wt_support
= migrate_query_write_tracking();
355 if (wt_support
< WT_SUPPORT_AVAILABLE
) {
356 error_setg(errp
, "Background-snapshot is not supported by host kernel");
359 if (wt_support
< WT_SUPPORT_COMPATIBLE
) {
360 error_setg(errp
, "Background-snapshot is not compatible "
361 "with guest memory configuration");
366 * Check if there are any migration capabilities
367 * incompatible with 'background-snapshot'.
369 for (idx
= 0; idx
< check_caps_background_snapshot
.size
; idx
++) {
370 int incomp_cap
= check_caps_background_snapshot
.caps
[idx
];
371 if (new_caps
[incomp_cap
]) {
373 "Background-snapshot is not compatible with %s",
374 MigrationCapability_str(incomp_cap
));
381 if (new_caps
[MIGRATION_CAPABILITY_ZERO_COPY_SEND
] &&
382 (!new_caps
[MIGRATION_CAPABILITY_MULTIFD
] ||
383 new_caps
[MIGRATION_CAPABILITY_COMPRESS
] ||
384 new_caps
[MIGRATION_CAPABILITY_XBZRLE
] ||
385 migrate_multifd_compression() ||
388 "Zero copy only available for non-compressed non-TLS multifd migration");
392 if (new_caps
[MIGRATION_CAPABILITY_ZERO_COPY_SEND
]) {
394 "Zero copy currently only available on Linux");
399 if (new_caps
[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT
]) {
400 if (!new_caps
[MIGRATION_CAPABILITY_POSTCOPY_RAM
]) {
401 error_setg(errp
, "Postcopy preempt requires postcopy-ram");
406 * Preempt mode requires urgent pages to be sent in separate
407 * channel, OTOH compression logic will disorder all pages into
408 * different compression channels, which is not compatible with the
409 * preempt assumptions on channel assignments.
411 if (new_caps
[MIGRATION_CAPABILITY_COMPRESS
]) {
412 error_setg(errp
, "Postcopy preempt not compatible with compress");
417 if (new_caps
[MIGRATION_CAPABILITY_MULTIFD
]) {
418 if (new_caps
[MIGRATION_CAPABILITY_COMPRESS
]) {
419 error_setg(errp
, "Multifd is not compatible with compress");
427 bool migrate_cap_set(int cap
, bool value
, Error
**errp
)
429 MigrationState
*s
= migrate_get_current();
430 bool new_caps
[MIGRATION_CAPABILITY__MAX
];
432 if (migration_is_running(s
->state
)) {
433 error_setg(errp
, QERR_MIGRATION_ACTIVE
);
437 memcpy(new_caps
, s
->capabilities
, sizeof(new_caps
));
438 new_caps
[cap
] = value
;
440 if (!migrate_caps_check(s
->capabilities
, new_caps
, errp
)) {
443 s
->capabilities
[cap
] = value
;
447 MigrationCapabilityStatusList
*qmp_query_migrate_capabilities(Error
**errp
)
449 MigrationCapabilityStatusList
*head
= NULL
, **tail
= &head
;
450 MigrationCapabilityStatus
*caps
;
451 MigrationState
*s
= migrate_get_current();
454 for (i
= 0; i
< MIGRATION_CAPABILITY__MAX
; i
++) {
455 #ifndef CONFIG_LIVE_BLOCK_MIGRATION
456 if (i
== MIGRATION_CAPABILITY_BLOCK
) {
460 caps
= g_malloc0(sizeof(*caps
));
461 caps
->capability
= i
;
462 caps
->state
= s
->capabilities
[i
];
463 QAPI_LIST_APPEND(tail
, caps
);
469 void qmp_migrate_set_capabilities(MigrationCapabilityStatusList
*params
,
472 MigrationState
*s
= migrate_get_current();
473 MigrationCapabilityStatusList
*cap
;
474 bool new_caps
[MIGRATION_CAPABILITY__MAX
];
476 if (migration_is_running(s
->state
)) {
477 error_setg(errp
, QERR_MIGRATION_ACTIVE
);
481 memcpy(new_caps
, s
->capabilities
, sizeof(new_caps
));
482 for (cap
= params
; cap
; cap
= cap
->next
) {
483 new_caps
[cap
->value
->capability
] = cap
->value
->state
;
486 if (!migrate_caps_check(s
->capabilities
, new_caps
, errp
)) {
490 for (cap
= params
; cap
; cap
= cap
->next
) {
491 s
->capabilities
[cap
->value
->capability
] = cap
->value
->state
;
497 bool migrate_block_incremental(void)
501 s
= migrate_get_current();
503 return s
->parameters
.block_incremental
;
506 uint32_t migrate_checkpoint_delay(void)
510 s
= migrate_get_current();
512 return s
->parameters
.x_checkpoint_delay
;
515 int migrate_compress_level(void)
519 s
= migrate_get_current();
521 return s
->parameters
.compress_level
;
524 int migrate_compress_threads(void)
528 s
= migrate_get_current();
530 return s
->parameters
.compress_threads
;
533 int migrate_compress_wait_thread(void)
537 s
= migrate_get_current();
539 return s
->parameters
.compress_wait_thread
;
542 uint8_t migrate_cpu_throttle_increment(void)
546 s
= migrate_get_current();
548 return s
->parameters
.cpu_throttle_increment
;
551 uint8_t migrate_cpu_throttle_initial(void)
555 s
= migrate_get_current();
557 return s
->parameters
.cpu_throttle_initial
;
560 bool migrate_cpu_throttle_tailslow(void)
564 s
= migrate_get_current();
566 return s
->parameters
.cpu_throttle_tailslow
;
569 int migrate_decompress_threads(void)
573 s
= migrate_get_current();
575 return s
->parameters
.decompress_threads
;
578 uint8_t migrate_max_cpu_throttle(void)
582 s
= migrate_get_current();
584 return s
->parameters
.max_cpu_throttle
;
587 uint64_t migrate_max_bandwidth(void)
591 s
= migrate_get_current();
593 return s
->parameters
.max_bandwidth
;
596 int64_t migrate_max_postcopy_bandwidth(void)
600 s
= migrate_get_current();
602 return s
->parameters
.max_postcopy_bandwidth
;
605 int migrate_multifd_channels(void)
609 s
= migrate_get_current();
611 return s
->parameters
.multifd_channels
;
614 MultiFDCompression
migrate_multifd_compression(void)
618 s
= migrate_get_current();
620 assert(s
->parameters
.multifd_compression
< MULTIFD_COMPRESSION__MAX
);
621 return s
->parameters
.multifd_compression
;
624 int migrate_multifd_zlib_level(void)
628 s
= migrate_get_current();
630 return s
->parameters
.multifd_zlib_level
;
633 int migrate_multifd_zstd_level(void)
637 s
= migrate_get_current();
639 return s
->parameters
.multifd_zstd_level
;
642 uint8_t migrate_throttle_trigger_threshold(void)
646 s
= migrate_get_current();
648 return s
->parameters
.throttle_trigger_threshold
;
651 uint64_t migrate_xbzrle_cache_size(void)
655 s
= migrate_get_current();
657 return s
->parameters
.xbzrle_cache_size
;
660 /* parameters helpers */
662 AnnounceParameters
*migrate_announce_params(void)
664 static AnnounceParameters ap
;
666 MigrationState
*s
= migrate_get_current();
668 ap
.initial
= s
->parameters
.announce_initial
;
669 ap
.max
= s
->parameters
.announce_max
;
670 ap
.rounds
= s
->parameters
.announce_rounds
;
671 ap
.step
= s
->parameters
.announce_step
;
676 MigrationParameters
*qmp_query_migrate_parameters(Error
**errp
)
678 MigrationParameters
*params
;
679 MigrationState
*s
= migrate_get_current();
681 /* TODO use QAPI_CLONE() instead of duplicating it inline */
682 params
= g_malloc0(sizeof(*params
));
683 params
->has_compress_level
= true;
684 params
->compress_level
= s
->parameters
.compress_level
;
685 params
->has_compress_threads
= true;
686 params
->compress_threads
= s
->parameters
.compress_threads
;
687 params
->has_compress_wait_thread
= true;
688 params
->compress_wait_thread
= s
->parameters
.compress_wait_thread
;
689 params
->has_decompress_threads
= true;
690 params
->decompress_threads
= s
->parameters
.decompress_threads
;
691 params
->has_throttle_trigger_threshold
= true;
692 params
->throttle_trigger_threshold
= s
->parameters
.throttle_trigger_threshold
;
693 params
->has_cpu_throttle_initial
= true;
694 params
->cpu_throttle_initial
= s
->parameters
.cpu_throttle_initial
;
695 params
->has_cpu_throttle_increment
= true;
696 params
->cpu_throttle_increment
= s
->parameters
.cpu_throttle_increment
;
697 params
->has_cpu_throttle_tailslow
= true;
698 params
->cpu_throttle_tailslow
= s
->parameters
.cpu_throttle_tailslow
;
699 params
->tls_creds
= g_strdup(s
->parameters
.tls_creds
);
700 params
->tls_hostname
= g_strdup(s
->parameters
.tls_hostname
);
701 params
->tls_authz
= g_strdup(s
->parameters
.tls_authz
?
702 s
->parameters
.tls_authz
: "");
703 params
->has_max_bandwidth
= true;
704 params
->max_bandwidth
= s
->parameters
.max_bandwidth
;
705 params
->has_downtime_limit
= true;
706 params
->downtime_limit
= s
->parameters
.downtime_limit
;
707 params
->has_x_checkpoint_delay
= true;
708 params
->x_checkpoint_delay
= s
->parameters
.x_checkpoint_delay
;
709 params
->has_block_incremental
= true;
710 params
->block_incremental
= s
->parameters
.block_incremental
;
711 params
->has_multifd_channels
= true;
712 params
->multifd_channels
= s
->parameters
.multifd_channels
;
713 params
->has_multifd_compression
= true;
714 params
->multifd_compression
= s
->parameters
.multifd_compression
;
715 params
->has_multifd_zlib_level
= true;
716 params
->multifd_zlib_level
= s
->parameters
.multifd_zlib_level
;
717 params
->has_multifd_zstd_level
= true;
718 params
->multifd_zstd_level
= s
->parameters
.multifd_zstd_level
;
719 params
->has_xbzrle_cache_size
= true;
720 params
->xbzrle_cache_size
= s
->parameters
.xbzrle_cache_size
;
721 params
->has_max_postcopy_bandwidth
= true;
722 params
->max_postcopy_bandwidth
= s
->parameters
.max_postcopy_bandwidth
;
723 params
->has_max_cpu_throttle
= true;
724 params
->max_cpu_throttle
= s
->parameters
.max_cpu_throttle
;
725 params
->has_announce_initial
= true;
726 params
->announce_initial
= s
->parameters
.announce_initial
;
727 params
->has_announce_max
= true;
728 params
->announce_max
= s
->parameters
.announce_max
;
729 params
->has_announce_rounds
= true;
730 params
->announce_rounds
= s
->parameters
.announce_rounds
;
731 params
->has_announce_step
= true;
732 params
->announce_step
= s
->parameters
.announce_step
;
734 if (s
->parameters
.has_block_bitmap_mapping
) {
735 params
->has_block_bitmap_mapping
= true;
736 params
->block_bitmap_mapping
=
737 QAPI_CLONE(BitmapMigrationNodeAliasList
,
738 s
->parameters
.block_bitmap_mapping
);
745 * Check whether the parameters are valid. Error will be put into errp
746 * (if provided). Return true if valid, otherwise false.
748 bool migrate_params_check(MigrationParameters
*params
, Error
**errp
)
750 if (params
->has_compress_level
&&
751 (params
->compress_level
> 9)) {
752 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "compress_level",
753 "a value between 0 and 9");
757 if (params
->has_compress_threads
&& (params
->compress_threads
< 1)) {
758 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
760 "a value between 1 and 255");
764 if (params
->has_decompress_threads
&& (params
->decompress_threads
< 1)) {
765 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
766 "decompress_threads",
767 "a value between 1 and 255");
771 if (params
->has_throttle_trigger_threshold
&&
772 (params
->throttle_trigger_threshold
< 1 ||
773 params
->throttle_trigger_threshold
> 100)) {
774 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
775 "throttle_trigger_threshold",
776 "an integer in the range of 1 to 100");
780 if (params
->has_cpu_throttle_initial
&&
781 (params
->cpu_throttle_initial
< 1 ||
782 params
->cpu_throttle_initial
> 99)) {
783 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
784 "cpu_throttle_initial",
785 "an integer in the range of 1 to 99");
789 if (params
->has_cpu_throttle_increment
&&
790 (params
->cpu_throttle_increment
< 1 ||
791 params
->cpu_throttle_increment
> 99)) {
792 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
793 "cpu_throttle_increment",
794 "an integer in the range of 1 to 99");
798 if (params
->has_max_bandwidth
&& (params
->max_bandwidth
> SIZE_MAX
)) {
799 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
801 "an integer in the range of 0 to "stringify(SIZE_MAX
)
806 if (params
->has_downtime_limit
&&
807 (params
->downtime_limit
> MAX_MIGRATE_DOWNTIME
)) {
808 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
810 "an integer in the range of 0 to "
811 stringify(MAX_MIGRATE_DOWNTIME
)" ms");
815 /* x_checkpoint_delay is now always positive */
817 if (params
->has_multifd_channels
&& (params
->multifd_channels
< 1)) {
818 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
820 "a value between 1 and 255");
824 if (params
->has_multifd_zlib_level
&&
825 (params
->multifd_zlib_level
> 9)) {
826 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "multifd_zlib_level",
827 "a value between 0 and 9");
831 if (params
->has_multifd_zstd_level
&&
832 (params
->multifd_zstd_level
> 20)) {
833 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "multifd_zstd_level",
834 "a value between 0 and 20");
838 if (params
->has_xbzrle_cache_size
&&
839 (params
->xbzrle_cache_size
< qemu_target_page_size() ||
840 !is_power_of_2(params
->xbzrle_cache_size
))) {
841 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
843 "a power of two no less than the target page size");
847 if (params
->has_max_cpu_throttle
&&
848 (params
->max_cpu_throttle
< params
->cpu_throttle_initial
||
849 params
->max_cpu_throttle
> 99)) {
850 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
852 "an integer in the range of cpu_throttle_initial to 99");
856 if (params
->has_announce_initial
&&
857 params
->announce_initial
> 100000) {
858 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
860 "a value between 0 and 100000");
863 if (params
->has_announce_max
&&
864 params
->announce_max
> 100000) {
865 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
867 "a value between 0 and 100000");
870 if (params
->has_announce_rounds
&&
871 params
->announce_rounds
> 1000) {
872 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
874 "a value between 0 and 1000");
877 if (params
->has_announce_step
&&
878 (params
->announce_step
< 1 ||
879 params
->announce_step
> 10000)) {
880 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
882 "a value between 0 and 10000");
886 if (params
->has_block_bitmap_mapping
&&
887 !check_dirty_bitmap_mig_alias_map(params
->block_bitmap_mapping
, errp
)) {
888 error_prepend(errp
, "Invalid mapping given for block-bitmap-mapping: ");
893 if (migrate_zero_copy_send() &&
894 ((params
->has_multifd_compression
&& params
->multifd_compression
) ||
895 (params
->tls_creds
&& *params
->tls_creds
))) {
897 "Zero copy only available for non-compressed non-TLS multifd migration");
905 static void migrate_params_test_apply(MigrateSetParameters
*params
,
906 MigrationParameters
*dest
)
908 *dest
= migrate_get_current()->parameters
;
910 /* TODO use QAPI_CLONE() instead of duplicating it inline */
912 if (params
->has_compress_level
) {
913 dest
->compress_level
= params
->compress_level
;
916 if (params
->has_compress_threads
) {
917 dest
->compress_threads
= params
->compress_threads
;
920 if (params
->has_compress_wait_thread
) {
921 dest
->compress_wait_thread
= params
->compress_wait_thread
;
924 if (params
->has_decompress_threads
) {
925 dest
->decompress_threads
= params
->decompress_threads
;
928 if (params
->has_throttle_trigger_threshold
) {
929 dest
->throttle_trigger_threshold
= params
->throttle_trigger_threshold
;
932 if (params
->has_cpu_throttle_initial
) {
933 dest
->cpu_throttle_initial
= params
->cpu_throttle_initial
;
936 if (params
->has_cpu_throttle_increment
) {
937 dest
->cpu_throttle_increment
= params
->cpu_throttle_increment
;
940 if (params
->has_cpu_throttle_tailslow
) {
941 dest
->cpu_throttle_tailslow
= params
->cpu_throttle_tailslow
;
944 if (params
->tls_creds
) {
945 assert(params
->tls_creds
->type
== QTYPE_QSTRING
);
946 dest
->tls_creds
= params
->tls_creds
->u
.s
;
949 if (params
->tls_hostname
) {
950 assert(params
->tls_hostname
->type
== QTYPE_QSTRING
);
951 dest
->tls_hostname
= params
->tls_hostname
->u
.s
;
954 if (params
->has_max_bandwidth
) {
955 dest
->max_bandwidth
= params
->max_bandwidth
;
958 if (params
->has_downtime_limit
) {
959 dest
->downtime_limit
= params
->downtime_limit
;
962 if (params
->has_x_checkpoint_delay
) {
963 dest
->x_checkpoint_delay
= params
->x_checkpoint_delay
;
966 if (params
->has_block_incremental
) {
967 dest
->block_incremental
= params
->block_incremental
;
969 if (params
->has_multifd_channels
) {
970 dest
->multifd_channels
= params
->multifd_channels
;
972 if (params
->has_multifd_compression
) {
973 dest
->multifd_compression
= params
->multifd_compression
;
975 if (params
->has_xbzrle_cache_size
) {
976 dest
->xbzrle_cache_size
= params
->xbzrle_cache_size
;
978 if (params
->has_max_postcopy_bandwidth
) {
979 dest
->max_postcopy_bandwidth
= params
->max_postcopy_bandwidth
;
981 if (params
->has_max_cpu_throttle
) {
982 dest
->max_cpu_throttle
= params
->max_cpu_throttle
;
984 if (params
->has_announce_initial
) {
985 dest
->announce_initial
= params
->announce_initial
;
987 if (params
->has_announce_max
) {
988 dest
->announce_max
= params
->announce_max
;
990 if (params
->has_announce_rounds
) {
991 dest
->announce_rounds
= params
->announce_rounds
;
993 if (params
->has_announce_step
) {
994 dest
->announce_step
= params
->announce_step
;
997 if (params
->has_block_bitmap_mapping
) {
998 dest
->has_block_bitmap_mapping
= true;
999 dest
->block_bitmap_mapping
= params
->block_bitmap_mapping
;
1003 static void migrate_params_apply(MigrateSetParameters
*params
, Error
**errp
)
1005 MigrationState
*s
= migrate_get_current();
1007 /* TODO use QAPI_CLONE() instead of duplicating it inline */
1009 if (params
->has_compress_level
) {
1010 s
->parameters
.compress_level
= params
->compress_level
;
1013 if (params
->has_compress_threads
) {
1014 s
->parameters
.compress_threads
= params
->compress_threads
;
1017 if (params
->has_compress_wait_thread
) {
1018 s
->parameters
.compress_wait_thread
= params
->compress_wait_thread
;
1021 if (params
->has_decompress_threads
) {
1022 s
->parameters
.decompress_threads
= params
->decompress_threads
;
1025 if (params
->has_throttle_trigger_threshold
) {
1026 s
->parameters
.throttle_trigger_threshold
= params
->throttle_trigger_threshold
;
1029 if (params
->has_cpu_throttle_initial
) {
1030 s
->parameters
.cpu_throttle_initial
= params
->cpu_throttle_initial
;
1033 if (params
->has_cpu_throttle_increment
) {
1034 s
->parameters
.cpu_throttle_increment
= params
->cpu_throttle_increment
;
1037 if (params
->has_cpu_throttle_tailslow
) {
1038 s
->parameters
.cpu_throttle_tailslow
= params
->cpu_throttle_tailslow
;
1041 if (params
->tls_creds
) {
1042 g_free(s
->parameters
.tls_creds
);
1043 assert(params
->tls_creds
->type
== QTYPE_QSTRING
);
1044 s
->parameters
.tls_creds
= g_strdup(params
->tls_creds
->u
.s
);
1047 if (params
->tls_hostname
) {
1048 g_free(s
->parameters
.tls_hostname
);
1049 assert(params
->tls_hostname
->type
== QTYPE_QSTRING
);
1050 s
->parameters
.tls_hostname
= g_strdup(params
->tls_hostname
->u
.s
);
1053 if (params
->tls_authz
) {
1054 g_free(s
->parameters
.tls_authz
);
1055 assert(params
->tls_authz
->type
== QTYPE_QSTRING
);
1056 s
->parameters
.tls_authz
= g_strdup(params
->tls_authz
->u
.s
);
1059 if (params
->has_max_bandwidth
) {
1060 s
->parameters
.max_bandwidth
= params
->max_bandwidth
;
1061 if (s
->to_dst_file
&& !migration_in_postcopy()) {
1062 qemu_file_set_rate_limit(s
->to_dst_file
,
1063 s
->parameters
.max_bandwidth
/ XFER_LIMIT_RATIO
);
1067 if (params
->has_downtime_limit
) {
1068 s
->parameters
.downtime_limit
= params
->downtime_limit
;
1071 if (params
->has_x_checkpoint_delay
) {
1072 s
->parameters
.x_checkpoint_delay
= params
->x_checkpoint_delay
;
1073 if (migration_in_colo_state()) {
1074 colo_checkpoint_notify(s
);
1078 if (params
->has_block_incremental
) {
1079 s
->parameters
.block_incremental
= params
->block_incremental
;
1081 if (params
->has_multifd_channels
) {
1082 s
->parameters
.multifd_channels
= params
->multifd_channels
;
1084 if (params
->has_multifd_compression
) {
1085 s
->parameters
.multifd_compression
= params
->multifd_compression
;
1087 if (params
->has_xbzrle_cache_size
) {
1088 s
->parameters
.xbzrle_cache_size
= params
->xbzrle_cache_size
;
1089 xbzrle_cache_resize(params
->xbzrle_cache_size
, errp
);
1091 if (params
->has_max_postcopy_bandwidth
) {
1092 s
->parameters
.max_postcopy_bandwidth
= params
->max_postcopy_bandwidth
;
1093 if (s
->to_dst_file
&& migration_in_postcopy()) {
1094 qemu_file_set_rate_limit(s
->to_dst_file
,
1095 s
->parameters
.max_postcopy_bandwidth
/ XFER_LIMIT_RATIO
);
1098 if (params
->has_max_cpu_throttle
) {
1099 s
->parameters
.max_cpu_throttle
= params
->max_cpu_throttle
;
1101 if (params
->has_announce_initial
) {
1102 s
->parameters
.announce_initial
= params
->announce_initial
;
1104 if (params
->has_announce_max
) {
1105 s
->parameters
.announce_max
= params
->announce_max
;
1107 if (params
->has_announce_rounds
) {
1108 s
->parameters
.announce_rounds
= params
->announce_rounds
;
1110 if (params
->has_announce_step
) {
1111 s
->parameters
.announce_step
= params
->announce_step
;
1114 if (params
->has_block_bitmap_mapping
) {
1115 qapi_free_BitmapMigrationNodeAliasList(
1116 s
->parameters
.block_bitmap_mapping
);
1118 s
->parameters
.has_block_bitmap_mapping
= true;
1119 s
->parameters
.block_bitmap_mapping
=
1120 QAPI_CLONE(BitmapMigrationNodeAliasList
,
1121 params
->block_bitmap_mapping
);
1125 void qmp_migrate_set_parameters(MigrateSetParameters
*params
, Error
**errp
)
1127 MigrationParameters tmp
;
1129 /* TODO Rewrite "" to null instead */
1130 if (params
->tls_creds
1131 && params
->tls_creds
->type
== QTYPE_QNULL
) {
1132 qobject_unref(params
->tls_creds
->u
.n
);
1133 params
->tls_creds
->type
= QTYPE_QSTRING
;
1134 params
->tls_creds
->u
.s
= strdup("");
1136 /* TODO Rewrite "" to null instead */
1137 if (params
->tls_hostname
1138 && params
->tls_hostname
->type
== QTYPE_QNULL
) {
1139 qobject_unref(params
->tls_hostname
->u
.n
);
1140 params
->tls_hostname
->type
= QTYPE_QSTRING
;
1141 params
->tls_hostname
->u
.s
= strdup("");
1144 migrate_params_test_apply(params
, &tmp
);
1146 if (!migrate_params_check(&tmp
, errp
)) {
1147 /* Invalid parameter */
1151 migrate_params_apply(params
, errp
);