]> Git Repo - qemu.git/blob - migration/migration.c
Merge remote-tracking branch 'remotes/amit/tags/vser-for-2.3-3' into staging
[qemu.git] / migration / migration.c
1 /*
2  * QEMU live migration
3  *
4  * Copyright IBM, Corp. 2008
5  *
6  * Authors:
7  *  Anthony Liguori   <[email protected]>
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  *
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.
14  */
15
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"
27 #include "trace.h"
28
29 #define MAX_THROTTLE  (32 << 20)      /* Migration speed throttling */
30
31 /* Amount of time to allocate to each "chunk" of bandwidth-throttled
32  * data. */
33 #define BUFFER_DELAY     100
34 #define XFER_LIMIT_RATIO (1000 / BUFFER_DELAY)
35
36 /* Migration XBZRLE default cache size */
37 #define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024)
38
39 static NotifierList migration_state_notifiers =
40     NOTIFIER_LIST_INITIALIZER(migration_state_notifiers);
41
42 static bool deferred_incoming;
43
44 /* When we add fault tolerance, we could have several
45    migrations at once.  For now we don't need to add
46    dynamic creation of migration */
47
48 MigrationState *migrate_get_current(void)
49 {
50     static MigrationState current_migration = {
51         .state = MIGRATION_STATUS_NONE,
52         .bandwidth_limit = MAX_THROTTLE,
53         .xbzrle_cache_size = DEFAULT_MIGRATE_CACHE_SIZE,
54         .mbps = -1,
55     };
56
57     return &current_migration;
58 }
59
60 /*
61  * Called on -incoming with a defer: uri.
62  * The migration can be started later after any parameters have been
63  * changed.
64  */
65 static void deferred_incoming_migration(Error **errp)
66 {
67     if (deferred_incoming) {
68         error_setg(errp, "Incoming migration already deferred");
69     }
70     deferred_incoming = true;
71 }
72
73 void qemu_start_incoming_migration(const char *uri, Error **errp)
74 {
75     const char *p;
76
77     if (!strcmp(uri, "defer")) {
78         deferred_incoming_migration(errp);
79     } else if (strstart(uri, "tcp:", &p)) {
80         tcp_start_incoming_migration(p, errp);
81 #ifdef CONFIG_RDMA
82     } else if (strstart(uri, "rdma:", &p)) {
83         rdma_start_incoming_migration(p, errp);
84 #endif
85 #if !defined(WIN32)
86     } else if (strstart(uri, "exec:", &p)) {
87         exec_start_incoming_migration(p, errp);
88     } else if (strstart(uri, "unix:", &p)) {
89         unix_start_incoming_migration(p, errp);
90     } else if (strstart(uri, "fd:", &p)) {
91         fd_start_incoming_migration(p, errp);
92 #endif
93     } else {
94         error_setg(errp, "unknown migration protocol: %s", uri);
95     }
96 }
97
98 static void process_incoming_migration_co(void *opaque)
99 {
100     QEMUFile *f = opaque;
101     Error *local_err = NULL;
102     int ret;
103
104     ret = qemu_loadvm_state(f);
105     qemu_fclose(f);
106     free_xbzrle_decoded_buf();
107     if (ret < 0) {
108         error_report("load of migration failed: %s", strerror(-ret));
109         exit(EXIT_FAILURE);
110     }
111     qemu_announce_self();
112
113     /* Make sure all file formats flush their mutable metadata */
114     bdrv_invalidate_cache_all(&local_err);
115     if (local_err) {
116         error_report_err(local_err);
117         exit(EXIT_FAILURE);
118     }
119
120     if (autostart) {
121         vm_start();
122     } else {
123         runstate_set(RUN_STATE_PAUSED);
124     }
125 }
126
127 void process_incoming_migration(QEMUFile *f)
128 {
129     Coroutine *co = qemu_coroutine_create(process_incoming_migration_co);
130     int fd = qemu_get_fd(f);
131
132     assert(fd != -1);
133     qemu_set_nonblock(fd);
134     qemu_coroutine_enter(co, f);
135 }
136
137 /* amount of nanoseconds we are willing to wait for migration to be down.
138  * the choice of nanoseconds is because it is the maximum resolution that
139  * get_clock() can achieve. It is an internal measure. All user-visible
140  * units must be in seconds */
141 static uint64_t max_downtime = 300000000;
142
143 uint64_t migrate_max_downtime(void)
144 {
145     return max_downtime;
146 }
147
148 MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp)
149 {
150     MigrationCapabilityStatusList *head = NULL;
151     MigrationCapabilityStatusList *caps;
152     MigrationState *s = migrate_get_current();
153     int i;
154
155     caps = NULL; /* silence compiler warning */
156     for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
157         if (head == NULL) {
158             head = g_malloc0(sizeof(*caps));
159             caps = head;
160         } else {
161             caps->next = g_malloc0(sizeof(*caps));
162             caps = caps->next;
163         }
164         caps->value =
165             g_malloc(sizeof(*caps->value));
166         caps->value->capability = i;
167         caps->value->state = s->enabled_capabilities[i];
168     }
169
170     return head;
171 }
172
173 static void get_xbzrle_cache_stats(MigrationInfo *info)
174 {
175     if (migrate_use_xbzrle()) {
176         info->has_xbzrle_cache = true;
177         info->xbzrle_cache = g_malloc0(sizeof(*info->xbzrle_cache));
178         info->xbzrle_cache->cache_size = migrate_xbzrle_cache_size();
179         info->xbzrle_cache->bytes = xbzrle_mig_bytes_transferred();
180         info->xbzrle_cache->pages = xbzrle_mig_pages_transferred();
181         info->xbzrle_cache->cache_miss = xbzrle_mig_pages_cache_miss();
182         info->xbzrle_cache->cache_miss_rate = xbzrle_mig_cache_miss_rate();
183         info->xbzrle_cache->overflow = xbzrle_mig_pages_overflow();
184     }
185 }
186
187 MigrationInfo *qmp_query_migrate(Error **errp)
188 {
189     MigrationInfo *info = g_malloc0(sizeof(*info));
190     MigrationState *s = migrate_get_current();
191
192     switch (s->state) {
193     case MIGRATION_STATUS_NONE:
194         /* no migration has happened ever */
195         break;
196     case MIGRATION_STATUS_SETUP:
197         info->has_status = true;
198         info->has_total_time = false;
199         break;
200     case MIGRATION_STATUS_ACTIVE:
201     case MIGRATION_STATUS_CANCELLING:
202         info->has_status = true;
203         info->has_total_time = true;
204         info->total_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME)
205             - s->total_time;
206         info->has_expected_downtime = true;
207         info->expected_downtime = s->expected_downtime;
208         info->has_setup_time = true;
209         info->setup_time = s->setup_time;
210
211         info->has_ram = true;
212         info->ram = g_malloc0(sizeof(*info->ram));
213         info->ram->transferred = ram_bytes_transferred();
214         info->ram->remaining = ram_bytes_remaining();
215         info->ram->total = ram_bytes_total();
216         info->ram->duplicate = dup_mig_pages_transferred();
217         info->ram->skipped = skipped_mig_pages_transferred();
218         info->ram->normal = norm_mig_pages_transferred();
219         info->ram->normal_bytes = norm_mig_bytes_transferred();
220         info->ram->dirty_pages_rate = s->dirty_pages_rate;
221         info->ram->mbps = s->mbps;
222         info->ram->dirty_sync_count = s->dirty_sync_count;
223
224         if (blk_mig_active()) {
225             info->has_disk = true;
226             info->disk = g_malloc0(sizeof(*info->disk));
227             info->disk->transferred = blk_mig_bytes_transferred();
228             info->disk->remaining = blk_mig_bytes_remaining();
229             info->disk->total = blk_mig_bytes_total();
230         }
231
232         get_xbzrle_cache_stats(info);
233         break;
234     case MIGRATION_STATUS_COMPLETED:
235         get_xbzrle_cache_stats(info);
236
237         info->has_status = true;
238         info->has_total_time = true;
239         info->total_time = s->total_time;
240         info->has_downtime = true;
241         info->downtime = s->downtime;
242         info->has_setup_time = true;
243         info->setup_time = s->setup_time;
244
245         info->has_ram = true;
246         info->ram = g_malloc0(sizeof(*info->ram));
247         info->ram->transferred = ram_bytes_transferred();
248         info->ram->remaining = 0;
249         info->ram->total = ram_bytes_total();
250         info->ram->duplicate = dup_mig_pages_transferred();
251         info->ram->skipped = skipped_mig_pages_transferred();
252         info->ram->normal = norm_mig_pages_transferred();
253         info->ram->normal_bytes = norm_mig_bytes_transferred();
254         info->ram->mbps = s->mbps;
255         info->ram->dirty_sync_count = s->dirty_sync_count;
256         break;
257     case MIGRATION_STATUS_FAILED:
258         info->has_status = true;
259         break;
260     case MIGRATION_STATUS_CANCELLED:
261         info->has_status = true;
262         break;
263     }
264     info->status = s->state;
265
266     return info;
267 }
268
269 void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
270                                   Error **errp)
271 {
272     MigrationState *s = migrate_get_current();
273     MigrationCapabilityStatusList *cap;
274
275     if (s->state == MIGRATION_STATUS_ACTIVE ||
276         s->state == MIGRATION_STATUS_SETUP) {
277         error_set(errp, QERR_MIGRATION_ACTIVE);
278         return;
279     }
280
281     for (cap = params; cap; cap = cap->next) {
282         s->enabled_capabilities[cap->value->capability] = cap->value->state;
283     }
284 }
285
286 /* shared migration helpers */
287
288 static void migrate_set_state(MigrationState *s, int old_state, int new_state)
289 {
290     if (atomic_cmpxchg(&s->state, old_state, new_state) == new_state) {
291         trace_migrate_set_state(new_state);
292     }
293 }
294
295 static void migrate_fd_cleanup(void *opaque)
296 {
297     MigrationState *s = opaque;
298
299     qemu_bh_delete(s->cleanup_bh);
300     s->cleanup_bh = NULL;
301
302     if (s->file) {
303         trace_migrate_fd_cleanup();
304         qemu_mutex_unlock_iothread();
305         qemu_thread_join(&s->thread);
306         qemu_mutex_lock_iothread();
307
308         qemu_fclose(s->file);
309         s->file = NULL;
310     }
311
312     assert(s->state != MIGRATION_STATUS_ACTIVE);
313
314     if (s->state != MIGRATION_STATUS_COMPLETED) {
315         qemu_savevm_state_cancel();
316         if (s->state == MIGRATION_STATUS_CANCELLING) {
317             migrate_set_state(s, MIGRATION_STATUS_CANCELLING,
318                               MIGRATION_STATUS_CANCELLED);
319         }
320     }
321
322     notifier_list_notify(&migration_state_notifiers, s);
323 }
324
325 void migrate_fd_error(MigrationState *s)
326 {
327     trace_migrate_fd_error();
328     assert(s->file == NULL);
329     s->state = MIGRATION_STATUS_FAILED;
330     trace_migrate_set_state(MIGRATION_STATUS_FAILED);
331     notifier_list_notify(&migration_state_notifiers, s);
332 }
333
334 static void migrate_fd_cancel(MigrationState *s)
335 {
336     int old_state ;
337     QEMUFile *f = migrate_get_current()->file;
338     trace_migrate_fd_cancel();
339
340     do {
341         old_state = s->state;
342         if (old_state != MIGRATION_STATUS_SETUP &&
343             old_state != MIGRATION_STATUS_ACTIVE) {
344             break;
345         }
346         migrate_set_state(s, old_state, MIGRATION_STATUS_CANCELLING);
347     } while (s->state != MIGRATION_STATUS_CANCELLING);
348
349     /*
350      * If we're unlucky the migration code might be stuck somewhere in a
351      * send/write while the network has failed and is waiting to timeout;
352      * if we've got shutdown(2) available then we can force it to quit.
353      * The outgoing qemu file gets closed in migrate_fd_cleanup that is
354      * called in a bh, so there is no race against this cancel.
355      */
356     if (s->state == MIGRATION_STATUS_CANCELLING && f) {
357         qemu_file_shutdown(f);
358     }
359 }
360
361 void add_migration_state_change_notifier(Notifier *notify)
362 {
363     notifier_list_add(&migration_state_notifiers, notify);
364 }
365
366 void remove_migration_state_change_notifier(Notifier *notify)
367 {
368     notifier_remove(notify);
369 }
370
371 bool migration_in_setup(MigrationState *s)
372 {
373     return s->state == MIGRATION_STATUS_SETUP;
374 }
375
376 bool migration_has_finished(MigrationState *s)
377 {
378     return s->state == MIGRATION_STATUS_COMPLETED;
379 }
380
381 bool migration_has_failed(MigrationState *s)
382 {
383     return (s->state == MIGRATION_STATUS_CANCELLED ||
384             s->state == MIGRATION_STATUS_FAILED);
385 }
386
387 static MigrationState *migrate_init(const MigrationParams *params)
388 {
389     MigrationState *s = migrate_get_current();
390     int64_t bandwidth_limit = s->bandwidth_limit;
391     bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
392     int64_t xbzrle_cache_size = s->xbzrle_cache_size;
393
394     memcpy(enabled_capabilities, s->enabled_capabilities,
395            sizeof(enabled_capabilities));
396
397     memset(s, 0, sizeof(*s));
398     s->params = *params;
399     memcpy(s->enabled_capabilities, enabled_capabilities,
400            sizeof(enabled_capabilities));
401     s->xbzrle_cache_size = xbzrle_cache_size;
402
403     s->bandwidth_limit = bandwidth_limit;
404     s->state = MIGRATION_STATUS_SETUP;
405     trace_migrate_set_state(MIGRATION_STATUS_SETUP);
406
407     s->total_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
408     return s;
409 }
410
411 static GSList *migration_blockers;
412
413 void migrate_add_blocker(Error *reason)
414 {
415     migration_blockers = g_slist_prepend(migration_blockers, reason);
416 }
417
418 void migrate_del_blocker(Error *reason)
419 {
420     migration_blockers = g_slist_remove(migration_blockers, reason);
421 }
422
423 void qmp_migrate_incoming(const char *uri, Error **errp)
424 {
425     Error *local_err = NULL;
426     static bool once = true;
427
428     if (!deferred_incoming) {
429         error_setg(errp, "For use with '-incoming defer'");
430         return;
431     }
432     if (!once) {
433         error_setg(errp, "The incoming migration has already been started");
434     }
435
436     qemu_start_incoming_migration(uri, &local_err);
437
438     if (local_err) {
439         error_propagate(errp, local_err);
440         return;
441     }
442
443     once = false;
444 }
445
446 void qmp_migrate(const char *uri, bool has_blk, bool blk,
447                  bool has_inc, bool inc, bool has_detach, bool detach,
448                  Error **errp)
449 {
450     Error *local_err = NULL;
451     MigrationState *s = migrate_get_current();
452     MigrationParams params;
453     const char *p;
454
455     params.blk = has_blk && blk;
456     params.shared = has_inc && inc;
457
458     if (s->state == MIGRATION_STATUS_ACTIVE ||
459         s->state == MIGRATION_STATUS_SETUP ||
460         s->state == MIGRATION_STATUS_CANCELLING) {
461         error_set(errp, QERR_MIGRATION_ACTIVE);
462         return;
463     }
464
465     if (runstate_check(RUN_STATE_INMIGRATE)) {
466         error_setg(errp, "Guest is waiting for an incoming migration");
467         return;
468     }
469
470     if (qemu_savevm_state_blocked(errp)) {
471         return;
472     }
473
474     if (migration_blockers) {
475         *errp = error_copy(migration_blockers->data);
476         return;
477     }
478
479     s = migrate_init(&params);
480
481     if (strstart(uri, "tcp:", &p)) {
482         tcp_start_outgoing_migration(s, p, &local_err);
483 #ifdef CONFIG_RDMA
484     } else if (strstart(uri, "rdma:", &p)) {
485         rdma_start_outgoing_migration(s, p, &local_err);
486 #endif
487 #if !defined(WIN32)
488     } else if (strstart(uri, "exec:", &p)) {
489         exec_start_outgoing_migration(s, p, &local_err);
490     } else if (strstart(uri, "unix:", &p)) {
491         unix_start_outgoing_migration(s, p, &local_err);
492     } else if (strstart(uri, "fd:", &p)) {
493         fd_start_outgoing_migration(s, p, &local_err);
494 #endif
495     } else {
496         error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol");
497         s->state = MIGRATION_STATUS_FAILED;
498         return;
499     }
500
501     if (local_err) {
502         migrate_fd_error(s);
503         error_propagate(errp, local_err);
504         return;
505     }
506 }
507
508 void qmp_migrate_cancel(Error **errp)
509 {
510     migrate_fd_cancel(migrate_get_current());
511 }
512
513 void qmp_migrate_set_cache_size(int64_t value, Error **errp)
514 {
515     MigrationState *s = migrate_get_current();
516     int64_t new_size;
517
518     /* Check for truncation */
519     if (value != (size_t)value) {
520         error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
521                   "exceeding address space");
522         return;
523     }
524
525     /* Cache should not be larger than guest ram size */
526     if (value > ram_bytes_total()) {
527         error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
528                   "exceeds guest ram size ");
529         return;
530     }
531
532     new_size = xbzrle_cache_resize(value);
533     if (new_size < 0) {
534         error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
535                   "is smaller than page size");
536         return;
537     }
538
539     s->xbzrle_cache_size = new_size;
540 }
541
542 int64_t qmp_query_migrate_cache_size(Error **errp)
543 {
544     return migrate_xbzrle_cache_size();
545 }
546
547 void qmp_migrate_set_speed(int64_t value, Error **errp)
548 {
549     MigrationState *s;
550
551     if (value < 0) {
552         value = 0;
553     }
554     if (value > SIZE_MAX) {
555         value = SIZE_MAX;
556     }
557
558     s = migrate_get_current();
559     s->bandwidth_limit = value;
560     if (s->file) {
561         qemu_file_set_rate_limit(s->file, s->bandwidth_limit / XFER_LIMIT_RATIO);
562     }
563 }
564
565 void qmp_migrate_set_downtime(double value, Error **errp)
566 {
567     value *= 1e9;
568     value = MAX(0, MIN(UINT64_MAX, value));
569     max_downtime = (uint64_t)value;
570 }
571
572 bool migrate_auto_converge(void)
573 {
574     MigrationState *s;
575
576     s = migrate_get_current();
577
578     return s->enabled_capabilities[MIGRATION_CAPABILITY_AUTO_CONVERGE];
579 }
580
581 bool migrate_zero_blocks(void)
582 {
583     MigrationState *s;
584
585     s = migrate_get_current();
586
587     return s->enabled_capabilities[MIGRATION_CAPABILITY_ZERO_BLOCKS];
588 }
589
590 int migrate_use_xbzrle(void)
591 {
592     MigrationState *s;
593
594     s = migrate_get_current();
595
596     return s->enabled_capabilities[MIGRATION_CAPABILITY_XBZRLE];
597 }
598
599 int64_t migrate_xbzrle_cache_size(void)
600 {
601     MigrationState *s;
602
603     s = migrate_get_current();
604
605     return s->xbzrle_cache_size;
606 }
607
608 /* migration thread support */
609
610 static void *migration_thread(void *opaque)
611 {
612     MigrationState *s = opaque;
613     int64_t initial_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
614     int64_t setup_start = qemu_clock_get_ms(QEMU_CLOCK_HOST);
615     int64_t initial_bytes = 0;
616     int64_t max_size = 0;
617     int64_t start_time = initial_time;
618     bool old_vm_running = false;
619
620     qemu_savevm_state_begin(s->file, &s->params);
621
622     s->setup_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) - setup_start;
623     migrate_set_state(s, MIGRATION_STATUS_SETUP, MIGRATION_STATUS_ACTIVE);
624
625     while (s->state == MIGRATION_STATUS_ACTIVE) {
626         int64_t current_time;
627         uint64_t pending_size;
628
629         if (!qemu_file_rate_limit(s->file)) {
630             pending_size = qemu_savevm_state_pending(s->file, max_size);
631             trace_migrate_pending(pending_size, max_size);
632             if (pending_size && pending_size >= max_size) {
633                 qemu_savevm_state_iterate(s->file);
634             } else {
635                 int ret;
636
637                 qemu_mutex_lock_iothread();
638                 start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
639                 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
640                 old_vm_running = runstate_is_running();
641
642                 ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
643                 if (ret >= 0) {
644                     qemu_file_set_rate_limit(s->file, INT64_MAX);
645                     qemu_savevm_state_complete(s->file);
646                 }
647                 qemu_mutex_unlock_iothread();
648
649                 if (ret < 0) {
650                     migrate_set_state(s, MIGRATION_STATUS_ACTIVE,
651                                       MIGRATION_STATUS_FAILED);
652                     break;
653                 }
654
655                 if (!qemu_file_get_error(s->file)) {
656                     migrate_set_state(s, MIGRATION_STATUS_ACTIVE,
657                                       MIGRATION_STATUS_COMPLETED);
658                     break;
659                 }
660             }
661         }
662
663         if (qemu_file_get_error(s->file)) {
664             migrate_set_state(s, MIGRATION_STATUS_ACTIVE,
665                               MIGRATION_STATUS_FAILED);
666             break;
667         }
668         current_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
669         if (current_time >= initial_time + BUFFER_DELAY) {
670             uint64_t transferred_bytes = qemu_ftell(s->file) - initial_bytes;
671             uint64_t time_spent = current_time - initial_time;
672             double bandwidth = transferred_bytes / time_spent;
673             max_size = bandwidth * migrate_max_downtime() / 1000000;
674
675             s->mbps = time_spent ? (((double) transferred_bytes * 8.0) /
676                     ((double) time_spent / 1000.0)) / 1000.0 / 1000.0 : -1;
677
678             trace_migrate_transferred(transferred_bytes, time_spent,
679                                       bandwidth, max_size);
680             /* if we haven't sent anything, we don't want to recalculate
681                10000 is a small enough number for our purposes */
682             if (s->dirty_bytes_rate && transferred_bytes > 10000) {
683                 s->expected_downtime = s->dirty_bytes_rate / bandwidth;
684             }
685
686             qemu_file_reset_rate_limit(s->file);
687             initial_time = current_time;
688             initial_bytes = qemu_ftell(s->file);
689         }
690         if (qemu_file_rate_limit(s->file)) {
691             /* usleep expects microseconds */
692             g_usleep((initial_time + BUFFER_DELAY - current_time)*1000);
693         }
694     }
695
696     qemu_mutex_lock_iothread();
697     if (s->state == MIGRATION_STATUS_COMPLETED) {
698         int64_t end_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
699         uint64_t transferred_bytes = qemu_ftell(s->file);
700         s->total_time = end_time - s->total_time;
701         s->downtime = end_time - start_time;
702         if (s->total_time) {
703             s->mbps = (((double) transferred_bytes * 8.0) /
704                        ((double) s->total_time)) / 1000;
705         }
706         runstate_set(RUN_STATE_POSTMIGRATE);
707     } else {
708         if (old_vm_running) {
709             vm_start();
710         }
711     }
712     qemu_bh_schedule(s->cleanup_bh);
713     qemu_mutex_unlock_iothread();
714
715     return NULL;
716 }
717
718 void migrate_fd_connect(MigrationState *s)
719 {
720     s->state = MIGRATION_STATUS_SETUP;
721     trace_migrate_set_state(MIGRATION_STATUS_SETUP);
722
723     /* This is a best 1st approximation. ns to ms */
724     s->expected_downtime = max_downtime/1000000;
725     s->cleanup_bh = qemu_bh_new(migrate_fd_cleanup, s);
726
727     qemu_file_set_rate_limit(s->file,
728                              s->bandwidth_limit / XFER_LIMIT_RATIO);
729
730     /* Notify before starting migration thread */
731     notifier_list_notify(&migration_state_notifiers, s);
732
733     qemu_thread_create(&s->thread, "migration", migration_thread, s,
734                        QEMU_THREAD_JOINABLE);
735 }
This page took 0.065747 seconds and 4 git commands to generate.