xref: /openbmc/qemu/tests/qemu-iotests/253 (revision fef80ea073c4862bc9eaddb6ddb0ed970b8ad7c4)
12fab30c8SMax Reitz#!/usr/bin/env bash
2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick
32fab30c8SMax Reitz#
42fab30c8SMax Reitz# Test qemu-img vs. unaligned images; O_DIRECT version
52fab30c8SMax Reitz# (Originates from 221)
62fab30c8SMax Reitz#
72fab30c8SMax Reitz# Copyright (C) 2019 Red Hat, Inc.
82fab30c8SMax Reitz#
92fab30c8SMax Reitz# This program is free software; you can redistribute it and/or modify
102fab30c8SMax Reitz# it under the terms of the GNU General Public License as published by
112fab30c8SMax Reitz# the Free Software Foundation; either version 2 of the License, or
122fab30c8SMax Reitz# (at your option) any later version.
132fab30c8SMax Reitz#
142fab30c8SMax Reitz# This program is distributed in the hope that it will be useful,
152fab30c8SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
162fab30c8SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
172fab30c8SMax Reitz# GNU General Public License for more details.
182fab30c8SMax Reitz#
192fab30c8SMax Reitz# You should have received a copy of the GNU General Public License
202fab30c8SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
212fab30c8SMax Reitz#
222fab30c8SMax Reitz
232fab30c8SMax Reitzseq="$(basename $0)"
242fab30c8SMax Reitzecho "QA output created by $seq"
252fab30c8SMax Reitz
262fab30c8SMax Reitzstatus=1 # failure is the default!
272fab30c8SMax Reitz
282fab30c8SMax Reitz_cleanup()
292fab30c8SMax Reitz{
302fab30c8SMax Reitz    _cleanup_test_img
312fab30c8SMax Reitz}
322fab30c8SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
332fab30c8SMax Reitz
342fab30c8SMax Reitz# get standard environment, filters and checks
352fab30c8SMax Reitz. ./common.rc
362fab30c8SMax Reitz. ./common.filter
372fab30c8SMax Reitz
382fab30c8SMax Reitz_supported_fmt raw
392fab30c8SMax Reitz_supported_proto file
402fab30c8SMax Reitz_supported_os Linux
412fab30c8SMax Reitz
422fab30c8SMax Reitz_default_cache_mode none
432fab30c8SMax Reitz_supported_cache_modes none directsync
442fab30c8SMax Reitz
452fab30c8SMax Reitzecho
462fab30c8SMax Reitzecho "=== Check mapping of unaligned raw image ==="
472fab30c8SMax Reitzecho
482fab30c8SMax Reitz
492fab30c8SMax Reitz# We do not know how large a physical sector is, but it is certainly
502fab30c8SMax Reitz# going to be a factor of 1 MB
512fab30c8SMax Reitzsize=$((1 * 1024 * 1024 - 1))
522fab30c8SMax Reitz
532fab30c8SMax Reitz# qemu-img create rounds size up to BDRV_SECTOR_SIZE
542fab30c8SMax Reitz_make_test_img $size
552fab30c8SMax Reitz$QEMU_IMG map --output=json --image-opts \
562fab30c8SMax Reitz    "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \
572fab30c8SMax Reitz    | _filter_qemu_img_map
582fab30c8SMax Reitz
592fab30c8SMax Reitz# so we resize it and check again
602fab30c8SMax Reitztruncate --size=$size "$TEST_IMG"
612fab30c8SMax Reitz$QEMU_IMG map --output=json --image-opts \
622fab30c8SMax Reitz    "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \
632fab30c8SMax Reitz    | _filter_qemu_img_map
642fab30c8SMax Reitz
652fab30c8SMax Reitz# qemu-io with O_DIRECT always writes whole physical sectors.  Again,
662fab30c8SMax Reitz# we do not know how large a physical sector is, so we just start
672fab30c8SMax Reitz# writing from a 64 kB boundary, which should always be aligned.
682fab30c8SMax Reitzoffset=$((1 * 1024 * 1024 - 64 * 1024))
692fab30c8SMax Reitz$QEMU_IO -c "w $offset $((size - offset))" "$TEST_IMG" | _filter_qemu_io
702fab30c8SMax Reitz$QEMU_IMG map --output=json --image-opts \
712fab30c8SMax Reitz    "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \
722fab30c8SMax Reitz    | _filter_qemu_img_map
732fab30c8SMax Reitz
742fab30c8SMax Reitz# Resize it and check again -- contrary to 221, we may not get partial
752fab30c8SMax Reitz# sectors here, so there should be only two areas (one zero, one
762fab30c8SMax Reitz# data).
772fab30c8SMax Reitztruncate --size=$size "$TEST_IMG"
782fab30c8SMax Reitz$QEMU_IMG map --output=json --image-opts \
792fab30c8SMax Reitz    "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \
802fab30c8SMax Reitz    | _filter_qemu_img_map
812fab30c8SMax Reitz
822fab30c8SMax Reitz# success, all done
832fab30c8SMax Reitzecho '*** done'
842fab30c8SMax Reitzrm -f $seq.full
852fab30c8SMax Reitzstatus=0
86