From 52ef48655f8b99b58dcad14134a7f57f54c76c9a Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Mon, 13 Oct 2025 11:46:36 +0200 Subject: [PATCH] Improve and change the order of the user messages The "Everything is OK" is now printed as latest one. --- cmdline/check.c | 2 +- cmdline/dry.c | 2 +- cmdline/scrub.c | 21 ++++++++++++++++++++- cmdline/snapraid.c | 16 ++-------------- cmdline/state.c | 4 ++-- cmdline/state.h | 2 +- cmdline/sync.c | 18 +++++++++++++----- 7 files changed, 40 insertions(+), 25 deletions(-) diff --git a/cmdline/check.c b/cmdline/check.c index 23d2abcb..a57cdd8c 100644 --- a/cmdline/check.c +++ b/cmdline/check.c @@ -1834,7 +1834,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna } end: - state_progress_end(state, countpos, countmax, countsize); + state_progress_end(state, countpos, countmax, countsize, "Nothing to check.\n"); bail: /* close all the files left open */ diff --git a/cmdline/dry.c b/cmdline/dry.c index 20cfc513..c3f67698 100644 --- a/cmdline/dry.c +++ b/cmdline/dry.c @@ -363,7 +363,7 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit } end: - state_progress_end(state, countpos, countmax, countsize); + state_progress_end(state, countpos, countmax, countsize, "Nothing to dry.\n"); state_usage_print(state); diff --git a/cmdline/scrub.c b/cmdline/scrub.c index 8d32e40a..bb072b39 100644 --- a/cmdline/scrub.c +++ b/cmdline/scrub.c @@ -665,7 +665,11 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par } end: - state_progress_end(state, countpos, countmax, countsize); + state_progress_end(state, countpos, countmax, countsize, "Nothing to scrub. Use the -p PLAN option to select a different plan, like -p full.\n"); + + /* save the new state if required */ + if (state->need_write || state->opt.force_content_write) + state_write(state); state_usage_print(state); @@ -788,10 +792,13 @@ int state_scrub(struct snapraid_state* state, int plan, int olderthan) ps.plan = SCRUB_EVEN; } else if (plan == SCRUB_FULL) { ps.plan = SCRUB_FULL; + msg_info("Scrub plan: full. All data blocks will be checked.\n"); } else if (plan == SCRUB_NEW) { ps.plan = SCRUB_NEW; + msg_info("Scrub plan: new. Only blocks that have never been scrubbed will be checked.\n"); } else if (plan == SCRUB_BAD) { ps.plan = SCRUB_BAD; + msg_info("Scrub plan: bad. Only blocks previously marked as bad will be checked.\n"); } else if (state->opt.force_scrub_at) { /* scrub the specified amount of blocks */ ps.plan = SCRUB_AUTO; @@ -812,6 +819,18 @@ int state_scrub(struct snapraid_state* state, int plan, int olderthan) /* by default use a 10 day time limit */ recentlimit = now - 10 * 24 * 3600; } + + if (plan >= 0) { + if (olderthan >= 0) + msg_info("Scrub plan: auto. %d%% of the array, older than %d days, will be checked.\n", plan, olderthan); + else + msg_info("Scrub plan: auto. %d%% of the array, older than 10 days, will be checked.\n", plan); + } else { + if (olderthan >= 0) + msg_info("Scrub plan: auto. 8.3%% of the array, older than %d days, will be checked.\n", olderthan); + else + msg_info("Scrub plan: auto. 8.3%% of the array, older than 10 days, will be checked.\n"); + } } /* identify the time limit */ diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index 765747de..a050fd2e 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -1420,14 +1420,6 @@ int snapraid_main(int argc, char* argv[]) ret = state_sync(&state, blockstart, blockcount); - /* save the new state if required */ - if (!opt.kill_after_sync) { - if ((state.need_write || state.opt.force_content_write)) - state_write(&state); - } else { - log_fatal("WARNING! Skipped writing state due to --test-kill-after-sync option.\n"); - } - /* abort if required */ if (ret != 0) { /* LCOV_EXCL_START */ @@ -1468,10 +1460,6 @@ int snapraid_main(int argc, char* argv[]) ret = state_scrub(&state, plan, olderthan); - /* save the new state if required */ - if (state.need_write || state.opt.force_content_write) - state_write(&state); - /* abort if required */ if (ret != 0) { /* LCOV_EXCL_START */ @@ -1494,14 +1482,14 @@ int snapraid_main(int argc, char* argv[]) } else if (operation == OPERATION_TOUCH) { state_read(&state); + memory(); + state_touch(&state); /* intercept signals while operating */ signal_init(); state_write(&state); - - memory(); } else if (operation == OPERATION_SPINUP) { state_device(&state, DEVICE_UP, &filterlist_disk); } else if (operation == OPERATION_SPINDOWN) { diff --git a/cmdline/state.c b/cmdline/state.c index 3ae18803..c78cd4da 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -4376,7 +4376,7 @@ int state_progress_begin(struct snapraid_state* state, block_off_t blockstart, b return 1; } -void state_progress_end(struct snapraid_state* state, block_off_t countpos, block_off_t countmax, data_off_t countsize) +void state_progress_end(struct snapraid_state* state, block_off_t countpos, block_off_t countmax, data_off_t countsize, const char* msg) { if (state->opt.gui) { log_tag("run:end\n"); @@ -4385,7 +4385,7 @@ void state_progress_end(struct snapraid_state* state, block_off_t countpos, bloc if (state->need_write || state->written) { msg_status("100%% completed\n"); } else { - msg_status("Nothing to do\n"); + msg_status("%s", msg); } } else { time_t now; diff --git a/cmdline/state.h b/cmdline/state.h index 9ca0b885..f37c2d15 100644 --- a/cmdline/state.h +++ b/cmdline/state.h @@ -327,7 +327,7 @@ int state_progress_begin(struct snapraid_state* state, block_off_t blockstart, b /** * End the progress visualization. */ -void state_progress_end(struct snapraid_state* state, block_off_t countpos, block_off_t countmax, data_off_t countsize); +void state_progress_end(struct snapraid_state* state, block_off_t countpos, block_off_t countmax, data_off_t countsize, const char* msg); /** * Write the progress. diff --git a/cmdline/sync.c b/cmdline/sync.c index d8d6606b..214af597 100644 --- a/cmdline/sync.c +++ b/cmdline/sync.c @@ -341,7 +341,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta } end: - state_progress_end(state, countpos, countmax, countsize); + state_progress_end(state, countpos, countmax, countsize, "Nothing to hash.\n"); /* note that at this point no io_error is possible */ /* because at the first one we bail out */ @@ -1361,9 +1361,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari } end: - state_progress_end(state, countpos, countmax, countsize); - - state_usage_print(state); + state_progress_end(state, countpos, countmax, countsize, "Nothing to sync.\n"); /* before returning we ensure that */ /* the parity is really written flushing the disk cache */ @@ -1376,6 +1374,16 @@ end: /* LCOV_EXCL_STOP */ } + /* save the new state if required */ + if (!state->opt.kill_after_sync) { + if ((state->need_write || state->opt.force_content_write)) + state_write(state); + } else { + log_fatal("WARNING! Skipped writing state due to --test-kill-after-sync option.\n"); + } + + state_usage_print(state); + if (error || silent_error || io_error) { msg_status("\n"); msg_status("%8u file errors\n", error); @@ -1607,7 +1615,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t /* LCOV_EXCL_STOP */ } } else { - msg_status("Nothing to do\n"); + msg_status("Nothing to sync.\n"); } }