qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Max Reitz <mreitz@redhat.com>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v14 03/14] qcow2: Optimize bdrv_make_empty()
Date: Fri, 24 Oct 2014 08:33:14 -0600	[thread overview]
Message-ID: <544A632A.30504@redhat.com> (raw)
In-Reply-To: <1414159063-25977-4-git-send-email-mreitz@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2991 bytes --]

On 10/24/2014 07:57 AM, Max Reitz wrote:
> bdrv_make_empty() is currently only called if the current image
> represents an external snapshot that has been committed to its base
> image; it is therefore unlikely to have internal snapshots. In this
> case, bdrv_make_empty() can be greatly sped up by emptying the L1 and
> refcount table (while having the dirty flag set, which only works for
> compat=1.1) and creating a trivial refcount structure.
> 
> If there are snapshots or for compat=0.10, fall back to the simple
> implementation (discard all clusters).
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  block/blkdebug.c      |   2 +
>  block/qcow2.c         | 165 +++++++++++++++++++++++++++++++++++++++++++++++++-
>  include/block/block.h |   2 +
>  3 files changed, 168 insertions(+), 1 deletion(-)
> 

Looks like you resolved Kevin's review points correctly (I'm trusting
his judgment here).


>  static int qcow2_make_empty(BlockDriverState *bs)
>  {
> -    int ret = 0;
> +    BDRVQcowState *s = bs->opaque;
>      uint64_t start_sector;
>      int sector_step = INT_MAX / BDRV_SECTOR_SIZE;
> +    int l1_clusters, ret = 0;
> +
> +    l1_clusters = DIV_ROUND_UP(s->l1_size, s->cluster_size / sizeof(uint64_t));
> +
> +    if (s->qcow_version >= 3 && !s->snapshots &&
> +        3 + l1_clusters <= s->refcount_block_size) {
> +        /* The following function only works for qcow2 v3 images (it requires
> +         * the dirty flag) and only as long as there are no snapshots (because
> +         * it completely empties the image). Furthermore, the L1 table and three
> +         * additional clusters (image header, refcount table, one refcount
> +         * block) have to fit inside one refcount block. */
> +        return make_completely_empty(bs);
> +    }

Is there ever a situation where if make_completely_empty() fails, you
can still safely fall back to the slower loop code?  For example,
failure to do qcow2_cache_empty() at the very beginning might still be
recoverable (basically, anywhere that did 'goto fail' instead of 'goto
fail_broken_refcounts' might have a chance at the fallback working).
But I'm okay with declaring all errors as fatal to the attempt, rather
than trying to figure out which errors are worth still trying the
fallback (especially since most errors are going to be caused by OOM or
file I/O error, and those are likely to still be triggered again during
fallback).

>  
> +    /* This fallback code simply discards every active clusters; this is slow,

s/clusters/cluster/

> +     * but works in all cases */
>      for (start_sector = 0; start_sector < bs->total_sectors;
>           start_sector += sector_step)
>      {

With the comment typo fixed (the maintainer could do that without
needing a v15):
Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
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: 539 bytes --]

  reply	other threads:[~2014-10-24 14:33 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-24 13:57 [Qemu-devel] [PATCH v14 00/14] qemu-img: Implement commit like QMP Max Reitz
2014-10-24 13:57 ` [Qemu-devel] [PATCH v14 01/14] qcow2: Allow "full" discard Max Reitz
2014-10-24 13:57 ` [Qemu-devel] [PATCH v14 02/14] qcow2: Implement bdrv_make_empty() Max Reitz
2014-10-24 13:57 ` [Qemu-devel] [PATCH v14 03/14] qcow2: Optimize bdrv_make_empty() Max Reitz
2014-10-24 14:33   ` Eric Blake [this message]
2014-10-24 13:57 ` [Qemu-devel] [PATCH v14 04/14] blockjob: Introduce block_job_complete_sync() Max Reitz
2014-10-24 13:57 ` [Qemu-devel] [PATCH v14 05/14] blockjob: Add "ready" field Max Reitz
2014-10-24 13:57 ` [Qemu-devel] [PATCH v14 06/14] iotests: Omit length/offset test in 040 and 041 Max Reitz
2014-10-24 15:14   ` Eric Blake
2014-10-24 13:57 ` [Qemu-devel] [PATCH v14 07/14] block/mirror: Improve progress report Max Reitz
2014-10-24 13:57 ` [Qemu-devel] [PATCH v14 08/14] qemu-img: Implement commit like QMP Max Reitz
2014-10-24 16:08   ` Eric Blake
2014-10-24 13:57 ` [Qemu-devel] [PATCH v14 09/14] qemu-img: Empty image after commit Max Reitz
2014-10-24 13:57 ` [Qemu-devel] [PATCH v14 10/14] qemu-img: Enable progress output for commit Max Reitz
2014-10-24 13:57 ` [Qemu-devel] [PATCH v14 11/14] qemu-img: Specify backing file " Max Reitz
2014-10-24 16:23   ` Eric Blake
2014-10-27  9:11     ` Max Reitz
2014-10-24 13:57 ` [Qemu-devel] [PATCH v14 12/14] iotests: Add _filter_qemu_img_map Max Reitz
2014-10-24 13:57 ` [Qemu-devel] [PATCH v14 13/14] iotests: Add test for backing-chain commits Max Reitz
2014-10-24 13:57 ` [Qemu-devel] [PATCH v14 14/14] iotests: Add test for qcow2's bdrv_make_empty Max Reitz
2014-10-24 16:31   ` Eric Blake
2014-10-27  8:06     ` Max Reitz
2014-10-27 15:44       ` Eric Blake
2014-10-28 10:38 ` [Qemu-devel] [PATCH v14 00/14] qemu-img: Implement commit like QMP Kevin Wolf
2014-10-29 10:25 ` Stefan Hajnoczi

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=544A632A.30504@redhat.com \
    --to=eblake@redhat.com \
    --cc=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).