xref: /openbmc/qemu/tests/qemu-iotests/039 (revision dc68afe0)
1*dc68afe0SStefan Hajnoczi#!/bin/bash
2*dc68afe0SStefan Hajnoczi#
3*dc68afe0SStefan Hajnoczi# Test qcow2 lazy refcounts
4*dc68afe0SStefan Hajnoczi#
5*dc68afe0SStefan Hajnoczi# Copyright (C) 2012 Red Hat, Inc.
6*dc68afe0SStefan Hajnoczi# Copyright IBM, Corp. 2010
7*dc68afe0SStefan Hajnoczi#
8*dc68afe0SStefan Hajnoczi# Based on test 038.
9*dc68afe0SStefan Hajnoczi#
10*dc68afe0SStefan Hajnoczi# This program is free software; you can redistribute it and/or modify
11*dc68afe0SStefan Hajnoczi# it under the terms of the GNU General Public License as published by
12*dc68afe0SStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or
13*dc68afe0SStefan Hajnoczi# (at your option) any later version.
14*dc68afe0SStefan Hajnoczi#
15*dc68afe0SStefan Hajnoczi# This program is distributed in the hope that it will be useful,
16*dc68afe0SStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of
17*dc68afe0SStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*dc68afe0SStefan Hajnoczi# GNU General Public License for more details.
19*dc68afe0SStefan Hajnoczi#
20*dc68afe0SStefan Hajnoczi# You should have received a copy of the GNU General Public License
21*dc68afe0SStefan Hajnoczi# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22*dc68afe0SStefan Hajnoczi#
23*dc68afe0SStefan Hajnoczi
24*dc68afe0SStefan Hajnoczi# creator
25*dc68afe0SStefan Hajnocziowner=stefanha@linux.vnet.ibm.com
26*dc68afe0SStefan Hajnoczi
27*dc68afe0SStefan Hajnocziseq=`basename $0`
28*dc68afe0SStefan Hajnocziecho "QA output created by $seq"
29*dc68afe0SStefan Hajnoczi
30*dc68afe0SStefan Hajnoczihere=`pwd`
31*dc68afe0SStefan Hajnoczitmp=/tmp/$$
32*dc68afe0SStefan Hajnoczistatus=1	# failure is the default!
33*dc68afe0SStefan Hajnoczi
34*dc68afe0SStefan Hajnoczi_cleanup()
35*dc68afe0SStefan Hajnoczi{
36*dc68afe0SStefan Hajnoczi	_cleanup_test_img
37*dc68afe0SStefan Hajnoczi}
38*dc68afe0SStefan Hajnoczitrap "_cleanup; exit \$status" 0 1 2 3 15
39*dc68afe0SStefan Hajnoczi
40*dc68afe0SStefan Hajnoczi# get standard environment, filters and checks
41*dc68afe0SStefan Hajnoczi. ./common.rc
42*dc68afe0SStefan Hajnoczi. ./common.filter
43*dc68afe0SStefan Hajnoczi
44*dc68afe0SStefan Hajnoczi_supported_fmt qcow2
45*dc68afe0SStefan Hajnoczi_supported_proto generic
46*dc68afe0SStefan Hajnoczi_supported_os Linux
47*dc68afe0SStefan Hajnoczi
48*dc68afe0SStefan Hajnoczisize=128M
49*dc68afe0SStefan Hajnoczi
50*dc68afe0SStefan Hajnocziecho
51*dc68afe0SStefan Hajnocziecho "== Checking that image is clean on shutdown =="
52*dc68afe0SStefan Hajnoczi
53*dc68afe0SStefan HajnocziIMGOPTS="compat=1.1,lazy_refcounts=on"
54*dc68afe0SStefan Hajnoczi_make_test_img $size
55*dc68afe0SStefan Hajnoczi
56*dc68afe0SStefan Hajnoczi$QEMU_IO -c "write -P 0x5a 0 512" $TEST_IMG | _filter_qemu_io
57*dc68afe0SStefan Hajnoczi
58*dc68afe0SStefan Hajnoczi# The dirty bit must not be set
59*dc68afe0SStefan Hajnoczi./qcow2.py $TEST_IMG dump-header | grep incompatible_features
60*dc68afe0SStefan Hajnoczi_check_test_img
61*dc68afe0SStefan Hajnoczi
62*dc68afe0SStefan Hajnocziecho
63*dc68afe0SStefan Hajnocziecho "== Creating a dirty image file =="
64*dc68afe0SStefan Hajnoczi
65*dc68afe0SStefan HajnocziIMGOPTS="compat=1.1,lazy_refcounts=on"
66*dc68afe0SStefan Hajnoczi_make_test_img $size
67*dc68afe0SStefan Hajnoczi
68*dc68afe0SStefan Hajnocziold_ulimit=$(ulimit -c)
69*dc68afe0SStefan Hajnocziulimit -c 0 # do not produce a core dump on abort(3)
70*dc68afe0SStefan Hajnoczi$QEMU_IO -c "write -P 0x5a 0 512" -c "abort" $TEST_IMG | _filter_qemu_io
71*dc68afe0SStefan Hajnocziulimit -c "$old_ulimit"
72*dc68afe0SStefan Hajnoczi
73*dc68afe0SStefan Hajnoczi# The dirty bit must be set
74*dc68afe0SStefan Hajnoczi./qcow2.py $TEST_IMG dump-header | grep incompatible_features
75*dc68afe0SStefan Hajnoczi_check_test_img
76*dc68afe0SStefan Hajnoczi
77*dc68afe0SStefan Hajnocziecho
78*dc68afe0SStefan Hajnocziecho "== Read-only access must still work =="
79*dc68afe0SStefan Hajnoczi
80*dc68afe0SStefan Hajnoczi$QEMU_IO -r -c "read -P 0x5a 0 512" $TEST_IMG | _filter_qemu_io
81*dc68afe0SStefan Hajnoczi
82*dc68afe0SStefan Hajnoczi# The dirty bit must be set
83*dc68afe0SStefan Hajnoczi./qcow2.py $TEST_IMG dump-header | grep incompatible_features
84*dc68afe0SStefan Hajnoczi
85*dc68afe0SStefan Hajnocziecho
86*dc68afe0SStefan Hajnocziecho "== Repairing the image file must succeed =="
87*dc68afe0SStefan Hajnoczi
88*dc68afe0SStefan Hajnoczi$QEMU_IMG check -r all $TEST_IMG
89*dc68afe0SStefan Hajnoczi
90*dc68afe0SStefan Hajnoczi# The dirty bit must not be set
91*dc68afe0SStefan Hajnoczi./qcow2.py $TEST_IMG dump-header | grep incompatible_features
92*dc68afe0SStefan Hajnoczi
93*dc68afe0SStefan Hajnocziecho
94*dc68afe0SStefan Hajnocziecho "== Data should still be accessible after repair =="
95*dc68afe0SStefan Hajnoczi
96*dc68afe0SStefan Hajnoczi$QEMU_IO -c "read -P 0x5a 0 512" $TEST_IMG | _filter_qemu_io
97*dc68afe0SStefan Hajnoczi
98*dc68afe0SStefan Hajnocziecho
99*dc68afe0SStefan Hajnocziecho "== Opening a dirty image read/write should repair it =="
100*dc68afe0SStefan Hajnoczi
101*dc68afe0SStefan HajnocziIMGOPTS="compat=1.1,lazy_refcounts=on"
102*dc68afe0SStefan Hajnoczi_make_test_img $size
103*dc68afe0SStefan Hajnoczi
104*dc68afe0SStefan Hajnocziold_ulimit=$(ulimit -c)
105*dc68afe0SStefan Hajnocziulimit -c 0 # do not produce a core dump on abort(3)
106*dc68afe0SStefan Hajnoczi$QEMU_IO -c "write -P 0x5a 0 512" -c "abort" $TEST_IMG | _filter_qemu_io
107*dc68afe0SStefan Hajnocziulimit -c "$old_ulimit"
108*dc68afe0SStefan Hajnoczi
109*dc68afe0SStefan Hajnoczi# The dirty bit must be set
110*dc68afe0SStefan Hajnoczi./qcow2.py $TEST_IMG dump-header | grep incompatible_features
111*dc68afe0SStefan Hajnoczi
112*dc68afe0SStefan Hajnoczi$QEMU_IO -c "write 0 512" $TEST_IMG | _filter_qemu_io
113*dc68afe0SStefan Hajnoczi
114*dc68afe0SStefan Hajnoczi# The dirty bit must not be set
115*dc68afe0SStefan Hajnoczi./qcow2.py $TEST_IMG dump-header | grep incompatible_features
116*dc68afe0SStefan Hajnoczi
117*dc68afe0SStefan Hajnocziecho
118*dc68afe0SStefan Hajnocziecho "== Creating an image file with lazy_refcounts=off =="
119*dc68afe0SStefan Hajnoczi
120*dc68afe0SStefan HajnocziIMGOPTS="compat=1.1,lazy_refcounts=off"
121*dc68afe0SStefan Hajnoczi_make_test_img $size
122*dc68afe0SStefan Hajnoczi
123*dc68afe0SStefan Hajnocziold_ulimit=$(ulimit -c)
124*dc68afe0SStefan Hajnocziulimit -c 0 # do not produce a core dump on abort(3)
125*dc68afe0SStefan Hajnoczi$QEMU_IO -c "write -P 0x5a 0 512" -c "abort" $TEST_IMG | _filter_qemu_io
126*dc68afe0SStefan Hajnocziulimit -c "$old_ulimit"
127*dc68afe0SStefan Hajnoczi
128*dc68afe0SStefan Hajnoczi# The dirty bit must not be set since lazy_refcounts=off
129*dc68afe0SStefan Hajnoczi./qcow2.py $TEST_IMG dump-header | grep incompatible_features
130*dc68afe0SStefan Hajnoczi_check_test_img
131*dc68afe0SStefan Hajnoczi
132*dc68afe0SStefan Hajnoczi# success, all done
133*dc68afe0SStefan Hajnocziecho "*** done"
134*dc68afe0SStefan Hajnoczirm -f $seq.full
135*dc68afe0SStefan Hajnoczistatus=0
136*dc68afe0SStefan Hajnoczi
137