All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] nodiscard for device add
@ 2013-09-17 14:53 David Sterba
  2013-09-17 14:54 ` [PATCH 1/2] btrfs-progs: use better name for nodiscard variable and flip the logic David Sterba
  2013-09-17 14:54 ` [PATCH 2/2] btrfs-progs: add nodiscard option to device add David Sterba
  0 siblings, 2 replies; 3+ messages in thread
From: David Sterba @ 2013-09-17 14:53 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

David Sterba (2):
  btrfs-progs: use better name for nodiscard variable and flip the logic
  btrfs-progs: add nodiscard option to device add

 cmds-device.c  | 34 +++++++++++++++++++++++++++++-----
 man/btrfs.8.in | 11 +++++++++--
 mkfs.c         |  8 ++++----
 utils.c        |  6 ++++--
 utils.h        |  2 +-
 5 files changed, 47 insertions(+), 14 deletions(-)

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] btrfs-progs: use better name for nodiscard variable and flip the logic
  2013-09-17 14:53 [PATCH 0/2] nodiscard for device add David Sterba
@ 2013-09-17 14:54 ` David Sterba
  2013-09-17 14:54 ` [PATCH 2/2] btrfs-progs: add nodiscard option to device add David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2013-09-17 14:54 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

Signed-off-by: David Sterba <dsterba@suse.cz>
---
 mkfs.c  | 8 ++++----
 utils.c | 4 ++--
 utils.h | 2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/mkfs.c b/mkfs.c
index 3ac00ba..40da546 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1324,7 +1324,7 @@ int main(int ac, char **av)
 	int mixed = 0;
 	int data_profile_opt = 0;
 	int metadata_profile_opt = 0;
-	int nodiscard = 0;
+	int discard = 1;
 	int ssd = 0;
 	int force_overwrite = 0;
 
@@ -1409,7 +1409,7 @@ int main(int ac, char **av)
 				source_dir_set = 1;
 				break;
 			case 'K':
-				nodiscard=1;
+				discard = 0;
 				break;
 			default:
 				print_usage();
@@ -1507,7 +1507,7 @@ int main(int ac, char **av)
 		}
 		first_file = file;
 		ret = btrfs_prepare_device(fd, file, zero_end, &dev_block_count,
-					   block_count, &mixed, nodiscard);
+					   block_count, &mixed, discard);
 		if (block_count && block_count > dev_block_count) {
 			fprintf(stderr, "%s is smaller than requested size\n", file);
 			exit(1);
@@ -1614,7 +1614,7 @@ int main(int ac, char **av)
 			continue;
 		}
 		ret = btrfs_prepare_device(fd, file, zero_end, &dev_block_count,
-					   block_count, &mixed, nodiscard);
+					   block_count, &mixed, discard);
 		mixed = old_mixed;
 		BUG_ON(ret);
 
diff --git a/utils.c b/utils.c
index 134bf80..bb1bcdb 100644
--- a/utils.c
+++ b/utils.c
@@ -569,7 +569,7 @@ 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,
-			   u64 max_block_count, int *mixed, int nodiscard)
+			   u64 max_block_count, int *mixed, int discard)
 {
 	u64 block_count;
 	u64 bytenr;
@@ -596,7 +596,7 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
 		*mixed = 1;
 	}
 
