Skip to contentSkip to conversation

btrfs: don't BUG_ON() NOCOW ordered-extents with checksum list

PATCH In review Johannes Thumshirn 2 participants 2 messages Oct 4, 2024 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 btrfs: don't BUG_ON() NOCOW ordered-extents with checksum list

From: Johannes Thumshirn <[email protected]>

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.

---
Changes to v2:
* Move ASSERT() out of if () block (Filipe)
* goto 'out' after aborting the transaction (Filipe)

Changes to v1:
* Fixup if () and ASSERT() (Qu)
* Fix spelling of 'Currently'

---
 fs/btrfs/inode.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/btrfs/inode.c +6 -1
index 103ec917ca9d..ef82579dfe09 100644
@@ -3088,7 +3088,12 @@ 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));
+		ASSERT(list_empty(&ordered_extent->list));
+		if (!list_empty(&ordered_extent->list)) {
+			ret = -EINVAL;
+			btrfs_abort_transaction(trans, ret);
+			goto out;
+		}
 
 		btrfs_inode_safe_disk_i_size_write(inode, 0);
 		ret = btrfs_update_inode_fallback(trans, inode);
Signature · 1 line
2.43.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 9 lines · Johannes Thumshirn

From: Johannes Thumshirn <[email protected]>

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.

Quoted 6 lines

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

Looks good, thanks.

Quoted 34 lines

---
Changes to v2:
* Move ASSERT() out of if () block (Filipe)
* goto 'out' after aborting the transaction (Filipe)

Changes to v1:
* Fixup if () and ASSERT() (Qu)
* Fix spelling of 'Currently'

---
 fs/btrfs/inode.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/btrfs/inode.c +6 -2
index 103ec917ca9d..ef82579dfe09 100644
@@ -3088,7 +3088,12 @@ 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));
+               ASSERT(list_empty(&ordered_extent->list));
+               if (!list_empty(&ordered_extent->list)) {
+                       ret = -EINVAL;
+                       btrfs_abort_transaction(trans, ret);
+                       goto out;
+               }
 
                btrfs_inode_safe_disk_i_size_write(inode, 0);
                ret = btrfs_update_inode_fallback(trans, inode);
--

2.43.0