1231f66d2SKevin Wolf#!/bin/bash 2231f66d2SKevin Wolf# 3231f66d2SKevin Wolf# Test qcow2 reopen 4231f66d2SKevin Wolf# 5231f66d2SKevin Wolf# Copyright (C) 2015 Red Hat, Inc. 6231f66d2SKevin Wolf# 7231f66d2SKevin Wolf# This program is free software; you can redistribute it and/or modify 8231f66d2SKevin Wolf# it under the terms of the GNU General Public License as published by 9231f66d2SKevin Wolf# the Free Software Foundation; either version 2 of the License, or 10231f66d2SKevin Wolf# (at your option) any later version. 11231f66d2SKevin Wolf# 12231f66d2SKevin Wolf# This program is distributed in the hope that it will be useful, 13231f66d2SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 14231f66d2SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15231f66d2SKevin Wolf# GNU General Public License for more details. 16231f66d2SKevin Wolf# 17231f66d2SKevin Wolf# You should have received a copy of the GNU General Public License 18231f66d2SKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 19231f66d2SKevin Wolf# 20231f66d2SKevin Wolf 21231f66d2SKevin Wolf# creator 22231f66d2SKevin Wolfowner=kwolf@redhat.com 23231f66d2SKevin Wolf 24231f66d2SKevin Wolfseq="$(basename $0)" 25231f66d2SKevin Wolfecho "QA output created by $seq" 26231f66d2SKevin Wolf 27231f66d2SKevin Wolfhere="$PWD" 28231f66d2SKevin Wolfstatus=1 # failure is the default! 29231f66d2SKevin Wolf 30231f66d2SKevin Wolf_cleanup() 31231f66d2SKevin Wolf{ 32231f66d2SKevin Wolf _cleanup_test_img 33231f66d2SKevin Wolf} 34231f66d2SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 35231f66d2SKevin Wolf 36231f66d2SKevin Wolf# get standard environment, filters and checks 37231f66d2SKevin Wolf. ./common.rc 38231f66d2SKevin Wolf. ./common.filter 39231f66d2SKevin Wolf. ./common.qemu 40231f66d2SKevin Wolf 41231f66d2SKevin Wolf_supported_fmt qcow2 42*2b12baf0SJeff Cody_supported_proto file 43231f66d2SKevin Wolf_supported_os Linux 44231f66d2SKevin Wolf 45231f66d2SKevin Wolf 46231f66d2SKevin Wolf_make_test_img 64M 47231f66d2SKevin Wolf 48231f66d2SKevin Wolfecho === Try setting valid values for all options === 49231f66d2SKevin Wolfecho 50231f66d2SKevin Wolf 51231f66d2SKevin Wolf# Try all options and then check that all of the basic I/O operations still 52231f66d2SKevin Wolf# work on this image. 53231f66d2SKevin Wolf$QEMU_IO \ 54231f66d2SKevin Wolf -c "reopen -o lazy-refcounts=on,pass-discard-request=on" \ 55231f66d2SKevin Wolf -c "reopen -o lazy-refcounts=off,pass-discard-request=off" \ 56231f66d2SKevin Wolf -c "reopen -o pass-discard-snapshot=on,pass-discard-other=on" \ 57231f66d2SKevin Wolf -c "reopen -o pass-discard-snapshot=off,pass-discard-other=off" \ 58231f66d2SKevin Wolf -c "reopen -o overlap-check=all" \ 59231f66d2SKevin Wolf -c "reopen -o overlap-check=none" \ 60231f66d2SKevin Wolf -c "reopen -o overlap-check=cached" \ 61231f66d2SKevin Wolf -c "reopen -o overlap-check=constant" \ 62231f66d2SKevin Wolf -c "reopen -o overlap-check.template=all" \ 63231f66d2SKevin Wolf -c "reopen -o overlap-check.template=none" \ 64231f66d2SKevin Wolf -c "reopen -o overlap-check.template=cached" \ 65231f66d2SKevin Wolf -c "reopen -o overlap-check.template=constant" \ 66231f66d2SKevin Wolf -c "reopen -o overlap-check.main-header=on" \ 67231f66d2SKevin Wolf -c "reopen -o overlap-check.main-header=off" \ 68231f66d2SKevin Wolf -c "reopen -o overlap-check.active-l1=on" \ 69231f66d2SKevin Wolf -c "reopen -o overlap-check.active-l1=off" \ 70231f66d2SKevin Wolf -c "reopen -o overlap-check.active-l2=on" \ 71231f66d2SKevin Wolf -c "reopen -o overlap-check.active-l2=off" \ 72231f66d2SKevin Wolf -c "reopen -o overlap-check.refcount-table=on" \ 73231f66d2SKevin Wolf -c "reopen -o overlap-check.refcount-table=off" \ 74231f66d2SKevin Wolf -c "reopen -o overlap-check.refcount-block=on" \ 75231f66d2SKevin Wolf -c "reopen -o overlap-check.refcount-block=off" \ 76231f66d2SKevin Wolf -c "reopen -o overlap-check.snapshot-table=on" \ 77231f66d2SKevin Wolf -c "reopen -o overlap-check.snapshot-table=off" \ 78231f66d2SKevin Wolf -c "reopen -o overlap-check.inactive-l1=on" \ 79231f66d2SKevin Wolf -c "reopen -o overlap-check.inactive-l1=off" \ 80231f66d2SKevin Wolf -c "reopen -o overlap-check.inactive-l2=on" \ 81231f66d2SKevin Wolf -c "reopen -o overlap-check.inactive-l2=off" \ 82231f66d2SKevin Wolf -c "reopen -o cache-size=1M" \ 83231f66d2SKevin Wolf -c "reopen -o l2-cache-size=512k" \ 84231f66d2SKevin Wolf -c "reopen -o refcount-cache-size=128k" \ 85231f66d2SKevin Wolf -c "reopen -o cache-clean-interval=5" \ 86231f66d2SKevin Wolf -c "reopen -o cache-clean-interval=0" \ 87231f66d2SKevin Wolf -c "reopen -o cache-clean-interval=10" \ 88231f66d2SKevin Wolf \ 89231f66d2SKevin Wolf -c "write -P 55 0 32M" \ 90231f66d2SKevin Wolf -c "read -P 55 0 32M" \ 91231f66d2SKevin Wolf -c "discard 0 32M" \ 92231f66d2SKevin Wolf -c "write -z 0 32M" \ 93231f66d2SKevin Wolf -c "read -P 0 0 32M" \ 94231f66d2SKevin Wolf \ 95231f66d2SKevin Wolf "$TEST_IMG" | _filter_qemu_io 96231f66d2SKevin Wolf 97231f66d2SKevin Wolf 98231f66d2SKevin Wolfecho 99231f66d2SKevin Wolfecho === Try setting some invalid values === 100231f66d2SKevin Wolfecho 101231f66d2SKevin Wolf 102231f66d2SKevin Wolf$QEMU_IO \ 103231f66d2SKevin Wolf -c "reopen -o lazy-refcounts=42" \ 104231f66d2SKevin Wolf -c "reopen -o cache-size=1M,l2-cache-size=64k,refcount-cache-size=64k" \ 105231f66d2SKevin Wolf -c "reopen -o cache-size=1M,l2-cache-size=2M" \ 106231f66d2SKevin Wolf -c "reopen -o cache-size=1M,refcount-cache-size=2M" \ 107231f66d2SKevin Wolf -c "reopen -o l2-cache-size=256T" \ 108231f66d2SKevin Wolf -c "reopen -o refcount-cache-size=256T" \ 109231f66d2SKevin Wolf -c "reopen -o overlap-check=constant,overlap-check.template=all" \ 110231f66d2SKevin Wolf -c "reopen -o overlap-check=blubb" \ 111231f66d2SKevin Wolf -c "reopen -o overlap-check.template=blubb" \ 112231f66d2SKevin Wolf -c "reopen -o cache-clean-interval=-1" \ 113231f66d2SKevin Wolf "$TEST_IMG" | _filter_qemu_io 114231f66d2SKevin Wolf 115231f66d2SKevin Wolfecho 116231f66d2SKevin Wolfecho === Test transaction semantics === 117231f66d2SKevin Wolfecho 118231f66d2SKevin Wolf 119231f66d2SKevin Wolf# Whether lazy-refcounts was actually enabled can easily be tested: Check if 120231f66d2SKevin Wolf# the dirty bit is set after a crash 121231f66d2SKevin Wolf$QEMU_IO \ 122231f66d2SKevin Wolf -c "reopen -o lazy-refcounts=on,overlap-check=blubb" \ 123231f66d2SKevin Wolf -c "write -P 0x5a 0 512" \ 124231f66d2SKevin Wolf -c "sigraise $(kill -l KILL)" \ 125231f66d2SKevin Wolf "$TEST_IMG" 2>&1 | _filter_qemu_io 126231f66d2SKevin Wolf 127231f66d2SKevin Wolf# The dirty bit must not be set 128231f66d2SKevin Wolf$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 129231f66d2SKevin Wolf 130231f66d2SKevin Wolf# Similarly we can test whether corruption detection has been enabled: 131231f66d2SKevin Wolf# Create L1/L2, overwrite first entry in refcount block, allocate something. 132231f66d2SKevin Wolf# Disabling the checks should fail, so the corruption must be detected. 133231f66d2SKevin Wolf_make_test_img 64M 134231f66d2SKevin Wolf$QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io 135231f66d2SKevin Wolfpoke_file "$TEST_IMG" "$((0x20000))" "\x00\x00" 136231f66d2SKevin Wolf$QEMU_IO \ 137231f66d2SKevin Wolf -c "reopen -o overlap-check=none,lazy-refcounts=42" \ 138231f66d2SKevin Wolf -c "write 64k 64k" \ 139231f66d2SKevin Wolf "$TEST_IMG" 2>&1 | _filter_qemu_io 140231f66d2SKevin Wolf 141231f66d2SKevin Wolf# success, all done 142231f66d2SKevin Wolfecho '*** done' 143231f66d2SKevin Wolfrm -f $seq.full 144231f66d2SKevin Wolfstatus=0 145