281 (3bbe296c1c7a6ddce7a294e006b8c4a53b385292) 281 (eaf1e85d4ddefdbd197f393fa9c5acc7ba8133b0)
1#!/usr/bin/env python3
1#!/usr/bin/env python3
2# group: rw quick
2# group: rw
3#
4# Test cases for blockdev + IOThread interactions
5#
6# Copyright (C) 2019 Red Hat, Inc.
7#
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

--- 4 unchanged lines hidden (view full) ---

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
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/>.
20#
21
22import os
3#
4# Test cases for blockdev + IOThread interactions
5#
6# Copyright (C) 2019 Red Hat, Inc.
7#
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

--- 4 unchanged lines hidden (view full) ---

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
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/>.
20#
21
22import os
23import time
23import iotests
24import iotests
24from iotests import qemu_img
25from iotests import qemu_img, QemuStorageDaemon
25
26image_len = 64 * 1024 * 1024
27
28# Test for RHBZ#1782175
29class TestDirtyBitmapIOThread(iotests.QMPTestCase):
30 drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
31 images = { 'drive0': drive0_img }
32

--- 205 unchanged lines hidden (view full) ---

238 'target': 'snap1',
239 'sync': 'full' }
240 },
241 ])
242
243 # Hangs on failure, we expect this error.
244 self.assert_qmp(result, 'error/class', 'GenericError')
245
26
27image_len = 64 * 1024 * 1024
28
29# Test for RHBZ#1782175
30class TestDirtyBitmapIOThread(iotests.QMPTestCase):
31 drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
32 images = { 'drive0': drive0_img }
33

--- 205 unchanged lines hidden (view full) ---

239 'target': 'snap1',
240 'sync': 'full' }
241 },
242 ])
243
244 # Hangs on failure, we expect this error.
245 self.assert_qmp(result, 'error/class', 'GenericError')
246
247# Test for RHBZ#2033626
248class TestYieldingAndTimers(iotests.QMPTestCase):
249 sock = os.path.join(iotests.sock_dir, 'nbd.sock')
250 qsd = None
251
252 def setUp(self):
253 self.create_nbd_export()
254
255 # Simple VM with an NBD block device connected to the NBD export
256 # provided by the QSD
257 self.vm = iotests.VM()
258 self.vm.add_blockdev('nbd,node-name=nbd,server.type=unix,' +
259 f'server.path={self.sock},export=exp,' +
260 'reconnect-delay=1,open-timeout=1')
261
262 self.vm.launch()
263
264 def tearDown(self):
265 self.stop_nbd_export()
266 self.vm.shutdown()
267
268 def test_timers_with_blockdev_del(self):
269 # The NBD BDS will have had an active open timer, because setUp() gave
270 # a positive value for @open-timeout. It should be gone once the BDS
271 # has been opened.
272 # (But there used to be a bug where it remained active, which will
273 # become important below.)
274
275 # Stop and restart the NBD server, and do some I/O on the client to
276 # trigger a reconnect and start the reconnect delay timer
277 self.stop_nbd_export()
278 self.create_nbd_export()
279
280 result = self.vm.qmp('human-monitor-command',
281 command_line='qemu-io nbd "write 0 512"')
282 self.assert_qmp(result, 'return', '')
283
284 # Reconnect is done, so the reconnect delay timer should be gone.
285 # (This is similar to how the open timer should be gone after open,
286 # and similarly there used to be a bug where it was not gone.)
287
288 # Delete the BDS to see whether both timers are gone. If they are not,
289 # they will remain active, fire later, and then access freed data.
290 # (Or, with "block/nbd: Assert there are no timers when closed"
291 # applied, the assertions added in that patch will fail.)
292 result = self.vm.qmp('blockdev-del', node_name='nbd')
293 self.assert_qmp(result, 'return', {})
294
295 # Give the timers some time to fire (both have a timeout of 1 s).
296 # (Sleeping in an iotest may ring some alarm bells, but note that if
297 # the timing is off here, the test will just always pass. If we kill
298 # the VM too early, then we just kill the timers before they can fire,
299 # thus not see the error, and so the test will pass.)
300 time.sleep(2)
301
302 def create_nbd_export(self):
303 assert self.qsd is None
304
305 # Simple NBD export of a null-co BDS
306 self.qsd = QemuStorageDaemon(
307 '--blockdev',
308 'null-co,node-name=null,read-zeroes=true',
309
310 '--nbd-server',
311 f'addr.type=unix,addr.path={self.sock}',
312
313 '--export',
314 'nbd,id=exp,node-name=null,name=exp,writable=true'
315 )
316
317 def stop_nbd_export(self):
318 self.qsd.stop()
319 self.qsd = None
320
246if __name__ == '__main__':
247 iotests.main(supported_fmts=['qcow2'],
248 supported_protocols=['file'],
249 unsupported_imgopts=['compat'])
321if __name__ == '__main__':
322 iotests.main(supported_fmts=['qcow2'],
323 supported_protocols=['file'],
324 unsupported_imgopts=['compat'])