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