]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_scrub: report FITRIM errors properly
authorDarrick J. Wong <djwong@kernel.org>
Mon, 29 Jul 2024 23:23:12 +0000 (16:23 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:01:09 +0000 (17:01 -0700)
Move the error reporting for the FITRIM ioctl out of vfs.c and into
phase8.c.  This makes it so that IO errors encountered during trim are
counted as runtime errors instead of being dropped silently.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
scrub/phase8.c
scrub/vfs.c
scrub/vfs.h

index dfe62e8d97be6d46fbbe2985690a9df8d8977931..288800a76cffc952b28e3ca3ca1ac1830847f80d 100644 (file)
@@ -47,10 +47,20 @@ int
 phase8_func(
        struct scrub_ctx        *ctx)
 {
+       int                     error;
+
        if (!fstrim_ok(ctx))
                return 0;
 
-       fstrim(ctx);
+       error = fstrim(ctx);
+       if (error == EOPNOTSUPP)
+               return 0;
+
+       if (error) {
+               str_liberror(ctx, error, _("fstrim"));
+               return error;
+       }
+
        progress_add(1);
        return 0;
 }
index 9e459d6243fa4428dd27de192fa5935db9ee8fcf..bcfd4f42ca8b6b932009029b0888c40dd1a2a516 100644 (file)
@@ -296,15 +296,17 @@ struct fstrim_range {
 #endif
 
 /* Call FITRIM to trim all the unused space in a filesystem. */
-void
+int
 fstrim(
        struct scrub_ctx        *ctx)
 {
        struct fstrim_range     range = {0};
-       int                     error;
 
        range.len = ULLONG_MAX;
-       error = ioctl(ctx->mnt.fd, FITRIM, &range);
-       if (error && errno != EOPNOTSUPP && errno != ENOTTY)
-               perror(_("fstrim"));
+       if (ioctl(ctx->mnt.fd, FITRIM, &range) == 0)
+               return 0;
+       if (errno == EOPNOTSUPP || errno == ENOTTY)
+               return EOPNOTSUPP;
+
+       return errno;
 }
index 1ac41e5aac078f006e9d4fa413bb5ae3d967efc2..a8a4d72e290a45f4be8d041bad5a223773dba60e 100644 (file)
@@ -24,6 +24,6 @@ typedef int (*scan_fs_tree_dirent_fn)(struct scrub_ctx *, const char *,
 int scan_fs_tree(struct scrub_ctx *ctx, scan_fs_tree_dir_fn dir_fn,
                scan_fs_tree_dirent_fn dirent_fn, void *arg);
 
-void fstrim(struct scrub_ctx *ctx);
+int fstrim(struct scrub_ctx *ctx);
 
 #endif /* XFS_SCRUB_VFS_H_ */