Skip to content

Commit bff6235

Browse files
LiBaokun96tytso
authored andcommitted
ext4: support large block size in ext4_block_write_begin()
Use the EXT4_PG_TO_LBLK() macro to convert folio indexes to blocks to avoid negative left shifts after supporting blocksize greater than PAGE_SIZE. 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: Ojaswin Mujoo <ojaswin@linux.ibm.com> Message-ID: <20251121090654.631996-18-libaokun@huaweicloud.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent a6d7324 commit bff6235

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

fs/ext4/inode.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,8 +1170,7 @@ int ext4_block_write_begin(handle_t *handle, struct folio *folio,
11701170
unsigned block_start, block_end;
11711171
sector_t block;
11721172
int err = 0;
1173-
unsigned blocksize = inode->i_sb->s_blocksize;
1174-
unsigned bbits;
1173+
unsigned int blocksize = i_blocksize(inode);
11751174
struct buffer_head *bh, *head, *wait[2];
11761175
int nr_wait = 0;
11771176
int i;
@@ -1180,12 +1179,12 @@ int ext4_block_write_begin(handle_t *handle, struct folio *folio,
11801179
BUG_ON(!folio_test_locked(folio));
11811180
BUG_ON(to > folio_size(folio));
11821181
BUG_ON(from > to);
1182+
WARN_ON_ONCE(blocksize > folio_size(folio));
11831183

11841184
head = folio_buffers(folio);
11851185
if (!head)
11861186
head = create_empty_buffers(folio, blocksize, 0);
1187-
bbits = ilog2(blocksize);
1188-
block = (sector_t)folio->index << (PAGE_SHIFT - bbits);
1187+
block = EXT4_PG_TO_LBLK(inode, folio->index);
11891188

11901189
for (bh = head, block_start = 0; bh != head || !block_start;
11911190
block++, block_start = block_end, bh = bh->b_this_page) {

0 commit comments

Comments
 (0)