Skip to contentSkip to conversation

e2fsck: Discard free data and inode blocks.

PATCH New Lukas Czerner 1 participant 1 message Oct 11, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 e2fsck: Discard free data and inode blocks.

In Pass 5 when we are checking block and inode bitmaps we have great opportunity to discard free space and unused inodes on the device, because bitmaps has just been verified as valid. This commit takes advantage of this opportunity and discards both, all free space and unused inodes.

I have added new option '-K' which when set, disables discard. Also when the underlying device does not support discard, or BLKDISCARD ioctl returns any kind of error, or when some errors occurred in bitmaps, the discard is disabled.

As an addition, when there is any not-yet-zeroed inode table and discard zeroes data, then inode table is marked as zeroed.

---
 e2fsck/e2fsck.8.in |    7 +++
 e2fsck/e2fsck.h    |    1 +
 e2fsck/pass5.c     |  119 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 e2fsck/unix.c      |   10 ++++-
 4 files changed, 135 insertions(+), 2 deletions(-)
e2fsck/e2fsck.8.in +7 -0
index 3fb15e6..507f7b1 100644
@@ -19,6 +19,9 @@ e2fsck \- check a Linux ext2/ext3/ext4 file system
 .I blocksize
 ]
 [
+.B \-K
+]
+[
 .BR \-l | \-L
 .I bad_blocks_file
 ]
@@ -204,6 +207,10 @@ time trials.
 @JDEV@Set the pathname where the external-journal for this filesystem can be
 @JDEV@found.
 .TP
+.BI \-K
+Keep, do not attempt to discard free blocks and unused inodes (discarding
+blocks is useful on solid state devices and sparse / thin-provisioned storage).
+.TP
 .BI \-k
 When combined with the 
 .B \-c
e2fsck/e2fsck.h +1 -0
index d4df5f3..a377246 100644
@@ -155,6 +155,7 @@ struct resource_track {
 #define E2F_OPT_WRITECHECK	0x0200
 #define E2F_OPT_COMPRESS_DIRS	0x0400
 #define E2F_OPT_FRAGCHECK	0x0800
+#define E2F_OPT_DISCARD		0x1000
 
 /*
  * E2fsck flags
e2fsck/pass5.c +119 -0

168 lines not on this page · raw message

e2fsck/unix.c +8 -1
index 6cb2214..5c8335a 100644
@@ -667,7 +667,11 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
 		ctx->program_name = *argv;
 	else
 		ctx->program_name = "e2fsck";
-	while ((c = getopt (argc, argv, "panyrcC:B:dE:fvtFVM:b:I:j:P:l:L:N:SsDk")) != EOF)
+
+	/* set defaults */
+	ctx->options |= E2F_OPT_DISCARD;
+
+	while ((c = getopt (argc, argv, "panyrcC:B:dE:fvtFVM:b:I:j:P:l:L:N:SsDkK")) != EOF)
 		switch (c) {
 		case 'C':
 			ctx->progress = e2fsck_update_progress;
@@ -790,6 +794,9 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
 		case 'k':
 			keep_bad_blocks++;
 			break;
+		case 'K':
+			ctx->options &= ~E2F_OPT_DISCARD;
+			break;
 		default:
 			usage(ctx);
 		}
@@ -943,7 +950,6 @@ static errcode_t try_open_fs(e2fsck_t ctx, int flags, io_manager io_ptr,
 	return retval;
 }