All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own
@ 2018-01-19  5:37 Qu Wenruo
  2018-01-19  5:37 ` [PATCH 01/16] btrfs-progs: Moves cmds-check.c to check/main.c Qu Wenruo
                   ` (16 more replies)
  0 siblings, 17 replies; 24+ messages in thread
From: Qu Wenruo @ 2018-01-19  5:37 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

The long planned cmds-check re-construction is finally here.

As the original cmds-check.c is getting larger and larger (already over
15K lines), it's always a good idea to split it into its own check/
directory.

This patchset do the following work:
1) Move cmds-check.c to check/main.c
2) Put codes shared by both original and lowmem mode into
   check/common.[ch]
3) Put lowmem code into check/lowmem.[ch]
   With minor renaming to get rid of unnecessary _v2 suffix.

The modification looks scary, but no functional change at all.

And considering how much the file structure changed, it's a good idea to
put PART1 as quick as possible, and there will be less pressure to
rebase new incoming fsck related codes.

The real move work happens in the 15th patch, which due to its size
(500KB+), it may not be able to reach mail list.
So please fetch the whole patchset from github:
https://github.com/adam900710/btrfs-progs/tree/split_check

There will be a part 2, mostly moving original mode to its own
check/original.[ch], along with extra comment explaining how the two
different modes work.

Qu Wenruo (16):
  btrfs-progs: Moves cmds-check.c to check/main.c
  btrfs-progs: check: Move original mode definitions to check/original.h
  btrfs-progs: check: Move definitions of lowmem mode to check/lowmem.h
  btrfs-progs: check: Move node_ptr structure to check/common.h
  btrfs-progs: check: Export check global variables to check/common.h
  btrfs-progs: check: Move imode_to_type function to check/common.h
  btrfs-progs: check: Move fs_root_objectid function to check/common.h
  btrfs-progs: check: Move count_csum_range function to check/common.c
  btrfs-progs: check: Move __create_inode_item function to
    check/common.c
  btrfs-progs: check: Move link_inode_to_lostfound function to common.c
  btrfs-progs: check: Move check_dev_size_alignment to check/common.c
  btrfs-progs: check: move reada_walk_down to check/common.c
  btrfs-progs: check: Move check_child_node to check/common.c
  btrfs-progs: check: Move reset_cached_block_groups to check/common.c
  btrfs-progs: check: Move lowmem check code to its own
    check/lowmem.[ch]
  btrfs-progs: check/lowmem: Cleanup unnecessary _v2 suffix

 Makefile                     |     6 +-
 check/common.c               |   351 +
 check/common.h               |   100 +
 check/lowmem.c               |  4571 ++++++++++++
 check/lowmem.h               |    67 +
 cmds-check.c => check/main.c | 16389 ++++++++++++++---------------------------
 check/original.h             |   293 +
 7 files changed, 11007 insertions(+), 10770 deletions(-)
 create mode 100644 check/common.c
 create mode 100644 check/common.h
 create mode 100644 check/lowmem.c
 create mode 100644 check/lowmem.h
 rename cmds-check.c => check/main.c (65%)
 create mode 100644 check/original.h

-- 
2.15.1


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

