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