]> Git Repo - qemu.git/blame - migration/migration.h
maint: Add .mailmap entries for patches claiming list authorship
[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
376253ec 17#include "qemu-common.h"
9af23989 18#include "qapi/qapi-types-migration.h"
9848a404 19#include "qemu/thread.h"
43487c67 20#include "exec/cpu-common.h"
25d0c16f 21#include "qemu/coroutine_int.h"
e5cb7e76 22#include "hw/qdev.h"
4f0fae7f 23#include "io/channel.h"
376253ec 24
bca7856a
DDAG
25/* State for the incoming migration */
26struct MigrationIncomingState {
42e2aa56 27 QEMUFile *from_src_file;
1a8f46f8 28
7b89bf27
DDAG
29 /*
30 * Free at the start of the main state load, set as the main thread finishes
31 * loading state.
32 */
33 QemuEvent main_thread_load_event;
34
67f11b5c 35 size_t largest_page_size;
c4faeed2 36 bool have_fault_thread;
f0a227ad
DDAG
37 QemuThread fault_thread;
38 QemuSemaphore fault_thread_sem;
64f615fe
PX
39 /* Set this when we want the fault thread to quit */
40 bool fault_thread_quit;
f0a227ad 41
c76201ab
DDAG
42 bool have_listen_thread;
43 QemuThread listen_thread;
44 QemuSemaphore listen_thread_sem;
45
1caddf8a
DDAG
46 /* For the kernel to send us notifications */
47 int userfault_fd;
64f615fe
PX
48 /* To notify the fault_thread to wake, e.g., when need to quit */
49 int userfault_event_fd;
2e37701e 50 QEMUFile *to_src_file;
6decec93 51 QemuMutex rp_mutex; /* We send replies from multiple threads */
096bf4c8
DDAG
52 /* RAMBlock of last request sent to source */
53 RAMBlock *last_rb;
696ed9a9 54 void *postcopy_tmp_page;
41d84210 55 void *postcopy_tmp_zero_page;
00fa4fc8
DDAG
56 /* PostCopyFD's for external userfaultfds & handlers of shared memory */
57 GArray *postcopy_remote_fds;
2e37701e 58
0aa6aefc
DL
59 QEMUBH *bh;
60
93d7af6f 61 int state;
25d0c16f
HZ
62
63 bool have_colo_incoming_thread;
64 QemuThread colo_incoming_thread;
65 /* The coroutine we should enter (back) after failover */
66 Coroutine *migration_incoming_co;
c937b9a6 67 QemuSemaphore colo_incoming_sem;
bca7856a
DDAG
68};
69
70MigrationIncomingState *migration_incoming_get_current(void);
bca7856a
DDAG
71void migration_incoming_state_destroy(void);
72
e5cb7e76
PX
73#define TYPE_MIGRATION "migration"
74
75#define MIGRATION_CLASS(klass) \
76 OBJECT_CLASS_CHECK(MigrationClass, (klass), TYPE_MIGRATION)
77#define MIGRATION_OBJ(obj) \
78 OBJECT_CHECK(MigrationState, (obj), TYPE_MIGRATION)
79#define MIGRATION_GET_CLASS(obj) \
80 OBJECT_GET_CLASS(MigrationClass, (obj), TYPE_MIGRATION)
81
82typedef struct MigrationClass {
83 /*< private >*/
84 DeviceClass parent_class;
85} MigrationClass;
86
22f00a44 87struct MigrationState
065e2813 88{
e5cb7e76
PX
89 /*< private >*/
90 DeviceState parent_obj;
91
92 /*< public >*/
9848a404
JQ
93 size_t bytes_xfer;
94 size_t xfer_limit;
9848a404 95 QemuThread thread;
bb1fadc4 96 QEMUBH *cleanup_bh;
89a02a9f 97 QEMUFile *to_dst_file;
2594f56d 98
b15df1ae
PX
99 /* bytes already send at the beggining of current interation */
100 uint64_t iteration_initial_bytes;
101 /* time at the start of current iteration */
102 int64_t iteration_start_time;
103 /*
104 * The final stage happens when the remaining data is smaller than
105 * this threshold; it's calculated from the requested downtime and
106 * measured bandwidth
107 */
108 int64_t threshold_size;
109
a0762d9e 110 /* params from 'migrate-set-parameters' */
2594f56d 111 MigrationParameters parameters;
f8bbc128 112
f8bbc128 113 int state;
70b20477
DDAG
114
115 /* State related to return path */
116 struct {
117 QEMUFile *from_dst_file;
118 QemuThread rp_thread;
119 bool error;
120 } rp_state;
121
7e114f8c 122 double mbps;
4af246a3
PX
123 /* Timestamp when recent migration starts (ms) */
124 int64_t start_time;
125 /* Total time used by latest migration (ms) */
d5f8a570 126 int64_t total_time;
64909f97
PX
127 /* Timestamp when VM is down (ms) to migrate the last stuff */
128 int64_t downtime_start;
9c5a9fcf 129 int64_t downtime;
2c52ddf1 130 int64_t expected_downtime;
7fb1cf16 131 bool enabled_capabilities[MIGRATION_CAPABILITY__MAX];
ed4fbd10 132 int64_t setup_time;
7287cbd4
PX
133 /*
134 * Whether guest was running when we enter the completion stage.
135 * If migration is interrupted by any reason, we need to continue
136 * running the guest on source.
137 */
138 bool vm_was_running;
4886a1bc
DDAG
139
140 /* Flag set once the migration has been asked to enter postcopy */
141 bool start_postcopy;
b82fc321
DDAG
142 /* Flag set after postcopy has sent the device state */
143 bool postcopy_after_devices;
1d34e4bf
DDAG
144
145 /* Flag set once the migration thread is running (and needs joining) */
146 bool migration_thread_running;
6c595cde 147
1d2acc31
HZ
148 /* Flag set once the migration thread called bdrv_inactivate_all */
149 bool block_inactive;
150
e91d8951
DDAG
151 /* Migration is paused due to pause-before-switchover */
152 QemuSemaphore pause_sem;
153
c937b9a6
HZ
154 /* The semaphore is used to notify COLO thread that failover is finished */
155 QemuSemaphore colo_exit_sem;
d59ce6f3 156
479125d5
HZ
157 /* The semaphore is used to notify COLO thread to do checkpoint */
158 QemuSemaphore colo_checkpoint_sem;
159 int64_t colo_checkpoint_time;
160 QEMUTimer *colo_delay_timer;
161
87db1a7d
JQ
162 /* The first error that has occurred.
163 We used the mutex to be able to return the 1st error message */
d59ce6f3 164 Error *error;
87db1a7d
JQ
165 /* mutex to protect errp */
166 QemuMutex error_mutex;
167
2833c59b
JQ
168 /* Do we have to clean up -b/-i from old migrate parameters */
169 /* This feature is deprecated and will be removed */
170 bool must_remove_block_options;
5272298c
PX
171
172 /*
173 * Global switch on whether we need to store the global state
174 * during migration.
175 */
176 bool store_global_state;
3df663e5
PX
177
178 /* Whether the VM is only allowing for migratable devices */
179 bool only_migratable;
71dd4c1a
PX
180
181 /* Whether we send QEMU_VM_CONFIGURATION during migration */
182 bool send_configuration;
15c38503
PX
183 /* Whether we send section footer during migration */
184 bool send_section_footer;
065e2813
AL
185};
186
48781e5b
HZ
187void migrate_set_state(int *state, int old_state, int new_state);
188
22724f49 189void migration_fd_process_incoming(QEMUFile *f);
4f0fae7f 190void migration_ioc_process_incoming(QIOChannel *ioc);
511c0231 191
428d8908
JQ
192bool migration_has_all_channels(void);
193
a0a3fd60
GC
194uint64_t migrate_max_downtime(void);
195
87db1a7d 196void migrate_set_error(MigrationState *s, const Error *error);
d59ce6f3 197void migrate_fd_error(MigrationState *s, const Error *error);
065e2813 198
cce8040b 199void migrate_fd_connect(MigrationState *s, Error *error_in);
065e2813 200
3e0c8050 201void migrate_init(MigrationState *s);
24f3902b 202bool migration_is_blocked(Error **errp);
9ec055ae 203/* True if outgoing migration has entered postcopy phase */
5727309d 204bool migration_in_postcopy(void);
859bc756 205MigrationState *migrate_get_current(void);
99a0db9b 206
58110f0a
VSO
207bool migrate_postcopy(void);
208
53f09a10 209bool migrate_release_ram(void);
53dd370c 210bool migrate_postcopy_ram(void);
323004a3 211bool migrate_zero_blocks(void);
55efc8c2 212bool migrate_dirty_bitmaps(void);
60d9222c 213
bde1e2ec 214bool migrate_auto_converge(void);
30126bbf 215bool migrate_use_multifd(void);
93fbd031 216bool migrate_pause_before_switchover(void);
4075fb1c 217int migrate_multifd_channels(void);
0fb86605 218int migrate_multifd_page_count(void);
bde1e2ec 219
17ad9b35
OW
220int migrate_use_xbzrle(void);
221int64_t migrate_xbzrle_cache_size(void);
35a6ed4f 222bool migrate_colo_enabled(void);
17ad9b35 223
2833c59b
JQ
224bool migrate_use_block(void);
225bool migrate_use_block_incremental(void);
c788ada8 226bool migrate_use_return_path(void);
2833c59b 227
8706d2d5
LL
228bool migrate_use_compression(void);
229int migrate_compress_level(void);
230int migrate_compress_threads(void);
3fcb38c2 231int migrate_decompress_threads(void);
b05dc723 232bool migrate_use_events(void);
8706d2d5 233
6decec93 234/* Sending on the return path - generic and then for each message type */
6decec93
DDAG
235void migrate_send_rp_shut(MigrationIncomingState *mis,
236 uint32_t value);
237void migrate_send_rp_pong(MigrationIncomingState *mis,
238 uint32_t value);
d6208e35 239int migrate_send_rp_req_pages(MigrationIncomingState *mis, const char* rbname,
1e2d90eb 240 ram_addr_t start, size_t len);
6decec93 241
b35ebdf0
VSO
242void dirty_bitmap_mig_before_vm_start(void);
243void init_dirty_bitmap_incoming_migration(void);
244
5bb7910a 245#endif
This page took 0.67368 seconds and 4 git commands to generate.