Skip to content

Commit 0519183

Browse files
committed
btrfs: add more zeroout modes to CLEAR_FREE ioctl
The zeroing mode BTRFS_CLEAR_OP_ZERO is safe for use regardless of the underlying device capabilities, either zeros are written or the device will unmap the blocks. This a safe behaviour. In case it's desired to do one or the another add modes that can enforce that or fail when unsupported; - CLEAR_OP_ZERO - overwrite by zero blocks, forbid unmapping blocks by the device - CLEAR_OP_ZERO_NOFALLBACK - unmap the blocks by device and do not fall back to overwriting by zeros Implemented by __blkdev_issue_zeroout() and also documented there. Signed-off-by: David Sterba <[email protected]>
1 parent f2750f1 commit 0519183

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

fs/btrfs/extent-tree.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,10 +1259,17 @@ static int btrfs_issue_clear_op(struct block_device *bdev, u64 start, u64 size,
12591259
case BTRFS_CLEAR_OP_DISCARD:
12601260
return blkdev_issue_discard(bdev, start >> SECTOR_SHIFT,
12611261
size >> SECTOR_SHIFT, GFP_NOFS);
1262+
case BTRFS_CLEAR_OP_ZERO_NOUNMAP:
1263+
flags |= BLKDEV_ZERO_NOUNMAP;
1264+
return blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT,
1265+
size >> SECTOR_SHIFT, GFP_NOFS, flags);
1266+
case BTRFS_CLEAR_OP_ZERO_NOFALLBACK:
1267+
flags |= BLKDEV_ZERO_NOFALLBACK;
1268+
return blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT,
1269+
size >> SECTOR_SHIFT, GFP_NOFS, flags);
12621270
case BTRFS_CLEAR_OP_ZERO:
12631271
return blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT,
1264-
size >> SECTOR_SHIFT, GFP_NOFS,
1265-
flags);
1272+
size >> SECTOR_SHIFT, GFP_NOFS, flags);
12661273
default:
12671274
return -EOPNOTSUPP;
12681275
}

include/uapi/linux/btrfs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,11 @@ enum btrfs_clear_op_type {
11141114
* garbage collection must also be erased.
11151115
*/
11161116
BTRFS_CLEAR_OP_SECURE_ERASE,
1117+
1118+
/* Overwrite by zeros, do not try to unmap blocks. */
1119+
BTRFS_CLEAR_OP_ZERO_NOUNMAP,
1120+
/* Request unmapping the blocks and don't fall back to writing zeros. */
1121+
BTRFS_CLEAR_OP_ZERO_NOFALLBACK,
11171122
BTRFS_NR_CLEAR_OP_TYPES,
11181123
};
11191124

0 commit comments

Comments
 (0)