2021-10-06 17:19:40 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# group: rw quick
|
|
|
|
#
|
|
|
|
# Test what happens when errors occur to a mirror job after it has
|
|
|
|
# been cancelled in the READY phase
|
|
|
|
#
|
|
|
|
# Copyright (C) 2021 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
|
|
|
import iotests
|
|
|
|
|
|
|
|
|
|
|
|
image_size = 1 * 1024 * 1024
|
|
|
|
source = os.path.join(iotests.test_dir, 'source.img')
|
|
|
|
target = os.path.join(iotests.test_dir, 'target.img')
|
|
|
|
|
|
|
|
|
|
|
|
class TestMirrorReadyCancelError(iotests.QMPTestCase):
|
|
|
|
def setUp(self) -> None:
|
2022-03-21 21:16:03 +01:00
|
|
|
iotests.qemu_img_create('-f', iotests.imgfmt, source, str(image_size))
|
|
|
|
iotests.qemu_img_create('-f', iotests.imgfmt, target, str(image_size))
|
2021-10-06 17:19:40 +02:00
|
|
|
|
iotests/MRCE: Write data to source
This test assumes that mirror flushes the source when entering the READY
state, and that the format level will pass that flush on to the protocol
level (where we intercept it with blkdebug).
However, apparently that does not happen when using a VMDK image with
zeroed_grain=on, which actually is the default set by testenv.py. Right
now, Python tests ignore IMGOPTS, though, so this has no effect; but
Vladimir has a series that will change this, so we need to fix this test
before that series lands.
We can fix it by writing data to the source before we start the mirror
job; apparently that makes the (VMDK) format layer change its mind and
pass on the pre-READY flush to the protocol level, so the test passes
again. (I presume, without any data written, mirror just does a 64M
zero write on the target, which VMDK with zeroed_grain=on basically just
ignores.)
Without this, we do not get a flush, and so blkdebug only sees a single
flush at the end of the job instead of two, and therefore does not
inject an error, which makes the block job complete instead of raising
an error.
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20211223165308.103793-1-hreitz@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2021-12-23 17:53:08 +01:00
|
|
|
# Ensure that mirror will copy something before READY so the
|
|
|
|
# target format layer will forward the pre-READY flush to its
|
|
|
|
# file child
|
2022-04-18 23:15:03 +02:00
|
|
|
iotests.qemu_io('-c', 'write -P 1 0 64k', source)
|
iotests/MRCE: Write data to source
This test assumes that mirror flushes the source when entering the READY
state, and that the format level will pass that flush on to the protocol
level (where we intercept it with blkdebug).
However, apparently that does not happen when using a VMDK image with
zeroed_grain=on, which actually is the default set by testenv.py. Right
now, Python tests ignore IMGOPTS, though, so this has no effect; but
Vladimir has a series that will change this, so we need to fix this test
before that series lands.
We can fix it by writing data to the source before we start the mirror
job; apparently that makes the (VMDK) format layer change its mind and
pass on the pre-READY flush to the protocol level, so the test passes
again. (I presume, without any data written, mirror just does a 64M
zero write on the target, which VMDK with zeroed_grain=on basically just
ignores.)
Without this, we do not get a flush, and so blkdebug only sees a single
flush at the end of the job instead of two, and therefore does not
inject an error, which makes the block job complete instead of raising
an error.
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20211223165308.103793-1-hreitz@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2021-12-23 17:53:08 +01:00
|
|
|
|
2021-10-06 17:19:40 +02:00
|
|
|
self.vm = iotests.VM()
|
|
|
|
self.vm.launch()
|
|
|
|
|
|
|
|
def tearDown(self) -> None:
|
|
|
|
self.vm.shutdown()
|
|
|
|
os.remove(source)
|
|
|
|
os.remove(target)
|
|
|
|
|
|
|
|
def add_blockdevs(self, once: bool) -> None:
|
|
|
|
res = self.vm.qmp('blockdev-add',
|
|
|
|
**{'node-name': 'source',
|
|
|
|
'driver': iotests.imgfmt,
|
|
|
|
'file': {
|
|
|
|
'driver': 'file',
|
|
|
|
'filename': source
|
|
|
|
}})
|
|
|
|
self.assert_qmp(res, 'return', {})
|
|
|
|
|
|
|
|
# blkdebug notes:
|
|
|
|
# Enter state 2 on the first flush, which happens before the
|
|
|
|
# job enters the READY state. The second flush will happen
|
|
|
|
# when the job is about to complete, and we want that one to
|
|
|
|
# fail.
|
|
|
|
res = self.vm.qmp('blockdev-add',
|
|
|
|
**{'node-name': 'target',
|
|
|
|
'driver': iotests.imgfmt,
|
|
|
|
'file': {
|
|
|
|
'driver': 'blkdebug',
|
|
|
|
'image': {
|
|
|
|
'driver': 'file',
|
|
|
|
'filename': target
|
|
|
|
},
|
|
|
|
'set-state': [{
|
|
|
|
'event': 'flush_to_disk',
|
|
|
|
'state': 1,
|
|
|
|
'new_state': 2
|
|
|
|
}],
|
|
|
|
'inject-error': [{
|
|
|
|
'event': 'flush_to_disk',
|
|
|
|
'once': once,
|
|
|
|
'immediately': True,
|
|
|
|
'state': 2
|
|
|
|
}]}})
|
|
|
|
self.assert_qmp(res, 'return', {})
|
|
|
|
|
|
|
|
def start_mirror(self) -> None:
|
|
|
|
res = self.vm.qmp('blockdev-mirror',
|
|
|
|
job_id='mirror',
|
|
|
|
device='source',
|
|
|
|
target='target',
|
|
|
|
filter_node_name='mirror-top',
|
|
|
|
sync='full',
|
|
|
|
on_target_error='stop')
|
|
|
|
self.assert_qmp(res, 'return', {})
|
|
|
|
|
|
|
|
def cancel_mirror_with_error(self) -> None:
|
|
|
|
self.vm.event_wait('BLOCK_JOB_READY')
|
|
|
|
|
|
|
|
# Write something so will not leave the job immediately, but
|
|
|
|
# flush first (which will fail, thanks to blkdebug)
|
|
|
|
res = self.vm.qmp('human-monitor-command',
|
iotests/MRCE: Write data to source
This test assumes that mirror flushes the source when entering the READY
state, and that the format level will pass that flush on to the protocol
level (where we intercept it with blkdebug).
However, apparently that does not happen when using a VMDK image with
zeroed_grain=on, which actually is the default set by testenv.py. Right
now, Python tests ignore IMGOPTS, though, so this has no effect; but
Vladimir has a series that will change this, so we need to fix this test
before that series lands.
We can fix it by writing data to the source before we start the mirror
job; apparently that makes the (VMDK) format layer change its mind and
pass on the pre-READY flush to the protocol level, so the test passes
again. (I presume, without any data written, mirror just does a 64M
zero write on the target, which VMDK with zeroed_grain=on basically just
ignores.)
Without this, we do not get a flush, and so blkdebug only sees a single
flush at the end of the job instead of two, and therefore does not
inject an error, which makes the block job complete instead of raising
an error.
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20211223165308.103793-1-hreitz@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2021-12-23 17:53:08 +01:00
|
|
|
command_line='qemu-io mirror-top "write -P 2 0 64k"')
|
2021-10-06 17:19:40 +02:00
|
|
|
self.assert_qmp(res, 'return', '')
|
|
|
|
|
|
|
|
# Drain status change events
|
|
|
|
while self.vm.event_wait('JOB_STATUS_CHANGE', timeout=0.0) is not None:
|
|
|
|
pass
|
|
|
|
|
|
|
|
res = self.vm.qmp('block-job-cancel', device='mirror')
|
|
|
|
self.assert_qmp(res, 'return', {})
|
|
|
|
|
|
|
|
self.vm.event_wait('BLOCK_JOB_ERROR')
|
|
|
|
|
|
|
|
def test_transient_error(self) -> None:
|
|
|
|
self.add_blockdevs(True)
|
|
|
|
self.start_mirror()
|
|
|
|
self.cancel_mirror_with_error()
|
|
|
|
|
|
|
|
while True:
|
|
|
|
e = self.vm.event_wait('JOB_STATUS_CHANGE')
|
|
|
|
if e['data']['status'] == 'standby':
|
|
|
|
# Transient error, try again
|
|
|
|
self.vm.qmp('block-job-resume', device='mirror')
|
|
|
|
elif e['data']['status'] == 'null':
|
|
|
|
break
|
|
|
|
|
|
|
|
def test_persistent_error(self) -> None:
|
|
|
|
self.add_blockdevs(False)
|
|
|
|
self.start_mirror()
|
|
|
|
self.cancel_mirror_with_error()
|
|
|
|
|
|
|
|
while True:
|
|
|
|
e = self.vm.event_wait('JOB_STATUS_CHANGE')
|
|
|
|
if e['data']['status'] == 'standby':
|
|
|
|
# Persistent error, no point in continuing
|
|
|
|
self.vm.qmp('block-job-cancel', device='mirror', force=True)
|
|
|
|
elif e['data']['status'] == 'null':
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# LUKS would require special key-secret handling in add_blockdevs()
|
|
|
|
iotests.main(supported_fmts=['generic'],
|
|
|
|
unsupported_fmts=['luks'],
|
|
|
|
supported_protocols=['file'])
|