Skip to content

Commit 9a0d619

Browse files
adam900710kdave
authored andcommitted
btrfs: enhance error messages for delalloc range failure
When running emulated write error tests like generic/475, we can hit error messages like this: BTRFS error (device dm-12 state EA): run_delalloc_nocow failed, root=596 inode=264 start=1605632 len=73728: -5 BTRFS error (device dm-12 state EA): failed to run delalloc range, root=596 ino=264 folio=1605632 submit_bitmap=0-7 start=1605632 len=73728: -5 Which is normally buried by direct IO error messages. However above error messages are not enough to determine which is the real range that caused the error. Considering we can have multiple different extents in one delalloc range (e.g. some COW extents along with some NOCOW extents), just outputting the error at the end of run_delalloc_nocow() is not enough. To enhance the error messages: - Remove the rate limit on the existing error messages In the generic/475 example, most error messages are from direct IO, not really from the delalloc range. Considering how useful the delalloc range error messages are, we don't want they to be rate limited. - Add extra @cur_offset output for cow_file_range() - Add extra variable output for run_delalloc_nocow() This is especially important for run_delalloc_nocow(), as there are extra error paths where we can hit error without into nocow_one_range() nor fallback_to_cow(). - Add an error message for nocow_one_range() That's the missing part. For fallback_to_cow(), we have error message from cow_file_range() already. - Constify the @len and @EnD local variables for nocow_one_range() This makes it much easier to make sure @len and @EnD are not modified at runtime. Reviewed-by: Boris Burkov <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 2fac4ed commit 9a0d619

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

fs/btrfs/inode.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,10 +1534,11 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
15341534
btrfs_qgroup_free_data(inode, NULL, start + cur_alloc_size,
15351535
end - start - cur_alloc_size + 1, NULL);
15361536
}
1537-
btrfs_err_rl(fs_info,
1538-
"%s failed, root=%llu inode=%llu start=%llu len=%llu: %d",
1539-
__func__, btrfs_root_id(inode->root),
1540-
btrfs_ino(inode), orig_start, end + 1 - orig_start, ret);
1537+
btrfs_err(fs_info,
1538+
"%s failed, root=%llu inode=%llu start=%llu len=%llu cur_offset=%llu cur_alloc_size=%llu: %d",
1539+
__func__, btrfs_root_id(inode->root),
1540+
btrfs_ino(inode), orig_start, end + 1 - orig_start,
1541+
start, cur_alloc_size, ret);
15411542
return ret;
15421543
}
15431544

@@ -1969,8 +1970,8 @@ static int nocow_one_range(struct btrfs_inode *inode, struct folio *locked_folio
19691970
u64 file_pos, bool is_prealloc)
19701971
{
19711972
struct btrfs_ordered_extent *ordered;
1972-
u64 len = nocow_args->file_extent.num_bytes;
1973-
u64 end = file_pos + len - 1;
1973+
const u64 len = nocow_args->file_extent.num_bytes;
1974+
const u64 end = file_pos + len - 1;
19741975
int ret = 0;
19751976

19761977
btrfs_lock_extent(&inode->io_tree, file_pos, end, cached);
@@ -2017,8 +2018,13 @@ static int nocow_one_range(struct btrfs_inode *inode, struct folio *locked_folio
20172018
* We do not clear the folio Dirty flags because they are set and
20182019
* cleaered by the caller.
20192020
*/
2020-
if (ret < 0)
2021+
if (ret < 0) {
20212022
btrfs_cleanup_ordered_extents(inode, file_pos, len);
2023+
btrfs_err(inode->root->fs_info,
2024+
"%s failed, root=%lld inode=%llu start=%llu len=%llu: %d",
2025+
__func__, btrfs_root_id(inode->root), btrfs_ino(inode),
2026+
file_pos, len, ret);
2027+
}
20222028
return ret;
20232029
}
20242030

@@ -2306,10 +2312,11 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
23062312
btrfs_qgroup_free_data(inode, NULL, untouched_start, untouched_len, NULL);
23072313
}
23082314
btrfs_free_path(path);
2309-
btrfs_err_rl(fs_info,
2310-
"%s failed, root=%llu inode=%llu start=%llu len=%llu: %d",
2311-
__func__, btrfs_root_id(inode->root),
2312-
btrfs_ino(inode), start, end + 1 - start, ret);
2315+
btrfs_err(fs_info,
2316+
"%s failed, root=%llu inode=%llu start=%llu len=%llu cur_offset=%llu oe_cleanup=%llu oe_cleanup_len=%llu untouched_start=%llu untouched_len=%llu: %d",
2317+
__func__, btrfs_root_id(inode->root), btrfs_ino(inode),
2318+
start, end + 1 - start, cur_offset, oe_cleanup_start, oe_cleanup_len,
2319+
untouched_start, untouched_len, ret);
23132320
return ret;
23142321
}
23152322

0 commit comments

Comments
 (0)