Merge remote-tracking branch 'remotes/nvme/tags/nvme-fixes-20210407-pull-request...
[qemu/ar7.git] / tests / qemu-iotests / 237
blob43dfd3bd40a4ad2495cea2778c8ab472ce1566bd
1 #!/usr/bin/env python3
2 # group: rw quick
4 # Test vmdk 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/>.
24 import math
25 import iotests
26 from iotests import imgfmt
28 iotests.script_initialize(supported_fmts=['vmdk'])
30 with iotests.FilePath('t.vmdk') as disk_path, \
31      iotests.FilePath('t.vmdk.1') as extent1_path, \
32      iotests.FilePath('t.vmdk.2') as extent2_path, \
33      iotests.FilePath('t.vmdk.3') as extent3_path, \
34      iotests.VM() as vm:
36     #
37     # Successful image creation (defaults)
38     #
39     iotests.log("=== Successful image creation (defaults) ===")
40     iotests.log("")
42     size = 5 * 1024 * 1024 * 1024
44     vm.launch()
45     vm.blockdev_create({ 'driver': 'file',
46                          'filename': disk_path,
47                          'size': 0 })
49     vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
50                node_name='imgfile', filters=[iotests.filter_qmp_testfiles])
52     vm.blockdev_create({ 'driver': imgfmt,
53                          'file': 'imgfile',
54                          'size': size })
55     vm.shutdown()
57     iotests.img_info_log(disk_path)
59     #
60     # Successful image creation (inline blockdev-add, explicit defaults)
61     #
62     iotests.log("=== Successful image creation (inline blockdev-add, explicit defaults) ===")
63     iotests.log("")
65     # Choose a different size to show that we got a new image
66     size = 64 * 1024 * 1024
68     vm.launch()
69     vm.blockdev_create({ 'driver': 'file',
70                          'filename': disk_path,
71                          'size': 0 })
73     vm.blockdev_create({ 'driver': imgfmt,
74                          'file': {
75                              'driver': 'file',
76                              'filename': disk_path,
77                          },
78                          'size': size,
79                          'extents': [],
80                          'subformat': 'monolithicSparse',
81                          'adapter-type': 'ide',
82                          'hwversion': '4',
83                          'zeroed-grain': False })
84     vm.shutdown()
86     iotests.img_info_log(disk_path)
88     #
89     # Successful image creation (non-default options)
90     #
91     iotests.log("=== Successful image creation (with non-default options) ===")
92     iotests.log("")
94     # Choose a different size to show that we got a new image
95     size = 32 * 1024 * 1024
97     vm.launch()
98     vm.blockdev_create({ 'driver': 'file',
99                          'filename': disk_path,
100                          'size': 0 })
102     vm.blockdev_create({ 'driver': imgfmt,
103                          'file': {
104                              'driver': 'file',
105                              'filename': disk_path,
106                          },
107                          'size': size,
108                          'extents': [],
109                          'subformat': 'monolithicSparse',
110                          'adapter-type': 'buslogic',
111                          'zeroed-grain': True })
112     vm.shutdown()
114     iotests.img_info_log(disk_path)
116     #
117     # Invalid BlockdevRef
118     #
119     iotests.log("=== Invalid BlockdevRef ===")
120     iotests.log("")
122     vm.launch()
123     vm.blockdev_create({ 'driver': imgfmt,
124                          'file': "this doesn't exist",
125                          'size': size })
126     vm.shutdown()
128     #
129     # Adapter types
130     #
132     iotests.log("=== Adapter types ===")
133     iotests.log("")
135     vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
137     # Valid
138     iotests.log("== Valid adapter types ==")
139     iotests.log("")
141     vm.launch()
142     for adapter_type in [ 'ide', 'buslogic', 'lsilogic', 'legacyESX' ]:
143         vm.blockdev_create({ 'driver': imgfmt,
144                              'file': 'node0',
145                              'size': size,
146                              'adapter-type': adapter_type })
147     vm.shutdown()
149     # Invalid
150     iotests.log("== Invalid adapter types ==")
151     iotests.log("")
153     vm.launch()
154     for adapter_type in [ 'foo', 'IDE', 'legacyesx', 1 ]:
155         vm.blockdev_create({ 'driver': imgfmt,
156                              'file': 'node0',
157                              'size': size,
158                              'adapter-type': adapter_type })
159     vm.shutdown()
161     #
162     # Other subformats
163     #
164     iotests.log("=== Other subformats ===")
165     iotests.log("")
167     for path in [ extent1_path, extent2_path, extent3_path ]:
168         msg = iotests.qemu_img_pipe('create', '-f', imgfmt, path, '0')
169         iotests.log(msg, [iotests.filter_testfiles])
171     vm.add_blockdev('driver=file,filename=%s,node-name=ext1' % (extent1_path))
172     vm.add_blockdev('driver=file,filename=%s,node-name=ext2' % (extent2_path))
173     vm.add_blockdev('driver=file,filename=%s,node-name=ext3' % (extent3_path))
175     # Missing extent
176     iotests.log("== Missing extent ==")
177     iotests.log("")
179     vm.launch()
180     vm.blockdev_create({ 'driver': imgfmt,
181                          'file': 'node0',
182                          'size': size,
183                          'subformat': 'monolithicFlat' })
184     vm.shutdown()
186     # Correct extent
187     iotests.log("== Correct extent ==")
188     iotests.log("")
190     vm.launch()
191     vm.blockdev_create({ 'driver': imgfmt,
192                          'file': 'node0',
193                          'size': size,
194                          'subformat': 'monolithicFlat',
195                          'extents': ['ext1'] })
196     vm.shutdown()
198     # Extra extent
199     iotests.log("== Extra extent ==")
200     iotests.log("")
202     vm.launch()
203     vm.blockdev_create({ 'driver': imgfmt,
204                          'file': 'node0',
205                          'size': 512,
206                          'subformat': 'monolithicFlat',
207                          'extents': ['ext1', 'ext2', 'ext3'] })
208     vm.shutdown()
210     # Split formats
211     iotests.log("== Split formats ==")
212     iotests.log("")
214     for size in [ 512, 1073741824, 2147483648, 5368709120 ]:
215         for subfmt in [ 'twoGbMaxExtentFlat', 'twoGbMaxExtentSparse' ]:
216             iotests.log("= %s %d =" % (subfmt, size))
217             iotests.log("")
219             num_extents = int(math.ceil(size / 2.0**31))
220             extents = [ "ext%d" % (i) for i in range(1, num_extents + 1) ]
222             vm.launch()
223             vm.blockdev_create({ 'driver': imgfmt,
224                                  'file': 'node0',
225                                  'size': size,
226                                  'subformat': subfmt,
227                                  'extents': extents })
228             vm.shutdown()
230             iotests.img_info_log(disk_path)