All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] btrfs-progs: Split lowmem mode check to its own
@ 2018-02-01  6:45 Qu Wenruo
  2018-02-01  6:45 ` [PATCH v2 2/3] btrfs-progs: check/lowmem: Cleanup unnecessary _v2 suffix Qu Wenruo
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Qu Wenruo @ 2018-02-01  6:45 UTC (permalink / raw)
  To: linux-btrfs, dsterba

As usual, the main part is over 500K so the biggest patch won't reach
mail list.
Please fetch the whole branch from github:
https://github.com/adam900710/btrfs-progs/tree/split_check

This update rebased (the truth is, it's re-created other than rebase)
the branch to David's devel branch, whose head is:

commit cfe255515ae0a27fdd8e612a884b94ffb703acdf (david/devel)
Author: Qu Wenruo <wqu@suse.com>
Date:   Thu Jan 18 16:38:23 2018 +0800

    btrfs-progs: check: Move reset_cached_block_groups to check/common.c
    
    Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
    Signed-off-by: Qu Wenruo <wqu@suse.com>


Despite the update, a new patch is introduced, to address the tons of
BORING errors and warning from checkpatch.pl.

Qu Wenruo (3):
  btrfs-progs: check: Move lowmem check code to its own
    check/lowmem.[ch]
  btrfs-progs: check/lowmem: Cleanup unnecessary _v2 suffix
  btrfs-progs: check: Cleanup all checkpatch error and warning

 Makefile       |     2 +-
 check/lowmem.c |  4579 ++++++++++++++++++++
 check/lowmem.h |     5 +
 check/main.c   | 12772 ++++++++++++++++++-------------------------------------
 4 files changed, 8694 insertions(+), 8664 deletions(-)
 create mode 100644 check/lowmem.c

-- 
2.16.1


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

* [PATCH v2 2/3] btrfs-progs: check/lowmem: Cleanup unnecessary _v2 suffix
  2018-02-01  6:45 [PATCH v2 0/3] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
@ 2018-02-01  6:45 ` Qu Wenruo
  2018-02-01  6:45 ` [PATCH v2 3/3] btrfs-progs: check: Cleanup all checkpatch error and warning Qu Wenruo
  2018-02-01 16:05 ` [PATCH v2 0/3] btrfs-progs: Split lowmem mode check to its own David Sterba
  2 siblings, 0 replies; 11+ messages in thread
From: Qu Wenruo @ 2018-02-01  6:45 UTC (permalink / raw)
  To: linux-btrfs, dsterba

There used to be some functions with _v2 suffix to distinguish them from
original mode similar functions.

However now moved lowmem code to their own check/lowmem.[ch], cleanup
such _v2 suffixes, and for functions really needs to be distinguished
from original mode (exported functions), change the _v2 suffix to
_lowmem.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/lowmem.c | 46 +++++++++++++++++++++++-----------------------
 check/lowmem.h |  4 ++--
 check/main.c   |  4 ++--
 3 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/check/lowmem.c b/check/lowmem.c
index 5d17961edda7..a3bda97fdea8 100644
--- a/check/lowmem.c
+++ b/check/lowmem.c
@@ -28,8 +28,8 @@
 #include "check/common.h"
 #include "check/lowmem.h"
 
