Skip to content

Commit

Permalink
Btrfs: Don't loop forever on metadata IO failures
Browse files Browse the repository at this point in the history
When a btrfs metadata read fails, the first thing we try to do is find
a good copy on another mirror of the block.  If this fails, read_tree_block()
ends up returning a buffer that isn't up to date.

The btrfs btree reading code was reworked to drop locks and repeat
the search when IO was done, but the changes didn't add a check for failed
reads.  The end result was looping forever on buffers that were never
going to become up to date.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
  • Loading branch information
Chris Mason committed May 14, 2009
1 parent 2757495 commit 76a05b3
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions fs/btrfs/ctree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1469,21 +1469,28 @@ read_block_for_search(struct btrfs_trans_handle *trans,
u32 blocksize;
struct extent_buffer *b = *eb_ret;
struct extent_buffer *tmp;
int ret;

blocknr = btrfs_node_blockptr(b, slot);
gen = btrfs_node_ptr_generation(b, slot);
blocksize = btrfs_level_size(root, level - 1);

tmp = btrfs_find_tree_block(root, blocknr, blocksize);
if (tmp && btrfs_buffer_uptodate(tmp, gen)) {
/*
* we found an up to date block without sleeping, return
* right away
*/
*eb_ret = tmp;
return 0;
}

/*
* reduce lock contention at high levels
* of the btree by dropping locks before
* we read.
* we read. Don't release the lock on the current
* level because we need to walk this node to figure
* out which blocks to read.
*/
btrfs_unlock_up_safe(p, level + 1);
btrfs_set_path_blocking(p);
Expand All @@ -1494,10 +1501,21 @@ read_block_for_search(struct btrfs_trans_handle *trans,
reada_for_search(root, p, level, slot, key->objectid);

btrfs_release_path(NULL, p);

ret = -EAGAIN;
tmp = read_tree_block(root, blocknr, blocksize, gen);
if (tmp)
if (tmp) {
/*
* If the read above didn't mark this buffer up to date,
* it will never end up being up to date. Set ret to EIO now
* and give up so that our caller doesn't loop forever
* on our EAGAINs.
*/
if (!btrfs_buffer_uptodate(tmp, 0))
ret = -EIO;
free_extent_buffer(tmp);
return -EAGAIN;
}
return ret;
}

/*
Expand Down Expand Up @@ -1696,6 +1714,9 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
if (ret == -EAGAIN)
goto again;

if (ret == -EIO)
goto done;

if (!p->skip_locking) {
int lret;

Expand Down Expand Up @@ -1738,6 +1759,8 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
*/
if (!p->leave_spinning)
btrfs_set_path_blocking(p);
if (ret < 0)
btrfs_release_path(root, p);
return ret;
}

Expand Down Expand Up @@ -4212,6 +4235,11 @@ int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path)
if (ret == -EAGAIN)
goto again;

if (ret < 0) {
btrfs_release_path(root, path);
goto done;
}

if (!path->skip_locking) {
ret = btrfs_try_spin_lock(next);
if (!ret) {
Expand Down Expand Up @@ -4246,6 +4274,11 @@ int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path)
if (ret == -EAGAIN)
goto again;

if (ret < 0) {
btrfs_release_path(root, path);
goto done;
}

if (!path->skip_locking) {
btrfs_assert_tree_locked(path->nodes[level]);
ret = btrfs_try_spin_lock(next);
Expand Down

0 comments on commit 76a05b3

Please sign in to comment.