]> git.proxmox.com Git - qemu.git/blame - migration.c
virtio-blk: cleanup: init and exit functions.
[qemu.git] / migration.c
CommitLineData
5bb7910a
AL
1/*
2 * QEMU live migration
3 *
4 * Copyright IBM, Corp. 2008
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
6b620ca3
PB
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.
5bb7910a
AL
14 */
15
16#include "qemu-common.h"
caf71f86 17#include "migration/migration.h"
83c9089e 18#include "monitor/monitor.h"
0d82d0e8 19#include "migration/qemu-file.h"
9c17d615 20#include "sysemu/sysemu.h"
737e150e 21#include "block/block.h"
1de7afc9 22#include "qemu/sockets.h"
caf71f86 23#include "migration/block.h"
766bd176 24#include "qemu/thread.h"
791e7c82 25#include "qmp-commands.h"
c09e5bb1 26#include "trace.h"
065e2813
AL
27
28//#define DEBUG_MIGRATION
29
30#ifdef DEBUG_MIGRATION
d0f2c4c6 31#define DPRINTF(fmt, ...) \
065e2813
AL
32 do { printf("migration: " fmt, ## __VA_ARGS__); } while (0)
33#else
d0f2c4c6 34#define DPRINTF(fmt, ...) \
065e2813
AL
35 do { } while (0)
36#endif
5bb7910a 37
7dc688ed
JQ
38enum {
39 MIG_STATE_ERROR,
40 MIG_STATE_SETUP,
41 MIG_STATE_CANCELLED,
42 MIG_STATE_ACTIVE,
43 MIG_STATE_COMPLETED,
44};
5bb7910a 45
d0ae46c1 46#define MAX_THROTTLE (32 << 20) /* Migration speed throttling */
5bb7910a 47
5b4e1eb7
JQ
48/* Amount of time to allocate to each "chunk" of bandwidth-throttled
49 * data. */
50#define BUFFER_DELAY 100
51#define XFER_LIMIT_RATIO (1000 / BUFFER_DELAY)
52
17ad9b35
OW
53/* Migration XBZRLE default cache size */
54#define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024)
55
99a0db9b
GH
56static NotifierList migration_state_notifiers =
57 NOTIFIER_LIST_INITIALIZER(migration_state_notifiers);
58
17549e84
JQ
59/* When we add fault tolerance, we could have several
60 migrations at once. For now we don't need to add
61 dynamic creation of migration */
62
859bc756 63MigrationState *migrate_get_current(void)
17549e84
JQ
64{
65 static MigrationState current_migration = {
66 .state = MIG_STATE_SETUP,
d0ae46c1 67 .bandwidth_limit = MAX_THROTTLE,
17ad9b35 68 .xbzrle_cache_size = DEFAULT_MIGRATE_CACHE_SIZE,
17549e84
JQ
69 };
70
71 return &current_migration;
72}
73
43eaae28 74void qemu_start_incoming_migration(const char *uri, Error **errp)
5bb7910a 75{
34c9dd8e
AL
76 const char *p;
77
78 if (strstart(uri, "tcp:", &p))
43eaae28 79 tcp_start_incoming_migration(p, errp);
065e2813
AL
80#if !defined(WIN32)
81 else if (strstart(uri, "exec:", &p))
43eaae28 82 exec_start_incoming_migration(p, errp);
4951f65b 83 else if (strstart(uri, "unix:", &p))
43eaae28 84 unix_start_incoming_migration(p, errp);
5ac1fad3 85 else if (strstart(uri, "fd:", &p))
43eaae28 86 fd_start_incoming_migration(p, errp);
065e2813 87#endif
8ca5e801 88 else {
312fd5f2 89 error_setg(errp, "unknown migration protocol: %s", uri);
8ca5e801 90 }
5bb7910a
AL
91}
92
82a4da79 93static void process_incoming_migration_co(void *opaque)
511c0231 94{
82a4da79 95 QEMUFile *f = opaque;
1c12e1f5
PB
96 int ret;
97
98 ret = qemu_loadvm_state(f);
99 qemu_fclose(f);
100 if (ret < 0) {
511c0231
JQ
101 fprintf(stderr, "load of migration failed\n");
102 exit(0);
103 }
104 qemu_announce_self();
105 DPRINTF("successfully loaded vm state\n");
106
901862cb 107 bdrv_clear_incoming_migration_all();
0f15423c
AL
108 /* Make sure all file formats flush their mutable metadata */
109 bdrv_invalidate_cache_all();
110
f5bbfba1 111 if (autostart) {
511c0231 112 vm_start();
f5bbfba1 113 } else {
29ed72f1 114 runstate_set(RUN_STATE_PAUSED);
f5bbfba1 115 }
511c0231
JQ
116}
117
82a4da79
PB
118void process_incoming_migration(QEMUFile *f)
119{
120 Coroutine *co = qemu_coroutine_create(process_incoming_migration_co);
121 int fd = qemu_get_fd(f);
122
123 assert(fd != -1);
124 socket_set_nonblock(fd);
82a4da79
PB
125 qemu_coroutine_enter(co, f);
126}
127
a0a3fd60
GC
128/* amount of nanoseconds we are willing to wait for migration to be down.
129 * the choice of nanoseconds is because it is the maximum resolution that
130 * get_clock() can achieve. It is an internal measure. All user-visible
131 * units must be in seconds */
132static uint64_t max_downtime = 30000000;
133
134uint64_t migrate_max_downtime(void)
135{
136 return max_downtime;
137}
138
bbf6da32
OW
139MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp)
140{
141 MigrationCapabilityStatusList *head = NULL;
142 MigrationCapabilityStatusList *caps;
143 MigrationState *s = migrate_get_current();
144 int i;
145
146 for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
147 if (head == NULL) {
148 head = g_malloc0(sizeof(*caps));
149 caps = head;
150 } else {
151 caps->next = g_malloc0(sizeof(*caps));
152 caps = caps->next;
153 }
154 caps->value =
155 g_malloc(sizeof(*caps->value));
156 caps->value->capability = i;
157 caps->value->state = s->enabled_capabilities[i];
158 }
159
160 return head;
161}
162
f36d55af
OW
163static void get_xbzrle_cache_stats(MigrationInfo *info)
164{
165 if (migrate_use_xbzrle()) {
166 info->has_xbzrle_cache = true;
167 info->xbzrle_cache = g_malloc0(sizeof(*info->xbzrle_cache));
168 info->xbzrle_cache->cache_size = migrate_xbzrle_cache_size();
169 info->xbzrle_cache->bytes = xbzrle_mig_bytes_transferred();
170 info->xbzrle_cache->pages = xbzrle_mig_pages_transferred();
171 info->xbzrle_cache->cache_miss = xbzrle_mig_pages_cache_miss();
172 info->xbzrle_cache->overflow = xbzrle_mig_pages_overflow();
173 }
174}
175
791e7c82 176MigrationInfo *qmp_query_migrate(Error **errp)
5bb7910a 177{
791e7c82 178 MigrationInfo *info = g_malloc0(sizeof(*info));
17549e84
JQ
179 MigrationState *s = migrate_get_current();
180
181 switch (s->state) {
182 case MIG_STATE_SETUP:
183 /* no migration has happened ever */
184 break;
185 case MIG_STATE_ACTIVE:
791e7c82
LC
186 info->has_status = true;
187 info->status = g_strdup("active");
7aa939af
JQ
188 info->has_total_time = true;
189 info->total_time = qemu_get_clock_ms(rt_clock)
190 - s->total_time;
2c52ddf1
JQ
191 info->has_expected_downtime = true;
192 info->expected_downtime = s->expected_downtime;
17549e84 193
791e7c82
LC
194 info->has_ram = true;
195 info->ram = g_malloc0(sizeof(*info->ram));
196 info->ram->transferred = ram_bytes_transferred();
197 info->ram->remaining = ram_bytes_remaining();
198 info->ram->total = ram_bytes_total();
004d4c10
OW
199 info->ram->duplicate = dup_mig_pages_transferred();
200 info->ram->normal = norm_mig_pages_transferred();
201 info->ram->normal_bytes = norm_mig_bytes_transferred();
8d017193
JQ
202 info->ram->dirty_pages_rate = s->dirty_pages_rate;
203
17549e84
JQ
204
205 if (blk_mig_active()) {
791e7c82
LC
206 info->has_disk = true;
207 info->disk = g_malloc0(sizeof(*info->disk));
208 info->disk->transferred = blk_mig_bytes_transferred();
209 info->disk->remaining = blk_mig_bytes_remaining();
210 info->disk->total = blk_mig_bytes_total();
ff8d81d8 211 }
f36d55af
OW
212
213 get_xbzrle_cache_stats(info);
17549e84
JQ
214 break;
215 case MIG_STATE_COMPLETED:
f36d55af
OW
216 get_xbzrle_cache_stats(info);
217
791e7c82
LC
218 info->has_status = true;
219 info->status = g_strdup("completed");
7aa939af 220 info->total_time = s->total_time;
9c5a9fcf
JQ
221 info->has_downtime = true;
222 info->downtime = s->downtime;
d5f8a570
JQ
223
224 info->has_ram = true;
225 info->ram = g_malloc0(sizeof(*info->ram));
226 info->ram->transferred = ram_bytes_transferred();
227 info->ram->remaining = 0;
228 info->ram->total = ram_bytes_total();
004d4c10
OW
229 info->ram->duplicate = dup_mig_pages_transferred();
230 info->ram->normal = norm_mig_pages_transferred();
231 info->ram->normal_bytes = norm_mig_bytes_transferred();
17549e84
JQ
232 break;
233 case MIG_STATE_ERROR:
791e7c82
LC
234 info->has_status = true;
235 info->status = g_strdup("failed");
17549e84
JQ
236 break;
237 case MIG_STATE_CANCELLED:
791e7c82
LC
238 info->has_status = true;
239 info->status = g_strdup("cancelled");
17549e84 240 break;
5bb7910a 241 }
791e7c82
LC
242
243 return info;
5bb7910a
AL
244}
245
00458433
OW
246void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
247 Error **errp)
248{
249 MigrationState *s = migrate_get_current();
250 MigrationCapabilityStatusList *cap;
251
252 if (s->state == MIG_STATE_ACTIVE) {
253 error_set(errp, QERR_MIGRATION_ACTIVE);
254 return;
255 }
256
257 for (cap = params; cap; cap = cap->next) {
258 s->enabled_capabilities[cap->value->capability] = cap->value->state;
259 }
260}
261
065e2813
AL
262/* shared migration helpers */
263
bb1fadc4 264static void migrate_fd_cleanup(void *opaque)
065e2813 265{
bb1fadc4
PB
266 MigrationState *s = opaque;
267
268 qemu_bh_delete(s->cleanup_bh);
269 s->cleanup_bh = NULL;
270
065e2813 271 if (s->file) {
d0f2c4c6 272 DPRINTF("closing file\n");
404a7c05
PB
273 qemu_mutex_unlock_iothread();
274 qemu_thread_join(&s->thread);
275 qemu_mutex_lock_iothread();
276
6f190a06
PB
277 qemu_fclose(s->file);
278 s->file = NULL;
065e2813
AL
279 }
280
a3fa1d78 281 assert(s->state != MIG_STATE_ACTIVE);
7a2c1721 282
a3fa1d78 283 if (s->state != MIG_STATE_COMPLETED) {
7a2c1721
PB
284 qemu_savevm_state_cancel();
285 }
a3fa1d78
PB
286
287 notifier_list_notify(&migration_state_notifiers, s);
065e2813
AL
288}
289
f4410a5d
PB
290static void migrate_finish_set_state(MigrationState *s, int new_state)
291{
292 if (__sync_val_compare_and_swap(&s->state, MIG_STATE_ACTIVE,
293 new_state) == new_state) {
294 trace_migrate_set_state(new_state);
295 }
296}
297
8b6b99b3 298void migrate_fd_error(MigrationState *s)
065e2813 299{
8b6b99b3 300 DPRINTF("setting error state\n");
bb1fadc4
PB
301 assert(s->file == NULL);
302 s->state = MIG_STATE_ERROR;
303 trace_migrate_set_state(MIG_STATE_ERROR);
304 notifier_list_notify(&migration_state_notifiers, s);
458cf28e
JQ
305}
306
0edda1c4 307static void migrate_fd_cancel(MigrationState *s)
065e2813 308{
d0f2c4c6 309 DPRINTF("cancelling migration\n");
065e2813 310
f4410a5d 311 migrate_finish_set_state(s, MIG_STATE_CANCELLED);
065e2813
AL
312}
313
99a0db9b
GH
314void add_migration_state_change_notifier(Notifier *notify)
315{
316 notifier_list_add(&migration_state_notifiers, notify);
317}
318
319void remove_migration_state_change_notifier(Notifier *notify)
320{
31552529 321 notifier_remove(notify);
99a0db9b
GH
322}
323
afe2df69
GH
324bool migration_is_active(MigrationState *s)
325{
326 return s->state == MIG_STATE_ACTIVE;
327}
328
7073693b 329bool migration_has_finished(MigrationState *s)
99a0db9b 330{
7073693b 331 return s->state == MIG_STATE_COMPLETED;
99a0db9b 332}
0edda1c4 333
afe2df69
GH
334bool migration_has_failed(MigrationState *s)
335{
336 return (s->state == MIG_STATE_CANCELLED ||
337 s->state == MIG_STATE_ERROR);
338}
339
6607ae23 340static MigrationState *migrate_init(const MigrationParams *params)
0edda1c4 341{
17549e84 342 MigrationState *s = migrate_get_current();
d0ae46c1 343 int64_t bandwidth_limit = s->bandwidth_limit;
bbf6da32 344 bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
17ad9b35 345 int64_t xbzrle_cache_size = s->xbzrle_cache_size;
bbf6da32
OW
346
347 memcpy(enabled_capabilities, s->enabled_capabilities,
348 sizeof(enabled_capabilities));
0edda1c4 349
17549e84 350 memset(s, 0, sizeof(*s));
d0ae46c1 351 s->bandwidth_limit = bandwidth_limit;
6607ae23 352 s->params = *params;
bbf6da32
OW
353 memcpy(s->enabled_capabilities, enabled_capabilities,
354 sizeof(enabled_capabilities));
17ad9b35 355 s->xbzrle_cache_size = xbzrle_cache_size;
1299c631 356
0edda1c4 357 s->bandwidth_limit = bandwidth_limit;
d5934dde 358 s->state = MIG_STATE_SETUP;
c09e5bb1 359 trace_migrate_set_state(MIG_STATE_SETUP);
0edda1c4 360
c09e5bb1 361 s->total_time = qemu_get_clock_ms(rt_clock);
0edda1c4
JQ
362 return s;
363}
cab30143 364
fa2756b7
AL
365static GSList *migration_blockers;
366
367void migrate_add_blocker(Error *reason)
368{
369 migration_blockers = g_slist_prepend(migration_blockers, reason);
370}
371
372void migrate_del_blocker(Error *reason)
373{
374 migration_blockers = g_slist_remove(migration_blockers, reason);
375}
376
e1c37d0e
LC
377void qmp_migrate(const char *uri, bool has_blk, bool blk,
378 bool has_inc, bool inc, bool has_detach, bool detach,
379 Error **errp)
cab30143 380{
be7059cd 381 Error *local_err = NULL;
17549e84 382 MigrationState *s = migrate_get_current();
6607ae23 383 MigrationParams params;
cab30143 384 const char *p;
cab30143 385
6607ae23
IY
386 params.blk = blk;
387 params.shared = inc;
388
17549e84 389 if (s->state == MIG_STATE_ACTIVE) {
e1c37d0e
LC
390 error_set(errp, QERR_MIGRATION_ACTIVE);
391 return;
cab30143
JQ
392 }
393
e1c37d0e
LC
394 if (qemu_savevm_state_blocked(errp)) {
395 return;
cab30143
JQ
396 }
397
fa2756b7 398 if (migration_blockers) {
e1c37d0e
LC
399 *errp = error_copy(migration_blockers->data);
400 return;
fa2756b7
AL
401 }
402
6607ae23 403 s = migrate_init(&params);
cab30143
JQ
404
405 if (strstart(uri, "tcp:", &p)) {
f37afb5a 406 tcp_start_outgoing_migration(s, p, &local_err);
cab30143
JQ
407#if !defined(WIN32)
408 } else if (strstart(uri, "exec:", &p)) {
f37afb5a 409 exec_start_outgoing_migration(s, p, &local_err);
cab30143 410 } else if (strstart(uri, "unix:", &p)) {
f37afb5a 411 unix_start_outgoing_migration(s, p, &local_err);
cab30143 412 } else if (strstart(uri, "fd:", &p)) {
f37afb5a 413 fd_start_outgoing_migration(s, p, &local_err);
cab30143 414#endif
99a0db9b 415 } else {
e1c37d0e
LC
416 error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol");
417 return;
cab30143
JQ
418 }
419
f37afb5a 420 if (local_err) {
342ab8d1 421 migrate_fd_error(s);
f37afb5a 422 error_propagate(errp, local_err);
e1c37d0e 423 return;
1299c631 424 }
cab30143
JQ
425}
426
6cdedb07 427void qmp_migrate_cancel(Error **errp)
cab30143 428{
17549e84 429 migrate_fd_cancel(migrate_get_current());
cab30143
JQ
430}
431
9e1ba4cc
OW
432void qmp_migrate_set_cache_size(int64_t value, Error **errp)
433{
434 MigrationState *s = migrate_get_current();
435
436 /* Check for truncation */
437 if (value != (size_t)value) {
438 error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
439 "exceeding address space");
440 return;
441 }
442
443 s->xbzrle_cache_size = xbzrle_cache_resize(value);
444}
445
446int64_t qmp_query_migrate_cache_size(Error **errp)
447{
448 return migrate_xbzrle_cache_size();
449}
450
3dc85383 451void qmp_migrate_set_speed(int64_t value, Error **errp)
cab30143 452{
cab30143
JQ
453 MigrationState *s;
454
3dc85383
LC
455 if (value < 0) {
456 value = 0;
99a0db9b 457 }
442773ce
PB
458 if (value > SIZE_MAX) {
459 value = SIZE_MAX;
460 }
cab30143 461
17549e84 462 s = migrate_get_current();
3dc85383 463 s->bandwidth_limit = value;
442773ce
PB
464 if (s->file) {
465 qemu_file_set_rate_limit(s->file, s->bandwidth_limit / XFER_LIMIT_RATIO);
466 }
cab30143
JQ
467}
468
4f0a993b 469void qmp_migrate_set_downtime(double value, Error **errp)
cab30143 470{
4f0a993b
LC
471 value *= 1e9;
472 value = MAX(0, MIN(UINT64_MAX, value));
473 max_downtime = (uint64_t)value;
99a0db9b 474}
17ad9b35
OW
475
476int migrate_use_xbzrle(void)
477{
478 MigrationState *s;
479
480 s = migrate_get_current();
481
482 return s->enabled_capabilities[MIGRATION_CAPABILITY_XBZRLE];
483}
484
485int64_t migrate_xbzrle_cache_size(void)
486{
487 MigrationState *s;
488
489 s = migrate_get_current();
490
491 return s->xbzrle_cache_size;
492}
0d82d0e8
JQ
493
494/* migration thread support */
495
5f496a1b 496static void *migration_thread(void *opaque)
0d82d0e8 497{
9848a404 498 MigrationState *s = opaque;
0d82d0e8 499 int64_t initial_time = qemu_get_clock_ms(rt_clock);
7161082c 500 int64_t sleep_time = 0;
be7172e2 501 int64_t initial_bytes = 0;
0d82d0e8 502 int64_t max_size = 0;
a3fa1d78
PB
503 int64_t start_time = initial_time;
504 bool old_vm_running = false;
76f5933a 505
76f5933a 506 DPRINTF("beginning savevm\n");
dba433c0 507 qemu_savevm_state_begin(s->file, &s->params);
0d82d0e8 508
dba433c0 509 while (s->state == MIG_STATE_ACTIVE) {
a3e879cd 510 int64_t current_time;
c369f40d 511 uint64_t pending_size;
0d82d0e8 512
a0ff044b 513 if (!qemu_file_rate_limit(s->file)) {
c369f40d
JQ
514 DPRINTF("iterate\n");
515 pending_size = qemu_savevm_state_pending(s->file, max_size);
516 DPRINTF("pending size %lu max %lu\n", pending_size, max_size);
b22ff1fb 517 if (pending_size && pending_size >= max_size) {
dba433c0 518 qemu_savevm_state_iterate(s->file);
c369f40d 519 } else {
c369f40d 520 DPRINTF("done iterating\n");
32c835ba 521 qemu_mutex_lock_iothread();
c369f40d
JQ
522 start_time = qemu_get_clock_ms(rt_clock);
523 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
a3fa1d78 524 old_vm_running = runstate_is_running();
891518ab 525 vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
442773ce 526 qemu_file_set_rate_limit(s->file, INT_MAX);
dba433c0 527 qemu_savevm_state_complete(s->file);
32c835ba 528 qemu_mutex_unlock_iothread();
059f896c
PB
529 if (!qemu_file_get_error(s->file)) {
530 migrate_finish_set_state(s, MIG_STATE_COMPLETED);
531 break;
532 }
c369f40d
JQ
533 }
534 }
f4410a5d 535
fd45ee2c
PB
536 if (qemu_file_get_error(s->file)) {
537 migrate_finish_set_state(s, MIG_STATE_ERROR);
538 break;
539 }
a3e879cd 540 current_time = qemu_get_clock_ms(rt_clock);
0d82d0e8 541 if (current_time >= initial_time + BUFFER_DELAY) {
be7172e2 542 uint64_t transferred_bytes = qemu_ftell(s->file) - initial_bytes;
7161082c 543 uint64_t time_spent = current_time - initial_time - sleep_time;
0d82d0e8
JQ
544 double bandwidth = transferred_bytes / time_spent;
545 max_size = bandwidth * migrate_max_downtime() / 1000000;
546
547 DPRINTF("transferred %" PRIu64 " time_spent %" PRIu64
548 " bandwidth %g max_size %" PRId64 "\n",
549 transferred_bytes, time_spent, bandwidth, max_size);
90f8ae72
JQ
550 /* if we haven't sent anything, we don't want to recalculate
551 10000 is a small enough number for our purposes */
552 if (s->dirty_bytes_rate && transferred_bytes > 10000) {
553 s->expected_downtime = s->dirty_bytes_rate / bandwidth;
554 }
0d82d0e8 555
1964a397 556 qemu_file_reset_rate_limit(s->file);
7161082c 557 sleep_time = 0;
0d82d0e8 558 initial_time = current_time;
be7172e2 559 initial_bytes = qemu_ftell(s->file);
0d82d0e8 560 }
a0ff044b 561 if (qemu_file_rate_limit(s->file)) {
0d82d0e8
JQ
562 /* usleep expects microseconds */
563 g_usleep((initial_time + BUFFER_DELAY - current_time)*1000);
7161082c 564 sleep_time += qemu_get_clock_ms(rt_clock) - current_time;
0d82d0e8 565 }
a3fa1d78
PB
566 }
567
f4410a5d 568 qemu_mutex_lock_iothread();
a3fa1d78
PB
569 if (s->state == MIG_STATE_COMPLETED) {
570 int64_t end_time = qemu_get_clock_ms(rt_clock);
571 s->total_time = end_time - s->total_time;
572 s->downtime = end_time - start_time;
573 runstate_set(RUN_STATE_POSTMIGRATE);
574 } else {
575 if (old_vm_running) {
a3fa1d78 576 vm_start();
dba433c0 577 }
0d82d0e8 578 }
bb1fadc4 579 qemu_bh_schedule(s->cleanup_bh);
dba433c0 580 qemu_mutex_unlock_iothread();
f4410a5d 581
0d82d0e8
JQ
582 return NULL;
583}
584
9848a404 585void migrate_fd_connect(MigrationState *s)
0d82d0e8 586{
9848a404 587 s->state = MIG_STATE_ACTIVE;
c09e5bb1
KS
588 trace_migrate_set_state(MIG_STATE_ACTIVE);
589
cc283e3b
JQ
590 /* This is a best 1st approximation. ns to ms */
591 s->expected_downtime = max_downtime/1000000;
bb1fadc4 592 s->cleanup_bh = qemu_bh_new(migrate_fd_cleanup, s);
0d82d0e8 593
442773ce
PB
594 qemu_file_set_rate_limit(s->file,
595 s->bandwidth_limit / XFER_LIMIT_RATIO);
596
5f496a1b 597 qemu_thread_create(&s->thread, migration_thread, s,
bb1fadc4 598 QEMU_THREAD_JOINABLE);
0d3b26f5 599 notifier_list_notify(&migration_state_notifiers, s);
0d82d0e8 600}