yeahuh / rpms / qemu-kvm

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