xref: /openbmc/qemu/tests/qemu-iotests/137 (revision 03b1b6f0220d5f50471a1f702bedcd789fee032d)
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
422b12baf0SJeff Cody_supported_proto file
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" \
86*03b1b6f0SAlberto Garcia    -c "reopen -o l2-cache-entry-size=512" \
87*03b1b6f0SAlberto Garcia    -c "reopen -o l2-cache-entry-size=4k" \
88*03b1b6f0SAlberto 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" \
112231f66d2SKevin Wolf    -c "reopen -o l2-cache-size=256T" \
113*03b1b6f0SAlberto Garcia    -c "reopen -o l2-cache-entry-size=33k" \
114*03b1b6f0SAlberto Garcia    -c "reopen -o l2-cache-entry-size=128k" \
115231f66d2SKevin Wolf    -c "reopen -o refcount-cache-size=256T" \
116231f66d2SKevin Wolf    -c "reopen -o overlap-check=constant,overlap-check.template=all" \
117231f66d2SKevin Wolf    -c "reopen -o overlap-check=blubb" \
118231f66d2SKevin Wolf    -c "reopen -o overlap-check.template=blubb" \
119231f66d2SKevin Wolf    -c "reopen -o cache-clean-interval=-1" \
120231f66d2SKevin Wolf    "$TEST_IMG" | _filter_qemu_io
121231f66d2SKevin Wolf
122231f66d2SKevin Wolfecho
123231f66d2SKevin Wolfecho === Test transaction semantics ===
124231f66d2SKevin Wolfecho
125231f66d2SKevin Wolf
126231f66d2SKevin Wolf# Whether lazy-refcounts was actually enabled can easily be tested: Check if
127231f66d2SKevin Wolf# the dirty bit is set after a crash
128231f66d2SKevin Wolf$QEMU_IO \
129231f66d2SKevin Wolf    -c "reopen -o lazy-refcounts=on,overlap-check=blubb" \
130231f66d2SKevin Wolf    -c "write -P 0x5a 0 512" \
131231f66d2SKevin Wolf    -c "sigraise $(kill -l KILL)" \
132231f66d2SKevin Wolf    "$TEST_IMG" 2>&1 | _filter_qemu_io
133231f66d2SKevin Wolf
134231f66d2SKevin Wolf# The dirty bit must not be set
135231f66d2SKevin Wolf$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
136231f66d2SKevin Wolf
137231f66d2SKevin Wolf# Similarly we can test whether corruption detection has been enabled:
138231f66d2SKevin Wolf# Create L1/L2, overwrite first entry in refcount block, allocate something.
139231f66d2SKevin Wolf# Disabling the checks should fail, so the corruption must be detected.
140231f66d2SKevin Wolf_make_test_img 64M
141231f66d2SKevin Wolf$QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io
142231f66d2SKevin Wolfpoke_file "$TEST_IMG" "$((0x20000))" "\x00\x00"
143231f66d2SKevin Wolf$QEMU_IO \
144231f66d2SKevin Wolf    -c "reopen -o overlap-check=none,lazy-refcounts=42" \
145231f66d2SKevin Wolf    -c "write 64k 64k" \
146231f66d2SKevin Wolf    "$TEST_IMG" 2>&1 | _filter_qemu_io
147231f66d2SKevin Wolf
148231f66d2SKevin Wolf# success, all done
149231f66d2SKevin Wolfecho '*** done'
150231f66d2SKevin Wolfrm -f $seq.full
151231f66d2SKevin Wolfstatus=0
152