From patchwork Thu Nov 24 06:40:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuezhang.Mo@sony.com" X-Patchwork-Id: 13054614 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 423D6C4332F for ; Thu, 24 Nov 2022 06:40:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229723AbiKXGkx (ORCPT ); Thu, 24 Nov 2022 01:40:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbiKXGkv (ORCPT ); Thu, 24 Nov 2022 01:40:51 -0500 Received: from mx08-001d1705.pphosted.com (mx08-001d1705.pphosted.com [185.183.30.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 661E5DAD17; Wed, 23 Nov 2022 22:40:47 -0800 (PST) Received: from pps.filterd (m0209323.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AO4TqwG004002; Thu, 24 Nov 2022 06:40:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sony.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=S1; bh=pJVCAmP0s0O5+5cQJOmo9S9CUSSws59MxuYtNmRRfww=; b=beIr8b08nm4ozljbQqbiWeup1QeYEVii+BdjOnAwNkXa5jqMOm1sBimZBqZrjdKOL30w lyUy6DWP8oFMoi5Lyz26YIe7iTo5mqVhSvS+7mRCvAz4BekTxn/iXIwqpzrIV1crs2Hy J6idPeu0QmanEBQ9VPdFMfIAgqHyO45rF4a4gizo1I7MEKPdyvkZbtRuW8Sb3TUksA26 NVBxhfqJdN1W/EUePt/iT7rwgKlVMxnM0tyoNQ9fH23nZokg5JH9dvIhTL1XvY5eqynY BVCGJM9tRq505YWLr0Ql98KVFkqw4h7KfsIQoVxLsv5YW2vAtO+HdsmnvPDJqQX3ODE1 /w== Received: from apc01-tyz-obe.outbound.protection.outlook.com (mail-tyzapc01lp2047.outbound.protection.outlook.com [104.47.110.47]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 3m1c0a95n9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Nov 2022 06:40:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c80e7hI7MICrJKRIeO6HP3hgIHIjb2aYF8I8GDepvKGrSriRQuOfCgpUic62fbUbT9KKIwWTFCHzjltw6ornuAYHlmru+wUvs2iE/lcCSfUM+eJl2iz14j3QMG7sagwxDf+tCYWMK3HIQbn+r7VUwPUeyTZSllXlHccMwdesWWDofTFAta1agDodSgaRz/VkaXguIzgfny34eLuRalGv4x08xV/awzfEObb+rJHLDhnqSywsGMz7kfKnUdQxj5TayVjcf9VMSclovZ6MP+tKqm2nHSsbt4HZbLrIFzAIhNmptnLLBv6MxnKbpDYnRYBQ+Vk74Tv22Ka/9tNER1mk3w== 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=pJVCAmP0s0O5+5cQJOmo9S9CUSSws59MxuYtNmRRfww=; b=VtOTr+j+LfovsXsMFGrIiigwAj1c7QEt+RpT+rdkdc/JfZ5Qr1K24ibSYpkEOOLEtDzp0o//ZYHGCruMQIs678gbsqngMAOhBUzgmv+mMyO0QE/3r5t5tp2BQxSdcEVmkRXzr073JsKDqw8Rfj9LWXn7oBWiHOSwMpeqxpADUEkfG77Hw333n9Z8gCY95v3DcqWFA45qeEu0U714unpWJ6Ur88Up8Mxa+Akr9uz5LVI8cRni064VtRYewd/+RkSIfLmjvfa8+eERuCLk4I66dDuXN+KcoEdh2wJ7RqY2AA5lgqYPzvIoMCwP425rNhKye2WzyrTm6yaOlQuI9vx2fQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=sony.com; dmarc=pass action=none header.from=sony.com; dkim=pass header.d=sony.com; arc=none Received: from PUZPR04MB6316.apcprd04.prod.outlook.com (2603:1096:301:fc::7) by SI2PR04MB4425.apcprd04.prod.outlook.com (2603:1096:4:e8::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.17; Thu, 24 Nov 2022 06:40:31 +0000 Received: from PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::708b:1447:3c12:c222]) by PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::708b:1447:3c12:c222%8]) with mapi id 15.20.5857.008; Thu, 24 Nov 2022 06:40:31 +0000 From: "Yuezhang.Mo@sony.com" To: "linkinjeon@kernel.org" , "sj1557.seo@samsung.com" CC: "linux-fsdevel@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "Andy.Wu@sony.com" , "Wataru.Aoyama@sony.com" Subject: [PATCH v2 2/5] exfat: support dynamic allocate bh for exfat_entry_set_cache Thread-Topic: [PATCH v2 2/5] exfat: support dynamic allocate bh for exfat_entry_set_cache Thread-Index: Adj/yf3EdbTZ4lxGQLaYPoSH9Dr5Mg== Date: Thu, 24 Nov 2022 06:40:31 +0000 Message-ID: Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PUZPR04MB6316:EE_|SI2PR04MB4425:EE_ x-ms-office365-filtering-correlation-id: 83912b38-a64a-4c54-275c-08dacde6c850 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: eyYdtDe8Z9MaRIY7evzEYyQoKYLiGoQQ8PrVldRWs+FQSPK9ExtcMob4xR+AezfKqQJGemmzV0KGG9MSrmM8STT/1d3Xf2CVHv82kduevuJaKxSGHLr0dSIfxWx9JD27u+2jE+1sgI+cqI2fCVUaeH/lYdk140ERoOuesltZcIRSTG7rcXilzO/VW9IWaFmukiPKF05Z49NtwBSmn6RC4AIYy8E8vjMltzkccsEbgNu2B/NH3eO2jAWOOyoNW8kZIczLSAMO+DzdxuuChEG/Wrw0FkypohEHUZbq3Xw6Co2EZLCC4hTDf+08IgBla9q4t6NcbSZLenKIJH4eqRVu4HnSTUKPCw7ogN38PWyD6Y4Tb7JlsbAs2uXtfwae4UDR1N11M9udz48KPo7nGe+9E97NJaeKpRaairaQprpupJ2ouhVsBiaMu3ln+HJEcYDzP9ndkuojDrm2EO2DFyOCmCWjQUR95D2vlpewanPI8W2qvK4vSn/lo7nRpkzVJ5dIsTzJYpE7xFxYlXh7sJMh/6QQ94vmi4pCpmFdKPOQp028+fJRxcnsVKFyzO1KxYocB/9JvV27mfEFfqzh7rlCsFsJUmIHVCRmxsUSNBe0lxaGP4XYEszV+6qNqw8/sNqvXCHQCtDHFevc8FDfv829vLN+jnIeO77ILCf5TqK8588mCsLJd0Wi0ghRgqQVt7KLAjjsLL06/38erxz81ZDiFw== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR04MB6316.apcprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(396003)(366004)(376002)(136003)(346002)(451199015)(41300700001)(8936002)(478600001)(54906003)(4326008)(5660300002)(316002)(66556008)(66476007)(66946007)(76116006)(52536014)(66446008)(64756008)(8676002)(71200400001)(107886003)(2906002)(7696005)(6506007)(9686003)(186003)(110136005)(122000001)(26005)(38070700005)(38100700002)(82960400001)(86362001)(83380400001)(33656002)(55016003);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?R4w/F/EDNVkgaDSA9cCJWa3NAtu6?= =?utf-8?q?5a6EzEcyrzT/koas0PWINUS8UMAvw7DsuVhr9u9FX7o6jzgWmaQ/0JOSoSGFUnNHZ?= =?utf-8?q?j9Ufz39oY4xHWHiIRYuppTS4Jg5NtvVEJ3XFTIB8rqofKP0C+WydMqq81SuT9pdwT?= =?utf-8?q?xVlnuOZiPOUYvFLm1vmqWrlxL3gD2lk2daVSNJ+FOTSx3NJrCWxmbFmYXM3icTNGG?= =?utf-8?q?EAgE68by/OKdY6V0kH7Tg0jsUCD2aH1lkt2NUgqAtPavsY+KlUQluftXcK1Gz3UbR?= =?utf-8?q?6bxLW6QPJcWL2Xp9F5vIfbQ5aAaRqvNwyjYVfgS0m3u/i6xtUa1p9NS2airj4ScK9?= =?utf-8?q?I++MgLLVBuIVoaMpabUEzB47KyS0POrJ22Jd7V8ZcHrp6ivQJf5qq05K2q0saZ6uz?= =?utf-8?q?PBvLFNzIeha1aoB3DSMs6fybNtNIgs6ayp/XGWl7+YBJ+WyvuVOLTJiIyl4FYr4FD?= =?utf-8?q?IzKnyfx6STYHluBYAzftkf7hUcSiRmCPlpHQzahrk1izCMGQ5NDxR/T8QQNFnEg1q?= =?utf-8?q?InXLcUCU6gtqfAlazUkYhdlLmBd1yNblgQ4U9hzxqOcE8lGL7olrqcC31K5tSH//Z?= =?utf-8?q?mCaT0gR4BXyurHeIIUA6tY8jw7nDTyLTkJcFrvjUc2sv1HFlYxiK+xMCv6QvRC++U?= =?utf-8?q?5xsHrRRbtdAccjv+ggu8vRfa2VWghcvtnyVRrHVcBBjlnxkC7dDM4bZY8c75J/5vY?= =?utf-8?q?GmrcAV7pXEahPQPlNXYSTASjOgGFZFpqVXP7G2gn55QRdRelKX0QdtlBrCWCTT2iB?= =?utf-8?q?T5P7KcCT8Az/xQ/1BM3Ag5+ImkBTNPeYSOyPQRoBzt5oYVZDXtjsZ/PVBwvpOGPbk?= =?utf-8?q?5jUQbWgvd7aZ4+MhcB5jKQesJIiOjG8wzsvCoNgKiaI6g2z4wkGAEStIj/xDFxlRN?= =?utf-8?q?MSmv6XWODYEqtyuo/el1UobyszzLZLHG4gbwy5emR34Z8wfSPdcXUir8cF/S6Sciq?= =?utf-8?q?EUDv6ARcIjCElrj1NhF29mbs9Y6nfugsD0DzrD6m9f/LFuTQg6Wzf0b0J63krY3IS?= =?utf-8?q?2/lSKYoX0/OzScOWKf/jCEiPehGXbx7TEztjqTvHACCT6lltveh9gFZ6mscSHO0IY?= =?utf-8?q?dm/7J3i1aYcdTNLGbdgASvhNLOpsERg6C4XE4yNoot8bqTElJL8BgbxK1/d9aYc+B?= =?utf-8?q?SgTfo74c9eFAlOhMmkHo+hIpbuRH2t7ZfpzCT/tFEbOLyFDUlRgIz5cWJZ4WDunsG?= =?utf-8?q?abDCYaP3NH430gaZFQDpjhDQ7ozLC9HXpHC/LJsS9mr05tEU8BqI74Pp19+75OTYJ?= =?utf-8?q?Y6hrWgcASLRD3s1+la0JGsVrCHsk7H2EkLWocZJkosZRKV8su1zrhPCAbUofTyc4V?= =?utf-8?q?DHsHhO52DIoUlgmXjBatNqJyvtu/QStKTB4z9k5GXXUQsZzd5j72h3FhTJmOo7gBH?= =?utf-8?q?GgtmY8PvxdWDqdEFRoghPPVV5eKePQ9nlYBWQS66viAsTbIYQDdDcAtXpC22iRL5y?= =?utf-8?q?LGjx1ym6VsFHPZpSKV2dn/vad9TTeIeI5JYCSgfptOBmQ4ugIayyeI/ie3/29I9Uf?= =?utf-8?q?jGf/bAsp7mqz?= MIME-Version: 1.0 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: SCit4Jp3R29+J6ukskENF3aB8Mfzuc9FQE+X6hw+x+OaPEGCuHByItVXLRN53i5WmNyZ0eVyYL9zh894kV+enSGkw373j0GcuN5Q5NNc+GWsM3EXKEg167+U4FYFwBwPJyWiEA0wq1FDgqcyOXC8XuRj8UKJOBZAntnYXn90FYl5XbWUXGoS2ZOdpecmllvpMHqyFNJDVFNuAQyXYvhMOUQY470icRhIkg797GzlaFNUlIAATSrt9dTG673WQ9QhpKuJtoSqLgz4YSqIrOZc/QkoaBIALpSRssyRYo2wNlub5J/t/vdmY23zFbsA87StuhbjjYIExYVbQ8sFa5f7SqHscXB7L5N/caRQtu7v9RfmlgN+NxatsLieqneU3SkUZaCzJpS8L+xvDofIs9eUdTdxI29cqa1VZPdh9gFmKqxvqs4aXef9/5MzPFkUVbhI8+AdIDwoIp8Ird7Iyd5Tk14RmTm+E6WXs6LzI8gTUcfKxKHVBThbVEiaaJazFwSem4+FwJb8Apb2GsDRFoT9nlGk8YV6W4vB8KoTVVkd4bh6EFrl0NvNMQuOAwDiqxd8yCkV0VWUonbzB72qFFH+twV8h2deGi9dwAjhX8Hzu46Tpk4euHARaWn/c7FUzLmN0ySjYBBDA69q9eokS0yAyI7JTCvt+8i3QMYIN/md9uuCl6V41vO4y3f3b5/ZZydHQ1+uKPST9I4qq0LC89ynIsudh1BLukdcmxngR3wR9DQzC0hcSeyI61HJlFCV7g8XkWCnKb3iLBw2jFuLffJpVpe1sP+DZa4vz103B2pbNzzXZrtVxduFA7FdabDPM/tqN5VXjpr/5yC3dnV/uxur0WTns2z8Tl4zDNDunts5WT7MFf7y4Bwb4IpKOe63VhGs X-OriginatorOrg: sony.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PUZPR04MB6316.apcprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 83912b38-a64a-4c54-275c-08dacde6c850 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Nov 2022 06:40:31.2589 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 66c65d8a-9158-4521-a2d8-664963db48e4 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: SQVrjfBOva3e5nRP8mHu3azsa2E+f1OLaMCz2mYGzjmenn6vF2lNmrhstliVqLUhywvD7UEyCF6Ax/80ye/e7Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SI2PR04MB4425 X-Proofpoint-GUID: IN6SF8FGayMl0tUn_DzfGR20FF4dH4Ux X-Proofpoint-ORIG-GUID: IN6SF8FGayMl0tUn_DzfGR20FF4dH4Ux X-Sony-Outbound-GUID: IN6SF8FGayMl0tUn_DzfGR20FF4dH4Ux X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-24_04,2022-11-23_01,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In special cases, a file or a directory may occupied more than 19 directory entries, pre-allocating 3 bh is not enough. Such as - Support vendor secondary directory entry in the future. - Since file directory entry is damaged, the SecondaryCount field is bigger than 18. So this commit supports dynamic allocation of bh. Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru --- fs/exfat/dir.c | 15 +++++++++++++++ fs/exfat/exfat_fs.h | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index 30d0ac43b66c..03e9c9e3966e 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -615,6 +615,10 @@ int exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync) bforget(es->bh[i]); else brelse(es->bh[i]); + + if (IS_DYNAMIC_ES(es)) + kfree(es->bh); + kfree(es); return err; } @@ -847,6 +851,7 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb, /* byte offset in sector */ off = EXFAT_BLK_OFFSET(byte_offset, sb); es->start_off = off; + es->bh = es->__bh; /* sector offset in cluster */ sec = EXFAT_B_TO_BLK(byte_offset, sb); @@ -866,6 +871,16 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb, es->num_entries = num_entries; num_bh = EXFAT_B_TO_BLK_ROUND_UP(off + num_entries * DENTRY_SIZE, sb); + if (num_bh > ARRAY_SIZE(es->__bh)) { + es->bh = kmalloc_array(num_bh, sizeof(*es->bh), GFP_KERNEL); + if (!es->bh) { + brelse(bh); + kfree(es); + return NULL; + } + es->bh[0] = bh; + } + for (i = 1; i < num_bh; i++) { /* get the next sector */ if (exfat_is_last_sector_in_cluster(sbi, sec)) { diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index af55018ff22e..82395ae80dba 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -185,11 +185,14 @@ struct exfat_entry_set_cache { struct super_block *sb; unsigned int start_off; int num_bh; - struct buffer_head *bh[DIR_CACHE_SIZE]; + struct buffer_head *__bh[DIR_CACHE_SIZE]; + struct buffer_head **bh; unsigned int num_entries; bool modified; }; +#define IS_DYNAMIC_ES(es) ((es)->__bh != (es)->bh) + struct exfat_dir_entry { struct exfat_chain dir; int entry;