From nobody Tue Apr 15 03:57:25 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589548230; cv=none; d=zohomail.com; s=zohoarc; b=OiMQ333+UJd2aJlxEbHTD+TZU0I62Sdf2sDjJMJjoNiB+RikvTxQ0jLfABKdeMP1Y/DSSLUsU2147vtmb6U3iXh1D7WHvPjTVv0YGVw4BrltDfiKRMW3w5jGWGBN+1Qrb06DOHVk6+6iwKZSmqiP+MyVTrQRYvq7hjvw9jypZYc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589548230; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZdZ9Ng9D2S+MWyTy/IA76hQD8meauYjfqfc65E4W2I0=; b=CJ1h66nnAMcIOnSKGNa5nN2NHe/h2jiEUVqY70j19diPxeNx3bZMd1KuueVpIq7dDHeebFRsoAnIMRj23XSi3vYHTo2Xo1+KXGLIeNBoUkQSO+brI+tYgwsAi8Xjv9l9Tpqm0yjAYW1RwfNw7VWvgW5g/7UTOqp/XzFfn+dgCaQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589548230412842.9403634622832; Fri, 15 May 2020 06:10:30 -0700 (PDT) Received: from localhost ([::1]:56120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZa6f-0005tZ-GR for importer@patchew.org; Fri, 15 May 2020 09:10:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZZjR-0003VE-UE for qemu-devel@nongnu.org; Fri, 15 May 2020 08:46:29 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:40106 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZZjQ-0002RD-SM for qemu-devel@nongnu.org; Fri, 15 May 2020 08:46:29 -0400 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-43-PJZnAgGSPnyvMHmLztxYDw-1; Fri, 15 May 2020 08:46:24 -0400 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 212F51005512; Fri, 15 May 2020 12:46:23 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-110.ams2.redhat.com [10.36.113.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 272D72E024; Fri, 15 May 2020 12:46:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589546788; 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=ZdZ9Ng9D2S+MWyTy/IA76hQD8meauYjfqfc65E4W2I0=; b=WKpfIKHD3JrFmP3N04guZ/uD+DtltTPqdQK/uHt0vp2xrptYOaVXm4TjVhd8A+osqdZuzT 5kWgSCnmhd8E7g7ZWYZdHTjNNeiAT/MZBjbSNib8f2DVfAAo25sbJeXx72wluuX84RP1Rn cV/kcRmcHXpwd3KLiP1Qzi8lQISab68= X-MC-Unique: PJZnAgGSPnyvMHmLztxYDw-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 37/51] block: Make format drivers use child_of_bds Date: Fri, 15 May 2020 14:45:07 +0200 Message-Id: <20200515124521.335403-38-kwolf@redhat.com> In-Reply-To: <20200515124521.335403-1-kwolf@redhat.com> References: <20200515124521.335403-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.81; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/15 00:39:12 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Max Reitz 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 Message-Id: <20200513110544.176672-26-mreitz@redhat.com> Signed-off-by: Kevin Wolf --- 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 *opti= ons, int flags, return ret; } =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file =3D 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 *option= s, int flags, return ret; } =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file =3D 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 8b516bfee2..457f3a06a5 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -218,8 +218,8 @@ static int block_crypto_open_generic(QCryptoBlockFormat= format, unsigned int cflags =3D 0; QDict *cryptoopts =3D NULL; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file =3D 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 *option= s, int flags, return ret; } =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file =3D 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 9855ac1162..168d6c531a 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -739,8 +739,8 @@ static int parallels_open(BlockDriverState *bs, QDict *= options, int flags, Error *local_err =3D NULL; char *buf; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file =3D 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 13583f0339..5347037720 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -130,8 +130,8 @@ static int qcow_open(BlockDriverState *bs, QDict *optio= ns, int flags, qdict_extract_subqdict(options, &encryptopts, "encrypt."); encryptfmt =3D qdict_get_try_str(encryptopts, "format"); =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_IMAGE, false, errp); if (!bs->file) { ret =3D -EINVAL; goto fail; diff --git a/block/qcow2.c b/block/qcow2.c index 86335d9403..8d7230dca8 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1590,8 +1590,9 @@ static int coroutine_fn qcow2_do_open(BlockDriverStat= e *bs, QDict *options, } =20 /* Open external data file */ - s->data_file =3D bdrv_open_child(NULL, options, "data-file", bs, &chil= d_file, - 0, true, &local_err); + s->data_file =3D 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 =3D -EINVAL; @@ -1601,8 +1602,8 @@ static int coroutine_fn qcow2_do_open(BlockDriverStat= e *bs, QDict *options, if (s->incompatible_features & QCOW2_INCOMPAT_DATA_FILE) { if (!s->data_file && s->image_data_file) { s->data_file =3D 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 =3D -EINVAL; goto fail; @@ -1613,6 +1614,12 @@ static int coroutine_fn qcow2_do_open(BlockDriverSta= te *bs, QDict *options, ret =3D -EINVAL; goto fail; } + + /* No data here */ + bs->file->role &=3D ~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 " @@ -1863,8 +1870,8 @@ static int qcow2_open(BlockDriverState *bs, QDict *op= tions, int flags, .ret =3D -EINPROGRESS }; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file =3D 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 1ad2aba810..ef6463b48d 100644 --- a/block/qed.c +++ b/block/qed.c @@ -547,8 +547,8 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *o= ptions, int flags, .ret =3D -EINPROGRESS }; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file =3D 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 653acb5fc1..d20698b3cc 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -378,8 +378,8 @@ static int vdi_open(BlockDriverState *bs, QDict *option= s, int flags, Error *local_err =3D NULL; QemuUUID uuid_link, uuid_parent; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file =3D 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 dde156c97b..62c6bd69ff 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -996,8 +996,8 @@ static int vhdx_open(BlockDriverState *bs, QDict *optio= ns, int flags, uint64_t signature; Error *local_err =3D NULL; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file =3D 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 c2cb741e2d..fadc98a262 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1089,6 +1089,7 @@ static int vmdk_parse_extents(const char *desc, Block= DriverState *bs, char *desc_file_dir =3D NULL; char *extent_path; BdrvChild *extent_file; + BdrvChildRole extent_role; BDRVVmdkState *s =3D bs->opaque; VmdkExtent *extent; char extent_opt_prefix[32]; @@ -1151,8 +1152,15 @@ static int vmdk_parse_extents(const char *desc, Bloc= kDriverState *bs, ret =3D snprintf(extent_opt_prefix, 32, "extents.%d", s->num_exten= ts); assert(ret < 32); =20 + extent_role =3D BDRV_CHILD_DATA; + if (strcmp(type, "FLAT") !=3D 0 && strcmp(type, "VMFS") !=3D 0) { + /* non-flat extents have metadata */ + extent_role |=3D BDRV_CHILD_METADATA; + } + extent_file =3D bdrv_open_child(extent_path, options, extent_opt_p= refix, - bs, &child_file, 0, false, &local_er= r); + bs, &child_of_bds, extent_role, fals= e, + &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 *opt= ions, int flags, uint32_t magic; Error *local_err =3D NULL; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file =3D 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 *op= tions, int flags, s->desc_offset =3D 0x200; break; default: + /* No data in the descriptor file */ + bs->file->role &=3D ~BDRV_CHILD_DATA; + + /* Must succeed because we have given up permissions if anythi= ng */ + bdrv_child_refresh_perms(bs, bs->file, &error_abort); + ret =3D vmdk_open_desc_file(bs, flags, buf, options, errp); break; } diff --git a/block/vpc.c b/block/vpc.c index b2a86074a5..651a6737b6 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -228,8 +228,8 @@ static int vpc_open(BlockDriverState *bs, QDict *option= s, int flags, int ret; int64_t bs_size; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, 0, - false, errp); + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_IMAGE, false, errp); if (!bs->file) { return -EINVAL; } --=20 2.25.4