From patchwork Tue Oct 30 08:32:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 195410 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 34F592C009B for ; Tue, 30 Oct 2012 21:25:34 +1100 (EST) Received: from localhost ([::1]:49586 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT7IM-00079O-0D for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2012 04:35:34 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60809) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT7GK-0004j8-Fp for qemu-devel@nongnu.org; Tue, 30 Oct 2012 04:33:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TT7GC-0000Z2-MN for qemu-devel@nongnu.org; Tue, 30 Oct 2012 04:33:28 -0400 Received: from mail.valinux.co.jp ([210.128.90.3]:44738) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT7GB-0000XI-VO for qemu-devel@nongnu.org; Tue, 30 Oct 2012 04:33:20 -0400 Received: from ps.local.valinux.co.jp (vagw.valinux.co.jp [210.128.90.14]) by mail.valinux.co.jp (Postfix) with SMTP id 1A0F8181BF; Tue, 30 Oct 2012 17:33:13 +0900 (JST) Received: (nullmailer pid 29441 invoked by uid 1000); Tue, 30 Oct 2012 08:33:12 -0000 From: Isaku Yamahata To: qemu-devel@nongnu.org, kvm@vger.kernel.org Date: Tue, 30 Oct 2012 17:32:52 +0900 Message-Id: <42d787bd049bd64c3c8959defa74a75ad1301cf9.1351582535.git.yamahata@valinux.co.jp> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: In-Reply-To: References: X-Virus-Scanned: clamav-milter 0.95.2 at va-mail.local.valinux.co.jp X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 210.128.90.3 Cc: benoit.hudzia@gmail.com, aarcange@redhat.com, aliguori@us.ibm.com, quintela@redhat.com, stefanha@gmail.com, t.hirofuchi@aist.go.jp, dlaor@redhat.com, satoshi.itoh@aist.go.jp, mdroth@linux.vnet.ibm.com, yoshikawa.takuya@oss.ntt.co.jp, owasserm@redhat.com, avi@redhat.com, pbonzini@redhat.com, chegu_vinod@hp.com Subject: [Qemu-devel] [PATCH v3 16/35] arch_init/ram_load: refactor ram_load X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org ram_load_page() will be used by postcopy. Signed-off-by: Isaku Yamahata --- Changes v2 -> v3: - new --- arch_init.c | 137 +++++++++++++++++++++++++++++++---------------------------- arch_init.h | 3 ++ 2 files changed, 74 insertions(+), 66 deletions(-) diff --git a/arch_init.c b/arch_init.c index 7e6d84e..c77e24d 100644 --- a/arch_init.c +++ b/arch_init.c @@ -721,7 +721,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque) return 0; } -static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host) +static int load_xbzrle(QEMUFile *f, void *host) { int ret, rc = 0; unsigned int xh_len; @@ -792,12 +792,73 @@ static inline void *host_from_stream_offset(QEMUFile *f, return NULL; } +int ram_load_mem_size(QEMUFile *f, ram_addr_t total_ram_bytes) +{ + /* Synchronize RAM block list */ + char id[256]; + ram_addr_t length; + + while (total_ram_bytes) { + RAMBlock *block; + uint8_t len; + + len = qemu_get_byte(f); + qemu_get_buffer(f, (uint8_t *)id, len); + id[len] = 0; + length = qemu_get_be64(f); + + QLIST_FOREACH(block, &ram_list.blocks, next) { + if (!strncmp(id, block->idstr, sizeof(id))) { + if (block->length != length) + return -EINVAL; + break; + } + } + + if (!block) { + fprintf(stderr, "Unknown ramblock \"%s\", cannot " + "accept migration\n", id); + return -EINVAL; + } + + total_ram_bytes -= length; + } + + return 0; +} + +int ram_load_page(QEMUFile *f, void *host, int flags) +{ + if (flags & RAM_SAVE_FLAG_COMPRESS) { + uint8_t ch; + ch = qemu_get_byte(f); + memset(host, ch, TARGET_PAGE_SIZE); +#ifndef _WIN32 + if (ch == 0 && + (!kvm_enabled() || kvm_has_sync_mmu())) { + qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNEED); + } +#endif + } else if (flags & RAM_SAVE_FLAG_PAGE) { + qemu_get_buffer(f, host, TARGET_PAGE_SIZE); + } else if (flags & RAM_SAVE_FLAG_XBZRLE) { + if (!migrate_use_xbzrle()) { + return -EINVAL; + } + if (load_xbzrle(f, host) < 0) { + return -EINVAL; + } + } + return 0; +} + static int ram_load(QEMUFile *f, void *opaque, int version_id) { ram_addr_t addr; int flags, ret = 0; int error; static uint64_t seq_iter; + void *host; seq_iter++; @@ -813,82 +874,26 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) if (flags & RAM_SAVE_FLAG_MEM_SIZE) { if (version_id == 4) { - /* Synchronize RAM block list */ - char id[256]; - ram_addr_t length; - ram_addr_t total_ram_bytes = addr; - - while (total_ram_bytes) { - RAMBlock *block; - uint8_t len; - - len = qemu_get_byte(f); - qemu_get_buffer(f, (uint8_t *)id, len); - id[len] = 0; - length = qemu_get_be64(f); - - QLIST_FOREACH(block, &ram_list.blocks, next) { - if (!strncmp(id, block->idstr, sizeof(id))) { - if (block->length != length) { - ret = -EINVAL; - goto done; - } - break; - } - } - - if (!block) { - fprintf(stderr, "Unknown ramblock \"%s\", cannot " - "accept migration\n", id); - ret = -EINVAL; - goto done; - } - - total_ram_bytes -= length; + error = ram_load_mem_size(f, addr); + if (error) { + DPRINTF("error %d\n", error); + return error; } } } - if (flags & RAM_SAVE_FLAG_COMPRESS) { - void *host; - uint8_t ch; - - host = host_from_stream_offset(f, addr, flags); - if (!host) { - return -EINVAL; - } - - ch = qemu_get_byte(f); - memset(host, ch, TARGET_PAGE_SIZE); -#ifndef _WIN32 - if (ch == 0 && - (!kvm_enabled() || kvm_has_sync_mmu())) { - qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNEED); - } -#endif - } else if (flags & RAM_SAVE_FLAG_PAGE) { - void *host; - + if (flags & (RAM_SAVE_FLAG_COMPRESS | RAM_SAVE_FLAG_PAGE | + RAM_SAVE_FLAG_XBZRLE)) { host = host_from_stream_offset(f, addr, flags); if (!host) { return -EINVAL; } - - qemu_get_buffer(f, host, TARGET_PAGE_SIZE); - } else if (flags & RAM_SAVE_FLAG_XBZRLE) { - if (!migrate_use_xbzrle()) { - return -EINVAL; - } - void *host = host_from_stream_offset(f, addr, flags); - if (!host) { - return -EINVAL; - } - - if (load_xbzrle(f, addr, host) < 0) { - ret = -EINVAL; + ret = ram_load_page(f, host, flags); + if (ret) { goto done; } } + error = qemu_file_get_error(f); if (error) { ret = error; diff --git a/arch_init.h b/arch_init.h index f2a7ae5..bca1a29 100644 --- a/arch_init.h +++ b/arch_init.h @@ -46,9 +46,12 @@ CpuDefinitionInfoList GCC_WEAK_DECL *arch_query_cpu_definitions(Error **errp); #define RAM_SAVE_VERSION_ID 4 /* currently version 4 */ +int ram_load_page(QEMUFile *f, void *host, int flags); + #if defined(NEED_CPU_H) && !defined(CONFIG_USER_ONLY) bool ram_save_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset, bool last_stage); +int ram_load_mem_size(QEMUFile *f, ram_addr_t total_ram_bytes); #endif #endif