Skip to content

Commit 2992e1d

Browse files
committed
btrfs: add zeroout mode to CLEAR_FREE ioctl
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 <[email protected]>
1 parent 982cb5c commit 2992e1d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

fs/btrfs/extent-tree.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,10 +1250,16 @@ static int remove_extent_backref(struct btrfs_trans_handle *trans,
12501250
static int btrfs_issue_clear_op(struct block_device *bdev, u64 start, u64 size,
12511251
enum btrfs_clear_op_type clear)
12521252
{
1253+
unsigned int flags = BLKDEV_ZERO_KILLABLE;
1254+
12531255
switch (clear) {
12541256
case BTRFS_CLEAR_OP_DISCARD:
12551257
return blkdev_issue_discard(bdev, start >> SECTOR_SHIFT,
12561258
size >> SECTOR_SHIFT, GFP_NOFS);
1259+
case BTRFS_CLEAR_OP_ZERO:
1260+
return blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT,
1261+
size >> SECTOR_SHIFT, GFP_NOFS,
1262+
flags);
12571263
default:
12581264
return -EOPNOTSUPP;
12591265
}

include/uapi/linux/btrfs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,12 @@ enum btrfs_err_code {
11011101
*/
11021102
enum btrfs_clear_op_type {
11031103
BTRFS_CLEAR_OP_DISCARD,
1104+
/*
1105+
* Write zeros to the range, either overwrite or with hardware offload
1106+
* that can unmap the blocks internally.
1107+
* (Same as blkdev_issue_zeroout() with 0 flags).
1108+
*/
1109+
BTRFS_CLEAR_OP_ZERO,
11041110
BTRFS_NR_CLEAR_OP_TYPES,
11051111
};
11061112

0 commit comments

Comments
 (0)