mbox series

[0/8] btrfs: extent-map: use disk_bytenr/offset to replace block_start/block_len/orig_start

Message ID cover.1712614770.git.wqu@suse.com (mailing list archive)
Headers show
Series btrfs: extent-map: use disk_bytenr/offset to replace block_start/block_len/orig_start | expand

Message

Qu Wenruo April 8, 2024, 10:33 p.m. UTC
[REASON FOR RFC]
Not all sanity checks are implemented, there is a missing check for
ram_bytes on non-compressed extent.
Because even without this series, generic/311 can generate a file extent
with ram_bytes larger than disk_num_bytes.

This seems harmless, but I still want to fix it and implement a full
version of the em sanity check.

[REPO]
https://github.com/adam900710/linux/tree/em_cleanup

Which relies on previous changes on extent maps.

This series introduce two new members (disk_bytenr/offset) to
extent_map, and removes three old members
(block_start/block_len/offset), finally rename one member
(orig_block_len -> disk_num_bytes).

This should save us one u64 for extent_map.

But to make things safe to migrate, I introduce extra sanity checks for
extent_map, and do cross check for both old and new members.

The extra sanity checks already exposed one bug (thankfully harmless)
causing em::block_start to be incorrect.

There is another bug related to bad btrfs_file_extent_item::ram_bytes,
which can be larger than disk_num_bytes for non-compressed file extents.
(Generated by generic/311 test case, but it seems to be created on-disk
 first)

But so far, the patchset is fine for default fstests run.

The patchset would do two renames as preparation.
Then introduce the new member, the extra sanity checks.
Finally do the migration by remove the old member one-by-one, to make
sure everything is fine.

Qu Wenruo (8):
  btrfs: rename extent_map::orig_block_len to disk_num_bytes
  btrfs: rename members of can_nocow_file_extent_args
  btrfs: introduce new members for extent_map
  btrfs: introduce extra sanity checks for extent maps
  btrfs: remove extent_map::orig_start member
  btrfs: remove extent_map::block_len member
  btrfs: remove extent_map::block_start member
  btrfs: reorder disk_bytenr/disk_num_bytes/ram_bytes/offset parameters

 fs/btrfs/btrfs_inode.h            |   5 +-
 fs/btrfs/compression.c            |   7 +-
 fs/btrfs/defrag.c                 |  14 +-
 fs/btrfs/extent_io.c              |  10 +-
 fs/btrfs/extent_map.c             | 187 ++++++++++++++++--------
 fs/btrfs/extent_map.h             |  51 +++----
 fs/btrfs/file-item.c              |  23 +--
 fs/btrfs/file.c                   |  18 +--
 fs/btrfs/inode.c                  | 234 ++++++++++++++++--------------
 fs/btrfs/relocation.c             |   5 +-
 fs/btrfs/tests/extent-map-tests.c | 114 ++++++++-------
 fs/btrfs/tests/inode-tests.c      | 177 +++++++++++-----------
 fs/btrfs/tree-log.c               |  27 ++--
 fs/btrfs/zoned.c                  |   4 +-
 include/trace/events/btrfs.h      |  20 +--
 15 files changed, 487 insertions(+), 409 deletions(-)

Comments

David Sterba April 9, 2024, 2:57 p.m. UTC | #1
On Tue, Apr 09, 2024 at 08:03:39AM +0930, Qu Wenruo wrote:
> [REASON FOR RFC]
> Not all sanity checks are implemented, there is a missing check for
> ram_bytes on non-compressed extent.
> Because even without this series, generic/311 can generate a file extent
> with ram_bytes larger than disk_num_bytes.
> 
> This seems harmless, but I still want to fix it and implement a full
> version of the em sanity check.
> 
> [REPO]
> https://github.com/adam900710/linux/tree/em_cleanup
> 
> Which relies on previous changes on extent maps.
> 
> This series introduce two new members (disk_bytenr/offset) to
> extent_map, and removes three old members
> (block_start/block_len/offset), finally rename one member
> (orig_block_len -> disk_num_bytes).
> 
> This should save us one u64 for extent_map.
> 
> But to make things safe to migrate, I introduce extra sanity checks for
> extent_map, and do cross check for both old and new members.
> 
> The extra sanity checks already exposed one bug (thankfully harmless)
> causing em::block_start to be incorrect.
> 
> There is another bug related to bad btrfs_file_extent_item::ram_bytes,
> which can be larger than disk_num_bytes for non-compressed file extents.
> (Generated by generic/311 test case, but it seems to be created on-disk
>  first)
> 
> But so far, the patchset is fine for default fstests run.

