4 * Copyright IBM, Corp. 2008
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
14 #ifndef QEMU_MIGRATION_H
15 #define QEMU_MIGRATION_H
17 #include "qemu-common.h"
18 #include "qemu/thread.h"
19 #include "qapi-types.h"
20 #include "exec/cpu-common.h"
21 #include "qemu/coroutine_int.h"
24 /* State for the incoming migration */
25 struct MigrationIncomingState
{
26 QEMUFile
*from_src_file
;
29 * Free at the start of the main state load, set as the main thread finishes
32 QemuEvent main_thread_load_event
;
34 size_t largest_page_size
;
35 bool have_fault_thread
;
36 QemuThread fault_thread
;
37 QemuSemaphore fault_thread_sem
;
39 bool have_listen_thread
;
40 QemuThread listen_thread
;
41 QemuSemaphore listen_thread_sem
;
43 /* For the kernel to send us notifications */
45 /* To tell the fault_thread to quit */
46 int userfault_quit_fd
;
47 QEMUFile
*to_src_file
;
48 QemuMutex rp_mutex
; /* We send replies from multiple threads */
49 void *postcopy_tmp_page
;
50 void *postcopy_tmp_zero_page
;
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
;
60 QemuSemaphore colo_incoming_sem
;
63 MigrationIncomingState
*migration_incoming_get_current(void);
64 void migration_incoming_state_destroy(void);
66 #define TYPE_MIGRATION "migration"
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)
75 typedef struct MigrationClass
{
77 DeviceClass parent_class
;
83 DeviceState parent_obj
;
90 QEMUFile
*to_dst_file
;
92 /* params from 'migrate-set-parameters' */
93 MigrationParameters parameters
;
97 /* State related to return path */
99 QEMUFile
*from_dst_file
;
100 QemuThread rp_thread
;
107 int64_t expected_downtime
;
108 bool enabled_capabilities
[MIGRATION_CAPABILITY__MAX
];
109 int64_t xbzrle_cache_size
;
112 /* Flag set once the migration has been asked to enter postcopy */
114 /* Flag set after postcopy has sent the device state */
115 bool postcopy_after_devices
;
117 /* Flag set once the migration thread is running (and needs joining) */
118 bool migration_thread_running
;
120 /* Flag set once the migration thread called bdrv_inactivate_all */
123 /* The semaphore is used to notify COLO thread that failover is finished */
124 QemuSemaphore colo_exit_sem
;
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
;
131 /* The last error that occurred */
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
;
138 * Global switch on whether we need to store the global state
141 bool store_global_state
;
143 /* Whether the VM is only allowing for migratable devices */
144 bool only_migratable
;
146 /* Whether we send QEMU_VM_CONFIGURATION during migration */
147 bool send_configuration
;
148 /* Whether we send section footer during migration */
149 bool send_section_footer
;
152 void migrate_set_state(int *state
, int old_state
, int new_state
);
154 void migration_fd_process_incoming(QEMUFile
*f
);
156 uint64_t migrate_max_downtime(void);
158 void migrate_fd_error(MigrationState
*s
, const Error
*error
);
160 void migrate_fd_connect(MigrationState
*s
);
162 MigrationState
*migrate_init(void);
163 bool migration_is_blocked(Error
**errp
);
164 /* True if outgoing migration has entered postcopy phase */
165 bool migration_in_postcopy(void);
166 MigrationState
*migrate_get_current(void);
168 bool migrate_release_ram(void);
169 bool migrate_postcopy_ram(void);
170 bool migrate_zero_blocks(void);
172 bool migrate_auto_converge(void);
174 int migrate_use_xbzrle(void);
175 int64_t migrate_xbzrle_cache_size(void);
176 bool migrate_colo_enabled(void);
178 bool migrate_use_block(void);
179 bool migrate_use_block_incremental(void);
181 bool migrate_use_compression(void);
182 int migrate_compress_level(void);
183 int migrate_compress_threads(void);
184 int migrate_decompress_threads(void);
185 bool migrate_use_events(void);
187 /* Sending on the return path - generic and then for each message type */
188 void migrate_send_rp_shut(MigrationIncomingState
*mis
,
190 void migrate_send_rp_pong(MigrationIncomingState
*mis
,
192 void migrate_send_rp_req_pages(MigrationIncomingState
*mis
, const char* rbname
,
193 ram_addr_t start
, size_t len
);