21
21
# creator
22
22
23
23
24
- seq=` basename $0 `
24
+ seq=" $( basename $0 ) "
25
25
echo " QA output created by $seq "
26
26
27
- here=` pwd `
27
+ here=" $PWD "
28
28
tmp=/tmp/$$
29
29
status=1 # failure is the default!
30
30
@@ -47,9 +47,15 @@ rt_offset=65536 # 0x10000 (XXX: just an assumption)
47
47
rb_offset=131072 # 0x20000 (XXX: just an assumption)
48
48
l1_offset=196608 # 0x30000 (XXX: just an assumption)
49
49
l2_offset=262144 # 0x40000 (XXX: just an assumption)
50
+ l2_offset_after_snapshot=524288 # 0x80000 (XXX: just an assumption)
50
51
51
52
IMGOPTS=" compat=1.1"
52
53
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
+
53
59
echo
54
60
echo " === Testing L2 reference into L1 ==="
55
61
echo
@@ -65,16 +71,18 @@ _check_test_img
65
71
./qcow2.py " $TEST_IMG " dump-header | grep incompatible_features
66
72
67
73
# 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
69
75
70
76
# The corrupt bit must now be set
71
77
./qcow2.py " $TEST_IMG " dump-header | grep incompatible_features
72
78
73
79
# 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
75
83
76
84
# 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
78
86
79
87
# We could now try to fix the image, but this would probably fail (how should an
80
88
# L2 table linked onto the L1 table be fixed?)
@@ -92,7 +100,7 @@ poke_file "$TEST_IMG" "$(($rb_offset+8))" "\x00\x01"
92
100
poke_file " $TEST_IMG " " $l2_offset " " \x80\x00\x00\x00\x00\x02\x00\x00"
93
101
_check_test_img
94
102
./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
96
104
./qcow2.py " $TEST_IMG " dump-header | grep incompatible_features
97
105
98
106
# Try to fix it
@@ -102,8 +110,33 @@ _check_test_img -r all
102
110
./qcow2.py " $TEST_IMG " dump-header | grep incompatible_features
103
111
104
112
# 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
106
127
./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
107
140
108
141
# success, all done
109
142
echo " *** done"
0 commit comments