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