zhanghailiang | 5821ebf | 2016-10-27 14:42:53 +0800 | [diff] [blame] | 1 | /* |
| 2 | * COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO) |
| 3 | * (a.k.a. Fault Tolerance or Continuous Replication) |
| 4 | * |
| 5 | * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD. |
| 6 | * Copyright (c) 2016 FUJITSU LIMITED |
| 7 | * Copyright (c) 2016 Intel Corporation |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU GPL, version 2 or |
| 10 | * later. See the COPYING file in the top-level directory. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include "qemu/osdep.h" |
Juan Quintela | 6666c96 | 2017-04-24 20:07:27 +0200 | [diff] [blame] | 15 | #include "migration.h" |
Juan Quintela | c59be01 | 2017-04-06 12:03:13 +0200 | [diff] [blame] | 16 | #include "migration/colo.h" |
Juan Quintela | 987772d | 2017-04-17 19:02:59 +0200 | [diff] [blame] | 17 | #include "migration/vmstate.h" |
zhanghailiang | 5821ebf | 2016-10-27 14:42:53 +0800 | [diff] [blame] | 18 | #include "trace.h" |
| 19 | |
| 20 | typedef struct { |
| 21 | bool colo_requested; |
| 22 | } COLOInfo; |
| 23 | |
| 24 | static COLOInfo colo_info; |
| 25 | |
zhanghailiang | d89e666 | 2016-10-27 14:43:03 +0800 | [diff] [blame] | 26 | COLOMode get_colo_mode(void) |
| 27 | { |
| 28 | if (migration_in_colo_state()) { |
| 29 | return COLO_MODE_PRIMARY; |
| 30 | } else if (migration_incoming_in_colo_state()) { |
| 31 | return COLO_MODE_SECONDARY; |
| 32 | } else { |
| 33 | return COLO_MODE_UNKNOWN; |
| 34 | } |
| 35 | } |
| 36 | |
Dr. David Alan Gilbert | 44b1ff3 | 2017-09-25 12:29:12 +0100 | [diff] [blame] | 37 | static int colo_info_pre_save(void *opaque) |
zhanghailiang | 5821ebf | 2016-10-27 14:42:53 +0800 | [diff] [blame] | 38 | { |
| 39 | COLOInfo *s = opaque; |
| 40 | |
| 41 | s->colo_requested = migrate_colo_enabled(); |
Dr. David Alan Gilbert | 44b1ff3 | 2017-09-25 12:29:12 +0100 | [diff] [blame] | 42 | |
| 43 | return 0; |
zhanghailiang | 5821ebf | 2016-10-27 14:42:53 +0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | static bool colo_info_need(void *opaque) |
| 47 | { |
| 48 | return migrate_colo_enabled(); |
| 49 | } |
| 50 | |
| 51 | static const VMStateDescription colo_state = { |
| 52 | .name = "COLOState", |
| 53 | .version_id = 1, |
| 54 | .minimum_version_id = 1, |
| 55 | .pre_save = colo_info_pre_save, |
| 56 | .needed = colo_info_need, |
| 57 | .fields = (VMStateField[]) { |
| 58 | VMSTATE_BOOL(colo_requested, COLOInfo), |
| 59 | VMSTATE_END_OF_LIST() |
| 60 | }, |
| 61 | }; |
| 62 | |
| 63 | void colo_info_init(void) |
| 64 | { |
| 65 | vmstate_register(NULL, 0, &colo_state, &colo_info); |
| 66 | } |
zhanghailiang | 25d0c16 | 2016-10-27 14:42:55 +0800 | [diff] [blame] | 67 | |
| 68 | bool migration_incoming_enable_colo(void) |
| 69 | { |
| 70 | return colo_info.colo_requested; |
| 71 | } |
| 72 | |
| 73 | void migration_incoming_exit_colo(void) |
| 74 | { |
| 75 | colo_info.colo_requested = false; |
| 76 | } |