Skip to content

Commit 1cc4ada

Browse files
jinbaohongkdave
authored andcommitted
btrfs: preserve first error in btrfs_trim_fs()
When multiple block groups or devices fail during trim, preserve the first error encountered rather than the last one. The first error is typically more useful for debugging as it represents the original failure, while subsequent errors may be cascading effects. Signed-off-by: Robbie Ko <robbieko@synology.com> Signed-off-by: jinbaohong <jinbaohong@synology.com> Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 912d1c6 commit 1cc4ada

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

fs/btrfs/extent-tree.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6608,7 +6608,7 @@ static int btrfs_trim_free_extents(struct btrfs_device *device, u64 *trimmed)
66086608
* 2) trimming the unallocated space on each device
66096609
*
66106610
* This will also continue trimming even if a block group or device encounters
6611-
* an error. The return value will be the last error, or 0 if nothing bad
6611+
* an error. The return value will be the first error, or 0 if nothing bad
66126612
* happens.
66136613
*/
66146614
int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range)
@@ -6653,7 +6653,8 @@ int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range)
66536653
ret = btrfs_cache_block_group(cache, true);
66546654
if (ret) {
66556655
bg_failed++;
6656-
bg_ret = ret;
6656+
if (!bg_ret)
6657+
bg_ret = ret;
66576658
continue;
66586659
}
66596660
}
@@ -6666,15 +6667,16 @@ int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range)
66666667
trimmed += group_trimmed;
66676668
if (ret) {
66686669
bg_failed++;
6669-
bg_ret = ret;
6670+
if (!bg_ret)
6671+
bg_ret = ret;
66706672
continue;
66716673
}
66726674
}
66736675
}
66746676

66756677
if (bg_failed)
66766678
btrfs_warn(fs_info,
6677-
"failed to trim %llu block group(s), last error %d",
6679+
"failed to trim %llu block group(s), first error %d",
66786680
bg_failed, bg_ret);
66796681

66806682
mutex_lock(&fs_devices->device_list_mutex);
@@ -6687,15 +6689,16 @@ int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range)
66876689
trimmed += group_trimmed;
66886690
if (ret) {
66896691
dev_failed++;
6690-
dev_ret = ret;
6692+
if (!dev_ret)
6693+
dev_ret = ret;
66916694
continue;
66926695
}
66936696
}
66946697
mutex_unlock(&fs_devices->device_list_mutex);
66956698

66966699
if (dev_failed)
66976700
btrfs_warn(fs_info,
6698-
"failed to trim %llu device(s), last error %d",
6701+
"failed to trim %llu device(s), first error %d",
66996702
dev_failed, dev_ret);
67006703
range->len = trimmed;
67016704
if (bg_ret)

0 commit comments

Comments
 (0)