]> git.proxmox.com Git - qemu.git/blame - migration.c
Update version for qemu-1.5.0-rc0
[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 101 fprintf(stderr, "load of migration failed\n");
4aead692 102 exit(EXIT_FAILURE);
511c0231
JQ
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);
f9e8cacc 124 qemu_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 199 info->ram->duplicate = dup_mig_pages_transferred();
f1c72795 200 info->ram->skipped = skipped_mig_pages_transferred();
004d4c10
OW
201 info->ram->normal = norm_mig_pages_transferred();
202 info->ram->normal_bytes = norm_mig_bytes_transferred();
8d017193
JQ
203 info->ram->dirty_pages_rate = s->dirty_pages_rate;
204
17549e84 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 229 info->ram->duplicate = dup_mig_pages_transferred();
f1c72795 230 info->ram->skipped = skipped_mig_pages_transferred();
004d4c10
OW
231 info->ram->normal = norm_mig_pages_transferred();
232 info->ram->normal_bytes = norm_mig_bytes_transferred();
17549e84
JQ
233 break;
234 case MIG_STATE_ERROR:
791e7c82
LC
235 info->has_status = true;
236 info->status = g_strdup("failed");
17549e84
JQ
237 break;
238 case MIG_STATE_CANCELLED:
791e7c82
LC
239 info->has_status = true;
240 info->status = g_strdup("cancelled");
17549e84 241 break;
5bb7910a 242 }
791e7c82
LC
243
244 return info;
5bb7910a
AL
245}
246
00458433
OW
247void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
248 Error **errp)
249{
250 MigrationState *s = migrate_get_current();
251 MigrationCapabilityStatusList *cap;
252
253 if (s->state == MIG_STATE_ACTIVE) {
254 error_set(errp, QERR_MIGRATION_ACTIVE);
255 return;
256 }
257
258 for (cap = params; cap; cap = cap->next) {
259 s->enabled_capabilities[cap->value->capability] = cap->value->state;
260 }
261}
262
065e2813
AL
263/* shared migration helpers */
264
bb1fadc4 265static void migrate_fd_cleanup(void *opaque)
065e2813 266{
bb1fadc4
PB
267 MigrationState *s = opaque;
268
269 qemu_bh_delete(s->cleanup_bh);
270 s->cleanup_bh = NULL;
271
065e2813 272 if (s->file) {
d0f2c4c6 273 DPRINTF("closing file\n");
404a7c05
PB
274 qemu_mutex_unlock_iothread();
275 qemu_thread_join(&s->thread);
276 qemu_mutex_lock_iothread();
277
6f190a06
PB
278 qemu_fclose(s->file);
279 s->file = NULL;
065e2813
AL
280 }
281
a3fa1d78 282 assert(s->state != MIG_STATE_ACTIVE);
7a2c1721 283
a3fa1d78 284 if (s->state != MIG_STATE_COMPLETED) {
7a2c1721
PB
285 qemu_savevm_state_cancel();
286 }
a3fa1d78
PB
287
288 notifier_list_notify(&migration_state_notifiers, s);
065e2813
AL
289}
290
f4410a5d
PB
291static void migrate_finish_set_state(MigrationState *s, int new_state)
292{
293 if (__sync_val_compare_and_swap(&s->state, MIG_STATE_ACTIVE,
294 new_state) == new_state) {
295 trace_migrate_set_state(new_state);
296 }
297}
298
8b6b99b3 299void migrate_fd_error(MigrationState *s)
065e2813 300{
8b6b99b3 301 DPRINTF("setting error state\n");
bb1fadc4
PB
302 assert(s->file == NULL);
303 s->state = MIG_STATE_ERROR;
304 trace_migrate_set_state(MIG_STATE_ERROR);
305 notifier_list_notify(&migration_state_notifiers, s);
458cf28e
JQ
306}
307
0edda1c4 308static void migrate_fd_cancel(MigrationState *s)
065e2813 309{
d0f2c4c6 310 DPRINTF("cancelling migration\n");
065e2813 311
f4410a5d 312 migrate_finish_set_state(s, MIG_STATE_CANCELLED);
065e2813
AL
313}
314
99a0db9b
GH
315void add_migration_state_change_notifier(Notifier *notify)
316{
317 notifier_list_add(&migration_state_notifiers, notify);
318}
319
320void remove_migration_state_change_notifier(Notifier *notify)
321{
31552529 322 notifier_remove(notify);
99a0db9b
GH
323}
324
afe2df69
GH
325bool migration_is_active(MigrationState *s)
326{
327 return s->state == MIG_STATE_ACTIVE;
328}
329
7073693b 330bool migration_has_finished(MigrationState *s)
99a0db9b 331{
7073693b 332 return s->state == MIG_STATE_COMPLETED;
99a0db9b 333}
0edda1c4 334
afe2df69
GH
335bool migration_has_failed(MigrationState *s)
336{
337 return (s->state == MIG_STATE_CANCELLED ||
338 s->state == MIG_STATE_ERROR);
339}
340
6607ae23 341static MigrationState *migrate_init(const MigrationParams *params)
0edda1c4 342{
17549e84 343 MigrationState *s = migrate_get_current();
d0ae46c1 344 int64_t bandwidth_limit = s->bandwidth_limit;
bbf6da32 345 bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
17ad9b35 346 int64_t xbzrle_cache_size = s->xbzrle_cache_size;
bbf6da32
OW
347
348 memcpy(enabled_capabilities, s->enabled_capabilities,
349 sizeof(enabled_capabilities));
0edda1c4 350
17549e84 351 memset(s, 0, sizeof(*s));
d0ae46c1 352 s->bandwidth_limit = bandwidth_limit;
6607ae23 353 s->params = *params;
bbf6da32
OW
354 memcpy(s->enabled_capabilities, enabled_capabilities,
355 sizeof(enabled_capabilities));
17ad9b35 356 s->xbzrle_cache_size = xbzrle_cache_size;
1299c631 357
0edda1c4 358 s->bandwidth_limit = bandwidth_limit;
d5934dde 359 s->state = MIG_STATE_SETUP;
c09e5bb1 360 trace_migrate_set_state(MIG_STATE_SETUP);
0edda1c4 361
c09e5bb1 362 s->total_time = qemu_get_clock_ms(rt_clock);
0edda1c4
JQ
363 return s;
364}
cab30143 365
fa2756b7
AL
366static GSList *migration_blockers;
367
368void migrate_add_blocker(Error *reason)
369{
370 migration_blockers = g_slist_prepend(migration_blockers, reason);
371}
372
373void migrate_del_blocker(Error *reason)
374{
375 migration_blockers = g_slist_remove(migration_blockers, reason);
376}
377
e1c37d0e
LC
378void qmp_migrate(const char *uri, bool has_blk, bool blk,
379 bool has_inc, bool inc, bool has_detach, bool detach,
380 Error **errp)
cab30143 381{
be7059cd 382 Error *local_err = NULL;
17549e84 383 MigrationState *s = migrate_get_current();
6607ae23 384 MigrationParams params;
cab30143 385 const char *p;
cab30143 386
6607ae23
IY
387 params.blk = blk;
388 params.shared = inc;
389
17549e84 390 if (s->state == MIG_STATE_ACTIVE) {
e1c37d0e
LC
391 error_set(errp, QERR_MIGRATION_ACTIVE);
392 return;
cab30143
JQ
393 }
394
e1c37d0e
LC
395 if (qemu_savevm_state_blocked(errp)) {
396 return;
cab30143
JQ
397 }
398
fa2756b7 399 if (migration_blockers) {
e1c37d0e
LC
400 *errp = error_copy(migration_blockers->data);
401 return;
fa2756b7
AL
402 }
403
6607ae23 404 s = migrate_init(&params);
cab30143
JQ
405
406 if (strstart(uri, "tcp:", &p)) {
f37afb5a 407 tcp_start_outgoing_migration(s, p, &local_err);
cab30143
JQ
408#if !defined(WIN32)
409 } else if (strstart(uri, "exec:", &p)) {
f37afb5a 410 exec_start_outgoing_migration(s, p, &local_err);
cab30143 411 } else if (strstart(uri, "unix:", &p)) {
f37afb5a 412 unix_start_outgoing_migration(s, p, &local_err);
cab30143 413 } else if (strstart(uri, "fd:", &p)) {
f37afb5a 414 fd_start_outgoing_migration(s, p, &local_err);
cab30143 415#endif
99a0db9b 416 } else {
e1c37d0e
LC
417 error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol");
418 return;
cab30143
JQ
419 }
420
f37afb5a 421 if (local_err) {
342ab8d1 422 migrate_fd_error(s);
f37afb5a 423 error_propagate(errp, local_err);
e1c37d0e 424 return;
1299c631 425 }
cab30143
JQ
426}
427
6cdedb07 428void qmp_migrate_cancel(Error **errp)
cab30143 429{
17549e84 430 migrate_fd_cancel(migrate_get_current());
cab30143
JQ
431}
432
9e1ba4cc
OW
433void qmp_migrate_set_cache_size(int64_t value, Error **errp)
434{
435 MigrationState *s = migrate_get_current();
436
437 /* Check for truncation */
438 if (value != (size_t)value) {
439 error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
440 "exceeding address space");
441 return;
442 }
443
444 s->xbzrle_cache_size = xbzrle_cache_resize(value);
445}
446
447int64_t qmp_query_migrate_cache_size(Error **errp)
448{
449 return migrate_xbzrle_cache_size();
450}
451
3dc85383 452void qmp_migrate_set_speed(int64_t value, Error **errp)
cab30143 453{
cab30143
JQ
454 MigrationState *s;
455
3dc85383
LC
456 if (value < 0) {
457 value = 0;
99a0db9b 458 }
442773ce
PB
459 if (value > SIZE_MAX) {
460 value = SIZE_MAX;
461 }
cab30143 462
17549e84 463 s = migrate_get_current();
3dc85383 464 s->bandwidth_limit = value;
442773ce
PB
465 if (s->file) {
466 qemu_file_set_rate_limit(s->file, s->bandwidth_limit / XFER_LIMIT_RATIO);
467 }
cab30143
JQ
468}
469
4f0a993b 470void qmp_migrate_set_downtime(double value, Error **errp)
cab30143 471{
4f0a993b
LC
472 value *= 1e9;
473 value = MAX(0, MIN(UINT64_MAX, value));
474 max_downtime = (uint64_t)value;
99a0db9b 475}
17ad9b35
OW
476
477int migrate_use_xbzrle(void)
478{
479 MigrationState *s;
480
481 s = migrate_get_current();
482
483 return s->enabled_capabilities[MIGRATION_CAPABILITY_XBZRLE];
484}
485
486int64_t migrate_xbzrle_cache_size(void)
487{
488 MigrationState *s;
489
490 s = migrate_get_current();
491
492 return s->xbzrle_cache_size;
493}
0d82d0e8
JQ
494
495/* migration thread support */
496
5f496a1b 497static void *migration_thread(void *opaque)
0d82d0e8 498{
9848a404 499 MigrationState *s = opaque;
0d82d0e8 500 int64_t initial_time = qemu_get_clock_ms(rt_clock);
7161082c 501 int64_t sleep_time = 0;
be7172e2 502 int64_t initial_bytes = 0;
0d82d0e8 503 int64_t max_size = 0;
a3fa1d78
PB
504 int64_t start_time = initial_time;
505 bool old_vm_running = false;
76f5933a 506
76f5933a 507 DPRINTF("beginning savevm\n");
dba433c0 508 qemu_savevm_state_begin(s->file, &s->params);
0d82d0e8 509
dba433c0 510 while (s->state == MIG_STATE_ACTIVE) {
a3e879cd 511 int64_t current_time;
c369f40d 512 uint64_t pending_size;
0d82d0e8 513
a0ff044b 514 if (!qemu_file_rate_limit(s->file)) {
c369f40d
JQ
515 DPRINTF("iterate\n");
516 pending_size = qemu_savevm_state_pending(s->file, max_size);
517 DPRINTF("pending size %lu max %lu\n", pending_size, max_size);
b22ff1fb 518 if (pending_size && pending_size >= max_size) {
dba433c0 519 qemu_savevm_state_iterate(s->file);
c369f40d 520 } else {
c369f40d 521 DPRINTF("done iterating\n");
32c835ba 522 qemu_mutex_lock_iothread();
c369f40d
JQ
523 start_time = qemu_get_clock_ms(rt_clock);
524 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
a3fa1d78 525 old_vm_running = runstate_is_running();
891518ab 526 vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
442773ce 527 qemu_file_set_rate_limit(s->file, INT_MAX);
dba433c0 528 qemu_savevm_state_complete(s->file);
32c835ba 529 qemu_mutex_unlock_iothread();
059f896c
PB
530 if (!qemu_file_get_error(s->file)) {
531 migrate_finish_set_state(s, MIG_STATE_COMPLETED);
532 break;
533 }
c369f40d
JQ
534 }
535 }
f4410a5d 536
fd45ee2c
PB
537 if (qemu_file_get_error(s->file)) {
538 migrate_finish_set_state(s, MIG_STATE_ERROR);
539 break;
540 }
a3e879cd 541 current_time = qemu_get_clock_ms(rt_clock);
0d82d0e8 542 if (current_time >= initial_time + BUFFER_DELAY) {
be7172e2 543 uint64_t transferred_bytes = qemu_ftell(s->file) - initial_bytes;
7161082c 544 uint64_t time_spent = current_time - initial_time - sleep_time;
0d82d0e8
JQ
545 double bandwidth = transferred_bytes / time_spent;
546 max_size = bandwidth * migrate_max_downtime() / 1000000;
547
548 DPRINTF("transferred %" PRIu64 " time_spent %" PRIu64
549 " bandwidth %g max_size %" PRId64 "\n",
550 transferred_bytes, time_spent, bandwidth, max_size);
90f8ae72
JQ
551 /* if we haven't sent anything, we don't want to recalculate
552 10000 is a small enough number for our purposes */
553 if (s->dirty_bytes_rate && transferred_bytes > 10000) {
554 s->expected_downtime = s->dirty_bytes_rate / bandwidth;
555 }
0d82d0e8 556
1964a397 557 qemu_file_reset_rate_limit(s->file);
7161082c 558 sleep_time = 0;
0d82d0e8 559 initial_time = current_time;
be7172e2 560 initial_bytes = qemu_ftell(s->file);
0d82d0e8 561 }
a0ff044b 562 if (qemu_file_rate_limit(s->file)) {
0d82d0e8
JQ
563 /* usleep expects microseconds */
564 g_usleep((initial_time + BUFFER_DELAY - current_time)*1000);
7161082c 565 sleep_time += qemu_get_clock_ms(rt_clock) - current_time;
0d82d0e8 566 }
a3fa1d78
PB
567 }
568
f4410a5d 569 qemu_mutex_lock_iothread();
a3fa1d78
PB
570 if (s->state == MIG_STATE_COMPLETED) {
571 int64_t end_time = qemu_get_clock_ms(rt_clock);
572 s->total_time = end_time - s->total_time;
573 s->downtime = end_time - start_time;
574 runstate_set(RUN_STATE_POSTMIGRATE);
575 } else {
576 if (old_vm_running) {
a3fa1d78 577 vm_start();
dba433c0 578 }
0d82d0e8 579 }
bb1fadc4 580 qemu_bh_schedule(s->cleanup_bh);
dba433c0 581 qemu_mutex_unlock_iothread();
f4410a5d 582
0d82d0e8
JQ
583 return NULL;
584}
585
9848a404 586void migrate_fd_connect(MigrationState *s)
0d82d0e8 587{
9848a404 588 s->state = MIG_STATE_ACTIVE;
c09e5bb1
KS
589 trace_migrate_set_state(MIG_STATE_ACTIVE);
590
cc283e3b
JQ
591 /* This is a best 1st approximation. ns to ms */
592 s->expected_downtime = max_downtime/1000000;
bb1fadc4 593 s->cleanup_bh = qemu_bh_new(migrate_fd_cleanup, s);
0d82d0e8 594
442773ce
PB
595 qemu_file_set_rate_limit(s->file,
596 s->bandwidth_limit / XFER_LIMIT_RATIO);
597
5f496a1b 598 qemu_thread_create(&s->thread, migration_thread, s,
bb1fadc4 599 QEMU_THREAD_JOINABLE);
0d3b26f5 600 notifier_list_notify(&migration_state_notifiers, s);
0d82d0e8 601}