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/>.
22 owner
=kwolf@redhat.com
25 echo "QA output created by $seq"
28 status
=1 # failure is the default!
30 # get standard environment, filters and checks
38 function do_run_qemu
()
41 $QEMU -nographic -qmp stdio
-serial none
"$@"
47 do_run_qemu
"$@" 2>&1 | _filter_testdir | _filter_qmp \
48 | _filter_qemu | _filter_imgfmt \
49 | _filter_actual_image_size
53 echo "=== Successful image creation (defaults) ==="
56 size
=$
((128 * 1024 * 1024))
58 run_qemu
-object secret
,id
=keysec0
,data
="foo" <<EOF
59 { "execute": "qmp_capabilities" }
60 { "execute": "x-blockdev-create",
63 "filename": "$TEST_IMG_FILE",
67 { "execute": "blockdev-add",
70 "node-name": "imgfile",
71 "filename": "$TEST_IMG_FILE"
74 { "execute": "x-blockdev-create",
78 "key-secret": "keysec0",
86 _img_info
--format-specific | _filter_img_info
--format-specific
89 echo "=== Successful image creation (with non-default options) ==="
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",
100 "filename": "$TEST_IMG_FILE",
104 { "execute": "x-blockdev-create",
109 "filename": "$TEST_IMG_FILE"
112 "key-secret": "keysec0",
113 "cipher-alg": "twofish-128",
114 "cipher-mode": "ctr",
115 "ivgen-alg": "plain64",
116 "ivgen-hash-alg": "md5",
121 { "execute": "quit" }
124 _img_info
--format-specific | _filter_img_info
--format-specific
127 echo "=== Invalid BlockdevRef ==="
131 { "execute": "qmp_capabilities" }
132 { "execute": "x-blockdev-create",
135 "file": "this doesn't exist",
139 { "execute": "quit" }
143 echo "=== Zero size ==="
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",
153 "key-secret": "keysec0",
158 { "execute": "quit" }
161 _img_info | _filter_img_info
165 echo "=== Invalid sizes ==="
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.
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
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",
184 "key-secret": "keysec0",
185 "size": 18446744073709551104
188 { "execute": "x-blockdev-create",
192 "key-secret": "keysec0",
193 "size": 9223372036854775808
196 { "execute": "x-blockdev-create",
200 "key-secret": "keysec0",
201 "size": 9223372036854775296
204 { "execute": "quit" }
208 echo "=== Resize image with invalid sizes ==="
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",
217 "node-name": "node1",
218 "size": 9223372036854775296
221 { "execute": "block_resize",
223 "node-name": "node1",
224 "size": 9223372036854775808
227 { "execute": "block_resize",
229 "node-name": "node1",
230 "size": 18446744073709551104
233 { "execute": "block_resize",
235 "node-name": "node1",
236 "size": -9223372036854775808
239 { "execute": "quit" }
242 _img_info | _filter_img_info