111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2c6a9d2f6SEric Blake# 3c6a9d2f6SEric Blake# Test qemu-img vs. unaligned images 42fab30c8SMax Reitz# (See also 253, which is the O_DIRECT version) 5c6a9d2f6SEric Blake# 6d3192de7SEric Blake# Copyright (C) 2018-2019 Red Hat, Inc. 7c6a9d2f6SEric Blake# 8c6a9d2f6SEric Blake# This program is free software; you can redistribute it and/or modify 9c6a9d2f6SEric Blake# it under the terms of the GNU General Public License as published by 10c6a9d2f6SEric Blake# the Free Software Foundation; either version 2 of the License, or 11c6a9d2f6SEric Blake# (at your option) any later version. 12c6a9d2f6SEric Blake# 13c6a9d2f6SEric Blake# This program is distributed in the hope that it will be useful, 14c6a9d2f6SEric Blake# but WITHOUT ANY WARRANTY; without even the implied warranty of 15c6a9d2f6SEric Blake# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16c6a9d2f6SEric Blake# GNU General Public License for more details. 17c6a9d2f6SEric Blake# 18c6a9d2f6SEric Blake# You should have received a copy of the GNU General Public License 19c6a9d2f6SEric Blake# along with this program. If not, see <http://www.gnu.org/licenses/>. 20c6a9d2f6SEric Blake# 21c6a9d2f6SEric Blake 22c6a9d2f6SEric Blakeseq="$(basename $0)" 23c6a9d2f6SEric Blakeecho "QA output created by $seq" 24c6a9d2f6SEric Blake 25c6a9d2f6SEric Blakestatus=1 # failure is the default! 26c6a9d2f6SEric Blake 27c6a9d2f6SEric Blake_cleanup() 28c6a9d2f6SEric Blake{ 29c6a9d2f6SEric Blake _cleanup_test_img 30c6a9d2f6SEric Blake} 31c6a9d2f6SEric Blaketrap "_cleanup; exit \$status" 0 1 2 3 15 32c6a9d2f6SEric Blake 33c6a9d2f6SEric Blake# get standard environment, filters and checks 34c6a9d2f6SEric Blake. ./common.rc 35c6a9d2f6SEric Blake. ./common.filter 36c6a9d2f6SEric Blake 37c6a9d2f6SEric Blake_supported_fmt raw 3857284d2aSMax Reitz_supported_proto file fuse 39c6a9d2f6SEric Blake_supported_os Linux 40c6a9d2f6SEric Blake 412fab30c8SMax Reitz_default_cache_mode writeback 422fab30c8SMax Reitz_supported_cache_modes writeback writethrough unsafe 432fab30c8SMax Reitz 44c6a9d2f6SEric Blakeecho 45c6a9d2f6SEric Blakeecho "=== Check mapping of unaligned raw image ===" 46c6a9d2f6SEric Blakeecho 47c6a9d2f6SEric Blake 48d3192de7SEric Blake_make_test_img 65537 # qemu-img create rounds size up 49*f0947dc6SMax Reitz 50*f0947dc6SMax Reitz# file-posix allocates the first block of any images when it is created; 51*f0947dc6SMax Reitz# the size of this block depends on the host page size and the file 52*f0947dc6SMax Reitz# system block size, none of which are constant. Discard the whole 53*f0947dc6SMax Reitz# image so we will not see this allocation in qemu-img map's output. 54*f0947dc6SMax Reitz$QEMU_IO -c 'discard 0 65537' "$TEST_IMG" | _filter_qemu_io 55*f0947dc6SMax Reitz 56c6a9d2f6SEric Blake$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 57c6a9d2f6SEric Blake 58d3192de7SEric Blaketruncate --size=65537 "$TEST_IMG" # so we resize it and check again 59c6a9d2f6SEric Blake$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 60c6a9d2f6SEric Blake 61d3192de7SEric Blake$QEMU_IO -c 'w 65536 1' "$TEST_IMG" | _filter_qemu_io # writing also rounds up 62c6a9d2f6SEric Blake$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 63c6a9d2f6SEric Blake 64d3192de7SEric Blaketruncate --size=65537 "$TEST_IMG" # so we resize it and check again 65c6a9d2f6SEric Blake$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 66c6a9d2f6SEric Blake 67c6a9d2f6SEric Blake# success, all done 68c6a9d2f6SEric Blakeecho '*** done' 69c6a9d2f6SEric Blakerm -f $seq.full 70c6a9d2f6SEric Blakestatus=0 71