Support decimal point for -p, --plan
Some checks failed
Build / build-mac (push) Has been cancelled
Build / build-linux (push) Has been cancelled
Build / build-win (push) Has been cancelled
CodeQL Advanced / Analyze (c-cpp) (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled

This commit is contained in:
Andrea Mazzoleni 2026-02-16 17:54:41 +01:00
parent 696ee97754
commit 11fd4ada69
4 changed files with 22 additions and 19 deletions

View file

@ -24,6 +24,8 @@ SnapRAID HISTORY
reclaiming unused space ("holes") that may exist in the parity due to reclaiming unused space ("holes") that may exist in the parity due to
previous fragmentation, allowing to compact the parity toward the beginning previous fragmentation, allowing to compact the parity toward the beginning
[Ralf1108]. [Ralf1108].
* The -p / --plan option now accepts percentage values with decimal points
(e.g. -p 1.5, -p 0.2)
* Added detection of the smartctl executable. Improves reliability when running * Added detection of the smartctl executable. Improves reliability when running
under sudo or in environments where /sbin and /usr/sbin are not in PATH. under sudo or in environments where /sbin and /usr/sbin are not in PATH.
* Avoided saving the content file when it was not strictly necessary. * Avoided saving the content file when it was not strictly necessary.

View file

@ -642,7 +642,7 @@ endif
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) status $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) status
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) fix -e $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) fix -e
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --percentage bad scrub $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --percentage bad scrub
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --plan 1 scrub $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --plan 1.5 scrub
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) -o 0 scrub $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) -o 0 scrub
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) -p full scrub $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) -p full scrub
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) sync $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) sync

View file

