Skip to content

Commit 120de40

Browse files
josefbacikkdave
authored andcommitted
btrfs: check the root node for uptodate before returning it
Now that we clear the extent buffer uptodate if we fail to write it out we need to check to see if our root node is uptodate before we search down it. Otherwise we could return stale data (or potentially corrupt data that was caught by the write verification step) and think that the path is OK to search down. CC: stable@vger.kernel.org # 5.4+ Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent a174c0a commit 120de40

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

‎fs/btrfs/ctree.c‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,12 +1569,9 @@ static struct extent_buffer *btrfs_search_slot_get_root(struct btrfs_root *root,
15691569
int write_lock_level)
15701570
{
15711571
struct extent_buffer *b;
1572-
int root_lock;
1572+
int root_lock = 0;
15731573
int level = 0;
15741574

1575-
/* We try very hard to do read locks on the root */
1576-
root_lock = BTRFS_READ_LOCK;
1577-
15781575
if (p->search_commit_root) {
15791576
b = root->commit_root;
15801577
atomic_inc(&b->refs);
@@ -1594,6 +1591,9 @@ static struct extent_buffer *btrfs_search_slot_get_root(struct btrfs_root *root,
15941591
goto out;
15951592
}
15961593

1594+
/* We try very hard to do read locks on the root */
1595+
root_lock = BTRFS_READ_LOCK;
1596+
15971597
/*
15981598
* If the level is set to maximum, we can skip trying to get the read
15991599
* lock.
@@ -1620,6 +1620,17 @@ static struct extent_buffer *btrfs_search_slot_get_root(struct btrfs_root *root,
16201620
level = btrfs_header_level(b);
16211621

16221622
out:
1623+
/*
1624+
* The root may have failed to write out at some point, and thus is no
1625+
* longer valid, return an error in this case.
1626+
*/
1627+
if (!extent_buffer_uptodate(b)) {
1628+
if (root_lock)
1629+
btrfs_tree_unlock_rw(b, root_lock);
1630+
free_extent_buffer(b);
1631+
return ERR_PTR(-EIO);
1632+
}
1633+
16231634
p->nodes[level] = b;
16241635
if (!p->skip_locking)
16251636
p->locks[level] = root_lock;

0 commit comments

Comments
 (0)