@@ -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;
}
@@ -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;
}
@@ -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_ */