Btrfs: Fix super block updates during transaction commit
The super block written during commit was not consistent with the state of
the trees. This change adds an in-memory copy of the super so that we can
make sure to write out consistent data during a commit.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 8025e9f..7e55034 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -796,8 +796,8 @@
for (i = 0; i < extent_root->fs_info->extent_tree_insert_nr; i++) {
ins.objectid = extent_root->fs_info->extent_tree_insert[i];
- super_blocks_used = btrfs_super_blocks_used(info->disk_super);
- btrfs_set_super_blocks_used(info->disk_super,
+ super_blocks_used = btrfs_super_blocks_used(&info->super_copy);
+ btrfs_set_super_blocks_used(&info->super_copy,
super_blocks_used + 1);
ret = btrfs_insert_item(trans, extent_root, &ins, &extent_item,
sizeof(extent_item));
@@ -892,8 +892,8 @@
BUG_ON(ret);
}
- super_blocks_used = btrfs_super_blocks_used(info->disk_super);
- btrfs_set_super_blocks_used(info->disk_super,
+ super_blocks_used = btrfs_super_blocks_used(&info->super_copy);
+ btrfs_set_super_blocks_used(&info->super_copy,
super_blocks_used - num_blocks);
ret = btrfs_del_item(trans, extent_root, path);
if (ret) {
@@ -1032,7 +1032,7 @@
info->extent_tree_prealloc_nr = 0;
}
if (search_end == (u64)-1)
- search_end = btrfs_super_total_blocks(info->disk_super);
+ search_end = btrfs_super_total_blocks(&info->super_copy);
if (hint_block) {
block_group = btrfs_lookup_block_group(info, hint_block);
block_group = btrfs_find_block_group(root, block_group,
@@ -1361,8 +1361,8 @@
}
}
- super_blocks_used = btrfs_super_blocks_used(info->disk_super);
- btrfs_set_super_blocks_used(info->disk_super, super_blocks_used +
+ super_blocks_used = btrfs_super_blocks_used(&info->super_copy);
+ btrfs_set_super_blocks_used(&info->super_copy, super_blocks_used +
num_blocks);
ret = btrfs_insert_item(trans, extent_root, ins, &extent_item,
sizeof(extent_item));
@@ -1737,7 +1737,7 @@
BTRFS_BLOCK_GROUP_AVAIL);
}
if (key.objectid >=
- btrfs_super_total_blocks(info->disk_super))
+ btrfs_super_total_blocks(&info->super_copy))
break;
}