From patchwork Tue Feb 18 12:42:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388349 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 68B2B139A for ; Tue, 18 Feb 2020 12:43:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3FBBF2173E for ; Tue, 18 Feb 2020 12:43:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TSsVHok6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3FBBF2173E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42E5-0005Tw-6v for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:43:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38677) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42DI-0003lx-DR for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:42:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42DG-0000s8-V5 for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:42:56 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:21152 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42DG-0000rl-Ry for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:42:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029774; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W6nUHkAqLbGE//sHpHWbkDZ9SsI0P2veHNCGFDv8d/w=; b=TSsVHok6sbIoSDzgojlSDBZdcNBcQRL32qSM2dQrFuOpV0jlDYJYq3p1QnqbH+VJS9SMby NdqdV+7eon9bNqIyDw0vo13KlmCrZnXBu8hsfxNbl2PxiTa+FPRqeLtFE+wMj7uHX8mQoB XvYEeF0uXRMbhCJgr67PceMU9F3EvSk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-42-_-JDPgsHNz27K0jmfhd0Ew-1; Tue, 18 Feb 2020 07:42:50 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5697518A5508; Tue, 18 Feb 2020 12:42:49 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 99A8417DC8; Tue, 18 Feb 2020 12:42:48 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 01/33] block: Add BlockDriver.is_format Date: Tue, 18 Feb 2020 13:42:10 +0100 Message-Id: <20200218124242.584644-2-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: _-JDPgsHNz27K0jmfhd0Ew-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" We want to unify child_format and child_file at some point. One of the important things that set format drivers apart from other drivers is that they do not expect other format nodes under them (except in the backing chain), i.e. we must not probe formats inside of formats. That means we need something on which to distinguish format drivers from others, and hence this flag. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia --- block/bochs.c | 1 + block/cloop.c | 1 + block/crypto.c | 2 ++ block/dmg.c | 1 + block/parallels.c | 1 + block/qcow.c | 1 + block/qcow2.c | 1 + block/qed.c | 1 + block/raw-format.c | 1 + block/vdi.c | 1 + block/vhdx.c | 1 + block/vmdk.c | 1 + block/vpc.c | 1 + include/block/block_int.h | 7 +++++++ 14 files changed, 21 insertions(+) diff --git a/block/bochs.c b/block/bochs.c index 32bb83b268..e7bbeaa1c4 100644 --- a/block/bochs.c +++ b/block/bochs.c @@ -301,6 +301,7 @@ static BlockDriver bdrv_bochs = { .bdrv_refresh_limits = bochs_refresh_limits, .bdrv_co_preadv = bochs_co_preadv, .bdrv_close = bochs_close, + .is_format = true, }; static void bdrv_bochs_init(void) diff --git a/block/cloop.c b/block/cloop.c index 4de94876d4..f90f1a4b4c 100644 --- a/block/cloop.c +++ b/block/cloop.c @@ -297,6 +297,7 @@ static BlockDriver bdrv_cloop = { .bdrv_refresh_limits = cloop_refresh_limits, .bdrv_co_preadv = cloop_co_preadv, .bdrv_close = cloop_close, + .is_format = true, }; static void bdrv_cloop_init(void) diff --git a/block/crypto.c b/block/crypto.c index 24823835c1..b81f673a51 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -673,6 +673,8 @@ static BlockDriver bdrv_crypto_luks = { .bdrv_get_info = block_crypto_get_info_luks, .bdrv_get_specific_info = block_crypto_get_specific_info_luks, + .is_format = true, + .strong_runtime_opts = block_crypto_strong_runtime_opts, }; diff --git a/block/dmg.c b/block/dmg.c index 4a045f2b3e..ef3c6e771d 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -753,6 +753,7 @@ static BlockDriver bdrv_dmg = { .bdrv_child_perm = bdrv_format_default_perms, .bdrv_co_preadv = dmg_co_preadv, .bdrv_close = dmg_close, + .is_format = true, }; static void bdrv_dmg_init(void) diff --git a/block/parallels.c b/block/parallels.c index 7a01997659..30eda982bd 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -910,6 +910,7 @@ static BlockDriver bdrv_parallels = { .bdrv_co_flush_to_os = parallels_co_flush_to_os, .bdrv_co_readv = parallels_co_readv, .bdrv_co_writev = parallels_co_writev, + .is_format = true, .supports_backing = true, .bdrv_co_create = parallels_co_create, .bdrv_co_create_opts = parallels_co_create_opts, diff --git a/block/qcow.c b/block/qcow.c index fce8989868..0e4f09934c 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -1184,6 +1184,7 @@ static BlockDriver bdrv_qcow = { .bdrv_co_create = qcow_co_create, .bdrv_co_create_opts = qcow_co_create_opts, .bdrv_has_zero_init = bdrv_has_zero_init_1, + .is_format = true, .supports_backing = true, .bdrv_refresh_limits = qcow_refresh_limits, diff --git a/block/qcow2.c b/block/qcow2.c index 3c754f616b..875eb7d5d9 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -5567,6 +5567,7 @@ BlockDriver bdrv_qcow2 = { .bdrv_save_vmstate = qcow2_save_vmstate, .bdrv_load_vmstate = qcow2_load_vmstate, + .is_format = true, .supports_backing = true, .bdrv_change_backing_file = qcow2_change_backing_file, diff --git a/block/qed.c b/block/qed.c index d8c4e5fb1e..eb6139acbc 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1663,6 +1663,7 @@ static BlockDriver bdrv_qed = { .format_name = "qed", .instance_size = sizeof(BDRVQEDState), .create_opts = &qed_create_opts, + .is_format = true, .supports_backing = true, .bdrv_probe = bdrv_qed_probe, diff --git a/block/raw-format.c b/block/raw-format.c index 3a76ec7dd2..2429ff0d23 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -567,6 +567,7 @@ BlockDriver bdrv_raw = { .bdrv_co_copy_range_to = &raw_co_copy_range_to, .bdrv_co_truncate = &raw_co_truncate, .bdrv_getlength = &raw_getlength, + .is_format = true, .has_variable_length = true, .bdrv_measure = &raw_measure, .bdrv_get_info = &raw_get_info, diff --git a/block/vdi.c b/block/vdi.c index 0142da7233..7e87b205b5 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -1051,6 +1051,7 @@ static BlockDriver bdrv_vdi = { .bdrv_get_info = vdi_get_info, + .is_format = true, .create_opts = &vdi_create_opts, .bdrv_co_check = vdi_co_check, }; diff --git a/block/vhdx.c b/block/vhdx.c index f02d2611be..d3c1619026 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -2241,6 +2241,7 @@ static BlockDriver bdrv_vhdx = { .bdrv_co_check = vhdx_co_check, .bdrv_has_zero_init = vhdx_has_zero_init, + .is_format = true, .create_opts = &vhdx_create_opts, }; diff --git a/block/vmdk.c b/block/vmdk.c index 20e909d997..631fcd15ab 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -3058,6 +3058,7 @@ static BlockDriver bdrv_vmdk = { .bdrv_get_info = vmdk_get_info, .bdrv_gather_child_options = vmdk_gather_child_options, + .is_format = true, .supports_backing = true, .create_opts = &vmdk_create_opts, }; diff --git a/block/vpc.c b/block/vpc.c index a65550298e..7cf0f87a16 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -1248,6 +1248,7 @@ static BlockDriver bdrv_vpc = { .bdrv_get_info = vpc_get_info, + .is_format = true, .create_opts = &vpc_create_opts, .bdrv_has_zero_init = vpc_has_zero_init, .strong_runtime_opts = vpc_strong_runtime_opts, diff --git a/include/block/block_int.h b/include/block/block_int.h index 6f9fd5e20e..8d10c94213 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -94,6 +94,13 @@ struct BlockDriver { * must implement them and return -ENOTSUP. */ bool is_filter; + /* + * Set to true if the BlockDriver is a format driver. Format nodes + * generally do not expect their children to be other format nodes + * (except for backing files), and so format probing is disabled + * on those children. + */ + bool is_format; /* * Return true if @to_replace can be replaced by a BDS with the * same data as @bs without it affecting @bs's behavior (that is, From patchwork Tue Feb 18 12:42:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388367 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 290281395 for ; Tue, 18 Feb 2020 12:48:14 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D3A7E2173E for ; Tue, 18 Feb 2020 12:48:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Lh3gkBBh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D3A7E2173E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33970 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42IP-000532-28 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:48:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38766) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42DQ-0003ut-CN for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42DM-0000zh-3v for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:04 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:41762 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42DL-0000zT-St for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BDpR5+6Ip8n2y0giAJ9PY9FqSc/f1aGtVVJmfIGJ2bY=; b=Lh3gkBBhUoxOd433XZTizS5JiJlPsV74tMsaKezGVPEAoqX56dQbofymu3nhkYFWy7vrZL tZSC859iVlfepygTyzXCalGa0m/3OFquQfhpPeo3m2va+FYzdcuTRD1Kpz9wu/G2uL0aRM 1zRcrxUs2FRBqpV2LjvCIjN8qrK4Mfw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-305-dShABBJTM_WWP705-gHjgQ-1; Tue, 18 Feb 2020 07:42:54 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 32C09100550E; Tue, 18 Feb 2020 12:42:53 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B522190F6B; Tue, 18 Feb 2020 12:42:51 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 02/33] block: Rename BdrvChildRole to BdrvChildClass Date: Tue, 18 Feb 2020 13:42:11 +0100 Message-Id: <20200218124242.584644-3-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: dShABBJTM_WWP705-gHjgQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This structure nearly only contains parent callbacks for child state changes. It cannot really reflect a child's role, because different roles may overlap (as we will see when real roles are introduced), and because parents can have custom callbacks even when the child fulfills a standard role. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia --- block.c | 142 ++++++++++++++++++------------------ block/backup-top.c | 8 +- block/blkdebug.c | 4 +- block/blklogwrites.c | 8 +- block/block-backend.c | 6 +- block/commit.c | 2 +- block/copy-on-read.c | 2 +- block/io.c | 22 +++--- block/mirror.c | 2 +- block/quorum.c | 2 +- block/replication.c | 2 +- block/vvfat.c | 6 +- blockjob.c | 2 +- include/block/block.h | 6 +- include/block/block_int.h | 22 +++--- tests/test-bdrv-drain.c | 36 ++++----- tests/test-bdrv-graph-mod.c | 2 +- 17 files changed, 141 insertions(+), 133 deletions(-) diff --git a/block.c b/block.c index ca2cfbcb62..a1326e956f 100644 --- a/block.c +++ b/block.c @@ -76,7 +76,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, const char *reference, QDict *options, int flags, BlockDriverState *parent, - const BdrvChildRole *child_role, + const BdrvChildClass *child_class, Error **errp); /* If non-zero, use only whitelisted block drivers */ @@ -1031,7 +1031,7 @@ static void bdrv_inherited_options(int *child_flags, QDict *child_options, *child_flags = flags; } -const BdrvChildRole child_file = { +const BdrvChildClass child_file = { .parent_is_bds = true, .get_parent_desc = bdrv_child_get_parent_desc, .inherit_options = bdrv_inherited_options, @@ -1059,7 +1059,7 @@ static void bdrv_inherited_fmt_options(int *child_flags, QDict *child_options, *child_flags &= ~(BDRV_O_PROTOCOL | BDRV_O_NO_IO); } -const BdrvChildRole child_format = { +const BdrvChildClass child_format = { .parent_is_bds = true, .get_parent_desc = bdrv_child_get_parent_desc, .inherit_options = bdrv_inherited_fmt_options, @@ -1183,7 +1183,7 @@ static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base, return ret; } -const BdrvChildRole child_backing = { +const BdrvChildClass child_backing = { .parent_is_bds = true, .get_parent_desc = bdrv_child_get_parent_desc, .attach = bdrv_backing_attach, @@ -1785,13 +1785,13 @@ bool bdrv_is_writable(BlockDriverState *bs) } static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs, - BdrvChild *c, const BdrvChildRole *role, + BdrvChild *c, const BdrvChildClass *child_class, BlockReopenQueue *reopen_queue, uint64_t parent_perm, uint64_t parent_shared, uint64_t *nperm, uint64_t *nshared) { assert(bs->drv && bs->drv->bdrv_child_perm); - bs->drv->bdrv_child_perm(bs, c, role, reopen_queue, + bs->drv->bdrv_child_perm(bs, c, child_class, reopen_queue, parent_perm, parent_shared, nperm, nshared); /* TODO Take force_share from reopen_queue */ @@ -1885,7 +1885,7 @@ static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q, uint64_t cur_perm, cur_shared; bool child_tighten_restr; - bdrv_child_perm(bs, c->bs, c, c->role, q, + bdrv_child_perm(bs, c->bs, c, c->klass, q, cumulative_perms, cumulative_shared_perms, &cur_perm, &cur_shared); ret = bdrv_child_check_perm(c, q, cur_perm, cur_shared, ignore_children, @@ -1952,7 +1952,7 @@ static void bdrv_set_perm(BlockDriverState *bs, uint64_t cumulative_perms, /* Update all children */ QLIST_FOREACH(c, &bs->children, next) { uint64_t cur_perm, cur_shared; - bdrv_child_perm(bs, c->bs, c, c->role, NULL, + bdrv_child_perm(bs, c->bs, c, c->klass, NULL, cumulative_perms, cumulative_shared_perms, &cur_perm, &cur_shared); bdrv_child_set_perm(c, cur_perm, cur_shared); @@ -1977,8 +1977,8 @@ static void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm, static char *bdrv_child_user_desc(BdrvChild *c) { - if (c->role->get_parent_desc) { - return c->role->get_parent_desc(c); + if (c->klass->get_parent_desc) { + return c->klass->get_parent_desc(c); } return g_strdup("another user"); @@ -2180,14 +2180,14 @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp) uint64_t perms, shared; bdrv_get_cumulative_perm(bs, &parent_perms, &parent_shared); - bdrv_child_perm(bs, c->bs, c, c->role, NULL, parent_perms, parent_shared, + bdrv_child_perm(bs, c->bs, c, c->klass, NULL, parent_perms, parent_shared, &perms, &shared); return bdrv_child_try_set_perm(c, perms, shared, errp); } void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, - const BdrvChildRole *role, + const BdrvChildClass *child_class, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) @@ -2197,21 +2197,21 @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, } void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, - const BdrvChildRole *role, + const BdrvChildClass *child_class, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) { - bool backing = (role == &child_backing); - assert(role == &child_backing || role == &child_file); + bool backing = (child_class == &child_backing); + assert(child_class == &child_backing || child_class == &child_file); if (!backing) { int flags = bdrv_reopen_get_flags(reopen_queue, bs); /* Apart from the modifications below, the same permissions are * forwarded and left alone as for filters */ - bdrv_filter_default_perms(bs, c, role, reopen_queue, perm, shared, - &perm, &shared); + bdrv_filter_default_perms(bs, c, child_class, reopen_queue, + perm, shared, &perm, &shared); /* Format drivers may touch metadata even if the guest doesn't write */ if (bdrv_is_writable_after_reopen(bs, reopen_queue)) { @@ -2288,7 +2288,7 @@ static void bdrv_replace_child_noperm(BdrvChild *child, * If the new child node is drained but the old one was not, flush * all outstanding requests to the old child node. */ - while (drain_saldo > 0 && child->role->drained_begin) { + while (drain_saldo > 0 && child->klass->drained_begin) { bdrv_parent_drained_begin_single(child, true); drain_saldo--; } @@ -2297,8 +2297,8 @@ static void bdrv_replace_child_noperm(BdrvChild *child, /* Detach first so that the recursive drain sections coming from @child * are already gone and we only end the drain sections that came from * elsewhere. */ - if (child->role->detach) { - child->role->detach(child); + if (child->klass->detach) { + child->klass->detach(child); } QLIST_REMOVE(child, next_parent); } @@ -2320,8 +2320,8 @@ static void bdrv_replace_child_noperm(BdrvChild *child, /* Attach only after starting new drained sections, so that recursive * drain sections coming from @child don't get an extra .drained_begin * callback. */ - if (child->role->attach) { - child->role->attach(child); + if (child->klass->attach) { + child->klass->attach(child); } } @@ -2329,7 +2329,7 @@ static void bdrv_replace_child_noperm(BdrvChild *child, * If the old child node was drained but the new one is not, allow * requests to come in only after the new node has been attached. */ - while (drain_saldo < 0 && child->role->drained_end) { + while (drain_saldo < 0 && child->klass->drained_end) { bdrv_parent_drained_end_single(child); drain_saldo++; } @@ -2402,7 +2402,7 @@ static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs) */ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, const char *child_name, - const BdrvChildRole *child_role, + const BdrvChildClass *child_class, AioContext *ctx, uint64_t perm, uint64_t shared_perm, void *opaque, Error **errp) @@ -2423,7 +2423,7 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, *child = (BdrvChild) { .bs = NULL, .name = g_strdup(child_name), - .role = child_role, + .klass = child_class, .perm = perm, .shared_perm = shared_perm, .opaque = opaque, @@ -2434,15 +2434,15 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, * try moving the parent into the AioContext of child_bs instead. */ if (bdrv_get_aio_context(child_bs) != ctx) { ret = bdrv_try_set_aio_context(child_bs, ctx, &local_err); - if (ret < 0 && child_role->can_set_aio_ctx) { + if (ret < 0 && child_class->can_set_aio_ctx) { GSList *ignore = g_slist_prepend(NULL, child);; ctx = bdrv_get_aio_context(child_bs); - if (child_role->can_set_aio_ctx(child, ctx, &ignore, NULL)) { + if (child_class->can_set_aio_ctx(child, ctx, &ignore, NULL)) { error_free(local_err); ret = 0; g_slist_free(ignore); ignore = g_slist_prepend(NULL, child);; - child_role->set_aio_ctx(child, ctx, &ignore); + child_class->set_aio_ctx(child, ctx, &ignore); } g_slist_free(ignore); } @@ -2474,7 +2474,7 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, BlockDriverState *child_bs, const char *child_name, - const BdrvChildRole *child_role, + const BdrvChildClass *child_class, Error **errp) { BdrvChild *child; @@ -2483,10 +2483,10 @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, bdrv_get_cumulative_perm(parent_bs, &perm, &shared_perm); assert(parent_bs->drv); - bdrv_child_perm(parent_bs, child_bs, NULL, child_role, NULL, + bdrv_child_perm(parent_bs, child_bs, NULL, child_class, NULL, perm, shared_perm, &perm, &shared_perm); - child = bdrv_root_attach_child(child_bs, child_name, child_role, + child = bdrv_root_attach_child(child_bs, child_name, child_class, bdrv_get_aio_context(parent_bs), perm, shared_perm, parent_bs, errp); if (child == NULL) { @@ -2562,8 +2562,8 @@ static void bdrv_parent_cb_change_media(BlockDriverState *bs, bool load) { BdrvChild *c; QLIST_FOREACH(c, &bs->parents, next_parent) { - if (c->role->change_media) { - c->role->change_media(c, load); + if (c->klass->change_media) { + c->klass->change_media(c, load); } } } @@ -2739,7 +2739,7 @@ free_exit: static BlockDriverState * bdrv_open_child_bs(const char *filename, QDict *options, const char *bdref_key, - BlockDriverState *parent, const BdrvChildRole *child_role, + BlockDriverState *parent, const BdrvChildClass *child_class, bool allow_none, Error **errp) { BlockDriverState *bs = NULL; @@ -2747,7 +2747,7 @@ bdrv_open_child_bs(const char *filename, QDict *options, const char *bdref_key, char *bdref_key_dot; const char *reference; - assert(child_role != NULL); + assert(child_class != NULL); bdref_key_dot = g_strdup_printf("%s.", bdref_key); qdict_extract_subqdict(options, &image_options, bdref_key_dot); @@ -2771,7 +2771,7 @@ bdrv_open_child_bs(const char *filename, QDict *options, const char *bdref_key, } bs = bdrv_open_inherit(filename, reference, image_options, 0, - parent, child_role, errp); + parent, child_class, errp); if (!bs) { goto done; } @@ -2798,22 +2798,24 @@ done: BdrvChild *bdrv_open_child(const char *filename, QDict *options, const char *bdref_key, BlockDriverState *parent, - const BdrvChildRole *child_role, + const BdrvChildClass *child_class, bool allow_none, Error **errp) { BlockDriverState *bs; - bs = bdrv_open_child_bs(filename, options, bdref_key, parent, child_role, + bs = bdrv_open_child_bs(filename, options, bdref_key, parent, child_class, allow_none, errp); if (bs == NULL) { return NULL; } - return bdrv_attach_child(parent, bs, bdref_key, child_role, errp); + return bdrv_attach_child(parent, bs, bdref_key, child_class, errp); } -/* TODO Future callers may need to specify parent/child_role in order for - * option inheritance to work. Existing callers use it for the root node. */ +/* + * TODO Future callers may need to specify parent/child_class in order for + * option inheritance to work. Existing callers use it for the root node. + */ BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp) { BlockDriverState *bs = NULL; @@ -2948,7 +2950,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, const char *reference, QDict *options, int flags, BlockDriverState *parent, - const BdrvChildRole *child_role, + const BdrvChildClass *child_class, Error **errp) { int ret; @@ -2962,8 +2964,8 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, QDict *snapshot_options = NULL; int snapshot_flags = 0; - assert(!child_role || !flags); - assert(!child_role == !parent); + assert(!child_class || !flags); + assert(!child_class == !parent); if (reference) { bool options_non_empty = options ? qdict_size(options) : false; @@ -2999,10 +3001,10 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, bs->explicit_options = qdict_clone_shallow(options); - if (child_role) { + if (child_class) { bs->inherits_from = parent; - child_role->inherit_options(&flags, options, - parent->open_flags, parent->options); + child_class->inherit_options(&flags, options, + parent->open_flags, parent->options); } ret = bdrv_fill_options(&options, filename, &flags, &local_err); @@ -3313,7 +3315,7 @@ static bool bdrv_recurse_has_child(BlockDriverState *bs, static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, BlockDriverState *bs, QDict *options, - const BdrvChildRole *role, + const BdrvChildClass *klass, QDict *parent_options, int parent_flags, bool keep_old_opts) @@ -3369,7 +3371,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, /* Inherit from parent node */ if (parent_options) { flags = 0; - role->inherit_options(&flags, options, parent_flags, parent_options); + klass->inherit_options(&flags, options, parent_flags, parent_options); } else { flags = bdrv_get_flags(bs); } @@ -3460,7 +3462,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, } bdrv_reopen_queue_child(bs_queue, child->bs, new_child_options, - child->role, options, flags, child_keep_old); + child->klass, options, flags, child_keep_old); } return bs_queue; @@ -3631,7 +3633,7 @@ static void bdrv_reopen_perm(BlockReopenQueue *q, BlockDriverState *bs, } else { uint64_t nperm, nshared; - bdrv_child_perm(parent->state.bs, bs, c, c->role, q, + bdrv_child_perm(parent->state.bs, bs, c, c->klass, q, parent->state.perm, parent->state.shared_perm, &nperm, &nshared); @@ -4117,7 +4119,7 @@ static bool should_update_child(BdrvChild *c, BlockDriverState *to) GHashTable *found; bool ret; - if (c->role->stay_at_node) { + if (c->klass->stay_at_node) { return false; } @@ -4587,9 +4589,9 @@ int bdrv_drop_intermediate(BlockDriverState *top, BlockDriverState *base, } /* If so, update the backing file path in the image file */ - if (c->role->update_filename) { - ret = c->role->update_filename(c, base, backing_file_str, - &local_err); + if (c->klass->update_filename) { + ret = c->klass->update_filename(c, base, backing_file_str, + &local_err); if (ret < 0) { bdrv_abort_perm_update(base); error_report_err(local_err); @@ -5037,8 +5039,8 @@ const char *bdrv_get_parent_name(const BlockDriverState *bs) /* If multiple parents have a name, just pick the first one. */ QLIST_FOREACH(c, &bs->parents, next_parent) { - if (c->role->get_name) { - name = c->role->get_name(c); + if (c->klass->get_name) { + name = c->klass->get_name(c); if (name && *name) { return name; } @@ -5418,8 +5420,8 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, } QLIST_FOREACH(parent, &bs->parents, next_parent) { - if (parent->role->activate) { - parent->role->activate(parent, &local_err); + if (parent->klass->activate) { + parent->klass->activate(parent, &local_err); if (local_err) { bs->open_flags |= BDRV_O_INACTIVE; error_propagate(errp, local_err); @@ -5487,7 +5489,7 @@ static bool bdrv_has_bds_parent(BlockDriverState *bs, bool only_active) BdrvChild *parent; QLIST_FOREACH(parent, &bs->parents, next_parent) { - if (parent->role->parent_is_bds) { + if (parent->klass->parent_is_bds) { BlockDriverState *parent_bs = parent->opaque; if (!only_active || !(parent_bs->open_flags & BDRV_O_INACTIVE)) { return true; @@ -5526,8 +5528,8 @@ static int bdrv_inactivate_recurse(BlockDriverState *bs) } QLIST_FOREACH(parent, &bs->parents, next_parent) { - if (parent->role->inactivate) { - ret = parent->role->inactivate(parent); + if (parent->klass->inactivate) { + ret = parent->klass->inactivate(parent); if (ret < 0) { return ret; } @@ -6027,9 +6029,9 @@ void bdrv_set_aio_context_ignore(BlockDriverState *bs, if (g_slist_find(*ignore, child)) { continue; } - assert(child->role->set_aio_ctx); + assert(child->klass->set_aio_ctx); *ignore = g_slist_prepend(*ignore, child); - child->role->set_aio_ctx(child, new_context, ignore); + child->klass->set_aio_ctx(child, new_context, ignore); } bdrv_detach_aio_context(bs); @@ -6069,15 +6071,17 @@ static bool bdrv_parent_can_set_aio_context(BdrvChild *c, AioContext *ctx, } *ignore = g_slist_prepend(*ignore, c); - /* A BdrvChildRole that doesn't handle AioContext changes cannot - * tolerate any AioContext changes */ - if (!c->role->can_set_aio_ctx) { + /* + * A BdrvChildClass that doesn't handle AioContext changes cannot + * tolerate any AioContext changes + */ + if (!c->klass->can_set_aio_ctx) { char *user = bdrv_child_user_desc(c); error_setg(errp, "Changing iothreads is not supported by %s", user); g_free(user); return false; } - if (!c->role->can_set_aio_ctx(c, ctx, ignore, errp)) { + if (!c->klass->can_set_aio_ctx(c, ctx, ignore, errp)) { assert(!errp || *errp); return false; } @@ -6463,7 +6467,7 @@ void bdrv_refresh_filename(BlockDriverState *bs) drv->bdrv_gather_child_options(bs, opts, backing_overridden); } else { QLIST_FOREACH(child, &bs->children, next) { - if (child->role == &child_backing && !backing_overridden) { + if (child->klass == &child_backing && !backing_overridden) { /* We can skip the backing BDS if it has not been overridden */ continue; } diff --git a/block/backup-top.c b/block/backup-top.c index 1bfb360bd3..2d232828ff 100644 --- a/block/backup-top.c +++ b/block/backup-top.c @@ -121,7 +121,7 @@ static void backup_top_refresh_filename(BlockDriverState *bs) } static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildRole *role, + const BdrvChildClass *child_class, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) @@ -141,7 +141,7 @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, return; } - if (role == &child_file) { + if (child_class == &child_file) { /* * Target child * @@ -152,8 +152,8 @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, *nperm = BLK_PERM_WRITE; } else { /* Source child */ - bdrv_filter_default_perms(bs, c, role, reopen_queue, perm, shared, - nperm, nshared); + bdrv_filter_default_perms(bs, c, child_class, reopen_queue, + perm, shared, nperm, nshared); if (perm & BLK_PERM_WRITE) { *nperm = *nperm | BLK_PERM_CONSISTENT_READ; diff --git a/block/blkdebug.c b/block/blkdebug.c index af44aa973f..f369d54ee4 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -993,14 +993,14 @@ static int blkdebug_reopen_prepare(BDRVReopenState *reopen_state, } static void blkdebug_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildRole *role, + const BdrvChildClass *child_class, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) { BDRVBlkdebugState *s = bs->opaque; - bdrv_filter_default_perms(bs, c, role, reopen_queue, perm, shared, + bdrv_filter_default_perms(bs, c, child_class, reopen_queue, perm, shared, nperm, nshared); *nperm |= s->take_child_perms; diff --git a/block/blklogwrites.c b/block/blklogwrites.c index 04d8b33607..f3b3259d8d 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -282,7 +282,7 @@ static int64_t blk_log_writes_getlength(BlockDriverState *bs) } static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildRole *role, + const BdrvChildClass *child_class, BlockReopenQueue *ro_q, uint64_t perm, uint64_t shrd, uint64_t *nperm, uint64_t *nshrd) @@ -294,9 +294,11 @@ static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, } if (!strcmp(c->name, "log")) { - bdrv_format_default_perms(bs, c, role, ro_q, perm, shrd, nperm, nshrd); + bdrv_format_default_perms(bs, c, child_class, ro_q, perm, shrd, nperm, + nshrd); } else { - bdrv_filter_default_perms(bs, c, role, ro_q, perm, shrd, nperm, nshrd); + bdrv_filter_default_perms(bs, c, child_class, ro_q, perm, shrd, nperm, + nshrd); } } diff --git a/block/block-backend.c b/block/block-backend.c index 8b8f2a80a0..3d7e96e0d4 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -297,7 +297,7 @@ static void blk_root_detach(BdrvChild *child) } } -static const BdrvChildRole child_root = { +static const BdrvChildClass child_root = { .inherit_options = blk_root_inherit_options, .change_media = blk_root_change_media, @@ -693,7 +693,7 @@ static BlockBackend *bdrv_first_blk(BlockDriverState *bs) { BdrvChild *child; QLIST_FOREACH(child, &bs->parents, next_parent) { - if (child->role == &child_root) { + if (child->klass == &child_root) { return child->opaque; } } @@ -717,7 +717,7 @@ bool bdrv_is_root_node(BlockDriverState *bs) BdrvChild *c; QLIST_FOREACH(c, &bs->parents, next_parent) { - if (c->role != &child_root) { + if (c->klass != &child_root) { return false; } } diff --git a/block/commit.c b/block/commit.c index 8e672799af..a712662633 100644 --- a/block/commit.c +++ b/block/commit.c @@ -223,7 +223,7 @@ static void bdrv_commit_top_refresh_filename(BlockDriverState *bs) } static void bdrv_commit_top_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildRole *role, + const BdrvChildClass *child_class, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 242d3ff055..7504ca6ffc 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -51,7 +51,7 @@ static int cor_open(BlockDriverState *bs, QDict *options, int flags, #define PERM_UNCHANGED (BLK_PERM_ALL & ~PERM_PASSTHROUGH) static void cor_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildRole *role, + const BdrvChildClass *child_class, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) diff --git a/block/io.c b/block/io.c index 7e4cb74cf4..b41f2bd227 100644 --- a/block/io.c +++ b/block/io.c @@ -50,7 +50,7 @@ static void bdrv_parent_drained_begin(BlockDriverState *bs, BdrvChild *ignore, BdrvChild *c, *next; QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) { - if (c == ignore || (ignore_bds_parents && c->role->parent_is_bds)) { + if (c == ignore || (ignore_bds_parents && c->klass->parent_is_bds)) { continue; } bdrv_parent_drained_begin_single(c, false); @@ -62,8 +62,8 @@ static void bdrv_parent_drained_end_single_no_poll(BdrvChild *c, { assert(c->parent_quiesce_counter > 0); c->parent_quiesce_counter--; - if (c->role->drained_end) { - c->role->drained_end(c, drained_end_counter); + if (c->klass->drained_end) { + c->klass->drained_end(c, drained_end_counter); } } @@ -81,7 +81,7 @@ static void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore, BdrvChild *c; QLIST_FOREACH(c, &bs->parents, next_parent) { - if (c == ignore || (ignore_bds_parents && c->role->parent_is_bds)) { + if (c == ignore || (ignore_bds_parents && c->klass->parent_is_bds)) { continue; } bdrv_parent_drained_end_single_no_poll(c, drained_end_counter); @@ -90,8 +90,8 @@ static void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore, static bool bdrv_parent_drained_poll_single(BdrvChild *c) { - if (c->role->drained_poll) { - return c->role->drained_poll(c); + if (c->klass->drained_poll) { + return c->klass->drained_poll(c); } return false; } @@ -103,7 +103,7 @@ static bool bdrv_parent_drained_poll(BlockDriverState *bs, BdrvChild *ignore, bool busy = false; QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) { - if (c == ignore || (ignore_bds_parents && c->role->parent_is_bds)) { + if (c == ignore || (ignore_bds_parents && c->klass->parent_is_bds)) { continue; } busy |= bdrv_parent_drained_poll_single(c); @@ -115,8 +115,8 @@ static bool bdrv_parent_drained_poll(BlockDriverState *bs, BdrvChild *ignore, void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll) { c->parent_quiesce_counter++; - if (c->role->drained_begin) { - c->role->drained_begin(c); + if (c->klass->drained_begin) { + c->klass->drained_begin(c); } if (poll) { BDRV_POLL_WHILE(c->bs, bdrv_parent_drained_poll_single(c)); @@ -3325,8 +3325,8 @@ static void bdrv_parent_cb_resize(BlockDriverState *bs) { BdrvChild *c; QLIST_FOREACH(c, &bs->parents, next_parent) { - if (c->role->resize) { - c->role->resize(c); + if (c->klass->resize) { + c->klass->resize(c); } } } diff --git a/block/mirror.c b/block/mirror.c index 447051dbc6..d8506af45a 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1484,7 +1484,7 @@ static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs) } static void bdrv_mirror_top_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildRole *role, + const BdrvChildClass *child_class, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) diff --git a/block/quorum.c b/block/quorum.c index 6d7a56bd93..a0824c300d 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1151,7 +1151,7 @@ static char *quorum_dirname(BlockDriverState *bs, Error **errp) } static void quorum_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildRole *role, + const BdrvChildClass *child_class, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) diff --git a/block/replication.c b/block/replication.c index d6681b6c84..e268a6e5c5 100644 --- a/block/replication.c +++ b/block/replication.c @@ -160,7 +160,7 @@ static void replication_close(BlockDriverState *bs) } static void replication_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildRole *role, + const BdrvChildClass *child_class, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) diff --git a/block/vvfat.c b/block/vvfat.c index ab800c4887..d41bdfc934 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3138,7 +3138,7 @@ static void vvfat_qcow_options(int *child_flags, QDict *child_options, qdict_set_default_str(child_options, BDRV_OPT_CACHE_NO_FLUSH, "on"); } -static const BdrvChildRole child_vvfat_qcow = { +static const BdrvChildClass child_vvfat_qcow = { .parent_is_bds = true, .inherit_options = vvfat_qcow_options, }; @@ -3212,14 +3212,14 @@ err: } static void vvfat_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildRole *role, + const BdrvChildClass *child_class, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) { BDRVVVFATState *s = bs->opaque; - assert(c == s->qcow || role == &child_backing); + assert(c == s->qcow || child_class == &child_backing); if (c == s->qcow) { /* This is a private node, nobody should try to attach to it */ diff --git a/blockjob.c b/blockjob.c index 5d63b1e89d..79f303822b 100644 --- a/blockjob.c +++ b/blockjob.c @@ -163,7 +163,7 @@ static void child_job_set_aio_ctx(BdrvChild *c, AioContext *ctx, job->job.aio_context = ctx; } -static const BdrvChildRole child_job = { +static const BdrvChildClass child_job = { .get_parent_desc = child_job_get_parent_desc, .drained_begin = child_job_drained_begin, .drained_poll = child_job_drained_poll, diff --git a/include/block/block.h b/include/block/block.h index cd6b5b95aa..fd89eb6c75 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -13,7 +13,7 @@ /* block.c */ typedef struct BlockDriver BlockDriver; typedef struct BdrvChild BdrvChild; -typedef struct BdrvChildRole BdrvChildRole; +typedef struct BdrvChildClass BdrvChildClass; typedef struct BlockDriverInfo { /* in bytes, 0 if irrelevant */ @@ -295,7 +295,7 @@ int bdrv_parse_discard_flags(const char *mode, int *flags); BdrvChild *bdrv_open_child(const char *filename, QDict *options, const char *bdref_key, BlockDriverState* parent, - const BdrvChildRole *child_role, + const BdrvChildClass *child_class, bool allow_none, Error **errp); BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp); void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, @@ -538,7 +538,7 @@ void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child); BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, BlockDriverState *child_bs, const char *child_name, - const BdrvChildRole *child_role, + const BdrvChildClass *child_class, Error **errp); bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp); diff --git a/include/block/block_int.h b/include/block/block_int.h index 8d10c94213..5d54debc34 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -556,14 +556,14 @@ struct BlockDriver { * the parents in @parent_perm and @parent_shared. * * If @c is NULL, return the permissions for attaching a new child for the - * given @role. + * given @child_class. * * If @reopen_queue is non-NULL, don't return the currently needed * permissions, but those that will be needed after applying the * @reopen_queue. */ void (*bdrv_child_perm)(BlockDriverState *bs, BdrvChild *c, - const BdrvChildRole *role, + const BdrvChildClass *child_class, BlockReopenQueue *reopen_queue, uint64_t parent_perm, uint64_t parent_shared, uint64_t *nperm, uint64_t *nshared); @@ -665,7 +665,7 @@ typedef struct BdrvAioNotifier { QLIST_ENTRY(BdrvAioNotifier) list; } BdrvAioNotifier; -struct BdrvChildRole { +struct BdrvChildClass { /* If true, bdrv_replace_node() doesn't change the node this BdrvChild * points to. */ bool stay_at_node; @@ -738,14 +738,14 @@ struct BdrvChildRole { void (*set_aio_ctx)(BdrvChild *child, AioContext *ctx, GSList **ignore); }; -extern const BdrvChildRole child_file; -extern const BdrvChildRole child_format; -extern const BdrvChildRole child_backing; +extern const BdrvChildClass child_file; +extern const BdrvChildClass child_format; +extern const BdrvChildClass child_backing; struct BdrvChild { BlockDriverState *bs; char *name; - const BdrvChildRole *role; + const BdrvChildClass *klass; void *opaque; /** @@ -772,7 +772,7 @@ struct BdrvChild { /* * How many times the parent of this child has been drained - * (through role->drained_*). + * (through klass->drained_*). * Usually, this is equal to bs->quiesce_counter (potentially * reduced by bdrv_drain_all_count). It may differ while the * child is entering or leaving a drained section. @@ -1226,7 +1226,7 @@ void hmp_drive_add_node(Monitor *mon, const char *optstr); BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, const char *child_name, - const BdrvChildRole *child_role, + const BdrvChildClass *child_class, AioContext *ctx, uint64_t perm, uint64_t shared_perm, void *opaque, Error **errp); @@ -1254,7 +1254,7 @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp); * block filters: Forward CONSISTENT_READ, WRITE, WRITE_UNCHANGED and RESIZE to * all children */ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, - const BdrvChildRole *role, + const BdrvChildClass *child_class, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared); @@ -1264,7 +1264,7 @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, * 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, + const BdrvChildClass *child_class, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared); diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index fa0e6a648b..9d683a6c11 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -86,18 +86,20 @@ static int coroutine_fn bdrv_test_co_preadv(BlockDriverState *bs, } static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildRole *role, + const BdrvChildClass *child_class, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) { - /* bdrv_format_default_perms() accepts only these two, so disguise - * detach_by_driver_cb_role as one of them. */ - if (role != &child_file && role != &child_backing) { - role = &child_file; + /* + * bdrv_format_default_perms() accepts only these two, so disguise + * detach_by_driver_cb_parent as one of them. + */ + if (child_class != &child_file && child_class != &child_backing) { + child_class = &child_file; } - bdrv_format_default_perms(bs, c, role, reopen_queue, perm, shared, + bdrv_format_default_perms(bs, c, child_class, reopen_queue, perm, shared, nperm, nshared); } @@ -1332,7 +1334,7 @@ static void detach_by_driver_cb_drained_begin(BdrvChild *child) child_file.drained_begin(child); } -static BdrvChildRole detach_by_driver_cb_role; +static BdrvChildClass detach_by_driver_cb_class; /* * Initial graph: @@ -1349,7 +1351,7 @@ static BdrvChildRole detach_by_driver_cb_role; * * by_parent_cb == false: Test that bdrv_drain_invoke() doesn't poll * - * PA's BdrvChildRole has a .drained_begin callback that schedules a BH + * PA's BdrvChildClass has a .drained_begin callback that schedules a BH * that does the same graph change. If bdrv_drain_invoke() calls it, the * state is messed up, but if it is only polled in the single * BDRV_POLL_WHILE() at the end of the drain, this should work fine. @@ -1364,8 +1366,8 @@ static void test_detach_indirect(bool by_parent_cb) QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, NULL, 0); if (!by_parent_cb) { - detach_by_driver_cb_role = child_file; - detach_by_driver_cb_role.drained_begin = + detach_by_driver_cb_class = child_file; + detach_by_driver_cb_class.drained_begin = detach_by_driver_cb_drained_begin; } @@ -1399,7 +1401,7 @@ static void test_detach_indirect(bool by_parent_cb) bdrv_ref(a); bdrv_attach_child(parent_a, a, "PA-A", - by_parent_cb ? &child_file : &detach_by_driver_cb_role, + by_parent_cb ? &child_file : &detach_by_driver_cb_class, &error_abort); g_assert_cmpint(parent_a->refcnt, ==, 1); @@ -1735,7 +1737,7 @@ static int drop_intermediate_poll_update_filename(BdrvChild *child, /** * Test a poll in the midst of bdrv_drop_intermediate(). * - * bdrv_drop_intermediate() calls BdrvChildRole.update_filename(), + * bdrv_drop_intermediate() calls BdrvChildClass.update_filename(), * which can yield or poll. This may lead to graph changes, unless * the whole subtree in question is drained. * @@ -1772,7 +1774,7 @@ static int drop_intermediate_poll_update_filename(BdrvChild *child, * * The solution is for bdrv_drop_intermediate() to drain top's * subtree. This prevents graph changes from happening just because - * BdrvChildRole.update_filename() yields or polls. Thus, the block + * BdrvChildClass.update_filename() yields or polls. Thus, the block * job is paused during that drained section and must finish before or * after. * @@ -1780,7 +1782,7 @@ static int drop_intermediate_poll_update_filename(BdrvChild *child, */ static void test_drop_intermediate_poll(void) { - static BdrvChildRole chain_child_role; + static BdrvChildClass chain_child_class; BlockDriverState *chain[3]; TestSimpleBlockJob *job; BlockDriverState *job_node; @@ -1788,8 +1790,8 @@ static void test_drop_intermediate_poll(void) int i; int ret; - chain_child_role = child_backing; - chain_child_role.update_filename = drop_intermediate_poll_update_filename; + chain_child_class = child_backing; + chain_child_class.update_filename = drop_intermediate_poll_update_filename; for (i = 0; i < 3; i++) { char name[32]; @@ -1810,7 +1812,7 @@ static void test_drop_intermediate_poll(void) if (i) { /* Takes the reference to chain[i - 1] */ chain[i]->backing = bdrv_attach_child(chain[i], chain[i - 1], - "chain", &chain_child_role, + "chain", &chain_child_class, &error_abort); } } diff --git a/tests/test-bdrv-graph-mod.c b/tests/test-bdrv-graph-mod.c index a007754d9e..fef42cb294 100644 --- a/tests/test-bdrv-graph-mod.c +++ b/tests/test-bdrv-graph-mod.c @@ -30,7 +30,7 @@ static BlockDriver bdrv_pass_through = { }; static void no_perm_default_perms(BlockDriverState *bs, BdrvChild *c, - const BdrvChildRole *role, + const BdrvChildClass *child_class, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) From patchwork Tue Feb 18 12:42:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388351 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B660E139A for ; Tue, 18 Feb 2020 12:43:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E1B82173E for ; Tue, 18 Feb 2020 12:43:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="W3oRPKJG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E1B82173E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42E8-0005dP-MG for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:43:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38714) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42DM-0003qC-BP for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42DL-0000zH-6D for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:00 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:46856 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42DL-0000yt-2f for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:42:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029778; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eGOeRG4Lx+pTp0i14plka3WDezKrZb39267MP8MsP8c=; b=W3oRPKJG0x+r3YDL5lqmGd7irl9lwILZ9jsm9uNwyKhQUS+FgkisrZlsawT97QHNWkubSa tLco7R1N4FrNtJJ8hppQgKeAswFM++F0FTdu3JBF/v4ffUI/CpmqXsY/gb72Sx6rzSXitD yxiW7Y16+r/RNuz75Uv47K3QIc8fzjw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-194-LbrfguFlOG2CaDugLou4VA-1; Tue, 18 Feb 2020 07:42:56 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C043B100550E; Tue, 18 Feb 2020 12:42:55 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D44560C80; Tue, 18 Feb 2020 12:42:55 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 03/33] block: Add BdrvChildRole and BdrvChildRoleBits Date: Tue, 18 Feb 2020 13:42:12 +0100 Message-Id: <20200218124242.584644-4-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: LbrfguFlOG2CaDugLou4VA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This mask will supplement BdrvChildClass when it comes to what role (or combination of roles) a child takes for its parent. It consists of BdrvChildRoleBits values (which is an enum). Because empty enums are not allowed, let us just start with it filled. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- include/block/block.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/include/block/block.h b/include/block/block.h index fd89eb6c75..8c23948d08 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -268,6 +268,44 @@ enum { DEFAULT_PERM_UNCHANGED = BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH, }; +enum BdrvChildRoleBits { + /* Child stores data */ + BDRV_CHILD_DATA = (1 << 0), + + /* Child stores metadata */ + BDRV_CHILD_METADATA = (1 << 1), + + /* + * A child to which the parent forwards all reads and writes. It + * must present exactly the same visible data as the parent. + * Any node may have at most one filtered child at a time. + */ + BDRV_CHILD_FILTERED = (1 << 2), + + /* + * Child from which to read all data that isn’t allocated in the + * parent (i.e., the backing child); such data is copied to the + * parent through COW (and optionally COR). + */ + BDRV_CHILD_COW = (1 << 3), + + /* + * The primary child. For most drivers, this is the child whose + * filename applies best to the parent node. + * Each parent must give this flag to no more than one child at a + * time. + */ + BDRV_CHILD_PRIMARY = (1 << 4), + + /* Useful combination of flags */ + BDRV_CHILD_IMAGE = BDRV_CHILD_DATA + | BDRV_CHILD_METADATA + | BDRV_CHILD_PRIMARY, +}; + +/* Mask of BdrvChildRoleBits values */ +typedef unsigned int BdrvChildRole; + char *bdrv_perm_names(uint64_t perm); uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission qapi_perm); From patchwork Tue Feb 18 12:42:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388359 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1292A139A for ; Tue, 18 Feb 2020 12:45:35 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CCA6D2173E for ; Tue, 18 Feb 2020 12:45:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IWBawlR5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CCA6D2173E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Fp-0000yf-Ud for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:45:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38795) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42DS-0003wc-VH for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42DO-00011N-Po for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:06 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:35058 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42DO-000111-Jx for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029782; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d48hMt81I5BpLdaIdwfPKTOORYuZKDWKmKsV+cQeX2I=; b=IWBawlR5NUBhcMNXT50MuLEdXXW46U38J/BjLmBnLMVBifEtqdZ+dOw5XaQSOYv4+jcX9l iwmZgjc7kdT8rnKRuEFakWesrq6JbqFlZn1hDurrzsUBguDdCPADTvGVgG0nZ5Iic3Zcp6 yaguJD6PQ9blT2IeB3Oz/QQiQAGE8zM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-357-1XlkG_cCPCGTcOrze8dSAw-1; Tue, 18 Feb 2020 07:43:00 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 65FF513E4; Tue, 18 Feb 2020 12:42:59 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5DA40390; Tue, 18 Feb 2020 12:42:58 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 04/33] block: Add BdrvChildRole to BdrvChild Date: Tue, 18 Feb 2020 13:42:13 +0100 Message-Id: <20200218124242.584644-5-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: 1XlkG_cCPCGTcOrze8dSAw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" For now, it is always set to 0. Later patches in this series will ensure that all callers pass an appropriate combination of flags. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 11 ++++++++--- block/backup-top.c | 3 ++- block/blkdebug.c | 2 +- block/blklogwrites.c | 6 +++--- block/blkreplay.c | 2 +- block/blkverify.c | 4 ++-- block/block-backend.c | 4 ++-- block/bochs.c | 2 +- block/cloop.c | 2 +- block/copy-on-read.c | 2 +- block/crypto.c | 2 +- block/dmg.c | 2 +- block/filter-compress.c | 2 +- block/parallels.c | 2 +- block/qcow.c | 2 +- block/qcow2.c | 6 +++--- block/qed.c | 2 +- block/quorum.c | 4 ++-- block/raw-format.c | 2 +- block/replication.c | 2 +- block/throttle.c | 2 +- block/vdi.c | 2 +- block/vhdx.c | 2 +- block/vmdk.c | 4 ++-- block/vpc.c | 2 +- block/vvfat.c | 2 +- blockjob.c | 5 +++-- include/block/block.h | 2 ++ include/block/block_int.h | 2 ++ tests/test-bdrv-drain.c | 20 +++++++++++--------- tests/test-bdrv-graph-mod.c | 4 ++-- 31 files changed, 62 insertions(+), 49 deletions(-) diff --git a/block.c b/block.c index a1326e956f..e8ddf1689e 100644 --- a/block.c +++ b/block.c @@ -2403,6 +2403,7 @@ static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs) BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, const char *child_name, const BdrvChildClass *child_class, + BdrvChildRole child_role, AioContext *ctx, uint64_t perm, uint64_t shared_perm, void *opaque, Error **errp) @@ -2424,6 +2425,7 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, .bs = NULL, .name = g_strdup(child_name), .klass = child_class, + .role = child_role, .perm = perm, .shared_perm = shared_perm, .opaque = opaque, @@ -2475,6 +2477,7 @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, BlockDriverState *child_bs, const char *child_name, const BdrvChildClass *child_class, + BdrvChildRole child_role, Error **errp) { BdrvChild *child; @@ -2487,7 +2490,7 @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, perm, shared_perm, &perm, &shared_perm); child = bdrv_root_attach_child(child_bs, child_name, child_class, - bdrv_get_aio_context(parent_bs), + child_role, bdrv_get_aio_context(parent_bs), perm, shared_perm, parent_bs, errp); if (child == NULL) { return NULL; @@ -2608,7 +2611,7 @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, } bs->backing = bdrv_attach_child(bs, backing_hd, "backing", &child_backing, - errp); + 0, errp); /* If backing_hd was already part of bs's backing chain, and * inherits_from pointed recursively to bs then let's update it to * point directly to bs (else it will become NULL). */ @@ -2799,6 +2802,7 @@ BdrvChild *bdrv_open_child(const char *filename, QDict *options, const char *bdref_key, BlockDriverState *parent, const BdrvChildClass *child_class, + BdrvChildRole child_role, bool allow_none, Error **errp) { BlockDriverState *bs; @@ -2809,7 +2813,8 @@ BdrvChild *bdrv_open_child(const char *filename, return NULL; } - return bdrv_attach_child(parent, bs, bdref_key, child_class, errp); + return bdrv_attach_child(parent, bs, bdref_key, child_class, child_role, + errp); } /* diff --git a/block/backup-top.c b/block/backup-top.c index 2d232828ff..b13d459e86 100644 --- a/block/backup-top.c +++ b/block/backup-top.c @@ -209,7 +209,8 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source, source->supported_zero_flags); bdrv_ref(target); - state->target = bdrv_attach_child(top, target, "target", &child_file, errp); + state->target = bdrv_attach_child(top, target, "target", &child_file, 0, + errp); if (!state->target) { bdrv_unref(target); bdrv_unref(top); diff --git a/block/blkdebug.c b/block/blkdebug.c index f369d54ee4..c91e78d5c8 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -497,7 +497,7 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags, /* Open the image file */ bs->file = bdrv_open_child(qemu_opt_get(opts, "x-image"), options, "image", - bs, &child_file, false, &local_err); + bs, &child_file, 0, false, &local_err); if (local_err) { ret = -EINVAL; error_propagate(errp, local_err); diff --git a/block/blklogwrites.c b/block/blklogwrites.c index f3b3259d8d..739db6dcf6 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -157,7 +157,7 @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags, } /* Open the file */ - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, false, + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, &local_err); if (local_err) { ret = -EINVAL; @@ -166,8 +166,8 @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags, } /* Open the log file */ - s->log_file = bdrv_open_child(NULL, options, "log", bs, &child_file, false, - &local_err); + s->log_file = bdrv_open_child(NULL, options, "log", bs, &child_file, 0, + false, &local_err); if (local_err) { ret = -EINVAL; error_propagate(errp, local_err); diff --git a/block/blkreplay.c b/block/blkreplay.c index c96ac8f4bc..f97493f45a 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -28,7 +28,7 @@ static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags, /* Open the image file */ bs->file = bdrv_open_child(NULL, options, "image", - bs, &child_file, false, &local_err); + bs, &child_file, 0, false, &local_err); if (local_err) { ret = -EINVAL; error_propagate(errp, local_err); diff --git a/block/blkverify.c b/block/blkverify.c index ba6b1853ae..ba4f6d7b7c 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -125,7 +125,7 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags, /* Open the raw file */ bs->file = bdrv_open_child(qemu_opt_get(opts, "x-raw"), options, "raw", - bs, &child_file, false, &local_err); + bs, &child_file, 0, false, &local_err); if (local_err) { ret = -EINVAL; error_propagate(errp, local_err); @@ -134,7 +134,7 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags, /* Open the test file */ s->test_file = bdrv_open_child(qemu_opt_get(opts, "x-image"), options, - "test", bs, &child_format, false, + "test", bs, &child_format, 0, false, &local_err); if (local_err) { ret = -EINVAL; diff --git a/block/block-backend.c b/block/block-backend.c index 3d7e96e0d4..4b79b2abb1 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -400,7 +400,7 @@ BlockBackend *blk_new_open(const char *filename, const char *reference, return NULL; } - blk->root = bdrv_root_attach_child(bs, "root", &child_root, blk->ctx, + blk->root = bdrv_root_attach_child(bs, "root", &child_root, 0, blk->ctx, perm, BLK_PERM_ALL, blk, errp); if (!blk->root) { blk_unref(blk); @@ -811,7 +811,7 @@ int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp) { ThrottleGroupMember *tgm = &blk->public.throttle_group_member; bdrv_ref(bs); - blk->root = bdrv_root_attach_child(bs, "root", &child_root, blk->ctx, + blk->root = bdrv_root_attach_child(bs, "root", &child_root, 0, blk->ctx, blk->perm, blk->shared_perm, blk, errp); if (blk->root == NULL) { return -EPERM; diff --git a/block/bochs.c b/block/bochs.c index e7bbeaa1c4..b013e73063 100644 --- a/block/bochs.c +++ b/block/bochs.c @@ -110,7 +110,7 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags, return ret; } - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, errp); if (!bs->file) { return -EINVAL; diff --git a/block/cloop.c b/block/cloop.c index f90f1a4b4c..3ed9fa63cc 100644 --- a/block/cloop.c +++ b/block/cloop.c @@ -71,7 +71,7 @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags, return ret; } - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, errp); if (!bs->file) { return -EINVAL; diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 7504ca6ffc..a2c4e6dc58 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -28,7 +28,7 @@ static int cor_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, false, + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, errp); if (!bs->file) { return -EINVAL; diff --git a/block/crypto.c b/block/crypto.c index b81f673a51..4da74a7737 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -200,7 +200,7 @@ static int block_crypto_open_generic(QCryptoBlockFormat format, unsigned int cflags = 0; QDict *cryptoopts = NULL; - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, errp); if (!bs->file) { return -EINVAL; diff --git a/block/dmg.c b/block/dmg.c index ef3c6e771d..af8188638c 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -439,7 +439,7 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, return ret; } - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, errp); if (!bs->file) { return -EINVAL; diff --git a/block/filter-compress.c b/block/filter-compress.c index 82c315b298..4dc5f9fb8c 100644 --- a/block/filter-compress.c +++ b/block/filter-compress.c @@ -30,7 +30,7 @@ static int compress_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, false, + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, errp); if (!bs->file) { return -EINVAL; diff --git a/block/parallels.c b/block/parallels.c index 30eda982bd..3d5b3b7c63 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -728,7 +728,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, Error *local_err = NULL; char *buf; - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, errp); if (!bs->file) { return -EINVAL; diff --git a/block/qcow.c b/block/qcow.c index 0e4f09934c..2bf8e8eb36 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -130,7 +130,7 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags, qdict_extract_subqdict(options, &encryptopts, "encrypt."); encryptfmt = qdict_get_try_str(encryptopts, "format"); - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, errp); if (!bs->file) { ret = -EINVAL; diff --git a/block/qcow2.c b/block/qcow2.c index 875eb7d5d9..2ce974df4d 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1538,7 +1538,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, /* Open external data file */ s->data_file = bdrv_open_child(NULL, options, "data-file", bs, &child_file, - true, &local_err); + 0, true, &local_err); if (local_err) { error_propagate(errp, local_err); ret = -EINVAL; @@ -1548,7 +1548,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, if (s->incompatible_features & QCOW2_INCOMPAT_DATA_FILE) { if (!s->data_file && s->image_data_file) { s->data_file = bdrv_open_child(s->image_data_file, options, - "data-file", bs, &child_file, + "data-file", bs, &child_file, 0, false, errp); if (!s->data_file) { ret = -EINVAL; @@ -1808,7 +1808,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, .ret = -EINPROGRESS }; - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, errp); if (!bs->file) { return -EINVAL; diff --git a/block/qed.c b/block/qed.c index eb6139acbc..d15ba11959 100644 --- a/block/qed.c +++ b/block/qed.c @@ -547,7 +547,7 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags, .ret = -EINPROGRESS }; - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, errp); if (!bs->file) { return -EINVAL; diff --git a/block/quorum.c b/block/quorum.c index a0824c300d..024de76e6f 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -977,7 +977,7 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, assert(ret < 32); s->children[i] = bdrv_open_child(NULL, options, indexstr, bs, - &child_format, false, &local_err); + &child_format, 0, false, &local_err); if (local_err) { ret = -EINVAL; goto close_exit; @@ -1053,7 +1053,7 @@ static void quorum_add_child(BlockDriverState *bs, BlockDriverState *child_bs, /* We can safely add the child now */ bdrv_ref(child_bs); - child = bdrv_attach_child(bs, child_bs, indexstr, &child_format, errp); + child = bdrv_attach_child(bs, child_bs, indexstr, &child_format, 0, errp); if (child == NULL) { s->next_child_index--; goto out; diff --git a/block/raw-format.c b/block/raw-format.c index 2429ff0d23..b600dae209 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -431,7 +431,7 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, BDRVRawState *s = bs->opaque; int ret; - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, errp); if (!bs->file) { return -EINVAL; diff --git a/block/replication.c b/block/replication.c index e268a6e5c5..c05df1bc16 100644 --- a/block/replication.c +++ b/block/replication.c @@ -90,7 +90,7 @@ static int replication_open(BlockDriverState *bs, QDict *options, const char *mode; const char *top_id; - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, errp); if (!bs->file) { return -EINVAL; diff --git a/block/throttle.c b/block/throttle.c index 71f4bb0ad1..2dea913be7 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -82,7 +82,7 @@ static int throttle_open(BlockDriverState *bs, QDict *options, int ret; bs->file = bdrv_open_child(NULL, options, "file", bs, - &child_file, false, errp); + &child_file, 0, false, errp); if (!bs->file) { return -EINVAL; } diff --git a/block/vdi.c b/block/vdi.c index 7e87b205b5..987e2ed592 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -378,7 +378,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, Error *local_err = NULL; QemuUUID uuid_link, uuid_parent; - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, errp); if (!bs->file) { return -EINVAL; diff --git a/block/vhdx.c b/block/vhdx.c index d3c1619026..be23290ac8 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -997,7 +997,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags, uint64_t signature; Error *local_err = NULL; - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, errp); if (!bs->file) { return -EINVAL; diff --git a/block/vmdk.c b/block/vmdk.c index 631fcd15ab..84f99d881f 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1152,7 +1152,7 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, assert(ret < 32); extent_file = bdrv_open_child(extent_path, options, extent_opt_prefix, - bs, &child_file, false, &local_err); + bs, &child_file, 0, false, &local_err); g_free(extent_path); if (local_err) { error_propagate(errp, local_err); @@ -1257,7 +1257,7 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags, uint32_t magic; Error *local_err = NULL; - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, errp); if (!bs->file) { return -EINVAL; diff --git a/block/vpc.c b/block/vpc.c index 7cf0f87a16..5378e32d1d 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -228,7 +228,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, int ret; int64_t bs_size; - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, errp); if (!bs->file) { return -EINVAL; diff --git a/block/vvfat.c b/block/vvfat.c index d41bdfc934..022462d9c9 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3185,7 +3185,7 @@ static int enable_write_target(BlockDriverState *bs, Error **errp) options = qdict_new(); qdict_put_str(options, "write-target.driver", "qcow"); s->qcow = bdrv_open_child(s->qcow_filename, options, "write-target", bs, - &child_vvfat_qcow, false, errp); + &child_vvfat_qcow, 0, false, errp); qobject_unref(options); if (!s->qcow) { ret = -EINVAL; diff --git a/blockjob.c b/blockjob.c index 79f303822b..533ef0af30 100644 --- a/blockjob.c +++ b/blockjob.c @@ -217,8 +217,9 @@ int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs, if (job->job.aio_context != qemu_get_aio_context()) { aio_context_release(job->job.aio_context); } - c = bdrv_root_attach_child(bs, name, &child_job, job->job.aio_context, - perm, shared_perm, job, errp); + c = bdrv_root_attach_child(bs, name, &child_job, 0, + job->job.aio_context, perm, shared_perm, job, + errp); if (job->job.aio_context != qemu_get_aio_context()) { aio_context_acquire(job->job.aio_context); } diff --git a/include/block/block.h b/include/block/block.h index 8c23948d08..01832ec79b 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -334,6 +334,7 @@ BdrvChild *bdrv_open_child(const char *filename, QDict *options, const char *bdref_key, BlockDriverState* parent, const BdrvChildClass *child_class, + BdrvChildRole child_role, bool allow_none, Error **errp); BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp); void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, @@ -577,6 +578,7 @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, BlockDriverState *child_bs, const char *child_name, const BdrvChildClass *child_class, + BdrvChildRole child_role, Error **errp); bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp); diff --git a/include/block/block_int.h b/include/block/block_int.h index 5d54debc34..0f51ff8f5a 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -746,6 +746,7 @@ struct BdrvChild { BlockDriverState *bs; char *name; const BdrvChildClass *klass; + BdrvChildRole role; void *opaque; /** @@ -1227,6 +1228,7 @@ void hmp_drive_add_node(Monitor *mon, const char *optstr); BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, const char *child_name, const BdrvChildClass *child_class, + BdrvChildRole child_role, AioContext *ctx, uint64_t perm, uint64_t shared_perm, void *opaque, Error **errp); diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index 9d683a6c11..c03705ea37 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -1202,7 +1202,7 @@ static void do_test_delete_by_drain(bool detach_instead_of_delete, null_bs = bdrv_open("null-co://", NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL, &error_abort); - bdrv_attach_child(bs, null_bs, "null-child", &child_file, &error_abort); + bdrv_attach_child(bs, null_bs, "null-child", &child_file, 0, &error_abort); /* This child will be the one to pass to requests through to, and * it will stall until a drain occurs */ @@ -1211,13 +1211,13 @@ static void do_test_delete_by_drain(bool detach_instead_of_delete, child_bs->total_sectors = 65536 >> BDRV_SECTOR_BITS; /* Takes our reference to child_bs */ tts->wait_child = bdrv_attach_child(bs, child_bs, "wait-child", &child_file, - &error_abort); + 0, &error_abort); /* This child is just there to be deleted * (for detach_instead_of_delete == true) */ null_bs = bdrv_open("null-co://", NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL, &error_abort); - bdrv_attach_child(bs, null_bs, "null-child", &child_file, &error_abort); + bdrv_attach_child(bs, null_bs, "null-child", &child_file, 0, &error_abort); blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); blk_insert_bs(blk, bs, &error_abort); @@ -1314,7 +1314,7 @@ static void detach_indirect_bh(void *opaque) bdrv_ref(data->c); data->child_c = bdrv_attach_child(data->parent_b, data->c, "PB-C", - &child_file, &error_abort); + &child_file, 0, &error_abort); } static void detach_by_parent_aio_cb(void *opaque, int ret) @@ -1396,13 +1396,15 @@ static void test_detach_indirect(bool by_parent_cb) /* Set child relationships */ bdrv_ref(b); bdrv_ref(a); - child_b = bdrv_attach_child(parent_b, b, "PB-B", &child_file, &error_abort); - child_a = bdrv_attach_child(parent_b, a, "PB-A", &child_backing, &error_abort); + child_b = bdrv_attach_child(parent_b, b, "PB-B", &child_file, 0, + &error_abort); + child_a = bdrv_attach_child(parent_b, a, "PB-A", &child_backing, 0, + &error_abort); bdrv_ref(a); bdrv_attach_child(parent_a, a, "PA-A", by_parent_cb ? &child_file : &detach_by_driver_cb_class, - &error_abort); + 0, &error_abort); g_assert_cmpint(parent_a->refcnt, ==, 1); g_assert_cmpint(parent_b->refcnt, ==, 1); @@ -1813,7 +1815,7 @@ static void test_drop_intermediate_poll(void) /* Takes the reference to chain[i - 1] */ chain[i]->backing = bdrv_attach_child(chain[i], chain[i - 1], "chain", &chain_child_class, - &error_abort); + 0, &error_abort); } } @@ -2031,7 +2033,7 @@ static void do_test_replace_child_mid_drain(int old_drain_count, bdrv_ref(old_child_bs); parent_bs->backing = bdrv_attach_child(parent_bs, old_child_bs, "child", - &child_backing, &error_abort); + &child_backing, 0, &error_abort); for (i = 0; i < old_drain_count; i++) { bdrv_drained_begin(old_child_bs); diff --git a/tests/test-bdrv-graph-mod.c b/tests/test-bdrv-graph-mod.c index fef42cb294..8b8c186c9f 100644 --- a/tests/test-bdrv-graph-mod.c +++ b/tests/test-bdrv-graph-mod.c @@ -111,7 +111,7 @@ static void test_update_perm_tree(void) blk_insert_bs(root, bs, &error_abort); - bdrv_attach_child(filter, bs, "child", &child_file, &error_abort); + bdrv_attach_child(filter, bs, "child", &child_file, 0, &error_abort); bdrv_append(filter, bs, &local_err); @@ -177,7 +177,7 @@ static void test_should_update_child(void) bdrv_set_backing_hd(target, bs, &error_abort); g_assert(target->backing->bs == bs); - bdrv_attach_child(filter, target, "target", &child_file, &error_abort); + bdrv_attach_child(filter, target, "target", &child_file, 0, &error_abort); bdrv_append(filter, bs, &error_abort); g_assert(target->backing->bs == bs); From patchwork Tue Feb 18 12:42:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388353 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 867D2930 for ; Tue, 18 Feb 2020 12:44:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4D8CE2173E for ; Tue, 18 Feb 2020 12:44:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="isOSHLBi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4D8CE2173E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42EV-0006RW-Dz for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:44:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38847) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42DX-00040Z-1E for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42DV-00014p-2F for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:10 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:31938 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42DU-00014V-Ty for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029788; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/dJOPDC9fjQjju6lJf7HC60yGLy5q+iK4hPSqsIQ2JE=; b=isOSHLBiRIaacCBipSEbLiht5jdcBhr0J26PnruevXnKtiyZdgBVFIJ66+N5rz/n3zP+Fg ZsVN5VbOBOgjHCrHdni1MU0csg6+pZP/L1er9KvQSZg/T8r+g1oFMdFN+nv1CwvVKNHQ4c BcAKQghDn/2Jxk9AE1V32OCZ2BDy3Z0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-79-_qOTR6reOZCJiqsc_5VlSA-1; Tue, 18 Feb 2020 07:43:04 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 11BEE18A5500; Tue, 18 Feb 2020 12:43:03 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F2CE08B550; Tue, 18 Feb 2020 12:43:01 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 05/33] block: Pass BdrvChildRole to bdrv_child_perm() Date: Tue, 18 Feb 2020 13:42:14 +0100 Message-Id: <20200218124242.584644-6-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: _qOTR6reOZCJiqsc_5VlSA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" For now, all callers pass 0 and no callee evaluates this value. Later patches will change both. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 22 ++++++++++++---------- block/backup-top.c | 3 ++- block/blkdebug.c | 5 +++-- block/blklogwrites.c | 9 +++++---- block/commit.c | 1 + block/copy-on-read.c | 1 + block/mirror.c | 1 + block/quorum.c | 1 + block/replication.c | 1 + block/vvfat.c | 1 + include/block/block_int.h | 5 ++++- tests/test-bdrv-drain.c | 5 +++-- tests/test-bdrv-graph-mod.c | 1 + 13 files changed, 36 insertions(+), 20 deletions(-) diff --git a/block.c b/block.c index e8ddf1689e..bfeed6e8d9 100644 --- a/block.c +++ b/block.c @@ -1786,12 +1786,12 @@ bool bdrv_is_writable(BlockDriverState *bs) static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs, BdrvChild *c, const BdrvChildClass *child_class, - BlockReopenQueue *reopen_queue, + BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t parent_perm, uint64_t parent_shared, uint64_t *nperm, uint64_t *nshared) { assert(bs->drv && bs->drv->bdrv_child_perm); - bs->drv->bdrv_child_perm(bs, c, child_class, reopen_queue, + bs->drv->bdrv_child_perm(bs, c, child_class, role, reopen_queue, parent_perm, parent_shared, nperm, nshared); /* TODO Take force_share from reopen_queue */ @@ -1885,7 +1885,7 @@ static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q, uint64_t cur_perm, cur_shared; bool child_tighten_restr; - bdrv_child_perm(bs, c->bs, c, c->klass, q, + bdrv_child_perm(bs, c->bs, c, c->klass, c->role, q, cumulative_perms, cumulative_shared_perms, &cur_perm, &cur_shared); ret = bdrv_child_check_perm(c, q, cur_perm, cur_shared, ignore_children, @@ -1952,7 +1952,7 @@ static void bdrv_set_perm(BlockDriverState *bs, uint64_t cumulative_perms, /* Update all children */ QLIST_FOREACH(c, &bs->children, next) { uint64_t cur_perm, cur_shared; - bdrv_child_perm(bs, c->bs, c, c->klass, NULL, + bdrv_child_perm(bs, c->bs, c, c->klass, c->role, NULL, cumulative_perms, cumulative_shared_perms, &cur_perm, &cur_shared); bdrv_child_set_perm(c, cur_perm, cur_shared); @@ -2180,14 +2180,15 @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp) uint64_t perms, shared; bdrv_get_cumulative_perm(bs, &parent_perms, &parent_shared); - bdrv_child_perm(bs, c->bs, c, c->klass, NULL, parent_perms, parent_shared, - &perms, &shared); + bdrv_child_perm(bs, c->bs, c, c->klass, c->role, NULL, + parent_perms, parent_shared, &perms, &shared); return bdrv_child_try_set_perm(c, perms, shared, errp); } void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, + BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) @@ -2198,6 +2199,7 @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, + BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) @@ -2210,7 +2212,7 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, /* Apart from the modifications below, the same permissions are * forwarded and left alone as for filters */ - bdrv_filter_default_perms(bs, c, child_class, reopen_queue, + bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, perm, shared, &perm, &shared); /* Format drivers may touch metadata even if the guest doesn't write */ @@ -2486,7 +2488,7 @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, bdrv_get_cumulative_perm(parent_bs, &perm, &shared_perm); assert(parent_bs->drv); - bdrv_child_perm(parent_bs, child_bs, NULL, child_class, NULL, + bdrv_child_perm(parent_bs, child_bs, NULL, child_class, child_role, NULL, perm, shared_perm, &perm, &shared_perm); child = bdrv_root_attach_child(child_bs, child_name, child_class, @@ -3524,7 +3526,7 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp) if (state->replace_backing_bs && state->new_backing_bs) { uint64_t nperm, nshared; bdrv_child_perm(state->bs, state->new_backing_bs, - NULL, &child_backing, bs_queue, + NULL, &child_backing, 0, bs_queue, state->perm, state->shared_perm, &nperm, &nshared); ret = bdrv_check_update_perm(state->new_backing_bs, NULL, @@ -3638,7 +3640,7 @@ static void bdrv_reopen_perm(BlockReopenQueue *q, BlockDriverState *bs, } else { uint64_t nperm, nshared; - bdrv_child_perm(parent->state.bs, bs, c, c->klass, q, + bdrv_child_perm(parent->state.bs, bs, c, c->klass, c->role, q, parent->state.perm, parent->state.shared_perm, &nperm, &nshared); diff --git a/block/backup-top.c b/block/backup-top.c index b13d459e86..9dd89c2fde 100644 --- a/block/backup-top.c +++ b/block/backup-top.c @@ -122,6 +122,7 @@ static void backup_top_refresh_filename(BlockDriverState *bs) static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, + BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) @@ -152,7 +153,7 @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, *nperm = BLK_PERM_WRITE; } else { /* Source child */ - bdrv_filter_default_perms(bs, c, child_class, reopen_queue, + bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, perm, shared, nperm, nshared); if (perm & BLK_PERM_WRITE) { diff --git a/block/blkdebug.c b/block/blkdebug.c index c91e78d5c8..8dd8ed6055 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -994,14 +994,15 @@ static int blkdebug_reopen_prepare(BDRVReopenState *reopen_state, static void blkdebug_child_perm(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, + BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) { BDRVBlkdebugState *s = bs->opaque; - bdrv_filter_default_perms(bs, c, child_class, reopen_queue, perm, shared, - nperm, nshared); + bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); *nperm |= s->take_child_perms; *nshared &= ~s->unshare_child_perms; diff --git a/block/blklogwrites.c b/block/blklogwrites.c index 739db6dcf6..4faf912ef1 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -283,6 +283,7 @@ static int64_t blk_log_writes_getlength(BlockDriverState *bs) static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, + BdrvChildRole role, BlockReopenQueue *ro_q, uint64_t perm, uint64_t shrd, uint64_t *nperm, uint64_t *nshrd) @@ -294,11 +295,11 @@ static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, } if (!strcmp(c->name, "log")) { - bdrv_format_default_perms(bs, c, child_class, ro_q, perm, shrd, nperm, - nshrd); + bdrv_format_default_perms(bs, c, child_class, role, ro_q, perm, shrd, + nperm, nshrd); } else { - bdrv_filter_default_perms(bs, c, child_class, ro_q, perm, shrd, nperm, - nshrd); + bdrv_filter_default_perms(bs, c, child_class, role, ro_q, perm, shrd, + nperm, nshrd); } } diff --git a/block/commit.c b/block/commit.c index a712662633..6d094c8cd1 100644 --- a/block/commit.c +++ b/block/commit.c @@ -224,6 +224,7 @@ static void bdrv_commit_top_refresh_filename(BlockDriverState *bs) static void bdrv_commit_top_child_perm(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, + BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) diff --git a/block/copy-on-read.c b/block/copy-on-read.c index a2c4e6dc58..a2d92ac394 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -52,6 +52,7 @@ static int cor_open(BlockDriverState *bs, QDict *options, int flags, static void cor_child_perm(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, + BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) diff --git a/block/mirror.c b/block/mirror.c index d8506af45a..25c5e8b622 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1485,6 +1485,7 @@ static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs) static void bdrv_mirror_top_child_perm(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, + BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) diff --git a/block/quorum.c b/block/quorum.c index 024de76e6f..d37b77a522 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1152,6 +1152,7 @@ static char *quorum_dirname(BlockDriverState *bs, Error **errp) static void quorum_child_perm(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, + BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) diff --git a/block/replication.c b/block/replication.c index c05df1bc16..9ca5c9368e 100644 --- a/block/replication.c +++ b/block/replication.c @@ -161,6 +161,7 @@ static void replication_close(BlockDriverState *bs) static void replication_child_perm(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, + BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) diff --git a/block/vvfat.c b/block/vvfat.c index 022462d9c9..8e56513604 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3213,6 +3213,7 @@ err: static void vvfat_child_perm(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, + BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) diff --git a/include/block/block_int.h b/include/block/block_int.h index 0f51ff8f5a..826d1bf6bd 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -556,7 +556,7 @@ struct BlockDriver { * the parents in @parent_perm and @parent_shared. * * If @c is NULL, return the permissions for attaching a new child for the - * given @child_class. + * given @child_class and @role. * * If @reopen_queue is non-NULL, don't return the currently needed * permissions, but those that will be needed after applying the @@ -564,6 +564,7 @@ struct BlockDriver { */ void (*bdrv_child_perm)(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, + BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t parent_perm, uint64_t parent_shared, uint64_t *nperm, uint64_t *nshared); @@ -1257,6 +1258,7 @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp); * all children */ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, + BdrvChildRole child_role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared); @@ -1267,6 +1269,7 @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, * CONSISTENT_READ and doesn't share WRITE. */ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, + BdrvChildRole child_role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared); diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index c03705ea37..b3d7960bd0 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -87,6 +87,7 @@ static int coroutine_fn bdrv_test_co_preadv(BlockDriverState *bs, static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, + BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) @@ -99,8 +100,8 @@ static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, child_class = &child_file; } - bdrv_format_default_perms(bs, c, child_class, reopen_queue, perm, shared, - nperm, nshared); + bdrv_format_default_perms(bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); } static int bdrv_test_change_backing_file(BlockDriverState *bs, diff --git a/tests/test-bdrv-graph-mod.c b/tests/test-bdrv-graph-mod.c index 8b8c186c9f..3707e2533c 100644 --- a/tests/test-bdrv-graph-mod.c +++ b/tests/test-bdrv-graph-mod.c @@ -31,6 +31,7 @@ static BlockDriver bdrv_pass_through = { static void no_perm_default_perms(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, + BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) From patchwork Tue Feb 18 12:42:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388363 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B9E19159A for ; Tue, 18 Feb 2020 12:46:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 80EB721D56 for ; Tue, 18 Feb 2020 12:46:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LchT9Xw5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 80EB721D56 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42GW-0002Ek-NX for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:46:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38880) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Da-00045b-0M for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42DY-00016T-Bd for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:13 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:55288 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42DY-000168-6L for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029791; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BWNJFp6c8JiWkSki5n2Yola1omAAkCRTSSkS+iglxjw=; b=LchT9Xw5le5OHWDgha78SM6hVMRWrzf7hFNWpJH0/zSJH8qwFx7wpxar5kNb+CHy2tPRQ/ S/09fa+aWksGLA9crwqT+S17j3Wko6xphb8KmnV8D5pYSWUYgR9Sc/3dk+MBB+KSDg8t7Y quECgfP1erhyv4wxex3oe1gSE/c1NE4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-60-JxDMu5ZaPMyFbA9LiGF9wA-1; Tue, 18 Feb 2020 07:43:07 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6309818A5512; Tue, 18 Feb 2020 12:43:06 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 902CB8B561; Tue, 18 Feb 2020 12:43:05 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 06/33] block: Pass BdrvChildRole to .inherit_options() Date: Tue, 18 Feb 2020 13:42:15 +0100 Message-Id: <20200218124242.584644-7-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: JxDMu5ZaPMyFbA9LiGF9wA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" For now, all callers (effectively) pass 0 and no callee evaluates thie value. Later patches will change both. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 40 +++++++++++++++++++++++---------------- block/block-backend.c | 3 ++- block/vvfat.c | 3 ++- include/block/block_int.h | 3 ++- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/block.c b/block.c index bfeed6e8d9..9fc865288d 100644 --- a/block.c +++ b/block.c @@ -77,6 +77,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, QDict *options, int flags, BlockDriverState *parent, const BdrvChildClass *child_class, + BdrvChildRole child_role, Error **errp); /* If non-zero, use only whitelisted block drivers */ @@ -1001,7 +1002,8 @@ static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options, * Returns the options and flags that bs->file should get if a protocol driver * is expected, based on the given options and flags for the parent BDS */ -static void bdrv_inherited_options(int *child_flags, QDict *child_options, +static void bdrv_inherited_options(BdrvChildRole role, + int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options) { int flags = parent_flags; @@ -1050,10 +1052,11 @@ const BdrvChildClass child_file = { * (and not only protocols) is permitted for it, based on the given options and * flags for the parent BDS */ -static void bdrv_inherited_fmt_options(int *child_flags, QDict *child_options, +static void bdrv_inherited_fmt_options(BdrvChildRole role, + int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options) { - child_file.inherit_options(child_flags, child_options, + child_file.inherit_options(role, child_flags, child_options, parent_flags, parent_options); *child_flags &= ~(BDRV_O_PROTOCOL | BDRV_O_NO_IO); @@ -1134,7 +1137,8 @@ static void bdrv_backing_detach(BdrvChild *c) * Returns the options and flags that bs->backing should get, based on the * given options and flags for the parent BDS */ -static void bdrv_backing_options(int *child_flags, QDict *child_options, +static void bdrv_backing_options(BdrvChildRole role, + int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options) { int flags = parent_flags; @@ -2710,7 +2714,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options, } backing_hd = bdrv_open_inherit(backing_filename, reference, options, 0, bs, - &child_backing, errp); + &child_backing, 0, errp); if (!backing_hd) { bs->open_flags |= BDRV_O_NO_BACKING; error_prepend(errp, "Could not open backing file: "); @@ -2745,7 +2749,7 @@ free_exit: static BlockDriverState * bdrv_open_child_bs(const char *filename, QDict *options, const char *bdref_key, BlockDriverState *parent, const BdrvChildClass *child_class, - bool allow_none, Error **errp) + BdrvChildRole child_role, bool allow_none, Error **errp) { BlockDriverState *bs = NULL; QDict *image_options; @@ -2776,7 +2780,7 @@ bdrv_open_child_bs(const char *filename, QDict *options, const char *bdref_key, } bs = bdrv_open_inherit(filename, reference, image_options, 0, - parent, child_class, errp); + parent, child_class, child_role, errp); if (!bs) { goto done; } @@ -2810,7 +2814,7 @@ BdrvChild *bdrv_open_child(const char *filename, BlockDriverState *bs; bs = bdrv_open_child_bs(filename, options, bdref_key, parent, child_class, - allow_none, errp); + child_role, allow_none, errp); if (bs == NULL) { return NULL; } @@ -2859,7 +2863,7 @@ BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp) } - bs = bdrv_open_inherit(NULL, reference, qdict, 0, NULL, NULL, errp); + bs = bdrv_open_inherit(NULL, reference, qdict, 0, NULL, NULL, 0, errp); obj = NULL; fail: @@ -2958,6 +2962,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, QDict *options, int flags, BlockDriverState *parent, const BdrvChildClass *child_class, + BdrvChildRole child_role, Error **errp) { int ret; @@ -3010,7 +3015,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, if (child_class) { bs->inherits_from = parent; - child_class->inherit_options(&flags, options, + child_class->inherit_options(child_role, &flags, options, parent->open_flags, parent->options); } @@ -3039,7 +3044,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, flags, options); /* Let bdrv_backing_options() override "read-only" */ qdict_del(options, BDRV_OPT_READ_ONLY); - bdrv_backing_options(&flags, options, flags, options); + bdrv_backing_options(0, &flags, options, flags, options); } bs->open_flags = flags; @@ -3081,7 +3086,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, BlockDriverState *file_bs; file_bs = bdrv_open_child_bs(filename, options, "file", bs, - &child_file, true, &local_err); + &child_file, 0, true, &local_err); if (local_err) { goto fail; } @@ -3226,7 +3231,7 @@ BlockDriverState *bdrv_open(const char *filename, const char *reference, QDict *options, int flags, Error **errp) { return bdrv_open_inherit(filename, reference, options, flags, NULL, - NULL, errp); + NULL, 0, errp); } /* Return true if the NULL-terminated @list contains @str */ @@ -3323,6 +3328,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, BlockDriverState *bs, QDict *options, const BdrvChildClass *klass, + BdrvChildRole role, QDict *parent_options, int parent_flags, bool keep_old_opts) @@ -3378,7 +3384,8 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, /* Inherit from parent node */ if (parent_options) { flags = 0; - klass->inherit_options(&flags, options, parent_flags, parent_options); + klass->inherit_options(role, &flags, options, + parent_flags, parent_options); } else { flags = bdrv_get_flags(bs); } @@ -3469,7 +3476,8 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, } bdrv_reopen_queue_child(bs_queue, child->bs, new_child_options, - child->klass, options, flags, child_keep_old); + child->klass, child->role, options, flags, + child_keep_old); } return bs_queue; @@ -3479,7 +3487,7 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, BlockDriverState *bs, QDict *options, bool keep_old_opts) { - return bdrv_reopen_queue_child(bs_queue, bs, options, NULL, NULL, 0, + return bdrv_reopen_queue_child(bs_queue, bs, options, NULL, 0, NULL, 0, keep_old_opts); } diff --git a/block/block-backend.c b/block/block-backend.c index 4b79b2abb1..98f3167fa6 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -120,7 +120,8 @@ static QTAILQ_HEAD(, BlockBackend) block_backends = static QTAILQ_HEAD(, BlockBackend) monitor_block_backends = QTAILQ_HEAD_INITIALIZER(monitor_block_backends); -static void blk_root_inherit_options(int *child_flags, QDict *child_options, +static void blk_root_inherit_options(BdrvChildRole role, + int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options) { /* We're not supposed to call this function for root nodes */ diff --git a/block/vvfat.c b/block/vvfat.c index 8e56513604..7ef2c9cdcc 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3130,7 +3130,8 @@ static BlockDriver vvfat_write_target = { .bdrv_co_pwritev = write_target_commit, }; -static void vvfat_qcow_options(int *child_flags, QDict *child_options, +static void vvfat_qcow_options(BdrvChildRole role, + int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options) { qdict_set_default_str(child_options, BDRV_OPT_READ_ONLY, "off"); diff --git a/include/block/block_int.h b/include/block/block_int.h index 826d1bf6bd..fbc1b90088 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -677,7 +677,8 @@ struct BdrvChildClass { * non-BDS parents. */ bool parent_is_bds; - void (*inherit_options)(int *child_flags, QDict *child_options, + void (*inherit_options)(BdrvChildRole role, + int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options); void (*change_media)(BdrvChild *child, bool load); From patchwork Tue Feb 18 12:42:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388377 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E1781395 for ; Tue, 18 Feb 2020 12:51:21 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 051302173E for ; Tue, 18 Feb 2020 12:51:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="h7yAtmmh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 051302173E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42LQ-0001dq-5B for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:51:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38884) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Da-00046c-CH for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42DY-00016n-UJ for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:14 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:35082 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42DY-00016d-Q5 for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029792; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4CUk/4bN8GAo34xsF8INvZX4Ka4KupQ2TDuZcBSaemg=; b=h7yAtmmhi3UZOquWkGWIviyTy5GJaaD84u95eml6gwKCa1WhsFE71U+k5AxC53LHbVb9xa wf6eXGQxy5HhnB8zeRC99l8CtnlIxbVpxN/wkls9ad9ExY3v+uJmS3b7XwHk4fGAzm+4pt oqcaZFEHBas6VXozQPwe/4ziujFdVcI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-9-QjmkOrHIPmK6uZFI3F5Y7g-1; Tue, 18 Feb 2020 07:43:10 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9367E13E6; Tue, 18 Feb 2020 12:43:09 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DC9425DA60; Tue, 18 Feb 2020 12:43:08 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 07/33] block: Pass parent_is_format to .inherit_options() Date: Tue, 18 Feb 2020 13:42:16 +0100 Message-Id: <20200218124242.584644-8-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: QjmkOrHIPmK6uZFI3F5Y7g-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" We plan to unify the generic .inherit_options() functions. The resulting common function will need to decide whether to force-enable format probing, force-disable it, or leave it as-is. To make this decision, it will need to know whether the parent node is a format node or not (because we never want format probing if the parent is a format node already (except for the backing chain)). Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 37 +++++++++++++++++++++++++++---------- block/block-backend.c | 2 +- block/vvfat.c | 2 +- include/block/block_int.h | 2 +- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/block.c b/block.c index 9fc865288d..706fae355e 100644 --- a/block.c +++ b/block.c @@ -1002,7 +1002,7 @@ static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options, * Returns the options and flags that bs->file should get if a protocol driver * is expected, based on the given options and flags for the parent BDS */ -static void bdrv_inherited_options(BdrvChildRole role, +static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options) { @@ -1053,10 +1053,12 @@ const BdrvChildClass child_file = { * flags for the parent BDS */ static void bdrv_inherited_fmt_options(BdrvChildRole role, + bool parent_is_format, int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options) { - child_file.inherit_options(role, child_flags, child_options, + child_file.inherit_options(role, parent_is_format, + child_flags, child_options, parent_flags, parent_options); *child_flags &= ~(BDRV_O_PROTOCOL | BDRV_O_NO_IO); @@ -1137,7 +1139,7 @@ static void bdrv_backing_detach(BdrvChild *c) * Returns the options and flags that bs->backing should get, based on the * given options and flags for the parent BDS */ -static void bdrv_backing_options(BdrvChildRole role, +static void bdrv_backing_options(BdrvChildRole role, bool parent_is_format, int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options) { @@ -3014,8 +3016,22 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, bs->explicit_options = qdict_clone_shallow(options); if (child_class) { + bool parent_is_format; + + if (parent->drv) { + parent_is_format = parent->drv->is_format; + } else { + /* + * parent->drv is not set yet because this node is opened for + * (potential) format probing. That means that @parent is going + * to be a format node. + */ + parent_is_format = true; + } + bs->inherits_from = parent; - child_class->inherit_options(child_role, &flags, options, + child_class->inherit_options(child_role, parent_is_format, + &flags, options, parent->open_flags, parent->options); } @@ -3044,7 +3060,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, flags, options); /* Let bdrv_backing_options() override "read-only" */ qdict_del(options, BDRV_OPT_READ_ONLY); - bdrv_backing_options(0, &flags, options, flags, options); + bdrv_backing_options(0, true, &flags, options, flags, options); } bs->open_flags = flags; @@ -3329,6 +3345,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, QDict *options, const BdrvChildClass *klass, BdrvChildRole role, + bool parent_is_format, QDict *parent_options, int parent_flags, bool keep_old_opts) @@ -3384,7 +3401,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, /* Inherit from parent node */ if (parent_options) { flags = 0; - klass->inherit_options(role, &flags, options, + klass->inherit_options(role, parent_is_format, &flags, options, parent_flags, parent_options); } else { flags = bdrv_get_flags(bs); @@ -3476,8 +3493,8 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, } bdrv_reopen_queue_child(bs_queue, child->bs, new_child_options, - child->klass, child->role, options, flags, - child_keep_old); + child->klass, child->role, bs->drv->is_format, + options, flags, child_keep_old); } return bs_queue; @@ -3487,8 +3504,8 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, BlockDriverState *bs, QDict *options, bool keep_old_opts) { - return bdrv_reopen_queue_child(bs_queue, bs, options, NULL, 0, NULL, 0, - keep_old_opts); + return bdrv_reopen_queue_child(bs_queue, bs, options, NULL, 0, false, + NULL, 0, keep_old_opts); } /* diff --git a/block/block-backend.c b/block/block-backend.c index 98f3167fa6..9e0078bfb5 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -120,7 +120,7 @@ static QTAILQ_HEAD(, BlockBackend) block_backends = static QTAILQ_HEAD(, BlockBackend) monitor_block_backends = QTAILQ_HEAD_INITIALIZER(monitor_block_backends); -static void blk_root_inherit_options(BdrvChildRole role, +static void blk_root_inherit_options(BdrvChildRole role, bool parent_is_format, int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options) { diff --git a/block/vvfat.c b/block/vvfat.c index 7ef2c9cdcc..a945eeb635 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3130,7 +3130,7 @@ static BlockDriver vvfat_write_target = { .bdrv_co_pwritev = write_target_commit, }; -static void vvfat_qcow_options(BdrvChildRole role, +static void vvfat_qcow_options(BdrvChildRole role, bool parent_is_format, int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options) { diff --git a/include/block/block_int.h b/include/block/block_int.h index fbc1b90088..1f8a818f76 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -677,7 +677,7 @@ struct BdrvChildClass { * non-BDS parents. */ bool parent_is_bds; - void (*inherit_options)(BdrvChildRole role, + void (*inherit_options)(BdrvChildRole role, bool parent_is_format, int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options); From patchwork Tue Feb 18 12:42:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388369 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 08F66139A for ; Tue, 18 Feb 2020 12:48:24 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D485F2173E for ; Tue, 18 Feb 2020 12:48:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SAHB+J4v" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D485F2173E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42IY-0005RM-Vl for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:48:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38924) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Dd-0004Ex-6h for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42Dc-00018a-68 for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:17 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:59126 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42Dc-00018I-1c for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029795; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oRCesg5ctRaehReWF4NUGPXX1zvSZ0LHWpEnMJ2iZ30=; b=SAHB+J4vPDJuJAbKmSvZuUKEys3xL2zE+ZhwkO528hs/i/Je0RWdP2WusOjKWRUzK0MkrA xQNuJO4Xdrp1lf6Ag087kRKSa8NJJ93RFK7Zi+m5xmLshiRhkLPZkntX2Fz9jMSiC0LkWP 3SbTYDDAdNoWZ828SmEJDgUFc4ZItE0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-311-qhPDADBKMUupawNlGrda2w-1; Tue, 18 Feb 2020 07:43:13 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A9545107ACCC; Tue, 18 Feb 2020 12:43:12 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 26E8B10001AE; Tue, 18 Feb 2020 12:43:11 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 08/33] block: Rename bdrv_inherited_options() Date: Tue, 18 Feb 2020 13:42:17 +0100 Message-Id: <20200218124242.584644-9-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: qhPDADBKMUupawNlGrda2w-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The other two .inherit_options implementations specify exactly for what case they are used in their name, so do it for this one as well. (The actual intention behind this patch is to follow it up with a generic bdrv_inherited_options() that works for all three cases.) Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index 706fae355e..c33f0e9b42 100644 --- a/block.c +++ b/block.c @@ -1002,9 +1002,9 @@ static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options, * Returns the options and flags that bs->file should get if a protocol driver * is expected, based on the given options and flags for the parent BDS */ -static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, - int *child_flags, QDict *child_options, - int parent_flags, QDict *parent_options) +static void bdrv_protocol_options(BdrvChildRole role, bool parent_is_format, + int *child_flags, QDict *child_options, + int parent_flags, QDict *parent_options) { int flags = parent_flags; @@ -1036,7 +1036,7 @@ static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, const BdrvChildClass child_file = { .parent_is_bds = true, .get_parent_desc = bdrv_child_get_parent_desc, - .inherit_options = bdrv_inherited_options, + .inherit_options = bdrv_protocol_options, .drained_begin = bdrv_child_cb_drained_begin, .drained_poll = bdrv_child_cb_drained_poll, .drained_end = bdrv_child_cb_drained_end, From patchwork Tue Feb 18 12:42:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388371 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7061F139A for ; Tue, 18 Feb 2020 12:48:51 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4795422527 for ; Tue, 18 Feb 2020 12:48:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="D5lymNz+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4795422527 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33975 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42J0-0006JD-EA for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:48:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39015) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Dl-0004dZ-7n for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42Dk-0001Dk-26 for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:25 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:44792 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42Dj-0001DZ-VF for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029803; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CoXOBQPAPA2CnsqwWNkbNSUQjhaIB3ZBKoZqaBZg2Gw=; b=D5lymNz+0VlNLD+p8DahjSoEmLfF+/yOudeDPwbOYQ8ND2tH2qJva1uCWSv6aq3QbXTWVs MIPbr7wDKKT/lEEmDJuoOqLce6QO5QGZ55l3gx+f3ei0WHFe/O1btOMBxLrwZa683s6H3k IwojM1I0xKIFz4uX3QeFE3J8IDDcFWM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-139-0-0zy09YPo6dhaD3xZjfjw-1; Tue, 18 Feb 2020 07:43:16 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C062E13EA; Tue, 18 Feb 2020 12:43:15 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 330BA100194E; Tue, 18 Feb 2020 12:43:15 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 09/33] block: Add generic bdrv_inherited_options() Date: Tue, 18 Feb 2020 13:42:18 +0100 Message-Id: <20200218124242.584644-10-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: 0-0zy09YPo6dhaD3xZjfjw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" After the series this patch belongs to, we want to have a common BdrvChildClass that encompasses all of child_file, child_format, and child_backing. Such a single class needs a single .inherit_options() implementation, and this patch introduces it. The next patch will show how the existing implementations can fall back to it just by passing appropriate BdrvChildRole and parent_is_format values. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/block.c b/block.c index c33f0e9b42..9179b9b604 100644 --- a/block.c +++ b/block.c @@ -998,6 +998,90 @@ static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options, *child_flags &= ~BDRV_O_NATIVE_AIO; } +/* + * Returns the options and flags that a generic child of a BDS should + * get, based on the given options and flags for the parent BDS. + */ +static void __attribute__((unused)) + bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, + int *child_flags, QDict *child_options, + int parent_flags, QDict *parent_options) +{ + int flags = parent_flags; + + /* + * First, decide whether to set, clear, or leave BDRV_O_PROTOCOL. + * Generally, the question to answer is: Should this child be + * format-probed by default? + */ + + /* + * Pure and non-filtered data children of non-format nodes should + * be probed by default (even when the node itself has BDRV_O_PROTOCOL + * set). This only affects a very limited set of drivers (namely + * quorum and blkverify when this comment was written). + * Force-clear BDRV_O_PROTOCOL then. + */ + if (!parent_is_format && + (role & (BDRV_CHILD_DATA | BDRV_CHILD_METADATA | + BDRV_CHILD_FILTERED)) == + BDRV_CHILD_DATA) + { + flags &= ~BDRV_O_PROTOCOL; + } + + /* + * All children of format nodes (except for COW children) and all + * metadata children in general should never be format-probed. + * Force-set BDRV_O_PROTOCOL then. + */ + if ((parent_is_format && !(role & BDRV_CHILD_COW)) || + (role & BDRV_CHILD_METADATA)) + { + flags |= BDRV_O_PROTOCOL; + } + + /* + * If the cache mode isn't explicitly set, inherit direct and no-flush from + * the parent. + */ + qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_DIRECT); + qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_NO_FLUSH); + qdict_copy_default(child_options, parent_options, BDRV_OPT_FORCE_SHARE); + + if (role & BDRV_CHILD_COW) { + /* backing files are always opened read-only */ + qdict_set_default_str(child_options, BDRV_OPT_READ_ONLY, "on"); + qdict_set_default_str(child_options, BDRV_OPT_AUTO_READ_ONLY, "off"); + } else { + /* Inherit the read-only option from the parent if it's not set */ + qdict_copy_default(child_options, parent_options, BDRV_OPT_READ_ONLY); + qdict_copy_default(child_options, parent_options, + BDRV_OPT_AUTO_READ_ONLY); + } + + if (parent_is_format && !(role & BDRV_CHILD_COW)) { + /* + * Our format drivers take care to send flushes and respect + * unmap policy, so we can default to enable both on lower + * layers regardless of the corresponding parent options. + */ + qdict_set_default_str(child_options, BDRV_OPT_DISCARD, "unmap"); + } + + /* Clear flags that only apply to the top layer */ + flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING | BDRV_O_COPY_ON_READ); + + if (role & BDRV_CHILD_METADATA) { + flags &= ~BDRV_O_NO_IO; + } + if (role & BDRV_CHILD_COW) { + flags &= ~BDRV_O_TEMPORARY; + } + + *child_flags = flags; +} + /* * Returns the options and flags that bs->file should get if a protocol driver * is expected, based on the given options and flags for the parent BDS From patchwork Tue Feb 18 12:42:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388383 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D08D41395 for ; Tue, 18 Feb 2020 12:53:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A60EC20659 for ; Tue, 18 Feb 2020 12:53:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="R5WMwxKZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A60EC20659 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42N1-0004V7-TF for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:52:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38985) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Dj-0004Vk-9h for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42Dh-0001CR-Uv for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:23 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:43181 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42Dh-0001By-RN for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029801; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TQKOddGHQBKAwo99MiEARBSo9qMz3oh0fxqkpLF66PE=; b=R5WMwxKZNfCuAk1c4ygyjFinTD0aJ7lEGk05oFfANTx6SBRC4pDp58GJYJEzpKcSXGQtma 5wbTKR9X6GnzBtEMpgdK+AJCNXJYkW0VLi1JRqq9en1i86Gzl6dPT6QaJvMadtSdeAlNjo b08J5x5d/C3TyRmrAZEG1IRXcZc3mPw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-156-UkhfGE7GMsOV8BZxrnY11Q-1; Tue, 18 Feb 2020 07:43:19 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EB4DA8010F0; Tue, 18 Feb 2020 12:43:18 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 666118B564; Tue, 18 Feb 2020 12:43:18 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 10/33] block: Use bdrv_inherited_options() Date: Tue, 18 Feb 2020 13:42:19 +0100 Message-Id: <20200218124242.584644-11-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: UkhfGE7GMsOV8BZxrnY11Q-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Let child_file's, child_format's, and child_backing's .inherit_options() implementations fall back to bdrv_inherited_options() to show that it would really work for all of these cases, if only the parents passed the appropriate BdrvChildRole and parent_is_format values. (Also, make bdrv_open_inherit(), the only place to explicitly call bdrv_backing_options(), call bdrv_inherited_options() instead.) This patch should incur only two visible changes, both for child_format children, both of which are effectively bug fixes: First, they no longer have discard=unmap set by default. This reason it was set is because bdrv_inherited_fmt_options() fell through to bdrv_protocol_options(), and that set it because "format drivers take care to send flushes and respect unmap policy". None of the drivers that use child_format for their children (quorum and blkverify) are format drivers, though, so this reasoning does not apply here. Second, they no longer have BDRV_O_NO_IO force-cleared. child_format was used solely for children that do not store any metadata and as such will not be accessed by their parents as long as those parents do not receive I/O themselves. Thus, such children should inherit BDRV_O_NO_IO. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 66 ++++++++++++--------------------------------------------- 1 file changed, 14 insertions(+), 52 deletions(-) diff --git a/block.c b/block.c index 9179b9b604..aa54d40e4f 100644 --- a/block.c +++ b/block.c @@ -1002,10 +1002,9 @@ static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options, * Returns the options and flags that a generic child of a BDS should * get, based on the given options and flags for the parent BDS. */ -static void __attribute__((unused)) - bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, - int *child_flags, QDict *child_options, - int parent_flags, QDict *parent_options) +static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, + int *child_flags, QDict *child_options, + int parent_flags, QDict *parent_options) { int flags = parent_flags; @@ -1090,31 +1089,9 @@ static void bdrv_protocol_options(BdrvChildRole role, bool parent_is_format, int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options) { - int flags = parent_flags; - - /* Enable protocol handling, disable format probing for bs->file */ - flags |= BDRV_O_PROTOCOL; - - /* If the cache mode isn't explicitly set, inherit direct and no-flush from - * the parent. */ - qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_DIRECT); - qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_NO_FLUSH); - qdict_copy_default(child_options, parent_options, BDRV_OPT_FORCE_SHARE); - - /* Inherit the read-only option from the parent if it's not set */ - qdict_copy_default(child_options, parent_options, BDRV_OPT_READ_ONLY); - qdict_copy_default(child_options, parent_options, BDRV_OPT_AUTO_READ_ONLY); - - /* Our block drivers take care to send flushes and respect unmap policy, - * so we can default to enable both on lower layers regardless of the - * corresponding parent options. */ - qdict_set_default_str(child_options, BDRV_OPT_DISCARD, "unmap"); - - /* Clear flags that only apply to the top layer */ - flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING | BDRV_O_COPY_ON_READ | - BDRV_O_NO_IO); - - *child_flags = flags; + bdrv_inherited_options(BDRV_CHILD_IMAGE, true, + child_flags, child_options, + parent_flags, parent_options); } const BdrvChildClass child_file = { @@ -1141,11 +1118,9 @@ static void bdrv_inherited_fmt_options(BdrvChildRole role, int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options) { - child_file.inherit_options(role, parent_is_format, - child_flags, child_options, - parent_flags, parent_options); - - *child_flags &= ~(BDRV_O_PROTOCOL | BDRV_O_NO_IO); + bdrv_inherited_options(BDRV_CHILD_DATA, false, + child_flags, child_options, + parent_flags, parent_options); } const BdrvChildClass child_format = { @@ -1227,23 +1202,9 @@ static void bdrv_backing_options(BdrvChildRole role, bool parent_is_format, int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options) { - int flags = parent_flags; - - /* The cache mode is inherited unmodified for backing files; except WCE, - * which is only applied on the top level (BlockBackend) */ - qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_DIRECT); - qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_NO_FLUSH); - qdict_copy_default(child_options, parent_options, BDRV_OPT_FORCE_SHARE); - - /* backing files always opened read-only */ - qdict_set_default_str(child_options, BDRV_OPT_READ_ONLY, "on"); - qdict_set_default_str(child_options, BDRV_OPT_AUTO_READ_ONLY, "off"); - flags &= ~BDRV_O_COPY_ON_READ; - - /* snapshot=on is handled on the top layer */ - flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_TEMPORARY); - - *child_flags = flags; + bdrv_inherited_options(BDRV_CHILD_COW, true, + child_flags, child_options, + parent_flags, parent_options); } static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base, @@ -3144,7 +3105,8 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, flags, options); /* Let bdrv_backing_options() override "read-only" */ qdict_del(options, BDRV_OPT_READ_ONLY); - bdrv_backing_options(0, true, &flags, options, flags, options); + bdrv_inherited_options(BDRV_CHILD_COW, true, + &flags, options, flags, options); } bs->open_flags = flags; From patchwork Tue Feb 18 12:42:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388389 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 27BC9139A for ; Tue, 18 Feb 2020 12:54:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F342220659 for ; Tue, 18 Feb 2020 12:54:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DBmFjK46" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F342220659 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42OV-0007AF-4o for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:54:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39036) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Dn-0004jW-1V for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42Dl-0001Ed-Tj for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:26 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:39227 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42Dl-0001EP-Pq for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029805; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UiwEtie4mG0tpZEOigS5yCgAGQoBI9oOsocQ+9eCakM=; b=DBmFjK46zAyq9g2GFeXjBjcKWc6EmJBj+nBX+jjaAj4Ll77GcsA+NwdioTc5aixms0KFvF 8gl3Rt2PCwytROJyvL3722a1CMxsmftQYQJGcs1hQ4QTzVgAw0ttuGUuIG/siv038yAyhk IkSv5KAnYp9HfMowOwr7K6ZAXWDYyT4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-6-xw-FVMkKM_y28_ZsDlhQkw-1; Tue, 18 Feb 2020 07:43:23 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 55972800D50; Tue, 18 Feb 2020 12:43:22 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C3786390; Tue, 18 Feb 2020 12:43:21 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 11/33] block: Unify bdrv_child_cb_attach() Date: Tue, 18 Feb 2020 13:42:20 +0100 Message-Id: <20200218124242.584644-12-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: xw-FVMkKM_y28_ZsDlhQkw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Make bdrv_child_cb_attach() call bdrv_backing_attach() for children with a COW role (and drop the reverse call from bdrv_backing_attach()), so it can be used for any child (with a proper role set). Because so far no child has a proper role set, we need a temporary new callback for child_backing.attach that ensures bdrv_backing_attach() is called for all COW children that do not have their role set yet. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index aa54d40e4f..3cf1293a7b 100644 --- a/block.c +++ b/block.c @@ -942,9 +942,16 @@ static void bdrv_child_cb_drained_end(BdrvChild *child, bdrv_drained_end_no_poll(bs, drained_end_counter); } +static void bdrv_backing_attach(BdrvChild *c); + static void bdrv_child_cb_attach(BdrvChild *child) { BlockDriverState *bs = child->opaque; + + if (child->role & BDRV_CHILD_COW) { + bdrv_backing_attach(child); + } + bdrv_apply_subtree_drain(child, bs); } @@ -1178,7 +1185,14 @@ static void bdrv_backing_attach(BdrvChild *c) parent->backing_blocker); bdrv_op_unblock(backing_hd, BLOCK_OP_TYPE_BACKUP_TARGET, parent->backing_blocker); +} +/* XXX: Will be removed along with child_backing */ +static void bdrv_child_cb_attach_backing(BdrvChild *c) +{ + if (!(c->role & BDRV_CHILD_COW)) { + bdrv_backing_attach(c); + } bdrv_child_cb_attach(c); } @@ -1237,7 +1251,7 @@ static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base, const BdrvChildClass child_backing = { .parent_is_bds = true, .get_parent_desc = bdrv_child_get_parent_desc, - .attach = bdrv_backing_attach, + .attach = bdrv_child_cb_attach_backing, .detach = bdrv_backing_detach, .inherit_options = bdrv_backing_options, .drained_begin = bdrv_child_cb_drained_begin, From patchwork Tue Feb 18 12:42:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388375 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E91741395 for ; Tue, 18 Feb 2020 12:51:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BCD252173E for ; Tue, 18 Feb 2020 12:51:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JAIud1aA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BCD252173E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34030 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42LE-0001Og-SS for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:51:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39084) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Dr-0004w0-Fs for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42Dq-0001IP-ED for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:31 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:22475 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42Dq-0001I5-AT for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029809; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Gb2qr377YHwIoNB6UQ1wvaIVzqIp6eDW6gDKy46lrqg=; b=JAIud1aAFG+eriTu2yBJJpsbAk8dqyAjpcXazj92x5H8cpOjAruhU2kl43TZyCWwAvw73X 9vEMmUIbGLihApLQImzPCpm79Pg+Qsh69L9adlYAcs8gl73ePPtZvmL+AA75em44lScQJb WQOMp15KecztS65uF+zfS0Z1cjXmMi4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-126-f7TQjBdlPkygVCy_BDd9zA-1; Tue, 18 Feb 2020 07:43:26 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 642AA18A5500; Tue, 18 Feb 2020 12:43:25 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D5C9A1BC6D; Tue, 18 Feb 2020 12:43:24 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 12/33] block: Unify bdrv_child_cb_detach() Date: Tue, 18 Feb 2020 13:42:21 +0100 Message-Id: <20200218124242.584644-13-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: f7TQjBdlPkygVCy_BDd9zA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Make bdrv_child_cb_detach() call bdrv_backing_detach() for children with a COW role (and drop the reverse call from bdrv_backing_detach()), so it can be used for any child (with a proper role set). Because so far no child has a proper role set, we need a temporary new callback for child_backing.detach that ensures bdrv_backing_detach() is called for all COW children that do not have their role set yet. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 3cf1293a7b..0f24546863 100644 --- a/block.c +++ b/block.c @@ -943,6 +943,7 @@ static void bdrv_child_cb_drained_end(BdrvChild *child, } static void bdrv_backing_attach(BdrvChild *c); +static void bdrv_backing_detach(BdrvChild *c); static void bdrv_child_cb_attach(BdrvChild *child) { @@ -958,6 +959,11 @@ static void bdrv_child_cb_attach(BdrvChild *child) static void bdrv_child_cb_detach(BdrvChild *child) { BlockDriverState *bs = child->opaque; + + if (child->role & BDRV_CHILD_COW) { + bdrv_backing_detach(child); + } + bdrv_unapply_subtree_drain(child, bs); } @@ -1204,7 +1210,14 @@ static void bdrv_backing_detach(BdrvChild *c) bdrv_op_unblock_all(c->bs, parent->backing_blocker); error_free(parent->backing_blocker); parent->backing_blocker = NULL; +} +/* XXX: Will be removed along with child_backing */ +static void bdrv_child_cb_detach_backing(BdrvChild *c) +{ + if (!(c->role & BDRV_CHILD_COW)) { + bdrv_backing_detach(c); + } bdrv_child_cb_detach(c); } @@ -1252,7 +1265,7 @@ const BdrvChildClass child_backing = { .parent_is_bds = true, .get_parent_desc = bdrv_child_get_parent_desc, .attach = bdrv_child_cb_attach_backing, - .detach = bdrv_backing_detach, + .detach = bdrv_child_cb_detach_backing, .inherit_options = bdrv_backing_options, .drained_begin = bdrv_child_cb_drained_begin, .drained_poll = bdrv_child_cb_drained_poll, From patchwork Tue Feb 18 12:42:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388385 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D3BFD159A for ; Tue, 18 Feb 2020 12:53:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A8E102176D for ; Tue, 18 Feb 2020 12:53:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ABNgfoFR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A8E102176D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42N1-0004Um-Sp for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:52:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39129) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Du-000534-Vj for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42Ds-0001Je-U1 for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:34 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:52683 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42Ds-0001JN-Pl for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029812; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J36EkZpRpBwpEnrHyZidJi7IGEtjwqVFpcpr1/dCcPc=; b=ABNgfoFRGLev+bQ2Cr9nVLDTt81oV2SMyjTSxyaMEkND4PvKz6Jd+k+g3EG+ByAfO202nq X1dItwjtxO9wxYLhpY4eEUzy5K9vBQGXbgGBfAwABK1DDOHOXG/6XPFYtGieP7M8ex6R02 nGFCgd9jVD3jA4Ak8Jamvy5Xn6AMmiE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-221-yzGo9SO0McaKlrxSZI2lCQ-1; Tue, 18 Feb 2020 07:43:29 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5D0681005512; Tue, 18 Feb 2020 12:43:28 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF4341001281; Tue, 18 Feb 2020 12:43:27 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 13/33] block: Add child_of_bds Date: Tue, 18 Feb 2020 13:42:22 +0100 Message-Id: <20200218124242.584644-14-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: yzGo9SO0McaKlrxSZI2lCQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Any current user of child_file, child_format, and child_backing can and should use this generic BdrvChildClass instead, as it can handle all of these cases. However, to be able to do so, the users must pass the appropriate BdrvChildRole when the child is created/attached. (The following commits will take care of that.) Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 27 +++++++++++++++++++++++++++ include/block/block_int.h | 1 + 2 files changed, 28 insertions(+) diff --git a/block.c b/block.c index 0f24546863..1d33f58ff8 100644 --- a/block.c +++ b/block.c @@ -1094,6 +1094,33 @@ static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, *child_flags = flags; } +static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base, + const char *filename, Error **errp); + +static int bdrv_child_cb_update_filename(BdrvChild *c, BlockDriverState *base, + const char *filename, Error **errp) +{ + if (c->role & BDRV_CHILD_COW) { + return bdrv_backing_update_filename(c, base, filename, errp); + } + return 0; +} + +const BdrvChildClass child_of_bds = { + .parent_is_bds = true, + .get_parent_desc = bdrv_child_get_parent_desc, + .inherit_options = bdrv_inherited_options, + .drained_begin = bdrv_child_cb_drained_begin, + .drained_poll = bdrv_child_cb_drained_poll, + .drained_end = bdrv_child_cb_drained_end, + .attach = bdrv_child_cb_attach, + .detach = bdrv_child_cb_detach, + .inactivate = bdrv_child_cb_inactivate, + .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx, + .set_aio_ctx = bdrv_child_cb_set_aio_ctx, + .update_filename = bdrv_child_cb_update_filename, +}; + /* * Returns the options and flags that bs->file should get if a protocol driver * is expected, based on the given options and flags for the parent BDS diff --git a/include/block/block_int.h b/include/block/block_int.h index 1f8a818f76..dd7ccea35e 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -740,6 +740,7 @@ struct BdrvChildClass { void (*set_aio_ctx)(BdrvChild *child, AioContext *ctx, GSList **ignore); }; +extern const BdrvChildClass child_of_bds; extern const BdrvChildClass child_file; extern const BdrvChildClass child_format; extern const BdrvChildClass child_backing; From patchwork Tue Feb 18 12:42:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388355 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 02050139A for ; Tue, 18 Feb 2020 12:44:29 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CCEA42173E for ; Tue, 18 Feb 2020 12:44:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bXvRFQ6m" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CCEA42173E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Em-00079A-0M for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:44:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39145) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Dv-00054c-H7 for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42Du-0001Lb-Hj for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:35 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:49355 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42Du-0001LN-DR for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029814; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Svr+RtKi3pCVX6eLWUCWA7YmRroPmrE7+yEhrpkVpHk=; b=bXvRFQ6m6gDZUwLq/qa5eHpV1OYCeKS6pGEVPkBC80MDH7vOl/RH3dl2ufvCb3ILdKzNAH hKAMnwJI11UNxT8wHtUfLsTMUTCbD+1Lm4kcYjEuQkJz3NDsh0uso27PlclyfuxbhlwZdU xvhvzXLYiIVIqyC0IPA8EPDrJ43SoOo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-294-tSSk4OHgP3KupRWauk98EQ-1; Tue, 18 Feb 2020 07:43:32 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 74144108442A; Tue, 18 Feb 2020 12:43:31 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF4735DA76; Tue, 18 Feb 2020 12:43:30 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 14/33] block: Distinguish paths in *_format_default_perms Date: Tue, 18 Feb 2020 13:42:23 +0100 Message-Id: <20200218124242.584644-15-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: tSSk4OHgP3KupRWauk98EQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" bdrv_format_default_perms() has one code path for backing files, and one for storage files. We want to pull them out into own functions, so make sure they are completely distinct before so the next patches will be a bit cleaner. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index 1d33f58ff8..982785b15a 100644 --- a/block.c +++ b/block.c @@ -2331,6 +2331,13 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, perm |= BLK_PERM_CONSISTENT_READ; } shared &= ~(BLK_PERM_WRITE | BLK_PERM_RESIZE); + + if (bs->open_flags & BDRV_O_INACTIVE) { + shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE; + } + + *nperm = perm; + *nshared = shared; } else { /* We want consistent read from backing files if the parent needs it. * No other operations are performed on backing files. */ @@ -2347,14 +2354,14 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, shared |= BLK_PERM_CONSISTENT_READ | BLK_PERM_GRAPH_MOD | BLK_PERM_WRITE_UNCHANGED; - } - if (bs->open_flags & BDRV_O_INACTIVE) { - shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE; - } + if (bs->open_flags & BDRV_O_INACTIVE) { + shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE; + } - *nperm = perm; - *nshared = shared; + *nperm = perm; + *nshared = shared; + } } uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission qapi_perm) From patchwork Tue Feb 18 12:42:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388391 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 420AD159A for ; Tue, 18 Feb 2020 12:54:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 19B752176D for ; Tue, 18 Feb 2020 12:54:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UjmhOgSS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 19B752176D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34082 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42OV-0007AT-8I for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:54:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39185) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Dy-0005Dq-Lo for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42Dx-0001Pz-J1 for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:38 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:25093 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42Dx-0001Pa-Ex for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029816; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LfVKdqV835QiWGlotzClIHLXhou0szKpLXr41gud1rg=; b=UjmhOgSSC8qNp2fm2MTul1sdbfod0OhcTQ6zCFqm8owOgVJjWoR5VTiYakc+fCq3/u9dDr u5+/tpsWDvpu04vfzI63dakPe0x2148kYkDhTKpcqtGvCbRXlfTqE/gCJImJwNerC5mM4N EV/W80/IypSajzSWnRm/TCAN/L35UvM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-108-klkNwiDcOvq8oCtfbHM4ig-1; Tue, 18 Feb 2020 07:43:35 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6008D800D50; Tue, 18 Feb 2020 12:43:34 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D317D5C1B2; Tue, 18 Feb 2020 12:43:33 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 15/33] block: Pull out bdrv_default_perms_for_backing() Date: Tue, 18 Feb 2020 13:42:24 +0100 Message-Id: <20200218124242.584644-16-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: klkNwiDcOvq8oCtfbHM4ig-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Right now, bdrv_format_default_perms() is used by format parents (generally). We want to switch to a model where most parents use a single BdrvChildClass, which then decides the permissions based on the child role. To do so, we have to split bdrv_format_default_perms() into separate functions for each such role. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 62 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/block.c b/block.c index 982785b15a..8b97412cbc 100644 --- a/block.c +++ b/block.c @@ -2302,6 +2302,44 @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, *nshared = (shared & DEFAULT_PERM_PASSTHROUGH) | DEFAULT_PERM_UNCHANGED; } +static void bdrv_default_perms_for_backing(BlockDriverState *bs, BdrvChild *c, + const BdrvChildClass *child_class, + BdrvChildRole role, + BlockReopenQueue *reopen_queue, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) +{ + assert(child_class == &child_backing || + (child_class == &child_of_bds && (role & BDRV_CHILD_COW))); + + /* + * We want consistent read from backing files if the parent needs it. + * No other operations are performed on backing files. + */ + perm &= BLK_PERM_CONSISTENT_READ; + + /* + * If the parent can deal with changing data, we're okay with a + * writable and resizable backing file. + * TODO Require !(perm & BLK_PERM_CONSISTENT_READ), too? + */ + if (shared & BLK_PERM_WRITE) { + shared = BLK_PERM_WRITE | BLK_PERM_RESIZE; + } else { + shared = 0; + } + + shared |= BLK_PERM_CONSISTENT_READ | BLK_PERM_GRAPH_MOD | + BLK_PERM_WRITE_UNCHANGED; + + if (bs->open_flags & BDRV_O_INACTIVE) { + shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE; + } + + *nperm = perm; + *nshared = shared; +} + void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, BdrvChildRole role, @@ -2339,28 +2377,8 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, *nperm = perm; *nshared = shared; } else { - /* We want consistent read from backing files if the parent needs it. - * No other operations are performed on backing files. */ - perm &= BLK_PERM_CONSISTENT_READ; - - /* If the parent can deal with changing data, we're okay with a - * writable and resizable backing file. */ - /* TODO Require !(perm & BLK_PERM_CONSISTENT_READ), too? */ - if (shared & BLK_PERM_WRITE) { - shared = BLK_PERM_WRITE | BLK_PERM_RESIZE; - } else { - shared = 0; - } - - shared |= BLK_PERM_CONSISTENT_READ | BLK_PERM_GRAPH_MOD | - BLK_PERM_WRITE_UNCHANGED; - - if (bs->open_flags & BDRV_O_INACTIVE) { - shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE; - } - - *nperm = perm; - *nshared = shared; + bdrv_default_perms_for_backing(bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); } } From patchwork Tue Feb 18 12:42:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388395 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7C00713A4 for ; Tue, 18 Feb 2020 12:56:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 538B02067D for ; Tue, 18 Feb 2020 12:56:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="W1bfpiZ+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 538B02067D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42QC-0001na-Fe for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:56:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39276) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42E8-0005eV-AP for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42E7-0001Xy-0g for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:48 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:53380 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42E6-0001Xf-Sc for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029826; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gArPcFvrgWgPAU5UnPYON1w06SOWCsg0NzSVFmmLTmI=; b=W1bfpiZ+vkgEHzpUt8WDPk39bltL/fQfP3UESByxGAc3vIhiF0SlwQWgr5b9jqc2EDdBvK wTQdDk49yYQrkZYhCmooavTU4bsu6/gW0RbEw31vSOcK5zVrmw9ldbOGnvBnPykxagd4Hr CUDiqSyrbXwjNkvj0Qx00GWnHwUiJoI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-97-E2tbPrHtOTyiCZhxTNASEA-1; Tue, 18 Feb 2020 07:43:38 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C5E9B18A5500; Tue, 18 Feb 2020 12:43:37 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F6A660C80; Tue, 18 Feb 2020 12:43:36 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 16/33] block: Pull out bdrv_default_perms_for_storage() Date: Tue, 18 Feb 2020 13:42:25 +0100 Message-Id: <20200218124242.584644-17-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: E2tbPrHtOTyiCZhxTNASEA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Right now, bdrv_format_default_perms() is used by format parents (generally). We want to switch to a model where most parents use a single BdrvChildClass, which then decides the permissions based on the child role. To do so, we have to split bdrv_format_default_perms() into separate functions for each such role. Note that bdrv_default_perms_for_storage() currently handles all DATA | METADATA children. A follow-up patch is going to split it further into one function for each case. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 71 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/block.c b/block.c index 8b97412cbc..64b5635122 100644 --- a/block.c +++ b/block.c @@ -2340,6 +2340,50 @@ static void bdrv_default_perms_for_backing(BlockDriverState *bs, BdrvChild *c, *nshared = shared; } +static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c, + const BdrvChildClass *child_class, + BdrvChildRole role, + BlockReopenQueue *reopen_queue, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) +{ + int flags; + + assert(child_class == &child_file || + (child_class == &child_of_bds && + (role & (BDRV_CHILD_METADATA | BDRV_CHILD_DATA)))); + + flags = bdrv_reopen_get_flags(reopen_queue, bs); + + /* + * Apart from the modifications below, the same permissions are + * forwarded and left alone as for filters + */ + bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, + perm, shared, &perm, &shared); + + /* Format drivers may touch metadata even if the guest doesn't write */ + if (bdrv_is_writable_after_reopen(bs, reopen_queue)) { + perm |= 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. + */ + if (!(flags & BDRV_O_NO_IO)) { + perm |= BLK_PERM_CONSISTENT_READ; + } + shared &= ~(BLK_PERM_WRITE | BLK_PERM_RESIZE); + + if (bs->open_flags & BDRV_O_INACTIVE) { + shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE; + } + + *nperm = perm; + *nshared = shared; +} + void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, BdrvChildRole role, @@ -2351,31 +2395,8 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, assert(child_class == &child_backing || child_class == &child_file); if (!backing) { - int flags = bdrv_reopen_get_flags(reopen_queue, bs); - - /* Apart from the modifications below, the same permissions are - * forwarded and left alone as for filters */ - bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, - perm, shared, &perm, &shared); - - /* Format drivers may touch metadata even if the guest doesn't write */ - if (bdrv_is_writable_after_reopen(bs, reopen_queue)) { - perm |= 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. */ - if (!(flags & BDRV_O_NO_IO)) { - perm |= BLK_PERM_CONSISTENT_READ; - } - shared &= ~(BLK_PERM_WRITE | BLK_PERM_RESIZE); - - if (bs->open_flags & BDRV_O_INACTIVE) { - shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE; - } - - *nperm = perm; - *nshared = shared; + bdrv_default_perms_for_storage(bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); } else { bdrv_default_perms_for_backing(bs, c, child_class, role, reopen_queue, perm, shared, nperm, nshared); From patchwork Tue Feb 18 12:42:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388373 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A5B00139A for ; Tue, 18 Feb 2020 12:50:52 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7B3262173E for ; Tue, 18 Feb 2020 12:50:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WWkSrUMl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7B3262173E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Kx-0000jz-L9 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:50:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39259) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42E7-0005bx-At for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42E5-0001WQ-VQ for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:47 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:45141 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42E5-0001W9-SD for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029825; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6kiqbqB6yqX1QsSKJvsQZ0438S46JzKxHIk0zsOKMyg=; b=WWkSrUMlnHq3EK52EafAqgYSmfRcgdEDEbf/+ZTIZi3zzL6bCyIy29TIZJGv2TTMogXYPh LC/08JhARKdG1bWvsOkPBrpCVuwpR7QkTeoU+zBulf0y5IL3nHiGIQpBEDN7dOgvwWOvSP eWxptE/ms3ou903J2r2j/M2A8bdJbAA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-235-lF7rPBwZMaaeGqQoL9G2LQ-1; Tue, 18 Feb 2020 07:43:41 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D5973800D50; Tue, 18 Feb 2020 12:43:40 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 51FAD5C1B2; Tue, 18 Feb 2020 12:43:39 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 17/33] block: Split bdrv_default_perms_for_storage() Date: Tue, 18 Feb 2020 13:42:26 +0100 Message-Id: <20200218124242.584644-18-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: lF7rPBwZMaaeGqQoL9G2LQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" We can be less restrictive about pure data children than those with metadata on them. For bdrv_format_default_perms(), we keep the safe option of bdrv_default_perms_for_metadata() (until we drop bdrv_format_default_perms() altogether). That means that bdrv_default_perms_for_data() is unused at this point. We will use it for all children that have the DATA role, but not the METADATA role. So far, no child has any role, so we do not use it, but that will change. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/block.c b/block.c index 64b5635122..c0ba274743 100644 --- a/block.c +++ b/block.c @@ -2340,18 +2340,17 @@ static void bdrv_default_perms_for_backing(BlockDriverState *bs, BdrvChild *c, *nshared = shared; } -static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, - BdrvChildRole role, - BlockReopenQueue *reopen_queue, - uint64_t perm, uint64_t shared, - uint64_t *nperm, uint64_t *nshared) +static void bdrv_default_perms_for_metadata(BlockDriverState *bs, BdrvChild *c, + const BdrvChildClass *child_class, + BdrvChildRole role, + BlockReopenQueue *reopen_queue, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) { int flags; assert(child_class == &child_file || - (child_class == &child_of_bds && - (role & (BDRV_CHILD_METADATA | BDRV_CHILD_DATA)))); + (child_class == &child_of_bds && (role & BDRV_CHILD_METADATA))); flags = bdrv_reopen_get_flags(reopen_queue, bs); @@ -2384,6 +2383,40 @@ static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c, *nshared = shared; } +/* TODO: Use */ +static void __attribute__((unused)) +bdrv_default_perms_for_data(BlockDriverState *bs, BdrvChild *c, + const BdrvChildClass *child_class, + BdrvChildRole role, + BlockReopenQueue *reopen_queue, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) +{ + assert(child_class == &child_of_bds && (role & BDRV_CHILD_DATA)); + + /* + * Apart from the modifications below, the same permissions are + * forwarded and left alone as for filters + */ + bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, + perm, shared, &perm, &shared); + + /* + * We cannot allow other users to resize the file because the + * format driver might have some assumptions about the size + * (e.g. because it is stored in metadata, or because the file is + * split into fixed-size data files). + */ + shared &= ~BLK_PERM_RESIZE; + + if (bs->open_flags & BDRV_O_INACTIVE) { + shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE; + } + + *nperm = perm; + *nshared = shared; +} + void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, BdrvChildRole role, @@ -2395,8 +2428,8 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, assert(child_class == &child_backing || child_class == &child_file); if (!backing) { - bdrv_default_perms_for_storage(bs, c, child_class, role, reopen_queue, - perm, shared, nperm, nshared); + bdrv_default_perms_for_metadata(bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); } else { bdrv_default_perms_for_backing(bs, c, child_class, role, reopen_queue, perm, shared, nperm, nshared); From patchwork Tue Feb 18 12:42:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388397 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 105A8139A for ; Tue, 18 Feb 2020 12:56:43 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DA95C2067D for ; Tue, 18 Feb 2020 12:56:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EhjeD6rq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA95C2067D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34132 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Qc-0002fd-2H for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:56:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39285) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42E8-0005fa-N3 for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42E7-0001YH-Cg for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:48 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:22957 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42E7-0001Xp-8Z for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029826; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=izpavJESRAm3sR19Ew5wdtfqWi7jEspf/lYr342uxIk=; b=EhjeD6rqakNOChTy/F7jSZ4j+OzCOlAnU8mDxNI4rrp0JXO3mzpXqEdk35EcyipFkcdGn4 rEbkdZMwEso6vWedVMcw/gdWoCm6ZCcDMZv+pkndJCCK1/bA1CTr9z3MoMA76PrTRfxa+3 tFSmU6fO09ZYSAJiAjg8mktfcHze2/I= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-272-8gQ0xmjsO6euVpIgEgKJUA-1; Tue, 18 Feb 2020 07:43:44 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 095AB100550E; Tue, 18 Feb 2020 12:43:44 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 71B53384; Tue, 18 Feb 2020 12:43:43 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 18/33] block: Add bdrv_default_perms() Date: Tue, 18 Feb 2020 13:42:27 +0100 Message-Id: <20200218124242.584644-19-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: 8gQ0xmjsO6euVpIgEgKJUA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This callback can be used by BDSs that use child_of_bds with the appropriate BdrvChildRole for their children. Also, make bdrv_format_default_perms() use it for child_of_bds children (just a temporary solution until we can drop bdrv_format_default_perms() altogether). Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 46 ++++++++++++++++++++++++++++++++------- include/block/block_int.h | 11 ++++++++++ 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/block.c b/block.c index c0ba274743..3e5b0bc345 100644 --- a/block.c +++ b/block.c @@ -2383,14 +2383,12 @@ static void bdrv_default_perms_for_metadata(BlockDriverState *bs, BdrvChild *c, *nshared = shared; } -/* TODO: Use */ -static void __attribute__((unused)) -bdrv_default_perms_for_data(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, - BdrvChildRole role, - BlockReopenQueue *reopen_queue, - uint64_t perm, uint64_t shared, - uint64_t *nperm, uint64_t *nshared) +static void bdrv_default_perms_for_data(BlockDriverState *bs, BdrvChild *c, + const BdrvChildClass *child_class, + BdrvChildRole role, + BlockReopenQueue *reopen_queue, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) { assert(child_class == &child_of_bds && (role & BDRV_CHILD_DATA)); @@ -2425,6 +2423,13 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, uint64_t *nperm, uint64_t *nshared) { bool backing = (child_class == &child_backing); + + if (child_class == &child_of_bds) { + bdrv_default_perms(bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); + return; + } + assert(child_class == &child_backing || child_class == &child_file); if (!backing) { @@ -2436,6 +2441,31 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, } } +void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c, + const BdrvChildClass *child_class, BdrvChildRole role, + BlockReopenQueue *reopen_queue, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) +{ + assert(child_class == &child_of_bds); + + if (role & BDRV_CHILD_FILTERED) { + bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); + } else if (role & BDRV_CHILD_COW) { + bdrv_default_perms_for_backing(bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); + } else if (role & BDRV_CHILD_METADATA) { + bdrv_default_perms_for_metadata(bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); + } else if (role & BDRV_CHILD_DATA) { + bdrv_default_perms_for_data(bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); + } else { + g_assert_not_reached(); + } +} + uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission qapi_perm) { static const uint64_t permissions[] = { diff --git a/include/block/block_int.h b/include/block/block_int.h index dd7ccea35e..d1d1af2a5c 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1279,6 +1279,17 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, bool bdrv_recurse_can_replace(BlockDriverState *bs, BlockDriverState *to_replace); +/* + * Default implementation for BlockDriver.bdrv_child_perm() that can + * be used by block filters and image formats, as long as they use the + * child_of_bds child class and set an appropriate BdrvChildRole. + */ +void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c, + const BdrvChildClass *child_class, BdrvChildRole role, + BlockReopenQueue *reopen_queue, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared); + /* * Default implementation for drivers to pass bdrv_co_block_status() to * their file. From patchwork Tue Feb 18 12:42:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388403 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F0E6413A4 for ; Tue, 18 Feb 2020 12:58:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C868F2067D for ; Tue, 18 Feb 2020 12:58:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PNbav2tp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C868F2067D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42SE-0006QP-U9 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:58:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39341) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42EB-0005nq-MZ for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42EA-0001aK-9r for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:51 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:44322 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42EA-0001a4-4o for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029829; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xVaEVxQpcVB7khDLriqwkmdJf1Jr1km4nzygAFTphb0=; b=PNbav2tpNHjxfyor3L8Gu2toE0052XjZoaKehETE/fy86Wpg/GlLmAjTGGCFsdAvSAZctJ N5nXWikBxqVNkeyYaIK64/K6O0W/t+bVFwkcVYbxuLYnwcVt2l7ENZCskkBiFj+3vZzrkg tTncxAEpa7BivqL6AnY9Ww2eocfrCVY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-316-1AuvUBq6Nr-pKSDFxvZTlA-1; Tue, 18 Feb 2020 07:43:48 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 16AD2100550E; Tue, 18 Feb 2020 12:43:47 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 87AD217DC8; Tue, 18 Feb 2020 12:43:46 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 19/33] raw-format: Split raw_read_options() Date: Tue, 18 Feb 2020 13:42:28 +0100 Message-Id: <20200218124242.584644-20-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: 1AuvUBq6Nr-pKSDFxvZTlA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Split raw_read_options() into one function that actually just reads the options, and another that applies them. This will allow us to detect whether the user has specified any options before attaching the file child (so we can decide on its role based on the options). Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block/raw-format.c | 110 ++++++++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 45 deletions(-) diff --git a/block/raw-format.c b/block/raw-format.c index b600dae209..33f5942474 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -71,20 +71,13 @@ static QemuOptsList raw_create_opts = { } }; -static int raw_read_options(QDict *options, BlockDriverState *bs, - BDRVRawState *s, Error **errp) +static int raw_read_options(QDict *options, uint64_t *offset, bool *has_size, + uint64_t *size, Error **errp) { Error *local_err = NULL; QemuOpts *opts = NULL; - int64_t real_size = 0; int ret; - real_size = bdrv_getlength(bs->file->bs); - if (real_size < 0) { - error_setg_errno(errp, -real_size, "Could not get image size"); - return real_size; - } - opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort); qemu_opts_absorb_qdict(opts, options, &local_err); if (local_err) { @@ -93,64 +86,84 @@ static int raw_read_options(QDict *options, BlockDriverState *bs, goto end; } - s->offset = qemu_opt_get_size(opts, "offset", 0); - if (s->offset > real_size) { - error_setg(errp, "Offset (%" PRIu64 ") cannot be greater than " - "size of the containing file (%" PRId64 ")", - s->offset, real_size); - ret = -EINVAL; - goto end; - } + *offset = qemu_opt_get_size(opts, "offset", 0); + *has_size = qemu_opt_find(opts, "size"); + *size = qemu_opt_get_size(opts, "size", 0); - if (qemu_opt_find(opts, "size") != NULL) { - s->size = qemu_opt_get_size(opts, "size", 0); - s->has_size = true; - } else { - s->has_size = false; - s->size = real_size - s->offset; + ret = 0; +end: + qemu_opts_del(opts); + return ret; +} + +static int raw_apply_options(BlockDriverState *bs, BDRVRawState *s, + uint64_t offset, bool has_size, uint64_t size, + Error **errp) +{ + int64_t real_size = 0; + + real_size = bdrv_getlength(bs->file->bs); + if (real_size < 0) { + error_setg_errno(errp, -real_size, "Could not get image size"); + return real_size; } /* Check size and offset */ - if ((real_size - s->offset) < s->size) { + if (offset > real_size) { + error_setg(errp, "Offset (%" PRIu64 ") cannot be greater than " + "size of the containing file (%" PRId64 ")", + s->offset, real_size); + return -EINVAL; + } + + if (has_size && (real_size - offset) < size) { error_setg(errp, "The sum of offset (%" PRIu64 ") and size " - "(%" PRIu64 ") has to be smaller or equal to the " - " actual size of the containing file (%" PRId64 ")", - s->offset, s->size, real_size); - ret = -EINVAL; - goto end; + "(%" PRIu64 ") has to be smaller or equal to the " + " actual size of the containing file (%" PRId64 ")", + s->offset, s->size, real_size); + return -EINVAL; } /* Make sure size is multiple of BDRV_SECTOR_SIZE to prevent rounding * up and leaking out of the specified area. */ - if (s->has_size && !QEMU_IS_ALIGNED(s->size, BDRV_SECTOR_SIZE)) { + if (has_size && !QEMU_IS_ALIGNED(size, BDRV_SECTOR_SIZE)) { error_setg(errp, "Specified size is not multiple of %llu", - BDRV_SECTOR_SIZE); - ret = -EINVAL; - goto end; + BDRV_SECTOR_SIZE); + return -EINVAL; } - ret = 0; - -end: + s->offset = offset; + s->has_size = has_size; + s->size = has_size ? size : real_size - offset; - qemu_opts_del(opts); - - return ret; + return 0; } static int raw_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, Error **errp) { + bool has_size; + uint64_t offset, size; + int ret; + assert(reopen_state != NULL); assert(reopen_state->bs != NULL); reopen_state->opaque = g_new0(BDRVRawState, 1); - return raw_read_options( - reopen_state->options, - reopen_state->bs, - reopen_state->opaque, - errp); + ret = raw_read_options(reopen_state->options, &offset, &has_size, &size, + errp); + if (ret < 0) { + return ret; + } + + ret = raw_apply_options(reopen_state->bs, reopen_state->opaque, + offset, has_size, size, errp); + if (ret < 0) { + return ret; + } + + return 0; } static void raw_reopen_commit(BDRVReopenState *state) @@ -429,8 +442,15 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { BDRVRawState *s = bs->opaque; + bool has_size; + uint64_t offset, size; int ret; + ret = raw_read_options(options, &offset, &has_size, &size, errp); + if (ret < 0) { + return ret; + } + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, errp); if (!bs->file) { @@ -456,7 +476,7 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, bs->file->bs->filename); } - ret = raw_read_options(options, bs, s, errp); + ret = raw_apply_options(bs, s, offset, has_size, size, errp); if (ret < 0) { return ret; } From patchwork Tue Feb 18 12:42:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388401 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 82ABC1580 for ; Tue, 18 Feb 2020 12:57:54 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 59D312067D for ; Tue, 18 Feb 2020 12:57:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NE4LyeRz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 59D312067D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Rl-0005ZS-H9 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:57:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39365) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42EE-0005wS-Nv for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42ED-0001by-O1 for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:54 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:59543) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42ED-0001bl-Ka for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029833; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5wu4P+OYuoR99HutDLk8Thy7By0AAkzOBY0tAknvND8=; b=NE4LyeRzv/zY3Y0D3lhre4VQXnWFcvmGmVFSfAzcn2f4jR3iIeH7PMJnz1YNqzfC+FbLdN 8/kyTAthnbNONY64v3xsQAVZN5rLb92wN1ObeXFVgHVkFfjRpSQ9zOu/nEX42EQecdgVrD MM3KFLWGLXEn+/JSnVlT+mIuKdnoGJ8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-17-VaKNiupOMJSxJ58bSNKtFQ-1; Tue, 18 Feb 2020 07:43:51 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6275B18A5500; Tue, 18 Feb 2020 12:43:50 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B847010001AE; Tue, 18 Feb 2020 12:43:49 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 20/33] block: Switch child_format users to child_of_bds Date: Tue, 18 Feb 2020 13:42:29 +0100 Message-Id: <20200218124242.584644-21-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: VaKNiupOMJSxJ58bSNKtFQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Both users (quorum and blkverify) use child_format for not-really-filtered children, so the appropriate BdrvChildRole in both cases is DATA. (Note that this will cause bdrv_inherited_options() to force-allow format probing.) Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block/blkverify.c | 4 ++-- block/quorum.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/block/blkverify.c b/block/blkverify.c index ba4f6d7b7c..1684b7aa2e 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -134,8 +134,8 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags, /* Open the test file */ s->test_file = bdrv_open_child(qemu_opt_get(opts, "x-image"), options, - "test", bs, &child_format, 0, false, - &local_err); + "test", bs, &child_of_bds, BDRV_CHILD_DATA, + false, &local_err); if (local_err) { ret = -EINVAL; error_propagate(errp, local_err); diff --git a/block/quorum.c b/block/quorum.c index d37b77a522..616ac3a927 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -977,7 +977,8 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, assert(ret < 32); s->children[i] = bdrv_open_child(NULL, options, indexstr, bs, - &child_format, 0, false, &local_err); + &child_of_bds, BDRV_CHILD_DATA, false, + &local_err); if (local_err) { ret = -EINVAL; goto close_exit; @@ -1053,7 +1054,8 @@ static void quorum_add_child(BlockDriverState *bs, BlockDriverState *child_bs, /* We can safely add the child now */ bdrv_ref(child_bs); - child = bdrv_attach_child(bs, child_bs, indexstr, &child_format, 0, errp); + child = bdrv_attach_child(bs, child_bs, indexstr, &child_of_bds, + BDRV_CHILD_DATA, errp); if (child == NULL) { s->next_child_index--; goto out; From patchwork Tue Feb 18 12:42:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388381 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 623D3139A for ; Tue, 18 Feb 2020 12:52:29 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 389CF20659 for ; Tue, 18 Feb 2020 12:52:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RtapTHcD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 389CF20659 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34050 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42MW-0003oq-CQ for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:52:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39391) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42EH-00065E-Qt for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42EG-0001dJ-N7 for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:57 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:21385 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42EG-0001d4-K5 for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:43:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029836; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9R9D82BvGJtOvztaohbyH9D3AYAi5Fj2oz0KyoS6kYw=; b=RtapTHcDOLNGlshRtC7bIwRESGFeZi/Wo2t9BQXYIq4u0p7Xr7M+3vpqwb+M49nhs2F1kM 022QONwgQGAbRkH0Zce15Fh/AZsihUCKhp/sLSpJkWHRALadqsHAylPbw/7aY26jsLIU7R JrcI19BEEsnldUAb+HAkQ3hvDX7cu1M= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-45-0V3k4Bf9PJS7pjWScHOfIQ-1; Tue, 18 Feb 2020 07:43:54 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8D03E8010E5; Tue, 18 Feb 2020 12:43:53 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0892060C80; Tue, 18 Feb 2020 12:43:52 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 21/33] block: Drop child_format Date: Tue, 18 Feb 2020 13:42:30 +0100 Message-Id: <20200218124242.584644-22-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: 0V3k4Bf9PJS7pjWScHOfIQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 29 ----------------------------- include/block/block_int.h | 1 - 2 files changed, 30 deletions(-) diff --git a/block.c b/block.c index 3e5b0bc345..43df38ca30 100644 --- a/block.c +++ b/block.c @@ -1148,35 +1148,6 @@ const BdrvChildClass child_file = { .set_aio_ctx = bdrv_child_cb_set_aio_ctx, }; -/* - * Returns the options and flags that bs->file should get if the use of formats - * (and not only protocols) is permitted for it, based on the given options and - * flags for the parent BDS - */ -static void bdrv_inherited_fmt_options(BdrvChildRole role, - bool parent_is_format, - int *child_flags, QDict *child_options, - int parent_flags, QDict *parent_options) -{ - bdrv_inherited_options(BDRV_CHILD_DATA, false, - child_flags, child_options, - parent_flags, parent_options); -} - -const BdrvChildClass child_format = { - .parent_is_bds = true, - .get_parent_desc = bdrv_child_get_parent_desc, - .inherit_options = bdrv_inherited_fmt_options, - .drained_begin = bdrv_child_cb_drained_begin, - .drained_poll = bdrv_child_cb_drained_poll, - .drained_end = bdrv_child_cb_drained_end, - .attach = bdrv_child_cb_attach, - .detach = bdrv_child_cb_detach, - .inactivate = bdrv_child_cb_inactivate, - .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx, - .set_aio_ctx = bdrv_child_cb_set_aio_ctx, -}; - static void bdrv_backing_attach(BdrvChild *c) { BlockDriverState *parent = c->opaque; diff --git a/include/block/block_int.h b/include/block/block_int.h index d1d1af2a5c..75139a95ae 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -742,7 +742,6 @@ struct BdrvChildClass { extern const BdrvChildClass child_of_bds; extern const BdrvChildClass child_file; -extern const BdrvChildClass child_format; extern const BdrvChildClass child_backing; struct BdrvChild { From patchwork Tue Feb 18 12:42:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388387 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3EB0B1395 for ; Tue, 18 Feb 2020 12:54:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1500520659 for ; Tue, 18 Feb 2020 12:54:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QXXW5ssv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1500520659 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42OB-0006Tu-7v for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:54:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39424) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42EQ-0006Jr-Ds for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42EM-0001gR-02 for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:06 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:30059 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42EL-0001gF-SW for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029841; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WfcYn3NPJfCa89MEqWlhaSxaTCgY1X4skqTlo4SozOU=; b=QXXW5ssvXu92AXG46Z4bc+Zr6wBEfkNMxqxGMM40VeS9SiQ6JnJloiAytqF/ITyIF4B0f4 i6eXP6x2n0o/sz0y/Au2b4IF5mZrc5DmY3BEYv5ZRrTt+yij15w6at2n68R7ds66XKoT9b sIIsbf/CIAR5x62kRcKtgcaTVrkQWvw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-332-pQ4GCu0qOPCvMrJp1D_nVg-1; Tue, 18 Feb 2020 07:43:57 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9E0C418A5508; Tue, 18 Feb 2020 12:43:56 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1D15F8B565; Tue, 18 Feb 2020 12:43:55 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 22/33] block: Make backing files child_of_bds children Date: Tue, 18 Feb 2020 13:42:31 +0100 Message-Id: <20200218124242.584644-23-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: pQ4GCu0qOPCvMrJp1D_nVg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Make all parents of backing files pass the appropriate BdrvChildRole. By doing so, we can switch their BdrvChildClass over to the generic child_of_bds, which will do the right thing when given a correct BdrvChildRole. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 26 ++++++++++++++++++++------ block/backup-top.c | 2 +- block/vvfat.c | 3 ++- tests/test-bdrv-drain.c | 13 +++++++------ 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/block.c b/block.c index 43df38ca30..31affcb4ee 100644 --- a/block.c +++ b/block.c @@ -2770,6 +2770,20 @@ static bool bdrv_inherits_from_recursive(BlockDriverState *child, return child != NULL; } +/* + * Return the BdrvChildRole for @bs's backing child. bs->backing is + * mostly used for COW backing children (role = COW), but also for + * filtered children (role = FILTERED | PRIMARY). + */ +static BdrvChildRole bdrv_backing_role(BlockDriverState *bs) +{ + if (bs->drv && bs->drv->is_filter) { + return BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY; + } else { + return BDRV_CHILD_COW; + } +} + /* * 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(). @@ -2797,8 +2811,8 @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, goto out; } - bs->backing = bdrv_attach_child(bs, backing_hd, "backing", &child_backing, - 0, errp); + bs->backing = bdrv_attach_child(bs, backing_hd, "backing", &child_of_bds, + bdrv_backing_role(bs), errp); /* If backing_hd was already part of bs's backing chain, and * inherits_from pointed recursively to bs then let's update it to * point directly to bs (else it will become NULL). */ @@ -2895,7 +2909,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options, } backing_hd = bdrv_open_inherit(backing_filename, reference, options, 0, bs, - &child_backing, 0, errp); + &child_of_bds, BDRV_CHILD_COW, errp); if (!backing_hd) { bs->open_flags |= BDRV_O_NO_BACKING; error_prepend(errp, "Could not open backing file: "); @@ -3731,8 +3745,8 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp) if (state->replace_backing_bs && state->new_backing_bs) { uint64_t nperm, nshared; bdrv_child_perm(state->bs, state->new_backing_bs, - NULL, &child_backing, 0, bs_queue, - state->perm, state->shared_perm, + NULL, &child_of_bds, bdrv_backing_role(state->bs), + bs_queue, state->perm, state->shared_perm, &nperm, &nshared); ret = bdrv_check_update_perm(state->new_backing_bs, NULL, nperm, nshared, NULL, NULL, errp); @@ -6679,7 +6693,7 @@ void bdrv_refresh_filename(BlockDriverState *bs) drv->bdrv_gather_child_options(bs, opts, backing_overridden); } else { QLIST_FOREACH(child, &bs->children, next) { - if (child->klass == &child_backing && !backing_overridden) { + if (child == bs->backing && !backing_overridden) { /* We can skip the backing BDS if it has not been overridden */ continue; } diff --git a/block/backup-top.c b/block/backup-top.c index 9dd89c2fde..c173e61250 100644 --- a/block/backup-top.c +++ b/block/backup-top.c @@ -142,7 +142,7 @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, return; } - if (child_class == &child_file) { + if (!(role & BDRV_CHILD_FILTERED)) { /* * Target child * diff --git a/block/vvfat.c b/block/vvfat.c index a945eeb635..8f4ff5a97e 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3221,7 +3221,8 @@ static void vvfat_child_perm(BlockDriverState *bs, BdrvChild *c, { BDRVVVFATState *s = bs->opaque; - assert(c == s->qcow || child_class == &child_backing); + assert(c == s->qcow || + (child_class == &child_of_bds && (role & BDRV_CHILD_COW))); if (c == s->qcow) { /* This is a private node, nobody should try to attach to it */ diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index b3d7960bd0..15393a0140 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -96,7 +96,7 @@ static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, * bdrv_format_default_perms() accepts only these two, so disguise * detach_by_driver_cb_parent as one of them. */ - if (child_class != &child_file && child_class != &child_backing) { + if (child_class != &child_file && child_class != &child_of_bds) { child_class = &child_file; } @@ -1399,8 +1399,8 @@ static void test_detach_indirect(bool by_parent_cb) bdrv_ref(a); child_b = bdrv_attach_child(parent_b, b, "PB-B", &child_file, 0, &error_abort); - child_a = bdrv_attach_child(parent_b, a, "PB-A", &child_backing, 0, - &error_abort); + child_a = bdrv_attach_child(parent_b, a, "PB-A", &child_of_bds, + BDRV_CHILD_COW, &error_abort); bdrv_ref(a); bdrv_attach_child(parent_a, a, "PA-A", @@ -1793,7 +1793,7 @@ static void test_drop_intermediate_poll(void) int i; int ret; - chain_child_class = child_backing; + chain_child_class = child_of_bds; chain_child_class.update_filename = drop_intermediate_poll_update_filename; for (i = 0; i < 3; i++) { @@ -1816,7 +1816,7 @@ static void test_drop_intermediate_poll(void) /* Takes the reference to chain[i - 1] */ chain[i]->backing = bdrv_attach_child(chain[i], chain[i - 1], "chain", &chain_child_class, - 0, &error_abort); + BDRV_CHILD_COW, &error_abort); } } @@ -2034,7 +2034,8 @@ static void do_test_replace_child_mid_drain(int old_drain_count, bdrv_ref(old_child_bs); parent_bs->backing = bdrv_attach_child(parent_bs, old_child_bs, "child", - &child_backing, 0, &error_abort); + &child_of_bds, BDRV_CHILD_COW, + &error_abort); for (i = 0; i < old_drain_count; i++) { bdrv_drained_begin(old_child_bs); From patchwork Tue Feb 18 12:42:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388405 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B5F9913A4 for ; Tue, 18 Feb 2020 12:59:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8C5632067D for ; Tue, 18 Feb 2020 12:59:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XJRStY6b" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8C5632067D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Tc-0000aS-Nl for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:59:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39442) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42ES-0006Ng-FA for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42ER-0001hh-78 for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:08 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:50647 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42ER-0001h4-3x for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029844; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Pqzr3KjSg9kvgeJy97iBRGIjIf4d6H7/OgxaNFvIJQg=; b=XJRStY6bWPwioMoKhudelD10RcA0Af5iKGveta2rlstFzDDAtxMMJ+7QaXhd7/wh2rmpqE z9O4Ii4IvYk10XfLF6V2P6ACchclPTEBG2Mrx+pwuqBul4DgMnn/S+cqsOqjxjfHpJPiTN EURZHcrRR6DBulVQ/9gyRhSJJq/fdvU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-148-YnGcoavaO_6M-vaVNwJ0AQ-1; Tue, 18 Feb 2020 07:44:00 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AEE5118A550B; Tue, 18 Feb 2020 12:43:59 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 295638B565; Tue, 18 Feb 2020 12:43:58 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 23/33] block: Drop child_backing Date: Tue, 18 Feb 2020 13:42:32 +0100 Message-Id: <20200218124242.584644-24-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: YnGcoavaO_6M-vaVNwJ0AQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 62 +++------------------------------------ include/block/block_int.h | 1 - 2 files changed, 4 insertions(+), 59 deletions(-) diff --git a/block.c b/block.c index 31affcb4ee..1f573f3815 100644 --- a/block.c +++ b/block.c @@ -1191,15 +1191,6 @@ static void bdrv_backing_attach(BdrvChild *c) parent->backing_blocker); } -/* XXX: Will be removed along with child_backing */ -static void bdrv_child_cb_attach_backing(BdrvChild *c) -{ - if (!(c->role & BDRV_CHILD_COW)) { - bdrv_backing_attach(c); - } - bdrv_child_cb_attach(c); -} - static void bdrv_backing_detach(BdrvChild *c) { BlockDriverState *parent = c->opaque; @@ -1210,28 +1201,6 @@ static void bdrv_backing_detach(BdrvChild *c) parent->backing_blocker = NULL; } -/* XXX: Will be removed along with child_backing */ -static void bdrv_child_cb_detach_backing(BdrvChild *c) -{ - if (!(c->role & BDRV_CHILD_COW)) { - bdrv_backing_detach(c); - } - bdrv_child_cb_detach(c); -} - -/* - * Returns the options and flags that bs->backing should get, based on the - * given options and flags for the parent BDS - */ -static void bdrv_backing_options(BdrvChildRole role, bool parent_is_format, - int *child_flags, QDict *child_options, - int parent_flags, QDict *parent_options) -{ - bdrv_inherited_options(BDRV_CHILD_COW, true, - child_flags, child_options, - parent_flags, parent_options); -} - static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base, const char *filename, Error **errp) { @@ -1259,21 +1228,6 @@ static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base, return ret; } -const BdrvChildClass child_backing = { - .parent_is_bds = true, - .get_parent_desc = bdrv_child_get_parent_desc, - .attach = bdrv_child_cb_attach_backing, - .detach = bdrv_child_cb_detach_backing, - .inherit_options = bdrv_backing_options, - .drained_begin = bdrv_child_cb_drained_begin, - .drained_poll = bdrv_child_cb_drained_poll, - .drained_end = bdrv_child_cb_drained_end, - .inactivate = bdrv_child_cb_inactivate, - .update_filename = bdrv_backing_update_filename, - .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx, - .set_aio_ctx = bdrv_child_cb_set_aio_ctx, -}; - static int bdrv_open_flags(BlockDriverState *bs, int flags) { int open_flags = flags; @@ -2280,8 +2234,7 @@ static void bdrv_default_perms_for_backing(BlockDriverState *bs, BdrvChild *c, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) { - assert(child_class == &child_backing || - (child_class == &child_of_bds && (role & BDRV_CHILD_COW))); + assert(child_class == &child_of_bds && (role & BDRV_CHILD_COW)); /* * We want consistent read from backing files if the parent needs it. @@ -2393,23 +2346,16 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) { - bool backing = (child_class == &child_backing); - if (child_class == &child_of_bds) { bdrv_default_perms(bs, c, child_class, role, reopen_queue, perm, shared, nperm, nshared); return; } - assert(child_class == &child_backing || child_class == &child_file); + assert(child_class == &child_file); - if (!backing) { - bdrv_default_perms_for_metadata(bs, c, child_class, role, reopen_queue, - perm, shared, nperm, nshared); - } else { - bdrv_default_perms_for_backing(bs, c, child_class, role, reopen_queue, - perm, shared, nperm, nshared); - } + bdrv_default_perms_for_metadata(bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); } void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c, diff --git a/include/block/block_int.h b/include/block/block_int.h index 75139a95ae..ab64a5ccea 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -742,7 +742,6 @@ struct BdrvChildClass { extern const BdrvChildClass child_of_bds; extern const BdrvChildClass child_file; -extern const BdrvChildClass child_backing; struct BdrvChild { BlockDriverState *bs; From patchwork Tue Feb 18 12:42:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388419 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 170AF930 for ; Tue, 18 Feb 2020 13:01:53 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D205521D56 for ; Tue, 18 Feb 2020 13:01:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hJSZUSkN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D205521D56 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34262 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Vb-0003KR-RE for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 08:01:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39473) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42EU-0006TT-TY for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42ET-0001is-6v for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:10 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:49004 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42ET-0001iK-3H for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029848; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9yjA9czqSvS3UWTFkQ6fAE9WaQRCJkehR+pElqvU+6o=; b=hJSZUSkN85DuWTks1HE2cNJtJnqREeOAIZ3TZCUQt+BBrEQeYaHsUNL+vV75uIRImbjZET 7ajFFCDWEKwaczunetIFzBgfhYr0F/fvgXqDpbXzSopwQOqTiCCxijfiRH3lg4X71DOqkn iM3TUuRK4Qz4+8KizyRyCA5sWYRry9M= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-222-QSgSPYEBPxmAWfLEV5pIGg-1; Tue, 18 Feb 2020 07:44:03 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EBBF78010F1; Tue, 18 Feb 2020 12:44:02 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3CFCD17DC8; Tue, 18 Feb 2020 12:44:01 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 24/33] block: Make format drivers use child_of_bds Date: Tue, 18 Feb 2020 13:42:33 +0100 Message-Id: <20200218124242.584644-25-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: QSgSPYEBPxmAWfLEV5pIGg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Commonly, they need to pass the BDRV_CHILD_IMAGE set as the BdrvChildRole; but there are exceptions for drivers with external data files (qcow2 and vmdk). Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block/bochs.c | 4 ++-- block/cloop.c | 4 ++-- block/crypto.c | 4 ++-- block/dmg.c | 4 ++-- block/parallels.c | 4 ++-- block/qcow.c | 4 ++-- block/qcow2.c | 19 +++++++++++++------ block/qed.c | 4 ++-- block/vdi.c | 4 ++-- block/vhdx.c | 4 ++-- block/vmdk.c | 20 +++++++++++++++++--- block/vpc.c | 4 ++-- 12 files changed, 50 insertions(+), 29 deletions(-) diff --git a/block/bochs.c b/block/bochs.c index b013e73063..62c3f42548 100644 --- a/block/bochs.c +++ b/block/bochs.c @@ -110,8 +110,8 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags, return ret; } - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_IMAGE, false, errp); if (!bs->file) { return -EINVAL; } diff --git a/block/cloop.c b/block/cloop.c index 3ed9fa63cc..d374a8427d 100644 --- a/block/cloop.c +++ b/block/cloop.c @@ -71,8 +71,8 @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags, return ret; } - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_IMAGE, false, errp); if (!bs->file) { return -EINVAL; } diff --git a/block/crypto.c b/block/crypto.c index 4da74a7737..2d85d9e70a 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -200,8 +200,8 @@ static int block_crypto_open_generic(QCryptoBlockFormat format, unsigned int cflags = 0; QDict *cryptoopts = NULL; - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_IMAGE, false, errp); if (!bs->file) { return -EINVAL; } diff --git a/block/dmg.c b/block/dmg.c index af8188638c..bc64194577 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -439,8 +439,8 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, return ret; } - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_IMAGE, false, errp); if (!bs->file) { return -EINVAL; } diff --git a/block/parallels.c b/block/parallels.c index 3d5b3b7c63..7dc9a1fa76 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -728,8 +728,8 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, Error *local_err = NULL; char *buf; - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_IMAGE, false, errp); if (!bs->file) { return -EINVAL; } diff --git a/block/qcow.c b/block/qcow.c index 2bf8e8eb36..bc7f7c1054 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -130,8 +130,8 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags, qdict_extract_subqdict(options, &encryptopts, "encrypt."); encryptfmt = qdict_get_try_str(encryptopts, "format"); - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_IMAGE, false, errp); if (!bs->file) { ret = -EINVAL; goto fail; diff --git a/block/qcow2.c b/block/qcow2.c index 2ce974df4d..7e1532cc5e 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1537,8 +1537,9 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, } /* Open external data file */ - s->data_file = bdrv_open_child(NULL, options, "data-file", bs, &child_file, - 0, true, &local_err); + s->data_file = bdrv_open_child(NULL, options, "data-file", bs, + &child_of_bds, BDRV_CHILD_DATA, + true, &local_err); if (local_err) { error_propagate(errp, local_err); ret = -EINVAL; @@ -1548,8 +1549,8 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, if (s->incompatible_features & QCOW2_INCOMPAT_DATA_FILE) { if (!s->data_file && s->image_data_file) { s->data_file = bdrv_open_child(s->image_data_file, options, - "data-file", bs, &child_file, 0, - false, errp); + "data-file", bs, &child_of_bds, + BDRV_CHILD_DATA, false, errp); if (!s->data_file) { ret = -EINVAL; goto fail; @@ -1560,6 +1561,12 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, ret = -EINVAL; goto fail; } + + /* No data here */ + bs->file->role &= ~BDRV_CHILD_DATA; + + /* Must succeed because we have given up permissions if anything */ + bdrv_child_refresh_perms(bs, bs->file, &error_abort); } else { if (s->data_file) { error_setg(errp, "'data-file' can only be set for images with an " @@ -1808,8 +1815,8 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, .ret = -EINPROGRESS }; - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_IMAGE, false, errp); if (!bs->file) { return -EINVAL; } diff --git a/block/qed.c b/block/qed.c index d15ba11959..d6222798c2 100644 --- a/block/qed.c +++ b/block/qed.c @@ -547,8 +547,8 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags, .ret = -EINPROGRESS }; - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_IMAGE, false, errp); if (!bs->file) { return -EINVAL; } diff --git a/block/vdi.c b/block/vdi.c index 987e2ed592..1736d02eee 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -378,8 +378,8 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, Error *local_err = NULL; QemuUUID uuid_link, uuid_parent; - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_IMAGE, false, errp); if (!bs->file) { return -EINVAL; } diff --git a/block/vhdx.c b/block/vhdx.c index be23290ac8..d8a315015d 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -997,8 +997,8 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags, uint64_t signature; Error *local_err = NULL; - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_IMAGE, false, errp); if (!bs->file) { return -EINVAL; } diff --git a/block/vmdk.c b/block/vmdk.c index 84f99d881f..497414e5f2 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1089,6 +1089,7 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, char *desc_file_dir = NULL; char *extent_path; BdrvChild *extent_file; + BdrvChildRole extent_role; BDRVVmdkState *s = bs->opaque; VmdkExtent *extent; char extent_opt_prefix[32]; @@ -1151,8 +1152,15 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, ret = snprintf(extent_opt_prefix, 32, "extents.%d", s->num_extents); assert(ret < 32); + extent_role = BDRV_CHILD_DATA; + if (strcmp(type, "FLAT") != 0 && strcmp(type, "VMFS") != 0) { + /* non-flat extents have metadata */ + extent_role |= BDRV_CHILD_METADATA; + } + extent_file = bdrv_open_child(extent_path, options, extent_opt_prefix, - bs, &child_file, 0, false, &local_err); + bs, &child_of_bds, extent_role, false, + &local_err); g_free(extent_path); if (local_err) { error_propagate(errp, local_err); @@ -1257,8 +1265,8 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags, uint32_t magic; Error *local_err = NULL; - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_IMAGE, false, errp); if (!bs->file) { return -EINVAL; } @@ -1277,6 +1285,12 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags, s->desc_offset = 0x200; break; default: + /* No data in the descriptor file */ + bs->file->role &= ~BDRV_CHILD_DATA; + + /* Must succeed because we have given up permissions if anything */ + bdrv_child_refresh_perms(bs, bs->file, &error_abort); + ret = vmdk_open_desc_file(bs, flags, buf, options, errp); break; } diff --git a/block/vpc.c b/block/vpc.c index 5378e32d1d..9acd6edac9 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -228,8 +228,8 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, int ret; int64_t bs_size; - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_IMAGE, false, errp); if (!bs->file) { return -EINVAL; } From patchwork Tue Feb 18 12:42:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388393 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 18BA513A4 for ; Tue, 18 Feb 2020 12:56:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E380020659 for ; Tue, 18 Feb 2020 12:56:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cbrh8GlF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E380020659 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Q4-0001RC-24 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:56:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39470) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42EU-0006Sj-J3 for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42ET-0001ik-4U for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:10 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:35904 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42ET-0001iG-0G for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029848; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p7sit8l2Ncd92nNS9DBTcJjUaipuRLXI3sHVoyodYYQ=; b=cbrh8GlFSis5tq1qubHv+S8loEaPLxerIw4kwCONWTA9lAsBCLi6tyQuDl4sFXKOCFGqq4 Lm0oKNJHEzPiCw7q1TKGp+FVzCqj4uIqcB0uGKti2PFLx/54nWQlnTvonetHsrt/4mq9Kz xGR9FzhZABw/HLQs1IdrYNWNPSHt7A8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-346-rYf_29ooOZiM_t5OYKVeLw-1; Tue, 18 Feb 2020 07:44:07 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2650A1005514; Tue, 18 Feb 2020 12:44:06 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 923445DA60; Tue, 18 Feb 2020 12:44:05 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 25/33] block: Make filter drivers use child_of_bds Date: Tue, 18 Feb 2020 13:42:34 +0100 Message-Id: <20200218124242.584644-26-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: rYf_29ooOZiM_t5OYKVeLw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Note that some filters have secondary children, namely blkverify (the image to be verified) and blklogwrites (the log). This patch does not touch those children. Note that for blkverify, the filtered child should not be format-probed. While there is nothing enforcing this here, in practice, it will not be: blkverify implements .bdrv_file_open. The block layer ensures (and in fact, asserts) that BDRV_O_PROTOCOL is set for every BDS whose driver implements .bdrv_file_open. This flag will then be bequeathed to blkverify's children, and they will thus (by default) not be probed either. ("By default" refers to the fact that blkverify's other child (the non-filtered one) will have BDRV_O_PROTOCOL force-unset, because that is what happens for all non-filtered children of non-format drivers.) Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block/blkdebug.c | 4 +++- block/blklogwrites.c | 3 ++- block/blkverify.c | 4 +++- block/copy-on-read.c | 5 +++-- block/filter-compress.c | 5 +++-- block/replication.c | 3 ++- block/throttle.c | 5 +++-- 7 files changed, 19 insertions(+), 10 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index 8dd8ed6055..b31fa40b0e 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -497,7 +497,9 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags, /* Open the image file */ bs->file = bdrv_open_child(qemu_opt_get(opts, "x-image"), options, "image", - bs, &child_file, 0, false, &local_err); + bs, &child_of_bds, + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, + false, &local_err); if (local_err) { ret = -EINVAL; error_propagate(errp, local_err); diff --git a/block/blklogwrites.c b/block/blklogwrites.c index 4faf912ef1..78b0c49460 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -157,7 +157,8 @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags, } /* Open the file */ - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, false, &local_err); if (local_err) { ret = -EINVAL; diff --git a/block/blkverify.c b/block/blkverify.c index 1684b7aa2e..5c3b29244a 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -125,7 +125,9 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags, /* Open the raw file */ bs->file = bdrv_open_child(qemu_opt_get(opts, "x-raw"), options, "raw", - bs, &child_file, 0, false, &local_err); + bs, &child_of_bds, + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, + false, &local_err); if (local_err) { ret = -EINVAL; error_propagate(errp, local_err); diff --git a/block/copy-on-read.c b/block/copy-on-read.c index a2d92ac394..c857ea0da7 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -28,8 +28,9 @@ static int cor_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, - errp); + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, + false, errp); if (!bs->file) { return -EINVAL; } diff --git a/block/filter-compress.c b/block/filter-compress.c index 4dc5f9fb8c..9edd937645 100644 --- a/block/filter-compress.c +++ b/block/filter-compress.c @@ -30,8 +30,9 @@ static int compress_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, - errp); + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, + false, errp); if (!bs->file) { return -EINVAL; } diff --git a/block/replication.c b/block/replication.c index 9ca5c9368e..ec512ae1c3 100644 --- a/block/replication.c +++ b/block/replication.c @@ -90,7 +90,8 @@ static int replication_open(BlockDriverState *bs, QDict *options, const char *mode; const char *top_id; - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, false, errp); if (!bs->file) { return -EINVAL; diff --git a/block/throttle.c b/block/throttle.c index 2dea913be7..47b0a3522d 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -81,8 +81,9 @@ static int throttle_open(BlockDriverState *bs, QDict *options, char *group; int ret; - bs->file = bdrv_open_child(NULL, options, "file", bs, - &child_file, 0, false, errp); + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, + false, errp); if (!bs->file) { return -EINVAL; } From patchwork Tue Feb 18 12:42:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388399 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 75C681580 for ; Tue, 18 Feb 2020 12:57:44 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4C6F82067D for ; Tue, 18 Feb 2020 12:57:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WQ848UcY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4C6F82067D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34153 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Rb-0005F0-Fj for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:57:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39502) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42EY-0006bv-5U for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42EW-0001kq-PU for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:14 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:44358 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42EW-0001kd-LR for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029852; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Mme04VKWjkqGlQi0dEDqTcpaqBw2ccPp0V4B4+kS2mU=; b=WQ848UcYDFXvhpjqhwYNNhYkDxO5la4KmeGEqlqzus82bcFv86yCaZxOxfCdr9F6axEh8/ 11Ai/78oFo2Ju+OWgLqeu94HBZ96ZgCMzaOTALwX4lbLZe4uScL69AfGx6keDIp/Y8zLW0 /wmZ9LHhCyD7GVDVFZdCYrNpLsNl+wA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-315-viTWG9wMOa-5t_rKf5FPyg-1; Tue, 18 Feb 2020 07:44:10 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 34E10107ACC9; Tue, 18 Feb 2020 12:44:09 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A886517DC8; Tue, 18 Feb 2020 12:44:08 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 26/33] block: Use child_of_bds in remaining places Date: Tue, 18 Feb 2020 13:42:35 +0100 Message-Id: <20200218124242.584644-27-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: viTWG9wMOa-5t_rKf5FPyg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Replace child_file by child_of_bds in all remaining places (excluding tests). Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 3 ++- block/backup-top.c | 4 ++-- block/blklogwrites.c | 4 ++-- block/blkreplay.c | 5 +++-- block/raw-format.c | 15 +++++++++++++-- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/block.c b/block.c index 1f573f3815..d3beed1819 100644 --- a/block.c +++ b/block.c @@ -3242,7 +3242,8 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, BlockDriverState *file_bs; file_bs = bdrv_open_child_bs(filename, options, "file", bs, - &child_file, 0, true, &local_err); + &child_of_bds, BDRV_CHILD_IMAGE, + true, &local_err); if (local_err) { goto fail; } diff --git a/block/backup-top.c b/block/backup-top.c index c173e61250..3d6f6530a2 100644 --- a/block/backup-top.c +++ b/block/backup-top.c @@ -210,8 +210,8 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source, source->supported_zero_flags); bdrv_ref(target); - state->target = bdrv_attach_child(top, target, "target", &child_file, 0, - errp); + state->target = bdrv_attach_child(top, target, "target", &child_of_bds, + BDRV_CHILD_DATA, errp); if (!state->target) { bdrv_unref(target); bdrv_unref(top); diff --git a/block/blklogwrites.c b/block/blklogwrites.c index 78b0c49460..3a57b273fc 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -167,8 +167,8 @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags, } /* Open the log file */ - s->log_file = bdrv_open_child(NULL, options, "log", bs, &child_file, 0, - false, &local_err); + s->log_file = bdrv_open_child(NULL, options, "log", bs, &child_of_bds, + BDRV_CHILD_METADATA, false, &local_err); if (local_err) { ret = -EINVAL; error_propagate(errp, local_err); diff --git a/block/blkreplay.c b/block/blkreplay.c index f97493f45a..71628f4d56 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -27,8 +27,9 @@ static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags, int ret; /* Open the image file */ - bs->file = bdrv_open_child(NULL, options, "image", - bs, &child_file, 0, false, &local_err); + bs->file = bdrv_open_child(NULL, options, "image", bs, &child_of_bds, + BDRV_CHILD_DATA | BDRV_CHILD_PRIMARY, + false, &local_err); if (local_err) { ret = -EINVAL; error_propagate(errp, local_err); diff --git a/block/raw-format.c b/block/raw-format.c index 33f5942474..c6470e4622 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -444,6 +444,7 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, BDRVRawState *s = bs->opaque; bool has_size; uint64_t offset, size; + BdrvChildRole file_role; int ret; ret = raw_read_options(options, &offset, &has_size, &size, errp); @@ -451,8 +452,18 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, return ret; } - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + /* + * Without offset and a size limit, this driver behaves very much + * like a filter. With any such limit, it does not. + */ + if (offset || has_size) { + file_role = BDRV_CHILD_DATA | BDRV_CHILD_PRIMARY; + } else { + file_role = BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY; + } + + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + file_role, false, errp); if (!bs->file) { return -EINVAL; } From patchwork Tue Feb 18 12:42:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388423 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6225D930 for ; Tue, 18 Feb 2020 13:04:15 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 39E212176D for ; Tue, 18 Feb 2020 13:04:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZPfw4Uxo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 39E212176D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Xu-0007Ff-Ej for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 08:04:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39571) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Eg-0006wU-1l for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42Ec-0001nM-4L for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:21 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:36254 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42Eb-0001my-VR for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IEYzWw3bUg1sVN29KbqYf/PTEHjMqvkLnFulM3okASA=; b=ZPfw4Uxo7zdO+rZV6kNH9e96mtGDS/zcDn/ExytdWHWZDh8g3js/F0QI267ULF7lFUfCyb GEgspsXcbhMJf00ri/0gZ3ML2gBzMVVScr1UBiWLNhjN0gXPwd8y3IwKBEd9AACBdc2cT4 EIl7YztdA4GU9qkIl1iF0CR7zqOfE+Q= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-290-UMGcZJgWMQKLEt1KQB_PNQ-1; Tue, 18 Feb 2020 07:44:13 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4368813E5; Tue, 18 Feb 2020 12:44:12 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B55031001281; Tue, 18 Feb 2020 12:44:11 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 27/33] tests: Use child_of_bds instead of child_file Date: Tue, 18 Feb 2020 13:42:36 +0100 Message-Id: <20200218124242.584644-28-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: UMGcZJgWMQKLEt1KQB_PNQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- tests/test-bdrv-drain.c | 29 +++++++++++++++++------------ tests/test-bdrv-graph-mod.c | 6 ++++-- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index 15393a0140..91567ca97d 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -97,7 +97,7 @@ static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, * detach_by_driver_cb_parent as one of them. */ if (child_class != &child_file && child_class != &child_of_bds) { - child_class = &child_file; + child_class = &child_of_bds; } bdrv_format_default_perms(bs, c, child_class, role, reopen_queue, @@ -1203,7 +1203,8 @@ static void do_test_delete_by_drain(bool detach_instead_of_delete, null_bs = bdrv_open("null-co://", NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL, &error_abort); - bdrv_attach_child(bs, null_bs, "null-child", &child_file, 0, &error_abort); + bdrv_attach_child(bs, null_bs, "null-child", &child_of_bds, + BDRV_CHILD_DATA, &error_abort); /* This child will be the one to pass to requests through to, and * it will stall until a drain occurs */ @@ -1211,14 +1212,17 @@ static void do_test_delete_by_drain(bool detach_instead_of_delete, &error_abort); child_bs->total_sectors = 65536 >> BDRV_SECTOR_BITS; /* Takes our reference to child_bs */ - tts->wait_child = bdrv_attach_child(bs, child_bs, "wait-child", &child_file, - 0, &error_abort); + tts->wait_child = bdrv_attach_child(bs, child_bs, "wait-child", + &child_of_bds, + BDRV_CHILD_DATA | BDRV_CHILD_PRIMARY, + &error_abort); /* This child is just there to be deleted * (for detach_instead_of_delete == true) */ null_bs = bdrv_open("null-co://", NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL, &error_abort); - bdrv_attach_child(bs, null_bs, "null-child", &child_file, 0, &error_abort); + bdrv_attach_child(bs, null_bs, "null-child", &child_of_bds, BDRV_CHILD_DATA, + &error_abort); blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); blk_insert_bs(blk, bs, &error_abort); @@ -1315,7 +1319,8 @@ static void detach_indirect_bh(void *opaque) bdrv_ref(data->c); data->child_c = bdrv_attach_child(data->parent_b, data->c, "PB-C", - &child_file, 0, &error_abort); + &child_of_bds, BDRV_CHILD_DATA, + &error_abort); } static void detach_by_parent_aio_cb(void *opaque, int ret) @@ -1332,7 +1337,7 @@ static void detach_by_driver_cb_drained_begin(BdrvChild *child) { aio_bh_schedule_oneshot(qemu_get_current_aio_context(), detach_indirect_bh, &detach_by_parent_data); - child_file.drained_begin(child); + child_of_bds.drained_begin(child); } static BdrvChildClass detach_by_driver_cb_class; @@ -1367,7 +1372,7 @@ static void test_detach_indirect(bool by_parent_cb) QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, NULL, 0); if (!by_parent_cb) { - detach_by_driver_cb_class = child_file; + detach_by_driver_cb_class = child_of_bds; detach_by_driver_cb_class.drained_begin = detach_by_driver_cb_drained_begin; } @@ -1397,15 +1402,15 @@ static void test_detach_indirect(bool by_parent_cb) /* Set child relationships */ bdrv_ref(b); bdrv_ref(a); - child_b = bdrv_attach_child(parent_b, b, "PB-B", &child_file, 0, - &error_abort); + child_b = bdrv_attach_child(parent_b, b, "PB-B", &child_of_bds, + BDRV_CHILD_DATA, &error_abort); child_a = bdrv_attach_child(parent_b, a, "PB-A", &child_of_bds, BDRV_CHILD_COW, &error_abort); bdrv_ref(a); bdrv_attach_child(parent_a, a, "PA-A", - by_parent_cb ? &child_file : &detach_by_driver_cb_class, - 0, &error_abort); + by_parent_cb ? &child_of_bds : &detach_by_driver_cb_class, + BDRV_CHILD_DATA, &error_abort); g_assert_cmpint(parent_a->refcnt, ==, 1); g_assert_cmpint(parent_b->refcnt, ==, 1); diff --git a/tests/test-bdrv-graph-mod.c b/tests/test-bdrv-graph-mod.c index 3707e2533c..6ae91ff171 100644 --- a/tests/test-bdrv-graph-mod.c +++ b/tests/test-bdrv-graph-mod.c @@ -112,7 +112,8 @@ static void test_update_perm_tree(void) blk_insert_bs(root, bs, &error_abort); - bdrv_attach_child(filter, bs, "child", &child_file, 0, &error_abort); + bdrv_attach_child(filter, bs, "child", &child_of_bds, + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, &error_abort); bdrv_append(filter, bs, &local_err); @@ -178,7 +179,8 @@ static void test_should_update_child(void) bdrv_set_backing_hd(target, bs, &error_abort); g_assert(target->backing->bs == bs); - bdrv_attach_child(filter, target, "target", &child_file, 0, &error_abort); + bdrv_attach_child(filter, target, "target", &child_of_bds, + BDRV_CHILD_DATA, &error_abort); bdrv_append(filter, bs, &error_abort); g_assert(target->backing->bs == bs); From patchwork Tue Feb 18 12:42:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388425 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 32675930 for ; Tue, 18 Feb 2020 13:06:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ED6272176D for ; Tue, 18 Feb 2020 13:06:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LyhC/znN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ED6272176D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Zs-0001RM-61 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 08:06:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39597) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Ei-00073X-QX for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42Ef-0001oq-ER for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:24 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:39699 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42Ef-0001ob-9h for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029860; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qA/7qS4JP1GxbM4FFcuj6PVmhReNCrhh+IXMxb/ir20=; b=LyhC/znNEQwp9kxCPL9WqJbvEYFdjpSQVzZyVbtSUk+mLJgWXooxJpQxeKgcjVYW+njYl+ E48hw1mGRI2F0oQPas7pMyltm8irSVlTCkM79vTE0pBVEG0Pwfxpi8RaUCoOxUJQEN8JRh /JjI92t5PfyMs8we4jvWKBTRav5WfKw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-228-zvn9Kk1NORSLFbxk8BflSw-1; Tue, 18 Feb 2020 07:44:17 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1C24A1005513; Tue, 18 Feb 2020 12:44:16 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0B0CF1BC6D; Tue, 18 Feb 2020 12:44:14 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 28/33] block: Use bdrv_default_perms() Date: Tue, 18 Feb 2020 13:42:37 +0100 Message-Id: <20200218124242.584644-29-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: zvn9Kk1NORSLFbxk8BflSw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" bdrv_default_perms() can decide which permission profile to use based on the BdrvChildRole, so block drivers do not need to select it explicitly. The blkverify driver now no longer shares the WRITE permission for the image to verify. We thus have to adjust two places in test-block-iothread not to take it. (Note that in theory, blkverify should behave like quorum in this regard and share neither WRITE nor RESIZE for both of its children. In practice, it does not really matter, because blkverify is used only for debugging, so we might as well keep its permissions rather liberal.) Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block/backup-top.c | 4 ++-- block/blkdebug.c | 4 ++-- block/blklogwrites.c | 9 ++------- block/blkreplay.c | 2 +- block/blkverify.c | 2 +- block/bochs.c | 2 +- block/cloop.c | 2 +- block/crypto.c | 2 +- block/dmg.c | 2 +- block/filter-compress.c | 2 +- block/parallels.c | 2 +- block/qcow.c | 2 +- block/qcow2.c | 2 +- block/qed.c | 2 +- block/raw-format.c | 2 +- block/throttle.c | 2 +- block/vdi.c | 2 +- block/vhdx.c | 2 +- block/vmdk.c | 2 +- block/vpc.c | 2 +- tests/test-bdrv-drain.c | 10 +++++----- tests/test-bdrv-graph-mod.c | 2 +- tests/test-block-iothread.c | 17 ++++++++++++++--- 23 files changed, 43 insertions(+), 37 deletions(-) diff --git a/block/backup-top.c b/block/backup-top.c index 3d6f6530a2..00dbad44b5 100644 --- a/block/backup-top.c +++ b/block/backup-top.c @@ -153,8 +153,8 @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, *nperm = BLK_PERM_WRITE; } else { /* Source child */ - bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, - perm, shared, nperm, nshared); + bdrv_default_perms(bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); if (perm & BLK_PERM_WRITE) { *nperm = *nperm | BLK_PERM_CONSISTENT_READ; diff --git a/block/blkdebug.c b/block/blkdebug.c index b31fa40b0e..a925d8295e 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -1003,8 +1003,8 @@ static void blkdebug_child_perm(BlockDriverState *bs, BdrvChild *c, { BDRVBlkdebugState *s = bs->opaque; - bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, - perm, shared, nperm, nshared); + bdrv_default_perms(bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); *nperm |= s->take_child_perms; *nshared &= ~s->unshare_child_perms; diff --git a/block/blklogwrites.c b/block/blklogwrites.c index 3a57b273fc..8684fb1c74 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -295,13 +295,8 @@ static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, return; } - if (!strcmp(c->name, "log")) { - bdrv_format_default_perms(bs, c, child_class, role, ro_q, perm, shrd, - nperm, nshrd); - } else { - bdrv_filter_default_perms(bs, c, child_class, role, ro_q, perm, shrd, - nperm, nshrd); - } + bdrv_default_perms(bs, c, child_class, role, ro_q, perm, shrd, + nperm, nshrd); } static void blk_log_writes_refresh_limits(BlockDriverState *bs, Error **errp) diff --git a/block/blkreplay.c b/block/blkreplay.c index 71628f4d56..be8cdb6b60 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -138,7 +138,7 @@ static BlockDriver bdrv_blkreplay = { .instance_size = 0, .bdrv_open = blkreplay_open, - .bdrv_child_perm = bdrv_filter_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_getlength = blkreplay_getlength, .bdrv_co_preadv = blkreplay_co_preadv, diff --git a/block/blkverify.c b/block/blkverify.c index 5c3b29244a..2f261de24b 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -319,7 +319,7 @@ static BlockDriver bdrv_blkverify = { .bdrv_parse_filename = blkverify_parse_filename, .bdrv_file_open = blkverify_open, .bdrv_close = blkverify_close, - .bdrv_child_perm = bdrv_filter_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_getlength = blkverify_getlength, .bdrv_refresh_filename = blkverify_refresh_filename, .bdrv_dirname = blkverify_dirname, diff --git a/block/bochs.c b/block/bochs.c index 62c3f42548..2f010ab40a 100644 --- a/block/bochs.c +++ b/block/bochs.c @@ -297,7 +297,7 @@ static BlockDriver bdrv_bochs = { .instance_size = sizeof(BDRVBochsState), .bdrv_probe = bochs_probe, .bdrv_open = bochs_open, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_refresh_limits = bochs_refresh_limits, .bdrv_co_preadv = bochs_co_preadv, .bdrv_close = bochs_close, diff --git a/block/cloop.c b/block/cloop.c index d374a8427d..c99192a57f 100644 --- a/block/cloop.c +++ b/block/cloop.c @@ -293,7 +293,7 @@ static BlockDriver bdrv_cloop = { .instance_size = sizeof(BDRVCloopState), .bdrv_probe = cloop_probe, .bdrv_open = cloop_open, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_refresh_limits = cloop_refresh_limits, .bdrv_co_preadv = cloop_co_preadv, .bdrv_close = cloop_close, diff --git a/block/crypto.c b/block/crypto.c index 2d85d9e70a..474f44b5db 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -659,7 +659,7 @@ static BlockDriver bdrv_crypto_luks = { .bdrv_close = block_crypto_close, /* This driver doesn't modify LUKS metadata except when creating image. * Allow share-rw=on as a special case. */ - .bdrv_child_perm = bdrv_filter_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_create = block_crypto_co_create_luks, .bdrv_co_create_opts = block_crypto_co_create_opts_luks, .bdrv_co_truncate = block_crypto_co_truncate, diff --git a/block/dmg.c b/block/dmg.c index bc64194577..0d6c317296 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -750,7 +750,7 @@ static BlockDriver bdrv_dmg = { .bdrv_probe = dmg_probe, .bdrv_open = dmg_open, .bdrv_refresh_limits = dmg_refresh_limits, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_preadv = dmg_co_preadv, .bdrv_close = dmg_close, .is_format = true, diff --git a/block/filter-compress.c b/block/filter-compress.c index 9edd937645..8ec1991c1f 100644 --- a/block/filter-compress.c +++ b/block/filter-compress.c @@ -133,7 +133,7 @@ static BlockDriver bdrv_compress = { .format_name = "compress", .bdrv_open = compress_open, - .bdrv_child_perm = bdrv_filter_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_getlength = compress_getlength, diff --git a/block/parallels.c b/block/parallels.c index 7dc9a1fa76..452d6dbfab 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -904,7 +904,7 @@ static BlockDriver bdrv_parallels = { .bdrv_probe = parallels_probe, .bdrv_open = parallels_open, .bdrv_close = parallels_close, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_block_status = parallels_co_block_status, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_co_flush_to_os = parallels_co_flush_to_os, diff --git a/block/qcow.c b/block/qcow.c index bc7f7c1054..f4219d9d56 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -1179,7 +1179,7 @@ static BlockDriver bdrv_qcow = { .bdrv_probe = qcow_probe, .bdrv_open = qcow_open, .bdrv_close = qcow_close, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_reopen_prepare = qcow_reopen_prepare, .bdrv_co_create = qcow_co_create, .bdrv_co_create_opts = qcow_co_create_opts, diff --git a/block/qcow2.c b/block/qcow2.c index 7e1532cc5e..cdcd544837 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -5543,7 +5543,7 @@ BlockDriver bdrv_qcow2 = { .bdrv_reopen_commit = qcow2_reopen_commit, .bdrv_reopen_abort = qcow2_reopen_abort, .bdrv_join_options = qcow2_join_options, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_create_opts = qcow2_co_create_opts, .bdrv_co_create = qcow2_co_create, .bdrv_has_zero_init = qcow2_has_zero_init, diff --git a/block/qed.c b/block/qed.c index d6222798c2..08c63f1378 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1670,7 +1670,7 @@ static BlockDriver bdrv_qed = { .bdrv_open = bdrv_qed_open, .bdrv_close = bdrv_qed_close, .bdrv_reopen_prepare = bdrv_qed_reopen_prepare, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_create = bdrv_qed_co_create, .bdrv_co_create_opts = bdrv_qed_co_create_opts, .bdrv_has_zero_init = bdrv_has_zero_init_1, diff --git a/block/raw-format.c b/block/raw-format.c index c6470e4622..87a6e3303d 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -587,7 +587,7 @@ BlockDriver bdrv_raw = { .bdrv_reopen_commit = &raw_reopen_commit, .bdrv_reopen_abort = &raw_reopen_abort, .bdrv_open = &raw_open, - .bdrv_child_perm = bdrv_filter_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_create_opts = &raw_co_create_opts, .bdrv_co_preadv = &raw_co_preadv, .bdrv_co_pwritev = &raw_co_pwritev, diff --git a/block/throttle.c b/block/throttle.c index 47b0a3522d..0ebbad0743 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -237,7 +237,7 @@ static BlockDriver bdrv_throttle = { .bdrv_close = throttle_close, .bdrv_co_flush = throttle_co_flush, - .bdrv_child_perm = bdrv_filter_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_getlength = throttle_getlength, diff --git a/block/vdi.c b/block/vdi.c index 1736d02eee..4df7f0fc60 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -1037,7 +1037,7 @@ static BlockDriver bdrv_vdi = { .bdrv_open = vdi_open, .bdrv_close = vdi_close, .bdrv_reopen_prepare = vdi_reopen_prepare, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_create = vdi_co_create, .bdrv_co_create_opts = vdi_co_create_opts, .bdrv_has_zero_init = vdi_has_zero_init, diff --git a/block/vhdx.c b/block/vhdx.c index d8a315015d..18c1f2768a 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -2232,7 +2232,7 @@ static BlockDriver bdrv_vhdx = { .bdrv_open = vhdx_open, .bdrv_close = vhdx_close, .bdrv_reopen_prepare = vhdx_reopen_prepare, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_readv = vhdx_co_readv, .bdrv_co_writev = vhdx_co_writev, .bdrv_co_create = vhdx_co_create, diff --git a/block/vmdk.c b/block/vmdk.c index 497414e5f2..79f6666a11 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -3055,7 +3055,7 @@ static BlockDriver bdrv_vmdk = { .bdrv_open = vmdk_open, .bdrv_co_check = vmdk_co_check, .bdrv_reopen_prepare = vmdk_reopen_prepare, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_preadv = vmdk_co_preadv, .bdrv_co_pwritev = vmdk_co_pwritev, .bdrv_co_pwritev_compressed = vmdk_co_pwritev_compressed, diff --git a/block/vpc.c b/block/vpc.c index 9acd6edac9..955c58aa2b 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -1238,7 +1238,7 @@ static BlockDriver bdrv_vpc = { .bdrv_open = vpc_open, .bdrv_close = vpc_close, .bdrv_reopen_prepare = vpc_reopen_prepare, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_create = vpc_co_create, .bdrv_co_create_opts = vpc_co_create_opts, diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index 91567ca97d..0da5a3a6a1 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -93,15 +93,15 @@ static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, uint64_t *nperm, uint64_t *nshared) { /* - * bdrv_format_default_perms() accepts only these two, so disguise + * bdrv_default_perms() accepts only these two, so disguise * detach_by_driver_cb_parent as one of them. */ if (child_class != &child_file && child_class != &child_of_bds) { child_class = &child_of_bds; } - bdrv_format_default_perms(bs, c, child_class, role, reopen_queue, - perm, shared, nperm, nshared); + bdrv_default_perms(bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); } static int bdrv_test_change_backing_file(BlockDriverState *bs, @@ -1137,7 +1137,7 @@ static BlockDriver bdrv_test_top_driver = { .bdrv_close = bdrv_test_top_close, .bdrv_co_preadv = bdrv_test_top_co_preadv, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, }; typedef struct TestCoDeleteByDrainData { @@ -1966,7 +1966,7 @@ static BlockDriver bdrv_replace_test = { .bdrv_co_drain_begin = bdrv_replace_test_co_drain_begin, .bdrv_co_drain_end = bdrv_replace_test_co_drain_end, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, }; static void coroutine_fn test_replace_child_mid_drain_read_co(void *opaque) diff --git a/tests/test-bdrv-graph-mod.c b/tests/test-bdrv-graph-mod.c index 6ae91ff171..a2d0318b16 100644 --- a/tests/test-bdrv-graph-mod.c +++ b/tests/test-bdrv-graph-mod.c @@ -26,7 +26,7 @@ static BlockDriver bdrv_pass_through = { .format_name = "pass-through", - .bdrv_child_perm = bdrv_filter_default_perms, + .bdrv_child_perm = bdrv_default_perms, }; static void no_perm_default_perms(BlockDriverState *bs, BdrvChild *c, diff --git a/tests/test-block-iothread.c b/tests/test-block-iothread.c index 0c861809f0..d928d2c6d9 100644 --- a/tests/test-block-iothread.c +++ b/tests/test-block-iothread.c @@ -481,8 +481,13 @@ static void test_propagate_basic(void) BlockDriverState *bs_a, *bs_b, *bs_verify; QDict *options; - /* Create bs_a and its BlockBackend */ - blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); + /* + * Create bs_a and its BlockBackend. We cannot take the RESIZE + * permission because blkverify will not share it on the test + * image. + */ + blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL & ~BLK_PERM_RESIZE, + BLK_PERM_ALL); bs_a = bdrv_new_open_driver(&bdrv_test, "bs_a", BDRV_O_RDWR, &error_abort); blk_insert_bs(blk, bs_a, &error_abort); @@ -565,7 +570,13 @@ static void test_propagate_diamond(void) qdict_put_str(options, "raw", "bs_c"); bs_verify = bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort); - blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); + /* + * Do not take the RESIZE permission: This would require the same + * from bs_c and thus from bs_a; however, blkverify will not share + * it on bs_b, and thus it will not be available for bs_a. + */ + blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL & ~BLK_PERM_RESIZE, + BLK_PERM_ALL); blk_insert_bs(blk, bs_verify, &error_abort); /* Switch the AioContext */ From patchwork Tue Feb 18 12:42:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388365 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 99A0E1395 for ; Tue, 18 Feb 2020 12:48:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 64B9A2173E for ; Tue, 18 Feb 2020 12:48:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UBALEtia" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 64B9A2173E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42IN-0004yz-Dj for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 07:48:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39608) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Ej-00074q-9y for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42Ei-0001qF-8O for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:25 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:38138) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42Ei-0001q8-5L for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029863; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H9ohRgucKFrjUPBiXOO6Cr0R65d/o4m/1ZQYnPhrDPE=; b=UBALEtiakU0AtIq7pmJlTvzj0pfYGJoTt9EAKVpInYpIsWQfXv6DVB9LNM/UdIzAnK01Wb f4opUu4QWSrpS7+/SGt0NMYviG+Vn3RTA5g5NO+atqJCwMlvJmbqVymAjF3r5EeQbmm+TC inrwD+x2PMCZ9HnSSiT7phzYTtGxQ7M= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-11-7dUJEBnXPjGKDczP40iNFw-1; Tue, 18 Feb 2020 07:44:20 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 11B998014CA; Tue, 18 Feb 2020 12:44:19 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 82BCD100194E; Tue, 18 Feb 2020 12:44:18 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 29/33] block: Make bdrv_filter_default_perms() static Date: Tue, 18 Feb 2020 13:42:38 +0100 Message-Id: <20200218124242.584644-30-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: 7dUJEBnXPjGKDczP40iNFw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 17 +++++++++++------ include/block/block_int.h | 10 ---------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/block.c b/block.c index d3beed1819..a7c2ad6c5b 100644 --- a/block.c +++ b/block.c @@ -2216,12 +2216,17 @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp) return bdrv_child_try_set_perm(c, perms, shared, errp); } -void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, - BdrvChildRole role, - BlockReopenQueue *reopen_queue, - uint64_t perm, uint64_t shared, - uint64_t *nperm, uint64_t *nshared) +/* + * Default implementation for .bdrv_child_perm() for block filters: + * Forward CONSISTENT_READ, WRITE, WRITE_UNCHANGED, and RESIZE to the + * filtered child. + */ +static void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, + const BdrvChildClass *child_class, + BdrvChildRole role, + BlockReopenQueue *reopen_queue, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) { *nperm = perm & DEFAULT_PERM_PASSTHROUGH; *nshared = (shared & DEFAULT_PERM_PASSTHROUGH) | DEFAULT_PERM_UNCHANGED; diff --git a/include/block/block_int.h b/include/block/block_int.h index ab64a5ccea..c2fb6b8899 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1253,16 +1253,6 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, */ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp); -/* Default implementation for BlockDriver.bdrv_child_perm() that can be used by - * block filters: Forward CONSISTENT_READ, WRITE, WRITE_UNCHANGED and RESIZE to - * all children */ -void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, - BdrvChildRole child_role, - BlockReopenQueue *reopen_queue, - uint64_t perm, uint64_t shared, - uint64_t *nperm, uint64_t *nshared); - /* Default implementation for BlockDriver.bdrv_child_perm() that can be used by * (non-raw) image formats: Like above for bs->backing, but for bs->file it * requires WRITE | RESIZE for read-write images, always requires From patchwork Tue Feb 18 12:42:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388421 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BC34F17EF for ; Tue, 18 Feb 2020 13:03:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 930932176D for ; Tue, 18 Feb 2020 13:03:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cFM8cY88" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 930932176D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Wl-0005Vj-NR for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 08:03:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39634) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42El-0007Ao-IT for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42Ek-0001rb-Dm for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:27 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:20863 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42Ek-0001rK-9m for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029865; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8hRA2oPB+6Kw4HC508F4CPC1l1NDHMCsSmfoIKimhgM=; b=cFM8cY88ZvncaHjDFE4YcdFDwubz9xwCP889NXDdsoSiAqpiaHOilS8mW+AaevigwzEi2J lqTTIVnolWk6cEdcHiF5aIYRsygb96KpwnbKMVlEwcWgK0Ing1YFJjTM18EbYm8cDM4X3o 8836+sTp4sCtY6O7UD8v62IaVb81OCQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-213-lH7k7QzpPoW_09b0SoDgIw-1; Tue, 18 Feb 2020 07:44:24 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 001F613E5; Tue, 18 Feb 2020 12:44:21 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 743ED5C241; Tue, 18 Feb 2020 12:44:21 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 30/33] block: Drop bdrv_format_default_perms() Date: Tue, 18 Feb 2020 13:42:39 +0100 Message-Id: <20200218124242.584644-31-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: lH7k7QzpPoW_09b0SoDgIw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 19 ------------------- include/block/block_int.h | 11 ----------- 2 files changed, 30 deletions(-) diff --git a/block.c b/block.c index a7c2ad6c5b..16eb790ea6 100644 --- a/block.c +++ b/block.c @@ -2344,25 +2344,6 @@ static void bdrv_default_perms_for_data(BlockDriverState *bs, BdrvChild *c, *nshared = shared; } -void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, - BdrvChildRole role, - BlockReopenQueue *reopen_queue, - uint64_t perm, uint64_t shared, - uint64_t *nperm, uint64_t *nshared) -{ - if (child_class == &child_of_bds) { - bdrv_default_perms(bs, c, child_class, role, reopen_queue, - perm, shared, nperm, nshared); - return; - } - - assert(child_class == &child_file); - - bdrv_default_perms_for_metadata(bs, c, child_class, role, reopen_queue, - perm, shared, nperm, nshared); -} - void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, diff --git a/include/block/block_int.h b/include/block/block_int.h index c2fb6b8899..28a35cd5d1 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1253,17 +1253,6 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, */ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp); -/* Default implementation for BlockDriver.bdrv_child_perm() that can be used 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 BdrvChildClass *child_class, - BdrvChildRole child_role, - BlockReopenQueue *reopen_queue, - uint64_t perm, uint64_t shared, - uint64_t *nperm, uint64_t *nshared); - bool bdrv_recurse_can_replace(BlockDriverState *bs, BlockDriverState *to_replace); From patchwork Tue Feb 18 12:42:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388427 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 75B7B17EF for ; Tue, 18 Feb 2020 13:08:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4CDBB20801 for ; Tue, 18 Feb 2020 13:08:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Vf5CXzei" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4CDBB20801 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34452 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42c8-0004gs-Ea for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 08:08:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39672) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Eo-0007Ev-5B for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42Em-0001uJ-9t for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:30 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:25305 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42Em-0001ti-5C for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029867; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EVNM86XVMKqugCb12twZ0/DNmmxlHxT6mS8rcuuuDLQ=; b=Vf5CXzeiq50TJDmVzZhuwUHv/S8GmEd48jO2VZV3TvJ7RNO/v+HGeYOZRSHX1y4aD36Sm6 vk+1SH+qeDjHtROcCEhIuySdNoFOITtbKKIcYNRzkLL2/MQjcuHNwzgvH2vNufh+FYFa02 SEBNy4goeqlgFuHiJnRhFsnlnhVn7JU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-404-xKp8y621O-W5C0FC_gLv7w-1; Tue, 18 Feb 2020 07:44:25 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 11F76800D5E; Tue, 18 Feb 2020 12:44:25 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8621F394; Tue, 18 Feb 2020 12:44:24 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 31/33] block: Drop child_file Date: Tue, 18 Feb 2020 13:42:40 +0100 Message-Id: <20200218124242.584644-32-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: xKp8y621O-W5C0FC_gLv7w-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 30 +----------------------------- include/block/block_int.h | 1 - tests/test-bdrv-drain.c | 8 +++----- 3 files changed, 4 insertions(+), 35 deletions(-) diff --git a/block.c b/block.c index 16eb790ea6..986f99415c 100644 --- a/block.c +++ b/block.c @@ -1121,33 +1121,6 @@ const BdrvChildClass child_of_bds = { .update_filename = bdrv_child_cb_update_filename, }; -/* - * Returns the options and flags that bs->file should get if a protocol driver - * is expected, based on the given options and flags for the parent BDS - */ -static void bdrv_protocol_options(BdrvChildRole role, bool parent_is_format, - int *child_flags, QDict *child_options, - int parent_flags, QDict *parent_options) -{ - bdrv_inherited_options(BDRV_CHILD_IMAGE, true, - child_flags, child_options, - parent_flags, parent_options); -} - -const BdrvChildClass child_file = { - .parent_is_bds = true, - .get_parent_desc = bdrv_child_get_parent_desc, - .inherit_options = bdrv_protocol_options, - .drained_begin = bdrv_child_cb_drained_begin, - .drained_poll = bdrv_child_cb_drained_poll, - .drained_end = bdrv_child_cb_drained_end, - .attach = bdrv_child_cb_attach, - .detach = bdrv_child_cb_detach, - .inactivate = bdrv_child_cb_inactivate, - .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx, - .set_aio_ctx = bdrv_child_cb_set_aio_ctx, -}; - static void bdrv_backing_attach(BdrvChild *c) { BlockDriverState *parent = c->opaque; @@ -2278,8 +2251,7 @@ static void bdrv_default_perms_for_metadata(BlockDriverState *bs, BdrvChild *c, { int flags; - assert(child_class == &child_file || - (child_class == &child_of_bds && (role & BDRV_CHILD_METADATA))); + assert(child_class == &child_of_bds && (role & BDRV_CHILD_METADATA)); flags = bdrv_reopen_get_flags(reopen_queue, bs); diff --git a/include/block/block_int.h b/include/block/block_int.h index 28a35cd5d1..1609e40b58 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -741,7 +741,6 @@ struct BdrvChildClass { }; extern const BdrvChildClass child_of_bds; -extern const BdrvChildClass child_file; struct BdrvChild { BlockDriverState *bs; diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index 0da5a3a6a1..655fd0d085 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -93,12 +93,10 @@ static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, uint64_t *nperm, uint64_t *nshared) { /* - * bdrv_default_perms() accepts only these two, so disguise - * detach_by_driver_cb_parent as one of them. + * bdrv_default_perms() accepts nothing else, so disguise + * detach_by_driver_cb_parent. */ - if (child_class != &child_file && child_class != &child_of_bds) { - child_class = &child_of_bds; - } + child_class = &child_of_bds; bdrv_default_perms(bs, c, child_class, role, reopen_queue, perm, shared, nperm, nshared); From patchwork Tue Feb 18 12:42:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388429 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D3FA117EF for ; Tue, 18 Feb 2020 13:10:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ABA7D22B48 for ; Tue, 18 Feb 2020 13:10:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bzy3yl2K" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ABA7D22B48 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42dT-0007ap-TI for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 08:09:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39695) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42Eq-0007HK-OY for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42Ep-0001w8-OI for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:32 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:39774 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42Ep-0001vu-KJ for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029871; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tEuTkgk8Im2JBBDdfMyL3Qhb/Rte2TyVItcIYV3lz8A=; b=bzy3yl2K/e6tf/m5lGC2cWchV7ZrAv3UtZDfNUuegPW3PBoYwItvMQ9JwyX7jKVMA56pCP Dfx4eTA4JmF41RccSsq6VT8mMkoOCx4g1/+HHXWOw+Raf8XexW9YNZbvRWXhT7ILdD1wV5 PaWvmAJIYVu+QzqpoA8zgYbSAHXWNB0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-41-iceRAwNAPnC2FbrhpTzGdQ-1; Tue, 18 Feb 2020 07:44:29 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4674713E4; Tue, 18 Feb 2020 12:44:28 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B689760C80; Tue, 18 Feb 2020 12:44:27 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 32/33] block: Pass BdrvChildRole in remaining cases Date: Tue, 18 Feb 2020 13:42:41 +0100 Message-Id: <20200218124242.584644-33-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: iceRAwNAPnC2FbrhpTzGdQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" These calls have no real use for the child role yet, but it will not harm to give one. Notably, the bdrv_root_attach_child() call in blockjob.c is left unmodified because there is not much the generic BlockJob object wants from its children. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block/block-backend.c | 11 +++++++---- block/vvfat.c | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 9e0078bfb5..e655e15675 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -401,8 +401,9 @@ BlockBackend *blk_new_open(const char *filename, const char *reference, return NULL; } - blk->root = bdrv_root_attach_child(bs, "root", &child_root, 0, blk->ctx, - perm, BLK_PERM_ALL, blk, errp); + blk->root = bdrv_root_attach_child(bs, "root", &child_root, + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, + blk->ctx, perm, BLK_PERM_ALL, blk, errp); if (!blk->root) { blk_unref(blk); return NULL; @@ -812,8 +813,10 @@ int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp) { ThrottleGroupMember *tgm = &blk->public.throttle_group_member; bdrv_ref(bs); - blk->root = bdrv_root_attach_child(bs, "root", &child_root, 0, blk->ctx, - blk->perm, blk->shared_perm, blk, errp); + blk->root = bdrv_root_attach_child(bs, "root", &child_root, + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, + blk->ctx, blk->perm, blk->shared_perm, + blk, errp); if (blk->root == NULL) { return -EPERM; } diff --git a/block/vvfat.c b/block/vvfat.c index 8f4ff5a97e..d4f4218924 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3186,7 +3186,7 @@ static int enable_write_target(BlockDriverState *bs, Error **errp) options = qdict_new(); qdict_put_str(options, "write-target.driver", "qcow"); s->qcow = bdrv_open_child(s->qcow_filename, options, "write-target", bs, - &child_vvfat_qcow, 0, false, errp); + &child_vvfat_qcow, BDRV_CHILD_DATA, false, errp); qobject_unref(options); if (!s->qcow) { ret = -EINVAL; From patchwork Tue Feb 18 12:42:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11388431 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7735417F0 for ; Tue, 18 Feb 2020 13:11:27 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3DEDE20801 for ; Tue, 18 Feb 2020 13:11:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GxzWtTDK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3DEDE20801 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42es-0001HR-DB for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Feb 2020 08:11:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39732) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j42F0-0007j2-T2 for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j42Ey-000222-Ga for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:42 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:35425 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j42Ey-00021u-CS for qemu-devel@nongnu.org; Tue, 18 Feb 2020 07:44:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582029879; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KKo2uT2e+aj3mNWpYL1H8pNIORZ+byTLeJNhOG6ihyg=; b=GxzWtTDK6bB04DQVBe5s+P99VGeb0UZw3TLczxqycZV6l1tTAZYn0N42ckQnvPCPhnzg+V t1aMKXvQLoazS/tSiwwfsbiXiCryWOVb/dAVtWaE6IhzgyNXVjyt2ee5sugv4QtViycp9l W2mw8CHMH/2CqmkzHUpiO49o+i9Hwhs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-231-xO7zMe6aN4eSTTkc1K4WqA-1; Tue, 18 Feb 2020 07:44:32 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D3DF71005512; Tue, 18 Feb 2020 12:44:31 +0000 (UTC) Received: from localhost (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C867A1BC6D; Tue, 18 Feb 2020 12:44:30 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 33/33] block: Drop @child_class from bdrv_child_perm() Date: Tue, 18 Feb 2020 13:42:42 +0100 Message-Id: <20200218124242.584644-34-mreitz@redhat.com> In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com> References: <20200218124242.584644-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: xO7zMe6aN4eSTTkc1K4WqA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Implementations should decide the necessary permissions based on @role. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 45 ++++++++++++++++--------------------- block/backup-top.c | 3 +-- block/blkdebug.c | 3 +-- block/blklogwrites.c | 3 +-- block/commit.c | 1 - block/copy-on-read.c | 1 - block/mirror.c | 1 - block/quorum.c | 1 - block/replication.c | 1 - block/vvfat.c | 4 +--- include/block/block_int.h | 4 +--- tests/test-bdrv-drain.c | 19 +--------------- tests/test-bdrv-graph-mod.c | 1 - 13 files changed, 25 insertions(+), 62 deletions(-) diff --git a/block.c b/block.c index 986f99415c..00c491dd91 100644 --- a/block.c +++ b/block.c @@ -1788,13 +1788,13 @@ bool bdrv_is_writable(BlockDriverState *bs) } static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs, - BdrvChild *c, const BdrvChildClass *child_class, - BdrvChildRole role, BlockReopenQueue *reopen_queue, + BdrvChild *c, BdrvChildRole role, + BlockReopenQueue *reopen_queue, uint64_t parent_perm, uint64_t parent_shared, uint64_t *nperm, uint64_t *nshared) { assert(bs->drv && bs->drv->bdrv_child_perm); - bs->drv->bdrv_child_perm(bs, c, child_class, role, reopen_queue, + bs->drv->bdrv_child_perm(bs, c, role, reopen_queue, parent_perm, parent_shared, nperm, nshared); /* TODO Take force_share from reopen_queue */ @@ -1888,7 +1888,7 @@ static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q, uint64_t cur_perm, cur_shared; bool child_tighten_restr; - bdrv_child_perm(bs, c->bs, c, c->klass, c->role, q, + bdrv_child_perm(bs, c->bs, c, c->role, q, cumulative_perms, cumulative_shared_perms, &cur_perm, &cur_shared); ret = bdrv_child_check_perm(c, q, cur_perm, cur_shared, ignore_children, @@ -1955,7 +1955,7 @@ static void bdrv_set_perm(BlockDriverState *bs, uint64_t cumulative_perms, /* Update all children */ QLIST_FOREACH(c, &bs->children, next) { uint64_t cur_perm, cur_shared; - bdrv_child_perm(bs, c->bs, c, c->klass, c->role, NULL, + bdrv_child_perm(bs, c->bs, c, c->role, NULL, cumulative_perms, cumulative_shared_perms, &cur_perm, &cur_shared); bdrv_child_set_perm(c, cur_perm, cur_shared); @@ -2183,7 +2183,7 @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp) uint64_t perms, shared; bdrv_get_cumulative_perm(bs, &parent_perms, &parent_shared); - bdrv_child_perm(bs, c->bs, c, c->klass, c->role, NULL, + bdrv_child_perm(bs, c->bs, c, c->role, NULL, parent_perms, parent_shared, &perms, &shared); return bdrv_child_try_set_perm(c, perms, shared, errp); @@ -2195,7 +2195,6 @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp) * filtered child. */ static void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, @@ -2206,13 +2205,12 @@ static void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, } static void bdrv_default_perms_for_backing(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) { - assert(child_class == &child_of_bds && (role & BDRV_CHILD_COW)); + assert(role & BDRV_CHILD_COW); /* * We want consistent read from backing files if the parent needs it. @@ -2243,7 +2241,6 @@ static void bdrv_default_perms_for_backing(BlockDriverState *bs, BdrvChild *c, } static void bdrv_default_perms_for_metadata(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, @@ -2251,7 +2248,7 @@ static void bdrv_default_perms_for_metadata(BlockDriverState *bs, BdrvChild *c, { int flags; - assert(child_class == &child_of_bds && (role & BDRV_CHILD_METADATA)); + assert(role & BDRV_CHILD_METADATA); flags = bdrv_reopen_get_flags(reopen_queue, bs); @@ -2259,7 +2256,7 @@ static void bdrv_default_perms_for_metadata(BlockDriverState *bs, BdrvChild *c, * Apart from the modifications below, the same permissions are * forwarded and left alone as for filters */ - bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, + bdrv_filter_default_perms(bs, c, role, reopen_queue, perm, shared, &perm, &shared); /* Format drivers may touch metadata even if the guest doesn't write */ @@ -2285,19 +2282,18 @@ static void bdrv_default_perms_for_metadata(BlockDriverState *bs, BdrvChild *c, } static void bdrv_default_perms_for_data(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) { - assert(child_class == &child_of_bds && (role & BDRV_CHILD_DATA)); + assert(role & BDRV_CHILD_DATA); /* * Apart from the modifications below, the same permissions are * forwarded and left alone as for filters */ - bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, + bdrv_filter_default_perms(bs, c, role, reopen_queue, perm, shared, &perm, &shared); /* @@ -2317,24 +2313,21 @@ static void bdrv_default_perms_for_data(BlockDriverState *bs, BdrvChild *c, } void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, - BlockReopenQueue *reopen_queue, + BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) { - assert(child_class == &child_of_bds); - if (role & BDRV_CHILD_FILTERED) { - bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, + bdrv_filter_default_perms(bs, c, role, reopen_queue, perm, shared, nperm, nshared); } else if (role & BDRV_CHILD_COW) { - bdrv_default_perms_for_backing(bs, c, child_class, role, reopen_queue, + bdrv_default_perms_for_backing(bs, c, role, reopen_queue, perm, shared, nperm, nshared); } else if (role & BDRV_CHILD_METADATA) { - bdrv_default_perms_for_metadata(bs, c, child_class, role, reopen_queue, + bdrv_default_perms_for_metadata(bs, c, role, reopen_queue, perm, shared, nperm, nshared); } else if (role & BDRV_CHILD_DATA) { - bdrv_default_perms_for_data(bs, c, child_class, role, reopen_queue, + bdrv_default_perms_for_data(bs, c, role, reopen_queue, perm, shared, nperm, nshared); } else { g_assert_not_reached(); @@ -2577,7 +2570,7 @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, bdrv_get_cumulative_perm(parent_bs, &perm, &shared_perm); assert(parent_bs->drv); - bdrv_child_perm(parent_bs, child_bs, NULL, child_class, child_role, NULL, + bdrv_child_perm(parent_bs, child_bs, NULL, child_role, NULL, perm, shared_perm, &perm, &shared_perm); child = bdrv_root_attach_child(child_bs, child_name, child_class, @@ -3650,7 +3643,7 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp) if (state->replace_backing_bs && state->new_backing_bs) { uint64_t nperm, nshared; bdrv_child_perm(state->bs, state->new_backing_bs, - NULL, &child_of_bds, bdrv_backing_role(state->bs), + NULL, bdrv_backing_role(state->bs), bs_queue, state->perm, state->shared_perm, &nperm, &nshared); ret = bdrv_check_update_perm(state->new_backing_bs, NULL, @@ -3764,7 +3757,7 @@ static void bdrv_reopen_perm(BlockReopenQueue *q, BlockDriverState *bs, } else { uint64_t nperm, nshared; - bdrv_child_perm(parent->state.bs, bs, c, c->klass, c->role, q, + bdrv_child_perm(parent->state.bs, bs, c, c->role, q, parent->state.perm, parent->state.shared_perm, &nperm, &nshared); diff --git a/block/backup-top.c b/block/backup-top.c index 00dbad44b5..351ced39ea 100644 --- a/block/backup-top.c +++ b/block/backup-top.c @@ -121,7 +121,6 @@ static void backup_top_refresh_filename(BlockDriverState *bs) } static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, @@ -153,7 +152,7 @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, *nperm = BLK_PERM_WRITE; } else { /* Source child */ - bdrv_default_perms(bs, c, child_class, role, reopen_queue, + bdrv_default_perms(bs, c, role, reopen_queue, perm, shared, nperm, nshared); if (perm & BLK_PERM_WRITE) { diff --git a/block/blkdebug.c b/block/blkdebug.c index a925d8295e..7194bc7f06 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -995,7 +995,6 @@ static int blkdebug_reopen_prepare(BDRVReopenState *reopen_state, } static void blkdebug_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, @@ -1003,7 +1002,7 @@ static void blkdebug_child_perm(BlockDriverState *bs, BdrvChild *c, { BDRVBlkdebugState *s = bs->opaque; - bdrv_default_perms(bs, c, child_class, role, reopen_queue, + bdrv_default_perms(bs, c, role, reopen_queue, perm, shared, nperm, nshared); *nperm |= s->take_child_perms; diff --git a/block/blklogwrites.c b/block/blklogwrites.c index 8684fb1c74..6753bd9a3e 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -283,7 +283,6 @@ static int64_t blk_log_writes_getlength(BlockDriverState *bs) } static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *ro_q, uint64_t perm, uint64_t shrd, @@ -295,7 +294,7 @@ static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, return; } - bdrv_default_perms(bs, c, child_class, role, ro_q, perm, shrd, + bdrv_default_perms(bs, c, role, ro_q, perm, shrd, nperm, nshrd); } diff --git a/block/commit.c b/block/commit.c index 6d094c8cd1..7bf05e69da 100644 --- a/block/commit.c +++ b/block/commit.c @@ -223,7 +223,6 @@ static void bdrv_commit_top_refresh_filename(BlockDriverState *bs) } static void bdrv_commit_top_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, diff --git a/block/copy-on-read.c b/block/copy-on-read.c index c857ea0da7..a6e3c74a68 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -52,7 +52,6 @@ static int cor_open(BlockDriverState *bs, QDict *options, int flags, #define PERM_UNCHANGED (BLK_PERM_ALL & ~PERM_PASSTHROUGH) static void cor_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, diff --git a/block/mirror.c b/block/mirror.c index 25c5e8b622..78f5939fac 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1484,7 +1484,6 @@ static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs) } static void bdrv_mirror_top_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, diff --git a/block/quorum.c b/block/quorum.c index 616ac3a927..7cf7ab1546 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1153,7 +1153,6 @@ static char *quorum_dirname(BlockDriverState *bs, Error **errp) } static void quorum_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, diff --git a/block/replication.c b/block/replication.c index ec512ae1c3..5843367944 100644 --- a/block/replication.c +++ b/block/replication.c @@ -161,7 +161,6 @@ static void replication_close(BlockDriverState *bs) } static void replication_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, diff --git a/block/vvfat.c b/block/vvfat.c index d4f4218924..6e36ad3175 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3213,7 +3213,6 @@ err: } static void vvfat_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, @@ -3221,8 +3220,7 @@ static void vvfat_child_perm(BlockDriverState *bs, BdrvChild *c, { BDRVVVFATState *s = bs->opaque; - assert(c == s->qcow || - (child_class == &child_of_bds && (role & BDRV_CHILD_COW))); + assert(c == s->qcow || (role & BDRV_CHILD_COW)); if (c == s->qcow) { /* This is a private node, nobody should try to attach to it */ diff --git a/include/block/block_int.h b/include/block/block_int.h index 1609e40b58..9c58b64903 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -563,7 +563,6 @@ struct BlockDriver { * @reopen_queue. */ void (*bdrv_child_perm)(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t parent_perm, uint64_t parent_shared, @@ -1261,8 +1260,7 @@ bool bdrv_recurse_can_replace(BlockDriverState *bs, * child_of_bds child class and set an appropriate BdrvChildRole. */ void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, - BlockReopenQueue *reopen_queue, + BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared); diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index 655fd0d085..1107271840 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -85,23 +85,6 @@ static int coroutine_fn bdrv_test_co_preadv(BlockDriverState *bs, return 0; } -static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, - BdrvChildRole role, - BlockReopenQueue *reopen_queue, - uint64_t perm, uint64_t shared, - uint64_t *nperm, uint64_t *nshared) -{ - /* - * bdrv_default_perms() accepts nothing else, so disguise - * detach_by_driver_cb_parent. - */ - child_class = &child_of_bds; - - bdrv_default_perms(bs, c, child_class, role, reopen_queue, - perm, shared, nperm, nshared); -} - static int bdrv_test_change_backing_file(BlockDriverState *bs, const char *backing_file, const char *backing_fmt) @@ -119,7 +102,7 @@ static BlockDriver bdrv_test = { .bdrv_co_drain_begin = bdrv_test_co_drain_begin, .bdrv_co_drain_end = bdrv_test_co_drain_end, - .bdrv_child_perm = bdrv_test_child_perm, + .bdrv_child_perm = bdrv_default_perms, .bdrv_change_backing_file = bdrv_test_change_backing_file, }; diff --git a/tests/test-bdrv-graph-mod.c b/tests/test-bdrv-graph-mod.c index a2d0318b16..f93f3168b0 100644 --- a/tests/test-bdrv-graph-mod.c +++ b/tests/test-bdrv-graph-mod.c @@ -30,7 +30,6 @@ static BlockDriver bdrv_pass_through = { }; static void no_perm_default_perms(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared,