diff options
author | Josef Bacik <josef@redhat.com> | 2009-11-10 21:23:48 -0500 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2009-11-11 14:20:16 -0500 |
commit | 249ac1e55c642c670f47aacdc57629bbbf10a8db (patch) | |
tree | b03fdf12ee409fb2b5d696f2644ac67a7a690778 | |
parent | 6346c93988caa3048bf4d81f9ba3608a7a195aa2 (diff) |
Btrfs: cleanup transaction starting and fix journal_info usage
We use journal_info to tell if we're in a nested transaction to make sure we
don't commit the transaction within a nested transaction. We use another
method to see if there are any outstanding ioctl trans handles, so if we're
starting one do not set current->journal_info, since it will screw with other
filesystems. This patch also cleans up the starting stuff so there aren't any
magic numbers.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
-rw-r--r-- | fs/btrfs/transaction.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index bca82a4ca8e6..c207e8c32c9b 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
@@ -163,8 +163,14 @@ static void wait_current_trans(struct btrfs_root *root) | |||
163 | } | 163 | } |
164 | } | 164 | } |
165 | 165 | ||
166 | enum btrfs_trans_type { | ||
167 | TRANS_START, | ||
168 | TRANS_JOIN, | ||
169 | TRANS_USERSPACE, | ||
170 | }; | ||
171 | |||
166 | static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, | 172 | static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, |
167 | int num_blocks, int wait) | 173 | int num_blocks, int type) |
168 | { | 174 | { |
169 | struct btrfs_trans_handle *h = | 175 | struct btrfs_trans_handle *h = |
170 | kmem_cache_alloc(btrfs_trans_handle_cachep, GFP_NOFS); | 176 | kmem_cache_alloc(btrfs_trans_handle_cachep, GFP_NOFS); |
@@ -172,7 +178,8 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, | |||
172 | 178 | ||
173 | mutex_lock(&root->fs_info->trans_mutex); | 179 | mutex_lock(&root->fs_info->trans_mutex); |
174 | if (!root->fs_info->log_root_recovering && | 180 | if (!root->fs_info->log_root_recovering && |
175 | ((wait == 1 && !root->fs_info->open_ioctl_trans) || wait == 2)) | 181 | ((type == TRANS_START && !root->fs_info->open_ioctl_trans) || |
182 | type == TRANS_USERSPACE)) | ||
176 | wait_current_trans(root); | 183 | wait_current_trans(root); |
177 | ret = join_transaction(root); | 184 | ret = join_transaction(root); |
178 | BUG_ON(ret); | 185 | BUG_ON(ret); |
@@ -186,7 +193,7 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, | |||
186 | h->alloc_exclude_start = 0; | 193 | h->alloc_exclude_start = 0; |
187 | h->delayed_ref_updates = 0; | 194 | h->delayed_ref_updates = 0; |
188 | 195 | ||
189 | if (!current->journal_info) | 196 | if (!current->journal_info && type != TRANS_USERSPACE) |
190 | current->journal_info = h; | 197 | current->journal_info = h; |
191 | 198 | ||
192 | root->fs_info->running_transaction->use_count++; | 199 | root->fs_info->running_transaction->use_count++; |
@@ -198,18 +205,18 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, | |||
198 | struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root, | 205 | struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root, |
199 | int num_blocks) | 206 | int num_blocks) |
200 | { | 207 | { |
201 | return start_transaction(root, num_blocks, 1); | 208 | return start_transaction(root, num_blocks, TRANS_START); |
202 | } | 209 | } |
203 | struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root, | 210 | struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root, |
204 | int num_blocks) | 211 | int num_blocks) |
205 | { | 212 | { |
206 | return start_transaction(root, num_blocks, 0); | 213 | return start_transaction(root, num_blocks, TRANS_JOIN); |
207 | } | 214 | } |
208 | 215 | ||
209 | struct btrfs_trans_handle *btrfs_start_ioctl_transaction(struct btrfs_root *r, | 216 | struct btrfs_trans_handle *btrfs_start_ioctl_transaction(struct btrfs_root *r, |
210 | int num_blocks) | 217 | int num_blocks) |
211 | { | 218 | { |
212 | return start_transaction(r, num_blocks, 2); | 219 | return start_transaction(r, num_blocks, TRANS_USERSPACE); |
213 | } | 220 | } |
214 | 221 | ||
215 | /* wait for a transaction commit to be fully complete */ | 222 | /* wait for a transaction commit to be fully complete */ |