3 # Test hot plugging and unplugging with iothreads
5 # Copyright (C) 2019 Igalia, S.L.
6 # Author: Alberto Garcia <berto@igalia.com>
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 nbd_sock = iotests.file_path('nbd.sock', base_dir=iotests.sock_dir)
26 class TestCase(iotests.QMPTestCase):
27 test_driver = "null-co"
29 def required_drivers(self):
30 return [self.test_driver]
32 @iotests.skip_if_unsupported(required_drivers)
34 self.vm = iotests.VM()
41 iotests.log('==Unplug a SCSI disk and then plug it again==')
42 self.vm.qmp_log('blockdev-add', driver='null-co', read_zeroes=True, node_name='hd0')
43 self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
44 self.vm.qmp_log('device_add', id='scsi0', driver=iotests.get_virtio_scsi_device(), iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
45 self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')
46 self.vm.qmp_log('device_del', id='scsi-hd0')
47 self.vm.event_wait('DEVICE_DELETED')
48 self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')
49 self.vm.qmp_log('device_del', id='scsi-hd0')
50 self.vm.event_wait('DEVICE_DELETED')
51 self.vm.qmp_log('blockdev-del', node_name='hd0')
54 iotests.log('==Attach two SCSI disks using the same block device and the same iothread==')
55 self.vm.qmp_log('blockdev-add', driver='null-co', read_zeroes=True, node_name='hd0', read_only=True)
56 self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
57 self.vm.qmp_log('device_add', id='scsi0', driver=iotests.get_virtio_scsi_device(), iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
59 self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')
60 self.vm.qmp_log('device_add', id='scsi-hd1', driver='scsi-hd', drive='hd0')
61 self.vm.qmp_log('device_del', id='scsi-hd0')
62 self.vm.event_wait('DEVICE_DELETED')
63 self.vm.qmp_log('device_del', id='scsi-hd1')
64 self.vm.event_wait('DEVICE_DELETED')
65 self.vm.qmp_log('blockdev-del', node_name='hd0')
68 iotests.log('==Attach two SCSI disks using the same block device but different iothreads==')
70 self.vm.qmp_log('blockdev-add', driver='null-co', read_zeroes=True, node_name='hd0', read_only=True)
72 self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
73 self.vm.qmp_log('object-add', qom_type='iothread', id="iothread1")
75 self.vm.qmp_log('device_add', id='scsi0', driver=iotests.get_virtio_scsi_device(), iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
76 self.vm.qmp_log('device_add', id='scsi1', driver=iotests.get_virtio_scsi_device(), iothread='iothread1', filters=[iotests.filter_qmp_virtio_scsi])
78 self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0', bus="scsi0.0")
79 self.vm.qmp_log('device_add', id='scsi-hd1', driver='scsi-hd', drive='hd0', bus="scsi1.0")
81 self.vm.qmp_log('device_del', id='scsi-hd0')
82 self.vm.event_wait('DEVICE_DELETED')
83 self.vm.qmp_log('device_add', id='scsi-hd1', driver='scsi-hd', drive='hd0', bus="scsi1.0")
85 self.vm.qmp_log('device_del', id='scsi-hd1')
86 self.vm.event_wait('DEVICE_DELETED')
87 self.vm.qmp_log('blockdev-del', node_name='hd0')
90 iotests.log('==Attach a SCSI disks using the same block device as a NBD server==')
92 self.vm.qmp_log('blockdev-add', driver='null-co', read_zeroes=True, node_name='hd0', read_only=True)
94 self.vm.qmp_log('nbd-server-start',
95 filters=[iotests.filter_qmp_testfiles],
96 addr={'type':'unix', 'data':{'path':nbd_sock}})
98 self.vm.qmp_log('nbd-server-add', device='hd0')
100 self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
101 self.vm.qmp_log('device_add', id='scsi0', driver=iotests.get_virtio_scsi_device(), iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
102 self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')
104 if __name__ == '__main__':
105 iotests.activate_logging()