3 # Test qcow2 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))
59 { "execute": "qmp_capabilities" }
60 { "execute": "x-blockdev-create",
63 "filename": "$TEST_IMG",
67 { "execute": "blockdev-add",
70 "node-name": "imgfile",
71 "filename": "$TEST_IMG"
74 { "execute": "x-blockdev-create",
84 _img_info
--format-specific
87 echo "=== Successful image creation (inline blockdev-add, explicit defaults) ==="
90 # Choose a different size to show that we got a new image
91 size
=$
((64 * 1024 * 1024))
94 { "execute": "qmp_capabilities" }
95 { "execute": "x-blockdev-create",
98 "filename": "$TEST_IMG",
100 "preallocation": "off",
104 { "execute": "x-blockdev-create",
109 "filename": "$TEST_IMG"
113 "cluster-size": 65536,
114 "preallocation": "off",
115 "lazy-refcounts": false,
119 { "execute": "quit" }
122 _img_info
--format-specific
125 echo "=== Successful image creation (v3 non-default options) ==="
128 # Choose a different size to show that we got a new image
129 size
=$
((32 * 1024 * 1024))
132 { "execute": "qmp_capabilities" }
133 { "execute": "x-blockdev-create",
136 "filename": "$TEST_IMG",
138 "preallocation": "falloc",
142 { "execute": "x-blockdev-create",
147 "filename": "$TEST_IMG"
151 "cluster-size": 2097152,
152 "preallocation": "metadata",
153 "lazy-refcounts": true,
157 { "execute": "quit" }
160 _img_info
--format-specific
163 echo "=== Successful image creation (v2 non-default options) ==="
166 mv $TEST_IMG $TEST_IMG.base
169 { "execute": "qmp_capabilities" }
170 { "execute": "x-blockdev-create",
173 "filename": "$TEST_IMG",
177 { "execute": "x-blockdev-create",
182 "filename": "$TEST_IMG"
185 "backing-file": "$TEST_IMG.base",
186 "backing-fmt": "qcow2",
191 { "execute": "quit" }
194 _img_info
--format-specific
197 echo "=== Successful image creation (encrypted) ==="
200 run_qemu
-object secret
,id
=keysec0
,data
="foo" <<EOF
201 { "execute": "qmp_capabilities" }
202 { "execute": "x-blockdev-create",
207 "filename": "$TEST_IMG"
212 "key-secret": "keysec0",
213 "cipher-alg": "twofish-128",
214 "cipher-mode": "ctr",
215 "ivgen-alg": "plain64",
216 "ivgen-hash-alg": "md5",
222 { "execute": "quit" }
225 _img_info
--format-specific | _filter_img_info
--format-specific
228 echo "=== Invalid BlockdevRef ==="
232 { "execute": "qmp_capabilities" }
233 { "execute": "x-blockdev-create",
236 "file": "this doesn't exist",
240 { "execute": "quit" }
245 echo "=== Invalid sizes ==="
248 # TODO Negative image sizes aren't handled correctly, but this is a problem
249 # with QAPI's implementation of the 'size' type and affects other commands as
250 # well. Once this is fixed, we may want to add a test case here.
252 # 1. Misaligned image size
254 # 3. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
255 # 4. 2^63 - 512 (generally valid, but qcow2 can't handle images this size)
257 run_qemu
-blockdev driver
=file,filename
="$TEST_IMG",node-name
=node0
<<EOF
258 { "execute": "qmp_capabilities" }
259 { "execute": "x-blockdev-create",
266 { "execute": "x-blockdev-create",
270 "size": 18446744073709551104
273 { "execute": "x-blockdev-create",
277 "size": 9223372036854775808
280 { "execute": "x-blockdev-create",
284 "size": 9223372036854775296
287 { "execute": "quit" }
291 echo "=== Invalid version ==="
294 run_qemu
-blockdev driver
=file,filename
="$TEST_IMG",node-name
=node0
<<EOF
295 { "execute": "qmp_capabilities" }
296 { "execute": "x-blockdev-create",
304 { "execute": "x-blockdev-create",
310 "lazy-refcounts": true
313 { "execute": "x-blockdev-create",
322 { "execute": "quit" }
326 echo "=== Invalid backing file options ==="
329 run_qemu
-blockdev driver
=file,filename
="$TEST_IMG",node-name
=node0
<<EOF
330 { "execute": "qmp_capabilities" }
331 { "execute": "x-blockdev-create",
336 "backing-file": "/dev/null",
337 "preallocation": "full"
340 { "execute": "x-blockdev-create",
345 "backing-fmt": "$IMGFMT"
348 { "execute": "quit" }
352 echo "=== Invalid cluster size ==="
355 run_qemu
-blockdev driver
=file,filename
="$TEST_IMG",node-name
=node0
<<EOF
356 { "execute": "qmp_capabilities" }
357 { "execute": "x-blockdev-create",
365 { "execute": "x-blockdev-create",
373 { "execute": "x-blockdev-create",
378 "cluster-size": 4194304
381 { "execute": "x-blockdev-create",
389 { "execute": "x-blockdev-create",
393 "size": 281474976710656,
397 { "execute": "quit" }
401 echo "=== Invalid refcount width ==="
404 run_qemu
-blockdev driver
=file,filename
="$TEST_IMG",node-name
=node0
<<EOF
405 { "execute": "qmp_capabilities" }
406 { "execute": "x-blockdev-create",
414 { "execute": "x-blockdev-create",
422 { "execute": "x-blockdev-create",
430 { "execute": "quit" }