xref: /openbmc/qemu/tests/qemu-iotests/059 (revision 9fb7b350)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
29dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick
3ca6cbb65SFam Zheng#
4ca6cbb65SFam Zheng# Test case for vmdk
5ca6cbb65SFam Zheng#
6ca6cbb65SFam Zheng# Copyright (C) 2013 Red Hat, Inc.
7ca6cbb65SFam Zheng#
8ca6cbb65SFam Zheng# This program is free software; you can redistribute it and/or modify
9ca6cbb65SFam Zheng# it under the terms of the GNU General Public License as published by
10ca6cbb65SFam Zheng# the Free Software Foundation; either version 2 of the License, or
11ca6cbb65SFam Zheng# (at your option) any later version.
12ca6cbb65SFam Zheng#
13ca6cbb65SFam Zheng# This program is distributed in the hope that it will be useful,
14ca6cbb65SFam Zheng# but WITHOUT ANY WARRANTY; without even the implied warranty of
15ca6cbb65SFam Zheng# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16ca6cbb65SFam Zheng# GNU General Public License for more details.
17ca6cbb65SFam Zheng#
18ca6cbb65SFam Zheng# You should have received a copy of the GNU General Public License
19ca6cbb65SFam Zheng# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20ca6cbb65SFam Zheng#
21ca6cbb65SFam Zheng
22ca6cbb65SFam Zheng# creator
2342a5009dSJohn Snowowner=fam@euphon.net
24ca6cbb65SFam Zheng
25ca6cbb65SFam Zhengseq=`basename $0`
26ca6cbb65SFam Zhengecho "QA output created by $seq"
27ca6cbb65SFam Zheng
28ca6cbb65SFam Zhengstatus=1	# failure is the default!
29ca6cbb65SFam Zheng
30ca6cbb65SFam Zheng_cleanup()
31ca6cbb65SFam Zheng{
32ca6cbb65SFam Zheng    _cleanup_test_img
33f91ecbd7SMax Reitz    IMGFMT=qcow2 _rm_test_img "$TEST_IMG.qcow2"
34ca6cbb65SFam Zheng}
35ca6cbb65SFam Zhengtrap "_cleanup; exit \$status" 0 1 2 3 15
36ca6cbb65SFam Zheng
37ca6cbb65SFam Zheng# get standard environment, filters and checks
38ca6cbb65SFam Zheng. ./common.rc
39ca6cbb65SFam Zheng. ./common.filter
40ca6cbb65SFam Zheng
41ca6cbb65SFam Zheng# This tests vmdk-specific low-level functionality
42ca6cbb65SFam Zheng_supported_fmt vmdk
431f7bf7d0SPeter Lieven_supported_proto file
44ca6cbb65SFam Zheng_supported_os Linux
45c1eafd27SKevin Wolf
46c1eafd27SKevin Wolf# We test all kinds of VMDK options here, so ignore user-specified options
47c1eafd27SKevin WolfIMGOPTS=""
48ca6cbb65SFam Zheng
492c43e43cSFam Zhengcapacity_offset=16
508aa1331cSFam Zhenggranularity_offset=20
51f8ce0403SFam Zhenggrain_table_size_offset=44
528aa1331cSFam Zheng
538aa1331cSFam Zhengecho
545dd75f9aSFam Zhengecho "=== Testing invalid granularity ==="
558aa1331cSFam Zheng_make_test_img 64M
568aa1331cSFam Zhengpoke_file "$TEST_IMG" "$granularity_offset" "\xff\xff\xff\xff\xff\xff\xff\xff"
57fef9c191SJeff Cody{ $QEMU_IO -c "read 0 512" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
58ca6cbb65SFam Zheng
59f8ce0403SFam Zhengecho
605dd75f9aSFam Zhengecho "=== Testing too big L2 table size ==="
61f8ce0403SFam Zheng_make_test_img 64M
62f8ce0403SFam Zhengpoke_file "$TEST_IMG" "$grain_table_size_offset" "\xff\xff\xff\xff"
63fef9c191SJeff Cody{ $QEMU_IO -c "read 0 512" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
64f8ce0403SFam Zheng
652c43e43cSFam Zhengecho
665dd75f9aSFam Zhengecho "=== Testing too big L1 table size ==="
672c43e43cSFam Zheng_make_test_img 64M
682c43e43cSFam Zhengpoke_file "$TEST_IMG" "$capacity_offset" "\xff\xff\xff\xff"
692c43e43cSFam Zhengpoke_file "$TEST_IMG" "$grain_table_size_offset" "\x01\x00\x00\x00"
70fef9c191SJeff Cody{ $QEMU_IO -c "read 0 512" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
712c43e43cSFam Zheng
722fe2e290SFam Zhengecho
735dd75f9aSFam Zhengecho "=== Testing monolithicFlat creation and opening ==="
74407fb56aSMax Reitz_make_test_img -o "subformat=monolithicFlat" 2G
75f4c129a3SFam Zheng_img_info
7659fa68f3SKevin Wolf_cleanup_test_img
772fe2e290SFam Zheng
7852c8d629SFam Zhengecho
7952c8d629SFam Zhengecho "=== Testing monolithicFlat with zeroed_grain ==="
80407fb56aSMax Reitz_make_test_img -o "subformat=monolithicFlat,zeroed_grain=on" 2G
8159fa68f3SKevin Wolf_cleanup_test_img
8252c8d629SFam Zheng
83981cbf59SFam Zhengecho
84af057fe7SFam Zhengecho "=== Testing big twoGbMaxExtentFlat ==="
85407fb56aSMax Reitz_make_test_img -o "subformat=twoGbMaxExtentFlat" 1000G
86046e07caSKevin Wolf_img_info --format-specific | _filter_img_info --format-specific
87*9fb7b350SFam Zheng$QEMU_IO -c "write 990G 512 -P 89" "$TEST_IMG" | _filter_qemu_io
88*9fb7b350SFam Zheng$QEMU_IO -c "read 990G 512 -P 89" "$TEST_IMG" | _filter_qemu_io
8959fa68f3SKevin Wolf_cleanup_test_img
90af057fe7SFam Zheng
91af057fe7SFam Zhengecho
92b47053bdSFam Zhengecho "=== Testing malformed VMFS extent description line ==="
93b47053bdSFam Zhengcat >"$TEST_IMG" <<EOF
94b47053bdSFam Zheng# Disk DescriptorFile
95b47053bdSFam Zhengversion=1
96b47053bdSFam ZhengCID=58ab4847
97b47053bdSFam ZhengparentCID=ffffffff
98b47053bdSFam ZhengcreateType="vmfs"
99b47053bdSFam Zheng
100b47053bdSFam Zheng# Extent description
101b47053bdSFam ZhengRW 12582912 VMFS "dummy.vmdk" 1
102b47053bdSFam ZhengEOF
103b47053bdSFam Zheng_img_info
104b47053bdSFam Zheng
105b47053bdSFam Zhengecho
10634ceed81SFam Zhengecho "=== Testing truncated sparse ==="
107407fb56aSMax Reitz_make_test_img -o "subformat=monolithicSparse" 100G
10834ceed81SFam Zhengtruncate -s 10M $TEST_IMG
10934ceed81SFam Zheng_img_info
11034ceed81SFam Zheng
11134ceed81SFam Zhengecho
11210f08a0aSFam Zhengecho "=== Converting to streamOptimized from image with small cluster size==="
113407fb56aSMax ReitzTEST_IMG="$TEST_IMG.qcow2" IMGFMT=qcow2 _make_test_img -o "cluster_size=4096" 1G
114b89689f5SMax Reitz$QEMU_IO -f qcow2 -c "write -P 0xa 0 512" "$TEST_IMG.qcow2" | _filter_qemu_io
115b89689f5SMax Reitz$QEMU_IO -f qcow2 -c "write -P 0xb 10240 512" "$TEST_IMG.qcow2" | _filter_qemu_io
11610f08a0aSFam Zheng$QEMU_IMG convert -f qcow2 -O vmdk -o subformat=streamOptimized "$TEST_IMG.qcow2" "$TEST_IMG" 2>&1
11710f08a0aSFam Zheng
11810f08a0aSFam Zhengecho
119942764ccSMax Reitzecho "=== Testing monolithicFlat with internally generated JSON file name ==="
12012b7cbcaSMax Reitz
12112b7cbcaSMax Reitzecho '--- blkdebug ---'
122cdc0dd25SMax Reitz# Should work, because bdrv_dirname() works fine with blkdebug
123407fb56aSMax Reitz_make_test_img -o "subformat=monolithicFlat" 64M
124cdc0dd25SMax Reitz$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=read_aio" \
125cdc0dd25SMax Reitz         -c info \
126cdc0dd25SMax Reitz    2>&1 \
127cdc0dd25SMax Reitz    | _filter_testdir | _filter_imgfmt | _filter_img_info
12859fa68f3SKevin Wolf_cleanup_test_img
129942764ccSMax Reitz
13012b7cbcaSMax Reitzecho '--- quorum ---'
13112b7cbcaSMax Reitz# Should not work, because bdrv_dirname() does not work with quorum
132407fb56aSMax Reitz_make_test_img -o "subformat=monolithicFlat" 64M
13312b7cbcaSMax Reitzcp "$TEST_IMG" "$TEST_IMG.orig"
13412b7cbcaSMax Reitz
13512b7cbcaSMax Reitzfilename="json:{
13612b7cbcaSMax Reitz    \"driver\": \"$IMGFMT\",
13712b7cbcaSMax Reitz    \"file\": {
13812b7cbcaSMax Reitz        \"driver\": \"quorum\",
13912b7cbcaSMax Reitz        \"children\": [ {
14012b7cbcaSMax Reitz            \"driver\": \"file\",
14112b7cbcaSMax Reitz            \"filename\": \"$TEST_IMG\"
14212b7cbcaSMax Reitz        }, {
14312b7cbcaSMax Reitz            \"driver\": \"file\",
14412b7cbcaSMax Reitz            \"filename\": \"$TEST_IMG.orig\"
14512b7cbcaSMax Reitz        } ],
14612b7cbcaSMax Reitz        \"vote-threshold\": 1
14712b7cbcaSMax Reitz    } }"
14812b7cbcaSMax Reitz
14912b7cbcaSMax Reitzfilename=$(echo "$filename" | tr '\n' ' ' | sed -e 's/\s\+/ /g')
15012b7cbcaSMax Reitz$QEMU_IMG info "$filename" 2>&1 \
15112b7cbcaSMax Reitz    | sed -e "s/'json:[^']*'/\$QUORUM_FILE/g" \
15212b7cbcaSMax Reitz    | _filter_testdir | _filter_imgfmt | _filter_img_info
15312b7cbcaSMax Reitz
15412b7cbcaSMax Reitz
155942764ccSMax Reitzecho
156981cbf59SFam Zhengecho "=== Testing version 3 ==="
157981cbf59SFam Zheng_use_sample_img iotest-version3.vmdk.bz2
158981cbf59SFam Zheng_img_info
159a8d8a1a0SFam Zhengfor i in {0..99}; do
160a8d8a1a0SFam Zheng    $QEMU_IO -r -c "read -P $(( i % 10 + 0x30 )) $(( i * 64 * 1024 * 10 + i * 512 )) 512" $TEST_IMG \
161a8d8a1a0SFam Zheng        | _filter_qemu_io
162a8d8a1a0SFam Zhengdone
16359fa68f3SKevin Wolf_cleanup_test_img
164981cbf59SFam Zheng
165585ea0c8SFam Zhengecho
166585ea0c8SFam Zhengecho "=== Testing 4TB monolithicFlat creation and IO ==="
167407fb56aSMax Reitz_make_test_img -o "subformat=monolithicFlat" 4T
168585ea0c8SFam Zheng_img_info
169585ea0c8SFam Zheng$QEMU_IO -c "write -P 0xa 900G 512" "$TEST_IMG" | _filter_qemu_io
170585ea0c8SFam Zheng$QEMU_IO -c "read -v 900G 1024" "$TEST_IMG" | _filter_qemu_io
17159fa68f3SKevin Wolf_cleanup_test_img
172585ea0c8SFam Zheng
173b93bbf4eSFam Zhengecho
174c7fc50d3SFam Zhengecho "=== Testing qemu-img map on extents ==="
175c7fc50d3SFam Zhengfor fmt in monolithicSparse twoGbMaxExtentSparse; do
176407fb56aSMax Reitz    _make_test_img -o "subformat=$fmt" 31G
177c7fc50d3SFam Zheng    $QEMU_IO -c "write 65024 1k" "$TEST_IMG" | _filter_qemu_io
178c7fc50d3SFam Zheng    $QEMU_IO -c "write 2147483136 1k" "$TEST_IMG" | _filter_qemu_io
179c7fc50d3SFam Zheng    $QEMU_IO -c "write 5G 1k" "$TEST_IMG" | _filter_qemu_io
180c7fc50d3SFam Zheng    $QEMU_IMG map "$TEST_IMG" | _filter_testdir
18159fa68f3SKevin Wolf    _cleanup_test_img
182c7fc50d3SFam Zhengdone
183c7fc50d3SFam Zheng
184c7fc50d3SFam Zhengecho
185b93bbf4eSFam Zhengecho "=== Testing afl image with a very large capacity ==="
186b93bbf4eSFam Zheng_use_sample_img afl9.vmdk.bz2
18796420a30SMichael Tokarev_img_info | grep -q 'Cannot allocate memory' && _notrun "Insufficient memory, skipped test"
1880bfed484SFam Zheng_img_info
18959fa68f3SKevin Wolf_cleanup_test_img
190b93bbf4eSFam Zheng
191ca6cbb65SFam Zheng# success, all done
192ca6cbb65SFam Zhengecho "*** done"
193ca6cbb65SFam Zhengrm -f $seq.full
194ca6cbb65SFam Zhengstatus=0
195