Josef Bacik
2007-Aug-10 11:46 UTC
[Btrfs-devel] [PATCH 1/2] add root item block accounting to btrfs
Hello, This patch adds used block accounting to root items in btrfs. I basically just copied what we do for super blocks, I assume this is right, I don't really have a way to check it (at least I don't think I do). Ran various tests on the FS with these two patches and no issues. Thanks much, Josef diff -r f6da57af2473 ctree.h --- a/ctree.h Wed Aug 08 20:17:12 2007 -0400 +++ b/ctree.h Fri Aug 10 14:08:46 2007 -0400 @@ -811,6 +811,17 @@ static inline void btrfs_set_root_flags( static inline void btrfs_set_root_flags(struct btrfs_root_item *item, u32 val) { item->flags = cpu_to_le32(val); +} + +static inline void btrfs_set_root_blocks_used(struct btrfs_root_item *r, + u64 val) +{ + r->blocks_used = cpu_to_le64(val); +} + +static inline u64 btrfs_root_blocks_used(struct btrfs_root_item *r) +{ + return le64_to_cpu(r->blocks_used); } static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s) diff -r f6da57af2473 extent-tree.c --- a/extent-tree.c Wed Aug 08 20:17:12 2007 -0400 +++ b/extent-tree.c Fri Aug 10 14:40:08 2007 -0400 @@ -852,16 +852,23 @@ static int __free_extent(struct btrfs_tr btrfs_set_extent_refs(ei, refs); btrfs_mark_buffer_dirty(path->nodes[0]); if (refs == 0) { - u64 super_blocks_used; + u64 super_blocks_used, root_blocks_used; if (pin) { ret = pin_down_block(root, blocknr, 0); BUG_ON(ret); } + /* block accounting for super block */ super_blocks_used = btrfs_super_blocks_used(&info->super_copy); btrfs_set_super_blocks_used(&info->super_copy, super_blocks_used - num_blocks); + + /* block accounting for root item */ + root_blocks_used = btrfs_root_blocks_used(&root->root_item); + btrfs_set_root_blocks_used(&root->root_item, + root_blocks_used - num_blocks); + ret = btrfs_del_item(trans, extent_root, path); if (ret) { return ret; @@ -1175,7 +1182,7 @@ int btrfs_alloc_extent(struct btrfs_tran { int ret; int pending_ret; - u64 super_blocks_used; + u64 super_blocks_used, root_blocks_used; u64 search_start = 0; struct btrfs_fs_info *info = root->fs_info; struct btrfs_root *extent_root = info->extent_root; @@ -1193,9 +1200,15 @@ int btrfs_alloc_extent(struct btrfs_tran if (ret) return ret; + /* block accounting for super block */ super_blocks_used = btrfs_super_blocks_used(&info->super_copy); btrfs_set_super_blocks_used(&info->super_copy, super_blocks_used + num_blocks); + + /* block accounting for root item */ + root_blocks_used = btrfs_root_blocks_used(&root->root_item); + btrfs_set_root_blocks_used(&root->root_item, root_blocks_used + + num_blocks); if (root == extent_root) { BUG_ON(num_blocks != 1); diff -r f6da57af2473 inode.c --- a/inode.c Wed Aug 08 20:17:12 2007 -0400 +++ b/inode.c Fri Aug 10 14:26:37 2007 -0400 @@ -2021,6 +2021,7 @@ static int create_subvol(struct btrfs_ro btrfs_set_root_blocknr(&root_item, bh_blocknr(subvol)); btrfs_set_root_refs(&root_item, 1); + btrfs_set_root_blocks_used(&root_item, 0); memset(&root_item.drop_progress, 0, sizeof(root_item.drop_progress)); root_item.drop_level = 0; brelse(subvol);