From nobody Tue May 7 14:29:10 2024 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 1487691565330922.6837607338607; Tue, 21 Feb 2017 07:39:25 -0800 (PST) Received: from localhost ([::1]:46398 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCXA-0003sU-Mn for importer@patchew.org; Tue, 21 Feb 2017 10:39:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42565) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuK-000861-8S for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuJ-0007lu-Fi for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60872) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuA-0007ff-Di; Tue, 21 Feb 2017 09:59:02 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 F21A9C05678D; Tue, 21 Feb 2017 14:58:59 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwucj030565; Tue, 21 Feb 2017 09:58:58 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:57:57 +0100 Message-Id: <1487689130-30373-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 21 Feb 2017 14:59:00 +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 01/54] blockdev: Use BlockBackend to resize in qmp_block_resize() 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" In order to be able to do permission checking and to keep working with the BdrvChild based bdrv_truncate() that this involves, we need to create a temporary BlockBackend to resize the image. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- blockdev.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index db82ac9..3596d87 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2855,6 +2855,7 @@ void qmp_block_resize(bool has_device, const char *de= vice, int64_t size, Error **errp) { Error *local_err =3D NULL; + BlockBackend *blk =3D NULL; BlockDriverState *bs; AioContext *aio_context; int ret; @@ -2885,10 +2886,13 @@ void qmp_block_resize(bool has_device, const char *= device, goto out; } =20 + blk =3D blk_new(); + blk_insert_bs(blk, bs); + /* complete all in-flight operations before resizing the device */ bdrv_drain_all(); =20 - ret =3D bdrv_truncate(bs, size); + ret =3D blk_truncate(blk, size); switch (ret) { case 0: break; @@ -2910,6 +2914,7 @@ void qmp_block_resize(bool has_device, const char *de= vice, } =20 out: + blk_unref(blk); aio_context_release(aio_context); } =20 --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487689282951821.0574551684208; Tue, 21 Feb 2017 07:01:22 -0800 (PST) Received: from localhost ([::1]:46119 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBwM-0001ff-LX for importer@patchew.org; Tue, 21 Feb 2017 10:01:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42477) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuH-00081e-2m for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuG-0007jp-Ez for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60962) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuA-0007g9-TD; Tue, 21 Feb 2017 09:59:03 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 826AA7F7A9; Tue, 21 Feb 2017 14:59:01 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwuck030565; Tue, 21 Feb 2017 09:59:00 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:57:58 +0100 Message-Id: <1487689130-30373-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 21 Feb 2017 14:59:01 +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 02/54] qcow2: Use BB for resizing in qcow2_amend_options() 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" In order to able to conver bdrv_truncate() to take a BdrvChild and later to correctly check the resize permission here, we need to use a BlockBackend for resizing the image. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/qcow2.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index 3e274bd..254545a 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3250,7 +3250,11 @@ static int qcow2_amend_options(BlockDriverState *bs,= QemuOpts *opts, } =20 if (new_size) { - ret =3D bdrv_truncate(bs, new_size); + BlockBackend *blk =3D blk_new(); + blk_insert_bs(blk, bs); + ret =3D blk_truncate(blk, new_size); + blk_unref(blk); + if (ret < 0) { return ret; } --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487691005098566.846959404597; Tue, 21 Feb 2017 07:30:05 -0800 (PST) Received: from localhost ([::1]:46351 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCOB-0003UP-Op for importer@patchew.org; Tue, 21 Feb 2017 10:30:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42495) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuH-00082M-LR for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuG-0007k2-Kp for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48046) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuA-0007gl-W5; Tue, 21 Feb 2017 09:59:03 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 11B326AAE0; Tue, 21 Feb 2017 14:59:03 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwucl030565; Tue, 21 Feb 2017 09:59:01 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:57:59 +0100 Message-Id: <1487689130-30373-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 21 Feb 2017 14:59:03 +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 03/54] mirror: Resize active commit base in mirror_run() 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" This is more consistent with the commit block job, and it moves the code to a place where we already have the necessary BlockBackends to resize the base image when bdrv_truncate() is changed to require a BdrvChild. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/mirror.c | 50 ++++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 698a54e..13f793e 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -657,7 +657,28 @@ static void coroutine_fn mirror_run(void *opaque) if (s->bdev_length < 0) { ret =3D s->bdev_length; goto immediate_exit; - } else if (s->bdev_length =3D=3D 0) { + } + + /* Active commit must resize the base image if its size differs from t= he + * active layer. */ + if (s->base =3D=3D blk_bs(s->target)) { + int64_t base_length; + + base_length =3D blk_getlength(s->target); + if (base_length < 0) { + ret =3D base_length; + goto immediate_exit; + } + + if (s->bdev_length > base_length) { + ret =3D blk_truncate(s->target, s->bdev_length); + if (ret < 0) { + goto immediate_exit; + } + } + } + + if (s->bdev_length =3D=3D 0) { /* Report BLOCK_JOB_READY and wait for complete. */ block_job_event_ready(&s->common); s->synced =3D true; @@ -1058,9 +1079,7 @@ void commit_active_start(const char *job_id, BlockDri= verState *bs, BlockCompletionFunc *cb, void *opaque, Error **er= rp, bool auto_complete) { - int64_t length, base_length; int orig_base_flags; - int ret; Error *local_err =3D NULL; =20 orig_base_flags =3D bdrv_get_flags(base); @@ -1069,31 +1088,6 @@ void commit_active_start(const char *job_id, BlockDr= iverState *bs, return; } =20 - length =3D bdrv_getlength(bs); - if (length < 0) { - error_setg_errno(errp, -length, - "Unable to determine length of %s", bs->filename); - goto error_restore_flags; - } - - base_length =3D bdrv_getlength(base); - if (base_length < 0) { - error_setg_errno(errp, -base_length, - "Unable to determine length of %s", base->filenam= e); - goto error_restore_flags; - } - - if (length > base_length) { - ret =3D bdrv_truncate(base, length); - if (ret < 0) { - error_setg_errno(errp, -ret, - "Top image %s is larger than base image %s, an= d " - "resize of base image failed", - bs->filename, base->filename); - goto error_restore_flags; - } - } - mirror_start_job(job_id, bs, creation_flags, base, NULL, speed, 0, 0, MIRROR_LEAVE_BACKING_CHAIN, on_error, on_error, true, cb, opaque, &local_err, --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487690788318759.3333906812732; Tue, 21 Feb 2017 07:26:28 -0800 (PST) Received: from localhost ([::1]:46309 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCKf-0008Gx-Od for importer@patchew.org; Tue, 21 Feb 2017 10:26:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42523) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuI-00083T-HS for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuH-0007kL-2y for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35006) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuC-0007hW-GB; Tue, 21 Feb 2017 09:59:04 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 86F726267F; Tue, 21 Feb 2017 14:59:04 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwucm030565; Tue, 21 Feb 2017 09:59:03 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:00 +0100 Message-Id: <1487689130-30373-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 21 Feb 2017 14:59: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 04/54] block: Pass BdrvChild to bdrv_truncate() 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" Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 3 ++- block/blkdebug.c | 2 +- block/block-backend.c | 2 +- block/crypto.c | 2 +- block/parallels.c | 8 ++++---- block/qcow.c | 4 ++-- block/qcow2-refcount.c | 2 +- block/qcow2.c | 4 ++-- block/raw-format.c | 2 +- block/vhdx-log.c | 2 +- block/vhdx.c | 2 +- include/block/block.h | 2 +- 12 files changed, 18 insertions(+), 17 deletions(-) diff --git a/block.c b/block.c index 743c349..d951b5d 100644 --- a/block.c +++ b/block.c @@ -2626,8 +2626,9 @@ exit: /** * Truncate file to 'offset' bytes (needed only for file protocols) */ -int bdrv_truncate(BlockDriverState *bs, int64_t offset) +int bdrv_truncate(BdrvChild *child, int64_t offset) { + BlockDriverState *bs =3D child->bs; BlockDriver *drv =3D bs->drv; int ret; if (!drv) diff --git a/block/blkdebug.c b/block/blkdebug.c index d8eee1b..6117ce5 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -663,7 +663,7 @@ static int64_t blkdebug_getlength(BlockDriverState *bs) =20 static int blkdebug_truncate(BlockDriverState *bs, int64_t offset) { - return bdrv_truncate(bs->file->bs, offset); + return bdrv_truncate(bs->file, offset); } =20 static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options) diff --git a/block/block-backend.c b/block/block-backend.c index 819f272..492e71e 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1605,7 +1605,7 @@ int blk_truncate(BlockBackend *blk, int64_t offset) return -ENOMEDIUM; } =20 - return bdrv_truncate(blk_bs(blk), offset); + return bdrv_truncate(blk->root, offset); } =20 static void blk_pdiscard_entry(void *opaque) diff --git a/block/crypto.c b/block/crypto.c index 7aa7eb5..e05e4dd 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -383,7 +383,7 @@ static int block_crypto_truncate(BlockDriverState *bs, = int64_t offset) =20 offset +=3D payload_offset; =20 - return bdrv_truncate(bs->file->bs, offset); + return bdrv_truncate(bs->file, offset); } =20 static void block_crypto_close(BlockDriverState *bs) diff --git a/block/parallels.c b/block/parallels.c index 2ccefa7..ac94dfb 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -215,7 +215,7 @@ static int64_t allocate_clusters(BlockDriverState *bs, = int64_t sector_num, s->data_end << BDRV_SECTOR_BITS, space << BDRV_SECTOR_BITS, 0); } else { - ret =3D bdrv_truncate(bs->file->bs, + ret =3D bdrv_truncate(bs->file, (s->data_end + space) << BDRV_SECTOR_BITS); } if (ret < 0) { @@ -449,7 +449,7 @@ static int parallels_check(BlockDriverState *bs, BdrvCh= eckResult *res, size - res->image_end_offset); res->leaks +=3D count; if (fix & BDRV_FIX_LEAKS) { - ret =3D bdrv_truncate(bs->file->bs, res->image_end_offset); + ret =3D bdrv_truncate(bs->file, res->image_end_offset); if (ret < 0) { res->check_errors++; return ret; @@ -681,7 +681,7 @@ static int parallels_open(BlockDriverState *bs, QDict *= options, int flags, goto fail_options; } if (!bdrv_has_zero_init(bs->file->bs) || - bdrv_truncate(bs->file->bs, bdrv_getlength(bs->file->bs)) !=3D= 0) { + bdrv_truncate(bs->file, bdrv_getlength(bs->file->bs)) !=3D 0) { s->prealloc_mode =3D PRL_PREALLOC_MODE_FALLOCATE; } =20 @@ -724,7 +724,7 @@ static void parallels_close(BlockDriverState *bs) } =20 if (bs->open_flags & BDRV_O_RDWR) { - bdrv_truncate(bs->file->bs, s->data_end << BDRV_SECTOR_BITS); + bdrv_truncate(bs->file, s->data_end << BDRV_SECTOR_BITS); } =20 g_free(s->bat_dirty_bmap); diff --git a/block/qcow.c b/block/qcow.c index fb738fc..4534515 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -467,7 +467,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, /* round to cluster size */ cluster_offset =3D (cluster_offset + s->cluster_size - 1) & ~(s->cluster_size - 1); - bdrv_truncate(bs->file->bs, cluster_offset + s->cluster_si= ze); + bdrv_truncate(bs->file, cluster_offset + s->cluster_size); /* if encrypted, we must initialize the cluster content which won't be written */ if (bs->encrypted && @@ -909,7 +909,7 @@ static int qcow_make_empty(BlockDriverState *bs) if (bdrv_pwrite_sync(bs->file, s->l1_table_offset, s->l1_table, l1_length) < 0) return -1; - ret =3D bdrv_truncate(bs->file->bs, s->l1_table_offset + l1_length); + ret =3D bdrv_truncate(bs->file, s->l1_table_offset + l1_length); if (ret < 0) return ret; =20 diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 3dbde18..9e96f64 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1734,7 +1734,7 @@ static int check_refblocks(BlockDriverState *bs, Bdrv= CheckResult *res, goto resize_fail; } =20 - ret =3D bdrv_truncate(bs->file->bs, offset + s->cluster_si= ze); + ret =3D bdrv_truncate(bs->file, offset + s->cluster_size); if (ret < 0) { goto resize_fail; } diff --git a/block/qcow2.c b/block/qcow2.c index 254545a..3e1172b 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2570,7 +2570,7 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uin= t64_t offset, /* align end of file to a sector boundary to ease reading with sector based I/Os */ cluster_offset =3D bdrv_getlength(bs->file->bs); - return bdrv_truncate(bs->file->bs, cluster_offset); + return bdrv_truncate(bs->file, cluster_offset); } =20 buf =3D qemu_blockalign(bs, s->cluster_size); @@ -2784,7 +2784,7 @@ static int make_completely_empty(BlockDriverState *bs) goto fail; } =20 - ret =3D bdrv_truncate(bs->file->bs, (3 + l1_clusters) * s->cluster_siz= e); + ret =3D bdrv_truncate(bs->file, (3 + l1_clusters) * s->cluster_size); if (ret < 0) { goto fail; } diff --git a/block/raw-format.c b/block/raw-format.c index 8404a82..0ddffbd 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -341,7 +341,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t o= ffset) =20 s->size =3D offset; offset +=3D s->offset; - return bdrv_truncate(bs->file->bs, offset); + return bdrv_truncate(bs->file, offset); } =20 static int raw_media_changed(BlockDriverState *bs) diff --git a/block/vhdx-log.c b/block/vhdx-log.c index 02eb104..67a91c0 100644 --- a/block/vhdx-log.c +++ b/block/vhdx-log.c @@ -548,7 +548,7 @@ static int vhdx_log_flush(BlockDriverState *bs, BDRVVHD= XState *s, if (new_file_size % (1024*1024)) { /* round up to nearest 1MB boundary */ new_file_size =3D ((new_file_size >> 20) + 1) << 20; - bdrv_truncate(bs->file->bs, new_file_size); + bdrv_truncate(bs->file, new_file_size); } } qemu_vfree(desc_entries); diff --git a/block/vhdx.c b/block/vhdx.c index 68db9e0..c67772e 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1165,7 +1165,7 @@ static int vhdx_allocate_block(BlockDriverState *bs, = BDRVVHDXState *s, /* per the spec, the address for a block is in units of 1MB */ *new_offset =3D ROUND_UP(*new_offset, 1024 * 1024); =20 - return bdrv_truncate(bs->file->bs, *new_offset + s->block_size); + return bdrv_truncate(bs->file, *new_offset + s->block_size); } =20 /* diff --git a/include/block/block.h b/include/block/block.h index 4e81f20..a4cd06f 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -253,7 +253,7 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverSt= ate *bs, const char *backing_file); int bdrv_get_backing_file_depth(BlockDriverState *bs); void bdrv_refresh_filename(BlockDriverState *bs); -int bdrv_truncate(BlockDriverState *bs, int64_t offset); +int bdrv_truncate(BdrvChild *child, int64_t offset); int64_t bdrv_nb_sectors(BlockDriverState *bs); int64_t bdrv_getlength(BlockDriverState *bs); int64_t bdrv_get_allocated_file_size(BlockDriverState *bs); --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487691051704572.8244652326653; Tue, 21 Feb 2017 07:30:51 -0800 (PST) Received: from localhost ([::1]:46357 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCOt-0004DL-Cv for importer@patchew.org; Tue, 21 Feb 2017 10:30:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42591) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuK-00086V-ST for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuI-0007lg-Ss for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47572) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuD-0007iE-Ow; Tue, 21 Feb 2017 09:59:05 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 D026F42BB9; Tue, 21 Feb 2017 14:59:05 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwucn030565; Tue, 21 Feb 2017 09:59:04 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:01 +0100 Message-Id: <1487689130-30373-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 21 Feb 2017 14:59:05 +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 05/54] block: Attach bs->file only during .bdrv_open() 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 way that attaching bs->file worked was a bit unusual in that it was the only child that would be attached to a node which is not opened yet. Because of this, the block layer couldn't know yet which permissions the driver would eventually need. This patch moves the point where bs->file is attached to the beginning of the individual .bdrv_open() implementations, so drivers already know what they are going to do with the child. This is also more consistent with how driver-specific children work. For a moment, bdrv_open() gets its own BdrvChild to perform image probing, but instead of directly assigning this BdrvChild to the BDS, it becomes a temporary one and the node name is passed as an option to the drivers, so that they can simply use bdrv_open_child() to create another reference for their own use. This duplicated child for (the not opened yet) bs is not the final state, a follow-up patch will change the image probing code to use a BlockBackend, which is completely independent of bs. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 35 ++++++++++++++++++++++++----------- block/bochs.c | 6 ++++++ block/cloop.c | 6 ++++++ block/crypto.c | 6 ++++++ block/dmg.c | 6 ++++++ block/parallels.c | 6 ++++++ block/qcow.c | 6 ++++++ block/qcow2.c | 18 +++++++++++++++--- block/qed.c | 18 +++++++++++++++--- block/raw-format.c | 6 ++++++ block/replication.c | 6 ++++++ block/vdi.c | 6 ++++++ block/vhdx.c | 6 ++++++ block/vmdk.c | 6 ++++++ block/vpc.c | 6 ++++++ tests/qemu-iotests/051.out | 4 ++-- tests/qemu-iotests/051.pc.out | 4 ++-- 17 files changed, 130 insertions(+), 21 deletions(-) diff --git a/block.c b/block.c index d951b5d..40c4dee 100644 --- a/block.c +++ b/block.c @@ -1103,13 +1103,6 @@ static int bdrv_open_common(BlockDriverState *bs, Bd= rvChild *file, assert(!drv->bdrv_needs_filename || filename !=3D NULL); ret =3D drv->bdrv_file_open(bs, options, open_flags, &local_err); } else { - if (file =3D=3D NULL) { - error_setg(errp, "Can't use '%s' as a block driver for the " - "protocol level", drv->format_name); - ret =3D -EINVAL; - goto free_and_fail; - } - bs->file =3D file; ret =3D drv->bdrv_open(bs, options, open_flags, &local_err); } =20 @@ -1145,7 +1138,6 @@ static int bdrv_open_common(BlockDriverState *bs, Bdr= vChild *file, return 0; =20 free_and_fail: - bs->file =3D NULL; g_free(bs->opaque); bs->opaque =3D NULL; bs->drv =3D NULL; @@ -1368,7 +1360,18 @@ void bdrv_unref_child(BlockDriverState *parent, Bdrv= Child *child) } =20 if (child->bs->inherits_from =3D=3D parent) { - child->bs->inherits_from =3D NULL; + BdrvChild *c; + + /* Remove inherits_from only when the last reference between paren= t and + * child->bs goes away. */ + QLIST_FOREACH(c, &parent->children, next) { + if (c !=3D child && c->bs =3D=3D child->bs) { + break; + } + } + if (c =3D=3D NULL) { + child->bs->inherits_from =3D NULL; + } } =20 bdrv_root_unref_child(child); @@ -1789,13 +1792,20 @@ static BlockDriverState *bdrv_open_inherit(const ch= ar *filename, qdict_del(options, "backing"); } =20 - /* Open image file without format layer */ + /* Open image file without format layer. This BdrvChild is only used f= or + * probing, the block drivers will do their own bdrv_open_child() for = the + * same BDS, which is why we put the node name back into options. */ if ((flags & BDRV_O_PROTOCOL) =3D=3D 0) { + /* FIXME Shouldn't attach a child to a node that isn't opened yet.= */ file =3D bdrv_open_child(filename, options, "file", bs, &child_file, true, &local_err); if (local_err) { goto fail; } + if (file !=3D NULL) { + qdict_put(options, "file", + qstring_from_str(bdrv_get_node_name(file->bs))); + } } =20 /* Image format probing */ @@ -1835,7 +1845,7 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, goto fail; } =20 - if (file && (bs->file !=3D file)) { + if (file) { bdrv_unref_child(bs, file); file =3D NULL; } @@ -1901,6 +1911,9 @@ fail: if (file !=3D NULL) { bdrv_unref_child(bs, file); } + if (bs->file !=3D NULL) { + bdrv_unref_child(bs, bs->file); + } QDECREF(snapshot_options); QDECREF(bs->explicit_options); QDECREF(bs->options); diff --git a/block/bochs.c b/block/bochs.c index 8c9652e..7dd2ac4 100644 --- a/block/bochs.c +++ b/block/bochs.c @@ -104,6 +104,12 @@ static int bochs_open(BlockDriverState *bs, QDict *opt= ions, int flags, struct bochs_header bochs; int ret; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + bs->read_only =3D true; /* no write support yet */ =20 ret =3D bdrv_pread(bs->file, 0, &bochs, sizeof(bochs)); diff --git a/block/cloop.c b/block/cloop.c index 7b75f7e..877c9b0 100644 --- a/block/cloop.c +++ b/block/cloop.c @@ -66,6 +66,12 @@ static int cloop_open(BlockDriverState *bs, QDict *optio= ns, int flags, uint32_t offsets_size, max_compressed_block_size =3D 1, i; int ret; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + bs->read_only =3D true; =20 /* read header */ diff --git a/block/crypto.c b/block/crypto.c index e05e4dd..7cb2ff2 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -300,6 +300,12 @@ static int block_crypto_open_generic(QCryptoBlockForma= t format, QCryptoBlockOpenOptions *open_opts =3D NULL; unsigned int cflags =3D 0; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + opts =3D qemu_opts_create(opts_spec, NULL, 0, &error_abort); qemu_opts_absorb_qdict(opts, options, &local_err); if (local_err) { diff --git a/block/dmg.c b/block/dmg.c index 58a3ae8..8e387cd 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -413,6 +413,12 @@ static int dmg_open(BlockDriverState *bs, QDict *optio= ns, int flags, int64_t offset; int ret; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + block_module_load_one("dmg-bz2"); bs->read_only =3D true; =20 diff --git a/block/parallels.c b/block/parallels.c index ac94dfb..b2ec09f 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -581,6 +581,12 @@ static int parallels_open(BlockDriverState *bs, QDict = *options, int flags, Error *local_err =3D NULL; char *buf; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + ret =3D bdrv_pread(bs->file, 0, &ph, sizeof(ph)); if (ret < 0) { goto fail; diff --git a/block/qcow.c b/block/qcow.c index 4534515..038b05a 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -106,6 +106,12 @@ static int qcow_open(BlockDriverState *bs, QDict *opti= ons, int flags, QCowHeader header; Error *local_err =3D NULL; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + ret =3D bdrv_pread(bs->file, 0, &header, sizeof(header)); if (ret < 0) { goto fail; diff --git a/block/qcow2.c b/block/qcow2.c index 3e1172b..21e6142 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -814,8 +814,8 @@ static int qcow2_update_options(BlockDriverState *bs, Q= Dict *options, return ret; } =20 -static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, - Error **errp) +static int qcow2_do_open(BlockDriverState *bs, QDict *options, int flags, + Error **errp) { BDRVQcow2State *s =3D bs->opaque; unsigned int len, i; @@ -1205,6 +1205,18 @@ static int qcow2_open(BlockDriverState *bs, QDict *o= ptions, int flags, return ret; } =20 +static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, + Error **errp) +{ + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + + return qcow2_do_open(bs, options, flags, errp); +} + static void qcow2_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVQcow2State *s =3D bs->opaque; @@ -1785,7 +1797,7 @@ static void qcow2_invalidate_cache(BlockDriverState *= bs, Error **errp) options =3D qdict_clone_shallow(bs->options); =20 flags &=3D ~BDRV_O_INACTIVE; - ret =3D qcow2_open(bs, options, flags, &local_err); + ret =3D qcow2_do_open(bs, options, flags, &local_err); QDECREF(options); if (local_err) { error_propagate(errp, local_err); diff --git a/block/qed.c b/block/qed.c index 0b62c77..62a0a09 100644 --- a/block/qed.c +++ b/block/qed.c @@ -415,8 +415,8 @@ static void bdrv_qed_drain(BlockDriverState *bs) } } =20 -static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags, - Error **errp) +static int bdrv_qed_do_open(BlockDriverState *bs, QDict *options, int flag= s, + Error **errp) { BDRVQEDState *s =3D bs->opaque; QEDHeader le_header; @@ -550,6 +550,18 @@ out: return ret; } =20 +static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags, + Error **errp) +{ + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + + return bdrv_qed_do_open(bs, options, flags, errp); +} + static void bdrv_qed_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVQEDState *s =3D bs->opaque; @@ -1629,7 +1641,7 @@ static void bdrv_qed_invalidate_cache(BlockDriverStat= e *bs, Error **errp) bdrv_qed_close(bs); =20 memset(s, 0, sizeof(BDRVQEDState)); - ret =3D bdrv_qed_open(bs, NULL, bs->open_flags, &local_err); + ret =3D bdrv_qed_do_open(bs, NULL, bs->open_flags, &local_err); if (local_err) { error_propagate(errp, local_err); error_prepend(errp, "Could not reopen qed layer: "); diff --git a/block/raw-format.c b/block/raw-format.c index 0ddffbd..ce34d1b 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -384,6 +384,12 @@ static int raw_open(BlockDriverState *bs, QDict *optio= ns, int flags, BDRVRawState *s =3D bs->opaque; int ret; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + bs->sg =3D bs->file->bs->sg; bs->supported_write_flags =3D BDRV_REQ_FUA & bs->file->bs->supported_write_flags; diff --git a/block/replication.c b/block/replication.c index 729dd12..eff85c7 100644 --- a/block/replication.c +++ b/block/replication.c @@ -86,6 +86,12 @@ static int replication_open(BlockDriverState *bs, QDict = *options, const char *mode; const char *top_id; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + ret =3D -EINVAL; opts =3D qemu_opts_create(&replication_runtime_opts, NULL, 0, &error_a= bort); qemu_opts_absorb_qdict(opts, options, &local_err); diff --git a/block/vdi.c b/block/vdi.c index 0aeb940..18b4773 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -363,6 +363,12 @@ static int vdi_open(BlockDriverState *bs, QDict *optio= ns, int flags, int ret; Error *local_err =3D NULL; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + logout("\n"); =20 ret =3D bdrv_read(bs->file, 0, (uint8_t *)&header, 1); diff --git a/block/vhdx.c b/block/vhdx.c index c67772e..9918ee9 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -898,6 +898,12 @@ static int vhdx_open(BlockDriverState *bs, QDict *opti= ons, int flags, uint64_t signature; Error *local_err =3D NULL; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + s->bat =3D NULL; s->first_visible_write =3D true; =20 diff --git a/block/vmdk.c b/block/vmdk.c index 393c84d..9d68ec5 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -943,6 +943,12 @@ static int vmdk_open(BlockDriverState *bs, QDict *opti= ons, int flags, uint32_t magic; Error *local_err =3D NULL; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + buf =3D vmdk_read_desc(bs->file, 0, errp); if (!buf) { return -EINVAL; diff --git a/block/vpc.c b/block/vpc.c index ed6353d..d0df2a1 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -220,6 +220,12 @@ static int vpc_open(BlockDriverState *bs, QDict *optio= ns, int flags, int disk_type =3D VHD_DYNAMIC; int ret; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + opts =3D qemu_opts_create(&vpc_runtime_opts, NULL, 0, &error_abort); qemu_opts_absorb_qdict(opts, options, &local_err); if (local_err) { diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out index 42bf416..7524c62 100644 --- a/tests/qemu-iotests/051.out +++ b/tests/qemu-iotests/051.out @@ -225,7 +225,7 @@ Testing: -drive driver=3Dnbd QEMU_PROG: -drive driver=3Dnbd: NBD server address missing =20 Testing: -drive driver=3Draw -QEMU_PROG: -drive driver=3Draw: Can't use 'raw' as a block driver for the = protocol level +QEMU_PROG: -drive driver=3Draw: A block device must be specified for "file" =20 Testing: -drive file.driver=3Dfile QEMU_PROG: -drive file.driver=3Dfile: The 'file' block driver requires a f= ile name @@ -234,7 +234,7 @@ Testing: -drive file.driver=3Dnbd QEMU_PROG: -drive file.driver=3Dnbd: NBD server address missing =20 Testing: -drive file.driver=3Draw -QEMU_PROG: -drive file.driver=3Draw: Can't use 'raw' as a block driver for= the protocol level +QEMU_PROG: -drive file.driver=3Draw: A block device must be specified for = "file" =20 Testing: -drive foo=3Dbar QEMU_PROG: -drive foo=3Dbar: Must specify either driver or file diff --git a/tests/qemu-iotests/051.pc.out b/tests/qemu-iotests/051.pc.out index 603bb76..f1669c1 100644 --- a/tests/qemu-iotests/051.pc.out +++ b/tests/qemu-iotests/051.pc.out @@ -319,7 +319,7 @@ Testing: -drive driver=3Dnbd QEMU_PROG: -drive driver=3Dnbd: NBD server address missing =20 Testing: -drive driver=3Draw -QEMU_PROG: -drive driver=3Draw: Can't use 'raw' as a block driver for the = protocol level +QEMU_PROG: -drive driver=3Draw: A block device must be specified for "file" =20 Testing: -drive file.driver=3Dfile QEMU_PROG: -drive file.driver=3Dfile: The 'file' block driver requires a f= ile name @@ -328,7 +328,7 @@ Testing: -drive file.driver=3Dnbd QEMU_PROG: -drive file.driver=3Dnbd: NBD server address missing =20 Testing: -drive file.driver=3Draw -QEMU_PROG: -drive file.driver=3Draw: Can't use 'raw' as a block driver for= the protocol level +QEMU_PROG: -drive file.driver=3Draw: A block device must be specified for = "file" =20 Testing: -drive foo=3Dbar QEMU_PROG: -drive foo=3Dbar: Must specify either driver or file --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487691292063359.11923181608654; Tue, 21 Feb 2017 07:34:52 -0800 (PST) Received: from localhost ([::1]:46373 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCSm-0007xj-Ko for importer@patchew.org; Tue, 21 Feb 2017 10:34:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42525) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuI-00083o-Nr for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuH-0007l5-Rv for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49512) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuF-0007io-Ee; Tue, 21 Feb 2017 09:59:07 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 7A07E1555C; Tue, 21 Feb 2017 14:59:07 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwuco030565; Tue, 21 Feb 2017 09:59:05 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:02 +0100 Message-Id: <1487689130-30373-7-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 21 Feb 2017 14:59:07 +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 06/54] block: Factor out bdrv_open_child_bs() 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" This is the part of bdrv_open_child() that opens a BDS with option inheritance, but doesn't attach it as a child to the parent yet. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 61 +++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/block.c b/block.c index 40c4dee..e9d90aa 100644 --- a/block.c +++ b/block.c @@ -1546,28 +1546,12 @@ free_exit: return ret; } =20 -/* - * Opens a disk image whose options are given as BlockdevRef in another bl= ock - * device's options. - * - * If allow_none is true, no image will be opened if filename is false and= no - * BlockdevRef is given. NULL will be returned, but errp remains unset. - * - * bdrev_key specifies the key for the image's BlockdevRef in the options = QDict. - * That QDict has to be flattened; therefore, if the BlockdevRef is a QDict - * itself, all options starting with "${bdref_key}." are considered part o= f the - * BlockdevRef. - * - * The BlockdevRef will be removed from the options QDict. - */ -BdrvChild *bdrv_open_child(const char *filename, - QDict *options, const char *bdref_key, - BlockDriverState* parent, - const BdrvChildRole *child_role, - bool allow_none, Error **errp) +static BlockDriverState * +bdrv_open_child_bs(const char *filename, QDict *options, const char *bdref= _key, + BlockDriverState* parent, const BdrvChildRole *child_ro= le, + bool allow_none, Error **errp) { - BdrvChild *c =3D NULL; - BlockDriverState *bs; + BlockDriverState *bs =3D NULL; QDict *image_options; char *bdref_key_dot; const char *reference; @@ -1594,11 +1578,40 @@ BdrvChild *bdrv_open_child(const char *filename, goto done; } =20 - c =3D bdrv_attach_child(parent, bs, bdref_key, child_role); - done: qdict_del(options, bdref_key); - return c; + return bs; +} + +/* + * Opens a disk image whose options are given as BlockdevRef in another bl= ock + * device's options. + * + * If allow_none is true, no image will be opened if filename is false and= no + * BlockdevRef is given. NULL will be returned, but errp remains unset. + * + * bdrev_key specifies the key for the image's BlockdevRef in the options = QDict. + * That QDict has to be flattened; therefore, if the BlockdevRef is a QDict + * itself, all options starting with "${bdref_key}." are considered part o= f the + * BlockdevRef. + * + * The BlockdevRef will be removed from the options QDict. + */ +BdrvChild *bdrv_open_child(const char *filename, + QDict *options, const char *bdref_key, + BlockDriverState* parent, + const BdrvChildRole *child_role, + bool allow_none, Error **errp) +{ + BlockDriverState *bs; + + bs =3D bdrv_open_child_bs(filename, options, bdref_key, parent, child_= role, + allow_none, errp); + if (bs =3D=3D NULL) { + return NULL; + } + + return bdrv_attach_child(parent, bs, bdref_key, child_role); } =20 static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs, --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 14876909137970.8598785403138436; Tue, 21 Feb 2017 07:28:33 -0800 (PST) Received: from localhost ([::1]:46333 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCMi-00021w-80 for importer@patchew.org; Tue, 21 Feb 2017 10:28:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42583) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuK-00086J-Lo for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuJ-0007lz-GT for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34076) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuG-0007jm-UJ; Tue, 21 Feb 2017 09:59:09 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 0A3A9C04B320; Tue, 21 Feb 2017 14:59:09 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwucp030565; Tue, 21 Feb 2017 09:59:07 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:03 +0100 Message-Id: <1487689130-30373-8-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 21 Feb 2017 14:59:09 +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 07/54] block: Use BlockBackend for image probing 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" This fixes the use of a parent-less BdrvChild in bdrv_open_inherit() by converting it into a BlockBackend. Which is exactly what it should be, image probing is an external, standalone user of a node. The requests can't be considered to originate from the format driver node because that one isn't even opened yet. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/block.c b/block.c index e9d90aa..0f17576 100644 --- a/block.c +++ b/block.c @@ -588,21 +588,20 @@ BlockDriver *bdrv_probe_all(const uint8_t *buf, int b= uf_size, return drv; } =20 -static int find_image_format(BdrvChild *file, const char *filename, +static int find_image_format(BlockBackend *file, const char *filename, BlockDriver **pdrv, Error **errp) { - BlockDriverState *bs =3D file->bs; BlockDriver *drv; uint8_t buf[BLOCK_PROBE_BUF_SIZE]; int ret =3D 0; =20 /* Return the raw BlockDriver * to scsi-generic devices or empty drive= s */ - if (bdrv_is_sg(bs) || !bdrv_is_inserted(bs) || bdrv_getlength(bs) =3D= =3D 0) { + if (blk_is_sg(file) || !blk_is_inserted(file) || blk_getlength(file) = =3D=3D 0) { *pdrv =3D &bdrv_raw; return ret; } =20 - ret =3D bdrv_pread(file, 0, buf, sizeof(buf)); + ret =3D blk_pread(file, 0, buf, sizeof(buf)); if (ret < 0) { error_setg_errno(errp, -ret, "Could not read image for determining= its " "format"); @@ -974,7 +973,7 @@ QemuOptsList bdrv_runtime_opts =3D { * * Removes all processed options from *options. */ -static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file, +static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file, QDict *options, Error **errp) { int ret, open_flags; @@ -1005,7 +1004,7 @@ static int bdrv_open_common(BlockDriverState *bs, Bdr= vChild *file, assert(drv !=3D NULL); =20 if (file !=3D NULL) { - filename =3D file->bs->filename; + filename =3D blk_bs(file)->filename; } else { filename =3D qdict_get_try_str(options, "filename"); } @@ -1707,7 +1706,7 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, Error **errp) { int ret; - BdrvChild *file =3D NULL; + BlockBackend *file =3D NULL; BlockDriverState *bs; BlockDriver *drv =3D NULL; const char *drvname; @@ -1805,19 +1804,24 @@ static BlockDriverState *bdrv_open_inherit(const ch= ar *filename, qdict_del(options, "backing"); } =20 - /* Open image file without format layer. This BdrvChild is only used f= or + /* Open image file without format layer. This BlockBackend is only use= d for * probing, the block drivers will do their own bdrv_open_child() for = the * same BDS, which is why we put the node name back into options. */ if ((flags & BDRV_O_PROTOCOL) =3D=3D 0) { - /* FIXME Shouldn't attach a child to a node that isn't opened yet.= */ - file =3D bdrv_open_child(filename, options, "file", bs, - &child_file, true, &local_err); + BlockDriverState *file_bs; + + file_bs =3D bdrv_open_child_bs(filename, options, "file", bs, + &child_file, true, &local_err); if (local_err) { goto fail; } - if (file !=3D NULL) { + if (file_bs !=3D NULL) { + file =3D blk_new(); + blk_insert_bs(file, file_bs); + bdrv_unref(file_bs); + qdict_put(options, "file", - qstring_from_str(bdrv_get_node_name(file->bs))); + qstring_from_str(bdrv_get_node_name(file_bs))); } } =20 @@ -1859,7 +1863,7 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, } =20 if (file) { - bdrv_unref_child(bs, file); + blk_unref(file); file =3D NULL; } =20 @@ -1922,7 +1926,7 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, =20 fail: if (file !=3D NULL) { - bdrv_unref_child(bs, file); + blk_unref(file); } if (bs->file !=3D NULL) { bdrv_unref_child(bs, bs->file); --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487691841268392.45258278286747; Tue, 21 Feb 2017 07:44:01 -0800 (PST) Received: from localhost ([::1]:46427 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCbf-0008N8-TE for importer@patchew.org; Tue, 21 Feb 2017 10:43:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42643) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuP-0008CC-Sd for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuL-0007n5-1J for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48132) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuI-0007kl-90; Tue, 21 Feb 2017 09:59:10 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 555046AAE3; Tue, 21 Feb 2017 14:59:10 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwucq030565; Tue, 21 Feb 2017 09:59:09 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:04 +0100 Message-Id: <1487689130-30373-9-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 21 Feb 2017 14:59:10 +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 08/54] block: Factor out bdrv_open_driver() 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" This is a function that doesn't do any option parsing, but just does some basic BlockDriverState setup and calls the .bdrv_open() function of the block driver. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 112 +++++++++++++++++++++++++++++++++++++-----------------------= ---- 1 file changed, 65 insertions(+), 47 deletions(-) diff --git a/block.c b/block.c index 0f17576..03fc115 100644 --- a/block.c +++ b/block.c @@ -925,6 +925,67 @@ out: g_free(gen_node_name); } =20 +static int bdrv_open_driver(BlockDriverState *bs, BlockDriver *drv, + const char *node_name, QDict *options, + int open_flags, Error **errp) +{ + Error *local_err =3D NULL; + int ret; + + bdrv_assign_node_name(bs, node_name, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return -EINVAL; + } + + bs->drv =3D drv; + bs->opaque =3D g_malloc0(drv->instance_size); + + if (drv->bdrv_file_open) { + assert(!drv->bdrv_needs_filename || bs->filename[0]); + ret =3D drv->bdrv_file_open(bs, options, open_flags, &local_err); + } else { + ret =3D drv->bdrv_open(bs, options, open_flags, &local_err); + } + + if (ret < 0) { + if (local_err) { + error_propagate(errp, local_err); + } else if (bs->filename[0]) { + error_setg_errno(errp, -ret, "Could not open '%s'", bs->filena= me); + } else { + error_setg_errno(errp, -ret, "Could not open image"); + } + goto free_and_fail; + } + + ret =3D refresh_total_sectors(bs, bs->total_sectors); + if (ret < 0) { + error_setg_errno(errp, -ret, "Could not refresh total sector count= "); + goto free_and_fail; + } + + bdrv_refresh_limits(bs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret =3D -EINVAL; + goto free_and_fail; + } + + assert(bdrv_opt_mem_align(bs) !=3D 0); + assert(bdrv_min_mem_align(bs) !=3D 0); + assert(is_power_of_2(bs->bl.request_alignment)); + + return 0; + +free_and_fail: + /* FIXME Close bs first if already opened*/ + g_free(bs->opaque); + bs->opaque =3D NULL; + bs->drv =3D NULL; + return ret; +} + QemuOptsList bdrv_runtime_opts =3D { .name =3D "bdrv_common", .head =3D QTAILQ_HEAD_INITIALIZER(bdrv_runtime_opts.head), @@ -1019,14 +1080,6 @@ static int bdrv_open_common(BlockDriverState *bs, Bl= ockBackend *file, trace_bdrv_open_common(bs, filename ?: "", bs->open_flags, drv->format_name); =20 - node_name =3D qemu_opt_get(opts, "node-name"); - bdrv_assign_node_name(bs, node_name, &local_err); - if (local_err) { - error_propagate(errp, local_err); - ret =3D -EINVAL; - goto fail_opts; - } - bs->read_only =3D !(bs->open_flags & BDRV_O_RDWR); =20 if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, bs->read_only)) { @@ -1092,54 +1145,19 @@ static int bdrv_open_common(BlockDriverState *bs, B= lockBackend *file, } pstrcpy(bs->exact_filename, sizeof(bs->exact_filename), bs->filename); =20 - bs->drv =3D drv; - bs->opaque =3D g_malloc0(drv->instance_size); - /* Open the image, either directly or using a protocol */ open_flags =3D bdrv_open_flags(bs, bs->open_flags); - if (drv->bdrv_file_open) { - assert(file =3D=3D NULL); - assert(!drv->bdrv_needs_filename || filename !=3D NULL); - ret =3D drv->bdrv_file_open(bs, options, open_flags, &local_err); - } else { - ret =3D drv->bdrv_open(bs, options, open_flags, &local_err); - } - - if (ret < 0) { - if (local_err) { - error_propagate(errp, local_err); - } else if (bs->filename[0]) { - error_setg_errno(errp, -ret, "Could not open '%s'", bs->filena= me); - } else { - error_setg_errno(errp, -ret, "Could not open image"); - } - goto free_and_fail; - } + node_name =3D qemu_opt_get(opts, "node-name"); =20 - ret =3D refresh_total_sectors(bs, bs->total_sectors); + assert(!drv->bdrv_file_open || file =3D=3D NULL); + ret =3D bdrv_open_driver(bs, drv, node_name, options, open_flags, errp= ); if (ret < 0) { - error_setg_errno(errp, -ret, "Could not refresh total sector count= "); - goto free_and_fail; - } - - bdrv_refresh_limits(bs, &local_err); - if (local_err) { - error_propagate(errp, local_err); - ret =3D -EINVAL; - goto free_and_fail; + goto fail_opts; } =20 - assert(bdrv_opt_mem_align(bs) !=3D 0); - assert(bdrv_min_mem_align(bs) !=3D 0); - assert(is_power_of_2(bs->bl.request_alignment)); - qemu_opts_del(opts); return 0; =20 -free_and_fail: - g_free(bs->opaque); - bs->opaque =3D NULL; - bs->drv =3D NULL; fail_opts: qemu_opts_del(opts); return ret; --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487691192214281.4586060883262; Tue, 21 Feb 2017 07:33:12 -0800 (PST) Received: from localhost ([::1]:46366 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCRB-0006NS-Lo for importer@patchew.org; Tue, 21 Feb 2017 10:33:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42690) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuR-0008Dl-83 for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuQ-0007px-1o for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47620) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuJ-0007lq-QY; Tue, 21 Feb 2017 09:59:11 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 D540E42BBE; Tue, 21 Feb 2017 14:59:11 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwucr030565; Tue, 21 Feb 2017 09:59:10 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:05 +0100 Message-Id: <1487689130-30373-10-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 21 Feb 2017 14:59:11 +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 09/54] block: Add bdrv_new_open_driver() 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" This function allows to create more or less normal BlockDriverStates even for BlockDrivers that aren't globally registered (e.g. helper filters for block jobs). Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 30 +++++++++++++++++++++++++++++- include/block/block.h | 2 ++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 03fc115..e166fe8 100644 --- a/block.c +++ b/block.c @@ -939,13 +939,16 @@ static int bdrv_open_driver(BlockDriverState *bs, Blo= ckDriver *drv, } =20 bs->drv =3D drv; + bs->read_only =3D !(bs->open_flags & BDRV_O_RDWR); bs->opaque =3D g_malloc0(drv->instance_size); =20 if (drv->bdrv_file_open) { assert(!drv->bdrv_needs_filename || bs->filename[0]); ret =3D drv->bdrv_file_open(bs, options, open_flags, &local_err); - } else { + } else if (drv->bdrv_open) { ret =3D drv->bdrv_open(bs, options, open_flags, &local_err); + } else { + ret =3D 0; } =20 if (ret < 0) { @@ -986,6 +989,31 @@ free_and_fail: return ret; } =20 +BlockDriverState *bdrv_new_open_driver(BlockDriver *drv, const char *node_= name, + int flags, Error **errp) +{ + BlockDriverState *bs; + int ret; + + bs =3D bdrv_new(); + bs->open_flags =3D flags; + bs->explicit_options =3D qdict_new(); + bs->options =3D qdict_new(); + bs->opaque =3D NULL; + + update_options_from_flags(bs->options, flags); + + ret =3D bdrv_open_driver(bs, drv, node_name, bs->options, flags, errp); + if (ret < 0) { + QDECREF(bs->explicit_options); + QDECREF(bs->options); + bdrv_unref(bs); + return NULL; + } + + return bs; +} + QemuOptsList bdrv_runtime_opts =3D { .name =3D "bdrv_common", .head =3D QTAILQ_HEAD_INITIALIZER(bdrv_runtime_opts.head), diff --git a/include/block/block.h b/include/block/block.h index a4cd06f..bde5ebd 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -215,6 +215,8 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict = *parent_options, const char *bdref_key, Error **errp); BlockDriverState *bdrv_open(const char *filename, const char *reference, QDict *options, int flags, Error **errp); +BlockDriverState *bdrv_new_open_driver(BlockDriver *drv, const char *node_= name, + int flags, Error **errp); BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, BlockDriverState *bs, QDict *options, int flags); --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487691346736347.0744508848554; Tue, 21 Feb 2017 07:35:46 -0800 (PST) Received: from localhost ([::1]:46377 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCTe-0000CJ-45 for importer@patchew.org; Tue, 21 Feb 2017 10:35:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42728) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuS-0008Es-1h for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuR-0007qj-1t for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:17819) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuL-0007ms-Ds; Tue, 21 Feb 2017 09:59:13 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 7609415447; Tue, 21 Feb 2017 14:59:13 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwucs030565; Tue, 21 Feb 2017 09:59:12 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:06 +0100 Message-Id: <1487689130-30373-11-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 21 Feb 2017 14:59:13 +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 10/54] vvfat: Use opened node as backing file 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" We should not try to assign a not yet opened node as the backing file, because as soon as the permission system is added it will fail. The just added bdrv_new_open_driver() function is the right tool to open a file with an internal driver, use it. In case anyone wonders whether that magic fake backing file to trigger a special action on 'commit' actually works today: No, not for me. One reason is that we've been adding a raw format driver on top for several years now and raw doesn't support commit. Other reasons include that the backing file isn't writable and the driver doesn't support reopen, and it's also size 0 and the driver doesn't support bdrv_truncate. All of these are easily fixable, but then 'commit' ended up in an infinite loop deep in the vvfat code for me, so I thought I'd best leave it alone. I'm not really sure what it was supposed to do anyway. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/vvfat.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index c6bf67e..7f230be 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -2968,6 +2968,7 @@ static void write_target_close(BlockDriverState *bs) { =20 static BlockDriver vvfat_write_target =3D { .format_name =3D "vvfat_write_target", + .instance_size =3D sizeof(void*), .bdrv_co_pwritev =3D write_target_commit, .bdrv_close =3D write_target_close, }; @@ -3036,14 +3037,13 @@ static int enable_write_target(BlockDriverState *bs= , Error **errp) unlink(s->qcow_filename); #endif =20 - backing =3D bdrv_new(); + backing =3D bdrv_new_open_driver(&vvfat_write_target, NULL, BDRV_O_ALL= OW_RDWR, + &error_abort); + *(void**) backing->opaque =3D s; + bdrv_set_backing_hd(s->bs, backing); bdrv_unref(backing); =20 - s->bs->backing->bs->drv =3D &vvfat_write_target; - s->bs->backing->bs->opaque =3D g_new(void *, 1); - *(void**)s->bs->backing->bs->opaque =3D s; - return 0; =20 err: --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487691487061572.0222187857356; Tue, 21 Feb 2017 07:38:07 -0800 (PST) Received: from localhost ([::1]:46394 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCVx-0002hi-Pi for importer@patchew.org; Tue, 21 Feb 2017 10:38:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42737) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuS-0008FK-D1 for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuR-0007rJ-Jj for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49576) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuN-0007nc-09; Tue, 21 Feb 2017 09:59:15 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 0F156BDD4; Tue, 21 Feb 2017 14:59:15 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwuct030565; Tue, 21 Feb 2017 09:59:13 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:07 +0100 Message-Id: <1487689130-30373-12-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 21 Feb 2017 14:59:15 +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 11/54] tests: Use opened block node for block job tests 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" blk_insert_bs() and block job related functions will soon require an opened block node (permission calculations will involve the block driver), so let our tests be consistent with the real users in this respect. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- tests/test-blockjob-txn.c | 6 +++++- tests/test-blockjob.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c index b132e39..f6dfd08 100644 --- a/tests/test-blockjob-txn.c +++ b/tests/test-blockjob-txn.c @@ -96,7 +96,10 @@ static BlockJob *test_block_job_start(unsigned int itera= tions, char job_id[24]; =20 data =3D g_new0(TestBlockJobCBData, 1); - bs =3D bdrv_new(); + + bs =3D bdrv_open("null-co://", NULL, NULL, 0, &error_abort); + g_assert_nonnull(bs); + snprintf(job_id, sizeof(job_id), "job%u", counter++); s =3D block_job_create(job_id, &test_block_job_driver, bs, 0, BLOCK_JOB_DEFAULT, test_block_job_cb, @@ -242,6 +245,7 @@ static void test_pair_jobs_fail_cancel_race(void) int main(int argc, char **argv) { qemu_init_main_loop(&error_abort); + bdrv_init(); =20 g_test_init(&argc, &argv, NULL); g_test_add_func("/single/success", test_single_job_success); diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c index 60b78a3..068c9e4 100644 --- a/tests/test-blockjob.c +++ b/tests/test-blockjob.c @@ -54,7 +54,10 @@ static BlockJob *do_test_id(BlockBackend *blk, const cha= r *id, static BlockBackend *create_blk(const char *name) { BlockBackend *blk =3D blk_new(); - BlockDriverState *bs =3D bdrv_new(); + BlockDriverState *bs; + + bs =3D bdrv_open("null-co://", NULL, NULL, 0, &error_abort); + g_assert_nonnull(bs); =20 blk_insert_bs(blk, bs); bdrv_unref(bs); @@ -140,6 +143,7 @@ static void test_job_ids(void) int main(int argc, char **argv) { qemu_init_main_loop(&error_abort); + bdrv_init(); =20 g_test_init(&argc, &argv, NULL); g_test_add_func("/blockjob/ids", test_job_ids); --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487692118405791.2777189167822; Tue, 21 Feb 2017 07:48:38 -0800 (PST) Received: from localhost ([::1]:46453 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCg8-000453-61 for importer@patchew.org; Tue, 21 Feb 2017 10:48:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42723) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuS-0008Eq-0X for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuR-0007qq-76 for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32846) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuO-0007p7-Ej; Tue, 21 Feb 2017 09:59:16 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 7D73F8124B; Tue, 21 Feb 2017 14:59:16 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwucu030565; Tue, 21 Feb 2017 09:59:15 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:08 +0100 Message-Id: <1487689130-30373-13-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 21 Feb 2017 14:59:16 +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 12/54] block: Add op blocker permission constants 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" This patch defines the permission categories that will be used by the new op blocker system. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- include/block/block.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/include/block/block.h b/include/block/block.h index bde5ebd..ac40c8d 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -187,6 +187,41 @@ typedef enum BlockOpType { BLOCK_OP_TYPE_MAX, } BlockOpType; =20 +/* Block node permission constants */ +enum { + /** + * A user that has the "permission" of consistent reads is guaranteed = that + * their view of the contents of the block device is complete and + * self-consistent, repesenting the contents of a disk at a specific p= oint. + * + * For most block devices (including their backing files) this is true= , but + * the property cannot be maintained in a few situations like for + * intermediate nodes of a commit block job. + */ + BLK_PERM_CONSISTENT_READ =3D 0x01, + + /** This permission is required to change the visible disk contents. */ + BLK_PERM_WRITE =3D 0x02, + + /** + * This permission (which is weaker than BLK_PERM_WRITE) is both enoug= h and + * required for writes to the block node when the caller promises that + * this visible disk contents doesn't change. + */ + BLK_PERM_WRITE_UNCHANGED =3D 0x04, + + /** This permission is required to change the size of a block node. */ + BLK_PERM_RESIZE =3D 0x08, + + /** + * This permission is required to change the node that this BdrvChild + * points to. + */ + BLK_PERM_GRAPH_MOD =3D 0x10, + + BLK_PERM_ALL =3D 0x1f, +}; + /* disk I/O throttling */ void bdrv_init(void); void bdrv_init_with_whitelist(void); --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 14876918142429.29493876842082; Tue, 21 Feb 2017 07:43:34 -0800 (PST) Received: from localhost ([::1]:46426 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCbC-0007q1-QJ for importer@patchew.org; Tue, 21 Feb 2017 10:43:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuY-0008Vd-Rd for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuS-0007sB-P7 for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32826) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuQ-0007pe-86; Tue, 21 Feb 2017 09:59:18 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 4750EC0703A6; Tue, 21 Feb 2017 14:59:18 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwucv030565; Tue, 21 Feb 2017 09:59:16 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:09 +0100 Message-Id: <1487689130-30373-14-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 21 Feb 2017 14:59:18 +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 13/54] block: Add Error argument to bdrv_attach_child() 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" It will have to return an error soon, so prepare the callers for it. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 16 +++++++++++++--- block/quorum.c | 9 ++++++++- include/block/block.h | 3 ++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/block.c b/block.c index e166fe8..b2b6be0 100644 --- a/block.c +++ b/block.c @@ -1368,7 +1368,8 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *c= hild_bs, BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, BlockDriverState *child_bs, const char *child_name, - const BdrvChildRole *child_role) + const BdrvChildRole *child_role, + Error **errp) { BdrvChild *child =3D bdrv_root_attach_child(child_bs, child_name, chil= d_role, parent_bs); @@ -1469,7 +1470,9 @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockD= riverState *backing_hd) bs->backing =3D NULL; goto out; } - bs->backing =3D bdrv_attach_child(bs, backing_hd, "backing", &child_ba= cking); + /* FIXME Error handling */ + bs->backing =3D bdrv_attach_child(bs, backing_hd, "backing", &child_ba= cking, + &error_abort); bs->open_flags &=3D ~BDRV_O_NO_BACKING; pstrcpy(bs->backing_file, sizeof(bs->backing_file), backing_hd->filena= me); pstrcpy(bs->backing_format, sizeof(bs->backing_format), @@ -1648,6 +1651,7 @@ BdrvChild *bdrv_open_child(const char *filename, const BdrvChildRole *child_role, bool allow_none, Error **errp) { + BdrvChild *c; BlockDriverState *bs; =20 bs =3D bdrv_open_child_bs(filename, options, bdref_key, parent, child_= role, @@ -1656,7 +1660,13 @@ BdrvChild *bdrv_open_child(const char *filename, return NULL; } =20 - return bdrv_attach_child(parent, bs, bdref_key, child_role); + c =3D bdrv_attach_child(parent, bs, bdref_key, child_role, errp); + if (!c) { + bdrv_unref(bs); + return NULL; + } + + return c; } =20 static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs, diff --git a/block/quorum.c b/block/quorum.c index 86e2072..bdbcec6 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1032,10 +1032,17 @@ static void quorum_add_child(BlockDriverState *bs, = BlockDriverState *child_bs, =20 /* We can safely add the child now */ bdrv_ref(child_bs); - child =3D bdrv_attach_child(bs, child_bs, indexstr, &child_format); + + child =3D bdrv_attach_child(bs, child_bs, indexstr, &child_format, err= p); + if (child =3D=3D NULL) { + s->next_child_index--; + bdrv_unref(child_bs); + goto out; + } s->children =3D g_renew(BdrvChild *, s->children, s->num_children + 1); s->children[s->num_children++] =3D child; =20 +out: bdrv_drained_end(bs); } =20 diff --git a/include/block/block.h b/include/block/block.h index ac40c8d..2d6ed7d 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -519,7 +519,8 @@ void bdrv_unref_child(BlockDriverState *parent, BdrvChi= ld *child); BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, BlockDriverState *child_bs, const char *child_name, - const BdrvChildRole *child_role); + const BdrvChildRole *child_role, + Error **errp); =20 bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp= ); void bdrv_op_block(BlockDriverState *bs, BlockOpType op, Error *reason); --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487692423688250.65505336854687; Tue, 21 Feb 2017 07:53:43 -0800 (PST) Received: from localhost ([::1]:46479 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCl1-0000QT-Sk for importer@patchew.org; Tue, 21 Feb 2017 10:53:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42841) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuZ-00006F-Sy for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuU-0007t8-V0 for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48204) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuR-0007qb-IU; Tue, 21 Feb 2017 09:59:19 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 9681F64A42; Tue, 21 Feb 2017 14:59:19 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwucw030565; Tue, 21 Feb 2017 09:59:18 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:10 +0100 Message-Id: <1487689130-30373-15-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 21 Feb 2017 14:59:19 +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 14/54] block: Let callers request permissions when attaching a child node 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" When attaching a node as a child to a new parent, the required and shared permissions for this parent are checked against all other parents of the node now, and an error is returned if there is a conflict. This allows error returns to a function that previously always succeeded, and the same is true for quite a few callers and their callers. Converting all of them within the same patch would be too much, so for now everyone tells that they don't need any permissions and allow everyone else to do anything. This way we can use &error_abort initially and convert caller by caller to pass actual permission requirements and implement error handling. All these places are marked with FIXME comments and it will be the job of the next patches to clean them up again. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 66 +++++++++++++++++++++++++++++++++++++++++--= ---- block/block-backend.c | 8 ++++-- include/block/block_int.h | 15 ++++++++++- 3 files changed, 78 insertions(+), 11 deletions(-) diff --git a/block.c b/block.c index b2b6be0..d9f2267 100644 --- a/block.c +++ b/block.c @@ -1326,6 +1326,38 @@ static int bdrv_fill_options(QDict **options, const = char *filename, return 0; } =20 +static int bdrv_check_update_perm(BlockDriverState *bs, uint64_t new_used_= perm, + uint64_t new_shared_perm, + BdrvChild *ignore_child, Error **errp) +{ + BdrvChild *c; + + /* There is no reason why anyone couldn't tolerate write_unchanged */ + assert(new_shared_perm & BLK_PERM_WRITE_UNCHANGED); + + QLIST_FOREACH(c, &bs->parents, next_parent) { + if (c =3D=3D ignore_child) { + continue; + } + + if ((new_used_perm & c->shared_perm) !=3D new_used_perm || + (c->perm & new_shared_perm) !=3D c->perm) + { + const char *user =3D NULL; + if (c->role->get_name) { + user =3D c->role->get_name(c); + if (user && !*user) { + user =3D NULL; + } + } + error_setg(errp, "Conflicts with %s", user ?: "another operati= on"); + return -EPERM; + } + } + + return 0; +} + static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs) { BlockDriverState *old_bs =3D child->bs; @@ -1350,14 +1382,25 @@ static void bdrv_replace_child(BdrvChild *child, Bl= ockDriverState *new_bs) BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, const char *child_name, const BdrvChildRole *child_role, - void *opaque) + uint64_t perm, uint64_t shared_perm, + void *opaque, Error **errp) { - BdrvChild *child =3D g_new(BdrvChild, 1); + BdrvChild *child; + int ret; + + ret =3D bdrv_check_update_perm(child_bs, perm, shared_perm, NULL, errp= ); + if (ret < 0) { + return NULL; + } + + child =3D g_new(BdrvChild, 1); *child =3D (BdrvChild) { - .bs =3D NULL, - .name =3D g_strdup(child_name), - .role =3D child_role, - .opaque =3D opaque, + .bs =3D NULL, + .name =3D g_strdup(child_name), + .role =3D child_role, + .perm =3D perm, + .shared_perm =3D shared_perm, + .opaque =3D opaque, }; =20 bdrv_replace_child(child, child_bs); @@ -1371,8 +1414,15 @@ BdrvChild *bdrv_attach_child(BlockDriverState *paren= t_bs, const BdrvChildRole *child_role, Error **errp) { - BdrvChild *child =3D bdrv_root_attach_child(child_bs, child_name, chil= d_role, - parent_bs); + BdrvChild *child; + + /* FIXME Use real permissions */ + child =3D bdrv_root_attach_child(child_bs, child_name, child_role, + 0, BLK_PERM_ALL, parent_bs, errp); + if (child =3D=3D NULL) { + return NULL; + } + QLIST_INSERT_HEAD(&parent_bs->children, child, next); return child; } diff --git a/block/block-backend.c b/block/block-backend.c index 492e71e..9bb4528 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -163,7 +163,9 @@ BlockBackend *blk_new_open(const char *filename, const = char *reference, return NULL; } =20 - blk->root =3D bdrv_root_attach_child(bs, "root", &child_root, blk); + /* FIXME Use real permissions */ + blk->root =3D bdrv_root_attach_child(bs, "root", &child_root, + 0, BLK_PERM_ALL, blk, &error_abort); =20 return blk; } @@ -498,7 +500,9 @@ void blk_remove_bs(BlockBackend *blk) void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs) { bdrv_ref(bs); - blk->root =3D bdrv_root_attach_child(bs, "root", &child_root, blk); + /* FIXME Use real permissions */ + blk->root =3D bdrv_root_attach_child(bs, "root", &child_root, + 0, BLK_PERM_ALL, blk, &error_abort); =20 notifier_list_notify(&blk->insert_bs_notifiers, blk); if (blk->public.throttle_state) { diff --git a/include/block/block_int.h b/include/block/block_int.h index 1670941..ed63bad 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -419,6 +419,18 @@ struct BdrvChild { char *name; const BdrvChildRole *role; void *opaque; + + /** + * Granted permissions for operating on this BdrvChild (BLK_PERM_* bit= mask) + */ + uint64_t perm; + + /** + * Permissions that can still be granted to other users of @bs while t= his + * BdrvChild is still attached to it. (BLK_PERM_* bitmask) + */ + uint64_t shared_perm; + QLIST_ENTRY(BdrvChild) next; QLIST_ENTRY(BdrvChild) next_parent; }; @@ -796,7 +808,8 @@ void hmp_drive_add_node(Monitor *mon, const char *optst= r); BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, const char *child_name, const BdrvChildRole *child_role, - void *opaque); + uint64_t perm, uint64_t shared_perm, + void *opaque, Error **errp); void bdrv_root_unref_child(BdrvChild *child); =20 const char *bdrv_get_parent_name(const BlockDriverState *bs); --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487691885591858.1370897103033; Tue, 21 Feb 2017 07:44:45 -0800 (PST) Received: from localhost ([::1]:46429 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCcN-0000gT-S6 for importer@patchew.org; Tue, 21 Feb 2017 10:44:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42901) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBub-0000Ds-R9 for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBua-0007vL-2L for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49684) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuS-0007rw-SZ; Tue, 21 Feb 2017 09:59:21 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 E91904DAF7; Tue, 21 Feb 2017 14:59:20 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwucx030565; Tue, 21 Feb 2017 09:59:19 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:11 +0100 Message-Id: <1487689130-30373-16-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 21 Feb 2017 14:59:20 +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 15/54] block: Involve block drivers in permission granting 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" In many cases, the required permissions of one node on its children depends on what its parents require from it. For example, the raw format or most filter drivers only need to request consistent reads if that's something that one of their parents wants. In order to achieve this, this patch introduces two new BlockDriver callbacks. The first one lets drivers first check (recursively) whether the requested permissions can be set; the second one actually sets the new permission bitmask. Also add helper functions that drivers can use in their implementation of the callbacks to update their permissions on a specific child. Signed-off-by: Kevin Wolf --- block.c | 176 ++++++++++++++++++++++++++++++++++++++++++= ++++ include/block/block_int.h | 61 ++++++++++++++++ 2 files changed, 237 insertions(+) diff --git a/block.c b/block.c index d9f2267..2a86781 100644 --- a/block.c +++ b/block.c @@ -1326,11 +1326,145 @@ static int bdrv_fill_options(QDict **options, cons= t char *filename, return 0; } =20 +/* + * Check whether permissions on this node can be changed in a way that + * @cumulative_perms and @cumulative_shared_perms are the new cumulative + * permissions of all its parents. This involves checking whether all nece= ssary + * permission changes to child nodes can be performed. + * + * A call to this function must always be followed by a call to bdrv_set_p= erm() + * or bdrv_abort_perm_update(). + */ +static int bdrv_check_perm(BlockDriverState *bs, uint64_t cumulative_perms, + uint64_t cumulative_shared_perms, Error **errp) +{ + BlockDriver *drv =3D bs->drv; + BdrvChild *c; + int ret; + + if (!drv) { + error_setg(errp, "Block node is not opened"); + return -EINVAL; + } + + /* Write permissions never work with read-only images */ + if ((cumulative_perms & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED)) && + bdrv_is_read_only(bs)) + { + error_setg(errp, "Block node is read-only"); + return -EPERM; + } + + /* Check this node */ + if (drv->bdrv_check_perm) { + return drv->bdrv_check_perm(bs, cumulative_perms, + cumulative_shared_perms, errp); + } + + /* Drivers may not have .bdrv_child_perm() */ + if (!drv->bdrv_child_perm) { + return 0; + } + + /* Check all children */ + QLIST_FOREACH(c, &bs->children, next) { + uint64_t cur_perm, cur_shared; + drv->bdrv_child_perm(bs, c, c->role, + cumulative_perms, cumulative_shared_perms, + &cur_perm, &cur_shared); + ret =3D bdrv_child_check_perm(c, cur_perm, cur_shared, errp); + if (ret < 0) { + return ret; + } + } + + return 0; +} + +/* + * Notifies drivers that after a previous bdrv_check_perm() call, the + * permission update is not performed and any preparations made for it (e.= g. + * taken file locks) need to be undone. + * + * This function recursively notifies all child nodes. + */ +static void bdrv_abort_perm_update(BlockDriverState *bs) +{ + BlockDriver *drv =3D bs->drv; + BdrvChild *c; + + if (!drv) { + return; + } + + if (drv->bdrv_abort_perm_update) { + drv->bdrv_abort_perm_update(bs); + } + + QLIST_FOREACH(c, &bs->children, next) { + bdrv_abort_perm_update(c->bs); + } +} + +static void bdrv_set_perm(BlockDriverState *bs, uint64_t cumulative_perms, + uint64_t cumulative_shared_perms) +{ + BlockDriver *drv =3D bs->drv; + BdrvChild *c; + + if (!drv) { + return; + } + + /* Update this node */ + if (drv->bdrv_set_perm) { + drv->bdrv_set_perm(bs, cumulative_perms, cumulative_shared_perms); + } + + /* Drivers may not have .bdrv_child_perm() */ + if (!drv->bdrv_child_perm) { + return; + } + + /* Update all children */ + QLIST_FOREACH(c, &bs->children, next) { + uint64_t cur_perm, cur_shared; + drv->bdrv_child_perm(bs, c, c->role, + cumulative_perms, cumulative_shared_perms, + &cur_perm, &cur_shared); + bdrv_child_set_perm(c, cur_perm, cur_shared); + } +} + +static void bdrv_update_perm(BlockDriverState *bs) +{ + BdrvChild *c; + uint64_t cumulative_perms =3D 0; + uint64_t cumulative_shared_perms =3D BLK_PERM_ALL; + + QLIST_FOREACH(c, &bs->parents, next_parent) { + cumulative_perms |=3D c->perm; + cumulative_shared_perms &=3D c->shared_perm; + } + + bdrv_set_perm(bs, cumulative_perms, cumulative_shared_perms); +} + +/* + * Checks whether a new reference to @bs can be added if the new user requ= ires + * @new_used_perm/@new_shared_perm as its permissions. If @ignore_child is= set, + * this old reference is ignored in the calculations; this allows checking + * permission updates for an existing reference. + * + * Needs to be followed by a call to either bdrv_set_perm() or + * bdrv_abort_perm_update(). */ static int bdrv_check_update_perm(BlockDriverState *bs, uint64_t new_used_= perm, uint64_t new_shared_perm, BdrvChild *ignore_child, Error **errp) { BdrvChild *c; + uint64_t cumulative_perms =3D new_used_perm; + uint64_t cumulative_shared_perms =3D new_shared_perm; =20 /* There is no reason why anyone couldn't tolerate write_unchanged */ assert(new_shared_perm & BLK_PERM_WRITE_UNCHANGED); @@ -1353,8 +1487,47 @@ static int bdrv_check_update_perm(BlockDriverState *= bs, uint64_t new_used_perm, error_setg(errp, "Conflicts with %s", user ?: "another operati= on"); return -EPERM; } + + cumulative_perms |=3D c->perm; + cumulative_shared_perms &=3D c->shared_perm; + } + + return bdrv_check_perm(bs, cumulative_perms, cumulative_shared_perms, = errp); +} + +/* Needs to be followed by a call to either bdrv_set_perm() or + * bdrv_abort_perm_update(). */ +int bdrv_child_check_perm(BdrvChild *c, uint64_t perm, uint64_t shared, + Error **errp) +{ + return bdrv_check_update_perm(c->bs, perm, shared, c, errp); +} + +void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared) +{ + c->perm =3D perm; + c->shared_perm =3D shared; + bdrv_update_perm(c->bs); +} + +void bdrv_child_abort_perm_update(BdrvChild *c) +{ + bdrv_abort_perm_update(c->bs); +} + +int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, + Error **errp) +{ + int ret; + + ret =3D bdrv_child_check_perm(c, perm, shared, errp); + if (ret < 0) { + bdrv_child_abort_perm_update(c); + return ret; } =20 + bdrv_child_set_perm(c, perm, shared); + return 0; } =20 @@ -1367,6 +1540,7 @@ static void bdrv_replace_child(BdrvChild *child, Bloc= kDriverState *new_bs) child->role->drained_end(child); } QLIST_REMOVE(child, next_parent); + bdrv_update_perm(old_bs); } =20 child->bs =3D new_bs; @@ -1376,6 +1550,7 @@ static void bdrv_replace_child(BdrvChild *child, Bloc= kDriverState *new_bs) if (new_bs->quiesce_counter && child->role->drained_begin) { child->role->drained_begin(child); } + bdrv_update_perm(new_bs); } } =20 @@ -1390,6 +1565,7 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *c= hild_bs, =20 ret =3D bdrv_check_update_perm(child_bs, perm, shared_perm, NULL, errp= ); if (ret < 0) { + bdrv_abort_perm_update(child_bs); return NULL; } =20 diff --git a/include/block/block_int.h b/include/block/block_int.h index ed63bad..cef2b6e 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -320,6 +320,59 @@ struct BlockDriver { void (*bdrv_del_child)(BlockDriverState *parent, BdrvChild *child, Error **errp); =20 + /** + * Informs the block driver that a permission change is intended. The + * driver checks whether the change is permissible and may take other + * preparations for the change (e.g. get file system locks). This oper= ation + * is always followed either by a call to either .bdrv_set_perm or + * .bdrv_abort_perm_update. + * + * Checks whether the requested set of cumulative permissions in @perm + * can be granted for accessing @bs and whether no other users are usi= ng + * permissions other than those given in @shared (both arguments take + * BLK_PERM_* bitmasks). + * + * If both conditions are met, 0 is returned. Otherwise, -errno is ret= urned + * and errp is set to an error describing the conflict. + */ + int (*bdrv_check_perm)(BlockDriverState *bs, uint64_t perm, + uint64_t shared, Error **errp); + + /** + * Called to inform the driver that the set of cumulative set of used + * permissions for @bs has changed to @perm, and the set of sharable + * permission to @shared. The driver can use this to propagate changes= to + * its children (i.e. request permissions only if a parent actually ne= eds + * them). + * + * This function is only invoked after bdrv_check_perm(), so block dri= vers + * may rely on preparations made in their .bdrv_check_perm implementat= ion. + */ + void (*bdrv_set_perm)(BlockDriverState *bs, uint64_t perm, uint64_t sh= ared); + + /* + * Called to inform the driver that after a previous bdrv_check_perm() + * call, the permission update is not performed and any preparations m= ade + * for it (e.g. taken file locks) need to be undone. + * + * This function can be called even for nodes that never saw a + * bdrv_check_perm() call. It is a no-op then. + */ + void (*bdrv_abort_perm_update)(BlockDriverState *bs); + + /** + * Returns in @nperm and @nshared the permissions that the driver for = @bs + * needs on its child @c, based on the cumulative permissions requeste= d by + * the parents in @parent_perm and @parent_shared. + * + * If @c is NULL, return the permissions for attaching a new child for= the + * given @role. + */ + void (*bdrv_child_perm)(BlockDriverState *bs, BdrvChild *c, + const BdrvChildRole *role, + uint64_t parent_perm, uint64_t parent_shared, + uint64_t *nperm, uint64_t *nshared); + QLIST_ENTRY(BlockDriver) list; }; =20 @@ -812,6 +865,14 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *ch= ild_bs, void *opaque, Error **errp); void bdrv_root_unref_child(BdrvChild *child); =20 +int bdrv_child_check_perm(BdrvChild *c, uint64_t perm, uint64_t shared, + Error **errp); +void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared); +void bdrv_child_abort_perm_update(BdrvChild *c); +int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, + Error **errp); + + const char *bdrv_get_parent_name(const BlockDriverState *bs); void blk_dev_change_media_cb(BlockBackend *blk, bool load); bool blk_dev_has_removable_media(BlockBackend *blk); --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487692102432868.3313897863316; Tue, 21 Feb 2017 07:48:22 -0800 (PST) Received: from localhost ([::1]:46452 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCfq-0003qj-Ru for importer@patchew.org; Tue, 21 Feb 2017 10:48:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42876) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBub-0000Am-5w for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBua-0007vQ-23 for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49724) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuU-0007sg-Ki; Tue, 21 Feb 2017 09:59:22 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 6DC22824; Tue, 21 Feb 2017 14:59:22 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwud0030565; Tue, 21 Feb 2017 09:59:21 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:12 +0100 Message-Id: <1487689130-30373-17-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 21 Feb 2017 14:59:22 +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 16/54] block: Default .bdrv_child_perm() for filter drivers 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" Most filters need permissions related to read and write for their children, but only if the node has a parent that wants to use the same operation on the filter. The same is true for resize. This adds a default implementation that simply forwards all necessary permissions to all children of the node and leaves the other permissions unchanged. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 24 ++++++++++++++++++++++++ include/block/block_int.h | 8 ++++++++ 2 files changed, 32 insertions(+) diff --git a/block.c b/block.c index 2a86781..523cbd3 100644 --- a/block.c +++ b/block.c @@ -1531,6 +1531,30 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t p= erm, uint64_t shared, return 0; } =20 +#define DEFAULT_PERM_PASSTHROUGH (BLK_PERM_CONSISTENT_READ \ + | BLK_PERM_WRITE \ + | BLK_PERM_WRITE_UNCHANGED \ + | BLK_PERM_RESIZE) +#define DEFAULT_PERM_UNCHANGED (BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH) + +void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, + const BdrvChildRole *role, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) +{ + if (c =3D=3D NULL) { + *nperm =3D 0; + *nshared =3D BLK_PERM_ALL; + return; + } + + *nperm =3D (perm & DEFAULT_PERM_PASSTHROUGH) | + (c->perm & DEFAULT_PERM_UNCHANGED); + *nshared =3D (shared & DEFAULT_PERM_PASSTHROUGH) | + (c->shared_perm & DEFAULT_PERM_UNCHANGED); +} + + static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs) { BlockDriverState *old_bs =3D child->bs; diff --git a/include/block/block_int.h b/include/block/block_int.h index cef2b6e..17f4c2d 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -872,6 +872,14 @@ void bdrv_child_abort_perm_update(BdrvChild *c); int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, Error **errp); =20 +/* Default implementation for BlockDriver.bdrv_child_perm() that can be us= ed by + * block filters: Forward CONSISTENT_READ, WRITE, WRITE_UNCHANGED and RESI= ZE to + * all children */ +void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, + const BdrvChildRole *role, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared); + =20 const char *bdrv_get_parent_name(const BlockDriverState *bs); void blk_dev_change_media_cb(BlockBackend *blk, bool load); --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487692391138314.9500081137619; Tue, 21 Feb 2017 07:53:11 -0800 (PST) Received: from localhost ([::1]:46478 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCkX-0008Qu-FE for importer@patchew.org; Tue, 21 Feb 2017 10:53:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42907) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuc-0000Eb-4D for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBub-0007vx-5N for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34224) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuW-0007tI-1i; Tue, 21 Feb 2017 09:59:24 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 1EA9DC04B320; Tue, 21 Feb 2017 14:59:24 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwud1030565; Tue, 21 Feb 2017 09:59:22 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:13 +0100 Message-Id: <1487689130-30373-18-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 21 Feb 2017 14:59:24 +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 17/54] block: Request child permissions in filter drivers 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" All callers will have to request permissions for all of their child nodes. Block drivers that act as simply filters can use the default implementation of .bdrv_child_perm(). Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/blkdebug.c | 2 ++ block/blkreplay.c | 1 + block/blkverify.c | 1 + block/quorum.c | 2 ++ block/raw-format.c | 1 + block/replication.c | 1 + 6 files changed, 8 insertions(+) diff --git a/block/blkdebug.c b/block/blkdebug.c index 6117ce5..67e8024 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -734,6 +734,8 @@ static BlockDriver bdrv_blkdebug =3D { .bdrv_file_open =3D blkdebug_open, .bdrv_close =3D blkdebug_close, .bdrv_reopen_prepare =3D blkdebug_reopen_prepare, + .bdrv_child_perm =3D bdrv_filter_default_perms, + .bdrv_getlength =3D blkdebug_getlength, .bdrv_truncate =3D blkdebug_truncate, .bdrv_refresh_filename =3D blkdebug_refresh_filename, diff --git a/block/blkreplay.c b/block/blkreplay.c index cfc8c5b..e110211 100755 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -137,6 +137,7 @@ static BlockDriver bdrv_blkreplay =3D { =20 .bdrv_file_open =3D blkreplay_open, .bdrv_close =3D blkreplay_close, + .bdrv_child_perm =3D bdrv_filter_default_perms, .bdrv_getlength =3D blkreplay_getlength, =20 .bdrv_co_preadv =3D blkreplay_co_preadv, diff --git a/block/blkverify.c b/block/blkverify.c index 43a940c..9a1e21c 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -320,6 +320,7 @@ static BlockDriver bdrv_blkverify =3D { .bdrv_parse_filename =3D blkverify_parse_filename, .bdrv_file_open =3D blkverify_open, .bdrv_close =3D blkverify_close, + .bdrv_child_perm =3D bdrv_filter_default_perms, .bdrv_getlength =3D blkverify_getlength, .bdrv_refresh_filename =3D blkverify_refresh_filename, =20 diff --git a/block/quorum.c b/block/quorum.c index bdbcec6..40205fb 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1133,6 +1133,8 @@ static BlockDriver bdrv_quorum =3D { .bdrv_add_child =3D quorum_add_child, .bdrv_del_child =3D quorum_del_child, =20 + .bdrv_child_perm =3D bdrv_filter_default_perms, + .is_filter =3D true, .bdrv_recurse_is_first_non_filter =3D quorum_recurse_is_first_non_fi= lter, }; diff --git a/block/raw-format.c b/block/raw-format.c index ce34d1b..86fbc65 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -467,6 +467,7 @@ BlockDriver bdrv_raw =3D { .bdrv_reopen_abort =3D &raw_reopen_abort, .bdrv_open =3D &raw_open, .bdrv_close =3D &raw_close, + .bdrv_child_perm =3D bdrv_filter_default_perms, .bdrv_create =3D &raw_create, .bdrv_co_preadv =3D &raw_co_preadv, .bdrv_co_pwritev =3D &raw_co_pwritev, diff --git a/block/replication.c b/block/replication.c index eff85c7..91465cb 100644 --- a/block/replication.c +++ b/block/replication.c @@ -660,6 +660,7 @@ BlockDriver bdrv_replication =3D { =20 .bdrv_open =3D replication_open, .bdrv_close =3D replication_close, + .bdrv_child_perm =3D bdrv_filter_default_perms, =20 .bdrv_getlength =3D replication_getlength, .bdrv_co_readv =3D replication_co_readv, --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 148768992494253.83595977845346; Tue, 21 Feb 2017 07:12:04 -0800 (PST) Received: from localhost ([::1]:46211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgC6i-0002Zl-9A for importer@patchew.org; Tue, 21 Feb 2017 10:12:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42913) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuc-0000GE-Et for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBub-0007wA-Be for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34240) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuX-0007tl-ES; Tue, 21 Feb 2017 09:59:25 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 7C306C04B320; Tue, 21 Feb 2017 14:59:25 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwud2030565; Tue, 21 Feb 2017 09:59:24 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:14 +0100 Message-Id: <1487689130-30373-19-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 21 Feb 2017 14:59:25 +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 18/54] block: Default .bdrv_child_perm() for format drivers 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" Almost all format drivers have the same characteristics as far as permissions are concerned: They have one or more children for storing their own data and, more importantly, metadata (can be written to and grow even without external write requests, must be protected against other writers and present consistent data) and optionally a backing file (this is just data, so like for a filter, it only depends on what the parent nodes need). This provides a default implementation that can be shared by most of our format drivers. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/block/block_int.h | 8 ++++++++ 2 files changed, 50 insertions(+) diff --git a/block.c b/block.c index 523cbd3..f2e7178 100644 --- a/block.c +++ b/block.c @@ -1554,6 +1554,48 @@ void bdrv_filter_default_perms(BlockDriverState *bs,= BdrvChild *c, (c->shared_perm & DEFAULT_PERM_UNCHANGED); } =20 +void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, + const BdrvChildRole *role, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) +{ + bool backing =3D (role =3D=3D &child_backing); + assert(role =3D=3D &child_backing || role =3D=3D &child_file); + + if (!backing) { + /* Apart from the modifications below, the same permissions are + * forwarded and left alone as for filters */ + bdrv_filter_default_perms(bs, c, role, perm, shared, &perm, &share= d); + + /* Format drivers may touch metadata even if the guest doesn't wri= te */ + if (!bdrv_is_read_only(bs)) { + perm |=3D BLK_PERM_WRITE | BLK_PERM_RESIZE; + } + + /* bs->file always needs to be consistent because of the metadata.= We + * can never allow other users to resize or write to it. */ + perm |=3D BLK_PERM_CONSISTENT_READ; + shared &=3D ~(BLK_PERM_WRITE | BLK_PERM_RESIZE); + } else { + /* We want consistent read from backing files if the parent needs = it. + * No other operations are performed on backing files. */ + perm &=3D BLK_PERM_CONSISTENT_READ; + + /* If the parent can deal with changing data, we're okay with a + * writable and resizable backing file. */ + if (shared & BLK_PERM_WRITE) { + shared =3D BLK_PERM_WRITE | BLK_PERM_RESIZE; + } else { + shared =3D 0; + } + + shared |=3D BLK_PERM_CONSISTENT_READ | BLK_PERM_GRAPH_MOD | + BLK_PERM_WRITE_UNCHANGED; + } + + *nperm =3D perm; + *nshared =3D shared; +} =20 static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs) { diff --git a/include/block/block_int.h b/include/block/block_int.h index 17f4c2d..eb0598e 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -880,6 +880,14 @@ void bdrv_filter_default_perms(BlockDriverState *bs, B= drvChild *c, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared); =20 +/* Default implementation for BlockDriver.bdrv_child_perm() that can be us= ed by + * (non-raw) image formats: Like above for bs->backing, but for bs->file it + * requires WRITE | RESIZE for read-write images, always requires + * CONSISTENT_READ and doesn't share WRITE. */ +void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, + const BdrvChildRole *role, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared); =20 const char *bdrv_get_parent_name(const BlockDriverState *bs); void blk_dev_change_media_cb(BlockBackend *blk, bool load); --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487690186260267.5859054521553; Tue, 21 Feb 2017 07:16:26 -0800 (PST) Received: from localhost ([::1]:46240 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCAu-00074L-Hr for importer@patchew.org; Tue, 21 Feb 2017 10:16:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42951) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBud-0000Lo-OL for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuc-0007wk-AC for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32944) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuY-0007uC-VK; Tue, 21 Feb 2017 09:59:27 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 0BD51C062D11; Tue, 21 Feb 2017 14:59:27 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwud3030565; Tue, 21 Feb 2017 09:59:25 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:15 +0100 Message-Id: <1487689130-30373-20-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 21 Feb 2017 14:59:27 +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 19/54] block: Request child permissions in format drivers 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" This makes use of the .bdrv_child_perm() implementation for formats that we just added. All format drivers expose the permissions they actually need nows, so that they can be set accordingly and updated when parents are attached or detached. The only format not included here is raw, which was already converted with the other filter drivers. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/bochs.c | 1 + block/cloop.c | 1 + block/crypto.c | 1 + block/dmg.c | 1 + block/parallels.c | 1 + block/qcow.c | 1 + block/qcow2.c | 1 + block/qed.c | 1 + block/vdi.c | 1 + block/vhdx.c | 1 + block/vmdk.c | 1 + block/vpc.c | 1 + 12 files changed, 12 insertions(+) diff --git a/block/bochs.c b/block/bochs.c index 7dd2ac4..516da56 100644 --- a/block/bochs.c +++ b/block/bochs.c @@ -293,6 +293,7 @@ static BlockDriver bdrv_bochs =3D { .instance_size =3D sizeof(BDRVBochsState), .bdrv_probe =3D bochs_probe, .bdrv_open =3D bochs_open, + .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_refresh_limits =3D bochs_refresh_limits, .bdrv_co_preadv =3D bochs_co_preadv, .bdrv_close =3D bochs_close, diff --git a/block/cloop.c b/block/cloop.c index 877c9b0..a6c7b9d 100644 --- a/block/cloop.c +++ b/block/cloop.c @@ -290,6 +290,7 @@ static BlockDriver bdrv_cloop =3D { .instance_size =3D sizeof(BDRVCloopState), .bdrv_probe =3D cloop_probe, .bdrv_open =3D cloop_open, + .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_refresh_limits =3D cloop_refresh_limits, .bdrv_co_preadv =3D cloop_co_preadv, .bdrv_close =3D cloop_close, diff --git a/block/crypto.c b/block/crypto.c index 7cb2ff2..4a20388 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -628,6 +628,7 @@ BlockDriver bdrv_crypto_luks =3D { .bdrv_probe =3D block_crypto_probe_luks, .bdrv_open =3D block_crypto_open_luks, .bdrv_close =3D block_crypto_close, + .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_create =3D block_crypto_create_luks, .bdrv_truncate =3D block_crypto_truncate, .create_opts =3D &block_crypto_create_opts_luks, diff --git a/block/dmg.c b/block/dmg.c index 8e387cd..a7d25fc 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -697,6 +697,7 @@ static BlockDriver bdrv_dmg =3D { .bdrv_probe =3D dmg_probe, .bdrv_open =3D dmg_open, .bdrv_refresh_limits =3D dmg_refresh_limits, + .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_co_preadv =3D dmg_co_preadv, .bdrv_close =3D dmg_close, }; diff --git a/block/parallels.c b/block/parallels.c index b2ec09f..6b0c0a9 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -762,6 +762,7 @@ static BlockDriver bdrv_parallels =3D { .bdrv_probe =3D parallels_probe, .bdrv_open =3D parallels_open, .bdrv_close =3D parallels_close, + .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_co_get_block_status =3D parallels_co_get_block_status, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_co_flush_to_os =3D parallels_co_flush_to_os, diff --git a/block/qcow.c b/block/qcow.c index 038b05a..eb5d54c 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -1052,6 +1052,7 @@ static BlockDriver bdrv_qcow =3D { .bdrv_probe =3D qcow_probe, .bdrv_open =3D qcow_open, .bdrv_close =3D qcow_close, + .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_reopen_prepare =3D qcow_reopen_prepare, .bdrv_create =3D qcow_create, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, diff --git a/block/qcow2.c b/block/qcow2.c index 21e6142..ef028f6 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3403,6 +3403,7 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_reopen_commit =3D qcow2_reopen_commit, .bdrv_reopen_abort =3D qcow2_reopen_abort, .bdrv_join_options =3D qcow2_join_options, + .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_create =3D qcow2_create, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_co_get_block_status =3D qcow2_co_get_block_status, diff --git a/block/qed.c b/block/qed.c index 62a0a09..d8f947a 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1704,6 +1704,7 @@ static BlockDriver bdrv_qed =3D { .bdrv_open =3D bdrv_qed_open, .bdrv_close =3D bdrv_qed_close, .bdrv_reopen_prepare =3D bdrv_qed_reopen_prepare, + .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_create =3D bdrv_qed_create, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_co_get_block_status =3D bdrv_qed_co_get_block_status, diff --git a/block/vdi.c b/block/vdi.c index 18b4773..fd6e26d 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -891,6 +891,7 @@ static BlockDriver bdrv_vdi =3D { .bdrv_open =3D vdi_open, .bdrv_close =3D vdi_close, .bdrv_reopen_prepare =3D vdi_reopen_prepare, + .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_create =3D vdi_create, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_co_get_block_status =3D vdi_co_get_block_status, diff --git a/block/vhdx.c b/block/vhdx.c index 9918ee9..ab747f6 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1983,6 +1983,7 @@ static BlockDriver bdrv_vhdx =3D { .bdrv_open =3D vhdx_open, .bdrv_close =3D vhdx_close, .bdrv_reopen_prepare =3D vhdx_reopen_prepare, + .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_co_readv =3D vhdx_co_readv, .bdrv_co_writev =3D vhdx_co_writev, .bdrv_create =3D vhdx_create, diff --git a/block/vmdk.c b/block/vmdk.c index 9d68ec5..f5e2fb5 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2359,6 +2359,7 @@ static BlockDriver bdrv_vmdk =3D { .bdrv_open =3D vmdk_open, .bdrv_check =3D vmdk_check, .bdrv_reopen_prepare =3D vmdk_reopen_prepare, + .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_co_preadv =3D vmdk_co_preadv, .bdrv_co_pwritev =3D vmdk_co_pwritev, .bdrv_co_pwritev_compressed =3D vmdk_co_pwritev_compressed, diff --git a/block/vpc.c b/block/vpc.c index d0df2a1..b9c9832 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -1067,6 +1067,7 @@ static BlockDriver bdrv_vpc =3D { .bdrv_open =3D vpc_open, .bdrv_close =3D vpc_close, .bdrv_reopen_prepare =3D vpc_reopen_prepare, + .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_create =3D vpc_create, =20 .bdrv_co_preadv =3D vpc_co_preadv, --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487692165603384.50513426547445; Tue, 21 Feb 2017 07:49:25 -0800 (PST) Received: from localhost ([::1]:46455 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCgt-0004eW-4N for importer@patchew.org; Tue, 21 Feb 2017 10:49:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42966) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBue-0000NI-AR for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBud-0007xD-B1 for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42434) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBua-0007vD-JO; Tue, 21 Feb 2017 09:59:28 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 A7064F44C8; Tue, 21 Feb 2017 14:59:28 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwud4030565; Tue, 21 Feb 2017 09:59:27 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:16 +0100 Message-Id: <1487689130-30373-21-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 21 Feb 2017 14:59:28 +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 20/54] vvfat: Implement .bdrv_child_perm() 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" vvfat is the last remaining driver that can have children, but doesn't implement .bdrv_child_perm() yet. The default handlers aren't suitable here, so let's implement a very simple driver-specific one that protects the internal child from being used by other users as good as our permissions permit. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 2 +- block/vvfat.c | 22 ++++++++++++++++++++++ include/block/block_int.h | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index f2e7178..6d1362e 100644 --- a/block.c +++ b/block.c @@ -823,7 +823,7 @@ static void bdrv_backing_options(int *child_flags, QDic= t *child_options, *child_flags =3D flags; } =20 -static const BdrvChildRole child_backing =3D { +const BdrvChildRole child_backing =3D { .inherit_options =3D bdrv_backing_options, .drained_begin =3D bdrv_child_cb_drained_begin, .drained_end =3D bdrv_child_cb_drained_end, diff --git a/block/vvfat.c b/block/vvfat.c index 7f230be..72b482c 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3052,6 +3052,27 @@ err: return ret; } =20 +static void vvfat_child_perm(BlockDriverState *bs, BdrvChild *c, + const BdrvChildRole *role, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) +{ + BDRVVVFATState *s =3D bs->opaque; + + assert(c =3D=3D s->qcow || role =3D=3D &child_backing); + + if (c =3D=3D s->qcow) { + /* This is a private node, nobody should try to attach to it */ + *nperm =3D BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE; + *nshared =3D BLK_PERM_WRITE_UNCHANGED; + } else { + /* The backing file is there so 'commit' can use it. vvfat doesn't + * access it in any way. */ + *nperm =3D 0; + *nshared =3D BLK_PERM_ALL; + } +} + static void vvfat_close(BlockDriverState *bs) { BDRVVVFATState *s =3D bs->opaque; @@ -3077,6 +3098,7 @@ static BlockDriver bdrv_vvfat =3D { .bdrv_file_open =3D vvfat_open, .bdrv_refresh_limits =3D vvfat_refresh_limits, .bdrv_close =3D vvfat_close, + .bdrv_child_perm =3D vvfat_child_perm, =20 .bdrv_co_preadv =3D vvfat_co_preadv, .bdrv_co_pwritev =3D vvfat_co_pwritev, diff --git a/include/block/block_int.h b/include/block/block_int.h index eb0598e..63d5446 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -466,6 +466,7 @@ struct BdrvChildRole { =20 extern const BdrvChildRole child_file; extern const BdrvChildRole child_format; +extern const BdrvChildRole child_backing; =20 struct BdrvChild { BlockDriverState *bs; --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487692688884983.0614483220489; Tue, 21 Feb 2017 07:58:08 -0800 (PST) Received: from localhost ([::1]:46503 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCpL-00055C-Lu for importer@patchew.org; Tue, 21 Feb 2017 10:58:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43003) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuf-0000Oy-HF for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBue-0007xo-FM for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47792) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuc-0007wE-22; Tue, 21 Feb 2017 09:59:30 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 1E52742BA3; Tue, 21 Feb 2017 14:59:30 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwud5030565; Tue, 21 Feb 2017 09:59:28 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:17 +0100 Message-Id: <1487689130-30373-22-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 21 Feb 2017 14:59:30 +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 21/54] block: Require .bdrv_child_perm() with child nodes 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" All block drivers that can have child nodes implement .bdrv_child_perm() now. Make this officially a requirement by asserting that only drivers without children can omit .bdrv_child_perm(). Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 6d1362e..1c5f211 100644 --- a/block.c +++ b/block.c @@ -1361,8 +1361,9 @@ static int bdrv_check_perm(BlockDriverState *bs, uint= 64_t cumulative_perms, cumulative_shared_perms, errp); } =20 - /* Drivers may not have .bdrv_child_perm() */ + /* Drivers that never have children can omit .bdrv_child_perm() */ if (!drv->bdrv_child_perm) { + assert(QLIST_EMPTY(&bs->children)); return 0; } =20 @@ -1421,8 +1422,9 @@ static void bdrv_set_perm(BlockDriverState *bs, uint6= 4_t cumulative_perms, drv->bdrv_set_perm(bs, cumulative_perms, cumulative_shared_perms); } =20 - /* Drivers may not have .bdrv_child_perm() */ + /* Drivers that never have children can omit .bdrv_child_perm() */ if (!drv->bdrv_child_perm) { + assert(QLIST_EMPTY(&bs->children)); return; } =20 --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487692661781915.6962487140278; Tue, 21 Feb 2017 07:57:41 -0800 (PST) Received: from localhost ([::1]:46502 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCou-0004bW-Gk for importer@patchew.org; Tue, 21 Feb 2017 10:57:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43061) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuk-0000Uk-C3 for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuf-0007yo-Qu for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59034) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBud-0007x4-IO; Tue, 21 Feb 2017 09:59:31 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 A45684E02B; Tue, 21 Feb 2017 14:59:31 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwud6030565; Tue, 21 Feb 2017 09:59:30 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:18 +0100 Message-Id: <1487689130-30373-23-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 21 Feb 2017 14:59:31 +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 22/54] block: Request real permissions in bdrv_attach_child() 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" Now that all block drivers with children tell us what permissions they need from each of their children, bdrv_attach_child() can use this information and make the right requirements while trying to attach new children. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 1c5f211..054e6f0 100644 --- a/block.c +++ b/block.c @@ -1659,10 +1659,14 @@ BdrvChild *bdrv_attach_child(BlockDriverState *pare= nt_bs, Error **errp) { BdrvChild *child; + uint64_t perm, shared_perm; + + assert(parent_bs->drv); + parent_bs->drv->bdrv_child_perm(parent_bs, NULL, child_role, + 0, BLK_PERM_ALL, &perm, &shared_perm); =20 - /* FIXME Use real permissions */ child =3D bdrv_root_attach_child(child_bs, child_name, child_role, - 0, BLK_PERM_ALL, parent_bs, errp); + perm, shared_perm, parent_bs, errp); if (child =3D=3D NULL) { return NULL; } --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 148769046439210.10530308322393; Tue, 21 Feb 2017 07:21:04 -0800 (PST) Received: from localhost ([::1]:46266 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCFQ-00035p-RU for importer@patchew.org; Tue, 21 Feb 2017 10:21:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43123) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBum-0000XG-KO for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBul-00082K-Og for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33018) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuf-0007y1-80; Tue, 21 Feb 2017 09:59:33 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 39925C06C9F7; Tue, 21 Feb 2017 14:59:33 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwud7030565; Tue, 21 Feb 2017 09:59:31 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:19 +0100 Message-Id: <1487689130-30373-24-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 21 Feb 2017 14:59:33 +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 23/54] block: Add permissions to BlockBackend 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 BlockBackend can now store the permissions that its user requires. This is necessary because nodes can be ejected from or inserted into a BlockBackend and all of these operations must make sure that the user still gets what it requested initially. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/block-backend.c | 27 +++++++++++++++++++++++++++ include/sysemu/block-backend.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 9bb4528..1ed75c6 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -59,6 +59,9 @@ struct BlockBackend { bool iostatus_enabled; BlockDeviceIoStatus iostatus; =20 + uint64_t perm; + uint64_t shared_perm; + bool allow_write_beyond_eof; =20 NotifierList remove_bs_notifiers, insert_bs_notifiers; @@ -126,6 +129,8 @@ BlockBackend *blk_new(void) =20 blk =3D g_new0(BlockBackend, 1); blk->refcnt =3D 1; + blk->perm =3D 0; + blk->shared_perm =3D BLK_PERM_ALL; blk_set_enable_write_cache(blk, true); =20 qemu_co_queue_init(&blk->public.throttled_reqs[0]); @@ -511,6 +516,27 @@ void blk_insert_bs(BlockBackend *blk, BlockDriverState= *bs) } } =20 +/* + * Sets the permission bitmasks that the user of the BlockBackend needs. + */ +int blk_set_perm(BlockBackend *blk, uint64_t perm, uint64_t shared_perm, + Error **errp) +{ + int ret; + + if (blk->root) { + ret =3D bdrv_child_try_set_perm(blk->root, perm, shared_perm, errp= ); + if (ret < 0) { + return ret; + } + } + + blk->perm =3D perm; + blk->shared_perm =3D shared_perm; + + return 0; +} + static int blk_do_attach_dev(BlockBackend *blk, void *dev) { if (blk->dev) { @@ -557,6 +583,7 @@ void blk_detach_dev(BlockBackend *blk, void *dev) blk->dev_ops =3D NULL; blk->dev_opaque =3D NULL; blk->guest_block_size =3D 512; + blk_set_perm(blk, 0, BLK_PERM_ALL, &error_abort); blk_unref(blk); } =20 diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index f365a51..4a18e86 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -105,6 +105,8 @@ void blk_remove_bs(BlockBackend *blk); void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs); bool bdrv_has_blk(BlockDriverState *bs); bool bdrv_is_root_node(BlockDriverState *bs); +int blk_set_perm(BlockBackend *blk, uint64_t perm, uint64_t shared_perm, + Error **errp); =20 void blk_set_allow_write_beyond_eof(BlockBackend *blk, bool allow); void blk_iostatus_enable(BlockBackend *blk); --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 148769247081929.07947575090361; Tue, 21 Feb 2017 07:54:30 -0800 (PST) Received: from localhost ([::1]:46481 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgClp-0001GU-E9 for importer@patchew.org; Tue, 21 Feb 2017 10:54:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43158) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuo-0000ZF-78 for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBum-00082s-Iq for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49870) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBug-0007yt-J3; Tue, 21 Feb 2017 09:59:34 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 9F5064DB14; Tue, 21 Feb 2017 14:59:34 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwud8030565; Tue, 21 Feb 2017 09:59:33 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:20 +0100 Message-Id: <1487689130-30373-25-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 21 Feb 2017 14:59:34 +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 24/54] block: Add permissions to blk_new() 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" We want every user to be specific about the permissions it needs, so we'll pass the initial permissions as parameters to blk_new(). A user only needs to call blk_set_perm() if it wants to change the permissions after the fact. The permissions are stored in the BlockBackend and applied whenever a BlockDriverState should be attached in blk_insert_bs(). This does not include actually choosing the right set of permissions everywhere yet. Instead, the usual FIXME comment is added to each place and will be addressed in individual patches. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 2 +- block/backup.c | 3 ++- block/block-backend.c | 21 ++++++++++++++------- block/commit.c | 12 ++++++++---- block/mirror.c | 3 ++- block/qcow2.c | 2 +- blockdev.c | 4 ++-- blockjob.c | 3 ++- hmp.c | 3 ++- hw/block/fdc.c | 3 ++- hw/core/qdev-properties-system.c | 3 ++- hw/ide/qdev.c | 3 ++- hw/scsi/scsi-disk.c | 3 ++- include/sysemu/block-backend.h | 2 +- migration/block.c | 3 ++- nbd/server.c | 3 ++- tests/test-blockjob.c | 3 ++- tests/test-throttle.c | 7 ++++--- 18 files changed, 53 insertions(+), 30 deletions(-) diff --git a/block.c b/block.c index 054e6f0..ed37d17 100644 --- a/block.c +++ b/block.c @@ -2170,7 +2170,7 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, goto fail; } if (file_bs !=3D NULL) { - file =3D blk_new(); + file =3D blk_new(BLK_PERM_CONSISTENT_READ, BLK_PERM_ALL); blk_insert_bs(file, file_bs); bdrv_unref(file_bs); =20 diff --git a/block/backup.c b/block/backup.c index fe010e7..4b3c94c 100644 --- a/block/backup.c +++ b/block/backup.c @@ -624,7 +624,8 @@ BlockJob *backup_job_create(const char *job_id, BlockDr= iverState *bs, goto error; } =20 - job->target =3D blk_new(); + /* FIXME Use real permissions */ + job->target =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(job->target, target); =20 job->on_source_error =3D on_source_error; diff --git a/block/block-backend.c b/block/block-backend.c index 1ed75c6..0319220 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -120,17 +120,23 @@ static const BdrvChildRole child_root =3D { =20 /* * Create a new BlockBackend with a reference count of one. - * Store an error through @errp on failure, unless it's null. + * + * @perm is a bitmasks of BLK_PERM_* constants which describes the permiss= ions + * to request for a block driver node that is attached to this BlockBacken= d. + * @shared_perm is a bitmask which describes which permissions may be gran= ted + * to other users of the attached node. + * Both sets of permissions can be changed later using blk_set_perm(). + * * Return the new BlockBackend on success, null on failure. */ -BlockBackend *blk_new(void) +BlockBackend *blk_new(uint64_t perm, uint64_t shared_perm) { BlockBackend *blk; =20 blk =3D g_new0(BlockBackend, 1); blk->refcnt =3D 1; - blk->perm =3D 0; - blk->shared_perm =3D BLK_PERM_ALL; + blk->perm =3D perm; + blk->shared_perm =3D shared_perm; blk_set_enable_write_cache(blk, true); =20 qemu_co_queue_init(&blk->public.throttled_reqs[0]); @@ -161,7 +167,7 @@ BlockBackend *blk_new_open(const char *filename, const = char *reference, BlockBackend *blk; BlockDriverState *bs; =20 - blk =3D blk_new(); + blk =3D blk_new(0, BLK_PERM_ALL); bs =3D bdrv_open(filename, reference, options, flags, errp); if (!bs) { blk_unref(blk); @@ -505,9 +511,10 @@ void blk_remove_bs(BlockBackend *blk) void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs) { bdrv_ref(bs); - /* FIXME Use real permissions */ + /* FIXME Error handling */ blk->root =3D bdrv_root_attach_child(bs, "root", &child_root, - 0, BLK_PERM_ALL, blk, &error_abort); + blk->perm, blk->shared_perm, blk, + &error_abort); =20 notifier_list_notify(&blk->insert_bs_notifiers, blk); if (blk->public.throttle_state) { diff --git a/block/commit.c b/block/commit.c index c284e85..1897e98 100644 --- a/block/commit.c +++ b/block/commit.c @@ -275,10 +275,12 @@ void commit_start(const char *job_id, BlockDriverStat= e *bs, block_job_add_bdrv(&s->common, overlay_bs); } =20 - s->base =3D blk_new(); + /* FIXME Use real permissions */ + s->base =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(s->base, base); =20 - s->top =3D blk_new(); + /* FIXME Use real permissions */ + s->top =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(s->top, top); =20 s->active =3D bs; @@ -328,10 +330,12 @@ int bdrv_commit(BlockDriverState *bs) } } =20 - src =3D blk_new(); + /* FIXME Use real permissions */ + src =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(src, bs); =20 - backing =3D blk_new(); + /* FIXME Use real permissions */ + backing =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(backing, bs->backing->bs); =20 length =3D blk_getlength(src); diff --git a/block/mirror.c b/block/mirror.c index 13f793e..8f015b2 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1012,7 +1012,8 @@ static void mirror_start_job(const char *job_id, Bloc= kDriverState *bs, return; } =20 - s->target =3D blk_new(); + /* FIXME Use real permissions */ + s->target =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(s->target, target); =20 s->replaces =3D g_strdup(replaces); diff --git a/block/qcow2.c b/block/qcow2.c index ef028f6..0356e69 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3262,7 +3262,7 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, } =20 if (new_size) { - BlockBackend *blk =3D blk_new(); + BlockBackend *blk =3D blk_new(BLK_PERM_RESIZE, BLK_PERM_ALL); blk_insert_bs(blk, bs); ret =3D blk_truncate(blk, new_size); blk_unref(blk); diff --git a/blockdev.c b/blockdev.c index 3596d87..10a12d1 100644 --- a/blockdev.c +++ b/blockdev.c @@ -554,7 +554,7 @@ static BlockBackend *blockdev_init(const char *file, QD= ict *bs_opts, if ((!file || !*file) && !qdict_size(bs_opts)) { BlockBackendRootState *blk_rs; =20 - blk =3D blk_new(); + blk =3D blk_new(0, BLK_PERM_ALL); blk_rs =3D blk_get_root_state(blk); blk_rs->open_flags =3D bdrv_flags; blk_rs->read_only =3D read_only; @@ -2886,7 +2886,7 @@ void qmp_block_resize(bool has_device, const char *de= vice, goto out; } =20 - blk =3D blk_new(); + blk =3D blk_new(BLK_PERM_RESIZE, BLK_PERM_ALL); blk_insert_bs(blk, bs); =20 /* complete all in-flight operations before resizing the device */ diff --git a/blockjob.c b/blockjob.c index abee11b..508e0e5 100644 --- a/blockjob.c +++ b/blockjob.c @@ -159,7 +159,8 @@ void *block_job_create(const char *job_id, const BlockJ= obDriver *driver, } } =20 - blk =3D blk_new(); + /* FIXME Use real permissions */ + blk =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(blk, bs); =20 job =3D g_malloc0(driver->instance_size); diff --git a/hmp.c b/hmp.c index 2bc4f06..15fd3f7 100644 --- a/hmp.c +++ b/hmp.c @@ -2044,7 +2044,8 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict) if (!blk) { BlockDriverState *bs =3D bdrv_lookup_bs(NULL, device, &err); if (bs) { - blk =3D local_blk =3D blk_new(); + /* FIXME Use real permissions */ + blk =3D local_blk =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(blk, bs); } else { goto fail; diff --git a/hw/block/fdc.c b/hw/block/fdc.c index 17d29e7..74f3634 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -533,7 +533,8 @@ static int floppy_drive_init(DeviceState *qdev) =20 if (!dev->conf.blk) { /* Anonymous BlockBackend for an empty drive */ - dev->conf.blk =3D blk_new(); + /* FIXME Use real permissions */ + dev->conf.blk =3D blk_new(0, BLK_PERM_ALL); ret =3D blk_attach_dev(dev->conf.blk, qdev); assert(ret =3D=3D 0); } diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-sys= tem.c index 94f4d8b..cca4775 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -78,7 +78,8 @@ static void parse_drive(DeviceState *dev, const char *str= , void **ptr, if (!blk) { BlockDriverState *bs =3D bdrv_lookup_bs(NULL, str, NULL); if (bs) { - blk =3D blk_new(); + /* FIXME Use real permissions */ + blk =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(blk, bs); blk_created =3D true; } diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index dbaa75c..bb3c377 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -170,7 +170,8 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind = kind) return -1; } else { /* Anonymous BlockBackend for an empty drive */ - dev->conf.blk =3D blk_new(); + /* FIXME Use real permissions */ + dev->conf.blk =3D blk_new(0, BLK_PERM_ALL); } } =20 diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index bbfb5dc..546acc7 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2380,7 +2380,8 @@ static void scsi_cd_realize(SCSIDevice *dev, Error **= errp) SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, dev); =20 if (!dev->conf.blk) { - dev->conf.blk =3D blk_new(); + /* FIXME Use real permissions */ + dev->conf.blk =3D blk_new(0, BLK_PERM_ALL); } =20 s->qdev.blocksize =3D 2048; diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 4a18e86..6651f43 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -84,7 +84,7 @@ typedef struct BlockBackendPublic { QLIST_ENTRY(BlockBackendPublic) round_robin; } BlockBackendPublic; =20 -BlockBackend *blk_new(void); +BlockBackend *blk_new(uint64_t perm, uint64_t shared_perm); BlockBackend *blk_new_open(const char *filename, const char *reference, QDict *options, int flags, Error **errp); int blk_get_refcnt(BlockBackend *blk); diff --git a/migration/block.c b/migration/block.c index ebc10e6..6b7ffd4 100644 --- a/migration/block.c +++ b/migration/block.c @@ -415,7 +415,8 @@ static void init_blk_migration(QEMUFile *f) } =20 bmds =3D g_new0(BlkMigDevState, 1); - bmds->blk =3D blk_new(); + /* FIXME Use real permissions */ + bmds->blk =3D blk_new(0, BLK_PERM_ALL); bmds->blk_name =3D g_strdup(bdrv_get_device_name(bs)); bmds->bulk_completed =3D 0; bmds->total_sectors =3D sectors; diff --git a/nbd/server.c b/nbd/server.c index ac92fa0..936d5aa 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -892,7 +892,8 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t d= ev_offset, off_t size, BlockBackend *blk; NBDExport *exp =3D g_malloc0(sizeof(NBDExport)); =20 - blk =3D blk_new(); + /* FIXME Use real permissions */ + blk =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(blk, bs); blk_set_enable_write_cache(blk, !writethrough); =20 diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c index 068c9e4..1dd1cfa 100644 --- a/tests/test-blockjob.c +++ b/tests/test-blockjob.c @@ -53,7 +53,8 @@ static BlockJob *do_test_id(BlockBackend *blk, const char= *id, * BlockDriverState inserted. */ static BlockBackend *create_blk(const char *name) { - BlockBackend *blk =3D blk_new(); + /* FIXME Use real permissions */ + BlockBackend *blk =3D blk_new(0, BLK_PERM_ALL); BlockDriverState *bs; =20 bs =3D bdrv_open("null-co://", NULL, NULL, 0, &error_abort); diff --git a/tests/test-throttle.c b/tests/test-throttle.c index 363b59a..5846433 100644 --- a/tests/test-throttle.c +++ b/tests/test-throttle.c @@ -593,9 +593,10 @@ static void test_groups(void) BlockBackend *blk1, *blk2, *blk3; BlockBackendPublic *blkp1, *blkp2, *blkp3; =20 - blk1 =3D blk_new(); - blk2 =3D blk_new(); - blk3 =3D blk_new(); + /* FIXME Use real permissions */ + blk1 =3D blk_new(0, BLK_PERM_ALL); + blk2 =3D blk_new(0, BLK_PERM_ALL); + blk3 =3D blk_new(0, BLK_PERM_ALL); =20 blkp1 =3D blk_get_public(blk1); blkp2 =3D blk_get_public(blk2); --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 148769074123730.726217062850537; Tue, 21 Feb 2017 07:25:41 -0800 (PST) Received: from localhost ([::1]:46300 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCJq-0007Tg-UQ for importer@patchew.org; Tue, 21 Feb 2017 10:25:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43176) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuo-0000Zk-Ou for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBum-00083E-Rd for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35630) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBui-0007zY-2S; Tue, 21 Feb 2017 09:59:36 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 178D861BB9; Tue, 21 Feb 2017 14:59:36 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwud9030565; Tue, 21 Feb 2017 09:59:34 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:21 +0100 Message-Id: <1487689130-30373-26-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 21 Feb 2017 14:59:36 +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 25/54] block: Add error parameter to blk_insert_bs() 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" Now that blk_insert_bs() requests the BlockBackend permissions for the node it attaches to, it can fail. Instead of aborting, pass the errors to the callers. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 5 ++++- block/backup.c | 5 ++++- block/block-backend.c | 13 ++++++++----- block/commit.c | 38 ++++++++++++++++++++++++++++++------= -- block/mirror.c | 15 ++++++++++++--- block/qcow2.c | 10 ++++++++-- blockdev.c | 11 +++++++++-- blockjob.c | 7 ++++++- hmp.c | 6 +++++- hw/core/qdev-properties-system.c | 7 ++++++- include/sysemu/block-backend.h | 2 +- migration/block.c | 2 +- nbd/server.c | 6 +++++- tests/test-blockjob.c | 2 +- 14 files changed, 100 insertions(+), 29 deletions(-) diff --git a/block.c b/block.c index ed37d17..9f46698 100644 --- a/block.c +++ b/block.c @@ -2171,8 +2171,11 @@ static BlockDriverState *bdrv_open_inherit(const cha= r *filename, } if (file_bs !=3D NULL) { file =3D blk_new(BLK_PERM_CONSISTENT_READ, BLK_PERM_ALL); - blk_insert_bs(file, file_bs); + blk_insert_bs(file, file_bs, &local_err); bdrv_unref(file_bs); + if (local_err) { + goto fail; + } =20 qdict_put(options, "file", qstring_from_str(bdrv_get_node_name(file_bs))); diff --git a/block/backup.c b/block/backup.c index 4b3c94c..f38d1d0 100644 --- a/block/backup.c +++ b/block/backup.c @@ -626,7 +626,10 @@ BlockJob *backup_job_create(const char *job_id, BlockD= riverState *bs, =20 /* FIXME Use real permissions */ job->target =3D blk_new(0, BLK_PERM_ALL); - blk_insert_bs(job->target, target); + ret =3D blk_insert_bs(job->target, target, errp); + if (ret < 0) { + goto error; + } =20 job->on_source_error =3D on_source_error; job->on_target_error =3D on_target_error; diff --git a/block/block-backend.c b/block/block-backend.c index 0319220..299948f 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -508,19 +508,22 @@ void blk_remove_bs(BlockBackend *blk) /* * Associates a new BlockDriverState with @blk. */ -void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs) +int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp) { - bdrv_ref(bs); - /* FIXME Error handling */ blk->root =3D bdrv_root_attach_child(bs, "root", &child_root, - blk->perm, blk->shared_perm, blk, - &error_abort); + blk->perm, blk->shared_perm, blk, e= rrp); + if (blk->root =3D=3D NULL) { + return -EPERM; + } + bdrv_ref(bs); =20 notifier_list_notify(&blk->insert_bs_notifiers, blk); if (blk->public.throttle_state) { throttle_timers_attach_aio_context( &blk->public.throttle_timers, bdrv_get_aio_context(bs)); } + + return 0; } =20 /* diff --git a/block/commit.c b/block/commit.c index 1897e98..2ad8138 100644 --- a/block/commit.c +++ b/block/commit.c @@ -220,6 +220,7 @@ void commit_start(const char *job_id, BlockDriverState = *bs, BlockDriverState *iter; BlockDriverState *overlay_bs; Error *local_err =3D NULL; + int ret; =20 assert(top !=3D bs); if (top =3D=3D base) { @@ -256,8 +257,7 @@ void commit_start(const char *job_id, BlockDriverState = *bs, bdrv_reopen_multiple(bdrv_get_aio_context(bs), reopen_queue, &loca= l_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); - block_job_unref(&s->common); - return; + goto fail; } } =20 @@ -277,11 +277,17 @@ void commit_start(const char *job_id, BlockDriverStat= e *bs, =20 /* FIXME Use real permissions */ s->base =3D blk_new(0, BLK_PERM_ALL); - blk_insert_bs(s->base, base); + ret =3D blk_insert_bs(s->base, base, errp); + if (ret < 0) { + goto fail; + } =20 /* FIXME Use real permissions */ s->top =3D blk_new(0, BLK_PERM_ALL); - blk_insert_bs(s->top, top); + ret =3D blk_insert_bs(s->top, top, errp); + if (ret < 0) { + goto fail; + } =20 s->active =3D bs; =20 @@ -294,6 +300,16 @@ void commit_start(const char *job_id, BlockDriverState= *bs, =20 trace_commit_start(bs, base, top, s); block_job_start(&s->common); + return; + +fail: + if (s->base) { + blk_unref(s->base); + } + if (s->top) { + blk_unref(s->top); + } + block_job_unref(&s->common); } =20 =20 @@ -332,11 +348,17 @@ int bdrv_commit(BlockDriverState *bs) =20 /* FIXME Use real permissions */ src =3D blk_new(0, BLK_PERM_ALL); - blk_insert_bs(src, bs); - - /* FIXME Use real permissions */ backing =3D blk_new(0, BLK_PERM_ALL); - blk_insert_bs(backing, bs->backing->bs); + + ret =3D blk_insert_bs(src, bs, NULL); + if (ret < 0) { + goto ro_cleanup; + } + + ret =3D blk_insert_bs(backing, bs->backing->bs, NULL); + if (ret < 0) { + goto ro_cleanup; + } =20 length =3D blk_getlength(src); if (length < 0) { diff --git a/block/mirror.c b/block/mirror.c index 8f015b2..c551bfc 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -523,9 +523,12 @@ static void mirror_exit(BlockJob *job, void *opaque) bdrv_replace_in_backing_chain(to_replace, target_bs); bdrv_drained_end(target_bs); =20 - /* We just changed the BDS the job BB refers to */ + /* We just changed the BDS the job BB refers to, so switch the BB = back + * so the cleanup does the right thing. We don't need any permissi= ons + * any more now. */ blk_remove_bs(job->blk); - blk_insert_bs(job->blk, src); + blk_set_perm(job->blk, 0, BLK_PERM_ALL, &error_abort); + blk_insert_bs(job->blk, src, &error_abort); } if (s->to_replace) { bdrv_op_unblock_all(s->to_replace, s->replace_blocker); @@ -990,6 +993,7 @@ static void mirror_start_job(const char *job_id, BlockD= riverState *bs, bool auto_complete) { MirrorBlockJob *s; + int ret; =20 if (granularity =3D=3D 0) { granularity =3D bdrv_get_default_bitmap_granularity(target); @@ -1014,7 +1018,12 @@ static void mirror_start_job(const char *job_id, Blo= ckDriverState *bs, =20 /* FIXME Use real permissions */ s->target =3D blk_new(0, BLK_PERM_ALL); - blk_insert_bs(s->target, target); + ret =3D blk_insert_bs(s->target, target, errp); + if (ret < 0) { + blk_unref(s->target); + block_job_unref(&s->common); + return; + } =20 s->replaces =3D g_strdup(replaces); s->on_source_error =3D on_source_error; diff --git a/block/qcow2.c b/block/qcow2.c index 0356e69..6f79df8 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3113,6 +3113,7 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, uint64_t cluster_size =3D s->cluster_size; bool encrypt; int refcount_bits =3D s->refcount_bits; + Error *local_err =3D NULL; int ret; QemuOptDesc *desc =3D opts->list->desc; Qcow2AmendHelperCBInfo helper_cb_info; @@ -3263,10 +3264,15 @@ static int qcow2_amend_options(BlockDriverState *bs= , QemuOpts *opts, =20 if (new_size) { BlockBackend *blk =3D blk_new(BLK_PERM_RESIZE, BLK_PERM_ALL); - blk_insert_bs(blk, bs); + ret =3D blk_insert_bs(blk, bs, &local_err); + if (ret < 0) { + error_report_err(local_err); + blk_unref(blk); + return ret; + } + ret =3D blk_truncate(blk, new_size); blk_unref(blk); - if (ret < 0) { return ret; } diff --git a/blockdev.c b/blockdev.c index 10a12d1..d01e313 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2432,6 +2432,7 @@ static void qmp_blockdev_insert_anon_medium(BlockBack= end *blk, BlockDriverState *bs, Error **= errp) { bool has_device; + int ret; =20 /* For BBs without a device, we can exchange the BDS tree at will */ has_device =3D blk_get_attached_dev(blk); @@ -2451,7 +2452,10 @@ static void qmp_blockdev_insert_anon_medium(BlockBac= kend *blk, return; } =20 - blk_insert_bs(blk, bs); + ret =3D blk_insert_bs(blk, bs, errp); + if (ret < 0) { + return; + } =20 if (!blk_dev_has_tray(blk)) { /* For tray-less devices, blockdev-close-tray is a no-op (or may n= ot be @@ -2887,7 +2891,10 @@ void qmp_block_resize(bool has_device, const char *d= evice, } =20 blk =3D blk_new(BLK_PERM_RESIZE, BLK_PERM_ALL); - blk_insert_bs(blk, bs); + ret =3D blk_insert_bs(blk, bs, errp); + if (ret < 0) { + goto out; + } =20 /* complete all in-flight operations before resizing the device */ bdrv_drain_all(); diff --git a/blockjob.c b/blockjob.c index 508e0e5..72b7d4c 100644 --- a/blockjob.c +++ b/blockjob.c @@ -128,6 +128,7 @@ void *block_job_create(const char *job_id, const BlockJ= obDriver *driver, { BlockBackend *blk; BlockJob *job; + int ret; =20 if (bs->job) { error_setg(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(bs)); @@ -161,7 +162,11 @@ void *block_job_create(const char *job_id, const Block= JobDriver *driver, =20 /* FIXME Use real permissions */ blk =3D blk_new(0, BLK_PERM_ALL); - blk_insert_bs(blk, bs); + ret =3D blk_insert_bs(blk, bs, errp); + if (ret < 0) { + blk_unref(blk); + return NULL; + } =20 job =3D g_malloc0(driver->instance_size); error_setg(&job->blocker, "block device is in use by block job: %s", diff --git a/hmp.c b/hmp.c index 15fd3f7..801fddb 100644 --- a/hmp.c +++ b/hmp.c @@ -2039,6 +2039,7 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict) const char* device =3D qdict_get_str(qdict, "device"); const char* command =3D qdict_get_str(qdict, "command"); Error *err =3D NULL; + int ret; =20 blk =3D blk_by_name(device); if (!blk) { @@ -2046,7 +2047,10 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict) if (bs) { /* FIXME Use real permissions */ blk =3D local_blk =3D blk_new(0, BLK_PERM_ALL); - blk_insert_bs(blk, bs); + ret =3D blk_insert_bs(blk, bs, &err); + if (ret < 0) { + goto fail; + } } else { goto fail; } diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-sys= tem.c index cca4775..66ba367 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -73,6 +73,7 @@ static void parse_drive(DeviceState *dev, const char *str= , void **ptr, { BlockBackend *blk; bool blk_created =3D false; + int ret; =20 blk =3D blk_by_name(str); if (!blk) { @@ -80,8 +81,12 @@ static void parse_drive(DeviceState *dev, const char *st= r, void **ptr, if (bs) { /* FIXME Use real permissions */ blk =3D blk_new(0, BLK_PERM_ALL); - blk_insert_bs(blk, bs); blk_created =3D true; + + ret =3D blk_insert_bs(blk, bs, errp); + if (ret < 0) { + goto fail; + } } } if (!blk) { diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 6651f43..0861113 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -102,7 +102,7 @@ BlockBackend *blk_by_public(BlockBackendPublic *public); =20 BlockDriverState *blk_bs(BlockBackend *blk); void blk_remove_bs(BlockBackend *blk); -void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs); +int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp); bool bdrv_has_blk(BlockDriverState *bs); bool bdrv_is_root_node(BlockDriverState *bs); int blk_set_perm(BlockBackend *blk, uint64_t perm, uint64_t shared_perm, diff --git a/migration/block.c b/migration/block.c index 6b7ffd4..d259936 100644 --- a/migration/block.c +++ b/migration/block.c @@ -446,7 +446,7 @@ static void init_blk_migration(QEMUFile *f) BlockDriverState *bs =3D bmds_bs[i].bs; =20 if (bmds) { - blk_insert_bs(bmds->blk, bs); + blk_insert_bs(bmds->blk, bs, &error_abort); =20 alloc_aio_bitmap(bmds); error_setg(&bmds->blocker, "block device is in use by migratio= n"); diff --git a/nbd/server.c b/nbd/server.c index 936d5aa..89362ba 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -891,10 +891,14 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t= dev_offset, off_t size, { BlockBackend *blk; NBDExport *exp =3D g_malloc0(sizeof(NBDExport)); + int ret; =20 /* FIXME Use real permissions */ blk =3D blk_new(0, BLK_PERM_ALL); - blk_insert_bs(blk, bs); + ret =3D blk_insert_bs(blk, bs, errp); + if (ret < 0) { + goto fail; + } blk_set_enable_write_cache(blk, !writethrough); =20 exp->refcount =3D 1; diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c index 1dd1cfa..143ce96 100644 --- a/tests/test-blockjob.c +++ b/tests/test-blockjob.c @@ -60,7 +60,7 @@ static BlockBackend *create_blk(const char *name) bs =3D bdrv_open("null-co://", NULL, NULL, 0, &error_abort); g_assert_nonnull(bs); =20 - blk_insert_bs(blk, bs); + blk_insert_bs(blk, bs, &error_abort); bdrv_unref(bs); =20 if (name) { --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487692733586660.105964745392; Tue, 21 Feb 2017 07:58:53 -0800 (PST) Received: from localhost ([::1]:46505 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCq3-0005hw-BH for importer@patchew.org; Tue, 21 Feb 2017 10:58:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43209) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuq-0000c5-I1 for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBup-00084Y-7n for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33066) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuj-00080G-DR; Tue, 21 Feb 2017 09:59:37 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 72B6B80086; Tue, 21 Feb 2017 14:59:37 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudA030565; Tue, 21 Feb 2017 09:59:36 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:22 +0100 Message-Id: <1487689130-30373-27-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 21 Feb 2017 14:59:37 +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 26/54] block: Add BDRV_O_RESIZE for blk_new_open() 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" blk_new_open() is a convenience function that processes flags rather than QDict options as a simple way to just open an image file. In order to keep it convenient in the future, it must automatically request the necessary permissions. This can easily be inferred from the flags for read and write, but we need another flag that tells us whether to get the resize permission. We can't just always request it because that means that no block jobs can run on the resulting BlockBackend (which is something that e.g. qemu-img commit wants to do), but we also can't request it never because most of the .bdrv_create() implementations call blk_truncate(). The solution is to introduce another flag that is passed by all users that want to resize the image. Signed-off-by: Kevin Wolf --- block/parallels.c | 3 ++- block/qcow.c | 3 ++- block/qcow2.c | 3 ++- block/qed.c | 3 ++- block/vdi.c | 3 ++- block/vhdx.c | 3 ++- block/vmdk.c | 6 ++++-- block/vpc.c | 3 ++- include/block/block.h | 1 + qemu-img.c | 2 +- 10 files changed, 20 insertions(+), 10 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 6b0c0a9..19935e2 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -488,7 +488,8 @@ static int parallels_create(const char *filename, QemuO= pts *opts, Error **errp) } =20 file =3D blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err); + BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, + &local_err); if (file =3D=3D NULL) { error_propagate(errp, local_err); return -EIO; diff --git a/block/qcow.c b/block/qcow.c index eb5d54c..9d6ac83 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -823,7 +823,8 @@ static int qcow_create(const char *filename, QemuOpts *= opts, Error **errp) } =20 qcow_blk =3D blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err); + BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, + &local_err); if (qcow_blk =3D=3D NULL) { error_propagate(errp, local_err); ret =3D -EIO; diff --git a/block/qcow2.c b/block/qcow2.c index 6f79df8..4ca9f24 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2266,7 +2266,8 @@ static int qcow2_create2(const char *filename, int64_= t total_size, options =3D qdict_new(); qdict_put(options, "driver", qstring_from_str("qcow2")); blk =3D blk_new_open(filename, NULL, options, - BDRV_O_RDWR | BDRV_O_NO_FLUSH, &local_err); + BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_NO_FLUSH, + &local_err); if (blk =3D=3D NULL) { error_propagate(errp, local_err); ret =3D -EIO; diff --git a/block/qed.c b/block/qed.c index d8f947a..5ec7fd8 100644 --- a/block/qed.c +++ b/block/qed.c @@ -625,7 +625,8 @@ static int qed_create(const char *filename, uint32_t cl= uster_size, } =20 blk =3D blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err); + BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, + &local_err); if (blk =3D=3D NULL) { error_propagate(errp, local_err); return -EIO; diff --git a/block/vdi.c b/block/vdi.c index fd6e26d..9b4f70e 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -763,7 +763,8 @@ static int vdi_create(const char *filename, QemuOpts *o= pts, Error **errp) } =20 blk =3D blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err); + BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, + &local_err); if (blk =3D=3D NULL) { error_propagate(errp, local_err); ret =3D -EIO; diff --git a/block/vhdx.c b/block/vhdx.c index ab747f6..052a753 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1859,7 +1859,8 @@ static int vhdx_create(const char *filename, QemuOpts= *opts, Error **errp) } =20 blk =3D blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err); + BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, + &local_err); if (blk =3D=3D NULL) { error_propagate(errp, local_err); ret =3D -EIO; diff --git a/block/vmdk.c b/block/vmdk.c index f5e2fb5..a9bd22b 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1703,7 +1703,8 @@ static int vmdk_create_extent(const char *filename, i= nt64_t filesize, } =20 blk =3D blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err); + BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, + &local_err); if (blk =3D=3D NULL) { error_propagate(errp, local_err); ret =3D -EIO; @@ -2071,7 +2072,8 @@ static int vmdk_create(const char *filename, QemuOpts= *opts, Error **errp) } =20 new_blk =3D blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err); + BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, + &local_err); if (new_blk =3D=3D NULL) { error_propagate(errp, local_err); ret =3D -EIO; diff --git a/block/vpc.c b/block/vpc.c index b9c9832..f591d4b 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -915,7 +915,8 @@ static int vpc_create(const char *filename, QemuOpts *o= pts, Error **errp) } =20 blk =3D blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err); + BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, + &local_err); if (blk =3D=3D NULL) { error_propagate(errp, local_err); ret =3D -EIO; diff --git a/include/block/block.h b/include/block/block.h index 2d6ed7d..701d22b 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -82,6 +82,7 @@ typedef struct HDGeometry { } HDGeometry; =20 #define BDRV_O_RDWR 0x0002 +#define BDRV_O_RESIZE 0x0004 /* requests permission for resizing the = node */ #define BDRV_O_SNAPSHOT 0x0008 /* open the file read only and save writ= es in a snapshot */ #define BDRV_O_TEMPORARY 0x0010 /* delete the file after use */ #define BDRV_O_NOCACHE 0x0020 /* do not use the host page cache */ diff --git a/qemu-img.c b/qemu-img.c index cff22e3..8d9195e 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3275,7 +3275,7 @@ static int img_resize(int argc, char **argv) qemu_opts_del(param); =20 blk =3D img_open(image_opts, filename, fmt, - BDRV_O_RDWR, false, quiet); + BDRV_O_RDWR | BDRV_O_RESIZE, false, quiet); if (!blk) { ret =3D -1; goto out; --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487692933498935.0845639761792; Tue, 21 Feb 2017 08:02:13 -0800 (PST) Received: from localhost ([::1]:46539 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCtF-000069-Dr for importer@patchew.org; Tue, 21 Feb 2017 11:02:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43157) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuo-0000ZD-6a for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBun-00083M-5R for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:16134) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBul-00081L-38; Tue, 21 Feb 2017 09:59:39 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 222907FB95; Tue, 21 Feb 2017 14:59:39 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudB030565; Tue, 21 Feb 2017 09:59:37 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:23 +0100 Message-Id: <1487689130-30373-28-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 21 Feb 2017 14:59:39 +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 27/54] block: Request real permissions in blk_new_open() 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" We can figure out the necessary permissions from the flags that the caller passed. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/block-backend.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 299948f..03d5495 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -166,17 +166,33 @@ BlockBackend *blk_new_open(const char *filename, cons= t char *reference, { BlockBackend *blk; BlockDriverState *bs; + uint64_t perm; + + /* blk_new_open() is mainly used in .bdrv_create implementations and t= he + * tools where sharing isn't a concern because the BDS stays private, = so we + * just request permission according to the flags. + * + * The exceptions are xen_disk and blockdev_init(); in these cases, the + * caller of blk_new_open() doesn't make use of the permissions, but t= hey + * shouldn't hurt either. We can still share everything here because t= he + * guest devices will add their own blockers if they can't share. */ + perm =3D BLK_PERM_CONSISTENT_READ; + if (flags & BDRV_O_RDWR) { + perm |=3D BLK_PERM_WRITE; + } + if (flags & BDRV_O_RESIZE) { + perm |=3D BLK_PERM_RESIZE; + } =20 - blk =3D blk_new(0, BLK_PERM_ALL); + blk =3D blk_new(perm, BLK_PERM_ALL); bs =3D bdrv_open(filename, reference, options, flags, errp); if (!bs) { blk_unref(blk); return NULL; } =20 - /* FIXME Use real permissions */ blk->root =3D bdrv_root_attach_child(bs, "root", &child_root, - 0, BLK_PERM_ALL, blk, &error_abort); + perm, BLK_PERM_ALL, blk, &error_abo= rt); =20 return blk; } --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487693212340387.14197814800025; Tue, 21 Feb 2017 08:06:52 -0800 (PST) Received: from localhost ([::1]:46561 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCxi-0004UR-Um for importer@patchew.org; Tue, 21 Feb 2017 11:06:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBur-0000ck-4l for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBup-000850-MN for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42520) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBum-00082P-Da; Tue, 21 Feb 2017 09:59:40 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 77085F44CA; Tue, 21 Feb 2017 14:59:40 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudC030565; Tue, 21 Feb 2017 09:59:39 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:24 +0100 Message-Id: <1487689130-30373-29-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 21 Feb 2017 14:59:40 +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 28/54] block: Allow error return in BlockDevOps.change_media_cb() 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" Some devices allow a media change between read-only and read-write media. They need to adapt the permissions in their .change_media_cb() implementation, which can fail. So add an Error parameter to the function. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/block-backend.c | 20 +++++++++++++++----- blockdev.c | 19 +++++++++++++++---- hw/block/fdc.c | 2 +- hw/ide/core.c | 2 +- hw/scsi/scsi-disk.c | 2 +- hw/sd/sd.c | 2 +- include/block/block_int.h | 2 +- include/sysemu/block-backend.h | 2 +- 8 files changed, 36 insertions(+), 15 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 03d5495..fcc42b5 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -677,19 +677,29 @@ void blk_set_dev_ops(BlockBackend *blk, const BlockDe= vOps *ops, =20 /* * Notify @blk's attached device model of media change. - * If @load is true, notify of media load. - * Else, notify of media eject. + * + * If @load is true, notify of media load. This action can fail, meaning t= hat + * the medium cannot be loaded. @errp is set then. + * + * If @load is false, notify of media eject. This can never fail. + * * Also send DEVICE_TRAY_MOVED events as appropriate. */ -void blk_dev_change_media_cb(BlockBackend *blk, bool load) +void blk_dev_change_media_cb(BlockBackend *blk, bool load, Error **errp) { if (blk->dev_ops && blk->dev_ops->change_media_cb) { bool tray_was_open, tray_is_open; + Error *local_err =3D NULL; =20 assert(!blk->legacy_dev); =20 tray_was_open =3D blk_dev_is_tray_open(blk); - blk->dev_ops->change_media_cb(blk->dev_opaque, load); + blk->dev_ops->change_media_cb(blk->dev_opaque, load, &local_err); + if (local_err) { + assert(load =3D=3D true); + error_propagate(errp, local_err); + return; + } tray_is_open =3D blk_dev_is_tray_open(blk); =20 if (tray_was_open !=3D tray_is_open) { @@ -703,7 +713,7 @@ void blk_dev_change_media_cb(BlockBackend *blk, bool lo= ad) =20 static void blk_root_change_media(BdrvChild *child, bool load) { - blk_dev_change_media_cb(child->opaque, load); + blk_dev_change_media_cb(child->opaque, load, NULL); } =20 /* diff --git a/blockdev.c b/blockdev.c index d01e313..bcee23e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2307,7 +2307,7 @@ static int do_open_tray(const char *blk_name, const c= har *qdev_id, } =20 if (!locked || force) { - blk_dev_change_media_cb(blk, false); + blk_dev_change_media_cb(blk, false, &error_abort); } =20 if (locked && !force) { @@ -2345,6 +2345,7 @@ void qmp_blockdev_close_tray(bool has_device, const c= har *device, Error **errp) { BlockBackend *blk; + Error *local_err =3D NULL; =20 device =3D has_device ? device : NULL; id =3D has_id ? id : NULL; @@ -2368,7 +2369,11 @@ void qmp_blockdev_close_tray(bool has_device, const = char *device, return; } =20 - blk_dev_change_media_cb(blk, true); + blk_dev_change_media_cb(blk, true, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } } =20 void qmp_x_blockdev_remove_medium(bool has_device, const char *device, @@ -2421,7 +2426,7 @@ void qmp_x_blockdev_remove_medium(bool has_device, co= nst char *device, * called at all); therefore, the medium needs to be ejected here. * Do it after blk_remove_bs() so blk_is_inserted(blk) returns the= @load * value passed here (i.e. false). */ - blk_dev_change_media_cb(blk, false); + blk_dev_change_media_cb(blk, false, &error_abort); } =20 out: @@ -2431,6 +2436,7 @@ out: static void qmp_blockdev_insert_anon_medium(BlockBackend *blk, BlockDriverState *bs, Error **= errp) { + Error *local_err =3D NULL; bool has_device; int ret; =20 @@ -2463,7 +2469,12 @@ static void qmp_blockdev_insert_anon_medium(BlockBac= kend *blk, * slot here. * Do it after blk_insert_bs() so blk_is_inserted(blk) returns the= @load * value passed here (i.e. true). */ - blk_dev_change_media_cb(blk, true); + blk_dev_change_media_cb(blk, true, &local_err); + if (local_err) { + error_propagate(errp, local_err); + blk_remove_bs(blk); + return; + } } } =20 diff --git a/hw/block/fdc.c b/hw/block/fdc.c index 74f3634..5f6c496 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -469,7 +469,7 @@ static void fd_revalidate(FDrive *drv) } } =20 -static void fd_change_cb(void *opaque, bool load) +static void fd_change_cb(void *opaque, bool load, Error **errp) { FDrive *drive =3D opaque; =20 diff --git a/hw/ide/core.c b/hw/ide/core.c index 43709e5..f88b1e5 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -1120,7 +1120,7 @@ static void ide_cfata_metadata_write(IDEState *s) } =20 /* called when the inserted state of the media has changed */ -static void ide_cd_change_cb(void *opaque, bool load) +static void ide_cd_change_cb(void *opaque, bool load, Error **errp) { IDEState *s =3D opaque; uint64_t nb_sectors; diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 546acc7..c1ccfad 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2240,7 +2240,7 @@ static void scsi_disk_resize_cb(void *opaque) } } =20 -static void scsi_cd_change_media_cb(void *opaque, bool load) +static void scsi_cd_change_media_cb(void *opaque, bool load, Error **errp) { SCSIDiskState *s =3D opaque; =20 diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 8e88e83..8e31491 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -458,7 +458,7 @@ static bool sd_get_readonly(SDState *sd) return sd->wp_switch; } =20 -static void sd_cardchange(void *opaque, bool load) +static void sd_cardchange(void *opaque, bool load, Error **errp) { SDState *sd =3D opaque; DeviceState *dev =3D DEVICE(sd); diff --git a/include/block/block_int.h b/include/block/block_int.h index 63d5446..e00d0f4 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -891,7 +891,7 @@ void bdrv_format_default_perms(BlockDriverState *bs, Bd= rvChild *c, uint64_t *nperm, uint64_t *nshared); =20 const char *bdrv_get_parent_name(const BlockDriverState *bs); -void blk_dev_change_media_cb(BlockBackend *blk, bool load); +void blk_dev_change_media_cb(BlockBackend *blk, bool load, Error **errp); bool blk_dev_has_removable_media(BlockBackend *blk); bool blk_dev_has_tray(BlockBackend *blk); void blk_dev_eject_request(BlockBackend *blk, bool force); diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 0861113..b23f683 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -34,7 +34,7 @@ typedef struct BlockDevOps { * changes. Sure would be useful if it did. * Device models with removable media must implement this callback. */ - void (*change_media_cb)(void *opaque, bool load); + void (*change_media_cb)(void *opaque, bool load, Error **errp); /* * Runs when an eject request is issued from the monitor, the tray * is closed, and the medium is locked. --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487694004677393.41752622614365; Tue, 21 Feb 2017 08:20:04 -0800 (PST) Received: from localhost ([::1]:46647 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgDAZ-0000pl-63 for importer@patchew.org; Tue, 21 Feb 2017 11:20:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBux-0000kS-Tw for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuv-00087k-Ls for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47860) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBun-00083Q-Qn; Tue, 21 Feb 2017 09:59:42 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 E2F1642BA9; Tue, 21 Feb 2017 14:59:41 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudD030565; Tue, 21 Feb 2017 09:59:40 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:25 +0100 Message-Id: <1487689130-30373-30-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 21 Feb 2017 14:59:41 +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 29/54] hw/block: Request permissions 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" This makes all device emulations with a qdev drive property request permissions on their BlockBackend. The only thing we block at this point is resizing images for some devices that can't support it. Signed-off-by: Kevin Wolf --- hw/block/block.c | 22 +++++++++++++++++++++- hw/block/fdc.c | 25 +++++++++++++++++++++++-- hw/block/m25p80.c | 8 ++++++++ hw/block/nand.c | 7 +++++++ hw/block/nvme.c | 8 +++++++- hw/block/onenand.c | 7 +++++++ hw/block/pflash_cfi01.c | 18 ++++++++++++------ hw/block/pflash_cfi02.c | 19 +++++++++++++------ hw/block/virtio-blk.c | 8 +++++++- hw/core/qdev-properties-system.c | 1 - hw/ide/qdev.c | 7 +++++-- hw/nvram/spapr_nvram.c | 8 ++++++++ hw/scsi/scsi-disk.c | 9 +++++++-- hw/sd/sd.c | 6 ++++++ hw/usb/dev-storage.c | 6 +++++- include/hw/block/block.h | 3 ++- tests/qemu-iotests/051.pc.out | 6 +++--- 17 files changed, 141 insertions(+), 27 deletions(-) diff --git a/hw/block/block.c b/hw/block/block.c index 8dc9d84..7059ba1 100644 --- a/hw/block/block.c +++ b/hw/block/block.c @@ -51,11 +51,31 @@ void blkconf_blocksizes(BlockConf *conf) } } =20 -void blkconf_apply_backend_options(BlockConf *conf) +void blkconf_apply_backend_options(BlockConf *conf, bool readonly, + bool resizable, Error **errp) { BlockBackend *blk =3D conf->blk; BlockdevOnError rerror, werror; + uint64_t perm, shared_perm; bool wce; + int ret; + + perm =3D BLK_PERM_CONSISTENT_READ; + if (!readonly) { + perm |=3D BLK_PERM_WRITE; + } + + /* TODO Remove BLK_PERM_WRITE unless explicitly configured so */ + shared_perm =3D BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED | + BLK_PERM_GRAPH_MOD | BLK_PERM_WRITE; + if (resizable) { + shared_perm |=3D BLK_PERM_RESIZE; + } + + ret =3D blk_set_perm(blk, perm, shared_perm, errp); + if (ret < 0) { + return; + } =20 switch (conf->wce) { case ON_OFF_AUTO_ON: wce =3D true; break; diff --git a/hw/block/fdc.c b/hw/block/fdc.c index 5f6c496..a328693 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -186,6 +186,7 @@ typedef enum FDiskFlags { struct FDrive { FDCtrl *fdctrl; BlockBackend *blk; + BlockConf *conf; /* Drive status */ FloppyDriveType drive; /* CMOS drive type */ uint8_t perpendicular; /* 2.88 MB access mode */ @@ -472,6 +473,19 @@ static void fd_revalidate(FDrive *drv) static void fd_change_cb(void *opaque, bool load, Error **errp) { FDrive *drive =3D opaque; + Error *local_err =3D NULL; + + if (!load) { + blk_set_perm(drive->blk, 0, BLK_PERM_ALL, &error_abort); + } else { + blkconf_apply_backend_options(drive->conf, + blk_is_read_only(drive->blk), false, + &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + } =20 drive->media_changed =3D 1; drive->media_validated =3D false; @@ -508,6 +522,7 @@ static int floppy_drive_init(DeviceState *qdev) FloppyDrive *dev =3D FLOPPY_DRIVE(qdev); FloppyBus *bus =3D FLOPPY_BUS(qdev->parent_bus); FDrive *drive; + Error *local_err =3D NULL; int ret; =20 if (dev->unit =3D=3D -1) { @@ -533,7 +548,6 @@ static int floppy_drive_init(DeviceState *qdev) =20 if (!dev->conf.blk) { /* Anonymous BlockBackend for an empty drive */ - /* FIXME Use real permissions */ dev->conf.blk =3D blk_new(0, BLK_PERM_ALL); ret =3D blk_attach_dev(dev->conf.blk, qdev); assert(ret =3D=3D 0); @@ -552,7 +566,13 @@ static int floppy_drive_init(DeviceState *qdev) * blkconf_apply_backend_options(). */ dev->conf.rerror =3D BLOCKDEV_ON_ERROR_AUTO; dev->conf.werror =3D BLOCKDEV_ON_ERROR_AUTO; - blkconf_apply_backend_options(&dev->conf); + + blkconf_apply_backend_options(&dev->conf, blk_is_read_only(dev->conf.b= lk), + false, &local_err); + if (local_err) { + error_report_err(local_err); + return -1; + } =20 /* 'enospc' is the default for -drive, 'report' is what blk_new() give= s us * for empty drives. */ @@ -566,6 +586,7 @@ static int floppy_drive_init(DeviceState *qdev) return -1; } =20 + drive->conf =3D &dev->conf; drive->blk =3D dev->conf.blk; drive->fdctrl =3D bus->fdc; =20 diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c index 2d6eb46..190573c 100644 --- a/hw/block/m25p80.c +++ b/hw/block/m25p80.c @@ -1215,6 +1215,7 @@ static void m25p80_realize(SSISlave *ss, Error **errp) { Flash *s =3D M25P80(ss); M25P80Class *mc =3D M25P80_GET_CLASS(s); + int ret; =20 s->pi =3D mc->pi; =20 @@ -1222,6 +1223,13 @@ static void m25p80_realize(SSISlave *ss, Error **err= p) s->dirty_page =3D -1; =20 if (s->blk) { + uint64_t perm =3D BLK_PERM_CONSISTENT_READ | + (blk_is_read_only(s->blk) ? 0 : BLK_PERM_WRITE); + ret =3D blk_set_perm(s->blk, perm, BLK_PERM_ALL, errp); + if (ret < 0) { + return; + } + DB_PRINT_L(0, "Binding to IF_MTD drive\n"); s->storage =3D blk_blockalign(s->blk, s->size); =20 diff --git a/hw/block/nand.c b/hw/block/nand.c index c69e675..0d33ac2 100644 --- a/hw/block/nand.c +++ b/hw/block/nand.c @@ -373,6 +373,8 @@ static void nand_realize(DeviceState *dev, Error **errp) { int pagesize; NANDFlashState *s =3D NAND(dev); + int ret; + =20 s->buswidth =3D nand_flash_ids[s->chip_id].width >> 3; s->size =3D nand_flash_ids[s->chip_id].size << 20; @@ -407,6 +409,11 @@ static void nand_realize(DeviceState *dev, Error **err= p) error_setg(errp, "Can't use a read-only drive"); return; } + ret =3D blk_set_perm(s->blk, BLK_PERM_CONSISTENT_READ | BLK_PERM_W= RITE, + BLK_PERM_ALL, errp); + if (ret < 0) { + return; + } if (blk_getlength(s->blk) >=3D (s->pages << s->page_shift) + (s->pages << s->oob_shift)) { pagesize =3D 0; diff --git a/hw/block/nvme.c b/hw/block/nvme.c index ae91a18..ae303d4 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -835,6 +835,7 @@ static int nvme_init(PCIDevice *pci_dev) int i; int64_t bs_size; uint8_t *pci_conf; + Error *local_err =3D NULL; =20 if (!n->conf.blk) { return -1; @@ -850,7 +851,12 @@ static int nvme_init(PCIDevice *pci_dev) return -1; } blkconf_blocksizes(&n->conf); - blkconf_apply_backend_options(&n->conf); + blkconf_apply_backend_options(&n->conf, blk_is_read_only(n->conf.blk), + false, &local_err); + if (local_err) { + error_report_err(local_err); + return -1; + } =20 pci_conf =3D pci_dev->config; pci_conf[PCI_INTERRUPT_PIN] =3D 1; diff --git a/hw/block/onenand.c b/hw/block/onenand.c index 8d84227..ddf5492 100644 --- a/hw/block/onenand.c +++ b/hw/block/onenand.c @@ -778,6 +778,7 @@ static int onenand_initfn(SysBusDevice *sbd) OneNANDState *s =3D ONE_NAND(dev); uint32_t size =3D 1 << (24 + ((s->id.dev >> 4) & 7)); void *ram; + Error *local_err =3D NULL; =20 s->base =3D (hwaddr)-1; s->rdy =3D NULL; @@ -796,6 +797,12 @@ static int onenand_initfn(SysBusDevice *sbd) error_report("Can't use a read-only drive"); return -1; } + blk_set_perm(s->blk, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE, + BLK_PERM_ALL, &local_err); + if (local_err) { + error_report_err(local_err); + return -1; + } s->blk_cur =3D s->blk; } s->otp =3D memset(g_malloc((64 + 2) << PAGE_SHIFT), diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 71b98a3..594d4cf 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -758,6 +758,18 @@ static void pflash_cfi01_realize(DeviceState *dev, Err= or **errp) sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem); =20 if (pfl->blk) { + uint64_t perm; + pfl->ro =3D blk_is_read_only(pfl->blk); + perm =3D BLK_PERM_CONSISTENT_READ | (pfl->ro ? 0 : BLK_PERM_WRITE); + ret =3D blk_set_perm(pfl->blk, perm, BLK_PERM_ALL, errp); + if (ret < 0) { + return; + } + } else { + pfl->ro =3D 0; + } + + if (pfl->blk) { /* read the initial flash content */ ret =3D blk_pread(pfl->blk, 0, pfl->storage, total_len); =20 @@ -768,12 +780,6 @@ static void pflash_cfi01_realize(DeviceState *dev, Err= or **errp) } } =20 - if (pfl->blk) { - pfl->ro =3D blk_is_read_only(pfl->blk); - } else { - pfl->ro =3D 0; - } - /* Default to devices being used at their maximum device width. This w= as * assumed before the device_width support was added. */ diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index ef71322..e6c5c6c 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -632,6 +632,19 @@ static void pflash_cfi02_realize(DeviceState *dev, Err= or **errp) vmstate_register_ram(&pfl->orig_mem, DEVICE(pfl)); pfl->storage =3D memory_region_get_ram_ptr(&pfl->orig_mem); pfl->chip_len =3D chip_len; + + if (pfl->blk) { + uint64_t perm; + pfl->ro =3D blk_is_read_only(pfl->blk); + perm =3D BLK_PERM_CONSISTENT_READ | (pfl->ro ? 0 : BLK_PERM_WRITE); + ret =3D blk_set_perm(pfl->blk, perm, BLK_PERM_ALL, errp); + if (ret < 0) { + return; + } + } else { + pfl->ro =3D 0; + } + if (pfl->blk) { /* read the initial flash content */ ret =3D blk_pread(pfl->blk, 0, pfl->storage, chip_len); @@ -646,12 +659,6 @@ static void pflash_cfi02_realize(DeviceState *dev, Err= or **errp) pfl->rom_mode =3D 1; sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem); =20 - if (pfl->blk) { - pfl->ro =3D blk_is_read_only(pfl->blk); - } else { - pfl->ro =3D 0; - } - pfl->timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, pflash_timer, pfl); pfl->wcycle =3D 0; pfl->cmd =3D 0; diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 843bd2f..98c16a7 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -928,7 +928,13 @@ static void virtio_blk_device_realize(DeviceState *dev= , Error **errp) } =20 blkconf_serial(&conf->conf, &conf->serial); - blkconf_apply_backend_options(&conf->conf); + blkconf_apply_backend_options(&conf->conf, + blk_is_read_only(conf->conf.blk), true, + &err); + if (err) { + error_propagate(errp, err); + return; + } s->original_wce =3D blk_enable_write_cache(conf->conf.blk); blkconf_geometry(&conf->conf, NULL, 65535, 255, 255, &err); if (err) { diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-sys= tem.c index 66ba367..c34be1c 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -79,7 +79,6 @@ static void parse_drive(DeviceState *dev, const char *str= , void **ptr, if (!blk) { BlockDriverState *bs =3D bdrv_lookup_bs(NULL, str, NULL); if (bs) { - /* FIXME Use real permissions */ blk =3D blk_new(0, BLK_PERM_ALL); blk_created =3D true; =20 diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index bb3c377..b588d62 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -170,7 +170,6 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind = kind) return -1; } else { /* Anonymous BlockBackend for an empty drive */ - /* FIXME Use real permissions */ dev->conf.blk =3D blk_new(0, BLK_PERM_ALL); } } @@ -197,7 +196,11 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind= kind) return -1; } } - blkconf_apply_backend_options(&dev->conf); + blkconf_apply_backend_options(&dev->conf, kind =3D=3D IDE_CD, true, &e= rr); + if (err) { + error_report_err(err); + return -1; + } =20 if (ide_init_drive(s, dev->conf.blk, kind, dev->version, dev->serial, dev->model, dev->wwn, diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c index 65ba188..aa5d2c1 100644 --- a/hw/nvram/spapr_nvram.c +++ b/hw/nvram/spapr_nvram.c @@ -141,9 +141,17 @@ static void rtas_nvram_store(PowerPCCPU *cpu, sPAPRMac= hineState *spapr, static void spapr_nvram_realize(VIOsPAPRDevice *dev, Error **errp) { sPAPRNVRAM *nvram =3D VIO_SPAPR_NVRAM(dev); + int ret; =20 if (nvram->blk) { nvram->size =3D blk_getlength(nvram->blk); + + ret =3D blk_set_perm(nvram->blk, + BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE, + BLK_PERM_ALL, errp); + if (ret < 0) { + return; + } } else { nvram->size =3D DEFAULT_NVRAM_SIZE; } diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index c1ccfad..2c3aaa0 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2328,7 +2328,13 @@ static void scsi_realize(SCSIDevice *dev, Error **er= rp) return; } } - blkconf_apply_backend_options(&dev->conf); + blkconf_apply_backend_options(&dev->conf, + blk_is_read_only(s->qdev.conf.blk), true, + &err); + if (err) { + error_propagate(errp, err); + return; + } =20 if (s->qdev.conf.discard_granularity =3D=3D -1) { s->qdev.conf.discard_granularity =3D @@ -2380,7 +2386,6 @@ static void scsi_cd_realize(SCSIDevice *dev, Error **= errp) SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, dev); =20 if (!dev->conf.blk) { - /* FIXME Use real permissions */ dev->conf.blk =3D blk_new(0, BLK_PERM_ALL); } =20 diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 8e31491..ba47bff 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1887,6 +1887,7 @@ static void sd_instance_finalize(Object *obj) static void sd_realize(DeviceState *dev, Error **errp) { SDState *sd =3D SD_CARD(dev); + int ret; =20 if (sd->blk && blk_is_read_only(sd->blk)) { error_setg(errp, "Cannot use read-only drive as SD card"); @@ -1894,6 +1895,11 @@ static void sd_realize(DeviceState *dev, Error **err= p) } =20 if (sd->blk) { + ret =3D blk_set_perm(sd->blk, BLK_PERM_CONSISTENT_READ | BLK_PERM_= WRITE, + BLK_PERM_ALL, errp); + if (ret < 0) { + return; + } blk_set_dev_ops(sd->blk, &sd_block_ops, sd); } } diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index c607f76..a71b354 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -603,7 +603,11 @@ static void usb_msd_realize_storage(USBDevice *dev, Er= ror **errp) =20 blkconf_serial(&s->conf, &dev->serial); blkconf_blocksizes(&s->conf); - blkconf_apply_backend_options(&s->conf); + blkconf_apply_backend_options(&s->conf, blk_is_read_only(blk), true, &= err); + if (err) { + error_propagate(errp, err); + return; + } =20 /* * Hack alert: this pretends to be a block device, but it's really diff --git a/include/hw/block/block.h b/include/hw/block/block.h index df9d207..5d462eb 100644 --- a/include/hw/block/block.h +++ b/include/hw/block/block.h @@ -73,7 +73,8 @@ void blkconf_geometry(BlockConf *conf, int *trans, unsigned cyls_max, unsigned heads_max, unsigned secs= _max, Error **errp); void blkconf_blocksizes(BlockConf *conf); -void blkconf_apply_backend_options(BlockConf *conf); +void blkconf_apply_backend_options(BlockConf *conf, bool readonly, + bool resizable, Error **errp); =20 /* Hard disk geometry */ =20 diff --git a/tests/qemu-iotests/051.pc.out b/tests/qemu-iotests/051.pc.out index f1669c1..eb4b3b5 100644 --- a/tests/qemu-iotests/051.pc.out +++ b/tests/qemu-iotests/051.pc.out @@ -176,7 +176,7 @@ QEMU X.Y.Z monitor - type 'help' for more information =20 Testing: -drive file=3DTEST_DIR/t.qcow2,if=3Dide,readonly=3Don QEMU X.Y.Z monitor - type 'help' for more information -(qemu) QEMU_PROG: Can't use a read-only drive +(qemu) QEMU_PROG: Block node is read-only QEMU_PROG: Initialization of device ide-hd failed: Device initialization f= ailed. =20 Testing: -drive file=3DTEST_DIR/t.qcow2,if=3Dscsi,readonly=3Don @@ -197,12 +197,12 @@ QEMU X.Y.Z monitor - type 'help' for more information =20 Testing: -drive file=3DTEST_DIR/t.qcow2,if=3Dnone,id=3Ddisk,readonly=3Don = -device ide-drive,drive=3Ddisk QEMU X.Y.Z monitor - type 'help' for more information -(qemu) QEMU_PROG: -device ide-drive,drive=3Ddisk: Can't use a read-only dr= ive +(qemu) QEMU_PROG: -device ide-drive,drive=3Ddisk: Block node is read-only QEMU_PROG: -device ide-drive,drive=3Ddisk: Device initialization failed. =20 Testing: -drive file=3DTEST_DIR/t.qcow2,if=3Dnone,id=3Ddisk,readonly=3Don = -device ide-hd,drive=3Ddisk QEMU X.Y.Z monitor - type 'help' for more information -(qemu) QEMU_PROG: -device ide-hd,drive=3Ddisk: Can't use a read-only drive +(qemu) QEMU_PROG: -device ide-hd,drive=3Ddisk: Block node is read-only QEMU_PROG: -device ide-hd,drive=3Ddisk: Device initialization failed. =20 Testing: -drive file=3DTEST_DIR/t.qcow2,if=3Dnone,id=3Ddisk,readonly=3Don = -device lsi53c895a -device scsi-disk,drive=3Ddisk --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487693344632465.4721334999256; Tue, 21 Feb 2017 08:09:04 -0800 (PST) Received: from localhost ([::1]:46571 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCzu-0006TY-39 for importer@patchew.org; Tue, 21 Feb 2017 11:09:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43363) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuy-0000kr-CZ for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuv-00087j-LH for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34358) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBup-00084F-7c; Tue, 21 Feb 2017 09:59:43 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 4EF2BC04BD47; Tue, 21 Feb 2017 14:59:43 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudE030565; Tue, 21 Feb 2017 09:59:42 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:26 +0100 Message-Id: <1487689130-30373-31-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 21 Feb 2017 14:59:43 +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 30/54] hw/block: Introduce share-rw qdev property 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" By default, don't allow another writer for block devices that are attached to a guest device. For the cases where this setup is intended (e.g. using a cluster filesystem on the disk), the new option can be used to allow it. This change affects only devices using DEFINE_BLOCK_PROPERTIES(). Devices directly using DEFINE_PROP_DRIVE() still accept writers unconditionally. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- hw/block/block.c | 6 ++++-- include/hw/block/block.h | 4 +++- tests/qemu-iotests/172.out | 53 ++++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/hw/block/block.c b/hw/block/block.c index 7059ba1..27878d0 100644 --- a/hw/block/block.c +++ b/hw/block/block.c @@ -65,12 +65,14 @@ void blkconf_apply_backend_options(BlockConf *conf, boo= l readonly, perm |=3D BLK_PERM_WRITE; } =20 - /* TODO Remove BLK_PERM_WRITE unless explicitly configured so */ shared_perm =3D BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED | - BLK_PERM_GRAPH_MOD | BLK_PERM_WRITE; + BLK_PERM_GRAPH_MOD; if (resizable) { shared_perm |=3D BLK_PERM_RESIZE; } + if (conf->share_rw) { + shared_perm |=3D BLK_PERM_WRITE; + } =20 ret =3D blk_set_perm(blk, perm, shared_perm, errp); if (ret < 0) { diff --git a/include/hw/block/block.h b/include/hw/block/block.h index 5d462eb..721064b 100644 --- a/include/hw/block/block.h +++ b/include/hw/block/block.h @@ -26,6 +26,7 @@ typedef struct BlockConf { /* geometry, not all devices use this */ uint32_t cyls, heads, secs; OnOffAuto wce; + bool share_rw; BlockdevOnError rerror; BlockdevOnError werror; } BlockConf; @@ -53,7 +54,8 @@ static inline unsigned int get_physical_block_exp(BlockCo= nf *conf) DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0), \ DEFINE_PROP_UINT32("discard_granularity", _state, \ _conf.discard_granularity, -1), \ - DEFINE_PROP_ON_OFF_AUTO("write-cache", _state, _conf.wce, ON_OFF_AUTO_= AUTO) + DEFINE_PROP_ON_OFF_AUTO("write-cache", _state, _conf.wce, ON_OFF_AUTO_= AUTO), \ + DEFINE_PROP_BOOL("share-rw", _state, _conf.share_rw, false) =20 #define DEFINE_BLOCK_CHS_PROPERTIES(_state, _conf) \ DEFINE_PROP_UINT32("cyls", _state, _conf.cyls, 0), \ diff --git a/tests/qemu-iotests/172.out b/tests/qemu-iotests/172.out index 6b7edaf..54b5329 100644 --- a/tests/qemu-iotests/172.out +++ b/tests/qemu-iotests/172.out @@ -28,6 +28,7 @@ Testing: opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "288" =20 =20 @@ -57,6 +58,7 @@ Testing: -fda TEST_DIR/t.qcow2 opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -fdb TEST_DIR/t.qcow2 @@ -83,6 +85,7 @@ Testing: -fdb TEST_DIR/t.qcow2 opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" dev: floppy, id "" unit =3D 0 (0x0) @@ -93,6 +96,7 @@ Testing: -fdb TEST_DIR/t.qcow2 opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "288" =20 Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2 @@ -119,6 +123,7 @@ Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2 opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" dev: floppy, id "" unit =3D 0 (0x0) @@ -129,6 +134,7 @@ Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2 opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 =20 @@ -158,6 +164,7 @@ Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2 opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2,index=3D1 @@ -184,6 +191,7 @@ Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2,ind= ex=3D1 opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" dev: floppy, id "" unit =3D 0 (0x0) @@ -194,6 +202,7 @@ Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2,ind= ex=3D1 opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "288" =20 Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2 -drive if=3Dfloppy,fil= e=3DTEST_DIR/t.qcow2,index=3D1 @@ -220,6 +229,7 @@ Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2 -dr= ive if=3Dfloppy,file=3DTEST_DIR/t opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" dev: floppy, id "" unit =3D 0 (0x0) @@ -230,6 +240,7 @@ Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2 -dr= ive if=3Dfloppy,file=3DTEST_DIR/t opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 =20 @@ -259,6 +270,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -glob= al isa-fdc.driveA=3Dnone0 opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -global isa-fdc.driveB= =3Dnone0 @@ -285,6 +297,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -glob= al isa-fdc.driveB=3Dnone0 opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -global isa-fdc.driveA=3Dnone0 -global isa-fdc.driveB=3Dno= ne1 @@ -311,6 +324,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -driv= e if=3Dnone,file=3DTEST_DIR/t.qco opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" dev: floppy, id "" unit =3D 0 (0x0) @@ -321,6 +335,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -driv= e if=3Dnone,file=3DTEST_DIR/t.qco opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 =20 @@ -350,6 +365,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -devi= ce floppy,drive=3Dnone0 opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -device floppy,drive=3Dn= one0,unit=3D1 @@ -376,6 +392,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -devi= ce floppy,drive=3Dnone0,unit=3D1 opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -device floppy,drive=3Dnone0 -device floppy,drive=3Dnone1,= unit=3D1 @@ -402,6 +419,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -driv= e if=3Dnone,file=3DTEST_DIR/t.qco opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" dev: floppy, id "" unit =3D 0 (0x0) @@ -412,6 +430,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -driv= e if=3Dnone,file=3DTEST_DIR/t.qco opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 =20 @@ -441,6 +460,7 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -global isa- opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" dev: floppy, id "" unit =3D 0 (0x0) @@ -451,6 +471,7 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -global isa- opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -fdb TEST_DIR/t.qcow2 -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -g= lobal isa-fdc.driveA=3Dnone0 @@ -477,6 +498,7 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -global isa- opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" dev: floppy, id "" unit =3D 0 (0x0) @@ -487,6 +509,7 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -global isa- opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -fda TEST_DIR/t.qcow2 -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -g= lobal isa-fdc.driveA=3Dnone0 @@ -513,6 +536,7 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -global isa- opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -fdb TEST_DIR/t.qcow2 -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -g= lobal isa-fdc.driveB=3Dnone0 @@ -539,6 +563,7 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -global isa- opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 =20 @@ -568,6 +593,7 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -device flop opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" dev: floppy, id "" unit =3D 0 (0x0) @@ -578,6 +604,7 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -device flop opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -fda TEST_DIR/t.qcow2 -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -d= evice floppy,drive=3Dnone0,unit=3D1 @@ -604,6 +631,7 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -device flop opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" dev: floppy, id "" unit =3D 0 (0x0) @@ -614,6 +642,7 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -device flop opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -fdb TEST_DIR/t.qcow2 -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -d= evice floppy,drive=3Dnone0 @@ -640,6 +669,7 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -device flop opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" dev: floppy, id "" unit =3D 1 (0x1) @@ -650,6 +680,7 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -device flop opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -fdb TEST_DIR/t.qcow2 -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -d= evice floppy,drive=3Dnone0,unit=3D0 @@ -676,6 +707,7 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -device flop opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" dev: floppy, id "" unit =3D 1 (0x1) @@ -686,6 +718,7 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -device flop opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -fda TEST_DIR/t.qcow2 -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -d= evice floppy,drive=3Dnone0,unit=3D0 @@ -723,6 +756,7 @@ Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2 -dr= ive if=3Dnone,file=3DTEST_DIR/t.q opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" dev: floppy, id "" unit =3D 0 (0x0) @@ -733,6 +767,7 @@ Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2 -dr= ive if=3Dnone,file=3DTEST_DIR/t.q opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2 -drive if=3Dnone,file= =3DTEST_DIR/t.qcow2 -device floppy,drive=3Dnone0,unit=3D1 @@ -759,6 +794,7 @@ Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2 -dr= ive if=3Dnone,file=3DTEST_DIR/t.q opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" dev: floppy, id "" unit =3D 0 (0x0) @@ -769,6 +805,7 @@ Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2 -dr= ive if=3Dnone,file=3DTEST_DIR/t.q opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2 -drive if=3Dnone,file= =3DTEST_DIR/t.qcow2 -device floppy,drive=3Dnone0,unit=3D0 @@ -802,6 +839,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -driv= e if=3Dnone,file=3DTEST_DIR/t.qco opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" dev: floppy, id "" unit =3D 0 (0x0) @@ -812,6 +850,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -driv= e if=3Dnone,file=3DTEST_DIR/t.qco opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -global isa-fdc.driveA=3Dnone0 -device floppy,drive=3Dnone= 1,unit=3D1 @@ -838,6 +877,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -driv= e if=3Dnone,file=3DTEST_DIR/t.qco opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" dev: floppy, id "" unit =3D 0 (0x0) @@ -848,6 +888,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -driv= e if=3Dnone,file=3DTEST_DIR/t.qco opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -global isa-fdc.driveB=3Dnone0 -device floppy,drive=3Dnone1 @@ -874,6 +915,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -driv= e if=3Dnone,file=3DTEST_DIR/t.qco opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" dev: floppy, id "" unit =3D 1 (0x1) @@ -884,6 +926,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -driv= e if=3Dnone,file=3DTEST_DIR/t.qco opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -global isa-fdc.driveB=3Dnone0 -device floppy,drive=3Dnone= 1,unit=3D0 @@ -910,6 +953,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -driv= e if=3Dnone,file=3DTEST_DIR/t.qco opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" dev: floppy, id "" unit =3D 1 (0x1) @@ -920,6 +964,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -driv= e if=3Dnone,file=3DTEST_DIR/t.qco opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2 -global isa-fdc.driveA=3Dnone0 -device floppy,drive=3Dnone= 1,unit=3D0 @@ -964,6 +1009,7 @@ Testing: -device floppy opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "288" =20 Testing: -device floppy,drive-type=3D120 @@ -990,6 +1036,7 @@ Testing: -device floppy,drive-type=3D120 opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "120" =20 Testing: -device floppy,drive-type=3D144 @@ -1016,6 +1063,7 @@ Testing: -device floppy,drive-type=3D144 opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -device floppy,drive-type=3D288 @@ -1042,6 +1090,7 @@ Testing: -device floppy,drive-type=3D288 opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "288" =20 =20 @@ -1071,6 +1120,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -de= vice floppy,drive=3Dnone0,drive-t opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "120" =20 Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -device floppy,drive=3Dn= one0,drive-type=3D288 @@ -1097,6 +1147,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -de= vice floppy,drive=3Dnone0,drive-t opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "288" =20 =20 @@ -1126,6 +1177,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -de= vice floppy,drive=3Dnone0,logical opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -device floppy,drive=3Dn= one0,physical_block_size=3D512 @@ -1152,6 +1204,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -de= vice floppy,drive=3Dnone0,physica opt_io_size =3D 0 (0x0) discard_granularity =3D 4294967295 (0xffffffff) write-cache =3D "auto" + share-rw =3D false drive-type =3D "144" =20 Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -device floppy,drive=3Dn= one0,logical_block_size=3D4096 --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487693722588423.8950915920577; Tue, 21 Feb 2017 08:15:22 -0800 (PST) Received: from localhost ([::1]:46611 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgD60-0004ol-08 for importer@patchew.org; Tue, 21 Feb 2017 11:15:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43371) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuy-0000l2-KV for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBux-00088h-4J for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49952) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuq-00085A-O4; Tue, 21 Feb 2017 09:59:44 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 B71BC3A768D; Tue, 21 Feb 2017 14:59:44 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudF030565; Tue, 21 Feb 2017 09:59:43 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:27 +0100 Message-Id: <1487689130-30373-32-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 21 Feb 2017 14:59:44 +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 31/54] blockjob: Add permissions to block_job_create() 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" This functions creates a BlockBackend internally, so the block jobs need to tell it what they want to do with the BB. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/backup.c | 5 +++-- block/commit.c | 5 +++-- block/mirror.c | 5 +++-- block/stream.c | 5 +++-- blockjob.c | 6 +++--- include/block/blockjob_int.h | 4 +++- tests/test-blockjob-txn.c | 6 +++--- tests/test-blockjob.c | 5 +++-- 8 files changed, 24 insertions(+), 17 deletions(-) diff --git a/block/backup.c b/block/backup.c index f38d1d0..c759684 100644 --- a/block/backup.c +++ b/block/backup.c @@ -618,8 +618,9 @@ BlockJob *backup_job_create(const char *job_id, BlockDr= iverState *bs, goto error; } =20 - job =3D block_job_create(job_id, &backup_job_driver, bs, speed, - creation_flags, cb, opaque, errp); + /* FIXME Use real permissions */ + job =3D block_job_create(job_id, &backup_job_driver, bs, 0, BLK_PERM_A= LL, + speed, creation_flags, cb, opaque, errp); if (!job) { goto error; } diff --git a/block/commit.c b/block/commit.c index 2ad8138..60d29a9 100644 --- a/block/commit.c +++ b/block/commit.c @@ -235,8 +235,9 @@ void commit_start(const char *job_id, BlockDriverState = *bs, return; } =20 - s =3D block_job_create(job_id, &commit_job_driver, bs, speed, - BLOCK_JOB_DEFAULT, NULL, NULL, errp); + /* FIXME Use real permissions */ + s =3D block_job_create(job_id, &commit_job_driver, bs, 0, BLK_PERM_ALL, + speed, BLOCK_JOB_DEFAULT, NULL, NULL, errp); if (!s) { return; } diff --git a/block/mirror.c b/block/mirror.c index c551bfc..9a61c1e 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1010,8 +1010,9 @@ static void mirror_start_job(const char *job_id, Bloc= kDriverState *bs, buf_size =3D DEFAULT_MIRROR_BUF_SIZE; } =20 - s =3D block_job_create(job_id, driver, bs, speed, creation_flags, - cb, opaque, errp); + /* FIXME Use real permissions */ + s =3D block_job_create(job_id, driver, bs, 0, BLK_PERM_ALL, speed, + creation_flags, cb, opaque, errp); if (!s) { return; } diff --git a/block/stream.c b/block/stream.c index 1523ba7..7f49279 100644 --- a/block/stream.c +++ b/block/stream.c @@ -229,8 +229,9 @@ void stream_start(const char *job_id, BlockDriverState = *bs, BlockDriverState *iter; int orig_bs_flags; =20 - s =3D block_job_create(job_id, &stream_job_driver, bs, speed, - BLOCK_JOB_DEFAULT, NULL, NULL, errp); + /* FIXME Use real permissions */ + s =3D block_job_create(job_id, &stream_job_driver, bs, 0, BLK_PERM_ALL, + speed, BLOCK_JOB_DEFAULT, NULL, NULL, errp); if (!s) { return; } diff --git a/blockjob.c b/blockjob.c index 72b7d4c..27833c7 100644 --- a/blockjob.c +++ b/blockjob.c @@ -123,7 +123,8 @@ void block_job_add_bdrv(BlockJob *job, BlockDriverState= *bs) } =20 void *block_job_create(const char *job_id, const BlockJobDriver *driver, - BlockDriverState *bs, int64_t speed, int flags, + BlockDriverState *bs, uint64_t perm, + uint64_t shared_perm, int64_t speed, int flags, BlockCompletionFunc *cb, void *opaque, Error **errp) { BlockBackend *blk; @@ -160,8 +161,7 @@ void *block_job_create(const char *job_id, const BlockJ= obDriver *driver, } } =20 - /* FIXME Use real permissions */ - blk =3D blk_new(0, BLK_PERM_ALL); + blk =3D blk_new(perm, shared_perm); ret =3D blk_insert_bs(blk, bs, errp); if (ret < 0) { blk_unref(blk); diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index 8223822..3f86cc5 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -119,6 +119,7 @@ struct BlockJobDriver { * generated automatically. * @job_type: The class object for the newly-created job. * @bs: The block + * @perm, @shared_perm: Permissions to request for @bs * @speed: The maximum speed, in bytes per second, or 0 for unlimited. * @cb: Completion function for the job. * @opaque: Opaque pointer value passed to @cb. @@ -134,7 +135,8 @@ struct BlockJobDriver { * called from a wrapper that is specific to the job type. */ void *block_job_create(const char *job_id, const BlockJobDriver *driver, - BlockDriverState *bs, int64_t speed, int flags, + BlockDriverState *bs, uint64_t perm, + uint64_t shared_perm, int64_t speed, int flags, BlockCompletionFunc *cb, void *opaque, Error **errp= ); =20 /** diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c index f6dfd08..4ccbda1 100644 --- a/tests/test-blockjob-txn.c +++ b/tests/test-blockjob-txn.c @@ -101,9 +101,9 @@ static BlockJob *test_block_job_start(unsigned int iter= ations, g_assert_nonnull(bs); =20 snprintf(job_id, sizeof(job_id), "job%u", counter++); - s =3D block_job_create(job_id, &test_block_job_driver, bs, 0, - BLOCK_JOB_DEFAULT, test_block_job_cb, - data, &error_abort); + s =3D block_job_create(job_id, &test_block_job_driver, bs, + 0, BLK_PERM_ALL, 0, BLOCK_JOB_DEFAULT, + test_block_job_cb, data, &error_abort); s->iterations =3D iterations; s->use_timer =3D use_timer; s->rc =3D rc; diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c index 143ce96..1afe17b 100644 --- a/tests/test-blockjob.c +++ b/tests/test-blockjob.c @@ -30,8 +30,9 @@ static BlockJob *do_test_id(BlockBackend *blk, const char= *id, BlockJob *job; Error *errp =3D NULL; =20 - job =3D block_job_create(id, &test_block_job_driver, blk_bs(blk), 0, - BLOCK_JOB_DEFAULT, block_job_cb, NULL, &errp); + job =3D block_job_create(id, &test_block_job_driver, blk_bs(blk), + 0, BLK_PERM_ALL, 0, BLOCK_JOB_DEFAULT, block_jo= b_cb, + NULL, &errp); if (should_succeed) { g_assert_null(errp); g_assert_nonnull(job); --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487693012559973.5536014628624; Tue, 21 Feb 2017 08:03:32 -0800 (PST) Received: from localhost ([::1]:46542 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCuW-0001pJ-76 for importer@patchew.org; Tue, 21 Feb 2017 11:03:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43357) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuy-0000kd-59 for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuw-00088S-Tv for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35712) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBus-00085m-6M; Tue, 21 Feb 2017 09:59:46 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 322B261B91; Tue, 21 Feb 2017 14:59:46 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudG030565; Tue, 21 Feb 2017 09:59:44 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:28 +0100 Message-Id: <1487689130-30373-33-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 21 Feb 2017 14:59:46 +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 32/54] block: Add BdrvChildRole.get_parent_desc() 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" For meaningful error messages in the permission system, we need to get some human-readable description of the parent of a BdrvChild. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 9 +++++++++ block/block-backend.c | 21 +++++++++++++++++++++ include/block/block_int.h | 6 ++++++ 3 files changed, 36 insertions(+) diff --git a/block.c b/block.c index 9f46698..19cf3b0 100644 --- a/block.c +++ b/block.c @@ -707,6 +707,12 @@ int bdrv_parse_cache_mode(const char *mode, int *flags= , bool *writethrough) return 0; } =20 +static char *bdrv_child_get_parent_desc(BdrvChild *c) +{ + BlockDriverState *parent =3D c->opaque; + return g_strdup(bdrv_get_device_or_node_name(parent)); +} + static void bdrv_child_cb_drained_begin(BdrvChild *child) { BlockDriverState *bs =3D child->opaque; @@ -774,6 +780,7 @@ static void bdrv_inherited_options(int *child_flags, QD= ict *child_options, } =20 const BdrvChildRole child_file =3D { + .get_parent_desc =3D bdrv_child_get_parent_desc, .inherit_options =3D bdrv_inherited_options, .drained_begin =3D bdrv_child_cb_drained_begin, .drained_end =3D bdrv_child_cb_drained_end, @@ -794,6 +801,7 @@ static void bdrv_inherited_fmt_options(int *child_flags= , QDict *child_options, } =20 const BdrvChildRole child_format =3D { + .get_parent_desc =3D bdrv_child_get_parent_desc, .inherit_options =3D bdrv_inherited_fmt_options, .drained_begin =3D bdrv_child_cb_drained_begin, .drained_end =3D bdrv_child_cb_drained_end, @@ -824,6 +832,7 @@ static void bdrv_backing_options(int *child_flags, QDic= t *child_options, } =20 const BdrvChildRole child_backing =3D { + .get_parent_desc =3D bdrv_child_get_parent_desc, .inherit_options =3D bdrv_backing_options, .drained_begin =3D bdrv_child_cb_drained_begin, .drained_end =3D bdrv_child_cb_drained_end, diff --git a/block/block-backend.c b/block/block-backend.c index fcc42b5..38a3858 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -80,6 +80,7 @@ static const AIOCBInfo block_backend_aiocb_info =3D { =20 static void drive_info_del(DriveInfo *dinfo); static BlockBackend *bdrv_first_blk(BlockDriverState *bs); +static char *blk_get_attached_dev_id(BlockBackend *blk); =20 /* All BlockBackends */ static QTAILQ_HEAD(, BlockBackend) block_backends =3D @@ -102,6 +103,25 @@ static void blk_root_drained_end(BdrvChild *child); static void blk_root_change_media(BdrvChild *child, bool load); static void blk_root_resize(BdrvChild *child); =20 +static char *blk_root_get_parent_desc(BdrvChild *child) +{ + BlockBackend *blk =3D child->opaque; + char *dev_id; + + if (blk->name) { + return g_strdup(blk->name); + } + + dev_id =3D blk_get_attached_dev_id(blk); + if (*dev_id) { + return dev_id; + } else { + /* TODO Callback into the BB owner for something more detailed */ + g_free(dev_id); + return g_strdup("a block device"); + } +} + static const char *blk_root_get_name(BdrvChild *child) { return blk_name(child->opaque); @@ -113,6 +133,7 @@ static const BdrvChildRole child_root =3D { .change_media =3D blk_root_change_media, .resize =3D blk_root_resize, .get_name =3D blk_root_get_name, + .get_parent_desc =3D blk_root_get_parent_desc, =20 .drained_begin =3D blk_root_drained_begin, .drained_end =3D blk_root_drained_end, diff --git a/include/block/block_int.h b/include/block/block_int.h index e00d0f4..3177b9f 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -452,6 +452,12 @@ struct BdrvChildRole { * name), or NULL if the parent can't provide a better name. */ const char* (*get_name)(BdrvChild *child); =20 + /* Returns a malloced string that describes the parent of the child fo= r a + * human reader. This could be a node-name, BlockBackend name, qdev ID= or + * QOM path of the device owning the BlockBackend, job type and ID etc= . The + * caller is responsible for freeing the memory. */ + char* (*get_parent_desc)(BdrvChild *child); + /* * If this pair of functions is implemented, the parent doesn't issue = new * requests after returning from .drained_begin() until .drained_end()= is --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487693065509276.8581455187219; Tue, 21 Feb 2017 08:04:25 -0800 (PST) Received: from localhost ([::1]:46545 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCvL-0002WA-Ku for importer@patchew.org; Tue, 21 Feb 2017 11:04:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43349) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBux-0000kO-TO for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuw-00088I-ON for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34374) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBut-00086N-R3; Tue, 21 Feb 2017 09:59:48 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 C2724C04BD47; Tue, 21 Feb 2017 14:59:47 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudH030565; Tue, 21 Feb 2017 09:59:46 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:29 +0100 Message-Id: <1487689130-30373-34-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 21 Feb 2017 14:59:47 +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 33/54] block: Include details on permission errors in message 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" Instead of just telling that there was some conflict, we can be specific and tell which permissions were in conflict and which way the conflict is. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-------= ---- 1 file changed, 56 insertions(+), 11 deletions(-) diff --git a/block.c b/block.c index 19cf3b0..a8a2fa7 100644 --- a/block.c +++ b/block.c @@ -1461,6 +1461,43 @@ static void bdrv_update_perm(BlockDriverState *bs) bdrv_set_perm(bs, cumulative_perms, cumulative_shared_perms); } =20 +static char *bdrv_child_user(BdrvChild *c) +{ + if (c->role->get_parent_desc) { + return c->role->get_parent_desc(c); + } + + return g_strdup("another user"); +} + +static char *bdrv_perm_names(uint64_t perm) +{ + struct perm_name { + uint64_t perm; + const char *name; + } permissions[] =3D { + { BLK_PERM_CONSISTENT_READ, "consistent read" }, + { BLK_PERM_WRITE, "write" }, + { BLK_PERM_WRITE_UNCHANGED, "write unchanged" }, + { BLK_PERM_RESIZE, "resize" }, + { BLK_PERM_GRAPH_MOD, "change children" }, + { 0, NULL } + }; + + char *result =3D g_strdup(""); + struct perm_name *p; + + for (p =3D permissions; p->name; p++) { + if (perm & p->perm) { + char *old =3D result; + result =3D g_strdup_printf("%s%s%s", old, *old ? ", " : "", p-= >name); + g_free(old); + } + } + + return result; +} + /* * Checks whether a new reference to @bs can be added if the new user requ= ires * @new_used_perm/@new_shared_perm as its permissions. If @ignore_child is= set, @@ -1485,17 +1522,25 @@ static int bdrv_check_update_perm(BlockDriverState = *bs, uint64_t new_used_perm, continue; } =20 - if ((new_used_perm & c->shared_perm) !=3D new_used_perm || - (c->perm & new_shared_perm) !=3D c->perm) - { - const char *user =3D NULL; - if (c->role->get_name) { - user =3D c->role->get_name(c); - if (user && !*user) { - user =3D NULL; - } - } - error_setg(errp, "Conflicts with %s", user ?: "another operati= on"); + if ((new_used_perm & c->shared_perm) !=3D new_used_perm) { + char *user =3D bdrv_child_user(c); + char *perm_names =3D bdrv_perm_names(new_used_perm & ~c->share= d_perm); + error_setg(errp, "Conflicts with use by %s as '%s', which does= not " + "allow '%s' on %s", + user, c->name, perm_names, bdrv_get_node_name(c->bs= )); + g_free(user); + g_free(perm_names); + return -EPERM; + } + + if ((c->perm & new_shared_perm) !=3D c->perm) { + char *user =3D bdrv_child_user(c); + char *perm_names =3D bdrv_perm_names(c->perm & ~new_shared_per= m); + error_setg(errp, "Conflicts with use by %s as '%s', which uses= " + "'%s' on %s", + user, c->name, perm_names, bdrv_get_node_name(c->bs= )); + g_free(user); + g_free(perm_names); return -EPERM; } =20 --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487693469618846.939027682647; Tue, 21 Feb 2017 08:11:09 -0800 (PST) Received: from localhost ([::1]:46585 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgD1u-0000Ux-GN for importer@patchew.org; Tue, 21 Feb 2017 11:11:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43364) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuy-0000ks-Cd for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBux-00088o-Em for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49976) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuv-00087A-7i; Tue, 21 Feb 2017 09:59:49 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 496F637F1F; Tue, 21 Feb 2017 14:59:49 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudI030565; Tue, 21 Feb 2017 09:59:47 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:30 +0100 Message-Id: <1487689130-30373-35-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 21 Feb 2017 14:59:49 +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 34/54] block: Add BdrvChildRole.stay_at_node 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" When the parents' child links are updated in bdrv_append() or bdrv_replace_in_backing_chain(), this should affect all child links of BlockBackends or other nodes, but not on child links held for other purposes (like for setting permissions). This patch allows to control the behaviour per BdrvChildRole. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 3 +++ include/block/block_int.h | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/block.c b/block.c index a8a2fa7..c7c0a8b 100644 --- a/block.c +++ b/block.c @@ -2832,6 +2832,9 @@ static void change_parent_backing_link(BlockDriverSta= te *from, BdrvChild *c, *next, *to_c; =20 QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) { + if (c->role->stay_at_node) { + continue; + } if (c->role =3D=3D &child_backing) { /* @from is generally not allowed to be a backing file, except= for * when @to is the overlay. In that case, @from may not be rep= laced diff --git a/include/block/block_int.h b/include/block/block_int.h index 3177b9f..a0d9328 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -441,6 +441,10 @@ typedef struct BdrvAioNotifier { } BdrvAioNotifier; =20 struct BdrvChildRole { + /* If true, bdrv_replace_in_backing_chain() doesn't change the node th= is + * BdrvChild points to. */ + bool stay_at_node; + void (*inherit_options)(int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options); =20 --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487693618682781.9129196837929; Tue, 21 Feb 2017 08:13:38 -0800 (PST) Received: from localhost ([::1]:46601 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgD4I-0003Js-OR for importer@patchew.org; Tue, 21 Feb 2017 11:13:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43455) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBv4-0000rc-6G for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuz-0008AJ-Rs for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35730) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuw-000881-Oj; Tue, 21 Feb 2017 09:59:50 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 CE8B161E4C; Tue, 21 Feb 2017 14:59:50 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudJ030565; Tue, 21 Feb 2017 09:59:49 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:31 +0100 Message-Id: <1487689130-30373-36-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 21 Feb 2017 14:59:50 +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 35/54] blockjob: Add permissions to block_job_add_bdrv() 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" Block jobs don't actually do I/O through the the reference they create with block_job_add_bdrv(), but they might want to use the permisssion system to express what the block job does to intermediate nodes. This adds permissions to block_job_add_bdrv() to provide the means to request permissions. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/backup.c | 4 +++- block/commit.c | 8 ++++++-- block/mirror.c | 9 +++++++-- block/stream.c | 4 +++- blockjob.c | 36 ++++++++++++++++++++++++++++++------ include/block/blockjob.h | 5 ++++- 6 files changed, 53 insertions(+), 13 deletions(-) diff --git a/block/backup.c b/block/backup.c index c759684..405f271 100644 --- a/block/backup.c +++ b/block/backup.c @@ -657,7 +657,9 @@ BlockJob *backup_job_create(const char *job_id, BlockDr= iverState *bs, job->cluster_size =3D MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster= _size); } =20 - block_job_add_bdrv(&job->common, target); + /* FIXME Use real permissions */ + block_job_add_bdrv(&job->common, "target", target, 0, BLK_PERM_ALL, + &error_abort); job->common.len =3D len; block_job_txn_add_job(txn, &job->common); =20 diff --git a/block/commit.c b/block/commit.c index 60d29a9..b69586f 100644 --- a/block/commit.c +++ b/block/commit.c @@ -267,13 +267,17 @@ void commit_start(const char *job_id, BlockDriverStat= e *bs, * disappear from the chain after this operation. */ assert(bdrv_chain_contains(top, base)); for (iter =3D top; iter !=3D backing_bs(base); iter =3D backing_bs(ite= r)) { - block_job_add_bdrv(&s->common, iter); + /* FIXME Use real permissions */ + block_job_add_bdrv(&s->common, "intermediate node", iter, 0, + BLK_PERM_ALL, &error_abort); } /* overlay_bs must be blocked because it needs to be modified to * update the backing image string, but if it's the root node then * don't block it again */ if (bs !=3D overlay_bs) { - block_job_add_bdrv(&s->common, overlay_bs); + /* FIXME Use real permissions */ + block_job_add_bdrv(&s->common, "overlay of top", overlay_bs, 0, + BLK_PERM_ALL, &error_abort); } =20 /* FIXME Use real permissions */ diff --git a/block/mirror.c b/block/mirror.c index 9a61c1e..767b7e7 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1047,13 +1047,18 @@ static void mirror_start_job(const char *job_id, Bl= ockDriverState *bs, return; } =20 - block_job_add_bdrv(&s->common, target); + /* FIXME Use real permissions */ + block_job_add_bdrv(&s->common, "target", target, 0, BLK_PERM_ALL, + &error_abort); + /* In commit_active_start() all intermediate nodes disappear, so * any jobs in them must be blocked */ if (bdrv_chain_contains(bs, target)) { BlockDriverState *iter; for (iter =3D backing_bs(bs); iter !=3D target; iter =3D backing_b= s(iter)) { - block_job_add_bdrv(&s->common, iter); + /* FIXME Use real permissions */ + block_job_add_bdrv(&s->common, "intermediate node", iter, 0, + BLK_PERM_ALL, &error_abort); } } =20 diff --git a/block/stream.c b/block/stream.c index 7f49279..ba8650f 100644 --- a/block/stream.c +++ b/block/stream.c @@ -248,7 +248,9 @@ void stream_start(const char *job_id, BlockDriverState = *bs, /* Block all intermediate nodes between bs and base, because they * will disappear from the chain after this operation */ for (iter =3D backing_bs(bs); iter && iter !=3D base; iter =3D backing= _bs(iter)) { - block_job_add_bdrv(&s->common, iter); + /* FIXME Use real permissions */ + block_job_add_bdrv(&s->common, "intermediate node", iter, 0, + BLK_PERM_ALL, &error_abort); } =20 s->base =3D base; diff --git a/blockjob.c b/blockjob.c index 27833c7..4216cde 100644 --- a/blockjob.c +++ b/blockjob.c @@ -55,6 +55,19 @@ struct BlockJobTxn { =20 static QLIST_HEAD(, BlockJob) block_jobs =3D QLIST_HEAD_INITIALIZER(block_= jobs); =20 +static char *child_job_get_parent_desc(BdrvChild *c) +{ + BlockJob *job =3D c->opaque; + return g_strdup_printf("%s job '%s'", + BlockJobType_lookup[job->driver->job_type], + job->id); +} + +static const BdrvChildRole child_job =3D { + .get_parent_desc =3D child_job_get_parent_desc, + .stay_at_node =3D true, +}; + BlockJob *block_job_next(BlockJob *job) { if (!job) { @@ -115,11 +128,22 @@ static void block_job_detach_aio_context(void *opaque) block_job_unref(job); } =20 -void block_job_add_bdrv(BlockJob *job, BlockDriverState *bs) +int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *= bs, + uint64_t perm, uint64_t shared_perm, Error **errp) { - job->nodes =3D g_slist_prepend(job->nodes, bs); + BdrvChild *c; + + c =3D bdrv_root_attach_child(bs, name, &child_job, perm, shared_perm, + job, errp); + if (c =3D=3D NULL) { + return -EPERM; + } + + job->nodes =3D g_slist_prepend(job->nodes, c); bdrv_ref(bs); bdrv_op_block_all(bs, job->blocker); + + return 0; } =20 void *block_job_create(const char *job_id, const BlockJobDriver *driver, @@ -171,7 +195,7 @@ void *block_job_create(const char *job_id, const BlockJ= obDriver *driver, job =3D g_malloc0(driver->instance_size); error_setg(&job->blocker, "block device is in use by block job: %s", BlockJobType_lookup[driver->job_type]); - block_job_add_bdrv(job, bs); + block_job_add_bdrv(job, "main node", bs, 0, BLK_PERM_ALL, &error_abort= ); bdrv_op_unblock(bs, BLOCK_OP_TYPE_DATAPLANE, job->blocker); =20 job->driver =3D driver; @@ -238,9 +262,9 @@ void block_job_unref(BlockJob *job) BlockDriverState *bs =3D blk_bs(job->blk); bs->job =3D NULL; for (l =3D job->nodes; l; l =3D l->next) { - bs =3D l->data; - bdrv_op_unblock_all(bs, job->blocker); - bdrv_unref(bs); + BdrvChild *c =3D l->data; + bdrv_op_unblock_all(c->bs, job->blocker); + bdrv_root_unref_child(c); } g_slist_free(job->nodes); blk_remove_aio_context_notifier(job->blk, diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 1acb256..9d65ef8 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -169,13 +169,16 @@ BlockJob *block_job_get(const char *id); /** * block_job_add_bdrv: * @job: A block job + * @name: The name to assign to the new BdrvChild * @bs: A BlockDriverState that is involved in @job + * @perm, @shared_perm: Permissions to request on the node * * Add @bs to the list of BlockDriverState that are involved in * @job. This means that all operations will be blocked on @bs while * @job exists. */ -void block_job_add_bdrv(BlockJob *job, BlockDriverState *bs); +int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *= bs, + uint64_t perm, uint64_t shared_perm, Error **errp); =20 /** * block_job_set_speed: --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487691289321486.5258765308571; Tue, 21 Feb 2017 07:34:49 -0800 (PST) Received: from localhost ([::1]:46372 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCSj-0007uy-IG for importer@patchew.org; Tue, 21 Feb 2017 10:34:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43487) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBv6-0000us-Pw for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBv1-0008B3-Q2 for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35748) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuy-000897-CG; Tue, 21 Feb 2017 09:59:52 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 679F461E4C; Tue, 21 Feb 2017 14:59:52 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudK030565; Tue, 21 Feb 2017 09:59:50 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:32 +0100 Message-Id: <1487689130-30373-37-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 21 Feb 2017 14:59:52 +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 36/54] commit: Use real permissions in commit 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" This is probably one of the most interesting conversions to the new op blocker system because a commit block job intentionally leaves some intermediate block nodes in the backing chain that aren't valid on their own any more; only the whole chain together results in a valid view. In order to provide the 'consistent read' permission to the parents of the 'top' node of the commit job, a new filter block driver is inserted above 'top' which doesn't require 'consistent read' on its backing chain. Subsequently, the commit job can block 'consistent read' on all intermediate nodes without causing a conflict. Signed-off-by: Kevin Wolf --- block/commit.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++-----= ---- 1 file changed, 91 insertions(+), 17 deletions(-) diff --git a/block/commit.c b/block/commit.c index b69586f..9336237 100644 --- a/block/commit.c +++ b/block/commit.c @@ -36,6 +36,7 @@ typedef struct CommitBlockJob { BlockJob common; RateLimit limit; BlockDriverState *active; + BlockDriverState *commit_top_bs; BlockBackend *top; BlockBackend *base; BlockdevOnError on_error; @@ -83,12 +84,19 @@ static void commit_complete(BlockJob *job, void *opaque) BlockDriverState *active =3D s->active; BlockDriverState *top =3D blk_bs(s->top); BlockDriverState *base =3D blk_bs(s->base); - BlockDriverState *overlay_bs =3D bdrv_find_overlay(active, top); + BlockDriverState *overlay_bs =3D bdrv_find_overlay(active, s->commit_t= op_bs); int ret =3D data->ret; + bool remove_commit_top_bs =3D false; =20 if (!block_job_is_cancelled(&s->common) && ret =3D=3D 0) { /* success */ - ret =3D bdrv_drop_intermediate(active, top, base, s->backing_file_= str); + ret =3D bdrv_drop_intermediate(active, s->commit_top_bs, base, + s->backing_file_str); + } else if (overlay_bs) { + /* XXX Can (or should) we somehow keep 'consistent read' blocked e= ven + * after the failed/cancelled commit job is gone? If we already wr= ote + * something to base, the intermediate images aren't valid any mor= e. */ + remove_commit_top_bs =3D true; } =20 /* restore base open flags here if appropriate (e.g., change the base = back @@ -105,6 +113,13 @@ static void commit_complete(BlockJob *job, void *opaqu= e) blk_unref(s->base); block_job_completed(&s->common, ret); g_free(data); + + /* If bdrv_drop_intermediate() didn't already do that, remove the comm= it + * filter driver from the backing chain. Do this as the final step so = that + * the 'consistent read' permission can be granted. */ + if (remove_commit_top_bs) { + bdrv_set_backing_hd(overlay_bs, top); + } } =20 static void coroutine_fn commit_run(void *opaque) @@ -208,6 +223,34 @@ static const BlockJobDriver commit_job_driver =3D { .start =3D commit_run, }; =20 +static int coroutine_fn bdrv_commit_top_preadv(BlockDriverState *bs, + uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags) +{ + return bdrv_co_preadv(bs->backing, offset, bytes, qiov, flags); +} + +static void bdrv_commit_top_close(BlockDriverState *bs) +{ +} + +static void bdrv_commit_top_child_perm(BlockDriverState *bs, BdrvChild *c, + const BdrvChildRole *role, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) +{ + *nperm =3D 0; + *nshared =3D BLK_PERM_ALL; +} + +/* Dummy node that provides consistent read to its users without requiring= it + * from its backing file and that allows writes on the backing file chain.= */ +static BlockDriver bdrv_commit_top =3D { + .format_name =3D "commit_top", + .bdrv_co_preadv =3D bdrv_commit_top_preadv, + .bdrv_close =3D bdrv_commit_top_close, + .bdrv_child_perm =3D bdrv_commit_top_child_perm, +}; + void commit_start(const char *job_id, BlockDriverState *bs, BlockDriverState *base, BlockDriverState *top, int64_t s= peed, BlockdevOnError on_error, const char *backing_file_str, @@ -219,6 +262,7 @@ void commit_start(const char *job_id, BlockDriverState = *bs, int orig_base_flags; BlockDriverState *iter; BlockDriverState *overlay_bs; + BlockDriverState *commit_top_bs =3D NULL; Error *local_err =3D NULL; int ret; =20 @@ -235,7 +279,6 @@ void commit_start(const char *job_id, BlockDriverState = *bs, return; } =20 - /* FIXME Use real permissions */ s =3D block_job_create(job_id, &commit_job_driver, bs, 0, BLK_PERM_ALL, speed, BLOCK_JOB_DEFAULT, NULL, NULL, errp); if (!s) { @@ -262,34 +305,62 @@ void commit_start(const char *job_id, BlockDriverStat= e *bs, } } =20 + /* Insert commit_top block node above top, so we can block consistent = read + * on the backing chain below it */ + commit_top_bs =3D bdrv_new_open_driver(&bdrv_commit_top, NULL, BDRV_O_= RDWR, + errp); + if (commit_top_bs =3D=3D NULL) { + goto fail; + } + + bdrv_set_backing_hd(commit_top_bs, top); + bdrv_set_backing_hd(overlay_bs, commit_top_bs); + + s->commit_top_bs =3D commit_top_bs; + bdrv_unref(commit_top_bs); =20 /* Block all nodes between top and base, because they will * disappear from the chain after this operation. */ assert(bdrv_chain_contains(top, base)); - for (iter =3D top; iter !=3D backing_bs(base); iter =3D backing_bs(ite= r)) { - /* FIXME Use real permissions */ - block_job_add_bdrv(&s->common, "intermediate node", iter, 0, - BLK_PERM_ALL, &error_abort); + for (iter =3D top; iter !=3D base; iter =3D backing_bs(iter)) { + /* XXX BLK_PERM_WRITE needs to be allowed so we don't block oursel= ves + * at s->base. The other options would be a second filter driver a= bove + * s->base. */ + ret =3D block_job_add_bdrv(&s->common, "intermediate node", iter, = 0, + BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE, + errp); + if (ret < 0) { + goto fail; + } } + + ret =3D block_job_add_bdrv(&s->common, "base", base, 0, BLK_PERM_ALL, = errp); + if (ret < 0) { + goto fail; + } + /* overlay_bs must be blocked because it needs to be modified to - * update the backing image string, but if it's the root node then - * don't block it again */ - if (bs !=3D overlay_bs) { - /* FIXME Use real permissions */ - block_job_add_bdrv(&s->common, "overlay of top", overlay_bs, 0, - BLK_PERM_ALL, &error_abort); + * update the backing image string. */ + ret =3D block_job_add_bdrv(&s->common, "overlay of top", overlay_bs, + BLK_PERM_GRAPH_MOD, BLK_PERM_ALL, errp); + if (ret < 0) { + goto fail; } =20 - /* FIXME Use real permissions */ - s->base =3D blk_new(0, BLK_PERM_ALL); + s->base =3D blk_new(BLK_PERM_CONSISTENT_READ + | BLK_PERM_WRITE + | BLK_PERM_RESIZE, + BLK_PERM_CONSISTENT_READ + | BLK_PERM_GRAPH_MOD + | BLK_PERM_WRITE_UNCHANGED); ret =3D blk_insert_bs(s->base, base, errp); if (ret < 0) { goto fail; } =20 - /* FIXME Use real permissions */ + /* Required permissions are already taken with block_job_add_bdrv() */ s->top =3D blk_new(0, BLK_PERM_ALL); - ret =3D blk_insert_bs(s->top, top, errp); + blk_insert_bs(s->top, top, errp); if (ret < 0) { goto fail; } @@ -314,6 +385,9 @@ fail: if (s->top) { blk_unref(s->top); } + if (commit_top_bs) { + bdrv_set_backing_hd(overlay_bs, top); + } block_job_unref(&s->common); } =20 --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487693290728698.3867278700869; Tue, 21 Feb 2017 08:08:10 -0800 (PST) Received: from localhost ([::1]:46568 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCz1-0005bU-Tv for importer@patchew.org; Tue, 21 Feb 2017 11:08:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43484) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBv6-0000uq-Oe for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBv1-0008BK-Rz for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35758) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuz-00089z-H4; Tue, 21 Feb 2017 09:59:53 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 9A4406333A; Tue, 21 Feb 2017 14:59:53 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudL030565; Tue, 21 Feb 2017 09:59:52 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:33 +0100 Message-Id: <1487689130-30373-38-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 21 Feb 2017 14:59: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 37/54] commit: Use real permissions for HMP 'commit' 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" This is a little simpler than the commit block job because it's synchronous and only commits into the immediate backing file, but otherwise doing more or less the same. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/commit.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/block/commit.c b/block/commit.c index 9336237..92f7bd3 100644 --- a/block/commit.c +++ b/block/commit.c @@ -398,11 +398,14 @@ fail: int bdrv_commit(BlockDriverState *bs) { BlockBackend *src, *backing; + BlockDriverState *backing_file_bs =3D NULL; + BlockDriverState *commit_top_bs =3D NULL; BlockDriver *drv =3D bs->drv; int64_t sector, total_sectors, length, backing_length; int n, ro, open_flags; int ret =3D 0; uint8_t *buf =3D NULL; + Error *local_err =3D NULL; =20 if (!drv) return -ENOMEDIUM; @@ -425,17 +428,31 @@ int bdrv_commit(BlockDriverState *bs) } } =20 - /* FIXME Use real permissions */ - src =3D blk_new(0, BLK_PERM_ALL); - backing =3D blk_new(0, BLK_PERM_ALL); + src =3D blk_new(BLK_PERM_CONSISTENT_READ, BLK_PERM_ALL); + backing =3D blk_new(BLK_PERM_WRITE | BLK_PERM_RESIZE, BLK_PERM_ALL); =20 - ret =3D blk_insert_bs(src, bs, NULL); + ret =3D blk_insert_bs(src, bs, &local_err); if (ret < 0) { + error_report_err(local_err); goto ro_cleanup; } =20 - ret =3D blk_insert_bs(backing, bs->backing->bs, NULL); + /* Insert commit_top block node above backing, so we can write to it */ + backing_file_bs =3D backing_bs(bs); + + commit_top_bs =3D bdrv_new_open_driver(&bdrv_commit_top, NULL, BDRV_O_= RDWR, + &local_err); + if (commit_top_bs =3D=3D NULL) { + error_report_err(local_err); + goto ro_cleanup; + } + + bdrv_set_backing_hd(commit_top_bs, backing_file_bs); + bdrv_set_backing_hd(bs, commit_top_bs); + + ret =3D blk_insert_bs(backing, backing_file_bs, &local_err); if (ret < 0) { + error_report_err(local_err); goto ro_cleanup; } =20 @@ -509,6 +526,10 @@ int bdrv_commit(BlockDriverState *bs) ro_cleanup: qemu_vfree(buf); =20 + if (backing_file_bs) { + bdrv_set_backing_hd(bs, backing_file_bs); + } + bdrv_unref(commit_top_bs); blk_unref(src); blk_unref(backing); =20 --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487693552998465.3448764604676; Tue, 21 Feb 2017 08:12:32 -0800 (PST) Received: from localhost ([::1]:46594 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgD3H-0002SF-Ia for importer@patchew.org; Tue, 21 Feb 2017 11:12:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43588) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBvC-00011i-6G for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBv8-0008EZ-4d for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42620) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBv1-0008Aa-61; Tue, 21 Feb 2017 09:59:55 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 378E1F44D7; Tue, 21 Feb 2017 14:59:55 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudM030565; Tue, 21 Feb 2017 09:59:53 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:34 +0100 Message-Id: <1487689130-30373-39-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 21 Feb 2017 14:59:55 +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 38/54] 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 From nobody Tue May 7 14:29:10 2024 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 1487691007503850.5319554045626; Tue, 21 Feb 2017 07:30:07 -0800 (PST) Received: from localhost ([::1]:46350 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCOB-0003TW-3e for importer@patchew.org; Tue, 21 Feb 2017 10:30:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43533) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBv8-0000xN-JF for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBv7-0008EL-Tr for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34482) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBv2-0008BQ-Kv; Tue, 21 Feb 2017 09:59:56 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 AB7B9C01C0F5; Tue, 21 Feb 2017 14:59:56 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudN030565; Tue, 21 Feb 2017 09:59:55 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:35 +0100 Message-Id: <1487689130-30373-40-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 21 Feb 2017 14:59:56 +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 39/54] block: Fix pending requests check in bdrv_append() 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" bdrv_append() cares about isolation of the node that it modifies, but not about activity in some subtree below it. Instead of using the recursive bdrv_requests_pending(), directly check bs->in_flight, which considers only the node in question. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index c7c0a8b..a800e81 100644 --- a/block.c +++ b/block.c @@ -2874,8 +2874,8 @@ static void change_parent_backing_link(BlockDriverSta= te *from, */ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top) { - assert(!bdrv_requests_pending(bs_top)); - assert(!bdrv_requests_pending(bs_new)); + assert(!atomic_read(&bs_top->in_flight)); + assert(!atomic_read(&bs_new->in_flight)); =20 bdrv_ref(bs_top); =20 --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487693901957470.1825394456871; Tue, 21 Feb 2017 08:18:21 -0800 (PST) Received: from localhost ([::1]:46636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgD8r-0007tk-C2 for importer@patchew.org; Tue, 21 Feb 2017 11:18:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43688) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBvJ-0001DN-5S for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBvD-0008Jg-7A for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59268) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBv4-0008Bw-9o; Tue, 21 Feb 2017 09:59:58 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 4BA2A4E024; Tue, 21 Feb 2017 14:59:58 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudO030565; Tue, 21 Feb 2017 09:59:56 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:36 +0100 Message-Id: <1487689130-30373-41-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 21 Feb 2017 14:59:58 +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 40/54] block: BdrvChildRole.attach/detach() callbacks 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" Backing files are somewhat special compared to other kinds of children because they are attached and detached using bdrv_set_backing_hd() rather than the normal set of functions, which does a few more things like setting backing blockers, toggling the BDRV_O_NO_BACKING flag, setting parent_bs->backing_file, etc. These special features are a reason why change_parent_backing_link() can't handle backing files yet. With abstracting the additional features into .attach/.detach callbacks, we get a step closer to a function that can actually deal with this. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 94 +++++++++++++++++++++++++++++--------------= ---- include/block/block_int.h | 3 ++ 2 files changed, 62 insertions(+), 35 deletions(-) diff --git a/block.c b/block.c index a800e81..97694fa 100644 --- a/block.c +++ b/block.c @@ -807,6 +807,57 @@ const BdrvChildRole child_format =3D { .drained_end =3D bdrv_child_cb_drained_end, }; =20 +static void bdrv_backing_attach(BdrvChild *c) +{ + BlockDriverState *parent =3D c->opaque; + BlockDriverState *backing_hd =3D c->bs; + + assert(!parent->backing_blocker); + error_setg(&parent->backing_blocker, + "node is used as backing hd of '%s'", + bdrv_get_device_or_node_name(parent)); + + parent->open_flags &=3D ~BDRV_O_NO_BACKING; + pstrcpy(parent->backing_file, sizeof(parent->backing_file), + backing_hd->filename); + pstrcpy(parent->backing_format, sizeof(parent->backing_format), + backing_hd->drv ? backing_hd->drv->format_name : ""); + + bdrv_op_block_all(backing_hd, parent->backing_blocker); + /* Otherwise we won't be able to commit or stream */ + bdrv_op_unblock(backing_hd, BLOCK_OP_TYPE_COMMIT_TARGET, + parent->backing_blocker); + bdrv_op_unblock(backing_hd, BLOCK_OP_TYPE_STREAM, + parent->backing_blocker); + /* + * We do backup in 3 ways: + * 1. drive backup + * The target bs is new opened, and the source is top BDS + * 2. blockdev backup + * Both the source and the target are top BDSes. + * 3. internal backup(used for block replication) + * Both the source and the target are backing file + * + * In case 1 and 2, neither the source nor the target is the backing f= ile. + * In case 3, we will block the top BDS, so there is only one block job + * for the top BDS and its backing chain. + */ + bdrv_op_unblock(backing_hd, BLOCK_OP_TYPE_BACKUP_SOURCE, + parent->backing_blocker); + bdrv_op_unblock(backing_hd, BLOCK_OP_TYPE_BACKUP_TARGET, + parent->backing_blocker); +} + +static void bdrv_backing_detach(BdrvChild *c) +{ + BlockDriverState *parent =3D c->opaque; + + assert(parent->backing_blocker); + bdrv_op_unblock_all(c->bs, parent->backing_blocker); + error_free(parent->backing_blocker); + parent->backing_blocker =3D NULL; +} + /* * Returns the options and flags that bs->backing should get, based on the * given options and flags for the parent BDS @@ -833,6 +884,8 @@ static void bdrv_backing_options(int *child_flags, QDic= t *child_options, =20 const BdrvChildRole child_backing =3D { .get_parent_desc =3D bdrv_child_get_parent_desc, + .attach =3D bdrv_backing_attach, + .detach =3D bdrv_backing_detach, .inherit_options =3D bdrv_backing_options, .drained_begin =3D bdrv_child_cb_drained_begin, .drained_end =3D bdrv_child_cb_drained_end, @@ -1661,6 +1714,9 @@ static void bdrv_replace_child(BdrvChild *child, Bloc= kDriverState *new_bs) if (old_bs->quiesce_counter && child->role->drained_end) { child->role->drained_end(child); } + if (child->role->detach) { + child->role->detach(child); + } QLIST_REMOVE(child, next_parent); bdrv_update_perm(old_bs); } @@ -1673,6 +1729,9 @@ static void bdrv_replace_child(BdrvChild *child, Bloc= kDriverState *new_bs) child->role->drained_begin(child); } bdrv_update_perm(new_bs); + if (child->role->attach) { + child->role->attach(child); + } } } =20 @@ -1807,52 +1866,17 @@ void bdrv_set_backing_hd(BlockDriverState *bs, Bloc= kDriverState *backing_hd) } =20 if (bs->backing) { - assert(bs->backing_blocker); - bdrv_op_unblock_all(bs->backing->bs, bs->backing_blocker); bdrv_unref_child(bs, bs->backing); - } else if (backing_hd) { - error_setg(&bs->backing_blocker, - "node is used as backing hd of '%s'", - bdrv_get_device_or_node_name(bs)); } =20 if (!backing_hd) { - error_free(bs->backing_blocker); - bs->backing_blocker =3D NULL; bs->backing =3D NULL; goto out; } /* FIXME Error handling */ bs->backing =3D bdrv_attach_child(bs, backing_hd, "backing", &child_ba= cking, &error_abort); - bs->open_flags &=3D ~BDRV_O_NO_BACKING; - pstrcpy(bs->backing_file, sizeof(bs->backing_file), backing_hd->filena= me); - pstrcpy(bs->backing_format, sizeof(bs->backing_format), - backing_hd->drv ? backing_hd->drv->format_name : ""); =20 - bdrv_op_block_all(backing_hd, bs->backing_blocker); - /* Otherwise we won't be able to commit or stream */ - bdrv_op_unblock(backing_hd, BLOCK_OP_TYPE_COMMIT_TARGET, - bs->backing_blocker); - bdrv_op_unblock(backing_hd, BLOCK_OP_TYPE_STREAM, - bs->backing_blocker); - /* - * We do backup in 3 ways: - * 1. drive backup - * The target bs is new opened, and the source is top BDS - * 2. blockdev backup - * Both the source and the target are top BDSes. - * 3. internal backup(used for block replication) - * Both the source and the target are backing file - * - * In case 1 and 2, neither the source nor the target is the backing f= ile. - * In case 3, we will block the top BDS, so there is only one block job - * for the top BDS and its backing chain. - */ - bdrv_op_unblock(backing_hd, BLOCK_OP_TYPE_BACKUP_SOURCE, - bs->backing_blocker); - bdrv_op_unblock(backing_hd, BLOCK_OP_TYPE_BACKUP_TARGET, - bs->backing_blocker); out: bdrv_refresh_limits(bs, NULL); } diff --git a/include/block/block_int.h b/include/block/block_int.h index a0d9328..a5c704b 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -472,6 +472,9 @@ struct BdrvChildRole { */ void (*drained_begin)(BdrvChild *child); void (*drained_end)(BdrvChild *child); + + void (*attach)(BdrvChild *child); + void (*detach)(BdrvChild *child); }; =20 extern const BdrvChildRole child_file; --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487691563313642.7198504239291; Tue, 21 Feb 2017 07:39:23 -0800 (PST) Received: from localhost ([::1]:46397 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCXA-0003rq-Td for importer@patchew.org; Tue, 21 Feb 2017 10:39:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBv8-0000xT-MI for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBv7-0008EQ-UQ for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48560) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBv5-0008CZ-Mi; Tue, 21 Feb 2017 09:59:59 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 BC82E7E9F7; Tue, 21 Feb 2017 14:59:59 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudP030565; Tue, 21 Feb 2017 09:59:58 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:37 +0100 Message-Id: <1487689130-30373-42-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 21 Feb 2017 14:59:59 +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 41/54] block: Allow backing file links in change_parent_backing_link() 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" Now that the backing file child role implements .attach/.detach callbacks, nothing prevents us from modifying the graph even if that involves changing backing file links. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index 97694fa..560e84a 100644 --- a/block.c +++ b/block.c @@ -2860,9 +2860,9 @@ static void change_parent_backing_link(BlockDriverSta= te *from, continue; } if (c->role =3D=3D &child_backing) { - /* @from is generally not allowed to be a backing file, except= for - * when @to is the overlay. In that case, @from may not be rep= laced - * by @to as @to's backing node. */ + /* If @from is a backing file of @to, ignore the child to avoid + * creating a loop. We only want to change the pointer of other + * parents. */ QLIST_FOREACH(to_c, &to->children, next) { if (to_c =3D=3D c) { break; @@ -2873,7 +2873,6 @@ static void change_parent_backing_link(BlockDriverSta= te *from, } } =20 - assert(c->role !=3D &child_backing); bdrv_ref(to); bdrv_replace_child(c, to); bdrv_unref(from); --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487691848836640.0151715572779; Tue, 21 Feb 2017 07:44:08 -0800 (PST) Received: from localhost ([::1]:46428 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCbm-0008Rn-Dv for importer@patchew.org; Tue, 21 Feb 2017 10:44:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43735) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBvL-0001Fo-3v for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBvG-0008NC-7P for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34524) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBv7-0008D7-59; Tue, 21 Feb 2017 10:00:01 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 2E35DC04BD47; Tue, 21 Feb 2017 15:00:01 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudQ030565; Tue, 21 Feb 2017 09:59:59 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:38 +0100 Message-Id: <1487689130-30373-43-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 21 Feb 2017 15:00:01 +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 42/54] mirror: Use real permissions in mirror/active commit 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 mirror block job is mainly used for two different scenarios: Mirroring to an otherwise unused, independent target node, or for active commit where the target node is part of the backing chain of the source. Similarly to the commit block job patch, we need to insert a new filter node to keep the permissions correct during active commit. Note that one change this implies is that job->blk points to mirror_top_bs as its root now, and mirror_top_bs (rather than the actual source node) contains the bs->job pointer. This requires qemu-img commit to get the job by name now rather than just taking bs->job. Signed-off-by: Kevin Wolf --- block/mirror.c | 161 +++++++++++++++++++++++++++++++++++++----= ---- qemu-img.c | 6 +- tests/qemu-iotests/141 | 2 +- tests/qemu-iotests/141.out | 4 +- 4 files changed, 143 insertions(+), 30 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 767b7e7..252107d 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -38,7 +38,10 @@ typedef struct MirrorBlockJob { BlockJob common; RateLimit limit; BlockBackend *target; + BlockDriverState *mirror_top_bs; + BlockDriverState *source; BlockDriverState *base; + /* The name of the graph node to replace */ char *replaces; /* The BDS to replace */ @@ -325,7 +328,7 @@ static void mirror_do_zero_or_discard(MirrorBlockJob *s, =20 static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) { - BlockDriverState *source =3D blk_bs(s->common.blk); + BlockDriverState *source =3D s->source; int64_t sector_num, first_chunk; uint64_t delay_ns =3D 0; /* At least the first dirty chunk is mirrored in one iteration. */ @@ -495,12 +498,14 @@ static void mirror_exit(BlockJob *job, void *opaque) MirrorBlockJob *s =3D container_of(job, MirrorBlockJob, common); MirrorExitData *data =3D opaque; AioContext *replace_aio_context =3D NULL; - BlockDriverState *src =3D blk_bs(s->common.blk); + BlockDriverState *src =3D s->source; BlockDriverState *target_bs =3D blk_bs(s->target); + BlockDriverState *mirror_top_bs =3D s->mirror_top_bs; =20 /* Make sure that the source BDS doesn't go away before we called * block_job_completed(). */ bdrv_ref(src); + bdrv_ref(mirror_top_bs); =20 if (s->to_replace) { replace_aio_context =3D bdrv_get_aio_context(s->to_replace); @@ -522,13 +527,6 @@ static void mirror_exit(BlockJob *job, void *opaque) bdrv_drained_begin(target_bs); bdrv_replace_in_backing_chain(to_replace, target_bs); bdrv_drained_end(target_bs); - - /* We just changed the BDS the job BB refers to, so switch the BB = back - * so the cleanup does the right thing. We don't need any permissi= ons - * any more now. */ - blk_remove_bs(job->blk); - blk_set_perm(job->blk, 0, BLK_PERM_ALL, &error_abort); - blk_insert_bs(job->blk, src, &error_abort); } if (s->to_replace) { bdrv_op_unblock_all(s->to_replace, s->replace_blocker); @@ -541,9 +539,23 @@ static void mirror_exit(BlockJob *job, void *opaque) g_free(s->replaces); blk_unref(s->target); s->target =3D NULL; + + /* Remove the mirror filter driver from the graph */ + bdrv_replace_in_backing_chain(mirror_top_bs, backing_bs(mirror_top_bs)= ); + + /* We just changed the BDS the job BB refers to (with either or both o= f the + * bdrv_replace_in_backing_chain() calls), so switch the BB back so the + * cleanup does the right thing. We don't need any permissions any more + * now. */ + blk_remove_bs(job->blk); + blk_set_perm(job->blk, 0, BLK_PERM_ALL, &error_abort); + blk_insert_bs(job->blk, mirror_top_bs, &error_abort); + block_job_completed(&s->common, data->ret); + g_free(data); bdrv_drained_end(src); + bdrv_unref(mirror_top_bs); bdrv_unref(src); } =20 @@ -563,7 +575,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJo= b *s) { int64_t sector_num, end; BlockDriverState *base =3D s->base; - BlockDriverState *bs =3D blk_bs(s->common.blk); + BlockDriverState *bs =3D s->source; BlockDriverState *target_bs =3D blk_bs(s->target); int ret, n; =20 @@ -642,7 +654,7 @@ static void coroutine_fn mirror_run(void *opaque) { MirrorBlockJob *s =3D opaque; MirrorExitData *data; - BlockDriverState *bs =3D blk_bs(s->common.blk); + BlockDriverState *bs =3D s->source; BlockDriverState *target_bs =3D blk_bs(s->target); bool need_drain =3D true; int64_t length; @@ -876,7 +888,7 @@ static void mirror_complete(BlockJob *job, Error **errp) MirrorBlockJob *s =3D container_of(job, MirrorBlockJob, common); BlockDriverState *src, *target; =20 - src =3D blk_bs(job->blk); + src =3D s->source; target =3D blk_bs(s->target); =20 if (!s->synced) { @@ -908,6 +920,10 @@ static void mirror_complete(BlockJob *job, Error **err= p) replace_aio_context =3D bdrv_get_aio_context(s->to_replace); aio_context_acquire(replace_aio_context); =20 + /* TODO Translate this into permission system. Current definition = of + * GRAPH_MOD would require to request it for the parents; they mig= ht + * not even be BlockDriverStates, however, so a BdrvChild can't ad= dress + * them. May need redefinition of GRAPH_MOD. */ error_setg(&s->replace_blocker, "block device is in use by block-job-complete"); bdrv_op_block_all(s->to_replace, s->replace_blocker); @@ -978,6 +994,46 @@ static const BlockJobDriver commit_active_job_driver = =3D { .drain =3D mirror_drain, }; =20 +static int coroutine_fn bdrv_mirror_top_preadv(BlockDriverState *bs, + uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags) +{ + return bdrv_co_preadv(bs->backing, offset, bytes, qiov, flags); +} + +static int coroutine_fn bdrv_mirror_top_pwritev(BlockDriverState *bs, + uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags) +{ + return bdrv_co_pwritev(bs->backing, offset, bytes, qiov, flags); +} + +static void bdrv_mirror_top_close(BlockDriverState *bs) +{ +} + +static void bdrv_mirror_top_child_perm(BlockDriverState *bs, BdrvChild *c, + const BdrvChildRole *role, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) +{ + /* Must be able to forward guest writes to the real image */ + *nperm =3D 0; + if (perm & BLK_PERM_WRITE) { + *nperm |=3D BLK_PERM_WRITE; + } + + *nshared =3D BLK_PERM_ALL; +} + +/* Dummy node that provides consistent read to its users without requiring= it + * from its backing file and that allows writes on the backing file chain.= */ +static BlockDriver bdrv_mirror_top =3D { + .format_name =3D "mirror_top", + .bdrv_co_preadv =3D bdrv_mirror_top_preadv, + .bdrv_co_pwritev =3D bdrv_mirror_top_pwritev, + .bdrv_close =3D bdrv_mirror_top_close, + .bdrv_child_perm =3D bdrv_mirror_top_child_perm, +}; + static void mirror_start_job(const char *job_id, BlockDriverState *bs, int creation_flags, BlockDriverState *target, const char *replaces, int64_t speed, @@ -993,6 +1049,9 @@ static void mirror_start_job(const char *job_id, Block= DriverState *bs, bool auto_complete) { MirrorBlockJob *s; + BlockDriverState *mirror_top_bs; + bool target_graph_mod; + bool target_is_backing; int ret; =20 if (granularity =3D=3D 0) { @@ -1010,20 +1069,54 @@ static void mirror_start_job(const char *job_id, Bl= ockDriverState *bs, buf_size =3D DEFAULT_MIRROR_BUF_SIZE; } =20 - /* FIXME Use real permissions */ - s =3D block_job_create(job_id, driver, bs, 0, BLK_PERM_ALL, speed, + /* In the case of active commit, add dummy driver to provide consistent + * reads on the top, while disabling it in the intermediate nodes */ + mirror_top_bs =3D bdrv_new_open_driver(&bdrv_mirror_top, NULL, BDRV_O_= RDWR, + errp); + if (mirror_top_bs =3D=3D NULL) { + return; + } + mirror_top_bs->total_sectors =3D bs->total_sectors; + + /* bdrv_append takes ownership of the mirror_top_bs reference, need to= keep + * it alive until block_job_create() even if bs has no parent. */ + bdrv_ref(mirror_top_bs); + bdrv_drained_begin(bs); + bdrv_append(mirror_top_bs, bs); + bdrv_drained_end(bs); + + /* Make sure that the source is not resized while the job is running */ + s =3D block_job_create(job_id, driver, mirror_top_bs, + BLK_PERM_CONSISTENT_READ, + BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANG= ED | + BLK_PERM_WRITE | BLK_PERM_GRAPH_MOD, speed, creation_flags, cb, opaque, errp); + bdrv_unref(mirror_top_bs); if (!s) { - return; + goto fail; } - - /* FIXME Use real permissions */ - s->target =3D blk_new(0, BLK_PERM_ALL); + s->source =3D bs; + s->mirror_top_bs =3D mirror_top_bs; + + /* No resize for the target either; while the mirror is still running,= a + * consistent read isn't necessarily possible. We could possibly allow + * writes and graph modifications, though it would likely defeat the + * purpose of a mirror, so leave them blocked for now. + * + * In the case of active commit, things look a bit different, though, + * because the target is an already populated backing file in active u= se. + * We can allow anything ecept resize there.*/ + target_is_backing =3D bdrv_chain_contains(bs, target); + target_graph_mod =3D (backing_mode !=3D MIRROR_LEAVE_BACKING_CHAIN); + s->target =3D blk_new(BLK_PERM_WRITE | BLK_PERM_RESIZE | + (target_graph_mod ? BLK_PERM_GRAPH_MOD : 0), + BLK_PERM_WRITE_UNCHANGED | + (target_is_backing ? BLK_PERM_CONSISTENT_READ | + BLK_PERM_WRITE | + BLK_PERM_GRAPH_MOD : 0)); ret =3D blk_insert_bs(s->target, target, errp); if (ret < 0) { - blk_unref(s->target); - block_job_unref(&s->common); - return; + goto fail; } =20 s->replaces =3D g_strdup(replaces); @@ -1047,23 +1140,39 @@ static void mirror_start_job(const char *job_id, Bl= ockDriverState *bs, return; } =20 - /* FIXME Use real permissions */ + /* Required permissions are already taken with blk_new() */ block_job_add_bdrv(&s->common, "target", target, 0, BLK_PERM_ALL, &error_abort); =20 /* In commit_active_start() all intermediate nodes disappear, so * any jobs in them must be blocked */ - if (bdrv_chain_contains(bs, target)) { + if (target_is_backing) { BlockDriverState *iter; for (iter =3D backing_bs(bs); iter !=3D target; iter =3D backing_b= s(iter)) { - /* FIXME Use real permissions */ - block_job_add_bdrv(&s->common, "intermediate node", iter, 0, - BLK_PERM_ALL, &error_abort); + /* XXX BLK_PERM_WRITE needs to be allowed so we don't block ou= rselves + * at s->base. The other options would be a second filter driv= er above + * s->base. */ + ret =3D block_job_add_bdrv(&s->common, "intermediate node", it= er, 0, + BLK_PERM_WRITE_UNCHANGED | BLK_PERM_W= RITE, + errp); + if (ret < 0) { + goto fail; + } } } =20 trace_mirror_start(bs, s, opaque); block_job_start(&s->common); + return; + +fail: + if (s) { + g_free(s->replaces); + blk_unref(s->target); + block_job_unref(&s->common); + } + + bdrv_replace_in_backing_chain(mirror_top_bs, backing_bs(mirror_top_bs)= ); } =20 void mirror_start(const char *job_id, BlockDriverState *bs, diff --git a/qemu-img.c b/qemu-img.c index 8d9195e..e20830f 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -795,6 +795,8 @@ static void run_block_job(BlockJob *job, Error **errp) { AioContext *aio_context =3D blk_get_aio_context(job->blk); =20 + /* FIXME In error cases, the job simply goes away and we access a dang= ling + * pointer below. */ aio_context_acquire(aio_context); do { aio_poll(aio_context, true); @@ -816,6 +818,7 @@ static int img_commit(int argc, char **argv) const char *filename, *fmt, *cache, *base; BlockBackend *blk; BlockDriverState *bs, *base_bs; + BlockJob *job; bool progress =3D false, quiet =3D false, drop =3D false; bool writethrough; Error *local_err =3D NULL; @@ -951,7 +954,8 @@ static int img_commit(int argc, char **argv) bdrv_ref(bs); } =20 - run_block_job(bs->job, &local_err); + job =3D block_job_get("commit"); + run_block_job(job, &local_err); if (local_err) { goto unref_backing; } diff --git a/tests/qemu-iotests/141 b/tests/qemu-iotests/141 index 3ba79f0..6d8f0a1 100755 --- a/tests/qemu-iotests/141 +++ b/tests/qemu-iotests/141 @@ -67,7 +67,7 @@ test_blockjob() _send_qemu_cmd $QEMU_HANDLE \ "{'execute': 'x-blockdev-del', 'arguments': {'node-name': 'drv0'}}" \ - 'error' + 'error' | _filter_generated_node_ids =20 _send_qemu_cmd $QEMU_HANDLE \ "{'execute': 'block-job-cancel', diff --git a/tests/qemu-iotests/141.out b/tests/qemu-iotests/141.out index 195ca1a..82e763b 100644 --- a/tests/qemu-iotests/141.out +++ b/tests/qemu-iotests/141.out @@ -20,7 +20,7 @@ Formatting 'TEST_DIR/o.IMGFMT', fmt=3DIMGFMT size=3D10485= 76 backing_file=3DTEST_DIR/t. Formatting 'TEST_DIR/o.IMGFMT', fmt=3DIMGFMT size=3D1048576 backing_file= =3DTEST_DIR/t.IMGFMT backing_fmt=3DIMGFMT {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "BLOCK_JOB_READY", "data": {"device": "job0", "len": 0, "offset": 0, "spe= ed": 0, "type": "mirror"}} {"return": {}} -{"error": {"class": "GenericError", "desc": "Node drv0 is in use"}} +{"error": {"class": "GenericError", "desc": "Node 'drv0' is busy: node is = used as backing hd of 'NODE_NAME'"}} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "BLOCK_JOB_COMPLETED", "data": {"device": "job0", "len": 0, "offset": 0, = "speed": 0, "type": "mirror"}} {"return": {}} @@ -30,7 +30,7 @@ Formatting 'TEST_DIR/o.IMGFMT', fmt=3DIMGFMT size=3D10485= 76 backing_file=3DTEST_DIR/t. {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "BLOCK_JOB_READY", "data": {"device": "job0", "len": 0, "offset": 0, "spe= ed": 0, "type": "commit"}} {"return": {}} -{"error": {"class": "GenericError", "desc": "Node drv0 is in use"}} +{"error": {"class": "GenericError", "desc": "Node 'drv0' is busy: node is = used as backing hd of 'NODE_NAME'"}} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "BLOCK_JOB_COMPLETED", "data": {"device": "job0", "len": 0, "offset": 0, = "speed": 0, "type": "commit"}} {"return": {}} --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487694176682306.9458938734631; Tue, 21 Feb 2017 08:22:56 -0800 (PST) Received: from localhost ([::1]:46666 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgDDJ-0003uV-2C for importer@patchew.org; Tue, 21 Feb 2017 11:22:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43737) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBvL-0001Fs-6K for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBvH-0008OC-Br for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34544) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBv8-0008EW-KO; Tue, 21 Feb 2017 10:00:02 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 B2949C0273AD; Tue, 21 Feb 2017 15:00:02 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudR030565; Tue, 21 Feb 2017 10:00:01 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:39 +0100 Message-Id: <1487689130-30373-44-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 21 Feb 2017 15:00:02 +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 43/54] stream: Use real permissions in streaming 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 correct permissions are relatively obvious here (and explained in code comments). For intermediate streaming, we need to reopen the top node read-write before creating the job now because the permissions system catches attempts to get the BLK_PERM_WRITE_UNCHANGED permission on a read-only node. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/stream.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/block/stream.c b/block/stream.c index ba8650f..0c30d41 100644 --- a/block/stream.c +++ b/block/stream.c @@ -229,28 +229,35 @@ void stream_start(const char *job_id, BlockDriverStat= e *bs, BlockDriverState *iter; int orig_bs_flags; =20 - /* FIXME Use real permissions */ - s =3D block_job_create(job_id, &stream_job_driver, bs, 0, BLK_PERM_ALL, - speed, BLOCK_JOB_DEFAULT, NULL, NULL, errp); - if (!s) { - return; - } - /* Make sure that the image is opened in read-write mode */ orig_bs_flags =3D bdrv_get_flags(bs); if (!(orig_bs_flags & BDRV_O_RDWR)) { if (bdrv_reopen(bs, orig_bs_flags | BDRV_O_RDWR, errp) !=3D 0) { - block_job_unref(&s->common); return; } } =20 - /* Block all intermediate nodes between bs and base, because they - * will disappear from the chain after this operation */ + /* Prevent concurrent jobs trying to modify the graph structure here, = we + * already have our own plans. Also don't allow resize as the image si= ze is + * queried only at the job start and then cached. */ + s =3D block_job_create(job_id, &stream_job_driver, bs, + BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANG= ED | + BLK_PERM_GRAPH_MOD, + BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANG= ED | + BLK_PERM_WRITE, + speed, BLOCK_JOB_DEFAULT, NULL, NULL, errp); + if (!s) { + goto fail; + } + + /* Block all intermediate nodes between bs and base, because they will + * disappear from the chain after this operation. The streaming job re= ads + * every block only once, assuming that it doesn't change, so block wr= ites + * and resizes. */ for (iter =3D backing_bs(bs); iter && iter !=3D base; iter =3D backing= _bs(iter)) { - /* FIXME Use real permissions */ block_job_add_bdrv(&s->common, "intermediate node", iter, 0, - BLK_PERM_ALL, &error_abort); + BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHA= NGED, + &error_abort); } =20 s->base =3D base; @@ -260,4 +267,10 @@ void stream_start(const char *job_id, BlockDriverState= *bs, s->on_error =3D on_error; trace_stream_start(bs, base, s); block_job_start(&s->common); + return; + +fail: + if (orig_bs_flags !=3D bdrv_get_flags(bs)) { + bdrv_reopen(bs, s->bs_flags, NULL); + } } --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487694301424777.9903840510551; Tue, 21 Feb 2017 08:25:01 -0800 (PST) Received: from localhost ([::1]:46679 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgDFL-0005ZH-Oh for importer@patchew.org; Tue, 21 Feb 2017 11:24:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43681) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBvI-0001Bp-Li for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBvH-0008OH-CT for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33304) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBvA-0008FT-4d; Tue, 21 Feb 2017 10:00:04 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 1653180084; Tue, 21 Feb 2017 15:00:04 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudS030565; Tue, 21 Feb 2017 10:00:02 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:40 +0100 Message-Id: <1487689130-30373-45-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 21 Feb 2017 15:00: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 44/54] mirror: Add filter-node-name to blockdev-mirror 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" Management tools need to be able to know about every node in the graph and need a way to address them. This new option to blockdev-mirror allows the client to set a node-name for the automatically inserted filter driver, and at the same time serves as a witness that this version of qemu does automatically insert a filter driver. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/mirror.c | 14 ++++++++------ blockdev.c | 12 +++++++++++- include/block/block_int.h | 5 ++++- qapi/block-core.json | 8 +++++++- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 252107d..2e1cd16 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1046,7 +1046,7 @@ static void mirror_start_job(const char *job_id, Bloc= kDriverState *bs, void *opaque, Error **errp, const BlockJobDriver *driver, bool is_none_mode, BlockDriverState *base, - bool auto_complete) + bool auto_complete, const char *filter_node_n= ame) { MirrorBlockJob *s; BlockDriverState *mirror_top_bs; @@ -1071,8 +1071,8 @@ static void mirror_start_job(const char *job_id, Bloc= kDriverState *bs, =20 /* In the case of active commit, add dummy driver to provide consistent * reads on the top, while disabling it in the intermediate nodes */ - mirror_top_bs =3D bdrv_new_open_driver(&bdrv_mirror_top, NULL, BDRV_O_= RDWR, - errp); + mirror_top_bs =3D bdrv_new_open_driver(&bdrv_mirror_top, filter_node_n= ame, + BDRV_O_RDWR, errp); if (mirror_top_bs =3D=3D NULL) { return; } @@ -1181,7 +1181,7 @@ void mirror_start(const char *job_id, BlockDriverStat= e *bs, MirrorSyncMode mode, BlockMirrorBackingMode backing_mode, BlockdevOnError on_source_error, BlockdevOnError on_target_error, - bool unmap, Error **errp) + bool unmap, const char *filter_node_name, Error **errp) { bool is_none_mode; BlockDriverState *base; @@ -1195,7 +1195,8 @@ void mirror_start(const char *job_id, BlockDriverStat= e *bs, mirror_start_job(job_id, bs, BLOCK_JOB_DEFAULT, target, replaces, speed, granularity, buf_size, backing_mode, on_source_error, on_target_error, unmap, NULL, NULL, = errp, - &mirror_job_driver, is_none_mode, base, false); + &mirror_job_driver, is_none_mode, base, false, + filter_node_name); } =20 void commit_active_start(const char *job_id, BlockDriverState *bs, @@ -1216,7 +1217,8 @@ void commit_active_start(const char *job_id, BlockDri= verState *bs, mirror_start_job(job_id, bs, creation_flags, base, NULL, speed, 0, 0, MIRROR_LEAVE_BACKING_CHAIN, on_error, on_error, true, cb, opaque, &local_err, - &commit_active_job_driver, false, base, auto_complete= ); + &commit_active_job_driver, false, base, auto_complete, + NULL); if (local_err) { error_propagate(errp, local_err); goto error_restore_flags; diff --git a/blockdev.c b/blockdev.c index bcee23e..4314584 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3362,6 +3362,8 @@ static void blockdev_mirror_common(const char *job_id= , BlockDriverState *bs, bool has_on_target_error, BlockdevOnError on_target_error, bool has_unmap, bool unmap, + bool has_filter_node_name, + const char *filter_node_name, Error **errp) { =20 @@ -3383,6 +3385,9 @@ static void blockdev_mirror_common(const char *job_id= , BlockDriverState *bs, if (!has_unmap) { unmap =3D true; } + if (!has_filter_node_name) { + filter_node_name =3D NULL; + } =20 if (granularity !=3D 0 && (granularity < 512 || granularity > 1048576 = * 64)) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "granularity", @@ -3412,7 +3417,8 @@ static void blockdev_mirror_common(const char *job_id= , BlockDriverState *bs, mirror_start(job_id, bs, target, has_replaces ? replaces : NULL, speed, granularity, buf_size, sync, backing_mode, - on_source_error, on_target_error, unmap, errp); + on_source_error, on_target_error, unmap, filter_node_name, + errp); } =20 void qmp_drive_mirror(DriveMirror *arg, Error **errp) @@ -3550,6 +3556,7 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) arg->has_on_source_error, arg->on_source_error, arg->has_on_target_error, arg->on_target_error, arg->has_unmap, arg->unmap, + false, NULL, &local_err); bdrv_unref(target_bs); error_propagate(errp, local_err); @@ -3568,6 +3575,8 @@ void qmp_blockdev_mirror(bool has_job_id, const char = *job_id, BlockdevOnError on_source_error, bool has_on_target_error, BlockdevOnError on_target_error, + bool has_filter_node_name, + const char *filter_node_name, Error **errp) { BlockDriverState *bs; @@ -3599,6 +3608,7 @@ void qmp_blockdev_mirror(bool has_job_id, const char = *job_id, has_on_source_error, on_source_error, has_on_target_error, on_target_error, true, true, + has_filter_node_name, filter_node_name, &local_err); error_propagate(errp, local_err); =20 diff --git a/include/block/block_int.h b/include/block/block_int.h index a5c704b..563b30c 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -824,6 +824,9 @@ void commit_active_start(const char *job_id, BlockDrive= rState *bs, * @on_source_error: The action to take upon error reading from the source. * @on_target_error: The action to take upon error writing to the target. * @unmap: Whether to unmap target where source sectors only contain zeroe= s. + * @filter_node_name: The node name that should be assigned to the filter + * driver that the mirror job inserts into the graph above @bs. NULL means= that + * a node name should be autogenerated. * @errp: Error object. * * Start a mirroring operation on @bs. Clusters that are allocated @@ -837,7 +840,7 @@ void mirror_start(const char *job_id, BlockDriverState = *bs, MirrorSyncMode mode, BlockMirrorBackingMode backing_mode, BlockdevOnError on_source_error, BlockdevOnError on_target_error, - bool unmap, Error **errp); + bool unmap, const char *filter_node_name, Error **errp); =20 /* * backup_job_create: diff --git a/qapi/block-core.json b/qapi/block-core.json index 932f5bb..893fa34 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1671,6 +1671,11 @@ # default 'report' (no limitations, since this applies to # a different block device than @device). # +# @filter-node-name: #optional the node name that should be assigned to the +# filter driver that the mirror job inserts into the gr= aph +# above @device. If this option is not given, a node na= me is +# autogenerated. (Since: 2.9) +# # Returns: nothing on success. # # Since: 2.6 @@ -1690,7 +1695,8 @@ 'sync': 'MirrorSyncMode', '*speed': 'int', '*granularity': 'uint32', '*buf-size': 'int', '*on-source-error': 'BlockdevOnError', - '*on-target-error': 'BlockdevOnError' } } + '*on-target-error': 'BlockdevOnError', + '*filter-node-name': 'str' } } =20 ## # @block_set_io_throttle: --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487692135074856.4366002341771; Tue, 21 Feb 2017 07:48:55 -0800 (PST) Received: from localhost ([::1]:46454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCgO-0004Im-Ig for importer@patchew.org; Tue, 21 Feb 2017 10:48:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43844) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBvS-0001Ne-0w for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBvN-0008SY-2c for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35922) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBvB-0008H5-ER; Tue, 21 Feb 2017 10:00:05 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 7AD3A6267F; Tue, 21 Feb 2017 15:00:05 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudT030565; Tue, 21 Feb 2017 10:00:04 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:41 +0100 Message-Id: <1487689130-30373-46-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 21 Feb 2017 15:00:05 +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 45/54] commit: Add filter-node-name to block-commit 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" Management tools need to be able to know about every node in the graph and need a way to address them. This new option to block-commit allows the client to set a node-name for the automatically inserted filter driver, and at the same time serves as a witness that this version of qemu does automatically insert a filter driver. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/commit.c | 6 +++--- block/mirror.c | 3 ++- block/replication.c | 2 +- blockdev.c | 10 +++++++--- include/block/block_int.h | 13 ++++++++++--- qapi/block-core.json | 8 +++++++- qemu-img.c | 4 ++-- 7 files changed, 32 insertions(+), 14 deletions(-) diff --git a/block/commit.c b/block/commit.c index 92f7bd3..b9ec363 100644 --- a/block/commit.c +++ b/block/commit.c @@ -254,7 +254,7 @@ static BlockDriver bdrv_commit_top =3D { void commit_start(const char *job_id, BlockDriverState *bs, BlockDriverState *base, BlockDriverState *top, int64_t s= peed, BlockdevOnError on_error, const char *backing_file_str, - Error **errp) + const char *filter_node_name, Error **errp) { CommitBlockJob *s; BlockReopenQueue *reopen_queue =3D NULL; @@ -307,8 +307,8 @@ void commit_start(const char *job_id, BlockDriverState = *bs, =20 /* Insert commit_top block node above top, so we can block consistent = read * on the backing chain below it */ - commit_top_bs =3D bdrv_new_open_driver(&bdrv_commit_top, NULL, BDRV_O_= RDWR, - errp); + commit_top_bs =3D bdrv_new_open_driver(&bdrv_commit_top, filter_node_n= ame, + BDRV_O_RDWR, errp); if (commit_top_bs =3D=3D NULL) { goto fail; } diff --git a/block/mirror.c b/block/mirror.c index 2e1cd16..fa0c0e5 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1202,6 +1202,7 @@ void mirror_start(const char *job_id, BlockDriverStat= e *bs, void commit_active_start(const char *job_id, BlockDriverState *bs, BlockDriverState *base, int creation_flags, int64_t speed, BlockdevOnError on_error, + const char *filter_node_name, BlockCompletionFunc *cb, void *opaque, Error **er= rp, bool auto_complete) { @@ -1218,7 +1219,7 @@ void commit_active_start(const char *job_id, BlockDri= verState *bs, MIRROR_LEAVE_BACKING_CHAIN, on_error, on_error, true, cb, opaque, &local_err, &commit_active_job_driver, false, base, auto_complete, - NULL); + filter_node_name); if (local_err) { error_propagate(errp, local_err); goto error_restore_flags; diff --git a/block/replication.c b/block/replication.c index 91465cb..22f170f 100644 --- a/block/replication.c +++ b/block/replication.c @@ -644,7 +644,7 @@ static void replication_stop(ReplicationState *rs, bool= failover, Error **errp) s->replication_state =3D BLOCK_REPLICATION_FAILOVER; commit_active_start(NULL, s->active_disk->bs, s->secondary_disk->b= s, BLOCK_JOB_INTERNAL, 0, BLOCKDEV_ON_ERROR_REPOR= T, - replication_done, bs, errp, true); + NULL, replication_done, bs, errp, true); break; default: aio_context_release(aio_context); diff --git a/blockdev.c b/blockdev.c index 4314584..63b1ac4 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3028,6 +3028,7 @@ void qmp_block_commit(bool has_job_id, const char *jo= b_id, const char *device, bool has_top, const char *top, bool has_backing_file, const char *backing_file, bool has_speed, int64_t speed, + bool has_filter_node_name, const char *filter_node_n= ame, Error **errp) { BlockDriverState *bs; @@ -3043,6 +3044,9 @@ void qmp_block_commit(bool has_job_id, const char *jo= b_id, const char *device, if (!has_speed) { speed =3D 0; } + if (!has_filter_node_name) { + filter_node_name =3D NULL; + } =20 /* Important Note: * libvirt relies on the DeviceNotFound error class in order to probe= for @@ -3117,8 +3121,8 @@ void qmp_block_commit(bool has_job_id, const char *jo= b_id, const char *device, goto out; } commit_active_start(has_job_id ? job_id : NULL, bs, base_bs, - BLOCK_JOB_DEFAULT, speed, on_error, NULL, NULL, - &local_err, false); + BLOCK_JOB_DEFAULT, speed, on_error, + filter_node_name, NULL, NULL, &local_err, fals= e); } else { BlockDriverState *overlay_bs =3D bdrv_find_overlay(bs, top_bs); if (bdrv_op_is_blocked(overlay_bs, BLOCK_OP_TYPE_COMMIT_TARGET, er= rp)) { @@ -3126,7 +3130,7 @@ void qmp_block_commit(bool has_job_id, const char *jo= b_id, const char *device, } commit_start(has_job_id ? job_id : NULL, bs, base_bs, top_bs, spee= d, on_error, has_backing_file ? backing_file : NULL, - &local_err); + filter_node_name, &local_err); } if (local_err !=3D NULL) { error_propagate(errp, local_err); diff --git a/include/block/block_int.h b/include/block/block_int.h index 563b30c..a57c0bf 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -780,13 +780,16 @@ void stream_start(const char *job_id, BlockDriverStat= e *bs, * @speed: The maximum speed, in bytes per second, or 0 for unlimited. * @on_error: The action to take upon error. * @backing_file_str: String to use as the backing file in @top's overlay + * @filter_node_name: The node name that should be assigned to the filter + * driver that the commit job inserts into the graph above @top. NULL means + * that a node name should be autogenerated. * @errp: Error object. * */ void commit_start(const char *job_id, BlockDriverState *bs, BlockDriverState *base, BlockDriverState *top, int64_t s= peed, BlockdevOnError on_error, const char *backing_file_str, - Error **errp); + const char *filter_node_name, Error **errp); /** * commit_active_start: * @job_id: The id of the newly-created job, or %NULL to use the @@ -797,6 +800,9 @@ void commit_start(const char *job_id, BlockDriverState = *bs, * See @BlockJobCreateFlags * @speed: The maximum speed, in bytes per second, or 0 for unlimited. * @on_error: The action to take upon error. + * @filter_node_name: The node name that should be assigned to the filter + * driver that the commit job inserts into the graph above @bs. NULL means= that + * a node name should be autogenerated. * @cb: Completion function for the job. * @opaque: Opaque pointer value passed to @cb. * @errp: Error object. @@ -806,8 +812,9 @@ void commit_start(const char *job_id, BlockDriverState = *bs, void commit_active_start(const char *job_id, BlockDriverState *bs, BlockDriverState *base, int creation_flags, int64_t speed, BlockdevOnError on_error, - BlockCompletionFunc *cb, - void *opaque, Error **errp, bool auto_complete); + const char *filter_node_name, + BlockCompletionFunc *cb, void *opaque, Error **er= rp, + bool auto_complete); /* * mirror_start: * @job_id: The id of the newly-created job, or %NULL to use the diff --git a/qapi/block-core.json b/qapi/block-core.json index 893fa34..36d38b9 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1304,6 +1304,11 @@ # # @speed: #optional the maximum speed, in bytes per second # +# @filter-node-name: #optional the node name that should be assigned to the +# filter driver that the commit job inserts into the gr= aph +# above @device. If this option is not given, a node na= me is +# autogenerated. (Since: 2.9) +# # Returns: Nothing on success # If commit or stream is already active on this device, DeviceInU= se # If @device does not exist, DeviceNotFound @@ -1323,7 +1328,8 @@ ## { 'command': 'block-commit', 'data': { '*job-id': 'str', 'device': 'str', '*base': 'str', '*top': 'st= r', - '*backing-file': 'str', '*speed': 'int' } } + '*backing-file': 'str', '*speed': 'int', + '*filter-node-name': 'str' } } =20 ## # @drive-backup: diff --git a/qemu-img.c b/qemu-img.c index e20830f..fc72d21 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -939,8 +939,8 @@ static int img_commit(int argc, char **argv) aio_context =3D bdrv_get_aio_context(bs); aio_context_acquire(aio_context); commit_active_start("commit", bs, base_bs, BLOCK_JOB_DEFAULT, 0, - BLOCKDEV_ON_ERROR_REPORT, common_block_job_cb, &cb= i, - &local_err, false); + BLOCKDEV_ON_ERROR_REPORT, NULL, common_block_job_c= b, + &cbi, &local_err, false); aio_context_release(aio_context); if (local_err) { goto done; --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487693909239137.3363412671606; Tue, 21 Feb 2017 08:18:29 -0800 (PST) Received: from localhost ([::1]:46637 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgD8z-0007yF-Rl for importer@patchew.org; Tue, 21 Feb 2017 11:18:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43786) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBvN-0001IN-EM for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBvM-0008Ry-2V for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48608) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBvC-0008I5-Ri; Tue, 21 Feb 2017 10:00:07 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 EB6584D69D; Tue, 21 Feb 2017 15:00:06 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudU030565; Tue, 21 Feb 2017 10:00:05 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:42 +0100 Message-Id: <1487689130-30373-47-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 21 Feb 2017 15:00:06 +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 46/54] hmp: Request permissions in qemu-io 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 HMP command 'qemu-io' is a bit tricky because it wants to work on the original BlockBackend, but additional permissions could be required. The details are explained in a comment in the code, but in summary, just request whatever permissions the current qemu-io command needs. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/block-backend.c | 6 ++++++ hmp.c | 26 +++++++++++++++++++++++++- include/qemu-io.h | 1 + include/sysemu/block-backend.h | 1 + qemu-io-cmds.c | 28 ++++++++++++++++++++++++++++ 5 files changed, 61 insertions(+), 1 deletion(-) diff --git a/block/block-backend.c b/block/block-backend.c index 38a3858..daa7908 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -584,6 +584,12 @@ int blk_set_perm(BlockBackend *blk, uint64_t perm, uin= t64_t shared_perm, return 0; } =20 +void blk_get_perm(BlockBackend *blk, uint64_t *perm, uint64_t *shared_perm) +{ + *perm =3D blk->perm; + *shared_perm =3D blk->shared_perm; +} + static int blk_do_attach_dev(BlockBackend *blk, void *dev) { if (blk->dev) { diff --git a/hmp.c b/hmp.c index 801fddb..fde5016 100644 --- a/hmp.c +++ b/hmp.c @@ -2045,7 +2045,6 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict) if (!blk) { BlockDriverState *bs =3D bdrv_lookup_bs(NULL, device, &err); if (bs) { - /* FIXME Use real permissions */ blk =3D local_blk =3D blk_new(0, BLK_PERM_ALL); ret =3D blk_insert_bs(blk, bs, &err); if (ret < 0) { @@ -2059,6 +2058,31 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict) aio_context =3D blk_get_aio_context(blk); aio_context_acquire(aio_context); =20 + /* + * Notably absent: Proper permission management. This is sad, but it s= eems + * almost impossible to achieve without changing the semantics and the= reby + * limiting the use cases of the qemu-io HMP command. + * + * In an ideal world we would unconditionally create a new BlockBacken= d for + * qemuio_command(), but we have commands like 'reopen' and want them = to + * take effect on the exact BlockBackend whose name the user passed in= stead + * of just on a temporary copy of it. + * + * Another problem is that deleting the temporary BlockBackend involves + * draining all requests on it first, but some qemu-iotests cases want= to + * issue multiple aio_read/write requests and expect them to complete = in + * the background while the monitor has already returned. + * + * This is also what prevents us from saving the original permissions = and + * restoring them later: We can't revoke permissions until all requests + * have completed, and we don't know when that is nor can we really let + * anything else run before we have revoken them to avoid race conditi= ons. + * + * What happens now is that command() in qemu-io-cmds.c can extend the + * permissions if necessary for the qemu-io command. And they simply s= tay + * extended, possibly resulting in a read-only guest device keeping wr= ite + * permissions. Ugly, but it appears to be the lesser evil. + */ qemuio_command(blk, command); =20 aio_context_release(aio_context); diff --git a/include/qemu-io.h b/include/qemu-io.h index 4d402b9..196fde0 100644 --- a/include/qemu-io.h +++ b/include/qemu-io.h @@ -36,6 +36,7 @@ typedef struct cmdinfo { const char *args; const char *oneline; helpfunc_t help; + uint64_t perm; } cmdinfo_t; =20 extern bool qemuio_misalign; diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index b23f683..096c17f 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -107,6 +107,7 @@ bool bdrv_has_blk(BlockDriverState *bs); bool bdrv_is_root_node(BlockDriverState *bs); int blk_set_perm(BlockBackend *blk, uint64_t perm, uint64_t shared_perm, Error **errp); +void blk_get_perm(BlockBackend *blk, uint64_t *perm, uint64_t *shared_perm= ); =20 void blk_set_allow_write_beyond_eof(BlockBackend *blk, bool allow); void blk_iostatus_enable(BlockBackend *blk); diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index e415b03..035cb96 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -83,6 +83,29 @@ static int command(BlockBackend *blk, const cmdinfo_t *c= t, int argc, } return 0; } + + /* Request additional permissions if necessary for this command. The c= aller + * is responsible for restoring the original permissions afterwards if= this + * is what it wants. */ + if (ct->perm && blk_is_available(blk)) { + uint64_t orig_perm, orig_shared_perm; + blk_get_perm(blk, &orig_perm, &orig_shared_perm); + + if (ct->perm & ~orig_perm) { + uint64_t new_perm; + Error *local_err =3D NULL; + int ret; + + new_perm =3D orig_perm | ct->perm; + + ret =3D blk_set_perm(blk, new_perm, orig_shared_perm, &local_e= rr); + if (ret < 0) { + error_report_err(local_err); + return 0; + } + } + } + optind =3D 0; return ct->cfunc(blk, argc, argv); } @@ -916,6 +939,7 @@ static const cmdinfo_t write_cmd =3D { .name =3D "write", .altname =3D "w", .cfunc =3D write_f, + .perm =3D BLK_PERM_WRITE, .argmin =3D 2, .argmax =3D -1, .args =3D "[-bcCfquz] [-P pattern] off len", @@ -1091,6 +1115,7 @@ static int writev_f(BlockBackend *blk, int argc, char= **argv); static const cmdinfo_t writev_cmd =3D { .name =3D "writev", .cfunc =3D writev_f, + .perm =3D BLK_PERM_WRITE, .argmin =3D 2, .argmax =3D -1, .args =3D "[-Cfq] [-P pattern] off len [len..]", @@ -1390,6 +1415,7 @@ static int aio_write_f(BlockBackend *blk, int argc, c= har **argv); static const cmdinfo_t aio_write_cmd =3D { .name =3D "aio_write", .cfunc =3D aio_write_f, + .perm =3D BLK_PERM_WRITE, .argmin =3D 2, .argmax =3D -1, .args =3D "[-Cfiquz] [-P pattern] off len [len..]", @@ -1554,6 +1580,7 @@ static const cmdinfo_t truncate_cmd =3D { .name =3D "truncate", .altname =3D "t", .cfunc =3D truncate_f, + .perm =3D BLK_PERM_WRITE | BLK_PERM_RESIZE, .argmin =3D 1, .argmax =3D 1, .args =3D "off", @@ -1651,6 +1678,7 @@ static const cmdinfo_t discard_cmd =3D { .name =3D "discard", .altname =3D "d", .cfunc =3D discard_f, + .perm =3D BLK_PERM_WRITE, .argmin =3D 2, .argmax =3D -1, .args =3D "[-Cq] off len", --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 14876949868341023.3322111399355; Tue, 21 Feb 2017 08:36:26 -0800 (PST) Received: from localhost ([::1]:46771 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgDQM-0007yi-D8 for importer@patchew.org; Tue, 21 Feb 2017 11:36:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43891) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBvU-0001R2-V8 for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBvP-0008To-7u for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33348) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBvE-0008KC-5v; Tue, 21 Feb 2017 10:00:08 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 3EFFF7FB96; Tue, 21 Feb 2017 15:00:08 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudV030565; Tue, 21 Feb 2017 10:00:07 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:43 +0100 Message-Id: <1487689130-30373-48-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 21 Feb 2017 15:00:08 +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 47/54] migration/block: Use real permissions 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" Request BLK_PERM_CONSISTENT_READ for the source of block migration, and handle potential permission errors as good as we can in this place (which is not very good, but it matches the other failure cases). Signed-off-by: Kevin Wolf --- migration/block.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/migration/block.c b/migration/block.c index d259936..958d0fc 100644 --- a/migration/block.c +++ b/migration/block.c @@ -379,7 +379,7 @@ static void unset_dirty_tracking(void) } } =20 -static void init_blk_migration(QEMUFile *f) +static int init_blk_migration(QEMUFile *f) { BlockDriverState *bs; BlkMigDevState *bmds; @@ -390,6 +390,8 @@ static void init_blk_migration(QEMUFile *f) BlkMigDevState *bmds; BlockDriverState *bs; } *bmds_bs; + Error *local_err =3D NULL; + int ret; =20 block_mig_state.submitted =3D 0; block_mig_state.read_done =3D 0; @@ -411,12 +413,12 @@ static void init_blk_migration(QEMUFile *f) =20 sectors =3D bdrv_nb_sectors(bs); if (sectors <=3D 0) { + ret =3D sectors; goto out; } =20 bmds =3D g_new0(BlkMigDevState, 1); - /* FIXME Use real permissions */ - bmds->blk =3D blk_new(0, BLK_PERM_ALL); + bmds->blk =3D blk_new(BLK_PERM_CONSISTENT_READ, BLK_PERM_ALL); bmds->blk_name =3D g_strdup(bdrv_get_device_name(bs)); bmds->bulk_completed =3D 0; bmds->total_sectors =3D sectors; @@ -446,7 +448,11 @@ static void init_blk_migration(QEMUFile *f) BlockDriverState *bs =3D bmds_bs[i].bs; =20 if (bmds) { - blk_insert_bs(bmds->blk, bs, &error_abort); + ret =3D blk_insert_bs(bmds->blk, bs, &local_err); + if (ret < 0) { + error_report_err(local_err); + goto out; + } =20 alloc_aio_bitmap(bmds); error_setg(&bmds->blocker, "block device is in use by migratio= n"); @@ -454,8 +460,10 @@ static void init_blk_migration(QEMUFile *f) } } =20 + ret =3D 0; out: g_free(bmds_bs); + return ret; } =20 /* Called with no lock taken. */ @@ -706,7 +714,10 @@ static int block_save_setup(QEMUFile *f, void *opaque) block_mig_state.submitted, block_mig_state.transferred); =20 qemu_mutex_lock_iothread(); - init_blk_migration(f); + ret =3D init_blk_migration(f); + if (ret < 0) { + return ret; + } =20 /* start track dirty blocks */ ret =3D set_dirty_tracking(); --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487692430540512.2985061733133; Tue, 21 Feb 2017 07:53:50 -0800 (PST) Received: from localhost ([::1]:46480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgClB-0000jp-7I for importer@patchew.org; Tue, 21 Feb 2017 10:53:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43863) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBvS-0001OW-NF for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBvN-0008Sl-93 for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42836) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBvF-0008MD-QC; Tue, 21 Feb 2017 10:00:09 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 D4ED9F44D7; Tue, 21 Feb 2017 15:00:09 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudW030565; Tue, 21 Feb 2017 10:00:08 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:44 +0100 Message-Id: <1487689130-30373-49-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 21 Feb 2017 15:00:09 +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 48/54] nbd/server: Use real permissions for NBD exports 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" NBD can't cope with device size changes, so resize must be forbidden, but otherwise we can tolerate anything. Depending on whether the export is writable or not, we only require consistent reads and writes. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- nbd/server.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 89362ba..924a1fe 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -891,10 +891,17 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t= dev_offset, off_t size, { BlockBackend *blk; NBDExport *exp =3D g_malloc0(sizeof(NBDExport)); + uint64_t perm; int ret; =20 - /* FIXME Use real permissions */ - blk =3D blk_new(0, BLK_PERM_ALL); + /* Don't allow resize while the NBD server is running, otherwise we do= n't + * care what happens with the node. */ + perm =3D BLK_PERM_CONSISTENT_READ; + if ((nbdflags & NBD_FLAG_READ_ONLY) =3D=3D 0) { + perm |=3D BLK_PERM_WRITE; + } + blk =3D blk_new(perm, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHAN= GED | + BLK_PERM_WRITE | BLK_PERM_GRAPH_MOD); ret =3D blk_insert_bs(blk, bs, errp); if (ret < 0) { goto fail; --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 14876944515941011.7976831241288; Tue, 21 Feb 2017 08:27:31 -0800 (PST) Received: from localhost ([::1]:46700 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgDHj-0007iz-CE for importer@patchew.org; Tue, 21 Feb 2017 11:27:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43875) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBvT-0001Or-2A for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBvS-0008V7-5K for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35992) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBvH-0008Nb-8x; Tue, 21 Feb 2017 10:00:11 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 511246267F; Tue, 21 Feb 2017 15:00:11 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudX030565; Tue, 21 Feb 2017 10:00:09 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:45 +0100 Message-Id: <1487689130-30373-50-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 21 Feb 2017 15:00:11 +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 49/54] tests: Remove FIXME comments 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" Not requesting any permissions is actually correct for these test cases because no actual I/O or other operation covered by the permission system is performed. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- tests/test-blockjob.c | 2 +- tests/test-throttle.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c index 1afe17b..740e740 100644 --- a/tests/test-blockjob.c +++ b/tests/test-blockjob.c @@ -54,7 +54,7 @@ static BlockJob *do_test_id(BlockBackend *blk, const char= *id, * BlockDriverState inserted. */ static BlockBackend *create_blk(const char *name) { - /* FIXME Use real permissions */ + /* No I/O is performed on this device */ BlockBackend *blk =3D blk_new(0, BLK_PERM_ALL); BlockDriverState *bs; =20 diff --git a/tests/test-throttle.c b/tests/test-throttle.c index 5846433..bd7c501 100644 --- a/tests/test-throttle.c +++ b/tests/test-throttle.c @@ -593,7 +593,7 @@ static void test_groups(void) BlockBackend *blk1, *blk2, *blk3; BlockBackendPublic *blkp1, *blkp2, *blkp3; =20 - /* FIXME Use real permissions */ + /* No actual I/O is performed on these devices */ blk1 =3D blk_new(0, BLK_PERM_ALL); blk2 =3D blk_new(0, BLK_PERM_ALL); blk3 =3D blk_new(0, BLK_PERM_ALL); --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487694567522985.9942232383875; Tue, 21 Feb 2017 08:29:27 -0800 (PST) Received: from localhost ([::1]:46713 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgDJd-0001MF-88 for importer@patchew.org; Tue, 21 Feb 2017 11:29:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43893) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBvV-0001R4-0A for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBvQ-0008UR-Ry for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50338) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBvJ-0008P1-DL; Tue, 21 Feb 2017 10:00:13 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 3DD552DC342; Tue, 21 Feb 2017 15:00:13 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudY030565; Tue, 21 Feb 2017 10:00:11 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:46 +0100 Message-Id: <1487689130-30373-51-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 21 Feb 2017 15:00:13 +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 50/54] block: Pass BdrvChild to bdrv_aligned_preadv/pwritev 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" This is where we want to check the permissions, so we need to have the BdrvChild around where they are stored. Signed-off-by: Kevin Wolf --- block/io.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/block/io.c b/block/io.c index d5c4544..63e4400 100644 --- a/block/io.c +++ b/block/io.c @@ -1001,10 +1001,11 @@ err: * handles copy on read, zeroing after EOF, and fragmentation of large * reads; any other features must be implemented by the caller. */ -static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs, +static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child, BdrvTrackedRequest *req, int64_t offset, unsigned int bytes, int64_t align, QEMUIOVector *qiov, int flags) { + BlockDriverState *bs =3D child->bs; int64_t total_bytes, max_bytes; int ret =3D 0; uint64_t bytes_remaining =3D bytes; @@ -1158,7 +1159,7 @@ int coroutine_fn bdrv_co_preadv(BdrvChild *child, } =20 tracked_request_begin(&req, bs, offset, bytes, BDRV_TRACKED_READ); - ret =3D bdrv_aligned_preadv(bs, &req, offset, bytes, align, + ret =3D bdrv_aligned_preadv(child, &req, offset, bytes, align, use_local_qiov ? &local_qiov : qiov, flags); tracked_request_end(&req); @@ -1306,10 +1307,11 @@ fail: * Forwards an already correctly aligned write request to the BlockDriver, * after possibly fragmenting it. */ -static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs, +static int coroutine_fn bdrv_aligned_pwritev(BdrvChild *child, BdrvTrackedRequest *req, int64_t offset, unsigned int bytes, int64_t align, QEMUIOVector *qiov, int flags) { + BlockDriverState *bs =3D child->bs; BlockDriver *drv =3D bs->drv; bool waited; int ret; @@ -1397,12 +1399,13 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockD= riverState *bs, return ret; } =20 -static int coroutine_fn bdrv_co_do_zero_pwritev(BlockDriverState *bs, +static int coroutine_fn bdrv_co_do_zero_pwritev(BdrvChild *child, int64_t offset, unsigned int bytes, BdrvRequestFlags flags, BdrvTrackedRequest *req) { + BlockDriverState *bs =3D child->bs; uint8_t *buf =3D NULL; QEMUIOVector local_qiov; struct iovec iov; @@ -1430,7 +1433,7 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(Block= DriverState *bs, mark_request_serialising(req, align); wait_serialising_requests(req); bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_HEAD); - ret =3D bdrv_aligned_preadv(bs, req, offset & ~(align - 1), align, + ret =3D bdrv_aligned_preadv(child, req, offset & ~(align - 1), ali= gn, align, &local_qiov, 0); if (ret < 0) { goto fail; @@ -1438,7 +1441,7 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(Block= DriverState *bs, bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_AFTER_HEAD); =20 memset(buf + head_padding_bytes, 0, zero_bytes); - ret =3D bdrv_aligned_pwritev(bs, req, offset & ~(align - 1), align, + ret =3D bdrv_aligned_pwritev(child, req, offset & ~(align - 1), al= ign, align, &local_qiov, flags & ~BDRV_REQ_ZERO_WRITE); if (ret < 0) { @@ -1452,7 +1455,7 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(Block= DriverState *bs, if (bytes >=3D align) { /* Write the aligned part in the middle. */ uint64_t aligned_bytes =3D bytes & ~(align - 1); - ret =3D bdrv_aligned_pwritev(bs, req, offset, aligned_bytes, align, + ret =3D bdrv_aligned_pwritev(child, req, offset, aligned_bytes, al= ign, NULL, flags); if (ret < 0) { goto fail; @@ -1468,7 +1471,7 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(Block= DriverState *bs, mark_request_serialising(req, align); wait_serialising_requests(req); bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_TAIL); - ret =3D bdrv_aligned_preadv(bs, req, offset, align, + ret =3D bdrv_aligned_preadv(child, req, offset, align, align, &local_qiov, 0); if (ret < 0) { goto fail; @@ -1476,7 +1479,7 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(Block= DriverState *bs, bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_AFTER_TAIL); =20 memset(buf, 0, bytes); - ret =3D bdrv_aligned_pwritev(bs, req, offset, align, align, + ret =3D bdrv_aligned_pwritev(child, req, offset, align, align, &local_qiov, flags & ~BDRV_REQ_ZERO_WRI= TE); } fail: @@ -1523,7 +1526,7 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child, tracked_request_begin(&req, bs, offset, bytes, BDRV_TRACKED_WRITE); =20 if (!qiov) { - ret =3D bdrv_co_do_zero_pwritev(bs, offset, bytes, flags, &req); + ret =3D bdrv_co_do_zero_pwritev(child, offset, bytes, flags, &req); goto out; } =20 @@ -1542,7 +1545,7 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child, qemu_iovec_init_external(&head_qiov, &head_iov, 1); =20 bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_HEAD); - ret =3D bdrv_aligned_preadv(bs, &req, offset & ~(align - 1), align, + ret =3D bdrv_aligned_preadv(child, &req, offset & ~(align - 1), al= ign, align, &head_qiov, 0); if (ret < 0) { goto fail; @@ -1584,8 +1587,8 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child, qemu_iovec_init_external(&tail_qiov, &tail_iov, 1); =20 bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_TAIL); - ret =3D bdrv_aligned_preadv(bs, &req, (offset + bytes) & ~(align -= 1), align, - align, &tail_qiov, 0); + ret =3D bdrv_aligned_preadv(child, &req, (offset + bytes) & ~(alig= n - 1), + align, align, &tail_qiov, 0); if (ret < 0) { goto fail; } @@ -1603,7 +1606,7 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child, bytes =3D ROUND_UP(bytes, align); } =20 - ret =3D bdrv_aligned_pwritev(bs, &req, offset, bytes, align, + ret =3D bdrv_aligned_pwritev(child, &req, offset, bytes, align, use_local_qiov ? &local_qiov : qiov, flags); =20 --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487694713441806.1130701585097; Tue, 21 Feb 2017 08:31:53 -0800 (PST) Received: from localhost ([::1]:46733 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgDLx-0003az-7I for importer@patchew.org; Tue, 21 Feb 2017 11:31:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43819) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBvQ-0001M1-DU for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBvM-0008S7-Cv for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59460) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBvK-0008PZ-70; Tue, 21 Feb 2017 10:00:14 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 3E0C84E02A; Tue, 21 Feb 2017 15:00:14 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudZ030565; Tue, 21 Feb 2017 10:00:12 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:47 +0100 Message-Id: <1487689130-30373-52-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 21 Feb 2017 15:00:14 +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 51/54] block: Assertions for write permissions 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" This adds assertions that ensure that the necessary write permissions have been granted before someone attempts to write to a node. Signed-off-by: Kevin Wolf --- block/io.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/block/io.c b/block/io.c index 63e4400..4c79745 100644 --- a/block/io.c +++ b/block/io.c @@ -925,9 +925,11 @@ bdrv_driver_pwritev_compressed(BlockDriverState *bs, u= int64_t offset, return drv->bdrv_co_pwritev_compressed(bs, offset, bytes, qiov); } =20 -static int coroutine_fn bdrv_co_do_copy_on_readv(BlockDriverState *bs, +static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child, int64_t offset, unsigned int bytes, QEMUIOVector *qiov) { + BlockDriverState *bs =3D child->bs; + /* Perform I/O through a temporary buffer so that users who scribble o= ver * their read buffer while the operation is in progress do not end up * modifying the image file. This is critical for zero-copy guest I/O @@ -943,6 +945,8 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BlockD= riverState *bs, size_t skip_bytes; int ret; =20 + assert(child->perm & (BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE)); + /* Cover entire cluster so no additional backing file I/O is required = when * allocating cluster in the image file. */ @@ -1051,7 +1055,7 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild= *child, } =20 if (!ret || pnum !=3D nb_sectors) { - ret =3D bdrv_co_do_copy_on_readv(bs, offset, bytes, qiov); + ret =3D bdrv_co_do_copy_on_readv(child, offset, bytes, qiov); goto out; } } @@ -1334,6 +1338,7 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChil= d *child, assert(!waited || !req->serialising); assert(req->overlap_offset <=3D offset); assert(offset + bytes <=3D req->overlap_offset + req->overlap_bytes); + assert(child->perm & BLK_PERM_WRITE); =20 ret =3D notifier_with_return_list_notify(&bs->before_write_notifiers, = req); =20 --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487692689261947.0444921315473; Tue, 21 Feb 2017 07:58:09 -0800 (PST) Received: from localhost ([::1]:46504 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCpM-00056B-31 for importer@patchew.org; Tue, 21 Feb 2017 10:58:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43968) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBvc-0001Ye-4V for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBvX-00006S-8l for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48754) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBvL-0008RG-QF; Tue, 21 Feb 2017 10:00:15 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 CE0306AAC5; Tue, 21 Feb 2017 15:00:15 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwuda030565; Tue, 21 Feb 2017 10:00:14 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:48 +0100 Message-Id: <1487689130-30373-53-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 21 Feb 2017 15:00:15 +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 52/54] block: Assertions for resize permission 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" This adds an assertion that ensures that the necessary resize permission has been granted before bdrv_truncate() is called. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block.c b/block.c index 560e84a..33e6415 100644 --- a/block.c +++ b/block.c @@ -3098,6 +3098,9 @@ int bdrv_truncate(BdrvChild *child, int64_t offset) BlockDriverState *bs =3D child->bs; BlockDriver *drv =3D bs->drv; int ret; + + assert(child->perm & BLK_PERM_RESIZE); + if (!drv) return -ENOMEDIUM; if (!drv->bdrv_truncate) --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487692954145516.7769370492375; Tue, 21 Feb 2017 08:02:34 -0800 (PST) Received: from localhost ([::1]:46540 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCtY-0000os-Hq for importer@patchew.org; Tue, 21 Feb 2017 11:02:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43967) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBvc-0001Yd-4N for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBvY-00007R-FF for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59538) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBvN-0008SN-GB; Tue, 21 Feb 2017 10:00:17 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 7062B4E359; Tue, 21 Feb 2017 15:00:17 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudb030565; Tue, 21 Feb 2017 10:00:15 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:49 +0100 Message-Id: <1487689130-30373-54-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 21 Feb 2017 15:00:17 +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 53/54] block: Add Error parameter to bdrv_set_backing_hd() 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" Not all callers of bdrv_set_backing_hd() know for sure that attaching the backing file will be allowed by the permission system. Return the error from the function rather than aborting. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 27 ++++++++++++++++++++------- block/commit.c | 14 +++++++------- block/mirror.c | 16 +++++++++++++++- block/stream.c | 9 ++++++++- block/vvfat.c | 2 +- include/block/block.h | 3 ++- 6 files changed, 53 insertions(+), 18 deletions(-) diff --git a/block.c b/block.c index 33e6415..b3f03a4 100644 --- a/block.c +++ b/block.c @@ -1859,7 +1859,8 @@ static void bdrv_parent_cb_resize(BlockDriverState *b= s) * Sets the backing file link of a BDS. A new reference is created; callers * which don't need their own reference any more must call bdrv_unref(). */ -void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_h= d) +void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_h= d, + Error **errp) { if (backing_hd) { bdrv_ref(backing_hd); @@ -1873,9 +1874,9 @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockD= riverState *backing_hd) bs->backing =3D NULL; goto out; } - /* FIXME Error handling */ + bs->backing =3D bdrv_attach_child(bs, backing_hd, "backing", &child_ba= cking, - &error_abort); + errp); =20 out: bdrv_refresh_limits(bs, NULL); @@ -1959,8 +1960,12 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDi= ct *parent_options, =20 /* Hook up the backing file link; drop our reference, bs owns the * backing_hd reference now */ - bdrv_set_backing_hd(bs, backing_hd); + bdrv_set_backing_hd(bs, backing_hd, &local_err); bdrv_unref(backing_hd); + if (local_err) { + ret =3D -EINVAL; + goto free_exit; + } =20 qdict_del(parent_options, bdref_key); =20 @@ -2796,7 +2801,7 @@ static void bdrv_close(BlockDriverState *bs) bs->drv->bdrv_close(bs); bs->drv =3D NULL; =20 - bdrv_set_backing_hd(bs, NULL); + bdrv_set_backing_hd(bs, NULL, &error_abort); =20 if (bs->file !=3D NULL) { bdrv_unref_child(bs, bs->file); @@ -2903,7 +2908,8 @@ void bdrv_append(BlockDriverState *bs_new, BlockDrive= rState *bs_top) bdrv_ref(bs_top); =20 change_parent_backing_link(bs_top, bs_new); - bdrv_set_backing_hd(bs_new, bs_top); + /* FIXME Error handling */ + bdrv_set_backing_hd(bs_new, bs_top, &error_abort); bdrv_unref(bs_top); =20 /* bs_new is now referenced by its new parents, we don't need the @@ -3051,6 +3057,7 @@ int bdrv_drop_intermediate(BlockDriverState *active, = BlockDriverState *top, BlockDriverState *base, const char *backing_fil= e_str) { BlockDriverState *new_top_bs =3D NULL; + Error *local_err =3D NULL; int ret =3D -EIO; =20 if (!top->drv || !base->drv) { @@ -3083,7 +3090,13 @@ int bdrv_drop_intermediate(BlockDriverState *active,= BlockDriverState *top, if (ret) { goto exit; } - bdrv_set_backing_hd(new_top_bs, base); + + bdrv_set_backing_hd(new_top_bs, base, &local_err); + if (local_err) { + ret =3D -EPERM; + error_report_err(local_err); + goto exit; + } =20 ret =3D 0; exit: diff --git a/block/commit.c b/block/commit.c index b9ec363..9838e77 100644 --- a/block/commit.c +++ b/block/commit.c @@ -118,7 +118,7 @@ static void commit_complete(BlockJob *job, void *opaque) * filter driver from the backing chain. Do this as the final step so = that * the 'consistent read' permission can be granted. */ if (remove_commit_top_bs) { - bdrv_set_backing_hd(overlay_bs, top); + bdrv_set_backing_hd(overlay_bs, top, &error_abort); } } =20 @@ -313,8 +313,8 @@ void commit_start(const char *job_id, BlockDriverState = *bs, goto fail; } =20 - bdrv_set_backing_hd(commit_top_bs, top); - bdrv_set_backing_hd(overlay_bs, commit_top_bs); + bdrv_set_backing_hd(commit_top_bs, top, &error_abort); + bdrv_set_backing_hd(overlay_bs, commit_top_bs, &error_abort); =20 s->commit_top_bs =3D commit_top_bs; bdrv_unref(commit_top_bs); @@ -386,7 +386,7 @@ fail: blk_unref(s->top); } if (commit_top_bs) { - bdrv_set_backing_hd(overlay_bs, top); + bdrv_set_backing_hd(overlay_bs, top, &error_abort); } block_job_unref(&s->common); } @@ -447,8 +447,8 @@ int bdrv_commit(BlockDriverState *bs) goto ro_cleanup; } =20 - bdrv_set_backing_hd(commit_top_bs, backing_file_bs); - bdrv_set_backing_hd(bs, commit_top_bs); + bdrv_set_backing_hd(commit_top_bs, backing_file_bs, &error_abort); + bdrv_set_backing_hd(bs, commit_top_bs, &error_abort); =20 ret =3D blk_insert_bs(backing, backing_file_bs, &local_err); if (ret < 0) { @@ -527,7 +527,7 @@ ro_cleanup: qemu_vfree(buf); =20 if (backing_file_bs) { - bdrv_set_backing_hd(bs, backing_file_bs); + bdrv_set_backing_hd(bs, backing_file_bs, &error_abort); } bdrv_unref(commit_top_bs); blk_unref(src); diff --git a/block/mirror.c b/block/mirror.c index fa0c0e5..abbd847 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -887,6 +887,7 @@ static void mirror_complete(BlockJob *job, Error **errp) { MirrorBlockJob *s =3D container_of(job, MirrorBlockJob, common); BlockDriverState *src, *target; + Error *local_err =3D NULL; =20 src =3D s->source; target =3D blk_bs(s->target); @@ -935,12 +936,25 @@ static void mirror_complete(BlockJob *job, Error **er= rp) if (s->backing_mode =3D=3D MIRROR_SOURCE_BACKING_CHAIN) { BlockDriverState *backing =3D s->is_none_mode ? src : s->base; if (backing_bs(target) !=3D backing) { - bdrv_set_backing_hd(target, backing); + bdrv_set_backing_hd(target, backing, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto fail; + } } } =20 s->should_complete =3D true; block_job_enter(&s->common); + return; + +fail: + if (s->replaces) { + bdrv_unref(s->to_replace); + bdrv_op_unblock_all(s->to_replace, s->replace_blocker); + error_free(s->replace_blocker); + s->replace_blocker =3D NULL; + } } =20 static void mirror_pause(BlockJob *job) diff --git a/block/stream.c b/block/stream.c index 0c30d41..bd3d2ce 100644 --- a/block/stream.c +++ b/block/stream.c @@ -68,6 +68,7 @@ static void stream_complete(BlockJob *job, void *opaque) StreamCompleteData *data =3D opaque; BlockDriverState *bs =3D blk_bs(job->blk); BlockDriverState *base =3D s->base; + Error *local_err =3D NULL; =20 if (!block_job_is_cancelled(&s->common) && data->reached_end && data->ret =3D=3D 0) { @@ -79,9 +80,15 @@ static void stream_complete(BlockJob *job, void *opaque) } } data->ret =3D bdrv_change_backing_file(bs, base_id, base_fmt); - bdrv_set_backing_hd(bs, base); + bdrv_set_backing_hd(bs, base, &local_err); + if (local_err) { + error_report_err(local_err); + data->ret =3D -EPERM; + goto out; + } } =20 +out: /* Reopen the image back in read-only mode if necessary */ if (s->bs_flags !=3D bdrv_get_flags(bs)) { bdrv_reopen(bs, s->bs_flags, NULL); diff --git a/block/vvfat.c b/block/vvfat.c index 72b482c..aa61c32 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3041,7 +3041,7 @@ static int enable_write_target(BlockDriverState *bs, = Error **errp) &error_abort); *(void**) backing->opaque =3D s; =20 - bdrv_set_backing_hd(s->bs, backing); + bdrv_set_backing_hd(s->bs, backing, &error_abort); bdrv_unref(backing); =20 return 0; diff --git a/include/block/block.h b/include/block/block.h index 701d22b..6a6408e 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -246,7 +246,8 @@ BdrvChild *bdrv_open_child(const char *filename, BlockDriverState* parent, const BdrvChildRole *child_role, bool allow_none, Error **errp); -void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_h= d); +void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_h= d, + Error **errp); int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options, const char *bdref_key, Error **errp); BlockDriverState *bdrv_open(const char *filename, const char *reference, --=20 1.8.3.1 From nobody Tue May 7 14:29:10 2024 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 1487694845039224.1706950198984; Tue, 21 Feb 2017 08:34:05 -0800 (PST) Received: from localhost ([::1]:46752 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgDO6-00064s-C2 for importer@patchew.org; Tue, 21 Feb 2017 11:34:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBvc-0001Yf-4W for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBvY-00007r-LQ for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:00:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34760) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBvO-0008TK-MG; Tue, 21 Feb 2017 10:00:18 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 B65C8C04B320; Tue, 21 Feb 2017 15:00:18 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwudc030565; Tue, 21 Feb 2017 10:00:17 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:50 +0100 Message-Id: <1487689130-30373-55-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 21 Feb 2017 15:00:18 +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 54/54] block: Add Error parameter to bdrv_append() 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" Aborting on error in bdrv_append() isn't correct. This patch fixes it and lets the callers handle failures. Test case 085 needs a reference output update. This is caused by the reversed order of bdrv_set_backing_hd() and change_parent_backing_link() in bdrv_append(): When the backing file of the new node is set, the parent nodes are still pointing to the old top, so the backing blocker is now initialised with the node name rather than the BlockBackend name. Signed-off-by: Kevin Wolf --- block.c | 23 +++++++++++++++++------ block/mirror.c | 9 ++++++++- blockdev.c | 15 +++++++++++++-- include/block/block.h | 3 ++- tests/qemu-iotests/085.out | 2 +- 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/block.c b/block.c index b3f03a4..33edbda 100644 --- a/block.c +++ b/block.c @@ -2060,6 +2060,7 @@ static BlockDriverState *bdrv_append_temp_snapshot(Bl= ockDriverState *bs, int64_t total_size; QemuOpts *opts =3D NULL; BlockDriverState *bs_snapshot; + Error *local_err =3D NULL; int ret; =20 /* if snapshot, we create a temporary backing file and open it @@ -2109,7 +2110,12 @@ static BlockDriverState *bdrv_append_temp_snapshot(B= lockDriverState *bs, * call bdrv_unref() on it), so in order to be able to return one, we = have * to increase bs_snapshot's refcount here */ bdrv_ref(bs_snapshot); - bdrv_append(bs_snapshot, bs); + bdrv_append(bs_snapshot, bs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret =3D -EINVAL; + goto out; + } =20 g_free(tmp_filename); return bs_snapshot; @@ -2900,20 +2906,25 @@ static void change_parent_backing_link(BlockDriverS= tate *from, * parents of bs_top after bdrv_append() returns. If the caller needs to k= eep a * reference of its own, it must call bdrv_ref(). */ -void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top) +void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top, + Error **errp) { + Error *local_err =3D NULL; + assert(!atomic_read(&bs_top->in_flight)); assert(!atomic_read(&bs_new->in_flight)); =20 - bdrv_ref(bs_top); + bdrv_set_backing_hd(bs_new, bs_top, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto out; + } =20 change_parent_backing_link(bs_top, bs_new); - /* FIXME Error handling */ - bdrv_set_backing_hd(bs_new, bs_top, &error_abort); - bdrv_unref(bs_top); =20 /* bs_new is now referenced by its new parents, we don't need the * additional reference any more. */ +out: bdrv_unref(bs_new); } =20 diff --git a/block/mirror.c b/block/mirror.c index abbd847..4e35d85 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1066,6 +1066,7 @@ static void mirror_start_job(const char *job_id, Bloc= kDriverState *bs, BlockDriverState *mirror_top_bs; bool target_graph_mod; bool target_is_backing; + Error *local_err =3D NULL; int ret; =20 if (granularity =3D=3D 0) { @@ -1096,9 +1097,15 @@ static void mirror_start_job(const char *job_id, Blo= ckDriverState *bs, * it alive until block_job_create() even if bs has no parent. */ bdrv_ref(mirror_top_bs); bdrv_drained_begin(bs); - bdrv_append(mirror_top_bs, bs); + bdrv_append(mirror_top_bs, bs, &local_err); bdrv_drained_end(bs); =20 + if (local_err) { + bdrv_unref(mirror_top_bs); + error_propagate(errp, local_err); + return; + } + /* Make sure that the source is not resized while the job is running */ s =3D block_job_create(job_id, driver, mirror_top_bs, BLK_PERM_CONSISTENT_READ, diff --git a/blockdev.c b/blockdev.c index 63b1ac4..580fa66 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1764,6 +1764,16 @@ static void external_snapshot_prepare(BlkActionState= *common, =20 if (!state->new_bs->drv->supports_backing) { error_setg(errp, "The snapshot does not support backing images"); + return; + } + + /* This removes our old bs and adds the new bs. This is an operation t= hat + * can fail, so we need to do it in .prepare; undoing it for abort is + * always possible. */ + bdrv_append(state->new_bs, state->old_bs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; } } =20 @@ -1774,8 +1784,6 @@ static void external_snapshot_commit(BlkActionState *= common) =20 bdrv_set_aio_context(state->new_bs, state->aio_context); =20 - /* This removes our old bs and adds the new bs */ - bdrv_append(state->new_bs, state->old_bs); /* We don't need (or want) to use the transactional * bdrv_reopen_multiple() across all the entries at once, because we * don't want to abort all of them if one of them fails the reopen */ @@ -1791,6 +1799,9 @@ static void external_snapshot_abort(BlkActionState *c= ommon) DO_UPCAST(ExternalSnapshotState, common, comm= on); if (state->new_bs) { bdrv_unref(state->new_bs); + if (state->new_bs->backing) { + bdrv_replace_in_backing_chain(state->new_bs, state->old_bs); + } } } =20 diff --git a/include/block/block.h b/include/block/block.h index 6a6408e..6ce8b26 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -235,7 +235,8 @@ int bdrv_create(BlockDriver *drv, const char* filename, QemuOpts *opts, Error **errp); int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp); BlockDriverState *bdrv_new(void); -void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top); +void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top, + Error **errp); void bdrv_replace_in_backing_chain(BlockDriverState *old, BlockDriverState *new); =20 diff --git a/tests/qemu-iotests/085.out b/tests/qemu-iotests/085.out index 08e4bb7..182acb4 100644 --- a/tests/qemu-iotests/085.out +++ b/tests/qemu-iotests/085.out @@ -74,7 +74,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D13421= 7728 backing_file=3DTEST_DIR/ =20 =3D=3D=3D Invalid command - snapshot node used as backing hd =3D=3D=3D =20 -{"error": {"class": "GenericError", "desc": "Node 'snap_11' is busy: node = is used as backing hd of 'virtio0'"}} +{"error": {"class": "GenericError", "desc": "Node 'snap_11' is busy: node = is used as backing hd of 'snap_12'"}} =20 =3D=3D=3D Invalid command - snapshot node has a backing image =3D=3D=3D =20 --=20 1.8.3.1