lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 27 May 2020 23:08:44 +0900
From:   Wang Shilong <wangshilong1991@...il.com>
To:     linux-ext4@...r.kernel.org
Cc:     Wang Shilong <wshilong@....com>, Shuichi Ihara <sihara@....com>,
        Andreas Dilger <adilger@...ger.ca>,
        Wang Shilong <wangshilong1991@...il.com>,
        Lukas Czerner <lczerner@...hat.com>
Subject: [PATCH 2/2] tune2fs: add clear_was_trimmed option

From: Wang Shilong <wshilong@....com>

It might be possible that admin want an option for clear
existed WAS_TRIMMED flag to force fstrim next run time.

Cc: Shuichi Ihara <sihara@....com>
Cc: Andreas Dilger <adilger@...ger.ca>
Cc: Wang Shilong <wangshilong1991@...il.com>
Cc: Lukas Czerner <lczerner@...hat.com>
Signed-off-by: Wang Shilong <wshilong@....com>
---
 misc/tune2fs.8.in |  5 +++++
 misc/tune2fs.c    | 30 +++++++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/misc/tune2fs.8.in b/misc/tune2fs.8.in
index 3cf1f5ed..b8025949 100644
--- a/misc/tune2fs.8.in
+++ b/misc/tune2fs.8.in
@@ -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
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 314cc0d0..3e9814e3 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -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);
 
-- 
2.25.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