9ae3a8
From f52b3a7ce94fb9a5e6feaac513940e6f4cb95fb0 Mon Sep 17 00:00:00 2001
9ae3a8
From: Max Reitz <mreitz@redhat.com>
9ae3a8
Date: Sun, 29 Dec 2013 22:06:56 +0100
9ae3a8
Subject: [PATCH 5/8] qemu-iotests: Add test for inactive L2 overlap
9ae3a8
9ae3a8
RH-Author: Max Reitz <mreitz@redhat.com>
9ae3a8
Message-id: <1388354817-3013-5-git-send-email-mreitz@redhat.com>
9ae3a8
Patchwork-id: 56446
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH 4/5] qemu-iotests: Add test for inactive L2 overlap
9ae3a8
Bugzilla: 1004347
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
9ae3a8
BZ: 1004347
9ae3a8
9ae3a8
Extend 060 by a test which creates a corrupted image with an active L2
9ae3a8
entry pointing to an inactive L2 table and writes to the corresponding
9ae3a8
guest offset.
9ae3a8
9ae3a8
Also, use overlap-check=all for all tests in 060.
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
(cherry picked from commit 34eeb82de65ce9f83081a3357b0afe80a6a1d86a)
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
---
9ae3a8
 tests/qemu-iotests/060     | 47 +++++++++++++++++++++++++++++++++++++++-------
9ae3a8
 tests/qemu-iotests/060.out | 40 ++++++++++++++++++++++++++++++++++++++-
9ae3a8
 2 files changed, 79 insertions(+), 8 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 tests/qemu-iotests/060     |   47 +++++++++++++++++++++++++++++++++++++------
9ae3a8
 tests/qemu-iotests/060.out |   40 ++++++++++++++++++++++++++++++++++++-
9ae3a8
 2 files changed, 79 insertions(+), 8 deletions(-)
9ae3a8
9ae3a8
diff --git a/tests/qemu-iotests/060 b/tests/qemu-iotests/060
9ae3a8
index 9bbc43b..bbb1909 100644
9ae3a8
--- a/tests/qemu-iotests/060
9ae3a8
+++ b/tests/qemu-iotests/060
9ae3a8
@@ -21,10 +21,10 @@
9ae3a8
 # creator
9ae3a8
 owner=mreitz@redhat.com
9ae3a8
 
9ae3a8
-seq=`basename $0`
9ae3a8
+seq="$(basename $0)"
9ae3a8
 echo "QA output created by $seq"
9ae3a8
 
9ae3a8
-here=`pwd`
9ae3a8
+here="$PWD"
9ae3a8
 tmp=/tmp/$$
9ae3a8
 status=1	# failure is the default!
9ae3a8
 
9ae3a8
@@ -47,9 +47,15 @@ rt_offset=65536  # 0x10000 (XXX: just an assumption)
9ae3a8
 rb_offset=131072 # 0x20000 (XXX: just an assumption)
9ae3a8
 l1_offset=196608 # 0x30000 (XXX: just an assumption)
9ae3a8
 l2_offset=262144 # 0x40000 (XXX: just an assumption)
9ae3a8
+l2_offset_after_snapshot=524288 # 0x80000 (XXX: just an assumption)
9ae3a8
 
9ae3a8
 IMGOPTS="compat=1.1"
9ae3a8
 
9ae3a8
+OPEN_RW="open -o overlap-check=all $TEST_IMG"
9ae3a8
+# Overlap checks are done before write operations only, therefore opening an
9ae3a8
+# image read-only makes the overlap-check option irrelevant
9ae3a8
+OPEN_RO="open -r $TEST_IMG"
9ae3a8
+
9ae3a8
 echo
9ae3a8
 echo "=== Testing L2 reference into L1 ==="
9ae3a8
 echo
9ae3a8
@@ -65,16 +71,18 @@ _check_test_img
9ae3a8
 ./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
9ae3a8
 
9ae3a8
 # Try to write something, thereby forcing the corrupt bit to be set
9ae3a8
-$QEMU_IO -c "write -P 0x2a 0 512" "$TEST_IMG" | _filter_qemu_io
9ae3a8
+$QEMU_IO -c "$OPEN_RW" -c "write -P 0x2a 0 512" | _filter_qemu_io
9ae3a8
 
9ae3a8
 # The corrupt bit must now be set
9ae3a8
 ./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
9ae3a8
 
9ae3a8
 # Try to open the image R/W (which should fail)
9ae3a8
-$QEMU_IO -c "read 0 512" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir | _filter_imgfmt
9ae3a8
+$QEMU_IO -c "$OPEN_RW" -c "read 0 512" 2>&1 | _filter_qemu_io \
9ae3a8
+                                            | _filter_testdir \
9ae3a8
+                                            | _filter_imgfmt
9ae3a8
 
9ae3a8
 # Try to open it RO (which should succeed)
9ae3a8
-$QEMU_IO -c "read 0 512" -r "$TEST_IMG" | _filter_qemu_io
9ae3a8
+$QEMU_IO -c "$OPEN_RO" -c "read 0 512" | _filter_qemu_io
9ae3a8
 
9ae3a8
 # We could now try to fix the image, but this would probably fail (how should an
9ae3a8
 # L2 table linked onto the L1 table be fixed?)
9ae3a8
@@ -92,7 +100,7 @@ poke_file "$TEST_IMG" "$(($rb_offset+8))" "\x00\x01"
9ae3a8
 poke_file "$TEST_IMG" "$l2_offset" "\x80\x00\x00\x00\x00\x02\x00\x00"
9ae3a8
 _check_test_img
9ae3a8
 ./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
