From patchwork Thu Jun 23 15:01:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel J Blueman X-Patchwork-Id: 909082 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5NF17D4019944 for ; Thu, 23 Jun 2011 15:01:08 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757939Ab1FWPBD (ORCPT ); Thu, 23 Jun 2011 11:01:03 -0400 Received: from mail-qy0-f181.google.com ([209.85.216.181]:60657 "EHLO mail-qy0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754264Ab1FWPBC (ORCPT ); Thu, 23 Jun 2011 11:01:02 -0400 Received: by qyk9 with SMTP id 9so1105684qyk.19 for ; Thu, 23 Jun 2011 08:01:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=/rX9b+CkgXo/fzL4QdJr4QngpawzRAbLW9K2sQbLm20=; b=dkRTTUSip0ZPailIRe5Ralp49bz8mrBITvGt53Ffds3Q2itORRxm+CAS38eK9ymV39 OfSCWyw/scM0hf+mRIC1OlKLtXrLWYGPbJ2645aQefLrOgx4MVk//wKNp9NU/gfq5jIu mL2nUKIjNwdaLRfIvU0PA3cle5AC5tM4jMxpU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=Fx/qXh7TmV8xULB2Ar4ZigWqcgnVbCbHEa0akggEG4HU2AdVdTlfsZGoXTlSukslt1 AV/MBoh2FzjMmFMfRMy8zoOV7U/62Y4izJGXZDIExja+fl9A7BCt/LI98lyNzhM6cLcL te/5yJBUwy2VRA7ynbMOQUReqEbaQi4x9IwDc= MIME-Version: 1.0 Received: by 10.224.186.5 with SMTP id cq5mr1507533qab.373.1308841261145; Thu, 23 Jun 2011 08:01:01 -0700 (PDT) Received: by 10.224.6.133 with HTTP; Thu, 23 Jun 2011 08:01:01 -0700 (PDT) In-Reply-To: <20110623103109.GN12709@twin.jikos.cz> References: <20110623103109.GN12709@twin.jikos.cz> Date: Thu, 23 Jun 2011 23:01:01 +0800 Message-ID: Subject: [PATCH v2] btrfs: fix oops on failure path From: Daniel J Blueman To: dave@jikos.cz, Chris Mason Cc: Linux BTRFS Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Thu, 23 Jun 2011 15:01:08 +0000 (UTC) On 23 June 2011 18:31, David Sterba 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 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)); 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;