summaryrefslogtreecommitdiffstats
path: root/sys-utils/fstrim.c
diff options
context:
space:
mode:
authorKarel Zak2018-12-10 11:45:03 +0100
committerKarel Zak2018-12-10 11:45:03 +0100
commit410d12e5beb78838fc7c6d47d4c433459dc8b857 (patch)
tree7b4aaab5417c35b8cc1f3d87182da86502eeb879 /sys-utils/fstrim.c
parentlibmount: export mnt_guess_system_root() by API (diff)
downloadkernel-qcow2-util-linux-410d12e5beb78838fc7c6d47d4c433459dc8b857.tar.gz
kernel-qcow2-util-linux-410d12e5beb78838fc7c6d47d4c433459dc8b857.tar.xz
kernel-qcow2-util-linux-410d12e5beb78838fc7c6d47d4c433459dc8b857.zip
fstrim: trim also root FS on --fstab
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>
Diffstat (limited to 'sys-utils/fstrim.c')
-rw-r--r--sys-utils/fstrim.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/sys-utils/fstrim.c b/sys-utils/fstrim.c
index b1823f5c5..00652cbb1 100644
--- a/sys-utils/fstrim.c
+++ b/sys-utils/fstrim.c
@@ -242,9 +242,26 @@ static int fstrim_all(struct fstrim_control *ctl)
mnt_table_uniq_fs(tab, MNT_UNIQ_FORWARD, uniq_fs_source_cmp);
if (ctl->fstab) {
+ char *rootdev = NULL;
+
cache = mnt_new_cache();
if (!cache)
err(MNT_EX_FAIL, _("failed to initialize libmount cache"));
+
+ /* Make sure we trim also root FS on --fstab */
+ if (mnt_table_find_target(tab, "/", MNT_ITER_FORWARD) == NULL &&
+ mnt_guess_system_root(0, cache, &rootdev) == 0) {
+
+ fs = mnt_new_fs();
+ if (!fs)
+ err(MNT_EX_FAIL, _("failed to allocate FS handler"));
+ mnt_fs_set_target(fs, "/");
+ mnt_fs_set_source(fs, rootdev);
+ mnt_fs_set_fstype(fs, "auto");
+ mnt_table_add_fs(tab, fs);
+ mnt_unref_fs(fs);
+ fs = NULL;
+ }
}
while (mnt_table_next_fs(tab, itr, &fs) == 0) {