aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 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 | * |
Paolo Bonzini | 6b620ca | 2012-01-13 17:44:23 +0100 | [diff] [blame] | 12 | * Contributions after 2012-01-13 are licensed under the terms of the |
| 13 | * GNU GPL, version 2 or (at your option) any later version. |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include "qemu-common.h" |
| 17 | #include "migration.h" |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 18 | #include "monitor.h" |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 19 | #include "buffered_file.h" |
| 20 | #include "sysemu.h" |
Paolo Bonzini | 737e150 | 2012-12-17 18:19:44 +0100 | [diff] [blame^] | 21 | #include "block/block.h" |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 22 | #include "qemu_socket.h" |
Jan Kiszka | 25f2364 | 2009-11-30 18:21:21 +0100 | [diff] [blame] | 23 | #include "block-migration.h" |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 24 | #include "qmp-commands.h" |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 25 | |
| 26 | //#define DEBUG_MIGRATION |
| 27 | |
| 28 | #ifdef DEBUG_MIGRATION |
malc | d0f2c4c | 2010-02-07 02:03:50 +0300 | [diff] [blame] | 29 | #define DPRINTF(fmt, ...) \ |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 30 | do { printf("migration: " fmt, ## __VA_ARGS__); } while (0) |
| 31 | #else |
malc | d0f2c4c | 2010-02-07 02:03:50 +0300 | [diff] [blame] | 32 | #define DPRINTF(fmt, ...) \ |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 33 | do { } while (0) |
| 34 | #endif |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 35 | |
Juan Quintela | 7dc688e | 2011-02-23 00:48:46 +0100 | [diff] [blame] | 36 | enum { |
| 37 | MIG_STATE_ERROR, |
| 38 | MIG_STATE_SETUP, |
| 39 | MIG_STATE_CANCELLED, |
| 40 | MIG_STATE_ACTIVE, |
| 41 | MIG_STATE_COMPLETED, |
| 42 | }; |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 43 | |
Juan Quintela | d0ae46c | 2011-02-23 00:33:19 +0100 | [diff] [blame] | 44 | #define MAX_THROTTLE (32 << 20) /* Migration speed throttling */ |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 45 | |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 46 | /* Migration XBZRLE default cache size */ |
| 47 | #define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024) |
| 48 | |
Gerd Hoffmann | 99a0db9 | 2010-12-13 17:30:12 +0100 | [diff] [blame] | 49 | static NotifierList migration_state_notifiers = |
| 50 | NOTIFIER_LIST_INITIALIZER(migration_state_notifiers); |
| 51 | |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 52 | /* When we add fault tolerance, we could have several |
| 53 | migrations at once. For now we don't need to add |
| 54 | dynamic creation of migration */ |
| 55 | |
Juan Quintela | 859bc75 | 2012-08-13 09:42:49 +0200 | [diff] [blame] | 56 | MigrationState *migrate_get_current(void) |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 57 | { |
| 58 | static MigrationState current_migration = { |
| 59 | .state = MIG_STATE_SETUP, |
Juan Quintela | d0ae46c | 2011-02-23 00:33:19 +0100 | [diff] [blame] | 60 | .bandwidth_limit = MAX_THROTTLE, |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 61 | .xbzrle_cache_size = DEFAULT_MIGRATE_CACHE_SIZE, |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | return ¤t_migration; |
| 65 | } |
| 66 | |
Paolo Bonzini | 43eaae2 | 2012-10-02 18:21:18 +0200 | [diff] [blame] | 67 | void qemu_start_incoming_migration(const char *uri, Error **errp) |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 68 | { |
aliguori | 34c9dd8 | 2008-10-13 03:14:31 +0000 | [diff] [blame] | 69 | const char *p; |
| 70 | |
| 71 | if (strstart(uri, "tcp:", &p)) |
Paolo Bonzini | 43eaae2 | 2012-10-02 18:21:18 +0200 | [diff] [blame] | 72 | tcp_start_incoming_migration(p, errp); |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 73 | #if !defined(WIN32) |
| 74 | else if (strstart(uri, "exec:", &p)) |
Paolo Bonzini | 43eaae2 | 2012-10-02 18:21:18 +0200 | [diff] [blame] | 75 | exec_start_incoming_migration(p, errp); |
Chris Lalancette | 4951f65 | 2009-08-05 17:24:29 +0200 | [diff] [blame] | 76 | else if (strstart(uri, "unix:", &p)) |
Paolo Bonzini | 43eaae2 | 2012-10-02 18:21:18 +0200 | [diff] [blame] | 77 | unix_start_incoming_migration(p, errp); |
Paolo Bonzini | 5ac1fad | 2009-08-18 15:56:25 +0200 | [diff] [blame] | 78 | else if (strstart(uri, "fd:", &p)) |
Paolo Bonzini | 43eaae2 | 2012-10-02 18:21:18 +0200 | [diff] [blame] | 79 | fd_start_incoming_migration(p, errp); |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 80 | #endif |
Juan Quintela | 8ca5e80 | 2010-06-09 14:10:54 +0200 | [diff] [blame] | 81 | else { |
Paolo Bonzini | 43eaae2 | 2012-10-02 18:21:18 +0200 | [diff] [blame] | 82 | error_setg(errp, "unknown migration protocol: %s\n", uri); |
Juan Quintela | 8ca5e80 | 2010-06-09 14:10:54 +0200 | [diff] [blame] | 83 | } |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Paolo Bonzini | 82a4da7 | 2012-08-07 10:57:43 +0200 | [diff] [blame] | 86 | static void process_incoming_migration_co(void *opaque) |
Juan Quintela | 511c023 | 2010-06-09 14:10:55 +0200 | [diff] [blame] | 87 | { |
Paolo Bonzini | 82a4da7 | 2012-08-07 10:57:43 +0200 | [diff] [blame] | 88 | QEMUFile *f = opaque; |
Paolo Bonzini | 1c12e1f | 2012-08-07 10:51:51 +0200 | [diff] [blame] | 89 | int ret; |
| 90 | |
| 91 | ret = qemu_loadvm_state(f); |
Paolo Bonzini | 82a4da7 | 2012-08-07 10:57:43 +0200 | [diff] [blame] | 92 | qemu_set_fd_handler(qemu_get_fd(f), NULL, NULL, NULL); |
Paolo Bonzini | 1c12e1f | 2012-08-07 10:51:51 +0200 | [diff] [blame] | 93 | qemu_fclose(f); |
| 94 | if (ret < 0) { |
Juan Quintela | 511c023 | 2010-06-09 14:10:55 +0200 | [diff] [blame] | 95 | fprintf(stderr, "load of migration failed\n"); |
| 96 | exit(0); |
| 97 | } |
| 98 | qemu_announce_self(); |
| 99 | DPRINTF("successfully loaded vm state\n"); |
| 100 | |
BenoƮt Canet | 901862c | 2012-03-23 08:36:52 +0100 | [diff] [blame] | 101 | bdrv_clear_incoming_migration_all(); |
Anthony Liguori | 0f15423 | 2011-11-14 15:09:45 -0600 | [diff] [blame] | 102 | /* Make sure all file formats flush their mutable metadata */ |
| 103 | bdrv_invalidate_cache_all(); |
| 104 | |
Luiz Capitulino | f5bbfba | 2011-07-29 15:04:45 -0300 | [diff] [blame] | 105 | if (autostart) { |
Juan Quintela | 511c023 | 2010-06-09 14:10:55 +0200 | [diff] [blame] | 106 | vm_start(); |
Luiz Capitulino | f5bbfba | 2011-07-29 15:04:45 -0300 | [diff] [blame] | 107 | } else { |
Paolo Bonzini | 29ed72f | 2012-10-19 16:45:24 +0200 | [diff] [blame] | 108 | runstate_set(RUN_STATE_PAUSED); |
Luiz Capitulino | f5bbfba | 2011-07-29 15:04:45 -0300 | [diff] [blame] | 109 | } |
Juan Quintela | 511c023 | 2010-06-09 14:10:55 +0200 | [diff] [blame] | 110 | } |
| 111 | |
Paolo Bonzini | 82a4da7 | 2012-08-07 10:57:43 +0200 | [diff] [blame] | 112 | static void enter_migration_coroutine(void *opaque) |
| 113 | { |
| 114 | Coroutine *co = opaque; |
| 115 | qemu_coroutine_enter(co, NULL); |
| 116 | } |
| 117 | |
| 118 | void process_incoming_migration(QEMUFile *f) |
| 119 | { |
| 120 | Coroutine *co = qemu_coroutine_create(process_incoming_migration_co); |
| 121 | int fd = qemu_get_fd(f); |
| 122 | |
| 123 | assert(fd != -1); |
| 124 | socket_set_nonblock(fd); |
| 125 | qemu_set_fd_handler(fd, enter_migration_coroutine, NULL, co); |
| 126 | qemu_coroutine_enter(co, f); |
| 127 | } |
| 128 | |
Glauber Costa | a0a3fd6 | 2009-05-28 15:22:57 -0400 | [diff] [blame] | 129 | /* amount of nanoseconds we are willing to wait for migration to be down. |
| 130 | * the choice of nanoseconds is because it is the maximum resolution that |
| 131 | * get_clock() can achieve. It is an internal measure. All user-visible |
| 132 | * units must be in seconds */ |
| 133 | static uint64_t max_downtime = 30000000; |
| 134 | |
| 135 | uint64_t migrate_max_downtime(void) |
| 136 | { |
| 137 | return max_downtime; |
| 138 | } |
| 139 | |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 140 | MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp) |
| 141 | { |
| 142 | MigrationCapabilityStatusList *head = NULL; |
| 143 | MigrationCapabilityStatusList *caps; |
| 144 | MigrationState *s = migrate_get_current(); |
| 145 | int i; |
| 146 | |
| 147 | for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) { |
| 148 | if (head == NULL) { |
| 149 | head = g_malloc0(sizeof(*caps)); |
| 150 | caps = head; |
| 151 | } else { |
| 152 | caps->next = g_malloc0(sizeof(*caps)); |
| 153 | caps = caps->next; |
| 154 | } |
| 155 | caps->value = |
| 156 | g_malloc(sizeof(*caps->value)); |
| 157 | caps->value->capability = i; |
| 158 | caps->value->state = s->enabled_capabilities[i]; |
| 159 | } |
| 160 | |
| 161 | return head; |
| 162 | } |
| 163 | |
Orit Wasserman | f36d55a | 2012-08-06 21:42:57 +0300 | [diff] [blame] | 164 | static void get_xbzrle_cache_stats(MigrationInfo *info) |
| 165 | { |
| 166 | if (migrate_use_xbzrle()) { |
| 167 | info->has_xbzrle_cache = true; |
| 168 | info->xbzrle_cache = g_malloc0(sizeof(*info->xbzrle_cache)); |
| 169 | info->xbzrle_cache->cache_size = migrate_xbzrle_cache_size(); |
| 170 | info->xbzrle_cache->bytes = xbzrle_mig_bytes_transferred(); |
| 171 | info->xbzrle_cache->pages = xbzrle_mig_pages_transferred(); |
| 172 | info->xbzrle_cache->cache_miss = xbzrle_mig_pages_cache_miss(); |
| 173 | info->xbzrle_cache->overflow = xbzrle_mig_pages_overflow(); |
| 174 | } |
| 175 | } |
| 176 | |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 177 | MigrationInfo *qmp_query_migrate(Error **errp) |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 178 | { |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 179 | MigrationInfo *info = g_malloc0(sizeof(*info)); |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 180 | MigrationState *s = migrate_get_current(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 181 | |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 182 | switch (s->state) { |
| 183 | case MIG_STATE_SETUP: |
| 184 | /* no migration has happened ever */ |
| 185 | break; |
| 186 | case MIG_STATE_ACTIVE: |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 187 | info->has_status = true; |
| 188 | info->status = g_strdup("active"); |
Juan Quintela | 7aa939a | 2012-08-18 13:17:10 +0200 | [diff] [blame] | 189 | info->has_total_time = true; |
| 190 | info->total_time = qemu_get_clock_ms(rt_clock) |
| 191 | - s->total_time; |
Juan Quintela | 2c52ddf | 2012-08-13 09:53:12 +0200 | [diff] [blame] | 192 | info->has_expected_downtime = true; |
| 193 | info->expected_downtime = s->expected_downtime; |
Luiz Capitulino | c86a668 | 2009-12-10 17:16:05 -0200 | [diff] [blame] | 194 | |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 195 | info->has_ram = true; |
| 196 | info->ram = g_malloc0(sizeof(*info->ram)); |
| 197 | info->ram->transferred = ram_bytes_transferred(); |
| 198 | info->ram->remaining = ram_bytes_remaining(); |
| 199 | info->ram->total = ram_bytes_total(); |
Orit Wasserman | 004d4c1 | 2012-08-06 21:42:56 +0300 | [diff] [blame] | 200 | info->ram->duplicate = dup_mig_pages_transferred(); |
| 201 | info->ram->normal = norm_mig_pages_transferred(); |
| 202 | info->ram->normal_bytes = norm_mig_bytes_transferred(); |
Juan Quintela | 8d01719 | 2012-08-13 12:31:25 +0200 | [diff] [blame] | 203 | info->ram->dirty_pages_rate = s->dirty_pages_rate; |
| 204 | |
Luiz Capitulino | c86a668 | 2009-12-10 17:16:05 -0200 | [diff] [blame] | 205 | |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 206 | if (blk_mig_active()) { |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 207 | info->has_disk = true; |
| 208 | info->disk = g_malloc0(sizeof(*info->disk)); |
| 209 | info->disk->transferred = blk_mig_bytes_transferred(); |
| 210 | info->disk->remaining = blk_mig_bytes_remaining(); |
| 211 | info->disk->total = blk_mig_bytes_total(); |
aliguori | ff8d81d | 2008-10-24 22:10:31 +0000 | [diff] [blame] | 212 | } |
Orit Wasserman | f36d55a | 2012-08-06 21:42:57 +0300 | [diff] [blame] | 213 | |
| 214 | get_xbzrle_cache_stats(info); |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 215 | break; |
| 216 | case MIG_STATE_COMPLETED: |
Orit Wasserman | f36d55a | 2012-08-06 21:42:57 +0300 | [diff] [blame] | 217 | get_xbzrle_cache_stats(info); |
| 218 | |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 219 | info->has_status = true; |
| 220 | info->status = g_strdup("completed"); |
Juan Quintela | 7aa939a | 2012-08-18 13:17:10 +0200 | [diff] [blame] | 221 | info->total_time = s->total_time; |
Juan Quintela | 9c5a9fc | 2012-08-13 09:35:16 +0200 | [diff] [blame] | 222 | info->has_downtime = true; |
| 223 | info->downtime = s->downtime; |
Juan Quintela | d5f8a57 | 2012-05-21 22:01:07 +0200 | [diff] [blame] | 224 | |
| 225 | info->has_ram = true; |
| 226 | info->ram = g_malloc0(sizeof(*info->ram)); |
| 227 | info->ram->transferred = ram_bytes_transferred(); |
| 228 | info->ram->remaining = 0; |
| 229 | info->ram->total = ram_bytes_total(); |
Orit Wasserman | 004d4c1 | 2012-08-06 21:42:56 +0300 | [diff] [blame] | 230 | info->ram->duplicate = dup_mig_pages_transferred(); |
| 231 | info->ram->normal = norm_mig_pages_transferred(); |
| 232 | info->ram->normal_bytes = norm_mig_bytes_transferred(); |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 233 | break; |
| 234 | case MIG_STATE_ERROR: |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 235 | info->has_status = true; |
| 236 | info->status = g_strdup("failed"); |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 237 | break; |
| 238 | case MIG_STATE_CANCELLED: |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 239 | info->has_status = true; |
| 240 | info->status = g_strdup("cancelled"); |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 241 | break; |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 242 | } |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 243 | |
| 244 | return info; |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Orit Wasserman | 0045843 | 2012-08-06 21:42:48 +0300 | [diff] [blame] | 247 | void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params, |
| 248 | Error **errp) |
| 249 | { |
| 250 | MigrationState *s = migrate_get_current(); |
| 251 | MigrationCapabilityStatusList *cap; |
| 252 | |
| 253 | if (s->state == MIG_STATE_ACTIVE) { |
| 254 | error_set(errp, QERR_MIGRATION_ACTIVE); |
| 255 | return; |
| 256 | } |
| 257 | |
| 258 | for (cap = params; cap; cap = cap->next) { |
| 259 | s->enabled_capabilities[cap->value->capability] = cap->value->state; |
| 260 | } |
| 261 | } |
| 262 | |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 263 | /* shared migration helpers */ |
| 264 | |
Juan Quintela | 8b6b99b | 2011-09-11 20:28:22 +0200 | [diff] [blame] | 265 | static int migrate_fd_cleanup(MigrationState *s) |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 266 | { |
Anthony Liguori | 41ef56e | 2010-06-02 14:55:25 -0500 | [diff] [blame] | 267 | int ret = 0; |
| 268 | |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 269 | if (s->file) { |
malc | d0f2c4c | 2010-02-07 02:03:50 +0300 | [diff] [blame] | 270 | DPRINTF("closing file\n"); |
Eduardo Habkost | a6d34a9 | 2011-11-10 10:41:42 -0200 | [diff] [blame] | 271 | ret = qemu_fclose(s->file); |
Jan Kiszka | 5d39c79 | 2009-11-30 18:21:19 +0100 | [diff] [blame] | 272 | s->file = NULL; |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Paolo Bonzini | 8dc592e | 2012-09-27 13:25:45 +0200 | [diff] [blame] | 275 | migrate_fd_close(s); |
Anthony Liguori | 41ef56e | 2010-06-02 14:55:25 -0500 | [diff] [blame] | 276 | return ret; |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Juan Quintela | 8b6b99b | 2011-09-11 20:28:22 +0200 | [diff] [blame] | 279 | void migrate_fd_error(MigrationState *s) |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 280 | { |
Juan Quintela | 8b6b99b | 2011-09-11 20:28:22 +0200 | [diff] [blame] | 281 | DPRINTF("setting error state\n"); |
| 282 | s->state = MIG_STATE_ERROR; |
Juan Quintela | e0eb739 | 2011-10-05 14:27:52 +0200 | [diff] [blame] | 283 | notifier_list_notify(&migration_state_notifiers, s); |
Juan Quintela | 8b6b99b | 2011-09-11 20:28:22 +0200 | [diff] [blame] | 284 | migrate_fd_cleanup(s); |
| 285 | } |
| 286 | |
Juan Quintela | 458cf28 | 2011-02-22 23:32:54 +0100 | [diff] [blame] | 287 | static void migrate_fd_completed(MigrationState *s) |
| 288 | { |
| 289 | DPRINTF("setting completed state\n"); |
| 290 | if (migrate_fd_cleanup(s) < 0) { |
| 291 | s->state = MIG_STATE_ERROR; |
| 292 | } else { |
| 293 | s->state = MIG_STATE_COMPLETED; |
| 294 | runstate_set(RUN_STATE_POSTMIGRATE); |
| 295 | } |
Juan Quintela | e0eb739 | 2011-10-05 14:27:52 +0200 | [diff] [blame] | 296 | notifier_list_notify(&migration_state_notifiers, s); |
Juan Quintela | 458cf28 | 2011-02-22 23:32:54 +0100 | [diff] [blame] | 297 | } |
| 298 | |
Juan Quintela | 8b6b99b | 2011-09-11 20:28:22 +0200 | [diff] [blame] | 299 | static void migrate_fd_put_notify(void *opaque) |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 300 | { |
Juan Quintela | 22f00a4 | 2010-05-11 15:56:35 +0200 | [diff] [blame] | 301 | MigrationState *s = opaque; |
Juan Quintela | a2b4135 | 2012-09-04 12:45:42 +0200 | [diff] [blame] | 302 | int ret; |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 303 | |
| 304 | qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); |
Juan Quintela | a2b4135 | 2012-09-04 12:45:42 +0200 | [diff] [blame] | 305 | ret = qemu_file_put_notify(s->file); |
| 306 | if (ret) { |
Yoshiaki Tamura | 2350e13 | 2011-02-23 00:01:24 +0900 | [diff] [blame] | 307 | migrate_fd_error(s); |
| 308 | } |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Juan Quintela | c87b015 | 2012-07-20 13:10:54 +0200 | [diff] [blame] | 311 | ssize_t migrate_fd_put_buffer(MigrationState *s, const void *data, |
| 312 | size_t size) |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 313 | { |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 314 | ssize_t ret; |
| 315 | |
Juan Quintela | fdbecb5 | 2011-09-21 22:37:29 +0200 | [diff] [blame] | 316 | if (s->state != MIG_STATE_ACTIVE) { |
| 317 | return -EIO; |
| 318 | } |
| 319 | |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 320 | do { |
| 321 | ret = s->write(s, data, size); |
Uri Lublin | 95b134e | 2009-05-19 14:08:53 +0300 | [diff] [blame] | 322 | } while (ret == -1 && ((s->get_error(s)) == EINTR)); |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 323 | |
| 324 | if (ret == -1) |
| 325 | ret = -(s->get_error(s)); |
| 326 | |
Marcelo Tosatti | e447b1a | 2010-08-19 10:18:39 -0300 | [diff] [blame] | 327 | if (ret == -EAGAIN) { |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 328 | qemu_set_fd_handler2(s->fd, NULL, NULL, migrate_fd_put_notify, s); |
Marcelo Tosatti | e447b1a | 2010-08-19 10:18:39 -0300 | [diff] [blame] | 329 | } |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 330 | |
| 331 | return ret; |
| 332 | } |
| 333 | |
Juan Quintela | 2c9adcb | 2012-07-20 13:13:59 +0200 | [diff] [blame] | 334 | void migrate_fd_put_ready(MigrationState *s) |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 335 | { |
| 336 | int ret; |
| 337 | |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 338 | if (s->state != MIG_STATE_ACTIVE) { |
malc | d0f2c4c | 2010-02-07 02:03:50 +0300 | [diff] [blame] | 339 | DPRINTF("put_ready returning because of non-active state\n"); |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 340 | return; |
| 341 | } |
| 342 | |
malc | d0f2c4c | 2010-02-07 02:03:50 +0300 | [diff] [blame] | 343 | DPRINTF("iterate\n"); |
Luiz Capitulino | 539de12 | 2011-12-05 14:06:56 -0200 | [diff] [blame] | 344 | ret = qemu_savevm_state_iterate(s->file); |
Juan Quintela | 3934638 | 2011-09-22 11:02:14 +0200 | [diff] [blame] | 345 | if (ret < 0) { |
| 346 | migrate_fd_error(s); |
| 347 | } else if (ret == 1) { |
Luiz Capitulino | 1354869 | 2011-07-29 15:36:43 -0300 | [diff] [blame] | 348 | int old_vm_running = runstate_is_running(); |
Juan Quintela | 9c5a9fc | 2012-08-13 09:35:16 +0200 | [diff] [blame] | 349 | int64_t start_time, end_time; |
Anthony Liguori | eeb34af | 2009-07-09 13:25:47 -0500 | [diff] [blame] | 350 | |
malc | d0f2c4c | 2010-02-07 02:03:50 +0300 | [diff] [blame] | 351 | DPRINTF("done iterating\n"); |
Juan Quintela | 9c5a9fc | 2012-08-13 09:35:16 +0200 | [diff] [blame] | 352 | start_time = qemu_get_clock_ms(rt_clock); |
Gerd Hoffmann | 7b5d3aa | 2012-03-07 08:00:26 +0100 | [diff] [blame] | 353 | qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); |
Luiz Capitulino | 8a9236f | 2011-10-14 11:18:09 -0300 | [diff] [blame] | 354 | vm_stop_force_state(RUN_STATE_FINISH_MIGRATE); |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 355 | |
Luiz Capitulino | 539de12 | 2011-12-05 14:06:56 -0200 | [diff] [blame] | 356 | if (qemu_savevm_state_complete(s->file) < 0) { |
Juan Quintela | 67afff7 | 2011-02-22 23:18:20 +0100 | [diff] [blame] | 357 | migrate_fd_error(s); |
aliguori | b161d12 | 2009-04-05 19:30:33 +0000 | [diff] [blame] | 358 | } else { |
Juan Quintela | 458cf28 | 2011-02-22 23:32:54 +0100 | [diff] [blame] | 359 | migrate_fd_completed(s); |
aliguori | b161d12 | 2009-04-05 19:30:33 +0000 | [diff] [blame] | 360 | } |
Juan Quintela | 97d4d96 | 2012-08-10 21:53:08 +0200 | [diff] [blame] | 361 | end_time = qemu_get_clock_ms(rt_clock); |
| 362 | s->total_time = end_time - s->total_time; |
Juan Quintela | 9c5a9fc | 2012-08-13 09:35:16 +0200 | [diff] [blame] | 363 | s->downtime = end_time - start_time; |
Juan Quintela | 48a2f4d | 2010-05-11 23:28:53 +0200 | [diff] [blame] | 364 | if (s->state != MIG_STATE_COMPLETED) { |
Anthony Liguori | 41ef56e | 2010-06-02 14:55:25 -0500 | [diff] [blame] | 365 | if (old_vm_running) { |
| 366 | vm_start(); |
| 367 | } |
Anthony Liguori | 41ef56e | 2010-06-02 14:55:25 -0500 | [diff] [blame] | 368 | } |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | |
Juan Quintela | 0edda1c | 2010-05-11 16:28:39 +0200 | [diff] [blame] | 372 | static void migrate_fd_cancel(MigrationState *s) |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 373 | { |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 374 | if (s->state != MIG_STATE_ACTIVE) |
| 375 | return; |
| 376 | |
malc | d0f2c4c | 2010-02-07 02:03:50 +0300 | [diff] [blame] | 377 | DPRINTF("cancelling migration\n"); |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 378 | |
| 379 | s->state = MIG_STATE_CANCELLED; |
Juan Quintela | e0eb739 | 2011-10-05 14:27:52 +0200 | [diff] [blame] | 380 | notifier_list_notify(&migration_state_notifiers, s); |
Luiz Capitulino | 539de12 | 2011-12-05 14:06:56 -0200 | [diff] [blame] | 381 | qemu_savevm_state_cancel(s->file); |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 382 | |
| 383 | migrate_fd_cleanup(s); |
| 384 | } |
| 385 | |
Juan Quintela | 9499743 | 2012-08-24 12:51:48 +0200 | [diff] [blame] | 386 | int migrate_fd_wait_for_unfreeze(MigrationState *s) |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 387 | { |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 388 | int ret; |
| 389 | |
malc | d0f2c4c | 2010-02-07 02:03:50 +0300 | [diff] [blame] | 390 | DPRINTF("wait for unfreeze\n"); |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 391 | if (s->state != MIG_STATE_ACTIVE) |
Juan Quintela | 9499743 | 2012-08-24 12:51:48 +0200 | [diff] [blame] | 392 | return -EINVAL; |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 393 | |
| 394 | do { |
| 395 | fd_set wfds; |
| 396 | |
| 397 | FD_ZERO(&wfds); |
| 398 | FD_SET(s->fd, &wfds); |
| 399 | |
| 400 | ret = select(s->fd + 1, NULL, &wfds, NULL, NULL); |
| 401 | } while (ret == -1 && (s->get_error(s)) == EINTR); |
Juan Quintela | af50945 | 2011-09-21 22:46:36 +0200 | [diff] [blame] | 402 | |
| 403 | if (ret == -1) { |
Juan Quintela | 9499743 | 2012-08-24 12:51:48 +0200 | [diff] [blame] | 404 | return -s->get_error(s); |
Juan Quintela | af50945 | 2011-09-21 22:46:36 +0200 | [diff] [blame] | 405 | } |
Juan Quintela | 9499743 | 2012-08-24 12:51:48 +0200 | [diff] [blame] | 406 | return 0; |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Juan Quintela | 11c7674 | 2012-07-20 13:19:36 +0200 | [diff] [blame] | 409 | int migrate_fd_close(MigrationState *s) |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 410 | { |
Paolo Bonzini | 8dc592e | 2012-09-27 13:25:45 +0200 | [diff] [blame] | 411 | int rc = 0; |
| 412 | if (s->fd != -1) { |
| 413 | qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); |
| 414 | rc = s->close(s); |
| 415 | s->fd = -1; |
| 416 | } |
| 417 | return rc; |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 418 | } |
Gerd Hoffmann | 99a0db9 | 2010-12-13 17:30:12 +0100 | [diff] [blame] | 419 | |
| 420 | void add_migration_state_change_notifier(Notifier *notify) |
| 421 | { |
| 422 | notifier_list_add(&migration_state_notifiers, notify); |
| 423 | } |
| 424 | |
| 425 | void remove_migration_state_change_notifier(Notifier *notify) |
| 426 | { |
Paolo Bonzini | 3155252 | 2012-01-13 17:34:01 +0100 | [diff] [blame] | 427 | notifier_remove(notify); |
Gerd Hoffmann | 99a0db9 | 2010-12-13 17:30:12 +0100 | [diff] [blame] | 428 | } |
| 429 | |
Gerd Hoffmann | afe2df6 | 2011-10-25 13:50:11 +0200 | [diff] [blame] | 430 | bool migration_is_active(MigrationState *s) |
| 431 | { |
| 432 | return s->state == MIG_STATE_ACTIVE; |
| 433 | } |
| 434 | |
Juan Quintela | 7073693 | 2011-02-23 00:43:59 +0100 | [diff] [blame] | 435 | bool migration_has_finished(MigrationState *s) |
Gerd Hoffmann | 99a0db9 | 2010-12-13 17:30:12 +0100 | [diff] [blame] | 436 | { |
Juan Quintela | 7073693 | 2011-02-23 00:43:59 +0100 | [diff] [blame] | 437 | return s->state == MIG_STATE_COMPLETED; |
Gerd Hoffmann | 99a0db9 | 2010-12-13 17:30:12 +0100 | [diff] [blame] | 438 | } |
Juan Quintela | 0edda1c | 2010-05-11 16:28:39 +0200 | [diff] [blame] | 439 | |
Gerd Hoffmann | afe2df6 | 2011-10-25 13:50:11 +0200 | [diff] [blame] | 440 | bool migration_has_failed(MigrationState *s) |
| 441 | { |
| 442 | return (s->state == MIG_STATE_CANCELLED || |
| 443 | s->state == MIG_STATE_ERROR); |
| 444 | } |
| 445 | |
Juan Quintela | 8b6b99b | 2011-09-11 20:28:22 +0200 | [diff] [blame] | 446 | void migrate_fd_connect(MigrationState *s) |
| 447 | { |
| 448 | int ret; |
| 449 | |
Juan Quintela | d5934dd | 2010-05-11 23:01:53 +0200 | [diff] [blame] | 450 | s->state = MIG_STATE_ACTIVE; |
Juan Quintela | 796b4b0 | 2012-07-20 13:33:53 +0200 | [diff] [blame] | 451 | s->file = qemu_fopen_ops_buffered(s); |
Juan Quintela | 8b6b99b | 2011-09-11 20:28:22 +0200 | [diff] [blame] | 452 | |
| 453 | DPRINTF("beginning savevm\n"); |
Isaku Yamahata | 6607ae2 | 2012-06-19 18:43:09 +0300 | [diff] [blame] | 454 | ret = qemu_savevm_state_begin(s->file, &s->params); |
Juan Quintela | 8b6b99b | 2011-09-11 20:28:22 +0200 | [diff] [blame] | 455 | if (ret < 0) { |
| 456 | DPRINTF("failed, %d\n", ret); |
| 457 | migrate_fd_error(s); |
| 458 | return; |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 459 | } |
Juan Quintela | 8b6b99b | 2011-09-11 20:28:22 +0200 | [diff] [blame] | 460 | migrate_fd_put_ready(s); |
| 461 | } |
| 462 | |
Isaku Yamahata | 6607ae2 | 2012-06-19 18:43:09 +0300 | [diff] [blame] | 463 | static MigrationState *migrate_init(const MigrationParams *params) |
Juan Quintela | 0edda1c | 2010-05-11 16:28:39 +0200 | [diff] [blame] | 464 | { |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 465 | MigrationState *s = migrate_get_current(); |
Juan Quintela | d0ae46c | 2011-02-23 00:33:19 +0100 | [diff] [blame] | 466 | int64_t bandwidth_limit = s->bandwidth_limit; |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 467 | bool enabled_capabilities[MIGRATION_CAPABILITY_MAX]; |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 468 | int64_t xbzrle_cache_size = s->xbzrle_cache_size; |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 469 | |
| 470 | memcpy(enabled_capabilities, s->enabled_capabilities, |
| 471 | sizeof(enabled_capabilities)); |
Juan Quintela | 0edda1c | 2010-05-11 16:28:39 +0200 | [diff] [blame] | 472 | |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 473 | memset(s, 0, sizeof(*s)); |
Juan Quintela | d0ae46c | 2011-02-23 00:33:19 +0100 | [diff] [blame] | 474 | s->bandwidth_limit = bandwidth_limit; |
Isaku Yamahata | 6607ae2 | 2012-06-19 18:43:09 +0300 | [diff] [blame] | 475 | s->params = *params; |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 476 | memcpy(s->enabled_capabilities, enabled_capabilities, |
| 477 | sizeof(enabled_capabilities)); |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 478 | s->xbzrle_cache_size = xbzrle_cache_size; |
Juan Quintela | 1299c63 | 2011-11-09 21:29:01 +0100 | [diff] [blame] | 479 | |
Juan Quintela | 0edda1c | 2010-05-11 16:28:39 +0200 | [diff] [blame] | 480 | s->bandwidth_limit = bandwidth_limit; |
Juan Quintela | d5934dd | 2010-05-11 23:01:53 +0200 | [diff] [blame] | 481 | s->state = MIG_STATE_SETUP; |
Juan Quintela | d5f8a57 | 2012-05-21 22:01:07 +0200 | [diff] [blame] | 482 | s->total_time = qemu_get_clock_ms(rt_clock); |
Juan Quintela | 0edda1c | 2010-05-11 16:28:39 +0200 | [diff] [blame] | 483 | |
Juan Quintela | 0edda1c | 2010-05-11 16:28:39 +0200 | [diff] [blame] | 484 | return s; |
| 485 | } |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 486 | |
Anthony Liguori | fa2756b | 2011-11-14 15:09:43 -0600 | [diff] [blame] | 487 | static GSList *migration_blockers; |
| 488 | |
| 489 | void migrate_add_blocker(Error *reason) |
| 490 | { |
| 491 | migration_blockers = g_slist_prepend(migration_blockers, reason); |
| 492 | } |
| 493 | |
| 494 | void migrate_del_blocker(Error *reason) |
| 495 | { |
| 496 | migration_blockers = g_slist_remove(migration_blockers, reason); |
| 497 | } |
| 498 | |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 499 | void qmp_migrate(const char *uri, bool has_blk, bool blk, |
| 500 | bool has_inc, bool inc, bool has_detach, bool detach, |
| 501 | Error **errp) |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 502 | { |
Paolo Bonzini | be7059c | 2012-10-03 14:34:33 +0200 | [diff] [blame] | 503 | Error *local_err = NULL; |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 504 | MigrationState *s = migrate_get_current(); |
Isaku Yamahata | 6607ae2 | 2012-06-19 18:43:09 +0300 | [diff] [blame] | 505 | MigrationParams params; |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 506 | const char *p; |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 507 | |
Isaku Yamahata | 6607ae2 | 2012-06-19 18:43:09 +0300 | [diff] [blame] | 508 | params.blk = blk; |
| 509 | params.shared = inc; |
| 510 | |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 511 | if (s->state == MIG_STATE_ACTIVE) { |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 512 | error_set(errp, QERR_MIGRATION_ACTIVE); |
| 513 | return; |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 514 | } |
| 515 | |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 516 | if (qemu_savevm_state_blocked(errp)) { |
| 517 | return; |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 518 | } |
| 519 | |
Anthony Liguori | fa2756b | 2011-11-14 15:09:43 -0600 | [diff] [blame] | 520 | if (migration_blockers) { |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 521 | *errp = error_copy(migration_blockers->data); |
| 522 | return; |
Anthony Liguori | fa2756b | 2011-11-14 15:09:43 -0600 | [diff] [blame] | 523 | } |
| 524 | |
Isaku Yamahata | 6607ae2 | 2012-06-19 18:43:09 +0300 | [diff] [blame] | 525 | s = migrate_init(¶ms); |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 526 | |
| 527 | if (strstart(uri, "tcp:", &p)) { |
Paolo Bonzini | f37afb5 | 2012-10-02 10:02:46 +0200 | [diff] [blame] | 528 | tcp_start_outgoing_migration(s, p, &local_err); |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 529 | #if !defined(WIN32) |
| 530 | } else if (strstart(uri, "exec:", &p)) { |
Paolo Bonzini | f37afb5 | 2012-10-02 10:02:46 +0200 | [diff] [blame] | 531 | exec_start_outgoing_migration(s, p, &local_err); |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 532 | } else if (strstart(uri, "unix:", &p)) { |
Paolo Bonzini | f37afb5 | 2012-10-02 10:02:46 +0200 | [diff] [blame] | 533 | unix_start_outgoing_migration(s, p, &local_err); |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 534 | } else if (strstart(uri, "fd:", &p)) { |
Paolo Bonzini | f37afb5 | 2012-10-02 10:02:46 +0200 | [diff] [blame] | 535 | fd_start_outgoing_migration(s, p, &local_err); |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 536 | #endif |
| 537 | } else { |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 538 | error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol"); |
| 539 | return; |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 540 | } |
| 541 | |
Paolo Bonzini | f37afb5 | 2012-10-02 10:02:46 +0200 | [diff] [blame] | 542 | if (local_err) { |
Paolo Bonzini | 342ab8d | 2012-10-02 09:59:38 +0200 | [diff] [blame] | 543 | migrate_fd_error(s); |
Paolo Bonzini | f37afb5 | 2012-10-02 10:02:46 +0200 | [diff] [blame] | 544 | error_propagate(errp, local_err); |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 545 | return; |
Juan Quintela | 1299c63 | 2011-11-09 21:29:01 +0100 | [diff] [blame] | 546 | } |
| 547 | |
Juan Quintela | e0eb739 | 2011-10-05 14:27:52 +0200 | [diff] [blame] | 548 | notifier_list_notify(&migration_state_notifiers, s); |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 549 | } |
| 550 | |
Luiz Capitulino | 6cdedb0 | 2011-11-27 22:54:09 -0200 | [diff] [blame] | 551 | void qmp_migrate_cancel(Error **errp) |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 552 | { |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 553 | migrate_fd_cancel(migrate_get_current()); |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 554 | } |
| 555 | |
Orit Wasserman | 9e1ba4c | 2012-08-06 21:42:54 +0300 | [diff] [blame] | 556 | void qmp_migrate_set_cache_size(int64_t value, Error **errp) |
| 557 | { |
| 558 | MigrationState *s = migrate_get_current(); |
| 559 | |
| 560 | /* Check for truncation */ |
| 561 | if (value != (size_t)value) { |
| 562 | error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", |
| 563 | "exceeding address space"); |
| 564 | return; |
| 565 | } |
| 566 | |
| 567 | s->xbzrle_cache_size = xbzrle_cache_resize(value); |
| 568 | } |
| 569 | |
| 570 | int64_t qmp_query_migrate_cache_size(Error **errp) |
| 571 | { |
| 572 | return migrate_xbzrle_cache_size(); |
| 573 | } |
| 574 | |
Luiz Capitulino | 3dc8538 | 2011-11-28 11:59:37 -0200 | [diff] [blame] | 575 | void qmp_migrate_set_speed(int64_t value, Error **errp) |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 576 | { |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 577 | MigrationState *s; |
| 578 | |
Luiz Capitulino | 3dc8538 | 2011-11-28 11:59:37 -0200 | [diff] [blame] | 579 | if (value < 0) { |
| 580 | value = 0; |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 581 | } |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 582 | |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 583 | s = migrate_get_current(); |
Luiz Capitulino | 3dc8538 | 2011-11-28 11:59:37 -0200 | [diff] [blame] | 584 | s->bandwidth_limit = value; |
Juan Quintela | d0ae46c | 2011-02-23 00:33:19 +0100 | [diff] [blame] | 585 | qemu_file_set_rate_limit(s->file, s->bandwidth_limit); |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 586 | } |
| 587 | |
Luiz Capitulino | 4f0a993 | 2011-11-27 23:18:01 -0200 | [diff] [blame] | 588 | void qmp_migrate_set_downtime(double value, Error **errp) |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 589 | { |
Luiz Capitulino | 4f0a993 | 2011-11-27 23:18:01 -0200 | [diff] [blame] | 590 | value *= 1e9; |
| 591 | value = MAX(0, MIN(UINT64_MAX, value)); |
| 592 | max_downtime = (uint64_t)value; |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 593 | } |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 594 | |
| 595 | int migrate_use_xbzrle(void) |
| 596 | { |
| 597 | MigrationState *s; |
| 598 | |
| 599 | s = migrate_get_current(); |
| 600 | |
| 601 | return s->enabled_capabilities[MIGRATION_CAPABILITY_XBZRLE]; |
| 602 | } |
| 603 | |
| 604 | int64_t migrate_xbzrle_cache_size(void) |
| 605 | { |
| 606 | MigrationState *s; |
| 607 | |
| 608 | s = migrate_get_current(); |
| 609 | |
| 610 | return s->xbzrle_cache_size; |
| 611 | } |