• Filipe Manana's avatar
    Btrfs: fix crash after inode cache writeback failure · e43699d4
    Filipe Manana authored
    If the writeback of an inode cache failed we were unnecessarilly
    attempting to release again the delalloc metadata that we previously
    reserved. However attempting to do this a second time triggers an
    assertion at drop_outstanding_extent() because we have no more
    outstanding extents for our inode cache's inode. If we were able
    to start writeback of the cache the reserved metadata space is
    released at btrfs_finished_ordered_io(), even if an error happens
    during writeback.
    
    So make sure we don't repeat the metadata space release if writeback
    started for our inode cache.
    
    This issue was trivial to reproduce by running the fstest btrfs/088
    with "-o inode_cache", which triggered the assertion leading to a
    BUG() call and requiring a reboot in order to run the remaining
    fstests. Trace produced by btrfs/088:
    
    [255289.385904] BTRFS: assertion failed: BTRFS_I(inode)->outstanding_extents >= num_extents, file: fs/btrfs/extent-tree.c, line: 5276
    [255289.388094] ------------[ cut here ]------------
    [255289.389184] kernel BUG at fs/btrfs/ctree.h:4057!
    [255289.390125] invalid opcode: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC
    (...)
    [255289.392068] Call Trace:
    [255289.392068]  [<ffffffffa035e774>] drop_outstanding_extent+0x3d/0x6d [btrfs]
    [255289.392068]  [<ffffffffa0364988>] btrfs_delalloc_release_metadata+0x54/0xe3 [btrfs]
    [255289.392068]  [<ffffffffa03b4174>] btrfs_write_out_ino_cache+0x95/0xad [btrfs]
    [255289.392068]  [<ffffffffa036f5c4>] btrfs_save_ino_cache+0x275/0x2dc [btrfs]
    [255289.392068]  [<ffffffffa03e2d83>] commit_fs_roots.isra.12+0xaa/0x137 [btrfs]
    [255289.392068]  [<ffffffff8107d33d>] ? trace_hardirqs_on+0xd/0xf
    [255289.392068]  [<ffffffffa037841f>] ? btrfs_commit_transaction+0x4b1/0x9c9 [btrfs]
    [255289.392068]  [<ffffffff814351a4>] ? _raw_spin_unlock+0x32/0x46
    [255289.392068]  [<ffffffffa037842e>] btrfs_commit_transaction+0x4c0/0x9c9 [btrfs]
    (...)
    Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
    Signed-off-by: default avatarChris Mason <clm@fb.com>
    e43699d4
free-space-cache.c 90.6 KB