Message ID | 8ae9d9cbfce4a3c1d21a413d5072694b1814aad1.1719291793.git.wqu@suse.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: detect and fix the ram_bytes mismatch | expand |
On Tue, Jun 25, 2024 at 6:08 AM Qu Wenruo <wqu@suse.com> wrote: > > Previously validate_extent_map() is only to catch bugs related to > extent_map member cleanups. > > But with recent btrfs-check enhancement to catch ram_bytes mismatch with > disk_num_bytes, it would be much better to catch such extent maps > earlier. > > So this patch would add extra ram_bytes validation for extent maps. would add -> adds > > Please note that, older filesystems with such mismatch won't trigger this error: > > - extent_map::ram_bytes is already fixed when reading from disk > At btrfs_extent_item_to_extent_map() we override extent_map::ram_bytes > to disk_num_bytes for non-compressed regular/preallocated extents. At btrfs_extent_item_to_extent_map() we override ram_bytes for any type of extent, it's not conditional on anything. So this is confusing because it doesn't match the code. > > So this enhanced sanity checks should not affect end users. checks -> check, otherwise "this" should be "these" (but there's only one check). The code looks good, thanks. > > Signed-off-by: Qu Wenruo <wqu@suse.com> > --- > fs/btrfs/extent_map.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c > index b869a0ee24d2..6961cc73fe3f 100644 > --- a/fs/btrfs/extent_map.c > +++ b/fs/btrfs/extent_map.c > @@ -317,6 +317,11 @@ static void validate_extent_map(struct btrfs_fs_info *fs_info, struct extent_map > if (em->offset + em->len > em->disk_num_bytes && > !extent_map_is_compressed(em)) > dump_extent_map(fs_info, "disk_num_bytes too small", em); > + if (!extent_map_is_compressed(em) && > + em->ram_bytes != em->disk_num_bytes) > + dump_extent_map(fs_info, > + "ram_bytes mismatch with disk_num_bytes for non-compressed em", > + em); > } else if (em->offset) { > dump_extent_map(fs_info, "non-zero offset for hole/inline", em); > } > -- > 2.45.2 > >
diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c index b869a0ee24d2..6961cc73fe3f 100644 --- a/fs/btrfs/extent_map.c +++ b/fs/btrfs/extent_map.c @@ -317,6 +317,11 @@ static void validate_extent_map(struct btrfs_fs_info *fs_info, struct extent_map if (em->offset + em->len > em->disk_num_bytes && !extent_map_is_compressed(em)) dump_extent_map(fs_info, "disk_num_bytes too small", em); + if (!extent_map_is_compressed(em) && + em->ram_bytes != em->disk_num_bytes) + dump_extent_map(fs_info, + "ram_bytes mismatch with disk_num_bytes for non-compressed em", + em); } else if (em->offset) { dump_extent_map(fs_info, "non-zero offset for hole/inline", em); }
Previously validate_extent_map() is only to catch bugs related to extent_map member cleanups. But with recent btrfs-check enhancement to catch ram_bytes mismatch with disk_num_bytes, it would be much better to catch such extent maps earlier. So this patch would add extra ram_bytes validation for extent maps. Please note that, older filesystems with such mismatch won't trigger this error: - extent_map::ram_bytes is already fixed when reading from disk At btrfs_extent_item_to_extent_map() we override extent_map::ram_bytes to disk_num_bytes for non-compressed regular/preallocated extents. So this enhanced sanity checks should not affect end users. Signed-off-by: Qu Wenruo <wqu@suse.com> --- fs/btrfs/extent_map.c | 5 +++++ 1 file changed, 5 insertions(+)