4 # Test qcow2 and file image creation
6 # Copyright (C) 2018 Red Hat, Inc.
8 # Creator/Owner: Kevin Wolf <kwolf@redhat.com>
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 from iotests import imgfmt
27 iotests.script_initialize(supported_fmts=['qcow2'],
28 supported_protocols=['file'])
29 iotests.verify_working_luks()
31 with iotests.FilePath('t.qcow2') as disk_path, \
32 iotests.FilePath('t.qcow2.base') as backing_path, \
35 vm.add_object('secret,id=keysec0,data=foo')
38 # Successful image creation (defaults)
40 iotests.log("=== Successful image creation (defaults) ===")
43 size = 128 * 1024 * 1024
46 vm.blockdev_create({ 'driver': 'file',
47 'filename': disk_path,
50 vm.qmp_log('blockdev-add',
51 filters=[iotests.filter_qmp_testfiles],
52 driver='file', filename=disk_path,
55 vm.blockdev_create({ 'driver': imgfmt,
60 iotests.img_info_log(disk_path)
63 # Successful image creation (inline blockdev-add, explicit defaults)
65 iotests.log("=== Successful image creation (inline blockdev-add, explicit defaults) ===")
68 # Choose a different size to show that we got a new image
69 size = 64 * 1024 * 1024
72 vm.blockdev_create({ 'driver': 'file',
73 'filename': disk_path,
75 'preallocation': 'off',
78 vm.blockdev_create({ 'driver': imgfmt,
81 'filename': disk_path,
85 'cluster-size': 65536,
86 'preallocation': 'off',
87 'lazy-refcounts': False,
88 'refcount-bits': 16 })
91 iotests.img_info_log(disk_path)
94 # Successful image creation (v3 non-default options)
96 iotests.log("=== Successful image creation (v3 non-default options) ===")
99 # Choose a different size to show that we got a new image
100 size = 32 * 1024 * 1024
103 vm.blockdev_create({ 'driver': 'file',
104 'filename': disk_path,
106 'preallocation': 'falloc',
109 vm.blockdev_create({ 'driver': imgfmt,
112 'filename': disk_path,
116 'cluster-size': 2097152,
117 'preallocation': 'metadata',
118 'lazy-refcounts': True,
119 'refcount-bits': 1 })
122 iotests.img_info_log(disk_path)
125 # Successful image creation (v2 non-default options)
127 iotests.log("=== Successful image creation (v2 non-default options) ===")
131 vm.blockdev_create({ 'driver': 'file',
132 'filename': disk_path,
135 vm.blockdev_create({ 'driver': imgfmt,
138 'filename': disk_path,
141 'backing-file': backing_path,
142 'backing-fmt': 'qcow2',
144 'cluster-size': 512 })
147 iotests.img_info_log(disk_path)
150 # Successful image creation (encrypted)
152 iotests.log("=== Successful image creation (encrypted) ===")
156 vm.blockdev_create({ 'driver': imgfmt,
159 'filename': disk_path,
164 'key-secret': 'keysec0',
165 'cipher-alg': 'aes-128',
166 'cipher-mode': 'cbc',
167 'ivgen-alg': 'plain64',
168 'ivgen-hash-alg': 'md5',
174 iotests.img_info_log(disk_path)
177 # Invalid BlockdevRef
179 iotests.log("=== Invalid BlockdevRef ===")
183 vm.blockdev_create({ 'driver': imgfmt,
184 'file': "this doesn't exist",
191 iotests.log("=== Invalid sizes ===")
193 # TODO Negative image sizes aren't handled correctly, but this is a problem
194 # with QAPI's implementation of the 'size' type and affects other commands
195 # as well. Once this is fixed, we may want to add a test case here.
197 # 1. Misaligned image size
199 # 3. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
200 # 4. 2^63 - 512 (generally valid, but qcow2 can't handle images this size)
202 vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
205 for size in [ 1234, 18446744073709551104, 9223372036854775808,
206 9223372036854775296, 9223372035781033984 ]:
207 vm.blockdev_create({ 'driver': imgfmt,
215 iotests.log("=== Invalid version ===")
218 vm.blockdev_create({ 'driver': imgfmt,
222 vm.blockdev_create({ 'driver': imgfmt,
226 'lazy-refcounts': True })
227 vm.blockdev_create({ 'driver': imgfmt,
231 'refcount-bits': 8 })
235 # Invalid backing file options
237 iotests.log("=== Invalid backing file options ===")
240 vm.blockdev_create({ 'driver': imgfmt,
243 'backing-file': '/dev/null',
244 'preallocation': 'full' })
245 vm.blockdev_create({ 'driver': imgfmt,
248 'backing-fmt': imgfmt })
252 # Invalid cluster size
254 iotests.log("=== Invalid cluster size ===")
257 for csize in [ 1234, 128, 4194304, 0 ]:
258 vm.blockdev_create({ 'driver': imgfmt,
261 'cluster-size': csize })
262 vm.blockdev_create({ 'driver': imgfmt,
264 'size': 281474976710656,
265 'cluster-size': 512 })
269 # Invalid refcount width
271 iotests.log("=== Invalid refcount width ===")
274 for refcount_bits in [ 128, 0, 7 ]:
275 vm.blockdev_create({ 'driver': imgfmt,
278 'refcount-bits': refcount_bits })