@@ -2559,6 +2559,7 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
u64 hint, u64 empty_size,
enum btrfs_lock_nesting nest)
{
+ struct btrfs_fs_info *fs_info = trans->fs_info;
struct btrfs_key ins;
int ret;
struct extent_buffer *buf;
@@ -2579,6 +2580,14 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
return ERR_PTR(-ENOMEM);
}
btrfs_set_buffer_uptodate(buf);
+ memset_extent_buffer(buf, 0, 0, sizeof(struct btrfs_header));
+ btrfs_set_header_level(buf, level);
+ btrfs_set_header_bytenr(buf, buf->start);
+ btrfs_set_header_generation(buf, trans->transid);
+ btrfs_set_header_backref_rev(buf, BTRFS_MIXED_BACKREF_REV);
+ btrfs_set_header_owner(buf, root_objectid);
+ write_extent_buffer_fsid(buf, fs_info->fs_devices->metadata_uuid);
+ write_extent_buffer_chunk_tree_uuid(buf, fs_info->chunk_tree_uuid);
trans->blocks_used++;
return buf;
This is how the kernel initializes blocks, so anybody who uses btrfs_alloc_tree_block in the kernel expects the blocks to be already initialized. Put this init code into btrfs-progs so as we sync code from the kernel we get the correct behavior. Signed-off-by: Josef Bacik <josef@toxicpanda.com> --- kernel-shared/extent-tree.c | 9 +++++++++ 1 file changed, 9 insertions(+)