From patchwork Mon Mar 18 05:21:54 2024 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: 13594976 Received: from mx08-001d1705.pphosted.com (mx08-001d1705.pphosted.com [185.183.30.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90C3620DC4 for ; Mon, 18 Mar 2024 05:22:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=185.183.30.70 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710739333; cv=fail; b=tW9SulFLSIu/dHyNcbJhxjiyO6jmhI8PxB69RD0iJxmvzpWRzy3XCAACzmX7ivhp4XyAI+XFSRNbcIb3W/dDZB0EFUmJUgL/TCMdFxNfrGnpzetsDQ39QAggIR2g2++Lr9n/JqW0K0/f52W5RlRr/WnYC3F5rJRj9UoCodi0ZfA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710739333; c=relaxed/simple; bh=+IIQhLmUS1tpocMZbumCvHZ/dfdPQ1/vOPA5l7CLrWg=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=qfK/mYer3a1hr2Lk8bmVq8jrQq5grXHhnA0ouP/89fauevZlrtNKbBdsC8smmAW/hckLKug5PEqhKfmnupaPoeg/tJnZRZ/cOnX2OpgFi47d2OVY+hcDPljZ3acHjprq64E36Chk29YpK6qRSRPZ5CY1S8eUVHjAV9njIP9HoYA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sony.com; spf=pass smtp.mailfrom=sony.com; dkim=pass (2048-bit key) header.d=sony.com header.i=@sony.com header.b=UTz7UbjQ; arc=fail smtp.client-ip=185.183.30.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sony.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sony.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sony.com header.i=@sony.com header.b="UTz7UbjQ" Received: from pps.filterd (m0209320.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 42I0YVtd006187; Mon, 18 Mar 2024 05:22:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sony.com; h=from : to : cc : subject : date : message-id : mime-version : content-type : content-transfer-encoding; s=S1; bh=+IIQhLmUS1tpocMZbumCvHZ/dfdPQ1/vOPA5l7CLrWg=; b=UTz7UbjQ7hqDmcBruuweKtUCRv85AAbD2F22H6Tkiwuk5ujgrGeOPBnYC6lnHWLlTx0n acf7oT+hJgb9F34tpVWTXV2dj0b2OwOKOVp/Zn8wVrmJlGQOpN1wzYc78AMXfR4L5b5V vYeeil8G/IrYzngYVir3PZ5xhIrPucDzExkn3gHho9YgsFPQeEOS9tT45wD78wx140L7 pH4mM24csDlMOuS2nzvwLPq2vbkeBRoPZ9Pe6xLDbxQ1su+AXW3g90RzkOnvD/rM0lLu hmwRe55zstaHnmzO/4bB8sw2GGoJjaVQ6NmbE3zSH8Gr42TBjxoNYWS6zIsA3F/Iboz+ BA== Received: from apc01-psa-obe.outbound.protection.outlook.com (mail-psaapc01lp2040.outbound.protection.outlook.com [104.47.26.40]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 3ww1am1hk6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Mar 2024 05:22:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c6N4wxAq81fq025tlcofXR4ATzvnHpIZAotyo4nXSOB0BJDVgdWGYIW5Vk52t8UrbaisgZ+ve35fjWDBZTiM/7AyQ+FqwzJGXx8qZIbcoIlnlKSm6RZChrXajz7femoQuFgT37rLcmK6UIDRkdFIH4tHvo4W/Ps7HOjtbPMQ/esTIAN1ZkomdJmFGaCIsy7h7D2Oi7rlTMhOBiFFDxeO8Inf6Fjys9TZQy4PKYn4UaMntw/gPDpUTO0hAAxmOUIN42qPLcwgsIOay6Ni/CuaAaCEEDpSl5Y0Y2H4C52+LaLfNudFG1JFyixtlwZWGog6l/95kBYYZpZM1eQ+43GHqQ== 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=+IIQhLmUS1tpocMZbumCvHZ/dfdPQ1/vOPA5l7CLrWg=; b=Rf1uEq4N6Lp0HmsNypBIY4bbS6goCo8XjiivCKPeu5KAnSSZd0PIa79Kvy6g1EevEEETxu8/rPELT0GiUCVRf+NCejdpRmAR5Vycvrl+M9S/zwYjJuros+e+rN5BKFxWIV3pdDsu3t9IqFEux/iVVxLFN7QizSQR9baxXbZeO0THSFIyRt+09Si2wS4rQdH+iwr2Hc+C/WrLWIyGC9PVMiZl3Cl/Ra3Gshx2ftmcK7YvD4Eg119oa9ClkFV3fb7htd2wsMdVNd4Hj7YTvr+CwV2qwUNKys/ZvEzFY2v0gFnbO0OnYAHnC2dAGjMqpM4ad+uWrACYZ/TsqH0pDjl2hA== 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 SI2PR04MB5895.apcprd04.prod.outlook.com (2603:1096:4:1eb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.26; Mon, 18 Mar 2024 05:21:54 +0000 Received: from PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::7414:91e1:bb61:1c8d]) by PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::7414:91e1:bb61:1c8d%7]) with mapi id 15.20.7386.022; Mon, 18 Mar 2024 05:21:54 +0000 From: "Yuezhang.Mo@sony.com" To: "linkinjeon@kernel.org" , "sj1557.seo@samsung.com" CC: "linux-fsdevel@vger.kernel.org" , "Andy.Wu@sony.com" , "Wataru.Aoyama@sony.com" Subject: [PATCH v4 04/10] exfat: convert exfat_remove_entries() to use dentry cache Thread-Topic: [PATCH v4 04/10] exfat: convert exfat_remove_entries() to use dentry cache Thread-Index: AdiooMwbxmVRnjZgQTisyZfS8SST6HQUX8mg Date: Mon, 18 Mar 2024 05:21:54 +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_|SI2PR04MB5895:EE_ x-ms-office365-filtering-correlation-id: be4c4766-bda3-4627-302c-08dc470b530b x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: tdD7cec7CqqibmHxdiLxVP9DxSHaAN47Fda6Dbx7KHze/nJWsBFiP0knj6fTJhkawnL6MMwWSCbxAvCGSVxHPcN0DwuD2RTvUObI7W9TEJa/kW4UfhM6+0dVxjjiXeOCIPsLPIZ8VUUyw35blsE39re1QouDg13/Oecr+md2pwt5i4b8sVKd1ykXHDfFDlOAaz0IZHXJY7+i/CruVqv2jChY6kLrdgSh7gv/2VQmi4AvGgj2YMKOojBsxOMoYgWgv90QSvhPx58tsI7VLoBswYJuYOBWL3JR92a+0eijWe7oWSUnMw57PYKSlxC2w4bqJXu6/OsvcDVjnLlWopp3aUnx+UtsMZL32kIfYOMJZugyDyuVNpLHfbxkLYSmIFsFlf2e9Wc/gylRM9ZBExpRqCyr7GTr+Pi7OFRrvsOkGs4ULQ+o9tHtTXmHRaCSu17/S3NTzI6FDWf1T1a5MqiIb4CxFmCr/+lF3qAYNCIpeyMp1ltie2j3EOYTY4qMhntyVEzey8Dyv2aZen4lSYVCvgOFt0xX09cF6ncOTEIElnIAclCivDxoPVwyr/kFlePF1yEtPoUQqmGM+XsXbgT0G4ICGrJUj1bLJZ771YJ/iNDU7DguMsFUK14z5e9cjZrvgWyGqTrxy/xp5MbA2YOvXPzR8Vj4VVlsnYzNuL5QSmt6KPq8azqwqvq41wLDSSRdCHD51uYFQFJF9TwlFiYAeHAvwlmD1l5NgqU1/pXVBOE= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:zh-cn;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR04MB6316.apcprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(366007)(1800799015)(38070700009);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?q3xByfovkc5XiPMFDAGXQUBjTYYX?= =?utf-8?q?lQwW29MqmyD35VkycpjN7PYi5zFOFuZTRmXe3izEz473JS2Dwbv+Dedjh/wCVMl27?= =?utf-8?q?in9FZDMQVG6IUMIEtuUf1aOEC//bGOsZbZHaGcbUVELtD7IsYmYVnCGN8UY4vsvvM?= =?utf-8?q?WbC3U28v00Q+/5ooozi8LgND12IfFqMeFAN/UStdLMTAX+gDpxcPEupKxlvisKEmi?= =?utf-8?q?O05kMggHTOA8zlnycrnZh4PqpAkO0NJcmsLL0wRZ6ZnCp/eLiW6bSxjvg4JumpLbk?= =?utf-8?q?hWiOxyduPX2EzU3/bYNMRdCrOt3o7RNxP/rkfthidH+S9pIQp1Jcfo807OJs5REF0?= =?utf-8?q?pDwbyychdPI3XicHzM70ta5Y2dBJfND/0Y6QZMNl5CBJgpIwvIilcyxO0AAid+/yg?= =?utf-8?q?nUwo87RUI0gXqyylyatyhk8/jtemtZFRlKwRl9bMmmM59aJuCM5VVJTvjTCKiKJ90?= =?utf-8?q?rA+J1OFMllFv+kvS5iFGC5NLtKZudmMgJXZQ6qXxECATrDX9jPTcoy0JChaFwFWwd?= =?utf-8?q?VjoIDmcAWNNSR1iFZRZlRFIX5JMnFQUphVFiRIdzAneyPRYpIIs299PyGDVqi+p/x?= =?utf-8?q?kYoELukcm3rW4kEtmI7hGuqNmNozbH9vevJDPVaaPP/SvMjGT+od9m2pAQYj9a1y7?= =?utf-8?q?cL61pAbENt8BWA142V4JtoBGtDw5n3XIMUjvxDnci4Tj98Jk42cZqZtIZsvSA5krv?= =?utf-8?q?E4EU5Cw2CiKji41c+jDkIwfHixejHBbJHQczJkfz4gFPn5844z7BiZNbpjKnVh2k0?= =?utf-8?q?O0DXSiZaaxhhbvo15wimDX8/bqGipIPyEjcKXrFpJKYmn7XCIhiR89fcogkYCTNtA?= =?utf-8?q?yWLO5zbHiP78Zd3439NQunfmMl2l/nW8n4nx14Y/2uZjomz6X7I97Q7OuksuBokWS?= =?utf-8?q?wGkzyUEFdW9D8DwOwcwVuzIX15JUSAYWRTbu+nYArHC95Liq8H62bXxebTSrKccn1?= =?utf-8?q?cfT9Eno6tdaeB+F3ZWYGULCD4lA/PIhTe8ckkhtkhig3unUwL9NEfozhP/sqSiRxU?= =?utf-8?q?j3iLvGR9mqUX2uW56PEoUMqdh6bZd6WzQrqPolE0f26VikMDxOz/oc4awmatQRQz1?= =?utf-8?q?GUJqbVS89u/OUwKh4ZEZsOhn9HjMk9KmsZNbduOJyHea+7B0tfSmW8TaNgebErtfR?= =?utf-8?q?6X4doQ6wFnHed8GD7un2DoTy1yEu4DfeFvFJ4IkkcVsfanuBBtHR+m4RU2jrLeMjp?= =?utf-8?q?HNhQRXqtsobke05rUJICgAkFVXUL2EkxiQHYvKZ/gcZxNRgAfyyuudTxFSHGSmWt9?= =?utf-8?q?NK5cAeYAAGyyoGyxDHtr6tcgOZ2x2HOvhmL4DbIYbHogZTb3qcdrXRgSWUlMlJXE+?= =?utf-8?q?sBw0ks97dK16qeZorZwytXyBOlu4F/vP/aBoEP6bzq4M0x89Gf/G/ukVBtJ25xbxh?= =?utf-8?q?MzQrjijCP1QAEPP+8wp+0cHSAf2AqnM1BP3O6iZ0n72qSANlPv/8Jfy+dLkBAWaCb?= =?utf-8?q?p8d+IV8xOVAEHqi5A8Kj1+/PjkDjhKIXXO7OJRN14R80lpNIS9OpuuYNBSbxu/X+N?= =?utf-8?q?bCYUj64d/Fhh?= Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 2XJkn1Vuy8cAaqFZogUt6QL/fANJMhCO0M2rcB/rcjKRtF8astVMK8SYO0/kQCpugxPrArVi1v1ZZu8ISLNq3mB7maPULY4Z9Xc5jsBCfNjI6J+3QhW1dW6OEam/mEsGLQlcE0hOoVLNXSq4TasTwbmitGZ+T0bPYuuPdxMRKakDt5kKWSwqxq7pAyd6GoGCYjpaWV/OYP5WXIbCkWE8qbKgen+16biMiGVPBJFUePqzLkFsZ09b+QbI5Snn+CNCYLvQsD3FfGFy2q5bhkNdVvHVgyaJyveo0JcjHJbvOBDf0SfDozI2cMYRcY3DYd80qWEQvfYcrSBZTVUif5LVhktvfLjQsUtT/Kls0ckD1R3BcmiN5hXe2kZDN2cFWmw3ljh49i7PB8fcFLKtlMhY14K5miA+P+VLM/Cem5SROma7Cgkm++JFJHNmcJnkAbva6vCvHwfUybt7CFm4Shl64Tec9Z5unMLf73ByukQDjJfqfC72LpepBhmSyU0wpHK2u9UJ7+xgA0PTpNHgPuTT49mv50JMijcD55QN+khYuer5KYu98rb3Lljnqcsu416Mw2uDk2XJ0Tkoc1jHZlR0ZxqVnMCQGAd0C9XVpKG43ojkElv6iXVRHcsbidwnnWnG 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: be4c4766-bda3-4627-302c-08dc470b530b X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Mar 2024 05:21:54.3040 (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: Hd/1TxLE5uzrAdW2l17LoZBJ7hmn0O0NrSrpnns65SgEnN4q8d+h7Z/1DSCmVYLdpkIpArWurLTk8novzdFLsg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SI2PR04MB5895 X-Proofpoint-ORIG-GUID: QjoO1Ib4w5vAImY4t3ClwD8dxAEsbnYa X-Proofpoint-GUID: QjoO1Ib4w5vAImY4t3ClwD8dxAEsbnYa X-Sony-Outbound-GUID: QjoO1Ib4w5vAImY4t3ClwD8dxAEsbnYa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-17_12,2024-03-15_01,2023-05-22_02 Before this conversion, in exfat_remove_entries(), to mark the dentries in a dentry set as deleted, the sync times is equals the dentry numbers if 'dirsync' or 'sync' is enabled. That affects not only performance but also device life. After this conversion, only needs to be synchronized once if 'dirsync' or 'sync' is enabled. Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru Reviewed-by: Sungjong Seo Signed-off-by: Namjae Jeon --- fs/exfat/dir.c | 17 ++-- fs/exfat/exfat_fs.h | 4 +- fs/exfat/namei.c | 184 ++++++++++++++++++++------------------------ 3 files changed, 90 insertions(+), 115 deletions(-) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index 0065d2abc983..599dc81c9a08 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -577,28 +577,23 @@ int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir, return 0; } -int exfat_remove_entries(struct inode *inode, struct exfat_chain *p_dir, - int entry, int order, int num_entries) +void exfat_remove_entries(struct inode *inode, struct exfat_entry_set_cache *es, + int order) { - struct super_block *sb = inode->i_sb; int i; struct exfat_dentry *ep; - struct buffer_head *bh; - for (i = order; i < num_entries; i++) { - ep = exfat_get_dentry(sb, p_dir, entry + i, &bh); - if (!ep) - return -EIO; + for (i = order; i < es->num_entries; i++) { + ep = exfat_get_dentry_cached(es, i); if (exfat_get_entry_type(ep) & TYPE_BENIGN_SEC) exfat_free_benign_secondary_clusters(inode, ep); exfat_set_entry_type(ep, TYPE_DELETED); - exfat_update_bh(bh, IS_DIRSYNC(inode)); - brelse(bh); } - return 0; + if (order < es->num_entries) + es->modified = true; } void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es) diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index ecc5f6a3ad87..83ae84a657cd 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -485,8 +485,8 @@ void exfat_init_dir_entry(struct exfat_entry_set_cache *es, unsigned long long size, struct timespec64 *ts); int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir, int entry, int num_entries, struct exfat_uni_name *p_uniname); -int exfat_remove_entries(struct inode *inode, struct exfat_chain *p_dir, - int entry, int order, int num_entries); +void exfat_remove_entries(struct inode *inode, struct exfat_entry_set_cache *es, + int order); int exfat_update_dir_chksum(struct inode *inode, struct exfat_chain *p_dir, int entry); void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es); diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index 07506f3882bb..f56e223b9b8f 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -803,12 +803,11 @@ static struct dentry *exfat_lookup(struct inode *dir, struct dentry *dentry, static int exfat_unlink(struct inode *dir, struct dentry *dentry) { struct exfat_chain cdir; - struct exfat_dentry *ep; struct super_block *sb = dir->i_sb; struct inode *inode = dentry->d_inode; struct exfat_inode_info *ei = EXFAT_I(inode); - struct buffer_head *bh; - int num_entries, entry, err = 0; + struct exfat_entry_set_cache es; + int entry, err = 0; mutex_lock(&EXFAT_SB(sb)->s_lock); exfat_chain_dup(&cdir, &ei->dir); @@ -819,26 +818,20 @@ static int exfat_unlink(struct inode *dir, struct dentry *dentry) goto unlock; } - ep = exfat_get_dentry(sb, &cdir, entry, &bh); - if (!ep) { - err = -EIO; - goto unlock; - } - num_entries = exfat_count_ext_entries(sb, &cdir, entry, ep); - if (num_entries < 0) { + err = exfat_get_dentry_set(&es, sb, &cdir, entry, ES_ALL_ENTRIES); + if (err) { err = -EIO; - brelse(bh); goto unlock; } - num_entries++; - brelse(bh); exfat_set_volume_dirty(sb); + /* update the directory entry */ - if (exfat_remove_entries(dir, &cdir, entry, 0, num_entries)) { - err = -EIO; + exfat_remove_entries(inode, &es, ES_IDX_FILE); + + err = exfat_put_dentry_set(&es, IS_DIRSYNC(inode)); + if (err) goto unlock; - } /* This doesn't modify ei */ ei->dir.dir = DIR_DELETED; @@ -954,13 +947,12 @@ static int exfat_check_dir_empty(struct super_block *sb, static int exfat_rmdir(struct inode *dir, struct dentry *dentry) { struct inode *inode = dentry->d_inode; - struct exfat_dentry *ep; struct exfat_chain cdir, clu_to_free; struct super_block *sb = inode->i_sb; struct exfat_sb_info *sbi = EXFAT_SB(sb); struct exfat_inode_info *ei = EXFAT_I(inode); - struct buffer_head *bh; - int num_entries, entry, err; + struct exfat_entry_set_cache es; + int entry, err; mutex_lock(&EXFAT_SB(inode->i_sb)->s_lock); @@ -984,27 +976,20 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry) goto unlock; } - ep = exfat_get_dentry(sb, &cdir, entry, &bh); - if (!ep) { - err = -EIO; - goto unlock; - } - - num_entries = exfat_count_ext_entries(sb, &cdir, entry, ep); - if (num_entries < 0) { + err = exfat_get_dentry_set(&es, sb, &cdir, entry, ES_ALL_ENTRIES); + if (err) { err = -EIO; - brelse(bh); goto unlock; } - num_entries++; - brelse(bh); exfat_set_volume_dirty(sb); - err = exfat_remove_entries(dir, &cdir, entry, 0, num_entries); - if (err) { - exfat_err(sb, "failed to exfat_remove_entries : err(%d)", err); + + exfat_remove_entries(inode, &es, ES_IDX_FILE); + + err = exfat_put_dentry_set(&es, IS_DIRSYNC(dir)); + if (err) goto unlock; - } + ei->dir.dir = DIR_DELETED; inode_inc_iversion(dir); @@ -1030,36 +1015,40 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir, int oldentry, struct exfat_uni_name *p_uniname, struct exfat_inode_info *ei) { - int ret, num_old_entries, num_new_entries; + int ret, num_new_entries; struct exfat_dentry *epold, *epnew; struct super_block *sb = inode->i_sb; - struct buffer_head *new_bh, *old_bh; + struct buffer_head *new_bh; + struct exfat_entry_set_cache old_es; int sync = IS_DIRSYNC(inode); - epold = exfat_get_dentry(sb, p_dir, oldentry, &old_bh); - if (!epold) - return -EIO; - - num_old_entries = exfat_count_ext_entries(sb, p_dir, oldentry, epold); - if (num_old_entries < 0) - return -EIO; - num_old_entries++; - num_new_entries = exfat_calc_num_entries(p_uniname); if (num_new_entries < 0) return num_new_entries; - if (num_old_entries < num_new_entries) { + ret = exfat_get_dentry_set(&old_es, sb, p_dir, oldentry, ES_ALL_ENTRIES); + if (ret) { + ret = -EIO; + return ret; + } + + epold = exfat_get_dentry_cached(&old_es, ES_IDX_FILE); + + if (old_es.num_entries < num_new_entries) { int newentry; newentry = exfat_find_empty_entry(inode, p_dir, num_new_entries); - if (newentry < 0) - return newentry; /* -EIO or -ENOSPC */ + if (newentry < 0) { + ret = newentry; /* -EIO or -ENOSPC */ + goto put_old_es; + } epnew = exfat_get_dentry(sb, p_dir, newentry, &new_bh); - if (!epnew) - return -EIO; + if (!epnew) { + ret = -EIO; + goto put_old_es; + } *epnew = *epold; if (exfat_get_entry_type(epnew) == TYPE_FILE) { @@ -1067,30 +1056,25 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir, ei->attr |= EXFAT_ATTR_ARCHIVE; } exfat_update_bh(new_bh, sync); - brelse(old_bh); brelse(new_bh); - epold = exfat_get_dentry(sb, p_dir, oldentry + 1, &old_bh); - if (!epold) - return -EIO; + epold = exfat_get_dentry_cached(&old_es, ES_IDX_STREAM); epnew = exfat_get_dentry(sb, p_dir, newentry + 1, &new_bh); if (!epnew) { - brelse(old_bh); - return -EIO; + ret = -EIO; + goto put_old_es; } *epnew = *epold; exfat_update_bh(new_bh, sync); - brelse(old_bh); brelse(new_bh); ret = exfat_init_ext_entry(inode, p_dir, newentry, num_new_entries, p_uniname); if (ret) - return ret; + goto put_old_es; - exfat_remove_entries(inode, p_dir, oldentry, 0, - num_old_entries); + exfat_remove_entries(inode, &old_es, ES_IDX_FILE); ei->dir = *p_dir; ei->entry = newentry; } else { @@ -1098,37 +1082,29 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir, epold->dentry.file.attr |= cpu_to_le16(EXFAT_ATTR_ARCHIVE); ei->attr |= EXFAT_ATTR_ARCHIVE; } - exfat_update_bh(old_bh, sync); - brelse(old_bh); ret = exfat_init_ext_entry(inode, p_dir, oldentry, num_new_entries, p_uniname); if (ret) - return ret; + goto put_old_es; - exfat_remove_entries(inode, p_dir, oldentry, num_new_entries, - num_old_entries); + exfat_remove_entries(inode, &old_es, num_new_entries); } - return 0; + return exfat_put_dentry_set(&old_es, sync); + +put_old_es: + exfat_put_dentry_set(&old_es, false); + return ret; } static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir, int oldentry, struct exfat_chain *p_newdir, struct exfat_uni_name *p_uniname, struct exfat_inode_info *ei) { - int ret, newentry, num_new_entries, num_old_entries; + int ret, newentry, num_new_entries; struct exfat_dentry *epmov, *epnew; struct super_block *sb = inode->i_sb; - struct buffer_head *mov_bh, *new_bh; - - epmov = exfat_get_dentry(sb, p_olddir, oldentry, &mov_bh); - if (!epmov) - return -EIO; - - num_old_entries = exfat_count_ext_entries(sb, p_olddir, oldentry, - epmov); - if (num_old_entries < 0) - return -EIO; - num_old_entries++; + struct buffer_head *new_bh; + struct exfat_entry_set_cache mov_es; num_new_entries = exfat_calc_num_entries(p_uniname); if (num_new_entries < 0) @@ -1138,31 +1114,35 @@ static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir, if (newentry < 0) return newentry; /* -EIO or -ENOSPC */ - epnew = exfat_get_dentry(sb, p_newdir, newentry, &new_bh); - if (!epnew) + ret = exfat_get_dentry_set(&mov_es, sb, p_olddir, oldentry, + ES_ALL_ENTRIES); + if (ret) return -EIO; + epmov = exfat_get_dentry_cached(&mov_es, ES_IDX_FILE); + epnew = exfat_get_dentry(sb, p_newdir, newentry, &new_bh); + if (!epnew) { + ret = -EIO; + goto put_mov_es; + } + *epnew = *epmov; if (exfat_get_entry_type(epnew) == TYPE_FILE) { epnew->dentry.file.attr |= cpu_to_le16(EXFAT_ATTR_ARCHIVE); ei->attr |= EXFAT_ATTR_ARCHIVE; } exfat_update_bh(new_bh, IS_DIRSYNC(inode)); - brelse(mov_bh); brelse(new_bh); - epmov = exfat_get_dentry(sb, p_olddir, oldentry + 1, &mov_bh); - if (!epmov) - return -EIO; + epmov = exfat_get_dentry_cached(&mov_es, ES_IDX_STREAM); epnew = exfat_get_dentry(sb, p_newdir, newentry + 1, &new_bh); if (!epnew) { - brelse(mov_bh); - return -EIO; + ret = -EIO; + goto put_mov_es; } *epnew = *epmov; exfat_update_bh(new_bh, IS_DIRSYNC(inode)); - brelse(mov_bh); brelse(new_bh); ret = exfat_init_ext_entry(inode, p_newdir, newentry, num_new_entries, @@ -1170,13 +1150,18 @@ static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir, if (ret) return ret; - exfat_remove_entries(inode, p_olddir, oldentry, 0, num_old_entries); + exfat_remove_entries(inode, &mov_es, ES_IDX_FILE); exfat_chain_set(&ei->dir, p_newdir->dir, p_newdir->size, p_newdir->flags); ei->entry = newentry; - return 0; + return exfat_put_dentry_set(&mov_es, IS_DIRSYNC(inode)); + +put_mov_es: + exfat_put_dentry_set(&mov_es, false); + + return ret; } /* rename or move a old file into a new file */ @@ -1194,7 +1179,6 @@ static int __exfat_rename(struct inode *old_parent_inode, struct exfat_sb_info *sbi = EXFAT_SB(sb); const unsigned char *new_path = new_dentry->d_name.name; struct inode *new_inode = new_dentry->d_inode; - int num_entries; struct exfat_inode_info *new_ei = NULL; unsigned int new_entry_type = TYPE_UNUSED; int new_entry = 0; @@ -1265,25 +1249,21 @@ static int __exfat_rename(struct inode *old_parent_inode, &newdir, &uni_name, ei); if (!ret && new_inode) { + struct exfat_entry_set_cache es; + /* delete entries of new_dir */ - ep = exfat_get_dentry(sb, p_dir, new_entry, &new_bh); - if (!ep) { + ret = exfat_get_dentry_set(&es, sb, p_dir, new_entry, + ES_ALL_ENTRIES); + if (ret) { ret = -EIO; goto del_out; } - num_entries = exfat_count_ext_entries(sb, p_dir, new_entry, ep); - if (num_entries < 0) { - ret = -EIO; - goto del_out; - } - brelse(new_bh); + exfat_remove_entries(new_inode, &es, ES_IDX_FILE); - if (exfat_remove_entries(new_inode, p_dir, new_entry, 0, - num_entries + 1)) { - ret = -EIO; + ret = exfat_put_dentry_set(&es, IS_DIRSYNC(new_inode)); + if (ret) goto del_out; - } /* Free the clusters if new_inode is a dir(as if exfat_rmdir) */ if (new_entry_type == TYPE_DIR &&