Btrfs: fix regression in btrfs_page_mkwrite() from vm_fault_t conversion
authorChris Mason <clm@fb.com>
Mon, 25 Jun 2018 17:03:41 +0000 (10:03 -0700)
committerDavid Sterba <dsterba@suse.com>
Thu, 28 Jun 2018 09:30:50 +0000 (11:30 +0200)
commit717beb96d969561cff53aad2f09547db20ee6ffd
treeba39d7f889f9c954a19779139a0739b6530bb5a6
parent6f7de19ed3d4d3526ca5eca428009f97cf969c2f
Btrfs: fix regression in btrfs_page_mkwrite() from vm_fault_t conversion

The vm_fault_t conversion commit introduced a ret2 variable for tracking
the integer return values from internal btrfs functions.  It was
sometimes returning VM_FAULT_LOCKED for pages that were actually invalid
and had been removed from the radix.  Something like this:

    ret2 = btrfs_delalloc_reserve_space() // returns zero on success

    lock_page(page)
    if (page->mapping != inode->i_mapping)
goto out_unlock;

...

out_unlock:
    if (!ret2) {
    ...
    return VM_FAULT_LOCKED;
    }

This ends up triggering this WARNING in btrfs_destroy_inode()
    WARN_ON(BTRFS_I(inode)->block_rsv.size);

xfstests generic/095 was able to reliably reproduce the errors.

Since out_unlock: is only used for errors, this fix moves it below the
if (!ret2) check we use to return VM_FAULT_LOCKED for success.

Fixes: a528a2415087 (btrfs: change return type of btrfs_page_mkwrite to vm_fault_t)
Signed-off-by: Chris Mason <clm@fb.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c