Skip to content

Commit 6b730a4

Browse files
Shida Zhangtytso
authored andcommitted
ext4: hoist ext4_block_write_begin and replace the __block_write_begin
Using __block_write_begin() make it inconvenient to journal the user data dirty process. We can't tell the block layer maintainer, ‘Hey, we want to trace the dirty user data in ext4, can we add some special code for ext4 in __block_write_begin?’:P So use ext4_block_write_begin() instead. The two functions are basically doing the same thing except for the fscrypt related code. Remove the unnecessary #ifdef since fscrypt_inode_uses_fs_layer_crypto() returns false (and it's known at compile time) when !CONFIG_FS_ENCRYPTION. And hoist the ext4_block_write_begin so that it can be used in other files. Suggested-by: Jan Kara <[email protected]> Suggested-by: Eric Biggers <[email protected]> Signed-off-by: Shida Zhang <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 3910b51 commit 6b730a4

File tree

3 files changed

+12
-24
lines changed

3 files changed

+12
-24
lines changed

fs/ext4/ext4.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3853,6 +3853,8 @@ static inline int ext4_buffer_uptodate(struct buffer_head *bh)
38533853
return buffer_uptodate(bh);
38543854
}
38553855

3856+
extern int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigned len,
3857+
get_block_t *get_block);
38563858
#endif /* __KERNEL__ */
38573859

38583860
#define EFSBADCRC EBADMSG /* Bad CRC detected */

fs/ext4/inline.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,10 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
601601
goto out;
602602

603603
if (ext4_should_dioread_nolock(inode)) {
604-
ret = __block_write_begin(&folio->page, from, to,
605-
ext4_get_block_unwritten);
604+
ret = ext4_block_write_begin(folio, from, to,
605+
ext4_get_block_unwritten);
606606
} else
607-
ret = __block_write_begin(&folio->page, from, to, ext4_get_block);
607+
ret = ext4_block_write_begin(folio, from, to, ext4_get_block);
608608

609609
if (!ret && ext4_should_journal_data(inode)) {
610610
ret = ext4_walk_page_buffers(handle, inode,
@@ -856,8 +856,8 @@ static int ext4_da_convert_inline_data_to_extent(struct address_space *mapping,
856856
goto out;
857857
}
858858

859-
ret = __block_write_begin(&folio->page, 0, inline_size,
860-
ext4_da_get_block_prep);
859+
ret = ext4_block_write_begin(folio, 0, inline_size,
860+
ext4_da_get_block_prep);
861861
if (ret) {
862862
up_read(&EXT4_I(inode)->xattr_sem);
863863
folio_unlock(folio);

fs/ext4/inode.c

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,10 +1006,10 @@ int do_journal_get_write_access(handle_t *handle, struct inode *inode,
10061006
if (!buffer_mapped(bh) || buffer_freed(bh))
10071007
return 0;
10081008
/*
1009-
* __block_write_begin() could have dirtied some buffers. Clean
1009+
* ext4_block_write_begin() could have dirtied some buffers. Clean
10101010
* the dirty bit as jbd2_journal_get_write_access() could complain
10111011
* otherwise about fs integrity issues. Setting of the dirty bit
1012-
* by __block_write_begin() isn't a real problem here as we clear
1012+
* by ext4_block_write_begin() isn't a real problem here as we clear
10131013
* the bit before releasing a page lock and thus writeback cannot
10141014
* ever write the buffer.
10151015
*/
@@ -1023,9 +1023,8 @@ int do_journal_get_write_access(handle_t *handle, struct inode *inode,
10231023
return ret;
10241024
}
10251025

1026-
#ifdef CONFIG_FS_ENCRYPTION
1027-
static int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigned len,
1028-
get_block_t *get_block)
1026+
int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigned len,
1027+
get_block_t *get_block)
10291028
{
10301029
unsigned from = pos & (PAGE_SIZE - 1);
10311030
unsigned to = from + len;
@@ -1116,7 +1115,6 @@ static int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigned len,
11161115

11171116
return err;
11181117
}
1119-
#endif
11201118

11211119
/*
11221120
* To preserve ordering, it is essential that the hole instantiation and
@@ -1198,19 +1196,11 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,
11981196
/* In case writeback began while the folio was unlocked */
11991197
folio_wait_stable(folio);
12001198

1201-
#ifdef CONFIG_FS_ENCRYPTION
12021199
if (ext4_should_dioread_nolock(inode))
12031200
ret = ext4_block_write_begin(folio, pos, len,
12041201
ext4_get_block_unwritten);
12051202
else
12061203
ret = ext4_block_write_begin(folio, pos, len, ext4_get_block);
1207-
#else
1208-
if (ext4_should_dioread_nolock(inode))
1209-
ret = __block_write_begin(&folio->page, pos, len,
1210-
ext4_get_block_unwritten);
1211-
else
1212-
ret = __block_write_begin(&folio->page, pos, len, ext4_get_block);
1213-
#endif
12141204
if (!ret && ext4_should_journal_data(inode)) {
12151205
ret = ext4_walk_page_buffers(handle, inode,
12161206
folio_buffers(folio), from, to,
@@ -1223,7 +1213,7 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,
12231213

12241214
folio_unlock(folio);
12251215
/*
1226-
* __block_write_begin may have instantiated a few blocks
1216+
* ext4_block_write_begin may have instantiated a few blocks
12271217
* outside i_size. Trim these off again. Don't need
12281218
* i_size_read because we hold i_rwsem.
12291219
*
@@ -2936,11 +2926,7 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping,
29362926
if (IS_ERR(folio))
29372927
return PTR_ERR(folio);
29382928

2939-
#ifdef CONFIG_FS_ENCRYPTION
29402929
ret = ext4_block_write_begin(folio, pos, len, ext4_da_get_block_prep);
2941-
#else
2942-
ret = __block_write_begin(&folio->page, pos, len, ext4_da_get_block_prep);
2943-
#endif
29442930
if (ret < 0) {
29452931
folio_unlock(folio);
29462932
folio_put(folio);

0 commit comments

Comments
 (0)