From patchwork Tue Oct 30 08:32:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 195390 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 AE2592C00B4 for ; Tue, 30 Oct 2012 21:14:57 +1100 (EST) Received: from localhost ([::1]:47799 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT7HM-00068t-E1 for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2012 04:34:32 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60797) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT7GK-0004j6-5b 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-0000Yl-LE for qemu-devel@nongnu.org; Tue, 30 Oct 2012 04:33:28 -0400 Received: from mail.valinux.co.jp ([210.128.90.3]:44725) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT7GC-0000Wn-45 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 4CFD8181C1; Tue, 30 Oct 2012 17:33:13 +0900 (JST) Received: (nullmailer pid 29445 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:53 +0900 Message-Id: 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 17/35] arch_init: factor out logic to find ram block with id string 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 Signed-off-by: Isaku Yamahata --- arch_init.c | 31 ++++++++++++++++++++----------- arch_init.h | 1 + exec.c | 12 ++++++------ 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/arch_init.c b/arch_init.c index c77e24d..d82316d 100644 --- a/arch_init.c +++ b/arch_init.c @@ -762,6 +762,19 @@ static int load_xbzrle(QEMUFile *f, void *host) return rc; } +RAMBlock *ram_find_block(const char *id, uint8_t len) +{ + RAMBlock *block; + + QLIST_FOREACH(block, &ram_list.blocks, next) { + if (!strncmp(id, block->idstr, len)) { + return block; + } + } + + return NULL; +} + static inline void *host_from_stream_offset(QEMUFile *f, ram_addr_t offset, int flags) @@ -783,9 +796,9 @@ static inline void *host_from_stream_offset(QEMUFile *f, qemu_get_buffer(f, (uint8_t *)id, len); id[len] = 0; - QLIST_FOREACH(block, &ram_list.blocks, next) { - if (!strncmp(id, block->idstr, sizeof(id))) - return memory_region_get_ram_ptr(block->mr) + offset; + block = ram_find_block(id, len); + if (block) { + return memory_region_get_ram_ptr(block->mr) + offset; } fprintf(stderr, "Can't find block %s!\n", id); @@ -807,19 +820,15 @@ int ram_load_mem_size(QEMUFile *f, ram_addr_t total_ram_bytes) 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; - } - } - + block = ram_find_block(id, len); if (!block) { fprintf(stderr, "Unknown ramblock \"%s\", cannot " "accept migration\n", id); return -EINVAL; } + if (block->length != length) { + return -EINVAL; + } total_ram_bytes -= length; } diff --git a/arch_init.h b/arch_init.h index bca1a29..499d0f1 100644 --- a/arch_init.h +++ b/arch_init.h @@ -51,6 +51,7 @@ 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); +RAMBlock *ram_find_block(const char *id, uint8_t len); int ram_load_mem_size(QEMUFile *f, ram_addr_t total_ram_bytes); #endif diff --git a/exec.c b/exec.c index 1414654..2aa4d90 100644 --- a/exec.c +++ b/exec.c @@ -33,6 +33,7 @@ #include "kvm.h" #include "hw/xen.h" #include "qemu-timer.h" +#include "arch_init.h" #include "memory.h" #include "exec-memory.h" #if defined(CONFIG_USER_ONLY) @@ -2517,12 +2518,11 @@ void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev) pstrcat(new_block->idstr, sizeof(new_block->idstr), name); qemu_mutex_lock_ramlist(); - QLIST_FOREACH(block, &ram_list.blocks, next) { - if (block != new_block && !strcmp(block->idstr, new_block->idstr)) { - fprintf(stderr, "RAMBlock \"%s\" already registered, abort!\n", - new_block->idstr); - abort(); - } + block = ram_find_block(new_block->idstr, strlen(new_block->idstr)); + if (block != new_block) { + fprintf(stderr, "RAMBlock \"%s\" already registered, abort!\n", + new_block->idstr); + abort(); } qemu_mutex_unlock_ramlist(); }