qemu-iotests: Test invalid resize on luks
[qemu/ar7.git] / tests / qemu-iotests / 210
blobe607c0d296d351f1df898ca49d28f2970e730724
1 #!/bin/bash
3 # Test luks and file image creation
5 # Copyright (C) 2018 Red Hat, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # creator
22 owner=kwolf@redhat.com
24 seq=`basename $0`
25 echo "QA output created by $seq"
27 here=`pwd`
28 status=1 # failure is the default!
30 # get standard environment, filters and checks
31 . ./common.rc
32 . ./common.filter
34 _supported_fmt luks
35 _supported_proto file
36 _supported_os Linux
38 function do_run_qemu()
40 echo Testing: "$@"
41 $QEMU -nographic -qmp stdio -serial none "$@"
42 echo
45 function run_qemu()
47 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \
48 | _filter_qemu | _filter_imgfmt \
49 | _filter_actual_image_size
52 echo
53 echo "=== Successful image creation (defaults) ==="
54 echo
56 size=$((128 * 1024 * 1024))
58 run_qemu -object secret,id=keysec0,data="foo" <<EOF
59 { "execute": "qmp_capabilities" }
60 { "execute": "x-blockdev-create",
61 "arguments": {
62 "driver": "file",
63 "filename": "$TEST_IMG_FILE",
64 "size": 0
67 { "execute": "blockdev-add",
68 "arguments": {
69 "driver": "file",
70 "node-name": "imgfile",
71 "filename": "$TEST_IMG_FILE"
74 { "execute": "x-blockdev-create",
75 "arguments": {
76 "driver": "$IMGFMT",
77 "file": "imgfile",
78 "key-secret": "keysec0",
79 "size": $size,
80 "iter-time": 10
83 { "execute": "quit" }
84 EOF
86 _img_info --format-specific | _filter_img_info --format-specific
88 echo
89 echo "=== Successful image creation (with non-default options) ==="
90 echo
92 # Choose a different size to show that we got a new image
93 size=$((64 * 1024 * 1024))
95 run_qemu -object secret,id=keysec0,data="foo" <<EOF
96 { "execute": "qmp_capabilities" }
97 { "execute": "x-blockdev-create",
98 "arguments": {
99 "driver": "file",
100 "filename": "$TEST_IMG_FILE",
101 "size": 0
104 { "execute": "x-blockdev-create",
105 "arguments": {
106 "driver": "$IMGFMT",
107 "file": {
108 "driver": "file",
109 "filename": "$TEST_IMG_FILE"
111 "size": $size,
112 "key-secret": "keysec0",
113 "cipher-alg": "twofish-128",
114 "cipher-mode": "ctr",
115 "ivgen-alg": "plain64",
116 "ivgen-hash-alg": "md5",
117 "hash-alg": "sha1",
118 "iter-time": 10
121 { "execute": "quit" }
124 _img_info --format-specific | _filter_img_info --format-specific
126 echo
127 echo "=== Invalid BlockdevRef ==="
128 echo
130 run_qemu <<EOF
131 { "execute": "qmp_capabilities" }
132 { "execute": "x-blockdev-create",
133 "arguments": {
134 "driver": "$IMGFMT",
135 "file": "this doesn't exist",
136 "size": $size
139 { "execute": "quit" }
142 echo
143 echo "=== Zero size ==="
144 echo
146 run_qemu -blockdev driver=file,filename="$TEST_IMG_FILE",node-name=node0 \
147 -object secret,id=keysec0,data="foo" <<EOF
148 { "execute": "qmp_capabilities" }
149 { "execute": "x-blockdev-create",
150 "arguments": {
151 "driver": "$IMGFMT",
152 "file": "node0",
153 "key-secret": "keysec0",
154 "size": 0,
155 "iter-time": 10
158 { "execute": "quit" }
161 _img_info | _filter_img_info
164 echo
165 echo "=== Invalid sizes ==="
166 echo
168 # TODO Negative image sizes aren't handled correctly, but this is a problem
169 # with QAPI's implementation of the 'size' type and affects other commands as
170 # well. Once this is fixed, we may want to add a test case here.
172 # 1. 2^64 - 512
173 # 2. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
174 # 3. 2^63 - 512 (generally valid, but with the crypto header the file will
175 # exceed 63 bits)
177 run_qemu -blockdev driver=file,filename="$TEST_IMG_FILE",node-name=node0 \
178 -object secret,id=keysec0,data="foo" <<EOF
179 { "execute": "qmp_capabilities" }
180 { "execute": "x-blockdev-create",
181 "arguments": {
182 "driver": "$IMGFMT",
183 "file": "node0",
184 "key-secret": "keysec0",
185 "size": 18446744073709551104
188 { "execute": "x-blockdev-create",
189 "arguments": {
190 "driver": "$IMGFMT",
191 "file": "node0",
192 "key-secret": "keysec0",
193 "size": 9223372036854775808
196 { "execute": "x-blockdev-create",
197 "arguments": {
198 "driver": "$IMGFMT",
199 "file": "node0",
200 "key-secret": "keysec0",
201 "size": 9223372036854775296
204 { "execute": "quit" }
207 echo
208 echo "=== Resize image with invalid sizes ==="
209 echo
211 run_qemu -blockdev driver=file,filename="$TEST_IMG_FILE",node-name=node0 \
212 -blockdev driver=luks,file=node0,key-secret=keysec0,node-name=node1 \
213 -object secret,id=keysec0,data="foo" <<EOF
214 { "execute": "qmp_capabilities" }
215 { "execute": "block_resize",
216 "arguments": {
217 "node-name": "node1",
218 "size": 9223372036854775296
221 { "execute": "block_resize",
222 "arguments": {
223 "node-name": "node1",
224 "size": 9223372036854775808
227 { "execute": "block_resize",
228 "arguments": {
229 "node-name": "node1",
230 "size": 18446744073709551104
233 { "execute": "block_resize",
234 "arguments": {
235 "node-name": "node1",
236 "size": -9223372036854775808
239 { "execute": "quit" }
242 _img_info | _filter_img_info
244 # success, all done
245 echo "*** done"
246 rm -f $seq.full
247 status=0