From: Eric Blake <eblake@redhat.com>
To: "Denis V. Lunev" <den@openvz.org>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 5/5] qcow2: merge is_zero_cluster helpers into qcow2_co_write_zeroes
Date: Tue, 24 May 2016 12:14:03 -0600 [thread overview]
Message-ID: <574499EB.6050905@redhat.com> (raw)
In-Reply-To: <1463476543-3087-6-git-send-email-den@openvz.org>
[-- Attachment #1: Type: text/plain, Size: 2469 bytes --]
On 05/17/2016 03:15 AM, Denis V. Lunev wrote:
> They are used once only. This makes code more compact.
>
> The patch also improves comments in the code.
>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Kevin Wolf <kwolf@redhat.com>
> ---
> block/qcow2.c | 39 +++++++++++++++------------------------
> 1 file changed, 15 insertions(+), 24 deletions(-)
>
> @@ -2439,20 +2418,32 @@ static coroutine_fn int qcow2_co_write_zeroes(BlockDriverState *bs,
> nb_sectors);
>
> if (head != 0 || tail != 0) {
> - int64_t cl_start = sector_num - head;
> + BlockDriverState *file;
> + uint64_t off;
> + int nr;
> +
> + int64_t cl_start = sector_num - head, res;
>
> assert(cl_start + s->cluster_sectors >= sector_num + nb_sectors);
>
> sector_num = cl_start;
> nb_sectors = s->cluster_sectors;
>
> - if (!is_zero_cluster(bs, sector_num)) {
> + /* check that the cluster is zeroed taking into account entire
> + backing chain */
> + nr = s->cluster_sectors;
> + res = bdrv_get_block_status_above(bs, NULL, cl_start,
> + s->cluster_sectors, &nr, &file);
> + if (res < 0 || !(res & BDRV_BLOCK_ZERO)) {
> return -ENOTSUP;
> }
This is somewhat pessimistic in certain cases. Suppose I have the
following cluster (borrowing from Kevin's nice notation in 154):
4k: -- -- XX --
and issue a 'write -z 2k 1k'
As written, the code will see that bdrv_get_block_status_above() does
NOT have all ZERO for the cluster, so it will return -ENOTSUP; we will
then call into the fallbacks and write explicit zeroes, so that the top
file now has an allocated cluster full of zero. But if we were a bit
smarter, we would only check the allocation status of the backing
sectors that do not overlap with our write_zeroes request, because the
remaining sectors are about to be overwritten; in this case, we can
specifically optimize to write a zero cluster without allocation.
You'll also need to rebase this series on top of my pending work to
rewrite bdrv_co_write_zeroes to instead be bdrv_co_pwrite_zeroes with a
byte interface (patches to be posted later today), if mine gets reviewed
first.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2016-05-24 18:14 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-17 9:15 [Qemu-devel] [PATCH v2 0/5] qcow2_co_write_zeroes and related improvements Denis V. Lunev
2016-05-17 9:15 ` [Qemu-devel] [PATCH 1/5] block: split write_zeroes always Denis V. Lunev
2016-05-17 16:34 ` Kevin Wolf
2016-05-25 18:36 ` Eric Blake
2016-05-17 9:15 ` [Qemu-devel] [PATCH 2/5] qcow2: simplify logic in qcow2_co_write_zeroes Denis V. Lunev
2016-05-17 9:15 ` [Qemu-devel] [PATCH 3/5] qcow2: add tracepoints for qcow2_co_write_zeroes Denis V. Lunev
2016-05-17 15:37 ` Eric Blake
2016-05-17 9:15 ` [Qemu-devel] [PATCH 4/5] qcow2: fix condition in is_zero_cluster Denis V. Lunev
2016-05-17 15:11 ` Kevin Wolf
2016-05-17 9:15 ` [Qemu-devel] [PATCH 5/5] qcow2: merge is_zero_cluster helpers into qcow2_co_write_zeroes Denis V. Lunev
2016-05-24 18:14 ` Eric Blake [this message]
2016-05-17 15:11 ` [Qemu-devel] [PATCH v2 0/5] qcow2_co_write_zeroes and related improvements Kevin Wolf
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=574499EB.6050905@redhat.com \
--to=eblake@redhat.com \
--cc=den@openvz.org \
--cc=kwolf@redhat.com \
--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).