Commit 4d5e74bc authored by Chris Mason's avatar Chris Mason

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: default avatarChris Mason <chris.mason@oracle.com>
parent 2da98f00
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
struct tree_entry { struct tree_entry {
u64 root_objectid; u64 root_objectid;
u64 objectid; u64 objectid;
struct inode *inode;
struct rb_node rb_node; struct rb_node rb_node;
}; };
...@@ -144,6 +145,7 @@ int btrfs_add_ordered_inode(struct inode *inode) ...@@ -144,6 +145,7 @@ int btrfs_add_ordered_inode(struct inode *inode)
write_lock(&tree->lock); write_lock(&tree->lock);
entry->objectid = inode->i_ino; entry->objectid = inode->i_ino;
entry->root_objectid = root_objectid; entry->root_objectid = root_objectid;
entry->inode = inode;
node = tree_insert(&tree->tree, root_objectid, node = tree_insert(&tree->tree, root_objectid,
inode->i_ino, &entry->rb_node); inode->i_ino, &entry->rb_node);
...@@ -159,7 +161,8 @@ int btrfs_add_ordered_inode(struct inode *inode) ...@@ -159,7 +161,8 @@ int btrfs_add_ordered_inode(struct inode *inode)
} }
int btrfs_find_first_ordered_inode(struct btrfs_ordered_inode_tree *tree, 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 tree_entry *entry;
struct rb_node *node; struct rb_node *node;
...@@ -184,13 +187,16 @@ int btrfs_find_first_ordered_inode(struct btrfs_ordered_inode_tree *tree, ...@@ -184,13 +187,16 @@ int btrfs_find_first_ordered_inode(struct btrfs_ordered_inode_tree *tree,
} }
*root_objectid = entry->root_objectid; *root_objectid = entry->root_objectid;
*inode = entry->inode;
atomic_inc(&entry->inode->i_count);
*objectid = entry->objectid; *objectid = entry->objectid;
write_unlock(&tree->lock); write_unlock(&tree->lock);
return 1; return 1;
} }
int btrfs_find_del_first_ordered_inode(struct btrfs_ordered_inode_tree *tree, 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 tree_entry *entry;
struct rb_node *node; struct rb_node *node;
...@@ -216,6 +222,8 @@ int btrfs_find_del_first_ordered_inode(struct btrfs_ordered_inode_tree *tree, ...@@ -216,6 +222,8 @@ int btrfs_find_del_first_ordered_inode(struct btrfs_ordered_inode_tree *tree,
*root_objectid = entry->root_objectid; *root_objectid = entry->root_objectid;
*objectid = entry->objectid; *objectid = entry->objectid;
*inode = entry->inode;
atomic_inc(&entry->inode->i_count);
rb_erase(node, &tree->tree); rb_erase(node, &tree->tree);
write_unlock(&tree->lock); write_unlock(&tree->lock);
kfree(entry); kfree(entry);
......
...@@ -33,8 +33,10 @@ btrfs_ordered_inode_tree_init(struct btrfs_ordered_inode_tree *t) ...@@ -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_add_ordered_inode(struct inode *inode);
int btrfs_find_del_first_ordered_inode(struct btrfs_ordered_inode_tree *tree, 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, 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); int btrfs_del_ordered_inode(struct inode *inode);
#endif #endif
...@@ -490,19 +490,17 @@ int btrfs_write_ordered_inodes(struct btrfs_trans_handle *trans, ...@@ -490,19 +490,17 @@ int btrfs_write_ordered_inodes(struct btrfs_trans_handle *trans,
while(1) { while(1) {
ret = btrfs_find_first_ordered_inode( ret = btrfs_find_first_ordered_inode(
&cur_trans->ordered_inode_tree, &cur_trans->ordered_inode_tree,
&root_objectid, &objectid); &root_objectid, &objectid, &inode);
if (!ret) if (!ret)
break; break;
mutex_unlock(&root->fs_info->trans_mutex); mutex_unlock(&root->fs_info->trans_mutex);
mutex_unlock(&root->fs_info->fs_mutex); mutex_unlock(&root->fs_info->fs_mutex);
inode = btrfs_ilookup(root->fs_info->sb, objectid,
root_objectid); if (S_ISREG(inode->i_mode))
if (inode) { filemap_fdatawrite(inode->i_mapping);
if (S_ISREG(inode->i_mode)) iput(inode);
filemap_fdatawrite(inode->i_mapping);
iput(inode);
}
mutex_lock(&root->fs_info->fs_mutex); mutex_lock(&root->fs_info->fs_mutex);
mutex_lock(&root->fs_info->trans_mutex); mutex_lock(&root->fs_info->trans_mutex);
} }
...@@ -511,19 +509,17 @@ int btrfs_write_ordered_inodes(struct btrfs_trans_handle *trans, ...@@ -511,19 +509,17 @@ int btrfs_write_ordered_inodes(struct btrfs_trans_handle *trans,
objectid = 0; objectid = 0;
ret = btrfs_find_del_first_ordered_inode( ret = btrfs_find_del_first_ordered_inode(
&cur_trans->ordered_inode_tree, &cur_trans->ordered_inode_tree,
&root_objectid, &objectid); &root_objectid, &objectid, &inode);
if (!ret) if (!ret)
break; break;
mutex_unlock(&root->fs_info->trans_mutex); mutex_unlock(&root->fs_info->trans_mutex);
mutex_unlock(&root->fs_info->fs_mutex); mutex_unlock(&root->fs_info->fs_mutex);
inode = btrfs_ilookup(root->fs_info->sb, objectid,
root_objectid); if (S_ISREG(inode->i_mode))
if (inode) { filemap_write_and_wait(inode->i_mapping);
if (S_ISREG(inode->i_mode)) atomic_dec(&inode->i_count);
filemap_write_and_wait(inode->i_mapping); iput(inode);
atomic_dec(&inode->i_count);
iput(inode);
}
mutex_lock(&root->fs_info->fs_mutex); mutex_lock(&root->fs_info->fs_mutex);
mutex_lock(&root->fs_info->trans_mutex); mutex_lock(&root->fs_info->trans_mutex);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment