From patchwork Mon Mar 11 04:25:16 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: 13588285 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 5EFEF14296 for ; Mon, 11 Mar 2024 04:25:33 +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=1710131135; cv=fail; b=eMyio2mCavQ1YH8yGlhsFF17wdsswCVh4DMRt/Gpx3co6FBEOxuwgTrD53R6F3BqQkXNBtFVgpfAl/um/ubZl4y/vdb5YsXxwY2AzltiksgDG+HsSXuS41gBnw3UfZ9QyFOxT7DKYzyNKDTIeWDOBUpdBbLHynIa6hY2WelLR9M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710131135; c=relaxed/simple; bh=3/6cH/wDJY98age2+HAFkkM3uEcunfDro76cGhZcCkg=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=OJ9DEI6PebOCc3tihFRFCfOiUn6toYrhQBYnTx77UXIuwya4fcFjqvIxwQjIblFbtCC+AjIJuHh4nYM99KHlFov366RMst+I1Y1FF0bcMJM+8cT2wgI3SJGxEaJvxDwbTh+MtQmPWNWvT9JuWROHvkZ0IZdiGtHxCF0DD2gKHlg= 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=GRfbg2+j; 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="GRfbg2+j" Received: from pps.filterd (m0209318.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 42ANjEgS021524; Mon, 11 Mar 2024 04:25:24 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=3/6cH/wDJY98age2+HAFkkM3uEcunfDro76cGhZcCkg=; b=GRfbg2+j24h0zzcDsWddtsnVSDSkun1AbpFT2beqEGJwhSTEdSWJL/WwLaYO11cNIxLf tjN9qYv+BZHQ/WKe0EwfABSD61QTxSiLqgN0HNsg+mXJpD5sBuGrsPyTz8FFYDG1hr62 WCvJ2E+DiWTV5FfpHyvIvPn2NRASB219Q97dInwkEU7cAML9hkjHSwug1z1DLXy7J2La d5MZaX0eSKZrl1e3jRLa4YA98bEirgsL2dH4YcoL4TTQnf913Zm6cDQkiincVrXTVPyk eP8YBv3yrQzBotCCWcx6SgBjsJjBCSirdzVoMgO0t7l0c1SAQpdOX9IvXxc7H67++O3T og== Received: from apc01-tyz-obe.outbound.protection.outlook.com (mail-tyzapc01lp2041.outbound.protection.outlook.com [104.47.110.41]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 3wreb6sdbb-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Mar 2024 04:25:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W2qa7geX54anvjzvJddi+lqw+DlPf34XJDFVJD2QBhCwfBRG800DR3O5bF9uiBc/x2SDhwMywUFwR0bx9kRyU6LVXU8TxsHUeiBvnh1SBBhaz1Qv+ROisqxh20N2s7YgWnR8SNFa+vPA5GS6zm4b1sUGfX9bYG5EfxPLzsqOAk0Yo4Az65DYrT5tAQSaE+Hxiby7qS41wlkyTb1Y4JU2wN93WWyEWxxBDMPeL5qYeo/kJzxs/9XsPTjDG8VfiAcDWIv/wWgijiIE0bvZ4NKf1rC9o2AAgLp91EAPzUwNq1ZNlmlXVIL3kuq+Rqg/hY+b07ZxKEtwWTcU0QViCFyG/g== 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=3/6cH/wDJY98age2+HAFkkM3uEcunfDro76cGhZcCkg=; b=L2sW0BJEbJFz86lt2ReH3PJUrpB+r+LO4B4/PRPkwfHiBvkL2qF5g7WTwaSiva9p7rjgL9gBLwIlu5i7PXn/D+rlVL7s4wzoB0VxEm9JRGcnE/LFrPdmUVlrMwuXWmjix0Kejqg32ptoFUJtHGvFQaQLd50zl74Jdza+D8cxaSbRCIgyShjdj1QXN++7kmVG7wIVswScgw6cmdoNIm3aOzLVPTFX9zn56bLtC5vokcjB2lc0qazj1gotpKCbzndVAzqfQT3dG2oFk0ZYeclejGAO0oypgjP2o6KRpb99YmibG4t2Pbn5Sw2XeKFf5cEnrXr9oPYk/tum4eKBfRkPHw== 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 TY0PR04MB6328.apcprd04.prod.outlook.com (2603:1096:400:279::9) by TYZPR04MB6635.apcprd04.prod.outlook.com (2603:1096:400:33f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.28; Mon, 11 Mar 2024 04:25:16 +0000 Received: from TY0PR04MB6328.apcprd04.prod.outlook.com ([fe80::c5b0:d335:658e:20bd]) by TY0PR04MB6328.apcprd04.prod.outlook.com ([fe80::c5b0:d335:658e:20bd%7]) with mapi id 15.20.7362.031; Mon, 11 Mar 2024 04:25:16 +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 v3 07/10] exfat: convert exfat_find_empty_entry() to use dentry cache Thread-Topic: [PATCH v3 07/10] exfat: convert exfat_find_empty_entry() to use dentry cache Thread-Index: AdoLF/aVR4xCnm2LRwWLHBiF9Ra8ZhoUtfpw Date: Mon, 11 Mar 2024 04:25:16 +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: TY0PR04MB6328:EE_|TYZPR04MB6635:EE_ x-ms-office365-filtering-correlation-id: 31f63688-bb11-4b03-a8ee-08dc41834106 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 2jtiMrksGZpnm4+jifJpaIjoPI/BK2LTWVZKbeFmxOeHzD+Nxs05SuGBFsTN2yU3oCFb0jgniPK/FjtyLwcyLh3dBjOXLOzzuHQT4xCdusbFSVc8Ueab4cBGXxup7C/8HQHdnDHwcueh7Rn5uVhdKF8vxP/uZFV/JcDk3dig455asKOqWGu+T0p/3Dxb5hhsTNcMFoyqqZIZU+rlj7n5aYyoq9aO202HKsJvE93MsQJFxEf0NxIm3mobPCxU11tjft/Aoqs0MeE49CFYV+xkTsg9FqGYQthKjiE2zK5/JkZmjw/QijWWnQsGIlWwH/QIBzlx+gV1CLAM9V//1nljpJGHXNvmv4Ssa79FP9HanDZXfDEm0VLGGJzte2oH3QoVhH7ZuqZ0nmWRENuR6Vm1nx8EcSvxWFv0FCVR2w2SQw6ASFqlO78OVEiMXzIdoWO8kwB8av+GVTg/MiS4v5UasJ0ydUrsHiOHpO5pMD45LJ+hULzKM7gx0Nh47Kd/Zm+25F01ST48Xq4rAyqrmq9i34pxgm+xROpxmtassGU5nnX+EUNqBc3/6QU7Whzzd4pJFEdifXsZFtI45pAie4SkdLjGKprevQgM8eHaCxU3pZufrIKzTxzF/D1jHis0yxdVprr3LGWMSkKnM3ZbHSwas+kBdImzFNoUYJ6z1tJIyIPVtsvaTYTC3U2JzD02XpITNIQKf0hucL0WIDDw0PghOg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:zh-cn;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:TY0PR04MB6328.apcprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(1800799015)(38070700009);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?ZwerorGbuSwAeTf8EvSICxAvXZz7?= =?utf-8?q?nOjRHw0Yt14o6ZDRg9JpssG+MfhsfusL7SmIYREd7DLKZB0wn64fRQ5XtMWhiTbo5?= =?utf-8?q?p0sNKNYNTijLrICMRhQlGOKGVOyRQoOQOXoeCc1nMlWK3KU+oo7K86cD76c2f2krs?= =?utf-8?q?2zMsM5v5dY+MnzJezRuqC6rQeXIarH/qGCVca6xADxNM7AuS4rcc0wqCbkSvU/p0U?= =?utf-8?q?aptMzeKy8Ds+hHF3ws0hY1bawvZk9qw3k0rGy7JS3Ggk/muts55ReFXX/Mnc3yS7f?= =?utf-8?q?y7QKw0AL1+Hyp+0JJ1qSjTmfwFeVOfm4liDpKlcKj1dXRjGU90T2MWxtL1DCcN2XF?= =?utf-8?q?66ODcO1iUslZA9JcIgurIL5ASBq4IUVG63v1I/gR+fw1KEHTbgpHKJxeW4WlJxaY7?= =?utf-8?q?kh/7pPZSKLV/QV2A8HfK2h6eOhnZ0juwGmZ5ow4g8Ix40gYCNDOhqd0H6dxrkmf8n?= =?utf-8?q?rxd2A8unWp7ShIubPDQUrjTRbstJ+7/CyJwDBQBDqrB2t3zlKtdyYOaxov3Jshy5X?= =?utf-8?q?k4LzmQn2sipp1z4NjZQzjVxR23fWJLvKYGJrO8jN7S3Bxro91oBnq/E6vbqEtfTjO?= =?utf-8?q?jUZmJNYo3pJzysfdqkzapeddCRcAJ/7Q/8zTyKKaG7/yd2xEqvkc+b74dF/8I5HWd?= =?utf-8?q?FFUJBu7CbAhAo4XX6KqO4A5i8h11QCacQVBTnpXx59Uj0o/ruA0MIlYkkKbLbEQzb?= =?utf-8?q?+6M4CPOJdQS2qtqsmRTpKT/hO7RfW11FlGZMMzmR/VFu4wrxvj1s8ybMVpKpSAKZc?= =?utf-8?q?PE6zMyTqoD9dM8K0RMNh2qdAO2+Y94vJhedh5nGprRYDPJQVi5UWnwSS3skaueC2H?= =?utf-8?q?VnyyMKvh8b740q9/kTx743qTCcz7r8xPeKIGhBz5FRGIuYvmVjUn2xKqMQ8/aXFX+?= =?utf-8?q?87lgSfaIPCZZ/3zQz7SN2VGYJsIZbX14NqPLglvCK+XrWxC0CNWljnLCSINwyRFft?= =?utf-8?q?DdQerysrydhpe+a/qkSiyuOlnPCnv44o2F1kJsL352ZA8/tNSbZ8geJkJSv3GdNYv?= =?utf-8?q?T0Z5fU0shbtGghLa0Xmv4ju9h1XODkQP8Wbp36BFA1jBWCiOI/MGhjQJ9qX4g67hw?= =?utf-8?q?YFp0XCsAmcpqI4X7aCzmNO8/pCc5ZjOHIQBgPuuqvAEfrJmGWFg8606yzeVbPJVRX?= =?utf-8?q?CnF2pcpWpGYW5yRe1Vio7I5Ib5gwhfj6e2lkWV9wXdvcmIYGDS+GHYmJ3NKeiY91k?= =?utf-8?q?45q+8h7KOvnhTchp/s5TlSLX+4lTwBaTu1DM4mDW+nnr982oDdx8oLwcGa2thiQ5G?= =?utf-8?q?jvhuJoTtCjvhIb/qKngr5um3y28LQE5/ssFoD49yqEzcFBVX/pAKBEPXA/GUbuUrZ?= =?utf-8?q?o4Rkh9YLZgTWlLbUNVEvUgcRJ33foch+mgse6Ihj8D2O31QHIyDE4Y8iedUWfhQab?= =?utf-8?q?M0kqI03EPeNXHC+1qK9bF+idgWwrXkyv356RB6pLbBylRRGdYUfYs7/G4HJx/UQSp?= =?utf-8?q?7n3dG+rHutYAJ8r15vPxeFr3nY4WTvYpxX6//FV3bOGLc+wurQgN4SKPT5XKfwElV?= =?utf-8?q?rmov0EOa40OW?= 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: cKgDsSvIxdJ3nqz0yCBSB1a3f0p8ngNf/bf5RKO29ozCeq60qBzt7OhjtbfFfdyZmeN1rFgXvZX2L0LBaKZPkuHTDnL8eE+rICTqaHiSVH4OxN3mqfeUWCLEdVULJAsnWos0NXgXE6rjd4YHWfVGf/N/nh2Fz5aI6DKQxWTBWdYU6eOs5eCQ2PRa/g8jLP3spPvG1l9O1Ph6gK8Da2ESLuFv/x0S3ngQYDM9o86b+eP7nZfUKff4EvgX3zAqU64OyGLtQz/U1hR9TZKho8B4+kIVStAi9RMYGf7BPWT3xxGwX6IkXTl5xfoz6OICmmGzkwuzEA9XupBVAq+frrph4lR1SRAX38Ucn2PGkWK8/VEo0yaeH8ABIej48d/EzroQYmFNbq/wOl7zYO7Lrsi8bL9+lAcBgFf5bCcf8Mzb+Kq8NAhbC6rbRvgK6LvNrE3auwrZxHV1Yv7dK5dScLDByY3X3HfThSXoRKQaBHSu479rlTtt1TR4pVPcFSjsqvNHYOSZ6LdPlUE38l9E2TNi1rEOuWnEJKCaj9zEfB7c8RKaTHildaTj9e9fgEAeF6yF9dHFhJ1SbE8DVvFeQRE1Jr9eNINnGX0sFtR4ajybTE/V82N9lPX0xwSL3zHO+0Xt X-OriginatorOrg: sony.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: TY0PR04MB6328.apcprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 31f63688-bb11-4b03-a8ee-08dc41834106 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Mar 2024 04:25:16.7050 (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: 8ljqLt7qB9NpnhG0yTOlpw9FQiJcBR9YHsgdXrLEBLxuzcEwXYyYtQ3fmU95xKbhKKRI+epRh/3k8Cn/w6xPLQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR04MB6635 X-Proofpoint-GUID: bz6bUWWDR9yjHfSuSlGRdsIj1tTkSgz9 X-Proofpoint-ORIG-GUID: bz6bUWWDR9yjHfSuSlGRdsIj1tTkSgz9 X-Sony-Outbound-GUID: bz6bUWWDR9yjHfSuSlGRdsIj1tTkSgz9 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-11_01,2024-03-06_01,2023-05-22_02 Before this conversion, each dentry traversed needs to be read from the storage device or page cache. There are at least 16 dentries in a sector. This will result in frequent page cache searches. After this conversion, if all directory entries in a sector are used, the sector only needs to be read once. Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru --- fs/exfat/namei.c | 126 ++++++++++++++++------------------------------- 1 file changed, 42 insertions(+), 84 deletions(-) diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index 2c6df4f966f5..79e3fc9d6e19 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -204,21 +204,16 @@ const struct dentry_operations exfat_utf8_dentry_ops = { .d_compare = exfat_utf8_d_cmp, }; -/* used only in search empty_slot() */ -#define CNT_UNUSED_NOHIT (-1) -#define CNT_UNUSED_HIT (-2) /* search EMPTY CONTINUOUS "num_entries" entries */ static int exfat_search_empty_slot(struct super_block *sb, struct exfat_hint_femp *hint_femp, struct exfat_chain *p_dir, - int num_entries) + int num_entries, struct exfat_entry_set_cache *es) { - int i, dentry, num_empty = 0; + int i, dentry, ret; int dentries_per_clu; - unsigned int type; struct exfat_chain clu; - struct exfat_dentry *ep; struct exfat_sb_info *sbi = EXFAT_SB(sb); - struct buffer_head *bh; + int total_entries = EXFAT_CLU_TO_DEN(p_dir->size, sbi); dentries_per_clu = sbi->dentries_per_clu; @@ -231,7 +226,7 @@ static int exfat_search_empty_slot(struct super_block *sb, * Otherwise, and if "dentry + hint_famp->count" is also equal * to "p_dir->size * dentries_per_clu", it means ENOSPC. */ - if (dentry + hint_femp->count == p_dir->size * dentries_per_clu && + if (dentry + hint_femp->count == total_entries && num_entries > hint_femp->count) return -ENOSPC; @@ -242,69 +237,41 @@ static int exfat_search_empty_slot(struct super_block *sb, dentry = 0; } - while (clu.dir != EXFAT_EOF_CLUSTER) { + while (dentry + num_entries < total_entries && + clu.dir != EXFAT_EOF_CLUSTER) { i = dentry & (dentries_per_clu - 1); - for (; i < dentries_per_clu; i++, dentry++) { - ep = exfat_get_dentry(sb, &clu, i, &bh); - if (!ep) - return -EIO; - type = exfat_get_entry_type(ep); - brelse(bh); - - if (type == TYPE_UNUSED || type == TYPE_DELETED) { - num_empty++; - if (hint_femp->eidx == EXFAT_HINT_NONE) { - hint_femp->eidx = dentry; - hint_femp->count = CNT_UNUSED_NOHIT; - exfat_chain_set(&hint_femp->cur, - clu.dir, clu.size, clu.flags); - } - - if (type == TYPE_UNUSED && - hint_femp->count != CNT_UNUSED_HIT) - hint_femp->count = CNT_UNUSED_HIT; + ret = exfat_get_empty_dentry_set(es, sb, &clu, i, num_entries); + if (ret < 0) + return ret; + else if (ret == 0) + return dentry; + + dentry += ret; + i += ret; + + while (i >= dentries_per_clu) { + if (clu.flags == ALLOC_NO_FAT_CHAIN) { + if (--clu.size > 0) + clu.dir++; + else + clu.dir = EXFAT_EOF_CLUSTER; } else { - if (hint_femp->eidx != EXFAT_HINT_NONE && - hint_femp->count == CNT_UNUSED_HIT) { - /* unused empty group means - * an empty group which includes - * unused dentry - */ - exfat_fs_error(sb, - "found bogus dentry(%d) beyond unused empty group(%d) (start_clu : %u, cur_clu : %u)", - dentry, hint_femp->eidx, - p_dir->dir, clu.dir); + if (exfat_get_next_cluster(sb, &clu.dir)) return -EIO; - } - - num_empty = 0; - hint_femp->eidx = EXFAT_HINT_NONE; } - if (num_empty >= num_entries) { - /* found and invalidate hint_femp */ - hint_femp->eidx = EXFAT_HINT_NONE; - return (dentry - (num_entries - 1)); - } - } - - if (clu.flags == ALLOC_NO_FAT_CHAIN) { - if (--clu.size > 0) - clu.dir++; - else - clu.dir = EXFAT_EOF_CLUSTER; - } else { - if (exfat_get_next_cluster(sb, &clu.dir)) - return -EIO; + i -= dentries_per_clu; } } - hint_femp->eidx = p_dir->size * dentries_per_clu - num_empty; - hint_femp->count = num_empty; - if (num_empty == 0) + hint_femp->eidx = dentry; + hint_femp->count = 0; + if (dentry == total_entries || clu.dir == EXFAT_EOF_CLUSTER) exfat_chain_set(&hint_femp->cur, EXFAT_EOF_CLUSTER, 0, clu.flags); + else + hint_femp->cur = clu; return -ENOSPC; } @@ -325,7 +292,8 @@ static int exfat_check_max_dentries(struct inode *inode) * if there isn't any empty slot, expand cluster chain. */ static int exfat_find_empty_entry(struct inode *inode, - struct exfat_chain *p_dir, int num_entries) + struct exfat_chain *p_dir, int num_entries, + struct exfat_entry_set_cache *es) { int dentry; unsigned int ret, last_clu; @@ -344,7 +312,7 @@ static int exfat_find_empty_entry(struct inode *inode, } while ((dentry = exfat_search_empty_slot(sb, &hint_femp, p_dir, - num_entries)) < 0) { + num_entries, es)) < 0) { if (dentry == -EIO) break; @@ -515,7 +483,7 @@ static int exfat_add_entry(struct inode *inode, const char *path, } /* exfat_find_empty_entry must be called before alloc_cluster() */ - dentry = exfat_find_empty_entry(inode, p_dir, num_entries); + dentry = exfat_find_empty_entry(inode, p_dir, num_entries, &es); if (dentry < 0) { ret = dentry; /* -EIO or -ENOSPC */ goto out; @@ -523,8 +491,10 @@ static int exfat_add_entry(struct inode *inode, const char *path, if (type == TYPE_DIR && !sbi->options.zero_size_dir) { ret = exfat_alloc_new_dir(inode, &clu); - if (ret) + if (ret) { + exfat_put_dentry_set(&es, false); goto out; + } start_clu = clu.dir; clu_size = sbi->cluster_size; } @@ -533,11 +503,6 @@ static int exfat_add_entry(struct inode *inode, const char *path, /* fill the dos name directory entry information of the created file. * the first cluster is not determined yet. (0) */ - - ret = exfat_get_empty_dentry_set(&es, sb, p_dir, dentry, num_entries); - if (ret) - goto out; - exfat_init_dir_entry(&es, type, start_clu, clu_size, &ts); exfat_init_ext_entry(&es, num_entries, &uniname); @@ -1033,18 +998,13 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir, if (old_es.num_entries < num_new_entries) { int newentry; - newentry = - exfat_find_empty_entry(inode, p_dir, num_new_entries); + newentry = exfat_find_empty_entry(inode, p_dir, num_new_entries, + &new_es); if (newentry < 0) { ret = newentry; /* -EIO or -ENOSPC */ goto put_old_es; } - ret = exfat_get_empty_dentry_set(&new_es, sb, p_dir, newentry, - num_new_entries); - if (ret) - goto put_old_es; - epnew = exfat_get_dentry_cached(&new_es, ES_IDX_FILE); *epnew = *epold; if (exfat_get_entry_type(epnew) == TYPE_FILE) { @@ -1094,19 +1054,17 @@ static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir, if (num_new_entries < 0) return num_new_entries; - newentry = exfat_find_empty_entry(inode, p_newdir, num_new_entries); - if (newentry < 0) - return newentry; /* -EIO or -ENOSPC */ - ret = exfat_get_dentry_set(&mov_es, sb, p_olddir, oldentry, ES_ALL_ENTRIES); if (ret) return -EIO; - ret = exfat_get_empty_dentry_set(&new_es, sb, p_newdir, newentry, - num_new_entries); - if (ret) + newentry = exfat_find_empty_entry(inode, p_newdir, num_new_entries, + &new_es); + if (newentry < 0) { + ret = newentry; /* -EIO or -ENOSPC */ goto put_mov_es; + } epmov = exfat_get_dentry_cached(&mov_es, ES_IDX_FILE); epnew = exfat_get_dentry_cached(&new_es, ES_IDX_FILE);