linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Mahoney <jeffm@suse.com>
To: Linux Btrfs List <linux-btrfs@vger.kernel.org>
Cc: David Sterba <dsterba@suse.com>
Subject: [patch 02/35] btrfs: Catch locking failures in {set,clear,convert}_extent_bit
Date: Wed, 21 Mar 2012 21:11:06 -0400	[thread overview]
Message-ID: <20120322011133.260932864@suse.com> (raw)
In-Reply-To: 20120322011104.212214639@suse.com

The *_state functions can only return 0 or -EEXIST. This patch addresses
the cases where those functions returning -EEXIST represent a locking
failure. It handles them by panicking with an appropriate error message.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/extent_io.c |   58 ++++++++++++++++++++++++++++++++-----------------
 1 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index a55fbe6..601f23b 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -53,6 +53,12 @@ struct extent_page_data {
 	unsigned int sync_io:1;
 };
 
+static inline struct btrfs_fs_info *
+tree_fs_info(struct extent_io_tree *tree)
+{
+	return btrfs_sb(tree->mapping->host->i_sb);
+}
+
 int __init extent_io_init(void)
 {
 	extent_state_cache = kmem_cache_create("extent_state",
@@ -439,6 +445,13 @@ alloc_extent_state_atomic(struct extent_state *prealloc)
 	return prealloc;
 }
 
+void extent_io_tree_panic(struct extent_io_tree *tree, int err)
+{
+	btrfs_panic(tree_fs_info(tree), err, "Locking error: "
+		    "Extent tree was modified by another "
+		    "thread while locked.");
+}
+
 /*
  * clear some bits on a range in the tree.  This may require splitting
  * or inserting elements in the tree, so the gfp mask is used to
@@ -542,7 +555,9 @@ hit_next:
 		prealloc = alloc_extent_state_atomic(prealloc);
 		BUG_ON(!prealloc);
 		err = split_state(tree, state, prealloc, start);
-		BUG_ON(err == -EEXIST);
+		if (err)
+			extent_io_tree_panic(tree, err);
+
 		prealloc = NULL;
 		if (err)
 			goto out;
@@ -564,7 +579,9 @@ hit_next:
 		prealloc = alloc_extent_state_atomic(prealloc);
 		BUG_ON(!prealloc);
 		err = split_state(tree, state, prealloc, end + 1);
-		BUG_ON(err == -EEXIST);
+		if (err)
+			extent_io_tree_panic(tree, err);
+
 		if (wake)
 			wake_up(&state->wq);
 
@@ -742,8 +759,10 @@ again:
 		prealloc = alloc_extent_state_atomic(prealloc);
 		BUG_ON(!prealloc);
 		err = insert_state(tree, prealloc, start, end, &bits);
+		if (err)
+			extent_io_tree_panic(tree, err);
+
 		prealloc = NULL;
-		BUG_ON(err == -EEXIST);
 		goto out;
 	}
 	state = rb_entry(node, struct extent_state, rb_node);
@@ -809,7 +828,9 @@ hit_next:
 		prealloc = alloc_extent_state_atomic(prealloc);
 		BUG_ON(!prealloc);
 		err = split_state(tree, state, prealloc, start);
-		BUG_ON(err == -EEXIST);
+		if (err)
+			extent_io_tree_panic(tree, err);
+
 		prealloc = NULL;
 		if (err)
 			goto out;
@@ -846,12 +867,9 @@ hit_next:
 		 */
 		err = insert_state(tree, prealloc, start, this_end,
 				   &bits);
-		BUG_ON(err == -EEXIST);
-		if (err) {
-			free_extent_state(prealloc);
-			prealloc = NULL;
-			goto out;
-		}
+		if (err)
+			extent_io_tree_panic(tree, err);
+
 		cache_state(prealloc, cached_state);
 		prealloc = NULL;
 		start = this_end + 1;
@@ -873,7 +891,8 @@ hit_next:
 		prealloc = alloc_extent_state_atomic(prealloc);
 		BUG_ON(!prealloc);
 		err = split_state(tree, state, prealloc, end + 1);
-		BUG_ON(err == -EEXIST);
+		if (err)
+			extent_io_tree_panic(tree, err);
 
 		set_state_bits(tree, prealloc, &bits);
 		cache_state(prealloc, cached_state);
@@ -946,7 +965,8 @@ again:
 		}
 		err = insert_state(tree, prealloc, start, end, &bits);
 		prealloc = NULL;
-		BUG_ON(err == -EEXIST);
+		if (err)
+			extent_io_tree_panic(tree, err);
 		goto out;
 	}
 	state = rb_entry(node, struct extent_state, rb_node);
@@ -1002,7 +1022,8 @@ hit_next:
 			goto out;
 		}
 		err = split_state(tree, state, prealloc, start);
-		BUG_ON(err == -EEXIST);
+		if (err)
+			extent_io_tree_panic(tree, err);
 		prealloc = NULL;
 		if (err)
 			goto out;
@@ -1041,12 +1062,8 @@ hit_next:
 		 */
 		err = insert_state(tree, prealloc, start, this_end,
 				   &bits);
-		BUG_ON(err == -EEXIST);
-		if (err) {
-			free_extent_state(prealloc);
-			prealloc = NULL;
-			goto out;
-		}
+		if (err)
+			extent_io_tree_panic(tree, err);
 		prealloc = NULL;
 		start = this_end + 1;
 		goto search_again;
