aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2008-06-25 16:01:31 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:04:04 -0400
commit1b1e2135dc1e4efbcf25ac9ac9979316d4e1193e (patch)
tree2af53ed5d4c368bbefd9de94f0adc2902a785468 /fs/btrfs
parentBtrfs: Change find_extent_buffer to use TestSetPageLocked (diff)
downloadlinux-dev-1b1e2135dc1e4efbcf25ac9ac9979316d4e1193e.tar.xz
linux-dev-1b1e2135dc1e4efbcf25ac9ac9979316d4e1193e.zip
Btrfs: Add a per-inode csum mutex to avoid races creating csum items
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/btrfs_inode.h1
-rw-r--r--fs/btrfs/file.c6
-rw-r--r--fs/btrfs/inode.c6
-rw-r--r--fs/btrfs/ordered-data.c5
-rw-r--r--fs/btrfs/transaction.c2
-rw-r--r--fs/btrfs/tree-defrag.c7
6 files changed, 21 insertions, 6 deletions
diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h
index 5ba83894c8b7..40b4e0c9cd09 100644
--- a/fs/btrfs/btrfs_inode.h
+++ b/fs/btrfs/btrfs_inode.h
@@ -30,6 +30,7 @@ struct btrfs_inode {
struct extent_map_tree extent_tree;
struct extent_io_tree io_tree;
struct extent_io_tree io_failure_tree;
+ struct mutex csum_mutex;
struct inode vfs_inode;
atomic_t ordered_writeback;
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index ece221cba90c..8037792f8789 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -267,13 +267,13 @@ static int noinline dirty_and_release_pages(struct btrfs_trans_handle *trans,
/* FIXME...EIEIO, ENOSPC and more */
/* insert any holes we need to create */
- if (isize < end_pos) {
+ if (isize < start_pos) {
u64 last_pos_in_file;
u64 hole_size;
u64 mask = root->sectorsize - 1;
last_pos_in_file = (isize + mask) & ~mask;
- hole_size = (end_pos - last_pos_in_file + mask) & ~mask;
- if (last_pos_in_file < end_pos) {
+ hole_size = (start_pos - last_pos_in_file + mask) & ~mask;
+ if (last_pos_in_file < start_pos) {
err = btrfs_drop_extents(trans, root, inode,
last_pos_in_file,
last_pos_in_file + hole_size,
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index bbba3350d023..d39433dfb2c7 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -351,7 +351,9 @@ int __btrfs_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,
trans = btrfs_start_transaction(root, 1);
btrfs_set_trans_block_group(trans, inode);
+ mutex_lock(&BTRFS_I(inode)->csum_mutex);
btrfs_csum_file_blocks(trans, root, inode, bio, sums);
+ mutex_unlock(&BTRFS_I(inode)->csum_mutex);
ret = btrfs_end_transaction(trans, root);
BUG_ON(ret);
@@ -1400,6 +1402,7 @@ static int btrfs_init_locked_inode(struct inode *inode, void *p)
inode->i_mapping, GFP_NOFS);
extent_io_tree_init(&BTRFS_I(inode)->io_failure_tree,
inode->i_mapping, GFP_NOFS);
+ mutex_init(&BTRFS_I(inode)->csum_mutex);
atomic_set(&BTRFS_I(inode)->ordered_writeback, 0);
return 0;
}
@@ -1701,6 +1704,7 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
inode->i_mapping, GFP_NOFS);
extent_io_tree_init(&BTRFS_I(inode)->io_failure_tree,
inode->i_mapping, GFP_NOFS);
+ mutex_init(&BTRFS_I(inode)->csum_mutex);
atomic_set(&BTRFS_I(inode)->ordered_writeback, 0);
BTRFS_I(inode)->delalloc_bytes = 0;
BTRFS_I(inode)->root = root;
@@ -1924,6 +1928,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
inode->i_mapping, GFP_NOFS);
extent_io_tree_init(&BTRFS_I(inode)->io_failure_tree,
inode->i_mapping, GFP_NOFS);
+ mutex_init(&BTRFS_I(inode)->csum_mutex);
BTRFS_I(inode)->delalloc_bytes = 0;
atomic_set(&BTRFS_I(inode)->ordered_writeback, 0);
BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops;
@@ -2862,6 +2867,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
inode->i_mapping, GFP_NOFS);
extent_io_tree_init(&BTRFS_I(inode)->io_failure_tree,
inode->i_mapping, GFP_NOFS);
+ mutex_init(&BTRFS_I(inode)->csum_mutex);
BTRFS_I(inode)->delalloc_bytes = 0;
atomic_set(&BTRFS_I(inode)->ordered_writeback, 0);
BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops;
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index 5e4c0d95ce43..254da8225664 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -152,12 +152,13 @@ int btrfs_add_ordered_inode(struct inode *inode)
inode->i_ino, &entry->rb_node);
BTRFS_I(inode)->ordered_trans = transid;
+ if (!node)
+ igrab(inode);
write_unlock(&tree->lock);
+
if (node)
kfree(entry);
- else
- igrab(inode);
return 0;
}
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 0c53ff775b92..8e909cb97c6d 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -477,7 +477,7 @@ static noinline int drop_dirty_roots(struct btrfs_root *tree_root,
if (err)
ret = err;
nr = trans->blocks_used;
- ret = btrfs_end_transaction(trans, tree_root);
+ ret = btrfs_end_transaction_throttle(trans, tree_root);
BUG_ON(ret);
mutex_unlock(&root->fs_info->drop_mutex);
diff --git a/fs/btrfs/tree-defrag.c b/fs/btrfs/tree-defrag.c
index 1677e4edaf6f..b17693f61fbc 100644
--- a/fs/btrfs/tree-defrag.c
+++ b/fs/btrfs/tree-defrag.c
@@ -38,8 +38,15 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
u64 last_ret = 0;
if (root->fs_info->extent_root == root) {
+ /*
+ * there's recursion here right now in the tree locking,
+ * we can't defrag the extent root without deadlock
+ */
+ goto out;
+#if 0
mutex_lock(&root->fs_info->alloc_mutex);
is_extent = 1;
+#endif
}
if (root->ref_cows == 0 && !is_extent)