4 # Test cases for blockdev + IOThread interactions
6 # Copyright (C) 2019 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 from iotests import qemu_img
26 image_len = 64 * 1024 * 1024
28 # Test for RHBZ#1782175
29 class TestDirtyBitmapIOThread(iotests.QMPTestCase):
30 drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
31 images = { 'drive0': drive0_img }
34 for name in self.images:
35 qemu_img('create', '-f', iotests.imgfmt,
36 self.images[name], str(image_len))
38 self.vm = iotests.VM()
39 self.vm.add_object('iothread,id=iothread0')
41 for name in self.images:
42 self.vm.add_blockdev('driver=file,filename=%s,node-name=file_%s'
43 % (self.images[name], name))
44 self.vm.add_blockdev('driver=qcow2,file=file_%s,node-name=%s'
48 self.vm.qmp('x-blockdev-set-iothread',
49 node_name='drive0', iothread='iothread0',
54 for name in self.images:
55 os.remove(self.images[name])
57 def test_add_dirty_bitmap(self):
59 'block-dirty-bitmap-add',
65 self.assert_qmp(result, 'return', {})
68 # Test for RHBZ#1746217 & RHBZ#1773517
69 class TestNBDMirrorIOThread(iotests.QMPTestCase):
70 nbd_sock = os.path.join(iotests.sock_dir, 'nbd.sock')
71 drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
72 mirror_img = os.path.join(iotests.test_dir, 'mirror.img')
73 images = { 'drive0': drive0_img, 'mirror': mirror_img }
76 for name in self.images:
77 qemu_img('create', '-f', iotests.imgfmt,
78 self.images[name], str(image_len))
80 self.vm_src = iotests.VM(path_suffix='src')
81 self.vm_src.add_object('iothread,id=iothread0')
82 self.vm_src.add_blockdev('driver=file,filename=%s,node-name=file0'
84 self.vm_src.add_blockdev('driver=qcow2,file=file0,node-name=drive0')
86 self.vm_src.qmp('x-blockdev-set-iothread',
87 node_name='drive0', iothread='iothread0',
90 self.vm_tgt = iotests.VM(path_suffix='tgt')
91 self.vm_tgt.add_object('iothread,id=iothread0')
92 self.vm_tgt.add_blockdev('driver=file,filename=%s,node-name=file0'
94 self.vm_tgt.add_blockdev('driver=qcow2,file=file0,node-name=drive0')
96 self.vm_tgt.qmp('x-blockdev-set-iothread',
97 node_name='drive0', iothread='iothread0',
101 self.vm_src.shutdown()
102 self.vm_tgt.shutdown()
103 for name in self.images:
104 os.remove(self.images[name])
106 def test_nbd_mirror(self):
107 result = self.vm_tgt.qmp(
111 'data': { 'path': self.nbd_sock }
114 self.assert_qmp(result, 'return', {})
116 result = self.vm_tgt.qmp(
121 self.assert_qmp(result, 'return', {})
123 result = self.vm_src.qmp(
126 target='nbd+unix:///drive0?socket=' + self.nbd_sock,
132 self.assert_qmp(result, 'return', {})
134 self.vm_src.event_wait(name="BLOCK_JOB_READY")
137 # Test for RHBZ#1779036
138 class TestExternalSnapshotAbort(iotests.QMPTestCase):
139 drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
140 snapshot_img = os.path.join(iotests.test_dir, 'snapshot.img')
141 images = { 'drive0': drive0_img, 'snapshot': snapshot_img }
144 for name in self.images:
145 qemu_img('create', '-f', iotests.imgfmt,
146 self.images[name], str(image_len))
148 self.vm = iotests.VM()
149 self.vm.add_object('iothread,id=iothread0')
150 self.vm.add_blockdev('driver=file,filename=%s,node-name=file0'
152 self.vm.add_blockdev('driver=qcow2,file=file0,node-name=drive0')
154 self.vm.qmp('x-blockdev-set-iothread',
155 node_name='drive0', iothread='iothread0',
160 for name in self.images:
161 os.remove(self.images[name])
163 def test_external_snapshot_abort(self):
164 # Use a two actions transaction with a bogus values on the second
165 # one to trigger an abort of the transaction.
166 result = self.vm.qmp('transaction', actions=[
168 'type': 'blockdev-snapshot-sync',
169 'data': { 'node-name': 'drive0',
170 'snapshot-file': self.snapshot_img,
171 'snapshot-node-name': 'snap1',
172 'mode': 'absolute-paths',
176 'type': 'blockdev-snapshot-sync',
177 'data': { 'node-name': 'drive0',
178 'snapshot-file': '/fakesnapshot',
179 'snapshot-node-name': 'snap2',
180 'mode': 'absolute-paths',
185 # Crashes on failure, we expect this error.
186 self.assert_qmp(result, 'error/class', 'GenericError')
189 # Test for RHBZ#1782111
190 class TestBlockdevBackupAbort(iotests.QMPTestCase):
191 drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
192 drive1_img = os.path.join(iotests.test_dir, 'drive1.img')
193 snap0_img = os.path.join(iotests.test_dir, 'snap0.img')
194 snap1_img = os.path.join(iotests.test_dir, 'snap1.img')
195 images = { 'drive0': drive0_img,
196 'drive1': drive1_img,
201 for name in self.images:
202 qemu_img('create', '-f', iotests.imgfmt,
203 self.images[name], str(image_len))
205 self.vm = iotests.VM()
206 self.vm.add_object('iothread,id=iothread0')
207 self.vm.add_device('virtio-scsi,iothread=iothread0')
209 for name in self.images:
210 self.vm.add_blockdev('driver=file,filename=%s,node-name=file_%s'
211 % (self.images[name], name))
212 self.vm.add_blockdev('driver=qcow2,file=file_%s,node-name=%s'
215 self.vm.add_device('scsi-hd,drive=drive0')
216 self.vm.add_device('scsi-hd,drive=drive1')
221 for name in self.images:
222 os.remove(self.images[name])
224 def test_blockdev_backup_abort(self):
225 # Use a two actions transaction with a bogus values on the second
226 # one to trigger an abort of the transaction.
227 result = self.vm.qmp('transaction', actions=[
229 'type': 'blockdev-backup',
230 'data': { 'device': 'drive0',
236 'type': 'blockdev-backup',
237 'data': { 'device': 'drive1',
243 # Hangs on failure, we expect this error.
244 self.assert_qmp(result, 'error/class', 'GenericError')
246 if __name__ == '__main__':
247 iotests.main(supported_fmts=['qcow2'],
248 supported_protocols=['file'])