From patchwork Mon Aug 15 19:50:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Mahoney X-Patchwork-Id: 1068882 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p7FJrJrT005972 for ; Mon, 15 Aug 2011 19:53:19 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752657Ab1HOTxM (ORCPT ); Mon, 15 Aug 2011 15:53:12 -0400 Received: from cantor2.suse.de ([195.135.220.15]:48611 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752599Ab1HOTxJ (ORCPT ); Mon, 15 Aug 2011 15:53:09 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id BDAED8F29D for ; Mon, 15 Aug 2011 21:53:06 +0200 (CEST) Message-Id: <20110815195233.066845613@suse.com> User-Agent: quilt/0.48-18.3 Date: Mon, 15 Aug 2011 15:50:50 -0400 From: Jeff Mahoney To: Btrfs Development List Subject: [patch v2 8/9] btrfs: Push up btrfs_pin_extent failures References: <20110815195042.559654068@suse.com> Content-Disposition: inline; filename=btrfs-push-up-btrfs_pin_extent-failures 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]); Mon, 15 Aug 2011 19:53:19 +0000 (UTC) btrfs_pin_extent looks up a block group and then calls pin_down_extent with it. If the lookup fails, it should return -ENOENT to allow callers to handle the error condition. For the three existing callers, it is a logic error if the lookup fails and a panic will occur. Signed-off-by: Jeff Mahoney --- fs/btrfs/extent-tree.c | 20 +++++++++++++++----- fs/btrfs/tree-log.c | 10 +++++++--- 2 files changed, 22 insertions(+), 8 deletions(-) -- 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 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2075,8 +2075,14 @@ static int run_one_delayed_ref(struct bt BUG_ON(extent_op); head = btrfs_delayed_node_to_head(node); if (insert_reserved) { - btrfs_pin_extent(root, node->bytenr, - node->num_bytes, 1); + ret = btrfs_pin_extent(root, node->bytenr, + node->num_bytes, 1); + if (ret) + btrfs_panic(root->fs_info, ret, + "Cannot pin extent in range " + "%llu(%llu)\n", + node->bytenr, node->num_bytes); + if (head->is_data) { ret = btrfs_del_csums(trans, root, node->bytenr, @@ -4205,7 +4211,8 @@ int btrfs_pin_extent(struct btrfs_root * struct btrfs_block_group_cache *cache; cache = btrfs_lookup_block_group(root->fs_info, bytenr); - BUG_ON(!cache); + if (cache == NULL) + return -ENOENT; pin_down_extent(root, cache, bytenr, num_bytes, reserved); @@ -4765,8 +4772,11 @@ int btrfs_free_extent(struct btrfs_trans if (root_objectid == BTRFS_TREE_LOG_OBJECTID) { WARN_ON(owner >= BTRFS_FIRST_FREE_OBJECTID); /* unlocks the pinned mutex */ - btrfs_pin_extent(root, bytenr, num_bytes, 1); - ret = 0; + ret = btrfs_pin_extent(root, bytenr, num_bytes, 1); + if (ret) + btrfs_panic(root->fs_info, ret, "Cannot pin " + "extent in range %llu(%llu)\n", + bytenr, num_bytes); } else if (owner < BTRFS_FIRST_FREE_OBJECTID) { ret = btrfs_add_delayed_tree_ref(trans, bytenr, num_bytes, parent, root_objectid, (int)owner, --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -275,9 +275,13 @@ static int process_one_buffer(struct btr struct extent_buffer *eb, struct walk_control *wc, u64 gen) { - if (wc->pin) - btrfs_pin_extent(log->fs_info->extent_root, - eb->start, eb->len, 0); + if (wc->pin) { + int ret = btrfs_pin_extent(log->fs_info->extent_root, + eb->start, eb->len, 0); + if (ret) + btrfs_panic(log->fs_info, ret, "Cannot pin extent in " + "range %llu(%llu)\n", eb->start, eb->len); + } if (btrfs_buffer_uptodate(eb, gen)) { if (wc->write)