1*2fab30c8SMax Reitz#!/usr/bin/env bash 2*2fab30c8SMax Reitz# 3*2fab30c8SMax Reitz# Test qemu-img vs. unaligned images; O_DIRECT version 4*2fab30c8SMax Reitz# (Originates from 221) 5*2fab30c8SMax Reitz# 6*2fab30c8SMax Reitz# Copyright (C) 2019 Red Hat, Inc. 7*2fab30c8SMax Reitz# 8*2fab30c8SMax Reitz# This program is free software; you can redistribute it and/or modify 9*2fab30c8SMax Reitz# it under the terms of the GNU General Public License as published by 10*2fab30c8SMax Reitz# the Free Software Foundation; either version 2 of the License, or 11*2fab30c8SMax Reitz# (at your option) any later version. 12*2fab30c8SMax Reitz# 13*2fab30c8SMax Reitz# This program is distributed in the hope that it will be useful, 14*2fab30c8SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 15*2fab30c8SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*2fab30c8SMax Reitz# GNU General Public License for more details. 17*2fab30c8SMax Reitz# 18*2fab30c8SMax Reitz# You should have received a copy of the GNU General Public License 19*2fab30c8SMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 20*2fab30c8SMax Reitz# 21*2fab30c8SMax Reitz 22*2fab30c8SMax Reitzseq="$(basename $0)" 23*2fab30c8SMax Reitzecho "QA output created by $seq" 24*2fab30c8SMax Reitz 25*2fab30c8SMax Reitzstatus=1 # failure is the default! 26*2fab30c8SMax Reitz 27*2fab30c8SMax Reitz_cleanup() 28*2fab30c8SMax Reitz{ 29*2fab30c8SMax Reitz _cleanup_test_img 30*2fab30c8SMax Reitz} 31*2fab30c8SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15 32*2fab30c8SMax Reitz 33*2fab30c8SMax Reitz# get standard environment, filters and checks 34*2fab30c8SMax Reitz. ./common.rc 35*2fab30c8SMax Reitz. ./common.filter 36*2fab30c8SMax Reitz 37*2fab30c8SMax Reitz_supported_fmt raw 38*2fab30c8SMax Reitz_supported_proto file 39*2fab30c8SMax Reitz_supported_os Linux 40*2fab30c8SMax Reitz 41*2fab30c8SMax Reitz_default_cache_mode none 42*2fab30c8SMax Reitz_supported_cache_modes none directsync 43*2fab30c8SMax Reitz 44*2fab30c8SMax Reitzecho 45*2fab30c8SMax Reitzecho "=== Check mapping of unaligned raw image ===" 46*2fab30c8SMax Reitzecho 47*2fab30c8SMax Reitz 48*2fab30c8SMax Reitz# We do not know how large a physical sector is, but it is certainly 49*2fab30c8SMax Reitz# going to be a factor of 1 MB 50*2fab30c8SMax Reitzsize=$((1 * 1024 * 1024 - 1)) 51*2fab30c8SMax Reitz 52*2fab30c8SMax Reitz# qemu-img create rounds size up to BDRV_SECTOR_SIZE 53*2fab30c8SMax Reitz_make_test_img $size 54*2fab30c8SMax Reitz$QEMU_IMG map --output=json --image-opts \ 55*2fab30c8SMax Reitz "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \ 56*2fab30c8SMax Reitz | _filter_qemu_img_map 57*2fab30c8SMax Reitz 58*2fab30c8SMax Reitz# so we resize it and check again 59*2fab30c8SMax Reitztruncate --size=$size "$TEST_IMG" 60*2fab30c8SMax Reitz$QEMU_IMG map --output=json --image-opts \ 61*2fab30c8SMax Reitz "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \ 62*2fab30c8SMax Reitz | _filter_qemu_img_map 63*2fab30c8SMax Reitz 64*2fab30c8SMax Reitz# qemu-io with O_DIRECT always writes whole physical sectors. Again, 65*2fab30c8SMax Reitz# we do not know how large a physical sector is, so we just start 66*2fab30c8SMax Reitz# writing from a 64 kB boundary, which should always be aligned. 67*2fab30c8SMax Reitzoffset=$((1 * 1024 * 1024 - 64 * 1024)) 68*2fab30c8SMax Reitz$QEMU_IO -c "w $offset $((size - offset))" "$TEST_IMG" | _filter_qemu_io 69*2fab30c8SMax Reitz$QEMU_IMG map --output=json --image-opts \ 70*2fab30c8SMax Reitz "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \ 71*2fab30c8SMax Reitz | _filter_qemu_img_map 72*2fab30c8SMax Reitz 73*2fab30c8SMax Reitz# Resize it and check again -- contrary to 221, we may not get partial 74*2fab30c8SMax Reitz# sectors here, so there should be only two areas (one zero, one 75*2fab30c8SMax Reitz# data). 76*2fab30c8SMax Reitztruncate --size=$size "$TEST_IMG" 77*2fab30c8SMax Reitz$QEMU_IMG map --output=json --image-opts \ 78*2fab30c8SMax Reitz "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \ 79*2fab30c8SMax Reitz | _filter_qemu_img_map 80*2fab30c8SMax Reitz 81*2fab30c8SMax Reitz# success, all done 82*2fab30c8SMax Reitzecho '*** done' 83*2fab30c8SMax Reitzrm -f $seq.full 84*2fab30c8SMax Reitzstatus=0 85