Sometimes it makes sense to skip fstrim for selected file mounts, but
still be able to use fstrim.service.
Add a possibility to specify "x-fstrim.notrim" in fstab.
Do not use "notrim", as it collides with the kernel rbd driver.
Signed-off-by: Stanislav Brabec <sbrabec@xxxxxxx>
---
sys-utils/fstrim.8.adoc | 4 +++-
sys-utils/fstrim.c | 2 ++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/sys-utils/fstrim.8.adoc b/sys-utils/fstrim.8.adoc
index b2c1fce22..66387ba35 100644
--- a/sys-utils/fstrim.8.adoc
+++ b/sys-utils/fstrim.8.adoc
@@ -29,7 +29,7 @@ Running *fstrim* frequently, or even using *mount -o
discard*, might negatively
The _offset_, _length_, and _minimum-size_ arguments may be followed
by the multiplicative suffixes KiB (=1024), MiB (=1024*1024), and so on
for GiB, TiB, PiB, EiB, ZiB and YiB (the "iB" is optional, e.g., "K" has
the same meaning as "KiB") or the suffixes KB (=1000), MB (=1000*1000),
and so on for GB, TB, PB, EB, ZB and YB.
*-A, --fstab*::
-Trim all mounted filesystems mentioned in _/etc/fstab_ on devices that
support the discard operation. The root filesystem is determined from
kernel command line if missing in the file. The other supplied options,
like *--offset*, *--length* and *--minimum*, are applied to all these
devices. Errors from filesystems that do not support the discard
operation, read-only devices, autofs and read-only filesystems are
silently ignored.
+Trim all mounted filesystems mentioned in _/etc/fstab_ on devices that
support the discard operation. The root filesystem is determined from
kernel command line if missing in the file. The other supplied options,
like *--offset*, *--length* and *--minimum*, are applied to all these
devices. Errors from filesystems that do not support the discard
operation, read-only devices, autofs and read-only filesystems are
silently ignored. Filesystems with "x-fstrim.notrim" mount option are
skipped.
*-a, --all*::
Trim all mounted filesystems on devices that support the discard
operation. The other supplied options, like *--offset*, *--length* and
*--minimum*, are applied to all these devices. Errors from filesystems
that do not support the discard operation, read-only devices and
read-only filesystems are silently ignored.
@@ -47,6 +47,8 @@ The number of bytes (after the starting point) to
search for free blocks to disc
Specifies a colon-separated list of files in fstab or kernel mountinfo
format. All missing or empty files are silently ignored. The evaluation
of the _list_ stops after first non-empty file. For example:
+
*--listed-in /etc/fstab:/proc/self/mountinfo*.
++
+Filesystems with "x-fstrim.notrim" mount option are skipped.
*-m, --minimum* _minimum-size_::
Minimum contiguous free range to discard, in bytes. (This value is
internally rounded up to a multiple of the filesystem block size.) Free
ranges smaller than this will be ignored and *fstrim* will adjust the
minimum if it's smaller than the device's minimum, and report that
(fstrim_range.minlen) back to userspace. By increasing this value, the
*fstrim* operation will complete more quickly for filesystems with badly
fragmented freespace, although not all blocks will be discarded. The
default value is zero, discarding every free block.
diff --git a/sys-utils/fstrim.c b/sys-utils/fstrim.c
index 88397f0ec..cbe1c76d0 100644
--- a/sys-utils/fstrim.c
+++ b/sys-utils/fstrim.c
@@ -224,6 +224,8 @@ static int is_unwanted_fs(struct libmnt_fs *fs,
const char *tgt)
return 1;
if (mnt_fs_match_options(fs, "ro"))
return 1;
+ if (mnt_fs_match_options(fs, "+x-fstrim.notrim"))
+ return 1;
fd = open(tgt, O_PATH);
if (fd < 0)
--
2.31.1
--
Best Regards / S pozdravem,
Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o. e-mail: sbrabec@xxxxxxxx
Křižíkova 148/34 (Corso IIa) tel: +420 284 084 060
186 00 Praha 8-Karlín fax: +420 284 084 001
Czech Republic http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76