[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] block-raw: Allow pread beyond the end of growab
From: |
Christoph Hellwig |
Subject: |
Re: [Qemu-devel] [PATCH] block-raw: Allow pread beyond the end of growable images |
Date: |
Tue, 30 Jun 2009 20:09:40 +0200 |
User-agent: |
Mutt/1.3.28i |
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.