9ae3a8
-$QEMU_IO -c "write -P 0x2a 0 512" "$TEST_IMG" | _filter_qemu_io
9ae3a8
+$QEMU_IO -c "$OPEN_RW" -c "write -P 0x2a 0 512" | _filter_qemu_io
9ae3a8
 ./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
9ae3a8
 
9ae3a8
 # Try to fix it
9ae3a8
@@ -102,8 +110,33 @@ _check_test_img -r all
9ae3a8
 ./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
9ae3a8
 
9ae3a8
 # Look if it's really really fixed
9ae3a8
-$QEMU_IO -c "write -P 0x2a 0 512" "$TEST_IMG" | _filter_qemu_io
9ae3a8
+$QEMU_IO -c "$OPEN_RW" -c "write -P 0x2a 0 512" | _filter_qemu_io
9ae3a8
+./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
9ae3a8
+
9ae3a8
+echo
9ae3a8
+echo "=== Testing cluster data reference into inactive L2 table ==="
9ae3a8
+echo
9ae3a8
+_make_test_img 64M
9ae3a8
+$QEMU_IO -c "$OPEN_RW" -c "write -P 1 0 512" | _filter_qemu_io
9ae3a8
+$QEMU_IMG snapshot -c foo "$TEST_IMG"
9ae3a8
+$QEMU_IO -c "$OPEN_RW" -c "write -P 2 0 512" | _filter_qemu_io
9ae3a8
+# The inactive L2 table remains at its old offset
9ae3a8
+poke_file "$TEST_IMG" "$l2_offset_after_snapshot" \
9ae3a8
+                      "\x80\x00\x00\x00\x00\x04\x00\x00"
9ae3a8
+_check_test_img
9ae3a8
 ./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
9ae3a8
+$QEMU_IO -c "$OPEN_RW" -c "write -P 3 0 512" | _filter_qemu_io
9ae3a8
+./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
9ae3a8
+_check_test_img -r all
9ae3a8
+./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
9ae3a8
+$QEMU_IO -c "$OPEN_RW" -c "write -P 4 0 512" | _filter_qemu_io
9ae3a8
+./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
9ae3a8
+
9ae3a8
+# Check data
9ae3a8
+$QEMU_IO -c "$OPEN_RO" -c "read -P 4 0 512" | _filter_qemu_io
9ae3a8
+$QEMU_IMG snapshot -a foo "$TEST_IMG"
9ae3a8
+_check_test_img
9ae3a8
+$QEMU_IO -c "$OPEN_RO" -c "read -P 1 0 512" | _filter_qemu_io
9ae3a8
 
9ae3a8
 # success, all done
9ae3a8
 echo "*** done"
9ae3a8
diff --git a/tests/qemu-iotests/060.out b/tests/qemu-iotests/060.out
9ae3a8
index 648f743..6c7bdbb 100644
9ae3a8
--- a/tests/qemu-iotests/060.out
9ae3a8
+++ b/tests/qemu-iotests/060.out
9ae3a8
@@ -12,7 +12,6 @@ qcow2: Preventing invalid write on metadata (overlaps with active L1 table); ima
9ae3a8
 write failed: Input/output error
9ae3a8
 incompatible_features     0x2
9ae3a8
 qemu-io: can't open device TEST_DIR/t.IMGFMT: IMGFMT: Image is corrupt; cannot be opened read/write
9ae3a8
-no file open, try 'help open'
9ae3a8
 read 512/512 bytes at offset 0
9ae3a8
 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
9ae3a8
 
9ae3a8
@@ -40,4 +39,43 @@ incompatible_features     0x0
9ae3a8
 wrote 512/512 bytes at offset 0
9ae3a8
 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
9ae3a8
 incompatible_features     0x0
9ae3a8
+
9ae3a8
+=== Testing cluster data reference into inactive L2 table ===
9ae3a8
+
9ae3a8
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 
9ae3a8
+wrote 512/512 bytes at offset 0
9ae3a8
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
9ae3a8
+wrote 512/512 bytes at offset 0
9ae3a8
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
9ae3a8
+ERROR cluster 4 refcount=1 reference=2
9ae3a8
+Leaked cluster 9 refcount=1 reference=0
9ae3a8
+
9ae3a8
+1 errors were found on the image.
9ae3a8
+Data may be corrupted, or further writes to the image may corrupt it.
9ae3a8
+
9ae3a8
+1 leaked clusters were found on the image.
9ae3a8
+This means waste of disk space, but no harm to data.
9ae3a8
+incompatible_features     0x0
9ae3a8
+qcow2: Preventing invalid write on metadata (overlaps with inactive L2 table); image marked as corrupt.
9ae3a8
+write failed: Input/output error
9ae3a8
+incompatible_features     0x2
9ae3a8
+Repairing cluster 4 refcount=1 reference=2
9ae3a8
+Repairing cluster 9 refcount=1 reference=0
9ae3a8
+Repairing OFLAG_COPIED data cluster: l2_entry=8000000000040000 refcount=2
9ae3a8
+The following inconsistencies were found and repaired:
9ae3a8
+
9ae3a8
+    1 leaked clusters
9ae3a8
+    2 corruptions
9ae3a8
+
9ae3a8
+Double checking the fixed image now...
9ae3a8
+No errors were found on the image.
9ae3a8
+incompatible_features     0x0
9ae3a8
+wrote 512/512 bytes at offset 0
9ae3a8
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
9ae3a8
+incompatible_features     0x0
9ae3a8
+read 512/512 bytes at offset 0
9ae3a8
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
9ae3a8
+No errors were found on the image.
9ae3a8
+read 512/512 bytes at offset 0
9ae3a8
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
9ae3a8
 *** done
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8