Transaction aborts in free-space-tree.c
David Sterba
maintainercover Transaction aborts in free-space-tree.c
Fix the transaction abort pattern in free-space-tree, it's been there from the beginning and not conforming to the pattern we use elsewhere.
David Sterba (4):
btrfs: move transaction aborts to the error site in
convert_free_space_to_bitmaps()
btrfs: move transaction aborts to the error site in
convert_free_space_to_extents()
btrfs: move transaction aborts to the error site in
remove_from_free_space_tree()
btrfs: move transaction aborts to the error site in
add_to_free_space_tree()
fs/btrfs/free-space-tree.c | 48 +++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 16 deletions(-)
Signature · 1 line
2.49.0
David Sterba
maintainerPATCH 1/4 btrfs: move transaction aborts to the error site in convert_free_space_to_bitmaps()
Transaction aborts should be done next to the place the error happens, which was not done in convert_free_space_to_bitmaps(). The DEBUG_WARN() is removed because we get the abort message.
--- fs/btrfs/free-space-tree.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
fs/btrfs/free-space-tree.c +12 -6
@@ -223,6 +223,7 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans, bitmap =alloc_bitmap (bitmap_size);if (!bitmap) { ret = -ENOMEM ; +btrfs_abort_transaction (trans, ret); goto out; }
@@ -235,8 +236,10 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,while (!done) { ret =btrfs_search_prev_slot (trans, root, &key, path,-1 ,1 ); -if (ret) +if (ret) { +btrfs_abort_transaction (trans, ret); goto out; + } leaf = path->nodes[0 ]; nr =0 ;
@@ -271,14 +274,17 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans, } ret =btrfs_del_items (trans, root, path, path->slots[0 ], nr); -if (ret) +if (ret) { +btrfs_abort_transaction (trans, ret); goto out; + }btrfs_release_path (path); } info =search_free_space_info (trans, block_group, path,1 );if (IS_ERR (info)) { ret =PTR_ERR (info); +btrfs_abort_transaction (trans, ret); goto out; } leaf = path->nodes[0 ];
@@ -293,8 +299,8 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,"incorrect extent count for %llu; counted %u, expected %u" , block_group->start, extent_count, expected_extent_count); -DEBUG_WARN (); ret = -EIO ; +btrfs_abort_transaction (trans, ret); goto out; }
@@ -315,8 +321,10 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans, ret =btrfs_insert_empty_item (trans, root, path, &key, data_size); -if (ret) +if (ret) { +btrfs_abort_transaction (trans, ret); goto out; + } leaf = path->nodes[0 ]; ptr =btrfs_item_ptr_offset (leaf, path->slots[0 ]);
@@ -331,8 +339,6 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans, ret =0 ; out:kvfree (bitmap); -if (ret) -btrfs_abort_transaction (trans, ret);return ret; }
Signature · 1 line
2.49.0
David Sterba
maintainerPATCH 2/4 btrfs: move transaction aborts to the error site in convert_free_space_to_extents()
In reply to David SterbaTransaction aborts should be done next to the place the error happens, which was not done in convert_free_space_to_extents().
--- fs/btrfs/free-space-tree.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
fs/btrfs/free-space-tree.c +12 -6
@@ -364,6 +364,7 @@ int convert_free_space_to_extents(struct btrfs_trans_handle *trans, bitmap =alloc_bitmap (bitmap_size);if (!bitmap) { ret = -ENOMEM ; +btrfs_abort_transaction (trans, ret); goto out; }
@@ -376,8 +377,10 @@ int convert_free_space_to_extents(struct btrfs_trans_handle *trans,while (!done) { ret =btrfs_search_prev_slot (trans, root, &key, path,-1 ,1 ); -if (ret) +if (ret) { +btrfs_abort_transaction (trans, ret); goto out; + } leaf = path->nodes[0 ]; nr =0 ;
@@ -418,14 +421,17 @@ int convert_free_space_to_extents(struct btrfs_trans_handle *trans, } ret =btrfs_del_items (trans, root, path, path->slots[0 ], nr); -if (ret) +if (ret) { +btrfs_abort_transaction (trans, ret); goto out; + }btrfs_release_path (path); } info =search_free_space_info (trans, block_group, path,1 );if (IS_ERR (info)) { ret =PTR_ERR (info); +btrfs_abort_transaction (trans, ret); goto out; } leaf = path->nodes[0 ];
@@ -447,8 +453,10 @@ int convert_free_space_to_extents(struct btrfs_trans_handle *trans, key.offset = (end_bit - start_bit) * block_group->fs_info->sectorsize; ret =btrfs_insert_empty_item (trans, root, path, &key,0 ); -if (ret) +if (ret) { +btrfs_abort_transaction (trans, ret); goto out; + }btrfs_release_path (path); extent_count++;
@@ -461,16 +469,14 @@ int convert_free_space_to_extents(struct btrfs_trans_handle *trans,"incorrect extent count for %llu; counted %u, expected %u" , block_group->start, extent_count, expected_extent_count); -DEBUG_WARN (); ret = -EIO ; +btrfs_abort_transaction (trans, ret); goto out; } ret =0 ; out:kvfree (bitmap); -if (ret) -btrfs_abort_transaction (trans, ret);return ret; }
Signature · 1 line
2.49.0
David Sterba
maintainerPATCH 3/4 btrfs: move transaction aborts to the error site in remove_from_free_space_tree()
In reply to David SterbaTransaction aborts should be done next to the place the error happens, which was not done in remove_from_free_space_tree().
--- fs/btrfs/free-space-tree.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/btrfs/free-space-tree.c +4 -2
@@ -850,6 +850,7 @@ int remove_from_free_space_tree(struct btrfs_trans_handle *trans, path =btrfs_alloc_path ();if (!path) { ret = -ENOMEM ; +btrfs_abort_transaction (trans, ret); goto out; }
@@ -857,6 +858,7 @@ int remove_from_free_space_tree(struct btrfs_trans_handle *trans,if (!block_group) {DEBUG_WARN ("no block group found for start=%llu" , start); ret = -ENOENT ; +btrfs_abort_transaction (trans, ret); goto out; }
@@ -864,12 +866,12 @@ int remove_from_free_space_tree(struct btrfs_trans_handle *trans, ret =__remove_from_free_space_tree (trans, block_group, path, start, size);mutex_unlock (&block_group->free_space_lock); +if (ret) +btrfs_abort_transaction (trans, ret);btrfs_put_block_group (block_group); out:btrfs_free_path (path); -if (ret) -btrfs_abort_transaction (trans, ret);return ret; }
Signature · 1 line
2.49.0
David Sterba
maintainerPATCH 4/4 btrfs: move transaction aborts to the error site in add_to_free_space_tree()
In reply to David SterbaTransaction aborts should be done next to the place the error happens, which was not done in add_to_free_space_tree().
--- fs/btrfs/free-space-tree.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/btrfs/free-space-tree.c +4 -2
@@ -1045,6 +1045,7 @@ int add_to_free_space_tree(struct btrfs_trans_handle *trans, path =btrfs_alloc_path ();if (!path) { ret = -ENOMEM ; +btrfs_abort_transaction (trans, ret); goto out; }
@@ -1052,18 +1053,19 @@ int add_to_free_space_tree(struct btrfs_trans_handle *trans,if (!block_group) {DEBUG_WARN ("no block group found for start=%llu" , start); ret = -ENOENT ; +btrfs_abort_transaction (trans, ret); goto out; }mutex_lock (&block_group->free_space_lock); ret =__add_to_free_space_tree (trans, block_group, path, start, size);mutex_unlock (&block_group->free_space_lock); +if (ret) +btrfs_abort_transaction (trans, ret);btrfs_put_block_group (block_group); out:btrfs_free_path (path); -if (ret) -btrfs_abort_transaction (trans, ret);return ret; }
Signature · 1 line
2.49.0
Quoted 14 lines · David Sterba
Fix the transaction abort pattern in free-space-tree, it's been there from the beginning and not conforming to the pattern we use elsewhere.
David Sterba (4):
btrfs: move transaction aborts to the error site in
convert_free_space_to_bitmaps()
btrfs: move transaction aborts to the error site in
convert_free_space_to_extents()
btrfs: move transaction aborts to the error site in
remove_from_free_space_tree()
btrfs: move transaction aborts to the error site in
add_to_free_space_tree()
Quoted 2 lines
fs/btrfs/free-space-tree.c | 48 +++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 16 deletions(-)
This looks like unnecessary duplicating the code. Shall we rather go the other way around?
Quoted 5 lines
--
2.49.0
Quoted 15 lines · Daniel Vacek
Quoted 14 lines · David Sterba
Fix the transaction abort pattern in free-space-tree, it's been there from the beginning and not conforming to the pattern we use elsewhere.
David Sterba (4):
btrfs: move transaction aborts to the error site in
convert_free_space_to_bitmaps()
btrfs: move transaction aborts to the error site in
convert_free_space_to_extents()
btrfs: move transaction aborts to the error site in
remove_from_free_space_tree()
btrfs: move transaction aborts to the error site in
add_to_free_space_tree()
Quoted 5 lines
Quoted 2 lines
fs/btrfs/free-space-tree.c | 48 +++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 16 deletions(-)This looks like unnecessary duplicating the code. Shall we rather go the other way around?
What do you mean? There's some smilarity among the functions so yeah the add/remove pairs can be merged to one, but this is orthogonal to the transaction abot calls.
Quoted 20 lines · David Sterba
Quoted 18 lines · Daniel Vacek
Quoted 16 lines · David Sterba
Fix the transaction abort pattern in free-space-tree, it's been there from the beginning and not conforming to the pattern we use elsewhere.
David Sterba (4):
btrfs: move transaction aborts to the error site in
convert_free_space_to_bitmaps()
btrfs: move transaction aborts to the error site in
convert_free_space_to_extents()
btrfs: move transaction aborts to the error site in
remove_from_free_space_tree()
btrfs: move transaction aborts to the error site in
add_to_free_space_tree()fs/btrfs/free-space-tree.c | 48 +++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 16 deletions(-)
Quoted 6 lines
Quoted 2 lines
This looks like unnecessary duplicating the code. Shall we rather go the other way around?
What do you mean? There's some smilarity among the functions so yeah the add/remove pairs can be merged to one, but this is orthogonal to the transaction abot calls.
Not that. I meant the code looks simpler without these patches. If this is the pattern used elsewhere, maybe we should rather change elsewhere to follow free-space-tree.c?
Quoted 24 lines · Daniel Vacek
Quoted 23 lines · David Sterba
Quoted 20 lines · Daniel Vacek
Quoted 14 lines · David Sterba
Fix the transaction abort pattern in free-space-tree, it's been there from the beginning and not conforming to the pattern we use elsewhere.
David Sterba (4):
btrfs: move transaction aborts to the error site in
convert_free_space_to_bitmaps()
btrfs: move transaction aborts to the error site in
convert_free_space_to_extents()
btrfs: move transaction aborts to the error site in
remove_from_free_space_tree()
btrfs: move transaction aborts to the error site in
add_to_free_space_tree()Quoted 2 lines
fs/btrfs/free-space-tree.c | 48 +++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 16 deletions(-)This looks like unnecessary duplicating the code. Shall we rather go the other way around?
Quoted 7 lines
Quoted 3 lines
What do you mean? There's some smilarity among the functions so yeah the add/remove pairs can be merged to one, but this is orthogonal to the transaction abot calls.
Not that. I meant the code looks simpler without these patches. If this is the pattern used elsewhere, maybe we should rather change elsewhere to follow
free-space-tree.c?
"Please keep all transaction abort exactly at the place where they happen and do not merge them to one. This pattern should be used everywhere and is important when debugging because we can pinpoint the line in the code from the syslog message and do not have to guess which way it got to the merged call."
Quoted 34 lines · David Sterba
Quoted 24 lines · Daniel Vacek
Quoted 23 lines · David Sterba
Quoted 20 lines · Daniel Vacek
Quoted 14 lines · David Sterba
Fix the transaction abort pattern in free-space-tree, it's been there from the beginning and not conforming to the pattern we use elsewhere.
David Sterba (4):
btrfs: move transaction aborts to the error site in
convert_free_space_to_bitmaps()
btrfs: move transaction aborts to the error site in
convert_free_space_to_extents()
btrfs: move transaction aborts to the error site in
remove_from_free_space_tree()
btrfs: move transaction aborts to the error site in
add_to_free_space_tree()Quoted 2 lines
fs/btrfs/free-space-tree.c | 48 +++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 16 deletions(-)This looks like unnecessary duplicating the code. Shall we rather go the other way around?
Quoted 7 lines
Quoted 3 lines
What do you mean? There's some smilarity among the functions so yeah the add/remove pairs can be merged to one, but this is orthogonal to the transaction abot calls.
Not that. I meant the code looks simpler without these patches. If this is the pattern used elsewhere, maybe we should rather change elsewhere to follow
free-space-tree.c?
Quoted 7 lines
"Please keep all transaction abort exactly at the place where they happen and do not merge them to one. This pattern should be used everywhere and is important when debugging because we can pinpoint the line in the code from the syslog message and do not have to guess which way it got to the merged call."
/*
* Call btrfs_abort_transaction as early as possible when an error condition is
* detected, that way the exact stack trace is reported for some errors. */
#define btrfs_abort_transaction(trans, error)
Indeed, that's clever. It was not clear from the commit message why this pattern is preferred.
Thanks for the explanation.