• Eryu Guan's avatar
    fs: invalidate page cache after end_io() in dio completion · 5e25c269
    Eryu Guan authored
    Commit 332391a9 ("fs: Fix page cache inconsistency when mixing
    buffered and AIO DIO") moved page cache invalidation from
    iomap_dio_rw() to iomap_dio_complete() for iomap based direct write
    path, but before the dio->end_io() call, and it re-introdued the bug
    fixed by commit c771c14b ("iomap: invalidate page caches should
    be after iomap_dio_complete() in direct write").
    
    I found this because fstests generic/418 started failing on XFS with
    v4.14-rc3 kernel, which is the regression test for this specific
    bug.
    
    So similarly, fix it by moving dio->end_io() (which does the
    unwritten extent conversion) before page cache invalidation, to make
    sure next buffer read reads the final real allocations not unwritten
    extents. I also add some comments about why should end_io() go first
    in case we get it wrong again in the future.
    
    Note that, there's no such problem in the non-iomap based direct
    write path, because we didn't remove the page cache invalidation
    after the ->direct_IO() in generic_file_direct_write() call, but I
    decided to fix dio_complete() too so we don't leave a landmine
    there, also be consistent with iomap_dio_complete().
    
    Fixes: 332391a9 ("fs: Fix page cache inconsistency when mixing buffered and AIO DIO")
    Signed-off-by: default avatarEryu Guan <eguan@redhat.com>
    Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
    Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
    Reviewed-by: default avatarJan Kara <jack@suse.cz>
    Reviewed-by: default avatarLukas Czerner <lczerner@redhat.com>
    5e25c269
direct-io.c 40.1 KB