qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] qcow2: Fix write/copy error path with data file
@ 2020-02-11  9:48 Kevin Wolf
  2020-02-11  9:48 ` [PATCH 1/3] qcow2: update_refcount(): Reset old_table_index after qcow2_cache_put() Kevin Wolf
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Kevin Wolf @ 2020-02-11  9:48 UTC (permalink / raw)
  To: qemu-block; +Cc: kwolf, pbutsykin, jsnow, qemu-devel, mreitz

Kevin Wolf (3):
  qcow2: update_refcount(): Reset old_table_index after
    qcow2_cache_put()
  qcow2: Fix qcow2_alloc_cluster_abort() for external data file
  iotests: Test copy offloading with external data file

 block/qcow2-cluster.c      |  7 +++++--
 block/qcow2-refcount.c     |  1 +
 tests/qemu-iotests/244     | 14 ++++++++++++++
 tests/qemu-iotests/244.out |  6 ++++++
 4 files changed, 26 insertions(+), 2 deletions(-)

-- 
2.20.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] qcow2: update_refcount(): Reset old_table_index after qcow2_cache_put()
  2020-02-11  9:48 [PATCH 0/3] qcow2: Fix write/copy error path with data file Kevin Wolf
@ 2020-02-11  9:48 ` Kevin Wolf
  2020-02-11  9:48 ` [PATCH 2/3] qcow2: Fix qcow2_alloc_cluster_abort() for external data file Kevin Wolf
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Kevin Wolf @ 2020-02-11  9:48 UTC (permalink / raw)
  To: qemu-block; +Cc: kwolf, pbutsykin, jsnow, qemu-devel, mreitz

In the case that update_refcount() frees a refcount block, it evicts it
from the metadata cache. Before doing so, however, it returns the
currently used refcount block to the cache because it might be the same.
Returning the refcount block early means that we need to reset
old_table_index so that we reload the refcount block in the next
iteration if it is actually still in use.

Fixes: f71c08ea8e60f035485a512fd2af8908567592f0
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/qcow2-refcount.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index f67ac6b2d8..b06a9fa9ce 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -889,6 +889,7 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,
                                                 offset);
             if (table != NULL) {
                 qcow2_cache_put(s->refcount_block_cache, &refcount_block);
+                old_table_index = -1;
                 qcow2_cache_discard(s->refcount_block_cache, table);
             }
 
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] qcow2: Fix qcow2_alloc_cluster_abort() for external data file
  2020-02-11  9:48 [PATCH 0/3] qcow2: Fix write/copy error path with data file Kevin Wolf
  2020-02-11  9:48 ` [PATCH 1/3] qcow2: update_refcount(): Reset old_table_index after qcow2_cache_put() Kevin Wolf
@ 2020-02-11  9:48 ` Kevin Wolf
  2020-02-11  9:49 ` [PATCH 3/3] iotests: Test copy offloading with " Kevin Wolf
  2020-02-14 13:22 ` [PATCH 0/3] qcow2: Fix write/copy error path with " Kevin Wolf
  3 siblings, 0 replies; 5+ messages in thread
From: Kevin Wolf @ 2020-02-11  9:48 UTC (permalink / raw)
  To: qemu-block; +Cc: kwolf, pbutsykin, jsnow, qemu-devel, mreitz

For external data file, cluster allocations return an offset in the data
file and are not refcounted. In this case, there is nothing to do for
qcow2_alloc_cluster_abort(). Freeing the same offset in the qcow2 file
is wrong and causes crashes in the better case or image corruption in
the worse case.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/qcow2-cluster.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 8982b7b762..dc3c270226 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -1015,8 +1015,11 @@ err:
 void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m)
 {
     BDRVQcow2State *s = bs->opaque;
-    qcow2_free_clusters(bs, m->alloc_offset, m->nb_clusters << s->cluster_bits,
-                        QCOW2_DISCARD_NEVER);
+    if (!has_data_file(bs)) {
+        qcow2_free_clusters(bs, m->alloc_offset,
+                            m->nb_clusters << s->cluster_bits,
+                            QCOW2_DISCARD_NEVER);
+    }
 }
 
 /*
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] iotests: Test copy offloading with external data file
  2020-02-11  9:48 [PATCH 0/3] qcow2: Fix write/copy error path with data file Kevin Wolf
  2020-02-11  9:48 ` [PATCH 1/3] qcow2: update_refcount(): Reset old_table_index after qcow2_cache_put() Kevin Wolf
  2020-02-11  9:48 ` [PATCH 2/3] qcow2: Fix qcow2_alloc_cluster_abort() for external data file Kevin Wolf
@ 2020-02-11  9:49 ` Kevin Wolf
  2020-02-14 13:22 ` [PATCH 0/3] qcow2: Fix write/copy error path with " Kevin Wolf
  3 siblings, 0 replies; 5+ messages in thread
From: Kevin Wolf @ 2020-02-11  9:49 UTC (permalink / raw)
  To: qemu-block; +Cc: kwolf, pbutsykin, jsnow, qemu-devel, mreitz

This adds a test for 'qemu-img convert' with copy offloading where the
target image has an external data file. If the test hosts supports it,
it tests both the case where copy offloading is supported and the case
where it isn't (otherwise we just test unsupported twice).

More specifically, the case with unsupported copy offloading tests
qcow2_alloc_cluster_abort() with external data files.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 tests/qemu-iotests/244     | 14 ++++++++++++++
 tests/qemu-iotests/244.out |  6 ++++++
 2 files changed, 20 insertions(+)

diff --git a/tests/qemu-iotests/244 b/tests/qemu-iotests/244
index 0d1efee6ef..2ec1815e6f 100755
--- a/tests/qemu-iotests/244
+++ b/tests/qemu-iotests/244
@@ -197,6 +197,20 @@ $QEMU_IO -c 'read -P 0x11 0 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
 $QEMU_IMG map --output=human "$TEST_IMG" | _filter_testdir
 $QEMU_IMG map --output=json "$TEST_IMG"
 
+echo
+echo "=== Copy offloading ==="
+echo
+
+# Make use of copy offloading if the test host can provide it
+_make_test_img -o "data_file=$TEST_IMG.data" 64M
+$QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n -C "$TEST_IMG.src" "$TEST_IMG"
+$QEMU_IMG compare -f $IMGFMT -F $IMGFMT "$TEST_IMG.src" "$TEST_IMG"
+
+# blkdebug doesn't support copy offloading, so this tests the error path
+$QEMU_IMG amend -f $IMGFMT -o "data_file=blkdebug::$TEST_IMG.data" "$TEST_IMG"
+$QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n -C "$TEST_IMG.src" "$TEST_IMG"
+$QEMU_IMG compare -f $IMGFMT -F $IMGFMT "$TEST_IMG.src" "$TEST_IMG"
+
 # success, all done
 echo "*** done"
 rm -f $seq.full
diff --git a/tests/qemu-iotests/244.out b/tests/qemu-iotests/244.out
index 6a3d0067cc..e6f4dc7993 100644
--- a/tests/qemu-iotests/244.out
+++ b/tests/qemu-iotests/244.out
@@ -122,4 +122,10 @@ Offset          Length          Mapped to       File
 0               0x100000        0               TEST_DIR/t.qcow2.data
 [{ "start": 0, "length": 1048576, "depth": 0, "zero": false, "data": true, "offset": 0},
 { "start": 1048576, "length": 66060288, "depth": 0, "zero": true, "data": false}]
+
+=== Copy offloading ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 data_file=TEST_DIR/t.IMGFMT.data
+Images are identical.
+Images are identical.
 *** done
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] qcow2: Fix write/copy error path with data file
  2020-02-11  9:48 [PATCH 0/3] qcow2: Fix write/copy error path with data file Kevin Wolf
                   ` (2 preceding siblings ...)
  2020-02-11  9:49 ` [PATCH 3/3] iotests: Test copy offloading with " Kevin Wolf
@ 2020-02-14 13:22 ` Kevin Wolf
  3 siblings, 0 replies; 5+ messages in thread
From: Kevin Wolf @ 2020-02-14 13:22 UTC (permalink / raw)
  To: qemu-block; +Cc: pbutsykin, jsnow, qemu-devel, mreitz

Am 11.02.2020 um 10:48 hat Kevin Wolf geschrieben:
> Kevin Wolf (3):
>   qcow2: update_refcount(): Reset old_table_index after
>     qcow2_cache_put()
>   qcow2: Fix qcow2_alloc_cluster_abort() for external data file
>   iotests: Test copy offloading with external data file

Applied to the block branch.

Kevin



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-02-14 13:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-11  9:48 [PATCH 0/3] qcow2: Fix write/copy error path with data file Kevin Wolf
2020-02-11  9:48 ` [PATCH 1/3] qcow2: update_refcount(): Reset old_table_index after qcow2_cache_put() Kevin Wolf
2020-02-11  9:48 ` [PATCH 2/3] qcow2: Fix qcow2_alloc_cluster_abort() for external data file Kevin Wolf
2020-02-11  9:49 ` [PATCH 3/3] iotests: Test copy offloading with " Kevin Wolf
2020-02-14 13:22 ` [PATCH 0/3] qcow2: Fix write/copy error path with " Kevin Wolf

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).