Skip to content

Commit 85456e0

Browse files
committed
iotests: Add VMDK backing file correlation test
This new test verifies that VMDK backing file reads fail when the backing file has a non-matching CID. This includes non-VMDK backing files. Signed-off-by: Max Reitz <[email protected]> Message-id: [email protected] Signed-off-by: Max Reitz <[email protected]>
1 parent 439e89f commit 85456e0

File tree

3 files changed

+157
-0
lines changed

3 files changed

+157
-0
lines changed

Diff for: tests/qemu-iotests/225

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/bin/bash
2+
#
3+
# Test vmdk backing file correlation
4+
#
5+
# Copyright (C) 2018 Red Hat, Inc.
6+
#
7+
# This program is free software; you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation; either version 2 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
21+
# creator
22+
23+
24+
seq=$(basename $0)
25+
echo "QA output created by $seq"
26+
27+
here=$PWD
28+
status=1 # failure is the default!
29+
30+
_cleanup()
31+
{
32+
_cleanup_test_img
33+
rm -f "$TEST_IMG.not_base"
34+
}
35+
trap "_cleanup; exit \$status" 0 1 2 3 15
36+
37+
# get standard environment, filters and checks
38+
. ./common.rc
39+
. ./common.filter
40+
. ./common.qemu
41+
42+
# This tests vmdk-specific low-level functionality
43+
_supported_fmt vmdk
44+
_supported_proto file
45+
_supported_os Linux
46+
_unsupported_imgopts "subformat=monolithicFlat" \
47+
"subformat=twoGbMaxExtentFlat" \
48+
"subformat=twoGbMaxExtentSparse"
49+
50+
TEST_IMG="$TEST_IMG.base" _make_test_img 1M
51+
TEST_IMG="$TEST_IMG.not_base" _make_test_img 1M
52+
_make_test_img -b "$TEST_IMG.base"
53+
54+
make_opts()
55+
{
56+
node_name=$1
57+
filename=$2
58+
backing=$3
59+
60+
if [ -z "$backing" ]; then
61+
backing="null"
62+
else
63+
backing="'$backing'"
64+
fi
65+
66+
echo "{ 'node-name': '$node_name',
67+
'driver': 'vmdk',
68+
'file': {
69+
'driver': 'file',
70+
'filename': '$filename'
71+
},
72+
'backing': $backing }"
73+
}
74+
75+
overlay_opts=$(make_opts overlay "$TEST_IMG" backing)
76+
base_opts=$(make_opts backing "$TEST_IMG.base")
77+
not_base_opts=$(make_opts backing "$TEST_IMG.not_base")
78+
79+
not_vmdk_opts="{ 'node-name': 'backing', 'driver': 'null-co' }"
80+
81+
echo
82+
echo '=== Testing fitting VMDK backing image ==='
83+
echo
84+
85+
qemu_comm_method=monitor \
86+
_launch_qemu -blockdev "$base_opts" -blockdev "$overlay_opts"
87+
88+
# Should not return an error
89+
_send_qemu_cmd $QEMU_HANDLE 'qemu-io overlay "read 0 512"' 'ops'
90+
91+
_cleanup_qemu
92+
93+
94+
echo
95+
echo '=== Testing unrelated VMDK backing image ==='
96+
echo
97+
98+
qemu_comm_method=monitor \
99+
_launch_qemu -blockdev "$not_base_opts" -blockdev "$overlay_opts"
100+
101+
# Should fail (gracefully)
102+
_send_qemu_cmd $QEMU_HANDLE 'qemu-io overlay "read 0 512"' 'failed'
103+
104+
_cleanup_qemu
105+
106+
107+
echo
108+
echo '=== Testing non-VMDK backing image ==='
109+
echo
110+
111+
# FIXME: This is the reason why we have to use two -blockdev
112+
# invocations. You can only fully override the backing file options
113+
# if you either specify a node reference (as done here) or the new
114+
# options contain file.filename (which in this case they do not).
115+
# In other cases, file.filename will be set to whatever the image
116+
# header of the overlay contains (which we do not want). I consider
117+
# this a FIXME because with -blockdev, you cannot specify "partial"
118+
# options, so setting file.filename but leaving the rest as specified
119+
# by the user does not make sense.
120+
qemu_comm_method=monitor \
121+
_launch_qemu -blockdev "$not_vmdk_opts" -blockdev "$overlay_opts"
122+
123+
# Should fail (gracefully)
124+
_send_qemu_cmd $QEMU_HANDLE 'qemu-io overlay "read 0 512"' 'failed'
125+
126+
_cleanup_qemu
127+
128+
129+
# success, all done
130+
echo "*** done"
131+
rm -f $seq.full
132+
status=0

Diff for: tests/qemu-iotests/225.out

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
QA output created by 225
2+
Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=1048576
3+
Formatting 'TEST_DIR/t.IMGFMT.not_base', fmt=IMGFMT size=1048576
4+
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 backing_file=TEST_DIR/t.IMGFMT.base
5+
6+
=== Testing fitting VMDK backing image ===
7+
8+
QEMU X.Y.Z monitor - type 'help' for more information
9+
(qemu) qemu-io overlay "read 0 512"
10+
read 512/512 bytes at offset 0
11+
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
12+
13+
=== Testing unrelated VMDK backing image ===
14+
15+
QEMU X.Y.Z monitor - type 'help' for more information
16+
(qemu) qemu-io overlay "read 0 512"
17+
read failed: Invalid argument
18+
19+
=== Testing non-VMDK backing image ===
20+
21+
QEMU X.Y.Z monitor - type 'help' for more information
22+
(qemu) qemu-io overlay "read 0 512"
23+
read failed: Invalid argument
24+
*** done

Diff for: tests/qemu-iotests/group

+1
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,4 @@
222222
221 rw auto quick
223223
222 rw auto quick
224224
223 rw auto quick
225+
225 rw auto quick

0 commit comments

Comments
 (0)