summaryrefslogtreecommitdiffstats
path: root/sys-utils/fstrim.c
Commit message (Collapse)AuthorAgeFilesLines
* fstrim: update man page, reuse libmnt_iterKarel Zak2019-06-111-5/+4Star
| | | | | | | | * add info about read-only to the man page * don't be systemd specific, people aso use crond * reuse libmnt_iter Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: properly de-duplicate fstrim -AStanislav Brabec2019-06-111-13/+30
| | | | | | | | | | fstab can contain tag based mounts. De-duplication by source has to be done after resolving the full source path. Perform the table iteration twice. First time, prepare for de-duplication, second time perform the TRIM itself. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* fstrim -a/-A: Skip read-only volumesStanislav Brabec2019-06-111-0/+8
| | | | | | | | | | | 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>
* fstrim: Fix fstrim_all() commentStanislav Brabec2019-06-111-1/+1
| | | | | | | | "convert LABEL=" does not happens in mnt_fs_get_source(), but later in mnt_resolve_spec(). To make this more clean, move the comment before this chunk of code. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* fstrim: affect only warnings by --quietKarel Zak2019-05-091-6/+7
| | | | | | | | We need the same return code from fstrim_filesystem() independently on --quiet command line option. Addresses: https://github.com/karelzak/util-linux/pull/791 Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: add --quiet option to suppress error messagesSami Kerola2019-05-071-4/+21
| | | | | | | | | | | | | When fstrim interacts with NTFS it result can be error reporting bad file descriptor. That seems to be a bug in NTFS. While waiting driver to get on top of the issue and be commonly available lets add to fstrim option to make it be more silent about errno 9 aka EBADF, Bad file descriptor. Reported-by: https://github.com/moviuro Proposed-by: Dave Reisner <dreisner@archlinux.org> Reference: https://bugs.archlinux.org/task/62288 Addresses: https://github.com/karelzak/util-linux/issues/789 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-8/+6Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: get realpath before trim ioctlWang Shilong2019-04-151-2/+9
| | | | | | | | | | | | | | | | | | | | | | Original motivation is we want to run fstrim command on Lustre[1] osd server mount point directly, however our server mount point doesn't export osd directory to users, and it will cause following command fail: $fstrim -v /mnt/mds/ But following succeed: $fstrim -v /mnt/mds We could improve this a bit by getting realpath before trapping kernel, this also give benifits to normal use cases. Cc: Andreas Dilger <adilger@dilger.ca> Cc: Shuichi Ihara <sihara@ddn.com> [1] http://wiki.lustre.org/Main_Page Signed-off-by: Wang Shilong <wshilong@ddn.com>
* fstrim.c: Remove commnet about vfat not supporting fstrimMarcos Paulo de Souza2019-04-011-1/+1
| | | | | | | Commit f663b5b38f ("fat: add FITRIM ioctl for FAT file system") in linux kernel added support for using fstrim with vfat filesystem. Signed-off-by: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
* fstrim: check for read-only devices on -a/-AKarel Zak2019-01-111-2/+4
| | | | | | | to avoid "FITRIM ioctl failed: Remote I/O error" Addresses: https://github.com/karelzak/util-linux/issues/738 Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: fix usage()Karel Zak2018-12-101-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: trim also root FS on --fstabKarel Zak2018-12-101-0/+17
| | | | | | | | | The root fs ("/") is optional in many case in /etc/fstab. This patch forces fstrim to read kernel command line for the root= option to get root FS if the entry is missing in your fstab. Addresses: https://github.com/karelzak/util-linux/issues/719 Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: use -n shortcut for --dry-runKarel Zak2018-08-161-3/+3
| | | | | | | | It seems 'n' is more common than 'd'. The patch also cleanup getopt_long() options string. Addresses: https://github.com/karelzak/util-linux/commit/fda0e2cf043994c77c29a2d109c03ce8957b1d38#commitcomment-30097920 Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: add -A|--fstab to trim according to /etc/fstabKarel Zak2018-07-311-13/+50
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/673 Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: add control structKarel Zak2018-07-311-19/+24
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: add --dry-runKarel Zak2018-06-211-7/+20
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: use new ul_path_* API, improve sysfs context usageKarel Zak2018-06-211-18/+34
| | | | | | | * improve has_discard() function to initialize sysfs context only once * use new ul_path_* API Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: Return EXIT_FAILURE when FTRIM ioctl failsKarel Zak2018-04-061-10/+7Star
| | | | | | | | | | commit 36c370cbf1481aa8724dff8b7b7fec4a8ba9930b adds fstrim_filesystem() that return -1 or 1 depending on the FTRIM ioctl failures. The fstrim_filesystem() return codes should not be used as exit codes. Reported-by: Gwendal Grignou <gwendal@chromium.org> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: include sys/mount.h only if necessaryKarel Zak2018-03-221-3/+1Star
| | | | | Addresses: https://github.com/systemd/systemd/issues/8507 Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: cleanup includesKarel Zak2018-03-221-4/+4
| | | | | | | | | * HAVE_SYS_FS_H is incorrect (should be HAVE_LINUX_FS_H) * linux/fs.h cannot be included together with sys/mount.h as the both files define MS_* constants. The libmount.h includes sys/mount.h now. Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: fix fs.h and mount.h collisionKarel Zak2018-03-201-1/+4
| | | | | | | | | Unfortunately, old version of the file linux/fs.h defines MS_* macros, so the file cannot be included together with sys/mount.h. We include sys/mount.h from libmount.h now. Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: don't include exitcodes.hKarel Zak2018-02-011-1/+0Star
| | | | | | The code uses generic and libmount return codes only. Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: consolidate macro style USAGE_HELP_OPTIONSRuediger Meier2017-06-291-2/+2
| | | | | | | | | changed in include/c.h and applied via sed: sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c") sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c") Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: introduce print_usage_help_options()Ruediger Meier2017-06-271-2/+1Star
| | | | | | | | | | | | Consolidate --help and --version descriptions. We are now able to align them to the other options. We changed include/c.h. The rest of this patch was generated by sed, plus manually setting the right alignment numbers. We do not change anything but white spaces in the --help output. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: never use usage(stderr)Ruediger Meier2017-06-261-4/+5
| | | | | | | Here we fix all cases where we have usage(FILE*) functions. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* fstrim: remove obsolete commentKarel Zak2017-06-151-1/+1
| | | | | | We do not de-duplicate by FS root (since afa382f2e087b71c9e626144f2f313abc42ad594). Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: prefer earlier mounted filesystemsAlex Ivanov2017-06-151-1/+1
| | | | | | | | | | | | | | | | | | | fstrim --all is broken in a way that if there is a bind mount for some filesystem, that filesystem will not be trimmed. This is especially critical for e.g. NixOS distribution, which needs bind mount within root fs: https://github.com/NixOS/nixos/blob/master/modules/system/boot/stage-2-init.sh#L55 Currently for a given filesystem during "de-duplication by source and root" phase, an early mounted fs path is filtered (e.g. "/"), while later mounted fs path is kept (e.g. "/nix/store") though anyway discarded later (since it's an overlaying mount). This leads to skipped trimming. So flip this behaviour. Should also help for other types of overlaying mounts. Reference: https://github.com/karelzak/util-linux/blob/stable/v2.29/libmount/src/tab.c#L715 Signed-off-by: Alex Ivanov <yourbestfriend@openmailbox.org>
* fstrim: use MNT_EX_* from libmountKarel Zak2017-04-271-4/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: do not use plain 0 as NULL [smatch scan]Sami Kerola2017-02-201-8/+8
| | | | | | | | | | text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer Since many 'struct option' has used zero as NULL make them more readable in same go by reindenting, and using named argument requirements. Reference: https://lwn.net/Articles/93577/ Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* fstrim: de-duplicate btrfs sub-volumesStanislav Brabec2017-01-311-13/+1Star
| | | | | | | | | | | | | There was a comparison of roots in uniq_fs_source_cmp(). As we care only on device names, comparing roots makes only a little sense, and it breaks on btrfs. As a result, FITRIM ioctl() is called for each subvolume. But by design, only one TRIM is needed for the whole btrfs volume. Remove it to be able to de-duplicate btrfs subvolumes. Fixes opensuse #1020077. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* Use --help suggestion on invalid optionKarel Zak2016-12-191-1/+1
| | | | | | | | The current default is to print all usage() output. This is overkill in many case. Addresses: https://github.com/karelzak/util-linux/issues/338 Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: Fix various typosSebastian Rasmussen2016-05-311-2/+2
| | | | | | | Fix various typos in error messages, warnings, debug strings, comments and names of static functions. Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
* misc: fix redundant assignment and reassignments before use [cppcheck]Sami Kerola2015-08-081-1/+1
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* fstrim: close dir before exit [coverity scan]Karel Zak2015-06-291-9/+15
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: de-duplicate by mount source tooKarel Zak2015-06-101-1/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Now fstrim de-duplicates by target (mountpoint). This patch adds de-duplication according to mount source (device) to avoid bind mounts or devices mounted more than once. Note that the patch also check FS root, the different FS roots of the same multi-root FS (e.g. btrfs) maybe mounted on different places. # mount --bind /home/wine /mnt/test old version: # fstrim -av /mnt/test: 0 B (0 bytes) trimmed <--- /home/wine: 0 B (0 bytes) trimmed <--- /boot: 0 B (0 bytes) trimmed /home: 0 B (0 bytes) trimmed /: 0 B (0 bytes) trimmed new version: # fstrim -av /mnt/test: 0 B (0 bytes) trimmed <--- /boot: 0 B (0 bytes) trimmed /home: 171.8 MiB (180113408 bytes) trimmed /: 0 B (0 bytes) trimmed Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1162213 Signed-off-by: Karel Zak <kzak@redhat.com>
* textual: grammarize and harmonize the stat error messageBenno Schulenberg2015-02-021-1/+1
| | | | | | | | | The message "stat failed %s" seems to say that stat() failed to do something, or failed to pass a test, but of course it means that the statting of something failed. So say so. Also make two very similar messages equal to this one. Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* textual: add a docstring to most of the utilitiesBenno Schulenberg2015-01-061-0/+4
| | | | | | | | | This adds a concise description of a tool to its usage text. A first form of this patch was proposed by Steven Honeyman (see http://www.spinics.net/lists/util-linux-ng/msg09994.html). Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* fstrim: initialize path variableSami Kerola2014-10-311-1/+1
| | | | | | | | | | | | Reading the code this initialization is not necessary, so the change is mostly about silencing a compiler warning and ensuring the program keeps on working if there is a future bug that could make uninitialized 'path' reachable to use. sys-utils/fstrim.c:247: warning: 'path' may be used uninitialized in this function Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* textual: remove some inconsistent periods from error messagesBenno Schulenberg2014-08-111-1/+1
| | | | | | While doing so, also improve translatability and some wordings. Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* fstrim: fix memory leak [coverity scan]Karel Zak2014-07-171-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: avoid TOCTOU raceSami Kerola2014-07-171-7/+6Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* textual: fix some typosSami Kerola2014-07-131-1/+1
| | | | | | | Found with misspell-check version 2.0d. Reference: https://github.com/lyda/misspell-check Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* textual: small inprovements to usage and man page of fstrimBenno Schulenberg2013-12-121-4/+4
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* fstrim: de-duplicate list of filesystemsKarel Zak2013-12-111-1/+15
| | | | | Reported-by: Pádraig Brady <P@draigBrady.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: add --all to discard all filesystemKarel Zak2013-12-101-30/+180
| | | | | | | | | | | | * read /proc/self/mountinfo to get filesystems * ignore net and pseudo filesystems * ignore unaccessible filesystems (over mounted by another FS) * read disk sysfs queue/discard_granularity to detect is discard support * call FITRIM ioctl * silently ignore EOPNOTSUPP (for example LUKS without discard) and ENOTTY (for example vfat) errors Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: cleanup usage()Karel Zak2013-12-101-4/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: remove unnecessary "were" from verbose messageKarel Zak2013-01-301-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: use human readable sizes in verbose outputKarel Zak2013-01-281-3/+9
| | | | | | | | # fstrim -v /home /home: 513.9 MiB (538828800 bytes) were trimmed Reported-by: member graysky <graysky@archlinux.us> Signed-off-by: Karel Zak <kzak@redhat.com>
* textual: remove inconsistent periods from two error messagesBenno Schulenberg2013-01-251-1/+1
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* Revert "blkdiscard: new command"Karel Zak2012-09-281-119/+35Star
| | | | | | | This was only attempt as alternative implementation, unfortunately pushed publicly... sorry. This reverts commit c84ed54cefdcaa07f3d1f40a65434c9d4277da08.