Skip to content

Commit 92a7cc4

Browse files
adam900710kdave
authored andcommitted
btrfs: rename BTRFS_ROOT_REF_COWS to BTRFS_ROOT_SHAREABLE
The name BTRFS_ROOT_REF_COWS is not very clear about the meaning. In fact, that bit can only be set to those trees: - Subvolume roots - Data reloc root - Reloc roots for above roots All other trees won't get this bit set. So just by the result, it is obvious that, roots with this bit set can have tree blocks shared with other trees. Either shared by snapshots, or by reloc roots (an special snapshot created by relocation). This patch will rename BTRFS_ROOT_REF_COWS to BTRFS_ROOT_SHAREABLE to make it easier to understand, and update all comment mentioning "reference counted" to follow the rename. Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent ae3e715 commit 92a7cc4

File tree

13 files changed

+81
-55
lines changed

13 files changed

+81
-55
lines changed

fs/btrfs/backref.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,7 +2702,7 @@ static int handle_indirect_tree_backref(struct btrfs_backref_cache *cache,
27022702
root = btrfs_get_fs_root(fs_info, &root_key, false);
27032703
if (IS_ERR(root))
27042704
return PTR_ERR(root);
2705-
if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state))
2705+
if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state))
27062706
cur->cowonly = 1;
27072707

27082708
if (btrfs_root_level(&root->root_item) == cur->level) {
@@ -2789,7 +2789,7 @@ static int handle_indirect_tree_backref(struct btrfs_backref_cache *cache,
27892789
goto out;
27902790
}
27912791
upper->owner = btrfs_header_owner(eb);
2792-
if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state))
2792+
if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state))
27932793
upper->cowonly = 1;
27942794

27952795
/*

fs/btrfs/backref.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ struct btrfs_backref_node {
184184
struct extent_buffer *eb;
185185
/* Level of the tree block */
186186
unsigned int level:8;
187-
/* Is the block in non-reference counted tree */
187+
/* Is the block in a non-shareable tree */
188188
unsigned int cowonly:1;
189189
/* 1 if no child node is in the cache */
190190
unsigned int lowest:1;

fs/btrfs/block-rsv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ static struct btrfs_block_rsv *get_block_rsv(
458458
struct btrfs_fs_info *fs_info = root->fs_info;
459459
struct btrfs_block_rsv *block_rsv = NULL;
460460

461-
if (test_bit(BTRFS_ROOT_REF_COWS, &root->state) ||
461+
if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state) ||
462462
(root == fs_info->csum_root && trans->adding_csums) ||
463463
(root == fs_info->uuid_root))
464464
block_rsv = trans->block_rsv;

fs/btrfs/ctree.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,10 @@ struct extent_buffer *btrfs_root_node(struct btrfs_root *root)
144144
return eb;
145145
}
146146

