From nobody Sun May 5 08:39:38 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1510933795936964.6346302868621; Fri, 17 Nov 2017 07:49:55 -0800 (PST) Received: from localhost ([::1]:46535 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eFitV-0003vb-Te for importer@patchew.org; Fri, 17 Nov 2017 10:49:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46608) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eFirz-0003Ex-US for qemu-devel@nongnu.org; Fri, 17 Nov 2017 10:47:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eFirz-00087p-0e for qemu-devel@nongnu.org; Fri, 17 Nov 2017 10:47:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54332) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eFirw-00081a-JC; Fri, 17 Nov 2017 10:47:52 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9295C3D953; Fri, 17 Nov 2017 15:47:51 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-103.ams2.redhat.com [10.36.117.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id D80CD83A9C; Fri, 17 Nov 2017 15:47:46 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 17 Nov 2017 16:47:38 +0100 Message-Id: <20171117154739.32565-2-kwolf@redhat.com> In-Reply-To: <20171117154739.32565-1-kwolf@redhat.com> References: <20171117154739.32565-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 17 Nov 2017 15:47:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.11 1/2] block: Fix permissions in image activation 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: kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Inactive images generally request less permissions for their image files than they would if they were active (in particular, write permissions). Activating the image involves extending the permissions, therefore. drv->bdrv_invalidate_cache() can already require write access to the image file, so we have to update the permissions earlier than that. The current code does it only later, so we have to move up this part. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/block.c b/block.c index edc5bb9f9b..6fe5b91260 100644 --- a/block.c +++ b/block.c @@ -4178,7 +4178,29 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Err= or **errp) } } =20 + /* + * Update permissions, they may differ for inactive nodes. + * + * Note that the required permissions of inactive images are always a + * subset of the permissions required after activating the image. This + * allows us to just get the permissions upfront without restricting + * drv->bdrv_invalidate_cache(). + * + * It also means that in error cases, we don't have to try and revert = to + * the old permissions (which is an operation that could fail, too). W= e can + * just keep the extended permissions for the next time that an activa= tion + * of the image is tried. + */ bs->open_flags &=3D ~BDRV_O_INACTIVE; + bdrv_get_cumulative_perm(bs, &perm, &shared_perm); + ret =3D bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, &local_err); + if (ret < 0) { + bs->open_flags |=3D BDRV_O_INACTIVE; + error_propagate(errp, local_err); + return; + } + bdrv_set_perm(bs, perm, shared_perm); + if (bs->drv->bdrv_invalidate_cache) { bs->drv->bdrv_invalidate_cache(bs, &local_err); if (local_err) { @@ -4195,16 +4217,6 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Err= or **errp) return; } =20 - /* Update permissions, they may differ for inactive nodes */ - bdrv_get_cumulative_perm(bs, &perm, &shared_perm); - ret =3D bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, &local_err); - if (ret < 0) { - bs->open_flags |=3D BDRV_O_INACTIVE; - error_propagate(errp, local_err); - return; - } - bdrv_set_perm(bs, perm, shared_perm); - QLIST_FOREACH(parent, &bs->parents, next_parent) { if (parent->role->activate) { parent->role->activate(parent, &local_err); --=20 2.13.6 From nobody Sun May 5 08:39:38 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1510933873462960.6698185993077; Fri, 17 Nov 2017 07:51:13 -0800 (PST) Received: from localhost ([::1]:46547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eFiuv-00051q-HR for importer@patchew.org; Fri, 17 Nov 2017 10:50:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46645) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eFis2-0003HX-Ia for qemu-devel@nongnu.org; Fri, 17 Nov 2017 10:48:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eFis1-0008CK-DB for qemu-devel@nongnu.org; Fri, 17 Nov 2017 10:47:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36486) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eFiry-000863-Eo; Fri, 17 Nov 2017 10:47:54 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 912B9DA32B; Fri, 17 Nov 2017 15:47:53 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-103.ams2.redhat.com [10.36.117.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id E043183A9B; Fri, 17 Nov 2017 15:47:51 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 17 Nov 2017 16:47:39 +0100 Message-Id: <20171117154739.32565-3-kwolf@redhat.com> In-Reply-To: <20171117154739.32565-1-kwolf@redhat.com> References: <20171117154739.32565-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 17 Nov 2017 15:47:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.11 2/2] iotests: test clearing unknown autoclear_features by qcow2 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: kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Test clearing unknown autoclear_features by qcow2 on incoming migration. [ kwolf: Fixed wait for destination VM startup ] Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- tests/qemu-iotests/196 | 66 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/196.out | 5 ++++ tests/qemu-iotests/group | 1 + 3 files changed, 72 insertions(+) create mode 100755 tests/qemu-iotests/196 create mode 100644 tests/qemu-iotests/196.out diff --git a/tests/qemu-iotests/196 b/tests/qemu-iotests/196 new file mode 100755 index 0000000000..4116ebc92b --- /dev/null +++ b/tests/qemu-iotests/196 @@ -0,0 +1,66 @@ +#!/usr/bin/env python +# +# Test clearing unknown autoclear_features flag by qcow2 after +# migration. This test mimics migration to older qemu. +# +# Copyright (c) 2017 Parallels International GmbH +# +# 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 . +# + +import os +import iotests +from iotests import qemu_img + +disk =3D os.path.join(iotests.test_dir, 'disk') +migfile =3D os.path.join(iotests.test_dir, 'migfile') + +class TestInvalidateAutoclear(iotests.QMPTestCase): + + def tearDown(self): + self.vm_a.shutdown() + self.vm_b.shutdown() + os.remove(disk) + os.remove(migfile) + + def setUp(self): + qemu_img('create', '-f', iotests.imgfmt, disk, '1M') + + self.vm_a =3D iotests.VM(path_suffix=3D'a').add_drive(disk) + self.vm_a.launch() + + self.vm_b =3D iotests.VM(path_suffix=3D'b').add_drive(disk) + self.vm_b.add_incoming("exec: cat '" + migfile + "'") + + def test_migration(self): + result =3D self.vm_a.qmp('migrate', uri=3D'exec:cat>' + migfile) + self.assert_qmp(result, 'return', {}); + self.assertNotEqual(self.vm_a.event_wait("STOP"), None) + + with open(disk, 'r+b') as f: + f.seek(88) # first byte of autoclear_features field + f.write(b'\xff') + + self.vm_b.launch() + while True: + result =3D self.vm_b.qmp('query-status') + if result['return']['status'] =3D=3D 'running': + break + + with open(disk, 'rb') as f: + f.seek(88) + self.assertEqual(f.read(1), b'\x00') + +if __name__ =3D=3D '__main__': + iotests.main(supported_fmts=3D['qcow2']) diff --git a/tests/qemu-iotests/196.out b/tests/qemu-iotests/196.out new file mode 100644 index 0000000000..ae1213e6f8 --- /dev/null +++ b/tests/qemu-iotests/196.out @@ -0,0 +1,5 @@ +. +---------------------------------------------------------------------- +Ran 1 tests + +OK diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 83b839bbe3..1fad602152 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -193,5 +193,6 @@ 192 rw auto quick 194 rw auto migration quick 195 rw auto quick +196 rw auto quick 197 rw auto quick 198 rw auto --=20 2.13.6