1#!/usr/bin/env bash 2# 3# Test qcow2 lazy refcounts 4# 5# Copyright (C) 2012 Red Hat, Inc. 6# Copyright IBM, Corp. 2010 7# 8# Based on test 038. 9# 10# This program is free software; you can redistribute it and/or modify 11# it under the terms of the GNU General Public License as published by 12# the Free Software Foundation; either version 2 of the License, or 13# (at your option) any later version. 14# 15# This program is distributed in the hope that it will be useful, 16# but WITHOUT ANY WARRANTY; without even the implied warranty of 17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18# GNU General Public License for more details. 19# 20# You should have received a copy of the GNU General Public License 21# along with this program. If not, see <http://www.gnu.org/licenses/>. 22# 23 24# creator 25owner=stefanha@linux.vnet.ibm.com 26 27seq=`basename $0` 28echo "QA output created by $seq" 29 30status=1 # failure is the default! 31 32_cleanup() 33{ 34 _cleanup_test_img 35} 36trap "_cleanup; exit \$status" 0 1 2 3 15 37 38# get standard environment, filters and checks 39. ./common.rc 40. ./common.filter 41 42_supported_fmt qcow2 43_supported_proto file 44_supported_os Linux 45_default_cache_mode writethrough 46_supported_cache_modes writethrough 47 48size=128M 49 50echo 51echo "== Checking that image is clean on shutdown ==" 52 53_make_test_img -o "compat=1.1,lazy_refcounts=on" $size 54 55$QEMU_IO -c "write -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io 56 57# The dirty bit must not be set 58$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 59_check_test_img 60 61echo 62echo "== Creating a dirty image file ==" 63 64_make_test_img -o "compat=1.1,lazy_refcounts=on" $size 65 66_NO_VALGRIND \ 67$QEMU_IO -c "write -P 0x5a 0 512" \ 68 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ 69 | _filter_qemu_io 70 71# The dirty bit must be set 72$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 73_check_test_img 74 75echo 76echo "== Read-only access must still work ==" 77 78$QEMU_IO -r -c "read -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io 79 80# The dirty bit must be set 81$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 82 83echo 84echo "== Repairing the image file must succeed ==" 85 86_check_test_img -r all 87 88# The dirty bit must not be set 89$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 90 91echo 92echo "== Data should still be accessible after repair ==" 93 94$QEMU_IO -c "read -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io 95 96echo 97echo "== Opening a dirty image read/write should repair it ==" 98 99_make_test_img -o "compat=1.1,lazy_refcounts=on" $size 100 101_NO_VALGRIND \ 102$QEMU_IO -c "write -P 0x5a 0 512" \ 103 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ 104 | _filter_qemu_io 105 106# The dirty bit must be set 107$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 108 109$QEMU_IO -c "write 0 512" "$TEST_IMG" | _filter_qemu_io 110 111# The dirty bit must not be set 112$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 113 114echo 115echo "== Creating an image file with lazy_refcounts=off ==" 116 117_make_test_img -o "compat=1.1,lazy_refcounts=off" $size 118 119_NO_VALGRIND \ 120$QEMU_IO -c "write -P 0x5a 0 512" \ 121 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ 122 | _filter_qemu_io 123 124# The dirty bit must not be set since lazy_refcounts=off 125$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 126_check_test_img 127 128echo 129echo "== Committing to a backing file with lazy_refcounts=on ==" 130 131TEST_IMG="$TEST_IMG".base _make_test_img -o "compat=1.1,lazy_refcounts=on" $size 132 133_make_test_img -o "compat=1.1,lazy_refcounts=on,backing_file=$TEST_IMG.base" $size 134 135$QEMU_IO -c "write 0 512" "$TEST_IMG" | _filter_qemu_io 136$QEMU_IMG commit "$TEST_IMG" 137 138# The dirty bit must not be set 139$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 140$PYTHON qcow2.py "$TEST_IMG".base dump-header | grep incompatible_features 141 142_check_test_img 143TEST_IMG="$TEST_IMG".base _check_test_img 144 145echo 146echo "== Changing lazy_refcounts setting at runtime ==" 147 148_make_test_img -o "compat=1.1,lazy_refcounts=off" $size 149 150_NO_VALGRIND \ 151$QEMU_IO -c "reopen -o lazy-refcounts=on" \ 152 -c "write -P 0x5a 0 512" \ 153 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ 154 | _filter_qemu_io 155 156# The dirty bit must be set 157$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 158_check_test_img 159 160_make_test_img -o "compat=1.1,lazy_refcounts=on" $size 161 162_NO_VALGRIND \ 163$QEMU_IO -c "reopen -o lazy-refcounts=off" \ 164 -c "write -P 0x5a 0 512" \ 165 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ 166 | _filter_qemu_io 167 168# The dirty bit must not be set 169$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 170_check_test_img 171 172 173# success, all done 174echo "*** done" 175rm -f $seq.full 176status=0 177 178