qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] qcow2-refcount: Snapshot update for zero clusters
Date: Thu, 29 Aug 2013 14:38:43 +0200	[thread overview]
Message-ID: <521F40D3.8000302@redhat.com> (raw)
In-Reply-To: <20130829123343.GH2961@dhcp-200-207.str.redhat.com>

Am 29.08.2013 14:33, schrieb Kevin Wolf:
> Am 29.08.2013 um 12:16 hat Max Reitz geschrieben:
>> Do not try to update the refcount for zero clusters in
>> qcow2_update_snapshot_refcount.
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>>   block/qcow2-refcount.c | 16 +++++++++++++---
>>   1 file changed, 13 insertions(+), 3 deletions(-)
> Please don't forget to add a test case for v2.
Okay.

>> diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
>> index 1244693..7555242 100644
>> --- a/block/qcow2-refcount.c
>> +++ b/block/qcow2-refcount.c
>> @@ -863,9 +863,13 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
>>               for(j = 0; j < s->l2_size; j++) {
>>                   offset = be64_to_cpu(l2_table[j]);
>>                   if (offset != 0) {
>> +                    uint64_t cluster_index;
>> +
>>                       old_offset = offset;
>>                       offset &= ~QCOW_OFLAG_COPIED;
>> -                    if (offset & QCOW_OFLAG_COMPRESSED) {
>> +
>> +                    switch (qcow2_get_cluster_type(offset)) {
>> +                    case QCOW2_CLUSTER_COMPRESSED:
>>                           nb_csectors = ((offset >> s->csize_shift) &
>>                                          s->csize_mask) + 1;
>>                           if (addend != 0) {
>> @@ -880,8 +884,10 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
>>                           }
>>                           /* compressed clusters are never modified */
>>                           refcount = 2;
>> -                    } else {
>> -                        uint64_t cluster_index = (offset & L2E_OFFSET_MASK) >> s->cluster_bits;
>> +                        break;
>> +
>> +                    case QCOW2_CLUSTER_NORMAL:
>> +                        cluster_index = (offset & L2E_OFFSET_MASK) >> s->cluster_bits;
>>                           if (addend != 0) {
>>                               refcount = update_cluster_refcount(bs, cluster_index, addend,
>>                                                                  QCOW2_DISCARD_SNAPSHOT);
>> @@ -893,6 +899,10 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
>>                               ret = refcount;
>>                               goto fail;
>>                           }
>> +                        break;
> I think this part isn't quite right. Even zero clusters can have an
> allocated offset, so I think what's really needed is that the same code
> runs from QCOW2_CLUSTER_ZERO. However, add an if (cluster_index == 0)
> case for the unallocated case.
So then it would be enough to change:

- if (offset != 0) {
+ if ((offset & L2E_OFFSET_MASK) != 0) {

and just execute the same code for QCOW2_CLUSTER_NORMAL and 
QCOW2_CLUSTER_ZERO?

>> +
>> +                    default:
>> +                        refcount = 0;
> Other places enumerate the enum values explicitly and have a default
> label that simply abort()s. This will help catching forgotten places
> when a new value is added.
Okay.

>>                       }
>>   
>>                       if (refcount == 1) {
> Kevin
Max

  reply	other threads:[~2013-08-29 12:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-29 10:16 [Qemu-devel] [PATCH] qcow2-refcount: Snapshot update for zero clusters Max Reitz
2013-08-29 12:30 ` Eric Blake
2013-08-29 12:35   ` Max Reitz
2013-08-29 12:33 ` Kevin Wolf
2013-08-29 12:38   ` Max Reitz [this message]
2013-08-29 12:53     ` Kevin Wolf
2013-08-29 12:56       ` Max Reitz
2013-08-29 13:04         ` Kevin Wolf
2013-08-29 13:06           ` Max Reitz

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=521F40D3.8000302@redhat.com \
    --to=mreitz@redhat.com \
    --cc=kwolf@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).