4 # Test writing image headers of other formats into raw images
6 # Copyright (C) 2014 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 owner=kwolf@redhat.com
26 echo "QA output created by $seq"
28 status=1 # failure is the default!
33 _rm_test_img "$TEST_IMG.src"
36 trap "_cleanup; exit \$status" 0 1 2 3 15
38 # get standard environment, filters and checks
46 _require_drivers qcow qcow2 qed vdi vmdk vpc
57 _launch_qemu -drive file="${source_img}",format=raw,cache=${CACHEMODE},aio=${AIOMODE},id=src
58 _send_qemu_cmd $QEMU_HANDLE "{ 'execute': 'qmp_capabilities' }" "return"
60 _send_qemu_cmd $QEMU_HANDLE \
61 "{'execute':'drive-mirror', 'arguments':{
62 'device': 'src', 'target': '$raw_img', $qmp_format
63 'mode': 'existing', 'sync': 'full'}}" \
66 _send_qemu_cmd $QEMU_HANDLE '' "$qmp_event"
67 if test "$qmp_event" = BLOCK_JOB_ERROR; then
68 _send_qemu_cmd $QEMU_HANDLE '' '"status": "null"'
70 _send_qemu_cmd $QEMU_HANDLE '{"execute":"query-block-jobs"}' "return"
71 _send_qemu_cmd $QEMU_HANDLE '{"execute":"quit"}' "return"
75 for fmt in qcow qcow2 qed vdi vmdk vpc; do
78 echo "=== Writing a $fmt header into raw ==="
81 TEST_IMG="$TEST_IMG.src" IMGFMT=$fmt _make_test_img 64M
82 _make_test_img $(du -b "$TEST_IMG.src" | cut -f1) | _filter_img_create_size
84 # This first test should fail: The image format was probed, we may not
85 # write an image header at the start of the image
86 run_qemu "$TEST_IMG" "$TEST_IMG.src" "" "BLOCK_JOB_ERROR" |
88 $QEMU_IO -c 'read -P 0 0 512' "$TEST_IMG" | _filter_qemu_io
91 # When raw was explicitly specified, the same must succeed
92 run_qemu "$TEST_IMG" "$TEST_IMG.src" "'format': 'raw'," "BLOCK_JOB_READY"
93 $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src"
98 for sample_img in empty.bochs iotest-dirtylog-10G-4M.vhdx parallels-v1 \
99 simple-pattern.cloop; do
102 echo "=== Copying sample image $sample_img into raw ==="
105 # Can't use _use_sample_img because that isn't designed to be used multiple
106 # times and it overwrites $TEST_IMG (both breaks cleanup)
107 bzcat "$SAMPLE_IMG_DIR/$sample_img.bz2" > "$TEST_IMG.src"
108 _make_test_img $(du -b "$TEST_IMG.src" | cut -f1) | _filter_img_create_size
110 run_qemu "$TEST_IMG" "$TEST_IMG.src" "" "BLOCK_JOB_ERROR" |
111 _filter_block_job_offset | _filter_block_job_len
112 $QEMU_IO -c 'read -P 0 0 512' "$TEST_IMG" | _filter_qemu_io
114 run_qemu "$TEST_IMG" "$TEST_IMG.src" "'format': 'raw'," "BLOCK_JOB_READY"
115 $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src"
119 echo "=== Write legitimate MBR into raw ==="
122 for sample_img in grub_mbr.raw; do
123 bzcat "$SAMPLE_IMG_DIR/$sample_img.bz2" > "$TEST_IMG.src"
124 _make_test_img $(du -b "$TEST_IMG.src" | cut -f1) | _filter_img_create_size
126 run_qemu "$TEST_IMG" "$TEST_IMG.src" "" "BLOCK_JOB_READY"
127 $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src"
129 run_qemu "$TEST_IMG" "$TEST_IMG.src" "'format': 'raw'," "BLOCK_JOB_READY"
130 $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src"