@@ -390,6 +390,16 @@ int __btrfs_cow_block(struct btrfs_trans_handle *trans,
return 0;
}
+static inline bool should_cow_block_v2(struct btrfs_root *root,
+ struct extent_buffer *buf)
+{
+ if (btrfs_header_flag(buf, BTRFS_HEADER_FLAG_V2) &&
+ (btrfs_root_snapshot_id(&root->root_item) >
+ btrfs_header_snapshot_id(buf)))
+ return true;
+ return false;
+}
+
static inline int should_cow_block(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct extent_buffer *buf)
@@ -397,7 +407,8 @@ static inline int should_cow_block(struct btrfs_trans_handle *trans,
if (btrfs_header_generation(buf) == trans->transid &&
!btrfs_header_flag(buf, BTRFS_HEADER_FLAG_WRITTEN) &&
!(root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID &&
- btrfs_header_flag(buf, BTRFS_HEADER_FLAG_RELOC)))
+ btrfs_header_flag(buf, BTRFS_HEADER_FLAG_RELOC)) &&
+ !should_cow_block_v2(root, buf))
return 0;
return 1;
}
All of the previous COW rules will apply, but with extent tree v2 we add a new COW rule where we must COW if the snapshot id of the buffer is less than the current snapshot id of the root. If the root's snapshot id has been increased we know that the block is now shared by a new root and we must cow this block. Signed-off-by: Josef Bacik <josef@toxicpanda.com> --- kernel-shared/ctree.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)