* [PATCH 01/16] btrfs-progs: Moves cmds-check.c to check/main.c
  2018-01-19  5:37 [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
@ 2018-01-19  5:37 ` Qu Wenruo
  2018-01-19  5:37 ` [PATCH 02/16] btrfs-progs: check: Move original mode definitions to check/original.h Qu Wenruo
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Qu Wenruo @ 2018-01-19  5:37 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 Makefile                     | 4 ++--
 cmds-check.c => check/main.c | 0
 2 files changed, 2 insertions(+), 2 deletions(-)
 rename cmds-check.c => check/main.c (100%)

diff --git a/Makefile b/Makefile
index 6369e8f4209c..c4e2dc5b68a9 100644
--- a/Makefile
+++ b/Makefile
@@ -109,7 +109,7 @@ objects = ctree.o disk-io.o kernel-lib/radix-tree.o extent-tree.o print-tree.o \
 	  fsfeatures.o kernel-lib/tables.o kernel-lib/raid56.o transaction.o
 cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
 	       cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
-	       cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
+	       cmds-quota.o cmds-qgroup.o cmds-replace.o check/main.o \
 	       cmds-restore.o cmds-rescue.o chunk-recover.o super-recover.o \
 	       cmds-property.o cmds-fi-usage.o cmds-inspect-dump-tree.o \
 	       cmds-inspect-dump-super.o cmds-inspect-tree-stats.o cmds-fi-du.o \
@@ -544,7 +544,7 @@ clean: $(CLEANDIRS)
 		kernel-shared/*.o kernel-shared/*.o.d \
 		image/*.o image/*.o.d \
 		convert/*.o convert/*.o.d \
-		mkfs/*.o mkfs/*.o.d \
+		mkfs/*.o mkfs/*.o.d check/*.o check/*.o.d \
 	      dir-test ioctl-test quick-test library-test library-test-static \
               mktables btrfs.static mkfs.btrfs.static fssum \
 	      $(check_defs) \
diff --git a/cmds-check.c b/check/main.c
similarity index 100%
rename from cmds-check.c
rename to check/main.c
-- 
2.15.1


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

* [PATCH 02/16] btrfs-progs: check: Move original mode definitions to check/original.h
  2018-01-19  5:37 [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
  2018-01-19  5:37 ` [PATCH 01/16] btrfs-progs: Moves cmds-check.c to check/main.c Qu Wenruo
@ 2018-01-19  5:37 ` Qu Wenruo
  2018-01-19  5:37 ` [PATCH 03/16] btrfs-progs: check: Move definitions of lowmem mode to check/lowmem.h Qu Wenruo
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Qu Wenruo @ 2018-01-19  5:37 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/main.c     | 269 +-------------------------------------------------
 check/original.h | 293 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 294 insertions(+), 268 deletions(-)
 create mode 100644 check/original.h

diff --git a/check/main.c b/check/main.c
index 7fc30da83ea1..c91a949ff7cc 100644
--- a/check/main.c
+++ b/check/main.c
@@ -43,6 +43,7 @@
 #include "kernel-shared/ulist.h"
 #include "hash.h"
 #include "help.h"
+#include "check/original.h"
 
 enum task_position {
 	TASK_EXTENTS,
@@ -84,35 +85,6 @@ enum btrfs_check_mode {
 
 static enum btrfs_check_mode check_mode = CHECK_MODE_DEFAULT;
 
-struct extent_backref {
-	struct rb_node node;
-	unsigned int is_data:1;
-	unsigned int found_extent_tree:1;
-	unsigned int full_backref:1;
-	unsigned int found_ref:1;
-	unsigned int broken:1;
-};
-
-static inline struct extent_backref* rb_node_to_extent_backref(struct rb_node *node)
-{
-	return rb_entry(node, struct extent_backref, node);
-}
-
-struct data_backref {
-	struct extent_backref node;
-	union {
-		u64 parent;
-		u64 root;
-	};
-	u64 owner;
-	u64 offset;
-	u64 disk_bytenr;
-	u64 bytes;
-	u64 ram_bytes;
-	u32 num_refs;
-	u32 found_ref;
-};
-
 #define ROOT_DIR_ERROR		(1<<1)	/* bad ROOT_DIR */
 #define DIR_ITEM_MISSING	(1<<2)	/* DIR_ITEM not found */
 #define DIR_ITEM_MISMATCH	(1<<3)	/* DIR_ITEM found but not match */
@@ -135,11 +107,6 @@ struct data_backref {
 #define DIR_COUNT_AGAIN         (1<<20) /* DIR isize should be recalculated */
 #define BG_ACCOUNTING_ERROR     (1<<21) /* Block group accounting error */
 
-static inline struct data_backref* to_data_backref(struct extent_backref *back)
-{
-	return container_of(back, struct data_backref, node);
-}
-
 static int compare_data_backref(struct rb_node *node1, struct rb_node *node2)
 {
 	struct extent_backref *ext1 = rb_node_to_extent_backref(node1);
@@ -185,34 +152,6 @@ static int compare_data_backref(struct rb_node *node1, struct rb_node *node2)
 	return 0;
 }
 
-/*
- * Much like data_backref, just removed the undetermined members
- * and change it to use list_head.
- * During extent scan, it is stored in root->orphan_data_extent.
- * During fs tree scan, it is then moved to inode_rec->orphan_data_extents.
- */
-struct orphan_data_extent {
-	struct list_head list;
-	u64 root;
-	u64 objectid;
-	u64 offset;
-	u64 disk_bytenr;
-	u64 disk_len;
-};
-
-struct tree_backref {
-	struct extent_backref node;
-	union {
-		u64 parent;
-		u64 root;
-	};
-};
-
-static inline struct tree_backref* to_tree_backref(struct extent_backref *back)
-{
-	return container_of(back, struct tree_backref, node);
-}
-
 static int compare_tree_backref(struct rb_node *node1, struct rb_node *node2)
 {
 	struct extent_backref *ext1 = rb_node_to_extent_backref(node1);
@@ -254,212 +193,6 @@ static int compare_extent_backref(struct rb_node *node1, struct rb_node *node2)
 		return compare_tree_backref(node1, node2);
 }
 
-/* Explicit initialization for extent_record::flag_block_full_backref */
-enum { FLAG_UNSET = 2 };
-
-struct extent_record {
-	struct list_head backrefs;
-	struct list_head dups;
-	struct rb_root backref_tree;
-	struct list_head list;
-	struct cache_extent cache;
-	struct btrfs_disk_key parent_key;
-	u64 start;
-	u64 max_size;
-	u64 nr;
-	u64 refs;
-	u64 extent_item_refs;
-	u64 generation;
-	u64 parent_generation;
-	u64 info_objectid;
-	u32 num_duplicates;
-	u8 info_level;
-	unsigned int flag_block_full_backref:2;
-	unsigned int found_rec:1;
-	unsigned int content_checked:1;
-	unsigned int owner_ref_checked:1;
-	unsigned int is_root:1;
-	unsigned int metadata:1;
-	unsigned int bad_full_backref:1;
-	unsigned int crossing_stripes:1;
-	unsigned int wrong_chunk_type:1;
-};
-
-static inline struct extent_record* to_extent_record(struct list_head *entry)
-{
-	return container_of(entry, struct extent_record, list);
-}
-
-struct inode_backref {
-	struct list_head list;
-	unsigned int found_dir_item:1;
-	unsigned int found_dir_index:1;
-	unsigned int found_inode_ref:1;
-	u8 filetype;
-	u8 ref_type;
-	int errors;
-	u64 dir;
-	u64 index;
-	u16 namelen;
-	char name[0];
-};
-
-static inline struct inode_backref* to_inode_backref(struct list_head *entry)
-{
-	return list_entry(entry, struct inode_backref, list);
-}
-
-struct root_item_record {
-	struct list_head list;
-	u64 objectid;
-	u64 bytenr;
-	u64 last_snapshot;
-	u8 level;
-	u8 drop_level;
-	struct btrfs_key drop_key;
-};
-
-#define REF_ERR_NO_DIR_ITEM		(1 << 0)
-#define REF_ERR_NO_DIR_INDEX		(1 << 1)
-#define REF_ERR_NO_INODE_REF		(1 << 2)
-#define REF_ERR_DUP_DIR_ITEM		(1 << 3)
-#define REF_ERR_DUP_DIR_INDEX		(1 << 4)
-#define REF_ERR_DUP_INODE_REF		(1 << 5)
-#define REF_ERR_INDEX_UNMATCH		(1 << 6)
-#define REF_ERR_FILETYPE_UNMATCH	(1 << 7)
-#define REF_ERR_NAME_TOO_LONG		(1 << 8) // 100
-#define REF_ERR_NO_ROOT_REF		(1 << 9)
-#define REF_ERR_NO_ROOT_BACKREF		(1 << 10)
-#define REF_ERR_DUP_ROOT_REF		(1 << 11)
-#define REF_ERR_DUP_ROOT_BACKREF	(1 << 12)
-
-struct file_extent_hole {
-	struct rb_node node;
-	u64 start;
-	u64 len;
-};
-
-struct inode_record {
-	struct list_head backrefs;
-	unsigned int checked:1;
-	unsigned int merging:1;
-	unsigned int found_inode_item:1;
-	unsigned int found_dir_item:1;
-	unsigned int found_file_extent:1;
-	unsigned int found_csum_item:1;
-	unsigned int some_csum_missing:1;
-	unsigned int nodatasum:1;
-	int errors;
-
-	u64 ino;
-	u32 nlink;
-	u32 imode;
-	u64 isize;
-	u64 nbytes;
-
-	u32 found_link;
-	u64 found_size;
-	u64 extent_start;
-	u64 extent_end;
-	struct rb_root holes;
-	struct list_head orphan_extents;
-
-	u32 refs;
-};
-
-#define I_ERR_NO_INODE_ITEM		(1 << 0)
-#define I_ERR_NO_ORPHAN_ITEM		(1 << 1)
-#define I_ERR_DUP_INODE_ITEM		(1 << 2)
-#define I_ERR_DUP_DIR_INDEX		(1 << 3)
-#define I_ERR_ODD_DIR_ITEM		(1 << 4)
-#define I_ERR_ODD_FILE_EXTENT		(1 << 5)
-#define I_ERR_BAD_FILE_EXTENT		(1 << 6)
-#define I_ERR_FILE_EXTENT_OVERLAP	(1 << 7)
-#define I_ERR_FILE_EXTENT_DISCOUNT	(1 << 8) // 100
-#define I_ERR_DIR_ISIZE_WRONG		(1 << 9)
-#define I_ERR_FILE_NBYTES_WRONG		(1 << 10) // 400
-#define I_ERR_ODD_CSUM_ITEM		(1 << 11)
-#define I_ERR_SOME_CSUM_MISSING		(1 << 12)
-#define I_ERR_LINK_COUNT_WRONG		(1 << 13)
-#define I_ERR_FILE_EXTENT_ORPHAN	(1 << 14)
-
-struct root_backref {
-	struct list_head list;
-	unsigned int found_dir_item:1;
-	unsigned int found_dir_index:1;
-	unsigned int found_back_ref:1;
-	unsigned int found_forward_ref:1;
-	unsigned int reachable:1;
-	int errors;
-	u64 ref_root;
-	u64 dir;
-	u64 index;
-	u16 namelen;
-	char name[0];
-};
-
-static inline struct root_backref* to_root_backref(struct list_head *entry)
-{
-	return list_entry(entry, struct root_backref, list);
-}
-
-struct root_record {
-	struct list_head backrefs;
-	struct cache_extent cache;
-	unsigned int found_root_item:1;
-	u64 objectid;
-	u32 found_ref;
-};
-
-struct ptr_node {
-	struct cache_extent cache;
-	void *data;
-};
-
-struct shared_node {
-	struct cache_extent cache;
-	struct cache_tree root_cache;
-	struct cache_tree inode_cache;
-	struct inode_record *current;
-	u32 refs;
-};
-
-struct block_info {
-	u64 start;
-	u32 size;
-};
-
-struct walk_control {
-	struct cache_tree shared;
-	struct shared_node *nodes[BTRFS_MAX_LEVEL];
-	int active_node;
-	int root_level;
-};
-
-struct bad_item {
-	struct btrfs_key key;
-	u64 root_id;
-	struct list_head list;
-};
-
-struct extent_entry {
-	u64 bytenr;
-	u64 bytes;
-	int count;
-	int broken;
-	struct list_head list;
-};
-
-struct root_item_info {
-	/* level of the root */
-	u8 level;
-	/* number of nodes at this level, must be 1 for a root */
-	int node_count;
-	u64 bytenr;
-	u64 gen;
-	struct cache_extent cache_extent;
-};
-
 /*
  * Error bit for low memory mode check.
  *
diff --git a/check/original.h b/check/original.h
new file mode 100644
index 000000000000..0d9ab353413b
--- /dev/null
+++ b/check/original.h
@@ -0,0 +1,293 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+/*
+ * Defines and function declarations for original mode check.
+ */
+
+#ifndef __BTRFS_CHECK_ORIGINAL_H__
+#define __BTRFS_CHECK_ORIGINAL_H__
+#include "rbtree-utils.h"
+
+struct extent_backref {
+	struct rb_node node;
+	unsigned int is_data:1;
+	unsigned int found_extent_tree:1;
+	unsigned int full_backref:1;
+	unsigned int found_ref:1;
+	unsigned int broken:1;
+};
+
+static inline struct extent_backref* rb_node_to_extent_backref(struct rb_node *node)
+{
+	return rb_entry(node, struct extent_backref, node);
+}
+
+struct data_backref {
+	struct extent_backref node;
+	union {
+		u64 parent;
+		u64 root;
+	};
+	u64 owner;
+	u64 offset;
+	u64 disk_bytenr;
+	u64 bytes;
+	u64 ram_bytes;
+	u32 num_refs;
+	u32 found_ref;
+};
+
+static inline struct data_backref* to_data_backref(struct extent_backref *back)
+{
+	return container_of(back, struct data_backref, node);
+}
+
+/*
+ * Much like data_backref, just removed the undetermined members
+ * and change it to use list_head.
+ * During extent scan, it is stored in root->orphan_data_extent.
+ * During fs tree scan, it is then moved to inode_rec->orphan_data_extents.
+ */
+struct orphan_data_extent {
+	struct list_head list;
+	u64 root;
+	u64 objectid;
+	u64 offset;
+	u64 disk_bytenr;
+	u64 disk_len;
+};
+
+struct tree_backref {
+	struct extent_backref node;
+	union {
+		u64 parent;
+		u64 root;
+	};
+};
+
+static inline struct tree_backref* to_tree_backref(struct extent_backref *back)
+{
+	return container_of(back, struct tree_backref, node);
+}
+
+/* Explicit initialization for extent_record::flag_block_full_backref */
+enum { FLAG_UNSET = 2 };
+
+struct extent_record {
+	struct list_head backrefs;
+	struct list_head dups;
+	struct rb_root backref_tree;
+	struct list_head list;
+	struct cache_extent cache;
+	struct btrfs_disk_key parent_key;
+	u64 start;
+	u64 max_size;
+	u64 nr;
+	u64 refs;
+	u64 extent_item_refs;
+	u64 generation;
+	u64 parent_generation;
+	u64 info_objectid;
+	u32 num_duplicates;
+	u8 info_level;
+	unsigned int flag_block_full_backref:2;
+	unsigned int found_rec:1;
+	unsigned int content_checked:1;
+	unsigned int owner_ref_checked:1;
+	unsigned int is_root:1;
+	unsigned int metadata:1;
+	unsigned int bad_full_backref:1;
+	unsigned int crossing_stripes:1;
+	unsigned int wrong_chunk_type:1;
+};
+
+static inline struct extent_record* to_extent_record(struct list_head *entry)
+{
+	return container_of(entry, struct extent_record, list);
+}
+
+struct inode_backref {
+	struct list_head list;
+	unsigned int found_dir_item:1;
+	unsigned int found_dir_index:1;
+	unsigned int found_inode_ref:1;
+	u8 filetype;
+	u8 ref_type;
+	int errors;
+	u64 dir;
+	u64 index;
+	u16 namelen;
+	char name[0];
+};
+
+static inline struct inode_backref* to_inode_backref(struct list_head *entry)
+{
+	return list_entry(entry, struct inode_backref, list);
+}
+
+struct root_item_record {
+	struct list_head list;
+	u64 objectid;
+	u64 bytenr;
+	u64 last_snapshot;
+	u8 level;
+	u8 drop_level;
+	struct btrfs_key drop_key;
+};
+
+#define REF_ERR_NO_DIR_ITEM		(1 << 0)
+#define REF_ERR_NO_DIR_INDEX		(1 << 1)
+#define REF_ERR_NO_INODE_REF		(1 << 2)
+#define REF_ERR_DUP_DIR_ITEM		(1 << 3)
+#define REF_ERR_DUP_DIR_INDEX		(1 << 4)
+#define REF_ERR_DUP_INODE_REF		(1 << 5)
+#define REF_ERR_INDEX_UNMATCH		(1 << 6)
+#define REF_ERR_FILETYPE_UNMATCH	(1 << 7)
+#define REF_ERR_NAME_TOO_LONG		(1 << 8) // 100
+#define REF_ERR_NO_ROOT_REF		(1 << 9)
+#define REF_ERR_NO_ROOT_BACKREF		(1 << 10)
+#define REF_ERR_DUP_ROOT_REF		(1 << 11)
+#define REF_ERR_DUP_ROOT_BACKREF	(1 << 12)
+
+struct file_extent_hole {
+	struct rb_node node;
+	u64 start;
+	u64 len;
+};
+
+#define I_ERR_NO_INODE_ITEM		(1 << 0)
+#define I_ERR_NO_ORPHAN_ITEM		(1 << 1)
+#define I_ERR_DUP_INODE_ITEM		(1 << 2)
+#define I_ERR_DUP_DIR_INDEX		(1 << 3)
+#define I_ERR_ODD_DIR_ITEM		(1 << 4)
+#define I_ERR_ODD_FILE_EXTENT		(1 << 5)
+#define I_ERR_BAD_FILE_EXTENT		(1 << 6)
+#define I_ERR_FILE_EXTENT_OVERLAP	(1 << 7)
+#define I_ERR_FILE_EXTENT_DISCOUNT	(1 << 8) // 100
+#define I_ERR_DIR_ISIZE_WRONG		(1 << 9)
+#define I_ERR_FILE_NBYTES_WRONG		(1 << 10) // 400
+#define I_ERR_ODD_CSUM_ITEM		(1 << 11)
+#define I_ERR_SOME_CSUM_MISSING		(1 << 12)
+#define I_ERR_LINK_COUNT_WRONG		(1 << 13)
+#define I_ERR_FILE_EXTENT_ORPHAN	(1 << 14)
+
+struct inode_record {
+	struct list_head backrefs;
+	unsigned int checked:1;
+	unsigned int merging:1;
+	unsigned int found_inode_item:1;
+	unsigned int found_dir_item:1;
+	unsigned int found_file_extent:1;
+	unsigned int found_csum_item:1;
+	unsigned int some_csum_missing:1;
+	unsigned int nodatasum:1;
+	int errors;
+
+	u64 ino;
+	u32 nlink;
+	u32 imode;
+	u64 isize;
+	u64 nbytes;
+
+	u32 found_link;
+	u64 found_size;
+	u64 extent_start;
+	u64 extent_end;
+	struct rb_root holes;
+	struct list_head orphan_extents;
+
+	u32 refs;
+};
+
+struct root_backref {
+	struct list_head list;
+	unsigned int found_dir_item:1;
+	unsigned int found_dir_index:1;
+	unsigned int found_back_ref:1;
+	unsigned int found_forward_ref:1;
+	unsigned int reachable:1;
+	int errors;
+	u64 ref_root;
+	u64 dir;
+	u64 index;
+	u16 namelen;
+	char name[0];
+};
+
+static inline struct root_backref* to_root_backref(struct list_head *entry)
+{
+	return list_entry(entry, struct root_backref, list);
+}
+
+struct root_record {
+	struct list_head backrefs;
+	struct cache_extent cache;
+	unsigned int found_root_item:1;
+	u64 objectid;
+	u32 found_ref;
+};
+
+struct ptr_node {
+	struct cache_extent cache;
+	void *data;
+};
+
+struct shared_node {
+	struct cache_extent cache;
+	struct cache_tree root_cache;
+	struct cache_tree inode_cache;
+	struct inode_record *current;
+	u32 refs;
+};
+
+struct block_info {
+	u64 start;
+	u32 size;
+};
+
+struct walk_control {
+	struct cache_tree shared;
+	struct shared_node *nodes[BTRFS_MAX_LEVEL];
+	int active_node;
+	int root_level;
+};
+
+struct bad_item {
+	struct btrfs_key key;
+	u64 root_id;
+	struct list_head list;
+};
+
+struct extent_entry {
+	u64 bytenr;
+	u64 bytes;
+	int count;
+	int broken;
+	struct list_head list;
+};
+
+struct root_item_info {
+	/* level of the root */
+	u8 level;
+	/* number of nodes at this level, must be 1 for a root */
+	int node_count;
+	u64 bytenr;
+	u64 gen;
+	struct cache_extent cache_extent;
+};
+
+#endif
-- 
2.15.1


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

* [PATCH 03/16] btrfs-progs: check: Move definitions of lowmem mode to check/lowmem.h
  2018-01-19  5:37 [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
  2018-01-19  5:37 ` [PATCH 01/16] btrfs-progs: Moves cmds-check.c to check/main.c Qu Wenruo
  2018-01-19  5:37 ` [PATCH 02/16] btrfs-progs: check: Move original mode definitions to check/original.h Qu Wenruo
@ 2018-01-19  5:37 ` Qu Wenruo
  2018-01-19  5:37 ` [PATCH 04/16] btrfs-progs: check: Move node_ptr structure to check/common.h Qu Wenruo
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Qu Wenruo @ 2018-01-19  5:37 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Unlike original mode, lowmem mode mostly uses normal tree operations, so
no structure definitions, only a lot of random error bits.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/lowmem.h | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 check/main.c   | 39 +-----------------------------------
 2 files changed, 63 insertions(+), 38 deletions(-)
 create mode 100644 check/lowmem.h

diff --git a/check/lowmem.h b/check/lowmem.h
new file mode 100644
index 000000000000..e6ca7634022c
--- /dev/null
+++ b/check/lowmem.h
@@ -0,0 +1,62 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+/*
+ * Defines and function declarations for lowmem mode check.
+ */
+#ifndef __BTRFS_CHECK_LOWMEM_H__
+#define __BTRFS_CHECK_LOWMEM_H__
+
+#define ROOT_DIR_ERROR		(1<<1)	/* bad ROOT_DIR */
+#define DIR_ITEM_MISSING	(1<<2)	/* DIR_ITEM not found */
+#define DIR_ITEM_MISMATCH	(1<<3)	/* DIR_ITEM found but not match */
+#define INODE_REF_MISSING	(1<<4)	/* INODE_REF/INODE_EXTREF not found */
+#define INODE_ITEM_MISSING	(1<<5)	/* INODE_ITEM not found */
+#define INODE_ITEM_MISMATCH	(1<<6)	/* INODE_ITEM found but not match */
+#define FILE_EXTENT_ERROR	(1<<7)	/* bad FILE_EXTENT */
+#define ODD_CSUM_ITEM		(1<<8)	/* CSUM_ITEM error */
+#define CSUM_ITEM_MISSING	(1<<9)	/* CSUM_ITEM not found */
+#define LINK_COUNT_ERROR	(1<<10)	/* INODE_ITEM nlink count error */
+#define NBYTES_ERROR		(1<<11)	/* INODE_ITEM nbytes count error */
+#define ISIZE_ERROR		(1<<12)	/* INODE_ITEM size count error */
+#define ORPHAN_ITEM		(1<<13) /* INODE_ITEM no reference */
+#define NO_INODE_ITEM		(1<<14) /* no inode_item */
+#define LAST_ITEM		(1<<15)	/* Complete this tree traversal */
+#define ROOT_REF_MISSING	(1<<16)	/* ROOT_REF not found */
+#define ROOT_REF_MISMATCH	(1<<17)	/* ROOT_REF found but not match */
+#define DIR_INDEX_MISSING       (1<<18) /* INODE_INDEX not found */
+#define DIR_INDEX_MISMATCH      (1<<19) /* INODE_INDEX found but not match */
+#define DIR_COUNT_AGAIN         (1<<20) /* DIR isize should be recalculated */
+#define BG_ACCOUNTING_ERROR     (1<<21) /* Block group accounting error */
+
+/*
+ * Error bit for low memory mode check.
+ *
+ * Currently no caller cares about it yet.  Just internal use for error
+ * classification.
+ */
+#define BACKREF_MISSING		(1 << 0) /* Backref missing in extent tree */
+#define BACKREF_MISMATCH	(1 << 1) /* Backref exists but does not match */
+#define BYTES_UNALIGNED		(1 << 2) /* Some bytes are not aligned */
+#define REFERENCER_MISSING	(1 << 3) /* Referencer not found */
+#define REFERENCER_MISMATCH	(1 << 4) /* Referenceer found but does not match */
+#define CROSSING_STRIPE_BOUNDARY (1 << 4) /* For kernel scrub workaround */
+#define ITEM_SIZE_MISMATCH	(1 << 5) /* Bad item size */
+#define UNKNOWN_TYPE		(1 << 6) /* Unknown type */
+#define ACCOUNTING_MISMATCH	(1 << 7) /* Used space accounting error */
+#define CHUNK_TYPE_MISMATCH	(1 << 8)
+
+#endif
diff --git a/check/main.c b/check/main.c
index c91a949ff7cc..dbd2b755c48f 100644
--- a/check/main.c
+++ b/check/main.c
@@ -44,6 +44,7 @@
 #include "hash.h"
 #include "help.h"
 #include "check/original.h"
+#include "check/lowmem.h"
 
 enum task_position {
 	TASK_EXTENTS,
@@ -85,28 +86,6 @@ enum btrfs_check_mode {
 
 static enum btrfs_check_mode check_mode = CHECK_MODE_DEFAULT;
 
-#define ROOT_DIR_ERROR		(1<<1)	/* bad ROOT_DIR */
-#define DIR_ITEM_MISSING	(1<<2)	/* DIR_ITEM not found */
-#define DIR_ITEM_MISMATCH	(1<<3)	/* DIR_ITEM found but not match */
-#define INODE_REF_MISSING	(1<<4)	/* INODE_REF/INODE_EXTREF not found */
-#define INODE_ITEM_MISSING	(1<<5)	/* INODE_ITEM not found */
-#define INODE_ITEM_MISMATCH	(1<<6)	/* INODE_ITEM found but not match */
-#define FILE_EXTENT_ERROR	(1<<7)	/* bad FILE_EXTENT */
-#define ODD_CSUM_ITEM		(1<<8)	/* CSUM_ITEM error */
-#define CSUM_ITEM_MISSING	(1<<9)	/* CSUM_ITEM not found */
-#define LINK_COUNT_ERROR	(1<<10)	/* INODE_ITEM nlink count error */
-#define NBYTES_ERROR		(1<<11)	/* INODE_ITEM nbytes count error */
-#define ISIZE_ERROR		(1<<12)	/* INODE_ITEM size count error */
-#define ORPHAN_ITEM		(1<<13) /* INODE_ITEM no reference */
-#define NO_INODE_ITEM		(1<<14) /* no inode_item */
-#define LAST_ITEM		(1<<15)	/* Complete this tree traversal */
-#define ROOT_REF_MISSING	(1<<16)	/* ROOT_REF not found */
-#define ROOT_REF_MISMATCH	(1<<17)	/* ROOT_REF found but not match */
-#define DIR_INDEX_MISSING       (1<<18) /* INODE_INDEX not found */
-#define DIR_INDEX_MISMATCH      (1<<19) /* INODE_INDEX found but not match */
-#define DIR_COUNT_AGAIN         (1<<20) /* DIR isize should be recalculated */
-#define BG_ACCOUNTING_ERROR     (1<<21) /* Block group accounting error */
-
 static int compare_data_backref(struct rb_node *node1, struct rb_node *node2)
 {
 	struct extent_backref *ext1 = rb_node_to_extent_backref(node1);
@@ -193,22 +172,6 @@ static int compare_extent_backref(struct rb_node *node1, struct rb_node *node2)
 		return compare_tree_backref(node1, node2);
 }
 
-/*
- * Error bit for low memory mode check.
- *
- * Currently no caller cares about it yet.  Just internal use for error
- * classification.
- */
-#define BACKREF_MISSING		(1 << 0) /* Backref missing in extent tree */
-#define BACKREF_MISMATCH	(1 << 1) /* Backref exists but does not match */
-#define BYTES_UNALIGNED		(1 << 2) /* Some bytes are not aligned */
-#define REFERENCER_MISSING	(1 << 3) /* Referencer not found */
-#define REFERENCER_MISMATCH	(1 << 4) /* Referenceer found but does not match */
-#define CROSSING_STRIPE_BOUNDARY (1 << 4) /* For kernel scrub workaround */
-#define ITEM_SIZE_MISMATCH	(1 << 5) /* Bad item size */
-#define UNKNOWN_TYPE		(1 << 6) /* Unknown type */
-#define ACCOUNTING_MISMATCH	(1 << 7) /* Used space accounting error */
-#define CHUNK_TYPE_MISMATCH	(1 << 8)
 
 static void *print_status_check(void *p)
 {
-- 
2.15.1


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

* [PATCH 04/16] btrfs-progs: check: Move node_ptr structure to check/common.h
  2018-01-19  5:37 [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
                   ` (2 preceding siblings ...)
  2018-01-19  5:37 ` [PATCH 03/16] btrfs-progs: check: Move definitions of lowmem mode to check/lowmem.h Qu Wenruo
@ 2018-01-19  5:37 ` Qu Wenruo
  2018-01-19  5:52   ` Su Yue
  2018-01-19  5:37 ` [PATCH 05/16] btrfs-progs: check: Export check global variables " Qu Wenruo
                   ` (12 subsequent siblings)
  16 siblings, 1 reply; 24+ messages in thread
From: Qu Wenruo @ 2018-01-19  5:37 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/common.h | 39 +++++++++++++++++++++++++++++++++++++++
 check/main.c   | 11 +----------
 2 files changed, 40 insertions(+), 10 deletions(-)
 create mode 100644 check/common.h

diff --git a/check/common.h b/check/common.h
new file mode 100644
index 000000000000..25874aec597b
--- /dev/null
+++ b/check/common.h
@@ -0,0 +1,39 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+/*
+ * Defines and function declarations for code shared by both lowmem and
+ * original mode
+ */
+#ifndef __BTRFS_CHECK_COMMON_H__
+#define __BTRFS_CHECK_COMMON_H__
+#include "ctree.h"
+
+/*
+ * Use for tree walk to walk through trees whose leaves/nodes can be shared
+ * between different trees. (Namely subvolume/fs trees)
+ */
+struct node_refs {
+	u64 bytenr[BTRFS_MAX_LEVEL];
+	u64 refs[BTRFS_MAX_LEVEL];
+	int need_check[BTRFS_MAX_LEVEL];
+	/* field for checking all trees */
+	int checked[BTRFS_MAX_LEVEL];
+	/* the corresponding extent should be marked as full backref or not */
+	int full_backref[BTRFS_MAX_LEVEL];
+};
+
+#endif
diff --git a/check/main.c b/check/main.c
index dbd2b755c48f..fbd73c42bee8 100644
--- a/check/main.c
+++ b/check/main.c
@@ -45,6 +45,7 @@
 #include "help.h"
 #include "check/original.h"
 #include "check/lowmem.h"
+#include "check/common.h"
 
 enum task_position {
 	TASK_EXTENTS,
@@ -1667,16 +1668,6 @@ static int process_one_leaf(struct btrfs_root *root, struct extent_buffer *eb,
 	return ret;
 }
 
-struct node_refs {
-	u64 bytenr[BTRFS_MAX_LEVEL];
-	u64 refs[BTRFS_MAX_LEVEL];
-	int need_check[BTRFS_MAX_LEVEL];
-	/* field for checking all trees */
-	int checked[BTRFS_MAX_LEVEL];
-	/* the corresponding extent should be marked as full backref or not */
-	int full_backref[BTRFS_MAX_LEVEL];
-};
-
 static int update_nodes_refs(struct btrfs_root *root, u64 bytenr,
 			     struct extent_buffer *eb, struct node_refs *nrefs,
 			     u64 level, int check_all);
-- 
2.15.1


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

* [PATCH 05/16] btrfs-progs: check: Export check global variables to check/common.h
  2018-01-19  5:37 [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
                   ` (3 preceding siblings ...)
  2018-01-19  5:37 ` [PATCH 04/16] btrfs-progs: check: Move node_ptr structure to check/common.h Qu Wenruo
@ 2018-01-19  5:37 ` Qu Wenruo
  2018-01-19  6:55   ` Su Yue
  2018-01-19  5:37 ` [PATCH 06/16] btrfs-progs: check: Move imode_to_type function " Qu Wenruo
                   ` (11 subsequent siblings)
  16 siblings, 1 reply; 24+ messages in thread
From: Qu Wenruo @ 2018-01-19  5:37 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

There are a dozen of variables which are used as "check global"
variables, like @total_csum_bytes or @no_holes.

These variables are used freely across the check code, however since
we're splitting check code, they need to be exported so they can be used
in other files.

This patch just export them and add declarations for them in
check/common.h.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/common.h | 17 +++++++++++++++++
 check/main.c   | 32 ++++++++++++++++----------------
 2 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/check/common.h b/check/common.h
index 25874aec597b..8d93ddbf4afb 100644
--- a/check/common.h
+++ b/check/common.h
@@ -36,4 +36,21 @@ struct node_refs {
 	int full_backref[BTRFS_MAX_LEVEL];
 };
 
+extern u64 bytes_used;
+extern u64 total_csum_bytes;
+extern u64 total_btree_bytes;
+extern u64 total_fs_tree_bytes;
+extern u64 total_extent_tree_bytes;
+extern u64 btree_space_waste;
+extern u64 data_bytes_allocated;
+extern u64 data_bytes_referenced;
+extern struct list_head duplicate_extents;
+extern struct list_head delete_items;
+extern int no_holes;
+extern int init_extent_tree;
+extern int check_data_csum;
+extern struct btrfs_fs_info *global_info;
+extern struct task_ctx ctx;
+extern struct cache_tree *roots_info_cache;
+
 #endif
diff --git a/check/main.c b/check/main.c
index fbd73c42bee8..bb927ecc87ee 100644
--- a/check/main.c
+++ b/check/main.c
@@ -61,22 +61,22 @@ struct task_ctx {
 	struct task_info *info;
 };
 
-static u64 bytes_used = 0;
-static u64 total_csum_bytes = 0;
-static u64 total_btree_bytes = 0;
-static u64 total_fs_tree_bytes = 0;
-static u64 total_extent_tree_bytes = 0;
-static u64 btree_space_waste = 0;
-static u64 data_bytes_allocated = 0;
-static u64 data_bytes_referenced = 0;
-static LIST_HEAD(duplicate_extents);
-static LIST_HEAD(delete_items);
-static int no_holes = 0;
-static int init_extent_tree = 0;
-static int check_data_csum = 0;
-static struct btrfs_fs_info *global_info;
-static struct task_ctx ctx = { 0 };
-static struct cache_tree *roots_info_cache = NULL;
+u64 bytes_used = 0;
+u64 total_csum_bytes = 0;
+u64 total_btree_bytes = 0;
+u64 total_fs_tree_bytes = 0;
+u64 total_extent_tree_bytes = 0;
+u64 btree_space_waste = 0;
+u64 data_bytes_allocated = 0;
+u64 data_bytes_referenced = 0;
+LIST_HEAD(duplicate_extents);
+LIST_HEAD(delete_items);
+int no_holes = 0;
+int init_extent_tree = 0;
+int check_data_csum = 0;
+struct btrfs_fs_info *global_info;
+struct task_ctx ctx = { 0 };
+struct cache_tree *roots_info_cache = NULL;
 
 enum btrfs_check_mode {
 	CHECK_MODE_ORIGINAL,
-- 
2.15.1


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

* [PATCH 06/16] btrfs-progs: check: Move imode_to_type function to check/common.h
  2018-01-19  5:37 [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
                   ` (4 preceding siblings ...)
  2018-01-19  5:37 ` [PATCH 05/16] btrfs-progs: check: Export check global variables " Qu Wenruo
@ 2018-01-19  5:37 ` Qu Wenruo
  2018-01-19  5:37 ` [PATCH 07/16] btrfs-progs: check: Move fs_root_objectid " Qu Wenruo
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Qu Wenruo @ 2018-01-19  5:37 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

This function is shared between original and lowmem mode, and it's small
enough, so move it to check/common.h.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/common.h | 19 +++++++++++++++++++
 check/main.c   | 17 -----------------
 2 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/check/common.h b/check/common.h
index 8d93ddbf4afb..3e0a5ebee54b 100644
--- a/check/common.h
+++ b/check/common.h
@@ -20,6 +20,8 @@
  */
 #ifndef __BTRFS_CHECK_COMMON_H__
 #define __BTRFS_CHECK_COMMON_H__
+
+#include <sys/stat.h>
 #include "ctree.h"
 
 /*
@@ -53,4 +55,21 @@ extern struct btrfs_fs_info *global_info;
 extern struct task_ctx ctx;
 extern struct cache_tree *roots_info_cache;
 
+static inline u8 imode_to_type(u32 imode)
+{
+#define S_SHIFT 12
+	static unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = {
+		[S_IFREG >> S_SHIFT]	= BTRFS_FT_REG_FILE,
+		[S_IFDIR >> S_SHIFT]	= BTRFS_FT_DIR,
+		[S_IFCHR >> S_SHIFT]	= BTRFS_FT_CHRDEV,
+		[S_IFBLK >> S_SHIFT]	= BTRFS_FT_BLKDEV,
+		[S_IFIFO >> S_SHIFT]	= BTRFS_FT_FIFO,
+		[S_IFSOCK >> S_SHIFT]	= BTRFS_FT_SOCK,
+		[S_IFLNK >> S_SHIFT]	= BTRFS_FT_SYMLINK,
+	};
+
+	return btrfs_type_by_mode[(imode & S_IFMT) >> S_SHIFT];
+#undef S_SHIFT
+}
+
 #endif
diff --git a/check/main.c b/check/main.c
index bb927ecc87ee..eaa8e7fbde20 100644
--- a/check/main.c
+++ b/check/main.c
@@ -425,23 +425,6 @@ static void record_root_in_trans(struct btrfs_trans_handle *trans,
 	}
 }
 
-static u8 imode_to_type(u32 imode)
-{
-#define S_SHIFT 12
-	static unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = {
-		[S_IFREG >> S_SHIFT]	= BTRFS_FT_REG_FILE,
-		[S_IFDIR >> S_SHIFT]	= BTRFS_FT_DIR,
-		[S_IFCHR >> S_SHIFT]	= BTRFS_FT_CHRDEV,
-		[S_IFBLK >> S_SHIFT]	= BTRFS_FT_BLKDEV,
-		[S_IFIFO >> S_SHIFT]	= BTRFS_FT_FIFO,
-		[S_IFSOCK >> S_SHIFT]	= BTRFS_FT_SOCK,
-		[S_IFLNK >> S_SHIFT]	= BTRFS_FT_SYMLINK,
-	};
-
-	return btrfs_type_by_mode[(imode & S_IFMT) >> S_SHIFT];
-#undef S_SHIFT
-}
-
 static int device_record_compare(struct rb_node *node1, struct rb_node *node2)
 {
 	struct device_record *rec1;
-- 
2.15.1


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

* [PATCH 07/16] btrfs-progs: check: Move fs_root_objectid function to check/common.h
  2018-01-19  5:37 [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
                   ` (5 preceding siblings ...)
  2018-01-19  5:37 ` [PATCH 06/16] btrfs-progs: check: Move imode_to_type function " Qu Wenruo
@ 2018-01-19  5:37 ` Qu Wenruo
  2018-01-19  5:37 ` [PATCH 08/16] btrfs-progs: check: Move count_csum_range function to check/common.c Qu Wenruo
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Qu Wenruo @ 2018-01-19  5:37 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Just another small wrapper shared between original and lowmem mode.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/common.h |  8 ++++++++
 check/main.c   | 10 ----------
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/check/common.h b/check/common.h
index 3e0a5ebee54b..77a0ab54166f 100644
--- a/check/common.h
+++ b/check/common.h
@@ -72,4 +72,12 @@ static inline u8 imode_to_type(u32 imode)
 #undef S_SHIFT
 }
 
+static inline int fs_root_objectid(u64 objectid)
+{
+	if (objectid == BTRFS_TREE_RELOC_OBJECTID ||
+	    objectid == BTRFS_DATA_RELOC_TREE_OBJECTID)
+		return 1;
+	return is_fstree(objectid);
+}
+
 #endif
diff --git a/check/main.c b/check/main.c
index eaa8e7fbde20..9ecbac8f19c3 100644
--- a/check/main.c
+++ b/check/main.c
@@ -2167,8 +2167,6 @@ out:
 	return err;
 }
 
-static int fs_root_objectid(u64 objectid);
-
 /*
  * Update global fs information.
  */
@@ -4250,14 +4248,6 @@ skip_walking:
 	return ret;
 }
 
-static int fs_root_objectid(u64 objectid)
-{
-	if (objectid == BTRFS_TREE_RELOC_OBJECTID ||
-	    objectid == BTRFS_DATA_RELOC_TREE_OBJECTID)
-		return 1;
-	return is_fstree(objectid);
-}
-
 static int check_fs_roots(struct btrfs_fs_info *fs_info,
 			  struct cache_tree *root_cache)
 {
-- 
2.15.1


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

* [PATCH 08/16] btrfs-progs: check: Move count_csum_range function to check/common.c
  2018-01-19  5:37 [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
                   ` (6 preceding siblings ...)
  2018-01-19  5:37 ` [PATCH 07/16] btrfs-progs: check: Move fs_root_objectid " Qu Wenruo
@ 2018-01-19  5:37 ` Qu Wenruo
  2018-01-19  6:46   ` Su Yue
  2018-01-19  5:37 ` [PATCH 09/16] btrfs-progs: check: Move __create_inode_item " Qu Wenruo
                   ` (8 subsequent siblings)
  16 siblings, 1 reply; 24+ messages in thread
From: Qu Wenruo @ 2018-01-19  5:37 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Despite of moving it to check/common.c, also:

1) Add extra comment of the function
2) Change @root paramter to @fs_info
   Since @root is never used, csum_root is picked from fs_info anyway.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 Makefile       |   2 +-
 check/common.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 check/common.h |   3 ++
 check/main.c   |  77 ++-----------------------------------------
 4 files changed, 108 insertions(+), 75 deletions(-)
 create mode 100644 check/common.c

diff --git a/Makefile b/Makefile
index c4e2dc5b68a9..a00a982a18df 100644
--- a/Makefile
+++ b/Makefile
@@ -113,7 +113,7 @@ cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
 	       cmds-restore.o cmds-rescue.o chunk-recover.o super-recover.o \
 	       cmds-property.o cmds-fi-usage.o cmds-inspect-dump-tree.o \
 	       cmds-inspect-dump-super.o cmds-inspect-tree-stats.o cmds-fi-du.o \
-	       mkfs/common.o
+	       mkfs/common.o check/common.o
 libbtrfs_objects = send-stream.o send-utils.o kernel-lib/rbtree.o btrfs-list.o \
 		   kernel-lib/crc32c.o messages.o \
 		   uuid-tree.o utils-lib.o rbtree-utils.o
diff --git a/check/common.c b/check/common.c
new file mode 100644
index 000000000000..ed4f2a40bac2
--- /dev/null
+++ b/check/common.c
@@ -0,0 +1,101 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+#include "ctree.h"
+#include "internal.h"
+#include "check/common.h"
+
+/*
+ * Search in csum tree to find how many bytes of range [@start, @start + @len)
+ * has the corresponding csum item.
+ *
+ * @start:	range start
+ * @len:	range length
+ * @found:	return value of found csum bytes
+ *		unit is BYTE.
+ */
+int count_csum_range(struct btrfs_fs_info *fs_info, u64 start,
+		     u64 len, u64 *found)
+{
+	struct btrfs_key key;
+	struct btrfs_path path;
+	struct extent_buffer *leaf;
+	int ret;
+	size_t size;
+	*found = 0;
+	u64 csum_end;
+	u16 csum_size = btrfs_super_csum_size(fs_info->super_copy);
+
+	btrfs_init_path(&path);
+
+	key.objectid = BTRFS_EXTENT_CSUM_OBJECTID;
+	key.offset = start;
+	key.type = BTRFS_EXTENT_CSUM_KEY;
+
+	ret = btrfs_search_slot(NULL, fs_info->csum_root,
+				&key, &path, 0, 0);
+	if (ret < 0)
+		goto out;
+	if (ret > 0 && path.slots[0] > 0) {
+		leaf = path.nodes[0];
+		btrfs_item_key_to_cpu(leaf, &key, path.slots[0] - 1);
+		if (key.objectid == BTRFS_EXTENT_CSUM_OBJECTID &&
+		    key.type == BTRFS_EXTENT_CSUM_KEY)
+			path.slots[0]--;
+	}
+
+	while (len > 0) {
+		leaf = path.nodes[0];
+		if (path.slots[0] >= btrfs_header_nritems(leaf)) {
+			ret = btrfs_next_leaf(fs_info->csum_root, &path);
+			if (ret > 0)
+				break;
+			else if (ret < 0)
+				goto out;
+			leaf = path.nodes[0];
+		}
+
+		btrfs_item_key_to_cpu(leaf, &key, path.slots[0]);
+		if (key.objectid != BTRFS_EXTENT_CSUM_OBJECTID ||
+		    key.type != BTRFS_EXTENT_CSUM_KEY)
+			break;
+
+		btrfs_item_key_to_cpu(leaf, &key, path.slots[0]);
+		if (key.offset >= start + len)
+			break;
+
+		if (key.offset > start)
+			start = key.offset;
+
+		size = btrfs_item_size_nr(leaf, path.slots[0]);
+		csum_end = key.offset + (size / csum_size) *
+			   fs_info->sectorsize;
+		if (csum_end > start) {
+			size = min(csum_end - start, len);
+			len -= size;
+			start += size;
+			*found += size;
+		}
+
+		path.slots[0]++;
+	}
+out:
+	btrfs_release_path(&path);
+	if (ret < 0)
+		return ret;
+	return 0;
+}
+
diff --git a/check/common.h b/check/common.h
index 77a0ab54166f..cd64798f4804 100644
--- a/check/common.h
+++ b/check/common.h
@@ -80,4 +80,7 @@ static inline int fs_root_objectid(u64 objectid)
 	return is_fstree(objectid);
 }
 
+int count_csum_range(struct btrfs_fs_info *fs_info, u64 start,
+		     u64 len, u64 *found);
+
 #endif
diff --git a/check/main.c b/check/main.c
index 9ecbac8f19c3..b891f4815d30 100644
--- a/check/main.c
+++ b/check/main.c
@@ -1423,78 +1423,6 @@ static int process_inode_extref(struct extent_buffer *eb,
 
 }
 
-static int count_csum_range(struct btrfs_root *root, u64 start,
-			    u64 len, u64 *found)
-{
-	struct btrfs_key key;
-	struct btrfs_path path;
-	struct extent_buffer *leaf;
-	int ret;
-	size_t size;
-	*found = 0;
-	u64 csum_end;
-	u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
-
-	btrfs_init_path(&path);
-
-	key.objectid = BTRFS_EXTENT_CSUM_OBJECTID;
-	key.offset = start;
-	key.type = BTRFS_EXTENT_CSUM_KEY;
-
-	ret = btrfs_search_slot(NULL, root->fs_info->csum_root,
-				&key, &path, 0, 0);
-	if (ret < 0)
-		goto out;
-	if (ret > 0 && path.slots[0] > 0) {
-		leaf = path.nodes[0];
-		btrfs_item_key_to_cpu(leaf, &key, path.slots[0] - 1);
-		if (key.objectid == BTRFS_EXTENT_CSUM_OBJECTID &&
-		    key.type == BTRFS_EXTENT_CSUM_KEY)
-			path.slots[0]--;
-	}
-
-	while (len > 0) {
-		leaf = path.nodes[0];
-		if (path.slots[0] >= btrfs_header_nritems(leaf)) {
-			ret = btrfs_next_leaf(root->fs_info->csum_root, &path);
-			if (ret > 0)
-				break;
-			else if (ret < 0)
-				goto out;
-			leaf = path.nodes[0];
-		}
-
-		btrfs_item_key_to_cpu(leaf, &key, path.slots[0]);
-		if (key.objectid != BTRFS_EXTENT_CSUM_OBJECTID ||
-		    key.type != BTRFS_EXTENT_CSUM_KEY)
-			break;
-
-		btrfs_item_key_to_cpu(leaf, &key, path.slots[0]);
-		if (key.offset >= start + len)
-			break;
-
-		if (key.offset > start)
-			start = key.offset;
-
-		size = btrfs_item_size_nr(leaf, path.slots[0]);
-		csum_end = key.offset + (size / csum_size) *
-			   root->fs_info->sectorsize;
-		if (csum_end > start) {
-			size = min(csum_end - start, len);
-			len -= size;
-			start += size;
-			*found += size;
-		}
-
-		path.slots[0]++;
-	}
-out:
-	btrfs_release_path(&path);
-	if (ret < 0)
-		return ret;
-	return 0;
-}
-
 static int process_file_extent(struct btrfs_root *root,
 				struct extent_buffer *eb,
 				int slot, struct btrfs_key *key,
@@ -1574,7 +1502,8 @@ static int process_file_extent(struct btrfs_root *root,
 		else
 			disk_bytenr += extent_offset;
 
-		ret = count_csum_range(root, disk_bytenr, num_bytes, &found);
+		ret = count_csum_range(root->fs_info, disk_bytenr, num_bytes,
+				       &found);
 		if (ret < 0)
 			return ret;
 		if (extent_type == BTRFS_FILE_EXTENT_REG) {
@@ -5508,7 +5437,7 @@ 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, 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",
-- 
2.15.1


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

* [PATCH 09/16] btrfs-progs: check: Move __create_inode_item function to check/common.c
  2018-01-19  5:37 [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
                   ` (7 preceding siblings ...)
  2018-01-19  5:37 ` [PATCH 08/16] btrfs-progs: check: Move count_csum_range function to check/common.c Qu Wenruo
@ 2018-01-19  5:37 ` Qu Wenruo
  2018-01-19  5:37 ` [PATCH 10/16] btrfs-progs: check: Move link_inode_to_lostfound function to common.c Qu Wenruo
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Qu Wenruo @ 2018-01-19  5:37 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Move __create_inode_item() function to check/common.c and rename it to
insert_inode_item(), with comment added.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/common.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 check/common.h |  3 +++
 check/main.c   | 36 ++----------------------------------
 3 files changed, 50 insertions(+), 34 deletions(-)

diff --git a/check/common.c b/check/common.c
index ed4f2a40bac2..6a7d86dfd8f7 100644
--- a/check/common.c
+++ b/check/common.c
@@ -14,8 +14,11 @@
  * Boston, MA 021110-1307, USA.
  */
 
+#include <time.h>
 #include "ctree.h"
 #include "internal.h"
+#include "messages.h"
+#include "transaction.h"
 #include "check/common.h"
 
 /*
@@ -99,3 +102,45 @@ out:
 	return 0;
 }
 
+/*
+ * Wrapper to insert one inode item into given @root
+ * Timestamp will be set to current time.
+ *
+ * @root:	the root to insert inode item into
+ * @ino:	inode number
+ * @size:	inode size
+ * @nbytes:	nbytes (real used size, without hole)
+ * @nlink:	number of links
+ * @mode:	file mode, including S_IF* bits
+ */
+int insert_inode_item(struct btrfs_trans_handle *trans,
+		      struct btrfs_root *root, u64 ino, u64 size,
+		      u64 nbytes, u64 nlink, u32 mode)
+{
+	struct btrfs_inode_item ii;
+	time_t now = time(NULL);
+	int ret;
+
+	btrfs_set_stack_inode_size(&ii, size);
+	btrfs_set_stack_inode_nbytes(&ii, nbytes);
+	btrfs_set_stack_inode_nlink(&ii, nlink);
+	btrfs_set_stack_inode_mode(&ii, mode);
+	btrfs_set_stack_inode_generation(&ii, trans->transid);
+	btrfs_set_stack_timespec_nsec(&ii.atime, 0);
+	btrfs_set_stack_timespec_sec(&ii.ctime, now);
+	btrfs_set_stack_timespec_nsec(&ii.ctime, 0);
+	btrfs_set_stack_timespec_sec(&ii.mtime, now);
+	btrfs_set_stack_timespec_nsec(&ii.mtime, 0);
+	btrfs_set_stack_timespec_sec(&ii.otime, 0);
+	btrfs_set_stack_timespec_nsec(&ii.otime, 0);
+
+	ret = btrfs_insert_inode(trans, root, ino, &ii);
+	ASSERT(!ret);
+
+	warning("root %llu inode %llu recreating inode item, this may "
+		"be incomplete, please check permissions and content after "
+		"the fsck completes.\n", (unsigned long long)root->objectid,
+		(unsigned long long)ino);
+
+	return 0;
+}
diff --git a/check/common.h b/check/common.h
index cd64798f4804..efab05ad6b68 100644
--- a/check/common.h
+++ b/check/common.h
@@ -82,5 +82,8 @@ static inline int fs_root_objectid(u64 objectid)
 
 int count_csum_range(struct btrfs_fs_info *fs_info, u64 start,
 		     u64 len, u64 *found);
+int insert_inode_item(struct btrfs_trans_handle *trans,
+		      struct btrfs_root *root, u64 ino, u64 size,
+		      u64 nbytes, u64 nlink, u32 mode);
 
 #endif
diff --git a/check/main.c b/check/main.c
index b891f4815d30..e594b5986a47 100644
--- a/check/main.c
+++ b/check/main.c
@@ -2691,45 +2691,13 @@ static int delete_dir_index(struct btrfs_root *root,
 	return ret;
 }
 
-static int __create_inode_item(struct btrfs_trans_handle *trans,
-			       struct btrfs_root *root, u64 ino, u64 size,
-			       u64 nbytes, u64 nlink, u32 mode)
-{
-	struct btrfs_inode_item ii;
-	time_t now = time(NULL);
-	int ret;
-
-	btrfs_set_stack_inode_size(&ii, size);
-	btrfs_set_stack_inode_nbytes(&ii, nbytes);
-	btrfs_set_stack_inode_nlink(&ii, nlink);
-	btrfs_set_stack_inode_mode(&ii, mode);
-	btrfs_set_stack_inode_generation(&ii, trans->transid);
-	btrfs_set_stack_timespec_nsec(&ii.atime, 0);
-	btrfs_set_stack_timespec_sec(&ii.ctime, now);
-	btrfs_set_stack_timespec_nsec(&ii.ctime, 0);
-	btrfs_set_stack_timespec_sec(&ii.mtime, now);
-	btrfs_set_stack_timespec_nsec(&ii.mtime, 0);
-	btrfs_set_stack_timespec_sec(&ii.otime, 0);
-	btrfs_set_stack_timespec_nsec(&ii.otime, 0);
-
-	ret = btrfs_insert_inode(trans, root, ino, &ii);
-	ASSERT(!ret);
-
-	warning("root %llu inode %llu recreating inode item, this may "
-		"be incomplete, please check permissions and content after "
-		"the fsck completes.\n", (unsigned long long)root->objectid,
-		(unsigned long long)ino);
-
-	return 0;
-}
-
 static int create_inode_item_lowmem(struct btrfs_trans_handle *trans,
 				    struct btrfs_root *root, u64 ino,
 				    u8 filetype)
 {
 	u32 mode = (filetype == BTRFS_FT_DIR ? S_IFDIR : S_IFREG) | 0755;
 
-	return __create_inode_item(trans, root, ino, 0, 0, 0, mode);
+	return insert_inode_item(trans, root, ino, 0, 0, 0, mode);
 }
 
 static int create_inode_item(struct btrfs_root *root,
@@ -2762,7 +2730,7 @@ static int create_inode_item(struct btrfs_root *root,
 		mode =  S_IFREG | 0755;
 	}
 
-	ret = __create_inode_item(trans, root, rec->ino, size, rec->nbytes,
+	ret = insert_inode_item(trans, root, rec->ino, size, rec->nbytes,
 				  nlink, mode);
 	btrfs_commit_transaction(trans, root);
 	return 0;
-- 
2.15.1


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

* [PATCH 10/16] btrfs-progs: check: Move link_inode_to_lostfound function to common.c
  2018-01-19  5:37 [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
                   ` (8 preceding siblings ...)
  2018-01-19  5:37 ` [PATCH 09/16] btrfs-progs: check: Move __create_inode_item " Qu Wenruo
@ 2018-01-19  5:37 ` Qu Wenruo
  2018-01-19  5:37 ` [PATCH 11/16] btrfs-progs: check: Move check_dev_size_alignment to check/common.c Qu Wenruo
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Qu Wenruo @ 2018-01-19  5:37 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/common.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 check/common.h |  5 ++++
 check/main.c   | 92 ---------------------------------------------------------
 3 files changed, 98 insertions(+), 92 deletions(-)

diff --git a/check/common.c b/check/common.c
index 6a7d86dfd8f7..9051936a61cb 100644
--- a/check/common.c
+++ b/check/common.c
@@ -19,6 +19,7 @@
 #include "internal.h"
 #include "messages.h"
 #include "transaction.h"
+#include "utils.h"
 #include "check/common.h"
 
 /*
@@ -144,3 +145,95 @@ int insert_inode_item(struct btrfs_trans_handle *trans,
 
 	return 0;
 }
+
+static int get_highest_inode(struct btrfs_trans_handle *trans,
+			     struct btrfs_root *root, struct btrfs_path *path,
+			     u64 *highest_ino)
+{
+	struct btrfs_key key, found_key;
+	int ret;
+
+	btrfs_init_path(path);
+	key.objectid = BTRFS_LAST_FREE_OBJECTID;
+	key.offset = -1;
+	key.type = BTRFS_INODE_ITEM_KEY;
+	ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
+	if (ret == 1) {
+		btrfs_item_key_to_cpu(path->nodes[0], &found_key,
+				path->slots[0] - 1);
+		*highest_ino = found_key.objectid;
+		ret = 0;
+	}
+	if (*highest_ino >= BTRFS_LAST_FREE_OBJECTID)
+		ret = -EOVERFLOW;
+	btrfs_release_path(path);
+	return ret;
+}
+
+/*
+ * Link inode to dir 'lost+found'. Increase @ref_count.
+ *
+ * Returns 0 means success.
+ * Returns <0 means failure.
+ */
+int link_inode_to_lostfound(struct btrfs_trans_handle *trans,
+			    struct btrfs_root *root,
+			    struct btrfs_path *path,
+			    u64 ino, char *namebuf, u32 name_len,
+			    u8 filetype, u64 *ref_count)
+{
+	char *dir_name = "lost+found";
+	u64 lost_found_ino;
+	int ret;
+	u32 mode = 0700;
+
+	btrfs_release_path(path);
+	ret = get_highest_inode(trans, root, path, &lost_found_ino);
+	if (ret < 0)
+		goto out;
+	lost_found_ino++;
+
+	ret = btrfs_mkdir(trans, root, dir_name, strlen(dir_name),
+			  BTRFS_FIRST_FREE_OBJECTID, &lost_found_ino,
+			  mode);
+	if (ret < 0) {
+		error("failed to create '%s' dir: %s", dir_name, strerror(-ret));
+		goto out;
+	}
+	ret = btrfs_add_link(trans, root, ino, lost_found_ino,
+			     namebuf, name_len, filetype, NULL, 1, 0);
+	/*
+	 * Add ".INO" suffix several times to handle case where
+	 * "FILENAME.INO" is already taken by another file.
+	 */
+	while (ret == -EEXIST) {
+		/*
+		 * Conflicting file name, add ".INO" as suffix * +1 for '.'
+		 */
+		if (name_len + count_digits(ino) + 1 > BTRFS_NAME_LEN) {
+			ret = -EFBIG;
+			goto out;
+		}
+		snprintf(namebuf + name_len, BTRFS_NAME_LEN - name_len,
+			 ".%llu", ino);
+		name_len += count_digits(ino) + 1;
+		ret = btrfs_add_link(trans, root, ino, lost_found_ino, namebuf,
+				     name_len, filetype, NULL, 1, 0);
+	}
+	if (ret < 0) {
+		error("failed to link the inode %llu to %s dir: %s",
+		      ino, dir_name, strerror(-ret));
+		goto out;
+	}
+
+	++*ref_count;
+	printf("Moving file '%.*s' to '%s' dir since it has no valid backref\n",
+	       name_len, namebuf, dir_name);
+out:
+	btrfs_release_path(path);
+	if (ret)
+		error("failed to move file '%.*s' to '%s' dir", name_len,
+				namebuf, dir_name);
+	return ret;
+}
+
diff --git a/check/common.h b/check/common.h
index efab05ad6b68..9a3488ae365a 100644
--- a/check/common.h
+++ b/check/common.h
@@ -85,5 +85,10 @@ int count_csum_range(struct btrfs_fs_info *fs_info, u64 start,
 int insert_inode_item(struct btrfs_trans_handle *trans,
 		      struct btrfs_root *root, u64 ino, u64 size,
 		      u64 nbytes, u64 nlink, u32 mode);
+int link_inode_to_lostfound(struct btrfs_trans_handle *trans,
+			    struct btrfs_root *root,
+			    struct btrfs_path *path,
+			    u64 ino, char *namebuf, u32 name_len,
+			    u8 filetype, u64 *ref_count);
 
 #endif
diff --git a/check/main.c b/check/main.c
index e594b5986a47..0da25c460336 100644
--- a/check/main.c
+++ b/check/main.c
@@ -2960,98 +2960,6 @@ out:
 	return ret;
 }
 
-static int get_highest_inode(struct btrfs_trans_handle *trans,
-				struct btrfs_root *root,
-				struct btrfs_path *path,
-				u64 *highest_ino)
-{
-	struct btrfs_key key, found_key;
-	int ret;
-
-	btrfs_init_path(path);
-	key.objectid = BTRFS_LAST_FREE_OBJECTID;
-	key.offset = -1;
-	key.type = BTRFS_INODE_ITEM_KEY;
-	ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
-	if (ret == 1) {
-		btrfs_item_key_to_cpu(path->nodes[0], &found_key,
-				path->slots[0] - 1);
-		*highest_ino = found_key.objectid;
-		ret = 0;
-	}
-	if (*highest_ino >= BTRFS_LAST_FREE_OBJECTID)
-		ret = -EOVERFLOW;
-	btrfs_release_path(path);
-	return ret;
-}
-
-/*
- * Link inode to dir 'lost+found'. Increase @ref_count.
- *
- * Returns 0 means success.
- * Returns <0 means failure.
- */
-static int link_inode_to_lostfound(struct btrfs_trans_handle *trans,
-				   struct btrfs_root *root,
-				   struct btrfs_path *path,
-				   u64 ino, char *namebuf, u32 name_len,
-				   u8 filetype, u64 *ref_count)
-{
-	char *dir_name = "lost+found";
-	u64 lost_found_ino;
-	int ret;
-	u32 mode = 0700;
-
-	btrfs_release_path(path);
-	ret = get_highest_inode(trans, root, path, &lost_found_ino);
-	if (ret < 0)
-		goto out;
-	lost_found_ino++;
-
-	ret = btrfs_mkdir(trans, root, dir_name, strlen(dir_name),
-			  BTRFS_FIRST_FREE_OBJECTID, &lost_found_ino,
-			  mode);
-	if (ret < 0) {
-		error("failed to create '%s' dir: %s", dir_name, strerror(-ret));
-		goto out;
-	}
-	ret = btrfs_add_link(trans, root, ino, lost_found_ino,
-			     namebuf, name_len, filetype, NULL, 1, 0);
-	/*
-	 * Add ".INO" suffix several times to handle case where
-	 * "FILENAME.INO" is already taken by another file.
-	 */
-	while (ret == -EEXIST) {
-		/*
-		 * Conflicting file name, add ".INO" as suffix * +1 for '.'
-		 */
-		if (name_len + count_digits(ino) + 1 > BTRFS_NAME_LEN) {
-			ret = -EFBIG;
-			goto out;
-		}
-		snprintf(namebuf + name_len, BTRFS_NAME_LEN - name_len,
-			 ".%llu", ino);
-		name_len += count_digits(ino) + 1;
-		ret = btrfs_add_link(trans, root, ino, lost_found_ino, namebuf,
-				     name_len, filetype, NULL, 1, 0);
-	}
-	if (ret < 0) {
-		error("failed to link the inode %llu to %s dir: %s",
-		      ino, dir_name, strerror(-ret));
-		goto out;
-	}
-
-	++*ref_count;
-	printf("Moving file '%.*s' to '%s' dir since it has no valid backref\n",
-	       name_len, namebuf, dir_name);
-out:
-	btrfs_release_path(path);
-	if (ret)
-		error("failed to move file '%.*s' to '%s' dir", name_len,
-				namebuf, dir_name);
-	return ret;
-}
-
 static int repair_inode_nlinks(struct btrfs_trans_handle *trans,
 			       struct btrfs_root *root,
 			       struct btrfs_path *path,
-- 
2.15.1


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

* [PATCH 11/16] btrfs-progs: check: Move check_dev_size_alignment to check/common.c
  2018-01-19  5:37 [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
                   ` (9 preceding siblings ...)
  2018-01-19  5:37 ` [PATCH 10/16] btrfs-progs: check: Move link_inode_to_lostfound function to common.c Qu Wenruo
@ 2018-01-19  5:37 ` Qu Wenruo
  2018-01-19  5:37 ` [PATCH 12/16] btrfs-progs: check: move reada_walk_down " Qu Wenruo
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Qu Wenruo @ 2018-01-19  5:37 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/common.c | 15 +++++++++++++++
 check/common.h |  1 +
 check/main.c   | 16 ----------------
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/check/common.c b/check/common.c
index 9051936a61cb..7392ed6b472f 100644
--- a/check/common.c
+++ b/check/common.c
@@ -237,3 +237,18 @@ out:
 	return ret;
 }
 
+/*
+ * Extra (optional) check for dev_item size to report possbile problem on a new
+ * kernel.
+ */
+void check_dev_size_alignment(u64 devid, u64 total_bytes, u32 sectorsize)
+{
+	if (!IS_ALIGNED(total_bytes, sectorsize)) {
+		warning(
+"unaligned total_bytes detected for devid %llu, have %llu should be aligned to %u",
+			devid, total_bytes, sectorsize);
+		warning(
+"this is OK for older kernel, but may cause kernel warning for newer kernels");
+		warning("this can be fixed by 'btrfs rescue fix-device-size'");
+	}
+}
diff --git a/check/common.h b/check/common.h
index 9a3488ae365a..72146b444a79 100644
--- a/check/common.h
+++ b/check/common.h
@@ -90,5 +90,6 @@ int link_inode_to_lostfound(struct btrfs_trans_handle *trans,
 			    struct btrfs_path *path,
 			    u64 ino, char *namebuf, u32 name_len,
 			    u8 filetype, u64 *ref_count);
+void check_dev_size_alignment(u64 devid, u64 total_bytes, u32 sectorsize);
 
 #endif
diff --git a/check/main.c b/check/main.c
index 0da25c460336..a8155630df18 100644
--- a/check/main.c
+++ b/check/main.c
@@ -10708,22 +10708,6 @@ static int check_device_used(struct device_record *dev_rec,
 	}
 }
 
-/*
- * Extra (optional) check for dev_item size to report possbile problem on a new
- * kernel.
- */
-static void check_dev_size_alignment(u64 devid, u64 total_bytes, u32 sectorsize)
-{
-	if (!IS_ALIGNED(total_bytes, sectorsize)) {
-		warning(
-"unaligned total_bytes detected for devid %llu, have %llu should be aligned to %u",
-			devid, total_bytes, sectorsize);
-		warning(
-"this is OK for older kernel, but may cause kernel warning for newer kernels");
-		warning("this can be fixed by 'btrfs rescue fix-device-size'");
-	}
-}
-
 /*
  * Unlike device size alignment check above, some super total_bytes check
  * failure can lead to mount failure for newer kernel.
-- 
2.15.1


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

* [PATCH 12/16] btrfs-progs: check: move reada_walk_down to check/common.c
  2018-01-19  5:37 [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
                   ` (10 preceding siblings ...)
  2018-01-19  5:37 ` [PATCH 11/16] btrfs-progs: check: Move check_dev_size_alignment to check/common.c Qu Wenruo
@ 2018-01-19  5:37 ` Qu Wenruo
  2018-01-19  5:37 ` [PATCH 13/16] btrfs-progs: check: Move check_child_node " Qu Wenruo
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Qu Wenruo @ 2018-01-19  5:37 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Both original and lowmem mode shares this function to do readahead.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/common.c | 23 +++++++++++++++++++++++
 check/common.h |  2 ++
 check/main.c   | 22 ----------------------
 3 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/check/common.c b/check/common.c
index 7392ed6b472f..1ea9f506713a 100644
--- a/check/common.c
+++ b/check/common.c
@@ -20,6 +20,7 @@
 #include "messages.h"
 #include "transaction.h"
 #include "utils.h"
+#include "disk-io.h"
 #include "check/common.h"
 
 /*
@@ -252,3 +253,25 @@ void check_dev_size_alignment(u64 devid, u64 total_bytes, u32 sectorsize)
 		warning("this can be fixed by 'btrfs rescue fix-device-size'");
 	}
 }
+
+void reada_walk_down(struct btrfs_root *root, struct extent_buffer *node,
+		     int slot)
+{
+	struct btrfs_fs_info *fs_info = root->fs_info;
+	u64 bytenr;
+	u64 ptr_gen;
+	u32 nritems;
+	int i;
+	int level;
+
+	level = btrfs_header_level(node);
+	if (level != 1)
+		return;
+
+	nritems = btrfs_header_nritems(node);
+	for (i = slot; i < nritems; i++) {
+		bytenr = btrfs_node_blockptr(node, i);
+		ptr_gen = btrfs_node_ptr_generation(node, i);
+		readahead_tree_block(fs_info, bytenr, ptr_gen);
+	}
+}
diff --git a/check/common.h b/check/common.h
index 72146b444a79..34b2f8a9cd87 100644
--- a/check/common.h
+++ b/check/common.h
@@ -91,5 +91,7 @@ int link_inode_to_lostfound(struct btrfs_trans_handle *trans,
 			    u64 ino, char *namebuf, u32 name_len,
 			    u8 filetype, u64 *ref_count);
 void check_dev_size_alignment(u64 devid, u64 total_bytes, u32 sectorsize);
+void reada_walk_down(struct btrfs_root *root, struct extent_buffer *node,
+		     int slot);
 
 #endif
diff --git a/check/main.c b/check/main.c
index a8155630df18..aa7098a0be96 100644
--- a/check/main.c
+++ b/check/main.c
@@ -1667,28 +1667,6 @@ out:
 	return ret;
 }
 
-static void reada_walk_down(struct btrfs_root *root,
-			    struct extent_buffer *node, int slot)
-{
-	struct btrfs_fs_info *fs_info = root->fs_info;
-	u64 bytenr;
-	u64 ptr_gen;
-	u32 nritems;
-	int i;
-	int level;
-
-	level = btrfs_header_level(node);
-	if (level != 1)
-		return;
-
-	nritems = btrfs_header_nritems(node);
-	for (i = slot; i < nritems; i++) {
-		bytenr = btrfs_node_blockptr(node, i);
-		ptr_gen = btrfs_node_ptr_generation(node, i);
-		readahead_tree_block(fs_info, bytenr, ptr_gen);
-	}
-}
-
 /*
  * Check the child node/leaf by the following condition:
  * 1. the first item key of the node/leaf should be the same with the one
-- 
2.15.1


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

* [PATCH 13/16] btrfs-progs: check: Move check_child_node to check/common.c
  2018-01-19  5:37 [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
                   ` (11 preceding siblings ...)
  2018-01-19  5:37 ` [PATCH 12/16] btrfs-progs: check: move reada_walk_down " Qu Wenruo
@ 2018-01-19  5:37 ` Qu Wenruo
  2018-01-19  5:37 ` [PATCH 14/16] btrfs-progs: check: Move reset_cached_block_groups " Qu Wenruo
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Qu Wenruo @ 2018-01-19  5:37 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/common.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 check/common.h |  2 ++
 check/main.c   | 49 -------------------------------------------------
 3 files changed, 51 insertions(+), 49 deletions(-)

diff --git a/check/common.c b/check/common.c
index 1ea9f506713a..4cdc46b0ba7c 100644
--- a/check/common.c
+++ b/check/common.c
@@ -275,3 +275,52 @@ void reada_walk_down(struct btrfs_root *root, struct extent_buffer *node,
 		readahead_tree_block(fs_info, bytenr, ptr_gen);
 	}
 }
+
+/*
+ * Check the child node/leaf by the following condition:
+ * 1. the first item key of the node/leaf should be the same with the one
+ *    in parent.
+ * 2. block in parent node should match the child node/leaf.
+ * 3. generation of parent node and child's header should be consistent.
+ *
+ * Or the child node/leaf pointed by the key in parent is not valid.
+ *
+ * We hope to check leaf owner too, but since subvol may share leaves,
+ * which makes leaf owner check not so strong, key check should be
+ * sufficient enough for that case.
+ */
+int check_child_node(struct extent_buffer *parent, int slot,
+		     struct extent_buffer *child)
+{
+	struct btrfs_key parent_key;
+	struct btrfs_key child_key;
+	int ret = 0;
+
+	btrfs_node_key_to_cpu(parent, &parent_key, slot);
+	if (btrfs_header_level(child) == 0)
+		btrfs_item_key_to_cpu(child, &child_key, 0);
+	else
+		btrfs_node_key_to_cpu(child, &child_key, 0);
+
+	if (memcmp(&parent_key, &child_key, sizeof(parent_key))) {
+		ret = -EINVAL;
+		fprintf(stderr,
+			"Wrong key of child node/leaf, wanted: (%llu, %u, %llu), have: (%llu, %u, %llu)\n",
+			parent_key.objectid, parent_key.type, parent_key.offset,
+			child_key.objectid, child_key.type, child_key.offset);
+	}
+	if (btrfs_header_bytenr(child) != btrfs_node_blockptr(parent, slot)) {
+		ret = -EINVAL;
+		fprintf(stderr, "Wrong block of child node/leaf, wanted: %llu, have: %llu\n",
+			btrfs_node_blockptr(parent, slot),
+			btrfs_header_bytenr(child));
+	}
+	if (btrfs_node_ptr_generation(parent, slot) !=
+	    btrfs_header_generation(child)) {
+		ret = -EINVAL;
+		fprintf(stderr, "Wrong generation of child node/leaf, wanted: %llu, have: %llu\n",
+			btrfs_header_generation(child),
+			btrfs_node_ptr_generation(parent, slot));
+	}
+	return ret;
+}
diff --git a/check/common.h b/check/common.h
index 34b2f8a9cd87..d200a0c90e38 100644
--- a/check/common.h
+++ b/check/common.h
@@ -93,5 +93,7 @@ int link_inode_to_lostfound(struct btrfs_trans_handle *trans,
 void check_dev_size_alignment(u64 devid, u64 total_bytes, u32 sectorsize);
 void reada_walk_down(struct btrfs_root *root, struct extent_buffer *node,
 		     int slot);
+int check_child_node(struct extent_buffer *parent, int slot,
+		     struct extent_buffer *child);
 
 #endif
diff --git a/check/main.c b/check/main.c
index aa7098a0be96..af4e54857fbf 100644
--- a/check/main.c
+++ b/check/main.c
@@ -1667,55 +1667,6 @@ out:
 	return ret;
 }
 
-/*
- * Check the child node/leaf by the following condition:
- * 1. the first item key of the node/leaf should be the same with the one
- *    in parent.
- * 2. block in parent node should match the child node/leaf.
- * 3. generation of parent node and child's header should be consistent.
- *
- * Or the child node/leaf pointed by the key in parent is not valid.
- *
- * We hope to check leaf owner too, but since subvol may share leaves,
- * which makes leaf owner check not so strong, key check should be
- * sufficient enough for that case.
- */
-static int check_child_node(struct extent_buffer *parent, int slot,
-			    struct extent_buffer *child)
-{
-	struct btrfs_key parent_key;
-	struct btrfs_key child_key;
-	int ret = 0;
-
-	btrfs_node_key_to_cpu(parent, &parent_key, slot);
-	if (btrfs_header_level(child) == 0)
-		btrfs_item_key_to_cpu(child, &child_key, 0);
-	else
-		btrfs_node_key_to_cpu(child, &child_key, 0);
-
-	if (memcmp(&parent_key, &child_key, sizeof(parent_key))) {
-		ret = -EINVAL;
-		fprintf(stderr,
-			"Wrong key of child node/leaf, wanted: (%llu, %u, %llu), have: (%llu, %u, %llu)\n",
-			parent_key.objectid, parent_key.type, parent_key.offset,
-			child_key.objectid, child_key.type, child_key.offset);
-	}
-	if (btrfs_header_bytenr(child) != btrfs_node_blockptr(parent, slot)) {
-		ret = -EINVAL;
-		fprintf(stderr, "Wrong block of child node/leaf, wanted: %llu, have: %llu\n",
-			btrfs_node_blockptr(parent, slot),
-			btrfs_header_bytenr(child));
-	}
-	if (btrfs_node_ptr_generation(parent, slot) !=
-	    btrfs_header_generation(child)) {
-		ret = -EINVAL;
-		fprintf(stderr, "Wrong generation of child node/leaf, wanted: %llu, have: %llu\n",
-			btrfs_header_generation(child),
-			btrfs_node_ptr_generation(parent, slot));
-	}
-	return ret;
-}
-
 /*
  * for a tree node or leaf, if it's shared, indeed we don't need to iterate it
  * in every fs or file tree check. Here we find its all root ids, and only check
-- 
2.15.1


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

* [PATCH 14/16] btrfs-progs: check: Move reset_cached_block_groups to check/common.c
  2018-01-19  5:37 [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
                   ` (12 preceding siblings ...)
  2018-01-19  5:37 ` [PATCH 13/16] btrfs-progs: check: Move check_child_node " Qu Wenruo
@ 2018-01-19  5:37 ` Qu Wenruo
  2018-01-19  5:37 ` [PATCH 16/16] btrfs-progs: check/lowmem: Cleanup unnecessary _v2 suffix Qu Wenruo
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Qu Wenruo @ 2018-01-19  5:37 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

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

diff --git a/check/common.c b/check/common.c
index 4cdc46b0ba7c..d6abf6d6733c 100644
--- a/check/common.c
+++ b/check/common.c
@@ -324,3 +324,28 @@ int check_child_node(struct extent_buffer *parent, int slot,
 	}
 	return ret;
 }
+
+void reset_cached_block_groups(struct btrfs_fs_info *fs_info)
+{
+	struct btrfs_block_group_cache *cache;
+	u64 start, end;
+	int ret;
+
+	while (1) {
+		ret = find_first_extent_bit(&fs_info->free_space_cache, 0,
+					    &start, &end, EXTENT_DIRTY);
+		if (ret)
+			break;
+		clear_extent_dirty(&fs_info->free_space_cache, start, end);
+	}
+
+	start = 0;
+	while (1) {
+		cache = btrfs_lookup_first_block_group(fs_info, start);
+		if (!cache)
+			break;
+		if (cache->cached)
+			cache->cached = 0;
+		start = cache->key.objectid + cache->key.offset;
+	}
+}
diff --git a/check/common.h b/check/common.h
index d200a0c90e38..09745af4932f 100644
--- a/check/common.h
+++ b/check/common.h
@@ -95,5 +95,6 @@ void reada_walk_down(struct btrfs_root *root, struct extent_buffer *node,
 		     int slot);
 int check_child_node(struct extent_buffer *parent, int slot,
 		     struct extent_buffer *child);
+void reset_cached_block_groups(struct btrfs_fs_info *fs_info);
 
 #endif
diff --git a/check/main.c b/check/main.c
index af4e54857fbf..3c556db90c30 100644
--- a/check/main.c
+++ b/check/main.c
@@ -412,8 +412,6 @@ static void free_file_extent_holes(struct rb_root *holes)
 	}
 }
 
-static void reset_cached_block_groups(struct btrfs_fs_info *fs_info);
-
 static void record_root_in_trans(struct btrfs_trans_handle *trans,
 				 struct btrfs_root *root)
 {
@@ -10196,31 +10194,6 @@ static int prune_corrupt_blocks(struct btrfs_fs_info *info)
 	return 0;
 }
 
-static void reset_cached_block_groups(struct btrfs_fs_info *fs_info)
-{
-	struct btrfs_block_group_cache *cache;
-	u64 start, end;
-	int ret;
-
-	while (1) {
-		ret = find_first_extent_bit(&fs_info->free_space_cache, 0,
-					    &start, &end, EXTENT_DIRTY);
-		if (ret)
-			break;
-		clear_extent_dirty(&fs_info->free_space_cache, start, end);
-	}
-
-	start = 0;
-	while (1) {
-		cache = btrfs_lookup_first_block_group(fs_info, start);
-		if (!cache)
-			break;
-		if (cache->cached)
-			cache->cached = 0;
-		start = cache->key.objectid + cache->key.offset;
-	}
-}
-
 static int check_extent_refs(struct btrfs_root *root,
 			     struct cache_tree *extent_cache)
 {
-- 
2.15.1


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

* [PATCH 16/16] btrfs-progs: check/lowmem: Cleanup unnecessary _v2 suffix
  2018-01-19  5:37 [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
                   ` (13 preceding siblings ...)
  2018-01-19  5:37 ` [PATCH 14/16] btrfs-progs: check: Move reset_cached_block_groups " Qu Wenruo
@ 2018-01-19  5:37 ` Qu Wenruo
  2018-01-19  7:50 ` [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Su Yue
  2018-01-31 18:26 ` David Sterba
  16 siblings, 0 replies; 24+ messages in thread
From: Qu Wenruo @ 2018-01-19  5:37 UTC (permalink / raw)
  To: linux-btrfs; +Cc: 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 7fb2016edb4a..fdd4d624881e 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;
 	}
@@ -2084,8 +2084,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;
@@ -3898,10 +3898,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;
@@ -3971,8 +3971,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);
@@ -3996,7 +3996,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]) {
@@ -4049,8 +4049,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;
@@ -4203,7 +4203,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.
@@ -4260,8 +4260,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;
 
@@ -4271,7 +4271,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;
@@ -4293,7 +4293,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);
@@ -4393,12 +4393,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;
@@ -4449,7 +4449,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)
@@ -4477,7 +4477,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 ac4e6655f9b9..77bbc7504d31 100644
--- a/check/main.c
+++ b/check/main.c
@@ -3524,7 +3524,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);
 
@@ -8310,7 +8310,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.15.1


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

* Re: [PATCH 04/16] btrfs-progs: check: Move node_ptr structure to check/common.h
  2018-01-19  5:37 ` [PATCH 04/16] btrfs-progs: check: Move node_ptr structure to check/common.h Qu Wenruo
@ 2018-01-19  5:52   ` Su Yue
  2018-01-19  5:53     ` Qu Wenruo
  0 siblings, 1 reply; 24+ messages in thread
From: Su Yue @ 2018-01-19  5:52 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs; +Cc: dsterba

The structure name is 'node_refs' not 'node_ptr'.
Misspelt the patch name?

Thanks,
Su

On 01/19/2018 01:37 PM, Qu Wenruo wrote:
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>   check/common.h | 39 +++++++++++++++++++++++++++++++++++++++
>   check/main.c   | 11 +----------
>   2 files changed, 40 insertions(+), 10 deletions(-)
>   create mode 100644 check/common.h
> 
> diff --git a/check/common.h b/check/common.h
> new file mode 100644
> index 000000000000..25874aec597b
> --- /dev/null
> +++ b/check/common.h
> @@ -0,0 +1,39 @@
> +/*
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public
> + * License v2 as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public
> + * License along with this program; if not, write to the
> + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
> + * Boston, MA 021110-1307, USA.
> + */
> +
> +/*
> + * Defines and function declarations for code shared by both lowmem and
> + * original mode
> + */
> +#ifndef __BTRFS_CHECK_COMMON_H__
> +#define __BTRFS_CHECK_COMMON_H__
> +#include "ctree.h"
> +
> +/*
> + * Use for tree walk to walk through trees whose leaves/nodes can be shared
> + * between different trees. (Namely subvolume/fs trees)
> + */
> +struct node_refs {
> +	u64 bytenr[BTRFS_MAX_LEVEL];
> +	u64 refs[BTRFS_MAX_LEVEL];
> +	int need_check[BTRFS_MAX_LEVEL];
> +	/* field for checking all trees */
> +	int checked[BTRFS_MAX_LEVEL];
> +	/* the corresponding extent should be marked as full backref or not */
> +	int full_backref[BTRFS_MAX_LEVEL];
> +};
> +
> +#endif
> diff --git a/check/main.c b/check/main.c
> index dbd2b755c48f..fbd73c42bee8 100644
> --- a/check/main.c
> +++ b/check/main.c
> @@ -45,6 +45,7 @@
>   #include "help.h"
>   #include "check/original.h"
>   #include "check/lowmem.h"
> +#include "check/common.h"
>   
>   enum task_position {
>   	TASK_EXTENTS,
> @@ -1667,16 +1668,6 @@ static int process_one_leaf(struct btrfs_root *root, struct extent_buffer *eb,
>   	return ret;
>   }
>   
> -struct node_refs {
> -	u64 bytenr[BTRFS_MAX_LEVEL];
> -	u64 refs[BTRFS_MAX_LEVEL];
> -	int need_check[BTRFS_MAX_LEVEL];
> -	/* field for checking all trees */
> -	int checked[BTRFS_MAX_LEVEL];
> -	/* the corresponding extent should be marked as full backref or not */
> -	int full_backref[BTRFS_MAX_LEVEL];
> -};
> -
>   static int update_nodes_refs(struct btrfs_root *root, u64 bytenr,
>   			     struct extent_buffer *eb, struct node_refs *nrefs,
>   			     u64 level, int check_all);
> 



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

* Re: [PATCH 04/16] btrfs-progs: check: Move node_ptr structure to check/common.h
  2018-01-19  5:52   ` Su Yue
@ 2018-01-19  5:53     ` Qu Wenruo
  0 siblings, 0 replies; 24+ messages in thread
From: Qu Wenruo @ 2018-01-19  5:53 UTC (permalink / raw)
  To: Su Yue, Qu Wenruo, linux-btrfs; +Cc: dsterba


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



On 2018年01月19日 13:52, Su Yue wrote:
> The structure name is 'node_refs' not 'node_ptr'.
> Misspelt the patch name?
> 

You got me!

I'll just update the title in github.

Thanks,
Qu

> Thanks,
> Su
> 
> On 01/19/2018 01:37 PM, Qu Wenruo wrote:
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>> ---
>>   check/common.h | 39 +++++++++++++++++++++++++++++++++++++++
>>   check/main.c   | 11 +----------
>>   2 files changed, 40 insertions(+), 10 deletions(-)
>>   create mode 100644 check/common.h
>>
>> diff --git a/check/common.h b/check/common.h
>> new file mode 100644
>> index 000000000000..25874aec597b
>> --- /dev/null
>> +++ b/check/common.h
>> @@ -0,0 +1,39 @@
>> +/*
>> + * This program is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU General Public
>> + * License v2 as published by the Free Software Foundation.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>> + * General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU General Public
>> + * License along with this program; if not, write to the
>> + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
>> + * Boston, MA 021110-1307, USA.
>> + */
>> +
>> +/*
>> + * Defines and function declarations for code shared by both lowmem and
>> + * original mode
>> + */
>> +#ifndef __BTRFS_CHECK_COMMON_H__
>> +#define __BTRFS_CHECK_COMMON_H__
>> +#include "ctree.h"
>> +
>> +/*
>> + * Use for tree walk to walk through trees whose leaves/nodes can be
>> shared
>> + * between different trees. (Namely subvolume/fs trees)
>> + */
>> +struct node_refs {
>> +    u64 bytenr[BTRFS_MAX_LEVEL];
>> +    u64 refs[BTRFS_MAX_LEVEL];
>> +    int need_check[BTRFS_MAX_LEVEL];
>> +    /* field for checking all trees */
>> +    int checked[BTRFS_MAX_LEVEL];
>> +    /* the corresponding extent should be marked as full backref or
>> not */
>> +    int full_backref[BTRFS_MAX_LEVEL];
>> +};
>> +
>> +#endif
>> diff --git a/check/main.c b/check/main.c
>> index dbd2b755c48f..fbd73c42bee8 100644
>> --- a/check/main.c
>> +++ b/check/main.c
>> @@ -45,6 +45,7 @@
>>   #include "help.h"
>>   #include "check/original.h"
>>   #include "check/lowmem.h"
>> +#include "check/common.h"
>>     enum task_position {
>>       TASK_EXTENTS,
>> @@ -1667,16 +1668,6 @@ static int process_one_leaf(struct btrfs_root
>> *root, struct extent_buffer *eb,
>>       return ret;
>>   }
>>   -struct node_refs {
>> -    u64 bytenr[BTRFS_MAX_LEVEL];
>> -    u64 refs[BTRFS_MAX_LEVEL];
>> -    int need_check[BTRFS_MAX_LEVEL];
>> -    /* field for checking all trees */
>> -    int checked[BTRFS_MAX_LEVEL];
>> -    /* the corresponding extent should be marked as full backref or
>> not */
>> -    int full_backref[BTRFS_MAX_LEVEL];
>> -};
>> -
>>   static int update_nodes_refs(struct btrfs_root *root, u64 bytenr,
>>                    struct extent_buffer *eb, struct node_refs *nrefs,
>>                    u64 level, int check_all);
>>
> 
> 
> -- 
> 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] 24+ messages in thread

* Re: [PATCH 08/16] btrfs-progs: check: Move count_csum_range function to check/common.c
  2018-01-19  5:37 ` [PATCH 08/16] btrfs-progs: check: Move count_csum_range function to check/common.c Qu Wenruo
@ 2018-01-19  6:46   ` Su Yue
  0 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-01-19  6:46 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs; +Cc: dsterba, Qu Wenruo




On 01/19/2018 01:37 PM, Qu Wenruo wrote:
> Despite of moving it to check/common.c, also:
> 
> 1) Add extra comment of the function
> 2) Change @root paramter to @fs_info

'paramter' may be misspelled - perhaps 'parameter'?

Thanks,
Su
>     Since @root is never used, csum_root is picked from fs_info anyway.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>   Makefile       |   2 +-
>   check/common.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>   check/common.h |   3 ++
>   check/main.c   |  77 ++-----------------------------------------
>   4 files changed, 108 insertions(+), 75 deletions(-)
>   create mode 100644 check/common.c
> 
> diff --git a/Makefile b/Makefile
> index c4e2dc5b68a9..a00a982a18df 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -113,7 +113,7 @@ cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
>   	       cmds-restore.o cmds-rescue.o chunk-recover.o super-recover.o \
>   	       cmds-property.o cmds-fi-usage.o cmds-inspect-dump-tree.o \
>   	       cmds-inspect-dump-super.o cmds-inspect-tree-stats.o cmds-fi-du.o \
> -	       mkfs/common.o
> +	       mkfs/common.o check/common.o
>   libbtrfs_objects = send-stream.o send-utils.o kernel-lib/rbtree.o btrfs-list.o \
>   		   kernel-lib/crc32c.o messages.o \
>   		   uuid-tree.o utils-lib.o rbtree-utils.o
> diff --git a/check/common.c b/check/common.c
> new file mode 100644
> index 000000000000..ed4f2a40bac2
> --- /dev/null
> +++ b/check/common.c
> @@ -0,0 +1,101 @@
> +/*
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public
> + * License v2 as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public
> + * License along with this program; if not, write to the
> + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
> + * Boston, MA 021110-1307, USA.
> + */
> +
> +#include "ctree.h"
> +#include "internal.h"
> +#include "check/common.h"
> +
> +/*
> + * Search in csum tree to find how many bytes of range [@start, @start + @len)
> + * has the corresponding csum item.
> + *
> + * @start:	range start
> + * @len:	range length
> + * @found:	return value of found csum bytes
> + *		unit is BYTE.
> + */
> +int count_csum_range(struct btrfs_fs_info *fs_info, u64 start,
> +		     u64 len, u64 *found)
> +{
> +	struct btrfs_key key;
> +	struct btrfs_path path;
> +	struct extent_buffer *leaf;
> +	int ret;
> +	size_t size;
> +	*found = 0;
> +	u64 csum_end;
> +	u16 csum_size = btrfs_super_csum_size(fs_info->super_copy);
> +
> +	btrfs_init_path(&path);
> +
> +	key.objectid = BTRFS_EXTENT_CSUM_OBJECTID;
> +	key.offset = start;
> +	key.type = BTRFS_EXTENT_CSUM_KEY;
> +
> +	ret = btrfs_search_slot(NULL, fs_info->csum_root,
> +				&key, &path, 0, 0);
> +	if (ret < 0)
> +		goto out;
> +	if (ret > 0 && path.slots[0] > 0) {
> +		leaf = path.nodes[0];
> +		btrfs_item_key_to_cpu(leaf, &key, path.slots[0] - 1);
> +		if (key.objectid == BTRFS_EXTENT_CSUM_OBJECTID &&
> +		    key.type == BTRFS_EXTENT_CSUM_KEY)
> +			path.slots[0]--;
> +	}
> +
> +	while (len > 0) {
> +		leaf = path.nodes[0];
> +		if (path.slots[0] >= btrfs_header_nritems(leaf)) {
> +			ret = btrfs_next_leaf(fs_info->csum_root, &path);
> +			if (ret > 0)
> +				break;
> +			else if (ret < 0)
> +				goto out;
> +			leaf = path.nodes[0];
> +		}
> +
> +		btrfs_item_key_to_cpu(leaf, &key, path.slots[0]);
> +		if (key.objectid != BTRFS_EXTENT_CSUM_OBJECTID ||
> +		    key.type != BTRFS_EXTENT_CSUM_KEY)
> +			break;
> +
> +		btrfs_item_key_to_cpu(leaf, &key, path.slots[0]);
> +		if (key.offset >= start + len)
> +			break;
> +
> +		if (key.offset > start)
> +			start = key.offset;
> +
> +		size = btrfs_item_size_nr(leaf, path.slots[0]);
> +		csum_end = key.offset + (size / csum_size) *
> +			   fs_info->sectorsize;
> +		if (csum_end > start) {
> +			size = min(csum_end - start, len);
> +			len -= size;
> +			start += size;
> +			*found += size;
> +		}
> +
> +		path.slots[0]++;
> +	}
> +out:
> +	btrfs_release_path(&path);
> +	if (ret < 0)
> +		return ret;
> +	return 0;
> +}
> +
> diff --git a/check/common.h b/check/common.h
> index 77a0ab54166f..cd64798f4804 100644
> --- a/check/common.h
> +++ b/check/common.h
> @@ -80,4 +80,7 @@ static inline int fs_root_objectid(u64 objectid)
>   	return is_fstree(objectid);
>   }
>   
> +int count_csum_range(struct btrfs_fs_info *fs_info, u64 start,
> +		     u64 len, u64 *found);
> +
>   #endif
> diff --git a/check/main.c b/check/main.c
> index 9ecbac8f19c3..b891f4815d30 100644
> --- a/check/main.c
> +++ b/check/main.c
> @@ -1423,78 +1423,6 @@ static int process_inode_extref(struct extent_buffer *eb,
>   
>   }
>   
> -static int count_csum_range(struct btrfs_root *root, u64 start,
> -			    u64 len, u64 *found)
> -{
> -	struct btrfs_key key;
> -	struct btrfs_path path;
> -	struct extent_buffer *leaf;
> -	int ret;
> -	size_t size;
> -	*found = 0;
> -	u64 csum_end;
> -	u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
> -
> -	btrfs_init_path(&path);
> -
> -	key.objectid = BTRFS_EXTENT_CSUM_OBJECTID;
> -	key.offset = start;
> -	key.type = BTRFS_EXTENT_CSUM_KEY;
> -
> -	ret = btrfs_search_slot(NULL, root->fs_info->csum_root,
> -				&key, &path, 0, 0);
> -	if (ret < 0)
> -		goto out;
> -	if (ret > 0 && path.slots[0] > 0) {
> -		leaf = path.nodes[0];
> -		btrfs_item_key_to_cpu(leaf, &key, path.slots[0] - 1);
> -		if (key.objectid == BTRFS_EXTENT_CSUM_OBJECTID &&
> -		    key.type == BTRFS_EXTENT_CSUM_KEY)
> -			path.slots[0]--;
> -	}
> -
> -	while (len > 0) {
> -		leaf = path.nodes[0];
> -		if (path.slots[0] >= btrfs_header_nritems(leaf)) {
> -			ret = btrfs_next_leaf(root->fs_info->csum_root, &path);
> -			if (ret > 0)
> -				break;
> -			else if (ret < 0)
> -				goto out;
> -			leaf = path.nodes[0];
> -		}
> -
> -		btrfs_item_key_to_cpu(leaf, &key, path.slots[0]);
> -		if (key.objectid != BTRFS_EXTENT_CSUM_OBJECTID ||
> -		    key.type != BTRFS_EXTENT_CSUM_KEY)
> -			break;
> -
> -		btrfs_item_key_to_cpu(leaf, &key, path.slots[0]);
> -		if (key.offset >= start + len)
> -			break;
> -
> -		if (key.offset > start)
> -			start = key.offset;
> -
> -		size = btrfs_item_size_nr(leaf, path.slots[0]);
> -		csum_end = key.offset + (size / csum_size) *
> -			   root->fs_info->sectorsize;
> -		if (csum_end > start) {
> -			size = min(csum_end - start, len);
> -			len -= size;
> -			start += size;
> -			*found += size;
> -		}
> -
> -		path.slots[0]++;
> -	}
> -out:
> -	btrfs_release_path(&path);
> -	if (ret < 0)
> -		return ret;
> -	return 0;
> -}
> -
>   static int process_file_extent(struct btrfs_root *root,
>   				struct extent_buffer *eb,
>   				int slot, struct btrfs_key *key,
> @@ -1574,7 +1502,8 @@ static int process_file_extent(struct btrfs_root *root,
>   		else
>   			disk_bytenr += extent_offset;
>   
> -		ret = count_csum_range(root, disk_bytenr, num_bytes, &found);
> +		ret = count_csum_range(root->fs_info, disk_bytenr, num_bytes,
> +				       &found);
>   		if (ret < 0)
>   			return ret;
>   		if (extent_type == BTRFS_FILE_EXTENT_REG) {
> @@ -5508,7 +5437,7 @@ 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, 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",
> 



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

* Re: [PATCH 05/16] btrfs-progs: check: Export check global variables to check/common.h
  2018-01-19  5:37 ` [PATCH 05/16] btrfs-progs: check: Export check global variables " Qu Wenruo
@ 2018-01-19  6:55   ` Su Yue
  2018-01-19  7:26     ` Qu Wenruo
  0 siblings, 1 reply; 24+ messages in thread
From: Su Yue @ 2018-01-19  6:55 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs; +Cc: dsterba, Qu Wenruo



On 01/19/2018 01:37 PM, Qu Wenruo wrote:
> There are a dozen of variables which are used as "check global"
> variables, like @total_csum_bytes or @no_holes.
> 
> These variables are used freely across the check code, however since
> we're splitting check code, they need to be exported so they can be used
> in other files.
> 
> This patch just export them and add declarations for them in
> check/common.h.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>   check/common.h | 17 +++++++++++++++++
>   check/main.c   | 32 ++++++++++++++++----------------
>   2 files changed, 33 insertions(+), 16 deletions(-)
> 
> diff --git a/check/common.h b/check/common.h
> index 25874aec597b..8d93ddbf4afb 100644
> --- a/check/common.h
> +++ b/check/common.h
> @@ -36,4 +36,21 @@ struct node_refs {
>   	int full_backref[BTRFS_MAX_LEVEL];
>   };
>   
> +extern u64 bytes_used;
> +extern u64 total_csum_bytes;
> +extern u64 total_btree_bytes;
> +extern u64 total_fs_tree_bytes;
> +extern u64 total_extent_tree_bytes;
> +extern u64 btree_space_waste;
> +extern u64 data_bytes_allocated;
> +extern u64 data_bytes_referenced;
> +extern struct list_head duplicate_extents;
> +extern struct list_head delete_items;
> +extern int no_holes;
> +extern int init_extent_tree;
> +extern int check_data_csum;
> +extern struct btrfs_fs_info *global_info;
> +extern struct task_ctx ctx;
> +extern struct cache_tree *roots_info_cache;
> +
>   #endif
> diff --git a/check/main.c b/check/main.c
> index fbd73c42bee8..bb927ecc87ee 100644
> --- a/check/main.c
> +++ b/check/main.c
> @@ -61,22 +61,22 @@ struct task_ctx {
>   	struct task_info *info;
>   };
>   
> -static u64 bytes_used = 0;
> -static u64 total_csum_bytes = 0;
> -static u64 total_btree_bytes = 0;
> -static u64 total_fs_tree_bytes = 0;
> -static u64 total_extent_tree_bytes = 0;
> -static u64 btree_space_waste = 0;
> -static u64 data_bytes_allocated = 0;
> -static u64 data_bytes_referenced = 0;
> -static LIST_HEAD(duplicate_extents);
> -static LIST_HEAD(delete_items);
> -static int no_holes = 0;
> -static int init_extent_tree = 0;
> -static int check_data_csum = 0;
> -static struct btrfs_fs_info *global_info;
> -static struct task_ctx ctx = { 0 };
> -static struct cache_tree *roots_info_cache = NULL;
> +u64 bytes_used = 0;
> +u64 total_csum_bytes = 0;
> +u64 total_btree_bytes = 0;
> +u64 total_fs_tree_bytes = 0;
> +u64 total_extent_tree_bytes = 0;
> +u64 btree_space_waste = 0;
> +u64 data_bytes_allocated = 0;
> +u64 data_bytes_referenced = 0;
> +LIST_HEAD(duplicate_extents);
> +LIST_HEAD(delete_items);
> +int no_holes = 0;
> +int init_extent_tree = 0;
> +int check_data_csum = 0;

Just a small suggestion:
Since the patchset only splits cmds-check.c without functional changes,
Maybe it's a good timing to adjust those lines of old code according by 
errors and warnings which reported by checkpatch?

Thanks,
Su

> +struct btrfs_fs_info *global_info;
> +struct task_ctx ctx = { 0 };
> +struct cache_tree *roots_info_cache = NULL;
>   
>   enum btrfs_check_mode {
>   	CHECK_MODE_ORIGINAL,
> 



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

* Re: [PATCH 05/16] btrfs-progs: check: Export check global variables to check/common.h
  2018-01-19  6:55   ` Su Yue
@ 2018-01-19  7:26     ` Qu Wenruo
  0 siblings, 0 replies; 24+ messages in thread
From: Qu Wenruo @ 2018-01-19  7:26 UTC (permalink / raw)
  To: Su Yue, Qu Wenruo, linux-btrfs; +Cc: dsterba


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



On 2018年01月19日 14:55, Su Yue wrote:
> 
> 
> On 01/19/2018 01:37 PM, Qu Wenruo wrote:
>> There are a dozen of variables which are used as "check global"
>> variables, like @total_csum_bytes or @no_holes.
>>
>> These variables are used freely across the check code, however since
>> we're splitting check code, they need to be exported so they can be used
>> in other files.
>>
>> This patch just export them and add declarations for them in
>> check/common.h.
>>
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>> ---
>>   check/common.h | 17 +++++++++++++++++
>>   check/main.c   | 32 ++++++++++++++++----------------
>>   2 files changed, 33 insertions(+), 16 deletions(-)
>>
>> diff --git a/check/common.h b/check/common.h
>> index 25874aec597b..8d93ddbf4afb 100644
>> --- a/check/common.h
>> +++ b/check/common.h
>> @@ -36,4 +36,21 @@ struct node_refs {
>>       int full_backref[BTRFS_MAX_LEVEL];
>>   };
>>   +extern u64 bytes_used;
>> +extern u64 total_csum_bytes;
>> +extern u64 total_btree_bytes;
>> +extern u64 total_fs_tree_bytes;
>> +extern u64 total_extent_tree_bytes;
>> +extern u64 btree_space_waste;
>> +extern u64 data_bytes_allocated;
>> +extern u64 data_bytes_referenced;
>> +extern struct list_head duplicate_extents;
>> +extern struct list_head delete_items;
>> +extern int no_holes;
>> +extern int init_extent_tree;
>> +extern int check_data_csum;
>> +extern struct btrfs_fs_info *global_info;
>> +extern struct task_ctx ctx;
>> +extern struct cache_tree *roots_info_cache;
>> +
>>   #endif
>> diff --git a/check/main.c b/check/main.c
>> index fbd73c42bee8..bb927ecc87ee 100644
>> --- a/check/main.c
>> +++ b/check/main.c
>> @@ -61,22 +61,22 @@ struct task_ctx {
>>       struct task_info *info;
>>   };
>>   -static u64 bytes_used = 0;
>> -static u64 total_csum_bytes = 0;
>> -static u64 total_btree_bytes = 0;
>> -static u64 total_fs_tree_bytes = 0;
>> -static u64 total_extent_tree_bytes = 0;
>> -static u64 btree_space_waste = 0;
>> -static u64 data_bytes_allocated = 0;
>> -static u64 data_bytes_referenced = 0;
>> -static LIST_HEAD(duplicate_extents);
>> -static LIST_HEAD(delete_items);
>> -static int no_holes = 0;
>> -static int init_extent_tree = 0;
>> -static int check_data_csum = 0;
>> -static struct btrfs_fs_info *global_info;
>> -static struct task_ctx ctx = { 0 };
>> -static struct cache_tree *roots_info_cache = NULL;
>> +u64 bytes_used = 0;
>> +u64 total_csum_bytes = 0;
>> +u64 total_btree_bytes = 0;
>> +u64 total_fs_tree_bytes = 0;
>> +u64 total_extent_tree_bytes = 0;
>> +u64 btree_space_waste = 0;
>> +u64 data_bytes_allocated = 0;
>> +u64 data_bytes_referenced = 0;
>> +LIST_HEAD(duplicate_extents);
>> +LIST_HEAD(delete_items);
>> +int no_holes = 0;
>> +int init_extent_tree = 0;
>> +int check_data_csum = 0;
> 
> Just a small suggestion:
> Since the patchset only splits cmds-check.c without functional changes,
> Maybe it's a good timing to adjust those lines of old code according by
> errors and warnings which reported by checkpatch?

I'll do it in PART2, with new comment and format cleanup.

Right now I prefer this get merged first to provide the basis for later
cleanup.

Thanks,
Qu

> 
> Thanks,
> Su
> 
>> +struct btrfs_fs_info *global_info;
>> +struct task_ctx ctx = { 0 };
>> +struct cache_tree *roots_info_cache = NULL;
>>     enum btrfs_check_mode {
>>       CHECK_MODE_ORIGINAL,
>>
> 
> 


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

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

* Re: [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own
  2018-01-19  5:37 [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
                   ` (14 preceding siblings ...)
  2018-01-19  5:37 ` [PATCH 16/16] btrfs-progs: check/lowmem: Cleanup unnecessary _v2 suffix Qu Wenruo
@ 2018-01-19  7:50 ` Su Yue
  2018-01-31 18:26 ` David Sterba
  16 siblings, 0 replies; 24+ messages in thread
From: Su Yue @ 2018-01-19  7:50 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs; +Cc: dsterba, Qu Wenruo



On 01/19/2018 01:37 PM, Qu Wenruo wrote:
> The long planned cmds-check re-construction is finally here.
> 
> As the original cmds-check.c is getting larger and larger (already over
> 15K lines), it's always a good idea to split it into its own check/
> directory.
> 
> This patchset do the following work:
> 1) Move cmds-check.c to check/main.c
> 2) Put codes shared by both original and lowmem mode into
>     check/common.[ch]
> 3) Put lowmem code into check/lowmem.[ch]
>     With minor renaming to get rid of unnecessary _v2 suffix.
> 
> The modification looks scary, but no functional change at all.
> 
> And considering how much the file structure changed, it's a good idea to
> put PART1 as quick as possible, and there will be less pressure to
> rebase new incoming fsck related codes.
> 
> The real move work happens in the 15th patch, which due to its size
> (500KB+), it may not be able to reach mail list.
> So please fetch the whole patchset from github:
> https://github.com/adam900710/btrfs-progs/tree/split_check
> 
> There will be a part 2, mostly moving original mode to its own
> check/original.[ch], along with extra comment explaining how the two
> different modes work.
> 
It's fine to do cleanup and extra comment in part2.
So, all patches except patch[4] with wrong title
are

Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
> Qu Wenruo (16):
>    btrfs-progs: Moves cmds-check.c to check/main.c
>    btrfs-progs: check: Move original mode definitions to check/original.h
>    btrfs-progs: check: Move definitions of lowmem mode to check/lowmem.h
>    btrfs-progs: check: Move node_ptr structure to check/common.h
>    btrfs-progs: check: Export check global variables to check/common.h
>    btrfs-progs: check: Move imode_to_type function to check/common.h
>    btrfs-progs: check: Move fs_root_objectid function to check/common.h
>    btrfs-progs: check: Move count_csum_range function to check/common.c
>    btrfs-progs: check: Move __create_inode_item function to
>      check/common.c
>    btrfs-progs: check: Move link_inode_to_lostfound function to common.c
>    btrfs-progs: check: Move check_dev_size_alignment to check/common.c
>    btrfs-progs: check: move reada_walk_down to check/common.c
>    btrfs-progs: check: Move check_child_node to check/common.c
>    btrfs-progs: check: Move reset_cached_block_groups to check/common.c
>    btrfs-progs: check: Move lowmem check code to its own
>      check/lowmem.[ch]
>    btrfs-progs: check/lowmem: Cleanup unnecessary _v2 suffix
> 
>   Makefile                     |     6 +-
>   check/common.c               |   351 +
>   check/common.h               |   100 +
>   check/lowmem.c               |  4571 ++++++++++++
>   check/lowmem.h               |    67 +
>   cmds-check.c => check/main.c | 16389 ++++++++++++++---------------------------
>   check/original.h             |   293 +
>   7 files changed, 11007 insertions(+), 10770 deletions(-)
>   create mode 100644 check/common.c
>   create mode 100644 check/common.h
>   create mode 100644 check/lowmem.c
>   create mode 100644 check/lowmem.h
>   rename cmds-check.c => check/main.c (65%)
>   create mode 100644 check/original.h
> 



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

* Re: [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own
  2018-01-19  5:37 [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
                   ` (15 preceding siblings ...)
  2018-01-19  7:50 ` [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Su Yue
@ 2018-01-31 18:26 ` David Sterba
  2018-02-01  5:00   ` Qu Wenruo
  16 siblings, 1 reply; 24+ messages in thread
From: David Sterba @ 2018-01-31 18:26 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs, dsterba

On Fri, Jan 19, 2018 at 01:37:15PM +0800, Qu Wenruo wrote:
> The long planned cmds-check re-construction is finally here.
> 
> As the original cmds-check.c is getting larger and larger (already over
> 15K lines), it's always a good idea to split it into its own check/
> directory.
> 
> This patchset do the following work:
> 1) Move cmds-check.c to check/main.c
> 2) Put codes shared by both original and lowmem mode into
>    check/common.[ch]
> 3) Put lowmem code into check/lowmem.[ch]
>    With minor renaming to get rid of unnecessary _v2 suffix.
> 
> The modification looks scary, but no functional change at all.
> 
> And considering how much the file structure changed, it's a good idea to
> put PART1 as quick as possible, and there will be less pressure to
> rebase new incoming fsck related codes.

I agree with the way you split check, my attempts were going along the
same lines. The question whether to split first and then add fixes shall
be resolved as I'm going to merge the split first. This would need
refreshing the lowmem fixes but the other way around would not avoid the
merge conflicts anyway.

The patch 15 does not apply cleanly to current devel, the conflict did
not seem big, but I did not try to resolve it and merge the last patch.
So, 1-14 goes to devel, please refresh 15 and 16.

> The real move work happens in the 15th patch, which due to its size
> (500KB+), it may not be able to reach mail list.
> So please fetch the whole patchset from github:
> https://github.com/adam900710/btrfs-progs/tree/split_check
> 
> There will be a part 2, mostly moving original mode to its own
> check/original.[ch], along with extra comment explaining how the two
> different modes work.

I'm going to do a few file renames, eg. original.c -> mode-original.c
and similar. It would be better if you send part 2 after that. I'm
expecting more patches that would do no functional change so we can
settle down with the new check/ structure.

As 'check' is the 1st level command, the cmds-check.c will need to be
restored at some point, but it will be only a simple wrapper around the
commandline handling.

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

* Re: [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own
  2018-01-31 18:26 ` David Sterba
@ 2018-02-01  5:00   ` Qu Wenruo
  0 siblings, 0 replies; 24+ messages in thread
From: Qu Wenruo @ 2018-02-01  5:00 UTC (permalink / raw)
  To: dsterba, Qu Wenruo, linux-btrfs


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



On 2018年02月01日 02:26, David Sterba wrote:
> On Fri, Jan 19, 2018 at 01:37:15PM +0800, Qu Wenruo wrote:
>> The long planned cmds-check re-construction is finally here.
>>
>> As the original cmds-check.c is getting larger and larger (already over
>> 15K lines), it's always a good idea to split it into its own check/
>> directory.
>>
>> This patchset do the following work:
>> 1) Move cmds-check.c to check/main.c
>> 2) Put codes shared by both original and lowmem mode into
>>    check/common.[ch]
>> 3) Put lowmem code into check/lowmem.[ch]
>>    With minor renaming to get rid of unnecessary _v2 suffix.
>>
>> The modification looks scary, but no functional change at all.
>>
>> And considering how much the file structure changed, it's a good idea to
>> put PART1 as quick as possible, and there will be less pressure to
>> rebase new incoming fsck related codes.
> 
> I agree with the way you split check, my attempts were going along the
> same lines. The question whether to split first and then add fixes shall
> be resolved as I'm going to merge the split first. This would need
> refreshing the lowmem fixes but the other way around would not avoid the
> merge conflicts anyway.
> 
> The patch 15 does not apply cleanly to current devel, the conflict did
> not seem big, but I did not try to resolve it and merge the last patch.
> So, 1-14 goes to devel, please refresh 15 and 16.

No problem.

Update under way.

> 
>> The real move work happens in the 15th patch, which due to its size
>> (500KB+), it may not be able to reach mail list.
>> So please fetch the whole patchset from github:
>> https://github.com/adam900710/btrfs-progs/tree/split_check
>>
>> There will be a part 2, mostly moving original mode to its own
>> check/original.[ch], along with extra comment explaining how the two
>> different modes work.
> 
> I'm going to do a few file renames, eg. original.c -> mode-original.c
> and similar.
> It would be better if you send part 2 after that.

Of course.
It would be a while for part 2.

> I'm
> expecting more patches that would do no functional change so we can
> settle down with the new check/ structure.
> 
> As 'check' is the 1st level command, the cmds-check.c will need to be
> restored at some point, but it will be only a simple wrapper around the
> commandline handling.

OK, I think it would be part of PART 2 to restore it.

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] 24+ messages in thread

end of thread, other threads:[~2018-02-01  5:00 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-19  5:37 [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Qu Wenruo
2018-01-19  5:37 ` [PATCH 01/16] btrfs-progs: Moves cmds-check.c to check/main.c Qu Wenruo
2018-01-19  5:37 ` [PATCH 02/16] btrfs-progs: check: Move original mode definitions to check/original.h Qu Wenruo
2018-01-19  5:37 ` [PATCH 03/16] btrfs-progs: check: Move definitions of lowmem mode to check/lowmem.h Qu Wenruo
2018-01-19  5:37 ` [PATCH 04/16] btrfs-progs: check: Move node_ptr structure to check/common.h Qu Wenruo
2018-01-19  5:52   ` Su Yue
2018-01-19  5:53     ` Qu Wenruo
2018-01-19  5:37 ` [PATCH 05/16] btrfs-progs: check: Export check global variables " Qu Wenruo
2018-01-19  6:55   ` Su Yue
2018-01-19  7:26     ` Qu Wenruo
2018-01-19  5:37 ` [PATCH 06/16] btrfs-progs: check: Move imode_to_type function " Qu Wenruo
2018-01-19  5:37 ` [PATCH 07/16] btrfs-progs: check: Move fs_root_objectid " Qu Wenruo
2018-01-19  5:37 ` [PATCH 08/16] btrfs-progs: check: Move count_csum_range function to check/common.c Qu Wenruo
2018-01-19  6:46   ` Su Yue
2018-01-19  5:37 ` [PATCH 09/16] btrfs-progs: check: Move __create_inode_item " Qu Wenruo
2018-01-19  5:37 ` [PATCH 10/16] btrfs-progs: check: Move link_inode_to_lostfound function to common.c Qu Wenruo
2018-01-19  5:37 ` [PATCH 11/16] btrfs-progs: check: Move check_dev_size_alignment to check/common.c Qu Wenruo
2018-01-19  5:37 ` [PATCH 12/16] btrfs-progs: check: move reada_walk_down " Qu Wenruo
2018-01-19  5:37 ` [PATCH 13/16] btrfs-progs: check: Move check_child_node " Qu Wenruo
2018-01-19  5:37 ` [PATCH 14/16] btrfs-progs: check: Move reset_cached_block_groups " Qu Wenruo
2018-01-19  5:37 ` [PATCH 16/16] btrfs-progs: check/lowmem: Cleanup unnecessary _v2 suffix Qu Wenruo
2018-01-19  7:50 ` [PATCH 00/16] btrfs-progs: Split lowmem mode check to its own Su Yue
2018-01-31 18:26 ` David Sterba
2018-02-01  5:00   ` 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.