• Qu Wenruo's avatar
    btrfs: introduce extra sanity checks for extent maps · 3f255ece
    Qu Wenruo authored
    Since extent_map structure has the all the needed members to represent a
    file extent directly, we can apply all the file extent sanity checks to
    an extent map.
    
    The new sanity checks will cross check both the old members
    (block_start/block_len/orig_start) and the new members
    (disk_bytenr/disk_num_bytes/offset).
    
    There is a special case for offset/orig_start/start cross check, we only
    do such sanity check for compressed extent, as only compressed
    read/encoded write really utilize orig_start.
    This can be proved by the cleanup patch of orig_start.
    
    The checks happens at the following times:
    
    - add_extent_mapping()
      This is for newly added extent map
    
    - replace_extent_mapping()
      This is for btrfs_drop_extent_map_range() and split_extent_map()
    
    - try_merge_map()
    
    For a lot of call sites we have to properly populate all the members to
    pass the sanity check, meanwhile the following code needs extra
    modification:
    
    - setup_file_extents() from inode-tests
      The file extents layout of setup_file_extents() is already too invalid
      that tree-checker would reject most of them in real world.
    
      However there is just a special unaligned regular extent which has
      mismatched disk_num_bytes (4096) and ram_bytes (4096 - 1).
      So instead of dropping the whole test case, here we just unify
      disk_num_bytes and ram_bytes to 4096 - 1.
    
    - test_case_7() from extent-map-tests
      An extent is inserted with 16K length, but on-disk extent size is
      only 4K.
      This means it must be a compressed extent, so set the compressed flag
      for it.
    Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
    Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
    Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
    Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    3f255ece
relocation.c 117 KB