All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: <calestyo@scientia.net>, <chris@colorremedies.com>,
	<dsterba@suse.cz>, Su Yue <suy.fnst@cn.fujitsu.com>
Subject: [PATCH v2 12/12] btrfs-progs: cmds-check.c: walk_down_tree_v2 break cause of leaf process
Date: Mon, 6 Feb 2017 13:47:35 +0800	[thread overview]
Message-ID: <20170206054735.5227-13-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <20170206054735.5227-1-quwenruo@cn.fujitsu.com>

From: Su Yue <suy.fnst@cn.fujitsu.com>

In lowmem mode, 'walk_down_tree_v2' returns negative values wheather
the error is fatal or not. It causes the loop where 'walk_down_tree_v2'
is to break even the error is tolerated and then subsequent nodes process
will be skipped.

Fix it by redefining meanings of values 'walk_down_tree_v2' returns.
Do a similar fix for 'process_one_leaf_v2'.

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

diff --git a/cmds-check.c b/cmds-check.c
index 7d273623..fae18e00 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -1868,6 +1868,11 @@ static int update_nodes_refs(struct btrfs_root *root, u64 bytenr,
 static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path,
 			    unsigned int ext_ref);
 
+/*
+ * Returns >0  Found error, not fatal, should continue process
+ * Returns <0  Fata error, must exit the whole check
+ * returns 0   No error is found
+ */
 static int process_one_leaf_v2(struct btrfs_root *root, struct btrfs_path *path,
 			       struct node_refs *nrefs, int *level, int ext_ref)
 {
@@ -1937,13 +1942,8 @@ again:
 	}
 out:
 	err &= ~LAST_ITEM;
-	/*
-	 * Convert any error bitmap to -EIO, as we should avoid
-	 * mixing positive and negative return value to represent
-	 * error
-	 */
 	if (err && !ret)
-		ret = -EIO;
+		ret = err;
 	return ret;
 }
 
@@ -2213,6 +2213,11 @@ out:
 static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path,
 			    unsigned int ext_ref);
 
+/*
+ * Returns >0  Found error, should continue
+ * Returns 0   No error is found
+ * Returns <0  Fatal error, must exit the whole check
+ */
 static int walk_down_tree_v2(struct btrfs_root *root, struct btrfs_path *path,
 			     int *level, struct node_refs *nrefs, int ext_ref)
 {
@@ -5028,8 +5033,9 @@ static int check_fs_root_v2(struct btrfs_root *root, unsigned int ext_ref)
 	struct btrfs_path path;
 	struct node_refs nrefs;
 	struct btrfs_root_item *root_item = &root->root_item;
-	int ret, wret;
+	int ret;
 	int level;
+	int err = 0;
 
 	/*
 	 * We need to manually check the first inode item(256)
@@ -5063,16 +5069,17 @@ static int check_fs_root_v2(struct btrfs_root *root, unsigned int ext_ref)
 	}
 
 	while (1) {
-		wret = walk_down_tree_v2(root, &path, &level, &nrefs, ext_ref);
-		if (wret < 0)
-			ret = wret;
-		if (wret != 0)
+		ret = walk_down_tree_v2(root, &path, &level, &nrefs, ext_ref);
+		err |= !!ret;
+
+		/* if ret is negative, walk shall stop */
+		if (ret < 0) {
+			ret = err;
 			break;
+		}
 
-		wret = walk_up_tree_v2(root, &path, &level);
-		if (wret < 0)
-			ret = wret;
-		if (wret != 0)
+		ret = walk_up_tree_v2(root, &path, &level);
+		if (ret != 0)
 			break;
 	}
 
-- 
2.11.0




  parent reply	other threads:[~2017-02-06  5:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-06  5:47 [PATCH v2 00/12] Variant lowmem mode fixes Qu Wenruo
2017-02-06  5:47 ` [PATCH v2 01/12] btrfs-progs: lowmem check: Fix several bugs related to afterward search Qu Wenruo
2017-02-06  5:47 ` [PATCH v2 02/12] btrfs-progs: check: Output verbose error when fsck found a bug in any tree Qu Wenruo
2017-02-06  5:47 ` [PATCH v2 03/12] btrfs-progs: lowmem check: Fix false alert in checking data extent csums Qu Wenruo
2017-02-06  5:47 ` [PATCH v2 04/12] btrfs-progs: lowmem check: Fix extent item size false alert Qu Wenruo
2017-02-06  5:47 ` [PATCH v2 05/12] btrfs-progs: lowmem check: Fix false alert on inline compressed extent Qu Wenruo
2017-02-06  5:47 ` [PATCH v2 06/12] btrfs-progs: lowmem check: Fix silent error if first inode item missing Qu Wenruo
2017-02-06  5:47 ` [PATCH v2 07/12] btrfs-progs: tests: Move fsck-tests/015 to fuzz tests Qu Wenruo
2017-02-06  5:47 ` [PATCH v2 08/12] btrfs-progs: fsck-test: Add test image for lowmem mode block group false alert Qu Wenruo
2017-02-06  5:47 ` [PATCH v2 09/12] btrfs-progs: fsck-test: Make 013 compatible with lowmem mode Qu Wenruo
2017-02-06  5:47 ` [PATCH v2 10/12] btrfs-progs: fsck-test: Add new test case for file extent false alerts Qu Wenruo
2017-02-06  5:47 ` [PATCH v2 11/12] btrfs-progs: fsck: Fix lowmem mode override to allow it skip repair work Qu Wenruo
2017-02-06  5:47 ` Qu Wenruo [this message]
2017-02-06  8:51   ` [PATCH v2 12/12] btrfs-progs: cmds-check.c: walk_down_tree_v2 break cause of leaf process Qu Wenruo

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20170206054735.5227-13-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=calestyo@scientia.net \
    --cc=chris@colorremedies.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=suy.fnst@cn.fujitsu.com \
    /path/to/YOUR_REPLY

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

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