From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
John Snow <jsnow@redhat.com>,
qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>
Subject: [PATCH for-6.1? v2 7/7] iotests: Add mirror-ready-cancel-error test
Date: Mon, 26 Jul 2021 16:46:13 +0200 [thread overview]
Message-ID: <20210726144613.954844-8-mreitz@redhat.com> (raw)
In-Reply-To: <20210726144613.954844-1-mreitz@redhat.com>
Test what happens when there is an I/O error after a mirror job in the
READY phase has been cancelled.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
.../tests/mirror-ready-cancel-error | 143 ++++++++++++++++++
.../tests/mirror-ready-cancel-error.out | 5 +
2 files changed, 148 insertions(+)
create mode 100755 tests/qemu-iotests/tests/mirror-ready-cancel-error
create mode 100644 tests/qemu-iotests/tests/mirror-ready-cancel-error.out
diff --git a/tests/qemu-iotests/tests/mirror-ready-cancel-error b/tests/qemu-iotests/tests/mirror-ready-cancel-error
new file mode 100755
index 0000000000..f2dc88881f
--- /dev/null
+++ b/tests/qemu-iotests/tests/mirror-ready-cancel-error
@@ -0,0 +1,143 @@
+#!/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:
+ assert iotests.qemu_img_create('-f', iotests.imgfmt, source,
+ str(image_size)) == 0
+ assert iotests.qemu_img_create('-f', iotests.imgfmt, target,
+ str(image_size)) == 0
+
+ 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',
+ command_line='qemu-io mirror-top "write 0 64k"')
+ 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'])
diff --git a/tests/qemu-iotests/tests/mirror-ready-cancel-error.out b/tests/qemu-iotests/tests/mirror-ready-cancel-error.out
new file mode 100644
index 0000000000..fbc63e62f8
--- /dev/null
+++ b/tests/qemu-iotests/tests/mirror-ready-cancel-error.out
@@ -0,0 +1,5 @@
+..
+----------------------------------------------------------------------
+Ran 2 tests
+
+OK
--
2.31.1
next prev parent reply other threads:[~2021-07-26 14:50 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-26 14:46 [PATCH for-6.1? v2 0/7] mirror: Handle errors after READY cancel Max Reitz
2021-07-26 14:46 ` [PATCH for-6.1? v2 1/7] mirror: Keep s->synced on error Max Reitz
2021-07-26 14:46 ` [PATCH for-6.1? v2 2/7] mirror: Drop s->synced Max Reitz
2021-07-26 15:26 ` Eric Blake
2021-07-27 11:41 ` Vladimir Sementsov-Ogievskiy
2021-07-26 14:46 ` [PATCH for-6.1? v2 3/7] job: @force parameter for job_cancel_sync{, _all}() Max Reitz
2021-08-03 14:00 ` [PATCH for-6.1? v2 3/7] job: @force parameter for job_cancel_sync{,_all}() Kevin Wolf
2021-07-26 14:46 ` [PATCH for-6.1? v2 4/7] jobs: Give Job.force_cancel more meaning Max Reitz
2021-07-26 21:38 ` Eric Blake
2021-07-27 12:40 ` Vladimir Sementsov-Ogievskiy
2021-07-26 14:46 ` [PATCH for-6.1? v2 5/7] job: Add job_cancel_requested() Max Reitz
2021-07-27 13:04 ` Vladimir Sementsov-Ogievskiy
2021-07-27 15:39 ` Max Reitz
2021-07-27 15:47 ` Vladimir Sementsov-Ogievskiy
2021-08-02 10:23 ` Max Reitz
2021-08-03 12:35 ` Vladimir Sementsov-Ogievskiy
2021-08-03 14:25 ` Kevin Wolf
2021-08-04 8:07 ` Max Reitz
2021-08-04 10:34 ` Kevin Wolf
2021-08-04 11:00 ` Peter Krempa
2021-08-04 14:15 ` Max Reitz
2021-07-26 14:46 ` [PATCH for-6.1? v2 6/7] mirror: Check job_is_cancelled() earlier Max Reitz
2021-07-27 13:13 ` Vladimir Sementsov-Ogievskiy
2021-07-27 15:40 ` Max Reitz
2021-08-03 14:34 ` Kevin Wolf
2021-08-04 8:25 ` Max Reitz
2021-08-04 9:48 ` Kevin Wolf
2021-08-04 10:12 ` Max Reitz
2021-07-26 14:46 ` Max Reitz [this message]
2021-07-27 13:24 ` [PATCH for-6.1? v2 7/7] iotests: Add mirror-ready-cancel-error test Vladimir Sementsov-Ogievskiy
2021-08-03 14:36 ` [PATCH for-6.1? v2 0/7] mirror: Handle errors after READY cancel Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210726144613.954844-8-mreitz@redhat.com \
--to=mreitz@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).