mirror of
https://github.com/kdave/btrfs-progs
synced 2025-04-19 13:35:22 +00:00
btrfs-progs: add nodiscard option to device add
Same as for mkfs. Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
This commit is contained in:
parent
15ac848f8a
commit
992fd23180
@ -22,6 +22,7 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
|
||||||
#include "kerncompat.h"
|
#include "kerncompat.h"
|
||||||
#include "ctree.h"
|
#include "ctree.h"
|
||||||
@ -36,8 +37,9 @@ static const char * const device_cmd_group_usage[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const char * const cmd_add_dev_usage[] = {
|
static const char * const cmd_add_dev_usage[] = {
|
||||||
"btrfs device add <device> [<device>...] <path>",
|
"btrfs device add [options] <device> [<device>...] <path>",
|
||||||
"Add a device to a filesystem",
|
"Add a device to a filesystem",
|
||||||
|
"-K|--nodiscard do not perform whole device TRIM",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -46,11 +48,33 @@ static int cmd_add_dev(int argc, char **argv)
|
|||||||
char *mntpnt;
|
char *mntpnt;
|
||||||
int i, fdmnt, ret=0, e;
|
int i, fdmnt, ret=0, e;
|
||||||
DIR *dirstream = NULL;
|
DIR *dirstream = NULL;
|
||||||
|
int discard = 1;
|
||||||
|
|
||||||
if (check_argc_min(argc, 3))
|
while (1) {
|
||||||
|
int long_index;
|
||||||
|
static struct option long_options[] = {
|
||||||
|
{ "nodiscard", optional_argument, NULL, 'K'},
|
||||||
|
{ 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
|
int c = getopt_long(argc, argv, "K", long_options,
|
||||||
|
&long_index);
|
||||||
|
if (c < 0)
|
||||||
|
break;
|
||||||
|
switch (c) {
|
||||||
|
case 'K':
|
||||||
|
discard = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage(cmd_add_dev_usage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
argc = argc - optind;
|
||||||
|
|
||||||
|
if (check_argc_min(argc, 2))
|
||||||
usage(cmd_add_dev_usage);
|
usage(cmd_add_dev_usage);
|
||||||
|
|
||||||
mntpnt = argv[argc - 1];
|
mntpnt = argv[optind + argc - 1];
|
||||||
|
|
||||||
fdmnt = open_file_or_dir(mntpnt, &dirstream);
|
fdmnt = open_file_or_dir(mntpnt, &dirstream);
|
||||||
if (fdmnt < 0) {
|
if (fdmnt < 0) {
|
||||||
@ -58,7 +82,7 @@ static int cmd_add_dev(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 1; i < argc - 1; i++ ){
|
for (i = optind; i < optind + argc - 1; i++){
|
||||||
struct btrfs_ioctl_vol_args ioctl_args;
|
struct btrfs_ioctl_vol_args ioctl_args;
|
||||||
int devfd, res;
|
int devfd, res;
|
||||||
u64 dev_block_count = 0;
|
u64 dev_block_count = 0;
|
||||||
@ -99,7 +123,7 @@ static int cmd_add_dev(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
res = btrfs_prepare_device(devfd, argv[i], 1, &dev_block_count,
|
res = btrfs_prepare_device(devfd, argv[i], 1, &dev_block_count,
|
||||||
0, &mixed, 0);
|
0, &mixed, discard);
|
||||||
if (res) {
|
if (res) {
|
||||||
fprintf(stderr, "ERROR: Unable to init '%s'\n", argv[i]);
|
fprintf(stderr, "ERROR: Unable to init '%s'\n", argv[i]);
|
||||||
close(devfd);
|
close(devfd);
|
||||||
|
@ -47,7 +47,7 @@ btrfs \- control a btrfs filesystem
|
|||||||
\fBbtrfs\fP \fB[filesystem] balance status\fP [-v] \fI<path>\fP
|
\fBbtrfs\fP \fB[filesystem] balance status\fP [-v] \fI<path>\fP
|
||||||
.PP
|
.PP
|
||||||
.PP
|
.PP
|
||||||
\fBbtrfs\fP \fBdevice add\fP \fI<device>\fP [\fI<device>...\fP] \fI<path>\fP
|
\fBbtrfs\fP \fBdevice add\fP [-K] \fI<device>\fP [\fI<device>...\fP] \fI<path>\fP
|
||||||
.PP
|
.PP
|
||||||
\fBbtrfs\fP \fBdevice delete\fP \fI<device>\fP [\fI<device>...\fP] \fI<path>\fP
|
\fBbtrfs\fP \fBdevice delete\fP \fI<device>\fP [\fI<device>...\fP] \fI<path>\fP
|
||||||
.PP
|
.PP
|
||||||
@ -381,8 +381,15 @@ be verbose
|
|||||||
.RE
|
.RE
|
||||||
.TP
|
.TP
|
||||||
|
|
||||||
\fBdevice add\fR\fI <dev> \fP[\fI<dev>...\fP] \fI<path>\fR
|
\fBdevice add\fR\fI [-K] <dev> \fP[\fI<dev>...\fP] \fI<path>\fR
|
||||||
Add device(s) to the filesystem identified by \fI<path>\fR.
|
Add device(s) to the filesystem identified by \fI<path>\fR.
|
||||||
|
If applicable, a whole device discard (TRIM) operation is performed.
|
||||||
|
.RS
|
||||||
|
|
||||||
|
\fIOptions\fR
|
||||||
|
.IP "\fB-K|--nodiscard\fP" 5
|
||||||
|
do not perform discard by default
|
||||||
|
.RE
|
||||||
.TP
|
.TP
|
||||||
|
|
||||||
\fBdevice delete\fR\fI <dev> \fP[\fI<dev>...\fP] \fI<path>\fR
|
\fBdevice delete\fR\fI <dev> \fP[\fI<dev>...\fP] \fI<path>\fR
|
||||||
|
2
utils.c
2
utils.c
@ -597,6 +597,8 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (discard) {
|
if (discard) {
|
||||||
|
fprintf(stderr, "Performing full device TRIM (%s) ...\n",
|
||||||
|
pretty_size(block_count));
|
||||||
/*
|
/*
|
||||||
* We intentionally ignore errors from the discard ioctl. It is
|
* We intentionally ignore errors from the discard ioctl. It is
|
||||||
* not necessary for the mkfs functionality but just an optimization.
|
* not necessary for the mkfs functionality but just an optimization.
|
||||||
|
Loading…
Reference in New Issue
Block a user