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 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" 22 23 /* State for the incoming migration */ 24 struct MigrationIncomingState { 25 QEMUFile *from_src_file; 26 27 /* 28 * Free at the start of the main state load, set as the main thread finishes 29 * loading state. 30 */ 31 QemuEvent main_thread_load_event; 32 33 size_t largest_page_size; 34 bool have_fault_thread; 35 QemuThread fault_thread; 36 QemuSemaphore fault_thread_sem; 37 38 bool have_listen_thread; 39 QemuThread listen_thread; 40 QemuSemaphore listen_thread_sem; 41 42 /* For the kernel to send us notifications */ 43 int userfault_fd; 44 /* To tell the fault_thread to quit */ 45 int userfault_quit_fd; 46 QEMUFile *to_src_file; 47 QemuMutex rp_mutex; /* We send replies from multiple threads */ 48 void *postcopy_tmp_page; 49 void *postcopy_tmp_zero_page; 50 51 QEMUBH *bh; 52 53 int state; 54 55 bool have_colo_incoming_thread; 56 QemuThread colo_incoming_thread; 57 /* The coroutine we should enter (back) after failover */ 58 Coroutine *migration_incoming_co; 59 QemuSemaphore colo_incoming_sem; 60 }; 61 62 MigrationIncomingState *migration_incoming_get_current(void); 63 void migration_incoming_state_destroy(void); 64 65 struct MigrationState 66 { 67 size_t bytes_xfer; 68 size_t xfer_limit; 69 QemuThread thread; 70 QEMUBH *cleanup_bh; 71 QEMUFile *to_dst_file; 72 73 /* params from 'migrate-set-parameters' */ 74 MigrationParameters parameters; 75 76 int state; 77 78 /* State related to return path */ 79 struct { 80 QEMUFile *from_dst_file; 81 QemuThread rp_thread; 82 bool error; 83 } rp_state; 84 85 double mbps; 86 int64_t total_time; 87 int64_t downtime; 88 int64_t expected_downtime; 89 bool enabled_capabilities[MIGRATION_CAPABILITY__MAX]; 90 int64_t xbzrle_cache_size; 91 int64_t setup_time; 92 93 /* Flag set once the migration has been asked to enter postcopy */ 94 bool start_postcopy; 95 /* Flag set after postcopy has sent the device state */ 96 bool postcopy_after_devices; 97 98 /* Flag set once the migration thread is running (and needs joining) */ 99 bool migration_thread_running; 100 101 /* Flag set once the migration thread called bdrv_inactivate_all */ 102 bool block_inactive; 103 104 /* The semaphore is used to notify COLO thread that failover is finished */ 105 QemuSemaphore colo_exit_sem; 106 107 /* The semaphore is used to notify COLO thread to do checkpoint */ 108 QemuSemaphore colo_checkpoint_sem; 109 int64_t colo_checkpoint_time; 110 QEMUTimer *colo_delay_timer; 111 112 /* The last error that occurred */ 113 Error *error; 114 /* Do we have to clean up -b/-i from old migrate parameters */ 115 /* This feature is deprecated and will be removed */ 116 bool must_remove_block_options; 117 }; 118 119 void migrate_set_state(int *state, int old_state, int new_state); 120 121 void migration_fd_process_incoming(QEMUFile *f); 122 123 uint64_t migrate_max_downtime(void); 124 125 void migrate_fd_error(MigrationState *s, const Error *error); 126 127 void migrate_fd_connect(MigrationState *s); 128 129 MigrationState *migrate_init(void); 130 bool migration_is_blocked(Error **errp); 131 /* True if outgoing migration has entered postcopy phase */ 132 bool migration_in_postcopy(void); 133 MigrationState *migrate_get_current(void); 134 135 bool migrate_release_ram(void); 136 bool migrate_postcopy_ram(void); 137 bool migrate_zero_blocks(void); 138 139 bool migrate_auto_converge(void); 140 141 int migrate_use_xbzrle(void); 142 int64_t migrate_xbzrle_cache_size(void); 143 bool migrate_colo_enabled(void); 144 145 bool migrate_use_block(void); 146 bool migrate_use_block_incremental(void); 147 148 bool migrate_use_compression(void); 149 int migrate_compress_level(void); 150 int migrate_compress_threads(void); 151 int migrate_decompress_threads(void); 152 bool migrate_use_events(void); 153 154 /* Sending on the return path - generic and then for each message type */ 155 void migrate_send_rp_shut(MigrationIncomingState *mis, 156 uint32_t value); 157 void migrate_send_rp_pong(MigrationIncomingState *mis, 158 uint32_t value); 159 void migrate_send_rp_req_pages(MigrationIncomingState *mis, const char* rbname, 160 ram_addr_t start, size_t len); 161 162 #endif 163