From patchwork Thu Jan 12 14:22:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5p2O5oms6Z+s?= X-Patchwork-Id: 42464 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3913498wrt; Thu, 12 Jan 2023 06:31:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXvJwES2Xr29qG7o63sRJ7UFq00UTx28sNHnypB+B8dc4ELMJhSwYyXY9bCHaJyPNnUkQPZN X-Received: by 2002:a05:6a20:158b:b0:af:6cc0:5b3d with SMTP id h11-20020a056a20158b00b000af6cc05b3dmr109257936pzj.7.1673533916825; Thu, 12 Jan 2023 06:31:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1673533916; cv=pass; d=google.com; s=arc-20160816; b=ICSV49kBVjSX/OrOaJbKRVa4n4WuVEpWOMWyCTFiTKxnO8naHGPVA/kluxc/kb5QLl m3ochqKtH5wqrj83Z1DmbyjMvQMchVLNpbZoKpXwP1fBdazOoHJwqKQqWoCi4xLPWvKm X7o2vmsyJDLBlET89IQpf6L2gVjfCBGs5wX69Dg4qVtiNmG9FcECf7DoZ7LNTCgOQZ+S sCpOl+nye2OXA7JCMN4aXlLut49ozGaNR0EzRsIpoGDbY6UVPYOzKg/YiQXiao8aYkuS i5chlIaJ9GEmljFopcuekUpZewld04c/nDiBSRMCyDv9FQmdSq8Zw9fmtWfTWaY+WPmO Hlzg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=Hbi8lnORPLsRlVi4gnEfVMIckbTcRLKyiyWVjIOS1yI=; b=Ri8S+TTr4HQ2W2t3WnCF0hDjj+nPZQUOVrzY8+Z5NwBpN33IreEcoUbVob1lTtCDMA qncJBNK0CQw6R6349+HLfGX5jQ5Lhix1n/MC9Vbd1jw1h5uzCJjoci1BUvryIMTVZYjZ ksx8ySQ/N2esNeokp6CUV0BVKyDvfVlYNg6Q9eVdGcpv4qZcBztxdhIFBVIAYMi4MXxl ReeQxLJpk1VlgdkUgjAK29rClCgAJm4mVG5lf3UAojBD7EZE8IsZ35C1y52puHEywrUZ QYTf+MBLxCWonora0/Imxu/7RCAV8zpx8YQ6GDFJE1hlnt3477ICxFa7qMF7jpzaBSib OrTg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=apsEcCsv; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p22-20020a639516000000b004a3510effacsi17423797pgd.222.2023.01.12.06.31.43; Thu, 12 Jan 2023 06:31:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=apsEcCsv; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238076AbjALObb (ORCPT + 99 others); Thu, 12 Jan 2023 09:31:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237251AbjALOaf (ORCPT ); Thu, 12 Jan 2023 09:30:35 -0500 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2072f.outbound.protection.outlook.com [IPv6:2a01:111:f400:feae::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 746E45E093 for ; Thu, 12 Jan 2023 06:22:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m//U41P/AJLPkoqJCC6Osfh2PoLbsWdGRZSRHhvsnUyAnIdZ4/S0ABH854ghK5G8g0HzNuXTqp8+45clXEVvx+gQO8KDLzkes1m1uY8fNjFsfP78JUNxpZPYWjyMVEa6409WJ/+DMC0AWNXb0SFi1t+vJ2KvIm9Yxb6+Kz/2hPUsbY7y9t2Nqd7F9E9ukKzKQL932JEih5l5Y2a+96IuoYo61oZuQOoW+vIjUfiaj8UORB5+tm0YSpw/4Y+vLZQW1tvUpQnFMw8cSas9PFhofFR97D/9USGBY/ybGIII5VzEvYBFr6/HH7CNtjIpljzTIXoUX496WcpcQCtvynTZtw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Hbi8lnORPLsRlVi4gnEfVMIckbTcRLKyiyWVjIOS1yI=; b=LuaKTKTv5qvWR8fsDs/kXDFEdOyugxi4IBi3RuhvXqOqo5cKiNwu2OlYEAI+FP99X/DTMk7ckH/rcvLI1MU2VPtpUCn1ZyvoRcEo00dAKeYbFQf3/3qWc1CMcqWKF9sXtW6XV0lsvVVw4CIj+9G/8C8XsXVqgkzDqL4fw8MGsWepGuLhbZr9mIfPdDGVUkz90Txwi3yP8YecvELH/UTsf055LhFGy0wIFmfN5XS4QDldgTXBwTQzdkQcyHQWjD2UydH3tD/kolPEnUoidf46sVw9xWyhft0p4MlhO46yYs93Ilpjjo3cEJQx5HLZ7LM+ib3t8n/TzhobGaa+MGQddQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Hbi8lnORPLsRlVi4gnEfVMIckbTcRLKyiyWVjIOS1yI=; b=apsEcCsvTyLt3HHLSQ3cP1hNAdB0yi8HXY6r3wQYdJIro46yt7kLftWTL90/OxDijTP1a4+qw/013pDNYzEFi1+ZxjQ5wTNI1WUk7PNM0EgcAgok0R9m3mkNaT8Aim0ltKh5ZcLeuhuh9lp7FDc50wKf2QuHKevqXZSdIW4sYKALRshm8jGe3bANuhefgzZ3ONvVsBuopceHS7Gn8GWmFYEOhMlL1WI1Oix6pyxkbANwZMVjm/kHpnS17ZbdKwssaMVte4akJj/AMkL8v10JuqUDdGv/O052I1JRbBw37VPaqGAqauIbzJQ6/a/8n3iSNWF7EgTwVC2GVkf0y+G86w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) by TYZPR06MB3903.apcprd06.prod.outlook.com (2603:1096:400:2a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.12; Thu, 12 Jan 2023 14:22:23 +0000 Received: from SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::3e52:d08c:ecf4:d572]) by SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::3e52:d08c:ecf4:d572%5]) with mapi id 15.20.6002.012; Thu, 12 Jan 2023 14:22:23 +0000 From: Yangtao Li To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Yangtao Li Subject: [PATCH] f2fs: introduce sanity_check_blocks() Date: Thu, 12 Jan 2023 22:22:13 +0800 Message-Id: <20230112142213.22784-1-frank.li@vivo.com> X-Mailer: git-send-email 2.35.1 X-ClientProxiedBy: SI2PR06CA0014.apcprd06.prod.outlook.com (2603:1096:4:186::11) To SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5269:EE_|TYZPR06MB3903:EE_ X-MS-Office365-Filtering-Correlation-Id: 8afcba88-d3ab-47e1-1304-08daf4a86ba3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3/MqNpUF5k+1o9R/bmJZzUmP9F9yqZzOjqYyAWjM3AYr3ck4AUN0ZQTOhP17duXCMT2CvuEOR61+qMynRsae5OJTPYni5GSN3CbWTqyCH7PTxg1oBFIg4sufhv88gmnE5RKPjgrK0v+4dAxtVqCTNIYtIIPtdFzeB4aoFYvwKCFwxYofb2IxXTTmx4faifMdPHtj33O0PBp/ZdCPCIXo/ZrspGf11MCgoHTCCLz6PNcFYiFLN9XtQ0eXV7HYjV5KaWbqONiEVSJJWUMuydEnFFcpnC9S+NJYa4wJjn2XjIDls5/UXL9zpJkNktEIXw6JuJqcsZYboajuQig3fSJI41Y6BHXPrg00siC1pxbGfhb9/jZXdwOFHOCyg7Nr6Og5tKv6z4vhlSekm/E2B+EzEuSCJEQRU+VWdwozxcDQPSsYx+imQI697o8Dwonp3mV8gW5Br1ItbVm3viGqLJ7NCwDmRW3ChbKZVYkkNL8sW3zdxMUvKb9HoJnnK1JgJOrsaVBEXiTd2u/nr9BCakBPlf/twOWCS2xhzXOOM+YV5BTRivqmjzeIvGFqmquDPS9GWRgC+f82KL1U4Zkrf9hyebpgmrlcsRGxregNsnqvMjc51rDuKQbItVf4ZavjGZ/GHNGnjN3sre2P1F1n22ScGVTMmfevQB61w8EtBAzRiPzqixdRAp3gOLNa57i0lYPd X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SEZPR06MB5269.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(346002)(366004)(136003)(376002)(396003)(451199015)(2906002)(66946007)(5660300002)(6486002)(36756003)(86362001)(8936002)(4326008)(316002)(38100700002)(66556008)(8676002)(38350700002)(66476007)(6506007)(41300700001)(52116002)(83380400001)(1076003)(2616005)(6512007)(186003)(6666004)(26005)(478600001)(107886003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: e0tBtrDnnocBr5vuvXgM6apR7lFDuutfLZMYp4pvgRJPM4dIftFkHWwKBOnMpm7Rfx/iJVdwgl8EfQLCPNSSY8+ejztman6CAnS9Jn3CwJe57PcdkZQpvG+dtBcCaxRHpeRv5GQStxGhgzKEUWsNYlD3uOhhYNf+tvJMMtTLqayBiAjRcnRFttKt80entT44JB3oXC+/iECgoxUdU6P8H+j2XYPLibulIkR6OgjE4p/dX0abxoV5BZiF034dHv3hxL2TKtUihHoSe7SbYNg70f3019qT+c0ZTSCj3F6N8mK3Ce3YGJO69HmnTCbGDiSLXSW/XmoQFa+U79JDOvraxHdRRUYeqpzMgponDWAdy9VWVUxCw7h0FxaZ4LOP74YeaNgRW1fB8QHl84WCmzlwl0XMJXaNzFrJ8SIutMLZ2CsIWTFPvegZ0wo+xuD86+oCej/RjbqlS+eu34j6xthO/pVJmUc16dHZQFmgy8ZvxUZx0ZybmDx/gVteuqL2IUNoPaqBQoN/HmbUQmVyVRDZ/bK9hnLmI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-Network-Message-Id: 8afcba88-d3ab-47e1-1304-08daf4a86ba3 X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB5269.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2023 14:22:22.5597 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kXsS5MxDRDq/0Ydn2J0e+/AsaBpDQpSgcBOsWdgSBxre8FVmvJ6qc3HDZzhUCSlRNTddxEkRhkNcczewW4fMwg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB3903 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754827500709856573?= X-GMAIL-MSGID: =?utf-8?q?1754827500709856573?= There are very similar codes in release_compress_blocks() and reserve_compress_blocks() which is used for data blocks check. This patch introduces a new helper sanity_check_blocks() to include those common codes, and used it instead for cleanup. Signed-off-by: Yangtao Li --- fs/f2fs/file.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index f5c1b7814954..0d539155379c 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3369,11 +3369,9 @@ static int f2fs_get_compress_blocks(struct file *filp, unsigned long arg) return put_user(blocks, (u64 __user *)arg); } -static int release_compress_blocks(struct dnode_of_data *dn, pgoff_t count) +static int sanity_check_blocks(struct dnode_of_data *dn, pgoff_t count) { struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); - unsigned int released_blocks = 0; - int cluster_size = F2FS_I(dn->inode)->i_cluster_size; block_t blkaddr; int i; @@ -3390,6 +3388,21 @@ static int release_compress_blocks(struct dnode_of_data *dn, pgoff_t count) } } + return 0; +} + +static int release_compress_blocks(struct dnode_of_data *dn, pgoff_t count) +{ + struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); + unsigned int released_blocks = 0; + int cluster_size = F2FS_I(dn->inode)->i_cluster_size; + block_t blkaddr; + int i, rc; + + rc = sanity_check_blocks(dn, count); + if (rc) + return rc; + while (count) { int compr_blocks = 0; @@ -3539,20 +3552,11 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) unsigned int reserved_blocks = 0; int cluster_size = F2FS_I(dn->inode)->i_cluster_size; block_t blkaddr; - int i; + int i, rc; - for (i = 0; i < count; i++) { - blkaddr = data_blkaddr(dn->inode, dn->node_page, - dn->ofs_in_node + i); - - if (!__is_valid_data_blkaddr(blkaddr)) - continue; - if (unlikely(!f2fs_is_valid_blkaddr(sbi, blkaddr, - DATA_GENERIC_ENHANCE))) { - f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR); - return -EFSCORRUPTED; - } - } + rc = sanity_check_blocks(dn, count); + if (rc) + return rc; while (count) { int compr_blocks = 0;