All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite
@ 2018-02-08  3:27 Su Yue
  2018-02-08  3:27 ` [PATCH v4 01/18] btrfs-progs: lowmem check: release path in repair_extent_data_item() Su Yue
                   ` (18 more replies)
  0 siblings, 19 replies; 24+ messages in thread
From: Su Yue @ 2018-02-08  3:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

This patchset can be fetched from my github:
https://github.com/Damenly/btrfs-progs/tree/lowmem
based on unmerged patchset whose cover:
      [PATCH 0/3] btrfs-progs: Split original mode check to its own
      Author: Qu Wenruo <wqu@suse.com>
      
I'm sorry to send patches based on unmerged patch if it let you feel
uncomfortable.
I think the three patches from Qu are good enough so I send it before
my vacation.

Patch[1-3] fix minor problems of lowmem repair.

Patch[4-8] introduce two ways to avoid extents overwrite:
1) Traverse trees and exclude all metadata blocks.
   It's time-inefficient for large filesystems.
2) Mark all existed chunks full, allocate new chunk for CoW and
   records chunk start.
   If the last allocated chunk is almost full, allocated a new one.
2) is More efficient than 1). However, it can't handle situations
like no space(fsck/004).
Lowmem repair will try method 2 first and then method 1.

Patch[9-17] remove parameters @trans in functions for lowmem repair.
They try to avoid extents overwrite if necessary and start
transactions by themselves.

Patch[18] adds a test image.
Those patches are mainly for lowmem repair. Original mode is not
influenced.

---
Changlog:
v4->v3:
 - Remove global enum extents_operation to simplify
   avoid_extents_overwrite() and its cleanup.
 - Rebase after work of check split.
 
v3->v2:
 - check_btrfs_root() returns FATAL_ERROR if check_fs_first_inode()
   failed. Thanks Nikolay Borisov.
 - Add function try_to_force_cow_in_new_chunk() and global u64
   varaiable to record start of the last allocated chunk.
 - Remove unused EXTENTS_PIN in enum lowmem_extents_operation.
 
v2->v1:
 - Let @err in check_btrfs_root() record err bits but excluded
   negative values.
 - Do not delete a line of code to release path after extent item'
   insertion in repair_extent_data_item().
 - Add patch[3].
 - Force CoW in new allocated chunk to avoid extents overwrite.
 - Remove parameters @trans in check_chunks_and_extents_v2() and
   related callees.
 - Repair functions for lowmem mode call try_avoid_extents_overwrite()
   and start transactions.
   
Su Yue (18):
  btrfs-progs: lowmem check: release path in repair_extent_data_item()
  btrfs-progs: lowmem check: record returned errors after
    walk_down_tree_v2()
  btrfs-progs: lowmem check: assign @parent early in
    repair_extent_data_item()
  btrfs-progs: lowmem check: exclude extents of metadata blocks
  btrfs-progs: lowmem check: introduce mark/clear_block_groups_full()
  btrfs-progs: lowmem check: introduce try_force_cow_in_new_chunk()
  btrfs-progs: lowmem check: introduce avoid_extents_overwrite()
  btrfs-progs: lowmem check: exclude extents if init-extent-tree in
    lowmem
  btrfs-progs: lowmem check: start to remove parameters @trans in lowmem
  btrfs-progs: lowmem check: remove parameter @trans of
    delete_extent_item()
  btrfs-progs: lowmem check: remove parameter @trans of
    repair_chunk_item()
  btrfs-progs: lowmem check: remove parameter @trans of
    repair_extent_item()
  btrfs-progs: lowmem check: remove parameter @trans of
    check_leaf_items()
  btrfs-progs: lowmem check: remove parameter @trans of
    repair_tree_back_ref()
  btrfs-progs: lowmem check: remove parameter @trans of
    check_btrfs_root()
  btrfs-progs: lowmem check: introduce repair_block_accounting()
  btrfs-progs: lowmem check: end of removing parameters @trans in lowmem
  btrfs-progs: fsck-tests: add image no extent with normal device size

 check/mode-common.c                                | 100 +++-
 check/mode-common.h                                |   4 +-
 check/mode-lowmem.c                                | 560 +++++++++++++++++----
 check/mode-lowmem.h                                |   1 +
 cmds-check.c                                       |   3 +-
 .../014-no-extent-info/.lowmem_repairable          |   0
 .../fsck-tests/014-no-extent-info/no_extent.raw.xz | Bin 0 -> 28084 bytes
 .../{default_case.img => no_extent_bad_dev.img}    | Bin
 8 files changed, 561 insertions(+), 107 deletions(-)
 create mode 100644 tests/fsck-tests/014-no-extent-info/.lowmem_repairable
 create mode 100644 tests/fsck-tests/014-no-extent-info/no_extent.raw.xz
 rename tests/fsck-tests/014-no-extent-info/{default_case.img => no_extent_bad_dev.img} (100%)

-- 
2.16.1




^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v4 01/18] btrfs-progs: lowmem check: release path in repair_extent_data_item()
  2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
@ 2018-02-08  3:27 ` Su Yue
  2018-02-08  3:27 ` [PATCH v4 02/18] btrfs-progs: lowmem check: record returned errors after walk_down_tree_v2() Su Yue
                   ` (17 subsequent siblings)
  18 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-02-08  3:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

In repair_extent_data_item(), path is not be released if some
errors occurs which causes extent buffer leak.

So release path in end of the function.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/mode-lowmem.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 62bcf3d2e126..d168a3ddd5e5 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -2537,6 +2537,7 @@ static int repair_extent_data_item(struct btrfs_trans_handle *trans,
 
 	err &= ~BACKREF_MISSING;
 out:
+	btrfs_release_path(&path);
 	if (ret)
 		error("can't repair root %llu extent data item[%llu %llu]",
 		      root->objectid, disk_bytenr, num_bytes);
-- 
2.16.1




^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 02/18] btrfs-progs: lowmem check: record returned errors after walk_down_tree_v2()
  2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
  2018-02-08  3:27 ` [PATCH v4 01/18] btrfs-progs: lowmem check: release path in repair_extent_data_item() Su Yue
@ 2018-02-08  3:27 ` Su Yue
  2018-02-08  3:27 ` [PATCH v4 03/18] btrfs-progs: lowmem check: assign @parent early in repair_extent_data_item() Su Yue
                   ` (16 subsequent siblings)
  18 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-02-08  3:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

In lowmem mode with '--repair', check_chunks_and_extents_v2()
will fix accounting in block groups and clear the error
bit BG_ACCOUNTING_ERROR.
However, return value of check_btrfs_root() doesn't contain error bits.

If extent tree is on error, lowmem repair always prints error and
returns nonzero value even the filesystem is fine after repair.

Introduce FATAL_ERROR for lowmem mode to represents negative return
values since negative and positive can't not be mixed in bits operations.

Then let check_btrfs_root() return error bits.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/mode-lowmem.c | 10 +++++-----
 check/mode-lowmem.h |  1 +
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index d168a3ddd5e5..18ec6db098e7 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -4215,7 +4215,7 @@ out:
  *                otherwise means check fs tree(s) items relationship and
  *		  @root MUST be a fs tree root.
  * Returns 0      represents OK.
- * Returns not 0  represents error.
+ * Returns >0     represents error bits.
  */
 static int check_btrfs_root(struct btrfs_trans_handle *trans,
 			    struct btrfs_root *root, unsigned int ext_ref,
@@ -4238,7 +4238,7 @@ static int check_btrfs_root(struct btrfs_trans_handle *trans,
 		 */
 		ret = check_fs_first_inode(root, ext_ref);
 		if (ret < 0)
-			return ret;
+			return FATAL_ERROR;
 	}
 
 
@@ -4266,11 +4266,11 @@ static int check_btrfs_root(struct btrfs_trans_handle *trans,
 		ret = walk_down_tree(trans, root, &path, &level, &nrefs,
 				     ext_ref, check_all);
 
-		err |= !!ret;
-
+		if (ret > 0)
+			err |= ret;
 		/* if ret is negative, walk shall stop */
 		if (ret < 0) {
-			ret = err;
+			ret = err | FATAL_ERROR;
 			break;
 		}
 
diff --git a/check/mode-lowmem.h b/check/mode-lowmem.h
index 73d5799951b7..e7ba62e2413e 100644
--- a/check/mode-lowmem.h
+++ b/check/mode-lowmem.h
@@ -43,6 +43,7 @@
 #define DIR_INDEX_MISMATCH      (1<<19) /* INODE_INDEX found but not match */
 #define DIR_COUNT_AGAIN         (1<<20) /* DIR isize should be recalculated */
 #define BG_ACCOUNTING_ERROR     (1<<21) /* Block group accounting error */
+#define FATAL_ERROR             (1<<22) /* Fatal bit for errno */
 
 /*
  * Error bit for low memory mode check.
-- 
2.16.1




^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 03/18] btrfs-progs: lowmem check: assign @parent early in repair_extent_data_item()
  2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
  2018-02-08  3:27 ` [PATCH v4 01/18] btrfs-progs: lowmem check: release path in repair_extent_data_item() Su Yue
  2018-02-08  3:27 ` [PATCH v4 02/18] btrfs-progs: lowmem check: record returned errors after walk_down_tree_v2() Su Yue
@ 2018-02-08  3:27 ` Su Yue
  2018-02-08  3:27 ` [PATCH v4 04/18] btrfs-progs: lowmem check: exclude extents of metadata blocks Su Yue
                   ` (15 subsequent siblings)
  18 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-02-08  3:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

The variable @eb is assigned to leaf in fs_tree before insertion of
backref. It will causes wrong parent of new inserted backref.

