[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH COLO-Frame v17 17/34] COLO failover: Introduce state
From: |
zhanghailiang |
Subject: |
[Qemu-devel] [PATCH COLO-Frame v17 17/34] COLO failover: Introduce state to record failover process |
Date: |
Fri, 3 Jun 2016 15:52:29 +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>
Reviewed-by: Dr. David Alan Gilbert <address@hidden>
---
v11:
- fix several typos found by Dave
- Add Reviewed-by tag
---
include/migration/failover.h | 10 ++++++++++
migration/colo-failover.c | 37 +++++++++++++++++++++++++++++++++++++
migration/colo.c | 4 ++++
trace-events | 1 +
4 files changed, 52 insertions(+)
diff --git a/include/migration/failover.h b/include/migration/failover.h
index 3274735..fe71bb4 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 413675d..69aac55 100644
--- a/migration/colo-failover.c
+++ b/migration/colo-failover.c
@@ -15,22 +15,59 @@
#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)
{
+ int old_state;
+
qemu_bh_delete(failover_bh);
failover_bh = NULL;
+ old_state = failover_set_state(FAILOVER_STATUS_REQUEST,
+ FAILOVER_STATUS_HANDLING);
+ if (old_state != FAILOVER_STATUS_REQUEST) {
+ error_report("Unkown error for failover, old_state=%d", old_state);
+ return;
+ }
/*TODO: Do failover work */
}
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_x_colo_lost_heartbeat(Error **errp)
{
if (get_colo_mode() == COLO_MODE_UNKNOWN) {
diff --git a/migration/colo.c b/migration/colo.c
index c087be8..f98d7fb 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -232,6 +232,8 @@ static void colo_process_checkpoint(MigrationState *s)
Error *local_err = NULL;
int ret;
+ failover_init_state();
+
s->rp_state.from_dst_file = qemu_file_get_return_path(s->to_dst_file);
if (!s->rp_state.from_dst_file) {
error_report("Open QEMUFile from_dst_file failed");
@@ -331,6 +333,8 @@ void *colo_process_incoming_thread(void *opaque)
migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,
MIGRATION_STATUS_COLO);
+ failover_init_state();
+
mis->to_src_file = qemu_file_get_return_path(mis->from_src_file);
if (!mis->to_src_file) {
error_report("colo incoming thread: Open QEMUFile to_src_file failed");
diff --git a/trace-events b/trace-events
index b58adc3..380276c 100644
--- a/trace-events
+++ b/trace-events
@@ -1626,6 +1626,7 @@ migration_tls_incoming_handshake_complete(void) ""
colo_vm_state_change(const char *old, const char *new) "Change '%s' => '%s'"
colo_send_message(const char *msg) "Send '%s' message"
colo_receive_message(const char *msg) "Receive '%s' message"
+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 v17 11/34] ram/COLO: Record the dirty pages that SVM received, (continued)
- [Qemu-devel] [PATCH COLO-Frame v17 11/34] ram/COLO: Record the dirty pages that SVM received, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 18/34] COLO: Implement failover work for Primary VM, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 22/34] COLO failover: Don't do failover during loading VM's state, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 29/34] COLO: Split qemu_savevm_state_begin out of checkpoint process, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 28/34] COLO: Separate the process of saving/loading ram and device state, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 25/34] savevm: Introduce two helper functions for save/find loadvm_handlers entry, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 19/34] COLO: Implement failover work for Secondary VM, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 24/34] COLO: Update the global runstate after going into colo state, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 05/34] migration: Integrate COLO checkpoint process into loadvm, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 16/34] COLO failover: Introduce a new command to trigger a failover, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 17/34] COLO failover: Introduce state to record failover process,
zhanghailiang <=
- [Qemu-devel] [PATCH COLO-Frame v17 31/34] net: Add notifier/callback for netdev init, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 34/34] COLO: Add block replication into colo process, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 30/34] filter-buffer: Accept zero interval, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 23/34] COLO: Process shutdown command for VM in COLO state, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 20/34] qmp event: Add COLO_EXIT event to notify users while exited from COLO, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 33/34] COLO: Control the status of buffer filters for PVM, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 32/34] COLO/filter: Add each netdev a buffer filter, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 26/34] migration/savevm: Add new helpers to process the different stages of loadvm, zhanghailiang, 2016/06/03
- Re: [Qemu-devel] [PATCH COLO-Frame v17 00/34] COarse-grain LOck-stepping(COLO) Virtual Machines for Non-stop Service (FT), Dr. David Alan Gilbert, 2016/06/07