]> git.proxmox.com Git - mirror_qemu.git/blame - migration/migration.h
migration: split use of MigrationState.total_time
[mirror_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 <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#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"
4f0fae7f 23#include "io/channel.h"
376253ec 24
01a87f0b
AP
25struct PostcopyBlocktimeContext;
26
bca7856a
DDAG
27/* State for the incoming migration */
28struct MigrationIncomingState {
42e2aa56 29 QEMUFile *from_src_file;
1a8f46f8 30
7b89bf27
DDAG
31 /*
32 * Free at the start of the main state load, set as the main thread finishes
33 * loading state.
34 */
35 QemuEvent main_thread_load_event;
36
67f11b5c 37 size_t largest_page_size;
c4faeed2 38 bool have_fault_thread;
f0a227ad
DDAG
39 QemuThread fault_thread;
40 QemuSemaphore fault_thread_sem;
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;
c4faeed2
DDAG
48 /* To tell the fault_thread to quit */
49 int userfault_quit_fd;
2e37701e 50 QEMUFile *to_src_file;
6decec93 51 QemuMutex rp_mutex; /* We send replies from multiple threads */
696ed9a9 52 void *postcopy_tmp_page;
41d84210 53 void *postcopy_tmp_zero_page;
2e37701e 54
0aa6aefc
DL
55 QEMUBH *bh;
56
93d7af6f 57 int state;
25d0c16f
HZ
58
59 bool have_colo_incoming_thread;
60 QemuThread colo_incoming_thread;
61 /* The coroutine we should enter (back) after failover */
62 Coroutine *migration_incoming_co;
c937b9a6 63 QemuSemaphore colo_incoming_sem;
01a87f0b
AP
64
65 /*
66 * PostcopyBlocktimeContext to keep information for postcopy
67 * live migration, to calculate vCPU block time
68 * */
69 struct PostcopyBlocktimeContext *blocktime_ctx;
bca7856a
DDAG
70};
71
72MigrationIncomingState *migration_incoming_get_current(void);
bca7856a 73void migration_incoming_state_destroy(void);
ca6011c2
AP
74/*
75 * Functions to work with blocktime context
76 */
77void fill_destination_postcopy_migration_info(MigrationInfo *info);
bca7856a 78
e5cb7e76
PX
79#define TYPE_MIGRATION "migration"
80
81#define MIGRATION_CLASS(klass) \
82 OBJECT_CLASS_CHECK(MigrationClass, (klass), TYPE_MIGRATION)
83#define MIGRATION_OBJ(obj) \
84 OBJECT_CHECK(MigrationState, (obj), TYPE_MIGRATION)
85#define MIGRATION_GET_CLASS(obj) \
86 OBJECT_GET_CLASS(MigrationClass, (obj), TYPE_MIGRATION)
87
88typedef struct MigrationClass {
89 /*< private >*/
90 DeviceClass parent_class;
91} MigrationClass;
92
22f00a44 93struct MigrationState
065e2813 94{
e5cb7e76
PX
95 /*< private >*/
96 DeviceState parent_obj;
97
98 /*< public >*/
9848a404
JQ
99 size_t bytes_xfer;
100 size_t xfer_limit;
9848a404 101 QemuThread thread;
bb1fadc4 102 QEMUBH *cleanup_bh;
89a02a9f 103 QEMUFile *to_dst_file;
2594f56d 104
a0762d9e 105 /* params from 'migrate-set-parameters' */
2594f56d 106 MigrationParameters parameters;
f8bbc128 107
f8bbc128 108 int state;
70b20477
DDAG
109
110 /* State related to return path */
111 struct {
112 QEMUFile *from_dst_file;
113 QemuThread rp_thread;
114 bool error;
115 } rp_state;
116
7e114f8c 117 double mbps;
4af246a3
PX
118 /* Timestamp when recent migration starts (ms) */
119 int64_t start_time;
120 /* Total time used by latest migration (ms) */
d5f8a570 121 int64_t total_time;
9c5a9fcf 122 int64_t downtime;
2c52ddf1 123 int64_t expected_downtime;
7fb1cf16 124 bool enabled_capabilities[MIGRATION_CAPABILITY__MAX];
ed4fbd10 125 int64_t setup_time;
4886a1bc
DDAG
126
127 /* Flag set once the migration has been asked to enter postcopy */
128 bool start_postcopy;
b82fc321
DDAG
129 /* Flag set after postcopy has sent the device state */
130 bool postcopy_after_devices;
1d34e4bf
DDAG
131
132 /* Flag set once the migration thread is running (and needs joining) */
133 bool migration_thread_running;
6c595cde 134
1d2acc31
HZ
135 /* Flag set once the migration thread called bdrv_inactivate_all */
136 bool block_inactive;
137
e91d8951
DDAG
138 /* Migration is paused due to pause-before-switchover */
139 QemuSemaphore pause_sem;
140
c937b9a6
HZ
141 /* The semaphore is used to notify COLO thread that failover is finished */
142 QemuSemaphore colo_exit_sem;
d59ce6f3 143
479125d5
HZ
144 /* The semaphore is used to notify COLO thread to do checkpoint */
145 QemuSemaphore colo_checkpoint_sem;
146 int64_t colo_checkpoint_time;
147 QEMUTimer *colo_delay_timer;
148
87db1a7d
JQ
149 /* The first error that has occurred.
150 We used the mutex to be able to return the 1st error message */
d59ce6f3 151 Error *error;
87db1a7d
JQ
152 /* mutex to protect errp */
153 QemuMutex error_mutex;
154
2833c59b
JQ
155 /* Do we have to clean up -b/-i from old migrate parameters */
156 /* This feature is deprecated and will be removed */
157 bool must_remove_block_options;
5272298c
PX
158
159 /*
160 * Global switch on whether we need to store the global state
161 * during migration.
162 */
163 bool store_global_state;
3df663e5
PX
164
165 /* Whether the VM is only allowing for migratable devices */
166 bool only_migratable;
71dd4c1a
PX
167
168 /* Whether we send QEMU_VM_CONFIGURATION during migration */
169 bool send_configuration;
15c38503
PX
170 /* Whether we send section footer during migration */
171 bool send_section_footer;
065e2813
AL
172};
173
48781e5b
HZ
174void migrate_set_state(int *state, int old_state, int new_state);
175
22724f49 176void migration_fd_process_incoming(QEMUFile *f);
4f0fae7f 177void migration_ioc_process_incoming(QIOChannel *ioc);
511c0231 178
428d8908
JQ
179bool migration_has_all_channels(void);
180
a0a3fd60
GC
181uint64_t migrate_max_downtime(void);
182
87db1a7d 183void migrate_set_error(MigrationState *s, const Error *error);
d59ce6f3 184void migrate_fd_error(MigrationState *s, const Error *error);
065e2813 185
22f00a44 186void migrate_fd_connect(MigrationState *s);
065e2813 187
a0762d9e 188MigrationState *migrate_init(void);
24f3902b 189bool migration_is_blocked(Error **errp);
9ec055ae 190/* True if outgoing migration has entered postcopy phase */
5727309d 191bool migration_in_postcopy(void);
859bc756 192MigrationState *migrate_get_current(void);
99a0db9b 193
58110f0a
VSO
194bool migrate_postcopy(void);
195
53f09a10 196bool migrate_release_ram(void);
53dd370c 197bool migrate_postcopy_ram(void);
323004a3 198bool migrate_zero_blocks(void);
60d9222c 199
bde1e2ec 200bool migrate_auto_converge(void);
30126bbf 201bool migrate_use_multifd(void);
93fbd031 202bool migrate_pause_before_switchover(void);
4075fb1c 203int migrate_multifd_channels(void);
0fb86605 204int migrate_multifd_page_count(void);
bde1e2ec 205
17ad9b35
OW
206int migrate_use_xbzrle(void);
207int64_t migrate_xbzrle_cache_size(void);
35a6ed4f 208bool migrate_colo_enabled(void);
17ad9b35 209
2833c59b
JQ
210bool migrate_use_block(void);
211bool migrate_use_block_incremental(void);
c788ada8 212bool migrate_use_return_path(void);
2833c59b 213
8706d2d5
LL
214bool migrate_use_compression(void);
215int migrate_compress_level(void);
216int migrate_compress_threads(void);
3fcb38c2 217int migrate_decompress_threads(void);
b05dc723 218bool migrate_use_events(void);
31bf06a9 219bool migrate_postcopy_blocktime(void);
8706d2d5 220
6decec93 221/* Sending on the return path - generic and then for each message type */
6decec93
DDAG
222void migrate_send_rp_shut(MigrationIncomingState *mis,
223 uint32_t value);
224void migrate_send_rp_pong(MigrationIncomingState *mis,
225 uint32_t value);
1e2d90eb
DDAG
226void migrate_send_rp_req_pages(MigrationIncomingState *mis, const char* rbname,
227 ram_addr_t start, size_t len);
6decec93 228
5bb7910a 229#endif