From nobody Thu Nov 14 18:13:16 2024 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; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1629794689; cv=pass; d=zohomail.com; s=zohoarc; b=abZNQ5AQshONse8TkFVPPU9m9J09DZgy1jk9VH7LULTl+kmjnYs7DS+ZnizuO3JIN3GiFv7FRJvM5RMwrIffm/uFCrhDOcX/Ix2FLb5/HlVX9JQX5J9ie+jN9LJnSmyUKy1jnX1blro4CxBZLn5xBMFPnsirc9wriuoaTGsgya4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629794689; 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=+Y9zwZ4FG3jmKMdQhuvSmetg9/t2U2WeUmbUBzVXQuA=; b=kvrkBNmvrDY+5GcpYooakqnL7Sexzo75q/6sw31eVA5tkhZpCd/dZ3p9smqHND7NWUjbKUfyOaw0DcZEVtsyDh5eX35/WbSoOu03tWnFq/uxMnw3cKYdgINZVEm2f/rcrg5OvHD+vJtwHoIHrBT6HKxQvwAOf+652h3Acx6IkSI= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1629794689141463.20271462130245; Tue, 24 Aug 2021 01:44:49 -0700 (PDT) Received: from localhost ([::1]:36538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mIS35-0004sZ-CU for importer@patchew.org; Tue, 24 Aug 2021 04:44:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58814) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIRyF-0002dO-4T; Tue, 24 Aug 2021 04:39:47 -0400 Received: from mail-db8eur05on2134.outbound.protection.outlook.com ([40.107.20.134]:13121 helo=EUR05-DB8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIRy9-0007US-8g; Tue, 24 Aug 2021 04:39:45 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5333.eurprd08.prod.outlook.com (2603:10a6:20b:104::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Tue, 24 Aug 2021 08:39:35 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::3c5e:7829:362d:1423]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::3c5e:7829:362d:1423%2]) with mapi id 15.20.4436.025; Tue, 24 Aug 2021 08:39:35 +0000 Received: from localhost.localdomain (185.215.60.249) by HE1PR05CA0178.eurprd05.prod.outlook.com (2603:10a6:3:f8::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 08:39:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fsaZg3t+B398tfCi+/4p7ygIIgKv1m1Wcd0uoGXvMuFGyyIGGUWevQAi70wM+6ZR+un8xwmyfNfCeNzZ/1tTlulMpa/fPJgkW0BZo+DF4k9MbzCMVbaniVg7NDr5BVcK+FKp19mAU+FzUg0lDXkcwmE+u411xCk2JhErFbeIuJDBfcYIPglgfKMzO+yQCRUnme5KbFrJ7MZso3DtJGljil8IxAM6Jkw8dhF4hK0A7ZibIW2f6PJtapnvhs0w/9SejtZZ4iHt+w8MJSOVwDeVV+pYc6xBp0PdyeWCToq4SnwH8v5OWZs0YKwGN1QVft5ZZJxMiYlVi0edfxrR1rBpaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+Y9zwZ4FG3jmKMdQhuvSmetg9/t2U2WeUmbUBzVXQuA=; b=H7N1rdJBat2VC1z4tqDEhKipEHQ3+jp45JJdaiH6E3Tw+rtgyhFyP1LxZqg4eN2WeXec1zQMEmKef4Hu3jZQoxC6T8i7MsdzTIOyMyuUCp+/mnyoV+iR/+jypMQnFXQPVfAC0pKgIUwuEIBMb+B3fRPZLX0ad/GvJhsP9LJahCz51YchWlu/Sg0QDb5dyWvhd/MXxwxr9FYDbJ+fCocyIrvo0LYTMT75IB0BbBPjjIM+5oftv78tpUn/j5YVeLj1mVtHsOz0bp9DA0g+yqsXXTCKZoJimC6lCk2w5M4ucsH8TmdR42WCrbzihawEWH3sI0OYrLL+0SrjDkipqS2LBQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+Y9zwZ4FG3jmKMdQhuvSmetg9/t2U2WeUmbUBzVXQuA=; b=BbrvYLHTgzHjp9CMYstjDFFNgO9TkDAXKnmgW+a86pNU1TQpMM0M3p69e1cYrShMetgm6M2DCPFAgPKitVE2Ljo/s5Dv66FIYUb48NlMAilhlFcY0QK6UtsqxuByaS28d+SA6t4zrF1HXBsHjlk3FTVsvY66obxVw5MV57nb6fM= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, eblake@redhat.com, armbru@redhat.com, crosa@redhat.com, ehabkost@redhat.com, berrange@redhat.com, pbonzini@redhat.com, vsementsov@virtuozzo.com, jsnow@redhat.com, hreitz@redhat.com, kwolf@redhat.com, Max Reitz Subject: [PATCH v8 13/34] block/copy-before-write: bdrv_cbw_append(): replace child at last Date: Tue, 24 Aug 2021 11:38:35 +0300 Message-Id: <20210824083856.17408-14-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210824083856.17408-1-vsementsov@virtuozzo.com> References: <20210824083856.17408-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: HE1PR05CA0178.eurprd05.prod.outlook.com (2603:10a6:3:f8::26) 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: d947d736-f8c4-4a10-b24e-08d966dab3b8 X-MS-TrafficTypeDiagnostic: AM7PR08MB5333: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1013; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: h0pS1bzV4dsXj66Xfg3jWRYXmY3swgL/4AvzVzOZ9+nP414AKfm13i+EwX1oLfC/BqeApJiJdM/1tBbb0b5s3FFvXUXgQbxAFeHdAR/MRCmD2Gu9kvt4nqbagEqPwYDJqmw08LVWjV7sbiSUxXH37mZwxXELillX7Vd92hK4MNHKuH5snWS4IDIcovecTMlk+qEM3nr6UqxogeMpoxwWqD3oEfSEG91xMUoWRKwUn4hTBswh8zfOtduigwG6Kk0FlUv8jw21fuZRU/gJDkGccWGe2Rxw7MaLQLrmVTJ7/q7DFx4nM0WFAiw+is3Qfd8pCRJU2E6crfONI8lW044qvrsm4HTZ0IPvbIkVePS3qyuqB7E6Hb3WTdVoTAI3VNJ2RlSOat+ayFPgYrwTN67muHn3OcXLHpcVsDeX6/TkyZeV4kWaQxbOGh3eq/ZdwF8MuYl4D5uxVnpHEVNJhHMLFe9wO6XxT33IdRz5Wgds4tlgnrxCpWugycbhRenzQNQewJEevw4zb+j3l7GFTQ1dPqF1ddhP4G6GA8ezn5gi678lrxCYWd+gCdBuNqkAAerAssI4BpRMRYfcb8O7IdlyOl+Hpz6QjFaSs1017tv1dqTxex3kdXE4vaW9jNslOKPostMYDGyjIhbnYzCZqFaAK2hVXA+0Tja32DOir4kmgQWe+eKSt/QE9OzCysW9e1OYhzIZQ9chswblt9VE/i+a/Q== 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)(136003)(39840400004)(346002)(396003)(366004)(376002)(38100700002)(8676002)(4326008)(86362001)(52116002)(38350700002)(83380400001)(7416002)(8936002)(6916009)(5660300002)(478600001)(26005)(1076003)(6506007)(6512007)(186003)(2616005)(66556008)(36756003)(66476007)(66946007)(956004)(316002)(6486002)(2906002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?x3PzPwI1wQZ/1SrJ/+EWmtUOKTZckz454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-ascii?Q?EemKxd4w6GpbA6vhLrSUPE7RUzG6qkvGssqbJRQcUvK/RFGGCa790NrIejyM?= =?us-ascii?Q?zrP0tp9IFc+mAKsX8YrJJncyMQcCxuz9kuePp1NxD3JG811o2T5/qZHWbnnB?= =?us-ascii?Q?hxep1nlf5zfHWlkyBVO9uizWpoT8Py07ym1VK8TPJBUienm9G40qFYyNY/J3?= =?us-ascii?Q?drul2ntoNAyj94NsaH1SqCf7hAEx1gxFd+nZ4Br2WK/5BwbwH86cSj0k3UZP?= =?us-ascii?Q?0kKa7Fq/nqw8UhUZ3LFLdjAaBCZDY8IEyt829TlVEWLe2EOdtZD1j1E+KRDA?= =?us-ascii?Q?oz4dwXKEL1v4lqrLTP61ZADhc5HS5dM+x1iA3l/HuX8lKMLF1fFBpgqLVk14?= =?us-ascii?Q?fY2pe2P75naElcGmLLBVViSuW3NME3S29eRqANer/7iYvmizgBGss+zPUeDM?= =?us-ascii?Q?uNsXhCaTgv5vVlVM8TBVfb/E?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: d947d736-f8c4-4a10-b24e-08d966dab3b8 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2021 08:39:35.5248 (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: cvb8/XkE70Y6mN0WdoEBk56k1bYfPi4D6z78rw3sktCMbJTU/nAWVPFXJoZGgR5jQFbzV1Gfqr+m1e+R6Zh0e017PWd1whUg1VqoDeSYJ48= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5333 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=40.107.20.134; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-DB8-obe.outbound.protection.outlook.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1629794689611100001 Content-Type: text/plain; charset="utf-8" Refactor the function to replace child at last. Thus we don't need to revert it and code is simplified. block-copy state initialization being done before replacing the child doesn't need any drained section. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/copy-before-write.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/block/copy-before-write.c b/block/copy-before-write.c index 7a6c15f141..adbbc64aa9 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -172,7 +172,6 @@ BlockDriverState *bdrv_cbw_append(BlockDriverState *sou= rce, int ret; BDRVCopyBeforeWriteState *state; BlockDriverState *top; - bool appended =3D false; =20 assert(source->total_sectors =3D=3D target->total_sectors); =20 @@ -196,8 +195,7 @@ BlockDriverState *bdrv_cbw_append(BlockDriverState *sou= rce, BDRV_CHILD_DATA, errp); if (!state->target) { error_prepend(errp, "Cannot attach target child: "); - bdrv_unref(top); - return NULL; + goto fail; } =20 bdrv_ref(source); @@ -206,18 +204,8 @@ BlockDriverState *bdrv_cbw_append(BlockDriverState *so= urce, errp); if (!top->file) { error_prepend(errp, "Cannot attach file child: "); - bdrv_unref(top); - return NULL; - } - - bdrv_drained_begin(source); - - ret =3D bdrv_replace_node(source, top, errp); - if (ret < 0) { - error_prepend(errp, "Cannot append copy-before-write filter: "); goto fail; } - appended =3D true; =20 state->bcs =3D block_copy_state_new(top->file, state->target, false, c= ompress, errp); @@ -225,21 +213,22 @@ BlockDriverState *bdrv_cbw_append(BlockDriverState *s= ource, error_prepend(errp, "Cannot create block-copy-state: "); goto fail; } - *bcs =3D state->bcs; =20 + bdrv_drained_begin(source); + ret =3D bdrv_replace_node(source, top, errp); bdrv_drained_end(source); + if (ret < 0) { + error_prepend(errp, "Cannot append copy-before-write filter: "); + goto fail; + } + + *bcs =3D state->bcs; =20 return top; =20 fail: - if (appended) { - bdrv_cbw_drop(top); - } else { - bdrv_unref(top); - } - - bdrv_drained_end(source); - + block_copy_state_free(state->bcs); + bdrv_unref(top); return NULL; } =20 --=20 2.29.2