Re: [PATCH v2] btrfs: don't BUG_ON() NOCOW ordered-extents with checksum list

From: Qu Wenruo
Date: Fri Oct 04 2024 - 06:57:17 EST




在 2024/10/4 20:23, Johannes Thumshirn 写道:
From: Johannes Thumshirn <johannes.thumshirn@xxxxxxx>

Currently we BUG_ON() in btrfs_finish_one_ordered() if we finishing an
ordered-extent that is flagged as NOCOW, but it's checsum list is non-empty.

This is clearly a logic error which we can recover from by aborting the
transaction.

For developer builds which enable CONFIG_BTRFS_ASSERT, also ASSERT() that the
list is empty.

Suggested-by: Filipe Manana <fdmanana@xxxxxxxx>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@xxxxxxx>

Reviewed-by: Qu Wenruo <wqu@xxxxxxxx>

Thanks,
Qu
---
Changes to v1:
* Fixup if () and ASSERT() (Qu)
* Fix spelling of 'Currently'
---
fs/btrfs/inode.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 103ec917ca9d..e57b73943ab8 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3088,7 +3088,10 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)

if (test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags)) {
/* Logic error */
- BUG_ON(!list_empty(&ordered_extent->list));
+ if (!list_empty(&ordered_extent->list)) {
+ ASSERT(list_empty(&ordered_extent->list));
+ btrfs_abort_transaction(trans, -EINVAL);
+ }

btrfs_inode_safe_disk_i_size_write(inode, 0);
ret = btrfs_update_inode_fallback(trans, inode);