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