From nobody Sun Feb 8 02:41:23 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 C36D4314D12; Fri, 26 Dec 2025 09:45:39 +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=1766742342; cv=none; b=hJW7gK+8EbxUV9Hu7kqI6A7es5wdx6GTeUSAB7vQZPoFbqwGGsysb6Cs1QLjmBZ+jul612cHOsp6zEPJ8zY2/5f3nd8NqZsqpKIEfNxuN2+f8dhqkepT7e6rwUhh8zWS+Qs/2WNsJjqwTQXT7T5XDa1unVq0JlGtqzlxL/Qa/us= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766742342; c=relaxed/simple; bh=Xb8C2JLdNadFXnGNd/14DTutB+ouyLvTF+ynAxnMW9g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NXS+V3srleGVk7hgEt4R931h5KGpnt5spGm+PE7OmfKRXDim4B0bTHPNk/AzwmX6QvHhREprsm4BU22JzTbF6AdNMwJSnE0rYhxLXMmriq24vLnQNee/Vavdqz02F+jpmpuKF9qid9a4XLDxPpcTfHWrAWb8Wh6iF7Tqpx3Qenk= 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=CvDIGtZV; 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="CvDIGtZV" 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=0v htbSvbnQVcK4ilcpDDyTdPLbheiLDwPIzUu6QCadA=; b=CvDIGtZVkBYLyVrzFe 0LXMhQROtoPXVr4L72bvG5/Lh9hCWhDOkn7ej2Y1a3pbejy3hjgm8XKj1gXXfCms 5Xd5hnR52GlPySWxkwcyaheGEnM49iU+Dv6/uNvSlHbvUvtvyLZRfpMbfKEifJG0 WbwhQx818NbPscwX7tWUBotas= Received: from chi-Redmi-Book.. (unknown []) by gzsmtp5 (Coremail) with SMTP id QCgvCgCnlXIPWU5p9JFCJA--.53S3; Fri, 26 Dec 2025 17:44:50 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Alexander Viro , Christian Brauner , Jan Kara , Matthew Wilcox , Chi Zhiling Subject: [PATCH v1 1/9] exfat: add cache option for __exfat_ent_get Date: Fri, 26 Dec 2025 17:44:32 +0800 Message-ID: <20251226094440.455563-2-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251226094440.455563-1-chizhiling@163.com> References: <20251226094440.455563-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: QCgvCgCnlXIPWU5p9JFCJA--.53S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7tF13XFyrZFy8WF1DKFy3Arb_yoW8Zry5pr ZxK34fKr4UX3W2v3ZFyrs5Zw1rC397GFyDGw45Cws3Jryrtr4kZryxtryYqF4xJ3y8AFWY vF1UtF15CwsrWa7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jz2NtUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC9xNI5WlOWROHCgAA3p 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 --- 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 02:41:23 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 D3ECE314D3F; Fri, 26 Dec 2025 09:45:39 +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=1766742342; cv=none; b=K55M2hdQlQfa4TSByhEL8Alh6J4DZ8geoqk0sbePeYT89FVgSPgSrGkDoHrwLCcHPSkjoyQ1ZatcTR091qCfFTFgS0lQGHtCgqvD7FtLpd7XhxV/XAXhRWqoKZ/Neu0C+SkWq3foVEfXK/pfhG5L6+ZWt+i2JK4X7lPNKtIrZ1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766742342; c=relaxed/simple; bh=1B+lE2U3eAYn+bEmF8/XAwLuFOqS0i95Q+IJTMt1yXc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=auUrRwQK7RqkTzbUwWen1Z+PrZe/Ph02YRDainikBy5lTDYWe5bexVsMArKXwKaCurm6BlhncxaEjxdvzSL7qkFjVdgHhFggVv1euTNMxeqdEzsZdibE8t6NycKkC6O8/8haI1ZvDwwjJlMTjn0B17ASwdgEAyXGogBQGJaLPaA= 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=K6ke+9RX; 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="K6ke+9RX" 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=W8 Dd4uKOqtugp8rh1JHuRfCfqK66RWhGo/RX+lV/P7o=; b=K6ke+9RXPEhzKJ0ZKT F/ES+xKMBXJND7+H1ZbLp2dEsxnDii/nhb/vN/OpriUw0dgU5p/+SlyhnzpreoRU 6W/cqjMYTX1yCTWY/zl12XNe6OusmtouZUOh1QqwBKwRA4BePrLNYVyZLctpsKTg X+Htz/A731LO+I7BFlMu2VhFM= Received: from chi-Redmi-Book.. (unknown []) by gzsmtp5 (Coremail) with SMTP id QCgvCgCnlXIPWU5p9JFCJA--.53S4; Fri, 26 Dec 2025 17:44:51 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Alexander Viro , Christian Brauner , Jan Kara , Matthew Wilcox , Chi Zhiling Subject: [PATCH v1 2/9] exfat: support reuse buffer head for exfat_ent_get Date: Fri, 26 Dec 2025 17:44:33 +0800 Message-ID: <20251226094440.455563-3-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251226094440.455563-1-chizhiling@163.com> References: <20251226094440.455563-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: QCgvCgCnlXIPWU5p9JFCJA--.53S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxAFW7WFykJr45AF1DZw1DZFb_yoWrCrykpF 4DKas5JrWUt3W7uwnrtr4kZ3WS93yxWFykGa15A3Z0yryDtrn5ur17tryayFWrA3y8C3Wa kF1jgF1Uur9xWaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j72-5UUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC+BNI5WlOWROBQAAA3q 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 --- 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 02:41:23 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.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 E148A291864; Fri, 26 Dec 2025 09:45:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766742340; cv=none; b=slk3vaQhGxtHDt64JYEh2KmbB8vsCdcMxfngkSS+/exZ34nsnaNf0HccJ/yptn8czmEbifqAv8OXlvuy2wNqRGLctisGr4R0dA4OgI0xaGcQ8lxVL9WUfDTsnm7a4I4kOfKBDoa8RjM1eonu6hmK3h+9FQuDcZgIA92Y1z+LAIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766742340; c=relaxed/simple; bh=p7J1A3k1PpQP8t2VLMhQe+7FnsV9LZt/G8cGNkFQSdQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sh/ggaRdeA0bq3IlI0Z+ohLY0VFaUWsunnl/+57Qzu27dYa3RNiAHo1dnYNV9Kes/b2DI6W56vU9zUTPdBvACVCO1B9UcIAmb4uBst1EpDEU8nsPtZykxbrx2IkEoxlyN2zzF3RZL1rnQ9nujWqOZ7PgJWgOkS5FQcoYEWLwe/U= 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=kGsHo69a; arc=none smtp.client-ip=220.197.31.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="kGsHo69a" 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=2z Kn3M2El0UGziHuxP9HkuCQv8bFi5A/9Zv8bRNdnds=; b=kGsHo69aQ6K/nbUAB9 +1wIe9EDo0JO3noJAI3k0nP/rJyvdSBtMgSVtvEzzOiyXoGDV1B76L6lKyF36e5x IiwCt4JtNQSiE/5dcpPzPhhchMHsDGh01teHyhSYO4wfhFa71uZZh44h9MZlbmbn oOw4oRJ2zCE5XsoCPuYrdUaek= Received: from chi-Redmi-Book.. (unknown []) by gzsmtp5 (Coremail) with SMTP id QCgvCgCnlXIPWU5p9JFCJA--.53S5; Fri, 26 Dec 2025 17:44:51 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Alexander Viro , Christian Brauner , Jan Kara , Matthew Wilcox , Chi Zhiling Subject: [PATCH v1 3/9] exfat: reuse cache to improve exfat_get_cluster Date: Fri, 26 Dec 2025 17:44:34 +0800 Message-ID: <20251226094440.455563-4-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251226094440.455563-1-chizhiling@163.com> References: <20251226094440.455563-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: QCgvCgCnlXIPWU5p9JFCJA--.53S5 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ar15Gr4ftrW3Aw1fWF15Jwb_yoW8WF13pr ZxKay5t3yrA3929w4rKFn3Z3WS9FZ7JF4UGay3A3Wjkryvyr4F9r17Kr9xA3WrJw4kuF4Y 9ryrK3WUurnrG3JanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jqYLkUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC+BNI5WlOWROBRAAA3u 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 --- fs/exfat/cache.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/fs/exfat/cache.c b/fs/exfat/cache.c index 61af3fa05ab7..4161b983b6af 100644 --- a/fs/exfat/cache.c +++ b/fs/exfat/cache.c @@ -241,6 +241,7 @@ int exfat_get_cluster(struct inode *inode, unsigned int= cluster, 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 buffer_head *bh =3D NULL; struct exfat_cache_id cid; unsigned int content; =20 @@ -284,11 +285,11 @@ int exfat_get_cluster(struct inode *inode, unsigned i= nt cluster, exfat_fs_error(sb, "detected the cluster chain loop (i_pos %u)", (*fclus)); - return -EIO; + goto err; } =20 - if (exfat_ent_get(sb, *dclus, &content, NULL)) - return -EIO; + if (exfat_ent_get(sb, *dclus, &content, &bh)) + goto err; =20 *last_dclus =3D *dclus; *dclus =3D content; @@ -299,7 +300,7 @@ int exfat_get_cluster(struct inode *inode, unsigned int= cluster, exfat_fs_error(sb, "invalid cluster chain (i_pos %u, last_clus 0x%08x is EOF)", *fclus, (*last_dclus)); - return -EIO; + goto err; } =20 break; @@ -309,6 +310,10 @@ int exfat_get_cluster(struct inode *inode, unsigned in= t cluster, cache_init(&cid, *fclus, *dclus); } =20 + brelse(bh); exfat_cache_add(inode, &cid); return 0; +err: + brelse(bh); + return -EIO; } --=20 2.43.0 From nobody Sun Feb 8 02:41:23 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 B6A2F31328B; Fri, 26 Dec 2025 09:45:40 +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=1766742343; cv=none; b=LJGF6fnAfWHpRTbd35hEfWjGhGTzsOdVOU7h9tnoulhmliWiYj/vIABa46VyNQy+rAs02MBpstHeCPrtI/tZ9SR3RejB5K2JOCE94bJ43CDJQIYyGthlLW0KOYpTAJZXLyXCKpjbdoZnrXiuBnLovnxutt99koUsJTuddQZQk3E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766742343; c=relaxed/simple; bh=QV3tmKsVrQB7Eux4rAx18e/5Tsm/yQOndaXeLh4Utr4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oV6FdbhuTUzOsaWCtXOObob97SONnCDo26CHBCFgoio4Ge4+UMkM4Y9D8TgN8NSz9kavMY9zhA2OGnSCwjwuZa10MJgDt51L/rLnx6DakyAm3BLh6/GR8w7mvUAQBwDJcz3xZv6JdPlMgfrAyJZaNuNiLqSUbL4LPK9SZ/r7H9U= 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=HPUT9OYH; 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="HPUT9OYH" 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=EB aNGS1nr6TdvpG1M4Ssyj0BII1bSbsHnPJMwETv0k0=; b=HPUT9OYHNiVpnPTy2+ pslvldUSba7jokGwmLsjkIQE/UUeZoGpxqrCKRtimFWz+11tVOhR79SFPIWuY+J8 SGF9+FSIyFry9OBw5qb7/4A+QAuPUe5p76Bel+i3Cm/bHXs9dxPng9ovesfqlyjh +a9tTTNb4DNZZPdZbK3eoY+V4= Received: from chi-Redmi-Book.. (unknown []) by gzsmtp5 (Coremail) with SMTP id QCgvCgCnlXIPWU5p9JFCJA--.53S6; Fri, 26 Dec 2025 17:44:52 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Alexander Viro , Christian Brauner , Jan Kara , Matthew Wilcox , Chi Zhiling Subject: [PATCH v1 4/9] exfat: improve exfat_count_num_clusters Date: Fri, 26 Dec 2025 17:44:35 +0800 Message-ID: <20251226094440.455563-5-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251226094440.455563-1-chizhiling@163.com> References: <20251226094440.455563-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: QCgvCgCnlXIPWU5p9JFCJA--.53S6 X-Coremail-Antispam: 1Uf129KBjvdXoW7Jw4UAryfAw48WF4fGryxGrg_yoWDuFb_CF 1IvryDWr4jyF1Syr1vk3yakFy2qa1xCryqvrW2yFyDW34DJrW7XFWUXFy7CwsFkrsxJr98 JrZ3Arn3Ga10yjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUbvtC3UUUUU== X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC3BRJ5mlOWRS7wAAA32 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 --- 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 02:41:23 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 B3ADA1DFDA1; Fri, 26 Dec 2025 09:45:37 +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=1766742340; cv=none; b=gumLCSEjZnGZ4RTQPN6fCRG9QMz2uyxPwtaR538ytICV82x10s2qVgGJxsLaTm08a44MrofbkuubqOEm2wg9QsZiBYctBtiUE/ZIDmP41QDy8SniWEJsvrEizwO0HLG0bMIc/VaSfWZLUJTBvn5ygqNQMXmuCBq9jd6ZZZA4JOg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766742340; c=relaxed/simple; bh=74LmjYwnmMRYJeOzGKk4SXKJbvlpLqWqPXWpNTKPxQA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cFUljxx1yysxRoRhY3CywJdgr3vhiAsqhCqfYPn5MYOw4OexHkt5EaEzd/Cmxr5tVXMI7y4S6ECBkOjx6z2s/2kGPOtvMeNGC6UktGrj6l+tyNGrgffTRaMtYpvlHDvecIL6vhf4ckxEqp9qQR8np30j4ZPlSKgsVDpUe+B42mg= 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=k4dvT9tj; 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="k4dvT9tj" 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=hZ X2IgCzqm8k95ZX1haEGmr3IocE/hgTRQBbaXgIu2o=; b=k4dvT9tj3xdR5rEiRS G+y4TPyB4UqyheMKdTrXBMt8PUK+T4cKJuTqPtudrtrnoiI9B8lO0+1A4N79dDRd 3z5+Xw+LxFOpvtsSH3ozIPyGQNDUZ5CBjeSCQcV1PnY6HP5Xf4NHEX9vYd6Tdsvq 1FzoJy8coXQCJxW5qML1VyqIo= Received: from chi-Redmi-Book.. (unknown []) by gzsmtp5 (Coremail) with SMTP id QCgvCgCnlXIPWU5p9JFCJA--.53S7; Fri, 26 Dec 2025 17:44:52 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Alexander Viro , Christian Brauner , Jan Kara , Matthew Wilcox , Chi Zhiling Subject: [PATCH v1 5/9] exfat: improve exfat_find_last_cluster Date: Fri, 26 Dec 2025 17:44:36 +0800 Message-ID: <20251226094440.455563-6-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251226094440.455563-1-chizhiling@163.com> References: <20251226094440.455563-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: QCgvCgCnlXIPWU5p9JFCJA--.53S7 X-Coremail-Antispam: 1Uf129KBjvdXoW7Jw4UAryfCr15ZFy8Cw1xKrg_yoWkZFc_uw 1xKrykWryYyrWSyr1DC3yayFWSya1kZ3yxury7tr9Fq3s8J39rZF4DXF9rCr4jkr1kAF95 Jr95Ar93Ga48ujkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUbveHPUUUUU== X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC9xRJ5mlOWRSHHgAA3- 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 --- 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 02:41:23 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 BC0CA800; Fri, 26 Dec 2025 09:45:35 +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=1766742338; cv=none; b=DvTTM46mf5zobHaDlcdK+WFTZQnzYjd6FkcJnCSJypD1NUyPthl8o2SMjq/cdtLaG0i4LqJ/XgNH31AnxUslxNE9Mfg5bw3HMr8X5C7hPBss9rGaoFHoMdH+x+fq6adJ/ZD1joDha/qQ1NAzOUrqSLPJFwT9jQOLaMBWV9vIL0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766742338; c=relaxed/simple; bh=7XQnh/VA/KqJu+7+aA4dxxn6OFQ3awzG6+iIQKJDZXQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aAqFqE9VT+N3VGjBYpFFp/0ZoY8ZQLjPsyLhsqFm3vt7U4+jkllNRFPmMEMnwKyvFMH4ymkAIDQ7pAa0Squ9ikHejNfFH2M+GRRqFx2xRDLrdmo6JuPm/+jSPKBpiKIk3V5yno5mZ5ycJGL+e4epqFYSeAGXvLG9bl2/hRUiOn4= 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=nSDOlbKe; 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="nSDOlbKe" 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=Hw hjI8LrnsS3V0SFfDxImoH+MP8b9nINkDRWIGH0XPQ=; b=nSDOlbKeebsa/WSXv3 XOpkJZiPaDaYaXhY9wyhP7lOK2wAxqtsKshSdDu2EM/ikuVrkD/5XTG+JFpwl8Wa /xZsJmWEza68+9vwAISZm5CxYDr95EqUPrNDR3aWqaeD/nWVr8sCjanrMFbeqoXd LwufFWphAXWElOY3Mxr9d5hSI= Received: from chi-Redmi-Book.. (unknown []) by gzsmtp5 (Coremail) with SMTP id QCgvCgCnlXIPWU5p9JFCJA--.53S8; Fri, 26 Dec 2025 17:44:52 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Alexander Viro , Christian Brauner , Jan Kara , Matthew Wilcox , Chi Zhiling Subject: [PATCH v1 6/9] exfat: remove unused parameters from exfat_get_cluster Date: Fri, 26 Dec 2025 17:44:37 +0800 Message-ID: <20251226094440.455563-7-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251226094440.455563-1-chizhiling@163.com> References: <20251226094440.455563-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: QCgvCgCnlXIPWU5p9JFCJA--.53S8 X-Coremail-Antispam: 1Uf129KBjvJXoWxCr18try7XF4rKF4kXF1fWFg_yoWruw47pr ZrKa4rt3y3Xayv9w48tFs5Za4fK3Z7GFWUJw43AryYkr90yr1F9FnFkr9Iya48Gw4kuayj 9F15Kw1j9rnxGw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jnCzZUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC+BRJ5mlOWRSBVAAA38 Content-Type: text/plain; charset="utf-8" From: Chi Zhiling Remove the unused fclus and allow_eof parameters from exfat_get_cluster. The fclus parameter is changed to a local variable as it is not needed to be returned. The allow_eof parameter was always 1, so remove it and the associated error handling. This simplifies the function and its callers, no logical changes. Signed-off-by: Chi Zhiling --- fs/exfat/cache.c | 31 +++++++++++-------------------- fs/exfat/exfat_fs.h | 3 +-- fs/exfat/inode.c | 12 +++++------- 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/fs/exfat/cache.c b/fs/exfat/cache.c index 4161b983b6af..43a6aa87c55d 100644 --- a/fs/exfat/cache.c +++ b/fs/exfat/cache.c @@ -234,8 +234,7 @@ static inline void cache_init(struct exfat_cache_id *ci= d, } =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_sb_info *sbi =3D EXFAT_SB(sb); @@ -243,7 +242,7 @@ int exfat_get_cluster(struct inode *inode, unsigned int= cluster, struct exfat_inode_info *ei =3D EXFAT_I(inode); struct buffer_head *bh =3D NULL; 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, @@ -252,7 +251,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 @@ -264,7 +263,7 @@ int exfat_get_cluster(struct inode *inode, unsigned int= cluster, =20 cache_init(&cid, EXFAT_EOF_CLUSTER, EXFAT_EOF_CLUSTER); =20 - if (exfat_cache_lookup(inode, cluster, &cid, fclus, dclus) =3D=3D + if (exfat_cache_lookup(inode, cluster, &cid, &fclus, dclus) =3D=3D EXFAT_EOF_CLUSTER) { /* * dummy, always not contiguous @@ -276,15 +275,15 @@ int exfat_get_cluster(struct inode *inode, unsigned i= nt cluster, cid.nr_contig !=3D 0); } =20 - if (*fclus =3D=3D cluster) + if (fclus =3D=3D cluster) return 0; =20 - while (*fclus < cluster) { + while (fclus < cluster) { /* prevent the infinite loop of cluster chain */ - if (*fclus > limit) { + if (fclus > limit) { exfat_fs_error(sb, "detected the cluster chain loop (i_pos %u)", - (*fclus)); + fclus); goto err; } =20 @@ -293,21 +292,13 @@ int exfat_get_cluster(struct inode *inode, unsigned i= nt cluster, =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)); - goto err; - } + 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 brelse(bh); 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..1062ce470cb1 100644 --- a/fs/exfat/inode.c +++ b/fs/exfat/inode.c @@ -157,28 +157,26 @@ 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 { + unsigned int fclus =3D 0; /* 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); + fclus =3D ei->hint_bmap.off; *clu =3D ei->hint_bmap.clu; } =20 - while (clu_offset > 0 && *clu !=3D EXFAT_EOF_CLUSTER) { + while (fclus < clu_offset && *clu !=3D EXFAT_EOF_CLUSTER) { last_clu =3D *clu; if (exfat_get_next_cluster(sb, clu)) return -EIO; - clu_offset--; + fclus++; } } =20 --=20 2.43.0 From nobody Sun Feb 8 02:41:23 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 DC4FB7640E; Fri, 26 Dec 2025 09:45:36 +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=1766742339; cv=none; b=almz8ETNqMqi8XA191G9UKi4z3xv2IluFJtDSu4Hdsz36nC+7kFRVRAxWOLQU+TH1WT+BzVf3VWjCUcEk1ehQd6xJTT6+1C3ma5rSGYpxVzsF0gWAYujHauWaLn1HJeMQhQoliVR6AHiYP7dQpRYNRJRIW1NEJPXWuIjiC8PYiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766742339; c=relaxed/simple; bh=Tokd7pF/jDlONJOJuFx6h8nJ4mrtbxR7j0Ky9FMdiD0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kEFQHqWfcQ15cIOSST36UdpD2IzOUlY21FhsndNpgs+6Xkt3s3A4mwLSTsRkM5gLmkey7cANqjo3pkQ1FTjVbSox9UMaQTSxSt1mO3f5ecvtG1FkUQp3eQ5j6CEyvX3eTA4mfd6eghtRZeGf49gPerZvOcRuKHPZePvRXLgc0ao= 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=S5CxqTyi; 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="S5CxqTyi" 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=el zMfq9IHeX1Psy38gcRlurD9UoTomtRfBJj6fK48OM=; b=S5CxqTyiax1dZDOzzd d+7wi885tl3Jm9cwTfvd+l67N6ARVSGGyxp9WcYDR3nOMNe7oCH4U+888iL2VxDA 0sh+PrsaGT74TZxtfr8x+8U0+0zsWH11MFqX8xEBc/uJYFoufv+eVcaC4YQhco1n hBaGYTBCw5+JuuziJb+M7Lu4c= Received: from chi-Redmi-Book.. (unknown []) by gzsmtp5 (Coremail) with SMTP id QCgvCgCnlXIPWU5p9JFCJA--.53S9; Fri, 26 Dec 2025 17:44:53 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Alexander Viro , Christian Brauner , Jan Kara , Matthew Wilcox , Chi Zhiling Subject: [PATCH v1 7/9] exfat: tweak exfat_cache_lookup to support zero offset cluster Date: Fri, 26 Dec 2025 17:44:38 +0800 Message-ID: <20251226094440.455563-8-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251226094440.455563-1-chizhiling@163.com> References: <20251226094440.455563-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: QCgvCgCnlXIPWU5p9JFCJA--.53S9 X-Coremail-Antispam: 1Uf129KBjvJXoWxZFWDZrW7GF1fJw43Cw13XFb_yoW5GFykpF W7Kay5trs3ZayDCw48tws7Z34fua4kKF47Jw17Gw15Cryqyr40gF1DArnxAF4UGw48Cw42 qF1rKw17ursrGaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jnJ5OUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC+BZJ5mlOWRaBdQAA3d Content-Type: text/plain; charset="utf-8" From: Chi Zhiling The current cache mechanism does not support reading clusters from zero file offset, so this patch modifies the exfat_cache_lookup function to enable the cache to support multiple contiguous clusters which starting from a zero offset, preparing for subsequent reads of contiguous clusters from the zero offset. Additionally, this patch removes unreachable WARN debugging code. Signed-off-by: Chi Zhiling --- fs/exfat/cache.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/fs/exfat/cache.c b/fs/exfat/cache.c index 43a6aa87c55d..57a66c067394 100644 --- a/fs/exfat/cache.c +++ b/fs/exfat/cache.c @@ -80,19 +80,19 @@ 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, +static bool exfat_cache_lookup(struct inode *inode, unsigned int fclus, struct exfat_cache_id *cid, 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 offset; =20 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; @@ -114,7 +114,7 @@ static unsigned int exfat_cache_lookup(struct inode *in= ode, } spin_unlock(&ei->cache_lru_lock); =20 - return offset; + return hit !=3D &nohit; } =20 static struct exfat_cache *exfat_cache_merge(struct inode *inode, @@ -261,19 +261,8 @@ int exfat_get_cluster(struct inode *inode, unsigned in= t cluster, if (cluster =3D=3D 0 || *dclus =3D=3D EXFAT_EOF_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); - } + cache_init(&cid, fclus, *dclus); + 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 02:41:23 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.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 DD4F82877F7; Fri, 26 Dec 2025 09:45:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766742341; cv=none; b=dpCoBHFfwodF7aOvfPSKD/zpTKHoQAZQwDTVH1hmzkMAjr0Lccke9okv6B/6BB5OV9DvnbuCrWXSgkIX/+hg96kyUtYcL3vOVNU9M/ChppSjysThcORr4cSL7/S2U5HIfwNsig+lK8hXCFoWO3Y5RLPSudpivpTualEWwnHN9r4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766742341; c=relaxed/simple; bh=Y+4+V+3jL+/gW4a5GlQGShJ3qbIiu4tlcmV+HCtNyTk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g0zrMFacRi/y1iP0t945Shx6ESraT+Rum9rfqEcBaxFo64DBteJ619JSoaIX0Yq0Kk5qG3yAO4h3eaAqBGOAXwEcGr6HFoOHFWioa+j7heNqKnffyDPhi7zVsjjZlfTXiL8nJSn98qglXsTA8BaA8ueG116woZoydhNHgF89Mak= 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=AJe/IXnY; arc=none smtp.client-ip=220.197.31.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="AJe/IXnY" 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=sr fBXNxGCh5Rq4nSeVRnEtAkghTflmqeu00QEdkWvkI=; b=AJe/IXnYVX8DqQzc94 wiMInhkOQ4tSzQYCU7M5sOUeakBBchqlgXhzYokxOW8acFEdfqGX7ozAM5KjiJzO uDWryjJ34Xix2LIhGnmYlxx+JBXeEtEM8QSr8DM7okMo1iyT+P8fFiqsMJMHGDd8 JcJf+kk7AV1LbXwVC78bOyifM= Received: from chi-Redmi-Book.. (unknown []) by gzsmtp5 (Coremail) with SMTP id QCgvCgCnlXIPWU5p9JFCJA--.53S10; Fri, 26 Dec 2025 17:44:54 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Alexander Viro , Christian Brauner , Jan Kara , Matthew Wilcox , Chi Zhiling Subject: [PATCH v1 8/9] exfat: support multi-cluster for exfat_map_cluster Date: Fri, 26 Dec 2025 17:44:39 +0800 Message-ID: <20251226094440.455563-9-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251226094440.455563-1-chizhiling@163.com> References: <20251226094440.455563-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: QCgvCgCnlXIPWU5p9JFCJA--.53S10 X-Coremail-Antispam: 1Uf129KBjvJXoWxAF1rZr47urWftw43ury8Krg_yoWrGFW3pr s7Ka4rtr13Ja4DGa1xJr4kZryS93Z7GFy5JayxWryUGr90qF1FgFWqyr9xC3W8Ga1ruF4q q3WrGw1UursxJaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07Um2NNUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC9xZJ5mlOWRaHQwAA3i 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 | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c index 1062ce470cb1..8c49ab15eafe 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 num_clusters - clu_offset; + } else { + *clu =3D EXFAT_EOF_CLUSTER; + *count =3D 0; } } else if (ei->type =3D=3D TYPE_FILE) { 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; } else { unsigned int fclus =3D 0; /* hint information */ @@ -178,6 +181,7 @@ static int exfat_map_cluster(struct inode *inode, unsig= ned int clu_offset, return -EIO; fclus++; } + *count =3D (*clu =3D=3D EXFAT_EOF_CLUSTER) ? 0 : 1; } =20 if (*clu =3D=3D EXFAT_EOF_CLUSTER) { @@ -249,7 +253,7 @@ static int exfat_map_cluster(struct inode *inode, unsig= ned int clu_offset, num_to_be_allocated--; } } - + *count =3D 1; } =20 /* hint information */ @@ -268,7 +272,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; @@ -281,8 +285,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, @@ -293,12 +298,14 @@ static int exfat_get_block(struct inode *inode, secto= r_t iblock, =20 if (cluster =3D=3D EXFAT_EOF_CLUSTER) goto done; + if (WARN_ON_ONCE(!count)) + count =3D 1; =20 /* sector offset in cluster */ 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 count * sbi->sect_per_clus - 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 02:41:23 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.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 05ACE31576D; Fri, 26 Dec 2025 09:45:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766742342; cv=none; b=mL+l0lG1v8+CXNOlvJHxX0l7kSZUs6K8zc9+OWqj24J+o3fHXi6s+9XsvV8p2Y33kuYsMrro3c0A7qnvFcl+TltNePSFlaWgCUJY2LHfz1WgCy6Shc0xn1Vq2eQORQVj6SF4l8PJrsnNWJYHJ0TkA1IUTHp2NY4FyETgJUxJFEU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766742342; c=relaxed/simple; bh=m8VAlUB9Ouq9dJggFfY52aVdUdWKdTiZu9urVGJLxbo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iU+5+AXWAvEgMZukkmFtVwcyhb7wQ04ek6lIMrnd4Zj+hvOz56YHDM5jWxDbZuIbBsJhjjsGr3/HTxDz+VFdbKzOF76oh/YrImgf557GVUwmvlBIfSQpj0lGCqsCatGctfFJre42QcnjeNQv5GS4LEpM7q7RbMr9jSUAPdv4ymM= 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=RZzh4Jhu; arc=none smtp.client-ip=220.197.31.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="RZzh4Jhu" 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=OL z45/biIqsJRdyUEJ63VpvHd0PioSptcgwR0uanzps=; b=RZzh4JhufGIcr//OuB i6mBrlVev8V2Ep3ctDH3Eds6JCqxsH0pHV9HaCyz2bJuhJZhWrTiV7yalJp5eQx5 iLWFlWiSXhWWWCtenP6HqHagDR/bKmYQU42EDhg6ktAMx5IG9pTD1l/W5z8P1ZkW WJ58+UmyapNTQkR3AeW4zrynw= Received: from chi-Redmi-Book.. (unknown []) by gzsmtp5 (Coremail) with SMTP id QCgvCgCnlXIPWU5p9JFCJA--.53S11; Fri, 26 Dec 2025 17:44:54 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Alexander Viro , Christian Brauner , Jan Kara , Matthew Wilcox , Chi Zhiling Subject: [PATCH v1 9/9] exfat: support multi-cluster for exfat_get_cluster Date: Fri, 26 Dec 2025 17:44:40 +0800 Message-ID: <20251226094440.455563-10-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251226094440.455563-1-chizhiling@163.com> References: <20251226094440.455563-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: QCgvCgCnlXIPWU5p9JFCJA--.53S11 X-Coremail-Antispam: 1Uf129KBjvJXoWxWw1fJw4kAF4UuFWkCF1rJFb_yoW7JFyrpr WxKayrtrZxXasruw4xtrs5ZryS93Z7GFW5J347Jry5Crn0yr4F9r1Dt3s0yF18Gw4kua1j vr1Fgw1UurnxGaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07Um2NNUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC3BdJ5mlOWRe78QAA3H 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 Signed-off-by: Chi Zhiling --- fs/exfat/cache.c | 51 +++++++++++++++++++++++++++++++++++++++++---- fs/exfat/exfat_fs.h | 2 +- fs/exfat/inode.c | 5 +++-- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/fs/exfat/cache.c b/fs/exfat/cache.c index 57a66c067394..80efe2e0393d 100644 --- a/fs/exfat/cache.c +++ b/fs/exfat/cache.c @@ -234,7 +234,8 @@ static inline void cache_init(struct exfat_cache_id *ci= d, } =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_sb_info *sbi =3D EXFAT_SB(sb); @@ -243,6 +244,7 @@ int exfat_get_cluster(struct inode *inode, unsigned int= cluster, struct buffer_head *bh =3D NULL; struct exfat_cache_id cid; unsigned int content, fclus; + unsigned int end =3D (*count <=3D 1) ? cluster : cluster + *count - 1; =20 if (ei->start_clu =3D=3D EXFAT_FREE_CLUSTER) { exfat_fs_error(sb, @@ -256,17 +258,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, cluster, &cid, &fclus, dclus); =20 - if (fclus =3D=3D cluster) + /* + * Return on cache hit to keep the code simple. + */ + if (fclus =3D=3D cluster) { + *count =3D cid.fcluster + cid.nr_contig - fclus + 1; return 0; + } =20 + /* + * Find the first cluster we need. + */ while (fclus < cluster) { /* prevent the infinite loop of cluster chain */ if (fclus > limit) { @@ -290,6 +308,31 @@ int exfat_get_cluster(struct inode *inode, unsigned in= t cluster, cache_init(&cid, fclus, *dclus); } =20 + /* + * Collect the remaining clusters of this contiguous extent. + */ + if (*dclus !=3D EXFAT_EOF_CLUSTER) { + unsigned int clu =3D *dclus; + + /* + * Now the cid cache contains the first cluster requested, + * Advance the fclus to the last cluster of contiguous + * extent, then update the count and cid cache accordingly. + */ + while (fclus < end) { + if (exfat_ent_get(sb, clu, &content, &bh)) + goto err; + if (++clu !=3D content) { + /* TODO: read ahead if content valid */ + break; + } + fclus++; + } + cid.nr_contig =3D fclus - cid.fcluster; + *count =3D fclus - cluster + 1; + } 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 8c49ab15eafe..317bc363f7d9 100644 --- a/fs/exfat/inode.c +++ b/fs/exfat/inode.c @@ -134,6 +134,7 @@ static int exfat_map_cluster(struct inode *inode, unsig= ned int clu_offset, struct exfat_inode_info *ei =3D EXFAT_I(inode); unsigned int local_clu_offset =3D clu_offset; unsigned int num_to_be_allocated =3D 0, num_clusters; + unsigned int hint_count =3D max(*count, 1); =20 num_clusters =3D EXFAT_B_TO_CLU(exfat_ondisk_size(inode), sbi); =20 @@ -159,11 +160,11 @@ static int exfat_map_cluster(struct inode *inode, uns= igned int clu_offset, *count =3D 0; } } else if (ei->type =3D=3D TYPE_FILE) { + *count =3D hint_count; 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; } else { unsigned int fclus =3D 0; /* hint information */ --=20 2.43.0