Set @parent at beginning solves the problem.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/mode-lowmem.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 18ec6db098e7..1fc84f1e8c44 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -2475,6 +2475,11 @@ static int repair_extent_data_item(struct btrfs_trans_handle *trans,
 	extent_offset = btrfs_file_extent_offset(eb, fi);
 	offset = file_offset - extent_offset;
 
+	if (nrefs->full_backref[0])
+		parent = btrfs_header_bytenr(eb);
+	else
+		parent = 0;
+
 	/* now repair only adds backref */
 	if ((err & BACKREF_MISSING) == 0)
 		return err;
@@ -2516,11 +2521,6 @@ static int repair_extent_data_item(struct btrfs_trans_handle *trans,
 		btrfs_release_path(&path);
 	}
 
-	if (nrefs->full_backref[0])
-		parent = btrfs_header_bytenr(eb);
-	else
-		parent = 0;
-
 	ret = btrfs_inc_extent_ref(trans, root, disk_bytenr, num_bytes, parent,
 				   root->objectid,
 		   parent ? BTRFS_FIRST_FREE_OBJECTID : fi_key.objectid,
-- 
2.16.1




^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 04/18] btrfs-progs: lowmem check: exclude extents of metadata blocks
  2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
                   ` (2 preceding siblings ...)
  2018-02-08  3:27 ` [PATCH v4 03/18] btrfs-progs: lowmem check: assign @parent early in repair_extent_data_item() Su Yue
@ 2018-02-08  3:27 ` Su Yue
  2018-02-08  3:27 ` [PATCH v4 05/18] btrfs-progs: lowmem check: introduce mark/clear_block_groups_full() Su Yue
                   ` (14 subsequent siblings)
  18 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-02-08  3:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

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.

Introduce exclude_metadata_blocks() to mark extents of all tree
blocks dirty in fs_info->excluded_extents.
Export it since it will be used in lowmem too.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/mode-common.c | 73 +++++++++++++++++++++++++++++++++++++++++++++--------
 check/mode-common.h |  2 ++
 2 files changed, 65 insertions(+), 10 deletions(-)

diff --git a/check/mode-common.c b/check/mode-common.c
index e6d8ebe8b9b7..acceb24b9597 100644
--- a/check/mode-common.c
+++ b/check/mode-common.c
@@ -377,40 +377,54 @@ int zero_log_tree(struct btrfs_root *root)
 	return ret;
 }
 
-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);
 
@@ -425,7 +439,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;
@@ -444,7 +458,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;
@@ -454,6 +469,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;
@@ -465,6 +486,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);
+}
+
+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);
+}
+
+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;
diff --git a/check/mode-common.h b/check/mode-common.h
index e1835d94ab11..e2a824a318c1 100644
--- a/check/mode-common.h
+++ b/check/mode-common.h
@@ -134,4 +134,6 @@ bool is_super_size_valid(struct btrfs_fs_info *fs_info);
 int check_space_cache(struct btrfs_root *root);
 int check_csums(struct btrfs_root *root);
 int recow_extent_buffer(struct btrfs_root *root, struct extent_buffer *eb);
+int exclude_metadata_blocks(struct btrfs_fs_info *fs_info);
+void cleanup_excluded_extents(struct btrfs_fs_info *fs_info);
 #endif
-- 
2.16.1




^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 05/18] btrfs-progs: lowmem check: introduce mark/clear_block_groups_full()
  2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
                   ` (3 preceding siblings ...)
  2018-02-08  3:27 ` [PATCH v4 04/18] btrfs-progs: lowmem check: exclude extents of metadata blocks Su Yue
@ 2018-02-08  3:27 ` Su Yue
  2018-02-08  3:27 ` [PATCH v4 06/18] btrfs-progs: lowmem check: introduce try_force_cow_in_new_chunk() Su Yue
                   ` (13 subsequent siblings)
  18 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-02-08  3:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

Excluding or pining all metadata blocks is not time-efficient for large
storage filesystems.
Here is another way to mark all metadata block groups full and allocate
a new chunk for CoW. So new reservered extents never overwrite
extents.

Introduce modify_block_groups_cache() to modify all blocks groups
cache state and set all extents in block groups unfree in free space
cache.
mark/clear_block_groups_full() wraps above function.

Suggested-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/mode-lowmem.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 93 insertions(+)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 1fc84f1e8c44..a200c28a9cf7 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -233,6 +233,99 @@ static int update_nodes_refs(struct btrfs_root *root, u64 bytenr,
 	return 0;
 }
 
+/*
+ * Mark all extents unfree in the block group. And set @block_group->cached
+ * according to @cache.
+ */
+static int modify_block_group_cache(struct btrfs_fs_info *fs_info,
+		    struct btrfs_block_group_cache *block_group, int cache)
+{
+	struct extent_io_tree *free_space_cache = &fs_info->free_space_cache;
+	u64 start = block_group->key.objectid;
+	u64 end = start + block_group->key.offset;
+
+	if (cache && !block_group->cached) {
+		block_group->cached = 1;
+		clear_extent_dirty(free_space_cache, start, end - 1);
+	}
+
+	if (!cache && block_group->cached) {
+		block_group->cached = 0;
+		clear_extent_dirty(free_space_cache, start, end - 1);
+	}
+	return 0;
+}
+
+/*
+ * Modify block groups which have @flags unfree in free space cache.
+ *
+ * @cache: if 0, clear block groups cache state;
+ *         not 0, mark blocks groups cached.
+ */
+static int modify_block_groups_cache(struct btrfs_fs_info *fs_info, u64 flags,
+				     int cache)
+{
+	struct btrfs_root *root = fs_info->extent_root;
+	struct btrfs_key key;
+	struct btrfs_path path;
+	struct btrfs_block_group_cache *bg_cache;
+	struct btrfs_block_group_item *bi;
+	struct btrfs_block_group_item bg_item;
+	struct extent_buffer *eb;
+	int slot;
+	int ret;
+
+	key.objectid = 0;
+	key.type = BTRFS_BLOCK_GROUP_ITEM_KEY;
+	key.offset = 0;
+
+	btrfs_init_path(&path);
+	ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
+	if (ret < 0) {
+		error("fail to search block groups due to %s", strerror(-ret));
+		goto out;
+	}
+
+	while (1) {
+		eb = path.nodes[0];
+		slot = path.slots[0];
+		btrfs_item_key_to_cpu(eb, &key, slot);
+		bg_cache = btrfs_lookup_block_group(fs_info, key.objectid);
+		if (!bg_cache) {
+			ret = -ENOENT;
+			goto out;
+		}
+
+		bi = btrfs_item_ptr(eb, slot, struct btrfs_block_group_item);
+		read_extent_buffer(eb, &bg_item, (unsigned long)bi,
+				   sizeof(bg_item));
+		if (btrfs_block_group_flags(&bg_item) & flags)
+			modify_block_group_cache(fs_info, bg_cache, cache);
+
+		ret = btrfs_next_item(root, &path);
+		if (ret > 0) {
+			ret = 0;
+			goto out;
+		}
+		if (ret < 0)
+			goto out;
+	}
+
+out:
+	btrfs_release_path(&path);
+	return ret;
+}
+
+static int mark_block_groups_full(struct btrfs_fs_info *fs_info, u64 flags)
+{
+	return modify_block_groups_cache(fs_info, flags, 1);
+}
+
+static int clear_block_groups_full(struct btrfs_fs_info *fs_info, u64 flags)
+{
+	return modify_block_groups_cache(fs_info, flags, 0);
+}
+
 /*
  * This function only handles BACKREF_MISSING,
  * If corresponding extent item exists, increase the ref, else insert an extent
-- 
2.16.1




^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 06/18] btrfs-progs: lowmem check: introduce try_force_cow_in_new_chunk()
  2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
                   ` (4 preceding siblings ...)
  2018-02-08  3:27 ` [PATCH v4 05/18] btrfs-progs: lowmem check: introduce mark/clear_block_groups_full() Su Yue
@ 2018-02-08  3:27 ` Su Yue
  2018-02-08  3:27 ` [PATCH v4 07/18] btrfs-progs: lowmem check: introduce avoid_extents_overwrite() Su Yue
                   ` (12 subsequent siblings)
  18 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-02-08  3:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

Introduce create_chunk_and_block_block_group() to allocate new chunk
and corresponding block group.

The new function force_cow_in_new_chunk() first allocates new chunk
and records its start.
Then it modifies all metadata block groups cached and full.
Finally it marks the new block group uncached and unfree.
In the next CoW, extents states will be updated automatically by
cache_block_group().

New function try_to_force_cow_in_new_chunk() will try to mark block
groups full, allocate a new chunk and records the start.
If the last allocated chunk is almost full, a new chunk will be
allocated.

Suggested-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/mode-lowmem.c | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 165 insertions(+)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index a200c28a9cf7..3649d570e11c 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -326,6 +326,171 @@ static int clear_block_groups_full(struct btrfs_fs_info *fs_info, u64 flags)
 	return modify_block_groups_cache(fs_info, flags, 0);
 }
 
+static int create_chunk_and_block_group(struct btrfs_fs_info *fs_info,
+					u64 flags, u64 *start, u64 *nbytes)
+{
+	struct btrfs_trans_handle *trans;
+	struct btrfs_root *root = fs_info->extent_root;
+	int ret;
+
+	if ((flags & BTRFS_BLOCK_GROUP_TYPE_MASK) == 0)
+		return -EINVAL;
+
+	trans = btrfs_start_transaction(root, 1);
+	if (IS_ERR(trans)) {
+		ret = PTR_ERR(trans);
+		error("error starting transaction %s", strerror(-ret));
+		return ret;
+	}
+	ret = btrfs_alloc_chunk(trans, fs_info, start, nbytes, flags);
+	if (ret) {
+		error("fail to allocate new chunk %s", strerror(-ret));
+		goto out;
+	}
+	ret = btrfs_make_block_group(trans, fs_info, 0, flags, *start,
+				     *nbytes);
+	if (ret) {
+		error("fail to make block group for chunk %llu %llu %s",
+		      *start, *nbytes, strerror(-ret));
+		goto out;
+	}
+out:
+	btrfs_commit_transaction(trans, root);
+	return ret;
+}
+
+static int force_cow_in_new_chunk(struct btrfs_fs_info *fs_info,
+				  u64 *start_ret)
+{
+	struct btrfs_block_group_cache *bg;
+	u64 start;
+	u64 nbytes;
+	u64 alloc_profile;
+	u64 flags;
+	int ret;
+
+	alloc_profile = (fs_info->avail_metadata_alloc_bits &
+			 fs_info->metadata_alloc_profile);
+	flags = BTRFS_BLOCK_GROUP_METADATA | alloc_profile;
+	if (btrfs_fs_incompat(fs_info, MIXED_GROUPS))
+		flags |= BTRFS_BLOCK_GROUP_DATA;
+
+	ret = create_chunk_and_block_group(fs_info, flags, &start, &nbytes);
+	if (ret)
+		goto err;
+	printf("Created new chunk [%llu %llu]\n", start, nbytes);
+
+	flags = BTRFS_BLOCK_GROUP_METADATA;
+	/* Mark all metadata block groups cached and full in free space*/
+	ret = mark_block_groups_full(fs_info, flags);
+	if (ret)
+		goto clear_bgs_full;
+
+	bg = btrfs_lookup_block_group(fs_info, start);
+	if (!bg) {
+		ret = -ENOENT;
+		error("fail to look up block group %llu %llu", start, nbytes);
+		goto clear_bgs_full;
+	}
+
+	/* Clear block group cache just allocated */
+	ret = modify_block_group_cache(fs_info, bg, 0);
+	if (ret)
+		goto clear_bgs_full;
+	if (start_ret)
+		*start_ret = start;
+	return 0;
+
+clear_bgs_full:
+	clear_block_groups_full(fs_info, flags);
+err:
+	return ret;
+}
+
+/*
+ * Returns 0 means not almost full.
+ * Returns >0 means almost full.
+ * Returns <0 means fatal error.
+ */
+static int is_chunk_almost_full(struct btrfs_fs_info *fs_info, u64 start)
+{
+	struct btrfs_path path;
+	struct btrfs_key key;
+	struct btrfs_root *root = fs_info->extent_root;
+	struct btrfs_block_group_item *bi;
+	struct btrfs_block_group_item bg_item;
+	struct extent_buffer *eb;
+	u64 used;
+	u64 total;
+	u64 min_free;
+	int ret;
+	int slot;
+
+	key.objectid = start;
+	key.type = BTRFS_BLOCK_GROUP_ITEM_KEY;
+	key.offset = (u64)-1;
+
+	btrfs_init_path(&path);
+	ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
+	if (!ret)
+		ret = -EIO;
+	if (ret < 0)
+		goto out;
+	ret = btrfs_previous_item(root, &path, start,
+				  BTRFS_BLOCK_GROUP_ITEM_KEY);
+	if (ret) {
+		error("failed to find block group %llu", start);
+		ret = -ENOENT;
+		goto out;
+	}
+
+	eb = path.nodes[0];
+	slot = path.slots[0];
+	btrfs_item_key_to_cpu(eb, &key, slot);
+	if (key.objectid != start) {
+		ret = -ENOENT;
+		goto out;
+	}
+
+	total = key.offset;
+	bi = btrfs_item_ptr(eb, slot, struct btrfs_block_group_item);
+	read_extent_buffer(eb, &bg_item, (unsigned long)bi, sizeof(bg_item));
+	used = btrfs_block_group_used(&bg_item);
+
+	/*
+	 * if the free space in the chunk is less than %10 of total,
+	 * or not not enough for CoW once, we think the chunk is almost full.
+	 */
+	min_free = max_t(u64, (BTRFS_MAX_LEVEL + 1) * fs_info->nodesize,
+			 div_factor(total, 1));
+
+	if ((total - used) > min_free)
+		ret = 0;
+	else
+		ret = 1;
+out:
+	btrfs_release_path(&path);
+	return ret;
+}
+
+/*
+ * Returns <0 for error.
+ * Returns 0 for success.
+ */
+static int try_to_force_cow_in_new_chunk(struct btrfs_fs_info *fs_info,
+					u64 old_start, u64 *new_start)
+{
+	int ret;
+
+	if (old_start) {
+		ret = is_chunk_almost_full(fs_info, old_start);
+		if (ret <= 0)
+			return ret;
+	}
+	ret = force_cow_in_new_chunk(fs_info, new_start);
+	return ret;
+}
+
 /*
  * This function only handles BACKREF_MISSING,
  * If corresponding extent item exists, increase the ref, else insert an extent
-- 
2.16.1




^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 07/18] btrfs-progs: lowmem check: introduce avoid_extents_overwrite()
  2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
                   ` (5 preceding siblings ...)
  2018-02-08  3:27 ` [PATCH v4 06/18] btrfs-progs: lowmem check: introduce try_force_cow_in_new_chunk() Su Yue
@ 2018-02-08  3:27 ` Su Yue
  2018-02-08  3:27 ` [PATCH v4 08/18] btrfs-progs: lowmem check: exclude extents if init-extent-tree in lowmem Su Yue
                   ` (11 subsequent siblings)
  18 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-02-08  3:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

Another global u64 last_allocated_chunk records the last chunk start
allocated by lowmem repair.
Although global variable is not so graceful, it simplifies codes much.

avoid_extents_overwrite() prefer to allocates new chunk first.
If it failed because of no space or wrong used bytes(fsck-tests/004),
then it try to exclude metadata blocks but costs lots of time in
large filesystem.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/mode-lowmem.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 3649d570e11c..ea4019c32a3f 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -28,6 +28,8 @@
 #include "check/mode-common.h"
 #include "check/mode-lowmem.h"
 
+static u64 last_allocated_chunk;
+
 static int calc_extent_flag(struct btrfs_root *root, struct extent_buffer *eb,
 			    u64 *flags_ret)
 {
@@ -491,6 +493,50 @@ static int try_to_force_cow_in_new_chunk(struct btrfs_fs_info *fs_info,
 	return ret;
 }
 
+static int avoid_extents_overwrite(struct btrfs_fs_info *fs_info)
+{
+	int ret;
+	int mixed = btrfs_fs_incompat(fs_info, MIXED_GROUPS);
+
+	if (fs_info->excluded_extents)
+		return 0;
+
+	if (last_allocated_chunk != (u64)-1) {
+		ret = try_to_force_cow_in_new_chunk(fs_info,
+			last_allocated_chunk, &last_allocated_chunk);
+		if (!ret)
+			goto out;
+		/*
+		 * If failed, do not try to allocate chunk again in
+		 * next call.
+		 * If there is no space left to allocate, try to exclude all
+		 * metadata blocks. Mixed filesystem is unsupported.
+		 */
+		last_allocated_chunk = (u64)-1;
+		if (ret != -ENOSPC || mixed)
+			goto out;
+	}
+
+	printf(
+	"Try to exclude all metadata blcoks and extents, it may be slow\n");
+	ret = exclude_metadata_blocks(fs_info);
+out:
+	if (ret)
+		error("failed to avoid extents overwrite %s", strerror(-ret));
+	return ret;
+}
+
+static int end_avoid_extents_overwrite(struct btrfs_fs_info *fs_info)
+{
+	int ret = 0;
+
+	cleanup_excluded_extents(fs_info);
+	if (last_allocated_chunk)
+		ret = clear_block_groups_full(fs_info,
+					BTRFS_BLOCK_GROUP_METADATA);
+	return ret;
+}
+
 /*
  * This function only handles BACKREF_MISSING,
  * If corresponding extent item exists, increase the ref, else insert an extent
-- 
2.16.1




^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 08/18] btrfs-progs: lowmem check: exclude extents if init-extent-tree in lowmem
  2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
                   ` (6 preceding siblings ...)
  2018-02-08  3:27 ` [PATCH v4 07/18] btrfs-progs: lowmem check: introduce avoid_extents_overwrite() Su Yue
@ 2018-02-08  3:27 ` Su Yue
  2018-02-08  3:27 ` [PATCH v4 09/18] btrfs-progs: lowmem check: start to remove parameters @trans " Su Yue
                   ` (10 subsequent siblings)
  18 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-02-08  3:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

If options '--init-extent-tree' and '--mode=lowmem' are both
input, all metadata blocks will be traversed twice.
First one is done by pin_metadata_blocks() in reinit_extent_tree().
Second one is in check_chunks_and_extents_v2().

Excluding instead of pining metadata blocks before reinit extent tree
in lowmem can save some time.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/mode-common.c | 27 ++++++++++++++++++++-------
 check/mode-common.h |  2 +-
 check/mode-lowmem.c |  8 +++++++-
 cmds-check.c        |  3 ++-
 4 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/check/mode-common.c b/check/mode-common.c
index acceb24b9597..afe5f04d1deb 100644
--- a/check/mode-common.c
+++ b/check/mode-common.c
@@ -706,7 +706,7 @@ out:
  * Using fs and other trees to rebuild extent tree.
  */
 int reinit_extent_tree(struct btrfs_trans_handle *trans,
-		       struct btrfs_fs_info *fs_info)
+		       struct btrfs_fs_info *fs_info, bool pin)
 {
 	u64 start = 0;
 	int ret;
@@ -728,13 +728,26 @@ int reinit_extent_tree(struct btrfs_trans_handle *trans,
 
 	/*
 	 * first we need to walk all of the trees except the extent tree and pin
-	 * down the bytes that are in use so we don't overwrite any existing
-	 * metadata.
+	 * down/exclude the bytes that are in use so we don't overwrite any
+	 * existing metadata.
+	 * If pin, unpin will be done in end of transaction.
+	 * If exclude, cleanup will be done in check_chunks_and_extents_lowmem.
 	 */
-	ret = pin_metadata_blocks(fs_info);
-	if (ret) {
-		fprintf(stderr, "error pinning down used bytes\n");
-		return ret;
+again:
+	if (pin) {
+		ret = pin_metadata_blocks(fs_info);
+		if (ret) {
+			fprintf(stderr, "error pinning down used bytes\n");
+			return ret;
+		}
+	} else {
+		ret = exclude_metadata_blocks(fs_info);
+		if (ret) {
+			fprintf(stderr, "error excluding used bytes\n");
+			printf("try to pin down used bytes\n");
+			pin = true;
+			goto again;
+		}
 	}
 
 	/*
diff --git a/check/mode-common.h b/check/mode-common.h
index e2a824a318c1..8af7dd3066ff 100644
--- a/check/mode-common.h
+++ b/check/mode-common.h
@@ -122,7 +122,7 @@ int check_child_node(struct extent_buffer *parent, int slot,
 void reset_cached_block_groups(struct btrfs_fs_info *fs_info);
 int zero_log_tree(struct btrfs_root *root);
 int reinit_extent_tree(struct btrfs_trans_handle *trans,
-		       struct btrfs_fs_info *fs_info);
+		       struct btrfs_fs_info *fs_info, bool pin);
 int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans,
 			   struct btrfs_root *root, int overwrite);
 int fill_csum_tree(struct btrfs_trans_handle *trans,
diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index ea4019c32a3f..1e0545e6249d 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -4860,8 +4860,14 @@ next:
 	}
 out:
 
-	/* if repair, update block accounting */
 	if (repair) {
+		ret = end_avoid_extents_overwrite(fs_info);
+		if (ret < 0)
+			ret = FATAL_ERROR;
+		err |= ret;
+
+		reset_cached_block_groups(fs_info);
+		/* update block accounting */
 		ret = btrfs_fix_block_accounting(trans, root);
 		if (ret)
 			err |= ret;
diff --git a/cmds-check.c b/cmds-check.c
index 28746712fac1..ed81fd3c22b4 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -453,7 +453,8 @@ int cmd_check(int argc, char **argv)
 
 		if (init_extent_tree) {
 			printf("Creating a new extent tree\n");
-			ret = reinit_extent_tree(trans, info);
+			ret = reinit_extent_tree(trans, info,
+					 check_mode == CHECK_MODE_ORIGINAL);
 			err |= !!ret;
 			if (ret)
 				goto close_out;
-- 
2.16.1




^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 09/18] btrfs-progs: lowmem check: start to remove parameters @trans in lowmem
  2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
                   ` (7 preceding siblings ...)
  2018-02-08  3:27 ` [PATCH v4 08/18] btrfs-progs: lowmem check: exclude extents if init-extent-tree in lowmem Su Yue
@ 2018-02-08  3:27 ` Su Yue
  2018-02-08  3:27 ` [PATCH v4 10/18] btrfs-progs: lowmem check: remove parameter @trans of delete_extent_item() Su Yue
                   ` (9 subsequent siblings)
  18 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-02-08  3:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

Since extents can be avoid overwrite by excluding or new chunk
allocation. It's unnessesary to do all repairs in one transaction.

This patch removes parameter @trans of repair_extent_data_item().
repair_extent_data_item() calls try_avoid_extents_overwrite()
and starts a transaction by itself.

Note: This patch and next patches cause error in lowmem repair like:
"Error: Commit_root already set when starting transaction".
This error will disappear after removing @trans finished.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/mode-lowmem.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 1e0545e6249d..446ea4a21bfa 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -2739,12 +2739,12 @@ out:
  *
  * Returns error bits after reapir.
  */
-static int repair_extent_data_item(struct btrfs_trans_handle *trans,
-				   struct btrfs_root *root,
+static int repair_extent_data_item(struct btrfs_root *root,
 				   struct btrfs_path *pathp,
 				   struct node_refs *nrefs,
 				   int err)
 {
+	struct btrfs_trans_handle *trans = NULL;
 	struct btrfs_file_extent_item *fi;
 	struct btrfs_key fi_key;
 	struct btrfs_key key;
@@ -2761,6 +2761,7 @@ static int repair_extent_data_item(struct btrfs_trans_handle *trans,
 	u64 file_offset;
 	int generation;
 	int slot;
+	int need_insert = 0;
 	int ret = 0;
 
 	eb = pathp->nodes[0];
@@ -2799,9 +2800,20 @@ static int repair_extent_data_item(struct btrfs_trans_handle *trans,
 		ret = -EIO;
 		goto out;
 	}
+	need_insert = ret;
 
+	ret = avoid_extents_overwrite(root->fs_info);
+	if (ret)
+		goto out;
+	trans = btrfs_start_transaction(root, 1);
+	if (IS_ERR(trans)) {
+		ret = PTR_ERR(trans);
+		trans = NULL;
+		error("fail to start transaction %s", strerror(-ret));
+		goto out;
+	}
 	/* insert an extent item */
-	if (ret > 0) {
+	if (need_insert) {
 		key.objectid = disk_bytenr;
 		key.type = BTRFS_EXTENT_ITEM_KEY;
 		key.offset = num_bytes;
@@ -2841,6 +2853,8 @@ static int repair_extent_data_item(struct btrfs_trans_handle *trans,
 
 	err &= ~BACKREF_MISSING;
 out:
+	if (trans)
+		btrfs_commit_transaction(trans, root);
 	btrfs_release_path(&path);
 	if (ret)
 		error("can't repair root %llu extent data item[%llu %llu]",
@@ -4117,8 +4131,7 @@ again:
 	case BTRFS_EXTENT_DATA_KEY:
 		ret = check_extent_data_item(root, path, nrefs, account_bytes);
 		if (repair && ret)
-			ret = repair_extent_data_item(trans, root, path, nrefs,
-						      ret);
+			ret = repair_extent_data_item(root, path, nrefs, ret);
 		err |= ret;
 		break;
 	case BTRFS_BLOCK_GROUP_ITEM_KEY:
-- 
2.16.1




^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 10/18] btrfs-progs: lowmem check: remove parameter @trans of delete_extent_item()
  2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
                   ` (8 preceding siblings ...)
  2018-02-08  3:27 ` [PATCH v4 09/18] btrfs-progs: lowmem check: start to remove parameters @trans " Su Yue
@ 2018-02-08  3:27 ` Su Yue
  2018-02-08  3:27 ` [PATCH v4 11/18] btrfs-progs: lowmem check: remove parameter @trans of repair_chunk_item() Su Yue
                   ` (8 subsequent siblings)
  18 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-02-08  3:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

This patch removes the parameter @trans of delete_extent_item().
It calls try_avoid_extents_overwrite() and starts a transaction by itself.

Note: This patch and next patches cause error in lowmem repair like:
"Error: Commit_root already set when starting transaction".
This error will disappear after removing @trans finished.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/mode-lowmem.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 446ea4a21bfa..272e658296e7 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -4063,13 +4063,22 @@ out:
 	return err;
 }
 
-static int delete_extent_tree_item(struct btrfs_trans_handle *trans,
-				   struct btrfs_root *root,
+static int delete_extent_tree_item(struct btrfs_root *root,
 				   struct btrfs_path *path)
 {
 	struct btrfs_key key;
+	struct btrfs_trans_handle *trans;
 	int ret = 0;
 
+	ret = avoid_extents_overwrite(root->fs_info);
+	if (ret)
+		return ret;
+	trans = btrfs_start_transaction(root, 1);
+	if (IS_ERR(trans)) {
+		ret = PTR_ERR(trans);
+		error("fail to start transaction %s", strerror(-ret));
+		goto out;
+	}
 	btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
 	btrfs_release_path(path);
 	ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
@@ -4087,6 +4096,7 @@ static int delete_extent_tree_item(struct btrfs_trans_handle *trans,
 	else
 		path->slots[0]--;
 out:
+	btrfs_commit_transaction(trans, root);
 	if (ret)
 		error("failed to delete root %llu item[%llu, %u, %llu]",
 		      root->objectid, key.objectid, key.type, key.offset);
@@ -4138,7 +4148,7 @@ again:
 		ret = check_block_group_item(fs_info, eb, slot);
 		if (repair &&
 		    ret & REFERENCER_MISSING)
-			ret = delete_extent_tree_item(trans, root, path);
+			ret = delete_extent_tree_item(root, path);
 		err |= ret;
 		break;
 	case BTRFS_DEV_ITEM_KEY:
@@ -4169,7 +4179,7 @@ again:
 					       key.objectid, -1);
 		if (repair &&
 		    ret & (REFERENCER_MISMATCH | REFERENCER_MISSING))
-			ret = delete_extent_tree_item(trans, root, path);
+			ret = delete_extent_tree_item(root, path);
 		err |= ret;
 		break;
 	case BTRFS_EXTENT_DATA_REF_KEY:
@@ -4182,7 +4192,7 @@ again:
 				btrfs_extent_data_ref_count(eb, dref));
 		if (repair &&
 		    ret & (REFERENCER_MISMATCH | REFERENCER_MISSING))
-			ret = delete_extent_tree_item(trans, root, path);
+			ret = delete_extent_tree_item(root, path);
 		err |= ret;
 		break;
 	case BTRFS_SHARED_BLOCK_REF_KEY:
@@ -4190,7 +4200,7 @@ again:
 						 key.objectid, -1);
 		if (repair &&
 		    ret & (REFERENCER_MISMATCH | REFERENCER_MISSING))
-			ret = delete_extent_tree_item(trans, root, path);
+			ret = delete_extent_tree_item(root, path);
 		err |= ret;
 		break;
 	case BTRFS_SHARED_DATA_REF_KEY:
@@ -4198,7 +4208,7 @@ again:
 						key.objectid);
 		if (repair &&
 		    ret & (REFERENCER_MISMATCH | REFERENCER_MISSING))
-			ret = delete_extent_tree_item(trans, root, path);
+			ret = delete_extent_tree_item(root, path);
 		err |= ret;
 		break;
 	default:
-- 
2.16.1




^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 11/18] btrfs-progs: lowmem check: remove parameter @trans of repair_chunk_item()
  2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
                   ` (9 preceding siblings ...)
  2018-02-08  3:27 ` [PATCH v4 10/18] btrfs-progs: lowmem check: remove parameter @trans of delete_extent_item() Su Yue
@ 2018-02-08  3:27 ` Su Yue
  2018-02-08  3:27 ` [PATCH v4 12/18] btrfs-progs: lowmem check: remove parameter @trans of repair_extent_item() Su Yue
                   ` (7 subsequent siblings)
  18 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-02-08  3:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

This patch removes parameter @trans of repair_chunk_item().
It calls try_avoid_extents_overwrite() and starts a transaction by
itself.

Note: This patch and next patches cause error in lowmem repair like:
"Error: Commit_root already set when starting transaction".
This error will disappear after removing @trans finished.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/mode-lowmem.c | 48 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 32 insertions(+), 16 deletions(-)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 272e658296e7..53377848f361 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -4026,13 +4026,14 @@ out:
  *
  * Returns error after repair.
  */
-static int repair_chunk_item(struct btrfs_trans_handle *trans,
-			     struct btrfs_root *chunk_root,
+static int repair_chunk_item(struct btrfs_root *chunk_root,
 			     struct btrfs_path *path, int err)
 {
 	struct btrfs_chunk *chunk;
 	struct btrfs_key chunk_key;
 	struct extent_buffer *eb = path->nodes[0];
+	struct btrfs_root *extent_root = chunk_root->fs_info->extent_root;
+	struct btrfs_trans_handle *trans;
 	u64 length;
 	int slot = path->slots[0];
 	u64 type;
@@ -4045,21 +4046,36 @@ static int repair_chunk_item(struct btrfs_trans_handle *trans,
 	type = btrfs_chunk_type(path->nodes[0], chunk);
 	length = btrfs_chunk_length(eb, chunk);
 
-	if (err & REFERENCER_MISSING) {
-		ret = btrfs_make_block_group(trans, chunk_root->fs_info, 0,
-					     type, chunk_key.offset, length);
-		if (ret) {
-			error("fail to add block group item[%llu %llu]",
-			      chunk_key.offset, length);
-			goto out;
-		} else {
-			err &= ~REFERENCER_MISSING;
-			printf("Added block group item[%llu %llu]\n",
-			       chunk_key.offset, length);
-		}
+	/* now repair only adds block group */
+	if ((err & REFERENCER_MISSING) == 0)
+		return err;
+
+	ret = avoid_extents_overwrite(chunk_root->fs_info);
+	if (ret)
+		return ret;
+
+	trans = btrfs_start_transaction(extent_root, 1);
+	if (IS_ERR(trans)) {
+		ret = PTR_ERR(trans);
+		error("fail to start transaction %s", strerror(-ret));
+		return ret;
 	}
 
-out:
+	ret = btrfs_make_block_group(trans, chunk_root->fs_info, 0, type,
+				     chunk_key.offset, length);
+	if (ret) {
+		error("fail to add block group item[%llu %llu]",
+		      chunk_key.offset, length);
+	} else {
+		err &= ~REFERENCER_MISSING;
+		printf("Added block group item[%llu %llu]\n", chunk_key.offset,
+		       length);
+	}
+
+	btrfs_commit_transaction(trans, extent_root);
+	if (ret)
+		error("fail to repair item(s) related to chunk item[%llu %llu]",
+		      chunk_key.objectid, chunk_key.offset);
 	return err;
 }
 
@@ -4158,7 +4174,7 @@ again:
 	case BTRFS_CHUNK_ITEM_KEY:
 		ret = check_chunk_item(fs_info, eb, slot);
 		if (repair && ret)
-			ret = repair_chunk_item(trans, root, path, ret);
+			ret = repair_chunk_item(root, path, ret);
 		err |= ret;
 		break;
 	case BTRFS_DEV_EXTENT_KEY:
-- 
2.16.1




^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 12/18] btrfs-progs: lowmem check: remove parameter @trans of repair_extent_item()
  2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
                   ` (10 preceding siblings ...)
  2018-02-08  3:27 ` [PATCH v4 11/18] btrfs-progs: lowmem check: remove parameter @trans of repair_chunk_item() Su Yue
@ 2018-02-08  3:27 ` Su Yue
  2018-02-08  3:27 ` [PATCH v4 13/18] btrfs-progs: lowmem check: remove parameter @trans of check_leaf_items() Su Yue
                   ` (6 subsequent siblings)
  18 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-02-08  3:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

This patch removes parameter @trans of repair_extent_item().
It calls try_avoid_extents_overwrite() and starts a transaction by
itself.

Note: This patch and next patches cause error in lowmem repair like:
"Error: Commit_root already set when starting transaction".
This error will disappear after removing @trans finished.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/mode-lowmem.c | 54 +++++++++++++++++++++++++++++++++--------------------
 1 file changed, 34 insertions(+), 20 deletions(-)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 53377848f361..443fa513a13e 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -3588,40 +3588,55 @@ out:
  *               means error after repair
  * Returns  0   nothing happened
  */
-static int repair_extent_item(struct btrfs_trans_handle *trans,
-		      struct btrfs_root *root, struct btrfs_path *path,
+static int repair_extent_item(struct btrfs_root *root, struct btrfs_path *path,
 		      u64 bytenr, u64 num_bytes, u64 parent, u64 root_objectid,
 		      u64 owner, u64 offset, int err)
 {
+	struct btrfs_trans_handle *trans;
+	struct btrfs_root *extent_root = root->fs_info->extent_root;
 	struct btrfs_key old_key;
 	int freed = 0;
 	int ret;
 
 	btrfs_item_key_to_cpu(path->nodes[0], &old_key, path->slots[0]);
 
-	if (err & (REFERENCER_MISSING | REFERENCER_MISMATCH)) {
-		/* delete the backref */
-		ret = btrfs_free_extent(trans, root->fs_info->fs_root, bytenr,
-			  num_bytes, parent, root_objectid, owner, offset);
-		if (!ret) {
-			freed = 1;
-			err &= ~REFERENCER_MISSING;
-			printf("Delete backref in extent [%llu %llu]\n",
-			       bytenr, num_bytes);
-		} else {
-			error("fail to delete backref in extent [%llu %llu]",
-			       bytenr, num_bytes);
-		}
+	if ((err & (REFERENCER_MISSING | REFERENCER_MISMATCH)) == 0)
+		return err;
+
+	ret = avoid_extents_overwrite(root->fs_info);
+	if (ret)
+		return err;
+
+	trans = btrfs_start_transaction(extent_root, 1);
+	if (IS_ERR(trans)) {
+		ret = PTR_ERR(trans);
+		error("fail to start transaction %s", strerror(-ret));
+		/* nothing happened */
+		ret = 0;
+		goto out;
 	}
+	/* delete the backref */
+	ret = btrfs_free_extent(trans, root->fs_info->fs_root, bytenr,
+			num_bytes, parent, root_objectid, owner, offset);
+	if (!ret) {
+		freed = 1;
+		err &= ~REFERENCER_MISSING;
+		printf("Delete backref in extent [%llu %llu]\n",
+		       bytenr, num_bytes);
+	} else {
+		error("fail to delete backref in extent [%llu %llu]",
+		      bytenr, num_bytes);
+	}
+	btrfs_commit_transaction(trans, extent_root);
 
 	/* btrfs_free_extent may delete the extent */
 	btrfs_release_path(path);
 	ret = btrfs_search_slot(NULL, root, &old_key, path, 0, 0);
-
 	if (ret)
 		ret = -ENOENT;
 	else if (freed)
 		ret = err;
+out:
 	return ret;
 }
 
@@ -3631,8 +3646,7 @@ static int repair_extent_item(struct btrfs_trans_handle *trans,
  *
  * Since we don't use extent_record anymore, introduce new error bit
  */
-static int check_extent_item(struct btrfs_trans_handle *trans,
-			     struct btrfs_fs_info *fs_info,
+static int check_extent_item(struct btrfs_fs_info *fs_info,
 			     struct btrfs_path *path)
 {
 	struct btrfs_extent_item *ei;
@@ -3763,7 +3777,7 @@ next:
 	}
 
 	if (err && repair) {
-		ret = repair_extent_item(trans, fs_info->extent_root, path,
+		ret = repair_extent_item(fs_info->extent_root, path,
 			 key.objectid, num_bytes, parent, root_objectid,
 			 owner, owner_offset, ret);
 		if (ret < 0)
@@ -4183,7 +4197,7 @@ again:
 		break;
 	case BTRFS_EXTENT_ITEM_KEY:
 	case BTRFS_METADATA_ITEM_KEY:
-		ret = check_extent_item(trans, fs_info, path);
+		ret = check_extent_item(fs_info, path);
 		err |= ret;
 		break;
 	case BTRFS_EXTENT_CSUM_KEY:
-- 
2.16.1




^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 13/18] btrfs-progs: lowmem check: remove parameter @trans of check_leaf_items()
  2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
                   ` (11 preceding siblings ...)
  2018-02-08  3:27 ` [PATCH v4 12/18] btrfs-progs: lowmem check: remove parameter @trans of repair_extent_item() Su Yue
@ 2018-02-08  3:27 ` Su Yue
  2018-02-08  3:27 ` [PATCH v4 14/18] btrfs-progs: lowmem check: remove parameter @trans of repair_tree_back_ref() Su Yue
                   ` (5 subsequent siblings)
  18 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-02-08  3:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

This patch removes parameter @trans of check_leaf_items().

Note: This patch and next patches cause error in lowmem repair like:
"Error: Commit_root already set when starting transaction".
This error will disappear after removing @trans finished.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/mode-lowmem.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 443fa513a13e..a7660a25b844 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -4139,8 +4139,7 @@ out:
 /*
  * Main entry function to check known items and update related accounting info
  */
-static int check_leaf_items(struct btrfs_trans_handle *trans,
-			    struct btrfs_root *root, struct btrfs_path *path,
+static int check_leaf_items(struct btrfs_root *root, struct btrfs_path *path,
 			    struct node_refs *nrefs, int account_bytes)
 {
 	struct btrfs_fs_info *fs_info = root->fs_info;
@@ -4336,7 +4335,7 @@ static int walk_down_tree(struct btrfs_trans_handle *trans,
 				ret = process_one_leaf(root, path, nrefs,
 						       level, ext_ref);
 			else
-				ret = check_leaf_items(trans, root, path,
+				ret = check_leaf_items(root, path,
 					       nrefs, account_file_data);
 			err |= ret;
 			break;
-- 
2.16.1




^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 14/18] btrfs-progs: lowmem check: remove parameter @trans of repair_tree_back_ref()
  2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
                   ` (12 preceding siblings ...)
  2018-02-08  3:27 ` [PATCH v4 13/18] btrfs-progs: lowmem check: remove parameter @trans of check_leaf_items() Su Yue
@ 2018-02-08  3:27 ` Su Yue
  2018-02-08  3:27 ` [PATCH v4 15/18] btrfs-progs: lowmem check: remove parameter @trans of check_btrfs_root() Su Yue
                   ` (4 subsequent siblings)
  18 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-02-08  3:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

This patch removes parameter @trans of repair_tree_back_ref().
It calls try_avoid_extents_overwrite() and starts a transaction by
itself.

Note: This patch and next patches cause error in lowmem repair like:
"Error: Commit_root already set when starting transaction".
This error will disappear after removing @trans finished.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/mode-lowmem.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index a7660a25b844..d4c8de4e69af 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -544,11 +544,11 @@ static int end_avoid_extents_overwrite(struct btrfs_fs_info *fs_info)
  *
  * Returns error bits after repair.
  */
-static int repair_tree_block_ref(struct btrfs_trans_handle *trans,
-				 struct btrfs_root *root,
+static int repair_tree_block_ref(struct btrfs_root *root,
 				 struct extent_buffer *node,
 				 struct node_refs *nrefs, int level, int err)
 {
+	struct btrfs_trans_handle *trans = NULL;
 	struct btrfs_fs_info *fs_info = root->fs_info;
 	struct btrfs_root *extent_root = fs_info->extent_root;
 	struct btrfs_path path;
@@ -598,6 +598,16 @@ static int repair_tree_block_ref(struct btrfs_trans_handle *trans,
 	if (nrefs->full_backref[level] != 0)
 		flags |= BTRFS_BLOCK_FLAG_FULL_BACKREF;
 
+	ret = avoid_extents_overwrite(root->fs_info);
+	if (ret)
+		goto out;
+	trans = btrfs_start_transaction(extent_root, 1);
+	if (IS_ERR(trans)) {
+		ret = PTR_ERR(trans);
+		trans = NULL;
+		error("fail to start transaction %s", strerror(-ret));
+		goto out;
+	}
 	/* insert an extent item */
 	if (insert_extent) {
 		struct btrfs_disk_key copy_key;
@@ -663,6 +673,8 @@ static int repair_tree_block_ref(struct btrfs_trans_handle *trans,
 
 	nrefs->refs[level]++;
 out:
+	if (trans)
+		btrfs_commit_transaction(trans, extent_root);
 	btrfs_release_path(&path);
 	if (ret) {
 		error(
@@ -4304,7 +4316,7 @@ static int walk_down_tree(struct btrfs_trans_handle *trans,
 			   btrfs_header_owner(cur), nrefs);
 
 			if (repair && ret)
-				ret = repair_tree_block_ref(trans, root,
+				ret = repair_tree_block_ref(root,
 				    path->nodes[*level], nrefs, *level, ret);
 			err |= ret;
 
-- 
2.16.1




^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 15/18] btrfs-progs: lowmem check: remove parameter @trans of check_btrfs_root()
  2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
                   ` (13 preceding siblings ...)
  2018-02-08  3:27 ` [PATCH v4 14/18] btrfs-progs: lowmem check: remove parameter @trans of repair_tree_back_ref() Su Yue
@ 2018-02-08  3:27 ` Su Yue
  2018-02-08  3:27 ` [PATCH v4 16/18] btrfs-progs: lowmem check: introduce repair_block_accounting() Su Yue
                   ` (3 subsequent siblings)
  18 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-02-08  3:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

Remove parameters @trans of delete_extent_item() and walk_down_tree_v2().

Note: This patch and next patches cause error in lowmem repair like:
"Error: Commit_root already set when starting transaction".
This error will disappear after removing @trans finished.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/mode-lowmem.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index d4c8de4e69af..d92278d2993c 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -4271,8 +4271,7 @@ out:
  * Returns <0  Fatal error, must exit the whole check
  * Returns 0   No errors found
  */
-static int walk_down_tree(struct btrfs_trans_handle *trans,
-			  struct btrfs_root *root, struct btrfs_path *path,
+static int walk_down_tree(struct btrfs_root *root, struct btrfs_path *path,
 			  int *level, struct node_refs *nrefs, int ext_ref,
 			  int check_all)
 {
@@ -4585,8 +4584,7 @@ out:
  * Returns 0      represents OK.
  * Returns >0     represents error bits.
  */
-static int check_btrfs_root(struct btrfs_trans_handle *trans,
-			    struct btrfs_root *root, unsigned int ext_ref,
+static int check_btrfs_root(struct btrfs_root *root, unsigned int ext_ref,
 			    int check_all)
 {
 	struct btrfs_path path;
@@ -4631,7 +4629,7 @@ static int check_btrfs_root(struct btrfs_trans_handle *trans,
 	}
 
 	while (1) {
-		ret = walk_down_tree(trans, root, &path, &level, &nrefs,
+		ret = walk_down_tree(root, &path, &level, &nrefs,
 				     ext_ref, check_all);
 
 		if (ret > 0)
@@ -4667,7 +4665,7 @@ out:
 static int check_fs_root(struct btrfs_root *root, unsigned int ext_ref)
 {
 	reset_cached_block_groups(root->fs_info);
-	return check_btrfs_root(NULL, root, ext_ref, 0);
+	return check_btrfs_root(root, ext_ref, 0);
 }
 
 /*
@@ -4871,11 +4869,11 @@ int check_chunks_and_extents_lowmem(struct btrfs_fs_info *fs_info)
 	}
 
 	root1 = root->fs_info->chunk_root;
-	ret = check_btrfs_root(trans, root1, 0, 1);
+	ret = check_btrfs_root(root1, 0, 1);
 	err |= ret;
 
 	root1 = root->fs_info->tree_root;
-	ret = check_btrfs_root(trans, root1, 0, 1);
+	ret = check_btrfs_root(root1, 0, 1);
 	err |= ret;
 
 	btrfs_init_path(&path);
@@ -4906,7 +4904,7 @@ int check_chunks_and_extents_lowmem(struct btrfs_fs_info *fs_info)
 			goto next;
 		}
 
-		ret = check_btrfs_root(trans, cur_root, 0, 1);
+		ret = check_btrfs_root(cur_root, 0, 1);
 		err |= ret;
 
 		if (key.objectid == BTRFS_TREE_RELOC_OBJECTID)
-- 
2.16.1




^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 16/18] btrfs-progs: lowmem check: introduce repair_block_accounting()
  2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
                   ` (14 preceding siblings ...)
  2018-02-08  3:27 ` [PATCH v4 15/18] btrfs-progs: lowmem check: remove parameter @trans of check_btrfs_root() Su Yue
@ 2018-02-08  3:27 ` Su Yue
  2018-02-08  3:27 ` [PATCH v4 17/18] btrfs-progs: lowmem check: end of removing parameters @trans in lowmem Su Yue
                   ` (2 subsequent siblings)
  18 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-02-08  3:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

Introduce repair_block_accounting() which calls
btrfs_fix_block_accounting() to repair block group accouting.

Replace btrfs_fix_block_accounting() with the new function.

Note: This patch and next patches cause error in lowmem repair like:
"Error: Commit_root already set when starting transaction".
This error will disappear after removing @trans finished.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/mode-lowmem.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index d92278d2993c..40a179f75319 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -537,6 +537,30 @@ static int end_avoid_extents_overwrite(struct btrfs_fs_info *fs_info)
 	return ret;
 }
 
+/*
+ * Wrapper function for btrfs_fix_block_accounting().
+ *
+ * Returns 0     on success.
+ * Returns != 0  on error.
+ */
+static int repair_block_accounting(struct btrfs_fs_info *fs_info)
+{
+	struct btrfs_trans_handle *trans = NULL;
+	struct btrfs_root *root = fs_info->extent_root;
+	int ret;
+
+	trans = btrfs_start_transaction(root, 1);
+	if (IS_ERR(trans)) {
+		ret = PTR_ERR(trans);
+		error("fail to start transaction %s", strerror(-ret));
+		return ret;
+	}
+
+	ret = btrfs_fix_block_accounting(trans, root);
+	btrfs_commit_transaction(trans, root);
+	return ret;
+}
+
 /*
  * This function only handles BACKREF_MISSING,
  * If corresponding extent item exists, increase the ref, else insert an extent
@@ -4930,7 +4954,7 @@ out:
 
 		reset_cached_block_groups(fs_info);
 		/* update block accounting */
-		ret = btrfs_fix_block_accounting(trans, root);
+		ret = repair_block_accounting(fs_info);
 		if (ret)
 			err |= ret;
 		else
-- 
2.16.1




^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 17/18] btrfs-progs: lowmem check: end of removing parameters @trans in lowmem
  2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
                   ` (15 preceding siblings ...)
  2018-02-08  3:27 ` [PATCH v4 16/18] btrfs-progs: lowmem check: introduce repair_block_accounting() Su Yue
@ 2018-02-08  3:27 ` Su Yue
  2018-02-08  3:27 ` [PATCH v4 18/18] btrfs-progs: fsck-tests: add image no extent with normal device size Su Yue
  2018-05-07 18:17 ` [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite David Sterba
  18 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-02-08  3:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

Remove @trans in check_chunks_and_extents().

This patch let lowmem repair work again.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/mode-lowmem.c | 13 -------------
 1 file changed, 13 deletions(-)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 40a179f75319..4aad69fc9eb1 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -4872,7 +4872,6 @@ out:
  */
 int check_chunks_and_extents_lowmem(struct btrfs_fs_info *fs_info)
 {
-	struct btrfs_trans_handle *trans = NULL;
 	struct btrfs_path path;
 	struct btrfs_key old_key;
 	struct btrfs_key key;
@@ -4884,14 +4883,6 @@ int check_chunks_and_extents_lowmem(struct btrfs_fs_info *fs_info)
 
 	root = fs_info->fs_root;
 
-	if (repair) {
-		trans = btrfs_start_transaction(fs_info->extent_root, 1);
-		if (IS_ERR(trans)) {
-			error("failed to start transaction before check");
-			return PTR_ERR(trans);
-		}
-	}
-
 	root1 = root->fs_info->chunk_root;
 	ret = check_btrfs_root(root1, 0, 1);
 	err |= ret;
@@ -4961,10 +4952,6 @@ out:
 			err &= ~BG_ACCOUNTING_ERROR;
 	}
 
-	if (trans)
-		btrfs_commit_transaction(trans, root->fs_info->extent_root);
-
 	btrfs_release_path(&path);
-
 	return err;
 }
-- 
2.16.1




^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 18/18] btrfs-progs: fsck-tests: add image no extent with normal device size
  2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
                   ` (16 preceding siblings ...)
  2018-02-08  3:27 ` [PATCH v4 17/18] btrfs-progs: lowmem check: end of removing parameters @trans in lowmem Su Yue
@ 2018-02-08  3:27 ` Su Yue
  2018-05-07 18:17 ` [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite David Sterba
  18 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-02-08  3:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

This new image only misses one extent which leads lowmem mode to
allocate new chunk in repair.
Original image renamed to no_extent_bad_dev.img should let lowmem mode
exclude blocks in repair.

Due to problems of btrfs-image, choose xz as compression tool.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 tests/fsck-tests/014-no-extent-info/.lowmem_repairable  |   0
 tests/fsck-tests/014-no-extent-info/no_extent.raw.xz    | Bin 0 -> 28084 bytes
 .../{default_case.img => no_extent_bad_dev.img}         | Bin
 3 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 tests/fsck-tests/014-no-extent-info/.lowmem_repairable
 create mode 100644 tests/fsck-tests/014-no-extent-info/no_extent.raw.xz
 rename tests/fsck-tests/014-no-extent-info/{default_case.img => no_extent_bad_dev.img} (100%)

diff --git a/tests/fsck-tests/014-no-extent-info/.lowmem_repairable b/tests/fsck-tests/014-no-extent-info/.lowmem_repairable
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/tests/fsck-tests/014-no-extent-info/no_extent.raw.xz b/tests/fsck-tests/014-no-extent-info/no_extent.raw.xz
new file mode 100644
index 0000000000000000000000000000000000000000..6e568a9cf1f0a1d1bcd00222b07cf14d3c09afc5
GIT binary patch
literal 28084
zcmeHwRdglUlAV~Dr4lnUGcz+Yl&Zw65;HTGm`hY*W@ct)W@gDf9*;jfYmHxzU(agW
z_wTOzlbMlmc0}y6&(3#_ADY@gKwt+8b>bjEM8LQ}KtM>7nq!}zeqgG4KtQ(dpP%`S
zpA!6%=nh;)N=@;U2l>H}&lh|6{<94I+`Pat)!xJ5;c^W5@XJ0$yOAWwDqC7u{m$V#
zu1^h#K5*Z<Hk_nPb#uyk@TWA-lsn%){ls!d^sIcP9gZ~zYnsr4q}ybl#F1lDvq#bO
z^9}<s#2LmQ!0el=gtT=&MCBgf;SOx~fVQ@Yp<J~hzxKcB5FvtNi5;etJXt{2&I^0{
z*zT?3JVd<eSars9=XOo3#|dyP1U}c*jujsjEh;JYCg9Fx8nX}akjLp3VFqTGF=&Wg
zhffr`8_?IsI`AUuBKg`o7;>_dr^8P5T*g?2u6pL-W6*Z@NVn9#3fEQ(6T&7fx32XO
zWHO>g#(kt{ScOiSKvXh&evRV3EMjeu4_;Plq;WL7Iu{J`?+x@6^!FpdHHm&<;)*WY
z8Rn^5bFn|!@yXFcCT5$omu(i5<CJ%yf|T+JI5x-#GJ9RL5lapcXVL!V`}zR)3%B=G
z8TruK9=z=UA*4>h&Tm2nXCtaA4Ciq!juG8#5Bf@(Wh;hXy3Jb%gsIt8E1kIoVm*L*
zitD=5-f$&(3aIQmZ34KrcEr%@!=(sJn2K1QUYwkk3q;%dQeDuxfR>hmL!Y>Wc`2e6
zZ>)H>s!r;AO0@Hsz$r<5p@s~;wA!0tS=04;ka*1Xw4Fd>Yxhc~Ht>!p8dc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A>vcNxLQW4?KbnBd8x@wVMCOE+>D<Q~U|K;V&}4ASH?<0+1Mgn#9NfW&t`K
zw6E7w<5;8u7faw^kr_^*`=mep`M<j3{6CsE{~J%BfB)3leWiqYfK2<-nFi=O09^;5
z>-bxB9e^bXSdxGx30RVUx&7R~@1p(*&UXMp7C^`X2w4Cj`(I?C3Ba(w6NCMS^{bQf
zvV;6Fnq4WHZJRq${V$dn<3KNMCF6J}DcwHnn)t(<p$SN^i|ma;;n7e5U7(mL`ATxi
zM0*0h|F2GgG;u`E1Lz6>T>(({0MtGIx2hTct=0b*!*75YDiTzqVFoqtf9SYQ!3cZ{
zKz#t}15h7;`v141KEML|AN&@?zm-WqzyJXQh+zNhH&Oru&)<pQ0btmlz%XCVF(4?Q
zGlyR#DT$ANe0y#0r8%#cJlO{bIARsp*Vk9@kN=8@QH0Sjc^E<e_zeW6rTyOkz9;_#

literal 0
HcmV?d00001

diff --git a/tests/fsck-tests/014-no-extent-info/default_case.img b/tests/fsck-tests/014-no-extent-info/no_extent_bad_dev.img
similarity index 100%
rename from tests/fsck-tests/014-no-extent-info/default_case.img
rename to tests/fsck-tests/014-no-extent-info/no_extent_bad_dev.img
-- 
2.16.1




^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite
  2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
                   ` (17 preceding siblings ...)
  2018-02-08  3:27 ` [PATCH v4 18/18] btrfs-progs: fsck-tests: add image no extent with normal device size Su Yue
@ 2018-05-07 18:17 ` David Sterba
  2018-05-08  2:09   ` Su Yue
  18 siblings, 1 reply; 24+ messages in thread
From: David Sterba @ 2018-05-07 18:17 UTC (permalink / raw)
  To: Su Yue; +Cc: linux-btrfs

On Thu, Feb 08, 2018 at 11:27:19AM +0800, Su Yue wrote:
> This patchset can be fetched from my github:
> https://github.com/Damenly/btrfs-progs/tree/lowmem
> based on unmerged patchset whose cover:
>       [PATCH 0/3] btrfs-progs: Split original mode check to its own
>       Author: Qu Wenruo <wqu@suse.com>
>       
> I'm sorry to send patches based on unmerged patch if it let you feel
> uncomfortable.
> I think the three patches from Qu are good enough so I send it before
> my vacation.
> 
> Patch[1-3] fix minor problems of lowmem repair.
> 
> Patch[4-8] introduce two ways to avoid extents overwrite:
> 1) Traverse trees and exclude all metadata blocks.
>    It's time-inefficient for large filesystems.
> 2) Mark all existed chunks full, allocate new chunk for CoW and
>    records chunk start.
>    If the last allocated chunk is almost full, allocated a new one.
> 2) is More efficient than 1). However, it can't handle situations
> like no space(fsck/004).
> Lowmem repair will try method 2 first and then method 1.
> 
> Patch[9-17] remove parameters @trans in functions for lowmem repair.
> They try to avoid extents overwrite if necessary and start
> transactions by themselves.
> 
> Patch[18] adds a test image.
> Those patches are mainly for lowmem repair. Original mode is not
> influenced.
> 
> ---
> Changlog:
> v4->v3:
>  - Remove global enum extents_operation to simplify
>    avoid_extents_overwrite() and its cleanup.
>  - Rebase after work of check split.
>  
> v3->v2:
>  - check_btrfs_root() returns FATAL_ERROR if check_fs_first_inode()
>    failed. Thanks Nikolay Borisov.
>  - Add function try_to_force_cow_in_new_chunk() and global u64
>    varaiable to record start of the last allocated chunk.
>  - Remove unused EXTENTS_PIN in enum lowmem_extents_operation.
>  
> v2->v1:
>  - Let @err in check_btrfs_root() record err bits but excluded
>    negative values.
>  - Do not delete a line of code to release path after extent item'
>    insertion in repair_extent_data_item().
>  - Add patch[3].
>  - Force CoW in new allocated chunk to avoid extents overwrite.
>  - Remove parameters @trans in check_chunks_and_extents_v2() and
>    related callees.
>  - Repair functions for lowmem mode call try_avoid_extents_overwrite()
>    and start transactions.
>    
> Su Yue (18):
>   btrfs-progs: lowmem check: release path in repair_extent_data_item()
>   btrfs-progs: lowmem check: record returned errors after
>     walk_down_tree_v2()
>   btrfs-progs: lowmem check: assign @parent early in
>     repair_extent_data_item()
>   btrfs-progs: lowmem check: exclude extents of metadata blocks

Patch 1-4 added to devel.

>   btrfs-progs: lowmem check: introduce mark/clear_block_groups_full()

There were too many conflicts starting with this patch.

Can you please refresh teh rest of the series and resend?

For subject please use "btrfs-progs: check: lowmem: ..." and try to fix
the typos in the changelogs. Thanks.



>   btrfs-progs: lowmem check: introduce try_force_cow_in_new_chunk()
>   btrfs-progs: lowmem check: introduce avoid_extents_overwrite()
>   btrfs-progs: lowmem check: exclude extents if init-extent-tree in
>     lowmem
>   btrfs-progs: lowmem check: start to remove parameters @trans in lowmem
>   btrfs-progs: lowmem check: remove parameter @trans of
>     delete_extent_item()
>   btrfs-progs: lowmem check: remove parameter @trans of
>     repair_chunk_item()
>   btrfs-progs: lowmem check: remove parameter @trans of
>     repair_extent_item()
>   btrfs-progs: lowmem check: remove parameter @trans of
>     check_leaf_items()
>   btrfs-progs: lowmem check: remove parameter @trans of
>     repair_tree_back_ref()
>   btrfs-progs: lowmem check: remove parameter @trans of
>     check_btrfs_root()
>   btrfs-progs: lowmem check: introduce repair_block_accounting()
>   btrfs-progs: lowmem check: end of removing parameters @trans in lowmem
>   btrfs-progs: fsck-tests: add image no extent with normal device size


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite
  2018-05-08  2:09   ` Su Yue
@ 2018-05-08  2:06     ` Qu Wenruo
  2018-05-08  2:19       ` Su Yue
  2018-05-08 16:30       ` David Sterba
  0 siblings, 2 replies; 24+ messages in thread
From: Qu Wenruo @ 2018-05-08  2:06 UTC (permalink / raw)
  To: Su Yue, Qu Wenruo, dsterba, linux-btrfs


[-- Attachment #1.1: Type: text/plain, Size: 5471 bytes --]



On 2018年05月08日 10:09, Su Yue wrote:
> 
> 
> On 05/08/2018 02:17 AM, David Sterba wrote:
>> On Thu, Feb 08, 2018 at 11:27:19AM +0800, Su Yue wrote:
>>> This patchset can be fetched from my github:
>>> https://github.com/Damenly/btrfs-progs/tree/lowmem
>>> based on unmerged patchset whose cover:
>>>        [PATCH 0/3] btrfs-progs: Split original mode check to its own
>>>        Author: Qu Wenruo <wqu@suse.com>
>>>        I'm sorry to send patches based on unmerged patch if it let
>>> you feel
>>> uncomfortable.
>>> I think the three patches from Qu are good enough so I send it before
>>> my vacation.
>>>
>>> Patch[1-3] fix minor problems of lowmem repair.
>>>
>>> Patch[4-8] introduce two ways to avoid extents overwrite:
>>> 1) Traverse trees and exclude all metadata blocks.
>>>     It's time-inefficient for large filesystems.
>>> 2) Mark all existed chunks full, allocate new chunk for CoW and
>>>     records chunk start.
>>>     If the last allocated chunk is almost full, allocated a new one.
>>> 2) is More efficient than 1). However, it can't handle situations
>>> like no space(fsck/004).
>>> Lowmem repair will try method 2 first and then method 1.
>>>
>>> Patch[9-17] remove parameters @trans in functions for lowmem repair.
>>> They try to avoid extents overwrite if necessary and start
>>> transactions by themselves.
>>>
>>> Patch[18] adds a test image.
>>> Those patches are mainly for lowmem repair. Original mode is not
>>> influenced.
>>>
>>> ---
>>> Changlog:
>>> v4->v3:
>>>   - Remove global enum extents_operation to simplify
>>>     avoid_extents_overwrite() and its cleanup.
>>>   - Rebase after work of check split.
>>>   v3->v2:
>>>   - check_btrfs_root() returns FATAL_ERROR if check_fs_first_inode()
>>>     failed. Thanks Nikolay Borisov.
>>>   - Add function try_to_force_cow_in_new_chunk() and global u64
>>>     varaiable to record start of the last allocated chunk.
>>>   - Remove unused EXTENTS_PIN in enum lowmem_extents_operation.
>>>   v2->v1:
>>>   - Let @err in check_btrfs_root() record err bits but excluded
>>>     negative values.
>>>   - Do not delete a line of code to release path after extent item'
>>>     insertion in repair_extent_data_item().
>>>   - Add patch[3].
>>>   - Force CoW in new allocated chunk to avoid extents overwrite.
>>>   - Remove parameters @trans in check_chunks_and_extents_v2() and
>>>     related callees.
>>>   - Repair functions for lowmem mode call try_avoid_extents_overwrite()
>>>     and start transactions.
>>>     Su Yue (18):
>>>    btrfs-progs: lowmem check: release path in repair_extent_data_item()
>>>    btrfs-progs: lowmem check: record returned errors after
>>>      walk_down_tree_v2()
>>>    btrfs-progs: lowmem check: assign @parent early in
>>>      repair_extent_data_item()
>>>    btrfs-progs: lowmem check: exclude extents of metadata blocks
>>
>> Patch 1-4 added to devel.
>>
>>>    btrfs-progs: lowmem check: introduce mark/clear_block_groups_full()
>>
>> There were too many conflicts starting with this patch.
>>
>> Can you please refresh teh rest of the series and resend?
>>
> OK of cource. An small question below.
> 
> Though this patchset is for lowmem mode, it also changes original mode
> for code reuse.
> 
> This patch and remainings base on Qu's unmerged patchset:
>     [PATCH 0/3] btrfs-progs: Split original mode check to its own
>         Author: Qu Wenruo <wqu@suse.com>
> New version is named
>     [PATCH 0/3] btrfs-progs: Split mode-original code
>     Author: Qu Wenruo <wqu@suse.com>

Sorry, that patchset will not be updated until we get a relatively
stable check code base.
So I'm afraid you need to base them on current devel branch other than
my patchset.

Thanks,
Qu

> 
> I just tried to rebase his brach named split_check_for_david to devel
> but failed with conflictions.
> 
> Does V2 need to get rid of the precondition and just rebases to devel?
> Or to wait completion of split?
> 
> Thanks,
> Su
> 
>> For subject please use "btrfs-progs: check: lowmem: ..." and try to fix
>> the typos in the changelogs. Thanks.
>>
>>
>>
>>>    btrfs-progs: lowmem check: introduce try_force_cow_in_new_chunk()
>>>    btrfs-progs: lowmem check: introduce avoid_extents_overwrite()
>>>    btrfs-progs: lowmem check: exclude extents if init-extent-tree in
>>>      lowmem
>>>    btrfs-progs: lowmem check: start to remove parameters @trans in
>>> lowmem
>>>    btrfs-progs: lowmem check: remove parameter @trans of
>>>      delete_extent_item()
>>>    btrfs-progs: lowmem check: remove parameter @trans of
>>>      repair_chunk_item()
>>>    btrfs-progs: lowmem check: remove parameter @trans of
>>>      repair_extent_item()
>>>    btrfs-progs: lowmem check: remove parameter @trans of
>>>      check_leaf_items()
>>>    btrfs-progs: lowmem check: remove parameter @trans of
>>>      repair_tree_back_ref()
>>>    btrfs-progs: lowmem check: remove parameter @trans of
>>>      check_btrfs_root()
>>>    btrfs-progs: lowmem check: introduce repair_block_accounting()
>>>    btrfs-progs: lowmem check: end of removing parameters @trans in
>>> lowmem
>>>    btrfs-progs: fsck-tests: add image no extent with normal device size
>>
>>
>>
> 
> 
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite
  2018-05-07 18:17 ` [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite David Sterba
@ 2018-05-08  2:09   ` Su Yue
  2018-05-08  2:06     ` Qu Wenruo
  0 siblings, 1 reply; 24+ messages in thread
From: Su Yue @ 2018-05-08  2:09 UTC (permalink / raw)
  To: dsterba, linux-btrfs, Qu Wenruo, Qu Wenruo



On 05/08/2018 02:17 AM, David Sterba wrote:
> On Thu, Feb 08, 2018 at 11:27:19AM +0800, Su Yue wrote:
>> This patchset can be fetched from my github:
>> https://github.com/Damenly/btrfs-progs/tree/lowmem
>> based on unmerged patchset whose cover:
>>        [PATCH 0/3] btrfs-progs: Split original mode check to its own
>>        Author: Qu Wenruo <wqu@suse.com>
>>        
>> I'm sorry to send patches based on unmerged patch if it let you feel
>> uncomfortable.
>> I think the three patches from Qu are good enough so I send it before
>> my vacation.
>>
>> Patch[1-3] fix minor problems of lowmem repair.
>>
>> Patch[4-8] introduce two ways to avoid extents overwrite:
>> 1) Traverse trees and exclude all metadata blocks.
>>     It's time-inefficient for large filesystems.
>> 2) Mark all existed chunks full, allocate new chunk for CoW and
>>     records chunk start.
>>     If the last allocated chunk is almost full, allocated a new one.
>> 2) is More efficient than 1). However, it can't handle situations
>> like no space(fsck/004).
>> Lowmem repair will try method 2 first and then method 1.
>>
>> Patch[9-17] remove parameters @trans in functions for lowmem repair.
>> They try to avoid extents overwrite if necessary and start
>> transactions by themselves.
>>
>> Patch[18] adds a test image.
>> Those patches are mainly for lowmem repair. Original mode is not
>> influenced.
>>
>> ---
>> Changlog:
>> v4->v3:
>>   - Remove global enum extents_operation to simplify
>>     avoid_extents_overwrite() and its cleanup.
>>   - Rebase after work of check split.
>>   
>> v3->v2:
>>   - check_btrfs_root() returns FATAL_ERROR if check_fs_first_inode()
>>     failed. Thanks Nikolay Borisov.
>>   - Add function try_to_force_cow_in_new_chunk() and global u64
>>     varaiable to record start of the last allocated chunk.
>>   - Remove unused EXTENTS_PIN in enum lowmem_extents_operation.
>>   
>> v2->v1:
>>   - Let @err in check_btrfs_root() record err bits but excluded
>>     negative values.
>>   - Do not delete a line of code to release path after extent item'
>>     insertion in repair_extent_data_item().
>>   - Add patch[3].
>>   - Force CoW in new allocated chunk to avoid extents overwrite.
>>   - Remove parameters @trans in check_chunks_and_extents_v2() and
>>     related callees.
>>   - Repair functions for lowmem mode call try_avoid_extents_overwrite()
>>     and start transactions.
>>     
>> Su Yue (18):
>>    btrfs-progs: lowmem check: release path in repair_extent_data_item()
>>    btrfs-progs: lowmem check: record returned errors after
>>      walk_down_tree_v2()
>>    btrfs-progs: lowmem check: assign @parent early in
>>      repair_extent_data_item()
>>    btrfs-progs: lowmem check: exclude extents of metadata blocks
> 
> Patch 1-4 added to devel.
> 
>>    btrfs-progs: lowmem check: introduce mark/clear_block_groups_full()
> 
> There were too many conflicts starting with this patch.
> 
> Can you please refresh teh rest of the series and resend?
> 
OK of cource. An small question below.

Though this patchset is for lowmem mode, it also changes original mode
for code reuse.

This patch and remainings base on Qu's unmerged patchset:
	[PATCH 0/3] btrfs-progs: Split original mode check to its own
         Author: Qu Wenruo <wqu@suse.com>
New version is named
	[PATCH 0/3] btrfs-progs: Split mode-original code
	Author: Qu Wenruo <wqu@suse.com>

I just tried to rebase his brach named split_check_for_david to devel 
but failed with conflictions.

Does V2 need to get rid of the precondition and just rebases to devel?
Or to wait completion of split?

Thanks,
Su

> For subject please use "btrfs-progs: check: lowmem: ..." and try to fix
> the typos in the changelogs. Thanks.
> 
> 
> 
>>    btrfs-progs: lowmem check: introduce try_force_cow_in_new_chunk()
>>    btrfs-progs: lowmem check: introduce avoid_extents_overwrite()
>>    btrfs-progs: lowmem check: exclude extents if init-extent-tree in
>>      lowmem
>>    btrfs-progs: lowmem check: start to remove parameters @trans in lowmem
>>    btrfs-progs: lowmem check: remove parameter @trans of
>>      delete_extent_item()
>>    btrfs-progs: lowmem check: remove parameter @trans of
>>      repair_chunk_item()
>>    btrfs-progs: lowmem check: remove parameter @trans of
>>      repair_extent_item()
>>    btrfs-progs: lowmem check: remove parameter @trans of
>>      check_leaf_items()
>>    btrfs-progs: lowmem check: remove parameter @trans of
>>      repair_tree_back_ref()
>>    btrfs-progs: lowmem check: remove parameter @trans of
>>      check_btrfs_root()
>>    btrfs-progs: lowmem check: introduce repair_block_accounting()
>>    btrfs-progs: lowmem check: end of removing parameters @trans in lowmem
>>    btrfs-progs: fsck-tests: add image no extent with normal device size
> 
> 
> 



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite
  2018-05-08  2:06     ` Qu Wenruo
@ 2018-05-08  2:19       ` Su Yue
  2018-05-08 16:30       ` David Sterba
  1 sibling, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-05-08  2:19 UTC (permalink / raw)
  To: Qu Wenruo, Qu Wenruo, dsterba, linux-btrfs



On 05/08/2018 10:06 AM, Qu Wenruo wrote:
> 
> 
> On 2018年05月08日 10:09, Su Yue wrote:
>>
>>
>> On 05/08/2018 02:17 AM, David Sterba wrote:
>>> On Thu, Feb 08, 2018 at 11:27:19AM +0800, Su Yue wrote:
>>>> This patchset can be fetched from my github:
>>>> https://github.com/Damenly/btrfs-progs/tree/lowmem
>>>> based on unmerged patchset whose cover:
>>>>         [PATCH 0/3] btrfs-progs: Split original mode check to its own
>>>>         Author: Qu Wenruo <wqu@suse.com>
>>>>         I'm sorry to send patches based on unmerged patch if it let
>>>> you feel
>>>> uncomfortable.
>>>> I think the three patches from Qu are good enough so I send it before
>>>> my vacation.
>>>>
>>>> Patch[1-3] fix minor problems of lowmem repair.
>>>>
>>>> Patch[4-8] introduce two ways to avoid extents overwrite:
>>>> 1) Traverse trees and exclude all metadata blocks.
>>>>      It's time-inefficient for large filesystems.
>>>> 2) Mark all existed chunks full, allocate new chunk for CoW and
>>>>      records chunk start.
>>>>      If the last allocated chunk is almost full, allocated a new one.
>>>> 2) is More efficient than 1). However, it can't handle situations
>>>> like no space(fsck/004).
>>>> Lowmem repair will try method 2 first and then method 1.
>>>>
>>>> Patch[9-17] remove parameters @trans in functions for lowmem repair.
>>>> They try to avoid extents overwrite if necessary and start
>>>> transactions by themselves.
>>>>
>>>> Patch[18] adds a test image.
>>>> Those patches are mainly for lowmem repair. Original mode is not
>>>> influenced.
>>>>
>>>> ---
>>>> Changlog:
>>>> v4->v3:
>>>>    - Remove global enum extents_operation to simplify
>>>>      avoid_extents_overwrite() and its cleanup.
>>>>    - Rebase after work of check split.
>>>>    v3->v2:
>>>>    - check_btrfs_root() returns FATAL_ERROR if check_fs_first_inode()
>>>>      failed. Thanks Nikolay Borisov.
>>>>    - Add function try_to_force_cow_in_new_chunk() and global u64
>>>>      varaiable to record start of the last allocated chunk.
>>>>    - Remove unused EXTENTS_PIN in enum lowmem_extents_operation.
>>>>    v2->v1:
>>>>    - Let @err in check_btrfs_root() record err bits but excluded
>>>>      negative values.
>>>>    - Do not delete a line of code to release path after extent item'
>>>>      insertion in repair_extent_data_item().
>>>>    - Add patch[3].
>>>>    - Force CoW in new allocated chunk to avoid extents overwrite.
>>>>    - Remove parameters @trans in check_chunks_and_extents_v2() and
>>>>      related callees.
>>>>    - Repair functions for lowmem mode call try_avoid_extents_overwrite()
>>>>      and start transactions.
>>>>      Su Yue (18):
>>>>     btrfs-progs: lowmem check: release path in repair_extent_data_item()
>>>>     btrfs-progs: lowmem check: record returned errors after
>>>>       walk_down_tree_v2()
>>>>     btrfs-progs: lowmem check: assign @parent early in
>>>>       repair_extent_data_item()
>>>>     btrfs-progs: lowmem check: exclude extents of metadata blocks
>>>
>>> Patch 1-4 added to devel.
>>>
>>>>     btrfs-progs: lowmem check: introduce mark/clear_block_groups_full()
>>>
>>> There were too many conflicts starting with this patch.
>>>
>>> Can you please refresh teh rest of the series and resend?
>>>
>> OK of cource. An small question below.
>>
>> Though this patchset is for lowmem mode, it also changes original mode
>> for code reuse.
>>
>> This patch and remainings base on Qu's unmerged patchset:
>>      [PATCH 0/3] btrfs-progs: Split original mode check to its own
>>          Author: Qu Wenruo <wqu@suse.com>
>> New version is named
>>      [PATCH 0/3] btrfs-progs: Split mode-original code
>>      Author: Qu Wenruo <wqu@suse.com>
> 
> Sorry, that patchset will not be updated until we get a relatively
> stable check code base.
> So I'm afraid you need to base them on current devel branch other than
> my patchset.
> 
Understood. Thanks a lot.

Thanks,
Su

> Thanks,
> Qu
> 
>>
>> I just tried to rebase his brach named split_check_for_david to devel
>> but failed with conflictions.
>>
>> Does V2 need to get rid of the precondition and just rebases to devel?
>> Or to wait completion of split?
>>
>> Thanks,
>> Su
>>
>>> For subject please use "btrfs-progs: check: lowmem: ..." and try to fix
>>> the typos in the changelogs. Thanks.
>>>
>>>
>>>
>>>>     btrfs-progs: lowmem check: introduce try_force_cow_in_new_chunk()
>>>>     btrfs-progs: lowmem check: introduce avoid_extents_overwrite()
>>>>     btrfs-progs: lowmem check: exclude extents if init-extent-tree in
>>>>       lowmem
>>>>     btrfs-progs: lowmem check: start to remove parameters @trans in
>>>> lowmem
>>>>     btrfs-progs: lowmem check: remove parameter @trans of
>>>>       delete_extent_item()
>>>>     btrfs-progs: lowmem check: remove parameter @trans of
>>>>       repair_chunk_item()
>>>>     btrfs-progs: lowmem check: remove parameter @trans of
>>>>       repair_extent_item()
>>>>     btrfs-progs: lowmem check: remove parameter @trans of
>>>>       check_leaf_items()
>>>>     btrfs-progs: lowmem check: remove parameter @trans of
>>>>       repair_tree_back_ref()
>>>>     btrfs-progs: lowmem check: remove parameter @trans of
>>>>       check_btrfs_root()
>>>>     btrfs-progs: lowmem check: introduce repair_block_accounting()
>>>>     btrfs-progs: lowmem check: end of removing parameters @trans in
>>>> lowmem
>>>>     btrfs-progs: fsck-tests: add image no extent with normal device size
>>>
>>>
>>>
>>
>>
>>
> 



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite
  2018-05-08  2:06     ` Qu Wenruo
  2018-05-08  2:19       ` Su Yue
@ 2018-05-08 16:30       ` David Sterba
  1 sibling, 0 replies; 24+ messages in thread
From: David Sterba @ 2018-05-08 16:30 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: Su Yue, Qu Wenruo, dsterba, linux-btrfs

On Tue, May 08, 2018 at 10:06:05AM +0800, Qu Wenruo wrote:
> >>>   - Repair functions for lowmem mode call try_avoid_extents_overwrite()
> >>>     and start transactions.
> >>>     Su Yue (18):
> >>>    btrfs-progs: lowmem check: release path in repair_extent_data_item()
> >>>    btrfs-progs: lowmem check: record returned errors after
> >>>      walk_down_tree_v2()
> >>>    btrfs-progs: lowmem check: assign @parent early in
> >>>      repair_extent_data_item()
> >>>    btrfs-progs: lowmem check: exclude extents of metadata blocks
> >>
> >> Patch 1-4 added to devel.
> >>
> >>>    btrfs-progs: lowmem check: introduce mark/clear_block_groups_full()
> >>
> >> There were too many conflicts starting with this patch.
> >>
> >> Can you please refresh teh rest of the series and resend?
> >>
> > OK of cource. An small question below.
> > 
> > Though this patchset is for lowmem mode, it also changes original mode
> > for code reuse.
> > 
> > This patch and remainings base on Qu's unmerged patchset:
> >     [PATCH 0/3] btrfs-progs: Split original mode check to its own
> >         Author: Qu Wenruo <wqu@suse.com>
> > New version is named
> >     [PATCH 0/3] btrfs-progs: Split mode-original code
> >     Author: Qu Wenruo <wqu@suse.com>
> 
> Sorry, that patchset will not be updated until we get a relatively
> stable check code base.
> So I'm afraid you need to base them on current devel branch other than
> my patchset.

Yeah, my plan for the upcoming weeks is to get all the pending patchsets
with fixes merged before any bigger code cleanups, in check/.

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2018-05-08 16:32 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-08  3:27 [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite Su Yue
2018-02-08  3:27 ` [PATCH v4 01/18] btrfs-progs: lowmem check: release path in repair_extent_data_item() Su Yue
2018-02-08  3:27 ` [PATCH v4 02/18] btrfs-progs: lowmem check: record returned errors after walk_down_tree_v2() Su Yue
2018-02-08  3:27 ` [PATCH v4 03/18] btrfs-progs: lowmem check: assign @parent early in repair_extent_data_item() Su Yue
2018-02-08  3:27 ` [PATCH v4 04/18] btrfs-progs: lowmem check: exclude extents of metadata blocks Su Yue
2018-02-08  3:27 ` [PATCH v4 05/18] btrfs-progs: lowmem check: introduce mark/clear_block_groups_full() Su Yue
2018-02-08  3:27 ` [PATCH v4 06/18] btrfs-progs: lowmem check: introduce try_force_cow_in_new_chunk() Su Yue
2018-02-08  3:27 ` [PATCH v4 07/18] btrfs-progs: lowmem check: introduce avoid_extents_overwrite() Su Yue
2018-02-08  3:27 ` [PATCH v4 08/18] btrfs-progs: lowmem check: exclude extents if init-extent-tree in lowmem Su Yue
2018-02-08  3:27 ` [PATCH v4 09/18] btrfs-progs: lowmem check: start to remove parameters @trans " Su Yue
2018-02-08  3:27 ` [PATCH v4 10/18] btrfs-progs: lowmem check: remove parameter @trans of delete_extent_item() Su Yue
2018-02-08  3:27 ` [PATCH v4 11/18] btrfs-progs: lowmem check: remove parameter @trans of repair_chunk_item() Su Yue
2018-02-08  3:27 ` [PATCH v4 12/18] btrfs-progs: lowmem check: remove parameter @trans of repair_extent_item() Su Yue
2018-02-08  3:27 ` [PATCH v4 13/18] btrfs-progs: lowmem check: remove parameter @trans of check_leaf_items() Su Yue
2018-02-08  3:27 ` [PATCH v4 14/18] btrfs-progs: lowmem check: remove parameter @trans of repair_tree_back_ref() Su Yue
2018-02-08  3:27 ` [PATCH v4 15/18] btrfs-progs: lowmem check: remove parameter @trans of check_btrfs_root() Su Yue
2018-02-08  3:27 ` [PATCH v4 16/18] btrfs-progs: lowmem check: introduce repair_block_accounting() Su Yue
2018-02-08  3:27 ` [PATCH v4 17/18] btrfs-progs: lowmem check: end of removing parameters @trans in lowmem Su Yue
2018-02-08  3:27 ` [PATCH v4 18/18] btrfs-progs: fsck-tests: add image no extent with normal device size Su Yue
2018-05-07 18:17 ` [PATCH v4 00/18] btrfs-progs: lowmem check: avoid extents overwrite David Sterba
2018-05-08  2:09   ` Su Yue
2018-05-08  2:06     ` Qu Wenruo
2018-05-08  2:19       ` Su Yue
2018-05-08 16:30       ` David Sterba

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.