[Btrfs-devel] [PATCH] extent_map: fix locking for bio completion handlers

Christoph Hellwig
Sat, 01 Sep 2007 12:55:30 -0000

The bio completion handlers can be run in any context, e.g. when using
the old ide driver they run in hardirq context with irqs disabled so
lockdep rightfully warns about using write_lock_irq useage in these
handlers.

This patch switches clear_extent_bit and set_extent_bit to
write_lock_irqsave to fix this problem.


Signed-off-by: Christoph Hellwig <hch@lst.de>

Index: btrfs-9cb5f0f5c713/extent_map.c
==================================================================---
btrfs-9cb5f0f5c713.orig/extent_map.c	2007-09-01 20:35:39.000000000 +0200
+++ btrfs-9cb5f0f5c713/extent_map.c	2007-09-01 20:36:16.000000000 +0200
@@ -452,6 +452,7 @@ int clear_extent_bit(struct extent_map_t
 	struct extent_state *state;
 	struct extent_state *prealloc = NULL;
 	struct rb_node *node;
+	unsigned long flags;
 	int err;
 	int set = 0;

@@ -462,7 +463,7 @@ again:
 			return -ENOMEM;
 	}

-	write_lock_irq(&tree->lock);
+	write_lock_irqsave(&tree->lock, flags);
 	/*
 	 * this search will find the extents that end after
 	 * our range starts
@@ -529,7 +530,7 @@ again:
 	goto search_again;

 out:
-	write_unlock_irq(&tree->lock);
+	write_unlock_irqrestore(&tree->lock, flags);
 	if (prealloc)
 		free_extent_state(prealloc);

@@ -538,7 +539,7 @@ out:
 search_again:
 	if (start >= end)
 		goto out;
-	write_unlock_irq(&tree->lock);
+	write_unlock_irqrestore(&tree->lock, flags);
 	if (mask & __GFP_WAIT)
 		cond_resched();
 	goto again;
@@ -624,6 +625,7 @@ int set_extent_bit(struct extent_map_tre
 	struct extent_state *state;
 	struct extent_state *prealloc = NULL;
 	struct rb_node *node;
+	unsigned long flags;
 	int err = 0;
 	int set;
 	u64 last_start;
@@ -635,7 +637,7 @@ again:
 			return -ENOMEM;
 	}

-	write_lock_irq(&tree->lock);
+	write_lock_irqsave(&tree->lock, flags);
 	/*
 	 * this search will find all the extents that end after
 	 * our range starts.
@@ -755,7 +757,7 @@ again:
 	goto search_again;

 out:
-	write_unlock_irq(&tree->lock);
+	write_unlock_irqrestore(&tree->lock, flags);
 	if (prealloc)
 		free_extent_state(prealloc);

@@ -764,7 +766,7 @@ out:
 search_again:
 	if (start > end)
 		goto out;
-	write_unlock_irq(&tree->lock);
+	write_unlock_irqrestore(&tree->lock, flags);
 	if (mask & __GFP_WAIT)
 		cond_resched();
 	goto again;