From 867808590094b03fc9cc45e95798d174231dbedf Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 1 Jul 2021 17:06:34 +0200 Subject: [PATCH] fstrim: clean return code on --quiet-unsupported This feature is already supported for -a and -A. Let's support it also when FS specified on command line. Addresses: https://github.com/systemd/mkosi/pull/721 Signed-off-by: Karel Zak --- sys-utils/fstrim.8.adoc | 2 +- sys-utils/fstrim.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sys-utils/fstrim.8.adoc b/sys-utils/fstrim.8.adoc index fe1c8d318..66671c293 100644 --- a/sys-utils/fstrim.8.adoc +++ b/sys-utils/fstrim.8.adoc @@ -57,7 +57,7 @@ Verbose execution. With this option *fstrim* will output the number of bytes pas *fstrim* will report the same potential discard bytes each time, but only sectors which had been written to between the discards would actually be discarded by the storage device. Further, the kernel block layer reserves the right to adjust the discard ranges to fit raid stripe geometry, non-trim capable devices in a LVM setup, etc. These reductions would not be reflected in fstrim_range.len (the *--length* option). *--quiet-unsupported*:: -Suppress error messages if trim operation (ioctl) is unsupported. This option is meant to be used in systemd service file or in cron scripts to hide warnings that are result of known problems, such as NTFS driver reporting _Bad file descriptor_ when device is mounted read-only, or lack of file system support for ioctl FITRIM call. +Suppress error messages if trim operation (ioctl) is unsupported. This option is meant to be used in systemd service file or in cron scripts to hide warnings that are result of known problems, such as NTFS driver reporting _Bad file descriptor_ when device is mounted read-only, or lack of file system support for ioctl FITRIM call. This option also cleans exit status when unsupported filesystem specified on fstrim command line. *-V*, *--version*:: Display version information and exit. diff --git a/sys-utils/fstrim.c b/sys-utils/fstrim.c index 1ca117071..d2aec4f71 100644 --- a/sys-utils/fstrim.c +++ b/sys-utils/fstrim.c @@ -541,7 +541,9 @@ int main(int argc, char **argv) return EXIT_FAILURE; rc = fstrim_filesystem(&ctl, path, NULL); - if (rc == 1 && !ctl.quiet_unsupp) + if (rc == 1 && ctl.quiet_unsupp) + rc = 0; + if (rc == 1) warnx(_("%s: the discard operation is not supported"), path); return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE;