qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Christoph Hellwig <hch@lst.de>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] block-raw: Allow pread beyond the end of growable images
Date: Wed, 01 Jul 2009 09:37:28 +0200	[thread overview]
Message-ID: <4A4B1238.8060302@redhat.com> (raw)
In-Reply-To: <20090630180940.GA4205@lst.de>

Christoph Hellwig schrieb:
> 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.

If you feel like posting a better patch, go ahead. I'm feeling that it's
going to be a whole lot uglier in bdrv_pwrite, but that might prove
wrong. And after all it is a problem with raw and not with the generic
block code - qcow2 for example was already reading zeros.

For the time being, this patch fixes a bug and should stay.

Kevin

  reply	other threads:[~2009-07-01  7:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-26 17:51 [Qemu-devel] [PATCH] block-raw: Allow pread beyond the end of growable images Kevin Wolf
2009-06-30 18:09 ` Christoph Hellwig
2009-07-01  7:37   ` Kevin Wolf [this message]
2009-07-01  8:56     ` Christoph Hellwig
2009-07-01  9:08       ` Kevin Wolf
2009-07-01 11:37         ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A4B1238.8060302@redhat.com \
    --to=kwolf@redhat.com \
    --cc=hch@lst.de \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).