]> git.proxmox.com Git - mirror_qemu.git/blame - migration/colo-failover.c
hw/fsi: Added FSI documentation
[mirror_qemu.git] / migration / colo-failover.c
CommitLineData
d89e666e
HZ
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#include "qemu/osdep.h"
14#include "migration/colo.h"
15#include "migration/failover.h"
1adc1cee
JQ
16#include "qemu/main-loop.h"
17#include "migration.h"
e688df6b 18#include "qapi/error.h"
9af23989 19#include "qapi/qapi-commands-migration.h"
aef06085
HZ
20#include "qemu/error-report.h"
21#include "trace.h"
d89e666e
HZ
22
23static QEMUBH *failover_bh;
aef06085 24static FailoverStatus failover_state;
d89e666e
HZ
25
26static void colo_failover_bh(void *opaque)
27{
aef06085
HZ
28 int old_state;
29
d89e666e
HZ
30 qemu_bh_delete(failover_bh);
31 failover_bh = NULL;
aef06085
HZ
32
33 old_state = failover_set_state(FAILOVER_STATUS_REQUIRE,
34 FAILOVER_STATUS_ACTIVE);
35 if (old_state != FAILOVER_STATUS_REQUIRE) {
36 error_report("Unknown error for failover, old_state = %s",
977c736f 37 FailoverStatus_str(old_state));
aef06085
HZ
38 return;
39 }
40
c0913d1d 41 colo_do_failover();
d89e666e
HZ
42}
43
44void failover_request_active(Error **errp)
45{
aef06085
HZ
46 if (failover_set_state(FAILOVER_STATUS_NONE,
47 FAILOVER_STATUS_REQUIRE) != FAILOVER_STATUS_NONE) {
3a4452d8 48 error_setg(errp, "COLO failover is already activated");
aef06085
HZ
49 return;
50 }
d89e666e
HZ
51 failover_bh = qemu_bh_new(colo_failover_bh, NULL);
52 qemu_bh_schedule(failover_bh);
53}
54
aef06085
HZ
55void failover_init_state(void)
56{
57 failover_state = FAILOVER_STATUS_NONE;
58}
59
60FailoverStatus failover_set_state(FailoverStatus old_state,
61 FailoverStatus new_state)
62{
63 FailoverStatus old;
64
d73415a3 65 old = qatomic_cmpxchg(&failover_state, old_state, new_state);
aef06085 66 if (old == old_state) {
977c736f 67 trace_colo_failover_set_state(FailoverStatus_str(new_state));
aef06085
HZ
68 }
69 return old;
70}
71
72FailoverStatus failover_get_state(void)
73{
d73415a3 74 return qatomic_read(&failover_state);
aef06085
HZ
75}
76
d89e666e
HZ
77void qmp_x_colo_lost_heartbeat(Error **errp)
78{
41b6b779 79 if (get_colo_mode() == COLO_MODE_NONE) {
43aef7e6 80 error_setg(errp, "VM is not in COLO mode");
d89e666e
HZ
81 return;
82 }
83
84 failover_request_active(errp);
85}