aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/transaction.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/transaction.c')
-rw-r--r--fs/btrfs/transaction.c45
1 files changed, 20 insertions, 25 deletions
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 4e7b56e9d3a5..56ab1f5ea11b 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -28,9 +28,6 @@
28#include "ref-cache.h" 28#include "ref-cache.h"
29#include "tree-log.h" 29#include "tree-log.h"
30 30
31extern struct kmem_cache *btrfs_trans_handle_cachep;
32extern struct kmem_cache *btrfs_transaction_cachep;
33
34#define BTRFS_ROOT_TRANS_TAG 0 31#define BTRFS_ROOT_TRANS_TAG 0
35 32
36static noinline void put_transaction(struct btrfs_transaction *transaction) 33static noinline void put_transaction(struct btrfs_transaction *transaction)
@@ -85,10 +82,10 @@ static noinline int join_transaction(struct btrfs_root *root)
85} 82}
86 83
87/* 84/*
88 * this does all the record keeping required to make sure that a 85 * this does all the record keeping required to make sure that a reference
89 * reference counted root is properly recorded in a given transaction. 86 * counted root is properly recorded in a given transaction. This is required
90 * This is required to make sure the old root from before we joined the transaction 87 * to make sure the old root from before we joined the transaction is deleted
91 * is deleted when the transaction commits 88 * when the transaction commits
92 */ 89 */
93noinline int btrfs_record_root_in_trans(struct btrfs_root *root) 90noinline int btrfs_record_root_in_trans(struct btrfs_root *root)
94{ 91{
@@ -144,7 +141,7 @@ static void wait_current_trans(struct btrfs_root *root)
144 if (cur_trans && cur_trans->blocked) { 141 if (cur_trans && cur_trans->blocked) {
145 DEFINE_WAIT(wait); 142 DEFINE_WAIT(wait);
146 cur_trans->use_count++; 143 cur_trans->use_count++;
147 while(1) { 144 while (1) {
148 prepare_to_wait(&root->fs_info->transaction_wait, &wait, 145 prepare_to_wait(&root->fs_info->transaction_wait, &wait,
149 TASK_UNINTERRUPTIBLE); 146 TASK_UNINTERRUPTIBLE);
150 if (cur_trans->blocked) { 147 if (cur_trans->blocked) {
@@ -213,7 +210,7 @@ static noinline int wait_for_commit(struct btrfs_root *root,
213{ 210{
214 DEFINE_WAIT(wait); 211 DEFINE_WAIT(wait);
215 mutex_lock(&root->fs_info->trans_mutex); 212 mutex_lock(&root->fs_info->trans_mutex);
216 while(!commit->commit_done) { 213 while (!commit->commit_done) {
217 prepare_to_wait(&commit->commit_wait, &wait, 214 prepare_to_wait(&commit->commit_wait, &wait,
218 TASK_UNINTERRUPTIBLE); 215 TASK_UNINTERRUPTIBLE);
219 if (commit->commit_done) 216 if (commit->commit_done)
@@ -228,8 +225,8 @@ static noinline int wait_for_commit(struct btrfs_root *root,
228} 225}
229 226
230/* 227/*
231 * rate limit against the drop_snapshot code. This helps to slow down new operations 228 * rate limit against the drop_snapshot code. This helps to slow down new
232 * if the drop_snapshot code isn't able to keep up. 229 * operations if the drop_snapshot code isn't able to keep up.
233 */ 230 */
234static void throttle_on_drops(struct btrfs_root *root) 231static void throttle_on_drops(struct btrfs_root *root)
235{ 232{
@@ -332,12 +329,12 @@ int btrfs_write_and_wait_marked_extents(struct btrfs_root *root,
332 u64 end; 329 u64 end;
333 unsigned long index; 330 unsigned long index;
334 331
335 while(1) { 332 while (1) {
336 ret = find_first_extent_bit(dirty_pages, start, &start, &end, 333 ret = find_first_extent_bit(dirty_pages, start, &start, &end,
337 EXTENT_DIRTY); 334 EXTENT_DIRTY);
338 if (ret) 335 if (ret)
339 break; 336 break;
340 while(start <= end) { 337 while (start <= end) {
341 cond_resched(); 338 cond_resched();
342 339
343 index = start >> PAGE_CACHE_SHIFT; 340 index = start >> PAGE_CACHE_SHIFT;
@@ -368,14 +365,14 @@ int btrfs_write_and_wait_marked_extents(struct btrfs_root *root,
368 page_cache_release(page); 365 page_cache_release(page);
369 } 366 }
370 } 367 }
371 while(1) { 368 while (1) {
372 ret = find_first_extent_bit(dirty_pages, 0, &start, &end, 369 ret = find_first_extent_bit(dirty_pages, 0, &start, &end,
373 EXTENT_DIRTY); 370 EXTENT_DIRTY);
374 if (ret) 371 if (ret)
375 break; 372 break;
376 373
377 clear_extent_dirty(dirty_pages, start, end, GFP_NOFS); 374 clear_extent_dirty(dirty_pages, start, end, GFP_NOFS);
378 while(start <= end) { 375 while (start <= end) {
379 index = start >> PAGE_CACHE_SHIFT; 376 index = start >> PAGE_CACHE_SHIFT;
380 start = (u64)(index + 1) << PAGE_CACHE_SHIFT; 377 start = (u64)(index + 1) << PAGE_CACHE_SHIFT;
381 page = find_get_page(btree_inode->i_mapping, index); 378 page = find_get_page(btree_inode->i_mapping, index);
@@ -431,7 +428,7 @@ static int update_cowonly_root(struct btrfs_trans_handle *trans,
431 btrfs_write_dirty_block_groups(trans, root); 428 btrfs_write_dirty_block_groups(trans, root);
432 btrfs_extent_post_op(trans, root); 429 btrfs_extent_post_op(trans, root);
433 430
434 while(1) { 431 while (1) {
435 old_root_bytenr = btrfs_root_bytenr(&root->root_item); 432 old_root_bytenr = btrfs_root_bytenr(&root->root_item);
436 if (old_root_bytenr == root->node->start) 433 if (old_root_bytenr == root->node->start)
437 break; 434 break;
@@ -472,7 +469,7 @@ int btrfs_commit_tree_roots(struct btrfs_trans_handle *trans,
472 469
473 btrfs_extent_post_op(trans, fs_info->tree_root); 470 btrfs_extent_post_op(trans, fs_info->tree_root);
474 471
475 while(!list_empty(&fs_info->dirty_cowonly_roots)) { 472 while (!list_empty(&fs_info->dirty_cowonly_roots)) {
476 next = fs_info->dirty_cowonly_roots.next; 473 next = fs_info->dirty_cowonly_roots.next;
477 list_del_init(next); 474 list_del_init(next);
478 root = list_entry(next, struct btrfs_root, dirty_list); 475 root = list_entry(next, struct btrfs_root, dirty_list);
@@ -521,7 +518,7 @@ static noinline int add_dirty_roots(struct btrfs_trans_handle *trans,
521 int err = 0; 518 int err = 0;
522 u32 refs; 519 u32 refs;
523 520
524 while(1) { 521 while (1) {
525 ret = radix_tree_gang_lookup_tag(radix, (void **)gang, 0, 522 ret = radix_tree_gang_lookup_tag(radix, (void **)gang, 0,
526 ARRAY_SIZE(gang), 523 ARRAY_SIZE(gang),
527 BTRFS_ROOT_TRANS_TAG); 524 BTRFS_ROOT_TRANS_TAG);
@@ -653,7 +650,7 @@ static noinline int drop_dirty_roots(struct btrfs_root *tree_root,
653 int ret = 0; 650 int ret = 0;
654 int err; 651 int err;
655 652
656 while(!list_empty(list)) { 653 while (!list_empty(list)) {
657 struct btrfs_root *root; 654 struct btrfs_root *root;
658 655
659 dirty = list_entry(list->prev, struct btrfs_dirty_root, list); 656 dirty = list_entry(list->prev, struct btrfs_dirty_root, list);
@@ -663,13 +660,12 @@ static noinline int drop_dirty_roots(struct btrfs_root *tree_root,
663 root = dirty->latest_root; 660 root = dirty->latest_root;
664 atomic_inc(&root->fs_info->throttles); 661 atomic_inc(&root->fs_info->throttles);
665 662
666 while(1) { 663 while (1) {
667 trans = btrfs_start_transaction(tree_root, 1); 664 trans = btrfs_start_transaction(tree_root, 1);
668 mutex_lock(&root->fs_info->drop_mutex); 665 mutex_lock(&root->fs_info->drop_mutex);
669 ret = btrfs_drop_snapshot(trans, dirty->root); 666 ret = btrfs_drop_snapshot(trans, dirty->root);
670 if (ret != -EAGAIN) { 667 if (ret != -EAGAIN)
671 break; 668 break;
672 }
673 mutex_unlock(&root->fs_info->drop_mutex); 669 mutex_unlock(&root->fs_info->drop_mutex);
674 670
675 err = btrfs_update_root(trans, 671 err = btrfs_update_root(trans,
@@ -874,7 +870,7 @@ static noinline int finish_pending_snapshots(struct btrfs_trans_handle *trans,
874 struct list_head *head = &trans->transaction->pending_snapshots; 870 struct list_head *head = &trans->transaction->pending_snapshots;
875 int ret; 871 int ret;
876 872
877 while(!list_empty(head)) { 873 while (!list_empty(head)) {
878 pending = list_entry(head->next, 874 pending = list_entry(head->next,
879 struct btrfs_pending_snapshot, list); 875 struct btrfs_pending_snapshot, list);
880 ret = finish_pending_snapshot(fs_info, pending); 876 ret = finish_pending_snapshot(fs_info, pending);
@@ -1076,9 +1072,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
1076 1072
1077 kmem_cache_free(btrfs_trans_handle_cachep, trans); 1073 kmem_cache_free(btrfs_trans_handle_cachep, trans);
1078 1074
1079 if (root->fs_info->closing) { 1075 if (root->fs_info->closing)
1080 drop_dirty_roots(root->fs_info->tree_root, &dirty_fs_roots); 1076 drop_dirty_roots(root->fs_info->tree_root, &dirty_fs_roots);
1081 }
1082 return ret; 1077 return ret;
1083} 1078}
1084 1079