Bug 1106214

Summary: fstrim attempts to auto trim partition without being told to and gives unclear feedback
Product: [openSUSE] openSUSE Distribution Reporter: Deleted Name <deleted>
Component: OtherAssignee: Stanislav Brabec <sbrabec>
Status: RESOLVED FIXED QA Contact: E-mail List <qa-bugs>
Severity: Normal    
Priority: P5 - None CC: jack, srid
Version: Leap 15.0   
Target Milestone: ---   
Hardware: x86-64   
OS: Other   
Whiteboard: ibs:running:12160:moderate ibs:running:12158:moderate ibs:running:12159:moderate
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Deleted Name 2018-08-28 10:25:00 UTC
# journalctl --since=2018-01-01 | grep -i fstrim | grep -iE "/win"
Jul 30 00:00:01 pc fstrim[28765]: fstrim: /win: FITRIM ioctl failed: Bad file descriptor
Aug 06 00:00:05 pc fstrim[8933]: fstrim: /win: FITRIM ioctl failed: Bad file descriptor
Aug 20 13:17:49 pc fstrim[2118]: fstrim: /win: FITRIM ioctl failed: Bad file descriptor
Aug 27 00:00:06 pc fstrim[6762]: fstrim: /win: FITRIM ioctl failed: Bad file descriptor

NOTE: This system was upgraded from Leap 42.3 to Leap 15.0 on 2018-07-24 and there are no such messages before that date. So it seems related to Leap 15.

# tree /etc/cron.*
/etc/cron.d
├── mdadm
└── unbound-anchor
/etc/cron.daily
├── mdadm
├── mlocate.cron
├── suse-clean_catman
├── suse-do_mandb
└── trim
/etc/cron.deny [error opening dir]
/etc/cron.hourly
/etc/cron.monthly
/etc/cron.weekly

0 directories, 7 files

# cat /etc/cron.daily/trim
#!/bin/sh
LOG=/var/log/trim.log
echo "*** $(date -R) ***" >> $LOG
fstrim -v / >> $LOG

The above short script has been working correctly for years and still works fine. However it does not attempt to trim the '/win' partition. So there is something else which does that.

Running manually the command shows the same message:

# fstrim -v /win
fstrim: /win: FITRIM ioctl failed: Bad file descriptor

The mount options for this ntfs-3g partition are:

ro,noatime,permissions,uid=myusername,gid=users,fmask=177,dmask=077,locale=en_US.UTF-8,windows_names        0 0

Removing the 'ro' option fixes the problem and the partition is trimmed correctly.


EXPECTED:

- do not fstrim partitions automatically without being told to

- do not fstrim read-only partitions and give a clearer feedback message when there is an attempt to do it


ACTUAL:

- fstrim obviously does attempt auto trim a partition without being told to do so

- fstrim attempts to trim a read-only partition and outputs a message which doesn't clearly say that the failure is due to the 'ro' mount
Comment 1 Tomáš Chvátal 2018-08-28 12:53:31 UTC
There is fstrim.timer to be executed once a week.
Comment 2 Deleted Name 2018-08-28 13:20:02 UTC
Is that new in Leap 15.0?
Comment 3 Iakov Karpov 2019-03-04 13:44:27 UTC
Happens with Leap 15.1 Beta.
fstrim fails to trim my read-only windows partition (Why would it try to do it in first place?)
Comment 4 Stanislav Brabec 2019-05-21 16:22:27 UTC
TRIM once in a week is a default behavior.

Attempting to TRIM read-only filesystems seems to be a bug in "fstrim -a" and/or "fstrim -A".
Comment 5 Stanislav Brabec 2019-06-07 18:57:32 UTC
Behavior of fstrim on read-only partitions is filesystem specific. For example, btrfs has no problem with trimming on read-only mount, as long as the device itself is R/W.

But skipping R/O volumes is safe and logical behavior.
Comment 7 Stanislav Brabec 2019-06-11 15:44:40 UTC
According to the upstream, the bug is primarily problem of the NTFS driver.

There are several related fixes in util-linux:

fstrim: check for read-only devices on -a/-A
https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/commit/?id=fe7d63105d923d43c9f478acded0ac888463e456

and introduces new option --quiet


My fix proposes complete skipping of read-only devices in fstrim -a/-A.

Sent to the upstream:
bug 1127701: https://www.spinics.net/lists/util-linux-ng/msg15752.html
bug 1127701: https://www.spinics.net/lists/util-linux-ng/msg15751.html
https://www.spinics.net/lists/util-linux-ng/msg15753.html

And accepted:
bug 1127701: https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/commit/?id=4080be3d7d84952e42048d2f266d49412ada955c
bug 1127701: https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/commit/?id=402006fa6e4dd1ce52758f9be91caaffffb3f337
https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/commit/?id=2d22ac64e4d6e6732640f38b7232b5bcdc84a877

Note that my fix is different than the fe7d63105d923d43c9f478acded0ac888463e456 above: The first one checks for ro mount options, my one checks for writability of the target. My one can skip temporary read-only remounts.


