[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH v2 09/23] COLO ctl: implement API's that communi
From: |
Yang Hongyang |
Subject: |
[Qemu-devel] [RFC PATCH v2 09/23] COLO ctl: implement API's that communicate with colo agent |
Date: |
Tue, 23 Sep 2014 17:23:41 +0800 |
We use COLO agent to compare the packets returned by
Primary VM and Secondary VM, and decide whether to start a
checkpoint according to some rules. It is a linux kernel
module for host.
COLO controller communicate with the agent through ioctl().
Signed-off-by: Yang Hongyang <address@hidden>
---
migration-colo.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 114 insertions(+), 3 deletions(-)
diff --git a/migration-colo.c b/migration-colo.c
index 1e6cd70..8610e15 100644
--- a/migration-colo.c
+++ b/migration-colo.c
@@ -12,7 +12,17 @@
#include "qemu/thread.h"
#include "block/coroutine.h"
#include "hw/qdev-core.h"
+#include "qemu/timer.h"
#include "migration/migration-colo.h"
+#include <sys/ioctl.h>
+#include "qemu/error-report.h"
+
+/*
+ * checkpoint timer: unit ms
+ * this is large because COLO checkpoint will mostly depend on
+ * COLO compare module.
+ */
+#define CHKPOINT_TIMER 10000
static QEMUBH *colo_bh;
@@ -21,16 +31,100 @@ bool colo_supported(void)
return true;
}
+/* colo compare */
+#define COMP_IOC_MAGIC 'k'
+#define COMP_IOCTWAIT _IO(COMP_IOC_MAGIC, 0)
+#define COMP_IOCTFLUSH _IO(COMP_IOC_MAGIC, 1)
+#define COMP_IOCTRESUME _IO(COMP_IOC_MAGIC, 2)
+
+#define COMPARE_DEV "/dev/HA_compare"
+/* COLO compare module FD */
+static int comp_fd = -1;
+
+static int colo_compare_init(void)
+{
+ comp_fd = open(COMPARE_DEV, O_RDONLY);
+ if (comp_fd < 0) {
+ return -1;
+ }
+
+ return 0;
+}
+
+static void colo_compare_destroy(void)
+{
+ if (comp_fd >= 0) {
+ close(comp_fd);
+ comp_fd = -1;
+ }
+}
+
+/*
+ * Communicate with COLO Agent through ioctl.
+ * return:
+ * 0: start a checkpoint
+ * other: errno == ETIME or ERESTART, try again
+ * errno == other, error, quit colo save
+ */
+static int colo_compare(void)
+{
+ return ioctl(comp_fd, COMP_IOCTWAIT, 250);
+}
+
+static __attribute__((unused)) int colo_compare_flush(void)
+{
+ return ioctl(comp_fd, COMP_IOCTFLUSH, 1);
+}
+
+static __attribute__((unused)) int colo_compare_resume(void)
+{
+ return ioctl(comp_fd, COMP_IOCTRESUME, 1);
+}
+
/* save */
static void *colo_thread(void *opaque)
{
MigrationState *s = opaque;
- int dev_hotplug = qdev_hotplug;
+ int dev_hotplug = qdev_hotplug, wait_cp = 0;
+ int64_t start_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);
+ int64_t current_time;
+
+ if (colo_compare_init() < 0) {
+ error_report("Init colo compare error");
+ goto out;
+ }
qdev_hotplug = 0;
- /*TODO: COLO checkpointed save loop*/
+ while (s->state == MIG_STATE_COLO) {
+ /* wait for a colo checkpoint */
+ wait_cp = colo_compare();
+ if (wait_cp) {
+ if (errno != ETIME && errno != ERESTART) {
+ error_report("compare module failed(%s)", strerror(errno));
+ goto out;
+ }
+ /*
+ * no checkpoint is needed, wait for 1ms and then
+ * check if we need checkpoint
+ */
+ current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);
+ if (current_time - start_time < CHKPOINT_TIMER) {
+ usleep(1000);
+ continue;
+ }
+ }
+
+ /* start a colo checkpoint */
+
+ /*TODO: COLO save */
+
+ start_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);
+ }
+
+out:
+ colo_compare_destroy();
migrate_set_state(s, MIG_STATE_COLO, MIG_STATE_COMPLETED);
@@ -72,6 +166,17 @@ void colo_init_checkpointer(MigrationState *s)
static Coroutine *colo;
+/*
+ * return:
+ * 0: start a checkpoint
+ * 1: some error happend, exit colo restore
+ */
+static int slave_wait_new_checkpoint(QEMUFile *f)
+{
+ /* TODO: wait checkpoint start command from master */
+ return 1;
+}
+
void colo_process_incoming_checkpoints(QEMUFile *f)
{
int dev_hotplug = qdev_hotplug;
@@ -85,7 +190,13 @@ void colo_process_incoming_checkpoints(QEMUFile *f)
colo = qemu_coroutine_self();
assert(colo != NULL);
- /* TODO: COLO checkpointed restore loop */
+ while (true) {
+ if (slave_wait_new_checkpoint(f)) {
+ break;
+ }
+
+ /* TODO: COLO restore */
+ }
colo = NULL;
restore_exit_colo();
--
1.9.1
- [Qemu-devel] [RFC PATCH v2 00/23] COarse-grain LOck-stepping(COLO) Virtual Machines for Non-stop Service, Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 01/23] QEMUSizedBuffer/QEMUFile, Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 02/23] configure: add CONFIG_COLO to switch COLO support, Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 05/23] COLO info: use colo info to tell migration target colo is enabled, Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 06/23] COLO save: integrate COLO checkpointed save into qemu migration, Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 09/23] COLO ctl: implement API's that communicate with colo agent,
Yang Hongyang <=
- [Qemu-devel] [RFC PATCH v2 07/23] COLO restore: integrate COLO checkpointed restore into qemu restore, Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 08/23] COLO: disable qdev hotplug, Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 10/23] COLO ctl: introduce is_slave() and is_master(), Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 03/23] COLO: introduce an api colo_supported() to indicate COLO support, Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 04/23] COLO migration: add a migration capability 'colo', Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 11/23] COLO ctl: implement colo checkpoint protocol, Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 12/23] COLO ctl: add a RunState RUN_STATE_COLO, Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 13/23] COLO ctl: implement colo save, Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 14/23] COLO ctl: implement colo restore, Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 16/23] COLO ram cache: implement colo ram cache on slave, Yang Hongyang, 2014/09/23