From patchwork Tue Mar 10 08:51:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 448415 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 86DCF1401AA for ; Tue, 10 Mar 2015 19:54:52 +1100 (AEDT) Received: from localhost ([::1]:47300 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVFwA-0006MV-PA for incoming@patchwork.ozlabs.org; Tue, 10 Mar 2015 04:54:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51660) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVFsV-0007bn-J7 for qemu-devel@nongnu.org; Tue, 10 Mar 2015 04:51:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YVFsN-0007ls-St for qemu-devel@nongnu.org; Tue, 10 Mar 2015 04:51:02 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:4740 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVFsM-0007id-Oc for qemu-devel@nongnu.org; Tue, 10 Mar 2015 04:50:55 -0400 Received: from hades.sw.ru ([10.30.8.132]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id t2A8olB8017896; Tue, 10 Mar 2015 11:50:49 +0300 (MSK) From: "Denis V. Lunev" To: Date: Tue, 10 Mar 2015 11:51:17 +0300 Message-Id: <1425977481-13317-24-git-send-email-den@openvz.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1425977481-13317-1-git-send-email-den@openvz.org> References: <1425977481-13317-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.0 [fuzzy] X-Received-From: 195.214.232.25 Cc: Kevin Wolf , "Denis V. Lunev" , qemu-devel@nongnu.org, Stefan Hajnoczi , Roman Kagan Subject: [Qemu-devel] [PATCH 23/27] block/parallels: create bat_entry_off helper 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 calculate offset of the BAT entry in the image file. Signed-off-by: Denis V. Lunev CC: Roman Kagan CC: Kevin Wolf CC: Stefan Hajnoczi Reviewed-by: Roman Kagan --- block/parallels.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index d0128c9..70445b1 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -76,6 +76,11 @@ static int64_t bat2sect(BDRVParallelsState *s, uint32_t idx) return (uint64_t)le32_to_cpu(s->bat_bitmap[idx]) * s->off_multiplier; } +static uint32_t bat_entry_off(uint32_t idx) +{ + return sizeof(ParallelsHeader) + sizeof(uint32_t) * idx; +} + static int64_t seek_to_sector(BDRVParallelsState *s, int64_t sector_num) { uint32_t index, offset; @@ -146,9 +151,8 @@ static int64_t allocate_cluster(BlockDriverState *bs, int64_t sector_num) bdrv_truncate(bs->file, (pos + s->tracks) << BDRV_SECTOR_BITS); s->bat_bitmap[idx] = cpu_to_le32(pos / s->off_multiplier); - ret = bdrv_pwrite(bs->file, - sizeof(ParallelsHeader) + idx * sizeof(s->bat_bitmap[idx]), - s->bat_bitmap + idx, sizeof(s->bat_bitmap[idx])); + ret = bdrv_pwrite(bs->file, bat_entry_off(idx), s->bat_bitmap + idx, + sizeof(s->bat_bitmap[idx])); if (ret < 0) { return ret; } @@ -384,8 +388,7 @@ static int parallels_create(const char *filename, QemuOpts *opts, Error **errp) } bat_entries = DIV_ROUND_UP(total_size, cl_size); - bat_sectors = DIV_ROUND_UP(bat_entries * sizeof(uint32_t) + - sizeof(ParallelsHeader), cl_size); + bat_sectors = DIV_ROUND_UP(bat_entry_off(bat_entries), cl_size); bat_sectors = (bat_sectors * cl_size) >> BDRV_SECTOR_BITS; memset(&header, 0, sizeof(header)); @@ -495,7 +498,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } - size = sizeof(ParallelsHeader) + sizeof(uint32_t) * s->bat_size; + size = bat_entry_off(s->bat_size); s->header_size = ROUND_UP(size, bdrv_opt_mem_align(bs->file)); s->header = qemu_try_blockalign(bs->file, s->header_size); if (s->header == NULL) {