From nobody Sat Feb 7 10:15:17 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.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 [170.10.129.124]) by mx.zohomail.com with SMTPS id 1645832659217821.0500723782277; Fri, 25 Feb 2022 15:44:19 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-141-TEVwzigXMH62q0-tvb3fPg-1; Fri, 25 Feb 2022 18:44:16 -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 0DC6E100CCCE; Fri, 25 Feb 2022 23:44:11 +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 CD2118BD63; Fri, 25 Feb 2022 23:44:10 +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 92C6B1808814; Fri, 25 Feb 2022 23:44:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21PNhpMr027593 for ; Fri, 25 Feb 2022 18:43:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id D8DBB400E101; Fri, 25 Feb 2022 23:43:51 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D3D044010A12 for ; Fri, 25 Feb 2022 23:43:51 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 B89B080159B for ; Fri, 25 Feb 2022 23:43:51 +0000 (UTC) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80095.outbound.protection.outlook.com [40.107.8.95]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-486-dFAW-75UNHOWdZDAgyBpRg-5; Fri, 25 Feb 2022 18:43:47 -0500 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by DB8PR08MB4172.eurprd08.prod.outlook.com (2603:10a6:10:af::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21; Fri, 25 Feb 2022 23:43:38 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714%3]) with mapi id 15.20.5017.021; Fri, 25 Feb 2022 23:43:38 +0000 X-MC-Unique: TEVwzigXMH62q0-tvb3fPg-1 X-MC-Unique: dFAW-75UNHOWdZDAgyBpRg-5 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v3 04/11] block: bdrv_replace_child_bs(): move to external transaction Date: Sat, 26 Feb 2022 00:43:01 +0100 Message-ID: <20220225234308.1754763-5-vsementsov@virtuozzo.com> In-Reply-To: <20220225234308.1754763-1-vsementsov@virtuozzo.com> References: <20220225234308.1754763-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: VE1PR03CA0006.eurprd03.prod.outlook.com (2603:10a6:802:a0::18) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f1c04a6f-ccc9-49f4-9af3-08d9f8b8a54a X-MS-TrafficTypeDiagnostic: DB8PR08MB4172:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0 X-Microsoft-Antispam-Message-Info: cv/Jfqocji2yX5vSUAmS/OI+mU/wXeHc3bvhBUJLrbaK81GxxflxLT+03fvXh+N3WcQxUnIU4FThNjdM8fb+8zoyxJncvIUhpYjMwQqUZmlQWYI76plPAgtVa4ZSP43vUcC13C1Z9fl+9oAOuetLrDCpnbWPE9pGdBLCJMeIIjEFOzALxlhOD+RKVYXELLMBbClJt17Jw7R22xtDEytD/bTpjnuWGu9XH88U6kpJCwc4KOIIxS/6FgnXMBZ6AM5MHZvgLEh4wS8/u5L3trVQGfmsQI39Z7rmhvYua04tKgJaHtseLnW7r64ufu+7J/n+fCVFhAsPmsiPXdeMy9+l8xEZY4735bazA2MHZi7l/vAgtt3seseVZ1a5KlWtuzzrA66d1gLtTpdc3yY7ycCI9m37874Xt3Q2zrbf6gz1R+p/JAeMNSk8GUVCSlTVeWEnwxNcziyBK1MkO/OVj82B+ijKjUKCEMRHnUaXTzh9Zt3PB3UMYGKhtdYab4aOkyvfMKb9BAjp1txyET1ZG5ddcOLGnMF2i6ZTYy5WPyk6l1UYmRZ5CAx4dHEJnDdf8Y3f02FS4MAwt/+MHxaRuUnEprmXqMnkcSbyu270BqGesDgTVdo7VKEP6fi7MtRF/Z84TCX+v85h3c0+Krthm3qcB9djyBoMcPmhOJeUll4n+plBAxJnG1LbFYt4tmwN2ZagdCst1B7b1UvZ0vNtZ1TxRA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(6916009)(6506007)(8676002)(66556008)(5660300002)(83380400001)(6666004)(7416002)(8936002)(52116002)(508600001)(6486002)(6512007)(2616005)(26005)(316002)(36756003)(38350700002)(1076003)(38100700002)(2906002)(86362001)(4326008)(186003)(66946007)(66476007); DIR:OUT; SFP:1102 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?0y2hBbaoe16Hm5oe6Iv2H1dGLDPzekTjyhxbSwhqC8FMKOuX6kUzsg377atU?= =?us-ascii?Q?uyUUFJZ0C+IaRQTo4nXFhDDGmkYnxMXU1W2TuhpQF3QnwNcnf+8BnJ8TZelL?= =?us-ascii?Q?7O7+3MAw9GFM/g7oaq4hshlVgRrgHYdLB29CK7JsmQagfvrLiWI0DT7mk7Gb?= =?us-ascii?Q?SvsiRR1OgFLcw59wKO+Eb2T7ZF3FRBE1777xelCnuwsY5hh+v/sWlDCFc2zj?= =?us-ascii?Q?KPjkLtYrdXci86Mvd0CvPusPf/bpuC9msO+dnfBQyLsNb7PLy4qJpYYxeh3Y?= =?us-ascii?Q?AbbVpkeAQuaV/u17wCtaEvKzb7F25xYntJY41XkBmR2qhKTQaivh0TUllL7d?= =?us-ascii?Q?Cs07izjz5TiQIvKha3Cg5FXFftoGOwAPBNXorpHQoFWTzB3RGbz1H22/j2B5?= =?us-ascii?Q?TK0ZpOZTt/HbC7rGvxOnI9EXP+BcJwdyMlzhz7Dk10POZp2jozYlsuHV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QWmjVtcqaF/r5tF2osYUxrcN0urEVUja7+T4dN?= =?us-ascii?Q?jB7LDBa++0LsY5a89QPBY/UqnHlo6bIAXm0n9ZNCGQxd13Baem/+TPhjDXtg?= =?us-ascii?Q?YLSwTnnbqS9RfQIN8/3cgP50/iJWph6B/w3k5YUrpwPap5llOLVrhSAfiUCZ?= =?us-ascii?Q?EcJLWXC5ttwDXF4dESvTOYLriWHlIEDLfJilvjIGUZ6la1YVqFEtkM/41+Ob?= =?us-ascii?Q?oJBW6bOJ2YPtfIs4qScSBmQigutn+hpM7/r5v5GompjGJrYes2D3tQX4dCa+?= =?us-ascii?Q?5bqP9nU4UKlb4uCJIvzfKJnl3cMq+GZbw9AuQQJLueitKc1lU+ELbjtR1uBy?= =?us-ascii?Q?XBSjLkkvq3U2brVgdJrrcBE9+js=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: f1c04a6f-ccc9-49f4-9af3-08d9f8b8a54a X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Feb 2022 23:43:38.1217 (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: 2Hunq56/z7yUP/ED7uEyxQ/fZJTIqt+pwK59DjzAkpmRiL2jlyCdDCnefmfLHgNiRf4Up9OQsFEeX+EQeMfMzBlVs15JQ0+BN/y0lXMhHys= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB4172 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.84 on 10.11.54.2 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 21PNhpMr027593 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, libvir-list@redhat.com, dim@virtuozzo.com, igor@virtuozzo.com, qemu-devel@nongnu.org, armbru@redhat.com, hreitz@redhat.com, pkrempa@redhat.com, yur@virtuozzo.com, nshirokovskiy@virtuozzo.com, stefanha@redhat.com, den@openvz.org, pbonzini@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: 1645832660162100002 Content-Type: text/plain; charset="utf-8" We'll need this functionality as part of external transaction, so make the whole function to be transaction action. For this we need to introduce a transaction action helper: bdrv_drained(), which calls bdrv_drained_begin() and postpone bdrv_drained_end() to .clean() phase. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/block/block.h | 2 +- block.c | 42 +++++++++++++++++++++++++++--------------- block/block-backend.c | 8 +++++++- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index e1713ee306..1cc1f736c7 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -362,7 +362,7 @@ int bdrv_append(BlockDriverState *bs_new, BlockDriverSt= ate *bs_top, int bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, Error **errp); int bdrv_replace_child_bs(BdrvChild *child, BlockDriverState *new_bs, - Error **errp); + Transaction *tran, Error **errp); BlockDriverState *bdrv_insert_node(BlockDriverState *bs, QDict *node_optio= ns, int flags, Error **errp); int bdrv_drop_filter(BlockDriverState *bs, Error **errp); diff --git a/block.c b/block.c index 601fee163b..b2f55ff872 100644 --- a/block.c +++ b/block.c @@ -5204,19 +5204,39 @@ out: return ret; } =20 +static void bdrv_drained_clean(void *opaque) +{ + BlockDriverState *bs =3D opaque; + + bdrv_drained_end(bs); + bdrv_unref(bs); +} + +TransactionActionDrv bdrv_drained_drv =3D { + .clean =3D bdrv_drained_clean, +}; + +/* + * Start drained section on @bs, and finish it in .clean action. + * Reference to @bs is kept, so @bs can't be removed during transaction. + */ +static void bdrv_drained(BlockDriverState *bs, Transaction *tran) +{ + bdrv_ref(bs); + bdrv_drained_begin(bs); + tran_add(tran, &bdrv_drained_drv, bs); +} + /* Not for empty child */ int bdrv_replace_child_bs(BdrvChild *child, BlockDriverState *new_bs, - Error **errp) + Transaction *tran, Error **errp) { - int ret; - Transaction *tran =3D tran_new(); g_autoptr(GHashTable) found =3D NULL; g_autoptr(GSList) refresh_list =3D NULL; BlockDriverState *old_bs =3D child->bs; =20 - bdrv_ref(old_bs); - bdrv_drained_begin(old_bs); - bdrv_drained_begin(new_bs); + bdrv_drained(old_bs, tran); + bdrv_drained(new_bs, tran); =20 bdrv_replace_child_tran(&child, new_bs, tran, true); /* @new_bs must have been non-NULL, so @child must not have been freed= */ @@ -5226,15 +5246,7 @@ int bdrv_replace_child_bs(BdrvChild *child, BlockDri= verState *new_bs, refresh_list =3D bdrv_topological_dfs(refresh_list, found, old_bs); refresh_list =3D bdrv_topological_dfs(refresh_list, found, new_bs); =20 - ret =3D bdrv_list_refresh_perms(refresh_list, NULL, tran, errp); - - tran_finalize(tran, ret); - - bdrv_drained_end(old_bs); - bdrv_drained_end(new_bs); - bdrv_unref(old_bs); - - return ret; + return bdrv_list_refresh_perms(refresh_list, NULL, tran, errp); } =20 static void bdrv_delete(BlockDriverState *bs) diff --git a/block/block-backend.c b/block/block-backend.c index 97913acfcd..dbbbc56b2c 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -892,7 +892,13 @@ int blk_insert_bs(BlockBackend *blk, BlockDriverState = *bs, Error **errp) */ int blk_replace_bs(BlockBackend *blk, BlockDriverState *new_bs, Error **er= rp) { - return bdrv_replace_child_bs(blk->root, new_bs, errp); + int ret; + Transaction *tran =3D tran_new(); + + ret =3D bdrv_replace_child_bs(blk->root, new_bs, tran, errp); + tran_finalize(tran, ret); + + return ret; } =20 /* --=20 2.31.1