diff options
author | Miao Xie <miaox@cn.fujitsu.com> | 2013-05-16 23:53:43 -0400 |
---|---|---|
committer | Josef Bacik <jbacik@fusionio.com> | 2013-06-14 11:29:51 -0400 |
commit | 4a9d8bdee368de78ace8b36da4eb2186afea162d (patch) | |
tree | d7a34e5414a25f24f48d4b9bb4284ef2ebe16313 /fs/btrfs/transaction.h | |
parent | 581227d0d2b8735f899182f50b3a05089d02fa24 (diff) |
Btrfs: make the state of the transaction more readable
We used 3 variants to track the state of the transaction, it was complex
and wasted the memory space. Besides that, it was hard to understand that
which types of the transaction handles should be blocked in each transaction
state, so the developers often made mistakes.
This patch improved the above problem. In this patch, we define 6 states
for the transaction,
enum btrfs_trans_state {
TRANS_STATE_RUNNING = 0,
TRANS_STATE_BLOCKED = 1,
TRANS_STATE_COMMIT_START = 2,
TRANS_STATE_COMMIT_DOING = 3,
TRANS_STATE_UNBLOCKED = 4,
TRANS_STATE_COMPLETED = 5,
TRANS_STATE_MAX = 6,
}
and just use 1 variant to track those state.
In order to make the blocked handle types for each state more clear,
we introduce a array:
unsigned int btrfs_blocked_trans_types[TRANS_STATE_MAX] = {
[TRANS_STATE_RUNNING] = 0U,
[TRANS_STATE_BLOCKED] = (__TRANS_USERSPACE |
__TRANS_START),
[TRANS_STATE_COMMIT_START] = (__TRANS_USERSPACE |
__TRANS_START |
__TRANS_ATTACH),
[TRANS_STATE_COMMIT_DOING] = (__TRANS_USERSPACE |
__TRANS_START |
__TRANS_ATTACH |
__TRANS_JOIN),
[TRANS_STATE_UNBLOCKED] = (__TRANS_USERSPACE |
__TRANS_START |
__TRANS_ATTACH |
__TRANS_JOIN |
__TRANS_JOIN_NOLOCK),
[TRANS_STATE_COMPLETED] = (__TRANS_USERSPACE |
__TRANS_START |
__TRANS_ATTACH |
__TRANS_JOIN |
__TRANS_JOIN_NOLOCK),
}
it is very intuitionistic.
Besides that, because we remove ->in_commit in transaction structure, so
the lock ->commit_lock which was used to protect it is unnecessary, remove
->commit_lock.
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Diffstat (limited to 'fs/btrfs/transaction.h')
-rw-r--r-- | fs/btrfs/transaction.h | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h index 0fc45e2a5139..66d2a6ccbf05 100644 --- a/fs/btrfs/transaction.h +++ b/fs/btrfs/transaction.h | |||
@@ -22,6 +22,16 @@ | |||
22 | #include "delayed-ref.h" | 22 | #include "delayed-ref.h" |
23 | #include "ctree.h" | 23 | #include "ctree.h" |
24 | 24 | ||
25 | enum btrfs_trans_state { | ||
26 | TRANS_STATE_RUNNING = 0, | ||
27 | TRANS_STATE_BLOCKED = 1, | ||
28 | TRANS_STATE_COMMIT_START = 2, | ||
29 | TRANS_STATE_COMMIT_DOING = 3, | ||
30 | TRANS_STATE_UNBLOCKED = 4, | ||
31 | TRANS_STATE_COMPLETED = 5, | ||
32 | TRANS_STATE_MAX = 6, | ||
33 | }; | ||
34 | |||
25 | struct btrfs_transaction { | 35 | struct btrfs_transaction { |
26 | u64 transid; | 36 | u64 transid; |
27 | /* | 37 | /* |
@@ -37,10 +47,8 @@ struct btrfs_transaction { | |||
37 | atomic_t num_writers; | 47 | atomic_t num_writers; |
38 | atomic_t use_count; | 48 | atomic_t use_count; |
39 | 49 | ||
40 | spinlock_t commit_lock; | 50 | /* Be protected by fs_info->trans_lock when we want to change it. */ |
41 | int in_commit; | 51 | enum btrfs_trans_state state; |
42 | int commit_done; | ||
43 | int blocked; | ||
44 | struct list_head list; | 52 | struct list_head list; |
45 | struct extent_io_tree dirty_pages; | 53 | struct extent_io_tree dirty_pages; |
46 | unsigned long start_time; | 54 | unsigned long start_time; |