@@ -1065,7 +1082,8 @@ hit_next:
 		}
 
 		err = split_state(tree, state, prealloc, end + 1);
-		BUG_ON(err == -EEXIST);
+		if (err)
+			extent_io_tree_panic(tree, err);
 
 		set_state_bits(tree, prealloc, &bits);
 		clear_state_bit(tree, prealloc, &clear_bits, 0);
-- 
1.7.9




  parent reply	other threads:[~2012-03-22  1:11 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-22  1:11 [patch 00/35] btrfs: Error Handling Patchset Jeff Mahoney
2012-03-22  1:11 ` [patch 01/35] btrfs: Add btrfs_panic() Jeff Mahoney
2012-03-22  1:11 ` Jeff Mahoney [this message]
2012-03-22  1:11 ` [patch 03/35] btrfs: Panic on bad rbtree operations Jeff Mahoney
2012-03-22  1:11 ` [patch 04/35] btrfs: Fix kfree of member instead of structure Jeff Mahoney
2012-03-22  1:11 ` [patch 05/35] btrfs: Simplify btrfs_insert_root Jeff Mahoney
2012-03-22  1:11 ` [patch 06/35] btrfs: clean_tree_block should panic on observed memory corruption and return void Jeff Mahoney
2012-03-22  1:11 ` [patch 07/35] btrfs: avoid NULL deref in btrfs_reserve_extent with DEBUG_ENOSPC Jeff Mahoney
2012-03-22  1:11 ` [patch 08/35] btrfs: Remove set bits return from clear_extent_bit Jeff Mahoney
2012-03-22  2:03   ` Liu Bo
2012-03-22  2:34     ` Jeff Mahoney
2012-03-22  1:11 ` [patch 09/35] btrfs: find_and_setup_root error push-up Jeff Mahoney
2012-03-22  1:11 ` [patch 10/35] btrfs: btrfs_update_root " Jeff Mahoney
2012-03-22  1:11 ` [patch 11/35] btrfs: Simplify btrfs_submit_bio_hook Jeff Mahoney
2012-03-22  1:11 ` [patch 12/35] btrfs: Factor out tree->ops->merge_bio_hook call Jeff Mahoney
2012-03-22  1:11 ` [patch 13/35] btrfs: ->submit_bio_hook error push-up Jeff Mahoney
2012-03-22  1:11 ` [patch 14/35] btrfs: __add_reloc_root " Jeff Mahoney
2012-03-22  1:11 ` [patch 15/35] btrfs: return void in functions without error conditions Jeff Mahoney
2012-03-22  1:11 ` [patch 16/35] btrfs: drop gfp_t from lock_extent Jeff Mahoney
2012-03-22  1:11 ` [patch 17/35] btrfs: split extent_state ops Jeff Mahoney
2012-03-22  1:56   ` Liu Bo
2012-03-22  2:35     ` Jeff Mahoney
2012-03-22  1:11 ` [patch 18/35] btrfs: btrfs_drop_snapshot should return int Jeff Mahoney
2012-03-22  1:11 ` [patch 19/35] btrfs: Dont BUG_ON errors from btrfs_create_subvol_root() Jeff Mahoney
2012-03-22  1:11 ` [patch 20/35] btrfs: Dont BUG_ON() errors in update_ref_for_cow() Jeff Mahoney
2012-03-22  1:11 ` [patch 21/35] btrfs: Dont BUG_ON kzalloc error in btrfs_lookup_csums_range() Jeff Mahoney
2012-03-22  1:11 ` [patch 22/35] btrfs: Dont BUG_ON errors in __finish_chunk_alloc() Jeff Mahoney
2012-03-22  1:11 ` [patch 23/35] btrfs: Go readonly on bad extent refs in update_ref_for_cow() Jeff Mahoney
2012-03-22  1:11 ` [patch 24/35] btrfs: Dont BUG_ON errors from update_ref_for_cow() Jeff Mahoney
2012-03-22  1:11 ` [patch 25/35] btrfs: Go readonly on tree errors in balance_level Jeff Mahoney
2012-03-22  1:11 ` [patch 26/35] btrfs: Dont BUG_ON insert errors in btrfs_alloc_dev_extent() Jeff Mahoney
2012-03-22  1:11 ` [patch 27/35] btrfs: Remove BUG_ON from __btrfs_alloc_chunk() Jeff Mahoney
2012-03-22  1:11 ` [patch 28/35] btrfs: Remove BUG_ON from __finish_chunk_alloc() Jeff Mahoney
2012-03-22  1:11 ` [patch 29/35] btrfs: add varargs to btrfs_error Jeff Mahoney
2012-03-22  1:11 ` [patch 30/35] btrfs: enhance transaction abort infrastructure Jeff Mahoney
2012-03-22  1:11 ` [patch 32/35] btrfs: Fix busyloop in transaction_kthread() Jeff Mahoney
2012-03-22  1:11 ` [patch 33/35] btrfs: handle errors when excluding super extents Jeff Mahoney
2012-03-23 17:21   ` David Sterba
2012-03-22  1:11 ` [patch 34/35] btrfs: enhance superblock sanity checks Jeff Mahoney
2012-03-22  1:11 ` [patch 35/35] btrfs: disallow unequal data/metadata blocksize for mixed block groups Jeff Mahoney
2012-03-22 16:02   ` Stefan Behrens
2012-03-23 17:13     ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120322011133.260932864@suse.com \
    --to=jeffm@suse.com \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).