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
.verify_image_format(supported_fmts
=['qcow2'])
28 with iotests
.FilePath('t.qcow2') as disk_path
, \
29 iotests
.FilePath('t.qcow2.base') as backing_path
, \
32 vm
.add_object('secret,id=keysec0,data=foo')
35 # Successful image creation (defaults)
37 iotests
.log("=== Successful image creation (defaults) ===")
40 size
= 128 * 1024 * 1024
43 vm
.blockdev_create({ 'driver': 'file',
44 'filename': disk_path
,
47 vm
.qmp_log('blockdev-add',
48 filters
=[iotests
.filter_qmp_testfiles
],
49 driver
='file', filename
=disk_path
,
52 vm
.blockdev_create({ 'driver': imgfmt
,
57 iotests
.img_info_log(disk_path
)
60 # Successful image creation (inline blockdev-add, explicit defaults)
62 iotests
.log("=== Successful image creation (inline blockdev-add, explicit defaults) ===")
65 # Choose a different size to show that we got a new image
66 size
= 64 * 1024 * 1024
69 vm
.blockdev_create({ 'driver': 'file',
70 'filename': disk_path
,
72 'preallocation': 'off',
75 vm
.blockdev_create({ 'driver': imgfmt
,
78 'filename': disk_path
,
82 'cluster-size': 65536,
83 'preallocation': 'off',
84 'lazy-refcounts': False,
85 'refcount-bits': 16 })
88 iotests
.img_info_log(disk_path
)
91 # Successful image creation (v3 non-default options)
93 iotests
.log("=== Successful image creation (v3 non-default options) ===")
96 # Choose a different size to show that we got a new image
97 size
= 32 * 1024 * 1024
100 vm
.blockdev_create({ 'driver': 'file',
101 'filename': disk_path
,
103 'preallocation': 'falloc',
106 vm
.blockdev_create({ 'driver': imgfmt
,
109 'filename': disk_path
,
113 'cluster-size': 2097152,
114 'preallocation': 'metadata',
115 'lazy-refcounts': True,
116 'refcount-bits': 1 })
119 iotests
.img_info_log(disk_path
)
122 # Successful image creation (v2 non-default options)
124 iotests
.log("=== Successful image creation (v2 non-default options) ===")
128 vm
.blockdev_create({ 'driver': 'file',
129 'filename': disk_path
,
132 vm
.blockdev_create({ 'driver': imgfmt
,
135 'filename': disk_path
,
138 'backing-file': backing_path
,
139 'backing-fmt': 'qcow2',
141 'cluster-size': 512 })
144 iotests
.img_info_log(disk_path
)
147 # Successful image creation (encrypted)
149 iotests
.log("=== Successful image creation (encrypted) ===")
153 vm
.blockdev_create({ 'driver': imgfmt
,
156 'filename': disk_path
,
161 'key-secret': 'keysec0',
162 'cipher-alg': 'twofish-128',
163 'cipher-mode': 'ctr',
164 'ivgen-alg': 'plain64',
165 'ivgen-hash-alg': 'md5',
171 iotests
.img_info_log(disk_path
)
174 # Invalid BlockdevRef
176 iotests
.log("=== Invalid BlockdevRef ===")
180 vm
.blockdev_create({ 'driver': imgfmt
,
181 'file': "this doesn't exist",
188 iotests
.log("=== Invalid sizes ===")
190 # TODO Negative image sizes aren't handled correctly, but this is a problem
191 # with QAPI's implementation of the 'size' type and affects other commands
192 # as well. Once this is fixed, we may want to add a test case here.
194 # 1. Misaligned image size
196 # 3. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
197 # 4. 2^63 - 512 (generally valid, but qcow2 can't handle images this size)
199 vm
.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path
))
202 for size
in [ 1234, 18446744073709551104, 9223372036854775808,
203 9223372036854775296 ]:
204 vm
.blockdev_create({ 'driver': imgfmt
,
212 iotests
.log("=== Invalid version ===")
215 vm
.blockdev_create({ 'driver': imgfmt
,
219 vm
.blockdev_create({ 'driver': imgfmt
,
223 'lazy-refcounts': True })
224 vm
.blockdev_create({ 'driver': imgfmt
,
228 'refcount-bits': 8 })
232 # Invalid backing file options
234 iotests
.log("=== Invalid backing file options ===")
237 vm
.blockdev_create({ 'driver': imgfmt
,
240 'backing-file': '/dev/null',
241 'preallocation': 'full' })
242 vm
.blockdev_create({ 'driver': imgfmt
,
245 'backing-fmt': imgfmt
})
249 # Invalid cluster size
251 iotests
.log("=== Invalid cluster size ===")
254 for csize
in [ 1234, 128, 4194304, 0 ]:
255 vm
.blockdev_create({ 'driver': imgfmt
,
258 'cluster-size': csize
})
259 vm
.blockdev_create({ 'driver': imgfmt
,
261 'size': 281474976710656,
262 'cluster-size': 512 })
266 # Invalid refcount width
268 iotests
.log("=== Invalid refcount width ===")
271 for refcount_bits
in [ 128, 0, 7 ]:
272 vm
.blockdev_create({ 'driver': imgfmt
,
275 'refcount-bits': refcount_bits
})