aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2008-04-22 13:26:47 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:04:02 -0400
commitbcbfce8abd5f8d3f84eab60a9df1ec147f81c34f (patch)
treefe3ce6b6acf66d7cb9278cc47e2d4985e8ca70cf /fs
parente1c4b7451e22f5b0a9fbccfa560ee7b80c35b8cd (diff)
Btrfs: Fix the unplug_io_fn to grab a consistent copy of page->mapping
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/disk-io.c13
-rw-r--r--fs/btrfs/inode.c16
2 files changed, 22 insertions, 7 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 19c258d2c7e2..1281c393c7e6 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -936,14 +936,25 @@ void btrfs_unplug_io_fn(struct backing_dev_info *bdi, struct page *page)
936 struct inode *inode; 936 struct inode *inode;
937 struct extent_map_tree *em_tree; 937 struct extent_map_tree *em_tree;
938 struct extent_map *em; 938 struct extent_map *em;
939 struct address_space *mapping;
939 u64 offset; 940 u64 offset;
940 941
942 /* the generic O_DIRECT read code does this */
941 if (!page) { 943 if (!page) {
942 __unplug_io_fn(bdi, page); 944 __unplug_io_fn(bdi, page);
943 return; 945 return;
944 } 946 }
945 947
946 inode = page->mapping->host; 948 /*
949 * page->mapping may change at any time. Get a consistent copy
950 * and use that for everything below
951 */
952 smp_mb();
953 mapping = page->mapping;
954 if (!mapping)
955 return;
956
957 inode = mapping->host;
947 offset = page_offset(page); 958 offset = page_offset(page);
948 959
949 em_tree = &BTRFS_I(inode)->extent_tree; 960 em_tree = &BTRFS_I(inode)->extent_tree;
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index abfe86df02d2..d58b4d5a1fef 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -80,6 +80,7 @@ int btrfs_check_free_space(struct btrfs_root *root, u64 num_required,
80 u64 total = btrfs_super_total_bytes(&root->fs_info->super_copy); 80 u64 total = btrfs_super_total_bytes(&root->fs_info->super_copy);
81 u64 used = btrfs_super_bytes_used(&root->fs_info->super_copy); 81 u64 used = btrfs_super_bytes_used(&root->fs_info->super_copy);
82 u64 thresh; 82 u64 thresh;
83 unsigned long flags;
83 int ret = 0; 84 int ret = 0;
84 85
85 if (for_del) 86 if (for_del)
@@ -89,10 +90,10 @@ int btrfs_check_free_space(struct btrfs_root *root, u64 num_required,
89 90
90 do_div(thresh, 100); 91 do_div(thresh, 100);
91 92
92 spin_lock(&root->fs_info->delalloc_lock); 93 spin_lock_irqsave(&root->fs_info->delalloc_lock, flags);
93 if (used + root->fs_info->delalloc_bytes + num_required > thresh) 94 if (used + root->fs_info->delalloc_bytes + num_required > thresh)
94 ret = -ENOSPC; 95 ret = -ENOSPC;
95 spin_unlock(&root->fs_info->delalloc_lock); 96 spin_unlock_irqrestore(&root->fs_info->delalloc_lock, flags);
96 return ret; 97 return ret;
97} 98}
98 99
@@ -275,12 +276,13 @@ static int run_delalloc_range(struct inode *inode, u64 start, u64 end)
275int btrfs_set_bit_hook(struct inode *inode, u64 start, u64 end, 276int btrfs_set_bit_hook(struct inode *inode, u64 start, u64 end,
276 unsigned long old, unsigned long bits) 277 unsigned long old, unsigned long bits)
277{ 278{
279 unsigned long flags;
278 if (!(old & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) { 280 if (!(old & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) {
279 struct btrfs_root *root = BTRFS_I(inode)->root; 281 struct btrfs_root *root = BTRFS_I(inode)->root;
280 spin_lock(&root->fs_info->delalloc_lock); 282 spin_lock_irqsave(&root->fs_info->delalloc_lock, flags);
281 BTRFS_I(inode)->delalloc_bytes += end - start + 1; 283 BTRFS_I(inode)->delalloc_bytes += end - start + 1;
282 root->fs_info->delalloc_bytes += end - start + 1; 284 root->fs_info->delalloc_bytes += end - start + 1;
283 spin_unlock(&root->fs_info->delalloc_lock); 285 spin_unlock_irqrestore(&root->fs_info->delalloc_lock, flags);
284 } 286 }
285 return 0; 287 return 0;
286} 288}
@@ -290,7 +292,9 @@ int btrfs_clear_bit_hook(struct inode *inode, u64 start, u64 end,
290{ 292{
291 if ((old & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) { 293 if ((old & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) {
292 struct btrfs_root *root = BTRFS_I(inode)->root; 294 struct btrfs_root *root = BTRFS_I(inode)->root;
293 spin_lock(&root->fs_info->delalloc_lock); 295 unsigned long flags;
296
297 spin_lock_irqsave(&root->fs_info->delalloc_lock, flags);
294 if (end - start + 1 > root->fs_info->delalloc_bytes) { 298 if (end - start + 1 > root->fs_info->delalloc_bytes) {
295 printk("warning: delalloc account %Lu %Lu\n", 299 printk("warning: delalloc account %Lu %Lu\n",
296 end - start + 1, root->fs_info->delalloc_bytes); 300 end - start + 1, root->fs_info->delalloc_bytes);
@@ -300,7 +304,7 @@ int btrfs_clear_bit_hook(struct inode *inode, u64 start, u64 end,
300 root->fs_info->delalloc_bytes -= end - start + 1; 304 root->fs_info->delalloc_bytes -= end - start + 1;
301 BTRFS_I(inode)->delalloc_bytes -= end - start + 1; 305 BTRFS_I(inode)->delalloc_bytes -= end - start + 1;
302 } 306 }
303 spin_unlock(&root->fs_info->delalloc_lock); 307 spin_unlock_irqrestore(&root->fs_info->delalloc_lock, flags);
304 } 308 }
305 return 0; 309 return 0;
306} 310}