Btrfs: Fix free block discard calls down to the block layer
authorLiu Hui <onlyflyer@gmail.com>
Mon, 5 Jan 2009 20:57:51 +0000 (15:57 -0500)
committerChris Mason <chris.mason@oracle.com>
Mon, 5 Jan 2009 20:57:51 +0000 (15:57 -0500)
commit1f3c79a28c8837e8572b98f6d14142d9a6133c56
tree09c7a7c46186806ec1ecd34f03780ef15e397245
parentec051c0f929afe5c42c24bb07abf577c616c208c
Btrfs: Fix free block discard calls down to the block layer

This is a patch to fix discard semantic to make Btrfs work with FTL and SSD.
We can improve FTL's performance by telling it which sectors are freed by file
system. But if we don't tell FTL the information of free sectors in proper
time, the transaction mechanism of Btrfs will be destroyed and Btrfs could not
roll back the previous transaction under the power loss condition.

There are some problems in the old implementation:
1, In __free_extent(), the pinned down extents should not be discarded.
2, In free_extents(), the free extents are all pinned, so they need to
be discarded in transaction committing time instead of free_extents().
3, The reserved extent used by log tree should be discard too.

This patch change discard behavior as follows:
1, For the extents which need to be free at once,
   we discard them in update_block_group().
2, Delay discarding the pinned extent in btrfs_finish_extent_commit()
   when committing transaction.
3, Remove discarding from free_extents() and __free_extent()
4, Add discard interface into btrfs_free_reserved_extent()
5, Discard sectors before updating the free space cache, otherwise,
   FTL will destroy file system data.
fs/btrfs/extent-tree.c