aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 @@
25struct tree_entry { 25struct tree_entry {
26 u64 root_objectid; 26 u64 root_objectid;
27 u64 objectid; 27 u64 objectid;
28 struct inode *inode;
28 struct rb_node rb_node; 29 struct rb_node rb_node;
29}; 30};
30 31
@@ -144,6 +145,7 @@ int btrfs_add_ordered_inode(struct inode *inode)
144 write_lock(&tree->lock); 145 write_lock(&tree->lock);
145 entry->objectid = inode->i_ino; 146 entry->objectid = inode->i_ino;
146 entry->root_objectid = root_objectid; 147 entry->root_objectid = root_objectid;
148 entry->inode = inode;
147 149
148 node = tree_insert(&tree->tree, root_objectid, 150 node = tree_insert(&tree->tree, root_objectid,
149 inode->i_ino, &entry->rb_node); 151 inode->i_ino, &entry->rb_node);
@@ -159,7 +161,8 @@ int btrfs_add_ordered_inode(struct inode *inode)
159} 161}
160 162
161int btrfs_find_first_ordered_inode(struct btrfs_ordered_inode_tree *tree, 163int btrfs_find_first_ordered_inode(struct btrfs_ordered_inode_tree *tree,
162 u64 *root_objectid, u64 *objectid) 164 u64 *root_objectid, u64 *objectid,
165 struct inode **inode)
163{ 166{
164 struct tree_entry *entry; 167 struct tree_entry *entry;
165 struct rb_node *node; 168 struct rb_node *node;
@@ -184,13 +187,16 @@ int btrfs_find_first_ordered_inode(struct btrfs_ordered_inode_tree *tree,
184 } 187 }
185 188
186 *root_objectid = entry->root_objectid; 189 *root_objectid = entry->root_objectid;
190 *inode = entry->inode;
191 atomic_inc(&entry->inode->i_count);
187 *objectid = entry->objectid; 192 *objectid = entry->objectid;
188 write_unlock(&tree->lock); 193 write_unlock(&tree->lock);
189 return 1; 194 return 1;
190} 195}
191 196
192int btrfs_find_del_first_ordered_inode(struct btrfs_ordered_inode_tree *tree, 197int btrfs_find_del_first_ordered_inode(struct btrfs_ordered_inode_tree *tree,
193 u64 *root_objectid, u64 *objectid) 198 u64 *root_objectid, u64 *objectid,
199 struct inode **inode)
194{ 200{
195 struct tree_entry *entry; 201 struct tree_entry *entry;
196 struct rb_node *node; 202 struct rb_node *node;
@@ -216,6 +222,8 @@ int btrfs_find_del_first_ordered_inode(struct btrfs_ordered_inode_tree *tree,
216 222
217 *root_objectid = entry->root_objectid; 223 *root_objectid = entry->root_objectid;
218 *objectid = entry->objectid; 224 *objectid = entry->objectid;
225 *inode = entry->inode;
226 atomic_inc(&entry->inode->i_count);
219 rb_erase(node, &tree->tree); 227 rb_erase(node, &tree->tree);
220 write_unlock(&tree->lock); 228 write_unlock(&tree->lock);
221 kfree(entry); 229 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)
33 33
34int btrfs_add_ordered_inode(struct inode *inode); 34int btrfs_add_ordered_inode(struct inode *inode);
35int btrfs_find_del_first_ordered_inode(struct btrfs_ordered_inode_tree *tree, 35int btrfs_find_del_first_ordered_inode(struct btrfs_ordered_inode_tree *tree,
36 u64 *root_objectid, u64 *objectid); 36 u64 *root_objectid, u64 *objectid,
37 struct inode **inode);
37int btrfs_find_first_ordered_inode(struct btrfs_ordered_inode_tree *tree, 38int btrfs_find_first_ordered_inode(struct btrfs_ordered_inode_tree *tree,
38 u64 *root_objectid, u64 *objectid); 39 u64 *root_objectid, u64 *objectid,
40 struct inode **inode);
39int btrfs_del_ordered_inode(struct inode *inode); 41int btrfs_del_ordered_inode(struct inode *inode);
40#endif 42#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,
490 while(1) { 490 while(1) {
491 ret = btrfs_find_first_ordered_inode( 491 ret = btrfs_find_first_ordered_inode(
492 &cur_trans->ordered_inode_tree, 492 &cur_trans->ordered_inode_tree,
493 &root_objectid, &objectid); 493 &root_objectid, &objectid, &inode);
494 if (!ret) 494 if (!ret)
495 break; 495 break;
496 496
497 mutex_unlock(&root->fs_info->trans_mutex); 497 mutex_unlock(&root->fs_info->trans_mutex);
498 mutex_unlock(&root->fs_info->fs_mutex); 498 mutex_unlock(&root->fs_info->fs_mutex);
499 inode = btrfs_ilookup(root->fs_info->sb, objectid, 499
500 root_objectid); 500 if (S_ISREG(inode->i_mode))
501 if (inode) { 501 filemap_fdatawrite(inode->i_mapping);
502 if (S_ISREG(inode->i_mode)) 502 iput(inode);
503 filemap_fdatawrite(inode->i_mapping); 503
504 iput(inode);
505 }
506 mutex_lock(&root->fs_info->fs_mutex); 504 mutex_lock(&root->fs_info->fs_mutex);
507 mutex_lock(&root->fs_info->trans_mutex); 505 mutex_lock(&root->fs_info->trans_mutex);
508 } 506 }
@@ -511,19 +509,17 @@ int btrfs_write_ordered_inodes(struct btrfs_trans_handle *trans,
511 objectid = 0; 509 objectid = 0;
512 ret = btrfs_find_del_first_ordered_inode( 510 ret = btrfs_find_del_first_ordered_inode(
513 &cur_trans->ordered_inode_tree, 511 &cur_trans->ordered_inode_tree,
514 &root_objectid, &objectid); 512 &root_objectid, &objectid, &inode);
515 if (!ret) 513 if (!ret)
516 break; 514 break;
517 mutex_unlock(&root->fs_info->trans_mutex); 515 mutex_unlock(&root->fs_info->trans_mutex);
518 mutex_unlock(&root->fs_info->fs_mutex); 516 mutex_unlock(&root->fs_info->fs_mutex);
519 inode = btrfs_ilookup(root->fs_info->sb, objectid, 517
520 root_objectid); 518 if (S_ISREG(inode->i_mode))
521 if (inode) { 519 filemap_write_and_wait(inode->i_mapping);
522 if (S_ISREG(inode->i_mode)) 520 atomic_dec(&inode->i_count);
523 filemap_write_and_wait(inode->i_mapping); 521 iput(inode);
524 atomic_dec(&inode->i_count); 522
525 iput(inode);
526 }
527 mutex_lock(&root->fs_info->fs_mutex); 523 mutex_lock(&root->fs_info->fs_mutex);
528 mutex_lock(&root->fs_info->trans_mutex); 524 mutex_lock(&root->fs_info->trans_mutex);
529 } 525 }