-	if (!nodiscard) {
+	if (discard) {
 		/*
 		 * We intentionally ignore errors from the discard ioctl.  It is
 		 * not necessary for the mkfs functionality but just an optimization.
diff --git a/utils.h b/utils.h
index 6c2553a..6bf7880 100644
--- a/utils.h
+++ b/utils.h
@@ -34,7 +34,7 @@ int make_btrfs(int fd, const char *device, const char *label,
 int btrfs_make_root_dir(struct btrfs_trans_handle *trans,
 			struct btrfs_root *root, u64 objectid);
 int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
-			 u64 max_block_count, int *mixed, int nodiscard);
+			 u64 max_block_count, int *mixed, int discard);
 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,
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] btrfs-progs: add nodiscard option to device add
  2013-09-17 14:53 [PATCH 0/2] nodiscard for device add David Sterba
  2013-09-17 14:54 ` [PATCH 1/2] btrfs-progs: use better name for nodiscard variable and flip the logic David Sterba
@ 2013-09-17 14:54 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2013-09-17 14:54 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

Same as for mkfs.

Signed-off-by: David Sterba <dsterba@suse.cz>
---
 cmds-device.c  | 34 +++++++++++++++++++++++++++++-----
 man/btrfs.8.in | 11 +++++++++--
 utils.c        |  2 ++
 3 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/cmds-device.c b/cmds-device.c
index 800a050..12c802e 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -22,6 +22,7 @@
 #include <sys/ioctl.h>
 #include <errno.h>
 #include <sys/stat.h>
+#include <getopt.h>
 
 #include "kerncompat.h"
 #include "ctree.h"
@@ -36,8 +37,9 @@ static const char * const device_cmd_group_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",
+	"-K|--nodiscard    do not perform whole device TRIM",
 	NULL
 };
 
@@ -46,11 +48,33 @@ static int cmd_add_dev(int argc, char **argv)
 	char	*mntpnt;
 	int	i, fdmnt, ret=0, e;
 	DIR	*dirstream = NULL;
+	int discard = 1;
+
+	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);
+		}
+	}
 
-	if (check_argc_min(argc, 3))
+	argc = argc - optind;
+
+	if (check_argc_min(argc, 2))
 		usage(cmd_add_dev_usage);
 
-	mntpnt = argv[argc - 1];
+	mntpnt = argv[optind + argc - 1];
 
 	fdmnt = open_file_or_dir(mntpnt, &dirstream);
 	if (fdmnt < 0) {
@@ -58,7 +82,7 @@ static int cmd_add_dev(int argc, char **argv)
 		return 1;
 	}
 
-	for (i = 1; i < argc - 1; i++ ){
+	for (i = optind; i < optind + argc - 1; i++){
 		struct btrfs_ioctl_vol_args ioctl_args;
 		int	devfd, res;
 		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,
-					   0, &mixed, 0);
+					   0, &mixed, discard);
 		if (res) {
 			fprintf(stderr, "ERROR: Unable to init '%s'\n", argv[i]);
 			close(devfd);
diff --git a/man/btrfs.8.in b/man/btrfs.8.in
index 61ffe8d..03126b4 100644
--- a/man/btrfs.8.in
+++ b/man/btrfs.8.in
@@ -47,7 +47,7 @@ btrfs \- control a btrfs filesystem
 \fBbtrfs\fP \fB[filesystem] balance status\fP [-v] \fI<path>\fP
 .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
 \fBbtrfs\fP \fBdevice delete\fP \fI<device>\fP [\fI<device>...\fP] \fI<path>\fP
 .PP
@@ -386,8 +386,15 @@ be verbose
 .RE
 .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.
+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
 
 \fBdevice delete\fR\fI <dev> \fP[\fI<dev>...\fP] \fI<path>\fR
diff --git a/utils.c b/utils.c
index bb1bcdb..68aa534 100644
--- a/utils.c
+++ b/utils.c
@@ -597,6 +597,8 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
 	}
 
 	if (discard) {
+		fprintf(stderr, "Performing full device TRIM (%s) ...\n",
+				pretty_size(block_count));
 		/*
 		 * We intentionally ignore errors from the discard ioctl.  It is
 		 * not necessary for the mkfs functionality but just an optimization.
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-09-17 14:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-17 14:53 [PATCH 0/2] nodiscard for device add David Sterba
2013-09-17 14:54 ` [PATCH 1/2] btrfs-progs: use better name for nodiscard variable and flip the logic David Sterba
2013-09-17 14:54 ` [PATCH 2/2] btrfs-progs: add nodiscard option to device add David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.