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