diff --git a/extent-tree.c b/extent-tree.c index 8c9cdeff..283a6917 100644 --- a/extent-tree.c +++ b/extent-tree.c @@ -2506,7 +2506,12 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans, profile = BTRFS_BLOCK_GROUP_METADATA | alloc_profile; } - if (root->ref_cows) { + /* + * Do metadata preallocation if we're not modifying the extent tree. + * Allocating chunk while modifying extent tree could lead to transid + * mismatch, as do_chunk_alloc() could commit transaction. + */ + if (root->root_key.objectid != BTRFS_EXTENT_TREE_OBJECTID) { if (!(profile & BTRFS_BLOCK_GROUP_METADATA)) { ret = do_chunk_alloc(trans, info, num_bytes,