111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 23778057dSKevin Wolf# 33778057dSKevin Wolf# Combined test to grow the refcount table and test snapshots. 43778057dSKevin Wolf# 53778057dSKevin Wolf# Copyright (C) 2009 Red Hat, Inc. 63778057dSKevin Wolf# 73778057dSKevin Wolf# This program is free software; you can redistribute it and/or modify 83778057dSKevin Wolf# it under the terms of the GNU General Public License as published by 93778057dSKevin Wolf# the Free Software Foundation; either version 2 of the License, or 103778057dSKevin Wolf# (at your option) any later version. 113778057dSKevin Wolf# 123778057dSKevin Wolf# This program is distributed in the hope that it will be useful, 133778057dSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 143778057dSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 153778057dSKevin Wolf# GNU General Public License for more details. 163778057dSKevin Wolf# 173778057dSKevin Wolf# You should have received a copy of the GNU General Public License 18e8c212d6SChristoph Hellwig# along with this program. If not, see <http://www.gnu.org/licenses/>. 193778057dSKevin Wolf# 203778057dSKevin Wolf 213778057dSKevin Wolf# creator 223778057dSKevin Wolfowner=kwolf@redhat.com 233778057dSKevin Wolf 243778057dSKevin Wolfseq=`basename $0` 253778057dSKevin Wolfecho "QA output created by $seq" 263778057dSKevin Wolf 273778057dSKevin Wolfstatus=1 # failure is the default! 283778057dSKevin Wolf 293778057dSKevin Wolf_cleanup() 303778057dSKevin Wolf{ 31e021915aSChristoph Hellwig _cleanup_test_img 323778057dSKevin Wolf true 333778057dSKevin Wolf} 343778057dSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 353778057dSKevin Wolf 363778057dSKevin Wolf# get standard environment, filters and checks 373778057dSKevin Wolf. ./common.rc 383778057dSKevin Wolf. ./common.filter 393778057dSKevin Wolf 40e76a8e89SChristoph Hellwig# actually any format that supports snapshots 413778057dSKevin Wolf_supported_fmt qcow2 429cdfa1b3SMORITA Kazutaka_supported_proto generic 43*3be2024aSMax Reitz# Internal snapshots are (currently) impossible with refcount_bits=1, 44*3be2024aSMax Reitz# and generally impossible with external data files 45*3be2024aSMax Reitz_unsupported_imgopts 'refcount_bits=1[^0-9]' data_file 463778057dSKevin Wolf 473778057dSKevin Wolfecho 483778057dSKevin Wolfecho "creating image" 493778057dSKevin Wolf 503778057dSKevin Wolf# With 1k clusters a refcount block contains 512 clusters 513778057dSKevin Wolf# This makes 512k of the image file covered by a refcount block 523778057dSKevin Wolf# A refcount table that spans one clusters has 128 refcount 533778057dSKevin Wolf# tables which makes up 64M in the image file. 543778057dSKevin Wolf# 553778057dSKevin Wolf# We use a 36M image, so initially we can be sure that only one cluster is used 563778057dSKevin Wolf# for the refcount table. On the other hand this is big enough to cause a 573778057dSKevin Wolf# refcount table growth when rewriting the image after creating one snapshot. 583778057dSKevin Wolfsize=36M 59bfe85248SKevin WolfCLUSTER_SIZE=1k 60bfe85248SKevin Wolf_make_test_img $size 613778057dSKevin Wolf 623778057dSKevin Wolf# Create two snapshots which fill the image with two different patterns 633778057dSKevin Wolfecho "creating first snapshot" 64fef9c191SJeff Cody$QEMU_IO -c "aio_write -P 123 0 $size" "$TEST_IMG" | _filter_qemu_io 65fef9c191SJeff Cody$QEMU_IMG snapshot -c snap1 "$TEST_IMG" 663778057dSKevin Wolfecho "creating second snapshot" 67fef9c191SJeff Cody$QEMU_IO -c "aio_write -P 165 0 $size" "$TEST_IMG" | _filter_qemu_io 68fef9c191SJeff Cody$QEMU_IMG snapshot -c snap2 "$TEST_IMG" 693778057dSKevin Wolf 703778057dSKevin Wolf# Now check the pattern 713778057dSKevin Wolfecho "checking first snapshot" 72fef9c191SJeff Cody$QEMU_IMG snapshot -a snap1 "$TEST_IMG" 73fef9c191SJeff Cody$QEMU_IO -c "aio_read -P 123 0 $size" "$TEST_IMG" | _filter_qemu_io 743778057dSKevin Wolfecho "checking second snapshot" 75fef9c191SJeff Cody$QEMU_IMG snapshot -a snap2 "$TEST_IMG" 76fef9c191SJeff Cody$QEMU_IO -c "aio_read -P 165 0 $size" "$TEST_IMG" | _filter_qemu_io 773778057dSKevin Wolf 783778057dSKevin Wolfecho 793778057dSKevin Wolfecho "checking image for errors" 803778057dSKevin Wolf_check_test_img 813778057dSKevin Wolf 823778057dSKevin Wolf# success, all done 833778057dSKevin Wolfecho "*** done" 843778057dSKevin Wolfrm -f $seq.full 853778057dSKevin Wolfstatus=0 86