]> git.proxmox.com Git - qemu.git/blob - migration.c
migration: use qemu_file_set_error
[qemu.git] / migration.c
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 *
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 void 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 if (ret < 0 && s->state == MIG_STATE_ACTIVE) {
275 s->state = MIG_STATE_ERROR;
276 }
277
278 if (s->state != MIG_STATE_ACTIVE) {
279 qemu_savevm_state_cancel();
280 }
281 }
282
283 void migrate_fd_error(MigrationState *s)
284 {
285 DPRINTF("setting error state\n");
286 s->state = MIG_STATE_ERROR;
287 notifier_list_notify(&migration_state_notifiers, s);
288 migrate_fd_cleanup(s);
289 }
290
291 static void migrate_fd_completed(MigrationState *s)
292 {
293 DPRINTF("setting completed state\n");
294 migrate_fd_cleanup(s);
295 if (s->state == MIG_STATE_ACTIVE) {
296 s->state = MIG_STATE_COMPLETED;
297 runstate_set(RUN_STATE_POSTMIGRATE);
298 }
299 notifier_list_notify(&migration_state_notifiers, s);
300 }
301
302 static ssize_t migrate_fd_put_buffer(MigrationState *s, const void *data,
303 size_t size)
304 {
305 ssize_t ret;
306
307 if (s->state != MIG_STATE_ACTIVE) {
308 return -EIO;
309 }
310
311 do {
312 ret = s->write(s, data, size);
313 } while (ret == -1 && ((s->get_error(s)) == EINTR));
314
315 if (ret == -1)
316 ret = -(s->get_error(s));
317
318 return ret;
319 }
320
321 static void migrate_fd_cancel(MigrationState *s)
322 {
323 if (s->state != MIG_STATE_ACTIVE)
324 return;
325
326 DPRINTF("cancelling migration\n");
327
328 s->state = MIG_STATE_CANCELLED;
329 notifier_list_notify(&migration_state_notifiers, s);
330
331 migrate_fd_cleanup(s);
332 }
333
334 int migrate_fd_close(MigrationState *s)
335 {
336 int rc = 0;
337 if (s->fd != -1) {
338 rc = s->close(s);
339 s->fd = -1;
340 }
341 return rc;
342 }
343
344 void add_migration_state_change_notifier(Notifier *notify)
345 {
346 notifier_list_add(&migration_state_notifiers, notify);
347 }
348
349 void remove_migration_state_change_notifier(Notifier *notify)
350 {
351 notifier_remove(notify);
352 }
353
354 bool migration_is_active(MigrationState *s)
355 {
356 return s->state == MIG_STATE_ACTIVE;
357 }
358
359 bool migration_has_finished(MigrationState *s)
360 {
361 return s->state == MIG_STATE_COMPLETED;
362 }
363
364 bool migration_has_failed(MigrationState *s)
365 {
366 return (s->state == MIG_STATE_CANCELLED ||
367 s->state == MIG_STATE_ERROR);
368 }
369
370 static MigrationState *migrate_init(const MigrationParams *params)
371 {
372 MigrationState *s = migrate_get_current();
373 int64_t bandwidth_limit = s->bandwidth_limit;
374 bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
375 int64_t xbzrle_cache_size = s->xbzrle_cache_size;
376
377 memcpy(enabled_capabilities, s->enabled_capabilities,
378 sizeof(enabled_capabilities));
379
380 memset(s, 0, sizeof(*s));
381 s->bandwidth_limit = bandwidth_limit;
382 s->params = *params;
383 memcpy(s->enabled_capabilities, enabled_capabilities,
384 sizeof(enabled_capabilities));
385 s->xbzrle_cache_size = xbzrle_cache_size;
386
387 s->bandwidth_limit = bandwidth_limit;
388 s->state = MIG_STATE_SETUP;
389 s->total_time = qemu_get_clock_ms(rt_clock);
390
391 return s;
392 }
393
394 static GSList *migration_blockers;
395
396 void migrate_add_blocker(Error *reason)
397 {
398 migration_blockers = g_slist_prepend(migration_blockers, reason);
399 }
400
401 void migrate_del_blocker(Error *reason)
402 {
403 migration_blockers = g_slist_remove(migration_blockers, reason);
404 }
405
406 void qmp_migrate(const char *uri, bool has_blk, bool blk,
407 bool has_inc, bool inc, bool has_detach, bool detach,
408 Error **errp)
409 {
410 Error *local_err = NULL;
411 MigrationState *s = migrate_get_current();
412 MigrationParams params;
413 const char *p;
414
415 params.blk = blk;
416 params.shared = inc;
417
418 if (s->state == MIG_STATE_ACTIVE) {
419 error_set(errp, QERR_MIGRATION_ACTIVE);
420 return;
421 }
422
423 if (qemu_savevm_state_blocked(errp)) {
424 return;
425 }
426
427 if (migration_blockers) {
428 *errp = error_copy(migration_blockers->data);
429 return;
430 }
431
432 s = migrate_init(&params);
433
434 if (strstart(uri, "tcp:", &p)) {
435 tcp_start_outgoing_migration(s, p, &local_err);
436 #if !defined(WIN32)
437 } else if (strstart(uri, "exec:", &p)) {
438 exec_start_outgoing_migration(s, p, &local_err);
439 } else if (strstart(uri, "unix:", &p)) {
440 unix_start_outgoing_migration(s, p, &local_err);
441 } else if (strstart(uri, "fd:", &p)) {
442 fd_start_outgoing_migration(s, p, &local_err);
443 #endif
444 } else {
445 error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol");
446 return;
447 }
448
449 if (local_err) {
450 migrate_fd_error(s);
451 error_propagate(errp, local_err);
452 return;
453 }
454 }
455
456 void qmp_migrate_cancel(Error **errp)
457 {
458 migrate_fd_cancel(migrate_get_current());
459 }
460
461 void qmp_migrate_set_cache_size(int64_t value, Error **errp)
462 {
463 MigrationState *s = migrate_get_current();
464
465 /* Check for truncation */
466 if (value != (size_t)value) {
467 error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
468 "exceeding address space");
469 return;
470 }
471
472 s->xbzrle_cache_size = xbzrle_cache_resize(value);
473 }
474
475 int64_t qmp_query_migrate_cache_size(Error **errp)
476 {
477 return migrate_xbzrle_cache_size();
478 }
479
480 void qmp_migrate_set_speed(int64_t value, Error **errp)
481 {
482 MigrationState *s;
483
484 if (value < 0) {
485 value = 0;
486 }
487
488 s = migrate_get_current();
489 s->bandwidth_limit = value;
490 qemu_file_set_rate_limit(s->file, s->bandwidth_limit);
491 }
492
493 void qmp_migrate_set_downtime(double value, Error **errp)
494 {
495 value *= 1e9;
496 value = MAX(0, MIN(UINT64_MAX, value));
497 max_downtime = (uint64_t)value;
498 }
499
500 int migrate_use_xbzrle(void)
501 {
502 MigrationState *s;
503
504 s = migrate_get_current();
505
506 return s->enabled_capabilities[MIGRATION_CAPABILITY_XBZRLE];
507 }
508
509 int64_t migrate_xbzrle_cache_size(void)
510 {
511 MigrationState *s;
512
513 s = migrate_get_current();
514
515 return s->xbzrle_cache_size;
516 }
517
518 /* migration thread support */
519
520
521 static void buffered_flush(MigrationState *s)
522 {
523 size_t offset = 0;
524 ssize_t ret = 0;
525
526 DPRINTF("flushing %zu byte(s) of data\n", s->buffer_size);
527
528 qemu_fflush(s->file);
529
530 while (s->bytes_xfer < s->xfer_limit && offset < s->buffer_size) {
531 size_t to_send = MIN(s->buffer_size - offset, s->xfer_limit - s->bytes_xfer);
532 ret = migrate_fd_put_buffer(s, s->buffer + offset, to_send);
533 if (ret <= 0) {
534 DPRINTF("error flushing data, %zd\n", ret);
535 break;
536 } else {
537 DPRINTF("flushed %zd byte(s)\n", ret);
538 offset += ret;
539 s->bytes_xfer += ret;
540 }
541 }
542
543 DPRINTF("flushed %zu of %zu byte(s)\n", offset, s->buffer_size);
544 memmove(s->buffer, s->buffer + offset, s->buffer_size - offset);
545 s->buffer_size -= offset;
546
547 if (ret < 0) {
548 qemu_file_set_error(s->file, ret);
549 }
550 }
551
552 static int buffered_put_buffer(void *opaque, const uint8_t *buf,
553 int64_t pos, int size)
554 {
555 MigrationState *s = opaque;
556 ssize_t error;
557
558 DPRINTF("putting %d bytes at %" PRId64 "\n", size, pos);
559
560 error = qemu_file_get_error(s->file);
561 if (error) {
562 DPRINTF("flush when error, bailing: %s\n", strerror(-error));
563 return error;
564 }
565
566 if (size <= 0) {
567 return size;
568 }
569
570 if (size > (s->buffer_capacity - s->buffer_size)) {
571 DPRINTF("increasing buffer capacity from %zu by %zu\n",
572 s->buffer_capacity, size + 1024);
573
574 s->buffer_capacity += size + 1024;
575
576 s->buffer = g_realloc(s->buffer, s->buffer_capacity);
577 }
578
579 memcpy(s->buffer + s->buffer_size, buf, size);
580 s->buffer_size += size;
581
582 return size;
583 }
584
585 static int buffered_close(void *opaque)
586 {
587 MigrationState *s = opaque;
588
589 DPRINTF("closing\n");
590
591 s->xfer_limit = INT_MAX;
592 while (!qemu_file_get_error(s->file) && s->buffer_size) {
593 buffered_flush(s);
594 }
595 s->complete = true;
596 return migrate_fd_close(s);
597 }
598
599 static int buffered_get_fd(void *opaque)
600 {
601 MigrationState *s = opaque;
602
603 return s->fd;
604 }
605
606 /*
607 * The meaning of the return values is:
608 * 0: We can continue sending
609 * 1: Time to stop
610 * negative: There has been an error
611 */
612 static int buffered_rate_limit(void *opaque)
613 {
614 MigrationState *s = opaque;
615 int ret;
616
617 ret = qemu_file_get_error(s->file);
618 if (ret) {
619 return ret;
620 }
621
622 if (s->bytes_xfer >= s->xfer_limit) {
623 return 1;
624 }
625
626 return 0;
627 }
628
629 static int64_t buffered_set_rate_limit(void *opaque, int64_t new_rate)
630 {
631 MigrationState *s = opaque;
632 if (qemu_file_get_error(s->file)) {
633 goto out;
634 }
635 if (new_rate > SIZE_MAX) {
636 new_rate = SIZE_MAX;
637 }
638
639 s->xfer_limit = new_rate / XFER_LIMIT_RATIO;
640
641 out:
642 return s->xfer_limit;
643 }
644
645 static int64_t buffered_get_rate_limit(void *opaque)
646 {
647 MigrationState *s = opaque;
648
649 return s->xfer_limit;
650 }
651
652 static void *buffered_file_thread(void *opaque)
653 {
654 MigrationState *s = opaque;
655 int64_t initial_time = qemu_get_clock_ms(rt_clock);
656 int64_t sleep_time = 0;
657 int64_t max_size = 0;
658 bool last_round = false;
659 int ret;
660
661 qemu_mutex_lock_iothread();
662 DPRINTF("beginning savevm\n");
663 ret = qemu_savevm_state_begin(s->file, &s->params);
664 qemu_mutex_unlock_iothread();
665
666 while (ret >= 0) {
667 int64_t current_time;
668 uint64_t pending_size;
669
670 qemu_mutex_lock_iothread();
671 if (s->state != MIG_STATE_ACTIVE) {
672 DPRINTF("put_ready returning because of non-active state\n");
673 qemu_mutex_unlock_iothread();
674 break;
675 }
676 if (s->complete) {
677 qemu_mutex_unlock_iothread();
678 break;
679 }
680 if (s->bytes_xfer < s->xfer_limit) {
681 DPRINTF("iterate\n");
682 pending_size = qemu_savevm_state_pending(s->file, max_size);
683 DPRINTF("pending size %lu max %lu\n", pending_size, max_size);
684 if (pending_size && pending_size >= max_size) {
685 ret = qemu_savevm_state_iterate(s->file);
686 if (ret < 0) {
687 qemu_mutex_unlock_iothread();
688 break;
689 }
690 } else {
691 int old_vm_running = runstate_is_running();
692 int64_t start_time, end_time;
693
694 DPRINTF("done iterating\n");
695 start_time = qemu_get_clock_ms(rt_clock);
696 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
697 vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
698 ret = qemu_savevm_state_complete(s->file);
699 if (ret < 0) {
700 qemu_mutex_unlock_iothread();
701 break;
702 } else {
703 migrate_fd_completed(s);
704 }
705 end_time = qemu_get_clock_ms(rt_clock);
706 s->total_time = end_time - s->total_time;
707 s->downtime = end_time - start_time;
708 if (s->state != MIG_STATE_COMPLETED) {
709 if (old_vm_running) {
710 vm_start();
711 }
712 }
713 last_round = true;
714 }
715 }
716 qemu_mutex_unlock_iothread();
717 current_time = qemu_get_clock_ms(rt_clock);
718 if (current_time >= initial_time + BUFFER_DELAY) {
719 uint64_t transferred_bytes = s->bytes_xfer;
720 uint64_t time_spent = current_time - initial_time - sleep_time;
721 double bandwidth = transferred_bytes / time_spent;
722 max_size = bandwidth * migrate_max_downtime() / 1000000;
723
724 DPRINTF("transferred %" PRIu64 " time_spent %" PRIu64
725 " bandwidth %g max_size %" PRId64 "\n",
726 transferred_bytes, time_spent, bandwidth, max_size);
727 /* if we haven't sent anything, we don't want to recalculate
728 10000 is a small enough number for our purposes */
729 if (s->dirty_bytes_rate && transferred_bytes > 10000) {
730 s->expected_downtime = s->dirty_bytes_rate / bandwidth;
731 }
732
733 s->bytes_xfer = 0;
734 sleep_time = 0;
735 initial_time = current_time;
736 }
737 if (!last_round && (s->bytes_xfer >= s->xfer_limit)) {
738 /* usleep expects microseconds */
739 g_usleep((initial_time + BUFFER_DELAY - current_time)*1000);
740 sleep_time += qemu_get_clock_ms(rt_clock) - current_time;
741 }
742 buffered_flush(s);
743 ret = qemu_file_get_error(s->file);
744 }
745
746 if (ret < 0) {
747 migrate_fd_error(s);
748 }
749 g_free(s->buffer);
750 return NULL;
751 }
752
753 static const QEMUFileOps buffered_file_ops = {
754 .get_fd = buffered_get_fd,
755 .put_buffer = buffered_put_buffer,
756 .close = buffered_close,
757 .rate_limit = buffered_rate_limit,
758 .get_rate_limit = buffered_get_rate_limit,
759 .set_rate_limit = buffered_set_rate_limit,
760 };
761
762 void migrate_fd_connect(MigrationState *s)
763 {
764 s->state = MIG_STATE_ACTIVE;
765 s->bytes_xfer = 0;
766 s->buffer = NULL;
767 s->buffer_size = 0;
768 s->buffer_capacity = 0;
769 /* This is a best 1st approximation. ns to ms */
770 s->expected_downtime = max_downtime/1000000;
771
772 s->xfer_limit = s->bandwidth_limit / XFER_LIMIT_RATIO;
773 s->complete = false;
774
775 s->file = qemu_fopen_ops(s, &buffered_file_ops);
776
777 qemu_thread_create(&s->thread, buffered_file_thread, s,
778 QEMU_THREAD_DETACHED);
779 notifier_list_notify(&migration_state_notifiers, s);
780 }