From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56149) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y5thR-0005Gi-UQ for qemu-devel@nongnu.org; Tue, 30 Dec 2014 05:06:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y5thQ-0003YA-NN for qemu-devel@nongnu.org; Tue, 30 Dec 2014 05:06:49 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:22277 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y5thP-0003WZ-Nu for qemu-devel@nongnu.org; Tue, 30 Dec 2014 05:06:48 -0500 From: "Denis V. Lunev" Date: Tue, 30 Dec 2014 13:07:06 +0300 Message-Id: <1419934032-24216-4-git-send-email-den@openvz.org> In-Reply-To: <1419934032-24216-1-git-send-email-den@openvz.org> References: <1419931701-19362-1-git-send-email-den@openvz.org> <1419934032-24216-1-git-send-email-den@openvz.org> Subject: [Qemu-devel] [PATCH 13/19] block/parallels: store ParallelsHeader to the BDRVParallelsState List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , "Denis V. Lunev" , qemu-devel@nongnu.org, Stefan Hajnoczi This would be useful for the future for speed optimizations of new block creation in the image. At the moment each write to the catalog bitmap results in read-modify-write transaction. It would be beneficial to write by pages or sectors. Though in order to do that for the begining of the image we should keep the header somethere to obtain first sector of the image properly. BDRVParallelsState would be a good place for that. Signed-off-by: Denis V. Lunev CC: Kevin Wolf CC: Stefan Hajnoczi --- block/parallels.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index e3abf4e..f79ddff 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -57,6 +57,8 @@ typedef struct ParallelsHeader { typedef struct BDRVParallelsState { CoMutex lock; + ParallelsHeader ph; + uint32_t *catalog_bitmap; unsigned int catalog_size; @@ -85,29 +87,28 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, { BDRVParallelsState *s = bs->opaque; int i; - ParallelsHeader ph; int ret; - ret = bdrv_pread(bs->file, 0, &ph, sizeof(ph)); + ret = bdrv_pread(bs->file, 0, &s->ph, sizeof(s->ph)); if (ret < 0) { goto fail; } - bs->total_sectors = le64_to_cpu(ph.nb_sectors); + bs->total_sectors = le64_to_cpu(s->ph.nb_sectors); - if (le32_to_cpu(ph.version) != HEADER_VERSION) { + if (le32_to_cpu(s->ph.version) != HEADER_VERSION) { goto fail_format; } - if (!memcmp(ph.magic, HEADER_MAGIC, 16)) { + if (!memcmp(s->ph.magic, HEADER_MAGIC, 16)) { s->off_multiplier = 1; bs->total_sectors = 0xffffffff & bs->total_sectors; - } else if (!memcmp(ph.magic, HEADER_MAGIC2, 16)) { - s->off_multiplier = le32_to_cpu(ph.tracks); + } else if (!memcmp(s->ph.magic, HEADER_MAGIC2, 16)) { + s->off_multiplier = le32_to_cpu(s->ph.tracks); } else { goto fail_format; } - s->tracks = le32_to_cpu(ph.tracks); + s->tracks = le32_to_cpu(s->ph.tracks); if (s->tracks == 0) { error_setg(errp, "Invalid image: Zero sectors per track"); ret = -EINVAL; @@ -119,7 +120,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } - s->catalog_size = le32_to_cpu(ph.catalog_entries); + s->catalog_size = le32_to_cpu(s->ph.catalog_entries); if (s->catalog_size > INT_MAX / sizeof(uint32_t)) { error_setg(errp, "Catalog too large"); ret = -EFBIG; -- 1.9.1