summaryrefslogtreecommitdiff
path: root/ctree.c
diff options
context:
space:
mode:
authorNikolay Borisov <nborisov@suse.com>2018-06-08 15:47:47 +0300
committerDavid Sterba <dsterba@suse.com>2018-08-06 15:01:51 +0200
commit3a0cf26beed04189a51d7e7f5a94bf3c7736fafc (patch)
tree757cdd3e94eff72ff81d279b24d4f635df4b1b3f /ctree.c
parent4d918a7299459174dec85f2056eb11c087dd7dbf (diff)
btrfs-progs: Refactor the root used bytes are updated
Instead of updating this during update_block_group, move the updating code at the places where we free/allocate a block. This resembles the current state of the kernel code. This is in prep for delayed refs. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'ctree.c')
-rw-r--r--ctree.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/ctree.c b/ctree.c
index 7b74716b..8f3338b4 100644
--- a/ctree.c
+++ b/ctree.c
@@ -734,6 +734,8 @@ static int balance_level(struct btrfs_trans_handle *trans,
/* once for the path */
free_extent_buffer(mid);
+ root_sub_used(root, mid->len);
+
ret = btrfs_free_extent(trans, root, mid->start, mid->len,
0, root->root_key.objectid,
level, 1);
@@ -789,6 +791,8 @@ static int balance_level(struct btrfs_trans_handle *trans,
wret = btrfs_del_ptr(root, path, level + 1, pslot + 1);
if (wret)
ret = wret;
+
+ root_sub_used(root, right->len);
wret = btrfs_free_extent(trans, root, bytenr,
blocksize, 0,
root->root_key.objectid,
@@ -835,6 +839,8 @@ static int balance_level(struct btrfs_trans_handle *trans,
wret = btrfs_del_ptr(root, path, level + 1, pslot);
if (wret)
ret = wret;
+
+ root_sub_used(root, blocksize);
wret = btrfs_free_extent(trans, root, bytenr, blocksize,
0, root->root_key.objectid,
level, 0);
@@ -1466,6 +1472,8 @@ static int noinline insert_new_root(struct btrfs_trans_handle *trans,
btrfs_set_header_backref_rev(c, BTRFS_MIXED_BACKREF_REV);
btrfs_set_header_owner(c, root->root_key.objectid);
+ root_add_used(root, root->fs_info->nodesize);
+
write_extent_buffer(c, root->fs_info->fsid,
btrfs_header_fsid(), BTRFS_FSID_SIZE);
@@ -1593,6 +1601,7 @@ static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root
btrfs_header_chunk_tree_uuid(split),
BTRFS_UUID_SIZE);
+ root_add_used(root, root->fs_info->nodesize);
copy_extent_buffer(split, c,
btrfs_node_key_ptr_offset(0),
@@ -2175,6 +2184,8 @@ again:
btrfs_header_chunk_tree_uuid(right),
BTRFS_UUID_SIZE);
+ root_add_used(root, root->fs_info->nodesize);
+
if (split == 0) {
if (mid <= slot) {
btrfs_set_header_nritems(right, 0);
@@ -2694,6 +2705,8 @@ static noinline int btrfs_del_leaf(struct btrfs_trans_handle *trans,
if (ret)
return ret;
+ root_sub_used(root, leaf->len);
+
ret = btrfs_free_extent(trans, root, leaf->start, leaf->len,
0, root->root_key.objectid, 0, 0);
return ret;