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