]>
Commit | Line | Data |
---|---|---|
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" |
9848a404 | 18 | #include "qemu/thread.h" |
bbf6da32 | 19 | #include "qapi-types.h" |
43487c67 | 20 | #include "exec/cpu-common.h" |
25d0c16f | 21 | #include "qemu/coroutine_int.h" |
e5cb7e76 | 22 | #include "hw/qdev.h" |
376253ec | 23 | |
bca7856a DDAG |
24 | /* State for the incoming migration */ |
25 | struct MigrationIncomingState { | |
42e2aa56 | 26 | QEMUFile *from_src_file; |
1a8f46f8 | 27 | |
7b89bf27 DDAG |
28 | /* |
29 | * Free at the start of the main state load, set as the main thread finishes | |
30 | * loading state. | |
31 | */ | |
32 | QemuEvent main_thread_load_event; | |
33 | ||
67f11b5c | 34 | size_t largest_page_size; |
c4faeed2 | 35 | bool have_fault_thread; |
f0a227ad DDAG |
36 | QemuThread fault_thread; |
37 | QemuSemaphore fault_thread_sem; | |
38 | ||
c76201ab DDAG |
39 | bool have_listen_thread; |
40 | QemuThread listen_thread; | |
41 | QemuSemaphore listen_thread_sem; | |
42 | ||
1caddf8a DDAG |
43 | /* For the kernel to send us notifications */ |
44 | int userfault_fd; | |
c4faeed2 DDAG |
45 | /* To tell the fault_thread to quit */ |
46 | int userfault_quit_fd; | |
2e37701e | 47 | QEMUFile *to_src_file; |
6decec93 | 48 | QemuMutex rp_mutex; /* We send replies from multiple threads */ |
696ed9a9 | 49 | void *postcopy_tmp_page; |
41d84210 | 50 | void *postcopy_tmp_zero_page; |
2e37701e | 51 | |
0aa6aefc DL |
52 | QEMUBH *bh; |
53 | ||
93d7af6f | 54 | int state; |
25d0c16f HZ |
55 | |
56 | bool have_colo_incoming_thread; | |
57 | QemuThread colo_incoming_thread; | |
58 | /* The coroutine we should enter (back) after failover */ | |
59 | Coroutine *migration_incoming_co; | |
c937b9a6 | 60 | QemuSemaphore colo_incoming_sem; |
bca7856a DDAG |
61 | }; |
62 | ||
63 | MigrationIncomingState *migration_incoming_get_current(void); | |
bca7856a DDAG |
64 | void migration_incoming_state_destroy(void); |
65 | ||
e5cb7e76 PX |
66 | #define TYPE_MIGRATION "migration" |
67 | ||
68 | #define MIGRATION_CLASS(klass) \ | |
69 | OBJECT_CLASS_CHECK(MigrationClass, (klass), TYPE_MIGRATION) | |
70 | #define MIGRATION_OBJ(obj) \ | |
71 | OBJECT_CHECK(MigrationState, (obj), TYPE_MIGRATION) | |
72 | #define MIGRATION_GET_CLASS(obj) \ | |
73 | OBJECT_GET_CLASS(MigrationClass, (obj), TYPE_MIGRATION) | |
74 | ||
75 | typedef struct MigrationClass { | |
76 | /*< private >*/ | |
77 | DeviceClass parent_class; | |
78 | } MigrationClass; | |
79 | ||
22f00a44 | 80 | struct MigrationState |
065e2813 | 81 | { |
e5cb7e76 PX |
82 | /*< private >*/ |
83 | DeviceState parent_obj; | |
84 | ||
85 | /*< public >*/ | |
9848a404 JQ |
86 | size_t bytes_xfer; |
87 | size_t xfer_limit; | |
9848a404 | 88 | QemuThread thread; |
bb1fadc4 | 89 | QEMUBH *cleanup_bh; |
89a02a9f | 90 | QEMUFile *to_dst_file; |
2594f56d | 91 | |
a0762d9e | 92 | /* params from 'migrate-set-parameters' */ |
2594f56d | 93 | MigrationParameters parameters; |
f8bbc128 | 94 | |
f8bbc128 | 95 | int state; |
70b20477 DDAG |
96 | |
97 | /* State related to return path */ | |
98 | struct { | |
99 | QEMUFile *from_dst_file; | |
100 | QemuThread rp_thread; | |
101 | bool error; | |
102 | } rp_state; | |
103 | ||
7e114f8c | 104 | double mbps; |
d5f8a570 | 105 | int64_t total_time; |
9c5a9fcf | 106 | int64_t downtime; |
2c52ddf1 | 107 | int64_t expected_downtime; |
7fb1cf16 | 108 | bool enabled_capabilities[MIGRATION_CAPABILITY__MAX]; |
17ad9b35 | 109 | int64_t xbzrle_cache_size; |
ed4fbd10 | 110 | int64_t setup_time; |
4886a1bc DDAG |
111 | |
112 | /* Flag set once the migration has been asked to enter postcopy */ | |
113 | bool start_postcopy; | |
b82fc321 DDAG |
114 | /* Flag set after postcopy has sent the device state */ |
115 | bool postcopy_after_devices; | |
1d34e4bf DDAG |
116 | |
117 | /* Flag set once the migration thread is running (and needs joining) */ | |
118 | bool migration_thread_running; | |
6c595cde | 119 | |
1d2acc31 HZ |
120 | /* Flag set once the migration thread called bdrv_inactivate_all */ |
121 | bool block_inactive; | |
122 | ||
c937b9a6 HZ |
123 | /* The semaphore is used to notify COLO thread that failover is finished */ |
124 | QemuSemaphore colo_exit_sem; | |
d59ce6f3 | 125 | |
479125d5 HZ |
126 | /* The semaphore is used to notify COLO thread to do checkpoint */ |
127 | QemuSemaphore colo_checkpoint_sem; | |
128 | int64_t colo_checkpoint_time; | |
129 | QEMUTimer *colo_delay_timer; | |
130 | ||
d59ce6f3 DB |
131 | /* The last error that occurred */ |
132 | Error *error; | |
2833c59b JQ |
133 | /* Do we have to clean up -b/-i from old migrate parameters */ |
134 | /* This feature is deprecated and will be removed */ | |
135 | bool must_remove_block_options; | |
5272298c PX |
136 | |
137 | /* | |
138 | * Global switch on whether we need to store the global state | |
139 | * during migration. | |
140 | */ | |
141 | bool store_global_state; | |
3df663e5 PX |
142 | |
143 | /* Whether the VM is only allowing for migratable devices */ | |
144 | bool only_migratable; | |
71dd4c1a PX |
145 | |
146 | /* Whether we send QEMU_VM_CONFIGURATION during migration */ | |
147 | bool send_configuration; | |
15c38503 PX |
148 | /* Whether we send section footer during migration */ |
149 | bool send_section_footer; | |
065e2813 AL |
150 | }; |
151 | ||
48781e5b HZ |
152 | void migrate_set_state(int *state, int old_state, int new_state); |
153 | ||
22724f49 | 154 | void migration_fd_process_incoming(QEMUFile *f); |
511c0231 | 155 | |
a0a3fd60 GC |
156 | uint64_t migrate_max_downtime(void); |
157 | ||
d59ce6f3 | 158 | void migrate_fd_error(MigrationState *s, const Error *error); |
065e2813 | 159 | |
22f00a44 | 160 | void migrate_fd_connect(MigrationState *s); |
065e2813 | 161 | |
a0762d9e | 162 | MigrationState *migrate_init(void); |
24f3902b | 163 | bool migration_is_blocked(Error **errp); |
9ec055ae | 164 | /* True if outgoing migration has entered postcopy phase */ |
5727309d | 165 | bool migration_in_postcopy(void); |
859bc756 | 166 | MigrationState *migrate_get_current(void); |
99a0db9b | 167 | |
53f09a10 | 168 | bool migrate_release_ram(void); |
53dd370c | 169 | bool migrate_postcopy_ram(void); |
323004a3 | 170 | bool migrate_zero_blocks(void); |
60d9222c | 171 | |
bde1e2ec CV |
172 | bool migrate_auto_converge(void); |
173 | ||
17ad9b35 OW |
174 | int migrate_use_xbzrle(void); |
175 | int64_t migrate_xbzrle_cache_size(void); | |
35a6ed4f | 176 | bool migrate_colo_enabled(void); |
17ad9b35 | 177 | |
2833c59b JQ |
178 | bool migrate_use_block(void); |
179 | bool migrate_use_block_incremental(void); | |
c788ada8 | 180 | bool migrate_use_return_path(void); |
2833c59b | 181 | |
8706d2d5 LL |
182 | bool migrate_use_compression(void); |
183 | int migrate_compress_level(void); | |
184 | int migrate_compress_threads(void); | |
3fcb38c2 | 185 | int migrate_decompress_threads(void); |
b05dc723 | 186 | bool migrate_use_events(void); |
8706d2d5 | 187 | |
6decec93 | 188 | /* Sending on the return path - generic and then for each message type */ |
6decec93 DDAG |
189 | void migrate_send_rp_shut(MigrationIncomingState *mis, |
190 | uint32_t value); | |
191 | void migrate_send_rp_pong(MigrationIncomingState *mis, | |
192 | uint32_t value); | |
1e2d90eb DDAG |
193 | void migrate_send_rp_req_pages(MigrationIncomingState *mis, const char* rbname, |
194 | ram_addr_t start, size_t len); | |
6decec93 | 195 | |
5bb7910a | 196 | #endif |