fprintf(stderr, "\t -n --nodesize size of btree nodes\n");
fprintf(stderr, "\t -s --sectorsize min block allocation\n");
fprintf(stderr, "\t -r --rootdir the source directory\n");
+ fprintf(stderr, "\t -T --nodiscard do not perform whole device TRIM\n");
fprintf(stderr, "%s\n", BTRFS_BUILD_VERSION);
exit(1);
}
{ "data", 1, NULL, 'd' },
{ "version", 0, NULL, 'V' },
{ "rootdir", 1, NULL, 'r' },
+ { "nodiscard", 0, NULL, 'T' },
{ 0, 0, 0, 0}
};
int mixed = 0;
int data_profile_opt = 0;
int metadata_profile_opt = 0;
+ int nodiscard = 0;
char *source_dir = NULL;
int source_dir_set = 0;
while(1) {
int c;
- c = getopt_long(ac, av, "A:b:l:n:s:m:d:L:r:VM", long_options,
+ c = getopt_long(ac, av, "A:b:l:n:s:m:d:L:r:VMT", long_options,
&option_index);
if (c < 0)
break;
source_dir = optarg;
source_dir_set = 1;
break;
+ case 'T':
+ nodiscard=1;
+ break;
default:
print_usage();
}
exit(1);
}
first_file = file;
- ret = btrfs_prepare_device(fd, file, zero_end, &dev_block_count, &mixed);
+ ret = __btrfs_prepare_device(fd, file, zero_end,
+ &dev_block_count, &mixed, nodiscard);
if (block_count == 0)
block_count = dev_block_count;
else if (block_count > dev_block_count) {
continue;
}
dev_block_count = block_count;
- ret = btrfs_prepare_device(fd, file, zero_end,
- &dev_block_count, &mixed);
+ ret = __btrfs_prepare_device(fd, file, zero_end,
+ &dev_block_count, &mixed, nodiscard);
mixed = old_mixed;
BUG_ON(ret);
int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
int *mixed)
+{
+ /* discard by default when called from 'device add' */
+ return __btrfs_prepare_device(fd, file, zero_end, block_count_ret, mixed, 0);
+}
+int __btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
+ int *mixed, int nodiscard)
{
u64 block_count;
u64 bytenr;
*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);
+ if (!nodiscard) {
+ /*
+ * 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) {
struct btrfs_root *root, u64 objectid);
int btrfs_prepare_device(int fd, char *file, int zero_end,
u64 *block_count_ret, int *mixed);
+int __btrfs_prepare_device(int fd, char *file, int zero_end,
+ u64 *block_count_ret, int *mixed, int nodiscard);
int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
struct btrfs_root *root, int fd, char *path,
u64 block_count, u32 io_width, u32 io_align,