diff mbox

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

Message ID 1514538104-20005-1-git-send-email-nborisov@suse.com (mailing list archive)
State New, archived
Headers show

Commit Message

Nikolay Borisov Dec. 29, 2017, 9:01 a.m. UTC
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.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 cmds-check.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

David Sterba Jan. 8, 2018, 7:29 p.m. UTC | #1
On Fri, Dec 29, 2017 at 11:01:44AM +0200, Nikolay Borisov wrote:
> 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.
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

Applied, thanks.

> ---
>  cmds-check.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/cmds-check.c b/cmds-check.c
> index a93ac2c88a38..371516709ed8 100644
> --- a/cmds-check.c
> +++ b/cmds-check.c
> @@ -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.
--
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
Anand Jain Jan. 25, 2018, 5:56 a.m. UTC | #2
nitpick:

  typo in $subject.

Thanks, Anand
--
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
diff mbox

Patch

diff --git a/cmds-check.c b/cmds-check.c
index a93ac2c88a38..371516709ed8 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -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