]>
git.proxmox.com Git - mirror_qemu.git/blob - tests/qemu-iotests/tests/stream-error-on-reset
4 # Test what happens when a stream job completes in a blk_drain().
6 # Copyright (C) 2022 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 imgfmt
, qemu_img_create
, qemu_io_silent
, QMPTestCase
27 image_size
= 1 * 1024 * 1024
29 base
= os
.path
.join(iotests
.test_dir
, 'base.img')
30 top
= os
.path
.join(iotests
.test_dir
, 'top.img')
33 # We want to test completing a stream job in a blk_drain().
35 # The blk_drain() we are going to use is a virtio-scsi device resetting,
36 # which we can trigger by resetting the system.
38 # In order to have the block job complete on drain, we (1) throttle its
39 # base image so we can start the drain after it has begun, but before it
40 # completes, and (2) make it encounter an I/O error on the ensuing write.
41 # (If it completes regularly, the completion happens after the drain for
44 class TestStreamErrorOnReset(QMPTestCase
):
45 def setUp(self
) -> None:
48 - base image {base} with {data_size} bytes allocated
49 - top image {top} without any data allocated
51 And the following VM configuration:
52 - base image throttled to {data_size}
53 - top image with a blkdebug configuration so the first write access
54 to it will result in an error
55 - top image is attached to a virtio-scsi device
57 qemu_img_create('-f', imgfmt
, base
, str(image_size
))
58 assert qemu_io_silent('-c', f
'write 0 {data_size}', base
) == 0
59 qemu_img_create('-f', imgfmt
, top
, str(image_size
))
61 self
.vm
= iotests
.VM()
62 self
.vm
.add_args('-accel', 'tcg') # Make throttling work properly
63 self
.vm
.add_object(self
.vm
.qmp_to_opts({
64 'qom-type': 'throttle-group',
66 'x-bps-total': str(data_size
)
68 self
.vm
.add_blockdev(self
.vm
.qmp_to_opts({
73 'throttle-group': 'thrgr',
80 self
.vm
.add_blockdev(self
.vm
.qmp_to_opts({
85 'node-name': 'top-blkdebug',
88 'immediately': 'true',
98 self
.vm
.add_device(self
.vm
.qmp_to_opts({
99 'driver': 'virtio-scsi',
102 self
.vm
.add_device(self
.vm
.qmp_to_opts({
109 def tearDown(self
) -> None:
114 def test_stream_error_on_reset(self
) -> None:
115 # Launch a stream job, which will take at least a second to
116 # complete, because the base image is throttled (so we can
117 # get in between it having started and it having completed)
118 res
= self
.vm
.qmp('block-stream', job_id
='stream', device
='top')
119 self
.assert_qmp(res
, 'return', {})
122 ev
= self
.vm
.event_wait('JOB_STATUS_CHANGE')
123 if ev
['data']['status'] == 'running':
124 # Once the stream job is running, reset the system, which
125 # forces the virtio-scsi device to be reset, thus draining
126 # the stream job, and making it complete. Completing
127 # inside of that drain should not result in a segfault.
128 res
= self
.vm
.qmp('system_reset')
129 self
.assert_qmp(res
, 'return', {})
130 elif ev
['data']['status'] == 'null':
131 # The test is done once the job is gone
135 if __name__
== '__main__':
136 # Passes with any format with backing file support, but qed and
137 # qcow1 do not seem to exercise the used-to-be problematic code
138 # path, so there is no point in having them in this list
139 iotests
.main(supported_fmts
=['qcow2', 'vmdk'],
140 supported_protocols
=['file'])