forked from Mirrors/btrfs-progs
btrfs-progs: mkfs: add option to skip trim
Signed-off-by: Chris Mason <chris.mason@fusionio.com>master
parent
134adafea2
commit
8935d84361
|
@ -63,6 +63,9 @@ Specify the sectorsize, the minimum block allocation.
|
||||||
\fB\-r\fR, \fB\-\-rootdir \fIrootdir\fR
|
\fB\-r\fR, \fB\-\-rootdir \fIrootdir\fR
|
||||||
Specify a directory to copy into the newly created fs.
|
Specify a directory to copy into the newly created fs.
|
||||||
.TP
|
.TP
|
||||||
|
\fB\-T\fR, \fB\-\-nodiscard \fR
|
||||||
|
Do not perform whole device TRIM operation by default.
|
||||||
|
.TP
|
||||||
\fB\-V\fR, \fB\-\-version\fR
|
\fB\-V\fR, \fB\-\-version\fR
|
||||||
Print the \fBmkfs.btrfs\fP version and exit.
|
Print the \fBmkfs.btrfs\fP version and exit.
|
||||||
.SH AVAILABILITY
|
.SH AVAILABILITY
|
||||||
|
|
15
mkfs.c
15
mkfs.c
|
@ -348,6 +348,7 @@ static void print_usage(void)
|
||||||
fprintf(stderr, "\t -n --nodesize size of btree nodes\n");
|
fprintf(stderr, "\t -n --nodesize size of btree nodes\n");
|
||||||
fprintf(stderr, "\t -s --sectorsize min block allocation\n");
|
fprintf(stderr, "\t -s --sectorsize min block allocation\n");
|
||||||
fprintf(stderr, "\t -r --rootdir the source directory\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);
|
fprintf(stderr, "%s\n", BTRFS_BUILD_VERSION);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -409,6 +410,7 @@ static struct option long_options[] = {
|
||||||
{ "data", 1, NULL, 'd' },
|
{ "data", 1, NULL, 'd' },
|
||||||
{ "version", 0, NULL, 'V' },
|
{ "version", 0, NULL, 'V' },
|
||||||
{ "rootdir", 1, NULL, 'r' },
|
{ "rootdir", 1, NULL, 'r' },
|
||||||
|
{ "nodiscard", 0, NULL, 'T' },
|
||||||
{ 0, 0, 0, 0}
|
{ 0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1224,6 +1226,7 @@ int main(int ac, char **av)
|
||||||
int mixed = 0;
|
int mixed = 0;
|
||||||
int data_profile_opt = 0;
|
int data_profile_opt = 0;
|
||||||
int metadata_profile_opt = 0;
|
int metadata_profile_opt = 0;
|
||||||
|
int nodiscard = 0;
|
||||||
|
|
||||||
char *source_dir = NULL;
|
char *source_dir = NULL;
|
||||||
int source_dir_set = 0;
|
int source_dir_set = 0;
|
||||||
|
@ -1234,7 +1237,7 @@ int main(int ac, char **av)
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
int c;
|
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);
|
&option_index);
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
break;
|
break;
|
||||||
|
@ -1280,6 +1283,9 @@ int main(int ac, char **av)
|
||||||
source_dir = optarg;
|
source_dir = optarg;
|
||||||
source_dir_set = 1;
|
source_dir_set = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'T':
|
||||||
|
nodiscard=1;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
print_usage();
|
print_usage();
|
||||||
}
|
}
|
||||||
|
@ -1318,7 +1324,8 @@ int main(int ac, char **av)
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
first_file = file;
|
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)
|
if (block_count == 0)
|
||||||
block_count = dev_block_count;
|
block_count = dev_block_count;
|
||||||
else if (block_count > dev_block_count) {
|
else if (block_count > dev_block_count) {
|
||||||
|
@ -1416,8 +1423,8 @@ int main(int ac, char **av)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
dev_block_count = block_count;
|
dev_block_count = block_count;
|
||||||
ret = btrfs_prepare_device(fd, file, zero_end,
|
ret = __btrfs_prepare_device(fd, file, zero_end,
|
||||||
&dev_block_count, &mixed);
|
&dev_block_count, &mixed, nodiscard);
|
||||||
mixed = old_mixed;
|
mixed = old_mixed;
|
||||||
BUG_ON(ret);
|
BUG_ON(ret);
|
||||||
|
|
||||||
|
|
18
utils.c
18
utils.c
|
@ -538,6 +538,12 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
|
||||||
|
|
||||||
int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
|
int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
|
||||||
int *mixed)
|
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 block_count;
|
||||||
u64 bytenr;
|
u64 bytenr;
|
||||||
|
@ -564,11 +570,13 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
|
||||||
*mixed = 1;
|
*mixed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (!nodiscard) {
|
||||||
* We intentionally ignore errors from the discard ioctl. It is
|
/*
|
||||||
* not necessary for the mkfs functionality but just an optimization.
|
* 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);
|
*/
|
||||||
|
discard_blocks(fd, 0, block_count);
|
||||||
|
}
|
||||||
|
|
||||||
ret = zero_dev_start(fd);
|
ret = zero_dev_start(fd);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
|
2
utils.h
2
utils.h
|
@ -28,6 +28,8 @@ int btrfs_make_root_dir(struct btrfs_trans_handle *trans,
|
||||||
struct btrfs_root *root, u64 objectid);
|
struct btrfs_root *root, u64 objectid);
|
||||||
int btrfs_prepare_device(int fd, char *file, int zero_end,
|
int btrfs_prepare_device(int fd, char *file, int zero_end,
|
||||||
u64 *block_count_ret, int *mixed);
|
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,
|
int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
|
||||||
struct btrfs_root *root, int fd, char *path,
|
struct btrfs_root *root, int fd, char *path,
|
||||||
u64 block_count, u32 io_width, u32 io_align,
|
u64 block_count, u32 io_width, u32 io_align,
|
||||||
|
|
Loading…
Reference in New Issue