3 # Test qemu-img vs. unaligned images; O_DIRECT version
4 # (Originates from 221)
6 # Copyright (C) 2019 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 echo "QA output created by $seq"
25 status
=1 # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
33 # get standard environment, filters and checks
41 _default_cache_mode none
42 _supported_cache_modes none directsync
45 echo "=== Check mapping of unaligned raw image ==="
48 # We do not know how large a physical sector is, but it is certainly
49 # going to be a factor of 1 MB
50 size
=$
((1 * 1024 * 1024 - 1))
52 # qemu-img create rounds size up to BDRV_SECTOR_SIZE
54 $QEMU_IMG map
--output=json
--image-opts \
55 "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \
56 | _filter_qemu_img_map
58 # so we resize it and check again
59 truncate
--size=$size "$TEST_IMG"
60 $QEMU_IMG map
--output=json
--image-opts \
61 "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \
62 | _filter_qemu_img_map
64 # qemu-io with O_DIRECT always writes whole physical sectors. Again,
65 # we do not know how large a physical sector is, so we just start
66 # writing from a 64 kB boundary, which should always be aligned.
67 offset
=$
((1 * 1024 * 1024 - 64 * 1024))
68 $QEMU_IO -c "w $offset $((size - offset))" "$TEST_IMG" | _filter_qemu_io
69 $QEMU_IMG map
--output=json
--image-opts \
70 "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \
71 | _filter_qemu_img_map
73 # Resize it and check again -- contrary to 221, we may not get partial
74 # sectors here, so there should be only two areas (one zero, one
76 truncate
--size=$size "$TEST_IMG"
77 $QEMU_IMG map
--output=json
--image-opts \
78 "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \
79 | _filter_qemu_img_map