Skip to content

Commit b3ff056

Browse files
taoma-tmtytso
authored andcommitted
ext4: don't check io->flag when setting EXT4_STATE_DIO_UNWRITTEN inode state
When we want to convert the unitialized extent in direct write, we can either do it in ext4_end_io_nolock(AIO case) or in ext4_ext_direct_IO(non AIO case) and EXT4_I(inode)->cur_aio_dio is a guard for ext4_ext_map_blocks to find the right case. In e9e3bce, we mistakenly change it by: - if (io) + if (io && !(io->flag & EXT4_IO_END_UNWRITTEN)) { io->flag = EXT4_IO_END_UNWRITTEN; - else + atomic_inc(&EXT4_I(inode)->i_aiodio_unwritten); + } else ext4_set_inode_state(inode, EXT4_STATE_DIO_UNWRITTEN); So now if we map 2 blocks, and the first one set the EXT_IO_END_UNWRITTEN, the 2nd mapping will set inode state because of the check for the flag. This is wrong. Cc: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Tao Ma <boyu.mt@taobao.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent 0a10da7 commit b3ff056

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

‎fs/ext4/extents.c‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3390,9 +3390,11 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode,
33903390
* that this IO needs to conversion to written when IO is
33913391
* completed
33923392
*/
3393-
if (io && !(io->flag & EXT4_IO_END_UNWRITTEN)) {
3394-
io->flag = EXT4_IO_END_UNWRITTEN;
3395-
atomic_inc(&EXT4_I(inode)->i_aiodio_unwritten);
3393+
if (io) {
3394+
if (!(io->flag & EXT4_IO_END_UNWRITTEN)) {
3395+
io->flag = EXT4_IO_END_UNWRITTEN;
3396+
atomic_inc(&EXT4_I(inode)->i_aiodio_unwritten);
3397+
}
33963398
} else
33973399
ext4_set_inode_state(inode, EXT4_STATE_DIO_UNWRITTEN);
33983400
if (ext4_should_dioread_nolock(inode))
@@ -3946,9 +3948,11 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
39463948
* that we need to perform conversion when IO is done.
39473949
*/
39483950
if ((flags & EXT4_GET_BLOCKS_PRE_IO)) {
3949-
if (io && !(io->flag & EXT4_IO_END_UNWRITTEN)) {
3950-
io->flag = EXT4_IO_END_UNWRITTEN;
3951-
atomic_inc(&EXT4_I(inode)->i_aiodio_unwritten);
3951+
if (io) {
3952+
if (!(io->flag & EXT4_IO_END_UNWRITTEN)) {
3953+
io->flag = EXT4_IO_END_UNWRITTEN;
3954+
atomic_inc(&EXT4_I(inode)->i_aiodio_unwritten);
3955+
}
39523956
} else
39533957
ext4_set_inode_state(inode,
39543958
EXT4_STATE_DIO_UNWRITTEN);

0 commit comments

Comments
 (0)