1*231f66d2SKevin Wolf#!/bin/bash 2*231f66d2SKevin Wolf# 3*231f66d2SKevin Wolf# Test qcow2 reopen 4*231f66d2SKevin Wolf# 5*231f66d2SKevin Wolf# Copyright (C) 2015 Red Hat, Inc. 6*231f66d2SKevin Wolf# 7*231f66d2SKevin Wolf# This program is free software; you can redistribute it and/or modify 8*231f66d2SKevin Wolf# it under the terms of the GNU General Public License as published by 9*231f66d2SKevin Wolf# the Free Software Foundation; either version 2 of the License, or 10*231f66d2SKevin Wolf# (at your option) any later version. 11*231f66d2SKevin Wolf# 12*231f66d2SKevin Wolf# This program is distributed in the hope that it will be useful, 13*231f66d2SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 14*231f66d2SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*231f66d2SKevin Wolf# GNU General Public License for more details. 16*231f66d2SKevin Wolf# 17*231f66d2SKevin Wolf# You should have received a copy of the GNU General Public License 18*231f66d2SKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 19*231f66d2SKevin Wolf# 20*231f66d2SKevin Wolf 21*231f66d2SKevin Wolf# creator 22*231f66d2SKevin Wolfowner=kwolf@redhat.com 23*231f66d2SKevin Wolf 24*231f66d2SKevin Wolfseq="$(basename $0)" 25*231f66d2SKevin Wolfecho "QA output created by $seq" 26*231f66d2SKevin Wolf 27*231f66d2SKevin Wolfhere="$PWD" 28*231f66d2SKevin Wolftmp=/tmp/$$ 29*231f66d2SKevin Wolfstatus=1 # failure is the default! 30*231f66d2SKevin Wolf 31*231f66d2SKevin Wolf_cleanup() 32*231f66d2SKevin Wolf{ 33*231f66d2SKevin Wolf _cleanup_test_img 34*231f66d2SKevin Wolf} 35*231f66d2SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 36*231f66d2SKevin Wolf 37*231f66d2SKevin Wolf# get standard environment, filters and checks 38*231f66d2SKevin Wolf. ./common.rc 39*231f66d2SKevin Wolf. ./common.filter 40*231f66d2SKevin Wolf. ./common.qemu 41*231f66d2SKevin Wolf 42*231f66d2SKevin Wolf_supported_fmt qcow2 43*231f66d2SKevin Wolf_supported_proto generic 44*231f66d2SKevin Wolf_supported_os Linux 45*231f66d2SKevin Wolf 46*231f66d2SKevin Wolf 47*231f66d2SKevin Wolf_make_test_img 64M 48*231f66d2SKevin Wolf 49*231f66d2SKevin Wolfecho === Try setting valid values for all options === 50*231f66d2SKevin Wolfecho 51*231f66d2SKevin Wolf 52*231f66d2SKevin Wolf# Try all options and then check that all of the basic I/O operations still 53*231f66d2SKevin Wolf# work on this image. 54*231f66d2SKevin Wolf$QEMU_IO \ 55*231f66d2SKevin Wolf -c "reopen -o lazy-refcounts=on,pass-discard-request=on" \ 56*231f66d2SKevin Wolf -c "reopen -o lazy-refcounts=off,pass-discard-request=off" \ 57*231f66d2SKevin Wolf -c "reopen -o pass-discard-snapshot=on,pass-discard-other=on" \ 58*231f66d2SKevin Wolf -c "reopen -o pass-discard-snapshot=off,pass-discard-other=off" \ 59*231f66d2SKevin Wolf -c "reopen -o overlap-check=all" \ 60*231f66d2SKevin Wolf -c "reopen -o overlap-check=none" \ 61*231f66d2SKevin Wolf -c "reopen -o overlap-check=cached" \ 62*231f66d2SKevin Wolf -c "reopen -o overlap-check=constant" \ 63*231f66d2SKevin Wolf -c "reopen -o overlap-check.template=all" \ 64*231f66d2SKevin Wolf -c "reopen -o overlap-check.template=none" \ 65*231f66d2SKevin Wolf -c "reopen -o overlap-check.template=cached" \ 66*231f66d2SKevin Wolf -c "reopen -o overlap-check.template=constant" \ 67*231f66d2SKevin Wolf -c "reopen -o overlap-check.main-header=on" \ 68*231f66d2SKevin Wolf -c "reopen -o overlap-check.main-header=off" \ 69*231f66d2SKevin Wolf -c "reopen -o overlap-check.active-l1=on" \ 70*231f66d2SKevin Wolf -c "reopen -o overlap-check.active-l1=off" \ 71*231f66d2SKevin Wolf -c "reopen -o overlap-check.active-l2=on" \ 72*231f66d2SKevin Wolf -c "reopen -o overlap-check.active-l2=off" \ 73*231f66d2SKevin Wolf -c "reopen -o overlap-check.refcount-table=on" \ 74*231f66d2SKevin Wolf -c "reopen -o overlap-check.refcount-table=off" \ 75*231f66d2SKevin Wolf -c "reopen -o overlap-check.refcount-block=on" \ 76*231f66d2SKevin Wolf -c "reopen -o overlap-check.refcount-block=off" \ 77*231f66d2SKevin Wolf -c "reopen -o overlap-check.snapshot-table=on" \ 78*231f66d2SKevin Wolf -c "reopen -o overlap-check.snapshot-table=off" \ 79*231f66d2SKevin Wolf -c "reopen -o overlap-check.inactive-l1=on" \ 80*231f66d2SKevin Wolf -c "reopen -o overlap-check.inactive-l1=off" \ 81*231f66d2SKevin Wolf -c "reopen -o overlap-check.inactive-l2=on" \ 82*231f66d2SKevin Wolf -c "reopen -o overlap-check.inactive-l2=off" \ 83*231f66d2SKevin Wolf -c "reopen -o cache-size=1M" \ 84*231f66d2SKevin Wolf -c "reopen -o l2-cache-size=512k" \ 85*231f66d2SKevin Wolf -c "reopen -o refcount-cache-size=128k" \ 86*231f66d2SKevin Wolf -c "reopen -o cache-clean-interval=5" \ 87*231f66d2SKevin Wolf -c "reopen -o cache-clean-interval=0" \ 88*231f66d2SKevin Wolf -c "reopen -o cache-clean-interval=10" \ 89*231f66d2SKevin Wolf \ 90*231f66d2SKevin Wolf -c "write -P 55 0 32M" \ 91*231f66d2SKevin Wolf -c "read -P 55 0 32M" \ 92*231f66d2SKevin Wolf -c "discard 0 32M" \ 93*231f66d2SKevin Wolf -c "write -z 0 32M" \ 94*231f66d2SKevin Wolf -c "read -P 0 0 32M" \ 95*231f66d2SKevin Wolf \ 96*231f66d2SKevin Wolf "$TEST_IMG" | _filter_qemu_io 97*231f66d2SKevin Wolf 98*231f66d2SKevin Wolf 99*231f66d2SKevin Wolfecho 100*231f66d2SKevin Wolfecho === Try setting some invalid values === 101*231f66d2SKevin Wolfecho 102*231f66d2SKevin Wolf 103*231f66d2SKevin Wolf$QEMU_IO \ 104*231f66d2SKevin Wolf -c "reopen -o lazy-refcounts=42" \ 105*231f66d2SKevin Wolf -c "reopen -o cache-size=1M,l2-cache-size=64k,refcount-cache-size=64k" \ 106*231f66d2SKevin Wolf -c "reopen -o cache-size=1M,l2-cache-size=2M" \ 107*231f66d2SKevin Wolf -c "reopen -o cache-size=1M,refcount-cache-size=2M" \ 108*231f66d2SKevin Wolf -c "reopen -o l2-cache-size=256T" \ 109*231f66d2SKevin Wolf -c "reopen -o refcount-cache-size=256T" \ 110*231f66d2SKevin Wolf -c "reopen -o overlap-check=constant,overlap-check.template=all" \ 111*231f66d2SKevin Wolf -c "reopen -o overlap-check=blubb" \ 112*231f66d2SKevin Wolf -c "reopen -o overlap-check.template=blubb" \ 113*231f66d2SKevin Wolf -c "reopen -o cache-clean-interval=-1" \ 114*231f66d2SKevin Wolf "$TEST_IMG" | _filter_qemu_io 115*231f66d2SKevin Wolf 116*231f66d2SKevin Wolfecho 117*231f66d2SKevin Wolfecho === Test transaction semantics === 118*231f66d2SKevin Wolfecho 119*231f66d2SKevin Wolf 120*231f66d2SKevin Wolf# Whether lazy-refcounts was actually enabled can easily be tested: Check if 121*231f66d2SKevin Wolf# the dirty bit is set after a crash 122*231f66d2SKevin Wolf$QEMU_IO \ 123*231f66d2SKevin Wolf -c "reopen -o lazy-refcounts=on,overlap-check=blubb" \ 124*231f66d2SKevin Wolf -c "write -P 0x5a 0 512" \ 125*231f66d2SKevin Wolf -c "sigraise $(kill -l KILL)" \ 126*231f66d2SKevin Wolf "$TEST_IMG" 2>&1 | _filter_qemu_io 127*231f66d2SKevin Wolf 128*231f66d2SKevin Wolf# The dirty bit must not be set 129*231f66d2SKevin Wolf$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 130*231f66d2SKevin Wolf 131*231f66d2SKevin Wolf# Similarly we can test whether corruption detection has been enabled: 132*231f66d2SKevin Wolf# Create L1/L2, overwrite first entry in refcount block, allocate something. 133*231f66d2SKevin Wolf# Disabling the checks should fail, so the corruption must be detected. 134*231f66d2SKevin Wolf_make_test_img 64M 135*231f66d2SKevin Wolf$QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io 136*231f66d2SKevin Wolfpoke_file "$TEST_IMG" "$((0x20000))" "\x00\x00" 137*231f66d2SKevin Wolf$QEMU_IO \ 138*231f66d2SKevin Wolf -c "reopen -o overlap-check=none,lazy-refcounts=42" \ 139*231f66d2SKevin Wolf -c "write 64k 64k" \ 140*231f66d2SKevin Wolf "$TEST_IMG" 2>&1 | _filter_qemu_io 141*231f66d2SKevin Wolf 142*231f66d2SKevin Wolf# success, all done 143*231f66d2SKevin Wolfecho '*** done' 144*231f66d2SKevin Wolfrm -f $seq.full 145*231f66d2SKevin Wolfstatus=0 146