root / migration.c @ c05c7a73
History | View | Annotate | Download (12.1 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 | 5bb7910a | aliguori | */
|
13 | 5bb7910a | aliguori | |
14 | 5bb7910a | aliguori | #include "qemu-common.h" |
15 | 5bb7910a | aliguori | #include "migration.h" |
16 | 376253ec | aliguori | #include "monitor.h" |
17 | 065e2813 | aliguori | #include "buffered_file.h" |
18 | 065e2813 | aliguori | #include "sysemu.h" |
19 | 065e2813 | aliguori | #include "block.h" |
20 | 065e2813 | aliguori | #include "qemu_socket.h" |
21 | 25f23643 | Jan Kiszka | #include "block-migration.h" |
22 | c86a6683 | Luiz Capitulino | #include "qemu-objects.h" |
23 | 065e2813 | aliguori | |
24 | 065e2813 | aliguori | //#define DEBUG_MIGRATION
|
25 | 065e2813 | aliguori | |
26 | 065e2813 | aliguori | #ifdef DEBUG_MIGRATION
|
27 | d0f2c4c6 | malc | #define DPRINTF(fmt, ...) \
|
28 | 065e2813 | aliguori | do { printf("migration: " fmt, ## __VA_ARGS__); } while (0) |
29 | 065e2813 | aliguori | #else
|
30 | d0f2c4c6 | malc | #define DPRINTF(fmt, ...) \
|
31 | 065e2813 | aliguori | do { } while (0) |
32 | 065e2813 | aliguori | #endif
|
33 | 5bb7910a | aliguori | |
34 | 5bb7910a | aliguori | /* Migration speed throttling */
|
35 | 5bb7910a | aliguori | static uint32_t max_throttle = (32 << 20); |
36 | 5bb7910a | aliguori | |
37 | 5bb7910a | aliguori | static MigrationState *current_migration;
|
38 | 5bb7910a | aliguori | |
39 | 5bb7910a | aliguori | void qemu_start_incoming_migration(const char *uri) |
40 | 5bb7910a | aliguori | { |
41 | 34c9dd8e | aliguori | const char *p; |
42 | 34c9dd8e | aliguori | |
43 | 34c9dd8e | aliguori | if (strstart(uri, "tcp:", &p)) |
44 | 34c9dd8e | aliguori | tcp_start_incoming_migration(p); |
45 | 065e2813 | aliguori | #if !defined(WIN32)
|
46 | 065e2813 | aliguori | else if (strstart(uri, "exec:", &p)) |
47 | 065e2813 | aliguori | exec_start_incoming_migration(p); |
48 | 4951f65b | Chris Lalancette | else if (strstart(uri, "unix:", &p)) |
49 | 4951f65b | Chris Lalancette | unix_start_incoming_migration(p); |
50 | 5ac1fad3 | Paolo Bonzini | else if (strstart(uri, "fd:", &p)) |
51 | 5ac1fad3 | Paolo Bonzini | fd_start_incoming_migration(p); |
52 | 065e2813 | aliguori | #endif
|
53 | 34c9dd8e | aliguori | else
|
54 | 34c9dd8e | aliguori | fprintf(stderr, "unknown migration protocol: %s\n", uri);
|
55 | 5bb7910a | aliguori | } |
56 | 5bb7910a | aliguori | |
57 | b5d17adb | Luiz Capitulino | int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data) |
58 | 5bb7910a | aliguori | { |
59 | 34c9dd8e | aliguori | MigrationState *s = NULL;
|
60 | 34c9dd8e | aliguori | const char *p; |
61 | f18c16de | Luiz Capitulino | int detach = qdict_get_int(qdict, "detach"); |
62 | f18c16de | Luiz Capitulino | const char *uri = qdict_get_str(qdict, "uri"); |
63 | 1302425d | Jan Kiszka | |
64 | 1302425d | Jan Kiszka | if (current_migration &&
|
65 | 1302425d | Jan Kiszka | current_migration->get_status(current_migration) == MIG_STATE_ACTIVE) { |
66 | 1302425d | Jan Kiszka | monitor_printf(mon, "migration already in progress\n");
|
67 | b5d17adb | Luiz Capitulino | return -1; |
68 | 1302425d | Jan Kiszka | } |
69 | 1302425d | Jan Kiszka | |
70 | b5d17adb | Luiz Capitulino | if (strstart(uri, "tcp:", &p)) { |
71 | f327aa0c | Jan Kiszka | s = tcp_start_outgoing_migration(mon, p, max_throttle, detach, |
72 | c163b5ca | lirans@il.ibm.com | (int)qdict_get_int(qdict, "blk"), |
73 | c163b5ca | lirans@il.ibm.com | (int)qdict_get_int(qdict, "inc")); |
74 | 065e2813 | aliguori | #if !defined(WIN32)
|
75 | b5d17adb | Luiz Capitulino | } else if (strstart(uri, "exec:", &p)) { |
76 | f327aa0c | Jan Kiszka | s = exec_start_outgoing_migration(mon, p, max_throttle, detach, |
77 | c163b5ca | lirans@il.ibm.com | (int)qdict_get_int(qdict, "blk"), |
78 | c163b5ca | lirans@il.ibm.com | (int)qdict_get_int(qdict, "inc")); |
79 | b5d17adb | Luiz Capitulino | } else if (strstart(uri, "unix:", &p)) { |
80 | f327aa0c | Jan Kiszka | s = unix_start_outgoing_migration(mon, p, max_throttle, detach, |
81 | c163b5ca | lirans@il.ibm.com | (int)qdict_get_int(qdict, "blk"), |
82 | c163b5ca | lirans@il.ibm.com | (int)qdict_get_int(qdict, "inc")); |
83 | b5d17adb | Luiz Capitulino | } else if (strstart(uri, "fd:", &p)) { |
84 | c163b5ca | lirans@il.ibm.com | s = fd_start_outgoing_migration(mon, p, max_throttle, detach, |
85 | c163b5ca | lirans@il.ibm.com | (int)qdict_get_int(qdict, "blk"), |
86 | c163b5ca | lirans@il.ibm.com | (int)qdict_get_int(qdict, "inc")); |
87 | 065e2813 | aliguori | #endif
|
88 | b5d17adb | Luiz Capitulino | } else {
|
89 | 376253ec | aliguori | monitor_printf(mon, "unknown migration protocol: %s\n", uri);
|
90 | b5d17adb | Luiz Capitulino | return -1; |
91 | b5d17adb | Luiz Capitulino | } |
92 | 34c9dd8e | aliguori | |
93 | b5d17adb | Luiz Capitulino | if (s == NULL) { |
94 | 376253ec | aliguori | monitor_printf(mon, "migration failed\n");
|
95 | b5d17adb | Luiz Capitulino | return -1; |
96 | b5d17adb | Luiz Capitulino | } |
97 | 34c9dd8e | aliguori | |
98 | b5d17adb | Luiz Capitulino | if (current_migration) {
|
99 | b5d17adb | Luiz Capitulino | current_migration->release(current_migration); |
100 | 34c9dd8e | aliguori | } |
101 | b5d17adb | Luiz Capitulino | |
102 | b5d17adb | Luiz Capitulino | current_migration = s; |
103 | b5d17adb | Luiz Capitulino | return 0; |
104 | 5bb7910a | aliguori | } |
105 | 5bb7910a | aliguori | |
106 | ef4b7eee | Luiz Capitulino | int do_migrate_cancel(Monitor *mon, const QDict *qdict, QObject **ret_data) |
107 | 5bb7910a | aliguori | { |
108 | 5bb7910a | aliguori | MigrationState *s = current_migration; |
109 | 5bb7910a | aliguori | |
110 | 5bb7910a | aliguori | if (s)
|
111 | ff8d81d8 | aliguori | s->cancel(s); |
112 | ef4b7eee | Luiz Capitulino | |
113 | ef4b7eee | Luiz Capitulino | return 0; |
114 | 5bb7910a | aliguori | } |
115 | 5bb7910a | aliguori | |
116 | ef4b7eee | Luiz Capitulino | int do_migrate_set_speed(Monitor *mon, const QDict *qdict, QObject **ret_data) |
117 | 5bb7910a | aliguori | { |
118 | 5bb7910a | aliguori | double d;
|
119 | daa91de2 | Glauber Costa | FdMigrationState *s; |
120 | 5bb7910a | aliguori | |
121 | 5667c493 | Markus Armbruster | d = qdict_get_double(qdict, "value");
|
122 | 5667c493 | Markus Armbruster | d = MAX(0, MIN(UINT32_MAX, d));
|
123 | 5667c493 | Markus Armbruster | max_throttle = d; |
124 | daa91de2 | Glauber Costa | |
125 | 5d39c799 | Jan Kiszka | s = migrate_to_fms(current_migration); |
126 | 5d39c799 | Jan Kiszka | if (s && s->file) {
|
127 | daa91de2 | Glauber Costa | qemu_file_set_rate_limit(s->file, max_throttle); |
128 | daa91de2 | Glauber Costa | } |
129 | ef4b7eee | Luiz Capitulino | |
130 | ef4b7eee | Luiz Capitulino | return 0; |
131 | 5bb7910a | aliguori | } |
132 | 5bb7910a | aliguori | |
133 | a0a3fd60 | Glauber Costa | /* amount of nanoseconds we are willing to wait for migration to be down.
|
134 | a0a3fd60 | Glauber Costa | * the choice of nanoseconds is because it is the maximum resolution that
|
135 | a0a3fd60 | Glauber Costa | * get_clock() can achieve. It is an internal measure. All user-visible
|
136 | a0a3fd60 | Glauber Costa | * units must be in seconds */
|
137 | a0a3fd60 | Glauber Costa | static uint64_t max_downtime = 30000000; |
138 | a0a3fd60 | Glauber Costa | |
139 | a0a3fd60 | Glauber Costa | uint64_t migrate_max_downtime(void)
|
140 | a0a3fd60 | Glauber Costa | { |
141 | a0a3fd60 | Glauber Costa | return max_downtime;
|
142 | a0a3fd60 | Glauber Costa | } |
143 | a0a3fd60 | Glauber Costa | |
144 | ef4b7eee | Luiz Capitulino | int do_migrate_set_downtime(Monitor *mon, const QDict *qdict, |
145 | ef4b7eee | Luiz Capitulino | QObject **ret_data) |
146 | 2ea42952 | Glauber Costa | { |
147 | 2ea42952 | Glauber Costa | double d;
|
148 | 2ea42952 | Glauber Costa | |
149 | b0fbf7d3 | Markus Armbruster | d = qdict_get_double(qdict, "value") * 1e9; |
150 | b0fbf7d3 | Markus Armbruster | d = MAX(0, MIN(UINT64_MAX, d));
|
151 | 2ea42952 | Glauber Costa | max_downtime = (uint64_t)d; |
152 | ef4b7eee | Luiz Capitulino | |
153 | ef4b7eee | Luiz Capitulino | return 0; |
154 | 2ea42952 | Glauber Costa | } |
155 | 2ea42952 | Glauber Costa | |
156 | c86a6683 | Luiz Capitulino | static void migrate_print_status(Monitor *mon, const char *name, |
157 | c86a6683 | Luiz Capitulino | const QDict *status_dict)
|
158 | 5bb7910a | aliguori | { |
159 | c86a6683 | Luiz Capitulino | QDict *qdict; |
160 | c86a6683 | Luiz Capitulino | |
161 | c86a6683 | Luiz Capitulino | qdict = qobject_to_qdict(qdict_get(status_dict, name)); |
162 | c86a6683 | Luiz Capitulino | |
163 | c86a6683 | Luiz Capitulino | monitor_printf(mon, "transferred %s: %" PRIu64 " kbytes\n", name, |
164 | c86a6683 | Luiz Capitulino | qdict_get_int(qdict, "transferred") >> 10); |
165 | c86a6683 | Luiz Capitulino | monitor_printf(mon, "remaining %s: %" PRIu64 " kbytes\n", name, |
166 | c86a6683 | Luiz Capitulino | qdict_get_int(qdict, "remaining") >> 10); |
167 | c86a6683 | Luiz Capitulino | monitor_printf(mon, "total %s: %" PRIu64 " kbytes\n", name, |
168 | c86a6683 | Luiz Capitulino | qdict_get_int(qdict, "total") >> 10); |
169 | c86a6683 | Luiz Capitulino | } |
170 | c86a6683 | Luiz Capitulino | |
171 | c86a6683 | Luiz Capitulino | void do_info_migrate_print(Monitor *mon, const QObject *data) |
172 | c86a6683 | Luiz Capitulino | { |
173 | c86a6683 | Luiz Capitulino | QDict *qdict; |
174 | c86a6683 | Luiz Capitulino | |
175 | c86a6683 | Luiz Capitulino | qdict = qobject_to_qdict(data); |
176 | c86a6683 | Luiz Capitulino | |
177 | c86a6683 | Luiz Capitulino | monitor_printf(mon, "Migration status: %s\n",
|
178 | c86a6683 | Luiz Capitulino | qdict_get_str(qdict, "status"));
|
179 | c86a6683 | Luiz Capitulino | |
180 | c86a6683 | Luiz Capitulino | if (qdict_haskey(qdict, "ram")) { |
181 | c86a6683 | Luiz Capitulino | migrate_print_status(mon, "ram", qdict);
|
182 | c86a6683 | Luiz Capitulino | } |
183 | c86a6683 | Luiz Capitulino | |
184 | c86a6683 | Luiz Capitulino | if (qdict_haskey(qdict, "disk")) { |
185 | c86a6683 | Luiz Capitulino | migrate_print_status(mon, "disk", qdict);
|
186 | c86a6683 | Luiz Capitulino | } |
187 | c86a6683 | Luiz Capitulino | } |
188 | c86a6683 | Luiz Capitulino | |
189 | c86a6683 | Luiz Capitulino | static void migrate_put_status(QDict *qdict, const char *name, |
190 | c86a6683 | Luiz Capitulino | uint64_t trans, uint64_t rem, uint64_t total) |
191 | c86a6683 | Luiz Capitulino | { |
192 | c86a6683 | Luiz Capitulino | QObject *obj; |
193 | c86a6683 | Luiz Capitulino | |
194 | c86a6683 | Luiz Capitulino | obj = qobject_from_jsonf("{ 'transferred': %" PRId64 ", " |
195 | c86a6683 | Luiz Capitulino | "'remaining': %" PRId64 ", " |
196 | c86a6683 | Luiz Capitulino | "'total': %" PRId64 " }", trans, rem, total); |
197 | c86a6683 | Luiz Capitulino | qdict_put_obj(qdict, name, obj); |
198 | c86a6683 | Luiz Capitulino | } |
199 | c86a6683 | Luiz Capitulino | |
200 | c86a6683 | Luiz Capitulino | /**
|
201 | c86a6683 | Luiz Capitulino | * do_info_migrate(): Migration status
|
202 | c86a6683 | Luiz Capitulino | *
|
203 | c86a6683 | Luiz Capitulino | * Return a QDict. If migration is active there will be another
|
204 | c86a6683 | Luiz Capitulino | * QDict with RAM migration status and if block migration is active
|
205 | c86a6683 | Luiz Capitulino | * another one with block migration status.
|
206 | c86a6683 | Luiz Capitulino | *
|
207 | c86a6683 | Luiz Capitulino | * The main QDict contains the following:
|
208 | c86a6683 | Luiz Capitulino | *
|
209 | c86a6683 | Luiz Capitulino | * - "status": migration status
|
210 | c86a6683 | Luiz Capitulino | * - "ram": only present if "status" is "active", it is a QDict with the
|
211 | c86a6683 | Luiz Capitulino | * following RAM information (in bytes):
|
212 | c86a6683 | Luiz Capitulino | * - "transferred": amount transferred
|
213 | c86a6683 | Luiz Capitulino | * - "remaining": amount remaining
|
214 | c86a6683 | Luiz Capitulino | * - "total": total
|
215 | c86a6683 | Luiz Capitulino | * - "disk": only present if "status" is "active" and it is a block migration,
|
216 | c86a6683 | Luiz Capitulino | * it is a QDict with the following disk information (in bytes):
|
217 | c86a6683 | Luiz Capitulino | * - "transferred": amount transferred
|
218 | c86a6683 | Luiz Capitulino | * - "remaining": amount remaining
|
219 | c86a6683 | Luiz Capitulino | * - "total": total
|
220 | c86a6683 | Luiz Capitulino | *
|
221 | c86a6683 | Luiz Capitulino | * Examples:
|
222 | c86a6683 | Luiz Capitulino | *
|
223 | c86a6683 | Luiz Capitulino | * 1. Migration is "completed":
|
224 | c86a6683 | Luiz Capitulino | *
|
225 | c86a6683 | Luiz Capitulino | * { "status": "completed" }
|
226 | c86a6683 | Luiz Capitulino | *
|
227 | c86a6683 | Luiz Capitulino | * 2. Migration is "active" and it is not a block migration:
|
228 | c86a6683 | Luiz Capitulino | *
|
229 | c86a6683 | Luiz Capitulino | * { "status": "active",
|
230 | c86a6683 | Luiz Capitulino | * "ram": { "transferred": 123, "remaining": 123, "total": 246 } }
|
231 | c86a6683 | Luiz Capitulino | *
|
232 | c86a6683 | Luiz Capitulino | * 3. Migration is "active" and it is a block migration:
|
233 | c86a6683 | Luiz Capitulino | *
|
234 | c86a6683 | Luiz Capitulino | * { "status": "active",
|
235 | c86a6683 | Luiz Capitulino | * "ram": { "total": 1057024, "remaining": 1053304, "transferred": 3720 },
|
236 | c86a6683 | Luiz Capitulino | * "disk": { "total": 20971520, "remaining": 20880384, "transferred": 91136 }}
|
237 | c86a6683 | Luiz Capitulino | */
|
238 | c86a6683 | Luiz Capitulino | void do_info_migrate(Monitor *mon, QObject **ret_data)
|
239 | c86a6683 | Luiz Capitulino | { |
240 | c86a6683 | Luiz Capitulino | QDict *qdict; |
241 | 5bb7910a | aliguori | MigrationState *s = current_migration; |
242 | 376253ec | aliguori | |
243 | 5bb7910a | aliguori | if (s) {
|
244 | ff8d81d8 | aliguori | switch (s->get_status(s)) {
|
245 | ff8d81d8 | aliguori | case MIG_STATE_ACTIVE:
|
246 | c86a6683 | Luiz Capitulino | qdict = qdict_new(); |
247 | c86a6683 | Luiz Capitulino | qdict_put(qdict, "status", qstring_from_str("active")); |
248 | c86a6683 | Luiz Capitulino | |
249 | c86a6683 | Luiz Capitulino | migrate_put_status(qdict, "ram", ram_bytes_transferred(),
|
250 | c86a6683 | Luiz Capitulino | ram_bytes_remaining(), ram_bytes_total()); |
251 | c86a6683 | Luiz Capitulino | |
252 | 25f23643 | Jan Kiszka | if (blk_mig_active()) {
|
253 | c86a6683 | Luiz Capitulino | migrate_put_status(qdict, "disk", blk_mig_bytes_transferred(),
|
254 | c86a6683 | Luiz Capitulino | blk_mig_bytes_remaining(), |
255 | c86a6683 | Luiz Capitulino | blk_mig_bytes_total()); |
256 | 25f23643 | Jan Kiszka | } |
257 | c86a6683 | Luiz Capitulino | |
258 | c86a6683 | Luiz Capitulino | *ret_data = QOBJECT(qdict); |
259 | ff8d81d8 | aliguori | break;
|
260 | ff8d81d8 | aliguori | case MIG_STATE_COMPLETED:
|
261 | c86a6683 | Luiz Capitulino | *ret_data = qobject_from_jsonf("{ 'status': 'completed' }");
|
262 | ff8d81d8 | aliguori | break;
|
263 | ff8d81d8 | aliguori | case MIG_STATE_ERROR:
|
264 | c86a6683 | Luiz Capitulino | *ret_data = qobject_from_jsonf("{ 'status': 'failed' }");
|
265 | ff8d81d8 | aliguori | break;
|
266 | ff8d81d8 | aliguori | case MIG_STATE_CANCELLED:
|
267 | c86a6683 | Luiz Capitulino | *ret_data = qobject_from_jsonf("{ 'status': 'cancelled' }");
|
268 | ff8d81d8 | aliguori | break;
|
269 | ff8d81d8 | aliguori | } |
270 | 5bb7910a | aliguori | } |
271 | 5bb7910a | aliguori | } |
272 | 5bb7910a | aliguori | |
273 | 065e2813 | aliguori | /* shared migration helpers */
|
274 | 065e2813 | aliguori | |
275 | f327aa0c | Jan Kiszka | void migrate_fd_monitor_suspend(FdMigrationState *s, Monitor *mon)
|
276 | 731b0364 | aliguori | { |
277 | f327aa0c | Jan Kiszka | s->mon = mon; |
278 | f327aa0c | Jan Kiszka | if (monitor_suspend(mon) == 0) { |
279 | d0f2c4c6 | malc | DPRINTF("suspending monitor\n");
|
280 | f327aa0c | Jan Kiszka | } else {
|
281 | f327aa0c | Jan Kiszka | monitor_printf(mon, "terminal does not allow synchronous "
|
282 | cde76ee1 | aliguori | "migration, continuing detached\n");
|
283 | f327aa0c | Jan Kiszka | } |
284 | 731b0364 | aliguori | } |
285 | 731b0364 | aliguori | |
286 | 065e2813 | aliguori | void migrate_fd_error(FdMigrationState *s)
|
287 | 065e2813 | aliguori | { |
288 | d0f2c4c6 | malc | DPRINTF("setting error state\n");
|
289 | 065e2813 | aliguori | s->state = MIG_STATE_ERROR; |
290 | 065e2813 | aliguori | migrate_fd_cleanup(s); |
291 | 065e2813 | aliguori | } |
292 | 065e2813 | aliguori | |
293 | 065e2813 | aliguori | void migrate_fd_cleanup(FdMigrationState *s)
|
294 | 065e2813 | aliguori | { |
295 | 065e2813 | aliguori | qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); |
296 | 065e2813 | aliguori | |
297 | 065e2813 | aliguori | if (s->file) {
|
298 | d0f2c4c6 | malc | DPRINTF("closing file\n");
|
299 | 065e2813 | aliguori | qemu_fclose(s->file); |
300 | 5d39c799 | Jan Kiszka | s->file = NULL;
|
301 | 065e2813 | aliguori | } |
302 | 065e2813 | aliguori | |
303 | 065e2813 | aliguori | if (s->fd != -1) |
304 | 065e2813 | aliguori | close(s->fd); |
305 | 065e2813 | aliguori | |
306 | 065e2813 | aliguori | /* Don't resume monitor until we've flushed all of the buffers */
|
307 | f327aa0c | Jan Kiszka | if (s->mon) {
|
308 | f327aa0c | Jan Kiszka | monitor_resume(s->mon); |
309 | f327aa0c | Jan Kiszka | } |
310 | 065e2813 | aliguori | |
311 | 065e2813 | aliguori | s->fd = -1;
|
312 | 065e2813 | aliguori | } |
313 | 065e2813 | aliguori | |
314 | 065e2813 | aliguori | void migrate_fd_put_notify(void *opaque) |
315 | 065e2813 | aliguori | { |
316 | 065e2813 | aliguori | FdMigrationState *s = opaque; |
317 | 065e2813 | aliguori | |
318 | 065e2813 | aliguori | qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); |
319 | 065e2813 | aliguori | qemu_file_put_notify(s->file); |
320 | 065e2813 | aliguori | } |
321 | 065e2813 | aliguori | |
322 | 065e2813 | aliguori | ssize_t migrate_fd_put_buffer(void *opaque, const void *data, size_t size) |
323 | 065e2813 | aliguori | { |
324 | 065e2813 | aliguori | FdMigrationState *s = opaque; |
325 | 065e2813 | aliguori | ssize_t ret; |
326 | 065e2813 | aliguori | |
327 | 065e2813 | aliguori | do {
|
328 | 065e2813 | aliguori | ret = s->write(s, data, size); |
329 | 95b134ea | Uri Lublin | } while (ret == -1 && ((s->get_error(s)) == EINTR)); |
330 | 065e2813 | aliguori | |
331 | 065e2813 | aliguori | if (ret == -1) |
332 | 065e2813 | aliguori | ret = -(s->get_error(s)); |
333 | 065e2813 | aliguori | |
334 | 065e2813 | aliguori | if (ret == -EAGAIN)
|
335 | 065e2813 | aliguori | qemu_set_fd_handler2(s->fd, NULL, NULL, migrate_fd_put_notify, s); |
336 | 065e2813 | aliguori | |
337 | 065e2813 | aliguori | return ret;
|
338 | 065e2813 | aliguori | } |
339 | 065e2813 | aliguori | |
340 | 065e2813 | aliguori | void migrate_fd_connect(FdMigrationState *s)
|
341 | 065e2813 | aliguori | { |
342 | 065e2813 | aliguori | int ret;
|
343 | 065e2813 | aliguori | |
344 | 065e2813 | aliguori | s->file = qemu_fopen_ops_buffered(s, |
345 | 065e2813 | aliguori | s->bandwidth_limit, |
346 | 065e2813 | aliguori | migrate_fd_put_buffer, |
347 | 065e2813 | aliguori | migrate_fd_put_ready, |
348 | 065e2813 | aliguori | migrate_fd_wait_for_unfreeze, |
349 | 065e2813 | aliguori | migrate_fd_close); |
350 | 065e2813 | aliguori | |
351 | d0f2c4c6 | malc | DPRINTF("beginning savevm\n");
|
352 | f327aa0c | Jan Kiszka | ret = qemu_savevm_state_begin(s->mon, s->file, s->mig_state.blk, |
353 | c163b5ca | lirans@il.ibm.com | s->mig_state.shared); |
354 | 065e2813 | aliguori | if (ret < 0) { |
355 | d0f2c4c6 | malc | DPRINTF("failed, %d\n", ret);
|
356 | 065e2813 | aliguori | migrate_fd_error(s); |
357 | 065e2813 | aliguori | return;
|
358 | 065e2813 | aliguori | } |
359 | c163b5ca | lirans@il.ibm.com | |
360 | 065e2813 | aliguori | migrate_fd_put_ready(s); |
361 | 065e2813 | aliguori | } |
362 | 065e2813 | aliguori | |
363 | 065e2813 | aliguori | void migrate_fd_put_ready(void *opaque) |
364 | 065e2813 | aliguori | { |
365 | 065e2813 | aliguori | FdMigrationState *s = opaque; |
366 | 065e2813 | aliguori | |
367 | 065e2813 | aliguori | if (s->state != MIG_STATE_ACTIVE) {
|
368 | d0f2c4c6 | malc | DPRINTF("put_ready returning because of non-active state\n");
|
369 | 065e2813 | aliguori | return;
|
370 | 065e2813 | aliguori | } |
371 | 065e2813 | aliguori | |
372 | d0f2c4c6 | malc | DPRINTF("iterate\n");
|
373 | f327aa0c | Jan Kiszka | if (qemu_savevm_state_iterate(s->mon, s->file) == 1) { |
374 | b161d123 | aliguori | int state;
|
375 | eeb34af9 | Anthony Liguori | int old_vm_running = vm_running;
|
376 | eeb34af9 | Anthony Liguori | |
377 | d0f2c4c6 | malc | DPRINTF("done iterating\n");
|
378 | 065e2813 | aliguori | vm_stop(0);
|
379 | 065e2813 | aliguori | |
380 | 0884657b | Glauber Costa | qemu_aio_flush(); |
381 | 065e2813 | aliguori | bdrv_flush_all(); |
382 | f327aa0c | Jan Kiszka | if ((qemu_savevm_state_complete(s->mon, s->file)) < 0) { |
383 | eeb34af9 | Anthony Liguori | if (old_vm_running) {
|
384 | eeb34af9 | Anthony Liguori | vm_start(); |
385 | eeb34af9 | Anthony Liguori | } |
386 | b161d123 | aliguori | state = MIG_STATE_ERROR; |
387 | b161d123 | aliguori | } else {
|
388 | b161d123 | aliguori | state = MIG_STATE_COMPLETED; |
389 | b161d123 | aliguori | } |
390 | 065e2813 | aliguori | migrate_fd_cleanup(s); |
391 | b161d123 | aliguori | s->state = state; |
392 | 065e2813 | aliguori | } |
393 | 065e2813 | aliguori | } |
394 | 065e2813 | aliguori | |
395 | 065e2813 | aliguori | int migrate_fd_get_status(MigrationState *mig_state)
|
396 | 065e2813 | aliguori | { |
397 | 065e2813 | aliguori | FdMigrationState *s = migrate_to_fms(mig_state); |
398 | 065e2813 | aliguori | return s->state;
|
399 | 065e2813 | aliguori | } |
400 | 065e2813 | aliguori | |
401 | 065e2813 | aliguori | void migrate_fd_cancel(MigrationState *mig_state)
|
402 | 065e2813 | aliguori | { |
403 | 065e2813 | aliguori | FdMigrationState *s = migrate_to_fms(mig_state); |
404 | 065e2813 | aliguori | |
405 | 065e2813 | aliguori | if (s->state != MIG_STATE_ACTIVE)
|
406 | 065e2813 | aliguori | return;
|
407 | 065e2813 | aliguori | |
408 | d0f2c4c6 | malc | DPRINTF("cancelling migration\n");
|
409 | 065e2813 | aliguori | |
410 | 065e2813 | aliguori | s->state = MIG_STATE_CANCELLED; |
411 | f327aa0c | Jan Kiszka | qemu_savevm_state_cancel(s->mon, s->file); |
412 | 065e2813 | aliguori | |
413 | 065e2813 | aliguori | migrate_fd_cleanup(s); |
414 | 065e2813 | aliguori | } |
415 | 065e2813 | aliguori | |
416 | 065e2813 | aliguori | void migrate_fd_release(MigrationState *mig_state)
|
417 | 065e2813 | aliguori | { |
418 | 065e2813 | aliguori | FdMigrationState *s = migrate_to_fms(mig_state); |
419 | 065e2813 | aliguori | |
420 | d0f2c4c6 | malc | DPRINTF("releasing state\n");
|
421 | 065e2813 | aliguori | |
422 | 065e2813 | aliguori | if (s->state == MIG_STATE_ACTIVE) {
|
423 | 065e2813 | aliguori | s->state = MIG_STATE_CANCELLED; |
424 | 065e2813 | aliguori | migrate_fd_cleanup(s); |
425 | 065e2813 | aliguori | } |
426 | 065e2813 | aliguori | free(s); |
427 | 065e2813 | aliguori | } |
428 | 065e2813 | aliguori | |
429 | 065e2813 | aliguori | void migrate_fd_wait_for_unfreeze(void *opaque) |
430 | 065e2813 | aliguori | { |
431 | 065e2813 | aliguori | FdMigrationState *s = opaque; |
432 | 065e2813 | aliguori | int ret;
|
433 | 065e2813 | aliguori | |
434 | d0f2c4c6 | malc | DPRINTF("wait for unfreeze\n");
|
435 | 065e2813 | aliguori | if (s->state != MIG_STATE_ACTIVE)
|
436 | 065e2813 | aliguori | return;
|
437 | 065e2813 | aliguori | |
438 | 065e2813 | aliguori | do {
|
439 | 065e2813 | aliguori | fd_set wfds; |
440 | 065e2813 | aliguori | |
441 | 065e2813 | aliguori | FD_ZERO(&wfds); |
442 | 065e2813 | aliguori | FD_SET(s->fd, &wfds); |
443 | 065e2813 | aliguori | |
444 | 065e2813 | aliguori | ret = select(s->fd + 1, NULL, &wfds, NULL, NULL); |
445 | 065e2813 | aliguori | } while (ret == -1 && (s->get_error(s)) == EINTR); |
446 | 065e2813 | aliguori | } |
447 | 065e2813 | aliguori | |
448 | 065e2813 | aliguori | int migrate_fd_close(void *opaque) |
449 | 065e2813 | aliguori | { |
450 | 065e2813 | aliguori | FdMigrationState *s = opaque; |
451 | e19252d3 | Uri Lublin | |
452 | e19252d3 | Uri Lublin | qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); |
453 | 065e2813 | aliguori | return s->close(s);
|
454 | 065e2813 | aliguori | } |