aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2008-07-17 12:54:14 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:04:04 -0400
commitf9295749388f82c8d2f485e99c72cd7c7876a99b (patch)
tree5089b0f723583d262116775b8b9fb5b4b8d291e0 /fs
parentdbe674a99c8af088faa4c95eddaeb271a3140ab6 (diff)
btrfs_start_transaction: wait for commits in progress to finish
btrfs_commit_transaction has to loop waiting for any writers in the transaction to finish before it can proceed. btrfs_start_transaction should be polite and not join a transaction that is in the process of being finished off. There are a few places that can't wait, basically the ones doing IO that might be needed to finish the transaction. For them, btrfs_join_transaction is added. Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/ctree.h1
-rw-r--r--fs/btrfs/disk-io.c1
-rw-r--r--fs/btrfs/file.c2
-rw-r--r--fs/btrfs/inode.c10
-rw-r--r--fs/btrfs/transaction.c43
-rw-r--r--fs/btrfs/transaction.h3
6 files changed, 51 insertions, 9 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 4ddc8a8f82cd..acbce542d291 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -513,6 +513,7 @@ struct btrfs_fs_info {
513 u64 alloc_start; 513 u64 alloc_start;
514 struct btrfs_transaction *running_transaction; 514 struct btrfs_transaction *running_transaction;
515 wait_queue_head_t transaction_throttle; 515 wait_queue_head_t transaction_throttle;
516 wait_queue_head_t transaction_wait;
516 struct btrfs_super_block super_copy; 517 struct btrfs_super_block super_copy;
517 struct btrfs_super_block super_for_commit; 518 struct btrfs_super_block super_for_commit;
518 struct block_device *__bdev; 519 struct block_device *__bdev;
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 66466d125c05..99bb385c2982 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1291,6 +1291,7 @@ struct btrfs_root *open_ctree(struct super_block *sb,
1291 mutex_init(&fs_info->cleaner_mutex); 1291 mutex_init(&fs_info->cleaner_mutex);
1292 mutex_init(&fs_info->volume_mutex); 1292 mutex_init(&fs_info->volume_mutex);
1293 init_waitqueue_head(&fs_info->transaction_throttle); 1293 init_waitqueue_head(&fs_info->transaction_throttle);
1294 init_waitqueue_head(&fs_info->transaction_wait);
1294 1295
1295#if 0 1296#if 0
1296 ret = add_hasher(fs_info, "crc32c"); 1297 ret = add_hasher(fs_info, "crc32c");
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 3e4e5c227c0c..d6505892cd52 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -251,7 +251,7 @@ static int noinline dirty_and_release_pages(struct btrfs_trans_handle *trans,
251 end_of_last_block = start_pos + num_bytes - 1; 251 end_of_last_block = start_pos + num_bytes - 1;
252 252
253 lock_extent(io_tree, start_pos, end_of_last_block, GFP_NOFS); 253 lock_extent(io_tree, start_pos, end_of_last_block, GFP_NOFS);
254 trans = btrfs_start_transaction(root, 1); 254 trans = btrfs_join_transaction(root, 1);
255 if (!trans) { 255 if (!trans) {
256 err = -ENOMEM; 256 err = -ENOMEM;
257 goto out_unlock; 257 goto out_unlock;
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index baf46017d0d3..0a687326c0b0 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -116,7 +116,7 @@ static int cow_file_range(struct inode *inode, u64 start, u64 end)
116 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; 116 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
117 int ret = 0; 117 int ret = 0;
118 118
119 trans = btrfs_start_transaction(root, 1); 119 trans = btrfs_join_transaction(root, 1);
120 BUG_ON(!trans); 120 BUG_ON(!trans);
121 btrfs_set_trans_block_group(trans, inode); 121 btrfs_set_trans_block_group(trans, inode);
122 122
@@ -502,7 +502,7 @@ int btrfs_writepage_end_io_hook(struct page *page, u64 start, u64 end,
502 return 0; 502 return 0;
503 } 503 }
504 504
505 trans = btrfs_start_transaction(root, 1); 505 trans = btrfs_join_transaction(root, 1);
506 506
507 ordered_extent = btrfs_lookup_ordered_extent(inode, start); 507 ordered_extent = btrfs_lookup_ordered_extent(inode, start);
508 BUG_ON(!ordered_extent); 508 BUG_ON(!ordered_extent);
@@ -1812,7 +1812,7 @@ int btrfs_write_inode(struct inode *inode, int wait)
1812 int ret = 0; 1812 int ret = 0;
1813 1813
1814 if (wait) { 1814 if (wait) {
1815 trans = btrfs_start_transaction(root, 1); 1815 trans = btrfs_join_transaction(root, 1);
1816 btrfs_set_trans_block_group(trans, inode); 1816 btrfs_set_trans_block_group(trans, inode);
1817 ret = btrfs_commit_transaction(trans, root); 1817 ret = btrfs_commit_transaction(trans, root);
1818 } 1818 }
@@ -1830,7 +1830,7 @@ void btrfs_dirty_inode(struct inode *inode)
1830 struct btrfs_root *root = BTRFS_I(inode)->root; 1830 struct btrfs_root *root = BTRFS_I(inode)->root;
1831 struct btrfs_trans_handle *trans; 1831 struct btrfs_trans_handle *trans;
1832 1832
1833 trans = btrfs_start_transaction(root, 1); 1833 trans = btrfs_join_transaction(root, 1);
1834 btrfs_set_trans_block_group(trans, inode); 1834 btrfs_set_trans_block_group(trans, inode);
1835 btrfs_update_inode(trans, root, inode); 1835 btrfs_update_inode(trans, root, inode);
1836 btrfs_end_transaction(trans, root); 1836 btrfs_end_transaction(trans, root);
@@ -2395,7 +2395,7 @@ again:
2395 free_extent_map(em); 2395 free_extent_map(em);
2396 em = NULL; 2396 em = NULL;
2397 btrfs_release_path(root, path); 2397 btrfs_release_path(root, path);
2398 trans = btrfs_start_transaction(root, 1); 2398 trans = btrfs_join_transaction(root, 1);
2399 goto again; 2399 goto again;
2400 } 2400 }
2401 write_extent_buffer(leaf, map + pg_offset, ptr, 2401 write_extent_buffer(leaf, map + pg_offset, ptr,
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 86a5acc19ce7..05823904ecba 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -62,6 +62,7 @@ static noinline int join_transaction(struct btrfs_root *root)
62 init_waitqueue_head(&cur_trans->writer_wait); 62 init_waitqueue_head(&cur_trans->writer_wait);
63 init_waitqueue_head(&cur_trans->commit_wait); 63 init_waitqueue_head(&cur_trans->commit_wait);
64 cur_trans->in_commit = 0; 64 cur_trans->in_commit = 0;
65 cur_trans->blocked = 0;
65 cur_trans->use_count = 1; 66 cur_trans->use_count = 1;
66 cur_trans->commit_done = 0; 67 cur_trans->commit_done = 0;
67 cur_trans->start_time = get_seconds(); 68 cur_trans->start_time = get_seconds();
@@ -99,14 +100,36 @@ static noinline int record_root_in_trans(struct btrfs_root *root)
99 return 0; 100 return 0;
100} 101}
101 102
102struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root, 103struct btrfs_trans_handle *start_transaction(struct btrfs_root *root,
103 int num_blocks) 104 int num_blocks, int join)
104{ 105{
105 struct btrfs_trans_handle *h = 106 struct btrfs_trans_handle *h =
106 kmem_cache_alloc(btrfs_trans_handle_cachep, GFP_NOFS); 107 kmem_cache_alloc(btrfs_trans_handle_cachep, GFP_NOFS);
108 struct btrfs_transaction *cur_trans;
107 int ret; 109 int ret;
108 110
109 mutex_lock(&root->fs_info->trans_mutex); 111 mutex_lock(&root->fs_info->trans_mutex);
112 cur_trans = root->fs_info->running_transaction;
113 if (cur_trans && cur_trans->blocked && !join) {
114 DEFINE_WAIT(wait);
115 cur_trans->use_count++;
116 while(1) {
117 prepare_to_wait(&root->fs_info->transaction_wait, &wait,
118 TASK_UNINTERRUPTIBLE);
119 if (cur_trans->blocked) {
120 mutex_unlock(&root->fs_info->trans_mutex);
121 schedule();
122 mutex_lock(&root->fs_info->trans_mutex);
123 finish_wait(&root->fs_info->transaction_wait,
124 &wait);
125 } else {
126 finish_wait(&root->fs_info->transaction_wait,
127 &wait);
128 break;
129 }
130 }
131 put_transaction(cur_trans);
132 }
110 ret = join_transaction(root); 133 ret = join_transaction(root);
111 BUG_ON(ret); 134 BUG_ON(ret);
112 135
@@ -123,6 +146,17 @@ struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root,
123 return h; 146 return h;
124} 147}
125 148
149struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root,
150 int num_blocks)
151{
152 return start_transaction(root, num_blocks, 0);
153}
154struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root,
155 int num_blocks)
156{
157 return start_transaction(root, num_blocks, 1);
158}
159
126static noinline int wait_for_commit(struct btrfs_root *root, 160static noinline int wait_for_commit(struct btrfs_root *root,
127 struct btrfs_transaction *commit) 161 struct btrfs_transaction *commit)
128{ 162{
@@ -156,7 +190,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
156 if (waitqueue_active(&cur_trans->writer_wait)) 190 if (waitqueue_active(&cur_trans->writer_wait))
157 wake_up(&cur_trans->writer_wait); 191 wake_up(&cur_trans->writer_wait);
158 192
159 if (cur_trans->in_commit && throttle) { 193 if (0 && cur_trans->in_commit && throttle) {
160 DEFINE_WAIT(wait); 194 DEFINE_WAIT(wait);
161 mutex_unlock(&root->fs_info->trans_mutex); 195 mutex_unlock(&root->fs_info->trans_mutex);
162 prepare_to_wait(&root->fs_info->transaction_throttle, &wait, 196 prepare_to_wait(&root->fs_info->transaction_throttle, &wait,
@@ -617,6 +651,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
617 651
618printk("commit trans %Lu\n", trans->transid); 652printk("commit trans %Lu\n", trans->transid);
619 trans->transaction->in_commit = 1; 653 trans->transaction->in_commit = 1;
654 trans->transaction->blocked = 1;
620 cur_trans = trans->transaction; 655 cur_trans = trans->transaction;
621 if (cur_trans->list.prev != &root->fs_info->trans_list) { 656 if (cur_trans->list.prev != &root->fs_info->trans_list) {
622 prev_trans = list_entry(cur_trans->list.prev, 657 prev_trans = list_entry(cur_trans->list.prev,
@@ -684,7 +719,9 @@ printk("commit trans %Lu\n", trans->transid);
684 719
685 btrfs_copy_pinned(root, pinned_copy); 720 btrfs_copy_pinned(root, pinned_copy);
686 721
722 trans->transaction->blocked = 0;
687 wake_up(&root->fs_info->transaction_throttle); 723 wake_up(&root->fs_info->transaction_throttle);
724 wake_up(&root->fs_info->transaction_wait);
688 725
689 mutex_unlock(&root->fs_info->trans_mutex); 726 mutex_unlock(&root->fs_info->trans_mutex);
690 ret = btrfs_write_and_wait_transaction(trans, root); 727 ret = btrfs_write_and_wait_transaction(trans, root);
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h
index 910350cd4cf0..11fbdeceb26c 100644
--- a/fs/btrfs/transaction.h
+++ b/fs/btrfs/transaction.h
@@ -27,6 +27,7 @@ struct btrfs_transaction {
27 int in_commit; 27 int in_commit;
28 int use_count; 28 int use_count;
29 int commit_done; 29 int commit_done;
30 int blocked;
30 struct list_head list; 31 struct list_head list;
31 struct extent_io_tree dirty_pages; 32 struct extent_io_tree dirty_pages;
32 unsigned long start_time; 33 unsigned long start_time;
@@ -75,6 +76,8 @@ int btrfs_end_transaction(struct btrfs_trans_handle *trans,
75 struct btrfs_root *root); 76 struct btrfs_root *root);
76struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root, 77struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root,
77 int num_blocks); 78 int num_blocks);
79struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root,
80 int num_blocks);
78int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans, 81int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans,
79 struct btrfs_root *root); 82 struct btrfs_root *root);
80int btrfs_commit_tree_roots(struct btrfs_trans_handle *trans, 83int btrfs_commit_tree_roots(struct btrfs_trans_handle *trans,