From nobody Mon Feb 9 01:16:10 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=quarantine dis=quarantine) header.from=virtuozzo.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1627930541602953.9345287737984; Mon, 2 Aug 2021 11:55:41 -0700 (PDT) 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-37-wcyStWaOOTuvAsgrqo1aJQ-1; Mon, 02 Aug 2021 14:55:39 -0400 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 4086118C8C0C; Mon, 2 Aug 2021 18:55:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1613B6A904; Mon, 2 Aug 2021 18:55:33 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D61194A7CB; Mon, 2 Aug 2021 18:55:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 172IsoFi006352 for ; Mon, 2 Aug 2021 14:54:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id E474AAEC9B; Mon, 2 Aug 2021 18:54:49 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DC196A9A1C for ; Mon, 2 Aug 2021 18:54:46 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C629A89C7E2 for ; Mon, 2 Aug 2021 18:54:46 +0000 (UTC) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70090.outbound.protection.outlook.com [40.107.7.90]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-515-JKwV1lqGMUGlWQaLQ996cg-2; Mon, 02 Aug 2021 14:54:44 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB4278.eurprd08.prod.outlook.com (2603:10a6:20b:71::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.18; Mon, 2 Aug 2021 18:54:39 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::44b9:68ac:bdc7:e23c]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::44b9:68ac:bdc7:e23c%8]) with mapi id 15.20.4373.026; Mon, 2 Aug 2021 18:54:39 +0000 Received: from localhost.localdomain (185.215.60.211) by HE1PR05CA0240.eurprd05.prod.outlook.com (2603:10a6:3:fb::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.18 via Frontend Transport; Mon, 2 Aug 2021 18:54:37 +0000 X-MC-Unique: wcyStWaOOTuvAsgrqo1aJQ-1 X-MC-Unique: JKwV1lqGMUGlWQaLQ996cg-2 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH 3/8] block: realize BlockParentClass for BlockDriverState Date: Mon, 2 Aug 2021 21:54:11 +0300 Message-ID: <20210802185416.50877-4-vsementsov@virtuozzo.com> In-Reply-To: <20210802185416.50877-1-vsementsov@virtuozzo.com> References: <20210802185416.50877-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: HE1PR05CA0240.eurprd05.prod.outlook.com (2603:10a6:3:fb::16) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e45cc2d5-c794-4b18-af52-08d955e6fb21 X-MS-TrafficTypeDiagnostic: AM6PR08MB4278: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:352 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0 X-Microsoft-Antispam-Message-Info: OmyPB8g+hKtwY9WQLyy/8rSv+F7/LnqSSEoLQ9B2zT9L8jFKKylIxRMExPbyE8XsJXmVoZAWgCsMNk+ilcGYmfXhfGVX1QLnemB3St248i7cCyjND5iTUZclpwGjQeofJ8uDRm0O8/WJQQtVr5NCkUDL+kmRfLb7Da6l+jr+KdvXWQmnB1oB2wASscr+Dk+SpxOfRP4fiIobLTRqYnUXQyjfM1kowjLJCj4qFCD0d+2yJ4qtTJgO+wWLHBo+djUSMcvIIYm/peXnsOwEPgdZGBPd6DMMFgS2QC7aP4vTkh+Y0D7HKd4bmlv6Q56Hu+1yvHJdoLo1wTXz6ld12+yyIjkJkswhDaWOLagYJOSgb3BAoeY4ses1eBLpDSREGOa4WO0MILscyqh2pIOCW5JYIykW2rIq4MYDRUni49vEUGqr8FqD64ogdFkrFtF4XWv/et8DJWwgJdiO3BViXDQD6ha3xhVFERfY4py4Hv+4kgH4XUTuSbx9bCmXcYaUOVGso0a9JIFAwxbuemAyk1jGFQphMAxahvPMf27GhLNsJSWnPSBcCCr7Nv/A9q6sqSQG9zttO2hTNJGrWD5+I5p2og3goR8TyRbZWBqqWcjEq/s27nvzdAotI23Go3RzZ0SSTX7PN1MEEYPzLjb6k6e3/x1j2FBVkuAm08Z6+Xc0tHIbtS/aBaG71l/3iEGu2eONYJEFS0RRyNjwmBrT6FvvYQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(376002)(39840400004)(136003)(396003)(366004)(186003)(6916009)(52116002)(1076003)(83380400001)(8676002)(6512007)(38350700002)(38100700002)(2906002)(7416002)(6506007)(2616005)(478600001)(6666004)(36756003)(5660300002)(8936002)(956004)(4326008)(86362001)(26005)(316002)(6486002)(66946007)(66556008)(66476007); DIR:OUT; SFP:1102 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?iIZqbLNbEcFcWpARwLAytnW+ElzI8nBhI8ijBvty2zeFhswpFpI8gN5cgAFW?= =?us-ascii?Q?ChnoWzXE7yB5kYoZjox4Hvo0+dxbUA9Xz5P+4jCquTqTb0hHDcwdcKC0yJkY?= =?us-ascii?Q?txQ16NzoCmxeLzTtApPEPk/qfci5iMxEaDeR/y8Fcvjh/KmGe8/CtEHyKtRq?= =?us-ascii?Q?HGFAkUlHLRqXwy0quvtJBh1xdwj0QwTK/80uXIcUR9cR4+wxLC/8eRW0fHrR?= =?us-ascii?Q?1VIKcRloZn5c8DQl24EMIwpYH9DM+FNcpdYaQ+mF9Iile+rC76k6oN8FC1GD?= =?us-ascii?Q?PMooZkicOvNnNDHwQaLE7mEMAI1CE/Kz2426ePc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VOFJ1zO04lFwGliBZO61ccaROdAeRqgV64yusazbQgcC9Daz6?= =?us-ascii?Q?AMks7AnuPaeWFHz4nLGu4UEDUXx5f4M2LmSHGSWMtqmHBzExI3INAST1yWvG?= =?us-ascii?Q?bIlMvmFUWKqSKunF3foiTZ/T?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: e45cc2d5-c794-4b18-af52-08d955e6fb21 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Aug 2021 18:54:39.5635 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: JZHBhgQNyE6PZAeEv9K6/PnNT5Pg4SPQwU08bLsjAE9csTyWs4yBMbfs1bdnV9YCMFiztTXf6jCTG5ovmifeyjEXvc5efk1Hu5DN2jqihYk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4278 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 172IsoFi006352 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, ehabkost@redhat.com, libvir-list@redhat.com, dim@virtuozzo.com, igor@virtuozzo.com, qemu-devel@nongnu.org, armbru@redhat.com, pkrempa@redhat.com, yur@virtuozzo.com, nshirokovskiy@virtuozzo.com, stefanha@redhat.com, den@openvz.org, pbonzini@redhat.com, mreitz@redhat.com, eblake@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1627930542152100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- block.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/block.c b/block.c index e97ce0b1c8..449f933661 100644 --- a/block.c +++ b/block.c @@ -26,6 +26,7 @@ #include "qemu/osdep.h" #include "block/trace.h" #include "block/block_int.h" +#include "block/block-parent.h" #include "block/blockjob.h" #include "block/fuse.h" #include "block/nbd.h" @@ -7501,6 +7502,47 @@ int bdrv_make_empty(BdrvChild *c, Error **errp) return 0; } =20 +static int bdrv_find_child(const char *parent_id, const char *child_name, + BlockDriverState *child_bs, BdrvChild **child, + Error **errp) +{ + BdrvChild *c, *found =3D NULL; + BlockDriverState *bs; + + bs =3D bdrv_find_node(parent_id); + if (!bs) { + return 0; + } + + QLIST_FOREACH(c, &bs->children, next) { + if ((!child_name || strcmp(c->name, child_name) =3D=3D 0) && + (!child_bs || child_bs =3D=3D c->bs)) + { + if (found) { + error_setg(errp, "node '%s' has more than one matching chi= ld", + parent_id); + return -EINVAL; + } else { + found =3D c; + } + } + } + + if (!found) { + error_setg(errp, "node '%s' exists but it doesn't have matching ch= ild", + parent_id); + return -EINVAL; + } + + *child =3D found; + return 1; +} + +BlockParentClass block_parent_bdrv =3D { + .name =3D "block driver", + .find_child =3D bdrv_find_child, +}; + /* * Return the child that @bs acts as an overlay for, and from which data m= ay be * copied in COW or COR operations. Usually this is the backing file. @@ -7653,3 +7695,10 @@ BlockDriverState *bdrv_backing_chain_next(BlockDrive= rState *bs) { return bdrv_skip_filters(bdrv_cow_bs(bdrv_skip_filters(bs))); } + +static void block_c_init(void) +{ + block_parent_class_register(&block_parent_bdrv); +} + +block_init(block_c_init); --=20 2.29.2