1#!/bin/bash 2# 3# qcow2 internal snapshots/VM state tests 4# 5# Copyright (C) 2011 Red Hat, Inc. 6# 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 2 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program. If not, see <http://www.gnu.org/licenses/>. 19# 20 21# creator 22owner=kwolf@redhat.com 23 24seq=`basename $0` 25echo "QA output created by $seq" 26 27here=`pwd` 28status=1 # failure is the default! 29 30_cleanup() 31{ 32 rm -f $TEST_IMG.snap 33 _cleanup_test_img 34} 35trap "_cleanup; exit \$status" 0 1 2 3 15 36 37# get standard environment, filters and checks 38. ./common.rc 39. ./common.filter 40. ./common.pattern 41 42# Any format supporting intenal snapshots 43_supported_fmt qcow2 44_supported_proto generic 45_unsupported_proto vxhs 46_supported_os Linux 47# Internal snapshots are (currently) impossible with refcount_bits=1 48_unsupported_imgopts 'refcount_bits=1[^0-9]' 49 50offset_size=24 51offset_l1_size=36 52 53echo 54echo Test loading internal snapshots where the L1 table of the snapshot 55echo is smaller than the current L1 table. 56echo 57 58CLUSTER_SIZE=65536 59_make_test_img 64M 60$QEMU_IMG snapshot -c foo "$TEST_IMG" 61$QEMU_IO -c 'write -b 0 4k' "$TEST_IMG" | _filter_qemu_io 62$QEMU_IMG snapshot -a foo "$TEST_IMG" 63_check_test_img 64 65CLUSTER_SIZE=1024 66_make_test_img 16M 67$QEMU_IMG snapshot -c foo "$TEST_IMG" 68$QEMU_IO -c 'write -b 0 4M' "$TEST_IMG" | _filter_qemu_io 69$QEMU_IMG snapshot -a foo "$TEST_IMG" 70_check_test_img 71 72 73echo 74echo Try using a huge VM state 75echo 76 77CLUSTER_SIZE=65536 78_make_test_img 64M 79{ $QEMU_IO -c "write -b -P 0x11 1T 4k" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 80{ $QEMU_IMG snapshot -c foo $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 81{ $QEMU_IMG snapshot -a foo $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 82{ $QEMU_IO -c "read -b -P 0x11 1T 4k" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 83_check_test_img 84 85 86echo 87echo "qcow2_snapshot_load_tmp() should take the L1 size from the snapshot" 88echo 89 90CLUSTER_SIZE=512 91_make_test_img 64M 92{ $QEMU_IMG snapshot -c foo $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 93poke_file "$TEST_IMG" "$offset_size" "\x00\x00\x00\x00\x00\x00\x02\x00" 94poke_file "$TEST_IMG" "$offset_l1_size" "\x00\x00\x00\x01" 95{ $QEMU_IMG convert -l foo $TEST_IMG $TEST_IMG.snap; } 2>&1 | _filter_qemu_io | _filter_testdir 96 97 98# success, all done 99echo "*** done" 100rm -f $seq.full 101status=0 102