root / migration.c @ 8cfd0495
History | View | Annotate | Download (18.7 kB)
1 | 5bb7910a | aliguori | /*
|
---|---|---|---|
2 | 5bb7910a | aliguori | * QEMU live migration
|
3 | 5bb7910a | aliguori | *
|
4 | 5bb7910a | aliguori | * Copyright IBM, Corp. 2008
|
5 | 5bb7910a | aliguori | *
|
6 | 5bb7910a | aliguori | * Authors:
|
7 | 5bb7910a | aliguori | * Anthony Liguori <aliguori@us.ibm.com>
|
8 | 5bb7910a | aliguori | *
|
9 | 5bb7910a | aliguori | * This work is licensed under the terms of the GNU GPL, version 2. See
|
10 | 5bb7910a | aliguori | * the COPYING file in the top-level directory.
|
11 | 5bb7910a | aliguori | *
|
12 | 6b620ca3 | Paolo Bonzini | * Contributions after 2012-01-13 are licensed under the terms of the
|
13 | 6b620ca3 | Paolo Bonzini | * GNU GPL, version 2 or (at your option) any later version.
|
14 | 5bb7910a | aliguori | */
|
15 | 5bb7910a | aliguori | |
16 | 5bb7910a | aliguori | #include "qemu-common.h" |
17 | 6a1751b7 | Alex Bligh | #include "qemu/main-loop.h" |
18 | caf71f86 | Paolo Bonzini | #include "migration/migration.h" |
19 | 83c9089e | Paolo Bonzini | #include "monitor/monitor.h" |
20 | 0d82d0e8 | Juan Quintela | #include "migration/qemu-file.h" |
21 | 9c17d615 | Paolo Bonzini | #include "sysemu/sysemu.h" |
22 | 737e150e | Paolo Bonzini | #include "block/block.h" |
23 | 1de7afc9 | Paolo Bonzini | #include "qemu/sockets.h" |
24 | caf71f86 | Paolo Bonzini | #include "migration/block.h" |
25 | 766bd176 | Juan Quintela | #include "qemu/thread.h" |
26 | 791e7c82 | Luiz Capitulino | #include "qmp-commands.h" |
27 | c09e5bb1 | Kazuya Saito | #include "trace.h" |
28 | 065e2813 | aliguori | |
29 | 065e2813 | aliguori | //#define DEBUG_MIGRATION
|
30 | 065e2813 | aliguori | |
31 | 065e2813 | aliguori | #ifdef DEBUG_MIGRATION
|
32 | d0f2c4c6 | malc | #define DPRINTF(fmt, ...) \
|
33 | 065e2813 | aliguori | do { printf("migration: " fmt, ## __VA_ARGS__); } while (0) |
34 | 065e2813 | aliguori | #else
|
35 | d0f2c4c6 | malc | #define DPRINTF(fmt, ...) \
|
36 | 065e2813 | aliguori | do { } while (0) |
37 | 065e2813 | aliguori | #endif
|
38 | 5bb7910a | aliguori | |
39 | 7dc688ed | Juan Quintela | enum {
|
40 | 29ae8a41 | Michael R. Hines | MIG_STATE_ERROR = -1,
|
41 | 29ae8a41 | Michael R. Hines | MIG_STATE_NONE, |
42 | 7dc688ed | Juan Quintela | MIG_STATE_SETUP, |
43 | 7dc688ed | Juan Quintela | MIG_STATE_CANCELLED, |
44 | 7dc688ed | Juan Quintela | MIG_STATE_ACTIVE, |
45 | 7dc688ed | Juan Quintela | MIG_STATE_COMPLETED, |
46 | 7dc688ed | Juan Quintela | }; |
47 | 5bb7910a | aliguori | |
48 | d0ae46c1 | Juan Quintela | #define MAX_THROTTLE (32 << 20) /* Migration speed throttling */ |
49 | 5bb7910a | aliguori | |
50 | 5b4e1eb7 | Juan Quintela | /* Amount of time to allocate to each "chunk" of bandwidth-throttled
|
51 | 5b4e1eb7 | Juan Quintela | * data. */
|
52 | 5b4e1eb7 | Juan Quintela | #define BUFFER_DELAY 100 |
53 | 5b4e1eb7 | Juan Quintela | #define XFER_LIMIT_RATIO (1000 / BUFFER_DELAY) |
54 | 5b4e1eb7 | Juan Quintela | |
55 | 17ad9b35 | Orit Wasserman | /* Migration XBZRLE default cache size */
|
56 | 17ad9b35 | Orit Wasserman | #define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024) |
57 | 17ad9b35 | Orit Wasserman | |
58 | 99a0db9b | Gerd Hoffmann | static NotifierList migration_state_notifiers =
|
59 | 99a0db9b | Gerd Hoffmann | NOTIFIER_LIST_INITIALIZER(migration_state_notifiers); |
60 | 99a0db9b | Gerd Hoffmann | |
61 | 17549e84 | Juan Quintela | /* When we add fault tolerance, we could have several
|
62 | 17549e84 | Juan Quintela | migrations at once. For now we don't need to add
|
63 | 17549e84 | Juan Quintela | dynamic creation of migration */
|
64 | 17549e84 | Juan Quintela | |
65 | 859bc756 | Juan Quintela | MigrationState *migrate_get_current(void)
|
66 | 17549e84 | Juan Quintela | { |
67 | 17549e84 | Juan Quintela | static MigrationState current_migration = {
|
68 | 29ae8a41 | Michael R. Hines | .state = MIG_STATE_NONE, |
69 | d0ae46c1 | Juan Quintela | .bandwidth_limit = MAX_THROTTLE, |
70 | 17ad9b35 | Orit Wasserman | .xbzrle_cache_size = DEFAULT_MIGRATE_CACHE_SIZE, |
71 | 7e114f8c | Michael R. Hines | .mbps = -1,
|
72 | 17549e84 | Juan Quintela | }; |
73 | 17549e84 | Juan Quintela | |
74 | 17549e84 | Juan Quintela | return ¤t_migration;
|
75 | 17549e84 | Juan Quintela | } |
76 | 17549e84 | Juan Quintela | |
77 | 43eaae28 | Paolo Bonzini | void qemu_start_incoming_migration(const char *uri, Error **errp) |
78 | 5bb7910a | aliguori | { |
79 | 34c9dd8e | aliguori | const char *p; |
80 | 34c9dd8e | aliguori | |
81 | 34c9dd8e | aliguori | if (strstart(uri, "tcp:", &p)) |
82 | 43eaae28 | Paolo Bonzini | tcp_start_incoming_migration(p, errp); |
83 | 2da776db | Michael R. Hines | #ifdef CONFIG_RDMA
|
84 | 2da776db | Michael R. Hines | else if (strstart(uri, "x-rdma:", &p)) |
85 | 2da776db | Michael R. Hines | rdma_start_incoming_migration(p, errp); |
86 | 2da776db | Michael R. Hines | #endif
|
87 | 065e2813 | aliguori | #if !defined(WIN32)
|
88 | 065e2813 | aliguori | else if (strstart(uri, "exec:", &p)) |
89 | 43eaae28 | Paolo Bonzini | exec_start_incoming_migration(p, errp); |
90 | 4951f65b | Chris Lalancette | else if (strstart(uri, "unix:", &p)) |
91 | 43eaae28 | Paolo Bonzini | unix_start_incoming_migration(p, errp); |
92 | 5ac1fad3 | Paolo Bonzini | else if (strstart(uri, "fd:", &p)) |
93 | 43eaae28 | Paolo Bonzini | fd_start_incoming_migration(p, errp); |
94 | 065e2813 | aliguori | #endif
|
95 | 8ca5e801 | Juan Quintela | else {
|
96 | 312fd5f2 | Markus Armbruster | error_setg(errp, "unknown migration protocol: %s", uri);
|
97 | 8ca5e801 | Juan Quintela | } |
98 | 5bb7910a | aliguori | } |
99 | 5bb7910a | aliguori | |
100 | 82a4da79 | Paolo Bonzini | static void process_incoming_migration_co(void *opaque) |
101 | 511c0231 | Juan Quintela | { |
102 | 82a4da79 | Paolo Bonzini | QEMUFile *f = opaque; |
103 | 1c12e1f5 | Paolo Bonzini | int ret;
|
104 | 1c12e1f5 | Paolo Bonzini | |
105 | 1c12e1f5 | Paolo Bonzini | ret = qemu_loadvm_state(f); |
106 | 1c12e1f5 | Paolo Bonzini | qemu_fclose(f); |
107 | 1c12e1f5 | Paolo Bonzini | if (ret < 0) { |
108 | 511c0231 | Juan Quintela | fprintf(stderr, "load of migration failed\n");
|
109 | 4aead692 | Eric Blake | exit(EXIT_FAILURE); |
110 | 511c0231 | Juan Quintela | } |
111 | 511c0231 | Juan Quintela | qemu_announce_self(); |
112 | 511c0231 | Juan Quintela | DPRINTF("successfully loaded vm state\n");
|
113 | 511c0231 | Juan Quintela | |
114 | 901862cb | Benoît Canet | bdrv_clear_incoming_migration_all(); |
115 | 0f15423c | Anthony Liguori | /* Make sure all file formats flush their mutable metadata */
|
116 | 0f15423c | Anthony Liguori | bdrv_invalidate_cache_all(); |
117 | 0f15423c | Anthony Liguori | |
118 | f5bbfba1 | Luiz Capitulino | if (autostart) {
|
119 | 511c0231 | Juan Quintela | vm_start(); |
120 | f5bbfba1 | Luiz Capitulino | } else {
|
121 | 29ed72f1 | Paolo Bonzini | runstate_set(RUN_STATE_PAUSED); |
122 | f5bbfba1 | Luiz Capitulino | } |
123 | 511c0231 | Juan Quintela | } |
124 | 511c0231 | Juan Quintela | |
125 | 82a4da79 | Paolo Bonzini | void process_incoming_migration(QEMUFile *f)
|
126 | 82a4da79 | Paolo Bonzini | { |
127 | 82a4da79 | Paolo Bonzini | Coroutine *co = qemu_coroutine_create(process_incoming_migration_co); |
128 | 82a4da79 | Paolo Bonzini | int fd = qemu_get_fd(f);
|
129 | 82a4da79 | Paolo Bonzini | |
130 | 82a4da79 | Paolo Bonzini | assert(fd != -1);
|
131 | f9e8cacc | Stefan Hajnoczi | qemu_set_nonblock(fd); |
132 | 82a4da79 | Paolo Bonzini | qemu_coroutine_enter(co, f); |
133 | 82a4da79 | Paolo Bonzini | } |
134 | 82a4da79 | Paolo Bonzini | |
135 | a0a3fd60 | Glauber Costa | /* amount of nanoseconds we are willing to wait for migration to be down.
|
136 | a0a3fd60 | Glauber Costa | * the choice of nanoseconds is because it is the maximum resolution that
|
137 | a0a3fd60 | Glauber Costa | * get_clock() can achieve. It is an internal measure. All user-visible
|
138 | a0a3fd60 | Glauber Costa | * units must be in seconds */
|
139 | a0a3fd60 | Glauber Costa | static uint64_t max_downtime = 30000000; |
140 | a0a3fd60 | Glauber Costa | |
141 | a0a3fd60 | Glauber Costa | uint64_t migrate_max_downtime(void)
|
142 | a0a3fd60 | Glauber Costa | { |
143 | a0a3fd60 | Glauber Costa | return max_downtime;
|
144 | a0a3fd60 | Glauber Costa | } |
145 | a0a3fd60 | Glauber Costa | |
146 | bbf6da32 | Orit Wasserman | MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp) |
147 | bbf6da32 | Orit Wasserman | { |
148 | bbf6da32 | Orit Wasserman | MigrationCapabilityStatusList *head = NULL;
|
149 | bbf6da32 | Orit Wasserman | MigrationCapabilityStatusList *caps; |
150 | bbf6da32 | Orit Wasserman | MigrationState *s = migrate_get_current(); |
151 | bbf6da32 | Orit Wasserman | int i;
|
152 | bbf6da32 | Orit Wasserman | |
153 | bbf6da32 | Orit Wasserman | for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) { |
154 | bbf6da32 | Orit Wasserman | if (head == NULL) { |
155 | bbf6da32 | Orit Wasserman | head = g_malloc0(sizeof(*caps));
|
156 | bbf6da32 | Orit Wasserman | caps = head; |
157 | bbf6da32 | Orit Wasserman | } else {
|
158 | bbf6da32 | Orit Wasserman | caps->next = g_malloc0(sizeof(*caps));
|
159 | bbf6da32 | Orit Wasserman | caps = caps->next; |
160 | bbf6da32 | Orit Wasserman | } |
161 | bbf6da32 | Orit Wasserman | caps->value = |
162 | bbf6da32 | Orit Wasserman | g_malloc(sizeof(*caps->value));
|
163 | bbf6da32 | Orit Wasserman | caps->value->capability = i; |
164 | bbf6da32 | Orit Wasserman | caps->value->state = s->enabled_capabilities[i]; |
165 | bbf6da32 | Orit Wasserman | } |
166 | bbf6da32 | Orit Wasserman | |
167 | bbf6da32 | Orit Wasserman | return head;
|
168 | bbf6da32 | Orit Wasserman | } |
169 | bbf6da32 | Orit Wasserman | |
170 | f36d55af | Orit Wasserman | static void get_xbzrle_cache_stats(MigrationInfo *info) |
171 | f36d55af | Orit Wasserman | { |
172 | f36d55af | Orit Wasserman | if (migrate_use_xbzrle()) {
|
173 | f36d55af | Orit Wasserman | info->has_xbzrle_cache = true;
|
174 | f36d55af | Orit Wasserman | info->xbzrle_cache = g_malloc0(sizeof(*info->xbzrle_cache));
|
175 | f36d55af | Orit Wasserman | info->xbzrle_cache->cache_size = migrate_xbzrle_cache_size(); |
176 | f36d55af | Orit Wasserman | info->xbzrle_cache->bytes = xbzrle_mig_bytes_transferred(); |
177 | f36d55af | Orit Wasserman | info->xbzrle_cache->pages = xbzrle_mig_pages_transferred(); |
178 | f36d55af | Orit Wasserman | info->xbzrle_cache->cache_miss = xbzrle_mig_pages_cache_miss(); |
179 | f36d55af | Orit Wasserman | info->xbzrle_cache->overflow = xbzrle_mig_pages_overflow(); |
180 | f36d55af | Orit Wasserman | } |
181 | f36d55af | Orit Wasserman | } |
182 | f36d55af | Orit Wasserman | |
183 | 791e7c82 | Luiz Capitulino | MigrationInfo *qmp_query_migrate(Error **errp) |
184 | 5bb7910a | aliguori | { |
185 | 791e7c82 | Luiz Capitulino | MigrationInfo *info = g_malloc0(sizeof(*info));
|
186 | 17549e84 | Juan Quintela | MigrationState *s = migrate_get_current(); |
187 | 17549e84 | Juan Quintela | |
188 | 17549e84 | Juan Quintela | switch (s->state) {
|
189 | 29ae8a41 | Michael R. Hines | case MIG_STATE_NONE:
|
190 | 17549e84 | Juan Quintela | /* no migration has happened ever */
|
191 | 17549e84 | Juan Quintela | break;
|
192 | 29ae8a41 | Michael R. Hines | case MIG_STATE_SETUP:
|
193 | 29ae8a41 | Michael R. Hines | info->has_status = true;
|
194 | 29ae8a41 | Michael R. Hines | info->status = g_strdup("setup");
|
195 | ed4fbd10 | Michael R. Hines | info->has_total_time = false;
|
196 | 29ae8a41 | Michael R. Hines | break;
|
197 | 17549e84 | Juan Quintela | case MIG_STATE_ACTIVE:
|
198 | 791e7c82 | Luiz Capitulino | info->has_status = true;
|
199 | 791e7c82 | Luiz Capitulino | info->status = g_strdup("active");
|
200 | 7aa939af | Juan Quintela | info->has_total_time = true;
|
201 | bc72ad67 | Alex Bligh | info->total_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) |
202 | 7aa939af | Juan Quintela | - s->total_time; |
203 | 2c52ddf1 | Juan Quintela | info->has_expected_downtime = true;
|
204 | 2c52ddf1 | Juan Quintela | info->expected_downtime = s->expected_downtime; |
205 | ed4fbd10 | Michael R. Hines | info->has_setup_time = true;
|
206 | ed4fbd10 | Michael R. Hines | info->setup_time = s->setup_time; |
207 | 17549e84 | Juan Quintela | |
208 | 791e7c82 | Luiz Capitulino | info->has_ram = true;
|
209 | 791e7c82 | Luiz Capitulino | info->ram = g_malloc0(sizeof(*info->ram));
|
210 | 791e7c82 | Luiz Capitulino | info->ram->transferred = ram_bytes_transferred(); |
211 | 791e7c82 | Luiz Capitulino | info->ram->remaining = ram_bytes_remaining(); |
212 | 791e7c82 | Luiz Capitulino | info->ram->total = ram_bytes_total(); |
213 | 004d4c10 | Orit Wasserman | info->ram->duplicate = dup_mig_pages_transferred(); |
214 | f1c72795 | Peter Lieven | info->ram->skipped = skipped_mig_pages_transferred(); |
215 | 004d4c10 | Orit Wasserman | info->ram->normal = norm_mig_pages_transferred(); |
216 | 004d4c10 | Orit Wasserman | info->ram->normal_bytes = norm_mig_bytes_transferred(); |
217 | 8d017193 | Juan Quintela | info->ram->dirty_pages_rate = s->dirty_pages_rate; |
218 | 7e114f8c | Michael R. Hines | info->ram->mbps = s->mbps; |
219 | 8d017193 | Juan Quintela | |
220 | 17549e84 | Juan Quintela | if (blk_mig_active()) {
|
221 | 791e7c82 | Luiz Capitulino | info->has_disk = true;
|
222 | 791e7c82 | Luiz Capitulino | info->disk = g_malloc0(sizeof(*info->disk));
|
223 | 791e7c82 | Luiz Capitulino | info->disk->transferred = blk_mig_bytes_transferred(); |
224 | 791e7c82 | Luiz Capitulino | info->disk->remaining = blk_mig_bytes_remaining(); |
225 | 791e7c82 | Luiz Capitulino | info->disk->total = blk_mig_bytes_total(); |
226 | ff8d81d8 | aliguori | } |
227 | f36d55af | Orit Wasserman | |
228 | f36d55af | Orit Wasserman | get_xbzrle_cache_stats(info); |
229 | 17549e84 | Juan Quintela | break;
|
230 | 17549e84 | Juan Quintela | case MIG_STATE_COMPLETED:
|
231 | f36d55af | Orit Wasserman | get_xbzrle_cache_stats(info); |
232 | f36d55af | Orit Wasserman | |
233 | 791e7c82 | Luiz Capitulino | info->has_status = true;
|
234 | 791e7c82 | Luiz Capitulino | info->status = g_strdup("completed");
|
235 | 00c14997 | Pawit Pornkitprasan | info->has_total_time = true;
|
236 | 7aa939af | Juan Quintela | info->total_time = s->total_time; |
237 | 9c5a9fcf | Juan Quintela | info->has_downtime = true;
|
238 | 9c5a9fcf | Juan Quintela | info->downtime = s->downtime; |
239 | ed4fbd10 | Michael R. Hines | info->has_setup_time = true;
|
240 | ed4fbd10 | Michael R. Hines | info->setup_time = s->setup_time; |
241 | d5f8a570 | Juan Quintela | |
242 | d5f8a570 | Juan Quintela | info->has_ram = true;
|
243 | d5f8a570 | Juan Quintela | info->ram = g_malloc0(sizeof(*info->ram));
|
244 | d5f8a570 | Juan Quintela | info->ram->transferred = ram_bytes_transferred(); |
245 | d5f8a570 | Juan Quintela | info->ram->remaining = 0;
|
246 | d5f8a570 | Juan Quintela | info->ram->total = ram_bytes_total(); |
247 | 004d4c10 | Orit Wasserman | info->ram->duplicate = dup_mig_pages_transferred(); |
248 | f1c72795 | Peter Lieven | info->ram->skipped = skipped_mig_pages_transferred(); |
249 | 004d4c10 | Orit Wasserman | info->ram->normal = norm_mig_pages_transferred(); |
250 | 004d4c10 | Orit Wasserman | info->ram->normal_bytes = norm_mig_bytes_transferred(); |
251 | 7e114f8c | Michael R. Hines | info->ram->mbps = s->mbps; |
252 | 17549e84 | Juan Quintela | break;
|
253 | 17549e84 | Juan Quintela | case MIG_STATE_ERROR:
|
254 | 791e7c82 | Luiz Capitulino | info->has_status = true;
|
255 | 791e7c82 | Luiz Capitulino | info->status = g_strdup("failed");
|
256 | 17549e84 | Juan Quintela | break;
|
257 | 17549e84 | Juan Quintela | case MIG_STATE_CANCELLED:
|
258 | 791e7c82 | Luiz Capitulino | info->has_status = true;
|
259 | 791e7c82 | Luiz Capitulino | info->status = g_strdup("cancelled");
|
260 | 17549e84 | Juan Quintela | break;
|
261 | 5bb7910a | aliguori | } |
262 | 791e7c82 | Luiz Capitulino | |
263 | 791e7c82 | Luiz Capitulino | return info;
|
264 | 5bb7910a | aliguori | } |
265 | 5bb7910a | aliguori | |
266 | 00458433 | Orit Wasserman | void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
|
267 | 00458433 | Orit Wasserman | Error **errp) |
268 | 00458433 | Orit Wasserman | { |
269 | 00458433 | Orit Wasserman | MigrationState *s = migrate_get_current(); |
270 | 00458433 | Orit Wasserman | MigrationCapabilityStatusList *cap; |
271 | 00458433 | Orit Wasserman | |
272 | 29ae8a41 | Michael R. Hines | if (s->state == MIG_STATE_ACTIVE || s->state == MIG_STATE_SETUP) {
|
273 | 00458433 | Orit Wasserman | error_set(errp, QERR_MIGRATION_ACTIVE); |
274 | 00458433 | Orit Wasserman | return;
|
275 | 00458433 | Orit Wasserman | } |
276 | 00458433 | Orit Wasserman | |
277 | 00458433 | Orit Wasserman | for (cap = params; cap; cap = cap->next) {
|
278 | 00458433 | Orit Wasserman | s->enabled_capabilities[cap->value->capability] = cap->value->state; |
279 | 00458433 | Orit Wasserman | } |
280 | 00458433 | Orit Wasserman | } |
281 | 00458433 | Orit Wasserman | |
282 | 065e2813 | aliguori | /* shared migration helpers */
|
283 | 065e2813 | aliguori | |
284 | bb1fadc4 | Paolo Bonzini | static void migrate_fd_cleanup(void *opaque) |
285 | 065e2813 | aliguori | { |
286 | bb1fadc4 | Paolo Bonzini | MigrationState *s = opaque; |
287 | bb1fadc4 | Paolo Bonzini | |
288 | bb1fadc4 | Paolo Bonzini | qemu_bh_delete(s->cleanup_bh); |
289 | bb1fadc4 | Paolo Bonzini | s->cleanup_bh = NULL;
|
290 | bb1fadc4 | Paolo Bonzini | |
291 | 065e2813 | aliguori | if (s->file) {
|
292 | d0f2c4c6 | malc | DPRINTF("closing file\n");
|
293 | 404a7c05 | Paolo Bonzini | qemu_mutex_unlock_iothread(); |
294 | 404a7c05 | Paolo Bonzini | qemu_thread_join(&s->thread); |
295 | 404a7c05 | Paolo Bonzini | qemu_mutex_lock_iothread(); |
296 | 404a7c05 | Paolo Bonzini | |
297 | 6f190a06 | Paolo Bonzini | qemu_fclose(s->file); |
298 | 6f190a06 | Paolo Bonzini | s->file = NULL;
|
299 | 065e2813 | aliguori | } |
300 | 065e2813 | aliguori | |
301 | a3fa1d78 | Paolo Bonzini | assert(s->state != MIG_STATE_ACTIVE); |
302 | 7a2c1721 | Paolo Bonzini | |
303 | a3fa1d78 | Paolo Bonzini | if (s->state != MIG_STATE_COMPLETED) {
|
304 | 7a2c1721 | Paolo Bonzini | qemu_savevm_state_cancel(); |
305 | 7a2c1721 | Paolo Bonzini | } |
306 | a3fa1d78 | Paolo Bonzini | |
307 | a3fa1d78 | Paolo Bonzini | notifier_list_notify(&migration_state_notifiers, s); |
308 | 065e2813 | aliguori | } |
309 | 065e2813 | aliguori | |
310 | d58f574b | Michael R. Hines | static void migrate_set_state(MigrationState *s, int old_state, int new_state) |
311 | f4410a5d | Paolo Bonzini | { |
312 | d58f574b | Michael R. Hines | if (atomic_cmpxchg(&s->state, old_state, new_state) == new_state) {
|
313 | f4410a5d | Paolo Bonzini | trace_migrate_set_state(new_state); |
314 | f4410a5d | Paolo Bonzini | } |
315 | f4410a5d | Paolo Bonzini | } |
316 | f4410a5d | Paolo Bonzini | |
317 | 8b6b99b3 | Juan Quintela | void migrate_fd_error(MigrationState *s)
|
318 | 065e2813 | aliguori | { |
319 | 8b6b99b3 | Juan Quintela | DPRINTF("setting error state\n");
|
320 | bb1fadc4 | Paolo Bonzini | assert(s->file == NULL);
|
321 | bb1fadc4 | Paolo Bonzini | s->state = MIG_STATE_ERROR; |
322 | bb1fadc4 | Paolo Bonzini | trace_migrate_set_state(MIG_STATE_ERROR); |
323 | bb1fadc4 | Paolo Bonzini | notifier_list_notify(&migration_state_notifiers, s); |
324 | 458cf28e | Juan Quintela | } |
325 | 458cf28e | Juan Quintela | |
326 | 0edda1c4 | Juan Quintela | static void migrate_fd_cancel(MigrationState *s) |
327 | 065e2813 | aliguori | { |
328 | d0f2c4c6 | malc | DPRINTF("cancelling migration\n");
|
329 | 065e2813 | aliguori | |
330 | d58f574b | Michael R. Hines | migrate_set_state(s, s->state, MIG_STATE_CANCELLED); |
331 | 065e2813 | aliguori | } |
332 | 065e2813 | aliguori | |
333 | 99a0db9b | Gerd Hoffmann | void add_migration_state_change_notifier(Notifier *notify)
|
334 | 99a0db9b | Gerd Hoffmann | { |
335 | 99a0db9b | Gerd Hoffmann | notifier_list_add(&migration_state_notifiers, notify); |
336 | 99a0db9b | Gerd Hoffmann | } |
337 | 99a0db9b | Gerd Hoffmann | |
338 | 99a0db9b | Gerd Hoffmann | void remove_migration_state_change_notifier(Notifier *notify)
|
339 | 99a0db9b | Gerd Hoffmann | { |
340 | 31552529 | Paolo Bonzini | notifier_remove(notify); |
341 | 99a0db9b | Gerd Hoffmann | } |
342 | 99a0db9b | Gerd Hoffmann | |
343 | 02edd2e7 | Stefan Hajnoczi | bool migration_in_setup(MigrationState *s)
|
344 | afe2df69 | Gerd Hoffmann | { |
345 | 02edd2e7 | Stefan Hajnoczi | return s->state == MIG_STATE_SETUP;
|
346 | afe2df69 | Gerd Hoffmann | } |
347 | afe2df69 | Gerd Hoffmann | |
348 | 7073693b | Juan Quintela | bool migration_has_finished(MigrationState *s)
|
349 | 99a0db9b | Gerd Hoffmann | { |
350 | 7073693b | Juan Quintela | return s->state == MIG_STATE_COMPLETED;
|
351 | 99a0db9b | Gerd Hoffmann | } |
352 | 0edda1c4 | Juan Quintela | |
353 | afe2df69 | Gerd Hoffmann | bool migration_has_failed(MigrationState *s)
|
354 | afe2df69 | Gerd Hoffmann | { |
355 | afe2df69 | Gerd Hoffmann | return (s->state == MIG_STATE_CANCELLED ||
|
356 | afe2df69 | Gerd Hoffmann | s->state == MIG_STATE_ERROR); |
357 | afe2df69 | Gerd Hoffmann | } |
358 | afe2df69 | Gerd Hoffmann | |
359 | 6607ae23 | Isaku Yamahata | static MigrationState *migrate_init(const MigrationParams *params) |
360 | 0edda1c4 | Juan Quintela | { |
361 | 17549e84 | Juan Quintela | MigrationState *s = migrate_get_current(); |
362 | d0ae46c1 | Juan Quintela | int64_t bandwidth_limit = s->bandwidth_limit; |
363 | bbf6da32 | Orit Wasserman | bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
|
364 | 17ad9b35 | Orit Wasserman | int64_t xbzrle_cache_size = s->xbzrle_cache_size; |
365 | bbf6da32 | Orit Wasserman | |
366 | bbf6da32 | Orit Wasserman | memcpy(enabled_capabilities, s->enabled_capabilities, |
367 | bbf6da32 | Orit Wasserman | sizeof(enabled_capabilities));
|
368 | 0edda1c4 | Juan Quintela | |
369 | 17549e84 | Juan Quintela | memset(s, 0, sizeof(*s)); |
370 | 6607ae23 | Isaku Yamahata | s->params = *params; |
371 | bbf6da32 | Orit Wasserman | memcpy(s->enabled_capabilities, enabled_capabilities, |
372 | bbf6da32 | Orit Wasserman | sizeof(enabled_capabilities));
|
373 | 17ad9b35 | Orit Wasserman | s->xbzrle_cache_size = xbzrle_cache_size; |
374 | 1299c631 | Juan Quintela | |
375 | 0edda1c4 | Juan Quintela | s->bandwidth_limit = bandwidth_limit; |
376 | d5934dde | Juan Quintela | s->state = MIG_STATE_SETUP; |
377 | c09e5bb1 | Kazuya Saito | trace_migrate_set_state(MIG_STATE_SETUP); |
378 | 0edda1c4 | Juan Quintela | |
379 | bc72ad67 | Alex Bligh | s->total_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); |
380 | 0edda1c4 | Juan Quintela | return s;
|
381 | 0edda1c4 | Juan Quintela | } |
382 | cab30143 | Juan Quintela | |
383 | fa2756b7 | Anthony Liguori | static GSList *migration_blockers;
|
384 | fa2756b7 | Anthony Liguori | |
385 | fa2756b7 | Anthony Liguori | void migrate_add_blocker(Error *reason)
|
386 | fa2756b7 | Anthony Liguori | { |
387 | fa2756b7 | Anthony Liguori | migration_blockers = g_slist_prepend(migration_blockers, reason); |
388 | fa2756b7 | Anthony Liguori | } |
389 | fa2756b7 | Anthony Liguori | |
390 | fa2756b7 | Anthony Liguori | void migrate_del_blocker(Error *reason)
|
391 | fa2756b7 | Anthony Liguori | { |
392 | fa2756b7 | Anthony Liguori | migration_blockers = g_slist_remove(migration_blockers, reason); |
393 | fa2756b7 | Anthony Liguori | } |
394 | fa2756b7 | Anthony Liguori | |
395 | e1c37d0e | Luiz Capitulino | void qmp_migrate(const char *uri, bool has_blk, bool blk, |
396 | e1c37d0e | Luiz Capitulino | bool has_inc, bool inc, bool has_detach, bool detach, |
397 | e1c37d0e | Luiz Capitulino | Error **errp) |
398 | cab30143 | Juan Quintela | { |
399 | be7059cd | Paolo Bonzini | Error *local_err = NULL;
|
400 | 17549e84 | Juan Quintela | MigrationState *s = migrate_get_current(); |
401 | 6607ae23 | Isaku Yamahata | MigrationParams params; |
402 | cab30143 | Juan Quintela | const char *p; |
403 | cab30143 | Juan Quintela | |
404 | 8c0426ae | Pawit Pornkitprasan | params.blk = has_blk && blk; |
405 | 8c0426ae | Pawit Pornkitprasan | params.shared = has_inc && inc; |
406 | 6607ae23 | Isaku Yamahata | |
407 | 29ae8a41 | Michael R. Hines | if (s->state == MIG_STATE_ACTIVE || s->state == MIG_STATE_SETUP) {
|
408 | e1c37d0e | Luiz Capitulino | error_set(errp, QERR_MIGRATION_ACTIVE); |
409 | e1c37d0e | Luiz Capitulino | return;
|
410 | cab30143 | Juan Quintela | } |
411 | cab30143 | Juan Quintela | |
412 | e1c37d0e | Luiz Capitulino | if (qemu_savevm_state_blocked(errp)) {
|
413 | e1c37d0e | Luiz Capitulino | return;
|
414 | cab30143 | Juan Quintela | } |
415 | cab30143 | Juan Quintela | |
416 | fa2756b7 | Anthony Liguori | if (migration_blockers) {
|
417 | e1c37d0e | Luiz Capitulino | *errp = error_copy(migration_blockers->data); |
418 | e1c37d0e | Luiz Capitulino | return;
|
419 | fa2756b7 | Anthony Liguori | } |
420 | fa2756b7 | Anthony Liguori | |
421 | 6607ae23 | Isaku Yamahata | s = migrate_init(¶ms); |
422 | cab30143 | Juan Quintela | |
423 | cab30143 | Juan Quintela | if (strstart(uri, "tcp:", &p)) { |
424 | f37afb5a | Paolo Bonzini | tcp_start_outgoing_migration(s, p, &local_err); |
425 | 2da776db | Michael R. Hines | #ifdef CONFIG_RDMA
|
426 | 2da776db | Michael R. Hines | } else if (strstart(uri, "x-rdma:", &p)) { |
427 | 2da776db | Michael R. Hines | rdma_start_outgoing_migration(s, p, &local_err); |
428 | 2da776db | Michael R. Hines | #endif
|
429 | cab30143 | Juan Quintela | #if !defined(WIN32)
|
430 | cab30143 | Juan Quintela | } else if (strstart(uri, "exec:", &p)) { |
431 | f37afb5a | Paolo Bonzini | exec_start_outgoing_migration(s, p, &local_err); |
432 | cab30143 | Juan Quintela | } else if (strstart(uri, "unix:", &p)) { |
433 | f37afb5a | Paolo Bonzini | unix_start_outgoing_migration(s, p, &local_err); |
434 | cab30143 | Juan Quintela | } else if (strstart(uri, "fd:", &p)) { |
435 | f37afb5a | Paolo Bonzini | fd_start_outgoing_migration(s, p, &local_err); |
436 | cab30143 | Juan Quintela | #endif
|
437 | 99a0db9b | Gerd Hoffmann | } else {
|
438 | e1c37d0e | Luiz Capitulino | error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol"); |
439 | e1c37d0e | Luiz Capitulino | return;
|
440 | cab30143 | Juan Quintela | } |
441 | cab30143 | Juan Quintela | |
442 | f37afb5a | Paolo Bonzini | if (local_err) {
|
443 | 342ab8d1 | Paolo Bonzini | migrate_fd_error(s); |
444 | f37afb5a | Paolo Bonzini | error_propagate(errp, local_err); |
445 | e1c37d0e | Luiz Capitulino | return;
|
446 | 1299c631 | Juan Quintela | } |
447 | cab30143 | Juan Quintela | } |
448 | cab30143 | Juan Quintela | |
449 | 6cdedb07 | Luiz Capitulino | void qmp_migrate_cancel(Error **errp)
|
450 | cab30143 | Juan Quintela | { |
451 | 17549e84 | Juan Quintela | migrate_fd_cancel(migrate_get_current()); |
452 | cab30143 | Juan Quintela | } |
453 | cab30143 | Juan Quintela | |
454 | 9e1ba4cc | Orit Wasserman | void qmp_migrate_set_cache_size(int64_t value, Error **errp)
|
455 | 9e1ba4cc | Orit Wasserman | { |
456 | 9e1ba4cc | Orit Wasserman | MigrationState *s = migrate_get_current(); |
457 | 9e1ba4cc | Orit Wasserman | |
458 | 9e1ba4cc | Orit Wasserman | /* Check for truncation */
|
459 | 9e1ba4cc | Orit Wasserman | if (value != (size_t)value) {
|
460 | 9e1ba4cc | Orit Wasserman | error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
|
461 | 9e1ba4cc | Orit Wasserman | "exceeding address space");
|
462 | 9e1ba4cc | Orit Wasserman | return;
|
463 | 9e1ba4cc | Orit Wasserman | } |
464 | 9e1ba4cc | Orit Wasserman | |
465 | 9e1ba4cc | Orit Wasserman | s->xbzrle_cache_size = xbzrle_cache_resize(value); |
466 | 9e1ba4cc | Orit Wasserman | } |
467 | 9e1ba4cc | Orit Wasserman | |
468 | 9e1ba4cc | Orit Wasserman | int64_t qmp_query_migrate_cache_size(Error **errp) |
469 | 9e1ba4cc | Orit Wasserman | { |
470 | 9e1ba4cc | Orit Wasserman | return migrate_xbzrle_cache_size();
|
471 | 9e1ba4cc | Orit Wasserman | } |
472 | 9e1ba4cc | Orit Wasserman | |
473 | 3dc85383 | Luiz Capitulino | void qmp_migrate_set_speed(int64_t value, Error **errp)
|
474 | cab30143 | Juan Quintela | { |
475 | cab30143 | Juan Quintela | MigrationState *s; |
476 | cab30143 | Juan Quintela | |
477 | 3dc85383 | Luiz Capitulino | if (value < 0) { |
478 | 3dc85383 | Luiz Capitulino | value = 0;
|
479 | 99a0db9b | Gerd Hoffmann | } |
480 | 442773ce | Paolo Bonzini | if (value > SIZE_MAX) {
|
481 | 442773ce | Paolo Bonzini | value = SIZE_MAX; |
482 | 442773ce | Paolo Bonzini | } |
483 | cab30143 | Juan Quintela | |
484 | 17549e84 | Juan Quintela | s = migrate_get_current(); |
485 | 3dc85383 | Luiz Capitulino | s->bandwidth_limit = value; |
486 | 442773ce | Paolo Bonzini | if (s->file) {
|
487 | 442773ce | Paolo Bonzini | qemu_file_set_rate_limit(s->file, s->bandwidth_limit / XFER_LIMIT_RATIO); |
488 | 442773ce | Paolo Bonzini | } |
489 | cab30143 | Juan Quintela | } |
490 | cab30143 | Juan Quintela | |
491 | 4f0a993b | Luiz Capitulino | void qmp_migrate_set_downtime(double value, Error **errp) |
492 | cab30143 | Juan Quintela | { |
493 | 4f0a993b | Luiz Capitulino | value *= 1e9;
|
494 | 4f0a993b | Luiz Capitulino | value = MAX(0, MIN(UINT64_MAX, value));
|
495 | 4f0a993b | Luiz Capitulino | max_downtime = (uint64_t)value; |
496 | 99a0db9b | Gerd Hoffmann | } |
497 | 17ad9b35 | Orit Wasserman | |
498 | 60d9222c | Michael R. Hines | bool migrate_rdma_pin_all(void) |
499 | 60d9222c | Michael R. Hines | { |
500 | 60d9222c | Michael R. Hines | MigrationState *s; |
501 | 60d9222c | Michael R. Hines | |
502 | 60d9222c | Michael R. Hines | s = migrate_get_current(); |
503 | 60d9222c | Michael R. Hines | |
504 | 60d9222c | Michael R. Hines | return s->enabled_capabilities[MIGRATION_CAPABILITY_X_RDMA_PIN_ALL];
|
505 | 60d9222c | Michael R. Hines | } |
506 | 60d9222c | Michael R. Hines | |
507 | bde1e2ec | Chegu Vinod | bool migrate_auto_converge(void) |
508 | bde1e2ec | Chegu Vinod | { |
509 | bde1e2ec | Chegu Vinod | MigrationState *s; |
510 | bde1e2ec | Chegu Vinod | |
511 | bde1e2ec | Chegu Vinod | s = migrate_get_current(); |
512 | bde1e2ec | Chegu Vinod | |
513 | bde1e2ec | Chegu Vinod | return s->enabled_capabilities[MIGRATION_CAPABILITY_AUTO_CONVERGE];
|
514 | bde1e2ec | Chegu Vinod | } |
515 | bde1e2ec | Chegu Vinod | |
516 | 323004a3 | Peter Lieven | bool migrate_zero_blocks(void) |
517 | 323004a3 | Peter Lieven | { |
518 | 323004a3 | Peter Lieven | MigrationState *s; |
519 | 323004a3 | Peter Lieven | |
520 | 323004a3 | Peter Lieven | s = migrate_get_current(); |
521 | 323004a3 | Peter Lieven | |
522 | 323004a3 | Peter Lieven | return s->enabled_capabilities[MIGRATION_CAPABILITY_ZERO_BLOCKS];
|
523 | 323004a3 | Peter Lieven | } |
524 | 323004a3 | Peter Lieven | |
525 | 17ad9b35 | Orit Wasserman | int migrate_use_xbzrle(void) |
526 | 17ad9b35 | Orit Wasserman | { |
527 | 17ad9b35 | Orit Wasserman | MigrationState *s; |
528 | 17ad9b35 | Orit Wasserman | |
529 | 17ad9b35 | Orit Wasserman | s = migrate_get_current(); |
530 | 17ad9b35 | Orit Wasserman | |
531 | 17ad9b35 | Orit Wasserman | return s->enabled_capabilities[MIGRATION_CAPABILITY_XBZRLE];
|
532 | 17ad9b35 | Orit Wasserman | } |
533 | 17ad9b35 | Orit Wasserman | |
534 | 17ad9b35 | Orit Wasserman | int64_t migrate_xbzrle_cache_size(void)
|
535 | 17ad9b35 | Orit Wasserman | { |
536 | 17ad9b35 | Orit Wasserman | MigrationState *s; |
537 | 17ad9b35 | Orit Wasserman | |
538 | 17ad9b35 | Orit Wasserman | s = migrate_get_current(); |
539 | 17ad9b35 | Orit Wasserman | |
540 | 17ad9b35 | Orit Wasserman | return s->xbzrle_cache_size;
|
541 | 17ad9b35 | Orit Wasserman | } |
542 | 0d82d0e8 | Juan Quintela | |
543 | 0d82d0e8 | Juan Quintela | /* migration thread support */
|
544 | 0d82d0e8 | Juan Quintela | |
545 | 5f496a1b | Juan Quintela | static void *migration_thread(void *opaque) |
546 | 0d82d0e8 | Juan Quintela | { |
547 | 9848a404 | Juan Quintela | MigrationState *s = opaque; |
548 | bc72ad67 | Alex Bligh | int64_t initial_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); |
549 | bc72ad67 | Alex Bligh | int64_t setup_start = qemu_clock_get_ms(QEMU_CLOCK_HOST); |
550 | be7172e2 | Paolo Bonzini | int64_t initial_bytes = 0;
|
551 | 0d82d0e8 | Juan Quintela | int64_t max_size = 0;
|
552 | a3fa1d78 | Paolo Bonzini | int64_t start_time = initial_time; |
553 | a3fa1d78 | Paolo Bonzini | bool old_vm_running = false; |
554 | 76f5933a | Juan Quintela | |
555 | 76f5933a | Juan Quintela | DPRINTF("beginning savevm\n");
|
556 | dba433c0 | Paolo Bonzini | qemu_savevm_state_begin(s->file, &s->params); |
557 | 0d82d0e8 | Juan Quintela | |
558 | bc72ad67 | Alex Bligh | s->setup_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) - setup_start; |
559 | 29ae8a41 | Michael R. Hines | migrate_set_state(s, MIG_STATE_SETUP, MIG_STATE_ACTIVE); |
560 | 29ae8a41 | Michael R. Hines | |
561 | ed4fbd10 | Michael R. Hines | DPRINTF("setup complete\n");
|
562 | ed4fbd10 | Michael R. Hines | |
563 | dba433c0 | Paolo Bonzini | while (s->state == MIG_STATE_ACTIVE) {
|
564 | a3e879cd | Juan Quintela | int64_t current_time; |
565 | c369f40d | Juan Quintela | uint64_t pending_size; |
566 | 0d82d0e8 | Juan Quintela | |
567 | a0ff044b | Paolo Bonzini | if (!qemu_file_rate_limit(s->file)) {
|
568 | c369f40d | Juan Quintela | DPRINTF("iterate\n");
|
569 | c369f40d | Juan Quintela | pending_size = qemu_savevm_state_pending(s->file, max_size); |
570 | c369f40d | Juan Quintela | DPRINTF("pending size %lu max %lu\n", pending_size, max_size);
|
571 | b22ff1fb | Juan Quintela | if (pending_size && pending_size >= max_size) {
|
572 | dba433c0 | Paolo Bonzini | qemu_savevm_state_iterate(s->file); |
573 | c369f40d | Juan Quintela | } else {
|
574 | 0e1146a7 | Kevin Wolf | int ret;
|
575 | 0e1146a7 | Kevin Wolf | |
576 | c369f40d | Juan Quintela | DPRINTF("done iterating\n");
|
577 | 32c835ba | Paolo Bonzini | qemu_mutex_lock_iothread(); |
578 | bc72ad67 | Alex Bligh | start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); |
579 | c369f40d | Juan Quintela | qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); |
580 | a3fa1d78 | Paolo Bonzini | old_vm_running = runstate_is_running(); |
581 | 0e1146a7 | Kevin Wolf | |
582 | 0e1146a7 | Kevin Wolf | ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE); |
583 | 0e1146a7 | Kevin Wolf | if (ret >= 0) { |
584 | 0e1146a7 | Kevin Wolf | qemu_file_set_rate_limit(s->file, INT_MAX); |
585 | 0e1146a7 | Kevin Wolf | qemu_savevm_state_complete(s->file); |
586 | 0e1146a7 | Kevin Wolf | } |
587 | 32c835ba | Paolo Bonzini | qemu_mutex_unlock_iothread(); |
588 | 0e1146a7 | Kevin Wolf | |
589 | 0e1146a7 | Kevin Wolf | if (ret < 0) { |
590 | d58f574b | Michael R. Hines | migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_ERROR); |
591 | 0e1146a7 | Kevin Wolf | break;
|
592 | 0e1146a7 | Kevin Wolf | } |
593 | 0e1146a7 | Kevin Wolf | |
594 | 059f896c | Paolo Bonzini | if (!qemu_file_get_error(s->file)) {
|
595 | d58f574b | Michael R. Hines | migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_COMPLETED); |
596 | 059f896c | Paolo Bonzini | break;
|
597 | 059f896c | Paolo Bonzini | } |
598 | c369f40d | Juan Quintela | } |
599 | c369f40d | Juan Quintela | } |
600 | f4410a5d | Paolo Bonzini | |
601 | fd45ee2c | Paolo Bonzini | if (qemu_file_get_error(s->file)) {
|
602 | d58f574b | Michael R. Hines | migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_ERROR); |
603 | fd45ee2c | Paolo Bonzini | break;
|
604 | fd45ee2c | Paolo Bonzini | } |
605 | bc72ad67 | Alex Bligh | current_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); |
606 | 0d82d0e8 | Juan Quintela | if (current_time >= initial_time + BUFFER_DELAY) {
|
607 | be7172e2 | Paolo Bonzini | uint64_t transferred_bytes = qemu_ftell(s->file) - initial_bytes; |
608 | 77417f10 | Michael Roth | uint64_t time_spent = current_time - initial_time; |
609 | 0d82d0e8 | Juan Quintela | double bandwidth = transferred_bytes / time_spent;
|
610 | 0d82d0e8 | Juan Quintela | max_size = bandwidth * migrate_max_downtime() / 1000000;
|
611 | 0d82d0e8 | Juan Quintela | |
612 | 7e114f8c | Michael R. Hines | s->mbps = time_spent ? (((double) transferred_bytes * 8.0) / |
613 | 7e114f8c | Michael R. Hines | ((double) time_spent / 1000.0)) / 1000.0 / 1000.0 : -1; |
614 | 7e114f8c | Michael R. Hines | |
615 | 0d82d0e8 | Juan Quintela | DPRINTF("transferred %" PRIu64 " time_spent %" PRIu64 |
616 | 0d82d0e8 | Juan Quintela | " bandwidth %g max_size %" PRId64 "\n", |
617 | 0d82d0e8 | Juan Quintela | transferred_bytes, time_spent, bandwidth, max_size); |
618 | 90f8ae72 | Juan Quintela | /* if we haven't sent anything, we don't want to recalculate
|
619 | 90f8ae72 | Juan Quintela | 10000 is a small enough number for our purposes */
|
620 | 90f8ae72 | Juan Quintela | if (s->dirty_bytes_rate && transferred_bytes > 10000) { |
621 | 90f8ae72 | Juan Quintela | s->expected_downtime = s->dirty_bytes_rate / bandwidth; |
622 | 90f8ae72 | Juan Quintela | } |
623 | 0d82d0e8 | Juan Quintela | |
624 | 1964a397 | Paolo Bonzini | qemu_file_reset_rate_limit(s->file); |
625 | 0d82d0e8 | Juan Quintela | initial_time = current_time; |
626 | be7172e2 | Paolo Bonzini | initial_bytes = qemu_ftell(s->file); |
627 | 0d82d0e8 | Juan Quintela | } |
628 | a0ff044b | Paolo Bonzini | if (qemu_file_rate_limit(s->file)) {
|
629 | 0d82d0e8 | Juan Quintela | /* usleep expects microseconds */
|
630 | 0d82d0e8 | Juan Quintela | g_usleep((initial_time + BUFFER_DELAY - current_time)*1000);
|
631 | 0d82d0e8 | Juan Quintela | } |
632 | a3fa1d78 | Paolo Bonzini | } |
633 | a3fa1d78 | Paolo Bonzini | |
634 | f4410a5d | Paolo Bonzini | qemu_mutex_lock_iothread(); |
635 | a3fa1d78 | Paolo Bonzini | if (s->state == MIG_STATE_COMPLETED) {
|
636 | bc72ad67 | Alex Bligh | int64_t end_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); |
637 | a3fa1d78 | Paolo Bonzini | s->total_time = end_time - s->total_time; |
638 | a3fa1d78 | Paolo Bonzini | s->downtime = end_time - start_time; |
639 | a3fa1d78 | Paolo Bonzini | runstate_set(RUN_STATE_POSTMIGRATE); |
640 | a3fa1d78 | Paolo Bonzini | } else {
|
641 | a3fa1d78 | Paolo Bonzini | if (old_vm_running) {
|
642 | a3fa1d78 | Paolo Bonzini | vm_start(); |
643 | dba433c0 | Paolo Bonzini | } |
644 | 0d82d0e8 | Juan Quintela | } |
645 | bb1fadc4 | Paolo Bonzini | qemu_bh_schedule(s->cleanup_bh); |
646 | dba433c0 | Paolo Bonzini | qemu_mutex_unlock_iothread(); |
647 | f4410a5d | Paolo Bonzini | |
648 | 0d82d0e8 | Juan Quintela | return NULL; |
649 | 0d82d0e8 | Juan Quintela | } |
650 | 0d82d0e8 | Juan Quintela | |
651 | 9848a404 | Juan Quintela | void migrate_fd_connect(MigrationState *s)
|
652 | 0d82d0e8 | Juan Quintela | { |
653 | 29ae8a41 | Michael R. Hines | s->state = MIG_STATE_SETUP; |
654 | 29ae8a41 | Michael R. Hines | trace_migrate_set_state(MIG_STATE_SETUP); |
655 | c09e5bb1 | Kazuya Saito | |
656 | cc283e3b | Juan Quintela | /* This is a best 1st approximation. ns to ms */
|
657 | cc283e3b | Juan Quintela | s->expected_downtime = max_downtime/1000000;
|
658 | bb1fadc4 | Paolo Bonzini | s->cleanup_bh = qemu_bh_new(migrate_fd_cleanup, s); |
659 | 0d82d0e8 | Juan Quintela | |
660 | 442773ce | Paolo Bonzini | qemu_file_set_rate_limit(s->file, |
661 | 442773ce | Paolo Bonzini | s->bandwidth_limit / XFER_LIMIT_RATIO); |
662 | 442773ce | Paolo Bonzini | |
663 | 9287ac27 | Stefan Hajnoczi | /* Notify before starting migration thread */
|
664 | 9287ac27 | Stefan Hajnoczi | notifier_list_notify(&migration_state_notifiers, s); |
665 | 9287ac27 | Stefan Hajnoczi | |
666 | 5f496a1b | Juan Quintela | qemu_thread_create(&s->thread, migration_thread, s, |
667 | bb1fadc4 | Paolo Bonzini | QEMU_THREAD_JOINABLE); |
668 | 0d82d0e8 | Juan Quintela | } |