Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Btrfs: use helpers for last_trans_log_full_commit instead of opencode

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>

authored by

Miao Xie and committed by
Chris Mason
995946dd 1f21ef0a

+36 -27
+2 -3
fs/btrfs/extent-tree.c
··· 26 26 #include <linux/ratelimit.h> 27 27 #include <linux/percpu_counter.h> 28 28 #include "hash.h" 29 - #include "ctree.h" 29 + #include "tree-log.h" 30 30 #include "disk-io.h" 31 31 #include "print-tree.h" 32 - #include "transaction.h" 33 32 #include "volumes.h" 34 33 #include "raid56.h" 35 34 #include "locking.h" ··· 8713 8714 8714 8715 extent_root = root->fs_info->extent_root; 8715 8716 8716 - root->fs_info->last_trans_log_full_commit = trans->transid; 8717 + btrfs_set_log_full_commit(root->fs_info, trans); 8717 8718 8718 8719 cache = btrfs_create_block_group_cache(root, chunk_offset, size); 8719 8720 if (!cache)
+1 -1
fs/btrfs/inode.c
··· 8329 8329 BTRFS_I(old_inode)->dir_index = 0ULL; 8330 8330 if (unlikely(old_ino == BTRFS_FIRST_FREE_OBJECTID)) { 8331 8331 /* force full log commit if subvolume involved. */ 8332 - root->fs_info->last_trans_log_full_commit = trans->transid; 8332 + btrfs_set_log_full_commit(root->fs_info, trans); 8333 8333 } else { 8334 8334 ret = btrfs_insert_inode_ref(trans, dest, 8335 8335 new_dentry->d_name.name,
+17 -23
fs/btrfs/tree-log.c
··· 20 20 #include <linux/slab.h> 21 21 #include <linux/blkdev.h> 22 22 #include <linux/list_sort.h> 23 - #include "ctree.h" 24 - #include "transaction.h" 23 + #include "tree-log.h" 25 24 #include "disk-io.h" 26 25 #include "locking.h" 27 26 #include "print-tree.h" 28 27 #include "backref.h" 29 - #include "tree-log.h" 30 28 #include "hash.h" 31 29 32 30 /* magic values for the inode_only field in btrfs_log_inode: ··· 142 144 143 145 mutex_lock(&root->log_mutex); 144 146 if (root->log_root) { 145 - if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) == 146 - trans->transid) { 147 + if (btrfs_need_log_full_commit(root->fs_info, trans)) { 147 148 ret = -EAGAIN; 148 149 goto out; 149 150 } 150 - 151 151 if (!root->log_start_pid) { 152 152 root->log_start_pid = current->pid; 153 153 clear_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state); ··· 2508 2512 } 2509 2513 2510 2514 /* bail out if we need to do a full commit */ 2511 - if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) == 2512 - trans->transid) { 2515 + if (btrfs_need_log_full_commit(root->fs_info, trans)) { 2513 2516 ret = -EAGAIN; 2514 2517 btrfs_free_logged_extents(log, log_transid); 2515 2518 mutex_unlock(&root->log_mutex); ··· 2529 2534 blk_finish_plug(&plug); 2530 2535 btrfs_abort_transaction(trans, root, ret); 2531 2536 btrfs_free_logged_extents(log, log_transid); 2532 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) = 2533 - trans->transid; 2537 + btrfs_set_log_full_commit(root->fs_info, trans); 2534 2538 mutex_unlock(&root->log_mutex); 2535 2539 goto out; 2536 2540 } ··· 2572 2578 list_del_init(&root_log_ctx.list); 2573 2579 2574 2580 blk_finish_plug(&plug); 2575 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) = 2576 - trans->transid; 2581 + btrfs_set_log_full_commit(root->fs_info, trans); 2582 + 2577 2583 if (ret != -ENOSPC) { 2578 2584 btrfs_abort_transaction(trans, root, ret); 2579 2585 mutex_unlock(&log_root_tree->log_mutex); ··· 2617 2623 * now that we've moved on to the tree of log tree roots, 2618 2624 * check the full commit flag again 2619 2625 */ 2620 - if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) == 2621 - trans->transid) { 2626 + if (btrfs_need_log_full_commit(root->fs_info, trans)) { 2622 2627 blk_finish_plug(&plug); 2623 2628 btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark); 2624 2629 btrfs_free_logged_extents(log, log_transid); ··· 2631 2638 EXTENT_DIRTY | EXTENT_NEW); 2632 2639 blk_finish_plug(&plug); 2633 2640 if (ret) { 2634 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) = 2635 - trans->transid; 2641 + btrfs_set_log_full_commit(root->fs_info, trans); 2636 2642 btrfs_abort_transaction(trans, root, ret); 2637 2643 btrfs_free_logged_extents(log, log_transid); 2638 2644 mutex_unlock(&log_root_tree->log_mutex); ··· 2660 2668 */ 2661 2669 ret = write_ctree_super(trans, root->fs_info->tree_root, 1); 2662 2670 if (ret) { 2663 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) = 2664 - trans->transid; 2671 + btrfs_set_log_full_commit(root->fs_info, trans); 2665 2672 btrfs_abort_transaction(trans, root, ret); 2666 2673 goto out_wake_log_root; 2667 2674 } ··· 2878 2887 out_unlock: 2879 2888 mutex_unlock(&BTRFS_I(dir)->log_mutex); 2880 2889 if (ret == -ENOSPC) { 2881 - root->fs_info->last_trans_log_full_commit = trans->transid; 2890 + btrfs_set_log_full_commit(root->fs_info, trans); 2882 2891 ret = 0; 2883 2892 } else if (ret < 0) 2884 2893 btrfs_abort_transaction(trans, root, ret); ··· 2911 2920 dirid, &index); 2912 2921 mutex_unlock(&BTRFS_I(inode)->log_mutex); 2913 2922 if (ret == -ENOSPC) { 2914 - root->fs_info->last_trans_log_full_commit = trans->transid; 2923 + btrfs_set_log_full_commit(root->fs_info, trans); 2915 2924 ret = 0; 2916 2925 } else if (ret < 0 && ret != -ENOENT) 2917 2926 btrfs_abort_transaction(trans, root, ret); ··· 4122 4131 * make sure any commits to the log are forced 4123 4132 * to be full commits 4124 4133 */ 4125 - root->fs_info->last_trans_log_full_commit = 4126 - trans->transid; 4134 + btrfs_set_log_full_commit(root->fs_info, trans); 4127 4135 ret = 1; 4128 4136 break; 4129 4137 } ··· 4168 4178 goto end_no_trans; 4169 4179 } 4170 4180 4181 + /* 4182 + * The prev transaction commit doesn't complete, we need do 4183 + * full commit by ourselves. 4184 + */ 4171 4185 if (root->fs_info->last_trans_log_full_commit > 4172 4186 root->fs_info->last_trans_committed) { 4173 4187 ret = 1; ··· 4241 4247 end_trans: 4242 4248 dput(old_parent); 4243 4249 if (ret < 0) { 4244 - root->fs_info->last_trans_log_full_commit = trans->transid; 4250 + btrfs_set_log_full_commit(root->fs_info, trans); 4245 4251 ret = 1; 4246 4252 } 4247 4253
+16
fs/btrfs/tree-log.h
··· 19 19 #ifndef __TREE_LOG_ 20 20 #define __TREE_LOG_ 21 21 22 + #include "ctree.h" 23 + #include "transaction.h" 24 + 22 25 /* return value for btrfs_log_dentry_safe that means we don't need to log it at all */ 23 26 #define BTRFS_NO_LOG_SYNC 256 24 27 ··· 36 33 ctx->log_ret = 0; 37 34 ctx->log_transid = 0; 38 35 INIT_LIST_HEAD(&ctx->list); 36 + } 37 + 38 + static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info, 39 + struct btrfs_trans_handle *trans) 40 + { 41 + ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid; 42 + } 43 + 44 + static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info, 45 + struct btrfs_trans_handle *trans) 46 + { 47 + return ACCESS_ONCE(fs_info->last_trans_log_full_commit) == 48 + trans->transid; 39 49 } 40 50 41 51 int btrfs_sync_log(struct btrfs_trans_handle *trans,