Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ext4: support large block size in ext4_readdir()

In ext4_readdir(), page_cache_sync_readahead() is used to readahead mapped
physical blocks. With LBS support, this can lead to a negative right shift.

To fix this, the page index is now calculated by first converting the
physical block number (pblk) to a file position (pos) before converting
it to a page index. Also, the correct number of pages to readahead is now
passed.

Signed-off-by: Baokun Li <libaokun1@huawei.com>
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Pankaj Raghav <p.raghav@samsung.com>
Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
Message-ID: <20251121090654.631996-9-libaokun@huaweicloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>

authored by

Baokun Li and committed by
Theodore Ts'o
609c5e00 6a28b5c9

+4 -4
+4 -4
fs/ext4/dir.c
··· 192 192 continue; 193 193 } 194 194 if (err > 0) { 195 - pgoff_t index = map.m_pblk >> 196 - (PAGE_SHIFT - inode->i_blkbits); 195 + pgoff_t index = map.m_pblk << inode->i_blkbits >> 196 + PAGE_SHIFT; 197 197 if (!ra_has_index(&file->f_ra, index)) 198 198 page_cache_sync_readahead( 199 199 sb->s_bdev->bd_mapping, 200 - &file->f_ra, file, 201 - index, 1); 200 + &file->f_ra, file, index, 201 + 1 << EXT4_SB(sb)->s_min_folio_order); 202 202 file->f_ra.prev_pos = (loff_t)index << PAGE_SHIFT; 203 203 bh = ext4_bread(NULL, inode, map.m_lblk, 0); 204 204 if (IS_ERR(bh)) {