qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, den@openvz.org, mreitz@redhat.com
Subject: Re: [Qemu-devel] [PATCH 6/7] block/qcow2-refcount: fix out-of-file L1 entries to be zero
Date: Tue, 19 Jun 2018 13:54:48 -0500	[thread overview]
Message-ID: <aa8426e8-2f3b-6d7f-50e3-90304ca69fbf@redhat.com> (raw)
In-Reply-To: <20180619183457.371081-7-vsementsov@virtuozzo.com>

On 06/19/2018 01:34 PM, Vladimir Sementsov-Ogievskiy wrote:
> Zero out corrupted L1 table entry, which reference L2 table out of
> underlying file.
> Zero L1 table entry means that "the L2 table and all clusters described
> by this L2 table are unallocated."
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>   block/qcow2-refcount.c | 37 +++++++++++++++++++++++++++++++++++++
>   1 file changed, 37 insertions(+)
> 
> diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
> index d993252fb6..3c9e2da39e 100644
> --- a/block/qcow2-refcount.c
> +++ b/block/qcow2-refcount.c
> @@ -1641,6 +1641,29 @@ static int fix_l2_entry_to_zero(BlockDriverState *bs, BdrvCheckResult *res,
>       return ret;
>   }
>   
> +/* Zero out L1 entry
> + *
> + * Returns: -errno if overlap check failed
> + *          0 if write failed

If the write failed, wouldn't there be an errno value worth returning?

> + *          1 on success
> + */
> +static int fix_l1_entry_to_zero(BlockDriverState *bs, BdrvCheckResult *res,
> +                                BdrvCheckMode fix, int64_t l1_offset,
> +                                int l1_index, bool active,
> +                                const char *fmt, ...)
> +{
> +    int ret;
> +    int ign = active ? QCOW2_OL_ACTIVE_L2 : QCOW2_OL_INACTIVE_L2;
> +    va_list args;
> +
> +    va_start(args, fmt);
> +    ret = fix_table_entry(bs, res, fix, "L1", l1_offset, l1_index, 0, ign,
> +                          fmt, args);
> +    va_end(args);
> +
> +    return ret;
> +}
> +
>   /*
>    * Increases the refcount in the given refcount table for the all clusters
>    * referenced in the L2 table. While doing so, performs some checks on L2
> @@ -1837,6 +1860,20 @@ static int check_refcounts_l1(BlockDriverState *bs,
>           if (l2_offset) {
>               /* Mark L2 table as used */
>               l2_offset &= L1E_OFFSET_MASK;
> +            if (l2_offset >= bdrv_getlength(bs->file->bs)) {

Again, bdrv_getlength() can fail; you want to make sure that you check 
for failures before using it in comparisons.

> +                ret = fix_l1_entry_to_zero(
> +                        bs, res, fix, l1_table_offset, i, active,
> +                        "l2 table offset out of file: offset 0x%" PRIx64,
> +                        l2_offset);
> +                if (ret < 0) {
> +                    /* Something is seriously wrong, so abort checking
> +                     * this L1 table */
> +                    goto fail;
> +                }
> +
> +                continue;
> +            }
> +
>               ret = qcow2_inc_refcounts_imrt(bs, res,
>                                              refcount_table, refcount_table_size,
>                                              l2_offset, s->cluster_size);
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

  reply	other threads:[~2018-06-19 18:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-19 18:34 [Qemu-devel] [PATCH 0/7] qcow2 check improvements Vladimir Sementsov-Ogievskiy
2018-06-19 18:34 ` [Qemu-devel] [PATCH 1/7] block/qcow2-refcount: fix check_oflag_copied Vladimir Sementsov-Ogievskiy
2018-06-19 18:34 ` [Qemu-devel] [PATCH 2/7] block/qcow2-refcount: avoid eating RAM Vladimir Sementsov-Ogievskiy
2018-06-19 18:47   ` Eric Blake
2018-06-19 18:34 ` [Qemu-devel] [PATCH 3/7] block/qcow2-refcount: check_refcounts_l2: refactor compressed case Vladimir Sementsov-Ogievskiy
2018-06-19 18:50   ` Eric Blake
2018-06-20  9:37     ` Vladimir Sementsov-Ogievskiy
2018-06-19 18:34 ` [Qemu-devel] [PATCH 4/7] block/qcow2-refcount: check_refcounts_l2: reduce ignored overlaps Vladimir Sementsov-Ogievskiy
2018-06-19 18:34 ` [Qemu-devel] [PATCH 5/7] block/qcow2-refcount: check_refcounts_l2: split fix_l2_entry_to_zero Vladimir Sementsov-Ogievskiy
2018-06-19 18:34 ` [Qemu-devel] [PATCH 6/7] block/qcow2-refcount: fix out-of-file L1 entries to be zero Vladimir Sementsov-Ogievskiy
2018-06-19 18:54   ` Eric Blake [this message]
2018-06-20  9:34     ` Vladimir Sementsov-Ogievskiy
2018-06-19 18:34 ` [Qemu-devel] [PATCH 7/7] block/qcow2-refcount: fix out-of-file L2 entries to be read-as-zero Vladimir Sementsov-Ogievskiy

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=aa8426e8-2f3b-6d7f-50e3-90304ca69fbf@redhat.com \
    --to=eblake@redhat.com \
    --cc=den@openvz.org \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.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).