blob: e43e7026ce335d8b2825203316048fff04789709 [file] [log] [blame]
Philippe Mathieu-Daudé11a82d12019-03-07 15:58:38 +01001#!/usr/bin/env bash
Vladimir Sementsov-Ogievskiy9dd003a2021-01-16 16:44:19 +03002# group: rw auto quick
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +01003#
4# Test qcow2 lazy refcounts
5#
6# Copyright (C) 2012 Red Hat, Inc.
7# Copyright IBM, Corp. 2010
8#
9# Based on test 038.
10#
11# This program is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation; either version 2 of the License, or
14# (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program. If not, see <http://www.gnu.org/licenses/>.
23#
24
25# creator
John Snow42a50092022-03-22 13:42:12 -040026owner=stefanha@redhat.com
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +010027
28seq=`basename $0`
29echo "QA output created by $seq"
30
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +010031status=1 # failure is the default!
32
33_cleanup()
34{
35 _cleanup_test_img
36}
37trap "_cleanup; exit \$status" 0 1 2 3 15
38
39# get standard environment, filters and checks
40. ./common.rc
41. ./common.filter
42
43_supported_fmt qcow2
Max Reitz57284d22020-10-27 20:05:59 +010044_supported_proto file fuse
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +010045_supported_os Linux
Nir Soffer755c5fe2019-08-27 20:34:32 +030046_default_cache_mode writethrough
47_supported_cache_modes writethrough
Max Reitz3be20242019-11-07 17:37:07 +010048# Some of these test cases expect no external data file so that all
49# clusters are part of the qcow2 image and refcounted
50_unsupported_imgopts data_file
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +010051
52size=128M
53
54echo
55echo "== Checking that image is clean on shutdown =="
56
Max Reitz407fb562019-11-07 17:36:57 +010057_make_test_img -o "compat=1.1,lazy_refcounts=on" $size
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +010058
Jeff Codyf897e392013-10-31 11:57:40 -040059$QEMU_IO -c "write -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +010060
61# The dirty bit must not be set
Vladimir Sementsov-Ogievskiy984d7a52021-12-23 17:01:39 +010062_qcow2_dump_header | grep incompatible_features
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +010063_check_test_img
64
65echo
66echo "== Creating a dirty image file =="
67
Max Reitz407fb562019-11-07 17:36:57 +010068_make_test_img -o "compat=1.1,lazy_refcounts=on" $size
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +010069
Andrey Shinkevich8af224d2019-09-04 12:11:20 +030070_NO_VALGRIND \
Max Reitz934659c2015-09-02 20:52:27 +020071$QEMU_IO -c "write -P 0x5a 0 512" \
72 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \
Max Reitz3f394472014-12-08 10:48:12 +010073 | _filter_qemu_io
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +010074
75# The dirty bit must be set
Vladimir Sementsov-Ogievskiy984d7a52021-12-23 17:01:39 +010076_qcow2_dump_header | grep incompatible_features
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +010077_check_test_img
78
79echo
80echo "== Read-only access must still work =="
81
Jeff Codyfef9c192013-09-25 08:12:22 -040082$QEMU_IO -r -c "read -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +010083
84# The dirty bit must be set
Vladimir Sementsov-Ogievskiy984d7a52021-12-23 17:01:39 +010085_qcow2_dump_header | grep incompatible_features
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +010086
87echo
88echo "== Repairing the image file must succeed =="
89
Federico Simoncellic6bb9ad2013-01-28 06:59:46 -050090_check_test_img -r all
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +010091
92# The dirty bit must not be set
Vladimir Sementsov-Ogievskiy984d7a52021-12-23 17:01:39 +010093_qcow2_dump_header | grep incompatible_features
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +010094
95echo
96echo "== Data should still be accessible after repair =="
97
Jeff Codyfef9c192013-09-25 08:12:22 -040098$QEMU_IO -c "read -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +010099
100echo
101echo "== Opening a dirty image read/write should repair it =="
102
Max Reitz407fb562019-11-07 17:36:57 +0100103_make_test_img -o "compat=1.1,lazy_refcounts=on" $size
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +0100104
Andrey Shinkevich8af224d2019-09-04 12:11:20 +0300105_NO_VALGRIND \
Max Reitz934659c2015-09-02 20:52:27 +0200106$QEMU_IO -c "write -P 0x5a 0 512" \
107 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \
Max Reitz3f394472014-12-08 10:48:12 +0100108 | _filter_qemu_io
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +0100109
110# The dirty bit must be set
Vladimir Sementsov-Ogievskiy984d7a52021-12-23 17:01:39 +0100111_qcow2_dump_header | grep incompatible_features
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +0100112
Jeff Codyfef9c192013-09-25 08:12:22 -0400113$QEMU_IO -c "write 0 512" "$TEST_IMG" | _filter_qemu_io
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +0100114
115# The dirty bit must not be set
Vladimir Sementsov-Ogievskiy984d7a52021-12-23 17:01:39 +0100116_qcow2_dump_header | grep incompatible_features
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +0100117
118echo
119echo "== Creating an image file with lazy_refcounts=off =="
120
Max Reitz407fb562019-11-07 17:36:57 +0100121_make_test_img -o "compat=1.1,lazy_refcounts=off" $size
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +0100122
Andrey Shinkevich8af224d2019-09-04 12:11:20 +0300123_NO_VALGRIND \
Max Reitz934659c2015-09-02 20:52:27 +0200124$QEMU_IO -c "write -P 0x5a 0 512" \
125 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \
Max Reitz3f394472014-12-08 10:48:12 +0100126 | _filter_qemu_io
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +0100127
128# The dirty bit must not be set since lazy_refcounts=off
Vladimir Sementsov-Ogievskiy984d7a52021-12-23 17:01:39 +0100129_qcow2_dump_header | grep incompatible_features
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +0100130_check_test_img
131
Kevin Wolf4c2e5f82014-04-03 13:47:50 +0200132echo
133echo "== Committing to a backing file with lazy_refcounts=on =="
134
Max Reitz407fb562019-11-07 17:36:57 +0100135TEST_IMG="$TEST_IMG".base _make_test_img -o "compat=1.1,lazy_refcounts=on" $size
Kevin Wolf4c2e5f82014-04-03 13:47:50 +0200136
Eric Blakeb66ff2c2020-07-06 15:39:52 -0500137_make_test_img -o "compat=1.1,lazy_refcounts=on,backing_file=$TEST_IMG.base" \
138 -F $IMGFMT $size
Kevin Wolf4c2e5f82014-04-03 13:47:50 +0200139
140$QEMU_IO -c "write 0 512" "$TEST_IMG" | _filter_qemu_io
141$QEMU_IMG commit "$TEST_IMG"
142
143# The dirty bit must not be set
Vladimir Sementsov-Ogievskiy984d7a52021-12-23 17:01:39 +0100144_qcow2_dump_header | grep incompatible_features
Vladimir Sementsov-Ogievskiy72be51d2021-12-23 17:01:40 +0100145_qcow2_dump_header "$TEST_IMG".base | grep incompatible_features
Kevin Wolf4c2e5f82014-04-03 13:47:50 +0200146
147_check_test_img
148TEST_IMG="$TEST_IMG".base _check_test_img
149
Kevin Wolfe6150532015-09-04 18:26:09 +0200150echo
151echo "== Changing lazy_refcounts setting at runtime =="
152
Max Reitz407fb562019-11-07 17:36:57 +0100153_make_test_img -o "compat=1.1,lazy_refcounts=off" $size
Kevin Wolfe6150532015-09-04 18:26:09 +0200154
Andrey Shinkevich8af224d2019-09-04 12:11:20 +0300155_NO_VALGRIND \
Kevin Wolfe6150532015-09-04 18:26:09 +0200156$QEMU_IO -c "reopen -o lazy-refcounts=on" \
157 -c "write -P 0x5a 0 512" \
158 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \
159 | _filter_qemu_io
160
161# The dirty bit must be set
Vladimir Sementsov-Ogievskiy984d7a52021-12-23 17:01:39 +0100162_qcow2_dump_header | grep incompatible_features
Kevin Wolfe6150532015-09-04 18:26:09 +0200163_check_test_img
164
Max Reitz407fb562019-11-07 17:36:57 +0100165_make_test_img -o "compat=1.1,lazy_refcounts=on" $size
Kevin Wolfe6150532015-09-04 18:26:09 +0200166
Andrey Shinkevich8af224d2019-09-04 12:11:20 +0300167_NO_VALGRIND \
Kevin Wolfe6150532015-09-04 18:26:09 +0200168$QEMU_IO -c "reopen -o lazy-refcounts=off" \
169 -c "write -P 0x5a 0 512" \
170 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \
171 | _filter_qemu_io
172
173# The dirty bit must not be set
Vladimir Sementsov-Ogievskiy984d7a52021-12-23 17:01:39 +0100174_qcow2_dump_header | grep incompatible_features
Kevin Wolfe6150532015-09-04 18:26:09 +0200175_check_test_img
176
Kevin Wolf4c2e5f82014-04-03 13:47:50 +0200177
Stefan Hajnoczidc68afe2012-07-27 09:05:24 +0100178# success, all done
179echo "*** done"
180rm -f $seq.full
181status=0
182