From: zhanghailiang <zhang.zhanghailiang@huawei.com>
To: quintela@redhat.com, amit.shah@redhat.com
Cc: qemu-devel@nongnu.org, dgilbert@redhat.com, wency@cn.fujitsu.com,
lizhijian@cn.fujitsu.com, xiecl.fnst@cn.fujitsu.com,
zhanghailiang <zhang.zhanghailiang@huawei.com>
Subject: [Qemu-devel] [PATCH COLO-Frame (Base) v23 13/18] COLO: Introduce state to record failover process
Date: Thu, 27 Oct 2016 14:43:04 +0800 [thread overview]
Message-ID: <1477550589-16288-14-git-send-email-zhang.zhanghailiang@huawei.com> (raw)
In-Reply-To: <1477550589-16288-1-git-send-email-zhang.zhanghailiang@huawei.com>
When handling failover, COLO processes differently 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 <zhang.zhanghailiang@huawei.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Amit Shah <amit.shah@redhat.com>
---
v22:
- Add Reviewed-by tag
v20:
- Convert 'enum COLOFailoverStatus' to qapi
v19:
- fix comments
v11:
- fix several typos found by Dave
- Add Reviewed-by tag
---
include/migration/failover.h | 5 +++++
migration/colo-failover.c | 41 +++++++++++++++++++++++++++++++++++++++++
migration/colo.c | 4 ++++
migration/trace-events | 1 +
qapi-schema.json | 18 ++++++++++++++++++
5 files changed, 69 insertions(+)
diff --git a/include/migration/failover.h b/include/migration/failover.h
index 3274735..7e0f36a 100644
--- a/include/migration/failover.h
+++ b/include/migration/failover.h
@@ -14,7 +14,12 @@
#define QEMU_FAILOVER_H
#include "qemu-common.h"
+#include "qapi-types.h"
+void failover_init_state(void);
+FailoverStatus failover_set_state(FailoverStatus old_state,
+ FailoverStatus new_state);
+FailoverStatus failover_get_state(void);
void failover_request_active(Error **errp);
#endif
diff --git a/migration/colo-failover.c b/migration/colo-failover.c
index e31fc10..6cca039 100644
--- a/migration/colo-failover.c
+++ b/migration/colo-failover.c
@@ -15,22 +15,63 @@
#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 FailoverStatus 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_REQUIRE,
+ FAILOVER_STATUS_ACTIVE);
+ if (old_state != FAILOVER_STATUS_REQUIRE) {
+ error_report("Unknown error for failover, old_state = %s",
+ FailoverStatus_lookup[old_state]);
+ return;
+ }
+
/* TODO: Do failover work */
}
void failover_request_active(Error **errp)
{
+ if (failover_set_state(FAILOVER_STATUS_NONE,
+ FAILOVER_STATUS_REQUIRE) != 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;
+}
+
+FailoverStatus failover_set_state(FailoverStatus old_state,
+ FailoverStatus new_state)
+{
+ FailoverStatus old;
+
+ old = atomic_cmpxchg(&failover_state, old_state, new_state);
+ if (old == old_state) {
+ trace_colo_failover_set_state(FailoverStatus_lookup[new_state]);
+ }
+ return old;
+}
+
+FailoverStatus 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 12fa0b4..6b32c91 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");
@@ -332,6 +334,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/migration/trace-events b/migration/trace-events
index f374c8c..94134f7 100644
--- a/migration/trace-events
+++ b/migration/trace-events
@@ -212,3 +212,4 @@ 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(const char *new_state) "new state %s"
diff --git a/qapi-schema.json b/qapi-schema.json
index a184841..8a7b527 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -840,6 +840,24 @@
'data': [ 'unknown', 'primary', 'secondary'] }
##
+# @FailoverStatus
+#
+# An enumeration of COLO failover status
+#
+# @none: no failover has ever happened
+#
+# @require: got failover requirement but not handled
+#
+# @active: in the process of doing failover
+#
+# @completed: finish the process of failover
+#
+# Since: 2.8
+##
+{ 'enum': 'FailoverStatus',
+ 'data': [ 'none', 'require', 'active', 'completed'] }
+
+##
# @x-colo-lost-heartbeat
#
# Tell qemu that heartbeat is lost, request it to do takeover procedures.
--
1.8.3.1
next prev parent reply other threads:[~2016-10-27 6:45 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-27 6:42 [Qemu-devel] [PATCH COLO-Frame (Base) v23 00/18] COarse-grain LOck-stepping(COLO) Virtual Machines for Non-stop Service (FT) zhanghailiang
2016-10-27 6:42 ` [Qemu-devel] [PATCH COLO-Frame (Base) v23 01/18] migration: Introduce capability 'x-colo' to migration zhanghailiang
2016-10-27 6:42 ` [Qemu-devel] [PATCH COLO-Frame (Base) v23 02/18] COLO: migrate COLO related info to secondary node zhanghailiang
2016-10-27 6:42 ` [Qemu-devel] [PATCH COLO-Frame (Base) v23 03/18] migration: Enter into COLO mode after migration if COLO is enabled zhanghailiang
2016-10-27 6:42 ` [Qemu-devel] [PATCH COLO-Frame (Base) v23 04/18] migration: Switch to COLO process after finishing loadvm zhanghailiang
2016-10-27 6:42 ` [Qemu-devel] [PATCH COLO-Frame (Base) v23 05/18] COLO: Establish a new communicating path for COLO zhanghailiang
2016-10-27 6:42 ` [Qemu-devel] [PATCH COLO-Frame (Base) v23 06/18] COLO: Introduce checkpointing protocol zhanghailiang
2016-10-27 6:42 ` [Qemu-devel] [PATCH COLO-Frame (Base) v23 07/18] COLO: Add a new RunState RUN_STATE_COLO zhanghailiang
2016-10-27 6:42 ` [Qemu-devel] [PATCH COLO-Frame (Base) v23 08/18] COLO: Send PVM state to secondary side when do checkpoint zhanghailiang
2016-10-27 6:43 ` [Qemu-devel] [PATCH COLO-Frame (Base) v23 09/18] COLO: Load VMState into QIOChannelBuffer before restore it zhanghailiang
2016-10-27 6:43 ` [Qemu-devel] [PATCH COLO-Frame (Base) v23 10/18] COLO: Add checkpoint-delay parameter for migrate-set-parameters zhanghailiang
2016-10-27 6:43 ` [Qemu-devel] [PATCH COLO-Frame (Base) v23 11/18] COLO: Synchronize PVM's state to SVM periodically zhanghailiang
2016-10-27 6:43 ` [Qemu-devel] [PATCH COLO-Frame (Base) v23 12/18] COLO: Add 'x-colo-lost-heartbeat' command to trigger failover zhanghailiang
2016-10-27 6:43 ` zhanghailiang [this message]
2016-10-27 6:43 ` [Qemu-devel] [PATCH COLO-Frame (Base) v23 14/18] COLO: Implement the process of failover for primary VM zhanghailiang
2016-10-27 6:43 ` [Qemu-devel] [PATCH COLO-Frame (Base) v23 15/18] COLO: Implement failover work for secondary VM zhanghailiang
2016-10-27 6:43 ` [Qemu-devel] [PATCH COLO-Frame (Base) v23 16/18] docs: Add documentation for COLO feature zhanghailiang
2016-10-27 6:43 ` [Qemu-devel] [PATCH COLO-Frame (Base) v23 17/18] configure: Support enable/disable " zhanghailiang
2016-10-27 6:43 ` [Qemu-devel] [PATCH COLO-Frame (Base) v23 18/18] MAINTAINERS: Add maintainer for COLO framework related files zhanghailiang
2016-10-27 7:34 ` Amit Shah
2016-10-28 1:42 ` Hailiang Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1477550589-16288-14-git-send-email-zhang.zhanghailiang@huawei.com \
--to=zhang.zhanghailiang@huawei.com \
--cc=amit.shah@redhat.com \
--cc=dgilbert@redhat.com \
--cc=lizhijian@cn.fujitsu.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=wency@cn.fujitsu.com \
--cc=xiecl.fnst@cn.fujitsu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).