From patchwork Wed Mar 11 10:28:10 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: 448938 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 4A11B140172 for ; Wed, 11 Mar 2015 21:40:58 +1100 (AEDT) Received: from localhost ([::1]:53685 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVe4O-00069b-94 for incoming@patchwork.ozlabs.org; Wed, 11 Mar 2015 06:40:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVdru-0000Ft-LA for qemu-devel@nongnu.org; Wed, 11 Mar 2015 06:28:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YVdrf-0003wD-35 for qemu-devel@nongnu.org; Wed, 11 Mar 2015 06:28:02 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:14697 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVdre-0003tt-JV for qemu-devel@nongnu.org; Wed, 11 Mar 2015 06:27:46 -0400 Received: from hades.sw.ru ([10.30.8.132]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id t2BARgbc017637; Wed, 11 Mar 2015 13:27:43 +0300 (MSK) From: "Denis V. Lunev" To: Date: Wed, 11 Mar 2015 13:28:10 +0300 Message-Id: <1426069701-1405-17-git-send-email-den@openvz.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426069701-1405-1-git-send-email-den@openvz.org> References: <1426069701-1405-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 Subject: [Qemu-devel] [PATCH 16/27] block/parallels: read parallels image header and BAT into single buffer 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 This metadata cache would allow to properly batch BAT updates to disk in next patches. These updates will be properly aligned to avoid read-modify-write transactions on block level. Signed-off-by: Denis V. Lunev Reviewed-by: Roman Kagan CC: Kevin Wolf CC: Stefan Hajnoczi Reviewed-by: Stefan Hajnoczi --- block/parallels.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 8301de4..3d515dd 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -57,6 +57,8 @@ typedef struct ParallelsHeader { typedef struct BDRVParallelsState { CoMutex lock; + ParallelsHeader *header; + uint32_t header_size; uint32_t *bat_bitmap; unsigned int bat_size; @@ -85,7 +87,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, { BDRVParallelsState *s = bs->opaque; ParallelsHeader ph; - int ret; + int ret, size; ret = bdrv_pread(bs->file, 0, &ph, sizeof(ph)); if (ret < 0) { @@ -124,17 +126,25 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, ret = -EFBIG; goto fail; } - s->bat_bitmap = g_try_new(uint32_t, s->bat_size); - if (s->bat_size && s->bat_bitmap == NULL) { + + size = sizeof(ParallelsHeader) + sizeof(uint32_t) * 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) { ret = -ENOMEM; goto fail; } + if (le32_to_cpu(ph.data_off) < s->header_size) { + /* there is not enough unused space to fit to block align between BAT + and actual data. We can't avoid read-modify-write... */ + s->header_size = size; + } - ret = bdrv_pread(bs->file, sizeof(ParallelsHeader), - s->bat_bitmap, s->bat_size * sizeof(uint32_t)); + ret = bdrv_pread(bs->file, 0, s->header, s->header_size); if (ret < 0) { goto fail; } + s->bat_bitmap = (uint32_t *)(s->header + 1); qemu_co_mutex_init(&s->lock); return 0; @@ -143,7 +153,7 @@ fail_format: error_setg(errp, "Image not in Parallels format"); ret = -EINVAL; fail: - g_free(s->bat_bitmap); + qemu_vfree(s->header); return ret; } @@ -384,7 +394,7 @@ exit: static void parallels_close(BlockDriverState *bs) { BDRVParallelsState *s = bs->opaque; - g_free(s->bat_bitmap); + qemu_vfree(s->header); } static QemuOptsList parallels_create_opts = {