111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto backing quick 3bce283ccSKevin Wolf# 4bce283ccSKevin Wolf# Test COW from backing files 5bce283ccSKevin Wolf# 6bce283ccSKevin Wolf# Copyright (C) 2012 Red Hat, Inc. 7bce283ccSKevin Wolf# 8bce283ccSKevin Wolf# This program is free software; you can redistribute it and/or modify 9bce283ccSKevin Wolf# it under the terms of the GNU General Public License as published by 10bce283ccSKevin Wolf# the Free Software Foundation; either version 2 of the License, or 11bce283ccSKevin Wolf# (at your option) any later version. 12bce283ccSKevin Wolf# 13bce283ccSKevin Wolf# This program is distributed in the hope that it will be useful, 14bce283ccSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 15bce283ccSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16bce283ccSKevin Wolf# GNU General Public License for more details. 17bce283ccSKevin Wolf# 18bce283ccSKevin Wolf# You should have received a copy of the GNU General Public License 19bce283ccSKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 20bce283ccSKevin Wolf# 21bce283ccSKevin Wolf 22bce283ccSKevin Wolf# creator 23bce283ccSKevin Wolfowner=kwolf@redhat.com 24bce283ccSKevin Wolf 25bce283ccSKevin Wolfseq=`basename $0` 26bce283ccSKevin Wolfecho "QA output created by $seq" 27bce283ccSKevin Wolf 28bce283ccSKevin Wolfstatus=1 # failure is the default! 29bce283ccSKevin Wolf 30bce283ccSKevin Wolf_cleanup() 31bce283ccSKevin Wolf{ 32bce283ccSKevin Wolf _cleanup_test_img 33bce283ccSKevin Wolf} 34bce283ccSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 35bce283ccSKevin Wolf 36bce283ccSKevin Wolf# get standard environment, filters and checks 37bce283ccSKevin Wolf. ./common.rc 38bce283ccSKevin Wolf. ./common.filter 39bce283ccSKevin Wolf 40bce283ccSKevin Wolf_supported_fmt qcow qcow2 vmdk qed 4157284d2aSMax Reitz_supported_proto file fuse 42d2329f27SFam Zheng_unsupported_imgopts "subformat=monolithicFlat" \ 43d2329f27SFam Zheng "subformat=twoGbMaxExtentFlat" \ 44325dd915SMax Reitz "subformat=twoGbMaxExtentSparse" \ 45325dd915SMax Reitz "subformat=streamOptimized" 46bce283ccSKevin Wolf 47bce283ccSKevin WolfCLUSTER_SIZE=4k 48bce283ccSKevin Wolfsize=128M 49bce283ccSKevin Wolf 50bce283ccSKevin Wolfecho 51bce283ccSKevin Wolfecho "== creating backing file for COW tests ==" 52bce283ccSKevin Wolf 539b652fbeSFam ZhengTEST_IMG_SAVE="$TEST_IMG" 549b652fbeSFam ZhengTEST_IMG="$TEST_IMG.base" 559b652fbeSFam Zheng 56bce283ccSKevin Wolf_make_test_img $size 57bce283ccSKevin Wolf 588cedcffdSEric Blakebacking_io() 59bce283ccSKevin Wolf{ 60bce283ccSKevin Wolf local offset=$1 61bce283ccSKevin Wolf local sectors=$2 62bce283ccSKevin Wolf local op=$3 63bce283ccSKevin Wolf local pattern=0 64bce283ccSKevin Wolf local cur_sec=0 65bce283ccSKevin Wolf 6630edd9faSThomas Huth for ((i=0;i<=$((sectors - 1));i++)); do 67bce283ccSKevin Wolf cur_sec=$((offset / 512 + i)) 68bce283ccSKevin Wolf pattern=$(( ( (cur_sec % 256) + (cur_sec / 256)) % 256 )) 69bce283ccSKevin Wolf 70bce283ccSKevin Wolf echo "$op -P $pattern $((cur_sec * 512)) 512" 71bce283ccSKevin Wolf done 72bce283ccSKevin Wolf} 73bce283ccSKevin Wolf 74fef9c191SJeff Codybacking_io 0 256 write | $QEMU_IO "$TEST_IMG" | _filter_qemu_io 75bce283ccSKevin Wolf 769b652fbeSFam ZhengTEST_IMG="$TEST_IMG_SAVE" 77bce283ccSKevin Wolf 78b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG.base" -F $IMGFMT 6G 79bce283ccSKevin Wolf 80bce283ccSKevin Wolfecho 81bce283ccSKevin Wolfecho "== COW in a single cluster ==" 82fef9c191SJeff Cody$QEMU_IO -c "write -P 0x77 0 2k" "$TEST_IMG" | _filter_qemu_io 83fef9c191SJeff Cody$QEMU_IO -c "write -P 0x88 6k 2k" "$TEST_IMG" | _filter_qemu_io 84fef9c191SJeff Cody$QEMU_IO -c "write -P 0x99 9k 2k" "$TEST_IMG" | _filter_qemu_io 85bce283ccSKevin Wolf 86fef9c191SJeff Cody$QEMU_IO -c "read -P 0x77 0 2k" "$TEST_IMG" | _filter_qemu_io 87fef9c191SJeff Codybacking_io $((2 * 1024)) 8 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io 88fef9c191SJeff Cody$QEMU_IO -c "read -P 0x88 6k 2k" "$TEST_IMG" | _filter_qemu_io 89fef9c191SJeff Codybacking_io $((8 * 1024)) 2 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io 90fef9c191SJeff Cody$QEMU_IO -c "read -P 0x99 9k 2k" "$TEST_IMG" | _filter_qemu_io 91fef9c191SJeff Codybacking_io $((11 * 1024)) 2 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io 92bce283ccSKevin Wolf 93bce283ccSKevin Wolfecho 94bce283ccSKevin Wolfecho "== COW in two-cluster allocations ==" 95fef9c191SJeff Cody$QEMU_IO -c "write -P 0x77 16k 6k" "$TEST_IMG" | _filter_qemu_io 96fef9c191SJeff Cody$QEMU_IO -c "write -P 0x88 26k 6k" "$TEST_IMG" | _filter_qemu_io 97fef9c191SJeff Cody$QEMU_IO -c "write -P 0x99 33k 5k" "$TEST_IMG" | _filter_qemu_io 98bce283ccSKevin Wolf 99fef9c191SJeff Cody$QEMU_IO -c "read -P 0x77 16k 6k" "$TEST_IMG" | _filter_qemu_io 100fef9c191SJeff Codybacking_io $((22 * 1024)) 8 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io 101fef9c191SJeff Cody$QEMU_IO -c "read -P 0x88 26k 6k" "$TEST_IMG" | _filter_qemu_io 102fef9c191SJeff Codybacking_io $((32 * 1024)) 2 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io 103fef9c191SJeff Cody$QEMU_IO -c "read -P 0x99 33k 5k" "$TEST_IMG" | _filter_qemu_io 104fef9c191SJeff Codybacking_io $((38 * 1024)) 4 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io 105bce283ccSKevin Wolf 106bce283ccSKevin Wolfecho 107bce283ccSKevin Wolfecho "== COW in multi-cluster allocations ==" 108fef9c191SJeff Cody$QEMU_IO -c "write -P 0x77 48k 15k" "$TEST_IMG" | _filter_qemu_io 109fef9c191SJeff Cody$QEMU_IO -c "write -P 0x88 66k 14k" "$TEST_IMG" | _filter_qemu_io 110fef9c191SJeff Cody$QEMU_IO -c "write -P 0x99 83k 15k" "$TEST_IMG" | _filter_qemu_io 111bce283ccSKevin Wolf 112fef9c191SJeff Cody$QEMU_IO -c "read -P 0x77 48k 15k" "$TEST_IMG" | _filter_qemu_io 113fef9c191SJeff Codybacking_io $((63 * 1024)) 6 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io 114fef9c191SJeff Cody$QEMU_IO -c "read -P 0x88 66k 14k" "$TEST_IMG" | _filter_qemu_io 115fef9c191SJeff Codybacking_io $((80 * 1024)) 6 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io 116fef9c191SJeff Cody$QEMU_IO -c "read -P 0x99 83k 15k" "$TEST_IMG" | _filter_qemu_io 117fef9c191SJeff Codybacking_io $((98 * 1024)) 4 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io 118bce283ccSKevin Wolf 119bce283ccSKevin Wolf_check_test_img 120bce283ccSKevin Wolf 121bce283ccSKevin Wolf# success, all done 122bce283ccSKevin Wolfecho "*** done" 123bce283ccSKevin Wolfrm -f $seq.full 124bce283ccSKevin Wolfstatus=0 125