From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59196) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XWMLK-0001wB-As for qemu-devel@nongnu.org; Tue, 23 Sep 2014 05:25:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XWMLE-00089n-Qf for qemu-devel@nongnu.org; Tue, 23 Sep 2014 05:25:06 -0400 Received: from [59.151.112.132] (port=56236 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XWMLD-00084T-IJ for qemu-devel@nongnu.org; Tue, 23 Sep 2014 05:25:00 -0400 From: Yang Hongyang Date: Tue, 23 Sep 2014 17:23:45 +0800 Message-ID: <1411464235-5653-14-git-send-email-yanghy@cn.fujitsu.com> In-Reply-To: <1411464235-5653-1-git-send-email-yanghy@cn.fujitsu.com> References: <1411464235-5653-1-git-send-email-yanghy@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [RFC PATCH v2 13/23] COLO ctl: implement colo save List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: GuiJianfeng@cn.fujitsu.com, yunhong.jiang@intel.com, eddie.dong@intel.com, dgilbert@redhat.com, mrhines@linux.vnet.ibm.com, yanghy@cn.fujitsu.com implement colo save Signed-off-by: Yang Hongyang --- migration-colo.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/migration-colo.c b/migration-colo.c index 2e478e9..d99342a 100644 --- a/migration-colo.c +++ b/migration-colo.c @@ -13,6 +13,7 @@ #include "block/coroutine.h" #include "hw/qdev-core.h" #include "qemu/timer.h" +#include "sysemu/sysemu.h" #include "migration/migration-colo.h" #include #include "qemu/error-report.h" @@ -106,12 +107,12 @@ static int colo_compare(void) return ioctl(comp_fd, COMP_IOCTWAIT, 250); } -static __attribute__((unused)) int colo_compare_flush(void) +static int colo_compare_flush(void) { return ioctl(comp_fd, COMP_IOCTFLUSH, 1); } -static __attribute__((unused)) int colo_compare_resume(void) +static int colo_compare_resume(void) { return ioctl(comp_fd, COMP_IOCTRESUME, 1); } @@ -200,6 +201,9 @@ static bool colo_is_master(void) static int do_colo_transaction(MigrationState *s, QEMUFile *control) { int ret; + uint8_t *buf; + size_t size; + QEMUFile *trans = NULL; ret = colo_ctl_put(s->file, COLO_CHECKPOINT_NEW); if (ret) { @@ -211,30 +215,73 @@ static int do_colo_transaction(MigrationState *s, QEMUFile *control) goto out; } - /* TODO: suspend and save vm state to colo buffer */ + /* open colo buffer for write */ + trans = qemu_bufopen("w", NULL); + if (!trans) { + error_report("Open colo buffer for write failed"); + goto out; + } + + /* suspend and save vm state to colo buffer */ + qemu_mutex_lock_iothread(); + vm_stop_force_state(RUN_STATE_COLO); + qemu_mutex_unlock_iothread(); + /* Disable block migration */ + s->params.blk = 0; + s->params.shared = 0; + qemu_savevm_state_begin(trans, &s->params); + qemu_savevm_state_complete(trans); + + qemu_fflush(trans); ret = colo_ctl_put(s->file, COLO_CHECKPOINT_SEND); if (ret) { goto out; } - /* TODO: send vmstate to slave */ + /* send vmstate to slave */ + + /* we send the total size of the vmstate first */ + size = qsb_get_length(qemu_buf_get(trans)); + ret = colo_ctl_put(s->file, size); + if (ret) { + goto out; + } + + buf = g_malloc(size); + qsb_get_buffer(qemu_buf_get(trans), 0, size, &buf); + qemu_put_buffer(s->file, buf, size); + g_free(buf); + ret = qemu_file_get_error(s->file); + if (ret < 0) { + goto out; + } + qemu_fflush(s->file); ret = colo_ctl_get(control, COLO_CHECKPOINT_RECEIVED); if (ret) { goto out; } - /* TODO: Flush network etc. */ + /* Flush network etc. */ + colo_compare_flush(); ret = colo_ctl_get(control, COLO_CHECKPOINT_LOADED); if (ret) { goto out; } - /* TODO: resume master */ + colo_compare_resume(); + ret = 0; out: + if (trans) + qemu_fclose(trans); + /* resume master */ + qemu_mutex_lock_iothread(); + vm_start(); + qemu_mutex_unlock_iothread(); + return ret; } @@ -289,7 +336,6 @@ static void *colo_thread(void *opaque) } /* start a colo checkpoint */ - if (do_colo_transaction(s, colo_control)) { goto out; } -- 1.9.1