Skip to contentSkip to conversation

btrfs-progs: check: Don't do early exit if maybe_repair_root_item() can't find needed root extent

PATCH In review Qu Wenruo 2 participants 2 messages Apr 29, 2020 – May 11, 2020 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH 1/1 btrfs-progs: check: Don't do early exit if maybe_repair_root_item() can't find needed root extent

The whole maybe_repair_root_item() and repair_root_items() functions are introduced to handle an ancient bug in v3.17.

However in certain extent tree corruption case, such early exit would only exit the whole check process early on, preventing user to know what's really wrong about the fs.

So this patch will allow the check to continue, since the ancient bug is no long that common.

---
 check/main.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)
check/main.c +20 -12
index be980c152274..ac11a35125b8 100644
@@ -10306,20 +10306,28 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
 			err = !!ret;
 			errno = -ret;
 			error("failed to repair root items: %m");
-			goto close_out;
-		}
-		if (repair) {
-			fprintf(stderr, "Fixed %d roots.\n", ret);
-			ret = 0;
-		} else if (ret > 0) {
-			fprintf(stderr,
+			/*
+			 * For repair, if we can't repair root items, it's
+			 * fatal.
+			 * But for non-repair, it's pretty rare to hit such
+			 * v3.17 era bug, we want to continue check.
+			 */
+			if (repair)
+				goto close_out;
+			err |= 1;
+		} else {
+			if (repair) {
+				fprintf(stderr, "Fixed %d roots.\n", ret);
+				ret = 0;
+			} else if (ret > 0) {
+				fprintf(stderr,
 				"Found %d roots with an outdated root item.\n",
-				ret);
-			fprintf(stderr,
+					ret);
+				fprintf(stderr,
 	"Please run a filesystem check with the option --repair to fix them.\n");
-			ret = 1;
-			err |= ret;
-			goto close_out;
+				ret = 1;
+				err |= ret;
+			}
 		}
 	} else {
 		fprintf(stderr, "[1/7] checking root items... skipped\n");
Signature · 1 line
2.26.2
#1 lore raw
Quoted 11 lines · Qu Wenruo

The whole maybe_repair_root_item() and repair_root_items() functions are introduced to handle an ancient bug in v3.17.

However in certain extent tree corruption case, such early exit would only exit the whole check process early on, preventing user to know what's really wrong about the fs.

So this patch will allow the check to continue, since the ancient bug is no long that common.

Added to devel, thanks.