]> Git Repo - qemu.git/blame - migration/migration.h
migration: Introduce migrate_send_rp_message_req_pages()
[qemu.git] / migration / migration.h
CommitLineData
5bb7910a
AL
1/*
2 * QEMU live migration
3 *
4 * Copyright IBM, Corp. 2008
5 *
6 * Authors:
7 * Anthony Liguori <[email protected]>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
12 */
13
14#ifndef QEMU_MIGRATION_H
15#define QEMU_MIGRATION_H
16
d4842052 17#include "exec/cpu-common.h"
a27bd6c7 18#include "hw/qdev-core.h"
9af23989 19#include "qapi/qapi-types-migration.h"
9848a404 20#include "qemu/thread.h"
25d0c16f 21#include "qemu/coroutine_int.h"
4f0fae7f 22#include "io/channel.h"
7659505c 23#include "net/announce.h"
db1015e9 24#include "qom/object.h"
376253ec 25
2a4c42f1
AP
26struct PostcopyBlocktimeContext;
27
13955b89
PX
28#define MIGRATION_RESUME_ACK_VALUE (1)
29
002cad6b
PX
30/*
31 * 1<<6=64 pages -> 256K chunk when page size is 4K. This gives us
32 * the benefit that all the chunks are 64 pages aligned then the
33 * bitmaps are always aligned to LONG.
34 */
35#define CLEAR_BITMAP_SHIFT_MIN 6
36/*
37 * 1<<18=256K pages -> 1G chunk when page size is 4K. This is the
38 * default value to use if no one specified.
39 */
40#define CLEAR_BITMAP_SHIFT_DEFAULT 18
41/*
42 * 1<<31=2G pages -> 8T chunk when page size is 4K. This should be
43 * big enough and make sure we won't overflow easily.
44 */
45#define CLEAR_BITMAP_SHIFT_MAX 31
46
bca7856a
DDAG
47/* State for the incoming migration */
48struct MigrationIncomingState {
42e2aa56 49 QEMUFile *from_src_file;
1a8f46f8 50
7b89bf27
DDAG
51 /*
52 * Free at the start of the main state load, set as the main thread finishes
53 * loading state.
54 */
55 QemuEvent main_thread_load_event;
56
7659505c
DDAG
57 /* For network announces */
58 AnnounceTimer announce_timer;
59
67f11b5c 60 size_t largest_page_size;
c4faeed2 61 bool have_fault_thread;
f0a227ad
DDAG
62 QemuThread fault_thread;
63 QemuSemaphore fault_thread_sem;
64f615fe
PX
64 /* Set this when we want the fault thread to quit */
65 bool fault_thread_quit;
f0a227ad 66
c76201ab
DDAG
67 bool have_listen_thread;
68 QemuThread listen_thread;
69 QemuSemaphore listen_thread_sem;
70
1caddf8a
DDAG
71 /* For the kernel to send us notifications */
72 int userfault_fd;
64f615fe
PX
73 /* To notify the fault_thread to wake, e.g., when need to quit */
74 int userfault_event_fd;
2e37701e 75 QEMUFile *to_src_file;
6decec93 76 QemuMutex rp_mutex; /* We send replies from multiple threads */
096bf4c8
DDAG
77 /* RAMBlock of last request sent to source */
78 RAMBlock *last_rb;
696ed9a9 79 void *postcopy_tmp_page;
41d84210 80 void *postcopy_tmp_zero_page;
00fa4fc8
DDAG
81 /* PostCopyFD's for external userfaultfds & handlers of shared memory */
82 GArray *postcopy_remote_fds;
2e37701e 83
0aa6aefc
DL
84 QEMUBH *bh;
85
93d7af6f 86 int state;
25d0c16f
HZ
87
88 bool have_colo_incoming_thread;
89 QemuThread colo_incoming_thread;
90 /* The coroutine we should enter (back) after failover */
91 Coroutine *migration_incoming_co;
c937b9a6 92 QemuSemaphore colo_incoming_sem;
2a4c42f1
AP
93
94 /*
95 * PostcopyBlocktimeContext to keep information for postcopy
96 * live migration, to calculate vCPU block time
97 * */
98 struct PostcopyBlocktimeContext *blocktime_ctx;
b411b844
PX
99
100 /* notify PAUSED postcopy incoming migrations to try to continue */
02affd41 101 bool postcopy_recover_triggered;
b411b844 102 QemuSemaphore postcopy_pause_sem_dst;
3a7804c3 103 QemuSemaphore postcopy_pause_sem_fault;
9aca82ba
JQ
104
105 /* List of listening socket addresses */
106 SocketAddressList *socket_address_list;
bca7856a
DDAG
107};
108
109MigrationIncomingState *migration_incoming_get_current(void);
bca7856a 110void migration_incoming_state_destroy(void);
65ace060
AP
111/*
112 * Functions to work with blocktime context
113 */
114void fill_destination_postcopy_migration_info(MigrationInfo *info);
bca7856a 115
e5cb7e76
PX
116#define TYPE_MIGRATION "migration"
117
db1015e9 118typedef struct MigrationClass MigrationClass;
8110fa1d
EH
119DECLARE_OBJ_CHECKERS(MigrationState, MigrationClass,
120 MIGRATION_OBJ, TYPE_MIGRATION)
e5cb7e76 121
db1015e9 122struct MigrationClass {
e5cb7e76
PX
123 /*< private >*/
124 DeviceClass parent_class;
db1015e9 125};
e5cb7e76 126
f16aee44 127struct MigrationState {
e5cb7e76
PX
128 /*< private >*/
129 DeviceState parent_obj;
130
131 /*< public >*/
9848a404 132 QemuThread thread;
bb1fadc4 133 QEMUBH *cleanup_bh;
89a02a9f 134 QEMUFile *to_dst_file;
62df066f
PX
135 /*
136 * Protects to_dst_file pointer. We need to make sure we won't
137 * yield or hang during the critical section, since this lock will
138 * be used in OOB command handler.
139 */
140 QemuMutex qemu_file_lock;
2594f56d 141
ad767bed
DDAG
142 /*
143 * Used to allow urgent requests to override rate limiting.
144 */
145 QemuSemaphore rate_limit_sem;
146
aecbfe9c
XG
147 /* pages already send at the beginning of current iteration */
148 uint64_t iteration_initial_pages;
149
150 /* pages transferred per second */
151 double pages_per_second;
152
153 /* bytes already send at the beginning of current iteration */
b15df1ae
PX
154 uint64_t iteration_initial_bytes;
155 /* time at the start of current iteration */
156 int64_t iteration_start_time;
157 /*
158 * The final stage happens when the remaining data is smaller than
159 * this threshold; it's calculated from the requested downtime and
160 * measured bandwidth
161 */
162 int64_t threshold_size;
163
a0762d9e 164 /* params from 'migrate-set-parameters' */
2594f56d 165 MigrationParameters parameters;
f8bbc128 166
f8bbc128 167 int state;
70b20477
DDAG
168
169 /* State related to return path */
170 struct {
171 QEMUFile *from_dst_file;
172 QemuThread rp_thread;
173 bool error;
edd090c7 174 QemuSemaphore rp_sem;
70b20477
DDAG
175 } rp_state;
176
7e114f8c 177 double mbps;
4af246a3
PX
178 /* Timestamp when recent migration starts (ms) */
179 int64_t start_time;
180 /* Total time used by latest migration (ms) */
d5f8a570 181 int64_t total_time;
64909f97
PX
182 /* Timestamp when VM is down (ms) to migrate the last stuff */
183 int64_t downtime_start;
9c5a9fcf 184 int64_t downtime;
2c52ddf1 185 int64_t expected_downtime;
7fb1cf16 186 bool enabled_capabilities[MIGRATION_CAPABILITY__MAX];
ed4fbd10 187 int64_t setup_time;
7287cbd4
PX
188 /*
189 * Whether guest was running when we enter the completion stage.
190 * If migration is interrupted by any reason, we need to continue
191 * running the guest on source.
192 */
193 bool vm_was_running;
4886a1bc
DDAG
194
195 /* Flag set once the migration has been asked to enter postcopy */
196 bool start_postcopy;
b82fc321
DDAG
197 /* Flag set after postcopy has sent the device state */
198 bool postcopy_after_devices;
1d34e4bf
DDAG
199
200 /* Flag set once the migration thread is running (and needs joining) */
201 bool migration_thread_running;
6c595cde 202
1d2acc31
HZ
203 /* Flag set once the migration thread called bdrv_inactivate_all */
204 bool block_inactive;
205
c7e0acd5
JF
206 /* Migration is waiting for guest to unplug device */
207 QemuSemaphore wait_unplug_sem;
208
e91d8951
DDAG
209 /* Migration is paused due to pause-before-switchover */
210 QemuSemaphore pause_sem;
211
c937b9a6
HZ
212 /* The semaphore is used to notify COLO thread that failover is finished */
213 QemuSemaphore colo_exit_sem;
d59ce6f3 214
bb70b66e
LS
215 /* The event is used to notify COLO thread to do checkpoint */
216 QemuEvent colo_checkpoint_event;
479125d5
HZ
217 int64_t colo_checkpoint_time;
218 QEMUTimer *colo_delay_timer;
219
87db1a7d
JQ
220 /* The first error that has occurred.
221 We used the mutex to be able to return the 1st error message */
d59ce6f3 222 Error *error;
87db1a7d
JQ
223 /* mutex to protect errp */
224 QemuMutex error_mutex;
225
2833c59b
JQ
226 /* Do we have to clean up -b/-i from old migrate parameters */
227 /* This feature is deprecated and will be removed */
228 bool must_remove_block_options;
5272298c
PX
229
230 /*
231 * Global switch on whether we need to store the global state
232 * during migration.
233 */
234 bool store_global_state;
3df663e5 235
71dd4c1a
PX
236 /* Whether we send QEMU_VM_CONFIGURATION during migration */
237 bool send_configuration;
15c38503
PX
238 /* Whether we send section footer during migration */
239 bool send_section_footer;
b23c2ade
PX
240
241 /* Needed by postcopy-pause state */
242 QemuSemaphore postcopy_pause_sem;
14b1742e 243 QemuSemaphore postcopy_pause_rp_sem;
f548222c
XG
244 /*
245 * Whether we abort the migration if decompression errors are
246 * detected at the destination. It is left at false for qemu
247 * older than 3.0, since only newer qemu sends streams that
248 * do not trigger spurious decompression errors.
249 */
250 bool decompress_error_check;
002cad6b
PX
251
252 /*
253 * This decides the size of guest memory chunk that will be used
254 * to track dirty bitmap clearing. The size of memory chunk will
255 * be GUEST_PAGE_SIZE << N. Say, N=0 means we will clear dirty
256 * bitmap for each page to send (1<<0=1); N=10 means we will clear
257 * dirty bitmap only once for 1<<10=1K continuous guest pages
258 * (which is in 4M chunk).
259 */
260 uint8_t clear_bitmap_shift;
d8053e73
CZ
261
262 /*
263 * This save hostname when out-going migration starts
264 */
265 char *hostname;
065e2813
AL
266};
267
48781e5b
HZ
268void migrate_set_state(int *state, int old_state, int new_state);
269
b673eab4 270void migration_fd_process_incoming(QEMUFile *f, Error **errp);
49ed0d24 271void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp);
36c2f8be 272void migration_incoming_process(void);
511c0231 273
428d8908
JQ
274bool migration_has_all_channels(void);
275
a0a3fd60
GC
276uint64_t migrate_max_downtime(void);
277
87db1a7d 278void migrate_set_error(MigrationState *s, const Error *error);
d59ce6f3 279void migrate_fd_error(MigrationState *s, const Error *error);
065e2813 280
cce8040b 281void migrate_fd_connect(MigrationState *s, Error *error_in);
065e2813 282
3d63da16 283bool migration_is_setup_or_active(int state);
392d87e2 284bool migration_is_running(int state);
3d63da16 285
3e0c8050 286void migrate_init(MigrationState *s);
24f3902b 287bool migration_is_blocked(Error **errp);
9ec055ae 288/* True if outgoing migration has entered postcopy phase */
5727309d 289bool migration_in_postcopy(void);
859bc756 290MigrationState *migrate_get_current(void);
99a0db9b 291
58110f0a
VSO
292bool migrate_postcopy(void);
293
53f09a10 294bool migrate_release_ram(void);
53dd370c 295bool migrate_postcopy_ram(void);
323004a3 296bool migrate_zero_blocks(void);
55efc8c2 297bool migrate_dirty_bitmaps(void);
18269069 298bool migrate_ignore_shared(void);
b9d68df6 299bool migrate_validate_uuid(void);
60d9222c 300
bde1e2ec 301bool migrate_auto_converge(void);
30126bbf 302bool migrate_use_multifd(void);
93fbd031 303bool migrate_pause_before_switchover(void);
4075fb1c 304int migrate_multifd_channels(void);
ab7cbb0b 305MultiFDCompression migrate_multifd_compression(void);
9004db48 306int migrate_multifd_zlib_level(void);
6a9ad154 307int migrate_multifd_zstd_level(void);
bde1e2ec 308
17ad9b35
OW
309int migrate_use_xbzrle(void);
310int64_t migrate_xbzrle_cache_size(void);
35a6ed4f 311bool migrate_colo_enabled(void);
17ad9b35 312
2833c59b
JQ
313bool migrate_use_block(void);
314bool migrate_use_block_incremental(void);
4cbc9c7f 315int migrate_max_cpu_throttle(void);
c788ada8 316bool migrate_use_return_path(void);
2833c59b 317
aecbfe9c
XG
318uint64_t ram_get_total_transferred_pages(void);
319
8706d2d5
LL
320bool migrate_use_compression(void);
321int migrate_compress_level(void);
322int migrate_compress_threads(void);
1d58872a 323int migrate_compress_wait_thread(void);
3fcb38c2 324int migrate_decompress_threads(void);
b05dc723 325bool migrate_use_events(void);
f22f928e 326bool migrate_postcopy_blocktime(void);
8706d2d5 327
6decec93 328/* Sending on the return path - generic and then for each message type */
6decec93
DDAG
329void migrate_send_rp_shut(MigrationIncomingState *mis,
330 uint32_t value);
331void migrate_send_rp_pong(MigrationIncomingState *mis,
332 uint32_t value);
2e2bce16
PX
333int migrate_send_rp_req_pages(MigrationIncomingState *mis, RAMBlock *rb,
334 ram_addr_t start);
7a267fc4
PX
335int migrate_send_rp_message_req_pages(MigrationIncomingState *mis,
336 RAMBlock *rb, ram_addr_t start);
a335debb
PX
337void migrate_send_rp_recv_bitmap(MigrationIncomingState *mis,
338 char *block_name);
13955b89 339void migrate_send_rp_resume_ack(MigrationIncomingState *mis, uint32_t value);
6decec93 340
b35ebdf0 341void dirty_bitmap_mig_before_vm_start(void);
1499ab09
VSO
342void dirty_bitmap_mig_cancel_outgoing(void);
343void dirty_bitmap_mig_cancel_incoming(void);
31e4c354
HR
344bool check_dirty_bitmap_mig_alias_map(const BitmapMigrationNodeAliasList *bbm,
345 Error **errp);
346
9aca82ba 347void migrate_add_address(SocketAddress *address);
b35ebdf0 348
fbd162e6
YK
349int foreach_not_ignored_block(RAMBlockIterFunc func, void *opaque);
350
343f632c 351#define qemu_ram_foreach_block \
fbd162e6 352 #warning "Use foreach_not_ignored_block in migration code"
343f632c 353
ad767bed
DDAG
354void migration_make_urgent_request(void);
355void migration_consume_urgent_request(void);
97e1e067 356bool migration_rate_limit(void);
ad767bed 357
5bb7910a 358#endif
This page took 0.827313 seconds and 4 git commands to generate.