diff options
author | Li Zefan <lizf@cn.fujitsu.com> | 2011-07-13 23:17:00 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2011-08-01 14:30:46 -0400 |
commit | 72d63ed6427cf233e2b352c0b80c3e5c5a444986 (patch) | |
tree | e88ba3e354552911f4ee8695e2123e7a4552a6f1 /fs/btrfs/transaction.c | |
parent | e55179b3d7d41d83fd6b5f59325f4a8d8ac9700a (diff) |
Btrfs: use wait_event()
Use wait_event() when possible to avoid code duplication.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/transaction.c')
-rw-r--r-- | fs/btrfs/transaction.c | 59 |
1 files changed, 7 insertions, 52 deletions
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index eb55863bb4ae..ff5549fe4624 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
@@ -216,17 +216,11 @@ static void wait_current_trans(struct btrfs_root *root) | |||
216 | spin_lock(&root->fs_info->trans_lock); | 216 | spin_lock(&root->fs_info->trans_lock); |
217 | cur_trans = root->fs_info->running_transaction; | 217 | cur_trans = root->fs_info->running_transaction; |
218 | if (cur_trans && cur_trans->blocked) { | 218 | if (cur_trans && cur_trans->blocked) { |
219 | DEFINE_WAIT(wait); | ||
220 | atomic_inc(&cur_trans->use_count); | 219 | atomic_inc(&cur_trans->use_count); |
221 | spin_unlock(&root->fs_info->trans_lock); | 220 | spin_unlock(&root->fs_info->trans_lock); |
222 | while (1) { | 221 | |
223 | prepare_to_wait(&root->fs_info->transaction_wait, &wait, | 222 | wait_event(root->fs_info->transaction_wait, |
224 | TASK_UNINTERRUPTIBLE); | 223 | !cur_trans->blocked); |
225 | if (!cur_trans->blocked) | ||
226 | break; | ||
227 | schedule(); | ||
228 | } | ||
229 | finish_wait(&root->fs_info->transaction_wait, &wait); | ||
230 | put_transaction(cur_trans); | 224 | put_transaction(cur_trans); |
231 | } else { | 225 | } else { |
232 | spin_unlock(&root->fs_info->trans_lock); | 226 | spin_unlock(&root->fs_info->trans_lock); |
@@ -360,15 +354,7 @@ struct btrfs_trans_handle *btrfs_start_ioctl_transaction(struct btrfs_root *root | |||
360 | static noinline int wait_for_commit(struct btrfs_root *root, | 354 | static noinline int wait_for_commit(struct btrfs_root *root, |
361 | struct btrfs_transaction *commit) | 355 | struct btrfs_transaction *commit) |
362 | { | 356 | { |
363 | DEFINE_WAIT(wait); | 357 | wait_event(commit->commit_wait, commit->commit_done); |
364 | while (!commit->commit_done) { | ||
365 | prepare_to_wait(&commit->commit_wait, &wait, | ||
366 | TASK_UNINTERRUPTIBLE); | ||
367 | if (commit->commit_done) | ||
368 | break; | ||
369 | schedule(); | ||
370 | } | ||
371 | finish_wait(&commit->commit_wait, &wait); | ||
372 | return 0; | 358 | return 0; |
373 | } | 359 | } |
374 | 360 | ||
@@ -1085,22 +1071,7 @@ int btrfs_transaction_blocked(struct btrfs_fs_info *info) | |||
1085 | static void wait_current_trans_commit_start(struct btrfs_root *root, | 1071 | static void wait_current_trans_commit_start(struct btrfs_root *root, |
1086 | struct btrfs_transaction *trans) | 1072 | struct btrfs_transaction *trans) |
1087 | { | 1073 | { |
1088 | DEFINE_WAIT(wait); | 1074 | wait_event(root->fs_info->transaction_blocked_wait, trans->in_commit); |
1089 | |||
1090 | if (trans->in_commit) | ||
1091 | return; | ||
1092 | |||
1093 | while (1) { | ||
1094 | prepare_to_wait(&root->fs_info->transaction_blocked_wait, &wait, | ||
1095 | TASK_UNINTERRUPTIBLE); | ||
1096 | if (trans->in_commit) { | ||
1097 | finish_wait(&root->fs_info->transaction_blocked_wait, | ||
1098 | &wait); | ||
1099 | break; | ||
1100 | } | ||
1101 | schedule(); | ||
1102 | finish_wait(&root->fs_info->transaction_blocked_wait, &wait); | ||
1103 | } | ||
1104 | } | 1075 | } |
1105 | 1076 | ||
1106 | /* | 1077 | /* |
@@ -1110,24 +1081,8 @@ static void wait_current_trans_commit_start(struct btrfs_root *root, | |||
1110 | static void wait_current_trans_commit_start_and_unblock(struct btrfs_root *root, | 1081 | static void wait_current_trans_commit_start_and_unblock(struct btrfs_root *root, |
1111 | struct btrfs_transaction *trans) | 1082 | struct btrfs_transaction *trans) |
1112 | { | 1083 | { |
1113 | DEFINE_WAIT(wait); | 1084 | wait_event(root->fs_info->transaction_wait, |
1114 | 1085 | trans->commit_done || (trans->in_commit && !trans->blocked)); | |
1115 | if (trans->commit_done || (trans->in_commit && !trans->blocked)) | ||
1116 | return; | ||
1117 | |||
1118 | while (1) { | ||
1119 | prepare_to_wait(&root->fs_info->transaction_wait, &wait, | ||
1120 | TASK_UNINTERRUPTIBLE); | ||
1121 | if (trans->commit_done || | ||
1122 | (trans->in_commit && !trans->blocked)) { | ||
1123 | finish_wait(&root->fs_info->transaction_wait, | ||
1124 | &wait); | ||
1125 | break; | ||
1126 | } | ||
1127 | schedule(); | ||
1128 | finish_wait(&root->fs_info->transaction_wait, | ||
1129 | &wait); | ||
1130 | } | ||
1131 | } | 1086 | } |
1132 | 1087 | ||
1133 | /* | 1088 | /* |