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