diff options
author | David Sterba <dsterba@suse.com> | 2024-03-15 00:16:32 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2024-03-15 00:16:32 +0100 |
commit | 3b560a6649c3f1d0a61c2e3c25b5aad1131154b6 (patch) | |
tree | 89a8e41186e7d01d448c11c066a00fa62c9c0ce8 | |
parent | bb12921b8af7a101f50c08f94807a3238fc01566 (diff) | |
download | btrfs-progs-3b560a6649c3f1d0a61c2e3c25b5aad1131154b6.tar.gz |
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>
-rw-r--r-- | common/extent-tree-utils.c | 13 | ||||
-rw-r--r-- | common/messages.c | 1 | ||||
-rw-r--r-- | common/messages.h | 1 |
3 files changed, 13 insertions, 2 deletions
diff --git a/common/extent-tree-utils.c b/common/extent-tree-utils.c index 736b21c6..34c7e509 100644 --- a/common/extent-tree-utils.c +++ b/common/extent-tree-utils.c @@ -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; diff --git a/common/messages.c b/common/messages.c index 0cdf56a7..2970122a 100644 --- a/common/messages.c +++ b/common/messages.c @@ -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))) diff --git a/common/messages.h b/common/messages.h index 4ade6d25..511b949c 100644 --- a/common/messages.h +++ b/common/messages.h @@ -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))) |