xref: /openbmc/qemu/tests/qemu-iotests/039 (revision 4c2e5f8f)
1dc68afe0SStefan Hajnoczi#!/bin/bash
2dc68afe0SStefan Hajnoczi#
3dc68afe0SStefan Hajnoczi# Test qcow2 lazy refcounts
4dc68afe0SStefan Hajnoczi#
5dc68afe0SStefan Hajnoczi# Copyright (C) 2012 Red Hat, Inc.
6dc68afe0SStefan Hajnoczi# Copyright IBM, Corp. 2010
7dc68afe0SStefan Hajnoczi#
8dc68afe0SStefan Hajnoczi# Based on test 038.
9dc68afe0SStefan Hajnoczi#
10dc68afe0SStefan Hajnoczi# This program is free software; you can redistribute it and/or modify
11dc68afe0SStefan Hajnoczi# it under the terms of the GNU General Public License as published by
12dc68afe0SStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or
13dc68afe0SStefan Hajnoczi# (at your option) any later version.
14dc68afe0SStefan Hajnoczi#
15dc68afe0SStefan Hajnoczi# This program is distributed in the hope that it will be useful,
16dc68afe0SStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of
17dc68afe0SStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18dc68afe0SStefan Hajnoczi# GNU General Public License for more details.
19dc68afe0SStefan Hajnoczi#
20dc68afe0SStefan Hajnoczi# You should have received a copy of the GNU General Public License
21dc68afe0SStefan Hajnoczi# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22dc68afe0SStefan Hajnoczi#
23dc68afe0SStefan Hajnoczi
24dc68afe0SStefan Hajnoczi# creator
25dc68afe0SStefan Hajnocziowner=stefanha@linux.vnet.ibm.com
26dc68afe0SStefan Hajnoczi
27dc68afe0SStefan Hajnocziseq=`basename $0`
28dc68afe0SStefan Hajnocziecho "QA output created by $seq"
29dc68afe0SStefan Hajnoczi
30dc68afe0SStefan Hajnoczihere=`pwd`
31dc68afe0SStefan Hajnoczitmp=/tmp/$$
32dc68afe0SStefan Hajnoczistatus=1	# failure is the default!
33dc68afe0SStefan Hajnoczi
34dc68afe0SStefan Hajnoczi_cleanup()
35dc68afe0SStefan Hajnoczi{
36dc68afe0SStefan Hajnoczi	_cleanup_test_img
37dc68afe0SStefan Hajnoczi}
38dc68afe0SStefan Hajnoczitrap "_cleanup; exit \$status" 0 1 2 3 15
39dc68afe0SStefan Hajnoczi
40dc68afe0SStefan Hajnoczi# get standard environment, filters and checks
41dc68afe0SStefan Hajnoczi. ./common.rc
42dc68afe0SStefan Hajnoczi. ./common.filter
43dc68afe0SStefan Hajnoczi
44dc68afe0SStefan Hajnoczi_supported_fmt qcow2
451f7bf7d0SPeter Lieven_supported_proto file
46dc68afe0SStefan Hajnoczi_supported_os Linux
47f210a83cSFam Zheng_default_cache_mode "writethrough"
48f210a83cSFam Zheng_supported_cache_modes "writethrough"
49dc68afe0SStefan Hajnoczi
50dc68afe0SStefan Hajnoczisize=128M
51dc68afe0SStefan Hajnoczi
52dc68afe0SStefan Hajnocziecho
53dc68afe0SStefan Hajnocziecho "== Checking that image is clean on shutdown =="
54dc68afe0SStefan Hajnoczi
55dc68afe0SStefan HajnocziIMGOPTS="compat=1.1,lazy_refcounts=on"
56dc68afe0SStefan Hajnoczi_make_test_img $size
57dc68afe0SStefan Hajnoczi
58f897e393SJeff Cody$QEMU_IO -c "write -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io
59dc68afe0SStefan Hajnoczi
60dc68afe0SStefan Hajnoczi# The dirty bit must not be set
61fef9c191SJeff Cody./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
62dc68afe0SStefan Hajnoczi_check_test_img
63dc68afe0SStefan Hajnoczi
64dc68afe0SStefan Hajnocziecho
65dc68afe0SStefan Hajnocziecho "== Creating a dirty image file =="
66dc68afe0SStefan Hajnoczi
67dc68afe0SStefan HajnocziIMGOPTS="compat=1.1,lazy_refcounts=on"
68dc68afe0SStefan Hajnoczi_make_test_img $size
69dc68afe0SStefan Hajnoczi
70dc68afe0SStefan Hajnocziold_ulimit=$(ulimit -c)
71dc68afe0SStefan Hajnocziulimit -c 0 # do not produce a core dump on abort(3)
72fef9c191SJeff Cody$QEMU_IO -c "write -P 0x5a 0 512" -c "abort" "$TEST_IMG" | _filter_qemu_io
73dc68afe0SStefan Hajnocziulimit -c "$old_ulimit"
74dc68afe0SStefan Hajnoczi
75dc68afe0SStefan Hajnoczi# The dirty bit must be set
76fef9c191SJeff Cody./qcow2.py "$TEST_IMG" 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
85fef9c191SJeff Cody./qcow2.py "$TEST_IMG" 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
93fef9c191SJeff Cody./qcow2.py "$TEST_IMG" 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
103dc68afe0SStefan HajnocziIMGOPTS="compat=1.1,lazy_refcounts=on"
104dc68afe0SStefan Hajnoczi_make_test_img $size
105dc68afe0SStefan Hajnoczi
106dc68afe0SStefan Hajnocziold_ulimit=$(ulimit -c)
107dc68afe0SStefan Hajnocziulimit -c 0 # do not produce a core dump on abort(3)
108fef9c191SJeff Cody$QEMU_IO -c "write -P 0x5a 0 512" -c "abort" "$TEST_IMG" | _filter_qemu_io
109dc68afe0SStefan Hajnocziulimit -c "$old_ulimit"
110dc68afe0SStefan Hajnoczi
111dc68afe0SStefan Hajnoczi# The dirty bit must be set
112fef9c191SJeff Cody./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
113dc68afe0SStefan Hajnoczi
114fef9c191SJeff Cody$QEMU_IO -c "write 0 512" "$TEST_IMG" | _filter_qemu_io
115dc68afe0SStefan Hajnoczi
116dc68afe0SStefan Hajnoczi# The dirty bit must not be set
117fef9c191SJeff Cody./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
118dc68afe0SStefan Hajnoczi
119dc68afe0SStefan Hajnocziecho
120dc68afe0SStefan Hajnocziecho "== Creating an image file with lazy_refcounts=off =="
121dc68afe0SStefan Hajnoczi
122dc68afe0SStefan HajnocziIMGOPTS="compat=1.1,lazy_refcounts=off"
123dc68afe0SStefan Hajnoczi_make_test_img $size
124dc68afe0SStefan Hajnoczi
125dc68afe0SStefan Hajnocziold_ulimit=$(ulimit -c)
126dc68afe0SStefan Hajnocziulimit -c 0 # do not produce a core dump on abort(3)
127fef9c191SJeff Cody$QEMU_IO -c "write -P 0x5a 0 512" -c "abort" "$TEST_IMG" | _filter_qemu_io
128dc68afe0SStefan Hajnocziulimit -c "$old_ulimit"
129dc68afe0SStefan Hajnoczi
130dc68afe0SStefan Hajnoczi# The dirty bit must not be set since lazy_refcounts=off
131fef9c191SJeff Cody./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
132dc68afe0SStefan Hajnoczi_check_test_img
133dc68afe0SStefan Hajnoczi
134*4c2e5f8fSKevin Wolfecho
135*4c2e5f8fSKevin Wolfecho "== Committing to a backing file with lazy_refcounts=on =="
136*4c2e5f8fSKevin Wolf
137*4c2e5f8fSKevin WolfIMGOPTS="compat=1.1,lazy_refcounts=on"
138*4c2e5f8fSKevin WolfTEST_IMG="$TEST_IMG".base _make_test_img $size
139*4c2e5f8fSKevin Wolf
140*4c2e5f8fSKevin WolfIMGOPTS="compat=1.1,lazy_refcounts=on,backing_file=$TEST_IMG.base"
141*4c2e5f8fSKevin Wolf_make_test_img $size
142*4c2e5f8fSKevin Wolf
143*4c2e5f8fSKevin Wolf$QEMU_IO -c "write 0 512" "$TEST_IMG" | _filter_qemu_io
144*4c2e5f8fSKevin Wolf$QEMU_IMG commit "$TEST_IMG"
145*4c2e5f8fSKevin Wolf
146*4c2e5f8fSKevin Wolf# The dirty bit must not be set
147*4c2e5f8fSKevin Wolf./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
148*4c2e5f8fSKevin Wolf./qcow2.py "$TEST_IMG".base dump-header | grep incompatible_features
149*4c2e5f8fSKevin Wolf
150*4c2e5f8fSKevin Wolf_check_test_img
151*4c2e5f8fSKevin WolfTEST_IMG="$TEST_IMG".base _check_test_img
152*4c2e5f8fSKevin Wolf
153*4c2e5f8fSKevin Wolf
154dc68afe0SStefan Hajnoczi# success, all done
155dc68afe0SStefan Hajnocziecho "*** done"
156dc68afe0SStefan Hajnoczirm -f $seq.full
157dc68afe0SStefan Hajnoczistatus=0
158dc68afe0SStefan Hajnoczi
159