From nobody Sun Feb 8 22:06:30 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 16279305292161014.57614630693; Mon, 2 Aug 2021 11:55:29 -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-435-KGF95qNPMgqZNe8gTuDFJA-1; Mon, 02 Aug 2021 14:55:26 -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 1842018C8C03; Mon, 2 Aug 2021 18:55:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9BDE74A66; Mon, 2 Aug 2021 18:55:19 +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 F0D1B180BAB2; Mon, 2 Aug 2021 18:55:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 172Ism8m006346 for ; Mon, 2 Aug 2021 14:54:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id A1E7A214700D; Mon, 2 Aug 2021 18:54:48 +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 9A0142147012 for ; Mon, 2 Aug 2021 18:54:45 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.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 C738989C7E1 for ; Mon, 2 Aug 2021 18:54:45 +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-sZ6TMAncNmqocqEc8c5hyQ-1; Mon, 02 Aug 2021 14:54:41 -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:37 +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:37 +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:35 +0000 X-MC-Unique: KGF95qNPMgqZNe8gTuDFJA-1 X-MC-Unique: sZ6TMAncNmqocqEc8c5hyQ-1 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH 2/8] block: add BlockParentClass class Date: Mon, 2 Aug 2021 21:54:10 +0300 Message-ID: <20210802185416.50877-3-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: 989e2429-7e7c-44bc-027c-08d955e6fa03 X-MS-TrafficTypeDiagnostic: AM6PR08MB4278: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:216 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0 X-Microsoft-Antispam-Message-Info: 8ur9WUP6aYKwKDMteWePsHr3FowifmPOjuvbxmWyqze61kiWUoZoj1xf8FYvwWJ/jdIDiH7crRVJ6DBUFTmdhopk6BMfBDBWBsDMhzrXCWJzb4RlyRGZERJo8+YtMg1dZCV9ZBnxoyK2MmWelZpmSQ/9TZVDWjNe+zKICWDKA3CebINGyULa2ePs/UjdQinaOJFjZrbykL1CHsjOP40yuOMbShTyeAGI7EInMwwWwg34cA1M85nhWyYv8PjkQ98BTtF2xYOs+Ms+lkVKTDAP5W6cQsB2ap0Q0m9SiKOg9oXF8Drl6639wneu+ySAoYLewy7LXkxgZ59ocbSlCmqhV7JvCYBFbDy+AlMjgNmfeTKupBLK7OFrepUaoJkT51F+DQnUo3Ig9vO8ywLjAOXjFQjknit1N7b9LUzC1Yn/DNSrcdrXeEitHkO153vpQfIRlVcmTVHi5jzc7+XtLhDR6YNo/La3n3xUSZMMrFTILqVeXJ5c5fCFIRaXQFqiN1hTCWXWEHTARbXaKHAT7snP9zjKlsWUoJV61opYm72+cWgzAkIbRJo3hmZ5YO4h/oawMKTNpLIsydEucNXxv5DZca7aLlzw74FoKF2i5AQG67ThxO8OEelVSSCW1XqeUSdyHbqv7xRtaYtikX4hdoajkx5sU2ziV6wOk8La2I9fj0KAncbWsBAraRWsbSJVi0JKXA0hjkhy7FNZFcR4JHGl8Q== 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?X4lsBvSvbklHDSNGwrJyyIg2w6PlJG/zubKlfQKsq4a1V5y0DDqhIvw0AxwQ?= =?us-ascii?Q?H0moPI1MyQ2j/J7fp2zMpjHDtBglRQHh/7BFamBy0T57OHElwJwmGNCuDTJG?= =?us-ascii?Q?CCCMtxBb/dXaY4ul8pXvbqL3L/SaQFyfgRGVmuj+WWRBSXPD2M0QfB/7dG8L?= =?us-ascii?Q?dVMRQxgnPn3N1dLEhRipH/P2X8JwUxHKx3GDSFMVqV7ZlWgwNlwOTc0sWV+X?= =?us-ascii?Q?LahKr89rMksnxQ7P7RzJFeJ5n9RGtvEDiMLEbk3MdClHCS89qBTFr4YSnPBx?= =?us-ascii?Q?8S6mDqTQ4s3CnI8A6fZ5vL38J5SzKWJAFBcXP+3vJK8/BKu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p1OSugFIl/AtVvZ/q19hAWRHV4+vdk4qU?= =?us-ascii?Q?+o1Ef8PG3yZfQ3aWg8fYZpClxhCroZ92hVVVUlR6hixgDPXcHnJbY8r1MOhV?= =?us-ascii?Q?L4ewT++FwRfVErV/iCHbB9NR?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 989e2429-7e7c-44bc-027c-08d955e6fa03 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:37.6429 (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: g8y4JYKBpB5at5mX6XcO/WhhddPnappkcxSAftbuJ9srcRPnALXs/CqzH15X+1HQjnwPZR20zLNcPPCY63ru7yNSmn3Dm07P7DIzAjFpcwA= 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.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 172Ism8m006346 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.84 on 10.5.11.23 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: 1627930531945100002 Content-Type: text/plain; charset="utf-8" Add a class that will unify block parents for blockdev-replace functionality we are going to add. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/block/block-parent.h | 32 +++++++++++++++++ block/block-parent.c | 66 ++++++++++++++++++++++++++++++++++++ block/meson.build | 1 + 3 files changed, 99 insertions(+) create mode 100644 include/block/block-parent.h create mode 100644 block/block-parent.c diff --git a/include/block/block-parent.h b/include/block/block-parent.h new file mode 100644 index 0000000000..bd9c9d91e6 --- /dev/null +++ b/include/block/block-parent.h @@ -0,0 +1,32 @@ +/* + * Block Parent class + * + * Copyright (c) 2021 Virtuozzo International GmbH. + * + * Authors: + * Vladimir Sementsov-Ogievskiy + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef BLOCK_PARENT_H +#define BLOCK_PARENT_H + +#include "block/block.h" + +typedef struct BlockParentClass { + const char *name; + + int (*find_child)(const char *parent_id, const char *child_name, + BlockDriverState *child_bs, BdrvChild **child, + Error **errp); + QTAILQ_ENTRY(BlockParentClass) next; +} BlockParentClass; + +void block_parent_class_register(BlockParentClass *cls); + +BdrvChild *block_find_child(const char *parent_id, const char *child_name, + BlockDriverState *child_bs, Error **errp); + +#endif /* BLOCK_PARENT_H */ diff --git a/block/block-parent.c b/block/block-parent.c new file mode 100644 index 0000000000..73b6026c42 --- /dev/null +++ b/block/block-parent.c @@ -0,0 +1,66 @@ +/* + * Block Parent class + * + * Copyright (c) 2021 Virtuozzo International GmbH. + * + * Authors: + * Vladimir Sementsov-Ogievskiy + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "block/block-parent.h" +#include "qapi/error.h" + +static QTAILQ_HEAD(, BlockParentClass) block_parent_classes =3D + QTAILQ_HEAD_INITIALIZER(block_parent_classes); + +void block_parent_class_register(BlockParentClass *cls) +{ + QTAILQ_INSERT_HEAD(&block_parent_classes, cls, next); +} + +BdrvChild *block_find_child(const char *parent_id, const char *child_name, + BlockDriverState *child_bs, Error **errp) +{ + BdrvChild *found_child =3D NULL; + BlockParentClass *found_cls =3D NULL, *cls; + + QTAILQ_FOREACH(cls, &block_parent_classes, next) { + int ret; + BdrvChild *c; + + /* + * Note that .find_child must fail if parent is found but doesn't = have + * corresponding child. + */ + ret =3D cls->find_child(parent_id, child_name, child_bs, &c, errp); + if (ret < 0) { + return NULL; + } + if (ret =3D=3D 0) { + continue; + } + + if (!found_child) { + found_cls =3D cls; + found_child =3D c; + continue; + } + + error_setg(errp, "{%s, %s} parent-child pair is ambiguous: it matc= h " + "both %s and %s", parent_id, child_name, found_cls->nam= e, + cls->name); + return NULL; + } + + if (!found_child) { + error_setg(errp, "{%s, %s} parent-child pair not found", parent_id, + child_name); + return NULL; + } + + return found_child; +} diff --git a/block/meson.build b/block/meson.build index 0450914c7a..5200e0ffce 100644 --- a/block/meson.build +++ b/block/meson.build @@ -10,6 +10,7 @@ block_ss.add(files( 'blkverify.c', 'block-backend.c', 'block-copy.c', + 'block-parent.c', 'commit.c', 'copy-on-read.c', 'preallocate.c', --=20 2.29.2