From nobody Tue Apr 15 13:26:17 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=1666896824; cv=none; d=zohomail.com; s=zohoarc; b=bboh/2lZGIsX5XxhocsAtHkD/uj1oJNMVZl1AWgfROY7aNbko/Iv2EqInbIqE5bxmtPxlA3qRGaPeDgjcvhqohZsDWtAokKl5aN0OdIf6q6Y4lhE5v3NHcoc9tuQmvP2CKZubOgknOT6RTz3bIBaYtsl8QqtES3fzgtG2wdY4oM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666896824; h=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=awiRcd0IeiOoVx7HjLmZzN9WM5Mf+MZr9m53BmKl7hQ=; b=PKPfRdB7miq/RgIXEQIoq/US369xOX/BE8gGhsQ57EenGRS2unkZ9qduhicAsuB7y/RKnc5ilZBXjPzBZCkoNethK0BKvQ7YdAJwJrAvPL7HTGSuAfeHlcT8uy501PGcORa1i1ayz5cVr8hJ3/sB4sDCg5FyLu/mwa8O4J6S+Xk= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTP id 1666896824978702.135753695962; Thu, 27 Oct 2022 11:53:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oo7gE-0001Ux-TC; Thu, 27 Oct 2022 14:32:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oo7gD-0001PQ-58 for qemu-devel@nongnu.org; Thu, 27 Oct 2022 14:32:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oo7g6-0002R2-71 for qemu-devel@nongnu.org; Thu, 27 Oct 2022 14:32:36 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-349-A9xfqKRTNu-gZCQ0a7sppQ-1; Thu, 27 Oct 2022 14:32:27 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2B861101E14C; Thu, 27 Oct 2022 18:32:27 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17EAF112C06D; Thu, 27 Oct 2022 18:32:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666895549; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=awiRcd0IeiOoVx7HjLmZzN9WM5Mf+MZr9m53BmKl7hQ=; b=MzTwzrTAQx40OKq2HyQ9Xw9rqKkz5PI+xU29Fp2JqZr+fSsxvQ0yKV0ZwX13NspB/mALgn BrGrD6gStrZR5aeKj64M8g8iMtSvdA9Hs4xAqqpgH/92aTRVWJc6Ho1K1p6pXsLaJyw/zZ hJm9Ew9WWC/GEph6Yh2LU7oocUDQ3FU= X-MC-Unique: A9xfqKRTNu-gZCQ0a7sppQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 09/58] block: introduce bdrv_open_file_child() helper Date: Thu, 27 Oct 2022 20:30:57 +0200 Message-Id: <20221027183146.463129-10-kwolf@redhat.com> In-Reply-To: <20221027183146.463129-1-kwolf@redhat.com> References: <20221027183146.463129-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.515, 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_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666896825846100001 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Almost all drivers call bdrv_open_child() similarly. Let's create a helper for this. The only not updated drivers that call bdrv_open_child() to set bs->file are raw-format and snapshot-access: raw-format sometimes want to have filtered child but don't set drv->is_filter to true. snapshot-access wants only DATA | PRIMARY Possibly we should implement drv->is_filter_func() handler, to consider raw-format as filter when it works as filter.. But it's another story. Note also, that we decrease assignments to bs->file in code: it helps us restrict modifying this field in further commit. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz Message-Id: <20220726201134.924743-3-vsementsov@yandex-team.ru> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/block-global-state.h | 3 +++ block.c | 21 +++++++++++++++++++++ block/blkdebug.c | 9 +++------ block/blklogwrites.c | 7 ++----- block/blkreplay.c | 7 ++----- block/blkverify.c | 9 +++------ block/bochs.c | 7 +++---- block/cloop.c | 7 +++---- block/copy-before-write.c | 9 ++++----- block/copy-on-read.c | 9 ++++----- block/crypto.c | 11 ++++++----- block/dmg.c | 7 +++---- block/filter-compress.c | 8 +++----- block/parallels.c | 7 +++---- block/preallocate.c | 9 ++++----- block/qcow.c | 6 ++---- block/qcow2.c | 8 ++++---- block/qed.c | 8 ++++---- block/replication.c | 8 +++----- block/throttle.c | 8 +++----- block/vdi.c | 7 +++---- block/vhdx.c | 7 +++---- block/vmdk.c | 7 +++---- block/vpc.c | 7 +++---- 24 files changed, 95 insertions(+), 101 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 21265e3966..29a38d7e18 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -76,6 +76,9 @@ BdrvChild *bdrv_open_child(const char *filename, const BdrvChildClass *child_class, BdrvChildRole child_role, bool allow_none, Error **errp); +int bdrv_open_file_child(const char *filename, + QDict *options, const char *bdref_key, + BlockDriverState *parent, Error **errp); BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp); int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, Error **errp); diff --git a/block.c b/block.c index c8374dac4f..25a596a612 100644 --- a/block.c +++ b/block.c @@ -3673,6 +3673,27 @@ BdrvChild *bdrv_open_child(const char *filename, errp); } =20 +/* + * Wrapper on bdrv_open_child() for most popular case: open primary child = of bs. + */ +int bdrv_open_file_child(const char *filename, + QDict *options, const char *bdref_key, + BlockDriverState *parent, Error **errp) +{ + BdrvChildRole role; + + /* commit_top and mirror_top don't use this function */ + assert(!parent->drv->filtered_child_is_backing); + + role =3D parent->drv->is_filter ? + (BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY) : BDRV_CHILD_IMAGE; + + parent->file =3D bdrv_open_child(filename, options, bdref_key, parent, + &child_of_bds, role, false, errp); + + return parent->file ? 0 : -EINVAL; +} + /* * 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. diff --git a/block/blkdebug.c b/block/blkdebug.c index bbf2948703..5fcfc8ac6f 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -503,12 +503,9 @@ static int blkdebug_open(BlockDriverState *bs, QDict *= options, int flags, } =20 /* Open the image file */ - bs->file =3D bdrv_open_child(qemu_opt_get(opts, "x-image"), options, "= image", - bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, errp); - if (!bs->file) { - ret =3D -EINVAL; + ret =3D bdrv_open_file_child(qemu_opt_get(opts, "x-image"), options, "= image", + bs, errp); + if (ret < 0) { goto out; } =20 diff --git a/block/blklogwrites.c b/block/blklogwrites.c index e3c6c4039c..12b4c3c8cf 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -155,11 +155,8 @@ static int blk_log_writes_open(BlockDriverState *bs, Q= Dict *options, int flags, } =20 /* Open the file */ - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, f= alse, - errp); - if (!bs->file) { - ret =3D -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { goto fail; } =20 diff --git a/block/blkreplay.c b/block/blkreplay.c index dcbe780ddb..76a0b8d12a 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -26,11 +26,8 @@ static int blkreplay_open(BlockDriverState *bs, QDict *o= ptions, int flags, int ret; =20 /* Open the image file */ - bs->file =3D bdrv_open_child(NULL, options, "image", bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, errp); - if (!bs->file) { - ret =3D -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "image", bs, errp); + if (ret < 0) { goto fail; } =20 diff --git a/block/blkverify.c b/block/blkverify.c index 020b1ae7b6..43a2d94f7b 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -122,12 +122,9 @@ static int blkverify_open(BlockDriverState *bs, QDict = *options, int flags, } =20 /* Open the raw file */ - bs->file =3D bdrv_open_child(qemu_opt_get(opts, "x-raw"), options, "ra= w", - bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, errp); - if (!bs->file) { - ret =3D -EINVAL; + ret =3D bdrv_open_file_child(qemu_opt_get(opts, "x-raw"), options, "ra= w", + bs, errp); + if (ret < 0) { goto fail; } =20 diff --git a/block/bochs.c b/block/bochs.c index b76f34fe03..e30e3908d9 100644 --- a/block/bochs.c +++ b/block/bochs.c @@ -110,10 +110,9 @@ static int bochs_open(BlockDriverState *bs, QDict *opt= ions, int flags, return ret; } =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 ret =3D bdrv_pread(bs->file, 0, sizeof(bochs), &bochs, 0); diff --git a/block/cloop.c b/block/cloop.c index 40b146e714..3ff975a94d 100644 --- a/block/cloop.c +++ b/block/cloop.c @@ -71,10 +71,9 @@ static int cloop_open(BlockDriverState *bs, QDict *optio= ns, int flags, return ret; } =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 /* read header */ diff --git a/block/copy-before-write.c b/block/copy-before-write.c index afbdd04489..4abaa7339e 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -412,6 +412,7 @@ static int cbw_open(BlockDriverState *bs, QDict *option= s, int flags, int64_t cluster_size; g_autoptr(BlockdevOptions) full_opts =3D NULL; BlockdevOptionsCbw *opts; + int ret; =20 full_opts =3D cbw_parse_options(options, errp); if (!full_opts) { @@ -420,11 +421,9 @@ static int cbw_open(BlockDriverState *bs, QDict *optio= ns, int flags, assert(full_opts->driver =3D=3D BLOCKDEV_DRIVER_COPY_BEFORE_WRITE); opts =3D &full_opts->u.copy_before_write; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 s->target =3D bdrv_open_child(NULL, options, "target", bs, &child_of_b= ds, diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 1fc7fb3333..815ac1d835 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -41,12 +41,11 @@ static int cor_open(BlockDriverState *bs, QDict *option= s, int flags, BDRVStateCOR *state =3D bs->opaque; /* Find a bottom node name, if any */ const char *bottom_node =3D qdict_get_try_str(options, "bottom"); + int ret; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 bs->supported_read_flags =3D BDRV_REQ_PREFETCH; diff --git a/block/crypto.c b/block/crypto.c index 7a57774b76..396e529bb2 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -261,15 +261,14 @@ static int block_crypto_open_generic(QCryptoBlockForm= at format, { BlockCrypto *crypto =3D bs->opaque; QemuOpts *opts =3D NULL; - int ret =3D -EINVAL; + int ret; QCryptoBlockOpenOptions *open_opts =3D NULL; unsigned int cflags =3D 0; QDict *cryptoopts =3D NULL; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 bs->supported_write_flags =3D BDRV_REQ_FUA & @@ -277,6 +276,7 @@ static int block_crypto_open_generic(QCryptoBlockFormat= format, =20 opts =3D qemu_opts_create(opts_spec, NULL, 0, &error_abort); if (!qemu_opts_absorb_qdict(opts, options, errp)) { + ret =3D -EINVAL; goto cleanup; } =20 @@ -285,6 +285,7 @@ static int block_crypto_open_generic(QCryptoBlockFormat= format, =20 open_opts =3D block_crypto_open_opts_init(cryptoopts, errp); if (!open_opts) { + ret =3D -EINVAL; goto cleanup; } =20 diff --git a/block/dmg.c b/block/dmg.c index 98db18d82a..422136276a 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -440,10 +440,9 @@ static int dmg_open(BlockDriverState *bs, QDict *optio= ns, int flags, return ret; } =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 block_module_load_one("dmg-bz2"); diff --git a/block/filter-compress.c b/block/filter-compress.c index d5be538619..305716c86c 100644 --- a/block/filter-compress.c +++ b/block/filter-compress.c @@ -30,11 +30,9 @@ static int compress_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, errp); - if (!bs->file) { - return -EINVAL; + int ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 if (!bs->file->bs->drv || !block_driver_can_compress(bs->file->bs->drv= )) { diff --git a/block/parallels.c b/block/parallels.c index c1523e7dab..27c81cee40 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -737,10 +737,9 @@ 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_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 ret =3D bdrv_pread(bs->file, 0, sizeof(ph), &ph, 0); diff --git a/block/preallocate.c b/block/preallocate.c index e15cb8c74a..d50ee7f49b 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -134,6 +134,7 @@ static int preallocate_open(BlockDriverState *bs, QDict= *options, int flags, Error **errp) { BDRVPreallocateState *s =3D bs->opaque; + int ret; =20 /* * s->data_end and friends should be initialized on permission update. @@ -141,11 +142,9 @@ static int preallocate_open(BlockDriverState *bs, QDic= t *options, int flags, */ s->file_end =3D s->zero_start =3D s->data_end =3D -EINVAL; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 if (!preallocate_absorb_opts(&s->opts, options, bs->file->bs, errp)) { diff --git a/block/qcow.c b/block/qcow.c index 311aaa8705..72ed4c3321 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -121,10 +121,8 @@ static int qcow_open(BlockDriverState *bs, QDict *opti= ons, 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_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - ret =3D -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { goto fail; } =20 diff --git a/block/qcow2.c b/block/qcow2.c index b57f7cc8ee..b47016cf61 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1905,11 +1905,11 @@ static int qcow2_open(BlockDriverState *bs, QDict *= options, int flags, .errp =3D errp, .ret =3D -EINPROGRESS }; + int ret; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 /* Initialise locks */ diff --git a/block/qed.c b/block/qed.c index bda00e6257..4627169348 100644 --- a/block/qed.c +++ b/block/qed.c @@ -561,11 +561,11 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict = *options, int flags, .errp =3D errp, .ret =3D -EINPROGRESS }; + int ret; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 bdrv_qed_init_state(bs); diff --git a/block/replication.c b/block/replication.c index c67f931f37..ee33dc4598 100644 --- a/block/replication.c +++ b/block/replication.c @@ -88,11 +88,9 @@ static int replication_open(BlockDriverState *bs, QDict = *options, const char *mode; const char *top_id; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 ret =3D -EINVAL; diff --git a/block/throttle.c b/block/throttle.c index ddd450593a..131eba3ab4 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -78,11 +78,9 @@ static int throttle_open(BlockDriverState *bs, QDict *op= tions, char *group; int ret; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } bs->supported_write_flags =3D bs->file->bs->supported_write_flags | BDRV_REQ_WRITE_UNCHANGED; diff --git a/block/vdi.c b/block/vdi.c index e942325455..a9bafb5a9e 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -377,10 +377,9 @@ static int vdi_open(BlockDriverState *bs, QDict *optio= ns, int flags, int ret; QemuUUID uuid_link, uuid_parent; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 logout("\n"); diff --git a/block/vhdx.c b/block/vhdx.c index e10e78ebfd..ce1e75f5ec 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1001,10 +1001,9 @@ static int vhdx_open(BlockDriverState *bs, QDict *op= tions, int flags, uint64_t signature; Error *local_err =3D NULL; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 s->bat =3D NULL; diff --git a/block/vmdk.c b/block/vmdk.c index f7d8856dfb..d75a87cb85 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1308,10 +1308,9 @@ static int vmdk_open(BlockDriverState *bs, QDict *op= tions, int flags, BDRVVmdkState *s =3D bs->opaque; uint32_t magic; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 buf =3D vmdk_read_desc(bs->file, 0, errp); diff --git a/block/vpc.c b/block/vpc.c index 4f49ef207f..95841f259a 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -233,10 +233,9 @@ static int vpc_open(BlockDriverState *bs, QDict *optio= ns, int flags, int ret; int64_t bs_size; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 opts =3D qemu_opts_create(&vpc_runtime_opts, NULL, 0, &error_abort); --=20 2.37.3