Allow read_tree_block() and read_node_slot() to return error pointer.
This should help caller to get more specified error number.
For existing callers, change (!eb) judgmentt to
(!extent_buffer_uptodate(eb)) to keep the compatibility, and for caller
missing the check, use PTR_ERR(eb) if possible.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
BUG_ON(!ref->wanted_disk_byte);
eb = read_tree_block(fs_info->tree_root, ref->wanted_disk_byte,
fs_info->tree_root->leafsize, 0);
- if (!eb || !extent_buffer_uptodate(eb)) {
+ if (!extent_buffer_uptodate(eb)) {
free_extent_buffer(eb);
return -EIO;
}
ref->level);
eb = read_tree_block(fs_info->extent_root,
ref->parent, bsz, 0);
- if (!eb || !extent_buffer_uptodate(eb)) {
+ if (!extent_buffer_uptodate(eb)) {
free_extent_buffer(eb);
ret = -EIO;
goto out;
tmp = read_tree_block(root, cur_blocknr,
btrfs_level_size(root, level - 1),
btrfs_node_ptr_generation(b, i));
- if (!tmp) {
+ if (!extent_buffer_uptodate(tmp)) {
fprintf(stderr, "Failed to read blocknr %Lu\n",
btrfs_node_blockptr(b, i));
continue;
struct extent_buffer *eb;
eb = read_tree_block(root, bytenr, root->leafsize, 0);
- if (!eb)
+ if (!extent_buffer_uptodate(eb))
return -EIO;;
corrupt_keys(NULL, root, eb);
next = read_tree_block(root, btrfs_node_blockptr(eb, i),
root->leafsize,
btrfs_node_ptr_generation(eb, i));
- if (!next)
+ if (!extent_buffer_uptodate(next))
continue;
btrfs_corrupt_extent_tree(trans, root, next);
free_extent_buffer(next);
}
eb = read_tree_block(root, block, root->leafsize, 0);
- if (!eb) {
+ if (!extent_buffer_uptodate(eb)) {
fprintf(stderr, "Couldn't read in tree block %s\n", field);
return -EINVAL;
}
btrfs_node_blockptr(eb, i),
size,
btrfs_node_ptr_generation(eb, i));
+ if (!extent_buffer_uptodate(next))
+ continue;
if (btrfs_is_leaf(next) &&
btrfs_header_level(eb) != 1)
BUG();
block_only,
root->leafsize, 0);
- if (leaf && btrfs_header_level(leaf) != 0) {
+ if (extent_buffer_uptodate(leaf) &&
+ btrfs_header_level(leaf) != 0) {
free_extent_buffer(leaf);
leaf = NULL;
}
block_only,
root->nodesize, 0);
}
- if (!leaf) {
+ if (!extent_buffer_uptodate(leaf)) {
fprintf(stderr, "failed to read %llu\n",
(unsigned long long)block_only);
goto close_root;
while (!md->data && size > 0) {
u64 this_read = min(blocksize, size);
eb = read_tree_block(md->root, start, this_read, 0);
- if (!eb) {
+ if (!extent_buffer_uptodate(eb)) {
free(async->buffer);
free(async);
fprintf(stderr,
ri = btrfs_item_ptr(eb, i, struct btrfs_root_item);
bytenr = btrfs_disk_root_bytenr(eb, ri);
tmp = read_tree_block(root, bytenr, root->leafsize, 0);
- if (!tmp) {
+ if (!extent_buffer_uptodate(tmp)) {
fprintf(stderr,
"Error reading log root block\n");
return -EIO;
} else {
bytenr = btrfs_node_blockptr(eb, i);
tmp = read_tree_block(root, bytenr, root->leafsize, 0);
- if (!tmp) {
+ if (!extent_buffer_uptodate(tmp)) {
fprintf(stderr, "Error reading log block\n");
return -EIO;
}
reada_walk_down(root, cur, path->slots[*level]);
next = read_tree_block(root, bytenr, blocksize,
ptr_gen);
- if (!next) {
+ if (!extent_buffer_uptodate(next)) {
struct btrfs_key node_key;
btrfs_node_key_to_cpu(path->nodes[*level],
*/
tmp = read_tree_block(fs_info->extent_root, bytenr,
leafsize, 0);
- if (!tmp) {
+ if (!extent_buffer_uptodate(tmp)) {
fprintf(stderr, "Error reading root block\n");
return -EIO;
}
tmp = read_tree_block(fs_info->extent_root, bytenr,
leafsize, 0);
- if (!tmp) {
+ if (!extent_buffer_uptodate(tmp)) {
fprintf(stderr, "Error reading tree block\n");
return -EIO;
}
reada_for_search(root, path, level, slot, 0);
next = read_node_slot(root, c, slot);
- if (next)
+ if (extent_buffer_uptodate(next))
break;
offset++;
}
if (path->reada)
reada_for_search(root, path, level, 0, 0);
next = read_node_slot(root, next, 0);
- if (!next)
+ if (!extent_buffer_uptodate(next))
goto again;
}
return 0;
if (fs_location != 0) {
free_extent_buffer(root->node);
root->node = read_tree_block(root, fs_location, root->leafsize, 0);
- if (!root->node) {
+ if (!extent_buffer_uptodate(root->node)) {
fprintf(stderr, "Failed to read fs location\n");
ret = 1;
goto out;
/* promote the child to a root */
child = read_node_slot(root, mid, 0);
- BUG_ON(!child);
+ BUG_ON(!extent_buffer_uptodate(child));
ret = btrfs_cow_block(trans, root, child, mid, 0, &child);
BUG_ON(ret);
return 0;
left = read_node_slot(root, parent, pslot - 1);
- if (left) {
+ if (extent_buffer_uptodate(left)) {
wret = btrfs_cow_block(trans, root, left,
parent, pslot - 1, &left);
if (wret) {
}
}
right = read_node_slot(root, parent, pslot + 1);
- if (right) {
+ if (extent_buffer_uptodate(right)) {
wret = btrfs_cow_block(trans, root, right,
parent, pslot + 1, &right);
if (wret) {
left = read_node_slot(root, parent, pslot - 1);
/* first, try to make some room in the middle buffer */
- if (left) {
+ if (extent_buffer_uptodate(left)) {
u32 left_nr;
left_nr = btrfs_header_nritems(left);
if (left_nr >= BTRFS_NODEPTRS_PER_BLOCK(root) - 1) {
/*
* then try to empty the right most buffer into the middle
*/
- if (right) {
+ if (extent_buffer_uptodate(right)) {
u32 right_nr;
right_nr = btrfs_header_nritems(right);
if (right_nr >= BTRFS_NODEPTRS_PER_BLOCK(root) - 1) {
return 1;
right = read_node_slot(root, upper, slot + 1);
+ if (!extent_buffer_uptodate(right)) {
+ if (IS_ERR(right))
+ return PTR_ERR(right);
+ return -EIO;
+ }
free_space = btrfs_leaf_free_space(root, right);
if (free_space < data_size) {
free_extent_buffer(right);
slot--;
next = read_node_slot(root, c, slot);
+ if (!extent_buffer_uptodate(next)) {
+ if (IS_ERR(next))
+ return PTR_ERR(next);
+ return -EIO;
+ }
break;
}
path->slots[level] = slot;
if (!level)
break;
next = read_node_slot(root, next, slot);
+ if (!extent_buffer_uptodate(next)) {
+ if (IS_ERR(next))
+ return PTR_ERR(next);
+ return -EIO;
+ }
}
return 0;
}
reada_for_search(root, path, level, slot, 0);
next = read_node_slot(root, c, slot);
- if (!next)
+ if (!extent_buffer_uptodate(next))
return -EIO;
break;
}
if (path->reada)
reada_for_search(root, path, level, 0, 0);
next = read_node_slot(root, next, 0);
- if (!next)
+ if (!extent_buffer_uptodate(next))
return -EIO;
}
return 0;
eb = btrfs_find_create_tree_block(root, bytenr, blocksize);
if (!eb)
- return NULL;
+ return ERR_PTR(-ENOMEM);
if (btrfs_buffer_uptodate(eb, parent_transid))
return eb;
printk("read block failed check_tree_block\n");
else
printk("Csum didn't match\n");
+ ret = -EIO;
break;
}
num_copies = btrfs_num_copies(&root->fs_info->mapping_tree,
}
}
free_extent_buffer(eb);
- return NULL;
+ return ERR_PTR(ret);
}
int write_and_map_eb(struct btrfs_trans_handle *trans,
blocksize = btrfs_level_size(root, btrfs_root_level(&root->root_item));
root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item),
blocksize, generation);
- if (!root->node) {
+ if (!extent_buffer_uptodate(root->node)) {
free(root);
return ERR_PTR(-EIO);
}
fs_info->chunk_root->node = read_tree_block(fs_info->chunk_root,
btrfs_super_chunk_root(sb),
blocksize, generation);
- if (!fs_info->chunk_root->node ||
- !extent_buffer_uptodate(fs_info->chunk_root->node)) {
+ if (!extent_buffer_uptodate(fs_info->chunk_root->node)) {
fprintf(stderr, "Couldn't read chunk root\n");
return -EIO;
}
next = read_tree_block(root, bytenr, blocksize,
ptr_gen);
mutex_lock(&root->fs_info->fs_mutex);
+ if (!extent_buffer_uptodate(next)) {
+ if (IS_ERR(next))
+ ret = PTR_ERR(next);
+ else
+ ret = -EIO;
+ break;
+ }
}
WARN_ON(*level <= 0);
if (path->nodes[*level-1])
void free_extent_buffer(struct extent_buffer *eb)
{
- if (!eb)
+ if (!eb || IS_ERR(eb))
return;
eb->refs--;
int extent_buffer_uptodate(struct extent_buffer *eb)
{
- if (!eb)
+ if (!eb || IS_ERR(eb))
return 0;
-
if (eb->flags & EXTENT_UPTODATE)
return 1;
return 0;
btrfs_node_blockptr(eb, i),
size,
btrfs_node_ptr_generation(eb, i));
- if (!next) {
+ if (!extent_buffer_uptodate(next)) {
fprintf(stderr, "failed to read %llu in tree %llu\n",
(unsigned long long)btrfs_node_blockptr(eb, i),
(unsigned long long)btrfs_header_owner(eb));
// bytenr, num_bytes, ref_parent);
eb = read_tree_block(root, bytenr, num_bytes, 0);
- if (!eb)
+ if (!extent_buffer_uptodate(eb))
return -EIO;
ret = 0;