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