From nobody Thu Apr 9 14:58:04 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 24B4737CD41; Tue, 3 Mar 2026 03:15:48 +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=1772507752; cv=none; b=shz2UuD+gfajtA47Zt3giPZj9eKJFdds4W/YcuozQNlViYmUHICIhhYYoOHxHQaWmhn1NMSvXKFmLYmevKKwJLASu91XTKII2uNIMxiWG9T0494ad/U5KX6rNo8tB6sZG/WJvEnnYFBuPvg18w48/yOKxndvQVJ8N6jXvJsTV1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772507752; c=relaxed/simple; bh=Q8mE89/Jp69yE2eovKWfvlU+V33ogRISgTFjxR7k1PQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xb0D4CxzYsq+zWqBhsbixVUydsJlHn3PjLNw01Xky0MLj6Y0FeKxegXCJ3WNCpCPANHzh14FGrBSVvkPe5FzXIkc4yAB3AwegThhPUhWsQe7zNiS4SRpGB3sR1OCnJIfdARvLcYuZxmoncneDBzgNxsO4/M6n70kPwai23zMQ9c= 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=B483pwfl; 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="B483pwfl" 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=gS CSHyxPm901Iut4Y6cl6bKalR2BhcwxVsIC28ds/rg=; b=B483pwfl3O0zxx8Pfs 2JWrkEu2pzrArvPISpH5DMFUtqhoGCDDyqOJeIi0HSlhhxC0osOfiBDmage2mgwy sm77Hri6/vEUyhZeJcm38I4fE5bRQjPHPj+10mti1uCp+LKpQQU/bsse6/C8WTp+ hdgnnPgFB00kT8GLWYGMXmImw= Received: from czl-ubuntu-pc.. (unknown []) by gzsmtp4 (Coremail) with SMTP id PygvCgAXh6xQUqZpOLCWQw--.188S3; Tue, 03 Mar 2026 11:15:33 +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 v2 1/6] exfat: add block readahead in exfat_chain_cont_cluster Date: Tue, 3 Mar 2026 11:14:04 +0800 Message-ID: <20260303031409.129136-2-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260303031409.129136-1-chizhiling@163.com> References: <20260303031409.129136-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: PygvCgAXh6xQUqZpOLCWQw--.188S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxZr17KrW7GF4rKr43Jr43ZFb_yoWrGFWfpa n8AayftrWUGa47Ww4fKF1kG3WfC3s7GFyrGrW3uryrAryavrs3urZrKryFqFykt3y5WF1j qF1YvFWUCrnxW37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jzhFxUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC3BWtS2mmUlWaqwAA3W Content-Type: text/plain; charset="utf-8" From: Chi Zhiling When a file cannot allocate contiguous clusters, exfat converts the file from NO_FAT_CHAIN to FAT_CHAIN format. For large files, this conversion process can take a significant amount of time. Add simple readahead to read all the FAT blocks in advance, as these blocks are consecutive, significantly improving the conversion performance. Test in an empty exfat filesystem: dd if=3D/dev/zero of=3D/mnt/file bs=3D1M count=3D30k dd if=3D/dev/zero of=3D/mnt/file2 bs=3D1M count=3D1 time cat /mnt/file2 >> /mnt/file | cluster size | before patch | after patch | | ------------ | ------------ | ----------- | | 512 | 47.667s | 4.316s | | 4k | 6.436s | 0.541s | | 32k | 0.758s | 0.071s | | 256k | 0.117s | 0.011s | Signed-off-by: Chi Zhiling --- fs/exfat/exfat_fs.h | 11 +++++++++-- fs/exfat/fatent.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index 2dbed5f8ec26..090f25d1a418 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -10,6 +10,7 @@ #include #include #include +#include #include =20 #define EXFAT_ROOT_INO 1 @@ -79,6 +80,10 @@ enum { #define EXFAT_HINT_NONE -1 #define EXFAT_MIN_SUBDIR 2 =20 +#define EXFAT_BLK_RA_SIZE(sb) \ + (min_t(blkcnt_t, (sb)->s_bdi->ra_pages, (sb)->s_bdi->io_pages) \ + << (PAGE_SHIFT - (sb)->s_blocksize_bits)) + /* * helpers for cluster size to byte conversion. */ @@ -117,9 +122,9 @@ enum { #define FAT_ENT_SIZE (4) #define FAT_ENT_SIZE_BITS (2) #define FAT_ENT_OFFSET_SECTOR(sb, loc) (EXFAT_SB(sb)->FAT1_start_sector + \ - (((u64)loc << FAT_ENT_SIZE_BITS) >> sb->s_blocksize_bits)) + (((u64)(loc) << FAT_ENT_SIZE_BITS) >> sb->s_blocksize_bits)) #define FAT_ENT_OFFSET_BYTE_IN_SECTOR(sb, loc) \ - ((loc << FAT_ENT_SIZE_BITS) & (sb->s_blocksize - 1)) + (((loc) << FAT_ENT_SIZE_BITS) & (sb->s_blocksize - 1)) =20 /* * helpers for bitmap. @@ -448,6 +453,8 @@ int exfat_find_last_cluster(struct super_block *sb, str= uct exfat_chain *p_chain, unsigned int *ret_clu); int exfat_count_num_clusters(struct super_block *sb, struct exfat_chain *p_chain, unsigned int *ret_count); +int exfat_blk_readahead(struct super_block *sb, sector_t sec, + sector_t *ra, blkcnt_t *ra_cnt, sector_t end); =20 /* balloc.c */ int exfat_load_bitmap(struct super_block *sb); diff --git a/fs/exfat/fatent.c b/fs/exfat/fatent.c index f87576ca7032..9a4143f3fc0c 100644 --- a/fs/exfat/fatent.c +++ b/fs/exfat/fatent.c @@ -142,13 +142,50 @@ int exfat_ent_get(struct super_block *sb, unsigned in= t loc, return -EIO; } =20 +int exfat_blk_readahead(struct super_block *sb, sector_t sec, + sector_t *ra, blkcnt_t *ra_cnt, sector_t end) +{ + struct blk_plug plug; + + if (sec < *ra) + return 0; + + *ra +=3D *ra_cnt; + + /* No blocks left (or only the last block), skip readahead. */ + if (*ra >=3D end) + return 0; + + *ra_cnt =3D min(end - *ra + 1, EXFAT_BLK_RA_SIZE(sb)); + if (*ra_cnt =3D=3D 0) { + /* Move 'ra' to the end to disable readahead. */ + *ra =3D end; + return 0; + } + + blk_start_plug(&plug); + for (unsigned int i =3D 0; i < *ra_cnt; i++) + sb_breadahead(sb, *ra + i); + blk_finish_plug(&plug); + return 0; +} + int exfat_chain_cont_cluster(struct super_block *sb, unsigned int chain, unsigned int len) { + sector_t sec, end, ra; + blkcnt_t ra_cnt =3D 0; + if (!len) return 0; =20 + ra =3D FAT_ENT_OFFSET_SECTOR(sb, chain); + end =3D FAT_ENT_OFFSET_SECTOR(sb, chain + len - 1); + while (len > 1) { + sec =3D FAT_ENT_OFFSET_SECTOR(sb, chain); + exfat_blk_readahead(sb, sec, &ra, &ra_cnt, end); + if (exfat_ent_set(sb, chain, chain + 1)) return -EIO; chain++; --=20 2.43.0 From nobody Thu Apr 9 14:58:04 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 60150382360; Tue, 3 Mar 2026 03:15:55 +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=1772507766; cv=none; b=J3v3R+8VnlwnN3hIdHnGcbboqWoyY9njZr0eAQj1iwUThrnBrVhNaTLRLuzEziiIXHAQwkaKJmMh5Ca40vE3NlzQtgP4G8DEOqo31i0+0B8A6ibkbAVrrYUjdWg2kVVudu5Zqp3Bpxx38bi7qJdBUkxqiKW33kZ4oJoB6B+iRMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772507766; c=relaxed/simple; bh=6cVp/PPkcqEjPu27yrav/1pqN6AkX3qOYMtENqKmNx4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GpXbngMbGsiuXV0ZT4mB0vOgAcHxxe340CC3568nvqqJIdSWcMcioM1vvM4EDUo48ycEc5s3/y0wdPnZX7OWH9Sw+3kT+n7v1R7j4W6ObWzjbxra5t4yDzVTtn8f2iH1DP9q7WXW1sKVJ074npkwFIJl4E0oHrX0TxWTAB+Dh7Q= 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=qTkR0DGx; 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="qTkR0DGx" 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=0A PR0ZvepNK5RtXn2wLzshvwXPKV4FDoQ0qE6qOSS2M=; b=qTkR0DGxAlORtPGK0v FFZcCmlYqnCzPnX1agr8wlbpSzKL/Owzvq1E6e7T9EDETExgL8uxG4b1oMsZqo6A DXKOEySMHw1qwpa3yasalL5azPdnHt96fa3ApVa+9+Bp1Mmue/Xjla4zGado/ZI4 xmYwxMPM4wv4fuzQR5nxlhYts= Received: from czl-ubuntu-pc.. (unknown []) by gzsmtp4 (Coremail) with SMTP id PygvCgAXh6xQUqZpOLCWQw--.188S4; Tue, 03 Mar 2026 11:15:33 +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 v2 2/6] exfat: use readahead helper in exfat_allocate_bitmap Date: Tue, 3 Mar 2026 11:14:05 +0800 Message-ID: <20260303031409.129136-3-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260303031409.129136-1-chizhiling@163.com> References: <20260303031409.129136-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: PygvCgAXh6xQUqZpOLCWQw--.188S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7trWrAr18XFy3tw17uF13XFb_yoW8CryfpF 47Ga17KrW5Xr1UWws8Ga40ga1fu34rGFy3GrWIv3s8urn3KrnI9FyvgFyUZFy2kas5JF40 vwn0kr15Zws7ua7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jDtxfUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC9xWtS2mmUlWL6wAA3s Content-Type: text/plain; charset="utf-8" From: Chi Zhiling Use the newly added exfat_blk_readahead() helper in exfat_allocate_bitmap() to simplify the code. This eliminates the duplicate inline readahead logic and uses the unified readahead interface. Signed-off-by: Chi Zhiling --- fs/exfat/balloc.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/fs/exfat/balloc.c b/fs/exfat/balloc.c index 3a32f49f9dbd..625f2f14d4fe 100644 --- a/fs/exfat/balloc.c +++ b/fs/exfat/balloc.c @@ -74,11 +74,10 @@ static int exfat_allocate_bitmap(struct super_block *sb, struct exfat_dentry *ep) { struct exfat_sb_info *sbi =3D EXFAT_SB(sb); - struct blk_plug plug; long long map_size; unsigned int i, j, need_map_size; - sector_t sector; - unsigned int max_ra_count; + sector_t sector, end, ra; + blkcnt_t ra_cnt =3D 0; =20 sbi->map_clu =3D le32_to_cpu(ep->dentry.bitmap.start_clu); map_size =3D le64_to_cpu(ep->dentry.bitmap.size); @@ -100,17 +99,12 @@ static int exfat_allocate_bitmap(struct super_block *s= b, if (!sbi->vol_amap) return -ENOMEM; =20 - sector =3D exfat_cluster_to_sector(sbi, sbi->map_clu); - max_ra_count =3D min(sb->s_bdi->ra_pages, sb->s_bdi->io_pages) << - (PAGE_SHIFT - sb->s_blocksize_bits); + sector =3D ra =3D exfat_cluster_to_sector(sbi, sbi->map_clu); + end =3D sector + sbi->map_sectors - 1; + for (i =3D 0; i < sbi->map_sectors; i++) { /* Trigger the next readahead in advance. */ - if (max_ra_count && 0 =3D=3D (i % max_ra_count)) { - blk_start_plug(&plug); - for (j =3D i; j < min(max_ra_count, sbi->map_sectors - i) + i; j++) - sb_breadahead(sb, sector + j); - blk_finish_plug(&plug); - } + exfat_blk_readahead(sb, sector + i, &ra, &ra_cnt, end); =20 sbi->vol_amap[i] =3D sb_bread(sb, sector + i); if (!sbi->vol_amap[i]) --=20 2.43.0 From nobody Thu Apr 9 14:58:04 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 9D00537DE96; Tue, 3 Mar 2026 03:15:54 +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=1772507756; cv=none; b=O5UtqDRpzTn5AZlckf7r0kNd0+OLUgh0GQvVSAPK1pWl15p06qTKgHG0scKA4ZD2OAJqwLODE5myHmFfcYwst8B0vx0bMps44vyF1CtkXvY7+K9UAHMV1YUeWWFDKv4CN79sinIFjmeQg+UxC45iIgRwwSYiehFI+vR8tOI5Olw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772507756; c=relaxed/simple; bh=DY/ty8QPMP9TkL8L3X5ZNyfeA542cemeI2M3dZXpF6Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R71GuyGSLMrvwHLpuCVgGP+e9DT4eEwJrjG0Z4wy1w2VH4nZ4IT6OklE6dRIQDOImCH12rcl41xVOSTaj1vJk4Hu601DmJcNnXOhAP4eSBejvFC99k3gRV97kRd+5n4apHRS+14rtoJ179HIAZSCxSr0r0xm8PBRxz42oErxdaA= 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=UAfOaVVM; 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="UAfOaVVM" 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=VA mBZgXf9g7iYFbDrSLHZzoP+KeydS6WcJLEuSOLAlk=; b=UAfOaVVM7lnyIDvCxN zR64/zVIcxlT5ioK9bS5f0iYedPMSLuE/jBOzW0BLkgY5q5QXGaGaoLgLY3ht/Eh rzS6QZJ0AO2gq7CM71dClhvoydq7LzCfFh+IwoN2w4bAEm2x+wefbaN30R18WFSV rDv4BpeatoTAUpirq+psGJwk8= Received: from czl-ubuntu-pc.. (unknown []) by gzsmtp4 (Coremail) with SMTP id PygvCgAXh6xQUqZpOLCWQw--.188S5; Tue, 03 Mar 2026 11:15:33 +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 v2 3/6] exfat: use readahead helper in exfat_get_dentry Date: Tue, 3 Mar 2026 11:14:06 +0800 Message-ID: <20260303031409.129136-4-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260303031409.129136-1-chizhiling@163.com> References: <20260303031409.129136-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: PygvCgAXh6xQUqZpOLCWQw--.188S5 X-Coremail-Antispam: 1Uf129KBjvJXoWxCr1fXr1rWw4xGrWDCF4fAFb_yoW5Ww47pF 4fJ39rtr48J34DXwsxJ3yruw1Sk3y8AF45JrWxZ34fJFsY9rnxury0qry0qFW7K3y09F1j va9Ygr15uanrW3JanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jl9a9UUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC9xatS2mmUlaL-AAA37 Content-Type: text/plain; charset="utf-8" From: Chi Zhiling Replace the custom exfat_dir_readahead() function with the unified exfat_blk_readahead() helper in exfat_get_dentry(). This removes the duplicate readahead implementation and uses the common interface, also reducing code complexity. Signed-off-by: Chi Zhiling --- fs/exfat/dir.c | 52 ++++++++++++++------------------------------------ 1 file changed, 14 insertions(+), 38 deletions(-) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index 3a4853693d8b..5e59c2a7853e 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -623,44 +623,11 @@ static int exfat_find_location(struct super_block *sb= , struct exfat_chain *p_dir return 0; } =20 -#define EXFAT_MAX_RA_SIZE (128*1024) -static int exfat_dir_readahead(struct super_block *sb, sector_t sec) -{ - struct exfat_sb_info *sbi =3D EXFAT_SB(sb); - struct buffer_head *bh; - unsigned int max_ra_count =3D EXFAT_MAX_RA_SIZE >> sb->s_blocksize_bits; - unsigned int page_ra_count =3D PAGE_SIZE >> sb->s_blocksize_bits; - unsigned int adj_ra_count =3D max(sbi->sect_per_clus, page_ra_count); - unsigned int ra_count =3D min(adj_ra_count, max_ra_count); - - /* Read-ahead is not required */ - if (sbi->sect_per_clus =3D=3D 1) - return 0; - - if (sec < sbi->data_start_sector) { - exfat_err(sb, "requested sector is invalid(sect:%llu, root:%llu)", - (unsigned long long)sec, sbi->data_start_sector); - return -EIO; - } - - /* Not sector aligned with ra_count, resize ra_count to page size */ - if ((sec - sbi->data_start_sector) & (ra_count - 1)) - ra_count =3D page_ra_count; - - bh =3D sb_find_get_block(sb, sec); - if (!bh || !buffer_uptodate(bh)) { - unsigned int i; - - for (i =3D 0; i < ra_count; i++) - sb_breadahead(sb, (sector_t)(sec + i)); - } - brelse(bh); - return 0; -} - struct exfat_dentry *exfat_get_dentry(struct super_block *sb, struct exfat_chain *p_dir, int entry, struct buffer_head **bh) { + struct exfat_sb_info *sbi =3D EXFAT_SB(sb); + unsigned int sect_per_clus =3D sbi->sect_per_clus; unsigned int dentries_per_page =3D EXFAT_B_TO_DEN(PAGE_SIZE); int off; sector_t sec; @@ -673,9 +640,18 @@ struct exfat_dentry *exfat_get_dentry(struct super_blo= ck *sb, if (exfat_find_location(sb, p_dir, entry, &sec, &off)) return NULL; =20 - if (p_dir->dir !=3D EXFAT_FREE_CLUSTER && - !(entry & (dentries_per_page - 1))) - exfat_dir_readahead(sb, sec); + if (sect_per_clus > 1 && + (entry & (dentries_per_page - 1)) =3D=3D 0) { + sector_t ra =3D sec; + blkcnt_t cnt =3D 0; + unsigned int ra_count =3D sect_per_clus; + + /* Not sector aligned with ra_count, resize ra_count to page size */ + if ((sec - sbi->data_start_sector) & (ra_count - 1)) + ra_count =3D PAGE_SIZE >> sb->s_blocksize_bits; + + exfat_blk_readahead(sb, sec, &ra, &cnt, sec + ra_count - 1); + } =20 *bh =3D sb_bread(sb, sec); if (!*bh) --=20 2.43.0 From nobody Thu Apr 9 14:58:04 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 36AB837CD59; Tue, 3 Mar 2026 03:15:48 +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=1772507752; cv=none; b=Zvzjhs299IByg13yqV7ZB+0/IIFdWyfQTEkqsIwq4jQZ+7gmAkEmoDq2c/k6rShpgcd9ov0sEegkqe5YZPBjJQZ7Wt/tdi8pgwbIlhSXuCHg+CsHk7aYR99ffRHj8j1WJS0R/WLytbXuiCqnt1ZPimAJPqyZGsGLwcNjqgzp3pA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772507752; c=relaxed/simple; bh=S3XS/C3umhS4PxygIwHBUUBspT4s7K00B9q9vPIy18w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OqjTchB7LzNObnVNz8YYYparkJmsADnNgklH3gppZPkOqTKw61ZrtwbInunby77VVdpsNpg6K3XV1tSEUFYT3MPJtaPfRci10hvUb0KYZae6mAd653TszNg4Cg4uzeFmoXLt2CNqhXipMkh7Km8508+ZBELsLJTAv+NVX4ibuko= 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=UMhZfH+T; 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="UMhZfH+T" 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=4u bQFK0LEaJeIG3aAZbVDCQ8bN1lGZcO+MXK4SF9IZQ=; b=UMhZfH+T5Cqz4u5N36 h0ScVtnI0uvtJEf8LQl+VqVMSfNaUH41s0feNTvDbjF7chvYntnSicfJcDB1NHLZ hawQ19NiwcieHod5DOuuIdTwKZDv1g6WO4KeYJQAtBT37Kz4r9O6++l0g1riUqy5 63B6OOOSQD8gTZIBf7NH/g2N4= Received: from czl-ubuntu-pc.. (unknown []) by gzsmtp4 (Coremail) with SMTP id PygvCgAXh6xQUqZpOLCWQw--.188S6; Tue, 03 Mar 2026 11:15:34 +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 v2 4/6] exfat: drop redundant sec parameter from exfat_mirror_bh Date: Tue, 3 Mar 2026 11:14:07 +0800 Message-ID: <20260303031409.129136-5-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260303031409.129136-1-chizhiling@163.com> References: <20260303031409.129136-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: PygvCgAXh6xQUqZpOLCWQw--.188S6 X-Coremail-Antispam: 1Uf129KBjvJXoW7WF17XF4UCr1rCr47WrW5GFg_yoW8WF4fpa y5Ca93tr4jq3WDW3W7JrsYvw4Sva95JF95CrWrC3W8ZrZYyryvvFy8tFWY9a1qvasIyr1F g3Wjqry5JwnrGrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j2ZXOUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC3BatS2mmUlaaygAA33 Content-Type: text/plain; charset="utf-8" From: Chi Zhiling The sector offset can be obtained from bh->b_blocknr, so drop the redundant sec parameter from exfat_mirror_bh(). Also clean up the function to use exfat_update_bh() helper. No functional changes. Signed-off-by: Chi Zhiling --- fs/exfat/fatent.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/fs/exfat/fatent.c b/fs/exfat/fatent.c index 9a4143f3fc0c..4177a933e0be 100644 --- a/fs/exfat/fatent.c +++ b/fs/exfat/fatent.c @@ -11,11 +11,11 @@ #include "exfat_raw.h" #include "exfat_fs.h" =20 -static int exfat_mirror_bh(struct super_block *sb, sector_t sec, - struct buffer_head *bh) +static int exfat_mirror_bh(struct super_block *sb, struct buffer_head *bh) { struct buffer_head *c_bh; struct exfat_sb_info *sbi =3D EXFAT_SB(sb); + sector_t sec =3D bh->b_blocknr; sector_t sec2; int err =3D 0; =20 @@ -25,10 +25,7 @@ static int exfat_mirror_bh(struct super_block *sb, secto= r_t sec, if (!c_bh) return -ENOMEM; memcpy(c_bh->b_data, bh->b_data, sb->s_blocksize); - set_buffer_uptodate(c_bh); - mark_buffer_dirty(c_bh); - if (sb->s_flags & SB_SYNCHRONOUS) - err =3D sync_dirty_buffer(c_bh); + exfat_update_bh(c_bh, sb->s_flags & SB_SYNCHRONOUS); brelse(c_bh); } =20 @@ -83,7 +80,7 @@ int exfat_ent_set(struct super_block *sb, unsigned int lo= c, fat_entry =3D (__le32 *)&(bh->b_data[off]); *fat_entry =3D cpu_to_le32(content); exfat_update_bh(bh, sb->s_flags & SB_SYNCHRONOUS); - exfat_mirror_bh(sb, sec, bh); + exfat_mirror_bh(sb, bh); brelse(bh); return 0; } --=20 2.43.0 From nobody Thu Apr 9 14:58:04 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 22D5037CD29; Tue, 3 Mar 2026 03:15:48 +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=1772507751; cv=none; b=ISCajUDxOkjevvHfkr+fzDKRocdwuMNahcdoLLbgGGanWNhRZKftCHcaBlH1beOCLYzDV1OLS91mGFpJzz81Jrnox+BrgNjyDxJI5X3StVG99ss1Hbc0joqXeMvnpshfatIYKzBuFp+1CosCa1Cjz8giPjd9BSaWX5BZO/LM41o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772507751; c=relaxed/simple; bh=w8rNkWEjUFCXjSAhc3cIFAG542b2c3mihzEDpHI9qfI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tDBvD+LorvcV5rijQrv0/eNFMqtAq6fFCps8JPQa1SurgJdVDwaWWT2Epzbw4GwA+eT1Y6GxLFJIbVxl4bM/K7+Hk+4kehNsrc71TMAt1LeekkIwLm78dVFGnFMIU4uCRZaDA+Xst2XQ7UTzJHyxGgPBg4qBpiH1cyZOrPyVnco= 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=nVA5AFcB; 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="nVA5AFcB" 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=ZL gy4MSlrRZC+zc/j95iZRJF8V8QJqf5zvBN0CeFOkQ=; b=nVA5AFcBaZsbMjh45q ixuwskp/2G0t72/HC0TatB++vsjmn5QBs6on1ixVXK/u15kK/Z+YlYkPATlXsIEn ZFgQ35pfKP88AI3IDKAJ7FH+twZPwdaRe4g9kFSYEZ0DcJ3YQB8sYcCIeAEiPGMZ Jr2lt2Z20Tu5ODcfdscNSpg+s= Received: from czl-ubuntu-pc.. (unknown []) by gzsmtp4 (Coremail) with SMTP id PygvCgAXh6xQUqZpOLCWQw--.188S7; Tue, 03 Mar 2026 11:15:34 +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 v2 5/6] exfat: optimize exfat_chain_cont_cluster with cached buffer heads Date: Tue, 3 Mar 2026 11:14:08 +0800 Message-ID: <20260303031409.129136-6-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260303031409.129136-1-chizhiling@163.com> References: <20260303031409.129136-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: PygvCgAXh6xQUqZpOLCWQw--.188S7 X-Coremail-Antispam: 1Uf129KBjvJXoWxAFy8tFyDXr48KF15tw1DKFg_yoWrJr1fpF ZIka93tr4UJ3ZFv3Z7tw4kXr1fC397J3WkGa13G34fAr90yFnY9ry8Kry8try0kayDuFyY vF4UtF15CwnrWFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j2XdUUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC9xatS2mmUlaMBgAA3G Content-Type: text/plain; charset="utf-8" From: Chi Zhiling When converting files from NO_FAT_CHAIN to FAT_CHAIN format, profiling reveals significant time spent in mark_buffer_dirty() and exfat_mirror_bh() operations. This overhead occurs because each FAT entry modification triggers a full block dirty marking and mirroring operation. For consecutive clusters that reside in the same block, optimize by caching the buffer head and performing dirty marking only once at the end of the block's modifications. Performance improvements for converting a 30GB file: | Cluster Size | Before Patch | After Patch | Speedup | |--------------|--------------|-------------|---------| | 512 bytes | 4.243s | 1.866s | 2.27x | | 4KB | 0.863s | 0.236s | 3.66x | | 32KB | 0.069s | 0.034s | 2.03x | | 256KB | 0.012s | 0.006s | 2.00x | Signed-off-by: Chi Zhiling --- fs/exfat/fatent.c | 49 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/fs/exfat/fatent.c b/fs/exfat/fatent.c index 4177a933e0be..a973aa4de57b 100644 --- a/fs/exfat/fatent.c +++ b/fs/exfat/fatent.c @@ -32,6 +32,17 @@ static int exfat_mirror_bh(struct super_block *sb, struc= t buffer_head *bh) return err; } =20 +static int exfat_end_bh(struct super_block *sb, struct buffer_head *bh) +{ + int err; + + exfat_update_bh(bh, sb->s_flags & SB_SYNCHRONOUS); + err =3D exfat_mirror_bh(sb, bh); + brelse(bh); + + return err; +} + static int __exfat_ent_get(struct super_block *sb, unsigned int loc, unsigned int *content, struct buffer_head **last) { @@ -62,29 +73,40 @@ static int __exfat_ent_get(struct super_block *sb, unsi= gned int loc, return 0; } =20 -int exfat_ent_set(struct super_block *sb, unsigned int loc, - unsigned int content) +static int __exfat_ent_set(struct super_block *sb, unsigned int loc, + unsigned int content, struct buffer_head **cache) { - unsigned int off; sector_t sec; __le32 *fat_entry; - struct buffer_head *bh; + struct buffer_head *bh =3D cache ? *cache : NULL; + unsigned int off; =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)) { + if (bh) + exfat_end_bh(sb, bh); + bh =3D sb_bread(sb, sec); + if (cache) + *cache =3D bh; + if (unlikely(!bh)) + return -EIO; + } =20 fat_entry =3D (__le32 *)&(bh->b_data[off]); *fat_entry =3D cpu_to_le32(content); - exfat_update_bh(bh, sb->s_flags & SB_SYNCHRONOUS); - exfat_mirror_bh(sb, bh); - brelse(bh); + if (!cache) + exfat_end_bh(sb, bh); return 0; } =20 +int exfat_ent_set(struct super_block *sb, unsigned int loc, + unsigned int content) +{ + return __exfat_ent_set(sb, loc, content, NULL); +} + /* * Caller must release the buffer_head if no error return. */ @@ -170,6 +192,7 @@ int exfat_blk_readahead(struct super_block *sb, sector_= t sec, int exfat_chain_cont_cluster(struct super_block *sb, unsigned int chain, unsigned int len) { + struct buffer_head *bh =3D NULL; sector_t sec, end, ra; blkcnt_t ra_cnt =3D 0; =20 @@ -183,14 +206,16 @@ int exfat_chain_cont_cluster(struct super_block *sb, = unsigned int chain, sec =3D FAT_ENT_OFFSET_SECTOR(sb, chain); exfat_blk_readahead(sb, sec, &ra, &ra_cnt, end); =20 - if (exfat_ent_set(sb, chain, chain + 1)) + if (__exfat_ent_set(sb, chain, chain + 1, &bh)) return -EIO; chain++; len--; } =20 - if (exfat_ent_set(sb, chain, EXFAT_EOF_CLUSTER)) + if (__exfat_ent_set(sb, chain, EXFAT_EOF_CLUSTER, &bh)) return -EIO; + + exfat_end_bh(sb, bh); return 0; } =20 --=20 2.43.0 From nobody Thu Apr 9 14:58:04 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 9775837DE84; Tue, 3 Mar 2026 03:15:50 +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=1772507752; cv=none; b=Kki324UQHG5J2NRy9R7FBzK+Y5bmSXmK7iE1y/ZQ67HjDjzxOyWpS1ZXg26Bcpm0G2AIag+Ge5DxOolj/vWVPcJnb/RLOeID8JKSBudOe8V4tEbWUNxmYsJptGIy1qkz3I/3BHJPtLbZrwkfIo1VdXcUb6zS1EJqb4X9OAQvPpw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772507752; c=relaxed/simple; bh=8B+R8dwddxja26oLC4AinePqXHd6MjXL921jpmJgrlM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EYfdwgCu8E6xD1KEJkVxxFmcCGyjrPhaARAwcGbcEqbwl+rLhpaMw1kHSoLE43uXCNa9eM2zE30rNX6b7ILmujHmHbF3g+VJk+0wtosGCIgTG5DvqCbx6f9M3dEUzlqaRWVHiGoH0gHXxGL+kTApl1XOazV7Ogspc6vR0YQymT8= 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=loPR6UjU; 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="loPR6UjU" 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=8d Zd8C/M0MqLRH9zbAMQbAVx9Qkc5/D3OtnivlKzTa0=; b=loPR6UjU4r0jvtG6Y9 1Vyn76tiqzDjlXJTUT0YDYKHt19eu6BebAAjVRMVEoU50UJGX7z0X0TUbuKFGYs1 nMqbAEQBL7V0aPBpAdNHn6v9RaGzzpsOSl+hXENFkDOZT4Xdn2wKh0pzMHVFTq98 aENF4MbNxAgzkmcpmTXzoYzoQ= Received: from czl-ubuntu-pc.. (unknown []) by gzsmtp4 (Coremail) with SMTP id PygvCgAXh6xQUqZpOLCWQw--.188S8; Tue, 03 Mar 2026 11:15:34 +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 v2 6/6] exfat: fix error handling for FAT table operations Date: Tue, 3 Mar 2026 11:14:09 +0800 Message-ID: <20260303031409.129136-7-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260303031409.129136-1-chizhiling@163.com> References: <20260303031409.129136-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: PygvCgAXh6xQUqZpOLCWQw--.188S8 X-Coremail-Antispam: 1Uf129KBjvJXoWxAryfXF45GFW8uryDAFW8JFb_yoWrWryrpF W5Ga95Jr4qqa4Dur17tr4qv3WFvrn7Kay5CrWrA3ZYq3yqyw1v9ryUtryYva1DKa1vgr4j kF4Ygr45WwnxWrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j2XdUUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC9xatS2mmUlaMEQAA3R Content-Type: text/plain; charset="utf-8" From: Chi Zhiling Fix three error handling issues in FAT table operations: 1. Fix exfat_update_bh() to properly return errors from sync_dirty_buffer 2. Fix exfat_end_bh() to properly return errors from exfat_update_bh() and exfat_mirror_bh() 3. Fix ignored return values from exfat_chain_cont_cluster() in inode.c and namei.c These fixes ensure that FAT table write errors are properly propagated to the caller instead of being silently ignored. Signed-off-by: Chi Zhiling --- fs/exfat/exfat_fs.h | 2 +- fs/exfat/fatent.c | 8 ++++---- fs/exfat/inode.c | 5 +++-- fs/exfat/misc.c | 8 ++++++-- fs/exfat/namei.c | 3 ++- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index 090f25d1a418..9fed9fb33cae 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -584,7 +584,7 @@ void exfat_set_entry_time(struct exfat_sb_info *sbi, st= ruct timespec64 *ts, u8 *tz, __le16 *time, __le16 *date, u8 *time_cs); u16 exfat_calc_chksum16(void *data, int len, u16 chksum, int type); u32 exfat_calc_chksum32(void *data, int len, u32 chksum, int type); -void exfat_update_bh(struct buffer_head *bh, int sync); +int exfat_update_bh(struct buffer_head *bh, int sync); int exfat_update_bhs(struct buffer_head **bhs, int nr_bhs, int sync); void exfat_chain_set(struct exfat_chain *ec, unsigned int dir, unsigned int size, unsigned char flags); diff --git a/fs/exfat/fatent.c b/fs/exfat/fatent.c index a973aa4de57b..f2e5d5dde393 100644 --- a/fs/exfat/fatent.c +++ b/fs/exfat/fatent.c @@ -25,7 +25,7 @@ static int exfat_mirror_bh(struct super_block *sb, struct= buffer_head *bh) if (!c_bh) return -ENOMEM; memcpy(c_bh->b_data, bh->b_data, sb->s_blocksize); - exfat_update_bh(c_bh, sb->s_flags & SB_SYNCHRONOUS); + err =3D exfat_update_bh(c_bh, sb->s_flags & SB_SYNCHRONOUS); brelse(c_bh); } =20 @@ -36,10 +36,10 @@ static int exfat_end_bh(struct super_block *sb, struct = buffer_head *bh) { int err; =20 - exfat_update_bh(bh, sb->s_flags & SB_SYNCHRONOUS); - err =3D exfat_mirror_bh(sb, bh); + err =3D exfat_update_bh(bh, sb->s_flags & SB_SYNCHRONOUS); + if (!err) + err =3D exfat_mirror_bh(sb, bh); brelse(bh); - return err; } =20 diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c index 2fb2d2d5d503..cb13a197eee9 100644 --- a/fs/exfat/inode.c +++ b/fs/exfat/inode.c @@ -204,8 +204,9 @@ static int exfat_map_cluster(struct inode *inode, unsig= ned int clu_offset, * so fat-chain should be synced with * alloc-bitmap */ - exfat_chain_cont_cluster(sb, ei->start_clu, - num_clusters); + if (exfat_chain_cont_cluster(sb, ei->start_clu, + num_clusters)) + return -EIO; ei->flags =3D ALLOC_FAT_CHAIN; } if (new_clu.flags =3D=3D ALLOC_FAT_CHAIN) diff --git a/fs/exfat/misc.c b/fs/exfat/misc.c index fa8459828046..6f11a96a4ffa 100644 --- a/fs/exfat/misc.c +++ b/fs/exfat/misc.c @@ -161,13 +161,17 @@ u32 exfat_calc_chksum32(void *data, int len, u32 chks= um, int type) return chksum; } =20 -void exfat_update_bh(struct buffer_head *bh, int sync) +int exfat_update_bh(struct buffer_head *bh, int sync) { + int err =3D 0; + set_buffer_uptodate(bh); mark_buffer_dirty(bh); =20 if (sync) - sync_dirty_buffer(bh); + err =3D sync_dirty_buffer(bh); + + return err; } =20 int exfat_update_bhs(struct buffer_head **bhs, int nr_bhs, int sync) diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index 670116ae9ec8..ef2a3488c1b3 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -365,7 +365,8 @@ int exfat_find_empty_entry(struct inode *inode, /* no-fat-chain bit is disabled, * so fat-chain should be synced with alloc-bitmap */ - exfat_chain_cont_cluster(sb, p_dir->dir, p_dir->size); + if (exfat_chain_cont_cluster(sb, p_dir->dir, p_dir->size)) + return -EIO; p_dir->flags =3D ALLOC_FAT_CHAIN; hint_femp.cur.flags =3D ALLOC_FAT_CHAIN; } --=20 2.43.0