transaction.c (4b82490649f5c8ecbf888752c325ea68831c497e) transaction.c (178260b2c14969f29ba39a78df74ed485abc6203)
1/*
2 * Copyright (C) 2007 Oracle. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,

--- 36 unchanged lines hidden (view full) ---

45}
46
47static noinline void switch_commit_root(struct btrfs_root *root)
48{
49 free_extent_buffer(root->commit_root);
50 root->commit_root = btrfs_root_node(root);
51}
52
1/*
2 * Copyright (C) 2007 Oracle. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,

--- 36 unchanged lines hidden (view full) ---

45}
46
47static noinline void switch_commit_root(struct btrfs_root *root)
48{
49 free_extent_buffer(root->commit_root);
50 root->commit_root = btrfs_root_node(root);
51}
52
53static inline int can_join_transaction(struct btrfs_transaction *trans,
54 int type)
55{
56 return !(trans->in_commit &&
57 type != TRANS_JOIN &&
58 type != TRANS_JOIN_NOLOCK);
59}
60
53/*
54 * either allocate a new transaction or hop into the existing one
55 */
56static noinline int join_transaction(struct btrfs_root *root, int type)
57{
58 struct btrfs_transaction *cur_trans;
59 struct btrfs_fs_info *fs_info = root->fs_info;
60

--- 19 unchanged lines hidden (view full) ---

80 }
81
82 cur_trans = fs_info->running_transaction;
83 if (cur_trans) {
84 if (cur_trans->aborted) {
85 spin_unlock(&fs_info->trans_lock);
86 return cur_trans->aborted;
87 }
61/*
62 * either allocate a new transaction or hop into the existing one
63 */
64static noinline int join_transaction(struct btrfs_root *root, int type)
65{
66 struct btrfs_transaction *cur_trans;
67 struct btrfs_fs_info *fs_info = root->fs_info;
68

--- 19 unchanged lines hidden (view full) ---

88 }
89
90 cur_trans = fs_info->running_transaction;
91 if (cur_trans) {
92 if (cur_trans->aborted) {
93 spin_unlock(&fs_info->trans_lock);
94 return cur_trans->aborted;
95 }
96 if (!can_join_transaction(cur_trans, type)) {
97 spin_unlock(&fs_info->trans_lock);
98 return -EBUSY;
99 }
88 atomic_inc(&cur_trans->use_count);
89 atomic_inc(&cur_trans->num_writers);
90 cur_trans->num_joined++;
91 spin_unlock(&fs_info->trans_lock);
92 return 0;
93 }
94 spin_unlock(&fs_info->trans_lock);
95

--- 259 unchanged lines hidden (view full) ---

355 if (type < TRANS_JOIN_NOLOCK)
356 sb_start_intwrite(root->fs_info->sb);
357
358 if (may_wait_transaction(root, type))
359 wait_current_trans(root);
360
361 do {
362 ret = join_transaction(root, type);
100 atomic_inc(&cur_trans->use_count);
101 atomic_inc(&cur_trans->num_writers);
102 cur_trans->num_joined++;
103 spin_unlock(&fs_info->trans_lock);
104 return 0;
105 }
106 spin_unlock(&fs_info->trans_lock);
107

--- 259 unchanged lines hidden (view full) ---

367 if (type < TRANS_JOIN_NOLOCK)
368 sb_start_intwrite(root->fs_info->sb);
369
370 if (may_wait_transaction(root, type))
371 wait_current_trans(root);
372
373 do {
374 ret = join_transaction(root, type);
363 if (ret == -EBUSY)
375 if (ret == -EBUSY) {
364 wait_current_trans(root);
376 wait_current_trans(root);
377 if (unlikely(type == TRANS_ATTACH))
378 ret = -ENOENT;
379 }
365 } while (ret == -EBUSY);
366
367 if (ret < 0) {
368 /* We must get the transaction if we are JOIN_NOLOCK. */
369 BUG_ON(type == TRANS_JOIN_NOLOCK);
370 goto join_fail;
371 }
372

--- 1454 unchanged lines hidden ---
380 } while (ret == -EBUSY);
381
382 if (ret < 0) {
383 /* We must get the transaction if we are JOIN_NOLOCK. */
384 BUG_ON(type == TRANS_JOIN_NOLOCK);
385 goto join_fail;
386 }
387

--- 1454 unchanged lines hidden ---