From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53782) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a19w0-0007Ch-1e for qemu-devel@nongnu.org; Tue, 24 Nov 2015 04:30:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a19vw-000881-LX for qemu-devel@nongnu.org; Tue, 24 Nov 2015 04:30:47 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:40475) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a19vv-00087H-Uz for qemu-devel@nongnu.org; Tue, 24 Nov 2015 04:30:44 -0500 From: zhanghailiang Date: Tue, 24 Nov 2015 17:25:24 +0800 Message-ID: <1448357149-17572-15-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 14/39] ram: Split host_from_stream_offset() into two helper functions 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 Split host_from_stream_offset() into two parts: One is to get ram block, which the block idstr may be get from migration stream, the other is to get hva (host) address from block and the offset. Signed-off-by: zhanghailiang --- v11: - New patch --- migration/ram.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index cfe78aa..a161620 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2136,9 +2136,9 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host) * offset: Offset within the block * flags: Page flags (mostly to see if it's a continuation of previous block) */ -static inline void *host_from_stream_offset(QEMUFile *f, - ram_addr_t offset, - int flags) +static inline RAMBlock *ram_block_from_stream(QEMUFile *f, + ram_addr_t offset, + int flags) { static RAMBlock *block = NULL; char id[256]; @@ -2150,22 +2150,31 @@ static inline void *host_from_stream_offset(QEMUFile *f, return NULL; } - return block->host + offset; + return block; } - len = qemu_get_byte(f); qemu_get_buffer(f, (uint8_t *)id, len); id[len] = 0; block = qemu_ram_block_by_name(id); if (block && block->max_length > offset) { - return block->host + offset; + return block; } error_report("Can't find block %s", id); return NULL; } +static inline void *host_from_ram_block_offset(RAMBlock *block, + ram_addr_t offset) +{ + if (!block) { + return NULL; + } + + return block->host + offset; +} + /* * If a page (or a whole RDMA chunk) has been * determined to be zero, then zap it. @@ -2310,7 +2319,9 @@ static int ram_load_postcopy(QEMUFile *f) trace_ram_load_postcopy_loop((uint64_t)addr, flags); place_needed = false; if (flags & (RAM_SAVE_FLAG_COMPRESS | RAM_SAVE_FLAG_PAGE)) { - host = host_from_stream_offset(f, addr, flags); + RAMBlock *block = ram_block_from_stream(f, addr, flags); + + host = host_from_ram_block_offset(block, addr); if (!host) { error_report("Illegal RAM offset " RAM_ADDR_FMT, addr); ret = -EINVAL; @@ -2441,7 +2452,9 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) if (flags & (RAM_SAVE_FLAG_COMPRESS | RAM_SAVE_FLAG_PAGE | RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE)) { - host = host_from_stream_offset(f, addr, flags); + RAMBlock *block = ram_block_from_stream(f, addr, flags); + + host = host_from_ram_block_offset(block, addr); if (!host) { error_report("Illegal RAM offset " RAM_ADDR_FMT, addr); ret = -EINVAL; -- 1.8.3.1