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_require_disk_usage 45 46echo 47echo "=== Check mapping of unaligned raw image ===" 48echo 49 50# We do not know how large a physical sector is, but it is certainly 51# going to be a factor of 1 MB 52size=$((1 * 1024 * 1024 - 1)) 53 54# qemu-img create rounds size up to BDRV_SECTOR_SIZE 55_make_test_img $size 56$QEMU_IMG map --output=json --image-opts \ 57 "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \ 58 | _filter_qemu_img_map 59 60# so we resize it and check again 61truncate --size=$size "$TEST_IMG" 62$QEMU_IMG map --output=json --image-opts \ 63 "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \ 64 | _filter_qemu_img_map 65 66# qemu-io with O_DIRECT always writes whole physical sectors. Again, 67# we do not know how large a physical sector is, so we just start 68# writing from a 64 kB boundary, which should always be aligned. 69offset=$((1 * 1024 * 1024 - 64 * 1024)) 70$QEMU_IO -c "w $offset $((size - offset))" "$TEST_IMG" | _filter_qemu_io 71$QEMU_IMG map --output=json --image-opts \ 72 "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \ 73 | _filter_qemu_img_map 74 75# Resize it and check again -- contrary to 221, we may not get partial 76# sectors here, so there should be only two areas (one zero, one 77# data). 78truncate --size=$size "$TEST_IMG" 79$QEMU_IMG map --output=json --image-opts \ 80 "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \ 81 | _filter_qemu_img_map 82 83# success, all done 84echo '*** done' 85rm -f $seq.full 86status=0 87