diff options
author | Chris Mason <chris.mason@oracle.com> | 2008-07-17 12:54:14 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2008-09-25 11:04:04 -0400 |
commit | f9295749388f82c8d2f485e99c72cd7c7876a99b (patch) | |
tree | 5089b0f723583d262116775b8b9fb5b4b8d291e0 /fs/btrfs/transaction.c | |
parent | dbe674a99c8af088faa4c95eddaeb271a3140ab6 (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/btrfs/transaction.c')
-rw-r--r-- | fs/btrfs/transaction.c | 43 |
1 files changed, 40 insertions, 3 deletions
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 | ||
102 | struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root, | 103 | struct 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 | ||
149 | struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root, | ||
150 | int num_blocks) | ||
151 | { | ||
152 | return start_transaction(root, num_blocks, 0); | ||
153 | } | ||
154 | struct 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 | |||
126 | static noinline int wait_for_commit(struct btrfs_root *root, | 160 | static 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 | ||
618 | printk("commit trans %Lu\n", trans->transid); | 652 | printk("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); |