From patchwork Mon Mar 18 05:22:08 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: 13594979 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 E225C22087 for ; Mon, 18 Mar 2024 05:22:23 +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=1710739346; cv=fail; b=Ac/x6VMgv/NHegjGIuoiu780Z4nQNjVwuMxCqYxYnjqVgloXoI5hJ7rV80BvIaIfR82oEDJsdEo4Y25jfihuJgu/nkROLjq9cmduPjlihlfJRgNB9vGOZZbjiPnyzd4L7beGHMs7TDEjXTjQ33tyNGOxlHqm/me2fPIE5XPI8bo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710739346; c=relaxed/simple; bh=iny/RLi5AJITGGyXIiTsZmhESbLXSqTlE9iCuz04RJk=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=U6KzcoN0jV6ekBvB65cka6r2HKchZBJrvQZQcIgmQuOiSCar8WtEMLOnHRIGwtt8rIbEK32pC8Yh6xYQPIiCgygohTQZcVHz98LeQcTHgEOEs13uY8iZKMleTpQ++s4jT7QSfZ/uO4ZtGNE+sYYX6EjFch0KdqX3OxqNw8tIwVs= 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=YA/CmI8r; 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="YA/CmI8r" 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 42HNd5eR030951; Mon, 18 Mar 2024 05:22:15 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=iny/RLi5AJITGGyXIiTsZmhESbLXSqTlE9iCuz04RJk=; b=YA/CmI8rtbfMbI1s8ePzE4PtF3/JJFkyykpOji5EV68axXvCX7Ty/M8TxXL494MtZVVf x1nLBNGggXDwivQIKdFkDCJ4oZxvvlBSIowDuJUdHs4iWxdsna2a3HVKFIKAgAbIK4cG NpNIHKXc5pAKF7E1XRh7xeTnNN9xQHzqfuoBLegcifLi/lYVqN0+fdw8E/akQnZMpLPR 4xZTi004lAex7Ik9YEM0HhyIPrgusLyirvQqCWyunjZ0sZoCRzbKhANl4zO11SNiETJK OW4EZPnEoIxGzaSZT5FBZKO0zhoze1ht8+vIiD4Vbx3ZOSR8pr2VGTQBAGpGscP3PwyN Rg== 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 3ww1am1hkc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Mar 2024 05:22:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l0J+Q4UV4Cu9QZ4AAivVXSdUvzRISWA7tI7jBahcsMwZyVpleEnqLJKeASfj3ocf6JYluLJmoi/ZoJop7LeDlzHbB0CU60UYsidEG1Wsq0ePJR6vExslILefRMvpauREPnrq4/M2yZe5jSAi/AnC9OniGr/R9bQKyDTb0BxFZBXs4oEmSRS/tFCcmecAhZojAOnGreKiHoPJw0LIjul06WMsBo6+QcwKPs3uMwgotfiXMqCRBW7mb6lKKobJGqNdHa+O0rwocHpJKKVJaWciJMu3Gue+0qdU2MXn/10mzEDe3vVx8EFha+ftRvno/JPqd6iOAAIPJZagTX35Zm2P2A== 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=iny/RLi5AJITGGyXIiTsZmhESbLXSqTlE9iCuz04RJk=; b=K1v/EaCtmWip2E+LTn2YMlSB9IWiivbupuA5ZE6ommS52TrDJVw0qTCCJ5EtLSGIhzFFWbdN7pxSTOziAeq59AQCc/twr867YPtxnZKKwKr/tepeA0ZovGHYKccW+1N72qtYBwcsqu0OKSsQKMai453wWlgDiWonRyZTjvC3NT9LnHBEXnMiiNly6FOClP/geyd5udIeYZZ/2SiZE5M8qf2oFN/QPrKZ5uAvKnmE78uamxSwgtstTMT+Y5K5xgiJCd+cjo8ZxQYg3IJm8scT1kHTU9AO1POQVsZcO9a7X8Sq/3FqAxvXjd11vGWHpBC9R0TwBCpo2fpemvNFOzF5Qg== 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:22:08 +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:22:08 +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 07/10] exfat: convert exfat_find_empty_entry() to use dentry cache Thread-Topic: [PATCH v4 07/10] exfat: convert exfat_find_empty_entry() to use dentry cache Thread-Index: AdoLF/aVSH28hG9dTA+AfxdrhgQHWRt2tcuQ Date: Mon, 18 Mar 2024 05:22:08 +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: b0d78aa1-0b2e-4aab-b265-08dc470b5b3f x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 9cVBQZHa/uYIVTnb/7W9HZIdemYav34CvbH2xGmCU7+1rEYhXuvfPtF3jp6FgKqoJDUv7k4v2Dc5bGXyRDcOoS4qHBMDb9Htv5aW2ngfdMwxMk5/U54YwmnCH63uM2HtY5eDml5nm0L/FoG1AkgvPpf8WBQ3fkfiXVWOFcd0c/Lh1c5HVSnX1ErJT86Odrfpkcj675dIfbGH9Ms43SeRWvpV2kISSuLycbDPidjBCNfoB9Z1ZaFZ3aMPPPnc/mJzOWZPk6OhmkHlyB++439G2iUAJgzA9l06+1mNRC5Pv1W4LWSCb7JELE3qzGyXZtJEETywCrgN8eZTLj22t9/te8bKQnk+05FV3wY4qLWR1Ai3mVQbrXPb0/8kCT/7+No2EKpC9MhMkaD62W4ONLNNG1KsBtNyBt5OmG7fzH8sLowtBoBBzRNBIkUZWeTOnvJQI5sKO6LPwdvMI4raGwVBL6B8esWI8vIQz4YpuG/fix42bp7jN0R9eQnQhCwMsvYt9WRvN7rrnME95le/y1Cf+1HIvqPOuxdzxAOye1ug37R9ijLWgovx42sfxbc6uTTDRZ7hLjqb+aTbcmp9PdmhtNwCqo0ekeCbjymv4Bqe8FQe1r4W1x5alK5K8VcgKhY/0dvB0V7t8JZrVpVt+pHWa+W2Nl4yKYzf4PdZCsYGykDG7PfsSYG2DuuhU0yXvRXwQ1cHnDqwp4/QB8TZrH+c1Q== 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?rwmzaJnXDQG8ju+DqcAEgrwax6Ic?= =?utf-8?q?RZPo4hL+65k88qNEVYlrA4OBuHZRk7FSdw/wa60RyKJRhKTCqU9o95b6zb+9ltHaj?= =?utf-8?q?q9Af76vhugJmIu91PhBWA6jBdutIo1CvuaX8N1C890EBIkQW55do/GNhe1cjmtjqP?= =?utf-8?q?mv0tXHrXKCg6xj4guMIEwebWNEYvmCbl3pkXlCFw9ABJDR0mEROwvvhIMjUmyHCjI?= =?utf-8?q?scbjf5Kf7QY0o5OszjuXutBOZhNgbRFgqp4RDErLxJEqj25Ynbo/vSfObk9oPgovF?= =?utf-8?q?I3zmNW/V4T5/wW+gC6bjSYDMWnC64MFNuRt9zb17dgasgCjaxGR2cOHp3AbAokF1e?= =?utf-8?q?AD9Hcf1zYjvjUtJ5LPlZuRfp0m5S/8NU8myKYvqe88hdD346LLdgNxlQIvqYw6ruj?= =?utf-8?q?K4U4tIKat8rvyXpc7sU8ucENGLunggUaFrU0G+Ig+NzrUOpurP6/Q5dGzMySON5dV?= =?utf-8?q?gTdc+MR9ott0Xzy09TsXnPtqQTKY5jwWYK/Mt6HTCc5gh+5FmuXvvKfkf4e5WzZWF?= =?utf-8?q?VDjLwaBGGV1XT55BMYhcbY5LX/ENWGpGg3W70iYBUqiuXlxbml9LhEzdNlsGrsoLz?= =?utf-8?q?IV3H4HyVwMcDquLPq5J7jkzT1I4tZTQdTsAcuW0XV9ksBle8UEYNLHoG7CfPII7zK?= =?utf-8?q?AzAXAmOZxQbloeI8RTIB2UkjLG7xZytFITmKmmT5Q+9QUtW8RKypmIgzo9p725+q1?= =?utf-8?q?zBS67NEQFls1INM5833QokHPiYS6UHJV7WmlleFDEZSPjWXx7I+t83iPMMebXs14O?= =?utf-8?q?NQpQQtNQ44nAFlwzCCgzV1a3gF4F3FA/ev42x7C/RAPOqguSbcwBVGOi6ZRArm5Qg?= =?utf-8?q?YkLi2S1Nxs+TSsA8Bqqpnz1KWWrjjh5S9V0QgP1gpgplENCwUnkcoBh8gyjOszOG2?= =?utf-8?q?ofg6pMCvKAK1lNA9lprKnh5uRJa8te7qkX5S2ris80Vv4K9/bsAcCncO6KlhQYIj8?= =?utf-8?q?sYrngs15eLG4dFoja6f/azJur/QfvMcSMsI+gOuqfO6pzvVd5xD+qYHYMkrUSFL6N?= =?utf-8?q?qkvvjyoR0xLeq40m1tMbGOYiunjbauSZTJCixPoXIlkoP9nRJO8ftyfJUlTy5tsH2?= =?utf-8?q?HAhEKU4p97JIjhMlt5y2DZsalQuOO0AsFIhMtES2tKwdzo43WVY5avTXNtl085Zm2?= =?utf-8?q?nE3osn7iBfWORoFc7d4v8NA9adMBcsy5wO4ZfAoEWzjQrPaxM4OZKA3nimedzYowZ?= =?utf-8?q?JMNeN50yDNDUiRx5eVhKBjZ6y/M3nPQjcZH/gEyAD1ULRoE1GsBc/PyOBbCt+q/5G?= =?utf-8?q?B5Xv97Y37rGlOm3cypxhD3LmqUgcF5LmxB1Q8lSw2W7xX6R81wMJO8dENzFw9ektP?= =?utf-8?q?PNU3e7ZxTEjUFs9hk8Q1Wgn4E5w8xtSg/BhGzzgM2PBIbgBDW7RlC28LSl7HisDQK?= =?utf-8?q?qSQD/rR23cjsaTr9aAZaPkSbTQzWudGQlhOF5LolHsm1LVaZjPyIWeqCg++jRRI24?= =?utf-8?q?AcptotKnO+tZEdsXm9lbN8qb/0q22nb32Mwzw/hEazOd4Bi926Wy8ogOJ0KxFAlQL?= =?utf-8?q?o2OOsKZHmRwj?= 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: CPJ+D68iuxQlWvl3tKPdyVbn8v5izW16sRRvWsNA1MXFQCmH+gcFAKr0Su989G5Lx+XMwbTatC/vVg6qCfK03Uevn7OT2cLyjSMMmCCbyJ2XDZ+aJfWVE3y5bxExADTyC4HHLKq6evLr8gbqg0ID+ei1n+i9uDh0DNmREMy0WHbN+F+3ck3692YP1JI/AfItd0sel7YYT20UVVcewRY5hMNY3SHTC2COu6tE/JH4iWDnpf0EeDGpZmDxb8pwy6HlBbVzKkQEdnMW8F7DgX+fk44Luhw5R8zWFM4PtEzJJshLCmMdULKMPNKTUcih1HOY62pJIq3QkVYKlWt2cd92XDc2UeYQj5AH7gxIdSAmjskgjBPIjzFhvFi4HfeK3D+mUpqO6DoMjU9GK5OnT1bJ91F5e8Fe5DC6nwXxTqDTSZX+fG2D9feYGF/G6XRShUyS3t6k54PBUuOpbC1qSMtknuozgbcjPY0ZkW1egLJBySYBcw7e3RCqhWSQjik9YqyN6GaTrEYvPbspNDBHo894vKL26AioR1AGP8xCFYxSwxFUJL+eM/gmJVYEX0SXxoKOGFAcUK1Z3dVoBcGYXQfHohP99pnKNbpvD/xd6/fe6AgBtjYU/HrSh3FTFZtGmiQl 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: b0d78aa1-0b2e-4aab-b265-08dc470b5b3f X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Mar 2024 05:22:08.0443 (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: Og0QGon1zN938oXZSo0mp21whEXhKIyEOoxv4M9QvT7a2lqmucYfDAUDdrbi/5rCoxi0ygIpGaqFlvY8Iv6YDg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SI2PR04MB5895 X-Proofpoint-ORIG-GUID: cAy1RI7Bjt_O_QpXBJedaQ5IQujzegKv X-Proofpoint-GUID: cAy1RI7Bjt_O_QpXBJedaQ5IQujzegKv X-Sony-Outbound-GUID: cAy1RI7Bjt_O_QpXBJedaQ5IQujzegKv 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, 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 Reviewed-by: Sungjong Seo Signed-off-by: Namjae Jeon --- 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);