From patchwork Thu Mar 24 06:33:21 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsutomu Itoh X-Patchwork-Id: 657891 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p2O6Ykaj028828 for ; Thu, 24 Mar 2011 06:34:47 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932238Ab1CXGeo (ORCPT ); Thu, 24 Mar 2011 02:34:44 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:36259 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932228Ab1CXGen (ORCPT ); Thu, 24 Mar 2011 02:34:43 -0400 Received: from m4.gw.fujitsu.co.jp (unknown [10.0.50.74]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id A3D843EE0B5 for ; Thu, 24 Mar 2011 15:34:41 +0900 (JST) Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 8A22545DE51 for ; Thu, 24 Mar 2011 15:34:41 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.fujitsu.co.jp [10.0.50.94]) by m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 6827C45DE4E for ; Thu, 24 Mar 2011 15:34:41 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 5D099E78003 for ; Thu, 24 Mar 2011 15:34:41 +0900 (JST) Received: from ml14.s.css.fujitsu.com (ml14.s.css.fujitsu.com [10.240.81.134]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 281951DB8037 for ; Thu, 24 Mar 2011 15:34:41 +0900 (JST) Received: from ml14.css.fujitsu.com (ml14 [127.0.0.1]) by ml14.s.css.fujitsu.com (Postfix) with ESMTP id F28229F6E5A; Thu, 24 Mar 2011 15:34:40 +0900 (JST) Received: from T-ITOH1.jp.fujitsu.com (unknown [10.124.101.86]) by ml14.s.css.fujitsu.com (Postfix) with SMTP id A3F9A9F6E51; Thu, 24 Mar 2011 15:34:40 +0900 (JST) X-SecurityPolicyCheck-FJ: OK by FujitsuOutboundMailChecker v1.4.0 Received: from T-ITOH1[10.124.101.86] by T-ITOH1 (FujitsuOutboundMailChecker v1.4.0/9992[10.124.101.86]); Thu, 24 Mar 2011 15:33:41 +0900 (JST) Message-Id: <201103240633.AA00011@T-ITOH1.jp.fujitsu.com> From: Tsutomu Itoh Date: Thu, 24 Mar 2011 15:33:21 +0900 To: linux-btrfs@vger.kernel.org Cc: chris.mason@oracle.com Subject: [PATCH] Btrfs: check return value of read_tree_block() MIME-Version: 1.0 X-Mailer: AL-Mail32 Version 1.13 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 (demeter1.kernel.org [140.211.167.41]); Thu, 24 Mar 2011 06:34:47 +0000 (UTC) diff -urNp linux-2.6.38/fs/btrfs/ctree.c linux-2.6.38.new/fs/btrfs/ctree.c --- linux-2.6.38/fs/btrfs/ctree.c 2011-03-15 10:20:32.000000000 +0900 +++ linux-2.6.38.new/fs/btrfs/ctree.c 2011-03-24 11:12:54.000000000 +0900 @@ -686,6 +686,8 @@ int btrfs_realloc_node(struct btrfs_tran if (!cur) { cur = read_tree_block(root, blocknr, blocksize, gen); + if (!cur) + return -EIO; } else if (!uptodate) { btrfs_read_buffer(cur, gen); } @@ -4217,6 +4219,7 @@ find_next_key: } btrfs_set_path_blocking(path); cur = read_node_slot(root, cur, slot); + BUG_ON(!cur); btrfs_tree_lock(cur); diff -urNp linux-2.6.38/fs/btrfs/extent-tree.c linux-2.6.38.new/fs/btrfs/extent-tree.c --- linux-2.6.38/fs/btrfs/extent-tree.c 2011-03-15 10:20:32.000000000 +0900 +++ linux-2.6.38.new/fs/btrfs/extent-tree.c 2011-03-24 11:32:55.000000000 +0900 @@ -6047,6 +6047,8 @@ static noinline int do_walk_down(struct if (reada && level == 1) reada_walk_down(trans, root, wc, path); next = read_tree_block(root, bytenr, blocksize, generation); + if (!next) + return -EIO; btrfs_tree_lock(next); btrfs_set_lock_blocking(next); } @@ -7906,6 +7908,10 @@ static noinline int relocate_one_extent( eb = read_tree_block(found_root, block_start, block_size, 0); + if (!eb) { + ret = -EIO; + goto out; + } btrfs_tree_lock(eb); BUG_ON(level != btrfs_header_level(eb)); diff -urNp linux-2.6.38/fs/btrfs/relocation.c linux-2.6.38.new/fs/btrfs/relocation.c --- linux-2.6.38/fs/btrfs/relocation.c 2011-03-15 10:20:32.000000000 +0900 +++ linux-2.6.38.new/fs/btrfs/relocation.c 2011-03-24 11:43:53.000000000 +0900 @@ -1724,6 +1724,7 @@ again: eb = read_tree_block(dest, old_bytenr, blocksize, old_ptr_gen); + BUG_ON(!eb); btrfs_tree_lock(eb); if (cow) { ret = btrfs_cow_block(trans, dest, eb, parent, @@ -2513,6 +2514,10 @@ static int do_relocation(struct btrfs_tr blocksize = btrfs_level_size(root, node->level); generation = btrfs_node_ptr_generation(upper->eb, slot); eb = read_tree_block(root, bytenr, blocksize, generation); + if (!eb) { + err = -EIO; + goto next; + } btrfs_tree_lock(eb); btrfs_set_lock_blocking(eb); @@ -2670,6 +2675,7 @@ static int get_tree_block_key(struct rel BUG_ON(block->key_ready); eb = read_tree_block(rc->extent_root, block->bytenr, block->key.objectid, block->key.offset); + BUG_ON(!eb); WARN_ON(btrfs_header_level(eb) != block->level); if (block->level == 0) btrfs_item_key_to_cpu(eb, &block->key, 0);