From patchwork Thu Aug 9 22:31:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 955890 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41mjxX5n78z9s4b for ; Fri, 10 Aug 2018 08:44:47 +1000 (AEST) Received: from localhost ([::1]:53466 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fntfh-0003BF-4W for incoming@patchwork.ozlabs.org; Thu, 09 Aug 2018 18:44:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60368) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fntT2-00083t-Ia for qemu-devel@nongnu.org; Thu, 09 Aug 2018 18:31:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fntT1-0002hf-9o for qemu-devel@nongnu.org; Thu, 09 Aug 2018 18:31:40 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54210 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fntSv-0002c7-4b; Thu, 09 Aug 2018 18:31:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AAA714022905; Thu, 9 Aug 2018 22:31:32 +0000 (UTC) Received: from localhost (ovpn-204-42.brq.redhat.com [10.40.204.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 531FD1C660; Thu, 9 Aug 2018 22:31:32 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 10 Aug 2018 00:31:12 +0200 Message-Id: <20180809223117.7846-7-mreitz@redhat.com> In-Reply-To: <20180809223117.7846-1-mreitz@redhat.com> References: <20180809223117.7846-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 09 Aug 2018 22:31:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 09 Aug 2018 22:31:32 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 06/11] iotests: Add tests for mirror @replaces loops X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This adds two tests for cases where our old check_to_replace_node() function failed to detect that executing this job with these parameters would result in a cyclic graph. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- tests/qemu-iotests/041 | 124 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/041.out | 4 +- 2 files changed, 126 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index c20ac7da87..186bd0f031 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -1061,5 +1061,129 @@ class TestOrphanedSource(iotests.QMPTestCase): target='dest-ro') self.assert_qmp(result, 'error/class', 'GenericError') +# Various tests for the @replaces option (independent of quorum) +class TestReplaces(iotests.QMPTestCase): + def setUp(self): + self.vm = iotests.VM() + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + + def test_drive_mirror_loop(self): + qemu_img('create', '-f', iotests.imgfmt, test_img, '1M') + + result = self.vm.qmp('object-add', qom_type='throttle-group', id='tg') + self.assert_qmp(result, 'return', {}) + + result = self.vm.qmp('blockdev-add', **{ + 'node-name': 'source', + 'driver': 'throttle', + 'throttle-group': 'tg', + 'file': { + 'node-name': 'filtered', + 'driver': 'qcow2', + 'file': { + 'driver': 'file', + 'filename': test_img + } + } + }) + self.assert_qmp(result, 'return', {}) + + # Mirror from @source to @target in sync=none, so that @source + # will be @target's backing file; but replace @filtered. + # Then, @target's backing file will be @source, whose backing + # file is now @target instead of @filtered. That is a loop. + # (But apart from the loop, replacing @filtered instead of + # @source is fine, because both are just filtered versions of + # each other.) + result = self.vm.qmp('drive-mirror', + job_id='mirror', + device='source', + target=target_img, + format=iotests.imgfmt, + node_name='target', + sync='none', + replaces='filtered') + if 'error' in result: + # This is the correct result + self.assert_qmp(result, 'error/class', 'GenericError') + else: + # This is wrong, but let's run it to the bitter conclusion + self.complete_and_wait(drive='mirror') + # Fail for good measure, although qemu should have crashed + # anyway + self.fail('Loop creation was successful') + + os.remove(test_img) + try: + os.remove(target_img) + except OSError: + pass + + def test_blockdev_mirror_loop(self): + qemu_img('create', '-f', iotests.imgfmt, test_img, '1M') + qemu_img('create', '-f', iotests.imgfmt, target_img, '1M') + + result = self.vm.qmp('object-add', qom_type='throttle-group', id='tg') + self.assert_qmp(result, 'return', {}) + + result = self.vm.qmp('blockdev-add', **{ + 'node-name': 'source', + 'driver': 'throttle', + 'throttle-group': 'tg', + 'file': { + 'node-name': 'middle', + 'driver': 'throttle', + 'throttle-group': 'tg', + 'file': { + 'node-name': 'bottom', + 'driver': 'qcow2', + 'file': { + 'driver': 'file', + 'filename': test_img + } + } + } + }) + self.assert_qmp(result, 'return', {}) + + result = self.vm.qmp('blockdev-add', **{ + 'node-name': 'target', + 'driver': 'qcow2', + 'file': { + 'driver': 'file', + 'filename': target_img + }, + 'backing': 'middle' + }) + + # Mirror from @source to @target. With blockdev-mirror, the + # current (old) backing file is retained (which is @middle). + # By replacing @bottom, @middle's file will be @target, whose + # backing file is @middle again. That is a loop. + # (But apart from the loop, replacing @bottom instead of + # @source is fine, because both are just filtered versions of + # each other.) + result = self.vm.qmp('blockdev-mirror', + job_id='mirror', + device='source', + target='target', + sync='full', + replaces='bottom') + if 'error' in result: + # This is the correct result + self.assert_qmp(result, 'error/class', 'GenericError') + else: + # This is wrong, but let's run it to the bitter conclusion + self.complete_and_wait(drive='mirror') + # Fail for good measure, although qemu should have crashed + # anyway + self.fail('Loop creation was successful') + + os.remove(test_img) + os.remove(target_img) + if __name__ == '__main__': iotests.main(supported_fmts=['qcow2', 'qed']) diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out index c28b392b87..d71481b010 100644 --- a/tests/qemu-iotests/041.out +++ b/tests/qemu-iotests/041.out @@ -1,5 +1,5 @@ -..................................................................................... +....................................................................................... ---------------------------------------------------------------------- -Ran 85 tests +Ran 87 tests OK