Skip to contentSkip to conversation

btrfs-progs: Preserve first error in loop of check_extent_refs()

PATCH In review tchou 3 participants 5 messages Feb 12, 2025 – Feb 13, 2025 Btrfs file system

lore
Share & tools
lore

tchou

author
#0 lore raw

PATCH 1/1 btrfs-progs: Preserve first error in loop of check_extent_refs()

Previously, the err variable inside the loop was updated with cur_err on every iteration, regardless of whether cur_err indicated an error. This caused a bug where an earlier error could be overwritten by a later successful iteration, losing the original failure.

This fix ensures that err retains the first encountered error and is not reset by subsequent successful iterations.

---
 check/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
check/main.c +2 -1
index 6290c6d4..974ff685 100644
@@ -8322,7 +8322,8 @@ static int check_extent_refs(struct btrfs_root *root,
 			cur_err = 1;
 		}
 next:
-		err = cur_err;
+		if (cur_err)
+			err = cur_err;
 		remove_cache_extent(extent_cache, cache);
 		free_all_extent_backrefs(rec);
 		if (!init_extent_tree && opt_check_repair && (!cur_err || fix))
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · tchou

Previously, the err variable inside the loop was updated with cur_err on every iteration, regardless of whether cur_err indicated an error. This caused a bug where an earlier error could be overwritten by a later successful iteration, losing the original failure.

This fix ensures that err retains the first encountered error and is not reset by subsequent successful iterations.

SoB line please, otherwise looks good to me.

And if it's a case you hit in real world, mind to extract or craft a minimal image as a test case?

Thanks,
Qu

Quoted 18 lines
---
  check/main.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
check/main.c +2 -1
index 6290c6d4..974ff685 100644
@@ -8322,7 +8322,8 @@ static int check_extent_refs(struct btrfs_root *root,
  			cur_err = 1;
  		}
  next:
-		err = cur_err;
+		if (cur_err)
+			err = cur_err;
  		remove_cache_extent(extent_cache, cache);
  		free_all_extent_backrefs(rec);
  		if (!init_extent_tree && opt_check_repair && (!cur_err || fix))
#2 lore raw
Quoted 10 lines · Qu Wenruo
Quoted 7 lines · tchou

Previously, the err variable inside the loop was updated with cur_err on every iteration, regardless of whether cur_err indicated an error. This caused a bug where an earlier error could be overwritten by a later successful iteration, losing the original failure.

This fix ensures that err retains the first encountered error and is not reset by subsequent successful iterations.

SoB line please, otherwise looks good to me.

For btrfs-progs teh SoB line is optional, I think it's mentioned in the README. It makes sense for kernel to insist on the attribution and some trace to real people but btrfs-progs are much smaller and I think it's better to lower the contribution barriers.

Quoted 1 line

Thanks, feel free to add the commit to devel.

Quoted 2 lines

And if it's a case you hit in real world, mind to extract or craft a minimal image as a test case?

From my experience, casual contributors will rarely write tests and I do not do that when I'm sending a fix or reporting a problem to other projects. In order to keep the track of that it may be best to open an issue, unless you or me will write the test case.

author
#3 lore raw

David Sterba 於 2025/2/13 07:29 寫道:

Quoted 10 lines · Qu Wenruo
Quoted 9 lines · tchou
Quoted 7 lines

Previously, the err variable inside the loop was updated with cur_err on every iteration, regardless of whether cur_err indicated an error. This caused a bug where an earlier error could be overwritten by a later successful iteration, losing the original failure.

This fix ensures that err retains the first encountered error and is not reset by subsequent successful iterations.

Quoted 6 lines
Quoted 1 line

SoB line please, otherwise looks good to me.

For btrfs-progs teh SoB line is optional, I think it's mentioned in the README. It makes sense for kernel to insist on the attribution and some trace to real people but btrfs-progs are much smaller and I think it's better to lower the contribution barriers.

Thanks, I will add it next time send patch.

Quoted 5 lines
Quoted 2 lines

Thanks, feel free to add the commit to devel.

Do I need to send PR in github of btrfs-progs, or maintainer will add the commit directly?

Quoted 7 lines
Quoted 2 lines

And if it's a case you hit in real world, mind to extract or craft a minimal image as a test case?

From my experience, casual contributors will rarely write tests and I do
not do that when I'm sending a fix or reporting a problem to other projects. In order to keep the track of that it may be best to open an issue, unless you or me will write the test case.

Not the real case, but fake case by modifying the bytenr of extent to wrong number when test the correctness of function we develop with backref check. I think every backpointer mismatch case can test it.

Thanks, TCHou

#4 lore raw
Quoted 21 lines · tchou

David Sterba 於 2025/2/13 07:29 寫道:

Quoted 10 lines · Qu Wenruo
Quoted 9 lines · tchou
Quoted 7 lines

Previously, the err variable inside the loop was updated with cur_err on every iteration, regardless of whether cur_err indicated an error. This caused a bug where an earlier error could be overwritten by a later successful iteration, losing the original failure.

This fix ensures that err retains the first encountered error and is not reset by subsequent successful iterations.

Quoted 6 lines
Quoted 1 line

SoB line please, otherwise looks good to me.

For btrfs-progs teh SoB line is optional, I think it's mentioned in the README. It makes sense for kernel to insist on the attribution and some trace to real people but btrfs-progs are much smaller and I think it's better to lower the contribution barriers.

Thanks, I will add it next time send patch.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Thanks, feel free to add the commit to devel.

Do I need to send PR in github of btrfs-progs, or maintainer will add the commit directly?

No worry, feel free to use either/both mail or github pull request.

We can handle both at merge time.

(In fact, I send mail for personal accounting, and github PR for real merge)

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

And if it's a case you hit in real world, mind to extract or craft a minimal image as a test case?

Quoted 8 lines
Quoted 4 lines

 From my experience, casual contributors will rarely write tests and I do not do that when I'm sending a fix or reporting a problem to other projects. In order to keep the track of that it may be best to open an issue, unless you or me will write the test case.

Not the real case, but fake case by modifying the bytenr of extent to wrong number when test the correctness of function we develop with backref check. I think every backpointer mismatch case can test it.

Thanks, let me try to craft a minimal image with this method.

Thanks,
Qu

Quoted 3 lines

Thanks, TCHou