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 | c87b015 | 2012-07-20 13:10:54 +0200 | [diff] [blame] | 300 | ssize_t migrate_fd_put_buffer(MigrationState *s, const void *data, |
| 301 | size_t size) |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 302 | { |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 303 | ssize_t ret; |
| 304 | |
Juan Quintela | fdbecb5 | 2011-09-21 22:37:29 +0200 | [diff] [blame] | 305 | if (s->state != MIG_STATE_ACTIVE) { |
| 306 | return -EIO; |
| 307 | } |
| 308 | |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 309 | do { |
| 310 | ret = s->write(s, data, size); |
Uri Lublin | 95b134e | 2009-05-19 14:08:53 +0300 | [diff] [blame] | 311 | } while (ret == -1 && ((s->get_error(s)) == EINTR)); |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 312 | |
| 313 | if (ret == -1) |
| 314 | ret = -(s->get_error(s)); |
| 315 | |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 316 | return ret; |
| 317 | } |
| 318 | |
Juan Quintela | e4ed154 | 2012-09-21 11:18:18 +0200 | [diff] [blame^] | 319 | bool migrate_fd_put_ready(MigrationState *s, uint64_t max_size) |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 320 | { |
| 321 | int ret; |
Juan Quintela | e4ed154 | 2012-09-21 11:18:18 +0200 | [diff] [blame^] | 322 | uint64_t pending_size; |
| 323 | bool last_round = false; |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 324 | |
Juan Quintela | e762748 | 2012-07-23 06:31:30 +0200 | [diff] [blame] | 325 | qemu_mutex_lock_iothread(); |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 326 | if (s->state != MIG_STATE_ACTIVE) { |
malc | d0f2c4c | 2010-02-07 02:03:50 +0300 | [diff] [blame] | 327 | DPRINTF("put_ready returning because of non-active state\n"); |
Juan Quintela | e762748 | 2012-07-23 06:31:30 +0200 | [diff] [blame] | 328 | qemu_mutex_unlock_iothread(); |
Juan Quintela | e4ed154 | 2012-09-21 11:18:18 +0200 | [diff] [blame^] | 329 | return false; |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 330 | } |
Juan Quintela | 766bd17 | 2012-07-23 05:45:29 +0200 | [diff] [blame] | 331 | if (s->first_time) { |
| 332 | s->first_time = false; |
| 333 | DPRINTF("beginning savevm\n"); |
| 334 | ret = qemu_savevm_state_begin(s->file, &s->params); |
| 335 | if (ret < 0) { |
| 336 | DPRINTF("failed, %d\n", ret); |
| 337 | migrate_fd_error(s); |
Juan Quintela | e762748 | 2012-07-23 06:31:30 +0200 | [diff] [blame] | 338 | qemu_mutex_unlock_iothread(); |
Juan Quintela | e4ed154 | 2012-09-21 11:18:18 +0200 | [diff] [blame^] | 339 | return false; |
Juan Quintela | 766bd17 | 2012-07-23 05:45:29 +0200 | [diff] [blame] | 340 | } |
| 341 | } |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 342 | |
malc | d0f2c4c | 2010-02-07 02:03:50 +0300 | [diff] [blame] | 343 | DPRINTF("iterate\n"); |
Juan Quintela | e4ed154 | 2012-09-21 11:18:18 +0200 | [diff] [blame^] | 344 | pending_size = qemu_savevm_state_pending(s->file, max_size); |
| 345 | DPRINTF("pending size %lu max %lu\n", pending_size, max_size); |
| 346 | if (pending_size >= max_size) { |
| 347 | ret = qemu_savevm_state_iterate(s->file); |
| 348 | if (ret < 0) { |
| 349 | migrate_fd_error(s); |
| 350 | } |
| 351 | } else { |
Luiz Capitulino | 1354869 | 2011-07-29 15:36:43 -0300 | [diff] [blame] | 352 | int old_vm_running = runstate_is_running(); |
Juan Quintela | 9c5a9fc | 2012-08-13 09:35:16 +0200 | [diff] [blame] | 353 | int64_t start_time, end_time; |
Anthony Liguori | eeb34af | 2009-07-09 13:25:47 -0500 | [diff] [blame] | 354 | |
malc | d0f2c4c | 2010-02-07 02:03:50 +0300 | [diff] [blame] | 355 | DPRINTF("done iterating\n"); |
Juan Quintela | 9c5a9fc | 2012-08-13 09:35:16 +0200 | [diff] [blame] | 356 | start_time = qemu_get_clock_ms(rt_clock); |
Gerd Hoffmann | 7b5d3aa | 2012-03-07 08:00:26 +0100 | [diff] [blame] | 357 | qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); |
Juan Quintela | 766bd17 | 2012-07-23 05:45:29 +0200 | [diff] [blame] | 358 | if (old_vm_running) { |
| 359 | vm_stop(RUN_STATE_FINISH_MIGRATE); |
| 360 | } else { |
| 361 | vm_stop_force_state(RUN_STATE_FINISH_MIGRATE); |
| 362 | } |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 363 | |
Luiz Capitulino | 539de12 | 2011-12-05 14:06:56 -0200 | [diff] [blame] | 364 | if (qemu_savevm_state_complete(s->file) < 0) { |
Juan Quintela | 67afff7 | 2011-02-22 23:18:20 +0100 | [diff] [blame] | 365 | migrate_fd_error(s); |
aliguori | b161d12 | 2009-04-05 19:30:33 +0000 | [diff] [blame] | 366 | } else { |
Juan Quintela | 458cf28 | 2011-02-22 23:32:54 +0100 | [diff] [blame] | 367 | migrate_fd_completed(s); |
aliguori | b161d12 | 2009-04-05 19:30:33 +0000 | [diff] [blame] | 368 | } |
Juan Quintela | 97d4d96 | 2012-08-10 21:53:08 +0200 | [diff] [blame] | 369 | end_time = qemu_get_clock_ms(rt_clock); |
| 370 | s->total_time = end_time - s->total_time; |
Juan Quintela | 9c5a9fc | 2012-08-13 09:35:16 +0200 | [diff] [blame] | 371 | s->downtime = end_time - start_time; |
Juan Quintela | 48a2f4d | 2010-05-11 23:28:53 +0200 | [diff] [blame] | 372 | if (s->state != MIG_STATE_COMPLETED) { |
Anthony Liguori | 41ef56e | 2010-06-02 14:55:25 -0500 | [diff] [blame] | 373 | if (old_vm_running) { |
| 374 | vm_start(); |
| 375 | } |
Anthony Liguori | 41ef56e | 2010-06-02 14:55:25 -0500 | [diff] [blame] | 376 | } |
Juan Quintela | e4ed154 | 2012-09-21 11:18:18 +0200 | [diff] [blame^] | 377 | last_round = true; |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 378 | } |
Juan Quintela | e762748 | 2012-07-23 06:31:30 +0200 | [diff] [blame] | 379 | qemu_mutex_unlock_iothread(); |
| 380 | |
Juan Quintela | e4ed154 | 2012-09-21 11:18:18 +0200 | [diff] [blame^] | 381 | return last_round; |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 382 | } |
| 383 | |
Juan Quintela | 0edda1c | 2010-05-11 16:28:39 +0200 | [diff] [blame] | 384 | static void migrate_fd_cancel(MigrationState *s) |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 385 | { |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 386 | if (s->state != MIG_STATE_ACTIVE) |
| 387 | return; |
| 388 | |
malc | d0f2c4c | 2010-02-07 02:03:50 +0300 | [diff] [blame] | 389 | DPRINTF("cancelling migration\n"); |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 390 | |
| 391 | s->state = MIG_STATE_CANCELLED; |
Juan Quintela | e0eb739 | 2011-10-05 14:27:52 +0200 | [diff] [blame] | 392 | notifier_list_notify(&migration_state_notifiers, s); |
Luiz Capitulino | 539de12 | 2011-12-05 14:06:56 -0200 | [diff] [blame] | 393 | qemu_savevm_state_cancel(s->file); |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 394 | |
| 395 | migrate_fd_cleanup(s); |
| 396 | } |
| 397 | |
Juan Quintela | 11c7674 | 2012-07-20 13:19:36 +0200 | [diff] [blame] | 398 | int migrate_fd_close(MigrationState *s) |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 399 | { |
Paolo Bonzini | 8dc592e | 2012-09-27 13:25:45 +0200 | [diff] [blame] | 400 | int rc = 0; |
| 401 | if (s->fd != -1) { |
Paolo Bonzini | 8dc592e | 2012-09-27 13:25:45 +0200 | [diff] [blame] | 402 | rc = s->close(s); |
| 403 | s->fd = -1; |
| 404 | } |
| 405 | return rc; |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 406 | } |
Gerd Hoffmann | 99a0db9 | 2010-12-13 17:30:12 +0100 | [diff] [blame] | 407 | |
| 408 | void add_migration_state_change_notifier(Notifier *notify) |
| 409 | { |
| 410 | notifier_list_add(&migration_state_notifiers, notify); |
| 411 | } |
| 412 | |
| 413 | void remove_migration_state_change_notifier(Notifier *notify) |
| 414 | { |
Paolo Bonzini | 3155252 | 2012-01-13 17:34:01 +0100 | [diff] [blame] | 415 | notifier_remove(notify); |
Gerd Hoffmann | 99a0db9 | 2010-12-13 17:30:12 +0100 | [diff] [blame] | 416 | } |
| 417 | |
Gerd Hoffmann | afe2df6 | 2011-10-25 13:50:11 +0200 | [diff] [blame] | 418 | bool migration_is_active(MigrationState *s) |
| 419 | { |
| 420 | return s->state == MIG_STATE_ACTIVE; |
| 421 | } |
| 422 | |
Juan Quintela | 7073693 | 2011-02-23 00:43:59 +0100 | [diff] [blame] | 423 | bool migration_has_finished(MigrationState *s) |
Gerd Hoffmann | 99a0db9 | 2010-12-13 17:30:12 +0100 | [diff] [blame] | 424 | { |
Juan Quintela | 7073693 | 2011-02-23 00:43:59 +0100 | [diff] [blame] | 425 | return s->state == MIG_STATE_COMPLETED; |
Gerd Hoffmann | 99a0db9 | 2010-12-13 17:30:12 +0100 | [diff] [blame] | 426 | } |
Juan Quintela | 0edda1c | 2010-05-11 16:28:39 +0200 | [diff] [blame] | 427 | |
Gerd Hoffmann | afe2df6 | 2011-10-25 13:50:11 +0200 | [diff] [blame] | 428 | bool migration_has_failed(MigrationState *s) |
| 429 | { |
| 430 | return (s->state == MIG_STATE_CANCELLED || |
| 431 | s->state == MIG_STATE_ERROR); |
| 432 | } |
| 433 | |
Juan Quintela | 8b6b99b | 2011-09-11 20:28:22 +0200 | [diff] [blame] | 434 | void migrate_fd_connect(MigrationState *s) |
| 435 | { |
Juan Quintela | d5934dd | 2010-05-11 23:01:53 +0200 | [diff] [blame] | 436 | s->state = MIG_STATE_ACTIVE; |
Juan Quintela | 766bd17 | 2012-07-23 05:45:29 +0200 | [diff] [blame] | 437 | s->first_time = true; |
Juan Quintela | edfa1af | 2012-07-23 02:13:23 +0200 | [diff] [blame] | 438 | qemu_fopen_ops_buffered(s); |
Juan Quintela | 8b6b99b | 2011-09-11 20:28:22 +0200 | [diff] [blame] | 439 | } |
| 440 | |
Isaku Yamahata | 6607ae2 | 2012-06-19 18:43:09 +0300 | [diff] [blame] | 441 | static MigrationState *migrate_init(const MigrationParams *params) |
Juan Quintela | 0edda1c | 2010-05-11 16:28:39 +0200 | [diff] [blame] | 442 | { |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 443 | MigrationState *s = migrate_get_current(); |
Juan Quintela | d0ae46c | 2011-02-23 00:33:19 +0100 | [diff] [blame] | 444 | int64_t bandwidth_limit = s->bandwidth_limit; |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 445 | bool enabled_capabilities[MIGRATION_CAPABILITY_MAX]; |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 446 | int64_t xbzrle_cache_size = s->xbzrle_cache_size; |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 447 | |
| 448 | memcpy(enabled_capabilities, s->enabled_capabilities, |
| 449 | sizeof(enabled_capabilities)); |
Juan Quintela | 0edda1c | 2010-05-11 16:28:39 +0200 | [diff] [blame] | 450 | |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 451 | memset(s, 0, sizeof(*s)); |
Juan Quintela | d0ae46c | 2011-02-23 00:33:19 +0100 | [diff] [blame] | 452 | s->bandwidth_limit = bandwidth_limit; |
Isaku Yamahata | 6607ae2 | 2012-06-19 18:43:09 +0300 | [diff] [blame] | 453 | s->params = *params; |
Orit Wasserman | bbf6da3 | 2012-08-06 21:42:47 +0300 | [diff] [blame] | 454 | memcpy(s->enabled_capabilities, enabled_capabilities, |
| 455 | sizeof(enabled_capabilities)); |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 456 | s->xbzrle_cache_size = xbzrle_cache_size; |
Juan Quintela | 1299c63 | 2011-11-09 21:29:01 +0100 | [diff] [blame] | 457 | |
Juan Quintela | 0edda1c | 2010-05-11 16:28:39 +0200 | [diff] [blame] | 458 | s->bandwidth_limit = bandwidth_limit; |
Juan Quintela | d5934dd | 2010-05-11 23:01:53 +0200 | [diff] [blame] | 459 | s->state = MIG_STATE_SETUP; |
Juan Quintela | d5f8a57 | 2012-05-21 22:01:07 +0200 | [diff] [blame] | 460 | s->total_time = qemu_get_clock_ms(rt_clock); |
Juan Quintela | 0edda1c | 2010-05-11 16:28:39 +0200 | [diff] [blame] | 461 | |
Juan Quintela | 0edda1c | 2010-05-11 16:28:39 +0200 | [diff] [blame] | 462 | return s; |
| 463 | } |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 464 | |
Anthony Liguori | fa2756b | 2011-11-14 15:09:43 -0600 | [diff] [blame] | 465 | static GSList *migration_blockers; |
| 466 | |
| 467 | void migrate_add_blocker(Error *reason) |
| 468 | { |
| 469 | migration_blockers = g_slist_prepend(migration_blockers, reason); |
| 470 | } |
| 471 | |
| 472 | void migrate_del_blocker(Error *reason) |
| 473 | { |
| 474 | migration_blockers = g_slist_remove(migration_blockers, reason); |
| 475 | } |
| 476 | |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 477 | void qmp_migrate(const char *uri, bool has_blk, bool blk, |
| 478 | bool has_inc, bool inc, bool has_detach, bool detach, |
| 479 | Error **errp) |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 480 | { |
Paolo Bonzini | be7059c | 2012-10-03 14:34:33 +0200 | [diff] [blame] | 481 | Error *local_err = NULL; |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 482 | MigrationState *s = migrate_get_current(); |
Isaku Yamahata | 6607ae2 | 2012-06-19 18:43:09 +0300 | [diff] [blame] | 483 | MigrationParams params; |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 484 | const char *p; |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 485 | |
Isaku Yamahata | 6607ae2 | 2012-06-19 18:43:09 +0300 | [diff] [blame] | 486 | params.blk = blk; |
| 487 | params.shared = inc; |
| 488 | |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 489 | if (s->state == MIG_STATE_ACTIVE) { |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 490 | error_set(errp, QERR_MIGRATION_ACTIVE); |
| 491 | return; |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 492 | } |
| 493 | |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 494 | if (qemu_savevm_state_blocked(errp)) { |
| 495 | return; |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 496 | } |
| 497 | |
Anthony Liguori | fa2756b | 2011-11-14 15:09:43 -0600 | [diff] [blame] | 498 | if (migration_blockers) { |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 499 | *errp = error_copy(migration_blockers->data); |
| 500 | return; |
Anthony Liguori | fa2756b | 2011-11-14 15:09:43 -0600 | [diff] [blame] | 501 | } |
| 502 | |
Isaku Yamahata | 6607ae2 | 2012-06-19 18:43:09 +0300 | [diff] [blame] | 503 | s = migrate_init(¶ms); |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 504 | |
| 505 | if (strstart(uri, "tcp:", &p)) { |
Paolo Bonzini | f37afb5 | 2012-10-02 10:02:46 +0200 | [diff] [blame] | 506 | tcp_start_outgoing_migration(s, p, &local_err); |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 507 | #if !defined(WIN32) |
| 508 | } else if (strstart(uri, "exec:", &p)) { |
Paolo Bonzini | f37afb5 | 2012-10-02 10:02:46 +0200 | [diff] [blame] | 509 | exec_start_outgoing_migration(s, p, &local_err); |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 510 | } else if (strstart(uri, "unix:", &p)) { |
Paolo Bonzini | f37afb5 | 2012-10-02 10:02:46 +0200 | [diff] [blame] | 511 | unix_start_outgoing_migration(s, p, &local_err); |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 512 | } else if (strstart(uri, "fd:", &p)) { |
Paolo Bonzini | f37afb5 | 2012-10-02 10:02:46 +0200 | [diff] [blame] | 513 | fd_start_outgoing_migration(s, p, &local_err); |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 514 | #endif |
| 515 | } else { |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 516 | error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol"); |
| 517 | return; |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 518 | } |
| 519 | |
Paolo Bonzini | f37afb5 | 2012-10-02 10:02:46 +0200 | [diff] [blame] | 520 | if (local_err) { |
Paolo Bonzini | 342ab8d | 2012-10-02 09:59:38 +0200 | [diff] [blame] | 521 | migrate_fd_error(s); |
Paolo Bonzini | f37afb5 | 2012-10-02 10:02:46 +0200 | [diff] [blame] | 522 | error_propagate(errp, local_err); |
Luiz Capitulino | e1c37d0 | 2011-12-05 14:48:01 -0200 | [diff] [blame] | 523 | return; |
Juan Quintela | 1299c63 | 2011-11-09 21:29:01 +0100 | [diff] [blame] | 524 | } |
| 525 | |
Juan Quintela | e0eb739 | 2011-10-05 14:27:52 +0200 | [diff] [blame] | 526 | notifier_list_notify(&migration_state_notifiers, s); |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 527 | } |
| 528 | |
Luiz Capitulino | 6cdedb0 | 2011-11-27 22:54:09 -0200 | [diff] [blame] | 529 | void qmp_migrate_cancel(Error **errp) |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 530 | { |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 531 | migrate_fd_cancel(migrate_get_current()); |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 532 | } |
| 533 | |
Orit Wasserman | 9e1ba4c | 2012-08-06 21:42:54 +0300 | [diff] [blame] | 534 | void qmp_migrate_set_cache_size(int64_t value, Error **errp) |
| 535 | { |
| 536 | MigrationState *s = migrate_get_current(); |
| 537 | |
| 538 | /* Check for truncation */ |
| 539 | if (value != (size_t)value) { |
| 540 | error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", |
| 541 | "exceeding address space"); |
| 542 | return; |
| 543 | } |
| 544 | |
| 545 | s->xbzrle_cache_size = xbzrle_cache_resize(value); |
| 546 | } |
| 547 | |
| 548 | int64_t qmp_query_migrate_cache_size(Error **errp) |
| 549 | { |
| 550 | return migrate_xbzrle_cache_size(); |
| 551 | } |
| 552 | |
Luiz Capitulino | 3dc8538 | 2011-11-28 11:59:37 -0200 | [diff] [blame] | 553 | void qmp_migrate_set_speed(int64_t value, Error **errp) |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 554 | { |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 555 | MigrationState *s; |
| 556 | |
Luiz Capitulino | 3dc8538 | 2011-11-28 11:59:37 -0200 | [diff] [blame] | 557 | if (value < 0) { |
| 558 | value = 0; |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 559 | } |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 560 | |
Juan Quintela | 17549e8 | 2011-10-05 13:50:43 +0200 | [diff] [blame] | 561 | s = migrate_get_current(); |
Luiz Capitulino | 3dc8538 | 2011-11-28 11:59:37 -0200 | [diff] [blame] | 562 | s->bandwidth_limit = value; |
Juan Quintela | d0ae46c | 2011-02-23 00:33:19 +0100 | [diff] [blame] | 563 | qemu_file_set_rate_limit(s->file, s->bandwidth_limit); |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 564 | } |
| 565 | |
Luiz Capitulino | 4f0a993 | 2011-11-27 23:18:01 -0200 | [diff] [blame] | 566 | void qmp_migrate_set_downtime(double value, Error **errp) |
Juan Quintela | cab3014 | 2011-02-22 23:54:21 +0100 | [diff] [blame] | 567 | { |
Luiz Capitulino | 4f0a993 | 2011-11-27 23:18:01 -0200 | [diff] [blame] | 568 | value *= 1e9; |
| 569 | value = MAX(0, MIN(UINT64_MAX, value)); |
| 570 | max_downtime = (uint64_t)value; |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 571 | } |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 572 | |
| 573 | int migrate_use_xbzrle(void) |
| 574 | { |
| 575 | MigrationState *s; |
| 576 | |
| 577 | s = migrate_get_current(); |
| 578 | |
| 579 | return s->enabled_capabilities[MIGRATION_CAPABILITY_XBZRLE]; |
| 580 | } |
| 581 | |
| 582 | int64_t migrate_xbzrle_cache_size(void) |
| 583 | { |
| 584 | MigrationState *s; |
| 585 | |
| 586 | s = migrate_get_current(); |
| 587 | |
| 588 | return s->xbzrle_cache_size; |
| 589 | } |