-static int calc_extent_flag_v2(struct btrfs_root *root, struct extent_buffer *eb,
-			       u64 *flags_ret)
+static int calc_extent_flag(struct btrfs_root *root, struct extent_buffer *eb,
+			    u64 *flags_ret)
 {
 	struct btrfs_root *extent_root = root->fs_info->extent_root;
 	struct btrfs_root_item *ri = &root->root_item;
@@ -225,7 +225,7 @@ static int update_nodes_refs(struct btrfs_root *root, u64 bytenr,
 	}
 
 	if (check_all && eb) {
-		calc_extent_flag_v2(root, eb, &flags);
+		calc_extent_flag(root, eb, &flags);
 		if (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)
 			nrefs->full_backref[level] = 1;
 	}
@@ -2081,8 +2081,8 @@ out:
  * Returns <0  Fatal error, must exit the whole check
  * Returns 0   No errors found
  */
-static int process_one_leaf_v2(struct btrfs_root *root, struct btrfs_path *path,
-			       struct node_refs *nrefs, int *level, int ext_ref)
+static int process_one_leaf(struct btrfs_root *root, struct btrfs_path *path,
+			    struct node_refs *nrefs, int *level, int ext_ref)
 {
 	struct extent_buffer *cur = path->nodes[0];
 	struct btrfs_key key;
@@ -3895,10 +3895,10 @@ out:
  * Returns <0  Fatal error, must exit the whole check
  * Returns 0   No errors found
  */
-static int walk_down_tree_v2(struct btrfs_trans_handle *trans,
-			     struct btrfs_root *root, struct btrfs_path *path,
-			     int *level, struct node_refs *nrefs, int ext_ref,
-			     int check_all)
+static int walk_down_tree(struct btrfs_trans_handle *trans,
+			  struct btrfs_root *root, struct btrfs_path *path,
+			  int *level, struct node_refs *nrefs, int ext_ref,
+			  int check_all)
 {
 	enum btrfs_tree_block_status status;
 	u64 bytenr;
@@ -3968,8 +3968,8 @@ static int walk_down_tree_v2(struct btrfs_trans_handle *trans,
 
 			ret = 0;
 			if (!check_all)
-				ret = process_one_leaf_v2(root, path, nrefs,
-							  level, ext_ref);
+				ret = process_one_leaf(root, path, nrefs,
+						       level, ext_ref);
 			else
 				ret = check_leaf_items(trans, root, path,
 					       nrefs, account_file_data);
@@ -3993,7 +3993,7 @@ static int walk_down_tree_v2(struct btrfs_trans_handle *trans,
 		if (ret < 0)
 			break;
 		/*
-		 * check all trees in check_chunks_and_extent_v2
+		 * check all trees in check_chunks_and_extent
 		 * check shared node once in check_fs_roots
 		 */
 		if (!check_all && !nrefs->need_check[*level - 1]) {
@@ -4046,8 +4046,8 @@ static int walk_down_tree_v2(struct btrfs_trans_handle *trans,
 	return err;
 }
 
-static int walk_up_tree_v2(struct btrfs_root *root, struct btrfs_path *path,
-			   int *level)
+static int walk_up_tree(struct btrfs_root *root, struct btrfs_path *path,
+			int *level)
 {
 	int i;
 	struct extent_buffer *leaf;
@@ -4200,7 +4200,7 @@ out:
 }
 
 /*
- * This function calls walk_down_tree_v2 and walk_up_tree_v2 to check tree
+ * This function calls walk_down_tree and walk_up_tree to check tree
  * blocks and integrity of fs tree items.
  *
  * @root:         the root of the tree to be checked.
@@ -4257,8 +4257,8 @@ static int check_btrfs_root(struct btrfs_trans_handle *trans,
 	}
 
 	while (1) {
-		ret = walk_down_tree_v2(trans, root, &path, &level, &nrefs,
-					ext_ref, check_all);
+		ret = walk_down_tree(trans, root, &path, &level, &nrefs,
+				     ext_ref, check_all);
 
 		err |= !!ret;
 
@@ -4268,7 +4268,7 @@ static int check_btrfs_root(struct btrfs_trans_handle *trans,
 			break;
 		}
 
-		ret = walk_up_tree_v2(root, &path, &level);
+		ret = walk_up_tree(root, &path, &level);
 		if (ret != 0) {
 			/* Normal exit, reset ret to err */
 			ret = err;
@@ -4290,7 +4290,7 @@ out:
  * Return 0 if no error found.
  * Return <0 for error.
  */
-static int check_fs_root_v2(struct btrfs_root *root, unsigned int ext_ref)
+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);
@@ -4390,12 +4390,12 @@ out:
 /*
  * Check all fs/file tree in low_memory mode.
  *
- * 1. for fs tree root item, call check_fs_root_v2()
+ * 1. for fs tree root item, call check_fs_root()
  * 2. for fs tree root ref/backref, call check_root_ref()
  *
  * Return 0 if no error occurred.
  */
-int check_fs_roots_v2(struct btrfs_fs_info *fs_info)
+int check_fs_roots_lowmem(struct btrfs_fs_info *fs_info)
 {
 	struct btrfs_root *tree_root = fs_info->tree_root;
 	struct btrfs_root *cur_root = NULL;
@@ -4446,7 +4446,7 @@ int check_fs_roots_v2(struct btrfs_fs_info *fs_info)
 				goto next;
 			}
 
-			ret = check_fs_root_v2(cur_root, ext_ref);
+			ret = check_fs_root(cur_root, ext_ref);
 			err |= ret;
 
 			if (key.objectid == BTRFS_TREE_RELOC_OBJECTID)
@@ -4474,7 +4474,7 @@ out:
 /*
  * Low memory usage version check_chunks_and_extents.
  */
-int check_chunks_and_extents_v2(struct btrfs_fs_info *fs_info)
+int check_chunks_and_extents_lowmem(struct btrfs_fs_info *fs_info)
 {
 	struct btrfs_trans_handle *trans = NULL;
 	struct btrfs_path path;
diff --git a/check/lowmem.h b/check/lowmem.h
index d1051a0b37ec..39deff0cc26c 100644
--- a/check/lowmem.h
+++ b/check/lowmem.h
@@ -61,7 +61,7 @@
 #define ACCOUNTING_MISMATCH	(1 << 7) /* Used space accounting error */
 #define CHUNK_TYPE_MISMATCH	(1 << 8)
 
-int check_fs_roots_v2(struct btrfs_fs_info *fs_info);
-int check_chunks_and_extents_v2(struct btrfs_fs_info *fs_info);
+int check_fs_roots_lowmem(struct btrfs_fs_info *fs_info);
+int check_chunks_and_extents_lowmem(struct btrfs_fs_info *fs_info);
 
 #endif
diff --git a/check/main.c b/check/main.c
index 98e24afb42b5..aec3881fc043 100644
--- a/check/main.c
+++ b/check/main.c
@@ -3465,7 +3465,7 @@ static int do_check_fs_roots(struct btrfs_fs_info *fs_info,
 	if (!ctx.progress_enabled)
 		fprintf(stderr, "checking fs roots\n");
 	if (check_mode == CHECK_MODE_LOWMEM)
-		ret = check_fs_roots_v2(fs_info);
+		ret = check_fs_roots_lowmem(fs_info);
 	else
 		ret = check_fs_roots(fs_info, root_cache);
 
@@ -8257,7 +8257,7 @@ static int do_check_chunks_and_extents(struct btrfs_fs_info *fs_info)
 	if (!ctx.progress_enabled)
 		fprintf(stderr, "checking extents\n");
 	if (check_mode == CHECK_MODE_LOWMEM)
-		ret = check_chunks_and_extents_v2(fs_info);
+		ret = check_chunks_and_extents_lowmem(fs_info);
 	else
 		ret = check_chunks_and_extents(fs_info);
 
-- 
2.16.1


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

* [PATCH v2 3/3] btrfs-progs: check: Cleanup all checkpatch error and warning
  2018-02-01  6:45 [PATCH v2 0/3] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
  2018-02-01  6:45 ` [PATCH v2 2/3] btrfs-progs: check/lowmem: Cleanup unnecessary _v2 suffix Qu Wenruo
@ 2018-02-01  6:45 ` Qu Wenruo
  2018-02-01  7:08   ` Su Yue
  2018-02-01  8:36   ` Nikolay Borisov
  2018-02-01 16:05 ` [PATCH v2 0/3] btrfs-progs: Split lowmem mode check to its own David Sterba
  2 siblings, 2 replies; 11+ messages in thread
From: Qu Wenruo @ 2018-02-01  6:45 UTC (permalink / raw)
  To: linux-btrfs, dsterba

Since we're moving tons of codes, it's a good idea to fix all errors and
warnings from checkpatch.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/lowmem.c |  65 +++++++++------
 check/main.c   | 253 +++++++++++++++++++++++++++++----------------------------
 2 files changed, 165 insertions(+), 153 deletions(-)

diff --git a/check/lowmem.c b/check/lowmem.c
index a3bda97fdea8..3e7fe148bc56 100644
--- a/check/lowmem.c
+++ b/check/lowmem.c
@@ -322,7 +322,8 @@ static int repair_tree_block_ref(struct btrfs_trans_handle *trans,
 			goto out;
 
 		eb = path.nodes[0];
-		ei = btrfs_item_ptr(eb, path.slots[0], struct btrfs_extent_item);
+		ei = btrfs_item_ptr(eb, path.slots[0],
+				    struct btrfs_extent_item);
 
 		btrfs_set_extent_refs(eb, ei, 0);
 		btrfs_set_extent_generation(eb, ei, generation);
@@ -730,7 +731,9 @@ begin:
 		need_research = 0;
 		btrfs_release_path(path);
 		ret = btrfs_search_slot(NULL, root, ref_key, path, 0, 0);
-		/* the item was deleted, let path point to the last checked item */
+		/*
+		 * the item was deleted, let path point to the last checked item
+		 */
 		if (ret > 0) {
 			if (path->slots[0] == 0)
 				btrfs_prev_leaf(root, path);
@@ -1486,7 +1489,8 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_key *fkey,
 		search_start = disk_bytenr;
 		search_len = disk_num_bytes;
 	}
-	ret = count_csum_range(root->fs_info, search_start, search_len, &csum_found);
+	ret = count_csum_range(root->fs_info, search_start, search_len,
+			       &csum_found);
 	if (csum_found > 0 && nodatasum) {
 		err |= ODD_CSUM_ITEM;
 		error("root %llu EXTENT_DATA[%llu %llu] nodatasum shouldn't have datasum",
@@ -1497,7 +1501,8 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_key *fkey,
 		error("root %llu EXTENT_DATA[%llu %llu] csum missing, have: %llu, expected: %llu",
 		      root->objectid, fkey->objectid, fkey->offset,
 		      csum_found, search_len);
-	} else if (extent_type == BTRFS_FILE_EXTENT_PREALLOC && csum_found > 0) {
+	} else if (extent_type == BTRFS_FILE_EXTENT_PREALLOC &&
+		   csum_found > 0) {
 		err |= ODD_CSUM_ITEM;
 		error("root %llu EXTENT_DATA[%llu %llu] prealloc shouldn't have csum, but has: %llu",
 		      root->objectid, fkey->objectid, fkey->offset, csum_found);
@@ -1561,7 +1566,8 @@ loop:
 	}
 
 special_case:
-	di = btrfs_item_ptr(path.nodes[0], path.slots[0], struct btrfs_dir_item);
+	di = btrfs_item_ptr(path.nodes[0], path.slots[0],
+			    struct btrfs_dir_item);
 	cur = 0;
 	total = btrfs_item_size_nr(path.nodes[0], path.slots[0]);
 
@@ -1913,7 +1919,8 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path,
 	nodatasum = btrfs_inode_flags(node, ii) & BTRFS_INODE_NODATASUM;
 
 	while (1) {
-		btrfs_item_key_to_cpu(path->nodes[0], &last_key, path->slots[0]);
+		btrfs_item_key_to_cpu(path->nodes[0], &last_key,
+				      path->slots[0]);
 		ret = btrfs_next_item(root, path);
 		if (ret < 0) {
 			/* out will fill 'err' rusing current statistics */
@@ -2360,7 +2367,7 @@ static int check_tree_block_ref(struct btrfs_root *root,
 				 * Check if the backref points to valid
 				 * referencer
 				 */
-				found_ref = !check_tree_block_ref( root, NULL,
+				found_ref = !check_tree_block_ref(root, NULL,
 						offset, level + 1, owner,
 						NULL);
 			}
@@ -2500,7 +2507,8 @@ static int repair_extent_data_item(struct btrfs_trans_handle *trans,
 		if (ret)
 			goto out;
 		eb = path.nodes[0];
-		ei = btrfs_item_ptr(eb, path.slots[0], struct btrfs_extent_item);
+		ei = btrfs_item_ptr(eb, path.slots[0],
+				    struct btrfs_extent_item);
 
 		btrfs_set_extent_refs(eb, ei, 0);
 		btrfs_set_extent_generation(eb, ei, generation);
@@ -2657,7 +2665,8 @@ static int check_extent_data_item(struct btrfs_root *root,
 		}
 		if (type == BTRFS_EXTENT_DATA_REF_KEY) {
 			ref_root = btrfs_extent_data_ref_root(leaf, dref);
-			ref_objectid = btrfs_extent_data_ref_objectid(leaf, dref);
+			ref_objectid = btrfs_extent_data_ref_objectid(leaf,
+								      dref);
 			ref_offset = btrfs_extent_data_ref_offset(leaf, dref);
 
 			if (ref_objectid == fi_key.objectid &&
@@ -2820,8 +2829,8 @@ static int check_block_group_item(struct btrfs_fs_info *fs_info,
 			if (!(bg_flags & BTRFS_BLOCK_GROUP_DATA)) {
 				error(
 			"bad extent[%llu, %llu) type mismatch with chunk",
-					extent_key.objectid,
-					extent_key.objectid + extent_key.offset);
+				      extent_key.objectid,
+				      extent_key.objectid + extent_key.offset);
 				err |= CHUNK_TYPE_MISMATCH;
 			}
 		} else if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
@@ -3175,7 +3184,8 @@ static int check_extent_data_backref(struct btrfs_fs_info *fs_info,
 		    btrfs_header_owner(leaf) != root_id)
 			goto next;
 		btrfs_item_key_to_cpu(leaf, &key, slot);
-		if (key.objectid != objectid || key.type != BTRFS_EXTENT_DATA_KEY)
+		if (key.objectid != objectid || key.type !=
+		    BTRFS_EXTENT_DATA_KEY)
 			break;
 		fi = btrfs_item_ptr(leaf, slot, struct btrfs_file_extent_item);
 		/*
@@ -3205,7 +3215,8 @@ out:
 	if (found_count != count) {
 		error(
 "extent[%llu, %llu] referencer count mismatch (root: %llu, owner: %llu, offset: %llu) wanted: %u, have: %u",
-			bytenr, len, root_id, objectid, offset, count, found_count);
+			bytenr, len, root_id, objectid, offset, count,
+			found_count);
 		return REFERENCER_MISSING;
 	}
 	return 0;
@@ -3975,13 +3986,12 @@ static int walk_down_tree(struct btrfs_trans_handle *trans,
 					       nrefs, account_file_data);
 			err |= ret;
 			break;
-		} else {
-			if (check || !check_all) {
-				ret = btrfs_check_node(root, NULL, cur);
-				if (ret != BTRFS_TREE_BLOCK_CLEAN) {
-					err |= -EIO;
-					break;
-				}
+		}
+		if (check || !check_all) {
+			ret = btrfs_check_node(root, NULL, cur);
+			if (ret != BTRFS_TREE_BLOCK_CLEAN) {
+				err |= -EIO;
+				break;
 			}
 		}
 
@@ -4001,7 +4011,8 @@ static int walk_down_tree(struct btrfs_trans_handle *trans,
 			continue;
 		}
 
-		next = btrfs_find_tree_block(fs_info, bytenr, fs_info->nodesize);
+		next = btrfs_find_tree_block(fs_info, bytenr,
+					     fs_info->nodesize);
 		if (!next || !btrfs_buffer_uptodate(next, ptr_gen)) {
 			free_extent_buffer(next);
 			reada_walk_down(root, cur, path->slots[*level]);
@@ -4022,7 +4033,7 @@ static int walk_down_tree(struct btrfs_trans_handle *trans,
 
 		ret = check_child_node(cur, path->slots[*level], next);
 		err |= ret;
-		if (ret < 0) 
+		if (ret < 0)
 			break;
 
 		if (btrfs_is_leaf(next))
@@ -4041,7 +4052,8 @@ static int walk_down_tree(struct btrfs_trans_handle *trans,
 		path->slots[*level] = 0;
 		account_file_data = 0;
 
-		update_nodes_refs(root, (u64)-1, next, nrefs, *level, check_all);
+		update_nodes_refs(root, (u64)-1, next, nrefs, *level,
+				  check_all);
 	}
 	return err;
 }
@@ -4058,11 +4070,10 @@ static int walk_up_tree(struct btrfs_root *root, struct btrfs_path *path,
 			path->slots[i]++;
 			*level = i;
 			return 0;
-		} else {
-			free_extent_buffer(path->nodes[*level]);
-			path->nodes[*level] = NULL;
-			*level = i + 1;
 		}
+		free_extent_buffer(path->nodes[*level]);
+		path->nodes[*level] = NULL;
+		*level = i + 1;
 	}
 	return 1;
 }
diff --git a/check/main.c b/check/main.c
index aec3881fc043..f6874cd86543 100644
--- a/check/main.c
+++ b/check/main.c
@@ -1720,14 +1720,13 @@ static int walk_up_tree(struct btrfs_root *root, struct btrfs_path *path,
 			path->slots[i]++;
 			*level = i;
 			return 0;
-		} else {
-			free_extent_buffer(path->nodes[*level]);
-			path->nodes[*level] = NULL;
-			BUG_ON(*level > wc->active_node);
-			if (*level == wc->active_node)
-				leave_shared_node(root, wc, *level);
-			*level = i + 1;
 		}
+		free_extent_buffer(path->nodes[*level]);
+		path->nodes[*level] = NULL;
+		BUG_ON(*level > wc->active_node);
+		if (*level == wc->active_node)
+			leave_shared_node(root, wc, *level);
+		*level = i + 1;
 	}
 	return 1;
 }
@@ -3488,22 +3487,21 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
 				goto out;
 			if (back->is_data) {
 				dback = to_data_backref(back);
-				fprintf(stderr, "Data backref %llu %s %llu"
-					" owner %llu offset %llu num_refs %lu"
-					" not found in extent tree\n",
+				fprintf(stderr,
+"Data backref %llu %s %llu owner %llu offset %llu num_refs %lu not found in extent tree\n",
 					(unsigned long long)rec->start,
 					back->full_backref ?
 					"parent" : "root",
 					back->full_backref ?
-					(unsigned long long)dback->parent:
+					(unsigned long long)dback->parent :
 					(unsigned long long)dback->root,
 					(unsigned long long)dback->owner,
 					(unsigned long long)dback->offset,
 					(unsigned long)dback->num_refs);
 			} else {
 				tback = to_tree_backref(back);
-				fprintf(stderr, "Tree backref %llu parent %llu"
-					" root %llu not found in extent tree\n",
+				fprintf(stderr,
+"Tree backref %llu parent %llu root %llu not found in extent tree\n",
 					(unsigned long long)rec->start,
 					(unsigned long long)tback->parent,
 					(unsigned long long)tback->root);
@@ -3514,7 +3512,8 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
 			if (!print_errs)
 				goto out;
 			tback = to_tree_backref(back);
-			fprintf(stderr, "Backref %llu %s %llu not referenced back %p\n",
+			fprintf(stderr,
+				"Backref %llu %s %llu not referenced back %p\n",
 				(unsigned long long)rec->start,
 				back->full_backref ? "parent" : "root",
 				back->full_backref ?
@@ -3527,26 +3526,25 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
 				err = 1;
 				if (!print_errs)
 					goto out;
-				fprintf(stderr, "Incorrect local backref count"
-					" on %llu %s %llu owner %llu"
-					" offset %llu found %u wanted %u back %p\n",
+				fprintf(stderr,
+"Incorrect local backref count on %llu %s %llu owner %llu offset %llu found %u wanted %u back %p\n",
 					(unsigned long long)rec->start,
 					back->full_backref ?
 					"parent" : "root",
 					back->full_backref ?
-					(unsigned long long)dback->parent:
+					(unsigned long long)dback->parent :
 					(unsigned long long)dback->root,
 					(unsigned long long)dback->owner,
 					(unsigned long long)dback->offset,
-					dback->found_ref, dback->num_refs, back);
+					dback->found_ref, dback->num_refs,
+					back);
 			}
 			if (dback->disk_bytenr != rec->start) {
 				err = 1;
 				if (!print_errs)
 					goto out;
-				fprintf(stderr, "Backref disk bytenr does not"
-					" match extent record, bytenr=%llu, "
-					"ref bytenr=%llu\n",
+				fprintf(stderr,
+"Backref disk bytenr does not match extent record, bytenr=%llu, ref bytenr=%llu\n",
 					(unsigned long long)rec->start,
 					(unsigned long long)dback->disk_bytenr);
 			}
@@ -3555,9 +3553,8 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
 				err = 1;
 				if (!print_errs)
 					goto out;
-				fprintf(stderr, "Backref bytes do not match "
-					"extent backref, bytenr=%llu, ref "
-					"bytes=%llu, backref bytes=%llu\n",
+				fprintf(stderr,
+"Backref bytes do not match extent backref, bytenr=%llu, ref bytes=%llu, backref bytes=%llu\n",
 					(unsigned long long)rec->start,
 					(unsigned long long)rec->nr,
 					(unsigned long long)dback->bytes);
@@ -3574,8 +3571,8 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
 		err = 1;
 		if (!print_errs)
 			goto out;
-		fprintf(stderr, "Incorrect global backref count "
-			"on %llu found %llu wanted %llu\n",
+		fprintf(stderr,
+"Incorrect global backref count on %llu found %llu wanted %llu\n",
 			(unsigned long long)rec->start,
 			(unsigned long long)found,
 			(unsigned long long)rec->refs);
@@ -3745,6 +3742,7 @@ static int swap_values(struct btrfs_root *root, struct btrfs_path *path,
 				    sizeof(struct btrfs_key_ptr));
 		if (slot == 0) {
 			struct btrfs_disk_key key;
+
 			btrfs_node_key(buf, &key, 0);
 			btrfs_fixup_low_keys(root, path, &key,
 					     btrfs_header_level(buf) + 1);
@@ -3877,8 +3875,8 @@ again:
 				ret = delete_bogus_item(root, path, buf, i);
 				if (!ret)
 					goto again;
-				fprintf(stderr, "item is off the end of the "
-					"leaf, can't fix\n");
+				fprintf(stderr,
+				"item is off the end of the leaf, can't fix\n");
 				ret = -EIO;
 				break;
 			}
@@ -4066,7 +4064,7 @@ static struct tree_backref *find_tree_backref(struct extent_record *rec,
 	struct extent_backref *node;
 	struct tree_backref *back;
 
-	while(cur != &rec->backrefs) {
+	while (cur != &rec->backrefs) {
 		node = to_extent_backref(cur);
 		cur = cur->next;
 		if (node->is_data)
@@ -4118,7 +4116,7 @@ static struct data_backref *find_data_backref(struct extent_record *rec,
 	struct extent_backref *node;
 	struct data_backref *back;
 
-	while(cur != &rec->backrefs) {
+	while (cur != &rec->backrefs) {
 		node = to_extent_backref(cur);
 		cur = cur->next;
 		if (!node->is_data)
@@ -4344,12 +4342,13 @@ static int add_extent_rec(struct cache_tree *extent_cache,
 
 		if (tmpl->extent_item_refs && !dup) {
 			if (rec->extent_item_refs) {
-				fprintf(stderr, "block %llu rec "
-					"extent_item_refs %llu, passed %llu\n",
+				fprintf(stderr,
+			"block %llu rec extent_item_refs %llu, passed %llu\n",
 					(unsigned long long)tmpl->start,
 					(unsigned long long)
 							rec->extent_item_refs,
-					(unsigned long long)tmpl->extent_item_refs);
+					(unsigned long long)
+							tmpl->extent_item_refs);
 			}
 			rec->extent_item_refs = tmpl->extent_item_refs;
 		}
@@ -4433,8 +4432,8 @@ static int add_tree_backref(struct cache_tree *extent_cache, u64 bytenr,
 
 	if (found_ref) {
 		if (back->node.found_ref) {
-			fprintf(stderr, "Extent back ref already exists "
-				"for %llu parent %llu root %llu \n",
+			fprintf(stderr,
+	"Extent back ref already exists for %llu parent %llu root %llu\n",
 				(unsigned long long)bytenr,
 				(unsigned long long)parent,
 				(unsigned long long)root);
@@ -4442,8 +4441,8 @@ static int add_tree_backref(struct cache_tree *extent_cache, u64 bytenr,
 		back->node.found_ref = 1;
 	} else {
 		if (back->node.found_extent_tree) {
-			fprintf(stderr, "Extent back ref already exists "
-				"for %llu parent %llu root %llu \n",
+			fprintf(stderr,
+	"Extent back ref already exists for %llu parent %llu root %llu\n",
 				(unsigned long long)bytenr,
 				(unsigned long long)parent,
 				(unsigned long long)root);
@@ -4530,9 +4529,8 @@ static int add_data_backref(struct cache_tree *extent_cache, u64 bytenr,
 		rec->owner_ref_checked = 1;
 	} else {
 		if (back->node.found_extent_tree) {
-			fprintf(stderr, "Extent back ref already exists "
-				"for %llu parent %llu root %llu "
-				"owner %llu offset %llu num_refs %lu\n",
+			fprintf(stderr,
+"Extent back ref already exists for %llu parent %llu root %llu owner %llu offset %llu num_refs %lu\n",
 				(unsigned long long)bytenr,
 				(unsigned long long)parent,
 				(unsigned long long)root,
@@ -4555,6 +4553,7 @@ static int add_pending(struct cache_tree *pending,
 		       struct cache_tree *seen, u64 bytenr, u32 size)
 {
 	int ret;
+
 	ret = add_cache_extent(seen, bytenr, size);
 	if (ret)
 		return ret;
@@ -4588,17 +4587,17 @@ static int pick_next_pending(struct cache_tree *pending,
 		cache = search_cache_extent(nodes, 0);
 
 	if (!cache) {
-		 cache = search_cache_extent(pending, 0);
-		 if (!cache)
-			 return 0;
-		 ret = 0;
-		 do {
-			 bits[ret].start = cache->start;
-			 bits[ret].size = cache->size;
-			 cache = next_cache_extent(cache);
-			 ret++;
-		 } while (cache && ret < bits_nr);
-		 return ret;
+		cache = search_cache_extent(pending, 0);
+		if (!cache)
+			return 0;
+		ret = 0;
+		do {
+			bits[ret].start = cache->start;
+			bits[ret].size = cache->size;
+			cache = next_cache_extent(cache);
+			ret++;
+		} while (cache && ret < bits_nr);
+		return ret;
 	}
 
 	ret = 0;
@@ -4612,8 +4611,9 @@ static int pick_next_pending(struct cache_tree *pending,
 	if (bits_nr - ret > 8) {
 		u64 lookup = bits[0].start + bits[0].size;
 		struct cache_extent *next;
+
 		next = search_cache_extent(pending, lookup);
-		while(next) {
+		while (next) {
 			if (next->start - lookup > 32768)
 				break;
 			bits[ret].start = next->start;
@@ -5004,6 +5004,7 @@ static int process_extent_item(struct btrfs_root *root,
 	if (item_size < sizeof(*ei)) {
 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
 		struct btrfs_extent_item_v0 *ei0;
+
 		if (item_size != sizeof(*ei0)) {
 			error(
 	"invalid extent item format: ITEM[%llu %u %llu] leaf: %llu slot: %d",
@@ -5356,8 +5357,8 @@ static int check_space_cache(struct btrfs_root *root)
 
 static int check_extent_csums(struct btrfs_root *root, u64 bytenr,
 			u64 num_bytes, unsigned long leaf_offset,
-			struct extent_buffer *eb) {
-
+			struct extent_buffer *eb)
+{
 	struct btrfs_fs_info *fs_info = root->fs_info;
 	u64 offset = 0;
 	u16 csum_size = btrfs_super_csum_size(fs_info->super_copy);
@@ -5646,7 +5647,8 @@ skip_csum_check:
 }
 
 static int is_dropped_key(struct btrfs_key *key,
-			  struct btrfs_key *drop_key) {
+			  struct btrfs_key *drop_key)
+{
 	if (key->objectid < drop_key->objectid)
 		return 1;
 	else if (key->objectid == drop_key->objectid) {
@@ -5823,7 +5825,7 @@ static int run_next_block(struct btrfs_root *root,
 		return 1;
 
 	if (!reada_bits) {
-		for(i = 0; i < nritems; i++) {
+		for (i = 0; i < nritems; i++) {
 			ret = add_cache_extent(reada, bits[i].start,
 					       bits[i].size);
 			if (ret == -EEXIST)
@@ -5933,6 +5935,7 @@ static int run_next_block(struct btrfs_root *root,
 		btree_space_waste += btrfs_leaf_free_space(root, buf);
 		for (i = 0; i < nritems; i++) {
 			struct btrfs_file_extent_item *fi;
+
 			btrfs_item_key_to_cpu(buf, &key, i);
 			/*
 			 * Check key type against the leaf owner.
@@ -6007,6 +6010,7 @@ static int run_next_block(struct btrfs_root *root,
 			}
 			if (key.type == BTRFS_EXTENT_DATA_REF_KEY) {
 				struct btrfs_extent_data_ref *ref;
+
 				ref = btrfs_item_ptr(buf, i,
 						struct btrfs_extent_data_ref);
 				add_data_backref(extent_cache,
@@ -6021,6 +6025,7 @@ static int run_next_block(struct btrfs_root *root,
 			}
 			if (key.type == BTRFS_SHARED_DATA_REF_KEY) {
 				struct btrfs_shared_data_ref *ref;
+
 				ref = btrfs_item_ptr(buf, i,
 						struct btrfs_shared_data_ref);
 				add_data_backref(extent_cache,
@@ -6058,9 +6063,9 @@ static int run_next_block(struct btrfs_root *root,
 
 			data_bytes_allocated +=
 				btrfs_file_extent_disk_num_bytes(buf, fi);
-			if (data_bytes_allocated < root->fs_info->sectorsize) {
+			if (data_bytes_allocated < root->fs_info->sectorsize)
 				abort();
-			}
+
 			data_bytes_referenced +=
 				btrfs_file_extent_num_bytes(buf, fi);
 			add_data_backref(extent_cache,
@@ -6093,7 +6098,8 @@ static int run_next_block(struct btrfs_root *root,
 
 			memset(&tmpl, 0, sizeof(tmpl));
 			btrfs_cpu_key_to_disk(&tmpl.parent_key, &key);
-			tmpl.parent_generation = btrfs_node_ptr_generation(buf, i);
+			tmpl.parent_generation =
+				btrfs_node_ptr_generation(buf, i);
 			tmpl.start = ptr;
 			tmpl.nr = size;
 			tmpl.refs = 1;
@@ -6112,11 +6118,10 @@ static int run_next_block(struct btrfs_root *root,
 				continue;
 			}
 
-			if (level > 1) {
+			if (level > 1)
 				add_pending(nodes, seen, ptr, size);
-			} else {
+			else
 				add_pending(pending, seen, ptr, size);
-			}
 		}
 		btree_space_waste += (BTRFS_NODEPTRS_PER_BLOCK(fs_info) -
 				      nritems) * sizeof(struct btrfs_key_ptr);
@@ -6188,6 +6193,7 @@ static int free_extent_hook(struct btrfs_trans_handle *trans,
 	rec = container_of(cache, struct extent_record, cache);
 	if (is_data) {
 		struct data_backref *back;
+
 		back = find_data_backref(rec, parent, root_objectid, owner,
 					 offset, 1, bytenr, num_bytes);
 		if (!back)
@@ -6213,6 +6219,7 @@ static int free_extent_hook(struct btrfs_trans_handle *trans,
 		}
 	} else {
 		struct tree_backref *back;
+
 		back = find_tree_backref(rec, parent, root_objectid);
 		if (!back)
 			goto out;
@@ -6252,7 +6259,7 @@ static int delete_extent_records(struct btrfs_trans_handle *trans,
 	key.type = (u8)-1;
 	key.offset = (u64)-1;
 
-	while(1) {
+	while (1) {
 		ret = btrfs_search_slot(trans, root->fs_info->extent_root,
 					&key, path, 0, 1);
 		if (ret < 0)
@@ -6365,7 +6372,7 @@ static int record_extent(struct btrfs_trans_handle *trans,
 			btrfs_set_extent_flags(leaf, ei,
 					       BTRFS_EXTENT_FLAG_DATA);
 		} else {
-			struct btrfs_disk_key copy_key;;
+			struct btrfs_disk_key copy_key;
 
 			bi = (struct btrfs_tree_block_info *)(ei + 1);
 			memset_extent_buffer(leaf, 0, (unsigned long)bi,
@@ -6379,8 +6386,8 @@ static int record_extent(struct btrfs_trans_handle *trans,
 			btrfs_set_tree_block_level(leaf, bi, rec->info_level);
 			btrfs_set_tree_block_key(leaf, bi, &copy_key);
 
-			btrfs_set_extent_flags(leaf, ei,
-					       BTRFS_EXTENT_FLAG_TREE_BLOCK | flags);
+			btrfs_set_extent_flags(leaf, ei, flags |
+					       BTRFS_EXTENT_FLAG_TREE_BLOCK);
 		}
 
 		btrfs_mark_buffer_dirty(leaf);
@@ -6418,18 +6425,14 @@ static int record_extent(struct btrfs_trans_handle *trans,
 			if (ret)
 				break;
 		}
-		fprintf(stderr, "adding new data backref"
-				" on %llu %s %llu owner %llu"
-				" offset %llu found %d\n",
-				(unsigned long long)rec->start,
-				back->full_backref ?
-				"parent" : "root",
-				back->full_backref ?
-				(unsigned long long)parent :
-				(unsigned long long)dback->root,
-				(unsigned long long)dback->owner,
-				(unsigned long long)dback->offset,
-				dback->found_ref);
+		fprintf(stderr,
+"adding new data backref on %llu %s %llu owner %llu offset %llu found %d\n",
+			(unsigned long long)rec->start,
+			back->full_backref ? "parent" : "root",
+			back->full_backref ? (unsigned long long)parent :
+					     (unsigned long long)dback->root,
+			(unsigned long long)dback->owner,
+			(unsigned long long)dback->offset, dback->found_ref);
 	} else {
 		u64 parent;
 		struct tree_backref *tback;
@@ -6443,8 +6446,8 @@ static int record_extent(struct btrfs_trans_handle *trans,
 		ret = btrfs_inc_extent_ref(trans, info->extent_root,
 					   rec->start, rec->max_size,
 					   parent, tback->root, 0, 0);
-		fprintf(stderr, "adding new tree backref on "
-			"start %llu len %llu parent %llu root %llu\n",
+		fprintf(stderr,
+"adding new tree backref on start %llu len %llu parent %llu root %llu\n",
 			rec->start, rec->max_size, parent, tback->root);
 	}
 fail:
@@ -6587,9 +6590,9 @@ static int repair_ref(struct btrfs_fs_info *info, struct btrfs_path *path,
 		goto out;
 	}
 	if (ret > 0) {
-		fprintf(stderr, "Well that's odd, we just found this key "
-			"[%Lu, %u, %Lu]\n", key.objectid, key.type,
-			key.offset);
+		fprintf(stderr,
+		"Well that's odd, we just found this key [%Lu, %u, %Lu]\n",
+			key.objectid, key.type, key.offset);
 		ret = -EINVAL;
 		goto out;
 	}
@@ -6599,10 +6602,8 @@ static int repair_ref(struct btrfs_fs_info *info, struct btrfs_path *path,
 
 	if (btrfs_file_extent_compression(leaf, fi) &&
 	    dback->disk_bytenr != entry->bytenr) {
-		fprintf(stderr, "Ref doesn't match the record start and is "
-			"compressed, please take a btrfs-image of this file "
-			"system and send it to a btrfs developer so they can "
-			"complete this functionality for bytenr %Lu\n",
+		fprintf(stderr,
+"Ref doesn't match the record start and is compressed, please take a btrfs-image of this file system and send it to a btrfs developer so they can complete this functionality for bytenr %Lu\n",
 			dback->disk_bytenr);
 		ret = -EINVAL;
 		goto out;
@@ -6618,9 +6619,8 @@ static int repair_ref(struct btrfs_fs_info *info, struct btrfs_path *path,
 		if (dback->disk_bytenr + offset +
 		    btrfs_file_extent_num_bytes(leaf, fi) >
 		    entry->bytenr + entry->bytes) {
-			fprintf(stderr, "Ref is past the entry end, please "
-				"take a btrfs-image of this file system and "
-				"send it to a btrfs developer, ref %Lu\n",
+			fprintf(stderr,
+"Ref is past the entry end, please take a btrfs-image of this file system and send it to a btrfs developer, ref %Lu\n",
 				dback->disk_bytenr);
 			ret = -EINVAL;
 			goto out;
@@ -6633,9 +6633,8 @@ static int repair_ref(struct btrfs_fs_info *info, struct btrfs_path *path,
 
 		offset = btrfs_file_extent_offset(leaf, fi);
 		if (dback->disk_bytenr + offset < entry->bytenr) {
-			fprintf(stderr, "Ref is before the entry start, please"
-				" take a btrfs-image of this file system and "
-				"send it to a btrfs developer, ref %Lu\n",
+			fprintf(stderr,
+"Ref is before the entry start, please take a btrfs-image of this file system and send it to a btrfs developer, ref %Lu\n",
 				dback->disk_bytenr);
 			ret = -EINVAL;
 			goto out;
@@ -6741,8 +6740,9 @@ static int verify_backrefs(struct btrfs_fs_info *info, struct btrfs_path *path,
 	if (nr_entries <= 1 && !mismatch)
 		goto out;
 
-	fprintf(stderr, "attempting to repair backref discrepency for bytenr "
-		"%Lu\n", rec->start);
+	fprintf(stderr,
+		"attempting to repair backref discrepency for bytenr %Lu\n",
+		rec->start);
 
 	/*
 	 * First we want to see if the backrefs can agree amongst themselves who
@@ -6758,9 +6758,8 @@ static int verify_backrefs(struct btrfs_fs_info *info, struct btrfs_path *path,
 	if (!best) {
 		entry = find_entry(&entries, rec->start, rec->nr);
 		if (!entry && (!broken_entries || !rec->found_rec)) {
-			fprintf(stderr, "Backrefs don't agree with each other "
-				"and extent record doesn't agree with anybody,"
-				" so we can't fix bytenr %Lu bytes %Lu\n",
+			fprintf(stderr,
+"Backrefs don't agree with each other and extent record doesn't agree with anybody, so we can't fix bytenr %Lu bytes %Lu\n",
 				rec->start, rec->nr);
 			ret = -EINVAL;
 			goto out;
@@ -6783,10 +6782,9 @@ static int verify_backrefs(struct btrfs_fs_info *info, struct btrfs_path *path,
 		entry->count++;
 		best = find_most_right_entry(&entries);
 		if (!best) {
-			fprintf(stderr, "Backrefs and extent record evenly "
-				"split on who is right, this is going to "
-				"require user input to fix bytenr %Lu bytes "
-				"%Lu\n", rec->start, rec->nr);
+			fprintf(stderr,
+"Backrefs and extent record evenly split on who is right, this is going to require user input to fix bytenr %Lu bytes %Lu\n",
+				rec->start, rec->nr);
 			ret = -EINVAL;
 			goto out;
 		}
@@ -6798,10 +6796,8 @@ static int verify_backrefs(struct btrfs_fs_info *info, struct btrfs_path *path,
 	 * deal with it properly here yet, so just bail out of that's the case.
 	 */
 	if (best->bytenr != rec->start) {
-		fprintf(stderr, "Extent start and backref starts don't match, "
-			"please use btrfs-image on this file system and send "
-			"it to a btrfs developer so they can make fsck fix "
-			"this particular case.  bytenr is %Lu, bytes is %Lu\n",
+		fprintf(stderr,
+"Extent start and backref starts don't match, please use btrfs-image on this file system and send it to a btrfs developer so they can make fsck fix this particular case.  bytenr is %Lu, bytes is %Lu\n",
 			rec->start, rec->nr);
 		ret = -EINVAL;
 		goto out;
@@ -6951,10 +6947,8 @@ static int delete_duplicate_records(struct btrfs_root *root,
 			continue;
 
 		if (tmp->start + tmp->nr < good->start + good->nr) {
-			fprintf(stderr, "Ok we have overlapping extents that "
-				"aren't completely covered by each other, this "
-				"is going to require more careful thought.  "
-				"The extents are [%Lu-%Lu] and [%Lu-%Lu]\n",
+			fprintf(stderr,
+"Ok we have overlapping extents that aren't completely covered by each other, this is going to require more careful thought. The extents are [%Lu-%Lu] and [%Lu-%Lu]\n",
 				tmp->start, tmp->nr, good->start, good->nr);
 			abort();
 		}
@@ -6986,9 +6980,9 @@ static int delete_duplicate_records(struct btrfs_root *root,
 
 		/* Shouldn't happen but just in case */
 		if (tmp->metadata) {
-			fprintf(stderr, "Well this shouldn't happen, extent "
-				"record overlaps but is metadata? "
-				"[%Lu, %Lu]\n", tmp->start, tmp->nr);
+			fprintf(stderr,
+"Well this shouldn't happen, extent record overlaps but is metadata? [%Lu, %Lu]\n",
+				tmp->start, tmp->nr);
 			abort();
 		}
 
@@ -7090,6 +7084,7 @@ static int find_possible_backrefs(struct btrfs_fs_info *info,
 		cache = lookup_cache_extent(extent_cache, bytenr, 1);
 		if (cache) {
 			struct extent_record *tmp;
+
 			tmp = container_of(cache, struct extent_record, cache);
 
 			/*
@@ -7271,7 +7266,8 @@ static int fixup_extent_refs(struct btrfs_fs_info *info,
 			continue;
 
 		rec->bad_full_backref = 0;
-		ret = record_extent(trans, info, &path, rec, back, allocated, flags);
+		ret = record_extent(trans, info, &path, rec, back, allocated,
+				    flags);
 		allocated = 1;
 
 		if (ret)
@@ -7280,6 +7276,7 @@ static int fixup_extent_refs(struct btrfs_fs_info *info,
 out:
 	if (trans) {
 		int err = btrfs_commit_transaction(trans, info->extent_root);
+
 		if (!ret)
 			ret = err;
 	}
@@ -7401,8 +7398,8 @@ again:
 			goto del_ptr;
 	}
 	/*
-	 * we couldn't find the bad block.  TODO, search all the nodes for pointers
-	 * to this block
+	 * we couldn't find the bad block.
+	 * TODO: search all the nodes for pointers to this block
 	 */
 	if (eb == info->extent_root->node) {
 		ret = -ENOENT;
@@ -7437,7 +7434,8 @@ static int prune_corrupt_blocks(struct btrfs_fs_info *info)
 			if (IS_ERR(trans))
 				return PTR_ERR(trans);
 		}
-		corrupt = container_of(cache, struct btrfs_corrupt_block, cache);
+		corrupt = container_of(cache, struct btrfs_corrupt_block,
+				       cache);
 		prune_one_block(trans, info, corrupt);
 		remove_cache_extent(info->corrupt_blocks, cache);
 	}
@@ -7463,7 +7461,7 @@ static int check_extent_refs(struct btrfs_root *root,
 		 * extents in the FS
 		 */
 		cache = search_cache_extent(extent_cache, 0);
-		while(cache) {
+		while (cache) {
 			rec = container_of(cache, struct extent_record, cache);
 			set_extent_dirty(root->fs_info->excluded_extents,
 					 rec->start,
@@ -7473,7 +7471,7 @@ static int check_extent_refs(struct btrfs_root *root,
 
 		/* pin down all the corrupted blocks too */
 		cache = search_cache_extent(root->fs_info->corrupt_blocks, 0);
-		while(cache) {
+		while (cache) {
 			set_extent_dirty(root->fs_info->excluded_extents,
 					 cache->start,
 					 cache->start + cache->size - 1);
@@ -7518,7 +7516,7 @@ static int check_extent_refs(struct btrfs_root *root,
 	if (had_dups)
 		return -EAGAIN;
 
-	while(1) {
+	while (1) {
 		int cur_err = 0;
 		int fix = 0;
 
@@ -7527,8 +7525,9 @@ static int check_extent_refs(struct btrfs_root *root,
 			break;
 		rec = container_of(cache, struct extent_record, cache);
 		if (rec->num_duplicates) {
-			fprintf(stderr, "extent item %llu has multiple extent "
-				"items\n", (unsigned long long)rec->start);
+			fprintf(stderr,
+				"extent item %llu has multiple extent items\n",
+				(unsigned long long)rec->start);
 			cur_err = 1;
 		}
 
@@ -7561,7 +7560,8 @@ static int check_extent_refs(struct btrfs_root *root,
 		}
 
 		if (repair && fix) {
-			ret = fixup_extent_refs(root->fs_info, extent_cache, rec);
+			ret = fixup_extent_refs(root->fs_info, extent_cache,
+						rec);
 			if (ret)
 				goto repair_abort;
 		}
@@ -7943,8 +7943,8 @@ static int add_root_item_to_list(struct list_head *head,
 				  u8 level, u8 drop_level,
 				  struct btrfs_key *drop_key)
 {
-
 	struct root_item_record *ri_rec;
+
 	ri_rec = malloc(sizeof(*ri_rec));
 	if (!ri_rec)
 		return -ENOMEM;
@@ -7992,6 +7992,7 @@ static int deal_root_from_list(struct list_head *list,
 	while (!list_empty(list)) {
 		struct root_item_record *rec;
 		struct extent_buffer *buf;
+
 		rec = list_entry(list->next,
 				 struct root_item_record, list);
 		last = 0;
@@ -8123,7 +8124,7 @@ again:
 	ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, &path, 0, 0);
 	if (ret < 0)
 		goto out;
-	while(1) {
+	while (1) {
 		leaf = path.nodes[0];
 		slot = path.slots[0];
 		if (slot >= btrfs_header_nritems(path.nodes[0])) {
-- 
2.16.1


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

* Re: [PATCH v2 3/3] btrfs-progs: check: Cleanup all checkpatch error and warning
  2018-02-01  6:45 ` [PATCH v2 3/3] btrfs-progs: check: Cleanup all checkpatch error and warning Qu Wenruo
@ 2018-02-01  7:08   ` Su Yue
  2018-02-01  7:48     ` Qu Wenruo
  2018-02-01  8:36   ` Nikolay Borisov
  1 sibling, 1 reply; 11+ messages in thread
From: Su Yue @ 2018-02-01  7:08 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs, dsterba, Qu Wenruo



On 02/01/2018 02:45 PM, Qu Wenruo wrote:
> Since we're moving tons of codes, it's a good idea to fix all errors and
> warnings from checkpatch.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>   check/lowmem.c |  65 +++++++++------
>   check/main.c   | 253 +++++++++++++++++++++++++++++----------------------------
>   2 files changed, 165 insertions(+), 153 deletions(-)
> 
> diff --git a/check/lowmem.c b/check/lowmem.c
> index a3bda97fdea8..3e7fe148bc56 100644
> --- a/check/lowmem.c
> +++ b/check/lowmem.c
> @@ -322,7 +322,8 @@ static int repair_tree_block_ref(struct btrfs_trans_handle *trans,
>   			goto out;
>   
>   		eb = path.nodes[0];
> -		ei = btrfs_item_ptr(eb, path.slots[0], struct btrfs_extent_item);
> +		ei = btrfs_item_ptr(eb, path.slots[0],
> +				    struct btrfs_extent_item);
>   
>   		btrfs_set_extent_refs(eb, ei, 0);
>   		btrfs_set_extent_generation(eb, ei, generation);
> @@ -730,7 +731,9 @@ begin:
>   		need_research = 0;
>   		btrfs_release_path(path);
>   		ret = btrfs_search_slot(NULL, root, ref_key, path, 0, 0);
> -		/* the item was deleted, let path point to the last checked item */
> +		/*
> +		 * the item was deleted, let path point to the last checked item
> +		 */
>   		if (ret > 0) {
>   			if (path->slots[0] == 0)
>   				btrfs_prev_leaf(root, path);
> @@ -1486,7 +1489,8 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_key *fkey,
>   		search_start = disk_bytenr;
>   		search_len = disk_num_bytes;
>   	}
> -	ret = count_csum_range(root->fs_info, search_start, search_len, &csum_found);
> +	ret = count_csum_range(root->fs_info, search_start, search_len,
> +			       &csum_found);
>   	if (csum_found > 0 && nodatasum) {
>   		err |= ODD_CSUM_ITEM;
>   		error("root %llu EXTENT_DATA[%llu %llu] nodatasum shouldn't have datasum",
> @@ -1497,7 +1501,8 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_key *fkey,
>   		error("root %llu EXTENT_DATA[%llu %llu] csum missing, have: %llu, expected: %llu",
>   		      root->objectid, fkey->objectid, fkey->offset,
>   		      csum_found, search_len);
> -	} else if (extent_type == BTRFS_FILE_EXTENT_PREALLOC && csum_found > 0) {
> +	} else if (extent_type == BTRFS_FILE_EXTENT_PREALLOC &&
> +		   csum_found > 0) {
>   		err |= ODD_CSUM_ITEM;
>   		error("root %llu EXTENT_DATA[%llu %llu] prealloc shouldn't have csum, but has: %llu",
>   		      root->objectid, fkey->objectid, fkey->offset, csum_found);
> @@ -1561,7 +1566,8 @@ loop:
>   	}
>   
>   special_case:
> -	di = btrfs_item_ptr(path.nodes[0], path.slots[0], struct btrfs_dir_item);
> +	di = btrfs_item_ptr(path.nodes[0], path.slots[0],
> +			    struct btrfs_dir_item);
>   	cur = 0;
>   	total = btrfs_item_size_nr(path.nodes[0], path.slots[0]);
>   
> @@ -1913,7 +1919,8 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path,
>   	nodatasum = btrfs_inode_flags(node, ii) & BTRFS_INODE_NODATASUM;
>   
>   	while (1) {
> -		btrfs_item_key_to_cpu(path->nodes[0], &last_key, path->slots[0]);
> +		btrfs_item_key_to_cpu(path->nodes[0], &last_key,
> +				      path->slots[0]);
>   		ret = btrfs_next_item(root, path);
>   		if (ret < 0) {
>   			/* out will fill 'err' rusing current statistics */
> @@ -2360,7 +2367,7 @@ static int check_tree_block_ref(struct btrfs_root *root,
>   				 * Check if the backref points to valid
>   				 * referencer
>   				 */
> -				found_ref = !check_tree_block_ref( root, NULL,
> +				found_ref = !check_tree_block_ref(root, NULL,
>   						offset, level + 1, owner,
>   						NULL);
>   			}
> @@ -2500,7 +2507,8 @@ static int repair_extent_data_item(struct btrfs_trans_handle *trans,
>   		if (ret)
>   			goto out;
>   		eb = path.nodes[0];
> -		ei = btrfs_item_ptr(eb, path.slots[0], struct btrfs_extent_item);
> +		ei = btrfs_item_ptr(eb, path.slots[0],
> +				    struct btrfs_extent_item);
>   
>   		btrfs_set_extent_refs(eb, ei, 0);
>   		btrfs_set_extent_generation(eb, ei, generation);
> @@ -2657,7 +2665,8 @@ static int check_extent_data_item(struct btrfs_root *root,
>   		}
>   		if (type == BTRFS_EXTENT_DATA_REF_KEY) {
>   			ref_root = btrfs_extent_data_ref_root(leaf, dref);
> -			ref_objectid = btrfs_extent_data_ref_objectid(leaf, dref);
> +			ref_objectid = btrfs_extent_data_ref_objectid(leaf,
> +								      dref);
>   			ref_offset = btrfs_extent_data_ref_offset(leaf, dref);
>   
>   			if (ref_objectid == fi_key.objectid &&
> @@ -2820,8 +2829,8 @@ static int check_block_group_item(struct btrfs_fs_info *fs_info,
>   			if (!(bg_flags & BTRFS_BLOCK_GROUP_DATA)) {
>   				error(
>   			"bad extent[%llu, %llu) type mismatch with chunk",
> -					extent_key.objectid,
> -					extent_key.objectid + extent_key.offset);
> +				      extent_key.objectid,
> +				      extent_key.objectid + extent_key.offset);
>   				err |= CHUNK_TYPE_MISMATCH;
>   			}
>   		} else if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
> @@ -3175,7 +3184,8 @@ static int check_extent_data_backref(struct btrfs_fs_info *fs_info,
>   		    btrfs_header_owner(leaf) != root_id)
>   			goto next;
>   		btrfs_item_key_to_cpu(leaf, &key, slot);
> -		if (key.objectid != objectid || key.type != BTRFS_EXTENT_DATA_KEY)
> +		if (key.objectid != objectid || key.type !=
> +		    BTRFS_EXTENT_DATA_KEY)
if (key.objectid != objectid ||
     key.type != BTRFS_EXTENT_DATA_KEY)
is more better.
Other changes are nice.

Thanks,
Su
>   			break;
>   		fi = btrfs_item_ptr(leaf, slot, struct btrfs_file_extent_item);
>   		/*
> @@ -3205,7 +3215,8 @@ out:
>   	if (found_count != count) {
>   		error(
>   "extent[%llu, %llu] referencer count mismatch (root: %llu, owner: %llu, offset: %llu) wanted: %u, have: %u",
> -			bytenr, len, root_id, objectid, offset, count, found_count);
> +			bytenr, len, root_id, objectid, offset, count,
> +			found_count);
>   		return REFERENCER_MISSING;
>   	}
>   	return 0;
> @@ -3975,13 +3986,12 @@ static int walk_down_tree(struct btrfs_trans_handle *trans,
>   					       nrefs, account_file_data);
>   			err |= ret;
>   			break;
> -		} else {
> -			if (check || !check_all) {
> -				ret = btrfs_check_node(root, NULL, cur);
> -				if (ret != BTRFS_TREE_BLOCK_CLEAN) {
> -					err |= -EIO;
> -					break;
> -				}
> +		}
> +		if (check || !check_all) {
> +			ret = btrfs_check_node(root, NULL, cur);
> +			if (ret != BTRFS_TREE_BLOCK_CLEAN) {
> +				err |= -EIO;
> +				break;
>   			}
>   		}
>   
> @@ -4001,7 +4011,8 @@ static int walk_down_tree(struct btrfs_trans_handle *trans,
>   			continue;
>   		}
>   
> -		next = btrfs_find_tree_block(fs_info, bytenr, fs_info->nodesize);
> +		next = btrfs_find_tree_block(fs_info, bytenr,
> +					     fs_info->nodesize);
>   		if (!next || !btrfs_buffer_uptodate(next, ptr_gen)) {
>   			free_extent_buffer(next);
>   			reada_walk_down(root, cur, path->slots[*level]);
> @@ -4022,7 +4033,7 @@ static int walk_down_tree(struct btrfs_trans_handle *trans,
>   
>   		ret = check_child_node(cur, path->slots[*level], next);
>   		err |= ret;
> -		if (ret < 0)
> +		if (ret < 0)
>   			break;
>   
>   		if (btrfs_is_leaf(next))
> @@ -4041,7 +4052,8 @@ static int walk_down_tree(struct btrfs_trans_handle *trans,
>   		path->slots[*level] = 0;
>   		account_file_data = 0;
>   
> -		update_nodes_refs(root, (u64)-1, next, nrefs, *level, check_all);
> +		update_nodes_refs(root, (u64)-1, next, nrefs, *level,
> +				  check_all);
>   	}
>   	return err;
>   }
> @@ -4058,11 +4070,10 @@ static int walk_up_tree(struct btrfs_root *root, struct btrfs_path *path,
>   			path->slots[i]++;
>   			*level = i;
>   			return 0;
> -		} else {
> -			free_extent_buffer(path->nodes[*level]);
> -			path->nodes[*level] = NULL;
> -			*level = i + 1;
>   		}
> +		free_extent_buffer(path->nodes[*level]);
> +		path->nodes[*level] = NULL;
> +		*level = i + 1;
>   	}
>   	return 1;
>   }
> diff --git a/check/main.c b/check/main.c
> index aec3881fc043..f6874cd86543 100644
> --- a/check/main.c
> +++ b/check/main.c
> @@ -1720,14 +1720,13 @@ static int walk_up_tree(struct btrfs_root *root, struct btrfs_path *path,
>   			path->slots[i]++;
>   			*level = i;
>   			return 0;
> -		} else {
> -			free_extent_buffer(path->nodes[*level]);
> -			path->nodes[*level] = NULL;
> -			BUG_ON(*level > wc->active_node);
> -			if (*level == wc->active_node)
> -				leave_shared_node(root, wc, *level);
> -			*level = i + 1;
>   		}
> +		free_extent_buffer(path->nodes[*level]);
> +		path->nodes[*level] = NULL;
> +		BUG_ON(*level > wc->active_node);
> +		if (*level == wc->active_node)
> +			leave_shared_node(root, wc, *level);
> +		*level = i + 1;
>   	}
>   	return 1;
>   }
> @@ -3488,22 +3487,21 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
>   				goto out;
>   			if (back->is_data) {
>   				dback = to_data_backref(back);
> -				fprintf(stderr, "Data backref %llu %s %llu"
> -					" owner %llu offset %llu num_refs %lu"
> -					" not found in extent tree\n",
> +				fprintf(stderr,
> +"Data backref %llu %s %llu owner %llu offset %llu num_refs %lu not found in extent tree\n",
>   					(unsigned long long)rec->start,
>   					back->full_backref ?
>   					"parent" : "root",
>   					back->full_backref ?
> -					(unsigned long long)dback->parent:
> +					(unsigned long long)dback->parent :
>   					(unsigned long long)dback->root,
>   					(unsigned long long)dback->owner,
>   					(unsigned long long)dback->offset,
>   					(unsigned long)dback->num_refs);
>   			} else {
>   				tback = to_tree_backref(back);
> -				fprintf(stderr, "Tree backref %llu parent %llu"
> -					" root %llu not found in extent tree\n",
> +				fprintf(stderr,
> +"Tree backref %llu parent %llu root %llu not found in extent tree\n",
>   					(unsigned long long)rec->start,
>   					(unsigned long long)tback->parent,
>   					(unsigned long long)tback->root);
> @@ -3514,7 +3512,8 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
>   			if (!print_errs)
>   				goto out;
>   			tback = to_tree_backref(back);
> -			fprintf(stderr, "Backref %llu %s %llu not referenced back %p\n",
> +			fprintf(stderr,
> +				"Backref %llu %s %llu not referenced back %p\n",
>   				(unsigned long long)rec->start,
>   				back->full_backref ? "parent" : "root",
>   				back->full_backref ?
> @@ -3527,26 +3526,25 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
>   				err = 1;
>   				if (!print_errs)
>   					goto out;
> -				fprintf(stderr, "Incorrect local backref count"
> -					" on %llu %s %llu owner %llu"
> -					" offset %llu found %u wanted %u back %p\n",
> +				fprintf(stderr,
> +"Incorrect local backref count on %llu %s %llu owner %llu offset %llu found %u wanted %u back %p\n",
>   					(unsigned long long)rec->start,
>   					back->full_backref ?
>   					"parent" : "root",
>   					back->full_backref ?
> -					(unsigned long long)dback->parent:
> +					(unsigned long long)dback->parent :
>   					(unsigned long long)dback->root,
>   					(unsigned long long)dback->owner,
>   					(unsigned long long)dback->offset,
> -					dback->found_ref, dback->num_refs, back);
> +					dback->found_ref, dback->num_refs,
> +					back);
>   			}
>   			if (dback->disk_bytenr != rec->start) {
>   				err = 1;
>   				if (!print_errs)
>   					goto out;
> -				fprintf(stderr, "Backref disk bytenr does not"
> -					" match extent record, bytenr=%llu, "
> -					"ref bytenr=%llu\n",
> +				fprintf(stderr,
> +"Backref disk bytenr does not match extent record, bytenr=%llu, ref bytenr=%llu\n",
>   					(unsigned long long)rec->start,
>   					(unsigned long long)dback->disk_bytenr);
>   			}
> @@ -3555,9 +3553,8 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
>   				err = 1;
>   				if (!print_errs)
>   					goto out;
> -				fprintf(stderr, "Backref bytes do not match "
> -					"extent backref, bytenr=%llu, ref "
> -					"bytes=%llu, backref bytes=%llu\n",
> +				fprintf(stderr,
> +"Backref bytes do not match extent backref, bytenr=%llu, ref bytes=%llu, backref bytes=%llu\n",
>   					(unsigned long long)rec->start,
>   					(unsigned long long)rec->nr,
>   					(unsigned long long)dback->bytes);
> @@ -3574,8 +3571,8 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
>   		err = 1;
>   		if (!print_errs)
>   			goto out;
> -		fprintf(stderr, "Incorrect global backref count "
> -			"on %llu found %llu wanted %llu\n",
> +		fprintf(stderr,
> +"Incorrect global backref count on %llu found %llu wanted %llu\n",
>   			(unsigned long long)rec->start,
>   			(unsigned long long)found,
>   			(unsigned long long)rec->refs);
> @@ -3745,6 +3742,7 @@ static int swap_values(struct btrfs_root *root, struct btrfs_path *path,
>   				    sizeof(struct btrfs_key_ptr));
>   		if (slot == 0) {
>   			struct btrfs_disk_key key;
> +
>   			btrfs_node_key(buf, &key, 0);
>   			btrfs_fixup_low_keys(root, path, &key,
>   					     btrfs_header_level(buf) + 1);
> @@ -3877,8 +3875,8 @@ again:
>   				ret = delete_bogus_item(root, path, buf, i);
>   				if (!ret)
>   					goto again;
> -				fprintf(stderr, "item is off the end of the "
> -					"leaf, can't fix\n");
> +				fprintf(stderr,
> +				"item is off the end of the leaf, can't fix\n");
>   				ret = -EIO;
>   				break;
>   			}
> @@ -4066,7 +4064,7 @@ static struct tree_backref *find_tree_backref(struct extent_record *rec,
>   	struct extent_backref *node;
>   	struct tree_backref *back;
>   
> -	while(cur != &rec->backrefs) {
> +	while (cur != &rec->backrefs) {
>   		node = to_extent_backref(cur);
>   		cur = cur->next;
>   		if (node->is_data)
> @@ -4118,7 +4116,7 @@ static struct data_backref *find_data_backref(struct extent_record *rec,
>   	struct extent_backref *node;
>   	struct data_backref *back;
>   
> -	while(cur != &rec->backrefs) {
> +	while (cur != &rec->backrefs) {
>   		node = to_extent_backref(cur);
>   		cur = cur->next;
>   		if (!node->is_data)
> @@ -4344,12 +4342,13 @@ static int add_extent_rec(struct cache_tree *extent_cache,
>   
>   		if (tmpl->extent_item_refs && !dup) {
>   			if (rec->extent_item_refs) {
> -				fprintf(stderr, "block %llu rec "
> -					"extent_item_refs %llu, passed %llu\n",
> +				fprintf(stderr,
> +			"block %llu rec extent_item_refs %llu, passed %llu\n",
>   					(unsigned long long)tmpl->start,
>   					(unsigned long long)
>   							rec->extent_item_refs,
> -					(unsigned long long)tmpl->extent_item_refs);
> +					(unsigned long long)
> +							tmpl->extent_item_refs);
>   			}
>   			rec->extent_item_refs = tmpl->extent_item_refs;
>   		}
> @@ -4433,8 +4432,8 @@ static int add_tree_backref(struct cache_tree *extent_cache, u64 bytenr,
>   
>   	if (found_ref) {
>   		if (back->node.found_ref) {
> -			fprintf(stderr, "Extent back ref already exists "
> -				"for %llu parent %llu root %llu \n",
> +			fprintf(stderr,
> +	"Extent back ref already exists for %llu parent %llu root %llu\n",
>   				(unsigned long long)bytenr,
>   				(unsigned long long)parent,
>   				(unsigned long long)root);
> @@ -4442,8 +4441,8 @@ static int add_tree_backref(struct cache_tree *extent_cache, u64 bytenr,
>   		back->node.found_ref = 1;
>   	} else {
>   		if (back->node.found_extent_tree) {
> -			fprintf(stderr, "Extent back ref already exists "
> -				"for %llu parent %llu root %llu \n",
> +			fprintf(stderr,
> +	"Extent back ref already exists for %llu parent %llu root %llu\n",
>   				(unsigned long long)bytenr,
>   				(unsigned long long)parent,
>   				(unsigned long long)root);
> @@ -4530,9 +4529,8 @@ static int add_data_backref(struct cache_tree *extent_cache, u64 bytenr,
>   		rec->owner_ref_checked = 1;
>   	} else {
>   		if (back->node.found_extent_tree) {
> -			fprintf(stderr, "Extent back ref already exists "
> -				"for %llu parent %llu root %llu "
> -				"owner %llu offset %llu num_refs %lu\n",
> +			fprintf(stderr,
> +"Extent back ref already exists for %llu parent %llu root %llu owner %llu offset %llu num_refs %lu\n",
>   				(unsigned long long)bytenr,
>   				(unsigned long long)parent,
>   				(unsigned long long)root,
> @@ -4555,6 +4553,7 @@ static int add_pending(struct cache_tree *pending,
>   		       struct cache_tree *seen, u64 bytenr, u32 size)
>   {
>   	int ret;
> +
>   	ret = add_cache_extent(seen, bytenr, size);
>   	if (ret)
>   		return ret;
> @@ -4588,17 +4587,17 @@ static int pick_next_pending(struct cache_tree *pending,
>   		cache = search_cache_extent(nodes, 0);
>   
>   	if (!cache) {
> -		 cache = search_cache_extent(pending, 0);
> -		 if (!cache)
> -			 return 0;
> -		 ret = 0;
> -		 do {
> -			 bits[ret].start = cache->start;
> -			 bits[ret].size = cache->size;
> -			 cache = next_cache_extent(cache);
> -			 ret++;
> -		 } while (cache && ret < bits_nr);
> -		 return ret;
> +		cache = search_cache_extent(pending, 0);
> +		if (!cache)
> +			return 0;
> +		ret = 0;
> +		do {
> +			bits[ret].start = cache->start;
> +			bits[ret].size = cache->size;
> +			cache = next_cache_extent(cache);
> +			ret++;
> +		} while (cache && ret < bits_nr);
> +		return ret;
>   	}
>   
>   	ret = 0;
> @@ -4612,8 +4611,9 @@ static int pick_next_pending(struct cache_tree *pending,
>   	if (bits_nr - ret > 8) {
>   		u64 lookup = bits[0].start + bits[0].size;
>   		struct cache_extent *next;
> +
>   		next = search_cache_extent(pending, lookup);
> -		while(next) {
> +		while (next) {
>   			if (next->start - lookup > 32768)
>   				break;
>   			bits[ret].start = next->start;
> @@ -5004,6 +5004,7 @@ static int process_extent_item(struct btrfs_root *root,
>   	if (item_size < sizeof(*ei)) {
>   #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
>   		struct btrfs_extent_item_v0 *ei0;
> +
>   		if (item_size != sizeof(*ei0)) {
>   			error(
>   	"invalid extent item format: ITEM[%llu %u %llu] leaf: %llu slot: %d",
> @@ -5356,8 +5357,8 @@ static int check_space_cache(struct btrfs_root *root)
>   
>   static int check_extent_csums(struct btrfs_root *root, u64 bytenr,
>   			u64 num_bytes, unsigned long leaf_offset,
> -			struct extent_buffer *eb) {
> -
> +			struct extent_buffer *eb)
> +{
>   	struct btrfs_fs_info *fs_info = root->fs_info;
>   	u64 offset = 0;
>   	u16 csum_size = btrfs_super_csum_size(fs_info->super_copy);
> @@ -5646,7 +5647,8 @@ skip_csum_check:
>   }
>   
>   static int is_dropped_key(struct btrfs_key *key,
> -			  struct btrfs_key *drop_key) {
> +			  struct btrfs_key *drop_key)
> +{
>   	if (key->objectid < drop_key->objectid)
>   		return 1;
>   	else if (key->objectid == drop_key->objectid) {
> @@ -5823,7 +5825,7 @@ static int run_next_block(struct btrfs_root *root,
>   		return 1;
>   
>   	if (!reada_bits) {
> -		for(i = 0; i < nritems; i++) {
> +		for (i = 0; i < nritems; i++) {
>   			ret = add_cache_extent(reada, bits[i].start,
>   					       bits[i].size);
>   			if (ret == -EEXIST)
> @@ -5933,6 +5935,7 @@ static int run_next_block(struct btrfs_root *root,
>   		btree_space_waste += btrfs_leaf_free_space(root, buf);
>   		for (i = 0; i < nritems; i++) {
>   			struct btrfs_file_extent_item *fi;
> +
>   			btrfs_item_key_to_cpu(buf, &key, i);
>   			/*
>   			 * Check key type against the leaf owner.
> @@ -6007,6 +6010,7 @@ static int run_next_block(struct btrfs_root *root,
>   			}
>   			if (key.type == BTRFS_EXTENT_DATA_REF_KEY) {
>   				struct btrfs_extent_data_ref *ref;
> +
>   				ref = btrfs_item_ptr(buf, i,
>   						struct btrfs_extent_data_ref);
>   				add_data_backref(extent_cache,
> @@ -6021,6 +6025,7 @@ static int run_next_block(struct btrfs_root *root,
>   			}
>   			if (key.type == BTRFS_SHARED_DATA_REF_KEY) {
>   				struct btrfs_shared_data_ref *ref;
> +
>   				ref = btrfs_item_ptr(buf, i,
>   						struct btrfs_shared_data_ref);
>   				add_data_backref(extent_cache,
> @@ -6058,9 +6063,9 @@ static int run_next_block(struct btrfs_root *root,
>   
>   			data_bytes_allocated +=
>   				btrfs_file_extent_disk_num_bytes(buf, fi);
> -			if (data_bytes_allocated < root->fs_info->sectorsize) {
> +			if (data_bytes_allocated < root->fs_info->sectorsize)
>   				abort();
> -			}
> +
>   			data_bytes_referenced +=
>   				btrfs_file_extent_num_bytes(buf, fi);
>   			add_data_backref(extent_cache,
> @@ -6093,7 +6098,8 @@ static int run_next_block(struct btrfs_root *root,
>   
>   			memset(&tmpl, 0, sizeof(tmpl));
>   			btrfs_cpu_key_to_disk(&tmpl.parent_key, &key);
> -			tmpl.parent_generation = btrfs_node_ptr_generation(buf, i);
> +			tmpl.parent_generation =
> +				btrfs_node_ptr_generation(buf, i);
>   			tmpl.start = ptr;
>   			tmpl.nr = size;
>   			tmpl.refs = 1;
> @@ -6112,11 +6118,10 @@ static int run_next_block(struct btrfs_root *root,
>   				continue;
>   			}
>   
> -			if (level > 1) {
> +			if (level > 1)
>   				add_pending(nodes, seen, ptr, size);
> -			} else {
> +			else
>   				add_pending(pending, seen, ptr, size);
> -			}
>   		}
>   		btree_space_waste += (BTRFS_NODEPTRS_PER_BLOCK(fs_info) -
>   				      nritems) * sizeof(struct btrfs_key_ptr);
> @@ -6188,6 +6193,7 @@ static int free_extent_hook(struct btrfs_trans_handle *trans,
>   	rec = container_of(cache, struct extent_record, cache);
>   	if (is_data) {
>   		struct data_backref *back;
> +
>   		back = find_data_backref(rec, parent, root_objectid, owner,
>   					 offset, 1, bytenr, num_bytes);
>   		if (!back)
> @@ -6213,6 +6219,7 @@ static int free_extent_hook(struct btrfs_trans_handle *trans,
>   		}
>   	} else {
>   		struct tree_backref *back;
> +
>   		back = find_tree_backref(rec, parent, root_objectid);
>   		if (!back)
>   			goto out;
> @@ -6252,7 +6259,7 @@ static int delete_extent_records(struct btrfs_trans_handle *trans,
>   	key.type = (u8)-1;
>   	key.offset = (u64)-1;
>   
> -	while(1) {
> +	while (1) {
>   		ret = btrfs_search_slot(trans, root->fs_info->extent_root,
>   					&key, path, 0, 1);
>   		if (ret < 0)
> @@ -6365,7 +6372,7 @@ static int record_extent(struct btrfs_trans_handle *trans,
>   			btrfs_set_extent_flags(leaf, ei,
>   					       BTRFS_EXTENT_FLAG_DATA);
>   		} else {
> -			struct btrfs_disk_key copy_key;;
> +			struct btrfs_disk_key copy_key;
>   
>   			bi = (struct btrfs_tree_block_info *)(ei + 1);
>   			memset_extent_buffer(leaf, 0, (unsigned long)bi,
> @@ -6379,8 +6386,8 @@ static int record_extent(struct btrfs_trans_handle *trans,
>   			btrfs_set_tree_block_level(leaf, bi, rec->info_level);
>   			btrfs_set_tree_block_key(leaf, bi, &copy_key);
>   
> -			btrfs_set_extent_flags(leaf, ei,
> -					       BTRFS_EXTENT_FLAG_TREE_BLOCK | flags);
> +			btrfs_set_extent_flags(leaf, ei, flags |
> +					       BTRFS_EXTENT_FLAG_TREE_BLOCK);
>   		}
>   
>   		btrfs_mark_buffer_dirty(leaf);
> @@ -6418,18 +6425,14 @@ static int record_extent(struct btrfs_trans_handle *trans,
>   			if (ret)
>   				break;
>   		}
> -		fprintf(stderr, "adding new data backref"
> -				" on %llu %s %llu owner %llu"
> -				" offset %llu found %d\n",
> -				(unsigned long long)rec->start,
> -				back->full_backref ?
> -				"parent" : "root",
> -				back->full_backref ?
> -				(unsigned long long)parent :
> -				(unsigned long long)dback->root,
> -				(unsigned long long)dback->owner,
> -				(unsigned long long)dback->offset,
> -				dback->found_ref);
> +		fprintf(stderr,
> +"adding new data backref on %llu %s %llu owner %llu offset %llu found %d\n",
> +			(unsigned long long)rec->start,
> +			back->full_backref ? "parent" : "root",
> +			back->full_backref ? (unsigned long long)parent :
> +					     (unsigned long long)dback->root,
> +			(unsigned long long)dback->owner,
> +			(unsigned long long)dback->offset, dback->found_ref);
>   	} else {
>   		u64 parent;
>   		struct tree_backref *tback;
> @@ -6443,8 +6446,8 @@ static int record_extent(struct btrfs_trans_handle *trans,
>   		ret = btrfs_inc_extent_ref(trans, info->extent_root,
>   					   rec->start, rec->max_size,
>   					   parent, tback->root, 0, 0);
> -		fprintf(stderr, "adding new tree backref on "
> -			"start %llu len %llu parent %llu root %llu\n",
> +		fprintf(stderr,
> +"adding new tree backref on start %llu len %llu parent %llu root %llu\n",
>   			rec->start, rec->max_size, parent, tback->root);
>   	}
>   fail:
> @@ -6587,9 +6590,9 @@ static int repair_ref(struct btrfs_fs_info *info, struct btrfs_path *path,
>   		goto out;
>   	}
>   	if (ret > 0) {
> -		fprintf(stderr, "Well that's odd, we just found this key "
> -			"[%Lu, %u, %Lu]\n", key.objectid, key.type,
> -			key.offset);
> +		fprintf(stderr,
> +		"Well that's odd, we just found this key [%Lu, %u, %Lu]\n",
> +			key.objectid, key.type, key.offset);
>   		ret = -EINVAL;
>   		goto out;
>   	}
> @@ -6599,10 +6602,8 @@ static int repair_ref(struct btrfs_fs_info *info, struct btrfs_path *path,
>   
>   	if (btrfs_file_extent_compression(leaf, fi) &&
>   	    dback->disk_bytenr != entry->bytenr) {
> -		fprintf(stderr, "Ref doesn't match the record start and is "
> -			"compressed, please take a btrfs-image of this file "
> -			"system and send it to a btrfs developer so they can "
> -			"complete this functionality for bytenr %Lu\n",
> +		fprintf(stderr,
> +"Ref doesn't match the record start and is compressed, please take a btrfs-image of this file system and send it to a btrfs developer so they can complete this functionality for bytenr %Lu\n",
>   			dback->disk_bytenr);
>   		ret = -EINVAL;
>   		goto out;
> @@ -6618,9 +6619,8 @@ static int repair_ref(struct btrfs_fs_info *info, struct btrfs_path *path,
>   		if (dback->disk_bytenr + offset +
>   		    btrfs_file_extent_num_bytes(leaf, fi) >
>   		    entry->bytenr + entry->bytes) {
> -			fprintf(stderr, "Ref is past the entry end, please "
> -				"take a btrfs-image of this file system and "
> -				"send it to a btrfs developer, ref %Lu\n",
> +			fprintf(stderr,
> +"Ref is past the entry end, please take a btrfs-image of this file system and send it to a btrfs developer, ref %Lu\n",
>   				dback->disk_bytenr);
>   			ret = -EINVAL;
>   			goto out;
> @@ -6633,9 +6633,8 @@ static int repair_ref(struct btrfs_fs_info *info, struct btrfs_path *path,
>   
>   		offset = btrfs_file_extent_offset(leaf, fi);
>   		if (dback->disk_bytenr + offset < entry->bytenr) {
> -			fprintf(stderr, "Ref is before the entry start, please"
> -				" take a btrfs-image of this file system and "
> -				"send it to a btrfs developer, ref %Lu\n",
> +			fprintf(stderr,
> +"Ref is before the entry start, please take a btrfs-image of this file system and send it to a btrfs developer, ref %Lu\n",
>   				dback->disk_bytenr);
>   			ret = -EINVAL;
>   			goto out;
> @@ -6741,8 +6740,9 @@ static int verify_backrefs(struct btrfs_fs_info *info, struct btrfs_path *path,
>   	if (nr_entries <= 1 && !mismatch)
>   		goto out;
>   
> -	fprintf(stderr, "attempting to repair backref discrepency for bytenr "
> -		"%Lu\n", rec->start);
> +	fprintf(stderr,
> +		"attempting to repair backref discrepency for bytenr %Lu\n",
> +		rec->start);
>   
>   	/*
>   	 * First we want to see if the backrefs can agree amongst themselves who
> @@ -6758,9 +6758,8 @@ static int verify_backrefs(struct btrfs_fs_info *info, struct btrfs_path *path,
>   	if (!best) {
>   		entry = find_entry(&entries, rec->start, rec->nr);
>   		if (!entry && (!broken_entries || !rec->found_rec)) {
> -			fprintf(stderr, "Backrefs don't agree with each other "
> -				"and extent record doesn't agree with anybody,"
> -				" so we can't fix bytenr %Lu bytes %Lu\n",
> +			fprintf(stderr,
> +"Backrefs don't agree with each other and extent record doesn't agree with anybody, so we can't fix bytenr %Lu bytes %Lu\n",
>   				rec->start, rec->nr);
>   			ret = -EINVAL;
>   			goto out;
> @@ -6783,10 +6782,9 @@ static int verify_backrefs(struct btrfs_fs_info *info, struct btrfs_path *path,
>   		entry->count++;
>   		best = find_most_right_entry(&entries);
>   		if (!best) {
> -			fprintf(stderr, "Backrefs and extent record evenly "
> -				"split on who is right, this is going to "
> -				"require user input to fix bytenr %Lu bytes "
> -				"%Lu\n", rec->start, rec->nr);
> +			fprintf(stderr,
> +"Backrefs and extent record evenly split on who is right, this is going to require user input to fix bytenr %Lu bytes %Lu\n",
> +				rec->start, rec->nr);
>   			ret = -EINVAL;
>   			goto out;
>   		}
> @@ -6798,10 +6796,8 @@ static int verify_backrefs(struct btrfs_fs_info *info, struct btrfs_path *path,
>   	 * deal with it properly here yet, so just bail out of that's the case.
>   	 */
>   	if (best->bytenr != rec->start) {
> -		fprintf(stderr, "Extent start and backref starts don't match, "
> -			"please use btrfs-image on this file system and send "
> -			"it to a btrfs developer so they can make fsck fix "
> -			"this particular case.  bytenr is %Lu, bytes is %Lu\n",
> +		fprintf(stderr,
> +"Extent start and backref starts don't match, please use btrfs-image on this file system and send it to a btrfs developer so they can make fsck fix this particular case.  bytenr is %Lu, bytes is %Lu\n",
>   			rec->start, rec->nr);
>   		ret = -EINVAL;
>   		goto out;
> @@ -6951,10 +6947,8 @@ static int delete_duplicate_records(struct btrfs_root *root,
>   			continue;
>   
>   		if (tmp->start + tmp->nr < good->start + good->nr) {
> -			fprintf(stderr, "Ok we have overlapping extents that "
> -				"aren't completely covered by each other, this "
> -				"is going to require more careful thought.  "
> -				"The extents are [%Lu-%Lu] and [%Lu-%Lu]\n",
> +			fprintf(stderr,
> +"Ok we have overlapping extents that aren't completely covered by each other, this is going to require more careful thought. The extents are [%Lu-%Lu] and [%Lu-%Lu]\n",
>   				tmp->start, tmp->nr, good->start, good->nr);
>   			abort();
>   		}
> @@ -6986,9 +6980,9 @@ static int delete_duplicate_records(struct btrfs_root *root,
>   
>   		/* Shouldn't happen but just in case */
>   		if (tmp->metadata) {
> -			fprintf(stderr, "Well this shouldn't happen, extent "
> -				"record overlaps but is metadata? "
> -				"[%Lu, %Lu]\n", tmp->start, tmp->nr);
> +			fprintf(stderr,
> +"Well this shouldn't happen, extent record overlaps but is metadata? [%Lu, %Lu]\n",
> +				tmp->start, tmp->nr);
>   			abort();
>   		}
>   
> @@ -7090,6 +7084,7 @@ static int find_possible_backrefs(struct btrfs_fs_info *info,
>   		cache = lookup_cache_extent(extent_cache, bytenr, 1);
>   		if (cache) {
>   			struct extent_record *tmp;
> +
>   			tmp = container_of(cache, struct extent_record, cache);
>   
>   			/*
> @@ -7271,7 +7266,8 @@ static int fixup_extent_refs(struct btrfs_fs_info *info,
>   			continue;
>   
>   		rec->bad_full_backref = 0;
> -		ret = record_extent(trans, info, &path, rec, back, allocated, flags);
> +		ret = record_extent(trans, info, &path, rec, back, allocated,
> +				    flags);
>   		allocated = 1;
>   
>   		if (ret)
> @@ -7280,6 +7276,7 @@ static int fixup_extent_refs(struct btrfs_fs_info *info,
>   out:
>   	if (trans) {
>   		int err = btrfs_commit_transaction(trans, info->extent_root);
> +
>   		if (!ret)
>   			ret = err;
>   	}
> @@ -7401,8 +7398,8 @@ again:
>   			goto del_ptr;
>   	}
>   	/*
> -	 * we couldn't find the bad block.  TODO, search all the nodes for pointers
> -	 * to this block
> +	 * we couldn't find the bad block.
> +	 * TODO: search all the nodes for pointers to this block
>   	 */
>   	if (eb == info->extent_root->node) {
>   		ret = -ENOENT;
> @@ -7437,7 +7434,8 @@ static int prune_corrupt_blocks(struct btrfs_fs_info *info)
>   			if (IS_ERR(trans))
>   				return PTR_ERR(trans);
>   		}
> -		corrupt = container_of(cache, struct btrfs_corrupt_block, cache);
> +		corrupt = container_of(cache, struct btrfs_corrupt_block,
> +				       cache);
>   		prune_one_block(trans, info, corrupt);
>   		remove_cache_extent(info->corrupt_blocks, cache);
>   	}
> @@ -7463,7 +7461,7 @@ static int check_extent_refs(struct btrfs_root *root,
>   		 * extents in the FS
>   		 */
>   		cache = search_cache_extent(extent_cache, 0);
> -		while(cache) {
> +		while (cache) {
>   			rec = container_of(cache, struct extent_record, cache);
>   			set_extent_dirty(root->fs_info->excluded_extents,
>   					 rec->start,
> @@ -7473,7 +7471,7 @@ static int check_extent_refs(struct btrfs_root *root,
>   
>   		/* pin down all the corrupted blocks too */
>   		cache = search_cache_extent(root->fs_info->corrupt_blocks, 0);
> -		while(cache) {
> +		while (cache) {
>   			set_extent_dirty(root->fs_info->excluded_extents,
>   					 cache->start,
>   					 cache->start + cache->size - 1);
> @@ -7518,7 +7516,7 @@ static int check_extent_refs(struct btrfs_root *root,
>   	if (had_dups)
>   		return -EAGAIN;
>   
> -	while(1) {
> +	while (1) {
>   		int cur_err = 0;
>   		int fix = 0;
>   
> @@ -7527,8 +7525,9 @@ static int check_extent_refs(struct btrfs_root *root,
>   			break;
>   		rec = container_of(cache, struct extent_record, cache);
>   		if (rec->num_duplicates) {
> -			fprintf(stderr, "extent item %llu has multiple extent "
> -				"items\n", (unsigned long long)rec->start);
> +			fprintf(stderr,
> +				"extent item %llu has multiple extent items\n",
> +				(unsigned long long)rec->start);
>   			cur_err = 1;
>   		}
>   
> @@ -7561,7 +7560,8 @@ static int check_extent_refs(struct btrfs_root *root,
>   		}
>   
>   		if (repair && fix) {
> -			ret = fixup_extent_refs(root->fs_info, extent_cache, rec);
> +			ret = fixup_extent_refs(root->fs_info, extent_cache,
> +						rec);
>   			if (ret)
>   				goto repair_abort;
>   		}
> @@ -7943,8 +7943,8 @@ static int add_root_item_to_list(struct list_head *head,
>   				  u8 level, u8 drop_level,
>   				  struct btrfs_key *drop_key)
>   {
> -
>   	struct root_item_record *ri_rec;
> +
>   	ri_rec = malloc(sizeof(*ri_rec));
>   	if (!ri_rec)
>   		return -ENOMEM;
> @@ -7992,6 +7992,7 @@ static int deal_root_from_list(struct list_head *list,
>   	while (!list_empty(list)) {
>   		struct root_item_record *rec;
>   		struct extent_buffer *buf;
> +
>   		rec = list_entry(list->next,
>   				 struct root_item_record, list);
>   		last = 0;
> @@ -8123,7 +8124,7 @@ again:
>   	ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, &path, 0, 0);
>   	if (ret < 0)
>   		goto out;
> -	while(1) {
> +	while (1) {
>   		leaf = path.nodes[0];
>   		slot = path.slots[0];
>   		if (slot >= btrfs_header_nritems(path.nodes[0])) {
> 



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

* Re: [PATCH v2 3/3] btrfs-progs: check: Cleanup all checkpatch error and warning
  2018-02-01  7:08   ` Su Yue
@ 2018-02-01  7:48     ` Qu Wenruo
  2018-02-01  8:28       ` Nikolay Borisov
  0 siblings, 1 reply; 11+ messages in thread
From: Qu Wenruo @ 2018-02-01  7:48 UTC (permalink / raw)
  To: Su Yue, Qu Wenruo, linux-btrfs, dsterba


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



On 2018年02月01日 15:08, Su Yue wrote:
> 
> 
> On 02/01/2018 02:45 PM, Qu Wenruo wrote:
>> Since we're moving tons of codes, it's a good idea to fix all errors and
[snip]
>>               }
>> @@ -2500,7 +2507,8 @@ static int repair_extent_data_item(struct
>> btrfs_trans_handle *trans,
>>           if (ret)
>>               goto out;
>>           eb = path.nodes[0];
>> -        ei = btrfs_item_ptr(eb, path.slots[0], struct
>> btrfs_extent_item);
>> +        ei = btrfs_item_ptr(eb, path.slots[0],
>> +                    struct btrfs_extent_item);
>>             btrfs_set_extent_refs(eb, ei, 0);
>>           btrfs_set_extent_generation(eb, ei, generation);
>> @@ -2657,7 +2665,8 @@ static int check_extent_data_item(struct
>> btrfs_root *root,
>>           }
>>           if (type == BTRFS_EXTENT_DATA_REF_KEY) {
>>               ref_root = btrfs_extent_data_ref_root(leaf, dref);
>> -            ref_objectid = btrfs_extent_data_ref_objectid(leaf, dref);
>> +            ref_objectid = btrfs_extent_data_ref_objectid(leaf,
>> +                                      dref);
>>               ref_offset = btrfs_extent_data_ref_offset(leaf, dref);
>>                 if (ref_objectid == fi_key.objectid &&
>> @@ -2820,8 +2829,8 @@ static int check_block_group_item(struct
>> btrfs_fs_info *fs_info,
>>               if (!(bg_flags & BTRFS_BLOCK_GROUP_DATA)) {
>>                   error(
>>               "bad extent[%llu, %llu) type mismatch with chunk",
>> -                    extent_key.objectid,
>> -                    extent_key.objectid + extent_key.offset);
>> +                      extent_key.objectid,
>> +                      extent_key.objectid + extent_key.offset);
>>                   err |= CHUNK_TYPE_MISMATCH;
>>               }
>>           } else if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
>> @@ -3175,7 +3184,8 @@ static int check_extent_data_backref(struct
>> btrfs_fs_info *fs_info,
>>               btrfs_header_owner(leaf) != root_id)
>>               goto next;
>>           btrfs_item_key_to_cpu(leaf, &key, slot);
>> -        if (key.objectid != objectid || key.type !=
>> BTRFS_EXTENT_DATA_KEY)
>> +        if (key.objectid != objectid || key.type !=
>> +            BTRFS_EXTENT_DATA_KEY)
> if (key.objectid != objectid ||
>     key.type != BTRFS_EXTENT_DATA_KEY)
> is more better.
> Other changes are nice.

I also thought about that, but that leaves too much space in previous line.

Not sure what should be the best practice here.

Thank,
Qu
> 
> Thanks,
> Su


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

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

* Re: [PATCH v2 3/3] btrfs-progs: check: Cleanup all checkpatch error and warning
  2018-02-01  7:48     ` Qu Wenruo
@ 2018-02-01  8:28       ` Nikolay Borisov
  2018-02-01 15:06         ` David Sterba
  0 siblings, 1 reply; 11+ messages in thread
From: Nikolay Borisov @ 2018-02-01  8:28 UTC (permalink / raw)
  To: Qu Wenruo, Su Yue, Qu Wenruo, linux-btrfs, dsterba



On  1.02.2018 09:48, Qu Wenruo wrote:
> 
> 
> On 2018年02月01日 15:08, Su Yue wrote:
>>
>>
>> On 02/01/2018 02:45 PM, Qu Wenruo wrote:
>>> Since we're moving tons of codes, it's a good idea to fix all errors and
> [snip]
>>>               }
>>> @@ -2500,7 +2507,8 @@ static int repair_extent_data_item(struct
>>> btrfs_trans_handle *trans,
>>>           if (ret)
>>>               goto out;
>>>           eb = path.nodes[0];
>>> -        ei = btrfs_item_ptr(eb, path.slots[0], struct
>>> btrfs_extent_item);
>>> +        ei = btrfs_item_ptr(eb, path.slots[0],
>>> +                    struct btrfs_extent_item);
>>>             btrfs_set_extent_refs(eb, ei, 0);
>>>           btrfs_set_extent_generation(eb, ei, generation);
>>> @@ -2657,7 +2665,8 @@ static int check_extent_data_item(struct
>>> btrfs_root *root,
>>>           }
>>>           if (type == BTRFS_EXTENT_DATA_REF_KEY) {
>>>               ref_root = btrfs_extent_data_ref_root(leaf, dref);
>>> -            ref_objectid = btrfs_extent_data_ref_objectid(leaf, dref);
>>> +            ref_objectid = btrfs_extent_data_ref_objectid(leaf,
>>> +                                      dref);
>>>               ref_offset = btrfs_extent_data_ref_offset(leaf, dref);
>>>                 if (ref_objectid == fi_key.objectid &&
>>> @@ -2820,8 +2829,8 @@ static int check_block_group_item(struct
>>> btrfs_fs_info *fs_info,
>>>               if (!(bg_flags & BTRFS_BLOCK_GROUP_DATA)) {
>>>                   error(
>>>               "bad extent[%llu, %llu) type mismatch with chunk",
>>> -                    extent_key.objectid,
>>> -                    extent_key.objectid + extent_key.offset);
>>> +                      extent_key.objectid,
>>> +                      extent_key.objectid + extent_key.offset);
>>>                   err |= CHUNK_TYPE_MISMATCH;
>>>               }
>>>           } else if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
>>> @@ -3175,7 +3184,8 @@ static int check_extent_data_backref(struct
>>> btrfs_fs_info *fs_info,
>>>               btrfs_header_owner(leaf) != root_id)
>>>               goto next;
>>>           btrfs_item_key_to_cpu(leaf, &key, slot);
>>> -        if (key.objectid != objectid || key.type !=
>>> BTRFS_EXTENT_DATA_KEY)
>>> +        if (key.objectid != objectid || key.type !=
>>> +            BTRFS_EXTENT_DATA_KEY)
>> if (key.objectid != objectid ||
>>     key.type != BTRFS_EXTENT_DATA_KEY)
>> is more better.
>> Other changes are nice.
> 
> I also thought about that, but that leaves too much space in previous line.
> 
> Not sure what should be the best practice here.

Su's suggestion is more readable so I'd say go with it

> 
> Thank,
> Qu
>>
>> Thanks,
>> Su
> 

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

* Re: [PATCH v2 3/3] btrfs-progs: check: Cleanup all checkpatch error and warning
  2018-02-01  6:45 ` [PATCH v2 3/3] btrfs-progs: check: Cleanup all checkpatch error and warning Qu Wenruo
  2018-02-01  7:08   ` Su Yue
@ 2018-02-01  8:36   ` Nikolay Borisov
  2018-02-01  9:20     ` Qu Wenruo
  1 sibling, 1 reply; 11+ messages in thread
From: Nikolay Borisov @ 2018-02-01  8:36 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs, dsterba



On  1.02.2018 08:45, Qu Wenruo wrote:
> Since we're moving tons of codes, it's a good idea to fix all errors and
> warnings from checkpatch.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Having this patch separate for review is fine, but in the end I think it
will be best if it's squashed in the commit that moves stuff around so
we don't introduce needless noise.

> ---
>  check/lowmem.c |  65 +++++++++------
>  check/main.c   | 253 +++++++++++++++++++++++++++++----------------------------
>  2 files changed, 165 insertions(+), 153 deletions(-)
> 
> diff --git a/check/lowmem.c b/check/lowmem.c
> index a3bda97fdea8..3e7fe148bc56 100644
> --- a/check/lowmem.c
> +++ b/check/lowmem.c
> @@ -322,7 +322,8 @@ static int repair_tree_block_ref(struct btrfs_trans_handle *trans,
>  			goto out;
>  
>  		eb = path.nodes[0];
> -		ei = btrfs_item_ptr(eb, path.slots[0], struct btrfs_extent_item);
> +		ei = btrfs_item_ptr(eb, path.slots[0],
> +				    struct btrfs_extent_item);
>  
>  		btrfs_set_extent_refs(eb, ei, 0);
>  		btrfs_set_extent_generation(eb, ei, generation);
> @@ -730,7 +731,9 @@ begin:
>  		need_research = 0;
>  		btrfs_release_path(path);
>  		ret = btrfs_search_slot(NULL, root, ref_key, path, 0, 0);
> -		/* the item was deleted, let path point to the last checked item */
> +		/*
> +		 * the item was deleted, let path point to the last checked item
> +		 */
>  		if (ret > 0) {
>  			if (path->slots[0] == 0)
>  				btrfs_prev_leaf(root, path);
> @@ -1486,7 +1489,8 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_key *fkey,
>  		search_start = disk_bytenr;
>  		search_len = disk_num_bytes;
>  	}
> -	ret = count_csum_range(root->fs_info, search_start, search_len, &csum_found);
> +	ret = count_csum_range(root->fs_info, search_start, search_len,
> +			       &csum_found);
>  	if (csum_found > 0 && nodatasum) {
>  		err |= ODD_CSUM_ITEM;
>  		error("root %llu EXTENT_DATA[%llu %llu] nodatasum shouldn't have datasum",
> @@ -1497,7 +1501,8 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_key *fkey,
>  		error("root %llu EXTENT_DATA[%llu %llu] csum missing, have: %llu, expected: %llu",
>  		      root->objectid, fkey->objectid, fkey->offset,
>  		      csum_found, search_len);
> -	} else if (extent_type == BTRFS_FILE_EXTENT_PREALLOC && csum_found > 0) {
> +	} else if (extent_type == BTRFS_FILE_EXTENT_PREALLOC &&
> +		   csum_found > 0) {
>  		err |= ODD_CSUM_ITEM;
>  		error("root %llu EXTENT_DATA[%llu %llu] prealloc shouldn't have csum, but has: %llu",
>  		      root->objectid, fkey->objectid, fkey->offset, csum_found);
> @@ -1561,7 +1566,8 @@ loop:
>  	}
>  
>  special_case:
> -	di = btrfs_item_ptr(path.nodes[0], path.slots[0], struct btrfs_dir_item);
> +	di = btrfs_item_ptr(path.nodes[0], path.slots[0],
> +			    struct btrfs_dir_item);
>  	cur = 0;
>  	total = btrfs_item_size_nr(path.nodes[0], path.slots[0]);
>  
> @@ -1913,7 +1919,8 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path,
>  	nodatasum = btrfs_inode_flags(node, ii) & BTRFS_INODE_NODATASUM;
>  
>  	while (1) {
> -		btrfs_item_key_to_cpu(path->nodes[0], &last_key, path->slots[0]);
> +		btrfs_item_key_to_cpu(path->nodes[0], &last_key,
> +				      path->slots[0]);
>  		ret = btrfs_next_item(root, path);
>  		if (ret < 0) {
>  			/* out will fill 'err' rusing current statistics */
> @@ -2360,7 +2367,7 @@ static int check_tree_block_ref(struct btrfs_root *root,
>  				 * Check if the backref points to valid
>  				 * referencer
>  				 */
> -				found_ref = !check_tree_block_ref( root, NULL,
> +				found_ref = !check_tree_block_ref(root, NULL,
>  						offset, level + 1, owner,
>  						NULL);
>  			}
> @@ -2500,7 +2507,8 @@ static int repair_extent_data_item(struct btrfs_trans_handle *trans,
>  		if (ret)
>  			goto out;
>  		eb = path.nodes[0];
> -		ei = btrfs_item_ptr(eb, path.slots[0], struct btrfs_extent_item);
> +		ei = btrfs_item_ptr(eb, path.slots[0],
> +				    struct btrfs_extent_item);
>  
>  		btrfs_set_extent_refs(eb, ei, 0);
>  		btrfs_set_extent_generation(eb, ei, generation);
> @@ -2657,7 +2665,8 @@ static int check_extent_data_item(struct btrfs_root *root,
>  		}
>  		if (type == BTRFS_EXTENT_DATA_REF_KEY) {
>  			ref_root = btrfs_extent_data_ref_root(leaf, dref);
> -			ref_objectid = btrfs_extent_data_ref_objectid(leaf, dref);
> +			ref_objectid = btrfs_extent_data_ref_objectid(leaf,
> +								      dref);
>  			ref_offset = btrfs_extent_data_ref_offset(leaf, dref);
>  
>  			if (ref_objectid == fi_key.objectid &&
> @@ -2820,8 +2829,8 @@ static int check_block_group_item(struct btrfs_fs_info *fs_info,
>  			if (!(bg_flags & BTRFS_BLOCK_GROUP_DATA)) {
>  				error(
>  			"bad extent[%llu, %llu) type mismatch with chunk",
> -					extent_key.objectid,
> -					extent_key.objectid + extent_key.offset);
> +				      extent_key.objectid,
> +				      extent_key.objectid + extent_key.offset);
>  				err |= CHUNK_TYPE_MISMATCH;
>  			}
>  		} else if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
> @@ -3175,7 +3184,8 @@ static int check_extent_data_backref(struct btrfs_fs_info *fs_info,
>  		    btrfs_header_owner(leaf) != root_id)
>  			goto next;
>  		btrfs_item_key_to_cpu(leaf, &key, slot);
> -		if (key.objectid != objectid || key.type != BTRFS_EXTENT_DATA_KEY)
> +		if (key.objectid != objectid || key.type !=
> +		    BTRFS_EXTENT_DATA_KEY)
>  			break;
>  		fi = btrfs_item_ptr(leaf, slot, struct btrfs_file_extent_item);
>  		/*
> @@ -3205,7 +3215,8 @@ out:
>  	if (found_count != count) {
>  		error(
>  "extent[%llu, %llu] referencer count mismatch (root: %llu, owner: %llu, offset: %llu) wanted: %u, have: %u",
> -			bytenr, len, root_id, objectid, offset, count, found_count);
> +			bytenr, len, root_id, objectid, offset, count,
> +			found_count);
>  		return REFERENCER_MISSING;
>  	}
>  	return 0;
> @@ -3975,13 +3986,12 @@ static int walk_down_tree(struct btrfs_trans_handle *trans,
>  					       nrefs, account_file_data);
>  			err |= ret;
>  			break;
> -		} else {
> -			if (check || !check_all) {
> -				ret = btrfs_check_node(root, NULL, cur);
> -				if (ret != BTRFS_TREE_BLOCK_CLEAN) {
> -					err |= -EIO;
> -					break;
> -				}
> +		}
> +		if (check || !check_all) {
> +			ret = btrfs_check_node(root, NULL, cur);
> +			if (ret != BTRFS_TREE_BLOCK_CLEAN) {
> +				err |= -EIO;
> +				break;
>  			}
>  		}
>  
> @@ -4001,7 +4011,8 @@ static int walk_down_tree(struct btrfs_trans_handle *trans,
>  			continue;
>  		}
>  
> -		next = btrfs_find_tree_block(fs_info, bytenr, fs_info->nodesize);
> +		next = btrfs_find_tree_block(fs_info, bytenr,
> +					     fs_info->nodesize);
>  		if (!next || !btrfs_buffer_uptodate(next, ptr_gen)) {
>  			free_extent_buffer(next);
>  			reada_walk_down(root, cur, path->slots[*level]);
> @@ -4022,7 +4033,7 @@ static int walk_down_tree(struct btrfs_trans_handle *trans,
>  
>  		ret = check_child_node(cur, path->slots[*level], next);
>  		err |= ret;
> -		if (ret < 0) 
> +		if (ret < 0)
>  			break;
>  
>  		if (btrfs_is_leaf(next))
> @@ -4041,7 +4052,8 @@ static int walk_down_tree(struct btrfs_trans_handle *trans,
>  		path->slots[*level] = 0;
>  		account_file_data = 0;
>  
> -		update_nodes_refs(root, (u64)-1, next, nrefs, *level, check_all);
> +		update_nodes_refs(root, (u64)-1, next, nrefs, *level,
> +				  check_all);
>  	}
>  	return err;
>  }
> @@ -4058,11 +4070,10 @@ static int walk_up_tree(struct btrfs_root *root, struct btrfs_path *path,
>  			path->slots[i]++;
>  			*level = i;
>  			return 0;
> -		} else {
> -			free_extent_buffer(path->nodes[*level]);
> -			path->nodes[*level] = NULL;
> -			*level = i + 1;
>  		}
> +		free_extent_buffer(path->nodes[*level]);
> +		path->nodes[*level] = NULL;
> +		*level = i + 1;
>  	}
>  	return 1;
>  }
> diff --git a/check/main.c b/check/main.c
> index aec3881fc043..f6874cd86543 100644
> --- a/check/main.c
> +++ b/check/main.c
> @@ -1720,14 +1720,13 @@ static int walk_up_tree(struct btrfs_root *root, struct btrfs_path *path,
>  			path->slots[i]++;
>  			*level = i;
>  			return 0;
> -		} else {
> -			free_extent_buffer(path->nodes[*level]);
> -			path->nodes[*level] = NULL;
> -			BUG_ON(*level > wc->active_node);
> -			if (*level == wc->active_node)
> -				leave_shared_node(root, wc, *level);
> -			*level = i + 1;
>  		}
> +		free_extent_buffer(path->nodes[*level]);
> +		path->nodes[*level] = NULL;
> +		BUG_ON(*level > wc->active_node);
> +		if (*level == wc->active_node)
> +			leave_shared_node(root, wc, *level);
> +		*level = i + 1;
>  	}
>  	return 1;
>  }
> @@ -3488,22 +3487,21 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
>  				goto out;
>  			if (back->is_data) {
>  				dback = to_data_backref(back);
> -				fprintf(stderr, "Data backref %llu %s %llu"
> -					" owner %llu offset %llu num_refs %lu"
> -					" not found in extent tree\n",
> +				fprintf(stderr,
> +"Data backref %llu %s %llu owner %llu offset %llu num_refs %lu not found in extent tree\n",
>  					(unsigned long long)rec->start,
>  					back->full_backref ?
>  					"parent" : "root",
>  					back->full_backref ?
> -					(unsigned long long)dback->parent:
> +					(unsigned long long)dback->parent :
>  					(unsigned long long)dback->root,
>  					(unsigned long long)dback->owner,
>  					(unsigned long long)dback->offset,
>  					(unsigned long)dback->num_refs);
>  			} else {
>  				tback = to_tree_backref(back);
> -				fprintf(stderr, "Tree backref %llu parent %llu"
> -					" root %llu not found in extent tree\n",
> +				fprintf(stderr,
> +"Tree backref %llu parent %llu root %llu not found in extent tree\n",
>  					(unsigned long long)rec->start,
>  					(unsigned long long)tback->parent,
>  					(unsigned long long)tback->root);
> @@ -3514,7 +3512,8 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
>  			if (!print_errs)
>  				goto out;
>  			tback = to_tree_backref(back);
> -			fprintf(stderr, "Backref %llu %s %llu not referenced back %p\n",
> +			fprintf(stderr,
> +				"Backref %llu %s %llu not referenced back %p\n",
>  				(unsigned long long)rec->start,
>  				back->full_backref ? "parent" : "root",
>  				back->full_backref ?
> @@ -3527,26 +3526,25 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
>  				err = 1;
>  				if (!print_errs)
>  					goto out;
> -				fprintf(stderr, "Incorrect local backref count"
> -					" on %llu %s %llu owner %llu"
> -					" offset %llu found %u wanted %u back %p\n",
> +				fprintf(stderr,
> +"Incorrect local backref count on %llu %s %llu owner %llu offset %llu found %u wanted %u back %p\n",
>  					(unsigned long long)rec->start,
>  					back->full_backref ?
>  					"parent" : "root",
>  					back->full_backref ?
> -					(unsigned long long)dback->parent:
> +					(unsigned long long)dback->parent :
>  					(unsigned long long)dback->root,
>  					(unsigned long long)dback->owner,
>  					(unsigned long long)dback->offset,
> -					dback->found_ref, dback->num_refs, back);
> +					dback->found_ref, dback->num_refs,
> +					back);
>  			}
>  			if (dback->disk_bytenr != rec->start) {
>  				err = 1;
>  				if (!print_errs)
>  					goto out;
> -				fprintf(stderr, "Backref disk bytenr does not"
> -					" match extent record, bytenr=%llu, "
> -					"ref bytenr=%llu\n",
> +				fprintf(stderr,
> +"Backref disk bytenr does not match extent record, bytenr=%llu, ref bytenr=%llu\n",
>  					(unsigned long long)rec->start,
>  					(unsigned long long)dback->disk_bytenr);
>  			}
> @@ -3555,9 +3553,8 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
>  				err = 1;
>  				if (!print_errs)
>  					goto out;
> -				fprintf(stderr, "Backref bytes do not match "
> -					"extent backref, bytenr=%llu, ref "
> -					"bytes=%llu, backref bytes=%llu\n",
> +				fprintf(stderr,
> +"Backref bytes do not match extent backref, bytenr=%llu, ref bytes=%llu, backref bytes=%llu\n",
>  					(unsigned long long)rec->start,
>  					(unsigned long long)rec->nr,
>  					(unsigned long long)dback->bytes);
> @@ -3574,8 +3571,8 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
>  		err = 1;
>  		if (!print_errs)
>  			goto out;
> -		fprintf(stderr, "Incorrect global backref count "
> -			"on %llu found %llu wanted %llu\n",
> +		fprintf(stderr,
> +"Incorrect global backref count on %llu found %llu wanted %llu\n",
>  			(unsigned long long)rec->start,
>  			(unsigned long long)found,
>  			(unsigned long long)rec->refs);
> @@ -3745,6 +3742,7 @@ static int swap_values(struct btrfs_root *root, struct btrfs_path *path,
>  				    sizeof(struct btrfs_key_ptr));
>  		if (slot == 0) {
>  			struct btrfs_disk_key key;
> +
>  			btrfs_node_key(buf, &key, 0);
>  			btrfs_fixup_low_keys(root, path, &key,
>  					     btrfs_header_level(buf) + 1);
> @@ -3877,8 +3875,8 @@ again:
>  				ret = delete_bogus_item(root, path, buf, i);
>  				if (!ret)
>  					goto again;
> -				fprintf(stderr, "item is off the end of the "
> -					"leaf, can't fix\n");
> +				fprintf(stderr,
> +				"item is off the end of the leaf, can't fix\n");
>  				ret = -EIO;
>  				break;
>  			}
> @@ -4066,7 +4064,7 @@ static struct tree_backref *find_tree_backref(struct extent_record *rec,
>  	struct extent_backref *node;
>  	struct tree_backref *back;
>  
> -	while(cur != &rec->backrefs) {
> +	while (cur != &rec->backrefs) {
>  		node = to_extent_backref(cur);
>  		cur = cur->next;
>  		if (node->is_data)
> @@ -4118,7 +4116,7 @@ static struct data_backref *find_data_backref(struct extent_record *rec,
>  	struct extent_backref *node;
>  	struct data_backref *back;
>  
> -	while(cur != &rec->backrefs) {
> +	while (cur != &rec->backrefs) {
>  		node = to_extent_backref(cur);
>  		cur = cur->next;
>  		if (!node->is_data)
> @@ -4344,12 +4342,13 @@ static int add_extent_rec(struct cache_tree *extent_cache,
>  
>  		if (tmpl->extent_item_refs && !dup) {
>  			if (rec->extent_item_refs) {
> -				fprintf(stderr, "block %llu rec "
> -					"extent_item_refs %llu, passed %llu\n",
> +				fprintf(stderr,
> +			"block %llu rec extent_item_refs %llu, passed %llu\n",
>  					(unsigned long long)tmpl->start,
>  					(unsigned long long)
>  							rec->extent_item_refs,
> -					(unsigned long long)tmpl->extent_item_refs);
> +					(unsigned long long)
> +							tmpl->extent_item_refs);
>  			}
>  			rec->extent_item_refs = tmpl->extent_item_refs;
>  		}
> @@ -4433,8 +4432,8 @@ static int add_tree_backref(struct cache_tree *extent_cache, u64 bytenr,
>  
>  	if (found_ref) {
>  		if (back->node.found_ref) {
> -			fprintf(stderr, "Extent back ref already exists "
> -				"for %llu parent %llu root %llu \n",
> +			fprintf(stderr,
> +	"Extent back ref already exists for %llu parent %llu root %llu\n",
>  				(unsigned long long)bytenr,
>  				(unsigned long long)parent,
>  				(unsigned long long)root);
> @@ -4442,8 +4441,8 @@ static int add_tree_backref(struct cache_tree *extent_cache, u64 bytenr,
>  		back->node.found_ref = 1;
>  	} else {
>  		if (back->node.found_extent_tree) {
> -			fprintf(stderr, "Extent back ref already exists "
> -				"for %llu parent %llu root %llu \n",
> +			fprintf(stderr,
> +	"Extent back ref already exists for %llu parent %llu root %llu\n",
>  				(unsigned long long)bytenr,
>  				(unsigned long long)parent,
>  				(unsigned long long)root);
> @@ -4530,9 +4529,8 @@ static int add_data_backref(struct cache_tree *extent_cache, u64 bytenr,
>  		rec->owner_ref_checked = 1;
>  	} else {
>  		if (back->node.found_extent_tree) {
> -			fprintf(stderr, "Extent back ref already exists "
> -				"for %llu parent %llu root %llu "
> -				"owner %llu offset %llu num_refs %lu\n",
> +			fprintf(stderr,
> +"Extent back ref already exists for %llu parent %llu root %llu owner %llu offset %llu num_refs %lu\n",
>  				(unsigned long long)bytenr,
>  				(unsigned long long)parent,
>  				(unsigned long long)root,
> @@ -4555,6 +4553,7 @@ static int add_pending(struct cache_tree *pending,
>  		       struct cache_tree *seen, u64 bytenr, u32 size)
>  {
>  	int ret;
> +
>  	ret = add_cache_extent(seen, bytenr, size);
>  	if (ret)
>  		return ret;
> @@ -4588,17 +4587,17 @@ static int pick_next_pending(struct cache_tree *pending,
>  		cache = search_cache_extent(nodes, 0);
>  
>  	if (!cache) {
> -		 cache = search_cache_extent(pending, 0);
> -		 if (!cache)
> -			 return 0;
> -		 ret = 0;
> -		 do {
> -			 bits[ret].start = cache->start;
> -			 bits[ret].size = cache->size;
> -			 cache = next_cache_extent(cache);
> -			 ret++;
> -		 } while (cache && ret < bits_nr);
> -		 return ret;
> +		cache = search_cache_extent(pending, 0);
> +		if (!cache)
> +			return 0;
> +		ret = 0;
> +		do {
> +			bits[ret].start = cache->start;
> +			bits[ret].size = cache->size;
> +			cache = next_cache_extent(cache);
> +			ret++;
> +		} while (cache && ret < bits_nr);
> +		return ret;
>  	}
>  
>  	ret = 0;
> @@ -4612,8 +4611,9 @@ static int pick_next_pending(struct cache_tree *pending,
>  	if (bits_nr - ret > 8) {
>  		u64 lookup = bits[0].start + bits[0].size;
>  		struct cache_extent *next;
> +
>  		next = search_cache_extent(pending, lookup);
> -		while(next) {
> +		while (next) {
>  			if (next->start - lookup > 32768)
>  				break;
>  			bits[ret].start = next->start;
> @@ -5004,6 +5004,7 @@ static int process_extent_item(struct btrfs_root *root,
>  	if (item_size < sizeof(*ei)) {
>  #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
>  		struct btrfs_extent_item_v0 *ei0;
> +
>  		if (item_size != sizeof(*ei0)) {
>  			error(
>  	"invalid extent item format: ITEM[%llu %u %llu] leaf: %llu slot: %d",
> @@ -5356,8 +5357,8 @@ static int check_space_cache(struct btrfs_root *root)
>  
>  static int check_extent_csums(struct btrfs_root *root, u64 bytenr,
>  			u64 num_bytes, unsigned long leaf_offset,
> -			struct extent_buffer *eb) {
> -
> +			struct extent_buffer *eb)
> +{
>  	struct btrfs_fs_info *fs_info = root->fs_info;
>  	u64 offset = 0;
>  	u16 csum_size = btrfs_super_csum_size(fs_info->super_copy);
> @@ -5646,7 +5647,8 @@ skip_csum_check:
>  }
>  
>  static int is_dropped_key(struct btrfs_key *key,
> -			  struct btrfs_key *drop_key) {
> +			  struct btrfs_key *drop_key)
> +{
>  	if (key->objectid < drop_key->objectid)
>  		return 1;
>  	else if (key->objectid == drop_key->objectid) {
> @@ -5823,7 +5825,7 @@ static int run_next_block(struct btrfs_root *root,
>  		return 1;
>  
>  	if (!reada_bits) {
> -		for(i = 0; i < nritems; i++) {
> +		for (i = 0; i < nritems; i++) {
>  			ret = add_cache_extent(reada, bits[i].start,
>  					       bits[i].size);
>  			if (ret == -EEXIST)
> @@ -5933,6 +5935,7 @@ static int run_next_block(struct btrfs_root *root,
>  		btree_space_waste += btrfs_leaf_free_space(root, buf);
>  		for (i = 0; i < nritems; i++) {
>  			struct btrfs_file_extent_item *fi;
> +
>  			btrfs_item_key_to_cpu(buf, &key, i);
>  			/*
>  			 * Check key type against the leaf owner.
> @@ -6007,6 +6010,7 @@ static int run_next_block(struct btrfs_root *root,
>  			}
>  			if (key.type == BTRFS_EXTENT_DATA_REF_KEY) {
>  				struct btrfs_extent_data_ref *ref;
> +
>  				ref = btrfs_item_ptr(buf, i,
>  						struct btrfs_extent_data_ref);
>  				add_data_backref(extent_cache,
> @@ -6021,6 +6025,7 @@ static int run_next_block(struct btrfs_root *root,
>  			}
>  			if (key.type == BTRFS_SHARED_DATA_REF_KEY) {
>  				struct btrfs_shared_data_ref *ref;
> +
>  				ref = btrfs_item_ptr(buf, i,
>  						struct btrfs_shared_data_ref);
>  				add_data_backref(extent_cache,
> @@ -6058,9 +6063,9 @@ static int run_next_block(struct btrfs_root *root,
>  
>  			data_bytes_allocated +=
>  				btrfs_file_extent_disk_num_bytes(buf, fi);
> -			if (data_bytes_allocated < root->fs_info->sectorsize) {
> +			if (data_bytes_allocated < root->fs_info->sectorsize)
>  				abort();
> -			}
> +
>  			data_bytes_referenced +=
>  				btrfs_file_extent_num_bytes(buf, fi);
>  			add_data_backref(extent_cache,
> @@ -6093,7 +6098,8 @@ static int run_next_block(struct btrfs_root *root,
>  
>  			memset(&tmpl, 0, sizeof(tmpl));
>  			btrfs_cpu_key_to_disk(&tmpl.parent_key, &key);
> -			tmpl.parent_generation = btrfs_node_ptr_generation(buf, i);
> +			tmpl.parent_generation =
> +				btrfs_node_ptr_generation(buf, i);
>  			tmpl.start = ptr;
>  			tmpl.nr = size;
>  			tmpl.refs = 1;
> @@ -6112,11 +6118,10 @@ static int run_next_block(struct btrfs_root *root,
>  				continue;
>  			}
>  
> -			if (level > 1) {
> +			if (level > 1)
>  				add_pending(nodes, seen, ptr, size);
> -			} else {
> +			else
>  				add_pending(pending, seen, ptr, size);
> -			}
>  		}
>  		btree_space_waste += (BTRFS_NODEPTRS_PER_BLOCK(fs_info) -
>  				      nritems) * sizeof(struct btrfs_key_ptr);
> @@ -6188,6 +6193,7 @@ static int free_extent_hook(struct btrfs_trans_handle *trans,
>  	rec = container_of(cache, struct extent_record, cache);
>  	if (is_data) {
>  		struct data_backref *back;
> +
>  		back = find_data_backref(rec, parent, root_objectid, owner,
>  					 offset, 1, bytenr, num_bytes);
>  		if (!back)
> @@ -6213,6 +6219,7 @@ static int free_extent_hook(struct btrfs_trans_handle *trans,
>  		}
>  	} else {
>  		struct tree_backref *back;
> +
>  		back = find_tree_backref(rec, parent, root_objectid);
>  		if (!back)
>  			goto out;
> @@ -6252,7 +6259,7 @@ static int delete_extent_records(struct btrfs_trans_handle *trans,
>  	key.type = (u8)-1;
>  	key.offset = (u64)-1;
>  
> -	while(1) {
> +	while (1) {
>  		ret = btrfs_search_slot(trans, root->fs_info->extent_root,
>  					&key, path, 0, 1);
>  		if (ret < 0)
> @@ -6365,7 +6372,7 @@ static int record_extent(struct btrfs_trans_handle *trans,
>  			btrfs_set_extent_flags(leaf, ei,
>  					       BTRFS_EXTENT_FLAG_DATA);
>  		} else {
> -			struct btrfs_disk_key copy_key;;
> +			struct btrfs_disk_key copy_key;
>  
>  			bi = (struct btrfs_tree_block_info *)(ei + 1);
>  			memset_extent_buffer(leaf, 0, (unsigned long)bi,
> @@ -6379,8 +6386,8 @@ static int record_extent(struct btrfs_trans_handle *trans,
>  			btrfs_set_tree_block_level(leaf, bi, rec->info_level);
>  			btrfs_set_tree_block_key(leaf, bi, &copy_key);
>  
> -			btrfs_set_extent_flags(leaf, ei,
> -					       BTRFS_EXTENT_FLAG_TREE_BLOCK | flags);
> +			btrfs_set_extent_flags(leaf, ei, flags |
> +					       BTRFS_EXTENT_FLAG_TREE_BLOCK);
>  		}
>  
>  		btrfs_mark_buffer_dirty(leaf);
> @@ -6418,18 +6425,14 @@ static int record_extent(struct btrfs_trans_handle *trans,
>  			if (ret)
>  				break;
>  		}
> -		fprintf(stderr, "adding new data backref"
> -				" on %llu %s %llu owner %llu"
> -				" offset %llu found %d\n",
> -				(unsigned long long)rec->start,
> -				back->full_backref ?
> -				"parent" : "root",
> -				back->full_backref ?
> -				(unsigned long long)parent :
> -				(unsigned long long)dback->root,
> -				(unsigned long long)dback->owner,
> -				(unsigned long long)dback->offset,
> -				dback->found_ref);
> +		fprintf(stderr,
> +"adding new data backref on %llu %s %llu owner %llu offset %llu found %d\n",
> +			(unsigned long long)rec->start,
> +			back->full_backref ? "parent" : "root",
> +			back->full_backref ? (unsigned long long)parent :
> +					     (unsigned long long)dback->root,
> +			(unsigned long long)dback->owner,
> +			(unsigned long long)dback->offset, dback->found_ref);
>  	} else {
>  		u64 parent;
>  		struct tree_backref *tback;
> @@ -6443,8 +6446,8 @@ static int record_extent(struct btrfs_trans_handle *trans,
>  		ret = btrfs_inc_extent_ref(trans, info->extent_root,
>  					   rec->start, rec->max_size,
>  					   parent, tback->root, 0, 0);
> -		fprintf(stderr, "adding new tree backref on "
> -			"start %llu len %llu parent %llu root %llu\n",
> +		fprintf(stderr,
> +"adding new tree backref on start %llu len %llu parent %llu root %llu\n",
>  			rec->start, rec->max_size, parent, tback->root);
>  	}
>  fail:
> @@ -6587,9 +6590,9 @@ static int repair_ref(struct btrfs_fs_info *info, struct btrfs_path *path,
>  		goto out;
>  	}
>  	if (ret > 0) {
> -		fprintf(stderr, "Well that's odd, we just found this key "
> -			"[%Lu, %u, %Lu]\n", key.objectid, key.type,
> -			key.offset);
> +		fprintf(stderr,
> +		"Well that's odd, we just found this key [%Lu, %u, %Lu]\n",
> +			key.objectid, key.type, key.offset);
>  		ret = -EINVAL;
>  		goto out;
>  	}
> @@ -6599,10 +6602,8 @@ static int repair_ref(struct btrfs_fs_info *info, struct btrfs_path *path,
>  
>  	if (btrfs_file_extent_compression(leaf, fi) &&
>  	    dback->disk_bytenr != entry->bytenr) {
> -		fprintf(stderr, "Ref doesn't match the record start and is "
> -			"compressed, please take a btrfs-image of this file "
> -			"system and send it to a btrfs developer so they can "
> -			"complete this functionality for bytenr %Lu\n",
> +		fprintf(stderr,
> +"Ref doesn't match the record start and is compressed, please take a btrfs-image of this file system and send it to a btrfs developer so they can complete this functionality for bytenr %Lu\n",
>  			dback->disk_bytenr);
>  		ret = -EINVAL;
>  		goto out;
> @@ -6618,9 +6619,8 @@ static int repair_ref(struct btrfs_fs_info *info, struct btrfs_path *path,
>  		if (dback->disk_bytenr + offset +
>  		    btrfs_file_extent_num_bytes(leaf, fi) >
>  		    entry->bytenr + entry->bytes) {
> -			fprintf(stderr, "Ref is past the entry end, please "
> -				"take a btrfs-image of this file system and "
> -				"send it to a btrfs developer, ref %Lu\n",
> +			fprintf(stderr,
> +"Ref is past the entry end, please take a btrfs-image of this file system and send it to a btrfs developer, ref %Lu\n",
>  				dback->disk_bytenr);
>  			ret = -EINVAL;
>  			goto out;
> @@ -6633,9 +6633,8 @@ static int repair_ref(struct btrfs_fs_info *info, struct btrfs_path *path,
>  
>  		offset = btrfs_file_extent_offset(leaf, fi);
>  		if (dback->disk_bytenr + offset < entry->bytenr) {
> -			fprintf(stderr, "Ref is before the entry start, please"
> -				" take a btrfs-image of this file system and "
> -				"send it to a btrfs developer, ref %Lu\n",
> +			fprintf(stderr,
> +"Ref is before the entry start, please take a btrfs-image of this file system and send it to a btrfs developer, ref %Lu\n",
>  				dback->disk_bytenr);
>  			ret = -EINVAL;
>  			goto out;
> @@ -6741,8 +6740,9 @@ static int verify_backrefs(struct btrfs_fs_info *info, struct btrfs_path *path,
>  	if (nr_entries <= 1 && !mismatch)
>  		goto out;
>  
> -	fprintf(stderr, "attempting to repair backref discrepency for bytenr "
> -		"%Lu\n", rec->start);
> +	fprintf(stderr,
> +		"attempting to repair backref discrepency for bytenr %Lu\n",
> +		rec->start);
>  
>  	/*
>  	 * First we want to see if the backrefs can agree amongst themselves who
> @@ -6758,9 +6758,8 @@ static int verify_backrefs(struct btrfs_fs_info *info, struct btrfs_path *path,
>  	if (!best) {
>  		entry = find_entry(&entries, rec->start, rec->nr);
>  		if (!entry && (!broken_entries || !rec->found_rec)) {
> -			fprintf(stderr, "Backrefs don't agree with each other "
> -				"and extent record doesn't agree with anybody,"
> -				" so we can't fix bytenr %Lu bytes %Lu\n",
> +			fprintf(stderr,
> +"Backrefs don't agree with each other and extent record doesn't agree with anybody, so we can't fix bytenr %Lu bytes %Lu\n",
>  				rec->start, rec->nr);
>  			ret = -EINVAL;
>  			goto out;
> @@ -6783,10 +6782,9 @@ static int verify_backrefs(struct btrfs_fs_info *info, struct btrfs_path *path,
>  		entry->count++;
>  		best = find_most_right_entry(&entries);
>  		if (!best) {
> -			fprintf(stderr, "Backrefs and extent record evenly "
> -				"split on who is right, this is going to "
> -				"require user input to fix bytenr %Lu bytes "
> -				"%Lu\n", rec->start, rec->nr);
> +			fprintf(stderr,
> +"Backrefs and extent record evenly split on who is right, this is going to require user input to fix bytenr %Lu bytes %Lu\n",
> +				rec->start, rec->nr);
>  			ret = -EINVAL;
>  			goto out;
>  		}
> @@ -6798,10 +6796,8 @@ static int verify_backrefs(struct btrfs_fs_info *info, struct btrfs_path *path,
>  	 * deal with it properly here yet, so just bail out of that's the case.
>  	 */
>  	if (best->bytenr != rec->start) {
> -		fprintf(stderr, "Extent start and backref starts don't match, "
> -			"please use btrfs-image on this file system and send "
> -			"it to a btrfs developer so they can make fsck fix "
> -			"this particular case.  bytenr is %Lu, bytes is %Lu\n",
> +		fprintf(stderr,
> +"Extent start and backref starts don't match, please use btrfs-image on this file system and send it to a btrfs developer so they can make fsck fix this particular case.  bytenr is %Lu, bytes is %Lu\n",
>  			rec->start, rec->nr);
>  		ret = -EINVAL;
>  		goto out;
> @@ -6951,10 +6947,8 @@ static int delete_duplicate_records(struct btrfs_root *root,
>  			continue;
>  
>  		if (tmp->start + tmp->nr < good->start + good->nr) {
> -			fprintf(stderr, "Ok we have overlapping extents that "
> -				"aren't completely covered by each other, this "
> -				"is going to require more careful thought.  "
> -				"The extents are [%Lu-%Lu] and [%Lu-%Lu]\n",
> +			fprintf(stderr,
> +"Ok we have overlapping extents that aren't completely covered by each other, this is going to require more careful thought. The extents are [%Lu-%Lu] and [%Lu-%Lu]\n",
>  				tmp->start, tmp->nr, good->start, good->nr);
>  			abort();
>  		}
> @@ -6986,9 +6980,9 @@ static int delete_duplicate_records(struct btrfs_root *root,
>  
>  		/* Shouldn't happen but just in case */
>  		if (tmp->metadata) {
> -			fprintf(stderr, "Well this shouldn't happen, extent "
> -				"record overlaps but is metadata? "
> -				"[%Lu, %Lu]\n", tmp->start, tmp->nr);
> +			fprintf(stderr,
> +"Well this shouldn't happen, extent record overlaps but is metadata? [%Lu, %Lu]\n",
> +				tmp->start, tmp->nr);
>  			abort();
>  		}
>  
> @@ -7090,6 +7084,7 @@ static int find_possible_backrefs(struct btrfs_fs_info *info,
>  		cache = lookup_cache_extent(extent_cache, bytenr, 1);
>  		if (cache) {
>  			struct extent_record *tmp;
> +
>  			tmp = container_of(cache, struct extent_record, cache);
>  
>  			/*
> @@ -7271,7 +7266,8 @@ static int fixup_extent_refs(struct btrfs_fs_info *info,
>  			continue;
>  
>  		rec->bad_full_backref = 0;
> -		ret = record_extent(trans, info, &path, rec, back, allocated, flags);
> +		ret = record_extent(trans, info, &path, rec, back, allocated,
> +				    flags);
>  		allocated = 1;
>  
>  		if (ret)
> @@ -7280,6 +7276,7 @@ static int fixup_extent_refs(struct btrfs_fs_info *info,
>  out:
>  	if (trans) {
>  		int err = btrfs_commit_transaction(trans, info->extent_root);
> +
>  		if (!ret)
>  			ret = err;
>  	}
> @@ -7401,8 +7398,8 @@ again:
>  			goto del_ptr;
>  	}
>  	/*
> -	 * we couldn't find the bad block.  TODO, search all the nodes for pointers
> -	 * to this block
> +	 * we couldn't find the bad block.
> +	 * TODO: search all the nodes for pointers to this block
>  	 */
>  	if (eb == info->extent_root->node) {
>  		ret = -ENOENT;
> @@ -7437,7 +7434,8 @@ static int prune_corrupt_blocks(struct btrfs_fs_info *info)
>  			if (IS_ERR(trans))
>  				return PTR_ERR(trans);
>  		}
> -		corrupt = container_of(cache, struct btrfs_corrupt_block, cache);
> +		corrupt = container_of(cache, struct btrfs_corrupt_block,
> +				       cache);
>  		prune_one_block(trans, info, corrupt);
>  		remove_cache_extent(info->corrupt_blocks, cache);
>  	}
> @@ -7463,7 +7461,7 @@ static int check_extent_refs(struct btrfs_root *root,
>  		 * extents in the FS
>  		 */
>  		cache = search_cache_extent(extent_cache, 0);
> -		while(cache) {
> +		while (cache) {
>  			rec = container_of(cache, struct extent_record, cache);
>  			set_extent_dirty(root->fs_info->excluded_extents,
>  					 rec->start,
> @@ -7473,7 +7471,7 @@ static int check_extent_refs(struct btrfs_root *root,
>  
>  		/* pin down all the corrupted blocks too */
>  		cache = search_cache_extent(root->fs_info->corrupt_blocks, 0);
> -		while(cache) {
> +		while (cache) {
>  			set_extent_dirty(root->fs_info->excluded_extents,
>  					 cache->start,
>  					 cache->start + cache->size - 1);
> @@ -7518,7 +7516,7 @@ static int check_extent_refs(struct btrfs_root *root,
>  	if (had_dups)
>  		return -EAGAIN;
>  
> -	while(1) {
> +	while (1) {
>  		int cur_err = 0;
>  		int fix = 0;
>  
> @@ -7527,8 +7525,9 @@ static int check_extent_refs(struct btrfs_root *root,
>  			break;
>  		rec = container_of(cache, struct extent_record, cache);
>  		if (rec->num_duplicates) {
> -			fprintf(stderr, "extent item %llu has multiple extent "
> -				"items\n", (unsigned long long)rec->start);
> +			fprintf(stderr,
> +				"extent item %llu has multiple extent items\n",
> +				(unsigned long long)rec->start);
>  			cur_err = 1;
>  		}
>  
> @@ -7561,7 +7560,8 @@ static int check_extent_refs(struct btrfs_root *root,
>  		}
>  
>  		if (repair && fix) {
> -			ret = fixup_extent_refs(root->fs_info, extent_cache, rec);
> +			ret = fixup_extent_refs(root->fs_info, extent_cache,
> +						rec);
>  			if (ret)
>  				goto repair_abort;
>  		}
> @@ -7943,8 +7943,8 @@ static int add_root_item_to_list(struct list_head *head,
>  				  u8 level, u8 drop_level,
>  				  struct btrfs_key *drop_key)
>  {
> -
>  	struct root_item_record *ri_rec;
> +
>  	ri_rec = malloc(sizeof(*ri_rec));
>  	if (!ri_rec)
>  		return -ENOMEM;
> @@ -7992,6 +7992,7 @@ static int deal_root_from_list(struct list_head *list,
>  	while (!list_empty(list)) {
>  		struct root_item_record *rec;
>  		struct extent_buffer *buf;
> +
>  		rec = list_entry(list->next,
>  				 struct root_item_record, list);
>  		last = 0;
> @@ -8123,7 +8124,7 @@ again:
>  	ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, &path, 0, 0);
>  	if (ret < 0)
>  		goto out;
> -	while(1) {
> +	while (1) {
>  		leaf = path.nodes[0];
>  		slot = path.slots[0];
>  		if (slot >= btrfs_header_nritems(path.nodes[0])) {
> 

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

* Re: [PATCH v2 3/3] btrfs-progs: check: Cleanup all checkpatch error and warning
  2018-02-01  8:36   ` Nikolay Borisov
@ 2018-02-01  9:20     ` Qu Wenruo
  0 siblings, 0 replies; 11+ messages in thread
From: Qu Wenruo @ 2018-02-01  9:20 UTC (permalink / raw)
  To: Nikolay Borisov, Qu Wenruo, linux-btrfs, dsterba


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



On 2018年02月01日 16:36, Nikolay Borisov wrote:
> 
> 
> On  1.02.2018 08:45, Qu Wenruo wrote:
>> Since we're moving tons of codes, it's a good idea to fix all errors and
>> warnings from checkpatch.
>>
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
> 
> Having this patch separate for review is fine, but in the end I think it
> will be best if it's squashed in the commit that moves stuff around so
> we don't introduce needless noise.

Yes, that's the normal case.

However what makes it special here is the first patch, which are moving
tons of codes around (+4000 -4000).

Squashing them into 1st is completely fine, but I'm pretty paranoid here
and will try my best to avoid any unnecessary modification to avoid
regression.

So the fixup is in this separate patch.
(Not to mention a lot of them are from the old original mode, nothing to
do with lowmem separation)

Thanks,
Qu
> 
>> ---
>>  check/lowmem.c |  65 +++++++++------
>>  check/main.c   | 253 +++++++++++++++++++++++++++++----------------------------
>>  2 files changed, 165 insertions(+), 153 deletions(-)
>>
>> diff --git a/check/lowmem.c b/check/lowmem.c
>> index a3bda97fdea8..3e7fe148bc56 100644
>> --- a/check/lowmem.c
>> +++ b/check/lowmem.c
>> @@ -322,7 +322,8 @@ static int repair_tree_block_ref(struct btrfs_trans_handle *trans,
>>  			goto out;
>>  
>>  		eb = path.nodes[0];
>> -		ei = btrfs_item_ptr(eb, path.slots[0], struct btrfs_extent_item);
>> +		ei = btrfs_item_ptr(eb, path.slots[0],
>> +				    struct btrfs_extent_item);
>>  
>>  		btrfs_set_extent_refs(eb, ei, 0);
>>  		btrfs_set_extent_generation(eb, ei, generation);
>> @@ -730,7 +731,9 @@ begin:
>>  		need_research = 0;
>>  		btrfs_release_path(path);
>>  		ret = btrfs_search_slot(NULL, root, ref_key, path, 0, 0);
>> -		/* the item was deleted, let path point to the last checked item */
>> +		/*
>> +		 * the item was deleted, let path point to the last checked item
>> +		 */
>>  		if (ret > 0) {
>>  			if (path->slots[0] == 0)
>>  				btrfs_prev_leaf(root, path);
>> @@ -1486,7 +1489,8 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_key *fkey,
>>  		search_start = disk_bytenr;
>>  		search_len = disk_num_bytes;
>>  	}
>> -	ret = count_csum_range(root->fs_info, search_start, search_len, &csum_found);
>> +	ret = count_csum_range(root->fs_info, search_start, search_len,
>> +			       &csum_found);
>>  	if (csum_found > 0 && nodatasum) {
>>  		err |= ODD_CSUM_ITEM;
>>  		error("root %llu EXTENT_DATA[%llu %llu] nodatasum shouldn't have datasum",
>> @@ -1497,7 +1501,8 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_key *fkey,
>>  		error("root %llu EXTENT_DATA[%llu %llu] csum missing, have: %llu, expected: %llu",
>>  		      root->objectid, fkey->objectid, fkey->offset,
>>  		      csum_found, search_len);
>> -	} else if (extent_type == BTRFS_FILE_EXTENT_PREALLOC && csum_found > 0) {
>> +	} else if (extent_type == BTRFS_FILE_EXTENT_PREALLOC &&
>> +		   csum_found > 0) {
>>  		err |= ODD_CSUM_ITEM;
>>  		error("root %llu EXTENT_DATA[%llu %llu] prealloc shouldn't have csum, but has: %llu",
>>  		      root->objectid, fkey->objectid, fkey->offset, csum_found);
>> @@ -1561,7 +1566,8 @@ loop:
>>  	}
>>  
>>  special_case:
>> -	di = btrfs_item_ptr(path.nodes[0], path.slots[0], struct btrfs_dir_item);
>> +	di = btrfs_item_ptr(path.nodes[0], path.slots[0],
>> +			    struct btrfs_dir_item);
>>  	cur = 0;
>>  	total = btrfs_item_size_nr(path.nodes[0], path.slots[0]);
>>  
>> @@ -1913,7 +1919,8 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path,
>>  	nodatasum = btrfs_inode_flags(node, ii) & BTRFS_INODE_NODATASUM;
>>  
>>  	while (1) {
>> -		btrfs_item_key_to_cpu(path->nodes[0], &last_key, path->slots[0]);
>> +		btrfs_item_key_to_cpu(path->nodes[0], &last_key,
>> +				      path->slots[0]);
>>  		ret = btrfs_next_item(root, path);
>>  		if (ret < 0) {
>>  			/* out will fill 'err' rusing current statistics */
>> @@ -2360,7 +2367,7 @@ static int check_tree_block_ref(struct btrfs_root *root,
>>  				 * Check if the backref points to valid
>>  				 * referencer
>>  				 */
>> -				found_ref = !check_tree_block_ref( root, NULL,
>> +				found_ref = !check_tree_block_ref(root, NULL,
>>  						offset, level + 1, owner,
>>  						NULL);
>>  			}
>> @@ -2500,7 +2507,8 @@ static int repair_extent_data_item(struct btrfs_trans_handle *trans,
>>  		if (ret)
>>  			goto out;
>>  		eb = path.nodes[0];
>> -		ei = btrfs_item_ptr(eb, path.slots[0], struct btrfs_extent_item);
>> +		ei = btrfs_item_ptr(eb, path.slots[0],
>> +				    struct btrfs_extent_item);
>>  
>>  		btrfs_set_extent_refs(eb, ei, 0);
>>  		btrfs_set_extent_generation(eb, ei, generation);
>> @@ -2657,7 +2665,8 @@ static int check_extent_data_item(struct btrfs_root *root,
>>  		}
>>  		if (type == BTRFS_EXTENT_DATA_REF_KEY) {
>>  			ref_root = btrfs_extent_data_ref_root(leaf, dref);
>> -			ref_objectid = btrfs_extent_data_ref_objectid(leaf, dref);
>> +			ref_objectid = btrfs_extent_data_ref_objectid(leaf,
>> +								      dref);
>>  			ref_offset = btrfs_extent_data_ref_offset(leaf, dref);
>>  
>>  			if (ref_objectid == fi_key.objectid &&
>> @@ -2820,8 +2829,8 @@ static int check_block_group_item(struct btrfs_fs_info *fs_info,
>>  			if (!(bg_flags & BTRFS_BLOCK_GROUP_DATA)) {
>>  				error(
>>  			"bad extent[%llu, %llu) type mismatch with chunk",
>> -					extent_key.objectid,
>> -					extent_key.objectid + extent_key.offset);
>> +				      extent_key.objectid,
>> +				      extent_key.objectid + extent_key.offset);
>>  				err |= CHUNK_TYPE_MISMATCH;
>>  			}
>>  		} else if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
>> @@ -3175,7 +3184,8 @@ static int check_extent_data_backref(struct btrfs_fs_info *fs_info,
>>  		    btrfs_header_owner(leaf) != root_id)
>>  			goto next;
>>  		btrfs_item_key_to_cpu(leaf, &key, slot);
>> -		if (key.objectid != objectid || key.type != BTRFS_EXTENT_DATA_KEY)
>> +		if (key.objectid != objectid || key.type !=
>> +		    BTRFS_EXTENT_DATA_KEY)
>>  			break;
>>  		fi = btrfs_item_ptr(leaf, slot, struct btrfs_file_extent_item);
>>  		/*
>> @@ -3205,7 +3215,8 @@ out:
>>  	if (found_count != count) {
>>  		error(
>>  "extent[%llu, %llu] referencer count mismatch (root: %llu, owner: %llu, offset: %llu) wanted: %u, have: %u",
>> -			bytenr, len, root_id, objectid, offset, count, found_count);
>> +			bytenr, len, root_id, objectid, offset, count,
>> +			found_count);
>>  		return REFERENCER_MISSING;
>>  	}
>>  	return 0;
>> @@ -3975,13 +3986,12 @@ static int walk_down_tree(struct btrfs_trans_handle *trans,
>>  					       nrefs, account_file_data);
>>  			err |= ret;
>>  			break;
>> -		} else {
>> -			if (check || !check_all) {
>> -				ret = btrfs_check_node(root, NULL, cur);
>> -				if (ret != BTRFS_TREE_BLOCK_CLEAN) {
>> -					err |= -EIO;
>> -					break;
>> -				}
>> +		}
>> +		if (check || !check_all) {
>> +			ret = btrfs_check_node(root, NULL, cur);
>> +			if (ret != BTRFS_TREE_BLOCK_CLEAN) {
>> +				err |= -EIO;
>> +				break;
>>  			}
>>  		}
>>  
>> @@ -4001,7 +4011,8 @@ static int walk_down_tree(struct btrfs_trans_handle *trans,
>>  			continue;
>>  		}
>>  
>> -		next = btrfs_find_tree_block(fs_info, bytenr, fs_info->nodesize);
>> +		next = btrfs_find_tree_block(fs_info, bytenr,
>> +					     fs_info->nodesize);
>>  		if (!next || !btrfs_buffer_uptodate(next, ptr_gen)) {
>>  			free_extent_buffer(next);
>>  			reada_walk_down(root, cur, path->slots[*level]);
>> @@ -4022,7 +4033,7 @@ static int walk_down_tree(struct btrfs_trans_handle *trans,
>>  
>>  		ret = check_child_node(cur, path->slots[*level], next);
>>  		err |= ret;
>> -		if (ret < 0) 
>> +		if (ret < 0)
>>  			break;
>>  
>>  		if (btrfs_is_leaf(next))
>> @@ -4041,7 +4052,8 @@ static int walk_down_tree(struct btrfs_trans_handle *trans,
>>  		path->slots[*level] = 0;
>>  		account_file_data = 0;
>>  
>> -		update_nodes_refs(root, (u64)-1, next, nrefs, *level, check_all);
>> +		update_nodes_refs(root, (u64)-1, next, nrefs, *level,
>> +				  check_all);
>>  	}
>>  	return err;
>>  }
>> @@ -4058,11 +4070,10 @@ static int walk_up_tree(struct btrfs_root *root, struct btrfs_path *path,
>>  			path->slots[i]++;
>>  			*level = i;
>>  			return 0;
>> -		} else {
>> -			free_extent_buffer(path->nodes[*level]);
>> -			path->nodes[*level] = NULL;
>> -			*level = i + 1;
>>  		}
>> +		free_extent_buffer(path->nodes[*level]);
>> +		path->nodes[*level] = NULL;
>> +		*level = i + 1;
>>  	}
>>  	return 1;
>>  }
>> diff --git a/check/main.c b/check/main.c
>> index aec3881fc043..f6874cd86543 100644
>> --- a/check/main.c
>> +++ b/check/main.c
>> @@ -1720,14 +1720,13 @@ static int walk_up_tree(struct btrfs_root *root, struct btrfs_path *path,
>>  			path->slots[i]++;
>>  			*level = i;
>>  			return 0;
>> -		} else {
>> -			free_extent_buffer(path->nodes[*level]);
>> -			path->nodes[*level] = NULL;
>> -			BUG_ON(*level > wc->active_node);
>> -			if (*level == wc->active_node)
>> -				leave_shared_node(root, wc, *level);
>> -			*level = i + 1;
>>  		}
>> +		free_extent_buffer(path->nodes[*level]);
>> +		path->nodes[*level] = NULL;
>> +		BUG_ON(*level > wc->active_node);
>> +		if (*level == wc->active_node)
>> +			leave_shared_node(root, wc, *level);
>> +		*level = i + 1;
>>  	}
>>  	return 1;
>>  }
>> @@ -3488,22 +3487,21 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
>>  				goto out;
>>  			if (back->is_data) {
>>  				dback = to_data_backref(back);
>> -				fprintf(stderr, "Data backref %llu %s %llu"
>> -					" owner %llu offset %llu num_refs %lu"
>> -					" not found in extent tree\n",
>> +				fprintf(stderr,
>> +"Data backref %llu %s %llu owner %llu offset %llu num_refs %lu not found in extent tree\n",
>>  					(unsigned long long)rec->start,
>>  					back->full_backref ?
>>  					"parent" : "root",
>>  					back->full_backref ?
>> -					(unsigned long long)dback->parent:
>> +					(unsigned long long)dback->parent :
>>  					(unsigned long long)dback->root,
>>  					(unsigned long long)dback->owner,
>>  					(unsigned long long)dback->offset,
>>  					(unsigned long)dback->num_refs);
>>  			} else {
>>  				tback = to_tree_backref(back);
>> -				fprintf(stderr, "Tree backref %llu parent %llu"
>> -					" root %llu not found in extent tree\n",
>> +				fprintf(stderr,
>> +"Tree backref %llu parent %llu root %llu not found in extent tree\n",
>>  					(unsigned long long)rec->start,
>>  					(unsigned long long)tback->parent,
>>  					(unsigned long long)tback->root);
>> @@ -3514,7 +3512,8 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
>>  			if (!print_errs)
>>  				goto out;
>>  			tback = to_tree_backref(back);
>> -			fprintf(stderr, "Backref %llu %s %llu not referenced back %p\n",
>> +			fprintf(stderr,
>> +				"Backref %llu %s %llu not referenced back %p\n",
>>  				(unsigned long long)rec->start,
>>  				back->full_backref ? "parent" : "root",
>>  				back->full_backref ?
>> @@ -3527,26 +3526,25 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
>>  				err = 1;
>>  				if (!print_errs)
>>  					goto out;
>> -				fprintf(stderr, "Incorrect local backref count"
>> -					" on %llu %s %llu owner %llu"
>> -					" offset %llu found %u wanted %u back %p\n",
>> +				fprintf(stderr,
>> +"Incorrect local backref count on %llu %s %llu owner %llu offset %llu found %u wanted %u back %p\n",
>>  					(unsigned long long)rec->start,
>>  					back->full_backref ?
>>  					"parent" : "root",
>>  					back->full_backref ?
>> -					(unsigned long long)dback->parent:
>> +					(unsigned long long)dback->parent :
>>  					(unsigned long long)dback->root,
>>  					(unsigned long long)dback->owner,
>>  					(unsigned long long)dback->offset,
>> -					dback->found_ref, dback->num_refs, back);
>> +					dback->found_ref, dback->num_refs,
>> +					back);
>>  			}
>>  			if (dback->disk_bytenr != rec->start) {
>>  				err = 1;
>>  				if (!print_errs)
>>  					goto out;
>> -				fprintf(stderr, "Backref disk bytenr does not"
>> -					" match extent record, bytenr=%llu, "
>> -					"ref bytenr=%llu\n",
>> +				fprintf(stderr,
>> +"Backref disk bytenr does not match extent record, bytenr=%llu, ref bytenr=%llu\n",
>>  					(unsigned long long)rec->start,
>>  					(unsigned long long)dback->disk_bytenr);
>>  			}
>> @@ -3555,9 +3553,8 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
>>  				err = 1;
>>  				if (!print_errs)
>>  					goto out;
>> -				fprintf(stderr, "Backref bytes do not match "
>> -					"extent backref, bytenr=%llu, ref "
>> -					"bytes=%llu, backref bytes=%llu\n",
>> +				fprintf(stderr,
>> +"Backref bytes do not match extent backref, bytenr=%llu, ref bytes=%llu, backref bytes=%llu\n",
>>  					(unsigned long long)rec->start,
>>  					(unsigned long long)rec->nr,
>>  					(unsigned long long)dback->bytes);
>> @@ -3574,8 +3571,8 @@ static int all_backpointers_checked(struct extent_record *rec, int print_errs)
>>  		err = 1;
>>  		if (!print_errs)
>>  			goto out;
>> -		fprintf(stderr, "Incorrect global backref count "
>> -			"on %llu found %llu wanted %llu\n",
>> +		fprintf(stderr,
>> +"Incorrect global backref count on %llu found %llu wanted %llu\n",
>>  			(unsigned long long)rec->start,
>>  			(unsigned long long)found,
>>  			(unsigned long long)rec->refs);
>> @@ -3745,6 +3742,7 @@ static int swap_values(struct btrfs_root *root, struct btrfs_path *path,
>>  				    sizeof(struct btrfs_key_ptr));
>>  		if (slot == 0) {
>>  			struct btrfs_disk_key key;
>> +
>>  			btrfs_node_key(buf, &key, 0);
>>  			btrfs_fixup_low_keys(root, path, &key,
>>  					     btrfs_header_level(buf) + 1);
>> @@ -3877,8 +3875,8 @@ again:
>>  				ret = delete_bogus_item(root, path, buf, i);
>>  				if (!ret)
>>  					goto again;
>> -				fprintf(stderr, "item is off the end of the "
>> -					"leaf, can't fix\n");
>> +				fprintf(stderr,
>> +				"item is off the end of the leaf, can't fix\n");
>>  				ret = -EIO;
>>  				break;
>>  			}
>> @@ -4066,7 +4064,7 @@ static struct tree_backref *find_tree_backref(struct extent_record *rec,
>>  	struct extent_backref *node;
>>  	struct tree_backref *back;
>>  
>> -	while(cur != &rec->backrefs) {
>> +	while (cur != &rec->backrefs) {
>>  		node = to_extent_backref(cur);
>>  		cur = cur->next;
>>  		if (node->is_data)
>> @@ -4118,7 +4116,7 @@ static struct data_backref *find_data_backref(struct extent_record *rec,
>>  	struct extent_backref *node;
>>  	struct data_backref *back;
>>  
>> -	while(cur != &rec->backrefs) {
>> +	while (cur != &rec->backrefs) {
>>  		node = to_extent_backref(cur);
>>  		cur = cur->next;
>>  		if (!node->is_data)
>> @@ -4344,12 +4342,13 @@ static int add_extent_rec(struct cache_tree *extent_cache,
>>  
>>  		if (tmpl->extent_item_refs && !dup) {
>>  			if (rec->extent_item_refs) {
>> -				fprintf(stderr, "block %llu rec "
>> -					"extent_item_refs %llu, passed %llu\n",
>> +				fprintf(stderr,
>> +			"block %llu rec extent_item_refs %llu, passed %llu\n",
>>  					(unsigned long long)tmpl->start,
>>  					(unsigned long long)
>>  							rec->extent_item_refs,
>> -					(unsigned long long)tmpl->extent_item_refs);
>> +					(unsigned long long)
>> +							tmpl->extent_item_refs);
>>  			}
>>  			rec->extent_item_refs = tmpl->extent_item_refs;
>>  		}
>> @@ -4433,8 +4432,8 @@ static int add_tree_backref(struct cache_tree *extent_cache, u64 bytenr,
>>  
>>  	if (found_ref) {
>>  		if (back->node.found_ref) {
>> -			fprintf(stderr, "Extent back ref already exists "
>> -				"for %llu parent %llu root %llu \n",
>> +			fprintf(stderr,
>> +	"Extent back ref already exists for %llu parent %llu root %llu\n",
>>  				(unsigned long long)bytenr,
>>  				(unsigned long long)parent,
>>  				(unsigned long long)root);
>> @@ -4442,8 +4441,8 @@ static int add_tree_backref(struct cache_tree *extent_cache, u64 bytenr,
>>  		back->node.found_ref = 1;
>>  	} else {
>>  		if (back->node.found_extent_tree) {
>> -			fprintf(stderr, "Extent back ref already exists "
>> -				"for %llu parent %llu root %llu \n",
>> +			fprintf(stderr,
>> +	"Extent back ref already exists for %llu parent %llu root %llu\n",
>>  				(unsigned long long)bytenr,
>>  				(unsigned long long)parent,
>>  				(unsigned long long)root);
>> @@ -4530,9 +4529,8 @@ static int add_data_backref(struct cache_tree *extent_cache, u64 bytenr,
>>  		rec->owner_ref_checked = 1;
>>  	} else {
>>  		if (back->node.found_extent_tree) {
>> -			fprintf(stderr, "Extent back ref already exists "
>> -				"for %llu parent %llu root %llu "
>> -				"owner %llu offset %llu num_refs %lu\n",
>> +			fprintf(stderr,
>> +"Extent back ref already exists for %llu parent %llu root %llu owner %llu offset %llu num_refs %lu\n",
>>  				(unsigned long long)bytenr,
>>  				(unsigned long long)parent,
>>  				(unsigned long long)root,
>> @@ -4555,6 +4553,7 @@ static int add_pending(struct cache_tree *pending,
>>  		       struct cache_tree *seen, u64 bytenr, u32 size)
>>  {
>>  	int ret;
>> +
>>  	ret = add_cache_extent(seen, bytenr, size);
>>  	if (ret)
>>  		return ret;
>> @@ -4588,17 +4587,17 @@ static int pick_next_pending(struct cache_tree *pending,
>>  		cache = search_cache_extent(nodes, 0);
>>  
>>  	if (!cache) {
>> -		 cache = search_cache_extent(pending, 0);
>> -		 if (!cache)
>> -			 return 0;
>> -		 ret = 0;
>> -		 do {
>> -			 bits[ret].start = cache->start;
>> -			 bits[ret].size = cache->size;
>> -			 cache = next_cache_extent(cache);
>> -			 ret++;
>> -		 } while (cache && ret < bits_nr);
>> -		 return ret;
>> +		cache = search_cache_extent(pending, 0);
>> +		if (!cache)
>> +			return 0;
>> +		ret = 0;
>> +		do {
>> +			bits[ret].start = cache->start;
>> +			bits[ret].size = cache->size;
>> +			cache = next_cache_extent(cache);
>> +			ret++;
>> +		} while (cache && ret < bits_nr);
>> +		return ret;
>>  	}
>>  
>>  	ret = 0;
>> @@ -4612,8 +4611,9 @@ static int pick_next_pending(struct cache_tree *pending,
>>  	if (bits_nr - ret > 8) {
>>  		u64 lookup = bits[0].start + bits[0].size;
>>  		struct cache_extent *next;
>> +
>>  		next = search_cache_extent(pending, lookup);
>> -		while(next) {
>> +		while (next) {
>>  			if (next->start - lookup > 32768)
>>  				break;
>>  			bits[ret].start = next->start;
>> @@ -5004,6 +5004,7 @@ static int process_extent_item(struct btrfs_root *root,
>>  	if (item_size < sizeof(*ei)) {
>>  #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
>>  		struct btrfs_extent_item_v0 *ei0;
>> +
>>  		if (item_size != sizeof(*ei0)) {
>>  			error(
>>  	"invalid extent item format: ITEM[%llu %u %llu] leaf: %llu slot: %d",
>> @@ -5356,8 +5357,8 @@ static int check_space_cache(struct btrfs_root *root)
>>  
>>  static int check_extent_csums(struct btrfs_root *root, u64 bytenr,
>>  			u64 num_bytes, unsigned long leaf_offset,
>> -			struct extent_buffer *eb) {
>> -
>> +			struct extent_buffer *eb)
>> +{
>>  	struct btrfs_fs_info *fs_info = root->fs_info;
>>  	u64 offset = 0;
>>  	u16 csum_size = btrfs_super_csum_size(fs_info->super_copy);
>> @@ -5646,7 +5647,8 @@ skip_csum_check:
>>  }
>>  
>>  static int is_dropped_key(struct btrfs_key *key,
>> -			  struct btrfs_key *drop_key) {
>> +			  struct btrfs_key *drop_key)
>> +{
>>  	if (key->objectid < drop_key->objectid)
>>  		return 1;
>>  	else if (key->objectid == drop_key->objectid) {
>> @@ -5823,7 +5825,7 @@ static int run_next_block(struct btrfs_root *root,
>>  		return 1;
>>  
>>  	if (!reada_bits) {
>> -		for(i = 0; i < nritems; i++) {
>> +		for (i = 0; i < nritems; i++) {
>>  			ret = add_cache_extent(reada, bits[i].start,
>>  					       bits[i].size);
>>  			if (ret == -EEXIST)
>> @@ -5933,6 +5935,7 @@ static int run_next_block(struct btrfs_root *root,
>>  		btree_space_waste += btrfs_leaf_free_space(root, buf);
>>  		for (i = 0; i < nritems; i++) {
>>  			struct btrfs_file_extent_item *fi;
>> +
>>  			btrfs_item_key_to_cpu(buf, &key, i);
>>  			/*
>>  			 * Check key type against the leaf owner.
>> @@ -6007,6 +6010,7 @@ static int run_next_block(struct btrfs_root *root,
>>  			}
>>  			if (key.type == BTRFS_EXTENT_DATA_REF_KEY) {
>>  				struct btrfs_extent_data_ref *ref;
>> +
>>  				ref = btrfs_item_ptr(buf, i,
>>  						struct btrfs_extent_data_ref);
>>  				add_data_backref(extent_cache,
>> @@ -6021,6 +6025,7 @@ static int run_next_block(struct btrfs_root *root,
>>  			}
>>  			if (key.type == BTRFS_SHARED_DATA_REF_KEY) {
>>  				struct btrfs_shared_data_ref *ref;
>> +
>>  				ref = btrfs_item_ptr(buf, i,
>>  						struct btrfs_shared_data_ref);
>>  				add_data_backref(extent_cache,
>> @@ -6058,9 +6063,9 @@ static int run_next_block(struct btrfs_root *root,
>>  
>>  			data_bytes_allocated +=
>>  				btrfs_file_extent_disk_num_bytes(buf, fi);
>> -			if (data_bytes_allocated < root->fs_info->sectorsize) {
>> +			if (data_bytes_allocated < root->fs_info->sectorsize)
>>  				abort();
>> -			}
>> +
>>  			data_bytes_referenced +=
>>  				btrfs_file_extent_num_bytes(buf, fi);
>>  			add_data_backref(extent_cache,
>> @@ -6093,7 +6098,8 @@ static int run_next_block(struct btrfs_root *root,
>>  
>>  			memset(&tmpl, 0, sizeof(tmpl));
>>  			btrfs_cpu_key_to_disk(&tmpl.parent_key, &key);
>> -			tmpl.parent_generation = btrfs_node_ptr_generation(buf, i);
>> +			tmpl.parent_generation =
>> +				btrfs_node_ptr_generation(buf, i);
>>  			tmpl.start = ptr;
>>  			tmpl.nr = size;
>>  			tmpl.refs = 1;
>> @@ -6112,11 +6118,10 @@ static int run_next_block(struct btrfs_root *root,
>>  				continue;
>>  			}
>>  
>> -			if (level > 1) {
>> +			if (level > 1)
>>  				add_pending(nodes, seen, ptr, size);
>> -			} else {
>> +			else
>>  				add_pending(pending, seen, ptr, size);
>> -			}
>>  		}
>>  		btree_space_waste += (BTRFS_NODEPTRS_PER_BLOCK(fs_info) -
>>  				      nritems) * sizeof(struct btrfs_key_ptr);
>> @@ -6188,6 +6193,7 @@ static int free_extent_hook(struct btrfs_trans_handle *trans,
>>  	rec = container_of(cache, struct extent_record, cache);
>>  	if (is_data) {
>>  		struct data_backref *back;
>> +
>>  		back = find_data_backref(rec, parent, root_objectid, owner,
>>  					 offset, 1, bytenr, num_bytes);
>>  		if (!back)
>> @@ -6213,6 +6219,7 @@ static int free_extent_hook(struct btrfs_trans_handle *trans,
>>  		}
>>  	} else {
>>  		struct tree_backref *back;
>> +
>>  		back = find_tree_backref(rec, parent, root_objectid);
>>  		if (!back)
>>  			goto out;
>> @@ -6252,7 +6259,7 @@ static int delete_extent_records(struct btrfs_trans_handle *trans,
>>  	key.type = (u8)-1;
>>  	key.offset = (u64)-1;
>>  
>> -	while(1) {
>> +	while (1) {
>>  		ret = btrfs_search_slot(trans, root->fs_info->extent_root,
>>  					&key, path, 0, 1);
>>  		if (ret < 0)
>> @@ -6365,7 +6372,7 @@ static int record_extent(struct btrfs_trans_handle *trans,
>>  			btrfs_set_extent_flags(leaf, ei,
>>  					       BTRFS_EXTENT_FLAG_DATA);
>>  		} else {
>> -			struct btrfs_disk_key copy_key;;
>> +			struct btrfs_disk_key copy_key;
>>  
>>  			bi = (struct btrfs_tree_block_info *)(ei + 1);
>>  			memset_extent_buffer(leaf, 0, (unsigned long)bi,
>> @@ -6379,8 +6386,8 @@ static int record_extent(struct btrfs_trans_handle *trans,
>>  			btrfs_set_tree_block_level(leaf, bi, rec->info_level);
>>  			btrfs_set_tree_block_key(leaf, bi, &copy_key);
>>  
>> -			btrfs_set_extent_flags(leaf, ei,
>> -					       BTRFS_EXTENT_FLAG_TREE_BLOCK | flags);
>> +			btrfs_set_extent_flags(leaf, ei, flags |
>> +					       BTRFS_EXTENT_FLAG_TREE_BLOCK);
>>  		}
>>  
>>  		btrfs_mark_buffer_dirty(leaf);
>> @@ -6418,18 +6425,14 @@ static int record_extent(struct btrfs_trans_handle *trans,
>>  			if (ret)
>>  				break;
>>  		}
>> -		fprintf(stderr, "adding new data backref"
>> -				" on %llu %s %llu owner %llu"
>> -				" offset %llu found %d\n",
>> -				(unsigned long long)rec->start,
>> -				back->full_backref ?
>> -				"parent" : "root",
>> -				back->full_backref ?
>> -				(unsigned long long)parent :
>> -				(unsigned long long)dback->root,
>> -				(unsigned long long)dback->owner,
>> -				(unsigned long long)dback->offset,
>> -				dback->found_ref);
>> +		fprintf(stderr,
>> +"adding new data backref on %llu %s %llu owner %llu offset %llu found %d\n",
>> +			(unsigned long long)rec->start,
>> +			back->full_backref ? "parent" : "root",
>> +			back->full_backref ? (unsigned long long)parent :
>> +					     (unsigned long long)dback->root,
>> +			(unsigned long long)dback->owner,
>> +			(unsigned long long)dback->offset, dback->found_ref);
>>  	} else {
>>  		u64 parent;
>>  		struct tree_backref *tback;
>> @@ -6443,8 +6446,8 @@ static int record_extent(struct btrfs_trans_handle *trans,
>>  		ret = btrfs_inc_extent_ref(trans, info->extent_root,
>>  					   rec->start, rec->max_size,
>>  					   parent, tback->root, 0, 0);
>> -		fprintf(stderr, "adding new tree backref on "
>> -			"start %llu len %llu parent %llu root %llu\n",
>> +		fprintf(stderr,
>> +"adding new tree backref on start %llu len %llu parent %llu root %llu\n",
>>  			rec->start, rec->max_size, parent, tback->root);
>>  	}
>>  fail:
>> @@ -6587,9 +6590,9 @@ static int repair_ref(struct btrfs_fs_info *info, struct btrfs_path *path,
>>  		goto out;
>>  	}
>>  	if (ret > 0) {
>> -		fprintf(stderr, "Well that's odd, we just found this key "
>> -			"[%Lu, %u, %Lu]\n", key.objectid, key.type,
>> -			key.offset);
>> +		fprintf(stderr,
>> +		"Well that's odd, we just found this key [%Lu, %u, %Lu]\n",
>> +			key.objectid, key.type, key.offset);
>>  		ret = -EINVAL;
>>  		goto out;
>>  	}
>> @@ -6599,10 +6602,8 @@ static int repair_ref(struct btrfs_fs_info *info, struct btrfs_path *path,
>>  
>>  	if (btrfs_file_extent_compression(leaf, fi) &&
>>  	    dback->disk_bytenr != entry->bytenr) {
>> -		fprintf(stderr, "Ref doesn't match the record start and is "
>> -			"compressed, please take a btrfs-image of this file "
>> -			"system and send it to a btrfs developer so they can "
>> -			"complete this functionality for bytenr %Lu\n",
>> +		fprintf(stderr,
>> +"Ref doesn't match the record start and is compressed, please take a btrfs-image of this file system and send it to a btrfs developer so they can complete this functionality for bytenr %Lu\n",
>>  			dback->disk_bytenr);
>>  		ret = -EINVAL;
>>  		goto out;
>> @@ -6618,9 +6619,8 @@ static int repair_ref(struct btrfs_fs_info *info, struct btrfs_path *path,
>>  		if (dback->disk_bytenr + offset +
>>  		    btrfs_file_extent_num_bytes(leaf, fi) >
>>  		    entry->bytenr + entry->bytes) {
>> -			fprintf(stderr, "Ref is past the entry end, please "
>> -				"take a btrfs-image of this file system and "
>> -				"send it to a btrfs developer, ref %Lu\n",
>> +			fprintf(stderr,
>> +"Ref is past the entry end, please take a btrfs-image of this file system and send it to a btrfs developer, ref %Lu\n",
>>  				dback->disk_bytenr);
>>  			ret = -EINVAL;
>>  			goto out;
>> @@ -6633,9 +6633,8 @@ static int repair_ref(struct btrfs_fs_info *info, struct btrfs_path *path,
>>  
>>  		offset = btrfs_file_extent_offset(leaf, fi);
>>  		if (dback->disk_bytenr + offset < entry->bytenr) {
>> -			fprintf(stderr, "Ref is before the entry start, please"
>> -				" take a btrfs-image of this file system and "
>> -				"send it to a btrfs developer, ref %Lu\n",
>> +			fprintf(stderr,
>> +"Ref is before the entry start, please take a btrfs-image of this file system and send it to a btrfs developer, ref %Lu\n",
>>  				dback->disk_bytenr);
>>  			ret = -EINVAL;
>>  			goto out;
>> @@ -6741,8 +6740,9 @@ static int verify_backrefs(struct btrfs_fs_info *info, struct btrfs_path *path,
>>  	if (nr_entries <= 1 && !mismatch)
>>  		goto out;
>>  
>> -	fprintf(stderr, "attempting to repair backref discrepency for bytenr "
>> -		"%Lu\n", rec->start);
>> +	fprintf(stderr,
>> +		"attempting to repair backref discrepency for bytenr %Lu\n",
>> +		rec->start);
>>  
>>  	/*
>>  	 * First we want to see if the backrefs can agree amongst themselves who
>> @@ -6758,9 +6758,8 @@ static int verify_backrefs(struct btrfs_fs_info *info, struct btrfs_path *path,
>>  	if (!best) {
>>  		entry = find_entry(&entries, rec->start, rec->nr);
>>  		if (!entry && (!broken_entries || !rec->found_rec)) {
>> -			fprintf(stderr, "Backrefs don't agree with each other "
>> -				"and extent record doesn't agree with anybody,"
>> -				" so we can't fix bytenr %Lu bytes %Lu\n",
>> +			fprintf(stderr,
>> +"Backrefs don't agree with each other and extent record doesn't agree with anybody, so we can't fix bytenr %Lu bytes %Lu\n",
>>  				rec->start, rec->nr);
>>  			ret = -EINVAL;
>>  			goto out;
>> @@ -6783,10 +6782,9 @@ static int verify_backrefs(struct btrfs_fs_info *info, struct btrfs_path *path,
>>  		entry->count++;
>>  		best = find_most_right_entry(&entries);
>>  		if (!best) {
>> -			fprintf(stderr, "Backrefs and extent record evenly "
>> -				"split on who is right, this is going to "
>> -				"require user input to fix bytenr %Lu bytes "
>> -				"%Lu\n", rec->start, rec->nr);
>> +			fprintf(stderr,
>> +"Backrefs and extent record evenly split on who is right, this is going to require user input to fix bytenr %Lu bytes %Lu\n",
>> +				rec->start, rec->nr);
>>  			ret = -EINVAL;
>>  			goto out;
>>  		}
>> @@ -6798,10 +6796,8 @@ static int verify_backrefs(struct btrfs_fs_info *info, struct btrfs_path *path,
>>  	 * deal with it properly here yet, so just bail out of that's the case.
>>  	 */
>>  	if (best->bytenr != rec->start) {
>> -		fprintf(stderr, "Extent start and backref starts don't match, "
>> -			"please use btrfs-image on this file system and send "
>> -			"it to a btrfs developer so they can make fsck fix "
>> -			"this particular case.  bytenr is %Lu, bytes is %Lu\n",
>> +		fprintf(stderr,
>> +"Extent start and backref starts don't match, please use btrfs-image on this file system and send it to a btrfs developer so they can make fsck fix this particular case.  bytenr is %Lu, bytes is %Lu\n",
>>  			rec->start, rec->nr);
>>  		ret = -EINVAL;
>>  		goto out;
>> @@ -6951,10 +6947,8 @@ static int delete_duplicate_records(struct btrfs_root *root,
>>  			continue;
>>  
>>  		if (tmp->start + tmp->nr < good->start + good->nr) {
>> -			fprintf(stderr, "Ok we have overlapping extents that "
>> -				"aren't completely covered by each other, this "
>> -				"is going to require more careful thought.  "
>> -				"The extents are [%Lu-%Lu] and [%Lu-%Lu]\n",
>> +			fprintf(stderr,
>> +"Ok we have overlapping extents that aren't completely covered by each other, this is going to require more careful thought. The extents are [%Lu-%Lu] and [%Lu-%Lu]\n",
>>  				tmp->start, tmp->nr, good->start, good->nr);
>>  			abort();
>>  		}
>> @@ -6986,9 +6980,9 @@ static int delete_duplicate_records(struct btrfs_root *root,
>>  
>>  		/* Shouldn't happen but just in case */
>>  		if (tmp->metadata) {
>> -			fprintf(stderr, "Well this shouldn't happen, extent "
>> -				"record overlaps but is metadata? "
>> -				"[%Lu, %Lu]\n", tmp->start, tmp->nr);
>> +			fprintf(stderr,
>> +"Well this shouldn't happen, extent record overlaps but is metadata? [%Lu, %Lu]\n",
>> +				tmp->start, tmp->nr);
>>  			abort();
>>  		}
>>  
>> @@ -7090,6 +7084,7 @@ static int find_possible_backrefs(struct btrfs_fs_info *info,
>>  		cache = lookup_cache_extent(extent_cache, bytenr, 1);
>>  		if (cache) {
>>  			struct extent_record *tmp;
>> +
>>  			tmp = container_of(cache, struct extent_record, cache);
>>  
>>  			/*
>> @@ -7271,7 +7266,8 @@ static int fixup_extent_refs(struct btrfs_fs_info *info,
>>  			continue;
>>  
>>  		rec->bad_full_backref = 0;
>> -		ret = record_extent(trans, info, &path, rec, back, allocated, flags);
>> +		ret = record_extent(trans, info, &path, rec, back, allocated,
>> +				    flags);
>>  		allocated = 1;
>>  
>>  		if (ret)
>> @@ -7280,6 +7276,7 @@ static int fixup_extent_refs(struct btrfs_fs_info *info,
>>  out:
>>  	if (trans) {
>>  		int err = btrfs_commit_transaction(trans, info->extent_root);
>> +
>>  		if (!ret)
>>  			ret = err;
>>  	}
>> @@ -7401,8 +7398,8 @@ again:
>>  			goto del_ptr;
>>  	}
>>  	/*
>> -	 * we couldn't find the bad block.  TODO, search all the nodes for pointers
>> -	 * to this block
>> +	 * we couldn't find the bad block.
>> +	 * TODO: search all the nodes for pointers to this block
>>  	 */
>>  	if (eb == info->extent_root->node) {
>>  		ret = -ENOENT;
>> @@ -7437,7 +7434,8 @@ static int prune_corrupt_blocks(struct btrfs_fs_info *info)
>>  			if (IS_ERR(trans))
>>  				return PTR_ERR(trans);
>>  		}
>> -		corrupt = container_of(cache, struct btrfs_corrupt_block, cache);
>> +		corrupt = container_of(cache, struct btrfs_corrupt_block,
>> +				       cache);
>>  		prune_one_block(trans, info, corrupt);
>>  		remove_cache_extent(info->corrupt_blocks, cache);
>>  	}
>> @@ -7463,7 +7461,7 @@ static int check_extent_refs(struct btrfs_root *root,
>>  		 * extents in the FS
>>  		 */
>>  		cache = search_cache_extent(extent_cache, 0);
>> -		while(cache) {
>> +		while (cache) {
>>  			rec = container_of(cache, struct extent_record, cache);
>>  			set_extent_dirty(root->fs_info->excluded_extents,
>>  					 rec->start,
>> @@ -7473,7 +7471,7 @@ static int check_extent_refs(struct btrfs_root *root,
>>  
>>  		/* pin down all the corrupted blocks too */
>>  		cache = search_cache_extent(root->fs_info->corrupt_blocks, 0);
>> -		while(cache) {
>> +		while (cache) {
>>  			set_extent_dirty(root->fs_info->excluded_extents,
>>  					 cache->start,
>>  					 cache->start + cache->size - 1);
>> @@ -7518,7 +7516,7 @@ static int check_extent_refs(struct btrfs_root *root,
>>  	if (had_dups)
>>  		return -EAGAIN;
>>  
>> -	while(1) {
>> +	while (1) {
>>  		int cur_err = 0;
>>  		int fix = 0;
>>  
>> @@ -7527,8 +7525,9 @@ static int check_extent_refs(struct btrfs_root *root,
>>  			break;
>>  		rec = container_of(cache, struct extent_record, cache);
>>  		if (rec->num_duplicates) {
>> -			fprintf(stderr, "extent item %llu has multiple extent "
>> -				"items\n", (unsigned long long)rec->start);
>> +			fprintf(stderr,
>> +				"extent item %llu has multiple extent items\n",
>> +				(unsigned long long)rec->start);
>>  			cur_err = 1;
>>  		}
>>  
>> @@ -7561,7 +7560,8 @@ static int check_extent_refs(struct btrfs_root *root,
>>  		}
>>  
>>  		if (repair && fix) {
>> -			ret = fixup_extent_refs(root->fs_info, extent_cache, rec);
>> +			ret = fixup_extent_refs(root->fs_info, extent_cache,
>> +						rec);
>>  			if (ret)
>>  				goto repair_abort;
>>  		}
>> @@ -7943,8 +7943,8 @@ static int add_root_item_to_list(struct list_head *head,
>>  				  u8 level, u8 drop_level,
>>  				  struct btrfs_key *drop_key)
>>  {
>> -
>>  	struct root_item_record *ri_rec;
>> +
>>  	ri_rec = malloc(sizeof(*ri_rec));
>>  	if (!ri_rec)
>>  		return -ENOMEM;
>> @@ -7992,6 +7992,7 @@ static int deal_root_from_list(struct list_head *list,
>>  	while (!list_empty(list)) {
>>  		struct root_item_record *rec;
>>  		struct extent_buffer *buf;
>> +
>>  		rec = list_entry(list->next,
>>  				 struct root_item_record, list);
>>  		last = 0;
>> @@ -8123,7 +8124,7 @@ again:
>>  	ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, &path, 0, 0);
>>  	if (ret < 0)
>>  		goto out;
>> -	while(1) {
>> +	while (1) {
>>  		leaf = path.nodes[0];
>>  		slot = path.slots[0];
>>  		if (slot >= btrfs_header_nritems(path.nodes[0])) {
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


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

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

* Re: [PATCH v2 3/3] btrfs-progs: check: Cleanup all checkpatch error and warning
  2018-02-01  8:28       ` Nikolay Borisov
@ 2018-02-01 15:06         ` David Sterba
  0 siblings, 0 replies; 11+ messages in thread
From: David Sterba @ 2018-02-01 15:06 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: Qu Wenruo, Su Yue, Qu Wenruo, linux-btrfs, dsterba

On Thu, Feb 01, 2018 at 10:28:13AM +0200, Nikolay Borisov wrote:
> >>> @@ -3175,7 +3184,8 @@ static int check_extent_data_backref(struct
> >>> btrfs_fs_info *fs_info,
> >>>               btrfs_header_owner(leaf) != root_id)
> >>>               goto next;
> >>>           btrfs_item_key_to_cpu(leaf, &key, slot);
> >>> -        if (key.objectid != objectid || key.type !=
> >>> BTRFS_EXTENT_DATA_KEY)
> >>> +        if (key.objectid != objectid || key.type !=
> >>> +            BTRFS_EXTENT_DATA_KEY)
> >> if (key.objectid != objectid ||
> >>     key.type != BTRFS_EXTENT_DATA_KEY)
> >> is more better.
> >> Other changes are nice.
> > 
> > I also thought about that, but that leaves too much space in previous line.
> > 
> > Not sure what should be the best practice here.
> 
> Su's suggestion is more readable so I'd say go with it

I slightly disagree with checkpatch about the 80 cols limit in case the
the ; or closing ) is on 80 or even 81 as long as the code becomes
readable. I've grepped for the condition and there are both one line and
2 line (split after ||), so it's IMO both acceptable.

If it's formatted as

if (key.objectid != objectid ||
    key.type != BTRFS_EXTENT_DATA_KEY)

it's ok.

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

* Re: [PATCH v2 0/3] btrfs-progs: Split lowmem mode check to its own
  2018-02-01  6:45 [PATCH v2 0/3] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
  2018-02-01  6:45 ` [PATCH v2 2/3] btrfs-progs: check/lowmem: Cleanup unnecessary _v2 suffix Qu Wenruo
  2018-02-01  6:45 ` [PATCH v2 3/3] btrfs-progs: check: Cleanup all checkpatch error and warning Qu Wenruo
@ 2018-02-01 16:05 ` David Sterba
  2018-02-02  1:36   ` Qu Wenruo
  2 siblings, 1 reply; 11+ messages in thread
From: David Sterba @ 2018-02-01 16:05 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs, dsterba

On Thu, Feb 01, 2018 at 02:45:38PM +0800, Qu Wenruo wrote:
> As usual, the main part is over 500K so the biggest patch won't reach
> mail list.
> Please fetch the whole branch from github:
> https://github.com/adam900710/btrfs-progs/tree/split_check

Thanks, patches added to devel, with some more adjustments.

> Despite the update, a new patch is introduced, to address the tons of
> BORING errors and warning from checkpatch.pl.

The checkpatch script can report lots of things to fix, but please note
that not all of them match the style we use. I've updated the patch 3/3
and undone some of the line splits, because it's the example where the
code looks worse after fixing.

We'd probably have to host our modified version of checkpatch so the
warnings don't get reported repeatedly.

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

* Re: [PATCH v2 0/3] btrfs-progs: Split lowmem mode check to its own
  2018-02-01 16:05 ` [PATCH v2 0/3] btrfs-progs: Split lowmem mode check to its own David Sterba
@ 2018-02-02  1:36   ` Qu Wenruo
  0 siblings, 0 replies; 11+ messages in thread
From: Qu Wenruo @ 2018-02-02  1:36 UTC (permalink / raw)
  To: dsterba, Qu Wenruo, linux-btrfs


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



On 2018年02月02日 00:05, David Sterba wrote:
> On Thu, Feb 01, 2018 at 02:45:38PM +0800, Qu Wenruo wrote:
>> As usual, the main part is over 500K so the biggest patch won't reach
>> mail list.
>> Please fetch the whole branch from github:
>> https://github.com/adam900710/btrfs-progs/tree/split_check
> 
> Thanks, patches added to devel, with some more adjustments.
> 
>> Despite the update, a new patch is introduced, to address the tons of
>> BORING errors and warning from checkpatch.pl.
> 
> The checkpatch script can report lots of things to fix, but please note
> that not all of them match the style we use. I've updated the patch 3/3
> and undone some of the line splits, because it's the example where the
> code looks worse after fixing.

Yep, some 81/82 chars modification is not that elegant.

> 
> We'd probably have to host our modified version of checkpatch so the
> warnings don't get reported repeatedly.

That would be the best case, I could take some spare time to port
checkpatch to btrfs-progs.

Thanks,
Qu

> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


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

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

end of thread, other threads:[~2018-02-02  1:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-01  6:45 [PATCH v2 0/3] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
2018-02-01  6:45 ` [PATCH v2 2/3] btrfs-progs: check/lowmem: Cleanup unnecessary _v2 suffix Qu Wenruo
2018-02-01  6:45 ` [PATCH v2 3/3] btrfs-progs: check: Cleanup all checkpatch error and warning Qu Wenruo
2018-02-01  7:08   ` Su Yue
2018-02-01  7:48     ` Qu Wenruo
2018-02-01  8:28       ` Nikolay Borisov
2018-02-01 15:06         ` David Sterba
2018-02-01  8:36   ` Nikolay Borisov
2018-02-01  9:20     ` Qu Wenruo
2018-02-01 16:05 ` [PATCH v2 0/3] btrfs-progs: Split lowmem mode check to its own David Sterba
2018-02-02  1:36   ` Qu Wenruo

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.