diff options
author | Christoph Hellwig <hch@lst.de> | 2011-04-21 16:24:07 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2011-10-25 09:18:32 -0400 |
commit | 43a06f07c7b64bc4cabfbbf2397fb17b666b155f (patch) | |
tree | 3a0bf4c3f5b63bb7fbdc6b810d710e3da7946a0e /utils.c | |
parent | b4d668ee6bcf93f097507df6d76fd0fca7d3888a (diff) |
btrfs-progs: add discard support to mkfs
Discard the whole device before starting to create the filesystem structures.
Modelled after similar support in mkfs.xfs.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -50,6 +50,20 @@ static inline int ioctl(int fd, int define, u64 *size) { return 0; } #endif +#ifndef BLKDISCARD +#define BLKDISCARD _IO(0x12,119) +#endif + +static int +discard_blocks(int fd, u64 start, u64 len) +{ + u64 range[2] = { start, len }; + + if (ioctl(fd, BLKDISCARD, &range) < 0) + return errno; + return 0; +} + static u64 reference_root_table[] = { [1] = BTRFS_ROOT_TREE_OBJECTID, [2] = BTRFS_EXTENT_TREE_OBJECTID, @@ -537,6 +551,13 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret, printf("SMALL VOLUME: forcing mixed metadata/data groups\n"); *mixed = 1; } + + /* + * We intentionally ignore errors from the discard ioctl. It is + * not necessary for the mkfs functionality but just an optimization. + */ + discard_blocks(fd, 0, block_count); + ret = zero_dev_start(fd); if (ret) { fprintf(stderr, "failed to zero device start %d\n", ret); |