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