@@ -249,6 +249,11 @@ mounted using experimental kernel code, such as the ext4dev filesystem.
.B ^test_fs
Clear the test_fs flag, indicating the filesystem should only be mounted
using production-level filesystem code.
+.TP
+.B clear_was_trimmed
+Clear block groups' WAS_TRIMMED flag, this will force fstrim to run every
+block group next time.
+.TP
.RE
.TP
.B \-f
@@ -101,6 +101,7 @@ static int rewrite_checksums;
static int feature_64bit;
static int fsck_requested;
static char *undo_file;
+static int clear_was_trimmed;
int journal_size, journal_flags;
char *journal_device;
@@ -949,6 +950,26 @@ static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
ext2fs_mark_super_dirty(fs);
}
+static void clear_bg_was_trimmed(ext2_filsys fs)
+{
+ dgrp_t i;
+ int dirty = 0;
+
+ for (i = 0; i < fs->group_desc_count; i++) {
+ if (ext2fs_bg_flags_test(fs, i, EXT2_BG_WAS_TRIMMED)) {
+ ext2fs_bg_flags_clear(fs, i, EXT2_BG_WAS_TRIMMED);
+ ext2fs_group_desc_csum_set(fs, i);
+ dirty = 1;
+ }
+ }
+
+ if (dirty) {
+ fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
+ ext2fs_mark_bb_dirty(fs);
+ ext2fs_mark_super_dirty(fs);
+ }
+}
+
static void enable_uninit_bg(ext2_filsys fs)
{
struct ext2_group_desc *gd;
@@ -2207,6 +2228,9 @@ static int parse_extended_opts(ext2_filsys fs, const char *opts)
continue;
}
ext_mount_opts = strdup(arg);
+ } else if (!strcmp(token, "clear_was_trimmed") ||
+ !strcmp(token, "clear_was-trimmed")) {
+ clear_was_trimmed = 1;
} else
r_usage++;
}
@@ -2224,7 +2248,8 @@ static int parse_extended_opts(ext2_filsys fs, const char *opts)
"\tstripe_width=<RAID stride*data disks in blocks>\n"
"\tforce_fsck\n"
"\ttest_fs\n"
- "\t^test_fs\n"));
+ "\t^test_fs\n"
+ "\tclear_was_trimmed\n"));
free(buf);
return 1;
}
@@ -3361,6 +3386,9 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
}
}
+ if (clear_was_trimmed)
+ clear_bg_was_trimmed(fs);
+
if (rewrite_checksums)
rewrite_metadata_checksums(fs, rewrite_checksums);