action_list_empty(ctx->file_repair_list))
return 0;
+ if (ctx->mode == SCRUB_MODE_PREEN && ctx->corruptions_found) {
+ str_info(ctx, ctx->mntpoint,
+ _("Corruptions found; will not optimize. Re-run without -p.\n"));
+ return 0;
+ }
+
/*
* Check the resource usage counters early. Normally we do this during
* phase 7, but some of the cross-referencing requires fairly accurate
* repair if desired, otherwise complain.
*/
if (is_corrupt(&meta) || xref_disagrees(&meta)) {
- if (ctx->mode < SCRUB_MODE_REPAIR) {
+ if (ctx->mode != SCRUB_MODE_REPAIR) {
/* Dry-run mode, so log an error and forget it. */
str_corrupt(ctx, descr_render(&dsc),
_("Repairs are required."));
* otherwise complain.
*/
if (is_unoptimized(&meta)) {
- if (ctx->mode != SCRUB_MODE_REPAIR) {
+ if (ctx->mode == SCRUB_MODE_DRY_RUN) {
/* Dry-run mode, so log an error and forget it. */
if (group != XFROG_SCRUB_GROUP_INODE) {
/* AG or FS metadata, always warn. */
fprintf(stderr, _(" -k Do not FITRIM the free space.\n"));
fprintf(stderr, _(" -m path Path to /etc/mtab.\n"));
fprintf(stderr, _(" -n Dry run. Do not modify anything.\n"));
+ fprintf(stderr, _(" -p Only optimize, do not fix corruptions.\n"));
fprintf(stderr, _(" -T Display timing/usage information.\n"));
fprintf(stderr, _(" -v Verbose output.\n"));
fprintf(stderr, _(" -V Print version.\n"));
sp->descr = _("Repair filesystem.");
sp->fn = phase4_func;
sp->must_run = true;
+ } else if (sp->fn == REPAIR_DUMMY_FN &&
+ ctx->mode == SCRUB_MODE_PREEN) {
+ sp->descr = _("Optimize filesystem.");
+ sp->fn = phase4_func;
+ sp->must_run = true;
}
/* Skip certain phases unless they're turned on. */
if (ctx->scrub_setup_succeeded && actionable_errors > 0) {
char *msg;
- if (ctx->mode == SCRUB_MODE_DRY_RUN)
+ if (ctx->mode != SCRUB_MODE_REPAIR)
msg = _("%s: Re-run xfs_scrub without -n.\n");
else
msg = _("%s: Unmount and run xfs_repair.\n");
pthread_mutex_init(&ctx.lock, NULL);
ctx.mode = SCRUB_MODE_REPAIR;
ctx.error_action = ERRORS_CONTINUE;
- while ((c = getopt(argc, argv, "a:bC:de:kM:m:no:TvxV")) != EOF) {
+ while ((c = getopt(argc, argv, "a:bC:de:kM:m:no:pTvxV")) != EOF) {
switch (c) {
case 'a':
ctx.max_errors = cvt_u64(optarg, 10);
mtab = optarg;
break;
case 'n':
+ if (ctx.mode != SCRUB_MODE_REPAIR) {
+ fprintf(stderr, _("Cannot use -n with -p.\n"));
+ usage();
+ }
ctx.mode = SCRUB_MODE_DRY_RUN;
break;
case 'o':
parse_o_opts(&ctx, optarg);
break;
+ case 'p':
+ if (ctx.mode != SCRUB_MODE_REPAIR) {
+ fprintf(stderr, _("Cannot use -p with -n.\n"));
+ usage();
+ }
+ ctx.mode = SCRUB_MODE_PREEN;
+ break;
case 'T':
display_rusage = true;
break;