Skip to contentSkip to conversation

btrfs: Don't panic when we can't find a root key

PATCH In review Qu Wenruo 2 participants 2 messages Feb 26, 2019 – Feb 27, 2019 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH v2 1/1 btrfs: Don't panic when we can't find a root key

When we failed to find a root key in btrfs_update_root(), we just panic.

That's definitely not cool, fix it by outputting an unique error message, aborting current transaction and return -EUCLEAN.

---
changelog:
v2:
- Remove the tree leaf dump, as it doesn't help much.
- Change return value to -EUCLEAN to show it's a corruption.

---
 fs/btrfs/root-tree.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
fs/btrfs/root-tree.c +8 -5
index 65bda0682928..7f5c98afce25 100644
@@ -137,11 +137,14 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
 		goto out;
 	}
 
-	if (ret != 0) {
-		btrfs_print_leaf(path->nodes[0]);
-		btrfs_crit(fs_info, "unable to update root key %llu %u %llu",
-			   key->objectid, key->type, key->offset);
-		BUG_ON(1);
+	if (ret > 0) {
+		btrfs_crit(fs_info,
+			"unable to find root key (%llu %u %llu) in tree %llu",
+			   key->objectid, key->type, key->offset,
+			   root->root_key.objectid);
+		ret = -EUCLEAN;
+		btrfs_abort_transaction(trans, ret);
+		goto out;
 	}
 
 	l = path->nodes[0];
Signature · 1 line
2.21.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Qu Wenruo

When we failed to find a root key in btrfs_update_root(), we just panic.

That's definitely not cool, fix it by outputting an unique error message, aborting current transaction and return -EUCLEAN.

I've added a sentence why the error should not normally happen.