From nobody Thu Nov 6 19:15:54 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488228806519297.7651061450439; Mon, 27 Feb 2017 12:53:26 -0800 (PST) Received: from localhost ([::1]:56760 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciSIM-0003FV-5a for importer@patchew.org; Mon, 27 Feb 2017 15:53:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57433) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciRdV-0000Gl-5Z for qemu-devel@nongnu.org; Mon, 27 Feb 2017 15:11:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciRdT-0003dW-U6 for qemu-devel@nongnu.org; Mon, 27 Feb 2017 15:11:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55082) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciRdQ-0003ZZ-CW; Mon, 27 Feb 2017 15:11:04 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9A23042BA1; Mon, 27 Feb 2017 20:11:04 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-148.ams2.redhat.com [10.36.116.148]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RK9n8e003294; Mon, 27 Feb 2017 15:11:02 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 27 Feb 2017 21:09:28 +0100 Message-Id: <1488226184-9044-28-git-send-email-kwolf@redhat.com> In-Reply-To: <1488226184-9044-1-git-send-email-kwolf@redhat.com> References: <1488226184-9044-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 27 Feb 2017 20:11:04 +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 v2 27/43] backup: Use real permissions in backup block job 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, jcody@redhat.com, famz@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The backup block job doesn't have very complicated requirements: It needs to read from the source and write to the target, but it's fine with either side being changed. The only restriction is that we can't resize the image because the job uses a cached value. qemu-iotests 055 needs to be changed because it used a target which was already attached to a virtio-blk device. The permission system correctly forbids this (virtio-blk can't accept another writer with its default share-rw=3Doff). Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/backup.c | 15 ++++++++++----- tests/qemu-iotests/055 | 11 +++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/block/backup.c b/block/backup.c index 405f271..d1ab617 100644 --- a/block/backup.c +++ b/block/backup.c @@ -618,15 +618,20 @@ BlockJob *backup_job_create(const char *job_id, Block= DriverState *bs, goto error; } =20 - /* FIXME Use real permissions */ - job =3D block_job_create(job_id, &backup_job_driver, bs, 0, BLK_PERM_A= LL, + /* job->common.len is fixed, so we can't allow resize */ + job =3D block_job_create(job_id, &backup_job_driver, bs, + BLK_PERM_CONSISTENT_READ, + BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE | + BLK_PERM_WRITE_UNCHANGED | BLK_PERM_GRAPH_MOD, speed, creation_flags, cb, opaque, errp); if (!job) { goto error; } =20 - /* FIXME Use real permissions */ - job->target =3D blk_new(0, BLK_PERM_ALL); + /* The target must match the source in size, so no resize here either = */ + job->target =3D blk_new(BLK_PERM_WRITE, + BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE | + BLK_PERM_WRITE_UNCHANGED | BLK_PERM_GRAPH_MOD); ret =3D blk_insert_bs(job->target, target, errp); if (ret < 0) { goto error; @@ -657,7 +662,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDr= iverState *bs, job->cluster_size =3D MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster= _size); } =20 - /* FIXME Use real permissions */ + /* Required permissions are already taken with target's blk_new() */ block_job_add_bdrv(&job->common, "target", target, 0, BLK_PERM_ALL, &error_abort); job->common.len =3D len; diff --git a/tests/qemu-iotests/055 b/tests/qemu-iotests/055 index 1d3fd04..aafcd24 100755 --- a/tests/qemu-iotests/055 +++ b/tests/qemu-iotests/055 @@ -48,7 +48,8 @@ class TestSingleDrive(iotests.QMPTestCase): def setUp(self): qemu_img('create', '-f', iotests.imgfmt, blockdev_target_img, str(= image_len)) =20 - self.vm =3D iotests.VM().add_drive(test_img).add_drive(blockdev_ta= rget_img) + self.vm =3D iotests.VM().add_drive(test_img) + self.vm.add_drive(blockdev_target_img, interface=3D"none") if iotests.qemu_default_machine =3D=3D 'pc': self.vm.add_drive(None, 'media=3Dcdrom', 'ide') self.vm.launch() @@ -164,7 +165,8 @@ class TestSetSpeed(iotests.QMPTestCase): def setUp(self): qemu_img('create', '-f', iotests.imgfmt, blockdev_target_img, str(= image_len)) =20 - self.vm =3D iotests.VM().add_drive(test_img).add_drive(blockdev_ta= rget_img) + self.vm =3D iotests.VM().add_drive(test_img) + self.vm.add_drive(blockdev_target_img, interface=3D"none") self.vm.launch() =20 def tearDown(self): @@ -247,7 +249,8 @@ class TestSingleTransaction(iotests.QMPTestCase): def setUp(self): qemu_img('create', '-f', iotests.imgfmt, blockdev_target_img, str(= image_len)) =20 - self.vm =3D iotests.VM().add_drive(test_img).add_drive(blockdev_ta= rget_img) + self.vm =3D iotests.VM().add_drive(test_img) + self.vm.add_drive(blockdev_target_img, interface=3D"none") if iotests.qemu_default_machine =3D=3D 'pc': self.vm.add_drive(None, 'media=3Dcdrom', 'ide') self.vm.launch() @@ -460,7 +463,7 @@ class TestDriveCompression(iotests.QMPTestCase): =20 qemu_img('create', '-f', fmt, blockdev_target_img, str(TestDriveCompression.image_len), *args) - self.vm.add_drive(blockdev_target_img, format=3Dfmt) + self.vm.add_drive(blockdev_target_img, format=3Dfmt, interface=3D"= none") =20 self.vm.launch() =20 --=20 1.8.3.1