Commit
6e181cfe2409 ("btrfs: revalidate cached tree blocks on the
uptodate path") introduced the @check parameter for
btrfs_buffer_uptodate() to allow re-validation of a cached extent
buffer.
But there are still call sites that don't utilize this parameter, which
exposes them to possible corrupted tree blocks, e.g. an empty child leaf
of a parent node, which should be rejected by btrfs_verify_level_key()
but if @check is NULL such check will be skipped and cause problems.
Thankfully for a lot of cases there is already an existing @check
structure around and we can pass it directly to btrfs_buffer_uptodate().
Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
if (p->reada == READA_FORWARD_ALWAYS)
reada_for_search(fs_info, p, parent_level, slot, key->objectid);
- /* first we do an atomic uptodate check */
- if (btrfs_buffer_uptodate(tmp, check.transid, NULL) > 0) {
- /*
- * Do extra check for first_key, eb can be stale due to
- * being cached, read from scrub, or have multiple
- * parents (shared tree blocks).
- */
- if (unlikely(btrfs_verify_level_key(tmp, &check))) {
- ret = -EUCLEAN;
- goto out;
- }
+ /* Check if the cached eb is uptodate. */
+ ret = btrfs_buffer_uptodate(tmp, check.transid, &check);
+ if (unlikely(ret < 0))
+ goto out;
+ if (ret > 0) {
*eb_ret = tmp;
tmp = NULL;
ret = 0;
generation = btrfs_node_ptr_generation(path->nodes[level], path->slots[level]);
- if (btrfs_buffer_uptodate(next, generation, NULL))
- return 0;
-
check.level = level - 1;
check.transid = generation;
check.owner_root = btrfs_root_id(root);
check.has_first_key = true;
btrfs_node_key_to_cpu(path->nodes[level], &check.first_key, path->slots[level]);
+ ret = btrfs_buffer_uptodate(next, generation, &check);
+ if (ret > 0)
+ return 0;
btrfs_tree_unlock(next);
+ if (ret < 0) {
+ free_extent_buffer(next);
+ return ret;
+ }
+
if (level == 1)
reada_walk_down(trans, root, wc, path);
ret = btrfs_read_extent_buffer(next, &check);
if (IS_ERR(eb))
return;
- if (btrfs_buffer_uptodate(eb, gen, NULL)) {
+ if (btrfs_buffer_uptodate(eb, gen, &check)) {
free_extent_buffer(eb);
return;
}