• Qu Wenruo's avatar
    btrfs: tree-checker: add type and sequence check for inline backrefs · 1645c283
    Qu Wenruo authored
    [BUG]
    There is a bug report that ntfs2btrfs had a bug that it can lead to
    transaction abort and the filesystem flips to read-only.
    
    [CAUSE]
    For inline backref items, kernel has a strict requirement for their
    ordered, they must follow the following rules:
    
    - All btrfs_extent_inline_ref::type should be in an ascending order
    
    - Within the same type, the items should follow a descending order by
      their sequence number
    
      For EXTENT_DATA_REF type, the sequence number is result from
      hash_extent_data_ref().
      For other types, their sequence numbers are
      btrfs_extent_inline_ref::offset.
    
    Thus if there is any code not following above rules, the resulted
    inline backrefs can prevent the kernel to locate the needed inline
    backref and lead to transaction abort.
    
    [FIX]
    Ntrfs2btrfs has already fixed the problem, and btrfs-progs has added the
    ability to detect such problems.
    
    For kernel, let's be more noisy and be more specific about the order, so
    that the next time kernel hits such problem we would reject it in the
    first place, without leading to transaction abort.
    
    Link: https://github.com/kdave/btrfs-progs/pull/622Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
    Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    1645c283
tree-checker.c 63.9 KB