[RFC] [PATCH] mkfs: implement discarding device at filesystem creation time.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A new flag, -d/--discard, is used for that purpose. No discard support
auto-detection is performed.
---
 progs/mkfs/mkfs.c | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/progs/mkfs/mkfs.c b/progs/mkfs/mkfs.c
index 43437d4..7b9bdea 100644
--- a/progs/mkfs/mkfs.c
+++ b/progs/mkfs/mkfs.c
@@ -34,7 +34,8 @@ typedef enum mkfs_behav_flags {
 	BF_YES        = 1 << 1,
 	BF_LOST       = 1 << 2,
 	BF_SHOW_PARM  = 1 << 3,
-	BF_SHOW_PLUG  = 1 << 4
+	BF_SHOW_PLUG  = 1 << 4,
+	BF_DISCARD    = 1 << 5
 } mkfs_behav_flags_t;
 
 /* Prints mkfs options */
@@ -62,7 +63,9 @@ static void mkfs_print_usage(char *name) {
 		"  -V, --version                 prints current version.\n"
 		"  -y, --yes                     assumes an answer 'yes' to all questions.\n"
 		"  -f, --force                   makes mkfs to use whole disk, not\n"
-		"                                block device or mounted partition.\n");
+		"                                block device or mounted partition.\n"
+		"  -d, --discard                 tells mkfs to discard given device\n"
+		"                                before creating the filesystem.\n");
 }
 
 /* Initializes used by mkfs exception streams */
@@ -128,6 +131,7 @@ int main(int argc, char *argv[]) {
 		{"print-profile", no_argument, NULL, 'p'},
 		{"print-plugins", no_argument, NULL, 'l'},
 		{"override", required_argument, NULL, 'o'},
+		{"discard", no_argument, NULL, 'd'},
 		{0, 0, 0, 0}
 	};
     
@@ -146,7 +150,7 @@ int main(int argc, char *argv[]) {
 	memset(hint.label, 0, sizeof(hint.label));
 
 	/* Parsing parameters */    
-	while ((c = getopt_long(argc, argv, "hVyfb:U:L:splo:?",
+	while ((c = getopt_long(argc, argv, "hVyfb:U:L:splo:d?",
 				long_options, (int *)0)) != EOF) 
 	{
 		switch (c) {
@@ -172,6 +176,9 @@ int main(int argc, char *argv[]) {
 		case 's':
 			flags |= BF_LOST;
 			break;
+		case 'd':
+			flags |= BF_DISCARD;
+			break;
 		case 'o':
 			aal_strncat(override, optarg,
 				    aal_strlen(optarg));
@@ -440,7 +447,25 @@ int main(int argc, char *argv[]) {
 				goto error_free_device;
 			}
 		}
-    
+
+		if (flags & BF_DISCARD) {
+			if (gauge) {
+				aal_gauge_rename(gauge, "Discarding %s ... ",
+						 host_dev);
+				aal_gauge_touch(gauge);
+			}
+
+			if ((aal_device_discard(device, 0, dev_len) != 0)) {
+				aal_error("Failed to discard %s (%s).",
+					  device->name, device->error);
+				/* discard is optional, don't fail the mkfs */
+			}
+
+			if (gauge) {
+				aal_gauge_done(gauge);
+			}
+		}
+
 		if (gauge) {
 			aal_gauge_rename(gauge, "Creating reiser4 on %s ... ",
 					 host_dev);
-- 
1.9.2

--
To unsubscribe from this list: send the line "unsubscribe reiserfs-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux File System Development]     [Linux BTRFS]     [Linux NFS]     [Linux Filesystems]     [Ext4 Filesystem]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Resources]

  Powered by Linux