147-
/* cowonly root (everything not a reference counted cow subvolume), just get
148-
* put onto a simple dirty list. transaction.c walks this to make sure they
149-
* get properly updated on disk.
147+
/*
148+
* Cowonly root (not-shareable trees, everything not subvolume or reloc roots),
149+
* just get put onto a simple dirty list. Transaction walks this list to make
150+
* sure they get properly updated on disk.
150151
*/
151152
static void add_root_to_dirty_list(struct btrfs_root *root)
152153
{
@@ -185,9 +186,9 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
185186
int level;
186187
struct btrfs_disk_key disk_key;
187188

188-
WARN_ON(test_bit(BTRFS_ROOT_REF_COWS, &root->state) &&
189+
WARN_ON(test_bit(BTRFS_ROOT_SHAREABLE, &root->state) &&
189190
trans->transid != fs_info->running_transaction->transid);
190-
WARN_ON(test_bit(BTRFS_ROOT_REF_COWS, &root->state) &&
191+
WARN_ON(test_bit(BTRFS_ROOT_SHAREABLE, &root->state) &&
191192
trans->transid != root->last_trans);
192193

193194
level = btrfs_header_level(buf);
@@ -826,12 +827,11 @@ int btrfs_block_can_be_shared(struct btrfs_root *root,
826827
struct extent_buffer *buf)
827828
{
828829
/*
829-
* Tree blocks not in reference counted trees and tree roots
830-
* are never shared. If a block was allocated after the last
831-
* snapshot and the block was not allocated by tree relocation,
832-
* we know the block is not shared.
830+
* Tree blocks not in shareable trees and tree roots are never shared.
831+
* If a block was allocated after the last snapshot and the block was
832+
* not allocated by tree relocation, we know the block is not shared.
833833
*/
834-
if (test_bit(BTRFS_ROOT_REF_COWS, &root->state) &&
834+
if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state) &&
835835
buf != root->node && buf != root->commit_root &&
836836
(btrfs_header_generation(buf) <=
837837
btrfs_root_last_snapshot(&root->root_item) ||
@@ -1024,9 +1024,9 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
10241024

10251025
btrfs_assert_tree_locked(buf);
10261026

1027-
WARN_ON(test_bit(BTRFS_ROOT_REF_COWS, &root->state) &&
1027+
WARN_ON(test_bit(BTRFS_ROOT_SHAREABLE, &root->state) &&
10281028
trans->transid != fs_info->running_transaction->transid);
1029-
WARN_ON(test_bit(BTRFS_ROOT_REF_COWS, &root->state) &&
1029+
WARN_ON(test_bit(BTRFS_ROOT_SHAREABLE, &root->state) &&
10301030
trans->transid != root->last_trans);
10311031

10321032
level = btrfs_header_level(buf);
@@ -1065,7 +1065,7 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
10651065
return ret;
10661066
}
10671067

1068-
if (test_bit(BTRFS_ROOT_REF_COWS, &root->state)) {
1068+
if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) {
10691069
ret = btrfs_reloc_cow_block(trans, root, buf, cow);
10701070
if (ret) {
10711071
btrfs_abort_transaction(trans, ret);

fs/btrfs/ctree.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,28 @@ enum {
969969
* is used to tell us when more checks are required
970970
*/
971971
BTRFS_ROOT_IN_TRANS_SETUP,
972-
BTRFS_ROOT_REF_COWS,
972+
973+
/*
974+
* Set if tree blocks of this root can be shared by other roots.
975+
* Only subvolume trees and their reloc trees have this bit set.
976+
* Conflicts with TRACK_DIRTY bit.
977+
*
978+
* This affects two things:
979+
*
980+
* - How balance works
981+
* For shareable roots, we need to use reloc tree and do path
982+
* replacement for balance, and need various pre/post hooks for
983+
* snapshot creation to handle them.
984+
*
985+
* While for non-shareable trees, we just simply do a tree search
986+
* with COW.
987+
*
988+
* - How dirty roots are tracked
989+
* For shareable roots, btrfs_record_root_in_trans() is needed to
990+
* track them, while non-subvolume roots have TRACK_DIRTY bit, they
991+
* don't need to set this manually.
992+
*/
993+
BTRFS_ROOT_SHAREABLE,
973994
BTRFS_ROOT_TRACK_DIRTY,
974995
BTRFS_ROOT_IN_RADIX,
975996
BTRFS_ROOT_ORPHAN_ITEM_INSERTED,
@@ -1055,7 +1076,7 @@ struct btrfs_root {
10551076
struct btrfs_key defrag_progress;
10561077
struct btrfs_key defrag_max;
10571078

1058-
/* the dirty list is only used by non-reference counted roots */
1079+
/* The dirty list is only used by non-shareable roots */
10591080
struct list_head dirty_list;
10601081

10611082
struct list_head root_list;

fs/btrfs/disk-io.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,12 +1273,13 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
12731273
root->root_key.offset = BTRFS_TREE_LOG_OBJECTID;
12741274

12751275
/*
1276-
* DON'T set REF_COWS for log trees
1276+
* DON'T set SHAREABLE bit for log trees.
12771277
*
1278-
* log trees do not get reference counted because they go away
1279-
* before a real commit is actually done. They do store pointers
1280-
* to file data extents, and those reference counts still get
1281-
* updated (along with back refs to the log tree).
1278+
* Log trees are not exposed to user space thus can't be snapshotted,
1279+
* and they go away before a real commit is actually done.
1280+
*
1281+
* They do store pointers to file data extents, and those reference
1282+
* counts still get updated (along with back refs to the log tree).
12821283
*/
12831284

12841285
leaf = btrfs_alloc_tree_block(trans, root, 0, BTRFS_TREE_LOG_OBJECTID,
@@ -1417,7 +1418,7 @@ static int btrfs_init_fs_root(struct btrfs_root *root)
14171418
goto fail;
14181419

14191420
if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) {
1420-
set_bit(BTRFS_ROOT_REF_COWS, &root->state);
1421+
set_bit(BTRFS_ROOT_SHAREABLE, &root->state);
14211422
btrfs_check_and_init_root_item(&root->root_item);
14221423
}
14231424

fs/btrfs/extent-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2426,7 +2426,7 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,
24262426
nritems = btrfs_header_nritems(buf);
24272427
level = btrfs_header_level(buf);
24282428

2429-
if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state) && level == 0)
2429+
if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state) && level == 0)
24302430
return 0;
24312431

24322432
if (full_backref)

fs/btrfs/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ int __btrfs_drop_extents(struct btrfs_trans_handle *trans,
775775
if (start >= BTRFS_I(inode)->disk_i_size && !replace_extent)
776776
modify_tree = 0;
777777

778-
update_refs = (test_bit(BTRFS_ROOT_REF_COWS, &root->state) ||
778+
update_refs = (test_bit(BTRFS_ROOT_SHAREABLE, &root->state) ||
779779
root == fs_info->tree_root);
780780
while (1) {
781781
recow = 0;

fs/btrfs/inode.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4100,11 +4100,12 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
41004100
BUG_ON(new_size > 0 && min_type != BTRFS_EXTENT_DATA_KEY);
41014101

41024102
/*
4103-
* for non-free space inodes and ref cows, we want to back off from
4104-
* time to time
4103+
* For non-free space inodes and non-shareable roots, we want to back
4104+
* off from time to time. This means all inodes in subvolume roots,
4105+
* reloc roots, and data reloc roots.
41054106
*/
41064107
if (!btrfs_is_free_space_inode(BTRFS_I(inode)) &&
4107-
test_bit(BTRFS_ROOT_REF_COWS, &root->state))
4108+
test_bit(BTRFS_ROOT_SHAREABLE, &root->state))
41084109
be_nice = true;
41094110

41104111
path = btrfs_alloc_path();
@@ -4121,7 +4122,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
41214122
* not block aligned since we will be keeping the last block of the
41224123
* extent just the way it is.
41234124
*/
4124-
if (test_bit(BTRFS_ROOT_REF_COWS, &root->state) ||
4125+
if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state) ||
41254126
root == fs_info->tree_root)
41264127
btrfs_drop_extent_cache(BTRFS_I(inode), ALIGN(new_size,
41274128
fs_info->sectorsize),
@@ -4233,7 +4234,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
42334234
extent_num_bytes);
42344235
num_dec = (orig_num_bytes -
42354236
extent_num_bytes);
4236-
if (test_bit(BTRFS_ROOT_REF_COWS,
4237+
if (test_bit(BTRFS_ROOT_SHAREABLE,
42374238
&root->state) &&
42384239
extent_start != 0)
42394240
inode_sub_bytes(inode, num_dec);
@@ -4249,7 +4250,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
42494250
num_dec = btrfs_file_extent_num_bytes(leaf, fi);
42504251
if (extent_start != 0) {
42514252
found_extent = 1;
4252-
if (test_bit(BTRFS_ROOT_REF_COWS,
4253+
if (test_bit(BTRFS_ROOT_SHAREABLE,
42534254
&root->state))
42544255
inode_sub_bytes(inode, num_dec);
42554256
}
@@ -4285,7 +4286,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
42854286
clear_len = fs_info->sectorsize;
42864287
}
42874288

4288-
if (test_bit(BTRFS_ROOT_REF_COWS, &root->state))
4289+
if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state))
42894290
inode_sub_bytes(inode, item_end + 1 - new_size);
42904291
}
42914292
delete:
@@ -4326,7 +4327,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
43264327
should_throttle = false;
43274328

43284329
if (found_extent &&
4329-
(test_bit(BTRFS_ROOT_REF_COWS, &root->state) ||
4330+
(test_bit(BTRFS_ROOT_SHAREABLE, &root->state) ||
43304331
root == fs_info->tree_root)) {
43314332
struct btrfs_ref ref = { 0 };
43324333

fs/btrfs/ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
750750
int ret;
751751
bool snapshot_force_cow = false;
752752

753-
if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state))
753+
if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state))
754754
return -EINVAL;
755755

756756
if (atomic_read(&root->nr_swapfiles)) {

0 commit comments

Comments
 (0)