]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fstrim -a/-A: Skip read-only volumes
authorStanislav Brabec <sbrabec@suse.cz>
Mon, 10 Jun 2019 19:59:45 +0000 (21:59 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 11 Jun 2019 08:23:45 +0000 (10:23 +0200)
Calling TRIM on some read-only volumes can fail with:
fstrim: /win: FITRIM ioctl failed: Bad file descriptor

Skipping all read-only mounts seems to be safe and logical strategy.

Fixes opensuse#1106214.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
sys-utils/fstrim.c

index ff029015e60acef25a531f96648c82065c7ca02c..ea29a569581bb8b5fb93934f5435ad22bf635cce 100644 (file)
@@ -311,6 +311,14 @@ static int fstrim_all(struct fstrim_control *ctl)
                if (rc)
                        continue;       /* overlaying mount */
 
+               /* FSTRIM on read-only filesystem can fail, and it can fail */
+               if (access(path, W_OK) != 0) {
+                       if (errno == EROFS)
+                               continue;
+                       if (errno == EACCES)
+                               continue;
+               }
+
                if (!has_discard(src, &wholedisk))
                        continue;
                cnt++;