1*52f2b896SVladimir Sementsov-Ogievskiy#!/bin/bash 2*52f2b896SVladimir Sementsov-Ogievskiy# 3*52f2b896SVladimir Sementsov-Ogievskiy# Test lseek influence on qcow2 block-status 4*52f2b896SVladimir Sementsov-Ogievskiy# 5*52f2b896SVladimir Sementsov-Ogievskiy# Block layer may recursively check block_status in file child of qcow2, if 6*52f2b896SVladimir Sementsov-Ogievskiy# qcow2 driver returned DATA. There are several test cases to check influence 7*52f2b896SVladimir Sementsov-Ogievskiy# of lseek on block_status performance. To see real difference run on tmpfs. 8*52f2b896SVladimir Sementsov-Ogievskiy# 9*52f2b896SVladimir Sementsov-Ogievskiy# Copyright (c) 2019 Virtuozzo International GmbH. All rights reserved. 10*52f2b896SVladimir Sementsov-Ogievskiy# 11*52f2b896SVladimir Sementsov-Ogievskiy# Tests originally written by Kevin Wolf 12*52f2b896SVladimir Sementsov-Ogievskiy# 13*52f2b896SVladimir Sementsov-Ogievskiy# This program is free software; you can redistribute it and/or modify 14*52f2b896SVladimir Sementsov-Ogievskiy# it under the terms of the GNU General Public License as published by 15*52f2b896SVladimir Sementsov-Ogievskiy# the Free Software Foundation; either version 2 of the License, or 16*52f2b896SVladimir Sementsov-Ogievskiy# (at your option) any later version. 17*52f2b896SVladimir Sementsov-Ogievskiy# 18*52f2b896SVladimir Sementsov-Ogievskiy# This program is distributed in the hope that it will be useful, 19*52f2b896SVladimir Sementsov-Ogievskiy# but WITHOUT ANY WARRANTY; without even the implied warranty of 20*52f2b896SVladimir Sementsov-Ogievskiy# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21*52f2b896SVladimir Sementsov-Ogievskiy# GNU General Public License for more details. 22*52f2b896SVladimir Sementsov-Ogievskiy# 23*52f2b896SVladimir Sementsov-Ogievskiy# You should have received a copy of the GNU General Public License 24*52f2b896SVladimir Sementsov-Ogievskiy# along with this program. If not, see <http://www.gnu.org/licenses/>. 25*52f2b896SVladimir Sementsov-Ogievskiy# 26*52f2b896SVladimir Sementsov-Ogievskiy 27*52f2b896SVladimir Sementsov-Ogievskiyif [ "$#" -lt 1 ]; then 28*52f2b896SVladimir Sementsov-Ogievskiy echo "Usage: $0 SOURCE_FILE" 29*52f2b896SVladimir Sementsov-Ogievskiy exit 1 30*52f2b896SVladimir Sementsov-Ogievskiyfi 31*52f2b896SVladimir Sementsov-Ogievskiy 32*52f2b896SVladimir Sementsov-OgievskiyROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../../../.." >/dev/null 2>&1 && pwd )" 33*52f2b896SVladimir Sementsov-OgievskiyQEMU_IMG="$ROOT_DIR/qemu-img" 34*52f2b896SVladimir Sementsov-OgievskiyQEMU_IO="$ROOT_DIR/qemu-io" 35*52f2b896SVladimir Sementsov-Ogievskiy 36*52f2b896SVladimir Sementsov-Ogievskiysize=1G 37*52f2b896SVladimir Sementsov-Ogievskiysrc="$1" 38*52f2b896SVladimir Sementsov-Ogievskiy 39*52f2b896SVladimir Sementsov-Ogievskiy# test-case plain 40*52f2b896SVladimir Sementsov-Ogievskiy 41*52f2b896SVladimir Sementsov-Ogievskiy( 42*52f2b896SVladimir Sementsov-Ogievskiy$QEMU_IMG create -f qcow2 "$src" $size 43*52f2b896SVladimir Sementsov-Ogievskiyfor i in $(seq 16384 -1 0); do 44*52f2b896SVladimir Sementsov-Ogievskiy echo "write $((i * 65536)) 64k" 45*52f2b896SVladimir Sementsov-Ogievskiydone | $QEMU_IO "$src" 46*52f2b896SVladimir Sementsov-Ogievskiy) > /dev/null 47*52f2b896SVladimir Sementsov-Ogievskiy 48*52f2b896SVladimir Sementsov-Ogievskiyecho -n "plain: " 49*52f2b896SVladimir Sementsov-Ogievskiy/usr/bin/time -f %e $QEMU_IMG convert -n "$src" null-co:// 50*52f2b896SVladimir Sementsov-Ogievskiy 51*52f2b896SVladimir Sementsov-Ogievskiy# test-case forward 52*52f2b896SVladimir Sementsov-Ogievskiy 53*52f2b896SVladimir Sementsov-Ogievskiy( 54*52f2b896SVladimir Sementsov-Ogievskiy$QEMU_IMG create -f qcow2 "$src" $size 55*52f2b896SVladimir Sementsov-Ogievskiyfor i in $(seq 0 2 16384); do 56*52f2b896SVladimir Sementsov-Ogievskiy echo "write $((i * 65536)) 64k" 57*52f2b896SVladimir Sementsov-Ogievskiydone | $QEMU_IO "$src" 58*52f2b896SVladimir Sementsov-Ogievskiyfor i in $(seq 1 2 16384); do 59*52f2b896SVladimir Sementsov-Ogievskiy echo "write $((i * 65536)) 64k" 60*52f2b896SVladimir Sementsov-Ogievskiydone | $QEMU_IO "$src" 61*52f2b896SVladimir Sementsov-Ogievskiy) > /dev/null 62*52f2b896SVladimir Sementsov-Ogievskiy 63*52f2b896SVladimir Sementsov-Ogievskiyecho -n "forward: " 64*52f2b896SVladimir Sementsov-Ogievskiy/usr/bin/time -f %e $QEMU_IMG convert -n "$src" null-co:// 65*52f2b896SVladimir Sementsov-Ogievskiy 66*52f2b896SVladimir Sementsov-Ogievskiy# test-case prealloc 67*52f2b896SVladimir Sementsov-Ogievskiy 68*52f2b896SVladimir Sementsov-Ogievskiy$QEMU_IMG create -f qcow2 -o preallocation=metadata "$src" $size > /dev/null 69*52f2b896SVladimir Sementsov-Ogievskiy 70*52f2b896SVladimir Sementsov-Ogievskiyecho -n "prealloc: " 71*52f2b896SVladimir Sementsov-Ogievskiy/usr/bin/time -f %e $QEMU_IMG convert -n "$src" null-co:// 72