Skip to content

Commit d81e341

Browse files
yangerkungregkh
authored andcommitted
ext4: refresh the ext4_ext_path struct after dropping i_data_sem.
commit 1811bc4 upstream. After we drop i_data sem, we need to reload the ext4_ext_path structure since the extent tree can change once i_data_sem is released. This addresses the BUG: [52117.465187] ------------[ cut here ]------------ [52117.465686] kernel BUG at fs/ext4/extents.c:1756! ... [52117.478306] Call Trace: [52117.478565] ext4_ext_shift_extents+0x3ee/0x710 [52117.479020] ext4_fallocate+0x139c/0x1b40 [52117.479405] ? __do_sys_newfstat+0x6b/0x80 [52117.479805] vfs_fallocate+0x151/0x4b0 [52117.480177] ksys_fallocate+0x4a/0xa0 [52117.480533] __x64_sys_fallocate+0x22/0x30 [52117.480930] do_syscall_64+0x35/0x80 [52117.481277] entry_SYSCALL_64_after_hwframe+0x44/0xae [52117.481769] RIP: 0033:0x7fa062f855ca Cc: stable@kernel.org Link: https://lore.kernel.org/r/20210903062748.4118886-4-yangerkun@huawei.com Signed-off-by: yangerkun <yangerkun@huawei.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4089432 commit d81e341

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

‎fs/ext4/extents.c‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5005,8 +5005,11 @@ ext4_ext_shift_path_extents(struct ext4_ext_path *path, ext4_lblk_t shift,
50055005
restart_credits = ext4_writepage_trans_blocks(inode);
50065006
err = ext4_datasem_ensure_credits(handle, inode, credits,
50075007
restart_credits, 0);
5008-
if (err)
5008+
if (err) {
5009+
if (err > 0)
5010+
err = -EAGAIN;
50095011
goto out;
5012+
}
50105013

50115014
err = ext4_ext_get_access(handle, inode, path + depth);
50125015
if (err)
@@ -5080,6 +5083,7 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
50805083
int ret = 0, depth;
50815084
struct ext4_extent *extent;
50825085
ext4_lblk_t stop, *iterator, ex_start, ex_end;
5086+
ext4_lblk_t tmp = EXT_MAX_BLOCKS;
50835087

50845088
/* Let path point to the last extent */
50855089
path = ext4_find_extent(inode, EXT_MAX_BLOCKS - 1, NULL,
@@ -5133,11 +5137,15 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
51335137
* till we reach stop. In case of right shift, iterator points to stop
51345138
* and it is decreased till we reach start.
51355139
*/
5140+
again:
51365141
if (SHIFT == SHIFT_LEFT)
51375142
iterator = &start;
51385143
else
51395144
iterator = &stop;
51405145

5146+
if (tmp != EXT_MAX_BLOCKS)
5147+
*iterator = tmp;
5148+
51415149
/*
51425150
* Its safe to start updating extents. Start and stop are unsigned, so
51435151
* in case of right shift if extent with 0 block is reached, iterator
@@ -5166,6 +5174,7 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
51665174
}
51675175
}
51685176

5177+
tmp = *iterator;
51695178
if (SHIFT == SHIFT_LEFT) {
51705179
extent = EXT_LAST_EXTENT(path[depth].p_hdr);
51715180
*iterator = le32_to_cpu(extent->ee_block) +
@@ -5184,6 +5193,9 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
51845193
}
51855194
ret = ext4_ext_shift_path_extents(path, shift, inode,
51865195
handle, SHIFT);
5196+
/* iterator can be NULL which means we should break */
5197+
if (ret == -EAGAIN)
5198+
goto again;
51875199
if (ret)
51885200
break;
51895201
}

0 commit comments

Comments
 (0)