[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH COLO-Frame v8 17/34] COLO failover: Introduce state
From: |
zhanghailiang |
Subject: |
[Qemu-devel] [PATCH COLO-Frame v8 17/34] COLO failover: Introduce state to record failover process |
Date: |
Wed, 29 Jul 2015 16:45:27 +0800 |
When handling failover, we do different things according to the different stage
of failover process, here we introduce a global atomic variable to record the
status of failover.
We add four failover status to indicate the different stage of failover process.
You should use the helpers to get and set the value.
Signed-off-by: zhanghailiang <address@hidden>
---
include/migration/failover.h | 10 ++++++++++
migration/colo-failover.c | 29 +++++++++++++++++++++++++++++
migration/colo.c | 3 +++
trace-events | 1 +
4 files changed, 43 insertions(+)
diff --git a/include/migration/failover.h b/include/migration/failover.h
index 1785b52..882c625 100644
--- a/include/migration/failover.h
+++ b/include/migration/failover.h
@@ -15,6 +15,16 @@
#include "qemu-common.h"
+typedef enum COLOFailoverStatus {
+ FAILOVER_STATUS_NONE = 0,
+ FAILOVER_STATUS_REQUEST = 1, /* Request but not handled */
+ FAILOVER_STATUS_HANDLING = 2, /* In the process of handling failover */
+ FAILOVER_STATUS_COMPLETED = 3, /* Finish the failover process */
+} COLOFailoverStatus;
+
+void failover_init_state(void);
+int failover_set_state(int old_state, int new_state);
+int failover_get_state(void);
void failover_request_active(Error **errp);
#endif
diff --git a/migration/colo-failover.c b/migration/colo-failover.c
index af068d3..94d047a 100644
--- a/migration/colo-failover.c
+++ b/migration/colo-failover.c
@@ -14,8 +14,11 @@
#include "migration/failover.h"
#include "qmp-commands.h"
#include "qapi/qmp/qerror.h"
+#include "qemu/error-report.h"
+#include "trace.h"
static QEMUBH *failover_bh;
+static COLOFailoverStatus failover_state;
static void colo_failover_bh(void *opaque)
{
@@ -26,10 +29,36 @@ static void colo_failover_bh(void *opaque)
void failover_request_active(Error **errp)
{
+ if (failover_set_state(FAILOVER_STATUS_NONE, FAILOVER_STATUS_REQUEST)
+ != FAILOVER_STATUS_NONE) {
+ error_setg(errp, "COLO failover is already actived");
+ return;
+ }
failover_bh = qemu_bh_new(colo_failover_bh, NULL);
qemu_bh_schedule(failover_bh);
}
+void failover_init_state(void)
+{
+ failover_state = FAILOVER_STATUS_NONE;
+}
+
+int failover_set_state(int old_state, int new_state)
+{
+ int old;
+
+ old = atomic_cmpxchg(&failover_state, old_state, new_state);;
+ if (old == old_state) {
+ trace_colo_failover_set_state(new_state);
+ }
+ return old;
+}
+
+int failover_get_state(void)
+{
+ return atomic_read(&failover_state);
+}
+
void qmp_colo_lost_heartbeat(Error **errp)
{
if (get_colo_mode() == COLO_MODE_UNKNOWN) {
diff --git a/migration/colo.c b/migration/colo.c
index 1a08fec..6f40a82 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -227,6 +227,8 @@ static void *colo_thread(void *opaque)
QEMUFile *colo_control = NULL;
int ret;
+ failover_init_state();
+
colo_control = qemu_fopen_socket(qemu_get_fd(s->file), "rb");
if (!colo_control) {
error_report("Open colo_control failed!");
@@ -339,6 +341,7 @@ void *colo_process_incoming_checkpoints(void *opaque)
migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,
MIGRATION_STATUS_COLO);
+ failover_init_state();
ctl = qemu_fopen_socket(fd, "wb");
if (!ctl) {
diff --git a/trace-events b/trace-events
index 86d4c49..3df120b 100644
--- a/trace-events
+++ b/trace-events
@@ -1476,6 +1476,7 @@
rdma_start_outgoing_migration_after_rdma_source_init(void) ""
colo_vm_state_change(const char *old, const char *new) "Change '%s' => '%s'"
colo_ctl_put(const char *msg) "Send '%s'"
colo_ctl_get(const char *msg) "Receive '%s'"
+colo_failover_set_state(int new_state) "new state %d"
# kvm-all.c
kvm_ioctl(int type, void *arg) "type 0x%x, arg %p"
--
1.8.3.1
- [Qemu-devel] [PATCH COLO-Frame v8 00/34] COarse-grain LOck-stepping(COLO) Virtual Machines for Non-stop Service (FT), zhanghailiang, 2015/07/29
- [Qemu-devel] [PATCH COLO-Frame v8 01/34] configure: Add parameter for configure to enable/disable COLO support, zhanghailiang, 2015/07/29
- [Qemu-devel] [PATCH COLO-Frame v8 08/34] COLO: Implement colo checkpoint protocol, zhanghailiang, 2015/07/29
- [Qemu-devel] [PATCH COLO-Frame v8 09/34] COLO: Add a new RunState RUN_STATE_COLO, zhanghailiang, 2015/07/29
- [Qemu-devel] [PATCH COLO-Frame v8 05/34] migration: Add state records for migration incoming, zhanghailiang, 2015/07/29
- [Qemu-devel] [PATCH COLO-Frame v8 10/34] QEMUSizedBuffer: Introduce two help functions for qsb, zhanghailiang, 2015/07/29
- [Qemu-devel] [PATCH COLO-Frame v8 07/34] migration: Integrate COLO checkpoint process into loadvm, zhanghailiang, 2015/07/29
- [Qemu-devel] [PATCH COLO-Frame v8 12/34] COLO RAM: Load PVM's dirty page into SVM's RAM cache temporarily, zhanghailiang, 2015/07/29
- [Qemu-devel] [PATCH COLO-Frame v8 06/34] migration: Integrate COLO checkpoint process into migration, zhanghailiang, 2015/07/29
- [Qemu-devel] [PATCH COLO-Frame v8 03/34] COLO: migrate colo related info to slave, zhanghailiang, 2015/07/29
- [Qemu-devel] [PATCH COLO-Frame v8 17/34] COLO failover: Introduce state to record failover process,
zhanghailiang <=
- [Qemu-devel] [PATCH COLO-Frame v8 11/34] COLO: Save VM state to slave when do checkpoint, zhanghailiang, 2015/07/29
- [Qemu-devel] [PATCH COLO-Frame v8 13/34] COLO VMstate: Load VM state into qsb before restore it, zhanghailiang, 2015/07/29
- [Qemu-devel] [PATCH COLO-Frame v8 22/34] COLO NIC: Init/remove colo nic devices when add/cleanup tap devices, zhanghailiang, 2015/07/29
- [Qemu-devel] [PATCH COLO-Frame v8 16/34] COLO failover: Introduce a new command to trigger a failover, zhanghailiang, 2015/07/29
- [Qemu-devel] [PATCH COLO-Frame v8 14/34] arch_init: Start to trace dirty pages of SVM, zhanghailiang, 2015/07/29
- [Qemu-devel] [PATCH COLO-Frame v8 20/34] COLO failover: Don't do failover during loading VM's state, zhanghailiang, 2015/07/29
- [Qemu-devel] [PATCH COLO-Frame v8 23/34] tap: Make launch_script() public, zhanghailiang, 2015/07/29