@@ -1250,10 +1250,16 @@ static int remove_extent_backref(struct btrfs_trans_handle *trans,
static int btrfs_issue_clear_op(struct block_device *bdev, u64 start, u64 size,
enum btrfs_clear_op_type clear)
{
+ unsigned int flags = BLKDEV_ZERO_KILLABLE;
+
switch (clear) {
case BTRFS_CLEAR_OP_DISCARD:
return blkdev_issue_discard(bdev, start >> SECTOR_SHIFT,
size >> SECTOR_SHIFT, GFP_NOFS);
+ case BTRFS_CLEAR_OP_ZERO:
+ return blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT,
+ size >> SECTOR_SHIFT, GFP_NOFS,
+ flags);
default:
return -EOPNOTSUPP;
}
@@ -1091,6 +1091,12 @@ enum btrfs_err_code {
*/
enum btrfs_clear_op_type {
BTRFS_CLEAR_OP_DISCARD,
+ /*
+ * Write zeros to the range, either overwrite or with hardware offload
+ * that can unmap the blocks internally.
+ * (Same as blkdev_issue_zeroout() with 0 flags).
+ */
+ BTRFS_CLEAR_OP_ZERO,
BTRFS_NR_CLEAR_OP_TYPES,
};
Add new type of clearing that will write zeros to the unused space (similar to what trim/discard would do). The mode is implemented by blkdev_issue_zeroout() that can write zeros to the blocks explicitly unless the hardware implements UNMAP command that unmaps the blocks that effectively appear as zeroed. This is handled transparently. As a special case of thin provisioning device, the UNMAP is usually handled and can free the underlying space. Signed-off-by: David Sterba <dsterba@suse.com> --- fs/btrfs/extent-tree.c | 6 ++++++ include/uapi/linux/btrfs.h | 6 ++++++ 2 files changed, 12 insertions(+)