Skip to contentSkip to conversation

bytrfs-progs: Print error on invalid extent item format during check

PATCH Applied Nikolay Borisov 3 participants 3 messages Dec 29, 2017 – Jan 25, 2018 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bytrfs-progs: Print error on invalid extent item format during check

While performing normal mode check if the code comes across an invalid extent format it will just BUG() and exit without printing any useful information for debugging. Improve the situation by outputting the key/leaf bytenr/slot which will enable to quickly inspect the tree and see what the corruption is.

---
 cmds-check.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
cmds-check.c +6 -1
index a93ac2c88a38..371516709ed8 100644
@@ -8362,7 +8362,12 @@ static int process_extent_item(struct btrfs_root *root,
 	if (item_size < sizeof(*ei)) {
 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
 		struct btrfs_extent_item_v0 *ei0;
-		BUG_ON(item_size != sizeof(*ei0));
+		if (item_size != sizeof(*ei0)) {
+			error("invalid extent item format: ITEM[%llu %u %llu] leaf: %llu slot: %d",
+			      key.objectid, key.type, key.offset,
+			      btrfs_header_bytenr(eb), slot);
+			BUG();
+		}
 		ei0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_item_v0);
 		refs = btrfs_extent_refs_v0(eb, ei0);
 #else
Signature · 1 line
2.7.4
Applied
#1 lore raw
Quoted 7 lines · Nikolay Borisov

While performing normal mode check if the code comes across an invalid extent format it will just BUG() and exit without printing any useful information for debugging. Improve the situation by outputting the key/leaf bytenr/slot which will enable to quickly inspect the tree and see what the corruption is.

Applied, thanks.

Quoted 9 lines
---
 cmds-check.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
cmds-check.c +0 -0
index a93ac2c88a38..371516709ed8 100644

cmds-check.c static int process_extent_item(struct btrfs_root *root, · line 8366

Quoted 6 lines
cmds-check.c +2 -1
@@ -8362,7 +8362,12 @@ static int process_extent_item(struct btrfs_root *root,
 	if (item_size < sizeof(*ei)) {
 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
 		struct btrfs_extent_item_v0 *ei0;
-		BUG_ON(item_size != sizeof(*ei0));
+		if (item_size != sizeof(*ei0)) {
+			error("invalid extent item format: ITEM[%llu %u %llu] leaf: %llu slot: %d",

String un-indented.