Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 443 lines (358 sloc) 11.413 kb
5bb7910 Introduce UI for live migration
aliguori authored
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 */
13
14 #include "qemu-common.h"
15 #include "migration.h"
376253e monitor: Rework API (Jan Kiszka)
aliguori authored
16 #include "monitor.h"
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
17 #include "buffered_file.h"
18 #include "sysemu.h"
19 #include "block.h"
20 #include "qemu_socket.h"
25f2364 @jan-kiszka block migration: Report progress also via info migration
jan-kiszka authored
21 #include "block-migration.h"
c86a668 migration: Convert do_info_migrate() to QObject
Luiz Capitulino authored
22 #include "qemu-objects.h"
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
23
24 //#define DEBUG_MIGRATION
25
26 #ifdef DEBUG_MIGRATION
d0f2c4c @moosotc Do not use dprintf
moosotc authored
27 #define DPRINTF(fmt, ...) \
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
28 do { printf("migration: " fmt, ## __VA_ARGS__); } while (0)
29 #else
d0f2c4c @moosotc Do not use dprintf
moosotc authored
30 #define DPRINTF(fmt, ...) \
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
31 do { } while (0)
32 #endif
5bb7910 Introduce UI for live migration
aliguori authored
33
34 /* Migration speed throttling */
35 static uint32_t max_throttle = (32 << 20);
36
37 static MigrationState *current_migration;
38
8ca5e80 @juanquintela Exit if incoming migration fails
juanquintela authored
39 int qemu_start_incoming_migration(const char *uri)
5bb7910 Introduce UI for live migration
aliguori authored
40 {
34c9dd8 Introduce TCP live migration protocol
aliguori authored
41 const char *p;
8ca5e80 @juanquintela Exit if incoming migration fails
juanquintela authored
42 int ret;
34c9dd8 Introduce TCP live migration protocol
aliguori authored
43
44 if (strstart(uri, "tcp:", &p))
8ca5e80 @juanquintela Exit if incoming migration fails
juanquintela authored
45 ret = tcp_start_incoming_migration(p);
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
46 #if !defined(WIN32)
47 else if (strstart(uri, "exec:", &p))
8ca5e80 @juanquintela Exit if incoming migration fails
juanquintela authored
48 ret = exec_start_incoming_migration(p);
4951f65 Migration via unix sockets.
Chris Lalancette authored
49 else if (strstart(uri, "unix:", &p))
8ca5e80 @juanquintela Exit if incoming migration fails
juanquintela authored
50 ret = unix_start_incoming_migration(p);
5ac1fad @bonzini add file descriptor migration
bonzini authored
51 else if (strstart(uri, "fd:", &p))
8ca5e80 @juanquintela Exit if incoming migration fails
juanquintela authored
52 ret = fd_start_incoming_migration(p);
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
53 #endif
8ca5e80 @juanquintela Exit if incoming migration fails
juanquintela authored
54 else {
34c9dd8 Introduce TCP live migration protocol
aliguori authored
55 fprintf(stderr, "unknown migration protocol: %s\n", uri);
8ca5e80 @juanquintela Exit if incoming migration fails
juanquintela authored
56 ret = -EPROTONOSUPPORT;
57 }
58 return ret;
5bb7910 Introduce UI for live migration
aliguori authored
59 }
60
511c023 @juanquintela Factorize common migration incoming code
juanquintela authored
61 void process_incoming_migration(QEMUFile *f)
62 {
63 if (qemu_loadvm_state(f) < 0) {
64 fprintf(stderr, "load of migration failed\n");
65 exit(0);
66 }
67 qemu_announce_self();
68 DPRINTF("successfully loaded vm state\n");
69
70 if (autostart)
71 vm_start();
72 }
73
b5d17ad Monitor: Convert do_migrate() to cmd_new_ret()
Luiz Capitulino authored
74 int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data)
5bb7910 Introduce UI for live migration
aliguori authored
75 {
34c9dd8 Introduce TCP live migration protocol
aliguori authored
76 MigrationState *s = NULL;
77 const char *p;
eb159d1 Monitor: handle optional '-' arg as a bool
Luiz Capitulino authored
78 int detach = qdict_get_try_bool(qdict, "detach", 0);
79 int blk = qdict_get_try_bool(qdict, "blk", 0);
80 int inc = qdict_get_try_bool(qdict, "inc", 0);
f18c16d monitor: Port handler_2 to use QDict
Luiz Capitulino authored
81 const char *uri = qdict_get_str(qdict, "uri");
1302425 @jan-kiszka migration: Catch multiple start commands
jan-kiszka authored
82
83 if (current_migration &&
84 current_migration->get_status(current_migration) == MIG_STATE_ACTIVE) {
85 monitor_printf(mon, "migration already in progress\n");
b5d17ad Monitor: Convert do_migrate() to cmd_new_ret()
Luiz Capitulino authored
86 return -1;
1302425 @jan-kiszka migration: Catch multiple start commands
jan-kiszka authored
87 }
88
b5d17ad Monitor: Convert do_migrate() to cmd_new_ret()
Luiz Capitulino authored
89 if (strstart(uri, "tcp:", &p)) {
f327aa0 @jan-kiszka live migration: Propagate output monitor to callback handler
jan-kiszka authored
90 s = tcp_start_outgoing_migration(mon, p, max_throttle, detach,
eb159d1 Monitor: handle optional '-' arg as a bool
Luiz Capitulino authored
91 blk, inc);
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
92 #if !defined(WIN32)
b5d17ad Monitor: Convert do_migrate() to cmd_new_ret()
Luiz Capitulino authored
93 } else if (strstart(uri, "exec:", &p)) {
f327aa0 @jan-kiszka live migration: Propagate output monitor to callback handler
jan-kiszka authored
94 s = exec_start_outgoing_migration(mon, p, max_throttle, detach,
eb159d1 Monitor: handle optional '-' arg as a bool
Luiz Capitulino authored
95 blk, inc);
b5d17ad Monitor: Convert do_migrate() to cmd_new_ret()
Luiz Capitulino authored
96 } else if (strstart(uri, "unix:", &p)) {
f327aa0 @jan-kiszka live migration: Propagate output monitor to callback handler
jan-kiszka authored
97 s = unix_start_outgoing_migration(mon, p, max_throttle, detach,
eb159d1 Monitor: handle optional '-' arg as a bool
Luiz Capitulino authored
98 blk, inc);
b5d17ad Monitor: Convert do_migrate() to cmd_new_ret()
Luiz Capitulino authored
99 } else if (strstart(uri, "fd:", &p)) {
c163b5c @liranschour Block live migration
liranschour authored
100 s = fd_start_outgoing_migration(mon, p, max_throttle, detach,
eb159d1 Monitor: handle optional '-' arg as a bool
Luiz Capitulino authored
101 blk, inc);
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
102 #endif
b5d17ad Monitor: Convert do_migrate() to cmd_new_ret()
Luiz Capitulino authored
103 } else {
376253e monitor: Rework API (Jan Kiszka)
aliguori authored
104 monitor_printf(mon, "unknown migration protocol: %s\n", uri);
b5d17ad Monitor: Convert do_migrate() to cmd_new_ret()
Luiz Capitulino authored
105 return -1;
106 }
34c9dd8 Introduce TCP live migration protocol
aliguori authored
107
b5d17ad Monitor: Convert do_migrate() to cmd_new_ret()
Luiz Capitulino authored
108 if (s == NULL) {
376253e monitor: Rework API (Jan Kiszka)
aliguori authored
109 monitor_printf(mon, "migration failed\n");
b5d17ad Monitor: Convert do_migrate() to cmd_new_ret()
Luiz Capitulino authored
110 return -1;
111 }
34c9dd8 Introduce TCP live migration protocol
aliguori authored
112
b5d17ad Monitor: Convert do_migrate() to cmd_new_ret()
Luiz Capitulino authored
113 if (current_migration) {
114 current_migration->release(current_migration);
34c9dd8 Introduce TCP live migration protocol
aliguori authored
115 }
b5d17ad Monitor: Convert do_migrate() to cmd_new_ret()
Luiz Capitulino authored
116
117 current_migration = s;
118 return 0;
5bb7910 Introduce UI for live migration
aliguori authored
119 }
120
ef4b7ee Monitor: Convert simple handlers to cmd_new_ret()
Luiz Capitulino authored
121 int do_migrate_cancel(Monitor *mon, const QDict *qdict, QObject **ret_data)
5bb7910 Introduce UI for live migration
aliguori authored
122 {
123 MigrationState *s = current_migration;
124
125 if (s)
ff8d81d Fix whitespace in migration code.
aliguori authored
126 s->cancel(s);
ef4b7ee Monitor: Convert simple handlers to cmd_new_ret()
Luiz Capitulino authored
127
128 return 0;
5bb7910 Introduce UI for live migration
aliguori authored
129 }
130
ef4b7ee Monitor: Convert simple handlers to cmd_new_ret()
Luiz Capitulino authored
131 int do_migrate_set_speed(Monitor *mon, const QDict *qdict, QObject **ret_data)
5bb7910 Introduce UI for live migration
aliguori authored
132 {
133 double d;
daa91de allow changing the speed of a running migration
Glauber Costa authored
134 FdMigrationState *s;
5bb7910 Introduce UI for live migration
aliguori authored
135
5667c49 monitor: Use argument type 'b' for migrate_set_speed
Markus Armbruster authored
136 d = qdict_get_double(qdict, "value");
137 d = MAX(0, MIN(UINT32_MAX, d));
138 max_throttle = d;
daa91de allow changing the speed of a running migration
Glauber Costa authored
139
5d39c79 @jan-kiszka migration: Fix use of file after release
jan-kiszka authored
140 s = migrate_to_fms(current_migration);
141 if (s && s->file) {
daa91de allow changing the speed of a running migration
Glauber Costa authored
142 qemu_file_set_rate_limit(s->file, max_throttle);
143 }
ef4b7ee Monitor: Convert simple handlers to cmd_new_ret()
Luiz Capitulino authored
144
145 return 0;
5bb7910 Introduce UI for live migration
aliguori authored
146 }
147
a0a3fd6 add non-arbitrary migration stop condition
Glauber Costa authored
148 /* amount of nanoseconds we are willing to wait for migration to be down.
149 * the choice of nanoseconds is because it is the maximum resolution that
150 * get_clock() can achieve. It is an internal measure. All user-visible
151 * units must be in seconds */
152 static uint64_t max_downtime = 30000000;
153
154 uint64_t migrate_max_downtime(void)
155 {
156 return max_downtime;
157 }
158
ef4b7ee Monitor: Convert simple handlers to cmd_new_ret()
Luiz Capitulino authored
159 int do_migrate_set_downtime(Monitor *mon, const QDict *qdict,
160 QObject **ret_data)
2ea4295 set migration max downtime
Glauber Costa authored
161 {
162 double d;
163
b0fbf7d monitor: Use argument type 'T' for migrate_set_downtime
Markus Armbruster authored
164 d = qdict_get_double(qdict, "value") * 1e9;
165 d = MAX(0, MIN(UINT64_MAX, d));
2ea4295 set migration max downtime
Glauber Costa authored
166 max_downtime = (uint64_t)d;
ef4b7ee Monitor: Convert simple handlers to cmd_new_ret()
Luiz Capitulino authored
167
168 return 0;
2ea4295 set migration max downtime
Glauber Costa authored
169 }
170
c86a668 migration: Convert do_info_migrate() to QObject
Luiz Capitulino authored
171 static void migrate_print_status(Monitor *mon, const char *name,
172 const QDict *status_dict)
5bb7910 Introduce UI for live migration
aliguori authored
173 {
c86a668 migration: Convert do_info_migrate() to QObject
Luiz Capitulino authored
174 QDict *qdict;
175
176 qdict = qobject_to_qdict(qdict_get(status_dict, name));
177
178 monitor_printf(mon, "transferred %s: %" PRIu64 " kbytes\n", name,
179 qdict_get_int(qdict, "transferred") >> 10);
180 monitor_printf(mon, "remaining %s: %" PRIu64 " kbytes\n", name,
181 qdict_get_int(qdict, "remaining") >> 10);
182 monitor_printf(mon, "total %s: %" PRIu64 " kbytes\n", name,
183 qdict_get_int(qdict, "total") >> 10);
184 }
185
186 void do_info_migrate_print(Monitor *mon, const QObject *data)
187 {
188 QDict *qdict;
189
190 qdict = qobject_to_qdict(data);
191
192 monitor_printf(mon, "Migration status: %s\n",
193 qdict_get_str(qdict, "status"));
194
195 if (qdict_haskey(qdict, "ram")) {
196 migrate_print_status(mon, "ram", qdict);
197 }
198
199 if (qdict_haskey(qdict, "disk")) {
200 migrate_print_status(mon, "disk", qdict);
201 }
202 }
203
204 static void migrate_put_status(QDict *qdict, const char *name,
205 uint64_t trans, uint64_t rem, uint64_t total)
206 {
207 QObject *obj;
208
209 obj = qobject_from_jsonf("{ 'transferred': %" PRId64 ", "
210 "'remaining': %" PRId64 ", "
211 "'total': %" PRId64 " }", trans, rem, total);
212 qdict_put_obj(qdict, name, obj);
213 }
214
215 void do_info_migrate(Monitor *mon, QObject **ret_data)
216 {
217 QDict *qdict;
5bb7910 Introduce UI for live migration
aliguori authored
218 MigrationState *s = current_migration;
376253e monitor: Rework API (Jan Kiszka)
aliguori authored
219
5bb7910 Introduce UI for live migration
aliguori authored
220 if (s) {
ff8d81d Fix whitespace in migration code.
aliguori authored
221 switch (s->get_status(s)) {
222 case MIG_STATE_ACTIVE:
c86a668 migration: Convert do_info_migrate() to QObject
Luiz Capitulino authored
223 qdict = qdict_new();
224 qdict_put(qdict, "status", qstring_from_str("active"));
225
226 migrate_put_status(qdict, "ram", ram_bytes_transferred(),
227 ram_bytes_remaining(), ram_bytes_total());
228
25f2364 @jan-kiszka block migration: Report progress also via info migration
jan-kiszka authored
229 if (blk_mig_active()) {
c86a668 migration: Convert do_info_migrate() to QObject
Luiz Capitulino authored
230 migrate_put_status(qdict, "disk", blk_mig_bytes_transferred(),
231 blk_mig_bytes_remaining(),
232 blk_mig_bytes_total());
25f2364 @jan-kiszka block migration: Report progress also via info migration
jan-kiszka authored
233 }
c86a668 migration: Convert do_info_migrate() to QObject
Luiz Capitulino authored
234
235 *ret_data = QOBJECT(qdict);
ff8d81d Fix whitespace in migration code.
aliguori authored
236 break;
237 case MIG_STATE_COMPLETED:
c86a668 migration: Convert do_info_migrate() to QObject
Luiz Capitulino authored
238 *ret_data = qobject_from_jsonf("{ 'status': 'completed' }");
ff8d81d Fix whitespace in migration code.
aliguori authored
239 break;
240 case MIG_STATE_ERROR:
c86a668 migration: Convert do_info_migrate() to QObject
Luiz Capitulino authored
241 *ret_data = qobject_from_jsonf("{ 'status': 'failed' }");
ff8d81d Fix whitespace in migration code.
aliguori authored
242 break;
243 case MIG_STATE_CANCELLED:
c86a668 migration: Convert do_info_migrate() to QObject
Luiz Capitulino authored
244 *ret_data = qobject_from_jsonf("{ 'status': 'cancelled' }");
ff8d81d Fix whitespace in migration code.
aliguori authored
245 break;
246 }
5bb7910 Introduce UI for live migration
aliguori authored
247 }
248 }
249
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
250 /* shared migration helpers */
251
f327aa0 @jan-kiszka live migration: Propagate output monitor to callback handler
jan-kiszka authored
252 void migrate_fd_monitor_suspend(FdMigrationState *s, Monitor *mon)
731b036 monitor: Decouple terminals (Jan Kiszka)
aliguori authored
253 {
f327aa0 @jan-kiszka live migration: Propagate output monitor to callback handler
jan-kiszka authored
254 s->mon = mon;
255 if (monitor_suspend(mon) == 0) {
d0f2c4c @moosotc Do not use dprintf
moosotc authored
256 DPRINTF("suspending monitor\n");
f327aa0 @jan-kiszka live migration: Propagate output monitor to callback handler
jan-kiszka authored
257 } else {
258 monitor_printf(mon, "terminal does not allow synchronous "
cde76ee monitor: Introduce MONITOR_USE_READLINE flag (Jan Kiszka)
aliguori authored
259 "migration, continuing detached\n");
f327aa0 @jan-kiszka live migration: Propagate output monitor to callback handler
jan-kiszka authored
260 }
731b036 monitor: Decouple terminals (Jan Kiszka)
aliguori authored
261 }
262
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
263 void migrate_fd_error(FdMigrationState *s)
264 {
d0f2c4c @moosotc Do not use dprintf
moosotc authored
265 DPRINTF("setting error state\n");
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
266 s->state = MIG_STATE_ERROR;
267 migrate_fd_cleanup(s);
268 }
269
41ef56e migration: respect exit status with exec:
Anthony Liguori authored
270 int migrate_fd_cleanup(FdMigrationState *s)
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
271 {
41ef56e migration: respect exit status with exec:
Anthony Liguori authored
272 int ret = 0;
273
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
274 qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
275
276 if (s->file) {
d0f2c4c @moosotc Do not use dprintf
moosotc authored
277 DPRINTF("closing file\n");
41ef56e migration: respect exit status with exec:
Anthony Liguori authored
278 if (qemu_fclose(s->file) != 0) {
279 ret = -1;
280 }
5d39c79 @jan-kiszka migration: Fix use of file after release
jan-kiszka authored
281 s->file = NULL;
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
282 }
283
284 if (s->fd != -1)
285 close(s->fd);
286
287 /* Don't resume monitor until we've flushed all of the buffers */
f327aa0 @jan-kiszka live migration: Propagate output monitor to callback handler
jan-kiszka authored
288 if (s->mon) {
289 monitor_resume(s->mon);
290 }
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
291
292 s->fd = -1;
41ef56e migration: respect exit status with exec:
Anthony Liguori authored
293
294 return ret;
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
295 }
296
297 void migrate_fd_put_notify(void *opaque)
298 {
299 FdMigrationState *s = opaque;
300
301 qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
302 qemu_file_put_notify(s->file);
303 }
304
305 ssize_t migrate_fd_put_buffer(void *opaque, const void *data, size_t size)
306 {
307 FdMigrationState *s = opaque;
308 ssize_t ret;
309
310 do {
311 ret = s->write(s, data, size);
95b134e migrate.c: migrate_fd_put_buffer: Do not busyloop: stop writing if EW…
Uri Lublin authored
312 } while (ret == -1 && ((s->get_error(s)) == EINTR));
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
313
314 if (ret == -1)
315 ret = -(s->get_error(s));
316
317 if (ret == -EAGAIN)
318 qemu_set_fd_handler2(s->fd, NULL, NULL, migrate_fd_put_notify, s);
319
320 return ret;
321 }
322
323 void migrate_fd_connect(FdMigrationState *s)
324 {
325 int ret;
326
327 s->file = qemu_fopen_ops_buffered(s,
328 s->bandwidth_limit,
329 migrate_fd_put_buffer,
330 migrate_fd_put_ready,
331 migrate_fd_wait_for_unfreeze,
332 migrate_fd_close);
333
d0f2c4c @moosotc Do not use dprintf
moosotc authored
334 DPRINTF("beginning savevm\n");
f327aa0 @jan-kiszka live migration: Propagate output monitor to callback handler
jan-kiszka authored
335 ret = qemu_savevm_state_begin(s->mon, s->file, s->mig_state.blk,
c163b5c @liranschour Block live migration
liranschour authored
336 s->mig_state.shared);
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
337 if (ret < 0) {
d0f2c4c @moosotc Do not use dprintf
moosotc authored
338 DPRINTF("failed, %d\n", ret);
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
339 migrate_fd_error(s);
340 return;
341 }
c163b5c @liranschour Block live migration
liranschour authored
342
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
343 migrate_fd_put_ready(s);
344 }
345
346 void migrate_fd_put_ready(void *opaque)
347 {
348 FdMigrationState *s = opaque;
349
350 if (s->state != MIG_STATE_ACTIVE) {
d0f2c4c @moosotc Do not use dprintf
moosotc authored
351 DPRINTF("put_ready returning because of non-active state\n");
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
352 return;
353 }
354
d0f2c4c @moosotc Do not use dprintf
moosotc authored
355 DPRINTF("iterate\n");
f327aa0 @jan-kiszka live migration: Propagate output monitor to callback handler
jan-kiszka authored
356 if (qemu_savevm_state_iterate(s->mon, s->file) == 1) {
b161d12 propagate error on failed completion (Glauber Costa)
aliguori authored
357 int state;
eeb34af Make sure to only vm_start() a failed migration if we were running to…
Anthony Liguori authored
358 int old_vm_running = vm_running;
359
d0f2c4c @moosotc Do not use dprintf
moosotc authored
360 DPRINTF("done iterating\n");
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
361 vm_stop(0);
362
0884657 flush pending aio requests
Glauber Costa authored
363 qemu_aio_flush();
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
364 bdrv_flush_all();
f327aa0 @jan-kiszka live migration: Propagate output monitor to callback handler
jan-kiszka authored
365 if ((qemu_savevm_state_complete(s->mon, s->file)) < 0) {
eeb34af Make sure to only vm_start() a failed migration if we were running to…
Anthony Liguori authored
366 if (old_vm_running) {
367 vm_start();
368 }
b161d12 propagate error on failed completion (Glauber Costa)
aliguori authored
369 state = MIG_STATE_ERROR;
370 } else {
371 state = MIG_STATE_COMPLETED;
372 }
41ef56e migration: respect exit status with exec:
Anthony Liguori authored
373 if (migrate_fd_cleanup(s) < 0) {
374 if (old_vm_running) {
375 vm_start();
376 }
377 state = MIG_STATE_ERROR;
378 }
b161d12 propagate error on failed completion (Glauber Costa)
aliguori authored
379 s->state = state;
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
380 }
381 }
382
383 int migrate_fd_get_status(MigrationState *mig_state)
384 {
385 FdMigrationState *s = migrate_to_fms(mig_state);
386 return s->state;
387 }
388
389 void migrate_fd_cancel(MigrationState *mig_state)
390 {
391 FdMigrationState *s = migrate_to_fms(mig_state);
392
393 if (s->state != MIG_STATE_ACTIVE)
394 return;
395
d0f2c4c @moosotc Do not use dprintf
moosotc authored
396 DPRINTF("cancelling migration\n");
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
397
398 s->state = MIG_STATE_CANCELLED;
f327aa0 @jan-kiszka live migration: Propagate output monitor to callback handler
jan-kiszka authored
399 qemu_savevm_state_cancel(s->mon, s->file);
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
400
401 migrate_fd_cleanup(s);
402 }
403
404 void migrate_fd_release(MigrationState *mig_state)
405 {
406 FdMigrationState *s = migrate_to_fms(mig_state);
407
d0f2c4c @moosotc Do not use dprintf
moosotc authored
408 DPRINTF("releasing state\n");
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
409
410 if (s->state == MIG_STATE_ACTIVE) {
411 s->state = MIG_STATE_CANCELLED;
412 migrate_fd_cleanup(s);
413 }
faa1f8d migration: use qemu_free() instead of free().
Yoshiaki Tamura authored
414 qemu_free(s);
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
415 }
416
417 void migrate_fd_wait_for_unfreeze(void *opaque)
418 {
419 FdMigrationState *s = opaque;
420 int ret;
421
d0f2c4c @moosotc Do not use dprintf
moosotc authored
422 DPRINTF("wait for unfreeze\n");
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
423 if (s->state != MIG_STATE_ACTIVE)
424 return;
425
426 do {
427 fd_set wfds;
428
429 FD_ZERO(&wfds);
430 FD_SET(s->fd, &wfds);
431
432 ret = select(s->fd + 1, NULL, &wfds, NULL, NULL);
433 } while (ret == -1 && (s->get_error(s)) == EINTR);
434 }
435
436 int migrate_fd_close(void *opaque)
437 {
438 FdMigrationState *s = opaque;
e19252d migrate_fd_close: delete associated io-handler before closing the fd
Uri Lublin authored
439
440 qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
065e281 Reintroduce migrate-to-exec: support (Charles Duffy)
aliguori authored
441 return s->close(s);
442 }
Something went wrong with that request. Please try again.