From patchwork Thu Dec 28 06:59:37 2023 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: 13505641 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 CA0A553BD for ; Thu, 28 Dec 2023 06:59:55 +0000 (UTC) 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="qDWojZUO" Received: from pps.filterd (m0209319.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3BS6KLiZ020276; Thu, 28 Dec 2023 06:59:45 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=PcMrvaLz/oy/f5T3szZONUqzCICAyANO6MzG09/4IEc=; b=qDWojZUOQKmkHkU1ExKXKOqPjehvlOpCdH2rjVZM/QSyji74IAqeSiH08uTrC+DE8dWa ybYJx6TynGtnbC84SwugtNkb1ief9uG317o/fF1MqZaH41x5j33mh1Y7cYxFF0Hday5N bdV4vy5ewL9LfPSMh3WuAwodd+7M2iu+dxdYnwu5J9Otk0a7RkOSSMso6Fnu2IfqgRvM 1Ty52sqzgyXzndsQSffipSpTiPnVlkqyYT6WNidtAJVDb48yQnqrO4WJCtbRYLKx+cEe xw0ojRB1SlF+p7VW3HkBUPxpFTmFrJDk1hGM5/CLlXgMgJnJUXpkmXtTjQpUWZT4mZpw MA== Received: from apc01-tyz-obe.outbound.protection.outlook.com (mail-tyzapc01lp2040.outbound.protection.outlook.com [104.47.110.40]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 3v5qxtbsed-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 28 Dec 2023 06:59:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pq/EIPzD/m/NPLZN/ACIFnhNujr7jCcChXdEN6uYduAGomlXR2Ki10mtb3nrvh/4pyNGsk51KUttQKV9rs0OybrIfuBYELd+IAAPDkli0DlsK8MG5g23tqY2aoM1/NM9I763KE/0rnqTfaAB6NFWxCRsGMfPH7tl2lVi+GNTMuCbBLzuWTmdfikil3FL+Llp/tCMq4BrtGH1yDqM2zQ3hCHktG0cHvmRXDb3GdupwWCxgI5BvpvpZjlFOMimC+KSamYvTW7rAlV0lSWzVFMV1f8bIFaZWm5234SIK0l/74rumS8bzBJ4dwPyRkQOYfNhxSe+r62wHVrk5qXvuxZQnA== 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=PcMrvaLz/oy/f5T3szZONUqzCICAyANO6MzG09/4IEc=; b=HyDcF/Em63F5L5O8S9ygY0MPb9HA9E8a6MNzBge6NrnwDAyy2siEikVAsQCKWkh+vvRHdMhSbuXiJuw1vxS/6X/kGGD3YGE2/M0iSBZzztErpQwbVud99yTvG3enr6j5U0MhwOeCN65EeElXUuQFBO4YcBWO9bkTZH+gEluQQYqj+tz3jqt49DwlIRm+WdVcazOm++jWYr0cLFzblptVVZCk1YpAMt4KXP3VlhqfjyKutS1++G8K9N09zWyP8UEx5F3aoWp+0LGu60/uvkXsP2FAAOapheVUqBoFNypB99ffJjnvLFPSmZVBR3u20BmmELvgeetzCC7rlzTsIdGO5w== 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 KL1PR04MB6878.apcprd04.prod.outlook.com (2603:1096:820:d5::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.26; Thu, 28 Dec 2023 06:59:38 +0000 Received: from PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::5914:6fc7:b79d:7e34]) by PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::5914:6fc7:b79d:7e34%7]) with mapi id 15.20.7113.026; Thu, 28 Dec 2023 06:59:37 +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 v2 04/10] exfat: convert exfat_remove_entries() to use dentry cache Thread-Topic: [PATCH v2 04/10] exfat: convert exfat_remove_entries() to use dentry cache Thread-Index: Ado5WaqHqlmx2w9PRSW0rtb1X5kIww== Date: Thu, 28 Dec 2023 06:59:37 +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_|KL1PR04MB6878:EE_ x-ms-office365-filtering-correlation-id: f634df37-24aa-4651-cc88-08dc07728e8c x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: lGZtz3g1Y60Xi77UN11GEkk3s6AR8Dxvkmj3uiDWwuUo7l6jGxlNTtV3y+225/daKg9TuOuwjeBgi4+eznesdbG79Rt5HZC+JSV/A4PBMpowuVPyoxvfaUQv3K7y6NyGIaCfvIC2xwbsaPJTOQiWA/STeeA8cYJgc6GOpEqzdwJZC+nfBtaoGcjNHyX9j4ObwVzd2bFiOTw/rfD+ph1gBuSmGiYqesT3NlHXnOeCx221YBInthuliE6rFyIQxCDkx7Yg3fL07m7S4N3PXWVoObbQAJC+XZvs04Hx8vtVCFHaPTJmMUb2u7js6x7xzobbc9cIffJXFpunXD9YBa2YxfxpIWOuCOawa2/EF8MXLwdPu3SFfcDGodRRayLGLsFF+PmL7uiildjVirJBKT/91B2ab6YZXzr+bhzXzZSccYTPuReMH8IXlBOPX4qFusQedBvw/6TWyOBSAwug0gRlohQnh3BBULmlfsldx7Mz32NTWUMyK4T6DHpVRasLwmdSpycYh9Kqjzx2WZKOHPaaGiYPMDP6eyHT0HFr7b4mGMJm6hyS0RlQc6+JbVpwNKddWOKBmQmN1MdKlIh1iYDZmedTZnqlbR2at38GAq0vJZf7u6S4bwVCjZTtEaESKeVE 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:(13230031)(39860400002)(136003)(376002)(346002)(396003)(366004)(230922051799003)(1800799012)(451199024)(186009)(64100799003)(33656002)(9686003)(6506007)(71200400001)(83380400001)(7696005)(478600001)(107886003)(26005)(38100700002)(122000001)(82960400001)(41300700001)(316002)(54906003)(110136005)(66556008)(66946007)(66446008)(30864003)(66476007)(64756008)(4326008)(8676002)(8936002)(52536014)(5660300002)(76116006)(2906002)(38070700009)(55016003)(86362001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?KskZahmkNXR8flU0Dab0NeTEHb/S?= =?utf-8?q?7xRa5Pu6+6aXHcWDwguZtSDJPmBU1/VCLsIY/RUsqWwfhg4U2L2FVTnMbAwnv/7rC?= =?utf-8?q?vDI5LuB6PfYD3Px4ZbCJV89KJ5KrpzHoW0iArmR2RlsRgBls8dVRJ4ZVJUS5SvdbZ?= =?utf-8?q?uw7hAV6lpUreRPbK9naWEajZwSX2/x4A77qKnGwDYJuwpSQGSCepWMjq7TVa1n7ez?= =?utf-8?q?tllJ+8JfPdZ/WI4RTQS2T7uojWHXzBdKaHzCVZr7+xYIxPUdNtmevsjYBSDW9WCYh?= =?utf-8?q?kD/HXDmJoeLhP9G1E5EOQ1Y1OTsWaNDDrILAXYmoLLEK5lcCJpyIcPznYSEnHsGQ6?= =?utf-8?q?d6AeRi+gaei6jaAjyn7lsjUGtILXqpwf/VBUialBV9lwTsfJykvjozQXJWpdn5Aj2?= =?utf-8?q?ALa36Q0UGnFFuGvmZuOp3tc/gnUBqllerJCYt8mbMnTQ7ywEhSw+T9Cf+i66I5DZ6?= =?utf-8?q?L8y/4aH/O3z4nZ4R9vAmHvd5FUCLjUDuvXHYrvdRJwl4gQrrZao2tdGILUCPiJNB1?= =?utf-8?q?7XxAr5jfrEIo2O9kIw1p11u1CAuWm6MyhZ4bDzJ8hc+7FVlMaO4xS9Hb7DFMHWAF4?= =?utf-8?q?daQiHoykKELXh3/Omej4Bwu8bXf56H5qj5QHZLs4ia/1hRwcyyk4LMQLo6VycZ7Ww?= =?utf-8?q?dJ2TmlPi91oGooINmTt8PXk+9k5gISSok/enpdVMvF2Hiq+GNXXHLxCDxZimB77/p?= =?utf-8?q?q4fhv5jIclOGXJQgLeDhPDF6LlC5W38lnu+Uy5BF6BXQaLpyT98t7J/43Jgm8POzf?= =?utf-8?q?2404xG8HKNqW2R/jbK2E9ybTm26aiC4Idnek8ziTguBWHWm3fzsviMmvSYW3xD88q?= =?utf-8?q?a8Wi0IGdK5CM0bX6Z+XFZaVvs75RLB5E2tUlA1FKiY6PNtkpyh66ez74TDeZmDdP7?= =?utf-8?q?oJYC/QSD559d4BexBUw9BJPE4nO6dHODsjpxPuw5zKGYHAoF1iHZRaovj8CCf2c4C?= =?utf-8?q?OnUwGSr6yuls9O1uJsjCGesM0TSlYfj+tLkYcOElH1Rwqe3bk3epr8gRLbpFdE2iU?= =?utf-8?q?UmUg/cdWrbvkBl7myag7Hxpggc6elujE97BDkJwj8TN4PNkaAIQnTekhAYQjRaPtQ?= =?utf-8?q?JM9/1LQQSfFEJljYF0Ugim3GeFCg40DmUigH7RFGo5DxmpEhGXVpxTfVWG5Z4VyOY?= =?utf-8?q?ALsvzcltYjs92LSwU3xlIwyzRaKA6w6YMM057ny2buWw88tE8qa4g28pHh3DZHcV/?= =?utf-8?q?YfStLeVVLufVUyik33/WUUR0JfDJBPj2NoJBMQ+StKjIFWOcfr9VrSGMzlK6VgLUF?= =?utf-8?q?dT9ZKOu/nrlGqQmUD97O1Oh2IcP30NoCyvqDITJRC6te3KnBLmj8gAVAjB/wQCXAg?= =?utf-8?q?WumiQ+tArHNSBWfVOoIcuusz+g1/G3D+CbP//oZvVqPItTbVVupvcX+AD815pBXvA?= =?utf-8?q?mH4bxU6xkDtDY6XV2gS9+D9wfqwRnJNYOKH9TXXw8SMAPxs31jtIJJ5HIgpFB8f8p?= =?utf-8?q?Ln+npuTbz4lmdFOpR+e+2uGqIT6yQARqdKygJDp2Xq79otJqPLoMy8IgaCzI9KpsT?= =?utf-8?q?csL0WRUPLqhL?= 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: /cfeH2d4i1CpEMXgU+N1GTTTHMJMWXxEyW4EA72wpeceAK3cDt3eD8VGFXpal0G7TF+OF8buCN151A51t7O0/Yf0oireRsXXZh0BW1z0VNy9pimNB477R+e0jAMjtL6TpBaj8Ga1XaUncmqdeFCwM+a+1kaE82pzX4RksJ+nW3odPrfPaxqcKiqSxh51enbAy7VarCnSj/w/+8F9/R2JQk6ON7sHsJVkoucx6iusZo3dqLQ0IsrJxaL8ld1F8ZUJ4sh1U9/YnXBgje8s3zJHpcatZ0sQ5drYaEeV1lsWP7XpHpgFIAwppOHzZVksNqUyGO54RI6kVQfKPzoBO6CSdo6y6OssAMNXmWjfoNsclTmWBfodf2KV1ed+bYKyZXpyr3CDr8vDtrDt7rsqB6G71dKy87GwXvDtiKL/gtmqyjrttC9DM0QV1imDh+wEZ/RYzryinFKux5DsvtqhUbBVeIbWdlMP3/EUmEGa1JJKIpmrBs+taMLjEbYRtm1Qy/TMjqlZkueHOdBym4plqg9X3F1U8BVVhcEPNX3IspoDklCxqQOMpMDlsBdCfUCgHOWQ9kKHVTW2u7qUJULG4oQjiwE2makMM64iR8z1PpPTN9HLwKWL4rBzHsheJ175aiyp 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: f634df37-24aa-4651-cc88-08dc07728e8c X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Dec 2023 06:59:37.8695 (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: G/d6OpFwARlstrwYF7kUcnQ6X+fIAJoIbq5Hj8QRi5xY/T4t9jq3DpLcTFiH374kBR+H9bZBEeikXnXpodQbpw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR04MB6878 X-Proofpoint-GUID: wMQNv7-ZR4vNQfxrXYbx4BVjb86qybyO X-Proofpoint-ORIG-GUID: wMQNv7-ZR4vNQfxrXYbx4BVjb86qybyO X-Sony-Outbound-GUID: wMQNv7-ZR4vNQfxrXYbx4BVjb86qybyO X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-28_02,2023-12-27_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 --- 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 42f96ee6b9d3..33ba96a05543 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 b77cf654750a..fbf76a8b5d88 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 &&