From nobody Sun Feb 8 12:42:58 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.3]) (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 443A035BDD9; Wed, 14 Jan 2026 12:13:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392824; cv=none; b=FysqlsfsnWncs4uO9qdkg/QdbwGpAN1lUaP3FOENVryX5tFj61AGattu/OiaZqWXL2a3xylbXuXJOeeSre/iyrBtCMHVOOAMPo8N8WCMqPoufEwpdm7oDc+eefeCrkPT3ZZ24Bgsecd+0rtyaWrgp2Kz28n/U6pDlE7kM86Mtk4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392824; c=relaxed/simple; bh=wSHkmJtxa0bvUNFSipEAHSRDbWgO6APGZwVjSWO54y4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DSWldLgVu2+0aBKBZRQFr1qc7vaVnp58xbjYLRrDrWZqTU/xodR0Ck2i6Nzw92lbZzXhcI7hhPHoMVaGay9a45A611GCz4M/QBg5eQ11sKvRbHJkYmAJvKXlNWjJJV+sZrrTTTrvP481Sjnhhmsxegbmmx1JUxfjDz729Lat1cI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=Hhe/ZZVD; arc=none smtp.client-ip=220.197.31.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="Hhe/ZZVD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=9z VD//8PA5fsQMoyhVWewQB2gVZ6awGsGvMm6NPrBhg=; b=Hhe/ZZVDQnzyUUeNEG Pq27W+Wmj+grYvx2HVK05EvtMA8C1HZEi6QrJGaJ3I3RhY4rezQq+vr2rumsFCly 5Oxt+fDhgzGP+j8s0y+inbhbe2fWaVwcQRaZ+E+CxKH1AbOBLTxEkdmKMczHtK8x kVY73sfgnHoAxVcFV0EdcyTng= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-3 (Coremail) with SMTP id _____wAXybtbiGdpFdouGQ--.5056S3; Wed, 14 Jan 2026 20:13:17 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Chi Zhiling , Yuezhang Mo Subject: [PATCH v3 01/13] exfat: add cache option for __exfat_ent_get Date: Wed, 14 Jan 2026 20:12:37 +0800 Message-ID: <20260114121250.615064-2-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260114121250.615064-1-chizhiling@163.com> References: <20260114121250.615064-1-chizhiling@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wAXybtbiGdpFdouGQ--.5056S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7tF13XFyrZFy8WF1kXrW5ZFb_yoW8ZFy3pr ZxK34fKr4UX3W293ZFyrs5Z3WrCa97GFykGay5Cws3Jryrtr1kZryxtryYvF4xJ3y8AFyY vF1UKF1rCwnrWa7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jzhFxUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC2x5tC2lniF6-6gAA3u Content-Type: text/plain; charset="utf-8" From: Chi Zhiling When multiple entries are obtained consecutively, these entries are mostly stored adjacent to each other. this patch introduces a "last" parameter to cache the last opened buffer head, and reuse it when possible, which reduces the number of sb_bread() calls. When the passed parameter "last" is NULL, it means cache option is disabled, the behavior unchanged as it was. Signed-off-by: Chi Zhiling Reviewed-by: Yuezhang Mo --- fs/exfat/fatent.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/fs/exfat/fatent.c b/fs/exfat/fatent.c index c9c5f2e3a05e..0cfbc0b435bd 100644 --- a/fs/exfat/fatent.c +++ b/fs/exfat/fatent.c @@ -36,18 +36,23 @@ static int exfat_mirror_bh(struct super_block *sb, sect= or_t sec, } =20 static int __exfat_ent_get(struct super_block *sb, unsigned int loc, - unsigned int *content) + unsigned int *content, struct buffer_head **last) { unsigned int off; sector_t sec; - struct buffer_head *bh; + struct buffer_head *bh =3D last ? *last : NULL; =20 sec =3D FAT_ENT_OFFSET_SECTOR(sb, loc); off =3D FAT_ENT_OFFSET_BYTE_IN_SECTOR(sb, loc); =20 - bh =3D sb_bread(sb, sec); - if (!bh) - return -EIO; + if (!bh || bh->b_blocknr !=3D sec || !buffer_uptodate(bh)) { + brelse(bh); + bh =3D sb_bread(sb, sec); + if (last) + *last =3D bh; + if (unlikely(!bh)) + return -EIO; + } =20 *content =3D le32_to_cpu(*(__le32 *)(&bh->b_data[off])); =20 @@ -55,7 +60,8 @@ static int __exfat_ent_get(struct super_block *sb, unsign= ed int loc, if (*content > EXFAT_BAD_CLUSTER) *content =3D EXFAT_EOF_CLUSTER; =20 - brelse(bh); + if (!last) + brelse(bh); return 0; } =20 @@ -95,7 +101,7 @@ int exfat_ent_get(struct super_block *sb, unsigned int l= oc, return -EIO; } =20 - err =3D __exfat_ent_get(sb, loc, content); + err =3D __exfat_ent_get(sb, loc, content, NULL); if (err) { exfat_fs_error_ratelimit(sb, "failed to access to FAT (entry 0x%08x, err:%d)", --=20 2.43.0 From nobody Sun Feb 8 12:42:58 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (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 B2A15396D03; Wed, 14 Jan 2026 12:13:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392823; cv=none; b=GUwpRQAmIxx/tRBp468EKOvf8qmBQK/LojGbWRxtIopcAq3NXHvrxZrSk/Zu7LsRzOp/sthkV9ZtrYoby+yPL2z59QqcSge8y/P9bCsORBTIx4uW54FU4wakVasyzUa7GtpGi0jYR9aI7KJ8YHtswcra4lSZ56M4IRtzhKYpWXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392823; c=relaxed/simple; bh=vXzeN87ZPW40M96npQ9uC2SA7mDPJUHl1+tWE7gw+NU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TnM96g2jLp7VTpQzWPMb1pUsxbaIiDbcQKTsuO97XNFphFZl2NhhcvCHs5Ie8ZGY4r4BJR0yF2Y2TeOFDP/KhgWRZQHDDcERkFujNhpEiRSUPy3TNdjKYrwmrwN6u2+6lYRumTXT74sp6Zw8ynor4amyfRc3XnrIn9tC/aPWHBM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=E83Cd5eC; arc=none smtp.client-ip=220.197.31.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="E83Cd5eC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=/q 6tTTqoj7s86leMp+s+1zFKx0nK5ToPirbKiCDB7lA=; b=E83Cd5eC5vKKFH5tC6 945ZRdjnxoHUktlWbJ5Bg2zuAwqTN6qOznCEiBv6GhwkQHSdRUAjggIE+rs0Yar7 0ISQqirOlOzhm/43ViRpJI9ScMF6cXYFR3UxmOIRWegOUDFcCxdn1SagIrv42QVY 4oR8FGebv5oVNr2Nq314ta+y0= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-3 (Coremail) with SMTP id _____wAXybtbiGdpFdouGQ--.5056S4; Wed, 14 Jan 2026 20:13:18 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Chi Zhiling , Yuezhang Mo Subject: [PATCH v3 02/13] exfat: support reuse buffer head for exfat_ent_get Date: Wed, 14 Jan 2026 20:12:38 +0800 Message-ID: <20260114121250.615064-3-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260114121250.615064-1-chizhiling@163.com> References: <20260114121250.615064-1-chizhiling@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wAXybtbiGdpFdouGQ--.5056S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxAFW7WFykJr45WF4fCw4Durg_yoWrCFWrpF 4DKa95JrW8t3W7uwnrtrs7Z3WS93yxWFykGa15A3Z0yryDtrn5ur17tryayFWrA3y8C3Wa kF1jgF1Uu3sxWaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jDEf5UUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC+B5tC2lniF5ykwAA35 Content-Type: text/plain; charset="utf-8" From: Chi Zhiling This patch is part 2 of cached buffer head for exfat_ent_get, it introduces an argument for exfat_ent_get, and make sure this routine releases buffer head refcount when any error return. Signed-off-by: Chi Zhiling Reviewed-by: Yuezhang Mo --- fs/exfat/cache.c | 2 +- fs/exfat/exfat_fs.h | 4 ++-- fs/exfat/fatent.c | 39 ++++++++++++++++++++++++--------------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/fs/exfat/cache.c b/fs/exfat/cache.c index d5ce0ae660ba..61af3fa05ab7 100644 --- a/fs/exfat/cache.c +++ b/fs/exfat/cache.c @@ -287,7 +287,7 @@ int exfat_get_cluster(struct inode *inode, unsigned int= cluster, return -EIO; } =20 - if (exfat_ent_get(sb, *dclus, &content)) + if (exfat_ent_get(sb, *dclus, &content, NULL)) return -EIO; =20 *last_dclus =3D *dclus; diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index 176fef62574c..f7f25e0600c7 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -432,13 +432,13 @@ int exfat_set_volume_dirty(struct super_block *sb); int exfat_clear_volume_dirty(struct super_block *sb); =20 /* fatent.c */ -#define exfat_get_next_cluster(sb, pclu) exfat_ent_get(sb, *(pclu), pclu) +#define exfat_get_next_cluster(sb, pclu) exfat_ent_get(sb, *(pclu), pclu, = NULL) =20 int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc, struct exfat_chain *p_chain, bool sync_bmap); int exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain); int exfat_ent_get(struct super_block *sb, unsigned int loc, - unsigned int *content); + unsigned int *content, struct buffer_head **last); int exfat_ent_set(struct super_block *sb, unsigned int loc, unsigned int content); int exfat_chain_cont_cluster(struct super_block *sb, unsigned int chain, diff --git a/fs/exfat/fatent.c b/fs/exfat/fatent.c index 0cfbc0b435bd..679688cfea01 100644 --- a/fs/exfat/fatent.c +++ b/fs/exfat/fatent.c @@ -88,49 +88,58 @@ int exfat_ent_set(struct super_block *sb, unsigned int = loc, return 0; } =20 +/* + * Caller must release the buffer_head if no error return. + */ int exfat_ent_get(struct super_block *sb, unsigned int loc, - unsigned int *content) + unsigned int *content, struct buffer_head **last) { struct exfat_sb_info *sbi =3D EXFAT_SB(sb); - int err; =20 if (!is_valid_cluster(sbi, loc)) { exfat_fs_error_ratelimit(sb, "invalid access to FAT (entry 0x%08x)", loc); - return -EIO; + goto err; } =20 - err =3D __exfat_ent_get(sb, loc, content, NULL); - if (err) { + if (unlikely(__exfat_ent_get(sb, loc, content, last))) { exfat_fs_error_ratelimit(sb, - "failed to access to FAT (entry 0x%08x, err:%d)", - loc, err); - return err; + "failed to access to FAT (entry 0x%08x)", + loc); + goto err; } =20 - if (*content =3D=3D EXFAT_FREE_CLUSTER) { + if (unlikely(*content =3D=3D EXFAT_FREE_CLUSTER)) { exfat_fs_error_ratelimit(sb, "invalid access to FAT free cluster (entry 0x%08x)", loc); - return -EIO; + goto err; } =20 - if (*content =3D=3D EXFAT_BAD_CLUSTER) { + if (unlikely(*content =3D=3D EXFAT_BAD_CLUSTER)) { exfat_fs_error_ratelimit(sb, "invalid access to FAT bad cluster (entry 0x%08x)", loc); - return -EIO; + goto err; } =20 if (*content !=3D EXFAT_EOF_CLUSTER && !is_valid_cluster(sbi, *content)) { exfat_fs_error_ratelimit(sb, "invalid access to FAT (entry 0x%08x) bogus content (0x%08x)", loc, *content); - return -EIO; + goto err; } =20 return 0; +err: + if (last) { + brelse(*last); + + /* Avoid double release */ + *last =3D NULL; + } + return -EIO; } =20 int exfat_chain_cont_cluster(struct super_block *sb, unsigned int chain, @@ -299,7 +308,7 @@ int exfat_find_last_cluster(struct super_block *sb, str= uct exfat_chain *p_chain, do { count++; clu =3D next; - if (exfat_ent_get(sb, clu, &next)) + if (exfat_ent_get(sb, clu, &next, NULL)) return -EIO; } while (next !=3D EXFAT_EOF_CLUSTER && count <=3D p_chain->size); =20 @@ -490,7 +499,7 @@ int exfat_count_num_clusters(struct super_block *sb, count =3D 0; for (i =3D EXFAT_FIRST_CLUSTER; i < sbi->num_clusters; i++) { count++; - if (exfat_ent_get(sb, clu, &clu)) + if (exfat_ent_get(sb, clu, &clu, NULL)) return -EIO; if (clu =3D=3D EXFAT_EOF_CLUSTER) break; --=20 2.43.0 From nobody Sun Feb 8 12:42:58 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.4]) (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 A8E013815E8; Wed, 14 Jan 2026 12:13:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392824; cv=none; b=dTNjD6wXOqsuM0+Qq4lq1eWBUPxXvS67hvO1w8RvR2vJA+xRGq3doLoj9fEqay3TqhiIJdCSxGCHlEcZtdnb4Fp9PCK8BoMLVXqSOIV7OdOvBDj13Kj0GciQehkCcdsFVQvD/KxwXDY3Q5Kv3VbR8nZf7OuNg5rd/X9D6z8OyDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392824; c=relaxed/simple; bh=lZ9o5twc++xSajO9MlRYLn+/RHkWGVkj3/AO8HpzkXQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QaM1YYr3fsGbXadtrEte0nMLJG3D+KNYJmiAhgWZe1ArbzNbnqsC6IzFGHlkFsSFiRT9zY76+p8E4llpF6r70xdDJth8TiaY8zLI4t2gd2K8QnAmsREVJ5P/C1AKlMGE/H4EtV0UKOFkUgLJlky1z+oGLhXc++ZqE31/dXxtqlA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=YEbUg+24; arc=none smtp.client-ip=117.135.210.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="YEbUg+24" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=DL +NcNIHLjMqkOTOK0OmVh7vEY80d2pJzl/dTNfgNAs=; b=YEbUg+24uV7pMO3E2W 7iCjVyZOwasz+Di9Ml2MQCbB1fQFW3e0vRkcQEDZcIDOESIT61lBNqW+CIamAvPG SuROdLZUECobKSjtOc0APyhijdDYdiVIUKgp6cwRq01Dn09dKo8C44viyi78Q1o1 TX36JGAnrLZ6vOd1YNeLtdJoU= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-3 (Coremail) with SMTP id _____wAXybtbiGdpFdouGQ--.5056S5; Wed, 14 Jan 2026 20:13:18 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Chi Zhiling , Yuezhang Mo Subject: [PATCH v3 03/13] exfat: improve exfat_count_num_clusters Date: Wed, 14 Jan 2026 20:12:39 +0800 Message-ID: <20260114121250.615064-4-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260114121250.615064-1-chizhiling@163.com> References: <20260114121250.615064-1-chizhiling@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wAXybtbiGdpFdouGQ--.5056S5 X-Coremail-Antispam: 1Uf129KBjvdXoW7Jw4UAryfAFWDJr17Jr43ZFb_yoWkGwb_CF 1IvryDWr4jyF1Syr1vk3yakFy2qa1xCrWqvrW2yFyDW3s8JrW7XFyUXFy7Cws2krsrJr98 ArZ3Arn3Ga10yjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU0l_M7UUUUU== X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC9x5tC2lniF56WwAA32 Content-Type: text/plain; charset="utf-8" From: Chi Zhiling Since exfat_ent_get support cache buffer head, let's apply it to exfat_count_num_clusters. Signed-off-by: Chi Zhiling Reviewed-by: Yuezhang Mo --- fs/exfat/fatent.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/exfat/fatent.c b/fs/exfat/fatent.c index 679688cfea01..f060eab2f2f2 100644 --- a/fs/exfat/fatent.c +++ b/fs/exfat/fatent.c @@ -484,6 +484,7 @@ int exfat_count_num_clusters(struct super_block *sb, unsigned int i, count; unsigned int clu; struct exfat_sb_info *sbi =3D EXFAT_SB(sb); + struct buffer_head *bh =3D NULL; =20 if (!p_chain->dir || p_chain->dir =3D=3D EXFAT_EOF_CLUSTER) { *ret_count =3D 0; @@ -499,12 +500,13 @@ int exfat_count_num_clusters(struct super_block *sb, count =3D 0; for (i =3D EXFAT_FIRST_CLUSTER; i < sbi->num_clusters; i++) { count++; - if (exfat_ent_get(sb, clu, &clu, NULL)) + if (exfat_ent_get(sb, clu, &clu, &bh)) return -EIO; if (clu =3D=3D EXFAT_EOF_CLUSTER) break; } =20 + brelse(bh); *ret_count =3D count; =20 /* --=20 2.43.0 From nobody Sun Feb 8 12:42:58 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.3]) (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 D173D393DF0; Wed, 14 Jan 2026 12:13:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392823; cv=none; b=oZ+jtTt89l5N/jPTbF+A4GFpjVP+5QRtlaRZ9XKxpHyUsaGxaPUfbftGuRxjp6Wv2RsmrGIhejrEwGsDztYSLBXalGTDn3664m4n+6+FLJTLGbCwuLRNQtM4342IdRunhSb+Njs3yBkCgMcKQiIdSruoDppmS1VslCdDjyqwq2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392823; c=relaxed/simple; bh=NW/VGH2Sry/Q+Tqpiz0QPIfYXbyj+zH9xmXmp1swjOA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GZMxFu4IowpGnClS0k6PpF2sl6efszBEFXV9tWKpIIjWhYU5t5ksnU2vXGflHxwNVxth48Supaok1gkLFdBgHrT4bs5YjEZV1YchIF+9wBx9kPssM+HLcRIbSWsgBzHrV3WSmImOfFXlZdIk+dpaDr9w18ifDpZwWDftKwZuDMk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=bVgX1Msk; arc=none smtp.client-ip=117.135.210.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="bVgX1Msk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=IL d38vwGbbZHuYFWPWdYhYKP11kWC8j3xNXdzwzfSj8=; b=bVgX1MskjKpHpsJLh9 sWTOaj1j1M/BKTXruAPOxD/9qrqp0uXw84Rc2zr5uFySh9cYgbbOnuSJbvZ/n1Qi C4fmrdbIHViUIqFSLblpg3Rb+ZpemzVhC9OoE0l7ckkgiIiA+cqLQR76FR3jKdQj Y0HqHfGoFlN0HibmYq8YTxqtY= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-3 (Coremail) with SMTP id _____wAXybtbiGdpFdouGQ--.5056S6; Wed, 14 Jan 2026 20:13:18 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Chi Zhiling , Yuezhang Mo Subject: [PATCH v3 04/13] exfat: improve exfat_find_last_cluster Date: Wed, 14 Jan 2026 20:12:40 +0800 Message-ID: <20260114121250.615064-5-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260114121250.615064-1-chizhiling@163.com> References: <20260114121250.615064-1-chizhiling@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wAXybtbiGdpFdouGQ--.5056S6 X-Coremail-Antispam: 1Uf129KBjvJXoW7Jw4UAryfCr15ur4rZFy8AFb_yoW8Jr1kpF WUCa15KrWrX3Wku3WUJFs3Z3Wfu3WxKF95CFW5Aw1Yy3s0qrnYyFy3tryayF4kJa1UKF1a gr1YgF1j9wsxGFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UR6wtUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC9x5tC2lniF56XQAA3w Content-Type: text/plain; charset="utf-8" From: Chi Zhiling Since exfat_ent_get support cache buffer head, let's apply it to exfat_find_last_cluster. Signed-off-by: Chi Zhiling Reviewed-by: Yuezhang Mo --- fs/exfat/fatent.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/exfat/fatent.c b/fs/exfat/fatent.c index f060eab2f2f2..71ee16479c43 100644 --- a/fs/exfat/fatent.c +++ b/fs/exfat/fatent.c @@ -296,6 +296,7 @@ int exfat_free_cluster(struct inode *inode, struct exfa= t_chain *p_chain) int exfat_find_last_cluster(struct super_block *sb, struct exfat_chain *p_= chain, unsigned int *ret_clu) { + struct buffer_head *bh =3D NULL; unsigned int clu, next; unsigned int count =3D 0; =20 @@ -308,10 +309,11 @@ int exfat_find_last_cluster(struct super_block *sb, s= truct exfat_chain *p_chain, do { count++; clu =3D next; - if (exfat_ent_get(sb, clu, &next, NULL)) + if (exfat_ent_get(sb, clu, &next, &bh)) return -EIO; } while (next !=3D EXFAT_EOF_CLUSTER && count <=3D p_chain->size); =20 + brelse(bh); if (p_chain->size !=3D count) { exfat_fs_error(sb, "bogus directory size (clus : ondisk(%d) !=3D counted(%d))", --=20 2.43.0 From nobody Sun Feb 8 12:42:58 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (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 D270A397AA3; Wed, 14 Jan 2026 12:13:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392838; cv=none; b=hQBTD6wuqyZbQRk2Qs4VGCpyuclJy/blqE3x1HdaZVrucCMVAL8KFkOaeyCJZXLmX0oNfPZ93qbr6uO1GRUWtFz553QNwjz7zbAWb2pUnPvpVXIWmbbdEypYOS0+UEHL/RYgtuabmywHSxRMitNtV2czj0QbgIo1zJxC1bbsAp4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392838; c=relaxed/simple; bh=KDXCotxwONhP6zSVi8AxEprmMBsQQ9R3cNSremX6cQI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KBk22WJtM/fepFZMJ6djBwQRg6rovq1yZQbbJHfhL09IibA2e5xibtDxkrmZY2S+i8USlUyN3x6WT+oGawY+b3Z5FYSOjySf6HknrIvYGKDid+zGsXxytufUiI3ei3WHAacFz2KTOa2iNV0wCB1azTVIM2hrH7YhKveU/xMJnKc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=Qb/YuNtx; arc=none smtp.client-ip=220.197.31.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="Qb/YuNtx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version: Content-Type; bh=o2HGJiUZh+JR18pAIXg9PAYBhKH/qnGqd4T6Crk2TrI=; b=Qb/YuNtxOzxIwuRKSEFRgH8u+Wwa2esWCXBeXVWLMUYPe6ThYLfQvAQcQpAokt 0bc2wxq6puhf4V2ErLWXuuDwXOoTLw5Ttumc/voFa39P7B98jLTYdLUWM/Ou6QDB iuHETwtMH+FE9EebIDh+EzmW5tipX1gh5Slgf6U0TQWPQ= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-3 (Coremail) with SMTP id _____wAXybtbiGdpFdouGQ--.5056S7; Wed, 14 Jan 2026 20:13:19 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Chi Zhiling , Yuezhang Mo Subject: [PATCH v3 05/13] exfat: remove the check for infinite cluster chain loop Date: Wed, 14 Jan 2026 20:12:41 +0800 Message-ID: <20260114121250.615064-6-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260114121250.615064-1-chizhiling@163.com> References: <20260114121250.615064-1-chizhiling@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wAXybtbiGdpFdouGQ--.5056S7 X-Coremail-Antispam: 1Uf129KBjvJXoW7Kw13Kr1DCr17tFy8uFWxWFg_yoW8XFWDpr WxKa15trW3J34Duw48trn7Xa4Skas7JF4xJan3G3Wjkw4qyrsYkrnxtr90kF98Gw1kWa1Y gr1Ygw4UuwnxGFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j2XdUUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC3B9tC2lniF+35wAA3s From: Chi Zhiling The infinite cluster chain loop check is not work because the loop will terminate when fclus reaches the parameter cluster, and the parameter cluster value is never greater than ei->valid_size. The following relationship holds: 'fclus' < 'cluster' =E2=89=A4 ei->valid_size =E2=89=A4 sb->num_clusters The check would only be triggered if a cluster number greater than sb->num_clusters is passed, but no caller currently does this. Signed-off-by: Chi Zhiling Reviewed-by: Yuezhang Mo --- fs/exfat/cache.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/fs/exfat/cache.c b/fs/exfat/cache.c index 61af3fa05ab7..0ee4bff1cb35 100644 --- a/fs/exfat/cache.c +++ b/fs/exfat/cache.c @@ -238,8 +238,6 @@ int exfat_get_cluster(struct inode *inode, unsigned int= cluster, unsigned int *last_dclus, int allow_eof) { struct super_block *sb =3D inode->i_sb; - struct exfat_sb_info *sbi =3D EXFAT_SB(sb); - unsigned int limit =3D sbi->num_clusters; struct exfat_inode_info *ei =3D EXFAT_I(inode); struct exfat_cache_id cid; unsigned int content; @@ -279,14 +277,6 @@ int exfat_get_cluster(struct inode *inode, unsigned in= t cluster, return 0; =20 while (*fclus < cluster) { - /* prevent the infinite loop of cluster chain */ - if (*fclus > limit) { - exfat_fs_error(sb, - "detected the cluster chain loop (i_pos %u)", - (*fclus)); - return -EIO; - } - if (exfat_ent_get(sb, *dclus, &content, NULL)) return -EIO; =20 --=20 2.43.0 From nobody Sun Feb 8 12:42:58 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.4]) (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 7CF05397AA1; Wed, 14 Jan 2026 12:13:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392843; cv=none; b=k5tNntGVn6w8WHuaOWPU5IVmIMZHL2MdHOM5RQ6OhvxcuNtiB8Y4TDPEw9VbrUCNNnpapW23p3LjqxnoU3IX3nZmoMdYnVGTarCu7AU5b9wQHgCa02yob7auWhmiGFg4TAdB1tBSdDmwT58QEjoQ9wkMIaQh9ujB9gIxouPpwxA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392843; c=relaxed/simple; bh=QOyXc4xe3hljiE5sVG55Bk9d8ZWEcfuxI1ERmTZgumU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jqzuWIRyXdVSzbSLI5snwQ2FQ4mD4379C2XUpZnUFO0I02L/2frTGez5qAAZwxlC93FaW8BkaE5Nsq6F4EW+cARVdCsjJmPRd4+lPKZlcA6G+jwHDiPxitSo3OVBLCP5RSNJWbYgC+ttOwg4uj87rMYQi+iS/zpNmo46mmMXMIg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=XZP+JyNF; arc=none smtp.client-ip=117.135.210.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="XZP+JyNF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=H1 PWdIvYYxqZSIKwGYx+IvVqayAKgIUIe9EptT3n8fY=; b=XZP+JyNFZs3A8RV4n8 3WEBNn9F0iGgGzocv7C+Fgp+punkPPq8AOiV+faNwkgAniN6eNeeM3FyOKtzS1fS 3XGKrVDyq6N6tSD0bINcb4MlrevVVW5dmVQJ/dCM2aOQWzNTTWwfCklsz0udTSjY CsBOJFLHax1eE4I0cu9Hor//g= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-3 (Coremail) with SMTP id _____wAXybtbiGdpFdouGQ--.5056S8; Wed, 14 Jan 2026 20:13:19 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Chi Zhiling , Yuezhang Mo Subject: [PATCH v3 06/13] exfat: remove the unreachable warning for cache miss cases Date: Wed, 14 Jan 2026 20:12:42 +0800 Message-ID: <20260114121250.615064-7-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260114121250.615064-1-chizhiling@163.com> References: <20260114121250.615064-1-chizhiling@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wAXybtbiGdpFdouGQ--.5056S8 X-Coremail-Antispam: 1Uf129KBjvdXoWrKFyUAw1rZr4kKFyxZry7Wrg_yoWkZrc_uF y0yFy8WFWa9w48tr4vyanI9ryYva10kF1Yyw1fArySq347Jr4Dt3ZrJa429r47Kr4xKF95 JFWFyFn3t3W09jkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU0eOJUUUUUU== X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC9wBuDGlniGB6dwAA3+ Content-Type: text/plain; charset="utf-8" From: Chi Zhiling The cache_id remains unchanged on a cache miss; its value is always exactly what was set by cache_init. Therefore, checking this value again is meaningless. Signed-off-by: Chi Zhiling Reviewed-by: Yuezhang Mo --- fs/exfat/cache.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/fs/exfat/cache.c b/fs/exfat/cache.c index 0ee4bff1cb35..d51737498ee4 100644 --- a/fs/exfat/cache.c +++ b/fs/exfat/cache.c @@ -260,18 +260,7 @@ int exfat_get_cluster(struct inode *inode, unsigned in= t cluster, return 0; =20 cache_init(&cid, EXFAT_EOF_CLUSTER, EXFAT_EOF_CLUSTER); - - if (exfat_cache_lookup(inode, cluster, &cid, fclus, dclus) =3D=3D - EXFAT_EOF_CLUSTER) { - /* - * dummy, always not contiguous - * This is reinitialized by cache_init(), later. - */ - WARN_ON(cid.id !=3D EXFAT_CACHE_VALID || - cid.fcluster !=3D EXFAT_EOF_CLUSTER || - cid.dcluster !=3D EXFAT_EOF_CLUSTER || - cid.nr_contig !=3D 0); - } + exfat_cache_lookup(inode, cluster, &cid, fclus, dclus); =20 if (*fclus =3D=3D cluster) return 0; --=20 2.43.0 From nobody Sun Feb 8 12:42:58 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.4]) (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 79D4D396B96; Wed, 14 Jan 2026 12:13:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392825; cv=none; b=OFLbtjTqqBAnggueBiw2WTGQxcZMaEw4v2gOqe9MacAd8kBiKgWDvd1ZYpLtYB8fqQCt72SdjSTzchM+B2oPUuTxyXTj3zgXz3UtO//zaUXrESH4QuuTz1AXfHZs4TJZsrps1SYxeYFDQ4O2oADRCmmuj/03PRfOnJ5oCaMdMpM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392825; c=relaxed/simple; bh=co0I1o3ERemVpy5nHn0jYfj0BpAaawHWYRwb/C39f14=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CXOaidMPG3EAvZuST4qnkEzZdJXx744gNJQL4WwWz1HjqifIqKyUVH946M3fV8uNMLw1hxzp9Dyrq3PtPkzq89tHRlvAQjc6U51LW5LPibBuMMjHFJH3bcLSj4pLj+FARDntzFQecidhQ2kxLrgx2yEw425OLn2jhGa9FZYvFug= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=KFc0z4+b; arc=none smtp.client-ip=117.135.210.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="KFc0z4+b" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Mu XaXsoluPLa5C1yrplDiQjMlRm3ZB3J+MRS6b3BMfw=; b=KFc0z4+bmXYVseW+yn zIVQFuI4Op3w1ZM/FzXuCOeuBuydQvRA5lGef76AWliTkN758NIoRrM+a8ZcmCXB H93uZNG1BP/xNUkNWPbvHlKJVepwrjA25dzpVKCsAcDTN+b6d722nJ4tQx2boXCG g+D1839L3v+HydWLGtcoaCU2Q= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-3 (Coremail) with SMTP id _____wAXybtbiGdpFdouGQ--.5056S9; Wed, 14 Jan 2026 20:13:20 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Chi Zhiling , Yuezhang Mo Subject: [PATCH v3 07/13] exfat: reduce the number of parameters for exfat_get_cluster() Date: Wed, 14 Jan 2026 20:12:43 +0800 Message-ID: <20260114121250.615064-8-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260114121250.615064-1-chizhiling@163.com> References: <20260114121250.615064-1-chizhiling@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wAXybtbiGdpFdouGQ--.5056S9 X-Coremail-Antispam: 1Uf129KBjvJXoWxAFyrGFykAw18XryfGryDWrg_yoW5KryUpr ZrKa48tay3Zayv9w48tr4kZa4fu3Z7GayUJ3y3Aryqkr90yr409F1qyr9IyFyrGw4kua1j 9FyYgw1j9rsrGw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j2CJPUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC+ABuDGlniGByrgAA3g Content-Type: text/plain; charset="utf-8" From: Chi Zhiling Remove parameter 'fclus' and 'allow_eof': - The fclus parameter is changed to a local variable as it is not needed to be returned. - The passed allow_eof parameter was always 1, remove it and the associated error handling. Signed-off-by: Chi Zhiling Reviewed-by: Yuezhang Mo --- fs/exfat/cache.c | 27 +++++++++------------------ fs/exfat/exfat_fs.h | 3 +-- fs/exfat/inode.c | 5 +---- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/fs/exfat/cache.c b/fs/exfat/cache.c index d51737498ee4..b806e7f5b00f 100644 --- a/fs/exfat/cache.c +++ b/fs/exfat/cache.c @@ -234,13 +234,12 @@ static inline void cache_init(struct exfat_cache_id *= cid, } =20 int exfat_get_cluster(struct inode *inode, unsigned int cluster, - unsigned int *fclus, unsigned int *dclus, - unsigned int *last_dclus, int allow_eof) + unsigned int *dclus, unsigned int *last_dclus) { struct super_block *sb =3D inode->i_sb; struct exfat_inode_info *ei =3D EXFAT_I(inode); struct exfat_cache_id cid; - unsigned int content; + unsigned int content, fclus; =20 if (ei->start_clu =3D=3D EXFAT_FREE_CLUSTER) { exfat_fs_error(sb, @@ -249,7 +248,7 @@ int exfat_get_cluster(struct inode *inode, unsigned int= cluster, return -EIO; } =20 - *fclus =3D 0; + fclus =3D 0; *dclus =3D ei->start_clu; *last_dclus =3D *dclus; =20 @@ -260,32 +259,24 @@ int exfat_get_cluster(struct inode *inode, unsigned i= nt cluster, return 0; =20 cache_init(&cid, EXFAT_EOF_CLUSTER, EXFAT_EOF_CLUSTER); - exfat_cache_lookup(inode, cluster, &cid, fclus, dclus); + exfat_cache_lookup(inode, cluster, &cid, &fclus, dclus); =20 - if (*fclus =3D=3D cluster) + if (fclus =3D=3D cluster) return 0; =20 - while (*fclus < cluster) { + while (fclus < cluster) { if (exfat_ent_get(sb, *dclus, &content, NULL)) return -EIO; =20 *last_dclus =3D *dclus; *dclus =3D content; - (*fclus)++; - - if (content =3D=3D EXFAT_EOF_CLUSTER) { - if (!allow_eof) { - exfat_fs_error(sb, - "invalid cluster chain (i_pos %u, last_clus 0x%08x is EOF)", - *fclus, (*last_dclus)); - return -EIO; - } + fclus++; =20 + if (content =3D=3D EXFAT_EOF_CLUSTER) break; - } =20 if (!cache_contiguous(&cid, *dclus)) - cache_init(&cid, *fclus, *dclus); + cache_init(&cid, fclus, *dclus); } =20 exfat_cache_add(inode, &cid); diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index f7f25e0600c7..e58d8eed5495 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -486,8 +486,7 @@ int exfat_cache_init(void); void exfat_cache_shutdown(void); void exfat_cache_inval_inode(struct inode *inode); int exfat_get_cluster(struct inode *inode, unsigned int cluster, - unsigned int *fclus, unsigned int *dclus, - unsigned int *last_dclus, int allow_eof); + unsigned int *dclus, unsigned int *last_dclus); =20 /* dir.c */ extern const struct inode_operations exfat_dir_inode_operations; diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c index f9501c3a3666..55984585526e 100644 --- a/fs/exfat/inode.c +++ b/fs/exfat/inode.c @@ -157,13 +157,10 @@ static int exfat_map_cluster(struct inode *inode, uns= igned int clu_offset, *clu +=3D clu_offset; } } else if (ei->type =3D=3D TYPE_FILE) { - unsigned int fclus =3D 0; int err =3D exfat_get_cluster(inode, clu_offset, - &fclus, clu, &last_clu, 1); + clu, &last_clu); if (err) return -EIO; - - clu_offset -=3D fclus; } else { /* hint information */ if (clu_offset > 0 && ei->hint_bmap.off !=3D EXFAT_EOF_CLUSTER && --=20 2.43.0 From nobody Sun Feb 8 12:42:58 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.2]) (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 AFEFF396D1A; Wed, 14 Jan 2026 12:13:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392843; cv=none; b=uyeVmSyWyYUOlKlivlMakfRgFH40nz15t6fq8Ofjh7n1lLt9wkOkdtUWL4dRoE6MULnWt+S7GNGmblUTd8azl4/QuO70u7vGhd4o8oYBUgY2tHs0oqSOij5cmac+l7NRx3z76DKsifdNfw5601mBATDjSvYP5yuc4VGV52B8nK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392843; c=relaxed/simple; bh=XiQcVI8iyJjioFbqheRyXGGGJfydAW9lCxKIUrohHcU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=awqG8Ap1rbcTkWSQNMmxV6IrKWLoNYv656U01JDFNztHjfgJSdnLc8FMiAisDP9WnHCcZeZSmgDhZ3ymoexx4cCP/YR9VMEKvLtEBPjEYtAxHdMngbNSIcVGt5SIAjSsPC3OP/1C6iQSuxXaR0jWKh/dbeLCtfMTsKgsSyrtDvI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=ViobYtjC; arc=none smtp.client-ip=117.135.210.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="ViobYtjC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Nd W1o9/NUG6DMBFpSt0Qe8w80cOjc3DMl1FZTjd3HAo=; b=ViobYtjC58qV/gVsoc vOTURytuHqKVASXWNfsCT5hXvJuUH1jrltD8R8ZI7Jh+xSb2gXxRTsM2f+UToSuE GjGrWF1CJjuf4dcoj9Y+WxvjgWF/kG9Rc/MbHuFwa/qmALl+9BtYgDAgX4a2Xz/6 IeTNXSW4hPFTFDD/5acCftaw8= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-3 (Coremail) with SMTP id _____wAXybtbiGdpFdouGQ--.5056S10; Wed, 14 Jan 2026 20:13:20 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Chi Zhiling , Yuezhang Mo Subject: [PATCH v3 08/13] exfat: reuse cache to improve exfat_get_cluster Date: Wed, 14 Jan 2026 20:12:44 +0800 Message-ID: <20260114121250.615064-9-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260114121250.615064-1-chizhiling@163.com> References: <20260114121250.615064-1-chizhiling@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wAXybtbiGdpFdouGQ--.5056S10 X-Coremail-Antispam: 1Uf129KBjvJXoW7Jw4UArW7KFy7Ar4DAr48Crg_yoW8JrWxpr WUKa1UJrWrX3s7uw48tF4kZr4F9as7GF4UJa1UAr1UAryqyr1F9F17tF9Iy3WrAw4kur4a 9FyrKw4j9wnrGaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j2JP_UUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC2wFuDGlniGHAFgAA3J Content-Type: text/plain; charset="utf-8" From: Chi Zhiling Since exfat_ent_get supports cache buffer head, we can use this option to reduce sb_bread calls when fetching consecutive entries. Signed-off-by: Chi Zhiling Reviewed-by: Yuezhang Mo --- fs/exfat/cache.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/exfat/cache.c b/fs/exfat/cache.c index b806e7f5b00f..025b39b7a9ac 100644 --- a/fs/exfat/cache.c +++ b/fs/exfat/cache.c @@ -238,6 +238,7 @@ int exfat_get_cluster(struct inode *inode, unsigned int= cluster, { struct super_block *sb =3D inode->i_sb; struct exfat_inode_info *ei =3D EXFAT_I(inode); + struct buffer_head *bh =3D NULL; struct exfat_cache_id cid; unsigned int content, fclus; =20 @@ -265,7 +266,7 @@ int exfat_get_cluster(struct inode *inode, unsigned int= cluster, return 0; =20 while (fclus < cluster) { - if (exfat_ent_get(sb, *dclus, &content, NULL)) + if (exfat_ent_get(sb, *dclus, &content, &bh)) return -EIO; =20 *last_dclus =3D *dclus; @@ -279,6 +280,7 @@ int exfat_get_cluster(struct inode *inode, unsigned int= cluster, cache_init(&cid, fclus, *dclus); } =20 + brelse(bh); exfat_cache_add(inode, &cid); return 0; } --=20 2.43.0 From nobody Sun Feb 8 12:42:58 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.5]) (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 5591C37C104; Wed, 14 Jan 2026 12:15:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392952; cv=none; b=ac6Ww8VTskP0jgt5xrjrpZIw94qFCcsfiK5M7LIhqfyoqyB2nNOCq8JzX8qSZ0U8Enhf3gHCKd5Gz4yHVQvuaMtY2eJS0QqsNEDNgrwPoQItPxISdoseuaund+GMJFf5+V5f/mHDgQc3oyanQG1GVOPhkcsP0Y2/GIG2KN4tDkI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392952; c=relaxed/simple; bh=kFA90oIXr+aBGkIf+9o0bpUAsXrYNksrybzcbm+Yj3U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qRinP+BCTO2kidNyK9Fxk3yo96J7GECJmF1nBd2s95UPp+pBY4R2Q/21yUjU7U8BWNNJaGOmEE0S5WfLcu1ihlFxCvtC1uI3LoulEKn9JzsoWQ9ITXpQR1iWSm/aHACvLAU7/aEbLu3/Hr+65CFVEWybrdeRyVqmSBI+CxbVgGk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=RBduyib9; arc=none smtp.client-ip=117.135.210.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="RBduyib9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=B0 Yc94LlFx90W4ro8+TYnrF+5U2is51KIPdGBdhy1Gc=; b=RBduyib9EuceBBrKnh pwfy/UMQUFaeYKD3LhXrQdg5EnGJGm181PvO+R5h8Uj4jLfyMGhky2+X3HD2pK6u SGskdpD4LhFKxYciL7+zvcDoPvLdkS35N4rdLStDwd9jd8zYNrZASto7yRSOiqmu x0aDpG65Q77PatpavZrfx+czs= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-3 (Coremail) with SMTP id _____wAXybtbiGdpFdouGQ--.5056S11; Wed, 14 Jan 2026 20:13:21 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Chi Zhiling , Yuezhang Mo Subject: [PATCH v3 09/13] exfat: remove handling of non-file types in exfat_map_cluster Date: Wed, 14 Jan 2026 20:12:45 +0800 Message-ID: <20260114121250.615064-10-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260114121250.615064-1-chizhiling@163.com> References: <20260114121250.615064-1-chizhiling@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wAXybtbiGdpFdouGQ--.5056S11 X-Coremail-Antispam: 1Uf129KBjvJXoW7Aw1fXF1fXF13Ar1DuFWxZwb_yoW8Gry7pr srGa4kKFWrXay7KF40gFs3Z343G3Z7GrWkXFW7Ar15Kr9Yyr1FvanFkr1xC3WUC3y8CFWY g3W3Gr4a9rnxGFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j2NtxUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC3AFuDGlniGG3-gAA3R Content-Type: text/plain; charset="utf-8" From: Chi Zhiling Yuezhang said: "exfat_map_cluster() is only used for files. The code in this 'else' block is never executed and can be cleaned up." Suggested-by: Yuezhang Mo Signed-off-by: Chi Zhiling Reviewed-by: Yuezhang Mo --- fs/exfat/inode.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c index 55984585526e..b714d242b238 100644 --- a/fs/exfat/inode.c +++ b/fs/exfat/inode.c @@ -156,27 +156,11 @@ static int exfat_map_cluster(struct inode *inode, uns= igned int clu_offset, else *clu +=3D clu_offset; } - } else if (ei->type =3D=3D TYPE_FILE) { + } else { int err =3D exfat_get_cluster(inode, clu_offset, clu, &last_clu); if (err) return -EIO; - } else { - /* hint information */ - if (clu_offset > 0 && ei->hint_bmap.off !=3D EXFAT_EOF_CLUSTER && - ei->hint_bmap.off > 0 && clu_offset >=3D ei->hint_bmap.off) { - clu_offset -=3D ei->hint_bmap.off; - /* hint_bmap.clu should be valid */ - WARN_ON(ei->hint_bmap.clu < 2); - *clu =3D ei->hint_bmap.clu; - } - - while (clu_offset > 0 && *clu !=3D EXFAT_EOF_CLUSTER) { - last_clu =3D *clu; - if (exfat_get_next_cluster(sb, clu)) - return -EIO; - clu_offset--; - } } =20 if (*clu =3D=3D EXFAT_EOF_CLUSTER) { --=20 2.43.0 From nobody Sun Feb 8 12:42:58 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.4]) (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 150E7397AA0; Wed, 14 Jan 2026 12:13:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392838; cv=none; b=FwcJ/j9WJTHA966qvah21lhEnCki88edztFuzJZh2WBt82iUQXw+lS10uOWMyCfi9v7SfnfmhO9spcFclkry1A4g+AoK1g9w0Z/qgzWIVHgmUIVRxn5WlWA5cF9dUMspTX7NSwhYNjuiJeBgqz2trEXWtpvlgJvjEodsxbDg6b4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768392838; c=relaxed/simple; bh=wggpCtCWmNQztcBxjMJh1Djqli2bnF8N8HdZHDOrBGo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l/LpX2lekqmST7qhzPmBYqhyJlBl0m5q48UekI7hftd6jwVjyl0JBNYUWeLCc5UKXYijiJ19wz8J7INQ9PliMIeJTK3CPb6C8KR2X7CJviwksGRUo0NeYK7QVrWHFIfnVRpiD+rY/RDkduG8cT4XC0OawLVcx131xwKCE3NmMCw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=VvBvJhRP; arc=none smtp.client-ip=117.135.210.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="VvBvJhRP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Sd u076G6wX8/527/HN6/TjfXwiqNfWXZAhmXWiv3CJ4=; b=VvBvJhRPlo0mxrsgVr sHqXOYeUe734KyHJR/ve8c1hmccTRNTSRQ71En/upqY2OEG8mePwcw4JahCwDQ1r NDn+UD782SguhHBg/o97Cr4w8QAXX7k+5ObTfQfknGO7MQvKwicC9kr2ZVlosLiO 2/OtZU8++QbNjBuebBcPlRlow= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-3 (Coremail) with SMTP id _____wAXybtbiGdpFdouGQ--.5056S12; Wed, 14 Jan 2026 20:13:21 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Chi Zhiling Subject: [PATCH v3 10/13] exfat: support multi-cluster for exfat_map_cluster Date: Wed, 14 Jan 2026 20:12:46 +0800 Message-ID: <20260114121250.615064-11-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260114121250.615064-1-chizhiling@163.com> References: <20260114121250.615064-1-chizhiling@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wAXybtbiGdpFdouGQ--.5056S12 X-Coremail-Antispam: 1Uf129KBjvJXoWxAF1rZr47urWftw43ury8Krg_yoW5tw4kpr s7Ka4rtr13Ja4DGa1xJr4kZryS9wn7GFy5JayxGryUGr90qF1FqFWqyr9xC3W8Ga95uFs0 q3WrGr1UuwsrJaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07URHqxUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC9wFuDGlniGF6gQAA3I Content-Type: text/plain; charset="utf-8" From: Chi Zhiling This patch introduces a parameter 'count' to support fetching multiple clusters in exfat_map_cluster. The returned 'count' indicates the number of consecutive clusters, or 0 when the input cluster offset is past EOF. And the 'count' is also an input parameter for the caller to specify the required number of clusters. Only NO_FAT_CHAIN files enable multi-cluster fetching in this patch. After this patch, the time proportion of exfat_get_block has decreased, The performance data is as follows: Cluster size: 512 bytes Sequential read of a 30GB NO_FAT_CHAIN file: 2.4GB/s -> 2.5 GB/s proportion of exfat_get_block: 10.8% -> 0.02% Signed-off-by: Chi Zhiling --- fs/exfat/inode.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c index b714d242b238..410f9c98b8dc 100644 --- a/fs/exfat/inode.c +++ b/fs/exfat/inode.c @@ -124,7 +124,7 @@ void exfat_sync_inode(struct inode *inode) * *clu =3D (~0), if it's unable to allocate a new cluster */ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset, - unsigned int *clu, int create) + unsigned int *clu, unsigned int *count, int create) { int ret; unsigned int last_clu; @@ -147,20 +147,23 @@ static int exfat_map_cluster(struct inode *inode, uns= igned int clu_offset, =20 *clu =3D last_clu =3D ei->start_clu; =20 - if (ei->flags =3D=3D ALLOC_NO_FAT_CHAIN) { - if (clu_offset > 0 && *clu !=3D EXFAT_EOF_CLUSTER) { - last_clu +=3D clu_offset - 1; - - if (clu_offset =3D=3D num_clusters) - *clu =3D EXFAT_EOF_CLUSTER; - else - *clu +=3D clu_offset; + if (*clu =3D=3D EXFAT_EOF_CLUSTER) { + *count =3D 0; + } else if (ei->flags =3D=3D ALLOC_NO_FAT_CHAIN) { + last_clu +=3D num_clusters - 1; + if (clu_offset < num_clusters) { + *clu +=3D clu_offset; + *count =3D min(num_clusters - clu_offset, *count); + } else { + *clu =3D EXFAT_EOF_CLUSTER; + *count =3D 0; } } else { int err =3D exfat_get_cluster(inode, clu_offset, clu, &last_clu); if (err) return -EIO; + *count =3D (*clu =3D=3D EXFAT_EOF_CLUSTER) ? 0 : 1; } =20 if (*clu =3D=3D EXFAT_EOF_CLUSTER) { @@ -232,7 +235,7 @@ static int exfat_map_cluster(struct inode *inode, unsig= ned int clu_offset, num_to_be_allocated--; } } - + *count =3D 1; } =20 /* hint information */ @@ -251,7 +254,7 @@ static int exfat_get_block(struct inode *inode, sector_= t iblock, unsigned long max_blocks =3D bh_result->b_size >> inode->i_blkbits; int err =3D 0; unsigned long mapped_blocks =3D 0; - unsigned int cluster, sec_offset; + unsigned int cluster, sec_offset, count; sector_t last_block; sector_t phys =3D 0; sector_t valid_blks; @@ -264,8 +267,9 @@ static int exfat_get_block(struct inode *inode, sector_= t iblock, goto done; =20 /* Is this block already allocated? */ + count =3D EXFAT_B_TO_CLU_ROUND_UP(bh_result->b_size, sbi); err =3D exfat_map_cluster(inode, iblock >> sbi->sect_per_clus_bits, - &cluster, create); + &cluster, &count, create); if (err) { if (err !=3D -ENOSPC) exfat_fs_error_ratelimit(sb, @@ -281,7 +285,7 @@ static int exfat_get_block(struct inode *inode, sector_= t iblock, sec_offset =3D iblock & (sbi->sect_per_clus - 1); =20 phys =3D exfat_cluster_to_sector(sbi, cluster) + sec_offset; - mapped_blocks =3D sbi->sect_per_clus - sec_offset; + mapped_blocks =3D ((unsigned long)count << sbi->sect_per_clus_bits) - sec= _offset; max_blocks =3D min(mapped_blocks, max_blocks); =20 map_bh(bh_result, sb, phys); --=20 2.43.0 From nobody Sun Feb 8 12:42:58 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.2]) (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 6F39E38A28D; Wed, 14 Jan 2026 12:18:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768393093; cv=none; b=Pkh5RCFYOjNk81EZr515hHYZcQFFExy8v2bzGnYnAnEhyPzEjE6morcP1SHrnAxS33TefeB85KLaKjrADsG9SVzdFNLUyPrZjoCw746Tl33w+pk0orJfFnTt0aH3jzdogUcvgvm3Q6hoauJaLb9PPcazYCvaSmCdN1AzRJtfahw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768393093; c=relaxed/simple; bh=5CPnencKtvcQWuRvkrQVcepJuJk42Lwa9FBjfMpnkWE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=POC18WXBa+cP4QKbPKxrm8jjG1mZpJbQGG5RBHqNcB9u6rov8pXPihlZ6FdR+pHGEwvg0Bzf8yalhjbZftzrYjwfAZ60ZeNvO4xypCKwhgaIsUfLODeNzeUx6b469UBO42UZer0OXf3cgVupMs1LutHvS1vUF0ktrjxsZhTYk1o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=DHPupvco; arc=none smtp.client-ip=117.135.210.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="DHPupvco" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=UI fjRH6grVewKiAQNlqkmnbVW08mAABKdCzAln6lWgM=; b=DHPupvcoNJ0e0qUyqk F6H5+7aqDeXodfz2MvWavn2Tz5n80bu+4/wpch/SDQ6FfPxfcaDQrvSu/RzsxnEc +yISpJBox7gOO577T+N9hVOEHimuM2UquOIhPq8wolU7jinhK1ODzxUsginpehOw UuMvCqRwIlCQOJe1Lr6nw8yEc= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g0-3 (Coremail) with SMTP id _____wDnj1NuiWdpGyITGQ--.2745S2; Wed, 14 Jan 2026 20:17:51 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Chi Zhiling , Yuezhang Mo Subject: [PATCH v3 11/13] exfat: tweak cluster cache to support zero offset Date: Wed, 14 Jan 2026 20:17:47 +0800 Message-ID: <20260114121747.616098-1-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260114121250.615064-1-chizhiling@163.com> References: <20260114121250.615064-1-chizhiling@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wDnj1NuiWdpGyITGQ--.2745S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7tFWUWw47KrW5ury8Wr1rJFb_yoW8Xr4DpF W7ta45Grs3ZasrCa18tFn2vayrWa97Ka17Ja1UGw1Ykr1qkr40qwnFyrnIv3WDKw48CrsF qFyru3WUur9xGF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07joE_NUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC2w+xT2lniW-P1QAA3Y Content-Type: text/plain; charset="utf-8" From: Chi Zhiling The current cache mechanism does not support reading clusters starting from a file offset of zero. This patch enables that feature in preparation for subsequent reads of contiguous clusters from offset zero. 1. support finding clusters with zero offset. 2. allow clusters with zero offset to be cached. Signed-off-by: Chi Zhiling Reviewed-by: Yuezhang Mo --- fs/exfat/cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/exfat/cache.c b/fs/exfat/cache.c index 025b39b7a9ac..73147e153c2c 100644 --- a/fs/exfat/cache.c +++ b/fs/exfat/cache.c @@ -92,7 +92,7 @@ static unsigned int exfat_cache_lookup(struct inode *inod= e, spin_lock(&ei->cache_lru_lock); list_for_each_entry(p, &ei->cache_lru, cache_list) { /* Find the cache of "fclus" or nearest cache. */ - if (p->fcluster <=3D fclus && hit->fcluster < p->fcluster) { + if (p->fcluster <=3D fclus && hit->fcluster <=3D p->fcluster) { hit =3D p; if (hit->fcluster + hit->nr_contig < fclus) { offset =3D hit->nr_contig; @@ -259,7 +259,7 @@ int exfat_get_cluster(struct inode *inode, unsigned int= cluster, if (cluster =3D=3D 0 || *dclus =3D=3D EXFAT_EOF_CLUSTER) return 0; =20 - cache_init(&cid, EXFAT_EOF_CLUSTER, EXFAT_EOF_CLUSTER); + cache_init(&cid, fclus, *dclus); exfat_cache_lookup(inode, cluster, &cid, &fclus, dclus); =20 if (fclus =3D=3D cluster) --=20 2.43.0 From nobody Sun Feb 8 12:42:58 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.4]) (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 E994E396D23; Wed, 14 Jan 2026 12:18:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768393105; cv=none; b=jnlep1wYOvyohvmpRki1effDXJp0ggg+ELlUfMXWDQmCErf4lXgD8FDcSzQ1/kcSIkIkgS2pj5mU36qGjIPhC3a2r0R3Y/9Zwg+N+vslMuuMqUbw7yB35i5mn38MuQ5MLNPiC2MTGNuMWdBy78IhmaOahCsQohdeVyzrYdksyTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768393105; c=relaxed/simple; bh=fnGVWejw8CBd4O40/UTXEaVE5/JOd8E0KH2F7dASF1E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t3gnlkJx6vkZziqPcmzSDX8akJxtVo7NfJamv6BYJW2Cnh7TLm2TeFI6Etou1H5LYL8whUDVBHm9Ufd2mG3BXueHSI4dU2g2J5ggvlmUnsOtkfPw//YXiWIkQzipiGVNyXCZqpzeZ0TjdMNHrjF1PngffptDTi82+GKc3Oyca54= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=ePEbt6Qg; arc=none smtp.client-ip=117.135.210.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="ePEbt6Qg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=1G jRKHO+YzW588aUda2BoS5KFPmuHGwkOhmS06xeg2k=; b=ePEbt6Qg0MiRsRMiud UlmTBVMgqUXqqR3SgvjlBDw2+Kk3Yfg7YuQiJCC2JGyHzaeqmm9zxVYNGQh39OIJ CiewDlyxEKZmH2o9lfYthkp1o6mf7njHptq6Vy3QoyQ1sw7DApmw52lUMKL1Z7ig g1se++e7l2l9yr5Uvnchgo/1M= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-4 (Coremail) with SMTP id _____wAnDqx4iWdpb3z5Fw--.339S2; Wed, 14 Jan 2026 20:18:01 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Chi Zhiling , Yuezhang Mo Subject: [PATCH v3 12/13] exfat: return the start of next cache in exfat_cache_lookup Date: Wed, 14 Jan 2026 20:17:58 +0800 Message-ID: <20260114121758.616122-1-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260114121250.615064-1-chizhiling@163.com> References: <20260114121250.615064-1-chizhiling@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wAnDqx4iWdpb3z5Fw--.339S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxXFW8ZrW7ZFWUGr1DJFyxXwb_yoWrGFy5pr Wxt3W5Jrs3Z347Ga1ftrs7Z34ruaykGF47J343Gwn8Crn09r4rurnrArnIyFWDKw18WF4a qr45Kw1Uur4DJaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07joksgUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC3Bm0UmlniXnIVwAA3C Content-Type: text/plain; charset="utf-8" From: Chi Zhiling Change exfat_cache_lookup to return the cluster number of the last cluster before the next cache (i.e., the end of the current cache range) or the given 'end' if there is no next cache. This allows the caller to know whether the next cluster after the current cache is cached. The function signature is changed to accept an 'end' parameter, which is the upper bound of the search range. The function now stops early if it finds a cache that starts within the current cache's tail, meaning caches are contiguous. The return value is the cluster number at which the next cache starts (minus one) or the original 'end' if no next cache is found. The new behavior is illustrated as follows: cache: [ccccccc-------ccccccccc] search: [..................] return: ^ Signed-off-by: Chi Zhiling Reviewed-by: Yuezhang Mo --- fs/exfat/cache.c | 49 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/fs/exfat/cache.c b/fs/exfat/cache.c index 73147e153c2c..5cdeac014a3d 100644 --- a/fs/exfat/cache.c +++ b/fs/exfat/cache.c @@ -80,41 +80,66 @@ static inline void exfat_cache_update_lru(struct inode = *inode, list_move(&cache->cache_list, &ei->cache_lru); } =20 -static unsigned int exfat_cache_lookup(struct inode *inode, - unsigned int fclus, struct exfat_cache_id *cid, +/* + * Find the cache that covers or precedes 'fclus' and return the last + * cluster before the next cache range. + */ +static inline unsigned int +exfat_cache_lookup(struct inode *inode, struct exfat_cache_id *cid, + unsigned int fclus, unsigned int end, unsigned int *cached_fclus, unsigned int *cached_dclus) { struct exfat_inode_info *ei =3D EXFAT_I(inode); static struct exfat_cache nohit =3D { .fcluster =3D 0, }; struct exfat_cache *hit =3D &nohit, *p; - unsigned int offset =3D EXFAT_EOF_CLUSTER; + unsigned int tail =3D 0; /* End boundary of hit cache */ =20 + /* + * Search range [fclus, end]. Stop early if: + * 1. Cache covers entire range, or + * 2. Next cache starts at current cache tail + */ spin_lock(&ei->cache_lru_lock); list_for_each_entry(p, &ei->cache_lru, cache_list) { /* Find the cache of "fclus" or nearest cache. */ - if (p->fcluster <=3D fclus && hit->fcluster <=3D p->fcluster) { + if (p->fcluster <=3D fclus) { + if (p->fcluster < hit->fcluster) + continue; + hit =3D p; - if (hit->fcluster + hit->nr_contig < fclus) { - offset =3D hit->nr_contig; - } else { - offset =3D fclus - hit->fcluster; + tail =3D hit->fcluster + hit->nr_contig; + + /* Current cache covers [fclus, end] completely */ + if (tail >=3D end) + break; + } else if (p->fcluster <=3D end) { + end =3D p->fcluster - 1; + + /* + * If we have a hit and next cache starts within/at + * its tail, caches are contiguous, stop searching. + */ + if (tail && tail >=3D end) break; - } } } if (hit !=3D &nohit) { - exfat_cache_update_lru(inode, hit); + unsigned int offset; =20 + exfat_cache_update_lru(inode, hit); cid->id =3D ei->cache_valid_id; cid->nr_contig =3D hit->nr_contig; cid->fcluster =3D hit->fcluster; cid->dcluster =3D hit->dcluster; + + offset =3D min(cid->nr_contig, fclus - cid->fcluster); *cached_fclus =3D cid->fcluster + offset; *cached_dclus =3D cid->dcluster + offset; } spin_unlock(&ei->cache_lru_lock); =20 - return offset; + /* Return next cache start or 'end' if no more caches */ + return end; } =20 static struct exfat_cache *exfat_cache_merge(struct inode *inode, @@ -260,7 +285,7 @@ int exfat_get_cluster(struct inode *inode, unsigned int= cluster, return 0; =20 cache_init(&cid, fclus, *dclus); - exfat_cache_lookup(inode, cluster, &cid, &fclus, dclus); + exfat_cache_lookup(inode, &cid, cluster, cluster, &fclus, dclus); =20 if (fclus =3D=3D cluster) return 0; --=20 2.43.0 From nobody Sun Feb 8 12:42:58 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (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 33AC039901C; Wed, 14 Jan 2026 12:18:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768393115; cv=none; b=pOIezsNS4fB+dw1KksS/tY2PzVoNUbp5tZltzHg1Yh+7YwVhxqzz6YiRDffjFNQBcoe0X4UiCuBJpyv4WCqTZVOGX2gOdsYXUjFVUUGo97lYDv8BPLCVvbEUFOkC5ug/KlXOfsel0MKIzUSf6fNJN5YQVvzn2HvFgmTU3IfUKX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768393115; c=relaxed/simple; bh=vhbO/+aBxW/vPqdx9L19jZqvSjNM1xaBM6Ja0kJ8RtE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YGAQIBoc8O2LIz6MLpihSbpUiBkfG94WY5h2gYgNfD7h/1Ld972Ij6dzUUfFytha9nTfE7xnoofhPya/9VL5wsTksm/CT3CbRrD9bQyfP1tKgAY4MqUeM5dCWbCKda13vkqPZ2Qse5J461qIOuSXIhB3gMhS5BjbD9wx/kSyV0U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=IMchwroI; arc=none smtp.client-ip=220.197.31.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="IMchwroI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=jf 9MOLjnXyA3xixjpSo2YcZ4xdjbYE/iej+10bxKbYo=; b=IMchwroIJGwvK9jRGg clI+ZEysYumWwEsB9Iaq6QuNK+htqPqZHHOs+h2LM7e3PhT6m5/qySkxS2Su8eVH fjCvTeYATMwhwMDh9Z6Y7Jv1EhJhscvruZwlLig0L1gvZQIxeXYGiz7IDcdsmk4B d+aXohOeuQzIDyjw9zYuIBkJg= Received: from czl-ubuntu-pc.. (unknown []) by gzsmtp5 (Coremail) with SMTP id QCgvCgDHK3aCiWdpxg+ELQ--.67S2; Wed, 14 Jan 2026 20:18:13 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Chi Zhiling , Yuezhang Mo Subject: [PATCH v3 13/13] exfat: support multi-cluster for exfat_get_cluster Date: Wed, 14 Jan 2026 20:18:08 +0800 Message-ID: <20260114121808.616139-1-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260114121250.615064-1-chizhiling@163.com> References: <20260114121250.615064-1-chizhiling@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: QCgvCgDHK3aCiWdpxg+ELQ--.67S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxWw1fJw4kAF4UuFWkCF1rJFb_yoWrtF1Dpr W7KayrtrZxXa9ruw4xtr4kZFyS93Z7GFW7J347Jr98Crn0yr4F9rnFy3s0yF48Gw4kua1j vr1rKw1UurnrGaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UXNV9UUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC+AW3VWlniYWDqQAA33 Content-Type: text/plain; charset="utf-8" From: Chi Zhiling This patch introduces a count parameter to exfat_get_cluster, which serves as an input parameter for the caller to specify the desired number of clusters, and as an output parameter to store the length of consecutive clusters. This patch can improve read performance by reducing the number of get_block calls in sequential read scenarios. speacially in small cluster size. According to my test data, the performance improvement is approximately 10% when read FAT_CHAIN file with 512 bytes of cluster size. 454 MB/s -> 511 MB/s Suggested-by: Yuezhang Mo Signed-off-by: Chi Zhiling --- fs/exfat/cache.c | 56 +++++++++++++++++++++++++++++++++++++++++---- fs/exfat/exfat_fs.h | 2 +- fs/exfat/inode.c | 3 +-- 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/fs/exfat/cache.c b/fs/exfat/cache.c index 5cdeac014a3d..7c8b4182f5de 100644 --- a/fs/exfat/cache.c +++ b/fs/exfat/cache.c @@ -259,13 +259,15 @@ static inline void cache_init(struct exfat_cache_id *= cid, } =20 int exfat_get_cluster(struct inode *inode, unsigned int cluster, - unsigned int *dclus, unsigned int *last_dclus) + unsigned int *dclus, unsigned int *count, + unsigned int *last_dclus) { struct super_block *sb =3D inode->i_sb; struct exfat_inode_info *ei =3D EXFAT_I(inode); struct buffer_head *bh =3D NULL; struct exfat_cache_id cid; unsigned int content, fclus; + unsigned int end =3D cluster + *count - 1; =20 if (ei->start_clu =3D=3D EXFAT_FREE_CLUSTER) { exfat_fs_error(sb, @@ -279,17 +281,33 @@ int exfat_get_cluster(struct inode *inode, unsigned i= nt cluster, *last_dclus =3D *dclus; =20 /* - * Don`t use exfat_cache if zero offset or non-cluster allocation + * This case should not exist, as exfat_map_cluster function doesn't + * call this routine when start_clu =3D=3D EXFAT_EOF_CLUSTER. + * This case is retained here for routine completeness. */ - if (cluster =3D=3D 0 || *dclus =3D=3D EXFAT_EOF_CLUSTER) + if (*dclus =3D=3D EXFAT_EOF_CLUSTER) { + *count =3D 0; + return 0; + } + + /* If only the first cluster is needed, return now. */ + if (fclus =3D=3D cluster && *count =3D=3D 1) return 0; =20 cache_init(&cid, fclus, *dclus); - exfat_cache_lookup(inode, &cid, cluster, cluster, &fclus, dclus); + /* + * Update the 'end' to exclude the next cache range, as clusters in + * different cache are typically not contiguous. + */ + end =3D exfat_cache_lookup(inode, &cid, cluster, end, &fclus, dclus); =20 - if (fclus =3D=3D cluster) + /* Return if the cache covers the entire range. */ + if (cid.fcluster + cid.nr_contig >=3D end) { + *count =3D end - cluster + 1; return 0; + } =20 + /* Find the first cluster we need. */ while (fclus < cluster) { if (exfat_ent_get(sb, *dclus, &content, &bh)) return -EIO; @@ -305,6 +323,34 @@ int exfat_get_cluster(struct inode *inode, unsigned in= t cluster, cache_init(&cid, fclus, *dclus); } =20 + /* + * Now the cid cache contains the first cluster requested, collect + * the remaining clusters of this contiguous extent. + */ + if (*dclus !=3D EXFAT_EOF_CLUSTER) { + unsigned int clu =3D *dclus; + + while (fclus < end) { + if (exfat_ent_get(sb, clu, &content, &bh)) + return -EIO; + if (++clu !=3D content) + break; + fclus++; + } + cid.nr_contig =3D fclus - cid.fcluster; + *count =3D fclus - cluster + 1; + + /* + * Cache this discontiguous cluster, we'll definitely need + * it later + */ + if (fclus < end && content !=3D EXFAT_EOF_CLUSTER) { + exfat_cache_add(inode, &cid); + cache_init(&cid, fclus + 1, content); + } + } else { + *count =3D 0; + } brelse(bh); exfat_cache_add(inode, &cid); return 0; diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index e58d8eed5495..2dbed5f8ec26 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -486,7 +486,7 @@ int exfat_cache_init(void); void exfat_cache_shutdown(void); void exfat_cache_inval_inode(struct inode *inode); int exfat_get_cluster(struct inode *inode, unsigned int cluster, - unsigned int *dclus, unsigned int *last_dclus); + unsigned int *dclus, unsigned int *count, unsigned int *last_dclus); =20 /* dir.c */ extern const struct inode_operations exfat_dir_inode_operations; diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c index 410f9c98b8dc..86bce7ea2725 100644 --- a/fs/exfat/inode.c +++ b/fs/exfat/inode.c @@ -160,10 +160,9 @@ static int exfat_map_cluster(struct inode *inode, unsi= gned int clu_offset, } } else { int err =3D exfat_get_cluster(inode, clu_offset, - clu, &last_clu); + clu, count, &last_clu); if (err) return -EIO; - *count =3D (*clu =3D=3D EXFAT_EOF_CLUSTER) ? 0 : 1; } =20 if (*clu =3D=3D EXFAT_EOF_CLUSTER) { --=20 2.43.0