From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1AOY-0000LQ-Pq for qemu-devel@nongnu.org; Tue, 24 Nov 2015 05:00:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1AON-00088T-FS for qemu-devel@nongnu.org; Tue, 24 Nov 2015 05:00:18 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:26588) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1AOM-00081U-JS for qemu-devel@nongnu.org; Tue, 24 Nov 2015 05:00:07 -0500 From: zhanghailiang Date: Tue, 24 Nov 2015 17:25:27 +0800 Message-ID: <1448357149-17572-18-git-send-email-zhang.zhanghailiang@huawei.com> In-Reply-To: <1448357149-17572-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1448357149-17572-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH COLO-Frame v11 17/39] COLO: Load VMState into qsb before restore it List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: lizhijian@cn.fujitsu.com, quintela@redhat.com, yunhong.jiang@intel.com, eddie.dong@intel.com, peter.huangpeng@huawei.com, dgilbert@redhat.com, zhanghailiang , arei.gonglei@huawei.com, stefanha@redhat.com, amit.shah@redhat.com, hongyang.yang@easystack.cn We should not destroy the state of SVM (Secondary VM) until we receive the whole state from the PVM (Primary VM), in case the primary fails in the middle of sending the state, so, here we cache the device state in Secondary before restore it. Besides, we should call qemu_system_reset() before load VM state, which can ensure the data is intact. Signed-off-by: zhanghailiang Signed-off-by: Li Zhijian Signed-off-by: Gonglei Reviewed-by: Dr. David Alan Gilbert --- migration/colo.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/migration/colo.c b/migration/colo.c index 6e933fa..5ac8ff2 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -285,6 +285,9 @@ static int colo_wait_handle_cmd(QEMUFile *f, int *checkpoint_request) void *colo_process_incoming_thread(void *opaque) { MigrationIncomingState *mis = opaque; + QEMUFile *fb = NULL; + QEMUSizedBuffer *buffer = NULL; /* Cache incoming device state */ + uint64_t total_size; int ret = 0; uint64_t value; @@ -310,6 +313,12 @@ void *colo_process_incoming_thread(void *opaque) goto out; } + buffer = qsb_create(NULL, COLO_BUFFER_BASE_SIZE); + if (buffer == NULL) { + error_report("Failed to allocate colo buffer!"); + goto out; + } + ret = colo_ctl_put(mis->to_src_file, COLO_COMMAND_CHECKPOINT_READY, 0); if (ret < 0) { goto out; @@ -338,19 +347,53 @@ void *colo_process_incoming_thread(void *opaque) goto out; } - /* TODO: read migration data into colo buffer */ + /* read the VM state total size first */ + ret = colo_ctl_get(mis->from_src_file, + COLO_COMMAND_VMSTATE_SIZE, &value); + if (ret < 0) { + error_report("%s: Failed to get vmstate size", __func__); + goto out; + } + + /* read vm device state into colo buffer */ + total_size = qsb_fill_buffer(buffer, mis->from_src_file, value); + if (total_size != value) { + error_report("Got %lu VMState data, less than expected %lu", + total_size, value); + ret = -EINVAL; + goto out; + } ret = colo_ctl_put(mis->to_src_file, COLO_COMMAND_VMSTATE_RECEIVED, 0); if (ret < 0) { goto out; } - /* TODO: load vm state */ + /* open colo buffer for read */ + fb = qemu_bufopen("r", buffer); + if (!fb) { + error_report("can't open colo buffer for read"); + goto out; + } + + qemu_mutex_lock_iothread(); + qemu_system_reset(VMRESET_SILENT); + if (qemu_loadvm_state(fb) < 0) { + error_report("COLO: loadvm failed"); + qemu_mutex_unlock_iothread(); + goto out; + } + qemu_mutex_unlock_iothread(); + + /* TODO: flush vm state */ ret = colo_ctl_put(mis->to_src_file, COLO_COMMAND_VMSTATE_LOADED, 0); if (ret < 0) { goto out; } + + qemu_fclose(fb); + fb = NULL; } out: @@ -359,6 +402,11 @@ out: strerror(-ret)); } + if (fb) { + qemu_fclose(fb); + } + qsb_free(buffer); + qemu_mutex_lock_iothread(); colo_release_ram_cache(); qemu_mutex_unlock_iothread(); -- 1.8.3.1