aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent-tree.c
diff options
context:
space:
mode:
authorYan, Zheng <zheng.yan@oracle.com>2009-11-12 04:36:50 -0500
committerChris Mason <chris.mason@oracle.com>2009-12-17 12:33:35 -0500
commit86b9f2eca5e0984145e3c7698a7cd6dd65c2a93f (patch)
tree75dd0a52848b6f5396023f811f1a602f62b9d34e /fs/btrfs/extent-tree.c
parent55ef68990029fcd8d04d42fc184aa7fb18cf309e (diff)
Btrfs: Fix per root used space accounting
The bytes_used field in root item was originally planned to trace the amount of used data and tree blocks. But it never worked right since we can't trace freeing of data accurately. This patch changes it to only trace the amount of tree blocks. Signed-off-by: Yan Zheng <zheng.yan@oracle.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index fcdccfa46004..44d7a322ec28 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3454,14 +3454,6 @@ static int update_block_group(struct btrfs_trans_handle *trans,
3454 else 3454 else
3455 old_val -= num_bytes; 3455 old_val -= num_bytes;
3456 btrfs_set_super_bytes_used(&info->super_copy, old_val); 3456 btrfs_set_super_bytes_used(&info->super_copy, old_val);
3457
3458 /* block accounting for root item */
3459 old_val = btrfs_root_used(&root->root_item);
3460 if (alloc)
3461 old_val += num_bytes;
3462 else
3463 old_val -= num_bytes;
3464 btrfs_set_root_used(&root->root_item, old_val);
3465 spin_unlock(&info->delalloc_lock); 3457 spin_unlock(&info->delalloc_lock);
3466 3458
3467 while (total) { 3459 while (total) {
@@ -4049,6 +4041,21 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans,
4049 return ret; 4041 return ret;
4050} 4042}
4051 4043
4044int btrfs_free_tree_block(struct btrfs_trans_handle *trans,
4045 struct btrfs_root *root,
4046 u64 bytenr, u32 blocksize,
4047 u64 parent, u64 root_objectid, int level)
4048{
4049 u64 used;
4050 spin_lock(&root->node_lock);
4051 used = btrfs_root_used(&root->root_item) - blocksize;
4052 btrfs_set_root_used(&root->root_item, used);
4053 spin_unlock(&root->node_lock);
4054
4055 return btrfs_free_extent(trans, root, bytenr, blocksize,
4056 parent, root_objectid, level, 0);
4057}
4058
4052static u64 stripe_align(struct btrfs_root *root, u64 val) 4059static u64 stripe_align(struct btrfs_root *root, u64 val)
4053{ 4060{
4054 u64 mask = ((u64)root->stripesize - 1); 4061 u64 mask = ((u64)root->stripesize - 1);
@@ -4897,6 +4904,14 @@ static int alloc_tree_block(struct btrfs_trans_handle *trans,
4897 extent_op); 4904 extent_op);
4898 BUG_ON(ret); 4905 BUG_ON(ret);
4899 } 4906 }
4907
4908 if (root_objectid == root->root_key.objectid) {
4909 u64 used;
4910 spin_lock(&root->node_lock);
4911 used = btrfs_root_used(&root->root_item) + num_bytes;
4912 btrfs_set_root_used(&root->root_item, used);
4913 spin_unlock(&root->node_lock);
4914 }
4900 return ret; 4915 return ret;
4901} 4916}
4902 4917