qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Max Reitz <mreitz@redhat.com>
Cc: qemu-devel@nongnu.org, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH] vpc: Implement bdrv_co_get_status()
Date: Thu, 12 Feb 2015 10:28:17 +0100	[thread overview]
Message-ID: <20150212092817.GB4189@noname.str.redhat.com> (raw)
In-Reply-To: <54DBDCFA.90000@redhat.com>

Am 11.02.2015 um 23:51 hat Max Reitz geschrieben:
> On 2015-02-11 at 11:23, Kevin Wolf wrote:
> >This implements bdrv_co_get_status() for VHD images. This can
> >significantly speed up qemu-img convert operation because only with this
> >function implemented sparseness can be considered. (Before, converting a
> >1 TB empty image took several minutes for me, now it's instantaneous.)
> >
> >Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> >---
> >  block/vpc.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
> >  1 file changed, 52 insertions(+), 2 deletions(-)
> >
> >diff --git a/block/vpc.c b/block/vpc.c
> >index 46803b1..379ff4a 100644
> >--- a/block/vpc.c
> >+++ b/block/vpc.c
> >@@ -597,6 +597,55 @@ static coroutine_fn int vpc_co_write(BlockDriverState *bs, int64_t sector_num,
> >      return ret;
> >  }
> >+static int64_t coroutine_fn vpc_co_get_block_status(BlockDriverState *bs,
> >+        int64_t sector_num, int nb_sectors, int *pnum)
> >+{
> >+    BDRVVPCState *s = bs->opaque;
> >+    VHDFooter *footer =  (VHDFooter *) s->footer_buf;
> 
> Double space before the left parenthesis.

Fun. As it happens, I copied this line from elsewhere...

> >+    int64_t start, offset;
> >+    bool allocated;
> >+    int n;
> >+
> >+    if (be32_to_cpu(footer->type) == VHD_FIXED) {
> >+        *pnum = nb_sectors;
> >+        return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_DATA |
> >+               (sector_num << BDRV_SECTOR_BITS);
> >+    }
> >+
> >+    offset = get_sector_offset(bs, sector_num, 0);
> >+
> >+    *pnum = 1;
> >+    start = offset;
> >+    allocated = (offset != -1);
> >+    nb_sectors--;
> >+
> >+    while (nb_sectors > 0) {
> >+        offset = get_sector_offset(bs, sector_num, 0);
> 
> During the first iteration, this will is exactly the function call
> as the one before this loop.
>
> >+
> >+        if ((offset != -1) != allocated) {
> >+            break;
> >+        }
> >+
> >+        if (allocated && offset != start + (*pnum * 512)) {
> 
> Therefore, if allocated is true, this check will always fail because
> offset == start.

Whoops, thanks for catching that. I'll fix it, even though it doesn't
seem to have any practicel consequences. VHD is a format braindead
enough that you never get two contiguous blocks anyway. There's always a
bitmap in between.

> >+            break;
> >+        }
> >+
> >+        /* All sectors in a block are contiguous (without using the bitmap) */
> >+        n = ROUND_UP(sector_num + 1, s->block_size / 512) - sector_num;
> >+        n = MIN(n, nb_sectors);
> 
> I think you can make use of this assumption even before calling
> get_sector_offset() in the first iteration.

Hm... Maybe I need to make it a do-while loop to get rid of some
duplication with the first iteration.

> Also, 512 is shorter than BDRV_SECTOR_SIZE and it's nice to get it
> on a single line, but I think not introducing another literal 512 in
> the code would be nicer; the same applies above in "*pnum * 512".

Fair enough.

Kevin

      reply	other threads:[~2015-02-12  9:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-11 16:23 [Qemu-devel] [PATCH] vpc: Implement bdrv_co_get_status() Kevin Wolf
2015-02-11 16:33 ` Kevin Wolf
2015-02-11 22:51 ` Max Reitz
2015-02-12  9:28   ` Kevin Wolf [this message]

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=20150212092817.GB4189@noname.str.redhat.com \
    --to=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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).