aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/locking.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2008-07-22 11:18:08 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:04:05 -0400
commita61e6f29dc7c9d56a776a518eed92bbc61848263 (patch)
tree6856ad3e5822eacfc2ac94693b6023ef81567fd2 /fs/btrfs/locking.c
parent6af118ce51b52ceda357c671550c79628b9c4a65 (diff)
Btrfs: Use a mutex in the extent buffer for tree block locking
This replaces the use of the page cache lock bit for locking, which wasn't suitable for block size < page size and couldn't be used recursively. The mutexes alone don't fix either problem, but they are the first step. Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/locking.c')
-rw-r--r--fs/btrfs/locking.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/fs/btrfs/locking.c b/fs/btrfs/locking.c
index 058a506a0dd8..01a9ac2be3f7 100644
--- a/fs/btrfs/locking.c
+++ b/fs/btrfs/locking.c
@@ -29,32 +29,31 @@ int btrfs_tree_lock(struct extent_buffer *eb)
29{ 29{
30 int i; 30 int i;
31 31
32 if (!TestSetPageLocked(eb->first_page)) 32 if (mutex_trylock(&eb->mutex))
33 return 0; 33 return 0;
34 for (i = 0; i < 512; i++) { 34 for (i = 0; i < 512; i++) {
35 cpu_relax(); 35 cpu_relax();
36 if (!TestSetPageLocked(eb->first_page)) 36 if (mutex_trylock(&eb->mutex))
37 return 0; 37 return 0;
38 } 38 }
39 cpu_relax(); 39 cpu_relax();
40 lock_page(eb->first_page); 40 mutex_lock(&eb->mutex);
41 return 0; 41 return 0;
42} 42}
43 43
44int btrfs_try_tree_lock(struct extent_buffer *eb) 44int btrfs_try_tree_lock(struct extent_buffer *eb)
45{ 45{
46 return TestSetPageLocked(eb->first_page); 46 return mutex_trylock(&eb->mutex);
47} 47}
48 48
49int btrfs_tree_unlock(struct extent_buffer *eb) 49int btrfs_tree_unlock(struct extent_buffer *eb)
50{ 50{
51 WARN_ON(!PageLocked(eb->first_page)); 51 mutex_unlock(&eb->mutex);
52 unlock_page(eb->first_page);
53 return 0; 52 return 0;
54} 53}
55 54
56int btrfs_tree_locked(struct extent_buffer *eb) 55int btrfs_tree_locked(struct extent_buffer *eb)
57{ 56{
58 return PageLocked(eb->first_page); 57 return mutex_is_locked(&eb->mutex);
59} 58}
60 59