4 * Copyright IBM, Corp. 2008
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
16 #include "qemu-common.h"
17 #include "qemu/main-loop.h"
18 #include "migration/migration.h"
19 #include "monitor/monitor.h"
20 #include "migration/qemu-file.h"
21 #include "sysemu/sysemu.h"
22 #include "block/block.h"
23 #include "qemu/sockets.h"
24 #include "migration/block.h"
25 #include "qemu/thread.h"
26 #include "qmp-commands.h"
29 #define MAX_THROTTLE (32 << 20) /* Migration speed throttling */
31 /* Amount of time to allocate to each "chunk" of bandwidth-throttled
33 #define BUFFER_DELAY 100
34 #define XFER_LIMIT_RATIO (1000 / BUFFER_DELAY)
36 /* Default compression thread count */
37 #define DEFAULT_MIGRATE_COMPRESS_THREAD_COUNT 8
38 /* Default decompression thread count, usually decompression is at
39 * least 4 times as fast as compression.*/
40 #define DEFAULT_MIGRATE_DECOMPRESS_THREAD_COUNT 2
41 /*0: means nocompress, 1: best speed, ... 9: best compress ratio */
42 #define DEFAULT_MIGRATE_COMPRESS_LEVEL 1
44 /* Migration XBZRLE default cache size */
45 #define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024)
47 static NotifierList migration_state_notifiers
=
48 NOTIFIER_LIST_INITIALIZER(migration_state_notifiers
);
50 static bool deferred_incoming
;
52 /* When we add fault tolerance, we could have several
53 migrations at once. For now we don't need to add
54 dynamic creation of migration */
56 MigrationState
*migrate_get_current(void)
58 static MigrationState current_migration
= {
59 .state
= MIGRATION_STATUS_NONE
,
60 .bandwidth_limit
= MAX_THROTTLE
,
61 .xbzrle_cache_size
= DEFAULT_MIGRATE_CACHE_SIZE
,
63 .compress_thread_count
= DEFAULT_MIGRATE_COMPRESS_THREAD_COUNT
,
64 .decompress_thread_count
= DEFAULT_MIGRATE_DECOMPRESS_THREAD_COUNT
,
65 .compress_level
= DEFAULT_MIGRATE_COMPRESS_LEVEL
,
68 return ¤t_migration
;
72 * Called on -incoming with a defer: uri.
73 * The migration can be started later after any parameters have been
76 static void deferred_incoming_migration(Error
**errp
)
78 if (deferred_incoming
) {
79 error_setg(errp
, "Incoming migration already deferred");
81 deferred_incoming
= true;
84 void qemu_start_incoming_migration(const char *uri
, Error
**errp
)
88 if (!strcmp(uri
, "defer")) {
89 deferred_incoming_migration(errp
);
90 } else if (strstart(uri
, "tcp:", &p
)) {
91 tcp_start_incoming_migration(p
, errp
);
93 } else if (strstart(uri
, "rdma:", &p
)) {
94 rdma_start_incoming_migration(p
, errp
);
97 } else if (strstart(uri
, "exec:", &p
)) {
98 exec_start_incoming_migration(p
, errp
);
99 } else if (strstart(uri
, "unix:", &p
)) {
100 unix_start_incoming_migration(p
, errp
);
101 } else if (strstart(uri
, "fd:", &p
)) {
102 fd_start_incoming_migration(p
, errp
);
105 error_setg(errp
, "unknown migration protocol: %s", uri
);
109 static void process_incoming_migration_co(void *opaque
)
111 QEMUFile
*f
= opaque
;
112 Error
*local_err
= NULL
;
115 ret
= qemu_loadvm_state(f
);
117 free_xbzrle_decoded_buf();
119 error_report("load of migration failed: %s", strerror(-ret
));
120 migrate_decompress_threads_join();
123 qemu_announce_self();
125 /* Make sure all file formats flush their mutable metadata */
126 bdrv_invalidate_cache_all(&local_err
);
128 error_report_err(local_err
);
129 migrate_decompress_threads_join();
136 runstate_set(RUN_STATE_PAUSED
);
138 migrate_decompress_threads_join();
141 void process_incoming_migration(QEMUFile
*f
)
143 Coroutine
*co
= qemu_coroutine_create(process_incoming_migration_co
);
144 int fd
= qemu_get_fd(f
);
147 migrate_decompress_threads_create();
148 qemu_set_nonblock(fd
);
149 qemu_coroutine_enter(co
, f
);
152 /* amount of nanoseconds we are willing to wait for migration to be down.
153 * the choice of nanoseconds is because it is the maximum resolution that
154 * get_clock() can achieve. It is an internal measure. All user-visible
155 * units must be in seconds */
156 static uint64_t max_downtime
= 300000000;
158 uint64_t migrate_max_downtime(void)
163 MigrationCapabilityStatusList
*qmp_query_migrate_capabilities(Error
**errp
)
165 MigrationCapabilityStatusList
*head
= NULL
;
166 MigrationCapabilityStatusList
*caps
;
167 MigrationState
*s
= migrate_get_current();
170 caps
= NULL
; /* silence compiler warning */
171 for (i
= 0; i
< MIGRATION_CAPABILITY_MAX
; i
++) {
173 head
= g_malloc0(sizeof(*caps
));
176 caps
->next
= g_malloc0(sizeof(*caps
));
180 g_malloc(sizeof(*caps
->value
));
181 caps
->value
->capability
= i
;
182 caps
->value
->state
= s
->enabled_capabilities
[i
];
188 static void get_xbzrle_cache_stats(MigrationInfo
*info
)
190 if (migrate_use_xbzrle()) {
191 info
->has_xbzrle_cache
= true;
192 info
->xbzrle_cache
= g_malloc0(sizeof(*info
->xbzrle_cache
));
193 info
->xbzrle_cache
->cache_size
= migrate_xbzrle_cache_size();
194 info
->xbzrle_cache
->bytes
= xbzrle_mig_bytes_transferred();
195 info
->xbzrle_cache
->pages
= xbzrle_mig_pages_transferred();
196 info
->xbzrle_cache
->cache_miss
= xbzrle_mig_pages_cache_miss();
197 info
->xbzrle_cache
->cache_miss_rate
= xbzrle_mig_cache_miss_rate();
198 info
->xbzrle_cache
->overflow
= xbzrle_mig_pages_overflow();
202 MigrationInfo
*qmp_query_migrate(Error
**errp
)
204 MigrationInfo
*info
= g_malloc0(sizeof(*info
));
205 MigrationState
*s
= migrate_get_current();
208 case MIGRATION_STATUS_NONE
:
209 /* no migration has happened ever */
211 case MIGRATION_STATUS_SETUP
:
212 info
->has_status
= true;
213 info
->has_total_time
= false;
215 case MIGRATION_STATUS_ACTIVE
:
216 case MIGRATION_STATUS_CANCELLING
:
217 info
->has_status
= true;
218 info
->has_total_time
= true;
219 info
->total_time
= qemu_clock_get_ms(QEMU_CLOCK_REALTIME
)
221 info
->has_expected_downtime
= true;
222 info
->expected_downtime
= s
->expected_downtime
;
223 info
->has_setup_time
= true;
224 info
->setup_time
= s
->setup_time
;
226 info
->has_ram
= true;
227 info
->ram
= g_malloc0(sizeof(*info
->ram
));
228 info
->ram
->transferred
= ram_bytes_transferred();
229 info
->ram
->remaining
= ram_bytes_remaining();
230 info
->ram
->total
= ram_bytes_total();
231 info
->ram
->duplicate
= dup_mig_pages_transferred();
232 info
->ram
->skipped
= skipped_mig_pages_transferred();
233 info
->ram
->normal
= norm_mig_pages_transferred();
234 info
->ram
->normal_bytes
= norm_mig_bytes_transferred();
235 info
->ram
->dirty_pages_rate
= s
->dirty_pages_rate
;
236 info
->ram
->mbps
= s
->mbps
;
237 info
->ram
->dirty_sync_count
= s
->dirty_sync_count
;
239 if (blk_mig_active()) {
240 info
->has_disk
= true;
241 info
->disk
= g_malloc0(sizeof(*info
->disk
));
242 info
->disk
->transferred
= blk_mig_bytes_transferred();
243 info
->disk
->remaining
= blk_mig_bytes_remaining();
244 info
->disk
->total
= blk_mig_bytes_total();
247 get_xbzrle_cache_stats(info
);
249 case MIGRATION_STATUS_COMPLETED
:
250 get_xbzrle_cache_stats(info
);
252 info
->has_status
= true;
253 info
->has_total_time
= true;
254 info
->total_time
= s
->total_time
;
255 info
->has_downtime
= true;
256 info
->downtime
= s
->downtime
;
257 info
->has_setup_time
= true;
258 info
->setup_time
= s
->setup_time
;
260 info
->has_ram
= true;
261 info
->ram
= g_malloc0(sizeof(*info
->ram
));
262 info
->ram
->transferred
= ram_bytes_transferred();
263 info
->ram
->remaining
= 0;
264 info
->ram
->total
= ram_bytes_total();
265 info
->ram
->duplicate
= dup_mig_pages_transferred();
266 info
->ram
->skipped
= skipped_mig_pages_transferred();
267 info
->ram
->normal
= norm_mig_pages_transferred();
268 info
->ram
->normal_bytes
= norm_mig_bytes_transferred();
269 info
->ram
->mbps
= s
->mbps
;
270 info
->ram
->dirty_sync_count
= s
->dirty_sync_count
;
272 case MIGRATION_STATUS_FAILED
:
273 info
->has_status
= true;
275 case MIGRATION_STATUS_CANCELLED
:
276 info
->has_status
= true;
279 info
->status
= s
->state
;
284 void qmp_migrate_set_capabilities(MigrationCapabilityStatusList
*params
,
287 MigrationState
*s
= migrate_get_current();
288 MigrationCapabilityStatusList
*cap
;
290 if (s
->state
== MIGRATION_STATUS_ACTIVE
||
291 s
->state
== MIGRATION_STATUS_SETUP
) {
292 error_set(errp
, QERR_MIGRATION_ACTIVE
);
296 for (cap
= params
; cap
; cap
= cap
->next
) {
297 s
->enabled_capabilities
[cap
->value
->capability
] = cap
->value
->state
;
301 /* shared migration helpers */
303 static void migrate_set_state(MigrationState
*s
, int old_state
, int new_state
)
305 if (atomic_cmpxchg(&s
->state
, old_state
, new_state
) == new_state
) {
306 trace_migrate_set_state(new_state
);
310 static void migrate_fd_cleanup(void *opaque
)
312 MigrationState
*s
= opaque
;
314 qemu_bh_delete(s
->cleanup_bh
);
315 s
->cleanup_bh
= NULL
;
318 trace_migrate_fd_cleanup();
319 qemu_mutex_unlock_iothread();
320 qemu_thread_join(&s
->thread
);
321 qemu_mutex_lock_iothread();
323 migrate_compress_threads_join();
324 qemu_fclose(s
->file
);
328 assert(s
->state
!= MIGRATION_STATUS_ACTIVE
);
330 if (s
->state
!= MIGRATION_STATUS_COMPLETED
) {
331 qemu_savevm_state_cancel();
332 if (s
->state
== MIGRATION_STATUS_CANCELLING
) {
333 migrate_set_state(s
, MIGRATION_STATUS_CANCELLING
,
334 MIGRATION_STATUS_CANCELLED
);
338 notifier_list_notify(&migration_state_notifiers
, s
);
341 void migrate_fd_error(MigrationState
*s
)
343 trace_migrate_fd_error();
344 assert(s
->file
== NULL
);
345 s
->state
= MIGRATION_STATUS_FAILED
;
346 trace_migrate_set_state(MIGRATION_STATUS_FAILED
);
347 notifier_list_notify(&migration_state_notifiers
, s
);
350 static void migrate_fd_cancel(MigrationState
*s
)
353 QEMUFile
*f
= migrate_get_current()->file
;
354 trace_migrate_fd_cancel();
357 old_state
= s
->state
;
358 if (old_state
!= MIGRATION_STATUS_SETUP
&&
359 old_state
!= MIGRATION_STATUS_ACTIVE
) {
362 migrate_set_state(s
, old_state
, MIGRATION_STATUS_CANCELLING
);
363 } while (s
->state
!= MIGRATION_STATUS_CANCELLING
);
366 * If we're unlucky the migration code might be stuck somewhere in a
367 * send/write while the network has failed and is waiting to timeout;
368 * if we've got shutdown(2) available then we can force it to quit.
369 * The outgoing qemu file gets closed in migrate_fd_cleanup that is
370 * called in a bh, so there is no race against this cancel.
372 if (s
->state
== MIGRATION_STATUS_CANCELLING
&& f
) {
373 qemu_file_shutdown(f
);
377 void add_migration_state_change_notifier(Notifier
*notify
)
379 notifier_list_add(&migration_state_notifiers
, notify
);
382 void remove_migration_state_change_notifier(Notifier
*notify
)
384 notifier_remove(notify
);
387 bool migration_in_setup(MigrationState
*s
)
389 return s
->state
== MIGRATION_STATUS_SETUP
;
392 bool migration_has_finished(MigrationState
*s
)
394 return s
->state
== MIGRATION_STATUS_COMPLETED
;
397 bool migration_has_failed(MigrationState
*s
)
399 return (s
->state
== MIGRATION_STATUS_CANCELLED
||
400 s
->state
== MIGRATION_STATUS_FAILED
);
403 static MigrationState
*migrate_init(const MigrationParams
*params
)
405 MigrationState
*s
= migrate_get_current();
406 int64_t bandwidth_limit
= s
->bandwidth_limit
;
407 bool enabled_capabilities
[MIGRATION_CAPABILITY_MAX
];
408 int64_t xbzrle_cache_size
= s
->xbzrle_cache_size
;
409 int compress_level
= s
->compress_level
;
410 int compress_thread_count
= s
->compress_thread_count
;
411 int decompress_thread_count
= s
->decompress_thread_count
;
413 memcpy(enabled_capabilities
, s
->enabled_capabilities
,
414 sizeof(enabled_capabilities
));
416 memset(s
, 0, sizeof(*s
));
418 memcpy(s
->enabled_capabilities
, enabled_capabilities
,
419 sizeof(enabled_capabilities
));
420 s
->xbzrle_cache_size
= xbzrle_cache_size
;
422 s
->compress_level
= compress_level
;
423 s
->compress_thread_count
= compress_thread_count
;
424 s
->decompress_thread_count
= decompress_thread_count
;
425 s
->bandwidth_limit
= bandwidth_limit
;
426 s
->state
= MIGRATION_STATUS_SETUP
;
427 trace_migrate_set_state(MIGRATION_STATUS_SETUP
);
429 s
->total_time
= qemu_clock_get_ms(QEMU_CLOCK_REALTIME
);
433 static GSList
*migration_blockers
;
435 void migrate_add_blocker(Error
*reason
)
437 migration_blockers
= g_slist_prepend(migration_blockers
, reason
);
440 void migrate_del_blocker(Error
*reason
)
442 migration_blockers
= g_slist_remove(migration_blockers
, reason
);
445 void qmp_migrate_incoming(const char *uri
, Error
**errp
)
447 Error
*local_err
= NULL
;
448 static bool once
= true;
450 if (!deferred_incoming
) {
451 error_setg(errp
, "For use with '-incoming defer'");
455 error_setg(errp
, "The incoming migration has already been started");
458 qemu_start_incoming_migration(uri
, &local_err
);
461 error_propagate(errp
, local_err
);
468 void qmp_migrate(const char *uri
, bool has_blk
, bool blk
,
469 bool has_inc
, bool inc
, bool has_detach
, bool detach
,
472 Error
*local_err
= NULL
;
473 MigrationState
*s
= migrate_get_current();
474 MigrationParams params
;
477 params
.blk
= has_blk
&& blk
;
478 params
.shared
= has_inc
&& inc
;
480 if (s
->state
== MIGRATION_STATUS_ACTIVE
||
481 s
->state
== MIGRATION_STATUS_SETUP
||
482 s
->state
== MIGRATION_STATUS_CANCELLING
) {
483 error_set(errp
, QERR_MIGRATION_ACTIVE
);
487 if (runstate_check(RUN_STATE_INMIGRATE
)) {
488 error_setg(errp
, "Guest is waiting for an incoming migration");
492 if (qemu_savevm_state_blocked(errp
)) {
496 if (migration_blockers
) {
497 *errp
= error_copy(migration_blockers
->data
);
501 s
= migrate_init(¶ms
);
503 if (strstart(uri
, "tcp:", &p
)) {
504 tcp_start_outgoing_migration(s
, p
, &local_err
);
506 } else if (strstart(uri
, "rdma:", &p
)) {
507 rdma_start_outgoing_migration(s
, p
, &local_err
);
510 } else if (strstart(uri
, "exec:", &p
)) {
511 exec_start_outgoing_migration(s
, p
, &local_err
);
512 } else if (strstart(uri
, "unix:", &p
)) {
513 unix_start_outgoing_migration(s
, p
, &local_err
);
514 } else if (strstart(uri
, "fd:", &p
)) {
515 fd_start_outgoing_migration(s
, p
, &local_err
);
518 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, "uri", "a valid migration protocol");
519 s
->state
= MIGRATION_STATUS_FAILED
;
525 error_propagate(errp
, local_err
);
530 void qmp_migrate_cancel(Error
**errp
)
532 migrate_fd_cancel(migrate_get_current());
535 void qmp_migrate_set_cache_size(int64_t value
, Error
**errp
)
537 MigrationState
*s
= migrate_get_current();
540 /* Check for truncation */
541 if (value
!= (size_t)value
) {
542 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, "cache size",
543 "exceeding address space");
547 /* Cache should not be larger than guest ram size */
548 if (value
> ram_bytes_total()) {
549 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, "cache size",
550 "exceeds guest ram size ");
554 new_size
= xbzrle_cache_resize(value
);
556 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, "cache size",
557 "is smaller than page size");
561 s
->xbzrle_cache_size
= new_size
;
564 int64_t qmp_query_migrate_cache_size(Error
**errp
)
566 return migrate_xbzrle_cache_size();
569 void qmp_migrate_set_speed(int64_t value
, Error
**errp
)
576 if (value
> SIZE_MAX
) {
580 s
= migrate_get_current();
581 s
->bandwidth_limit
= value
;
583 qemu_file_set_rate_limit(s
->file
, s
->bandwidth_limit
/ XFER_LIMIT_RATIO
);
587 void qmp_migrate_set_downtime(double value
, Error
**errp
)
590 value
= MAX(0, MIN(UINT64_MAX
, value
));
591 max_downtime
= (uint64_t)value
;
594 bool migrate_auto_converge(void)
598 s
= migrate_get_current();
600 return s
->enabled_capabilities
[MIGRATION_CAPABILITY_AUTO_CONVERGE
];
603 bool migrate_zero_blocks(void)
607 s
= migrate_get_current();
609 return s
->enabled_capabilities
[MIGRATION_CAPABILITY_ZERO_BLOCKS
];
612 bool migrate_use_compression(void)
614 /* Disable compression before the patch series are applied */
618 int migrate_compress_level(void)
622 s
= migrate_get_current();
624 return s
->compress_level
;
627 int migrate_compress_threads(void)
631 s
= migrate_get_current();
633 return s
->compress_thread_count
;
636 int migrate_decompress_threads(void)
640 s
= migrate_get_current();
642 return s
->decompress_thread_count
;
645 int migrate_use_xbzrle(void)
649 s
= migrate_get_current();
651 return s
->enabled_capabilities
[MIGRATION_CAPABILITY_XBZRLE
];
654 int64_t migrate_xbzrle_cache_size(void)
658 s
= migrate_get_current();
660 return s
->xbzrle_cache_size
;
663 /* migration thread support */
665 static void *migration_thread(void *opaque
)
667 MigrationState
*s
= opaque
;
668 int64_t initial_time
= qemu_clock_get_ms(QEMU_CLOCK_REALTIME
);
669 int64_t setup_start
= qemu_clock_get_ms(QEMU_CLOCK_HOST
);
670 int64_t initial_bytes
= 0;
671 int64_t max_size
= 0;
672 int64_t start_time
= initial_time
;
673 bool old_vm_running
= false;
675 qemu_savevm_state_begin(s
->file
, &s
->params
);
677 s
->setup_time
= qemu_clock_get_ms(QEMU_CLOCK_HOST
) - setup_start
;
678 migrate_set_state(s
, MIGRATION_STATUS_SETUP
, MIGRATION_STATUS_ACTIVE
);
680 while (s
->state
== MIGRATION_STATUS_ACTIVE
) {
681 int64_t current_time
;
682 uint64_t pending_size
;
684 if (!qemu_file_rate_limit(s
->file
)) {
685 pending_size
= qemu_savevm_state_pending(s
->file
, max_size
);
686 trace_migrate_pending(pending_size
, max_size
);
687 if (pending_size
&& pending_size
>= max_size
) {
688 qemu_savevm_state_iterate(s
->file
);
692 qemu_mutex_lock_iothread();
693 start_time
= qemu_clock_get_ms(QEMU_CLOCK_REALTIME
);
694 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER
);
695 old_vm_running
= runstate_is_running();
697 ret
= vm_stop_force_state(RUN_STATE_FINISH_MIGRATE
);
699 qemu_file_set_rate_limit(s
->file
, INT64_MAX
);
700 qemu_savevm_state_complete(s
->file
);
702 qemu_mutex_unlock_iothread();
705 migrate_set_state(s
, MIGRATION_STATUS_ACTIVE
,
706 MIGRATION_STATUS_FAILED
);
710 if (!qemu_file_get_error(s
->file
)) {
711 migrate_set_state(s
, MIGRATION_STATUS_ACTIVE
,
712 MIGRATION_STATUS_COMPLETED
);
718 if (qemu_file_get_error(s
->file
)) {
719 migrate_set_state(s
, MIGRATION_STATUS_ACTIVE
,
720 MIGRATION_STATUS_FAILED
);
723 current_time
= qemu_clock_get_ms(QEMU_CLOCK_REALTIME
);
724 if (current_time
>= initial_time
+ BUFFER_DELAY
) {
725 uint64_t transferred_bytes
= qemu_ftell(s
->file
) - initial_bytes
;
726 uint64_t time_spent
= current_time
- initial_time
;
727 double bandwidth
= transferred_bytes
/ time_spent
;
728 max_size
= bandwidth
* migrate_max_downtime() / 1000000;
730 s
->mbps
= time_spent
? (((double) transferred_bytes
* 8.0) /
731 ((double) time_spent
/ 1000.0)) / 1000.0 / 1000.0 : -1;
733 trace_migrate_transferred(transferred_bytes
, time_spent
,
734 bandwidth
, max_size
);
735 /* if we haven't sent anything, we don't want to recalculate
736 10000 is a small enough number for our purposes */
737 if (s
->dirty_bytes_rate
&& transferred_bytes
> 10000) {
738 s
->expected_downtime
= s
->dirty_bytes_rate
/ bandwidth
;
741 qemu_file_reset_rate_limit(s
->file
);
742 initial_time
= current_time
;
743 initial_bytes
= qemu_ftell(s
->file
);
745 if (qemu_file_rate_limit(s
->file
)) {
746 /* usleep expects microseconds */
747 g_usleep((initial_time
+ BUFFER_DELAY
- current_time
)*1000);
751 qemu_mutex_lock_iothread();
752 if (s
->state
== MIGRATION_STATUS_COMPLETED
) {
753 int64_t end_time
= qemu_clock_get_ms(QEMU_CLOCK_REALTIME
);
754 uint64_t transferred_bytes
= qemu_ftell(s
->file
);
755 s
->total_time
= end_time
- s
->total_time
;
756 s
->downtime
= end_time
- start_time
;
758 s
->mbps
= (((double) transferred_bytes
* 8.0) /
759 ((double) s
->total_time
)) / 1000;
761 runstate_set(RUN_STATE_POSTMIGRATE
);
763 if (old_vm_running
) {
767 qemu_bh_schedule(s
->cleanup_bh
);
768 qemu_mutex_unlock_iothread();
773 void migrate_fd_connect(MigrationState
*s
)
775 s
->state
= MIGRATION_STATUS_SETUP
;
776 trace_migrate_set_state(MIGRATION_STATUS_SETUP
);
778 /* This is a best 1st approximation. ns to ms */
779 s
->expected_downtime
= max_downtime
/1000000;
780 s
->cleanup_bh
= qemu_bh_new(migrate_fd_cleanup
, s
);
782 qemu_file_set_rate_limit(s
->file
,
783 s
->bandwidth_limit
/ XFER_LIMIT_RATIO
);
785 /* Notify before starting migration thread */
786 notifier_list_notify(&migration_state_notifiers
, s
);
788 migrate_compress_threads_create();
789 qemu_thread_create(&s
->thread
, "migration", migration_thread
, s
,
790 QEMU_THREAD_JOINABLE
);