All of lore.kernel.org
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>
Subject: [PATCH v3 09/16] qcow2: Add qcow2_check_fix_snapshot_table()
Date: Fri, 11 Oct 2019 17:28:07 +0200	[thread overview]
Message-ID: <20191011152814.14791-10-mreitz@redhat.com> (raw)
In-Reply-To: <20191011152814.14791-1-mreitz@redhat.com>

qcow2_check_read_snapshot_table() can perform consistency checks, but it
cannot fix everything.  Specifically, it cannot allocate new clusters,
because that should wait until the refcount structures are known to be
consistent (i.e., after qcow2_check_refcounts()).  Thus, it cannot call
qcow2_write_snapshots().

Do that in qcow2_check_fix_snapshot_table(), which is called after
qcow2_check_refcounts().

Currently, there is nothing that would set result->corruptions, so this
is a no-op.  A follow-up patch will change that.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 block/qcow2.h          |  3 +++
 block/qcow2-snapshot.c | 25 +++++++++++++++++++++++++
 block/qcow2.c          |  9 ++++++++-
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/block/qcow2.h b/block/qcow2.h
index 6c2a38c98d..b6125899b8 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -719,6 +719,9 @@ int qcow2_write_snapshots(BlockDriverState *bs);
 int coroutine_fn qcow2_check_read_snapshot_table(BlockDriverState *bs,
                                                  BdrvCheckResult *result,
                                                  BdrvCheckMode fix);
+int coroutine_fn qcow2_check_fix_snapshot_table(BlockDriverState *bs,
+                                                BdrvCheckResult *result,
+                                                BdrvCheckMode fix);
 
 /* qcow2-cache.c functions */
 Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables,
diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
index d667bfd935..b526a8f819 100644
--- a/block/qcow2-snapshot.c
+++ b/block/qcow2-snapshot.c
@@ -380,6 +380,31 @@ int coroutine_fn qcow2_check_read_snapshot_table(BlockDriverState *bs,
     return 0;
 }
 
+int coroutine_fn qcow2_check_fix_snapshot_table(BlockDriverState *bs,
+                                                BdrvCheckResult *result,
+                                                BdrvCheckMode fix)
+{
+    BDRVQcow2State *s = bs->opaque;
+    int ret;
+
+    if (result->corruptions && (fix & BDRV_FIX_ERRORS)) {
+        qemu_co_mutex_unlock(&s->lock);
+        ret = qcow2_write_snapshots(bs);
+        qemu_co_mutex_lock(&s->lock);
+        if (ret < 0) {
+            result->check_errors++;
+            fprintf(stderr, "ERROR failed to update snapshot table: %s\n",
+                    strerror(-ret));
+            return ret;
+        }
+
+        result->corruptions_fixed += result->corruptions;
+        result->corruptions = 0;
+    }
+
+    return 0;
+}
+
 static void find_new_snapshot_id(BlockDriverState *bs,
                                  char *id_str, int id_str_size)
 {
diff --git a/block/qcow2.c b/block/qcow2.c
index 7f47444ab7..c8b3726dff 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -597,13 +597,20 @@ static int coroutine_fn qcow2_co_check_locked(BlockDriverState *bs,
     memset(result, 0, sizeof(*result));
 
     ret = qcow2_check_read_snapshot_table(bs, &snapshot_res, fix);
-    qcow2_add_check_result(result, &snapshot_res, false);
     if (ret < 0) {
+        qcow2_add_check_result(result, &snapshot_res, false);
         return ret;
     }
 
     ret = qcow2_check_refcounts(bs, &refcount_res, fix);
     qcow2_add_check_result(result, &refcount_res, true);
+    if (ret < 0) {
+        qcow2_add_check_result(result, &snapshot_res, false);
+        return ret;
+    }
+
+    ret = qcow2_check_fix_snapshot_table(bs, &snapshot_res, fix);
+    qcow2_add_check_result(result, &snapshot_res, false);
     if (ret < 0) {
         return ret;
     }
-- 
2.21.0



  parent reply	other threads:[~2019-10-11 15:40 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-11 15:27 [PATCH v3 00/16] qcow2: Let check -r all repair some snapshot bits Max Reitz
2019-10-11 15:27 ` [PATCH v3 01/16] include: Move endof() up from hw/virtio/virtio.h Max Reitz
2019-10-11 15:28 ` [PATCH v3 02/16] qcow2: Use endof() Max Reitz
2019-10-11 15:28 ` [PATCH v3 03/16] qcow2: Add Error ** to qcow2_read_snapshots() Max Reitz
2019-10-11 15:28 ` [PATCH v3 04/16] qcow2: Keep unknown extra snapshot data Max Reitz
2019-10-11 16:20   ` Eric Blake
2019-10-14  8:46     ` Max Reitz
2019-10-11 15:28 ` [PATCH v3 05/16] qcow2: Make qcow2_write_snapshots() public Max Reitz
2019-10-11 15:28 ` [PATCH v3 06/16] qcow2: Put qcow2_upgrade() into its own function Max Reitz
2019-10-11 15:28 ` [PATCH v3 07/16] qcow2: Write v3-compliant snapshot list on upgrade Max Reitz
2019-10-11 16:23   ` Eric Blake
2019-10-14  8:45     ` Max Reitz
2019-10-14 13:53       ` Eric Blake
2019-10-14 14:09         ` Max Reitz
2019-10-11 15:28 ` [PATCH v3 08/16] qcow2: Separate qcow2_check_read_snapshot_table() Max Reitz
2019-10-11 15:28 ` Max Reitz [this message]
2019-10-11 15:28 ` [PATCH v3 10/16] qcow2: Fix broken snapshot table entries Max Reitz
2019-10-11 15:28 ` [PATCH v3 11/16] qcow2: Keep track of the snapshot table length Max Reitz
2019-10-11 15:28 ` [PATCH v3 12/16] qcow2: Fix overly long snapshot tables Max Reitz
2019-10-11 15:28 ` [PATCH v3 13/16] qcow2: Repair snapshot table with too many entries Max Reitz
2019-10-11 16:31   ` Eric Blake
2019-10-11 15:28 ` [PATCH v3 14/16] qcow2: Fix v3 snapshot table entry compliancy Max Reitz
2019-10-11 16:32   ` Eric Blake
2019-10-11 15:28 ` [PATCH v3 15/16] iotests: Add peek_file* functions Max Reitz
2019-10-11 15:28 ` [PATCH v3 16/16] iotests: Test qcow2's snapshot table handling Max Reitz
2019-10-28 10:55 ` [PATCH v3 00/16] qcow2: Let check -r all repair some snapshot bits 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=20191011152814.14791-10-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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.