From patchwork Fri Jun 4 10:03:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 54560 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 16906B7D70 for ; Fri, 4 Jun 2010 20:04:32 +1000 (EST) Received: from localhost ([127.0.0.1]:45171 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKTlM-0008Ju-KA for incoming@patchwork.ozlabs.org; Fri, 04 Jun 2010 06:04:28 -0400 Received: from [140.186.70.92] (port=45731 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKTkX-0008Jo-My for qemu-devel@nongnu.org; Fri, 04 Jun 2010 06:03:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OKTkW-00057v-FS for qemu-devel@nongnu.org; Fri, 04 Jun 2010 06:03:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26172) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OKTkW-00057m-88 for qemu-devel@nongnu.org; Fri, 04 Jun 2010 06:03:36 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o54A3Z4g032538 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 4 Jun 2010 06:03:35 -0400 Received: from localhost.localdomain (vpn1-5-49.ams2.redhat.com [10.36.5.49]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o54A3MwO022472; Fri, 4 Jun 2010 06:03:26 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Fri, 4 Jun 2010 12:03:05 +0200 Message-Id: <1275645785-24658-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com Subject: [Qemu-devel] [PATCH] vpc: Read/write multiple sectors at once X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This changes the vpc block driver (for VHD) to read/write multiple sectors at once instead of doing a request for each single sector. Before this, running qemu-iotests for VPC took ages, now it's actually quite reasonable to run it always (down from ~1 hour to 40 seconds for me). Signed-off-by: Kevin Wolf --- block/vpc.c | 41 ++++++++++++++++++++++++++++++----------- 1 files changed, 30 insertions(+), 11 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index 214e9d1..f1f73e2 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -371,23 +371,33 @@ fail: static int vpc_read(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_sectors) { + BDRVVPCState *s = bs->opaque; int ret; int64_t offset; + int64_t sectors, sectors_per_block; while (nb_sectors > 0) { offset = get_sector_offset(bs, sector_num, 0); + sectors_per_block = s->block_size >> BDRV_SECTOR_BITS; + sectors = sectors_per_block - (sector_num % sectors_per_block); + if (sectors > nb_sectors) { + sectors = nb_sectors; + } + if (offset == -1) { - memset(buf, 0, 512); + memset(buf, 0, sectors * BDRV_SECTOR_SIZE); } else { - ret = bdrv_pread(bs->file, offset, buf, 512); - if (ret != 512) + ret = bdrv_pread(bs->file, offset, buf, + sectors * BDRV_SECTOR_SIZE); + if (ret != sectors * BDRV_SECTOR_SIZE) { return -1; + } } - nb_sectors--; - sector_num++; - buf += 512; + nb_sectors -= sectors; + sector_num += sectors; + buf += sectors * BDRV_SECTOR_SIZE; } return 0; } @@ -395,25 +405,34 @@ static int vpc_read(BlockDriverState *bs, int64_t sector_num, static int vpc_write(BlockDriverState *bs, int64_t sector_num, const uint8_t *buf, int nb_sectors) { + BDRVVPCState *s = bs->opaque; int64_t offset; + int64_t sectors, sectors_per_block; int ret; while (nb_sectors > 0) { offset = get_sector_offset(bs, sector_num, 1); + sectors_per_block = s->block_size >> BDRV_SECTOR_BITS; + sectors = sectors_per_block - (sector_num % sectors_per_block); + if (sectors > nb_sectors) { + sectors = nb_sectors; + } + if (offset == -1) { offset = alloc_block(bs, sector_num); if (offset < 0) return -1; } - ret = bdrv_pwrite(bs->file, offset, buf, 512); - if (ret != 512) + ret = bdrv_pwrite(bs->file, offset, buf, sectors * BDRV_SECTOR_SIZE); + if (ret != sectors * BDRV_SECTOR_SIZE) { return -1; + } - nb_sectors--; - sector_num++; - buf += 512; + nb_sectors -= sectors; + sector_num += sectors; + buf += sectors * BDRV_SECTOR_SIZE; } return 0;