xref: /openbmc/qemu/tests/qemu-iotests/059 (revision c1eafd27)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2ca6cbb65SFam Zheng#
3ca6cbb65SFam Zheng# Test case for vmdk
4ca6cbb65SFam Zheng#
5ca6cbb65SFam Zheng# Copyright (C) 2013 Red Hat, Inc.
6ca6cbb65SFam Zheng#
7ca6cbb65SFam Zheng# This program is free software; you can redistribute it and/or modify
8ca6cbb65SFam Zheng# it under the terms of the GNU General Public License as published by
9ca6cbb65SFam Zheng# the Free Software Foundation; either version 2 of the License, or
10ca6cbb65SFam Zheng# (at your option) any later version.
11ca6cbb65SFam Zheng#
12ca6cbb65SFam Zheng# This program is distributed in the hope that it will be useful,
13ca6cbb65SFam Zheng# but WITHOUT ANY WARRANTY; without even the implied warranty of
14ca6cbb65SFam Zheng# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15ca6cbb65SFam Zheng# GNU General Public License for more details.
16ca6cbb65SFam Zheng#
17ca6cbb65SFam Zheng# You should have received a copy of the GNU General Public License
18ca6cbb65SFam Zheng# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19ca6cbb65SFam Zheng#
20ca6cbb65SFam Zheng
21ca6cbb65SFam Zheng# creator
22ca6cbb65SFam Zhengowner=famz@redhat.com
23ca6cbb65SFam Zheng
24ca6cbb65SFam Zhengseq=`basename $0`
25ca6cbb65SFam Zhengecho "QA output created by $seq"
26ca6cbb65SFam Zheng
27ca6cbb65SFam Zhengstatus=1	# failure is the default!
28ca6cbb65SFam Zheng
29ca6cbb65SFam Zheng_cleanup()
30ca6cbb65SFam Zheng{
31ca6cbb65SFam Zheng    _cleanup_test_img
32f91ecbd7SMax Reitz    IMGFMT=qcow2 _rm_test_img "$TEST_IMG.qcow2"
33ca6cbb65SFam Zheng}
34ca6cbb65SFam Zhengtrap "_cleanup; exit \$status" 0 1 2 3 15
35ca6cbb65SFam Zheng
36ca6cbb65SFam Zheng# get standard environment, filters and checks
37ca6cbb65SFam Zheng. ./common.rc
38ca6cbb65SFam Zheng. ./common.filter
39ca6cbb65SFam Zheng
40ca6cbb65SFam Zheng# This tests vmdk-specific low-level functionality
41ca6cbb65SFam Zheng_supported_fmt vmdk
421f7bf7d0SPeter Lieven_supported_proto file
43ca6cbb65SFam Zheng_supported_os Linux
44*c1eafd27SKevin Wolf
45*c1eafd27SKevin Wolf# We test all kinds of VMDK options here, so ignore user-specified options
46*c1eafd27SKevin WolfIMGOPTS=""
47ca6cbb65SFam Zheng
482c43e43cSFam Zhengcapacity_offset=16
498aa1331cSFam Zhenggranularity_offset=20
50f8ce0403SFam Zhenggrain_table_size_offset=44
518aa1331cSFam Zheng
528aa1331cSFam Zhengecho
535dd75f9aSFam Zhengecho "=== Testing invalid granularity ==="
548aa1331cSFam Zheng_make_test_img 64M
558aa1331cSFam Zhengpoke_file "$TEST_IMG" "$granularity_offset" "\xff\xff\xff\xff\xff\xff\xff\xff"
56fef9c191SJeff Cody{ $QEMU_IO -c "read 0 512" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
57ca6cbb65SFam Zheng
58f8ce0403SFam Zhengecho
595dd75f9aSFam Zhengecho "=== Testing too big L2 table size ==="
60f8ce0403SFam Zheng_make_test_img 64M
61f8ce0403SFam Zhengpoke_file "$TEST_IMG" "$grain_table_size_offset" "\xff\xff\xff\xff"
62fef9c191SJeff Cody{ $QEMU_IO -c "read 0 512" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
63f8ce0403SFam Zheng
642c43e43cSFam Zhengecho
655dd75f9aSFam Zhengecho "=== Testing too big L1 table size ==="
662c43e43cSFam Zheng_make_test_img 64M
672c43e43cSFam Zhengpoke_file "$TEST_IMG" "$capacity_offset" "\xff\xff\xff\xff"
682c43e43cSFam Zhengpoke_file "$TEST_IMG" "$grain_table_size_offset" "\x01\x00\x00\x00"
69fef9c191SJeff Cody{ $QEMU_IO -c "read 0 512" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
702c43e43cSFam Zheng
712fe2e290SFam Zhengecho
725dd75f9aSFam Zhengecho "=== Testing monolithicFlat creation and opening ==="
73407fb56aSMax Reitz_make_test_img -o "subformat=monolithicFlat" 2G
74f4c129a3SFam Zheng_img_info
7559fa68f3SKevin Wolf_cleanup_test_img
762fe2e290SFam Zheng
7752c8d629SFam Zhengecho
7852c8d629SFam Zhengecho "=== Testing monolithicFlat with zeroed_grain ==="
79407fb56aSMax Reitz_make_test_img -o "subformat=monolithicFlat,zeroed_grain=on" 2G
8059fa68f3SKevin Wolf_cleanup_test_img
8152c8d629SFam Zheng
82981cbf59SFam Zhengecho
83af057fe7SFam Zhengecho "=== Testing big twoGbMaxExtentFlat ==="
84407fb56aSMax Reitz_make_test_img -o "subformat=twoGbMaxExtentFlat" 1000G
85af057fe7SFam Zheng$QEMU_IMG info $TEST_IMG | _filter_testdir | sed -e 's/cid: [0-9]*/cid: XXXXXXXX/'
8659fa68f3SKevin Wolf_cleanup_test_img
87af057fe7SFam Zheng
88af057fe7SFam Zhengecho
89b47053bdSFam Zhengecho "=== Testing malformed VMFS extent description line ==="
90b47053bdSFam Zhengcat >"$TEST_IMG" <<EOF
91b47053bdSFam Zheng# Disk DescriptorFile
92b47053bdSFam Zhengversion=1
93b47053bdSFam ZhengCID=58ab4847
94b47053bdSFam ZhengparentCID=ffffffff
95b47053bdSFam ZhengcreateType="vmfs"
96b47053bdSFam Zheng
97b47053bdSFam Zheng# Extent description
98b47053bdSFam ZhengRW 12582912 VMFS "dummy.vmdk" 1
99b47053bdSFam ZhengEOF
100b47053bdSFam Zheng_img_info
101b47053bdSFam Zheng
102b47053bdSFam Zhengecho
10334ceed81SFam Zhengecho "=== Testing truncated sparse ==="
104407fb56aSMax Reitz_make_test_img -o "subformat=monolithicSparse" 100G
10534ceed81SFam Zhengtruncate -s 10M $TEST_IMG
10634ceed81SFam Zheng_img_info
10734ceed81SFam Zheng
10834ceed81SFam Zhengecho
10910f08a0aSFam Zhengecho "=== Converting to streamOptimized from image with small cluster size==="
110407fb56aSMax ReitzTEST_IMG="$TEST_IMG.qcow2" IMGFMT=qcow2 _make_test_img -o "cluster_size=4096" 1G
111b89689f5SMax Reitz$QEMU_IO -f qcow2 -c "write -P 0xa 0 512" "$TEST_IMG.qcow2" | _filter_qemu_io
112b89689f5SMax Reitz$QEMU_IO -f qcow2 -c "write -P 0xb 10240 512" "$TEST_IMG.qcow2" | _filter_qemu_io
11310f08a0aSFam Zheng$QEMU_IMG convert -f qcow2 -O vmdk -o subformat=streamOptimized "$TEST_IMG.qcow2" "$TEST_IMG" 2>&1
11410f08a0aSFam Zheng
11510f08a0aSFam Zhengecho
116942764ccSMax Reitzecho "=== Testing monolithicFlat with internally generated JSON file name ==="
11712b7cbcaSMax Reitz
11812b7cbcaSMax Reitzecho '--- blkdebug ---'
119cdc0dd25SMax Reitz# Should work, because bdrv_dirname() works fine with blkdebug
120407fb56aSMax Reitz_make_test_img -o "subformat=monolithicFlat" 64M
121cdc0dd25SMax Reitz$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=read_aio" \
122cdc0dd25SMax Reitz         -c info \
123cdc0dd25SMax Reitz    2>&1 \
124cdc0dd25SMax Reitz    | _filter_testdir | _filter_imgfmt | _filter_img_info
12559fa68f3SKevin Wolf_cleanup_test_img
126942764ccSMax Reitz
12712b7cbcaSMax Reitzecho '--- quorum ---'
12812b7cbcaSMax Reitz# Should not work, because bdrv_dirname() does not work with quorum
129407fb56aSMax Reitz_make_test_img -o "subformat=monolithicFlat" 64M
13012b7cbcaSMax Reitzcp "$TEST_IMG" "$TEST_IMG.orig"
13112b7cbcaSMax Reitz
13212b7cbcaSMax Reitzfilename="json:{
13312b7cbcaSMax Reitz    \"driver\": \"$IMGFMT\",
13412b7cbcaSMax Reitz    \"file\": {
13512b7cbcaSMax Reitz        \"driver\": \"quorum\",
13612b7cbcaSMax Reitz        \"children\": [ {
13712b7cbcaSMax Reitz            \"driver\": \"file\",
13812b7cbcaSMax Reitz            \"filename\": \"$TEST_IMG\"
13912b7cbcaSMax Reitz        }, {
14012b7cbcaSMax Reitz            \"driver\": \"file\",
14112b7cbcaSMax Reitz            \"filename\": \"$TEST_IMG.orig\"
14212b7cbcaSMax Reitz        } ],
14312b7cbcaSMax Reitz        \"vote-threshold\": 1
14412b7cbcaSMax Reitz    } }"
14512b7cbcaSMax Reitz
14612b7cbcaSMax Reitzfilename=$(echo "$filename" | tr '\n' ' ' | sed -e 's/\s\+/ /g')
14712b7cbcaSMax Reitz$QEMU_IMG info "$filename" 2>&1 \
14812b7cbcaSMax Reitz    | sed -e "s/'json:[^']*'/\$QUORUM_FILE/g" \
14912b7cbcaSMax Reitz    | _filter_testdir | _filter_imgfmt | _filter_img_info
15012b7cbcaSMax Reitz
15112b7cbcaSMax Reitz
152942764ccSMax Reitzecho
153981cbf59SFam Zhengecho "=== Testing version 3 ==="
154981cbf59SFam Zheng_use_sample_img iotest-version3.vmdk.bz2
155981cbf59SFam Zheng_img_info
156a8d8a1a0SFam Zhengfor i in {0..99}; do
157a8d8a1a0SFam Zheng    $QEMU_IO -r -c "read -P $(( i % 10 + 0x30 )) $(( i * 64 * 1024 * 10 + i * 512 )) 512" $TEST_IMG \
158a8d8a1a0SFam Zheng        | _filter_qemu_io
159a8d8a1a0SFam Zhengdone
16059fa68f3SKevin Wolf_cleanup_test_img
161981cbf59SFam Zheng
162585ea0c8SFam Zhengecho
163585ea0c8SFam Zhengecho "=== Testing 4TB monolithicFlat creation and IO ==="
164407fb56aSMax Reitz_make_test_img -o "subformat=monolithicFlat" 4T
165585ea0c8SFam Zheng_img_info
166585ea0c8SFam Zheng$QEMU_IO -c "write -P 0xa 900G 512" "$TEST_IMG" | _filter_qemu_io
167585ea0c8SFam Zheng$QEMU_IO -c "read -v 900G 1024" "$TEST_IMG" | _filter_qemu_io
16859fa68f3SKevin Wolf_cleanup_test_img
169585ea0c8SFam Zheng
170b93bbf4eSFam Zhengecho
171c7fc50d3SFam Zhengecho "=== Testing qemu-img map on extents ==="
172c7fc50d3SFam Zhengfor fmt in monolithicSparse twoGbMaxExtentSparse; do
173407fb56aSMax Reitz    _make_test_img -o "subformat=$fmt" 31G
174c7fc50d3SFam Zheng    $QEMU_IO -c "write 65024 1k" "$TEST_IMG" | _filter_qemu_io
175c7fc50d3SFam Zheng    $QEMU_IO -c "write 2147483136 1k" "$TEST_IMG" | _filter_qemu_io
176c7fc50d3SFam Zheng    $QEMU_IO -c "write 5G 1k" "$TEST_IMG" | _filter_qemu_io
177c7fc50d3SFam Zheng    $QEMU_IMG map "$TEST_IMG" | _filter_testdir
17859fa68f3SKevin Wolf    _cleanup_test_img
179c7fc50d3SFam Zhengdone
180c7fc50d3SFam Zheng
181c7fc50d3SFam Zhengecho
182b93bbf4eSFam Zhengecho "=== Testing afl image with a very large capacity ==="
183b93bbf4eSFam Zheng_use_sample_img afl9.vmdk.bz2
1840bfed484SFam Zheng_img_info | grep -q 'Cannot allocate memory' && _notrun "Insufficent memory, skipped test"
1850bfed484SFam Zheng_img_info
18659fa68f3SKevin Wolf_cleanup_test_img
187b93bbf4eSFam Zheng
188ca6cbb65SFam Zheng# success, all done
189ca6cbb65SFam Zhengecho "*** done"
190ca6cbb65SFam Zhengrm -f $seq.full
191ca6cbb65SFam Zhengstatus=0
192