3 # Test qcow2 and file image creation
5 # Copyright (C) 2018 Red Hat, Inc.
7 # Creator/Owner: Kevin Wolf <kwolf@redhat.com>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 from iotests import imgfmt
26 iotests.script_initialize(supported_fmts=['qcow2'],
27 supported_protocols=['file'])
28 iotests.verify_working_luks()
30 with iotests.FilePath('t.qcow2') as disk_path, \
31 iotests.FilePath('t.qcow2.base') as backing_path, \
34 vm.add_object('secret,id=keysec0,data=foo')
37 # Successful image creation (defaults)
39 iotests.log("=== Successful image creation (defaults) ===")
42 size = 128 * 1024 * 1024
45 vm.blockdev_create({ 'driver': 'file',
46 'filename': disk_path,
49 vm.qmp_log('blockdev-add',
50 filters=[iotests.filter_qmp_testfiles],
51 driver='file', filename=disk_path,
54 vm.blockdev_create({ 'driver': imgfmt,
59 iotests.img_info_log(disk_path)
62 # Successful image creation (inline blockdev-add, explicit defaults)
64 iotests.log("=== Successful image creation (inline blockdev-add, explicit defaults) ===")
67 # Choose a different size to show that we got a new image
68 size = 64 * 1024 * 1024
71 vm.blockdev_create({ 'driver': 'file',
72 'filename': disk_path,
74 'preallocation': 'off',
77 vm.blockdev_create({ 'driver': imgfmt,
80 'filename': disk_path,
84 'cluster-size': 65536,
85 'preallocation': 'off',
86 'lazy-refcounts': False,
87 'refcount-bits': 16 })
90 iotests.img_info_log(disk_path)
93 # Successful image creation (v3 non-default options)
95 iotests.log("=== Successful image creation (v3 non-default options) ===")
98 # Choose a different size to show that we got a new image
99 size = 32 * 1024 * 1024
102 vm.blockdev_create({ 'driver': 'file',
103 'filename': disk_path,
105 'preallocation': 'falloc',
108 vm.blockdev_create({ 'driver': imgfmt,
111 'filename': disk_path,
115 'cluster-size': 2097152,
116 'preallocation': 'metadata',
117 'lazy-refcounts': True,
118 'refcount-bits': 1 })
121 iotests.img_info_log(disk_path)
124 # Successful image creation (v2 non-default options)
126 iotests.log("=== Successful image creation (v2 non-default options) ===")
130 vm.blockdev_create({ 'driver': 'file',
131 'filename': disk_path,
134 vm.blockdev_create({ 'driver': imgfmt,
137 'filename': disk_path,
140 'backing-file': backing_path,
141 'backing-fmt': 'qcow2',
143 'cluster-size': 512 })
146 iotests.img_info_log(disk_path)
149 # Successful image creation (encrypted)
151 iotests.log("=== Successful image creation (encrypted) ===")
155 vm.blockdev_create({ 'driver': imgfmt,
158 'filename': disk_path,
163 'key-secret': 'keysec0',
164 'cipher-alg': 'twofish-128',
165 'cipher-mode': 'ctr',
166 'ivgen-alg': 'plain64',
167 'ivgen-hash-alg': 'md5',
173 iotests.img_info_log(disk_path)
176 # Invalid BlockdevRef
178 iotests.log("=== Invalid BlockdevRef ===")
182 vm.blockdev_create({ 'driver': imgfmt,
183 'file': "this doesn't exist",
190 iotests.log("=== Invalid sizes ===")
192 # TODO Negative image sizes aren't handled correctly, but this is a problem
193 # with QAPI's implementation of the 'size' type and affects other commands
194 # as well. Once this is fixed, we may want to add a test case here.
196 # 1. Misaligned image size
198 # 3. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
199 # 4. 2^63 - 512 (generally valid, but qcow2 can't handle images this size)
201 vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
204 for size in [ 1234, 18446744073709551104, 9223372036854775808,
205 9223372036854775296, 9223372035781033984 ]:
206 vm.blockdev_create({ 'driver': imgfmt,
214 iotests.log("=== Invalid version ===")
217 vm.blockdev_create({ 'driver': imgfmt,
221 vm.blockdev_create({ 'driver': imgfmt,
225 'lazy-refcounts': True })
226 vm.blockdev_create({ 'driver': imgfmt,
230 'refcount-bits': 8 })
234 # Invalid backing file options
236 iotests.log("=== Invalid backing file options ===")
239 vm.blockdev_create({ 'driver': imgfmt,
242 'backing-file': '/dev/null',
243 'preallocation': 'full' })
244 vm.blockdev_create({ 'driver': imgfmt,
247 'backing-fmt': imgfmt })
251 # Invalid cluster size
253 iotests.log("=== Invalid cluster size ===")
256 for csize in [ 1234, 128, 4194304, 0 ]:
257 vm.blockdev_create({ 'driver': imgfmt,
260 'cluster-size': csize })
261 vm.blockdev_create({ 'driver': imgfmt,
263 'size': 281474976710656,
264 'cluster-size': 512 })
268 # Invalid refcount width
270 iotests.log("=== Invalid refcount width ===")
273 for refcount_bits in [ 128, 0, 7 ]:
274 vm.blockdev_create({ 'driver': imgfmt,
277 'refcount-bits': refcount_bits })