btrfs-progs: check: change commit condition in fixup_extent_refs()
PATCH 1/1 btrfs-progs: check: change commit condition in fixup_extent_refs()
This patch fixes potential bugs in fixup_extent_refs(). If btrfs_start_transaction() fails in some way and returns error ptr, It goes to out logic. But old code checkes whether it is null and it calls commit. This patch solves the problem with change the condition to checks if it is error by IS_ERR().
Issue: #409
--- check/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
check/main.c +1 -1
@@ -7735,7 +7735,7 @@ static int fixup_extent_refs(struct cache_tree *extent_cache, goto out; } out: -if (trans) { +if (!IS_ERR (trans)) {int err =btrfs_commit_transaction (trans, gfs_info->extent_root);if (!ret)
Signature · 1 line
2.25.1
Quoted 18 lines · Sidong Yang
This patch fixes potential bugs in
fixup_extent_refs(). Ifbtrfs_start_transaction()fails in some way and returns error ptr, It goes to out logic. But old code checkes whether it is null and it calls commit. This patch solves the problem with change the condition to checks if it is error byIS_ERR().Issue: #409
Signed-off-by Sidong Yang <[email protected]>--- check/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)check/main.c +0
-0
check/main.c static int fixup_extent_refs(struct cache_tree *extent_cache, · line 7738
Quoted 5 lines
check/main.c +1
-1@@ -7735,7 +7735,7 @@ static int fixup_extent_refs(struct cache_tree *extent_cache, goto out; } out: -if (trans) { +if (!IS_ERR (trans)) {
Actually I think we want to commit the transaction only if ret is not error, otherwise we run the risk of committing partial changes to the fs.
Quoted 4 lines
check/main.c +0
-0int err =btrfs_commit_transaction (trans, gfs_info->extent_root);if (!ret)
Quoted 16 lines · Nikolay Borisov
Quoted 13 lines · Sidong Yang
This patch fixes potential bugs in
fixup_extent_refs(). Ifbtrfs_start_transaction()fails in some way and returns error ptr, It goes to out logic. But old code checkes whether it is null and it calls commit. This patch solves the problem with change the condition to checks if it is error byIS_ERR().Issue: #409
Signed-off-by Sidong Yang <[email protected]>--- check/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines
check/main.c static int fixup_extent_refs(struct cache_tree *extent_cache, · line 7738
Quoted 10 lines
check/main.c +1
-1@@ -7735,7 +7735,7 @@ static int fixup_extent_refs(struct cache_tree *extent_cache, goto out; } out: -if (trans) { +if (!IS_ERR (trans)) {Actually I think we want to commit the transaction only if ret is not error, otherwise we run the risk of committing partial changes to the fs.
I agree. If ret is error, committing should not be happen. But I think it needs to check trans.
I wonder that if ret is error but trans is okay, trans needs to be aborted by calling btrfs_abort_transaction()?
Quoted 5 lines
Quoted 5 lines
check/main.c +0
-0int err =btrfs_commit_transaction (trans, gfs_info->extent_root);if (!ret)
Quoted 31 lines · Sidong Yang
Quoted 16 lines · Nikolay Borisov
Quoted 13 lines · Sidong Yang
This patch fixes potential bugs in
fixup_extent_refs(). Ifbtrfs_start_transaction()fails in some way and returns error ptr, It goes to out logic. But old code checkes whether it is null and it calls commit. This patch solves the problem with change the condition to checks if it is error byIS_ERR().Issue: #409
Signed-off-by Sidong Yang <[email protected]>--- check/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 13 lines
check/main.c static int fixup_extent_refs(struct cache_tree *extent_cache, · line 7738
Quoted 10 lines
check/main.c +1
-1@@ -7735,7 +7735,7 @@ static int fixup_extent_refs(struct cache_tree *extent_cache, goto out; } out: -if (trans) { +if (!IS_ERR (trans)) {Actually I think we want to commit the transaction only if ret is not error, otherwise we run the risk of committing partial changes to the fs.
Quoted 5 lines
I agree. If ret is error, committing should not be happen. But I think it needs to check trans.
I wonder that if ret is error but trans is okay, trans needs to be aborted by calling
btrfs_abort_transaction()?
This is the general way errors are handled in kernel. Currently abort trans in progs simply sets transaction_aborted = error and commit_transaction checks if this is set and returns an EROFS. Every failure site in this function should ideally have a btrfs_abort_transaction, because in the future we probably want to add code which would yield the exact call site where a transaction abort occurred.
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
check/main.c +0
-0int err =btrfs_commit_transaction (trans, gfs_info->extent_root);if (!ret)
Quoted 40 lines · Nikolay Borisov
Quoted 31 lines · Sidong Yang
Quoted 16 lines · Nikolay Borisov
Quoted 13 lines · Sidong Yang
This patch fixes potential bugs in
fixup_extent_refs(). Ifbtrfs_start_transaction()fails in some way and returns error ptr, It goes to out logic. But old code checkes whether it is null and it calls commit. This patch solves the problem with change the condition to checks if it is error byIS_ERR().Issue: #409
Signed-off-by Sidong Yang <[email protected]>--- check/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 13 lines
check/main.c static int fixup_extent_refs(struct cache_tree *extent_cache, · line 7738
Quoted 10 lines
check/main.c +1
-1@@ -7735,7 +7735,7 @@ static int fixup_extent_refs(struct cache_tree *extent_cache, goto out; } out: -if (trans) { +if (!IS_ERR (trans)) {Actually I think we want to commit the transaction only if ret is not error, otherwise we run the risk of committing partial changes to the fs.
Quoted 5 lines
I agree. If ret is error, committing should not be happen. But I think it needs to check trans.
I wonder that if ret is error but trans is okay, trans needs to be aborted by calling
btrfs_abort_transaction()?
Quoted 7 lines
This is the general way errors are handled in kernel. Currently abort trans in progs simply sets
transaction_aborted= error andcommit_transactionchecks if this is set and returns an EROFS. Every failure site in this function should ideally have abtrfs_abort_transaction, because in the future we probably want to add code which would yield the exact call site where a transaction abort occurred.
Okay, Thanks for detailed description. I understood that we don't need to call btrfs_abort_transaction() in the function.
I would write new version for this patch.
Thanks again for helping me.
Thanks,
Sidong
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
check/main.c +0
-0int err =btrfs_commit_transaction (trans, gfs_info->extent_root);if (!ret)