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)))