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

Btrfs: use bitfield instead of integer data type for the some variants in btrfs_root

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
27cdeb70 f959492f

+109 -94
+14 -11
fs/btrfs/ctree.c
··· 224 224 static void add_root_to_dirty_list(struct btrfs_root *root) 225 225 { 226 226 spin_lock(&root->fs_info->trans_lock); 227 - if (root->track_dirty && list_empty(&root->dirty_list)) { 227 + if (test_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state) && 228 + list_empty(&root->dirty_list)) { 228 229 list_add(&root->dirty_list, 229 230 &root->fs_info->dirty_cowonly_roots); 230 231 } ··· 247 246 int level; 248 247 struct btrfs_disk_key disk_key; 249 248 250 - WARN_ON(root->ref_cows && trans->transid != 251 - root->fs_info->running_transaction->transid); 252 - WARN_ON(root->ref_cows && trans->transid != root->last_trans); 249 + WARN_ON(test_bit(BTRFS_ROOT_REF_COWS, &root->state) && 250 + trans->transid != root->fs_info->running_transaction->transid); 251 + WARN_ON(test_bit(BTRFS_ROOT_REF_COWS, &root->state) && 252 + trans->transid != root->last_trans); 253 253 254 254 level = btrfs_header_level(buf); 255 255 if (level == 0) ··· 999 997 * snapshot and the block was not allocated by tree relocation, 1000 998 * we know the block is not shared. 1001 999 */ 1002 - if (root->ref_cows && 1000 + if (test_bit(BTRFS_ROOT_REF_COWS, &root->state) && 1003 1001 buf != root->node && buf != root->commit_root && 1004 1002 (btrfs_header_generation(buf) <= 1005 1003 btrfs_root_last_snapshot(&root->root_item) || 1006 1004 btrfs_header_flag(buf, BTRFS_HEADER_FLAG_RELOC))) 1007 1005 return 1; 1008 1006 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 1009 - if (root->ref_cows && 1007 + if (test_bit(BTRFS_ROOT_REF_COWS, &root->state) && 1010 1008 btrfs_header_backref_rev(buf) < BTRFS_MIXED_BACKREF_REV) 1011 1009 return 1; 1012 1010 #endif ··· 1148 1146 1149 1147 btrfs_assert_tree_locked(buf); 1150 1148 1151 - WARN_ON(root->ref_cows && trans->transid != 1152 - root->fs_info->running_transaction->transid); 1153 - WARN_ON(root->ref_cows && trans->transid != root->last_trans); 1149 + WARN_ON(test_bit(BTRFS_ROOT_REF_COWS, &root->state) && 1150 + trans->transid != root->fs_info->running_transaction->transid); 1151 + WARN_ON(test_bit(BTRFS_ROOT_REF_COWS, &root->state) && 1152 + trans->transid != root->last_trans); 1154 1153 1155 1154 level = btrfs_header_level(buf); 1156 1155 ··· 1196 1193 return ret; 1197 1194 } 1198 1195 1199 - if (root->ref_cows) { 1196 + if (test_bit(BTRFS_ROOT_REF_COWS, &root->state)) { 1200 1197 ret = btrfs_reloc_cow_block(trans, root, buf, cow); 1201 1198 if (ret) 1202 1199 return ret; ··· 1559 1556 !btrfs_header_flag(buf, BTRFS_HEADER_FLAG_WRITTEN) && 1560 1557 !(root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID && 1561 1558 btrfs_header_flag(buf, BTRFS_HEADER_FLAG_RELOC)) && 1562 - !root->force_cow) 1559 + !test_bit(BTRFS_ROOT_FORCE_COW, &root->state)) 1563 1560 return 0; 1564 1561 return 1; 1565 1562 }
+21 -18
fs/btrfs/ctree.h
··· 1711 1711 }; 1712 1712 1713 1713 /* 1714 + * The state of btrfs root 1715 + */ 1716 + /* 1717 + * btrfs_record_root_in_trans is a multi-step process, 1718 + * and it can race with the balancing code. But the 1719 + * race is very small, and only the first time the root 1720 + * is added to each transaction. So IN_TRANS_SETUP 1721 + * is used to tell us when more checks are required 1722 + */ 1723 + #define BTRFS_ROOT_IN_TRANS_SETUP 0 1724 + #define BTRFS_ROOT_REF_COWS 1 1725 + #define BTRFS_ROOT_TRACK_DIRTY 2 1726 + #define BTRFS_ROOT_IN_RADIX 3 1727 + #define BTRFS_ROOT_DUMMY_ROOT 4 1728 + #define BTRFS_ROOT_ORPHAN_ITEM_INSERTED 5 1729 + #define BTRFS_ROOT_DEFRAG_RUNNING 6 1730 + #define BTRFS_ROOT_FORCE_COW 7 1731 + #define BTRFS_ROOT_MULTI_LOG_TASKS 8 1732 + 1733 + /* 1714 1734 * in ram representation of the tree. extent_root is used for all allocations 1715 1735 * and for the extent tree extent_root root. 1716 1736 */ ··· 1741 1721 struct btrfs_root *log_root; 1742 1722 struct btrfs_root *reloc_root; 1743 1723 1724 + unsigned long state; 1744 1725 struct btrfs_root_item root_item; 1745 1726 struct btrfs_key root_key; 1746 1727 struct btrfs_fs_info *fs_info; ··· 1776 1755 /* Just be updated when the commit succeeds. */ 1777 1756 int last_log_commit; 1778 1757 pid_t log_start_pid; 1779 - bool log_multiple_pids; 1780 1758 1781 1759 u64 objectid; 1782 1760 u64 last_trans; ··· 1795 1775 1796 1776 u64 highest_objectid; 1797 1777 1798 - /* btrfs_record_root_in_trans is a multi-step process, 1799 - * and it can race with the balancing code. But the 1800 - * race is very small, and only the first time the root 1801 - * is added to each transaction. So in_trans_setup 1802 - * is used to tell us when more checks are required 1803 - */ 1804 - unsigned long in_trans_setup; 1805 - int ref_cows; 1806 - int track_dirty; 1807 - int in_radix; 1808 - #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS 1809 - int dummy_root; 1810 - #endif 1811 1778 u64 defrag_trans_start; 1812 1779 struct btrfs_key defrag_progress; 1813 1780 struct btrfs_key defrag_max; 1814 - int defrag_running; 1815 1781 char *name; 1816 1782 1817 1783 /* the dirty list is only used by non-reference counted roots */ ··· 1811 1805 spinlock_t orphan_lock; 1812 1806 atomic_t orphan_inodes; 1813 1807 struct btrfs_block_rsv *orphan_block_rsv; 1814 - int orphan_item_inserted; 1815 1808 int orphan_cleanup_state; 1816 1809 1817 1810 spinlock_t inode_lock; ··· 1827 1822 * for stat. It may be used for more later 1828 1823 */ 1829 1824 dev_t anon_dev; 1830 - 1831 - int force_cow; 1832 1825 1833 1826 spinlock_t root_item_lock; 1834 1827 atomic_t refs;
+15 -18
fs/btrfs/disk-io.c
··· 1201 1201 root->nodesize = nodesize; 1202 1202 root->leafsize = leafsize; 1203 1203 root->stripesize = stripesize; 1204 - root->ref_cows = 0; 1205 - root->track_dirty = 0; 1206 - root->in_radix = 0; 1207 - root->orphan_item_inserted = 0; 1204 + root->state = 0; 1208 1205 root->orphan_cleanup_state = 0; 1209 1206 1210 1207 root->objectid = objectid; ··· 1262 1265 else 1263 1266 root->defrag_trans_start = 0; 1264 1267 init_completion(&root->kobj_unregister); 1265 - root->defrag_running = 0; 1266 1268 root->root_key.objectid = objectid; 1267 1269 root->anon_dev = 0; 1268 1270 ··· 1286 1290 if (!root) 1287 1291 return ERR_PTR(-ENOMEM); 1288 1292 __setup_root(4096, 4096, 4096, 4096, root, NULL, 1); 1289 - root->dummy_root = 1; 1293 + set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state); 1290 1294 1291 1295 return root; 1292 1296 } ··· 1337 1341 btrfs_mark_buffer_dirty(leaf); 1338 1342 1339 1343 root->commit_root = btrfs_root_node(root); 1340 - root->track_dirty = 1; 1341 - 1344 + set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); 1342 1345 1343 1346 root->root_item.flags = 0; 1344 1347 root->root_item.byte_limit = 0; ··· 1391 1396 root->root_key.objectid = BTRFS_TREE_LOG_OBJECTID; 1392 1397 root->root_key.type = BTRFS_ROOT_ITEM_KEY; 1393 1398 root->root_key.offset = BTRFS_TREE_LOG_OBJECTID; 1399 + 1394 1400 /* 1401 + * DON'T set REF_COWS for log trees 1402 + * 1395 1403 * log trees do not get reference counted because they go away 1396 1404 * before a real commit is actually done. They do store pointers 1397 1405 * to file data extents, and those reference counts still get 1398 1406 * updated (along with back refs to the log tree). 1399 1407 */ 1400 - root->ref_cows = 0; 1401 1408 1402 1409 leaf = btrfs_alloc_free_block(trans, root, root->leafsize, 0, 1403 1410 BTRFS_TREE_LOG_OBJECTID, NULL, ··· 1533 1536 return root; 1534 1537 1535 1538 if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { 1536 - root->ref_cows = 1; 1539 + set_bit(BTRFS_ROOT_REF_COWS, &root->state); 1537 1540 btrfs_check_and_init_root_item(&root->root_item); 1538 1541 } 1539 1542 ··· 1603 1606 (unsigned long)root->root_key.objectid, 1604 1607 root); 1605 1608 if (ret == 0) 1606 - root->in_radix = 1; 1609 + set_bit(BTRFS_ROOT_IN_RADIX, &root->state); 1607 1610 spin_unlock(&fs_info->fs_roots_radix_lock); 1608 1611 radix_tree_preload_end(); 1609 1612 ··· 1659 1662 if (ret < 0) 1660 1663 goto fail; 1661 1664 if (ret == 0) 1662 - root->orphan_item_inserted = 1; 1665 + set_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &root->state); 1663 1666 1664 1667 ret = btrfs_insert_fs_root(fs_info, root); 1665 1668 if (ret) { ··· 2098 2101 struct btrfs_root, root_list); 2099 2102 list_del(&gang[0]->root_list); 2100 2103 2101 - if (gang[0]->in_radix) { 2104 + if (test_bit(BTRFS_ROOT_IN_RADIX, &gang[0]->state)) { 2102 2105 btrfs_drop_and_free_fs_root(fs_info, gang[0]); 2103 2106 } else { 2104 2107 free_extent_buffer(gang[0]->node); ··· 2691 2694 ret = PTR_ERR(extent_root); 2692 2695 goto recovery_tree_root; 2693 2696 } 2694 - extent_root->track_dirty = 1; 2697 + set_bit(BTRFS_ROOT_TRACK_DIRTY, &extent_root->state); 2695 2698 fs_info->extent_root = extent_root; 2696 2699 2697 2700 location.objectid = BTRFS_DEV_TREE_OBJECTID; ··· 2700 2703 ret = PTR_ERR(dev_root); 2701 2704 goto recovery_tree_root; 2702 2705 } 2703 - dev_root->track_dirty = 1; 2706 + set_bit(BTRFS_ROOT_TRACK_DIRTY, &dev_root->state); 2704 2707 fs_info->dev_root = dev_root; 2705 2708 btrfs_init_devices_late(fs_info); 2706 2709 ··· 2710 2713 ret = PTR_ERR(csum_root); 2711 2714 goto recovery_tree_root; 2712 2715 } 2713 - csum_root->track_dirty = 1; 2716 + set_bit(BTRFS_ROOT_TRACK_DIRTY, &csum_root->state); 2714 2717 fs_info->csum_root = csum_root; 2715 2718 2716 2719 location.objectid = BTRFS_QUOTA_TREE_OBJECTID; 2717 2720 quota_root = btrfs_read_tree_root(tree_root, &location); 2718 2721 if (!IS_ERR(quota_root)) { 2719 - quota_root->track_dirty = 1; 2722 + set_bit(BTRFS_ROOT_TRACK_DIRTY, &quota_root->state); 2720 2723 fs_info->quota_enabled = 1; 2721 2724 fs_info->pending_quota_state = 1; 2722 2725 fs_info->quota_root = quota_root; ··· 2731 2734 create_uuid_tree = true; 2732 2735 check_uuid_tree = false; 2733 2736 } else { 2734 - uuid_root->track_dirty = 1; 2737 + set_bit(BTRFS_ROOT_TRACK_DIRTY, &uuid_root->state); 2735 2738 fs_info->uuid_root = uuid_root; 2736 2739 create_uuid_tree = false; 2737 2740 check_uuid_tree =
+3 -3
fs/btrfs/extent-tree.c
··· 2983 2983 nritems = btrfs_header_nritems(buf); 2984 2984 level = btrfs_header_level(buf); 2985 2985 2986 - if (!root->ref_cows && level == 0) 2986 + if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state) && level == 0) 2987 2987 return 0; 2988 2988 2989 2989 if (inc) ··· 4472 4472 { 4473 4473 struct btrfs_block_rsv *block_rsv = NULL; 4474 4474 4475 - if (root->ref_cows) 4475 + if (test_bit(BTRFS_ROOT_REF_COWS, &root->state)) 4476 4476 block_rsv = trans->block_rsv; 4477 4477 4478 4478 if (root == root->fs_info->csum_root && trans->adding_csums) ··· 7838 7838 } 7839 7839 } 7840 7840 7841 - if (root->in_radix) { 7841 + if (test_bit(BTRFS_ROOT_IN_RADIX, &root->state)) { 7842 7842 btrfs_drop_and_free_fs_root(tree_root->fs_info, root); 7843 7843 } else { 7844 7844 free_extent_buffer(root->node);
+3 -1
fs/btrfs/file.c
··· 714 714 int recow; 715 715 int ret; 716 716 int modify_tree = -1; 717 - int update_refs = (root->ref_cows || root == root->fs_info->tree_root); 717 + int update_refs; 718 718 int found = 0; 719 719 int leafs_visited = 0; 720 720 ··· 724 724 if (start >= BTRFS_I(inode)->disk_i_size && !replace_extent) 725 725 modify_tree = 0; 726 726 727 + update_refs = (test_bit(BTRFS_ROOT_REF_COWS, &root->state) || 728 + root == root->fs_info->tree_root); 727 729 while (1) { 728 730 recow = 0; 729 731 ret = btrfs_lookup_file_extent(trans, root, path, ino,
+18 -11
fs/btrfs/inode.c
··· 2947 2947 root->orphan_block_rsv = NULL; 2948 2948 spin_unlock(&root->orphan_lock); 2949 2949 2950 - if (root->orphan_item_inserted && 2950 + if (test_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &root->state) && 2951 2951 btrfs_root_refs(&root->root_item) > 0) { 2952 2952 ret = btrfs_del_orphan_item(trans, root->fs_info->tree_root, 2953 2953 root->root_key.objectid); 2954 2954 if (ret) 2955 2955 btrfs_abort_transaction(trans, root, ret); 2956 2956 else 2957 - root->orphan_item_inserted = 0; 2957 + clear_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, 2958 + &root->state); 2958 2959 } 2959 2960 2960 2961 if (block_rsv) { ··· 3272 3271 btrfs_block_rsv_release(root, root->orphan_block_rsv, 3273 3272 (u64)-1); 3274 3273 3275 - if (root->orphan_block_rsv || root->orphan_item_inserted) { 3274 + if (root->orphan_block_rsv || 3275 + test_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &root->state)) { 3276 3276 trans = btrfs_join_transaction(root); 3277 3277 if (!IS_ERR(trans)) 3278 3278 btrfs_end_transaction(trans, root); ··· 4000 3998 * not block aligned since we will be keeping the last block of the 4001 3999 * extent just the way it is. 4002 4000 */ 4003 - if (root->ref_cows || root == root->fs_info->tree_root) 4001 + if (test_bit(BTRFS_ROOT_REF_COWS, &root->state) || 4002 + root == root->fs_info->tree_root) 4004 4003 btrfs_drop_extent_cache(inode, ALIGN(new_size, 4005 4004 root->sectorsize), (u64)-1, 0); 4006 4005 ··· 4094 4091 extent_num_bytes); 4095 4092 num_dec = (orig_num_bytes - 4096 4093 extent_num_bytes); 4097 - if (root->ref_cows && extent_start != 0) 4094 + if (test_bit(BTRFS_ROOT_REF_COWS, 4095 + &root->state) && 4096 + extent_start != 0) 4098 4097 inode_sub_bytes(inode, num_dec); 4099 4098 btrfs_mark_buffer_dirty(leaf); 4100 4099 } else { ··· 4110 4105 num_dec = btrfs_file_extent_num_bytes(leaf, fi); 4111 4106 if (extent_start != 0) { 4112 4107 found_extent = 1; 4113 - if (root->ref_cows) 4108 + if (test_bit(BTRFS_ROOT_REF_COWS, 4109 + &root->state)) 4114 4110 inode_sub_bytes(inode, num_dec); 4115 4111 } 4116 4112 } ··· 4126 4120 btrfs_file_extent_other_encoding(leaf, fi) == 0) { 4127 4121 u32 size = new_size - found_key.offset; 4128 4122 4129 - if (root->ref_cows) { 4123 + if (test_bit(BTRFS_ROOT_REF_COWS, &root->state)) 4130 4124 inode_sub_bytes(inode, item_end + 1 - 4131 4125 new_size); 4132 - } 4133 4126 4134 4127 /* 4135 4128 * update the ram bytes to properly reflect ··· 4138 4133 size = 4139 4134 btrfs_file_extent_calc_inline_size(size); 4140 4135 btrfs_truncate_item(root, path, size, 1); 4141 - } else if (root->ref_cows) { 4136 + } else if (test_bit(BTRFS_ROOT_REF_COWS, 4137 + &root->state)) { 4142 4138 inode_sub_bytes(inode, item_end + 1 - 4143 4139 found_key.offset); 4144 4140 } ··· 4161 4155 } else { 4162 4156 break; 4163 4157 } 4164 - if (found_extent && (root->ref_cows || 4165 - root == root->fs_info->tree_root)) { 4158 + if (found_extent && 4159 + (test_bit(BTRFS_ROOT_REF_COWS, &root->state) || 4160 + root == root->fs_info->tree_root)) { 4166 4161 btrfs_set_path_blocking(path); 4167 4162 ret = btrfs_free_extent(trans, root, extent_start, 4168 4163 extent_num_bytes, 0,
+2 -2
fs/btrfs/ioctl.c
··· 638 638 struct btrfs_trans_handle *trans; 639 639 int ret; 640 640 641 - if (!root->ref_cows) 641 + if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state)) 642 642 return -EINVAL; 643 643 644 644 atomic_inc(&root->will_be_snapshoted); ··· 2369 2369 dest->root_item.drop_level = 0; 2370 2370 btrfs_set_root_refs(&dest->root_item, 0); 2371 2371 2372 - if (!xchg(&dest->orphan_item_inserted, 1)) { 2372 + if (!test_and_set_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &dest->state)) { 2373 2373 ret = btrfs_insert_orphan_item(trans, 2374 2374 root->fs_info->tree_root, 2375 2375 dest->root_key.objectid);
+9 -8
fs/btrfs/relocation.c
··· 528 528 { 529 529 struct btrfs_root *reloc_root; 530 530 531 - if (!root->ref_cows) 531 + if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state)) 532 532 return 0; 533 533 534 534 reloc_root = root->reloc_root; ··· 610 610 root = read_fs_root(rc->extent_root->fs_info, root_objectid); 611 611 BUG_ON(IS_ERR(root)); 612 612 613 - if (root->ref_cows && 613 + if (test_bit(BTRFS_ROOT_REF_COWS, &root->state) && 614 614 generation != btrfs_root_generation(&root->root_item)) 615 615 return NULL; 616 616 ··· 887 887 goto out; 888 888 } 889 889 890 - if (!root->ref_cows) 890 + if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state)) 891 891 cur->cowonly = 1; 892 892 893 893 if (btrfs_root_level(&root->root_item) == cur->level) { ··· 954 954 upper->bytenr = eb->start; 955 955 upper->owner = btrfs_header_owner(eb); 956 956 upper->level = lower->level + 1; 957 - if (!root->ref_cows) 957 + if (!test_bit(BTRFS_ROOT_REF_COWS, 958 + &root->state)) 958 959 upper->cowonly = 1; 959 960 960 961 /* ··· 2442 2441 next = walk_up_backref(next, edges, &index); 2443 2442 root = next->root; 2444 2443 BUG_ON(!root); 2445 - BUG_ON(!root->ref_cows); 2444 + BUG_ON(!test_bit(BTRFS_ROOT_REF_COWS, &root->state)); 2446 2445 2447 2446 if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) { 2448 2447 record_reloc_root_in_trans(trans, root); ··· 2507 2506 BUG_ON(!root); 2508 2507 2509 2508 /* no other choice for non-references counted tree */ 2510 - if (!root->ref_cows) 2509 + if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state)) 2511 2510 return root; 2512 2511 2513 2512 if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) ··· 2894 2893 goto out; 2895 2894 } 2896 2895 2897 - if (!root || root->ref_cows) { 2896 + if (!root || test_bit(BTRFS_ROOT_REF_COWS, &root->state)) { 2898 2897 ret = reserve_metadata_space(trans, rc, node); 2899 2898 if (ret) 2900 2899 goto out; 2901 2900 } 2902 2901 2903 2902 if (root) { 2904 - if (root->ref_cows) { 2903 + if (test_bit(BTRFS_ROOT_REF_COWS, &root->state)) { 2905 2904 BUG_ON(node->new_bytenr); 2906 2905 BUG_ON(!list_empty(&node->list)); 2907 2906 btrfs_record_root_in_trans(trans, root);
+1 -1
fs/btrfs/root-tree.c
··· 306 306 break; 307 307 } 308 308 309 - root->orphan_item_inserted = 1; 309 + set_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &root->state); 310 310 311 311 err = btrfs_insert_fs_root(root->fs_info, root); 312 312 if (err) {
+17 -16
fs/btrfs/transaction.c
··· 241 241 static int record_root_in_trans(struct btrfs_trans_handle *trans, 242 242 struct btrfs_root *root) 243 243 { 244 - if (root->ref_cows && root->last_trans < trans->transid) { 244 + if (test_bit(BTRFS_ROOT_REF_COWS, &root->state) && 245 + root->last_trans < trans->transid) { 245 246 WARN_ON(root == root->fs_info->extent_root); 246 247 WARN_ON(root->commit_root != root->node); 247 248 248 249 /* 249 - * see below for in_trans_setup usage rules 250 + * see below for IN_TRANS_SETUP usage rules 250 251 * we have the reloc mutex held now, so there 251 252 * is only one writer in this function 252 253 */ 253 - root->in_trans_setup = 1; 254 + set_bit(BTRFS_ROOT_IN_TRANS_SETUP, &root->state); 254 255 255 - /* make sure readers find in_trans_setup before 256 + /* make sure readers find IN_TRANS_SETUP before 256 257 * they find our root->last_trans update 257 258 */ 258 259 smp_wmb(); ··· 280 279 * But, we have to set root->last_trans before we 281 280 * init the relocation root, otherwise, we trip over warnings 282 281 * in ctree.c. The solution used here is to flag ourselves 283 - * with root->in_trans_setup. When this is 1, we're still 282 + * with root IN_TRANS_SETUP. When this is 1, we're still 284 283 * fixing up the reloc trees and everyone must wait. 285 284 * 286 285 * When this is zero, they can trust root->last_trans and fly ··· 289 288 * done before we pop in the zero below 290 289 */ 291 290 btrfs_init_reloc_root(trans, root); 292 - smp_wmb(); 293 - root->in_trans_setup = 0; 291 + smp_mb__before_clear_bit(); 292 + clear_bit(BTRFS_ROOT_IN_TRANS_SETUP, &root->state); 294 293 } 295 294 return 0; 296 295 } ··· 299 298 int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, 300 299 struct btrfs_root *root) 301 300 { 302 - if (!root->ref_cows) 301 + if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state)) 303 302 return 0; 304 303 305 304 /* 306 - * see record_root_in_trans for comments about in_trans_setup usage 305 + * see record_root_in_trans for comments about IN_TRANS_SETUP usage 307 306 * and barriers 308 307 */ 309 308 smp_rmb(); 310 309 if (root->last_trans == trans->transid && 311 - !root->in_trans_setup) 310 + !test_bit(BTRFS_ROOT_IN_TRANS_SETUP, &root->state)) 312 311 return 0; 313 312 314 313 mutex_lock(&root->fs_info->reloc_mutex); ··· 366 365 static inline bool need_reserve_reloc_root(struct btrfs_root *root) 367 366 { 368 367 if (!root->fs_info->reloc_ctl || 369 - !root->ref_cows || 368 + !test_bit(BTRFS_ROOT_REF_COWS, &root->state) || 370 369 root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID || 371 370 root->reloc_root) 372 371 return false; ··· 1050 1049 btrfs_save_ino_cache(root, trans); 1051 1050 1052 1051 /* see comments in should_cow_block() */ 1053 - root->force_cow = 0; 1054 - smp_wmb(); 1052 + clear_bit(BTRFS_ROOT_FORCE_COW, &root->state); 1053 + smp_mb__after_clear_bit(); 1055 1054 1056 1055 if (root->commit_root != root->node) { 1057 1056 list_add_tail(&root->dirty_list, ··· 1082 1081 struct btrfs_trans_handle *trans; 1083 1082 int ret; 1084 1083 1085 - if (xchg(&root->defrag_running, 1)) 1084 + if (test_and_set_bit(BTRFS_ROOT_DEFRAG_RUNNING, &root->state)) 1086 1085 return 0; 1087 1086 1088 1087 while (1) { ··· 1105 1104 break; 1106 1105 } 1107 1106 } 1108 - root->defrag_running = 0; 1107 + clear_bit(BTRFS_ROOT_DEFRAG_RUNNING, &root->state); 1109 1108 return ret; 1110 1109 } 1111 1110 ··· 1272 1271 } 1273 1272 1274 1273 /* see comments in should_cow_block() */ 1275 - root->force_cow = 1; 1274 + set_bit(BTRFS_ROOT_FORCE_COW, &root->state); 1276 1275 smp_wmb(); 1277 1276 1278 1277 btrfs_set_root_node(new_root_item, tmp);
+1 -1
fs/btrfs/tree-defrag.c
··· 49 49 goto out; 50 50 } 51 51 52 - if (root->ref_cows == 0) 52 + if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state)) 53 53 goto out; 54 54 55 55 if (btrfs_test_opt(root, SSD))
+5 -4
fs/btrfs/tree-log.c
··· 152 152 153 153 if (!root->log_start_pid) { 154 154 root->log_start_pid = current->pid; 155 - root->log_multiple_pids = false; 155 + clear_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state); 156 156 } else if (root->log_start_pid != current->pid) { 157 - root->log_multiple_pids = true; 157 + set_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state); 158 158 } 159 159 160 160 atomic_inc(&root->log_batch); ··· 181 181 if (ret) 182 182 goto out; 183 183 } 184 - root->log_multiple_pids = false; 184 + clear_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state); 185 185 root->log_start_pid = current->pid; 186 186 atomic_inc(&root->log_batch); 187 187 atomic_inc(&root->log_writers); ··· 2500 2500 while (1) { 2501 2501 int batch = atomic_read(&root->log_batch); 2502 2502 /* when we're on an ssd, just kick the log commit out */ 2503 - if (!btrfs_test_opt(root, SSD) && root->log_multiple_pids) { 2503 + if (!btrfs_test_opt(root, SSD) && 2504 + test_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state)) { 2504 2505 mutex_unlock(&root->log_mutex); 2505 2506 schedule_timeout_uninterruptible(1); 2506 2507 mutex_lock(&root->log_mutex);