aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent-tree.c
diff options
context:
space:
mode:
authorDavid Woodhouse <David.Woodhouse@intel.com>2008-08-12 09:13:26 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:04:06 -0400
commit21af804c07141c035085f99798efaabbc7836a97 (patch)
treeb744fd22d7484be4322b0230bf110861f040fd51 /fs/btrfs/extent-tree.c
parentcbdf5a2442330102c08f5a2ad3058e29e90a43a9 (diff)
Btrfs: Discard sector data in __free_extent()
Date: Tue, 12 Aug 2008 14:13:26 +0100 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index fff219ed61d9..e63b3b4bed7c 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -18,6 +18,7 @@
18#include <linux/sched.h> 18#include <linux/sched.h>
19#include <linux/pagemap.h> 19#include <linux/pagemap.h>
20#include <linux/writeback.h> 20#include <linux/writeback.h>
21#include <linux/blkdev.h>
21#include "hash.h" 22#include "hash.h"
22#include "crc32c.h" 23#include "crc32c.h"
23#include "ctree.h" 24#include "ctree.h"
@@ -1716,6 +1717,10 @@ static int __free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1716 if (refs == 0) { 1717 if (refs == 0) {
1717 u64 super_used; 1718 u64 super_used;
1718 u64 root_used; 1719 u64 root_used;
1720#ifdef BIO_RW_DISCARD
1721 u64 map_length = num_bytes;
1722 struct btrfs_multi_bio *multi = NULL;
1723#endif
1719 1724
1720 if (pin) { 1725 if (pin) {
1721 ret = pin_down_bytes(root, bytenr, num_bytes, 0); 1726 ret = pin_down_bytes(root, bytenr, num_bytes, 0);
@@ -1743,6 +1748,26 @@ static int __free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1743 ret = update_block_group(trans, root, bytenr, num_bytes, 0, 1748 ret = update_block_group(trans, root, bytenr, num_bytes, 0,
1744 mark_free); 1749 mark_free);
1745 BUG_ON(ret); 1750 BUG_ON(ret);
1751
1752#ifdef BIO_RW_DISCARD
1753 /* Tell the block device(s) that the sectors can be discarded */
1754 ret = btrfs_map_block(&root->fs_info->mapping_tree, READ,
1755 bytenr, &map_length, &multi, 0);
1756 if (!ret) {
1757 struct btrfs_bio_stripe *stripe = multi->stripes;
1758 int i;
1759
1760 if (map_length > num_bytes)
1761 map_length = num_bytes;
1762
1763 for (i = 0; i < multi->num_stripes; i++, stripe++) {
1764 blkdev_issue_discard(stripe->dev->bdev,
1765 stripe->physical >> 9,
1766 map_length >> 9);
1767 }
1768 kfree(multi);
1769 }
1770#endif
1746 } 1771 }
1747 btrfs_free_path(path); 1772 btrfs_free_path(path);
1748 finish_current_insert(trans, extent_root); 1773 finish_current_insert(trans, extent_root);