From: Stefan Hajnoczi <stefanha@redhat.com>
To: Peter Lieven <pl@kamp.de>
Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [RFC][PATCH] qemu-img: add support for skipping zeroes in input during convert
Date: Mon, 2 Dec 2013 15:13:36 +0100 [thread overview]
Message-ID: <20131202141336.GC28132@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <1385131710-8978-1-git-send-email-pl@kamp.de>
On Fri, Nov 22, 2013 at 03:48:30PM +0100, Peter Lieven wrote:
> - /* If the output image is being created as a copy on write image,
> - assume that sectors which are unallocated in the input image
> - are present in both the output's and input's base images (no
> - need to copy them). */
> - if (out_baseimg) {
> - ret = bdrv_is_allocated(bs[bs_i], sector_num - bs_offset,
> - n, &n1);
int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num,
int nb_sectors, int *pnum)
{
int64_t ret = bdrv_get_block_status(bs, sector_num, nb_sectors, pnum);
if (ret < 0) {
return ret;
}
return
(ret & BDRV_BLOCK_DATA) ||
((ret & BDRV_BLOCK_ZERO) && !bdrv_has_zero_init(bs));
}
bdrv_has_zero_init() returns false when bs->backing_hd != NULL.
> + if (out_baseimg || has_zero_init) {
> + n = nb_sectors > INT_MAX ? INT_MAX : nb_sectors;
> + ret = bdrv_get_block_status(bs[bs_i], sector_num - bs_offset,
> + n, &n1);
> if (ret < 0) {
> - error_report("error while reading metadata for sector "
> - "%" PRId64 ": %s",
> + error_report("error while reading block status of sector %" PRId64 ": %s",
> sector_num - bs_offset, strerror(-ret));
> goto out;
> }
> - if (!ret) {
> + /* If the output image is zero initialized, we are not working
> + * on a shared base and the input is zero we can skip the next
> + * n1 bytes */
> + if (!out_baseimg && has_zero_init && ret & BDRV_BLOCK_ZERO) {
> + sector_num += n1;
> + continue;
> + }
> + /* If the output image is being created as a copy on write image,
> + assume that sectors which are unallocated in the input image
> + are present in both the output's and input's base images (no
> + need to copy them). */
> + if (out_baseimg && !(ret & BDRV_BLOCK_DATA)) {
> sector_num += n1;
> continue;
> }
How are these two if statements different from bdrv_is_allocated()?
Stefan
next prev parent reply other threads:[~2013-12-02 14:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-22 14:48 [Qemu-devel] [RFC][PATCH] qemu-img: add support for skipping zeroes in input during convert Peter Lieven
2013-12-02 14:13 ` Stefan Hajnoczi [this message]
2013-12-02 14:15 ` Peter Lieven
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=20131202141336.GC28132@stefanha-thinkpad.redhat.com \
--to=stefanha@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=pl@kamp.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).