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 <kzak@redhat.com>
This commit is contained in:
Karel Zak 2021-07-01 17:06:34 +02:00
parent effda97409
commit 8678085900
2 changed files with 4 additions and 2 deletions

View File

@ -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.

View File

@ -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;