[v2] btrfs: fix oops on failure path
diff mbox

Message ID BANLkTindeWYaCu3ppdHK9sgOMRcFoAU+sw@mail.gmail.com
State New, archived
Headers show

Commit Message

Daniel J Blueman June 23, 2011, 3:01 p.m. UTC
On 23 June 2011 18:31, David Sterba <dave@jikos.cz> wrote:
> Hi,
>
> On Sun, Jun 19, 2011 at 06:53:28PM +0800, Daniel J Blueman wrote:
>> I hit this BTRFS oops [1] in 3.0-rc3, clearly due to filesystem corruption.
>>
>> If lookup_extent_backref fails, path->nodes[0] reasonably could be
>> null, so look before leaping [2].

> I think the check should be placed into btrfs_print_leaf, this function
> is mostly called before a BUG after some error condition. The
> extent_buffer leaf argument could be NULL in more cases (i've seen at
> least another 2). Otherwise the if-NULL check would have to be placed
> before each call of btrfs_print_leaf.

The other cases where btrfs_print_leaf can be called with NULL are a
good reason. Updated patch:
(how does one follow up an email in git send-email with the message id?)

If lookup_extent_backref fails, path->nodes[0] reasonably could be
null along with other callers of btrfs_print_leaf, so ensure we have a
valid extent buffer before dereferencing.

Signed-off-by: Daniel J Blueman <daniel.blueman@gmail.com>

 	struct btrfs_dir_item *di;
@@ -172,6 +171,11 @@ void btrfs_print_leaf(struct btrfs_root *root,
struct extent_buffer *l)
 	struct btrfs_key key;
 	struct btrfs_key found_key;

+	if (!l)
+		return;
+
+	nr = btrfs_header_nritems(l);
+
 	printk(KERN_INFO "leaf %llu total ptrs %d free space %d\n",
 		(unsigned long long)btrfs_header_bytenr(l), nr,
 		btrfs_leaf_free_space(root, l));

Comments

David Sterba June 23, 2011, 4:36 p.m. UTC | #1
On Thu, Jun 23, 2011 at 11:01:01PM +0800, Daniel J Blueman wrote:
> On 23 June 2011 18:31, David Sterba <dave@jikos.cz> wrote:
> (how does one follow up an email in git send-email with the message id?)

git-send-email --in-reply-to=<identifier>

(if it does not ask for it) and paste identifier from mail header
In-Reply-To:

> If lookup_extent_backref fails, path->nodes[0] reasonably could be
> null along with other callers of btrfs_print_leaf, so ensure we have a
> valid extent buffer before dereferencing.

ack.


thanks,
david

> 
> Signed-off-by: Daniel J Blueman <daniel.blueman@gmail.com>
> 
> diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
> index fb2605d..f38e452 100644
> --- a/fs/btrfs/print-tree.c
> +++ b/fs/btrfs/print-tree.c
> @@ -158,8 +158,7 @@ static void print_extent_ref_v0(struct
> extent_buffer *eb, int slot)
>  void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
>  {
>  	int i;
> -	u32 type;
> -	u32 nr = btrfs_header_nritems(l);
> +	u32 type, nr;
>  	struct btrfs_item *item;
>  	struct btrfs_root_item *ri;
>  	struct btrfs_dir_item *di;
> @@ -172,6 +171,11 @@ void btrfs_print_leaf(struct btrfs_root *root,
> struct extent_buffer *l)
>  	struct btrfs_key key;
>  	struct btrfs_key found_key;
> 
> +	if (!l)
> +		return;
> +
> +	nr = btrfs_header_nritems(l);
> +
>  	printk(KERN_INFO "leaf %llu total ptrs %d free space %d\n",
>  		(unsigned long long)btrfs_header_bytenr(l), nr,
>  		btrfs_leaf_free_space(root, l));
> -- 
> Daniel J Blueman
--
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
Mitch Harder June 27, 2011, 10:27 p.m. UTC | #2
On Thu, Jun 23, 2011 at 11:36 AM, David Sterba <dave@jikos.cz> wrote:
> On Thu, Jun 23, 2011 at 11:01:01PM +0800, Daniel J Blueman wrote:
>> On 23 June 2011 18:31, David Sterba <dave@jikos.cz> wrote:
>> (how does one follow up an email in git send-email with the message id?)
>
> git-send-email --in-reply-to=<identifier>
>
> (if it does not ask for it) and paste identifier from mail header
> In-Reply-To:
>
>> If lookup_extent_backref fails, path->nodes[0] reasonably could be
>> null along with other callers of btrfs_print_leaf, so ensure we have a
>> valid extent buffer before dereferencing.
>
> ack.
>
>
> thanks,
> david
>
>>
>> Signed-off-by: Daniel J Blueman <daniel.blueman@gmail.com>
>>
>> diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
>> index fb2605d..f38e452 100644
>> --- a/fs/btrfs/print-tree.c
>> +++ b/fs/btrfs/print-tree.c
>> @@ -158,8 +158,7 @@ static void print_extent_ref_v0(struct
>> extent_buffer *eb, int slot)
>>  void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
>>  {
>>       int i;
>> -     u32 type;
>> -     u32 nr = btrfs_header_nritems(l);
>> +     u32 type, nr;
>>       struct btrfs_item *item;
>>       struct btrfs_root_item *ri;
>>       struct btrfs_dir_item *di;
>> @@ -172,6 +171,11 @@ void btrfs_print_leaf(struct btrfs_root *root,
>> struct extent_buffer *l)
>>       struct btrfs_key key;
>>       struct btrfs_key found_key;
>>
>> +     if (!l)
>> +             return;
>> +
>> +     nr = btrfs_header_nritems(l);
>> +
>>       printk(KERN_INFO "leaf %llu total ptrs %d free space %d\n",
>>               (unsigned long long)btrfs_header_bytenr(l), nr,
>>               btrfs_leaf_free_space(root, l));
>> --
>> Daniel J Blueman
> --
> 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
>

I've also run into a corruption with spots where path->nodes[0] has a
value of NULL.

But, I'm getting the error showing up elsewhere when I try to mount
the partition:

[ 6168.790849] device fsid 7c35237f-d72a-4d65-bd01-b853d853c17a devid
1 transid 507394 /dev/sdb6
[ 6168.832825] attempt to access beyond end of device
[ 6168.832831] sdb6: rw=0, want=20033720, limit=20016927
[ 6168.832843] Failed to read block groups: -5
[ 6168.833663] btrfs: open_ctree failed

In my case, I need to handle the corruption earlier in order to
properly handle the error.

Btrfs-progs also has troubles handling this corruption (debugging
btrfsck was how I discovered I was running into path->nodes[0] ==
NULL).

For reference, I'm using a 2.6.39.1 kernel with Chris' latest
'for-linus' branch merged in.
--
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

Patch
diff mbox

diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index fb2605d..f38e452 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c
@@ -158,8 +158,7 @@  static void print_extent_ref_v0(struct
extent_buffer *eb, int slot)
 void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
 {
 	int i;
-	u32 type;
-	u32 nr = btrfs_header_nritems(l);
+	u32 type, nr;
 	struct btrfs_item *item;
 	struct btrfs_root_item *ri;