mbox series

[v2,0/5] btrfs: detect and fix the ram_bytes mismatch

Message ID cover.1719366258.git.wqu@suse.com (mailing list archive)
Headers show
Series btrfs: detect and fix the ram_bytes mismatch | expand

Message

Qu Wenruo June 26, 2024, 1:47 a.m. UTC
[CHANGELOG]
v2:
- Add the missing patch fixing ram_bytes
  Now the 2nd patch would ignore the incorrect value and use a correct
  one from btrfs_file_extent_item::disk_num_bytes.

- Update the commit messages to fix my usual "would" and other grammar
  errors

There is a long existing mismatch between ram_bytes and disk_num_bytes
for regular non-compressed data extents.

It turns out to be caused by truncated ordered extents, which modified
ram_bytes unnecessarily.

Thankfully this is not going to cause any data corruption or whatever,
kernel can handle it correctly without any extra problem.
It's only a small violation on the on-disk format.

This series would fix by:

- Cleanup the @bytenr usage inside btrfs_extent_item_to_extent_map()
- Override the ram_bytes when reading file extent items from disk
  So that we always get correct extent maps even if the on-disk one is
  incorrect.
- Add an extra check on extent_map members
- Add the proper fix for the ram_bytes mismatch
- Add a tree-checker for the ram_bytes mismatch
  Since we can have on-disk ram_bytes incorrect already, this check is
  only for DEBUG and ASSERT builds, and it won't report error but only
  does a kernel warning for us to catch.

Qu Wenruo (5):
  btrfs: cleanup the bytenr usage inside
    btrfs_extent_item_to_extent_map()
  btrfs: ignore incorrect btrfs_file_extent_item::ram_bytes
  btrfs: make validate_extent_map() to catch ram_bytes mismatch
  btrfs: fix the ram_bytes assignment for truncated ordered extents
  btrfs: tree-checker: add extra ram_bytes and disk_num_bytes check

 fs/btrfs/extent_map.c   |  5 +++++
 fs/btrfs/file-item.c    | 16 +++++++++++-----
 fs/btrfs/inode.c        |  4 +---
 fs/btrfs/tree-checker.c | 18 ++++++++++++++++++
 4 files changed, 35 insertions(+), 8 deletions(-)

Comments

Filipe Manana June 26, 2024, 11:21 a.m. UTC | #1
On Wed, Jun 26, 2024 at 2:48 AM Qu Wenruo <wqu@suse.com> wrote:
>
> [CHANGELOG]
> v2:
> - Add the missing patch fixing ram_bytes
>   Now the 2nd patch would ignore the incorrect value and use a correct
>   one from btrfs_file_extent_item::disk_num_bytes.
>
> - Update the commit messages to fix my usual "would" and other grammar
>   errors
>
> There is a long existing mismatch between ram_bytes and disk_num_bytes
> for regular non-compressed data extents.
>
> It turns out to be caused by truncated ordered extents, which modified
> ram_bytes unnecessarily.
>
> Thankfully this is not going to cause any data corruption or whatever,
> kernel can handle it correctly without any extra problem.
> It's only a small violation on the on-disk format.
>
> This series would fix by:
>
> - Cleanup the @bytenr usage inside btrfs_extent_item_to_extent_map()
> - Override the ram_bytes when reading file extent items from disk
>   So that we always get correct extent maps even if the on-disk one is
>   incorrect.
> - Add an extra check on extent_map members
> - Add the proper fix for the ram_bytes mismatch
> - Add a tree-checker for the ram_bytes mismatch
>   Since we can have on-disk ram_bytes incorrect already, this check is
>   only for DEBUG and ASSERT builds, and it won't report error but only
>   does a kernel warning for us to catch.
>
> Qu Wenruo (5):
>   btrfs: cleanup the bytenr usage inside
>     btrfs_extent_item_to_extent_map()
>   btrfs: ignore incorrect btrfs_file_extent_item::ram_bytes
>   btrfs: make validate_extent_map() to catch ram_bytes mismatch
>   btrfs: fix the ram_bytes assignment for truncated ordered extents
>   btrfs: tree-checker: add extra ram_bytes and disk_num_bytes check
>
>  fs/btrfs/extent_map.c   |  5 +++++
>  fs/btrfs/file-item.c    | 16 +++++++++++-----
>  fs/btrfs/inode.c        |  4 +---
>  fs/btrfs/tree-checker.c | 18 ++++++++++++++++++
>  4 files changed, 35 insertions(+), 8 deletions(-)

Reviewed-by: Filipe Manana <fdmanana@suse.com>

Looks good, thanks.

>
> --
> 2.45.2
>
>