xref: /openbmc/qemu/tests/qemu-iotests/039 (revision 42a5009d)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
29dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto quick
3dc68afe0SStefan Hajnoczi#
4dc68afe0SStefan Hajnoczi# Test qcow2 lazy refcounts
5dc68afe0SStefan Hajnoczi#
6dc68afe0SStefan Hajnoczi# Copyright (C) 2012 Red Hat, Inc.
7dc68afe0SStefan Hajnoczi# Copyright IBM, Corp. 2010
8dc68afe0SStefan Hajnoczi#
9dc68afe0SStefan Hajnoczi# Based on test 038.
10dc68afe0SStefan Hajnoczi#
11dc68afe0SStefan Hajnoczi# This program is free software; you can redistribute it and/or modify
12dc68afe0SStefan Hajnoczi# it under the terms of the GNU General Public License as published by
13dc68afe0SStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or
14dc68afe0SStefan Hajnoczi# (at your option) any later version.
15dc68afe0SStefan Hajnoczi#
16dc68afe0SStefan Hajnoczi# This program is distributed in the hope that it will be useful,
17dc68afe0SStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of
18dc68afe0SStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19dc68afe0SStefan Hajnoczi# GNU General Public License for more details.
20dc68afe0SStefan Hajnoczi#
21dc68afe0SStefan Hajnoczi# You should have received a copy of the GNU General Public License
22dc68afe0SStefan Hajnoczi# along with this program.  If not, see <http://www.gnu.org/licenses/>.
23dc68afe0SStefan Hajnoczi#
24dc68afe0SStefan Hajnoczi
25dc68afe0SStefan Hajnoczi# creator
26*42a5009dSJohn Snowowner=stefanha@redhat.com
27dc68afe0SStefan Hajnoczi
28dc68afe0SStefan Hajnocziseq=`basename $0`
29dc68afe0SStefan Hajnocziecho "QA output created by $seq"
30dc68afe0SStefan Hajnoczi
31dc68afe0SStefan Hajnoczistatus=1	# failure is the default!
32dc68afe0SStefan Hajnoczi
33dc68afe0SStefan Hajnoczi_cleanup()
34dc68afe0SStefan Hajnoczi{
35dc68afe0SStefan Hajnoczi	_cleanup_test_img
36dc68afe0SStefan Hajnoczi}
37dc68afe0SStefan Hajnoczitrap "_cleanup; exit \$status" 0 1 2 3 15
38dc68afe0SStefan Hajnoczi
39dc68afe0SStefan Hajnoczi# get standard environment, filters and checks
40dc68afe0SStefan Hajnoczi. ./common.rc
41dc68afe0SStefan Hajnoczi. ./common.filter
42dc68afe0SStefan Hajnoczi
43dc68afe0SStefan Hajnoczi_supported_fmt qcow2
4457284d2aSMax Reitz_supported_proto file fuse
45dc68afe0SStefan Hajnoczi_supported_os Linux
46755c5fe7SNir Soffer_default_cache_mode writethrough
47755c5fe7SNir Soffer_supported_cache_modes writethrough
483be2024aSMax Reitz# Some of these test cases expect no external data file so that all
493be2024aSMax Reitz# clusters are part of the qcow2 image and refcounted
503be2024aSMax Reitz_unsupported_imgopts data_file
51dc68afe0SStefan Hajnoczi
52dc68afe0SStefan Hajnoczisize=128M
53dc68afe0SStefan Hajnoczi
54dc68afe0SStefan Hajnocziecho
55dc68afe0SStefan Hajnocziecho "== Checking that image is clean on shutdown =="
56dc68afe0SStefan Hajnoczi
57407fb56aSMax Reitz_make_test_img -o "compat=1.1,lazy_refcounts=on" $size
58dc68afe0SStefan Hajnoczi
59f897e393SJeff Cody$QEMU_IO -c "write -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io
60dc68afe0SStefan Hajnoczi
61dc68afe0SStefan Hajnoczi# The dirty bit must not be set
62984d7a52SVladimir Sementsov-Ogievskiy_qcow2_dump_header | grep incompatible_features
63dc68afe0SStefan Hajnoczi_check_test_img
64dc68afe0SStefan Hajnoczi
65dc68afe0SStefan Hajnocziecho
66dc68afe0SStefan Hajnocziecho "== Creating a dirty image file =="
67dc68afe0SStefan Hajnoczi
68407fb56aSMax Reitz_make_test_img -o "compat=1.1,lazy_refcounts=on" $size
69dc68afe0SStefan Hajnoczi
708af224d6SAndrey Shinkevich_NO_VALGRIND \
71934659c4SMax Reitz$QEMU_IO -c "write -P 0x5a 0 512" \
723f394472SMax Reitz         -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \
733f394472SMax Reitz    | _filter_qemu_io
74dc68afe0SStefan Hajnoczi
75dc68afe0SStefan Hajnoczi# The dirty bit must be set
76984d7a52SVladimir Sementsov-Ogievskiy_qcow2_dump_header | grep incompatible_features
77dc68afe0SStefan Hajnoczi_check_test_img
78dc68afe0SStefan Hajnoczi
79dc68afe0SStefan Hajnocziecho
80dc68afe0SStefan Hajnocziecho "== Read-only access must still work =="
81dc68afe0SStefan Hajnoczi
82fef9c191SJeff Cody$QEMU_IO -r -c "read -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io
83dc68afe0SStefan Hajnoczi
84dc68afe0SStefan Hajnoczi# The dirty bit must be set
85984d7a52SVladimir Sementsov-Ogievskiy_qcow2_dump_header | grep incompatible_features
86dc68afe0SStefan Hajnoczi
87dc68afe0SStefan Hajnocziecho
88dc68afe0SStefan Hajnocziecho "== Repairing the image file must succeed =="
89dc68afe0SStefan Hajnoczi
90c6bb9ad1SFederico Simoncelli_check_test_img -r all
91dc68afe0SStefan Hajnoczi
92dc68afe0SStefan Hajnoczi# The dirty bit must not be set
93984d7a52SVladimir Sementsov-Ogievskiy_qcow2_dump_header | grep incompatible_features
94dc68afe0SStefan Hajnoczi
95dc68afe0SStefan Hajnocziecho
96dc68afe0SStefan Hajnocziecho "== Data should still be accessible after repair =="
97dc68afe0SStefan Hajnoczi
98fef9c191SJeff Cody$QEMU_IO -c "read -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io
99dc68afe0SStefan Hajnoczi
100dc68afe0SStefan Hajnocziecho
101dc68afe0SStefan Hajnocziecho "== Opening a dirty image read/write should repair it =="
102dc68afe0SStefan Hajnoczi
103407fb56aSMax Reitz_make_test_img -o "compat=1.1,lazy_refcounts=on" $size
104dc68afe0SStefan Hajnoczi
1058af224d6SAndrey Shinkevich_NO_VALGRIND \
106934659c4SMax Reitz$QEMU_IO -c "write -P 0x5a 0 512" \
1073f394472SMax Reitz         -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \
1083f394472SMax Reitz    | _filter_qemu_io
109dc68afe0SStefan Hajnoczi
110dc68afe0SStefan Hajnoczi# The dirty bit must be set
111984d7a52SVladimir Sementsov-Ogievskiy_qcow2_dump_header | grep incompatible_features
112dc68afe0SStefan Hajnoczi
113fef9c191SJeff Cody$QEMU_IO -c "write 0 512" "$TEST_IMG" | _filter_qemu_io
114dc68afe0SStefan Hajnoczi
115dc68afe0SStefan Hajnoczi# The dirty bit must not be set
116984d7a52SVladimir Sementsov-Ogievskiy_qcow2_dump_header | grep incompatible_features
117dc68afe0SStefan Hajnoczi
118dc68afe0SStefan Hajnocziecho
119dc68afe0SStefan Hajnocziecho "== Creating an image file with lazy_refcounts=off =="
120dc68afe0SStefan Hajnoczi
121407fb56aSMax Reitz_make_test_img -o "compat=1.1,lazy_refcounts=off" $size
122dc68afe0SStefan Hajnoczi
1238af224d6SAndrey Shinkevich_NO_VALGRIND \
124934659c4SMax Reitz$QEMU_IO -c "write -P 0x5a 0 512" \
1253f394472SMax Reitz         -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \
1263f394472SMax Reitz    | _filter_qemu_io
127dc68afe0SStefan Hajnoczi
128dc68afe0SStefan Hajnoczi# The dirty bit must not be set since lazy_refcounts=off
129984d7a52SVladimir Sementsov-Ogievskiy_qcow2_dump_header | grep incompatible_features
130dc68afe0SStefan Hajnoczi_check_test_img
131dc68afe0SStefan Hajnoczi
1324c2e5f8fSKevin Wolfecho
1334c2e5f8fSKevin Wolfecho "== Committing to a backing file with lazy_refcounts=on =="
1344c2e5f8fSKevin Wolf
135407fb56aSMax ReitzTEST_IMG="$TEST_IMG".base _make_test_img -o "compat=1.1,lazy_refcounts=on" $size
1364c2e5f8fSKevin Wolf
137b66ff2c2SEric Blake_make_test_img -o "compat=1.1,lazy_refcounts=on,backing_file=$TEST_IMG.base" \
138b66ff2c2SEric Blake    -F $IMGFMT $size
1394c2e5f8fSKevin Wolf
1404c2e5f8fSKevin Wolf$QEMU_IO -c "write 0 512" "$TEST_IMG" | _filter_qemu_io
1414c2e5f8fSKevin Wolf$QEMU_IMG commit "$TEST_IMG"
1424c2e5f8fSKevin Wolf
1434c2e5f8fSKevin Wolf# The dirty bit must not be set
144984d7a52SVladimir Sementsov-Ogievskiy_qcow2_dump_header | grep incompatible_features
14572be51ddSVladimir Sementsov-Ogievskiy_qcow2_dump_header "$TEST_IMG".base | grep incompatible_features
1464c2e5f8fSKevin Wolf
1474c2e5f8fSKevin Wolf_check_test_img
1484c2e5f8fSKevin WolfTEST_IMG="$TEST_IMG".base _check_test_img
1494c2e5f8fSKevin Wolf
150e615053bSKevin Wolfecho
151e615053bSKevin Wolfecho "== Changing lazy_refcounts setting at runtime =="
152e615053bSKevin Wolf
153407fb56aSMax Reitz_make_test_img -o "compat=1.1,lazy_refcounts=off" $size
154e615053bSKevin Wolf
1558af224d6SAndrey Shinkevich_NO_VALGRIND \
156e615053bSKevin Wolf$QEMU_IO -c "reopen -o lazy-refcounts=on" \
157e615053bSKevin Wolf         -c "write -P 0x5a 0 512" \
158e615053bSKevin Wolf         -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \
159e615053bSKevin Wolf    | _filter_qemu_io
160e615053bSKevin Wolf
161e615053bSKevin Wolf# The dirty bit must be set
162984d7a52SVladimir Sementsov-Ogievskiy_qcow2_dump_header | grep incompatible_features
163e615053bSKevin Wolf_check_test_img
164e615053bSKevin Wolf
165407fb56aSMax Reitz_make_test_img -o "compat=1.1,lazy_refcounts=on" $size
166e615053bSKevin Wolf
1678af224d6SAndrey Shinkevich_NO_VALGRIND \
168e615053bSKevin Wolf$QEMU_IO -c "reopen -o lazy-refcounts=off" \
169e615053bSKevin Wolf         -c "write -P 0x5a 0 512" \
170e615053bSKevin Wolf         -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \
171e615053bSKevin Wolf    | _filter_qemu_io
172e615053bSKevin Wolf
173e615053bSKevin Wolf# The dirty bit must not be set
174984d7a52SVladimir Sementsov-Ogievskiy_qcow2_dump_header | grep incompatible_features
175e615053bSKevin Wolf_check_test_img
176e615053bSKevin Wolf
1774c2e5f8fSKevin Wolf
178dc68afe0SStefan Hajnoczi# success, all done
179dc68afe0SStefan Hajnocziecho "*** done"
180dc68afe0SStefan Hajnoczirm -f $seq.full
181dc68afe0SStefan Hajnoczistatus=0
182dc68afe0SStefan Hajnoczi
183