xref: /qemu/tests/qemu-iotests/015 (revision bfe852486224d604c259b362bc4c952cc934ef0b)
1908eaf68SStefan Hajnoczi#!/bin/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 Wolfhere=`pwd`
283778057dSKevin Wolftmp=/tmp/$$
293778057dSKevin Wolfstatus=1	# failure is the default!
303778057dSKevin Wolf
313778057dSKevin Wolf_cleanup()
323778057dSKevin Wolf{
33e021915aSChristoph Hellwig	_cleanup_test_img
343778057dSKevin Wolf	true
353778057dSKevin Wolf}
363778057dSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
373778057dSKevin Wolf
383778057dSKevin Wolf# get standard environment, filters and checks
393778057dSKevin Wolf. ./common.rc
403778057dSKevin Wolf. ./common.filter
413778057dSKevin Wolf
42e76a8e89SChristoph Hellwig# actually any format that supports snapshots
433778057dSKevin Wolf_supported_fmt qcow2
449cdfa1b3SMORITA Kazutaka_supported_proto generic
453778057dSKevin Wolf_supported_os Linux
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
59*bfe85248SKevin WolfCLUSTER_SIZE=1k
60*bfe85248SKevin 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"
643778057dSKevin Wolf$QEMU_IO -c "aio_write -P 123 0 $size" $TEST_IMG | _filter_qemu_io
653778057dSKevin Wolf$QEMU_IMG snapshot -c snap1 $TEST_IMG
663778057dSKevin Wolfecho "creating second snapshot"
673778057dSKevin Wolf$QEMU_IO -c "aio_write -P 165 0 $size" $TEST_IMG | _filter_qemu_io
683778057dSKevin Wolf$QEMU_IMG snapshot -c snap2 $TEST_IMG
693778057dSKevin Wolf
703778057dSKevin Wolf# Now check the pattern
713778057dSKevin Wolfecho "checking first snapshot"
723778057dSKevin Wolf$QEMU_IMG snapshot -a snap1 $TEST_IMG
733778057dSKevin Wolf$QEMU_IO -c "aio_read -P 123 0 $size" $TEST_IMG | _filter_qemu_io
743778057dSKevin Wolfecho "checking second snapshot"
753778057dSKevin Wolf$QEMU_IMG snapshot -a snap2 $TEST_IMG
763778057dSKevin Wolf$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