From patchwork Mon Dec 22 13:06:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 423398 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 2D9DF14007D for ; Tue, 23 Dec 2014 00:09:47 +1100 (AEDT) Received: from localhost ([::1]:40549 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y32k5-0006eN-6x for incoming@patchwork.ozlabs.org; Mon, 22 Dec 2014 08:09:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35151) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y32fX-00078V-Qy for qemu-devel@nongnu.org; Mon, 22 Dec 2014 08:05:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y32fR-0001hG-5F for qemu-devel@nongnu.org; Mon, 22 Dec 2014 08:05:03 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:36472 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y32fQ-0001h7-Pk for qemu-devel@nongnu.org; Mon, 22 Dec 2014 08:04:57 -0500 Received: from hades.sw.ru ([10.30.8.132]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id sBMD4kKC013499; Mon, 22 Dec 2014 17:04:53 +0400 (MSK) From: "Denis V. Lunev" To: Date: Mon, 22 Dec 2014 16:06:02 +0300 Message-Id: <1419253570-16914-5-git-send-email-den@openvz.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1419253570-16914-1-git-send-email-den@openvz.org> References: <1419253570-16914-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Cc: Kevin Wolf , Roman Kagan , Jeff Cody , qemu-devel@nongnu.org, Stefan Hajnoczi , "Denis V. Lunev" Subject: [Qemu-devel] [PATCH 04/12] block/parallels: read up to cluster end in one go 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 From: Roman Kagan Teach parallels_read() to do reads in coarser granularity than just a single sector: if requested, read up to the cluster end in one go. Signed-off-by: Roman Kagan Signed-off-by: Denis V. Lunev CC: Jeff Cody CC: Kevin Wolf CC: Stefan Hajnoczi --- block/parallels.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index baefd3e..8770c82 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -159,6 +159,13 @@ static int64_t seek_to_sector(BDRVParallelsState *s, int64_t sector_num) return (uint64_t)s->catalog_bitmap[index] * s->off_multiplier + offset; } +static int cluster_remainder(BDRVParallelsState *s, int64_t sector_num, + int nb_sectors) +{ + int ret = s->tracks - sector_num % s->tracks; + return MIN(nb_sectors, ret); +} + static int parallels_read(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_sectors) { @@ -166,17 +173,18 @@ static int parallels_read(BlockDriverState *bs, int64_t sector_num, while (nb_sectors > 0) { int64_t position = seek_to_sector(s, sector_num); + int n = cluster_remainder(s, sector_num, nb_sectors); if (position >= 0) { - int ret = bdrv_read(bs->file, position, buf, 1); + int ret = bdrv_read(bs->file, position, buf, n); if (ret < 0) { return ret; } } else { - memset(buf, 0, BDRV_SECTOR_SIZE); + memset(buf, 0, n << BDRV_SECTOR_BITS); } - nb_sectors--; - sector_num++; - buf += BDRV_SECTOR_SIZE; + nb_sectors -= n; + sector_num += n; + buf += n << BDRV_SECTOR_BITS; } return 0; }