All of lore.kernel.org
 help / color / mirror / Atom feed
From: Su Yue <suy.fnst@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: <quwenruo.btrfs@gmx.com>, <suy.fnst@cn.fujitsu.com>
Subject: [PATCH v2 04/17] btrfs-progs: lowmem check: exclude extents of metadata blocks
Date: Wed, 20 Dec 2017 12:57:18 +0800	[thread overview]
Message-ID: <20171220045731.19343-5-suy.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <20171220045731.19343-1-suy.fnst@cn.fujitsu.com>

Commit d17d6663c99c ("btrfs-progs: lowmem check: Fix regression which
screws up extent allocator") removes pin_metadata_blocks() from
lowmem repair.
So we have to find another way to exclude extents which should be
occupied by tree blocks.

Modify pin_down_tree_blocks() only for code reuse.
So behavior of pin_metadata_blocks() which works with option
'init-extent-tree' is not influenced.

Introduce exclude_blocks_and_extent_items() to mark extents of all tree
blocks dirty in fs_info->excluded_extents.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 cmds-check.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 63 insertions(+), 10 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index 1f06f0a0ea61..dd46569f3811 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -13537,40 +13537,54 @@ init:
 	return 0;
 }
 
-static int pin_down_tree_blocks(struct btrfs_fs_info *fs_info,
-				struct extent_buffer *eb, int tree_root)
+static int traverse_tree_blocks(struct btrfs_fs_info *fs_info,
+				struct extent_buffer *eb, int tree_root,
+				int pin)
 {
 	struct extent_buffer *tmp;
 	struct btrfs_root_item *ri;
 	struct btrfs_key key;
+	struct extent_io_tree *tree;
 	u64 bytenr;
 	int level = btrfs_header_level(eb);
 	int nritems;
 	int ret;
 	int i;
+	u64 end = eb->start + eb->len;
 
+	if (pin)
+		tree = &fs_info->pinned_extents;
+	else
+		tree = fs_info->excluded_extents;
 	/*
-	 * If we have pinned this block before, don't pin it again.
+	 * If we have pinned/excluded this block before, don't do it again.
 	 * This can not only avoid forever loop with broken filesystem
 	 * but also give us some speedups.
 	 */
-	if (test_range_bit(&fs_info->pinned_extents, eb->start,
-			   eb->start + eb->len - 1, EXTENT_DIRTY, 0))
+	if (test_range_bit(tree, eb->start, end - 1, EXTENT_DIRTY, 0))
 		return 0;
 
-	btrfs_pin_extent(fs_info, eb->start, eb->len);
+	if (pin)
+		btrfs_pin_extent(fs_info, eb->start, eb->len);
+	else
+		set_extent_dirty(tree, eb->start, end - 1);
 
 	nritems = btrfs_header_nritems(eb);
 	for (i = 0; i < nritems; i++) {
 		if (level == 0) {
+			bool is_extent_root;
 			btrfs_item_key_to_cpu(eb, &key, i);
 			if (key.type != BTRFS_ROOT_ITEM_KEY)
 				continue;
 			/* Skip the extent root and reloc roots */
-			if (key.objectid == BTRFS_EXTENT_TREE_OBJECTID ||
-			    key.objectid == BTRFS_TREE_RELOC_OBJECTID ||
+			if (key.objectid == BTRFS_TREE_RELOC_OBJECTID ||
 			    key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID)
 				continue;
+			is_extent_root =
+				key.objectid == BTRFS_EXTENT_TREE_OBJECTID;
+			/* If pin, skip the extent root */
+			if (pin && is_extent_root)
+				continue;
 			ri = btrfs_item_ptr(eb, i, struct btrfs_root_item);
 			bytenr = btrfs_disk_root_bytenr(eb, ri);
 
@@ -13585,7 +13599,7 @@ static int pin_down_tree_blocks(struct btrfs_fs_info *fs_info,
 				fprintf(stderr, "Error reading root block\n");
 				return -EIO;
 			}
-			ret = pin_down_tree_blocks(fs_info, tmp, 0);
+			ret = traverse_tree_blocks(fs_info, tmp, 0, pin);
 			free_extent_buffer(tmp);
 			if (ret)
 				return ret;
@@ -13604,7 +13618,8 @@ static int pin_down_tree_blocks(struct btrfs_fs_info *fs_info,
 				fprintf(stderr, "Error reading tree block\n");
 				return -EIO;
 			}
-			ret = pin_down_tree_blocks(fs_info, tmp, tree_root);
+			ret = traverse_tree_blocks(fs_info, tmp, tree_root,
+						   pin);
 			free_extent_buffer(tmp);
 			if (ret)
 				return ret;
@@ -13614,6 +13629,12 @@ static int pin_down_tree_blocks(struct btrfs_fs_info *fs_info,
 	return 0;
 }
 
+static int pin_down_tree_blocks(struct btrfs_fs_info *fs_info,
+				struct extent_buffer *eb, int tree_root)
+{
+	return traverse_tree_blocks(fs_info, eb, tree_root, 1);
+}
+
 static int pin_metadata_blocks(struct btrfs_fs_info *fs_info)
 {
 	int ret;
@@ -13625,6 +13646,38 @@ static int pin_metadata_blocks(struct btrfs_fs_info *fs_info)
 	return pin_down_tree_blocks(fs_info, fs_info->tree_root->node, 1);
 }
 
+static int exclude_tree_blocks(struct btrfs_fs_info *fs_info,
+				struct extent_buffer *eb, int tree_root)
+{
+	return traverse_tree_blocks(fs_info, eb, tree_root, 0);
+}
+
+static int exclude_metadata_blocks(struct btrfs_fs_info *fs_info)
+{
+	int ret;
+	struct extent_io_tree *excluded_extents;
+
+	excluded_extents = malloc(sizeof(*excluded_extents));
+	if (!excluded_extents)
+		return -ENOMEM;
+	extent_io_tree_init(excluded_extents);
+	fs_info->excluded_extents = excluded_extents;
+
+	ret = exclude_tree_blocks(fs_info, fs_info->chunk_root->node, 0);
+	if (ret)
+		return ret;
+	return exclude_tree_blocks(fs_info, fs_info->tree_root->node, 1);
+}
+
+static void cleanup_excluded_extents(struct btrfs_fs_info *fs_info)
+{
+	if (fs_info->excluded_extents) {
+		extent_io_tree_cleanup(fs_info->excluded_extents);
+		free(fs_info->excluded_extents);
+	}
+	fs_info->excluded_extents = NULL;
+}
+
 static int reset_block_groups(struct btrfs_fs_info *fs_info)
 {
 	struct btrfs_block_group_cache *cache;
-- 
2.15.1




  parent reply	other threads:[~2017-12-20  4:53 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-20  4:57 [PATCH v2 00/17] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
2017-12-20  4:57 ` [PATCH v2 01/17] btrfs-progs: lowmem check: release path in repair_extent_data_item() Su Yue
2017-12-20  4:57 ` [PATCH v2 02/17] btrfs-progs: lowmem check: record returned errors after walk_down_tree_v2() Su Yue
2017-12-29 11:17   ` Nikolay Borisov
2018-01-02  1:44     ` Su Yue
2018-01-02  1:50     ` Su Yue
2017-12-20  4:57 ` [PATCH v2 03/17] btrfs-progs: lowmem check: assign @parent early in repair_extent_data_item() Su Yue
2017-12-20  4:57 ` Su Yue [this message]
2017-12-20  4:57 ` [PATCH v2 05/17] btrfs-progs: lowmem check: introduce modify_block_groups_cache() Su Yue
2017-12-20  5:38   ` Qu Wenruo
2017-12-20  4:57 ` [PATCH v2 06/17] btrfs-progs: lowmem check: introduce force_cow_in_new_chunk() Su Yue
2017-12-20  5:41   ` Qu Wenruo
2017-12-20  8:21     ` Su Yue
2017-12-20  8:37       ` Qu Wenruo
2017-12-21  6:51         ` Qu Wenruo
2017-12-21  7:06           ` Su Yue
2017-12-21  7:09           ` Su Yue
2017-12-21  7:12             ` Qu Wenruo
2017-12-26  8:17               ` Su Yue
2017-12-26 10:28                 ` Qu Wenruo
2017-12-27  1:11                   ` Su Yue
2018-01-09  7:44                     ` Qu Wenruo
2017-12-20  4:57 ` [PATCH v2 07/17] btrfs-progs: lowmem check: introduce try_avoid_extents_overwrite() Su Yue
2017-12-20  5:46   ` Qu Wenruo
2017-12-20  4:57 ` [PATCH v2 08/17] btrfs-progs: lowmem check: exclude extents if init-extent-tree in lowmem Su Yue
2017-12-20  4:57 ` [PATCH v2 09/17] btrfs-progs: lowmem check: start to remove parameters @trans " Su Yue
2017-12-20  5:51   ` Qu Wenruo
2017-12-20  4:57 ` [PATCH v2 10/17] btrfs-progs: lowmem check: remove parameter @trans of delete_extent_item() Su Yue
2017-12-20  4:57 ` [PATCH v2 11/17] btrfs-progs: lowmem check: remove parameter @trans of repair_chunk_item() Su Yue
2017-12-20  4:57 ` [PATCH v2 12/17] btrfs-progs: lowmem check: remove parameter @trans of repair_extent_item() Su Yue
2017-12-20  4:57 ` [PATCH v2 13/17] btrfs-progs: lowmem check: remove parameter @trans of check_leaf_items() Su Yue
2017-12-20  4:57 ` [PATCH v2 14/17] btrfs-progs: lowmem check: remove parameter @trans of repair_tree_back_ref() Su Yue
2017-12-20  4:57 ` [PATCH v2 15/17] btrfs-progs: lowmem check: remove parameter @trans of check_btrfs_root() Su Yue
2017-12-20  4:57 ` [PATCH v2 16/17] btrfs-progs: lowmem check: introduce repair_block_accounting() Su Yue
2017-12-20  4:57 ` [PATCH v2 17/17] btrfs-progs: lowmem check: end of removing parameters @trans in lowmem Su Yue
2017-12-20  5:59 ` [PATCH v2 00/17] btrfs-progs: lowmem check: avoid extents overwrite Qu Wenruo

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=20171220045731.19343-5-suy.fnst@cn.fujitsu.com \
    --to=suy.fnst@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo.btrfs@gmx.com \
    /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.