aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent-tree.c
diff options
context:
space:
mode:
authorYan Zheng <zheng.yan@oracle.com>2008-12-19 10:58:46 -0500
committerChris Mason <chris.mason@oracle.com>2008-12-19 10:58:46 -0500
commit34bf63c4ddddd92bfba3387d134c37bf4426b2ce (patch)
treea7a2f1fc2d88cb5a5b0a1ca54aa9647ec6e51fa4 /fs/btrfs/extent-tree.c
parentab67b7c1f780a8a321fe7ee49117775009350fb3 (diff)
Btrfs: properly update block accounting for metadata
This adds the missing block accounting code to finish_current_insert and makes block accounting for root item properly protected by the delalloc spin lock. Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 9ef2a2be2686..274bb91efa22 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -1051,11 +1051,11 @@ search:
1051 super_used = btrfs_super_bytes_used(&info->super_copy); 1051 super_used = btrfs_super_bytes_used(&info->super_copy);
1052 btrfs_set_super_bytes_used(&info->super_copy, 1052 btrfs_set_super_bytes_used(&info->super_copy,
1053 super_used - bytes_freed); 1053 super_used - bytes_freed);
1054 spin_unlock(&info->delalloc_lock);
1055 1054
1056 root_used = btrfs_root_used(&extent_root->root_item); 1055 root_used = btrfs_root_used(&extent_root->root_item);
1057 btrfs_set_root_used(&extent_root->root_item, 1056 btrfs_set_root_used(&extent_root->root_item,
1058 root_used - bytes_freed); 1057 root_used - bytes_freed);
1058 spin_unlock(&info->delalloc_lock);
1059 1059
1060 /* delete the items */ 1060 /* delete the items */
1061 ret = btrfs_del_items(trans, extent_root, path, 1061 ret = btrfs_del_items(trans, extent_root, path,
@@ -2242,6 +2242,7 @@ again:
2242 extent_op->bytenr + extent_op->num_bytes - 1, 2242 extent_op->bytenr + extent_op->num_bytes - 1,
2243 EXTENT_WRITEBACK, GFP_NOFS); 2243 EXTENT_WRITEBACK, GFP_NOFS);
2244 if (extent_op->del) { 2244 if (extent_op->del) {
2245 u64 used;
2245 list_del_init(&extent_op->list); 2246 list_del_init(&extent_op->list);
2246 unlock_extent(&info->extent_ins, extent_op->bytenr, 2247 unlock_extent(&info->extent_ins, extent_op->bytenr,
2247 extent_op->bytenr + extent_op->num_bytes 2248 extent_op->bytenr + extent_op->num_bytes
@@ -2253,6 +2254,15 @@ again:
2253 extent_op->num_bytes, 0); 2254 extent_op->num_bytes, 0);
2254 mutex_unlock(&extent_root->fs_info->pinned_mutex); 2255 mutex_unlock(&extent_root->fs_info->pinned_mutex);
2255 2256
2257 spin_lock(&info->delalloc_lock);
2258 used = btrfs_super_bytes_used(&info->super_copy);
2259 btrfs_set_super_bytes_used(&info->super_copy,
2260 used - extent_op->num_bytes);
2261 used = btrfs_root_used(&extent_root->root_item);
2262 btrfs_set_root_used(&extent_root->root_item,
2263 used - extent_op->num_bytes);
2264 spin_unlock(&info->delalloc_lock);
2265
2256 ret = update_block_group(trans, extent_root, 2266 ret = update_block_group(trans, extent_root,
2257 extent_op->bytenr, 2267 extent_op->bytenr,
2258 extent_op->num_bytes, 2268 extent_op->num_bytes,
@@ -2467,12 +2477,12 @@ static int __free_extent(struct btrfs_trans_handle *trans,
2467 super_used = btrfs_super_bytes_used(&info->super_copy); 2477 super_used = btrfs_super_bytes_used(&info->super_copy);
2468 btrfs_set_super_bytes_used(&info->super_copy, 2478 btrfs_set_super_bytes_used(&info->super_copy,
2469 super_used - num_bytes); 2479 super_used - num_bytes);
2470 spin_unlock(&info->delalloc_lock);
2471 2480
2472 /* block accounting for root item */ 2481 /* block accounting for root item */
2473 root_used = btrfs_root_used(&root->root_item); 2482 root_used = btrfs_root_used(&root->root_item);
2474 btrfs_set_root_used(&root->root_item, 2483 btrfs_set_root_used(&root->root_item,
2475 root_used - num_bytes); 2484 root_used - num_bytes);
2485 spin_unlock(&info->delalloc_lock);
2476 ret = btrfs_del_items(trans, extent_root, path, path->slots[0], 2486 ret = btrfs_del_items(trans, extent_root, path, path->slots[0],
2477 num_to_del); 2487 num_to_del);
2478 BUG_ON(ret); 2488 BUG_ON(ret);
@@ -3154,11 +3164,11 @@ static int __btrfs_alloc_reserved_extent(struct btrfs_trans_handle *trans,
3154 spin_lock(&info->delalloc_lock); 3164 spin_lock(&info->delalloc_lock);
3155 super_used = btrfs_super_bytes_used(&info->super_copy); 3165 super_used = btrfs_super_bytes_used(&info->super_copy);
3156 btrfs_set_super_bytes_used(&info->super_copy, super_used + num_bytes); 3166 btrfs_set_super_bytes_used(&info->super_copy, super_used + num_bytes);
3157 spin_unlock(&info->delalloc_lock);
3158 3167
3159 /* block accounting for root item */ 3168 /* block accounting for root item */
3160 root_used = btrfs_root_used(&root->root_item); 3169 root_used = btrfs_root_used(&root->root_item);
3161 btrfs_set_root_used(&root->root_item, root_used + num_bytes); 3170 btrfs_set_root_used(&root->root_item, root_used + num_bytes);
3171 spin_unlock(&info->delalloc_lock);
3162 3172
3163 if (root == extent_root) { 3173 if (root == extent_root) {
3164 struct pending_extent_op *extent_op; 3174 struct pending_extent_op *extent_op;