111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env 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 Wolfstatus=1 # failure is the default! 28231f66d2SKevin Wolf 29231f66d2SKevin Wolf_cleanup() 30231f66d2SKevin Wolf{ 31231f66d2SKevin Wolf _cleanup_test_img 32231f66d2SKevin Wolf} 33231f66d2SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 34231f66d2SKevin Wolf 35231f66d2SKevin Wolf# get standard environment, filters and checks 36231f66d2SKevin Wolf. ./common.rc 37231f66d2SKevin Wolf. ./common.filter 38231f66d2SKevin Wolf. ./common.qemu 39231f66d2SKevin Wolf 40231f66d2SKevin Wolf_supported_fmt qcow2 412b12baf0SJeff Cody_supported_proto file 42231f66d2SKevin Wolf_supported_os Linux 4394254c9bSMax Reitz# We are going to use lazy-refcounts 4494254c9bSMax Reitz_unsupported_imgopts 'compat=0.10' 45231f66d2SKevin Wolf 46231f66d2SKevin Wolf 47231f66d2SKevin Wolf_make_test_img 64M 48231f66d2SKevin Wolf 49231f66d2SKevin Wolfecho === Try setting valid values for all options === 50231f66d2SKevin Wolfecho 51231f66d2SKevin Wolf 52231f66d2SKevin Wolf# Try all options and then check that all of the basic I/O operations still 53231f66d2SKevin Wolf# work on this image. 54231f66d2SKevin Wolf$QEMU_IO \ 55231f66d2SKevin Wolf -c "reopen -o lazy-refcounts=on,pass-discard-request=on" \ 56231f66d2SKevin Wolf -c "reopen -o lazy-refcounts=off,pass-discard-request=off" \ 57231f66d2SKevin Wolf -c "reopen -o pass-discard-snapshot=on,pass-discard-other=on" \ 58231f66d2SKevin Wolf -c "reopen -o pass-discard-snapshot=off,pass-discard-other=off" \ 59231f66d2SKevin Wolf -c "reopen -o overlap-check=all" \ 60231f66d2SKevin Wolf -c "reopen -o overlap-check=none" \ 61231f66d2SKevin Wolf -c "reopen -o overlap-check=cached" \ 62231f66d2SKevin Wolf -c "reopen -o overlap-check=constant" \ 63231f66d2SKevin Wolf -c "reopen -o overlap-check.template=all" \ 64231f66d2SKevin Wolf -c "reopen -o overlap-check.template=none" \ 65231f66d2SKevin Wolf -c "reopen -o overlap-check.template=cached" \ 66231f66d2SKevin Wolf -c "reopen -o overlap-check.template=constant" \ 67231f66d2SKevin Wolf -c "reopen -o overlap-check.main-header=on" \ 68231f66d2SKevin Wolf -c "reopen -o overlap-check.main-header=off" \ 69231f66d2SKevin Wolf -c "reopen -o overlap-check.active-l1=on" \ 70231f66d2SKevin Wolf -c "reopen -o overlap-check.active-l1=off" \ 71231f66d2SKevin Wolf -c "reopen -o overlap-check.active-l2=on" \ 72231f66d2SKevin Wolf -c "reopen -o overlap-check.active-l2=off" \ 73231f66d2SKevin Wolf -c "reopen -o overlap-check.refcount-table=on" \ 74231f66d2SKevin Wolf -c "reopen -o overlap-check.refcount-table=off" \ 75231f66d2SKevin Wolf -c "reopen -o overlap-check.refcount-block=on" \ 76231f66d2SKevin Wolf -c "reopen -o overlap-check.refcount-block=off" \ 77231f66d2SKevin Wolf -c "reopen -o overlap-check.snapshot-table=on" \ 78231f66d2SKevin Wolf -c "reopen -o overlap-check.snapshot-table=off" \ 79231f66d2SKevin Wolf -c "reopen -o overlap-check.inactive-l1=on" \ 80231f66d2SKevin Wolf -c "reopen -o overlap-check.inactive-l1=off" \ 81231f66d2SKevin Wolf -c "reopen -o overlap-check.inactive-l2=on" \ 82231f66d2SKevin Wolf -c "reopen -o overlap-check.inactive-l2=off" \ 83231f66d2SKevin Wolf -c "reopen -o cache-size=1M" \ 84231f66d2SKevin Wolf -c "reopen -o l2-cache-size=512k" \ 8503b1b6f0SAlberto Garcia -c "reopen -o l2-cache-entry-size=512" \ 8603b1b6f0SAlberto Garcia -c "reopen -o l2-cache-entry-size=4k" \ 8703b1b6f0SAlberto Garcia -c "reopen -o l2-cache-entry-size=64k" \ 88231f66d2SKevin Wolf -c "reopen -o refcount-cache-size=128k" \ 89231f66d2SKevin Wolf -c "reopen -o cache-clean-interval=5" \ 90231f66d2SKevin Wolf -c "reopen -o cache-clean-interval=0" \ 91231f66d2SKevin Wolf -c "reopen -o cache-clean-interval=10" \ 92231f66d2SKevin Wolf \ 93231f66d2SKevin Wolf -c "write -P 55 0 32M" \ 94231f66d2SKevin Wolf -c "read -P 55 0 32M" \ 95231f66d2SKevin Wolf -c "discard 0 32M" \ 96231f66d2SKevin Wolf -c "write -z 0 32M" \ 97231f66d2SKevin Wolf -c "read -P 0 0 32M" \ 98231f66d2SKevin Wolf \ 99231f66d2SKevin Wolf "$TEST_IMG" | _filter_qemu_io 100231f66d2SKevin Wolf 101231f66d2SKevin Wolf 102231f66d2SKevin Wolfecho 103231f66d2SKevin Wolfecho === Try setting some invalid values === 104231f66d2SKevin Wolfecho 105231f66d2SKevin Wolf 106231f66d2SKevin Wolf$QEMU_IO \ 107231f66d2SKevin Wolf -c "reopen -o lazy-refcounts=42" \ 108231f66d2SKevin Wolf -c "reopen -o cache-size=1M,l2-cache-size=64k,refcount-cache-size=64k" \ 109231f66d2SKevin Wolf -c "reopen -o cache-size=1M,l2-cache-size=2M" \ 110231f66d2SKevin Wolf -c "reopen -o cache-size=1M,refcount-cache-size=2M" \ 11103b1b6f0SAlberto Garcia -c "reopen -o l2-cache-entry-size=33k" \ 11203b1b6f0SAlberto Garcia -c "reopen -o l2-cache-entry-size=128k" \ 113231f66d2SKevin Wolf -c "reopen -o refcount-cache-size=256T" \ 114231f66d2SKevin Wolf -c "reopen -o overlap-check=constant,overlap-check.template=all" \ 115231f66d2SKevin Wolf -c "reopen -o overlap-check=blubb" \ 116231f66d2SKevin Wolf -c "reopen -o overlap-check.template=blubb" \ 117231f66d2SKevin Wolf -c "reopen -o cache-clean-interval=-1" \ 118231f66d2SKevin Wolf "$TEST_IMG" | _filter_qemu_io 119231f66d2SKevin Wolf 120*407fb56aSMax Reitz_make_test_img -o "cluster_size=256k" 32P 121b749562dSLeonid Bloch$QEMU_IO \ 122b749562dSLeonid Bloch -c "reopen -o l2-cache-entry-size=512,l2-cache-size=1T" \ 123b749562dSLeonid Bloch "$TEST_IMG" | _filter_qemu_io 124b749562dSLeonid Bloch 125b749562dSLeonid Bloch_make_test_img 64M 126b749562dSLeonid Bloch 127231f66d2SKevin Wolfecho 128231f66d2SKevin Wolfecho === Test transaction semantics === 129231f66d2SKevin Wolfecho 130231f66d2SKevin Wolf 131231f66d2SKevin Wolf# Whether lazy-refcounts was actually enabled can easily be tested: Check if 132231f66d2SKevin Wolf# the dirty bit is set after a crash 1338af224d6SAndrey Shinkevich_NO_VALGRIND \ 134231f66d2SKevin Wolf$QEMU_IO \ 135231f66d2SKevin Wolf -c "reopen -o lazy-refcounts=on,overlap-check=blubb" \ 136231f66d2SKevin Wolf -c "write -P 0x5a 0 512" \ 137231f66d2SKevin Wolf -c "sigraise $(kill -l KILL)" \ 138231f66d2SKevin Wolf "$TEST_IMG" 2>&1 | _filter_qemu_io 139231f66d2SKevin Wolf 140231f66d2SKevin Wolf# The dirty bit must not be set 141231f66d2SKevin Wolf$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 142231f66d2SKevin Wolf 143231f66d2SKevin Wolf# Similarly we can test whether corruption detection has been enabled: 144231f66d2SKevin Wolf# Create L1/L2, overwrite first entry in refcount block, allocate something. 145231f66d2SKevin Wolf# Disabling the checks should fail, so the corruption must be detected. 146231f66d2SKevin Wolf_make_test_img 64M 147231f66d2SKevin Wolf$QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io 148231f66d2SKevin Wolfpoke_file "$TEST_IMG" "$((0x20000))" "\x00\x00" 149231f66d2SKevin Wolf$QEMU_IO \ 150231f66d2SKevin Wolf -c "reopen -o overlap-check=none,lazy-refcounts=42" \ 151231f66d2SKevin Wolf -c "write 64k 64k" \ 152231f66d2SKevin Wolf "$TEST_IMG" 2>&1 | _filter_qemu_io 153231f66d2SKevin Wolf 154231f66d2SKevin Wolf# success, all done 155231f66d2SKevin Wolfecho '*** done' 156231f66d2SKevin Wolfrm -f $seq.full 157231f66d2SKevin Wolfstatus=0 158