All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alberto Garcia <berto@igalia.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-block@nongnu.org, Max Reitz <mreitz@redhat.com>
Subject: Re: [PATCH] qcow2: Document and enforce the QCowL2Meta invariants
Date: Wed, 07 Oct 2020 18:03:33 +0200	[thread overview]
Message-ID: <w51a6wyauqy.fsf@maestria.local.igalia.com> (raw)
In-Reply-To: <9105bbe6-dd05-4568-b2ee-9eb8f943c535@virtuozzo.com>

On Wed 07 Oct 2020 05:47:32 PM CEST, Vladimir Sementsov-Ogievskiy wrote:
> 07.10.2020 18:38, Alberto Garcia wrote:
>> On Wed 07 Oct 2020 04:42:37 PM CEST, Vladimir Sementsov-Ogievskiy wrote:
>>>>        /**
>>>> -     * The COW Region between the start of the first allocated cluster and the
>>>> -     * area the guest actually writes to.
>>>> +     * The COW Region immediately before the area the guest actually
>>>> +     * writes to. This (part of the) write request starts at
>>>> +     * cow_start.offset + cow_start.nb_bytes.
>>>
>>> "starts at" is a bit misleading.. As here is not guest offset, not
>>> host offset, but offset relative to QCowL2Meta.offset
>> 
>> I thought it was clear by the context since Qcow2COWRegion.offset is
>> defined to be relative to QCowL2Meta.offset
>> 
>>>> @@ -1049,6 +1049,8 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m)
>>>>        qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_slice);
>>>>    
>>>>        assert(l2_index + m->nb_clusters <= s->l2_slice_size);
>>>> +    assert(m->cow_end.offset + m->cow_end.nb_bytes <=
>>>> +           m->nb_clusters << s->cluster_bits);
>>>
>>> should we also assert that cow_end.offset + cow_end.nb_bytes is not
>>> zero?
>> 
>> No, a write request that fills a complete cluster has no COW but still
>> needs to call qcow2_alloc_cluster_link_l2() to update the L2 metadata.
>
> but cow_end.offset will not be zero still? I suggest it because you
> actually rely on this fact by dropping written_to conditional
> assignment.

No, cow_end.offset must not be 0 but the offset where the data region
ends, this is already enforced by this assertion in perform_cow():

    assert(start->offset + start->nb_bytes <= end->offset);

And it is explicitly mentioned in the commit message:

    Even when those regions themselves are empty their offsets must be
    correct because they are used to know the location of the middle
    region.

and also in qcow2.h:

  /**
   * The COW Region immediately after the area the guest actually
   * writes to. This (part of the) write request ends at cow_end.offset
   * (which must always be set even when cow_end.nb_bytes is 0).
   */
  Qcow2COWRegion cow_end;

Berto


      reply	other threads:[~2020-10-07 16:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-07 11:52 [PATCH] qcow2: Document and enforce the QCowL2Meta invariants Alberto Garcia
2020-10-07 14:34 ` Eric Blake
2020-10-07 14:42 ` Vladimir Sementsov-Ogievskiy
2020-10-07 15:38   ` Alberto Garcia
2020-10-07 15:47     ` Vladimir Sementsov-Ogievskiy
2020-10-07 16:03       ` Alberto Garcia [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=w51a6wyauqy.fsf@maestria.local.igalia.com \
    --to=berto@igalia.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.