Skip to content

Commit ce0a2b8

Browse files
zhangyi089gregkh
authored andcommitted
ext4: subdivide EXT4_EXT_DATA_VALID1
commit 22784ca upstream. When splitting an extent, if the EXT4_GET_BLOCKS_CONVERT flag is set and it is necessary to split the target extent in the middle, ext4_split_extent() first handles splitting the latter half of the extent and passes the EXT4_EXT_DATA_VALID1 flag. This flag implies that all blocks before the split point contain valid data; however, this assumption is incorrect. Therefore, subdivid EXT4_EXT_DATA_VALID1 into EXT4_EXT_DATA_ENTIRE_VALID1 and EXT4_EXT_DATA_PARTIAL_VALID1, which indicate that the first half of the extent is either entirely valid or only partially valid, respectively. These two flags cannot be set simultaneously. This patch does not use EXT4_EXT_DATA_PARTIAL_VALID1, it only replaces EXT4_EXT_DATA_VALID1 with EXT4_EXT_DATA_ENTIRE_VALID1 at the location where it is set, no logical changes. Signed-off-by: Zhang Yi <yi.zhang@huawei.com> Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> Reviewed-by: Baokun Li <libaokun1@huawei.com> Cc: stable@kernel.org Message-ID: <20251129103247.686136-2-yi.zhang@huaweicloud.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4c38600 commit ce0a2b8

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

fs/ext4/extents.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@
4343
#define EXT4_EXT_MARK_UNWRIT1 0x2 /* mark first half unwritten */
4444
#define EXT4_EXT_MARK_UNWRIT2 0x4 /* mark second half unwritten */
4545

46-
#define EXT4_EXT_DATA_VALID1 0x8 /* first half contains valid data */
47-
#define EXT4_EXT_DATA_VALID2 0x10 /* second half contains valid data */
46+
/* first half contains valid data */
47+
#define EXT4_EXT_DATA_ENTIRE_VALID1 0x8 /* has entirely valid data */
48+
#define EXT4_EXT_DATA_PARTIAL_VALID1 0x10 /* has partially valid data */
49+
#define EXT4_EXT_DATA_VALID1 (EXT4_EXT_DATA_ENTIRE_VALID1 | \
50+
EXT4_EXT_DATA_PARTIAL_VALID1)
51+
52+
#define EXT4_EXT_DATA_VALID2 0x20 /* second half contains valid data */
4853

4954
static __le32 ext4_extent_block_csum(struct inode *inode,
5055
struct ext4_extent_header *eh)
@@ -3190,8 +3195,9 @@ static struct ext4_ext_path *ext4_split_extent_at(handle_t *handle,
31903195
unsigned int ee_len, depth;
31913196
int err = 0;
31923197

3193-
BUG_ON((split_flag & (EXT4_EXT_DATA_VALID1 | EXT4_EXT_DATA_VALID2)) ==
3194-
(EXT4_EXT_DATA_VALID1 | EXT4_EXT_DATA_VALID2));
3198+
BUG_ON((split_flag & EXT4_EXT_DATA_VALID1) == EXT4_EXT_DATA_VALID1);
3199+
BUG_ON((split_flag & EXT4_EXT_DATA_VALID1) &&
3200+
(split_flag & EXT4_EXT_DATA_VALID2));
31953201

31963202
ext_debug(inode, "logical block %llu\n", (unsigned long long)split);
31973203

@@ -3373,7 +3379,7 @@ static struct ext4_ext_path *ext4_split_extent(handle_t *handle,
33733379
split_flag1 |= EXT4_EXT_MARK_UNWRIT1 |
33743380
EXT4_EXT_MARK_UNWRIT2;
33753381
if (split_flag & EXT4_EXT_DATA_VALID2)
3376-
split_flag1 |= EXT4_EXT_DATA_VALID1;
3382+
split_flag1 |= EXT4_EXT_DATA_ENTIRE_VALID1;
33773383
path = ext4_split_extent_at(handle, inode, path,
33783384
map->m_lblk + map->m_len, split_flag1, flags1);
33793385
if (IS_ERR(path))
@@ -3728,7 +3734,7 @@ static struct ext4_ext_path *ext4_split_convert_extents(handle_t *handle,
37283734

37293735
/* Convert to unwritten */
37303736
if (flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN) {
3731-
split_flag |= EXT4_EXT_DATA_VALID1;
3737+
split_flag |= EXT4_EXT_DATA_ENTIRE_VALID1;
37323738
/* Convert to initialized */
37333739
} else if (flags & EXT4_GET_BLOCKS_CONVERT) {
37343740
/*

0 commit comments

Comments
 (0)