Skip to content

Commit

Permalink
Btrfs: Don't allow written blocks from this transaction to be realloc…
Browse files Browse the repository at this point in the history
…ated

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.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
  • Loading branch information
Chris Mason committed Sep 25, 2008
1 parent 611f0e0 commit 6bc3467
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,9 @@ static int pin_down_bytes(struct btrfs_root *root, u64 bytenr, u32 num_bytes,
root->fs_info->running_transaction->transid;
u64 header_transid =
btrfs_header_generation(buf);
if (header_transid == transid) {
if (header_transid == transid &&
!btrfs_header_flag(buf,
BTRFS_HEADER_FLAG_WRITTEN)) {
clean_tree_block(NULL, root, buf);
free_extent_buffer(buf);
return 1;
Expand Down

0 comments on commit 6bc3467

Please sign in to comment.