• Josef Bacik's avatar
    Btrfs: fix dio write vs buffered read race · c3473e83
    Josef Bacik authored
    Miao pointed out there's a problem with mixing dio writes and buffered
    reads.  If the read happens between us invalidating the page range and
    actually locking the extent we can bring in pages into page cache.  Then
    once the write finishes if somebody tries to read again it will just find
    uptodate pages and we'll read stale data.  So we need to lock the extent and
    check for uptodate bits in the range.  If there are uptodate bits we need to
    unlock and invalidate again.  This will keep this race from happening since
    we will hold the extent locked until we create the ordered extent, and then
    teh read side always waits for ordered extents.  There was also a race in
    how we updated i_size, previously we were relying on the generic DIO stuff
    to adjust the i_size after the DIO had completed, but this happens outside
    of the extent lock which means reads could come in and not see the updated
    i_size.  So instead move this work into where we create the extents, and
    then this way the update ordered i_size stuff works properly in the endio
    handlers.  Thanks,
    Signed-off-by: default avatarJosef Bacik <josef@redhat.com>
    c3473e83
file.c 48.6 KB