From 5d8f17dcd131099423bdb1c14d15a3ebf9e07668 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Sun, 16 Feb 2014 21:05:25 +0100 Subject: [PATCH] Keeps the default value of -p and -o. --- HISTORY | 4 +++- TODO | 3 --- scrub.c | 30 ++++++++++++++++++++++-------- snapraid.1 | 3 +-- snapraid.d | 3 +-- snapraid.txt | 3 +-- 6 files changed, 28 insertions(+), 18 deletions(-) diff --git a/HISTORY b/HISTORY index 9f9d9806..7ece9282 100644 --- a/HISTORY +++ b/HISTORY @@ -19,8 +19,10 @@ SnapRAID HISTORY * In "fix", if a previous fixing attempt was made resulting in a .unrecoverable file, uses this file as starting point for the new attempt. - * In the log file name allow the use of the '>>', %D, %T modifiers + * In the log file name allows the use of the '>>', %D, %T modifiers to select append mode, and to insert the date and time in the name. + * The options -p, --percentage and -o, --older-than now keep their + default value even if the other one is specified. * New source code organization. The RAID engine is now an external component usable also in other projects. diff --git a/TODO b/TODO index d3d78077..ade02890 100644 --- a/TODO +++ b/TODO @@ -5,9 +5,6 @@ This is the list of TODO items for SnapRAID. - Next -* Don't disable default 10d/12% if -p or -o is specified. -But check that -p0 still work. - * Checks if splitting hash/parity computation in 4K pages can improve speed in sync. That should increase cache locality, becase we read the data two times for hash and and parity, diff --git a/scrub.c b/scrub.c index 09d43787..6eed9fb1 100644 --- a/scrub.c +++ b/scrub.c @@ -459,6 +459,20 @@ bail: return 0; } +/** + * Returns a * b / c approximated to the upper value. + */ +static uint32_t md(uint32_t a, uint32_t b, uint32_t c) +{ + uint64_t v = a; + + v *= b; + v += c - 1; + v /= c; + + return v; +} + int state_scrub(struct snapraid_state* state, int percentage, int olderthan) { block_off_t blockmax; @@ -490,21 +504,21 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) /* scrub the specified amount of blocks */ countlimit = state->opt.force_scrub; recentlimit = now; - } else if (percentage != -1 || olderthan != -1) { + } else { + /* by default scrub 1/12 of the array */ + countlimit = md(blockmax, 1, 12); + + /* by default use a 10 day time limit */ + recentlimit = now - 10 * 24 * 3600; + if (percentage != -1) - countlimit = (blockmax * (uint64_t)percentage + 99) / 100; + countlimit = md(blockmax, percentage, 100); else countlimit = blockmax; if (olderthan != -1) recentlimit = now - olderthan * 24 * 3600; else recentlimit = now; - } else { - /* by default scrub 1/12 of the array */ - countlimit = blockmax / 12; - - /* by default use a 10 day time limit */ - recentlimit = now - 10 * 24 * 3600; } /* identify the time limit */ diff --git a/snapraid.1 b/snapraid.1 index 04cc0bbd..b55678cc 100644 --- a/snapraid.1 +++ b/snapraid.1 @@ -557,8 +557,7 @@ at least one time every two months. .PP You can use the \-p, \-\-percentage option to specify a different amount, and the \-o, \-\-older\-than option to specify a different age in days. -Note that if only one of \-p and \-o is specified the default value of -the other option is not used. +You can have a full scrub with \(a"\-p100 \-o0\(a". .PP Any silent error identified is recorded in the content file, and it\(cqs listed in the \(a"status\(a" command until it\(cqs fixed calling diff --git a/snapraid.d b/snapraid.d index 59a7fd60..8f2b6477 100644 --- a/snapraid.d +++ b/snapraid.d @@ -315,8 +315,7 @@ Commands You can use the -p, --percentage option to specify a different amount, and the -o, --older-than option to specify a different age in days. - Note that if only one of -p and -o is specified the default value of - the other option is not used. + You can have a full scrub with "-p100 -o0". Any silent error identified is recorded in the content file, and it's listed in the "status" command until it's fixed calling diff --git a/snapraid.txt b/snapraid.txt index e109434e..71cd1bdd 100644 --- a/snapraid.txt +++ b/snapraid.txt @@ -343,8 +343,7 @@ at least one time every two months. You can use the -p, --percentage option to specify a different amount, and the -o, --older-than option to specify a different age in days. -Note that if only one of -p and -o is specified the default value of -the other option is not used. +You can have a full scrub with "-p100 -o0". Any silent error identified is recorded in the content file, and it's listed in the "status" command until it's fixed calling