All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, stefanha@gmail.com, qemu-devel@nongnu.org,
	hahn@univention.de
Subject: [Qemu-devel] [PATCH 0.15.0] qcow2: Fix L1 table size after bdrv_snapshot_goto
Date: Thu,  4 Aug 2011 18:17:53 +0200	[thread overview]
Message-ID: <1312474673-2705-1-git-send-email-kwolf@redhat.com> (raw)

When loading an internal snapshot whose L1 table is smaller than the current L1
table, the size of the current L1 would be shrunk to the snapshot's L1 size in
memory, but not on disk. This lead to incorrect refcount updates and eventuelly
to image corruption.

Instead of writing the new L1 size to disk, this simply retains the bigger L1
size that is currently in use and makes sure that the unused part is zeroed.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---

Philipp, I think this should fix your corruption. Please give it a try.

Anthony, this must go into 0.15. Given the short time until -rc2, do you prefer
to pick it up directly or should I send a pull request tomorrow? The patch
looks obvious, is tested with the given testcase and survives a basic
qemu-iotests run (though qemu-iotests doesn't exercise snapshots a lot)

Stefan, please review :-)

 block/qcow2-snapshot.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
index 74823a5..4a8868a 100644
--- a/block/qcow2-snapshot.c
+++ b/block/qcow2-snapshot.c
@@ -330,8 +330,9 @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
     if (qcow2_grow_l1_table(bs, sn->l1_size, true) < 0)
         goto fail;
 
-    s->l1_size = sn->l1_size;
+    memset(s->l1_table + sn->l1_size, 0, s->l1_size - sn->l1_size);
     l1_size2 = s->l1_size * sizeof(uint64_t);
+
     /* copy the snapshot l1 table to the current l1 table */
     if (bdrv_pread(bs->file, sn->l1_table_offset,
                    s->l1_table, l1_size2) != l1_size2)
-- 
1.7.6

             reply	other threads:[~2011-08-04 16:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Message-Id: <1312474673-2705-1-git-send-email-kwolf@redhat.com>
2011-08-04 16:17 ` Kevin Wolf [this message]
2011-08-04 16:24 ` [Qemu-devel] [PATCH v2 0.15.0] qcow2: Fix L1 table size after bdrv_snapshot_goto Kevin Wolf
2011-08-04 17:19   ` Philipp Hahn
2011-08-05  6:35   ` Frediano Ziglio
2011-08-05  7:51     ` Kevin Wolf
2011-08-05  8:28       ` Frediano Ziglio
2011-08-05  9:37         ` Frediano Ziglio

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=1312474673-2705-1-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=hahn@univention.de \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.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.