From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MLhm7-000634-IX for qemu-devel@nongnu.org; Tue, 30 Jun 2009 14:09:47 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MLhm3-000616-2o for qemu-devel@nongnu.org; Tue, 30 Jun 2009 14:09:47 -0400 Received: from [199.232.76.173] (port=39125 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MLhm2-000613-Vu for qemu-devel@nongnu.org; Tue, 30 Jun 2009 14:09:43 -0400 Received: from verein.lst.de ([213.95.11.210]:50893) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA1:24) (Exim 4.60) (envelope-from ) id 1MLhm2-0002QQ-GD for qemu-devel@nongnu.org; Tue, 30 Jun 2009 14:09:42 -0400 Date: Tue, 30 Jun 2009 20:09:40 +0200 From: Christoph Hellwig Subject: Re: [Qemu-devel] [PATCH] block-raw: Allow pread beyond the end of growable images Message-ID: <20090630180940.GA4205@lst.de> References: <1246038684-3702-1-git-send-email-kwolf@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1246038684-3702-1-git-send-email-kwolf@redhat.com> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: qemu-devel@nongnu.org On Fri, Jun 26, 2009 at 07:51:24PM +0200, Kevin Wolf wrote: > diff --git a/block/raw-posix.c b/block/raw-posix.c > index fa1a394..985bf69 100644 > --- a/block/raw-posix.c > +++ b/block/raw-posix.c > @@ -117,6 +117,7 @@ typedef struct BDRVRawState { > static int posix_aio_init(void); > > static int fd_open(BlockDriverState *bs); > +static int64_t raw_getlength(BlockDriverState *bs); > > #if defined(__FreeBSD__) > static int cdrom_reopen(BlockDriverState *bs); > @@ -231,6 +232,16 @@ static int raw_pread_aligned(BlockDriverState *bs, int64_t offset, > if (ret == count) > goto label__raw_read__success; > > + /* Allow reads beyond the end (needed for pwrite) */ > + if ((ret == 0) && bs->growable) { > + int64_t size = raw_getlength(bs); > + if (offset >= size) { > + memset(buf, 0, count); > + ret = count; > + goto label__raw_read__success; > + } > + } I really don't like doing this inside the lowelevel read handler. If this is indeed only needed for pwrite we might be better off doing the right thing in the place that needs it, bdrv_pwrite.