Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / tests / qemu-iotests / 253
blob35039d20a8936e380b786500e77b4e7ef94b1184
1 #!/usr/bin/env bash
2 # group: rw quick
4 # Test qemu-img vs. unaligned images; O_DIRECT version
5 # (Originates from 221)
7 # Copyright (C) 2019 Red Hat, Inc.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 seq="$(basename $0)"
24 echo "QA output created by $seq"
26 status=1 # failure is the default!
28 _cleanup()
30 _cleanup_test_img
32 trap "_cleanup; exit \$status" 0 1 2 3 15
34 # get standard environment, filters and checks
35 . ./common.rc
36 . ./common.filter
38 _supported_fmt raw
39 _supported_proto file
40 _supported_os Linux
42 _default_cache_mode none
43 _supported_cache_modes none directsync
45 echo
46 echo "=== Check mapping of unaligned raw image ==="
47 echo
49 # We do not know how large a physical sector is, but it is certainly
50 # going to be a factor of 1 MB
51 size=$((1 * 1024 * 1024 - 1))
53 # qemu-img create rounds size up to BDRV_SECTOR_SIZE
54 _make_test_img $size
55 $QEMU_IMG map --output=json --image-opts \
56 "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \
57 | _filter_qemu_img_map
59 # so we resize it and check again
60 truncate --size=$size "$TEST_IMG"
61 $QEMU_IMG map --output=json --image-opts \
62 "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \
63 | _filter_qemu_img_map
65 # qemu-io with O_DIRECT always writes whole physical sectors. Again,
66 # we do not know how large a physical sector is, so we just start
67 # writing from a 64 kB boundary, which should always be aligned.
68 offset=$((1 * 1024 * 1024 - 64 * 1024))
69 $QEMU_IO -c "w $offset $((size - offset))" "$TEST_IMG" | _filter_qemu_io
70 $QEMU_IMG map --output=json --image-opts \
71 "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \
72 | _filter_qemu_img_map
74 # Resize it and check again -- contrary to 221, we may not get partial
75 # sectors here, so there should be only two areas (one zero, one
76 # data).
77 truncate --size=$size "$TEST_IMG"
78 $QEMU_IMG map --output=json --image-opts \
79 "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \
80 | _filter_qemu_img_map
82 # success, all done
83 echo '*** done'
84 rm -f $seq.full
85 status=0