3 # Test cases for blockdev + IOThread interactions
5 # Copyright (C) 2019 Red Hat, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 from iotests import qemu_img
25 image_len = 64 * 1024 * 1024
27 # Test for RHBZ#1782175
28 class TestDirtyBitmapIOThread(iotests.QMPTestCase):
29 drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
30 images = { 'drive0': drive0_img }
33 for name in self.images:
34 qemu_img('create', '-f', iotests.imgfmt,
35 self.images[name], str(image_len))
37 self.vm = iotests.VM()
38 self.vm.add_object('iothread,id=iothread0')
40 for name in self.images:
41 self.vm.add_blockdev('driver=file,filename=%s,node-name=file_%s'
42 % (self.images[name], name))
43 self.vm.add_blockdev('driver=qcow2,file=file_%s,node-name=%s'
47 self.vm.qmp('x-blockdev-set-iothread',
48 node_name='drive0', iothread='iothread0',
53 for name in self.images:
54 os.remove(self.images[name])
56 def test_add_dirty_bitmap(self):
58 'block-dirty-bitmap-add',
64 self.assert_qmp(result, 'return', {})
67 # Test for RHBZ#1746217 & RHBZ#1773517
68 class TestNBDMirrorIOThread(iotests.QMPTestCase):
69 nbd_sock = os.path.join(iotests.sock_dir, 'nbd.sock')
70 drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
71 mirror_img = os.path.join(iotests.test_dir, 'mirror.img')
72 images = { 'drive0': drive0_img, 'mirror': mirror_img }
75 for name in self.images:
76 qemu_img('create', '-f', iotests.imgfmt,
77 self.images[name], str(image_len))
79 self.vm_src = iotests.VM(path_suffix='src')
80 self.vm_src.add_object('iothread,id=iothread0')
81 self.vm_src.add_blockdev('driver=file,filename=%s,node-name=file0'
83 self.vm_src.add_blockdev('driver=qcow2,file=file0,node-name=drive0')
85 self.vm_src.qmp('x-blockdev-set-iothread',
86 node_name='drive0', iothread='iothread0',
89 self.vm_tgt = iotests.VM(path_suffix='tgt')
90 self.vm_tgt.add_object('iothread,id=iothread0')
91 self.vm_tgt.add_blockdev('driver=file,filename=%s,node-name=file0'
93 self.vm_tgt.add_blockdev('driver=qcow2,file=file0,node-name=drive0')
95 self.vm_tgt.qmp('x-blockdev-set-iothread',
96 node_name='drive0', iothread='iothread0',
100 self.vm_src.shutdown()
101 self.vm_tgt.shutdown()
102 for name in self.images:
103 os.remove(self.images[name])
105 def test_nbd_mirror(self):
106 result = self.vm_tgt.qmp(
110 'data': { 'path': self.nbd_sock }
113 self.assert_qmp(result, 'return', {})
115 result = self.vm_tgt.qmp(
120 self.assert_qmp(result, 'return', {})
122 result = self.vm_src.qmp(
125 target='nbd+unix:///drive0?socket=' + self.nbd_sock,
131 self.assert_qmp(result, 'return', {})
133 self.vm_src.event_wait(name="BLOCK_JOB_READY")
136 # Test for RHBZ#1779036
137 class TestExternalSnapshotAbort(iotests.QMPTestCase):
138 drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
139 snapshot_img = os.path.join(iotests.test_dir, 'snapshot.img')
140 images = { 'drive0': drive0_img, 'snapshot': snapshot_img }
143 for name in self.images:
144 qemu_img('create', '-f', iotests.imgfmt,
145 self.images[name], str(image_len))
147 self.vm = iotests.VM()
148 self.vm.add_object('iothread,id=iothread0')
149 self.vm.add_blockdev('driver=file,filename=%s,node-name=file0'
151 self.vm.add_blockdev('driver=qcow2,file=file0,node-name=drive0')
153 self.vm.qmp('x-blockdev-set-iothread',
154 node_name='drive0', iothread='iothread0',
159 for name in self.images:
160 os.remove(self.images[name])
162 def test_external_snapshot_abort(self):
163 # Use a two actions transaction with a bogus values on the second
164 # one to trigger an abort of the transaction.
165 result = self.vm.qmp('transaction', actions=[
167 'type': 'blockdev-snapshot-sync',
168 'data': { 'node-name': 'drive0',
169 'snapshot-file': self.snapshot_img,
170 'snapshot-node-name': 'snap1',
171 'mode': 'absolute-paths',
175 'type': 'blockdev-snapshot-sync',
176 'data': { 'node-name': 'drive0',
177 'snapshot-file': '/fakesnapshot',
178 'snapshot-node-name': 'snap2',
179 'mode': 'absolute-paths',
184 # Crashes on failure, we expect this error.
185 self.assert_qmp(result, 'error/class', 'GenericError')
188 # Test for RHBZ#1782111
189 class TestBlockdevBackupAbort(iotests.QMPTestCase):
190 drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
191 drive1_img = os.path.join(iotests.test_dir, 'drive1.img')
192 snap0_img = os.path.join(iotests.test_dir, 'snap0.img')
193 snap1_img = os.path.join(iotests.test_dir, 'snap1.img')
194 images = { 'drive0': drive0_img,
195 'drive1': drive1_img,
200 for name in self.images:
201 qemu_img('create', '-f', iotests.imgfmt,
202 self.images[name], str(image_len))
204 self.vm = iotests.VM()
205 self.vm.add_object('iothread,id=iothread0')
206 self.vm.add_device('virtio-scsi,iothread=iothread0')
208 for name in self.images:
209 self.vm.add_blockdev('driver=file,filename=%s,node-name=file_%s'
210 % (self.images[name], name))
211 self.vm.add_blockdev('driver=qcow2,file=file_%s,node-name=%s'
214 self.vm.add_device('scsi-hd,drive=drive0')
215 self.vm.add_device('scsi-hd,drive=drive1')
220 for name in self.images:
221 os.remove(self.images[name])
223 def test_blockdev_backup_abort(self):
224 # Use a two actions transaction with a bogus values on the second
225 # one to trigger an abort of the transaction.
226 result = self.vm.qmp('transaction', actions=[
228 'type': 'blockdev-backup',
229 'data': { 'device': 'drive0',
235 'type': 'blockdev-backup',
236 'data': { 'device': 'drive1',
242 # Hangs on failure, we expect this error.
243 self.assert_qmp(result, 'error/class', 'GenericError')
245 if __name__ == '__main__':
246 iotests.main(supported_fmts=['qcow2'],
247 supported_protocols=['file'])