btrfs: don't BUG_ON() NOCOW ordered-extents with checksum list
PATCH v2 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 v1:
* Fixup if () and ASSERT() (Qu)
* Fix spelling of 'Currently'
--- fs/btrfs/inode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/btrfs/inode.c +4 -1
@@ -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);
Signature · 1 line
2.43.0
Quoted 5 lines · Johannes Thumshirn
From: Johannes Thumshirn <[email protected]>
Currently we
BUG_ON()inbtrfs_finish_one_ordered()if we finishing an ordered-extent that is flagged as NOCOW, but it's checsum list is non-empty.
Quoted 8 lines
This is clearly a logic error which we can recover from by aborting the transaction.
For developer builds which enable
CONFIG_BTRFS_ASSERT, alsoASSERT()that the list is empty.Suggested-by Filipe Manana <[email protected]>Signed-off-by Johannes Thumshirn <[email protected]>
Thanks,
Qu
Quoted 24 lines
---
Changes to v1:
* Fixup if () andASSERT()(Qu)
* Fix spelling of 'Currently'--- fs/btrfs/inode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/btrfs/inode.c +4
-1@@ -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);
Quoted 27 lines · Johannes Thumshirn
From: Johannes Thumshirn <[email protected]>
Currently we
BUG_ON()inbtrfs_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, alsoASSERT()that the list is empty.Suggested-by Filipe Manana <[email protected]>Signed-off-by Johannes Thumshirn <[email protected]>---
Changes to v1:
* Fixup if () andASSERT()(Qu)
* Fix spelling of 'Currently'--- fs/btrfs/inode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/btrfs/inode.c +0
-0
fs/btrfs/inode.c int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent) · line 3092
Quoted 6 lines
fs/btrfs/inode.c +2
-1@@ -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));
I find this confusing and not so easy to grasp immediately. It's the same as older places where we have:
if (unexpected condition) {
ASSERT(0);
(...)
}
I find it more natural and less confusing to just do:
ASSERT(list_empty(&ordered_extent->list));
if (unlikely(!list_empty(&ordered_extent->list))) {
ret = -EINVAL;
btrfs_abort_transaction(trans, ret);
goto out;
}fs/btrfs/inode.c int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent) · line 3094
Quoted 2 lines
fs/btrfs/inode.c +2
-0+btrfs_abort_transaction (trans, -EINVAL ); + }
This also misses setting 'ret' to the error and the goto into the label 'out', as I've placed in the example above.
Thanks.
Quoted 7 lines
fs/btrfs/inode.c +0
-1btrfs_inode_safe_disk_i_size_write (inode,0 ); ret =btrfs_update_inode_fallback (trans, inode); --2.43.0