Iakov Karpov, comment 3: This behavior is intentional. Regular TRIM should increase performance of SSD discs by pre-erasing of unused blocks. It is safe for rotating devices, as the command is ignored there.
Comment 8 Iakov Karpov 2019-06-11 16:00:19 UTC
(In reply to Stanislav Brabec from comment #7)
> Iakov Karpov, comment 3: This behavior is intentional. Regular TRIM should
> increase performance of SSD discs by pre-erasing of unused blocks. It is
> safe for rotating devices, as the command is ignored there.

I don't think that trimming blocks, claimed by read-only filesystem is a good idea. If someone explicitly mounts a filesystem as read-only, they probably want it to stay untouched.
Comment 9 Stanislav Brabec 2019-06-11 18:54:51 UTC
Iakov Karpov, comment 8: I agree. Trimming the read-only partition sounds wrong, and makes no sense. I assumed that your "Why would it try" refers to the trimming of the partition itself.

Surprisingly, many kernel drivers have no problem with trimming of read-only mounts.

To Jan Kára: Do you think that kernel should implement EROFS error when trying to FITRIM of read-only file system?
Comment 10 Jan Kara 2019-06-12 13:43:55 UTC
So technically there's no problem with trimming read-only filesystem. I agree it may be somewhat unexpected that the kernel allows this but OTOH the filesystem as such does not change. We just tell underlying storage which blocks are free and which not, which makes sense for read-only filesystem as well and I can even see some uses for that (such as populating filesystem image, then remounting it read-only, then when block allocations are all stable we can fstrim to tell underlying storage about unused blocks).

That being said I agree that "fstrim -a" periodically trimming read-only filesystems is probably just a waste of disk time so I think the most sensible solution would be for "fstrim -a" to just skip read-only filesystems.
Comment 11 Stanislav Brabec 2019-07-09 22:18:33 UTC
Proposal for the forthcoming online update of util-linux:
Fix for: SLE15SP1 SLE15 SLE12SP5 SLE12SP4 SLE12SP3 SLE12SP2 Leap15.1 Leap15
Fixed by the version update for: Factory
Ignore for: SLE12SP1 SLE12
If you want to change this proposal, please let me know.


Note: For technical reasons (fstrim -A patch sequence), the patch will have different names in different updates:

util-linux-fstrim-A-2.patch
in
SLE15SP1 SLE12SP5 Leap15.1

util-linux-fstrim-RO.patch
in
SLE15 SLE12SP4 SLE12SP3 SLE12SP2 Leap15
Comment 16 Stanislav Brabec 2019-07-25 18:40:03 UTC
Fixed for: SLE15SP1 SLE15 Leap15.1 Leap15.0 SLE12SP5 SLE12SP4 SLE12SP3 SLE12SP2
Fixed out of the box for: Factory
Ignored for: SLE12SP1 SLE12
Comment 18 Swamp Workflow Management 2019-09-05 16:14:39 UTC
SUSE-SU-2019:2307-1: An update that contains security fixes can now be installed.

Category: security (moderate)
Bug References: 1081947,1082293,1085196,1106214,1121197,1122417,1125886,1127701,1135534,1135708,1141113,353876
CVE References: 
Sources used:
SUSE Linux Enterprise Module for Server Applications 15-SP1 (src):    util-linux-systemd-2.33.1-4.5.1
SUSE Linux Enterprise Module for Open Buildservice Development Tools 15-SP1 (src):    python3-libmount-2.33.1-4.5.1, util-linux-2.33.1-4.5.1
SUSE Linux Enterprise Module for Basesystem 15-SP1 (src):    shadow-4.6-3.5.6, util-linux-2.33.1-4.5.1, util-linux-systemd-2.33.1-4.5.1

NOTE: This line indicates an update has been released for the listed product(s). At times this might be only a partial fix. If you have questions please reach out to maintenance coordination.
Comment 19 Swamp Workflow Management 2019-09-10 22:16:49 UTC
openSUSE-SU-2019:2121-1: An update that contains security fixes can now be installed.

Category: security (moderate)
Bug References: 1081947,1082293,1085196,1106214,1121197,1122417,1125886,1127701,1135534,1135708,1141113,353876
CVE References: 
Sources used:
openSUSE Leap 15.1 (src):    python3-libmount-2.33.1-lp151.3.3.2, shadow-4.6-lp151.2.3.2, util-linux-2.33.1-lp151.3.3.2, util-linux-systemd-2.33.1-lp151.3.3.2
Comment 20 Stanislav Brabec 2019-09-11 17:15:18 UTC
The fix was just released. Closing.
Comment 21 Swamp Workflow Management 2019-09-17 19:12:49 UTC
SUSE-SU-2019:2392-1: An update that contains security fixes can now be installed.

Category: security (moderate)
Bug References: 1081947,1082293,1085196,1106214,1121197,1122417,1125886,1135534,1135708,353876
CVE References: 
Sources used:
SUSE Linux Enterprise Module for Server Applications 15 (src):    util-linux-systemd-2.31.1-9.8.1
SUSE Linux Enterprise Module for Open Buildservice Development Tools 15-SP1 (src):    python-libmount-2.31.1-9.8.1
SUSE Linux Enterprise Module for Open Buildservice Development Tools 15 (src):    python-libmount-2.31.1-9.8.1, util-linux-2.31.1-9.8.1
SUSE Linux Enterprise Module for Basesystem 15 (src):    shadow-4.5-7.6.4, util-linux-2.31.1-9.8.1, util-linux-systemd-2.31.1-9.8.1

NOTE: This line indicates an update has been released for the listed product(s). At times this might be only a partial fix. If you have questions please reach out to maintenance coordination.
Comment 22 Swamp Workflow Management 2019-09-24 13:13:44 UTC
openSUSE-SU-2019:2175-1: An update that contains security fixes can now be installed.

Category: security (moderate)
Bug References: 1081947,1082293,1085196,1106214,1121197,1122417,1125886,1135534,1135708,353876
CVE References: 
Sources used:
openSUSE Leap 15.0 (src):    shadow-4.5-lp150.11.2, util-linux-2.31.1-lp150.7.10.2
Comment 26 Swamp Workflow Management 2021-10-19 13:17:24 UTC
SUSE-SU-2021:3463-1: An update that solves one vulnerability and has 19 fixes is now available.

Category: security (moderate)
Bug References: 1081947,1082293,1084671,1085196,1106214,1122417,1125886,1135534,1135708,1151708,1168235,1168389,1169006,1174942,1175514,1175623,1178236,1178554,1178825,1188921
CVE References: CVE-2021-37600
JIRA References: 
Sources used:
SUSE OpenStack Cloud Crowbar 8 (src):    python-libmount-2.29.2-3.24.1, util-linux-2.29.2-3.24.1, util-linux-systemd-2.29.2-3.24.1
SUSE OpenStack Cloud 8 (src):    python-libmount-2.29.2-3.24.1, util-linux-2.29.2-3.24.1, util-linux-systemd-2.29.2-3.24.1
SUSE Linux Enterprise Server for SAP 12-SP3 (src):    python-libmount-2.29.2-3.24.1, util-linux-2.29.2-3.24.1, util-linux-systemd-2.29.2-3.24.1
SUSE Linux Enterprise Server 12-SP3-LTSS (src):    python-libmount-2.29.2-3.24.1, util-linux-2.29.2-3.24.1, util-linux-systemd-2.29.2-3.24.1
SUSE Linux Enterprise Server 12-SP3-BCL (src):    python-libmount-2.29.2-3.24.1, util-linux-2.29.2-3.24.1, util-linux-systemd-2.29.2-3.24.1
HPE Helion Openstack 8 (src):    python-libmount-2.29.2-3.24.1, util-linux-2.29.2-3.24.1, util-linux-systemd-2.29.2-3.24.1

NOTE: This line indicates an update has been released for the listed product(s). At times this might be only a partial fix. If you have questions please reach out to maintenance coordination.
Comment 32 Swamp Workflow Management 2022-04-04 19:21:09 UTC
SUSE-SU-2022:1103-1: An update that solves one vulnerability and has 23 fixes is now available.

Category: security (important)
Bug References: 1038841,1081947,1082293,1084671,1085196,1106214,1116347,1122417,1125886,1135534,1135708,1151708,1168235,1168389,1169006,1172427,1174942,1175514,1175623,1178236,1178554,1178825,1188921,1194642
CVE References: CVE-2021-37600
JIRA References: 
Sources used:
SUSE Linux Enterprise Server 12-SP2-BCL (src):    python-libmount-2.28-44.35.1, util-linux-2.28-44.35.1, util-linux-systemd-2.28-44.35.1

NOTE: This line indicates an update has been released for the listed product(s). At times this might be only a partial fix. If you have questions please reach out to maintenance coordination.
Comment 33 Swamp Workflow Management 2022-04-04 19:24:20 UTC
SUSE-SU-2022:1105-1: An update that solves one vulnerability and has 21 fixes is now available.

Category: security (important)
Bug References: 1081947,1082293,1084671,1085196,1106214,1122417,1125886,1135534,1135708,1151708,1168235,1168389,1169006,1172427,1174942,1175514,1175623,1178236,1178554,1178825,1188921,1194642
CVE References: CVE-2021-37600
JIRA References: 
Sources used:
SUSE OpenStack Cloud Crowbar 9 (src):    python-libmount-2.29.2-9.17.1, util-linux-2.29.2-9.17.1, util-linux-systemd-2.29.2-9.17.1
SUSE OpenStack Cloud 9 (src):    python-libmount-2.29.2-9.17.1, util-linux-2.29.2-9.17.1, util-linux-systemd-2.29.2-9.17.1
SUSE Linux Enterprise Server for SAP 12-SP4 (src):    python-libmount-2.29.2-9.17.1, util-linux-2.29.2-9.17.1, util-linux-systemd-2.29.2-9.17.1
SUSE Linux Enterprise Server 12-SP4-LTSS (src):    python-libmount-2.29.2-9.17.1, util-linux-2.29.2-9.17.1, util-linux-systemd-2.29.2-9.17.1

NOTE: This line indicates an update has been released for the listed product(s). At times this might be only a partial fix. If you have questions please reach out to maintenance coordination.