xref: /openbmc/qemu/tests/qemu-iotests/253 (revision 6e0bc06e)
1#!/usr/bin/env bash
2# group: rw quick
3#
4# Test qemu-img vs. unaligned images; O_DIRECT version
5# (Originates from 221)
6#
7# Copyright (C) 2019 Red Hat, Inc.
8#
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.
13#
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.
18#
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/>.
21#
22
23seq="$(basename $0)"
24echo "QA output created by $seq"
25
26status=1 # failure is the default!
27
28_cleanup()
29{
30    _cleanup_test_img
31}
32trap "_cleanup; exit \$status" 0 1 2 3 15
33
34# get standard environment, filters and checks
35. ./common.rc
36. ./common.filter
37
38_supported_fmt raw
39_supported_proto file
40_supported_os Linux
41
42_default_cache_mode none
43_supported_cache_modes none directsync
44
45echo
46echo "=== Check mapping of unaligned raw image ==="
47echo
48
49# We do not know how large a physical sector is, but it is certainly
50# going to be a factor of 1 MB
51size=$((1 * 1024 * 1024 - 1))
52
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
58
59# so we resize it and check again
60truncate --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
64
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.
68offset=$((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
73
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).
77truncate --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
81
82# success, all done
83echo '*** done'
84rm -f $seq.full
85status=0
86