Btrfs: add a type field for the transaction handle
authorMiao Xie <miaox@cn.fujitsu.com>
Thu, 20 Sep 2012 07:51:59 +0000 (01:51 -0600)
committerChris Mason <chris.mason@fusionio.com>
Tue, 9 Oct 2012 13:15:38 +0000 (09:15 -0400)
This patch add a type field into the transaction handle structure,
in this way, we needn't implement various end-transaction functions
and can make the code more simple and readable.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
fs/btrfs/inode.c
fs/btrfs/transaction.c
fs/btrfs/transaction.h

index 596305e4d75b6904b11bb7cf69bfe4a1782fd120..e355eb0aea1eccb83fd75d4ba78854caea9d447c 100644 (file)
@@ -1363,11 +1363,7 @@ out_check:
        }
 
 error:
-       if (nolock) {
-               err = btrfs_end_transaction_nolock(trans, root);
-       } else {
-               err = btrfs_end_transaction(trans, root);
-       }
+       err = btrfs_end_transaction(trans, root);
        if (!ret)
                ret = err;
 
@@ -1957,12 +1953,8 @@ out_unlock:
 out:
        if (root != root->fs_info->tree_root)
                btrfs_delalloc_release_metadata(inode, ordered_extent->len);
-       if (trans) {
-               if (nolock)
-                       btrfs_end_transaction_nolock(trans, root);
-               else
-                       btrfs_end_transaction(trans, root);
-       }
+       if (trans)
+               btrfs_end_transaction(trans, root);
 
        if (ret)
                clear_extent_uptodate(io_tree, ordered_extent->file_offset,
@@ -4524,10 +4516,7 @@ int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc)
                        trans = btrfs_join_transaction(root);
                if (IS_ERR(trans))
                        return PTR_ERR(trans);
-               if (nolock)
-                       ret = btrfs_end_transaction_nolock(trans, root);
-               else
-                       ret = btrfs_commit_transaction(trans, root);
+               ret = btrfs_commit_transaction(trans, root);
        }
        return ret;
 }
index 35489644c24783c925fd870f4fcb8bd80f36c285..d0a2b7e493814c61a28c21f3e636b6b1a1d31dd1 100644 (file)
@@ -267,14 +267,6 @@ static void wait_current_trans(struct btrfs_root *root)
        }
 }
 
-enum btrfs_trans_type {
-       TRANS_START,
-       TRANS_JOIN,
-       TRANS_USERSPACE,
-       TRANS_JOIN_NOLOCK,
-       TRANS_JOIN_FREEZE,
-};
-
 static int may_wait_transaction(struct btrfs_root *root, int type)
 {
        if (root->fs_info->log_root_recovering)
@@ -388,6 +380,7 @@ again:
        h->aborted = 0;
        h->qgroup_reserved = qgroup_reserved;
        h->delayed_ref_elem.seq = 0;
+       h->type = type;
        INIT_LIST_HEAD(&h->qgroup_ref_list);
        INIT_LIST_HEAD(&h->new_bgs);
 
@@ -540,11 +533,12 @@ int btrfs_should_end_transaction(struct btrfs_trans_handle *trans,
 }
 
 static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
-                         struct btrfs_root *root, int throttle, int lock)
+                         struct btrfs_root *root, int throttle)
 {
        struct btrfs_transaction *cur_trans = trans->transaction;
        struct btrfs_fs_info *info = root->fs_info;
        int count = 0;
+       int lock = (trans->type != TRANS_JOIN_NOLOCK);
        int err = 0;
 
        if (--trans->use_count) {
@@ -645,7 +639,7 @@ int btrfs_end_transaction(struct btrfs_trans_handle *trans,
 {
        int ret;
 
-       ret = __btrfs_end_transaction(trans, root, 0, 1);
+       ret = __btrfs_end_transaction(trans, root, 0);
        if (ret)
                return ret;
        return 0;
@@ -656,18 +650,7 @@ int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans,
 {
        int ret;
 
-       ret = __btrfs_end_transaction(trans, root, 1, 1);
-       if (ret)
-               return ret;
-       return 0;
-}
-
-int btrfs_end_transaction_nolock(struct btrfs_trans_handle *trans,
-                                struct btrfs_root *root)
-{
-       int ret;
-
-       ret = __btrfs_end_transaction(trans, root, 0, 0);
+       ret = __btrfs_end_transaction(trans, root, 1);
        if (ret)
                return ret;
        return 0;
@@ -676,7 +659,7 @@ int btrfs_end_transaction_nolock(struct btrfs_trans_handle *trans,
 int btrfs_end_transaction_dmeta(struct btrfs_trans_handle *trans,
                                struct btrfs_root *root)
 {
-       return __btrfs_end_transaction(trans, root, 1, 1);
+       return __btrfs_end_transaction(trans, root, 1);
 }
 
 /*
index fbf8313b9d67463d5da5a3d6cc273f655287aa65..0630bd19396a4ab5a0a681cb90707f747767f218 100644 (file)
@@ -47,6 +47,14 @@ struct btrfs_transaction {
        int aborted;
 };
 
+enum btrfs_trans_type {
+       TRANS_START,
+       TRANS_JOIN,
+       TRANS_USERSPACE,
+       TRANS_JOIN_NOLOCK,
+       TRANS_JOIN_FREEZE,
+};
+
 struct btrfs_trans_handle {
        u64 transid;
        u64 bytes_reserved;
@@ -58,8 +66,9 @@ struct btrfs_trans_handle {
        struct btrfs_transaction *transaction;
        struct btrfs_block_rsv *block_rsv;
        struct btrfs_block_rsv *orig_rsv;
-       int aborted;
-       int adding_csums;
+       short aborted;
+       short adding_csums;
+       enum btrfs_trans_type type;
        /*
         * this root is only needed to validate that the root passed to
         * start_transaction is the same as the one passed to end_transaction.
@@ -94,8 +103,6 @@ static inline void btrfs_set_inode_last_trans(struct btrfs_trans_handle *trans,
 
 int btrfs_end_transaction(struct btrfs_trans_handle *trans,
                          struct btrfs_root *root);
-int btrfs_end_transaction_nolock(struct btrfs_trans_handle *trans,
-                                struct btrfs_root *root);
 struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root,
                                                   int num_items);
 struct btrfs_trans_handle *btrfs_start_transaction_noflush(