diff options
author | Karel Zak <kzak@redhat.com> | 2013-12-11 17:01:23 +0100 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2013-12-11 17:01:23 +0100 |
commit | e05a3400e79e8cba6aca8725fd53d2b9753f0cf3 (patch) | |
tree | 9137a57adf90d38d1d989682d032341775f97bd4 /sys-utils | |
parent | bebdda30360f4341c8b87386898775cb246dbfe3 (diff) | |
download | util-linux-e05a3400e79e8cba6aca8725fd53d2b9753f0cf3.tar.gz |
fstrim: de-duplicate list of filesystems
Reported-by: Pádraig Brady <P@draigBrady.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils')
-rw-r--r-- | sys-utils/fstrim.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/sys-utils/fstrim.c b/sys-utils/fstrim.c index 747e6bb2..f58b6d4c 100644 --- a/sys-utils/fstrim.c +++ b/sys-utils/fstrim.c @@ -139,6 +139,15 @@ static int has_discard(const char *devname, struct sysfs_cxt *wholedisk) return rc == 0 && dg > 0; } + +static int uniq_fs_target_cmp( + struct libmnt_table *tb __attribute__((__unused__)), + struct libmnt_fs *a, + struct libmnt_fs *b) +{ + return !mnt_fs_streq_target(a, mnt_fs_get_target(b)); +} + /* * fstrim --all follows "mount -a" return codes: * @@ -154,6 +163,8 @@ static int fstrim_all(struct fstrim_range *rangetpl, int verbose) struct sysfs_cxt wholedisk = UL_SYSFSCXT_EMPTY; int cnt = 0, cnt_err = 0; + mnt_init_debug(0); + itr = mnt_new_iter(MNT_ITER_BACKWARD); if (!itr) err(MOUNT_EX_FAIL, _("failed to initialize libmount iterator")); @@ -162,6 +173,9 @@ static int fstrim_all(struct fstrim_range *rangetpl, int verbose) if (!tab) err(MOUNT_EX_FAIL, _("failed to parse %s"), _PATH_PROC_MOUNTINFO); + /* de-duplicate the table */ + mnt_table_uniq_fs(tab, 0, uniq_fs_target_cmp); + while (mnt_table_next_fs(tab, itr, &fs) == 0) { const char *src = mnt_fs_get_srcpath(fs), *tgt = mnt_fs_get_target(fs); @@ -199,7 +213,7 @@ static int fstrim_all(struct fstrim_range *rangetpl, int verbose) } sysfs_deinit(&wholedisk); - mnt_free_table(tab); + mnt_unref_table(tab); if (cnt && cnt == cnt_err) return MOUNT_EX_FAIL; /* all failed */ |