@ -786,7 +786,7 @@ static uint32_t md(uint32_t a, uint32_t b, uint32_t c)
return v; return v;
} }
int state_scrub(struct snapraid_state* state, int plan, int olderthan) int state_scrub(struct snapraid_state* state, int plan100, int olderthan)
{ {
block_off_t blockmax; block_off_t blockmax;
block_off_t countlimit; block_off_t countlimit;
@ -804,7 +804,7 @@ int state_scrub(struct snapraid_state* state, int plan, int olderthan)
msg_progress("Initializing...\n"); msg_progress("Initializing...\n");
if ((plan == SCRUB_BAD || plan == SCRUB_NEW || plan == SCRUB_FULL) if ((plan100 == SCRUB_BAD || plan100 == SCRUB_NEW || plan100 == SCRUB_FULL)
&& olderthan >= 0) { && olderthan >= 0) {
/* LCOV_EXCL_START */ /* LCOV_EXCL_START */
log_fatal(EUSER, "You can specify -o, --older-than only with a numeric percentage.\n"); log_fatal(EUSER, "You can specify -o, --older-than only with a numeric percentage.\n");
@ -821,13 +821,13 @@ int state_scrub(struct snapraid_state* state, int plan, int olderthan)
ps.state = state; ps.state = state;
if (state->opt.force_scrub_even) { if (state->opt.force_scrub_even) {
ps.plan = SCRUB_EVEN; ps.plan = SCRUB_EVEN;
} else if (plan == SCRUB_FULL) { } else if (plan100 == SCRUB_FULL) {
ps.plan = SCRUB_FULL; ps.plan = SCRUB_FULL;
msg_progress("Scrub plan: full. All data blocks will be checked.\n"); msg_progress("Scrub plan: full. All data blocks will be checked.\n");
} else if (plan == SCRUB_NEW) { } else if (plan100 == SCRUB_NEW) {
ps.plan = SCRUB_NEW; ps.plan = SCRUB_NEW;
msg_progress("Scrub plan: new. Only blocks that have never been scrubbed will be checked.\n"); msg_progress("Scrub plan: new. Only blocks that have never been scrubbed will be checked.\n");
} else if (plan == SCRUB_BAD) { } else if (plan100 == SCRUB_BAD) {
ps.plan = SCRUB_BAD; ps.plan = SCRUB_BAD;
msg_progress("Scrub plan: bad. Only blocks previously marked as bad will be checked.\n"); msg_progress("Scrub plan: bad. Only blocks previously marked as bad will be checked.\n");
} else if (state->opt.force_scrub_at) { } else if (state->opt.force_scrub_at) {
@ -837,8 +837,8 @@ int state_scrub(struct snapraid_state* state, int plan, int olderthan)
recentlimit = now; recentlimit = now;
} else { } else {
ps.plan = SCRUB_AUTO; ps.plan = SCRUB_AUTO;
if (plan >= 0) { if (plan100 >= 0) {
countlimit = md(blockmax, plan, 100); countlimit = md(blockmax, plan100, 10000);
} else { } else {
/* by default scrub 8.33% of the array (100/12=8.(3)) */ /* by default scrub 8.33% of the array (100/12=8.(3)) */
countlimit = md(blockmax, 1, 12); countlimit = md(blockmax, 1, 12);
@ -851,11 +851,11 @@ int state_scrub(struct snapraid_state* state, int plan, int olderthan)
recentlimit = now - 10 * 24 * 3600; recentlimit = now - 10 * 24 * 3600;
} }
if (plan >= 0) { if (plan100 >= 0) {
if (olderthan >= 0) if (olderthan >= 0)
msg_progress("Scrub plan: auto. %d%% of the array, older than %d days, will be checked.\n", plan, olderthan); msg_progress("Scrub plan: auto. %.1f%% of the array, older than %d days, will be checked.\n", plan100 / 100.0, olderthan);
else else
msg_progress("Scrub plan: auto. %d%% of the array, older than 10 days, will be checked.\n", plan); msg_progress("Scrub plan: auto. %.1f%% of the array, older than 10 days, will be checked.\n", plan100 / 100.0);
} else { } else {
if (olderthan >= 0) if (olderthan >= 0)
msg_progress("Scrub plan: auto. 8.3%% of the array, older than %d days, will be checked.\n", olderthan); msg_progress("Scrub plan: auto. 8.3%% of the array, older than %d days, will be checked.\n", olderthan);

View file

@ -981,7 +981,7 @@ int snapraid_main(int argc, char* argv[])
tommy_list filterlist_disk; tommy_list filterlist_disk;
int filter_missing; int filter_missing;
int filter_error; int filter_error;
int plan; int plan100;
int olderthan; int olderthan;
char* e; char* e;
const char* command; const char* command;
@ -1019,7 +1019,7 @@ int snapraid_main(int argc, char* argv[])
speed_test_disks_number = -1; speed_test_disks_number = -1;
filter_missing = 0; filter_missing = 0;
filter_error = 0; filter_error = 0;
plan = SCRUB_AUTO; plan100 = SCRUB_AUTO;
olderthan = SCRUB_AUTO; olderthan = SCRUB_AUTO;
import_timestamp = 0; import_timestamp = 0;
import_content = 0; import_content = 0;
@ -1082,14 +1082,15 @@ int snapraid_main(int argc, char* argv[])
break; break;
case 'p' : case 'p' :
if (strcmp(optarg, "bad") == 0) { if (strcmp(optarg, "bad") == 0) {
plan = SCRUB_BAD; plan100 = SCRUB_BAD;
} else if (strcmp(optarg, "new") == 0) { } else if (strcmp(optarg, "new") == 0) {
plan = SCRUB_NEW; plan100 = SCRUB_NEW;
} else if (strcmp(optarg, "full") == 0) { } else if (strcmp(optarg, "full") == 0) {
plan = SCRUB_FULL; plan100 = SCRUB_FULL;
} else { } else {
plan = strtoul(optarg, &e, 10); double plan_double = strtod(optarg, &e);
if (!e || *e || plan > 100) { plan100 = plan_double * 100;
if (!e || *e || plan100 > 10000) {
/* LCOV_EXCL_START */ /* LCOV_EXCL_START */
log_fatal(EUSER, "Invalid plan/percentage '%s'\n", optarg); log_fatal(EUSER, "Invalid plan/percentage '%s'\n", optarg);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -1937,7 +1938,7 @@ int snapraid_main(int argc, char* argv[])
/* intercept signals while operating */ /* intercept signals while operating */
signal_init(); signal_init();
ret = state_scrub(&state, plan, olderthan); ret = state_scrub(&state, plan100, olderthan);
} else if (operation == OPERATION_REWRITE) { } else if (operation == OPERATION_REWRITE) {
state_read(&state); state_read(&state);