I've only paged through the patches, besides the renames there are so
many changes where it's hard to spot a subtle bug, but overall it looks
ok.
Qu Wenruo April 9, 2024, 9:40 p.m. UTC | #2
在 2024/4/10 00:27, David Sterba 写道:
> On Tue, Apr 09, 2024 at 08:03:39AM +0930, Qu Wenruo wrote:
>> [REASON FOR RFC]
>> Not all sanity checks are implemented, there is a missing check for
>> ram_bytes on non-compressed extent.
>> Because even without this series, generic/311 can generate a file extent
>> with ram_bytes larger than disk_num_bytes.
>>
>> This seems harmless, but I still want to fix it and implement a full
>> version of the em sanity check.
>>
>> [REPO]
>> https://github.com/adam900710/linux/tree/em_cleanup
>>
>> Which relies on previous changes on extent maps.
>>
>> This series introduce two new members (disk_bytenr/offset) to
>> extent_map, and removes three old members
>> (block_start/block_len/offset), finally rename one member
>> (orig_block_len -> disk_num_bytes).
>>
>> This should save us one u64 for extent_map.
>>
>> But to make things safe to migrate, I introduce extra sanity checks for
>> extent_map, and do cross check for both old and new members.
>>
>> The extra sanity checks already exposed one bug (thankfully harmless)
>> causing em::block_start to be incorrect.
>>
>> There is another bug related to bad btrfs_file_extent_item::ram_bytes,
>> which can be larger than disk_num_bytes for non-compressed file extents.
>> (Generated by generic/311 test case, but it seems to be created on-disk
>>   first)
>>
>> But so far, the patchset is fine for default fstests run.
>
> I've only paged through the patches, besides the renames there are so
> many changes where it's hard to spot a subtle bug, but overall it looks
> ok.
>

That's why this time I go sanity/cross checks immediately after adding
new members, to make sure the behavior is not changed.

So that even it's pretty hard to review, if something obviously wrong
happened, I'll hit a crash.

You will be surprised by how many crashes it triggered during the
development.

Thanks,
Qu
David Sterba April 9, 2024, 10:18 p.m. UTC | #3
On Wed, Apr 10, 2024 at 07:10:08AM +0930, Qu Wenruo wrote:
> 在 2024/4/10 00:27, David Sterba 写道:
> >>
> >> The extra sanity checks already exposed one bug (thankfully harmless)
> >> causing em::block_start to be incorrect.
> >>
> >> There is another bug related to bad btrfs_file_extent_item::ram_bytes,
> >> which can be larger than disk_num_bytes for non-compressed file extents.
> >> (Generated by generic/311 test case, but it seems to be created on-disk
> >>   first)
> >>
> >> But so far, the patchset is fine for default fstests run.
> >
> > I've only paged through the patches, besides the renames there are so
> > many changes where it's hard to spot a subtle bug, but overall it looks
> > ok.
> 
> That's why this time I go sanity/cross checks immediately after adding
> new members, to make sure the behavior is not changed.
> 
> So that even it's pretty hard to review, if something obviously wrong
> happened, I'll hit a crash.
> 
> You will be surprised by how many crashes it triggered during the
> development.

Yeah, I can imagine. If you make it work in the end then it's good.  The
self tests can verify the boundary conditions without having to create a
complete filesystem and just focused on some API so here it's easier.

The review I'd like to see is by somebody familiar with the extent maps
if it all makes sense or there are no missing test cases.

This series depends on another one that looks almost finished except
some comments in patch that adds just code comments (so no functional
changes). This kind of changes would be good to get enough testing in
for-next so please go ahead and add it in case there's not something
really serious outstanding. We can do some minor tweaks later.