Skip to content

Commit 34eeb82

Browse files
XanClickevmw
authored andcommitted
qemu-iotests: Add test for inactive L2 overlap
Extend 060 by a test which creates a corrupted image with an active L2 entry pointing to an inactive L2 table and writes to the corresponding guest offset. Also, use overlap-check=all for all tests in 060. Signed-off-by: Max Reitz <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent b543c5c commit 34eeb82

File tree

2 files changed

+79
-8
lines changed

2 files changed

+79
-8
lines changed

tests/qemu-iotests/060

+40-7
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
# creator
2222
2323

24-
seq=`basename $0`
24+
seq="$(basename $0)"
2525
echo "QA output created by $seq"
2626

27-
here=`pwd`
27+
here="$PWD"
2828
tmp=/tmp/$$
2929
status=1 # failure is the default!
3030

@@ -47,9 +47,15 @@ rt_offset=65536 # 0x10000 (XXX: just an assumption)
4747
rb_offset=131072 # 0x20000 (XXX: just an assumption)
4848
l1_offset=196608 # 0x30000 (XXX: just an assumption)
4949
l2_offset=262144 # 0x40000 (XXX: just an assumption)
50+
l2_offset_after_snapshot=524288 # 0x80000 (XXX: just an assumption)
5051

5152
IMGOPTS="compat=1.1"
5253

54+
OPEN_RW="open -o overlap-check=all $TEST_IMG"
55+
# Overlap checks are done before write operations only, therefore opening an
56+
# image read-only makes the overlap-check option irrelevant
57+
OPEN_RO="open -r $TEST_IMG"
58+
5359
echo
5460
echo "=== Testing L2 reference into L1 ==="
5561
echo
@@ -65,16 +71,18 @@ _check_test_img
6571
./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
6672

6773
# Try to write something, thereby forcing the corrupt bit to be set
68-
$QEMU_IO -c "write -P 0x2a 0 512" "$TEST_IMG" | _filter_qemu_io
74+
$QEMU_IO -c "$OPEN_RW" -c "write -P 0x2a 0 512" | _filter_qemu_io
6975

7076
# The corrupt bit must now be set
7177
./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
7278

7379
# Try to open the image R/W (which should fail)
74-
$QEMU_IO -c "read 0 512" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir | _filter_imgfmt
80+
$QEMU_IO -c "$OPEN_RW" -c "read 0 512" 2>&1 | _filter_qemu_io \
81+
| _filter_testdir \
82+
| _filter_imgfmt
7583

7684
# Try to open it RO (which should succeed)
77-
$QEMU_IO -c "read 0 512" -r "$TEST_IMG" | _filter_qemu_io
85+
$QEMU_IO -c "$OPEN_RO" -c "read 0 512" | _filter_qemu_io
7886

7987
# We could now try to fix the image, but this would probably fail (how should an
8088
# L2 table linked onto the L1 table be fixed?)
@@ -92,7 +100,7 @@ poke_file "$TEST_IMG" "$(($rb_offset+8))" "\x00\x01"
92100
poke_file "$TEST_IMG" "$l2_offset" "\x80\x00\x00\x00\x00\x02\x00\x00"
93101
_check_test_img
94102
./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
95-
$QEMU_IO -c "write -P 0x2a 0 512" "$TEST_IMG" | _filter_qemu_io
103+
$QEMU_IO -c "$OPEN_RW" -c "write -P 0x2a 0 512" | _filter_qemu_io
96104
./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
97105

98106
# Try to fix it
@@ -102,8 +110,33 @@ _check_test_img -r all
102110
./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
103111

104112
# Look if it's really really fixed
105-
$QEMU_IO -c "write -P 0x2a 0 512" "$TEST_IMG" | _filter_qemu_io
113+
$QEMU_IO -c "$OPEN_RW" -c "write -P 0x2a 0 512" | _filter_qemu_io
114+
./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
115+
116+
echo
117+
echo "=== Testing cluster data reference into inactive L2 table ==="
118+
echo
119+
_make_test_img 64M
120+
$QEMU_IO -c "$OPEN_RW" -c "write -P 1 0 512" | _filter_qemu_io
121+
$QEMU_IMG snapshot -c foo "$TEST_IMG"
122+
$QEMU_IO -c "$OPEN_RW" -c "write -P 2 0 512" | _filter_qemu_io
123+
# The inactive L2 table remains at its old offset
124+
poke_file "$TEST_IMG" "$l2_offset_after_snapshot" \
125+
"\x80\x00\x00\x00\x00\x04\x00\x00"
126+
_check_test_img
106127
./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
128+
$QEMU_IO -c "$OPEN_RW" -c "write -P 3 0 512" | _filter_qemu_io
129+
./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
130+
_check_test_img -r all
131+
./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
132+
$QEMU_IO -c "$OPEN_RW" -c "write -P 4 0 512" | _filter_qemu_io
133+
./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
134+
135+
# Check data
136+
$QEMU_IO -c "$OPEN_RO" -c "read -P 4 0 512" | _filter_qemu_io
137+
$QEMU_IMG snapshot -a foo "$TEST_IMG"
138+
_check_test_img
139+
$QEMU_IO -c "$OPEN_RO" -c "read -P 1 0 512" | _filter_qemu_io
107140

108141
# success, all done
109142
echo "*** done"

tests/qemu-iotests/060.out

+39-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ qcow2: Preventing invalid write on metadata (overlaps with active L1 table); ima
1212
write failed: Input/output error
1313
incompatible_features 0x2
1414
qemu-io: can't open device TEST_DIR/t.IMGFMT: IMGFMT: Image is corrupt; cannot be opened read/write
15-
no file open, try 'help open'
1615
read 512/512 bytes at offset 0
1716
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
1817

@@ -40,4 +39,43 @@ incompatible_features 0x0
4039
wrote 512/512 bytes at offset 0
4140
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
4241
incompatible_features 0x0
42+
43+
=== Testing cluster data reference into inactive L2 table ===
44+
45+
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
46+
wrote 512/512 bytes at offset 0
47+
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
48+
wrote 512/512 bytes at offset 0
49+
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
50+
ERROR cluster 4 refcount=1 reference=2
51+
Leaked cluster 9 refcount=1 reference=0
52+
53+
1 errors were found on the image.
54+
Data may be corrupted, or further writes to the image may corrupt it.
55+
56+
1 leaked clusters were found on the image.
57+
This means waste of disk space, but no harm to data.
58+
incompatible_features 0x0
59+
qcow2: Preventing invalid write on metadata (overlaps with inactive L2 table); image marked as corrupt.
60+
write failed: Input/output error
61+
incompatible_features 0x2
62+
Repairing cluster 4 refcount=1 reference=2
63+
Repairing cluster 9 refcount=1 reference=0
64+
Repairing OFLAG_COPIED data cluster: l2_entry=8000000000040000 refcount=2
65+
The following inconsistencies were found and repaired:
66+
67+
1 leaked clusters
68+
2 corruptions
69+
70+
Double checking the fixed image now...
71+
No errors were found on the image.
72+
incompatible_features 0x0
73+
wrote 512/512 bytes at offset 0
74+
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
75+
incompatible_features 0x0
76+
read 512/512 bytes at offset 0
77+
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
78+
No errors were found on the image.
79+
read 512/512 bytes at offset 0
80+
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
4381
*** done

0 commit comments

Comments
 (0)