All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 2/2] btrfs: tree-checker: Remove comprehensive root owner check
Date: Wed,  3 Apr 2019 19:59:19 +0800	[thread overview]
Message-ID: <20190403115919.17049-2-wqu@suse.com> (raw)
In-Reply-To: <20190403115919.17049-1-wqu@suse.com>

Commit 1ba98d086fe3 ("Btrfs: detect corruption when non-root leaf has
zero item") introduced comprehensive root owner checker.

However it's pretty expensive tree search to locate the owner root,
especially when it get reused by mandatory read and write time
tree-checker.

This patch will remove that check, and completely rely on owner based
empty leaf check, which is much faster and still works fine for most
case.

And since we skip the old root owner check, now write time tree check
can be merged with btrfs_check_leaf_full().

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/disk-io.c      |  2 +-
 fs/btrfs/tree-checker.c | 51 +++--------------------------------------
 fs/btrfs/tree-checker.h |  2 --
 3 files changed, 4 insertions(+), 51 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index c3b89584dad6..fddcf7d7c30c 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -539,7 +539,7 @@ static int csum_dirty_buffer(struct btrfs_fs_info *fs_info, struct page *page)
 	if (btrfs_header_level(eb))
 		err = btrfs_check_node(fs_info, eb);
 	else
-		err = btrfs_check_leaf_write(fs_info, eb);
+		err = btrfs_check_leaf_full(fs_info, eb);
 
 	if (err < 0) {
 		btrfs_err(fs_info,
diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c
index 204fe53c90aa..e325d4df5c23 100644
--- a/fs/btrfs/tree-checker.c
+++ b/fs/btrfs/tree-checker.c
@@ -812,8 +812,7 @@ static int check_leaf_item(struct extent_buffer *leaf,
 	return ret;
 }
 
-static int check_leaf(struct extent_buffer *leaf, bool check_item_data,
-		      bool check_empty_leaf)
+static int check_leaf(struct extent_buffer *leaf, bool check_item_data)
 {
 	struct btrfs_fs_info *fs_info = leaf->fs_info;
 	/* No valid key type is 0, so all key should be larger than this key */
@@ -839,7 +838,6 @@ static int check_leaf(struct extent_buffer *leaf, bool check_item_data,
 	 */
 	if (nritems == 0 && !btrfs_header_flag(leaf, BTRFS_HEADER_FLAG_RELOC)) {
 		u64 owner = btrfs_header_owner(leaf);
-		struct btrfs_root *check_root;
 
 		/* These trees must never be empty */
 		if (owner == BTRFS_ROOT_TREE_OBJECTID ||
@@ -853,38 +851,6 @@ static int check_leaf(struct extent_buffer *leaf, bool check_item_data,
 				    owner);
 			return -EUCLEAN;
 		}
-
-		/*
-		 * Don't check empty leaves at write time for trees where we
-		 * can't use @owner to indicate the right owner. This happens
-		 * for reloc trees or for a new commit root.
-		 */
-		if (!check_empty_leaf)
-			return 0;
-
-		key.objectid = owner;
-		key.type = BTRFS_ROOT_ITEM_KEY;
-		key.offset = (u64)-1;
-
-		check_root = btrfs_get_fs_root(fs_info, &key, false);
-		/*
-		 * The only reason we also check NULL here is that during
-		 * open_ctree() some roots has not yet been set up.
-		 */
-		if (!IS_ERR_OR_NULL(check_root)) {
-			struct extent_buffer *eb;
-
-			eb = btrfs_root_node(check_root);
-			/* if leaf is the root, then it's fine */
-			if (leaf != eb) {
-				generic_err(leaf, 0,
-		"invalid nritems, have %u should not be 0 for non-root leaf",
-					nritems);
-				free_extent_buffer(eb);
-				return -EUCLEAN;
-			}
-			free_extent_buffer(eb);
-		}
 		return 0;
 	}
 
@@ -982,24 +948,13 @@ static int check_leaf(struct extent_buffer *leaf, bool check_item_data,
 int btrfs_check_leaf_full(struct btrfs_fs_info *fs_info,
 			  struct extent_buffer *leaf)
 {
-	return check_leaf(leaf, true, true);
+	return check_leaf(leaf, true);
 }
 
 int btrfs_check_leaf_relaxed(struct btrfs_fs_info *fs_info,
 			     struct extent_buffer *leaf)
 {
-	return check_leaf(leaf, false, true);
-}
-
-/*
- * Write time specific leaf checker.
- * Don't check if the empty leaf belongs to a tree root. Mostly for balance
- * and new tree created in current transaction.
- */
-int btrfs_check_leaf_write(struct btrfs_fs_info *fs_info,
-			   struct extent_buffer *leaf)
-{
-	return check_leaf(leaf, true, false);
+	return check_leaf(leaf, false);
 }
 
 int btrfs_check_node(struct btrfs_fs_info *fs_info, struct extent_buffer *node)
diff --git a/fs/btrfs/tree-checker.h b/fs/btrfs/tree-checker.h
index 281eb7136bc1..4df45e8a6659 100644
--- a/fs/btrfs/tree-checker.h
+++ b/fs/btrfs/tree-checker.h
@@ -23,8 +23,6 @@ int btrfs_check_leaf_full(struct btrfs_fs_info *fs_info,
  */
 int btrfs_check_leaf_relaxed(struct btrfs_fs_info *fs_info,
 			     struct extent_buffer *leaf);
-int btrfs_check_leaf_write(struct btrfs_fs_info *fs_info,
-			   struct extent_buffer *leaf);
 int btrfs_check_node(struct btrfs_fs_info *fs_info, struct extent_buffer *node);
 
 int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
-- 
2.21.0


  reply	other threads:[~2019-04-03 11:59 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-03 11:59 [PATCH 1/2] btrfs: tree-checker: Make write time tree checker verify the content of leaves Qu Wenruo
2019-04-03 11:59 ` Qu Wenruo [this message]
2019-04-03 14:21   ` [PATCH 2/2] btrfs: tree-checker: Remove comprehensive root owner check David Sterba
2019-04-03 14:26     ` Qu Wenruo
2019-04-03 15:00       ` David Sterba
2019-04-03 14:22   ` Nikolay Borisov
2019-04-03 14:12 ` [PATCH 1/2] btrfs: tree-checker: Make write time tree checker verify the content of leaves Nikolay Borisov
2019-04-03 14:20   ` Qu Wenruo
2019-04-03 14:13 ` David Sterba
2019-04-03 14:15   ` Qu Wenruo
2019-04-03 14:25     ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190403115919.17049-2-wqu@suse.com \
    --to=wqu@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.