From patchwork Fri May 7 15:17:09 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 51933 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 4607DB7D28 for ; Sat, 8 May 2010 01:38:48 +1000 (EST) Received: from localhost ([127.0.0.1]:35385 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OAPdT-0007VE-NF for incoming@patchwork.ozlabs.org; Fri, 07 May 2010 11:38:43 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1OAPIg-0000Fl-7Q for qemu-devel@nongnu.org; Fri, 07 May 2010 11:17:14 -0400 Received: from [140.186.70.92] (port=55287 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OAPIe-0000Es-CQ for qemu-devel@nongnu.org; Fri, 07 May 2010 11:17:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OAPIc-0007Kb-JL for qemu-devel@nongnu.org; Fri, 07 May 2010 11:17:12 -0400 Received: from verein.lst.de ([213.95.11.210]:57565) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OAPIc-0007KM-4u for qemu-devel@nongnu.org; Fri, 07 May 2010 11:17:10 -0400 Received: from verein.lst.de (localhost [127.0.0.1]) by verein.lst.de (8.12.3/8.12.3/Debian-7.1) with ESMTP id o47FH9WY015266 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Fri, 7 May 2010 17:17:09 +0200 Received: (from hch@localhost) by verein.lst.de (8.12.3/8.12.3/Debian-7.2) id o47FH9Df015265 for qemu-devel@nongnu.org; Fri, 7 May 2010 17:17:09 +0200 Date: Fri, 7 May 2010 17:17:09 +0200 From: Christoph Hellwig To: qemu-devel@nongnu.org Message-ID: <20100507151709.GA15249@lst.de> References: <20100507151658.GA15132@lst.de> Mime-Version: 1.0 Content-Disposition: inline In-Reply-To: <20100507151658.GA15132@lst.de> User-Agent: Mutt/1.3.28i X-Scanned-By: MIMEDefang 2.39 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH 1/3] cow: use pread/pwrite 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 Use pread/pwrite instead of lseek + read/write in preparation of using the qemu block API. Signed-off-by: Christoph Hellwig Index: qemu/block/cow.c =================================================================== --- qemu.orig/block/cow.c 2010-05-04 19:11:24.897004616 +0200 +++ qemu/block/cow.c 2010-05-04 19:12:29.010255070 +0200 @@ -78,7 +78,7 @@ static int cow_open(BlockDriverState *bs } s->fd = fd; /* see if it is a cow image */ - if (read(fd, &cow_header, sizeof(cow_header)) != sizeof(cow_header)) { + if (pread(fd, &cow_header, sizeof(cow_header), 0) != sizeof(cow_header)) { goto fail; } @@ -159,8 +159,8 @@ static int cow_read(BlockDriverState *bs while (nb_sectors > 0) { if (is_changed(s->cow_bitmap, sector_num, nb_sectors, &n)) { - lseek(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET); - ret = read(s->fd, buf, n * 512); + ret = pread(s->fd, buf, n * 512, + s->cow_sectors_offset + sector_num * 512); if (ret != n * 512) return -1; } else { @@ -186,8 +186,8 @@ static int cow_write(BlockDriverState *b BDRVCowState *s = bs->opaque; int ret, i; - lseek(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET); - ret = write(s->fd, buf, nb_sectors * 512); + ret = pwrite(s->fd, buf, nb_sectors * 512, + s->cow_sectors_offset + sector_num * 512); if (ret != nb_sectors * 512) return -1; for (i = 0; i < nb_sectors; i++)