These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / tests / qemu-iotests / 109
1 #!/bin/bash
2 #
3 # Test writing image headers of other formats into raw images
4 #
5 # Copyright (C) 2014 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 owner=kwolf@redhat.com
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     rm -f $TEST_IMG.src
33         _cleanup_test_img
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 _supported_fmt raw
43 _supported_proto file
44 _supported_os Linux
45
46 qemu_comm_method=qmp
47
48 function run_qemu()
49 {
50     local raw_img="$1"
51     local source_img="$2"
52     local qmp_format="$3"
53     local qmp_event="$4"
54
55     _launch_qemu -drive file="${source_img}",format=raw,cache=${CACHEMODE},id=src
56     _send_qemu_cmd $QEMU_HANDLE "{ 'execute': 'qmp_capabilities' }" "return"
57
58     _send_qemu_cmd $QEMU_HANDLE \
59         "{'execute':'drive-mirror', 'arguments':{
60             'device': 'src', 'target': '$raw_img', $qmp_format
61             'mode': 'existing', 'sync': 'full'}}" \
62         "return"
63
64     _send_qemu_cmd $QEMU_HANDLE '' "$qmp_event"
65     _send_qemu_cmd $QEMU_HANDLE '{"execute":"query-block-jobs"}' "return"
66     _cleanup_qemu
67 }
68
69 for fmt in qcow qcow2 qed vdi vmdk vpc; do
70
71     echo
72     echo "=== Writing a $fmt header into raw ==="
73     echo
74
75     _make_test_img 64M
76     TEST_IMG="$TEST_IMG.src" IMGFMT=$fmt _make_test_img 64M
77
78     # This first test should fail: The image format was probed, we may not
79     # write an image header at the start of the image
80     run_qemu "$TEST_IMG" "$TEST_IMG.src" "" "BLOCK_JOB_ERROR"
81     $QEMU_IO -c 'read -P 0 0 64k' "$TEST_IMG" | _filter_qemu_io
82
83
84     # When raw was explicitly specified, the same must succeed
85     run_qemu "$TEST_IMG" "$TEST_IMG.src" "'format': 'raw'," "BLOCK_JOB_READY"
86     $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src"
87
88 done
89
90
91 for sample_img in empty.bochs iotest-dirtylog-10G-4M.vhdx parallels-v1 \
92                   simple-pattern.cloop; do
93
94     echo
95     echo "=== Copying sample image $sample_img into raw ==="
96     echo
97
98     # Can't use _use_sample_img because that isn't designed to be used multiple
99     # times and it overwrites $TEST_IMG (both breaks cleanup)
100     _make_test_img 64M
101     bzcat "$SAMPLE_IMG_DIR/$sample_img.bz2" > "$TEST_IMG.src"
102
103     run_qemu "$TEST_IMG" "$TEST_IMG.src" "" "BLOCK_JOB_ERROR"
104     $QEMU_IO -c 'read -P 0 0 64k' "$TEST_IMG" | _filter_qemu_io
105
106     run_qemu "$TEST_IMG" "$TEST_IMG.src" "'format': 'raw'," "BLOCK_JOB_READY"
107     # qemu-img compare can't handle unaligned file sizes
108     $QEMU_IMG resize -f raw "$TEST_IMG.src" +0
109     $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src"
110 done
111
112 echo
113 echo "=== Write legitimate MBR into raw ==="
114 echo
115
116 for sample_img in grub_mbr.raw; do
117     _make_test_img 64M
118     bzcat "$SAMPLE_IMG_DIR/$sample_img.bz2" > "$TEST_IMG.src"
119
120     run_qemu "$TEST_IMG" "$TEST_IMG.src" "" "BLOCK_JOB_READY"
121     $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src"
122
123     run_qemu "$TEST_IMG" "$TEST_IMG.src" "'format': 'raw'," "BLOCK_JOB_READY"
124     $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src"
125 done
126
127
128 # success, all done
129 echo '*** done'
130 rm -f $seq.full
131 status=0