From nobody Thu Nov 14 06:54:00 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1621521433; cv=pass; d=zohomail.com; s=zohoarc; b=Tkvh676gqQcUXDl3MFS8F6cmugTU94YCClcnzsRXRkQbmM5DweK/S538xhTeCewG1vWjQ+KhLmqARRPauu83TTfFJq1+9d1way/nX0c/vzrr3qv7l+KVGPgoMaPVUKzK2b1usiM5kFGERNKCrs7bnHmOW2basnRsdedGHO/kcz8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621521433; 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=ULbIfGle2hk6n2Q+v6LxIxzjL5NY6wdwu5ZWXwnhWDY=; b=E2WacvM0VxE51jyzBbmZLBl+qdAqE7sCvsGtEl4J8enOecAfo7mfol6b4IdPqwB3OddNOt6g0qRRtFlgWNYP1EfqCMDRiFsPzsTXHOUI7gXybeeZnA+SRlKNkQAFYTxMB7dB4366KMZ+GIrGmUfebUM0GKYl5gg9VwRHOhSxvXg= 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1621521433362155.24037303034493; Thu, 20 May 2021 07:37:13 -0700 (PDT) Received: from localhost ([::1]:56060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljjnU-0002PR-8K for importer@patchew.org; Thu, 20 May 2021 10:37:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljjZs-00068r-Vc; Thu, 20 May 2021 10:23:09 -0400 Received: from mail-eopbgr00114.outbound.protection.outlook.com ([40.107.0.114]:2638 helo=EUR02-AM5-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 1ljjZp-0005ik-LK; Thu, 20 May 2021 10:23:08 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB3544.eurprd08.prod.outlook.com (2603:10a6:20b:4e::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.25; Thu, 20 May 2021 14:22:43 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4129.033; Thu, 20 May 2021 14:22:43 +0000 Received: from localhost.localdomain (185.215.60.197) by HE1P190CA0034.EURP190.PROD.OUTLOOK.COM (2603:10a6:7:52::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.23 via Frontend Transport; Thu, 20 May 2021 14:22:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TGFBimQe9hONPEn6uaWyvVFLPsPIuseBovdlEPdtltALZPiHaJimTHxuTIgnLRdd8WqhafWPcr2q4hopEC+YyJ60P5QpEH+LOCDLXByoT17AJg0fIiPv2Zw+/WY1LzXeNdMatzaDK7zdGQIsDlnwuQkTLn1PmfufLqCd0LFmgp4PPJ8RqhzL61oZqia2GE+5Rfq5pK6MFxopPQZ/ynOjzIThNp/HJ1RL+4JSwhNddJDND79f5gOCcw9h3q/tQAwXG4+QSfq8j+SR3WUYoYLlzlNKLzt/adJaZLET+C/P99mMxcBHlh50ueUqL46of42ggxJho4zUQZfdC/SQfmIlcA== 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=ULbIfGle2hk6n2Q+v6LxIxzjL5NY6wdwu5ZWXwnhWDY=; b=Y5OnXceRuKQn2uMfUdTdf9g+YH0ek0yFNgYky8E+Y0GaAW7dIfZe9XTYETuTMYbWB+aFyN9XU3Wu19Bb0xd/pVMTACBXEjKKNr16LfsoT59fNTxnXPff10TrHZImatOZ8S1m2xCnkH3g7m56fjsrtoJIvqZKaUDgqQ2iyFjw1LGNEJuCbAV4cU//safweqPPL9xAZL3+CE1vzU2M8T85awBiegA7qqFGMIrPr7vCHRe+4LxhU7kbl/psRP8pUYHzyMwjbAVNg+CQdhgu3cYfsF4HMzmHZJBlAWpBqmZpqooeAMhKQhb14y4Gz8iNO/2vjDKoIzHda9sw3VS93MNYwA== 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=ULbIfGle2hk6n2Q+v6LxIxzjL5NY6wdwu5ZWXwnhWDY=; b=dG0jeFjNhei3lQlQLWfzOyBMdMLFBlJ6FXrkUdDjQku/71twk12AtI+WM+3XYNV8FaNTmWlee/yyhcA8afvv8kRGJ1/eKNia9mm66cmAQLfPgM+7O+sO66JrqpDBeWqGG/Cn76TG06qqeWBJAim0jmSt5v+B/h3BsnIg6QmmFbg= 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, mreitz@redhat.com, kwolf@redhat.com, den@openvz.org Subject: [PATCH v2 15/33] block/copy-before-write: introduce cbw_init() Date: Thu, 20 May 2021 17:21:47 +0300 Message-Id: <20210520142205.607501-16-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210520142205.607501-1-vsementsov@virtuozzo.com> References: <20210520142205.607501-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.197] X-ClientProxiedBy: HE1P190CA0034.EURP190.PROD.OUTLOOK.COM (2603:10a6:7:52::23) 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: fbc9def4-ece7-4a42-65e7-08d91b9abbb2 X-MS-TrafficTypeDiagnostic: AM6PR08MB3544: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:813; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gfIlSY9StB0VNi/h7Nu0hT13RiG6wdFInftAij5wAPjx91X2gG/8kl411PVcoeybLY3qliH8L6YhwWWbJfK9BpfkfBTOvHiEYM6HLrrOzdh8TFXpD7ySKk62qIUYxBQr3FaTiUyf6qJuQpx/7mYbfDR/McSzyvVshLRX1ccOf+Ea8G3iuW/NuFQMpe0OMAi8N4fVUh7ejffhkcQbXwy1BmQ0PV7vBKo416bZcu+9pcgMVa4HLX7S0vYcEtNNbzGg48PPi9zmlKX45LhVV7RcrPOteNz9xjY8DsrCW4BAOpL9l3Fq3bQ1/+hdfESK14CkqovjZhnm+abvRFmZq1nQTyqWssyuurrfkNj8ycTobEsjZ2QZnigAhs1a/vhMIlw3EKwo0J6e7WOSXAm/ml9uP02inTCSGaat8lpUpCKjGwzS8qDRqczoIJ3v89pCY/ycNk/c2JpzICQgKvWcS3SjqT9nWomewybNBpsLocr2NN1pPb19DZ3KtCtv56VMk9fmGZO1JJt2PEKmkGPistc/XSFUIUCIS4OuRByyCd4aCdU8n0kF73cKuGynPTXUcwZiVtcFecpNwZq8OnE+aM6YLQ/AEYHWCxJqI+gOoetzHQDvVK2aG2zTAcvX38TKlkTnAtZqNM+8yfOe7Bdfic3Wh8x+YM6ZKjN5w0SarP72k/YvepAU4a4oBB18it1BOPe3 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)(366004)(346002)(376002)(396003)(136003)(39830400003)(478600001)(1076003)(52116002)(86362001)(66946007)(66476007)(4326008)(6486002)(2616005)(66556008)(956004)(26005)(5660300002)(6506007)(107886003)(7416002)(38100700002)(2906002)(8936002)(36756003)(186003)(316002)(6916009)(6512007)(8676002)(16526019)(38350700002)(83380400001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?1Fbpl8j1nHecqVDjrCn1AyIGXS09TyE7fSC7fCXktxdCkd7Cc35Kg23Uj9Kn?= =?us-ascii?Q?t+TE8sI39DpTZyh7Q5mbD5dVKf0UPM3BrBNZM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RrqpDzsNIMz2JMlu91Vxk3gDL4q9b5meWFXv+Mj/s//HaOWEoJEGC2fQ?= =?us-ascii?Q?qDrCoM7vNcrfQhf+py3G/wJjuPzo5OUGQYbK7mE0SOC/11Uuiaitk+5ROr7r?= =?us-ascii?Q?8PC3/IrNSE7AArPex6z0wsRYH36jywm1IYQKVbj5d1qaejwYhRjLio0Hm9Qz?= =?us-ascii?Q?iUEkeKtXuDzy1bG1DlxjGoOyuwH2/O2ZfcTxbBAT33N61uRgdelhnQ6i0bOO?= =?us-ascii?Q?oGyDSu0ipafjo0ezPYjJ43aqKBhLRuf1xRh2TQu1ulTbrM19VW51a3IiVjhf?= =?us-ascii?Q?ECPEWUsUgQchK5PQsKICFIySBjXyTJxWvnO+bXOoPWGibLIXtDy/rYpbIJMt?= =?us-ascii?Q?JGRAFPa0kA453TS7m7vT8AqY?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: fbc9def4-ece7-4a42-65e7-08d91b9abbb2 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 May 2021 14:22:43.8675 (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: s6zM/E2YYrC+AOvpYS0xtEhioATG7MtjPk03P5nWhRuNILQ3o/skTAfuVWEbWtypFOH/xpMczLi0pagFavzRkELlxWkZjXGUSoVBhKi8x0w= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3544 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.0.114; envelope-from=vsementsov@virtuozzo.com; helo=EUR02-AM5-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_HELO_PASS=-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.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) Content-Type: text/plain; charset="utf-8" Move part of bdrv_cbw_append() to new function cbw_open(). It's an intermediate step for adding noramal .bdrv_open() handler to the filter. With this commit no logic is changed, but we have a function which will be turned into .bdrv_open() handler in future commit. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/copy-before-write.c | 69 +++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/block/copy-before-write.c b/block/copy-before-write.c index adbbc64aa9..a4fee645fd 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -144,6 +144,45 @@ static void cbw_child_perm(BlockDriverState *bs, BdrvC= hild *c, } } =20 +static int cbw_init(BlockDriverState *top, BlockDriverState *source, + BlockDriverState *target, bool compress, Error **errp) +{ + BDRVCopyBeforeWriteState *state =3D top->opaque; + + top->total_sectors =3D source->total_sectors; + top->supported_write_flags =3D BDRV_REQ_WRITE_UNCHANGED | + (BDRV_REQ_FUA & source->supported_write_flags); + top->supported_zero_flags =3D BDRV_REQ_WRITE_UNCHANGED | + ((BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK) & + source->supported_zero_flags); + + bdrv_ref(target); + state->target =3D bdrv_attach_child(top, target, "target", &child_of_b= ds, + BDRV_CHILD_DATA, errp); + if (!state->target) { + error_prepend(errp, "Cannot attach target child: "); + return -EINVAL; + } + + bdrv_ref(source); + top->file =3D bdrv_attach_child(top, source, "file", &child_of_bds, + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, + errp); + if (!top->file) { + error_prepend(errp, "Cannot attach file child: "); + return -EINVAL; + } + + state->bcs =3D block_copy_state_new(top->file, state->target, false, c= ompress, + errp); + if (!state->bcs) { + error_prepend(errp, "Cannot create block-copy-state: "); + return -EINVAL; + } + + return 0; +} + BlockDriver bdrv_cbw_filter =3D { .format_name =3D "copy-before-write", .instance_size =3D sizeof(BDRVCopyBeforeWriteState), @@ -181,36 +220,10 @@ BlockDriverState *bdrv_cbw_append(BlockDriverState *s= ource, error_prepend(errp, "Cannot open driver: "); return NULL; } - state =3D top->opaque; - top->total_sectors =3D source->total_sectors; - top->supported_write_flags =3D BDRV_REQ_WRITE_UNCHANGED | - (BDRV_REQ_FUA & source->supported_write_flags); - top->supported_zero_flags =3D BDRV_REQ_WRITE_UNCHANGED | - ((BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK) & - source->supported_zero_flags); - - bdrv_ref(target); - state->target =3D bdrv_attach_child(top, target, "target", &child_of_b= ds, - BDRV_CHILD_DATA, errp); - if (!state->target) { - error_prepend(errp, "Cannot attach target child: "); - goto fail; - } =20 - bdrv_ref(source); - top->file =3D bdrv_attach_child(top, source, "file", &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - errp); - if (!top->file) { - error_prepend(errp, "Cannot attach file child: "); - goto fail; - } - - state->bcs =3D block_copy_state_new(top->file, state->target, false, c= ompress, - errp); - if (!state->bcs) { - error_prepend(errp, "Cannot create block-copy-state: "); + ret =3D cbw_init(top, source, target, compress, errp); + if (ret < 0) { goto fail; } =20 --=20 2.29.2