Skip to content

Commit f2750f1

Browse files
committed
btrfs: add secure erase mode to CLEAR_FREE ioctl
Add another type of clearing that will do secure erase on the unused space. This requires hardware support and works as a regular discard while also deleting any copied or cached blocks. Same as "blkdiscard --secure". The unused space ranges may not be aligned to the secure erase block or be of a sufficient length, the exact result depends on the device. Some blocks may still contain valid data even after this ioctl. Signed-off-by: David Sterba <[email protected]>
1 parent 2992e1d commit f2750f1

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

fs/btrfs/extent-tree.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,9 @@ static int btrfs_issue_clear_op(struct block_device *bdev, u64 start, u64 size,
12531253
unsigned int flags = BLKDEV_ZERO_KILLABLE;
12541254

12551255
switch (clear) {
1256+
case BTRFS_CLEAR_OP_SECURE_ERASE:
1257+
return blkdev_issue_secure_erase(bdev, start >> SECTOR_SHIFT,
1258+
size >> SECTOR_SHIFT, GFP_NOFS);
12561259
case BTRFS_CLEAR_OP_DISCARD:
12571260
return blkdev_issue_discard(bdev, start >> SECTOR_SHIFT,
12581261
size >> SECTOR_SHIFT, GFP_NOFS);

include/uapi/linux/btrfs.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,13 @@ enum btrfs_clear_op_type {
11071107
* (Same as blkdev_issue_zeroout() with 0 flags).
11081108
*/
11091109
BTRFS_CLEAR_OP_ZERO,
1110+
/*
1111+
* Do a secure erase operation on the range. If supported by the
1112+
* underlying hardware, this works as regular discard except that all
1113+
* copies of the discarded blocks that were possibly created by
1114+
* garbage collection must also be erased.
1115+
*/
1116+
BTRFS_CLEAR_OP_SECURE_ERASE,
11101117
BTRFS_NR_CLEAR_OP_TYPES,
11111118
};
11121119

0 commit comments

Comments
 (0)