aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);