|
|
d017ad |
From c76c1e5d7d3b043549f69c8dc8d6b878b1db0231 Mon Sep 17 00:00:00 2001
|
|
|
d017ad |
From: Scott Shambarger <devel@shambarger.net>
|
|
|
d017ad |
Date: Thu, 12 May 2022 16:27:26 -0700
|
|
|
d017ad |
Subject: fstrim: Remove all skipped entries before de-duplication
|
|
|
d017ad |
|
|
|
d017ad |
When processing fstab entries, de-duplication is performed based on the
|
|
|
d017ad |
source before all tests on the target have been checked, resulting in
|
|
|
d017ad |
some entries being skipped when a removed duplicate with a different
|
|
|
d017ad |
target would not have been.
|
|
|
d017ad |
|
|
|
d017ad |
The fix is to move all the target checks before the source
|
|
|
d017ad |
de-duplication.
|
|
|
d017ad |
|
|
|
d017ad |
Addresses: #1686
|
|
|
d017ad |
Signed-off-by: Scott Shambarger <devel@shambarger.net>
|
|
|
d017ad |
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2165981
|
|
|
d017ad |
---
|
|
|
d017ad |
sys-utils/fstrim.c | 53 ++++++++++++++++++++++++++--------------------
|
|
|
d017ad |
1 file changed, 30 insertions(+), 23 deletions(-)
|
|
|
d017ad |
|
|
|
d017ad |
diff --git a/sys-utils/fstrim.c b/sys-utils/fstrim.c
|
|
|
d017ad |
index 88397f0ec..0b05e590e 100644
|
|
|
d017ad |
--- a/sys-utils/fstrim.c
|
|
|
d017ad |
+++ b/sys-utils/fstrim.c
|
|
|
d017ad |
@@ -230,8 +230,17 @@ static int is_unwanted_fs(struct libmnt_fs *fs, const char *tgt)
|
|
|
d017ad |
return 1;
|
|
|
d017ad |
rc = fstatfs(fd, &vfs) != 0 || vfs.f_type == STATFS_AUTOFS_MAGIC;
|
|
|
d017ad |
close(fd);
|
|
|
d017ad |
+ if (rc)
|
|
|
d017ad |
+ return 1;
|
|
|
d017ad |
|
|
|
d017ad |
- return rc;
|
|
|
d017ad |
+ /* FITRIM on read-only filesystem can fail, and it can fail */
|
|
|
d017ad |
+ if (access(tgt, W_OK) != 0) {
|
|
|
d017ad |
+ if (errno == EROFS)
|
|
|
d017ad |
+ return 1;
|
|
|
d017ad |
+ if (errno == EACCES)
|
|
|
d017ad |
+ return 1;
|
|
|
d017ad |
+ }
|
|
|
d017ad |
+ return 0;
|
|
|
d017ad |
}
|
|
|
d017ad |
|
|
|
d017ad |
static int uniq_fs_target_cmp(
|
|
|
d017ad |
@@ -317,6 +326,8 @@ static int fstrim_all_from_file(struct fstrim_control *ctl, const char *filename
|
|
|
d017ad |
while (mnt_table_next_fs(tab, itr, &fs) == 0) {
|
|
|
d017ad |
const char *src = mnt_fs_get_srcpath(fs),
|
|
|
d017ad |
*tgt = mnt_fs_get_target(fs);
|
|
|
d017ad |
+ char *path;
|
|
|
d017ad |
+ int rc = 1;
|
|
|
d017ad |
|
|
|
d017ad |
if (!tgt || is_unwanted_fs(fs, tgt)) {
|
|
|
d017ad |
mnt_table_remove_fs(tab, fs);
|
|
|
d017ad |
@@ -339,19 +350,6 @@ static int fstrim_all_from_file(struct fstrim_control *ctl, const char *filename
|
|
|
d017ad |
mnt_table_remove_fs(tab, fs);
|
|
|
d017ad |
continue;
|
|
|
d017ad |
}
|
|
|
d017ad |
- }
|
|
|
d017ad |
-
|
|
|
d017ad |
- /* de-duplicate by source */
|
|
|
d017ad |
- mnt_table_uniq_fs(tab, MNT_UNIQ_FORWARD, uniq_fs_source_cmp);
|
|
|
d017ad |
-
|
|
|
d017ad |
- mnt_reset_iter(itr, MNT_ITER_BACKWARD);
|
|
|
d017ad |
-
|
|
|
d017ad |
- /* Do FITRIM */
|
|
|
d017ad |
- while (mnt_table_next_fs(tab, itr, &fs) == 0) {
|
|
|
d017ad |
- const char *src = mnt_fs_get_srcpath(fs),
|
|
|
d017ad |
- *tgt = mnt_fs_get_target(fs);
|
|
|
d017ad |
- char *path;
|
|
|
d017ad |
- int rc = 1;
|
|
|
d017ad |
|
|
|
d017ad |
/* Is it really accessible mountpoint? Not all mountpoints are
|
|
|
d017ad |
* accessible (maybe over mounted by another filesystem) */
|
|
|
d017ad |
@@ -359,20 +357,29 @@ static int fstrim_all_from_file(struct fstrim_control *ctl, const char *filename
|
|
|
d017ad |
if (path && streq_paths(path, tgt))
|
|
|
d017ad |
rc = 0;
|
|
|
d017ad |
free(path);
|
|
|
d017ad |
- if (rc)
|
|
|
d017ad |
+ if (rc) {
|
|
|
d017ad |
+ mnt_table_remove_fs(tab, fs);
|
|
|
d017ad |
continue; /* overlaying mount */
|
|
|
d017ad |
-
|
|
|
d017ad |
- /* FITRIM on read-only filesystem can fail, and it can fail */
|
|
|
d017ad |
- if (access(tgt, W_OK) != 0) {
|
|
|
d017ad |
- if (errno == EROFS)
|
|
|
d017ad |
- continue;
|
|
|
d017ad |
- if (errno == EACCES)
|
|
|
d017ad |
- continue;
|
|
|
d017ad |
}
|
|
|
d017ad |
|
|
|
d017ad |
if (!is_directory(tgt, 1) ||
|
|
|
d017ad |
- !has_discard(src, &wholedisk))
|
|
|
d017ad |
+ !has_discard(src, &wholedisk)) {
|
|
|
d017ad |
+ mnt_table_remove_fs(tab, fs);
|
|
|
d017ad |
continue;
|
|
|
d017ad |
+ }
|
|
|
d017ad |
+ }
|
|
|
d017ad |
+
|
|
|
d017ad |
+ /* de-duplicate by source */
|
|
|
d017ad |
+ mnt_table_uniq_fs(tab, MNT_UNIQ_FORWARD, uniq_fs_source_cmp);
|
|
|
d017ad |
+
|
|
|
d017ad |
+ mnt_reset_iter(itr, MNT_ITER_BACKWARD);
|
|
|
d017ad |
+
|
|
|
d017ad |
+ /* Do FITRIM */
|
|
|
d017ad |
+ while (mnt_table_next_fs(tab, itr, &fs) == 0) {
|
|
|
d017ad |
+ const char *src = mnt_fs_get_srcpath(fs),
|
|
|
d017ad |
+ *tgt = mnt_fs_get_target(fs);
|
|
|
d017ad |
+ int rc;
|
|
|
d017ad |
+
|
|
|
d017ad |
cnt++;
|
|
|
d017ad |
|
|
|
d017ad |
/*
|
|
|
d017ad |
--
|
|
|
d017ad |
2.39.1
|
|
|
d017ad |
|