xref: /openbmc/qemu/tests/qemu-iotests/061 (revision a8110c3d327cabff8dc258c5c8705903b56c1513)
1*a8110c3dSMax Reitz#!/bin/bash
2*a8110c3dSMax Reitz#
3*a8110c3dSMax Reitz# Test case for image option amendment in qcow2.
4*a8110c3dSMax Reitz#
5*a8110c3dSMax Reitz# Copyright (C) 2013 Red Hat, Inc.
6*a8110c3dSMax Reitz#
7*a8110c3dSMax Reitz# This program is free software; you can redistribute it and/or modify
8*a8110c3dSMax Reitz# it under the terms of the GNU General Public License as published by
9*a8110c3dSMax Reitz# the Free Software Foundation; either version 2 of the License, or
10*a8110c3dSMax Reitz# (at your option) any later version.
11*a8110c3dSMax Reitz#
12*a8110c3dSMax Reitz# This program is distributed in the hope that it will be useful,
13*a8110c3dSMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*a8110c3dSMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*a8110c3dSMax Reitz# GNU General Public License for more details.
16*a8110c3dSMax Reitz#
17*a8110c3dSMax Reitz# You should have received a copy of the GNU General Public License
18*a8110c3dSMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*a8110c3dSMax Reitz#
20*a8110c3dSMax Reitz
21*a8110c3dSMax Reitz# creator
22*a8110c3dSMax Reitzowner=mreitz@redhat.com
23*a8110c3dSMax Reitz
24*a8110c3dSMax Reitzseq=`basename $0`
25*a8110c3dSMax Reitzecho "QA output created by $seq"
26*a8110c3dSMax Reitz
27*a8110c3dSMax Reitzhere=`pwd`
28*a8110c3dSMax Reitztmp=/tmp/$$
29*a8110c3dSMax Reitzstatus=1	# failure is the default!
30*a8110c3dSMax Reitz
31*a8110c3dSMax Reitz_cleanup()
32*a8110c3dSMax Reitz{
33*a8110c3dSMax Reitz	_cleanup_test_img
34*a8110c3dSMax Reitz}
35*a8110c3dSMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
36*a8110c3dSMax Reitz
37*a8110c3dSMax Reitz# get standard environment, filters and checks
38*a8110c3dSMax Reitz. ./common.rc
39*a8110c3dSMax Reitz. ./common.filter
40*a8110c3dSMax Reitz
41*a8110c3dSMax Reitz# This tests qocw2-specific low-level functionality
42*a8110c3dSMax Reitz_supported_fmt qcow2
43*a8110c3dSMax Reitz_supported_proto generic
44*a8110c3dSMax Reitz_supported_os Linux
45*a8110c3dSMax Reitz
46*a8110c3dSMax Reitzecho
47*a8110c3dSMax Reitzecho "=== Testing version downgrade with zero expansion ==="
48*a8110c3dSMax Reitzecho
49*a8110c3dSMax ReitzIMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M
50*a8110c3dSMax Reitz$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
51*a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" dump-header
52*a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
53*a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" dump-header
54*a8110c3dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
55*a8110c3dSMax Reitz_check_test_img
56*a8110c3dSMax Reitz
57*a8110c3dSMax Reitzecho
58*a8110c3dSMax Reitzecho "=== Testing dirty version downgrade ==="
59*a8110c3dSMax Reitzecho
60*a8110c3dSMax ReitzIMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M
61*a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" -c flush -c abort "$TEST_IMG" | _filter_qemu_io
62*a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" dump-header
63*a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
64*a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" dump-header
65*a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
66*a8110c3dSMax Reitz_check_test_img
67*a8110c3dSMax Reitz
68*a8110c3dSMax Reitzecho
69*a8110c3dSMax Reitzecho "=== Testing version downgrade with unknown compat/autoclear flags ==="
70*a8110c3dSMax Reitzecho
71*a8110c3dSMax ReitzIMGOPTS="compat=1.1" _make_test_img 64M
72*a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" set-feature-bit compatible 42
73*a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" set-feature-bit autoclear 42
74*a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" dump-header
75*a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
76*a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" dump-header
77*a8110c3dSMax Reitz_check_test_img
78*a8110c3dSMax Reitz
79*a8110c3dSMax Reitzecho
80*a8110c3dSMax Reitzecho "=== Testing version upgrade and resize ==="
81*a8110c3dSMax Reitzecho
82*a8110c3dSMax ReitzIMGOPTS="compat=0.10" _make_test_img 64M
83*a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
84*a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" dump-header
85*a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=1.1,lazy_refcounts=on,size=128M" "$TEST_IMG"
86*a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" dump-header
87*a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
88*a8110c3dSMax Reitz_check_test_img
89*a8110c3dSMax Reitz
90*a8110c3dSMax Reitzecho
91*a8110c3dSMax Reitzecho "=== Testing dirty lazy_refcounts=off ==="
92*a8110c3dSMax Reitzecho
93*a8110c3dSMax ReitzIMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M
94*a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" -c flush -c abort "$TEST_IMG" | _filter_qemu_io
95*a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" dump-header
96*a8110c3dSMax Reitz$QEMU_IMG amend -o "lazy_refcounts=off" "$TEST_IMG"
97*a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" dump-header
98*a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
99*a8110c3dSMax Reitz_check_test_img
100*a8110c3dSMax Reitz
101*a8110c3dSMax Reitzecho
102*a8110c3dSMax Reitzecho "=== Testing backing file ==="
103*a8110c3dSMax Reitzecho
104*a8110c3dSMax ReitzIMGOPTS="compat=1.1" _make_test_img 64M
105*a8110c3dSMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
106*a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
107*a8110c3dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
108*a8110c3dSMax Reitz$QEMU_IMG amend -o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG"
109*a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
110*a8110c3dSMax Reitz_check_test_img
111*a8110c3dSMax Reitz
112*a8110c3dSMax Reitzecho
113*a8110c3dSMax Reitzecho "=== Testing invalid configurations ==="
114*a8110c3dSMax Reitzecho
115*a8110c3dSMax ReitzIMGOPTS="compat=0.10" _make_test_img 64M
116*a8110c3dSMax Reitz$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
117*a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=1.1" "$TEST_IMG" # actually valid
118*a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10,lazy_refcounts=on" "$TEST_IMG"
119*a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.42" "$TEST_IMG"
120*a8110c3dSMax Reitz$QEMU_IMG amend -o "foo=bar" "$TEST_IMG"
121*a8110c3dSMax Reitz$QEMU_IMG amend -o "cluster_size=1k" "$TEST_IMG"
122*a8110c3dSMax Reitz$QEMU_IMG amend -o "encryption=on" "$TEST_IMG"
123*a8110c3dSMax Reitz$QEMU_IMG amend -o "preallocation=on" "$TEST_IMG"
124*a8110c3dSMax Reitz
125*a8110c3dSMax Reitzecho
126*a8110c3dSMax Reitzecho "=== Testing correct handling of unset value ==="
127*a8110c3dSMax Reitzecho
128*a8110c3dSMax ReitzIMGOPTS="compat=1.1,cluster_size=1k" _make_test_img 64M
129*a8110c3dSMax Reitzecho "Should work:"
130*a8110c3dSMax Reitz$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
131*a8110c3dSMax Reitzecho "Should not work:" # Just to know which of these tests actually fails
132*a8110c3dSMax Reitz$QEMU_IMG amend -o "cluster_size=64k" "$TEST_IMG"
133*a8110c3dSMax Reitz
134*a8110c3dSMax Reitzecho
135*a8110c3dSMax Reitzecho "=== Testing zero expansion on inactive clusters ==="
136*a8110c3dSMax Reitzecho
137*a8110c3dSMax ReitzIMGOPTS="compat=1.1" _make_test_img 64M
138*a8110c3dSMax Reitz$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
139*a8110c3dSMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG"
140*a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
141*a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
142*a8110c3dSMax Reitz_check_test_img
143*a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
144*a8110c3dSMax Reitz$QEMU_IMG snapshot -a foo "$TEST_IMG"
145*a8110c3dSMax Reitz_check_test_img
146*a8110c3dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
147*a8110c3dSMax Reitz
148*a8110c3dSMax Reitzecho
149*a8110c3dSMax Reitzecho "=== Testing zero expansion on backed image ==="
150*a8110c3dSMax Reitzecho
151*a8110c3dSMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
152*a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
153*a8110c3dSMax ReitzIMGOPTS="compat=1.1,backing_file=$TEST_IMG.base" _make_test_img 64M
154*a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
155*a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
156*a8110c3dSMax Reitz_check_test_img
157*a8110c3dSMax Reitz$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
158*a8110c3dSMax Reitz
159*a8110c3dSMax Reitzecho
160*a8110c3dSMax Reitzecho "=== Testing zero expansion on backed inactive clusters ==="
161*a8110c3dSMax Reitzecho
162*a8110c3dSMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
163*a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
164*a8110c3dSMax ReitzIMGOPTS="compat=1.1,backing_file=$TEST_IMG.base" _make_test_img 64M
165*a8110c3dSMax Reitz$QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
166*a8110c3dSMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG"
167*a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
168*a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
169*a8110c3dSMax Reitz_check_test_img
170*a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
171*a8110c3dSMax Reitz$QEMU_IMG snapshot -a foo "$TEST_IMG"
172*a8110c3dSMax Reitz_check_test_img
173*a8110c3dSMax Reitz$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
174*a8110c3dSMax Reitz
175*a8110c3dSMax Reitz# success, all done
176*a8110c3dSMax Reitzecho "*** done"
177*a8110c3dSMax Reitzrm -f $seq.full
178*a8110c3dSMax Reitzstatus=0
179