summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2008-01-16 16:09:22 -0500
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:03:59 -0400
commit4d5e74bc0aec3f54b7e429d77b7c35de042c507d (patch)
treebba22e2a9cfbe5663a2489c5404fff72639b5277 /fs
parent2da98f003f4788b0a72c5f87bc55b061f65f30fa (diff)
downloadlinux-stable-4d5e74bc0aec3f54b7e429d77b7c35de042c507d.tar.gz
linux-stable-4d5e74bc0aec3f54b7e429d77b7c35de042c507d.tar.bz2
linux-stable-4d5e74bc0aec3f54b7e429d77b7c35de042c507d.zip
Btrfs: Fix data=ordered vs wait_on_inode deadlock on older kernels
Using ilookup5 during data=ordered writeback could deadlock on I_LOCK. This saves a pointer to the inode instead. Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/ordered-data.c12
-rw-r--r--fs/btrfs/ordered-data.h6
-rw-r--r--fs/btrfs/transaction.c30
3 files changed, 27 insertions, 21 deletions
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index cba2b623d02e..3ee51e10c187 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -25,6 +25,7 @@
struct tree_entry {
u64 root_objectid;
u64 objectid;
+ struct inode *inode;
struct rb_node rb_node;
};
@@ -144,6 +145,7 @@ int btrfs_add_ordered_inode(struct inode *inode)
write_lock(&tree->lock);
entry->objectid = inode->i_ino;
entry->root_objectid = root_objectid;
+ entry->inode = inode;
node = tree_insert(&tree->tree, root_objectid,
inode->i_ino, &entry->rb_node);
@@ -159,7 +161,8 @@ int btrfs_add_ordered_inode(struct inode *inode)
}
int btrfs_find_first_ordered_inode(struct btrfs_ordered_inode_tree *tree,
- u64 *root_objectid, u64 *objectid)
+ u64 *root_objectid, u64 *objectid,
+ struct inode **inode)
{
struct tree_entry *entry;
struct rb_node *node;
@@ -184,13 +187,16 @@ int btrfs_find_first_ordered_inode(struct btrfs_ordered_inode_tree *tree,
}
*root_objectid = entry->root_objectid;
+ *inode = entry->inode;
+ atomic_inc(&entry->inode->i_count);
*objectid = entry->objectid;
write_unlock(&tree->lock);
return 1;
}
int btrfs_find_del_first_ordered_inode(struct btrfs_ordered_inode_tree *tree,
- u64 *root_objectid, u64 *objectid)
+ u64 *root_objectid, u64 *objectid,
+ struct inode **inode)
{
struct tree_entry *entry;
struct rb_node *node;
@@ -216,6 +222,8 @@ int btrfs_find_del_first_ordered_inode(struct btrfs_ordered_inode_tree *tree,
*root_objectid = entry->root_objectid;
*objectid = entry->objectid;
+ *inode = entry->inode;
+ atomic_inc(&entry->inode->i_count);
rb_erase(node, &tree->tree);
write_unlock(&tree->lock);
kfree(entry);
diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h
index 26b26212865b..f25c6771ec64 100644
--- a/fs/btrfs/ordered-data.h
+++ b/fs/btrfs/ordered-data.h
@@ -33,8 +33,10 @@ btrfs_ordered_inode_tree_init(struct btrfs_ordered_inode_tree *t)
int btrfs_add_ordered_inode(struct inode *inode);
int btrfs_find_del_first_ordered_inode(struct btrfs_ordered_inode_tree *tree,
- u64 *root_objectid, u64 *objectid);
+ u64 *root_objectid, u64 *objectid,
+ struct inode **inode);
int btrfs_find_first_ordered_inode(struct btrfs_ordered_inode_tree *tree,
- u64 *root_objectid, u64 *objectid);
+ u64 *root_objectid, u64 *objectid,
+ struct inode **inode);
int btrfs_del_ordered_inode(struct inode *inode);
#endif
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 08f7a188dc3e..b6bbfc179c29 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -490,19 +490,17 @@ int btrfs_write_ordered_inodes(struct btrfs_trans_handle *trans,
while(1) {
ret = btrfs_find_first_ordered_inode(
&cur_trans->ordered_inode_tree,
- &root_objectid, &objectid);
+ &root_objectid, &objectid, &inode);
if (!ret)
break;
mutex_unlock(&root->fs_info->trans_mutex);
mutex_unlock(&root->fs_info->fs_mutex);
- inode = btrfs_ilookup(root->fs_info->sb, objectid,
- root_objectid);
- if (inode) {
- if (S_ISREG(inode->i_mode))
- filemap_fdatawrite(inode->i_mapping);
- iput(inode);
- }
+
+ if (S_ISREG(inode->i_mode))
+ filemap_fdatawrite(inode->i_mapping);
+ iput(inode);
+
mutex_lock(&root->fs_info->fs_mutex);
mutex_lock(&root->fs_info->trans_mutex);
}
@@ -511,19 +509,17 @@ int btrfs_write_ordered_inodes(struct btrfs_trans_handle *trans,
objectid = 0;
ret = btrfs_find_del_first_ordered_inode(
&cur_trans->ordered_inode_tree,
- &root_objectid, &objectid);
+ &root_objectid, &objectid, &inode);
if (!ret)
break;
mutex_unlock(&root->fs_info->trans_mutex);
mutex_unlock(&root->fs_info->fs_mutex);
- inode = btrfs_ilookup(root->fs_info->sb, objectid,
- root_objectid);
- if (inode) {
- if (S_ISREG(inode->i_mode))
- filemap_write_and_wait(inode->i_mapping);
- atomic_dec(&inode->i_count);
- iput(inode);
- }
+
+ if (S_ISREG(inode->i_mode))
+ filemap_write_and_wait(inode->i_mapping);
+ atomic_dec(&inode->i_count);
+ iput(inode);
+
mutex_lock(&root->fs_info->fs_mutex);
mutex_lock(&root->fs_info->trans_mutex);
}