111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 29dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto 3231f66d2SKevin Wolf# 4231f66d2SKevin Wolf# Test qcow2 reopen 5231f66d2SKevin Wolf# 6231f66d2SKevin Wolf# Copyright (C) 2015 Red Hat, Inc. 7231f66d2SKevin Wolf# 8231f66d2SKevin Wolf# This program is free software; you can redistribute it and/or modify 9231f66d2SKevin Wolf# it under the terms of the GNU General Public License as published by 10231f66d2SKevin Wolf# the Free Software Foundation; either version 2 of the License, or 11231f66d2SKevin Wolf# (at your option) any later version. 12231f66d2SKevin Wolf# 13231f66d2SKevin Wolf# This program is distributed in the hope that it will be useful, 14231f66d2SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 15231f66d2SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16231f66d2SKevin Wolf# GNU General Public License for more details. 17231f66d2SKevin Wolf# 18231f66d2SKevin Wolf# You should have received a copy of the GNU General Public License 19231f66d2SKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 20231f66d2SKevin Wolf# 21231f66d2SKevin Wolf 22231f66d2SKevin Wolf# creator 23231f66d2SKevin Wolfowner=kwolf@redhat.com 24231f66d2SKevin Wolf 25231f66d2SKevin Wolfseq="$(basename $0)" 26231f66d2SKevin Wolfecho "QA output created by $seq" 27231f66d2SKevin Wolf 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 4257284d2aSMax Reitz_supported_proto file fuse 43231f66d2SKevin Wolf_supported_os Linux 4494254c9bSMax Reitz# We are going to use lazy-refcounts 4594254c9bSMax Reitz_unsupported_imgopts 'compat=0.10' 46231f66d2SKevin Wolf 47231f66d2SKevin Wolf 48231f66d2SKevin Wolf_make_test_img 64M 49231f66d2SKevin Wolf 50231f66d2SKevin Wolfecho === Try setting valid values for all options === 51231f66d2SKevin Wolfecho 52231f66d2SKevin Wolf 53231f66d2SKevin Wolf# Try all options and then check that all of the basic I/O operations still 54231f66d2SKevin Wolf# work on this image. 55231f66d2SKevin Wolf$QEMU_IO \ 56231f66d2SKevin Wolf -c "reopen -o lazy-refcounts=on,pass-discard-request=on" \ 57231f66d2SKevin Wolf -c "reopen -o lazy-refcounts=off,pass-discard-request=off" \ 58231f66d2SKevin Wolf -c "reopen -o pass-discard-snapshot=on,pass-discard-other=on" \ 59231f66d2SKevin Wolf -c "reopen -o pass-discard-snapshot=off,pass-discard-other=off" \ 60231f66d2SKevin Wolf -c "reopen -o overlap-check=all" \ 61231f66d2SKevin Wolf -c "reopen -o overlap-check=none" \ 62231f66d2SKevin Wolf -c "reopen -o overlap-check=cached" \ 63231f66d2SKevin Wolf -c "reopen -o overlap-check=constant" \ 64231f66d2SKevin Wolf -c "reopen -o overlap-check.template=all" \ 65231f66d2SKevin Wolf -c "reopen -o overlap-check.template=none" \ 66231f66d2SKevin Wolf -c "reopen -o overlap-check.template=cached" \ 67231f66d2SKevin Wolf -c "reopen -o overlap-check.template=constant" \ 68231f66d2SKevin Wolf -c "reopen -o overlap-check.main-header=on" \ 69231f66d2SKevin Wolf -c "reopen -o overlap-check.main-header=off" \ 70231f66d2SKevin Wolf -c "reopen -o overlap-check.active-l1=on" \ 71231f66d2SKevin Wolf -c "reopen -o overlap-check.active-l1=off" \ 72231f66d2SKevin Wolf -c "reopen -o overlap-check.active-l2=on" \ 73231f66d2SKevin Wolf -c "reopen -o overlap-check.active-l2=off" \ 74231f66d2SKevin Wolf -c "reopen -o overlap-check.refcount-table=on" \ 75231f66d2SKevin Wolf -c "reopen -o overlap-check.refcount-table=off" \ 76231f66d2SKevin Wolf -c "reopen -o overlap-check.refcount-block=on" \ 77231f66d2SKevin Wolf -c "reopen -o overlap-check.refcount-block=off" \ 78231f66d2SKevin Wolf -c "reopen -o overlap-check.snapshot-table=on" \ 79231f66d2SKevin Wolf -c "reopen -o overlap-check.snapshot-table=off" \ 80231f66d2SKevin Wolf -c "reopen -o overlap-check.inactive-l1=on" \ 81231f66d2SKevin Wolf -c "reopen -o overlap-check.inactive-l1=off" \ 82231f66d2SKevin Wolf -c "reopen -o overlap-check.inactive-l2=on" \ 83231f66d2SKevin Wolf -c "reopen -o overlap-check.inactive-l2=off" \ 84231f66d2SKevin Wolf -c "reopen -o cache-size=1M" \ 85231f66d2SKevin Wolf -c "reopen -o l2-cache-size=512k" \ 8603b1b6f0SAlberto Garcia -c "reopen -o l2-cache-entry-size=512" \ 8703b1b6f0SAlberto Garcia -c "reopen -o l2-cache-entry-size=4k" \ 8803b1b6f0SAlberto Garcia -c "reopen -o l2-cache-entry-size=64k" \ 89231f66d2SKevin Wolf -c "reopen -o refcount-cache-size=128k" \ 90231f66d2SKevin Wolf -c "reopen -o cache-clean-interval=5" \ 91231f66d2SKevin Wolf -c "reopen -o cache-clean-interval=0" \ 92231f66d2SKevin Wolf -c "reopen -o cache-clean-interval=10" \ 93231f66d2SKevin Wolf \ 94231f66d2SKevin Wolf -c "write -P 55 0 32M" \ 95231f66d2SKevin Wolf -c "read -P 55 0 32M" \ 96231f66d2SKevin Wolf -c "discard 0 32M" \ 97231f66d2SKevin Wolf -c "write -z 0 32M" \ 98231f66d2SKevin Wolf -c "read -P 0 0 32M" \ 99231f66d2SKevin Wolf \ 100231f66d2SKevin Wolf "$TEST_IMG" | _filter_qemu_io 101231f66d2SKevin Wolf 102231f66d2SKevin Wolf 103231f66d2SKevin Wolfecho 104231f66d2SKevin Wolfecho === Try setting some invalid values === 105231f66d2SKevin Wolfecho 106231f66d2SKevin Wolf 107231f66d2SKevin Wolf$QEMU_IO \ 108231f66d2SKevin Wolf -c "reopen -o lazy-refcounts=42" \ 109231f66d2SKevin Wolf -c "reopen -o cache-size=1M,l2-cache-size=64k,refcount-cache-size=64k" \ 110231f66d2SKevin Wolf -c "reopen -o cache-size=1M,l2-cache-size=2M" \ 111231f66d2SKevin Wolf -c "reopen -o cache-size=1M,refcount-cache-size=2M" \ 11203b1b6f0SAlberto Garcia -c "reopen -o l2-cache-entry-size=33k" \ 11303b1b6f0SAlberto Garcia -c "reopen -o l2-cache-entry-size=128k" \ 114231f66d2SKevin Wolf -c "reopen -o refcount-cache-size=256T" \ 115231f66d2SKevin Wolf -c "reopen -o overlap-check=constant,overlap-check.template=all" \ 116231f66d2SKevin Wolf -c "reopen -o overlap-check=blubb" \ 117231f66d2SKevin Wolf -c "reopen -o overlap-check.template=blubb" \ 118231f66d2SKevin Wolf -c "reopen -o cache-clean-interval=-1" \ 119231f66d2SKevin Wolf "$TEST_IMG" | _filter_qemu_io 120231f66d2SKevin Wolf 121407fb56aSMax Reitz_make_test_img -o "cluster_size=256k" 32P 122b749562dSLeonid Bloch$QEMU_IO \ 123b749562dSLeonid Bloch -c "reopen -o l2-cache-entry-size=512,l2-cache-size=1T" \ 124b749562dSLeonid Bloch "$TEST_IMG" | _filter_qemu_io 125b749562dSLeonid Bloch 126b749562dSLeonid Bloch_make_test_img 64M 127b749562dSLeonid Bloch 128231f66d2SKevin Wolfecho 129231f66d2SKevin Wolfecho === Test transaction semantics === 130231f66d2SKevin Wolfecho 131231f66d2SKevin Wolf 132231f66d2SKevin Wolf# Whether lazy-refcounts was actually enabled can easily be tested: Check if 133231f66d2SKevin Wolf# the dirty bit is set after a crash 1348af224d6SAndrey Shinkevich_NO_VALGRIND \ 135231f66d2SKevin Wolf$QEMU_IO \ 136231f66d2SKevin Wolf -c "reopen -o lazy-refcounts=on,overlap-check=blubb" \ 137231f66d2SKevin Wolf -c "write -P 0x5a 0 512" \ 138231f66d2SKevin Wolf -c "sigraise $(kill -l KILL)" \ 139231f66d2SKevin Wolf "$TEST_IMG" 2>&1 | _filter_qemu_io 140231f66d2SKevin Wolf 141231f66d2SKevin Wolf# The dirty bit must not be set 142e66566e6SMax Reitz# (Filter the external data file bit) 143*984d7a52SVladimir Sementsov-Ogievskiyif _qcow2_dump_header | grep incompatible_features \ 144e66566e6SMax Reitz | grep -q '\<0\>' 145e66566e6SMax Reitzthen 146e66566e6SMax Reitz echo 'ERROR: Dirty bit set' 147e66566e6SMax Reitzelse 148e66566e6SMax Reitz echo 'OK: Dirty bit not set' 149e66566e6SMax Reitzfi 150231f66d2SKevin Wolf 151231f66d2SKevin Wolf# Similarly we can test whether corruption detection has been enabled: 152e66566e6SMax Reitz# Create L1, overwrite refcounts, force allocation of L2 by writing 153e66566e6SMax Reitz# data. 154231f66d2SKevin Wolf# Disabling the checks should fail, so the corruption must be detected. 155231f66d2SKevin Wolf_make_test_img 64M 156e66566e6SMax Reitzpoke_file "$TEST_IMG" "$((0x20000))" "\x00\x00\x00\x00\x00\x00\x00\x00" 157231f66d2SKevin Wolf$QEMU_IO \ 158231f66d2SKevin Wolf -c "reopen -o overlap-check=none,lazy-refcounts=42" \ 159231f66d2SKevin Wolf -c "write 64k 64k" \ 160231f66d2SKevin Wolf "$TEST_IMG" 2>&1 | _filter_qemu_io 161231f66d2SKevin Wolf 162231f66d2SKevin Wolf# success, all done 163231f66d2SKevin Wolfecho '*** done' 164231f66d2SKevin Wolfrm -f $seq.full 165231f66d2SKevin Wolfstatus=0 166