xref: /openbmc/qemu/tests/qemu-iotests/015 (revision 5262caa75468adce44b57ed9c076b2f22bd9315f)
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
46*5262caa7SMax Reitz# Internal snapshots are (currently) impossible with refcount_bits=1
47*5262caa7SMax Reitz_unsupported_imgopts 'refcount_bits=1[^0-9]'
483778057dSKevin Wolf
493778057dSKevin Wolfecho
503778057dSKevin Wolfecho "creating image"
513778057dSKevin Wolf
523778057dSKevin Wolf# With 1k clusters a refcount block contains 512 clusters
533778057dSKevin Wolf# This makes 512k of the image file covered by a refcount block
543778057dSKevin Wolf# A refcount table that spans one clusters has 128 refcount
553778057dSKevin Wolf# tables which makes up 64M in the image file.
563778057dSKevin Wolf#
573778057dSKevin Wolf# We use a 36M image, so initially we can be sure that only one cluster is used
583778057dSKevin Wolf# for the refcount table. On the other hand this is big enough to cause a
593778057dSKevin Wolf# refcount table growth when rewriting the image after creating one snapshot.
603778057dSKevin Wolfsize=36M
61bfe85248SKevin WolfCLUSTER_SIZE=1k
62bfe85248SKevin Wolf_make_test_img $size
633778057dSKevin Wolf
643778057dSKevin Wolf# Create two snapshots which fill the image with two different patterns
653778057dSKevin Wolfecho "creating first snapshot"
66fef9c191SJeff Cody$QEMU_IO -c "aio_write -P 123 0 $size" "$TEST_IMG" | _filter_qemu_io
67fef9c191SJeff Cody$QEMU_IMG snapshot -c snap1 "$TEST_IMG"
683778057dSKevin Wolfecho "creating second snapshot"
69fef9c191SJeff Cody$QEMU_IO -c "aio_write -P 165 0 $size" "$TEST_IMG" | _filter_qemu_io
70fef9c191SJeff Cody$QEMU_IMG snapshot -c snap2 "$TEST_IMG"
713778057dSKevin Wolf
723778057dSKevin Wolf# Now check the pattern
733778057dSKevin Wolfecho "checking first snapshot"
74fef9c191SJeff Cody$QEMU_IMG snapshot -a snap1 "$TEST_IMG"
75fef9c191SJeff Cody$QEMU_IO -c "aio_read -P 123 0 $size" "$TEST_IMG" | _filter_qemu_io
763778057dSKevin Wolfecho "checking second snapshot"
77fef9c191SJeff Cody$QEMU_IMG snapshot -a snap2 "$TEST_IMG"
78fef9c191SJeff Cody$QEMU_IO -c "aio_read -P 165 0 $size" "$TEST_IMG" | _filter_qemu_io
793778057dSKevin Wolf
803778057dSKevin Wolfecho
813778057dSKevin Wolfecho "checking image for errors"
823778057dSKevin Wolf_check_test_img
833778057dSKevin Wolf
843778057dSKevin Wolf# success, all done
853778057dSKevin Wolfecho "*** done"
863778057dSKevin Wolfrm -f $seq.full
873778057dSKevin Wolfstatus=0
88