From patchwork Fri Oct 30 21:02:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11870829 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CAD9C4742C for ; Fri, 30 Oct 2020 21:03:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2AB882076D for ; Fri, 30 Oct 2020 21:03:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="VXM3fs0g" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727379AbgJ3VDL (ORCPT ); Fri, 30 Oct 2020 17:03:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727050AbgJ3VDL (ORCPT ); Fri, 30 Oct 2020 17:03:11 -0400 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44B83C0613D2 for ; Fri, 30 Oct 2020 14:03:11 -0700 (PDT) Received: by mail-qk1-x744.google.com with SMTP id x20so6220284qkn.1 for ; Fri, 30 Oct 2020 14:03:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=o4kW1gWmkUqX15XC3VgB86RSBgXKlsCwAe0i7TwFvdg=; b=VXM3fs0gBKJlp4+f+TRllDZ2Tg0hglPNgfuy7Mlm1tZN+VGx7C9oVMomm+BRcsskVf RuMENn4YuSWVCRBQzBcjhfIyf4FCxFxsNbHVnNoOkT+Yl9xuNd87YEyTa178OFtqLTrF PvGyzkJ8dH9P1xNE2nGADN6vuorZvbdW5jvcdXavbwq2szmYhMI55K6uaHE3HX5zYIF5 0VPOZLe7KW2hs0sQ70ICudRcrkGSonKblo7bJwZUT9RUoimtyRDFsmRQ4fK1bubZDgc+ Zt3XupSXyns/5eoTLVIrHbiLn8q+x6RTNhL51S2iK4AnK4EWHADmCeEjx9U8eJ2K4ef0 gHxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o4kW1gWmkUqX15XC3VgB86RSBgXKlsCwAe0i7TwFvdg=; b=R6ZB4xlHn+/bKPVEj4bXhrhOhaV2LcfiXqIvZiLf1Z75hxghneLvvsKfPIjQXxMZfW DS+B73Qdu20YcdL4TvkbnAPJW5sFFo7CnGkcsYRjzIqLwG21azZqzuaiXkiMCFWQTrJe LgamlMVwoE1dbTyz98AwEDomSAJiWmPayVI0T+0S5hv9Qi4dMvDjS51WxnCAXWFh7hte FG7CEVb8NmLVOkiD0ukT5iQNbZZt/9sf5iyAQalN84wufLwkeBD2T0upFBdavIFCvydH 9fAfgJxCV/98Jlg1bIucYR/L4849XfJN1GCbJLF3E+rINQMOalO1TJIvIVYrqV4EC4Ik iYaA== X-Gm-Message-State: AOAM532QRrXW8dy+appAZHc+lB9dwrXQ9fEXHPJu+nNos3+++jPhIyXy Y83L+SYnc6x2f/8IzRA9YGsfrluNGbosh4sP X-Google-Smtp-Source: ABdhPJxbDeTbTwZZI+GN3zHHTPLSpm9BLuVOFlG1YSnEDMU17jxhvx0w42rParaUhwKgbuHlX0Oj+g== X-Received: by 2002:a37:a38b:: with SMTP id m133mr4355038qke.45.1604091790086; Fri, 30 Oct 2020 14:03:10 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id d14sm3344702qtr.62.2020.10.30.14.03.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 14:03:09 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 01/14] btrfs: remove lockdep classes for the fs tree Date: Fri, 30 Oct 2020 17:02:53 -0400 Message-Id: <4dcc77e1f45454ed6c21bae655041d33efd0e0b7.1604091530.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We have this weird problem where our lockdep class is set after we read a tree block, which can race with concurrent readers and result in erroneous lockdep errors. We want to set the lockdep class at allocation time if possible, but in certain cases we may not have the actual root owner, such as with relocation or any backref lookups. This is only really a problem for reference counted tree's, because all other tree's have their root reference set in their extent reference. Remove the fs tree specific lock class. We need to still keep the reloc tree one, it's still reference counted, because replace_path will lock the reloc tree and the destination tree, and if they're both set to tree- we'll have issues. Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 601a7ab2adb4..73eae594e934 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -160,7 +160,6 @@ static struct btrfs_lockdep_keyset { { .id = BTRFS_EXTENT_TREE_OBJECTID, .name_stem = "extent" }, { .id = BTRFS_CHUNK_TREE_OBJECTID, .name_stem = "chunk" }, { .id = BTRFS_DEV_TREE_OBJECTID, .name_stem = "dev" }, - { .id = BTRFS_FS_TREE_OBJECTID, .name_stem = "fs" }, { .id = BTRFS_CSUM_TREE_OBJECTID, .name_stem = "csum" }, { .id = BTRFS_QUOTA_TREE_OBJECTID, .name_stem = "quota" }, { .id = BTRFS_TREE_LOG_OBJECTID, .name_stem = "log" }, From patchwork Fri Oct 30 21:02:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11870833 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27392C00A89 for ; Fri, 30 Oct 2020 21:03:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA1FF2076D for ; Fri, 30 Oct 2020 21:03:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="GrBgL2zs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727653AbgJ3VDO (ORCPT ); Fri, 30 Oct 2020 17:03:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726917AbgJ3VDO (ORCPT ); Fri, 30 Oct 2020 17:03:14 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CFF0C0613CF for ; Fri, 30 Oct 2020 14:03:13 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id 12so2301623qkl.8 for ; Fri, 30 Oct 2020 14:03:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ZVqTZUivwyGZXz4YCJVu8kQfpynmGi1Av7J3i6fozac=; b=GrBgL2zszggf+ugpJUVcjoZQ4JpLjgoRdhKMWDZX6LDYLPyD8GHjb54MMXXIJL2+jR oTSdI8ofk9FBOl4yRUYMLVdUodJoj3hda7RHDZ65w9vlCWoZSY5rcrJtuOlyv7urfH2V i0v13rI+KxpnYN1PQTCvUmGEI2gZF6U6eyFIqq+gS0JvgAF3eEVjziTm1Bw9X4sOHZWC gDs/1yrx2ZXxBV4CnyCCUMnDUjL1FTlgyTO9f1Uq2Bj3G0nEFI4bkBL6E8DehGUns09T /JfNQdS+sANgicckf0qYgL5EcXjeMLQCNW7HyUT7OSKjtlX8pxdyqSBiwAk6zvju3m/U Y+vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZVqTZUivwyGZXz4YCJVu8kQfpynmGi1Av7J3i6fozac=; b=n+23jGtQxqXCzIvMBmuRax6x0ZWABU/UX0tXEHhy7gVUF5nyVjIxEEThqayGDPP2YC 8BwfwgZNpslbmdwPx3OPpoXtfvBW5hr+Q04vGlXOlAC6IarrXTSne1Pf9yExTL0Jf38l Fa7PaJEy6bLbdN/H76xEXTPfwy34FwBcEeo5lnJWIqSCH/sJXL1L8XRmSO+3AP2ntx+g GW2HQ5GEU6GA9d3fffaPm0OybUscPzWl05RCeFxSZzdQMO9hmpKJB1QHpXuS9TpIJXXo F4eJpV32ZvPRzdUER9Q2cxk2GwUkfCz9B0xebNMuBWqdBGfv5SVkgKgpE8Om0GAtd1SK tFsw== X-Gm-Message-State: AOAM53283o+V02vIeiRyMAgpDyTvZbOmp/wrn7Fi4QLz2OJRXgOvzVTe 4mmUQ7kmIQYbqyOh2bQx4INjj03tS3CQpQ19 X-Google-Smtp-Source: ABdhPJzRKh6bacjt0Lh3N3iGD3nu0bL6oik8DLbemGTIqcn/n1YyceiuU0cMPy1lqYNoshyrBmVzGw== X-Received: by 2002:a37:a34a:: with SMTP id m71mr4208260qke.81.1604091792090; Fri, 30 Oct 2020 14:03:12 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id w25sm2925797qkj.85.2020.10.30.14.03.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 14:03:11 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 02/14] btrfs: cleanup extent buffer readahead Date: Fri, 30 Oct 2020 17:02:54 -0400 Message-Id: <40fe12160324eaee77987b106ae12ef5d067d288.1604091530.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org I'm going to need to start passing around a lot more information when we allocate extent buffers, in order to make that cleaner we need to cleanup how we do readahead. Most of the callers have the parent node that we're getting our blockptr from, with the sole exception of relocation which simply has the bytenr it wants to read. Add a helper that takes the current arguments that we need (bytenr and gen), and add another helper for simply reading the slot out of a node. In followup patches the helper that takes all the extra arguments will be expanded, and the simpler helper won't need to have it's arguments adjusted. Signed-off-by: Josef Bacik --- fs/btrfs/ctree.c | 45 ++++++++-------------------------------- fs/btrfs/disk-io.c | 16 -------------- fs/btrfs/disk-io.h | 1 - fs/btrfs/extent-tree.c | 2 +- fs/btrfs/extent_io.c | 47 ++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/extent_io.h | 3 +++ fs/btrfs/relocation.c | 3 ++- fs/btrfs/volumes.c | 8 ++----- 8 files changed, 64 insertions(+), 61 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 113da62dc17f..f8a7416d8a24 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -2243,7 +2243,7 @@ static void reada_for_search(struct btrfs_fs_info *fs_info, search = btrfs_node_blockptr(node, nr); if ((search <= target && target - search <= 65536) || (search > target && search - target <= 65536)) { - readahead_tree_block(fs_info, search); + btrfs_readahead_node_child(node, nr); nread += blocksize; } nscan++; @@ -2252,16 +2252,11 @@ static void reada_for_search(struct btrfs_fs_info *fs_info, } } -static noinline void reada_for_balance(struct btrfs_fs_info *fs_info, - struct btrfs_path *path, int level) +static noinline void reada_for_balance(struct btrfs_path *path, int level) { + struct extent_buffer *parent; int slot; int nritems; - struct extent_buffer *parent; - struct extent_buffer *eb; - u64 gen; - u64 block1 = 0; - u64 block2 = 0; parent = path->nodes[level + 1]; if (!parent) @@ -2270,32 +2265,10 @@ static noinline void reada_for_balance(struct btrfs_fs_info *fs_info, nritems = btrfs_header_nritems(parent); slot = path->slots[level + 1]; - if (slot > 0) { - block1 = btrfs_node_blockptr(parent, slot - 1); - gen = btrfs_node_ptr_generation(parent, slot - 1); - eb = find_extent_buffer(fs_info, block1); - /* - * if we get -eagain from btrfs_buffer_uptodate, we - * don't want to return eagain here. That will loop - * forever - */ - if (eb && btrfs_buffer_uptodate(eb, gen, 1) != 0) - block1 = 0; - free_extent_buffer(eb); - } - if (slot + 1 < nritems) { - block2 = btrfs_node_blockptr(parent, slot + 1); - gen = btrfs_node_ptr_generation(parent, slot + 1); - eb = find_extent_buffer(fs_info, block2); - if (eb && btrfs_buffer_uptodate(eb, gen, 1) != 0) - block2 = 0; - free_extent_buffer(eb); - } - - if (block1) - readahead_tree_block(fs_info, block1); - if (block2) - readahead_tree_block(fs_info, block2); + if (slot > 0) + btrfs_readahead_node_child(parent, slot - 1); + if (slot + 1 < nritems) + btrfs_readahead_node_child(parent, slot + 1); } @@ -2481,7 +2454,7 @@ setup_nodes_for_search(struct btrfs_trans_handle *trans, } btrfs_set_path_blocking(p); - reada_for_balance(fs_info, p, level); + reada_for_balance(p, level); sret = split_node(trans, root, p, level); BUG_ON(sret > 0); @@ -2501,7 +2474,7 @@ setup_nodes_for_search(struct btrfs_trans_handle *trans, } btrfs_set_path_blocking(p); - reada_for_balance(fs_info, p, level); + reada_for_balance(p, level); sret = balance_level(trans, root, p, level); if (sret) { diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 73eae594e934..464dfb15b054 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -946,22 +946,6 @@ static const struct address_space_operations btree_aops = { .set_page_dirty = btree_set_page_dirty, }; -void readahead_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr) -{ - struct extent_buffer *buf = NULL; - int ret; - - buf = btrfs_find_create_tree_block(fs_info, bytenr); - if (IS_ERR(buf)) - return; - - ret = read_extent_buffer_pages(buf, WAIT_NONE, 0); - if (ret < 0) - free_extent_buffer_stale(buf); - else - free_extent_buffer(buf); -} - struct extent_buffer *btrfs_find_create_tree_block( struct btrfs_fs_info *fs_info, u64 bytenr) diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index 182540bdcea0..34934f38582b 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -45,7 +45,6 @@ int btrfs_verify_level_key(struct extent_buffer *eb, int level, struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr, u64 parent_transid, int level, struct btrfs_key *first_key); -void readahead_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr); struct extent_buffer *btrfs_find_create_tree_block( struct btrfs_fs_info *fs_info, u64 bytenr); diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 5fd60b13f4f8..0ca1135dab8c 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4905,7 +4905,7 @@ static noinline void reada_walk_down(struct btrfs_trans_handle *trans, continue; } reada: - readahead_tree_block(fs_info, bytenr); + btrfs_readahead_node_child(eb, slot); nread++; } wc->reada_slot = slot; diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index cf3f576d6277..654e2e517f3d 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -6106,3 +6106,50 @@ int try_release_extent_buffer(struct page *page) return release_extent_buffer(eb); } + +/** + * btrfs_readahead_tree_block - attempt to readahead a child block. + * @fs_info - the fs_info for the fs. + * @bytenr - the bytenr to read. + * @gen - the generation for the uptodate check, can be 0. + * + * Attempt to readahead a tree block at @bytenr. If @gen is 0 then we do a + * normal uptodate check of the eb, without checking the generation. If we have + * to read the block we will not block on anything. + */ +void btrfs_readahead_tree_block(struct btrfs_fs_info *fs_info, + u64 bytenr, u64 gen) +{ + struct extent_buffer *eb; + int ret; + + eb = btrfs_find_create_tree_block(fs_info, bytenr); + if (IS_ERR(eb)) + return; + + if (btrfs_buffer_uptodate(eb, gen, 1)) { + free_extent_buffer(eb); + return; + } + + ret = read_extent_buffer_pages(eb, WAIT_NONE, 0); + if (ret < 0) + free_extent_buffer_stale(eb); + else + free_extent_buffer(eb); +} + +/** + * btrfs_readahead_node_child - readahead a node's child block. + * @node - the parent node we're reading from. + * @slot - the slot in the parent node for the child we want to read. + * + * A helper for btrfs_readahead_tree_block, we simply read the bytenr pointed at + * the slot in the node provided. + */ +void btrfs_readahead_node_child(struct extent_buffer *node, int slot) +{ + btrfs_readahead_tree_block(node->fs_info, + btrfs_node_blockptr(node, slot), + btrfs_node_ptr_generation(node, slot)); +} diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index 3801eb3b726e..4f95b087a901 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -198,6 +198,9 @@ void free_extent_buffer_stale(struct extent_buffer *eb); int read_extent_buffer_pages(struct extent_buffer *eb, int wait, int mirror_num); void wait_on_extent_buffer_writeback(struct extent_buffer *eb); +void btrfs_readahead_tree_block(struct btrfs_fs_info *fs_info, + u64 bytenr, u64 gen); +void btrfs_readahead_node_child(struct extent_buffer *node, int slot); static inline int num_extent_pages(const struct extent_buffer *eb) { diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 9ba92d86da0b..50ca5a4f0a96 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2546,7 +2546,8 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans, /* Kick in readahead for tree blocks with missing keys */ rbtree_postorder_for_each_entry_safe(block, next, blocks, rb_node) { if (!block->key_ready) - readahead_tree_block(fs_info, block->bytenr); + btrfs_readahead_tree_block(fs_info, + block->bytenr, 0); } /* Get first keys */ diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index eb9ee7c2998f..75350c78ca02 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -7077,12 +7077,8 @@ static void readahead_tree_node_children(struct extent_buffer *node) int i; const int nr_items = btrfs_header_nritems(node); - for (i = 0; i < nr_items; i++) { - u64 start; - - start = btrfs_node_blockptr(node, i); - readahead_tree_block(node->fs_info, start); - } + for (i = 0; i < nr_items; i++) + btrfs_readahead_node_child(node, i); } int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info) From patchwork Fri Oct 30 21:02:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11870819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41118C4742C for ; Fri, 30 Oct 2020 21:03:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CDD122076D for ; Fri, 30 Oct 2020 21:03:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="qGDqiKbz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727658AbgJ3VDQ (ORCPT ); Fri, 30 Oct 2020 17:03:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726917AbgJ3VDP (ORCPT ); Fri, 30 Oct 2020 17:03:15 -0400 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F4080C0613CF for ; Fri, 30 Oct 2020 14:03:14 -0700 (PDT) Received: by mail-qt1-x841.google.com with SMTP id r8so5126422qtp.13 for ; Fri, 30 Oct 2020 14:03:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=WauWhR/+pt1gJWtIc3vo/FkfYt8/jl6mKnEG7cOK4es=; b=qGDqiKbzxY5TxLwkGQbtoDOgSfdPC41tAvvN1VcKgiCCutOOYM9NKAs27wV17e5FUe +UZOEcOC5fmN+WYuB3299e3ZtfMpg9P+fgMvwaPEWj/7GKCIDUS4sRVvJGm31s7nNL0L 0mhCwJZkFMXbbyT0XzLN+SdpysXepW9YEsoG/Xq31cm9IS/QMCWKAkugZrO4r14Q0FrE iHW4frh3ZrLfc3J5hx8AmBeVQakUpeex5WO+L2qXXpscWxd0PJA6sEUOEBBwld3aFlUA /jP+6fxbzGUljOCW8mtDM9D/SMLar+3bHRX41rEfWLhDpAPRtNnqr9DMtUK/R2KZABvO 24VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WauWhR/+pt1gJWtIc3vo/FkfYt8/jl6mKnEG7cOK4es=; b=F+hJs74vSmz7nj0j/PkXDpHixGL307z3o+vAezLvdA+uDnO+7Huhxwz/NXBJSCzUZY JLXneAVLgRpV2HRI8GcXeeWXxctuRQQk2n9SnB7xlnCMyKc/4p6MVKfJKhdRKW1kkRF+ HxVYchbMLcP9HB3A9AMLUZw2c04v34/aCr6fS3FRIWqSmaNuDbq8/ALjnslyFQ0ERyvQ nQ8mWuCmh6k7TkE0eEoTJLgaESownGTf4OuoepHcmst7uFv2RQAh7wc2j30gQP7YH9bc 0FqjFRS4OXXSSz/N5x+wu1VbaUz/eqwWrmQN0sWhya2RcL5kK/63txwnnEPPkiZq6d5G oDFA== X-Gm-Message-State: AOAM5306mzVCKL1IeTsLoy6Diwi61TEH6NwX4tMpdoIXM+n1Auiz8HNd sUfKs6V1gLgAKbdudKP63W7cOMjS3ttYTBRY X-Google-Smtp-Source: ABdhPJwHvbX84881scvmshQTaJfmbeDX4R2hi0CA69oo0HzCClSWCHP8k3x2x7NOpgf7Bu10fhxakw== X-Received: by 2002:ac8:58c8:: with SMTP id u8mr4060487qta.63.1604091793867; Fri, 30 Oct 2020 14:03:13 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id r133sm1160660qke.23.2020.10.30.14.03.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 14:03:13 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 03/14] btrfs: use btrfs_read_node_slot in btrfs_realloc_node Date: Fri, 30 Oct 2020 17:02:55 -0400 Message-Id: <2e17fbd6cb092191a3e1a87bf538375747e5dd7a.1604091530.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We have this giant open-coded nightmare in btrfs_realloc_node that does the same thing that the normal read path does, which is to see if we have the eb in memory already, and if not read it, and verify the eb is uptodate. Delete this open coding and simply use btrfs_read_node_slot. Signed-off-by: Josef Bacik --- fs/btrfs/ctree.c | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index f8a7416d8a24..000f18923c5a 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -1578,7 +1578,6 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info = root->fs_info; struct extent_buffer *cur; u64 blocknr; - u64 gen; u64 search_start = *last_ret; u64 last_block = 0; u64 other; @@ -1587,7 +1586,6 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, int i; int err = 0; int parent_level; - int uptodate; u32 blocksize; int progress_passed = 0; struct btrfs_disk_key disk_key; @@ -1607,7 +1605,6 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, btrfs_set_lock_blocking_write(parent); for (i = start_slot; i <= end_slot; i++) { - struct btrfs_key first_key; int close = 1; btrfs_node_key(parent, &disk_key, i); @@ -1616,8 +1613,6 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, progress_passed = 1; blocknr = btrfs_node_blockptr(parent, i); - gen = btrfs_node_ptr_generation(parent, i); - btrfs_node_key_to_cpu(parent, &first_key, i); if (last_block == 0) last_block = blocknr; @@ -1634,31 +1629,9 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, continue; } - cur = find_extent_buffer(fs_info, blocknr); - if (cur) - uptodate = btrfs_buffer_uptodate(cur, gen, 0); - else - uptodate = 0; - if (!cur || !uptodate) { - if (!cur) { - cur = read_tree_block(fs_info, blocknr, gen, - parent_level - 1, - &first_key); - if (IS_ERR(cur)) { - return PTR_ERR(cur); - } else if (!extent_buffer_uptodate(cur)) { - free_extent_buffer(cur); - return -EIO; - } - } else if (!uptodate) { - err = btrfs_read_buffer(cur, gen, - parent_level - 1,&first_key); - if (err) { - free_extent_buffer(cur); - return err; - } - } - } + cur = btrfs_read_node_slot(parent, i); + if (IS_ERR(cur)) + return PTR_ERR(cur); if (search_start == 0) search_start = last_block; From patchwork Fri Oct 30 21:02:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11870827 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E78B0C00A89 for ; Fri, 30 Oct 2020 21:03:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 913322076D for ; Fri, 30 Oct 2020 21:03:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="rTscMUjJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727678AbgJ3VDS (ORCPT ); Fri, 30 Oct 2020 17:03:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726917AbgJ3VDQ (ORCPT ); Fri, 30 Oct 2020 17:03:16 -0400 Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D94DC0613CF for ; Fri, 30 Oct 2020 14:03:16 -0700 (PDT) Received: by mail-qt1-x842.google.com with SMTP id m14so5124556qtc.12 for ; Fri, 30 Oct 2020 14:03:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=uS1AzD48zy+/eWvlXR0+OsODxNt6ULD82nvo8FQ7Lv8=; b=rTscMUjJ9mla5/IQgQfG+CzECUzxq9an/VJb0VYApBoChPvhil45yYI/C6LIIJ+Ij6 y+ACUXYFRLQcR/igMGME6edJypF4+sjwCaJmD5r1CWV3R/Zo0mnGkffktGd59FC2UmhM zKXX1r7NR9n2DXr7dtVnO9HcO+LS1KPnd/Rqcpijf41ehXs8SCcX6IAFncCpy5TrhHDc pjBXn8d855T3E/TuHbwxMKv7I582vJK/nOtaDdT3LOrXNOt1qLR6VTPipEq7np4zIbdo 5QExy+CvGLDf/V8Wl/YVsQxuj7L248zUKhUFEh9p8geNzcaOzbCqbnVTqCs1+KX8Oty0 Xv+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uS1AzD48zy+/eWvlXR0+OsODxNt6ULD82nvo8FQ7Lv8=; b=KLuWBTopTq0i7gpVSSHk/05WgO7aEkyb1nq4QMj0ipQBSvPEWxTzKEBM6a/5AyLBM3 X51cxa8l3Jhyt4C1DTIqqeH+O8fWXuz0m7JsuINCa6yX7H/ZRJ54IqOCEZGP0SrqD715 F9GlLdAT7eeCGpZ6Iv29oZpGHg7eV2POLLoWs7IvR17r46881t0OlX7bhcbwTZ5gLPCe 2DFYbTThsnO5dqldqRsRDJ6IpJsakatCIuTT/u7e5GqW0nJEq0fcPQscBgCsZPNusblR LzS3d+O7Yis28nyzfyaPZGSIQJTU8/UvwSXT+im6D9cJD+UiwsjAh8qkL6piNEIsfXLu h0rA== X-Gm-Message-State: AOAM532GjlOxv4nmVQe6YmEMmNOfId32HsMb2noYcRkYAAAiY+0+Kj6d 9CCzJD75++2d/54lF+80L7f46TEaUEFNNeX5 X-Google-Smtp-Source: ABdhPJyTpBVKW1Hqzh7d78NuHZiiKqmXlkaMRx1su36mZpzAcvWfrzQfJkByfH4KMd0LQY9BOLlMZQ== X-Received: by 2002:a05:622a:14f:: with SMTP id v15mr4177271qtw.245.1604091795514; Fri, 30 Oct 2020 14:03:15 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id o5sm3431220qtt.3.2020.10.30.14.03.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 14:03:14 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 04/14] btrfs: use btrfs_read_node_slot in walk_down_reloc_tree Date: Fri, 30 Oct 2020 17:02:56 -0400 Message-Id: <8c7e00e7c4aed3b97fc42b4c229c97760122685f.1604091530.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We do not need to call read_tree_block() here, simply use the btrfs_read_node_slot helper. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 50ca5a4f0a96..bf31b86945d5 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1418,10 +1418,8 @@ static noinline_for_stack int walk_down_reloc_tree(struct btrfs_root *root, struct btrfs_path *path, int *level) { - struct btrfs_fs_info *fs_info = root->fs_info; struct extent_buffer *eb = NULL; int i; - u64 bytenr; u64 ptr_gen = 0; u64 last_snapshot; u32 nritems; @@ -1429,8 +1427,6 @@ int walk_down_reloc_tree(struct btrfs_root *root, struct btrfs_path *path, last_snapshot = btrfs_root_last_snapshot(&root->root_item); for (i = *level; i > 0; i--) { - struct btrfs_key first_key; - eb = path->nodes[i]; nritems = btrfs_header_nritems(eb); while (path->slots[i] < nritems) { @@ -1450,16 +1446,9 @@ int walk_down_reloc_tree(struct btrfs_root *root, struct btrfs_path *path, return 0; } - bytenr = btrfs_node_blockptr(eb, path->slots[i]); - btrfs_node_key_to_cpu(eb, &first_key, path->slots[i]); - eb = read_tree_block(fs_info, bytenr, ptr_gen, i - 1, - &first_key); - if (IS_ERR(eb)) { + eb = btrfs_read_node_slot(eb, path->slots[i]); + if (IS_ERR(eb)) return PTR_ERR(eb); - } else if (!extent_buffer_uptodate(eb)) { - free_extent_buffer(eb); - return -EIO; - } BUG_ON(btrfs_header_level(eb) != i - 1); path->nodes[i - 1] = eb; path->slots[i - 1] = 0; From patchwork Fri Oct 30 21:02:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11870823 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D900C388F9 for ; Fri, 30 Oct 2020 21:03:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9EF0D2076D for ; Fri, 30 Oct 2020 21:03:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="QxjRj6in" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727691AbgJ3VDT (ORCPT ); Fri, 30 Oct 2020 17:03:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726917AbgJ3VDT (ORCPT ); Fri, 30 Oct 2020 17:03:19 -0400 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18B25C0613CF for ; Fri, 30 Oct 2020 14:03:19 -0700 (PDT) Received: by mail-qk1-x742.google.com with SMTP id i21so5457962qka.12 for ; Fri, 30 Oct 2020 14:03:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=489xY/ksKkbphR6OI0Tcd5nO9x9Gb8yGvGWYLqRlrv0=; b=QxjRj6intARIE+TX+7e32N4Wd5S3mWkXfqzvFEMyB+XNaUAOJc700ftA94pEfXvq7z oEW8ZYDKFQLi1pqymxu1cuhfP02bsL8HahDPQpiBRokCaHE0qMg4Y0u+BVv2TmzGZHQi 304erLg8PZpQI8oxYPtyZ9aF4L9RNNs25P6HnYng0kzc/0kddghG8rdvTUbxBwOqIhOr PWQLcLBHn1yvTDAr/iRJ+CkvVtxhT5CqoeQhlTMPStd+PzSFCDP1uwaMn1eJYmMAM3kl Rre6ekP7vC9EWq3Pij46VCW6cAGKDbkX7LDHen3MNJ4fh8mFKYxP68j6TxSvLequAII9 kojg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=489xY/ksKkbphR6OI0Tcd5nO9x9Gb8yGvGWYLqRlrv0=; b=H+eY92Nmr+LfFXbomYt20QVbEfFkMb3PXdj0jjnQBORxOMV9cV6aSemB865iJsfpQ6 63WPBvl3ifrgIsI3mp7VH06wSHYFjlZHNKDNrAfQRsXcTImzcCPC5+84h/tXztdKeNWq c42P1m5+AWUdRm/6QK5BKZg4RpxSi+o8Tpxw9Toajuw8SvsRd3ciaNpRicIRRMzd7zOH WjurcIS8SF4bIoOleu5xeOvKbj4IA80HYfncbh5M+364boYhzuQKZH/52Uw8w15GzeJJ 9yI8/SGwgJmZM4z61wTz97VqtbuZ+AkAPqQc4Uj8Wzg0nx4n1FRVuqZdkLyEiqCeBUT5 J7hQ== X-Gm-Message-State: AOAM530tOvjOwL2Pllwenm7RhROfj6G4s47JnD0D3ToyItP2QU62+Lf7 stTsANwofvw379H+59mE8OpWmNRBL6EfMRi5 X-Google-Smtp-Source: ABdhPJzLUiIB0T/BQWKUdr8c5lXFf0eT8fazNtDyG4io5lhkoaVmztD7yshanS/1obqymCJxJLjRGQ== X-Received: by 2002:a37:a411:: with SMTP id n17mr4059033qke.230.1604091797939; Fri, 30 Oct 2020 14:03:17 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id u5sm3340415qtg.57.2020.10.30.14.03.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 14:03:16 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 05/14] btrfs: use btrfs_read_node_slot in do_relocation Date: Fri, 30 Oct 2020 17:02:57 -0400 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We're open coding btrfs_read_node_slot in do_relocation, replace this with the proper helper. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index bf31b86945d5..874ae92c0df4 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2194,7 +2194,6 @@ static int do_relocation(struct btrfs_trans_handle *trans, struct btrfs_key *key, struct btrfs_path *path, int lowest) { - struct btrfs_fs_info *fs_info = rc->extent_root->fs_info; struct btrfs_backref_node *upper; struct btrfs_backref_edge *edge; struct btrfs_backref_edge *edges[BTRFS_MAX_LEVEL - 1]; @@ -2202,7 +2201,6 @@ static int do_relocation(struct btrfs_trans_handle *trans, struct extent_buffer *eb; u32 blocksize; u64 bytenr; - u64 generation; int slot; int ret; int err = 0; @@ -2212,7 +2210,6 @@ static int do_relocation(struct btrfs_trans_handle *trans, path->lowest_level = node->level + 1; rc->backref_cache.path[node->level] = node; list_for_each_entry(edge, &node->upper, list[LOWER]) { - struct btrfs_key first_key; struct btrfs_ref ref = { 0 }; cond_resched(); @@ -2285,17 +2282,10 @@ static int do_relocation(struct btrfs_trans_handle *trans, } blocksize = root->fs_info->nodesize; - generation = btrfs_node_ptr_generation(upper->eb, slot); - btrfs_node_key_to_cpu(upper->eb, &first_key, slot); - eb = read_tree_block(fs_info, bytenr, generation, - upper->level - 1, &first_key); + eb = btrfs_read_node_slot(upper->eb, slot); if (IS_ERR(eb)) { err = PTR_ERR(eb); goto next; - } else if (!extent_buffer_uptodate(eb)) { - free_extent_buffer(eb); - err = -EIO; - goto next; } btrfs_tree_lock(eb); btrfs_set_lock_blocking_write(eb); From patchwork Fri Oct 30 21:02:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11870831 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D932BC388F9 for ; Fri, 30 Oct 2020 21:03:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B5102076D for ; Fri, 30 Oct 2020 21:03:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="iDPwYJYD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727711AbgJ3VDX (ORCPT ); Fri, 30 Oct 2020 17:03:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726917AbgJ3VDX (ORCPT ); Fri, 30 Oct 2020 17:03:23 -0400 Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8276C0613CF for ; Fri, 30 Oct 2020 14:03:22 -0700 (PDT) Received: by mail-qt1-x842.google.com with SMTP id p45so5155182qtb.5 for ; Fri, 30 Oct 2020 14:03:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=jyAOhBhO0viV5uEUq4XQaZzaVinrCge6QmkS5qPW3k4=; b=iDPwYJYDSkjSAZB/tX1HoK5PY63Dw8hdLefUgoIEXoth2YR8cjjKwxuESQS+IeW7Vg 9SdUc2qHwm3QcDscfBHXbWF8KnaJYo7biI0/rpZWNTIh2hGfEyS/HcA9qV9tc0+pUvut v06Qti+/hc7ojKs35/jf41bht+IOHoSHIO30RIPO7c3XTYvZ5+ZnaQB5ryDFze3CSzpB z2QjII4PolEEJlM4HjnJufmZXTPV68iLhEbJVvP9X7i+FI3aSDYCHYO3fCIdn7vPVwh4 HDPlBnWvX+rFv4PUtxlPZL1uEjFmPh+blIi9GGL3k0XPR7wcWyLeShwQ+Dp6K4NpejZg oNbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jyAOhBhO0viV5uEUq4XQaZzaVinrCge6QmkS5qPW3k4=; b=OL8a98sywmuOHEGedBojCsNQxnaRQQSKY4FJcOZz4RwcmLjfEaazbFeiFdsFZbRDLh vkUK2lpqKTUwzDGbUlACAI/rpHoIWMpL1FYTQCt1kswbhNBdvfe/KMeD49XzcTVYmGqH GXZdlMer472dn9K5D4XLFGCgw9dfA0zNNnGcnB5S/ChsjszyypdJhycqZ1u9x309dXE/ Ia0ApcTqBS62TxtqGmFQmG5sIoOy+IGH0ZT7UF3GU6VcY/yfhb26sqtjQ+TitdupVuuf xV8ITiePNx16TlZqcPy2LnhobdRyiJI9h3ELw1mvm3qbGpMGlePwYbU7ZCgMNeAuyCIJ BXpQ== X-Gm-Message-State: AOAM533tids/wl6KXYUpNWZUTAN7vUytIkgr4sQJwDEfb56uMHMM5NYh ShDR3gxGfexTMHI6wSBxGomHGv1jFZhWy0e/ X-Google-Smtp-Source: ABdhPJzpvViXD1OSk4Ysg5iFPAYvNK9FWLd3i6soGx2XAowSNTsXRBhNxupzx40fXMGS8sygf5xczg== X-Received: by 2002:ac8:1e84:: with SMTP id c4mr4232747qtm.340.1604091801828; Fri, 30 Oct 2020 14:03:21 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id z66sm3387102qkb.50.2020.10.30.14.03.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 14:03:20 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 07/14] btrfs: use btrfs_read_node_slot in walk_down_tree Date: Fri, 30 Oct 2020 17:02:59 -0400 Message-Id: <191719dc15aa5ce13b7f58ab9e796c18509f0264.1604091530.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We're open-coding btrfs_read_node_slot() here, replace with the helper. Signed-off-by: Josef Bacik --- fs/btrfs/ref-verify.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/fs/btrfs/ref-verify.c b/fs/btrfs/ref-verify.c index 7f03dbe5b609..4c9ddc750914 100644 --- a/fs/btrfs/ref-verify.c +++ b/fs/btrfs/ref-verify.c @@ -551,29 +551,15 @@ static int process_leaf(struct btrfs_root *root, static int walk_down_tree(struct btrfs_root *root, struct btrfs_path *path, int level, u64 *bytenr, u64 *num_bytes) { - struct btrfs_fs_info *fs_info = root->fs_info; struct extent_buffer *eb; - u64 block_bytenr, gen; int ret = 0; while (level >= 0) { if (level) { - struct btrfs_key first_key; - - block_bytenr = btrfs_node_blockptr(path->nodes[level], - path->slots[level]); - gen = btrfs_node_ptr_generation(path->nodes[level], - path->slots[level]); - btrfs_node_key_to_cpu(path->nodes[level], &first_key, - path->slots[level]); - eb = read_tree_block(fs_info, block_bytenr, gen, - level - 1, &first_key); + eb = btrfs_read_node_slot(path->nodes[level], + path->slots[level]); if (IS_ERR(eb)) return PTR_ERR(eb); - if (!extent_buffer_uptodate(eb)) { - free_extent_buffer(eb); - return -EIO; - } btrfs_tree_read_lock(eb); btrfs_set_lock_blocking_read(eb); path->nodes[level-1] = eb; From patchwork Fri Oct 30 21:03:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11870839 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C44E2C00A89 for ; Fri, 30 Oct 2020 21:03:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 683322076D for ; Fri, 30 Oct 2020 21:03:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="JK87gXBe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727721AbgJ3VD0 (ORCPT ); Fri, 30 Oct 2020 17:03:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726917AbgJ3VDZ (ORCPT ); Fri, 30 Oct 2020 17:03:25 -0400 Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9BF5C0613CF for ; Fri, 30 Oct 2020 14:03:24 -0700 (PDT) Received: by mail-qv1-xf41.google.com with SMTP id cv1so3428764qvb.2 for ; Fri, 30 Oct 2020 14:03:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=WMUbVGZ7vNT9aaXRMWfM9y5LnBlAxY8h1QiNSBsIprI=; b=JK87gXBeH0oxvU2LkdCauncrKA8+ZYMdorYGWMrb/qS8tcFt3czpQn3GMQCi9vkNrT Ugf3A6jkDgp6c4yq2pqEbvwTru9ETAN4sS1WnP+73eTAj2/OlEfSj+JOIO1v3o1ZtVyQ zIBl+Z9BQJBu2FnIj+8iVE8RzViOAeM2SmEOaKv3Lm63x+R+C916KvGtqEyjDYXZ47OW dv2uhg0++r3eHeYnQ2JG094dgRawLcm8U3NZn799xt6rggMN/pBU8hn8NAXhfY8TNzJw TKhWsGYFWyvxyawDOYAw+2goPbcim07z28ljNdluma1Z5JxYILhdrBgHVqj1N2D4ZxoC To3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WMUbVGZ7vNT9aaXRMWfM9y5LnBlAxY8h1QiNSBsIprI=; b=UcJku1ZGMtlAFybEb+Hl3Iddf0npeDssieWEbdevkuX7tB2cHiDRonGonCUokAoKG/ Btkmg8mKoNNviO6IphVGtDJMUYHi/Q/dskBaNkO/X1VJJ2cpVZkgm0bjtJ2LI0SZvpfX qLwWzRPYwUqab4/rqpVgmmI3YUUd32oFxNQf1Y0OBLmAicLvLZOCrQuLXyNcr+6OdqbR lB9YMGDEc+o0AQVvisIn73QF2QmauCwoV2FaZP/czEkq/UfTmRDg7WQFBE1gDVBFWPUO JgpGpRmQJK8t+/QFVwNCXMBkl84q7K/AejuKfv06dvVcRdIs/1xsKu0tmU2u8PLm7iPT mRuQ== X-Gm-Message-State: AOAM532a5sJjZqilAHwkofYiAqMnNznXMAJTPp3XAj73/rHIhqhs2c5P KAOh70F3GIhS65EALOImPht7tqFvYR/SAcW9 X-Google-Smtp-Source: ABdhPJytp6wNVaiLrHgK/uj/h2JLttW1AhUMms/m9MkfmqmLjggyJD/uwTooSFyyTcZToNDKesHhhw== X-Received: by 2002:a05:6214:209:: with SMTP id i9mr11485484qvt.38.1604091803584; Fri, 30 Oct 2020 14:03:23 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id n201sm3399812qka.32.2020.10.30.14.03.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 14:03:22 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 08/14] btrfs: use btrfs_read_node_slot in qgroup_trace_extent_swap Date: Fri, 30 Oct 2020 17:03:00 -0400 Message-Id: <2ce778346135ceaf868dca5ec26c4dfa0846853b.1604091530.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We're open-coding btrfs_read_node_slot() here, replace with the helper. Signed-off-by: Josef Bacik --- fs/btrfs/qgroup.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 77c54749f432..f009beeba385 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -1894,27 +1894,16 @@ static int qgroup_trace_extent_swap(struct btrfs_trans_handle* trans, struct btrfs_key dst_key; if (src_path->nodes[cur_level] == NULL) { - struct btrfs_key first_key; struct extent_buffer *eb; int parent_slot; - u64 child_gen; - u64 child_bytenr; eb = src_path->nodes[cur_level + 1]; parent_slot = src_path->slots[cur_level + 1]; - child_bytenr = btrfs_node_blockptr(eb, parent_slot); - child_gen = btrfs_node_ptr_generation(eb, parent_slot); - btrfs_node_key_to_cpu(eb, &first_key, parent_slot); - eb = read_tree_block(fs_info, child_bytenr, child_gen, - cur_level, &first_key); + eb = btrfs_read_node_slot(eb, parent_slot); if (IS_ERR(eb)) { ret = PTR_ERR(eb); goto out; - } else if (!extent_buffer_uptodate(eb)) { - free_extent_buffer(eb); - ret = -EIO; - goto out; } src_path->nodes[cur_level] = eb; From patchwork Fri Oct 30 21:03:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11870835 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B52EC388F9 for ; Fri, 30 Oct 2020 21:03:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D654E2076D for ; Fri, 30 Oct 2020 21:03:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="VY53MwRp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727725AbgJ3VD2 (ORCPT ); Fri, 30 Oct 2020 17:03:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726917AbgJ3VD1 (ORCPT ); Fri, 30 Oct 2020 17:03:27 -0400 Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CB3EC0613CF for ; Fri, 30 Oct 2020 14:03:26 -0700 (PDT) Received: by mail-qt1-x842.google.com with SMTP id m14so5124903qtc.12 for ; Fri, 30 Oct 2020 14:03:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=o/bz1iIWHTfbrqVDCQV3PVmyOtuMZXS2SbpHpZVesTQ=; b=VY53MwRpRP+8rLf05KILsDT77OT0ugyiefi0/pobGcYuhBgX+t+czUMFZWUQY3zS3S 5Z91P4uJweBHMlWO28UZAGezrVPFBLE4zyvLUnYP5WSah9xj2jU3/tWnwEyg2Zx9LAEz w0MGhz4dJNwqsW0NvpgqqOl5+hF2M13FEGDctUv+X92ULPejId5DLUu3oJz5mHNZF1py K0Rp36yikESmdRjd7ebUqL664H54h8lHITHGgJ78ms59PReIt8NUMRKjtHVuHpgvYRqo PI73Cnp586QMefZHwwJ+xgelyicVrosUMJquE+PqFfwA1ednJ2bfdiybcY4+8NRoBOyv STOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o/bz1iIWHTfbrqVDCQV3PVmyOtuMZXS2SbpHpZVesTQ=; b=mwhh2iJYJHXsnaPCpHRsHnA61flMd/5/S+XhgKAhe5zPjptbq1oBRELnvRJGwejPu2 zgpaYN/hDqhQPsplazQp/dt+Rr78JQWA5T1L0SwwWxOxr1t44LuR6SIMJkIkVnCkJDNP lLoMvIPyxBHDNJno9IowJuIfuS322fOmkWzhSLnAZz0HpsqG/WKgA18Su5LzVwLxZdGn SAHwkpRJAR4u6VgBdyoTzQsnlxiNKrY7Vihu3lMG65jTAYIM5dN1GhXLoiMuXDBjnXTx 1DqFjGjWGZ5iXaWEBaavxqP/0KYIz3MSj4RgG7IlZTExtHM2jklCrxxZLhZ8uq+z0+Fk gRoQ== X-Gm-Message-State: AOAM533THoWmIIumtmuhWaJp59CAGJZHfzO7AUC4ejoCyE9lKMKh2Byy NXhzV6jFqzsnHVvyTAuHsvYxQgOvbP4baJ2F X-Google-Smtp-Source: ABdhPJxylZICDS5JMoexbY4JQFyQU5XsjRjvN4tIMkwzuBYZNcmE9XJVcCWiD1J2081g3NxwIfw02A== X-Received: by 2002:ac8:7454:: with SMTP id h20mr4082361qtr.34.1604091805365; Fri, 30 Oct 2020 14:03:25 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id z6sm3253866qti.88.2020.10.30.14.03.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 14:03:24 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 09/14] btrfs: use btrfs_read_node_slot in qgroup_trace_new_subtree_blocks Date: Fri, 30 Oct 2020 17:03:01 -0400 Message-Id: <35706903f3ff92e0e2a44b9d2c468149b85380bd.1604091530.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We're open-coding btrfs_read_node_slot() here, replace with the helper. Signed-off-by: Josef Bacik --- fs/btrfs/qgroup.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index f009beeba385..ddd1cd6db6c4 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2005,10 +2005,8 @@ static int qgroup_trace_new_subtree_blocks(struct btrfs_trans_handle* trans, /* Read the tree block if needed */ if (dst_path->nodes[cur_level] == NULL) { - struct btrfs_key first_key; - int parent_slot; u64 child_gen; - u64 child_bytenr; + int parent_slot; /* * dst_path->nodes[root_level] must be initialized before @@ -2027,23 +2025,16 @@ static int qgroup_trace_new_subtree_blocks(struct btrfs_trans_handle* trans, */ eb = dst_path->nodes[cur_level + 1]; parent_slot = dst_path->slots[cur_level + 1]; - child_bytenr = btrfs_node_blockptr(eb, parent_slot); child_gen = btrfs_node_ptr_generation(eb, parent_slot); - btrfs_node_key_to_cpu(eb, &first_key, parent_slot); /* This node is old, no need to trace */ if (child_gen < last_snapshot) goto out; - eb = read_tree_block(fs_info, child_bytenr, child_gen, - cur_level, &first_key); + eb = btrfs_read_node_slot(eb, parent_slot); if (IS_ERR(eb)) { ret = PTR_ERR(eb); goto out; - } else if (!extent_buffer_uptodate(eb)) { - free_extent_buffer(eb); - ret = -EIO; - goto out; } dst_path->nodes[cur_level] = eb; From patchwork Fri Oct 30 21:03:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11870845 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61E47C388F9 for ; Fri, 30 Oct 2020 21:03:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 09C3A2076D for ; Fri, 30 Oct 2020 21:03:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="K8ZuRdHJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727731AbgJ3VDa (ORCPT ); Fri, 30 Oct 2020 17:03:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726917AbgJ3VD3 (ORCPT ); Fri, 30 Oct 2020 17:03:29 -0400 Received: from mail-qv1-xf43.google.com (mail-qv1-xf43.google.com [IPv6:2607:f8b0:4864:20::f43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63B46C0613CF for ; Fri, 30 Oct 2020 14:03:28 -0700 (PDT) Received: by mail-qv1-xf43.google.com with SMTP id t20so3412343qvv.8 for ; Fri, 30 Oct 2020 14:03:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=kC1BvpNjGdLAI7Rfy9a66TcHawg1xO4t+0xXAe1Gyyg=; b=K8ZuRdHJXAJOo3oNKipwRYzLsAF0XXLv/Zg6v71kfr35uTMV5VWqpjtbXbNeg2BS3C UDBYYkf4n2ZE/Ick56pkPAJpkkRGNW1vr9i9QQPZjhRRuy7y6JPRTKvLqs4QJ1N8wknp 5wsfmh3EZ+p3OBIvrNvPIdIy/kWxEF1ZKjR2rJCZmfOHAU4ZK4+z1PM5I19edvaFfXK/ BHtePxgsVa3T4vjRnZaBIVqYZoR3edBvqlLEhJY4UdZ1zAcuf+13ox8/S7AFgg6M/AKG sR+JOjUgM5JOYpZO+Z4MuDRs3RcSzQfAQWHx9a8Nhq1QoXt6RXLGei7hQN/kIIVs8gz1 bR/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kC1BvpNjGdLAI7Rfy9a66TcHawg1xO4t+0xXAe1Gyyg=; b=kPGUle1XmI7eZfARSI58DC3xpIyHXLtFMQqI+mhUiahfXBZBeksWRkGMkQoC5XwBqf GL42ZJ9sh2WBk3hnK7MRua5YGQTDWwtzTWcPsiZ+MLjXb4qHoMKyXBKkHlNqCp53/uXl a1sDn2Otbp++K4LkJqAZCOwBceahZH4ouJ4jwS6ii8lKaO4GQKsyTHYJAZOepT3cnJft vnZ2hV6zWqaH8L+GXXuHHM0ob/Jywn5wdbXZ53nmRoO1PupPKcGr4uOMO7VyW3lpZiwg AkfMcF61ouCm2j2IqvQEMNSceE6t3oz/cxda8tEIChriUp3Fokmf8kasRg4+B859rRne yQRA== X-Gm-Message-State: AOAM533F4YHSOCp11eqipSp7+IMSSF/Psz+WHzWQqjFoYPGpn18VcOFy 36czYhBx/rfd1JM3fg352HOdTfEw7FoCiHeK X-Google-Smtp-Source: ABdhPJyr7udmF2ikf2L80m0aU1Hqz1r7GpKK0MX2d0QIgD8TCRQtC5v9KRar0NQd1UHcHiuVNGjYsw== X-Received: by 2002:a05:6214:1588:: with SMTP id m8mr11408953qvw.18.1604091807272; Fri, 30 Oct 2020 14:03:27 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id a3sm3396615qtp.63.2020.10.30.14.03.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 14:03:26 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 10/14] btrfs: use btrfs_read_node_slot in btrfs_qgroup_trace_subtree Date: Fri, 30 Oct 2020 17:03:02 -0400 Message-Id: <7a0adeab1bc81dbcd0199aa3108899890015f244.1604091530.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We're open-coding btrfs_read_node_slot() here, replace with the helper. Signed-off-by: Josef Bacik --- fs/btrfs/qgroup.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index ddd1cd6db6c4..0052b1c7d4c3 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2186,30 +2186,21 @@ int btrfs_qgroup_trace_subtree(struct btrfs_trans_handle *trans, level = root_level; while (level >= 0) { if (path->nodes[level] == NULL) { - struct btrfs_key first_key; int parent_slot; - u64 child_gen; u64 child_bytenr; /* - * We need to get child blockptr/gen from parent before - * we can read it. + * We need to get child blockptr from parent before we + * can read it. */ eb = path->nodes[level + 1]; parent_slot = path->slots[level + 1]; child_bytenr = btrfs_node_blockptr(eb, parent_slot); - child_gen = btrfs_node_ptr_generation(eb, parent_slot); - btrfs_node_key_to_cpu(eb, &first_key, parent_slot); - eb = read_tree_block(fs_info, child_bytenr, child_gen, - level, &first_key); + eb = btrfs_read_node_slot(eb, parent_slot); if (IS_ERR(eb)) { ret = PTR_ERR(eb); goto out; - } else if (!extent_buffer_uptodate(eb)) { - free_extent_buffer(eb); - ret = -EIO; - goto out; } path->nodes[level] = eb; From patchwork Fri Oct 30 21:03:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11870837 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E876C388F9 for ; Fri, 30 Oct 2020 21:03:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ABF3A20791 for ; Fri, 30 Oct 2020 21:03:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="M8VBYNej" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727739AbgJ3VDd (ORCPT ); Fri, 30 Oct 2020 17:03:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726917AbgJ3VDc (ORCPT ); Fri, 30 Oct 2020 17:03:32 -0400 Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF743C0613CF for ; Fri, 30 Oct 2020 14:03:30 -0700 (PDT) Received: by mail-qv1-xf36.google.com with SMTP id g13so3427814qvu.1 for ; Fri, 30 Oct 2020 14:03:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=UM46WmeG+KmciI8KpEDBOxs8xdJTIGNM8kEYfwY63vk=; b=M8VBYNej99jwrI+usWZtS1uuptwZUkTNbG+bO9ZwUpt9EO17D6P42AAg1KdZ23esS5 iHCwFykNiBBKaTbZtRnVsyPRnSQjudOJ+xwXfuwkp3K6G0Sul7BkPRytJDNLMyMbF7zr +cu1MTFe+thFSRZSEtEiAqq3Dbt3kYxEE3y0zVhlgRK13qsLh4Ohl+Q+LYHW1mBLjpYH /z3YJ0oo12GR/UmDQ0h9NFnu7lStiakpJBUgVJTEc9fbIEwZQFVeB/fas3z7eU9t4a/l AUcflMR4LHKqdVgc66IKX1M8ebrt8lZNCSW58bEIbLX1O5WqM71PeJbjE49Lv93n/D7z H5Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UM46WmeG+KmciI8KpEDBOxs8xdJTIGNM8kEYfwY63vk=; b=knk/WNdSNGWqV+0u8A+Xodi1OgG+d0BY4/biwNjNxfF11GAibbZ5DXvCP85He4pcTT b1GydmY08VAIRtcf88Z3gM6/2ypoXcA5kURvvhJbgt7r3x4JzjJiZMJOUP79zbWpjWls UO5vvw9drRHkeNu9tSm4DxkHDm++LzMnLNyl5PffSPDHFi8B4GMJUMimUe6jYdr648LR rLVgBGH/DhM/ivqHTuxTjt1uY0ME+NGWc+kXCFq9dr/VR2e9iodUIlQGnxevU0KIa7uh bOlkAfRn3raxyYGqM0tWaK+5e1/TEnunQlNE/CoNq5YdPk6egaCOeHAkeHDzpRXy+kX8 LKYQ== X-Gm-Message-State: AOAM532LVQKFbdE3RBIprxG9RbCDvmxzoUhOww/wsDxmTL+AvS7fXF4l V3858D9jzbNRucToyfLPegi2DWmdUI0mMvwm X-Google-Smtp-Source: ABdhPJzyO5903MzL0PgQHfr1CFTFkAsIr96P8GRv7jo5kjkBnR3fKQHrRZ5uu4VltxK5D2M6kQRrKg== X-Received: by 2002:a0c:db13:: with SMTP id d19mr10729643qvk.23.1604091809158; Fri, 30 Oct 2020 14:03:29 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id x191sm2802828qkb.53.2020.10.30.14.03.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 14:03:28 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 11/14] btrfs: pass root owner to read_tree_block Date: Fri, 30 Oct 2020 17:03:03 -0400 Message-Id: <21e67878c84457a9ea83e09c26a9a85c8281e6b6.1604091530.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In order to properly set the lockdep class of a newly allocated block we need to know the owner of the block. For non refcount'ed tree's this is straightforward, we always know in advance what tree we're reading from. For refcount'ed trees we don't necessarily know, however all refcount'ed trees share the same lockdep class name, tree-. Fix all of the callers of read_tree_block() to pass in the root objectid we're using. In places like relocation and backref we could probably unconditionally use 0, but just in case use the root when we have it, otherwise use 0 in the cases we don't have the root as it's going to be a refcount'ed tree anyway. This is a preparation patch for further changes. Signed-off-by: Josef Bacik --- fs/btrfs/backref.c | 6 +++--- fs/btrfs/ctree.c | 8 +++++--- fs/btrfs/disk-io.c | 14 +++++++++----- fs/btrfs/disk-io.h | 4 ++-- fs/btrfs/extent-tree.c | 4 ++-- fs/btrfs/print-tree.c | 1 + fs/btrfs/qgroup.c | 2 +- fs/btrfs/relocation.c | 4 ++-- 8 files changed, 25 insertions(+), 18 deletions(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 771a036867dc..23d01d152377 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -783,8 +783,8 @@ static int add_missing_keys(struct btrfs_fs_info *fs_info, BUG_ON(ref->key_for_search.type); BUG_ON(!ref->wanted_disk_byte); - eb = read_tree_block(fs_info, ref->wanted_disk_byte, 0, - ref->level - 1, NULL); + eb = read_tree_block(fs_info, ref->wanted_disk_byte, + ref->root_id, 0, ref->level - 1, NULL); if (IS_ERR(eb)) { free_pref(ref); return PTR_ERR(eb); @@ -1331,7 +1331,7 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans, struct extent_buffer *eb; eb = read_tree_block(fs_info, ref->parent, 0, - ref->level, NULL); + 0, ref->level, NULL); if (IS_ERR(eb)) { ret = PTR_ERR(eb); goto out; diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 000f18923c5a..c675bd8e8266 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -1356,7 +1356,8 @@ get_old_root(struct btrfs_root *root, u64 time_seq) if (old_root && tm && tm->op != MOD_LOG_KEY_REMOVE_WHILE_FREEING) { btrfs_tree_read_unlock(eb_root); free_extent_buffer(eb_root); - old = read_tree_block(fs_info, logical, 0, level, NULL); + old = read_tree_block(fs_info, logical, + root->root_key.objectid, 0, level, NULL); if (WARN_ON(IS_ERR(old) || !extent_buffer_uptodate(old))) { if (!IS_ERR(old)) free_extent_buffer(old); @@ -1774,6 +1775,7 @@ struct extent_buffer *btrfs_read_node_slot(struct extent_buffer *parent, btrfs_node_key_to_cpu(parent, &first_key, slot); eb = read_tree_block(parent->fs_info, btrfs_node_blockptr(parent, slot), + btrfs_header_owner(parent), btrfs_node_ptr_generation(parent, slot), level - 1, &first_key); if (!IS_ERR(eb) && !extent_buffer_uptodate(eb)) { @@ -2378,8 +2380,8 @@ read_block_for_search(struct btrfs_root *root, struct btrfs_path *p, reada_for_search(fs_info, p, level, slot, key->objectid); ret = -EAGAIN; - tmp = read_tree_block(fs_info, blocknr, gen, parent_level - 1, - &first_key); + tmp = read_tree_block(fs_info, blocknr, root->root_key.objectid, + gen, parent_level - 1, &first_key); if (!IS_ERR(tmp)) { /* * If the read above didn't mark this buffer up to date, diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 464dfb15b054..8a7f2b26e98a 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -959,13 +959,14 @@ struct extent_buffer *btrfs_find_create_tree_block( * Read tree block at logical address @bytenr and do variant basic but critical * verification. * + * @owner_root: the objectid of the root owner for this block. * @parent_transid: expected transid of this tree block, skip check if 0 * @level: expected level, mandatory check * @first_key: expected key in slot 0, skip check if NULL */ struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr, - u64 parent_transid, int level, - struct btrfs_key *first_key) + u64 owner_root, u64 parent_transid, + int level, struct btrfs_key *first_key) { struct extent_buffer *buf = NULL; int ret; @@ -1290,7 +1291,7 @@ static struct btrfs_root *read_tree_root_path(struct btrfs_root *tree_root, level = btrfs_root_level(&root->root_item); root->node = read_tree_block(fs_info, btrfs_root_bytenr(&root->root_item), - generation, level, NULL); + key->objectid, generation, level, NULL); if (IS_ERR(root->node)) { ret = PTR_ERR(root->node); root->node = NULL; @@ -2244,8 +2245,9 @@ static int btrfs_replay_log(struct btrfs_fs_info *fs_info, return -ENOMEM; log_tree_root->node = read_tree_block(fs_info, bytenr, - fs_info->generation + 1, - level, NULL); + BTRFS_TREE_LOG_OBJECTID, + fs_info->generation + 1, level, + NULL); if (IS_ERR(log_tree_root->node)) { btrfs_warn(fs_info, "failed to read log tree"); ret = PTR_ERR(log_tree_root->node); @@ -2631,6 +2633,7 @@ static int __cold init_tree_roots(struct btrfs_fs_info *fs_info) generation = btrfs_super_generation(sb); level = btrfs_super_root_level(sb); tree_root->node = read_tree_block(fs_info, btrfs_super_root(sb), + BTRFS_ROOT_TREE_OBJECTID, generation, level, NULL); if (IS_ERR(tree_root->node)) { handle_error = true; @@ -3117,6 +3120,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device chunk_root->node = read_tree_block(fs_info, btrfs_super_chunk_root(disk_super), + BTRFS_CHUNK_TREE_OBJECTID, generation, level, NULL); if (IS_ERR(chunk_root->node) || !extent_buffer_uptodate(chunk_root->node)) { diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index 34934f38582b..f3bc5ff8a8cf 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -43,8 +43,8 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info); int btrfs_verify_level_key(struct extent_buffer *eb, int level, struct btrfs_key *first_key, u64 parent_transid); struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr, - u64 parent_transid, int level, - struct btrfs_key *first_key); + u64 owner_root, u64 parent_transid, + int level, struct btrfs_key *first_key); struct extent_buffer *btrfs_find_create_tree_block( struct btrfs_fs_info *fs_info, u64 bytenr); diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 0ca1135dab8c..898b26f1a391 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5124,8 +5124,8 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, if (!next) { if (reada && level == 1) reada_walk_down(trans, root, wc, path); - next = read_tree_block(fs_info, bytenr, generation, level - 1, - &first_key); + next = read_tree_block(fs_info, bytenr, root->root_key.objectid, + generation, level - 1, &first_key); if (IS_ERR(next)) { return PTR_ERR(next); } else if (!extent_buffer_uptodate(next)) { diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c index 48b57dd57436..5b8c03985226 100644 --- a/fs/btrfs/print-tree.c +++ b/fs/btrfs/print-tree.c @@ -391,6 +391,7 @@ void btrfs_print_tree(struct extent_buffer *c, bool follow) btrfs_node_key_to_cpu(c, &first_key, i); next = read_tree_block(fs_info, btrfs_node_blockptr(c, i), + btrfs_header_owner(c), btrfs_node_ptr_generation(c, i), level - 1, &first_key); if (IS_ERR(next)) { diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 0052b1c7d4c3..959ff4ed9df6 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -4145,7 +4145,7 @@ int btrfs_qgroup_trace_subtree_after_cow(struct btrfs_trans_handle *trans, spin_unlock(&blocks->lock); /* Read out reloc subtree root */ - reloc_eb = read_tree_block(fs_info, block->reloc_bytenr, + reloc_eb = read_tree_block(fs_info, block->reloc_bytenr, 0, block->reloc_generation, block->level, &block->first_key); if (IS_ERR(reloc_eb)) { diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 55a745cb28d4..48a95a115149 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2417,7 +2417,7 @@ static int get_tree_block_key(struct btrfs_fs_info *fs_info, { struct extent_buffer *eb; - eb = read_tree_block(fs_info, block->bytenr, block->key.offset, + eb = read_tree_block(fs_info, block->bytenr, 0, block->key.offset, block->level, NULL); if (IS_ERR(eb)) { return PTR_ERR(eb); @@ -3043,7 +3043,7 @@ int add_data_references(struct reloc_control *rc, while ((ref_node = ulist_next(leaves, &leaf_uiter))) { struct extent_buffer *eb; - eb = read_tree_block(fs_info, ref_node->val, 0, 0, NULL); + eb = read_tree_block(fs_info, ref_node->val, 0, 0, 0, NULL); if (IS_ERR(eb)) { ret = PTR_ERR(eb); break; From patchwork Fri Oct 30 21:03:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11870843 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9083C00A89 for ; Fri, 30 Oct 2020 21:03:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7427B2076D for ; Fri, 30 Oct 2020 21:03:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="jEJVzNkn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727736AbgJ3VDc (ORCPT ); Fri, 30 Oct 2020 17:03:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727732AbgJ3VDc (ORCPT ); Fri, 30 Oct 2020 17:03:32 -0400 Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1B44C0613D2 for ; Fri, 30 Oct 2020 14:03:31 -0700 (PDT) Received: by mail-qt1-x844.google.com with SMTP id h12so5180455qtu.1 for ; Fri, 30 Oct 2020 14:03:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=5ZEVCZsB8BcQMqzEFVB5tNTMAaMa97cVIIYifJmf9KA=; b=jEJVzNknQXURMVS5NVN7IomvuwjtRR4SsM7bR6NsEo7DBuFwhlQnCnelemDJHUgwix 4kheoW6BFhMyCFRRhzNsVUDGKwgxuxTmZscRR9wd92Immu3SYvHgvSg3DzLrDhVJkWLe oXWnfFoeVZTSBL6l1TSkiWEE0JjrzdlJG4jsQDZBtXIm1KNVY/LcDpLhb7+k5UWZyGYX YNihSXQ25T07IIQayNM1/sVRgZxBAok7Z9gycBDKVEb0137eGrfA/LRqzxU3sgNpqptQ RN8D2976PoVdUUkbJ+fOSmuagpIXn05rsJWKeYj0pa1k4cuHaBw4PK2UgHdeljQE/2MN QNog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5ZEVCZsB8BcQMqzEFVB5tNTMAaMa97cVIIYifJmf9KA=; b=ct4yLFehrrqG0N7nQ+b9e3ipyU32yyTt41saHEPWWY5es+XzTI8Pyuhx+WcPchEh6M 1L+bsb7lLSkAt2dPdQLOJ6T9d6wZ2peaaiA1QpVn1WIKqMrbqyEz8VhYTwKhmINXYScS e/ji+batR3anPvHaByrD8SJsOm2udi3kMF5vJJGXd9UKFABLGPqoP4Wuo3mMQy9BEGy3 iWVMRCDiCV515L/OLxZ/6MBy8PWgRnEta+675YKc3ELxOnydttv1A73CvsD1Cgq418dr DYsAfzWd4PMGCTXkdJ4/mz0AcSjox2zhlFCcPnmfdtO60Ca2ZQeg+6xTvFSnebjkbhzv lerQ== X-Gm-Message-State: AOAM532W0jvsH8JiX05nHm5TGFjv2xBkR2ENSaA+YXDUfkTEVkQB1EpT GYAstpHE0tx+uRm93urOVJCP2Hv8QtE01GxG X-Google-Smtp-Source: ABdhPJxy2xTTIVOm+Kl1Qh2z2I4TloTuf6WZLh8Ub9qm2g+vCiJ4kcbPQBcRl9+vr+IdO6Z+fvEnpg== X-Received: by 2002:ac8:3975:: with SMTP id t50mr4117095qtb.53.1604091810884; Fri, 30 Oct 2020 14:03:30 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id b8sm3304288qkn.133.2020.10.30.14.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 14:03:30 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 12/14] btrfs: pass the root owner and level around for reada Date: Fri, 30 Oct 2020 17:03:04 -0400 Message-Id: <2f3fa423ef57986c74b110bb6141cf17c9e44b40.1604091530.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The reada infrastructure does raw reads of extent buffers, but we're going to need to know their owner and level in order to set the lockdep key properly, so plumb in the infrastructure that we'll need to have this information when we start allocating extent buffers. Signed-off-by: Josef Bacik --- fs/btrfs/reada.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c index 6e33cb755fa5..83f4e6c53e46 100644 --- a/fs/btrfs/reada.c +++ b/fs/btrfs/reada.c @@ -52,6 +52,7 @@ struct reada_extctl { struct reada_extent { u64 logical; + u64 owner_root; struct btrfs_key top; struct list_head extctl; int refcnt; @@ -59,6 +60,7 @@ struct reada_extent { struct reada_zone *zones[BTRFS_MAX_MIRRORS]; int nzones; int scheduled; + int level; }; struct reada_zone { @@ -87,7 +89,8 @@ static void reada_start_machine(struct btrfs_fs_info *fs_info); static void __reada_start_machine(struct btrfs_fs_info *fs_info); static int reada_add_block(struct reada_control *rc, u64 logical, - struct btrfs_key *top, u64 generation); + struct btrfs_key *top, u64 owner_root, + u64 generation, int level); /* recurses */ /* in case of err, eb might be NULL */ @@ -165,7 +168,9 @@ static void __readahead_hook(struct btrfs_fs_info *fs_info, if (rec->generation == generation && btrfs_comp_cpu_keys(&key, &rc->key_end) < 0 && btrfs_comp_cpu_keys(&next_key, &rc->key_start) > 0) - reada_add_block(rc, bytenr, &next_key, n_gen); + reada_add_block(rc, bytenr, &next_key, + btrfs_header_owner(eb), n_gen, + btrfs_header_level(eb) - 1); } } @@ -298,7 +303,8 @@ static struct reada_zone *reada_find_zone(struct btrfs_device *dev, u64 logical, static struct reada_extent *reada_find_extent(struct btrfs_fs_info *fs_info, u64 logical, - struct btrfs_key *top) + struct btrfs_key *top, + u64 owner_root, int level) { int ret; struct reada_extent *re = NULL; @@ -331,6 +337,8 @@ static struct reada_extent *reada_find_extent(struct btrfs_fs_info *fs_info, INIT_LIST_HEAD(&re->extctl); spin_lock_init(&re->lock); re->refcnt = 1; + re->owner_root = owner_root; + re->level = level; /* * map block @@ -548,14 +556,15 @@ static void reada_control_release(struct kref *kref) } static int reada_add_block(struct reada_control *rc, u64 logical, - struct btrfs_key *top, u64 generation) + struct btrfs_key *top, u64 owner_root, + u64 generation, int level) { struct btrfs_fs_info *fs_info = rc->fs_info; struct reada_extent *re; struct reada_extctl *rec; /* takes one ref */ - re = reada_find_extent(fs_info, logical, top); + re = reada_find_extent(fs_info, logical, top, owner_root, level); if (!re) return -1; @@ -947,6 +956,7 @@ struct reada_control *btrfs_reada_add(struct btrfs_root *root, u64 start; u64 generation; int ret; + int level; struct extent_buffer *node; static struct btrfs_key max_key = { .objectid = (u64)-1, @@ -969,9 +979,11 @@ struct reada_control *btrfs_reada_add(struct btrfs_root *root, node = btrfs_root_node(root); start = node->start; generation = btrfs_header_generation(node); + level = btrfs_header_level(node); free_extent_buffer(node); - ret = reada_add_block(rc, start, &max_key, generation); + ret = reada_add_block(rc, start, &max_key, + root->root_key.objectid, generation, level); if (ret) { kfree(rc); return ERR_PTR(ret); From patchwork Fri Oct 30 21:03:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11870841 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC504C388F9 for ; Fri, 30 Oct 2020 21:03:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 81E882076D for ; Fri, 30 Oct 2020 21:03:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="p8eyVHCS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727744AbgJ3VDg (ORCPT ); Fri, 30 Oct 2020 17:03:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726917AbgJ3VDg (ORCPT ); Fri, 30 Oct 2020 17:03:36 -0400 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2BECC0613CF for ; Fri, 30 Oct 2020 14:03:34 -0700 (PDT) Received: by mail-qt1-x843.google.com with SMTP id s39so5171016qtb.2 for ; Fri, 30 Oct 2020 14:03:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=/r/I+VsSzk0lIq2a7CMlUV12p+ExOV3xq+9TM7jXnBM=; b=p8eyVHCS/GhIuPn8Rke+9alQG14NjF08FJg/YPTxwiiUX72Ex/S79Y49ixzDGDcDe2 6M8ULbhAxxO8jXf9arUsYpweA8tMQpNduEX+V++WRy9W0YiTf8LMHdoodfAz9NYZzrci ovZHqG96Gqu+l0W4EAuyR6S7xlZQ8tpOW93Xngs0a5HjTszo0isFgvYjgTAt/YPPJz7r SqoPSqIuuBqgMe7MWxzfxHBB35tYDAidXnnxiW+OnDuF9Wzg92tssX36ikUm4cRP8UIH dOvCfG3Bh8Ho/KlXPULGdU4IFOElcPZPxg2DfHoXM6NmTAM0atbdGsVlBPmM5YrrhXj7 B0Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/r/I+VsSzk0lIq2a7CMlUV12p+ExOV3xq+9TM7jXnBM=; b=qnOJ7BbMx4aEELKgv3wT9tH/0vPPcmhK+ZQFxy2kReCjZO1QTglFpQwWA8FP2OCDJu Vzs2d9Q26XGhXcdx2GIorh0pKtH4KmXoNIDZwjjk/LD/8xz0b4NRKMINiKMtgiih0aZk 6Mn8nOiW0XsC5NY2cuP2hL7wj24LPSKFA9DkJITP/TWa46O9Ac/pTVgoyt4JKUQUFPji Al78Fjx4k8JNsajkwNQCPFeoBOJiiImmqDQERFTvByEFS/AaSfG5k8hAnJkIy95uADjc teIqpp+M2qWalqh9te8WCYbc8iYtENEjHGYbkBdCBIktfmyhec4+j1kpjhlJBa4rn7wT fmZQ== X-Gm-Message-State: AOAM533lr3rwlj0ZevYUxn5wBKW5vettYe0togn5x/Okt7+o4VWjS27M WcOEtP8Ou8P6Q2hLe0dDCqN2azLWmWc2PPDz X-Google-Smtp-Source: ABdhPJz5PjJHUC9nGD9q87fY1rWMofOLJpCgV2koPEqdwX9b6U176g/wui3U/cVR9rVU/RYUhPrf0g== X-Received: by 2002:ac8:7758:: with SMTP id g24mr4104964qtu.307.1604091813428; Fri, 30 Oct 2020 14:03:33 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id t45sm1175985qte.44.2020.10.30.14.03.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 14:03:32 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 13/14] btrfs: pass the owner_root and level to alloc_extent_buffer Date: Fri, 30 Oct 2020 17:03:05 -0400 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Now that we've plumbed all of the callers to have the owner root and the level, plumb it down into alloc_extent_buffer(). Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 7 ++++--- fs/btrfs/disk-io.h | 3 ++- fs/btrfs/extent-tree.c | 6 ++++-- fs/btrfs/extent_io.c | 13 +++++++++---- fs/btrfs/extent_io.h | 5 +++-- fs/btrfs/reada.c | 8 +++++--- fs/btrfs/relocation.c | 3 ++- fs/btrfs/tree-log.c | 4 +++- fs/btrfs/volumes.c | 3 ++- 9 files changed, 34 insertions(+), 18 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 8a7f2b26e98a..989412501a92 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -948,11 +948,12 @@ static const struct address_space_operations btree_aops = { struct extent_buffer *btrfs_find_create_tree_block( struct btrfs_fs_info *fs_info, - u64 bytenr) + u64 bytenr, u64 owner_root, + int level) { if (btrfs_is_testing(fs_info)) return alloc_test_extent_buffer(fs_info, bytenr); - return alloc_extent_buffer(fs_info, bytenr); + return alloc_extent_buffer(fs_info, bytenr, owner_root, level); } /* @@ -971,7 +972,7 @@ struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr, struct extent_buffer *buf = NULL; int ret; - buf = btrfs_find_create_tree_block(fs_info, bytenr); + buf = btrfs_find_create_tree_block(fs_info, bytenr, owner_root, level); if (IS_ERR(buf)) return buf; diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index f3bc5ff8a8cf..740667700e6c 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -47,7 +47,8 @@ struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr, int level, struct btrfs_key *first_key); struct extent_buffer *btrfs_find_create_tree_block( struct btrfs_fs_info *fs_info, - u64 bytenr); + u64 bytenr, u64 owner_root, + int level); void btrfs_clean_tree_block(struct extent_buffer *buf); int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_devices, diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 898b26f1a391..a2c611a83057 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4662,7 +4662,7 @@ btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_fs_info *fs_info = root->fs_info; struct extent_buffer *buf; - buf = btrfs_find_create_tree_block(fs_info, bytenr); + buf = btrfs_find_create_tree_block(fs_info, bytenr, owner, level); if (IS_ERR(buf)) return buf; @@ -5064,7 +5064,9 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, next = find_extent_buffer(fs_info, bytenr); if (!next) { - next = btrfs_find_create_tree_block(fs_info, bytenr); + next = btrfs_find_create_tree_block(fs_info, bytenr, + root->root_key.objectid, + level - 1); if (IS_ERR(next)) return PTR_ERR(next); diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 654e2e517f3d..0af8333ccca1 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -5163,7 +5163,7 @@ struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info, #endif struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info, - u64 start) + u64 start, u64 owner_root, int level) { unsigned long len = fs_info->nodesize; int num_pages; @@ -6111,19 +6111,22 @@ int try_release_extent_buffer(struct page *page) * btrfs_readahead_tree_block - attempt to readahead a child block. * @fs_info - the fs_info for the fs. * @bytenr - the bytenr to read. + * @owner_root - the objectid of the root that owns this eb. * @gen - the generation for the uptodate check, can be 0. + * @level - the level for the eb. * * Attempt to readahead a tree block at @bytenr. If @gen is 0 then we do a * normal uptodate check of the eb, without checking the generation. If we have * to read the block we will not block on anything. */ void btrfs_readahead_tree_block(struct btrfs_fs_info *fs_info, - u64 bytenr, u64 gen) + u64 bytenr, u64 owner_root, u64 gen, + int level) { struct extent_buffer *eb; int ret; - eb = btrfs_find_create_tree_block(fs_info, bytenr); + eb = btrfs_find_create_tree_block(fs_info, bytenr, owner_root, level); if (IS_ERR(eb)) return; @@ -6151,5 +6154,7 @@ void btrfs_readahead_node_child(struct extent_buffer *node, int slot) { btrfs_readahead_tree_block(node->fs_info, btrfs_node_blockptr(node, slot), - btrfs_node_ptr_generation(node, slot)); + btrfs_header_owner(node), + btrfs_node_ptr_generation(node, slot), + btrfs_header_level(node) - 1); } diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index 4f95b087a901..9e97d28f2d8f 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -182,7 +182,7 @@ int extent_fiemap(struct btrfs_inode *inode, struct fiemap_extent_info *fieinfo, void set_page_extent_mapped(struct page *page); struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info, - u64 start); + u64 start, u64 owner_root, int level); struct extent_buffer *__alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info, u64 start, unsigned long len); struct extent_buffer *alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info, @@ -199,7 +199,8 @@ int read_extent_buffer_pages(struct extent_buffer *eb, int wait, int mirror_num); void wait_on_extent_buffer_writeback(struct extent_buffer *eb); void btrfs_readahead_tree_block(struct btrfs_fs_info *fs_info, - u64 bytenr, u64 gen); + u64 bytenr, u64 owner_root, u64 gen, + int level); void btrfs_readahead_node_child(struct extent_buffer *node, int slot); static inline int num_extent_pages(const struct extent_buffer *eb) diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c index 83f4e6c53e46..8f26b3b22308 100644 --- a/fs/btrfs/reada.c +++ b/fs/btrfs/reada.c @@ -656,12 +656,13 @@ static int reada_pick_zone(struct btrfs_device *dev) } static int reada_tree_block_flagged(struct btrfs_fs_info *fs_info, u64 bytenr, - int mirror_num, struct extent_buffer **eb) + u64 owner_root, int level, int mirror_num, + struct extent_buffer **eb) { struct extent_buffer *buf = NULL; int ret; - buf = btrfs_find_create_tree_block(fs_info, bytenr); + buf = btrfs_find_create_tree_block(fs_info, bytenr, owner_root, level); if (IS_ERR(buf)) return 0; @@ -749,7 +750,8 @@ static int reada_start_machine_dev(struct btrfs_device *dev) logical = re->logical; atomic_inc(&dev->reada_in_flight); - ret = reada_tree_block_flagged(fs_info, logical, mirror_num, &eb); + ret = reada_tree_block_flagged(fs_info, logical, re->owner_root, + re->level, mirror_num, &eb); if (ret) __readahead_hook(fs_info, re, NULL, ret); else if (eb) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 48a95a115149..7954f2389d70 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2518,7 +2518,8 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans, rbtree_postorder_for_each_entry_safe(block, next, blocks, rb_node) { if (!block->key_ready) btrfs_readahead_tree_block(fs_info, - block->bytenr, 0); + block->bytenr, 0, 0, + block->level); } /* Get first keys */ diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 135cb40295c1..0db96c263c94 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -2699,7 +2699,9 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans, btrfs_node_key_to_cpu(cur, &first_key, path->slots[*level]); blocksize = fs_info->nodesize; - next = btrfs_find_create_tree_block(fs_info, bytenr); + next = btrfs_find_create_tree_block(fs_info, bytenr, + btrfs_header_owner(cur), + *level - 1); if (IS_ERR(next)) return PTR_ERR(next); diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 75350c78ca02..9ef1a51379e9 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6909,7 +6909,8 @@ int btrfs_read_sys_array(struct btrfs_fs_info *fs_info) * fixed to BTRFS_SUPER_INFO_SIZE. If nodesize > sb size, this will * overallocate but we can keep it as-is, only the first page is used. */ - sb = btrfs_find_create_tree_block(fs_info, BTRFS_SUPER_INFO_OFFSET); + sb = btrfs_find_create_tree_block(fs_info, BTRFS_SUPER_INFO_OFFSET, + root->root_key.objectid, 0); if (IS_ERR(sb)) return PTR_ERR(sb); set_extent_buffer_uptodate(sb); From patchwork Fri Oct 30 21:03:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11870847 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA27EC4742C for ; Fri, 30 Oct 2020 21:03:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 72D212076D for ; Fri, 30 Oct 2020 21:03:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="HhUAIN+v" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727748AbgJ3VDi (ORCPT ); Fri, 30 Oct 2020 17:03:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726917AbgJ3VDi (ORCPT ); Fri, 30 Oct 2020 17:03:38 -0400 Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7502AC0613CF for ; Fri, 30 Oct 2020 14:03:36 -0700 (PDT) Received: by mail-qt1-x844.google.com with SMTP id s39so5171080qtb.2 for ; Fri, 30 Oct 2020 14:03:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=s7FiwgcGjSfDhX/Lpxflgb2UTT8b3aN4mUKTmLw4FpI=; b=HhUAIN+v5dzKMzIILYF6xWB6w6bPeScf2FvidW8ZE4rAFbmaAbI6bDU9xMBSySmMHW oY1VSg9aoIY4d+bMV5Pk1OKWvRSYGyT9nbW9CT/VY6W1J2Jo2xTlkbSwR4r7ig2JrY5M C7lzZfrwgt6Zb4x/9R0If8PyrDxtA+Sfcn/A2Ld8EJZ70V2M9a32ZEJVcRQyfxb+QeQT C/Te3wA+ZnpAF23yKDeWxeadYAhkMb15rR1/6R/SVhNVF2uAeAx2sdqc+a4fBeVSLpCu Hhjc1JwDPb+9oFA6VLdHlvzZw/Udjuo6XrNUx2rlzFpY/M9zM/kIwi6E+BEMhkjjyL75 kahA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=s7FiwgcGjSfDhX/Lpxflgb2UTT8b3aN4mUKTmLw4FpI=; b=FM7fHHrs6r7rX+Trxnj8kPs0s0P4Krx2Vq62RWrgAj4tz7+SqueexGSJoYZXfJguFY Uq7jTsB7q7nsdKG1gXEELVjSnlRU8YePRT0Y63CYZ0LyH1lqVpsFfwnh//Mu2cs3s6w7 Eh7vgj609iX1IXcJ01UDiTsFt1Vd9Ov+m0Y6MEDsNZd3HleUewuvBWUdMt8TShHhJLjT 2d2bzaE71o+SsSz+qn1+iE4kqv3/9aLXFsddVIgSpHtlQUgFzRQwZs4adHGx2iYMjVMH I4oMz/+CFTfV/izlDCtutlE/z5v88gIjmNbaAPsA5L+mMkgAcP7A8JYZ4g1yB7vHtogg iiqQ== X-Gm-Message-State: AOAM530leeZRG68mxw/ZaNEUq75j1qQBw0zSlNlcS9MWiZIKbDJ57rLw 4RYKXAWQlTSQyF+Oap/EAzstwKKv5N/C5N31 X-Google-Smtp-Source: ABdhPJzNelHSXcB80f7t7v0c3qMoqACh7Pq/HKXFfgFYuykCNtj/MOxNrXcNjDdigZJszU1ltTBGuw== X-Received: by 2002:ac8:5916:: with SMTP id 22mr4061842qty.352.1604091815220; Fri, 30 Oct 2020 14:03:35 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id z26sm3290419qki.40.2020.10.30.14.03.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 14:03:34 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 14/14] btrfs: set the lockdep class for ebs on creation Date: Fri, 30 Oct 2020 17:03:06 -0400 Message-Id: <684352674d9bc1db4373af4b94cbe56667f90503.1604091530.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Both Filipe and Fedora QA recently hit the following lockdep splat WARNING: possible recursive locking detected 5.10.0-0.rc1.20201028gited8780e3f2ec.57.fc34.x86_64 #1 Not tainted -------------------------------------------- rsync/2610 is trying to acquire lock: ffff89617ed48f20 (&eb->lock){++++}-{2:2}, at: btrfs_tree_read_lock_atomic+0x34/0x140 but task is already holding lock: ffff8961757b1130 (&eb->lock){++++}-{2:2}, at: btrfs_tree_read_lock_atomic+0x34/0x140 other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&eb->lock); lock(&eb->lock); *** DEADLOCK *** May be due to missing lock nesting notation 2 locks held by rsync/2610: #0: ffff896107212b90 (&type->i_mutex_dir_key#10){++++}-{3:3}, at: walk_component+0x10c/0x190 #1: ffff8961757b1130 (&eb->lock){++++}-{2:2}, at: btrfs_tree_read_lock_atomic+0x34/0x140 stack backtrace: CPU: 1 PID: 2610 Comm: rsync Not tainted 5.10.0-0.rc1.20201028gited8780e3f2ec.57.fc34.x86_64 #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 0.0.0 02/06/2015 Call Trace: dump_stack+0x8b/0xb0 __lock_acquire.cold+0x12d/0x2a4 ? kvm_sched_clock_read+0x14/0x30 ? sched_clock+0x5/0x10 lock_acquire+0xc8/0x400 ? btrfs_tree_read_lock_atomic+0x34/0x140 ? read_block_for_search.isra.0+0xdd/0x320 _raw_read_lock+0x3d/0xa0 ? btrfs_tree_read_lock_atomic+0x34/0x140 btrfs_tree_read_lock_atomic+0x34/0x140 btrfs_search_slot+0x616/0x9a0 btrfs_lookup_dir_item+0x6c/0xb0 btrfs_lookup_dentry+0xa8/0x520 ? lockdep_init_map_waits+0x4c/0x210 btrfs_lookup+0xe/0x30 __lookup_slow+0x10f/0x1e0 walk_component+0x11b/0x190 path_lookupat+0x72/0x1c0 filename_lookup+0x97/0x180 ? strncpy_from_user+0x96/0x1e0 ? getname_flags.part.0+0x45/0x1a0 vfs_statx+0x64/0x100 ? lockdep_hardirqs_on_prepare+0xff/0x180 ? _raw_spin_unlock_irqrestore+0x41/0x50 __do_sys_newlstat+0x26/0x40 ? lockdep_hardirqs_on_prepare+0xff/0x180 ? syscall_enter_from_user_mode+0x27/0x80 ? syscall_enter_from_user_mode+0x27/0x80 do_syscall_64+0x33/0x40 entry_SYSCALL_64_after_hwframe+0x44/0xa9 I have also seen a report of lockdep complaining about the lock class that was looked up being the same as the lock class on the lock we were using, but I can't find the report. These are problems that occur because we do not have the lockdep class set on the extent buffer until _after_ we read the eb in properly. This is problematic for concurrent readers, because we will create the extent buffer, lock it, and then attempt to read the extent buffer. If a second thread comes in and tries to do a search down the same path they'll get the above lockdep splat because the class isn't set properly on the extent buffer. There was a good reason for this, we generally didn't know the real owner of the eb until we read it, specifically in refcount'ed roots. However now all refcount'ed roots have the same class name, so we no longer need to worry about this. For non-refcount'ed tree's we know which root we're on based on the parent. Fix this by setting the lockdep class on the eb at creation time instead of read time. This will fix the splat and the weirdness where the class changes in the middle of locking the block. Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 3 --- fs/btrfs/extent-tree.c | 8 +++++--- fs/btrfs/extent_io.c | 1 + fs/btrfs/volumes.c | 1 - 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 989412501a92..d8ce8bbb3a45 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -578,9 +578,6 @@ int btrfs_validate_metadata_buffer(struct btrfs_io_bio *io_bio, u64 phy_offset, goto err; } - btrfs_set_buffer_lockdep_class(btrfs_header_owner(eb), - eb, found_level); - csum_tree_block(eb, result); if (memcmp_extent_buffer(eb, result, 0, csum_size)) { diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index a2c611a83057..1ddd8f4e9564 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4679,6 +4679,11 @@ btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root, return ERR_PTR(-EUCLEAN); } + /* + * This needs to stay, because we could allocate a free'd block from an + * old tree into a new tree, so we need to make sure this new block is + * set to the appropriate level and owner. + */ btrfs_set_buffer_lockdep_class(owner, buf, level); __btrfs_tree_lock(buf, nest); btrfs_clean_tree_block(buf); @@ -5069,9 +5074,6 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, level - 1); if (IS_ERR(next)) return PTR_ERR(next); - - btrfs_set_buffer_lockdep_class(root->root_key.objectid, next, - level - 1); reada = 1; } btrfs_tree_lock(next); diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 0af8333ccca1..4e758d670fc1 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -5188,6 +5188,7 @@ struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info, eb = __alloc_extent_buffer(fs_info, start, len); if (!eb) return ERR_PTR(-ENOMEM); + btrfs_set_buffer_lockdep_class(owner_root, eb, level); num_pages = num_extent_pages(eb); for (i = 0; i < num_pages; i++, index++) { diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 9ef1a51379e9..ad244b44a3a1 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6914,7 +6914,6 @@ int btrfs_read_sys_array(struct btrfs_fs_info *fs_info) if (IS_ERR(sb)) return PTR_ERR(sb); set_extent_buffer_uptodate(sb); - btrfs_set_buffer_lockdep_class(root->root_key.objectid, sb, 0); /* * The sb extent buffer is artificial and just used to read the system array. * set_extent_buffer_uptodate() call does not properly mark all it's