From 97864fa126c1e7675595882943d0397c45ef4b67 Mon Sep 17 00:00:00 2001 From: Chris Mason Date: Fri, 4 Apr 2008 15:40:00 -0400 Subject: [PATCH] Don't allow written blocks from this transaction to be reallocated When a block is freed, it can be immediately reused if it is from the current transaction. But, an extra check is required to make sure the block had not been written yet. If it were reused after being written, the transid in the block header might match the transid of the next time the block was allocated. The parent node records the transaction ID of the block it is pointing to, and this is used as part of validating the block on reads. So, there can only be one version of a block per transaction. --- extent-tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extent-tree.c b/extent-tree.c index 8c39537..f3c36e1 100644 --- a/extent-tree.c +++ b/extent-tree.c @@ -1262,7 +1262,9 @@ static int pin_down_bytes(struct btrfs_root *root, u64 bytenr, u32 num_bytes, if (btrfs_buffer_uptodate(buf)) { u64 transid = root->fs_info->running_transaction->transid; - if (btrfs_header_generation(buf) == transid) { + if (btrfs_header_generation(buf) == + transid && !btrfs_header_flag(buf, + BTRFS_HEADER_FLAG_WRITTEN)) { free_extent_buffer(buf); return 1; } -- 2.7.4