btrfs-progs: handle range overlaps in extent-tree-utils.c

Add new error message template and use it to report invalid range
overlaps and do proper error handling.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2024-03-15 00:16:32 +01:00
parent bb12921b8a
commit 3b560a6649
3 changed files with 13 additions and 2 deletions

View File

@ -88,7 +88,10 @@ static int btrfs_search_overlap_extent(struct btrfs_root *root,
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
if (ret < 0)
return ret;
BUG_ON(ret == 0);
if (ret == 0) {
error_msg(ERROR_MSG_UNEXPECTED, "EXTENT_DATA found at %llu", bytenr);
return -EUCLEAN;
}
ret = btrfs_previous_extent_item(root, path, 0);
if (ret < 0)
@ -168,7 +171,13 @@ static int __btrfs_record_file_extent(struct btrfs_trans_handle *trans,
__get_extent_size(extent_root, path, &cur_start, &cur_len);
/* For convert case, this extent should be a subset of existing one. */
BUG_ON(disk_bytenr < cur_start);
if (disk_bytenr < cur_start) {
error_msg(ERROR_MSG_UNEXPECTED,
"invalid range disk_bytenr < cur_start: %llu < %llu",
disk_bytenr, cur_start);
ret = -EUCLEAN;
goto fail;
}
extent_bytenr = cur_start;
extent_num_bytes = cur_len;

View File

@ -24,6 +24,7 @@ static const char *common_error_string[] = {
[ERROR_MSG_MEMORY] = "not enough memory",
[ERROR_MSG_START_TRANS] = "failed to start transaction",
[ERROR_MSG_COMMIT_TRANS] = "failed to commit transaction",
[ERROR_MSG_UNEXPECTED] = "unexpected condition, probably corruption",
};
__attribute__ ((format (printf, 1, 2)))

View File

@ -190,6 +190,7 @@ enum common_error {
ERROR_MSG_MEMORY,
ERROR_MSG_START_TRANS,
ERROR_MSG_COMMIT_TRANS,
ERROR_MSG_UNEXPECTED,
};
__attribute__ ((format (printf, 2, 3)))