• Qu Wenruo's avatar
    btrfs: don't clear page extent mapped if we're not invalidating the full page · bcd77455
    Qu Wenruo authored
    [BUG]
    With current btrfs subpage rw support, the following script can lead to
    fs hang:
    
      $ mkfs.btrfs -f -s 4k $dev
      $ mount $dev -o nospace_cache $mnt
      $ fsstress -w -n 100 -p 1 -s 1608140256 -v -d $mnt
    
    The fs will hang at btrfs_start_ordered_extent().
    
    [CAUSE]
    In above test case, btrfs_invalidate() will be called with the following
    parameters:
    
      offset = 0 length = 53248 page dirty = 1 subpage dirty bitmap = 0x2000
    
    Since @offset is 0, btrfs_invalidate() will try to invalidate the full
    page, and finally call clear_page_extent_mapped() which will detach
    subpage structure from the page.
    
    And since the page no longer has subpage structure, the subpage dirty
    bitmap will be cleared, preventing the dirty range from being written
    back, thus no way to wake up the ordered extent.
    
    [FIX]
    Just follow other filesystems, only to invalidate the page if the range
    covers the full page.
    
    There are cases like truncate_setsize() which can call
    btrfs_invalidatepage() with offset == 0 and length != 0 for the last
    page of an inode.
    
    Although the old code will still try to invalidate the full page, we are
    still safe to just wait for ordered extent to finish.
    So it shouldn't cause extra problems.
    
    Tested-by: Ritesh Harjani <riteshh@linux.ibm.com> # [ppc64]
    Tested-by: Anand Jain <anand.jain@oracle.com> # [aarch64]
    Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    bcd77455
inode.c 300 KB