]> Git Repo - qemu.git/blob - migration.c
virtio-serial: make flow control explicit in virtio-console
[qemu.git] / 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 "migration/migration.h"
18 #include "monitor/monitor.h"
19 #include "migration/qemu-file.h"
20 #include "sysemu/sysemu.h"
21 #include "block/block.h"
22 #include "qemu/sockets.h"
23 #include "migration/block.h"
24 #include "qemu/thread.h"
25 #include "qmp-commands.h"
26
27 //#define DEBUG_MIGRATION
28
29 #ifdef DEBUG_MIGRATION
30 #define DPRINTF(fmt, ...) \
31     do { printf("migration: " fmt, ## __VA_ARGS__); } while (0)
32 #else
33 #define DPRINTF(fmt, ...) \
34     do { } while (0)
35 #endif
36
37 enum {
38     MIG_STATE_ERROR,
39     MIG_STATE_SETUP,
40     MIG_STATE_CANCELLED,
41     MIG_STATE_ACTIVE,
42     MIG_STATE_COMPLETED,
43 };
44
45 #define MAX_THROTTLE  (32 << 20)      /* Migration speed throttling */
46
47 /* Amount of time to allocate to each "chunk" of bandwidth-throttled
48  * data. */
49 #define BUFFER_DELAY     100
50 #define XFER_LIMIT_RATIO (1000 / BUFFER_DELAY)
51
52 /* Migration XBZRLE default cache size */
53 #define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024)
54
55 static NotifierList migration_state_notifiers =
56     NOTIFIER_LIST_INITIALIZER(migration_state_notifiers);
57
58 /* When we add fault tolerance, we could have several
59    migrations at once.  For now we don't need to add
60    dynamic creation of migration */
61
62 MigrationState *migrate_get_current(void)
63 {
64     static MigrationState current_migration = {
65         .state = MIG_STATE_SETUP,
66         .bandwidth_limit = MAX_THROTTLE,
67         .xbzrle_cache_size = DEFAULT_MIGRATE_CACHE_SIZE,
68     };
69
70     return &current_migration;
71 }
72
73 void qemu_start_incoming_migration(const char *uri, Error **errp)
74 {
75     const char *p;
76
77     if (strstart(uri, "tcp:", &p))
78         tcp_start_incoming_migration(p, errp);
79 #if !defined(WIN32)
80     else if (strstart(uri, "exec:", &p))
81         exec_start_incoming_migration(p, errp);
82     else if (strstart(uri, "unix:", &p))
83         unix_start_incoming_migration(p, errp);
84     else if (strstart(uri, "fd:", &p))
85         fd_start_incoming_migration(p, errp);
86 #endif
87     else {
88         error_setg(errp, "unknown migration protocol: %s", uri);
89     }
90 }
91
92 static void process_incoming_migration_co(void *opaque)
93 {
94     QEMUFile *f = opaque;
95     int ret;
96
97     ret = qemu_loadvm_state(f);
98     qemu_fclose(f);
99     if (ret < 0) {
100         fprintf(stderr, "load of migration failed\n");
101         exit(0);
102     }
103     qemu_announce_self();
104     DPRINTF("successfully loaded vm state\n");
105
106     bdrv_clear_incoming_migration_all();
107     /* Make sure all file formats flush their mutable metadata */
108     bdrv_invalidate_cache_all();
109
110     if (autostart) {
111         vm_start();
112     } else {
113         runstate_set(RUN_STATE_PAUSED);
114     }
115 }
116
117 void process_incoming_migration(QEMUFile *f)
118 {
119     Coroutine *co = qemu_coroutine_create(process_incoming_migration_co);
120     int fd = qemu_get_fd(f);
121
122     assert(fd != -1);
123     socket_set_nonblock(fd);
124     qemu_coroutine_enter(co, f);
125 }
126
127 /* amount of nanoseconds we are willing to wait for migration to be down.
128  * the choice of nanoseconds is because it is the maximum resolution that
129  * get_clock() can achieve. It is an internal measure. All user-visible
130  * units must be in seconds */
131 static uint64_t max_downtime = 30000000;
132
133 uint64_t migrate_max_downtime(void)
134 {
135     return max_downtime;
136 }
137
138 MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp)
139 {
140     MigrationCapabilityStatusList *head = NULL;
141     MigrationCapabilityStatusList *caps;
142     MigrationState *s = migrate_get_current();
143     int i;
144
145     for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
146         if (head == NULL) {
147             head = g_malloc0(sizeof(*caps));
148             caps = head;
149         } else {
150             caps->next = g_malloc0(sizeof(*caps));
151             caps = caps->next;
152         }
153         caps->value =
154             g_malloc(sizeof(*caps->value));
155         caps->value->capability = i;
156         caps->value->state = s->enabled_capabilities[i];
157     }
158
159     return head;
160 }
161
162 static void get_xbzrle_cache_stats(MigrationInfo *info)
163 {
164     if (migrate_use_xbzrle()) {
165         info->has_xbzrle_cache = true;
166         info->xbzrle_cache = g_malloc0(sizeof(*info->xbzrle_cache));
167         info->xbzrle_cache->cache_size = migrate_xbzrle_cache_size();
168         info->xbzrle_cache->bytes = xbzrle_mig_bytes_transferred();
169         info->xbzrle_cache->pages = xbzrle_mig_pages_transferred();
170         info->xbzrle_cache->cache_miss = xbzrle_mig_pages_cache_miss();
171         info->xbzrle_cache->overflow = xbzrle_mig_pages_overflow();
172     }
173 }
174
175 MigrationInfo *qmp_query_migrate(Error **errp)
176 {
177     MigrationInfo *info = g_malloc0(sizeof(*info));
178     MigrationState *s = migrate_get_current();
179
180     switch (s->state) {
181     case MIG_STATE_SETUP:
182         /* no migration has happened ever */
183         break;
184     case MIG_STATE_ACTIVE:
185         info->has_status = true;
186         info->status = g_strdup("active");
187         info->has_total_time = true;
188         info->total_time = qemu_get_clock_ms(rt_clock)
189             - s->total_time;
190         info->has_expected_downtime = true;
191         info->expected_downtime = s->expected_downtime;
192
193         info->has_ram = true;
194         info->ram = g_malloc0(sizeof(*info->ram));
195         info->ram->transferred = ram_bytes_transferred();
196         info->ram->remaining = ram_bytes_remaining();
197         info->ram->total = ram_bytes_total();
198         info->ram->duplicate = dup_mig_pages_transferred();
199         info->ram->normal = norm_mig_pages_transferred();
200         info->ram->normal_bytes = norm_mig_bytes_transferred();
201         info->ram->dirty_pages_rate = s->dirty_pages_rate;
202
203
204         if (blk_mig_active()) {
205             info->has_disk = true;
206             info->disk = g_malloc0(sizeof(*info->disk));
207             info->disk->transferred = blk_mig_bytes_transferred();
208             info->disk->remaining = blk_mig_bytes_remaining();
209             info->disk->total = blk_mig_bytes_total();
210         }
211
212         get_xbzrle_cache_stats(info);
213         break;
214     case MIG_STATE_COMPLETED:
215         get_xbzrle_cache_stats(info);
216
217         info->has_status = true;
218         info->status = g_strdup("completed");
219         info->total_time = s->total_time;
220         info->has_downtime = true;
221         info->downtime = s->downtime;
222
223         info->has_ram = true;
224         info->ram = g_malloc0(sizeof(*info->ram));
225         info->ram->transferred = ram_bytes_transferred();
226         info->ram->remaining = 0;
227         info->ram->total = ram_bytes_total();
228         info->ram->duplicate = dup_mig_pages_transferred();
229         info->ram->normal = norm_mig_pages_transferred();
230         info->ram->normal_bytes = norm_mig_bytes_transferred();
231         break;
232     case MIG_STATE_ERROR:
233         info->has_status = true;
234         info->status = g_strdup("failed");
235         break;
236     case MIG_STATE_CANCELLED:
237         info->has_status = true;
238         info->status = g_strdup("cancelled");
239         break;
240     }
241
242     return info;
243 }
244
245 void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
246                                   Error **errp)
247 {
248     MigrationState *s = migrate_get_current();
249     MigrationCapabilityStatusList *cap;
250
251     if (s->state == MIG_STATE_ACTIVE) {
252         error_set(errp, QERR_MIGRATION_ACTIVE);
253         return;
254     }
255
256     for (cap = params; cap; cap = cap->next) {
257         s->enabled_capabilities[cap->value->capability] = cap->value->state;
258     }
259 }
260
261 /* shared migration helpers */
262
263 static int migrate_fd_cleanup(MigrationState *s)
264 {
265     int ret = 0;
266
267     if (s->file) {
268         DPRINTF("closing file\n");
269         ret = qemu_fclose(s->file);
270         s->file = NULL;
271     }
272
273     assert(s->fd == -1);
274     return ret;
275 }
276
277 void migrate_fd_error(MigrationState *s)
278 {
279     DPRINTF("setting error state\n");
280     s->state = MIG_STATE_ERROR;
281     notifier_list_notify(&migration_state_notifiers, s);
282     migrate_fd_cleanup(s);
283 }
284
285 static void migrate_fd_completed(MigrationState *s)
286 {
287     DPRINTF("setting completed state\n");
288     if (migrate_fd_cleanup(s) < 0) {
289         s->state = MIG_STATE_ERROR;
290     } else {
291         s->state = MIG_STATE_COMPLETED;
292         runstate_set(RUN_STATE_POSTMIGRATE);
293     }
294     notifier_list_notify(&migration_state_notifiers, s);
295 }
296
297 static ssize_t migrate_fd_put_buffer(MigrationState *s, const void *data,
298                                      size_t size)
299 {
300     ssize_t ret;
301
302     if (s->state != MIG_STATE_ACTIVE) {
303         return -EIO;
304     }
305
306     do {
307         ret = s->write(s, data, size);
308     } while (ret == -1 && ((s->get_error(s)) == EINTR));
309
310     if (ret == -1)
311         ret = -(s->get_error(s));
312
313     return ret;
314 }
315
316 static void migrate_fd_cancel(MigrationState *s)
317 {
318     if (s->state != MIG_STATE_ACTIVE)
319         return;
320
321     DPRINTF("cancelling migration\n");
322
323     s->state = MIG_STATE_CANCELLED;
324     notifier_list_notify(&migration_state_notifiers, s);
325     qemu_savevm_state_cancel();
326
327     migrate_fd_cleanup(s);
328 }
329
330 int migrate_fd_close(MigrationState *s)
331 {
332     int rc = 0;
333     if (s->fd != -1) {
334         rc = s->close(s);
335         s->fd = -1;
336     }
337     return rc;
338 }
339
340 void add_migration_state_change_notifier(Notifier *notify)
341 {
342     notifier_list_add(&migration_state_notifiers, notify);
343 }
344
345 void remove_migration_state_change_notifier(Notifier *notify)
346 {
347     notifier_remove(notify);
348 }
349
350 bool migration_is_active(MigrationState *s)
351 {
352     return s->state == MIG_STATE_ACTIVE;
353 }
354
355 bool migration_has_finished(MigrationState *s)
356 {
357     return s->state == MIG_STATE_COMPLETED;
358 }
359
360 bool migration_has_failed(MigrationState *s)
361 {
362     return (s->state == MIG_STATE_CANCELLED ||
363             s->state == MIG_STATE_ERROR);
364 }
365
366 static MigrationState *migrate_init(const MigrationParams *params)
367 {
368     MigrationState *s = migrate_get_current();
369     int64_t bandwidth_limit = s->bandwidth_limit;
370     bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
371     int64_t xbzrle_cache_size = s->xbzrle_cache_size;
372
373     memcpy(enabled_capabilities, s->enabled_capabilities,
374            sizeof(enabled_capabilities));
375
376     memset(s, 0, sizeof(*s));
377     s->bandwidth_limit = bandwidth_limit;
378     s->params = *params;
379     memcpy(s->enabled_capabilities, enabled_capabilities,
380            sizeof(enabled_capabilities));
381     s->xbzrle_cache_size = xbzrle_cache_size;
382
383     s->bandwidth_limit = bandwidth_limit;
384     s->state = MIG_STATE_SETUP;
385     s->total_time = qemu_get_clock_ms(rt_clock);
386
387     return s;
388 }
389
390 static GSList *migration_blockers;
391
392 void migrate_add_blocker(Error *reason)
393 {
394     migration_blockers = g_slist_prepend(migration_blockers, reason);
395 }
396
397 void migrate_del_blocker(Error *reason)
398 {
399     migration_blockers = g_slist_remove(migration_blockers, reason);
400 }
401
402 void qmp_migrate(const char *uri, bool has_blk, bool blk,
403                  bool has_inc, bool inc, bool has_detach, bool detach,
404                  Error **errp)
405 {
406     Error *local_err = NULL;
407     MigrationState *s = migrate_get_current();
408     MigrationParams params;
409     const char *p;
410
411     params.blk = blk;
412     params.shared = inc;
413
414     if (s->state == MIG_STATE_ACTIVE) {
415         error_set(errp, QERR_MIGRATION_ACTIVE);
416         return;
417     }
418
419     if (qemu_savevm_state_blocked(errp)) {
420         return;
421     }
422
423     if (migration_blockers) {
424         *errp = error_copy(migration_blockers->data);
425         return;
426     }
427
428     s = migrate_init(&params);
429
430     if (strstart(uri, "tcp:", &p)) {
431         tcp_start_outgoing_migration(s, p, &local_err);
432 #if !defined(WIN32)
433     } else if (strstart(uri, "exec:", &p)) {
434         exec_start_outgoing_migration(s, p, &local_err);
435     } else if (strstart(uri, "unix:", &p)) {
436         unix_start_outgoing_migration(s, p, &local_err);
437     } else if (strstart(uri, "fd:", &p)) {
438         fd_start_outgoing_migration(s, p, &local_err);
439 #endif
440     } else {
441         error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol");
442         return;
443     }
444
445     if (local_err) {
446         migrate_fd_error(s);
447         error_propagate(errp, local_err);
448         return;
449     }
450 }
451
452 void qmp_migrate_cancel(Error **errp)
453 {
454     migrate_fd_cancel(migrate_get_current());
455 }
456
457 void qmp_migrate_set_cache_size(int64_t value, Error **errp)
458 {
459     MigrationState *s = migrate_get_current();
460
461     /* Check for truncation */
462     if (value != (size_t)value) {
463         error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
464                   "exceeding address space");
465         return;
466     }
467
468     s->xbzrle_cache_size = xbzrle_cache_resize(value);
469 }
470
471 int64_t qmp_query_migrate_cache_size(Error **errp)
472 {
473     return migrate_xbzrle_cache_size();
474 }
475
476 void qmp_migrate_set_speed(int64_t value, Error **errp)
477 {
478     MigrationState *s;
479
480     if (value < 0) {
481         value = 0;
482     }
483
484     s = migrate_get_current();
485     s->bandwidth_limit = value;
486     qemu_file_set_rate_limit(s->file, s->bandwidth_limit);
487 }
488
489 void qmp_migrate_set_downtime(double value, Error **errp)
490 {
491     value *= 1e9;
492     value = MAX(0, MIN(UINT64_MAX, value));
493     max_downtime = (uint64_t)value;
494 }
495
496 int migrate_use_xbzrle(void)
497 {
498     MigrationState *s;
499
500     s = migrate_get_current();
501
502     return s->enabled_capabilities[MIGRATION_CAPABILITY_XBZRLE];
503 }
504
505 int64_t migrate_xbzrle_cache_size(void)
506 {
507     MigrationState *s;
508
509     s = migrate_get_current();
510
511     return s->xbzrle_cache_size;
512 }
513
514 /* migration thread support */
515
516
517 static ssize_t buffered_flush(MigrationState *s)
518 {
519     size_t offset = 0;
520     ssize_t ret = 0;
521
522     DPRINTF("flushing %zu byte(s) of data\n", s->buffer_size);
523
524     while (s->bytes_xfer < s->xfer_limit && offset < s->buffer_size) {
525         size_t to_send = MIN(s->buffer_size - offset, s->xfer_limit - s->bytes_xfer);
526         ret = migrate_fd_put_buffer(s, s->buffer + offset, to_send);
527         if (ret <= 0) {
528             DPRINTF("error flushing data, %zd\n", ret);
529             break;
530         } else {
531             DPRINTF("flushed %zd byte(s)\n", ret);
532             offset += ret;
533             s->bytes_xfer += ret;
534         }
535     }
536
537     DPRINTF("flushed %zu of %zu byte(s)\n", offset, s->buffer_size);
538     memmove(s->buffer, s->buffer + offset, s->buffer_size - offset);
539     s->buffer_size -= offset;
540
541     if (ret < 0) {
542         return ret;
543     }
544     return offset;
545 }
546
547 static int buffered_put_buffer(void *opaque, const uint8_t *buf,
548                                int64_t pos, int size)
549 {
550     MigrationState *s = opaque;
551     ssize_t error;
552
553     DPRINTF("putting %d bytes at %" PRId64 "\n", size, pos);
554
555     error = qemu_file_get_error(s->file);
556     if (error) {
557         DPRINTF("flush when error, bailing: %s\n", strerror(-error));
558         return error;
559     }
560
561     if (size <= 0) {
562         return size;
563     }
564
565     if (size > (s->buffer_capacity - s->buffer_size)) {
566         DPRINTF("increasing buffer capacity from %zu by %zu\n",
567                 s->buffer_capacity, size + 1024);
568
569         s->buffer_capacity += size + 1024;
570
571         s->buffer = g_realloc(s->buffer, s->buffer_capacity);
572     }
573
574     memcpy(s->buffer + s->buffer_size, buf, size);
575     s->buffer_size += size;
576
577     return size;
578 }
579
580 static int buffered_close(void *opaque)
581 {
582     MigrationState *s = opaque;
583     ssize_t ret = 0;
584     int ret2;
585
586     DPRINTF("closing\n");
587
588     s->xfer_limit = INT_MAX;
589     while (!qemu_file_get_error(s->file) && s->buffer_size) {
590         ret = buffered_flush(s);
591         if (ret < 0) {
592             break;
593         }
594     }
595
596     ret2 = migrate_fd_close(s);
597     if (ret >= 0) {
598         ret = ret2;
599     }
600     s->complete = true;
601     return ret;
602 }
603
604 static int buffered_get_fd(void *opaque)
605 {
606     MigrationState *s = opaque;
607
608     return s->fd;
609 }
610
611 /*
612  * The meaning of the return values is:
613  *   0: We can continue sending
614  *   1: Time to stop
615  *   negative: There has been an error
616  */
617 static int buffered_rate_limit(void *opaque)
618 {
619     MigrationState *s = opaque;
620     int ret;
621
622     ret = qemu_file_get_error(s->file);
623     if (ret) {
624         return ret;
625     }
626
627     if (s->bytes_xfer >= s->xfer_limit) {
628         return 1;
629     }
630
631     return 0;
632 }
633
634 static int64_t buffered_set_rate_limit(void *opaque, int64_t new_rate)
635 {
636     MigrationState *s = opaque;
637     if (qemu_file_get_error(s->file)) {
638         goto out;
639     }
640     if (new_rate > SIZE_MAX) {
641         new_rate = SIZE_MAX;
642     }
643
644     s->xfer_limit = new_rate / XFER_LIMIT_RATIO;
645
646 out:
647     return s->xfer_limit;
648 }
649
650 static int64_t buffered_get_rate_limit(void *opaque)
651 {
652     MigrationState *s = opaque;
653
654     return s->xfer_limit;
655 }
656
657 static void *buffered_file_thread(void *opaque)
658 {
659     MigrationState *s = opaque;
660     int64_t initial_time = qemu_get_clock_ms(rt_clock);
661     int64_t sleep_time = 0;
662     int64_t max_size = 0;
663     bool last_round = false;
664     int ret;
665
666     qemu_mutex_lock_iothread();
667     DPRINTF("beginning savevm\n");
668     ret = qemu_savevm_state_begin(s->file, &s->params);
669     if (ret < 0) {
670         DPRINTF("failed, %d\n", ret);
671         qemu_mutex_unlock_iothread();
672         goto out;
673     }
674     qemu_mutex_unlock_iothread();
675
676     while (true) {
677         int64_t current_time;
678         uint64_t pending_size;
679
680         qemu_mutex_lock_iothread();
681         if (s->state != MIG_STATE_ACTIVE) {
682             DPRINTF("put_ready returning because of non-active state\n");
683             qemu_mutex_unlock_iothread();
684             break;
685         }
686         if (s->complete) {
687             qemu_mutex_unlock_iothread();
688             break;
689         }
690         if (s->bytes_xfer < s->xfer_limit) {
691             DPRINTF("iterate\n");
692             pending_size = qemu_savevm_state_pending(s->file, max_size);
693             DPRINTF("pending size %lu max %lu\n", pending_size, max_size);
694             if (pending_size && pending_size >= max_size) {
695                 ret = qemu_savevm_state_iterate(s->file);
696                 if (ret < 0) {
697                     qemu_mutex_unlock_iothread();
698                     break;
699                 }
700             } else {
701                 int old_vm_running = runstate_is_running();
702                 int64_t start_time, end_time;
703
704                 DPRINTF("done iterating\n");
705                 start_time = qemu_get_clock_ms(rt_clock);
706                 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
707                 if (old_vm_running) {
708                     vm_stop(RUN_STATE_FINISH_MIGRATE);
709                 } else {
710                     vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
711                 }
712                 ret = qemu_savevm_state_complete(s->file);
713                 if (ret < 0) {
714                     qemu_mutex_unlock_iothread();
715                     break;
716                 } else {
717                     migrate_fd_completed(s);
718                 }
719                 end_time = qemu_get_clock_ms(rt_clock);
720                 s->total_time = end_time - s->total_time;
721                 s->downtime = end_time - start_time;
722                 if (s->state != MIG_STATE_COMPLETED) {
723                     if (old_vm_running) {
724                         vm_start();
725                     }
726                 }
727                 last_round = true;
728             }
729         }
730         qemu_mutex_unlock_iothread();
731         current_time = qemu_get_clock_ms(rt_clock);
732         if (current_time >= initial_time + BUFFER_DELAY) {
733             uint64_t transferred_bytes = s->bytes_xfer;
734             uint64_t time_spent = current_time - initial_time - sleep_time;
735             double bandwidth = transferred_bytes / time_spent;
736             max_size = bandwidth * migrate_max_downtime() / 1000000;
737
738             DPRINTF("transferred %" PRIu64 " time_spent %" PRIu64
739                     " bandwidth %g max_size %" PRId64 "\n",
740                     transferred_bytes, time_spent, bandwidth, max_size);
741             /* if we haven't sent anything, we don't want to recalculate
742                10000 is a small enough number for our purposes */
743             if (s->dirty_bytes_rate && transferred_bytes > 10000) {
744                 s->expected_downtime = s->dirty_bytes_rate / bandwidth;
745             }
746
747             s->bytes_xfer = 0;
748             sleep_time = 0;
749             initial_time = current_time;
750         }
751         if (!last_round && (s->bytes_xfer >= s->xfer_limit)) {
752             /* usleep expects microseconds */
753             g_usleep((initial_time + BUFFER_DELAY - current_time)*1000);
754             sleep_time += qemu_get_clock_ms(rt_clock) - current_time;
755         }
756         ret = buffered_flush(s);
757         if (ret < 0) {
758             break;
759         }
760     }
761
762 out:
763     if (ret < 0) {
764         migrate_fd_error(s);
765     }
766     g_free(s->buffer);
767     return NULL;
768 }
769
770 static const QEMUFileOps buffered_file_ops = {
771     .get_fd =         buffered_get_fd,
772     .put_buffer =     buffered_put_buffer,
773     .close =          buffered_close,
774     .rate_limit =     buffered_rate_limit,
775     .get_rate_limit = buffered_get_rate_limit,
776     .set_rate_limit = buffered_set_rate_limit,
777 };
778
779 void migrate_fd_connect(MigrationState *s)
780 {
781     s->state = MIG_STATE_ACTIVE;
782     s->bytes_xfer = 0;
783     s->buffer = NULL;
784     s->buffer_size = 0;
785     s->buffer_capacity = 0;
786     /* This is a best 1st approximation. ns to ms */
787     s->expected_downtime = max_downtime/1000000;
788
789     s->xfer_limit = s->bandwidth_limit / XFER_LIMIT_RATIO;
790     s->complete = false;
791
792     s->file = qemu_fopen_ops(s, &buffered_file_ops);
793
794     qemu_thread_create(&s->thread, buffered_file_thread, s,
795                        QEMU_THREAD_DETACHED);
796     notifier_list_notify(&migration_state_notifiers, s);
797 }
This page took 0.067234 seconds and 4 git commands to generate.