linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wang Shilong <wangshilong1991@gmail.com>
To: linux-ext4@vger.kernel.org
Cc: Wang Shilong <wshilong@ddn.com>, Shuichi Ihara <sihara@ddn.com>,
	Andreas Dilger <adilger@dilger.ca>,
	Wang Shilong <wangshilong1991@gmail.com>,
	Lukas Czerner <lczerner@redhat.com>
Subject: [PATCH 2/2] tune2fs: add clear_was_trimmed option
Date: Wed, 27 May 2020 23:08:44 +0900	[thread overview]
Message-ID: <1590588525-29669-2-git-send-email-wangshilong1991@gmail.com> (raw)
In-Reply-To: <1590588525-29669-1-git-send-email-wangshilong1991@gmail.com>

From: Wang Shilong <wshilong@ddn.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@ddn.com>
Cc: Andreas Dilger <adilger@dilger.ca>
Cc: Wang Shilong <wangshilong1991@gmail.com>
Cc: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Wang Shilong <wshilong@ddn.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


  reply	other threads:[~2020-05-27 14:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-27 14:08 [PATCH 1/2] e2fsprogs: add EXT2_FLAG_BG_WAS_TRIMMED to optimize fstrim Wang Shilong
2020-05-27 14:08 ` Wang Shilong [this message]
2020-05-27 14:08 ` [PATCH v2] ext4: introduce EXT4_BG_WAS_TRIMMED to optimize trim Wang Shilong
2020-05-27 19:29   ` Andreas Dilger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1590588525-29669-2-git-send-email-wangshilong1991@gmail.com \
    --to=wangshilong1991@gmail.com \
    --cc=adilger@dilger.ca \
    --cc=lczerner@redhat.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=sihara@ddn.com \
    --cc=wshilong@ddn.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).