add patch add-missing-error-check-in-ext4_new_inode
[ext4-patch-queue.git] / fix-fdatasync-after-fallocate-operation
blob2cb17da3eb499659705826c269e01796fe8309a2
1 ext4: fix fdatasync(2) after fallocate(2) operation
3 From: Eryu Guan <eguan@redhat.com>
5 Currently, fallocate(2) with KEEP_SIZE followed by a fdatasync(2)
6 then crash, we'll see wrong allocated block number (stat -c %b), the
7 blocks allocated beyond EOF are all lost. fstests generic/468
8 exposes this bug.
10 Commit 67a7d5f561f4 ("ext4: fix fdatasync(2) after extent
11 manipulation operations") fixed all the other extent manipulation
12 operation paths such as hole punch, zero range, collapse range etc.,
13 but forgot the fallocate case.
15 So similarly, fix it by recording the correct journal tid in ext4
16 inode in fallocate(2) path, so that ext4_sync_file() will wait for
17 the right tid to be committed on fdatasync(2).
19 This addresses the test failure in xfstests test generic/468.
21 Signed-off-by: Eryu Guan <eguan@redhat.com>
22 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
23 Cc: stable@vger.kernel.org
24 ---
26 Note that fstests case generic/468 has not been pushed to upstream yet,
27 please find it at
28 https://patchwork.kernel.org/patch/7284531/
30 So the final test seq number can be different, though it's unlikely to
31 change. If changed I'll send an updated patch.
33 I've tested this patch with the pending generic/468 test and a auto
34 group run of fstests with default ext4 configuration (data=ordered and
35 4k block size), test results all look good.
37  fs/ext4/extents.c | 1 +
38  1 file changed, 1 insertion(+)
40 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
41 index 07bca11749d4..c941251ac0c0 100644
42 --- a/fs/ext4/extents.c
43 +++ b/fs/ext4/extents.c
44 @@ -4722,6 +4722,7 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,
45                                                     EXT4_INODE_EOFBLOCKS);
46                 }
47                 ext4_mark_inode_dirty(handle, inode);
48 +               ext4_update_inode_fsync_trans(handle, inode, 1);
49                 ret2 = ext4_journal_stop(handle);
50                 if (ret2)
51                         break;
52 -- 
53 2.13.6